Skip to content

Commit 910500c

Browse files
committed
Reset session flags when chapter timer is reset due to dying in the first room in a collab map
1 parent aae2f70 commit 910500c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

SpringCollab2020Module.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using Celeste.Mod.SpringCollab2020.Entities;
33
using Celeste.Mod.SpringCollab2020.Triggers;
44
using Microsoft.Xna.Framework;
5+
using Mono.Cecil.Cil;
56
using Monocle;
7+
using MonoMod.Cil;
68
using System;
79

810
namespace Celeste.Mod.SpringCollab2020 {
@@ -49,6 +51,8 @@ public override void Load() {
4951
WaterRocketLaunchingComponent.Load();
5052
Everest.Events.Level.OnLoadBackdrop += onLoadBackdrop;
5153

54+
IL.Celeste.Level.Reload += resetFlagsOnTimerResets;
55+
5256
DecalRegistry.AddPropertyHandler("scale", (decal, attrs) => {
5357
Vector2 scale = decal.Scale;
5458
if (attrs["multiply"] != null) {
@@ -94,6 +98,8 @@ public override void Unload() {
9498
BadelineBounceDirectionTrigger.Unload();
9599
WaterRocketLaunchingComponent.Unload();
96100
Everest.Events.Level.OnLoadBackdrop -= onLoadBackdrop;
101+
102+
IL.Celeste.Level.Reload -= resetFlagsOnTimerResets;
97103
}
98104

99105
private Backdrop onLoadBackdrop(MapData map, BinaryPacker.Element child, BinaryPacker.Element above) {
@@ -117,5 +123,21 @@ public override void PrepareMapDataProcessors(MapDataFixup context) {
117123

118124
context.Add<SpringCollab2020MapDataProcessor>();
119125
}
126+
127+
private void resetFlagsOnTimerResets(ILContext il) {
128+
ILCursor cursor = new ILCursor(il);
129+
130+
if (cursor.TryGotoNext(MoveType.After, instr => instr.MatchStfld<Level>("TimerStarted"))) {
131+
Logger.Log("SpringCollab2020", $"Injecting call to reset flags along with timer at {cursor.Index} in IL for Level.Reload");
132+
133+
cursor.Emit(OpCodes.Ldarg_0);
134+
cursor.EmitDelegate<Action<Level>>(self => {
135+
if (self.Session.Area.GetSID().StartsWith("SpringCollab2020/")) {
136+
Logger.Log(LogLevel.Debug, "SpringCollab2020", "Resetting session flags along with chapter timer");
137+
self.Session.Flags.Clear();
138+
}
139+
});
140+
}
141+
}
120142
}
121143
}

0 commit comments

Comments
 (0)