Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!hide #47

Merged
merged 12 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gamedata/cs2fixes.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@
{
"windows" "173"
"linux" "172"
}
"IsEntityPawn"
{
"windows" "152"
"linux" "151"
}
"IsEntityController"
{
"windows" "153"
"linux" "152"
}
}
"Patches"
Expand Down
2 changes: 1 addition & 1 deletion sdk
Submodule sdk updated 53 files
+2 −2 entity2/entitysystem.cpp
+1 −1 game/server/baseentity.h
+3 −3 game/shared/ehandle.h
+ lib/linux64/libtier0.so
+ lib/linux64/mathlib.a
+ lib/linux64/tier1.a
+ lib/public/win64/interfaces.lib
+ lib/public/win64/mathlib.lib
+ lib/public/win64/tier0.lib
+ lib/public/win64/tier1.lib
+1 −1 linux_sdk/Makefile
+1 −4 linux_sdk/Makefile.tier1
+1 −1 mathlib/mathlib.vcxproj
+1 −1 public/const.h
+0 −276 public/edict.h
+7 −27 public/eiface.h
+2 −2 public/engine/ICollideable.h
+24 −20 public/engine/IEngineService.h
+9 −9 public/engine/IEngineTrace.h
+1 −1 public/engine/IStaticPropMgr.h
+62 −0 public/engine/eventdispatcher.h
+55 −14 public/entity2/entityidentity.h
+66 −0 public/entity2/entityinstance.h
+3 −3 public/entity2/entitysystem.h
+14 −33 public/entityhandle.h
+0 −1 public/gametrace.h
+2 −2 public/iclientunknown.h
+8 −11 public/igameevents.h
+0 −25 public/ihandleentity.h
+150 −0 public/iloopmode.h
+5 −1 public/inputsystem/InputEnums.h
+2 −2 public/irecipientfilter.h
+6 −4 public/iserver.h
+5 −16 public/iservernetworkable.h
+2 −2 public/iserverunknown.h
+4 −4 public/ispatialpartition.h
+1 −1 public/particles/particles.h
+4 −7 public/tier0/dbg.h
+2 −0 public/tier0/memalloc.h
+26 −1 public/tier0/platform.h
+61 −43 public/tier0/threadtools.h
+1 −1 public/tier1/generichash.h
+74 −0 public/tier1/memblockallocator.h
+34 −0 public/tier1/rawallocator.h
+2 −0 public/tier1/strtools.h
+120 −59 public/tier1/utlhashtable.h
+341 −92 public/tier1/utlmemory.h
+238 −345 public/tier1/utlsymbollarge.h
+4 −4 public/tier1/utlvector.h
+1 −1 public/toolframework/ienginetool.h
+1 −1 tier1/bitbuf.cpp
+10 −0 tier1/generichash.cpp
+1 −1 tier1/tier1.vcxproj
68 changes: 58 additions & 10 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@


extern CEntitySystem *g_pEntitySystem;
extern IVEngineServer2* g_pEngineServer2;
extern int g_targetPawn;
extern int g_targetController;

WeaponMapEntry_t WeaponMap[] = {
{"bizon", "weapon_bizon", 1400, 26},
Expand Down Expand Up @@ -226,6 +229,16 @@ CON_COMMAND_CHAT(toggledecals, "toggle world decals, if you're into having 10 fp
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have %s world decals", pZEPlayer->IsUsingStopDecals() ? "disabled" : "enabled");
}

CON_COMMAND_CHAT(myuid, "test")
{
if (!player)
return;

int iPlayer = player->GetPlayerSlot();

ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Your userid is %i, slot: %i, retrieved slot: %i", g_pEngineServer2->GetPlayerUserId(iPlayer).Get(), iPlayer, g_playerManager->GetSlotFromUserId(g_pEngineServer2->GetPlayerUserId(iPlayer).Get()));
}

CON_COMMAND_CHAT(ztele, "teleport to spawn")
{
if (!player)
Expand Down Expand Up @@ -268,16 +281,9 @@ CON_COMMAND_CHAT(ztele, "teleport to spawn")
{
//Convert handle into controller so we can use it again, and check it isn't invalid
CCSPlayerController* controller = (CCSPlayerController*)Z_CBaseEntity::EntityFromHandle(handle);
if (!controller)
{
ConMsg("Couldn't resolve entity handle\n");
return;
}
if (controller->m_iConnected() != PlayerConnectedState::PlayerConnected)
{
ConMsg("Controller is not connected\n");

if (!controller || controller->m_iConnected() != PlayerConnectedState::PlayerConnected)
return;
}

//Get pawn (again) so we can do shit
CBasePlayerPawn* pPawn2 = controller->m_hPawn();
Expand All @@ -303,7 +309,49 @@ CON_COMMAND_CHAT(ztele, "teleport to spawn")
});
}

