Skip to content

Commit

Permalink
add customization option for resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Underscore76 committed Oct 1, 2023
1 parent f0fbc4b commit f6ec02e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
11 changes: 11 additions & 0 deletions TASMod/ModConfig.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

2 changes: 2 additions & 0 deletions TASMod/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ 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;

public override void Entry(IModHelper helper)
{
Instance = this;
Config = this.Helper.ReadConfig<ModConfig>();

helper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded;
helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked;
Expand Down
14 changes: 8 additions & 6 deletions TASMod/Patches/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f6ec02e

Please sign in to comment.