diff --git a/UnlockFrameRate/FrameRatePlugin.cs b/UnlockFrameRate/FrameRatePlugin.cs index 973c77b..e633995 100644 --- a/UnlockFrameRate/FrameRatePlugin.cs +++ b/UnlockFrameRate/FrameRatePlugin.cs @@ -13,17 +13,23 @@ namespace UnlockFrameRate; [BepInProcess("Sinmai.exe")] public class FrameRatePlugin : BaseUnityPlugin { - public static int TargetFrameRate { get; private set; } = 60; public new static ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource("FrameRate"); + public static FrameRatePlugin Instance { get; private set; } + + public int TargetFrameRate => _configFrameRate.Value; + public bool PatchJudgementTiming => _configChangeJudgementTiming.Value; private ConfigEntry _configFrameRate; private ConfigEntry _configVSyncCount; private ConfigEntry _configDisplayFps; + private ConfigEntry _configChangeJudgementTiming; private Harmony _harmony; private void Awake() { + Instance = this; + _configFrameRate = Config.Bind( "Config", "FrameRate", @@ -39,10 +45,14 @@ public class FrameRatePlugin : BaseUnityPlugin "DisplayFPS", false, "Show an FPS counter"); + _configChangeJudgementTiming = Config.Bind( + "Config", + "ChangeJudgementTiming", + true, + "Adjusts JUDGEMENT TIMING options to match the new frame rate.\nIf this is enabled, 0.1 in-game offset is equivalent to 10000 / FrameRate."); if (_configVSyncCount.Value is > 0 and <= 4) { - TargetFrameRate = Screen.currentResolution.refreshRate / _configVSyncCount.Value; QualitySettings.vSyncCount = _configVSyncCount.Value; Logger.LogInfo( @@ -52,7 +62,6 @@ public class FrameRatePlugin : BaseUnityPlugin } else { - TargetFrameRate = _configFrameRate.Value; Application.targetFrameRate = TargetFrameRate; QualitySettings.vSyncCount = 0; diff --git a/UnlockFrameRate/ManualLogSourceExtensions.cs b/UnlockFrameRate/ManualLogSourceExtensions.cs index de0386a..af05320 100644 --- a/UnlockFrameRate/ManualLogSourceExtensions.cs +++ b/UnlockFrameRate/ManualLogSourceExtensions.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BepInEx.Logging; +using BepInEx.Logging; namespace UnlockFrameRate; diff --git a/UnlockFrameRate/PatchFrameTime.cs b/UnlockFrameRate/PatchFrameTime.cs index 8e3052a..e6ef97d 100644 --- a/UnlockFrameRate/PatchFrameTime.cs +++ b/UnlockFrameRate/PatchFrameTime.cs @@ -1,13 +1,13 @@ // ReSharper disable InconsistentNaming using HarmonyLib; +using Manager; +using Manager.UserDatas; using Monitor; using System; using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; -using Manager; -using Manager.UserDatas; namespace UnlockFrameRate; @@ -20,16 +20,25 @@ internal class PatchFrameTime private static IEnumerable TargetMethods() { - var noteJudge = AccessTools.TypeByName("NoteJudge"); - var juggeTiming = AccessTools.Inner(noteJudge, "JuggeTiming"); // lol + // This shouldn't be patched, because they make the judgements + // harder or easier depending on your frame rate. + // var noteJudge = AccessTools.TypeByName("NoteJudge"); + // var juggeTiming = AccessTools.Inner(noteJudge, "JuggeTiming"); // lol + + // yield return AccessTools.Constructor(juggeTiming); + + // This changes the effect of judgement timing based on the set FPS, + // so +2.0 at 120Hz will only add 17ms instead of 33ms. + if (FrameRatePlugin.Instance.PatchJudgementTiming) + { + yield return AccessTools.Method(typeof(NoteJudge), nameof(NoteJudge.GetJudgeTiming)); + yield return AccessTools.Method(typeof(NoteJudge), nameof(NoteJudge.GetSlideJudgeTiming)); + yield return AccessTools.Method(typeof(UserOption), nameof(UserOption.GetAdjustMSec)); + } - yield return AccessTools.Constructor(juggeTiming); - yield return AccessTools.Method(typeof(UserOption), nameof(UserOption.GetAdjustMSec)); yield return AccessTools.Method(typeof(NoteBase), "IsNoteCheckTimeStart"); yield return AccessTools.Method(typeof(TouchNoteB), "GetNoteYPosition"); yield return AccessTools.Method(typeof(SlideRoot), "IsNoteCheckTimeStart"); - yield return AccessTools.Method(typeof(NoteJudge), nameof(NoteJudge.GetJudgeTiming)); - yield return AccessTools.Method(typeof(NoteJudge), nameof(NoteJudge.GetSlideJudgeTiming)); yield return AccessTools.Method(typeof(SlideJudge), nameof(SlideJudge.Initialize)); yield return AccessTools.Method(typeof(JudgeGrade), nameof(JudgeGrade.Initialize)); yield return AccessTools.Method(typeof(NotesManager), nameof(NotesManager.getPlayFirstMsec)); @@ -45,8 +54,8 @@ internal class PatchFrameTime private static IEnumerable Transpiler(IEnumerable instructions, MethodBase __originalMethod) { - var targetFrameTime = 1000f / FrameRatePlugin.TargetFrameRate; - var targetFramePerMs = (float)FrameRatePlugin.TargetFrameRate / 1000; + var targetFrameTime = 1000f / FrameRatePlugin.Instance.TargetFrameRate; + var targetFramePerMs = (float)FrameRatePlugin.Instance.TargetFrameRate / 1000; var i = 0; foreach (var instruction in instructions) diff --git a/UnlockFrameRate/PatchGetMaiBugAdjustMSec.cs b/UnlockFrameRate/PatchGetMaiBugAdjustMSec.cs index 94577c4..fe94841 100644 --- a/UnlockFrameRate/PatchGetMaiBugAdjustMSec.cs +++ b/UnlockFrameRate/PatchGetMaiBugAdjustMSec.cs @@ -27,7 +27,7 @@ internal class PatchGetMaiBugAdjustMSec if (Math.Abs(operand - OriginalFrameRate) < float.Epsilon) { - instruction.operand = (float)FrameRatePlugin.TargetFrameRate; + instruction.operand = (float)FrameRatePlugin.Instance.TargetFrameRate; FrameRatePlugin.Logger.LogDebug( "Overrode constant at opcode index {0} in {1}: {2} => {3}", i,