Skip to content

Commit

Permalink
add hooks for getting/setting viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
sd805 committed Jun 8, 2022
1 parent 15a77e5 commit 54431c5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
31 changes: 31 additions & 0 deletions L4D2VR/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Hooks::Hooks(Game *game)
hkReadUsercmd.enableHook();
hkWriteUsercmdDeltaToBuffer.enableHook();
hkWriteUsercmd.enableHook();
hkAdjustEngineViewport.enableHook();
hkViewport.enableHook();
hkGetViewport.enableHook();
}

Hooks::~Hooks()
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
9 changes: 9 additions & 0 deletions L4D2VR/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,6 +91,9 @@ class Hooks
static inline Hook<tReadUsercmd> hkReadUsercmd;
static inline Hook<tWriteUsercmdDeltaToBuffer> hkWriteUsercmdDeltaToBuffer;
static inline Hook<tWriteUsercmd> hkWriteUsercmd;
static inline Hook<tAdjustEngineViewport> hkAdjustEngineViewport;
static inline Hook<tViewport> hkViewport;
static inline Hook<tGetViewport> hkGetViewport;

Hooks() {};
Hooks(Game *game);
Expand All @@ -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);
};
3 changes: 3 additions & 0 deletions L4D2VR/l4d2vr.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@
<ItemGroup>
<ResourceCompile Include="..\dxvk\src\d3d9\version.rc" />
</ItemGroup>
<ItemGroup>
<Text Include="config.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
5 changes: 5 additions & 0 deletions L4D2VR/l4d2vr.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1240,4 +1240,9 @@
<Filter>dxvk</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Text Include="config.txt">
<Filter>Source Files</Filter>
</Text>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions L4D2VR/offsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ 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" };
Offset ProcessUsercmds = { "server.dll", 0xEF710, "55 8B EC B8 ? ? ? ? E8 ? ? ? ? A1 ? ? ? ? 33 C5 89 45 FC 8B 45 0C 8B 55 08" };
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 ? ?" };

};

0 comments on commit 54431c5

Please sign in to comment.