Skip to content

Commit

Permalink
Changed code due of reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG committed Feb 21, 2023
1 parent 6d9240a commit 95872b2
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 98 deletions.
7 changes: 1 addition & 6 deletions BunnymodXT/hud_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,8 @@ namespace CustomHud
{
out << "Yaw: " << ent->v.angles[1] << '\n';

// Borrowed from https://github.com/SNMetamorph/goldsrc-monitor/blob/08c368e246d09996b2d85e4367d4d8cc1e507712/sources/library/displaymode_entityreport.cpp#L45
Vector origin;

if (ent->v.solid == SOLID_BSP || ent->v.movetype == MOVETYPE_PUSHSTEP)
origin = ent->v.origin + ((ent->v.mins + ent->v.maxs) / 2.f);
else
origin = ent->v.origin;
HwDLL::GetInstance().GetOriginOfEntity(origin, ent);

out << "X: " << origin.x << '\n';
out << "Y: " << origin.y << '\n';
Expand Down
186 changes: 95 additions & 91 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2893,7 +2893,7 @@ struct HwDLL::Cmd_BXT_CH_Get_Other_Player_Info
if ((*hw.sv_player)->v.flags & FL_DUCKING)
out << "FL_DUCKING; ";
if ((*hw.sv_player)->v.flags & FL_ONTRAIN)
out << "FL_ONTRAIN";
out << "FL_ONTRAIN; ";
out << '\n';
hw.ORIG_Con_Printf("%s", out.str().c_str());
hw.ORIG_Con_Printf("bInDuck: %d\n", (*hw.sv_player)->v.bInDuck);
Expand Down Expand Up @@ -3046,7 +3046,7 @@ struct HwDLL::Cmd_BXT_Timer_Reset
}
};

struct HwDLL::Cmd_BXT_Get_ServerTime
struct HwDLL::Cmd_BXT_Get_Server_Time
{
NO_USAGE();

Expand Down Expand Up @@ -3807,26 +3807,72 @@ struct HwDLL::Cmd_BXT_FreeCam
}
};

void HwDLL::PrintEntities(std::ostringstream &out, int e, const edict_t* ent)
{
const auto& hw = HwDLL::GetInstance();
const char* classname = hw.GetString(ent->v.classname);
const char* targetname = hw.GetString(ent->v.targetname);
const char* target = hw.GetString(ent->v.target);

out << e << ": " << classname;

if (ent->v.targetname != 0) {
out << "; name: " << targetname;
}

if (ent->v.target != 0) {
out << "; target: " << target;
}

out << "; hp: " << ent->v.health;

if ((!strncmp(classname, "func_door", 9)) || (!strncmp(classname, "func_rotating", 13)) || (!strncmp(classname, "func_train", 10)))
out << "; dmg: " << ent->v.dmg;

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;

Vector origin;
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;

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

out << '\n';
}

