Files

202 lines
6.9 KiB
C++
Raw Permalink Normal View History

2023-10-02 17:31:02 +08:00
#include "native_sdk.h"
2023-10-04 06:01:28 +08:00
CBaseEntity* CHandle::GetBaseEntity() const {
2023-10-05 03:24:31 +08:00
CGameEntitySystem* pEntitySystem = global::EntitySystem;
2023-10-04 06:01:28 +08:00
if (!pEntitySystem) return nullptr;
2023-10-02 17:31:02 +08:00
return pEntitySystem->GetBaseEntity(GetEntryIndex());
}
CGameEntitySystem* CGameEntitySystem::GetInstance() {
return Offset::InterFaces::GameResourceServiceServer->GetGameEntitySystem();
}
2023-10-04 06:01:28 +08:00
auto CSchemaSystemTypeScope::FindDeclaredClass(const char* pClass)
-> SchemaClassInfoData_t* {
2023-10-02 17:31:02 +08:00
SchemaClassInfoData_t* rv = nullptr;
CALL_VIRTUAL(void, 2, this, &rv, pClass);
return rv;
}
2023-10-04 06:01:28 +08:00
auto CSchemaSystem::FindTypeScopeForModule(const char* module)
-> CSchemaSystemTypeScope* {
2023-10-02 17:31:02 +08:00
return CALL_VIRTUAL(CSchemaSystemTypeScope*, 13, this, module, nullptr);
}
2023-10-04 06:01:28 +08:00
auto CBaseEntity::IsBasePlayerController() -> bool {
2023-10-08 01:56:49 +08:00
SchemaClassInfoData_t* pClassInfo = Schema_DynamicBinding();
if (!pClassInfo) return false;
const char* className = pClassInfo->GetName();
if (!className) return false;
static constexpr auto C_CCSPlayerController = hash_32_fnv1a_const("CCSPlayerController");
static constexpr auto C_CCSPlayerPawn = hash_32_fnv1a_const("CCSPlayerPawn");
return hash_32_fnv1a_const(className) == C_CCSPlayerController || hash_32_fnv1a_const(className) == C_CCSPlayerPawn;
2023-10-02 17:31:02 +08:00
}
2023-10-04 06:01:28 +08:00
auto CBaseEntity::SpawnClientEntity() -> void { CALL_VIRTUAL(void, 19, this); }
auto CBasePlayer::ForceRespawn() -> void {
2023-10-02 17:31:02 +08:00
return CALL_VIRTUAL(void, 26, this);
}
2023-10-04 06:01:28 +08:00
auto CCSPlayerPawn::GetPlayerController() -> CCSPlayerController* {
2023-10-05 03:24:31 +08:00
CGameEntitySystem* pEntitySystem = global::EntitySystem;
2023-10-02 17:31:02 +08:00
if (!pEntitySystem) {
return nullptr;
}
2023-10-21 04:24:28 +08:00
for (int i = 0; i <= global::MaxPlayers; ++i) {
2023-10-02 17:31:02 +08:00
CBaseEntity* pEntity = pEntitySystem->GetBaseEntity(i);
if (!pEntity) continue;
if (pEntity->IsBasePlayerController()) {
const auto player = reinterpret_cast<CCSPlayerController*>(pEntity);
if (player->m_hPawn().Get() == this) {
2023-10-04 06:01:28 +08:00
// printf("Found Pawn Player: %d %s \n",
// player->GetRefEHandle().GetEntryIndex(),
// &player->m_iszPlayerName());
2023-10-02 17:31:02 +08:00
return player;
}
}
}
return nullptr;
}
2023-10-03 04:07:50 +08:00
using SchemaKeyValueMap_t = CUtlMap<uint32_t, SchemaKey>;
using SchemaTableMap_t = CUtlMap<uint32_t, SchemaKeyValueMap_t*>;
2023-10-01 02:28:13 +08:00
2023-10-04 06:01:28 +08:00
static bool IsFieldNetworked(SchemaClassFieldData_t& field) {
for (int i = 0; i < field.m_metadata_size; i++) {
2023-10-03 04:07:50 +08:00
static auto networkEnabled = hash_32_fnv1a_const("MNetworkEnable");
if (networkEnabled == hash_32_fnv1a_const(field.m_metadata[i].m_name))
return true;
}
return false;
}
2023-10-04 06:01:28 +08:00
static bool InitSchemaFieldsForClass(SchemaTableMap_t* tableMap,
const char* className, uint32_t classKey) {
CSchemaSystemTypeScope* pType =
Offset::InterFaces::SchemaSystem->FindTypeScopeForModule("server.dll");
2023-10-03 04:07:50 +08:00
2023-10-04 06:01:28 +08:00
if (!pType) return false;
2023-10-01 02:28:13 +08:00
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className);
2023-10-03 04:07:50 +08:00
2023-10-04 06:01:28 +08:00
if (!pClassInfo) {
SchemaKeyValueMap_t* map =
new SchemaKeyValueMap_t(0, 0, DefLessFunc(uint32_t));
2023-10-03 04:07:50 +08:00
tableMap->Insert(classKey, map);
2023-10-01 02:28:13 +08:00
LOG("InitSchemaFieldsForClass(): '%s' was not found!\n", className);
return false;
}
short fieldsSize = pClassInfo->GetFieldsSize();
SchemaClassFieldData_t* pFields = pClassInfo->GetFields();
2023-10-04 06:01:28 +08:00
SchemaKeyValueMap_t* keyValueMap =
new SchemaKeyValueMap_t(0, 0, DefLessFunc(uint32_t));
2023-10-03 04:07:50 +08:00
keyValueMap->EnsureCapacity(fieldsSize);
tableMap->Insert(classKey, keyValueMap);
2023-10-01 02:28:13 +08:00
2023-10-04 06:01:28 +08:00
for (int i = 0; i < fieldsSize; ++i) {
2023-10-01 02:28:13 +08:00
SchemaClassFieldData_t& field = pFields[i];
2023-10-09 00:18:43 +08:00
LOG("%s::%s found at -> 0x%X - %llx\n", className, field.m_name, field.m_offset, &field);
2023-10-03 04:07:50 +08:00
2023-10-04 06:01:28 +08:00
keyValueMap->Insert(hash_32_fnv1a_const(field.m_name),
{field.m_offset, IsFieldNetworked(field)});
2023-10-01 02:28:13 +08:00
}
return true;
}
2023-10-04 06:01:28 +08:00
int16_t schema::FindChainOffset(const char* className) {
CSchemaSystemTypeScope* pType =
Offset::InterFaces::SchemaSystem->FindTypeScopeForModule("server.dll");
2023-10-03 04:07:50 +08:00
2023-10-04 06:01:28 +08:00
if (!pType) return false;
2023-10-01 02:28:13 +08:00
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className);
2023-10-04 06:01:28 +08:00
do {
2023-10-01 02:28:13 +08:00
SchemaClassFieldData_t* pFields = pClassInfo->GetFields();
short fieldsSize = pClassInfo->GetFieldsSize();
2023-10-04 06:01:28 +08:00
for (int i = 0; i < fieldsSize; ++i) {
2023-10-01 02:28:13 +08:00
SchemaClassFieldData_t& field = pFields[i];
2023-10-04 06:01:28 +08:00
if (strcmp(field.m_name, "__m_pChainEntity") == 0) {
2023-10-01 02:28:13 +08:00
return field.m_offset;
}
}
} while ((pClassInfo = pClassInfo->GetParent()) != nullptr);
return 0;
}
2023-10-04 06:01:28 +08:00
SchemaKey schema::GetOffset(const char* className, uint32_t classKey,
const char* memberName, uint32_t memberKey) {
2023-10-03 04:07:50 +08:00
static SchemaTableMap_t schemaTableMap(0, 0, DefLessFunc(uint32_t));
int16_t tableMapIndex = schemaTableMap.Find(classKey);
2023-10-04 06:01:28 +08:00
if (!schemaTableMap.IsValidIndex(tableMapIndex)) {
2023-10-03 04:07:50 +08:00
if (InitSchemaFieldsForClass(&schemaTableMap, className, classKey))
2023-10-01 02:28:13 +08:00
return GetOffset(className, classKey, memberName, memberKey);
2023-10-03 04:07:50 +08:00
2023-10-04 06:01:28 +08:00
return {0, 0};
2023-10-01 02:28:13 +08:00
}
2023-10-03 04:07:50 +08:00
SchemaKeyValueMap_t* tableMap = schemaTableMap[tableMapIndex];
int16_t memberIndex = tableMap->Find(memberKey);
2023-10-04 06:01:28 +08:00
if (!tableMap->IsValidIndex(memberIndex)) {
LOG("schema::GetOffset(): '%s' was not found in '%s'!\n", memberName,
className);
return {0, 0};
2023-10-01 02:28:13 +08:00
}
2023-10-03 04:07:50 +08:00
return tableMap->Element(memberIndex);
}
bool CEconItemDefinition::IsWeapon() {
// Every gun supports at least 4 stickers.
return GetStickersSupportedCount() >= 4;
}
bool CEconItemDefinition::IsKnife(bool excludeDefault) {
static constexpr auto CSGO_Type_Knife =
hash_32_fnv1a_const("#CSGO_Type_Knife");
if (hash_32_fnv1a_const(m_pszItemTypeName) != CSGO_Type_Knife) return false;
return excludeDefault ? m_nDefIndex >= 500 : true;
}
bool CEconItemDefinition::IsGlove(bool excludeDefault) {
static constexpr auto Type_Hands = hash_32_fnv1a_const("#Type_Hands");
if (hash_32_fnv1a_const(m_pszItemTypeName) != Type_Hands) return false;
const bool defaultGlove = m_nDefIndex == 5028 || m_nDefIndex == 5029;
return excludeDefault ? !defaultGlove : true;
}
2023-10-04 06:01:28 +08:00
auto CLocalize::FindSafe(const char* tokenName) -> const char* {
2023-10-03 04:07:50 +08:00
return CALL_VIRTUAL(const char*, 17, this, tokenName);
}
2023-10-04 06:01:28 +08:00
auto GetGameGlobals() -> CGlobalVars* {
INetworkGameServer* server =
Offset::InterFaces::INetworkServerServiceInteFace->GetIGameServer();
2023-10-03 04:07:50 +08:00
2023-10-04 06:01:28 +08:00
if (!server) return nullptr;
2023-10-03 04:07:50 +08:00
2023-10-04 06:01:28 +08:00
return Offset::InterFaces::INetworkServerServiceInteFace->GetIGameServer()
->GetGlobals();
2023-10-03 04:07:50 +08:00
}
2023-10-04 06:01:28 +08:00
auto SetStateChanged(Z_CBaseEntity* pEntity, int offset) -> void {
Offset::FnStateChanged(pEntity->m_NetworkTransmitComponent(), pEntity,
offset, -1, -1);
// auto vars = GetGameGlobals();
auto vars = global::GlobalVars;
2023-10-03 04:07:50 +08:00
2023-10-04 06:01:28 +08:00
if (vars) pEntity->m_lastNetworkChange(vars->curtime);
2023-10-03 04:07:50 +08:00
pEntity->m_isSteadyState(0);
};