Skip to content

Commit

Permalink
added support for windows' high contrast mode
Browse files Browse the repository at this point in the history
fixed a file race condition with OBS
  • Loading branch information
uberhalit committed Feb 4, 2020
1 parent f485974 commit 53fd55c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)](#)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions SekiroFpsUnlockAndMore/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Reference pointer pFovTableEntry to FOV entry in game FOV table that gets used i


/**
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
Expand Down Expand Up @@ -230,12 +230,6 @@ Reference pointer pFovTableEntry to FOV entry in game FOV table that gets used i
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
Expand Down
4 changes: 2 additions & 2 deletions SekiroFpsUnlockAndMore/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<Grid Background="#FFF9F9F9">
<Grid x:Name="gMainGrid" Background="#FFF9F9F9">
<DockPanel>
<StackPanel DockPanel.Dock="Top" Margin="10,10,10,0" Width="300" Height="Auto">
<DockPanel LastChildFill="False">
Expand All @@ -33,7 +33,7 @@
</StackPanel>
<CheckBox x:Name="cbLogStats" Margin="0,5,0,0" Height="25" FontSize="14 px" VerticalContentAlignment="Center" Content="Log stats (Deaths, Kills) to file for OBS" ToolTip="Check the guide on how to display these on stream with OBS" Checked="CbStatChanged" Unchecked="CbStatChanged" TabIndex="10" />
<Expander x:Name="exGameMods" Margin="-3,5,0,0" Height="Auto" FontSize="14 px" Header="Modifications" IsExpanded="True" TabIndex="11">
<Grid Margin="3,1,0,0" Background="#FFF9F9F9">
<Grid x:Name="gSubGrid1" Margin="3,1,0,0" Background="#FFF9F9F9">
<StackPanel Width="Auto" Height="Auto">
<CheckBox x:Name="cbCamAdjust" Margin="0,5,0,0" Height="25" FontSize="14 px" VerticalContentAlignment="Center" Content="Disable camera auto rotate on movement" ToolTip="Disables the annoying automatic camera adjustment on movement. Intended for mouse users" Checked="CbCamAdjust_Check_Handler" Unchecked="CbCamAdjust_Check_Handler" TabIndex="12" />
<CheckBox x:Name="cbCamReset" Margin="0,3,0,0" Height="25" FontSize="14 px" VerticalContentAlignment="Center" Content="Disable camera reset on lock-on" ToolTip="Disables the annoying camera centering on lock-on when there is no target" Checked="CbCamReset_Check_Handler" Unchecked="CbCamReset_Check_Handler" TabIndex="13" />
Expand Down
37 changes: 36 additions & 1 deletion SekiroFpsUnlockAndMore/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
}
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";
Expand Down Expand Up @@ -1619,7 +1638,9 @@ private void LogStatsFile(string filename, string msg)
}
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");
}
}

Expand Down Expand Up @@ -1873,6 +1894,8 @@ private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.
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);
Expand All @@ -1889,6 +1912,18 @@ private static extern IntPtr OpenProcess(
[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);

Expand Down
6 changes: 3 additions & 3 deletions SekiroFpsUnlockAndMore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("uberhalit")]
[assembly: AssemblyProduct("SekiroFpsUnlockAndMore")]
[assembly: AssemblyCopyright("Copyright © uberhalit 2019")]
[assembly: AssemblyCopyright("Copyright © uberhalit 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -18,5 +18,5 @@
ResourceDictionaryLocation.SourceAssembly
)]

[assembly: AssemblyVersion("1.2.5.0")]
[assembly: AssemblyFileVersion("1.2.5.0")]
[assembly: AssemblyVersion("1.2.5.1")]
[assembly: AssemblyFileVersion("1.2.5.1")]

0 comments on commit 53fd55c

Please sign in to comment.