#ifdef _DEBUG
// TODO: Make this a convar when it's possible to do so
static constexpr int g_iMaxHideDistance = 2000;

CON_COMMAND_CHAT(hide, "hides nearby teammates")
{
if (!player)
return;

if (args.ArgC() < 2)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !hide <distance> (0 to disable)");
return;
}

int distance = V_StringToInt32(args[1], -1);

if (distance > g_iMaxHideDistance || distance < 0)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You can only hide players between 0 and %i units away.", g_iMaxHideDistance);
return;
}

int iPlayer = player->GetPlayerSlot();

ZEPlayer *pZEPlayer = g_playerManager->GetPlayer(iPlayer);

// Something has to really go wrong for this to happen
if (!pZEPlayer)
{
Warning("%s Tried to access a null ZEPlayer!!\n", player->GetPlayerName());
return;
}

pZEPlayer->SetHideDistance(distance);

if (distance == 0)
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Hiding teammates is now disabled.", distance);
else
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Now hiding teammates within %i units.", distance);
}


#if _DEBUG
CON_COMMAND_CHAT(message, "message someone")
{
if (!player)
Expand Down
22 changes: 20 additions & 2 deletions src/cs2_sdk/entity/cbaseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "../schema.h"
#include "ccollisionproperty.h"
#include "mathlib/vector.h"
#include "baseentity.h"
#include "ehandle.h"
#include "../../gameconfig.h"

Expand Down Expand Up @@ -132,6 +131,7 @@ class Z_CBaseEntity : public CBaseEntity
SCHEMA_FIELD(MoveType_t, m_MoveType)
SCHEMA_FIELD(uint32, m_spawnflags)
SCHEMA_FIELD(uint32, m_fFlags)
SCHEMA_FIELD(LifeState_t, m_lifeState)

int entindex() { return m_pEntity->m_EHandle.GetEntryIndex(); }

Expand All @@ -140,7 +140,25 @@ class Z_CBaseEntity : public CBaseEntity

void Teleport(Vector *position, QAngle *angles, Vector *velocity) { static int offset = g_GameConfig->GetOffset("Teleport"); CALL_VIRTUAL(void, offset, this, position, angles, velocity); }

void CollisionRulesChanged() { static int offset = g_GameConfig->GetOffset("CollisionRulesChanged"); CALL_VIRTUAL(void, offset, this); }
void CollisionRulesChanged()
{
static int offset = g_GameConfig->GetOffset("CollisionRulesChanged");
CALL_VIRTUAL(void, offset, this);
}

bool IsPawn()
{
static int offset = g_GameConfig->GetOffset("IsEntityPawn");
CALL_VIRTUAL(bool, offset, this);
}

bool IsController()
{
static int offset = g_GameConfig->GetOffset("IsEntityController");
CALL_VIRTUAL(bool, offset, this);
}

bool IsAlive() { return m_lifeState == LifeState_t::LIFE_ALIVE; }

CHandle<CBaseEntity> GetHandle() { return m_pEntity->m_EHandle; }

Expand Down
3 changes: 1 addition & 2 deletions src/cs2_sdk/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "../common.h"
#include "interfaces/cs2_interfaces.h"
//#include <unordered_map>
#include "tier1/utlmap.h"
#include "tier0/memdbgon.h"
#include "plat.h"
Expand Down Expand Up @@ -72,7 +71,7 @@ static bool InitSchemaFieldsForClass(SchemaTableMap_t *tableMap, const char* cla
{
SchemaClassFieldData_t& field = pFields[i];

#ifndef CS2_SDK_ENABLE_SCHEMA_FIELD_OFFSET_LOGGING
#ifdef _DEBUG
Message("%s::%s found at -> 0x%X - %llx\n", className, field.m_name, field.m_offset, &field);
#endif

Expand Down
94 changes: 78 additions & 16 deletions src/cs2fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ SH_DECL_HOOK6(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, CPlayerSl
SH_DECL_HOOK8_void(IGameEventSystem, PostEventAbstract, SH_NOATTRIB, 0, CSplitScreenSlot, bool, int, const uint64*,
INetworkSerializable*, const void*, unsigned long, NetChannelBufType_t)
SH_DECL_HOOK3_void(INetworkServerService, StartupServer, SH_NOATTRIB, 0, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*);


// , bool, IRecipientFilter*, INetworkSerializable*, void* data, unsigned long nSize
SH_DECL_HOOK2_void( IServerGameClients, ClientCommand, SH_NOATTRIB, 0, CPlayerSlot, const CCommand & );
SH_DECL_HOOK6_void(ISource2GameEntities, CheckTransmit, SH_NOATTRIB, 0, CCheckTransmitInfo **, int, CBitVec<16384> &, const Entity2Networkable_t **, const uint16 *, int);
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, CPlayerSlot, const CCommand &);

CS2Fixes g_CS2Fixes;

Expand All @@ -122,7 +120,7 @@ ConVar sample_cvar("sample_cvar", "42", 0);

CON_COMMAND_F(sample_command, "Sample command", FCVAR_SPONLY | FCVAR_LINKED_CONCOMMAND)
{
META_CONPRINTF( "Sample command called by %d. Command: %s\n", context.GetPlayerSlot(), args.GetCommandString() );
Message( "Sample command called by %d. Command: %s\n", context.GetPlayerSlot(), args.GetCommandString() );
}

CON_COMMAND_F(toggle_logs, "Toggle printing most logs and warnings", FCVAR_SPONLY | FCVAR_LINKED_CONCOMMAND)
Expand All @@ -146,6 +144,7 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
GET_V_IFACE_CURRENT(GetEngineFactory, g_pEngineServer2, IVEngineServer2, SOURCE2ENGINETOSERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2Server, ISource2Server, SOURCE2SERVER_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2GameEntities, ISource2GameEntities, SOURCE2GAMEENTITIES_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2GameClients, IServerGameClients, SOURCE2GAMECLIENTS_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_pNetworkServerService, INetworkServerService, NETWORKSERVERSERVICE_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_gameEventSystem, IGameEventSystem, GAMEEVENTSYSTEM_INTERFACE_VERSION);
Expand All @@ -155,7 +154,7 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
// this needs to run in case of a late load
gpGlobals = GetGameGlobals();

META_CONPRINTF( "Starting plugin.\n" );
Message( "Starting plugin.\n" );

SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, g_pSource2Server, this, &CS2Fixes::Hook_GameFrame, true);
SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientActive, g_pSource2GameClients, this, &CS2Fixes::Hook_ClientActive, true);
Expand All @@ -167,6 +166,7 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, g_pSource2GameClients, this, &CS2Fixes::Hook_ClientCommand, false);
SH_ADD_HOOK_MEMFUNC(IGameEventSystem, PostEventAbstract, g_gameEventSystem, this, &CS2Fixes::Hook_PostEvent, false);
SH_ADD_HOOK_MEMFUNC(INetworkServerService, StartupServer, g_pNetworkServerService, this, &CS2Fixes::Hook_StartupServer, true);
SH_ADD_HOOK_MEMFUNC(ISource2GameEntities, CheckTransmit, g_pSource2GameEntities, this, &CS2Fixes::Hook_CheckTransmit, true);

