Skip to content

Commit

Permalink
Tentative changes for coop support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gistix committed Sep 23, 2023
1 parent 4c0a569 commit 7c26ca0
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 47 deletions.
101 changes: 72 additions & 29 deletions L4D2VR/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ int Hooks::initSourceHooks()

//
hkClientThink.createHook((LPVOID)(m_Game->m_Offsets->ClientThink.address), &dClientThink);
EntityIndex = (tEntindex)m_Game->m_Offsets->CBaseEntity_entindex.address;
GetOwner = (tGetOwner)m_Game->m_Offsets->GetOwner.address;

hkCWeaponPortalgun_FirePortal.createHook((LPVOID)m_Game->m_Offsets->CWeaponPortalgun_FirePortal.address, &dCWeaponPortalgun_FirePortal);

return 1;
}
Expand Down Expand Up @@ -582,7 +586,7 @@ int Hooks::dReadUsercmd(void *buf, CUserCmd *move, CUserCmd *from)
{
hkReadUsercmd.fOriginal(buf, move, from);

/*int i = m_Game->m_CurrentUsercmdID;
int i = m_Game->m_CurrentUsercmdID;
if (move->tick_count < 0) // Signal for VR CUserCmd
{
move->tick_count *= -1;
Expand Down Expand Up @@ -613,7 +617,7 @@ int Hooks::dReadUsercmd(void *buf, CUserCmd *move, CUserCmd *from)
else
{
m_Game->m_PlayersVRInfo[i].isUsingVR = false;
}*/
}
return 1;
}

Expand All @@ -626,7 +630,7 @@ int Hooks::dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from)
{
if (m_VR->m_IsVREnabled)
{
/*CInput *m_Input = **(CInput ***)(m_Game->m_Offsets->g_pppInput.address);
CInput *m_Input = **(CInput ***)(m_Game->m_Offsets->g_pppInput.address);
CVerifiedUserCmd *pVerifiedCommands = *(CVerifiedUserCmd **)((uintptr_t)m_Input + 0xF0);
CVerifiedUserCmd *pVerified = &pVerifiedCommands[(to->command_number) % 150];

Expand Down Expand Up @@ -659,13 +663,13 @@ int Hooks::dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from)
to->tick_count *= -1;
to->viewangles.z = 0;
to->upmove = 0;
to->command_number = originalCommandNum;*/
to->command_number = originalCommandNum;

// Must recalculate checksum for the edited CUserCmd or gunshots will sound
// terrible in multiplayer.
/*pVerified->m_cmd = *to;
pVerified->m_crc = to->GetChecksum();*/
//return 1;
return 1;
}
return hkWriteUsercmd.fOriginal(buf, to, from);
}
Expand Down Expand Up @@ -719,15 +723,6 @@ Vector *Hooks::dEyePosition(void *ecx, void *edx, Vector *eyePos)
return result;
}

Vector* Hooks::dWeapon_ShootPosition(void* ecx, void* edx, Vector* eyePos)
{
Vector* result = hkWeapon_ShootPosition.fOriginal(ecx, eyePos);

*result = m_VR->GetRightControllerAbsPos();

return result;
}

// We'll keep this for... future reference!
void Hooks::dDrawModelExecute(void *ecx, void *edx, void *state, const ModelRenderInfo_t &info, void *pCustomBoneToWorld)
{
Expand Down Expand Up @@ -840,34 +835,71 @@ DWORD *Hooks::dPrePushRenderTarget(void *ecx, void *edx, int a2)
return hkPrePushRenderTarget.fOriginal(ecx, a2);
}

Vector* Hooks::dWeapon_ShootPosition(void* ecx, void* edx, Vector* eyePos)
{
Vector* result = hkWeapon_ShootPosition.fOriginal(ecx, eyePos);

int localIndex = m_Game->m_EngineClient->GetLocalPlayer();
int index = EntityIndex(ecx);

auto vrPlayer = m_Game->m_PlayersVRInfo[index];

if (m_VR->m_IsVREnabled && localIndex == index) {
*result = m_VR->GetRightControllerAbsPos();
}
else if (vrPlayer.isUsingVR)
{
*result = vrPlayer.controllerPos;
}

return result;
}

void* Hooks::dCWeaponPortalgun_FirePortal(void* ecx, void* edx, bool bPortal2, Vector* pVector = 0) {
bool wasTrue = m_VR->m_OverrideEyeAngles;

m_VR->m_OverrideEyeAngles = true;

auto result = hkCWeaponPortalgun_FirePortal.fOriginal(ecx, bPortal2, pVector);

if (!wasTrue)
m_VR->m_OverrideEyeAngles = false;

return result;
}

