Skip to content

Commit

Permalink
const_cast to avoid SDK change
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Mar 8, 2024
1 parent f3944c6 commit e4656f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions BunnymodXT/modules/ServerDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" void __cdecl _Z8CmdStartPK7edict_sPK9usercmd_sj(const edict_t* player
return ServerDLL::HOOKED_CmdStart(player, cmd, random_seed);
}

extern "C" void __cdecl _Z6CmdEndPK7edict_s(edict_t *player)
extern "C" void __cdecl _Z6CmdEndPK7edict_s(const edict_t* player)
{
return ServerDLL::HOOKED_CmdEnd(player);
}
Expand Down Expand Up @@ -2132,17 +2132,19 @@ HOOK_DEF_3(ServerDLL, void, __cdecl, CmdStart, const edict_t*, player, const use
return ORIG_CmdStart(player, cmd, seed);
}

HOOK_DEF_1(ServerDLL, void, __cdecl, CmdEnd, edict_t*, player)
HOOK_DEF_1(ServerDLL, void, __cdecl, CmdEnd, const edict_t*, player)
{
if (CVars::bxt_ch_fix_sticky_slide.GetBool() && CVars::sv_cheats.GetBool()) {
Vector end_origin = Vector(player->v.origin);
Vector end_velocity = Vector(player->v.velocity);
entvars_t *pev = const_cast<entvars_t *>(&player->v);

Vector end_origin = Vector(pev->origin);
Vector end_velocity = Vector(pev->velocity);

if (end_velocity.Length2D() == 0.0f // stuck, exclude z vel because it will be -4.0
&& cmdStartVelocity.Length() != 0.0f // not standing still, can include z
&& cmdStartOrigin == end_origin // origin doesn't change when stuck
) {
const auto is_duck = player->v.button & (IN_DUCK) || player->v.flags & (FL_DUCKING);
const auto is_duck = pev->button & (IN_DUCK) || player->v.flags & (FL_DUCKING);

auto origin_z_offset = CVars::bxt_ch_fix_sticky_slide_offset.GetFloat(); // offset so player isn't "stuck"
auto tr_down = HwDLL::GetInstance().PlayerTrace(end_origin,
Expand All @@ -2161,8 +2163,8 @@ HOOK_DEF_1(ServerDLL, void, __cdecl, CmdEnd, edict_t*, player)
cmdStartVelocity = Vector();
}

player->v.origin[2] += origin_z_offset;
player->v.velocity = cmdStartVelocity;
pev->origin[2] += origin_z_offset;
pev->velocity = cmdStartVelocity;
}
}

Expand Down
2 changes: 1 addition & 1 deletion BunnymodXT/modules/ServerDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ServerDLL : public IHookableDirFilter
HOOK_DECL(bool, __cdecl, PM_AddToTouched, pmtrace_t tr, float* impactvelocity)
HOOK_DECL(void, __cdecl, PM_Move, struct playermove_s* ppmove, int server)
HOOK_DECL(void, __cdecl, CmdStart, const edict_t* player, const usercmd_t* cmd, unsigned int random_seed)
HOOK_DECL(void, __cdecl, CmdEnd, edict_t* player)
HOOK_DECL(void, __cdecl, CmdEnd, const edict_t* player)
HOOK_DECL(void, __fastcall, CNihilanth__DyingThink, void* thisptr, int edx)
HOOK_DECL(void, __cdecl, CNihilanth__DyingThink_Linux, void* thisptr)
HOOK_DECL(void, __fastcall, COFGeneWorm__DyingThink, void* thisptr, int edx)
Expand Down
2 changes: 1 addition & 1 deletion HLSDK/engine/eiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ typedef struct
int (*pfnGetWeaponData) ( struct edict_s *player, struct weapon_data_s *info );

void (*pfnCmdStart) ( const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed );
void (*pfnCmdEnd) ( edict_t *player );
void (*pfnCmdEnd) ( const edict_t *player );

// Return 1 if the packet is valid. Set response_buffer_size if you want to send a response packet. Incoming, it holds the max
// size of the response_buffer, so you must zero it out if you choose not to respond.
Expand Down

0 comments on commit e4656f0

Please sign in to comment.