META_CONPRINTF( "All hooks started!\n" );

Expand All @@ -190,6 +190,8 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
addresses::Initialize(g_GameConfig);
interfaces::Initialize();

Message( "All hooks started!\n" );

UnlockConVars();
UnlockConCommands();

Expand Down Expand Up @@ -217,6 +219,12 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
g_playerManager->TryAuthenticate();
});

// Check hide distance
new CTimer(0.5f, true, true, []()
{
g_playerManager->CheckHideDistances();
});

// Check for the expiration of infractions like mutes or gags
new CTimer(30.0f, true, true, []()
{
Expand Down Expand Up @@ -244,6 +252,7 @@ bool CS2Fixes::Unload(char *error, size_t maxlen)
SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, g_pSource2GameClients, this, &CS2Fixes::Hook_ClientCommand, false);
SH_REMOVE_HOOK_MEMFUNC(IGameEventSystem, PostEventAbstract, g_gameEventSystem, this, &CS2Fixes::Hook_PostEvent, false);
SH_REMOVE_HOOK_MEMFUNC(INetworkServerService, StartupServer, g_pNetworkServerService, this, &CS2Fixes::Hook_StartupServer, true);
SH_REMOVE_HOOK_MEMFUNC(ISource2GameEntities, CheckTransmit, g_pSource2GameEntities, this, &CS2Fixes::Hook_CheckTransmit, true);

ConVar_Unregister();

Expand Down Expand Up @@ -330,30 +339,34 @@ void CS2Fixes::AllPluginsLoaded()

void CS2Fixes::Hook_ClientActive( CPlayerSlot slot, bool bLoadGame, const char *pszName, uint64 xuid )
{
META_CONPRINTF( "Hook_ClientActive(%d, %d, \"%s\", %lli)\n", slot, bLoadGame, pszName, xuid );
Message( "Hook_ClientActive(%d, %d, \"%s\", %lli)\n", slot, bLoadGame, pszName, xuid );
}

void CS2Fixes::Hook_ClientCommand( CPlayerSlot slot, const CCommand &args )
{
META_CONPRINTF( "Hook_ClientCommand(%d, \"%s\")\n", slot, args.GetCommandString() );
#ifdef _DEBUG
Message( "Hook_ClientCommand(%d, \"%s\")\n", slot, args.GetCommandString() );
#endif
}

void CS2Fixes::Hook_ClientSettingsChanged( CPlayerSlot slot )
{
META_CONPRINTF( "Hook_ClientSettingsChanged(%d)\n", slot );
#ifdef _DEBUG
Message( "Hook_ClientSettingsChanged(%d)\n", slot );
#endif
}

void CS2Fixes::Hook_OnClientConnected( CPlayerSlot slot, const char *pszName, uint64 xuid, const char *pszNetworkID, const char *pszAddress, bool bFakePlayer )
{
META_CONPRINTF( "Hook_OnClientConnected(%d, \"%s\", %lli, \"%s\", \"%s\", %d)\n", slot, pszName, xuid, pszNetworkID, pszAddress, bFakePlayer );
Message( "Hook_OnClientConnected(%d, \"%s\", %lli, \"%s\", \"%s\", %d)\n", slot, pszName, xuid, pszNetworkID, pszAddress, bFakePlayer );

if(bFakePlayer)
g_playerManager->OnBotConnected(slot);
}

bool CS2Fixes::Hook_ClientConnect( CPlayerSlot slot, const char *pszName, uint64 xuid, const char *pszNetworkID, bool unk1, CBufferString *pRejectReason )
{
META_CONPRINTF( "Hook_ClientConnect(%d, \"%s\", %lli, \"%s\", %d, \"%s\")\n", slot, pszName, xuid, pszNetworkID, unk1, pRejectReason->ToGrowable()->Get() );
Message( "Hook_ClientConnect(%d, \"%s\", %lli, \"%s\", %d, \"%s\")\n", slot, pszName, xuid, pszNetworkID, unk1, pRejectReason->ToGrowable()->Get() );

g_playerManager->OnClientConnected(slot);

Expand All @@ -362,12 +375,12 @@ bool CS2Fixes::Hook_ClientConnect( CPlayerSlot slot, const char *pszName, uint64

void CS2Fixes::Hook_ClientPutInServer( CPlayerSlot slot, char const *pszName, int type, uint64 xuid )
{
META_CONPRINTF( "Hook_ClientPutInServer(%d, \"%s\", %d, %d, %lli)\n", slot, pszName, type, xuid );
Message( "Hook_ClientPutInServer(%d, \"%s\", %d, %d, %lli)\n", slot, pszName, type, xuid );
}

void CS2Fixes::Hook_ClientDisconnect( CPlayerSlot slot, int reason, const char *pszName, uint64 xuid, const char *pszNetworkID )
{
META_CONPRINTF( "Hook_ClientDisconnect(%d, %d, \"%s\", %lli, \"%s\")\n", slot, reason, pszName, xuid, pszNetworkID );
Message( "Hook_ClientDisconnect(%d, %d, \"%s\", %lli, \"%s\")\n", slot, reason, pszName, xuid, pszNetworkID );

g_playerManager->OnClientDisconnect(slot);
}
Expand Down Expand Up @@ -423,6 +436,55 @@ void CS2Fixes::Hook_GameFrame( bool simulating, bool bFirstTick, bool bLastTick
}
}

void CS2Fixes::Hook_CheckTransmit(CCheckTransmitInfo **ppInfoList, int infoCount, CBitVec<16384> &unionTransmitEdicts,
const Entity2Networkable_t **pNetworkables, const uint16 *pEntityIndicies, int nEntities)
{
if (!g_pEntitySystem)
return;

for (int i = 0; i < infoCount; i++)
{
auto &pInfo = ppInfoList[i];

// offset 560 happens to have a player index here,
// though this is probably part of the client class that contains the CCheckTransmitInfo
int iPlayerSlot = (int)*((uint8 *)pInfo + 560);

auto pPlayer = g_playerManager->GetPlayer(iPlayerSlot);

if (!pPlayer)
continue;

auto pSelfController = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pPlayer->GetPlayerSlot().Get() + 1));

if (!pSelfController)
continue;

auto pSelfPawn = pSelfController->GetPawn();

if (!pSelfPawn || !pSelfPawn->IsAlive())
continue;

for (int i = 1; i <= MAXPLAYERS; i++)
{
if (!pPlayer->ShouldBlockTransmit(i - 1))
continue;

auto pController = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)i);

if (!pController)
continue;

auto pPawn = pController->GetPawn();

if (!pPawn)
continue;

pInfo->m_pTransmitEntity->Clear(pPawn->entindex());
}
}
}

