@@ -45,6 +45,8 @@ public static void Load() {
4545 IL . Celeste . StrawberriesCounter . Render += ModStrawberriesCounterRender ;
4646 On . Celeste . MapData . Load += ModMapDataLoad ;
4747 On . Celeste . OuiChapterPanel . Start += OnOuiChapterPanelStart ;
48+ On . Celeste . Player . Die += OnPlayerDie ;
49+ On . Celeste . Mod . AssetReloadHelper . ReloadLevel += OnReloadLevel ;
4850 }
4951
5052 public static void Unload ( ) {
@@ -63,6 +65,8 @@ public static void Unload() {
6365 IL . Celeste . StrawberriesCounter . Render -= ModStrawberriesCounterRender ;
6466 On . Celeste . MapData . Load -= ModMapDataLoad ;
6567 On . Celeste . OuiChapterPanel . Start -= OnOuiChapterPanelStart ;
68+ On . Celeste . Player . Die -= OnPlayerDie ;
69+ On . Celeste . Mod . AssetReloadHelper . ReloadLevel -= OnReloadLevel ;
6670 }
6771
6872 private static void OnOuiChapterPanelStart ( On . Celeste . OuiChapterPanel . orig_Start orig , OuiChapterPanel self , string checkpoint ) {
@@ -77,6 +81,35 @@ private static void OnPause(Level level, int startIndex, bool minimal, bool quic
7781 if ( overworldWrapper != null ) {
7882 Close ( level , true , true ) ;
7983 }
84+ }
85+
86+ private static PlayerDeadBody OnPlayerDie ( On . Celeste . Player . orig_Die orig , Player self , Vector2 direction , bool evenIfInvincible , bool registerDeathInStats ) {
87+ PlayerDeadBody result = orig ( self , direction , evenIfInvincible , registerDeathInStats ) ;
88+ if ( result != null && self . Scene is Level level && overworldWrapper != null ) {
89+ // the player died, so we should close the "in-game overworld" before weird stuff happens.
90+ Close ( level , true , true ) ;
91+ }
92+ return result ;
93+ }
94+
95+ private static void OnReloadLevel ( On . Celeste . Mod . AssetReloadHelper . orig_ReloadLevel orig ) {
96+ if ( overworldWrapper != null ) {
97+ Level level = Engine . Scene as Level ;
98+ if ( level == null ) {
99+ level = AssetReloadHelper . ReturnToScene as Level ;
100+ }
101+
102+ if ( level != null ) {
103+ // the level is about to get reloaded: make sure to unlock player movement if it is locked.
104+ // (no need to close the in-game overworld, the reload will do that for us.)
105+ Player player = level . Tracker . GetEntity < Player > ( ) ;
106+ if ( player != null && player . StateMachine . State == Player . StDummy ) {
107+ player . StateMachine . State = Player . StNormal ;
108+ }
109+ }
110+ }
111+
112+ orig ( ) ;
80113 }
81114
82115 private static bool OnSetMusic ( On . Celeste . Audio . orig_SetMusic orig , string path , bool startPlaying , bool allowFadeOut ) {
0 commit comments