From f6ec02e48f0009f48974a83475d2f3d59ab1f0b6 Mon Sep 17 00:00:00 2001 From: Underscore76 Date: Sat, 30 Sep 2023 20:27:19 -0500 Subject: [PATCH] add customization option for resolution --- TASMod/ModConfig.cs | 11 +++++++++++ TASMod/ModEntry.cs | 2 ++ TASMod/Patches/Game1.cs | 14 ++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 TASMod/ModConfig.cs diff --git a/TASMod/ModConfig.cs b/TASMod/ModConfig.cs new file mode 100644 index 0000000..368f2bf --- /dev/null +++ b/TASMod/ModConfig.cs @@ -0,0 +1,11 @@ +using System; +namespace TASMod +{ + public class ModConfig + { + public int ScreenWidth { get; set; } = 1920; + public int ScreenHeight { get; set; } = 1080; + public bool Windowed { get; set; } = true; + } +} + diff --git a/TASMod/ModEntry.cs b/TASMod/ModEntry.cs index 7af7a84..a8b1e8f 100644 --- a/TASMod/ModEntry.cs +++ b/TASMod/ModEntry.cs @@ -22,6 +22,7 @@ namespace TASMod { public class ModEntry : Mod { + public static ModConfig Config; public static ModEntry Instance; public static IReflectionHelper Reflection => Instance.Helper.Reflection; public static IMonitor Console => Instance.Monitor; @@ -29,6 +30,7 @@ public class ModEntry : Mod public override void Entry(IModHelper helper) { Instance = this; + Config = this.Helper.ReadConfig(); helper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded; helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked; diff --git a/TASMod/Patches/Game1.cs b/TASMod/Patches/Game1.cs index e18d967..beb71dc 100644 --- a/TASMod/Patches/Game1.cs +++ b/TASMod/Patches/Game1.cs @@ -138,12 +138,14 @@ public override void Patch(Harmony harmony) public static bool Prefix(Game1 __instance, ref int w, ref int h) { Trace($"Game1.SetWindowSize {TASDateTime.CurrentFrame} {Game1.graphics.IsFullScreen}"); - Game1.graphics.IsFullScreen = false; - // HARD FORCE THE RESOLUTION - // TODO: Move this to a config that you can set for the mod - w = 1920; - h = 1080; - __instance.Window.BeginScreenDeviceChange(false); + bool windowed = ModEntry.Config.Windowed; + Game1.graphics.IsFullScreen = !windowed; + w = ModEntry.Config.ScreenWidth; + h = ModEntry.Config.ScreenHeight; + Game1.options.fullscreen = !windowed; + Game1.options.preferredResolutionX = w; + Game1.options.preferredResolutionY = h; + __instance.Window.BeginScreenDeviceChange(!windowed); __instance.Window.EndScreenDeviceChange(__instance.Window.ScreenDeviceName, w, h); Game1.graphics.PreferredBackBufferWidth = w; Game1.graphics.PreferredBackBufferHeight = h;