Skip to content
Open
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
1 change: 1 addition & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ for sdk_target in MMSPlugin.sdk_targets:
'src/utils/weapon.cpp',
'src/utils/hud_manager.cpp',
'src/utils/utils.cpp',
'src/utils/script_function.cpp',
'src/cs2_sdk/entity/services.cpp',
'src/cs2_sdk/schema.cpp',
'src/ctimer.cpp',
Expand Down
2 changes: 2 additions & 0 deletions CS2Fixes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<ClCompile Include="src\utils\weapon.cpp" />
<ClCompile Include="src\utils\hud_manager.cpp" />
<ClCompile Include="src\utils\utils.cpp" />
<ClCompile Include="src\utils\script_function.cpp" />
<ClCompile Include="src\cs2_sdk\entity\services.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -294,6 +295,7 @@
<ClInclude Include="src\utils\entity.h" />
<ClInclude Include="src\utils\module.h" />
<ClInclude Include="src\utils\plat.h" />
<ClInclude Include="src\utils\script_function.h" />
<ClInclude Include="src\utils\virtual.h" />
<ClInclude Include="src\cs2_sdk\netmessages.h" />
<ClInclude Include="src\utils\weapon.h" />
Expand Down
6 changes: 6 additions & 0 deletions CS2Fixes.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@
<ClCompile Include="src\utils\utils.cpp">
<Filter>Source Files\utils</Filter>
</ClCompile>
<ClCompile Include="src\utils\script_function.cpp">
<Filter>Source Files\utils</Filter>
</ClCompile>
<ClCompile Include="src\cs2_sdk\entity\services.cpp">
<Filter>Source Files\cs2_sdk\entity</Filter>
</ClCompile>
Expand Down Expand Up @@ -217,6 +220,9 @@
<ClInclude Include="src\utils\virtual.h">
<Filter>Header Files\utils</Filter>
</ClInclude>
<ClInclude Include="src\utils\script_function.h">
<Filter>Header Files\utils</Filter>
</ClInclude>
<ClInclude Include="src\cs2_sdk\schema.h">
<Filter>Header Files\cs2_sdk</Filter>
</ClInclude>
Expand Down
47 changes: 0 additions & 47 deletions gamedata/cs2fixes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@
"windows": "40 55 53 56 57 41 54 48 8D 6C 24 ? 48 81 EC ? ? ? ? 4D 8B E0",
"linux": "55 66 0F EF C0 48 89 E5 41 57 41 56 41 55 49 89 FD 31 FF"
},
// Should be xref'd right above "flGravity", takes a float arg
"CBaseEntity::SetGravityScale":
{
"library": "server",
"windows": "48 89 5C 24 ? 57 48 83 EC ? F3 0F 10 81 ? ? ? ? 48 8B F9 0F 29 74 24 ? 0F 28 F1 0F 2E C6 7A ? 74 ? BA ? ? ? ? 41 B8 ? ? ? ? 48 81 C1 ? ? ? ? E8 ? ? ? ? 48 8B CF F3 0F 11 B7 ? ? ? ? E8 ? ? ? ? 48 8B 5C 24 ? 0F 28 74 24 ? 48 83 C4 ? 5F C3 CC CC CC CC CC 48 89 5C 24",
"linux": "55 48 89 E5 41 57 41 56 41 55 41 54 53 48 89 FB 48 81 EC ? ? ? ? 0F 2E 87 ? ? ? ? 7A ? 75 ? 48 81 C4 ? ? ? ? 5B 41 5C 41 5D 41 5E 41 5F 5D C3 0F 1F 40 ? 31 C9 BE ? ? ? ? 66 0F EF C9 F3 0F 11 85 ? ? ? ? 48 8D BD ? ? ? ? 48 C7 85 ? ? ? ? ? ? ? ? 0F 29 8D ? ? ? ? 4C 8D A5 ? ? ? ? 48 C7 85 ? ? ? ? ? ? ? ? 48 C7 85 ? ? ? ? ? ? ? ? 48 C7 85 ? ? ? ? ? ? ? ? 48 C7 85 ? ? ? ? ? ? ? ? C7 85 ? ? ? ? ? ? ? ? 66 89 8D ? ? ? ? E8 ? ? ? ? 48 8B 85 ? ? ? ? 48 8D 15 ? ? ? ? 83 85 ? ? ? ? ? F3 0F 10 85 ? ? ? ? C7 00 ? ? ? ? 48 8B 03 48 8B 80 ? ? ? ? 48 39 D0 0F 85 ? ? ? ? 8B 95 ? ? ? ? 4C 8D 7B ? 85 D2 0F 85 ? ? ? ? 80 BB ? ? ? ? ? 75"
},
// "Game System %s is defined twice!\n"
// Note that this signature points to the instruction with sm_pFirst which is the first qword referenced in the function.
"IGameSystem_InitAllSystems_pFirst":
Expand Down Expand Up @@ -199,30 +192,13 @@
"windows": "48 89 5C 24 10 57 48 83 EC 30 48 8B DA 48 8B F9 48 85 C9",
"linux": "48 85 FF 74 ? 55 48 89 E5 41 55 41 54 49 89 FC"
},
// Look for "SetEntityName", that will be the vscript binding definition
// Scroll a bit down and you'll find something like this (note the offset): *(_QWORD *)(v453 + 64) = sub_1807B0350;
// that function is just a jump to the one we want
"CEntityIdentity_SetEntityName":
{
"library": "server",
"windows": "48 89 5C 24 10 57 48 83 EC 20 48 8B D9 4C 8B C2",
"linux": "55 48 89 F2 48 89 E5 41 55 41 54 53"
},
// "Error - cannot add bots after game is over."
"BotNavIgnore":
{
"library": "server",
"windows": "0F 84 ? ? ? ? 80 B8 ? ? ? ? 00 0F 84 ? ? ? ? 80 3D ? ? ? ? 00 74 15",
"linux": "0F 84 ? ? ? ? 44 0F B6 B8 ? ? ? ? 45 84 FF 0F 84"
},
// next to "soundname", in windows it's the last referenced sub while in linux it's right after
// this is a vscript binding though so it may be removed in the future?
"CBaseEntity_EmitSoundParams":
{
"library": "server",
"windows": "48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 55 48 8B EC 48 81 EC ? ? ? ? 33 C0",
"linux": "48 B8 ? ? ? ? ? ? ? ? 55 0F 28 D0"
},
// "ParticleEffect", found in a function with 9 arguments
"DispatchParticleEffect":
{
Expand Down Expand Up @@ -401,12 +377,6 @@
"windows": 53,
"linux": 52
},
// String: "%s<%i><%s><%s>" ChangeTeam() CTMDBG..."
"CCSPlayerController_ChangeTeam":
{
"windows": 103,
"linux": 102
},
"CBaseEntity::Use":
{
"windows": 145,
Expand All @@ -427,23 +397,6 @@
"windows": 150,
"linux": 149
},
"Teleport":
{
"windows": 163,
"linux": 162
},
// For these two, look for the names, you'll find vscript bindings
// Scroll down to where the var + 64 gets set to a function, that calls the offset we want
"IsPlayerPawn":
{
"windows": 169,
"linux": 168
},
"IsPlayerController":
{
"windows": 170,
"linux": 169
},
"CollisionRulesChanged":
{
"windows": 186,
Expand Down
40 changes: 37 additions & 3 deletions src/addresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "gameconfig.h"
#include "utils/module.h"

#include "entityinstance.h"
#include "tier1/strtools.h"
#include "vscript/ivscript.h"
#include "tier0/memdbgon.h"

#define RESOLVE_SIG(gameConfig, name, variable) \
Expand All @@ -29,6 +32,14 @@
return false; \
Message("Found %s at 0x%p\n", name, variable);

#define RESOLVE_SF(scriptDesc, funcName, variable) \
if (!variable.Initialize(GetScriptFunction(scriptDesc, funcName))) \
return false; \
if (variable.IsVirtual()) \
Message("Found %s::%s at vtable index %i\n", scriptDesc->m_pszClassname, funcName, variable.GetOffset()); \
else \
Message("Found %s::%s at 0x%p\n", scriptDesc->m_pszClassname, funcName, variable.GetPtr());

bool addresses::Initialize(CGameConfig* g_GameConfig)
{
modules::engine = new CModule(ROOTBIN, "engine2");
Expand All @@ -51,7 +62,6 @@ bool addresses::Initialize(CGameConfig* g_GameConfig)
#endif

RESOLVE_SIG(g_GameConfig, "SetGroundEntity", addresses::SetGroundEntity);
RESOLVE_SIG(g_GameConfig, "CBaseEntity::SetGravityScale", addresses::SetGravityScale);
RESOLVE_SIG(g_GameConfig, "CCSPlayerController_SwitchTeam", addresses::CCSPlayerController_SwitchTeam);
RESOLVE_SIG(g_GameConfig, "CBasePlayerController_SetPawn", addresses::CBasePlayerController_SetPawn);
RESOLVE_SIG(g_GameConfig, "CBaseModelEntity_SetModel", addresses::CBaseModelEntity_SetModel);
Expand All @@ -62,8 +72,6 @@ bool addresses::Initialize(CGameConfig* g_GameConfig)
RESOLVE_SIG(g_GameConfig, "CGameRules_TerminateRound", addresses::CGameRules_TerminateRound);
RESOLVE_SIG(g_GameConfig, "CreateEntityByName", addresses::CreateEntityByName);
RESOLVE_SIG(g_GameConfig, "DispatchSpawn", addresses::DispatchSpawn);
RESOLVE_SIG(g_GameConfig, "CEntityIdentity_SetEntityName", addresses::CEntityIdentity_SetEntityName);
RESOLVE_SIG(g_GameConfig, "CBaseEntity_EmitSoundParams", addresses::CBaseEntity_EmitSoundParams);
RESOLVE_SIG(g_GameConfig, "DispatchParticleEffect", addresses::DispatchParticleEffect);
RESOLVE_SIG(g_GameConfig, "CBaseEntity_EmitSoundFilter", addresses::CBaseEntity_EmitSoundFilter);
RESOLVE_SIG(g_GameConfig, "CBaseEntity_SetMoveType", addresses::CBaseEntity_SetMoveType);
Expand Down Expand Up @@ -101,3 +109,29 @@ bool addresses::InitializeBanMap(CGameConfig* g_GameConfig)
Message("Found %s at 0x%p\n", "CCSGameRules__sm_mapGcBanInformation", addresses::sm_mapGcBanInformation);
return true;
}

bool addresses::InitializeVScriptFunctions()
{
void* pCBaseEntityVTable = modules::server->FindVirtualTable("CBaseEntity");
if (!pCBaseEntityVTable)
{
Message("Failed to find CBaseEntity vtable\n");
return false;
}

// GetScriptDesc ignores this, so the vtable pointer is sufficient here.
ScriptClassDesc_t* pCBaseEntityScriptDesc = reinterpret_cast<ScriptClassDesc_t*>(reinterpret_cast<CEntityInstance*>(&pCBaseEntityVTable)->GetScriptDesc());

RESOLVE_SF(pCBaseEntityScriptDesc, "SetGravity", SetGravityScale);
RESOLVE_SF(pCBaseEntityScriptDesc, "SetEntityName", ScriptSetEntityName);
RESOLVE_SF(pCBaseEntityScriptDesc, "EmitSoundParams", ScriptEmitSoundParams);
RESOLVE_SF(pCBaseEntityScriptDesc, "SetTeam", ChangeTeam);
RESOLVE_SF(pCBaseEntityScriptDesc, "IsPlayerPawn", IsPlayerPawn);
RESOLVE_SF(pCBaseEntityScriptDesc, "IsPlayerController", IsPlayerController);

if (!Teleport.Initialize(GetScriptFunction(pCBaseEntityScriptDesc, "SetOrigin")))
return false;
Message("Found %s::Teleport through SetOrigin at vtable index %i\n", pCBaseEntityScriptDesc->m_pszClassname, Teleport.GetOffset());

return true;
}
15 changes: 11 additions & 4 deletions src/addresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "platform.h"
#include "stdint.h"
#include "utils/module.h"
#include "utils/script_function.h"
#include "utlstring.h"
#include "variant.h"

Expand Down Expand Up @@ -74,11 +75,11 @@ namespace addresses
{
bool Initialize(CGameConfig* g_GameConfig);
bool InitializeBanMap(CGameConfig* g_GameConfig);
bool InitializeVScriptFunctions();

inline CUtlMap<uint32, CGcBanInformation_t, uint32>* sm_mapGcBanInformation;

inline void(FASTCALL* SetGroundEntity)(CBaseEntity* ent, CBaseEntity* ground, CBaseEntity* unk3);
inline void(FASTCALL* SetGravityScale)(CBaseEntity*, float);
inline void(FASTCALL* CCSPlayerController_SwitchTeam)(CCSPlayerController* pController, uint32 team);
inline void(FASTCALL* CBasePlayerController_SetPawn)(CBasePlayerController* pController, CCSPlayerPawn* pPawn, bool a3, bool a4, bool a5, bool a6);
inline void(FASTCALL* CBaseModelEntity_SetModel)(CBaseModelEntity* pModel, const char* pszModel);
Expand All @@ -97,8 +98,6 @@ namespace addresses
inline void(FASTCALL* CGameRules_TerminateRound)(CGameRules* pGameRules, float delay, unsigned int reason, int64 a4);
inline CBaseEntity*(FASTCALL* CreateEntityByName)(const char* className, int iForceEdictIndex);
inline void(FASTCALL* DispatchSpawn)(CBaseEntity* pEntity, CEntityKeyValues* pEntityKeyValues);
inline void(FASTCALL* CEntityIdentity_SetEntityName)(CEntityIdentity* pEntity, const char* pName);
inline void(FASTCALL* CBaseEntity_EmitSoundParams)(CBaseEntity* pEntity, const char* pszSound, int nPitch, float flVolume, float flDelay);
inline int(FASTCALL* DispatchParticleEffect)(const char* pszParticleName, int iAttachType, CBaseEntity* pEntity,
char iAttachmentPoint, CUtlSymbolLarge iAttachmentName, bool bResetAllParticlesOnEntity, int nSplitScreenPlayerSlot, IRecipientFilter* a7, byte* a8);
inline StartSoundEventInfo(FASTCALL* CBaseEntity_EmitSoundFilter)(IRecipientFilter& filter, CEntityIndex ent, const EmitSound_t& params);
Expand All @@ -108,4 +107,12 @@ namespace addresses
inline void(FASTCALL* CCSPlayer_WeaponServices_EquipWeapon)(CCSPlayer_WeaponServices* pWeaponServices, CBasePlayerWeapon* pPlayerWeapon);
inline void(FASTCALL* GetSpawnGroups)(CSpawnGroupMgrGameSystem* pSpawnGroupMgr, CUtlVector<SpawnGroupHandle_t>* pList);
inline void(FASTCALL* CBasePlayerPawn_SnapViewAngles)(CBasePlayerPawn* pPawn, QAngle* pAngles);
} // namespace addresses

inline CVScriptFunction<void, CBaseEntity, float> SetGravityScale;
inline CVScriptFunction<void, CBaseEntity, const char*> ScriptSetEntityName;
inline CVScriptFunction<void, CBaseEntity, const char*, int, float, float> ScriptEmitSoundParams;
inline CVScriptFunction<void, CBaseEntity, int> ChangeTeam;
inline CVScriptFunction<bool, CBaseEntity> IsPlayerPawn;
inline CVScriptFunction<bool, CBaseEntity> IsPlayerController;
inline CVScriptTeleportFunction Teleport;
} // namespace addresses
13 changes: 5 additions & 8 deletions src/cs2_sdk/entity/cbaseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class CBaseEntity : public CEntityInstance

