diff --git a/Source/Mods/PerformanceOptimizer.cs b/Source/Mods/PerformanceOptimizer.cs index 39459478..2d6f4728 100644 --- a/Source/Mods/PerformanceOptimizer.cs +++ b/Source/Mods/PerformanceOptimizer.cs @@ -23,8 +23,11 @@ public PerformanceOptimizer(ModContentPack mod) { var doTimeControlsHotkeys = AccessTools.DeclaredMethod("Multiplayer.Client.AsyncTime.TimeControlPatch:DoTimeControlsHotkeys"); if (doTimeControlsHotkeys != null) + { + doTimeControlsHotkeysMethod = MethodInvoker.GetHandler(doTimeControlsHotkeys); MpCompat.harmony.Patch(AccessTools.DeclaredMethod("PerformanceOptimizer.Optimization_DoPlaySettings_DoTimespeedControls:DoTimeControlsGUI"), - prefix: new HarmonyMethod(doTimeControlsHotkeys)); + prefix: new HarmonyMethod(typeof(PerformanceOptimizer), nameof(PreDoTimeControlsGUI))); + } else Log.Error("Could not find TimeControlPatch:DoTimeControlsHotkeys, speed control hot keys won't work with disabled/hidden speed control UI."); } @@ -214,5 +217,20 @@ private static IEnumerable SeparateCachesTranspiler(IEnumerable } #endregion + + #region Time controls + + private static FastInvokeHandler doTimeControlsHotkeysMethod; + + private static bool PreDoTimeControlsGUI() + { + if (!MP.IsInMultiplayer) + return true; + + doTimeControlsHotkeysMethod(null); + return false; + } + + #endregion } } \ No newline at end of file