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