shangjiaxuan / Barotrauma-Item-IO-Framework-Mod

A mod that reduces entity count from all stackable items.
0 stars 2 forks source link

Plugin contained harmony patches #1

Open amadare42 opened 1 year ago

amadare42 commented 1 year ago

Hello. Currently, Lua for Barotrauma have significant limitation - all ACsMods are compiled in the same assembly. Therefore when you do Harmony.PatchAll(Assembly.GetExecutingAssembly());, Harmony will find not only your mod, but all other mods that have defined HarmonyPatches. Hence same postfix, prefix, tranpiler hooks would be applied again. That will break other mods with Harmony patches.

Please consider opting out of using default Harmony.PatchAll() statement to make your mod more compatible with other mods. You may use same helper class that I wrote https://github.com/amadare42/BarotraumaMods/blob/master/ItemFinderCountProj/CSharp/Client/HarmonyHelper.cs that allows to apply all patches in class recursively. Or came up with your own solution.

Thank you.

shangjiaxuan commented 1 year ago

@amadare42 I thought each compiled code had separate nameless assemblies. I set a debug break here, and only one ACsMod from the currently compiled mod is found (here):

return Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ACsMod))).ToList();
TBN-MapleWheels commented 1 year ago

No, this was in fact how it used to be. the Cs modloader has been rewritten as of the 1.1.19.x update. You can now use PatchAll() again.