Skip to content

Commit

Permalink
Merge pull request #218 from Baldie-dev/pause-game-fix
Browse files Browse the repository at this point in the history
Game is not being paused for players in multiplayer
  • Loading branch information
hubastard authored Apr 24, 2021
2 parents 138367f + c11733e commit 5adb677
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions NebulaPatcher/NebulaPatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="Patches\Dynamic\UIStarmap_Patch.cs" />
<Compile Include="Patches\Dynamic\VFInput_Patch.cs" />
<Compile Include="Patches\Transpilers\CargoTraffic_Patch.cs" />
<Compile Include="Patches\Transpilers\GameMain_Patch.cs" />
<Compile Include="Patches\Transpilers\PlanetFactory_Patch.cs" />
<Compile Include="Patches\Transpilers\MechaDroneLogic_Patch.cs" />
<Compile Include="Patches\Transpilers\PlayerAction_Build_Patch.cs" />
Expand Down
48 changes: 48 additions & 0 deletions NebulaPatcher/Patches/Transpilers/GameMain_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using HarmonyLib;
using NebulaWorld;
using System.Collections.Generic;
using System.Reflection.Emit;

namespace NebulaPatcher.Patches.Transpiler
{
[HarmonyPatch(typeof(GameMain))]
class GameMain_Patch
{
//Ignore Pausing in the multiplayer:
//Change: if (!this._paused)
//To: if (!this._paused || SimulatedWorld.Initialized)

[HarmonyTranspiler]
[HarmonyPatch("FixedUpdate")]
static IEnumerable<CodeInstruction> PickupBeltItems_Transpiler(ILGenerator gen, IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
for (int i = 6; i < codes.Count; i++)
{
if (codes[i].opcode == OpCodes.Callvirt &&
codes[i - 1].opcode == OpCodes.Ldc_I4_1 &&
codes[i - 2].opcode == OpCodes.Br &&
codes[i - 3].opcode == OpCodes.Ldc_I4_0 &&
codes[i - 4].opcode == OpCodes.Br &&
codes[i - 5].opcode == OpCodes.Ceq)
{
//Define new jump for firct condition
Label targetLabel = gen.DefineLabel();
codes[i + 4].labels.Add(targetLabel);

//Add my condition
codes.InsertRange(i + 4, new CodeInstruction[] {
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(SimulatedWorld), "get_Initialized")),
new CodeInstruction(OpCodes.Brfalse_S, codes[i+3].operand)
});

//Change jump of first condition
codes[i + 3] = new CodeInstruction(OpCodes.Brfalse_S, targetLabel);

break;
}
}
return codes;
}
}
}

0 comments on commit 5adb677

Please sign in to comment.