Skip to content

Commit

Permalink
feat: SetModel input & Steam ID filtering (#317)
Browse files Browse the repository at this point in the history
* feat: map perks api

* add fake convar

* Fix being affected by noblock cvar & rename cvar

---------

Co-authored-by: Alex <[email protected]>
  • Loading branch information
Kxnrl and Vauff authored Oct 31, 2024
1 parent e293b76 commit a8b95f8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions cfg/cs2fixes/cs2fixes.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cs2f_disable_subtick_shooting 0 // Whether to disable subtick shooting, experim
cs2f_full_alltalk 0 // Whether to enforce sv_full_alltalk 1
cs2f_drop_map_weapons 0 // Whether to force drop map-spawned weapons on death
cs2f_prevent_using_players 0 // Whether to prevent +use from hitting players (0=can use players, 1=cannot use players)
cs2f_map_steamids_enable 0 // Whether to make Steam ID's available to maps
cs2f_beacon_particle "particles/cs2fixes/player_beacon.vpcf" // .vpcf file to be precached and used for player beacon
Expand Down
8 changes: 8 additions & 0 deletions src/cs2_sdk/entity/cbaseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ class CBaseEntity : public CEntityInstance
return nullptr;
}

[[nodiscard]] CBaseModelEntity* AsBaseModelEntity()
{
if (const auto pCollision = this->m_pCollision())
return reinterpret_cast<CBaseModelEntity*>(this);

return nullptr;
}

/* End Custom Entities Cast */
};

Expand Down
14 changes: 13 additions & 1 deletion src/detours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ bool FASTCALL Detour_CEntityIdentity_AcceptInput(CEntityIdentity* pThis, CUtlSym
Message("Invalid value type for input %s\n", pInputName->String());
return false;
}
else if (!V_strnicmp(pInputName->String(), "IgniteL", 7)) // Override IgniteLifetime

if (!V_strnicmp(pInputName->String(), "IgniteL", 7)) // Override IgniteLifetime
{
float flDuration = 0.f;

Expand Down Expand Up @@ -435,6 +436,17 @@ bool FASTCALL Detour_CEntityIdentity_AcceptInput(CEntityIdentity* pThis, CUtlSym
return true;
}
}
else if (!V_strcasecmp(pInputName->String(), "SetModel"))
{
if (const auto pModelEntity = reinterpret_cast<CBaseEntity*>(pThis->m_pInstance)->AsBaseModelEntity())
{
if ((value->m_type == FIELD_CSTRING || value->m_type == FIELD_STRING) && value->m_pszString)
{
pModelEntity->SetModel(value->m_pszString);
}
return true;
}
}
else if (const auto pGameUI = reinterpret_cast<CBaseEntity*>(pThis->m_pInstance)->AsGameUI())
{
if (!V_strcasecmp(pInputName->String(), "Activate"))
Expand Down
14 changes: 8 additions & 6 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,26 @@ GAME_EVENT_F(player_spawn)
if (pController->IsConnected())
pController->GetZEPlayer()->OnSpawn();

// Rest of the code is to set debris collisions
if (!g_bNoblock)
return;

CHandle<CCSPlayerController> hController = pController->GetHandle();

// Gotta do this on the next frame...
new CTimer(0.0f, false, false, [hController]()
{
CCSPlayerController *pController = hController.Get();

if (!pController || !pController->m_bPawnIsAlive())
if (!pController)
return -1.0f;

if (const auto player = pController->GetZEPlayer())
player->SetSteamIdAttribute();

if (!pController->m_bPawnIsAlive())
return -1.0f;

CBasePlayerPawn *pPawn = pController->GetPawn();

// Just in case somehow there's health but the player is, say, an observer
if (!pPawn || !pPawn->IsAlive())
if (!g_bNoblock || !pPawn || !pPawn->IsAlive())
return -1.0f;

pPawn->SetCollisionGroup(COLLISION_GROUP_DEBRIS);
Expand Down
25 changes: 25 additions & 0 deletions src/playermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ extern CGameEntitySystem *g_pEntitySystem;
extern CGlobalVars *gpGlobals;

static int g_iAdminImmunityTargetting = 0;
static bool g_bEnableMapSteamIds = false;

FAKE_INT_CVAR(cs2f_admin_immunity, "Mode for which admin immunity system targetting allows: 0 - strictly lower, 1 - equal to or lower, 2 - ignore immunity levels", g_iAdminImmunityTargetting, 0, false)
FAKE_BOOL_CVAR(cs2f_map_steamids_enable, "Whether to make Steam ID's available to maps", g_bEnableMapSteamIds, false, 0)

ZEPlayerHandle::ZEPlayerHandle() : m_Index(INVALID_ZEPLAYERHANDLE_INDEX) {};

Expand Down Expand Up @@ -110,6 +112,8 @@ void ZEPlayer::OnAuthenticated()
CheckAdmin();
CheckInfractions();
g_pUserPreferencesSystem->PullPreferences(GetPlayerSlot().Get());

SetSteamIdAttribute();
}

void ZEPlayer::CheckInfractions()
Expand Down Expand Up @@ -497,6 +501,27 @@ void ZEPlayer::EndGlow()
addresses::UTIL_Remove(pModelParent);
}

void ZEPlayer::SetSteamIdAttribute()
{
if (!g_bEnableMapSteamIds)
return;

if (!IsAuthenticated())
return;

const auto pController = CCSPlayerController::FromSlot(GetPlayerSlot());
if (!pController || !pController->IsConnected() || pController->IsBot() || pController->m_bIsHLTV())
return;

const auto pPawn = pController->GetPlayerPawn();
if (!pPawn)
return;

const auto& steamId = std::to_string(GetSteamId64());
pPawn->AcceptInput("AddAttribute", steamId.c_str());
pController->AcceptInput("AddAttribute", steamId.c_str());
}

void ZEPlayer::ReplicateConVar(const char* pszName, const char* pszValue)
{
INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("SetConVar");
Expand Down
1 change: 1 addition & 0 deletions src/playermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class ZEPlayer
void PurgeLeaderVotes();
void StartGlow(Color color, int duration);
void EndGlow();
void SetSteamIdAttribute();

private:
bool m_bAuthenticated;
Expand Down

0 comments on commit a8b95f8

Please sign in to comment.