├── README.md ├── csgo.sln ├── csgo ├── AimAssist.cpp ├── AimAssist.h ├── BaseCombatWeapon.cpp ├── BaseCombatWeapon.h ├── BaseEntity.cpp ├── BaseEntity.h ├── Client.cpp ├── Client.h ├── ClientEntList.cpp ├── ClientEntList.h ├── Collideable.h ├── Engine.cpp ├── Engine.h ├── EngineTrace.cpp ├── EngineTrace.h ├── Esp.cpp ├── Esp.h ├── GameInterface.cpp ├── GameInterface.h ├── GameTrace.h ├── Hooks.cpp ├── Hooks.h ├── InputSystem.cpp ├── InputSystem.h ├── Loader.cpp ├── Loader.h ├── Math3.cpp ├── Math3.h ├── Menu.cpp ├── Menu.h ├── QAngle.cpp ├── QAngle.h ├── Surface.cpp ├── Surface.h ├── Timer.cpp ├── Timer.h ├── UserCmd.h ├── VTableHook.cpp ├── VTableHook.h ├── Vector2.cpp ├── Vector2.h ├── Vector3.cpp ├── Vector3.h ├── Vector4.cpp ├── Vector4.h ├── Vmatrix.h ├── Vpanel.cpp ├── Vpnanel.h ├── boneId.h ├── csgo.vcxproj ├── csgo.vcxproj.filters ├── imgui │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui_color_picker.cpp │ ├── imgui_color_picker.h │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_impl_dx9.cpp │ ├── imgui_impl_dx9.h │ ├── imgui_internal.h │ ├── stb_rect_pack.h │ ├── stb_textedit.h │ └── stb_truetype.h ├── inButtons.h ├── main.cpp ├── mask.h └── vmtIndexes.h ├── screenshot.png └── slides.pdf /README.md: -------------------------------------------------------------------------------- 1 | 2 | ██████╗███████╗ ██████╗ ██████╗ 3 | ██╔════╝██╔════╝██╗██╔════╝ ██╔═══██╗ 4 | ██║ ███████╗╚═╝██║ ███╗██║ ██║ 5 | ██║ ╚════██║██╗██║ ██║██║ ██║ 6 | ╚██████╗███████║╚═╝╚██████╔╝╚██████╔╝ 7 | ╚═════╝╚══════╝ ╚═════╝ ╚═════╝ 8 | HACK 9 | 10 | Description 11 | ============ 12 | 13 | Proof Of Concept of a CS:GO hack written in C++. 14 | I have done a conference about this project, you can check [slides.pdf](https://github.com/DimitriFourny/csgo-hack/blob/master/slides.pdf). 15 | 16 | 17 | Screenshot 18 | ============ 19 | 20 | ![Screenshot](https://raw.githubusercontent.com/DimitriFourny/csgo-hack/master/screenshot.png) -------------------------------------------------------------------------------- /csgo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "csgo", "csgo\csgo.vcxproj", "{6ADF7003-F0D3-459E-A66B-14E3901E6B68}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68}.Debug|x64.ActiveCfg = Debug|x64 17 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68}.Debug|x64.Build.0 = Debug|x64 18 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68}.Debug|x86.ActiveCfg = Debug|Win32 19 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68}.Debug|x86.Build.0 = Debug|Win32 20 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68}.Release|x64.ActiveCfg = Release|x64 21 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68}.Release|x64.Build.0 = Release|x64 22 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68}.Release|x86.ActiveCfg = Release|Win32 23 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /csgo/AimAssist.cpp: -------------------------------------------------------------------------------- 1 | #include "AimAssist.h" 2 | #include "Client.h" 3 | #include "ClientEntList.h" 4 | #include "Engine.h" 5 | #include "EngineTrace.h" 6 | #include "BaseCombatWeapon.h" 7 | #include "Math3.h" 8 | #include "boneId.h" 9 | #include "Menu.h" 10 | #include "inButtons.h" 11 | 12 | DWORD AimAssist::m_lastShot = 0; 13 | bool AimAssist::m_hasFired = false; 14 | bool AimAssist::m_hasZoomed = false; 15 | Timer AimAssist::m_zoomTimer = Timer(); 16 | 17 | AimAssist::AimAssist(Loader* loader) { 18 | m_loader = loader; 19 | } 20 | 21 | void AimAssist::triggerBot(UserCmd* userCmd) { 22 | Client* client = (Client*)m_loader->get(CLIENT); 23 | ClientEntList* clientEntList = (ClientEntList*)m_loader->get(CLIENTENTLIST); 24 | Engine* engine = (Engine*)m_loader->get(ENGINE); 25 | EngineTrace* engineTrace = (EngineTrace*)m_loader->get(ENGINETRACE); 26 | 27 | BaseEntity localPlayer = BaseEntity(m_loader); 28 | if (!clientEntList->getLocalPlayer(localPlayer)) { 29 | return; 30 | } 31 | 32 | if (localPlayer.getHealth() <= 0) { 33 | return; 34 | } 35 | 36 | BaseCombatWeapon weapon = BaseCombatWeapon(NULL, m_loader, localPlayer); 37 | if (!localPlayer.getWeapon(weapon)) { 38 | return; 39 | } 40 | 41 | if (!weapon.isGun() || weapon.isEmpty() || weapon.isReloading()) { 42 | return; 43 | } 44 | 45 | // Calc the forward vector 46 | QAngle viewAngle = userCmd->viewangles; 47 | viewAngle = viewAngle + localPlayer.getPunch() * 2.0f; 48 | Vector3 forward; 49 | Math3::angleToForwardVector(viewAngle, forward); 50 | forward = forward * weapon.getCSWpnData()->m_flRange; 51 | Vector3 src = localPlayer.getEyePosition(); 52 | Vector3 dst = src + forward; 53 | 54 | // Check if we target an enemy 55 | Ray ray; 56 | GameTrace tr; 57 | ray.init(src, dst); 58 | 59 | TraceFilter filter; 60 | filter.pSkip = localPlayer.self(); 61 | engineTrace->TraceRay(ray, MASK_SHOT, &filter, &tr); 62 | 63 | if (tr.m_pEnt != NULL) { 64 | BaseEntity enemy = BaseEntity(tr.m_pEnt, m_loader); 65 | if (!enemy.isDormant() && enemy.getHealth() > 0 && enemy.isEnemy()) { 66 | if (Menu::config.triggerbotWaitingTime > 0) { 67 | DWORD minDelay = m_lastShot + Menu::config.triggerbotWaitingTime; 68 | if (GetTickCount() < minDelay) { 69 | return; 70 | } 71 | m_lastShot = GetTickCount(); 72 | } 73 | 74 | userCmd->buttons |= IN_ATTACK; 75 | m_hasFired = true; 76 | } 77 | } 78 | } 79 | 80 | 81 | void AimAssist::aimBot(UserCmd* userCmd) { 82 | Client* client = (Client*)m_loader->get(CLIENT); 83 | ClientEntList* clientEntList = (ClientEntList*)m_loader->get(CLIENTENTLIST); 84 | Engine* engine = (Engine*)m_loader->get(ENGINE); 85 | EngineTrace* engineTrace = (EngineTrace*)m_loader->get(ENGINETRACE); 86 | 87 | BaseEntity localPlayer = BaseEntity(m_loader); 88 | if (!clientEntList->getLocalPlayer(localPlayer)) { 89 | return; 90 | } 91 | 92 | if (localPlayer.getHealth() <= 0) { 93 | return; 94 | } 95 | 96 | BaseCombatWeapon weapon = BaseCombatWeapon(NULL, m_loader, localPlayer); 97 | if (!localPlayer.getWeapon(weapon)) { 98 | return; 99 | } 100 | 101 | if (!weapon.isGun() || weapon.isEmpty() || weapon.isReloading()) { 102 | if (weapon.isSniperRifle() && weapon.zoomLevel() > 0) { 103 | m_zoomTimer.start(400); 104 | } 105 | 106 | return; 107 | } 108 | 109 | BaseEntity entity = BaseEntity(m_loader); 110 | float lowestDistance = -1; 111 | Vector3 vec; 112 | float distance; 113 | PVOID bestEnemy = NULL; 114 | 115 | // Search the best enemy 116 | for (int i = 0; i < clientEntList->getHighestEntityIndex(); i++) { 117 | if (!clientEntList->getClientEntity(i, entity)) { 118 | continue; 119 | } 120 | if (entity.getHealth() <= 0) { 121 | continue; 122 | } 123 | if (entity.isEnemy() && entity.isVisible(Terrorist::head_0)) { 124 | vec = entity.getEyePosition() - localPlayer.getEyePosition(); 125 | distance = vec.lengthSquare(); 126 | 127 | if (lowestDistance == -1 || distance < lowestDistance) { 128 | lowestDistance = distance; 129 | bestEnemy = entity.self(); 130 | } 131 | } 132 | } 133 | 134 | if (bestEnemy == NULL) { 135 | return; 136 | } 137 | BaseEntity enemy = BaseEntity(bestEnemy, m_loader); 138 | 139 | // Calc the angle 140 | Vector3 src = localPlayer.getEyePosition(); 141 | Vector3 dst = enemy.getBonePosition(Menu::config.aimbotBoneId); 142 | QAngle angle = Math3::angleBtwVectors(src, dst); 143 | angle = angle - localPlayer.getPunch() * 2.0f; 144 | 145 | // Smooth aim bot 146 | QAngle delta; 147 | if (Menu::config.smoothAimbot) { 148 | delta = angle - userCmd->viewangles; 149 | delta.clamp(); 150 | 151 | if (!delta.isNull()) { 152 | angle = userCmd->viewangles + delta*Menu::config.aimbotSmoothSpeed; 153 | } 154 | } 155 | 156 | // Set the angle 157 | angle.clamp(); 158 | userCmd->viewangles = angle; 159 | if (!Menu::config.silentAim) { 160 | engine->setViewAngles(angle); 161 | } 162 | 163 | if (Menu::config.smoothAimbot && !delta.isNull()) { 164 | return; 165 | } 166 | 167 | if (Menu::config.aimbotAutoFire) { 168 | if (Menu::config.aimbotWaitingTime > 0) { 169 | DWORD minDelay = m_lastShot + Menu::config.aimbotWaitingTime; 170 | if (GetTickCount() < minDelay) { 171 | return; 172 | } 173 | m_lastShot = GetTickCount(); 174 | } 175 | 176 | if (Menu::config.aimbotAutoZoom && weapon.isSniperRifle() && weapon.zoomLevel() == 0) { 177 | userCmd->buttons |= IN_ATTACK2; 178 | m_hasZoomed = true; 179 | return; 180 | } 181 | 182 | userCmd->buttons |= IN_ATTACK; 183 | m_hasFired = true; 184 | } 185 | } 186 | 187 | bool AimAssist::updateFireState(UserCmd* userCmd) { 188 | if (userCmd->command_number == 0) { 189 | return false; 190 | } 191 | 192 | if (m_hasZoomed) { 193 | m_hasZoomed = false; 194 | userCmd->buttons &= ~IN_ATTACK2; 195 | m_zoomTimer.start(250); 196 | return false; 197 | } 198 | if (Menu::config.aimbotAutoZoom && !m_zoomTimer.isElapsed()) { 199 | return false; 200 | } 201 | if (m_hasFired) { 202 | m_hasFired = false; 203 | userCmd->buttons &= ~IN_ATTACK; 204 | return false; 205 | } 206 | 207 | return true; 208 | } -------------------------------------------------------------------------------- /csgo/AimAssist.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Loader.h" 4 | #include "UserCmd.h" 5 | #include "Timer.h" 6 | 7 | class AimAssist { 8 | public: 9 | AimAssist(Loader* loader); 10 | void triggerBot(UserCmd* userCmd); 11 | void aimBot(UserCmd* userCmd); 12 | bool updateFireState(UserCmd* userCmd); 13 | 14 | private: 15 | Loader* m_loader; 16 | static DWORD m_lastShot; 17 | static bool m_hasFired; 18 | static bool m_hasZoomed; 19 | static Timer m_zoomTimer; 20 | }; -------------------------------------------------------------------------------- /csgo/BaseCombatWeapon.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseCombatWeapon.h" 2 | #include "Client.h" 3 | #include "Loader.h" 4 | 5 | int BaseCombatWeapon::m_offsetsInitialized = false; 6 | int BaseCombatWeapon::m_id = -1; 7 | int BaseCombatWeapon::m_clip1 = -1; 8 | int BaseCombatWeapon::m_isReloading = -1; 9 | int BaseCombatWeapon::m_zoomLevel = -1; 10 | 11 | BaseCombatWeapon::BaseCombatWeapon(PVOID pObject, Loader* loader, BaseEntity& player) : GameInterface(pObject, loader) { 12 | if (!m_offsetsInitialized) { 13 | Client* client = (Client*)m_loader->get(CLIENT); 14 | m_id = client->netvarOffset("DT_WeaponCSBase", "m_fAccuracyPenalty") + 0x30; 15 | m_clip1 = client->netvarOffset("DT_BaseCombatWeapon", "m_iClip1"); 16 | m_isReloading = 0x3235; 17 | m_zoomLevel = client->netvarOffset("DT_WeaponCSBaseGun", "m_zoomLevel"); 18 | m_offsetsInitialized = true; 19 | } 20 | } 21 | 22 | BaseCombatWeapon::~BaseCombatWeapon() { 23 | 24 | } 25 | 26 | int BaseCombatWeapon::getWeaponId() { 27 | return *(int*)((DWORD)self() + m_id); 28 | } 29 | 30 | bool BaseCombatWeapon::isGun() { 31 | int id = getWeaponId(); 32 | 33 | switch (id) { 34 | case WEAPON_DEAGLE: 35 | case WEAPON_ELITE: 36 | case WEAPON_FIVESEVEN: 37 | case WEAPON_GLOCK: 38 | case WEAPON_AK47: 39 | case WEAPON_AUG: 40 | case WEAPON_AWP: 41 | case WEAPON_FAMAS: 42 | case WEAPON_G3SG1: 43 | case WEAPON_GALILAR: 44 | case WEAPON_M249: 45 | case WEAPON_M4A1: 46 | case WEAPON_MAC10: 47 | case WEAPON_P90: 48 | case WEAPON_UMP45: 49 | case WEAPON_XM1014: 50 | case WEAPON_BIZON: 51 | case WEAPON_MAG7: 52 | case WEAPON_NEGEV: 53 | case WEAPON_SAWEDOFF: 54 | case WEAPON_TEC9: 55 | return true; 56 | case WEAPON_TASER: 57 | return false; 58 | case WEAPON_HKP2000: 59 | case WEAPON_MP7: 60 | case WEAPON_MP9: 61 | case WEAPON_NOVA: 62 | case WEAPON_P250: 63 | case WEAPON_SCAR20: 64 | case WEAPON_SG556: 65 | case WEAPON_SSG08: 66 | return true; 67 | case WEAPON_KNIFE: 68 | case WEAPON_FLASHBANG: 69 | case WEAPON_HEGRENADE: 70 | case WEAPON_SMOKEGRENADE: 71 | case WEAPON_MOLOTOV: 72 | case WEAPON_DECOY: 73 | case WEAPON_INCGRENADE: 74 | case WEAPON_C4: 75 | case WEAPON_KNIFE_T: 76 | return false; 77 | case WEAPON_M4A1_SILENCER: 78 | case WEAPON_USP_SILENCER: 79 | case WEAPON_CZ75A: 80 | case WEAPON_REVOLVER: 81 | return true; 82 | default: 83 | return false; 84 | } 85 | } 86 | 87 | bool BaseCombatWeapon::isSniperRifle() { 88 | int id = getWeaponId(); 89 | 90 | switch (id) { 91 | case WEAPON_AWP: 92 | case WEAPON_G3SG1: 93 | case WEAPON_SSG08: 94 | case WEAPON_SCAR20: 95 | return true; 96 | default: 97 | return false; 98 | } 99 | } 100 | 101 | bool BaseCombatWeapon::isEmpty() { 102 | int clip1 = *(int*)((DWORD)self() + m_clip1); 103 | return clip1 == 0; 104 | } 105 | 106 | bool BaseCombatWeapon::isReloading() { 107 | return *(bool*)((DWORD)self() + m_isReloading); 108 | } 109 | 110 | int BaseCombatWeapon::zoomLevel() { 111 | return *(int*)((DWORD)self() + m_zoomLevel); 112 | } 113 | 114 | WeaponInfo* BaseCombatWeapon::getCSWpnData() { 115 | typedef WeaponInfo*(__thiscall *GetCSWpnDataFn)(PVOID pThis); 116 | GetCSWpnDataFn oGetCSWpnData = (GetCSWpnDataFn)m_vtable->GetMethodAddress(VMT_GETCSWPNDATA); 117 | return oGetCSWpnData(self()); 118 | } -------------------------------------------------------------------------------- /csgo/BaseCombatWeapon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameInterface.h" 4 | #include "BaseEntity.h" 5 | 6 | enum ItemDefinitionIndex : int { 7 | WEAPON_DEAGLE = 1, 8 | WEAPON_ELITE = 2, 9 | WEAPON_FIVESEVEN = 3, 10 | WEAPON_GLOCK = 4, 11 | WEAPON_AK47 = 7, 12 | WEAPON_AUG = 8, 13 | WEAPON_AWP = 9, 14 | WEAPON_FAMAS = 10, 15 | WEAPON_G3SG1 = 11, 16 | WEAPON_GALILAR = 13, 17 | WEAPON_M249 = 14, 18 | WEAPON_M4A1 = 16, 19 | WEAPON_MAC10 = 17, 20 | WEAPON_P90 = 19, 21 | WEAPON_UMP45 = 24, 22 | WEAPON_XM1014 = 25, 23 | WEAPON_BIZON = 26, 24 | WEAPON_MAG7 = 27, 25 | WEAPON_NEGEV = 28, 26 | WEAPON_SAWEDOFF = 29, 27 | WEAPON_TEC9 = 30, 28 | WEAPON_TASER = 31, 29 | WEAPON_HKP2000 = 32, 30 | WEAPON_MP7 = 33, 31 | WEAPON_MP9 = 34, 32 | WEAPON_NOVA = 35, 33 | WEAPON_P250 = 36, 34 | WEAPON_SCAR20 = 38, 35 | WEAPON_SG556 = 39, 36 | WEAPON_SSG08 = 40, 37 | WEAPON_KNIFE = 42, 38 | WEAPON_FLASHBANG = 43, 39 | WEAPON_HEGRENADE = 44, 40 | WEAPON_SMOKEGRENADE = 45, 41 | WEAPON_MOLOTOV = 46, 42 | WEAPON_DECOY = 47, 43 | WEAPON_INCGRENADE = 48, 44 | WEAPON_C4 = 49, 45 | WEAPON_KNIFE_T = 59, 46 | WEAPON_M4A1_SILENCER = 60, 47 | WEAPON_USP_SILENCER = 61, 48 | WEAPON_CZ75A = 63, 49 | WEAPON_REVOLVER = 64, 50 | WEAPON_KNIFE_BAYONET = 500, 51 | WEAPON_KNIFE_FLIP = 505, 52 | WEAPON_KNIFE_GUT = 506, 53 | WEAPON_KNIFE_KARAMBIT = 507, 54 | WEAPON_KNIFE_M9_BAYONET = 508, 55 | WEAPON_KNIFE_TACTICAL = 509, 56 | WEAPON_KNIFE_FALCHION = 512, 57 | WEAPON_KNIFE_SURVIVAL_BOWIE = 514, 58 | WEAPON_KNIFE_BUTTERFLY = 515, 59 | WEAPON_KNIFE_PUSH = 516 60 | }; 61 | 62 | class WeaponInfo { 63 | public: 64 | char pad_0x0000[99]; //0x0000 65 | char m_name[80]; //0x0063 66 | char pad_0x07B0[0x74D]; //0x00B3 67 | float m_flArmorRatio; //0x0800 68 | float unkwn1; //0x0804 69 | float unkwn2; //0x0808 70 | __int32 unkwn3; //0x080C 71 | __int32 unkwn4; //0x0810 72 | float m_flPenetration; //0x0814 73 | __int32 m_iDamage; //0x0818 74 | float m_flRange; //0x081C 75 | float m_flRangeModifier; //0x0820 76 | }; 77 | 78 | class BaseCombatWeapon : public GameInterface { 79 | public: 80 | BaseCombatWeapon(PVOID pObject, Loader* loader, BaseEntity& player); 81 | ~BaseCombatWeapon(); 82 | int getWeaponId(); 83 | bool isGun(); 84 | bool isSniperRifle(); 85 | bool isEmpty(); 86 | bool isReloading(); 87 | int zoomLevel(); 88 | WeaponInfo* getCSWpnData(); 89 | 90 | private: 91 | static int m_offsetsInitialized; 92 | static int m_id; 93 | static int m_clip1; 94 | static int m_isReloading; 95 | static int m_zoomLevel; 96 | }; -------------------------------------------------------------------------------- /csgo/BaseEntity.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseEntity.h" 2 | #include "Client.h" 3 | #include "ClientEntList.h" 4 | #include "BaseCombatWeapon.h" 5 | #include 6 | 7 | bool BaseEntity::m_offsetsInitialized = false; 8 | int BaseEntity::m_teamNum = -1; 9 | int BaseEntity::m_health = -1; 10 | int BaseEntity::m_armorValue = -1; 11 | int BaseEntity::m_hashElmet = -1; 12 | int BaseEntity::m_vecOrigin = -1; 13 | int BaseEntity::m_collision = -1; 14 | int BaseEntity::m_isDormant = -1; 15 | int BaseEntity::m_vecViewOffset = -1; 16 | int BaseEntity::m_index = -1; 17 | int BaseEntity::m_activeWeapon = -1; 18 | int BaseEntity::m_aimPunchAngle = -1; 19 | 20 | BaseEntity::BaseEntity(PVOID pObject, Loader* loader) : GameInterface(pObject, loader) { 21 | if (!m_offsetsInitialized) { 22 | Client* client = (Client*)m_loader->get(CLIENT); 23 | m_teamNum = client->netvarOffset("DT_CSPlayer", "m_iTeamNum"); 24 | m_health = client->netvarOffset("DT_CSPlayer", "m_iHealth"); 25 | m_armorValue = client->netvarOffset("DT_CSPlayer", "m_ArmorValue"); 26 | m_hashElmet = client->netvarOffset("DT_CSPlayer", "m_bHasElmet"); 27 | m_vecOrigin = client->netvarOffset("DT_BasePlayer", "m_vecOrigin"); 28 | m_collision = client->netvarOffset("DT_CSPlayer", "m_Collision"); 29 | m_isDormant = 0xE9; 30 | m_vecViewOffset = client->netvarOffset("DT_CSPlayer", "m_vecViewOffset[0]"); 31 | m_index = 0x64; 32 | m_activeWeapon = client->netvarOffset("DT_CSPlayer", "m_hActiveWeapon"); 33 | m_aimPunchAngle = client->netvarOffset("DT_BasePlayer", "m_aimPunchAngle"); 34 | m_offsetsInitialized = true; 35 | } 36 | } 37 | 38 | bool BaseEntity::isEnemy() { 39 | ClientEntList* clientEntList = (ClientEntList*)m_loader->get(CLIENTENTLIST); 40 | BaseEntity localPlayer = BaseEntity(m_loader); 41 | if (!clientEntList->getLocalPlayer(localPlayer)) { 42 | return false; 43 | } 44 | 45 | int localTeamNumber = localPlayer.getTeamNum(); 46 | 47 | if (localTeamNumber == TEAM_TERRORIST) { 48 | return (getTeamNum() == TEAM_COUNTER_TERRORIST); 49 | } else if (localTeamNumber == TEAM_COUNTER_TERRORIST) { 50 | return (getTeamNum() == TEAM_TERRORIST); 51 | } 52 | 53 | return false; 54 | } 55 | 56 | bool BaseEntity::isVisible(int bone) { 57 | ClientEntList* clientEntList = (ClientEntList*)m_loader->get(CLIENTENTLIST); 58 | EngineTrace* engineTrace = (EngineTrace*)m_loader->get(ENGINETRACE); 59 | 60 | BaseEntity localPlayer = BaseEntity(m_loader); 61 | if (!clientEntList->getLocalPlayer(localPlayer)) { 62 | return false; 63 | } 64 | 65 | Ray ray; 66 | GameTrace tr; 67 | ray.init(localPlayer.getEyePosition(), getBonePosition(bone)); 68 | 69 | TraceFilter filter; 70 | filter.pSkip = localPlayer.self(); 71 | engineTrace->TraceRay(ray, MASK_SHOT, &filter, &tr); 72 | 73 | return (tr.m_pEnt == self()); 74 | } 75 | 76 | Vector3 BaseEntity::getBonePosition(int bone) { 77 | Matrix3x4 boneMatrixes[128]; 78 | 79 | if (setupBones(boneMatrixes, 128, 0x100, 0)) { 80 | Matrix3x4 boneMatrix = boneMatrixes[bone]; 81 | return Vector3(boneMatrix.m_matVal[0][3], boneMatrix.m_matVal[1][3], boneMatrix.m_matVal[2][3]); 82 | } else { 83 | return Vector3(0, 0, 0); 84 | } 85 | } 86 | 87 | bool BaseEntity::setupBones(Matrix3x4* pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime) { 88 | PVOID pRenderable = (PVOID)((DWORD)self() + sizeof(DWORD)); 89 | VTableHook vtable = VTableHook((DWORD**)pRenderable); 90 | 91 | typedef bool(__thiscall *SetupBonesFn)(PVOID pThis, Matrix3x4* pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime); 92 | SetupBonesFn oSetupBones = (SetupBonesFn) vtable.GetMethodAddress(VMT_SETUPBONES); 93 | return oSetupBones(pRenderable, pBoneToWorldOut, nMaxBones, boneMask, currentTime); 94 | } 95 | 96 | int BaseEntity::getTeamNum() { 97 | return *(int*)((DWORD)self() + m_teamNum); 98 | } 99 | 100 | int BaseEntity::getHealth() { 101 | return *(int*)((DWORD)self() + m_health); 102 | } 103 | 104 | int BaseEntity::getAmorValue() { 105 | return *(int*)((DWORD)self() + m_armorValue); 106 | } 107 | 108 | bool BaseEntity::hasElmet() { 109 | return *(bool*)((DWORD)self() + m_hashElmet); 110 | } 111 | 112 | Vector3 BaseEntity::getOrigin() { 113 | return *(Vector3*)((DWORD)self() + m_vecOrigin); 114 | } 115 | 116 | Collideable* BaseEntity::getCollideable() { 117 | return (Collideable*)((DWORD)self() + m_collision); 118 | } 119 | 120 | bool BaseEntity::isDormant() { 121 | return *(bool*)((DWORD)self() + m_isDormant); 122 | } 123 | 124 | int BaseEntity::getIndex() { 125 | return *(int*)((DWORD)self() + m_index); 126 | } 127 | 128 | Vector3 BaseEntity::getEyePosition() { 129 | Vector3 origin = getOrigin(); 130 | Vector3 offset = *(Vector3*)((DWORD)self() + m_vecViewOffset); 131 | 132 | return origin + offset; 133 | } 134 | 135 | void BaseEntity::getName(OUT std::string& name) { 136 | Engine* engine = (Engine*)m_loader->get(ENGINE); 137 | PlayerInfo playerInfo; 138 | engine->getPlayerInfo(getIndex(), &playerInfo); 139 | name = (char*) &playerInfo.name; 140 | } 141 | 142 | bool BaseEntity::getWeapon(OUT BaseCombatWeapon& weapon) { 143 | ClientEntList* clientEntList = (ClientEntList*)m_loader->get(CLIENTENTLIST); 144 | HANDLE weaponHandle = *(HANDLE*)((DWORD)self() + m_activeWeapon); 145 | if ((int)weaponHandle == -1) { 146 | return false; 147 | } 148 | 149 | BaseEntity entity = BaseEntity(m_loader); 150 | if (!clientEntList->getClientEntityFromHandle(weaponHandle, entity)) { 151 | return false; 152 | } 153 | 154 | weapon.setSelf(entity.self()); 155 | return true; 156 | } 157 | 158 | QAngle BaseEntity::getPunch() { 159 | return *(QAngle*)((DWORD)self() + m_aimPunchAngle); 160 | } -------------------------------------------------------------------------------- /csgo/BaseEntity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameInterface.h" 4 | #include "Loader.h" 5 | #include "Vector3.h" 6 | #include "Collideable.h" 7 | #include "EngineTrace.h" 8 | #include "mask.h" 9 | #include "QAngle.h" 10 | 11 | class BaseCombatWeapon; 12 | 13 | enum Team { 14 | TEAM_UNK1, 15 | TEAM_UNK2, 16 | TEAM_TERRORIST, 17 | TEAM_COUNTER_TERRORIST 18 | }; 19 | 20 | struct PlayerInfo { 21 | char __pad0[0x8]; 22 | int xuidlow; 23 | int xuidhigh; 24 | char name[128]; 25 | int userid; 26 | char guid[33]; 27 | char __pad1[0x17B]; 28 | }; 29 | 30 | class BaseEntity : public GameInterface { 31 | public: 32 | BaseEntity(Loader* loader) : BaseEntity(NULL, loader) {}; 33 | BaseEntity(PVOID pObject, Loader* loader); 34 | bool isEnemy(); 35 | bool isVisible(int bone); 36 | Vector3 getBonePosition(int bone); 37 | bool setupBones(Matrix3x4* pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime); 38 | 39 | int getTeamNum(); 40 | int getHealth(); 41 | int getAmorValue(); 42 | bool hasElmet(); 43 | Vector3 getOrigin(); 44 | Collideable* getCollideable(); 45 | bool isDormant(); 46 | Vector3 getEyePosition(); 47 | int getIndex(); 48 | void getName(OUT std::string& name); 49 | bool getWeapon(OUT BaseCombatWeapon& weapon); 50 | QAngle getPunch(); 51 | 52 | private: 53 | static bool m_offsetsInitialized; 54 | static int m_teamNum; 55 | static int m_health; 56 | static int m_armorValue; 57 | static int m_hashElmet; 58 | static int m_vecOrigin; 59 | static int m_collision; 60 | static int m_isDormant; 61 | static int m_vecViewOffset; 62 | static int m_index; 63 | static int m_activeWeapon; 64 | static int m_aimPunchAngle; 65 | }; -------------------------------------------------------------------------------- /csgo/Client.cpp: -------------------------------------------------------------------------------- 1 | #include "Client.h" 2 | 3 | #include 4 | #include 5 | 6 | int Client::netvarOffset(char* tableName, char* memberName) { 7 | ClientClass* clientClass = getAllClasses(); 8 | 9 | while (clientClass != NULL) { 10 | if (strcmp(clientClass->recvTable->netTableName, tableName) == 0) { 11 | return netvarOffset(clientClass->recvTable, memberName); 12 | } 13 | 14 | clientClass = clientClass->next; 15 | } 16 | 17 | return 0; 18 | } 19 | 20 | int Client::netvarOffset(RecvTable* recvTable, char* memberName) { 21 | RecvProp* prop; 22 | RecvTable* child; 23 | int extraOffset = 0; 24 | int tmpOffset; 25 | 26 | for (int i = 0; i < recvTable->size; i++) { 27 | prop = &recvTable->props[i]; 28 | child = prop->dataTable; 29 | 30 | if (child != NULL && child->size > 0) { 31 | tmpOffset = netvarOffset(child, memberName); 32 | if (tmpOffset != 0) { 33 | extraOffset += prop->offset + tmpOffset; 34 | } 35 | } 36 | 37 | if (strcmp(prop->varName, memberName) == 0) { 38 | return prop->offset + extraOffset; 39 | } 40 | } 41 | 42 | return extraOffset; 43 | } 44 | 45 | void Client::dumpNetvarOffset() { 46 | FILE* file = NULL; 47 | errno_t err = fopen_s(&file, "C:\\csgo\\dump.txt", "w+"); 48 | if (err != 0) { 49 | return; 50 | } 51 | 52 | ClientClass* clientClass = getAllClasses(); 53 | 54 | while (clientClass != NULL) { 55 | dumpNetvarOffset(clientClass->recvTable, file); 56 | clientClass = clientClass->next; 57 | } 58 | 59 | fclose(file); 60 | } 61 | 62 | int Client::dumpNetvarOffset(RecvTable* recvTable, FILE* file) { 63 | RecvProp* prop; 64 | RecvTable* child; 65 | int extraOffset = 0; 66 | int tmpOffset; 67 | 68 | for (int i = 0; i < recvTable->size; i++) { 69 | prop = &recvTable->props[i]; 70 | child = prop->dataTable; 71 | 72 | if (child != NULL && child->size > 0) { 73 | tmpOffset = dumpNetvarOffset(child, file); 74 | if (tmpOffset != 0) { 75 | extraOffset += prop->offset + tmpOffset; 76 | } 77 | } 78 | 79 | fprintf(file, "%s :: %s :: 0x%X\n", recvTable->netTableName, prop->varName, prop->offset + extraOffset); 80 | } 81 | 82 | return extraOffset; 83 | } 84 | 85 | ClientClass* Client::getAllClasses() { 86 | typedef ClientClass*(__thiscall *GetAllClassesFn)(PVOID pThis); 87 | GetAllClassesFn oGetAllClasses = (GetAllClassesFn)m_vtable->GetMethodAddress(VMT_GETALLCLASSES); 88 | return oGetAllClasses(self()); 89 | } 90 | 91 | PVOID Client::getClientMode() { 92 | DWORD addrHudProcessInput = m_vtable->GetMethodAddress(VMT_HUDPROCESSINPUT); 93 | if (addrHudProcessInput == NULL) { 94 | return NULL; 95 | } 96 | 97 | /* 98 | 0:050> u client+0x22e040: 99 | 1c0ce040 55 push ebp 100 | 1c0ce041 8bec mov ebp,esp 101 | 1c0ce043 8b0dc867d820 mov ecx,dword ptr [client!CreateInterface+0x4805a18 (20d867c8)] 102 | 1c0ce049 8b01 mov eax,dword ptr [ecx] 103 | 1c0ce04b 5d pop ebp 104 | 1c0ce04c ff6030 jmp dword ptr [eax+30h] 105 | 0:050> dd client+0x22e040 + 5 106 | 1c4ae045 211667c8 107 | */ 108 | PVOID* clientMode = *(PVOID**)(addrHudProcessInput + 5); // clientMode = client!CreateInterface+0x4805a18 109 | return *clientMode; 110 | } -------------------------------------------------------------------------------- /csgo/Client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "GameInterface.h" 5 | #include "vmtIndexes.h" 6 | 7 | struct RecvProp; 8 | struct RecvTable { 9 | RecvProp* props; 10 | int size; 11 | void* decoder; 12 | char* netTableName; 13 | bool initialized; 14 | bool inMainList; 15 | }; 16 | 17 | struct RecvProp { 18 | char* varName; 19 | int recvType; 20 | int flags; 21 | int stringBufferSize; 22 | bool insideArray; 23 | const void* extraData; 24 | RecvProp* arrayProp; 25 | void* arrayLengthProxy; 26 | void* proxyFn; 27 | void* dataTableProxyFn; 28 | RecvTable* dataTable; 29 | int offset; 30 | int elementStride; 31 | int nbElements; 32 | const char* parentArrayPropName; 33 | }; 34 | 35 | struct ClientClass { 36 | void* createFn; 37 | void* createEventFn; 38 | char* networkName; 39 | RecvTable* recvTable; 40 | ClientClass* next; 41 | int classID; 42 | }; 43 | 44 | 45 | class Client : public GameInterface { 46 | public: 47 | using GameInterface::GameInterface; 48 | 49 | int netvarOffset(char* tableName, char* memberName); 50 | void dumpNetvarOffset(); 51 | PVOID getClientMode(); 52 | 53 | private: 54 | ClientClass* getAllClasses(); 55 | int netvarOffset(RecvTable* recvTable, char* memberName); 56 | int dumpNetvarOffset(RecvTable* recvTable, FILE* file); 57 | }; -------------------------------------------------------------------------------- /csgo/ClientEntList.cpp: -------------------------------------------------------------------------------- 1 | #include "ClientEntList.h" 2 | 3 | bool ClientEntList::getClientEntity(int index, OUT BaseEntity& entity) { 4 | typedef void*(__thiscall *GetClientEntityFn)(PVOID pThis, int index); 5 | GetClientEntityFn oGetClientEntity = (GetClientEntityFn) m_vtable->GetMethodAddress(VMT_GETCLIENTENTITY); 6 | PVOID pEntity = oGetClientEntity(self(), index); 7 | if (pEntity == NULL) { 8 | return false; 9 | } 10 | 11 | entity.setSelf(pEntity); 12 | return true; 13 | } 14 | 15 | bool ClientEntList::getClientEntityFromHandle(HANDLE handle, OUT BaseEntity& entity) { 16 | typedef void*(__thiscall *GetClientEntityFromHandleFn)(PVOID pThis, HANDLE handle); 17 | GetClientEntityFromHandleFn oGetClientEntityFromHandle = (GetClientEntityFromHandleFn)m_vtable->GetMethodAddress(VMT_GETCLIENTENTITYFROMHANDLE); 18 | PVOID pEntity = oGetClientEntityFromHandle(self(), handle); 19 | if (pEntity == NULL) { 20 | return false; 21 | } 22 | 23 | entity.setSelf(pEntity); 24 | return true; 25 | } 26 | 27 | int ClientEntList::numberOfEntities(bool includeNonNetworkable) { 28 | typedef int(__thiscall *NumberOfEntitiesFn)(PVOID pThis, bool includeNonNetworkable); 29 | NumberOfEntitiesFn oNumberOfEntities = (NumberOfEntitiesFn)m_vtable->GetMethodAddress(VMT_NUMBEROFENTITIES); 30 | return oNumberOfEntities(self(), includeNonNetworkable); 31 | } 32 | 33 | int ClientEntList::getHighestEntityIndex() { 34 | typedef int(__thiscall *GetHighestEntityIndexFn)(PVOID pThis); 35 | GetHighestEntityIndexFn oGetHighestEntityIndex = (GetHighestEntityIndexFn)m_vtable->GetMethodAddress(VMT_GETHIGHESTENTITYINDEX); 36 | return oGetHighestEntityIndex(self()); 37 | } 38 | 39 | bool ClientEntList::getLocalPlayer(OUT BaseEntity& entity) { 40 | Engine* engine = (Engine*) m_loader->get(ENGINE); 41 | return getClientEntity(engine->getLocalPlayer(), entity); 42 | } -------------------------------------------------------------------------------- /csgo/ClientEntList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameInterface.h" 4 | #include "vmtIndexes.h" 5 | #include "Engine.h" 6 | #include "Loader.h" 7 | #include "BaseEntity.h" 8 | 9 | class ClientEntList : public GameInterface { 10 | public: 11 | using GameInterface::GameInterface; 12 | 13 | bool getClientEntity(int index, OUT BaseEntity& entity); 14 | bool getClientEntityFromHandle(HANDLE handle, OUT BaseEntity& entity); 15 | int numberOfEntities(bool includeNonNetworkable); 16 | int getHighestEntityIndex(); 17 | bool getLocalPlayer(OUT BaseEntity& entity); 18 | }; -------------------------------------------------------------------------------- /csgo/Collideable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector3.h" 4 | 5 | class Collideable { 6 | public: 7 | virtual void pad0() = 0; 8 | virtual const Vector3& OBBMins() const = 0; 9 | virtual const Vector3& OBBMaxs() const = 0; 10 | }; -------------------------------------------------------------------------------- /csgo/Engine.cpp: -------------------------------------------------------------------------------- 1 | #include "Engine.h" 2 | 3 | 4 | bool Engine::screenTransform(const Vector3& world, Vector2& screen) { 5 | float w; 6 | Vmatrix& worldToScreen = worldToScreenMatrix(); 7 | 8 | screen.x = worldToScreen[0][0] * world.x + worldToScreen[0][1] * world.y + worldToScreen[0][2] * world.z + worldToScreen[0][3]; 9 | screen.y = worldToScreen[1][0] * world.x + worldToScreen[1][1] * world.y + worldToScreen[1][2] * world.z + worldToScreen[1][3]; 10 | w = worldToScreen[3][0] * world.x + worldToScreen[3][1] * world.y + worldToScreen[3][2] * world.z + worldToScreen[3][3]; 11 | 12 | bool behind = false; 13 | 14 | if (w < 0.001f) { 15 | behind = true; 16 | screen.x *= 100000; 17 | screen.y *= 100000; 18 | } 19 | else { 20 | behind = false; 21 | float invw = 1.0f / w; 22 | screen.x *= invw; 23 | screen.y *= invw; 24 | } 25 | 26 | return behind; 27 | } 28 | 29 | bool Engine::worldToScreen(const Vector3& origin, Vector2& screen) { 30 | if (!screenTransform(origin, screen)) { 31 | int screenWidth = 0, screenHeight = 0; 32 | getScreenSize(screenWidth, screenHeight); 33 | 34 | float x = (float)screenWidth / 2.0f; 35 | float y = (float)screenHeight / 2.0f; 36 | x += 0.5f * screen.x * screenWidth + 0.5f; 37 | y -= 0.5f * screen.y * screenHeight + 0.5f; 38 | screen.x = x; 39 | screen.y = y; 40 | 41 | return true; 42 | } 43 | 44 | return false; 45 | } 46 | 47 | void Engine::getScreenSize(int& width, int& height) { 48 | typedef void(__thiscall *GetScreenSizeFn)(PVOID pThis, int& width, int& height); 49 | GetScreenSizeFn oGetScreenSize = (GetScreenSizeFn)m_vtable->GetMethodAddress(VMT_GETSCREENSIZE); 50 | oGetScreenSize(self(), width, height); 51 | } 52 | 53 | int Engine::getLocalPlayer() { 54 | typedef int(__thiscall *GetLocalPlayerFn)(PVOID pThis); 55 | GetLocalPlayerFn oGetLocalPlayer = (GetLocalPlayerFn)m_vtable->GetMethodAddress(VMT_GETLOCALPLAYER); 56 | return oGetLocalPlayer(self()); 57 | } 58 | 59 | struct Vmatrix& Engine::worldToScreenMatrix() { 60 | typedef struct Vmatrix&(__thiscall *WorldToScreenMatrixFn)(PVOID pThis); 61 | WorldToScreenMatrixFn oWorldToScreenMatrix = (WorldToScreenMatrixFn)m_vtable->GetMethodAddress(VMT_WORLDTOSCREENMATRIX); 62 | return oWorldToScreenMatrix(self()); 63 | } 64 | 65 | bool Engine::getPlayerInfo(int entNum, PlayerInfo* playerInfo) { 66 | typedef bool(__thiscall *GetPlayerInfoFn)(PVOID pThis, int entNum, PlayerInfo* playerInfo); 67 | GetPlayerInfoFn oGetPlayerInfo = (GetPlayerInfoFn)m_vtable->GetMethodAddress(VMT_GETPLAYERINFO); 68 | return oGetPlayerInfo(self(), entNum, playerInfo); 69 | } 70 | 71 | void Engine::setViewAngles(const QAngle& angle) { 72 | typedef void(__thiscall *SetViewAnglesFn)(PVOID pThis, const QAngle& angle); 73 | SetViewAnglesFn oSetViewAngles = (SetViewAnglesFn)m_vtable->GetMethodAddress(VMT_SETVIEWANGLES); 74 | return oSetViewAngles(self(), angle); 75 | } 76 | 77 | void Engine::clientCmd(const char* cmd) { 78 | typedef void(__thiscall *ClientCmd_UnrestrictedFn)(PVOID pThis, const char* cmd, bool unk0); 79 | ClientCmd_UnrestrictedFn oClientCmd_Unrestricted = (ClientCmd_UnrestrictedFn)m_vtable->GetMethodAddress(VMT_CLIENTCMDUNRESTRICTED); 80 | oClientCmd_Unrestricted(self(), cmd, false); 81 | } -------------------------------------------------------------------------------- /csgo/Engine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameInterface.h" 4 | #include "vmtIndexes.h" 5 | #include "Vmatrix.h" 6 | #include "Vector3.h" 7 | #include "Vector2.h" 8 | #include "QAngle.h" 9 | 10 | struct PlayerInfo; 11 | 12 | class Engine : public GameInterface { 13 | public: 14 | using GameInterface::GameInterface; 15 | 16 | bool screenTransform(const Vector3& worldPos, Vector2& screenPos); 17 | bool worldToScreen(const Vector3& origin, Vector2& screen); 18 | 19 | void getScreenSize(int& width, int& height); 20 | bool getPlayerInfo(int entNum, PlayerInfo* playerInfo); 21 | int getLocalPlayer(); 22 | struct Vmatrix& worldToScreenMatrix(); 23 | void setViewAngles(const QAngle& angle); 24 | void clientCmd(const char* cmd); 25 | }; -------------------------------------------------------------------------------- /csgo/EngineTrace.cpp: -------------------------------------------------------------------------------- 1 | #include "EngineTrace.h" 2 | 3 | void EngineTrace::TraceRay(const Ray& ray, unsigned int mask, TraceFilter* pTraceFilter, GameTrace* pTrace) { 4 | typedef void(__thiscall *TraceRayFn)(PVOID pThis, const Ray& ray, unsigned int mask, TraceFilter* pTraceFilter, GameTrace* pTrace); 5 | TraceRayFn oTraceRay = (TraceRayFn)m_vtable->GetMethodAddress(VMT_TRACERAY); 6 | oTraceRay(self(), ray, mask, pTraceFilter, pTrace); 7 | } -------------------------------------------------------------------------------- /csgo/EngineTrace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameInterface.h" 4 | #include "Vector4.h" 5 | #include "GameTrace.h" 6 | #include "vmtIndexes.h" 7 | 8 | 9 | struct Matrix3x4 { 10 | float m_matVal[3][4]; 11 | }; 12 | 13 | struct Ray { 14 | Ray() { } 15 | 16 | Vector4 m_start; 17 | Vector4 m_delta; 18 | Vector4 m_startOffset; 19 | Vector4 m_extents; 20 | const Matrix3x4* m_worldAxisTransform; 21 | bool m_isRay; 22 | bool m_isSwept; 23 | 24 | void init(Vector3 vecStart, Vector3 vecEnd) { 25 | m_delta = vecEnd - vecStart; 26 | m_isSwept = (m_delta.lengthSquare() != 0); 27 | m_extents.reset(); 28 | m_worldAxisTransform = NULL; 29 | m_isRay = true; 30 | m_startOffset.reset(); 31 | m_start = vecStart; 32 | } 33 | }; 34 | 35 | enum TraceType { 36 | TRACE_EVERYTHING, 37 | TRACE_WORLD_ONLY, 38 | TRACE_ENTITIES_ONLY, 39 | TRACE_EVERYTHING_FILTER_PROPS, 40 | }; 41 | 42 | class ITraceFilter { 43 | public: 44 | virtual bool ShouldHitEntity(BaseEntity* pEntityHandle, int contentsMask) = 0; 45 | virtual TraceType GetTraceType() = 0; 46 | }; 47 | class TraceFilter : ITraceFilter { 48 | public: 49 | virtual bool ShouldHitEntity(BaseEntity* pEntityHandle, int contentsMask) { 50 | return pEntityHandle != pSkip; 51 | } 52 | virtual TraceType GetTraceType() { 53 | return TRACE_EVERYTHING; 54 | } 55 | void* pSkip; 56 | }; 57 | 58 | 59 | class EngineTrace : public GameInterface { 60 | public: 61 | using GameInterface::GameInterface; 62 | 63 | void TraceRay(const Ray& ray, unsigned int mask, TraceFilter* pTraceFilter, GameTrace* pTrace); 64 | }; -------------------------------------------------------------------------------- /csgo/Esp.cpp: -------------------------------------------------------------------------------- 1 | #include "Esp.h" 2 | #include "Surface.h" 3 | #include "Engine.h" 4 | #include "boneId.h" 5 | #include "Menu.h" 6 | #include "BaseCombatWeapon.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | Esp::Esp(Loader* loader) { 13 | m_loader = loader; 14 | } 15 | 16 | void Esp::setEspColor(BaseEntity& entity) { 17 | Surface* surface = (Surface*)m_loader->get(SURFACE); 18 | 19 | // Allie 20 | if (!entity.isEnemy()) { 21 | surface->drawSetColor(0, 0, 255, 255); 22 | return; 23 | } 24 | 25 | // Last position 26 | if (entity.isDormant()) { 27 | int r = (int)(Menu::config.espLastPosition[0] * 255); 28 | int g = (int)(Menu::config.espLastPosition[1] * 255); 29 | int b = (int)(Menu::config.espLastPosition[2] * 255); 30 | surface->drawSetColor(r, g, b, 255); 31 | return; 32 | } 33 | 34 | // Enemy 35 | if (entity.isVisible(Terrorist::BoneId::head_0)) { 36 | surface->drawSetColor(0, 255, 0, 255); 37 | } 38 | else { 39 | surface->drawSetColor(255, 0, 0, 255); 40 | } 41 | } 42 | 43 | void Esp::drawSkeleton(BaseEntity& entity) { 44 | Surface* surface = (Surface*)m_loader->get(SURFACE); 45 | Engine* engine = (Engine*)m_loader->get(ENGINE); 46 | 47 | int terroristBoneIds[] = { 48 | Terrorist::BoneId::head_0, Terrorist::BoneId::pelvis, 49 | // Left arm 50 | Terrorist::BoneId::neck_0, Terrorist::BoneId::arm_upper_L, 51 | Terrorist::BoneId::arm_upper_L, Terrorist::BoneId::arm_lower_L, 52 | Terrorist::BoneId::arm_lower_L, Terrorist::BoneId::hand_L, 53 | // Right arm 54 | Terrorist::BoneId::neck_0, Terrorist::BoneId::arm_upper_R, 55 | Terrorist::BoneId::arm_upper_R, Terrorist::BoneId::arm_lower_R, 56 | Terrorist::BoneId::arm_lower_R, Terrorist::BoneId::hand_R, 57 | // Left leg 58 | Terrorist::BoneId::pelvis, Terrorist::BoneId::leg_upper_L, 59 | Terrorist::BoneId::leg_upper_L, Terrorist::BoneId::leg_lower_L, 60 | Terrorist::BoneId::leg_lower_L, Terrorist::BoneId::ankle_L, 61 | // Right leg 62 | Terrorist::BoneId::pelvis, Terrorist::BoneId::leg_upper_R, 63 | Terrorist::BoneId::leg_upper_R, Terrorist::BoneId::leg_lower_R, 64 | Terrorist::BoneId::leg_lower_R, Terrorist::BoneId::ankle_R 65 | }; 66 | 67 | int counterTerroristBoneIds[] = { 68 | CounterTerrorist::BoneId::head_0, CounterTerrorist::BoneId::pelvis, 69 | // Left arm 70 | CounterTerrorist::BoneId::neck_0, CounterTerrorist::BoneId::arm_upper_L, 71 | CounterTerrorist::BoneId::arm_upper_L, CounterTerrorist::BoneId::arm_lower_L, 72 | CounterTerrorist::BoneId::arm_lower_L, CounterTerrorist::BoneId::hand_L, 73 | // Right arm 74 | CounterTerrorist::BoneId::neck_0, CounterTerrorist::BoneId::arm_upper_R, 75 | CounterTerrorist::BoneId::arm_upper_R, CounterTerrorist::BoneId::arm_lower_R, 76 | CounterTerrorist::BoneId::arm_lower_R, CounterTerrorist::BoneId::hand_R, 77 | // Left leg 78 | CounterTerrorist::BoneId::pelvis, CounterTerrorist::BoneId::leg_upper_L, 79 | CounterTerrorist::BoneId::leg_upper_L, CounterTerrorist::BoneId::leg_lower_L, 80 | CounterTerrorist::BoneId::leg_lower_L, CounterTerrorist::BoneId::ankle_L, 81 | // Right leg 82 | CounterTerrorist::BoneId::pelvis, CounterTerrorist::BoneId::leg_upper_R, 83 | CounterTerrorist::BoneId::leg_upper_R, CounterTerrorist::BoneId::leg_lower_R, 84 | CounterTerrorist::BoneId::leg_lower_R, CounterTerrorist::BoneId::ankle_R 85 | }; 86 | 87 | 88 | int nbBones = sizeof(terroristBoneIds) / sizeof(terroristBoneIds[0]); 89 | int* boneIds = terroristBoneIds; 90 | if (entity.getTeamNum() == TEAM_COUNTER_TERRORIST) { 91 | boneIds = counterTerroristBoneIds; 92 | } 93 | 94 | if (entity.isDormant()) { 95 | return; 96 | } 97 | setEspColor(entity); 98 | 99 | Vector2 a, b; 100 | Vector3 v; 101 | bool status; 102 | 103 | for (int i = 0; i < nbBones; i += 2) { 104 | status = true; 105 | 106 | v = entity.getBonePosition(boneIds[i]); 107 | if (v.isNull()) { 108 | continue; 109 | } 110 | status &= engine->worldToScreen(v, a); 111 | 112 | v = entity.getBonePosition(boneIds[i+1]); 113 | if (v.isNull()) { 114 | continue; 115 | } 116 | status &= engine->worldToScreen(v, b); 117 | 118 | if (status) { 119 | surface->drawLine((int)a.x, (int)a.y, (int)b.x, (int)b.y); 120 | } 121 | } 122 | } 123 | 124 | 125 | void Esp::drawBox(BaseEntity& entity) { 126 | Surface* surface = (Surface*)m_loader->get(SURFACE); 127 | Engine* engine = (Engine*)m_loader->get(ENGINE); 128 | 129 | BaseCombatWeapon weapon = BaseCombatWeapon(NULL, m_loader, entity); 130 | if (!entity.getWeapon(weapon)) { 131 | return; 132 | } 133 | 134 | // Foots position 135 | Vector3 pos3D = entity.getOrigin(); 136 | Vector2 pos2D = Vector2(0.0f, 0.0f); 137 | if (!engine->worldToScreen(pos3D, pos2D)) { 138 | return; 139 | } 140 | 141 | // Head position 142 | Collideable* collideable = entity.getCollideable(); 143 | if (collideable == NULL) { 144 | return; 145 | } 146 | Vector3 max = collideable->OBBMaxs(); 147 | Vector3 top3D = Vector3(pos3D.x, pos3D.y, pos3D.z + max.z); 148 | Vector2 top2D = Vector2(0.0f, 0.0f); 149 | if (!engine->worldToScreen(top3D, top2D)) { 150 | return; 151 | } 152 | 153 | // ESP 154 | float height = pos2D.y - top2D.y; 155 | float width = height / 3.0f; 156 | 157 | if (entity.isDormant() && !Menu::config.espShowLastPosition) { 158 | return; 159 | } 160 | setEspColor(entity); 161 | 162 | int x0 = (int)(pos2D.x - width); 163 | int y0 = (int)top2D.y; 164 | int x1 = (int)(pos2D.x + width); 165 | int y1 = (int)pos2D.y; 166 | surface->drawOutlinedRect(x0, y0, x1, y1); 167 | surface->drawSetColor(0, 0, 0, 255); 168 | surface->drawOutlinedRect(x0 - 1, y0 - 1, x1 + 1, y1 + 1); 169 | surface->drawOutlinedRect(x0 + 1, y0 + 1, x1 - 1, y1 - 1); 170 | 171 | // Name 172 | std::string name; 173 | entity.getName(name); 174 | std::string weaponName = (char*) &weapon.getCSWpnData()->m_name; 175 | std::wstring_convert> converter; 176 | std::wstring wname = converter.from_bytes(name) + L" :: " + converter.from_bytes(weaponName); 177 | surface->drawSetTextPos(x0, y0 - 5); 178 | surface->drawPrintText(wname.c_str(), wname.size()); 179 | 180 | // Health bar 181 | float health = (float)entity.getHealth(); 182 | int heightBar = (int)(height * (health / 100.0f)); 183 | int widthBar = (int)(3 + height / 100.0f); 184 | surface->drawSetColor(0, 0, 0, 255); 185 | surface->drawFilledRect(x0 - widthBar - 1, y0, x0, y1); 186 | if (health > 60) { 187 | surface->drawSetColor(0, 255, 0, 255); 188 | } 189 | else if (health > 30) { 190 | surface->drawSetColor(255, 255, 0, 255); 191 | } 192 | else { 193 | surface->drawSetColor(255, 0, 0, 255); 194 | } 195 | 196 | surface->drawFilledRect(x0 - widthBar, y1 - heightBar, x0 - 1, y1); 197 | } -------------------------------------------------------------------------------- /csgo/Esp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseEntity.h" 4 | 5 | class Esp { 6 | public: 7 | Esp(Loader* loader); 8 | void drawSkeleton(BaseEntity& entity); 9 | void drawBox(BaseEntity& entity); 10 | 11 | private: 12 | void setEspColor(BaseEntity& entity); 13 | 14 | Loader* m_loader; 15 | }; -------------------------------------------------------------------------------- /csgo/GameInterface.cpp: -------------------------------------------------------------------------------- 1 | #include "GameInterface.h" 2 | 3 | GameInterface::GameInterface(PVOID pObject, Loader* loader) { 4 | m_this = pObject; 5 | m_vtable = new VTableHook((PDWORD*)m_this); 6 | m_loader = loader; 7 | } 8 | 9 | GameInterface::~GameInterface() { 10 | delete m_vtable; 11 | } 12 | 13 | PVOID GameInterface::self() { 14 | return m_this; 15 | } 16 | 17 | void GameInterface::setSelf(PVOID pObject) { 18 | m_this = pObject; 19 | delete m_vtable; 20 | m_vtable = new VTableHook((PDWORD*)m_this); 21 | } 22 | 23 | Loader* GameInterface::getLoader() { 24 | return m_loader; 25 | } -------------------------------------------------------------------------------- /csgo/GameInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "VTableHook.h" 5 | 6 | class Loader; 7 | 8 | class GameInterface { 9 | public: 10 | GameInterface(Loader* loader) : GameInterface(NULL, loader) {}; 11 | GameInterface(PVOID pObject, Loader* loader); 12 | ~GameInterface(); 13 | PVOID self(); 14 | void setSelf(PVOID pObject); 15 | Loader* getLoader(); 16 | 17 | protected: 18 | PVOID m_this; 19 | VTableHook* m_vtable; 20 | Loader* m_loader; 21 | }; 22 | -------------------------------------------------------------------------------- /csgo/GameTrace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector3.h" 4 | 5 | typedef unsigned char byte; 6 | 7 | struct Plane { 8 | Vector3 normal; 9 | float dist; 10 | byte type; 11 | byte signbits; 12 | byte pad[2]; 13 | }; 14 | 15 | class BaseTrace { 16 | public: 17 | Vector3 startpos; 18 | Vector3 endpos; 19 | Plane plane; 20 | float fraction; 21 | int contents; 22 | unsigned short dispFlags; 23 | bool allsolid; 24 | bool startsolid; 25 | }; 26 | 27 | struct Surface_t { 28 | const char* name; 29 | short surfaceProps; 30 | unsigned short flags; 31 | }; 32 | 33 | class BaseEntity; 34 | class GameTrace : public BaseTrace { 35 | public: 36 | float fractionleftsolid; 37 | Surface_t surface; 38 | int hitgroup; 39 | short physicsbone; 40 | unsigned short worldSurfaceIndex; 41 | BaseEntity* m_pEnt; 42 | int hitbox; 43 | }; -------------------------------------------------------------------------------- /csgo/Hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "Hooks.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "VTableHook.h" 10 | #include "Loader.h" 11 | #include "Vpnanel.h" 12 | #include "ClientEntList.h" 13 | #include "Surface.h" 14 | #include "Client.h" 15 | #include "boneId.h" 16 | #include "UserCmd.h" 17 | #include "BaseCombatWeapon.h" 18 | #include "InputSystem.h" 19 | #include "imgui\imgui.h" 20 | #include "imgui\imgui_impl_dx9.h" 21 | #include "Esp.h" 22 | #include "AimAssist.h" 23 | #include "Menu.h" 24 | #include "inButtons.h" 25 | #include "Math3.h" 26 | 27 | typedef void(__thiscall *PaintTraverseFn)(PVOID pThis, unsigned int vguiPanel, bool forceRepaint, bool allowForce); 28 | PaintTraverseFn oPaintTraverse; 29 | typedef bool(__thiscall *CreateMoveFn)(PVOID pThis, float inputSampleTime, UserCmd* cmd); 30 | CreateMoveFn oCreateMove; 31 | typedef long(__stdcall *EndSceneFn)(IDirect3DDevice9* device); 32 | EndSceneFn oEndScene; 33 | HFONT fontConsolas = NULL; 34 | int g_gamePanel = 0; 35 | Loader* g_loader; 36 | 37 | bool d3dIsInit = false; 38 | HWND valveWindow = NULL; 39 | WNDPROC oWndProc = NULL; 40 | 41 | QAngle Hooks::m_viewAngles = QAngle(0,0,0); 42 | 43 | void Hooks::setupHooks() { 44 | g_loader = new Loader(); 45 | Surface* surface = (Surface*)g_loader->get(SURFACE); 46 | Vpanel* vpanel = (Vpanel*)g_loader->get(VPANEL); 47 | Client* client = (Client*)g_loader->get(CLIENT); 48 | 49 | //client->dumpNetvarOffset(); 50 | 51 | // Load font 52 | fontConsolas = surface->createFont(); 53 | surface->setFontGlyphSet(fontConsolas, "Consolas", 12, FW_DONTCARE, NULL, NULL, FONTFLAG_OUTLINE, 0, 0); 54 | 55 | // Hook PaintTraverse 56 | VTableHook paintTraverseHook = VTableHook((DWORD**)vpanel->self()); 57 | oPaintTraverse = (PaintTraverseFn)paintTraverseHook.GetMethodAddress(VMT_PAINTTRAVERSE); 58 | paintTraverseHook.HookMethod((DWORD)PaintTraverse, VMT_PAINTTRAVERSE); 59 | 60 | // Hook CreateMove 61 | PVOID clientMode = client->getClientMode(); 62 | VTableHook createMoveHook = VTableHook((DWORD**)clientMode); 63 | oCreateMove = (CreateMoveFn)createMoveHook.GetMethodAddress(VMT_CREATEMOVE); 64 | createMoveHook.HookMethod((DWORD)CreateMove, VMT_CREATEMOVE); 65 | 66 | // Hook WndProc 67 | while (valveWindow == NULL) { 68 | valveWindow = FindWindow(L"Valve001", NULL); 69 | Sleep(10); 70 | } 71 | oWndProc = (WNDPROC)GetWindowLongPtr(valveWindow, GWL_WNDPROC); 72 | SetWindowLongPtr(valveWindow, GWL_WNDPROC, (LONG_PTR)WndProc); 73 | 74 | // Hook EndScene 75 | IDirect3DDevice9* d3d9Device = g_loader->getD3d9Device(); 76 | VTableHook endSceneHook = VTableHook((DWORD**)d3d9Device); 77 | oEndScene = (EndSceneFn)endSceneHook.GetMethodAddress(VMT_ENDSCENE); 78 | endSceneHook.HookMethod((DWORD)EndScene, VMT_ENDSCENE); 79 | 80 | // @todo: hook reset for ImGui 81 | 82 | while (true) { 83 | /* Infinite loop or it will destroy ours hooks */ 84 | Sleep(100); 85 | } 86 | } 87 | 88 | std::wstring ptrToStr(std::wstring name, PVOID ptr) { 89 | std::wstring msg = name + L": 0x"; 90 | std::wstringstream stream; 91 | stream << std::hex << ptr; 92 | msg += stream.str(); 93 | return msg; 94 | } 95 | 96 | void drawDebug(std::wstring msg, int line) { 97 | Surface* surface = (Surface*)g_loader->get(SURFACE); 98 | surface->drawSetTextFont(fontConsolas); 99 | surface->drawSetTextColor(255, 255, 255, 255); 100 | surface->drawSetTextPos(10, line * 10); 101 | surface->drawPrintText(msg.c_str(), msg.size()); 102 | } 103 | 104 | void drawDebug(std::string msg, int line) { 105 | using convert_type = std::codecvt_utf8; 106 | std::wstring_convert converter; 107 | std::wstring wmsg = converter.from_bytes(msg); 108 | drawDebug(wmsg, line); 109 | } 110 | 111 | void __stdcall Hooks::PaintTraverse(unsigned int vguiPanel, bool forceRepaint, bool allowForce) { 112 | Vpanel* vpanel = (Vpanel*)g_loader->get(VPANEL); 113 | ClientEntList* clientEntList = (ClientEntList*)g_loader->get(CLIENTENTLIST); 114 | Engine* engine = (Engine*)g_loader->get(ENGINE); 115 | Client* client = (Client*)g_loader->get(CLIENT); 116 | 117 | oPaintTraverse(vpanel->self(), vguiPanel, forceRepaint, allowForce); 118 | 119 | if (g_gamePanel == 0) { 120 | char* panelName = vpanel->getName(vguiPanel); 121 | if (panelName[0] != 'M' || panelName[2] != 't') { 122 | return; 123 | } 124 | 125 | g_gamePanel = vguiPanel; 126 | } 127 | if (vguiPanel != g_gamePanel) { 128 | return; 129 | } 130 | 131 | std::wstring msg = L"DEBUG"; 132 | drawDebug(msg, 0); 133 | 134 | BaseEntity localPlayer = BaseEntity(g_loader); 135 | if (!clientEntList->getLocalPlayer(localPlayer)) { 136 | return; 137 | } 138 | 139 | msg = L"Team " + std::to_wstring(localPlayer.getTeamNum()); 140 | drawDebug(msg, 1); 141 | msg = std::to_wstring(localPlayer.getHealth()) + L" HP"; 142 | drawDebug(msg, 2); 143 | msg = std::to_wstring(localPlayer.getAmorValue()) + L" Armor"; 144 | drawDebug(msg, 3); 145 | BaseCombatWeapon weapon = BaseCombatWeapon(NULL, g_loader, localPlayer); 146 | if (!localPlayer.getWeapon(weapon)) { 147 | return; 148 | } 149 | std::string smsg = std::string("weapon: ") + std::string((char*) &weapon.getCSWpnData()->m_name); 150 | drawDebug(smsg, 4); 151 | msg = L"weapon range: " + std::to_wstring(weapon.getCSWpnData()->m_flRange); 152 | drawDebug(msg, 5); 153 | msg = L"angle y: " + std::to_wstring(Hooks::m_viewAngles.y); 154 | drawDebug(msg, 6); 155 | 156 | int line = 0; 157 | BaseEntity entity = BaseEntity(g_loader); 158 | Esp esp = Esp(g_loader); 159 | 160 | for (int i = 0; i < clientEntList->getHighestEntityIndex(); i++) { 161 | if (!clientEntList->getClientEntity(i, entity)) { 162 | continue; 163 | } 164 | if (entity.getHealth() <= 0) { 165 | continue; 166 | } 167 | if (entity.self() == localPlayer.self()) { 168 | continue; 169 | } 170 | 171 | if (Menu::config.espAllies || entity.isEnemy()) { 172 | if (Menu::config.espBox) { 173 | esp.drawBox(entity); 174 | } 175 | if (Menu::config.espSkeleton) { 176 | esp.drawSkeleton(entity); 177 | } 178 | } 179 | } 180 | } 181 | 182 | bool __stdcall Hooks::CreateMove(float inputSampleTime, UserCmd* userCmd) { 183 | Client* client = (Client*)g_loader->get(CLIENT); 184 | ClientEntList* clientEntList = (ClientEntList*)g_loader->get(CLIENTENTLIST); 185 | Engine* engine = (Engine*)g_loader->get(ENGINE); 186 | EngineTrace* engineTrace = (EngineTrace*)g_loader->get(ENGINETRACE); 187 | 188 | oCreateMove(client->getClientMode(), inputSampleTime, userCmd); 189 | m_viewAngles = userCmd->viewangles; 190 | 191 | AimAssist aim = AimAssist(g_loader); 192 | if (aim.updateFireState(userCmd)) { 193 | if (Menu::config.aimbotIsActivated || GetKeyState(Menu::config.aimbotKey) & 0x8000) { 194 | aim.aimBot(userCmd); 195 | } 196 | else if (Menu::config.triggerbotIsActivated) { 197 | aim.triggerBot(userCmd); 198 | } 199 | } 200 | 201 | return false; 202 | } 203 | 204 | long __stdcall Hooks::EndScene(IDirect3DDevice9* device) { 205 | if (!d3dIsInit) { 206 | ImGui_ImplDX9_Init(valveWindow, device); 207 | d3dIsInit = true; 208 | } else { 209 | Menu::showMenu(g_loader); 210 | } 211 | 212 | return oEndScene(device); 213 | } 214 | 215 | LRESULT __stdcall Hooks::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 216 | if (uMsg == WM_KEYDOWN) { 217 | if (wParam == VK_INSERT) { 218 | Menu::tmpMenuIsOpen = !Menu::tmpMenuIsOpen; 219 | } 220 | if (Menu::waitForAimbotKey) { 221 | Menu::config.aimbotKey = wParam; 222 | Menu::waitForAimbotKey = false; 223 | } 224 | } 225 | 226 | if (d3dIsInit) { 227 | if (Menu::menuIsOpen() && ImGui_ImplDX9_WndProcHandler(hWnd, uMsg, wParam, lParam)) { 228 | return true; 229 | } 230 | } 231 | 232 | return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam); 233 | } -------------------------------------------------------------------------------- /csgo/Hooks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "UserCmd.h" 5 | 6 | 7 | class Hooks { 8 | public: 9 | static void setupHooks(); 10 | static void __stdcall PaintTraverse(unsigned int vguiPanel, bool forceRepaint, bool allowForce); 11 | static bool __stdcall CreateMove(float inputSampleTime, UserCmd* userCmd); 12 | static long __stdcall EndScene(IDirect3DDevice9* device); 13 | static LRESULT __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 14 | 15 | static QAngle m_viewAngles; 16 | }; -------------------------------------------------------------------------------- /csgo/InputSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "InputSystem.h" 2 | #include "vmtIndexes.h" 3 | 4 | void InputSystem::getCursorPosition(int* x, int* y) { 5 | typedef void(__thiscall *GetCursorPositionFn)(PVOID pThis, int* x, int* y); 6 | GetCursorPositionFn oGetCursorPosition = (GetCursorPositionFn)m_vtable->GetMethodAddress(VMT_GETCURSORPOSITION); 7 | oGetCursorPosition(self(), x, y); 8 | } -------------------------------------------------------------------------------- /csgo/InputSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameInterface.h" 4 | 5 | class InputSystem : public GameInterface { 6 | public: 7 | using GameInterface::GameInterface; 8 | void getCursorPosition(int* x, int* y); 9 | }; -------------------------------------------------------------------------------- /csgo/Loader.cpp: -------------------------------------------------------------------------------- 1 | #include "Loader.h" 2 | #include "Client.h" 3 | #include "ClientEntList.h" 4 | #include "Surface.h" 5 | #include "Vpnanel.h" 6 | #include "Engine.h" 7 | 8 | #include 9 | 10 | typedef PVOID(*CreateInterfaceFn)(const char* szName, int iReturn); 11 | IDirect3DDevice9* Loader::m_d3d9Device = NULL; 12 | 13 | Loader::Loader() { 14 | m_interfaces.resize(NB_INTERFACES); 15 | m_interfaces[CLIENT] = new Client(GetInterface(L"client.dll", "VClient018"), this); 16 | m_interfaces[CLIENTENTLIST] = new ClientEntList(GetInterface(L"client.dll", "VClientEntityList003"), this); 17 | m_interfaces[SURFACE] = new Surface(GetInterface(L"vguimatsurface.dll", "VGUI_Surface031"), this); 18 | m_interfaces[VPANEL] = new Vpanel(GetInterface(L"vgui2.dll", "VGUI_Panel009"), this); 19 | m_interfaces[ENGINE] = new Engine(GetInterface(L"engine.dll", "VEngineClient014"), this); 20 | m_interfaces[ENGINETRACE] = new Engine(GetInterface(L"engine.dll", "EngineTraceClient004"), this); 21 | m_interfaces[INPUTSYSTEM] = new Engine(GetInterface(L"inputsystem.dll", "InputSystemVersion001"), this); 22 | 23 | for (size_t i = 0; i < m_interfaces.size(); i++) { 24 | if (m_interfaces[i] == NULL) { 25 | OutputDebugString(L"One interface is NULL"); 26 | } 27 | } 28 | } 29 | 30 | Loader::~Loader() { 31 | for (size_t i = 0; i < m_interfaces.size(); i++) { 32 | delete m_interfaces[i]; 33 | } 34 | } 35 | 36 | GameInterface* Loader::get(InterfaceType type) { 37 | return m_interfaces.at(type); 38 | } 39 | 40 | PVOID Loader::GetInterface(wchar_t* moduleName, char* interfaceName) { 41 | HMODULE hModule = GetModuleHandle(moduleName); 42 | if (hModule == NULL) { 43 | OutputDebugString(L"Failed to found the following module: "); 44 | OutputDebugString(moduleName); 45 | return NULL; 46 | } 47 | 48 | CreateInterfaceFn CreateInterface = (CreateInterfaceFn)GetProcAddress(hModule, "CreateInterface"); 49 | if (CreateInterface == NULL) { 50 | OutputDebugString(L"Failed to load CreateInterface from module: "); 51 | OutputDebugString(moduleName); 52 | return NULL; 53 | } 54 | 55 | return CreateInterface(interfaceName, 0); 56 | } 57 | 58 | 59 | #define INRANGE(x,a,b) (x >= a && x <= b) 60 | #define getBits(x) (INRANGE((x&(~0x20)),'A','F') ? ((x&(~0x20)) - 'A' + 0xa) : (INRANGE(x,'0','9') ? x - '0' : 0)) 61 | #define getByte(x) (getBits(x[0]) << 4 | getBits(x[1])) 62 | DWORD Loader::findPattern(std::string module, std::string pattern) { 63 | HMODULE hModule = GetModuleHandleA(module.c_str()); 64 | if (hModule == NULL) { 65 | return 0; 66 | } 67 | 68 | MODULEINFO modInfo; 69 | BOOL success = GetModuleInformation(GetCurrentProcess(), hModule, &modInfo, sizeof(modInfo)); 70 | if (!success) { 71 | return 0; 72 | } 73 | 74 | char* data = (char*)hModule; 75 | unsigned int size = modInfo.SizeOfImage; 76 | unsigned int i = 0; 77 | unsigned int indexPattern; 78 | unsigned int numPattern; 79 | unsigned int patternFound; 80 | DWORD firstOccurence = 0; 81 | char byte; 82 | 83 | while (i < size - pattern.size()) { 84 | patternFound = false; 85 | indexPattern = 0; 86 | numPattern = 0; 87 | 88 | while (indexPattern < pattern.size()) { 89 | if (pattern[indexPattern] == ' ') { 90 | indexPattern++; 91 | continue; 92 | } 93 | if (pattern[indexPattern] == '?') { 94 | indexPattern++; 95 | i++; 96 | continue; 97 | } 98 | 99 | byte = getByte((&pattern[indexPattern])); 100 | 101 | if (data[i+numPattern] != byte) { 102 | break; 103 | } else { 104 | if (numPattern == 0) { 105 | firstOccurence = (DWORD) data + i; 106 | } 107 | } 108 | 109 | indexPattern += 2; 110 | numPattern++; 111 | 112 | if (indexPattern >= pattern.size()) { 113 | patternFound = true; 114 | break; 115 | } 116 | } 117 | 118 | if (patternFound) { 119 | return firstOccurence; 120 | } 121 | 122 | i++; 123 | } 124 | 125 | return 0; 126 | } 127 | 128 | IDirect3DDevice9* Loader::getD3d9Device() { 129 | if (m_d3d9Device == NULL) { 130 | /* 131 | 0:050> u shaderapidx9+0x2da0e: 132 | 0f47da0e a1608d4e0f mov eax,dword ptr [shaderapidx9!CreateInterface+0x5b370 (0f4e8d60)] 133 | 0f47da13 50 push eax 134 | 0f47da14 8b08 mov ecx,dword ptr [eax] 135 | 0f47da16 ff510c call dword ptr [ecx+0Ch] 136 | */ 137 | DWORD pattern = findPattern("shaderapidx9.dll", "A1 ? ? ? ? 50 8B 08 FF 51 0C"); 138 | PDWORD pD3d9Device = *(PDWORD*)(pattern + 1); 139 | m_d3d9Device = (IDirect3DDevice9*) *pD3d9Device; 140 | } 141 | 142 | return m_d3d9Device; 143 | } -------------------------------------------------------------------------------- /csgo/Loader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "GameInterface.h" 6 | #include 7 | 8 | enum InterfaceType { 9 | CLIENT, 10 | CLIENTENTLIST, 11 | SURFACE, 12 | VPANEL, 13 | ENGINE, 14 | ENGINETRACE, 15 | INPUTSYSTEM, 16 | NB_INTERFACES 17 | }; 18 | 19 | class Loader { 20 | public: 21 | Loader(); 22 | ~Loader(); 23 | GameInterface* get(InterfaceType type); 24 | DWORD findPattern(std::string module, std::string pattern); 25 | IDirect3DDevice9* getD3d9Device(); 26 | 27 | private: 28 | PVOID GetInterface(wchar_t* moduleName, char* interfaceName); 29 | std::vector m_interfaces; 30 | static IDirect3DDevice9* m_d3d9Device; 31 | }; -------------------------------------------------------------------------------- /csgo/Math3.cpp: -------------------------------------------------------------------------------- 1 | #include "Math3.h" 2 | #include 3 | 4 | void Math3::angleToForwardVector(const QAngle& angles, Vector3& forward) { 5 | float xRad = DEG2RAD(angles.x); 6 | float yRad = DEG2RAD(angles.y); 7 | float cosX = (float)cos(xRad); 8 | float sinX = (float)sin(xRad); 9 | float cosY = (float)cos(yRad); 10 | float sinY = (float)sin(yRad); 11 | forward.x = cosX * cosY; 12 | forward.y = cosX * sinY; 13 | forward.z = -sinX; 14 | } 15 | 16 | QAngle Math3::angleBtwVectors(Vector3 src, Vector3 dst) { 17 | QAngle angle; 18 | Vector3 delta = src - dst; 19 | angle.x = asinf(delta.z / delta.length()) * M_RADPI; 20 | angle.y = atanf(delta.y / delta.x) * M_RADPI; 21 | angle.z = 0.0f; 22 | if (delta.x >= 0) { 23 | angle.y += 180; 24 | } 25 | 26 | return angle; 27 | } 28 | -------------------------------------------------------------------------------- /csgo/Math3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector3.h" 4 | #include "QAngle.h" 5 | 6 | #define M_PI 3.14159265358979323846f 7 | #define M_RADPI 57.295779513082f 8 | #define RAD2DEG(x) ( (float)(x) * (float)(180.f / M_PI) ) 9 | #define DEG2RAD(x) ( (float)(x) * (float)(M_PI / 180.f) ) 10 | 11 | 12 | class Math3 { 13 | public: 14 | static void angleToForwardVector(const QAngle& angles, Vector3& forward); 15 | static QAngle angleBtwVectors(Vector3 src, Vector3 dst); 16 | }; -------------------------------------------------------------------------------- /csgo/Menu.cpp: -------------------------------------------------------------------------------- 1 | #include "Menu.h" 2 | #include "Engine.h" 3 | #include "InputSystem.h" 4 | #include "boneId.h" 5 | #include "imgui\imgui.h" 6 | #include "imgui\imgui_impl_dx9.h" 7 | #include "imgui\imgui_color_picker.h" 8 | #include 9 | 10 | // Radar headers 11 | #include "BaseEntity.h" 12 | #include "ClientEntList.h" 13 | #include "Hooks.h" 14 | #include "Math3.h" 15 | 16 | bool Menu::tmpMenuIsOpen = false; 17 | int Menu::menuId = false; 18 | bool Menu::m_menuIsOpen = false; 19 | Config Menu::config = {0}; 20 | bool Menu::m_radarIsActive = true; 21 | bool Menu::waitForAimbotKey = false; 22 | 23 | 24 | bool Menu::save() { 25 | // In the futur, the settings will be saves in the server 26 | // For the moment, we save it in C:\csgo\config.dat 27 | 28 | FILE* file = NULL; 29 | errno_t err = fopen_s(&file, "C:\\csgo\\config.dat", "wb+"); 30 | if (err != 0) { 31 | return false; 32 | } 33 | 34 | fwrite(&config, sizeof(config), 1, file); 35 | fclose(file); 36 | return true; 37 | } 38 | 39 | bool Menu::load() { 40 | FILE* file = NULL; 41 | errno_t err = fopen_s(&file, "C:\\csgo\\config.dat", "rb"); 42 | if (err != 0) { 43 | return false; 44 | } 45 | 46 | fread(&config, sizeof(config), 1, file); 47 | fclose(file); 48 | return true; 49 | } 50 | 51 | void Menu::updateMenuState(Loader* loader) { 52 | Engine* engine = (Engine*) loader->get(ENGINE); 53 | 54 | if (tmpMenuIsOpen != m_menuIsOpen) { 55 | m_menuIsOpen = tmpMenuIsOpen; 56 | std::string msg = "cl_mouseenable " + std::to_string(!m_menuIsOpen); 57 | engine->clientCmd(msg.c_str()); 58 | } 59 | } 60 | 61 | bool Menu::menuIsOpen() { 62 | return m_menuIsOpen; 63 | } 64 | 65 | float colors[] = { 0, 0, 0 }; 66 | void Menu::showMenu(Loader* loader) { 67 | updateMenuState(loader); 68 | 69 | ImGui_ImplDX9_NewFrame(); 70 | 71 | if (menuIsOpen()) { 72 | InputSystem* inputSystem = (InputSystem*)loader->get(INPUTSYSTEM); 73 | 74 | int x, y; 75 | inputSystem->getCursorPosition(&x, &y); 76 | ImGuiIO& io = ImGui::GetIO(); 77 | io.MousePos.x = (float)x; 78 | io.MousePos.y = (float)y; 79 | 80 | ImGui::Begin("Menu", &tmpMenuIsOpen, ImVec2(620, 300), 0.9f, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); 81 | ImGui::Columns(2); 82 | ImGui::SetColumnOffset(1, 115.f); 83 | 84 | if (ImGui::Button("Visual", ImVec2(100.f, 20.f))) menuId = MENU_VISUAL; 85 | if (ImGui::Button("AimBot##settings", ImVec2(100.f, 20.f))) menuId = MENU_AIMBOT; 86 | if (ImGui::Button("TriggerBot##settings", ImVec2(100.f, 20.f))) menuId = MENU_TRIGGERBOT; 87 | if (ImGui::Button("Load", ImVec2(100.f, 20.f))) load(); 88 | if (ImGui::Button("Save", ImVec2(100.f, 20.f))) save(); 89 | ImGui::NextColumn(); 90 | 91 | char* bones[] = { 92 | "Pelvis", 93 | "Spine 0", 94 | "Spine 1", 95 | "Spine 2", 96 | "Spine 3", 97 | "Neck", 98 | "Head" 99 | }; 100 | int nbBones = 7; 101 | 102 | std::string aimKeyText; 103 | if (waitForAimbotKey) { 104 | aimKeyText = "<>"; 105 | } else { 106 | aimKeyText = std::string("AimBot Key: ") + std::string(1, (char)config.aimbotKey).c_str(); 107 | } 108 | 109 | switch (menuId) { 110 | case MENU_VISUAL: 111 | ImGui::Checkbox("ESP Box", &config.espBox); 112 | ImGui::Checkbox("ESP Skeleton", &config.espSkeleton); 113 | ImGui::Checkbox("Allies ESP", &config.espAllies); 114 | ImGui::Checkbox("Show last position", &config.espShowLastPosition); 115 | ImGui::ColorEdit3("Last position", config.espLastPosition); 116 | ImGui::Checkbox("Show Radar", &m_radarIsActive); 117 | break; 118 | case MENU_AIMBOT: 119 | ImGui::Checkbox("AimBot always activated", &config.aimbotIsActivated); 120 | if (ImGui::Button(aimKeyText.c_str(), ImVec2(200.f, 20.f))) waitForAimbotKey = true; 121 | ImGui::Checkbox("Auto Fire", &config.aimbotAutoFire); 122 | ImGui::Checkbox("Auto Zoom", &config.aimbotAutoZoom); 123 | ImGui::Checkbox("Smooth Aim", &config.smoothAimbot); 124 | ImGui::SliderFloat("Smooth speed", &config.aimbotSmoothSpeed, 0.f, 1.f); 125 | ImGui::SliderInt("Time between shots (ms)", &config.aimbotWaitingTime, 0, 2000); 126 | ImGui::Combo("Target", &config.aimbotBoneId, (const char**)bones, nbBones, -1); 127 | ImGui::Checkbox("Silent Aim", &config.silentAim); 128 | break; 129 | case MENU_TRIGGERBOT: 130 | ImGui::Checkbox("TriggerBot", &config.triggerbotIsActivated); 131 | ImGui::SliderInt("Time between shots (ms)", &config.triggerbotWaitingTime, 0, 2000); 132 | break; 133 | } 134 | 135 | ImGui::Columns(1); 136 | ImGui::End(); 137 | } 138 | 139 | if (m_radarIsActive) { 140 | showRadarHack(loader); 141 | } 142 | 143 | ImGui::Render(); 144 | ImGui::GetIO().MouseDrawCursor = menuIsOpen(); 145 | } 146 | 147 | void rotateVector(float& x, float& y, float angle, float originX = 0, float originY = 0) { 148 | x -= originX; 149 | y -= originY; 150 | float tx = x, ty = y; 151 | float fCos = cos(angle); 152 | float fSin = sin(angle); 153 | 154 | tx = x*fCos - y*fSin; 155 | ty = x*fSin + y*fCos; 156 | 157 | x = tx + originX; 158 | y = ty + originY; 159 | } 160 | 161 | #define MAKE_IMU32(r, g, b, a) ((a << 24) + (b << 16) + (g << 8) + r) 162 | void Menu::showRadarHack(Loader* loader) { 163 | ImGui::Begin("Radar", &m_radarIsActive, ImVec2(200, 200), 0.9f, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); 164 | 165 | // Background 166 | ImVec2 bgPos = ImGui::GetCursorScreenPos(); 167 | ImVec2 bgSize = ImGui::GetContentRegionAvail(); 168 | ImGui::GetWindowDrawList()->AddRectFilled(bgPos, ImVec2(bgPos.x + bgSize.x, bgPos.y + bgSize.y), 0xFF333333); 169 | 170 | // Check if we are in game 171 | ClientEntList* clientEntList = (ClientEntList*)loader->get(CLIENTENTLIST); 172 | BaseEntity localPlayer = BaseEntity(loader); 173 | if (!clientEntList->getLocalPlayer(localPlayer)) { 174 | ImGui::End(); 175 | return; 176 | } 177 | 178 | // Radar 179 | BaseEntity entity = BaseEntity(loader); 180 | Vector3 pos; 181 | float x, y; 182 | ImVec2 midRadar = ImVec2(bgPos.x + (bgSize.x / 2), bgPos.y + (bgSize.y / 2)); 183 | float mapSizeX = -5000; 184 | float mapSizeY = 5000; 185 | ImGui::GetWindowDrawList()->AddLine(ImVec2(midRadar.x-bgSize.x/2.f, midRadar.y), ImVec2(midRadar.x+ bgSize.x / 2.f, midRadar.y), MAKE_IMU32(0, 0, 0, 64)); 186 | ImGui::GetWindowDrawList()->AddLine(ImVec2(midRadar.x, midRadar.y - bgSize.y / 2.f), ImVec2(midRadar.x, midRadar.y + bgSize.y / 2.f), MAKE_IMU32(0, 0, 0, 64)); 187 | // @todo: Use the farthest for the map size 188 | 189 | // Show local player position 190 | pos = localPlayer.getOrigin(); 191 | x = midRadar.x; 192 | y = midRadar.y; 193 | ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(x - 2, y - 2), ImVec2(x + 2, y + 2), 0xFFFFFFFF); 194 | 195 | // Show local camera 196 | bool radarViewFixed = true; 197 | ImVec2 camPos; 198 | Vector3 forward; 199 | Math3::angleToForwardVector(Hooks::m_viewAngles, forward); 200 | forward = forward * 1000; 201 | 202 | if (radarViewFixed) { 203 | camPos = ImVec2(midRadar.x, 0); 204 | } else { 205 | camPos = ImVec2(x - forward.x, y + forward.y); 206 | } 207 | 208 | float fov = DEG2RAD(90.f); // @todo: get fov 209 | rotateVector(camPos.x, camPos.y, fov/2.f, x, y); 210 | ImGui::GetWindowDrawList()->AddLine(ImVec2(x, y), camPos, MAKE_IMU32(199, 202, 74, 255)); 211 | rotateVector(camPos.x, camPos.y, -fov, x, y); 212 | ImGui::GetWindowDrawList()->AddLine(ImVec2(x, y), camPos, MAKE_IMU32(199, 202, 74, 255)); 213 | 214 | // Players positions 215 | ImU32 color = MAKE_IMU32(0, 0, 255, 255); 216 | int r, g, b; 217 | for (int i = 0; i < clientEntList->getHighestEntityIndex(); i++) { 218 | if (!clientEntList->getClientEntity(i, entity)) { 219 | continue; 220 | } 221 | if (entity.getHealth() <= 0) { 222 | continue; 223 | } 224 | if (entity.self() == localPlayer.self()) { 225 | continue; 226 | } 227 | 228 | if (Menu::config.espAllies || entity.isEnemy()) { 229 | if (entity.isDormant() && !Menu::config.espShowLastPosition) { 230 | continue; 231 | } 232 | 233 | // Color 234 | if (entity.isEnemy()) { 235 | if (entity.isDormant()) { 236 | r = (int)(Menu::config.espLastPosition[0] * 255); 237 | g = (int)(Menu::config.espLastPosition[1] * 255); 238 | b = (int)(Menu::config.espLastPosition[2] * 255); 239 | color = MAKE_IMU32(r, g, b, 255); 240 | } 241 | else if (entity.isVisible(Terrorist::BoneId::head_0)) { 242 | color = MAKE_IMU32(0, 255, 0, 255); 243 | } else { 244 | color = MAKE_IMU32(255, 0, 0, 255); 245 | } 246 | } else { 247 | color = MAKE_IMU32(0, 0, 255, 255); 248 | } 249 | 250 | // Show 251 | pos = entity.getOrigin(); 252 | pos = pos - localPlayer.getOrigin(); 253 | 254 | x = midRadar.x + (pos.x / mapSizeX) * bgSize.x; 255 | y = midRadar.y + (pos.y / mapSizeY) * bgSize.y; 256 | 257 | if (radarViewFixed) { 258 | rotateVector(x, y, DEG2RAD((Hooks::m_viewAngles.y + 90)), midRadar.x, midRadar.y); 259 | } 260 | 261 | ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(x-2,y-2), ImVec2(x+2, y+2), color); 262 | } 263 | } 264 | 265 | ImGui::End(); 266 | } -------------------------------------------------------------------------------- /csgo/Menu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Loader.h" 4 | 5 | enum { 6 | MENU_VISUAL, 7 | MENU_AIMBOT, 8 | MENU_TRIGGERBOT 9 | }; 10 | 11 | struct Config { 12 | // Visual 13 | bool espBox; 14 | bool espSkeleton; 15 | bool espAllies; 16 | bool espShowLastPosition; 17 | float espLastPosition[3]; 18 | 19 | // Aimbot 20 | bool aimbotIsActivated; 21 | DWORD aimbotKey; 22 | bool aimbotAutoFire; 23 | bool silentAim; 24 | int aimbotWaitingTime; 25 | int aimbotBoneId; 26 | bool aimbotAutoZoom; 27 | bool smoothAimbot; 28 | float aimbotSmoothSpeed; 29 | 30 | // Triggerbot 31 | bool triggerbotIsActivated; 32 | int triggerbotWaitingTime; 33 | }; 34 | 35 | class Menu { 36 | public: 37 | static bool save(); 38 | static bool load(); 39 | static void updateMenuState(Loader* loader); 40 | static bool menuIsOpen(); 41 | static void showMenu(Loader* loader); 42 | static void showRadarHack(Loader* loader); 43 | 44 | static bool tmpMenuIsOpen; 45 | static int menuId; 46 | static Config config; 47 | static bool waitForAimbotKey; 48 | 49 | private: 50 | static bool m_menuIsOpen; 51 | static bool m_radarIsActive; 52 | }; -------------------------------------------------------------------------------- /csgo/QAngle.cpp: -------------------------------------------------------------------------------- 1 | #include "QAngle.h" 2 | #include 3 | 4 | QAngle::QAngle() { 5 | x = 0; 6 | y = 0; 7 | z = 0; 8 | } 9 | 10 | QAngle::QAngle(float x, float y, float z) { 11 | this->x = x; 12 | this->y = y; 13 | this->z = z; 14 | } 15 | 16 | float QAngle::lengthSquare() { 17 | return (x*x + y*y + z*z); 18 | } 19 | 20 | float QAngle::length() { 21 | return (float)sqrt(lengthSquare()); 22 | } 23 | 24 | bool QAngle::isNull() { 25 | return (x < 1 && y < 1 && z < 1); 26 | } 27 | 28 | void QAngle::clamp() { 29 | if (x < -89.0f) { 30 | x = -89.0f; 31 | } 32 | 33 | if (x > 89.0f) { 34 | x = 89.0f; 35 | } 36 | 37 | while (y < -180.0f) { 38 | y += 360.0f; 39 | } 40 | while (y > 180.0f) { 41 | y -= 360.0f; 42 | } 43 | 44 | z = 0.0f; 45 | } 46 | 47 | QAngle QAngle::operator+(QAngle v) { 48 | QAngle r; 49 | r.x = x + v.x; 50 | r.y = y + v.y; 51 | r.z = z + v.z; 52 | return r; 53 | } 54 | 55 | QAngle QAngle::operator-(QAngle v) { 56 | QAngle r; 57 | r.x = x - v.x; 58 | r.y = y - v.y; 59 | r.z = z - v.z; 60 | return r; 61 | } 62 | 63 | QAngle QAngle::operator*(float f) { 64 | QAngle r; 65 | r.x = x * f; 66 | r.y = y * f; 67 | r.z = z * f; 68 | return r; 69 | } -------------------------------------------------------------------------------- /csgo/QAngle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class QAngle { 4 | public: 5 | float x, y, z; 6 | QAngle(); 7 | QAngle(float x, float y, float z); 8 | float lengthSquare(); 9 | float length(); 10 | bool isNull(); 11 | void clamp(); 12 | QAngle operator+(QAngle v); 13 | QAngle operator-(QAngle v); 14 | QAngle operator*(float f); 15 | }; -------------------------------------------------------------------------------- /csgo/Surface.cpp: -------------------------------------------------------------------------------- 1 | #include "Surface.h" 2 | 3 | void Surface::drawSetColor(int r, int g, int b, int a) { 4 | typedef void(__thiscall *DrawSetColorFn)(PVOID pThis, int, int, int, int); 5 | DrawSetColorFn oDrawSetColor = (DrawSetColorFn) m_vtable->GetMethodAddress(VMT_DRAWSETCOLOR); 6 | oDrawSetColor(self(), r, g, b, a); 7 | } 8 | 9 | void Surface::drawFilledRect(int x0, int y0, int x1, int y1) { 10 | typedef void(__thiscall *DrawFilledRectFn)(PVOID pThis, int, int, int, int); 11 | DrawFilledRectFn oDrawFilledRect = (DrawFilledRectFn)m_vtable->GetMethodAddress(VMT_DRAWFILLEDRECT); 12 | oDrawFilledRect(self(), x0, y0, x1, y1); 13 | } 14 | 15 | void Surface::drawOutlinedRect(int x0, int y0, int x1, int y1) { 16 | typedef void(__thiscall *DrawOutlinedRectFn)(PVOID pThis, int, int, int, int); 17 | DrawOutlinedRectFn oDrawOutlinedRect = (DrawOutlinedRectFn)m_vtable->GetMethodAddress(VMT_DRAWOUTLINEDRECT); 18 | oDrawOutlinedRect(self(), x0, y0, x1, y1); 19 | } 20 | 21 | void Surface::drawLine(int x0, int y0, int x1, int y1) { 22 | typedef void(__thiscall *DrawLineFn)(PVOID pThis, int, int, int, int); 23 | DrawLineFn oDrawLine = (DrawLineFn)m_vtable->GetMethodAddress(VMT_DRAWLINE); 24 | oDrawLine(self(), x0, y0, x1, y1); 25 | } 26 | 27 | void Surface::drawSetTextFont(PVOID font) { 28 | typedef void(__thiscall *DrawSetTextFontFn)(PVOID pThis, PVOID font); 29 | DrawSetTextFontFn oDrawSetTextFont = (DrawSetTextFontFn)m_vtable->GetMethodAddress(VMT_DRAWSETTEXTFONT); 30 | oDrawSetTextFont(self(), font); 31 | } 32 | 33 | void Surface::drawSetTextColor(int r, int g, int b, int a) { 34 | typedef void(__thiscall *DrawSetTextColorFn)(PVOID pThis, int r, int g, int b, int a); 35 | DrawSetTextColorFn oDrawSetTextColor = (DrawSetTextColorFn)m_vtable->GetMethodAddress(VMT_DRAWSETTEXTCOLOR); 36 | oDrawSetTextColor(self(), r, g, b, a); 37 | } 38 | 39 | void Surface::drawSetTextPos(int x, int y) { 40 | typedef void(__thiscall *DrawSetTextPosFn)(PVOID pThis, int x, int y); 41 | DrawSetTextPosFn oDrawSetTextPos = (DrawSetTextPosFn)m_vtable->GetMethodAddress(VMT_DRAWSETTEXTPOS); 42 | oDrawSetTextPos(self(), x, y); 43 | } 44 | 45 | void Surface::drawPrintText(const wchar_t* str, int strlen) { 46 | typedef void(__thiscall *DrawPrintTextFn)(PVOID pThis, const wchar_t* str, int strlen, int drawType); 47 | DrawPrintTextFn oDrawPrintText = (DrawPrintTextFn)m_vtable->GetMethodAddress(VMT_DRAWPRINTTEXT); 48 | oDrawPrintText(self(), str, strlen, 0); 49 | } 50 | 51 | HFONT Surface::createFont() { 52 | typedef HFONT(__thiscall *CreateFontFn)(PVOID pThis); 53 | CreateFontFn oCreateFont = (CreateFontFn)m_vtable->GetMethodAddress(VMT_CREATEFONT); 54 | return oCreateFont(self()); 55 | } 56 | 57 | bool Surface::setFontGlyphSet(HFONT font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin, int nRangeMax) { 58 | typedef bool(__thiscall *SetFontGlyphSetFn)(PVOID pThis, HFONT, const char*, int, int, int, int, int, int, int); 59 | SetFontGlyphSetFn oSetFontGlyphSet = (SetFontGlyphSetFn)m_vtable->GetMethodAddress(VMT_SETFONTGLYPHSET); 60 | return oSetFontGlyphSet(self(), font, windowsFontName, tall, weight, blur, scanlines, flags, nRangeMin, nRangeMax); 61 | } 62 | -------------------------------------------------------------------------------- /csgo/Surface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameInterface.h" 4 | #include "vmtIndexes.h" 5 | 6 | enum FontFlag { 7 | FONTFLAG_NONE, 8 | FONTFLAG_ITALIC = 0x001, 9 | FONTFLAG_UNDERLINE = 0x002, 10 | FONTFLAG_STRIKEOUT = 0x004, 11 | FONTFLAG_SYMBOL = 0x008, 12 | FONTFLAG_ANTIALIAS = 0x010, 13 | FONTFLAG_GAUSSIANBLUR = 0x020, 14 | FONTFLAG_ROTARY = 0x040, 15 | FONTFLAG_DROPSHADOW = 0x080, 16 | FONTFLAG_ADDITIVE = 0x100, 17 | FONTFLAG_OUTLINE = 0x200, 18 | FONTFLAG_CUSTOM = 0x400, 19 | FONTFLAG_BITMAP = 0x800, 20 | }; 21 | 22 | class Surface : public GameInterface { 23 | public: 24 | using GameInterface::GameInterface; 25 | 26 | void drawSetColor(int r, int g, int b, int a); 27 | void drawFilledRect(int x0, int y0, int x1, int y1); 28 | void drawOutlinedRect(int x0, int y0, int x1, int y1); 29 | void drawLine(int x0, int y0, int x1, int y1); 30 | void drawSetTextFont(PVOID font); 31 | void drawSetTextColor(int r, int g, int b, int a); 32 | void drawSetTextPos(int x, int y); 33 | void drawPrintText(const wchar_t* str, int strlen); 34 | HFONT createFont(); 35 | bool setFontGlyphSet(HFONT font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin = 0, int nRangeMax = 0); 36 | }; -------------------------------------------------------------------------------- /csgo/Timer.cpp: -------------------------------------------------------------------------------- 1 | #include "Timer.h" 2 | #include 3 | 4 | Timer::Timer() { 5 | m_started = 0; 6 | m_waitingTime = 0; 7 | } 8 | 9 | void Timer::start(unsigned int ms) { 10 | m_waitingTime = ms; 11 | m_started = GetTickCount(); 12 | } 13 | 14 | bool Timer::isElapsed() { 15 | unsigned int elapsedTime = GetTickCount() - m_started; 16 | return (elapsedTime >= m_waitingTime); 17 | } -------------------------------------------------------------------------------- /csgo/Timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Timer { 4 | public: 5 | Timer(); 6 | void start(unsigned int ms); 7 | bool isElapsed(); 8 | 9 | private: 10 | unsigned int m_started; 11 | unsigned int m_waitingTime; 12 | }; -------------------------------------------------------------------------------- /csgo/UserCmd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "QAngle.h" 4 | #include "Vector3.h" 5 | 6 | typedef unsigned char byte; 7 | 8 | class UserCmd { 9 | public: 10 | virtual ~UserCmd() { }; 11 | int command_number; 12 | int tick_count; 13 | QAngle viewangles; 14 | Vector3 aimdirection; 15 | float forwardmove; 16 | float sidemove; 17 | float upmove; 18 | int buttons; 19 | byte impulse; 20 | int weaponselect; 21 | int weaponsubtype; 22 | int random_seed; 23 | short mousedx; 24 | short mousedy; 25 | bool hasbeenpredicted; 26 | char pad_0x4C[0x18]; 27 | }; -------------------------------------------------------------------------------- /csgo/VTableHook.cpp: -------------------------------------------------------------------------------- 1 | #include "VTableHook.h" 2 | 3 | VTableHook::VTableHook(PDWORD* pClassBase) { 4 | m_pClassBase = pClassBase; 5 | m_pVTable = NULL; 6 | m_pOriginalVTable = NULL; 7 | } 8 | 9 | VTableHook::~VTableHook() { 10 | if (m_pVTable != NULL) { 11 | VirtualFree(m_pVTable, 0, MEM_RELEASE); 12 | } 13 | } 14 | 15 | DWORD VTableHook::GetMethodAddress(unsigned int index) { 16 | if (m_pOriginalVTable == NULL) { 17 | m_pOriginalVTable = *m_pClassBase; 18 | } 19 | 20 | return m_pOriginalVTable[index]; 21 | } 22 | 23 | unsigned int VTableHook::getVTableSize() { 24 | unsigned int size = 0; 25 | DWORD vtable = *(PDWORD)m_pClassBase; 26 | 27 | DWORD function; 28 | while (true) { 29 | function = *(PDWORD)(vtable + sizeof(DWORD)*size); 30 | if (function <= 0x1000) { 31 | break; 32 | } 33 | size++; 34 | } 35 | 36 | return size; 37 | } 38 | 39 | void VTableHook::hookVTable() { 40 | DWORD dwOldProtect, dwOldProtect2; 41 | 42 | if (m_pVTable == NULL) { 43 | m_pOriginalVTable = *m_pClassBase; 44 | unsigned int vtableSize = getVTableSize(); 45 | 46 | // Copy the actual vtable 47 | m_pVTable = (PDWORD) VirtualAlloc(NULL, sizeof(DWORD)*vtableSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); 48 | memcpy(m_pVTable, m_pOriginalVTable, sizeof(DWORD)*vtableSize); 49 | 50 | // Assign the same protection that the real vtable (hello VAC) 51 | MEMORY_BASIC_INFORMATION memInfo; 52 | VirtualQuery(m_pOriginalVTable, &memInfo, sizeof(memInfo)); 53 | VirtualProtect(m_pVTable, sizeof(DWORD)*vtableSize, memInfo.Protect, &dwOldProtect); 54 | 55 | // Replace the vtable pointer 56 | VirtualProtect(m_pClassBase, sizeof(DWORD), PAGE_READWRITE, &dwOldProtect); 57 | *m_pClassBase = m_pVTable; 58 | VirtualProtect(m_pClassBase, sizeof(DWORD), dwOldProtect, &dwOldProtect2); 59 | } 60 | } 61 | 62 | DWORD VTableHook::HookMethod(DWORD dwNewFunc, unsigned int index) { 63 | DWORD dwOldProtect, dwOldProtect2; 64 | 65 | hookVTable(); 66 | 67 | VirtualProtect(&m_pVTable[index], sizeof(DWORD), PAGE_READWRITE, &dwOldProtect); 68 | m_pVTable[index] = dwNewFunc; 69 | VirtualProtect(&m_pVTable[index], sizeof(DWORD), dwOldProtect, &dwOldProtect2); 70 | 71 | return m_pVTable[index]; 72 | } -------------------------------------------------------------------------------- /csgo/VTableHook.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | class VTableHook { 7 | 8 | public: 9 | VTableHook(PDWORD* pClassBase); 10 | ~VTableHook(); 11 | DWORD VTableHook::GetMethodAddress(unsigned int index); 12 | unsigned int getVTableSize(); 13 | DWORD VTableHook::HookMethod(DWORD dwNewFunc, unsigned int index); 14 | 15 | private: 16 | void hookVTable(); 17 | PDWORD* m_pClassBase; 18 | PDWORD m_pVTable; 19 | PDWORD m_pOriginalVTable; 20 | }; 21 | -------------------------------------------------------------------------------- /csgo/Vector2.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector2.h" 2 | 3 | Vector2::Vector2() { 4 | x = 0; 5 | y = 0; 6 | } 7 | 8 | Vector2::Vector2(float x, float y) { 9 | this->x = x; 10 | this->y = y; 11 | } -------------------------------------------------------------------------------- /csgo/Vector2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Vector2 { 4 | public: 5 | float x, y; 6 | Vector2(); 7 | Vector2(float x, float y); 8 | }; -------------------------------------------------------------------------------- /csgo/Vector3.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector3.h" 2 | #include 3 | 4 | Vector3::Vector3() { 5 | x = 0; 6 | y = 0; 7 | z = 0; 8 | } 9 | 10 | Vector3::Vector3(float x, float y, float z) { 11 | this->x = x; 12 | this->y = y; 13 | this->z = z; 14 | } 15 | 16 | float Vector3::lengthSquare() { 17 | return (x*x + y*y + z*z); 18 | } 19 | 20 | float Vector3::length() { 21 | return (float) sqrt(lengthSquare()); 22 | } 23 | 24 | bool Vector3::isNull() { 25 | return (x < 1 && y < 1 && z < 1); 26 | } 27 | 28 | Vector3 Vector3::operator+(Vector3 v) { 29 | Vector3 r; 30 | r.x = x + v.x; 31 | r.y = y + v.y; 32 | r.z = z + v.z; 33 | return r; 34 | } 35 | 36 | Vector3 Vector3::operator-(Vector3 v) { 37 | Vector3 r; 38 | r.x = x - v.x; 39 | r.y = y - v.y; 40 | r.z = z - v.z; 41 | return r; 42 | } 43 | 44 | Vector3 Vector3::operator*(float f) { 45 | Vector3 r; 46 | r.x = x * f; 47 | r.y = y * f; 48 | r.z = z * f; 49 | return r; 50 | } -------------------------------------------------------------------------------- /csgo/Vector3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Vector3 { 4 | public: 5 | float x, y, z; 6 | Vector3(); 7 | Vector3(float x, float y, float z); 8 | float lengthSquare(); 9 | float length(); 10 | bool isNull(); 11 | Vector3 operator+(Vector3 v); 12 | Vector3 operator-(Vector3 v); 13 | Vector3 operator*(float f); 14 | }; -------------------------------------------------------------------------------- /csgo/Vector4.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector4.h" 2 | 3 | Vector4::Vector4() { 4 | reset(); 5 | } 6 | 7 | Vector4::Vector4(float x, float y, float z, float w) { 8 | this->x = x; 9 | this->y = y; 10 | this->z = z; 11 | this->w = w; 12 | } 13 | 14 | void Vector4::reset() { 15 | this->x = 0; 16 | this->y = 0; 17 | this->z = 0; 18 | this->w = 0; 19 | } 20 | 21 | void Vector4::operator=(Vector3 v) { 22 | x = v.x; 23 | y = v.y; 24 | z = v.z; 25 | w = 0; 26 | } -------------------------------------------------------------------------------- /csgo/Vector4.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector3.h" 4 | 5 | class Vector4 : public Vector3 { 6 | public: 7 | float w; 8 | Vector4(); 9 | Vector4(float x, float y, float z, float w); 10 | void reset(); 11 | void operator=(Vector3 v); 12 | }; -------------------------------------------------------------------------------- /csgo/Vmatrix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct Vmatrix { 4 | float m[4][4]; 5 | 6 | inline float* operator[](int i) { 7 | return m[i]; 8 | } 9 | 10 | inline const float* operator[](int i) const { 11 | return m[i]; 12 | } 13 | }; -------------------------------------------------------------------------------- /csgo/Vpanel.cpp: -------------------------------------------------------------------------------- 1 | #include "Vpnanel.h" 2 | 3 | 4 | char* Vpanel::getName(int index) { 5 | typedef char*(__thiscall *GetNameFn)(PVOID pThis, int index); 6 | GetNameFn oGameName = (GetNameFn)m_vtable->GetMethodAddress(VMT_GETPANELNAME); 7 | return oGameName(self(), index); 8 | } -------------------------------------------------------------------------------- /csgo/Vpnanel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameInterface.h" 4 | #include "vmtIndexes.h" 5 | 6 | 7 | class Vpanel : public GameInterface { 8 | public: 9 | using GameInterface::GameInterface; 10 | 11 | char* getName(int index); 12 | }; -------------------------------------------------------------------------------- /csgo/boneId.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Terrorist { 4 | enum BoneId { 5 | pelvis, 6 | spine_0, 7 | spine_1, 8 | spine_2, 9 | spine_3, 10 | neck_0, 11 | head_0, 12 | clavicle_L, 13 | arm_upper_L, 14 | arm_lower_L, 15 | hand_L, 16 | finger_middle_meta_L, 17 | finger_middle_0_L, 18 | finger_middle_1_L, 19 | finger_middle_2_L, 20 | finger_pinky_meta_L, 21 | finger_pinky_0_L, 22 | finger_pinky_1_L, 23 | finger_pinky_2_L, 24 | finger_index_meta_L, 25 | finger_index_0_L, 26 | finger_index_1_L, 27 | finger_index_2_L, 28 | finger_thumb_0_L, 29 | finger_thumb_1_L, 30 | finger_thumb_2_L, 31 | finger_ring_meta_L, 32 | finger_ring_0_L, 33 | finger_ring_1_L, 34 | finger_ring_2_L, 35 | weapon_hand_L, 36 | arm_lower_L_TWIST, 37 | arm_lower_L_TWIST1, 38 | arm_upper_L_TWIST, 39 | arm_upper_L_TWIST1, 40 | clavicle_R, 41 | arm_upper_R, 42 | arm_lower_R, 43 | hand_R, 44 | finger_middle_meta_R, 45 | finger_middle_0_R, 46 | finger_middle_1_R, 47 | finger_middle_2_R, 48 | finger_pinky_meta_R, 49 | finger_pinky_0_R, 50 | finger_pinky_1_R, 51 | finger_pinky_2_R, 52 | finger_index_meta_R, 53 | finger_index_0_R, 54 | finger_index_1_R, 55 | finger_index_2_R, 56 | finger_thumb_0_R, 57 | finger_thumb_1_R, 58 | finger_thumb_2_R, 59 | finger_ring_meta_R, 60 | finger_ring_0_R, 61 | finger_ring_1_R, 62 | finger_ring_2_R, 63 | weapon_hand_R, 64 | arm_lower_R_TWIST, 65 | arm_lower_R_TWIST1, 66 | arm_upper_R_TWIST, 67 | arm_upper_R_TWIST1, 68 | leg_upper_L, 69 | leg_lower_L, 70 | ankle_L, 71 | ball_L, 72 | leg_upper_L_TWIST, 73 | leg_upper_L_TWIST1, 74 | leg_upper_R, 75 | leg_lower_R, 76 | ankle_R, 77 | ball_R, 78 | leg_upper_R_TWIST, 79 | leg_upper_R_TWIST1, 80 | ValveBiped_weapon_bone, 81 | lh_ik_driver, 82 | lean_root, 83 | lfoot_lock, 84 | rfoot_lock, 85 | primary_jiggle_jnt, 86 | primary_smg_jiggle_jnt 87 | }; 88 | } 89 | 90 | namespace CounterTerrorist { 91 | enum BoneId { 92 | pelvis, 93 | spine_0, 94 | spine_1, 95 | spine_2, 96 | spine_3, 97 | neck_0, 98 | head_0, 99 | clavicle_L, 100 | arm_upper_L = 9, 101 | arm_lower_L = 10, 102 | hand_L = 11, 103 | arm_upper_R = 39, 104 | arm_lower_R = 40, 105 | hand_R = 41, 106 | leg_upper_L = 72, 107 | leg_lower_L = 69, 108 | ankle_L = 70, 109 | leg_upper_R = 78, 110 | leg_lower_R = 75, 111 | ankle_R = 76 112 | }; 113 | } -------------------------------------------------------------------------------- /csgo/csgo.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {6ADF7003-F0D3-459E-A66B-14E3901E6B68} 23 | Win32Proj 24 | csgo 25 | 8.1 26 | 27 | 28 | 29 | DynamicLibrary 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | DynamicLibrary 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | DynamicLibrary 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | DynamicLibrary 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | WIN32;_DEBUG;_WINDOWS;_USRDLL;CSGO_EXPORTS;%(PreprocessorDefinitions) 91 | true 92 | 93 | 94 | Windows 95 | true 96 | 97 | 98 | 99 | 100 | 101 | 102 | Level3 103 | Disabled 104 | _DEBUG;_WINDOWS;_USRDLL;CSGO_EXPORTS;%(PreprocessorDefinitions) 105 | true 106 | 107 | 108 | Windows 109 | true 110 | 111 | 112 | 113 | 114 | Level3 115 | 116 | 117 | MaxSpeed 118 | true 119 | true 120 | WIN32;NDEBUG;_WINDOWS;_USRDLL;CSGO_EXPORTS;%(PreprocessorDefinitions) 121 | true 122 | 123 | 124 | Windows 125 | true 126 | true 127 | true 128 | 129 | 130 | 131 | 132 | Level3 133 | 134 | 135 | MaxSpeed 136 | true 137 | true 138 | NDEBUG;_WINDOWS;_USRDLL;CSGO_EXPORTS;%(PreprocessorDefinitions) 139 | true 140 | 141 | 142 | Windows 143 | true 144 | true 145 | true 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | -------------------------------------------------------------------------------- /csgo/csgo.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {f813221b-1e8a-4f8f-93ff-0594c9fe55fb} 18 | 19 | 20 | {221d83e4-b729-49ef-bd98-c28203dadeaf} 21 | 22 | 23 | 24 | 25 | Fichiers sources 26 | 27 | 28 | Fichiers sources 29 | 30 | 31 | Fichiers sources 32 | 33 | 34 | Fichiers sources 35 | 36 | 37 | Fichiers sources 38 | 39 | 40 | Fichiers sources 41 | 42 | 43 | Fichiers sources 44 | 45 | 46 | Fichiers sources 47 | 48 | 49 | Fichiers sources 50 | 51 | 52 | Fichiers sources 53 | 54 | 55 | Fichiers sources 56 | 57 | 58 | Fichiers sources 59 | 60 | 61 | Fichiers sources 62 | 63 | 64 | Fichiers sources 65 | 66 | 67 | Fichiers sources 68 | 69 | 70 | Fichiers sources 71 | 72 | 73 | Fichiers sources\ImGui 74 | 75 | 76 | Fichiers sources\ImGui 77 | 78 | 79 | Fichiers sources\ImGui 80 | 81 | 82 | Fichiers sources\ImGui 83 | 84 | 85 | Fichiers sources 86 | 87 | 88 | Fichiers sources 89 | 90 | 91 | Fichiers sources 92 | 93 | 94 | Fichiers sources 95 | 96 | 97 | Fichiers sources 98 | 99 | 100 | Fichiers sources 101 | 102 | 103 | Fichiers sources\ImGui 104 | 105 | 106 | Fichiers sources 107 | 108 | 109 | 110 | 111 | Fichiers d%27en-tête 112 | 113 | 114 | Fichiers d%27en-tête 115 | 116 | 117 | Fichiers d%27en-tête 118 | 119 | 120 | Fichiers d%27en-tête 121 | 122 | 123 | Fichiers d%27en-tête 124 | 125 | 126 | Fichiers d%27en-tête 127 | 128 | 129 | Fichiers d%27en-tête 130 | 131 | 132 | Fichiers d%27en-tête 133 | 134 | 135 | Fichiers d%27en-tête 136 | 137 | 138 | Fichiers d%27en-tête 139 | 140 | 141 | Fichiers d%27en-tête 142 | 143 | 144 | Fichiers d%27en-tête 145 | 146 | 147 | Fichiers d%27en-tête 148 | 149 | 150 | Fichiers d%27en-tête 151 | 152 | 153 | Fichiers d%27en-tête 154 | 155 | 156 | Fichiers d%27en-tête 157 | 158 | 159 | Fichiers d%27en-tête 160 | 161 | 162 | Fichiers d%27en-tête 163 | 164 | 165 | Fichiers d%27en-tête 166 | 167 | 168 | Fichiers d%27en-tête 169 | 170 | 171 | Fichiers d%27en-tête 172 | 173 | 174 | Fichiers d%27en-tête 175 | 176 | 177 | Fichiers d%27en-tête\ImGui 178 | 179 | 180 | Fichiers d%27en-tête\ImGui 181 | 182 | 183 | Fichiers d%27en-tête\ImGui 184 | 185 | 186 | Fichiers d%27en-tête\ImGui 187 | 188 | 189 | Fichiers d%27en-tête\ImGui 190 | 191 | 192 | Fichiers d%27en-tête\ImGui 193 | 194 | 195 | Fichiers d%27en-tête\ImGui 196 | 197 | 198 | Fichiers d%27en-tête 199 | 200 | 201 | Fichiers d%27en-tête 202 | 203 | 204 | Fichiers d%27en-tête 205 | 206 | 207 | Fichiers d%27en-tête 208 | 209 | 210 | Fichiers d%27en-tête 211 | 212 | 213 | Fichiers d%27en-tête 214 | 215 | 216 | Fichiers d%27en-tête\ImGui 217 | 218 | 219 | Fichiers d%27en-tête 220 | 221 | 222 | Fichiers d%27en-tête 223 | 224 | 225 | -------------------------------------------------------------------------------- /csgo/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // USER IMPLEMENTATION 3 | // This file contains compile-time options for ImGui. 4 | // Other options (memory allocation overrides, callbacks, etc.) can be set at runtime via the ImGuiIO structure - ImGui::GetIO(). 5 | //----------------------------------------------------------------------------- 6 | 7 | #pragma once 8 | 9 | //---- Define assertion handler. Defaults to calling assert(). 10 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 11 | 12 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows. 13 | //#define IMGUI_API __declspec( dllexport ) 14 | //#define IMGUI_API __declspec( dllimport ) 15 | 16 | //---- Include imgui_user.h at the end of imgui.h 17 | //#define IMGUI_INCLUDE_IMGUI_USER_H 18 | 19 | //---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions) 20 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS 21 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS 22 | 23 | //---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty) 24 | //#define IMGUI_DISABLE_TEST_WINDOWS 25 | 26 | //---- Don't define obsolete functions names 27 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 28 | 29 | //---- Implement STB libraries in a namespace to avoid conflicts 30 | //#define IMGUI_STB_NAMESPACE ImGuiStb 31 | 32 | //---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. 33 | /* 34 | #define IM_VEC2_CLASS_EXTRA \ 35 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ 36 | operator MyVec2() const { return MyVec2(x,y); } 37 | 38 | #define IM_VEC4_CLASS_EXTRA \ 39 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ 40 | operator MyVec4() const { return MyVec4(x,y,z,w); } 41 | */ 42 | 43 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 44 | //---- e.g. create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers. 45 | /* 46 | namespace ImGui 47 | { 48 | void Value(const char* prefix, const MyMatrix44& v, const char* float_format = NULL); 49 | } 50 | */ 51 | 52 | -------------------------------------------------------------------------------- /csgo/imgui/imgui_color_picker.cpp: -------------------------------------------------------------------------------- 1 | // https://gist.github.com/ocornut/9a55357df27d73cb8b34 2 | // [src] https://github.com/ocornut/imgui/issues/346 3 | // v2.36 4 | // TODO: try to integrate properly within ColorEdit4() 5 | // TODO: expose size (how?) 6 | // TODO: expose ID in api? 7 | // TODO: massage, cleanup 8 | 9 | #include "imgui.h" 10 | #define IMGUI_DEFINE_MATH_OPERATORS 11 | #include "imgui_internal.h" // ImSaturate 12 | 13 | bool ColorPicker4(float* col, bool show_alpha) 14 | { 15 | ImGuiIO& io = ImGui::GetIO(); 16 | ImGuiStyle& style = ImGui::GetStyle(); 17 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 18 | 19 | // Setup 20 | ImVec2 picker_pos = ImGui::GetCursorScreenPos(); 21 | ImVec2 sv_picker_size = ImVec2(256.0f, 256.0f); // Saturation/Value picking box 22 | float bars_width = ImGui::GetWindowFontSize() + style.FramePadding.y*2.0f; // Width of Hue/Alpha picking bars (using Framepadding.y to match the ColorButton sides) 23 | float bar0_pos_x = picker_pos.x + sv_picker_size.x + style.ItemInnerSpacing.x; 24 | float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x; 25 | 26 | float H,S,V; 27 | ImGui::ColorConvertRGBtoHSV(col[0], col[1], col[2], H, S, V); 28 | 29 | // Color matrix logic 30 | bool value_changed = false, hsv_changed = false; 31 | ImGui::BeginGroup(); 32 | ImGui::InvisibleButton("sv", sv_picker_size); 33 | if (ImGui::IsItemActive()) 34 | { 35 | S = ImSaturate((io.MousePos.x - picker_pos.x) / (sv_picker_size.x-1)); 36 | V = 1.0f - ImSaturate((io.MousePos.y - picker_pos.y) / (sv_picker_size.y-1)); 37 | value_changed = hsv_changed = true; 38 | } 39 | 40 | // Hue bar logic 41 | ImGui::SetCursorScreenPos(ImVec2(bar0_pos_x, picker_pos.y)); 42 | ImGui::InvisibleButton("hue", ImVec2(bars_width, sv_picker_size.y)); 43 | if (ImGui::IsItemActive()) 44 | { 45 | H = ImSaturate((io.MousePos.y - picker_pos.y) / (sv_picker_size.y-1)); 46 | value_changed = hsv_changed = true; 47 | } 48 | 49 | // Alpha bar logic 50 | if (show_alpha) 51 | { 52 | ImGui::SetCursorScreenPos(ImVec2(bar1_pos_x, picker_pos.y)); 53 | ImGui::InvisibleButton("alpha", ImVec2(bars_width, sv_picker_size.y)); 54 | if (ImGui::IsItemActive()) 55 | { 56 | col[3] = 1.0f - ImSaturate((io.MousePos.y - picker_pos.y) / (sv_picker_size.y-1)); 57 | value_changed = true; 58 | } 59 | } 60 | 61 | // Convert back to RGB 62 | if (hsv_changed) 63 | ImGui::ColorConvertHSVtoRGB(H >= 1.0f ? H - 10 * 1e-6f : H, S > 0.0f ? S : 10*1e-6f, V > 0.0f ? V : 1e-6f, col[0], col[1], col[2]); 64 | 65 | // R,G,B or H,S,V color editor 66 | ImGui::PushItemWidth((show_alpha ? bar1_pos_x : bar0_pos_x) + bars_width - picker_pos.x); 67 | value_changed |= show_alpha ? ImGui::ColorEdit4("##edit", col) : ImGui::ColorEdit3("##edit", col); 68 | ImGui::PopItemWidth(); 69 | 70 | // Try to cancel hue wrap (after ColorEdit), if any 71 | if (value_changed) 72 | { 73 | float new_H, new_S, new_V; 74 | ImGui::ColorConvertRGBtoHSV(col[0], col[1], col[2], new_H, new_S, new_V); 75 | if (new_H <= 0 && H > 0) 76 | { 77 | if (new_V <= 0 && V != new_V) 78 | ImGui::ColorConvertHSVtoRGB(H, S, new_V <= 0 ? V * 0.5f : new_V, col[0], col[1], col[2]); 79 | else if (new_S <= 0) 80 | ImGui::ColorConvertHSVtoRGB(H, new_S <= 0 ? S * 0.5f : new_S, new_V, col[0], col[1], col[2]); 81 | } 82 | } 83 | 84 | // Render hue bar 85 | ImU32 hue_colors[] = { IM_COL32(255,0,0,255), IM_COL32(255,255,0,255), IM_COL32(0,255,0,255), IM_COL32(0,255,255,255), IM_COL32(0,0,255,255), IM_COL32(255,0,255,255), IM_COL32(255,0,0,255) }; 86 | for (int i = 0; i < 6; ++i) 87 | { 88 | draw_list->AddRectFilledMultiColor( 89 | ImVec2(bar0_pos_x, picker_pos.y + i * (sv_picker_size.y / 6)), 90 | ImVec2(bar0_pos_x + bars_width, picker_pos.y + (i + 1) * (sv_picker_size.y / 6)), 91 | hue_colors[i], hue_colors[i], hue_colors[i + 1], hue_colors[i + 1]); 92 | } 93 | float bar0_line_y = (float)(int)(picker_pos.y + H * sv_picker_size.y + 0.5f); 94 | draw_list->AddLine(ImVec2(bar0_pos_x - 1, bar0_line_y), ImVec2(bar0_pos_x + bars_width + 1, bar0_line_y), IM_COL32_WHITE); 95 | 96 | // Render alpha bar 97 | if (show_alpha) 98 | { 99 | float alpha = ImSaturate(col[3]); 100 | float bar1_line_y = (float)(int)(picker_pos.y + (1.0f-alpha) * sv_picker_size.y + 0.5f); 101 | draw_list->AddRectFilledMultiColor(ImVec2(bar1_pos_x, picker_pos.y), ImVec2(bar1_pos_x + bars_width, picker_pos.y + sv_picker_size.y), IM_COL32_WHITE, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32_BLACK); 102 | draw_list->AddLine(ImVec2(bar1_pos_x - 1, bar1_line_y), ImVec2(bar1_pos_x + bars_width + 1, bar1_line_y), IM_COL32_WHITE); 103 | } 104 | 105 | // Render color matrix 106 | ImVec4 hue_color_f(1, 1, 1, 1); 107 | ImGui::ColorConvertHSVtoRGB(H, 1, 1, hue_color_f.x, hue_color_f.y, hue_color_f.z); 108 | ImU32 hue_color32 = ImGui::ColorConvertFloat4ToU32(hue_color_f); 109 | draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + sv_picker_size, IM_COL32_WHITE, hue_color32, hue_color32, IM_COL32_WHITE); 110 | draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + sv_picker_size, IM_COL32_BLACK_TRANS, IM_COL32_BLACK_TRANS, IM_COL32_BLACK, IM_COL32_BLACK); 111 | 112 | // Render cross-hair 113 | const float CROSSHAIR_SIZE = 7.0f; 114 | ImVec2 p((float)(int)(picker_pos.x + S * sv_picker_size.x + 0.5f), (float)(int)(picker_pos.y + (1 - V) * sv_picker_size.y + 0.5f)); 115 | draw_list->AddLine(ImVec2(p.x - CROSSHAIR_SIZE, p.y), ImVec2(p.x - 2, p.y), IM_COL32_WHITE); 116 | draw_list->AddLine(ImVec2(p.x + CROSSHAIR_SIZE, p.y), ImVec2(p.x + 2, p.y), IM_COL32_WHITE); 117 | draw_list->AddLine(ImVec2(p.x, p.y + CROSSHAIR_SIZE), ImVec2(p.x, p.y + 2), IM_COL32_WHITE); 118 | draw_list->AddLine(ImVec2(p.x, p.y - CROSSHAIR_SIZE), ImVec2(p.x, p.y - 2), IM_COL32_WHITE); 119 | ImGui::EndGroup(); 120 | 121 | return value_changed; 122 | } 123 | 124 | bool ColorPicker3(float col[3]) 125 | { 126 | return ColorPicker4(col, false); 127 | } -------------------------------------------------------------------------------- /csgo/imgui/imgui_color_picker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | bool ColorPicker4(float* col, bool show_alpha); 4 | bool ColorPicker3(float col[3]); -------------------------------------------------------------------------------- /csgo/imgui/imgui_impl_dx9.cpp: -------------------------------------------------------------------------------- 1 | // ImGui Win32 + DirectX9 binding 2 | // In this binding, ImTextureID is used to store a 'LPDIRECT3DTEXTURE9' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. 3 | 4 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 5 | // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). 6 | // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. 7 | // https://github.com/ocornut/imgui 8 | 9 | #include "imgui.h" 10 | #include "imgui_impl_dx9.h" 11 | 12 | // DirectX 13 | #include 14 | #define DIRECTINPUT_VERSION 0x0800 15 | #include 16 | 17 | // Data 18 | static HWND g_hWnd = 0; 19 | static INT64 g_Time = 0; 20 | static INT64 g_TicksPerSecond = 0; 21 | static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; 22 | static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; 23 | static LPDIRECT3DINDEXBUFFER9 g_pIB = NULL; 24 | static LPDIRECT3DTEXTURE9 g_FontTexture = NULL; 25 | static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000; 26 | 27 | struct CUSTOMVERTEX 28 | { 29 | float pos[3]; 30 | D3DCOLOR col; 31 | float uv[2]; 32 | }; 33 | #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) 34 | 35 | // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) 36 | // If text or lines are blurry when integrating ImGui in your engine: 37 | // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) 38 | void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data) 39 | { 40 | // Avoid rendering when minimized 41 | ImGuiIO& io = ImGui::GetIO(); 42 | if (io.DisplaySize.x <= 0.0f || io.DisplaySize.y <= 0.0f) 43 | return; 44 | 45 | // Create and grow buffers if needed 46 | if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount) 47 | { 48 | if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } 49 | g_VertexBufferSize = draw_data->TotalVtxCount + 5000; 50 | if (g_pd3dDevice->CreateVertexBuffer(g_VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0) 51 | return; 52 | } 53 | if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount) 54 | { 55 | if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } 56 | g_IndexBufferSize = draw_data->TotalIdxCount + 10000; 57 | if (g_pd3dDevice->CreateIndexBuffer(g_IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &g_pIB, NULL) < 0) 58 | return; 59 | } 60 | 61 | // Backup the DX9 state 62 | IDirect3DStateBlock9* d3d9_state_block = NULL; 63 | if (g_pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0) 64 | return; 65 | 66 | // Copy and convert all vertices into a single contiguous buffer 67 | CUSTOMVERTEX* vtx_dst; 68 | ImDrawIdx* idx_dst; 69 | if (g_pVB->Lock(0, (UINT)(draw_data->TotalVtxCount * sizeof(CUSTOMVERTEX)), (void**)&vtx_dst, D3DLOCK_DISCARD) < 0) 70 | return; 71 | if (g_pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0) 72 | return; 73 | for (int n = 0; n < draw_data->CmdListsCount; n++) 74 | { 75 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 76 | const ImDrawVert* vtx_src = &cmd_list->VtxBuffer[0]; 77 | for (int i = 0; i < cmd_list->VtxBuffer.size(); i++) 78 | { 79 | vtx_dst->pos[0] = vtx_src->pos.x; 80 | vtx_dst->pos[1] = vtx_src->pos.y; 81 | vtx_dst->pos[2] = 0.0f; 82 | vtx_dst->col = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9 83 | vtx_dst->uv[0] = vtx_src->uv.x; 84 | vtx_dst->uv[1] = vtx_src->uv.y; 85 | vtx_dst++; 86 | vtx_src++; 87 | } 88 | memcpy(idx_dst, &cmd_list->IdxBuffer[0], cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx)); 89 | idx_dst += cmd_list->IdxBuffer.size(); 90 | } 91 | g_pVB->Unlock(); 92 | g_pIB->Unlock(); 93 | g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX)); 94 | g_pd3dDevice->SetIndices(g_pIB); 95 | g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); 96 | 97 | // Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing 98 | g_pd3dDevice->SetPixelShader(NULL); 99 | g_pd3dDevice->SetVertexShader(NULL); 100 | g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); 101 | g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, false); 102 | g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); 103 | g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true); 104 | g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false); 105 | g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); 106 | g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); 107 | g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); 108 | g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, true); 109 | g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); 110 | g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); 111 | g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); 112 | g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); 113 | g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); 114 | g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); 115 | g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); 116 | g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); 117 | 118 | // Setup orthographic projection matrix 119 | // Being agnostic of whether or can be used, we aren't relying on D3DXMatrixIdentity()/D3DXMatrixOrthoOffCenterLH() or DirectX::XMMatrixIdentity()/DirectX::XMMatrixOrthographicOffCenterLH() 120 | { 121 | const float L = 0.5f, R = io.DisplaySize.x+0.5f, T = 0.5f, B = io.DisplaySize.y+0.5f; 122 | D3DMATRIX mat_identity = { { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; 123 | D3DMATRIX mat_projection = 124 | { 125 | 2.0f/(R-L), 0.0f, 0.0f, 0.0f, 126 | 0.0f, 2.0f/(T-B), 0.0f, 0.0f, 127 | 0.0f, 0.0f, 0.5f, 0.0f, 128 | (L+R)/(L-R), (T+B)/(B-T), 0.5f, 1.0f, 129 | }; 130 | g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat_identity); 131 | g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat_identity); 132 | g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat_projection); 133 | } 134 | 135 | // Render command lists 136 | int vtx_offset = 0; 137 | int idx_offset = 0; 138 | for (int n = 0; n < draw_data->CmdListsCount; n++) 139 | { 140 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 141 | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++) 142 | { 143 | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; 144 | if (pcmd->UserCallback) 145 | { 146 | pcmd->UserCallback(cmd_list, pcmd); 147 | } 148 | else 149 | { 150 | const RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w }; 151 | g_pd3dDevice->SetTexture(0, (LPDIRECT3DTEXTURE9)pcmd->TextureId); 152 | g_pd3dDevice->SetScissorRect(&r); 153 | g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.size(), idx_offset, pcmd->ElemCount/3); 154 | } 155 | idx_offset += pcmd->ElemCount; 156 | } 157 | vtx_offset += cmd_list->VtxBuffer.size(); 158 | } 159 | 160 | // Restore the DX9 state 161 | d3d9_state_block->Apply(); 162 | d3d9_state_block->Release(); 163 | } 164 | 165 | IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam) 166 | { 167 | ImGuiIO& io = ImGui::GetIO(); 168 | switch (msg) 169 | { 170 | case WM_LBUTTONDOWN: 171 | io.MouseDown[0] = true; 172 | return true; 173 | case WM_LBUTTONUP: 174 | io.MouseDown[0] = false; 175 | return true; 176 | case WM_RBUTTONDOWN: 177 | io.MouseDown[1] = true; 178 | return true; 179 | case WM_RBUTTONUP: 180 | io.MouseDown[1] = false; 181 | return true; 182 | case WM_MBUTTONDOWN: 183 | io.MouseDown[2] = true; 184 | return true; 185 | case WM_MBUTTONUP: 186 | io.MouseDown[2] = false; 187 | return true; 188 | case WM_MOUSEWHEEL: 189 | io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; 190 | return true; 191 | case WM_MOUSEMOVE: 192 | io.MousePos.x = (signed short)(lParam); 193 | io.MousePos.y = (signed short)(lParam >> 16); 194 | return true; 195 | case WM_KEYDOWN: 196 | if (wParam < 256) 197 | io.KeysDown[wParam] = 1; 198 | return true; 199 | case WM_KEYUP: 200 | if (wParam < 256) 201 | io.KeysDown[wParam] = 0; 202 | return true; 203 | case WM_CHAR: 204 | // You can also use ToAscii()+GetKeyboardState() to retrieve characters. 205 | if (wParam > 0 && wParam < 0x10000) 206 | io.AddInputCharacter((unsigned short)wParam); 207 | return true; 208 | } 209 | return 0; 210 | } 211 | 212 | bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device) 213 | { 214 | g_hWnd = (HWND)hwnd; 215 | g_pd3dDevice = device; 216 | 217 | if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond)) 218 | return false; 219 | if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time)) 220 | return false; 221 | 222 | ImGuiIO& io = ImGui::GetIO(); 223 | io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. 224 | io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; 225 | io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; 226 | io.KeyMap[ImGuiKey_UpArrow] = VK_UP; 227 | io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; 228 | io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR; 229 | io.KeyMap[ImGuiKey_PageDown] = VK_NEXT; 230 | io.KeyMap[ImGuiKey_Home] = VK_HOME; 231 | io.KeyMap[ImGuiKey_End] = VK_END; 232 | io.KeyMap[ImGuiKey_Delete] = VK_DELETE; 233 | io.KeyMap[ImGuiKey_Backspace] = VK_BACK; 234 | io.KeyMap[ImGuiKey_Enter] = VK_RETURN; 235 | io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; 236 | io.KeyMap[ImGuiKey_A] = 'A'; 237 | io.KeyMap[ImGuiKey_C] = 'C'; 238 | io.KeyMap[ImGuiKey_V] = 'V'; 239 | io.KeyMap[ImGuiKey_X] = 'X'; 240 | io.KeyMap[ImGuiKey_Y] = 'Y'; 241 | io.KeyMap[ImGuiKey_Z] = 'Z'; 242 | 243 | io.RenderDrawListsFn = ImGui_ImplDX9_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer. 244 | io.ImeWindowHandle = g_hWnd; 245 | 246 | return true; 247 | } 248 | 249 | void ImGui_ImplDX9_Shutdown() 250 | { 251 | ImGui_ImplDX9_InvalidateDeviceObjects(); 252 | ImGui::Shutdown(); 253 | g_pd3dDevice = NULL; 254 | g_hWnd = 0; 255 | } 256 | 257 | static bool ImGui_ImplDX9_CreateFontsTexture() 258 | { 259 | // Build texture atlas 260 | ImGuiIO& io = ImGui::GetIO(); 261 | unsigned char* pixels; 262 | int width, height, bytes_per_pixel; 263 | io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &bytes_per_pixel); 264 | 265 | // Upload texture to graphics system 266 | g_FontTexture = NULL; 267 | if (g_pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_FontTexture, NULL) < 0) 268 | return false; 269 | D3DLOCKED_RECT tex_locked_rect; 270 | if (g_FontTexture->LockRect(0, &tex_locked_rect, NULL, 0) != D3D_OK) 271 | return false; 272 | for (int y = 0; y < height; y++) 273 | memcpy((unsigned char *)tex_locked_rect.pBits + tex_locked_rect.Pitch * y, pixels + (width * bytes_per_pixel) * y, (width * bytes_per_pixel)); 274 | g_FontTexture->UnlockRect(0); 275 | 276 | // Store our identifier 277 | io.Fonts->TexID = (void *)g_FontTexture; 278 | 279 | return true; 280 | } 281 | 282 | bool ImGui_ImplDX9_CreateDeviceObjects() 283 | { 284 | if (!g_pd3dDevice) 285 | return false; 286 | if (!ImGui_ImplDX9_CreateFontsTexture()) 287 | return false; 288 | return true; 289 | } 290 | 291 | void ImGui_ImplDX9_InvalidateDeviceObjects() 292 | { 293 | if (!g_pd3dDevice) 294 | return; 295 | if (g_pVB) 296 | { 297 | g_pVB->Release(); 298 | g_pVB = NULL; 299 | } 300 | if (g_pIB) 301 | { 302 | g_pIB->Release(); 303 | g_pIB = NULL; 304 | } 305 | if (LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)ImGui::GetIO().Fonts->TexID) 306 | { 307 | tex->Release(); 308 | ImGui::GetIO().Fonts->TexID = 0; 309 | } 310 | g_FontTexture = NULL; 311 | } 312 | 313 | void ImGui_ImplDX9_NewFrame() 314 | { 315 | if (!g_FontTexture) 316 | ImGui_ImplDX9_CreateDeviceObjects(); 317 | 318 | ImGuiIO& io = ImGui::GetIO(); 319 | 320 | // Setup display size (every frame to accommodate for window resizing) 321 | RECT rect; 322 | GetClientRect(g_hWnd, &rect); 323 | io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); 324 | 325 | // Setup time step 326 | INT64 current_time; 327 | QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); 328 | io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond; 329 | g_Time = current_time; 330 | 331 | // Read keyboard modifiers inputs 332 | io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0; 333 | io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0; 334 | io.KeyAlt = (GetKeyState(VK_MENU) & 0x8000) != 0; 335 | io.KeySuper = false; 336 | // io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events 337 | // io.MousePos : filled by WM_MOUSEMOVE events 338 | // io.MouseDown : filled by WM_*BUTTON* events 339 | // io.MouseWheel : filled by WM_MOUSEWHEEL events 340 | 341 | // Hide OS mouse cursor if ImGui is drawing it 342 | SetCursor(io.MouseDrawCursor ? NULL : LoadCursor(NULL, IDC_ARROW)); 343 | 344 | // Start the frame 345 | ImGui::NewFrame(); 346 | } 347 | -------------------------------------------------------------------------------- /csgo/imgui/imgui_impl_dx9.h: -------------------------------------------------------------------------------- 1 | // ImGui Win32 + DirectX9 binding 2 | // In this binding, ImTextureID is used to store a 'LPDIRECT3DTEXTURE9' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. 3 | 4 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 5 | // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). 6 | // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. 7 | // https://github.com/ocornut/imgui 8 | 9 | #include 10 | struct IDirect3DDevice9; 11 | 12 | IMGUI_API bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device); 13 | IMGUI_API void ImGui_ImplDX9_Shutdown(); 14 | IMGUI_API void ImGui_ImplDX9_NewFrame(); 15 | 16 | // Use if you want to reset your rendering device without losing ImGui state. 17 | IMGUI_API void ImGui_ImplDX9_InvalidateDeviceObjects(); 18 | IMGUI_API bool ImGui_ImplDX9_CreateDeviceObjects(); 19 | 20 | // Handler for Win32 messages, update mouse/keyboard data. 21 | // You may or not need this for your implementation, but it can serve as reference for handling inputs. 22 | // Commented out to avoid dragging dependencies on types. You can copy the extern declaration in your code. 23 | //* 24 | IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 25 | //*/ 26 | -------------------------------------------------------------------------------- /csgo/imgui/imgui_internal.h: -------------------------------------------------------------------------------- 1 | // dear imgui, v1.50 WIP 2 | // (internals) 3 | 4 | // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! 5 | // Implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators) 6 | // #define IMGUI_DEFINE_MATH_OPERATORS 7 | 8 | #pragma once 9 | 10 | #ifndef IMGUI_VERSION 11 | #error Must include imgui.h before imgui_internal.h 12 | #endif 13 | 14 | #include // FILE* 15 | #include // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf 16 | 17 | #ifdef _MSC_VER 18 | #pragma warning (push) 19 | #pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport) 20 | #endif 21 | 22 | #ifdef __clang__ 23 | #pragma clang diagnostic push 24 | #pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h 25 | #pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h 26 | #pragma clang diagnostic ignored "-Wold-style-cast" 27 | #endif 28 | 29 | //----------------------------------------------------------------------------- 30 | // Forward Declarations 31 | //----------------------------------------------------------------------------- 32 | 33 | struct ImRect; 34 | struct ImGuiColMod; 35 | struct ImGuiStyleMod; 36 | struct ImGuiGroupData; 37 | struct ImGuiSimpleColumns; 38 | struct ImGuiDrawContext; 39 | struct ImGuiTextEditState; 40 | struct ImGuiIniData; 41 | struct ImGuiMouseCursorData; 42 | struct ImGuiPopupRef; 43 | struct ImGuiWindow; 44 | 45 | typedef int ImGuiLayoutType; // enum ImGuiLayoutType_ 46 | typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_ 47 | typedef int ImGuiTreeNodeFlags; // enum ImGuiTreeNodeFlags_ 48 | typedef int ImGuiSliderFlags; // enum ImGuiSliderFlags_ 49 | 50 | //------------------------------------------------------------------------- 51 | // STB libraries 52 | //------------------------------------------------------------------------- 53 | 54 | namespace ImGuiStb 55 | { 56 | 57 | #undef STB_TEXTEDIT_STRING 58 | #undef STB_TEXTEDIT_CHARTYPE 59 | #define STB_TEXTEDIT_STRING ImGuiTextEditState 60 | #define STB_TEXTEDIT_CHARTYPE ImWchar 61 | #define STB_TEXTEDIT_GETWIDTH_NEWLINE -1.0f 62 | #include "stb_textedit.h" 63 | 64 | } // namespace ImGuiStb 65 | 66 | //----------------------------------------------------------------------------- 67 | // Context 68 | //----------------------------------------------------------------------------- 69 | 70 | extern IMGUI_API ImGuiContext* GImGui; // current implicit ImGui context pointer 71 | 72 | //----------------------------------------------------------------------------- 73 | // Helpers 74 | //----------------------------------------------------------------------------- 75 | 76 | #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) 77 | #define IM_PI 3.14159265358979323846f 78 | 79 | // Helpers: UTF-8 <> wchar 80 | IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count 81 | IMGUI_API int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count 82 | IMGUI_API int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count 83 | IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) 84 | IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points 85 | 86 | // Helpers: Misc 87 | IMGUI_API ImU32 ImHash(const void* data, int data_size, ImU32 seed = 0); // Pass data_size==0 for zero-terminated strings 88 | IMGUI_API void* ImLoadFileToMemory(const char* filename, const char* file_open_mode, int* out_file_size = NULL, int padding_bytes = 0); 89 | IMGUI_API bool ImIsPointInTriangle(const ImVec2& p, const ImVec2& a, const ImVec2& b, const ImVec2& c); 90 | static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; } 91 | static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } 92 | 93 | // Helpers: String 94 | IMGUI_API int ImStricmp(const char* str1, const char* str2); 95 | IMGUI_API int ImStrnicmp(const char* str1, const char* str2, int count); 96 | IMGUI_API char* ImStrdup(const char* str); 97 | IMGUI_API int ImStrlenW(const ImWchar* str); 98 | IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line 99 | IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end); 100 | IMGUI_API int ImFormatString(char* buf, int buf_size, const char* fmt, ...) IM_PRINTFARGS(3); 101 | IMGUI_API int ImFormatStringV(char* buf, int buf_size, const char* fmt, va_list args); 102 | 103 | // Helpers: Math 104 | // We are keeping those not leaking to the user by default, in the case the user has implicit cast operators between ImVec2 and its own types (when IM_VEC2_CLASS_EXTRA is defined) 105 | #ifdef IMGUI_DEFINE_MATH_OPERATORS 106 | static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); } 107 | static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); } 108 | static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); } 109 | static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); } 110 | static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); } 111 | static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); } 112 | static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } 113 | static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } 114 | static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } 115 | static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } 116 | static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-rhs.w); } 117 | #endif 118 | 119 | static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; } 120 | static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; } 121 | static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; } 122 | static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; } 123 | static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); } 124 | static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); } 125 | static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; } 126 | static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; } 127 | static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); } 128 | static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; } 129 | static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; } 130 | static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); } 131 | static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; } 132 | static inline float ImLengthSqr(const ImVec4& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; } 133 | static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = lhs.x*lhs.x + lhs.y*lhs.y; if (d > 0.0f) return 1.0f / sqrtf(d); return fail_value; } 134 | static inline float ImFloor(float f) { return (float)(int)f; } 135 | static inline ImVec2 ImFloor(ImVec2 v) { return ImVec2((float)(int)v.x, (float)(int)v.y); } 136 | 137 | // We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax. 138 | // Defining a custom placement new() with a dummy parameter allows us to bypass including which on some platforms complains when user has disabled exceptions. 139 | #ifdef IMGUI_DEFINE_PLACEMENT_NEW 140 | struct ImPlacementNewDummy {}; 141 | inline void* operator new(size_t, ImPlacementNewDummy, void* ptr) { return ptr; } 142 | inline void operator delete(void*, ImPlacementNewDummy, void*) {} 143 | #define IM_PLACEMENT_NEW(_PTR) new(ImPlacementNewDummy(), _PTR) 144 | #endif 145 | 146 | //----------------------------------------------------------------------------- 147 | // Types 148 | //----------------------------------------------------------------------------- 149 | 150 | enum ImGuiButtonFlags_ 151 | { 152 | ImGuiButtonFlags_Repeat = 1 << 0, // hold to repeat 153 | ImGuiButtonFlags_PressedOnClickRelease = 1 << 1, // (default) return pressed on click+release on same item (default if no PressedOn** flag is set) 154 | ImGuiButtonFlags_PressedOnClick = 1 << 2, // return pressed on click (default requires click+release) 155 | ImGuiButtonFlags_PressedOnRelease = 1 << 3, // return pressed on release (default requires click+release) 156 | ImGuiButtonFlags_PressedOnDoubleClick = 1 << 4, // return pressed on double-click (default requires click+release) 157 | ImGuiButtonFlags_FlattenChilds = 1 << 5, // allow interaction even if a child window is overlapping 158 | ImGuiButtonFlags_DontClosePopups = 1 << 6, // disable automatically closing parent popup on press 159 | ImGuiButtonFlags_Disabled = 1 << 7, // disable interaction 160 | ImGuiButtonFlags_AlignTextBaseLine = 1 << 8, // vertically align button to match text baseline - ButtonEx() only 161 | ImGuiButtonFlags_NoKeyModifiers = 1 << 9, // disable interaction if a key modifier is held 162 | ImGuiButtonFlags_AllowOverlapMode = 1 << 10 // require previous frame HoveredId to either match id or be null before being usable 163 | }; 164 | 165 | enum ImGuiSliderFlags_ 166 | { 167 | ImGuiSliderFlags_Vertical = 1 << 0 168 | }; 169 | 170 | enum ImGuiSelectableFlagsPrivate_ 171 | { 172 | // NB: need to be in sync with last value of ImGuiSelectableFlags_ 173 | ImGuiSelectableFlags_Menu = 1 << 3, 174 | ImGuiSelectableFlags_MenuItem = 1 << 4, 175 | ImGuiSelectableFlags_Disabled = 1 << 5, 176 | ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6 177 | }; 178 | 179 | // FIXME: this is in development, not exposed/functional as a generic feature yet. 180 | enum ImGuiLayoutType_ 181 | { 182 | ImGuiLayoutType_Vertical, 183 | ImGuiLayoutType_Horizontal 184 | }; 185 | 186 | enum ImGuiPlotType 187 | { 188 | ImGuiPlotType_Lines, 189 | ImGuiPlotType_Histogram 190 | }; 191 | 192 | enum ImGuiDataType 193 | { 194 | ImGuiDataType_Int, 195 | ImGuiDataType_Float 196 | }; 197 | 198 | // 2D axis aligned bounding-box 199 | // NB: we can't rely on ImVec2 math operators being available here 200 | struct IMGUI_API ImRect 201 | { 202 | ImVec2 Min; // Upper-left 203 | ImVec2 Max; // Lower-right 204 | 205 | ImRect() : Min(FLT_MAX,FLT_MAX), Max(-FLT_MAX,-FLT_MAX) {} 206 | ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} 207 | ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} 208 | ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} 209 | 210 | ImVec2 GetCenter() const { return ImVec2((Min.x+Max.x)*0.5f, (Min.y+Max.y)*0.5f); } 211 | ImVec2 GetSize() const { return ImVec2(Max.x-Min.x, Max.y-Min.y); } 212 | float GetWidth() const { return Max.x-Min.x; } 213 | float GetHeight() const { return Max.y-Min.y; } 214 | ImVec2 GetTL() const { return Min; } // Top-left 215 | ImVec2 GetTR() const { return ImVec2(Max.x, Min.y); } // Top-right 216 | ImVec2 GetBL() const { return ImVec2(Min.x, Max.y); } // Bottom-left 217 | ImVec2 GetBR() const { return Max; } // Bottom-right 218 | bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; } 219 | bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x < Max.x && r.Max.y < Max.y; } 220 | bool Overlaps(const ImRect& r) const { return r.Min.y < Max.y && r.Max.y > Min.y && r.Min.x < Max.x && r.Max.x > Min.x; } 221 | void Add(const ImVec2& rhs) { if (Min.x > rhs.x) Min.x = rhs.x; if (Min.y > rhs.y) Min.y = rhs.y; if (Max.x < rhs.x) Max.x = rhs.x; if (Max.y < rhs.y) Max.y = rhs.y; } 222 | void Add(const ImRect& rhs) { if (Min.x > rhs.Min.x) Min.x = rhs.Min.x; if (Min.y > rhs.Min.y) Min.y = rhs.Min.y; if (Max.x < rhs.Max.x) Max.x = rhs.Max.x; if (Max.y < rhs.Max.y) Max.y = rhs.Max.y; } 223 | void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; } 224 | void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; } 225 | void Reduce(const ImVec2& amount) { Min.x += amount.x; Min.y += amount.y; Max.x -= amount.x; Max.y -= amount.y; } 226 | void Clip(const ImRect& clip) { if (Min.x < clip.Min.x) Min.x = clip.Min.x; if (Min.y < clip.Min.y) Min.y = clip.Min.y; if (Max.x > clip.Max.x) Max.x = clip.Max.x; if (Max.y > clip.Max.y) Max.y = clip.Max.y; } 227 | void Floor() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; } 228 | ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const 229 | { 230 | if (!on_edge && Contains(p)) 231 | return p; 232 | if (p.x > Max.x) p.x = Max.x; 233 | else if (p.x < Min.x) p.x = Min.x; 234 | if (p.y > Max.y) p.y = Max.y; 235 | else if (p.y < Min.y) p.y = Min.y; 236 | return p; 237 | } 238 | }; 239 | 240 | // Stacked color modifier, backup of modified data so we can restore it 241 | struct ImGuiColMod 242 | { 243 | ImGuiCol Col; 244 | ImVec4 PreviousValue; 245 | }; 246 | 247 | // Stacked style modifier, backup of modified data so we can restore it 248 | struct ImGuiStyleMod 249 | { 250 | ImGuiStyleVar Var; 251 | ImVec2 PreviousValue; 252 | }; 253 | 254 | // Stacked data for BeginGroup()/EndGroup() 255 | struct ImGuiGroupData 256 | { 257 | ImVec2 BackupCursorPos; 258 | ImVec2 BackupCursorMaxPos; 259 | float BackupIndentX; 260 | float BackupCurrentLineHeight; 261 | float BackupCurrentLineTextBaseOffset; 262 | float BackupLogLinePosY; 263 | bool AdvanceCursor; 264 | }; 265 | 266 | // Per column data for Columns() 267 | struct ImGuiColumnData 268 | { 269 | float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) 270 | //float IndentX; 271 | }; 272 | 273 | // Simple column measurement currently used for MenuItem() only. This is very short-sighted/throw-away code and NOT a generic helper. 274 | struct IMGUI_API ImGuiSimpleColumns 275 | { 276 | int Count; 277 | float Spacing; 278 | float Width, NextWidth; 279 | float Pos[8], NextWidths[8]; 280 | 281 | ImGuiSimpleColumns(); 282 | void Update(int count, float spacing, bool clear); 283 | float DeclColumns(float w0, float w1, float w2); 284 | float CalcExtraSpace(float avail_w); 285 | }; 286 | 287 | // Internal state of the currently focused/edited text input box 288 | struct IMGUI_API ImGuiTextEditState 289 | { 290 | ImGuiID Id; // widget id owning the text state 291 | ImVector Text; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer. 292 | ImVector InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered) 293 | ImVector TempTextBuffer; 294 | int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format. 295 | int BufSizeA; // end-user buffer size 296 | float ScrollX; 297 | ImGuiStb::STB_TexteditState StbState; 298 | float CursorAnim; 299 | bool CursorFollow; 300 | bool SelectedAllMouseLock; 301 | 302 | ImGuiTextEditState() { memset(this, 0, sizeof(*this)); } 303 | void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking 304 | void CursorClamp() { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); } 305 | bool HasSelection() const { return StbState.select_start != StbState.select_end; } 306 | void ClearSelection() { StbState.select_start = StbState.select_end = StbState.cursor; } 307 | void SelectAll() { StbState.select_start = 0; StbState.select_end = CurLenW; StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; } 308 | void OnKeyPressed(int key); 309 | }; 310 | 311 | // Data saved in imgui.ini file 312 | struct ImGuiIniData 313 | { 314 | char* Name; 315 | ImGuiID Id; 316 | ImVec2 Pos; 317 | ImVec2 Size; 318 | bool Collapsed; 319 | }; 320 | 321 | // Mouse cursor data (used when io.MouseDrawCursor is set) 322 | struct ImGuiMouseCursorData 323 | { 324 | ImGuiMouseCursor Type; 325 | ImVec2 HotOffset; 326 | ImVec2 Size; 327 | ImVec2 TexUvMin[2]; 328 | ImVec2 TexUvMax[2]; 329 | }; 330 | 331 | // Storage for current popup stack 332 | struct ImGuiPopupRef 333 | { 334 | ImGuiID PopupId; // Set on OpenPopup() 335 | ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() 336 | ImGuiWindow* ParentWindow; // Set on OpenPopup() 337 | ImGuiID ParentMenuSet; // Set on OpenPopup() 338 | ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup 339 | 340 | ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; } 341 | }; 342 | 343 | // Main state for ImGui 344 | struct ImGuiContext 345 | { 346 | bool Initialized; 347 | ImGuiIO IO; 348 | ImGuiStyle Style; 349 | ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() 350 | float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize() 351 | float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters. 352 | ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvWhitePixel 353 | 354 | float Time; 355 | int FrameCount; 356 | int FrameCountEnded; 357 | int FrameCountRendered; 358 | ImVector Windows; 359 | ImVector WindowsSortBuffer; 360 | ImGuiWindow* CurrentWindow; // Being drawn into 361 | ImVector CurrentWindowStack; 362 | ImGuiWindow* FocusedWindow; // Will catch keyboard inputs 363 | ImGuiWindow* HoveredWindow; // Will catch mouse inputs 364 | ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only) 365 | ImGuiID HoveredId; // Hovered widget 366 | bool HoveredIdAllowOverlap; 367 | ImGuiID HoveredIdPreviousFrame; 368 | ImGuiID ActiveId; // Active widget 369 | ImGuiID ActiveIdPreviousFrame; 370 | bool ActiveIdIsAlive; 371 | bool ActiveIdIsJustActivated; // Set at the time of activation for one frame 372 | bool ActiveIdAllowOverlap; // Set only by active widget 373 | ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) 374 | ImGuiWindow* ActiveIdWindow; 375 | ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. 376 | ImGuiID MovedWindowMoveId; // == MovedWindow->RootWindow->MoveId 377 | ImVector Settings; // .ini Settings 378 | float SettingsDirtyTimer; // Save .ini Settings on disk when time reaches zero 379 | ImVector ColorModifiers; // Stack for PushStyleColor()/PopStyleColor() 380 | ImVector StyleModifiers; // Stack for PushStyleVar()/PopStyleVar() 381 | ImVector FontStack; // Stack for PushFont()/PopFont() 382 | ImVector OpenPopupStack; // Which popups are open (persistent) 383 | ImVector CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame) 384 | 385 | // Storage for SetNexWindow** and SetNextTreeNode*** functions 386 | ImVec2 SetNextWindowPosVal; 387 | ImVec2 SetNextWindowSizeVal; 388 | ImVec2 SetNextWindowContentSizeVal; 389 | bool SetNextWindowCollapsedVal; 390 | ImGuiSetCond SetNextWindowPosCond; 391 | ImGuiSetCond SetNextWindowSizeCond; 392 | ImGuiSetCond SetNextWindowContentSizeCond; 393 | ImGuiSetCond SetNextWindowCollapsedCond; 394 | ImRect SetNextWindowSizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true 395 | ImGuiSizeConstraintCallback SetNextWindowSizeConstraintCallback; 396 | void* SetNextWindowSizeConstraintCallbackUserData; 397 | bool SetNextWindowSizeConstraint; 398 | bool SetNextWindowFocus; 399 | bool SetNextTreeNodeOpenVal; 400 | ImGuiSetCond SetNextTreeNodeOpenCond; 401 | 402 | // Render 403 | ImDrawData RenderDrawData; // Main ImDrawData instance to pass render information to the user 404 | ImVector RenderDrawLists[3]; 405 | float ModalWindowDarkeningRatio; 406 | ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays 407 | ImGuiMouseCursor MouseCursor; 408 | ImGuiMouseCursorData MouseCursorData[ImGuiMouseCursor_Count_]; 409 | 410 | // Widget state 411 | ImGuiTextEditState InputTextState; 412 | ImFont InputTextPasswordFont; 413 | ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. 414 | ImGuiStorage ColorEditModeStorage; // Store user selection of color edit mode 415 | float DragCurrentValue; // Currently dragged value, always float, not rounded by end-user precision settings 416 | ImVec2 DragLastMouseDelta; 417 | float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio 418 | float DragSpeedScaleSlow; 419 | float DragSpeedScaleFast; 420 | ImVec2 ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? 421 | char Tooltip[1024]; 422 | char* PrivateClipboard; // If no custom clipboard handler is defined 423 | ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor 424 | 425 | // Logging 426 | bool LogEnabled; 427 | FILE* LogFile; // If != NULL log to stdout/ file 428 | ImGuiTextBuffer* LogClipboard; // Else log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators. 429 | int LogStartDepth; 430 | int LogAutoExpandMaxDepth; 431 | 432 | // Misc 433 | float FramerateSecPerFrame[120]; // calculate estimate of framerate for user 434 | int FramerateSecPerFrameIdx; 435 | float FramerateSecPerFrameAccum; 436 | int CaptureMouseNextFrame; // explicit capture via CaptureInputs() sets those flags 437 | int CaptureKeyboardNextFrame; 438 | char TempBuffer[1024*3+1]; // temporary text buffer 439 | 440 | ImGuiContext() 441 | { 442 | Initialized = false; 443 | Font = NULL; 444 | FontSize = FontBaseSize = 0.0f; 445 | FontTexUvWhitePixel = ImVec2(0.0f, 0.0f); 446 | 447 | Time = 0.0f; 448 | FrameCount = 0; 449 | FrameCountEnded = FrameCountRendered = -1; 450 | CurrentWindow = NULL; 451 | FocusedWindow = NULL; 452 | HoveredWindow = NULL; 453 | HoveredRootWindow = NULL; 454 | HoveredId = 0; 455 | HoveredIdAllowOverlap = false; 456 | HoveredIdPreviousFrame = 0; 457 | ActiveId = 0; 458 | ActiveIdPreviousFrame = 0; 459 | ActiveIdIsAlive = false; 460 | ActiveIdIsJustActivated = false; 461 | ActiveIdAllowOverlap = false; 462 | ActiveIdClickOffset = ImVec2(-1,-1); 463 | ActiveIdWindow = NULL; 464 | MovedWindow = NULL; 465 | MovedWindowMoveId = 0; 466 | SettingsDirtyTimer = 0.0f; 467 | 468 | SetNextWindowPosVal = ImVec2(0.0f, 0.0f); 469 | SetNextWindowSizeVal = ImVec2(0.0f, 0.0f); 470 | SetNextWindowCollapsedVal = false; 471 | SetNextWindowPosCond = 0; 472 | SetNextWindowSizeCond = 0; 473 | SetNextWindowContentSizeCond = 0; 474 | SetNextWindowCollapsedCond = 0; 475 | SetNextWindowFocus = false; 476 | SetNextWindowSizeConstraintCallback = NULL; 477 | SetNextWindowSizeConstraintCallbackUserData = NULL; 478 | SetNextTreeNodeOpenVal = false; 479 | SetNextTreeNodeOpenCond = 0; 480 | 481 | ScalarAsInputTextId = 0; 482 | DragCurrentValue = 0.0f; 483 | DragLastMouseDelta = ImVec2(0.0f, 0.0f); 484 | DragSpeedDefaultRatio = 1.0f / 100.0f; 485 | DragSpeedScaleSlow = 0.01f; 486 | DragSpeedScaleFast = 10.0f; 487 | ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f); 488 | memset(Tooltip, 0, sizeof(Tooltip)); 489 | PrivateClipboard = NULL; 490 | OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f); 491 | 492 | ModalWindowDarkeningRatio = 0.0f; 493 | OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging 494 | MouseCursor = ImGuiMouseCursor_Arrow; 495 | memset(MouseCursorData, 0, sizeof(MouseCursorData)); 496 | 497 | LogEnabled = false; 498 | LogFile = NULL; 499 | LogClipboard = NULL; 500 | LogStartDepth = 0; 501 | LogAutoExpandMaxDepth = 2; 502 | 503 | memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); 504 | FramerateSecPerFrameIdx = 0; 505 | FramerateSecPerFrameAccum = 0.0f; 506 | CaptureMouseNextFrame = CaptureKeyboardNextFrame = -1; 507 | memset(TempBuffer, 0, sizeof(TempBuffer)); 508 | } 509 | }; 510 | 511 | // Transient per-window data, reset at the beginning of the frame 512 | // FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiDrawContext is quite tenuous and could be reconsidered. 513 | struct IMGUI_API ImGuiDrawContext 514 | { 515 | ImVec2 CursorPos; 516 | ImVec2 CursorPosPrevLine; 517 | ImVec2 CursorStartPos; 518 | ImVec2 CursorMaxPos; // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame 519 | float CurrentLineHeight; 520 | float CurrentLineTextBaseOffset; 521 | float PrevLineHeight; 522 | float PrevLineTextBaseOffset; 523 | float LogLinePosY; 524 | int TreeDepth; 525 | ImGuiID LastItemId; 526 | ImRect LastItemRect; 527 | bool LastItemHoveredAndUsable; // Item rectangle is hovered, and its window is currently interactable with (not blocked by a popup preventing access to the window) 528 | bool LastItemHoveredRect; // Item rectangle is hovered, but its window may or not be currently interactable with (might be blocked by a popup preventing access to the window) 529 | bool MenuBarAppending; 530 | float MenuBarOffsetX; 531 | ImVector ChildWindows; 532 | ImGuiStorage* StateStorage; 533 | ImGuiLayoutType LayoutType; 534 | 535 | // We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings. 536 | float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window 537 | float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f] 538 | bool AllowKeyboardFocus; // == AllowKeyboardFocusStack.back() [empty == true] 539 | bool ButtonRepeat; // == ButtonRepeatStack.back() [empty == false] 540 | ImVector ItemWidthStack; 541 | ImVector TextWrapPosStack; 542 | ImVector AllowKeyboardFocusStack; 543 | ImVector ButtonRepeatStack; 544 | ImVectorGroupStack; 545 | ImGuiColorEditMode ColorEditMode; 546 | int StackSizesBackup[6]; // Store size of various stacks for asserting 547 | 548 | float IndentX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) 549 | float GroupOffsetX; 550 | float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. 551 | int ColumnsCurrent; 552 | int ColumnsCount; 553 | float ColumnsMinX; 554 | float ColumnsMaxX; 555 | float ColumnsStartPosY; 556 | float ColumnsCellMinY; 557 | float ColumnsCellMaxY; 558 | bool ColumnsShowBorders; 559 | ImGuiID ColumnsSetId; 560 | ImVector ColumnsData; 561 | 562 | ImGuiDrawContext() 563 | { 564 | CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f); 565 | CurrentLineHeight = PrevLineHeight = 0.0f; 566 | CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f; 567 | LogLinePosY = -1.0f; 568 | TreeDepth = 0; 569 | LastItemId = 0; 570 | LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f); 571 | LastItemHoveredAndUsable = LastItemHoveredRect = false; 572 | MenuBarAppending = false; 573 | MenuBarOffsetX = 0.0f; 574 | StateStorage = NULL; 575 | LayoutType = ImGuiLayoutType_Vertical; 576 | ItemWidth = 0.0f; 577 | ButtonRepeat = false; 578 | AllowKeyboardFocus = true; 579 | TextWrapPos = -1.0f; 580 | ColorEditMode = ImGuiColorEditMode_RGB; 581 | memset(StackSizesBackup, 0, sizeof(StackSizesBackup)); 582 | 583 | IndentX = 0.0f; 584 | ColumnsOffsetX = 0.0f; 585 | ColumnsCurrent = 0; 586 | ColumnsCount = 1; 587 | ColumnsMinX = ColumnsMaxX = 0.0f; 588 | ColumnsStartPosY = 0.0f; 589 | ColumnsCellMinY = ColumnsCellMaxY = 0.0f; 590 | ColumnsShowBorders = true; 591 | ColumnsSetId = 0; 592 | } 593 | }; 594 | 595 | // Windows data 596 | struct IMGUI_API ImGuiWindow 597 | { 598 | char* Name; 599 | ImGuiID ID; // == ImHash(Name) 600 | ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_ 601 | int IndexWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0. 602 | ImVec2 PosFloat; 603 | ImVec2 Pos; // Position rounded-up to nearest pixel 604 | ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) 605 | ImVec2 SizeFull; // Size when non collapsed 606 | ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame 607 | ImVec2 SizeContentsExplicit; // Size of contents explicitly set by the user via SetNextWindowContentSize() 608 | ImRect ContentsRegionRect; // Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis 609 | ImVec2 WindowPadding; // Window padding at the time of begin. We need to lock it, in particular manipulation of the ShowBorder would have an effect 610 | ImGuiID MoveId; // == window->GetID("#MOVE") 611 | ImVec2 Scroll; 612 | ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change) 613 | ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered 614 | bool ScrollbarX, ScrollbarY; 615 | ImVec2 ScrollbarSizes; 616 | float BorderSize; 617 | bool Active; // Set to true on Begin() 618 | bool WasActive; 619 | bool Accessed; // Set to true when any widget access the current window 620 | bool Collapsed; // Set when collapsing window to become only title-bar 621 | bool SkipItems; // == Visible && !Collapsed 622 | int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs) 623 | ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling) 624 | int AutoFitFramesX, AutoFitFramesY; 625 | bool AutoFitOnlyGrows; 626 | int AutoPosLastDirection; 627 | int HiddenFrames; 628 | int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call will succeed with this particular flag. 629 | int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call will succeed with this particular flag. 630 | int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call will succeed with this particular flag. 631 | bool SetWindowPosCenterWanted; 632 | 633 | ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame 634 | ImVector IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack 635 | ImRect ClipRect; // = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2. 636 | ImRect WindowRectClipped; // = WindowRect just after setup in Begin(). == window->Rect() for root window. 637 | int LastFrameActive; 638 | float ItemWidthDefault; 639 | ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items 640 | ImGuiStorage StateStorage; 641 | float FontWindowScale; // Scale multiplier per-window 642 | ImDrawList* DrawList; 643 | ImGuiWindow* RootWindow; // If we are a child window, this is pointing to the first non-child parent window. Else point to ourself. 644 | ImGuiWindow* RootNonPopupWindow; // If we are a child window, this is pointing to the first non-child non-popup parent window. Else point to ourself. 645 | ImGuiWindow* ParentWindow; // If we are a child window, this is pointing to our parent window. Else point to NULL. 646 | 647 | // Navigation / Focus 648 | int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister() 649 | int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through) 650 | int FocusIdxAllRequestCurrent; // Item being requested for focus 651 | int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus 652 | int FocusIdxAllRequestNext; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame) 653 | int FocusIdxTabRequestNext; // " 654 | 655 | public: 656 | ImGuiWindow(const char* name); 657 | ~ImGuiWindow(); 658 | 659 | ImGuiID GetID(const char* str, const char* str_end = NULL); 660 | ImGuiID GetID(const void* ptr); 661 | ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL); 662 | 663 | ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); } 664 | float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; } 665 | float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; } 666 | ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); } 667 | float MenuBarHeight() const { return (Flags & ImGuiWindowFlags_MenuBar) ? CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; } 668 | ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); } 669 | }; 670 | 671 | //----------------------------------------------------------------------------- 672 | // Internal API 673 | // No guarantee of forward compatibility here. 674 | //----------------------------------------------------------------------------- 675 | 676 | namespace ImGui 677 | { 678 | // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window) 679 | // If this ever crash because g.CurrentWindow is NULL it means that either 680 | // - ImGui::NewFrame() has never been called, which is illegal. 681 | // - You are calling ImGui functions after ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal. 682 | inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; } 683 | inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->Accessed = true; return g.CurrentWindow; } 684 | IMGUI_API ImGuiWindow* GetParentWindow(); 685 | IMGUI_API ImGuiWindow* FindWindowByName(const char* name); 686 | IMGUI_API void FocusWindow(ImGuiWindow* window); 687 | 688 | IMGUI_API void EndFrame(); // Ends the ImGui frame. Automatically called by Render()! you most likely don't need to ever call that yourself directly. If you don't need to render you can call EndFrame() but you'll have wasted CPU already. If you don't need to render, don't create any windows instead! 689 | 690 | IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); 691 | IMGUI_API void SetHoveredID(ImGuiID id); 692 | IMGUI_API void KeepAliveID(ImGuiID id); 693 | 694 | IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f); 695 | IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f); 696 | IMGUI_API bool ItemAdd(const ImRect& bb, const ImGuiID* id); 697 | IMGUI_API bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged); 698 | IMGUI_API bool IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs = false); 699 | IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, bool is_active, bool tab_stop = true); // Return true if focus is requested 700 | IMGUI_API void FocusableItemUnregister(ImGuiWindow* window); 701 | IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y); 702 | IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x); 703 | 704 | IMGUI_API void OpenPopupEx(const char* str_id, bool reopen_existing); 705 | 706 | // NB: All position are in absolute pixels coordinates (not window coordinates) 707 | // FIXME: All those functions are a mess and needs to be refactored into something decent. Avoid use outside of imgui.cpp! 708 | // We need: a sort of symbol library, preferably baked into font atlas when possible + decent text rendering helpers. 709 | IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); 710 | IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); 711 | IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align = ImGuiAlign_Default, const ImVec2* clip_min = NULL, const ImVec2* clip_max = NULL); 712 | IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); 713 | IMGUI_API void RenderCollapseTriangle(ImVec2 pos, bool is_open, float scale = 1.0f, bool shadow = false); 714 | IMGUI_API void RenderBullet(ImVec2 pos); 715 | IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col); 716 | IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. 717 | 718 | IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0); 719 | IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0); 720 | IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius); 721 | 722 | IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags = 0); 723 | IMGUI_API bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power); 724 | IMGUI_API bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format); 725 | 726 | IMGUI_API bool DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power); 727 | IMGUI_API bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power); 728 | IMGUI_API bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format); 729 | 730 | IMGUI_API bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); 731 | IMGUI_API bool InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags); 732 | IMGUI_API bool InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags); 733 | IMGUI_API bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags); 734 | IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision); 735 | 736 | IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL); 737 | IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging 738 | IMGUI_API void TreePushRawID(ImGuiID id); 739 | 740 | IMGUI_API void PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size); 741 | 742 | IMGUI_API int ParseFormatPrecision(const char* fmt, int default_value); 743 | IMGUI_API float RoundScalar(float value, int decimal_precision); 744 | 745 | } // namespace ImGui 746 | 747 | #ifdef __clang__ 748 | #pragma clang diagnostic pop 749 | #endif 750 | 751 | #ifdef _MSC_VER 752 | #pragma warning (pop) 753 | #endif 754 | -------------------------------------------------------------------------------- /csgo/imgui/stb_rect_pack.h: -------------------------------------------------------------------------------- 1 | // stb_rect_pack.h - v0.08 - public domain - rectangle packing 2 | // Sean Barrett 2014 3 | // 4 | // Useful for e.g. packing rectangular textures into an atlas. 5 | // Does not do rotation. 6 | // 7 | // Not necessarily the awesomest packing method, but better than 8 | // the totally naive one in stb_truetype (which is primarily what 9 | // this is meant to replace). 10 | // 11 | // Has only had a few tests run, may have issues. 12 | // 13 | // More docs to come. 14 | // 15 | // No memory allocations; uses qsort() and assert() from stdlib. 16 | // Can override those by defining STBRP_SORT and STBRP_ASSERT. 17 | // 18 | // This library currently uses the Skyline Bottom-Left algorithm. 19 | // 20 | // Please note: better rectangle packers are welcome! Please 21 | // implement them to the same API, but with a different init 22 | // function. 23 | // 24 | // Credits 25 | // 26 | // Library 27 | // Sean Barrett 28 | // Minor features 29 | // Martins Mozeiko 30 | // Bugfixes / warning fixes 31 | // Jeremy Jaussaud 32 | // 33 | // Version history: 34 | // 35 | // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) 36 | // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) 37 | // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort 38 | // 0.05: added STBRP_ASSERT to allow replacing assert 39 | // 0.04: fixed minor bug in STBRP_LARGE_RECTS support 40 | // 0.01: initial release 41 | // 42 | // LICENSE 43 | // 44 | // This software is in the public domain. Where that dedication is not 45 | // recognized, you are granted a perpetual, irrevocable license to copy, 46 | // distribute, and modify this file as you see fit. 47 | 48 | ////////////////////////////////////////////////////////////////////////////// 49 | // 50 | // INCLUDE SECTION 51 | // 52 | 53 | #ifndef STB_INCLUDE_STB_RECT_PACK_H 54 | #define STB_INCLUDE_STB_RECT_PACK_H 55 | 56 | #define STB_RECT_PACK_VERSION 1 57 | 58 | #ifdef STBRP_STATIC 59 | #define STBRP_DEF static 60 | #else 61 | #define STBRP_DEF extern 62 | #endif 63 | 64 | #ifdef __cplusplus 65 | extern "C" { 66 | #endif 67 | 68 | typedef struct stbrp_context stbrp_context; 69 | typedef struct stbrp_node stbrp_node; 70 | typedef struct stbrp_rect stbrp_rect; 71 | 72 | #ifdef STBRP_LARGE_RECTS 73 | typedef int stbrp_coord; 74 | #else 75 | typedef unsigned short stbrp_coord; 76 | #endif 77 | 78 | STBRP_DEF void stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); 79 | // Assign packed locations to rectangles. The rectangles are of type 80 | // 'stbrp_rect' defined below, stored in the array 'rects', and there 81 | // are 'num_rects' many of them. 82 | // 83 | // Rectangles which are successfully packed have the 'was_packed' flag 84 | // set to a non-zero value and 'x' and 'y' store the minimum location 85 | // on each axis (i.e. bottom-left in cartesian coordinates, top-left 86 | // if you imagine y increasing downwards). Rectangles which do not fit 87 | // have the 'was_packed' flag set to 0. 88 | // 89 | // You should not try to access the 'rects' array from another thread 90 | // while this function is running, as the function temporarily reorders 91 | // the array while it executes. 92 | // 93 | // To pack into another rectangle, you need to call stbrp_init_target 94 | // again. To continue packing into the same rectangle, you can call 95 | // this function again. Calling this multiple times with multiple rect 96 | // arrays will probably produce worse packing results than calling it 97 | // a single time with the full rectangle array, but the option is 98 | // available. 99 | 100 | struct stbrp_rect 101 | { 102 | // reserved for your use: 103 | int id; 104 | 105 | // input: 106 | stbrp_coord w, h; 107 | 108 | // output: 109 | stbrp_coord x, y; 110 | int was_packed; // non-zero if valid packing 111 | 112 | }; // 16 bytes, nominally 113 | 114 | 115 | STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes); 116 | // Initialize a rectangle packer to: 117 | // pack a rectangle that is 'width' by 'height' in dimensions 118 | // using temporary storage provided by the array 'nodes', which is 'num_nodes' long 119 | // 120 | // You must call this function every time you start packing into a new target. 121 | // 122 | // There is no "shutdown" function. The 'nodes' memory must stay valid for 123 | // the following stbrp_pack_rects() call (or calls), but can be freed after 124 | // the call (or calls) finish. 125 | // 126 | // Note: to guarantee best results, either: 127 | // 1. make sure 'num_nodes' >= 'width' 128 | // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1' 129 | // 130 | // If you don't do either of the above things, widths will be quantized to multiples 131 | // of small integers to guarantee the algorithm doesn't run out of temporary storage. 132 | // 133 | // If you do #2, then the non-quantized algorithm will be used, but the algorithm 134 | // may run out of temporary storage and be unable to pack some rectangles. 135 | 136 | STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem); 137 | // Optionally call this function after init but before doing any packing to 138 | // change the handling of the out-of-temp-memory scenario, described above. 139 | // If you call init again, this will be reset to the default (false). 140 | 141 | 142 | STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic); 143 | // Optionally select which packing heuristic the library should use. Different 144 | // heuristics will produce better/worse results for different data sets. 145 | // If you call init again, this will be reset to the default. 146 | 147 | enum 148 | { 149 | STBRP_HEURISTIC_Skyline_default=0, 150 | STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default, 151 | STBRP_HEURISTIC_Skyline_BF_sortHeight 152 | }; 153 | 154 | 155 | ////////////////////////////////////////////////////////////////////////////// 156 | // 157 | // the details of the following structures don't matter to you, but they must 158 | // be visible so you can handle the memory allocations for them 159 | 160 | struct stbrp_node 161 | { 162 | stbrp_coord x,y; 163 | stbrp_node *next; 164 | }; 165 | 166 | struct stbrp_context 167 | { 168 | int width; 169 | int height; 170 | int align; 171 | int init_mode; 172 | int heuristic; 173 | int num_nodes; 174 | stbrp_node *active_head; 175 | stbrp_node *free_head; 176 | stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2' 177 | }; 178 | 179 | #ifdef __cplusplus 180 | } 181 | #endif 182 | 183 | #endif 184 | 185 | ////////////////////////////////////////////////////////////////////////////// 186 | // 187 | // IMPLEMENTATION SECTION 188 | // 189 | 190 | #ifdef STB_RECT_PACK_IMPLEMENTATION 191 | #ifndef STBRP_SORT 192 | #include 193 | #define STBRP_SORT qsort 194 | #endif 195 | 196 | #ifndef STBRP_ASSERT 197 | #include 198 | #define STBRP_ASSERT assert 199 | #endif 200 | 201 | enum 202 | { 203 | STBRP__INIT_skyline = 1 204 | }; 205 | 206 | STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic) 207 | { 208 | switch (context->init_mode) { 209 | case STBRP__INIT_skyline: 210 | STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight); 211 | context->heuristic = heuristic; 212 | break; 213 | default: 214 | STBRP_ASSERT(0); 215 | } 216 | } 217 | 218 | STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem) 219 | { 220 | if (allow_out_of_mem) 221 | // if it's ok to run out of memory, then don't bother aligning them; 222 | // this gives better packing, but may fail due to OOM (even though 223 | // the rectangles easily fit). @TODO a smarter approach would be to only 224 | // quantize once we've hit OOM, then we could get rid of this parameter. 225 | context->align = 1; 226 | else { 227 | // if it's not ok to run out of memory, then quantize the widths 228 | // so that num_nodes is always enough nodes. 229 | // 230 | // I.e. num_nodes * align >= width 231 | // align >= width / num_nodes 232 | // align = ceil(width/num_nodes) 233 | 234 | context->align = (context->width + context->num_nodes-1) / context->num_nodes; 235 | } 236 | } 237 | 238 | STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) 239 | { 240 | int i; 241 | #ifndef STBRP_LARGE_RECTS 242 | STBRP_ASSERT(width <= 0xffff && height <= 0xffff); 243 | #endif 244 | 245 | for (i=0; i < num_nodes-1; ++i) 246 | nodes[i].next = &nodes[i+1]; 247 | nodes[i].next = NULL; 248 | context->init_mode = STBRP__INIT_skyline; 249 | context->heuristic = STBRP_HEURISTIC_Skyline_default; 250 | context->free_head = &nodes[0]; 251 | context->active_head = &context->extra[0]; 252 | context->width = width; 253 | context->height = height; 254 | context->num_nodes = num_nodes; 255 | stbrp_setup_allow_out_of_mem(context, 0); 256 | 257 | // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly) 258 | context->extra[0].x = 0; 259 | context->extra[0].y = 0; 260 | context->extra[0].next = &context->extra[1]; 261 | context->extra[1].x = (stbrp_coord) width; 262 | #ifdef STBRP_LARGE_RECTS 263 | context->extra[1].y = (1<<30); 264 | #else 265 | context->extra[1].y = 65535; 266 | #endif 267 | context->extra[1].next = NULL; 268 | } 269 | 270 | // find minimum y position if it starts at x1 271 | static int stbrp__skyline_find_min_y(stbrp_context *, stbrp_node *first, int x0, int width, int *pwaste) 272 | { 273 | //(void)c; 274 | stbrp_node *node = first; 275 | int x1 = x0 + width; 276 | int min_y, visited_width, waste_area; 277 | STBRP_ASSERT(first->x <= x0); 278 | 279 | #if 0 280 | // skip in case we're past the node 281 | while (node->next->x <= x0) 282 | ++node; 283 | #else 284 | STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency 285 | #endif 286 | 287 | STBRP_ASSERT(node->x <= x0); 288 | 289 | min_y = 0; 290 | waste_area = 0; 291 | visited_width = 0; 292 | while (node->x < x1) { 293 | if (node->y > min_y) { 294 | // raise min_y higher. 295 | // we've accounted for all waste up to min_y, 296 | // but we'll now add more waste for everything we've visted 297 | waste_area += visited_width * (node->y - min_y); 298 | min_y = node->y; 299 | // the first time through, visited_width might be reduced 300 | if (node->x < x0) 301 | visited_width += node->next->x - x0; 302 | else 303 | visited_width += node->next->x - node->x; 304 | } else { 305 | // add waste area 306 | int under_width = node->next->x - node->x; 307 | if (under_width + visited_width > width) 308 | under_width = width - visited_width; 309 | waste_area += under_width * (min_y - node->y); 310 | visited_width += under_width; 311 | } 312 | node = node->next; 313 | } 314 | 315 | *pwaste = waste_area; 316 | return min_y; 317 | } 318 | 319 | typedef struct 320 | { 321 | int x,y; 322 | stbrp_node **prev_link; 323 | } stbrp__findresult; 324 | 325 | static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height) 326 | { 327 | int best_waste = (1<<30), best_x, best_y = (1 << 30); 328 | stbrp__findresult fr; 329 | stbrp_node **prev, *node, *tail, **best = NULL; 330 | 331 | // align to multiple of c->align 332 | width = (width + c->align - 1); 333 | width -= width % c->align; 334 | STBRP_ASSERT(width % c->align == 0); 335 | 336 | node = c->active_head; 337 | prev = &c->active_head; 338 | while (node->x + width <= c->width) { 339 | int y,waste; 340 | y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste); 341 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL 342 | // bottom left 343 | if (y < best_y) { 344 | best_y = y; 345 | best = prev; 346 | } 347 | } else { 348 | // best-fit 349 | if (y + height <= c->height) { 350 | // can only use it if it first vertically 351 | if (y < best_y || (y == best_y && waste < best_waste)) { 352 | best_y = y; 353 | best_waste = waste; 354 | best = prev; 355 | } 356 | } 357 | } 358 | prev = &node->next; 359 | node = node->next; 360 | } 361 | 362 | best_x = (best == NULL) ? 0 : (*best)->x; 363 | 364 | // if doing best-fit (BF), we also have to try aligning right edge to each node position 365 | // 366 | // e.g, if fitting 367 | // 368 | // ____________________ 369 | // |____________________| 370 | // 371 | // into 372 | // 373 | // | | 374 | // | ____________| 375 | // |____________| 376 | // 377 | // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned 378 | // 379 | // This makes BF take about 2x the time 380 | 381 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) { 382 | tail = c->active_head; 383 | node = c->active_head; 384 | prev = &c->active_head; 385 | // find first node that's admissible 386 | while (tail->x < width) 387 | tail = tail->next; 388 | while (tail) { 389 | int xpos = tail->x - width; 390 | int y,waste; 391 | STBRP_ASSERT(xpos >= 0); 392 | // find the left position that matches this 393 | while (node->next->x <= xpos) { 394 | prev = &node->next; 395 | node = node->next; 396 | } 397 | STBRP_ASSERT(node->next->x > xpos && node->x <= xpos); 398 | y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); 399 | if (y + height < c->height) { 400 | if (y <= best_y) { 401 | if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { 402 | best_x = xpos; 403 | STBRP_ASSERT(y <= best_y); 404 | best_y = y; 405 | best_waste = waste; 406 | best = prev; 407 | } 408 | } 409 | } 410 | tail = tail->next; 411 | } 412 | } 413 | 414 | fr.prev_link = best; 415 | fr.x = best_x; 416 | fr.y = best_y; 417 | return fr; 418 | } 419 | 420 | static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height) 421 | { 422 | // find best position according to heuristic 423 | stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height); 424 | stbrp_node *node, *cur; 425 | 426 | // bail if: 427 | // 1. it failed 428 | // 2. the best node doesn't fit (we don't always check this) 429 | // 3. we're out of memory 430 | if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) { 431 | res.prev_link = NULL; 432 | return res; 433 | } 434 | 435 | // on success, create new node 436 | node = context->free_head; 437 | node->x = (stbrp_coord) res.x; 438 | node->y = (stbrp_coord) (res.y + height); 439 | 440 | context->free_head = node->next; 441 | 442 | // insert the new node into the right starting point, and 443 | // let 'cur' point to the remaining nodes needing to be 444 | // stiched back in 445 | 446 | cur = *res.prev_link; 447 | if (cur->x < res.x) { 448 | // preserve the existing one, so start testing with the next one 449 | stbrp_node *next = cur->next; 450 | cur->next = node; 451 | cur = next; 452 | } else { 453 | *res.prev_link = node; 454 | } 455 | 456 | // from here, traverse cur and free the nodes, until we get to one 457 | // that shouldn't be freed 458 | while (cur->next && cur->next->x <= res.x + width) { 459 | stbrp_node *next = cur->next; 460 | // move the current node to the free list 461 | cur->next = context->free_head; 462 | context->free_head = cur; 463 | cur = next; 464 | } 465 | 466 | // stitch the list back in 467 | node->next = cur; 468 | 469 | if (cur->x < res.x + width) 470 | cur->x = (stbrp_coord) (res.x + width); 471 | 472 | #ifdef _DEBUG 473 | cur = context->active_head; 474 | while (cur->x < context->width) { 475 | STBRP_ASSERT(cur->x < cur->next->x); 476 | cur = cur->next; 477 | } 478 | STBRP_ASSERT(cur->next == NULL); 479 | 480 | { 481 | stbrp_node *L1 = NULL, *L2 = NULL; 482 | int count=0; 483 | cur = context->active_head; 484 | while (cur) { 485 | L1 = cur; 486 | cur = cur->next; 487 | ++count; 488 | } 489 | cur = context->free_head; 490 | while (cur) { 491 | L2 = cur; 492 | cur = cur->next; 493 | ++count; 494 | } 495 | STBRP_ASSERT(count == context->num_nodes+2); 496 | } 497 | #endif 498 | 499 | return res; 500 | } 501 | 502 | static int rect_height_compare(const void *a, const void *b) 503 | { 504 | stbrp_rect *p = (stbrp_rect *) a; 505 | stbrp_rect *q = (stbrp_rect *) b; 506 | if (p->h > q->h) 507 | return -1; 508 | if (p->h < q->h) 509 | return 1; 510 | return (p->w > q->w) ? -1 : (p->w < q->w); 511 | } 512 | 513 | static int rect_width_compare(const void *a, const void *b) 514 | { 515 | stbrp_rect *p = (stbrp_rect *) a; 516 | stbrp_rect *q = (stbrp_rect *) b; 517 | if (p->w > q->w) 518 | return -1; 519 | if (p->w < q->w) 520 | return 1; 521 | return (p->h > q->h) ? -1 : (p->h < q->h); 522 | } 523 | 524 | static int rect_original_order(const void *a, const void *b) 525 | { 526 | stbrp_rect *p = (stbrp_rect *) a; 527 | stbrp_rect *q = (stbrp_rect *) b; 528 | return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); 529 | } 530 | 531 | #ifdef STBRP_LARGE_RECTS 532 | #define STBRP__MAXVAL 0xffffffff 533 | #else 534 | #define STBRP__MAXVAL 0xffff 535 | #endif 536 | 537 | STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) 538 | { 539 | int i; 540 | 541 | // we use the 'was_packed' field internally to allow sorting/unsorting 542 | for (i=0; i < num_rects; ++i) { 543 | rects[i].was_packed = i; 544 | #ifndef STBRP_LARGE_RECTS 545 | STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff); 546 | #endif 547 | } 548 | 549 | // sort according to heuristic 550 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare); 551 | 552 | for (i=0; i < num_rects; ++i) { 553 | if (rects[i].w == 0 || rects[i].h == 0) { 554 | rects[i].x = rects[i].y = 0; // empty rect needs no space 555 | } else { 556 | stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); 557 | if (fr.prev_link) { 558 | rects[i].x = (stbrp_coord) fr.x; 559 | rects[i].y = (stbrp_coord) fr.y; 560 | } else { 561 | rects[i].x = rects[i].y = STBRP__MAXVAL; 562 | } 563 | } 564 | } 565 | 566 | // unsort 567 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); 568 | 569 | // set was_packed flags 570 | for (i=0; i < num_rects; ++i) 571 | rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL); 572 | } 573 | #endif 574 | -------------------------------------------------------------------------------- /csgo/inButtons.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define IN_ATTACK (1 << 0) 4 | #define IN_JUMP (1 << 1) 5 | #define IN_DUCK (1 << 2) 6 | #define IN_FORWARD (1 << 3) 7 | #define IN_BACK (1 << 4) 8 | #define IN_USE (1 << 5) 9 | #define IN_CANCEL (1 << 6) 10 | #define IN_LEFT (1 << 7) 11 | #define IN_RIGHT (1 << 8) 12 | #define IN_MOVELEFT (1 << 9) 13 | #define IN_MOVERIGHT (1 << 10) 14 | #define IN_ATTACK2 (1 << 11) 15 | #define IN_RUN (1 << 12) 16 | #define IN_RELOAD (1 << 13) 17 | #define IN_ALT1 (1 << 14) 18 | #define IN_ALT2 (1 << 15) 19 | #define IN_SCORE (1 << 16) 20 | #define IN_SPEED (1 << 17) 21 | #define IN_WALK (1 << 18) 22 | #define IN_ZOOM (1 << 19) 23 | #define IN_WEAPON1 (1 << 20) 24 | #define IN_WEAPON2 (1 << 21) 25 | #define IN_BULLRUSH (1 << 22) 26 | #define IN_GRENADE1 (1 << 23) 27 | #define IN_GRENADE2 (1 << 24) -------------------------------------------------------------------------------- /csgo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Hooks.h" 4 | 5 | void MainThread() { 6 | OutputDebugString(L"MainThread"); 7 | Hooks::setupHooks(); 8 | } 9 | 10 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { 11 | if (fdwReason == DLL_PROCESS_ATTACH) { 12 | CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)MainThread, NULL, NULL, NULL); 13 | } 14 | 15 | return TRUE; 16 | } 17 | -------------------------------------------------------------------------------- /csgo/mask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define CONTENTS_EMPTY 0 // No contents 4 | 5 | #define CONTENTS_SOLID 0x1 // an eye is never valid in a solid 6 | #define CONTENTS_WINDOW 0x2 // translucent, but not watery (glass) 7 | #define CONTENTS_AUX 0x4 8 | #define CONTENTS_GRATE 0x8 // alpha-tested "grate" textures. Bullets/sight pass through, but solids don't 9 | #define CONTENTS_SLIME 0x10 10 | #define CONTENTS_WATER 0x20 11 | #define CONTENTS_BLOCKLOS 0x40 // block AI line of sight 12 | #define CONTENTS_OPAQUE 0x80 // things that cannot be seen through (may be non-solid though) 13 | #define LAST_VISIBLE_CONTENTS CONTENTS_OPAQUE 14 | 15 | #define ALL_VISIBLE_CONTENTS (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1)) 16 | 17 | #define CONTENTS_TESTFOGVOLUME 0x100 18 | #define CONTENTS_UNUSED 0x200 19 | 20 | // unused 21 | // NOTE: If it's visible, grab from the top + update LAST_VISIBLE_CONTENTS 22 | // if not visible, then grab from the bottom. 23 | // CONTENTS_OPAQUE + SURF_NODRAW count as CONTENTS_OPAQUE (shadow-casting toolsblocklight textures) 24 | #define CONTENTS_BLOCKLIGHT 0x400 25 | 26 | #define CONTENTS_TEAM1 0x800 // per team contents used to differentiate collisions 27 | #define CONTENTS_TEAM2 0x1000 // between players and objects on different teams 28 | 29 | // ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW 30 | #define CONTENTS_IGNORE_NODRAW_OPAQUE 0x2000 31 | 32 | // hits entities which are MOVETYPE_PUSH (doors, plats, etc.) 33 | #define CONTENTS_MOVEABLE 0x4000 34 | 35 | // remaining contents are non-visible, and don't eat brushes 36 | #define CONTENTS_AREAPORTAL 0x8000 37 | 38 | #define CONTENTS_PLAYERCLIP 0x10000 39 | #define CONTENTS_MONSTERCLIP 0x20000 40 | 41 | // currents can be added to any other contents, and may be mixed 42 | #define CONTENTS_CURRENT_0 0x40000 43 | #define CONTENTS_CURRENT_90 0x80000 44 | #define CONTENTS_CURRENT_180 0x100000 45 | #define CONTENTS_CURRENT_270 0x200000 46 | #define CONTENTS_CURRENT_UP 0x400000 47 | #define CONTENTS_CURRENT_DOWN 0x800000 48 | 49 | #define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity 50 | 51 | #define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game 52 | #define CONTENTS_DEBRIS 0x4000000 53 | #define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs 54 | #define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans 55 | #define CONTENTS_LADDER 0x20000000 56 | #define CONTENTS_HITBOX 0x40000000 // use accurate hitboxes on trace 57 | 58 | #define MASK_ALL (0xFFFFFFFF) 59 | // everything that is normally solid 60 | #define MASK_SOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 61 | // everything that blocks player movement 62 | #define MASK_PLAYERSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 63 | // blocks npc movement 64 | #define MASK_NPCSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 65 | // blocks fluid movement 66 | #define MASK_NPCFLUID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER) 67 | // water physics in these contents 68 | #define MASK_WATER (CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) 69 | // everything that blocks lighting 70 | #define MASK_OPAQUE (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) 71 | // everything that blocks lighting, but with monsters added. 72 | #define MASK_OPAQUE_AND_NPCS (MASK_OPAQUE|CONTENTS_MONSTER) 73 | // everything that blocks line of sight for AI 74 | #define MASK_BLOCKLOS (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_BLOCKLOS) 75 | // everything that blocks line of sight for AI plus NPCs 76 | #define MASK_BLOCKLOS_AND_NPCS (MASK_BLOCKLOS|CONTENTS_MONSTER) 77 | // everything that blocks line of sight for players 78 | #define MASK_VISIBLE (MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE) 79 | // everything that blocks line of sight for players, but with monsters added. 80 | #define MASK_VISIBLE_AND_NPCS (MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE) 81 | // bullets see these as solid 82 | #define MASK_SHOT (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) 83 | // bullets see these as solid, except monsters (world+brush only) 84 | #define MASK_SHOT_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_DEBRIS) 85 | // non-raycasted weapons see this as solid (includes grates) 86 | #define MASK_SHOT_HULL (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_GRATE) 87 | // hits solids (not grates) and passes through everything else 88 | #define MASK_SHOT_PORTAL (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER) 89 | // everything normally solid, except monsters (world+brush only) 90 | #define MASK_SOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) 91 | // everything normally solid for player movement, except monsters (world+brush only) 92 | #define MASK_PLAYERSOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_PLAYERCLIP|CONTENTS_GRATE) 93 | // everything normally solid for npc movement, except monsters (world+brush only) 94 | #define MASK_NPCSOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) 95 | // just the world, used for route rebuilding 96 | #define MASK_NPCWORLDSTATIC (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) 97 | // just the world, used for route rebuilding 98 | #define MASK_NPCWORLDSTATIC_FLUID (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP) 99 | // These are things that can split areaportals 100 | #define MASK_SPLITAREAPORTAL (CONTENTS_WATER|CONTENTS_SLIME) -------------------------------------------------------------------------------- /csgo/vmtIndexes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Client 4 | #define VMT_GETALLCLASSES 8 5 | #define VMT_HUDPROCESSINPUT 10 6 | 7 | // ClientMode 8 | #define VMT_CREATEMOVE 24 9 | 10 | // Vpanel 11 | #define VMT_GETPANELNAME 36 12 | #define VMT_PAINTTRAVERSE 41 13 | 14 | // Surface 15 | #define VMT_DRAWSETCOLOR 15 16 | #define VMT_DRAWFILLEDRECT 16 17 | #define VMT_DRAWOUTLINEDRECT 18 18 | #define VMT_DRAWLINE 19 19 | #define VMT_DRAWSETTEXTFONT 23 20 | #define VMT_DRAWSETTEXTCOLOR 25 21 | #define VMT_DRAWSETTEXTPOS 26 22 | #define VMT_DRAWPRINTTEXT 28 23 | #define VMT_CREATEFONT 71 24 | #define VMT_SETFONTGLYPHSET 72 25 | 26 | // ClientEntList 27 | #define VMT_GETCLIENTENTITY 3 28 | #define VMT_GETCLIENTENTITYFROMHANDLE 4 29 | #define VMT_NUMBEROFENTITIES 5 30 | #define VMT_GETHIGHESTENTITYINDEX 6 31 | 32 | // Engine 33 | #define VMT_GETSCREENSIZE 5 34 | #define VMT_GETPLAYERINFO 8 35 | #define VMT_GETLOCALPLAYER 12 36 | #define VMT_SETVIEWANGLES 19 37 | #define VMT_WORLDTOSCREENMATRIX 37 38 | #define VMT_CLIENTCMDUNRESTRICTED 114 39 | 40 | // EngineTrace 41 | #define VMT_TRACERAY 5 42 | 43 | // BaseEntity 44 | #define VMT_SETUPBONES 13 45 | 46 | // D3d9Device 47 | #define VMT_ENDSCENE 42 48 | 49 | // InputSystem 50 | #define VMT_GETCURSORPOSITION 56 51 | 52 | // BaseCombatWeapon 53 | #define VMT_GETCSWPNDATA 456 -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimitriFourny/csgo-hack/cffa7d8de698edfff2d9ed99831ce4e2a07d002a/screenshot.png -------------------------------------------------------------------------------- /slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimitriFourny/csgo-hack/cffa7d8de698edfff2d9ed99831ce4e2a07d002a/slides.pdf --------------------------------------------------------------------------------