Skip to content

Commit

Permalink
Add bxt_ch_noclip_speed
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Jul 12, 2024
1 parent 63a1212 commit cff64fc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion BunnymodXT/cvars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@
X(bxt_ch_checkpoint_with_vel, "1") \
X(bxt_ch_checkpoint_onground_only, "0") \
X(bxt_ch_fix_sticky_slide, "0") \
X(bxt_ch_fix_sticky_slide_offset, "0.01")
X(bxt_ch_fix_sticky_slide_offset, "0.01") \
X(bxt_ch_noclip_speed, "0")

class CVarWrapper
{
Expand Down
31 changes: 31 additions & 0 deletions BunnymodXT/modules/ServerDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ void ServerDLL::Clear()
offAngles = 0;
offCmd = 0;
offBhopcap = 0;
offMaxspeed = 0;
offClientMaxspeed = 0;
offMoveType = 0;
pBhopcapWindows = 0;
pCZDS_Velocity_Byte = 0;
pCBasePlayer__Jump_OldButtons_Check_Byte = 0;
Expand Down Expand Up @@ -408,6 +411,9 @@ void ServerDLL::FindStuff()
offInDuck = 0x90;
offFlags = 0xB8;
offBasevelocity = 0x74;
offMaxspeed = 0x1f4;
offClientMaxspeed = 0x1f8;
offMoveType = 0xdc;
});

auto fPM_Jump = FindFunctionAsync(
Expand Down Expand Up @@ -1609,6 +1615,8 @@ void ServerDLL::RegisterCVarsAndCommands()
REG(bxt_cof_disable_monsters_teleport_to_spawn_after_load);
if (ORIG_CTriggerCamera__FollowTarget && is_cof)
REG(bxt_cof_allow_skipping_all_cutscenes);
if (ORIG_PM_Move)
REG(bxt_ch_noclip_speed);

REG(bxt_splits_print);
REG(bxt_splits_print_times_at_end);
Expand Down Expand Up @@ -2802,8 +2810,26 @@ HOOK_DEF_2(ServerDLL, void, __cdecl, PM_Move, struct playermove_s*, ppmove, int,
auto pmove = reinterpret_cast<uintptr_t>(ppmove);
auto origin = reinterpret_cast<float *>(pmove + offOrigin);
auto flags = reinterpret_cast<int *>(pmove + offFlags);
usercmd_t *cmd = reinterpret_cast<usercmd_t*>(pmove + offCmd);
float *maxspeed = reinterpret_cast<float*>(pmove + offMaxspeed);
float *clientmaxspeed = reinterpret_cast<float*>(pmove + offClientMaxspeed);
int *movetype = reinterpret_cast<int*>(pmove + offMoveType);

auto start_origin = Vector(origin);
auto ch_noclip_vel = CVars::bxt_ch_noclip_speed.GetFloat();

if (*movetype == MOVETYPE_NOCLIP && ch_noclip_vel != 0.f) {
ch_noclip_vel_prev_maxspeed = *maxspeed;
ch_noclip_vel_prev_clientmaxspeed = *clientmaxspeed;

if (*clientmaxspeed == 0.0f)
*clientmaxspeed = *maxspeed;

cmd->forwardmove = cmd->forwardmove / *clientmaxspeed * ch_noclip_vel;
cmd->sidemove = cmd->sidemove / *clientmaxspeed * ch_noclip_vel;
cmd->upmove = cmd->upmove / *clientmaxspeed * ch_noclip_vel;
*maxspeed = *clientmaxspeed = ch_noclip_vel;
}

ORIG_PM_Move(ppmove, server);

Expand All @@ -2812,6 +2838,11 @@ HOOK_DEF_2(ServerDLL, void, __cdecl, PM_Move, struct playermove_s*, ppmove, int,
* This is not always the case but it is a good approximation.
*/
CustomTriggers::Update(start_origin, Vector(origin), (*flags & FL_DUCKING) != 0);

if (*movetype == MOVETYPE_NOCLIP && ch_noclip_vel != 0.f) {
*maxspeed = ch_noclip_vel_prev_maxspeed;
*clientmaxspeed = ch_noclip_vel_prev_clientmaxspeed;
}
}

bool ServerDLL::GetGlobalState(const std::string& name, int& state)
Expand Down
6 changes: 6 additions & 0 deletions BunnymodXT/modules/ServerDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ class ServerDLL : public IHookableDirFilter
ptrdiff_t offInDuck;
ptrdiff_t offFlags;
ptrdiff_t offBasevelocity;
ptrdiff_t offMaxspeed;
ptrdiff_t offClientMaxspeed;
ptrdiff_t offMoveType;

void *pGlobalState;

Expand Down Expand Up @@ -238,4 +241,7 @@ class ServerDLL : public IHookableDirFilter

Vector cmdStartOrigin;
Vector cmdStartVelocity;

float ch_noclip_vel_prev_maxspeed;
float ch_noclip_vel_prev_clientmaxspeed;
};

0 comments on commit cff64fc

Please sign in to comment.