From d787a7da07555d517f52486acf011adb1a633302 Mon Sep 17 00:00:00 2001 From: Huoji's <1296564236@qq.com> Date: Sun, 8 Oct 2023 01:56:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0loader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- csgo2/csgo2.vcxproj | 13 + csgo2/csgo2.vcxproj.filters | 20 ++ csgo2/dllmain.cpp | 4 +- csgo2/events.cpp | 42 +++ csgo2/events.h | 2 + csgo2/hooks.cpp | 8 + csgo2/native_sdk.cpp | 11 +- csgo2/native_sdk.h | 1 - csgo2/offset.cpp | 7 + csgo2/offset.h | 1 + csgo2/script_apis.cpp | 17 +- csgo2/script_callbacks.cpp | 35 +++ csgo2/script_callbacks.h | 7 +- csgo2/script_engine.cpp | 9 +- csgo2/sdk/convar/convar.cpp | 63 ++++- csgo2/sdk/convar/convar.hpp | 272 +++++++++++++++++++- csgo2/sdk/gameevent/IGameEvent.h | 231 +++++++++-------- csgo2/sdk/public/Vector_Sdk.h | 49 ++++ csgo2/sdk/public/color.h | 367 +++++++++++++++++++++++++++ csgo2/sdk/public/eiface.h | 31 ++- csgo2/sdk/public/icvar.h | 84 ++++++ csgo2/sdk/sdk.h | 7 +- csgo2/version_hijack.cpp | 187 ++++++++++++++ csgo2/version_jump.asm | 97 +++++++ loader/loader.sln | 31 +++ loader/loader/loader.cpp | 56 ++++ loader/loader/loader.vcxproj | 149 +++++++++++ loader/loader/loader.vcxproj.filters | 22 ++ 28 files changed, 1692 insertions(+), 131 deletions(-) create mode 100644 csgo2/sdk/public/Vector_Sdk.h create mode 100644 csgo2/sdk/public/color.h create mode 100644 csgo2/sdk/public/icvar.h create mode 100644 csgo2/version_hijack.cpp create mode 100644 csgo2/version_jump.asm create mode 100644 loader/loader.sln create mode 100644 loader/loader/loader.cpp create mode 100644 loader/loader/loader.vcxproj create mode 100644 loader/loader/loader.vcxproj.filters diff --git a/csgo2/csgo2.vcxproj b/csgo2/csgo2.vcxproj index e464d5e..91df1b8 100644 --- a/csgo2/csgo2.vcxproj +++ b/csgo2/csgo2.vcxproj @@ -54,6 +54,7 @@ + @@ -79,10 +80,14 @@ true $(MSBuildProjectDirectory)\sdk\protobuf-2.6.1\src;$(MSBuildProjectDirectory)\LuaBridge;$(IncludePath) + $(ProjectName) + $(SolutionDir)$(Configuration)\ false $(MSBuildProjectDirectory)\sdk\protobuf-2.6.1\src;$(MSBuildProjectDirectory)\LuaBridge;$(IncludePath) + $(ProjectName) + $(SolutionDir)$(Configuration)\ @@ -214,8 +219,10 @@ + + @@ -223,6 +230,7 @@ + @@ -305,14 +313,19 @@ + + + Document + + \ No newline at end of file diff --git a/csgo2/csgo2.vcxproj.filters b/csgo2/csgo2.vcxproj.filters index 69d8aeb..da8a3a2 100644 --- a/csgo2/csgo2.vcxproj.filters +++ b/csgo2/csgo2.vcxproj.filters @@ -82,6 +82,9 @@ {f26913ae-881a-43da-a215-8c0c7a9173cd} + + {23cedcbc-aa1d-444b-baf2-0f55c87c525e} + @@ -342,6 +345,15 @@ 头文件\sdk\tier1 + + 头文件\sdk\public + + + 头文件\sdk\public + + + 头文件\sdk\public + @@ -521,6 +533,9 @@ 源文件\native_sdk + + 源文件\hijack + @@ -528,4 +543,9 @@ 头文件\lua + + + 源文件\hijack + + \ No newline at end of file diff --git a/csgo2/dllmain.cpp b/csgo2/dllmain.cpp index 167b86b..2b9b716 100644 --- a/csgo2/dllmain.cpp +++ b/csgo2/dllmain.cpp @@ -54,12 +54,14 @@ auto init(void* ctx) -> bool { } return isSuccess; } - +extern BOOL APIENTRY VersionHijack_DllMain(HMODULE hModule, DWORD dwReason, PVOID pvReserved); BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { bool result = true; switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: + // 有vac + //VersionHijack_DllMain(hModule, ul_reason_for_call, lpReserved); CreateThread(NULL, 0, reinterpret_cast(init), NULL, 0, NULL); diff --git a/csgo2/events.cpp b/csgo2/events.cpp index 49a7949..a15a1af 100644 --- a/csgo2/events.cpp +++ b/csgo2/events.cpp @@ -1,6 +1,48 @@ #include "events.h" namespace events { +auto OnRoundEndEvent(IGameEvent* event) -> void { + /* + "winner" "byte" // winner team/user i + "reason" "byte" // reson why team won + "message" "string" // end round message + */ + + UnkGameEventStruct_t winnerNameParams{0}; + UnkGameEventStruct_t reasonNameParams{0}; + UnkGameEventStruct_t messageNameParams{0}; + + static const auto winnerStr = "winner"; + static const auto reasonStr = "reason"; + static const auto messageStr = "message"; + + winnerNameParams.m_Unk = Offset::FnServerHashFunction( + winnerStr, sizeof winnerStr, SERVER_HASH_FUCNTION_KEY); + winnerNameParams.m_Key = winnerStr; + + reasonNameParams.m_Unk = Offset::FnServerHashFunction( + reasonStr, sizeof reasonStr, SERVER_HASH_FUCNTION_KEY); + reasonNameParams.m_Key = reasonStr; + + messageNameParams.m_Unk = Offset::FnServerHashFunction( + messageStr, sizeof messageStr, SERVER_HASH_FUCNTION_KEY); + messageNameParams.m_Key = messageStr; + + const auto message = event->GetString(&messageNameParams); + const auto winner = event->GetInt(&winnerNameParams); + const auto reason = event->GetInt(&reasonNameParams); + + ScriptCallBacks::luaCall_onRoundEnd(winner, reason, message); +} +auto OnRoundStartEvent(IGameEvent* event) -> void { + UnkGameEventStruct_t timelimitNameParams{0}; + static const auto timelimitStr = "timelimit"; + timelimitNameParams.m_Unk = Offset::FnServerHashFunction( + timelimitStr, sizeof timelimitStr, SERVER_HASH_FUCNTION_KEY); + timelimitNameParams.m_Key = timelimitStr; + const auto timelimit = event->GetInt(&timelimitNameParams); + ScriptCallBacks::luaCall_onRoundStart(timelimit); +} auto OnPlayerSpawnEvent(IGameEvent* event) -> void { UnkGameEventStruct_t userIdNameParams{"userid"}; const auto playerPawn = reinterpret_cast( diff --git a/csgo2/events.h b/csgo2/events.h index b693cac..dce7912 100644 --- a/csgo2/events.h +++ b/csgo2/events.h @@ -11,4 +11,6 @@ auto OnPlayerDisconnect(int slot, const char* pszName, uint64_t xuid, const char* pszNetworkID, const char* pszAddress, bool bFakePlayer) -> void; auto OnPlayerSpawnEvent(IGameEvent* event) -> void; +auto OnRoundStartEvent(IGameEvent* event) -> void; +auto OnRoundEndEvent(IGameEvent* event) -> void; } // namespace events diff --git a/csgo2/hooks.cpp b/csgo2/hooks.cpp index cb88f61..6c61e9e 100644 --- a/csgo2/hooks.cpp +++ b/csgo2/hooks.cpp @@ -130,6 +130,8 @@ bool __fastcall hook_FireEventServerSide(CGameEventManager* rcx, static constexpr auto player_chat = hash_32_fnv1a_const("player_chat"); static constexpr auto player_spawn = hash_32_fnv1a_const("player_spawn"); + static constexpr auto round_start = hash_32_fnv1a_const("round_start"); + static constexpr auto round_end = hash_32_fnv1a_const("round_end"); switch (hash_32_fnv1a_const(eventName)) { case player_death: @@ -138,6 +140,12 @@ bool __fastcall hook_FireEventServerSide(CGameEventManager* rcx, case player_spawn: events::OnPlayerSpawnEvent(event); break; + case round_start: + events::OnRoundStartEvent(event); + break; + case round_end: + events::OnRoundEndEvent(event); + break; // Vbug,ⲻ /* case player_chat: diff --git a/csgo2/native_sdk.cpp b/csgo2/native_sdk.cpp index 4937536..68ac29b 100644 --- a/csgo2/native_sdk.cpp +++ b/csgo2/native_sdk.cpp @@ -23,8 +23,15 @@ auto CSchemaSystem::FindTypeScopeForModule(const char* module) } auto CBaseEntity::IsBasePlayerController() -> bool { - return true; - //return CALL_VIRTUAL(bool, 146, this); + SchemaClassInfoData_t* pClassInfo = Schema_DynamicBinding(); + if (!pClassInfo) return false; + + const char* className = pClassInfo->GetName(); + if (!className) return false; + static constexpr auto C_CCSPlayerController = hash_32_fnv1a_const("CCSPlayerController"); + static constexpr auto C_CCSPlayerPawn = hash_32_fnv1a_const("CCSPlayerPawn"); + + return hash_32_fnv1a_const(className) == C_CCSPlayerController || hash_32_fnv1a_const(className) == C_CCSPlayerPawn; } auto CBaseEntity::SpawnClientEntity() -> void { CALL_VIRTUAL(void, 19, this); } auto CBasePlayer::ForceRespawn() -> void { diff --git a/csgo2/native_sdk.h b/csgo2/native_sdk.h index 49b7a0d..e032999 100644 --- a/csgo2/native_sdk.h +++ b/csgo2/native_sdk.h @@ -152,7 +152,6 @@ class SchemaClassInfoData_t { return m_schema_parent->m_class; } - private: char pad_0x0000[0x8]; // 0x0000 diff --git a/csgo2/offset.cpp b/csgo2/offset.cpp index 6cb149d..6d8a00b 100644 --- a/csgo2/offset.cpp +++ b/csgo2/offset.cpp @@ -30,6 +30,7 @@ ISource2Server* ISource2ServerInterFace; CLocalize* ILocalize; INetworkServerService* INetworkServerServiceInteFace; CCSGameRules* CCSGameRulesInterFace; +ICvar* IVEngineCvar; }; // namespace InterFaces auto SafeDelayInit(void* ctx) -> void { // ҪϷúʼ @@ -84,6 +85,9 @@ auto Init() -> bool { // engine.FindInterface("GameEventSystemServerV001").Get()); InterFaces::ILocalize = reinterpret_cast( localize.FindInterface("Localize_001").Get()); + InterFaces::IVEngineCvar = reinterpret_cast( + engine.FindInterface("VEngineCvar007").Get()); + InterFaces::GameResourceServiceServer = reinterpret_cast( engine.FindInterface("GameResourceServiceServerV001").Get()); @@ -96,6 +100,7 @@ auto Init() -> bool { server.FindInterface("Source2GameClients001").Get()); InterFaces::ISource2ServerInterFace = reinterpret_cast( server.FindInterface("Source2Server001").Get()); + if (InterFaces::ISource2ServerInterFace) { InterFaces::GameEventManager = (IGameEventManager2*)(CALL_VIRTUAL( @@ -135,6 +140,8 @@ auto Init() -> bool { InterFaces::IVEngineServer); LOG("[huoji]InterFaces::ISource2ServerInterFace : %llx \n", InterFaces::ISource2ServerInterFace); + LOG("[huoji]InterFaces::IVEngineCvar : %llx \n", + InterFaces::IVEngineCvar); LOG("[huoji] CGameEntitySystem::GetInstance : %llx \n", CGameEntitySystem::GetInstance()); LOG("init offset success !\n"); diff --git a/csgo2/offset.h b/csgo2/offset.h index 5ecd8c0..0186e05 100644 --- a/csgo2/offset.h +++ b/csgo2/offset.h @@ -41,6 +41,7 @@ extern CLocalize* ILocalize; extern INetworkServerService* INetworkServerServiceInteFace; extern ISource2Server* ISource2ServerInterFace; extern CCSGameRules* CCSGameRulesInterFace; +extern ICvar* IVEngineCvar; }; // namespace InterFaces static const auto pattern_CGameEventManager = THE_GAME_SIG( "48 ?? ?? ?? ?? ?? ?? 48 89 ?? ?? ?? 48 89 01 48 8B D9 48 ?? ?? ?? ?? ?? " diff --git a/csgo2/script_apis.cpp b/csgo2/script_apis.cpp index 3e410d0..0d37601 100644 --- a/csgo2/script_apis.cpp +++ b/csgo2/script_apis.cpp @@ -24,8 +24,8 @@ auto RunTickCallBack(_GameTickRunTime* timer) -> void { luaL_unref(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iParamIndex); } auto TimerCallBack(_GameTimer* timer) -> void { - LOG("excute timer: %d %d m_bRepeat: %d\n", timer->m_iLuaCallBackFn, - timer->m_iParamIndex, timer->m_bRepeat); + // LOG("excute timer: %d %d m_bRepeat: %d\n", timer->m_iLuaCallBackFn, + // timer->m_iParamIndex, timer->m_bRepeat); lua_rawgeti(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iLuaCallBackFn); lua_rawgeti(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iParamIndex); lua_pcall(timer->m_luaVm, 1, 0, 0); @@ -231,7 +231,9 @@ auto luaApi_GetPlayerWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo { ? _luaApi_WeaponType::kGun : _luaApi_WeaponType::kOther)); info.weaponIndex = weaponIndex; - //LOG("luaApi_GetPlayerWeaponInfo: %s %s %s %d \n", info.weaponName.c_str(), info.weaponBaseName.c_str(), checkWeaponName, weaponIndex); + // LOG("luaApi_GetPlayerWeaponInfo: %s %s %s %d \n", + // info.weaponName.c_str(), info.weaponBaseName.c_str(), + // checkWeaponName, weaponIndex); } while (false); }); return info; @@ -399,6 +401,9 @@ auto luaApi_GivePlayerWeapon(lua_State* luaVm) -> int { const auto weaponName = lua_tostring(luaVm, 2); auto isSuccess = false; ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) { + if (playerController->m_bPawnIsAlive() == false) { + return; + } isSuccess = GameWeapons::ParseWeaponCommand(playerController, weaponName); }); @@ -430,7 +435,8 @@ auto luApi_GetPlayerAllWeaponIndex(lua_State* luaVm) -> int { continue; } const auto activeWeapon = handle->Get(); - const auto attributeManager = activeWeapon->m_AttributeManager(); + const auto attributeManager = + activeWeapon->m_AttributeManager(); if (activeWeapon == nullptr) { break; } @@ -448,7 +454,8 @@ auto luApi_GetPlayerAllWeaponIndex(lua_State* luaVm) -> int { if (checkWeaponName == nullptr || strlen(checkWeaponName) < 1) { break; } - //printf("weapon name: %s \n", itemStaticData->GetSimpleWeaponName()); + // printf("weapon name: %s \n", + // itemStaticData->GetSimpleWeaponName()); const auto weaponIndex = weapon->GetRefEHandle().GetEntryIndex(); diff --git a/csgo2/script_callbacks.cpp b/csgo2/script_callbacks.cpp index a88e625..af3f14d 100644 --- a/csgo2/script_callbacks.cpp +++ b/csgo2/script_callbacks.cpp @@ -11,6 +11,8 @@ std::unordered_map callbackNameWithEnumMap{ {hash_32_fnv1a_const("player_death"), _CallbackNames::kOnPlayerDeath}, {hash_32_fnv1a_const("player_chat"), _CallbackNames::kOnPlayerSpeak}, {hash_32_fnv1a_const("player_spawn"), _CallbackNames::kOnPlayerSpawn}, + {hash_32_fnv1a_const("round_start"), _CallbackNames::kOnRoundStart}, + {hash_32_fnv1a_const("round_end"), _CallbackNames::kOnRoundEnd}, }; auto CallBackNameToEnum(const char* name) -> _CallbackNames { @@ -146,4 +148,37 @@ auto luaCall_onPlayerSpawn(int player) -> void { } }); } +auto luaCall_onRoundStart(int timeLimit) -> void { + ExcuteCallbackInAllLuaVm(_CallbackNames::kOnRoundStart, + [&](lua_State* luaVm, int refIndex) -> void { + lua_rawgeti(luaVm, LUA_REGISTRYINDEX, + refIndex); + if (lua_isfunction(luaVm, -1)) { + lua_pushinteger(luaVm, timeLimit); + if (lua_pcall(luaVm, 1, 0, 0) != LUA_OK) { + LOG("Error calling Lua callback: %s\n", + lua_tostring(luaVm, -1)); + lua_pop(luaVm, 1); + } + } + }); +} +auto luaCall_onRoundEnd(int winnerTeam, int reason, const char* message) + -> void { + ExcuteCallbackInAllLuaVm(_CallbackNames::kOnRoundEnd, + [&](lua_State* luaVm, int refIndex) -> void { + lua_rawgeti(luaVm, LUA_REGISTRYINDEX, + refIndex); + if (lua_isfunction(luaVm, -1)) { + lua_pushinteger(luaVm, winnerTeam); + lua_pushinteger(luaVm, reason); + lua_pushstring(luaVm, message); + if (lua_pcall(luaVm, 3, 0, 0) != LUA_OK) { + LOG("Error calling Lua callback: %s\n", + lua_tostring(luaVm, -1)); + lua_pop(luaVm, 1); + } + } + }); +} } // namespace ScriptCallBacks diff --git a/csgo2/script_callbacks.h b/csgo2/script_callbacks.h index 284a70d..518afa8 100644 --- a/csgo2/script_callbacks.h +++ b/csgo2/script_callbacks.h @@ -8,7 +8,9 @@ enum class _CallbackNames { kOnPlayerDisconnect, kOnPlayerDeath, kOnPlayerSpeak, - kOnPlayerSpawn + kOnPlayerSpawn, + kOnRoundStart, + kOnRoundEnd }; extern std::unordered_map> callbackList; @@ -24,4 +26,7 @@ auto luaCall_onPlayerDeath(int victim, int killer, bool isHeadShot) -> void; auto luaCall_onPlayerSpeak(int speaker, int chatType, std::string message) -> bool; auto luaCall_onPlayerSpawn(int player) -> void; +auto luaCall_onRoundStart(int timeLimit) -> void; +auto luaCall_onRoundEnd(int winnerTeam, int reason, const char* message) + -> void; } // namespace ScriptCallBacks diff --git a/csgo2/script_engine.cpp b/csgo2/script_engine.cpp index dcdeb5e..8174ad5 100644 --- a/csgo2/script_engine.cpp +++ b/csgo2/script_engine.cpp @@ -47,11 +47,14 @@ auto initLuaScripts() -> void { ScriptApis::initFunciton(L); pluginEnvs[dirName] = L; - + if (dirPath.starts_with("disable_")) { + continue; + } std::string file = dirPath + "\\main.lua"; if (std::filesystem::exists(file) == false) { continue; } + LOG("execute: %s\n", file.c_str()); std::string scriptDir = dirPath; @@ -87,8 +90,8 @@ auto reloadLuaScripts() -> void { initLuaScripts(); } auto Init() -> void { - // luaPath = Tools::GetExePath() + "\\huoji_scripts\\"; - luaPath = "F:\\source2\\huoji_scripts\\"; + luaPath = Tools::GetExePath() + "\\huoji_scripts\\"; + // luaPath = "F:\\source2\\huoji_scripts\\"; initLuaScripts(); } } // namespace ScriptEngine diff --git a/csgo2/sdk/convar/convar.cpp b/csgo2/sdk/convar/convar.cpp index 0e21f48..54d6962 100644 --- a/csgo2/sdk/convar/convar.cpp +++ b/csgo2/sdk/convar/convar.cpp @@ -1,5 +1,5 @@ #include "convar.hpp" - +#include "../../head.h" inline const char** CCommand::ArgV() const { return ArgC() ? (const char**)m_Args.Base() : NULL; } @@ -114,3 +114,64 @@ int DefaultCompletionFunc(const char* partial, CUtlVector& commands) { return 0; } + +//----------------------------------------------------------------------------- +// Statically constructed list of ConCommandBases, +// used for registering them with the ICVar interface +//----------------------------------------------------------------------------- +static int64 s_nCVarFlag = 0; +static bool s_bRegistered = false; + +class ConCommandRegList; +class ConCommandRegList +{ +public: + static void RegisterCommand(ConCommand* pCmd) + { + if (s_bConCommandsRegistered) + { + ConCommandHandle hndl = Offset::InterFaces::IVEngineCvar->RegisterConCommand(pCmd, s_nCVarFlag); + if (!hndl.IsValid()) + { + __debugbreak(); + } + + pCmd->SetHandle(hndl); + } + else + { + GetCommandRegList()->AddToTail(pCmd); + } + } + + static void RegisterAll() + { + if (!s_bConCommandsRegistered && Offset::InterFaces::IVEngineCvar) + { + s_bConCommandsRegistered = true; + + for (int i = 0; i < GetCommandRegList()->Count(); i++) + { + ConCommand* pCmd = GetCommandRegList()->Element(i); + ConCommandHandle hndl = Offset::InterFaces::IVEngineCvar->RegisterConCommand(pCmd, s_nCVarFlag); + pCmd->SetHandle(hndl); + + if (!hndl.IsValid()) + { + __debugbreak(); + + } + } + } + } +private: + + // GAMMACASE: Required to prevent static initialization order problem https://isocpp.org/wiki/faq/ctors#static-init-order + static CUtlVector* GetCommandRegList() + { + static CUtlVector s_ConCommandRegList; + return &s_ConCommandRegList; + } + + static bool s_bConCommandsRegistered; +}; diff --git a/csgo2/sdk/convar/convar.hpp b/csgo2/sdk/convar/convar.hpp index 2e90146..3d06bf6 100644 --- a/csgo2/sdk/convar/convar.hpp +++ b/csgo2/sdk/convar/convar.hpp @@ -1,25 +1,49 @@ #pragma once #include "../sdk.h" -struct characterset_t { - char set[256]; +class CCommandContext; +class ConCommandHandle; +class CCommand; +class ConCommandRefAbstract; +class ICommandCallback +{ +public: + virtual void CommandCallback(const CCommandContext& context, const CCommand& command) = 0; }; -class ConCommandBase { + +class ICommandCompletionCallback +{ +public: + virtual int CommandCompletionCallback(const char* pPartial, CUtlVector< CUtlString >& commands) = 0; +}; +//----------------------------------------------------------------------------- +// Called when a ConCommand needs to execute +//----------------------------------------------------------------------------- +typedef void (*FnCommandCallback_t)(const CCommandContext& context, const CCommand& command); +typedef void (*FnCommandCallbackNoContext_t)(const CCommand& command); +typedef void (*FnCommandCallbackVoid_t)(); +typedef int(*FnCommandCompletionCallback)(const char* partial, CUtlVector< CUtlString >& commands); + +//----------------------------------------------------------------------------- +// Purpose: The base console invoked command/cvar interface +//----------------------------------------------------------------------------- +class ConCommandBase +{ friend class CCvar; friend class ConCommand; - protected: +protected: ConCommandBase(void); +public: - public: ~ConCommandBase(void); // Check flag - bool IsFlagSet(int64_t flag) const; + bool IsFlagSet(int64 flag) const; // Set flag - void AddFlags(int64_t flags); + void AddFlags(int64 flags); // Clear flag - void RemoveFlags(int64_t flags); + void RemoveFlags(int64 flags); - int64_t GetFlags() const; + int64 GetFlags() const; // Return name of cvar const char* GetName(void) const; @@ -27,14 +51,127 @@ class ConCommandBase { // Return help text for cvar const char* GetHelpText(void) const; - private: +private: // Static data const char* m_pszName; const char* m_pszHelpString; // ConVar flags - int64_t m_nFlags; + int64 m_nFlags; }; +class ConCommandHandle +{ +public: + bool IsValid() { return value != kInvalidConCommandHandle; } + uint16 Get() { return value; } + void Set(uint16 _value) { value = _value; } + void Reset() { value = kInvalidConCommandHandle; } + + bool HasCallback() const; + void Dispatch(const CCommandContext& context, const CCommand& command); + + void Unregister(); + +private: + uint16_t value = kInvalidConCommandHandle; + +private: + static const uint16 kInvalidConCommandHandle = 0xFFFF; +}; + +class ConCommandRefAbstract +{ +public: + ConCommandHandle handle; +}; + + +//----------------------------------------------------------------------------- +// Purpose: The console invoked command +//----------------------------------------------------------------------------- +class ConCommand : public ConCommandBase +{ + friend class CCvar; + friend class ConCommandHandle; + +public: + typedef ConCommandBase BaseClass; + + ConCommand(ConCommandRefAbstract* pReferenceOut, const char* pName, FnCommandCallback_t callback, + const char* pHelpString = 0, int64 flags = 0, FnCommandCompletionCallback completionFunc = 0); + ConCommand(ConCommandRefAbstract* pReferenceOut, const char* pName, FnCommandCallbackVoid_t callback, + const char* pHelpString = 0, int64 flags = 0, FnCommandCompletionCallback completionFunc = 0); + ConCommand(ConCommandRefAbstract* pReferenceOut, const char* pName, FnCommandCallbackNoContext_t callback, + const char* pHelpString = 0, int64 flags = 0, FnCommandCompletionCallback completionFunc = 0); + ConCommand(ConCommandRefAbstract* pReferenceOut, const char* pName, ICommandCallback* pCallback, + const char* pHelpString = 0, int64 flags = 0, ICommandCompletionCallback* pCommandCompletionCallback = 0); + + ~ConCommand(void); + + // Used internally by OneTimeInit to initialize/shutdown + void Init(); + void Shutdown(); + + void Create(const char* pName, const char* pHelpString = 0, + int64 flags = 0); + + int AutoCompleteSuggest(const char* partial, CUtlVector< CUtlString >& commands); + + bool CanAutoComplete(void); + + inline ConCommandRefAbstract* GetRef(void) const + { + return m_pReference; + } + + inline void SetHandle(ConCommandHandle hndl) + { + m_pReference->handle = hndl; + } + +private: + // Call this function when executing the command + class CallbackInfo_t + { + public: + union { + FnCommandCallback_t m_fnCommandCallback; + FnCommandCallbackVoid_t m_fnVoidCommandCallback; + FnCommandCallbackNoContext_t m_fnContextlessCommandCallback; + ICommandCallback* m_pCommandCallback; + }; + + bool m_bUsingCommandCallbackInterface : 1; + bool m_bHasVoidCommandCallback : 1; + bool m_bHasContextlessCommandCallback : 1; + }; + + CallbackInfo_t m_Callback; + + // NOTE: To maintain backward compat, we have to be very careful: + // All public virtual methods must appear in the same order always + // since engine code will be calling into this code, which *does not match* + // in the mod code; it's using slightly different, but compatible versions + // of this class. Also: Be very careful about adding new fields to this class. + // Those fields will not exist in the version of this class that is instanced + // in mod code. + + union + { + FnCommandCompletionCallback m_fnCompletionCallback; + ICommandCompletionCallback* m_pCommandCompletionCallback; + }; + + bool m_bHasCompletionCallback : 1; + bool m_bUsingCommandCompletionInterface : 1; + + ConCommandRefAbstract* m_pReference; +}; + +struct characterset_t { + char set[256]; +}; + class CCommand { public: @@ -81,3 +218,116 @@ class CCommand { CUtlVectorFixedGrowable m_ArgvBuffer; CUtlVectorFixedGrowable m_Args; }; +struct CSplitScreenSlot +{ + CSplitScreenSlot(int index) + { + m_Data = index; + } + + int Get() const + { + return m_Data; + } + + int m_Data; +}; + +class ConVarHandle +{ +public: + bool IsValid() { return value != kInvalidConVarHandle; } + uint32 Get() { return value; } + void Set(uint32 _value) { value = _value; } + +private: + uint32 value = kInvalidConVarHandle; + +private: + static const uint32 kInvalidConVarHandle = 0xFFFFFFFF; +}; + + + +enum EConVarType : short +{ + EConVarType_Invalid = -1, + EConVarType_Bool, + EConVarType_Int16, + EConVarType_UInt16, + EConVarType_Int32, + EConVarType_UInt32, + EConVarType_Int64, + EConVarType_UInt64, + EConVarType_Float32, + EConVarType_Float64, + EConVarType_String, + EConVarType_Color, + EConVarType_Vector2, + EConVarType_Vector3, + EConVarType_Vector4, + EConVarType_Qangle +}; +class Vector; +union CVValue_t +{ + bool m_bValue; + short m_i16Value; + uint16 m_u16Value; + int m_i32Value; + uint m_u32Value; + int64 m_i64Value; + uint64 m_u64Value; + float m_flValue; + double m_dbValue; + const char* m_szValue; + Color m_clrValue; + Vector2D m_vec2Value; + Vector_SimPleSdk m_vec3Value; + Vector4D m_vec4Value; + Vector_SimPleSdk m_angValue; +}; + +//----------------------------------------------------------------------------- +// Purpose: A console variable +//----------------------------------------------------------------------------- +class ConVar +{ + friend class CCvar; + friend class ConVarRef; + friend class SplitScreenConVarRef; + +public: + const char* m_pszName; + CVValue_t* m_cvvDefaultValue; + CVValue_t* m_cvvMinValue; + CVValue_t* m_cvvMaxValue; + const char* m_pszHelpString; + EConVarType m_eVarType; + + // This gets copied from the ConVarDesc_t on creation + short unk1; + + unsigned int timesChanged; + int64 flags; + unsigned int callback_index; + + // Used when setting default, max, min values from the ConVarDesc_t + // although that's not the only place of usage + // flags seems to be: + // (1 << 0) Skip setting value to split screen slots and also something keyvalues related + // (1 << 1) Skip setting default value + // (1 << 2) Skip setting min/max values + int allocation_flag_of_some_sort; + + CVValue_t** values; +}; + +class ConVarRefAbstract +{ +public: + // High-speed method to read convar data + ConVarHandle m_Handle; + ConVar* m_pConVarState; +}; + diff --git a/csgo2/sdk/gameevent/IGameEvent.h b/csgo2/sdk/gameevent/IGameEvent.h index 2491c27..0a25ed4 100644 --- a/csgo2/sdk/gameevent/IGameEvent.h +++ b/csgo2/sdk/gameevent/IGameEvent.h @@ -6,146 +6,169 @@ #include "../interfaces/interfaces.h" class CMsgSource1LegacyGameEvent; class CUtlString; -class IToolGameEventAPI -{ - virtual void unk001(void*) = 0; +class IToolGameEventAPI { + virtual void unk001(void*) = 0; }; struct UnkGameEventStruct_t { - UnkGameEventStruct_t(const char* keyName) { - m_Unk = 0; - m_Key = keyName; - } + UnkGameEventStruct_t(const char* keyName) { + m_Unk = 0; + m_Key = keyName; + } - uint64_t m_Unk; - const char* m_Key; + uint64_t m_Unk; + const char* m_Key; }; -class IGameEvent -{ -public: - // 0 - virtual ~IGameEvent() {}; - virtual const char* GetName() const = 0; // get event name - virtual int GetID() const = 0; +class IGameEvent { + public: + // 0 + virtual ~IGameEvent(){}; + virtual const char* GetName() const = 0; // get event name + virtual int GetID() const = 0; - virtual bool IsReliable() const = 0; // if event handled reliable - 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 IsReliable() const = 0; // if event handled reliable + virtual bool IsLocal() const = 0; // if event is never networked + virtual bool IsEmpty( + const char* keyName = NULL) = 0; // check if data field exists - // Data access index 6 - virtual bool GetBool(UnkGameEventStruct_t* keyName = NULL, bool defaultValue = false) = 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 float GetFloat(const char* keyName = NULL, float defaultValue = 0.0f) = 0; - virtual const char* GetString(const char* keyName = NULL, const char* defaultValue = "") = 0; - virtual void* GetPtr(const char* keyName = NULL, void* defaultValue = NULL) = 0; + // Data access index 6 + virtual bool GetBool(UnkGameEventStruct_t* keyName = NULL, + bool defaultValue = false) = 0; + virtual int GetInt(UnkGameEventStruct_t* keyName = NULL, + int 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 const char* GetString(UnkGameEventStruct_t* keyName = NULL, + const char* defaultValue = "") = 0; + virtual void* GetPtr(const char* keyName = NULL, + void* defaultValue = NULL) = 0; - /* These function prototypes and names are very speculative and might be incorrect */ - virtual CEntityHandle GetEHandle(UnkGameEventStruct_t* keyName, CEntityHandle defaultValue) = 0; - virtual CEntityHandle GetStrictEHandle(UnkGameEventStruct_t* keyName, CEntityHandle defaultValue) = 0; - virtual CEntityHandle GetEHandle2(UnkGameEventStruct_t* keyName, CEntityHandle defaultValue) = 0; + /* These function prototypes and names are very speculative and might be + * incorrect */ + virtual CEntityHandle GetEHandle(UnkGameEventStruct_t* keyName, + CEntityHandle defaultValue) = 0; + virtual CEntityHandle GetStrictEHandle(UnkGameEventStruct_t* keyName, + CEntityHandle defaultValue) = 0; + virtual CEntityHandle GetEHandle2(UnkGameEventStruct_t* keyName, + CEntityHandle defaultValue) = 0; - virtual CPlayerSlot* GetPlayerSlot(UnkGameEventStruct_t* keyName = NULL) = 0; - virtual CBasePlayer* GetPlayer(UnkGameEventStruct_t* keyName = NULL) = 0; + virtual CPlayerSlot* GetPlayerSlot( + UnkGameEventStruct_t* keyName = NULL) = 0; + virtual CBasePlayer* GetPlayer(UnkGameEventStruct_t* keyName = NULL) = 0; - virtual void* GetPlayerPawn(UnkGameEventStruct_t* keyName = NULL) = 0; - virtual CEntityHandle GetPlayerControllerEHandle(UnkGameEventStruct_t* keyName = NULL) = 0; - virtual CEntityHandle GetPlayerControllerEHandle2(UnkGameEventStruct_t* keyName = NULL) = 0; - /* ============================================================ */ + virtual void* GetPlayerPawn(UnkGameEventStruct_t* keyName = NULL) = 0; + virtual CEntityHandle GetPlayerControllerEHandle( + UnkGameEventStruct_t* keyName = NULL) = 0; + virtual CEntityHandle GetPlayerControllerEHandle2( + UnkGameEventStruct_t* keyName = NULL) = 0; + /* ============================================================ */ - virtual void SetBool(const char* keyName, bool value) = 0; - virtual void SetInt(const char* keyName, int value) = 0; - virtual void SetUint64(const char* keyName, uint64_t value) = 0; - virtual void SetFloat(const char* keyName, float value) = 0; - virtual void SetString(const char* keyName, const char* value) = 0; - virtual void SetPtr(const char* keyName, void* value) = 0; + virtual void SetBool(const char* keyName, bool value) = 0; + virtual void SetInt(const char* keyName, int value) = 0; + virtual void SetUint64(const char* keyName, uint64_t value) = 0; + virtual void SetFloat(const char* keyName, float value) = 0; + virtual void SetString(const char* keyName, const char* value) = 0; + virtual void SetPtr(const char* keyName, void* value) = 0; - /* These function prototypes and names are very speculative and might be incorrect */ - virtual void SetEHandleStrict(const char* keyName, CEntityHandle handle) = 0; - virtual void SetEHandle(const char* keyName, CEntityHandle handle) = 0; + /* These function prototypes and names are very speculative and might be + * incorrect */ + virtual void SetEHandleStrict(const char* keyName, + CEntityHandle handle) = 0; + virtual void SetEHandle(const char* keyName, CEntityHandle handle) = 0; - // Also sets the _pawn key - virtual void SetPlayerSlot(const char* keyName, CPlayerSlot value) = 0; - virtual void SetPlayer(const char* keyName, CBasePlayer* value) = 0; - /* ============================================================ */ + // Also sets the _pawn key + virtual void SetPlayerSlot(const char* keyName, CPlayerSlot value) = 0; + virtual void SetPlayer(const char* keyName, CBasePlayer* value) = 0; + /* ============================================================ */ - virtual bool HasKey(const char* keyName) = 0; + virtual bool HasKey(const char* keyName) = 0; - // Something script vm related - virtual void unk001() = 0; + // Something script vm related + virtual void unk001() = 0; - //virtual KeyValues* GetDataKeys() const = 0; + // virtual KeyValues* GetDataKeys() const = 0; }; -class IGameEventListener2 -{ -public: - virtual ~IGameEventListener2(void) {}; +class IGameEventListener2 { + public: + virtual ~IGameEventListener2(void){}; - // FireEvent is called by EventManager if event just occured - // KeyValue memory will be freed by manager if not needed anymore - virtual void FireGameEvent(IGameEvent* event) = 0; + // FireEvent is called by EventManager if event just occured + // KeyValue memory will be freed by manager if not needed anymore + virtual void FireGameEvent(IGameEvent* event) = 0; }; -class IGameEventManager2 : public IBaseInterface, public IToolGameEventAPI -{ -public: - virtual ~IGameEventManager2(void) {}; +class IGameEventManager2 : public IBaseInterface, public IToolGameEventAPI { + public: + virtual ~IGameEventManager2(void){}; - // load game event descriptions from a file eg "resource\gameevents.res" - virtual int LoadEventsFromFile(const char* filename, bool bSearchAll) = 0; + // load game event descriptions from a file eg "resource\gameevents.res" + virtual int LoadEventsFromFile(const char* filename, bool bSearchAll) = 0; - // removes all and anything - virtual void Reset() = 0; + // removes all and anything + virtual void Reset() = 0; - // adds a listener for a particular event - virtual bool AddListener(IGameEventListener2* listener, const char* name, bool bServerSide) = 0; + // adds a listener for a particular event + virtual bool AddListener(IGameEventListener2* listener, const char* name, + bool bServerSide) = 0; - // returns true if this listener is listens to given event - virtual bool FindListener(IGameEventListener2* listener, const char* name) = 0; + // returns true if this listener is listens to given event + virtual bool FindListener(IGameEventListener2* listener, + const char* name) = 0; - // removes a listener - virtual void RemoveListener(IGameEventListener2* listener) = 0; + // removes a listener + virtual void RemoveListener(IGameEventListener2* listener) = 0; - // create an event by name, but doesn't fire it. returns NULL is event is not - // known or no listener is registered for it. bForce forces the creation even if no listener is active - virtual IGameEvent* CreateEvent(const char* name, bool bForce = false, int* pCookie = NULL) = 0; + // create an event by name, but doesn't fire it. returns NULL is event is + // not known or no listener is registered for it. bForce forces the creation + // even if no listener is active + virtual IGameEvent* CreateEvent(const char* name, bool bForce = false, + int* pCookie = NULL) = 0; - // fires a server event created earlier, if bDontBroadcast is set, event is not send to clients - virtual bool FireEvent(IGameEvent* event, bool bDontBroadcast = false) = 0; + // fires a server event created earlier, if bDontBroadcast is set, event is + // not send to clients + virtual bool FireEvent(IGameEvent* event, bool bDontBroadcast = false) = 0; - // fires an event for the local client only, should be used only by client code - virtual bool FireEventClientSide(IGameEvent* event) = 0; + // fires an event for the local client only, should be used only by client + // code + virtual bool FireEventClientSide(IGameEvent* event) = 0; - // create a new copy of this event, must be free later - virtual IGameEvent* DuplicateEvent(IGameEvent* event) = 0; + // create a new copy of this event, must be free later + virtual IGameEvent* DuplicateEvent(IGameEvent* event) = 0; - // if an event was created but not fired for some reason, it has to bee freed, same UnserializeEvent - virtual void FreeEvent(IGameEvent* event) = 0; + // if an event was created but not fired for some reason, it has to bee + // freed, same UnserializeEvent + virtual void FreeEvent(IGameEvent* event) = 0; - // write/read event to/from bitbuffer - virtual bool SerializeEvent(IGameEvent* event, CMsgSource1LegacyGameEvent* ev) = 0; - virtual IGameEvent* UnserializeEvent(const CMsgSource1LegacyGameEvent& ev) = 0; // create new KeyValues, must be deleted + // write/read event to/from bitbuffer + virtual bool SerializeEvent(IGameEvent* event, + CMsgSource1LegacyGameEvent* ev) = 0; + virtual IGameEvent* UnserializeEvent( + const CMsgSource1LegacyGameEvent& + ev) = 0; // create new KeyValues, must be deleted - virtual int LookupEventId(const char* name) = 0; + virtual int LookupEventId(const char* name) = 0; - virtual void PrintEventToString(IGameEvent* event, CUtlString& out) = 0; + virtual void PrintEventToString(IGameEvent* event, CUtlString& out) = 0; - virtual bool HasEventDescriptor(const char* name) = 0; + virtual bool HasEventDescriptor(const char* name) = 0; }; -class CGameEventManager : public IGameEventManager2 -{ -public: // IGameEventManager functions - virtual ~CGameEventManager() = 0; +class CGameEventManager : public IGameEventManager2 { + public: // IGameEventManager functions + virtual ~CGameEventManager() = 0; - virtual int LoadEventsFromFile(const char* filename) = 0; - virtual void Reset() = 0; + virtual int LoadEventsFromFile(const char* filename) = 0; + virtual void Reset() = 0; - virtual bool AddListener(IGameEventListener2* listener, const char* name, bool bServerSide) = 0; - virtual bool FindListener(IGameEventListener2* listener, const char* name) = 0; - virtual void RemoveListener(IGameEventListener2* listener) = 0; + virtual bool AddListener(IGameEventListener2* listener, const char* name, + bool bServerSide) = 0; + virtual bool FindListener(IGameEventListener2* listener, + const char* name) = 0; + virtual void RemoveListener(IGameEventListener2* listener) = 0; - virtual IGameEvent* CreateEvent(const char* name, bool bForce = false) = 0; - virtual IGameEvent* DuplicateEvent(IGameEvent* event) = 0; - virtual bool FireEvent(IGameEvent* event, bool bDontBroadcast = false) = 0; - virtual bool FireEventClientSide(IGameEvent* event) = 0; + virtual IGameEvent* CreateEvent(const char* name, bool bForce = false) = 0; + virtual IGameEvent* DuplicateEvent(IGameEvent* event) = 0; + virtual bool FireEvent(IGameEvent* event, bool bDontBroadcast = false) = 0; + virtual bool FireEventClientSide(IGameEvent* event) = 0; }; diff --git a/csgo2/sdk/public/Vector_Sdk.h b/csgo2/sdk/public/Vector_Sdk.h new file mode 100644 index 0000000..d097863 --- /dev/null +++ b/csgo2/sdk/public/Vector_Sdk.h @@ -0,0 +1,49 @@ +#pragma once +#include "../sdk.h" + +//cancer fix me +struct Vector_SimPleSdk +{ +public: + float x, y, z; + + Vector_SimPleSdk() + {} + + Vector_SimPleSdk(float x_, float y_, float z_) + { + x = x_; + y = y_; + z = z_; + } +}; +struct Vector2D +{ +public: + float x, y; + + Vector2D() + {} + + Vector2D(float x_, float y_) + { + x = x_; + y = y_; + } +}; +struct Vector4D +{ +public: + float x, y, z, c; + + Vector4D() + {} + + Vector4D(float x_, float y_, float z_, float c_) + { + x = x_; + y = y_; + z = z_; + c = c_; + } +}; \ No newline at end of file diff --git a/csgo2/sdk/public/color.h b/csgo2/sdk/public/color.h new file mode 100644 index 0000000..a60d599 --- /dev/null +++ b/csgo2/sdk/public/color.h @@ -0,0 +1,367 @@ +#pragma once +#include "../sdk.h" + +class Color +{ +public: + Color() + { + *((int*)this) = 0; + } + + Color(int color32) + { + *((int*)this) = color32; + } + + Color(int _r, int _g, int _b) + { + SetColor(_r, _g, _b, 255); + } + + Color(int _r, int _g, int _b, int _a) + { + SetColor(_r, _g, _b, _a); + } + + void SetColor(int _r, int _g, int _b, int _a = 255) + { + _color[0] = (unsigned char)_r; + _color[1] = (unsigned char)_g; + _color[2] = (unsigned char)_b; + _color[3] = (unsigned char)_a; + } + + void GetColor(int& _r, int& _g, int& _b, int& _a) const + { + _r = _color[0]; + _g = _color[1]; + _b = _color[2]; + _a = _color[3]; + } + + void SetRawColor(int color32) + { + *((int*)this) = color32; + } + + int GetRawColor() const + { + return *((int*)this); + } + + int GetD3DColor() const + { + return ((int)((((_color[3]) & 0xff) << 24) | (((_color[0]) & 0xff) << 16) | (((_color[1]) & 0xff) << 8) | ((_color[2]) & 0xff))); + } + + inline int r() const + { + return _color[0]; + } + + inline int g() const + { + return _color[1]; + } + + inline int b() const + { + return _color[2]; + } + + inline int a() const + { + return _color[3]; + } + + inline float rBase() const + { + return _color[0] / 255.0f; + } + + inline float gBase() const + { + return _color[1] / 255.0f; + } + + inline float bBase() const + { + return _color[2] / 255.0f; + } + + inline float aBase() const + { + return _color[3] / 255.0f; + } + + unsigned char& operator[](int index) + { + return _color[index]; + } + + const unsigned char& operator[](int index) const + { + return _color[index]; + } + + bool operator ==(const Color& rhs) const + { + return (*((int*)this) == *((int*)&rhs)); + } + + bool operator !=(const Color& rhs) const + { + return !(operator==(rhs)); + } + + Color& operator=(const Color& rhs) + { + SetRawColor(rhs.GetRawColor()); + return *this; + } + + float* Base() + { + float clr[3]; + + clr[0] = _color[0] / 255.0f; + clr[1] = _color[1] / 255.0f; + clr[2] = _color[2] / 255.0f; + + return &clr[0]; + } + + float* BaseAlpha() + { + float clr[4]; + + clr[0] = _color[0] / 255.0f; + clr[1] = _color[1] / 255.0f; + clr[2] = _color[2] / 255.0f; + clr[3] = _color[3] / 255.0f; + + return &clr[0]; + } + + float Hue() const + { + if (_color[0] == _color[1] && _color[1] == _color[2]) + { + return 0.0f; + } + + float r = _color[0] / 255.0f; + float g = _color[1] / 255.0f; + float b = _color[2] / 255.0f; + + float max = r > g ? r : g > b ? g : b, + min = r < g ? r : g < b ? g : b; + float delta = max - min; + float hue = 0.0f; + + if (r == max) + { + hue = (g - b) / delta; + } + else if (g == max) + { + hue = 2 + (b - r) / delta; + } + else if (b == max) + { + hue = 4 + (r - g) / delta; + } + hue *= 60; + + if (hue < 0.0f) + { + hue += 360.0f; + } + return hue; + } + + float Saturation() const + { + float r = _color[0] / 255.0f; + float g = _color[1] / 255.0f; + float b = _color[2] / 255.0f; + + float max = r > g ? r : g > b ? g : b, + min = r < g ? r : g < b ? g : b; + float l, s = 0; + + if (max != min) + { + l = (max + min) / 2; + if (l <= 0.5f) + s = (max - min) / (max + min); + else + s = (max - min) / (2 - max - min); + } + return s; + } + + float Brightness() const + { + float r = _color[0] / 255.0f; + float g = _color[1] / 255.0f; + float b = _color[2] / 255.0f; + + float max = r > g ? r : g > b ? g : b, + min = r < g ? r : g < b ? g : b; + return (max + min) / 2; + } + + static Color FromHSB(float hue, float saturation, float brightness) + { + float h = hue == 1.0f ? 0 : hue * 6.0f; + float f = h - (int)h; + float p = brightness * (1.0f - saturation); + float q = brightness * (1.0f - saturation * f); + float t = brightness * (1.0f - (saturation * (1.0f - f))); + + if (h < 1) + { + return Color( + (unsigned char)(brightness * 255), + (unsigned char)(t * 255), + (unsigned char)(p * 255) + ); + } + else if (h < 2) + { + return Color( + (unsigned char)(q * 255), + (unsigned char)(brightness * 255), + (unsigned char)(p * 255) + ); + } + else if (h < 3) + { + return Color( + (unsigned char)(p * 255), + (unsigned char)(brightness * 255), + (unsigned char)(t * 255) + ); + } + else if (h < 4) + { + return Color( + (unsigned char)(p * 255), + (unsigned char)(q * 255), + (unsigned char)(brightness * 255) + ); + } + else if (h < 5) + { + return Color( + (unsigned char)(t * 255), + (unsigned char)(p * 255), + (unsigned char)(brightness * 255) + ); + } + else + { + return Color( + (unsigned char)(brightness * 255), + (unsigned char)(p * 255), + (unsigned char)(q * 255) + ); + } + } + + static Color Red() + { + return Color(255, 0, 0); + } + + static Color Green() + { + return Color(0, 255, 0); + } + + static Color Blue() + { + return Color(0, 0, 255); + } + + static Color LightBlue() + { + return Color(100, 100, 255); + } + + static Color Grey() + { + return Color(128, 128, 128); + } + + static Color DarkGrey() + { + return Color(45, 45, 45); + } + + static Color Black() + { + return Color(0, 0, 0); + } + + static Color White() + { + return Color(255, 255, 255); + } + + static Color Purple() + { + return Color(220, 0, 220); + } + + //Menu + static Color Background() + { + return Color(55, 55, 55); + } + + static Color FrameBorder() + { + return Color(80, 80, 80); + } + + static Color MainText() + { + return Color(230, 230, 230); + } + + static Color HeaderText() + { + return Color(49, 124, 230); + } + + static Color CurrentTab() + { + return Color(55, 55, 55); + } + + static Color Tabs() + { + return Color(23, 23, 23); + } + + static Color Highlight() + { + return Color(49, 124, 230); + } + + static Color ElementBorder() + { + return Color(0, 0, 0); + } + + static Color SliderScroll() + { + return Color(78, 143, 230); + } + +private: + unsigned char _color[4]; +}; diff --git a/csgo2/sdk/public/eiface.h b/csgo2/sdk/public/eiface.h index 0296e55..afc5bb7 100644 --- a/csgo2/sdk/public/eiface.h +++ b/csgo2/sdk/public/eiface.h @@ -127,7 +127,36 @@ inline CGlobalVars::CGlobalVars() : } class CSharedEdictChangeInfo; class IAchievementMgr; -class CCommandContext; +enum CommandTarget_t +{ + CT_NO_TARGET = -1, + CT_FIRST_SPLITSCREEN_CLIENT = 0, + CT_LAST_SPLITSCREEN_CLIENT = 3, +}; + +class CCommandContext +{ +public: + CCommandContext(CommandTarget_t nTarget, CPlayerSlot nSlot) : + m_nTarget(nTarget), m_nPlayerSlot(nSlot) + { + } + + CommandTarget_t GetTarget() const + { + return m_nTarget; + } + + CPlayerSlot GetPlayerSlot() const + { + return m_nPlayerSlot; + } + +private: + CommandTarget_t m_nTarget; + CPlayerSlot m_nPlayerSlot; +}; + class EconControlPointInfo_t; struct EconItemInfo_t { diff --git a/csgo2/sdk/public/icvar.h b/csgo2/sdk/public/icvar.h new file mode 100644 index 0000000..1f3467d --- /dev/null +++ b/csgo2/sdk/public/icvar.h @@ -0,0 +1,84 @@ +#pragma once +#include "../sdk.h" + +class ConCommandBase; + +class ConVar; +class Color; +class IConVarListener; +class CConVarDetail; +struct ConVarSnapshot_t; +union CVValue_t; +class KeyValues; +class ConVarRefAbstract; +class ConVarHandle; +struct CSplitScreenSlot; +class ConCommandHandle; +class ConCommand; +typedef void(*FnChangeCallbackGlobal_t)(ConVarRefAbstract* cvar, CSplitScreenSlot nSlot, const char* pNewValue, const char* pOldValue); +typedef void(*FnChangeCallback_t)(ConVarRefAbstract* cvar, CSplitScreenSlot nSlot, CVValue_t* pNewValue, CVValue_t* pOldValue); +class ConCommandRefAbstract; +class ConVarRefAbstract; +class ICVarListenerCallbacks +{ +public: + virtual void OnConVarCreated(ConVarRefAbstract* pNewCvar) = 0; + virtual void OnConCommandCreated(ConCommandRefAbstract* pNewCommand) = 0; +}; + +//----------------------------------------------------------------------------- +// Purpose: DLL interface to ConVars/ConCommands +//----------------------------------------------------------------------------- +class ICvar : public IAppSystem +{ +public: + // bAllowDeveloper - Allows finding convars with FCVAR_DEVELOPMENTONLY flag + virtual ConVarHandle FindConVar(const char* name, bool bAllowDeveloper = false) = 0; + virtual ConVarHandle FindFirstConVar() = 0; + virtual ConVarHandle FindNextConVar(ConVarHandle prev) = 0; + virtual void SetConVarValue(ConVarHandle cvarid, CSplitScreenSlot nSlot, CVValue_t* pNewValue, CVValue_t* pOldValue) = 0; + + virtual ConCommandHandle FindCommand(const char* name) = 0; + virtual ConCommandHandle FindFirstCommand() = 0; + virtual ConCommandHandle FindNextCommand(ConCommandHandle prev) = 0; + virtual void DispatchConCommand(ConCommandHandle cmd, const CCommandContext& ctx, const CCommand& args) = 0; + + // Install a global change callback (to be called when any convar changes) + virtual void InstallGlobalChangeCallback(FnChangeCallbackGlobal_t callback) = 0; + virtual void RemoveGlobalChangeCallback(FnChangeCallbackGlobal_t callback) = 0; + virtual void CallGlobalChangeCallbacks(ConVarRefAbstract* var, CSplitScreenSlot nSlot, const char* pOldString, float flOldValue) = 0; + + // Reverts cvars which contain a specific flag + virtual void RevertFlaggedConVars(int nFlag) = 0; + + virtual void SetMaxSplitScreenSlots(int nSlots) = 0; + virtual int GetMaxSplitScreenSlots() const = 0; + + virtual void RegisterCreationListeners(ICVarListenerCallbacks* callbacks) = 0; + virtual void RemoveCreationListeners(ICVarListenerCallbacks* callbacks) = 0; + + virtual void unk1() = 0; + + virtual void ResetConVarsToDefaultValues(const char* pszPrefix) = 0; + + virtual ConVarSnapshot_t* TakeConVarSnapshot(void) = 0; + virtual void ResetConVarsToSnapshot(ConVarSnapshot_t* pSnapshot) = 0; + virtual void DestroyConVarSnapshot(ConVarSnapshot_t* pSnaoshot) = 0; + + virtual characterset_t GetCharacterSet(void) = 0; + virtual void SetConVarsFromGameInfo(KeyValues* pKV) = 0; + + virtual void unk2() = 0; + + // Register, unregister vars + virtual void RegisterConVar(ConVar* pConVar, int64 nAdditionalFlags, ConVarHandle& pCvarRef, ConVar& pCvar) = 0; + virtual void UnregisterConVar(ConVarHandle handle) = 0; + virtual ConVar* GetConVar(ConVarHandle handle) = 0; + + // Register, unregister commands + virtual ConCommandHandle RegisterConCommand(ConCommand* pCmd, int64 nAdditionalFlags = 0) = 0; + virtual void UnregisterConCommand(ConCommandHandle handle) = 0; + virtual ConCommand* GetCommand(ConCommandHandle handle) = 0; + + virtual void QueueThreadSetValue(ConVarRefAbstract* ref, CSplitScreenSlot nSlot, CVValue_t* value) = 0; +}; \ No newline at end of file diff --git a/csgo2/sdk/sdk.h b/csgo2/sdk/sdk.h index b3bbd01..1b2f594 100644 --- a/csgo2/sdk/sdk.h +++ b/csgo2/sdk/sdk.h @@ -16,6 +16,7 @@ #define INCORRECT_PATH_SEPARATOR '/' #define INCORRECT_PATH_SEPARATOR_S "/" #define FMTFUNCTION(a, b) + enum EStringConvertErrorPolicy { _STRINGCONVERTFLAG_SKIP = 1, _STRINGCONVERTFLAG_FAIL = 2, @@ -79,6 +80,10 @@ inline T AlignValue(T val, uintptr_t alignment) { return (T)(((uintptr_t)val + alignment - 1) & ~(alignment - 1)); } + +#include "public/Vector_Sdk.h" +#include "public/color.h" + #include "player/playerslot.h" #include "public/mathlib.h" @@ -103,7 +108,7 @@ inline T AlignValue(T val, uintptr_t alignment) { #include "interfaces/interfaces.h" #include "gameevent/IGameEvent.h" #include "convar/convar.hpp" - +#include "public/icvar.h" #include "gameevent/IGameEvent.h" #include "tier1/bufferstring.h" #include "public/eiface.h" diff --git a/csgo2/version_hijack.cpp b/csgo2/version_hijack.cpp new file mode 100644 index 0000000..d8af13c --- /dev/null +++ b/csgo2/version_hijack.cpp @@ -0,0 +1,187 @@ + +// +// created by AheadLib +// github:https://github.com/strivexjun/AheadLib-x86-x64 +// + +#include +#include + +#pragma comment( lib, "Shlwapi.lib") + +#pragma comment(linker, "/EXPORT:GetFileVersionInfoA=AheadLib_GetFileVersionInfoA,@1") +#pragma comment(linker, "/EXPORT:GetFileVersionInfoByHandle=AheadLib_GetFileVersionInfoByHandle,@2") +#pragma comment(linker, "/EXPORT:GetFileVersionInfoExA=AheadLib_GetFileVersionInfoExA,@3") +#pragma comment(linker, "/EXPORT:GetFileVersionInfoExW=AheadLib_GetFileVersionInfoExW,@4") +#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeA=AheadLib_GetFileVersionInfoSizeA,@5") +#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeExA=AheadLib_GetFileVersionInfoSizeExA,@6") +#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeExW=AheadLib_GetFileVersionInfoSizeExW,@7") +#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeW=AheadLib_GetFileVersionInfoSizeW,@8") +#pragma comment(linker, "/EXPORT:GetFileVersionInfoW=AheadLib_GetFileVersionInfoW,@9") +#pragma comment(linker, "/EXPORT:VerFindFileA=AheadLib_VerFindFileA,@10") +#pragma comment(linker, "/EXPORT:VerFindFileW=AheadLib_VerFindFileW,@11") +#pragma comment(linker, "/EXPORT:VerInstallFileA=AheadLib_VerInstallFileA,@12") +#pragma comment(linker, "/EXPORT:VerInstallFileW=AheadLib_VerInstallFileW,@13") +#pragma comment(linker, "/EXPORT:VerLanguageNameA=KERNEL32.VerLanguageNameA,@14") +#pragma comment(linker, "/EXPORT:VerLanguageNameW=KERNEL32.VerLanguageNameW,@15") +#pragma comment(linker, "/EXPORT:VerQueryValueA=AheadLib_VerQueryValueA,@16") +#pragma comment(linker, "/EXPORT:VerQueryValueW=AheadLib_VerQueryValueW,@17") + + +extern "C" +{ +PVOID pfnAheadLib_GetFileVersionInfoA; +PVOID pfnAheadLib_GetFileVersionInfoByHandle; +PVOID pfnAheadLib_GetFileVersionInfoExA; +PVOID pfnAheadLib_GetFileVersionInfoExW; +PVOID pfnAheadLib_GetFileVersionInfoSizeA; +PVOID pfnAheadLib_GetFileVersionInfoSizeExA; +PVOID pfnAheadLib_GetFileVersionInfoSizeExW; +PVOID pfnAheadLib_GetFileVersionInfoSizeW; +PVOID pfnAheadLib_GetFileVersionInfoW; +PVOID pfnAheadLib_VerFindFileA; +PVOID pfnAheadLib_VerFindFileW; +PVOID pfnAheadLib_VerInstallFileA; +PVOID pfnAheadLib_VerInstallFileW; +PVOID pfnAheadLib_VerQueryValueA; +PVOID pfnAheadLib_VerQueryValueW; +} + + +static +HMODULE g_OldModule = NULL; + +VOID WINAPI Free() +{ + if (g_OldModule) + { + FreeLibrary(g_OldModule); + } +} + + +BOOL WINAPI Load() +{ + TCHAR tzPath[MAX_PATH]; + TCHAR tzTemp[MAX_PATH * 2]; + + // + // ǷϵͳĿ¼ǰĿ¼ԭʼDLL + // + //GetModuleFileName(NULL,tzPath,MAX_PATH); //ȡĿ¼µ + //PathRemoveFileSpec(tzPath); + + GetSystemDirectory(tzPath, MAX_PATH); //ĬϻȡϵͳĿ¼ + + lstrcat(tzPath, TEXT("\\version.dll")); + + g_OldModule = LoadLibrary(tzPath); + if (g_OldModule == NULL) + { + wsprintf(tzTemp, TEXT("޷ҵģ %s,޷"), tzPath); + MessageBox(NULL, tzTemp, TEXT("AheadLib"), MB_ICONSTOP); + } + + return (g_OldModule != NULL); + +} + + +FARPROC WINAPI GetAddress(PCSTR pszProcName) +{ + FARPROC fpAddress; + CHAR szProcName[64]; + TCHAR tzTemp[MAX_PATH]; + + fpAddress = GetProcAddress(g_OldModule, pszProcName); + if (fpAddress == NULL) + { + if (HIWORD(pszProcName) == 0) + { + wsprintfA(szProcName, "#%d", pszProcName); + pszProcName = szProcName; + } + + wsprintf(tzTemp, TEXT("޷ҵ %hs,޷"), pszProcName); + MessageBox(NULL, tzTemp, TEXT("AheadLib"), MB_ICONSTOP); + ExitProcess(-2); + } + return fpAddress; +} + +BOOL WINAPI Init() +{ + pfnAheadLib_GetFileVersionInfoA = GetAddress("GetFileVersionInfoA"); + pfnAheadLib_GetFileVersionInfoByHandle = GetAddress("GetFileVersionInfoByHandle"); + pfnAheadLib_GetFileVersionInfoExA = GetAddress("GetFileVersionInfoExA"); + pfnAheadLib_GetFileVersionInfoExW = GetAddress("GetFileVersionInfoExW"); + pfnAheadLib_GetFileVersionInfoSizeA = GetAddress("GetFileVersionInfoSizeA"); + pfnAheadLib_GetFileVersionInfoSizeExA = GetAddress("GetFileVersionInfoSizeExA"); + pfnAheadLib_GetFileVersionInfoSizeExW = GetAddress("GetFileVersionInfoSizeExW"); + pfnAheadLib_GetFileVersionInfoSizeW = GetAddress("GetFileVersionInfoSizeW"); + pfnAheadLib_GetFileVersionInfoW = GetAddress("GetFileVersionInfoW"); + pfnAheadLib_VerFindFileA = GetAddress("VerFindFileA"); + pfnAheadLib_VerFindFileW = GetAddress("VerFindFileW"); + pfnAheadLib_VerInstallFileA = GetAddress("VerInstallFileA"); + pfnAheadLib_VerInstallFileW = GetAddress("VerInstallFileW"); + pfnAheadLib_VerQueryValueA = GetAddress("VerQueryValueA"); + pfnAheadLib_VerQueryValueW = GetAddress("VerQueryValueW"); + return TRUE; +} + +DWORD WINAPI ThreadProc(LPVOID lpThreadParameter) +{ + HANDLE hProcess; + + PVOID addr1 = reinterpret_cast(0x00401000); + BYTE data1[] = { 0x90, 0x90, 0x90, 0x90 }; + + // + // ƹVMP3.x ڴ汣 + // + hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, GetCurrentProcessId()); + if (hProcess) + { + WriteProcessMemory(hProcess, addr1, data1, sizeof(data1), NULL); + + CloseHandle(hProcess); + } + + return 0; +} + + +BOOL APIENTRY VersionHijack_DllMain(HMODULE hModule, DWORD dwReason, PVOID pvReserved) +{ + if (dwReason == DLL_PROCESS_ATTACH) + { + DisableThreadLibraryCalls(hModule); + + if (Load() && Init()) + { + TCHAR szAppName[MAX_PATH] = TEXT("cs2.exe");//޸ + TCHAR szCurName[MAX_PATH]; + + GetModuleFileName(NULL, szCurName, MAX_PATH); + PathStripPath(szCurName); + + //Ƿж + if (StrCmpI(szCurName, szAppName) == 0) + { + //̻߳ + HANDLE hThread = CreateThread(NULL, NULL, ThreadProc, NULL, NULL, NULL); + if (hThread) + { + CloseHandle(hThread); + } + } + } + } + else if (dwReason == DLL_PROCESS_DETACH) + { + Free(); + } + + return TRUE; +} + diff --git a/csgo2/version_jump.asm b/csgo2/version_jump.asm new file mode 100644 index 0000000..9db347d --- /dev/null +++ b/csgo2/version_jump.asm @@ -0,0 +1,97 @@ + +; +; created by AheadLib +; github:https://github.com/strivexjun/AheadLib-x86-x64 +; +; .asm ļӵһ +; Ҽļ--- +; :Զɹ +; ų: + +; Ȼ +; : ml64 /Fo $(IntDir)%(fileName).obj /c /Cp %(fileName).asm +; : $(IntDir)%(fileName).obj;%(Outputs) +; Ӷ: +; + + +.DATA +EXTERN pfnAheadLib_GetFileVersionInfoA:dq; +EXTERN pfnAheadLib_GetFileVersionInfoByHandle:dq; +EXTERN pfnAheadLib_GetFileVersionInfoExA:dq; +EXTERN pfnAheadLib_GetFileVersionInfoExW:dq; +EXTERN pfnAheadLib_GetFileVersionInfoSizeA:dq; +EXTERN pfnAheadLib_GetFileVersionInfoSizeExA:dq; +EXTERN pfnAheadLib_GetFileVersionInfoSizeExW:dq; +EXTERN pfnAheadLib_GetFileVersionInfoSizeW:dq; +EXTERN pfnAheadLib_GetFileVersionInfoW:dq; +EXTERN pfnAheadLib_VerFindFileA:dq; +EXTERN pfnAheadLib_VerFindFileW:dq; +EXTERN pfnAheadLib_VerInstallFileA:dq; +EXTERN pfnAheadLib_VerInstallFileW:dq; +EXTERN pfnAheadLib_VerQueryValueA:dq; +EXTERN pfnAheadLib_VerQueryValueW:dq; + +.CODE +AheadLib_GetFileVersionInfoA PROC + jmp pfnAheadLib_GetFileVersionInfoA +AheadLib_GetFileVersionInfoA ENDP + +AheadLib_GetFileVersionInfoByHandle PROC + jmp pfnAheadLib_GetFileVersionInfoByHandle +AheadLib_GetFileVersionInfoByHandle ENDP + +AheadLib_GetFileVersionInfoExA PROC + jmp pfnAheadLib_GetFileVersionInfoExA +AheadLib_GetFileVersionInfoExA ENDP + +AheadLib_GetFileVersionInfoExW PROC + jmp pfnAheadLib_GetFileVersionInfoExW +AheadLib_GetFileVersionInfoExW ENDP + +AheadLib_GetFileVersionInfoSizeA PROC + jmp pfnAheadLib_GetFileVersionInfoSizeA +AheadLib_GetFileVersionInfoSizeA ENDP + +AheadLib_GetFileVersionInfoSizeExA PROC + jmp pfnAheadLib_GetFileVersionInfoSizeExA +AheadLib_GetFileVersionInfoSizeExA ENDP + +AheadLib_GetFileVersionInfoSizeExW PROC + jmp pfnAheadLib_GetFileVersionInfoSizeExW +AheadLib_GetFileVersionInfoSizeExW ENDP + +AheadLib_GetFileVersionInfoSizeW PROC + jmp pfnAheadLib_GetFileVersionInfoSizeW +AheadLib_GetFileVersionInfoSizeW ENDP + +AheadLib_GetFileVersionInfoW PROC + jmp pfnAheadLib_GetFileVersionInfoW +AheadLib_GetFileVersionInfoW ENDP + +AheadLib_VerFindFileA PROC + jmp pfnAheadLib_VerFindFileA +AheadLib_VerFindFileA ENDP + +AheadLib_VerFindFileW PROC + jmp pfnAheadLib_VerFindFileW +AheadLib_VerFindFileW ENDP + +AheadLib_VerInstallFileA PROC + jmp pfnAheadLib_VerInstallFileA +AheadLib_VerInstallFileA ENDP + +AheadLib_VerInstallFileW PROC + jmp pfnAheadLib_VerInstallFileW +AheadLib_VerInstallFileW ENDP + +AheadLib_VerQueryValueA PROC + jmp pfnAheadLib_VerQueryValueA +AheadLib_VerQueryValueA ENDP + +AheadLib_VerQueryValueW PROC + jmp pfnAheadLib_VerQueryValueW +AheadLib_VerQueryValueW ENDP + + +END diff --git a/loader/loader.sln b/loader/loader.sln new file mode 100644 index 0000000..ebf7977 --- /dev/null +++ b/loader/loader.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33130.400 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loader", "loader\loader.vcxproj", "{5B7C31B7-436F-403A-B1FE-D5C44227C6A8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5B7C31B7-436F-403A-B1FE-D5C44227C6A8}.Debug|x64.ActiveCfg = Debug|x64 + {5B7C31B7-436F-403A-B1FE-D5C44227C6A8}.Debug|x64.Build.0 = Debug|x64 + {5B7C31B7-436F-403A-B1FE-D5C44227C6A8}.Debug|x86.ActiveCfg = Debug|Win32 + {5B7C31B7-436F-403A-B1FE-D5C44227C6A8}.Debug|x86.Build.0 = Debug|Win32 + {5B7C31B7-436F-403A-B1FE-D5C44227C6A8}.Release|x64.ActiveCfg = Release|x64 + {5B7C31B7-436F-403A-B1FE-D5C44227C6A8}.Release|x64.Build.0 = Release|x64 + {5B7C31B7-436F-403A-B1FE-D5C44227C6A8}.Release|x86.ActiveCfg = Release|Win32 + {5B7C31B7-436F-403A-B1FE-D5C44227C6A8}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0EE46AF2-88B0-404B-A6B5-777E97DF934D} + EndGlobalSection +EndGlobal diff --git a/loader/loader/loader.cpp b/loader/loader/loader.cpp new file mode 100644 index 0000000..77219dd --- /dev/null +++ b/loader/loader/loader.cpp @@ -0,0 +1,56 @@ +// loader.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 + +#include +#include +#include +#include + +// 读取INI文件 +std::pair readConfig() { + char path[255], command[255]; + + GetPrivateProfileStringA("server", "path", "", path, 255, ".\\config.ini"); + GetPrivateProfileStringA("server", "command", "", command, 255, ".\\config.ini"); + + return { std::string(path), std::string(command) }; +} + +// 创建进程 +PROCESS_INFORMATION createProcess(const std::string& path, const std::string& command) { + STARTUPINFOA si; + PROCESS_INFORMATION pi; + + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + ZeroMemory(&pi, sizeof(pi)); + + // 注意:CreateProcessW需要宽字符,如果你的项目是使用多字节字符集,需要转换 + if (!CreateProcessA(path.c_str(), const_cast(command.c_str()), NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) { + std::cerr << "CreateProcess failed (" << GetLastError() << ").\n"; + } + + return pi; +} + +// 加载DLL +void loadDll(PROCESS_INFORMATION pi) { + LPVOID addr = (LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA"); + LPVOID arg = (LPVOID)VirtualAllocEx(pi.hProcess, NULL, strlen("csgo2.dll") + 1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + + WriteProcessMemory(pi.hProcess, arg, "csgo2.dll", strlen("csgo2.dll") + 1, NULL); + HANDLE hThread = CreateRemoteThread(pi.hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)addr, arg, 0, NULL); + + if (hThread == NULL) { + std::cerr << "CreateRemoteThread failed (" << GetLastError() << ").\n"; + } + + ResumeThread(pi.hThread); +} + +int main() { + auto [path, command] = readConfig(); + PROCESS_INFORMATION pi = createProcess(path, command); + loadDll(pi); + + return 0; +} \ No newline at end of file diff --git a/loader/loader/loader.vcxproj b/loader/loader/loader.vcxproj new file mode 100644 index 0000000..8cc1ffb --- /dev/null +++ b/loader/loader/loader.vcxproj @@ -0,0 +1,149 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {5b7c31b7-436f-403a-b1fe-d5c44227c6a8} + loader + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpplatest + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpplatest + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/loader/loader/loader.vcxproj.filters b/loader/loader/loader.vcxproj.filters new file mode 100644 index 0000000..fdfc1cb --- /dev/null +++ b/loader/loader/loader.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file