@@ -250,6 +250,7 @@ private XmlDocument getModdedSpritesXml(string path) {
250250 [ MonoModIgnore ] // We don't want to change anything about the method...
251251 [ PatchLoadingThreadAddEvent ] // ... except for manually manipulating the method via MonoModRules
252252 [ PatchLoadingThreadAddSubHudRenderer ]
253+ [ PatchLoadingThreadForMapMetadata ]
253254 private extern void LoadingThread ( ) ;
254255
255256 private void LoadingThread_Safe ( ) {
@@ -325,6 +326,9 @@ public override void Update() {
325326 }
326327 }
327328
329+ private static bool _ShouldAddIceTileOverlay ( MapData mapData )
330+ => ( ( patch_MapData ) mapData ) . Meta ? . CoreModeIceTileOverlay ?? false ;
331+
328332 }
329333}
330334
@@ -366,6 +370,12 @@ class PatchLoadingThreadAddSubHudRendererAttribute : Attribute { }
366370 [ MonoModCustomMethodAttribute ( nameof ( MonoModRules . PatchLoadingThreadAddEvent ) ) ]
367371 class PatchLoadingThreadAddEventAttribute : Attribute { }
368372
373+ /// <summary>
374+ /// Handles map metadata properties in some places throughout the loading thread.
375+ /// </summary>
376+ [ MonoModCustomMethodAttribute ( nameof ( MonoModRules . PatchLoadingThreadForMapMetadata ) ) ]
377+ class PatchLoadingThreadForMapMetadataAttribute : Attribute { }
378+
369379 static partial class MonoModRules {
370380
371381 public static void PatchLevelLoaderOrigCtor ( ILContext context , CustomAttribute attrib ) {
@@ -431,5 +441,40 @@ public static void PatchLoadingThreadAddEvent(ILContext context, CustomAttribute
431441 cursor . Emit ( OpCodes . Call , m_Everest_Events_LevelLoader_LoadingThread ) ;
432442 }
433443
444+ public static void PatchLoadingThreadForMapMetadata ( ILContext context , CustomAttribute attrib ) {
445+ MethodDefinition m_shouldAddIceTileOverlay = context . Method . DeclaringType . FindMethod ( "_ShouldAddIceTileOverlay" ) ;
446+
447+ ILCursor cursor = new ( context ) ;
448+
449+ // first, get the local for MapData
450+ int loc_mapData = - 1 ;
451+ cursor . GotoNext (
452+ instr => instr . MatchCallvirt ( "Celeste.Session" , "get_MapData" ) ,
453+ instr => instr . MatchStloc ( out loc_mapData )
454+ ) ;
455+
456+ /*
457+ now let's change this bit of code
458+ if (session.Area.ID == 9) { ... }
459+ to this
460+ if (session.Area.ID == 9 || _ShouldAddIceTileOverlay(mapData)) { ... }
461+ */
462+ ILLabel addIceTileOverlaybel = cursor . DefineLabel ( ) ;
463+ ILLabel branchOutLabel = null ;
464+ cursor . GotoNext ( instr => instr . MatchLdcI4 ( 9 ) ) ;
465+ cursor . GotoNext ( MoveType . Before , instr => instr . MatchBneUn ( out branchOutLabel ) ) ;
466+
467+ // for simplicity, we'll remove the bne.un.s, and replace it with a different branch instruction
468+ cursor . Remove ( ) ;
469+
470+ cursor . Emit ( OpCodes . Beq_S , addIceTileOverlaybel ) ; // beq.s <=> bne.un.s
471+
472+ cursor . EmitLdloc ( loc_mapData ) ;
473+ cursor . Emit ( OpCodes . Call , m_shouldAddIceTileOverlay ) ;
474+ cursor . Emit ( OpCodes . Brfalse_S , branchOutLabel ) ;
475+
476+ cursor . MarkLabel ( addIceTileOverlaybel ) ;
477+ }
478+
434479 }
435480}
0 commit comments