增加pawn名字
This commit is contained in:
@@ -214,6 +214,7 @@
|
|||||||
<ClCompile Include="MinHook\src\trampoline.c" />
|
<ClCompile Include="MinHook\src\trampoline.c" />
|
||||||
<ClCompile Include="native_sdk\cgameentitysystem.cpp" />
|
<ClCompile Include="native_sdk\cgameentitysystem.cpp" />
|
||||||
<ClCompile Include="native_sdk\cschemasystem.cpp" />
|
<ClCompile Include="native_sdk\cschemasystem.cpp" />
|
||||||
|
<ClCompile Include="native_sdk\entity\cbaseentity.cpp" />
|
||||||
<ClCompile Include="native_sdk\handle\handle.cpp" />
|
<ClCompile Include="native_sdk\handle\handle.cpp" />
|
||||||
<ClCompile Include="offset.cpp" />
|
<ClCompile Include="offset.cpp" />
|
||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
|
|||||||
@@ -287,6 +287,9 @@
|
|||||||
<ClCompile Include="player_manager.cpp">
|
<ClCompile Include="player_manager.cpp">
|
||||||
<Filter>源文件\players</Filter>
|
<Filter>源文件\players</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="native_sdk\entity\cbaseentity.cpp">
|
||||||
|
<Filter>源文件\native_sdk\entity</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="cpp.hint" />
|
<None Include="cpp.hint" />
|
||||||
|
|||||||
@@ -4,27 +4,30 @@
|
|||||||
#include "player_manager.h"
|
#include "player_manager.h"
|
||||||
|
|
||||||
namespace events {
|
namespace events {
|
||||||
auto OnPlayerDeathEvent(IGameEvent* event) -> void {
|
auto OnPlayerDeathEvent(IGameEvent* event) -> void {
|
||||||
UnkGameEventStruct_t userIdNameParams{ "userid" };
|
UnkGameEventStruct_t userIdNameParams{"userid"};
|
||||||
UnkGameEventStruct_t attackerNameParams{ "attacker" };
|
UnkGameEventStruct_t attackerNameParams{"attacker"};
|
||||||
|
|
||||||
const auto victim = reinterpret_cast<CCSPlayerController*>(event->GetPlayerPawn(&userIdNameParams));
|
const auto victim = reinterpret_cast<CCSPlayerPawn*>(
|
||||||
const auto attacker = reinterpret_cast<CCSPlayerController*>(event->GetPlayerPawn(&attackerNameParams));
|
event->GetPlayerPawn(&userIdNameParams));
|
||||||
|
const auto attacker = reinterpret_cast<CCSPlayerPawn*>(
|
||||||
|
event->GetPlayerPawn(&attackerNameParams));
|
||||||
|
|
||||||
auto victimName = std::string(PlayerManager::GetPlayerNameByPlayerSlot(victim->GetRefEHandle().GetPlayerSlot()));
|
CGameEntitySystem* pEntitySystem = CGameEntitySystem::GetInstance();
|
||||||
auto attackerName = std::string(PlayerManager::GetPlayerNameByPlayerSlot(attacker->GetRefEHandle().GetPlayerSlot()));
|
if (!pEntitySystem) return;
|
||||||
|
|
||||||
printf("player %s killed %s\n", victimName.c_str(), attackerName.c_str());
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto OnPlayerChat(IGameEvent* event) -> void
|
//printf("player[%p] %s kill[%p] %llu\n", attacker, &attacker->m_iszPlayerName(), victim, &victim->m_steamID());
|
||||||
{
|
}
|
||||||
UnkGameEventStruct_t userIdNameParams{ "userid" };
|
auto OnPlayerChat(IGameEvent* event) -> void {}
|
||||||
const auto chater = reinterpret_cast<CCSPlayerController*>(event->GetPlayer(&userIdNameParams));
|
} // namespace events
|
||||||
const auto text = event->GetString("text");
|
|
||||||
const auto chaterName = chater->m_iszPlayerName();
|
|
||||||
|
|
||||||
LOG("player: %s say: %s \n", chaterName, text);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
namespace global {
|
namespace global {
|
||||||
bool Exit;
|
bool Exit;
|
||||||
|
int MaxPlayers;
|
||||||
}
|
}
|
||||||
@@ -2,4 +2,5 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
namespace global {
|
namespace global {
|
||||||
extern bool Exit;
|
extern bool Exit;
|
||||||
|
extern int MaxPlayers;
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,10 @@ VMTHook* VMT_IServerGameClient;
|
|||||||
void __fastcall hook_ClientDisconnect(void* rcx, CPlayerSlot slot, int reason,
|
void __fastcall hook_ClientDisconnect(void* rcx, CPlayerSlot slot, int reason,
|
||||||
const char* pszName, uint64_t xuid,
|
const char* pszName, uint64_t xuid,
|
||||||
const char* pszNetworkID) {
|
const char* pszNetworkID) {
|
||||||
PlayerManager::RemovePlayerNameFromPlayerNameList(slot, pszName);
|
if (pszNetworkID != NULL && *pszNetworkID == '[') {
|
||||||
|
ExtendPlayerManager::RemovePlayerSlotBySteamId(
|
||||||
|
ExtendPlayerManager::SteamIDStringToUInt64(pszNetworkID));
|
||||||
|
}
|
||||||
return original_OnClientDisconnect(rcx, slot, reason, pszName, xuid,
|
return original_OnClientDisconnect(rcx, slot, reason, pszName, xuid,
|
||||||
pszNetworkID);
|
pszNetworkID);
|
||||||
}
|
}
|
||||||
@@ -24,10 +27,10 @@ void __fastcall hook_OnClientConnected(void* rcx, CPlayerSlot slot,
|
|||||||
const char* pszAddress,
|
const char* pszAddress,
|
||||||
bool bFakePlayer) {
|
bool bFakePlayer) {
|
||||||
if (bFakePlayer == false) {
|
if (bFakePlayer == false) {
|
||||||
LOG("%s %d %s %s %s %d", __FUNCTION__, slot.Get(), pszName, pszNetworkID,
|
ExtendPlayerManager::AddSteamIdToPlayerSteamIdWithNameTable(
|
||||||
pszAddress, bFakePlayer);
|
ExtendPlayerManager::SteamIDStringToUInt64(pszNetworkID),
|
||||||
|
slot.Get());
|
||||||
}
|
}
|
||||||
PlayerManager::AddPlayerNameToPlayerNameList(slot, pszName);
|
|
||||||
|
|
||||||
return original_OnClientConnected(rcx, slot, pszName, xuid, pszNetworkID,
|
return original_OnClientConnected(rcx, slot, pszName, xuid, pszNetworkID,
|
||||||
pszAddress, bFakePlayer);
|
pszAddress, bFakePlayer);
|
||||||
@@ -43,9 +46,8 @@ void __fastcall hook_Host_Say(void* pEntity, void* args, bool teamonly,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto message = std::string(theArgs->GetCommandString());
|
auto message = std::string(theArgs->GetCommandString());
|
||||||
auto playerName = PlayerManager::GetPlayerNameByPlayerSlot(
|
printf("player[%d][%p] %s : %s \n", theEntity->GetRefEHandle().GetEntryIndex(),theEntity, &theEntity->m_iszPlayerName(),
|
||||||
theEntity->GetRefEHandle().GetPlayerSlot());
|
message.c_str());
|
||||||
printf("player %s : %s \n", playerName.c_str(), message.c_str());
|
|
||||||
} while (false);
|
} while (false);
|
||||||
/*
|
/*
|
||||||
if (*pMessage == '!' || *pMessage == '/')
|
if (*pMessage == '!' || *pMessage == '/')
|
||||||
|
|||||||
4
csgo2/native_sdk/entity/cbaseentity.cpp
Normal file
4
csgo2/native_sdk/entity/cbaseentity.cpp
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#include "cbaseentity.h"
|
||||||
|
bool CBaseEntity::IsBasePlayerController() {
|
||||||
|
return CALL_VIRTUAL(bool, 144, this);
|
||||||
|
}
|
||||||
@@ -6,38 +6,37 @@
|
|||||||
#include "../cgameentitysystem.h"
|
#include "../cgameentitysystem.h"
|
||||||
class CEntityIdentity;
|
class CEntityIdentity;
|
||||||
class CEntityInstance {
|
class CEntityInstance {
|
||||||
public:
|
public:
|
||||||
DECLARE_CLASS(CEntityInstance);
|
DECLARE_CLASS(CEntityInstance);
|
||||||
|
|
||||||
auto Schema_DynamicBinding() {
|
auto Schema_DynamicBinding() {
|
||||||
SchemaClassInfoData_t* rv = nullptr;
|
SchemaClassInfoData_t* rv = nullptr;
|
||||||
CALL_VIRTUAL(void, 34, this, &rv);
|
CALL_VIRTUAL(void, 34, this, &rv);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GetRefEHandle() {
|
auto GetRefEHandle() {
|
||||||
char* pIdentity = (char*)m_pEntity();
|
char* pIdentity = (char*)m_pEntity();
|
||||||
auto v3 = *(uint32_t*)(pIdentity + 16);
|
auto v3 = *(uint32_t*)(pIdentity + 16);
|
||||||
auto v4 = ENT_ENTRY_MASK;
|
auto v4 = ENT_ENTRY_MASK;
|
||||||
auto v5 = ((v3 >> 15) - (*(uint32_t*)(pIdentity + 48) & 1)) << 15;
|
auto v5 = ((v3 >> 15) - (*(uint32_t*)(pIdentity + 48) & 1)) << 15;
|
||||||
if (v3 != -1) {
|
if (v3 != -1) {
|
||||||
v4 = *(uint32_t*)(pIdentity + 16) & ENT_ENTRY_MASK;
|
v4 = *(uint32_t*)(pIdentity + 16) & ENT_ENTRY_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CHandle(v4 | v5);
|
return CHandle(v4 | v5);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCHEMA_FIELD(CEntityIdentity*, m_pEntity);
|
|
||||||
SCHEMA_FIELD(const char*, m_designerName);
|
|
||||||
|
|
||||||
|
SCHEMA_FIELD(CEntityIdentity*, m_pEntity);
|
||||||
|
SCHEMA_FIELD(const char*, m_designerName);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBaseEntity : public CEntityInstance
|
class CBaseEntity : public CEntityInstance {
|
||||||
{
|
public:
|
||||||
public:
|
DECLARE_CLASS(CBaseEntity);
|
||||||
DECLARE_CLASS(CBaseEntity);
|
|
||||||
|
|
||||||
SCHEMA_FIELD(int, m_iHealth)
|
SCHEMA_FIELD(int, m_iHealth)
|
||||||
//SCHEMA_FIELD(Vector, m_vecBaseVelocity)
|
// SCHEMA_FIELD(Vector, m_vecBaseVelocity)
|
||||||
SCHEMA_FIELD(CCollisionProperty*, m_pCollision)
|
SCHEMA_FIELD(CCollisionProperty*, m_pCollision)
|
||||||
};
|
bool IsBasePlayerController();
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,23 +2,22 @@
|
|||||||
#include "../../pch.h"
|
#include "../../pch.h"
|
||||||
#include "../handle/handle.h"
|
#include "../handle/handle.h"
|
||||||
#include "cbaseentity.h"
|
#include "cbaseentity.h"
|
||||||
class CBasePlayerController : public CBaseEntity
|
#include "sdk/tier1/UtlString.hpp"
|
||||||
{
|
class CBasePlayerController : public CBaseEntity {
|
||||||
public:
|
public:
|
||||||
DECLARE_CLASS(CBasePlayerController);
|
DECLARE_CLASS(CBasePlayerController);
|
||||||
|
|
||||||
SCHEMA_FIELD(uint64_t, m_steamID)
|
|
||||||
SCHEMA_FIELD(CHandle, m_hPawn)
|
|
||||||
SCHEMA_FIELD(char, m_iszPlayerName)
|
|
||||||
|
|
||||||
|
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 {
|
class CCSPlayerController : public CBasePlayerController {
|
||||||
public:
|
public:
|
||||||
DECLARE_CLASS(CCSPlayerController)
|
DECLARE_CLASS(CCSPlayerController)
|
||||||
|
|
||||||
SCHEMA_FIELD(uint32_t, m_iPawnHealth)
|
SCHEMA_FIELD(uint32_t, m_iPawnHealth)
|
||||||
SCHEMA_FIELD(bool, m_bPawnIsAlive)
|
SCHEMA_FIELD(bool, m_bPawnIsAlive)
|
||||||
SCHEMA_FIELD(const char*, m_szClanName)
|
SCHEMA_FIELD(const char*, m_szClanName)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#define INVALID_EHANDLE_INDEX 0xFFFFFFFF
|
#define INVALID_EHANDLE_INDEX 0xFFFFFFFF
|
||||||
#define ENT_ENTRY_MASK 0x7FFF
|
#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 CBaseEntity;
|
||||||
|
|
||||||
class CHandle
|
class CHandle
|
||||||
@@ -22,8 +20,5 @@ public:
|
|||||||
{
|
{
|
||||||
return reinterpret_cast<T*>(GetBaseEntity());
|
return reinterpret_cast<T*>(GetBaseEntity());
|
||||||
}
|
}
|
||||||
auto GetPlayerSlot() {
|
|
||||||
return m_Index - 1;
|
|
||||||
}
|
|
||||||
uint32_t m_Index;
|
uint32_t m_Index;
|
||||||
};
|
};
|
||||||
@@ -7,6 +7,8 @@ uint64_t NetworkStateChangedPtr;
|
|||||||
uint64_t CGameEventManagerPtr;
|
uint64_t CGameEventManagerPtr;
|
||||||
uint64_t Host_SayPtr;
|
uint64_t Host_SayPtr;
|
||||||
uint64_t Module_tier0;
|
uint64_t Module_tier0;
|
||||||
|
uint64_t MaxPlayerNumsPtr;
|
||||||
|
|
||||||
namespace InterFaces {
|
namespace InterFaces {
|
||||||
CSchemaSystem* SchemaSystem;
|
CSchemaSystem* SchemaSystem;
|
||||||
IGameEventManager2* GameEventManager;
|
IGameEventManager2* GameEventManager;
|
||||||
@@ -19,6 +21,8 @@ auto Init() -> bool {
|
|||||||
CModule server("server.dll");
|
CModule server("server.dll");
|
||||||
CModule schemasystem("schemasystem.dll");
|
CModule schemasystem("schemasystem.dll");
|
||||||
CModule engine("engine2.dll");
|
CModule engine("engine2.dll");
|
||||||
|
// engine.dll
|
||||||
|
engine.FindPattern(pattern_MaxPlayerNumsPtr).ToAbsolute(3, 0).Get(MaxPlayerNumsPtr);
|
||||||
|
|
||||||
// server.dll
|
// server.dll
|
||||||
server.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
|
server.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
|
||||||
@@ -49,10 +53,13 @@ auto Init() -> bool {
|
|||||||
InterFaces::CGameEventManger =
|
InterFaces::CGameEventManger =
|
||||||
reinterpret_cast<CGameEventManager*>(CGameEventManagerPtr);
|
reinterpret_cast<CGameEventManager*>(CGameEventManagerPtr);
|
||||||
|
|
||||||
|
//global::MaxPlayers = *(int*)((char*)MaxPlayerNumsPtr + 2);
|
||||||
// client.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
|
// client.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
|
||||||
LOG("[huoji]FireEventServerSidePtr : %llx \n", FireEventServerSidePtr);
|
LOG("[huoji]FireEventServerSidePtr : %llx \n", FireEventServerSidePtr);
|
||||||
LOG("[huoji]NetworkStateChangedPtr : %llx \n", NetworkStateChangedPtr);
|
LOG("[huoji]NetworkStateChangedPtr : %llx \n", NetworkStateChangedPtr);
|
||||||
LOG("[huoji]Host_SayPtr : %llx \n", Host_SayPtr);
|
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::SchemaSystem : %llx \n", InterFaces::SchemaSystem);
|
||||||
LOG("[huoji]InterFaces::GameEventManager : %llx \n",
|
LOG("[huoji]InterFaces::GameEventManager : %llx \n",
|
||||||
|
|||||||
@@ -30,10 +30,13 @@ static const auto pattern_fnGetLocalPlayerController =
|
|||||||
//"\"Console<0>\" say \"%s\"\n"
|
//"\"Console<0>\" say \"%s\"\n"
|
||||||
static const auto pattern_fnHost_SayPtr =
|
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");
|
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 GameResourceServicePtr;
|
||||||
extern uint64_t FireEventServerSidePtr;
|
extern uint64_t FireEventServerSidePtr;
|
||||||
extern uint64_t Module_tier0;
|
extern uint64_t Module_tier0;
|
||||||
extern uint64_t NetworkStateChangedPtr;
|
extern uint64_t NetworkStateChangedPtr;
|
||||||
extern uint64_t Host_SayPtr;
|
extern uint64_t Host_SayPtr;
|
||||||
|
extern uint64_t MaxPlayerNumsPtr;
|
||||||
auto Init() -> bool;
|
auto Init() -> bool;
|
||||||
}; // namespace Offset
|
}; // namespace Offset
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "framework.h"
|
#include "framework.h"
|
||||||
#include "stb.hh"
|
#include "stb.hh"
|
||||||
|
|||||||
@@ -2,37 +2,34 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "schema.h"
|
#include "schema.h"
|
||||||
#include "native_sdk/entity/cbaseentity.h"
|
#include "native_sdk/entity/cbaseentity.h"
|
||||||
|
#include "sdk/player/playerslot.h"
|
||||||
|
|
||||||
class CBasePlayer {
|
class CBasePlayer {
|
||||||
public:
|
public:
|
||||||
auto ForceRespawn() -> void;
|
auto ForceRespawn() -> void;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPlayer_MovementServices
|
class CPlayer_MovementServices {
|
||||||
{
|
public:
|
||||||
public:
|
DECLARE_CLASS(CPlayer_MovementServices);
|
||||||
DECLARE_CLASS(CPlayer_MovementServices);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CCSPlayerController_InGameMoneyServices
|
class CCSPlayerController_InGameMoneyServices {
|
||||||
{
|
public:
|
||||||
public:
|
DECLARE_CLASS(CCSPlayerController_InGameMoneyServices);
|
||||||
DECLARE_CLASS(CCSPlayerController_InGameMoneyServices);
|
|
||||||
|
|
||||||
SCHEMA_FIELD(int, m_iAccount)
|
SCHEMA_FIELD(int, m_iAccount)
|
||||||
};
|
};
|
||||||
class CBasePlayerPawn : public CBaseEntity
|
class CBasePlayerPawn : public CBaseEntity {
|
||||||
{
|
public:
|
||||||
public:
|
DECLARE_CLASS(CBasePlayerPawn);
|
||||||
DECLARE_CLASS(CBasePlayerPawn);
|
|
||||||
|
|
||||||
SCHEMA_FIELD(CPlayer_MovementServices*, m_pMovementServices)
|
SCHEMA_FIELD(CPlayer_MovementServices*, m_pMovementServices)
|
||||||
SCHEMA_FIELD(uint8_t*, m_pWeaponServices)
|
SCHEMA_FIELD(uint8_t*, m_pWeaponServices)
|
||||||
SCHEMA_FIELD(uint8_t**, m_pItemServices)
|
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)
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -1,26 +1,50 @@
|
|||||||
#include "player_manager.h"
|
#include "player_manager.h"
|
||||||
namespace PlayerManager {
|
#include "native_sdk/cgameentitysystem.h"
|
||||||
std::shared_mutex mutex_PlayerNameList;
|
namespace ExtendPlayerManager {
|
||||||
std::unordered_map<uint32_t, std::string> PlayerNameList;
|
std::shared_mutex mutex_Table_PlayerSteamIdPlayerSlot;
|
||||||
auto AddPlayerNameToPlayerNameList(const CPlayerSlot PlayerSlot,
|
|
||||||
const char* PlayerName) -> void {
|
std::unordered_map<uint64_t, uint64_t> Table_PlayerSteamIdPlayerSlot;
|
||||||
std::unique_lock lock(mutex_PlayerNameList);
|
|
||||||
PlayerNameList[PlayerSlot.Get()] = PlayerName;
|
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t {
|
||||||
LOG("%s PlayerNameList[%d] = %s \n", __FUNCTION__, PlayerSlot.Get(),
|
std::istringstream iss(
|
||||||
PlayerName);
|
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 {
|
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
|
||||||
std::unique_lock lock(mutex_PlayerNameList);
|
uint64_t PlayerSlot) -> void {
|
||||||
PlayerNameList.erase(PlayerSlot.Get());
|
std::unique_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
|
||||||
LOG("%s PlayerNameList[%d] = %s \n", __FUNCTION__, PlayerSlot.Get(),
|
LOG("steamid: %llu playername: %ld \n", SteamId, PlayerSlot);
|
||||||
PlayerName);
|
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, PlayerSlot));
|
||||||
}
|
}
|
||||||
auto GetPlayerNameByPlayerSlot(const CPlayerSlot PlayerSlot) -> std::string {
|
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
|
||||||
std::shared_lock lock(mutex_PlayerNameList);
|
std::shared_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
|
||||||
auto index = PlayerSlot.Get();
|
LOG("steamid: %llu \n", SteamId);
|
||||||
auto name = PlayerNameList[index];
|
|
||||||
LOG("get player name: %d %s \n", index, name.c_str());
|
auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
|
||||||
return name;
|
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
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "sdk/player/playerslot.h"
|
#include "sdk/player/playerslot.h"
|
||||||
namespace PlayerManager {
|
namespace ExtendPlayerManager {
|
||||||
auto AddPlayerNameToPlayerNameList(const CPlayerSlot PlayerSlot,
|
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
|
||||||
const char* PlayerName) -> void;
|
uint64_t PlayerSlot) -> void;
|
||||||
auto RemovePlayerNameFromPlayerNameList(const CPlayerSlot PlayerSlot,
|
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t;
|
||||||
const char* PlayerName) -> void;
|
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t;
|
||||||
auto GetPlayerNameByPlayerSlot(const CPlayerSlot PlayerSlot) -> std::string;
|
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void;
|
||||||
}; // namespace PlayerManager
|
}; // namespace ExtendPlayerManager
|
||||||
|
|||||||
Reference in New Issue
Block a user