Skip to content

Commit

Permalink
Runtime env settings: XNATOFNA_DISPLAY_SIZE=WxH & XNATOFNA_DISPLAY_FU…
Browse files Browse the repository at this point in the history
…LLSCREEN=1 / 0
  • Loading branch information
0x0ade committed Oct 26, 2017
1 parent 1519430 commit 96a116d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Helper/XnaToFnaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ public static IntPtr GetProxyFormHandle(this GameWindow window) {
// Only used when --hook-istrialmode / --arr is provided when patching.
public static bool get_IsTrialMode()
=> Environment.GetEnvironmentVariable("XNATOFNA_ISTRIALMODE") != "0";

// This needs to be hooked to check for the env vars at runtime.
public static void ApplyChanges(GraphicsDeviceManager self) {
string forceFullscreen = Environment.GetEnvironmentVariable("XNATOFNA_DISPLAY_FULLSCREEN");
if (forceFullscreen == "0")
self.IsFullScreen = false;
else if (forceFullscreen == "1")
self.IsFullScreen = true;

int forceWidth;
if (int.TryParse(Environment.GetEnvironmentVariable("XNATOFNA_DISPLAY_WIDTH"), out forceWidth))
self.PreferredBackBufferWidth = forceWidth;
int forceHeight;
if (int.TryParse(Environment.GetEnvironmentVariable("XNATOFNA_DISPLAY_HEIGHT"), out forceHeight))
self.PreferredBackBufferHeight = forceHeight;
string[] forceSize = Environment.GetEnvironmentVariable("XNATOFNA_DISPLAY_SIZE").Split('x');
if (forceSize.Length == 2) {
if (int.TryParse(forceSize[0], out forceWidth))
self.PreferredBackBufferWidth = forceWidth;
if (int.TryParse(forceSize[1], out forceHeight))
self.PreferredBackBufferHeight = forceHeight;
}

self.ApplyChanges();
}

public static void PreUpdate(GameTime time) {
// Don't ask me why some games use Win32 calls instead of Keyboard.GetState()...
Expand Down
4 changes: 4 additions & 0 deletions src/XnaToFnaUtil.Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public void SetupHelperRelinker() {
Modder.RelinkMap["System.IntPtr Microsoft.Xna.Framework.GameWindow::get_Handle()"] =
Tuple.Create("XnaToFna.XnaToFnaHelper", "System.IntPtr GetProxyFormHandle(Microsoft.Xna.Framework.GameWindow)");

// X360 games can be larger than the screen. Allow the user to "fix" this by forcing a display resolution via env vars.
Modder.RelinkMap["System.Void Microsoft.Xna.Framework.GraphicsDeviceManager::ApplyChanges()"] =
Tuple.Create("XnaToFna.XnaToFnaHelper", "System.Void ApplyChanges(Microsoft.Xna.Framework.GraphicsDeviceManager)");

// Let's just completely wreck everything.
foreach (Type type in typeof(Form).Assembly.GetTypes()) {
string name = type.FullName;
Expand Down

0 comments on commit 96a116d

Please sign in to comment.