Skip to content

Commit

Permalink
Replaced pev declarations with GET_PEV macro
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG authored and YaLTeR committed Jul 27, 2024
1 parent 9b0dc2d commit 498e7ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
3 changes: 1 addition & 2 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5071,8 +5071,7 @@ struct HwDLL::Cmd_BXT_Give
auto &sv_dll = ServerDLL::GetInstance();

void* classPtr = (*hw_dll.sv_player)->pvPrivateData;
uintptr_t thisAddr = reinterpret_cast<uintptr_t>(classPtr);
entvars_t *pev = *reinterpret_cast<entvars_t**>(thisAddr + 4);
auto pev = GET_PEV(classPtr);

int iszItem = sv_dll.pEngfuncs->pfnAllocString(classname); // Make a copy of the classname

Expand Down
42 changes: 21 additions & 21 deletions BunnymodXT/modules/ServerDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ HOOK_DEF_1(ServerDLL, void, __cdecl, COFGeneWorm__DyingThink_Linux, void*, thisp
HOOK_DEF_1(ServerDLL, void, __fastcall, CApache__DyingThink, void*, thisptr)
{
if (HwDLL::GetInstance().ppGlobals) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->targetname) {
const char *targetname = HwDLL::GetInstance().ppGlobals->pStringBase + pev->targetname;
if (!std::strcmp(targetname, "sheriffs_chppr") && ClientDLL::GetInstance().DoesGameDirContain("hunger")) { // They Hunger Episode 3
Expand All @@ -2208,7 +2208,7 @@ HOOK_DEF_1(ServerDLL, void, __fastcall, CApache__DyingThink, void*, thisptr)
HOOK_DEF_2(ServerDLL, void, __fastcall, CBreakable__Die, void*, thisptr, int, edx)
{
if (HwDLL::GetInstance().ppGlobals) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->target) {
const char *target = HwDLL::GetInstance().ppGlobals->pStringBase + pev->target;
if (!std::strcmp(target, "BLOOOM") && ClientDLL::GetInstance().DoesGameDirContain("czeror")) { // CSCZDS
Expand All @@ -2223,7 +2223,7 @@ HOOK_DEF_2(ServerDLL, void, __fastcall, CBreakable__Die, void*, thisptr, int, ed
HOOK_DEF_1(ServerDLL, void, __cdecl, CBreakable__Die_Linux, void*, thisptr)
{
if (HwDLL::GetInstance().ppGlobals) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->target) {
const char *target = HwDLL::GetInstance().ppGlobals->pStringBase + pev->target;
if (!std::strcmp(target, "BLOOOM") && ClientDLL::GetInstance().DoesGameDirContain("czeror")) {
Expand All @@ -2240,7 +2240,7 @@ HOOK_DEF_2(ServerDLL, int, __fastcall, CBaseDoor__DoorActivate, void*, thisptr,
auto isActivated = ORIG_CBaseDoor__DoorActivate(thisptr, edx);

if (isActivated && HwDLL::GetInstance().ppGlobals) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->targetname) {
const char *targetname = HwDLL::GetInstance().ppGlobals->pStringBase + pev->targetname;
Splits::Activate(targetname);
Expand All @@ -2252,7 +2252,7 @@ HOOK_DEF_2(ServerDLL, int, __fastcall, CBaseDoor__DoorActivate, void*, thisptr,
HOOK_DEF_1(ServerDLL, void, __fastcall, CBaseDoor__DoorGoUp, void*, thisptr)
{
if (HwDLL::GetInstance().ppGlobals) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->target) {
const char *target = HwDLL::GetInstance().ppGlobals->pStringBase + pev->target;
if (!std::strcmp(target, "oil_spouts1_mm") && ClientDLL::GetInstance().DoesGameDirContain("hunger")) { // They Hunger Episode 2
Expand All @@ -2267,7 +2267,7 @@ HOOK_DEF_1(ServerDLL, void, __fastcall, CBaseDoor__DoorGoUp, void*, thisptr)
HOOK_DEF_1(ServerDLL, void, __fastcall, CBaseDoor__DoorHitTop, void*, thisptr)
{
if (HwDLL::GetInstance().ppGlobals && pEngfuncs) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
edict_t *pPlayer = pEngfuncs->pfnPEntityOfEntIndex(1);
if (pev && pev->targetname && pPlayer) {
void *classPtr = pPlayer->pvPrivateData;
Expand All @@ -2286,7 +2286,7 @@ HOOK_DEF_1(ServerDLL, void, __fastcall, CBaseDoor__DoorHitTop, void*, thisptr)
HOOK_DEF_4(ServerDLL, void, __fastcall, CBaseMonster__Killed, void*, thisptr, int, edx, entvars_t*, pevAttacker, int, iGib)
{
if (HwDLL::GetInstance().ppGlobals) {
entvars_t* pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->classname) {
const char* classname = HwDLL::GetInstance().ppGlobals->pStringBase + pev->classname;
if (!std::strcmp(classname, "monster_gargantua") && ClientDLL::GetInstance().DoesGameDirMatch("tetsu0_cot")) {
Expand All @@ -2303,7 +2303,7 @@ HOOK_DEF_2(ServerDLL, void, __fastcall, CMultiManager__ManagerThink, void*, this
auto &hw = HwDLL::GetInstance();

if (hw.ppGlobals) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->targetname) {
const char *targetname = hw.ppGlobals->pStringBase + pev->targetname;
OnMultiManagerFired(targetname);
Expand All @@ -2322,7 +2322,7 @@ HOOK_DEF_2(ServerDLL, void, __fastcall, CMultiManager__ManagerThink, void*, this
HOOK_DEF_5(ServerDLL, void, __cdecl, FireTargets_Linux, char*, targetName, void*, pActivator, void*, pCaller, int, useType, float, value)
{
if (HwDLL::GetInstance().ppGlobals && targetName != NULL && pCaller) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(pCaller) + 4);
auto pev = GET_PEV(pCaller);
if(pev && pev->targetname)
{
const char *targetname = HwDLL::GetInstance().ppGlobals->pStringBase + pev->targetname;
Expand Down Expand Up @@ -2571,7 +2571,7 @@ HOOK_DEF_1(ServerDLL, void, __fastcall, CTriggerVolume__Spawn, void*, thisptr)
return;
}

entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
string_t old_model = pev->model;
ORIG_CTriggerVolume__Spawn(thisptr);
pev->model = old_model;
Expand All @@ -2586,7 +2586,7 @@ HOOK_DEF_1(ServerDLL, void, __cdecl, CTriggerVolume__Spawn_Linux, void*, thisptr
return;
}

entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
string_t old_model = pev->model;
ORIG_CTriggerVolume__Spawn_Linux(thisptr);
pev->model = old_model;
Expand Down Expand Up @@ -2703,8 +2703,8 @@ bool ServerDLL::IsPlayerMovingPushable(const entvars_t *pevPushable, const entva

HOOK_DEF_4(ServerDLL, void, __fastcall, CPushable__Move, void*, thisptr, int, edx, void*, pOther, int, push)
{
const entvars_t *pevToucher = *reinterpret_cast<entvars_t **>(reinterpret_cast<uintptr_t>(pOther) + 4);
entvars_t *pevPushable = *reinterpret_cast<entvars_t **>(reinterpret_cast<uintptr_t>(thisptr) + 4);
const auto pevToucher = GET_PEV(pOther);
auto pevPushable = GET_PEV(thisptr);

if (IsPlayerMovingPushable(pevPushable, pevToucher, push)) {
if (!push)
Expand All @@ -2728,8 +2728,8 @@ HOOK_DEF_4(ServerDLL, void, __fastcall, CPushable__Move, void*, thisptr, int, ed

HOOK_DEF_3(ServerDLL, void, __cdecl, CPushable__Move_Linux, void*, thisptr, void*, pOther, int, push)
{
const entvars_t *pevToucher = *reinterpret_cast<entvars_t **>(reinterpret_cast<uintptr_t>(pOther) + 4);
entvars_t *pevPushable = *reinterpret_cast<entvars_t **>(reinterpret_cast<uintptr_t>(thisptr) + 4);
const auto pevToucher = GET_PEV(pOther);
auto pevPushable = GET_PEV(thisptr);

if (IsPlayerMovingPushable(pevPushable, pevToucher, push)) {
if (!push)
Expand Down Expand Up @@ -3070,7 +3070,7 @@ HOOK_DEF_3(ServerDLL, void, __fastcall, CChangeLevel__TouchChangeLevel, void*, t

HOOK_DEF_1(ServerDLL, void, __fastcall, CTriggerCamera__FollowTarget, void*, thisptr)
{
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev)
{
bool changed = false;
Expand Down Expand Up @@ -3201,7 +3201,7 @@ void ServerDLL::ClearBulletsTrace() {
HOOK_DEF_6(ServerDLL, void, __fastcall, CBaseButton__ButtonUse, void*, thisptr, int, edx, void*, pActivator, void*, pCaller, int, useType, float, value)
{
if (HwDLL::GetInstance().ppGlobals) {
entvars_t* pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev) {
if (pev->target) {
const char* target = HwDLL::GetInstance().ppGlobals->pStringBase + pev->target;
Expand Down Expand Up @@ -3232,7 +3232,7 @@ HOOK_DEF_6(ServerDLL, void, __fastcall, CBaseButton__ButtonUse, void*, thisptr,
HOOK_DEF_2(ServerDLL, void, __fastcall, CBaseButton__ButtonTriggerAndWait, void*, thisptr, int, edx)
{
if (HwDLL::GetInstance().ppGlobals) {
entvars_t* pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->target) {
// Fire any splitter that matches this button's target's name. This one compared to ButtonUse, should
// already have the button's master entity triggered and the button should already be enabled, so it's
Expand Down Expand Up @@ -3267,7 +3267,7 @@ HOOK_DEF_3(ServerDLL, void, __fastcall, CTriggerEndSection__EndSectionTouch, voi
// trigger_endsection sends you to the menu, effectively stopping the demo,
// but not the timer and neither LiveSplit of course, so we have to do it here
if (HwDLL::GetInstance().ppGlobals) {
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev && pev->targetname) {
const char *targetname = HwDLL::GetInstance().ppGlobals->pStringBase + pev->targetname;
if (!std::strcmp(targetname, "tr_endchange")) {
Expand Down Expand Up @@ -3358,7 +3358,7 @@ HOOK_DEF_1(ServerDLL, int, __fastcall, CBaseEntity__IsInWorld, void*, thisptr)
{
if (HwDLL::GetInstance().is_big_map)
{
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev)
return IsInWorld(pev->origin, pev->velocity, BIG_MAP_SIZE, BIG_MAP_MAX_VELOCITY);
}
Expand All @@ -3370,7 +3370,7 @@ HOOK_DEF_1(ServerDLL, int, __cdecl, CBaseEntity__IsInWorld_Linux, void*, thisptr
{
if (HwDLL::GetInstance().is_big_map)
{
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
auto pev = GET_PEV(thisptr);
if (pev)
return IsInWorld(pev->origin, pev->velocity, BIG_MAP_SIZE, BIG_MAP_MAX_VELOCITY);
}
Expand Down

0 comments on commit 498e7ec

Please sign in to comment.