diff --git a/NebulaPatcher/NebulaPlugin.cs b/NebulaPatcher/NebulaPlugin.cs index f5872d3a9..ac8debaed 100644 --- a/NebulaPatcher/NebulaPlugin.cs +++ b/NebulaPatcher/NebulaPlugin.cs @@ -13,6 +13,7 @@ using NebulaPatcher.Logger; using NebulaPatcher.MonoBehaviours; using NebulaPatcher.Patches.Dynamic; +using NebulaPatcher.Patches.Misc; using NebulaWorld; using NebulaWorld.GameStates; using NebulaWorld.SocialIntegration; @@ -156,7 +157,7 @@ private void Awake() } else if (newgameArgExists) { - Log.Error(">> New game parameters incorrect! Exiting...\nExpect: -newgame seed starCount resourceMltiplier"); + Log.Error(">> New game parameters incorrect! Exiting...\nExpect: -newgame seed starCount resourceMultiplier"); } else { @@ -264,7 +265,7 @@ public static void SetGameDescFromConfigFile(GameDesc gameDesc) } var resourceMultiplier = customFile.Bind("Basic", "resourceMultiplier", -1f, - "Resource Multiplier. Infinte = 100. Negative value: Default(1.0f) or remain the same.").Value; + "Resource Multiplier. Infinite = 100. Negative value: Default(1.0f) or remain the same.").Value; if (resourceMultiplier >= 0f) { gameDesc.resourceMultiplier = resourceMultiplier; @@ -375,10 +376,11 @@ private static void InitPatches() } #endif var harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), PluginInfo.PLUGIN_ID); + harmony.PatchAll(typeof(Fix_Patches)); if (Multiplayer.IsDedicated) { Log.Info("Patching for headless mode..."); - harmony.PatchAll(typeof(Dedicated_Server_Patch)); + harmony.PatchAll(typeof(Dedicated_Server_Patches)); } #if DEBUG Environment.SetEnvironmentVariable("MONOMOD_DMD_DUMP", ""); diff --git a/NebulaPatcher/Patches/Dynamic/Debugging.cs b/NebulaPatcher/Patches/Misc/Debugging.cs similarity index 97% rename from NebulaPatcher/Patches/Dynamic/Debugging.cs rename to NebulaPatcher/Patches/Misc/Debugging.cs index bc55356bd..76fcc0fc4 100644 --- a/NebulaPatcher/Patches/Dynamic/Debugging.cs +++ b/NebulaPatcher/Patches/Misc/Debugging.cs @@ -9,7 +9,7 @@ #endregion -namespace NebulaPatcher.Patches.Dynamic; +namespace NebulaPatcher.Patches.Misc; [HarmonyPatch(typeof(EnemyFormation))] internal class Debug_EnemyFormation_Patch @@ -46,7 +46,7 @@ public static void EnqueueTech_Postfix(GameHistoryData __instance, int techId) { if (Multiplayer.IsActive && Multiplayer.Session.History.IsIncomingRequest) { - //Do not run if this was triggered by incomming request + //Do not run if this was triggered by incoming request return; } __instance.UnlockTech(techId); @@ -97,13 +97,13 @@ public static void SetForNewGame_Postfix(Mecha __instance) __instance.player.package.AddItemStacked(1501, 600, 1, out _); //add sails __instance.player.package.AddItemStacked(1503, 60, 1, out _); //add rockets __instance.player.package.AddItemStacked(2312, 10, 1, out _); //add launching silo - __instance.player.package.AddItemStacked(2210, 10, 1, out _); //add artifical sun + __instance.player.package.AddItemStacked(2210, 10, 1, out _); //add artificial sun __instance.player.package.AddItemStacked(2311, 20, 1, out _); //add railgun __instance.player.package.AddItemStacked(2001, 600, 1, out _); //add MK3 belts __instance.player.package.AddItemStacked(2002, 600, 1, out _); //add MK3 belts __instance.player.package.AddItemStacked(2003, 600, 1, out _); //add MK3 belts __instance.player.package.AddItemStacked(2013, 100, 1, out _); //add MK3 inserters - __instance.player.package.AddItemStacked(2212, 20, 1, out _); //add satelite sub-station + __instance.player.package.AddItemStacked(2212, 20, 1, out _); //add satellite sub-station __instance.player.package.AddItemStacked(1128, 100, 1, out _); // add combustible unit __instance.player.package.AddItemStacked(1601, 100, 1, out _); // add magnum ammo box __instance.player.package.AddItemStacked(1604, 100, 1, out _); // add shell set @@ -111,7 +111,7 @@ public static void SetForNewGame_Postfix(Mecha __instance) __instance.player.package.AddItemStacked(1609, 100, 1, out _); // add missile set __instance.player.package.AddItemStacked(1613, 100, 1, out _); // add jammer - // temporay fix before PlayerTechBonuses update + // temporary fix before PlayerTechBonuses update __instance.energyShieldUnlocked = true; } } diff --git a/NebulaPatcher/Patches/Dynamic/Dedicated_Server_Patch.cs b/NebulaPatcher/Patches/Misc/Dedicated_Server_Patches.cs similarity index 99% rename from NebulaPatcher/Patches/Dynamic/Dedicated_Server_Patch.cs rename to NebulaPatcher/Patches/Misc/Dedicated_Server_Patches.cs index 430ef278d..d03fe2142 100644 --- a/NebulaPatcher/Patches/Dynamic/Dedicated_Server_Patch.cs +++ b/NebulaPatcher/Patches/Misc/Dedicated_Server_Patches.cs @@ -14,11 +14,11 @@ #endregion -namespace NebulaPatcher.Patches.Dynamic; +namespace NebulaPatcher.Patches.Misc; // Collections of patches that need to make game run in nographics mode // This part only get patch when Multiplayer.IsDedicated is true -internal class Dedicated_Server_Patch +internal class Dedicated_Server_Patches { [HarmonyPostfix] [HarmonyPatch(typeof(GameMain), nameof(GameMain.Begin))] diff --git a/NebulaPatcher/Patches/Misc/Fix_Patches.cs b/NebulaPatcher/Patches/Misc/Fix_Patches.cs new file mode 100644 index 000000000..4c5ccf148 --- /dev/null +++ b/NebulaPatcher/Patches/Misc/Fix_Patches.cs @@ -0,0 +1,60 @@ +#region + +using System; +using HarmonyLib; +using UnityEngine; + +#endregion + +namespace NebulaPatcher.Patches.Misc; + +// Collections of patches to deal with bugs that root cause is unknown +internal class Fix_Patches +{ + // IndexOutOfRangeException: Index was outside the bounds of the array. + // at BuildTool.GetPrefabDesc (System.Int32 objId)[0x0000e] ; IL_000E + // at BuildTool_Path.DeterminePreviews()[0x0008f] ;IL_008F + // + // This means BuildTool_Path.startObjectId has a positive id that is exceed entity pool + // May due to local buildTool affect by other player's build request + [HarmonyFinalizer] + [HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path.DeterminePreviews))] + public static Exception DeterminePreviews(Exception __exception, BuildTool_Path __instance) + { + if (__exception != null) + { + // Reset state + __instance.startObjectId = 0; + __instance.startNearestAddonAreaIdx = 0; + __instance.startTarget = Vector3.zero; + __instance.pathPointCount = 0; + } + return null; + } + + // IndexOutOfRangeException: Index was outside the bounds of the array. + // at CargoTraffic.SetBeltState(System.Int32 beltId, System.Int32 state); (IL_002D) + // at CargoTraffic.SetBeltSelected(System.Int32 beltId); (IL_0000) + // at PlayerAction_Inspect.GameTick(System.Int64 timei); (IL_053E) + // + // Worst outcome when suppressed: Belt highlight is incorrect + [HarmonyFinalizer] + [HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.SetBeltState))] + public static Exception SetBeltState() + { + return null; + } + + // NullReferenceException: Object reference not set to an instance of an object + // at BGMController.UpdateLogic();(IL_03BC) + // at BGMController.LateUpdate(); (IL_0000) + // + // This means if (DSPGame.Game.running) is null + // Worst outcome when suppressed: BGM stops + [HarmonyFinalizer] + [HarmonyPatch(typeof(BGMController), nameof(BGMController.UpdateLogic))] + public static Exception UpdateLogic() + { + return null; + } +}