@@ -21,9 +21,48 @@ class UpsideDownJumpThru : JumpThru {
2121
2222 private static ILHook playerOrigUpdateHook ;
2323
24- private static readonly Hitbox normalHitbox = new Hitbox ( 8f , 11f , - 4f , - 11f ) ;
24+ private static bool hooksActive = false ;
2525
26+ private static readonly Hitbox normalHitbox = new Hitbox ( 8f , 11f , - 4f , - 11f ) ;
27+
2628 public static void Load ( ) {
29+ On . Celeste . LevelLoader . ctor += onLevelLoad ;
30+ On . Celeste . OverworldLoader . ctor += onOverworldLoad ;
31+ }
32+
33+ public static void Unload ( ) {
34+ On . Celeste . LevelLoader . ctor -= onLevelLoad ;
35+ On . Celeste . OverworldLoader . ctor -= onOverworldLoad ;
36+ deactivateHooks ( ) ;
37+ }
38+
39+ private static void onLevelLoad ( On . Celeste . LevelLoader . orig_ctor orig , LevelLoader self , Session session , Vector2 ? startPosition ) {
40+ orig ( self , session , startPosition ) ;
41+
42+ if ( session . MapData ? . Levels ? . Any ( level => level . Entities ? . Any ( entity => entity . Name == "SpringCollab2020/UpsideDownJumpThru" ) ?? false ) ?? false ) {
43+ activateHooks ( ) ;
44+ } else {
45+ deactivateHooks ( ) ;
46+ }
47+ }
48+
49+ private static void onOverworldLoad ( On . Celeste . OverworldLoader . orig_ctor orig , OverworldLoader self , Overworld . StartMode startMode , HiresSnow snow ) {
50+ orig ( self , startMode , snow ) ;
51+
52+ if ( startMode != ( Overworld . StartMode ) ( - 1 ) ) { // -1 = in-game overworld from the collab utils
53+ deactivateHooks ( ) ;
54+ }
55+ }
56+
57+
58+ public static void activateHooks ( ) {
59+ if ( hooksActive ) {
60+ return ;
61+ }
62+ hooksActive = true ;
63+
64+ Logger . Log ( LogLevel . Info , "SpringCollab2020/UpsideDownJumpThru" , "=== Activating upside-down jumpthru hooks" ) ;
65+
2766 using ( new DetourContext { Before = { "*" } } ) { // these don't always call the orig methods, better apply them first.
2867 // fix general actor/platform behavior to make them comply with jumpthrus.
2968 On . Celeste . Actor . MoveVExact += onActorMoveVExact ;
@@ -50,7 +89,14 @@ public static void Load() {
5089 }
5190 }
5291
53- public static void Unload ( ) {
92+ public static void deactivateHooks ( ) {
93+ if ( ! hooksActive ) {
94+ return ;
95+ }
96+ hooksActive = false ;
97+
98+ Logger . Log ( LogLevel . Info , "SpringCollab2020/UpsideDownJumpThru" , "=== Deactivating upside-down jumpthru hooks" ) ;
99+
54100 On . Celeste . Actor . MoveVExact -= onActorMoveVExact ;
55101 On . Celeste . Platform . MoveVExactCollideSolids -= onPlatformMoveVExactCollideSolids ;
56102
0 commit comments