diff --git a/Source/DebugActions.cs b/Source/DebugActions.cs index 55d447b..1985a68 100644 --- a/Source/DebugActions.cs +++ b/Source/DebugActions.cs @@ -68,6 +68,12 @@ internal enum StuffToSearch AccessTools.DeclaredMethod("HugsLib.ModBase:Update"), AccessTools.DeclaredMethod("HugsLib.ModBase:FixedUpdate"), AccessTools.DeclaredMethod("HugsLib.ModBase:OnGUI"), + AccessTools.DeclaredMethod("BiomesCore.TerrainInstance:Update"), + AccessTools.DeclaredMethod("BiomesCore.TerrainComp:CompUpdate"), + AccessTools.DeclaredMethod("BiomesCore.DefExtensionActive:DoWork", new [] { AccessTools.TypeByName("Verse.TerrainDef") }), + AccessTools.DeclaredMethod("VFECore.TerrainInstance:Update"), + AccessTools.DeclaredMethod("VFECore.TerrainComp:CompUpdate"), + AccessTools.DeclaredMethod("VFECore.DefExtensionActive:DoWork", new [] { AccessTools.TypeByName("Verse.TerrainDef") }), }.Where(x => x != null).ToHashSet(); private static readonly HashSet NonTickingUpdateMethodCalls = new[] diff --git a/Source/Mods/BiomesCore.cs b/Source/Mods/BiomesCore.cs index 915c59f..36c4f6d 100644 --- a/Source/Mods/BiomesCore.cs +++ b/Source/Mods/BiomesCore.cs @@ -11,14 +11,8 @@ namespace Multiplayer.Compat [MpCompatFor("BiomesTeam.BiomesCore")] public class BiomesCore { - private static Type terrainCompType; - private static AccessTools.FieldRef terrainCompParentField; - private static AccessTools.FieldRef terrainInstancePositionField; - public BiomesCore(ModContentPack mod) { - LongEventHandler.ExecuteWhenFinished(LatePatch); - // Gizmos (only dev mode gizmos) { var typeNames = new[] @@ -51,7 +45,11 @@ public BiomesCore(ModContentPack mod) // RNG + GenView.ShouldSpawnMotesAt { - // BiomesCore.GenSteps.ValleyPatch:Postfix - System RNG called, but never used + PatchingUtilities.PatchSystemRand(new[] + { + // Two 'new Random()' calls, one is never used + "BiomesCore.GenSteps.ValleyPatch:Postfix", + }, false); PatchingUtilities.PatchPushPopRand(new[] { @@ -59,54 +57,6 @@ public BiomesCore(ModContentPack mod) "BiomesCore.TerrainComp_MoteSpawner:ThrowMote", }); } - - // Stopwatch - { - MpCompat.harmony.Patch(AccessTools.DeclaredMethod("BiomesCore.SpecialTerrainList:TerrainUpdate"), - prefix: new HarmonyMethod(typeof(BiomesCore), nameof(RemoveTerrainUpdateTimeBudget))); - } - } - - private static void LatePatch() - { - // HashCode on unsafe type - { - // Some extra setup for stuff that will be used by the patch - terrainCompType = AccessTools.TypeByName("BiomesCore.TerrainComp"); - terrainCompParentField = AccessTools.FieldRefAccess(terrainCompType, "parent"); - terrainInstancePositionField = AccessTools.FieldRefAccess("BiomesCore.TerrainInstance:positionInt"); - - // Patch the method using hash code to use different object if it's unsupported - MpCompat.harmony.Patch(AccessTools.DeclaredMethod("BiomesCore.ActiveTerrainUtility:HashCodeToMod"), - prefix: new HarmonyMethod(typeof(BiomesCore), nameof(HashCodeOnSafeObject))); - } - } - - private static void RemoveTerrainUpdateTimeBudget(ref long timeBudget) - { - if (MP.IsInMultiplayer) - timeBudget = long.MaxValue; // Basically limitless time - - // The method is limited in updating a max of 1/3 of all active special terrains. - // If we'd want to work on having a performance option of some sort, we'd have to - // base it around amount of terrain updates per tick, instead of basing it on actual time. - } - - private static void HashCodeOnSafeObject(ref object obj) - { - // We don't care out of MP - if (!MP.IsInMultiplayer) - return; - - if (obj is ThingComp comp) - obj = comp.parent; - else if (obj.GetType().IsAssignableFrom(terrainCompType)) - { - // Get the parent field (TerrainInstance) - obj = terrainCompParentField(obj); - // Get the IntVec3 and use that for hash code (since it's safe for MP) - obj = terrainInstancePositionField(obj); - } } } } \ No newline at end of file