Skip to content

Commit

Permalink
feat: Custom resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Repflez committed Jan 27, 2022
1 parent a215cce commit 85333dd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@ MigrationBackup/
FodyWeavers.xsd

# Ignore game data
lib/Assembly-CSharp.dll
lib/*.dll
52 changes: 52 additions & 0 deletions CustomResolution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using HarmonyLib;
using UnityEngine;

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

[HarmonyPatch(typeof(FocusManager), "SetScreenType")]
[HarmonyPrefix]
static void setCustomResolution(int type)
{
int width = 1920;
int height = 1080;
int framerate = Plugin.configCustomFramerate.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 (type) {
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;
}

// TODO: Fix this
Traverse.CreateWithType("FocusManager").Field("m_typeScreenMode").SetValue((DataConst.ScreenModeType)type);
}
}
}
21 changes: 21 additions & 0 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class Plugin : BaseUnityPlugin
{
public static ConfigEntry<bool> configForceFontChange;

public static ConfigEntry<int> configCustomWindowedWidth;
public static ConfigEntry<int> configCustomWindowedHeight;

public static ConfigEntry<int> configCustomFramerate;

private void Awake()
{
// Add configurations
Expand All @@ -17,8 +22,24 @@ private void Awake()
false,
"Force the game font to the JP font");

configCustomWindowedWidth = Config.Bind("General.Resolution",
"CustomWidth",
1920,
"Custom width to use. Set to 0 to disable setting the custom resolution");

configCustomWindowedHeight = Config.Bind("General.Resolution",
"CustomHeight",
1080,
"Custom height to use");

configCustomFramerate = Config.Bind("General.Framerate",
"CustomFramerate",
60,
"Custom framerate. Use with caution");

var instance = new Harmony(PluginInfo.PLUGIN_NAME);
instance.PatchAll(typeof(FontChanger));
instance.PatchAll(typeof(CustomResolution));

// Plugin startup logic
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
Expand Down
4 changes: 4 additions & 0 deletions TaikoModStuff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
<HintPath>lib\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>lib\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</Project>

0 comments on commit 85333dd

Please sign in to comment.