From 53fd55c3b96bc650d3b8a59671366c7b14ffe481 Mon Sep 17 00:00:00 2001 From: uberhalit Date: Tue, 4 Feb 2020 19:39:05 +0100 Subject: [PATCH] added support for windows' high contrast mode fixed a file race condition with OBS --- README.md | 7 +++- SekiroFpsUnlockAndMore/GameData.cs | 8 +--- SekiroFpsUnlockAndMore/MainWindow.xaml | 4 +- SekiroFpsUnlockAndMore/MainWindow.xaml.cs | 37 ++++++++++++++++++- .../Properties/AssemblyInfo.cs | 6 +-- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 84fd6cb..6b5d61e 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ Whenever you upgrade your prosthetic arm the maximum spirit emblem capacity will Slow down the game to beat a boss like a game journalist or speed it up and become gud. Game speed acts as a global time scale and is used by the game itself to create a dramatic effect in a few cutscenes. All game physics (even opening the menu) will be affected equally: all time-critical windows like dodge and deflect will be proportionally prolonged or shortened while the amount of damage given and taken as well as all other damage physics will be unaltered. A hit from an enemy on 150% game speed will do the exact same damage as on 80%, the deflect window on 50% is exactly twice as long as on 100% and so on. Of course, Sekiro himself will be affected by the speed too so even though a time window might be different now, the speed which you can react on it is different too. Can be toggled by pressing CTRL+M. Be aware that both speed modifications can potentially crash the game in certain cutscenes and NPC interactions so use them with caution. ### On 'Player speed': -This modifier enables you to control Sekiro's speed independently from general game speed. Combat physics however are not guaranteed to stay the same on every setting. For example if you increase player speed you will be able to react to an attack faster but your own 'deflect' window is shorter now because you move faster. Use this to explore the world or to keep player speed near normal while altering general game speed. Grappling as well as jumping is handled by game speed while falling damage is calculated based on player speed so take care when grappling to a lower level with a low game speed and high player speed as this could instantly kill you as the game thinks you fell to death. +This modifier enables you to control Sekiro's speed independently from general game speed. Combat physics however are not guaranteed to stay the same on every setting. For example if you increase player speed you will be able to react to an attack faster but your own 'deflect' window is shorter now because you move faster. Use this to explore the world or to keep player speed near normal while altering general game speed. Grappling as well as jumping is handled by game speed while falling damage is calculated based on player speed so take care when grappling to a lower level with a low game speed and high player speed as this could instantly kill you as the game thinks you fell to death. Can be toggled by pressing CTRL+M. Be aware that both speed modifications can potentially crash the game in certain cutscenes and NPC interactions so use them with caution. ## Troubleshooting: @@ -190,7 +190,7 @@ Be aware that both speed modifications can potentially crash the game in certain ## Preview -[![Sekiro FPS Unlocker and more](https://camo.githubusercontent.com/998730c9a8d472c8e426f61d0dde589661b4f378/68747470733a2f2f692e696d6775722e636f6d2f466249424271742e706e67)](#) +[![Sekiro FPS Unlocker and more](https://camo.githubusercontent.com/825b3ef500ce18358566b0ec96a74555eddf2603/68747470733a2f2f692e696d6775722e636f6d2f4868396335634a2e706e67)](#) ### Unlocked framerate [![Sekiro FPS Unlocker and more](https://camo.githubusercontent.com/53f52adb98a5111b31538466f91b58599d56d6d7/68747470733a2f2f692e696d6775722e636f6d2f4c4c524a5a554c2e706e67)](#) @@ -240,6 +240,9 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file ## Version History +* v1.2.5.1 (2020-02-04) + * added support for windows' high contrast mode (thanks to [khvorov45](https://github.com/khvorov45) for pointing it out) + * focus of the game won't be stolen anymore when OBS and the utility try to write/read the stats log files at the same time * v1.2.5.0 (2019-05-04) * added feature to automatically loot enemies * v1.2.4.0 (2019-05-02) diff --git a/SekiroFpsUnlockAndMore/GameData.cs b/SekiroFpsUnlockAndMore/GameData.cs index 6da9ad7..b8afa89 100644 --- a/SekiroFpsUnlockAndMore/GameData.cs +++ b/SekiroFpsUnlockAndMore/GameData.cs @@ -193,7 +193,7 @@ namespace SekiroFpsUnlockAndMore /** - Controls camera pitch. xmm4 holds new pitch from a calculation while rps+170 holds current one from mouse so we overwrite xmm4 with the old pitch value. + Controls camera pitch. xmm4 holds new pitch from a calculation while rsi+170 holds current one from mouse so we overwrite xmm4 with the old pitch value. 000000014073AF86 | 0F29A5 70080000 | movaps xmmword ptr ss:[rbp+870],xmm4 | code inject overwrite from here 000000014073AF8D | 0F29A5 80080000 | movaps xmmword ptr ss:[rbp+880],xmm4 | jump back here from code inject 000000014073AF94 | 0F29A6 70010000 | movaps xmmword ptr ds:[rsi+170],xmm4 | camPitch, newCamPitch @@ -230,12 +230,6 @@ namespace SekiroFpsUnlockAndMore Controls automatic camera pitch adjust on move on XY-axis. Pointer in rax holds new pitch while rsi+170 holds current one prior movement so we overwrite xmm0 with the old pitch value and then overwrite [rax] with xmm0. Breaks Pitch on emulated controllers... - 000000014073B476 | F3:0F1000 | movss xmm0,dword ptr ds:[rax] | newCamPitch | code inject overwrite from here - 000000014073B47A | F3:0F1186 70010000 | movss dword ptr ds:[rsi+170],xmm0 | camPitch - 000000014073B482 | F3:0F1085 E4120000 | movss xmm0,dword ptr ss:[rbp+12E4] | jump back here from code inject - 000000014073B48A | E8 91BDFFFF | call sekiro.140737220 | - 000000014073B48F | 0F28D0 | movaps xmm2,xmm0 | - 000000014073B4D6 | F3:0F1000 | movss xmm0,dword ptr ds:[rax] | newCamPitch | code inject overwrite from here 000000014073B4DA | F3:0F1186 70010000 | movss dword ptr ds:[rsi+170],xmm0 | camePitch 000000014073B4E2 | F3:0F1085 E4120000 | movss xmm0,dword ptr ss:[rbp+12E4] | jump back here from code inject diff --git a/SekiroFpsUnlockAndMore/MainWindow.xaml b/SekiroFpsUnlockAndMore/MainWindow.xaml index e4a1eec..13cb786 100644 --- a/SekiroFpsUnlockAndMore/MainWindow.xaml +++ b/SekiroFpsUnlockAndMore/MainWindow.xaml @@ -7,7 +7,7 @@ mc:Ignorable="d" Title="Sekiro FPS Unlocker and more v1.2.5" Width="Auto" Height="Auto" SizeToContent="WidthAndHeight" ResizeMode="CanMinimize" Loaded="Window_Loaded" Closing="Window_Closing"> - + @@ -33,7 +33,7 @@ - + diff --git a/SekiroFpsUnlockAndMore/MainWindow.xaml.cs b/SekiroFpsUnlockAndMore/MainWindow.xaml.cs index 10bc6b0..babe961 100644 --- a/SekiroFpsUnlockAndMore/MainWindow.xaml.cs +++ b/SekiroFpsUnlockAndMore/MainWindow.xaml.cs @@ -93,6 +93,25 @@ namespace SekiroFpsUnlockAndMore } GC.KeepAlive(mutex); + try + { + HIGHCONTRAST highContrastInfo = new HIGHCONTRAST(); + highContrastInfo.cbSize = Marshal.SizeOf(typeof(HIGHCONTRAST)); + if (SystemParametersInfo(SPI_GETHIGHCONTRAST, (uint)highContrastInfo.cbSize, ref highContrastInfo, 0)) + { + if ((highContrastInfo.dwFlags & HCF_HIGHCONTRASTON) == 1) + { + // high contrast mode is active, remove grid background color and let the OS handle it + gMainGrid.Background = null; + gSubGrid1.Background = null; + } + } + } + catch (Exception ex) + { + Debug.WriteLine("Could not fetch SystemParameters: " + ex.Message); + } + _path_logs = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\SekiroFpsUnlockAndMore.log"; _path_deathsLog = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\DeathCounter.txt"; _path_killsLog = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\TotalKillsCounter.txt"; @@ -1619,7 +1638,9 @@ namespace SekiroFpsUnlockAndMore } catch (Exception ex) { - MessageBox.Show("Failed writing stats file: " + ex.Message, "Sekiro Fps Unlock And More"); + LogToFile("Failed writing stats file: " + ex.Message); + // don't show a messagebox as this will potentially steal focus from game + //MessageBox.Show("Failed writing stats file: " + ex.Message, "Sekiro Fps Unlock And More"); } } @@ -1873,6 +1894,8 @@ namespace SekiroFpsUnlockAndMore private const uint SWP_FRAMECHANGED = 0x0020; private const uint SWP_SHOWWINDOW = 0x0040; private const int ZUH_HIDDEN_DP = 0x7; + private const uint SPI_GETHIGHCONTRAST = 0x0042; + private const int HCF_HIGHCONTRASTON = 0x00000001; [DllImport("user32.dll")] public static extern Boolean RegisterHotKey(IntPtr hWnd, Int32 id, UInt32 fsModifiers, UInt32 vlc); @@ -1889,6 +1912,18 @@ namespace SekiroFpsUnlockAndMore [DllImport("kernel32.dll", SetLastError = true)] private static extern Boolean CloseHandle(IntPtr hObject); + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + private struct HIGHCONTRAST + { + public int cbSize; + public int dwFlags; + public IntPtr lpszDefaultScheme; + } + + [DllImport("user32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, ref HIGHCONTRAST pvParam, UInt32 fWinIni); + [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, Int32 nIndex); diff --git a/SekiroFpsUnlockAndMore/Properties/AssemblyInfo.cs b/SekiroFpsUnlockAndMore/Properties/AssemblyInfo.cs index 0e1357a..43099e5 100644 --- a/SekiroFpsUnlockAndMore/Properties/AssemblyInfo.cs +++ b/SekiroFpsUnlockAndMore/Properties/AssemblyInfo.cs @@ -7,7 +7,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("uberhalit")] [assembly: AssemblyProduct("SekiroFpsUnlockAndMore")] -[assembly: AssemblyCopyright("Copyright © uberhalit 2019")] +[assembly: AssemblyCopyright("Copyright © uberhalit 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -18,5 +18,5 @@ using System.Runtime.InteropServices; ResourceDictionaryLocation.SourceAssembly )] -[assembly: AssemblyVersion("1.2.5.0")] -[assembly: AssemblyFileVersion("1.2.5.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.5.1")] +[assembly: AssemblyFileVersion("1.2.5.1")] \ No newline at end of file