Skip to content

Commit 4eb589d

Browse files
committed
Added bitbuf classes, additional cleanup
1 parent f7e003c commit 4eb589d

File tree

5 files changed

+1683
-60
lines changed

5 files changed

+1683
-60
lines changed

L4D2VR/hooks.cpp

Lines changed: 69 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Hooks::~Hooks()
7070

7171
int Hooks::initSourceHooks()
7272
{
73-
LPVOID pGetRenderTargetVFunc = (LPVOID)(m_Game->m_Offsets->GetRenderTarget.address);
74-
hkGetRenderTarget.createHook(pGetRenderTargetVFunc, &dGetRenderTarget);
73+
/*LPVOID pGetRenderTargetVFunc = (LPVOID)(m_Game->m_Offsets->GetRenderTarget.address);
74+
hkGetRenderTarget.createHook(pGetRenderTargetVFunc, &dGetRenderTarget);*/
7575

7676
LPVOID pRenderViewVFunc = (LPVOID)(m_Game->m_Offsets->RenderView.address);
7777
hkRenderView.createHook(pRenderViewVFunc, &dRenderView);
@@ -91,14 +91,14 @@ int Hooks::initSourceHooks()
9191
LPVOID WriteUsercmdAddr = (LPVOID)(m_Game->m_Offsets->WriteUsercmd.address);
9292
hkWriteUsercmd.createHook(WriteUsercmdAddr, &dWriteUsercmd);
9393

94-
LPVOID AdjustEngineViewportAddr = (LPVOID)(m_Game->m_Offsets->AdjustEngineViewport.address);
94+
/*LPVOID AdjustEngineViewportAddr = (LPVOID)(m_Game->m_Offsets->AdjustEngineViewport.address);
9595
hkAdjustEngineViewport.createHook(AdjustEngineViewportAddr, &dAdjustEngineViewport);
9696
9797
LPVOID ViewportAddr = (LPVOID)(m_Game->m_Offsets->Viewport.address);
9898
hkViewport.createHook(ViewportAddr, &dViewport);
9999
100100
LPVOID GetViewportAddr = (LPVOID)(m_Game->m_Offsets->GetViewport.address);
101-
hkGetViewport.createHook(GetViewportAddr, &dGetViewport);
101+
hkGetViewport.createHook(GetViewportAddr, &dGetViewport);*/
102102

103103
LPVOID EyePositionAddr = (LPVOID)(m_Game->m_Offsets->EyePosition.address);
104104
hkEyePosition.createHook(EyePositionAddr, &dEyePosition);
@@ -115,14 +115,14 @@ int Hooks::initSourceHooks()
115115
LPVOID VGui_PaintAddr = (LPVOID)(m_Game->m_Offsets->VGui_Paint.address);
116116
hkVgui_Paint.createHook(VGui_PaintAddr, &dVGui_Paint);
117117

118-
LPVOID IsSplitScreenAddr = (LPVOID)(m_Game->m_Offsets->IsSplitScreen.address);
119-
hkIsSplitScreen.createHook(IsSplitScreenAddr, &dIsSplitScreen);
118+
/*LPVOID IsSplitScreenAddr = (LPVOID)(m_Game->m_Offsets->IsSplitScreen.address);
119+
hkIsSplitScreen.createHook(IsSplitScreenAddr, &dIsSplitScreen);*/
120120

121121
LPVOID PrePushRenderTargetAddr = (LPVOID)(m_Game->m_Offsets->PrePushRenderTarget.address);
122122
hkPrePushRenderTarget.createHook(PrePushRenderTargetAddr, &dPrePushRenderTarget);
123123

124-
LPVOID GetFullScreenTextureAddr = (LPVOID)(m_Game->m_Offsets->GetFullScreenTexture.address);
125-
hkGetFullScreenTexture.createHook(GetFullScreenTextureAddr, &dGetFullScreenTexture);
124+
/*LPVOID GetFullScreenTextureAddr = (LPVOID)(m_Game->m_Offsets->GetFullScreenTexture.address);
125+
hkGetFullScreenTexture.createHook(GetFullScreenTextureAddr, &dGetFullScreenTexture);*/
126126

127127
LPVOID Weapon_ShootPositionAddr = (LPVOID)(m_Game->m_Offsets->Weapon_ShootPosition.address);
128128
hkWeapon_ShootPosition.createHook(Weapon_ShootPositionAddr, &dWeapon_ShootPosition);
@@ -174,7 +174,7 @@ int Hooks::initSourceHooks()
174174
//
175175
EntityIndex = (tEntindex)m_Game->m_Offsets->CBaseEntity_entindex.address;
176176
GetOwner = (tGetOwner)m_Game->m_Offsets->GetOwner.address;
177-
177+
GetFullScreenTexture = (tGetFullScreenTexture)m_Game->m_Offsets->GetFullScreenTexture.address;
178178
return 1;
179179
}
180180

