Skip to content

Commit

Permalink
Add line wrapping to strawberry tracker in pause menu
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Sep 27, 2023
1 parent 5fdadfb commit 46fbb19
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions Celeste.Mod.mm/Patches/GameplayStats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Microsoft.Xna.Framework;
using Mono.Cecil;
using MonoMod.Cil;
using MonoMod.Utils;
using System;
using System.Linq;
using Mono.Cecil.Cil;
using MonoMod;

namespace Celeste {
public class patch_GameplayStats : GameplayStats {
[MonoModIgnore]
[WrapBerryTracker]
public extern new void Render();

private static float lastLineOffset;
private static int remainingLineCount;

private static void getInitialPosition(ref Vector2 orig) {
remainingLineCount = 0;

if (orig.X >= 32f) {
return;
}

while (orig.X < 32f) {
orig.X += (1920f - 32f) / 2f;
orig.Y -= 48f;

remainingLineCount++;
}

lastLineOffset = orig.X;
orig.X = 32f;
}

private static void wrapPosition(ref Vector2 orig) {
if (orig.X > 1920f - 32f) {
orig.X = 32f;
orig.Y += 48f;

remainingLineCount--;
if (remainingLineCount < 1) {
orig.X = lastLineOffset;
}
}
}
}
}


namespace MonoMod {
[MonoModCustomMethodAttribute(nameof(MonoModRules.WrapBerryTracker))]
class WrapBerryTrackerAttribute : Attribute { }

static partial class MonoModRules {
public static void WrapBerryTracker(ILContext context, CustomAttribute attrib) {
ILCursor cursor = new ILCursor(context);

int vectorIndex = context.Body.Variables.Where(var => var.VariableType.FullName == "Microsoft.Xna.Framework.Vector2").First().Index;
MethodDefinition m_getInitialPosition = context.Method.DeclaringType.FindMethod("getInitialPosition");
MethodDefinition m_wrapPosition = context.Method.DeclaringType.FindMethod("wrapPosition");

cursor.GotoNext(MoveType.After, instr => instr.OpCode == OpCodes.Call && (instr.Operand as MethodReference).FullName == "System.Void Microsoft.Xna.Framework.Vector2::.ctor(System.Single,System.Single)");
cursor.Emit(OpCodes.Ldloca, vectorIndex);
cursor.Emit(OpCodes.Call, m_getInitialPosition);

for (int i = 0; i < 2; i++) {
cursor.GotoNext(MoveType.After, instr => instr.MatchStindR4());
cursor.Emit(OpCodes.Ldloca, vectorIndex);
cursor.Emit(OpCodes.Call, m_wrapPosition);
}
}
}
}

0 comments on commit 46fbb19

Please sign in to comment.