22using Celeste . Mod . SpringCollab2020 . Entities ;
33using Celeste . Mod . SpringCollab2020 . Triggers ;
44using Microsoft . Xna . Framework ;
5+ using Mono . Cecil . Cil ;
56using Monocle ;
7+ using MonoMod . Cil ;
68using System ;
79
810namespace 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