From 7e53fc034b369291b7d7875a57b0ddb3eedea831 Mon Sep 17 00:00:00 2001 From: Repflez <659133+Repflez@users.noreply.github.com> Date: Thu, 27 Jan 2022 14:45:13 -0700 Subject: [PATCH] fix: Attempt to fix custom framerate --- CustomResolution.cs | 66 +++++++++++++++++++++++++++++++++++++++++--- TaikoModStuff.csproj | 4 +-- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/CustomResolution.cs b/CustomResolution.cs index 8948cae..27c4951 100644 --- a/CustomResolution.cs +++ b/CustomResolution.cs @@ -1,4 +1,6 @@ using HarmonyLib; +using OnlineManager; +using System; using UnityEngine; namespace TaikoModStuff @@ -6,13 +8,70 @@ namespace TaikoModStuff internal class CustomResolution { // Skip the original method, we're doing magic here - [HarmonyPatch(typeof(FocusManager), "SetScreenType")] + [HarmonyPatch(typeof(FocusManager), "OnApplicationFocus")] [HarmonyPrefix] - static bool Prefix() + static bool PrefixFocus() { return false; } + // Skip the original method, we're doing magic here + [HarmonyPatch(typeof(FocusManager), "SetScreenType")] + [HarmonyPrefix] + static bool PrefixScreenType() + { + return false; + } + + [HarmonyPatch(typeof(FocusManager), "OnApplicationFocus")] + [HarmonyPrefix] + static void setCustomFocus(bool focusStatus) + { + if (focusStatus) + { + Traverse focusManager = Traverse.CreateWithType("FocusManager"); + DataConst.ScreenModeType m_typeScreenMode = focusManager.Field("m_typeScreenMode").Value; + int width = 1920; + int height = 1080; + int framerate = Plugin.configCustomFramerate.Value; + + // Namco does typos + int hegiht = focusManager.Field("hegiht").Value; + + if (Plugin.configCustomWindowedWidth.Value > 0) + { + width = Plugin.configCustomWindowedWidth.Value; + + // Set custom height if the width is set first + if (Plugin.configCustomWindowedHeight.Value > 0) + { + height = Plugin.configCustomWindowedHeight.Value; + } + } + + switch ((int)m_typeScreenMode) + { + case 1: // Borderless + Screen.fullScreen = true; + Screen.SetResolution(width, height, FullScreenMode.FullScreenWindow, framerate); + break; + case 2: // Windowed + Screen.fullScreen = false; + Screen.SetResolution(width, height, FullScreenMode.Windowed, framerate); + break; + default: // Fullscreen + Screen.fullScreen = true; + Screen.SetResolution(width, height, FullScreenMode.FullScreenWindow, framerate); + break; + } + + if (TaikoSingletonMonoBehaviour.Instance.MySceneManager.CurrentSceneName == "RankedMatch") + { + TaikoSingletonMonoBehaviour.Instance.GetNetworkTimeOnApplicationFocus(); + } + } + } + [HarmonyPatch(typeof(FocusManager), "SetScreenType")] [HarmonyPrefix] static void setCustomResolution(int type) @@ -45,8 +104,7 @@ namespace TaikoModStuff break; } - // TODO: Fix this - Traverse.CreateWithType("FocusManager").Field("m_typeScreenMode").SetValue((DataConst.ScreenModeType)type); + Traverse.CreateWithType("FocusManager").Method("setScreenModeType", new Type[] { typeof(DataConst.ScreenModeType) }, new object[] { (DataConst.ScreenModeType)type }).ToString(); } } } diff --git a/TaikoModStuff.csproj b/TaikoModStuff.csproj index 0158639..4fd9cd2 100644 --- a/TaikoModStuff.csproj +++ b/TaikoModStuff.csproj @@ -1,10 +1,10 @@ - + net46 TaikoModStuff My first plugin - 1.1.0 + 1.1.1 true latest