struct HwDLL::Cmd_BXT_Print_Entities
{
NO_USAGE();
USAGE("Usage:\n"
"bxt_print_entities <classname>\n"
"bxt_print_entities <targetname>\n"
"bxt_print_entities <target>\n"
"bxt_print_entities <classname> <classname>\n"
"bxt_print_entities <classname> strcmp\n"
"bxt_print_entities <targetname> targetname\n"
"bxt_print_entities <target> targetname\n"
);

static void handler(const char *name1, const char *name2)
static void handler(const char* name1, const char* name2)
{
const auto& hw = HwDLL::GetInstance();

std::ostringstream out;

edict_t *edicts;
edict_t* edicts;
const int numEdicts = hw.GetEdicts(&edicts);
for (int e = 0; e < numEdicts; ++e) {
const edict_t *ent = edicts + e;
const edict_t* ent = edicts + e;
if (!hw.IsValidEdict(ent))
continue;

const char *classname = hw.GetString(ent->v.classname);
const char *targetname = hw.GetString(ent->v.targetname);
const char *target = hw.GetString(ent->v.target);
const char* classname = hw.GetString(ent->v.classname);
const char* targetname = hw.GetString(ent->v.targetname);
const char* target = hw.GetString(ent->v.target);
if (std::strcmp(name2, "targetname") == 0)
{
if ((std::strcmp(targetname, name1) != 0) && (std::strcmp(target, name1) != 0))
Expand All @@ -3843,127 +3889,85 @@ struct HwDLL::Cmd_BXT_Print_Entities
continue;
}

out << e << ": " << classname;

if (ent->v.targetname != 0) {
out << "; name: " << targetname;
}

if (ent->v.target != 0) {
out << "; target: " << target;
}

out << "; hp: " << ent->v.health;

if ((strstr(classname, "func_door") != NULL) || (!strncmp(classname, "func_rotating", 13)) || (!strncmp(classname, "func_train", 10)))
out << "; dmg: " << ent->v.dmg;

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;

Vector origin;
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;

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

out << '\n';
HwDLL::GetInstance().PrintEntities(out, e, ent);
}

auto str = out.str();
hw.ORIG_Con_Printf("%s", str.c_str());
}

static void handler(const char *name)
static void handler(const char* name)
{
const auto& hw = HwDLL::GetInstance();

std::ostringstream out;

edict_t *edicts;
edict_t* edicts;
const int numEdicts = hw.GetEdicts(&edicts);
for (int e = 0; e < numEdicts; ++e) {
const edict_t *ent = edicts + e;
const edict_t* ent = edicts + e;
if (!hw.IsValidEdict(ent))
continue;

const char *classname = hw.GetString(ent->v.classname);
if (strstr(classname, name) == 0)
continue;

out << e << ": " << classname;

if (ent->v.targetname != 0) {
const char *targetname = hw.GetString(ent->v.targetname);
out << "; name: " << targetname;
}

if (ent->v.target != 0) {
const char *target = hw.GetString(ent->v.target);
out << "; target: " << target;
}

out << "; hp: " << ent->v.health;

if ((strstr(classname, "func_door") != NULL) || (!strncmp(classname, "func_rotating", 13)) || (!strncmp(classname, "func_train", 10)))
out << "; dmg: " << ent->v.dmg;

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;

Vector origin;
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;

out << "; xyz: " << origin.x << " " << origin.y << " " << origin.z;
const char* classname = hw.GetString(ent->v.classname);
const char* targetname = hw.GetString(ent->v.targetname);
const char* target = hw.GetString(ent->v.target);
if ((strstr(classname, name) == 0) && (std::strcmp(targetname, name) != 0) && (std::strcmp(target, name) != 0))
continue;

out << '\n';
HwDLL::GetInstance().PrintEntities(out, e, ent);
}

auto str = out.str();
hw.ORIG_Con_Printf("%s", str.c_str());
}
};

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
{
NO_USAGE();
USAGE("Usage: bxt_ch_teleport_to_entity <index>\n");

static void handler(int num)
{
const auto& hw = HwDLL::GetInstance();

std::ostringstream out;

edict_t *edicts;
edict_t* edicts;
const int numEdicts = hw.GetEdicts(&edicts);

if (num >= numEdicts)
{
hw.ORIG_Con_Printf("Error: not found entity with that index; num_edicts is %d\n", numEdicts);
return;
}

for (int e = 0; e < numEdicts; ++e) {
const edict_t *ent = edicts + e;
const edict_t* ent = edicts + e;
if (!hw.IsValidEdict(ent))
continue;

if (e != num)
continue;

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;

Vector origin;
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;
HwDLL::GetInstance().GetOriginOfEntity(origin, ent);

out << "bxt_ch_set_pos " << origin.x << " " << origin.y << " " << origin.z;

Expand Down Expand Up @@ -4845,7 +4849,7 @@ void HwDLL::RegisterCVarsAndCommandsIfNeeded()
Cmd_BXT_Set_Angles,
Handler<float, float>,
Handler<float, float, float>>("bxt_set_angles");
wrapper::Add<Cmd_BXT_Get_ServerTime, Handler<>>("bxt_get_servertime");
wrapper::Add<Cmd_BXT_Get_Server_Time, Handler<>>("bxt_get_server_time");
wrapper::Add<
Cmd_Multiwait,
Handler<>,
Expand Down Expand Up @@ -5872,9 +5876,9 @@ const char* HwDLL::GetMovetypeName(int moveType)
case MOVETYPE_TOSS: return "Toss";
case MOVETYPE_PUSH: return "Push";
case MOVETYPE_NOCLIP: return "Noclip";
case MOVETYPE_FLYMISSILE: return "Fly-missle";
case MOVETYPE_FLYMISSILE: return "Fly-missile";
case MOVETYPE_BOUNCE: return "Bounce";
case MOVETYPE_BOUNCEMISSILE: return "Bounce-missle";
case MOVETYPE_BOUNCEMISSILE: return "Bounce-missile";
case MOVETYPE_FOLLOW: return "Follow";
case MOVETYPE_PUSHSTEP: return "Push-step";
default: return "Unknown";
Expand Down
4 changes: 3 additions & 1 deletion BunnymodXT/modules/HwDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class HwDLL : public IHookableNameFilterOrdered
struct Cmd_BXT_CH_Get_Velocity;
struct Cmd_BXT_CH_Get_Other_Player_Info;
struct Cmd_BXT_Get_Origin_And_Angles;
struct Cmd_BXT_Get_ServerTime;
struct Cmd_BXT_Get_Server_Time;
struct Cmd_Multiwait;
struct Cmd_BXT_Camera_Fixed;
struct Cmd_BXT_Camera_Clear;
Expand Down Expand Up @@ -503,9 +503,11 @@ class HwDLL : public IHookableNameFilterOrdered
bool GetNextMovementFrame(HLTAS::Frame& f);
void ResetButtons();
void FindCVarsIfNeeded();
void PrintEntities(std::ostringstream &out, int e, const edict_t* ent);
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

0 comments on commit 95872b2

Please sign in to comment.