Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game is not being paused for players in multiplayer #218

Merged
merged 3 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}