Skip to content

Commit

Permalink
Add Patches\Misc\Fix_Patches
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Aug 30, 2024
1 parent 19d8c0b commit e0677c9
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
8 changes: 5 additions & 3 deletions NebulaPatcher/NebulaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#endregion

namespace NebulaPatcher.Patches.Dynamic;
namespace NebulaPatcher.Patches.Misc;

[HarmonyPatch(typeof(EnemyFormation))]
internal class Debug_EnemyFormation_Patch
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -97,21 +97,21 @@ 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
__instance.player.package.AddItemStacked(1607, 100, 1, out _); // add plasma capsule
__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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
60 changes: 60 additions & 0 deletions NebulaPatcher/Patches/Misc/Fix_Patches.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit e0677c9

Please sign in to comment.