Add potential fix for Unity setting the screen resolution too small

This commit is contained in:
NGnius (Graham) 2021-05-12 16:42:25 -04:00
parent 037a653eca
commit 9b00055a02
3 changed files with 57 additions and 2 deletions

View file

@ -48,6 +48,7 @@ namespace CLre
// patches for bugs // patches for bugs
Fixes.InitLogSooner.Init(); Fixes.InitLogSooner.Init();
Fixes.MiniScreenHelper.Init();
// misc // misc
LogIPAPlugins(); LogIPAPlugins();
@ -118,7 +119,7 @@ namespace CLre
int modCount = IllusionInjector.PluginManager.Plugins.Count(); int modCount = IllusionInjector.PluginManager.Plugins.Count();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendFormat(" {0} {1}\n", Name, Version); 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 #if DEBUG
sb.AppendFormat(" DEBUG version\n"); sb.AppendFormat(" DEBUG version\n");
#endif #endif

View file

@ -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}");
}
}
}
}
}
}

View file

@ -3,6 +3,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using HarmonyLib; using HarmonyLib;
#if DEBUG
namespace CLre.Fixes namespace CLre.Fixes
{ {
public class StartupSpeedup public class StartupSpeedup
@ -54,4 +55,5 @@ namespace CLre.Fixes
Speedup_Benchmark.test = Stopwatch.StartNew(); Speedup_Benchmark.test = Stopwatch.StartNew();
} }
} }
} }
#endif