-
Notifications
You must be signed in to change notification settings - Fork 3
/
DoonvHelperModule.cs
137 lines (119 loc) · 4.06 KB
/
DoonvHelperModule.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using Guneline;
using MonoMod.RuntimeDetour;
using Celeste.Mod.DoonvHelper.Entities;
using System.Reflection;
using MonoMod.Utils;
using Celeste.Mod.DoonvHelper.DoonvHelperUtils;
using MonoMod.ModInterop;
namespace Celeste.Mod.DoonvHelper;
public class DoonvHelperModule : EverestModule
{
public static DoonvHelperModule Instance { get; private set; }
public override Type SettingsType => typeof(DoonvHelperModuleSettings);
public static DoonvHelperModuleSettings Settings => (DoonvHelperModuleSettings)Instance._Settings;
public override Type SessionType => typeof(DoonvHelperModuleSession);
public static DoonvHelperModuleSession Session => (DoonvHelperModuleSession)Instance._Session;
public override Type SaveDataType => typeof(DoonvHelperSaveData);
public static DoonvHelperSaveData SaveData => (DoonvHelperSaveData)Instance._SaveData;
private ComfCounterInChapterPanel chapterPanel;
private Dictionary<LevelSideID, int> comfLevelTotals = new Dictionary<LevelSideID, int>();
public static Dictionary<LevelSideID, int> ComfLevelTotals => Instance.comfLevelTotals;
private LuaCutscenes.LuaCutscenesMod luaCutscenesModule = null;
internal static LuaCutscenes.LuaCutscenesMod LuaCutscenesModule => Instance.luaCutscenesModule;
private Type xaphanLiquid = null;
internal static Type XaphanLiquid => Instance.xaphanLiquid;
[ModImportName("FrostHelper")]
public static class FrostHelperImports
{
public static Func<string, Type> EntityNameToType;
}
public DoonvHelperModule()
{
Instance = this;
chapterPanel = new ComfCounterInChapterPanel();
#if DEBUG
// Debug Builds log any level of logging.
Logger.SetLogLevel("DoonvHelper", LogLevel.Verbose);
#else
// Release builds only log log levels higher or equal to `LogLevel.Info`.
Logger.SetLogLevel("DoonvHelper", LogLevel.Info);
#endif
}
private Hook gunelineHook;
public override void Load()
{
typeof(FrostHelperImports).ModInterop();
On.Celeste.Level.Begin += ModLevelBegin;
if (Everest.Loader.DependencyLoaded(new()
{
Name = "Guneline",
Version = new Version(1, 0, 0)
}))
{
HookGuneline();
}
if (Everest.Loader.TryGetDependency(new()
{
Name = "LuaCutscenes",
Version = new Version(0, 2, 7)
}, out EverestModule luaModule))
{
this.luaCutscenesModule = (LuaCutscenes.LuaCutscenesMod)luaModule;
}
if (Everest.Loader.TryGetDependency(new()
{
Name = "XaphanHelper",
Version = new Version(1, 0, 54)
}, out EverestModule xaphanModule))
{
this.xaphanLiquid = xaphanModule.GetType().Assembly
.GetType("Celeste.Mod.XaphanHelper.Entities.Liquid");
}
chapterPanel.HookMethods();
}
/// <summary> TODO: Remove this when Guneline 2 comes out </summary>
private void HookGuneline()
{
gunelineHook = new Hook(
typeof(Guneline.Bullet).GetMethod("CollisionCheck", BindingFlags.NonPublic | BindingFlags.Instance),
modGunelineBulletCollisionCheck
);
}
/// <summary> TODO: Remove this when Guneline 2 comes out </summary>
private void modGunelineBulletCollisionCheck(Action<Bullet> orig, Guneline.Bullet bullet)
{
DynamicData bulletData = DynamicData.For(bullet);
CustomNPC enemy = bulletData.Get<Actor>("owner").Scene.CollideFirst<CustomNPC>(bullet.Hitbox);
if (enemy is not null && !bulletData.Get<bool>("dead"))
{
enemy.Kill();
bulletData.Invoke("Kill");
return;
}
orig(bullet);
}
public override void Unload()
{
On.Celeste.Level.Begin -= ModLevelBegin;
gunelineHook?.Dispose();
chapterPanel.UnhookMethods();
}
public override void PrepareMapDataProcessors(MapDataFixup context)
{
context.Add<DoonvHelperMapDataProcessor>();
}
/// <summary>
/// This is a hook that overrides the `Level.Begin` method.
/// </summary>
private void ModLevelBegin(On.Celeste.Level.orig_Begin orig, Level level)
{
orig(level); // Call original method that we have overriden so we maintain the original functionality.
if (ComfLevelTotals.SafeGet(new LevelSideID(level)) > 0)
{
// Add the In-game comf display so we can see our comf counter in game.
level.Add(new Entities.ComfInGameDisplay());
}
}
}