Stabilize RimWorld 1.6 caches and tick optimizations
This commit is contained in:
@@ -90,6 +90,7 @@ public abstract class FishPatch : SingletonFactory<FishPatch>, IExposable, IHasD
|
||||
public List<MethodInfo> BenchmarkHarmonyMethodInfos { get; } = [];
|
||||
private bool Patched { get; set; }
|
||||
private bool ShouldBePatched { get; set; }
|
||||
private readonly HashSet<MethodBase> _patchedTargets = [];
|
||||
|
||||
public virtual string? Name => null;
|
||||
|
||||
@@ -190,15 +191,16 @@ public abstract class FishPatch : SingletonFactory<FishPatch>, IExposable, IHasD
|
||||
|
||||
protected virtual void ApplyPatch()
|
||||
{
|
||||
Patched = true;
|
||||
foreach (var method in TargetMethodInfos)
|
||||
var targets = TargetMethodInfos.ToArray();
|
||||
foreach (var method in targets)
|
||||
{
|
||||
if (_patchedTargets.Contains(method))
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
if (IsBenchmarking)
|
||||
{
|
||||
Patched = false;
|
||||
|
||||
if (AccessTools.EnumeratorMoveNext(method) is { } moveNext)
|
||||
{
|
||||
BenchmarkHarmonyMethodInfos.Add(PerformanceFishMod.Harmony!.Patch(moveNext,
|
||||
@@ -229,6 +231,7 @@ public abstract class FishPatch : SingletonFactory<FishPatch>, IExposable, IHasD
|
||||
transpiler: TryMakeHarmonyMethod(TranspilerMethodInfo, TranspilerMethodPriority),
|
||||
finalizer: TryMakeHarmonyMethod(FinalizerMethodInfo, FinalizerMethodPriority)));
|
||||
}
|
||||
_patchedTargets.Add(method);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -240,6 +243,7 @@ public abstract class FishPatch : SingletonFactory<FishPatch>, IExposable, IHasD
|
||||
FinalizerMethodInfo.FullDescription()}:\n{e}");
|
||||
}
|
||||
}
|
||||
Patched = !IsBenchmarking && targets.All(_patchedTargets.Contains);
|
||||
}
|
||||
|
||||
private static HarmonyMethod? TryMakeHarmonyMethod(MethodInfo? method, int priority = -1, string[]? before = null,
|
||||
@@ -249,7 +253,7 @@ public abstract class FishPatch : SingletonFactory<FishPatch>, IExposable, IHasD
|
||||
public virtual void TryUnpatch()
|
||||
{
|
||||
ShouldBePatched = false;
|
||||
if ( /*!Enabled &&*/ Patched)
|
||||
if (Patched || _patchedTargets.Count != 0)
|
||||
ApplyUnpatching();
|
||||
}
|
||||
|
||||
@@ -269,6 +273,7 @@ public abstract class FishPatch : SingletonFactory<FishPatch>, IExposable, IHasD
|
||||
});
|
||||
}
|
||||
}
|
||||
_patchedTargets.Clear();
|
||||
}
|
||||
|
||||
private static void TryUnpatchMethod(MethodBase targetMethod, MethodInfo? patchMethod)
|
||||
|
||||
Reference in New Issue
Block a user