void SetName(const char* pName)
{
addresses::CEntityIdentity_SetEntityName(m_pEntity, pName);
addresses::ScriptSetEntityName(this, pName);
}

void TakeDamage(CTakeDamageInfo& info)
Expand All @@ -175,8 +175,7 @@ class CBaseEntity : public CEntityInstance

void Teleport(const Vector* pPosition, const QAngle* pAngles, const Vector* pVelocity)
{
static int offset = g_GameConfig->GetOffset("Teleport");
CALL_VIRTUAL(void, offset, this, pPosition, pAngles, pVelocity);
addresses::Teleport(this, pPosition, pAngles, pVelocity);
}

void SetCollisionGroup(StandardCollisionGroups_t nCollisionGroup)
Expand All @@ -196,14 +195,12 @@ class CBaseEntity : public CEntityInstance

bool IsPawn()
{
static int offset = g_GameConfig->GetOffset("IsPlayerPawn");
return CALL_VIRTUAL(bool, offset, this);
return addresses::IsPlayerPawn(this);
}

bool IsController()
{
static int offset = g_GameConfig->GetOffset("IsPlayerController");
return CALL_VIRTUAL(bool, offset, this);
return addresses::IsPlayerController(this);
}

void AcceptInput(const char* pInputName, variant_t value = variant_t(""), CEntityInstance* pActivator = nullptr, CEntityInstance* pCaller = nullptr)
Expand All @@ -226,7 +223,7 @@ class CBaseEntity : public CEntityInstance
// Emit a sound event
void EmitSound(const char* pszSound, int nPitch = 100, float flVolume = 1.0, float flDelay = 0.0)
{
addresses::CBaseEntity_EmitSoundParams(this, pszSound, nPitch, flVolume, flDelay);
addresses::ScriptEmitSoundParams(this, pszSound, nPitch, flVolume, flDelay);
}

