Skip to content

Commit 8705690

Browse files
authored
Merge pull request #1063 from SilverDorian46/ice-tile-overlay-map-metadata
Add `CoreModeIceTileOverlay` map metadata property
2 parents 50fafd1 + 06465b9 commit 8705690

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Celeste.Mod.mm/Mod/Meta/MapMeta.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ public MapMetaModeProperties(BinaryPacker.Element meta) {
336336
public bool? HeartIsEnd { get; set; }
337337
public bool? SeekerSlowdown { get; set; }
338338
public bool? TheoInBubble { get; set; }
339+
public bool? CoreModeIceTileOverlay { get; set; }
339340

340341
public patch_ModeProperties Convert()
341342
=> new patch_ModeProperties() {
@@ -356,6 +357,7 @@ public void Parse(BinaryPacker.Element meta) {
356357
meta.AttrIfBool("HeartIsEnd", v => HeartIsEnd = v);
357358
meta.AttrIfBool("SeekerSlowdown", v => SeekerSlowdown = v);
358359
meta.AttrIfBool("TheoInBubble", v => TheoInBubble = v);
360+
meta.AttrIfBool("CoreModeIceTileOverlay", v => CoreModeIceTileOverlay = v);
359361

360362
BinaryPacker.Element child;
361363

Celeste.Mod.mm/Patches/LevelLoader.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)