增加pawn名字

This commit is contained in:
Huoji's
2023-10-02 05:03:37 +08:00
parent 1bae80e38d
commit 7d24c5a405
16 changed files with 167 additions and 127 deletions

View File

@@ -214,6 +214,7 @@
<ClCompile Include="MinHook\src\trampoline.c" />
<ClCompile Include="native_sdk\cgameentitysystem.cpp" />
<ClCompile Include="native_sdk\cschemasystem.cpp" />
<ClCompile Include="native_sdk\entity\cbaseentity.cpp" />
<ClCompile Include="native_sdk\handle\handle.cpp" />
<ClCompile Include="offset.cpp" />
<ClCompile Include="pch.cpp">

View File

@@ -287,6 +287,9 @@
<ClCompile Include="player_manager.cpp">
<Filter>源文件\players</Filter>
</ClCompile>
<ClCompile Include="native_sdk\entity\cbaseentity.cpp">
<Filter>源文件\native_sdk\entity</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />

View File

@@ -4,27 +4,30 @@
#include "player_manager.h"
namespace events {
auto OnPlayerDeathEvent(IGameEvent* event) -> void {
UnkGameEventStruct_t userIdNameParams{ "userid" };
UnkGameEventStruct_t attackerNameParams{ "attacker" };
auto OnPlayerDeathEvent(IGameEvent* event) -> void {
UnkGameEventStruct_t userIdNameParams{"userid"};
UnkGameEventStruct_t attackerNameParams{"attacker"};
const auto victim = reinterpret_cast<CCSPlayerController*>(event->GetPlayerPawn(&userIdNameParams));
const auto attacker = reinterpret_cast<CCSPlayerController*>(event->GetPlayerPawn(&attackerNameParams));
const auto victim = reinterpret_cast<CCSPlayerPawn*>(
event->GetPlayerPawn(&userIdNameParams));
const auto attacker = reinterpret_cast<CCSPlayerPawn*>(
event->GetPlayerPawn(&attackerNameParams));
auto victimName = std::string(PlayerManager::GetPlayerNameByPlayerSlot(victim->GetRefEHandle().GetPlayerSlot()));
auto attackerName = std::string(PlayerManager::GetPlayerNameByPlayerSlot(attacker->GetRefEHandle().GetPlayerSlot()));
printf("player %s killed %s\n", victimName.c_str(), attackerName.c_str());
}
auto OnPlayerChat(IGameEvent* event) -> void
{
UnkGameEventStruct_t userIdNameParams{ "userid" };
const auto chater = reinterpret_cast<CCSPlayerController*>(event->GetPlayer(&userIdNameParams));
const auto text = event->GetString("text");
const auto chaterName = chater->m_iszPlayerName();
LOG("player: %s say: %s \n", chaterName, text);
CGameEntitySystem* pEntitySystem = CGameEntitySystem::GetInstance();
if (!pEntitySystem) return;
for (int i = 1; i <= 64; ++i) {
CBaseEntity* pEntity = pEntitySystem->GetBaseEntity(i);
if (!pEntity) continue;
if (pEntity->IsBasePlayerController()) {
const auto player = reinterpret_cast<CCSPlayerController*>(pEntity);
if (player->m_hPawn().Get() == victim) {
printf("Found Pawn Player: %d %s \n", player->GetRefEHandle().GetEntryIndex(),&player->m_iszPlayerName());
break;
}
}
}
//printf("player[%p] %s kill[%p] %llu\n", attacker, &attacker->m_iszPlayerName(), victim, &victim->m_steamID());
}
auto OnPlayerChat(IGameEvent* event) -> void {}
} // namespace events

View File

@@ -1,4 +1,5 @@
#include "global.h"
namespace global {
bool Exit;
int MaxPlayers;
}

View File

@@ -2,4 +2,5 @@
#include "pch.h"
namespace global {
extern bool Exit;
extern int MaxPlayers;
}

View File

@@ -14,7 +14,10 @@ VMTHook* VMT_IServerGameClient;
void __fastcall hook_ClientDisconnect(void* rcx, CPlayerSlot slot, int reason,
const char* pszName, uint64_t xuid,
const char* pszNetworkID) {
PlayerManager::RemovePlayerNameFromPlayerNameList(slot, pszName);
if (pszNetworkID != NULL && *pszNetworkID == '[') {
ExtendPlayerManager::RemovePlayerSlotBySteamId(
ExtendPlayerManager::SteamIDStringToUInt64(pszNetworkID));
}
return original_OnClientDisconnect(rcx, slot, reason, pszName, xuid,
pszNetworkID);
}
@@ -24,10 +27,10 @@ void __fastcall hook_OnClientConnected(void* rcx, CPlayerSlot slot,
const char* pszAddress,
bool bFakePlayer) {
if (bFakePlayer == false) {
LOG("%s %d %s %s %s %d", __FUNCTION__, slot.Get(), pszName, pszNetworkID,
pszAddress, bFakePlayer);
ExtendPlayerManager::AddSteamIdToPlayerSteamIdWithNameTable(
ExtendPlayerManager::SteamIDStringToUInt64(pszNetworkID),
slot.Get());
}
PlayerManager::AddPlayerNameToPlayerNameList(slot, pszName);
return original_OnClientConnected(rcx, slot, pszName, xuid, pszNetworkID,
pszAddress, bFakePlayer);
@@ -43,9 +46,8 @@ void __fastcall hook_Host_Say(void* pEntity, void* args, bool teamonly,
break;
}
auto message = std::string(theArgs->GetCommandString());
auto playerName = PlayerManager::GetPlayerNameByPlayerSlot(
theEntity->GetRefEHandle().GetPlayerSlot());
printf("player %s : %s \n", playerName.c_str(), message.c_str());
printf("player[%d][%p] %s : %s \n", theEntity->GetRefEHandle().GetEntryIndex(),theEntity, &theEntity->m_iszPlayerName(),
message.c_str());
} while (false);
/*
if (*pMessage == '!' || *pMessage == '/')

View File

@@ -0,0 +1,4 @@
#include "cbaseentity.h"
bool CBaseEntity::IsBasePlayerController() {
return CALL_VIRTUAL(bool, 144, this);
}

View File

@@ -6,38 +6,37 @@
#include "../cgameentitysystem.h"
class CEntityIdentity;
class CEntityInstance {
public:
DECLARE_CLASS(CEntityInstance);
public:
DECLARE_CLASS(CEntityInstance);
auto Schema_DynamicBinding() {
SchemaClassInfoData_t* rv = nullptr;
CALL_VIRTUAL(void, 34, this, &rv);
return rv;
}
auto Schema_DynamicBinding() {
SchemaClassInfoData_t* rv = nullptr;
CALL_VIRTUAL(void, 34, this, &rv);
return rv;
}
auto GetRefEHandle() {
char* pIdentity = (char*)m_pEntity();
auto v3 = *(uint32_t*)(pIdentity + 16);
auto v4 = ENT_ENTRY_MASK;
auto v5 = ((v3 >> 15) - (*(uint32_t*)(pIdentity + 48) & 1)) << 15;
if (v3 != -1) {
v4 = *(uint32_t*)(pIdentity + 16) & ENT_ENTRY_MASK;
}
auto GetRefEHandle() {
char* pIdentity = (char*)m_pEntity();
auto v3 = *(uint32_t*)(pIdentity + 16);
auto v4 = ENT_ENTRY_MASK;
auto v5 = ((v3 >> 15) - (*(uint32_t*)(pIdentity + 48) & 1)) << 15;
if (v3 != -1) {
v4 = *(uint32_t*)(pIdentity + 16) & ENT_ENTRY_MASK;
}
return CHandle(v4 | v5);
}
SCHEMA_FIELD(CEntityIdentity*, m_pEntity);
SCHEMA_FIELD(const char*, m_designerName);
return CHandle(v4 | v5);
}
SCHEMA_FIELD(CEntityIdentity*, m_pEntity);
SCHEMA_FIELD(const char*, m_designerName);
};
class CBaseEntity : public CEntityInstance
{
public:
DECLARE_CLASS(CBaseEntity);
class CBaseEntity : public CEntityInstance {
public:
DECLARE_CLASS(CBaseEntity);
SCHEMA_FIELD(int, m_iHealth)
//SCHEMA_FIELD(Vector, m_vecBaseVelocity)
SCHEMA_FIELD(CCollisionProperty*, m_pCollision)
SCHEMA_FIELD(int, m_iHealth)
// SCHEMA_FIELD(Vector, m_vecBaseVelocity)
SCHEMA_FIELD(CCollisionProperty*, m_pCollision)
bool IsBasePlayerController();
};

View File

@@ -2,23 +2,22 @@
#include "../../pch.h"
#include "../handle/handle.h"
#include "cbaseentity.h"
class CBasePlayerController : public CBaseEntity
{
public:
DECLARE_CLASS(CBasePlayerController);
SCHEMA_FIELD(uint64_t, m_steamID)
SCHEMA_FIELD(CHandle, m_hPawn)
SCHEMA_FIELD(char, m_iszPlayerName)
#include "sdk/tier1/UtlString.hpp"
class CBasePlayerController : public CBaseEntity {
public:
DECLARE_CLASS(CBasePlayerController);
SCHEMA_FIELD(uint64_t, m_steamID)
SCHEMA_FIELD(CHandle, m_hPawn)
SCHEMA_FIELD(char, m_iszPlayerName)
SCHEMA_FIELD(CUtlString, m_szNetworkIDString)
};
class CCSPlayerController : public CBasePlayerController {
public:
public:
DECLARE_CLASS(CCSPlayerController)
SCHEMA_FIELD(uint32_t, m_iPawnHealth)
SCHEMA_FIELD(bool, m_bPawnIsAlive)
SCHEMA_FIELD(const char*, m_szClanName)
SCHEMA_FIELD(uint32_t, m_iPawnHealth)
SCHEMA_FIELD(bool, m_bPawnIsAlive)
SCHEMA_FIELD(const char*, m_szClanName)
};

View File

@@ -2,8 +2,6 @@
#include <cstdint>
#define INVALID_EHANDLE_INDEX 0xFFFFFFFF
#define ENT_ENTRY_MASK 0x7FFF
inline int PlayerSlot_to_EntityIndex(int PlayerSlot) { return PlayerSlot + 1; }
inline int EntityIndex_to_PlayerSlot(int EntityIndex) { return EntityIndex - 1; }
class CBaseEntity;
class CHandle
@@ -22,8 +20,5 @@ public:
{
return reinterpret_cast<T*>(GetBaseEntity());
}
auto GetPlayerSlot() {
return m_Index - 1;
}
uint32_t m_Index;
};

View File

@@ -7,6 +7,8 @@ uint64_t NetworkStateChangedPtr;
uint64_t CGameEventManagerPtr;
uint64_t Host_SayPtr;
uint64_t Module_tier0;
uint64_t MaxPlayerNumsPtr;
namespace InterFaces {
CSchemaSystem* SchemaSystem;
IGameEventManager2* GameEventManager;
@@ -19,6 +21,8 @@ auto Init() -> bool {
CModule server("server.dll");
CModule schemasystem("schemasystem.dll");
CModule engine("engine2.dll");
// engine.dll
engine.FindPattern(pattern_MaxPlayerNumsPtr).ToAbsolute(3, 0).Get(MaxPlayerNumsPtr);
// server.dll
server.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
@@ -49,10 +53,13 @@ auto Init() -> bool {
InterFaces::CGameEventManger =
reinterpret_cast<CGameEventManager*>(CGameEventManagerPtr);
//global::MaxPlayers = *(int*)((char*)MaxPlayerNumsPtr + 2);
// client.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
LOG("[huoji]FireEventServerSidePtr : %llx \n", FireEventServerSidePtr);
LOG("[huoji]NetworkStateChangedPtr : %llx \n", NetworkStateChangedPtr);
LOG("[huoji]Host_SayPtr : %llx \n", Host_SayPtr);
LOG("[huoji]Host_SayPtr : %llx \n", MaxPlayerNumsPtr);
LOG("[huoji]MaxGlobals : %d \n", global::MaxPlayers);
LOG("[huoji]InterFaces::SchemaSystem : %llx \n", InterFaces::SchemaSystem);
LOG("[huoji]InterFaces::GameEventManager : %llx \n",

View File

@@ -30,10 +30,13 @@ static const auto pattern_fnGetLocalPlayerController =
//"\"Console<0>\" say \"%s\"\n"
static const auto pattern_fnHost_SayPtr =
THE_GAME_SIG("44 89 4C 24 ?? 44 88 44 24 ?? 55 53 56 57 41 54 41 55");
static const auto pattern_MaxPlayerNumsPtr =
THE_GAME_SIG("41 3B 87 ?? ?? ?? ?? 0F 8E ?? ?? ?? ?? 8B 0D ?? ?? ?? ??");
extern uint64_t GameResourceServicePtr;
extern uint64_t FireEventServerSidePtr;
extern uint64_t Module_tier0;
extern uint64_t NetworkStateChangedPtr;
extern uint64_t Host_SayPtr;
extern uint64_t MaxPlayerNumsPtr;
auto Init() -> bool;
}; // namespace Offset

View File

@@ -11,6 +11,7 @@
#include <unordered_map>
#include <map>
#include <shared_mutex>
#include <sstream>
#include "framework.h"
#include "stb.hh"

View File

@@ -2,37 +2,34 @@
#include "pch.h"
#include "schema.h"
#include "native_sdk/entity/cbaseentity.h"
#include "sdk/player/playerslot.h"
class CBasePlayer {
public:
auto ForceRespawn() -> void;
public:
auto ForceRespawn() -> void;
};
class CPlayer_MovementServices
{
public:
DECLARE_CLASS(CPlayer_MovementServices);
class CPlayer_MovementServices {
public:
DECLARE_CLASS(CPlayer_MovementServices);
};
class CCSPlayerController_InGameMoneyServices
{
public:
DECLARE_CLASS(CCSPlayerController_InGameMoneyServices);
class CCSPlayerController_InGameMoneyServices {
public:
DECLARE_CLASS(CCSPlayerController_InGameMoneyServices);
SCHEMA_FIELD(int, m_iAccount)
SCHEMA_FIELD(int, m_iAccount)
};
class CBasePlayerPawn : public CBaseEntity
{
public:
DECLARE_CLASS(CBasePlayerPawn);
class CBasePlayerPawn : public CBaseEntity {
public:
DECLARE_CLASS(CBasePlayerPawn);
SCHEMA_FIELD(CPlayer_MovementServices*, m_pMovementServices)
SCHEMA_FIELD(uint8_t*, m_pWeaponServices)
SCHEMA_FIELD(uint8_t**, m_pItemServices)
SCHEMA_FIELD(CPlayer_MovementServices*, m_pMovementServices)
SCHEMA_FIELD(uint8_t*, m_pWeaponServices)
SCHEMA_FIELD(uint8_t**, m_pItemServices)
};
class CCSPlayerPawn : public CBasePlayerPawn
{
public:
DECLARE_CLASS(CCSPlayerPawn);
SCHEMA_FIELD(const char*, m_szLastPlaceName)
class CCSPlayerPawn : public CBasePlayerPawn {
public:
DECLARE_CLASS(CCSPlayerPawn);
SCHEMA_FIELD(const char*, m_szLastPlaceName)
};

View File

@@ -1,26 +1,50 @@
#include "player_manager.h"
namespace PlayerManager {
std::shared_mutex mutex_PlayerNameList;
std::unordered_map<uint32_t, std::string> PlayerNameList;
auto AddPlayerNameToPlayerNameList(const CPlayerSlot PlayerSlot,
const char* PlayerName) -> void {
std::unique_lock lock(mutex_PlayerNameList);
PlayerNameList[PlayerSlot.Get()] = PlayerName;
LOG("%s PlayerNameList[%d] = %s \n", __FUNCTION__, PlayerSlot.Get(),
PlayerName);
#include "native_sdk/cgameentitysystem.h"
namespace ExtendPlayerManager {
std::shared_mutex mutex_Table_PlayerSteamIdPlayerSlot;
std::unordered_map<uint64_t, uint64_t> Table_PlayerSteamIdPlayerSlot;
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t {
std::istringstream iss(
steamID.substr(3, steamID.size() - 4)); // 去掉"[U:"和"]"
std::string tmp;
uint32_t instance, account_id;
// 读取 Account Instance
std::getline(iss, tmp, ':');
instance = std::stoi(tmp);
// 读取 Account ID
std::getline(iss, tmp);
account_id = std::stoi(tmp);
// 计算并返回结果
return (uint64_t(account_id) << 1 | instance) + 76561197960265728ULL;
}
auto RemovePlayerNameFromPlayerNameList(const CPlayerSlot PlayerSlot,
const char* PlayerName) -> void {
std::unique_lock lock(mutex_PlayerNameList);
PlayerNameList.erase(PlayerSlot.Get());
LOG("%s PlayerNameList[%d] = %s \n", __FUNCTION__, PlayerSlot.Get(),
PlayerName);
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
uint64_t PlayerSlot) -> void {
std::unique_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
LOG("steamid: %llu playername: %ld \n", SteamId, PlayerSlot);
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, PlayerSlot));
}
auto GetPlayerNameByPlayerSlot(const CPlayerSlot PlayerSlot) -> std::string {
std::shared_lock lock(mutex_PlayerNameList);
auto index = PlayerSlot.Get();
auto name = PlayerNameList[index];
LOG("get player name: %d %s \n", index, name.c_str());
return name;
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
std::shared_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
LOG("steamid: %llu \n", SteamId);
auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
return it->second;
}
return -1;
}
}; // namespace PlayerManager
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void {
std::unique_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
LOG("steamid: %llu \n", SteamId);
if (Table_PlayerSteamIdPlayerSlot.find(SteamId) !=
Table_PlayerSteamIdPlayerSlot.end()) {
Table_PlayerSteamIdPlayerSlot.erase(SteamId);
}
}
}; // namespace ExtendPlayerManager

View File

@@ -1,10 +1,10 @@
#pragma once
#include "pch.h"
#include "sdk/player/playerslot.h"
namespace PlayerManager {
auto AddPlayerNameToPlayerNameList(const CPlayerSlot PlayerSlot,
const char* PlayerName) -> void;
auto RemovePlayerNameFromPlayerNameList(const CPlayerSlot PlayerSlot,
const char* PlayerName) -> void;
auto GetPlayerNameByPlayerSlot(const CPlayerSlot PlayerSlot) -> std::string;
}; // namespace PlayerManager
namespace ExtendPlayerManager {
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
uint64_t PlayerSlot) -> void;
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t;
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t;
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void;
}; // namespace ExtendPlayerManager