Skip to content

Commit

Permalink
Added HF_IsEntityTrigger macro to determine if entity is trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG committed Apr 7, 2024
1 parent 6e9626e commit c64f37a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 4 additions & 0 deletions BunnymodXT/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const steamid_t STEAMID64_CONST = 76561197960265728; // 0x110000100000000
#define HF_DoesMapNameMatch(map) \
helper_functions::does_mapname_match(map)

// Don't remove parentheses from this macro or we're doomed!
#define HF_IsEntityTrigger(classname) \
(!strncmp(classname, "trigger_", 8) || !strcmp(classname, "func_ladder"))

namespace helper_functions
{
// https://github.com/ValveSoftware/halflife/blob/master/common/parsemsg.cpp
Expand Down
13 changes: 4 additions & 9 deletions BunnymodXT/modules/ServerDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,9 +2317,7 @@ void ServerDLL::DoAutoStopTasks()

void ServerDLL::GetTriggerColor(const char *classname, float &r, float &g, float &b)
{
bool is_trigger = std::strncmp(classname, "trigger_", 8) == 0;
bool is_ladder = std::strncmp(classname, "func_ladder", 11) == 0;
if (!is_trigger && !is_ladder)
if (!HF_IsEntityTrigger(classname))
return;

if (is_ladder)
Expand Down Expand Up @@ -2385,9 +2383,7 @@ void ServerDLL::GetTriggerColor(const char *classname, float &r, float &g, float

void ServerDLL::GetTriggerAlpha(const char *classname, bool inactive, bool additive, float &a)
{
bool is_trigger = std::strncmp(classname, "trigger_", 8) == 0;
bool is_ladder = std::strncmp(classname, "func_ladder", 11) == 0;
if (!is_trigger && !is_ladder)
if (!HF_IsEntityTrigger(classname))
return;

// The alpha should be lower in additive modes.
Expand Down Expand Up @@ -2421,8 +2417,7 @@ HOOK_DEF_7(ServerDLL, int, __cdecl, AddToFullPack, struct entity_state_s*, state
auto oldIUser2 = ent->v.iuser2;

const char *classname = HwDLL::GetInstance().ppGlobals->pStringBase + ent->v.classname;
bool is_trigger = std::strncmp(classname, "trigger_", 8) == 0;
bool is_ladder = std::strncmp(classname, "func_ladder", 11) == 0;
bool is_trigger = HF_IsEntityTrigger(classname);

if (!is_trigger && CVars::bxt_show_hidden_entities.GetBool()) {
bool show = ent->v.rendermode != kRenderNormal && ent->v.rendermode != kRenderGlow;
Expand Down Expand Up @@ -2451,7 +2446,7 @@ HOOK_DEF_7(ServerDLL, int, __cdecl, AddToFullPack, struct entity_state_s*, state
ent->v.rendermode = kRenderTransTexture;
}
}
else if ((is_trigger || is_ladder) && CVars::bxt_show_triggers_legacy.GetBool()) {
else if (is_trigger && CVars::bxt_show_triggers_legacy.GetBool()) {
ent->v.effects &= ~EF_NODRAW;
ent->v.renderamt = 0;
ent->v.rendermode = kRenderTransColor;
Expand Down
4 changes: 1 addition & 3 deletions BunnymodXT/triangle_drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ namespace TriangleDrawing
continue;

const char *classname = HwDLL::GetInstance().GetString(ent->v.classname);
bool is_trigger = std::strncmp(classname, "trigger_", 8) == 0;
bool is_ladder = std::strncmp(classname, "func_ladder", 11) == 0;

if (!is_trigger && !is_ladder)
if (!HF_IsEntityTrigger(classname))
continue;

const model_t *model = HwDLL::GetInstance().GetModelByIndex(ent->v.modelindex);
Expand Down

0 comments on commit c64f37a

Please sign in to comment.