Skip to content

Commit 6009dbc

Browse files
Merge pull request #949 from SnipUndercover/fix-banner-rotation
2 parents 04c0cd4 + d2b4c35 commit 6009dbc

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

Celeste.Mod.mm/Patches/Decal.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public patch_Banner()
6565

6666
[MonoModIgnore]
6767
[PatchDecalImageRender]
68+
[PatchBannerRotation]
6869
public extern override void Render();
6970

7071
}
@@ -300,10 +301,10 @@ public override void Added(Scene scene) {
300301

301302
if (!DecalRegistry.RegisteredDecals.TryGetValue(text, out DecalRegistry.DecalInfo info))
302303
return;
303-
304+
304305
Remove(image);
305306
image = null;
306-
307+
307308
// apply all decal registry handlers.
308309
foreach (var handler in info.Handlers) {
309310
try {
@@ -363,6 +364,12 @@ class PatchDecalUpdateAttribute : Attribute { }
363364
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchDecalImageRender))]
364365
class PatchDecalImageRenderAttribute : Attribute { }
365366

367+
/// <summary>
368+
/// Make "Banner" decal slices respect the decal's rotation.
369+
/// </summary>
370+
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchBannerRotation))]
371+
class PatchBannerRotationAttribute : Attribute { }
372+
366373
/// <summary>
367374
/// Allow mirror masks to be rotated.
368375
/// </summary>
@@ -464,5 +471,25 @@ public static void PatchMirrorMaskRotation(ILContext context, CustomAttribute at
464471
cursor.Remove();
465472
});
466473
}
474+
475+
public static void PatchBannerRotation(ILContext context, CustomAttribute attrib) {
476+
MethodDefinition m_Rotate = MonoModRule.Modder.FindType("Monocle.Calc").Resolve()
477+
.FindMethod("Microsoft.Xna.Framework.Vector2 Rotate(Microsoft.Xna.Framework.Vector2,System.Single)");
478+
FieldDefinition f_Decal_Rotation = MonoModRule.Modder.FindType("Celeste.Decal").Resolve()
479+
.FindField("Rotation");
480+
PropertyDefinition p_Decal = context.Method.DeclaringType
481+
.FindProperty("Decal");
482+
483+
ILCursor cursor = new ILCursor(context);
484+
485+
// we want to attach a .Rotate(Decal.Rotation) to the new vector like so:
486+
// Decal.Position + new Vector2(x, 0).Rotate(Decal.Rotation)
487+
488+
cursor.GotoNext(MoveType.After, static instr => instr.MatchNewobj("Microsoft.Xna.Framework.Vector2"));
489+
cursor.EmitLdarg0();
490+
cursor.EmitCallvirt(p_Decal.GetMethod);
491+
cursor.EmitLdfld(f_Decal_Rotation);
492+
cursor.EmitCall(m_Rotate);
493+
}
467494
}
468495
}

0 commit comments

Comments
 (0)