Skip to content

Commit

Permalink
Prevent a powerup being picked up by 2 pilots at the same time.
Browse files Browse the repository at this point in the history
Fixes #81.
  • Loading branch information
roncli committed Mar 10, 2021
1 parent e5cf368 commit 6e28088
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions GameMod/GameMod.csproj
Expand Up @@ -127,6 +127,7 @@
<Compile Include="MPMatchPresets.cs" />
<Compile Include="MPModifiers.cs" />
<Compile Include="MPModPrivateData.cs" />
<Compile Include="MPNoDupes.cs" />
<Compile Include="MPNoPositionCompression.cs" />
<Compile Include="MPPickupCheck.cs" />
<Compile Include="MPPrimaries.cs" />
Expand Down
43 changes: 43 additions & 0 deletions GameMod/MPNoDupes.cs
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using Harmony;
using Overload;

namespace GameMod {
/// <summary>
/// Prevents stock items from being picked up by multiple pilots in the same frame.
/// </summary>
[HarmonyPatch(typeof(Item), "OnTriggerEnter")]
class MPNoDupes_OnTriggerEnter {
public static bool Prefix(Item __instance) {
return __instance.m_type != ItemType.NONE;
}

public static void SetItemTypeToNoneAndDestroy(Item item) {
item.m_type = ItemType.NONE;
UnityEngine.Object.Destroy(item.c_go);
}

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes) {
var ldfldCount = 0;

foreach (var code in codes) {
if (code.opcode == OpCodes.Ldfld) {
ldfldCount++;

if (ldfldCount == 39) {
continue;
}
}

if (code.opcode == OpCodes.Call && ((MethodInfo)code.operand).Name == "Destroy") {
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(MPNoDupes_OnTriggerEnter), "SetItemTypeToNoneAndDestroy"));
continue;
}

yield return code;
}
}
}
}

0 comments on commit 6e28088

Please sign in to comment.