├── cs2-sdk ├── pch │ ├── pch.cpp │ └── pch.hpp ├── src │ ├── vars │ │ └── vars.cpp │ ├── cache │ │ ├── entities │ │ │ ├── hen.cpp │ │ │ ├── gun.cpp │ │ │ ├── captive.cpp │ │ │ ├── base.cpp │ │ │ └── player.cpp │ │ └── cache.cpp │ ├── renderer │ │ └── renderer.cpp │ ├── virtual │ │ └── virtual.cpp │ ├── hooks │ │ ├── input │ │ │ ├── input_hooks.cpp │ │ │ ├── sdl │ │ │ │ └── sdl_hooks.cpp │ │ │ └── wndproc │ │ │ │ └── wndproc_hooks.cpp │ │ ├── render │ │ │ ├── render_hooks.cpp │ │ │ └── directx11 │ │ │ │ └── directx11_hooks.cpp │ │ ├── hooks.cpp │ │ └── game │ │ │ └── game_hooks.cpp │ ├── logger │ │ └── logger.cpp │ ├── math │ │ ├── types │ │ │ └── transform.cpp │ │ └── math.cpp │ ├── entry.cpp │ ├── hacks │ │ └── esp │ │ │ └── esp.cpp │ ├── schemamgr │ │ └── schema_manager.cpp │ ├── instance │ │ └── instance.cpp │ ├── memory │ │ └── memory.cpp │ ├── sigscan │ │ └── sigscan.cpp │ ├── menu │ │ └── menu.cpp │ └── signatures │ │ └── signatures.cpp ├── libs │ ├── distorm │ │ └── src │ │ │ ├── prefix.c │ │ │ ├── decoder.h │ │ │ ├── operands.h │ │ │ ├── wstring.h │ │ │ ├── textdefs.h │ │ │ ├── insts.h │ │ │ ├── x86defs.h │ │ │ ├── textdefs.c │ │ │ ├── prefix.h │ │ │ └── config.h │ ├── imgui │ │ ├── imgui_impl_dx11.h │ │ ├── imgui_impl_sdl3.h │ │ └── imgui_impl_win32.h │ └── funchook │ │ ├── src │ │ ├── funchook_x86.h │ │ ├── disasm.h │ │ ├── funchook_internal.h │ │ └── disasm_distorm.c │ │ └── include │ │ └── funchook.h ├── include │ ├── math │ │ ├── types │ │ │ ├── quaternion.hpp │ │ │ ├── vmatrix.hpp │ │ │ ├── matrix3x4.hpp │ │ │ ├── transform.hpp │ │ │ ├── bbox.hpp │ │ │ └── vector.hpp │ │ └── math.hpp │ ├── hooks │ │ ├── game │ │ │ └── game_hooks.hpp │ │ ├── input │ │ │ ├── sdl │ │ │ │ └── sdl_hooks.hpp │ │ │ ├── input_hooks.hpp │ │ │ └── wndproc │ │ │ │ └── wndproc_hooks.hpp │ │ ├── render │ │ │ ├── render_hooks.hpp │ │ │ ├── vulkan │ │ │ │ └── vulkan_hooks.hpp │ │ │ └── directx11 │ │ │ │ └── directx11_hooks.hpp │ │ └── hooks.hpp │ ├── hacks │ │ └── esp │ │ │ └── esp.hpp │ ├── cache │ │ ├── entities │ │ │ ├── hen.hpp │ │ │ ├── gun.hpp │ │ │ ├── captive.hpp │ │ │ ├── player.hpp │ │ │ └── base.hpp │ │ └── cache.hpp │ ├── platform │ │ └── platform.hpp │ ├── vars │ │ └── vars.hpp │ ├── signatures │ │ └── signatures.hpp │ ├── instance │ │ └── instance.hpp │ ├── renderer │ │ └── renderer.hpp │ ├── menu │ │ └── menu.hpp │ ├── virtual │ │ └── virtual.hpp │ ├── fnv │ │ └── fnv1a.hpp │ ├── memory │ │ └── memory.hpp │ ├── logger │ │ └── logger.hpp │ ├── constants │ │ └── constants.hpp │ ├── sigscan │ │ └── sigscan.hpp │ ├── schemamgr │ │ └── schema_manager.hpp │ └── stb │ │ └── stb.hh ├── sdk │ ├── include │ │ ├── input │ │ │ └── ccsgoinput.hpp │ │ ├── interfaces │ │ │ ├── source2client.hpp │ │ │ ├── inputsystem.hpp │ │ │ ├── engineclient.hpp │ │ │ ├── gameresourceservice.hpp │ │ │ ├── gameentitysystem.hpp │ │ │ ├── cvar.hpp │ │ │ └── schemasystem.hpp │ │ ├── bindings │ │ │ ├── entityidentity.hpp │ │ │ ├── gamescenenode.hpp │ │ │ ├── hostage.hpp │ │ │ ├── playerpawn.hpp │ │ │ ├── collisionproperty.hpp │ │ │ ├── entityinstance.hpp │ │ │ ├── playercontroller.hpp │ │ │ ├── hitbox.hpp │ │ │ └── baseentity.hpp │ │ ├── sdl │ │ │ └── sdl.hpp │ │ └── types │ │ │ ├── utlvector.hpp │ │ │ └── handle.hpp │ └── src │ │ ├── input │ │ └── ccsgoinput.cpp │ │ ├── interfaces │ │ ├── source2client.cpp │ │ ├── gameresourceservice.cpp │ │ ├── inputsystem.cpp │ │ ├── engineclient.cpp │ │ ├── gameentitysystem.cpp │ │ ├── schemasystem.cpp │ │ └── cvar.cpp │ │ ├── bindings │ │ ├── playerpawn.cpp │ │ ├── entityinstance.cpp │ │ └── baseentity.cpp │ │ ├── sdl │ │ └── sdl.cpp │ │ └── types │ │ └── handle.cpp ├── cs2-sdk.vcxproj.user ├── api │ ├── include │ │ ├── hook │ │ │ └── hook.hpp │ │ ├── module │ │ │ └── module.hpp │ │ └── pointer │ │ │ └── pointer.hpp │ └── src │ │ ├── pointer │ │ └── pointer.cpp │ │ ├── hook │ │ └── hook.cpp │ │ └── module │ │ └── module.cpp └── cs2-sdk.vcxproj.filters ├── .gitattributes ├── .editorconfig ├── .gitignore ├── scripts └── .gdbinit ├── LICENSE ├── cs2-sdk.sln ├── CMakeLists.txt ├── README.md └── .clang-format /cs2-sdk/pch/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | cs2-sdk/libs/** linguist-vendored=true -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | insert_final_newline = true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/* 2 | .vscode/* 3 | 4 | bin/* 5 | binlinux/* 6 | 7 | obj/* -------------------------------------------------------------------------------- /cs2-sdk/src/vars/vars.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | Vars_t g_Vars; 6 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/prefix.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bruhmoment21/cs2-sdk/HEAD/cs2-sdk/libs/distorm/src/prefix.c -------------------------------------------------------------------------------- /cs2-sdk/include/math/types/quaternion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Quaternion { 4 | public: 5 | float x, y, z, w; 6 | }; 7 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/input/ccsgoinput.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CCSGOInput { 4 | public: 5 | static CCSGOInput* Get(); 6 | }; 7 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/interfaces/source2client.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CSource2Client { 4 | public: 5 | static CSource2Client* Get(); 6 | }; 7 | -------------------------------------------------------------------------------- /cs2-sdk/include/math/types/vmatrix.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class VMatrix { 4 | public: 5 | auto operator[](int i) const { return m[i]; } 6 | 7 | float m[4][4]; 8 | }; 9 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/entityidentity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CEntityIdentity { 4 | public: 5 | SCHEMA(uint32_t, m_flags, "CEntityIdentity", "m_flags"); 6 | }; 7 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/interfaces/inputsystem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CInputSystem { 4 | public: 5 | static CInputSystem* Get(); 6 | 7 | bool IsRelativeMouseMode(); 8 | void* GetSDLWindow(); 9 | }; 10 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/gamescenenode.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class CGameSceneNode { 6 | public: 7 | SCHEMA(CTransform, m_nodeToWorld, "CGameSceneNode", "m_nodeToWorld"); 8 | }; 9 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/hostage.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class C_Hostage : public C_BaseEntity { 6 | public: 7 | SCHEMA(CHandle, m_leader, "C_Hostage", "m_leader"); 8 | }; 9 | -------------------------------------------------------------------------------- /cs2-sdk/include/math/types/matrix3x4.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct matrix3x4_t { 4 | auto operator[](int i) const { return m_flMatVal[i]; } 5 | auto operator[](int i) { return m_flMatVal[i]; } 6 | 7 | float m_flMatVal[3][4]; 8 | }; 9 | -------------------------------------------------------------------------------- /cs2-sdk/include/hooks/game/game_hooks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CGameHooks { 4 | public: 5 | static CGameHooks& Get() { 6 | static CGameHooks inst; 7 | return inst; 8 | } 9 | 10 | void Initialize(); 11 | }; 12 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/playerpawn.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class C_CSPlayerPawnBase : public C_BaseEntity { 6 | public: 7 | bool IsPlayerPawn(); 8 | bool IsObserverPawn(); 9 | }; 10 | -------------------------------------------------------------------------------- /cs2-sdk/include/hooks/input/sdl/sdl_hooks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CSDLHooks { 4 | public: 5 | static CSDLHooks& Get() { 6 | static CSDLHooks inst; 7 | return inst; 8 | } 9 | 10 | void Initialize(); 11 | }; 12 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/interfaces/engineclient.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CEngineClient { 4 | public: 5 | static CEngineClient* Get(); 6 | 7 | bool IsInGame(); 8 | int GetLocalPlayer(); 9 | int GetEngineBuildNumber(); 10 | }; 11 | -------------------------------------------------------------------------------- /cs2-sdk/cs2-sdk.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/collisionproperty.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CCollisionProperty { 4 | public: 5 | SCHEMA(Vector, m_vecMins, "CCollisionProperty", "m_vecMins"); 6 | SCHEMA(Vector, m_vecMaxs, "CCollisionProperty", "m_vecMaxs"); 7 | }; 8 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/interfaces/gameresourceservice.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CGameEntitySystem; 4 | 5 | class CGameResourceService { 6 | public: 7 | static CGameResourceService* Get(); 8 | 9 | CGameEntitySystem* GetGameEntitySystem(); 10 | }; 11 | -------------------------------------------------------------------------------- /cs2-sdk/include/hacks/esp/esp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CESP { 4 | public: 5 | static CESP& Get() { 6 | static CESP inst; 7 | return inst; 8 | } 9 | 10 | bool IsEnabled(); 11 | 12 | void Render(); 13 | void Update(); 14 | }; 15 | -------------------------------------------------------------------------------- /cs2-sdk/include/hooks/input/input_hooks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CInputHooks { 4 | public: 5 | static CInputHooks& Get() { 6 | static CInputHooks inst; 7 | return inst; 8 | } 9 | 10 | void Initialize(); 11 | void Shutdown(); 12 | }; 13 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/sdl/sdl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace sdl { 4 | bool SetWindowRelativeMouseMode(void* window, int enabled); 5 | bool SetWindowMouseGrab(void* window, int grabbed); 6 | void WarpMouseInWindow(void* window, float x, float y); 7 | } // namespace sdl 8 | -------------------------------------------------------------------------------- /cs2-sdk/src/cache/entities/hen.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | void CCachedHen::DrawESP() { 8 | if (g_Vars.m_ChickenBoxes) { 9 | DrawBoundingBox(IM_COL32(206, 66, 245, 255)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /cs2-sdk/include/hooks/render/render_hooks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CRenderHooks { 4 | public: 5 | static CRenderHooks& Get() { 6 | static CRenderHooks inst; 7 | return inst; 8 | } 9 | 10 | void Initialize(); 11 | bool RunningVulkan(); 12 | }; 13 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/input/ccsgoinput.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 13 | 14 | #ifdef _WIN32 15 | #include 16 | #include 17 | #elif __linux__ 18 | #include 19 | #include 20 | #include 21 | #endif 22 | -------------------------------------------------------------------------------- /cs2-sdk/include/hooks/input/wndproc/wndproc_hooks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CWndProcHooks { 4 | public: 5 | static CWndProcHooks& Get() { 6 | static CWndProcHooks inst; 7 | return inst; 8 | } 9 | 10 | #ifdef _WIN32 11 | auto GetWindow() const { return m_Window; } 12 | #endif 13 | 14 | void Initialize(); 15 | void Shutdown(); 16 | 17 | private: 18 | #ifdef _WIN32 19 | HWND m_Window; 20 | #endif 21 | }; 22 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/entityinstance.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | class CSchemaClassInfo; 10 | 11 | class CEntityInstance { 12 | public: 13 | CSchemaClassInfo* Schema_DynamicBinding(); 14 | CBaseHandle GetRefEHandle(); 15 | 16 | SCHEMA(CEntityIdentity*, m_pEntity, "CEntityInstance", "m_pEntity"); 17 | }; 18 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/types/utlvector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | class CUtlVector { 5 | public: 6 | auto At(int i) const { return m_Data[i]; } 7 | auto AtPtr(int i) const { return m_Data + i; } 8 | 9 | // C++ STL Iterators 10 | auto begin() const { return m_Data; } 11 | auto end() const { return m_Data + m_Size; } 12 | 13 | int m_Size; 14 | char pad0[0x4]; 15 | T* m_Data; 16 | char pad1[0x8]; 17 | }; 18 | -------------------------------------------------------------------------------- /cs2-sdk/src/renderer/renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | 12 | void CRenderer::Initialize() { SDK_LOG_PROLOGUE(); } 13 | 14 | void CRenderer::NewFrame() { 15 | m_BackgroundDrawList = ImGui::GetBackgroundDrawList(); 16 | 17 | CMenu::Get().Render(); 18 | CESP::Get().Render(); 19 | } 20 | -------------------------------------------------------------------------------- /cs2-sdk/include/cache/entities/captive.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // Has been named "Captive" to possibly avoid future naming conflicts. 6 | 7 | class C_Hostage; 8 | 9 | class CCachedCaptive : public CCachedBaseEntity { 10 | public: 11 | Type GetType() const override { return Type::HOSTAGE; } 12 | 13 | auto Get() const { return CCachedBaseEntity::Get(); } 14 | 15 | bool CanDoESP() override; 16 | void DrawESP() override; 17 | }; 18 | -------------------------------------------------------------------------------- /cs2-sdk/src/cache/entities/gun.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | bool CCachedGun::CanDoESP() { 10 | C_BaseEntity* weapon = Get(); 11 | if (!weapon || weapon->m_hOwnerEntity().IsValid()) { 12 | return false; 13 | } 14 | 15 | return true; 16 | } 17 | 18 | void CCachedGun::DrawESP() { 19 | if (g_Vars.m_WeaponBoxes) { 20 | DrawBoundingBox(IM_COL32(255, 255, 0, 255)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cs2-sdk/src/cache/entities/captive.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | bool CCachedCaptive::CanDoESP() { 10 | C_Hostage* hostage = Get(); 11 | if (!hostage || hostage->m_leader().IsValid()) { 12 | return false; 13 | } 14 | 15 | return true; 16 | } 17 | 18 | void CCachedCaptive::DrawESP() { 19 | if (g_Vars.m_HostageBoxes) { 20 | DrawBoundingBox(IM_COL32(255, 119, 0, 255)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cs2-sdk/include/math/types/bbox.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct BBox_t { 6 | BBox_t() { Invalidate(); } 7 | 8 | void Invalidate() { 9 | static constexpr auto MAX_FLOAT = std::numeric_limits::max(); 10 | 11 | m_Mins.x = m_Mins.y = MAX_FLOAT; 12 | m_Maxs.x = m_Maxs.y = -MAX_FLOAT; 13 | 14 | std::fill(std::begin(m_Vertices), std::end(m_Vertices), ImVec2{-MAX_FLOAT, -MAX_FLOAT}); 15 | } 16 | 17 | ImVec2 m_Mins, m_Maxs; 18 | ImVec2 m_Vertices[8]; 19 | }; 20 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/playercontroller.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class C_CSPlayerPawnBase; 6 | 7 | class CBasePlayerController : public C_BaseEntity { 8 | public: 9 | SCHEMA(CHandle, m_hPawn, "CBasePlayerController", "m_hPawn"); 10 | }; 11 | 12 | class CCSPlayerController : public CBasePlayerController { 13 | public: 14 | SCHEMA(bool, m_bPawnIsAlive, "CCSPlayerController", "m_bPawnIsAlive"); 15 | SCHEMA(const char*, m_sSanitizedPlayerName, "CCSPlayerController", "m_sSanitizedPlayerName"); 16 | }; 17 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/interfaces/gameentitysystem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class C_BaseEntity; 4 | 5 | class CGameEntitySystem { 6 | public: 7 | static CGameEntitySystem* Get(); 8 | 9 | template 10 | static auto GetBaseEntity(int index) { 11 | return static_cast(Get()->GetBaseEntityInternal(index)); 12 | } 13 | 14 | static auto GetHighestEntityIndex() { return Get()->GetHighestEntityIndexInternal(); } 15 | 16 | private: 17 | C_BaseEntity* GetBaseEntityInternal(int index); 18 | int GetHighestEntityIndexInternal(); 19 | }; 20 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/interfaces/gameresourceservice.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | CGameResourceService* CGameResourceService::Get() { 9 | static const auto inst = CMemory::GetInterface(CConstants::ENGINE_LIB, "GameResourceServiceClientV001"); 10 | return inst.Get(); 11 | } 12 | 13 | CGameEntitySystem* CGameResourceService::GetGameEntitySystem() { 14 | return CPointer(this).GetField(platform::Constant(0x58, 0x50)); 15 | } 16 | -------------------------------------------------------------------------------- /cs2-sdk/include/math/math.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct ImVec2; 7 | 8 | class CMath { 9 | public: 10 | static CMath& Get() { 11 | static CMath inst; 12 | return inst; 13 | } 14 | 15 | void UpdateViewMatrix(VMatrix* viewMatrix); 16 | 17 | bool WorldToScreen(const Vector& in, ImVec2& out); 18 | void TransformAABB(const matrix3x4_t& transform, const Vector& minsIn, const Vector& maxsIn, Vector& minsOut, Vector& maxsOut); 19 | 20 | private: 21 | VMatrix m_ViewMatrix; 22 | }; 23 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/decoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | decoder.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2021 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef DECODER_H 13 | #define DECODER_H 14 | 15 | #include "config.h" 16 | 17 | typedef unsigned int _iflags; 18 | 19 | _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[], unsigned int maxResultCount, unsigned int* usedInstructionsCount); 20 | 21 | #endif /* DECODER_H */ 22 | -------------------------------------------------------------------------------- /cs2-sdk/src/virtual/virtual.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | CPointer vt::GetMethod(CPointer base, uint32_t index) { 7 | if (!base.IsValid()) { 8 | CLogger::Log("[virtual] Tried getting virtual method from a null class."); 9 | return 0; 10 | } 11 | 12 | CPointer VTable = base.GetField(0); 13 | if (!VTable.IsValid()) { 14 | CLogger::Log("[virtual] Tried getting virtual method from a null vtable."); 15 | return 0; 16 | } 17 | 18 | return VTable.GetField(index * sizeof(uintptr_t)); 19 | } 20 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/interfaces/cvar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class ConVar { 6 | public: 7 | const char* m_Name; 8 | 9 | template 10 | T GetValue() { 11 | return CPointer(this).GetField(0x40); 12 | } 13 | }; 14 | 15 | class CCVar { 16 | public: 17 | using CVarIterator_t = uint64_t; 18 | 19 | static CCVar* Get(); 20 | 21 | CVarIterator_t GetFirstCvarIterator(); 22 | CVarIterator_t GetNextCvarIterator(CVarIterator_t prev); 23 | 24 | ConVar* GetCvarByIndex(CVarIterator_t index); 25 | ConVar* GetCvarByName(const char* name); 26 | }; 27 | -------------------------------------------------------------------------------- /cs2-sdk/src/hooks/input/input_hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | void CInputHooks::Initialize() { 12 | SDK_LOG_PROLOGUE(); 13 | 14 | #ifdef _WIN32 15 | CWndProcHooks::Get().Initialize(); 16 | #else 17 | CSDLHooks::Get().Initialize(); 18 | #endif 19 | } 20 | 21 | void CInputHooks::Shutdown() { 22 | SDK_LOG_PROLOGUE(); 23 | 24 | #ifdef _WIN32 25 | CWndProcHooks::Get().Shutdown(); 26 | #endif 27 | } 28 | -------------------------------------------------------------------------------- /cs2-sdk/src/logger/logger.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | void CLogger::Initialize() { 6 | #if defined(SDK_ENABLE_LOGGING) && defined(_WIN32) 7 | AllocConsole(); 8 | SetConsoleTitleA("cs2-sdk console"); 9 | 10 | freopen_s(&m_ConsoleStream, "CONOUT$", "w", stdout); 11 | #endif 12 | } 13 | 14 | void CLogger::LogStringInternal(const std::string& str) { 15 | #ifdef SDK_ENABLE_LOGGING 16 | std::cout << "[cs2-sdk] " << str << '\n'; 17 | #endif 18 | } 19 | 20 | CLogger::~CLogger() { 21 | #if defined(SDK_ENABLE_LOGGING) && defined(_WIN32) 22 | fclose(m_ConsoleStream); 23 | FreeConsole(); 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /cs2-sdk/include/cache/entities/player.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class CCSPlayerController; 6 | 7 | class CCachedPlayer : public CCachedBaseEntity { 8 | public: 9 | enum class Team { UNKNOWN = 0, SPECTATOR, TERRORIST, COUNTER_TERRORIST }; 10 | 11 | Type GetType() const override { return Type::PLAYER; } 12 | 13 | auto Get() const { return CCachedBaseEntity::Get(); } 14 | 15 | bool CanDoESP() override; 16 | void DrawESP() override; 17 | void CalculateDrawInfo() override; 18 | 19 | Team GetTeam(); 20 | bool IsEnemyWithTeam(Team team); 21 | bool IsLocalPlayer(); 22 | }; 23 | -------------------------------------------------------------------------------- /scripts/.gdbinit: -------------------------------------------------------------------------------- 1 | set confirm off 2 | set $library = 0 3 | 4 | define openlib 5 | set $dlopen = (void*(*)(char*, int)) dlopen 6 | set $dlclose = (int(*)(void*)) dlclose 7 | 8 | # Replace /path/to/lib with the built library's path. 9 | set $library = $dlopen("/path/to/lib", $arg0) 10 | end 11 | 12 | define lc 13 | openlib 6 14 | 15 | if $library == 0 16 | openlib 1 17 | else 18 | call $dlclose($library) 19 | echo Already loaded.\n 20 | end 21 | end 22 | 23 | define uc 24 | openlib 6 25 | 26 | if $library == 0 27 | echo Nothing to unload.\n 28 | else 29 | call $dlclose($library) 30 | call $dlclose($library) 31 | 32 | set $library = 0 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /cs2-sdk/include/menu/menu.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CMenu { 4 | public: 5 | static CMenu& Get() { 6 | static CMenu inst; 7 | return inst; 8 | } 9 | 10 | auto IsOpen() const { return m_State == OPEN || m_State == TOGGLE_CLOSE; } 11 | 12 | void Render(); 13 | void HandleStates(bool mouseIsEnabled); 14 | 15 | private: 16 | void DeclareShutdown(); 17 | 18 | void Toggle(); 19 | 20 | void RenderWatermark(); 21 | void RenderUI(); 22 | void RenderMainMenu(); 23 | 24 | enum State { CLOSED = 0, TOGGLE_OPEN, OPEN, TOGGLE_CLOSE, TOGGLE_SHUTDOWN, TOGGLE_SHUTDOWN_AND_CLOSE_MENU, SHUTDOWN }; 25 | 26 | State m_State; 27 | }; 28 | -------------------------------------------------------------------------------- /cs2-sdk/api/include/hook/hook.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Use this to also pass in the hook name. 4 | #define SDK_HOOK(hook) reinterpret_cast(hook), #hook 5 | 6 | #include 7 | 8 | #include 9 | 10 | class CHook { 11 | public: 12 | void Hook(void* target, void* hook, const char* name = ""); 13 | void VHook(void* base, int index, void* hook, const char* name = ""); 14 | 15 | template 16 | auto CallOriginal(Args... args) { 17 | return CPointer(m_Original).Call(std::forward(args)...); 18 | } 19 | 20 | static funchook_t* s_FuncHookContext; 21 | 22 | private: 23 | void* m_Original; 24 | }; 25 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/bindings/playerpawn.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | bool C_CSPlayerPawnBase::IsPlayerPawn() { 8 | static CSchemaClassInfo* playerPawnClass = 9 | CSchemaSystem::Get()->FindTypeScopeForModule(CConstants::CLIENT_LIB)->FindDeclaredClass("C_CSPlayerPawn"); 10 | return Schema_DynamicBinding() == playerPawnClass; 11 | } 12 | 13 | bool C_CSPlayerPawnBase::IsObserverPawn() { 14 | static CSchemaClassInfo* observerPawnClass = 15 | CSchemaSystem::Get()->FindTypeScopeForModule(CConstants::CLIENT_LIB)->FindDeclaredClass("C_CSObserverPawn"); 16 | return Schema_DynamicBinding() == observerPawnClass; 17 | } 18 | -------------------------------------------------------------------------------- /cs2-sdk/src/hooks/render/render_hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | void CRenderHooks::Initialize() { 13 | SDK_LOG_PROLOGUE(); 14 | 15 | #ifdef _WIN32 16 | if (!RunningVulkan()) { 17 | return CDirectX11Hooks::Get().Initialize(); 18 | } 19 | #endif 20 | 21 | return CVulkanHooks::Get().Initialize(); 22 | } 23 | 24 | bool CRenderHooks::RunningVulkan() { return CMemory::GetModule(CConstants::RENDERSYSTEMVULKAN_LIB) != nullptr; } 25 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/interfaces/inputsystem.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | CInputSystem* CInputSystem::Get() { 9 | static const auto inst = CMemory::GetInterface(CConstants::INPUTSYSTEM_LIB, "InputSystemVersion001"); 10 | return inst.Get(); 11 | } 12 | 13 | void* CInputSystem::GetSDLWindow() { 14 | // Offset in 'CInputSystem::DebugSpew'. 15 | // xref: "SDL says cursor is %s and is set to 0x%p\n". 16 | 17 | // Offset in 'CInputSystem::SetCursorClip'. 18 | // xref: "SetCursorClip: %s SDL_SetWindowGrab on 0x%p (%s) %s\n". 19 | 20 | return CPointer(this).GetField(0x2648); 21 | } 22 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/operands.h: -------------------------------------------------------------------------------- 1 | /* 2 | operands.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2021 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef OPERANDS_H 13 | #define OPERANDS_H 14 | 15 | #include "config.h" 16 | #include "decoder.h" 17 | #include "prefix.h" 18 | #include "instructions.h" 19 | 20 | int operands_extract(_CodeInfo* ci, _DInst* di, _InstInfo* ii, 21 | _iflags instFlags, _OpType type, 22 | unsigned int modrm, _PrefixState* ps, _DecodeType effOpSz, 23 | _DecodeType effAdrSz, _Operand* op); 24 | 25 | #endif /* OPERANDS_H */ 26 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/hitbox.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class CHitBox { 6 | public: 7 | SCHEMA_EXTENDED(Vector, m_vMinBounds, CConstants::ANIMATIONSYSTEM_LIB, "CHitBox", "m_vMinBounds", 0); 8 | SCHEMA_EXTENDED(Vector, m_vMaxBounds, CConstants::ANIMATIONSYSTEM_LIB, "CHitBox", "m_vMaxBounds", 0); 9 | 10 | private: 11 | // Size of 'CHitBox' class. Can be obtainted through the SchemaSystem. 12 | // Must have this here or we can't iterate the 'm_HitBoxes' vector that stores 13 | // CHitBox directly and not by a pointer. 14 | char pad[0x70]; 15 | }; 16 | 17 | class CHitBoxSet { 18 | public: 19 | SCHEMA_EXTENDED(CUtlVector, m_HitBoxes, CConstants::ANIMATIONSYSTEM_LIB, "CHitBoxSet", "m_HitBoxes", 0); 20 | }; 21 | -------------------------------------------------------------------------------- /cs2-sdk/include/virtual/virtual.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace vt { 6 | CPointer GetMethod(CPointer base, uint32_t index); 7 | 8 | /* 9 | * CallMethod usage: 10 | * CallMethod(thisPointer, methodIndex, arg1, arg2, arg3...); 11 | * 12 | * It automatically deduces argument types except for references, usually you don't have those 13 | * but you can pass the argument with reference using std::ref(arg4) <- Example. 14 | */ 15 | template 16 | inline T CallMethod(CPointer base, uint32_t index, Args... args) { 17 | return GetMethod(base, index).Call(base.Get(), std::forward(args)...); 18 | } 19 | } // namespace vt 20 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/bindings/entityinstance.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | CSchemaClassInfo* CEntityInstance::Schema_DynamicBinding() { 8 | CSchemaClassInfo* binding = nullptr; 9 | 10 | #ifdef _WIN32 11 | vt::CallMethod(this, 38, &binding); 12 | #elif __linux__ 13 | binding = vt::CallMethod(this, 39); 14 | #endif 15 | 16 | return binding; 17 | } 18 | 19 | CBaseHandle CEntityInstance::GetRefEHandle() { 20 | CBaseHandle handle{}; 21 | 22 | CEntityIdentity* identity = m_pEntity(); 23 | if (!identity) return handle; 24 | 25 | CBaseHandle unkHandle = CPointer(identity).GetField(0x10); 26 | handle.Init(unkHandle.GetEntryIndex(), unkHandle.GetSerialNumber() - (identity->m_flags() & 1)); 27 | 28 | return handle; 29 | } 30 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/interfaces/engineclient.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | CEngineClient* CEngineClient::Get() { 11 | static const auto inst = CMemory::GetInterface(CConstants::ENGINE_LIB, "Source2EngineToClient001"); 12 | return inst.Get(); 13 | } 14 | 15 | bool CEngineClient::IsInGame() { return vt::CallMethod(this, 35); } 16 | 17 | int CEngineClient::GetLocalPlayer() { 18 | int index = -1; 19 | 20 | #if _WIN32 21 | vt::CallMethod(this, 49, &index, 0); 22 | #elif __linux__ 23 | index = vt::CallMethod(this, 49, 0); 24 | #endif 25 | 26 | return index + 1; 27 | } 28 | 29 | int CEngineClient::GetEngineBuildNumber() { return vt::CallMethod(this, 83); } 30 | -------------------------------------------------------------------------------- /cs2-sdk/api/include/module/module.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CModule { 4 | public: 5 | CModule(const char* name); 6 | ~CModule(); 7 | 8 | auto GetHandle() const { return m_Handle; } 9 | auto GetName() const { return m_Name.c_str(); } 10 | 11 | // Returns false if module not loaded. 12 | bool Retrieve(); 13 | 14 | uintptr_t GetInterface(uint32_t versionHash); 15 | uintptr_t GetProcAddress(const char* procName); 16 | uintptr_t FindPattern(const std::span& pattern) const; 17 | 18 | private: 19 | void InitializeHandle(); 20 | void InitializeBounds(); 21 | 22 | void SetBounds(uintptr_t begin, uintptr_t size); 23 | 24 | // Module name. 25 | std::string m_Name; 26 | 27 | // Module handle. 28 | void* m_Handle; 29 | 30 | // Used for pattern scanning. 31 | uintptr_t m_Begin, m_Size; 32 | }; 33 | -------------------------------------------------------------------------------- /cs2-sdk/include/fnv/fnv1a.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class FNV1A { 4 | public: 5 | // Not guaranteed to be hashed at compile-time. 6 | static constexpr uint32_t Hash(const char* string) { 7 | uint32_t hash = FNV_OFFSET_BASIS; 8 | for (size_t i = 0; string[i]; ++i) { 9 | hash = FNV_PRIME * (hash ^ static_cast(string[i])); 10 | } 11 | 12 | return hash; 13 | } 14 | 15 | // Guaranteed to be hashed at compile-time. 16 | static consteval uint32_t HashConst(const char* string) { 17 | uint32_t hash = FNV_OFFSET_BASIS; 18 | for (size_t i = 0; string[i]; ++i) { 19 | hash = FNV_PRIME * (hash ^ static_cast(string[i])); 20 | } 21 | 22 | return hash; 23 | } 24 | 25 | private: 26 | static constexpr uint32_t FNV_PRIME = 0x01000193, FNV_OFFSET_BASIS = 0x811c9dc5; 27 | }; 28 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/interfaces/gameentitysystem.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | CGameEntitySystem* CGameEntitySystem::Get() { return CGameResourceService::Get()->GetGameEntitySystem(); } 9 | 10 | C_BaseEntity* CGameEntitySystem::GetBaseEntityInternal(int index) { 11 | return signatures::GetBaseEntity.GetPtr().Call(this, index); 12 | } 13 | 14 | int CGameEntitySystem::GetHighestEntityIndexInternal() { 15 | int highestIdx = -1; 16 | 17 | #ifdef _WIN32 18 | signatures::GetHighestEntityIndex.GetPtr().Call(this, &highestIdx); 19 | #elif __linux__ 20 | highestIdx = signatures::GetHighestEntityIndex.GetPtr().Call(this); 21 | #endif 22 | 23 | return highestIdx; 24 | } 25 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/types/handle.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | constexpr auto INVALID_EHANDLE_INDEX = 0xffffffff; 4 | constexpr auto ENT_ENTRY_MASK = 0x7fff; 5 | constexpr auto NUM_SERIAL_NUM_SHIFT_BITS = 15; 6 | 7 | class C_BaseEntity; 8 | 9 | class CBaseHandle { 10 | public: 11 | CBaseHandle() : m_Index(INVALID_EHANDLE_INDEX) {} 12 | CBaseHandle(uint32_t value) : m_Index(value) {} 13 | CBaseHandle(int entry, int serialNumber) { Init(entry, serialNumber); } 14 | 15 | void Init(int entry, int serialNumber); 16 | 17 | bool IsValid() const; 18 | 19 | int GetEntryIndex() const; 20 | int GetSerialNumber() const; 21 | 22 | int ToInt() const; 23 | bool operator==(CBaseHandle rhs) const; 24 | 25 | C_BaseEntity* Get() const; 26 | 27 | protected: 28 | uint32_t m_Index; 29 | }; 30 | 31 | template 32 | class CHandle : public CBaseHandle { 33 | public: 34 | auto Get() const { return reinterpret_cast(CBaseHandle::Get()); } 35 | }; 36 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/sdl/sdl.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace sdl { 9 | bool SetWindowRelativeMouseMode(void* window, int enabled) { 10 | static const auto fn = CMemory::GetProcAddress(CConstants::SDL_LIB, "SDL_SetWindowRelativeMouseMode"); 11 | return fn.Call(window, enabled); 12 | } 13 | 14 | bool SetWindowMouseGrab(void* window, int grabbed) { 15 | static const auto fn = CMemory::GetProcAddress(CConstants::SDL_LIB, "SDL_SetWindowMouseGrab"); 16 | return fn.Call(window, grabbed); 17 | } 18 | 19 | void WarpMouseInWindow(void* window, float x, float y) { 20 | static const auto fn = CMemory::GetProcAddress(CConstants::SDL_LIB, "SDL_WarpMouseInWindow"); 21 | return fn.Call(window, x, y); 22 | } 23 | } // namespace sdl 24 | -------------------------------------------------------------------------------- /cs2-sdk/include/cache/cache.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class CEntityInstance; 6 | class CCachedPlayer; 7 | 8 | class CMatchCache { 9 | public: 10 | using CachedEntityPtr = std::unique_ptr; 11 | 12 | static CMatchCache& Get() { 13 | static CMatchCache inst; 14 | return inst; 15 | } 16 | 17 | static const auto& GetCachedEntities() { return Get().m_CachedEntities; } 18 | static auto& GetLock() { return Get().m_EntitiesLock; } 19 | 20 | void Initialize(); 21 | 22 | void AddEntity(CEntityInstance* inst, CBaseHandle handle); 23 | void RemoveEntity(CEntityInstance* inst, CBaseHandle handle); 24 | 25 | CachedEntityPtr& GetEntityByIndex(int i); 26 | CCachedPlayer* GetLocalPlayer(); 27 | 28 | private: 29 | CachedEntityPtr CreateCachedEntityPointer(C_BaseEntity* ent); 30 | 31 | std::mutex m_EntitiesLock; 32 | std::unordered_map m_CachedEntities; 33 | }; 34 | -------------------------------------------------------------------------------- /cs2-sdk/src/math/types/transform.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | matrix3x4_t CTransform::ToMatrix() const { 6 | matrix3x4_t matrix{}; 7 | 8 | const auto& rot = m_Orientation; 9 | const auto& pos = m_Position; 10 | 11 | matrix[0][0] = 1.0f - 2.0f * rot.y * rot.y - 2.0f * rot.z * rot.z; 12 | matrix[1][0] = 2.0f * rot.x * rot.y + 2.0f * rot.w * rot.z; 13 | matrix[2][0] = 2.0f * rot.x * rot.z - 2.0f * rot.w * rot.y; 14 | 15 | matrix[0][1] = 2.0f * rot.x * rot.y - 2.0f * rot.w * rot.z; 16 | matrix[1][1] = 1.0f - 2.0f * rot.x * rot.x - 2.0f * rot.z * rot.z; 17 | matrix[2][1] = 2.0f * rot.y * rot.z + 2.0f * rot.w * rot.x; 18 | 19 | matrix[0][2] = 2.0f * rot.x * rot.z + 2.0f * rot.w * rot.y; 20 | matrix[1][2] = 2.0f * rot.y * rot.z - 2.0f * rot.w * rot.x; 21 | matrix[2][2] = 1.0f - 2.0f * rot.x * rot.x - 2.0f * rot.y * rot.y; 22 | 23 | matrix[0][3] = pos.x; 24 | matrix[1][3] = pos.y; 25 | matrix[2][3] = pos.z; 26 | 27 | return matrix; 28 | } 29 | -------------------------------------------------------------------------------- /cs2-sdk/include/memory/memory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | using ModulePtr_t = std::unique_ptr; 7 | 8 | class CMemory { 9 | public: 10 | static CMemory& Get() { 11 | static CMemory inst; 12 | return inst; 13 | } 14 | 15 | static auto& GetModule(const char* libName) { return Get().GetModuleInternal(libName); } 16 | static auto GetInterface(const char* libName, const char* version) { return Get().GetInterfaceInternal(libName, version); } 17 | static auto GetProcAddress(const char* libName, const char* procName) { return Get().GetProcAddressInternal(libName, procName); } 18 | 19 | void Initialize(); 20 | 21 | private: 22 | ModulePtr_t& GetModuleInternal(const char* libName); 23 | 24 | CPointer GetInterfaceInternal(const char* libName, const char* version); 25 | CPointer GetProcAddressInternal(const char* libName, const char* procName); 26 | 27 | std::unordered_map m_CachedModules; 28 | }; 29 | -------------------------------------------------------------------------------- /cs2-sdk/include/logger/logger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Comment if you'd wish to disable logging. 4 | #define SDK_ENABLE_LOGGING 5 | 6 | #define SDK_LOG_PROLOGUE() CLogger::Log("[prologue] {}", std::source_location::current().function_name()) 7 | #define SDK_LOG_PTR(x) reinterpret_cast(x) 8 | 9 | class CLogger { 10 | public: 11 | static CLogger& Get() { 12 | static CLogger inst; 13 | return inst; 14 | } 15 | 16 | template 17 | static void Log(const char* fmt, const Args&... args) { 18 | Get().LogInternal(fmt, args...); 19 | } 20 | 21 | void Initialize(); 22 | 23 | private: 24 | template 25 | void LogInternal(const char* fmt, const Args&... args) { 26 | #ifdef SDK_ENABLE_LOGGING 27 | LogStringInternal(std::vformat(fmt, std::make_format_args(args...))); 28 | #endif 29 | } 30 | 31 | void LogStringInternal(const std::string& str); 32 | 33 | ~CLogger(); 34 | 35 | #ifdef _WIN32 36 | FILE* m_ConsoleStream; 37 | #endif 38 | }; 39 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/types/handle.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | void CBaseHandle::Init(int entry, int serialNumber) { m_Index = entry | (serialNumber << NUM_SERIAL_NUM_SHIFT_BITS); } 10 | 11 | bool CBaseHandle::IsValid() const { return m_Index != INVALID_EHANDLE_INDEX; } 12 | 13 | int CBaseHandle::GetEntryIndex() const { return IsValid() ? m_Index & ENT_ENTRY_MASK : ENT_ENTRY_MASK; } 14 | 15 | int CBaseHandle::GetSerialNumber() const { return m_Index >> NUM_SERIAL_NUM_SHIFT_BITS; } 16 | 17 | int CBaseHandle::ToInt() const { return static_cast(m_Index); } 18 | 19 | bool CBaseHandle::operator==(CBaseHandle rhs) const { return m_Index == rhs.m_Index; } 20 | 21 | C_BaseEntity* CBaseHandle::Get() const { 22 | if (!IsValid()) return nullptr; 23 | 24 | C_BaseEntity* ent = CGameEntitySystem::GetBaseEntity(GetEntryIndex()); 25 | if (!ent || ent->GetRefEHandle() != *this) return nullptr; 26 | 27 | return ent; 28 | } 29 | -------------------------------------------------------------------------------- /cs2-sdk/include/constants/constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class CConstants { 6 | public: 7 | static constexpr auto MATCHMAKING_LIB = platform::Constant("matchmaking.dll", "libmatchmaking.so"); 8 | static constexpr auto CLIENT_LIB = platform::Constant("client.dll", "libclient.so"); 9 | static constexpr auto ENGINE_LIB = platform::Constant("engine2.dll", "libengine2.so"); 10 | static constexpr auto SDL_LIB = platform::Constant("SDL3.dll", "libSDL3.so.0"); 11 | static constexpr auto INPUTSYSTEM_LIB = platform::Constant("inputsystem.dll", "libinputsystem.so"); 12 | static constexpr auto SCHEMASYSTEM_LIB = platform::Constant("schemasystem.dll", "libschemasystem.so"); 13 | static constexpr auto ANIMATIONSYSTEM_LIB = platform::Constant("animationsystem.dll", "libanimationsystem.so"); 14 | static constexpr auto TIER_LIB = platform::Constant("tier0.dll", "libtier0.so"); 15 | static constexpr auto RENDERSYSTEMVULKAN_LIB = platform::Constant("rendersystemvulkan.dll", "librendersystemvulkan.so"); 16 | }; 17 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/bindings/baseentity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | struct BBox_t; 10 | 11 | class C_BaseEntity : public CEntityInstance { 12 | public: 13 | bool IsPlayerController(); 14 | bool IsWeapon(); 15 | bool IsProjectile(); 16 | bool IsPlantedC4(); 17 | bool IsChicken(); 18 | bool IsHostage(); 19 | 20 | bool CalculateBBoxByCollision(BBox_t& out); 21 | bool CalculateBBoxByHitbox(BBox_t& out); 22 | 23 | CHitBoxSet* GetHitboxSet(int i); 24 | int HitboxToWorldTransforms(CHitBoxSet* hitBoxSet, CTransform* hitboxToWorld); 25 | 26 | SCHEMA(CGameSceneNode*, m_pGameSceneNode, "C_BaseEntity", "m_pGameSceneNode"); 27 | SCHEMA(CBaseHandle, m_hOwnerEntity, "C_BaseEntity", "m_hOwnerEntity"); 28 | SCHEMA(CCollisionProperty*, m_pCollision, "C_BaseEntity", "m_pCollision"); 29 | SCHEMA(uint8_t, m_iTeamNum, "C_BaseEntity", "m_iTeamNum"); 30 | SCHEMA(int, m_iHealth, "C_BaseEntity", "m_iHealth"); 31 | }; 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Marius 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cs2-sdk/api/src/pointer/pointer.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | CPointer CPointer::GetFieldPtr(int offset) const { 7 | if (IsValid()) { 8 | return m_Value + offset; 9 | } 10 | 11 | LogInvalid(); 12 | 13 | static CPointer null{}; 14 | return &null; 15 | } 16 | 17 | CPointer& CPointer::Offset(int offset) { 18 | if (IsValid()) { 19 | m_Value += offset; 20 | } 21 | 22 | return *this; 23 | } 24 | 25 | CPointer& CPointer::Absolute(int preAbs, int postAbs) { 26 | if (IsValid()) { 27 | Offset(preAbs); 28 | m_Value = m_Value + sizeof(int) + *reinterpret_cast(m_Value); 29 | Offset(postAbs); 30 | } 31 | 32 | return *this; 33 | } 34 | 35 | CPointer& CPointer::Dereference(int count) { 36 | if (IsValid()) { 37 | while (count-- != 0) { 38 | m_Value = *reinterpret_cast(m_Value); 39 | } 40 | } 41 | 42 | return *this; 43 | } 44 | 45 | void CPointer::LogInvalid() const { CLogger::Log("[CPointer] Avoided performing an operation with nullptr. (Debug?)"); } 46 | -------------------------------------------------------------------------------- /cs2-sdk.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.5.33516.290 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cs2-sdk", "cs2-sdk\cs2-sdk.vcxproj", "{2C6645A9-9703-4667-AC9A-58D0B2A00976}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2C6645A9-9703-4667-AC9A-58D0B2A00976}.Debug|x64.ActiveCfg = Debug|x64 15 | {2C6645A9-9703-4667-AC9A-58D0B2A00976}.Debug|x64.Build.0 = Debug|x64 16 | {2C6645A9-9703-4667-AC9A-58D0B2A00976}.Release|x64.ActiveCfg = Release|x64 17 | {2C6645A9-9703-4667-AC9A-58D0B2A00976}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {156D73A9-A16D-49D2-821D-36019C3FF67F} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /cs2-sdk/src/entry.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #ifdef _WIN32 7 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { 8 | if (fdwReason == DLL_PROCESS_ATTACH) { 9 | DisableThreadLibraryCalls(hinstDLL); 10 | 11 | HANDLE hThread = CreateThread( 12 | NULL, 0, 13 | [](LPVOID pData) -> DWORD { 14 | CLogger::Get().Initialize(); 15 | CInstance::Get().Initialize(); 16 | 17 | return 0; 18 | }, 19 | hinstDLL, 0, NULL); 20 | 21 | if (hThread != NULL) { 22 | CloseHandle(hThread); 23 | } 24 | } else if (fdwReason == DLL_PROCESS_DETACH && !lpvReserved) { 25 | CInstance::Get().Shutdown(); 26 | } 27 | 28 | return TRUE; 29 | } 30 | #elif __linux__ 31 | static void __attribute__((constructor)) Initialize() { 32 | std::thread thread{[]() { CInstance::Get().Initialize(); }}; 33 | thread.detach(); 34 | } 35 | 36 | static void __attribute__((destructor)) Shutdown() { CInstance::Get().Shutdown(); } 37 | #endif 38 | -------------------------------------------------------------------------------- /cs2-sdk/include/cache/entities/base.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | class CCachedBaseEntity { 8 | public: 9 | enum class Type { GENERIC = 0, PLAYER, GUN, HEN, HOSTAGE }; 10 | 11 | CCachedBaseEntity() {} 12 | CCachedBaseEntity(const CCachedBaseEntity&) = delete; 13 | CCachedBaseEntity& operator=(const CCachedBaseEntity&) = delete; 14 | 15 | // Gets rid of the need to dynamic_cast. 16 | virtual Type GetType() const { return Type::GENERIC; } 17 | 18 | template 19 | auto Get() const { 20 | return CHandle(m_Handle).Get(); 21 | } 22 | 23 | auto GetHandle() const { return m_Handle; } 24 | auto SetHandle(CBaseHandle handle) { m_Handle = handle; } 25 | 26 | auto GetIndex() const { return m_Handle.GetEntryIndex(); } 27 | auto GetSerial() const { return m_Handle.GetSerialNumber(); } 28 | 29 | // Used by ESP. 30 | virtual bool CanDoESP(); 31 | virtual void DrawESP(); 32 | virtual void InvalidateDrawInfo(); 33 | virtual void CalculateDrawInfo(); 34 | 35 | protected: 36 | void DrawBoundingBox(ImU32 color); 37 | 38 | CBaseHandle m_Handle; 39 | BBox_t m_BBox; 40 | }; 41 | -------------------------------------------------------------------------------- /cs2-sdk/src/hacks/esp/esp.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | bool CESP::IsEnabled() { return g_Vars.m_EnableESP && CEngineClient::Get()->IsInGame(); } 11 | 12 | void CESP::Render() { 13 | const std::lock_guard lock(CMatchCache::GetLock()); 14 | 15 | const auto& cachedEntities = CMatchCache::GetCachedEntities(); 16 | for (const auto& it : cachedEntities) { 17 | const auto& cachedEntity = it.second; 18 | if (!cachedEntity->CanDoESP() || !IsEnabled()) { 19 | cachedEntity->InvalidateDrawInfo(); 20 | continue; 21 | } 22 | 23 | cachedEntity->DrawESP(); 24 | } 25 | } 26 | 27 | void CESP::Update() { 28 | const std::lock_guard lock(CMatchCache::GetLock()); 29 | 30 | const auto& cachedEntities = CMatchCache::GetCachedEntities(); 31 | for (const auto& it : cachedEntities) { 32 | const auto& cachedEntity = it.second; 33 | if (!cachedEntity->CanDoESP() || !IsEnabled()) { 34 | cachedEntity->InvalidateDrawInfo(); 35 | continue; 36 | } 37 | 38 | cachedEntity->CalculateDrawInfo(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/wstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wstring.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2021 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef WSTRING_H 13 | #define WSTRING_H 14 | 15 | #include "config.h" 16 | #include "../include/mnemonics.h" 17 | 18 | #ifndef DISTORM_LIGHT 19 | 20 | _INLINE_ void strcat_WSR(unsigned char** str, const _WRegister* reg) 21 | { 22 | /* 23 | * Longest register name is YMM15 - 5 characters, 24 | * Copy 8 so compiler can do a QWORD move. 25 | * We copy nul termination and fix the length, so it's okay to copy more to the output buffer. 26 | * There's a sentinel register to make sure we don't read past the end of the registers table. 27 | */ 28 | memcpy((int8_t*)*str, (const int8_t*)reg->p, 8); 29 | *str += reg->length; 30 | } 31 | 32 | #define strfinalize_WS(s, end) do { *end = 0; s.length = (unsigned int)((size_t)end - (size_t)s.p); } while (0) 33 | #define chrcat_WS(s, ch) do { *s = ch; s += 1; } while (0) 34 | #define strcat_WS(s, buf, copylen, advancelen) do { memcpy((int8_t*)s, buf, copylen); s += advancelen; } while(0) 35 | 36 | #endif /* DISTORM_LIGHT */ 37 | 38 | #endif /* WSTRING_H */ 39 | -------------------------------------------------------------------------------- /cs2-sdk/api/src/hook/hook.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | funchook_t* CHook::s_FuncHookContext; 9 | 10 | void CHook::Hook(void* target, void* hook, const char* name) { 11 | // Even though the function is called "Hook" 12 | // its purpose is to prepare the hooking. 13 | // Hooks are installed by funchook_install in hooks.cpp. 14 | 15 | if (!s_FuncHookContext) { 16 | return CLogger::Log("[hook] CHook::s_FuncHookContext not initialized!"); 17 | } 18 | 19 | if (m_Original) { 20 | return CLogger::Log("[hook] tried rehooking {}. (Debug?)", name); 21 | } 22 | 23 | if (!target) { 24 | return CLogger::Log("[hook] tried hooking null to redirect to {}. (Debug?)", name); 25 | } 26 | 27 | m_Original = target; 28 | if (funchook_prepare(s_FuncHookContext, &m_Original, hook) != FUNCHOOK_ERROR_SUCCESS) { 29 | m_Original = nullptr; 30 | CLogger::Log("[hook] failed to prepare hooking {}. {}", name, funchook_error_message(s_FuncHookContext)); 31 | } else { 32 | CLogger::Log("[hook] prepared {} [ {} -> {} ]", name, target, hook); 33 | } 34 | } 35 | 36 | void CHook::VHook(void* base, int index, void* hook, const char* name) { Hook(vt::GetMethod(base, index).Get(), hook, name); } 37 | -------------------------------------------------------------------------------- /cs2-sdk/include/math/types/vector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Vector { 6 | public: 7 | Vector() : x(0.f), y(0.f), z(0.f) {} 8 | Vector(float rhs) : x(rhs), y(rhs), z(rhs) {} 9 | Vector(float x, float y, float z) : x(x), y(y), z(z) {} 10 | 11 | Vector operator+(const Vector& rhs) const { return Vector{x + rhs.x, y + rhs.y, z + rhs.z}; } 12 | Vector operator-(const Vector& rhs) const { return Vector{x - rhs.x, y - rhs.y, z - rhs.z}; } 13 | Vector operator*(float scalar) const { return Vector{x * scalar, y * scalar, z * scalar}; } 14 | 15 | Vector Transform(const matrix3x4_t& matrix) const { 16 | return Vector{x * matrix[0][0] + y * matrix[0][1] + z * matrix[0][2] + matrix[0][3], 17 | x * matrix[1][0] + y * matrix[1][1] + z * matrix[1][2] + matrix[1][3], 18 | x * matrix[2][0] + y * matrix[2][1] + z * matrix[2][2] + matrix[2][3]}; 19 | } 20 | 21 | float DotProductAbsolute(const Vector& rhs) const { return std::abs(x * rhs.x) + std::abs(y * rhs.y) + std::abs(z * rhs.z); } 22 | 23 | Vector Min(const Vector& rhs) const { return Vector{std::min(x, rhs.x), std::min(y, rhs.y), std::min(z, rhs.z)}; } 24 | Vector Max(const Vector& rhs) const { return Vector{std::max(x, rhs.x), std::max(y, rhs.y), std::max(z, rhs.z)}; } 25 | 26 | float x, y, z; 27 | }; 28 | -------------------------------------------------------------------------------- /cs2-sdk/api/include/pointer/pointer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CPointer { 4 | public: 5 | CPointer() { m_Value = 0; } 6 | 7 | template 8 | CPointer(T value) { 9 | m_Value = (uintptr_t)(value); 10 | } 11 | 12 | bool IsValid() const { return m_Value != 0; } 13 | 14 | template 15 | auto Get() const { 16 | return reinterpret_cast(m_Value); 17 | } 18 | 19 | template 20 | std::add_lvalue_reference_t GetField(int offset) const { 21 | return *GetFieldPtr(offset).Get(); 22 | } 23 | 24 | template 25 | auto Call(Args... args) const { 26 | if constexpr (std::is_invocable_v) { 27 | if (IsValid()) { 28 | return std::invoke(Get(), std::forward(args)...); 29 | } 30 | } else { 31 | static_assert(std::is_invocable_v, "T must be an invocable type."); 32 | } 33 | 34 | LogInvalid(); 35 | return std::invoke_result_t{}; 36 | } 37 | 38 | CPointer GetFieldPtr(int offset) const; 39 | 40 | CPointer& Offset(int offset); 41 | CPointer& Absolute(int preAbs, int postAbs); 42 | CPointer& Dereference(int count); 43 | 44 | private: 45 | void LogInvalid() const; 46 | 47 | uintptr_t m_Value; 48 | }; 49 | -------------------------------------------------------------------------------- /cs2-sdk/src/schemamgr/schema_manager.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | std::optional CSchemaManager::GetSchemaOffsetInternal(const char* moduleName, const char* bindingName, const char* fieldName) { 11 | CSchemaSystemTypeScope* typeScope = CSchemaSystem::Get()->FindTypeScopeForModule(moduleName); 12 | if (!typeScope) { 13 | CLogger::Log("[schemamgr] No type scope found for '{}'.", moduleName); 14 | return {}; 15 | } 16 | 17 | CSchemaClassInfo* classInfo = typeScope->FindDeclaredClass(bindingName); 18 | if (!classInfo) { 19 | CLogger::Log("[schemamgr] No binding named '{}' has been found in module '{}'.", bindingName, moduleName); 20 | return {}; 21 | } 22 | 23 | uint32_t fieldHash = FNV1A::Hash(fieldName); 24 | for (int i = 0; classInfo->m_Fields && i < classInfo->m_nFieldsCount; ++i) { 25 | auto& field = classInfo->m_Fields[i]; 26 | if (FNV1A::Hash(field.m_Name) == fieldHash) { 27 | CLogger::Log("[schemamgr] '{}::{}' offset is 0x{:x}.", bindingName, fieldName, field.m_nSingleInheritanceOffset); 28 | return field.m_nSingleInheritanceOffset; 29 | } 30 | } 31 | 32 | CLogger::Log("[schemamgr] No field named '{}' has been found in binding '{}'.", fieldName, bindingName); 33 | return {}; 34 | } 35 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/interfaces/schemasystem.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | CSchemaSystem* CSchemaSystem::Get() { 12 | static const auto inst = CMemory::GetInterface(CConstants::SCHEMASYSTEM_LIB, "SchemaSystem_001"); 13 | return inst.Get(); 14 | } 15 | 16 | CSchemaSystemTypeScope* CSchemaSystem::FindTypeScopeForModule(const char* name) { 17 | return vt::CallMethod(this, 13, name, nullptr); 18 | } 19 | 20 | CSchemaClassInfo* CSchemaSystemTypeScope::FindDeclaredClass(const char* name) { 21 | CSchemaClassInfo* binding = nullptr; 22 | 23 | #if _WIN32 24 | vt::CallMethod(this, 2, &binding, name); 25 | #elif __linux__ 26 | binding = vt::CallMethod(this, 2, name); 27 | #endif 28 | 29 | return binding; 30 | } 31 | 32 | bool CSchemaClassInfo::InheritsFrom(CSchemaClassInfo* classToInherit) { 33 | if (classToInherit == this && classToInherit) { 34 | return true; 35 | } else if (!this || !m_BaseClasses || !classToInherit) { 36 | return false; 37 | } 38 | 39 | for (int i = 0; i < m_nBaseClassesCount; ++i) { 40 | auto& baseClass = m_BaseClasses[i]; 41 | if (baseClass.m_pClass->InheritsFrom(classToInherit)) { 42 | return true; 43 | } 44 | } 45 | 46 | return false; 47 | } 48 | -------------------------------------------------------------------------------- /cs2-sdk/src/hooks/hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | void CHooks::Initialize() { 13 | SDK_LOG_PROLOGUE(); 14 | 15 | CHook::s_FuncHookContext = funchook_create(); 16 | if (!CHook::s_FuncHookContext) { 17 | return CLogger::Log("[fh] funchook_create() failed!"); 18 | } 19 | 20 | CInputHooks::Get().Initialize(); 21 | CRenderHooks::Get().Initialize(); 22 | CGameHooks::Get().Initialize(); 23 | 24 | if (funchook_install(CHook::s_FuncHookContext, 0) != FUNCHOOK_ERROR_SUCCESS) { 25 | return CLogger::Log("[fh] funchook_install() failed!"); 26 | } 27 | } 28 | 29 | void CHooks::Shutdown() { 30 | SDK_LOG_PROLOGUE(); 31 | 32 | if (!CHook::s_FuncHookContext) return; 33 | 34 | CInputHooks::Get().Shutdown(); 35 | 36 | if (funchook_uninstall(CHook::s_FuncHookContext, 0) != FUNCHOOK_ERROR_SUCCESS) { 37 | return CLogger::Log("[fh] funchook_uninstall() failed!"); 38 | } 39 | 40 | std::this_thread::sleep_for(std::chrono::milliseconds(200)); 41 | } 42 | 43 | CHooks::~CHooks() { 44 | SDK_LOG_PROLOGUE(); 45 | 46 | if (!CHook::s_FuncHookContext) return; 47 | 48 | if (funchook_destroy(CHook::s_FuncHookContext) != FUNCHOOK_ERROR_SUCCESS) { 49 | CLogger::Log("[fh] funchook_destroy() failed!"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/textdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | textdefs.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2021 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef TEXTDEFS_H 13 | #define TEXTDEFS_H 14 | 15 | #include "config.h" 16 | #include "wstring.h" 17 | 18 | #ifndef DISTORM_LIGHT 19 | 20 | #define PLUS_DISP_CHR '+' 21 | #define MINUS_DISP_CHR '-' 22 | #define OPEN_CHR '[' 23 | #define CLOSE_CHR ']' 24 | #define SP_CHR ' ' 25 | #define SEG_OFF_CHR ':' 26 | 27 | /* 28 | Naming Convention: 29 | 30 | * get - returns a pointer to a string. 31 | * str - concatenates to string. 32 | 33 | * hex - means the function is used for hex dump (number is padded to required size) - Little Endian output. 34 | * code - means the function is used for disassembled instruction - Big Endian output. 35 | * off - means the function is used for 64bit offset - Big Endian output. 36 | 37 | * h - '0x' in front of the string. 38 | 39 | * b - byte 40 | * dw - double word (can be used for word also) 41 | * qw - quad word 42 | 43 | * all numbers are in HEX. 44 | */ 45 | 46 | void str_hex(_WString* s, const uint8_t* buf, unsigned int len); 47 | 48 | #ifdef SUPPORT_64BIT_OFFSET 49 | #define str_int(s, x) str_int_impl((s), (x)) 50 | void str_int_impl(unsigned char** s, uint64_t x); 51 | #else 52 | #define str_int(s, x) str_int_impl((s), (uint8_t*)&(x)) 53 | void str_int_impl(unsigned char** s, uint8_t src[8]); 54 | #endif 55 | 56 | #endif /* DISTORM_LIGHT */ 57 | 58 | #endif /* TEXTDEFS_H */ 59 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/interfaces/cvar.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | CCVar* CCVar::Get() { 14 | static const auto inst = CMemory::GetInterface(CConstants::TIER_LIB, "VEngineCvar007"); 15 | return inst.Get(); 16 | } 17 | 18 | CCVar::CVarIterator_t CCVar::GetFirstCvarIterator() { 19 | CVarIterator_t iterator = -1; 20 | 21 | #ifdef _WIN32 22 | vt::CallMethod(this, 12, &iterator); 23 | #elif __linux__ 24 | iterator = vt::CallMethod(this, 12); 25 | #endif 26 | 27 | return iterator; 28 | } 29 | 30 | CCVar::CVarIterator_t CCVar::GetNextCvarIterator(CVarIterator_t prev) { 31 | CVarIterator_t iterator = prev; 32 | 33 | #ifdef _WIN32 34 | vt::CallMethod(this, 13, &iterator, prev); 35 | #elif __linux__ 36 | iterator = vt::CallMethod(this, 13, prev); 37 | #endif 38 | 39 | return iterator; 40 | } 41 | 42 | ConVar* CCVar::GetCvarByIndex(CVarIterator_t index) { return vt::CallMethod(this, 37, index); } 43 | 44 | ConVar* CCVar::GetCvarByName(const char* name) { 45 | const uint32_t hash = FNV1A::Hash(name); 46 | 47 | CVarIterator_t it = GetFirstCvarIterator(); 48 | do { 49 | ConVar* cvar = GetCvarByIndex(it); 50 | 51 | if (cvar && FNV1A::Hash(cvar->m_Name) == hash) { 52 | CLogger::Log("[cvar] {} -> {}", name, SDK_LOG_PTR(cvar)); 53 | return cvar; 54 | } 55 | 56 | it = GetNextCvarIterator(it); 57 | } while (it != static_cast(-1)); 58 | 59 | CLogger::Log("[cvar] Couldn't find cvar named '{}'.", name); 60 | return nullptr; 61 | } 62 | -------------------------------------------------------------------------------- /cs2-sdk/src/cache/entities/base.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | 12 | bool CCachedBaseEntity::CanDoESP() { return Get() != nullptr; } 13 | 14 | void CCachedBaseEntity::DrawESP() { 15 | if (g_Vars.m_OtherBoxes) { 16 | DrawBoundingBox(IM_COL32(255, 255, 255, 255)); 17 | } 18 | } 19 | 20 | void CCachedBaseEntity::InvalidateDrawInfo() { m_BBox.Invalidate(); } 21 | 22 | void CCachedBaseEntity::CalculateDrawInfo() { 23 | C_BaseEntity* ent = Get(); 24 | 25 | if (!ent->CalculateBBoxByHitbox(m_BBox)) { 26 | return InvalidateDrawInfo(); 27 | } 28 | } 29 | 30 | void CCachedBaseEntity::DrawBoundingBox(ImU32 color) { 31 | static constexpr auto outlineColor = IM_COL32(0, 0, 0, 255); 32 | 33 | auto drawList = CRenderer::GetBackgroundDrawList(); 34 | 35 | if (g_Vars.m_Use3DBoxes) { 36 | for (int i = 0; i < 8; ++i) { 37 | for (int j = 1; j <= 4; j <<= 1) { 38 | if (!(i & j)) drawList->AddLine(m_BBox.m_Vertices[i], m_BBox.m_Vertices[i + j], outlineColor, 2.5f); 39 | } 40 | } 41 | 42 | for (int i = 0; i < 8; ++i) { 43 | for (int j = 1; j <= 4; j <<= 1) { 44 | if (!(i & j)) drawList->AddLine(m_BBox.m_Vertices[i], m_BBox.m_Vertices[i + j], color); 45 | } 46 | } 47 | } else { 48 | const ImVec2& min = m_BBox.m_Mins; 49 | const ImVec2& max = m_BBox.m_Maxs; 50 | 51 | drawList->AddRect(min - ImVec2{1.f, 1.f}, max + ImVec2{1.f, 1.f}, outlineColor); 52 | drawList->AddRect(min + ImVec2{1.f, 1.f}, max - ImVec2{1.f, 1.f}, outlineColor); 53 | drawList->AddRect(min, max, color); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /cs2-sdk/src/math/math.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | void CMath::UpdateViewMatrix(VMatrix* viewMatrix) { 8 | if (!viewMatrix) return; 9 | m_ViewMatrix = *viewMatrix; 10 | } 11 | 12 | bool CMath::WorldToScreen(const Vector& in, ImVec2& out) { 13 | if (!ImGui::GetCurrentContext()) return false; 14 | 15 | const float z = m_ViewMatrix[3][0] * in.x + m_ViewMatrix[3][1] * in.y + m_ViewMatrix[3][2] * in.z + m_ViewMatrix[3][3]; 16 | if (z < 0.001f) return false; 17 | 18 | out = ImGui::GetIO().DisplaySize * 0.5f; 19 | out.x *= 1.0f + (m_ViewMatrix[0][0] * in.x + m_ViewMatrix[0][1] * in.y + m_ViewMatrix[0][2] * in.z + m_ViewMatrix[0][3]) / z; 20 | out.y *= 1.0f - (m_ViewMatrix[1][0] * in.x + m_ViewMatrix[1][1] * in.y + m_ViewMatrix[1][2] * in.z + m_ViewMatrix[1][3]) / z; 21 | 22 | // Prevents rounded corners. 23 | out = ImTrunc(out); 24 | 25 | return true; 26 | } 27 | 28 | void CMath::TransformAABB(const matrix3x4_t& transform, const Vector& minsIn, const Vector& maxsIn, Vector& minsOut, Vector& maxsOut) { 29 | const Vector localCenter = (minsIn + maxsIn) * 0.5f; 30 | const Vector localExtent = maxsIn - localCenter; 31 | 32 | const auto& mat = transform.m_flMatVal; 33 | const Vector worldAxisX{mat[0][0], mat[0][1], mat[0][2]}; 34 | const Vector worldAxisY{mat[1][0], mat[1][1], mat[1][2]}; 35 | const Vector worldAxisZ{mat[2][0], mat[2][1], mat[2][2]}; 36 | 37 | const Vector worldCenter = localCenter.Transform(transform); 38 | const Vector worldExtent{ 39 | localExtent.DotProductAbsolute(worldAxisX), 40 | localExtent.DotProductAbsolute(worldAxisY), 41 | localExtent.DotProductAbsolute(worldAxisZ), 42 | }; 43 | 44 | minsOut = worldCenter - worldExtent; 45 | maxsOut = worldCenter + worldExtent; 46 | } 47 | -------------------------------------------------------------------------------- /cs2-sdk/src/hooks/input/sdl/sdl_hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | static std::once_flag g_InputInit; 17 | 18 | static CHook g_PeepEvents; 19 | static int hkPeepEvents(SDL_Event* events, int numevents, SDL_EventAction action, Uint32 minType, Uint32 maxType) { 20 | int rv = g_PeepEvents.CallOriginal(events, numevents, action, minType, maxType); 21 | if (rv == 0) return rv; 22 | 23 | for (int i = 0; i < numevents; ++i) { 24 | ImGuiContext* ctx = ImGui::GetCurrentContext(); 25 | SDL_Event& event = events[i]; 26 | if (!ctx && SDL_EVENT_WINDOW_FIRST <= event.type && event.type <= SDL_EVENT_WINDOW_LAST) { 27 | std::call_once(g_InputInit, [event]() { 28 | ImGui::CreateContext(); 29 | 30 | SDL_Window* window = SDL_GetWindowFromID(event.window.windowID); 31 | CLogger::Log("[sdl] SDL_Window -> {}", SDK_LOG_PTR(window)); 32 | 33 | ImGui_ImplSDL3_InitForVulkan(window); 34 | 35 | ImGuiIO& io = ImGui::GetIO(); 36 | io.IniFilename = io.LogFilename = nullptr; 37 | }); 38 | } else if (ctx) { 39 | ImGui_ImplSDL3_ProcessEvent(&event); 40 | if (CMenu::Get().IsOpen()) { 41 | event.type = SDL_EVENT_FIRST; 42 | } 43 | } 44 | } 45 | 46 | return rv; 47 | } 48 | 49 | void CSDLHooks::Initialize() { 50 | SDK_LOG_PROLOGUE(); 51 | 52 | auto peepEvents = CMemory::GetProcAddress(CConstants::SDL_LIB, "SDL_PeepEvents"); 53 | g_PeepEvents.Hook(peepEvents.Get(), SDK_HOOK(hkPeepEvents)); 54 | } 55 | -------------------------------------------------------------------------------- /cs2-sdk/src/instance/instance.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #ifdef _WIN32 12 | EXTERN_C IMAGE_DOS_HEADER __ImageBase; 13 | #endif 14 | 15 | void CInstance::Initialize() { 16 | SDK_LOG_PROLOGUE(); 17 | 18 | while (!AppFullyLoaded()) { 19 | std::this_thread::sleep_for(std::chrono::milliseconds(250)); 20 | } 21 | 22 | auto start = std::chrono::high_resolution_clock::now(); 23 | CMemory::Get().Initialize(); 24 | CHooks::Get().Initialize(); 25 | auto end = std::chrono::high_resolution_clock::now(); 26 | 27 | std::chrono::duration time = end - start; 28 | CLogger::Log("[benchmark] initialization has taken {}ms.", time.count()); 29 | } 30 | 31 | void CInstance::Shutdown() { 32 | SDK_LOG_PROLOGUE(); 33 | 34 | CHooks::Get().Shutdown(); 35 | } 36 | 37 | bool CInstance::AppFullyLoaded() { return CMemory::GetModule(CConstants::MATCHMAKING_LIB) != nullptr; } 38 | 39 | void CInstance::FreeLibrary() { 40 | SDK_LOG_PROLOGUE(); 41 | 42 | #ifdef _WIN32 43 | HANDLE hThread = CreateThread( 44 | NULL, 0, [](LPVOID pData) -> DWORD { FreeLibraryAndExitThread((HMODULE)(pData), EXIT_SUCCESS); }, (HINSTANCE)&__ImageBase, 0, NULL); 45 | 46 | if (hThread != NULL) { 47 | CloseHandle(hThread); 48 | } 49 | #else 50 | Dl_info info{}; 51 | if (dladdr(this, &info) != 0) { 52 | void* currLib = dlopen(info.dli_fname, RTLD_LAZY | RTLD_NOLOAD); 53 | if (currLib) { 54 | for (int i = 0; i < 2; ++i) { 55 | pthread_t thread; 56 | pthread_create(&thread, nullptr, reinterpret_cast(dlclose), currLib); 57 | pthread_detach(thread); 58 | } 59 | } 60 | } 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /cs2-sdk/src/memory/memory.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | void CMemory::Initialize() { 11 | SDK_LOG_PROLOGUE(); 12 | 13 | CSigScanManager::Get().ProcessScans(); 14 | } 15 | 16 | ModulePtr_t& CMemory::GetModuleInternal(const char* libName) { 17 | auto hash = FNV1A::Hash(libName); 18 | 19 | auto it = m_CachedModules.find(hash); 20 | if (it != m_CachedModules.end()) { 21 | return it->second; 22 | } 23 | 24 | auto module = std::make_unique(libName); 25 | if (module->Retrieve()) { 26 | CLogger::Log("[module] {} -> {}", libName, module->GetHandle()); 27 | return m_CachedModules.emplace(hash, std::move(module)).first->second; 28 | } 29 | 30 | CLogger::Log("[module] {} not found.", libName); 31 | 32 | static ModulePtr_t null{}; 33 | return null; 34 | } 35 | 36 | CPointer CMemory::GetInterfaceInternal(const char* libName, const char* version) { 37 | CPointer rv = 0; 38 | 39 | auto& library = CMemory::GetModuleInternal(libName); 40 | if (!library) { 41 | CLogger::Log("[interface] Couldn't retrieve {} because {} was not loaded", version, libName); 42 | return rv; 43 | } 44 | 45 | rv = library->GetInterface(FNV1A::Hash(version)); 46 | CLogger::Log("[interface] {} -> {} -> {}", libName, version, rv.Get()); 47 | 48 | return rv; 49 | } 50 | 51 | CPointer CMemory::GetProcAddressInternal(const char* libName, const char* procName) { 52 | CPointer rv = 0; 53 | 54 | auto& library = CMemory::GetModuleInternal(libName); 55 | if (!library) { 56 | CLogger::Log("[export] Couldn't retrieve {} because {} was not loaded.", procName, libName); 57 | return rv; 58 | } 59 | 60 | rv = library->GetProcAddress(procName); 61 | CLogger::Log("[export] {} -> {} -> {}", libName, procName, rv.Get()); 62 | 63 | return rv; 64 | } 65 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/include/interfaces/schemasystem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CSchemaSystemTypeScope; 4 | class CSchemaClassInfo; 5 | class CSchemaBaseClassInfo; 6 | class CSchemaClassField; 7 | 8 | class CSchemaSystem { 9 | public: 10 | static CSchemaSystem* Get(); 11 | 12 | CSchemaSystemTypeScope* FindTypeScopeForModule(const char* name); 13 | }; 14 | 15 | class CSchemaSystemTypeScope { 16 | public: 17 | CSchemaClassInfo* FindDeclaredClass(const char* name); 18 | }; 19 | 20 | struct SchemaClassInfoData_t { 21 | char pad0[0x8]; // 0x00 22 | const char* m_Name; // 0x08 23 | const char* m_Description; // 0x10 24 | int32_t m_nSizeOf; // 0x18 25 | uint8_t m_nFieldsCount; // 0x1C 26 | char pad1[0x5]; // 0x1D 27 | uint8_t m_nAlignOf; // 0x22 28 | uint8_t m_nBaseClassesCount; // 0x23 29 | char pad2[0x4]; // 0x24 30 | CSchemaClassField* m_Fields; // 0x28 31 | char pad3[0x8]; // 0x30 32 | CSchemaBaseClassInfo* m_BaseClasses; // 0x38 33 | char pad4[0x28]; // 0x40 34 | }; 35 | 36 | class CSchemaClassInfo : public SchemaClassInfoData_t { 37 | public: 38 | // Full implementation here: 39 | // https://github.com/neverlosecc/source2gen/blob/fc4f43dfc65dd47c9eb118ce1646a5ccf90a00f0/include/sdk/interfaces/schemasystem/schema.h#L267-L309 40 | 41 | bool InheritsFrom(CSchemaClassInfo* classToInherit); 42 | }; 43 | 44 | struct SchemaBaseClassInfoData_t { 45 | int32_t m_nOffset; 46 | CSchemaClassInfo* m_pClass; 47 | }; 48 | 49 | class CSchemaBaseClassInfo : public SchemaBaseClassInfoData_t { 50 | public: 51 | }; 52 | 53 | struct SchemaClassFieldData_t { 54 | const char* m_Name; 55 | char pad0[0x8]; 56 | int32_t m_nSingleInheritanceOffset; 57 | char pad1[0xC]; 58 | }; 59 | 60 | class CSchemaClassField : public SchemaClassFieldData_t { 61 | public: 62 | }; 63 | -------------------------------------------------------------------------------- /cs2-sdk/src/sigscan/sigscan.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | CSigScan::CSigScan(const char* signatureName, const char* libraryName, const std::initializer_list& data) { 9 | #ifdef SDK_ENABLE_LOGGING 10 | m_Name = signatureName; 11 | #else 12 | m_Name = ""; 13 | #endif 14 | 15 | m_LibraryName = libraryName; 16 | 17 | m_Data.reserve(data.size()); 18 | m_Data.insert(m_Data.end(), data.begin(), data.end()); 19 | 20 | CSigScanManager::Get().ScheduleScan(this); 21 | } 22 | 23 | void CSigScan::FindSignature() { 24 | auto& library = CMemory::GetModule(m_LibraryName); 25 | if (!library) { 26 | return CLogger::Log("[signature] Couldn't find {} because {} was not loaded.", m_Name, m_LibraryName); 27 | } 28 | 29 | for (size_t i = 0; i < m_Data.size(); ++i) { 30 | // Faster than m_Data[] in debug builds because of _STL_VERIFY. 31 | const auto& data = m_Data.data()[i]; 32 | 33 | m_Value = library->FindPattern(data.m_Signature); 34 | if (m_Value.IsValid()) { 35 | if (data.m_Procedure) { 36 | data.m_Procedure(m_Value); 37 | } 38 | 39 | return CLogger::Log("[signature] {} -> {} [{}]", m_Name, m_Value.Get(), i); 40 | } 41 | } 42 | 43 | CLogger::Log("[signature] {} was not found!", m_Name); 44 | } 45 | 46 | void CSigScanManager::ScheduleScan(CSigScan* sigScan) { m_ScheduledScans.emplace_back(sigScan); } 47 | 48 | void CSigScanManager::ProcessScans() { 49 | for (size_t i = 0; i < m_ScheduledScans.size(); ++i) { 50 | // Faster than m_ScheduledScans[] in debug builds because of _STL_VERIFY. 51 | const auto& scheduledScan = m_ScheduledScans.data()[i]; 52 | 53 | scheduledScan->FindSignature(); 54 | scheduledScan->FreeData(); 55 | } 56 | 57 | // No need to keep the scans in memory if we're done with them. 58 | std::vector().swap(m_ScheduledScans); 59 | } 60 | -------------------------------------------------------------------------------- /cs2-sdk/include/sigscan/sigscan.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* 6 | * CSigScan usage: (Should be used with stb.hh, see signatures.h for SDK_SIG) 7 | * 8 | * Can be passed multiple signatures, the first FOUND signature is FINAL. 9 | * Third argument is a list that consists of a signature and procedure. 10 | * Procedure: Lambda passed after the signature that tells what's 11 | done to the pointer after being successfully found. 12 | * 13 | * CSigScan variable(signatureName, libraryName, { 14 | * 1. {SDK_SIG("8B D3 E8 ?")}, 15 | * 2. {SDK_SIG("8B D3 E8 ?"), [](CPointer& ptr) { ptr.Absolute(3, 0); }}, 16 | * 3. ..., 17 | * 4. ..., 18 | * }); 19 | * 20 | * See also CPointer usage for GetPtr() and GetPtrAs(). 21 | */ 22 | class CSigScan { 23 | public: 24 | using ProcedureFn = std::function; 25 | 26 | struct SigData_t { 27 | std::span m_Signature; 28 | ProcedureFn m_Procedure; 29 | }; 30 | 31 | CSigScan(const char* signatureName, const char* libraryName, const std::initializer_list& data); 32 | 33 | auto GetPtr() const { return m_Value; } 34 | 35 | template 36 | auto GetPtrAs() const { 37 | return m_Value.Get(); 38 | } 39 | 40 | CSigScan(const CSigScan&) = delete; 41 | CSigScan& operator=(const CSigScan&) = delete; 42 | 43 | private: 44 | friend class CSigScanManager; 45 | 46 | void FindSignature(); 47 | auto FreeData() { std::vector().swap(m_Data); } 48 | 49 | const char* m_Name; 50 | const char* m_LibraryName; 51 | 52 | std::vector m_Data; 53 | 54 | CPointer m_Value; 55 | }; 56 | 57 | class CSigScanManager { 58 | public: 59 | static CSigScanManager& Get() { 60 | static CSigScanManager inst; 61 | return inst; 62 | } 63 | 64 | void ScheduleScan(CSigScan* sigScan); 65 | void ProcessScans(); 66 | 67 | private: 68 | std::vector m_ScheduledScans; 69 | }; 70 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/insts.h: -------------------------------------------------------------------------------- 1 | /* 2 | insts.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2021 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef INSTS_H 13 | #define INSTS_H 14 | 15 | #include "instructions.h" 16 | 17 | 18 | /* Flags Table */ 19 | extern _iflags FlagsTable[]; 20 | 21 | /* Root Trie DB */ 22 | extern _InstSharedInfo InstSharedInfoTable[]; 23 | extern _InstInfo InstInfos[]; 24 | extern _InstInfoEx InstInfosEx[]; 25 | extern _InstNode InstructionsTree[]; 26 | 27 | /* 3DNow! Trie DB */ 28 | extern _InstNode Table_0F_0F; 29 | /* AVX related: */ 30 | extern _InstNode Table_0F, Table_0F_38, Table_0F_3A; 31 | 32 | /* 33 | * The inst_lookup will return on of these two instructions according to the specified decoding mode. 34 | * ARPL or MOVSXD on 64 bits is one byte instruction at index 0x63. 35 | */ 36 | extern _InstInfo II_MOVSXD; 37 | 38 | /* 39 | * The NOP instruction can be prefixed by REX in 64bits, therefore we have to decide in runtime whether it's an XCHG or NOP instruction. 40 | * If 0x90 is prefixed by a usable REX it will become XCHG, otherwise it will become a NOP. 41 | * Also note that if it's prefixed by 0xf3, it becomes a Pause. 42 | */ 43 | extern _InstInfo II_NOP; 44 | extern _InstInfo II_PAUSE; 45 | 46 | /* 47 | * RDRAND and VMPTRLD share same 2.3 bytes opcode, and then alternates on the MOD bits, 48 | * RDRAND is OT_FULL_REG while VMPTRLD is OT_MEM, and there's no such mixed type. 49 | * So a hack into the inst_lookup was added for this decision, the DB isn't flexible enough. :( 50 | */ 51 | extern _InstInfo II_RDRAND; 52 | 53 | /* 54 | * Used for letting the extract operand know the type of operands without knowing the 55 | * instruction itself yet, because of the way those instructions work. 56 | * See function instructions.c!inst_lookup_3dnow. 57 | */ 58 | extern _InstInfo II_3DNOW; 59 | 60 | /* Helper tables for pseudo compare mnemonics. */ 61 | extern uint16_t CmpMnemonicOffsets[8]; /* SSE */ 62 | extern uint16_t VCmpMnemonicOffsets[32]; /* AVX */ 63 | 64 | #endif /* INSTS_H */ 65 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/x86defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | x86defs.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2021 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef X86DEFS_H 13 | #define X86DEFS_H 14 | 15 | 16 | #define SEG_REGS_MAX (6) 17 | #define CREGS_MAX (9) 18 | #define DREGS_MAX (8) 19 | 20 | /* Maximum instruction size, including prefixes */ 21 | #define INST_MAXIMUM_SIZE (15) 22 | 23 | /* Maximum range of imm8 (comparison type) of special SSE CMP instructions. */ 24 | #define INST_CMP_MAX_RANGE (8) 25 | 26 | /* Maximum range of imm8 (comparison type) of special AVX VCMP instructions. */ 27 | #define INST_VCMP_MAX_RANGE (32) 28 | 29 | /* Wait instruction byte code. */ 30 | #define INST_WAIT_INDEX (0x9b) 31 | 32 | /* Lea instruction byte code. */ 33 | #define INST_LEA_INDEX (0x8d) 34 | 35 | /* NOP/XCHG instruction byte code. */ 36 | #define INST_NOP_INDEX (0x90) 37 | 38 | /* ARPL/MOVSXD instruction byte code. */ 39 | #define INST_ARPL_INDEX (0x63) 40 | 41 | /* 42 | * Minimal MODR/M value of divided instructions. 43 | * It's 0xc0, two MSBs set, which indicates a general purpose register is used too. 44 | */ 45 | #define INST_DIVIDED_MODRM (0xc0) 46 | 47 | /* This is the escape byte value used for 3DNow! instructions. */ 48 | #define _3DNOW_ESCAPE_BYTE (0x0f) 49 | 50 | #define PREFIX_LOCK (0xf0) 51 | #define PREFIX_REPNZ (0xf2) 52 | #define PREFIX_REP (0xf3) 53 | #define PREFIX_CS (0x2e) 54 | #define PREFIX_SS (0x36) 55 | #define PREFIX_DS (0x3e) 56 | #define PREFIX_ES (0x26) 57 | #define PREFIX_FS (0x64) 58 | #define PREFIX_GS (0x65) 59 | #define PREFIX_OP_SIZE (0x66) 60 | #define PREFIX_ADDR_SIZE (0x67) 61 | #define PREFIX_VEX2b (0xc5) 62 | #define PREFIX_VEX3b (0xc4) 63 | 64 | /* REX prefix value range, 64 bits mode decoding only. */ 65 | #define PREFIX_REX_LOW (0x40) 66 | #define PREFIX_REX_HI (0x4f) 67 | /* In order to use the extended GPR's we have to add 8 to the Modr/M info values. */ 68 | #define EX_GPR_BASE (8) 69 | 70 | /* Mask for REX and VEX features: */ 71 | /* Base */ 72 | #define PREFIX_EX_B (1) 73 | /* Index */ 74 | #define PREFIX_EX_X (2) 75 | /* Register */ 76 | #define PREFIX_EX_R (4) 77 | /* Operand Width */ 78 | #define PREFIX_EX_W (8) 79 | /* Vector Lengh */ 80 | #define PREFIX_EX_L (0x10) 81 | 82 | #endif /* X86DEFS_H */ 83 | -------------------------------------------------------------------------------- /cs2-sdk/libs/imgui/imgui_impl_dx11.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX11 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset). 7 | // [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'. 8 | 9 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 10 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 11 | // Learn about Dear ImGui: 12 | // - FAQ https://dearimgui.com/faq 13 | // - Getting Started https://dearimgui.com/getting-started 14 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 15 | // - Introduction, links and more at the top of imgui.cpp 16 | 17 | #pragma once 18 | #include "imgui.h" // IMGUI_IMPL_API 19 | #ifndef IMGUI_DISABLE 20 | 21 | struct ID3D11Device; 22 | struct ID3D11DeviceContext; 23 | struct ID3D11SamplerState; 24 | struct ID3D11Buffer; 25 | 26 | // Follow "Getting Started" link and check examples/ folder to learn about using backends! 27 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 28 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 29 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 30 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 31 | 32 | // Use if you want to reset your rendering device without losing Dear ImGui state. 33 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 34 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 35 | 36 | // [BETA] Selected render state data shared with callbacks. 37 | // This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplDX11_RenderDrawData() call. 38 | // (Please open an issue if you feel you need access to more data) 39 | struct ImGui_ImplDX11_RenderState 40 | { 41 | ID3D11Device* Device; 42 | ID3D11DeviceContext* DeviceContext; 43 | ID3D11SamplerState* SamplerDefault; 44 | ID3D11Buffer* VertexConstantBuffer; 45 | }; 46 | 47 | #endif // #ifndef IMGUI_DISABLE 48 | -------------------------------------------------------------------------------- /cs2-sdk/libs/funchook/src/funchook_x86.h: -------------------------------------------------------------------------------- 1 | /* -*- indent-tabs-mode: nil -*- 2 | * 3 | * This file is part of Funchook. 4 | * https://github.com/kubo/funchook 5 | * 6 | * Funchook is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation, either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * As a special exception, the copyright holders of this library give you 12 | * permission to link this library with independent modules to produce an 13 | * executable, regardless of the license terms of these independent 14 | * modules, and to copy and distribute the resulting executable under 15 | * terms of your choice, provided that you also meet, for each linked 16 | * independent module, the terms and conditions of the license of that 17 | * module. An independent module is a module which is not derived from or 18 | * based on this library. If you modify this library, you may extend this 19 | * exception to your version of the library, but you are not obliged to 20 | * do so. If you do not wish to do so, delete this exception statement 21 | * from your version. 22 | * 23 | * Funchook is distributed in the hope that it will be useful, but WITHOUT 24 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26 | * for more details. 27 | * 28 | * You should have received a copy of the GNU General Public License 29 | * along with Funchook. If not, see . 30 | */ 31 | #ifndef FUNCHOOK_X86_H 32 | #define FUNCHOOK_X86_H 1 33 | 34 | #define MAX_INSN_LEN 16 35 | #define MAX_INSN_CHECK_SIZE 256 36 | 37 | #define JUMP32_SIZE 5 38 | #ifdef CPU_X86_64 39 | #define JUMP64_SIZE 14 40 | #endif 41 | 42 | #define TRAMPOLINE_SIZE (JUMP32_SIZE + (MAX_INSN_LEN - 1) + JUMP32_SIZE) 43 | 44 | typedef uint8_t insn_t; 45 | 46 | typedef struct funchook_entry { 47 | void *target_func; 48 | void *hook_func; 49 | uint8_t trampoline[TRAMPOLINE_SIZE]; 50 | uint8_t old_code[JUMP32_SIZE]; 51 | uint8_t new_code[JUMP32_SIZE]; 52 | #ifdef CPU_X86_64 53 | uint8_t transit[JUMP64_SIZE]; 54 | #endif 55 | } funchook_entry_t; 56 | 57 | typedef struct { 58 | const insn_t *dst_addr; 59 | intptr_t src_addr_offset; 60 | intptr_t pos_offset; 61 | } ip_displacement_entry_t; 62 | 63 | typedef struct { 64 | ip_displacement_entry_t disp[2]; 65 | } ip_displacement_t; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /cs2-sdk/src/hooks/game/game_hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #include

2 | cs2-sdk 3 | 4 | 5 | 6 | 7 |

8 | 9 |

10 | EDUCATIONAL PURPOSES ONLY 11 |

12 | 13 | ## What's this? 14 | Counter-Strike 2 SDK written in C++ to aid your development. This SDK has been written as simplified as possible and kept as close as possible to Source 2 code supporting both DirectX11 and Vulkan graphical APIs. I'll keep the project updated if I have time, project's features can be seen in the picture below. 15 | 16 | ## What's different from v1? 17 | Now supports both Windows and Linux, main base logic has been refactored. I've gotten rid of the 'Inventory Changer' and skins altogether since I don't have the time to maintain them anymore, v1 can be found [here](https://github.com/bruhmoment21/cs2-sdk/tree/v1) and won't receive any updates from now on. 18 | 19 | ## Injection 20 | *(⚠️ This also applies for **v1**.)* 21 | *(⚠️ **Manual mapping** will break unloading.)* 22 | 23 | ### Windows 24 | - ✅ LoadLibrary - Works as expected. 25 | - ⚠️ Manual map - `/Zc:threadSafeInit-` flag is required. C/C++ -> Command Line -> Additional Options. 26 | ### Linux 27 | - ✅ dlopen - Works as expected. 28 | 29 | ## Detection ❗ 30 | *(⚠️ This also applies for **v1**.)* 31 | 32 | The base should be **DETECTED** since the base uses generic approaches such as *trampoline hooking*. Hence the detection I recommend just seeing how stuff is done/works to try to implement it in your own project. Be creative! 33 | 34 | ## Building 35 | ### Windows 36 | - Open `cs2-sdk.sln` with Visual Studio 2022 and Build Solution or `Ctrl+Shift+B`. Select the `Release` configuration if you don't plan on debugging and also [disable logging](https://github.com/bruhmoment21/cs2-sdk/blob/v2/cs2-sdk/include/logger/logger.hpp#L3-L4) if not necessary. 37 | ### Linux 38 | - Create a binary folder and use CMake after going in the directory, what's left is to build the library. Here's what it should look like: 39 | `mkdir binlinux && cd binlinux && cmake ../ && make` 40 | 41 | ## Media 42 | ![image](https://github.com/bruhmoment21/cs2-sdk/assets/53657322/d19eeea9-3309-4fa2-804c-ca5b7e84f319) 43 | ![image](https://github.com/user-attachments/assets/2a4a1dd9-88dc-4dc6-a70d-c332c3f1f32d) 44 | 45 | ## Dependencies 46 | - [funchook](https://github.com/kubo/funchook) - hooking 47 | - [distorm](https://github.com/gdabah/distorm/) - disassembler 48 | - [imgui](https://github.com/ocornut/imgui) - gui 49 | - [STB](https://github.com/cristeigabriel/STB) - signatures 50 | ### Windows 51 | - [Vulkan](https://vulkan.lunarg.com/) - [vulkan_hooks.cpp](https://github.com/bruhmoment21/cs2-sdk/blob/v2/cs2-sdk/src/hooks/render/vulkan/vulkan_hooks.cpp#L6-L9) 52 | ### Linux 53 | - [SDL3](https://archlinux.org/packages/extra/x86_64/sdl3/) - input 54 | - [Vulkan](https://archlinux.org/packages/extra/any/vulkan-headers/) - rendering 55 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/prefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | prefix.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2021 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef PREFIX_H 13 | #define PREFIX_H 14 | 15 | #include "config.h" 16 | #include "decoder.h" 17 | 18 | 19 | /* Specifies the type of the extension prefix, such as: REX, 2 bytes VEX, 3 bytes VEX. */ 20 | typedef enum {PET_NONE = 0, PET_REX, PET_VEX2BYTES, PET_VEX3BYTES} _PrefixExtType; 21 | 22 | /* Specifies an index into a table of prefixes by their type. */ 23 | typedef enum {PFXIDX_NONE = -1, PFXIDX_REX, PFXIDX_LOREP, PFXIDX_SEG, PFXIDX_OP_SIZE, PFXIDX_ADRS, PFXIDX_MAX} _PrefixIndexer; 24 | 25 | /* 26 | * This holds the prefixes state for the current instruction we decode. 27 | * decodedPrefixes includes all specific prefixes that the instruction got. 28 | * start is a pointer to the first prefix to take into account. 29 | * last is a pointer to the last byte we scanned. 30 | * Other pointers are used to keep track of prefixes positions and help us know if they appeared already and where. 31 | */ 32 | typedef struct { 33 | _iflags decodedPrefixes, usedPrefixes; 34 | /* Number of prefixes scanned for current instruction, including VEX! */ 35 | unsigned int count; 36 | uint16_t unusedPrefixesMask; 37 | /* Holds the offset to the prefix byte by its type. */ 38 | uint16_t pfxIndexer[PFXIDX_MAX]; 39 | _PrefixExtType prefixExtType; 40 | /* Indicates whether the operand size prefix (0x66) was used as a mandatory prefix. */ 41 | int isOpSizeMandatory; 42 | /* If VEX prefix is used, store the VEX.vvvv field. */ 43 | unsigned int vexV; 44 | /* The fields B/X/R/W/L of REX and VEX are stored together in this byte. */ 45 | unsigned int vrex; 46 | const uint8_t* vexPos; 47 | } _PrefixState; 48 | 49 | /* 50 | * Intel supports 6 types of prefixes, whereas AMD supports 5 types (lock is seperated from rep/nz). 51 | * REX is the fifth prefix type, this time I'm based on AMD64. 52 | * VEX is the 6th, though it can't be repeated. 53 | */ 54 | #define MAX_PREFIXES (5) 55 | 56 | extern int PrefixTables[256 * 2]; 57 | 58 | _INLINE_ int prefixes_is_valid(unsigned char ch, _DecodeType dt) 59 | { 60 | /* The predicate selects (branchlessly) second half table for 64 bits otherwise selects first half. */ 61 | return PrefixTables[ch + ((dt >> 1) << 8)]; 62 | } 63 | 64 | /* Ignore a specific prefix type. */ 65 | _INLINE_ void prefixes_ignore(_PrefixState* ps, _PrefixIndexer pi) 66 | { 67 | /* 68 | * If that type of prefix appeared already, set the bit of that *former* prefix. 69 | * Anyway, set the new index of that prefix type to the current index, so next time we know its position. 70 | */ 71 | ps->unusedPrefixesMask |= ps->pfxIndexer[pi]; 72 | } 73 | 74 | void prefixes_ignore_all(_PrefixState* ps); 75 | uint16_t prefixes_set_unused_mask(_PrefixState* ps); 76 | void prefixes_decode(_CodeInfo* ci, _PrefixState* ps); 77 | void prefixes_use_segment(_iflags defaultSeg, _PrefixState* ps, _DecodeType dt, _DInst* di); 78 | 79 | #endif /* PREFIX_H */ 80 | -------------------------------------------------------------------------------- /cs2-sdk/libs/imgui/imgui_impl_sdl3.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for SDL3 2 | // This needs to be used along with a Renderer (e.g. SDL_GPU, DirectX11, OpenGL3, Vulkan..) 3 | // (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen. 8 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values are obsolete since 1.87 and not supported since 1.91.5] 9 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 10 | // [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 11 | // [X] Platform: IME support. 12 | 13 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 14 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 15 | // Learn about Dear ImGui: 16 | // - FAQ https://dearimgui.com/faq 17 | // - Getting Started https://dearimgui.com/getting-started 18 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 19 | // - Introduction, links and more at the top of imgui.cpp 20 | 21 | #pragma once 22 | #include "imgui.h" // IMGUI_IMPL_API 23 | #ifndef IMGUI_DISABLE 24 | 25 | struct SDL_Window; 26 | struct SDL_Renderer; 27 | struct SDL_Gamepad; 28 | typedef union SDL_Event SDL_Event; 29 | 30 | // Follow "Getting Started" link and check examples/ folder to learn about using backends! 31 | IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); 32 | IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window); 33 | IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window); 34 | IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window); 35 | IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer); 36 | IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLGPU(SDL_Window* window); 37 | IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOther(SDL_Window* window); 38 | IMGUI_IMPL_API void ImGui_ImplSDL3_Shutdown(); 39 | IMGUI_IMPL_API void ImGui_ImplSDL3_NewFrame(); 40 | IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event); 41 | 42 | // Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. You may override this. 43 | // When using manual mode, caller is responsible for opening/closing gamepad. 44 | enum ImGui_ImplSDL3_GamepadMode { ImGui_ImplSDL3_GamepadMode_AutoFirst, ImGui_ImplSDL3_GamepadMode_AutoAll, ImGui_ImplSDL3_GamepadMode_Manual }; 45 | IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array = nullptr, int manual_gamepads_count = -1); 46 | 47 | #endif // #ifndef IMGUI_DISABLE 48 | -------------------------------------------------------------------------------- /cs2-sdk/src/hooks/input/wndproc/wndproc_hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | static WNDPROC g_WndProc; 11 | static std::once_flag g_InputInit; 12 | 13 | static LRESULT hkWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 14 | std::call_once(g_InputInit, [hWnd]() { 15 | ImGui::CreateContext(); 16 | ImGui_ImplWin32_Init(hWnd); 17 | ImGuiIO &io = ImGui::GetIO(); 18 | io.IniFilename = io.LogFilename = nullptr; 19 | }); 20 | 21 | LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 22 | ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam); 23 | if (CMenu::Get().IsOpen()) { 24 | // Messages handled by 'ImGui_ImplWin32_WndProcHandler'. 25 | switch (uMsg) { 26 | case WM_MOUSEMOVE: 27 | case WM_NCMOUSEMOVE: 28 | case WM_MOUSELEAVE: 29 | case WM_NCMOUSELEAVE: 30 | case WM_LBUTTONDOWN: 31 | case WM_LBUTTONDBLCLK: 32 | case WM_RBUTTONDOWN: 33 | case WM_RBUTTONDBLCLK: 34 | case WM_MBUTTONDOWN: 35 | case WM_MBUTTONDBLCLK: 36 | case WM_XBUTTONDOWN: 37 | case WM_XBUTTONDBLCLK: 38 | case WM_LBUTTONUP: 39 | case WM_RBUTTONUP: 40 | case WM_MBUTTONUP: 41 | case WM_XBUTTONUP: 42 | case WM_MOUSEWHEEL: 43 | case WM_MOUSEHWHEEL: 44 | case WM_KEYDOWN: 45 | case WM_KEYUP: 46 | case WM_SYSKEYDOWN: 47 | case WM_SYSKEYUP: 48 | case WM_SETFOCUS: 49 | case WM_KILLFOCUS: 50 | case WM_CHAR: 51 | case WM_SETCURSOR: 52 | case WM_DEVICECHANGE: 53 | return 1; 54 | } 55 | } 56 | 57 | return CallWindowProc(g_WndProc, hWnd, uMsg, wParam, lParam); 58 | } 59 | 60 | static BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam) { 61 | const auto isMainWindow = [handle]() { 62 | return GetWindow(handle, GW_OWNER) == nullptr && IsWindowVisible(handle) && handle != GetConsoleWindow(); 63 | }; 64 | 65 | DWORD pID = 0; 66 | GetWindowThreadProcessId(handle, &pID); 67 | 68 | if (GetCurrentProcessId() != pID || !isMainWindow()) { 69 | return TRUE; 70 | } 71 | 72 | *reinterpret_cast(lParam) = handle; 73 | return FALSE; 74 | } 75 | 76 | void CWndProcHooks::Initialize() { 77 | SDK_LOG_PROLOGUE(); 78 | 79 | EnumWindows(::EnumWindowsCallback, reinterpret_cast(&m_Window)); 80 | if (!m_Window) { 81 | return CLogger::Log("[wndproc] EnumWindows() returned nullptr!"); 82 | } 83 | 84 | CLogger::Log("[wndproc] CWndProcHooks::m_Window -> {}", SDK_LOG_PTR(m_Window)); 85 | g_WndProc = reinterpret_cast(SetWindowLongPtr(m_Window, GWLP_WNDPROC, reinterpret_cast(hkWndProc))); 86 | } 87 | 88 | void CWndProcHooks::Shutdown() { 89 | SDK_LOG_PROLOGUE(); 90 | 91 | if (g_WndProc) { 92 | SetWindowLongPtr(m_Window, GWLP_WNDPROC, reinterpret_cast(g_WndProc)); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /cs2-sdk/include/schemamgr/schema_manager.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | /* 7 | * Basic usage of schemas: 8 | * 9 | * 1. SCHEMA(Type, fieldName, "ClassToFindField", "fieldNameInClass"); 10 | * 2. SCHEMA_EXTENDED(Type, fieldName, "ClassToFindField", "fieldNameInClass", extraOffset); 11 | * 12 | * PSCHEMA and PSCHEMA_EXTENDED has the same usage as SCHEMA but for pointers. 13 | * 14 | * SCHEMA_EXTENDED is used for specific fields that don't explicitly appear 15 | * in the CSchemaClassInfo* but we know they exist so we will find them 16 | * through another field that exists. 17 | * Example: 18 | * class BaseEntity { 19 | * ... // 0xFFF 20 | * int m_SomeValue; // 0x1000 21 | * int m_SomeHiddenValue; // 0x1004 22 | * }; 23 | * m_SomeHiddenValue doesn't appear in the CSchemaClassInfo* of class but we know its below 24 | * m_SomeValue that appears in the CSchemaClassInfo* and its just below it so right after 4 bytes. 25 | * Usage: SCHEMA_EXTENDED(int, m_SomeHiddenValue, "BaseEntity", "m_SomeValue", 4); 26 | */ 27 | 28 | class CSchemaManager { 29 | public: 30 | static CSchemaManager& Get() { 31 | static CSchemaManager inst; 32 | return inst; 33 | } 34 | 35 | static auto GetSchemaOffset(const char* moduleName, const char* bindingName, const char* fieldName) { 36 | return Get().GetSchemaOffsetInternal(moduleName, bindingName, fieldName); 37 | } 38 | 39 | private: 40 | std::optional GetSchemaOffsetInternal(const char* moduleName, const char* bindingName, const char* fieldName); 41 | }; 42 | 43 | #define SCHEMA_EXTENDED(type, name, module_name, binding_name, field_name, extra_offset) \ 44 | std::add_lvalue_reference_t name() const { \ 45 | static const auto offset = CSchemaManager::GetSchemaOffset(module_name, binding_name, field_name); \ 46 | if (offset) return CPointer(this).GetField(offset.value() + extra_offset); \ 47 | static type null{}; \ 48 | return null; \ 49 | } 50 | 51 | #define SCHEMA(type, name, binding_name, field_name) SCHEMA_EXTENDED(type, name, CConstants::CLIENT_LIB, binding_name, field_name, 0) 52 | 53 | #define PSCHEMA_EXTENDED(type, name, module_name, binding_name, field_name, extra_offset) \ 54 | std::add_pointer_t name() const { \ 55 | static const auto offset = CSchemaManager::GetSchemaOffset(module_name, binding_name, field_name); \ 56 | if (offset) return CPointer(this).GetFieldPtr(offset.value() + extra_offset).Get>(); \ 57 | return nullptr; \ 58 | } 59 | 60 | #define PSCHEMA(type, name, binding_name, field_name) PSCHEMA_EXTENDED(type, name, CConstants::CLIENT_LIB, binding_name, field_name, 0) 61 | -------------------------------------------------------------------------------- /cs2-sdk/libs/imgui/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for Windows (standard windows API for 32-bits AND 64-bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. 7 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values are obsolete since 1.87 and not supported since 1.91.5] 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | // [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 10 | 11 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 12 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 13 | // Learn about Dear ImGui: 14 | // - FAQ https://dearimgui.com/faq 15 | // - Getting Started https://dearimgui.com/getting-started 16 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 17 | // - Introduction, links and more at the top of imgui.cpp 18 | 19 | #pragma once 20 | #include "imgui.h" // IMGUI_IMPL_API 21 | #ifndef IMGUI_DISABLE 22 | 23 | // Follow "Getting Started" link and check examples/ folder to learn about using backends! 24 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 25 | IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); 26 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 27 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 28 | 29 | // Win32 message handler your application need to call. 30 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 31 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 32 | // - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. 33 | 34 | #if 0 35 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 36 | #endif 37 | 38 | // DPI-related helpers (optional) 39 | // - Use to enable DPI awareness without having to create an application manifest. 40 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 41 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 42 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 43 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 44 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 45 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 46 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 47 | 48 | // Transparency related helpers (optional) [experimental] 49 | // - Use to enable alpha compositing transparency with the desktop. 50 | // - Use together with e.g. clearing your framebuffer with zero-alpha. 51 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd); // HWND hwnd 52 | 53 | #endif // #ifndef IMGUI_DISABLE 54 | -------------------------------------------------------------------------------- /cs2-sdk/src/cache/entities/player.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | bool CCachedPlayer::CanDoESP() { 18 | CCSPlayerController* controller = Get(); 19 | if (!controller || !controller->m_bPawnIsAlive()) { 20 | return false; 21 | } 22 | 23 | C_CSPlayerPawnBase* pawn = controller->m_hPawn().Get(); 24 | if (!pawn || pawn->IsObserverPawn()) { 25 | return false; 26 | } 27 | 28 | return true; 29 | } 30 | 31 | void CCachedPlayer::DrawESP() { 32 | CCachedPlayer* cachedLocalPlayer = CMatchCache::Get().GetLocalPlayer(); 33 | if (!cachedLocalPlayer) { 34 | return InvalidateDrawInfo(); 35 | } 36 | 37 | auto drawList = CRenderer::GetBackgroundDrawList(); 38 | 39 | const ImVec2& min = m_BBox.m_Mins; 40 | const ImVec2& max = m_BBox.m_Maxs; 41 | 42 | CCSPlayerController* controller = Get(); 43 | C_CSPlayerPawnBase* pawn = controller->m_hPawn().Get(); 44 | 45 | if (g_Vars.m_PlayerBoxes) { 46 | DrawBoundingBox([this, cachedLocalPlayer]() { 47 | if (IsLocalPlayer()) { 48 | return IM_COL32(52, 131, 235, 255); 49 | } else if (IsEnemyWithTeam(cachedLocalPlayer->GetTeam())) { 50 | return IM_COL32(255, 0, 0, 255); 51 | } 52 | 53 | return IM_COL32(0, 255, 0, 255); 54 | }()); 55 | } 56 | 57 | if (g_Vars.m_PlayerNames) { 58 | const char* playerName = controller->m_sSanitizedPlayerName(); 59 | if (playerName) { 60 | const ImVec2 textSize = ImGui::CalcTextSize(playerName); 61 | const ImVec2 textPos = ImTrunc({(min.x + max.x - textSize.x) * 0.5f, min.y - textSize.y - 2.f}); 62 | 63 | drawList->AddText(textPos + ImVec2{1, 1}, IM_COL32(0, 0, 0, 255), playerName); 64 | drawList->AddText(textPos, IM_COL32(255, 255, 255, 255), playerName); 65 | } 66 | } 67 | 68 | if (g_Vars.m_PlayerHealthBar) { 69 | const int clampedHp = std::min(pawn->m_iHealth(), 100); 70 | 71 | const ImVec2 barMin = min - ImVec2{5, 0}; 72 | const ImVec2 barMax{min.x - 2, max.y}; 73 | 74 | const float green = clampedHp * 2.f * 2.55f; 75 | const float greenClamped = (std::min)(255.f, green); 76 | const float red = (std::min)(255.f, 510 - green); 77 | 78 | const float height = ((barMax.y - barMin.y) * clampedHp) / 100.f; 79 | 80 | drawList->AddRectFilled(barMin - ImVec2{0, 1}, barMax + ImVec2{0, 1}, IM_COL32(0, 0, 0, 255)); 81 | if (clampedHp > 0) { 82 | drawList->AddRectFilled({barMin.x + 1, barMax.y - (std::max)(1.f, height)}, {barMax.x - 1, barMax.y}, 83 | IM_COL32(red, greenClamped, 0, 255)); 84 | } 85 | } 86 | } 87 | 88 | void CCachedPlayer::CalculateDrawInfo() { 89 | CCSPlayerController* controller = Get(); 90 | C_BaseEntity* pawn = controller->m_hPawn().Get(); 91 | if (!pawn->CalculateBBoxByCollision(m_BBox)) { 92 | return InvalidateDrawInfo(); 93 | } 94 | } 95 | 96 | CCachedPlayer::Team CCachedPlayer::GetTeam() { 97 | CCSPlayerController* controller = Get(); 98 | if (!controller) return Team::UNKNOWN; 99 | 100 | C_CSPlayerPawnBase* pawn = controller->m_hPawn().Get(); 101 | if (!pawn) return Team::UNKNOWN; 102 | 103 | return static_cast(pawn->m_iTeamNum()); 104 | } 105 | 106 | bool CCachedPlayer::IsEnemyWithTeam(Team team) { 107 | static ConVar* mp_teammates_are_enemies = CCVar::Get()->GetCvarByName("mp_teammates_are_enemies"); 108 | return mp_teammates_are_enemies->GetValue() ? true : GetTeam() != team; 109 | } 110 | 111 | bool CCachedPlayer::IsLocalPlayer() { return GetIndex() == CEngineClient::Get()->GetLocalPlayer(); } 112 | -------------------------------------------------------------------------------- /cs2-sdk/src/menu/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | void CMenu::Render() { 19 | if (ImGui::IsKeyPressed(ImGuiKey_Insert, false)) { 20 | Toggle(); 21 | } else if (ImGui::IsKeyPressed(ImGuiKey_End, false)) { 22 | DeclareShutdown(); 23 | } 24 | 25 | RenderWatermark(); 26 | RenderUI(); 27 | } 28 | 29 | void CMenu::HandleStates(bool mouseIsEnabled) { 30 | auto inputSystem = CInputSystem::Get(); 31 | if (!inputSystem || !ImGui::GetCurrentContext()) { 32 | return; 33 | } 34 | 35 | const ImVec2 screenCenter = ImGui::GetIO().DisplaySize * 0.5f; 36 | switch (m_State) { 37 | case TOGGLE_CLOSE: 38 | case TOGGLE_OPEN: 39 | m_State = (m_State == TOGGLE_OPEN) ? OPEN : CLOSED; 40 | 41 | if (mouseIsEnabled) { 42 | sdl::SetWindowRelativeMouseMode(inputSystem->GetSDLWindow(), !IsOpen()); 43 | sdl::SetWindowMouseGrab(inputSystem->GetSDLWindow(), !IsOpen()); 44 | sdl::WarpMouseInWindow(nullptr, screenCenter.x, screenCenter.y); 45 | } 46 | 47 | break; 48 | case OPEN: 49 | if (mouseIsEnabled) { 50 | sdl::SetWindowRelativeMouseMode(inputSystem->GetSDLWindow(), false); 51 | } 52 | 53 | break; 54 | case TOGGLE_SHUTDOWN_AND_CLOSE_MENU: 55 | if (mouseIsEnabled) { 56 | sdl::SetWindowRelativeMouseMode(inputSystem->GetSDLWindow(), true); 57 | } 58 | 59 | m_State = TOGGLE_SHUTDOWN; 60 | 61 | break; 62 | case TOGGLE_SHUTDOWN: 63 | CInstance::Get().FreeLibrary(); 64 | m_State = SHUTDOWN; 65 | 66 | break; 67 | } 68 | } 69 | 70 | void CMenu::DeclareShutdown() { 71 | SDK_LOG_PROLOGUE(); 72 | 73 | m_State = IsOpen() ? TOGGLE_SHUTDOWN_AND_CLOSE_MENU : TOGGLE_SHUTDOWN; 74 | } 75 | 76 | void CMenu::Toggle() { 77 | if (m_State == OPEN || m_State == CLOSED) { 78 | m_State = static_cast(m_State + 1); 79 | } 80 | } 81 | 82 | void CMenu::RenderWatermark() { 83 | auto drawList = CRenderer::GetBackgroundDrawList(); 84 | 85 | char watermarkText[128]; 86 | snprintf(watermarkText, IM_ARRAYSIZE(watermarkText), "cs2-sdk v2 [%d]\nFPS: %d\n\n%s %s\nhttps://github.com/bruhmoment21/cs2-sdk", 87 | CEngineClient::Get()->GetEngineBuildNumber(), static_cast(ImGui::GetIO().Framerate), __DATE__, __TIME__); 88 | 89 | drawList->AddText({17, 9}, IM_COL32(0, 0, 0, 255), watermarkText); 90 | drawList->AddText({16, 8}, IM_COL32(27, 227, 200, 255), watermarkText); 91 | } 92 | 93 | void CMenu::RenderUI() { 94 | ImGuiIO& IO = ImGui::GetIO(); 95 | IO.ConfigFlags = ImGuiConfigFlags_NoMouseCursorChange; 96 | 97 | if (!IsOpen()) { 98 | return; 99 | } 100 | 101 | IO.ConfigFlags = ImGuiConfigFlags_None; 102 | 103 | RenderMainMenu(); 104 | } 105 | 106 | void CMenu::RenderMainMenu() { 107 | constexpr auto windowStartWidth = 256.f; 108 | 109 | const ImGuiIO& IO = ImGui::GetIO(); 110 | 111 | ImGui::SetNextWindowSize({windowStartWidth, 0}, ImGuiCond_Once); 112 | ImGui::SetNextWindowPos(IO.DisplaySize * 0.5f, ImGuiCond_Once, {0.5f, 0.5f}); 113 | ImGui::Begin("cs2-sdk | main menu", nullptr); 114 | { 115 | ImGui::Checkbox("Master switch", &g_Vars.m_EnableESP); 116 | ImGui::SeparatorText("Visuals"); 117 | 118 | ImGui::Checkbox("Players box", &g_Vars.m_PlayerBoxes); 119 | ImGui::Checkbox("Players name", &g_Vars.m_PlayerNames); 120 | ImGui::Checkbox("Players healthbar", &g_Vars.m_PlayerHealthBar); 121 | 122 | ImGui::Checkbox("Weapons box", &g_Vars.m_WeaponBoxes); 123 | ImGui::Checkbox("Chickens box", &g_Vars.m_ChickenBoxes); 124 | ImGui::Checkbox("Hostages box", &g_Vars.m_HostageBoxes); 125 | ImGui::Checkbox("Others box", &g_Vars.m_OtherBoxes); 126 | 127 | ImGui::Checkbox("Three-dimensional boxes", &g_Vars.m_Use3DBoxes); 128 | 129 | if (ImGui::Button("Unload", {-FLT_MIN, 0})) DeclareShutdown(); 130 | } 131 | ImGui::End(); 132 | } 133 | -------------------------------------------------------------------------------- /cs2-sdk/libs/funchook/src/disasm.h: -------------------------------------------------------------------------------- 1 | /* -*- indent-tabs-mode: nil -*- 2 | * 3 | * This file is part of Funchook. 4 | * https://github.com/kubo/funchook 5 | * 6 | * Funchook is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation, either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * As a special exception, the copyright holders of this library give you 12 | * permission to link this library with independent modules to produce an 13 | * executable, regardless of the license terms of these independent 14 | * modules, and to copy and distribute the resulting executable under 15 | * terms of your choice, provided that you also meet, for each linked 16 | * independent module, the terms and conditions of the license of that 17 | * module. An independent module is a module which is not derived from or 18 | * based on this library. If you modify this library, you may extend this 19 | * exception to your version of the library, but you are not obliged to 20 | * do so. If you do not wish to do so, delete this exception statement 21 | * from your version. 22 | * 23 | * Funchook is distributed in the hope that it will be useful, but WITHOUT 24 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26 | * for more details. 27 | * 28 | * You should have received a copy of the GNU General Public License 29 | * along with Funchook. If not, see . 30 | */ 31 | #ifndef DISASM_H 32 | #define DISASM_H 1 33 | 34 | #ifdef DISASM_DISTORM 35 | #include 36 | #include 37 | 38 | typedef struct funchook_disasm { 39 | funchook_t *funchook; 40 | _CodeInfo ci; 41 | unsigned int idx; 42 | unsigned int cnt; 43 | _DInst dis[MAX_INSN_CHECK_SIZE]; 44 | } funchook_disasm_t; 45 | typedef _DInst funchook_insn_t; 46 | 47 | #define funchook_insn_size(insn) ((insn)->size) 48 | #define funchook_insn_address(insn) ((size_t)(insn)->addr) 49 | #define funchook_insn_branch_address(insn) ((size_t)INSTRUCTION_GET_TARGET(insn)) 50 | 51 | #endif 52 | 53 | #ifdef DISASM_CAPSTONE 54 | #include 55 | 56 | typedef struct funchook_disasm { 57 | funchook_t *funchook; 58 | csh handle; 59 | cs_insn *insns; 60 | size_t index; 61 | size_t count; 62 | } funchook_disasm_t; 63 | 64 | typedef cs_insn funchook_insn_t; 65 | 66 | #define funchook_insn_size(insn) ((insn)->size / sizeof(insn_t)) 67 | #define funchook_insn_address(insn) ((size_t)(insn)->address) 68 | #define funchook_insn_branch_address(insn) ((size_t)(insn)->detail->x86.operands[0].imm) 69 | #endif 70 | 71 | #ifdef DISASM_ZYDIS 72 | #include 73 | 74 | typedef struct { 75 | ZydisDecodedInstruction insn; 76 | size_t next_address; 77 | } funchook_insn_t; 78 | 79 | typedef struct funchook_disasm { 80 | funchook_t *funchook; 81 | ZydisDecoder decoder; 82 | ZydisFormatter formatter; 83 | funchook_insn_t insn; 84 | const uint8_t *code; 85 | const uint8_t *code_end; 86 | } funchook_disasm_t; 87 | 88 | #define funchook_insn_size(insn) ((insn)->insn.length) 89 | #define funchook_insn_address(insn) ((insn)->next_address - (insn)->insn.length) 90 | #define funchook_insn_branch_address(insn) ((insn)->next_address + (intptr_t)(insn)->insn.raw.imm[0].value.s) 91 | 92 | #endif 93 | 94 | #define FUNCHOOK_ERROR_END_OF_INSTRUCTION -2 95 | 96 | int funchook_disasm_init(funchook_disasm_t *disasm, funchook_t *funchook, const insn_t *code, size_t code_size, size_t address); 97 | void funchook_disasm_cleanup(funchook_disasm_t *disasm); 98 | int funchook_disasm_next(funchook_disasm_t *disasm, const funchook_insn_t **next_insn); 99 | void funchook_disasm_log_instruction(funchook_disasm_t *disasm, const funchook_insn_t *insn); 100 | 101 | #if defined(CPU_ARM64) 102 | funchook_insn_info_t funchook_disasm_arm64_insn_info(funchook_disasm_t *disasm, const funchook_insn_t *insn); 103 | #endif 104 | 105 | #if defined(CPU_X86) || defined(CPU_X86_64) 106 | /* RIP-relative address information */ 107 | typedef struct { 108 | insn_t *addr; /* absolute address */ 109 | intptr_t raddr; /* relative address */ 110 | int offset; 111 | int size; 112 | } rip_relative_t; 113 | 114 | void funchook_disasm_x86_rip_relative(funchook_disasm_t *disasm, const funchook_insn_t *insn, rip_relative_t *rel_disp, rip_relative_t *rel_imm); 115 | #endif 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /cs2-sdk/src/cache/cache.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #define SDK_ENABLE_CACHE_LOGGING 18 | 19 | void CMatchCache::Initialize() { 20 | CLogger::Log("[game] engine build number: {}", CEngineClient::Get()->GetEngineBuildNumber()); 21 | 22 | int highestIdx = CGameEntitySystem::GetHighestEntityIndex(); 23 | for (int i = 1; i <= highestIdx; ++i) { 24 | C_BaseEntity* ent = CGameEntitySystem::GetBaseEntity(i); 25 | if (!ent) continue; 26 | 27 | AddEntity(ent, ent->GetRefEHandle()); 28 | } 29 | } 30 | 31 | void CMatchCache::AddEntity(CEntityInstance* inst, CBaseHandle handle) { 32 | // Cache only networked entities. 33 | // https://developer.valvesoftware.com/wiki/Entity_limit#Source_2_limits 34 | 35 | C_BaseEntity* ent = static_cast(inst); 36 | if (!ent || handle.GetEntryIndex() > 0x3FFF) return; 37 | 38 | // Sanity check if CHandle or GetRefEHandle changed. 39 | if (ent->GetRefEHandle() != handle) { 40 | return CLogger::Log("[cache] CHandle mismatch detected! Needs debugging..."); 41 | } 42 | 43 | // Returns a valid pointer if the entity is what we are looking for. 44 | // Example: PlayerController, Chicken, Weapon, etc... 45 | CachedEntityPtr cachedEntity = CreateCachedEntityPointer(ent); 46 | if (!cachedEntity) return; 47 | 48 | // Set the cached entity's handle. 49 | cachedEntity->SetHandle(handle); 50 | 51 | { 52 | const std::lock_guard lock(m_EntitiesLock); 53 | m_CachedEntities.emplace(handle.ToInt(), std::move(cachedEntity)); 54 | } 55 | 56 | #ifdef SDK_ENABLE_CACHE_LOGGING 57 | // Log that we've added the entity. 58 | CSchemaClassInfo* dynamicBinding = ent->Schema_DynamicBinding(); 59 | if (!dynamicBinding) return; 60 | 61 | CLogger::Log("[cache] [+] {} -> {} | CHandle [Serial: {}, Index: {}]", dynamicBinding->m_Name, SDK_LOG_PTR(ent), 62 | handle.GetSerialNumber(), handle.GetEntryIndex()); 63 | #endif 64 | } 65 | 66 | void CMatchCache::RemoveEntity(CEntityInstance* inst, CBaseHandle handle) { 67 | C_BaseEntity* ent = static_cast(inst); 68 | if (!ent || handle.GetEntryIndex() > 0x3FFF) return; 69 | 70 | auto it = m_CachedEntities.find(handle.ToInt()); 71 | if (it == m_CachedEntities.end()) return; 72 | 73 | { 74 | const std::lock_guard lock(m_EntitiesLock); 75 | m_CachedEntities.erase(it); 76 | } 77 | 78 | #ifdef SDK_ENABLE_CACHE_LOGGING 79 | // Log that we've removed the entity. 80 | CSchemaClassInfo* dynamicBinding = ent->Schema_DynamicBinding(); 81 | if (!dynamicBinding) return; 82 | 83 | CLogger::Log("[cache] [-] {} -> {} | CHandle [Serial: {}, Index: {}]", dynamicBinding->m_Name, SDK_LOG_PTR(ent), 84 | handle.GetSerialNumber(), handle.GetEntryIndex()); 85 | #endif 86 | } 87 | 88 | CMatchCache::CachedEntityPtr& CMatchCache::GetEntityByIndex(int i) { 89 | C_BaseEntity* ent = CGameEntitySystem::GetBaseEntity(i); 90 | if (ent) { 91 | auto it = m_CachedEntities.find(ent->GetRefEHandle().ToInt()); 92 | if (it != m_CachedEntities.end()) return it->second; 93 | } 94 | 95 | static CachedEntityPtr null; 96 | return null; 97 | } 98 | 99 | CCachedPlayer* CMatchCache::GetLocalPlayer() { 100 | CachedEntityPtr& cachedEntity = GetEntityByIndex(CEngineClient::Get()->GetLocalPlayer()); 101 | if (cachedEntity && cachedEntity->GetType() == CCachedBaseEntity::Type::PLAYER) { 102 | return static_cast(cachedEntity.get()); 103 | } 104 | 105 | return nullptr; 106 | } 107 | 108 | CMatchCache::CachedEntityPtr CMatchCache::CreateCachedEntityPointer(C_BaseEntity* ent) { 109 | if (ent->IsPlayerController()) { 110 | return std::make_unique(); 111 | } else if (ent->IsWeapon()) { 112 | return std::make_unique(); 113 | } else if (ent->IsChicken()) { 114 | return std::make_unique(); 115 | } else if (ent->IsHostage()) { 116 | return std::make_unique(); 117 | } else if (ent->IsProjectile() || ent->IsPlantedC4()) { 118 | return std::make_unique(); 119 | } 120 | 121 | return nullptr; 122 | } 123 | -------------------------------------------------------------------------------- /cs2-sdk/api/src/module/module.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | CModule::CModule(const char* name) { 10 | m_Name = name; 11 | m_Handle = nullptr; 12 | 13 | m_Begin = m_Size = 0; 14 | } 15 | 16 | CModule::~CModule() { 17 | if (!m_Handle) { 18 | return; 19 | } 20 | 21 | #ifndef _WIN32 22 | dlclose(m_Handle); 23 | #endif 24 | } 25 | 26 | bool CModule::Retrieve() { 27 | if (m_Handle) { 28 | return true; 29 | } 30 | 31 | InitializeHandle(); 32 | InitializeBounds(); 33 | 34 | return m_Handle != nullptr; 35 | } 36 | 37 | uintptr_t CModule::GetInterface(uint32_t versionHash) { 38 | uintptr_t rv = 0; 39 | if (m_Handle) { 40 | CPointer pCreateInterface = GetProcAddress("CreateInterface"); 41 | if (!pCreateInterface.IsValid()) { 42 | return rv; 43 | } 44 | 45 | // Used internally to register classes. 46 | struct InterfaceReg { 47 | std::add_pointer_t m_CreateFn; 48 | const char* m_pName; 49 | InterfaceReg* m_pNext; // For the global list. 50 | }; 51 | 52 | InterfaceReg* s_pInterfaceRegs = 53 | #ifdef _WIN32 54 | pCreateInterface.Absolute(3, 0).Dereference(1).Get() 55 | #elif __linux__ 56 | pCreateInterface.Absolute(1, 0).Absolute(19, 0).Dereference(1).Get() 57 | #endif 58 | ; 59 | 60 | for (; s_pInterfaceRegs; s_pInterfaceRegs = s_pInterfaceRegs->m_pNext) { 61 | if (FNV1A::Hash(s_pInterfaceRegs->m_pName) == versionHash) { 62 | rv = s_pInterfaceRegs->m_CreateFn(); 63 | break; 64 | } 65 | } 66 | } 67 | 68 | return rv; 69 | } 70 | 71 | uintptr_t CModule::GetProcAddress(const char* procName) { 72 | uintptr_t rv = 0; 73 | if (m_Handle) { 74 | #ifdef _WIN32 75 | rv = reinterpret_cast(::GetProcAddress(static_cast(m_Handle), procName)); 76 | #else 77 | rv = reinterpret_cast(dlsym(m_Handle, procName)); 78 | #endif 79 | } 80 | 81 | return rv; 82 | } 83 | 84 | uintptr_t CModule::FindPattern(const std::span& pattern) const { 85 | uintptr_t rv = 0; 86 | if (m_Handle) { 87 | uint8_t* bytes = reinterpret_cast(m_Begin); 88 | 89 | // Faster than pattern[] in debug builds because of _STL_VERIFY. 90 | const int* patternData = pattern.data(); 91 | const size_t patternSize = pattern.size(); 92 | 93 | for (size_t i = 0; i < m_Size - patternSize; ++i) { 94 | bool found = true; 95 | for (size_t j = 0; j < patternSize; ++j) { 96 | if (bytes[i + j] != patternData[j] && patternData[j] != -1) { 97 | found = false; 98 | break; 99 | } 100 | } 101 | 102 | if (found) { 103 | rv = reinterpret_cast(&bytes[i]); 104 | break; 105 | } 106 | } 107 | } 108 | 109 | return rv; 110 | } 111 | 112 | void CModule::InitializeHandle() { 113 | #ifdef _WIN32 114 | m_Handle = GetModuleHandle(GetName()); 115 | #else 116 | m_Handle = dlopen(GetName(), RTLD_LAZY | RTLD_NOLOAD); 117 | #endif 118 | } 119 | 120 | void CModule::InitializeBounds() { 121 | if (!m_Handle) { 122 | return; 123 | } 124 | 125 | #ifdef _WIN32 126 | MODULEINFO mi; 127 | BOOL status = GetModuleInformation(GetCurrentProcess(), static_cast(m_Handle), &mi, sizeof(mi)); 128 | if (status == 0) { 129 | return; 130 | } 131 | 132 | SetBounds(reinterpret_cast(m_Handle), mi.SizeOfImage); 133 | #elif __linux__ 134 | dl_iterate_phdr( 135 | [](struct dl_phdr_info* info, size_t, void* data) { 136 | CModule* currentModule = static_cast(data); 137 | if (strstr(info->dlpi_name, currentModule->GetName()) != 0) { 138 | for (Elf64_Half i = 0; i < info->dlpi_phnum; ++i) { 139 | const auto& phdr = info->dlpi_phdr[i]; 140 | if (phdr.p_type != PT_LOAD || !(phdr.p_flags & PF_X)) continue; 141 | 142 | currentModule->SetBounds(info->dlpi_addr + phdr.p_vaddr, phdr.p_memsz); 143 | return 1; 144 | } 145 | } 146 | 147 | return 0; 148 | }, 149 | static_cast(this)); 150 | #endif 151 | } 152 | 153 | void CModule::SetBounds(uintptr_t begin, uintptr_t size) { 154 | m_Begin = begin; 155 | m_Size = size; 156 | } 157 | -------------------------------------------------------------------------------- /cs2-sdk/src/signatures/signatures.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #define STB_OMIT_TESTS 7 | #include 8 | 9 | #define SDK_SIG(sig) stb::simple_conversion::build::value 10 | 11 | namespace signatures { 12 | CSigScan GetBaseEntity("CGameEntitySystem::GetBaseEntity", CConstants::CLIENT_LIB, 13 | { 14 | #ifdef _WIN32 15 | {SDK_SIG("8B D3 E8 ? ? ? ? 48 8B F8 48 85 C0 74 76"), [](CPointer& ptr) { ptr.Absolute(3, 0); }}, 16 | {SDK_SIG("81 FA ? ? ? ? 77 36")}, 17 | #elif __linux__ 18 | {SDK_SIG("44 89 E6 E8 ? ? ? ? 48 89 C3 48 85 C0 0F 85 ? ? ? ?"), [](CPointer& ptr) { ptr.Absolute(4, 0); }}, 19 | {SDK_SIG("81 FE ? ? ? ? 77 38 89 F0")}, 20 | #endif 21 | }); 22 | 23 | CSigScan GetHighestEntityIndex("CGameEntitySystem::GetHighestEntityIndex", CConstants::CLIENT_LIB, 24 | { 25 | #ifdef _WIN32 26 | {SDK_SIG("33 DB E8 ? ? ? ? 8B 08"), [](CPointer& ptr) { ptr.Absolute(3, 0); }}, 27 | {SDK_SIG("E8 ? ? ? ? 33 DB 39 5C 24 40"), [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 28 | #elif __linux__ 29 | {SDK_SIG("E8 ? ? ? ? 41 39 C4 7F 50"), [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 30 | {SDK_SIG("E8 ? ? ? ? 85 C0 78 4D"), [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 31 | #endif 32 | }); 33 | 34 | CSigScan GetCSGOInput("CCSGOInput Pointer", CConstants::CLIENT_LIB, 35 | { 36 | #ifdef _WIN32 37 | {SDK_SIG("48 8D 0D ? ? ? ? E8 ? ? ? ? 33 C9 C7 05 ? ? ? ? ? ? ? ?"), 38 | [](CPointer& ptr) { ptr.Absolute(3, 0); }}, 39 | {SDK_SIG("74 0C 48 8D 0D ? ? ? ? E8 ? ? ? ? E8 ? ? ? ?"), [](CPointer& ptr) { ptr.Absolute(5, 0); }}, 40 | #elif __linux__ 41 | {SDK_SIG("0F 84 ? ? ? ? 48 8D 3D ? ? ? ? E8 ? ? ? ? E9 ? ? ? ? 0F 1F 44 00 00"), 42 | [](CPointer& ptr) { ptr.Absolute(9, 0); }}, 43 | {SDK_SIG("E8 ? ? ? ? 4D 8B 7C 24 ? 49 89 C5 41 8B 44 24 ? 45 8B 74 24 ? 85 C0 75 08"), 44 | [](CPointer& ptr) { ptr.Absolute(1, 3).Dereference(1); }}, 45 | #endif 46 | }); 47 | 48 | CSigScan GetMatricesForView("CRenderGameSystem::GetMatricesForView", CConstants::CLIENT_LIB, 49 | { 50 | #ifdef _WIN32 51 | {SDK_SIG("40 53 48 81 EC ? ? ? ? 49 8B C1")}, 52 | {SDK_SIG("E8 ? ? ? ? 48 8B 9C 24 ? ? ? ? B0 01 48 81 C4 ? ? ? ? 41 5E"), 53 | [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 54 | #elif __linux__ 55 | {SDK_SIG("55 48 89 D7 4C 89 C2")}, 56 | {SDK_SIG("48 8B 38 E8 ? ? ? ? B8 ? ? ? ? 48 81 C4 ? ? ? ?"), [](CPointer& ptr) { ptr.Absolute(4, 0); }}, 57 | #endif 58 | }); 59 | 60 | CSigScan GetHitboxSet("C_BaseEntity::GetHitboxSet", CConstants::CLIENT_LIB, 61 | { 62 | #ifdef _WIN32 63 | {SDK_SIG("E8 ? ? ? ? 48 8B F0 48 85 C0 0F 84 ? ? ? ? 44 39 70 10"), 64 | [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 65 | {SDK_SIG("41 8B D6 E8 ? ? ? ? 4C 8B F8"), [](CPointer& ptr) { ptr.Absolute(4, 0); }}, 66 | #elif __linux__ 67 | {SDK_SIG("E8 ? ? ? ? 48 89 85 ? ? ? ? 48 85 C0 74 0F"), [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 68 | {SDK_SIG("E8 ? ? ? ? 48 89 C3 48 89 85 ? ? ? ? 48 85 C0 74 07 8B 40"), 69 | [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 70 | #endif 71 | }); 72 | 73 | CSigScan HitboxToWorldTransforms("C_BaseEntity::HitboxToWorldTransforms", CConstants::CLIENT_LIB, 74 | { 75 | #ifdef _WIN32 76 | {SDK_SIG("E8 ? ? ? ? C7 06 ? ? ? ?"), [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 77 | {SDK_SIG("E8 ? ? ? ? 85 C0 0F 84 ? ? ? ? C7 07 ? ? ? ?"), 78 | [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 79 | #elif __linux__ 80 | {SDK_SIG("E8 ? ? ? ? 89 C2 85 C0 74 B8"), [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 81 | {SDK_SIG("E8 ? ? ? ? 41 C7 45 ? ? ? ? ? 4C 89 F7 89 C3 48 B8 ? ? ? ? ? ? ? ? 49 89 45"), 82 | [](CPointer& ptr) { ptr.Absolute(1, 0); }}, 83 | #endif 84 | }); 85 | } // namespace signatures 86 | -------------------------------------------------------------------------------- /cs2-sdk/libs/funchook/include/funchook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Funchook. 3 | * https://github.com/kubo/funchook 4 | * 5 | * Funchook is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation, either version 2 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * As a special exception, the copyright holders of this library give you 11 | * permission to link this library with independent modules to produce an 12 | * executable, regardless of the license terms of these independent 13 | * modules, and to copy and distribute the resulting executable under 14 | * terms of your choice, provided that you also meet, for each linked 15 | * independent module, the terms and conditions of the license of that 16 | * module. An independent module is a module which is not derived from or 17 | * based on this library. If you modify this library, you may extend this 18 | * exception to your version of the library, but you are not obliged to 19 | * do so. If you do not wish to do so, delete this exception statement 20 | * from your version. 21 | * 22 | * Funchook is distributed in the hope that it will be useful, but WITHOUT 23 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25 | * for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with Funchook. If not, see . 29 | */ 30 | #ifndef FUNCHOOK_H 31 | #define FUNCHOOK_H 1 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* 38 | * Only functions with FUNCHOOK_EXPORT are visible from outside of funchook.dll 39 | * or libfunchook.so. Others are invisible. 40 | */ 41 | #ifdef FUNCHOOK_EXPORTS 42 | #if defined(_WIN32) 43 | #define FUNCHOOK_EXPORT __declspec(dllexport) 44 | #elif defined(__GNUC__) 45 | #define FUNCHOOK_EXPORT __attribute__((visibility("default"))) 46 | #endif 47 | #endif /* FUNCHOOK_EXPORTS */ 48 | #ifndef FUNCHOOK_EXPORT 49 | #define FUNCHOOK_EXPORT 50 | #endif 51 | 52 | typedef struct funchook funchook_t; 53 | 54 | #define FUNCHOOK_ERROR_INTERNAL_ERROR -1 55 | #define FUNCHOOK_ERROR_SUCCESS 0 56 | #define FUNCHOOK_ERROR_OUT_OF_MEMORY 1 57 | #define FUNCHOOK_ERROR_ALREADY_INSTALLED 2 58 | #define FUNCHOOK_ERROR_DISASSEMBLY 3 59 | #define FUNCHOOK_ERROR_IP_RELATIVE_OFFSET 4 60 | #define FUNCHOOK_ERROR_CANNOT_FIX_IP_RELATIVE 5 61 | #define FUNCHOOK_ERROR_FOUND_BACK_JUMP 6 62 | #define FUNCHOOK_ERROR_TOO_SHORT_INSTRUCTIONS 7 63 | #define FUNCHOOK_ERROR_MEMORY_ALLOCATION 8 /* memory allocation error */ 64 | #define FUNCHOOK_ERROR_MEMORY_FUNCTION 9 /* other memory function errors */ 65 | #define FUNCHOOK_ERROR_NOT_INSTALLED 10 66 | #define FUNCHOOK_ERROR_NO_AVAILABLE_REGISTERS 11 67 | 68 | /** 69 | * Create a funchook handle 70 | * 71 | * @return allocated funchook handle. NULL when out-of-memory. 72 | */ 73 | FUNCHOOK_EXPORT funchook_t *funchook_create(void); 74 | 75 | /** 76 | * Prepare hooking 77 | * 78 | * @param funchook a funchook handle created by funchook_create() 79 | * @param target_func function pointer to be intercepted. The pointer to trampoline function is set on success. 80 | * @param hook_func function pointer which is called istead of target_func 81 | * @return error code. one of FUNCHOOK_ERROR_*. 82 | */ 83 | FUNCHOOK_EXPORT int funchook_prepare(funchook_t *funchook, void **target_func, void *hook_func); 84 | 85 | /** 86 | * Install hooks prepared by funchook_prepare(). 87 | * 88 | * @param funchook a funchook handle created by funchook_create() 89 | * @param flags reserved. Set zero. 90 | * @return error code. one of FUNCHOOK_ERROR_*. 91 | */ 92 | FUNCHOOK_EXPORT int funchook_install(funchook_t *funchook, int flags); 93 | 94 | /** 95 | * Uninstall hooks installed by funchook_install(). 96 | * 97 | * @param funchook a funchook handle created by funchook_create() 98 | * @param flags reserved. Set zero. 99 | * @return error code. one of FUNCHOOK_ERROR_*. 100 | */ 101 | FUNCHOOK_EXPORT int funchook_uninstall(funchook_t *funchook, int flags); 102 | 103 | /** 104 | * Destroy a funchook handle 105 | * 106 | * @param funchook a funchook handle created by funchook_create() 107 | * @return error code. one of FUNCHOOK_ERROR_*. 108 | */ 109 | FUNCHOOK_EXPORT int funchook_destroy(funchook_t *funchook); 110 | 111 | /** 112 | * Get error message 113 | * 114 | * @param funchook a funchook handle created by funchook_create() 115 | * @return pointer to buffer containing error message 116 | */ 117 | FUNCHOOK_EXPORT const char *funchook_error_message(const funchook_t *funchook); 118 | 119 | /** 120 | * Set log file name to debug funchook itself. 121 | * 122 | * @param name log file name 123 | * @return error code. one of FUNCHOOK_ERROR_*. 124 | */ 125 | FUNCHOOK_EXPORT int funchook_set_debug_file(const char *name); 126 | 127 | #ifdef __cplusplus 128 | } // extern "C" 129 | #endif 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /cs2-sdk/sdk/src/bindings/baseentity.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | bool C_BaseEntity::IsPlayerController() { 17 | static CSchemaClassInfo* playerControllerClass = 18 | CSchemaSystem::Get()->FindTypeScopeForModule(CConstants::CLIENT_LIB)->FindDeclaredClass("CCSPlayerController"); 19 | return Schema_DynamicBinding() == playerControllerClass; 20 | } 21 | 22 | bool C_BaseEntity::IsWeapon() { 23 | static CSchemaClassInfo* weaponBaseClass = 24 | CSchemaSystem::Get()->FindTypeScopeForModule(CConstants::CLIENT_LIB)->FindDeclaredClass("C_CSWeaponBase"); 25 | 26 | CSchemaClassInfo* entClass = Schema_DynamicBinding(); 27 | if (!entClass) return false; 28 | 29 | return entClass->InheritsFrom(weaponBaseClass); 30 | } 31 | 32 | bool C_BaseEntity::IsProjectile() { 33 | static CSchemaClassInfo* baseGrenadeClass = 34 | CSchemaSystem::Get()->FindTypeScopeForModule(CConstants::CLIENT_LIB)->FindDeclaredClass("C_BaseGrenade"); 35 | 36 | CSchemaClassInfo* entClass = Schema_DynamicBinding(); 37 | if (!entClass) return false; 38 | 39 | return entClass->InheritsFrom(baseGrenadeClass); 40 | } 41 | 42 | bool C_BaseEntity::IsPlantedC4() { 43 | static CSchemaClassInfo* plantedC4Class = 44 | CSchemaSystem::Get()->FindTypeScopeForModule(CConstants::CLIENT_LIB)->FindDeclaredClass("C_PlantedC4"); 45 | return Schema_DynamicBinding() == plantedC4Class; 46 | } 47 | 48 | bool C_BaseEntity::IsChicken() { 49 | static CSchemaClassInfo* chickenClass = 50 | CSchemaSystem::Get()->FindTypeScopeForModule(CConstants::CLIENT_LIB)->FindDeclaredClass("C_Chicken"); 51 | return Schema_DynamicBinding() == chickenClass; 52 | } 53 | 54 | bool C_BaseEntity::IsHostage() { 55 | static CSchemaClassInfo* hostageClass = 56 | CSchemaSystem::Get()->FindTypeScopeForModule(CConstants::CLIENT_LIB)->FindDeclaredClass("C_Hostage"); 57 | return Schema_DynamicBinding() == hostageClass; 58 | } 59 | 60 | bool C_BaseEntity::CalculateBBoxByCollision(BBox_t& out) { 61 | CGameSceneNode* node = m_pGameSceneNode(); 62 | if (!node) return false; 63 | 64 | CCollisionProperty* collision = m_pCollision(); 65 | if (!collision) return false; 66 | 67 | const Vector mins = collision->m_vecMins(), maxs = collision->m_vecMaxs(); 68 | 69 | out.Invalidate(); 70 | 71 | for (int i = 0; i < 8; ++i) { 72 | const Vector worldPoint{i & 1 ? maxs.x : mins.x, i & 2 ? maxs.y : mins.y, i & 4 ? maxs.z : mins.z}; 73 | 74 | if (!CMath::Get().WorldToScreen(worldPoint.Transform(node->m_nodeToWorld().ToMatrix()), out.m_Vertices[i])) return false; 75 | 76 | out.m_Mins = ImMin(out.m_Mins, out.m_Vertices[i]); 77 | out.m_Maxs = ImMax(out.m_Maxs, out.m_Vertices[i]); 78 | } 79 | 80 | return true; 81 | } 82 | 83 | bool C_BaseEntity::CalculateBBoxByHitbox(BBox_t& out) { 84 | constexpr int MAX_HITBOXES = 64; 85 | 86 | CHitBoxSet* hitBoxSet = GetHitboxSet(0); 87 | if (!hitBoxSet) return false; 88 | 89 | const CUtlVector& hitBoxes = hitBoxSet->m_HitBoxes(); 90 | if (hitBoxes.m_Size > MAX_HITBOXES) { 91 | CLogger::Log("[bbox] hitBoxTransforms[{}] way too small! (Debug?)", MAX_HITBOXES); 92 | return false; 93 | } 94 | 95 | CTransform hitBoxTransforms[MAX_HITBOXES]; 96 | int hitBoxCount = HitboxToWorldTransforms(hitBoxSet, hitBoxTransforms); 97 | if (!hitBoxCount) return false; 98 | 99 | Vector mins{std::numeric_limits::max()}, maxs{-std::numeric_limits::max()}; 100 | for (int i = 0; i < hitBoxCount; ++i) { 101 | const matrix3x4_t hitBoxMatrix = hitBoxTransforms[i].ToMatrix(); 102 | auto hitBox = hitBoxes.AtPtr(i); 103 | 104 | Vector worldMins, worldMaxs; 105 | CMath::Get().TransformAABB(hitBoxMatrix, hitBox->m_vMinBounds(), hitBox->m_vMaxBounds(), worldMins, worldMaxs); 106 | 107 | mins = mins.Min(worldMins); 108 | maxs = maxs.Max(worldMaxs); 109 | } 110 | 111 | out.Invalidate(); 112 | 113 | for (int i = 0; i < 8; ++i) { 114 | const Vector worldPoint{i & 1 ? maxs.x : mins.x, i & 2 ? maxs.y : mins.y, i & 4 ? maxs.z : mins.z}; 115 | 116 | if (!CMath::Get().WorldToScreen(worldPoint, out.m_Vertices[i])) return false; 117 | 118 | out.m_Mins = ImMin(out.m_Mins, out.m_Vertices[i]); 119 | out.m_Maxs = ImMax(out.m_Maxs, out.m_Vertices[i]); 120 | } 121 | 122 | return true; 123 | } 124 | 125 | CHitBoxSet* C_BaseEntity::GetHitboxSet(int i) { return signatures::GetHitboxSet.GetPtr().Call(this, i); } 126 | 127 | int C_BaseEntity::HitboxToWorldTransforms(CHitBoxSet* hitBoxSet, CTransform* hitboxToWorld) { 128 | return signatures::HitboxToWorldTransforms.GetPtr().Call(this, hitBoxSet, hitboxToWorld, 129 | 1024); 130 | } 131 | -------------------------------------------------------------------------------- /cs2-sdk/libs/distorm/src/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | config.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2021 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef CONFIG_H 13 | #define CONFIG_H 14 | 15 | /* diStorm version number. */ 16 | #define __DISTORMV__ 0x030502 17 | 18 | #include /* memset, memcpy - can be easily self implemented for libc independency. */ 19 | 20 | #include "../include/distorm.h" 21 | 22 | 23 | /* 24 | * 64 bit offsets support: 25 | * This macro should be defined from compiler command line flags, e.g: -DSUPPORT_64BIT_OFFSET 26 | * Note: make sure that the caller (library user) defines it too! 27 | */ 28 | /* #define SUPPORT_64BIT_OFFSET */ 29 | 30 | /* 31 | * If you compile diStorm as a dynamic library (.dll or .so) file, make sure you uncomment the next line. 32 | * So the interface functions will be exported, otherwise they are useable only for static library. 33 | * For example, this macro is being set for compiling diStorm as a .dll for Python with CTypes. 34 | */ 35 | /* #define DISTORM_DYNAMIC */ 36 | 37 | /* 38 | * If DISTORM_LIGHT is defined, everything involved in formatting the instructions 39 | * as text will be excluded from compilation. 40 | * distorm_decode(..) and distorm_format(..) will not be available. 41 | * This will decrease the size of the executable and leave you with decomposition functionality only. 42 | * 43 | * Note: it should be either set in the preprocessor definitions manually or in command line -D switch. 44 | * #define DISTORM_LIGHT 45 | */ 46 | 47 | /* 48 | * diStorm now supports little/big endian CPU's. 49 | * It should detect the endianness according to predefined macro's of the compiler. 50 | * If you don't use GCC/MSVC you will have to define it on your own. 51 | */ 52 | 53 | /* These macros are used in order to make the code portable. */ 54 | #ifdef __GNUC__ 55 | 56 | #include 57 | 58 | #define _DLLEXPORT_ 59 | #define _FASTCALL_ 60 | /* Keep inline as static (arrrrg) as it would break linux on some flavors otherwise. */ 61 | #define _INLINE_ static 62 | /* GCC ignores this directive... */ 63 | /*#define _FASTCALL_ __attribute__((__fastcall__))*/ 64 | 65 | /* Set endianity (supposed to be LE though): */ 66 | #ifdef __BIG_ENDIAN__ 67 | #define BE_SYSTEM 68 | #endif 69 | 70 | /* End of __GCC__ */ 71 | 72 | #elif __WATCOMC__ 73 | 74 | #include 75 | 76 | #define _DLLEXPORT_ 77 | #define _FASTCALL_ 78 | #define _INLINE_ __inline 79 | 80 | /* End of __WATCOMC__ */ 81 | 82 | #elif __DMC__ 83 | 84 | #include 85 | 86 | #define _DLLEXPORT_ 87 | #define _FASTCALL_ 88 | #define _INLINE_ __inline 89 | 90 | /* End of __DMC__ */ 91 | 92 | #elif __TINYC__ 93 | 94 | #include 95 | 96 | #define _DLLEXPORT_ 97 | #define _FASTCALL_ 98 | #define _INLINE_ static 99 | 100 | /* End of __TINYC__ */ 101 | 102 | #elif _MSC_VER 103 | 104 | /* stdint alternative is defined in distorm.h */ 105 | 106 | #define _DLLEXPORT_ __declspec(dllexport) 107 | #define _FASTCALL_ __fastcall 108 | #define _INLINE_ __inline 109 | 110 | /* Set endianity (supposed to be LE though): */ 111 | #if !defined(_M_IX86) && !defined(_M_X64) 112 | #define BE_SYSTEM 113 | #endif 114 | 115 | #endif /* #elif _MSC_VER */ 116 | 117 | /* If the library isn't compiled as a dynamic library don't export any functions. */ 118 | #ifndef DISTORM_DYNAMIC 119 | #undef _DLLEXPORT_ 120 | #define _DLLEXPORT_ 121 | #endif 122 | 123 | #ifndef FALSE 124 | #define FALSE 0 125 | #endif 126 | #ifndef TRUE 127 | #define TRUE 1 128 | #endif 129 | 130 | /* Define stream read functions for big endian systems. */ 131 | #ifdef BE_SYSTEM 132 | 133 | /* Avoid defining 'static static' for GCC. */ 134 | #ifndef __GNUC__ 135 | #define STATIC_INLINE static _INLINE_ 136 | #else 137 | #define STATIC_INLINE static 138 | #endif 139 | 140 | /* 141 | * Assumption: These functions can read from the stream safely! 142 | * Swap endianity of input to little endian. 143 | */ 144 | STATIC_INLINE int16_t RSHORT(const uint8_t *s) 145 | { 146 | return s[0] | (s[1] << 8); 147 | } 148 | STATIC_INLINE uint16_t RUSHORT(const uint8_t *s) 149 | { 150 | return s[0] | (s[1] << 8); 151 | } 152 | STATIC_INLINE int32_t RLONG(const uint8_t *s) 153 | { 154 | return s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); 155 | } 156 | STATIC_INLINE uint32_t RULONG(const uint8_t *s) 157 | { 158 | return s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); 159 | } 160 | STATIC_INLINE int64_t RLLONG(const uint8_t *s) 161 | { 162 | return s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24) | ((uint64_t)s[4] << 32) | ((uint64_t)s[5] << 40) | ((uint64_t)s[6] << 48) | ((uint64_t)s[7] << 56); 163 | } 164 | STATIC_INLINE uint64_t RULLONG(const uint8_t *s) 165 | { 166 | return s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24) | ((uint64_t)s[4] << 32) | ((uint64_t)s[5] << 40) | ((uint64_t)s[6] << 48) | ((uint64_t)s[7] << 56); 167 | } 168 | 169 | #undef STATIC_INLINE 170 | 171 | #else 172 | /* Little endian macro's will just make the cast. */ 173 | #define RSHORT(x) *(int16_t *)x 174 | #define RUSHORT(x) *(uint16_t *)x 175 | #define RLONG(x) *(int32_t *)x 176 | #define RULONG(x) *(uint32_t *)x 177 | #define RLLONG(x) *(int64_t *)x 178 | #define RULLONG(x) *(uint64_t *)x 179 | #endif 180 | 181 | #endif /* CONFIG_H */ 182 | -------------------------------------------------------------------------------- /cs2-sdk/libs/funchook/src/funchook_internal.h: -------------------------------------------------------------------------------- 1 | /* -*- indent-tabs-mode: nil -*- 2 | * 3 | * This file is part of Funchook. 4 | * https://github.com/kubo/funchook 5 | * 6 | * Funchook is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation, either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * As a special exception, the copyright holders of this library give you 12 | * permission to link this library with independent modules to produce an 13 | * executable, regardless of the license terms of these independent 14 | * modules, and to copy and distribute the resulting executable under 15 | * terms of your choice, provided that you also meet, for each linked 16 | * independent module, the terms and conditions of the license of that 17 | * module. An independent module is a module which is not derived from or 18 | * based on this library. If you modify this library, you may extend this 19 | * exception to your version of the library, but you are not obliged to 20 | * do so. If you do not wish to do so, delete this exception statement 21 | * from your version. 22 | * 23 | * Funchook is distributed in the hope that it will be useful, but WITHOUT 24 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26 | * for more details. 27 | * 28 | * You should have received a copy of the GNU General Public License 29 | * along with Funchook. If not, see . 30 | */ 31 | #ifndef FUNCHOOK_INTERNAL_H 32 | #define FUNCHOOK_INTERNAL_H 1 33 | #include "funchook.h" 34 | #ifdef _WIN32 35 | #include 36 | #endif 37 | 38 | #if defined(_MSC_VER) && _MSC_VER < 1700 39 | #ifdef _WIN64 40 | #define PRIxPTR "I64" 41 | #else 42 | #define PRIxPTR "" 43 | #endif 44 | #else 45 | #include 46 | #endif 47 | 48 | #ifndef MIN 49 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 50 | #endif 51 | 52 | #ifndef MAX 53 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 54 | #endif 55 | 56 | #ifdef __GNUC__ 57 | #ifdef __MINGW32__ 58 | #include 59 | #define ATTR_FORMAT_PRINTF(a, b) __attribute__((__format__ (__MINGW_PRINTF_FORMAT, a, b))) 60 | #else 61 | #define ATTR_FORMAT_PRINTF(a, b) __attribute__((__format__ (__printf__, a, b))) 62 | #endif 63 | #else 64 | #define ATTR_FORMAT_PRINTF(a, b) 65 | #endif 66 | 67 | #define ROUND_DOWN(num, unit) ((num) & ~((unit) - 1)) 68 | #define ROUND_UP(num, unit) (((num) + (unit) - 1) & ~((unit) - 1)) 69 | 70 | #if SIZEOF_VOID_P == 8 71 | #define ADDR_FMT "%016" PRIxPTR 72 | #else 73 | #define ADDR_FMT "%08" PRIxPTR 74 | #endif 75 | 76 | #if defined _M_ARM64 || defined __aarch64__ 77 | #define CPU_ARM64 78 | #define CPU_64BIT 79 | #endif 80 | 81 | #if defined _M_AMD64 || defined __x86_64__ 82 | #define CPU_X86_64 83 | #define CPU_64BIT 84 | #endif 85 | 86 | #if defined _M_IX86 || defined __i686__ || defined __i386__ 87 | #define CPU_X86 88 | #endif 89 | 90 | #if defined(CPU_ARM64) 91 | #include "funchook_arm64.h" 92 | #endif 93 | #if defined(CPU_X86) || defined(CPU_X86_64) 94 | #include "funchook_x86.h" 95 | #endif 96 | 97 | #define JUMP32_BYTE_SIZE (JUMP32_SIZE * sizeof(insn_t)) 98 | #define TRAMPOLINE_BYTE_SIZE (TRAMPOLINE_SIZE * sizeof(insn_t)) 99 | 100 | /* This must be same with sysconf(_SC_PAGE_SIZE) on Unix 101 | * or the dwPageSize member of the SYSTEM_INFO structure on Windows. 102 | */ 103 | #undef PAGE_SIZE 104 | #define PAGE_SIZE 0x1000 /* 4k */ 105 | 106 | /* This must be same with the dwAllocationGranularity 107 | * member of the SYSTEM_INFO structure on Windows. 108 | */ 109 | #define ALLOCATION_UNIT 0x10000 /* 64k */ 110 | 111 | typedef struct { 112 | void *addr; 113 | size_t size; 114 | #ifdef _WIN32 115 | DWORD protect; 116 | #endif 117 | } mem_state_t; 118 | 119 | typedef struct funchook_page { 120 | #ifdef FUNCHOOK_ENTRY_AT_PAGE_BOUNDARY 121 | funchook_entry_t entries[1]; /* This contains at most one. */ 122 | #endif 123 | struct funchook_page *next; 124 | uint16_t used; 125 | #ifndef FUNCHOOK_ENTRY_AT_PAGE_BOUNDARY 126 | funchook_entry_t entries[1]; /* This contains zero or more. */ 127 | #endif 128 | } funchook_page_t; 129 | 130 | /* Functions in funchook.c */ 131 | extern const size_t funchook_size; 132 | extern char funchook_debug_file[]; 133 | void funchook_log(funchook_t *funchook, const char *fmt, ...) ATTR_FORMAT_PRINTF(2, 3); 134 | void funchook_set_error_message(funchook_t *funchook, const char *fmt, ...) ATTR_FORMAT_PRINTF(2, 3); 135 | 136 | /* Functions in funchook_linux.c & funchook_windows.c */ 137 | extern const size_t page_size; 138 | extern const size_t allocation_unit; /* windows only */ 139 | 140 | funchook_t *funchook_alloc(void); 141 | int funchook_free(funchook_t *funchook); 142 | 143 | int funchook_page_alloc(funchook_t *funchook, funchook_page_t **page_out, uint8_t *func, ip_displacement_t *disp); 144 | int funchook_page_free(funchook_t *funchook, funchook_page_t *page); 145 | int funchook_page_protect(funchook_t *funchook, funchook_page_t *page); 146 | int funchook_page_unprotect(funchook_t *funchook, funchook_page_t *page); 147 | 148 | int funchook_unprotect_begin(funchook_t *funchook, mem_state_t *mstate, void *addr, size_t len); 149 | int funchook_unprotect_end(funchook_t *funchook, const mem_state_t *mstate); 150 | 151 | void *funchook_resolve_func(funchook_t *funchook, void *func); 152 | 153 | /* Functions in funchook_{CPU_NAME}.c */ 154 | int funchook_make_trampoline(funchook_t *funchook, ip_displacement_t *disp, const insn_t *func, insn_t *trampoline, size_t *trampoline_size); 155 | int funchook_fix_code(funchook_t *funchook, funchook_entry_t *entry, const ip_displacement_t *disp); 156 | #ifdef CPU_X86_64 157 | int funchook_page_avail(funchook_t *funchook, funchook_page_t *page, int idx, uint8_t *addr, ip_displacement_t *disp); 158 | #else 159 | #define funchook_page_avail(funchook, page, idx, addr, disp) (1) 160 | #endif 161 | 162 | #endif 163 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: Google 4 | AccessModifierOffset: -1 5 | AlignAfterOpenBracket: Align 6 | AlignArrayOfStructures: None 7 | AlignConsecutiveAssignments: 8 | Enabled: false 9 | AcrossEmptyLines: false 10 | AcrossComments: false 11 | AlignCompound: false 12 | PadOperators: true 13 | AlignConsecutiveBitFields: 14 | Enabled: false 15 | AcrossEmptyLines: false 16 | AcrossComments: false 17 | AlignCompound: false 18 | PadOperators: false 19 | AlignConsecutiveDeclarations: 20 | Enabled: false 21 | AcrossEmptyLines: false 22 | AcrossComments: false 23 | AlignCompound: false 24 | PadOperators: false 25 | AlignConsecutiveMacros: 26 | Enabled: false 27 | AcrossEmptyLines: false 28 | AcrossComments: false 29 | AlignCompound: false 30 | PadOperators: false 31 | AlignEscapedNewlines: Left 32 | AlignOperands: Align 33 | AlignTrailingComments: true 34 | AllowAllArgumentsOnNextLine: true 35 | AllowAllParametersOfDeclarationOnNextLine: true 36 | AllowShortEnumsOnASingleLine: true 37 | AllowShortBlocksOnASingleLine: Never 38 | AllowShortCaseLabelsOnASingleLine: false 39 | AllowShortFunctionsOnASingleLine: All 40 | AllowShortLambdasOnASingleLine: All 41 | AllowShortIfStatementsOnASingleLine: WithoutElse 42 | AllowShortLoopsOnASingleLine: true 43 | AlwaysBreakAfterDefinitionReturnType: None 44 | AlwaysBreakAfterReturnType: None 45 | AlwaysBreakBeforeMultilineStrings: true 46 | AlwaysBreakTemplateDeclarations: Yes 47 | AttributeMacros: 48 | - __capability 49 | BinPackArguments: true 50 | BinPackParameters: true 51 | BraceWrapping: 52 | AfterCaseLabel: false 53 | AfterClass: false 54 | AfterControlStatement: Never 55 | AfterEnum: false 56 | AfterFunction: false 57 | AfterNamespace: false 58 | AfterObjCDeclaration: false 59 | AfterStruct: false 60 | AfterUnion: false 61 | AfterExternBlock: false 62 | BeforeCatch: false 63 | BeforeElse: false 64 | BeforeLambdaBody: false 65 | BeforeWhile: false 66 | IndentBraces: false 67 | SplitEmptyFunction: true 68 | SplitEmptyRecord: true 69 | SplitEmptyNamespace: true 70 | BreakBeforeBinaryOperators: None 71 | BreakBeforeConceptDeclarations: Always 72 | BreakBeforeBraces: Attach 73 | BreakBeforeInheritanceComma: false 74 | BreakInheritanceList: BeforeColon 75 | BreakBeforeTernaryOperators: true 76 | BreakConstructorInitializersBeforeComma: false 77 | BreakConstructorInitializers: BeforeColon 78 | BreakAfterJavaFieldAnnotations: false 79 | BreakStringLiterals: true 80 | ColumnLimit: 140 81 | CommentPragmas: '^ IWYU pragma:' 82 | QualifierAlignment: Leave 83 | CompactNamespaces: false 84 | ConstructorInitializerIndentWidth: 4 85 | ContinuationIndentWidth: 4 86 | Cpp11BracedListStyle: true 87 | DeriveLineEnding: true 88 | DerivePointerAlignment: true 89 | DisableFormat: false 90 | EmptyLineAfterAccessModifier: Never 91 | EmptyLineBeforeAccessModifier: LogicalBlock 92 | ExperimentalAutoDetectBinPacking: false 93 | PackConstructorInitializers: NextLine 94 | BasedOnStyle: '' 95 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 96 | AllowAllConstructorInitializersOnNextLine: true 97 | FixNamespaceComments: true 98 | ForEachMacros: 99 | - foreach 100 | - Q_FOREACH 101 | - BOOST_FOREACH 102 | IfMacros: 103 | - KJ_IF_MAYBE 104 | IncludeBlocks: Regroup 105 | IncludeCategories: 106 | - Regex: '^' 107 | Priority: 2 108 | SortPriority: 0 109 | CaseSensitive: false 110 | - Regex: '^<.*\.h>' 111 | Priority: 1 112 | SortPriority: 0 113 | CaseSensitive: false 114 | - Regex: '^<.*' 115 | Priority: 2 116 | SortPriority: 0 117 | CaseSensitive: false 118 | - Regex: '.*' 119 | Priority: 3 120 | SortPriority: 0 121 | CaseSensitive: false 122 | IncludeIsMainRegex: '([-_](test|unittest))?$' 123 | IncludeIsMainSourceRegex: '' 124 | IndentAccessModifiers: false 125 | IndentCaseLabels: true 126 | IndentCaseBlocks: false 127 | IndentGotoLabels: true 128 | IndentPPDirectives: None 129 | IndentExternBlock: AfterExternBlock 130 | IndentRequiresClause: true 131 | IndentWidth: 4 132 | IndentWrappedFunctionNames: false 133 | InsertBraces: false 134 | InsertTrailingCommas: None 135 | JavaScriptQuotes: Leave 136 | JavaScriptWrapImports: true 137 | KeepEmptyLinesAtTheStartOfBlocks: false 138 | LambdaBodyIndentation: Signature 139 | MacroBlockBegin: '' 140 | MacroBlockEnd: '' 141 | MaxEmptyLinesToKeep: 1 142 | NamespaceIndentation: All 143 | ObjCBinPackProtocolList: Never 144 | ObjCBlockIndentWidth: 2 145 | ObjCBreakBeforeNestedBlockParam: true 146 | ObjCSpaceAfterProperty: false 147 | ObjCSpaceBeforeProtocolList: true 148 | PenaltyBreakAssignment: 2 149 | PenaltyBreakBeforeFirstCallParameter: 1 150 | PenaltyBreakComment: 300 151 | PenaltyBreakFirstLessLess: 120 152 | PenaltyBreakOpenParenthesis: 0 153 | PenaltyBreakString: 1000 154 | PenaltyBreakTemplateDeclaration: 10 155 | PenaltyExcessCharacter: 1000000 156 | PenaltyReturnTypeOnItsOwnLine: 200 157 | PenaltyIndentedWhitespace: 0 158 | PointerAlignment: Left 159 | PPIndentWidth: -1 160 | RawStringFormats: 161 | - Language: Cpp 162 | Delimiters: 163 | - cc 164 | - CC 165 | - cpp 166 | - Cpp 167 | - CPP 168 | - 'c++' 169 | - 'C++' 170 | CanonicalDelimiter: '' 171 | BasedOnStyle: google 172 | - Language: TextProto 173 | Delimiters: 174 | - pb 175 | - PB 176 | - proto 177 | - PROTO 178 | EnclosingFunctions: 179 | - EqualsProto 180 | - EquivToProto 181 | - PARSE_PARTIAL_TEXT_PROTO 182 | - PARSE_TEST_PROTO 183 | - PARSE_TEXT_PROTO 184 | - ParseTextOrDie 185 | - ParseTextProtoOrDie 186 | - ParseTestProto 187 | - ParsePartialTestProto 188 | CanonicalDelimiter: pb 189 | BasedOnStyle: google 190 | ReferenceAlignment: Pointer 191 | ReflowComments: true 192 | RemoveBracesLLVM: false 193 | RequiresClausePosition: OwnLine 194 | SeparateDefinitionBlocks: Leave 195 | ShortNamespaceLines: 1 196 | SortIncludes: Never 197 | SortJavaStaticImport: Before 198 | SortUsingDeclarations: true 199 | SpaceAfterCStyleCast: false 200 | SpaceAfterLogicalNot: false 201 | SpaceAfterTemplateKeyword: true 202 | SpaceBeforeAssignmentOperators: true 203 | SpaceBeforeCaseColon: false 204 | SpaceBeforeCpp11BracedList: false 205 | SpaceBeforeCtorInitializerColon: true 206 | SpaceBeforeInheritanceColon: true 207 | SpaceBeforeParens: ControlStatements 208 | SpaceBeforeParensOptions: 209 | AfterControlStatements: true 210 | AfterForeachMacros: true 211 | AfterFunctionDefinitionName: false 212 | AfterFunctionDeclarationName: false 213 | AfterIfMacros: true 214 | AfterOverloadedOperator: false 215 | AfterRequiresInClause: false 216 | AfterRequiresInExpression: false 217 | BeforeNonEmptyParentheses: false 218 | SpaceAroundPointerQualifiers: Default 219 | SpaceBeforeRangeBasedForLoopColon: true 220 | SpaceInEmptyBlock: false 221 | SpaceInEmptyParentheses: false 222 | SpacesBeforeTrailingComments: 2 223 | SpacesInAngles: Never 224 | SpacesInConditionalStatement: false 225 | SpacesInContainerLiterals: true 226 | SpacesInCStyleCastParentheses: false 227 | SpacesInLineCommentPrefix: 228 | Minimum: 1 229 | Maximum: -1 230 | SpacesInParentheses: false 231 | SpacesInSquareBrackets: false 232 | SpaceBeforeSquareBrackets: false 233 | BitFieldColonSpacing: Both 234 | Standard: Auto 235 | StatementAttributeLikeMacros: 236 | - Q_EMIT 237 | StatementMacros: 238 | - Q_UNUSED 239 | - QT_REQUIRE_VERSION 240 | TabWidth: 8 241 | UseCRLF: false 242 | UseTab: Never 243 | WhitespaceSensitiveMacros: 244 | - STRINGIZE 245 | - PP_STRINGIZE 246 | - BOOST_PP_STRINGIZE 247 | - NS_SWIFT_NAME 248 | - CF_SWIFT_NAME 249 | ... 250 | 251 | -------------------------------------------------------------------------------- /cs2-sdk/include/stb/stb.hh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file stb.hh 3 | * @author Cristei Gabriel-Marian (cristei.g772@gmail.com) 4 | * @brief Compile-time String To Bytes (STB) 5 | * @version 1.0 6 | * @date 2023-03-23 7 | * 8 | * Last update: 03/23/2023 (mm/dd/yyyy): [Breaking update] 9 | * Modernize, undo some cancer, change some naming, file structure, 10 | * implement tests directly in file. 11 | * 12 | */ 13 | 14 | #ifndef STB_DEFINED 15 | #define STB_DEFINED 16 | 17 | #include 18 | #include 19 | 20 | namespace stb { 21 | namespace detail { 22 | // detail methods assume null terminator. 23 | 24 | template 25 | constexpr auto find_first_of_start(std::array const& data, std::size_t start, char ch) noexcept { 26 | std::size_t idx = start; 27 | while (data[idx] != ch && idx < N) 28 | ++idx; 29 | 30 | return idx; 31 | } 32 | 33 | template 34 | constexpr auto find_first_not_of_start(std::array const& data, std::size_t start, char ch) noexcept { 35 | if (start < N && data[start] != ch) 36 | return start; 37 | 38 | std::size_t idx = start; 39 | while (data[idx] == ch && idx < N) 40 | ++idx; 41 | 42 | return idx; 43 | } 44 | 45 | template 46 | constexpr auto find_last_of(std::array const& data, char ch) noexcept { 47 | std::size_t idx = data.size() - 2; 48 | while (data[idx] != ch && idx >= 0) 49 | --idx; 50 | 51 | return idx; 52 | } 53 | 54 | template 55 | constexpr auto find_last_not_of(std::array const& data, char ch) noexcept { 56 | std::size_t idx = data.size() - 2; 57 | while (data[idx] == ch && idx >= 0) 58 | --idx; 59 | 60 | return idx; 61 | } 62 | 63 | constexpr auto char_to_hex(char ch) noexcept { 64 | if (ch >= '0' && ch <= '9') 65 | return ch - '0'; 66 | 67 | if (ch >= 'A' && ch <= 'F') 68 | return ch - 'A' + 10; 69 | 70 | return ch - 'a' + 10; 71 | } 72 | 73 | template 74 | constexpr T concat_hex(T lhs, T rhs) noexcept { 75 | return F * lhs + rhs; 76 | } 77 | } // namespace detail 78 | 79 | template 80 | struct consteval_value { 81 | constexpr static decltype(V) value = V; 82 | }; 83 | 84 | template 85 | struct fixed_string: public std::array { 86 | using std::array::array; 87 | 88 | constexpr fixed_string(const char* str) noexcept 89 | : std::array() { 90 | for (auto i = 0; i != N; ++i) 91 | (*this)[i] = str[i]; 92 | } 93 | }; 94 | 95 | template 96 | fixed_string(const char (&)[N]) noexcept -> fixed_string; 97 | 98 | template 99 | struct basic_hex_string_array_conversion { 100 | template 101 | struct build { 102 | private: 103 | struct parse { 104 | struct result { 105 | std::size_t delimiter_count; 106 | std::size_t start; 107 | std::size_t next; 108 | std::size_t end; 109 | }; 110 | 111 | constexpr static auto get() noexcept { 112 | std::size_t count = 1; 113 | 114 | constexpr std::size_t start = detail::find_first_not_of_start(str, 0, delimiter); 115 | constexpr std::size_t next = detail::find_first_of_start(str, start, delimiter); 116 | constexpr std::size_t end = detail::find_last_not_of(str, delimiter); 117 | 118 | bool previous_delimiter = false; 119 | for (auto i = next; i < end; ++i) { 120 | if (str[i] == delimiter) { 121 | if (!previous_delimiter) 122 | ++count; 123 | 124 | previous_delimiter = true; 125 | } else 126 | previous_delimiter = false; 127 | } 128 | 129 | return result { 130 | count, 131 | start, 132 | next, 133 | end}; 134 | } 135 | }; 136 | 137 | constexpr static auto make() noexcept { 138 | constexpr auto data = parse::get(); 139 | constexpr auto count = data.delimiter_count; 140 | constexpr auto start = data.start; 141 | constexpr auto next = data.next; 142 | constexpr auto end = data.end; 143 | 144 | std::array result = {}; 145 | std::array skips = {}; 146 | std::size_t skipped = 0; 147 | std::size_t traversed = start; 148 | 149 | bool previous_skip = false; 150 | for (auto i = start; i < end; ++i) { 151 | if (str[i] == delimiter) { 152 | if (!previous_skip) 153 | skips[skipped++] = traversed; 154 | 155 | previous_skip = true; 156 | } else 157 | previous_skip = false; 158 | 159 | ++traversed; 160 | } 161 | 162 | bool one_char = str[start + 1] == delimiter; 163 | result[0] = static_cast(str[start] == mask ? masked : (one_char ? detail::char_to_hex(str[start]) : detail::concat_hex(detail::char_to_hex(str[start]), detail::char_to_hex(str[start + 1])))); 164 | 165 | std::size_t conversions = 1; 166 | for (auto i = next; i < end; ++i) { 167 | for (auto entry : skips) { 168 | if (entry == i && entry < end) { 169 | std::size_t idx = detail::find_first_not_of_start(str, i + 1, delimiter); 170 | one_char = str[idx + 1] == delimiter; 171 | result[conversions++] = static_cast(str[idx] == mask ? masked : (one_char ? detail::char_to_hex(str[idx]) : detail::concat_hex(detail::char_to_hex(str[idx]), detail::char_to_hex(str[idx + 1])))); 172 | } 173 | } 174 | } 175 | 176 | return result; 177 | } 178 | 179 | public: 180 | constexpr static auto value = consteval_value::value; 181 | }; 182 | }; 183 | 184 | using hex_string_array_conversion = basic_hex_string_array_conversion<' ', '?', int, -1>; 185 | using simple_conversion = hex_string_array_conversion; 186 | } // namespace stb 187 | 188 | #ifndef STB_OMIT_TESTS 189 | struct _ignore_me_stb_compliance_tests { 190 | using conv_type = stb::simple_conversion; 191 | 192 | constexpr static auto value_1 = conv_type::build<"AA BB CC DD EE FF">::value; 193 | static_assert(value_1[0] == 0xAA); 194 | static_assert(value_1[1] == 0xBB); 195 | static_assert(value_1[2] == 0xCC); 196 | static_assert(value_1[3] == 0xDD); 197 | static_assert(value_1[4] == 0xEE); 198 | static_assert(value_1[5] == 0xFF); 199 | static_assert(value_1.size() == 6); 200 | 201 | constexpr static auto value_2 = conv_type::build<" C 0f C a B ef ">::value; 202 | static_assert(value_2[0] == 0x0C); 203 | static_assert(value_2[1] == 0x0F); 204 | static_assert(value_2[2] == 0x0C); 205 | static_assert(value_2[3] == 0x0A); 206 | static_assert(value_2[4] == 0x0B); 207 | static_assert(value_2[5] == 0xEF); 208 | static_assert(value_2.size() == 6); 209 | 210 | constexpr static auto value_3 = conv_type::build<"AA bb CC dd ">::value; 211 | static_assert(value_3[0] == 0xAA); 212 | static_assert(value_3[1] == 0xBB); 213 | static_assert(value_3[2] == 0xCC); 214 | static_assert(value_3[3] == 0xDD); 215 | static_assert(value_3.size() == 4); 216 | 217 | constexpr static auto value_4 = conv_type::build<" aa bb ee ff">::value; 218 | static_assert(value_4[0] == 0xAA); 219 | static_assert(value_4[1] == 0xBB); 220 | static_assert(value_4[2] == 0xEE); 221 | static_assert(value_4[3] == 0xFF); 222 | static_assert(value_4.size() == 4); 223 | }; 224 | #endif 225 | 226 | #endif 227 | -------------------------------------------------------------------------------- /cs2-sdk/cs2-sdk.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /cs2-sdk/src/hooks/render/directx11/directx11_hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | static ID3D11Device* g_Device = NULL; 19 | static ID3D11DeviceContext* g_DeviceContext = NULL; 20 | static ID3D11RenderTargetView* g_RenderTarget = NULL; 21 | static IDXGISwapChain* g_SwapChain = NULL; 22 | 23 | static auto GetCorrectDXGIFormat(DXGI_FORMAT currentFormat) { 24 | switch (currentFormat) { 25 | case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: 26 | return DXGI_FORMAT_R8G8B8A8_UNORM; 27 | } 28 | 29 | return currentFormat; 30 | } 31 | 32 | static bool CreateDevice(HWND hWnd) { 33 | SDK_LOG_PROLOGUE(); 34 | 35 | DXGI_SWAP_CHAIN_DESC swapChainDesc = {}; 36 | swapChainDesc.Windowed = TRUE; 37 | swapChainDesc.BufferCount = 2; 38 | swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 39 | swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 40 | swapChainDesc.OutputWindow = hWnd; 41 | swapChainDesc.SampleDesc.Count = 1; 42 | 43 | constexpr D3D_FEATURE_LEVEL featureLevels[] = { 44 | D3D_FEATURE_LEVEL_11_0, 45 | D3D_FEATURE_LEVEL_10_0, 46 | }; 47 | 48 | HRESULT hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_NULL, NULL, 0, featureLevels, 2, D3D11_SDK_VERSION, &swapChainDesc, 49 | &g_SwapChain, &g_Device, nullptr, nullptr); 50 | 51 | return hr == S_OK; 52 | } 53 | 54 | static void CreateRenderTarget(IDXGISwapChain* pSwapChain) { 55 | SDK_LOG_PROLOGUE(); 56 | 57 | ID3D11Texture2D* pBackBuffer = NULL; 58 | pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); 59 | if (pBackBuffer) { 60 | DXGI_SWAP_CHAIN_DESC sd; 61 | pSwapChain->GetDesc(&sd); 62 | 63 | D3D11_RENDER_TARGET_VIEW_DESC desc = {}; 64 | desc.Format = GetCorrectDXGIFormat(sd.BufferDesc.Format); 65 | 66 | desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS; 67 | if (FAILED(g_Device->CreateRenderTargetView(pBackBuffer, &desc, &g_RenderTarget))) { 68 | desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; 69 | if (FAILED(g_Device->CreateRenderTargetView(pBackBuffer, &desc, &g_RenderTarget))) { 70 | if (FAILED(g_Device->CreateRenderTargetView(pBackBuffer, NULL, &g_RenderTarget))) { 71 | CLogger::Log("[dx11] CreateRenderTargetView() failed!"); 72 | } 73 | } 74 | } 75 | 76 | pBackBuffer->Release(); 77 | } 78 | } 79 | 80 | static void CleanupRenderTarget() { 81 | SDK_LOG_PROLOGUE(); 82 | 83 | if (g_RenderTarget) { 84 | g_RenderTarget->Release(); 85 | g_RenderTarget = NULL; 86 | } 87 | } 88 | 89 | static void CleanupDevice() { 90 | SDK_LOG_PROLOGUE(); 91 | 92 | CleanupRenderTarget(); 93 | 94 | if (g_SwapChain) { 95 | g_SwapChain->Release(); 96 | g_SwapChain = NULL; 97 | } 98 | if (g_Device) { 99 | g_Device->Release(); 100 | g_Device = NULL; 101 | } 102 | if (g_DeviceContext) { 103 | g_DeviceContext->Release(); 104 | g_DeviceContext = NULL; 105 | } 106 | } 107 | 108 | static void RenderImGui(IDXGISwapChain* pSwapChain) { 109 | if (!ImGui::GetCurrentContext()) return; 110 | 111 | if (!ImGui::GetIO().BackendRendererUserData) { 112 | if (SUCCEEDED(pSwapChain->GetDevice(IID_PPV_ARGS(&g_Device)))) { 113 | g_Device->GetImmediateContext(&g_DeviceContext); 114 | ImGui_ImplDX11_Init(g_Device, g_DeviceContext); 115 | 116 | CRenderer::Get().Initialize(); 117 | } else { 118 | return CLogger::Log("[dx11] GetDevice() failed!"); 119 | } 120 | } 121 | 122 | if (!g_RenderTarget) { 123 | CreateRenderTarget(pSwapChain); 124 | } else { 125 | ImGui_ImplDX11_NewFrame(); 126 | ImGui_ImplWin32_NewFrame(); 127 | ImGui::NewFrame(); 128 | 129 | CRenderer::Get().NewFrame(); 130 | 131 | ImGui::Render(); 132 | g_DeviceContext->OMSetRenderTargets(1, &g_RenderTarget, NULL); 133 | ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); 134 | } 135 | } 136 | 137 | static CHook g_Present; 138 | static HRESULT WINAPI hkPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) { 139 | RenderImGui(pSwapChain); 140 | 141 | return g_Present.CallOriginal(pSwapChain, SyncInterval, Flags); 142 | } 143 | 144 | static CHook g_Present1; 145 | static HRESULT WINAPI hkPresent1(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT PresentFlags, 146 | const DXGI_PRESENT_PARAMETERS* pPresentParameters) { 147 | RenderImGui(pSwapChain); 148 | 149 | return g_Present1.CallOriginal(pSwapChain, SyncInterval, PresentFlags, pPresentParameters); 150 | } 151 | 152 | static CHook g_ResizeBuffers; 153 | static HRESULT WINAPI hkResizeBuffers(IDXGISwapChain* pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, 154 | UINT SwapChainFlags) { 155 | CleanupRenderTarget(); 156 | 157 | return g_ResizeBuffers.CallOriginal(pSwapChain, BufferCount, Width, Height, NewFormat, SwapChainFlags); 158 | } 159 | 160 | static CHook g_ResizeBuffers1; 161 | static HRESULT WINAPI hkResizeBuffers1(IDXGISwapChain* pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, 162 | UINT SwapChainFlags, const UINT* pCreationNodeMask, IUnknown* const* ppPresentQueue) { 163 | CleanupRenderTarget(); 164 | 165 | return g_ResizeBuffers1.CallOriginal(pSwapChain, BufferCount, Width, Height, NewFormat, SwapChainFlags, pCreationNodeMask, 166 | ppPresentQueue); 167 | } 168 | 169 | static CHook g_CreateSwapChain; 170 | static HRESULT WINAPI hkCreateSwapChain(IDXGIFactory* pFactory, IUnknown* pDevice, DXGI_SWAP_CHAIN_DESC* pDesc, 171 | IDXGISwapChain** ppSwapChain) { 172 | CleanupRenderTarget(); 173 | 174 | return g_CreateSwapChain.CallOriginal(pFactory, pDevice, pDesc, ppSwapChain); 175 | } 176 | 177 | static CHook g_CreateSwapChainForHwnd; 178 | static HRESULT WINAPI hkCreateSwapChainForHwnd(IDXGIFactory* pFactory, IUnknown* pDevice, HWND hWnd, const DXGI_SWAP_CHAIN_DESC1* pDesc, 179 | const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc, IDXGIOutput* pRestrictToOutput, 180 | IDXGISwapChain1** ppSwapChain) { 181 | CleanupRenderTarget(); 182 | 183 | return g_CreateSwapChainForHwnd.CallOriginal(pFactory, pDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput, ppSwapChain); 184 | } 185 | 186 | static CHook g_CreateSwapChainForCoreWindow; 187 | static HRESULT WINAPI hkCreateSwapChainForCoreWindow(IDXGIFactory* pFactory, IUnknown* pDevice, IUnknown* pWindow, 188 | const DXGI_SWAP_CHAIN_DESC1* pDesc, IDXGIOutput* pRestrictToOutput, 189 | IDXGISwapChain1** ppSwapChain) { 190 | CleanupRenderTarget(); 191 | 192 | return g_CreateSwapChainForCoreWindow.CallOriginal(pFactory, pDevice, pWindow, pDesc, pRestrictToOutput, ppSwapChain); 193 | } 194 | 195 | static CHook g_CreateSwapChainForComposition; 196 | static HRESULT WINAPI hkCreateSwapChainForComposition(IDXGIFactory* pFactory, IUnknown* pDevice, const DXGI_SWAP_CHAIN_DESC1* pDesc, 197 | IDXGIOutput* pRestrictToOutput, IDXGISwapChain1** ppSwapChain) { 198 | CleanupRenderTarget(); 199 | 200 | return g_CreateSwapChainForComposition.CallOriginal(pFactory, pDevice, pDesc, pRestrictToOutput, ppSwapChain); 201 | } 202 | 203 | void CDirectX11Hooks::Initialize() { 204 | SDK_LOG_PROLOGUE(); 205 | 206 | if (!CreateDevice(CWndProcHooks::Get().GetWindow())) { 207 | return CLogger::Log("[dx11] CreateDevice() failed!"); 208 | } 209 | 210 | IDXGIDevice* pDXGIDevice = NULL; 211 | g_Device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)); 212 | 213 | IDXGIAdapter* pDXGIAdapter = NULL; 214 | pDXGIDevice->GetAdapter(&pDXGIAdapter); 215 | 216 | IDXGIFactory* pIDXGIFactory = NULL; 217 | pDXGIAdapter->GetParent(IID_PPV_ARGS(&pIDXGIFactory)); 218 | 219 | g_CreateSwapChain.VHook(pIDXGIFactory, 10, SDK_HOOK(hkCreateSwapChain)); 220 | g_CreateSwapChainForHwnd.VHook(pIDXGIFactory, 15, SDK_HOOK(hkCreateSwapChainForHwnd)); 221 | g_CreateSwapChainForCoreWindow.VHook(pIDXGIFactory, 16, SDK_HOOK(hkCreateSwapChainForCoreWindow)); 222 | g_CreateSwapChainForComposition.VHook(pIDXGIFactory, 24, SDK_HOOK(hkCreateSwapChainForComposition)); 223 | 224 | g_Present.VHook(g_SwapChain, 8, SDK_HOOK(hkPresent)); 225 | g_Present1.VHook(g_SwapChain, 22, SDK_HOOK(hkPresent1)); 226 | 227 | g_ResizeBuffers.VHook(g_SwapChain, 13, SDK_HOOK(hkResizeBuffers)); 228 | g_ResizeBuffers1.VHook(g_SwapChain, 39, SDK_HOOK(hkResizeBuffers1)); 229 | 230 | pIDXGIFactory->Release(); 231 | pDXGIAdapter->Release(); 232 | pDXGIDevice->Release(); 233 | 234 | CleanupDevice(); 235 | } 236 | 237 | CDirectX11Hooks::~CDirectX11Hooks() { 238 | SDK_LOG_PROLOGUE(); 239 | 240 | if (ImGui::GetCurrentContext()) { 241 | ImGuiIO& io = ImGui::GetIO(); 242 | 243 | if (io.BackendRendererUserData) { 244 | ImGui_ImplDX11_Shutdown(); 245 | } 246 | 247 | if (io.BackendPlatformUserData) { 248 | ImGui_ImplWin32_Shutdown(); 249 | } 250 | 251 | ImGui::DestroyContext(); 252 | } 253 | 254 | CleanupDevice(); 255 | } 256 | -------------------------------------------------------------------------------- /cs2-sdk/libs/funchook/src/disasm_distorm.c: -------------------------------------------------------------------------------- 1 | /* -*- indent-tabs-mode: nil -*- 2 | * 3 | * This file is part of Funchook. 4 | * https://github.com/kubo/funchook 5 | * 6 | * Funchook is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation, either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * As a special exception, the copyright holders of this library give you 12 | * permission to link this library with independent modules to produce an 13 | * executable, regardless of the license terms of these independent 14 | * modules, and to copy and distribute the resulting executable under 15 | * terms of your choice, provided that you also meet, for each linked 16 | * independent module, the terms and conditions of the license of that 17 | * module. An independent module is a module which is not derived from or 18 | * based on this library. If you modify this library, you may extend this 19 | * exception to your version of the library, but you are not obliged to 20 | * do so. If you do not wish to do so, delete this exception statement 21 | * from your version. 22 | * 23 | * Funchook is distributed in the hope that it will be useful, but WITHOUT 24 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26 | * for more details. 27 | * 28 | * You should have received a copy of the GNU General Public License 29 | * along with Funchook. If not, see . 30 | */ 31 | #include "config.h" 32 | #include 33 | #include 34 | #include 35 | #include "funchook_internal.h" 36 | #include "disasm.h" 37 | 38 | int funchook_disasm_init(funchook_disasm_t *disasm, funchook_t *funchook, const uint8_t *code, size_t code_size, size_t address) 39 | { 40 | _DecodeResult decres; 41 | 42 | disasm->funchook = funchook; 43 | disasm->ci.codeOffset = address; 44 | disasm->ci.code = code; 45 | disasm->ci.codeLen = (int)code_size; 46 | #ifdef CPU_X86_64 47 | disasm->ci.dt = Decode64Bits; 48 | #else 49 | disasm->ci.dt = Decode32Bits; 50 | #endif 51 | disasm->ci.features = DF_STOP_ON_RET; 52 | disasm->idx = 0; 53 | decres = distorm_decompose64(&disasm->ci, disasm->dis, MAX_INSN_CHECK_SIZE, &disasm->cnt); 54 | if (decres != DECRES_SUCCESS) { 55 | funchook_set_error_message(funchook, "Disassemble Error: %d", decres); 56 | return FUNCHOOK_ERROR_DISASSEMBLY; 57 | } 58 | return 0; 59 | } 60 | 61 | void funchook_disasm_cleanup(funchook_disasm_t *disasm) 62 | { 63 | /* no need to free resources */ 64 | } 65 | 66 | int funchook_disasm_next(funchook_disasm_t *disasm, const funchook_insn_t **next_insn) 67 | { 68 | if (disasm->idx < disasm->cnt) { 69 | *next_insn = &disasm->dis[disasm->idx++]; 70 | return 0; 71 | } else { 72 | return FUNCHOOK_ERROR_END_OF_INSTRUCTION; 73 | } 74 | } 75 | 76 | void funchook_disasm_log_instruction(funchook_disasm_t *disasm, const funchook_insn_t *insn) 77 | { 78 | _DecodedInst dec; 79 | distorm_format64(&disasm->ci, insn, &dec); 80 | funchook_log(disasm->funchook, " "ADDR_FMT" (%02d) %-24s %s%s%s\n", 81 | (size_t)dec.offset, dec.size, (char*)dec.instructionHex.p, 82 | (char*)dec.mnemonic.p, dec.operands.length != 0 ? " " : "", (char*)dec.operands.p); 83 | } 84 | 85 | void funchook_disasm_x86_rip_relative(funchook_disasm_t *disasm, const funchook_insn_t *insn, rip_relative_t *rel_disp, rip_relative_t *rel_imm) 86 | { 87 | int opsiz = 0; 88 | int disp_offset = 0; 89 | int imm_offset = 0; 90 | int i; 91 | 92 | memset(rel_disp, 0, sizeof(rip_relative_t)); 93 | memset(rel_imm, 0, sizeof(rip_relative_t)); 94 | 95 | /* 96 | * Estimate total operand size and RIP-relative address offsets. 97 | */ 98 | for (i = 0; i < OPERANDS_NO && insn->ops[i].type != O_NONE; i++) { 99 | const _Operand *op = &insn->ops[i]; 100 | switch (op->type) { 101 | case O_IMM: 102 | opsiz += op->size / 8; 103 | break; 104 | case O_PC: 105 | rel_imm->addr = (uint8_t*)(size_t)(insn->addr + insn->size + insn->imm.addr); 106 | rel_imm->raddr = (intptr_t)insn->imm.addr; 107 | rel_imm->size = op->size; 108 | imm_offset = opsiz; 109 | opsiz += op->size / 8; 110 | break; 111 | case O_SMEM: 112 | if (insn->dispSize != 0 && op->index == R_RIP) { 113 | rel_disp->addr = (uint8_t*)(size_t)(insn->addr + insn->size + insn->disp); 114 | rel_disp->raddr = (intptr_t)insn->disp; 115 | rel_disp->size = insn->dispSize; 116 | disp_offset = opsiz; 117 | } 118 | opsiz += insn->dispSize / 8; 119 | break; 120 | case O_MEM: 121 | case O_DISP: 122 | opsiz += insn->dispSize / 8; 123 | break; 124 | } 125 | } 126 | switch (insn->opcode) { 127 | /* CMPSD */ 128 | case I_CMPEQSD: 129 | case I_CMPLTSD: 130 | case I_CMPLESD: 131 | case I_CMPUNORDSD: 132 | case I_CMPNEQSD: 133 | case I_CMPNLTSD: 134 | case I_CMPNLESD: 135 | case I_CMPORDSD: 136 | case I_VCMPEQSD: 137 | case I_VCMPLTSD: 138 | case I_VCMPLESD: 139 | case I_VCMPUNORDSD: 140 | case I_VCMPNEQSD: 141 | case I_VCMPNLTSD: 142 | case I_VCMPNLESD: 143 | case I_VCMPORDSD: 144 | case I_VCMPEQ_UQSD: 145 | case I_VCMPNGESD: 146 | case I_VCMPNGTSD: 147 | case I_VCMPFALSESD: 148 | case I_VCMPNEQ_OQSD: 149 | case I_VCMPGESD: 150 | case I_VCMPGTSD: 151 | case I_VCMPTRUESD: 152 | case I_VCMPEQ_OSSD: 153 | case I_VCMPLT_OQSD: 154 | case I_VCMPLE_OQSD: 155 | case I_VCMPUNORD_SSD: 156 | case I_VCMPNEQ_USSD: 157 | case I_VCMPNLT_UQSD: 158 | case I_VCMPNLE_UQSD: 159 | case I_VCMPORD_SSD: 160 | case I_VCMPEQ_USSD: 161 | case I_VCMPNGE_UQSD: 162 | case I_VCMPNGT_UQSD: 163 | case I_VCMPFALSE_OSSD: 164 | case I_VCMPNEQ_OSSD: 165 | case I_VCMPGE_OQSD: 166 | case I_VCMPGT_OQSD: 167 | /* CMPSS */ 168 | case I_CMPEQSS: 169 | case I_CMPLTSS: 170 | case I_CMPLESS: 171 | case I_CMPUNORDSS: 172 | case I_CMPNEQSS: 173 | case I_CMPNLTSS: 174 | case I_CMPNLESS: 175 | case I_CMPORDSS: 176 | case I_VCMPEQSS: 177 | case I_VCMPLTSS: 178 | case I_VCMPLESS: 179 | case I_VCMPUNORDSS: 180 | case I_VCMPNEQSS: 181 | case I_VCMPNLTSS: 182 | case I_VCMPNLESS: 183 | case I_VCMPORDSS: 184 | case I_VCMPEQ_UQSS: 185 | case I_VCMPNGESS: 186 | case I_VCMPNGTSS: 187 | case I_VCMPFALSESS: 188 | case I_VCMPNEQ_OQSS: 189 | case I_VCMPGESS: 190 | case I_VCMPGTSS: 191 | case I_VCMPTRUESS: 192 | case I_VCMPEQ_OSSS: 193 | case I_VCMPLT_OQSS: 194 | case I_VCMPLE_OQSS: 195 | case I_VCMPUNORD_SSS: 196 | case I_VCMPNEQ_USSS: 197 | case I_VCMPNLT_UQSS: 198 | case I_VCMPNLE_UQSS: 199 | case I_VCMPORD_SSS: 200 | case I_VCMPEQ_USSS: 201 | case I_VCMPNGE_UQSS: 202 | case I_VCMPNGT_UQSS: 203 | case I_VCMPFALSE_OSSS: 204 | case I_VCMPNEQ_OSSS: 205 | case I_VCMPGE_OQSS: 206 | case I_VCMPGT_OQSS: 207 | /* CMPPD */ 208 | case I_CMPEQPD: 209 | case I_CMPLTPD: 210 | case I_CMPLEPD: 211 | case I_CMPUNORDPD: 212 | case I_CMPNEQPD: 213 | case I_CMPNLTPD: 214 | case I_CMPNLEPD: 215 | case I_CMPORDPD: 216 | case I_VCMPEQPD: 217 | case I_VCMPLTPD: 218 | case I_VCMPLEPD: 219 | case I_VCMPUNORDPD: 220 | case I_VCMPNEQPD: 221 | case I_VCMPNLTPD: 222 | case I_VCMPNLEPD: 223 | case I_VCMPORDPD: 224 | case I_VCMPEQ_UQPD: 225 | case I_VCMPNGEPD: 226 | case I_VCMPNGTPD: 227 | case I_VCMPFALSEPD: 228 | case I_VCMPNEQ_OQPD: 229 | case I_VCMPGEPD: 230 | case I_VCMPGTPD: 231 | case I_VCMPTRUEPD: 232 | case I_VCMPEQ_OSPD: 233 | case I_VCMPLT_OQPD: 234 | case I_VCMPLE_OQPD: 235 | case I_VCMPUNORD_SPD: 236 | case I_VCMPNEQ_USPD: 237 | case I_VCMPNLT_UQPD: 238 | case I_VCMPNLE_UQPD: 239 | case I_VCMPORD_SPD: 240 | case I_VCMPEQ_USPD: 241 | case I_VCMPNGE_UQPD: 242 | case I_VCMPNGT_UQPD: 243 | case I_VCMPFALSE_OSPD: 244 | case I_VCMPNEQ_OSPD: 245 | case I_VCMPGE_OQPD: 246 | case I_VCMPGT_OQPD: 247 | case I_VCMPTRUE_USPD: 248 | /* CMPPS */ 249 | case I_CMPEQPS: 250 | case I_CMPLTPS: 251 | case I_CMPLEPS: 252 | case I_CMPUNORDPS: 253 | case I_CMPNEQPS: 254 | case I_CMPNLTPS: 255 | case I_CMPNLEPS: 256 | case I_CMPORDPS: 257 | case I_VCMPEQPS: 258 | case I_VCMPLTPS: 259 | case I_VCMPLEPS: 260 | case I_VCMPUNORDPS: 261 | case I_VCMPNEQPS: 262 | case I_VCMPNLTPS: 263 | case I_VCMPNLEPS: 264 | case I_VCMPORDPS: 265 | case I_VCMPEQ_UQPS: 266 | case I_VCMPNGEPS: 267 | case I_VCMPNGTPS: 268 | case I_VCMPFALSEPS: 269 | case I_VCMPNEQ_OQPS: 270 | case I_VCMPGEPS: 271 | case I_VCMPGTPS: 272 | case I_VCMPTRUEPS: 273 | case I_VCMPEQ_OSPS: 274 | case I_VCMPLT_OQPS: 275 | case I_VCMPLE_OQPS: 276 | case I_VCMPUNORD_SPS: 277 | case I_VCMPNEQ_USPS: 278 | case I_VCMPNLT_UQPS: 279 | case I_VCMPNLE_UQPS: 280 | case I_VCMPORD_SPS: 281 | case I_VCMPEQ_USPS: 282 | case I_VCMPNGE_UQPS: 283 | case I_VCMPNGT_UQPS: 284 | case I_VCMPFALSE_OSPS: 285 | case I_VCMPNEQ_OSPS: 286 | case I_VCMPGE_OQPS: 287 | case I_VCMPGT_OQPS: 288 | case I_VCMPTRUE_USPS: 289 | /* ohters */ 290 | case I_PI2FD: 291 | case I_PI2FW: 292 | case I_PF2IW: 293 | case I_PF2ID: 294 | case I_PSWAPD: 295 | case I_VPBLENDVB: 296 | case I_PFNACC: 297 | opsiz++; 298 | } 299 | 300 | if (rel_disp->size > 0) { 301 | rel_disp->offset = insn->size - opsiz + disp_offset; 302 | funchook_log(disasm->funchook, " ip-relative %08x, absolute address= "ADDR_FMT", offset=%d, size=%d\n", 303 | (uint32_t)rel_disp->raddr, (size_t)rel_disp->addr, rel_disp->offset, rel_disp->size); 304 | } 305 | if (rel_imm->size > 0) { 306 | rel_imm->offset = insn->size - opsiz + imm_offset; 307 | funchook_log(disasm->funchook, " ip-relative %08x, absolute address= "ADDR_FMT", offset=%d, size=%d\n", 308 | (uint32_t)rel_imm->raddr, (size_t)rel_imm->addr, rel_imm->offset, rel_imm->size); 309 | } 310 | } 311 | --------------------------------------------------------------------------------