From 9b00055a028dbe604b74c916d1d31b3924975134 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Wed, 12 May 2021 16:42:25 -0400 Subject: [PATCH] Add potential fix for Unity setting the screen resolution too small --- CLre/CLre.cs | 3 +- CLre/Fixes/MiniScreenEmbiggener.cs | 52 ++++++++++++++++++++++++++++++ CLre/Fixes/StartupSpeedup.cs | 4 ++- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 CLre/Fixes/MiniScreenEmbiggener.cs diff --git a/CLre/CLre.cs b/CLre/CLre.cs index b12c6cb..2bc4b61 100644 --- a/CLre/CLre.cs +++ b/CLre/CLre.cs @@ -48,6 +48,7 @@ namespace CLre // patches for bugs Fixes.InitLogSooner.Init(); + Fixes.MiniScreenHelper.Init(); // misc LogIPAPlugins(); @@ -118,7 +119,7 @@ namespace CLre int modCount = IllusionInjector.PluginManager.Plugins.Count(); StringBuilder sb = new StringBuilder(); sb.AppendFormat(" {0} {1}\n", Name, Version); - sb.AppendFormat("{0} bugfixes, {1} plugins, no frills", fixCount, modCount); + sb.AppendFormat("{0} bugfixes, {1} plugins, no frills\n", fixCount, modCount); #if DEBUG sb.AppendFormat(" DEBUG version\n"); #endif diff --git a/CLre/Fixes/MiniScreenEmbiggener.cs b/CLre/Fixes/MiniScreenEmbiggener.cs new file mode 100644 index 0000000..2862010 --- /dev/null +++ b/CLre/Fixes/MiniScreenEmbiggener.cs @@ -0,0 +1,52 @@ +using System.Runtime.CompilerServices; +using UnityEngine; + +namespace CLre.Fixes +{ + [Bugfix(name = "MiniScreenEmbiggener", + more = "https://trello.com/c/NAls3XaE/17-game-starts-minimized-and-wont-restore", + description = "Go into fullscreen when Unity does dumb display stuff", + component = BugfixType.Initialiser, id = 6)] + public static class MiniScreenHelper + { + private const int WIDTH_MINIMUM = 200; + private const int HEIGHT_MINIMUM = 200; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Init() + { + if (Screen.width < WIDTH_MINIMUM || Screen.height < HEIGHT_MINIMUM) + { + // fix screen that's too small + API.Utility.Logging.LogWarning($"Window is too small! (detected: {Screen.width}x{Screen.height})"); + if (Screen.resolutions.Length > 0) + { + Resolution r = Screen.resolutions[Screen.resolutions.Length - 1]; + Screen.SetResolution(r.width, r.height, true); + API.Utility.Logging.MetaLog($"Set screen resolution to {r.width}x{r.height} (fullscreen)"); + } + else + { + // no resolutions, try some stuff to fix this (this is basically a bunch of random guesses) + API.Utility.Logging.LogError("No screen resolutions available, hopefully it'll be ok eventually..."); + Screen.fullScreen = true; + Display.onDisplaysUpdated += () => // hope displays update fixes things + { + API.Utility.Logging.MetaLog("Displays updated"); + if (Screen.resolutions.Length > 0) + { + Resolution r = Screen.resolutions[Screen.resolutions.Length - 1]; + Screen.SetResolution(r.width, r.height, true); + API.Utility.Logging.MetaLog($"Set screen resolution to {r.width}x{r.height} (fullscreen)"); + } + }; + // log displays to help debug this issue + foreach (var display in Display.displays) + { + API.Utility.Logging.MetaLog($"Display: {display.renderingWidth}x{display.renderingHeight} (sys: {display.systemWidth}x{display.systemHeight}) Active? {display.active}"); + } + } + } + } + } +} \ No newline at end of file diff --git a/CLre/Fixes/StartupSpeedup.cs b/CLre/Fixes/StartupSpeedup.cs index 3fb94ca..0dc5280 100644 --- a/CLre/Fixes/StartupSpeedup.cs +++ b/CLre/Fixes/StartupSpeedup.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using HarmonyLib; +#if DEBUG namespace CLre.Fixes { public class StartupSpeedup @@ -54,4 +55,5 @@ namespace CLre.Fixes Speedup_Benchmark.test = Stopwatch.StartNew(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file