2024-06-01 12:30:03 +00:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using Monitor;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
|
|
|
|
|
namespace UnlockFrameRate;
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(NoteBase), "GetMaiBugAdjustMSec")]
|
|
|
|
|
internal class PatchGetMaiBugAdjustMSec
|
|
|
|
|
{
|
|
|
|
|
private const float OriginalFrameRate = 60f;
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
|
|
|
|
|
{
|
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var instruction in instructions)
|
|
|
|
|
{
|
|
|
|
|
if (instruction.opcode != OpCodes.Ldc_R4 || instruction.operand is not float operand)
|
|
|
|
|
{
|
|
|
|
|
yield return instruction;
|
|
|
|
|
i++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Math.Abs(operand - OriginalFrameRate) < float.Epsilon)
|
|
|
|
|
{
|
2024-07-08 18:56:35 +00:00
|
|
|
|
instruction.operand = (float)FrameRatePlugin.Instance.TargetFrameRate;
|
2024-06-01 12:30:03 +00:00
|
|
|
|
FrameRatePlugin.Logger.LogDebug(
|
|
|
|
|
"Overrode constant at opcode index {0} in {1}: {2} => {3}",
|
|
|
|
|
i,
|
|
|
|
|
__originalMethod.Name,
|
|
|
|
|
operand,
|
|
|
|
|
instruction.operand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield return instruction;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|