@@ -315,10 +315,29 @@ void __fastcall Hooks::dRenderView(void *ecx, void *edx, CViewSetup &setup, CVie
315315

316316
m_PushedHud = false;
317317

318+
319+
318320
rndrContext = matSystem->GetRenderContext();
319321
rndrContext->SetRenderTarget(NULL);
320322
rndrContext->Release();
321323

324+
/*rndrContext = matSystem->GetRenderContext();
325+
326+
ITexture* fullscreenTxt = rndrContext->GetRenderTarget();
327+
328+
Rect_t srcRect;
329+
srcRect.x = setup.x;
330+
srcRect.y = setup.y;
331+
srcRect.width = 1920;
332+
srcRect.height = 1080;
333+
334+
rndrContext->SetRenderTarget(m_VR->m_RightEyeTexture);
335+
rndrContext->CopyRenderTargetToTextureEx(fullscreenTxt, 0, &srcRect, &srcRect);
336+
337+
rndrContext->SetRenderTarget(NULL);
338+
rndrContext->Release();*/
339+
340+
322341
m_VR->m_RenderedNewFrame = true;
323342
}
324343

@@ -500,51 +519,12 @@ float __fastcall Hooks::dProcessUsercmds(void *ecx, void *edx, edict_t *player,
500519
return result;
501520
}
502521

503-
int Hooks::dReadUsercmd(void *buf, CUserCmd *move, CUserCmd *from)
504-
{
505-
hkReadUsercmd.fOriginal(buf, move, from);
506-
507-
int i = m_Game->m_CurrentUsercmdID;
508-
if (move->tick_count < 0) // Signal for VR CUserCmd
509-
{
510-
move->tick_count *= -1;
511-
512-
m_Game->m_PlayersVRInfo[i].isUsingVR = true;
513-
m_Game->m_PlayersVRInfo[i].controllerAngle.x = (float)move->mousedx / 10;
514-
m_Game->m_PlayersVRInfo[i].controllerAngle.y = (float)move->mousedy / 10;
515-
m_Game->m_PlayersVRInfo[i].controllerPos.x = move->viewangles.z;
516-
m_Game->m_PlayersVRInfo[i].controllerPos.y = move->upmove;
517-
518-
// Decode controllerAngle.z
519-
int rollEncoding = move->command_number / 10000000;
520-
move->command_number -= rollEncoding * 10000000;
521-
m_Game->m_PlayersVRInfo[i].controllerAngle.z = (rollEncoding * 2) - 180;
522-
523-
// Decode viewangles.x
524-
int decodedZInt = (move->viewangles.x / 10000);
525-
float decodedAngle = abs((float)(move->viewangles.x - (decodedZInt * 10000)) / 10);
526-
decodedAngle -= 360;
527-
float decodedZ = (float)decodedZInt / 10;
528-
529-
m_Game->m_PlayersVRInfo[i].controllerPos.z = decodedZ;
530-
531-
move->viewangles.x = decodedAngle;
532-
move->viewangles.z = 0;
533-
move->upmove = 0;
534-
}
535-
else
536-
{
537-
m_Game->m_PlayersVRInfo[i].isUsingVR = false;
538-
}
539-
return 1;
540-
}
541-
542522
void __fastcall Hooks::dWriteUsercmdDeltaToBuffer(void *ecx, void *edx, int a1, void *buf, int from, int to, bool isnewcommand)
543523
{
544524
return hkWriteUsercmdDeltaToBuffer.fOriginal(ecx, a1, buf, from, to, isnewcommand);
545525
}
546526

