Skip to content

Commit

Permalink
Do not leave space for cassette in chapter panel if there is no cassette
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Sep 29, 2023
1 parent c1acd19 commit 4258fa8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Celeste.Mod.mm/Patches/OuiChapterPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,9 @@ private float _FixTitleLength(float vanillaValue) {

private static float vanillaOffsetForStrawberryWidth = 0;

private static float getStrawberryWidth(float vanillaValue, int strawberryCount) {
const float maxWidth = 440;
private float getStrawberryWidth(float vanillaValue, int strawberryCount, int checkpointIndex) {
bool hasCassette = (Area.Mode == AreaMode.Normal && Data.CassetteCheckpointIndex == checkpointIndex);
float maxWidth = hasCassette ? 440 : 520;

float modifiedValue = vanillaValue;
if (vanillaValue * strawberryCount > maxWidth) {
Expand Down Expand Up @@ -492,16 +493,19 @@ public static void PatchOuiChapterPanelOptionBg(ILContext context, CustomAttribu


public static void PatchStrawberryWidthInChapterPanel(ILContext context, CustomAttribute attrib) {
MethodDefinition m_getStrawberryWidth = context.Method.DeclaringType.FindMethod("System.Single Celeste.OuiChapterPanel::getStrawberryWidth(System.Single,System.Int32)");
MethodDefinition m_getStrawberryWidth = context.Method.DeclaringType.FindMethod("System.Single Celeste.OuiChapterPanel::getStrawberryWidth(System.Single,System.Int32,System.Int32)");
MethodDefinition m_correctInitialStrawberryOffset = context.Method.DeclaringType.FindMethod("Microsoft.Xna.Framework.Vector2 Celeste.OuiChapterPanel::correctInitialStrawberryOffset(Microsoft.Xna.Framework.Vector2,Microsoft.Xna.Framework.Vector2)");
int boolArrayIndex = context.Body.Variables.Where(var => var.VariableType.FullName == "System.Boolean[]").First().Index;

ILCursor cursor = new ILCursor(context);

for (int i = 0; i < 2; i++) {
cursor.GotoNext(MoveType.After, instr => instr.MatchLdcR4(44f));
cursor.GotoNext(instr => instr.MatchLdcR4(44f));
cursor.Emit(OpCodes.Ldarg_0);
cursor.Index++;
cursor.Emit(OpCodes.Ldloc, boolArrayIndex);
cursor.Emit(OpCodes.Ldlen);
cursor.Emit(OpCodes.Ldarg_3);
cursor.Emit(OpCodes.Call, m_getStrawberryWidth);

if (i == 0) {
Expand Down

0 comments on commit 4258fa8

Please sign in to comment.