Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
huoji120 committed Oct 20, 2023
1 parent 56cd154 commit 4a5a37b
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 22 deletions.
1 change: 1 addition & 0 deletions csgo2/csgo2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
<ClInclude Include="sdk\public\eiface.h" />
<ClInclude Include="sdk\public\IAppSystem.h" />
<ClInclude Include="sdk\public\icvar.h" />
<ClInclude Include="sdk\public\igameeventsystem.h" />
<ClInclude Include="sdk\public\irecipientfilter.h" />
<ClInclude Include="sdk\public\iserver.h" />
<ClInclude Include="sdk\public\mathlib.h" />
Expand Down
3 changes: 3 additions & 0 deletions csgo2/csgo2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@
<ClInclude Include="luaCjson\strbuf.h">
<Filter>源文件\script_engine\lua_cjson</Filter>
</ClInclude>
<ClInclude Include="sdk\public\igameeventsystem.h">
<Filter>头文件\sdk\public</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down
4 changes: 2 additions & 2 deletions csgo2/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ auto init(void* ctx) -> bool {
serverHandle = reinterpret_cast<uint64_t>(GetModuleHandleA("server.dll"));
localizeHandle = reinterpret_cast<uint64_t>(GetModuleHandleA("localize.dll"));

Sleep(200);
Sleep(100);
}
global::isMetaModInit = (GetModuleHandleA("metamod.2.cs2.dll") != nullptr);
global::IsMetaModInit = (GetModuleHandleA("metamod.2.cs2.dll") != nullptr);
if (Offset::Init() == false) {
LOG("Offset::Init() == false !\n");
return false;
Expand Down
3 changes: 2 additions & 1 deletion csgo2/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace global {
CGlobalVars* GlobalVars;
float m_flUniversalTime;
float m_flLastTickedTime;
bool isMetaModInit;
bool IsMetaModInit;
bool IsDisableBlood;
}
3 changes: 2 additions & 1 deletion csgo2/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ namespace global {
extern CGlobalVars* GlobalVars;
extern float m_flUniversalTime;
extern float m_flLastTickedTime;
extern bool isMetaModInit;
extern bool IsMetaModInit;
extern bool IsDisableBlood;
}
60 changes: 49 additions & 11 deletions csgo2/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace hooks {
VMTHook* VMT_IServerGameClient;
VMTHook* VMT_INetworkServerServiceInteFace;
VMTHook* VMT_ISource2ServerInterFace;
VMTHook* VMT_GameEventSystem;

FireEventServerSide_t original_FireEventServerSide = NULL;
OnClientConnect_t original_OnClientConnected = NULL;
OnClientDisconnect_t original_OnClientDisconnect = NULL;
Expand All @@ -14,23 +16,45 @@ StartupServer_t origin_StartServer = NULL;
GameFrame_t origin_GameFrame = NULL;
CCSWeaponBase_Spawn_t origin_CCSWeaponBase_Spawn = NULL;
UTIL_SayText2Filter_t origin_UTIL_SayText2Filter = NULL;
PostEventAbstract_t origin_PostEventAbstract = NULL;
void __fastcall hook_PostEventAbstract(
void* rcx,
CSplitScreenSlot nSlot,
bool bLocalOnly,
int nClientCount,
const uint64* clients,
INetworkSerializable* pEvent,
const void* pData,
unsigned long nSize,
NetChannelBufType_t bufType)
{
/*
if (global::IsDisableBlood == true) {
NetMessageInfo_t* info = pEvent->GetNetMessageInfo();
if (info) {
if (info->m_MessageId == TE_WorldDecalId)
{
LOG("delete the blood in here \n");
//*(uint64_t*)clients &= ~((uint64)1 << nSlot.Get());
}
}
}
*/
if (pEvent) {
NetMessageInfo_t* info = pEvent->GetNetMessageInfo();
if (info && info->m_MessageId != 0) {
LOG("1111:%d \n", info->m_MessageId);
}
}
return origin_PostEventAbstract(rcx, nSlot, bLocalOnly, nClientCount, clients, pEvent, pData, nSize, bufType);
}
void __fastcall hook_UTIL_SayText2Filter(
IRecipientFilter& filter, CCSPlayerController* pEntity,
uint64_t eMessageType, const char* messeageName, const char* param1,
const char* param2, const char* param3, const char* param4) {
const auto entIndex =
PlayerSlot_to_EntityIndex(filter.GetRecipientIndex(0).Get());
/*
LOG("UTIL_SayText2Filter: %s\n", messeageName);
LOG("entIndex: %d\n", entIndex);
LOG("param1: %s\n", param1);
LOG("param2: %s\n", param2);
LOG("param3: %s\n", param3);
LOG("param4: %s\n", param4);
LOG("eMessageType: %d\n", eMessageType);
*/
const auto isHandle = ScriptCallBacks::luCall_onSayText2Filter(
entIndex, eMessageType, messeageName, param1, param2, param3, param4);
if (isHandle == false) {
Expand Down Expand Up @@ -110,6 +134,9 @@ void __fastcall hook_GameFrame(void* rcx, bool simulating, bool bFirstTick,
if (global::EntitySystem == nullptr) {
global::EntitySystem = CGameEntitySystem::GetInstance();
}
if (global::GlobalVars == nullptr) {
global::GlobalVars = GetGameGlobals();
}
return origin_GameFrame(rcx, simulating, bFirstTick, bLastTick);
}
void __fastcall hook_StartServer(void* rcx,
Expand Down Expand Up @@ -300,7 +327,12 @@ auto initVmtHook() -> bool {
VMT_ISource2ServerInterFace =
new VMTHook(Memory::read<void*>(reinterpret_cast<uint64_t>(
Offset::InterFaces::ISource2ServerInterFace)));
VMT_GameEventSystem =
new VMTHook(Memory::read<void*>(reinterpret_cast<uint64_t>(
Offset::InterFaces::GameEventSystem)));

origin_PostEventAbstract = reinterpret_cast<PostEventAbstract_t>(
VMT_GameEventSystem->Hook(16, hook_PostEventAbstract));
original_OnClientConnected = reinterpret_cast<OnClientConnect_t>(
VMT_IServerGameClient->Hook(11, hook_OnClientConnected));
original_OnClientDisconnect = reinterpret_cast<OnClientDisconnect_t>(
Expand All @@ -323,8 +355,14 @@ auto init() -> bool {
}
auto unload() -> void {
VMT_IServerGameClient->ClearHooks();
VMT_INetworkServerServiceInteFace->ClearHooks();
VMT_ISource2ServerInterFace->ClearHooks();
VMT_GameEventSystem->ClearHooks();

delete VMT_IServerGameClient;
delete VMT_INetworkServerServiceInteFace;
delete VMT_ISource2ServerInterFace;
delete VMT_GameEventSystem;

MH_DisableHook(MH_ALL_HOOKS);
MH_RemoveHook(MH_ALL_HOOKS);
Expand Down
2 changes: 1 addition & 1 deletion csgo2/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef void(__fastcall* UTIL_SayText2Filter_t)(IRecipientFilter&,
const char*, const char*,
const char*, const char*,
const char*);

typedef void(__fastcall* PostEventAbstract_t)(void*, CSplitScreenSlot, bool, int, const uint64_t*, INetworkSerializable*, const void*, unsigned long, NetChannelBufType_t);
namespace hooks {
extern Host_Say_t original_Host_Say;
auto init() -> bool;
Expand Down
4 changes: 2 additions & 2 deletions csgo2/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class InterfaceReg;
//cancer fix me plz
namespace global {
extern bool isMetaModInit;
extern bool IsMetaModInit;
};
// Pointer arithmetic utility class.
struct UTILPtr {
Expand Down Expand Up @@ -119,7 +119,7 @@ class CModule {

private:
void InitializeHandle() {
if (global::isMetaModInit == false) {
if (global::IsMetaModInit == false) {
this->m_handle = static_cast<void*>(GetModuleHandleA(this->GetName()));
return;
}
Expand Down
7 changes: 7 additions & 0 deletions csgo2/offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ CLocalize* ILocalize;
INetworkServerService* INetworkServerServiceInteFace;
CCSGameRules* CCSGameRulesInterFace;
ICvar* IVEngineCvar;
IGameEventSystem* GameEventSystem;
}; // namespace InterFaces
auto SafeDelayInit(void* ctx) -> void {
// 需要游戏调用函数初始化
Expand Down Expand Up @@ -108,10 +109,13 @@ auto Init() -> bool {
InterFaces::INetworkServerServiceInteFace =
reinterpret_cast<INetworkServerService*>(
engine.FindInterface("NetworkServerService_001").Get());
InterFaces::GameEventSystem = reinterpret_cast<IGameEventSystem*>(
engine.FindInterface("GameEventSystemServerV001").Get());
InterFaces::IServerGameClient = reinterpret_cast<IServerGameClients*>(
server.FindInterface("Source2GameClients001").Get());
InterFaces::ISource2ServerInterFace = reinterpret_cast<ISource2Server*>(
server.FindInterface("Source2Server001").Get());

if (InterFaces::ISource2ServerInterFace) {
InterFaces::GameEventManager =
(IGameEventManager2*)(CALL_VIRTUAL(
Expand Down Expand Up @@ -156,6 +160,8 @@ auto Init() -> bool {
LOG("[huoji]InterFaces::ISource2ServerInterFace : %llx \n",
InterFaces::ISource2ServerInterFace);
LOG("[huoji]InterFaces::IVEngineCvar : %llx \n", InterFaces::IVEngineCvar);
LOG("[huoji]InterFaces::GameEventSystem : %llx \n", InterFaces::GameEventSystem);

LOG("[huoji] CGameEntitySystem::GetInstance : %llx \n",
CGameEntitySystem::GetInstance());
LOG("init offset success !\n");
Expand All @@ -166,6 +172,7 @@ auto Init() -> bool {
// sizeof("here") - 1, 0x31415926));
return FnPlayerChangeName && FnCCSWeaponBase_Spawn && FnEntityRemove &&
FnRespawnPlayerInDeathMatch && FnGiveNamedItem && Host_SayPtr &&
InterFaces::GameEventSystem &&
InterFaces::IVEngineServer &&
InterFaces::GameResourceServiceServer &&
InterFaces::IServerGameClient && InterFaces::GameEventManager &&
Expand Down
11 changes: 7 additions & 4 deletions csgo2/offset.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class CCSPlayerPawn;
class CGameEntitySystem;
class CCSPlayerController;
class CBaseEntity;
class IGameEventSystem;
class CSchemaSystem;
class CGameResourceService;
class CLocalize;
class CCSGameRules;
typedef uint64_t(__fastcall* HashFunction_t)(const char*, unsigned int,
unsigned int);
typedef void(__fastcall* StateChanged_t)(void* networkTransmitComponent,
Expand All @@ -32,10 +37,7 @@ typedef void(__fastcall* ClientPrint_t)(CCSPlayerController* player,
const char* param3, const char* param4);
typedef void(__fastcall* CCSWeaponBase_Spawn_t)(CBaseEntity*, void*);
typedef void(__fastcall* PlayerChangeName_t)(CBaseEntity*, char*);
class CSchemaSystem;
class CGameResourceService;
class CLocalize;
class CCSGameRules;

namespace Offset {
namespace InterFaces {
extern CSchemaSystem* SchemaSystem;
Expand All @@ -49,6 +51,7 @@ extern INetworkServerService* INetworkServerServiceInteFace;
extern ISource2Server* ISource2ServerInterFace;
extern CCSGameRules* CCSGameRulesInterFace;
extern ICvar* IVEngineCvar;
extern IGameEventSystem* GameEventSystem;
}; // namespace InterFaces
static const auto pattern_FnUTIL_SayText2FilterPtr = THE_GAME_SIG(
"48 89 5C 24 ?? 55 56 57 48 8D 6C 24 ?? 48 81 EC ?? ?? ?? ?? 41 0F B6 F8");
Expand Down
10 changes: 10 additions & 0 deletions csgo2/script_apis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,17 @@ auto luaApi_GetConVarObject(lua_State* luaVm) -> int {
const auto name = lua_tostring(luaVm, 1);
lua_pushnumber(luaVm,
Offset::InterFaces::IVEngineCvar->FindConVar(name).Get());
lua_pop(luaVm, 1);

return 1;
}

auto luaApi_SetServerBloodStatus(lua_State* luaVm) -> int {
// param: isEnableBoold:bool
global::IsDisableBlood = !lua_toboolean(luaVm, 1);
lua_pop(luaVm, 1);
return 0;
}
auto initFunciton(lua_State* luaVm) -> void {
lua_register(luaVm, "ListenToGameEvent", luaApi_ListenToGameEvent);
lua_register(luaVm, "luaApi_SetPlayerCurrentWeaponAmmo",
Expand Down Expand Up @@ -1029,6 +1038,7 @@ auto initFunciton(lua_State* luaVm) -> void {
lua_register(luaVm, "luaApi_GetPlayerName", luaApi_GetPlayerName);
lua_register(luaVm, "luaApi_SetPlayerNameSlient",
luaApi_SetPlayerNameSlient);
lua_register(luaVm, "luaApi_SetServerBloodStatus", luaApi_SetServerBloodStatus);

// lua_register(luaVm, "luaApi_TeleportPlayer", luaApi_TeleportPlayer);

Expand Down
1 change: 1 addition & 0 deletions csgo2/sdk/public/eiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class EconControlPointInfo_t;
struct EconItemInfo_t {

};
class bf_read;
class bf_write;
typedef uint32_t SpawnGroupHandle_t;
typedef uint32_t SwapChainHandle_t;
Expand Down
Loading

0 comments on commit 4a5a37b

Please sign in to comment.