增加serverfunctionhash函数
This commit is contained in:
@@ -205,6 +205,7 @@
|
|||||||
<ClInclude Include="offset.h" />
|
<ClInclude Include="offset.h" />
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
<ClInclude Include="player_manager.h" />
|
<ClInclude Include="player_manager.h" />
|
||||||
|
<ClInclude Include="script_apis.h" />
|
||||||
<ClInclude Include="script_engine.h" />
|
<ClInclude Include="script_engine.h" />
|
||||||
<ClInclude Include="sdk\convar\convar.hpp" />
|
<ClInclude Include="sdk\convar\convar.hpp" />
|
||||||
<ClInclude Include="sdk\gameevent\IGameEvent.h" />
|
<ClInclude Include="sdk\gameevent\IGameEvent.h" />
|
||||||
@@ -224,6 +225,7 @@
|
|||||||
<ClInclude Include="tools.h" />
|
<ClInclude Include="tools.h" />
|
||||||
<ClInclude Include="vmt.h" />
|
<ClInclude Include="vmt.h" />
|
||||||
<ClInclude Include="vmthook.h" />
|
<ClInclude Include="vmthook.h" />
|
||||||
|
<ClInclude Include="script_callbacks.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp" />
|
<ClCompile Include="dllmain.cpp" />
|
||||||
@@ -280,6 +282,8 @@
|
|||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="player_manager.cpp" />
|
<ClCompile Include="player_manager.cpp" />
|
||||||
|
<ClCompile Include="script_apis.cpp" />
|
||||||
|
<ClCompile Include="script_callbacks.cpp" />
|
||||||
<ClCompile Include="script_engine.cpp" />
|
<ClCompile Include="script_engine.cpp" />
|
||||||
<ClCompile Include="sdk\convar\convar.cpp" />
|
<ClCompile Include="sdk\convar\convar.cpp" />
|
||||||
<ClCompile Include="sdk\tier1\UtlString.cpp" />
|
<ClCompile Include="sdk\tier1\UtlString.cpp" />
|
||||||
|
|||||||
@@ -285,6 +285,12 @@
|
|||||||
<ClInclude Include="lua\lzio.h">
|
<ClInclude Include="lua\lzio.h">
|
||||||
<Filter>头文件\lua</Filter>
|
<Filter>头文件\lua</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="script_apis.h">
|
||||||
|
<Filter>头文件\script_engine</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="script_callbacks.h">
|
||||||
|
<Filter>头文件\script_engine</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp">
|
<ClCompile Include="dllmain.cpp">
|
||||||
@@ -452,6 +458,12 @@
|
|||||||
<ClCompile Include="lua\lzio.c">
|
<ClCompile Include="lua\lzio.c">
|
||||||
<Filter>头文件\lua</Filter>
|
<Filter>头文件\lua</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="script_apis.cpp">
|
||||||
|
<Filter>源文件\script_engine</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="script_callbacks.cpp">
|
||||||
|
<Filter>源文件\script_engine</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="cpp.hint" />
|
<None Include="cpp.hint" />
|
||||||
|
|||||||
@@ -4,24 +4,59 @@ 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"};
|
||||||
|
UnkGameEventStruct_t headshotNameParams{ 0 };
|
||||||
const auto victim = reinterpret_cast<CCSPlayerPawn*>(
|
static const auto headShotStr = "headshot";
|
||||||
|
headshotNameParams.m_Unk = Offset::FnServerHashFunction(headShotStr, sizeof headShotStr, SERVER_HASH_FUCNTION_KEY);
|
||||||
|
headshotNameParams.m_Key = headShotStr;
|
||||||
|
const auto victimPawn = reinterpret_cast<CCSPlayerPawn*>(
|
||||||
event->GetPlayerPawn(&userIdNameParams));
|
event->GetPlayerPawn(&userIdNameParams));
|
||||||
const auto attacker = reinterpret_cast<CCSPlayerPawn*>(
|
const auto attackerPawn = reinterpret_cast<CCSPlayerPawn*>(
|
||||||
event->GetPlayerPawn(&attackerNameParams));
|
event->GetPlayerPawn(&attackerNameParams));
|
||||||
|
const auto isHeadShot = event->GetBool(&headshotNameParams);
|
||||||
//printf("player[%p] %s kill[%p] %llu\n", attacker, &attacker->m_iszPlayerName(), victim, &victim->m_steamID());
|
if (victimPawn == nullptr || attackerPawn == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (victimPawn->IsBasePlayerController() == false ||
|
||||||
|
attackerPawn->IsBasePlayerController() == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto victim = victimPawn->GetPlayerController();
|
||||||
|
const auto attacker = attackerPawn->GetPlayerController();
|
||||||
|
if (victim == nullptr || attacker == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto victimIndex = victim->GetRefEHandle().m_Index;
|
||||||
|
const auto attackerIndex = attacker->GetRefEHandle().m_Index;
|
||||||
|
LOG("is head shot: %d \n", isHeadShot);
|
||||||
|
ScriptCallBacks::luaCall_onPlayerDeath(victimIndex, attackerIndex);
|
||||||
|
// printf("player[%p] %s kill[%p] %llu\n", attacker,
|
||||||
|
// &attacker->m_iszPlayerName(), victim, &victim->m_steamID());
|
||||||
}
|
}
|
||||||
auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool {
|
auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool {
|
||||||
auto [procesChatSuccess, chatType, chatCtx] = SdkTools::ProcessChatString(message);
|
auto [procesChatSuccess, chatType, chatCtx] =
|
||||||
|
SdkTools::ProcessChatString(message);
|
||||||
if (procesChatSuccess == false) {
|
if (procesChatSuccess == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG("player %s say[%d]: %s steamid: %llu\n", &player->m_iszPlayerName(), chatType ,chatCtx.c_str(), player->m_steamID());
|
|
||||||
if (chatCtx.at(0) == '/' || chatCtx.at(0) == '!') {
|
if (chatCtx.at(0) == '/' || chatCtx.at(0) == '!') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
|
||||||
|
const char* pszNetworkID, const char* pszAddress,
|
||||||
|
bool bFakePlayer) -> void {
|
||||||
|
const auto PlayerIndex = PlayerSlot_to_EntityIndex(slot);
|
||||||
|
ScriptCallBacks::luaCall_onPlayerConnect(PlayerIndex, slot, pszName, xuid,
|
||||||
|
pszNetworkID, pszAddress,
|
||||||
|
bFakePlayer);
|
||||||
|
}
|
||||||
|
auto OnPlayerDisconnect(int slot, const char* pszName, uint64_t xuid,
|
||||||
|
const char* pszNetworkID, const char* pszAddress,
|
||||||
|
bool bFakePlayer) -> void {
|
||||||
|
const auto PlayerIndex = PlayerSlot_to_EntityIndex(slot);
|
||||||
|
ScriptCallBacks::luaCall_onPlayerDisconnect(PlayerIndex, slot, pszName,
|
||||||
|
xuid, pszNetworkID, pszAddress,
|
||||||
|
bFakePlayer);
|
||||||
|
}
|
||||||
} // namespace events
|
} // namespace events
|
||||||
|
|||||||
@@ -4,4 +4,10 @@ class CCSPlayerController;
|
|||||||
namespace events {
|
namespace events {
|
||||||
auto OnPlayerDeathEvent(IGameEvent* event) -> void;
|
auto OnPlayerDeathEvent(IGameEvent* event) -> void;
|
||||||
auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool;
|
auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool;
|
||||||
}
|
auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
|
||||||
|
const char* pszNetworkID, const char* pszAddress,
|
||||||
|
bool bFakePlayer) -> void;
|
||||||
|
auto OnPlayerDisconnect(int slot, const char* pszName, uint64_t xuid,
|
||||||
|
const char* pszNetworkID, const char* pszAddress,
|
||||||
|
bool bFakePlayer) -> void;
|
||||||
|
} // namespace events
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include "framework.h"
|
#include "framework.h"
|
||||||
#include "stb.hh"
|
#include "stb.hh"
|
||||||
// #define LOG DebugPrintA
|
// #define LOG DebugPrintA
|
||||||
@@ -64,3 +66,5 @@ static void DebugPrintA(const char* format, ...) {
|
|||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "script_engine.h"
|
#include "script_engine.h"
|
||||||
|
#include "script_apis.h"
|
||||||
|
#include "script_callbacks.h"
|
||||||
|
|||||||
@@ -11,10 +11,14 @@ 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) {
|
||||||
|
bool isFakePlayer = true;
|
||||||
if (pszNetworkID != NULL && *pszNetworkID == '[') {
|
if (pszNetworkID != NULL && *pszNetworkID == '[') {
|
||||||
ExtendPlayerManager::RemovePlayerSlotBySteamId(
|
ExtendPlayerManager::RemovePlayerSlotBySteamId(
|
||||||
ExtendPlayerManager::SteamIDStringToUInt64(pszNetworkID));
|
ExtendPlayerManager::SteamIDStringToUInt64(pszNetworkID));
|
||||||
|
isFakePlayer = false;
|
||||||
}
|
}
|
||||||
|
events::OnPlayerDisconnect(slot.Get(), pszName, xuid, pszNetworkID,
|
||||||
|
pszNetworkID, isFakePlayer);
|
||||||
return original_OnClientDisconnect(rcx, slot, reason, pszName, xuid,
|
return original_OnClientDisconnect(rcx, slot, reason, pszName, xuid,
|
||||||
pszNetworkID);
|
pszNetworkID);
|
||||||
}
|
}
|
||||||
@@ -28,7 +32,8 @@ void __fastcall hook_OnClientConnected(void* rcx, CPlayerSlot slot,
|
|||||||
ExtendPlayerManager::SteamIDStringToUInt64(pszNetworkID),
|
ExtendPlayerManager::SteamIDStringToUInt64(pszNetworkID),
|
||||||
slot.Get());
|
slot.Get());
|
||||||
}
|
}
|
||||||
|
events::OnPlayerConnect(slot.Get(), pszName, xuid, pszNetworkID, pszAddress,
|
||||||
|
bFakePlayer);
|
||||||
return original_OnClientConnected(rcx, slot, pszName, xuid, pszNetworkID,
|
return original_OnClientConnected(rcx, slot, pszName, xuid, pszNetworkID,
|
||||||
pszAddress, bFakePlayer);
|
pszAddress, bFakePlayer);
|
||||||
}
|
}
|
||||||
@@ -57,8 +62,9 @@ void __fastcall hook_Host_Say(void* pEntity, void* args, bool teamonly,
|
|||||||
if (*pMessage == '/')
|
if (*pMessage == '/')
|
||||||
return;
|
return;
|
||||||
*/
|
*/
|
||||||
if (blockMsg) { return; }
|
if (blockMsg) {
|
||||||
else {
|
return;
|
||||||
|
} else {
|
||||||
return original_Host_Say(pEntity, args, teamonly, unk1, unk2);
|
return original_Host_Say(pEntity, args, teamonly, unk1, unk2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,6 +83,7 @@ bool __fastcall hook_FireEventServerSide(CGameEventManager* rcx,
|
|||||||
static constexpr auto player_death =
|
static constexpr auto player_death =
|
||||||
hash_32_fnv1a_const("player_death");
|
hash_32_fnv1a_const("player_death");
|
||||||
static constexpr auto player_chat = hash_32_fnv1a_const("player_chat");
|
static constexpr auto player_chat = hash_32_fnv1a_const("player_chat");
|
||||||
|
|
||||||
switch (hash_32_fnv1a_const(eventName)) {
|
switch (hash_32_fnv1a_const(eventName)) {
|
||||||
case player_death:
|
case player_death:
|
||||||
events::OnPlayerDeathEvent(event);
|
events::OnPlayerDeathEvent(event);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ uint64_t CGameEventManagerPtr;
|
|||||||
uint64_t Host_SayPtr;
|
uint64_t Host_SayPtr;
|
||||||
uint64_t Module_tier0;
|
uint64_t Module_tier0;
|
||||||
uint64_t MaxPlayerNumsPtr;
|
uint64_t MaxPlayerNumsPtr;
|
||||||
|
HashFunction_t FnServerHashFunction;
|
||||||
namespace InterFaces {
|
namespace InterFaces {
|
||||||
CSchemaSystem* SchemaSystem;
|
CSchemaSystem* SchemaSystem;
|
||||||
IGameEventManager2* GameEventManager;
|
IGameEventManager2* GameEventManager;
|
||||||
@@ -16,6 +16,7 @@ CGameEventManager* CGameEventManger;
|
|||||||
CGameResourceService* GameResourceServiceServer;
|
CGameResourceService* GameResourceServiceServer;
|
||||||
IServerGameClients* IServerGameClient;
|
IServerGameClients* IServerGameClient;
|
||||||
IVEngineServer2* IVEngineServer;
|
IVEngineServer2* IVEngineServer;
|
||||||
|
ISource2Server* ISource2ServerInterFace;
|
||||||
}; // namespace InterFaces
|
}; // namespace InterFaces
|
||||||
auto Init() -> bool {
|
auto Init() -> bool {
|
||||||
CModule server("server.dll");
|
CModule server("server.dll");
|
||||||
@@ -32,13 +33,16 @@ auto Init() -> bool {
|
|||||||
.ToAbsolute(3, 0)
|
.ToAbsolute(3, 0)
|
||||||
.Get(CGameEventManagerPtr);
|
.Get(CGameEventManagerPtr);
|
||||||
server.FindPattern(pattern_fnHost_SayPtr).Get(Host_SayPtr);
|
server.FindPattern(pattern_fnHost_SayPtr).Get(Host_SayPtr);
|
||||||
|
server.FindPattern(pattern_ServerHashFunctionPtr).Get(FnServerHashFunction);
|
||||||
|
|
||||||
// schemasystem
|
// schemasystem
|
||||||
InterFaces::SchemaSystem = reinterpret_cast<CSchemaSystem*>(
|
InterFaces::SchemaSystem = reinterpret_cast<CSchemaSystem*>(
|
||||||
schemasystem.FindInterface("SchemaSystem_001").Get());
|
schemasystem.FindInterface("SchemaSystem_001").Get());
|
||||||
|
|
||||||
// engine.dll
|
// engine.dll
|
||||||
InterFaces::GameEventManager = reinterpret_cast<IGameEventManager2*>(
|
//InterFaces::GameEventManager = reinterpret_cast<IGameEventManager2*>(
|
||||||
engine.FindInterface("GameEventSystemServerV001").Get());
|
// engine.FindInterface("GameEventSystemServerV001").Get());
|
||||||
|
//InterFaces::GameEventManager = reinterpret_cast<IGameEventManager2*>(engine.FindInterface("GameEventSystemServerV001").Get());
|
||||||
InterFaces::GameResourceServiceServer =
|
InterFaces::GameResourceServiceServer =
|
||||||
reinterpret_cast<CGameResourceService*>(
|
reinterpret_cast<CGameResourceService*>(
|
||||||
engine.FindInterface("GameResourceServiceServerV001").Get());
|
engine.FindInterface("GameResourceServiceServerV001").Get());
|
||||||
@@ -48,17 +52,22 @@ auto Init() -> bool {
|
|||||||
// server.dll
|
// server.dll
|
||||||
InterFaces::IServerGameClient = reinterpret_cast<IServerGameClients*>(
|
InterFaces::IServerGameClient = reinterpret_cast<IServerGameClients*>(
|
||||||
server.FindInterface("Source2GameClients001").Get());
|
server.FindInterface("Source2GameClients001").Get());
|
||||||
|
InterFaces::ISource2ServerInterFace = reinterpret_cast<ISource2Server*>(
|
||||||
// only init in console server
|
server.FindInterface("Source2Server001").Get());
|
||||||
|
if (InterFaces::ISource2ServerInterFace) {
|
||||||
|
InterFaces::GameEventManager = (IGameEventManager2*)(CALL_VIRTUAL(uintptr_t, 91, InterFaces::ISource2ServerInterFace) - 8);
|
||||||
|
}
|
||||||
InterFaces::CGameEventManger =
|
InterFaces::CGameEventManger =
|
||||||
reinterpret_cast<CGameEventManager*>(CGameEventManagerPtr);
|
reinterpret_cast<CGameEventManager*>(CGameEventManagerPtr);
|
||||||
|
|
||||||
//global::MaxPlayers = *(int*)((char*)MaxPlayerNumsPtr + 2);
|
//global::MaxPlayers = *(int*)((char*)MaxPlayerNumsPtr + 2);
|
||||||
// client.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
|
// client.FindPattern(pattern_FireEventServerSide).Get(FireEventServerSidePtr);
|
||||||
|
global::MaxPlayers = 64;
|
||||||
|
|
||||||
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]FnServerHashFunction : %llx \n", FnServerHashFunction);
|
||||||
LOG("[huoji]MaxGlobals : %d \n", global::MaxPlayers);
|
LOG("[huoji]MaxGlobals : %d \n", global::MaxPlayers);
|
||||||
|
|
||||||
LOG("[huoji]InterFaces::SchemaSystem : %llx \n", InterFaces::SchemaSystem);
|
LOG("[huoji]InterFaces::SchemaSystem : %llx \n", InterFaces::SchemaSystem);
|
||||||
@@ -72,10 +81,13 @@ auto Init() -> bool {
|
|||||||
InterFaces::IServerGameClient);
|
InterFaces::IServerGameClient);
|
||||||
LOG("[huoji]InterFaces::IVEngineServer : %llx \n",
|
LOG("[huoji]InterFaces::IVEngineServer : %llx \n",
|
||||||
InterFaces::IVEngineServer);
|
InterFaces::IVEngineServer);
|
||||||
|
LOG("[huoji]InterFaces::ISource2ServerInterFace : %llx \n",
|
||||||
|
InterFaces::ISource2ServerInterFace);
|
||||||
|
|
||||||
// GetOffsets();
|
// GetOffsets();
|
||||||
LOG("init offset success !\n");
|
LOG("init offset success !\n");
|
||||||
return Host_SayPtr && InterFaces::IVEngineServer &&
|
LOG("FnServerHashFunction: %llx \n", FnServerHashFunction("here", sizeof("here") - 1, 0x31415926));
|
||||||
|
return FnServerHashFunction && Host_SayPtr && InterFaces::IVEngineServer &&
|
||||||
InterFaces::GameResourceServiceServer &&
|
InterFaces::GameResourceServiceServer &&
|
||||||
InterFaces::IServerGameClient && InterFaces::GameEventManager &&
|
InterFaces::IServerGameClient && InterFaces::GameEventManager &&
|
||||||
InterFaces::SchemaSystem && FireEventServerSidePtr &&
|
InterFaces::SchemaSystem && FireEventServerSidePtr &&
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "head.h"
|
#include "head.h"
|
||||||
|
#define SERVER_HASH_FUCNTION_KEY 0x31415926
|
||||||
|
typedef uint64_t(__fastcall* HashFunction_t)(const char*, unsigned int, unsigned int);
|
||||||
|
|
||||||
class CSchemaSystem;
|
class CSchemaSystem;
|
||||||
class CGameResourceService;
|
class CGameResourceService;
|
||||||
@@ -28,6 +30,8 @@ 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_ServerHashFunctionPtr =
|
||||||
|
THE_GAME_SIG("48 89 ?? ?? ?? 57 48 ?? ?? ?? ?? ?? ?? 33 C0 8B DA 41 8B F8 48 89 ?? ?? ?? 4C 8B C1 C7 44 ?? ?? ?? ?? ?? ?? 44 8B CA 89 44 ?? ?? 48 8D ?? ?? ?? 88 44 ?? ?? 33 D2");
|
||||||
static const auto pattern_MaxPlayerNumsPtr =
|
static const auto pattern_MaxPlayerNumsPtr =
|
||||||
THE_GAME_SIG("41 3B 87 ?? ?? ?? ?? 0F 8E ?? ?? ?? ?? 8B 0D ?? ?? ?? ??");
|
THE_GAME_SIG("41 3B 87 ?? ?? ?? ?? 0F 8E ?? ?? ?? ?? 8B 0D ?? ?? ?? ??");
|
||||||
extern uint64_t GameResourceServicePtr;
|
extern uint64_t GameResourceServicePtr;
|
||||||
@@ -36,5 +40,6 @@ 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;
|
extern uint64_t MaxPlayerNumsPtr;
|
||||||
|
extern HashFunction_t FnServerHashFunction;
|
||||||
auto Init() -> bool;
|
auto Init() -> bool;
|
||||||
}; // namespace Offset
|
}; // namespace Offset
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t {
|
|||||||
|
|
||||||
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
|
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
|
||||||
uint64_t PlayerSlot) -> void {
|
uint64_t PlayerSlot) -> void {
|
||||||
std::unique_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
|
std::unique_lock<std::shared_mutex> lock(
|
||||||
LOG("steamid: %llu playername: %ld \n", SteamId, PlayerSlot);
|
mutex_Table_PlayerSteamIdPlayerSlot);
|
||||||
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, PlayerSlot));
|
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, PlayerSlot));
|
||||||
}
|
}
|
||||||
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
|
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
|
||||||
std::shared_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
|
std::shared_lock<std::shared_mutex> lock(
|
||||||
LOG("steamid: %llu \n", SteamId);
|
mutex_Table_PlayerSteamIdPlayerSlot);
|
||||||
|
|
||||||
auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
|
auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
|
||||||
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
|
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
|
||||||
@@ -38,12 +38,43 @@ auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
auto GetPlayerSteamIdByPlayerSlot(uint64_t playerSlot) -> uint64_t {
|
||||||
|
std::shared_lock<std::shared_mutex> lock(
|
||||||
|
mutex_Table_PlayerSteamIdPlayerSlot);
|
||||||
|
for (auto& [SteamId, PlayerSlot] : Table_PlayerSteamIdPlayerSlot) {
|
||||||
|
if (PlayerSlot == playerSlot) {
|
||||||
|
return SteamId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void {
|
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void {
|
||||||
std::unique_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
|
std::unique_lock<std::shared_mutex> lock(
|
||||||
LOG("steamid: %llu \n", SteamId);
|
mutex_Table_PlayerSteamIdPlayerSlot);
|
||||||
if (Table_PlayerSteamIdPlayerSlot.find(SteamId) !=
|
if (Table_PlayerSteamIdPlayerSlot.find(SteamId) !=
|
||||||
Table_PlayerSteamIdPlayerSlot.end()) {
|
Table_PlayerSteamIdPlayerSlot.end()) {
|
||||||
Table_PlayerSteamIdPlayerSlot.erase(SteamId);
|
Table_PlayerSteamIdPlayerSlot.erase(SteamId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auto GetPlayerByPlayerSlot(uint64_t playerSlot) -> CCSPlayerController* {
|
||||||
|
auto PlayerSteamId = GetPlayerSteamIdByPlayerSlot(playerSlot);
|
||||||
|
if (PlayerSteamId == -1) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
CGameEntitySystem* pEntitySystem = CGameEntitySystem::GetInstance();
|
||||||
|
if (!pEntitySystem) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= global::MaxPlayers; ++i) {
|
||||||
|
CBaseEntity* pEntity = pEntitySystem->GetBaseEntity(i);
|
||||||
|
if (!pEntity) continue;
|
||||||
|
if (pEntity->IsBasePlayerController()) {
|
||||||
|
const auto player = reinterpret_cast<CCSPlayerController*>(pEntity);
|
||||||
|
if (player->m_steamID() == PlayerSteamId) {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}; // namespace ExtendPlayerManager
|
}; // namespace ExtendPlayerManager
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
|
|||||||
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t;
|
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t;
|
||||||
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t;
|
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t;
|
||||||
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void;
|
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void;
|
||||||
|
auto GetPlayerByPlayerSlot(uint64_t playerSlot) -> CCSPlayerController*;
|
||||||
}; // namespace ExtendPlayerManager
|
}; // namespace ExtendPlayerManager
|
||||||
|
|||||||
36
csgo2/script_apis.cpp
Normal file
36
csgo2/script_apis.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include "script_apis.h"
|
||||||
|
namespace ScriptApis {
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ҫ<EFBFBD>Լ<EFBFBD>push<73><68>stack<63><6B>
|
||||||
|
auto luaApi_ListenToGameEvent(lua_State* luaVm) -> int {
|
||||||
|
const auto eventName = lua_tostring(luaVm, 1);
|
||||||
|
do {
|
||||||
|
if (eventName == nullptr) {
|
||||||
|
LOG("luaApi_ListenToGameEvent eventName == nullptr || callbackName "
|
||||||
|
"== "
|
||||||
|
"nullptr\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!lua_isfunction(luaVm, 2)) {
|
||||||
|
LOG("luaApi_ListenToGameEvent callback is not a function\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto callbackType = ScriptCallBacks::CallBackNameToEnum(eventName);
|
||||||
|
if (callbackType == ScriptCallBacks::_CallbackNames::kError) {
|
||||||
|
LOG("luaApi_ListenToGameEvent unknown event name: %s\n", eventName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>ӵ<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>
|
||||||
|
std::unique_lock lock(ScriptCallBacks::mutex_callbackList);
|
||||||
|
ScriptCallBacks::callbackList[luaVm][callbackType] = luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
|
LOG("luaApi_ListenToGameEvent eventName:%s callback added\n",
|
||||||
|
eventName);
|
||||||
|
} while (false);
|
||||||
|
|
||||||
|
lua_pop(luaVm, 2); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
auto initFunciton(lua_State* luaVm) -> void {
|
||||||
|
lua_register(luaVm, "ListenToGameEvent", luaApi_ListenToGameEvent);
|
||||||
|
}
|
||||||
|
}; // namespace ScriptApis
|
||||||
5
csgo2/script_apis.h
Normal file
5
csgo2/script_apis.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "head.h"
|
||||||
|
namespace ScriptApis {
|
||||||
|
auto initFunciton(lua_State* luaVm) -> void;
|
||||||
|
};
|
||||||
105
csgo2/script_callbacks.cpp
Normal file
105
csgo2/script_callbacks.cpp
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
#include "script_callbacks.h"
|
||||||
|
#include <functional>
|
||||||
|
namespace ScriptCallBacks {
|
||||||
|
std::unordered_map<lua_State*, std::unordered_map<_CallbackNames, int>>
|
||||||
|
callbackList;
|
||||||
|
std::shared_mutex mutex_callbackList;
|
||||||
|
std::unordered_map<uint32_t, _CallbackNames> callbackNameWithEnumMap{
|
||||||
|
{hash_32_fnv1a_const("player_connect"), _CallbackNames::kOnPlayerConnect},
|
||||||
|
{hash_32_fnv1a_const("player_disconnect"),
|
||||||
|
_CallbackNames::kOnPlayerDisconnect},
|
||||||
|
{hash_32_fnv1a_const("player_death"), _CallbackNames::kOnPlayerDeath}};
|
||||||
|
auto CallBackNameToEnum(const char* name) -> _CallbackNames {
|
||||||
|
if (name == nullptr) {
|
||||||
|
return _CallbackNames::kError;
|
||||||
|
}
|
||||||
|
auto hash = hash_32_fnv1a_const(name);
|
||||||
|
auto it = callbackNameWithEnumMap.find(hash);
|
||||||
|
if (it == callbackNameWithEnumMap.end()) {
|
||||||
|
return _CallbackNames::kError;
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
auto ExcuteCallbackInAllLuaVm(_CallbackNames cbType,
|
||||||
|
std::function<void(lua_State*, int)> cb) -> void {
|
||||||
|
std::shared_lock lock(mutex_callbackList);
|
||||||
|
|
||||||
|
for (auto& [pluginName, luaVm] : ScriptEngine::pluginEnvs) {
|
||||||
|
// find lua in callbackList
|
||||||
|
if (callbackList.find(luaVm) == callbackList.end()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto luaVMCallbackLists = callbackList[luaVm];
|
||||||
|
if (luaVMCallbackLists.find(cbType) == luaVMCallbackLists.end()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LOG("excute callback %d in %s \n", cbType, pluginName.c_str());
|
||||||
|
const auto luaRefIndex = luaVMCallbackLists.at(cbType);
|
||||||
|
cb(luaVm, luaRefIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto luaCall_onPlayerConnect(int player, int playerSlot, const char* playerName,
|
||||||
|
uint64_t xuid, const char* SteamId,
|
||||||
|
const char* IpAddress, bool isBot) -> void {
|
||||||
|
ExcuteCallbackInAllLuaVm(_CallbackNames::kOnPlayerConnect,
|
||||||
|
[&](lua_State* luaVm, int refIndex) -> void {
|
||||||
|
lua_rawgeti(luaVm, LUA_REGISTRYINDEX,
|
||||||
|
refIndex);
|
||||||
|
if (lua_isfunction(luaVm, -1)) {
|
||||||
|
lua_pushinteger(luaVm, player);
|
||||||
|
lua_pushinteger(luaVm, playerSlot);
|
||||||
|
lua_pushstring(luaVm, playerName);
|
||||||
|
lua_pushinteger(luaVm, xuid);
|
||||||
|
lua_pushstring(luaVm, SteamId);
|
||||||
|
lua_pushstring(luaVm, IpAddress);
|
||||||
|
lua_pushboolean(luaVm, isBot);
|
||||||
|
if (lua_pcall(luaVm, 7, 0, 0) != LUA_OK) {
|
||||||
|
LOG("Error calling Lua callback: %s\n",
|
||||||
|
lua_tostring(luaVm, -1));
|
||||||
|
lua_pop(luaVm, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// lua_pop(luaVm, 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
auto luaCall_onPlayerDisconnect(int player, int slot, const char* pszName,
|
||||||
|
uint64_t xuid, const char* pszNetworkID,
|
||||||
|
const char* pszAddress, bool bFakePlayer)
|
||||||
|
-> void {
|
||||||
|
ExcuteCallbackInAllLuaVm(_CallbackNames::kOnPlayerDisconnect,
|
||||||
|
[&](lua_State* luaVm, int refIndex) -> void {
|
||||||
|
lua_rawgeti(luaVm, LUA_REGISTRYINDEX,
|
||||||
|
refIndex);
|
||||||
|
if (lua_isfunction(luaVm, -1)) {
|
||||||
|
lua_pushinteger(luaVm, player);
|
||||||
|
lua_pushinteger(luaVm, slot);
|
||||||
|
lua_pushstring(luaVm, pszName);
|
||||||
|
lua_pushinteger(luaVm, xuid);
|
||||||
|
lua_pushstring(luaVm, pszNetworkID);
|
||||||
|
lua_pushstring(luaVm, pszAddress);
|
||||||
|
lua_pushboolean(luaVm, bFakePlayer);
|
||||||
|
if (lua_pcall(luaVm, 7, 0, 0) != LUA_OK) {
|
||||||
|
LOG("Error calling Lua callback: %s\n",
|
||||||
|
lua_tostring(luaVm, -1));
|
||||||
|
lua_pop(luaVm, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
auto luaCall_onPlayerDeath(int victim, int killer) -> void {
|
||||||
|
ExcuteCallbackInAllLuaVm(_CallbackNames::kOnPlayerDeath,
|
||||||
|
[&](lua_State* luaVm, int refIndex) -> void {
|
||||||
|
lua_rawgeti(luaVm, LUA_REGISTRYINDEX,
|
||||||
|
refIndex);
|
||||||
|
if (lua_isfunction(luaVm, -1)) {
|
||||||
|
lua_pushinteger(luaVm, victim);
|
||||||
|
lua_pushinteger(luaVm, killer);
|
||||||
|
if (lua_pcall(luaVm, 2, 0, 0) != LUA_OK) {
|
||||||
|
LOG("Error calling Lua callback: %s\n",
|
||||||
|
lua_tostring(luaVm, -1));
|
||||||
|
lua_pop(luaVm, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} // namespace ScriptCallBacks
|
||||||
22
csgo2/script_callbacks.h
Normal file
22
csgo2/script_callbacks.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "head.h"
|
||||||
|
namespace ScriptCallBacks {
|
||||||
|
extern std::shared_mutex mutex_callbackList;
|
||||||
|
enum class _CallbackNames {
|
||||||
|
kError,
|
||||||
|
kOnPlayerConnect,
|
||||||
|
kOnPlayerDisconnect,
|
||||||
|
kOnPlayerDeath
|
||||||
|
};
|
||||||
|
extern std::unordered_map<lua_State*, std::unordered_map<_CallbackNames, int>>
|
||||||
|
callbackList;
|
||||||
|
auto CallBackNameToEnum(const char* name) -> ScriptCallBacks::_CallbackNames;
|
||||||
|
auto luaCall_onPlayerConnect(int player, int playerSlot, const char* playerName,
|
||||||
|
uint64_t xuid, const char* SteamId,
|
||||||
|
const char* IpAddress, bool isBot) -> void;
|
||||||
|
auto luaCall_onPlayerDisconnect(int player, int slot, const char* pszName,
|
||||||
|
uint64_t xuid, const char* pszNetworkID,
|
||||||
|
const char* pszAddress, bool bFakePlayer)
|
||||||
|
-> void;
|
||||||
|
auto luaCall_onPlayerDeath(int victim, int killer) -> void;
|
||||||
|
} // namespace ScriptCallBacks
|
||||||
@@ -1,44 +1,81 @@
|
|||||||
#include "script_engine.h"
|
#include "script_engine.h"
|
||||||
namespace ScriptEngine {
|
namespace ScriptEngine {
|
||||||
lua_State* luaVm;
|
|
||||||
std::string luaPath;
|
std::string luaPath;
|
||||||
auto callFunction(const char* funcName) -> int {
|
std::map<std::string, lua_State*> pluginEnvs;
|
||||||
|
std::shared_mutex mutex_pluginEnvs;
|
||||||
|
|
||||||
|
auto callFunction(lua_State* luaVm, const char* funcName) -> int {
|
||||||
lua_getglobal(luaVm, funcName);
|
lua_getglobal(luaVm, funcName);
|
||||||
_ASSERT(lua_isfunction(luaVm, -1));
|
auto result = 0;
|
||||||
|
do {
|
||||||
|
if (lua_type(luaVm, -1) == LUA_TNIL) {
|
||||||
|
printf("lua_getglobal :%s\n\n", lua_tostring(luaVm, -1));
|
||||||
|
result = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!lua_isfunction(luaVm, -1)) {
|
||||||
|
printf("lua_isfunction_err:%s\n\n", lua_tostring(luaVm, -1));
|
||||||
|
result = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (lua_pcall(luaVm, 0, 1, 0)) {
|
if (lua_pcall(luaVm, 0, 1, 0)) {
|
||||||
printf("lua_pcall_err:%s\n\n", lua_tostring(luaVm, -1));
|
printf("lua_pcall_err:%s\n\n", lua_tostring(luaVm, -1));
|
||||||
|
result = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
const auto result = lua_toboolean(luaVm, 1);
|
const auto result = lua_toboolean(luaVm, 1);
|
||||||
|
} while (false);
|
||||||
|
|
||||||
lua_pop(luaVm, 1);
|
lua_pop(luaVm, 1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
auto initFunciton() -> void {
|
|
||||||
}
|
|
||||||
auto initLuaScripts() -> void {
|
|
||||||
std::vector<std::string> files;
|
|
||||||
Tools::GetFiles(luaPath, files);
|
|
||||||
if (files.size() == 0) {
|
|
||||||
LOG("no lua file in %s\n", luaPath.c_str());
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < files.size(); i++) {
|
|
||||||
std::string file = files[i];
|
|
||||||
if (file.find(".lua") != std::string::npos) {
|
|
||||||
LOG("excute: %s\n", file.c_str());
|
|
||||||
|
|
||||||
if (luaL_dofile(luaVm, file.c_str())) {
|
auto initLuaScripts() -> void {
|
||||||
LOG("dofile_err:%s\n\n", lua_tostring(luaVm, -1));
|
auto [dirPaths, dirNames] = Tools::GetDirs(luaPath);
|
||||||
|
if (dirPaths.size() == 0) {
|
||||||
|
LOG("no lua file in %s\n", luaPath.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::unique_lock lock(mutex_pluginEnvs);
|
||||||
|
for (size_t i = 0; i < dirPaths.size(); i++) {
|
||||||
|
std::string dirPath = dirPaths[i];
|
||||||
|
std::string dirName = dirNames[i];
|
||||||
|
|
||||||
|
lua_State* L = luaL_newstate();
|
||||||
|
ScriptApis::initFunciton(L);
|
||||||
|
|
||||||
|
luaL_openlibs(L);
|
||||||
|
pluginEnvs[dirName] = L;
|
||||||
|
|
||||||
|
std::string file = dirPath + "\\main.lua";
|
||||||
|
if (std::filesystem::exists(file) == false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
callFunction("main");
|
LOG("execute: %s\n", file.c_str());
|
||||||
|
|
||||||
|
if (luaL_dofile(L, file.c_str())) {
|
||||||
|
LOG("dofile_err:%s\n\n", lua_tostring(L, -1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
callFunction(L, "Main");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto releaseLuaScripts() -> void {
|
||||||
|
std::unique_lock lock(mutex_pluginEnvs);
|
||||||
|
for (auto& pair : pluginEnvs) {
|
||||||
|
lua_close(pair.second);
|
||||||
}
|
}
|
||||||
auto Init() -> void {
|
pluginEnvs.clear();
|
||||||
luaVm = luaL_newstate();
|
}
|
||||||
luaPath = Tools::GetExePath() + "\\huoji_scripts\\";
|
|
||||||
initFunciton();
|
auto reloadLuaScripts() -> void {
|
||||||
|
releaseLuaScripts();
|
||||||
initLuaScripts();
|
initLuaScripts();
|
||||||
}
|
}
|
||||||
|
auto Init() -> void {
|
||||||
|
// luaPath = Tools::GetExePath() + "\\huoji_scripts\\";
|
||||||
|
luaPath = "F:\\source2\\huoji_scripts\\";
|
||||||
|
initLuaScripts();
|
||||||
}
|
}
|
||||||
|
} // namespace ScriptEngine
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "head.h"
|
#include "head.h"
|
||||||
namespace ScriptEngine {
|
namespace ScriptEngine {
|
||||||
|
extern std::map<std::string, lua_State*> pluginEnvs;
|
||||||
|
extern std::shared_mutex mutex_pluginEnvs;
|
||||||
|
extern std::shared_mutex mutex_pluginEnvs;
|
||||||
auto Init() -> void;
|
auto Init() -> void;
|
||||||
auto callFunction(const char* funcName) -> int;
|
auto callFunction(const char* funcName) -> int;
|
||||||
}
|
auto releaseLuaScripts() -> void;
|
||||||
|
auto reloadLuaScripts() -> void;
|
||||||
|
} // namespace ScriptEngine
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ class IToolGameEventAPI
|
|||||||
{
|
{
|
||||||
virtual void unk001(void*) = 0;
|
virtual void unk001(void*) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UnkGameEventStruct_t {
|
struct UnkGameEventStruct_t {
|
||||||
UnkGameEventStruct_t(const char* keyName) {
|
UnkGameEventStruct_t(const char* keyName) {
|
||||||
m_Unk = 0;
|
m_Unk = 0;
|
||||||
@@ -24,6 +23,7 @@ struct UnkGameEventStruct_t {
|
|||||||
class IGameEvent
|
class IGameEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// 0
|
||||||
virtual ~IGameEvent() {};
|
virtual ~IGameEvent() {};
|
||||||
virtual const char* GetName() const = 0; // get event name
|
virtual const char* GetName() const = 0; // get event name
|
||||||
virtual int GetID() const = 0;
|
virtual int GetID() const = 0;
|
||||||
@@ -32,8 +32,8 @@ public:
|
|||||||
virtual bool IsLocal() const = 0; // if event is never networked
|
virtual bool IsLocal() const = 0; // if event is never networked
|
||||||
virtual bool IsEmpty(const char* keyName = NULL) = 0; // check if data field exists
|
virtual bool IsEmpty(const char* keyName = NULL) = 0; // check if data field exists
|
||||||
|
|
||||||
// Data access
|
// Data access index 6
|
||||||
virtual bool GetBool(const char* keyName = NULL, bool defaultValue = false) = 0;
|
virtual bool GetBool(UnkGameEventStruct_t* keyName = NULL, bool defaultValue = false) = 0;
|
||||||
virtual int GetInt(const char* keyName = NULL, int defaultValue = 0) = 0;
|
virtual int GetInt(const char* keyName = NULL, int defaultValue = 0) = 0;
|
||||||
virtual uint64_t GetUint64(const char* keyName = NULL, uint64_t defaultValue = 0) = 0;
|
virtual uint64_t GetUint64(const char* keyName = NULL, uint64_t defaultValue = 0) = 0;
|
||||||
virtual float GetFloat(const char* keyName = NULL, float defaultValue = 0.0f) = 0;
|
virtual float GetFloat(const char* keyName = NULL, float defaultValue = 0.0f) = 0;
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ class CGlobalVars;
|
|||||||
class CSharedEdictChangeInfo;
|
class CSharedEdictChangeInfo;
|
||||||
class IAchievementMgr;
|
class IAchievementMgr;
|
||||||
class CCommandContext;
|
class CCommandContext;
|
||||||
|
class EconControlPointInfo_t;
|
||||||
|
struct EconItemInfo_t {
|
||||||
|
|
||||||
|
};
|
||||||
|
class bf_write;
|
||||||
typedef uint32_t SpawnGroupHandle_t;
|
typedef uint32_t SpawnGroupHandle_t;
|
||||||
typedef uint32_t SwapChainHandle_t;
|
typedef uint32_t SwapChainHandle_t;
|
||||||
struct CEntityIndex
|
struct CEntityIndex
|
||||||
@@ -78,7 +83,98 @@ public:
|
|||||||
virtual void* UnknownFunc1(const char* pszFilename, void* pUnknown1, void* pUnknown2, void* pUnknown3) = 0;
|
virtual void* UnknownFunc1(const char* pszFilename, void* pUnknown1, void* pUnknown2, void* pUnknown3) = 0;
|
||||||
virtual void UnknownFunc2() = 0;
|
virtual void UnknownFunc2() = 0;
|
||||||
};
|
};
|
||||||
|
class ISource2Server : public IAppSystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool Unknown0() const = 0;
|
||||||
|
|
||||||
|
virtual void SetGlobals(CGlobalVars* pGlobals) = 0;
|
||||||
|
|
||||||
|
// Let the game .dll allocate it's own network/shared string tables
|
||||||
|
virtual void GameCreateNetworkStringTables(void) = 0;
|
||||||
|
|
||||||
|
virtual void WriteSignonMessages(const bf_write& buf) = 0;
|
||||||
|
|
||||||
|
virtual void PreWorldUpdate(bool simulating) = 0;
|
||||||
|
|
||||||
|
virtual void* GetEntity2Networkables(void) const = 0;
|
||||||
|
|
||||||
|
virtual void* GetEntityInfo() = 0;
|
||||||
|
|
||||||
|
// Called to apply lobby settings to a dedicated server
|
||||||
|
virtual void ApplyGameSettings(KeyValues* pKV) = 0;
|
||||||
|
|
||||||
|
// The server should run physics/think on all edicts
|
||||||
|
// One of these bools is 'simulating'... probably
|
||||||
|
virtual void GameFrame(bool simulating, bool bFirstTick, bool bLastTick) = 0;
|
||||||
|
|
||||||
|
// Returns true if the game DLL wants the server not to be made public.
|
||||||
|
// Used by commentary system to hide multiplayer commentary servers from the master.
|
||||||
|
virtual bool ShouldHideFromMasterServer(bool bServerHasPassword) = 0;
|
||||||
|
|
||||||
|
virtual void GetMatchmakingTags(char* buf, size_t bufSize) = 0;
|
||||||
|
|
||||||
|
virtual void ServerHibernationUpdate(bool bHibernating) = 0;
|
||||||
|
|
||||||
|
virtual void* GetServerGCLobby() = 0;
|
||||||
|
|
||||||
|
virtual void GetMatchmakingGameData(CBufferString& buf) = 0;
|
||||||
|
|
||||||
|
// return true to disconnect client due to timeout (used to do stricter timeouts when the game is sure the client isn't loading a map)
|
||||||
|
virtual bool ShouldTimeoutClient(int nUserID, float flTimeSinceLastReceived) = 0;
|
||||||
|
|
||||||
|
virtual void PrintStatus(CEntityIndex nPlayerEntityIndex, CBufferString& output) = 0;
|
||||||
|
|
||||||
|
virtual int GetServerGameDLLFlags(void) const = 0;
|
||||||
|
|
||||||
|
// Get the list of cvars that require tags to show differently in the server browser
|
||||||
|
virtual void GetTaggedConVarList(KeyValues* pCvarTagList) = 0;
|
||||||
|
|
||||||
|
// Give the list of datatable classes to the engine. The engine matches class names from here with
|
||||||
|
// edict_t::classname to figure out how to encode a class's data for networking
|
||||||
|
virtual void* GetAllServerClasses(void) = 0;
|
||||||
|
|
||||||
|
virtual const char* GetActiveWorldName(void) const = 0;
|
||||||
|
|
||||||
|
virtual bool IsPaused(void) const = 0;
|
||||||
|
|
||||||
|
virtual bool GetNavMeshData(void* pNavMeshData) = 0;
|
||||||
|
virtual void SetNavMeshData(const void* navMeshData) = 0;
|
||||||
|
virtual void RegisterNavListener(void* pNavListener) = 0;
|
||||||
|
virtual void UnregisterNavListener(void* pNavListener) = 0;
|
||||||
|
virtual void* GetSpawnDebugInterface(void) = 0;
|
||||||
|
virtual void* Unknown1(void) = 0;
|
||||||
|
virtual void* GetToolGameSimulationAPI(void) = 0;
|
||||||
|
virtual void GetAnimationActivityList(void* activityList) = 0;
|
||||||
|
virtual void GetAnimationEventList(void* eventList) = 0;
|
||||||
|
virtual void FilterPlayerCounts(int* pInOutHumans, int* pInOutHumansSlots, int* pInOutBots) = 0;
|
||||||
|
|
||||||
|
// Called after the steam API has been activated post-level startup
|
||||||
|
virtual void GameServerSteamAPIActivated(void) = 0;
|
||||||
|
|
||||||
|
virtual void GameServerSteamAPIDeactivated(void) = 0;
|
||||||
|
|
||||||
|
virtual void OnHostNameChanged(const char* pHostname) = 0;
|
||||||
|
virtual void PreFatalShutdown(void) const = 0;
|
||||||
|
virtual void UpdateWhenNotInGame(float flFrameTime) = 0;
|
||||||
|
|
||||||
|
virtual void GetEconItemNamesForModel(const char* pModelName, bool bExcludeItemSets, bool bExcludeIndividualItems, void* econItemNames) = 0;
|
||||||
|
virtual void GetEconItemNamesForCharacter(const char* pCharacterName, bool bExcludeItemSets, bool bExcludeIndividualItems, void* econItemNames) = 0;
|
||||||
|
virtual void GetEconItemsInfoForModel(const char* pModelName, const char* pEconItemName, bool bExcludeItemSets, bool bExcludeIndividualItems, bool bExcludeStockItemSet, void* econInfo) = 0;
|
||||||
|
virtual void GetEconItemsInfoForCharacter(const char* pCharacterName, const char* pEconItemName, bool bExcludeItemSets, bool bExcludeIndividualItems, bool bExcludeStockItemSet, void* econInfo) = 0;
|
||||||
|
|
||||||
|
virtual void GetDefaultScaleForModel(const char* pModelName, bool bCheckLoadoutScale) = 0;
|
||||||
|
virtual void GetDefaultScaleForCharacter(const char* pCharacterName, bool bCheckLoadoutScale) = 0;
|
||||||
|
virtual void GetDefaultControlPointAutoUpdates(const char* pParticleSystemName, void* autoUpdates) = 0;
|
||||||
|
virtual void GetCharacterNameForModel(const char* pModelName, bool bCheckItemModifiers, CUtlString& characterName) = 0;
|
||||||
|
virtual void GetModelNameForCharacter(const char* pCharacterNamel, int nIndex, CBufferString& modelName) = 0;
|
||||||
|
virtual void GetCharacterList(void* characterNames) = 0;
|
||||||
|
virtual void GetDefaultChoreoDirForModel(const char* pModelName, CBufferString& defaultVCDDir) = 0;
|
||||||
|
|
||||||
|
virtual void* GetEconItemSystem(void) = 0;
|
||||||
|
|
||||||
|
virtual void ServerConVarChanged(const char* pVarName, const char* pValue) = 0;
|
||||||
|
};
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Purpose: Interface the engine exposes to the game DLL
|
// Purpose: Interface the engine exposes to the game DLL
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "head.h"
|
#include "head.h"
|
||||||
|
inline int PlayerSlot_to_EntityIndex(int PlayerSlot) { return PlayerSlot + 1; }
|
||||||
|
inline int EntityIndex_to_PlayerSlot(int EntityIndex) { return EntityIndex - 1; }
|
||||||
enum _ChatType
|
enum _ChatType
|
||||||
{
|
{
|
||||||
kTeam,
|
kTeam,
|
||||||
|
|||||||
@@ -1,6 +1,33 @@
|
|||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
namespace Tools {
|
namespace Tools {
|
||||||
|
auto GetDirs(const std::string& path)
|
||||||
|
-> std::pair<std::vector<std::string>, std::vector<std::string>> {
|
||||||
|
std::vector<std::string> dirPaths;
|
||||||
|
std::vector<std::string> dirNames;
|
||||||
|
std::string pattern(path);
|
||||||
|
pattern.append("\\*");
|
||||||
|
WIN32_FIND_DATAA data;
|
||||||
|
HANDLE hFind;
|
||||||
|
if ((hFind = FindFirstFileA(pattern.c_str(), &data)) !=
|
||||||
|
INVALID_HANDLE_VALUE) {
|
||||||
|
do {
|
||||||
|
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
if (strcmp(data.cFileName, ".") != 0 &&
|
||||||
|
strcmp(data.cFileName, "..") != 0) {
|
||||||
|
dirPaths.push_back(path + "\\" + data.cFileName);
|
||||||
|
dirNames.push_back(data.cFileName);
|
||||||
|
auto subDirs = GetDirs(path + "\\" + data.cFileName);
|
||||||
|
dirPaths.insert(dirPaths.end(), subDirs.first.begin(),
|
||||||
|
subDirs.first.end());
|
||||||
|
dirNames.insert(dirNames.end(), subDirs.second.begin(),
|
||||||
|
subDirs.second.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (FindNextFileA(hFind, &data) != 0);
|
||||||
|
FindClose(hFind);
|
||||||
|
}
|
||||||
|
return {dirPaths, dirNames};
|
||||||
|
}
|
||||||
auto GetFiles(const std::string& path, std::vector<std::string>& files)
|
auto GetFiles(const std::string& path, std::vector<std::string>& files)
|
||||||
-> void {
|
-> void {
|
||||||
std::string pattern(path);
|
std::string pattern(path);
|
||||||
@@ -15,8 +42,7 @@ namespace Tools {
|
|||||||
strcmp(data.cFileName, "..") != 0) {
|
strcmp(data.cFileName, "..") != 0) {
|
||||||
GetFiles((path + "\\" + data.cFileName), files);
|
GetFiles((path + "\\" + data.cFileName), files);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
files.push_back(path + "\\" + data.cFileName);
|
files.push_back(path + "\\" + data.cFileName);
|
||||||
}
|
}
|
||||||
} while (FindNextFileA(hFind, &data) != 0);
|
} while (FindNextFileA(hFind, &data) != 0);
|
||||||
@@ -32,4 +58,4 @@ namespace Tools {
|
|||||||
std::string f = GetExeFileName();
|
std::string f = GetExeFileName();
|
||||||
return f.substr(0, f.find_last_of("\\/"));
|
return f.substr(0, f.find_last_of("\\/"));
|
||||||
}
|
}
|
||||||
}
|
} // namespace Tools
|
||||||
|
|||||||
@@ -4,4 +4,6 @@ namespace Tools {
|
|||||||
auto GetExeFileName() -> std::string;
|
auto GetExeFileName() -> std::string;
|
||||||
auto GetExePath() -> std::string;
|
auto GetExePath() -> std::string;
|
||||||
auto GetFiles(const std::string& path, std::vector<std::string>& files) -> void;
|
auto GetFiles(const std::string& path, std::vector<std::string>& files) -> void;
|
||||||
};
|
auto GetDirs(const std::string& path)
|
||||||
|
-> std::pair<std::vector<std::string>, std::vector<std::string>>;
|
||||||
|
}; // namespace Tools
|
||||||
|
|||||||
Reference in New Issue
Block a user