Skip to content

Commit

Permalink
fix: Attempt to fix custom framerate
Browse files Browse the repository at this point in the history
  • Loading branch information
Repflez committed Jan 27, 2022
1 parent 335987c commit 7e53fc0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
64 changes: 61 additions & 3 deletions CustomResolution.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,77 @@
using HarmonyLib;
using OnlineManager;
using System;
using UnityEngine;

namespace TaikoModStuff
{
internal class CustomResolution
{
// Skip the original method, we're doing magic here
[HarmonyPatch(typeof(FocusManager), "OnApplicationFocus")]
[HarmonyPrefix]
static bool PrefixFocus()
{
return false;
}

// Skip the original method, we're doing magic here
[HarmonyPatch(typeof(FocusManager), "SetScreenType")]
[HarmonyPrefix]
static bool Prefix()
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")]
[HarmonyPrefix]
static void setCustomResolution(int type)
Expand Down Expand Up @@ -45,8 +104,7 @@ static void setCustomResolution(int type)
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();
}
}
}
4 changes: 2 additions & 2 deletions TaikoModStuff.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<AssemblyName>TaikoModStuff</AssemblyName>
<Description>My first plugin</Description>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down

0 comments on commit 7e53fc0

Please sign in to comment.