From 5a7bb275f8ff2d9b89f83de49d959119486a99f6 Mon Sep 17 00:00:00 2001 From: SmileyAG <58108407+SmileyAG@users.noreply.github.com> Date: Fri, 12 Jul 2024 23:17:40 +0400 Subject: [PATCH 1/2] helper_functions: added IsBSPModel function to determine if it is brush entity --- BunnymodXT/helper_functions.cpp | 10 ++++++++++ BunnymodXT/helper_functions.hpp | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/BunnymodXT/helper_functions.cpp b/BunnymodXT/helper_functions.cpp index 34600c6b..a905ebc7 100644 --- a/BunnymodXT/helper_functions.cpp +++ b/BunnymodXT/helper_functions.cpp @@ -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 diff --git a/BunnymodXT/helper_functions.hpp b/BunnymodXT/helper_functions.hpp index 44961a28..890dd177 100644 --- a/BunnymodXT/helper_functions.hpp +++ b/BunnymodXT/helper_functions.hpp @@ -10,6 +10,10 @@ 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); From d11780c1eb621ae56318c23ed51a62b281f772c0 Mon Sep 17 00:00:00 2001 From: SmileyAG <58108407+SmileyAG@users.noreply.github.com> Date: Fri, 12 Jul 2024 23:48:11 +0400 Subject: [PATCH 2/2] helper_functions: added get_origin_of_entity function to determine the real origin of entity --- BunnymodXT/helper_functions.cpp | 11 ++++++++++- BunnymodXT/helper_functions.hpp | 3 ++- BunnymodXT/hud_custom.cpp | 3 +-- BunnymodXT/modules/HwDLL.cpp | 22 ++-------------------- BunnymodXT/modules/HwDLL.hpp | 1 - 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/BunnymodXT/helper_functions.cpp b/BunnymodXT/helper_functions.cpp index a905ebc7..6a0312c3 100644 --- a/BunnymodXT/helper_functions.cpp +++ b/BunnymodXT/helper_functions.cpp @@ -50,4 +50,13 @@ namespace helper_functions std::exit(1); } -}; \ No newline at end of file + + Vector get_origin_of_entity(const edict_t* ent) + { + Vector origin = ent->v.origin; + if (IsBSPModel(ent)) + origin = Center(ent); + + return origin; + } +}; diff --git a/BunnymodXT/helper_functions.hpp b/BunnymodXT/helper_functions.hpp index 890dd177..a471a569 100644 --- a/BunnymodXT/helper_functions.hpp +++ b/BunnymodXT/helper_functions.hpp @@ -17,4 +17,5 @@ namespace helper_functions 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); -} \ No newline at end of file + Vector get_origin_of_entity(const edict_t* ent); +} diff --git a/BunnymodXT/hud_custom.cpp b/BunnymodXT/hud_custom.cpp index 732f2eb3..21511d83 100644 --- a/BunnymodXT/hud_custom.cpp +++ b/BunnymodXT/hud_custom.cpp @@ -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'; diff --git a/BunnymodXT/modules/HwDLL.cpp b/BunnymodXT/modules/HwDLL.cpp index 55d0377a..2578a661 100644 --- a/BunnymodXT/modules/HwDLL.cpp +++ b/BunnymodXT/modules/HwDLL.cpp @@ -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; @@ -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; - - // 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 \n"); @@ -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]; diff --git a/BunnymodXT/modules/HwDLL.hpp b/BunnymodXT/modules/HwDLL.hpp index e759818a..a069f9cc 100644 --- a/BunnymodXT/modules/HwDLL.hpp +++ b/BunnymodXT/modules/HwDLL.hpp @@ -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;