From 54431c5813ca13d45c281303201769390f43ae80 Mon Sep 17 00:00:00 2001 From: Shane Davis Date: Tue, 7 Jun 2022 20:26:45 -0700 Subject: [PATCH] add hooks for getting/setting viewport --- L4D2VR/hooks.cpp | 31 +++++++++++++++++++++++++++++++ L4D2VR/hooks.h | 9 +++++++++ L4D2VR/l4d2vr.vcxproj | 3 +++ L4D2VR/l4d2vr.vcxproj.filters | 5 +++++ L4D2VR/offsets.h | 4 ++++ 5 files changed, 52 insertions(+) diff --git a/L4D2VR/hooks.cpp b/L4D2VR/hooks.cpp index 1b8508f..e27088b 100644 --- a/L4D2VR/hooks.cpp +++ b/L4D2VR/hooks.cpp @@ -26,6 +26,9 @@ Hooks::Hooks(Game *game) hkReadUsercmd.enableHook(); hkWriteUsercmdDeltaToBuffer.enableHook(); hkWriteUsercmd.enableHook(); + hkAdjustEngineViewport.enableHook(); + hkViewport.enableHook(); + hkGetViewport.enableHook(); } Hooks::~Hooks() @@ -70,6 +73,15 @@ int Hooks::initSourceHooks() LPVOID WriteUsercmdAddr = (LPVOID)(m_Game->m_Offsets->WriteUsercmd.address); hkWriteUsercmd.createHook(WriteUsercmdAddr, &dWriteUsercmd); + LPVOID AdjustEngineViewportAddr = (LPVOID)(m_Game->m_Offsets->AdjustEngineViewport.address); + hkAdjustEngineViewport.createHook(AdjustEngineViewportAddr, &dAdjustEngineViewport); + + LPVOID ViewportAddr = (LPVOID)(m_Game->m_Offsets->Viewport.address); + hkViewport.createHook(ViewportAddr, &dViewport); + + LPVOID GetViewportAddr = (LPVOID)(m_Game->m_Offsets->GetViewport.address); + hkGetViewport.createHook(GetViewportAddr, &dGetViewport); + return 1; } @@ -281,4 +293,23 @@ int Hooks::dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from) } return hkWriteUsercmd.fOriginal(buf, to, from); +} + +void Hooks::dAdjustEngineViewport(int &x, int &y, int &width, int &height) +{ + hkAdjustEngineViewport.fOriginal(x, y, width, height); +} + +void Hooks::dViewport(void *ecx, void *edx, int x, int y, int width, int height) +{ + + //hkViewport.fOriginal(ecx, x, y, 1800, 1800); + hkViewport.fOriginal(ecx, x, y, width, height); +} + +void Hooks::dGetViewport(void *ecx, void *edx, int &x, int &y, int &width, int &height) +{ + //int newWidth = 1000; + //int newHeight = 1000; + hkGetViewport.fOriginal(ecx, x, y, width, height); } \ No newline at end of file diff --git a/L4D2VR/hooks.h b/L4D2VR/hooks.h index 58afb1a..e42f160 100644 --- a/L4D2VR/hooks.h +++ b/L4D2VR/hooks.h @@ -69,6 +69,9 @@ typedef float(__thiscall *tProcessUsercmds)(void *thisptr, edict_t *player, void typedef int(__cdecl *tReadUsercmd)(void *buf, CUserCmd *move, CUserCmd *from); typedef void(__thiscall *tWriteUsercmdDeltaToBuffer)(void *thisptr, int a1, void *buf, int from, int to, bool isnewcommand); typedef int(__cdecl *tWriteUsercmd)(void *buf, CUserCmd *to, CUserCmd *from); +typedef int(__cdecl *tAdjustEngineViewport)(int &x, int &y, int &width, int &height); +typedef void(__thiscall *tViewport)(void *thisptr, int x, int y, int width, int height); +typedef void(__thiscall *tGetViewport)(void *thisptr, int &x, int &y, int &width, int &height); class Hooks @@ -88,6 +91,9 @@ class Hooks static inline Hook hkReadUsercmd; static inline Hook hkWriteUsercmdDeltaToBuffer; static inline Hook hkWriteUsercmd; + static inline Hook hkAdjustEngineViewport; + static inline Hook hkViewport; + static inline Hook hkGetViewport; Hooks() {}; Hooks(Game *game); @@ -108,4 +114,7 @@ class Hooks static int dReadUsercmd(void *buf, CUserCmd *move, CUserCmd *from); static void __fastcall dWriteUsercmdDeltaToBuffer(void *ecx, void *edx, int a1, void *buf, int from, int to, bool isnewcommand); static int dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from); + static void dAdjustEngineViewport(int &x, int &y, int &width, int &height); + static void __fastcall dViewport(void *ecx, void *edx, int x, int y, int width, int height); + static void __fastcall dGetViewport(void *ecx, void *edx, int &x, int &y, int &width, int &height); }; \ No newline at end of file diff --git a/L4D2VR/l4d2vr.vcxproj b/L4D2VR/l4d2vr.vcxproj index 8dcce22..3725405 100644 --- a/L4D2VR/l4d2vr.vcxproj +++ b/L4D2VR/l4d2vr.vcxproj @@ -597,6 +597,9 @@ + + + diff --git a/L4D2VR/l4d2vr.vcxproj.filters b/L4D2VR/l4d2vr.vcxproj.filters index b4c5491..b0ad9b2 100644 --- a/L4D2VR/l4d2vr.vcxproj.filters +++ b/L4D2VR/l4d2vr.vcxproj.filters @@ -1240,4 +1240,9 @@ dxvk + + + Source Files + + \ No newline at end of file diff --git a/L4D2VR/offsets.h b/L4D2VR/offsets.h index 174912d..9021304 100644 --- a/L4D2VR/offsets.h +++ b/L4D2VR/offsets.h @@ -44,6 +44,7 @@ class Offsets Offset WriteUsercmdDeltaToBuffer = { "client.dll", 0x134790, "55 8B EC 83 EC 60 0F 57 C0 8B 55 0C" }; Offset WriteUsercmd = { "client.dll", 0x1AAD50, "55 8B EC A1 ? ? ? ? 83 78 30 00 53 8B 5D 10 56 57" }; Offset g_pppInput = { "client.dll", 0xA8A22, "8B 0D ? ? ? ? 8B 01 8B 50 58 FF E2", 2 }; + Offset AdjustEngineViewport = { "client.dll", 0x31A890, "55 8B EC 8B 0D ? ? ? ? 85 C9 74 17" }; Offset ServerFireTerrorBullets = { "server.dll", 0x3C3FC0, "55 8B EC 81 EC ? ? ? ? A1 ? ? ? ? 33 C5 89 45 FC 8B 45 08 8B 4D 10" }; Offset ReadUserCmd = { "server.dll", 0x205100, "55 8B EC 53 8B 5D 10 56 57 8B 7D 0C 53" }; @@ -51,4 +52,7 @@ class Offsets Offset CBaseEntity_entindex = { "server.dll", 0x25390, "8B 41 28 85 C0 75 01 C3 8B 0D ? ? ? ? 2B 41 58 C1 F8 04 C3 CC CC CC CC CC CC CC CC CC CC CC 55"}; Offset GetRenderTarget = { "materialsystem.dll", 0x2CD30, "83 79 4C 00" }; + Offset Viewport = { "materialsystem.dll", 0x2E010, "55 8B EC 83 EC 28 8B C1" }; + Offset GetViewport = { "materialsystem.dll", 0x2D240, "55 8B EC 8B 41 4C 8B 49 40 8D 04 C0 83 7C 81 ? ?" }; + }; \ No newline at end of file