Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle cases when player in water / on ladder for +bxt_tas_autojump #357

Merged
merged 4 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BunnymodXT/input_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ void EditedInput::simulate() {
std::placeholders::_3
);

const auto point_contents_func = std::bind(
*(ClientDLL::GetInstance().pEngfuncs->PM_PointContents),
std::placeholders::_1,
nullptr
);

size_t total_frames = frame_bulk_starts[first_frame_bulk];

auto player = *(player_datas.cend() - 1);
Expand Down Expand Up @@ -153,6 +159,7 @@ void EditedInput::simulate() {
hw.Buttons,
hw.ButtonsPresent,
trace_func,
point_contents_func,
hw.hlstrafe_version
);

Expand Down
29 changes: 20 additions & 9 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4235,6 +4235,7 @@ void HwDLL::InsertCommands()
player.InDuckAnimation = (pl->v.bInDuck != 0);
player.DuckTime = static_cast<float>(pl->v.flDuckTime);
player.StaminaTime = pl->v.fuser2;
player.Walking = (pl->v.movetype == MOVETYPE_WALK);

if (ORIG_PF_GetPhysicsKeyValue) {
auto slj = std::atoi(ORIG_PF_GetPhysicsKeyValue(pl, "slj"));
Expand Down Expand Up @@ -4334,7 +4335,16 @@ void HwDLL::InsertCommands()
});

StartTracing();
auto p = HLStrafe::MainFunc(player, movement_vars, f, StrafeState, Buttons, ButtonsPresent, std::bind(&HwDLL::UnsafePlayerTrace, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), hlstrafe_version);
auto p = HLStrafe::MainFunc(
player,
movement_vars,
f,
StrafeState,
Buttons,
ButtonsPresent,
std::bind(&HwDLL::UnsafePlayerTrace, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3),
std::bind(*(ClientDLL::GetInstance().pEngfuncs->PM_PointContents), std::placeholders::_1, nullptr),
hlstrafe_version);
StopTracing();

PrevFractions = { p.fractions[0], p.fractions[1], p.fractions[2], p.fractions[3] };
Expand Down Expand Up @@ -4823,6 +4833,7 @@ void HwDLL::InsertCommands()
player.InDuckAnimation = (pl->v.bInDuck != 0);
player.DuckTime = static_cast<float>(pl->v.flDuckTime);
player.StaminaTime = pl->v.fuser2;
player.Walking = (pl->v.movetype == MOVETYPE_WALK);

if (ORIG_PF_GetPhysicsKeyValue) {
auto slj = std::atoi(ORIG_PF_GetPhysicsKeyValue(pl, "slj"));
Expand All @@ -4841,9 +4852,9 @@ void HwDLL::InsertCommands()

auto playerCopy = HLStrafe::PlayerData(player); // Our copy that we will mess with.
auto traceFunc = std::bind(&HwDLL::PlayerTrace, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, false);
auto postype = GetPositionType(playerCopy, traceFunc);
if (postype == HLStrafe::PositionType::GROUND) {
if (ducktap) {
auto pointContentsFunc = std::bind(*(ClientDLL::GetInstance().pEngfuncs->PM_PointContents), std::placeholders::_1, nullptr);
auto postype = GetPositionType(playerCopy, traceFunc, pointContentsFunc);
if (ducktap && postype == HLStrafe::PositionType::GROUND) {
if (!currentKeys.Duck.IsDown() && !playerCopy.InDuckAnimation) {
// This should check against the next frame's origin but meh.
const float VEC_HULL_MIN[3] = { -16, -16, -36 };
Expand All @@ -4856,25 +4867,24 @@ void HwDLL::InsertCommands()
if (!tr.StartSolid)
Duck = true;
}
} else if (autojump && !currentKeys.Jump.IsDown()) {
Jump = true;
}
} else if (autojump && !currentKeys.Jump.IsDown() && (postype != HLStrafe::PositionType::AIR || !player.Walking)) {
Jump = true;
} else if (jumpbug && postype == HLStrafe::PositionType::AIR) {
if (player.Ducking) {
// Predict what will happen if we unduck.
playerCopy.Ducking = false;
playerCopy.InDuckAnimation = false;
playerCopy.DuckTime = 0;

auto nextPostype = HLStrafe::GetPositionType(playerCopy, traceFunc);
auto nextPostype = HLStrafe::GetPositionType(playerCopy, traceFunc, pointContentsFunc);
if (nextPostype == HLStrafe::PositionType::GROUND) {
// Jumpbug if we're about to land.
Jump = true;
Duck = false;
}
} else {
auto vars = GetMovementVars();
auto nextPostype = HLStrafe::Move(playerCopy, vars, postype, vars.Maxspeed, traceFunc);
auto nextPostype = HLStrafe::Move(playerCopy, vars, postype, vars.Maxspeed, traceFunc, pointContentsFunc);
if (nextPostype == HLStrafe::PositionType::GROUND) {
// Duck to prepare for the Jumpbug.
Duck = true;
Expand Down Expand Up @@ -4953,6 +4963,7 @@ HLStrafe::PlayerData HwDLL::GetPlayerData()
player.InDuckAnimation = (pl->v.bInDuck != 0);
player.DuckTime = static_cast<float>(pl->v.flDuckTime);
player.StaminaTime = pl->v.fuser2;
player.Walking = (pl->v.movetype == MOVETYPE_WALK);

if (ORIG_PF_GetPhysicsKeyValue) {
auto slj = std::atoi(ORIG_PF_GetPhysicsKeyValue(pl, "slj"));
Expand Down
2 changes: 1 addition & 1 deletion HLSDK/engine/cdll_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ typedef struct cl_enginefuncs_s
void ( *V_CalcShake ) ( void );
void ( *V_ApplyShake ) ( float *origin, float *angles, float factor );

int ( *PM_PointContents ) ( float *point, int *truecontents );
int ( *PM_PointContents ) ( const float *point, int *truecontents );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check in ghidra that it doesn't modify point? Just in case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it does not

int ( *PM_WaterEntity ) ( float *p );
struct pmtrace_s *( *PM_TraceLine ) ( float *start, float *end, int flags, int usehull, int ignore_pe );

Expand Down
2 changes: 1 addition & 1 deletion hlstrafe
Submodule hlstrafe updated 2 files
+73 −53 src/hlstrafe.cpp
+15 −13 src/hlstrafe.hpp