aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/latencyflex.cpp
diff options
context:
space:
mode:
authorKyle Gospodnetich <KyleGospo@users.noreply.github.com>2022-01-14 18:38:26 -0800
committerGitHub <noreply@github.com>2022-01-14 23:38:26 -0300
commit0fdbe2237df643b0327a0906e8d399a6e458ae87 (patch)
tree5fc9420ac6f82764a8059c242cfa9f8d7ddfb63a /NorthstarDedicatedTest/latencyflex.cpp
parente272e2b2d2898029c4fd2c285db24e2d4b70a0f2 (diff)
downloadNorthstarLauncher-0fdbe2237df643b0327a0906e8d399a6e458ae87.tar.gz
NorthstarLauncher-0fdbe2237df643b0327a0906e8d399a6e458ae87.zip
LatencyFleX Implementation (#41)
* Adds LatencyFleX, an open source and vendor agnostic input latency reduction technology similar to Nvidia's Reflex. Currently only works on Linux via Wine/Proton, but future versions may support Windows as well. Falls back to doing nothing if LatencyFleX isn't available. See here for more information: https://ishitatsuyuki.github.io/post/latencyflex/ * Add the ability to toggle LatencyFlex on or off with a cvar.
Diffstat (limited to 'NorthstarDedicatedTest/latencyflex.cpp')
-rw-r--r--NorthstarDedicatedTest/latencyflex.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/latencyflex.cpp b/NorthstarDedicatedTest/latencyflex.cpp
new file mode 100644
index 00000000..84b79d33
--- /dev/null
+++ b/NorthstarDedicatedTest/latencyflex.cpp
@@ -0,0 +1,47 @@
+#include "pch.h"
+#include "latencyflex.h"
+#include "hookutils.h"
+#include "dedicated.h"
+#include "convar.h"
+
+typedef void(*OnRenderStartType)();
+OnRenderStartType OnRenderStart;
+
+ConVar* Cvar_r_latencyflex;
+
+HMODULE m_lfxModule{};
+typedef void (*PFN_winelfx_WaitAndBeginFrame)();
+PFN_winelfx_WaitAndBeginFrame m_winelfx_WaitAndBeginFrame{};
+
+void OnRenderStartHook()
+{
+ if (Cvar_r_latencyflex->m_nValue)
+ m_winelfx_WaitAndBeginFrame();
+
+ OnRenderStart();
+}
+
+void InitialiseLatencyFleX(HMODULE baseAddress)
+{
+ if (IsDedicated())
+ return;
+
+ // 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/
+ m_lfxModule = LoadLibraryA("latencyflex_wine.dll");
+
+ if (m_lfxModule == nullptr)
+ {
+ spdlog::info("Unable to load LatencyFleX library, LatencyFleX disabled.");
+ return;
+ }
+
+ m_winelfx_WaitAndBeginFrame = reinterpret_cast<PFN_winelfx_WaitAndBeginFrame>(reinterpret_cast<void*>(GetProcAddress(m_lfxModule,"winelfx_WaitAndBeginFrame")));
+ spdlog::info("LatencyFleX initialized.");
+
+ Cvar_r_latencyflex = RegisterConVar("r_latencyflex", "1", FCVAR_ARCHIVE, "Whether or not to use LatencyFleX input latency reduction.");
+
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1952C0, &OnRenderStartHook, reinterpret_cast<LPVOID*>(&OnRenderStart));
+} \ No newline at end of file