547-
int Hooks::dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from)
527+
int Hooks::dWriteUsercmd(bf_write *buf, CUserCmd *to, CUserCmd *from)
548528
{
549529
if (m_VR->m_IsVREnabled)
550530
{
@@ -592,6 +572,46 @@ int Hooks::dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from)
592572
return hkWriteUsercmd.fOriginal(buf, to, from);
593573
}
594574

575+
int Hooks::dReadUsercmd(bf_read *buf, CUserCmd* move, CUserCmd* from)
576+
{
577+
hkReadUsercmd.fOriginal(buf, move, from);
578+
579+
int i = m_Game->m_CurrentUsercmdID;
580+
if (move->tick_count < 0) // Signal for VR CUserCmd
581+
{
582+
move->tick_count *= -1;
583+
584+
m_Game->m_PlayersVRInfo[i].isUsingVR = true;
585+
m_Game->m_PlayersVRInfo[i].controllerAngle.x = (float)move->mousedx / 10;
586+
m_Game->m_PlayersVRInfo[i].controllerAngle.y = (float)move->mousedy / 10;
587+
m_Game->m_PlayersVRInfo[i].controllerPos.x = move->viewangles.z;
588+
m_Game->m_PlayersVRInfo[i].controllerPos.y = move->upmove;
589+
590+
// Decode controllerAngle.z
591+
int rollEncoding = move->command_number / 10000000;
592+
move->command_number -= rollEncoding * 10000000;
593+
m_Game->m_PlayersVRInfo[i].controllerAngle.z = (rollEncoding * 2) - 180;
594+
595+
// Decode viewangles.x
596+
int decodedZInt = (move->viewangles.x / 10000);
597+
float decodedAngle = abs((float)(move->viewangles.x - (decodedZInt * 10000)) / 10);
598+
decodedAngle -= 360;
599+
float decodedZ = (float)decodedZInt / 10;
600+
601+
m_Game->m_PlayersVRInfo[i].controllerPos.z = decodedZ;
602+
603+
move->viewangles.x = decodedAngle;
604+
move->viewangles.z = 0;
605+
move->upmove = 0;
606+
}
607+
else
608+
{
609+
m_Game->m_PlayersVRInfo[i].isUsingVR = false;
610+
}
611+
return 1;
612+
}
613+
614+
595615
void Hooks::dAdjustEngineViewport(int &x, int &y, int &width, int &height)
596616
{
597617
width = m_VR->m_RenderWidth;

L4D2VR/hooks.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class IMatRenderContext;
1616
struct vrect_t;
1717
struct Ray_t;
1818
struct VMatrix;
19+
struct Rect_t;
20+
class bf_write;
21+
class bf_read;
22+
1923

2024
template <typename T>
2125
struct Hook {
@@ -221,9 +225,9 @@ class Hooks
221225
static int dServerFireTerrorBullets(int playerId, const Vector &vecOrigin, const QAngle &vecAngles, int a4, int a5, int a6, float a7);
222226
static int dClientFireTerrorBullets(int playerId, const Vector &vecOrigin, const QAngle &vecAngles, int a4, int a5, int a6, float a7);
223227
static float __fastcall dProcessUsercmds(void *ecx, void *edx, edict_t *player, void *buf, int numcmds, int totalcmds, int dropped_packets, bool ignore, bool paused);
224-
static int dReadUsercmd(void *buf, CUserCmd *move, CUserCmd *from);
228+
static int dReadUsercmd(bf_read *buf, CUserCmd *move, CUserCmd *from);
225229
static void __fastcall dWriteUsercmdDeltaToBuffer(void *ecx, void *edx, int a1, void *buf, int from, int to, bool isnewcommand);
226-
static int dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from);
230+
static int dWriteUsercmd(bf_write *buf, CUserCmd *to, CUserCmd *from);
227231
static void dAdjustEngineViewport(int &x, int &y, int &width, int &height);
228232
static void __fastcall dViewport(void *ecx, void *edx, int x, int y, int width, int height);
229233
static void __fastcall dGetViewport(void *ecx, void *edx, int &x, int &y, int &width, int &height);
@@ -301,4 +305,5 @@ class Hooks
301305
static inline tUTIL_Portal_AngleTransform UTIL_Portal_AngleTransform;
302306
static inline tEntindex EntityIndex;
303307
static inline tGetOwner GetOwner;
308+
static inline tGetFullScreenTexture GetFullScreenTexture;
304309
};

