From 85b5e5628baffc6665f937e9e099f1ce7aea3acc Mon Sep 17 00:00:00 2001 From: coloursofnoise Date: Fri, 14 Jan 2022 13:54:29 -0800 Subject: [PATCH 1/4] Use MonoModLinkTo for base.base. calls --- Celeste.Mod.mm/Patches/BounceBlock.cs | 18 +++++++++--------- Celeste.Mod.mm/Patches/Checkpoint.cs | 13 +++++++++++-- Celeste.Mod.mm/Patches/InputMappingInfo.cs | 1 + Celeste.Mod.mm/Patches/IntroCrusher.cs | 15 ++++++--------- Celeste.Mod.mm/Patches/LevelEnter.cs | 1 + Celeste.Mod.mm/Patches/RotateSpinner.cs | 15 +++++++++------ Celeste.Mod.mm/Patches/StarJumpBlock.cs | 13 +++++++++---- 7 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Celeste.Mod.mm/Patches/BounceBlock.cs b/Celeste.Mod.mm/Patches/BounceBlock.cs index ad82f5721..34a8a3a87 100644 --- a/Celeste.Mod.mm/Patches/BounceBlock.cs +++ b/Celeste.Mod.mm/Patches/BounceBlock.cs @@ -6,7 +6,7 @@ namespace Celeste { // : Solid because base.Added - class patch_BounceBlock : Solid { + class patch_BounceBlock : BounceBlock { // We're effectively in BounceBlock, but still need to "expose" private fields to our mod. private bool iceMode; @@ -14,19 +14,19 @@ class patch_BounceBlock : Solid { private bool notCoreMode; - public patch_BounceBlock(EntityData data, Vector2 offset) - : base(data.Position + offset, data.Width, data.Height, false) { - // no-op. MonoMod ignores this - we only need this to make the compiler shut up. - } + [MonoModIgnore] + public extern patch_BounceBlock(Vector2 position, float width, float height); - public extern void orig_ctor(EntityData data, Vector2 offset); [MonoModConstructor] - public void ctor(EntityData data, Vector2 offset) { - orig_ctor(data, offset); - + [MonoModReplace] + public patch_BounceBlock(EntityData data, Vector2 offset) + : this(data.Position + offset, data.Width, data.Height) { notCoreMode = data.Bool("notCoreMode"); } + [MonoModLinkTo("Monocle.Entity", "Added")] + [MonoModIgnore] + public extern void base_Added(Scene scene); [MonoModReplace] public override void Added(Scene scene) { base.Added(scene); diff --git a/Celeste.Mod.mm/Patches/Checkpoint.cs b/Celeste.Mod.mm/Patches/Checkpoint.cs index a89779c14..ababe6e60 100644 --- a/Celeste.Mod.mm/Patches/Checkpoint.cs +++ b/Celeste.Mod.mm/Patches/Checkpoint.cs @@ -3,18 +3,27 @@ using Microsoft.Xna.Framework; using Monocle; +using MonoMod; using System; namespace Celeste { - class patch_Checkpoint : Entity { + class patch_Checkpoint : Checkpoint { private string bg; private Image image; private Sprite sprite; private Sprite flash; + public patch_Checkpoint(Vector2 position, string bg = "", Vector2? spawnTarget = null) + : base(position, bg, spawnTarget) { + //no-op + } + + [MonoModLinkTo("Monocle.Entity", "Awake")] + [MonoModIgnore] + public extern void base_Awake(Scene scene); public override void Awake(Scene scene) { - base.Awake(scene); + base_Awake(scene); Level level = scene as Level; if (level == null || level.Session.Area.GetLevelSet() == "Celeste") diff --git a/Celeste.Mod.mm/Patches/InputMappingInfo.cs b/Celeste.Mod.mm/Patches/InputMappingInfo.cs index d4606f3bb..277e75162 100755 --- a/Celeste.Mod.mm/Patches/InputMappingInfo.cs +++ b/Celeste.Mod.mm/Patches/InputMappingInfo.cs @@ -1,6 +1,7 @@ using MonoMod; namespace Celeste { + // Extend patch_Item so we can override AlwaysRender properly class patch_InputMappingInfo : patch_TextMenu.patch_Item { // we want it to always render, as it overlays on top of the menu when scrolling down (so it never goes off-screen). public override bool AlwaysRender => true; diff --git a/Celeste.Mod.mm/Patches/IntroCrusher.cs b/Celeste.Mod.mm/Patches/IntroCrusher.cs index 0b9ba20a8..8c0b743a8 100644 --- a/Celeste.Mod.mm/Patches/IntroCrusher.cs +++ b/Celeste.Mod.mm/Patches/IntroCrusher.cs @@ -10,8 +10,7 @@ using System.Linq; namespace Celeste { - // : Solid because base.Added - class patch_IntroCrusher : Solid { + class patch_IntroCrusher : IntroCrusher { // We're effectively in IntroCrusher, but still need to "expose" private fields to our mod. private Vector2 end; @@ -19,15 +18,10 @@ class patch_IntroCrusher : Solid { public string levelFlags; - public patch_IntroCrusher(Vector2 position, int width, int height, Vector2 node) - : base(position, width, height, true) { - // no-op. MonoMod ignores this - we only need this to make the compiler shut up. - } - [MonoModConstructor] [MonoModReplace] public patch_IntroCrusher(EntityData data, Vector2 offset) - : this(data.Position + offset, data.Width, data.Height, data.Nodes[0] + offset) { + : base(data.Position + offset, data.Width, data.Height, data.Nodes[0] + offset) { levelFlags = data.Attr("flags"); @@ -38,6 +32,9 @@ public patch_IntroCrusher(EntityData data, Vector2 offset) } } + [MonoModLinkTo("Monocle.Entity", "Added")] + [MonoModIgnore] + public extern void base_Added(Scene scene); public extern void orig_Added(Scene scene); public override void Added(Scene scene) { Level level = scene as Level; @@ -46,7 +43,7 @@ public override void Added(Scene scene) { return; } - base.Added(scene); + base_Added(scene); if (levelFlags.Split(',').Any(flag => level.Session.GetLevelFlag(flag))) { Position = end; diff --git a/Celeste.Mod.mm/Patches/LevelEnter.cs b/Celeste.Mod.mm/Patches/LevelEnter.cs index f9f115f61..b7fdaac64 100644 --- a/Celeste.Mod.mm/Patches/LevelEnter.cs +++ b/Celeste.Mod.mm/Patches/LevelEnter.cs @@ -10,6 +10,7 @@ using System.Collections; namespace Celeste { + // LevelEnter has a private .ctor class patch_LevelEnter : Scene { /// diff --git a/Celeste.Mod.mm/Patches/RotateSpinner.cs b/Celeste.Mod.mm/Patches/RotateSpinner.cs index aeb87f1f4..5621cbe7f 100644 --- a/Celeste.Mod.mm/Patches/RotateSpinner.cs +++ b/Celeste.Mod.mm/Patches/RotateSpinner.cs @@ -4,15 +4,18 @@ using Microsoft.Xna.Framework; using Monocle; using MonoMod; +using System; namespace Celeste { // : Entity because there's no original Awake method to hook, thus base.Awake must be Entity::Awake. - class patch_RotateSpinner : Entity { + class patch_RotateSpinner : RotateSpinner { - public float Angle => - fixAngle ? - MathHelper.Lerp(MathHelper.Pi, -MathHelper.Pi, Easer(rotationPercent)) : - MathHelper.Lerp(4.712389f, -1.57079637f, Easer(rotationPercent)); + public new float Angle { + [MonoModReplace] + get => fixAngle ? + MathHelper.Lerp(MathHelper.Pi, -MathHelper.Pi, Easer(rotationPercent)) : + MathHelper.Lerp(4.712389f, -(float)Math.PI / 2f, Easer(rotationPercent)); + } private bool fixAngle; @@ -24,7 +27,7 @@ class patch_RotateSpinner : Entity { private Vector2 startPosition; public patch_RotateSpinner(EntityData data, Vector2 offset) - : base(data.Position + offset) { + : base(data, offset) { // no-op. MonoMod ignores this - we only need this to make the compiler shut up. } diff --git a/Celeste.Mod.mm/Patches/StarJumpBlock.cs b/Celeste.Mod.mm/Patches/StarJumpBlock.cs index 1358a7a9d..28a36cd9e 100644 --- a/Celeste.Mod.mm/Patches/StarJumpBlock.cs +++ b/Celeste.Mod.mm/Patches/StarJumpBlock.cs @@ -7,14 +7,16 @@ using System.Collections.Generic; namespace Celeste { - // : Solid because base.Awake - class patch_StarJumpBlock : Solid { + class patch_StarJumpBlock : StarJumpBlock { private Level level; public patch_StarJumpBlock(Vector2 position, float width, float height, bool sinks) : base(position, width, height, sinks) { // no-op. MonoMod ignores this - we only need this to make the compiler shut up. } + [MonoModLinkTo("Celeste.Solid", "Awake")] + [MonoModIgnore] + public extern void base_Awake(Scene scene); public extern void orig_Awake(Scene scene); public override void Awake(Scene scene) { if ((scene as Level).Session.Area.GetLevelSet() == "Celeste") { @@ -27,7 +29,7 @@ public override void Awake(Scene scene) { // TODO: Inner corner textures? Or keep them empty as-is? - base.Awake(scene); + base_Awake(scene); level = SceneAs(); @@ -177,6 +179,9 @@ public override void Awake(Scene scene) { } } + [MonoModLinkTo("Monocle.Entity", "Render")] + [MonoModIgnore] + public extern void base_Render(); public extern void orig_Render(); public override void Render() { if (SceneAs().Session.Area.GetLevelSet() == "Celeste") { @@ -208,7 +213,7 @@ public override void Render() { ); } - base.Render(); + base_Render(); } [MonoModIgnore] From b5886e26657c4663824d51b53f88f338148021b5 Mon Sep 17 00:00:00 2001 From: coloursofnoise Date: Sat, 15 Jan 2022 18:36:35 -0800 Subject: [PATCH 2/4] Remove outdated comments Co-authored-by: WEGFan --- Celeste.Mod.mm/Patches/BounceBlock.cs | 1 - Celeste.Mod.mm/Patches/RotateSpinner.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Celeste.Mod.mm/Patches/BounceBlock.cs b/Celeste.Mod.mm/Patches/BounceBlock.cs index 34a8a3a87..b473f8024 100644 --- a/Celeste.Mod.mm/Patches/BounceBlock.cs +++ b/Celeste.Mod.mm/Patches/BounceBlock.cs @@ -5,7 +5,6 @@ using MonoMod; namespace Celeste { - // : Solid because base.Added class patch_BounceBlock : BounceBlock { // We're effectively in BounceBlock, but still need to "expose" private fields to our mod. diff --git a/Celeste.Mod.mm/Patches/RotateSpinner.cs b/Celeste.Mod.mm/Patches/RotateSpinner.cs index 5621cbe7f..3303a2e4b 100644 --- a/Celeste.Mod.mm/Patches/RotateSpinner.cs +++ b/Celeste.Mod.mm/Patches/RotateSpinner.cs @@ -7,7 +7,6 @@ using System; namespace Celeste { - // : Entity because there's no original Awake method to hook, thus base.Awake must be Entity::Awake. class patch_RotateSpinner : RotateSpinner { public new float Angle { From 3ed9ae6202ba90f5fedd69ff4b61f40a7fc02341 Mon Sep 17 00:00:00 2001 From: WEGFan Date: Sun, 16 Jan 2022 23:52:26 +0800 Subject: [PATCH 3/4] Fix BounceBlock causing stack overflow --- Celeste.Mod.mm/Patches/BounceBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Celeste.Mod.mm/Patches/BounceBlock.cs b/Celeste.Mod.mm/Patches/BounceBlock.cs index b473f8024..ec4cc4013 100644 --- a/Celeste.Mod.mm/Patches/BounceBlock.cs +++ b/Celeste.Mod.mm/Patches/BounceBlock.cs @@ -28,7 +28,7 @@ public patch_BounceBlock(EntityData data, Vector2 offset) public extern void base_Added(Scene scene); [MonoModReplace] public override void Added(Scene scene) { - base.Added(scene); + base_Added(scene); iceModeNext = iceMode = SceneAs().CoreMode == Session.CoreModes.Cold || notCoreMode; ToggleSprite(); } From b1eab71b214f7ee1bf1862563617034ee1261442 Mon Sep 17 00:00:00 2001 From: WEGFan Date: Wed, 19 Jan 2022 21:22:31 +0800 Subject: [PATCH 4/4] Unhardcode pi --- Celeste.Mod.mm/Patches/RotateSpinner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Celeste.Mod.mm/Patches/RotateSpinner.cs b/Celeste.Mod.mm/Patches/RotateSpinner.cs index 3303a2e4b..46628e5f3 100644 --- a/Celeste.Mod.mm/Patches/RotateSpinner.cs +++ b/Celeste.Mod.mm/Patches/RotateSpinner.cs @@ -13,7 +13,7 @@ class patch_RotateSpinner : RotateSpinner { [MonoModReplace] get => fixAngle ? MathHelper.Lerp(MathHelper.Pi, -MathHelper.Pi, Easer(rotationPercent)) : - MathHelper.Lerp(4.712389f, -(float)Math.PI / 2f, Easer(rotationPercent)); + MathHelper.Lerp(MathHelper.Pi + MathHelper.Pi / 2, -MathHelper.Pi / 2, Easer(rotationPercent)); } private bool fixAngle;