Skip to content

Commit

Permalink
fix melee no damage bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sd805 committed Sep 13, 2022
1 parent 295289b commit 2b33f52
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions L4D2VR/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ struct Player
QAngle controllerAngle;
Vector controllerPos;
bool isMeleeing;
bool isNewSwing;
QAngle prevControllerAngle;

Player()
: isUsingVR(false),
controllerAngle({ 0,0,0 }),
controllerPos({ 0,0,0 }),
isMeleeing(false),
isNewSwing(false),
prevControllerAngle({ 0,0,0 })
{}
};
Expand Down
18 changes: 14 additions & 4 deletions L4D2VR/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,26 @@ float __fastcall Hooks::dProcessUsercmds(void *ecx, void *edx, edict_t *player,
if (curWep)
{
int wepID = curWep->GetWeaponID();
if (wepID == 19)
if (wepID == 19) // melee weapon
{
if (m_Game->m_PlayersVRInfo[index].isNewSwing)
{
m_Game->m_PlayersVRInfo[index].isNewSwing = false;
curWep->entitiesHitThisSwing = 0;
}

typedef void *(__thiscall *tGetMeleeWepInfo)(void *thisptr);
static tGetMeleeWepInfo oGetMeleeWepInfo = (tGetMeleeWepInfo)(m_Game->m_Offsets->GetMeleeWeaponInfo.address);
void *meleeWepInfo = oGetMeleeWepInfo(curWep);

Vector initialForward, initialRight, initialUp;
QAngle::AngleVectors(m_Game->m_PlayersVRInfo[index].prevControllerAngle, &initialForward, &initialRight, &initialUp);
Vector initialMeleeDirection = VectorRotate(initialForward, initialRight, 75.0);
Vector initialMeleeDirection = VectorRotate(initialForward, initialRight, 50.0);
VectorNormalize(initialMeleeDirection);

Vector finalForward, finalRight, finalUp;
QAngle::AngleVectors(m_Game->m_PlayersVRInfo[index].controllerAngle, &finalForward, &finalRight, &finalUp);
Vector finalMeleeDirection = VectorRotate(finalForward, finalRight, 75.0);
Vector finalMeleeDirection = VectorRotate(finalForward, finalRight, 50.0);
VectorNormalize(finalMeleeDirection);

Vector pivot;
Expand All @@ -320,6 +326,10 @@ float __fastcall Hooks::dProcessUsercmds(void *ecx, void *edx, edict_t *player,
}
}
}
else
{
m_Game->m_PlayersVRInfo[index].isNewSwing = true;
}

m_Game->m_PlayersVRInfo[index].prevControllerAngle = m_Game->m_PlayersVRInfo[index].controllerAngle;

Expand Down Expand Up @@ -399,7 +409,7 @@ int Hooks::dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from)
int rollEncoding = (((int)controllerAngles.z + 180) / 2 * 10000000);
to->command_number += rollEncoding;

if (VectorLength(m_VR->m_RightControllerPose.TrackedDeviceVel) > .9)
if (VectorLength(m_VR->m_RightControllerPose.TrackedDeviceVel) > 1.1)
{
to->command_number *= -1; // Signal to server that melee swing in motion
}
Expand Down
6 changes: 5 additions & 1 deletion L4D2VR/sdk/sdk_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ class Server_WeaponCSBase
virtual void sub_1024C590() = 0;
virtual void sub_1024C5A0() = 0;
virtual void sub_1024C5B0() = 0;
};

char pad_0000[6124]; //0x0000
int entitiesHitThisSwing; //0x17F0
}; //Size: 0x17F4
static_assert(sizeof(Server_WeaponCSBase) == 0x17F4);

class Server_BaseEntity
{
Expand Down

0 comments on commit 2b33f52

Please sign in to comment.