thorwin99 / SEWorldGenPlugin

A world generation plugin for space engineers
36 stars 8 forks source link

patching: fails with Nexus installed #116

Closed StalkR closed 3 years ago

StalkR commented 3 years ago

Describe the bug SEWorldGen patching for asteroid check (cf. https://github.com/thorwin99/SEWorldGenPlugin/commit/38a8b6040c4fcd638c4d86f6ae3ac344db96d32e) fails when the Nexus (Server Sectoring & DataSync) Torch plugin is enabled. I'm investigating why is that.

To Reproduce Steps to reproduce the behavior:

  1. Prepare a Torch server
  2. Add SEWorldGenPlugin (using latest v2.0.6.5) and enable patching (<EnablePatching>true</EnablePatching>)
  3. Add Nexus plugin (using latest v0.92.48) - also start the Nexus Controller
  4. Start server, logs report that Harmony patch failed:
21:30:37.0363 [DEBUG]  Keen: SEWorldGenPlugin - INFO Version is 2.0.6.5
21:30:37.0675 [DEBUG]  Keen: SEWorldGenPlugin - INFO Latest Version is 2.0.6.5.0
21:30:37.0675 [DEBUG]  Keen: SEWorldGenPlugin - INFO Patching...
21:30:37.0675 [DEBUG]  Keen: SEWorldGenPlugin - INFO Applying patch 'Asteroids jumpdrive fix'
21:30:37.3331 [ERROR]  Keen: SEWorldGenPlugin - ERROR Something went wrong while patching: 
21:30:37.3331 [ERROR]  Keen: SEWorldGenPlugin - ERROR    at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at MonoMod.Utils.Cil.ILGeneratorShim.GetProxy()
   at HarmonyLib.MethodPatcher..ctor(MethodBase original, MethodBase source, List`1 prefixes, List`1 postfixes, List`1 transpilers, List`1 finalizers, Boolean debug)
   at HarmonyLib.PatchFunctions.UpdateWrapper(MethodBase original, PatchInfo patchInfo)
   at HarmonyLib.PatchProcessor.Patch()
   at SEWorldGenPlugin.Patches.PatchOverlapAllAsteroidSeedsInSphere.ApplyPatch(Harmony harmony)
   at SEWorldGenPlugin.Startup.TryEnablePatches()
21:30:37.3331 [DEBUG]  Keen: SEWorldGenPlugin - INFO Init completed
  1. Optionally, connect to the server and confirm that indeed, you can jump in/next SEWorldGen asteroids without the obstacle detection

Expected behavior Patching doesn't fail.

Additional context I was playing on Sigma Draconis Impossible and wasn't careful and jumped into an asteroid and destroyed my ship :) This made me look why is that, read Keen's code, your plugin's code, figured what was the issue and how to fix it (patch it to also check for SEWorldGen voxels not just Keen's procedural ones), found that you fixed it already (https://github.com/thorwin99/SEWorldGenPlugin/issues/26) - great! I don't know if the server administrators there updated the plugin already and if they enabled patching, but I wanted to reproduce locally, so I setup as described above, and noticed the log complaining. I confirm the patching works without Nexus running (no error in the logs) and that obstacle detection works when jumping.

kontu commented 3 years ago

Sigma draconis is still running the Old plugin version (before the rewrite even) and hasn't tested patching on the new one yet

On Mon, Jun 28, 2021 at 15:49 StalkR @.***> wrote:

Describe the bug SEWorldGen patching for asteroid check (cf. 38a8b60 https://github.com/thorwin99/SEWorldGenPlugin/commit/38a8b6040c4fcd638c4d86f6ae3ac344db96d32e) fails when the Nexus (Server Sectoring & DataSync) Torch plugin is enabled. I'm investigating why is that.

To Reproduce Steps to reproduce the behavior:

  1. Prepare a Torch server
  2. Add SEWorldGenPlugin (using latest v2.0.6.5) and enable patching ( true)
  3. Add Nexus plugin (using latest v0.92.48) - also start the Nexus Controller
  4. Start server, logs report that Harmony patch failed:

21:30:37.3331 [ERROR] Keen: SEWorldGenPlugin - ERROR Something went wrong while patching: 21:30:37.3331 [ERROR] Keen: SEWorldGenPlugin - ERROR at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e) at System.RuntimeType.MakeGenericType(Type[] instantiation) at MonoMod.Utils.Cil.ILGeneratorShim.GetProxy() at HarmonyLib.MethodPatcher..ctor(MethodBase original, MethodBase source, List1 prefixes, List1 postfixes, List1 transpilers, List1 finalizers, Boolean debug) at HarmonyLib.PatchFunctions.UpdateWrapper(MethodBase original, PatchInfo patchInfo) at HarmonyLib.PatchProcessor.Patch() at SEWorldGenPlugin.Patches.PatchOverlapAllAsteroidSeedsInSphere.ApplyPatch(Harmony harmony) at SEWorldGenPlugin.Startup.TryEnablePatches() 21:30:38.0206 [INFO] Torch: Starting server watchdog.

  1. Optionally, connect to the server and confirm that indeed, you can jump in/next SEWorldGen asteroids without the obstacle detection

Expected behavior Patching doesn't fail.

Additional context I was playing on Sigma Draconis Impossible and wasn't careful and jumped into an asteroid and destroyed my ship :) This made me look why is that, read Keen's code, your plugin's code, figured what was the issue and how to fix it (patch it to also check for SEWorldGen voxels not just Keen's procedural ones), found that you fixed it already (#26 https://github.com/thorwin99/SEWorldGenPlugin/issues/26) - great! I don't know if the server administrators there updated the plugin already and if they enabled patching, but I wanted to reproduce locally, so I setup as described above, and noticed the log complaining. I confirm the patching works without Nexus running (no error in the logs) and that obstacle detection works when jumping.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/thorwin99/SEWorldGenPlugin/issues/116, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLQ7YP26YODGSVHJRIKGRDTVDG4VANCNFSM47OTYZPA .

StalkR commented 3 years ago

Oh hey Kontu, long time no see :) ok I was asking in a ticket (#ticket-34377) which SEWorldGen version sigma draconis is using but nobody could answer. In any case even if up to date there's this issue, I'll try to find out why and fix first.

StalkR commented 3 years ago

Found the issue: don't include SEWorldGen's 0Harmony.dll, it somehow conflicts with the one shipped in Nexus. Just SEWorldGenPlugin.dll and it patches nicely.

00:02:40.0101 [DEBUG]  Keen: SEWorldGenPlugin - INFO Version is 2.0.6.5
00:02:40.0293 [DEBUG]  Keen: SEWorldGenPlugin - INFO Latest Version is 2.0.6.5.0
00:02:40.0313 [DEBUG]  Keen: SEWorldGenPlugin - INFO Patching...
00:02:40.0313 [DEBUG]  Keen: SEWorldGenPlugin - INFO Applying patch 'Asteroids jumpdrive fix'
00:02:40.0523 [DEBUG]  Keen: SEWorldGenPlugin - INFO Patches applied
00:02:40.0523 [DEBUG]  Keen: SEWorldGenPlugin - INFO Init completed

Continuing my testing, two conclusions:

I imagine this is an issue for non-Nexus servers if jumping into an Asteroid field nobody has been before and being unlucky, but otherwise if jumping to a player-made GPS next to an Asteroid they've been before, the voxels were already generated.

For Nexus servers, by definition the departing sector has not loaded the destination Asteroid field (because it belongs to another server), and since the obstacle detection code runs on the departing sector server, kaboom.

So I don't know, maybe you have a better idea of what could be the issue? It seems related to some first-time generation/loading, but I don't know exactly where. I saw the check for loadedCells and generating cells otherwise so it's likely not that https://github.com/thorwin99/SEWorldGenPlugin/blob/master/SEWorldGenPlugin/Generator/ProceduralGeneration/MyAbstractProceduralCellModule.cs#L125

(we can move this discussion to a separate issue if you prefer)

thorwin99 commented 3 years ago

Yea there can be different harmony versions involved which causes that. In that case you should just download the SEWorldGen.dll file and not 0harmony, since it will be loaded with the game then from the other mod