Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

helper_functions: added IsBSPModel and get_origin_of_entity functions #544

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion BunnymodXT/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

namespace helper_functions
{
bool IsBSPModel(const int solid, const int movetype)
{
if ((solid == SOLID_BSP) || (movetype == MOVETYPE_PUSHSTEP))
return true;

return false;
}

bool IsBSPModel(const edict_t *ent) { return IsBSPModel(ent->v.solid, ent->v.movetype); }

void com_fixslashes(std::string &str)
{
// https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/game_shared/bot/nav_file.cpp#L680
Expand Down Expand Up @@ -40,4 +50,13 @@ namespace helper_functions

std::exit(1);
}
};

Vector get_origin_of_entity(const edict_t* ent)
{
Vector origin = ent->v.origin;
if (IsBSPModel(ent))
origin = Center(ent);

return origin;
}
};
7 changes: 6 additions & 1 deletion BunnymodXT/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

namespace helper_functions
{
// https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/cbase.h#L197-L198
bool IsBSPModel(const int solid, const int movetype);
bool IsBSPModel(const edict_t *ent);

void com_fixslashes(std::string &str);
std::string swap_lib(const char* current_lib_path, std::string new_lib_path, const char *start);
void crash_if_failed(std::string str);
}
Vector get_origin_of_entity(const edict_t* ent);
}
3 changes: 1 addition & 2 deletions BunnymodXT/hud_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,7 @@ namespace CustomHud
{
out << "Yaw: " << ent->v.angles[1] << '\n';

Vector origin;
HwDLL::GetInstance().GetOriginOfEntity(origin, ent);
Vector origin = helper_functions::get_origin_of_entity(ent);

out << "X: " << origin.x << '\n';
out << "Y: " << origin.y << '\n';
Expand Down
22 changes: 2 additions & 20 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4628,8 +4628,7 @@ void HwDLL::PrintEntity(std::ostringstream &out, int index)
if ((!strncmp(classname, "func_door", 9)) || (!strncmp(classname, "func_rotating", 13)) || (!strncmp(classname, "func_train", 10)))
out << "; dmg: " << ent->v.dmg;

Vector origin;
HwDLL::GetInstance().GetOriginOfEntity(origin, ent);
Vector origin = helper_functions::get_origin_of_entity(ent);

out << "; xyz: " << origin.x << " " << origin.y << " " << origin.z;

Expand Down Expand Up @@ -4777,22 +4776,6 @@ struct HwDLL::Cmd_BXT_Print_Entities_By_Index
}
};

void HwDLL::GetOriginOfEntity(Vector& origin, const edict_t* ent)
{
const auto& hw = HwDLL::GetInstance();
const char* classname = hw.GetString(ent->v.classname);
bool is_trigger = std::strncmp(classname, "trigger_", 8) == 0;
bool is_ladder = std::strncmp(classname, "func_ladder", 11) == 0;
bool is_friction = std::strncmp(classname, "func_friction", 13) == 0;
bool is_water = std::strncmp(classname, "func_water", 10) == 0;
Comment on lines -4784 to -4787
Copy link
Owner

Choose a reason for hiding this comment

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

This seems relevant at least for teleport to entity?

Copy link
Collaborator Author

@SmileyAG SmileyAG Jul 31, 2024

Choose a reason for hiding this comment

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

Well, in general, yes, but at first thought I thinked about making a separate mode or cmd that will teleport to the center point of the entity.

Although I'll probably try to think more about how to better determine cases when an adjustment in the position for entities is needed, because the HLSDK function does not handle that types of brush entities.

Copy link
Collaborator Author

@SmileyAG SmileyAG Jul 31, 2024

Choose a reason for hiding this comment

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

But still, if nothing better happens, then it will be possible to return to the initial version, when all entities whose classname begins with trigger_ and func_ are set to the origin of the point from the center, stupid - but better than nothing.


// Credits to 'goldsrc_monitor' tool for their code to get origin of entities
if (ent->v.solid == SOLID_BSP || ent->v.movetype == MOVETYPE_PUSHSTEP || is_trigger || is_ladder || is_friction || is_water)
origin = ent->v.origin + ((ent->v.mins + ent->v.maxs) / 2.f);
else
origin = ent->v.origin;
}

struct HwDLL::Cmd_BXT_CH_Teleport_To_Entity
{
USAGE("Usage: bxt_ch_teleport_to_entity <index>\n");
Expand All @@ -4817,8 +4800,7 @@ struct HwDLL::Cmd_BXT_CH_Teleport_To_Entity
return;
}

Vector origin;
HwDLL::GetInstance().GetOriginOfEntity(origin, ent);
Vector origin = helper_functions::get_origin_of_entity(ent);

(*hw.sv_player)->v.origin[0] = origin[0];
(*hw.sv_player)->v.origin[1] = origin[1];
Expand Down
1 change: 0 additions & 1 deletion BunnymodXT/modules/HwDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ class HwDLL : public IHookableNameFilterOrdered
public:
HLStrafe::MovementVars GetMovementVars();
const char* GetMovetypeName(int moveType);
void GetOriginOfEntity(Vector& origin, const edict_t* ent);

bool ducktap;
edict_t **sv_player;
Expand Down
Loading