StartSoundEventInfo EmitSoundFilter(IRecipientFilter& filter, const char* pszSound, float flVolume = 1.0, float flPitch = 1.0)
Expand Down
3 changes: 1 addition & 2 deletions src/cs2_sdk/entity/ccsplayercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ class CCSPlayerController : public CBasePlayerController

void ChangeTeam(int iTeam)
{
static int offset = g_GameConfig->GetOffset("CCSPlayerController_ChangeTeam");
CALL_VIRTUAL(void, offset, this, iTeam);
addresses::ChangeTeam(this, iTeam);
}

void SwitchTeam(int iTeam)
Expand Down
5 changes: 4 additions & 1 deletion src/cs2fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool
if (!addresses::Initialize(g_GameConfig))
bRequiredInitLoaded = false;

if (!addresses::InitializeVScriptFunctions())
bRequiredInitLoaded = false;

if (!InitPatches(g_GameConfig))
bRequiredInitLoaded = false;

Expand Down Expand Up @@ -279,7 +282,7 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool
SH_MANUALHOOK_RECONFIGURE(OnTakeDamage_Alive, offset, 0, 0);
g_iOnTakeDamageAliveId = SH_ADD_MANUALDVPHOOK(OnTakeDamage_Alive, pCCSPlayerPawnVTable, SH_MEMBER(this, &CS2Fixes::Hook_OnTakeDamage_Alive), false);

offset = g_GameConfig->GetOffset("Teleport");
offset = addresses::Teleport.GetOffset();
if (offset == -1)
{
snprintf(error, maxlen, "Failed to find Teleport\n");
Expand Down
Loading
Loading