/
MercCore.cs
102 lines (93 loc) · 3.41 KB
/
MercCore.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using UnityEngine;
using RoR2;
using BepInEx.Configuration;
using MonoMod.Cil;
using Mono.Cecil.Cil;
using System;
using System.Linq;
using System.Collections.Generic;
namespace RiskyMod.Survivors.Merc
{
public class MercCore
{
public static bool enabled = true;
public static bool evisTargetingFix = true;
public static bool modifyStats = true;
public static ConfigEntry<bool> m1ComboFinishTweak;
public static GameObject bodyPrefab = LegacyResourcesAPI.Load<GameObject>("Prefabs/CharacterBodies/MercBody");
public MercCore()
{
if (!enabled) return;
ModifyStats(bodyPrefab.GetComponent<CharacterBody>());
ModifySkills(bodyPrefab.GetComponent<SkillLocator>());
}
private void ModifySkills(SkillLocator sk)
{
ModifyPrimaries(sk);
ModifySpecials(sk);
}
private void ModifyPrimaries(SkillLocator sk)
{
On.EntityStates.Merc.Weapon.GroundLight2.OnEnter += (orig, self) =>
{
if (m1ComboFinishTweak.Value)
{
if (self.isComboFinisher)
{
self.ignoreAttackSpeed = true;
}
else
{
self.ignoreAttackSpeed = false;
}
}
orig(self);
};
}
private void ModifySpecials(SkillLocator sk)
{
if (evisTargetingFix)
{
IL.EntityStates.Merc.EvisDash.FixedUpdate += (il) =>
{
ILCursor c = new ILCursor(il);
if (c.TryGotoNext(MoveType.After,
x => x.MatchCall<Physics>("OverlapSphere")
))
{
c.Emit(OpCodes.Ldarg_0);//self
c.EmitDelegate<Func<Collider[], EntityStates.Merc.EvisDash, Collider[]>>((colliders, self) =>
{
if (FriendlyFireManager.friendlyFireMode != FriendlyFireManager.FriendlyFireMode.Off) return colliders;
//This is inefficient
List<Collider> enemyHurtboxes = new List<Collider>();
foreach (Collider cl in colliders)
{
HurtBox hb = cl.GetComponent<HurtBox>();
if (hb && hb.healthComponent != self.healthComponent)
{
if(hb.teamIndex != self.GetTeam())
{
enemyHurtboxes.Add(cl);
}
}
}
//Re-order list so that friendly hurtboxes are at the end
return enemyHurtboxes.ToArray();
});
}
else
{
Debug.LogError("RiskyMod: Merc EvisDash IL Hook failed");
}
};
}
}
private void ModifyStats(CharacterBody cb)
{
if (!modifyStats) return;
cb.baseRegen = 2.5f;
cb.levelRegen = 0.5f;
}
}
}