Fixed scaling issue in borderless window mode

This commit is contained in:
uberhalit 2019-03-26 03:43:00 +01:00
parent a990d1b955
commit 7829d124ea
4 changed files with 30 additions and 16 deletions

View file

@ -105,8 +105,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
## Credits ## Credits
* jackfuste for FOV findings and running speed fix * jackfuste for FOV findings and running speed fix
* TyChii93 for AMD and widescreen testing * TyChii93#2376 for AMD and widescreen testing
* [Darius Dan](www.dariusdan.com) for the icon * [Darius Dan](https://www.dariusdan.com) for the icon
## Limitations ## Limitations
@ -114,9 +114,11 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
* in fullscreen the game forces the monitor to 60 Hz so you'll have to handle this with driver override too, see Usage * in fullscreen the game forces the monitor to 60 Hz so you'll have to handle this with driver override too, see Usage
* your monitor has to support your custom resolution otherwise it won't show up correctly * your monitor has to support your custom resolution otherwise it won't show up correctly
* due to how the game renders altering FOV will not move the HUD * due to how the game renders altering FOV will not move the HUD
* the HUD is limited to 16/9 even in 21/9 resolutions * the HUD is limited to 16/9 even on 21/9 resolutions
## Version History ## Version History
* v1.0.1 (2019-03-26)
* Fixed scaling issue in borderless window mode (thanks to Spacecop42#0947 for reporting)
* v1.0.0 (2019-03-25) * v1.0.0 (2019-03-25)
* Initial release * Initial release

View file

@ -41,7 +41,7 @@
<Label HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="12 px"> <Label HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="12 px">
<Hyperlink NavigateUri="https://github.com/uberhalit/SekiroFpsUnlockAndMore" RequestNavigate="Hyperlink_RequestNavigate"> <Hyperlink NavigateUri="https://github.com/uberhalit/SekiroFpsUnlockAndMore" RequestNavigate="Hyperlink_RequestNavigate">
v1.0.0 - by uberhalit v1.0.1 - by uberhalit
</Hyperlink> </Hyperlink>
</Label> </Label>
</StackPanel> </StackPanel>

View file

@ -62,8 +62,10 @@ namespace SekiroFpsUnlockAndMore
internal IntPtr _gameProc = IntPtr.Zero; internal IntPtr _gameProc = IntPtr.Zero;
internal static IntPtr _gameProcStatic; internal static IntPtr _gameProcStatic;
internal readonly DispatcherTimer _dispatcherTimerCheck = new DispatcherTimer(); internal readonly DispatcherTimer _dispatcherTimerCheck = new DispatcherTimer();
internal string logPath; internal string _logPath;
internal bool retryAccess = true; internal bool _retryAccess = true;
internal RECT _windowRect;
internal RECT _clientRect;
public MainWindow() public MainWindow()
{ {
@ -75,7 +77,7 @@ namespace SekiroFpsUnlockAndMore
/// </summary> /// </summary>
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
logPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\SekiroFpsUnlockAndMore.log"; _logPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\SekiroFpsUnlockAndMore.log";
this.cbSelectFov.ItemsSource = _fovMatrix; this.cbSelectFov.ItemsSource = _fovMatrix;
this.cbSelectFov.SelectedIndex = 0; this.cbSelectFov.SelectedIndex = 0;
@ -166,7 +168,7 @@ namespace SekiroFpsUnlockAndMore
LogToFile("Hwnd: " + _gameHwnd.ToString("X")); LogToFile("Hwnd: " + _gameHwnd.ToString("X"));
LogToFile("Proc: " + _gameProc.ToString("X")); LogToFile("Proc: " + _gameProc.ToString("X"));
LogToFile("Base: " + procList[gameIndex].MainModule.BaseAddress.ToString("X")); LogToFile("Base: " + procList[gameIndex].MainModule.BaseAddress.ToString("X"));
if (!retryAccess) if (!_retryAccess)
{ {
UpdateStatus("no access to game...", Brushes.Red); UpdateStatus("no access to game...", Brushes.Red);
_dispatcherTimerCheck.Stop(); _dispatcherTimerCheck.Stop();
@ -180,7 +182,7 @@ namespace SekiroFpsUnlockAndMore
_gameProcStatic = IntPtr.Zero; _gameProcStatic = IntPtr.Zero;
} }
LogToFile("retrying..."); LogToFile("retrying...");
retryAccess = false; _retryAccess = false;
return; return;
} }
@ -239,6 +241,8 @@ namespace SekiroFpsUnlockAndMore
this.cbFov.IsChecked = false; this.cbFov.IsChecked = false;
} }
GetWindowRect(_gameHwnd, out _windowRect);
GetClientRect(_gameHwnd, out _clientRect);
_running = true; _running = true;
_dispatcherTimerCheck.Stop(); _dispatcherTimerCheck.Stop();
PatchGame(); PatchGame();
@ -426,7 +430,11 @@ namespace SekiroFpsUnlockAndMore
/// <param name="hwnd">The handle to the window.</param> /// <param name="hwnd">The handle to the window.</param>
private void SetWindowWindowed(IntPtr hwnd) private void SetWindowWindowed(IntPtr hwnd)
{ {
var width = _windowRect.Right - _windowRect.Left;
var height = _windowRect.Bottom - _windowRect.Top;
Debug.WriteLine(string.Format("Window Resolution: {0}x{1}", width, height));
SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_CAPTION | WS_BORDER | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_SYSMENU | WS_GROUP | WS_MINIMIZEBOX); SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_CAPTION | WS_BORDER | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_SYSMENU | WS_GROUP | WS_MINIMIZEBOX);
SetWindowPos(hwnd, HWND_NOTOPMOST, 40, 40, width, height, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
} }
/// <summary> /// <summary>
@ -435,10 +443,11 @@ namespace SekiroFpsUnlockAndMore
/// <param name="hwnd">The handle to the window.</param> /// <param name="hwnd">The handle to the window.</param>
private void SetWindowBorderless(IntPtr hwnd) private void SetWindowBorderless(IntPtr hwnd)
{ {
var width = _clientRect.Right - _clientRect.Left;
var height = _clientRect.Bottom - _clientRect.Top;
Debug.WriteLine(string.Format("Client Resolution: {0}x{1}", width, height));
SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP); SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP);
RECT rect; SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, width, height, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
GetWindowRect(hwnd, out rect);
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, rect.Right - rect.Left, rect.Bottom - rect.Top, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
} }
/// <summary> /// <summary>
@ -518,7 +527,7 @@ namespace SekiroFpsUnlockAndMore
Debug.WriteLine(timedMsg); Debug.WriteLine(timedMsg);
try try
{ {
using (StreamWriter writer = new StreamWriter(logPath, true)) using (StreamWriter writer = new StreamWriter(_logPath, true))
{ {
writer.WriteLine(timedMsg); writer.WriteLine(timedMsg);
} }
@ -578,6 +587,9 @@ namespace SekiroFpsUnlockAndMore
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect); public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
[DllImport("user32.dll")]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct RECT public struct RECT
{ {

View file

@ -21,5 +21,5 @@ using System.Windows;
ResourceDictionaryLocation.SourceAssembly ResourceDictionaryLocation.SourceAssembly
)] )]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.1.0")]