uberhalit / EldenRingFpsUnlockAndMore

A small utility to remove frame rate limit, change FOV, add widescreen support and more for Elden Ring
MIT License
1.19k stars 110 forks source link

Request: shortcuts for checking box and "patch game" button, and more #93

Open dgdg123 opened 2 years ago

dgdg123 commented 2 years ago

I like to speed up the game 500% when I die in a boss and gonna have to wait 30s in the "you died" screen, plus loading, plus walking from the check point to the boss room and slow the game back to the default speed when I enter fight is going to start. Its a pain in the ass to do that right now, some shortcuts for those options would be amazing.

the "disable camera auto rotate on movement" worked but I cant disable the feature after I enable it. The box is unchecked, I patched the game but the camera behavior still is "patched". Tried to close the game and reopening it and didnt manage to revert the game back to the default camera behavior. I will check a bit more and post here if anything changes about that.

dcealopez commented 2 years ago

This PR should fix the camera auto rotate disable not working: https://github.com/uberhalit/EldenRingFpsUnlockAndMore/pull/111

smcpeak commented 1 year ago

For my own use, I've hacked in a hotkey to toggle the game speed adjustment. The diff is below (although it won't apply automatically with patch due to unrelated factoring I did nearby). If there is interest, I could make the key customizable and submit a PR.

diff --git a/EldenRingFPSUnlockAndMore/MainWindow.xaml.cs b/EldenRingFPSUnlockAndMore/MainWindow.xaml.cs
index e3b3b95..5762826 100644
--- a/EldenRingFPSUnlockAndMore/MainWindow.xaml.cs
+++ b/EldenRingFPSUnlockAndMore/MainWindow.xaml.cs
@@ -15,6 +15,8 @@ using System.Management;
 using System.Text.RegularExpressions;
 using System.Collections.Generic;
 using System.Security.Principal;
+using System.Windows.Input;
+using System.Windows.Interop;

 namespace EldenRingFPSUnlockAndMore
 {
@@ -69,6 +71,17 @@ namespace EldenRingFPSUnlockAndMore
         internal readonly DispatcherTimer _dispatcherTimerGameCheck = new DispatcherTimer(DispatcherPriority.Send);
         internal readonly BackgroundWorker _bgwScanGame = new BackgroundWorker();

+        /// <summary>
+        /// True if the speed toggle hotkey is registered.
+        /// </summary>
+        internal bool _registeredHotKey = false;
+
+        // Hotkey registration functions.
+        [DllImport("user32.dll")]
+        private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
+        [DllImport("user32.dll")]
+        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
+
         public MainWindow()
         {
             InitializeComponent();
@@ -85,6 +98,21 @@ namespace EldenRingFPSUnlockAndMore
                 Directory.CreateDirectory(appdir);
             _path_logs = Path.Combine(appdir, "logs.log");

+            // Register a global hotkey (F4) to toggle the speed change in-game.
+            IntPtr myWindowHandle = new WindowInteropHelper(this).Handle;
+            if (RegisterHotKey(myWindowHandle, 1 /*id*/, 0, 0x73 /*F4*/))
+            {
+                _registeredHotKey = true;
+
+                // Arrange to intercept the resulting WM_HOTKEY messages.
+                HwndSource source = HwndSource.FromHwnd(myWindowHandle);
+                source.AddHook(new HwndSourceHook(WndProc));
+            }
+            else
+            {
+                LogToFile("RegisterHotKey failed");
+            }
+
             var mutex = new Mutex(true, "ErFpsUnlockAndMore", out bool isNewInstance);
             if (!isNewInstance)
             {
@@ -142,6 +170,25 @@ namespace EldenRingFPSUnlockAndMore
                 }
                 catch { }
             }
+
+            if (_registeredHotKey)
+            {
+                IntPtr myWindowHandle = new WindowInteropHelper(this).Handle;
+                UnregisterHotKey(myWindowHandle, 1 /*id*/);
+            }
+        }
+
+        // Intercepted window message handler.
+        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
+        {
+            const int WM_HOTKEY = 0x0312;
+            if (msg == WM_HOTKEY)
+            {
+                ToggleGameSpeed();
+                handled = true;
+            }
+
+            return IntPtr.Zero;
         }

         /// <summary>
@@ -812,6 +859,13 @@ namespace EldenRingFPSUnlockAndMore
             return true;
         }

+        // Toggle the game speed checkbox, then re-patch.
+        private void ToggleGameSpeed()
+        {
+            cbGameSpeed.IsChecked = !cbGameSpeed.IsChecked;
+            PatchGameSpeed();
+        }
+
         /// <summary>
         /// Checks if the user has called this application as administrator.
         /// </summary>