Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent a powerup being picked up by 2 pilots at the same time.
Fixes #81.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} |