aboutsummaryrefslogtreecommitdiff
path: root/primedev/client/latencyflex.cpp
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2023-12-27 00:32:01 +0000
committerGitHub <noreply@github.com>2023-12-27 01:32:01 +0100
commitf5ab6fb5e8be7b73e6003d4145081d5e0c0ce287 (patch)
tree90f2c6a4885dbd181799e2325cf33588697674e1 /primedev/client/latencyflex.cpp
parentbb8ed59f6891b1196c5f5bbe7346cd171c8215fa (diff)
downloadNorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.tar.gz
NorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.zip
Folder restructuring from primedev (#624)v1.21.2-rc3v1.21.2
Copies of over the primedev folder structure for easier cherry-picking of further changes Co-authored-by: F1F7Y <filip.bartos07@proton.me>
Diffstat (limited to 'primedev/client/latencyflex.cpp')
-rw-r--r--primedev/client/latencyflex.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/primedev/client/latencyflex.cpp b/primedev/client/latencyflex.cpp
new file mode 100644
index 00000000..25e38c7a
--- /dev/null
+++ b/primedev/client/latencyflex.cpp
@@ -0,0 +1,43 @@
+#include "core/convar/convar.h"
+
+AUTOHOOK_INIT()
+
+ConVar* Cvar_r_latencyflex;
+
+void (*m_winelfx_WaitAndBeginFrame)();
+
+// clang-format off
+AUTOHOOK(OnRenderStart, client.dll + 0x1952C0,
+void, __fastcall, ())
+// clang-format on
+{
+ if (Cvar_r_latencyflex->GetBool() && m_winelfx_WaitAndBeginFrame)
+ m_winelfx_WaitAndBeginFrame();
+
+ OnRenderStart();
+}
+
+ON_DLL_LOAD_CLIENT_RELIESON("client.dll", LatencyFlex, ConVar, (CModule module))
+{
+ // Connect to the LatencyFleX service
+ // LatencyFleX is an open source vendor agnostic replacement for Nvidia Reflex input latency reduction technology.
+ // https://ishitatsuyuki.github.io/post/latencyflex/
+ HMODULE pLfxModule;
+
+ if (pLfxModule = LoadLibraryA("latencyflex_layer.dll"))
+ m_winelfx_WaitAndBeginFrame =
+ reinterpret_cast<void (*)()>(reinterpret_cast<void*>(GetProcAddress(pLfxModule, "lfx_WaitAndBeginFrame")));
+ else if (pLfxModule = LoadLibraryA("latencyflex_wine.dll"))
+ m_winelfx_WaitAndBeginFrame =
+ reinterpret_cast<void (*)()>(reinterpret_cast<void*>(GetProcAddress(pLfxModule, "winelfx_WaitAndBeginFrame")));
+ else
+ {
+ spdlog::info("Unable to load LatencyFleX library, LatencyFleX disabled.");
+ return;
+ }
+
+ AUTOHOOK_DISPATCH()
+
+ spdlog::info("LatencyFleX initialized.");
+ Cvar_r_latencyflex = new ConVar("r_latencyflex", "1", FCVAR_ARCHIVE, "Whether or not to use LatencyFleX input latency reduction.");
+}