Skip to content

Commit

Permalink
Add bxt_ch_trigger_tp_landmark
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Feb 26, 2024
1 parent 3b32058 commit c59f190
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion BunnymodXT/cvars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@
X(bxt_ch_trigger_tp_keeps_momentum, "0") \
X(bxt_ch_trigger_tp_keeps_momentum_velocity, "1") \
X(bxt_ch_trigger_tp_keeps_momentum_velocity_redirect, "0") \
X(bxt_ch_trigger_tp_keeps_momentum_viewangles, "1")
X(bxt_ch_trigger_tp_keeps_momentum_viewangles, "1") \
X(bxt_ch_trigger_tp_landmark, "0")

class CVarWrapper
{
Expand Down
47 changes: 47 additions & 0 deletions BunnymodXT/modules/ServerDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,7 @@ void ServerDLL::RegisterCVarsAndCommands()
REG(bxt_ch_trigger_tp_keeps_momentum_velocity);
REG(bxt_ch_trigger_tp_keeps_momentum_velocity_redirect);
REG(bxt_ch_trigger_tp_keeps_momentum_viewangles);
REG(bxt_ch_trigger_tp_landmark);
}

REG(bxt_splits_print);
Expand Down Expand Up @@ -3375,10 +3376,14 @@ bool ServerDLL::IsPlayer(edict_t *ent)
return true;
}

#define STRING(offset) ((const char *)(HwDLL::GetInstance().ppGlobals->pStringBase + (unsigned int)(offset)))

HOOK_DEF_3(ServerDLL, void, __fastcall, CBaseTrigger__TeleportTouch, void*, thisptr, int, edx, void*, pOther)
{
auto is_bxt_ch_trigger_tp_keeps_momentum_enabled = CVars::sv_cheats.GetBool() && CVars::bxt_ch_trigger_tp_keeps_momentum.GetBool();
auto is_bxt_ch_trigger_tp_landmark_enabled = CVars::sv_cheats.GetBool() && CVars::bxt_ch_trigger_tp_landmark.GetBool() && pEngfuncs && HwDLL::GetInstance().ppGlobals;

entvars_t *this_pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(pOther) + 4);
Vector prev_vel;
Vector prev_view;
Expand All @@ -3392,6 +3397,16 @@ HOOK_DEF_3(ServerDLL, void, __fastcall, CBaseTrigger__TeleportTouch, void*, this
prev_basevelocity = pev->basevelocity;
}

if (is_bxt_ch_trigger_tp_landmark_enabled) {
edict_t *landmark = pEngfuncs->pfnFindEntityByString(NULL, "targetname", STRING(this_pev->message));
ch_trigger_tp_landmark_available = true;

if (!landmark || landmark->free || !this_pev->message)
ch_trigger_tp_landmark_available = false;

ch_trigger_tp_landmark_offset = Vector(pev->origin) - Vector(landmark->v.origin);
}

ORIG_CBaseTrigger__TeleportTouch(thisptr, edx, pOther);

if (is_bxt_ch_trigger_tp_keeps_momentum_enabled && pev && pEngfuncs && IsPlayer(pev->pContainingEntity)) {
Expand Down Expand Up @@ -3428,12 +3443,24 @@ HOOK_DEF_3(ServerDLL, void, __fastcall, CBaseTrigger__TeleportTouch, void*, this
pev->angles = prev_angles;
}
}

if (is_bxt_ch_trigger_tp_landmark_enabled && ch_trigger_tp_landmark_available) {
pev->origin = pev->origin + ch_trigger_tp_landmark_offset;
// have to offset by some HULL because of origin z diff
auto is_duck = pev->button & (IN_DUCK) || pev->flags & (FL_DUCKING);
if (is_duck)
pev->origin[2] -= 19;
else
pev->origin[2] -= 37;
}
}

HOOK_DEF_2(ServerDLL, void, __cdecl, CBaseTrigger__TeleportTouch_Linux, void*, thisptr, void*, pOther)
{
auto is_bxt_ch_trigger_tp_keeps_momentum_enabled = CVars::sv_cheats.GetBool() && CVars::bxt_ch_trigger_tp_keeps_momentum.GetBool();
auto is_bxt_ch_trigger_tp_landmark_enabled = CVars::sv_cheats.GetBool() && CVars::bxt_ch_trigger_tp_landmark.GetBool() && pEngfuncs && HwDLL::GetInstance().ppGlobals;

entvars_t *this_pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(thisptr) + 4);
entvars_t *pev = *reinterpret_cast<entvars_t**>(reinterpret_cast<uintptr_t>(pOther) + 4);
Vector prev_vel;
Vector prev_view;
Expand All @@ -3443,6 +3470,16 @@ HOOK_DEF_2(ServerDLL, void, __cdecl, CBaseTrigger__TeleportTouch_Linux, void*, t
prev_view = pev->v_angle;
}

if (is_bxt_ch_trigger_tp_landmark_enabled) {
edict_t *landmark = pEngfuncs->pfnFindEntityByString(NULL, "targetname", STRING(this_pev->message));
ch_trigger_tp_landmark_available = true;

if (!landmark || landmark->free || !this_pev->message)
ch_trigger_tp_landmark_available = false;

ch_trigger_tp_landmark_offset = Vector(pev->origin) - Vector(landmark->v.origin);
}

ORIG_CBaseTrigger__TeleportTouch_Linux(thisptr, pOther);

if (is_bxt_ch_trigger_tp_keeps_momentum_enabled && pev && pEngfuncs && IsPlayer(pev->pContainingEntity)) {
Expand All @@ -3469,4 +3506,14 @@ HOOK_DEF_2(ServerDLL, void, __cdecl, CBaseTrigger__TeleportTouch_Linux, void*, t
pev->v_angle = prev_view;
}
}

if (is_bxt_ch_trigger_tp_landmark_enabled && ch_trigger_tp_landmark_available) {
pev->origin = pev->origin + ch_trigger_tp_landmark_offset;
// have to offset by some HULL because of origin z diff
auto is_duck = pev->button & (IN_DUCK) || pev->flags & (FL_DUCKING);
if (is_duck)
pev->origin[2] -= 19;
else
pev->origin[2] -= 37;
}
}
3 changes: 3 additions & 0 deletions BunnymodXT/modules/ServerDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,7 @@ class ServerDLL : public IHookableDirFilter
std::deque<bool> traceLineFireBulletsHit;

bool insideCBasePlayerJump = false;

Vector ch_trigger_tp_landmark_offset;
bool ch_trigger_tp_landmark_available;
};

0 comments on commit c59f190

Please sign in to comment.