Skip to content

Commit

Permalink
Merge pull request #177 from Baldie-dev/bug-fix-items-on-belts
Browse files Browse the repository at this point in the history
Bug fix for items being granted to all players when belt was destroyed
  • Loading branch information
hubastard authored Apr 17, 2021
2 parents acc3054 + 8d0345b commit dea551e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void ProcessPacket(DestructEntityRequest packet, NebulaConnection conn)
}
}
planet.factory.DestructFinally(GameMain.mainPlayer, packet.ObjId, ref protoId);
FactoryManager.DoNotAddItemsFromBuildingOnDestruct = false;
FactoryManager.EventFromServer = false;
}
}
Expand Down
40 changes: 40 additions & 0 deletions NebulaPatcher/Patches/Transpilers/CargoTraffic_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,45 @@ static IEnumerable<CodeInstruction> PickupBeltItems_Transpiler(ILGenerator gen,
}
return codes;
}

/* Change:
if (num27 > 0)
{
int upCount = GameMain.mainPlayer.TryAddItemToPackage(num27, 1, true, this.beltPool[beltId].entityId);
UIItemup.Up(num27, upCount);
}
* To:
if (num27 > 0 && !FactoryManager.DoNotAddItemsFromBuildingOnDestruct)
{
int upCount = GameMain.mainPlayer.TryAddItemToPackage(num27, 1, true, this.beltPool[beltId].entityId);
UIItemup.Up(num27, upCount);
}
*/
[HarmonyTranspiler]
[HarmonyPatch("AlterBeltConnections")]
static IEnumerable<CodeInstruction> AlterBeltConnections_Transpiler(ILGenerator gen, IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
for (int i = 0; i < codes.Count; i++)
{
if (codes[i].opcode == OpCodes.Call && codes[i].operand?.ToString() == "Player get_mainPlayer()" &&
codes[i - 1].opcode == OpCodes.Ble &&
codes[i - 2].opcode == OpCodes.Ldc_I4_0 &&
codes[i - 3].opcode == OpCodes.Ldloc_S &&
codes[i - 4].opcode == OpCodes.Stloc_S &&
codes[i - 5].opcode == OpCodes.Ldelem_I4 &&
codes[i - 6].opcode == OpCodes.Ldloc_S &&
codes[i - 7].opcode == OpCodes.Ldfld)
{
codes.InsertRange(i, new CodeInstruction[] {
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(FactoryManager), "get_DoNotAddItemsFromBuildingOnDestruct")),
new CodeInstruction(OpCodes.Brtrue_S, codes[i-1].operand),
});
break;
}
}
return codes;
}
}
}

0 comments on commit dea551e

Please sign in to comment.