Skip to content

Commit

Permalink
Fix viewport width when hovering collection
Browse files Browse the repository at this point in the history
Co-authored-by: Metalit <48568911+Metalit@users.noreply.github.com>
  • Loading branch information
Meivyn and Metalit committed Jun 17, 2024
1 parent f645344 commit dfaaf1f
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using SiraUtil.Affinity;
Expand Down Expand Up @@ -92,5 +93,21 @@ private IEnumerable<CodeInstruction> OpenCollectionWithOneRow(IEnumerable<CodeIn
.SetOpcodeAndAdvance(OpCodes.Ldc_I4_0)
.InstructionEnumeration();
}

[AffinityPatch(typeof(AnnotatedBeatmapLevelCollectionsGridViewAnimator), nameof(AnnotatedBeatmapLevelCollectionsGridViewAnimator.AnimateOpen))]
[AffinityTranspiler]
private IEnumerable<CodeInstruction> FixViewportWidth(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions)
.PrintInstructions()
.MatchStartForward(
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(i => i.opcode == OpCodes.Call && (ConstructorInfo)i.operand == AccessTools.Constructor(typeof(Vector2))))
.ThrowIfInvalid()
.SetInstruction(new CodeInstruction(OpCodes.Ldarg_0))
.Insert(Transpilers.EmitDelegate<Func<AnnotatedBeatmapLevelCollectionsGridViewAnimator, float>>(animator =>
((animator._columnCount - animator._visibleColumnCount) * 2 + animator._visibleColumnCount) * animator._columnWidth))
.InstructionEnumeration();
}
}
}

0 comments on commit dfaaf1f

Please sign in to comment.