-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDecreasedFallDamage_Patch.cs
More file actions
79 lines (68 loc) · 2.42 KB
/
DecreasedFallDamage_Patch.cs
File metadata and controls
79 lines (68 loc) · 2.42 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using HarmonyLib;
using UnityEngine;
namespace Decreased_Fall_Damage
{
// Token: 0x02000002 RID: 2
[HarmonyPatch(typeof(Character))]
public static class DecreasedFallDamage_Patch
{
// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
[HarmonyPatch("UpdateGroundContact")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> UpdateGroundContact(IEnumerable<CodeInstruction> instructions)
{
bool patch1_done = false;
bool patch2_done = false;
List<CodeInstruction> list = instructions.ToList<CodeInstruction>();
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_R4 && object.Equals(list[i].operand, 100f) && !patch1_done)
{
list[i] = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DecreasedFallDamage_Patch), "GetMaxFallDamage", null, null));
patch1_done = true;
#if DEBUG
DecreasedFallDamage.Logger.LogWarning("[DEBUG] Patching " + list[i].ToString());
#endif
}
else if (
list[i].opcode == OpCodes.Ldloc_0 &&
list[i + 1].opcode == OpCodes.Ldc_R4 &&
object.Equals(list[i + 1].operand, 4f) &&
!patch2_done)
{
list[i + 1] = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DecreasedFallDamage_Patch), "GetMinFallHeight", null, null));
patch2_done = true;
#if DEBUG
DecreasedFallDamage.Logger.LogWarning("[DEBUG] Patching " + list[i + 1].ToString());
#endif
}
}
return list;
}
// Token: 0x06000002 RID: 2 RVA: 0x000020E8 File Offset: 0x000002E8
private static float GetMaxFallDamage()
{
if(Configuration.skillMode)
{
float jumpSkill = Player.m_localPlayer.GetSkills().GetSkill(Skills.SkillType.Jump).m_level;
float newFallDamage = Configuration.fallDamage - jumpSkill;
if(newFallDamage < 0)
{
newFallDamage = 0;
}
DecreasedFallDamage.Logger.LogInfo("Player fall damage reduced by " + jumpSkill.ToString() + "%" + Environment.NewLine);
return newFallDamage;
}
DecreasedFallDamage.Logger.LogInfo("Player fall damage reduced by " + (100 - Configuration.fallDamage) + "%" + Environment.NewLine);
return Configuration.fallDamage;
}
private static float GetMinFallHeight()
{
return Configuration.minFallHeight;
}
}
}