forked from M3TO/GizmoReloaded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdatePlacementGhost_Patch.cs
39 lines (35 loc) · 1.36 KB
/
UpdatePlacementGhost_Patch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using HarmonyLib;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
namespace GizmoReloaded
{
[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
public static class UpdatePlacementGhost_Patch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var placementAnglePatched = false;
var codes = new List<CodeInstruction>(instructions);
for (var i = 0; i < codes.Count; i++)
{
if(!placementAnglePatched)
if (codes[i].opcode == OpCodes.Callvirt &&
codes[i + 1].opcode == OpCodes.Ldc_R4 &&
codes[i + 2].opcode == OpCodes.Ldc_R4 &&
codes[i + 3].opcode == OpCodes.Ldarg_0 &&
codes[i + 4].opcode == OpCodes.Ldfld &&
codes[i + 5].opcode == OpCodes.Conv_R4 &&
codes[i + 6].opcode == OpCodes.Mul &&
codes[i + 7].opcode == OpCodes.Ldc_R4 &&
codes[i + 8].opcode == OpCodes.Call
)
{
codes[i + 8] = CodeInstruction.Call(typeof(Plugin), "GetPlacementAngle");
placementAnglePatched = true;
}
}
return codes.AsEnumerable();
}
}
}