-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathPlayer_OnKill_Patch.cs
More file actions
44 lines (39 loc) · 1.4 KB
/
Player_OnKill_Patch.cs
File metadata and controls
44 lines (39 loc) · 1.4 KB
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
40
41
42
43
44
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using NitroxModel.Helper;
namespace NitroxPatcher.Patches.Dynamic;
public sealed partial class Player_OnKill_Patch : NitroxPatch, IDynamicPatch
{
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Player t) => t.OnKill(default(DamageType)));
private static readonly MethodInfo SKIP_METHOD = Reflect.Method(() => GameModeUtils.IsPermadeath());
public static IEnumerable<CodeInstruction> Transpiler(MethodBase original, IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> instructionList = instructions.ToList();
/**
* Skips
* if (GameModeUtils.IsPermadeath())
* {
* SaveLoadManager.main.ClearSlotAsync(SaveLoadManager.main.GetCurrentSlot());
* this.EndGame();
* return;
* }
*/
for (int i = 0; i < instructionList.Count; i++)
{
CodeInstruction instr = instructionList[i];
if (instr.opcode == OpCodes.Call && instr.operand.Equals(SKIP_METHOD))
{
CodeInstruction newInstr = new(OpCodes.Ldc_I4_0);
newInstr.labels = instr.labels;
yield return newInstr;
}
else
{
yield return instr;
}
}
}
}