1
0
mirror of synced 2024-11-23 22:10:57 +01:00

fix: Attempt to fix custom framerate

This commit is contained in:
Repflez 2022-01-27 14:45:13 -07:00
parent 335987c48e
commit 7e53fc034b
2 changed files with 64 additions and 6 deletions

View File

@ -1,4 +1,6 @@
using HarmonyLib; using HarmonyLib;
using OnlineManager;
using System;
using UnityEngine; using UnityEngine;
namespace TaikoModStuff namespace TaikoModStuff
@ -6,13 +8,70 @@ namespace TaikoModStuff
internal class CustomResolution internal class CustomResolution
{ {
// Skip the original method, we're doing magic here // Skip the original method, we're doing magic here
[HarmonyPatch(typeof(FocusManager), "SetScreenType")] [HarmonyPatch(typeof(FocusManager), "OnApplicationFocus")]
[HarmonyPrefix] [HarmonyPrefix]
static bool Prefix() static bool PrefixFocus()
{ {
return false; 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<DataConst.ScreenModeType>("m_typeScreenMode").Value;
int width = 1920;
int height = 1080;
int framerate = Plugin.configCustomFramerate.Value;
// Namco does typos
int hegiht = focusManager.Field<int>("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<CommonObjects>.Instance.MySceneManager.CurrentSceneName == "RankedMatch")
{
TaikoSingletonMonoBehaviour<XboxLiveOnlineManager>.Instance.GetNetworkTimeOnApplicationFocus();
}
}
}
[HarmonyPatch(typeof(FocusManager), "SetScreenType")] [HarmonyPatch(typeof(FocusManager), "SetScreenType")]
[HarmonyPrefix] [HarmonyPrefix]
static void setCustomResolution(int type) static void setCustomResolution(int type)
@ -45,8 +104,7 @@ namespace TaikoModStuff
break; break;
} }
// TODO: Fix this Traverse.CreateWithType("FocusManager").Method("setScreenModeType", new Type[] { typeof(DataConst.ScreenModeType) }, new object[] { (DataConst.ScreenModeType)type }).ToString();
Traverse.CreateWithType("FocusManager").Field("m_typeScreenMode").SetValue((DataConst.ScreenModeType)type);
} }
} }
} }

View File

@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net46</TargetFramework> <TargetFramework>net46</TargetFramework>
<AssemblyName>TaikoModStuff</AssemblyName> <AssemblyName>TaikoModStuff</AssemblyName>
<Description>My first plugin</Description> <Description>My first plugin</Description>
<Version>1.1.0</Version> <Version>1.1.1</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>