L4D2VR/offsets.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ class Offsets
4646
//Offset WriteUsercmdDeltaToBuffer = { "client.dll", 0x134790, "55 8B EC 83 EC 60 0F 57 C0 8B 55 0C" }; //
4747
Offset WriteUsercmd = { "client.dll", 0x1C2060, "55 8B EC A1 ? ? ? ? 83 78 30 00 53 8B 5D 0C 56 57" };
4848
Offset g_pppInput = { "client.dll", 0xD12A0, "8B 0D ? ? ? ? 8B 01 8B 50 68 FF E2", 2 };
49-
Offset AdjustEngineViewport = { "client.dll", 0x41AD10, "55 8B EC 8B 0D ? ? ? ? 85 C9 74 17" };
50-
Offset IsSplitScreen = { "client.dll", 0x1B2A60, "33 C0 83 3D ? ? ? ? ? 0F 9D C0" };
49+
/*Offset AdjustEngineViewport = { "client.dll", 0x41AD10, "55 8B EC 8B 0D ? ? ? ? 85 C9 74 17" };
50+
Offset IsSplitScreen = { "client.dll", 0x1B2A60, "33 C0 83 3D ? ? ? ? ? 0F 9D C0" };*/
5151
Offset PrePushRenderTarget = { "client.dll", 0xA8C80, "55 8B EC 8B C1 56 8B 75 08 8B 0E 89 08 8B 56 04 89" };
5252

5353
Offset ReadUserCmd = { "server.dll", 0x205100, "55 8B EC 53 8B 5D 10 56 57 8B 7D 0C 53" };
5454
Offset ProcessUsercmds = { "server.dll", 0x170300, "55 8B EC B8 ? ? ? ? E8 ? ? ? ? 0F 57 C0 53 56 57 B9 ? ? ? ? 8D 85 ? ? ? ? 33 DB" }; //?
5555
Offset CBaseEntity_entindex = { "server.dll", 0x39F00, "8B 41 1C 85 C0 75 01 C3 8B 0D ? ? ? ? 2B 41 58 C1 F8 04 C3 CC"};
5656
Offset EyePosition = { "server.dll", 0xF40E0, "55 8B EC 56 8B F1 8B 86 ? ? ? ? C1 E8 0B A8 01 74 05 E8 ? ? ? ? 8B 45 08 F3" };
5757

58-
Offset GetRenderTarget = { "materialsystem.dll", 0x2CD30, "83 79 4C 00" };
58+
/*Offset GetRenderTarget = { "materialsystem.dll", 0x2CD30, "83 79 4C 00" };
5959
Offset Viewport = { "materialsystem.dll", 0x2E010, "55 8B EC 8B 45 0C 53 8B 5D" };
60-
Offset GetViewport = { "materialsystem.dll", 0x2CAF0, "55 8B EC 8B 41 4C 8B 49 40 8D 04 C0 83 7C 81 ? ?" };
60+
Offset GetViewport = { "materialsystem.dll", 0x2CAF0, "55 8B EC 8B 41 4C 8B 49 40 8D 04 C0 83 7C 81 ? ?" };*/
6161
Offset PushRenderTargetAndViewport = { "materialsystem.dll", 0x2D5F0, "55 8B EC 83 EC 24 8B 45 08 8B 55 10 89" };
6262
Offset PopRenderTargetAndViewport = { "materialsystem.dll", 0x2CE80, "56 8B F1 83 7E 4C 00" };
6363

0 commit comments

Comments
 (0)