// Potentially might not work
void CS2Fixes::OnLevelInit( char const *pMapName,
char const *pMapEntities,
Expand All @@ -431,13 +493,13 @@ void CS2Fixes::OnLevelInit( char const *pMapName,
bool loadGame,
bool background )
{
META_CONPRINTF("OnLevelInit(%s)\n", pMapName);
Message("OnLevelInit(%s)\n", pMapName);
}

// Potentially might not work
void CS2Fixes::OnLevelShutdown()
{
META_CONPRINTF("OnLevelShutdown()\n");
Message("OnLevelShutdown()\n");
}

bool CS2Fixes::Pause(char *error, size_t maxlen)
Expand All @@ -452,7 +514,7 @@ bool CS2Fixes::Unpause(char *error, size_t maxlen)

const char *CS2Fixes::GetLicense()
{
return "MIT License";
return "GPL v3 License";
}

const char *CS2Fixes::GetVersion()
Expand Down
3 changes: 3 additions & 0 deletions src/cs2fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class CS2Fixes : public ISmmPlugin, public IMetamodListener
void Hook_OnClientConnected( CPlayerSlot slot, const char *pszName, uint64 xuid, const char *pszNetworkID, const char *pszAddress, bool bFakePlayer );
bool Hook_ClientConnect( CPlayerSlot slot, const char *pszName, uint64 xuid, const char *pszNetworkID, bool unk1, CBufferString *pRejectReason );
void Hook_ClientCommand( CPlayerSlot nSlot, const CCommand &_cmd );
void Hook_CheckTransmit(CCheckTransmitInfo **ppInfoList, int infoCount, CBitVec<16384> &unionTransmitEdicts,
const Entity2Networkable_t **pNetworkables, const uint16 *pEntityIndicies, int nEntities);

public:
const char *GetAuthor();
const char *GetName();
Expand Down
Loading