forked from SalehAce1/FuryAlwaysOn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuryAlwaysOn.cs
53 lines (44 loc) · 1.64 KB
/
FuryAlwaysOn.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
using Modding;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using USceneManager = UnityEngine.SceneManagement.SceneManager;
using UObject = UnityEngine.Object;
namespace FuryAlwaysOn
{
public class FuryAlwaysOn : Mod, ITogglableMod
{
internal static FuryAlwaysOn instance;
public override string GetVersion() => GetType().Assembly.GetName().Version.ToString();
public override void Initialize()
{
instance = this;
Log("Initializing.");
Unload(); // Ensures two instances of this mod are not working at the same time
ModHooks.AfterSavegameLoadHook += AfterSaveGameLoad; // Runs when a save file is chosen
ModHooks.NewGameHook += AddComponent;
IL.KnightHatchling.OnEnable += ChangeGlowingWombFuryCondition;
}
private static void ChangeGlowingWombFuryCondition(ILContext il)
{
ILCursor cursor = new ILCursor(il).Goto(0);
if (cursor.TryGotoNext(MoveType.After, i => i.MatchCallvirt<PlayerData>("GetInt")))
{
Logger.Log("LdcI4 was found");
cursor.Emit(OpCodes.Pop);
cursor.Emit(OpCodes.Ldc_I4_1);
}
}
private void AfterSaveGameLoad(SaveGameData data) => AddComponent();
private void AddComponent() => GameManager.instance.gameObject.AddComponent<EffectFixer>(); // Begins class EffectFixer when a new save file loads
public void Unload()
{
ModHooks.AfterSavegameLoadHook -= AfterSaveGameLoad;
ModHooks.NewGameHook -= AddComponent;
IL.KnightHatchling.OnEnable -= ChangeGlowingWombFuryCondition;
var x = GameManager.instance.gameObject.GetComponent<EffectFixer>();
if (x == null)
return;
UObject.Destroy(x);
}
}
}