bool __fastcall Hooks::dTraceFirePortal(void* ecx, void* edx, const Vector& vTraceStart, const Vector& vDirection, bool bPortal2, int iPlacedBy, void* tr) //trace_tx& tr, Vector& vFinalPosition // , Vector& vFinalPosition, QAngle& qFinalAngles, int iPlacedBy, bool bTest /*= false*/
{
Vector vNewTraceStart = vTraceStart;
Vector vNewDirection = vDirection;

if (m_VR->m_IsVREnabled && iPlacedBy == 2)
{
vNewTraceStart = m_VR->GetRightControllerAbsPos();
vNewDirection = m_VR->m_RightControllerForward;
if (iPlacedBy == 2) {
int localIndex = m_Game->m_EngineClient->GetLocalPlayer();

}
std::cout << "dTraceFirePortal: " << ecx << "\n";

bool bTraceSucceeded = hkTraceFirePortal.fOriginal(ecx, vNewTraceStart, vNewDirection, bPortal2, iPlacedBy, tr);
auto owner = GetOwner(ecx);

/*if (iPlacedBy == 2 && bTraceSucceeded) {
C_Portal_Player* pPortalPlayer = ecx + ;
if (owner) {
int index = EntityIndex(owner);

if (pPortalPlayer) {
pPortalPlayer->m_PointLaser
if (bPortal2) {
auto vrPlayer = m_Game->m_PlayersVRInfo[index];

if (m_VR->m_IsVREnabled && localIndex == index) {
vNewTraceStart = m_VR->GetRightControllerAbsPos();
vNewDirection = m_VR->m_RightControllerForward;
}
else {
else if (vrPlayer.isUsingVR)
{
vNewTraceStart = vrPlayer.controllerPos;
Vector fwd, rt, up;
QAngle::AngleVectors(vrPlayer.controllerAngle, &fwd, &rt, &up);
vNewDirection = fwd;
}
}
}*/
}

bool bTraceSucceeded = hkTraceFirePortal.fOriginal(ecx, vNewTraceStart, vNewDirection, bPortal2, iPlacedBy, tr);

return bTraceSucceeded;
}
Expand Down Expand Up @@ -1077,7 +1109,18 @@ void __fastcall Hooks::dRotateObject(void* ecx, void* edx, void* pPlayer, float
// This works for release, but why was it crashing before??? TODO: buy a c++ book...
QAngle& __fastcall Hooks::dEyeAngles(void* ecx, void* edx) {
if (m_VR->m_OverrideEyeAngles) {
return m_VR->GetRightControllerAbsAngleConst();
int localIndex = m_Game->m_EngineClient->GetLocalPlayer();
int index = EntityIndex(ecx);

auto vrPlayer = m_Game->m_PlayersVRInfo[index];

if (m_VR->m_IsVREnabled && localIndex == index) {
return m_VR->GetRightControllerAbsAngleConst();
}
else if (vrPlayer.isUsingVR)
{
return vrPlayer.controllerAngle;
}
}
else {
return hkEyeAngles.fOriginal(ecx);
Expand Down
14 changes: 10 additions & 4 deletions L4D2VR/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ typedef bool(__thiscall* tCHudCrosshair_ShouldDraw)(void* thisptr);
typedef void*(__cdecl* tUTIL_Portal_FirstAlongRay)(const Ray_t& ray, float& fMustBeCloserThan);
typedef float(__cdecl* tUTIL_IntersectRayWithPortal)(const Ray_t& ray, const void* pPortal);
typedef void(__cdecl* tUTIL_Portal_AngleTransform)(const VMatrix& matThisToLinked, const QAngle& qSource, QAngle& qTransformed);

typedef int(__thiscall* tEntindex)(void* thisptr);
typedef void*(__thiscall* tGetOwner)(void* thisptr);
typedef void* (__thiscall* tCWeaponPortalgun_FirePortal)(void* thisptr, bool bPortal2, Vector* pVector);

class Hooks
{
Expand Down Expand Up @@ -196,7 +198,8 @@ class Hooks
static inline Hook<tClientThink> hkClientThink;
static inline Hook<tPrecache> hkPrecache;
static inline Hook<tCHudCrosshair_ShouldDraw> hkCHudCrosshair_ShouldDraw;

static inline Hook<tCWeaponPortalgun_FirePortal> hkCWeaponPortalgun_FirePortal;

//Precache

Hooks() {};
Expand Down Expand Up @@ -280,7 +283,9 @@ class Hooks
static void __fastcall dClientThink(void* ecx, void* edx);
static void __fastcall dPrecache(void* ecx, void* edx);
static bool __fastcall dCHudCrosshair_ShouldDraw(void* ecx, void* edx);


static void* __fastcall dCWeaponPortalgun_FirePortal(void* ecx, void* edx, bool bPortal2, Vector* pVector = 0);

static inline int m_PushHUDStep;
static inline bool m_PushedHud;

Expand All @@ -291,5 +296,6 @@ class Hooks
static inline tUTIL_Portal_FirstAlongRay UTIL_Portal_FirstAlongRay;
static inline tUTIL_IntersectRayWithPortal UTIL_IntersectRayWithPortal;
static inline tUTIL_Portal_AngleTransform UTIL_Portal_AngleTransform;

static inline tEntindex EntityIndex;
static inline tGetOwner GetOwner;
};
26 changes: 16 additions & 10 deletions L4D2VR/offsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class Offsets
Offset PushRenderTargetAndViewport = { "materialsystem.dll", 0x2D5F0, "55 8B EC 83 EC 24 8B 45 08 8B 55 10 89" };
Offset PopRenderTargetAndViewport = { "materialsystem.dll", 0x2CE80, "56 8B F1 83 7E 4C 00" };

Offset TraceFirePortalClient = { "client.dll", 0x3E0980, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 81 EC ? ? ? ? 56 57 8B F1 6A" };
//Offset TraceFirePortalClient = { "client.dll", 0x3E0980, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 81 EC ? ? ? ? 56 57 8B F1 6A" };
// Firing Portals
Offset TraceFirePortalServer = { "server.dll", 0x400D50, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 81 EC ? ? ? ? 56 57 8B F1 6A" };
Offset CWeaponPortalgun_FirePortal = { "server.dll", 0x401370, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 81 EC ? ? ? ? 56 57 8B F9 89 7D EC E8 ? ? ? ?" };

//53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 81 EC ? ? ? ? 56 57 8B F1 6A 00 56 8D 4D C0 89 75 F8 E8
//Offset DrawModelExecute = { "engine.dll", 0xE05E0, "55 8B EC 81 EC ? ? ? ? A1 ? ? ? ? 33 C5 89 45 FC 8B 45 10 56 8B 75 08 57 8B" }; //
Expand All @@ -73,23 +75,22 @@ class Offsets
// Ingame UI
Offset DrawSelf = { "client.dll", 0x12CC90, "55 8B EC 56 8B F1 80 BE ? ? ? ? ? 0F 84 ? ? ? ? 8B 0D" };
Offset ClipTransform = { "client.dll", 0x1DD130, "55 8B EC 8B 0D ? ? ? ? 8B 01 8B 90 ? ? ? ? FF D2 8B 4D" };
Offset VGui_GetHudBounds = { "client.dll", 0x1CC550, "55 8B EC 51 56 8B 75 08 8B CE" };
/*Offset VGui_GetHudBounds = { "client.dll", 0x1CC550, "55 8B EC 51 56 8B 75 08 8B CE" };
Offset VGui_GetPanelBounds = { "client.dll", 0x1CC350, "55 8B EC 8B 45 08 8B C8 83 E1 1F BA ? ? ? ?" };
Offset VGUI_UpdateScreenSpaceBounds = { "client.dll", 0x1CC8C0, "55 8B EC 83 EC 14 8B 45 0C 8B 4D 10 53 8B 5D 18 56 A3 ? ? ? ? 33 C0" };
Offset VGui_GetTrueScreenSize = { "client.dll", 0x1CBCF0, "55 8B EC 8B 45 08 8B 0D ? ? ? ? 8B 55 0C 89 08 A1 ? ? ? ? 89 02 5D C3" };
Offset VGui_GetClientDLLRootPanel = { "client.dll", 0x26EDF0, "8B 0D ? ? ? ? 8B 01 8B 90 ? ? ? ? FF D2 8B 04 85 ? ? ? ? 8B 48 04" };
Offset g_pFullscreenRootPanel = { "client.dll", 0x26EE20, "A1 ? ? ? ? C3", 2 };
//Offset VGui_GetFullscreenRootPanel = { "client.dll", 0x26EE20, "A1 ? ? ? ? C3", 2 };
Offset g_pFullscreenRootPanel = { "client.dll", 0x26EE20, "A1 ? ? ? ? C3", 2 };*/

// Pointer laser
Offset CreatePingPointer = { "client.dll", 0x280660, "55 8B EC 83 EC 14 53 56 8B F1 8B 8E ? ? ? ? 57 85 C9 74 30" };
Offset ClientThink = { "client.dll", 0x27EA30, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 81 EC ? ? ? ?" };
//Offset ClientThink = { "client.dll", 0x27EA30, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 81 EC ? ? ? ?" };
Offset GetPortalPlayer = { "client.dll", 0x8DCA0, "55 8B EC 8B 45 08 83 F8 FF 75 10 8B 0D ? ? ? ? 8B 01 8B 90 ? ? ? ? FF D2" };
Offset PrecacheParticleSystem = { "server.dll", 0x16DF40, "55 8B EC 8B 0D ? ? ? ? 8B 55 08 8B 01 8B 40 20 6A 00 6A FF" };
Offset Precache = { "server.dll", 0x35A2C0, "E8 ? ? ? ? 68 ? ? ? ? E8 ? ? ? ?" };
Offset GetActivePortalWeapon = { "client.dll", 0x2A8910, "8B 89 ? ? ? ? 83 F9 FF 74 1F 8B 15 ? ? ? ?" };
//Offset GetActivePortalWeapon = { "client.dll", 0x2A8910, "8B 89 ? ? ? ? 83 F9 FF 74 1F 8B 15 ? ? ? ?" };

Offset SetControlPoint = { "client.dll", 0x17BD30, "55 8B EC 53 56 8B 75 0C 57 8B F9 BB ? ? ? ? 84 9F ? ? ? ?" };
Offset SetDrawOnlyForSplitScreenUser = { "client.dll", 0x17B9E0, "55 8B EC 8B 45 08 53 8B D9 3B 83 ? ? ? ? 74 55" };
Expand All @@ -103,22 +104,23 @@ class Offsets
Offset UTIL_IntersectRayWithPortal = { "server.dll", 0x376730, "55 8B EC 83 EC 48 56 8B 75 0C 85 F6 0F 84 ? ? ? ?" };
Offset UTIL_Portal_AngleTransform = { "server.dll", 0x375CA0, "55 8B EC 8B 45 08 8B 4D 0C 83 EC 0C 50 51 8D 55 F4" };

Offset GetScreenSize = { "vguimatsurface.dll", 0xB8C0, "55 8B EC 83 EC 08 80 B9 ? ? ? ? ? 74 1C" };
/*Offset GetScreenSize = { "vguimatsurface.dll", 0xB8C0, "55 8B EC 83 EC 08 80 B9 ? ? ? ? ? 74 1C" };
Offset GetHudSize = { "client.dll", 0x1CBCD0, "55 8B EC 8B 55 0C 8B 0D ? ? ? ? 8B 01 8B 80 ? ? ? ? 52 8B 55 08 52 FF D0 5D C3" };
Offset SetSizeC = { "client.dll", 0x63FB70, "55 8B EC 8B 41 04 8B 50 04 8B 45 0C 56 8B 35 ? ? ? ?" };
Offset SetSizeE = { "engine.dll", 0x298620, "55 8B EC 8B 41 04 8B 50 04 8B 45 0C 56 8B 35 ? ? ? ?" };
Offset SetSizeV = { "vguimatsurface.dll", 0x4B6D0, "55 8B EC 8B 41 04 8B 50 04 8B 45 0C 56 8B 35 ? ? ? ?" };
//Offset SetBoundsC = { "client.dll", 0x63FBF0, "55 8B EC 8B 55 0C 53 56 8B F1 8B 46 04 8B 48 04 8B 45 08 57 8B 3D ? ? ? ?" };
Offset SetBoundsE = { "engine.dll", 0x2986A0, "55 8B EC 8B 55 0C 53 56 8B F1 8B 46 04 8B 48 04 8B 45 08 57 8B 3D ? ? ? ? 8B 1F 8D 4C 31 04 52 8B 11 50 8B 02 FF D0 8B 53 08 50 8B CF FF D2" };
Offset SetBoundsE = { "engine.dll", 0x2986A0, "55 8B EC 8B 55 0C 53 56 8B F1 8B 46 04 8B 48 04 8B 45 08 57 8B 3D ? ? ? ? 8B 1F 8D 4C 31 04 52 8B 11 50 8B 02 FF D0 8B 53 08 50 8B CF FF D2" };*/


Offset Push2DView = { "engine.dll", 0xDF980, "55 8B EC 51 53 8B D9 8B 83 ? ? ? ? 56 8D B3 ? ? ? ? 57 89 5D FC 3B 46 04 7C 09" };
/*Offset Push2DView = { "engine.dll", 0xDF980, "55 8B EC 51 53 8B D9 8B 83 ? ? ? ? 56 8D B3 ? ? ? ? 57 89 5D FC 3B 46 04 7C 09" };
Offset Render = { "client.dll", 0x1D6800, "55 8B EC 81 EC ? ? ? ? 53 56 57 8B F9 8B 0D ? ? ? ? 89 7D F4 FF 15 ? ? ? ?" };
Offset GetClipRect = { "vguimatsurface.dll", 0x4C700, "55 8B EC 8B 81 ? ? ? ? 8B 50 04 8B 45 14 56 8B 35 ? ? ? ? 57 8B 3E 8D 8C 0A ? ? ? ? 8B 55 10 50" };
//Offset GetWeaponCrosshairScale = {}
Offset GetModeHeight = { "engine.dll", 0x1F9F10, "8B 81 ? ? ? ? C3" };
Offset GetModeHeight = { "engine.dll", 0x1F9F10, "8B 81 ? ? ? ? C3" };*/

//Grababbles
//Offset Weapon_ShootPosition = { "client.dll", 0x2A8A60, "55 8B EC 8B 01 8B 90 ? ? ? ? 56 8B 75 08 56 FF D2 8B C6 5E 5D C2 04 00" };
Offset Weapon_ShootPosition = { "server.dll", 0x1033C0, "55 8B EC 8B 01 8B 90 ? ? ? ? 56 8B 75 08 56 FF D2 8B C6 5E 5D C2 04 00" };
Expand All @@ -133,4 +135,8 @@ class Offsets
Offset GetFOV = { "client.dll", 0x2772B0, "55 8B EC 51 56 8B F1 E8 ? ? ? ? D9 5D FC 8B 06 8B 90 ? ? ? ? 8B CE FF D2" };
Offset GetDefaultFOV = { "client.dll", 0x279020, "A1 ? ? ? ? F3 0F 2C 40 ? C3" };
Offset GetViewModelFOV = { "client.dll", 0x28AB80, "A1 ? ? ? ? D9 40 2C C3" };

// Multiplayer
Offset GetOwner = { "server.dll", 0xD7550, "8B 81 ? ? ? ? 83 F8 FF 74 23 8B 15 ? ? ? ?" };
//Offset GetActiveWeapon = { "server.dll", 0xD3FD0, "8B 89 ? ? ? ? 83 F9 FF 74 1F 8B 15 ? ? ? ?" };
};
7 changes: 5 additions & 2 deletions L4D2VR/sdk/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -2125,9 +2125,12 @@ class ISurface
class CWeaponPortalBase
{
public:
char pad_0000[3740]; //0000
//char pad_0000[3740]; //0000
char pad_0000[300];
CBaseEntity* m_hOwner;
char pad_0001[3436];
int m_iLastFiredPortal; //0xE9C
};
}; static_assert(sizeof(CWeaponPortalBase) == 0xEA0);

class C_Portal_Player
{
Expand Down
8 changes: 7 additions & 1 deletion L4D2VR/sdk/sdk_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,13 @@ class CBaseEntity
{
public:
virtual ~CBaseEntity() = 0;
char pad_0004[340]; //0x0004
char pad_0004[20]; //0x0004
CBaseEntity* m_hOwnerEntity; //0x0018
char pad_001C[68]; //0x001C
char* EntityClass; //0x0060
char pad_0064[72]; //0x0064
char* ModelName; //0x00AC
char pad_00B0[168]; //0x00B0
void* m_hGroundEntity; //0x0158
float m_flGroundChangeTime; //0x015C
Vector m_vecBaseVelocity; //0x0160
Expand Down
4 changes: 3 additions & 1 deletion L4D2VR/vr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,9 @@ void VR::ParseConfigFile()
if (std::getline(sLine, key, '='))
{
std::string value;
if (std::getline(sLine, value))
if (std::getline(sLine, value, '#'))
userConfig[key] = value;
else if (std::getline(sLine, value))
userConfig[key] = value;
}
}
Expand Down

0 comments on commit 7c26ca0

Please sign in to comment.