Skip to content

Commit

Permalink
Fix PerformanceOptimizer compat (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
SokyranTheDragon authored Jan 4, 2024
1 parent 473499a commit b398782
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Source/Mods/PerformanceOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ public PerformanceOptimizer(ModContentPack mod)
prefix: new HarmonyMethod(typeof(PerformanceOptimizer), nameof(CancelIfAutosaving)));
refreshCache = MethodInvoker.GetHandler(resetDataMethod);

MpCompat.harmony.Patch(AccessTools.DeclaredMethod("Multiplayer.Client.MultiplayerSession:SaveGameToFile_Overwrite"),
prefix: new HarmonyMethod(typeof(PerformanceOptimizer), nameof(PreSaveToFile)),
postfix: new HarmonyMethod(typeof(PerformanceOptimizer), nameof(PostSaveToFile)));
var method = AccessTools.DeclaredMethod("Multiplayer.Client.Autosaving:SaveGameToFile_Overwrite");
// Backwards compat
method ??= AccessTools.DeclaredMethod("Multiplayer.Client.MultiplayerSession:SaveGameToFile_Overwrite");
// Even more backwards compat
method ??= AccessTools.DeclaredMethod("Multiplayer.Client.MultiplayerSession:SaveGameToFile");
if (method != null)
{
MpCompat.harmony.Patch(method,
prefix: new HarmonyMethod(typeof(PerformanceOptimizer), nameof(PreSaveToFile)),
postfix: new HarmonyMethod(typeof(PerformanceOptimizer), nameof(PostSaveToFile)));
}
else Log.Error("Couldn't find MP SaveGameToFile method, PerformanceOptimizer will now likely cause desyncs because the patch failed.");

// Big shoutout to NotFood for pointing me to the correct method to clear the cache in.
// I spent hours trying to find a correct method where to clear the cache but failed.
Expand Down

0 comments on commit b398782

Please sign in to comment.