-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpringCollab2020Module.cs
150 lines (129 loc) · 5.98 KB
/
SpringCollab2020Module.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
138
139
140
141
142
143
144
145
146
147
148
149
150
using Celeste.Mod.SpringCollab2020.Effects;
using Celeste.Mod.SpringCollab2020.Entities;
using Celeste.Mod.SpringCollab2020.Triggers;
using Microsoft.Xna.Framework;
using Mono.Cecil.Cil;
using Monocle;
using MonoMod.Cil;
using System;
namespace Celeste.Mod.SpringCollab2020 {
public class SpringCollab2020Module : EverestModule {
public static SpringCollab2020Module Instance;
public override Type SaveDataType => typeof(SpringCollab2020SaveData);
public SpringCollab2020SaveData SaveData => (SpringCollab2020SaveData) _SaveData;
public override Type SessionType => typeof(SpringCollab2020Session);
public SpringCollab2020Session Session => (SpringCollab2020Session) _Session;
public SpringCollab2020Module() {
Instance = this;
}
public override void Load() {
Logger.SetLogLevel("SpringCollab2020", LogLevel.Info);
NoRefillField.Load();
FloatierSpaceBlock.Load();
MoveBlockBarrier.Load();
MoveBlockBarrierRenderer.Load();
RemoveLightSourcesTrigger.Load();
SafeRespawnCrumble.Load();
UpsideDownJumpThru.Load();
BubbleReturnBerry.Load();
SidewaysJumpThru.Load();
CrystalBombDetonatorRenderer.Load();
FlagTouchSwitch.Load();
DisableIcePhysicsTrigger.Load();
MultiRoomStrawberrySeed.Load();
MadelineSilhouetteTrigger.Load();
BlockJellySpawnTrigger.Load();
StrawberryIgnoringLighting.Load();
SeekerCustomColors.Load();
CameraCatchupSpeedTrigger.Load();
ColorGradeFadeTrigger.Load();
SpeedBasedMusicParamTrigger.Load();
StaticPuffer.Load();
LeaveTheoBehindTrigger.Load();
BadelineBounceDirectionTrigger.Load();
SpikeJumpThroughController.Load();
Everest.Events.Level.OnLoadBackdrop += onLoadBackdrop;
GrandmasterHeartSideHelper.Load();
IL.Celeste.Level.Reload += resetFlagsOnTimerResets;
DecalRegistry.AddPropertyHandler("SpringCollab2020_scale", (decal, attrs) => {
Vector2 scale = decal.Scale;
if (attrs["multiply"] != null) {
scale *= float.Parse(attrs["multiply"].Value);
}
if (attrs["divide"] != null) {
scale /= float.Parse(attrs["divide"].Value);
}
decal.Scale = scale;
});
}
public override void LoadContent(bool firstLoad) {
base.LoadContent(firstLoad);
GlassBerry.LoadContent();
StrawberryIgnoringLighting.LoadContent();
}
public override void Unload() {
NoRefillField.Unload();
FloatierSpaceBlock.Unload();
MoveBlockBarrier.Unload();
MoveBlockBarrierRenderer.Unload();
RemoveLightSourcesTrigger.Unload();
SafeRespawnCrumble.Unload();
GlassBerry.Unload();
UpsideDownJumpThru.Unload();
BubbleReturnBerry.Unload();
SidewaysJumpThru.Unload();
CrystalBombDetonatorRenderer.Unload();
FlagTouchSwitch.Unload();
DisableIcePhysicsTrigger.Unload();
MultiRoomStrawberrySeed.Unload();
MadelineSilhouetteTrigger.Unload();
BlockJellySpawnTrigger.Unload();
StrawberryIgnoringLighting.Unload();
SeekerCustomColors.Unload();
CameraCatchupSpeedTrigger.Unload();
ColorGradeFadeTrigger.Unload();
SpeedBasedMusicParamTrigger.Unload();
StaticPuffer.Unload();
LeaveTheoBehindTrigger.Unload();
BadelineBounceDirectionTrigger.Unload();
SpikeJumpThroughController.Unload();
Everest.Events.Level.OnLoadBackdrop -= onLoadBackdrop;
GrandmasterHeartSideHelper.Unload();
IL.Celeste.Level.Reload -= resetFlagsOnTimerResets;
}
private Backdrop onLoadBackdrop(MapData map, BinaryPacker.Element child, BinaryPacker.Element above) {
if (child.Name.Equals("SpringCollab2020/HeatWaveNoColorGrade", StringComparison.OrdinalIgnoreCase)) {
return new HeatWaveNoColorGrade();
}
if (child.Name.Equals("SpringCollab2020/CustomSnow", StringComparison.OrdinalIgnoreCase)) {
string[] colorsAsStrings = child.Attr("colors").Split(',');
Color[] colors = new Color[colorsAsStrings.Length];
for (int i = 0; i < colors.Length; i++) {
colors[i] = Calc.HexToColor(colorsAsStrings[i]);
}
return new CustomSnow(colors, child.AttrBool("foreground"));
}
if (child.Name.Equals("SpringCollab2020/BlackholeCustomColors", StringComparison.OrdinalIgnoreCase)) {
return BlackholeCustomColors.CreateBlackholeWithCustomColors(child);
}
return null;
}
public override void PrepareMapDataProcessors(MapDataFixup context) {
base.PrepareMapDataProcessors(context);
context.Add<SpringCollab2020MapDataProcessor>();
}
private void resetFlagsOnTimerResets(ILContext il) {
ILCursor cursor = new ILCursor(il);
if (cursor.TryGotoNext(MoveType.After, instr => instr.MatchStfld<Level>("TimerStarted"))) {
Logger.Log("SpringCollab2020", $"Injecting call to reset flags along with timer at {cursor.Index} in IL for Level.Reload");
cursor.Emit(OpCodes.Ldarg_0);
cursor.EmitDelegate<Action<Level>>(self => {
if (self.Session.Area.GetSID().StartsWith("SpringCollab2020/")) {
Logger.Log(LogLevel.Debug, "SpringCollab2020", "Resetting session flags along with chapter timer");
self.Session.Flags.Clear();
}
});
}
}
}
}