├── LICENSE ├── README.md ├── cs2-external-cheat.sln └── cs2-external-cheat ├── aimbot.cpp ├── aimbot.h ├── cheat.cpp ├── cheat.h ├── config.cpp ├── config.h ├── cs2-external-cheat.vcxproj ├── cs2-external-cheat.vcxproj.filters ├── cs2-external-cheat.vcxproj.user ├── datatypes.cpp ├── datatypes.h ├── fonts.hpp ├── gui.cpp ├── gui.h ├── imgui ├── imconfig.h ├── imgui.cpp ├── imgui.h ├── imgui_demo.cpp ├── imgui_draw.cpp ├── imgui_impl_dx11.cpp ├── imgui_impl_dx11.h ├── imgui_impl_win32.cpp ├── imgui_impl_win32.h ├── imgui_internal.h ├── imgui_tables.cpp ├── imgui_widgets.cpp ├── imstb_rectpack.h ├── imstb_textedit.h └── imstb_truetype.h ├── json.h ├── main.cpp ├── math.cpp ├── math.h ├── memory.h ├── offsets.cpp ├── offsets.h ├── offsetsDump.h ├── options.h ├── overlay.cpp ├── overlay.h ├── visuals.cpp └── visuals.h /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Nikita 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 📌 Introduction 2 | 3 | Cs2 external legit cheat without WPM based on ImGui and DirectX, i made it for educational purposes, use it only with bots or you will get ban. 4 | It's only reading and using mouse_event to move mouse, also drawing with imgui. 5 | 6 | ![изображение](https://github.com/user-attachments/assets/b941007a-22d8-451b-9a95-27103dc6706a) 7 | 8 | 9 | # ⚡ Features 10 | - Aimbot 11 | - Triggerbot 12 | - Esp 13 | - Esp preview 14 | - 2D boxes 15 | - 3D boxes 16 | - Skeleton 17 | - Names 18 | - Health 19 | - Team visible 20 | - Config system 21 | - Auto update offsets 22 | 23 | # ⚒ How-to-use 24 | Open cs2, start game, then start cheat and wait till initialization. 25 | Press Insert to open/close menu, End to close cheat. 26 | Config files are in Documents/Vireless path. 27 | 28 | # 💾 Build 29 | Release x64 30 | -------------------------------------------------------------------------------- /cs2-external-cheat.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.34931.43 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cs2-external-cheat", "cs2-external-cheat\cs2-external-cheat.vcxproj", "{60DD80F0-30FA-4F04-8808-436FEFB5DB58}" 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 | {60DD80F0-30FA-4F04-8808-436FEFB5DB58}.Debug|x64.ActiveCfg = Debug|x64 17 | {60DD80F0-30FA-4F04-8808-436FEFB5DB58}.Debug|x64.Build.0 = Debug|x64 18 | {60DD80F0-30FA-4F04-8808-436FEFB5DB58}.Debug|x86.ActiveCfg = Debug|Win32 19 | {60DD80F0-30FA-4F04-8808-436FEFB5DB58}.Debug|x86.Build.0 = Debug|Win32 20 | {60DD80F0-30FA-4F04-8808-436FEFB5DB58}.Release|x64.ActiveCfg = Release|x64 21 | {60DD80F0-30FA-4F04-8808-436FEFB5DB58}.Release|x64.Build.0 = Release|x64 22 | {60DD80F0-30FA-4F04-8808-436FEFB5DB58}.Release|x86.ActiveCfg = Release|Win32 23 | {60DD80F0-30FA-4F04-8808-436FEFB5DB58}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {C68FECDC-1EBE-4DCA-882B-926683EC99EA} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /cs2-external-cheat/aimbot.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lityrgia/cs2-external-cheat/ad54f8af1ca7180d01f5bdb53cfaefc3443b2525/cs2-external-cheat/aimbot.cpp -------------------------------------------------------------------------------- /cs2-external-cheat/aimbot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void startAimbot(game::CSplayerPawn& localPlayerPawn, Vec2& targetScreenPos); 4 | void drawFovCircle(float radius); 5 | void startTriggerbot(game::CSplayerPawn& localPlayer); 6 | Vec2 getClosestBoneScrPos(std::vector& bones); -------------------------------------------------------------------------------- /cs2-external-cheat/cheat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "datatypes.h" 4 | #include "cheat.h" 5 | #include "options.h" 6 | #include "visuals.h" 7 | #include "offsets.h" 8 | #include "memory.h" 9 | #include "math.h" 10 | #include "aimbot.h" 11 | 12 | void startCheat() { 13 | game::CSplayerController localPlayerController; 14 | localPlayerController.controller = mem.Read(offsets.localController); 15 | 16 | game::CSplayerPawn localPlayerPawn; 17 | localPlayerPawn.pawn = mem.Read(offsets.localPawn); 18 | localPlayerPawn.getTeamNum(); 19 | localPlayerPawn.getViewAngles(); 20 | localPlayerPawn.getFeetPos(); 21 | localPlayerPawn.getHeadPos(); 22 | localPlayerPawn.getIndex(); 23 | 24 | Matrix viewMatrix = mem.Read(offsets.viewMatrix); 25 | 26 | Vec2 targetScreenPosFin{0,0}; 27 | 28 | int closestToCrosshair{ 999999 }; 29 | float fov{ 300 }; 30 | 31 | if (menu::bFOV) { 32 | drawFovCircle(options::radiusFOV); 33 | } 34 | 35 | offsets.getListEntry(); 36 | 37 | for (short i = 1; i < 32; ++i) { 38 | game::CSplayerController entityController; 39 | game::CSplayerPawn entityPawn; 40 | 41 | entityController.num = i; 42 | entityController.getController(); 43 | 44 | if (entityController.controller == 0 || entityController.controller == localPlayerController.controller) continue; 45 | 46 | entityPawn.value = entityController.get_CSPlayerPawn(); 47 | entityPawn.getPawn(); 48 | entityPawn.getPlayerHealth(); 49 | 50 | if (entityPawn.playerHealth <= 0) continue; 51 | 52 | entityPawn.updateBones(viewMatrix); 53 | 54 | entityPawn.getTeamNum(); 55 | entityPawn.getSpotted(); 56 | entityPawn.getFeetPos(); 57 | entityPawn.getHeadPos(); 58 | entityPawn.getViewAngles(); 59 | entityPawn.getIndex(); 60 | entityController.getName(); 61 | 62 | bool isTeammate = entityPawn.teamNum == localPlayerPawn.teamNum; 63 | 64 | if (!isTeammate && entityPawn.spotted != 0 && menu::bEnableAim) { 65 | Vec2 targetScreenPos; 66 | float distance{0}; 67 | 68 | if (options::aimingType == 1) { 69 | targetScreenPos = getClosestBoneScrPos(entityPawn.BonePosList); 70 | 71 | distance = getDistanceToCenter(targetScreenPos); 72 | 73 | } 74 | else if (options::aimingType == 0) { 75 | targetScreenPos = entityPawn.BonePosList[head].ScreenPos; 76 | 77 | distance = getDistanceToCenter(targetScreenPos); 78 | } 79 | 80 | if (distance < options::radiusFOV && distance < closestToCrosshair) 81 | { 82 | targetScreenPosFin = targetScreenPos; 83 | closestToCrosshair = distance; 84 | } 85 | } 86 | 87 | if (menu::bEnableESP) { 88 | startEsp(viewMatrix, entityPawn, entityController.name, isTeammate); 89 | } 90 | } 91 | 92 | if (menu::bEnableTriggerbot) { 93 | startTriggerbot(localPlayerPawn); 94 | } 95 | 96 | int aimButton = options::aimButton; 97 | bool isAimingEnabled = menu::bEnableAim && targetScreenPosFin.x != 0 && targetScreenPosFin.y != 0; 98 | 99 | if (isAimingEnabled) { 100 | if (aimButton == 0) { 101 | startAimbot(localPlayerPawn, targetScreenPosFin); 102 | } 103 | else { 104 | int mouseButton = (aimButton == 1) ? VK_LBUTTON : VK_RBUTTON; 105 | 106 | if (GetAsyncKeyState(mouseButton) & 0x8000) { 107 | startAimbot(localPlayerPawn, targetScreenPosFin); 108 | } 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /cs2-external-cheat/cheat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "datatypes.h" 3 | #include "imgui/imgui.h" 4 | 5 | void drawLines(Vec2& end, ImVec4 color); 6 | void startCheat(); -------------------------------------------------------------------------------- /cs2-external-cheat/config.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "json.h" 8 | #include "config.h" 9 | #include "options.h" 10 | 11 | using json = nlohmann::json; 12 | 13 | void Config::getDocumentsFolderPath() { 14 | char path[MAX_PATH]; 15 | if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, path))) { 16 | this->configPath = std::string(path); 17 | } 18 | else { 19 | std::cout << "[cheat]: Can't get documents path" << '\n'; 20 | } 21 | } 22 | 23 | bool Config::createConfigFolder() { 24 | HRESULT result = SHCreateDirectoryExA(NULL, (this->configPath + "\\Vireless").c_str(), NULL); 25 | this->configPath = configPath + "\\Vireless"; 26 | 27 | if (result == ERROR_SUCCESS) { 28 | std::cout << "[cheat]: Config folder created " << '\n'; 29 | return true; 30 | } 31 | else if (result == ERROR_ALREADY_EXISTS) { 32 | std::cout << "[cheat]: Config folder already created" << '\n'; 33 | return true; 34 | } 35 | else { 36 | std::cout << "[cheat]: Can't create config folder, try disabling your antivirus or adding a cheat to the exceptions " << '\n'; 37 | return false; 38 | } 39 | } 40 | 41 | bool Config::downloadOffsetsFromGithub() { 42 | // Ñîçäàåì êîìàíäó äëÿ âûçîâà PowerShell ñêðèïòà 43 | std::string urlOffsets = "https://raw.githubusercontent.com/a2x/cs2-dumper/main/output/offsets.json"; 44 | std::string commandOffsets = "Invoke-WebRequest -Uri \"" + urlOffsets + "\" -OutFile \"" + this->offsetsPath + "\\offsetsDump.json" + "\""; 45 | 46 | std::string urlClient = "https://raw.githubusercontent.com/a2x/cs2-dumper/main/output/client_dll.json"; 47 | std::string commandClient = "Invoke-WebRequest -Uri \"" + urlClient + "\" -OutFile \"" + this->offsetsPath + "\\clientDump.json" + "\""; 48 | 49 | std::string fullCommand = "powershell -ExecutionPolicy Bypass -Command \"" + commandOffsets + "\""; 50 | 51 | int result = std::system(fullCommand.c_str()); 52 | 53 | fullCommand = "powershell -ExecutionPolicy Bypass -Command \"" + commandClient + "\""; 54 | 55 | result = std::system(fullCommand.c_str()); 56 | 57 | if (result != 0) { 58 | std::cerr << "[cheat]: Failed to download offsets " << '\n'; 59 | return false; 60 | } 61 | 62 | return true; 63 | } 64 | 65 | bool Config::createOffsetsFolder(){ 66 | HRESULT result = SHCreateDirectoryExA(NULL, (this->configPath + "\\Offsets").c_str(), NULL); 67 | 68 | if (result == ERROR_SUCCESS) { 69 | std::cout << "[cheat]: Offsets folder created " << '\n'; 70 | } 71 | else if (result == ERROR_ALREADY_EXISTS) { 72 | std::cout << "[cheat]: Offsets folder already created" << '\n'; 73 | } 74 | else { 75 | std::cout << "[cheat]: Can't create offsets folder " << '\n'; 76 | return false; 77 | } 78 | 79 | this->offsetsPath = this->configPath + "\\Offsets"; 80 | 81 | std::ofstream clientDump(this->offsetsPath + "\\clientDump.json"); 82 | std::ofstream offsetsDump(this->offsetsPath + "\\offsetsDump.json"); 83 | 84 | if (clientDump.is_open() && offsetsDump.is_open()) { 85 | clientDump.close(); 86 | offsetsDump.close(); 87 | } 88 | 89 | return true; 90 | } 91 | 92 | void Config::getConfigFiles() { 93 | try { 94 | if (!std::filesystem::exists(this->configPath) || !std::filesystem::is_directory(this->configPath)) { 95 | std::cerr << "[cheat]: Path doesn't exist " << configPath << std::endl; 96 | return; 97 | } 98 | 99 | for (const auto& entry : std::filesystem::directory_iterator(this->configPath)) { 100 | if (entry.is_regular_file() && entry.path().extension() == ".json") { 101 | this->configFiles.push_back(entry.path().filename().string()); 102 | } 103 | } 104 | } 105 | catch (const std::filesystem::filesystem_error& e) { 106 | std::cerr << "[cheat]: Error with filesystem " << e.what() << '\n'; 107 | } 108 | catch (const std::exception& e) { 109 | std::cerr << "[cheat]: Unable to loop through config files " << e.what() << '\n'; 110 | } 111 | } 112 | 113 | void Config::vectorStrToChar() { 114 | for (const auto& file : config.configFiles) { 115 | this->configNames.push_back(file.c_str()); 116 | } 117 | } 118 | 119 | void Config::update(){ 120 | this->configFiles.clear(); 121 | this->configNames.clear(); 122 | this->getConfigFiles(); 123 | this->vectorStrToChar(); 124 | } 125 | 126 | json imvec4ToJson(const ImVec4& color) { 127 | return json{ {"r", color.x}, {"g", color.y}, {"b", color.z}, {"a", color.w} }; 128 | } 129 | 130 | bool Config::saveConfig(std::string configName) { 131 | json config; 132 | 133 | config["name"] = "Vireless"; 134 | config["version"] = "1.0"; 135 | config["config-name"] = "test"; 136 | config["menu"] = { 137 | {"Aim", menu::bEnableAim}, 138 | {"FOV", menu::bFOV}, 139 | {"Smooth", menu::bSmooth}, 140 | {"Triggerbot", menu::bEnableTriggerbot}, 141 | {"Esp", menu::bEnableESP}, 142 | {"2D-box", menu::bEnableBox2D}, 143 | {"2D-box-lines", menu::bEnableBox2DLines}, 144 | {"2D-box-fill", menu::bEnableBox2DFill}, 145 | {"3D-box", menu::bEnableBox3D}, 146 | {"3D-box-anim", menu::bEnableBox3DAnim}, 147 | {"Name", menu::bEnableName}, 148 | {"Health", menu::bEnableHealth}, 149 | {"Snaplines", menu::bEnableLines}, 150 | {"Skeleton", menu::bEnableSkeleton}, 151 | {"Direction", menu::bEnableDirection}, 152 | {"Team-visible", menu::bTeamVisible}, 153 | {"Toggle-button", menu::bToggleButton}, 154 | {"End-button", menu::bEndButton}, 155 | }; 156 | config["options"] = { 157 | {"Radius-fov", options::radiusFOV}, 158 | {"Aiming-type", options::aimingType}, 159 | {"Triggerbot-delay", options::triggerbotDelay}, 160 | {"Smoothness", options::smoothness}, 161 | {"2d-box-rounding", options::box2DRounding}, 162 | 163 | {"2d-box-lines-color", imvec4ToJson(options::boxes2DLinesColor)}, 164 | {"2d-box-fill-color", imvec4ToJson(options::boxes2DFillColor)}, 165 | {"2d-box-lines-team-color", imvec4ToJson(options::boxes2DLinesColorTeam)}, 166 | {"2d-box-fill-team-color", imvec4ToJson(options::boxes2DFillColorTeam)}, 167 | 168 | {"3d-box-lines-color", imvec4ToJson(options::boxes3DLinesColor)}, 169 | {"3d-box-lines-team-color", imvec4ToJson(options::boxes3DLinesColorTeam)}, 170 | 171 | {"Snaplines-color-team", imvec4ToJson(options::snapLinesColorTeam)}, 172 | {"Snaplines-color", imvec4ToJson(options::snapLinesColor)}, 173 | {"Direction-color", imvec4ToJson(options::directionColor)}, 174 | {"Skeleton-color", imvec4ToJson(options::skeletonColor)}, 175 | {"Skeleton-team-color", imvec4ToJson(options::skeletonColorTeam)}, 176 | }; 177 | 178 | if (configName.empty()) { 179 | configName = "config"; 180 | } 181 | 182 | std::ofstream configFile(configPath + "\\" + configName + ".json"); 183 | 184 | if (configFile.is_open()) { 185 | configFile << config.dump(4); 186 | configFile.close(); 187 | 188 | std::cout << "[cheat]: Config " + std::string(configName) + ".json saved" << '\n'; 189 | } 190 | else { 191 | std::cout << "[cheat]: Can't save " + std::string(configName) << ".json" << '\n'; 192 | } 193 | 194 | return true; 195 | } 196 | 197 | ImVec4 jsonToImvec4(const json& j) { 198 | return ImVec4(j.at("r").get(), j.at("g").get(), j.at("b").get(), j.at("a").get()); 199 | } 200 | 201 | bool Config::loadConfig(std::string configName) { 202 | std::ifstream configFile(configPath + "\\" + configName); 203 | 204 | if (configFile.is_open()) { 205 | json config; 206 | configFile >> config; 207 | configFile.close(); 208 | 209 | menu::bEnableAim = config["menu"]["Aim"]; 210 | menu::bEnableTriggerbot = config["menu"]["Triggerbot"]; 211 | menu::bSmooth = config["menu"]["Smooth"]; 212 | menu::bFOV = config["menu"]["FOV"]; 213 | 214 | menu::bEnableESP = config["menu"]["Esp"]; 215 | menu::bEnableBox2D = config["menu"]["2D-box"]; 216 | menu::bEnableBox2DFill = config["menu"]["2D-box-fill"]; 217 | menu::bEnableBox2DLines = config["menu"]["2D-box-lines"]; 218 | menu::bEnableBox3D = config["menu"]["3D-box"]; 219 | menu::bEnableBox3DAnim = config["menu"]["3D-box-anim"]; 220 | menu::bEnableLines = config["menu"]["Snaplines"]; 221 | menu::bEnableSkeleton = config["menu"]["Skeleton"]; 222 | menu::bEnableName = config["menu"]["Name"]; 223 | menu::bEnableDirection = config["menu"]["Direction"]; 224 | menu::bEnableHealth = config["menu"]["Health"]; 225 | menu::bTeamVisible = config["menu"]["Team-visible"]; 226 | 227 | menu::bToggleButton = config["menu"]["Toggle-button"]; 228 | menu::bEndButton = config["menu"]["End-button"]; 229 | 230 | options::radiusFOV = config["options"]["Radius-fov"]; 231 | options::aimingType = config["options"]["Aiming-type"]; 232 | options::smoothness = config["options"]["Smoothness"]; 233 | options::triggerbotDelay = config["options"]["Triggerbot-delay"]; 234 | options::box2DRounding = config["options"]["2d-box-rounding"]; 235 | 236 | options::boxes2DLinesColor = jsonToImvec4(config["options"]["2d-box-lines-color"]); 237 | options::boxes2DFillColor = jsonToImvec4(config["options"]["2d-box-fill-color"]); 238 | options::boxes2DLinesColorTeam = jsonToImvec4(config["options"]["2d-box-lines-team-color"]); 239 | options::boxes2DFillColorTeam = jsonToImvec4(config["options"]["2d-box-fill-team-color"]); 240 | 241 | options::boxes3DLinesColorTeam = jsonToImvec4(config["options"]["3d-box-lines-team-color"]); 242 | options::boxes3DLinesColor = jsonToImvec4(config["options"]["3d-box-lines-color"]); 243 | 244 | options::snapLinesColorTeam = jsonToImvec4(config["options"]["Snaplines-color-team"]); 245 | options::snapLinesColor = jsonToImvec4(config["options"]["Snaplines-color"]); 246 | options::directionColor = jsonToImvec4(config["options"]["Direction-color"]); 247 | 248 | options::skeletonColor = jsonToImvec4(config["options"]["Skeleton-color"]); 249 | options::skeletonColorTeam = jsonToImvec4(config["options"]["Skeleton-team-color"]); 250 | 251 | std::cout << "[cheat]: Config " + configName + " loaded" << '\n'; 252 | } 253 | else { 254 | std::cout << "[cheat]: Can't load config " + configName << '\n'; 255 | } 256 | } 257 | 258 | bool Config::deleteConfig(std::string configName) { 259 | if (std::filesystem::remove(configPath + "\\" + configName)) { 260 | std::cout << "[cheat]: Config " << configName << " deleted" << '\n'; 261 | } 262 | else { 263 | std::cout << "[cheat]: Can't delete " << configName << '\n'; 264 | } 265 | } 266 | 267 | bool Config::initialize() { 268 | this->getDocumentsFolderPath(); 269 | if (!this->createConfigFolder()) return false; 270 | if (!this->createOffsetsFolder()) return false; 271 | this->getConfigFiles(); 272 | this->vectorStrToChar(); 273 | 274 | return true; 275 | } 276 | -------------------------------------------------------------------------------- /cs2-external-cheat/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Config { 5 | public: 6 | std::string configPath; 7 | std::string offsetsPath; 8 | std::vector configFiles; 9 | std::vector configNames; 10 | public: 11 | bool downloadOffsetsFromGithub(); 12 | bool createConfigFolder(); 13 | bool createOffsetsFolder(); 14 | void vectorStrToChar(); 15 | void getDocumentsFolderPath(); 16 | void getConfigFiles(); 17 | bool deleteConfig(std::string configName); 18 | bool loadConfig(std::string configName); 19 | bool saveConfig(std::string configName); 20 | bool initialize(); 21 | void update(); 22 | }; 23 | 24 | inline Config config; -------------------------------------------------------------------------------- /cs2-external-cheat/cs2-external-cheat.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 | 16.0 23 | Win32Proj 24 | {60dd80f0-30fa-4f04-8808-436fefb5db58} 25 | cs2externalcheat 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | $(ProjectDir)hacks;$(ProjectDir)assets;$(ProjectDir)json;$(ProjectDir)imgui;$(IncludePath) 76 | 77 | 78 | false 79 | $(ProjectDir)hacks;$(ProjectDir)assets;$(ProjectDir)json;$(ProjectDir)imgui;$(IncludePath) 80 | 81 | 82 | true 83 | $(ProjectDir)hacks;$(ProjectDir)assets;$(ProjectDir)json;$(ProjectDir)imgui;$(IncludePath) 84 | 85 | 86 | false 87 | $(ProjectDir)hacks;$(ProjectDir)assets;$(ProjectDir)json;$(ProjectDir)imgui;$(IncludePath) 88 | 89 | 90 | 91 | Level3 92 | true 93 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 94 | true 95 | stdcpp20 96 | MinSpace 97 | Default 98 | Neither 99 | false 100 | true 101 | 102 | 103 | Console 104 | true 105 | d3d11.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 106 | 107 | 108 | 109 | 110 | Level3 111 | true 112 | true 113 | true 114 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 115 | true 116 | stdcpp20 117 | MinSpace 118 | Default 119 | Neither 120 | false 121 | true 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | d3d11.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 129 | 130 | 131 | 132 | 133 | Level3 134 | true 135 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | true 137 | stdcpp20 138 | MinSpace 139 | Default 140 | Neither 141 | false 142 | true 143 | 144 | 145 | Console 146 | true 147 | d3d11.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 148 | 149 | 150 | 151 | 152 | Level3 153 | true 154 | true 155 | true 156 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 157 | true 158 | stdcpp20 159 | MinSpace 160 | Default 161 | Neither 162 | false 163 | true 164 | 165 | 166 | Console 167 | true 168 | true 169 | true 170 | d3d11.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 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 | -------------------------------------------------------------------------------- /cs2-external-cheat/cs2-external-cheat.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;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 | {186f136b-d57a-4629-b716-61adb91f5687} 18 | 19 | 20 | {6dd801e2-bd93-4657-a848-fc238c549369} 21 | 22 | 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files\imgui 29 | 30 | 31 | Header Files\imgui 32 | 33 | 34 | Header Files\imgui 35 | 36 | 37 | Header Files\imgui 38 | 39 | 40 | Header Files\imgui 41 | 42 | 43 | Header Files\imgui 44 | 45 | 46 | Header Files\imgui 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | hacks 68 | 69 | 70 | hacks 71 | 72 | 73 | hacks 74 | 75 | 76 | 77 | 78 | Header Files\imgui 79 | 80 | 81 | Header Files\imgui 82 | 83 | 84 | Header Files\imgui 85 | 86 | 87 | Header Files\imgui 88 | 89 | 90 | Header Files\imgui 91 | 92 | 93 | Header Files\imgui 94 | 95 | 96 | Header Files\imgui 97 | 98 | 99 | Header Files\imgui 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | hacks 127 | 128 | 129 | hacks 130 | 131 | 132 | hacks 133 | 134 | 135 | Header Files 136 | 137 | 138 | Header Files 139 | 140 | 141 | -------------------------------------------------------------------------------- /cs2-external-cheat/cs2-external-cheat.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /cs2-external-cheat/datatypes.cpp: -------------------------------------------------------------------------------- 1 | #include "datatypes.h" 2 | 3 | Vec3 operator- (const Vec3& first, const Vec3& second) { 4 | Vec3 temp; 5 | temp.x = first.x - second.x; 6 | temp.y = first.y - second.y; 7 | temp.z = first.z - second.z; 8 | return temp; 9 | }; 10 | 11 | Vec2 operator- (const Vec2& first, const Vec2& second) { 12 | Vec2 temp; 13 | temp.x = first.x - second.x; 14 | temp.y = first.y - second.y; 15 | return temp; 16 | }; 17 | 18 | Vec2 operator/ (const Vec2& first, const float& second) { 19 | Vec2 temp; 20 | temp.x = first.x / second; 21 | temp.y = first.y / second; 22 | return temp; 23 | }; -------------------------------------------------------------------------------- /cs2-external-cheat/datatypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imgui.h" 3 | 4 | struct Vec2 { 5 | float x; 6 | float y; 7 | 8 | Vec2() : x(0.0f), y(0.0f) {} 9 | Vec2(float x, float y) : x(x), y(y) {} 10 | Vec2(const ImVec2& imVec) : x(imVec.x), y(imVec.y) {} 11 | 12 | operator ImVec2() const { return ImVec2(x, y); } 13 | 14 | bool operator< (const Vec2& other) { 15 | if (x < other.x) return true; 16 | if (x > other.x) return false; 17 | return y < other.y; 18 | } 19 | }; 20 | 21 | struct Vec3 { 22 | float x; 23 | float y; 24 | float z; 25 | }; 26 | 27 | Vec3 operator- (const Vec3& first, const Vec3& second); 28 | Vec2 operator- (const Vec2& first, const Vec2& second); 29 | Vec2 operator/ (const Vec2& first, const float& second); 30 | 31 | struct Vec4 { 32 | float x; 33 | float y; 34 | float z; 35 | float w; 36 | }; 37 | 38 | struct BoneJointData 39 | { 40 | Vec3 Pos; 41 | char pad[0x14]; 42 | }; 43 | 44 | struct BoneJointPos 45 | { 46 | Vec3 Pos; 47 | Vec2 ScreenPos; 48 | bool IsVisible = false; 49 | }; 50 | 51 | struct Matrix { 52 | float VMatrix[16]; 53 | }; -------------------------------------------------------------------------------- /cs2-external-cheat/gui.cpp: -------------------------------------------------------------------------------- 1 | #include "gui.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "imgui/imgui.h" 10 | 11 | #include "config.h" 12 | #include "options.h" 13 | #include "fonts.hpp" 14 | 15 | void setImguiStyle() { 16 | auto& colors = ImGui::GetStyle().Colors; 17 | 18 | colors[ImGuiCol_ResizeGrip] = ImColor(0, 0, 0, 0); 19 | colors[ImGuiCol_ResizeGripActive] = ImColor(0, 0, 0, 0); 20 | colors[ImGuiCol_ResizeGripHovered] = ImColor(0, 0, 0, 0); 21 | 22 | colors[ImGuiCol_Button] = ImColor(0, 0, 0, 0); 23 | colors[ImGuiCol_ButtonActive] = ImColor(255, 122, 0, 255); 24 | colors[ImGuiCol_ButtonHovered] = ImColor(255, 140, 0, 255); 25 | 26 | colors[ImGuiCol_SliderGrab] = ImColor(16, 24, 32, 255); 27 | colors[ImGuiCol_SliderGrabActive] = ImColor(16, 24, 32, 255); 28 | 29 | colors[ImGuiCol_CheckMark] = ImColor(0, 0, 0, 255); 30 | 31 | colors[ImGuiCol_FrameBg] = ImColor(255, 255, 255); 32 | colors[ImGuiCol_FrameBgActive] = ImColor(255, 255, 255); 33 | colors[ImGuiCol_FrameBgHovered] = ImColor(255, 255, 255); 34 | 35 | colors[ImGuiCol_PopupBg] = ImColor(255, 255, 255, 255); 36 | 37 | colors[ImGuiCol_WindowBg] = ImColor(16, 24, 32, 255); 38 | 39 | colors[ImGuiCol_TitleBg] = ImColor(16, 24, 32, 255); 40 | colors[ImGuiCol_TitleBgActive] = ImColor(16, 24, 32, 255); 41 | colors[ImGuiCol_TitleBgCollapsed] = ImColor(16, 24, 32, 255); 42 | 43 | ImGuiStyle& style = ImGui::GetStyle(); 44 | 45 | style.WindowBorderSize = 0.0f; 46 | style.ChildBorderSize = 0.0f; 47 | style.FramePadding = ImVec2(0, 0); 48 | style.WindowPadding = ImVec2(0, 0); 49 | style.ItemSpacing = ImVec2(0, 0); 50 | style.WindowRounding = 5.f; 51 | style.FrameRounding = 4.0f; 52 | style.GrabMinSize = 9.f; 53 | style.GrabRounding = 100.f; 54 | } 55 | 56 | void DrawLine(ImColor color, float thickness, std::string direction) { 57 | ImDrawList* drawList = ImGui::GetWindowDrawList(); 58 | ImVec2 windowPos = ImGui::GetWindowPos(); 59 | ImVec2 windowSize = ImGui::GetWindowSize(); 60 | ImVec2 lineStart; 61 | ImVec2 lineEnd; 62 | 63 | if (direction == "up") { 64 | lineStart = ImVec2(windowPos.x, windowPos.y); 65 | lineEnd = ImVec2(windowPos.x + windowSize.x - 1, windowPos.y); 66 | } 67 | else if (direction == "down") { 68 | lineStart = ImVec2(windowPos.x, windowPos.y + windowSize.y); 69 | lineEnd = ImVec2(windowPos.x + windowSize.x - 1, windowPos.y + windowSize.y); 70 | } 71 | else if (direction == "right") { 72 | lineStart = ImVec2(windowPos.x + windowSize.x - 1, windowPos.y); 73 | lineEnd = ImVec2(windowPos.x + windowSize.x - 1, windowPos.y + windowSize.y); 74 | } 75 | else if (direction == "left") { 76 | lineStart = ImVec2(windowPos.x, windowPos.y); 77 | lineEnd = ImVec2(windowPos.x, windowPos.y + windowSize.y); 78 | } 79 | else { 80 | return; 81 | } 82 | 83 | drawList->AddLine(lineStart, lineEnd, color, thickness); 84 | } 85 | 86 | void ShowColorPickerButton(ImVec4* color, int id) { 87 | ImGui::PushID(id); 88 | 89 | ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 1)); 90 | ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(0, 0, 0, 1)); 91 | ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(0, 0, 0, 1)); 92 | 93 | if (ImGui::ColorButton("ColorButton", *color)) { 94 | ImGui::OpenPopup("ColorPickerPopup"); 95 | } 96 | 97 | if (ImGui::BeginPopup("ColorPickerPopup")) { 98 | ImGui::ColorPicker4("##picker", (float*)color, ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview); 99 | ImGui::EndPopup(); 100 | } 101 | 102 | ImGui::PopStyleColor(3); 103 | ImGui::PopID(); 104 | } 105 | 106 | void CenteredText(const char* text) { 107 | ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, 0.0f); 108 | ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); 109 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); 110 | 111 | ImVec2 windowSize = ImGui::GetWindowSize(); 112 | ImVec2 textSize = ImGui::CalcTextSize(text); 113 | float x = (windowSize.x - textSize.x) * 0.5f; 114 | ImGui::SetCursorPosX(x); 115 | ImGui::Text("%s", text); 116 | 117 | ImGui::PopStyleVar(3); 118 | } 119 | 120 | bool ToggleButton(const char* str_id, bool* v) { 121 | ImVec2 p = ImGui::GetCursorScreenPos(); 122 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 123 | 124 | float height = ImGui::GetFrameHeight(); 125 | float width = height * 1.55f; 126 | float radius = height * 0.50f; 127 | 128 | ImGui::InvisibleButton(str_id, ImVec2(width, height)); 129 | if (ImGui::IsItemClicked()) 130 | *v = !*v; 131 | 132 | ImU32 col_bg = *v ? IM_COL32(255, 140, 0, 255) : IM_COL32(255, 255, 255, 255); 133 | ImU32 circle_bg = *v ? IM_COL32(255, 255, 255, 255) : IM_COL32(16, 24, 32, 255); 134 | 135 | draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, height * 0.5f); 136 | draw_list->AddCircleFilled(ImVec2(*v ? (p.x + width - radius) : (p.x + radius), p.y + radius), radius - 1.5f, circle_bg); 137 | 138 | return *v; 139 | } 140 | 141 | inline ImFont* iconsFont = nullptr; 142 | inline ImFont* largeFont = nullptr; 143 | 144 | ImVec2 menuSize(600, 500); 145 | ImVec2 buttonSize(140, 40); 146 | ImColor separatorsColor(255, 140, 0, 255); 147 | ImVec2 paddings(0.f, 15.f); 148 | 149 | int selectedConfigIndex = -1; 150 | std::string selectedConfig; 151 | 152 | bool snaplinessettings = false; 153 | bool box2dsettings = false; 154 | bool box3dsettings = false; 155 | bool skeletonsettings = false; 156 | 157 | char configName[256] = ""; 158 | 159 | static std::string keyName = "Press a key"; 160 | bool waitingForToggleKey = false; 161 | bool waitingForEndKey = false; 162 | 163 | bool keyPressed = false; 164 | 165 | static int selectedTab = 0; // 0: Aim, 1: ESP, 2: Config, 3: Settings 166 | 167 | const char* aimingTypes[] = { "Head", "Nearest Bone" }; 168 | const char* aimbotButtons[] = { "Auto", "Left button", "Right button"}; 169 | 170 | void SetupFonts() { 171 | static const ImWchar iconRanges[]{ ICON_MIN_FA, ICON_MAX_FA, 0 }; 172 | 173 | ImGuiIO& io = ImGui::GetIO(); 174 | io.IniFilename = nullptr; 175 | io.LogFilename = nullptr; 176 | 177 | static const ImWchar* glyphRanges = io.Fonts->GetGlyphRangesCyrillic(); 178 | 179 | ImFont* fontLarge = io.Fonts->AddFontFromMemoryTTF((void*)custom_font, sizeof(custom_font), 19.f, nullptr, glyphRanges); 180 | 181 | largeFont = io.Fonts->AddFontFromMemoryTTF((void*)custom_font, sizeof(custom_font), 30.f); 182 | 183 | io.Fonts->AddFontFromMemoryTTF((void*)custom_font, sizeof(custom_font), 19.f); 184 | 185 | ImFontConfig iconsConfig; 186 | 187 | iconsConfig.MergeMode = true; 188 | iconsConfig.PixelSnapH = true; 189 | iconsConfig.OversampleH = 3; 190 | iconsConfig.OversampleV = 3; 191 | 192 | iconsFont = io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_data, font_awesome_size, 22.0f, &iconsConfig, iconRanges); 193 | } 194 | 195 | void guiStart() { 196 | 197 | ImGui::Begin("Vireless", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); 198 | ImGui::SetWindowSize(menuSize, ImGuiCond_Always); 199 | 200 | ImGui::PushFont(largeFont); 201 | 202 | ImGui::Dummy(ImVec2(0.0f, 5.0f)); 203 | CenteredText("Vireless"); 204 | ImGui::Dummy(ImVec2(0.0f, 5.0f)); 205 | 206 | ImGui::PopFont(); 207 | 208 | ImGui::BeginChild("LeftPane", ImVec2(160, 0), true); 209 | 210 | ImVec2 windowSize = ImGui::GetWindowSize(); 211 | 212 | ImGui::PushFont(iconsFont); 213 | 214 | ImGui::NewLine(); 215 | 216 | if (selectedTab == 0) ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(255, 140, 0, 255)); 217 | ImGui::Dummy(ImVec2((windowSize.x - buttonSize.x) * 0.5f, 0)); 218 | ImGui::SameLine(); 219 | if (ImGui::Button(ICON_FA_CROSSHAIRS " Aimbot ", buttonSize)) selectedTab = 0; 220 | if (selectedTab == 0) ImGui::PopStyleColor(); 221 | 222 | ImGui::NewLine(); 223 | 224 | if (selectedTab == 1) ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(255, 140, 0, 255)); 225 | ImGui::Dummy(ImVec2((windowSize.x - buttonSize.x) * 0.5f, 0)); 226 | ImGui::SameLine(); 227 | if (ImGui::Button(ICON_FA_EYE " Visuals ", buttonSize)) selectedTab = 1; 228 | if (selectedTab == 1) ImGui::PopStyleColor(); 229 | 230 | ImGui::NewLine(); 231 | 232 | if (selectedTab == 2) ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(255, 140, 0, 255)); 233 | ImGui::Dummy(ImVec2((windowSize.x - buttonSize.x) * 0.5f, 0)); 234 | ImGui::SameLine(); 235 | if (ImGui::Button(ICON_FA_FOLDER " Config ", buttonSize)) selectedTab = 2; 236 | if (selectedTab == 2) ImGui::PopStyleColor(); 237 | 238 | ImGui::NewLine(); 239 | 240 | if (selectedTab == 3) ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor(255, 140, 0, 255)); 241 | ImGui::Dummy(ImVec2((windowSize.x - buttonSize.x) * 0.5f, 0)); 242 | ImGui::SameLine(); 243 | if (ImGui::Button(ICON_FA_BULLSEYE " Settings ", buttonSize)) selectedTab = 3; 244 | if (selectedTab == 3) ImGui::PopStyleColor(); 245 | 246 | DrawLine(separatorsColor, 1.0f, "up"); 247 | DrawLine(separatorsColor, 1.0f, "right"); 248 | 249 | ImGui::EndChild(); 250 | 251 | ImGui::SameLine(); 252 | 253 | ImGui::BeginChild("RightPane", ImVec2(0, 0), true); 254 | 255 | DrawLine(separatorsColor, 1.0f, "up"); 256 | ImGui::Indent(20.f); 257 | 258 | ImGui::NewLine(); 259 | 260 | if (selectedTab == 0) { 261 | ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); 262 | 263 | ImGui::BeginChild("AimbotFrame", ImVec2(404, 280), true); 264 | 265 | ImGui::Indent(14.f); 266 | 267 | ImGui::Dummy(ImVec2(0, 15)); 268 | ToggleButton("asdf", &menu::bEnableAim); 269 | ImGui::SameLine(); 270 | ImGui::Text(" Enable aimbot"); 271 | 272 | ImGui::Dummy(paddings); 273 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 4)); 274 | ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2)); 275 | ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.f, 140.f / 255, 0, 1.f)); 276 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(16.f / 255.f, 24.f / 255.f, 32.f / 255.f, 1.f)); 277 | ImGui::Combo("##comboAimingButton", &options::aimButton, aimbotButtons, IM_ARRAYSIZE(aimbotButtons)); 278 | ImGui::SameLine(); 279 | ImGui::PopStyleColor(2); 280 | ImGui::Text(" Toggle button "); 281 | 282 | ImGui::Dummy(ImVec2(0, 6)); 283 | 284 | ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.f, 140.f / 255, 0, 1.f)); 285 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(16.f / 255.f, 24.f / 255.f, 32.f / 255.f, 1.f)); 286 | ImGui::Combo("##comboAimingType", &options::aimingType, aimingTypes, IM_ARRAYSIZE(aimingTypes)); 287 | ImGui::SameLine(); 288 | ImGui::PopStyleColor(2); 289 | ImGui::PopStyleVar(2); 290 | ImGui::Text(" Aiming type"); 291 | 292 | ImGui::Dummy(paddings); 293 | ToggleButton("asdsad", &menu::bSmooth); 294 | ImGui::SameLine(); 295 | ImGui::Text(" Smooth"); 296 | 297 | ImGui::Dummy(paddings); 298 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(16.f / 255.f, 24.f / 255.f, 32.f / 255.f, 1.f)); 299 | ImGui::SliderFloat("##sliderSmooth", &options::smoothness, 1.0f, 10.f, "%.1f", ImGuiSliderFlags_AlwaysClamp); 300 | ImGui::SameLine(); 301 | ImGui::PopStyleColor(); 302 | ImGui::Text(" Smoothness"); 303 | 304 | ImGui::Dummy(paddings); 305 | ToggleButton("zxcmvs", &menu::bFOV); 306 | ImGui::SameLine(); 307 | ImGui::Text(" Draw FOV"); 308 | 309 | ImGui::Dummy(paddings); 310 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(16.f / 255.f, 24.f / 255.f, 32.f / 255.f, 1.f)); 311 | ImGui::SliderFloat("##sliderRadiusFOV", &options::radiusFOV, 0.0f, 300.f, "%.1f", ImGuiSliderFlags_AlwaysClamp); 312 | ImGui::SameLine(); 313 | ImGui::PopStyleColor(); 314 | ImGui::Text(" FOV radius"); 315 | 316 | ImGui::EndChild(); 317 | /////////////////////////////////// 318 | ImGui::Dummy(ImVec2(0, 20)); 319 | /////////////////////////////////// 320 | ImGui::BeginChild("TriggerbotFrame", ImVec2(404, 120), true); 321 | 322 | ImGui::Indent(10.f); 323 | 324 | ImGui::Dummy(ImVec2(0, 15)); 325 | ToggleButton("asasda", &menu::bEnableTriggerbot); 326 | ImGui::SameLine(); 327 | ImGui::Text(" Enable Triggerbot"); 328 | 329 | ImGui::Dummy(paddings); 330 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(16.f / 255.f, 24.f / 255.f, 32.f / 255.f, 1.f)); 331 | ImGui::SliderInt("##triggerbotDelay ", &options::triggerbotDelay, 1, 100, "%d ms", ImGuiSliderFlags_AlwaysClamp); 332 | ImGui::SameLine(); 333 | ImGui::PopStyleColor(); 334 | ImGui::Text(" Delay"); 335 | 336 | ImGui::EndChild(); 337 | 338 | ImGui::PopStyleVar(); 339 | } 340 | else if (selectedTab == 1) { 341 | ImVec2 mainWindowPos = ImGui::GetWindowPos(); 342 | ImVec2 mainWindowSize = ImGui::GetWindowSize(); 343 | 344 | ImVec2 espWindowPos = ImVec2(mainWindowPos.x + mainWindowSize.x + 40, mainWindowPos.y); 345 | 346 | ImGui::Begin("Esp preview", nullptr, ImGuiWindowFlags_NoResize); 347 | ImGui::SetWindowPos(espWindowPos, ImGuiCond_FirstUseEver); 348 | ImGui::SetWindowSize(ImVec2(230, 400), ImGuiCond_FirstUseEver); 349 | 350 | ImVec2 espFramePos = ImGui::GetWindowPos(); 351 | ImVec2 espFrameSize = ImGui::GetWindowSize(); 352 | 353 | ImDrawList* drawList = ImGui::GetWindowDrawList(); 354 | 355 | if (menu::bEnableBox2D) { 356 | if (menu::bEnableBox2DLines) { 357 | drawList->AddRect(ImVec2(espFramePos.x + 20, espFramePos.y + 30), ImVec2(espFramePos.x + espFrameSize.x - 20, espFramePos.y + espFrameSize.y - 20), (ImColor)options::boxes2DLinesColor, options::box2DRounding, 0, 1.4f); 358 | } 359 | if (menu::bEnableBox2DFill) { 360 | drawList->AddRectFilled(ImVec2(espFramePos.x + 20, espFramePos.y + 30), ImVec2(espFramePos.x + espFrameSize.x - 20, espFramePos.y + espFrameSize.y - 20), (ImColor)options::boxes2DFillColor, options::box2DRounding); 361 | } 362 | } 363 | 364 | if (menu::bEnableLines) { 365 | drawList->AddLine(ImVec2(espFramePos.x + espFrameSize.x / 2, espFramePos.y + espFrameSize.y), ImVec2(espFramePos.x + espFrameSize.x / 2, espFramePos.y + espFrameSize.y - 20), (ImColor)options::snapLinesColor, 2.f); 366 | } 367 | 368 | if (menu::bEnableHealth) { 369 | drawList->AddRectFilled(ImVec2(espFramePos.x + 20, espFramePos.y + 30), ImVec2(espFramePos.x + 13, espFramePos.y + espFrameSize.y - 20), ImColor(0.0f, 1.0f, 0.0f, 1.f)); 370 | } 371 | 372 | ImGui::End(); 373 | 374 | ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); 375 | ImGui::BeginChild("TriggerbotFrame", ImVec2(404, 340), true); 376 | 377 | ImGui::Indent(14.f); 378 | 379 | ImGui::Dummy(paddings); 380 | ToggleButton("##enableESP", &menu::bEnableESP); 381 | ImGui::SameLine(); 382 | ImGui::Text(" Enable ESP "); 383 | 384 | ImGui::Dummy(paddings); 385 | 386 | ToggleButton("##enable2dbox", &menu::bEnableBox2D); 387 | ImGui::SameLine(); 388 | ImGui::Text(" 2D Box "); 389 | 390 | ImGui::SameLine(); 391 | 392 | ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.f, 0.f, 0.f)); 393 | ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f)); 394 | ImGui::PushFont(iconsFont); 395 | if (ImGui::Button(ICON_FA_COG, ImVec2(20, 22))) box2dsettings = !box2dsettings; 396 | ImGui::PopFont(); 397 | ImGui::PopStyleColor(2); 398 | 399 | if (box2dsettings) { 400 | ImGui::Begin("2D box settings", nullptr, ImGuiWindowFlags_NoResize); 401 | ImGui::SetWindowSize(ImVec2(200, 300), ImGuiCond_Always); 402 | 403 | ImGui::Indent(10.f); 404 | ImGui::Dummy(paddings); 405 | 406 | ToggleButton("asdsad", &menu::bEnableBox2DFill); 407 | ImGui::SameLine(); 408 | ImGui::Text(" Fill"); 409 | 410 | ImGui::Dummy(paddings); 411 | 412 | ToggleButton("asdsdsdad", &menu::bEnableBox2DLines); 413 | ImGui::SameLine(); 414 | ImGui::Text(" Lines"); 415 | 416 | ImGui::Dummy(paddings); 417 | 418 | ImGui::Text("Rounding"); 419 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(16.f / 255.f, 24.f / 255.f, 32.f / 255.f, 1.f)); 420 | ImGui::SliderFloat("##Rouning", &options::box2DRounding, 0.f, 50.f, "%.0f", 0); 421 | ImGui::PopStyleColor(); 422 | 423 | ImGui::Dummy(paddings); 424 | 425 | ShowColorPickerButton(&options::boxes2DFillColor, 0); 426 | ImGui::SameLine(); 427 | ImGui::Text(" Fill color"); 428 | 429 | ImGui::Dummy(paddings); 430 | 431 | ShowColorPickerButton(&options::boxes2DLinesColor, 1); 432 | ImGui::SameLine(); 433 | ImGui::Text(" Lines color"); 434 | 435 | ImGui::Dummy(paddings); 436 | 437 | ShowColorPickerButton(&options::boxes2DLinesColorTeam, 2); 438 | ImGui::SameLine(); 439 | ImGui::Text(" Lines color team"); 440 | 441 | ImGui::Dummy(paddings); 442 | 443 | ShowColorPickerButton(&options::boxes2DFillColorTeam, 3); 444 | ImGui::SameLine(); 445 | ImGui::Text(" Fill color team"); 446 | 447 | ImGui::End(); 448 | } 449 | 450 | ImGui::Dummy(ImVec2(paddings.x, paddings.y - 2)); 451 | 452 | ToggleButton("##enable3dbox", &menu::bEnableBox3D); 453 | ImGui::SameLine(); 454 | ImGui::Text(" 3D Box "); 455 | 456 | ImGui::SameLine(); 457 | 458 | ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.f, 0.f, 0.f)); 459 | ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f)); 460 | ImGui::PushFont(iconsFont); 461 | if (ImGui::Button(ICON_FA_COG" ", ImVec2(20, 22))) box3dsettings = !box3dsettings; 462 | ImGui::PopFont(); 463 | ImGui::PopStyleColor(2); 464 | 465 | if (box3dsettings) { 466 | ImGui::Begin("3D box settings", nullptr, ImGuiWindowFlags_NoResize); 467 | ImGui::SetWindowSize(ImVec2(200, 140), ImGuiCond_Always); 468 | 469 | ImGui::Indent(10.f); 470 | 471 | ImGui::Dummy(paddings); 472 | 473 | ToggleButton("##animation", &menu::bEnableBox3DAnim); 474 | ImGui::SameLine(); 475 | ImGui::Text(" Animation"); 476 | 477 | ImGui::Dummy(paddings); 478 | 479 | ShowColorPickerButton(&options::boxes3DLinesColor, 3); 480 | ImGui::SameLine(); 481 | ImGui::Text(" Lines color"); 482 | 483 | ImGui::Dummy(paddings); 484 | 485 | ShowColorPickerButton(&options::boxes3DLinesColorTeam, 7); 486 | ImGui::SameLine(); 487 | ImGui::Text(" Lines color team"); 488 | ImGui::End(); 489 | } 490 | 491 | ImGui::Dummy(ImVec2(paddings.x, paddings.y - 2)); 492 | 493 | ToggleButton("##enablesnaplines", &menu::bEnableLines); 494 | ImGui::SameLine(); 495 | ImGui::Text(" Snaplines "); 496 | ImGui::SameLine(); 497 | 498 | ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.f, 0.f, 0.f)); 499 | ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f)); 500 | ImGui::PushFont(iconsFont); 501 | if (ImGui::Button(ICON_FA_COG" ", ImVec2(20, 22))) snaplinessettings = !snaplinessettings; 502 | ImGui::PopFont(); 503 | ImGui::PopStyleColor(2); 504 | 505 | if (snaplinessettings) { 506 | ImGui::Begin("Snaplines settings", nullptr, ImGuiWindowFlags_NoResize); 507 | ImGui::SetWindowSize(ImVec2(200, 100), ImGuiCond_Always); 508 | 509 | ImGui::Indent(10.f); 510 | 511 | ImGui::Dummy(paddings); 512 | 513 | ShowColorPickerButton(&options::snapLinesColor, 12); 514 | ImGui::SameLine(); 515 | ImGui::Text(" Color"); 516 | 517 | ImGui::Dummy(paddings); 518 | 519 | ShowColorPickerButton(&options::snapLinesColorTeam, 10); 520 | ImGui::SameLine(); 521 | ImGui::Text(" Color team"); 522 | 523 | ImGui::End(); 524 | } 525 | 526 | ImGui::Dummy(paddings); 527 | 528 | ToggleButton("##enablehealth", &menu::bEnableHealth); 529 | ImGui::SameLine(); 530 | ImGui::Text(" Health "); 531 | 532 | ImGui::Dummy(paddings); 533 | 534 | ToggleButton("##enabledirections", &menu::bEnableDirection); 535 | ImGui::SameLine(); 536 | ImGui::Text(" Directions "); 537 | ImGui::SameLine(); 538 | ShowColorPickerButton(&options::directionColor, 6); 539 | 540 | ImGui::Dummy(paddings); 541 | 542 | ToggleButton("##enableskeleton", &menu::bEnableSkeleton); 543 | ImGui::SameLine(); 544 | ImGui::Text(" Skeleton "); 545 | ImGui::SameLine(); 546 | 547 | ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.f, 0.f, 0.f)); 548 | ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f)); 549 | ImGui::PushFont(iconsFont); 550 | if (ImGui::Button(ICON_FA_COG" ", ImVec2(20, 22))) skeletonsettings = !skeletonsettings; 551 | ImGui::PopFont(); 552 | ImGui::PopStyleColor(2); 553 | 554 | if (skeletonsettings) { 555 | ImGui::Begin("Skeleton settings", nullptr, ImGuiWindowFlags_NoResize); 556 | ImGui::SetWindowSize(ImVec2(200, 130), ImGuiCond_Always); 557 | ImGui::Indent(10.f); 558 | 559 | ImGui::Dummy(paddings); 560 | 561 | ShowColorPickerButton(&options::skeletonColor, 8); 562 | ImGui::SameLine(); 563 | ImGui::Text("Color"); 564 | 565 | ImGui::Dummy(paddings); 566 | 567 | ShowColorPickerButton(&options::skeletonColorTeam, 9); 568 | ImGui::SameLine(); 569 | ImGui::Text("Color team"); 570 | 571 | ImGui::End(); 572 | } 573 | 574 | ImGui::Dummy(ImVec2(paddings.x, paddings.y - 2)); 575 | 576 | ToggleButton("##enablename", &menu::bEnableName); 577 | ImGui::SameLine(); 578 | ImGui::Text(" Name "); 579 | ImGui::SameLine(); 580 | 581 | ImGui::Dummy(paddings); 582 | ImGui::Dummy(paddings); 583 | 584 | ToggleButton("##teamvisible", &menu::bTeamVisible); 585 | ImGui::SameLine(); 586 | ImGui::Text(" Team visible "); 587 | ImGui::SameLine(); 588 | 589 | ImGui::EndChild(); 590 | ImGui::PopStyleVar(); 591 | } 592 | else if (selectedTab == 2) { 593 | ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); 594 | 595 | ImGui::BeginChild("##savecfgframe", ImVec2(404, 100), true); 596 | ImGui::Indent(14.f); 597 | ImGui::Dummy(ImVec2(0, 20)); 598 | 599 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(16.f / 255.f, 24.f / 255.f, 32.f / 255.f, 1.f)); 600 | ImGui::InputText("##configname", configName, IM_ARRAYSIZE(configName)); 601 | 602 | ImGui::SameLine(); 603 | ImGui::PopStyleColor(); 604 | ImGui::Text(" Config name"); 605 | 606 | ImGui::Dummy(paddings); 607 | 608 | ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.f, 140.f / 255, 0, 1.f)); 609 | if (ImGui::Button("Save config", ImVec2(130, 30))) { 610 | config.saveConfig(std::string (configName)); 611 | config.update(); 612 | selectedConfig = config.configFiles[0]; 613 | } 614 | 615 | ImGui::EndChild(); 616 | 617 | ImGui::Dummy(ImVec2(0, 25)); 618 | 619 | ImGui::BeginChild("##loadcfgframe", ImVec2(404, 190), true); 620 | ImGui::Indent(14.f); 621 | ImGui::Dummy(ImVec2(0, 20)); 622 | 623 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(16.f / 255.f, 24.f / 255.f, 32.f / 255.f, 1.f)); 624 | if (ImGui::Combo("##selectconfig", &selectedConfigIndex, config.configNames.data(), config.configNames.size())) { 625 | if (selectedConfigIndex >= 0 && selectedConfigIndex < config.configFiles.size()) { 626 | selectedConfig = config.configFiles[selectedConfigIndex]; 627 | } 628 | } 629 | ImGui::PopStyleColor(); 630 | ImGui::SameLine(); 631 | ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); 632 | ImGui::Text(" Choose config"); 633 | ImGui::PopStyleColor(); 634 | 635 | ImGui::Dummy(paddings); 636 | 637 | if (ImGui::Button("Load config", ImVec2(130, 30))) { 638 | config.loadConfig(selectedConfig); 639 | } 640 | 641 | ImGui::Dummy(paddings); 642 | 643 | if (ImGui::Button("Delete config", ImVec2(130, 30))) { 644 | if (!config.configFiles.empty() && !selectedConfig.empty()) { 645 | config.deleteConfig(selectedConfig); 646 | config.update(); 647 | selectedConfig = config.configFiles[0]; 648 | } 649 | } 650 | 651 | ImGui::Dummy(paddings); 652 | 653 | if (ImGui::Button("Update configs", ImVec2(130, 30))) { 654 | config.update(); 655 | selectedConfig = config.configFiles[0]; 656 | } 657 | 658 | ImGui::EndChild(); 659 | 660 | ImGui::PopStyleColor(); 661 | ImGui::PopStyleVar(); 662 | } 663 | else if (selectedTab == 3) { 664 | ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); 665 | ImGui::BeginChild("##settingsframe", ImVec2(404, 300), true); 666 | ImGui::Dummy(paddings); 667 | ImGui::Indent(14.f); 668 | 669 | ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.f, 140.f / 255, 0, 1.f)); 670 | 671 | if (ImGui::Button("Toggle menu key", ImVec2(140, 27))) { 672 | waitingForToggleKey = true; 673 | } 674 | 675 | ImGui::Dummy(paddings); 676 | 677 | if (waitingForToggleKey) { 678 | ImGui::Text("Press key..."); 679 | 680 | for (int key = 0; key < 256; ++key) { 681 | if (GetAsyncKeyState(key) & 0x8000) { 682 | menu::bToggleButton = key; 683 | waitingForToggleKey = false; 684 | break; 685 | } 686 | } 687 | } 688 | 689 | ImGui::Text("Key: % s", ImGui::GetKeyName(static_cast(menu::bToggleButton))); 690 | 691 | ImGui::Dummy(paddings); 692 | 693 | if (ImGui::Button("End menu key", ImVec2(140, 27))) { 694 | waitingForEndKey = true; 695 | } 696 | 697 | ImGui::Dummy(paddings); 698 | 699 | if (waitingForEndKey) { 700 | ImGui::Text("Press key..."); 701 | 702 | for (int key = 0; key < 256; ++key) { 703 | if (GetAsyncKeyState(key) & 0x8000) { 704 | menu::bEndButton = key; 705 | waitingForEndKey = false; 706 | break; 707 | } 708 | } 709 | } 710 | 711 | ImGui::Text("Key: % s", ImGui::GetKeyName(static_cast(menu::bEndButton))); 712 | 713 | ImGui::PopStyleColor(); 714 | ImGui::EndChild(); 715 | ImGui::PopStyleVar(); 716 | } 717 | 718 | ImGui::PopFont(); 719 | ImGui::EndChild(); 720 | 721 | ImGui::End(); 722 | } -------------------------------------------------------------------------------- /cs2-external-cheat/gui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void guiStart(); 4 | void SetupFonts(); 5 | void setImguiStyle(); -------------------------------------------------------------------------------- /cs2-external-cheat/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // DEAR IMGUI COMPILE-TIME OPTIONS 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty. 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | // May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included. 54 | //#define IMGUI_INCLUDE_IMGUI_USER_H 55 | //#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h" 56 | 57 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 58 | //#define IMGUI_USE_BGRA_PACKED_COLOR 59 | 60 | //---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 61 | //#define IMGUI_USE_WCHAR32 62 | 63 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 64 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 65 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 66 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 67 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined. 68 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 69 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 70 | //#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. 71 | 72 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 73 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 74 | //#define IMGUI_USE_STB_SPRINTF 75 | 76 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 77 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 78 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 79 | //#define IMGUI_ENABLE_FREETYPE 80 | 81 | //---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) 82 | // Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). 83 | // Only works in combination with IMGUI_ENABLE_FREETYPE. 84 | // (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) 85 | //#define IMGUI_ENABLE_FREETYPE_LUNASVG 86 | 87 | //---- Use stb_truetype to build and rasterize the font atlas (default) 88 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 89 | //#define IMGUI_ENABLE_STB_TRUETYPE 90 | 91 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 92 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 93 | /* 94 | #define IM_VEC2_CLASS_EXTRA \ 95 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 96 | operator MyVec2() const { return MyVec2(x,y); } 97 | 98 | #define IM_VEC4_CLASS_EXTRA \ 99 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 100 | operator MyVec4() const { return MyVec4(x,y,z,w); } 101 | */ 102 | //---- ...Or use Dear ImGui's own very basic math operators. 103 | //#define IMGUI_DEFINE_MATH_OPERATORS 104 | 105 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 106 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 107 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 108 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 109 | //#define ImDrawIdx unsigned int 110 | 111 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 112 | //struct ImDrawList; 113 | //struct ImDrawCmd; 114 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 115 | //#define ImDrawCallback MyImDrawCallback 116 | 117 | //---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) 118 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 119 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 120 | //#define IM_DEBUG_BREAK __debugbreak() 121 | 122 | //---- Debug Tools: Enable slower asserts 123 | //#define IMGUI_DEBUG_PARANOID 124 | 125 | //---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) 126 | /* 127 | namespace ImGui 128 | { 129 | void MyFunction(const char* name, MyMatrix44* mtx); 130 | } 131 | */ 132 | -------------------------------------------------------------------------------- /cs2-external-cheat/imgui/imgui_impl_dx11.cpp: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX11 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | 8 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 9 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 10 | // Learn about Dear ImGui: 11 | // - FAQ https://dearimgui.com/faq 12 | // - Getting Started https://dearimgui.com/getting-started 13 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 14 | // - Introduction, links and more at the top of imgui.cpp 15 | 16 | // CHANGELOG 17 | // (minor and older changes stripped away, please see git history for details) 18 | // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. 19 | // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). 20 | // 2021-05-19: DirectX11: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) 21 | // 2021-02-18: DirectX11: Change blending equation to preserve alpha in output buffer. 22 | // 2019-08-01: DirectX11: Fixed code querying the Geometry Shader state (would generally error with Debug layer enabled). 23 | // 2019-07-21: DirectX11: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData. Clearing Hull/Domain/Compute shaders without backup/restore. 24 | // 2019-05-29: DirectX11: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. 25 | // 2019-04-30: DirectX11: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. 26 | // 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile(). 27 | // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window. 28 | // 2018-08-01: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility. 29 | // 2018-07-13: DirectX11: Fixed unreleased resources in Init and Shutdown functions. 30 | // 2018-06-08: Misc: Extracted imgui_impl_dx11.cpp/.h away from the old combined DX11+Win32 example. 31 | // 2018-06-08: DirectX11: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. 32 | // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX11_RenderDrawData() in the .h file so you can call it yourself. 33 | // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. 34 | // 2016-05-07: DirectX11: Disabling depth-write. 35 | 36 | #include "imgui.h" 37 | #ifndef IMGUI_DISABLE 38 | #include "imgui_impl_dx11.h" 39 | 40 | // DirectX 41 | #include 42 | #include 43 | #include 44 | #ifdef _MSC_VER 45 | #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. 46 | #endif 47 | 48 | // DirectX11 data 49 | struct ImGui_ImplDX11_Data 50 | { 51 | ID3D11Device* pd3dDevice; 52 | ID3D11DeviceContext* pd3dDeviceContext; 53 | IDXGIFactory* pFactory; 54 | ID3D11Buffer* pVB; 55 | ID3D11Buffer* pIB; 56 | ID3D11VertexShader* pVertexShader; 57 | ID3D11InputLayout* pInputLayout; 58 | ID3D11Buffer* pVertexConstantBuffer; 59 | ID3D11PixelShader* pPixelShader; 60 | ID3D11SamplerState* pFontSampler; 61 | ID3D11ShaderResourceView* pFontTextureView; 62 | ID3D11RasterizerState* pRasterizerState; 63 | ID3D11BlendState* pBlendState; 64 | ID3D11DepthStencilState* pDepthStencilState; 65 | int VertexBufferSize; 66 | int IndexBufferSize; 67 | 68 | ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; } 69 | }; 70 | 71 | struct VERTEX_CONSTANT_BUFFER_DX11 72 | { 73 | float mvp[4][4]; 74 | }; 75 | 76 | // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts 77 | // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. 78 | static ImGui_ImplDX11_Data* ImGui_ImplDX11_GetBackendData() 79 | { 80 | return ImGui::GetCurrentContext() ? (ImGui_ImplDX11_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; 81 | } 82 | 83 | // Functions 84 | static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceContext* ctx) 85 | { 86 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 87 | 88 | // Setup viewport 89 | D3D11_VIEWPORT vp; 90 | memset(&vp, 0, sizeof(D3D11_VIEWPORT)); 91 | vp.Width = draw_data->DisplaySize.x; 92 | vp.Height = draw_data->DisplaySize.y; 93 | vp.MinDepth = 0.0f; 94 | vp.MaxDepth = 1.0f; 95 | vp.TopLeftX = vp.TopLeftY = 0; 96 | ctx->RSSetViewports(1, &vp); 97 | 98 | // Setup shader and vertex buffers 99 | unsigned int stride = sizeof(ImDrawVert); 100 | unsigned int offset = 0; 101 | ctx->IASetInputLayout(bd->pInputLayout); 102 | ctx->IASetVertexBuffers(0, 1, &bd->pVB, &stride, &offset); 103 | ctx->IASetIndexBuffer(bd->pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); 104 | ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 105 | ctx->VSSetShader(bd->pVertexShader, nullptr, 0); 106 | ctx->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer); 107 | ctx->PSSetShader(bd->pPixelShader, nullptr, 0); 108 | ctx->PSSetSamplers(0, 1, &bd->pFontSampler); 109 | ctx->GSSetShader(nullptr, nullptr, 0); 110 | ctx->HSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 111 | ctx->DSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 112 | ctx->CSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 113 | 114 | // Setup blend state 115 | const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; 116 | ctx->OMSetBlendState(bd->pBlendState, blend_factor, 0xffffffff); 117 | ctx->OMSetDepthStencilState(bd->pDepthStencilState, 0); 118 | ctx->RSSetState(bd->pRasterizerState); 119 | } 120 | 121 | // Render function 122 | void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) 123 | { 124 | // Avoid rendering when minimized 125 | if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f) 126 | return; 127 | 128 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 129 | ID3D11DeviceContext* ctx = bd->pd3dDeviceContext; 130 | 131 | // Create and grow vertex/index buffers if needed 132 | if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount) 133 | { 134 | if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } 135 | bd->VertexBufferSize = draw_data->TotalVtxCount + 5000; 136 | D3D11_BUFFER_DESC desc; 137 | memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); 138 | desc.Usage = D3D11_USAGE_DYNAMIC; 139 | desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert); 140 | desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; 141 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 142 | desc.MiscFlags = 0; 143 | if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVB) < 0) 144 | return; 145 | } 146 | if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount) 147 | { 148 | if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } 149 | bd->IndexBufferSize = draw_data->TotalIdxCount + 10000; 150 | D3D11_BUFFER_DESC desc; 151 | memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); 152 | desc.Usage = D3D11_USAGE_DYNAMIC; 153 | desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx); 154 | desc.BindFlags = D3D11_BIND_INDEX_BUFFER; 155 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 156 | if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pIB) < 0) 157 | return; 158 | } 159 | 160 | // Upload vertex/index data into a single contiguous GPU buffer 161 | D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource; 162 | if (ctx->Map(bd->pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK) 163 | return; 164 | if (ctx->Map(bd->pIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &idx_resource) != S_OK) 165 | return; 166 | ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData; 167 | ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource.pData; 168 | for (int n = 0; n < draw_data->CmdListsCount; n++) 169 | { 170 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 171 | memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); 172 | memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); 173 | vtx_dst += cmd_list->VtxBuffer.Size; 174 | idx_dst += cmd_list->IdxBuffer.Size; 175 | } 176 | ctx->Unmap(bd->pVB, 0); 177 | ctx->Unmap(bd->pIB, 0); 178 | 179 | // Setup orthographic projection matrix into our constant buffer 180 | // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. 181 | { 182 | D3D11_MAPPED_SUBRESOURCE mapped_resource; 183 | if (ctx->Map(bd->pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) 184 | return; 185 | VERTEX_CONSTANT_BUFFER_DX11* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX11*)mapped_resource.pData; 186 | float L = draw_data->DisplayPos.x; 187 | float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; 188 | float T = draw_data->DisplayPos.y; 189 | float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y; 190 | float mvp[4][4] = 191 | { 192 | { 2.0f/(R-L), 0.0f, 0.0f, 0.0f }, 193 | { 0.0f, 2.0f/(T-B), 0.0f, 0.0f }, 194 | { 0.0f, 0.0f, 0.5f, 0.0f }, 195 | { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, 196 | }; 197 | memcpy(&constant_buffer->mvp, mvp, sizeof(mvp)); 198 | ctx->Unmap(bd->pVertexConstantBuffer, 0); 199 | } 200 | 201 | // Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!) 202 | struct BACKUP_DX11_STATE 203 | { 204 | UINT ScissorRectsCount, ViewportsCount; 205 | D3D11_RECT ScissorRects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; 206 | D3D11_VIEWPORT Viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; 207 | ID3D11RasterizerState* RS; 208 | ID3D11BlendState* BlendState; 209 | FLOAT BlendFactor[4]; 210 | UINT SampleMask; 211 | UINT StencilRef; 212 | ID3D11DepthStencilState* DepthStencilState; 213 | ID3D11ShaderResourceView* PSShaderResource; 214 | ID3D11SamplerState* PSSampler; 215 | ID3D11PixelShader* PS; 216 | ID3D11VertexShader* VS; 217 | ID3D11GeometryShader* GS; 218 | UINT PSInstancesCount, VSInstancesCount, GSInstancesCount; 219 | ID3D11ClassInstance *PSInstances[256], *VSInstances[256], *GSInstances[256]; // 256 is max according to PSSetShader documentation 220 | D3D11_PRIMITIVE_TOPOLOGY PrimitiveTopology; 221 | ID3D11Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer; 222 | UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset; 223 | DXGI_FORMAT IndexBufferFormat; 224 | ID3D11InputLayout* InputLayout; 225 | }; 226 | BACKUP_DX11_STATE old = {}; 227 | old.ScissorRectsCount = old.ViewportsCount = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; 228 | ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects); 229 | ctx->RSGetViewports(&old.ViewportsCount, old.Viewports); 230 | ctx->RSGetState(&old.RS); 231 | ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask); 232 | ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef); 233 | ctx->PSGetShaderResources(0, 1, &old.PSShaderResource); 234 | ctx->PSGetSamplers(0, 1, &old.PSSampler); 235 | old.PSInstancesCount = old.VSInstancesCount = old.GSInstancesCount = 256; 236 | ctx->PSGetShader(&old.PS, old.PSInstances, &old.PSInstancesCount); 237 | ctx->VSGetShader(&old.VS, old.VSInstances, &old.VSInstancesCount); 238 | ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer); 239 | ctx->GSGetShader(&old.GS, old.GSInstances, &old.GSInstancesCount); 240 | 241 | ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology); 242 | ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset); 243 | ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); 244 | ctx->IAGetInputLayout(&old.InputLayout); 245 | 246 | // Setup desired DX state 247 | ImGui_ImplDX11_SetupRenderState(draw_data, ctx); 248 | 249 | // Render command lists 250 | // (Because we merged all buffers into a single one, we maintain our own offset into them) 251 | int global_idx_offset = 0; 252 | int global_vtx_offset = 0; 253 | ImVec2 clip_off = draw_data->DisplayPos; 254 | for (int n = 0; n < draw_data->CmdListsCount; n++) 255 | { 256 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 257 | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) 258 | { 259 | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; 260 | if (pcmd->UserCallback != nullptr) 261 | { 262 | // User callback, registered via ImDrawList::AddCallback() 263 | // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) 264 | if (pcmd->UserCallback == ImDrawCallback_ResetRenderState) 265 | ImGui_ImplDX11_SetupRenderState(draw_data, ctx); 266 | else 267 | pcmd->UserCallback(cmd_list, pcmd); 268 | } 269 | else 270 | { 271 | // Project scissor/clipping rectangles into framebuffer space 272 | ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y); 273 | ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y); 274 | if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) 275 | continue; 276 | 277 | // Apply scissor/clipping rectangle 278 | const D3D11_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y }; 279 | ctx->RSSetScissorRects(1, &r); 280 | 281 | // Bind texture, Draw 282 | ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->GetTexID(); 283 | ctx->PSSetShaderResources(0, 1, &texture_srv); 284 | ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset); 285 | } 286 | } 287 | global_idx_offset += cmd_list->IdxBuffer.Size; 288 | global_vtx_offset += cmd_list->VtxBuffer.Size; 289 | } 290 | 291 | // Restore modified DX state 292 | ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects); 293 | ctx->RSSetViewports(old.ViewportsCount, old.Viewports); 294 | ctx->RSSetState(old.RS); if (old.RS) old.RS->Release(); 295 | ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release(); 296 | ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release(); 297 | ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release(); 298 | ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release(); 299 | ctx->PSSetShader(old.PS, old.PSInstances, old.PSInstancesCount); if (old.PS) old.PS->Release(); 300 | for (UINT i = 0; i < old.PSInstancesCount; i++) if (old.PSInstances[i]) old.PSInstances[i]->Release(); 301 | ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount); if (old.VS) old.VS->Release(); 302 | ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release(); 303 | ctx->GSSetShader(old.GS, old.GSInstances, old.GSInstancesCount); if (old.GS) old.GS->Release(); 304 | for (UINT i = 0; i < old.VSInstancesCount; i++) if (old.VSInstances[i]) old.VSInstances[i]->Release(); 305 | ctx->IASetPrimitiveTopology(old.PrimitiveTopology); 306 | ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release(); 307 | ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release(); 308 | ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); 309 | } 310 | 311 | static void ImGui_ImplDX11_CreateFontsTexture() 312 | { 313 | // Build texture atlas 314 | ImGuiIO& io = ImGui::GetIO(); 315 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 316 | unsigned char* pixels; 317 | int width, height; 318 | io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); 319 | 320 | // Upload texture to graphics system 321 | { 322 | D3D11_TEXTURE2D_DESC desc; 323 | ZeroMemory(&desc, sizeof(desc)); 324 | desc.Width = width; 325 | desc.Height = height; 326 | desc.MipLevels = 1; 327 | desc.ArraySize = 1; 328 | desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 329 | desc.SampleDesc.Count = 1; 330 | desc.Usage = D3D11_USAGE_DEFAULT; 331 | desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 332 | desc.CPUAccessFlags = 0; 333 | 334 | ID3D11Texture2D* pTexture = nullptr; 335 | D3D11_SUBRESOURCE_DATA subResource; 336 | subResource.pSysMem = pixels; 337 | subResource.SysMemPitch = desc.Width * 4; 338 | subResource.SysMemSlicePitch = 0; 339 | bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); 340 | IM_ASSERT(pTexture != nullptr); 341 | 342 | // Create texture view 343 | D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; 344 | ZeroMemory(&srvDesc, sizeof(srvDesc)); 345 | srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 346 | srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; 347 | srvDesc.Texture2D.MipLevels = desc.MipLevels; 348 | srvDesc.Texture2D.MostDetailedMip = 0; 349 | bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &bd->pFontTextureView); 350 | pTexture->Release(); 351 | } 352 | 353 | // Store our identifier 354 | io.Fonts->SetTexID((ImTextureID)bd->pFontTextureView); 355 | 356 | // Create texture sampler 357 | // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling) 358 | { 359 | D3D11_SAMPLER_DESC desc; 360 | ZeroMemory(&desc, sizeof(desc)); 361 | desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; 362 | desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; 363 | desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; 364 | desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; 365 | desc.MipLODBias = 0.f; 366 | desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; 367 | desc.MinLOD = 0.f; 368 | desc.MaxLOD = 0.f; 369 | bd->pd3dDevice->CreateSamplerState(&desc, &bd->pFontSampler); 370 | } 371 | } 372 | 373 | bool ImGui_ImplDX11_CreateDeviceObjects() 374 | { 375 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 376 | if (!bd->pd3dDevice) 377 | return false; 378 | if (bd->pFontSampler) 379 | ImGui_ImplDX11_InvalidateDeviceObjects(); 380 | 381 | // By using D3DCompile() from / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) 382 | // If you would like to use this DX11 sample code but remove this dependency you can: 383 | // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution] 384 | // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL. 385 | // See https://github.com/ocornut/imgui/pull/638 for sources and details. 386 | 387 | // Create the vertex shader 388 | { 389 | static const char* vertexShader = 390 | "cbuffer vertexBuffer : register(b0) \ 391 | {\ 392 | float4x4 ProjectionMatrix; \ 393 | };\ 394 | struct VS_INPUT\ 395 | {\ 396 | float2 pos : POSITION;\ 397 | float4 col : COLOR0;\ 398 | float2 uv : TEXCOORD0;\ 399 | };\ 400 | \ 401 | struct PS_INPUT\ 402 | {\ 403 | float4 pos : SV_POSITION;\ 404 | float4 col : COLOR0;\ 405 | float2 uv : TEXCOORD0;\ 406 | };\ 407 | \ 408 | PS_INPUT main(VS_INPUT input)\ 409 | {\ 410 | PS_INPUT output;\ 411 | output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ 412 | output.col = input.col;\ 413 | output.uv = input.uv;\ 414 | return output;\ 415 | }"; 416 | 417 | ID3DBlob* vertexShaderBlob; 418 | if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr))) 419 | return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! 420 | if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), nullptr, &bd->pVertexShader) != S_OK) 421 | { 422 | vertexShaderBlob->Release(); 423 | return false; 424 | } 425 | 426 | // Create the input layout 427 | D3D11_INPUT_ELEMENT_DESC local_layout[] = 428 | { 429 | { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 430 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 431 | { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)offsetof(ImDrawVert, col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 432 | }; 433 | if (bd->pd3dDevice->CreateInputLayout(local_layout, 3, vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pInputLayout) != S_OK) 434 | { 435 | vertexShaderBlob->Release(); 436 | return false; 437 | } 438 | vertexShaderBlob->Release(); 439 | 440 | // Create the constant buffer 441 | { 442 | D3D11_BUFFER_DESC desc; 443 | desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER_DX11); 444 | desc.Usage = D3D11_USAGE_DYNAMIC; 445 | desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 446 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 447 | desc.MiscFlags = 0; 448 | bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVertexConstantBuffer); 449 | } 450 | } 451 | 452 | // Create the pixel shader 453 | { 454 | static const char* pixelShader = 455 | "struct PS_INPUT\ 456 | {\ 457 | float4 pos : SV_POSITION;\ 458 | float4 col : COLOR0;\ 459 | float2 uv : TEXCOORD0;\ 460 | };\ 461 | sampler sampler0;\ 462 | Texture2D texture0;\ 463 | \ 464 | float4 main(PS_INPUT input) : SV_Target\ 465 | {\ 466 | float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \ 467 | return out_col; \ 468 | }"; 469 | 470 | ID3DBlob* pixelShaderBlob; 471 | if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr))) 472 | return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! 473 | if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), nullptr, &bd->pPixelShader) != S_OK) 474 | { 475 | pixelShaderBlob->Release(); 476 | return false; 477 | } 478 | pixelShaderBlob->Release(); 479 | } 480 | 481 | // Create the blending setup 482 | { 483 | D3D11_BLEND_DESC desc; 484 | ZeroMemory(&desc, sizeof(desc)); 485 | desc.AlphaToCoverageEnable = false; 486 | desc.RenderTarget[0].BlendEnable = true; 487 | desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; 488 | desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; 489 | desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; 490 | desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; 491 | desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; 492 | desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; 493 | desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; 494 | bd->pd3dDevice->CreateBlendState(&desc, &bd->pBlendState); 495 | } 496 | 497 | // Create the rasterizer state 498 | { 499 | D3D11_RASTERIZER_DESC desc; 500 | ZeroMemory(&desc, sizeof(desc)); 501 | desc.FillMode = D3D11_FILL_SOLID; 502 | desc.CullMode = D3D11_CULL_NONE; 503 | desc.ScissorEnable = true; 504 | desc.DepthClipEnable = true; 505 | bd->pd3dDevice->CreateRasterizerState(&desc, &bd->pRasterizerState); 506 | } 507 | 508 | // Create depth-stencil State 509 | { 510 | D3D11_DEPTH_STENCIL_DESC desc; 511 | ZeroMemory(&desc, sizeof(desc)); 512 | desc.DepthEnable = false; 513 | desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; 514 | desc.DepthFunc = D3D11_COMPARISON_ALWAYS; 515 | desc.StencilEnable = false; 516 | desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; 517 | desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; 518 | desc.BackFace = desc.FrontFace; 519 | bd->pd3dDevice->CreateDepthStencilState(&desc, &bd->pDepthStencilState); 520 | } 521 | 522 | ImGui_ImplDX11_CreateFontsTexture(); 523 | 524 | return true; 525 | } 526 | 527 | void ImGui_ImplDX11_InvalidateDeviceObjects() 528 | { 529 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 530 | if (!bd->pd3dDevice) 531 | return; 532 | 533 | if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = nullptr; } 534 | if (bd->pFontTextureView) { bd->pFontTextureView->Release(); bd->pFontTextureView = nullptr; ImGui::GetIO().Fonts->SetTexID(0); } // We copied data->pFontTextureView to io.Fonts->TexID so let's clear that as well. 535 | if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } 536 | if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } 537 | if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; } 538 | if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = nullptr; } 539 | if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = nullptr; } 540 | if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = nullptr; } 541 | if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = nullptr; } 542 | if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = nullptr; } 543 | if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = nullptr; } 544 | } 545 | 546 | bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context) 547 | { 548 | ImGuiIO& io = ImGui::GetIO(); 549 | IMGUI_CHECKVERSION(); 550 | IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); 551 | 552 | // Setup backend capabilities flags 553 | ImGui_ImplDX11_Data* bd = IM_NEW(ImGui_ImplDX11_Data)(); 554 | io.BackendRendererUserData = (void*)bd; 555 | io.BackendRendererName = "imgui_impl_dx11"; 556 | io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. 557 | 558 | // Get factory from device 559 | IDXGIDevice* pDXGIDevice = nullptr; 560 | IDXGIAdapter* pDXGIAdapter = nullptr; 561 | IDXGIFactory* pFactory = nullptr; 562 | 563 | if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK) 564 | if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK) 565 | if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK) 566 | { 567 | bd->pd3dDevice = device; 568 | bd->pd3dDeviceContext = device_context; 569 | bd->pFactory = pFactory; 570 | } 571 | if (pDXGIDevice) pDXGIDevice->Release(); 572 | if (pDXGIAdapter) pDXGIAdapter->Release(); 573 | bd->pd3dDevice->AddRef(); 574 | bd->pd3dDeviceContext->AddRef(); 575 | 576 | return true; 577 | } 578 | 579 | void ImGui_ImplDX11_Shutdown() 580 | { 581 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 582 | IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); 583 | ImGuiIO& io = ImGui::GetIO(); 584 | 585 | ImGui_ImplDX11_InvalidateDeviceObjects(); 586 | if (bd->pFactory) { bd->pFactory->Release(); } 587 | if (bd->pd3dDevice) { bd->pd3dDevice->Release(); } 588 | if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); } 589 | io.BackendRendererName = nullptr; 590 | io.BackendRendererUserData = nullptr; 591 | io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; 592 | IM_DELETE(bd); 593 | } 594 | 595 | void ImGui_ImplDX11_NewFrame() 596 | { 597 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 598 | IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplDX11_Init()?"); 599 | 600 | if (!bd->pFontSampler) 601 | ImGui_ImplDX11_CreateDeviceObjects(); 602 | } 603 | 604 | //----------------------------------------------------------------------------- 605 | 606 | #endif // #ifndef IMGUI_DISABLE 607 | -------------------------------------------------------------------------------- /cs2-external-cheat/imgui/imgui_impl_dx11.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX11 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | 8 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 9 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 10 | // Learn about Dear ImGui: 11 | // - FAQ https://dearimgui.com/faq 12 | // - Getting Started https://dearimgui.com/getting-started 13 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 14 | // - Introduction, links and more at the top of imgui.cpp 15 | 16 | #pragma once 17 | #include "imgui.h" // IMGUI_IMPL_API 18 | #ifndef IMGUI_DISABLE 19 | 20 | struct ID3D11Device; 21 | struct ID3D11DeviceContext; 22 | 23 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 24 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 25 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 26 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 27 | 28 | // Use if you want to reset your rendering device without losing Dear ImGui state. 29 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 30 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 31 | 32 | #endif // #ifndef IMGUI_DISABLE 33 | -------------------------------------------------------------------------------- /cs2-external-cheat/imgui/imgui_impl_win32.cpp: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for Windows (standard windows API for 32-bits AND 64-bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. 7 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 10 | 11 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 12 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 13 | // Learn about Dear ImGui: 14 | // - FAQ https://dearimgui.com/faq 15 | // - Getting Started https://dearimgui.com/getting-started 16 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 17 | // - Introduction, links and more at the top of imgui.cpp 18 | 19 | // Configuration flags to add in your imconfig file: 20 | //#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD // Disable gamepad support. This was meaningful before <1.81 but we now load XInput dynamically so the option is now less relevant. 21 | 22 | // CHANGELOG 23 | // (minor and older changes stripped away, please see git history for details) 24 | // 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys. 25 | // 2023-09-25: Inputs: Synthesize key-down event on key-up for VK_SNAPSHOT / ImGuiKey_PrintScreen as Windows doesn't emit it (same behavior as GLFW/SDL). 26 | // 2023-09-07: Inputs: Added support for keyboard codepage conversion for when application is compiled in MBCS mode and using a non-Unicode window. 27 | // 2023-04-19: Added ImGui_ImplWin32_InitForOpenGL() to facilitate combining raw Win32/Winapi with OpenGL. (#3218) 28 | // 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen. (#2702) 29 | // 2023-02-15: Inputs: Use WM_NCMOUSEMOVE / WM_NCMOUSELEAVE to track mouse position over non-client area (e.g. OS decorations) when app is not focused. (#6045, #6162) 30 | // 2023-02-02: Inputs: Flipping WM_MOUSEHWHEEL (horizontal mouse-wheel) value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463) 31 | // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. 32 | // 2022-09-28: Inputs: Convert WM_CHAR values with MultiByteToWideChar() when window class was registered as MBCS (not Unicode). 33 | // 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). 34 | // 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. 35 | // 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[]. 36 | // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). 37 | // 2022-01-17: Inputs: always update key mods next and before a key event (not in NewFrame) to fix input queue with very low framerates. 38 | // 2022-01-12: Inputs: Update mouse inputs using WM_MOUSEMOVE/WM_MOUSELEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API. 39 | // 2022-01-12: Inputs: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted. 40 | // 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range. 41 | // 2021-12-16: Inputs: Fill VK_LCONTROL/VK_RCONTROL/VK_LSHIFT/VK_RSHIFT/VK_LMENU/VK_RMENU for completeness. 42 | // 2021-08-17: Calling io.AddFocusEvent() on WM_SETFOCUS/WM_KILLFOCUS messages. 43 | // 2021-08-02: Inputs: Fixed keyboard modifiers being reported when host window doesn't have focus. 44 | // 2021-07-29: Inputs: MousePos is correctly reported when the host platform window is hovered but not focused (using TrackMouseEvent() to receive WM_MOUSELEAVE events). 45 | // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). 46 | // 2021-06-08: Fixed ImGui_ImplWin32_EnableDpiAwareness() and ImGui_ImplWin32_GetDpiScaleForMonitor() to handle Windows 8.1/10 features without a manifest (per-monitor DPI, and properly calls SetProcessDpiAwareness() on 8.1). 47 | // 2021-03-23: Inputs: Clearing keyboard down array when losing focus (WM_KILLFOCUS). 48 | // 2021-02-18: Added ImGui_ImplWin32_EnableAlphaCompositing(). Non Visual Studio users will need to link with dwmapi.lib (MinGW/gcc: use -ldwmapi). 49 | // 2021-02-17: Fixed ImGui_ImplWin32_EnableDpiAwareness() attempting to get SetProcessDpiAwareness from shcore.dll on Windows 8 whereas it is only supported on Windows 8.1. 50 | // 2021-01-25: Inputs: Dynamically loading XInput DLL. 51 | // 2020-12-04: Misc: Fixed setting of io.DisplaySize to invalid/uninitialized data when after hwnd has been closed. 52 | // 2020-03-03: Inputs: Calling AddInputCharacterUTF16() to support surrogate pairs leading to codepoint >= 0x10000 (for more complete CJK inputs) 53 | // 2020-02-17: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helper functions. 54 | // 2020-01-14: Inputs: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD/IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT. 55 | // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. 56 | // 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter(). 57 | // 2019-01-17: Misc: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created in a different thread or parent. 58 | // 2019-01-17: Inputs: Added support for mouse buttons 4 and 5 via WM_XBUTTON* messages. 59 | // 2019-01-15: Inputs: Added support for XInput gamepads (if ImGuiConfigFlags_NavEnableGamepad is set by user application). 60 | // 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window. 61 | // 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor. 62 | // 2018-06-10: Inputs: Fixed handling of mouse wheel messages to support fine position messages (typically sent by track-pads). 63 | // 2018-06-08: Misc: Extracted imgui_impl_win32.cpp/.h away from the old combined DX9/DX10/DX11/DX12 examples. 64 | // 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors and ImGuiBackendFlags_HasSetMousePos flags + honor ImGuiConfigFlags_NoMouseCursorChange flag. 65 | // 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value and WM_SETCURSOR message handling). 66 | // 2018-02-06: Inputs: Added mapping for ImGuiKey_Space. 67 | // 2018-02-06: Inputs: Honoring the io.WantSetMousePos by repositioning the mouse (when using navigation and ImGuiConfigFlags_NavMoveMouse is set). 68 | // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. 69 | // 2018-01-20: Inputs: Added Horizontal Mouse Wheel support. 70 | // 2018-01-08: Inputs: Added mapping for ImGuiKey_Insert. 71 | // 2018-01-05: Inputs: Added WM_LBUTTONDBLCLK double-click handlers for window classes with the CS_DBLCLKS flag. 72 | // 2017-10-23: Inputs: Added WM_SYSKEYDOWN / WM_SYSKEYUP handlers so e.g. the VK_MENU key can be read. 73 | // 2017-10-23: Inputs: Using Win32 ::SetCapture/::GetCapture() to retrieve mouse positions outside the client area when dragging. 74 | // 2016-11-12: Inputs: Only call Win32 ::SetCursor(nullptr) when io.MouseDrawCursor is set. 75 | 76 | #include "imgui.h" 77 | #ifndef IMGUI_DISABLE 78 | #include "imgui_impl_win32.h" 79 | #ifndef WIN32_LEAN_AND_MEAN 80 | #define WIN32_LEAN_AND_MEAN 81 | #endif 82 | #include 83 | #include // GET_X_LPARAM(), GET_Y_LPARAM() 84 | #include 85 | #include 86 | 87 | // Using XInput for gamepad (will load DLL dynamically) 88 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 89 | #include 90 | typedef DWORD(WINAPI* PFN_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES*); 91 | typedef DWORD(WINAPI* PFN_XInputGetState)(DWORD, XINPUT_STATE*); 92 | #endif 93 | 94 | // Clang/GCC warnings with -Weverything 95 | #if defined(__clang__) 96 | #pragma clang diagnostic push 97 | #pragma clang diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader) 98 | #endif 99 | #if defined(__GNUC__) 100 | #pragma GCC diagnostic push 101 | #pragma GCC diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader) 102 | #endif 103 | 104 | struct ImGui_ImplWin32_Data 105 | { 106 | HWND hWnd; 107 | HWND MouseHwnd; 108 | int MouseTrackedArea; // 0: not tracked, 1: client are, 2: non-client area 109 | int MouseButtonsDown; 110 | INT64 Time; 111 | INT64 TicksPerSecond; 112 | ImGuiMouseCursor LastMouseCursor; 113 | UINT32 KeyboardCodePage; 114 | 115 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 116 | bool HasGamepad; 117 | bool WantUpdateHasGamepad; 118 | HMODULE XInputDLL; 119 | PFN_XInputGetCapabilities XInputGetCapabilities; 120 | PFN_XInputGetState XInputGetState; 121 | #endif 122 | 123 | ImGui_ImplWin32_Data() { memset((void*)this, 0, sizeof(*this)); } 124 | }; 125 | 126 | // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts 127 | // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. 128 | // FIXME: multi-context support is not well tested and probably dysfunctional in this backend. 129 | // FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context. 130 | static ImGui_ImplWin32_Data* ImGui_ImplWin32_GetBackendData() 131 | { 132 | return ImGui::GetCurrentContext() ? (ImGui_ImplWin32_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr; 133 | } 134 | 135 | // Functions 136 | static void ImGui_ImplWin32_UpdateKeyboardCodePage() 137 | { 138 | // Retrieve keyboard code page, required for handling of non-Unicode Windows. 139 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 140 | HKL keyboard_layout = ::GetKeyboardLayout(0); 141 | LCID keyboard_lcid = MAKELCID(HIWORD(keyboard_layout), SORT_DEFAULT); 142 | if (::GetLocaleInfoA(keyboard_lcid, (LOCALE_RETURN_NUMBER | LOCALE_IDEFAULTANSICODEPAGE), (LPSTR)&bd->KeyboardCodePage, sizeof(bd->KeyboardCodePage)) == 0) 143 | bd->KeyboardCodePage = CP_ACP; // Fallback to default ANSI code page when fails. 144 | } 145 | 146 | static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc) 147 | { 148 | ImGuiIO& io = ImGui::GetIO(); 149 | IMGUI_CHECKVERSION(); 150 | IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); 151 | 152 | INT64 perf_frequency, perf_counter; 153 | if (!::QueryPerformanceFrequency((LARGE_INTEGER*)&perf_frequency)) 154 | return false; 155 | if (!::QueryPerformanceCounter((LARGE_INTEGER*)&perf_counter)) 156 | return false; 157 | 158 | // Setup backend capabilities flags 159 | ImGui_ImplWin32_Data* bd = IM_NEW(ImGui_ImplWin32_Data)(); 160 | io.BackendPlatformUserData = (void*)bd; 161 | io.BackendPlatformName = "imgui_impl_win32"; 162 | io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) 163 | io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) 164 | 165 | bd->hWnd = (HWND)hwnd; 166 | bd->TicksPerSecond = perf_frequency; 167 | bd->Time = perf_counter; 168 | bd->LastMouseCursor = ImGuiMouseCursor_COUNT; 169 | ImGui_ImplWin32_UpdateKeyboardCodePage(); 170 | 171 | // Set platform dependent data in viewport 172 | ImGui::GetMainViewport()->PlatformHandleRaw = (void*)hwnd; 173 | IM_UNUSED(platform_has_own_dc); // Used in 'docking' branch 174 | 175 | // Dynamically load XInput library 176 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 177 | bd->WantUpdateHasGamepad = true; 178 | const char* xinput_dll_names[] = 179 | { 180 | "xinput1_4.dll", // Windows 8+ 181 | "xinput1_3.dll", // DirectX SDK 182 | "xinput9_1_0.dll", // Windows Vista, Windows 7 183 | "xinput1_2.dll", // DirectX SDK 184 | "xinput1_1.dll" // DirectX SDK 185 | }; 186 | for (int n = 0; n < IM_ARRAYSIZE(xinput_dll_names); n++) 187 | if (HMODULE dll = ::LoadLibraryA(xinput_dll_names[n])) 188 | { 189 | bd->XInputDLL = dll; 190 | bd->XInputGetCapabilities = (PFN_XInputGetCapabilities)::GetProcAddress(dll, "XInputGetCapabilities"); 191 | bd->XInputGetState = (PFN_XInputGetState)::GetProcAddress(dll, "XInputGetState"); 192 | break; 193 | } 194 | #endif // IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 195 | 196 | return true; 197 | } 198 | 199 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd) 200 | { 201 | return ImGui_ImplWin32_InitEx(hwnd, false); 202 | } 203 | 204 | IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd) 205 | { 206 | // OpenGL needs CS_OWNDC 207 | return ImGui_ImplWin32_InitEx(hwnd, true); 208 | } 209 | 210 | void ImGui_ImplWin32_Shutdown() 211 | { 212 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 213 | IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); 214 | ImGuiIO& io = ImGui::GetIO(); 215 | 216 | // Unload XInput library 217 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 218 | if (bd->XInputDLL) 219 | ::FreeLibrary(bd->XInputDLL); 220 | #endif // IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 221 | 222 | io.BackendPlatformName = nullptr; 223 | io.BackendPlatformUserData = nullptr; 224 | io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad); 225 | IM_DELETE(bd); 226 | } 227 | 228 | static bool ImGui_ImplWin32_UpdateMouseCursor() 229 | { 230 | ImGuiIO& io = ImGui::GetIO(); 231 | if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) 232 | return false; 233 | 234 | ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor(); 235 | if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor) 236 | { 237 | // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor 238 | ::SetCursor(nullptr); 239 | } 240 | else 241 | { 242 | // Show OS mouse cursor 243 | LPTSTR win32_cursor = IDC_ARROW; 244 | switch (imgui_cursor) 245 | { 246 | case ImGuiMouseCursor_Arrow: win32_cursor = IDC_ARROW; break; 247 | case ImGuiMouseCursor_TextInput: win32_cursor = IDC_IBEAM; break; 248 | case ImGuiMouseCursor_ResizeAll: win32_cursor = IDC_SIZEALL; break; 249 | case ImGuiMouseCursor_ResizeEW: win32_cursor = IDC_SIZEWE; break; 250 | case ImGuiMouseCursor_ResizeNS: win32_cursor = IDC_SIZENS; break; 251 | case ImGuiMouseCursor_ResizeNESW: win32_cursor = IDC_SIZENESW; break; 252 | case ImGuiMouseCursor_ResizeNWSE: win32_cursor = IDC_SIZENWSE; break; 253 | case ImGuiMouseCursor_Hand: win32_cursor = IDC_HAND; break; 254 | case ImGuiMouseCursor_NotAllowed: win32_cursor = IDC_NO; break; 255 | } 256 | ::SetCursor(::LoadCursor(nullptr, win32_cursor)); 257 | } 258 | return true; 259 | } 260 | 261 | static bool IsVkDown(int vk) 262 | { 263 | return (::GetKeyState(vk) & 0x8000) != 0; 264 | } 265 | 266 | static void ImGui_ImplWin32_AddKeyEvent(ImGuiKey key, bool down, int native_keycode, int native_scancode = -1) 267 | { 268 | ImGuiIO& io = ImGui::GetIO(); 269 | io.AddKeyEvent(key, down); 270 | io.SetKeyEventNativeData(key, native_keycode, native_scancode); // To support legacy indexing (<1.87 user code) 271 | IM_UNUSED(native_scancode); 272 | } 273 | 274 | static void ImGui_ImplWin32_ProcessKeyEventsWorkarounds() 275 | { 276 | // Left & right Shift keys: when both are pressed together, Windows tend to not generate the WM_KEYUP event for the first released one. 277 | if (ImGui::IsKeyDown(ImGuiKey_LeftShift) && !IsVkDown(VK_LSHIFT)) 278 | ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftShift, false, VK_LSHIFT); 279 | if (ImGui::IsKeyDown(ImGuiKey_RightShift) && !IsVkDown(VK_RSHIFT)) 280 | ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightShift, false, VK_RSHIFT); 281 | 282 | // Sometimes WM_KEYUP for Win key is not passed down to the app (e.g. for Win+V on some setups, according to GLFW). 283 | if (ImGui::IsKeyDown(ImGuiKey_LeftSuper) && !IsVkDown(VK_LWIN)) 284 | ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftSuper, false, VK_LWIN); 285 | if (ImGui::IsKeyDown(ImGuiKey_RightSuper) && !IsVkDown(VK_RWIN)) 286 | ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightSuper, false, VK_RWIN); 287 | } 288 | 289 | static void ImGui_ImplWin32_UpdateKeyModifiers() 290 | { 291 | ImGuiIO& io = ImGui::GetIO(); 292 | io.AddKeyEvent(ImGuiMod_Ctrl, IsVkDown(VK_CONTROL)); 293 | io.AddKeyEvent(ImGuiMod_Shift, IsVkDown(VK_SHIFT)); 294 | io.AddKeyEvent(ImGuiMod_Alt, IsVkDown(VK_MENU)); 295 | io.AddKeyEvent(ImGuiMod_Super, IsVkDown(VK_APPS)); 296 | } 297 | 298 | static void ImGui_ImplWin32_UpdateMouseData() 299 | { 300 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 301 | ImGuiIO& io = ImGui::GetIO(); 302 | IM_ASSERT(bd->hWnd != 0); 303 | 304 | HWND focused_window = ::GetForegroundWindow(); 305 | const bool is_app_focused = (focused_window == bd->hWnd); 306 | if (is_app_focused) 307 | { 308 | // (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) 309 | if (io.WantSetMousePos) 310 | { 311 | POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; 312 | if (::ClientToScreen(bd->hWnd, &pos)) 313 | ::SetCursorPos(pos.x, pos.y); 314 | } 315 | 316 | // (Optional) Fallback to provide mouse position when focused (WM_MOUSEMOVE already provides this when hovered or captured) 317 | // This also fills a short gap when clicking non-client area: WM_NCMOUSELEAVE -> modal OS move -> gap -> WM_NCMOUSEMOVE 318 | if (!io.WantSetMousePos && bd->MouseTrackedArea == 0) 319 | { 320 | POINT pos; 321 | if (::GetCursorPos(&pos) && ::ScreenToClient(bd->hWnd, &pos)) 322 | io.AddMousePosEvent((float)pos.x, (float)pos.y); 323 | } 324 | } 325 | } 326 | 327 | // Gamepad navigation mapping 328 | static void ImGui_ImplWin32_UpdateGamepads() 329 | { 330 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 331 | ImGuiIO& io = ImGui::GetIO(); 332 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 333 | //if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. 334 | // return; 335 | 336 | // Calling XInputGetState() every frame on disconnected gamepads is unfortunately too slow. 337 | // Instead we refresh gamepad availability by calling XInputGetCapabilities() _only_ after receiving WM_DEVICECHANGE. 338 | if (bd->WantUpdateHasGamepad) 339 | { 340 | XINPUT_CAPABILITIES caps = {}; 341 | bd->HasGamepad = bd->XInputGetCapabilities ? (bd->XInputGetCapabilities(0, XINPUT_FLAG_GAMEPAD, &caps) == ERROR_SUCCESS) : false; 342 | bd->WantUpdateHasGamepad = false; 343 | } 344 | 345 | io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; 346 | XINPUT_STATE xinput_state; 347 | XINPUT_GAMEPAD& gamepad = xinput_state.Gamepad; 348 | if (!bd->HasGamepad || bd->XInputGetState == nullptr || bd->XInputGetState(0, &xinput_state) != ERROR_SUCCESS) 349 | return; 350 | io.BackendFlags |= ImGuiBackendFlags_HasGamepad; 351 | 352 | #define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V) 353 | #define MAP_BUTTON(KEY_NO, BUTTON_ENUM) { io.AddKeyEvent(KEY_NO, (gamepad.wButtons & BUTTON_ENUM) != 0); } 354 | #define MAP_ANALOG(KEY_NO, VALUE, V0, V1) { float vn = (float)(VALUE - V0) / (float)(V1 - V0); io.AddKeyAnalogEvent(KEY_NO, vn > 0.10f, IM_SATURATE(vn)); } 355 | MAP_BUTTON(ImGuiKey_GamepadStart, XINPUT_GAMEPAD_START); 356 | MAP_BUTTON(ImGuiKey_GamepadBack, XINPUT_GAMEPAD_BACK); 357 | MAP_BUTTON(ImGuiKey_GamepadFaceLeft, XINPUT_GAMEPAD_X); 358 | MAP_BUTTON(ImGuiKey_GamepadFaceRight, XINPUT_GAMEPAD_B); 359 | MAP_BUTTON(ImGuiKey_GamepadFaceUp, XINPUT_GAMEPAD_Y); 360 | MAP_BUTTON(ImGuiKey_GamepadFaceDown, XINPUT_GAMEPAD_A); 361 | MAP_BUTTON(ImGuiKey_GamepadDpadLeft, XINPUT_GAMEPAD_DPAD_LEFT); 362 | MAP_BUTTON(ImGuiKey_GamepadDpadRight, XINPUT_GAMEPAD_DPAD_RIGHT); 363 | MAP_BUTTON(ImGuiKey_GamepadDpadUp, XINPUT_GAMEPAD_DPAD_UP); 364 | MAP_BUTTON(ImGuiKey_GamepadDpadDown, XINPUT_GAMEPAD_DPAD_DOWN); 365 | MAP_BUTTON(ImGuiKey_GamepadL1, XINPUT_GAMEPAD_LEFT_SHOULDER); 366 | MAP_BUTTON(ImGuiKey_GamepadR1, XINPUT_GAMEPAD_RIGHT_SHOULDER); 367 | MAP_ANALOG(ImGuiKey_GamepadL2, gamepad.bLeftTrigger, XINPUT_GAMEPAD_TRIGGER_THRESHOLD, 255); 368 | MAP_ANALOG(ImGuiKey_GamepadR2, gamepad.bRightTrigger, XINPUT_GAMEPAD_TRIGGER_THRESHOLD, 255); 369 | MAP_BUTTON(ImGuiKey_GamepadL3, XINPUT_GAMEPAD_LEFT_THUMB); 370 | MAP_BUTTON(ImGuiKey_GamepadR3, XINPUT_GAMEPAD_RIGHT_THUMB); 371 | MAP_ANALOG(ImGuiKey_GamepadLStickLeft, gamepad.sThumbLX, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 372 | MAP_ANALOG(ImGuiKey_GamepadLStickRight, gamepad.sThumbLX, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 373 | MAP_ANALOG(ImGuiKey_GamepadLStickUp, gamepad.sThumbLY, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 374 | MAP_ANALOG(ImGuiKey_GamepadLStickDown, gamepad.sThumbLY, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 375 | MAP_ANALOG(ImGuiKey_GamepadRStickLeft, gamepad.sThumbRX, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 376 | MAP_ANALOG(ImGuiKey_GamepadRStickRight, gamepad.sThumbRX, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 377 | MAP_ANALOG(ImGuiKey_GamepadRStickUp, gamepad.sThumbRY, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 378 | MAP_ANALOG(ImGuiKey_GamepadRStickDown, gamepad.sThumbRY, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 379 | #undef MAP_BUTTON 380 | #undef MAP_ANALOG 381 | #endif // #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 382 | } 383 | 384 | void ImGui_ImplWin32_NewFrame() 385 | { 386 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 387 | IM_ASSERT(bd != nullptr && "Context or backend not initialized? Did you call ImGui_ImplWin32_Init()?"); 388 | ImGuiIO& io = ImGui::GetIO(); 389 | 390 | // Setup display size (every frame to accommodate for window resizing) 391 | RECT rect = { 0, 0, 0, 0 }; 392 | ::GetClientRect(bd->hWnd, &rect); 393 | io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); 394 | 395 | // Setup time step 396 | INT64 current_time = 0; 397 | ::QueryPerformanceCounter((LARGE_INTEGER*)¤t_time); 398 | io.DeltaTime = (float)(current_time - bd->Time) / bd->TicksPerSecond; 399 | bd->Time = current_time; 400 | 401 | // Update OS mouse position 402 | ImGui_ImplWin32_UpdateMouseData(); 403 | 404 | // Process workarounds for known Windows key handling issues 405 | ImGui_ImplWin32_ProcessKeyEventsWorkarounds(); 406 | 407 | // Update OS mouse cursor with the cursor requested by imgui 408 | ImGuiMouseCursor mouse_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor(); 409 | if (bd->LastMouseCursor != mouse_cursor) 410 | { 411 | bd->LastMouseCursor = mouse_cursor; 412 | ImGui_ImplWin32_UpdateMouseCursor(); 413 | } 414 | 415 | // Update game controllers (if enabled and available) 416 | ImGui_ImplWin32_UpdateGamepads(); 417 | } 418 | 419 | // There is no distinct VK_xxx for keypad enter, instead it is VK_RETURN + KF_EXTENDED, we assign it an arbitrary value to make code more readable (VK_ codes go up to 255) 420 | #define IM_VK_KEYPAD_ENTER (VK_RETURN + 256) 421 | 422 | // Map VK_xxx to ImGuiKey_xxx. 423 | static ImGuiKey ImGui_ImplWin32_VirtualKeyToImGuiKey(WPARAM wParam) 424 | { 425 | switch (wParam) 426 | { 427 | case VK_TAB: return ImGuiKey_Tab; 428 | case VK_LEFT: return ImGuiKey_LeftArrow; 429 | case VK_RIGHT: return ImGuiKey_RightArrow; 430 | case VK_UP: return ImGuiKey_UpArrow; 431 | case VK_DOWN: return ImGuiKey_DownArrow; 432 | case VK_PRIOR: return ImGuiKey_PageUp; 433 | case VK_NEXT: return ImGuiKey_PageDown; 434 | case VK_HOME: return ImGuiKey_Home; 435 | case VK_END: return ImGuiKey_End; 436 | case VK_INSERT: return ImGuiKey_Insert; 437 | case VK_DELETE: return ImGuiKey_Delete; 438 | case VK_BACK: return ImGuiKey_Backspace; 439 | case VK_SPACE: return ImGuiKey_Space; 440 | case VK_RETURN: return ImGuiKey_Enter; 441 | case VK_ESCAPE: return ImGuiKey_Escape; 442 | case VK_OEM_7: return ImGuiKey_Apostrophe; 443 | case VK_OEM_COMMA: return ImGuiKey_Comma; 444 | case VK_OEM_MINUS: return ImGuiKey_Minus; 445 | case VK_OEM_PERIOD: return ImGuiKey_Period; 446 | case VK_OEM_2: return ImGuiKey_Slash; 447 | case VK_OEM_1: return ImGuiKey_Semicolon; 448 | case VK_OEM_PLUS: return ImGuiKey_Equal; 449 | case VK_OEM_4: return ImGuiKey_LeftBracket; 450 | case VK_OEM_5: return ImGuiKey_Backslash; 451 | case VK_OEM_6: return ImGuiKey_RightBracket; 452 | case VK_OEM_3: return ImGuiKey_GraveAccent; 453 | case VK_CAPITAL: return ImGuiKey_CapsLock; 454 | case VK_SCROLL: return ImGuiKey_ScrollLock; 455 | case VK_NUMLOCK: return ImGuiKey_NumLock; 456 | case VK_SNAPSHOT: return ImGuiKey_PrintScreen; 457 | case VK_PAUSE: return ImGuiKey_Pause; 458 | case VK_NUMPAD0: return ImGuiKey_Keypad0; 459 | case VK_NUMPAD1: return ImGuiKey_Keypad1; 460 | case VK_NUMPAD2: return ImGuiKey_Keypad2; 461 | case VK_NUMPAD3: return ImGuiKey_Keypad3; 462 | case VK_NUMPAD4: return ImGuiKey_Keypad4; 463 | case VK_NUMPAD5: return ImGuiKey_Keypad5; 464 | case VK_NUMPAD6: return ImGuiKey_Keypad6; 465 | case VK_NUMPAD7: return ImGuiKey_Keypad7; 466 | case VK_NUMPAD8: return ImGuiKey_Keypad8; 467 | case VK_NUMPAD9: return ImGuiKey_Keypad9; 468 | case VK_DECIMAL: return ImGuiKey_KeypadDecimal; 469 | case VK_DIVIDE: return ImGuiKey_KeypadDivide; 470 | case VK_MULTIPLY: return ImGuiKey_KeypadMultiply; 471 | case VK_SUBTRACT: return ImGuiKey_KeypadSubtract; 472 | case VK_ADD: return ImGuiKey_KeypadAdd; 473 | case IM_VK_KEYPAD_ENTER: return ImGuiKey_KeypadEnter; 474 | case VK_LSHIFT: return ImGuiKey_LeftShift; 475 | case VK_LCONTROL: return ImGuiKey_LeftCtrl; 476 | case VK_LMENU: return ImGuiKey_LeftAlt; 477 | case VK_LWIN: return ImGuiKey_LeftSuper; 478 | case VK_RSHIFT: return ImGuiKey_RightShift; 479 | case VK_RCONTROL: return ImGuiKey_RightCtrl; 480 | case VK_RMENU: return ImGuiKey_RightAlt; 481 | case VK_RWIN: return ImGuiKey_RightSuper; 482 | case VK_APPS: return ImGuiKey_Menu; 483 | case '0': return ImGuiKey_0; 484 | case '1': return ImGuiKey_1; 485 | case '2': return ImGuiKey_2; 486 | case '3': return ImGuiKey_3; 487 | case '4': return ImGuiKey_4; 488 | case '5': return ImGuiKey_5; 489 | case '6': return ImGuiKey_6; 490 | case '7': return ImGuiKey_7; 491 | case '8': return ImGuiKey_8; 492 | case '9': return ImGuiKey_9; 493 | case 'A': return ImGuiKey_A; 494 | case 'B': return ImGuiKey_B; 495 | case 'C': return ImGuiKey_C; 496 | case 'D': return ImGuiKey_D; 497 | case 'E': return ImGuiKey_E; 498 | case 'F': return ImGuiKey_F; 499 | case 'G': return ImGuiKey_G; 500 | case 'H': return ImGuiKey_H; 501 | case 'I': return ImGuiKey_I; 502 | case 'J': return ImGuiKey_J; 503 | case 'K': return ImGuiKey_K; 504 | case 'L': return ImGuiKey_L; 505 | case 'M': return ImGuiKey_M; 506 | case 'N': return ImGuiKey_N; 507 | case 'O': return ImGuiKey_O; 508 | case 'P': return ImGuiKey_P; 509 | case 'Q': return ImGuiKey_Q; 510 | case 'R': return ImGuiKey_R; 511 | case 'S': return ImGuiKey_S; 512 | case 'T': return ImGuiKey_T; 513 | case 'U': return ImGuiKey_U; 514 | case 'V': return ImGuiKey_V; 515 | case 'W': return ImGuiKey_W; 516 | case 'X': return ImGuiKey_X; 517 | case 'Y': return ImGuiKey_Y; 518 | case 'Z': return ImGuiKey_Z; 519 | case VK_F1: return ImGuiKey_F1; 520 | case VK_F2: return ImGuiKey_F2; 521 | case VK_F3: return ImGuiKey_F3; 522 | case VK_F4: return ImGuiKey_F4; 523 | case VK_F5: return ImGuiKey_F5; 524 | case VK_F6: return ImGuiKey_F6; 525 | case VK_F7: return ImGuiKey_F7; 526 | case VK_F8: return ImGuiKey_F8; 527 | case VK_F9: return ImGuiKey_F9; 528 | case VK_F10: return ImGuiKey_F10; 529 | case VK_F11: return ImGuiKey_F11; 530 | case VK_F12: return ImGuiKey_F12; 531 | case VK_F13: return ImGuiKey_F13; 532 | case VK_F14: return ImGuiKey_F14; 533 | case VK_F15: return ImGuiKey_F15; 534 | case VK_F16: return ImGuiKey_F16; 535 | case VK_F17: return ImGuiKey_F17; 536 | case VK_F18: return ImGuiKey_F18; 537 | case VK_F19: return ImGuiKey_F19; 538 | case VK_F20: return ImGuiKey_F20; 539 | case VK_F21: return ImGuiKey_F21; 540 | case VK_F22: return ImGuiKey_F22; 541 | case VK_F23: return ImGuiKey_F23; 542 | case VK_F24: return ImGuiKey_F24; 543 | case VK_BROWSER_BACK: return ImGuiKey_AppBack; 544 | case VK_BROWSER_FORWARD: return ImGuiKey_AppForward; 545 | default: return ImGuiKey_None; 546 | } 547 | } 548 | 549 | // Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions. 550 | #ifndef WM_MOUSEHWHEEL 551 | #define WM_MOUSEHWHEEL 0x020E 552 | #endif 553 | #ifndef DBT_DEVNODES_CHANGED 554 | #define DBT_DEVNODES_CHANGED 0x0007 555 | #endif 556 | 557 | // Win32 message handler (process Win32 mouse/keyboard inputs, etc.) 558 | // Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. 559 | // When implementing your own backend, you can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if Dear ImGui wants to use your inputs. 560 | // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. 561 | // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. 562 | // Generally you may always pass all inputs to Dear ImGui, and hide them from your application based on those two flags. 563 | // PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinates when dragging mouse outside of our window bounds. 564 | // PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag. 565 | #if 0 566 | // Copy this line into your .cpp file to forward declare the function. 567 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 568 | #endif 569 | 570 | // See https://learn.microsoft.com/en-us/windows/win32/tablet/system-events-and-mouse-messages 571 | // Prefer to call this at the top of the message handler to avoid the possibility of other Win32 calls interfering with this. 572 | static ImGuiMouseSource GetMouseSourceFromMessageExtraInfo() 573 | { 574 | LPARAM extra_info = ::GetMessageExtraInfo(); 575 | if ((extra_info & 0xFFFFFF80) == 0xFF515700) 576 | return ImGuiMouseSource_Pen; 577 | if ((extra_info & 0xFFFFFF80) == 0xFF515780) 578 | return ImGuiMouseSource_TouchScreen; 579 | return ImGuiMouseSource_Mouse; 580 | } 581 | 582 | IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 583 | { 584 | // Most backends don't have silent checks like this one, but we need it because WndProc are called early in CreateWindow(). 585 | // We silently allow both context or just only backend data to be nullptr. 586 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 587 | if (bd == nullptr) 588 | return 0; 589 | ImGuiIO& io = ImGui::GetIO(); 590 | 591 | switch (msg) 592 | { 593 | case WM_MOUSEMOVE: 594 | case WM_NCMOUSEMOVE: 595 | { 596 | // We need to call TrackMouseEvent in order to receive WM_MOUSELEAVE events 597 | ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); 598 | const int area = (msg == WM_MOUSEMOVE) ? 1 : 2; 599 | bd->MouseHwnd = hwnd; 600 | if (bd->MouseTrackedArea != area) 601 | { 602 | TRACKMOUSEEVENT tme_cancel = { sizeof(tme_cancel), TME_CANCEL, hwnd, 0 }; 603 | TRACKMOUSEEVENT tme_track = { sizeof(tme_track), (DWORD)((area == 2) ? (TME_LEAVE | TME_NONCLIENT) : TME_LEAVE), hwnd, 0 }; 604 | if (bd->MouseTrackedArea != 0) 605 | ::TrackMouseEvent(&tme_cancel); 606 | ::TrackMouseEvent(&tme_track); 607 | bd->MouseTrackedArea = area; 608 | } 609 | POINT mouse_pos = { (LONG)GET_X_LPARAM(lParam), (LONG)GET_Y_LPARAM(lParam) }; 610 | if (msg == WM_NCMOUSEMOVE && ::ScreenToClient(hwnd, &mouse_pos) == FALSE) // WM_NCMOUSEMOVE are provided in absolute coordinates. 611 | return 0; 612 | io.AddMouseSourceEvent(mouse_source); 613 | io.AddMousePosEvent((float)mouse_pos.x, (float)mouse_pos.y); 614 | return 0; 615 | } 616 | case WM_MOUSELEAVE: 617 | case WM_NCMOUSELEAVE: 618 | { 619 | const int area = (msg == WM_MOUSELEAVE) ? 1 : 2; 620 | if (bd->MouseTrackedArea == area) 621 | { 622 | if (bd->MouseHwnd == hwnd) 623 | bd->MouseHwnd = nullptr; 624 | bd->MouseTrackedArea = 0; 625 | io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); 626 | } 627 | return 0; 628 | } 629 | case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: 630 | case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: 631 | case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: 632 | case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: 633 | { 634 | ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); 635 | int button = 0; 636 | if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) { button = 0; } 637 | if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) { button = 1; } 638 | if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) { button = 2; } 639 | if (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONDBLCLK) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; } 640 | if (bd->MouseButtonsDown == 0 && ::GetCapture() == nullptr) 641 | ::SetCapture(hwnd); 642 | bd->MouseButtonsDown |= 1 << button; 643 | io.AddMouseSourceEvent(mouse_source); 644 | io.AddMouseButtonEvent(button, true); 645 | return 0; 646 | } 647 | case WM_LBUTTONUP: 648 | case WM_RBUTTONUP: 649 | case WM_MBUTTONUP: 650 | case WM_XBUTTONUP: 651 | { 652 | ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); 653 | int button = 0; 654 | if (msg == WM_LBUTTONUP) { button = 0; } 655 | if (msg == WM_RBUTTONUP) { button = 1; } 656 | if (msg == WM_MBUTTONUP) { button = 2; } 657 | if (msg == WM_XBUTTONUP) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; } 658 | bd->MouseButtonsDown &= ~(1 << button); 659 | if (bd->MouseButtonsDown == 0 && ::GetCapture() == hwnd) 660 | ::ReleaseCapture(); 661 | io.AddMouseSourceEvent(mouse_source); 662 | io.AddMouseButtonEvent(button, false); 663 | return 0; 664 | } 665 | case WM_MOUSEWHEEL: 666 | io.AddMouseWheelEvent(0.0f, (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA); 667 | return 0; 668 | case WM_MOUSEHWHEEL: 669 | io.AddMouseWheelEvent(-(float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA, 0.0f); 670 | return 0; 671 | case WM_KEYDOWN: 672 | case WM_KEYUP: 673 | case WM_SYSKEYDOWN: 674 | case WM_SYSKEYUP: 675 | { 676 | const bool is_key_down = (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN); 677 | if (wParam < 256) 678 | { 679 | // Submit modifiers 680 | ImGui_ImplWin32_UpdateKeyModifiers(); 681 | 682 | // Obtain virtual key code 683 | // (keypad enter doesn't have its own... VK_RETURN with KF_EXTENDED flag means keypad enter, see IM_VK_KEYPAD_ENTER definition for details, it is mapped to ImGuiKey_KeyPadEnter.) 684 | int vk = (int)wParam; 685 | if ((wParam == VK_RETURN) && (HIWORD(lParam) & KF_EXTENDED)) 686 | vk = IM_VK_KEYPAD_ENTER; 687 | const ImGuiKey key = ImGui_ImplWin32_VirtualKeyToImGuiKey(vk); 688 | const int scancode = (int)LOBYTE(HIWORD(lParam)); 689 | 690 | // Special behavior for VK_SNAPSHOT / ImGuiKey_PrintScreen as Windows doesn't emit the key down event. 691 | if (key == ImGuiKey_PrintScreen && !is_key_down) 692 | ImGui_ImplWin32_AddKeyEvent(key, true, vk, scancode); 693 | 694 | // Submit key event 695 | if (key != ImGuiKey_None) 696 | ImGui_ImplWin32_AddKeyEvent(key, is_key_down, vk, scancode); 697 | 698 | // Submit individual left/right modifier events 699 | if (vk == VK_SHIFT) 700 | { 701 | // Important: Shift keys tend to get stuck when pressed together, missing key-up events are corrected in ImGui_ImplWin32_ProcessKeyEventsWorkarounds() 702 | if (IsVkDown(VK_LSHIFT) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftShift, is_key_down, VK_LSHIFT, scancode); } 703 | if (IsVkDown(VK_RSHIFT) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightShift, is_key_down, VK_RSHIFT, scancode); } 704 | } 705 | else if (vk == VK_CONTROL) 706 | { 707 | if (IsVkDown(VK_LCONTROL) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftCtrl, is_key_down, VK_LCONTROL, scancode); } 708 | if (IsVkDown(VK_RCONTROL) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightCtrl, is_key_down, VK_RCONTROL, scancode); } 709 | } 710 | else if (vk == VK_MENU) 711 | { 712 | if (IsVkDown(VK_LMENU) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftAlt, is_key_down, VK_LMENU, scancode); } 713 | if (IsVkDown(VK_RMENU) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightAlt, is_key_down, VK_RMENU, scancode); } 714 | } 715 | } 716 | return 0; 717 | } 718 | case WM_SETFOCUS: 719 | case WM_KILLFOCUS: 720 | io.AddFocusEvent(msg == WM_SETFOCUS); 721 | return 0; 722 | case WM_INPUTLANGCHANGE: 723 | ImGui_ImplWin32_UpdateKeyboardCodePage(); 724 | return 0; 725 | case WM_CHAR: 726 | if (::IsWindowUnicode(hwnd)) 727 | { 728 | // You can also use ToAscii()+GetKeyboardState() to retrieve characters. 729 | if (wParam > 0 && wParam < 0x10000) 730 | io.AddInputCharacterUTF16((unsigned short)wParam); 731 | } 732 | else 733 | { 734 | wchar_t wch = 0; 735 | ::MultiByteToWideChar(bd->KeyboardCodePage, MB_PRECOMPOSED, (char*)&wParam, 1, &wch, 1); 736 | io.AddInputCharacter(wch); 737 | } 738 | return 0; 739 | case WM_SETCURSOR: 740 | // This is required to restore cursor when transitioning from e.g resize borders to client area. 741 | if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor()) 742 | return 1; 743 | return 0; 744 | case WM_DEVICECHANGE: 745 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 746 | if ((UINT)wParam == DBT_DEVNODES_CHANGED) 747 | bd->WantUpdateHasGamepad = true; 748 | #endif 749 | return 0; 750 | } 751 | return 0; 752 | } 753 | 754 | 755 | //-------------------------------------------------------------------------------------------------------- 756 | // DPI-related helpers (optional) 757 | //-------------------------------------------------------------------------------------------------------- 758 | // - Use to enable DPI awareness without having to create an application manifest. 759 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 760 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 761 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 762 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 763 | //--------------------------------------------------------------------------------------------------------- 764 | // This is the scheme successfully used by GLFW (from which we borrowed some of the code) and other apps aiming to be highly portable. 765 | // ImGui_ImplWin32_EnableDpiAwareness() is just a helper called by main.cpp, we don't call it automatically. 766 | // If you are trying to implement your own backend for your own engine, you may ignore that noise. 767 | //--------------------------------------------------------------------------------------------------------- 768 | 769 | // Perform our own check with RtlVerifyVersionInfo() instead of using functions from as they 770 | // require a manifest to be functional for checks above 8.1. See https://github.com/ocornut/imgui/issues/4200 771 | static BOOL _IsWindowsVersionOrGreater(WORD major, WORD minor, WORD) 772 | { 773 | typedef LONG(WINAPI* PFN_RtlVerifyVersionInfo)(OSVERSIONINFOEXW*, ULONG, ULONGLONG); 774 | static PFN_RtlVerifyVersionInfo RtlVerifyVersionInfoFn = nullptr; 775 | if (RtlVerifyVersionInfoFn == nullptr) 776 | if (HMODULE ntdllModule = ::GetModuleHandleA("ntdll.dll")) 777 | RtlVerifyVersionInfoFn = (PFN_RtlVerifyVersionInfo)GetProcAddress(ntdllModule, "RtlVerifyVersionInfo"); 778 | if (RtlVerifyVersionInfoFn == nullptr) 779 | return FALSE; 780 | 781 | RTL_OSVERSIONINFOEXW versionInfo = { }; 782 | ULONGLONG conditionMask = 0; 783 | versionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); 784 | versionInfo.dwMajorVersion = major; 785 | versionInfo.dwMinorVersion = minor; 786 | VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); 787 | VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); 788 | return (RtlVerifyVersionInfoFn(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask) == 0) ? TRUE : FALSE; 789 | } 790 | 791 | #define _IsWindowsVistaOrGreater() _IsWindowsVersionOrGreater(HIBYTE(0x0600), LOBYTE(0x0600), 0) // _WIN32_WINNT_VISTA 792 | #define _IsWindows8OrGreater() _IsWindowsVersionOrGreater(HIBYTE(0x0602), LOBYTE(0x0602), 0) // _WIN32_WINNT_WIN8 793 | #define _IsWindows8Point1OrGreater() _IsWindowsVersionOrGreater(HIBYTE(0x0603), LOBYTE(0x0603), 0) // _WIN32_WINNT_WINBLUE 794 | #define _IsWindows10OrGreater() _IsWindowsVersionOrGreater(HIBYTE(0x0A00), LOBYTE(0x0A00), 0) // _WIN32_WINNT_WINTHRESHOLD / _WIN32_WINNT_WIN10 795 | 796 | #ifndef DPI_ENUMS_DECLARED 797 | typedef enum { PROCESS_DPI_UNAWARE = 0, PROCESS_SYSTEM_DPI_AWARE = 1, PROCESS_PER_MONITOR_DPI_AWARE = 2 } PROCESS_DPI_AWARENESS; 798 | typedef enum { MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2, MDT_DEFAULT = MDT_EFFECTIVE_DPI } MONITOR_DPI_TYPE; 799 | #endif 800 | #ifndef _DPI_AWARENESS_CONTEXTS_ 801 | DECLARE_HANDLE(DPI_AWARENESS_CONTEXT); 802 | #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE (DPI_AWARENESS_CONTEXT)-3 803 | #endif 804 | #ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 805 | #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (DPI_AWARENESS_CONTEXT)-4 806 | #endif 807 | typedef HRESULT(WINAPI* PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS); // Shcore.lib + dll, Windows 8.1+ 808 | typedef HRESULT(WINAPI* PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); // Shcore.lib + dll, Windows 8.1+ 809 | typedef DPI_AWARENESS_CONTEXT(WINAPI* PFN_SetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); // User32.lib + dll, Windows 10 v1607+ (Creators Update) 810 | 811 | // Helper function to enable DPI awareness without setting up a manifest 812 | void ImGui_ImplWin32_EnableDpiAwareness() 813 | { 814 | if (_IsWindows10OrGreater()) 815 | { 816 | static HINSTANCE user32_dll = ::LoadLibraryA("user32.dll"); // Reference counted per-process 817 | if (PFN_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContextFn = (PFN_SetThreadDpiAwarenessContext)::GetProcAddress(user32_dll, "SetThreadDpiAwarenessContext")) 818 | { 819 | SetThreadDpiAwarenessContextFn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); 820 | return; 821 | } 822 | } 823 | if (_IsWindows8Point1OrGreater()) 824 | { 825 | static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process 826 | if (PFN_SetProcessDpiAwareness SetProcessDpiAwarenessFn = (PFN_SetProcessDpiAwareness)::GetProcAddress(shcore_dll, "SetProcessDpiAwareness")) 827 | { 828 | SetProcessDpiAwarenessFn(PROCESS_PER_MONITOR_DPI_AWARE); 829 | return; 830 | } 831 | } 832 | #if _WIN32_WINNT >= 0x0600 833 | ::SetProcessDPIAware(); 834 | #endif 835 | } 836 | 837 | #if defined(_MSC_VER) && !defined(NOGDI) 838 | #pragma comment(lib, "gdi32") // Link with gdi32.lib for GetDeviceCaps(). MinGW will require linking with '-lgdi32' 839 | #endif 840 | 841 | float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor) 842 | { 843 | UINT xdpi = 96, ydpi = 96; 844 | if (_IsWindows8Point1OrGreater()) 845 | { 846 | static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process 847 | static PFN_GetDpiForMonitor GetDpiForMonitorFn = nullptr; 848 | if (GetDpiForMonitorFn == nullptr && shcore_dll != nullptr) 849 | GetDpiForMonitorFn = (PFN_GetDpiForMonitor)::GetProcAddress(shcore_dll, "GetDpiForMonitor"); 850 | if (GetDpiForMonitorFn != nullptr) 851 | { 852 | GetDpiForMonitorFn((HMONITOR)monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi); 853 | IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert! 854 | return xdpi / 96.0f; 855 | } 856 | } 857 | #ifndef NOGDI 858 | const HDC dc = ::GetDC(nullptr); 859 | xdpi = ::GetDeviceCaps(dc, LOGPIXELSX); 860 | ydpi = ::GetDeviceCaps(dc, LOGPIXELSY); 861 | IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert! 862 | ::ReleaseDC(nullptr, dc); 863 | #endif 864 | return xdpi / 96.0f; 865 | } 866 | 867 | float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd) 868 | { 869 | HMONITOR monitor = ::MonitorFromWindow((HWND)hwnd, MONITOR_DEFAULTTONEAREST); 870 | return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); 871 | } 872 | 873 | //--------------------------------------------------------------------------------------------------------- 874 | // Transparency related helpers (optional) 875 | //-------------------------------------------------------------------------------------------------------- 876 | 877 | #if defined(_MSC_VER) 878 | #pragma comment(lib, "dwmapi") // Link with dwmapi.lib. MinGW will require linking with '-ldwmapi' 879 | #endif 880 | 881 | // [experimental] 882 | // Borrowed from GLFW's function updateFramebufferTransparency() in src/win32_window.c 883 | // (the Dwm* functions are Vista era functions but we are borrowing logic from GLFW) 884 | void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd) 885 | { 886 | if (!_IsWindowsVistaOrGreater()) 887 | return; 888 | 889 | BOOL composition; 890 | if (FAILED(::DwmIsCompositionEnabled(&composition)) || !composition) 891 | return; 892 | 893 | BOOL opaque; 894 | DWORD color; 895 | if (_IsWindows8OrGreater() || (SUCCEEDED(::DwmGetColorizationColor(&color, &opaque)) && !opaque)) 896 | { 897 | HRGN region = ::CreateRectRgn(0, 0, -1, -1); 898 | DWM_BLURBEHIND bb = {}; 899 | bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; 900 | bb.hRgnBlur = region; 901 | bb.fEnable = TRUE; 902 | ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); 903 | ::DeleteObject(region); 904 | } 905 | else 906 | { 907 | DWM_BLURBEHIND bb = {}; 908 | bb.dwFlags = DWM_BB_ENABLE; 909 | ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); 910 | } 911 | } 912 | 913 | //--------------------------------------------------------------------------------------------------------- 914 | 915 | #if defined(__GNUC__) 916 | #pragma GCC diagnostic pop 917 | #endif 918 | #if defined(__clang__) 919 | #pragma clang diagnostic pop 920 | #endif 921 | 922 | #endif // #ifndef IMGUI_DISABLE 923 | -------------------------------------------------------------------------------- /cs2-external-cheat/imgui/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for Windows (standard windows API for 32-bits AND 64-bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. 7 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 10 | 11 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 12 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 13 | // Learn about Dear ImGui: 14 | // - FAQ https://dearimgui.com/faq 15 | // - Getting Started https://dearimgui.com/getting-started 16 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 17 | // - Introduction, links and more at the top of imgui.cpp 18 | 19 | #pragma once 20 | #include "imgui.h" // IMGUI_IMPL_API 21 | #ifndef IMGUI_DISABLE 22 | 23 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 24 | IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); 25 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 26 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 27 | 28 | // Win32 message handler your application need to call. 29 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 30 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 31 | // - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. 32 | 33 | #if 0 34 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 35 | #endif 36 | 37 | // DPI-related helpers (optional) 38 | // - Use to enable DPI awareness without having to create an application manifest. 39 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 40 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 41 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 42 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 43 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 44 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 45 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 46 | 47 | // Transparency related helpers (optional) [experimental] 48 | // - Use to enable alpha compositing transparency with the desktop. 49 | // - Use together with e.g. clearing your framebuffer with zero-alpha. 50 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd); // HWND hwnd 51 | 52 | #endif // #ifndef IMGUI_DISABLE 53 | -------------------------------------------------------------------------------- /cs2-external-cheat/imgui/imstb_rectpack.h: -------------------------------------------------------------------------------- 1 | // [DEAR IMGUI] 2 | // This is a slightly modified version of stb_rect_pack.h 1.01. 3 | // Grep for [DEAR IMGUI] to find the changes. 4 | // 5 | // stb_rect_pack.h - v1.01 - public domain - rectangle packing 6 | // Sean Barrett 2014 7 | // 8 | // Useful for e.g. packing rectangular textures into an atlas. 9 | // Does not do rotation. 10 | // 11 | // Before #including, 12 | // 13 | // #define STB_RECT_PACK_IMPLEMENTATION 14 | // 15 | // in the file that you want to have the implementation. 16 | // 17 | // Not necessarily the awesomest packing method, but better than 18 | // the totally naive one in stb_truetype (which is primarily what 19 | // this is meant to replace). 20 | // 21 | // Has only had a few tests run, may have issues. 22 | // 23 | // More docs to come. 24 | // 25 | // No memory allocations; uses qsort() and assert() from stdlib. 26 | // Can override those by defining STBRP_SORT and STBRP_ASSERT. 27 | // 28 | // This library currently uses the Skyline Bottom-Left algorithm. 29 | // 30 | // Please note: better rectangle packers are welcome! Please 31 | // implement them to the same API, but with a different init 32 | // function. 33 | // 34 | // Credits 35 | // 36 | // Library 37 | // Sean Barrett 38 | // Minor features 39 | // Martins Mozeiko 40 | // github:IntellectualKitty 41 | // 42 | // Bugfixes / warning fixes 43 | // Jeremy Jaussaud 44 | // Fabian Giesen 45 | // 46 | // Version history: 47 | // 48 | // 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section 49 | // 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles 50 | // 0.99 (2019-02-07) warning fixes 51 | // 0.11 (2017-03-03) return packing success/fail result 52 | // 0.10 (2016-10-25) remove cast-away-const to avoid warnings 53 | // 0.09 (2016-08-27) fix compiler warnings 54 | // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) 55 | // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) 56 | // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort 57 | // 0.05: added STBRP_ASSERT to allow replacing assert 58 | // 0.04: fixed minor bug in STBRP_LARGE_RECTS support 59 | // 0.01: initial release 60 | // 61 | // LICENSE 62 | // 63 | // See end of file for license information. 64 | 65 | ////////////////////////////////////////////////////////////////////////////// 66 | // 67 | // INCLUDE SECTION 68 | // 69 | 70 | #ifndef STB_INCLUDE_STB_RECT_PACK_H 71 | #define STB_INCLUDE_STB_RECT_PACK_H 72 | 73 | #define STB_RECT_PACK_VERSION 1 74 | 75 | #ifdef STBRP_STATIC 76 | #define STBRP_DEF static 77 | #else 78 | #define STBRP_DEF extern 79 | #endif 80 | 81 | #ifdef __cplusplus 82 | extern "C" { 83 | #endif 84 | 85 | typedef struct stbrp_context stbrp_context; 86 | typedef struct stbrp_node stbrp_node; 87 | typedef struct stbrp_rect stbrp_rect; 88 | 89 | typedef int stbrp_coord; 90 | 91 | #define STBRP__MAXVAL 0x7fffffff 92 | // Mostly for internal use, but this is the maximum supported coordinate value. 93 | 94 | STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); 95 | // Assign packed locations to rectangles. The rectangles are of type 96 | // 'stbrp_rect' defined below, stored in the array 'rects', and there 97 | // are 'num_rects' many of them. 98 | // 99 | // Rectangles which are successfully packed have the 'was_packed' flag 100 | // set to a non-zero value and 'x' and 'y' store the minimum location 101 | // on each axis (i.e. bottom-left in cartesian coordinates, top-left 102 | // if you imagine y increasing downwards). Rectangles which do not fit 103 | // have the 'was_packed' flag set to 0. 104 | // 105 | // You should not try to access the 'rects' array from another thread 106 | // while this function is running, as the function temporarily reorders 107 | // the array while it executes. 108 | // 109 | // To pack into another rectangle, you need to call stbrp_init_target 110 | // again. To continue packing into the same rectangle, you can call 111 | // this function again. Calling this multiple times with multiple rect 112 | // arrays will probably produce worse packing results than calling it 113 | // a single time with the full rectangle array, but the option is 114 | // available. 115 | // 116 | // The function returns 1 if all of the rectangles were successfully 117 | // packed and 0 otherwise. 118 | 119 | struct stbrp_rect 120 | { 121 | // reserved for your use: 122 | int id; 123 | 124 | // input: 125 | stbrp_coord w, h; 126 | 127 | // output: 128 | stbrp_coord x, y; 129 | int was_packed; // non-zero if valid packing 130 | 131 | }; // 16 bytes, nominally 132 | 133 | 134 | STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes); 135 | // Initialize a rectangle packer to: 136 | // pack a rectangle that is 'width' by 'height' in dimensions 137 | // using temporary storage provided by the array 'nodes', which is 'num_nodes' long 138 | // 139 | // You must call this function every time you start packing into a new target. 140 | // 141 | // There is no "shutdown" function. The 'nodes' memory must stay valid for 142 | // the following stbrp_pack_rects() call (or calls), but can be freed after 143 | // the call (or calls) finish. 144 | // 145 | // Note: to guarantee best results, either: 146 | // 1. make sure 'num_nodes' >= 'width' 147 | // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1' 148 | // 149 | // If you don't do either of the above things, widths will be quantized to multiples 150 | // of small integers to guarantee the algorithm doesn't run out of temporary storage. 151 | // 152 | // If you do #2, then the non-quantized algorithm will be used, but the algorithm 153 | // may run out of temporary storage and be unable to pack some rectangles. 154 | 155 | STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem); 156 | // Optionally call this function after init but before doing any packing to 157 | // change the handling of the out-of-temp-memory scenario, described above. 158 | // If you call init again, this will be reset to the default (false). 159 | 160 | 161 | STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic); 162 | // Optionally select which packing heuristic the library should use. Different 163 | // heuristics will produce better/worse results for different data sets. 164 | // If you call init again, this will be reset to the default. 165 | 166 | enum 167 | { 168 | STBRP_HEURISTIC_Skyline_default=0, 169 | STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default, 170 | STBRP_HEURISTIC_Skyline_BF_sortHeight 171 | }; 172 | 173 | 174 | ////////////////////////////////////////////////////////////////////////////// 175 | // 176 | // the details of the following structures don't matter to you, but they must 177 | // be visible so you can handle the memory allocations for them 178 | 179 | struct stbrp_node 180 | { 181 | stbrp_coord x,y; 182 | stbrp_node *next; 183 | }; 184 | 185 | struct stbrp_context 186 | { 187 | int width; 188 | int height; 189 | int align; 190 | int init_mode; 191 | int heuristic; 192 | int num_nodes; 193 | stbrp_node *active_head; 194 | stbrp_node *free_head; 195 | stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2' 196 | }; 197 | 198 | #ifdef __cplusplus 199 | } 200 | #endif 201 | 202 | #endif 203 | 204 | ////////////////////////////////////////////////////////////////////////////// 205 | // 206 | // IMPLEMENTATION SECTION 207 | // 208 | 209 | #ifdef STB_RECT_PACK_IMPLEMENTATION 210 | #ifndef STBRP_SORT 211 | #include 212 | #define STBRP_SORT qsort 213 | #endif 214 | 215 | #ifndef STBRP_ASSERT 216 | #include 217 | #define STBRP_ASSERT assert 218 | #endif 219 | 220 | #ifdef _MSC_VER 221 | #define STBRP__NOTUSED(v) (void)(v) 222 | #define STBRP__CDECL __cdecl 223 | #else 224 | #define STBRP__NOTUSED(v) (void)sizeof(v) 225 | #define STBRP__CDECL 226 | #endif 227 | 228 | enum 229 | { 230 | STBRP__INIT_skyline = 1 231 | }; 232 | 233 | STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic) 234 | { 235 | switch (context->init_mode) { 236 | case STBRP__INIT_skyline: 237 | STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight); 238 | context->heuristic = heuristic; 239 | break; 240 | default: 241 | STBRP_ASSERT(0); 242 | } 243 | } 244 | 245 | STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem) 246 | { 247 | if (allow_out_of_mem) 248 | // if it's ok to run out of memory, then don't bother aligning them; 249 | // this gives better packing, but may fail due to OOM (even though 250 | // the rectangles easily fit). @TODO a smarter approach would be to only 251 | // quantize once we've hit OOM, then we could get rid of this parameter. 252 | context->align = 1; 253 | else { 254 | // if it's not ok to run out of memory, then quantize the widths 255 | // so that num_nodes is always enough nodes. 256 | // 257 | // I.e. num_nodes * align >= width 258 | // align >= width / num_nodes 259 | // align = ceil(width/num_nodes) 260 | 261 | context->align = (context->width + context->num_nodes-1) / context->num_nodes; 262 | } 263 | } 264 | 265 | STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) 266 | { 267 | int i; 268 | 269 | for (i=0; i < num_nodes-1; ++i) 270 | nodes[i].next = &nodes[i+1]; 271 | nodes[i].next = NULL; 272 | context->init_mode = STBRP__INIT_skyline; 273 | context->heuristic = STBRP_HEURISTIC_Skyline_default; 274 | context->free_head = &nodes[0]; 275 | context->active_head = &context->extra[0]; 276 | context->width = width; 277 | context->height = height; 278 | context->num_nodes = num_nodes; 279 | stbrp_setup_allow_out_of_mem(context, 0); 280 | 281 | // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly) 282 | context->extra[0].x = 0; 283 | context->extra[0].y = 0; 284 | context->extra[0].next = &context->extra[1]; 285 | context->extra[1].x = (stbrp_coord) width; 286 | context->extra[1].y = (1<<30); 287 | context->extra[1].next = NULL; 288 | } 289 | 290 | // find minimum y position if it starts at x1 291 | static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste) 292 | { 293 | stbrp_node *node = first; 294 | int x1 = x0 + width; 295 | int min_y, visited_width, waste_area; 296 | 297 | STBRP__NOTUSED(c); 298 | 299 | STBRP_ASSERT(first->x <= x0); 300 | 301 | #if 0 302 | // skip in case we're past the node 303 | while (node->next->x <= x0) 304 | ++node; 305 | #else 306 | STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency 307 | #endif 308 | 309 | STBRP_ASSERT(node->x <= x0); 310 | 311 | min_y = 0; 312 | waste_area = 0; 313 | visited_width = 0; 314 | while (node->x < x1) { 315 | if (node->y > min_y) { 316 | // raise min_y higher. 317 | // we've accounted for all waste up to min_y, 318 | // but we'll now add more waste for everything we've visted 319 | waste_area += visited_width * (node->y - min_y); 320 | min_y = node->y; 321 | // the first time through, visited_width might be reduced 322 | if (node->x < x0) 323 | visited_width += node->next->x - x0; 324 | else 325 | visited_width += node->next->x - node->x; 326 | } else { 327 | // add waste area 328 | int under_width = node->next->x - node->x; 329 | if (under_width + visited_width > width) 330 | under_width = width - visited_width; 331 | waste_area += under_width * (min_y - node->y); 332 | visited_width += under_width; 333 | } 334 | node = node->next; 335 | } 336 | 337 | *pwaste = waste_area; 338 | return min_y; 339 | } 340 | 341 | typedef struct 342 | { 343 | int x,y; 344 | stbrp_node **prev_link; 345 | } stbrp__findresult; 346 | 347 | static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height) 348 | { 349 | int best_waste = (1<<30), best_x, best_y = (1 << 30); 350 | stbrp__findresult fr; 351 | stbrp_node **prev, *node, *tail, **best = NULL; 352 | 353 | // align to multiple of c->align 354 | width = (width + c->align - 1); 355 | width -= width % c->align; 356 | STBRP_ASSERT(width % c->align == 0); 357 | 358 | // if it can't possibly fit, bail immediately 359 | if (width > c->width || height > c->height) { 360 | fr.prev_link = NULL; 361 | fr.x = fr.y = 0; 362 | return fr; 363 | } 364 | 365 | node = c->active_head; 366 | prev = &c->active_head; 367 | while (node->x + width <= c->width) { 368 | int y,waste; 369 | y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste); 370 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL 371 | // bottom left 372 | if (y < best_y) { 373 | best_y = y; 374 | best = prev; 375 | } 376 | } else { 377 | // best-fit 378 | if (y + height <= c->height) { 379 | // can only use it if it first vertically 380 | if (y < best_y || (y == best_y && waste < best_waste)) { 381 | best_y = y; 382 | best_waste = waste; 383 | best = prev; 384 | } 385 | } 386 | } 387 | prev = &node->next; 388 | node = node->next; 389 | } 390 | 391 | best_x = (best == NULL) ? 0 : (*best)->x; 392 | 393 | // if doing best-fit (BF), we also have to try aligning right edge to each node position 394 | // 395 | // e.g, if fitting 396 | // 397 | // ____________________ 398 | // |____________________| 399 | // 400 | // into 401 | // 402 | // | | 403 | // | ____________| 404 | // |____________| 405 | // 406 | // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned 407 | // 408 | // This makes BF take about 2x the time 409 | 410 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) { 411 | tail = c->active_head; 412 | node = c->active_head; 413 | prev = &c->active_head; 414 | // find first node that's admissible 415 | while (tail->x < width) 416 | tail = tail->next; 417 | while (tail) { 418 | int xpos = tail->x - width; 419 | int y,waste; 420 | STBRP_ASSERT(xpos >= 0); 421 | // find the left position that matches this 422 | while (node->next->x <= xpos) { 423 | prev = &node->next; 424 | node = node->next; 425 | } 426 | STBRP_ASSERT(node->next->x > xpos && node->x <= xpos); 427 | y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); 428 | if (y + height <= c->height) { 429 | if (y <= best_y) { 430 | if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { 431 | best_x = xpos; 432 | //STBRP_ASSERT(y <= best_y); [DEAR IMGUI] 433 | best_y = y; 434 | best_waste = waste; 435 | best = prev; 436 | } 437 | } 438 | } 439 | tail = tail->next; 440 | } 441 | } 442 | 443 | fr.prev_link = best; 444 | fr.x = best_x; 445 | fr.y = best_y; 446 | return fr; 447 | } 448 | 449 | static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height) 450 | { 451 | // find best position according to heuristic 452 | stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height); 453 | stbrp_node *node, *cur; 454 | 455 | // bail if: 456 | // 1. it failed 457 | // 2. the best node doesn't fit (we don't always check this) 458 | // 3. we're out of memory 459 | if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) { 460 | res.prev_link = NULL; 461 | return res; 462 | } 463 | 464 | // on success, create new node 465 | node = context->free_head; 466 | node->x = (stbrp_coord) res.x; 467 | node->y = (stbrp_coord) (res.y + height); 468 | 469 | context->free_head = node->next; 470 | 471 | // insert the new node into the right starting point, and 472 | // let 'cur' point to the remaining nodes needing to be 473 | // stiched back in 474 | 475 | cur = *res.prev_link; 476 | if (cur->x < res.x) { 477 | // preserve the existing one, so start testing with the next one 478 | stbrp_node *next = cur->next; 479 | cur->next = node; 480 | cur = next; 481 | } else { 482 | *res.prev_link = node; 483 | } 484 | 485 | // from here, traverse cur and free the nodes, until we get to one 486 | // that shouldn't be freed 487 | while (cur->next && cur->next->x <= res.x + width) { 488 | stbrp_node *next = cur->next; 489 | // move the current node to the free list 490 | cur->next = context->free_head; 491 | context->free_head = cur; 492 | cur = next; 493 | } 494 | 495 | // stitch the list back in 496 | node->next = cur; 497 | 498 | if (cur->x < res.x + width) 499 | cur->x = (stbrp_coord) (res.x + width); 500 | 501 | #ifdef _DEBUG 502 | cur = context->active_head; 503 | while (cur->x < context->width) { 504 | STBRP_ASSERT(cur->x < cur->next->x); 505 | cur = cur->next; 506 | } 507 | STBRP_ASSERT(cur->next == NULL); 508 | 509 | { 510 | int count=0; 511 | cur = context->active_head; 512 | while (cur) { 513 | cur = cur->next; 514 | ++count; 515 | } 516 | cur = context->free_head; 517 | while (cur) { 518 | cur = cur->next; 519 | ++count; 520 | } 521 | STBRP_ASSERT(count == context->num_nodes+2); 522 | } 523 | #endif 524 | 525 | return res; 526 | } 527 | 528 | static int STBRP__CDECL rect_height_compare(const void *a, const void *b) 529 | { 530 | const stbrp_rect *p = (const stbrp_rect *) a; 531 | const stbrp_rect *q = (const stbrp_rect *) b; 532 | if (p->h > q->h) 533 | return -1; 534 | if (p->h < q->h) 535 | return 1; 536 | return (p->w > q->w) ? -1 : (p->w < q->w); 537 | } 538 | 539 | static int STBRP__CDECL rect_original_order(const void *a, const void *b) 540 | { 541 | const stbrp_rect *p = (const stbrp_rect *) a; 542 | const stbrp_rect *q = (const stbrp_rect *) b; 543 | return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); 544 | } 545 | 546 | STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) 547 | { 548 | int i, all_rects_packed = 1; 549 | 550 | // we use the 'was_packed' field internally to allow sorting/unsorting 551 | for (i=0; i < num_rects; ++i) { 552 | rects[i].was_packed = i; 553 | } 554 | 555 | // sort according to heuristic 556 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare); 557 | 558 | for (i=0; i < num_rects; ++i) { 559 | if (rects[i].w == 0 || rects[i].h == 0) { 560 | rects[i].x = rects[i].y = 0; // empty rect needs no space 561 | } else { 562 | stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); 563 | if (fr.prev_link) { 564 | rects[i].x = (stbrp_coord) fr.x; 565 | rects[i].y = (stbrp_coord) fr.y; 566 | } else { 567 | rects[i].x = rects[i].y = STBRP__MAXVAL; 568 | } 569 | } 570 | } 571 | 572 | // unsort 573 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); 574 | 575 | // set was_packed flags and all_rects_packed status 576 | for (i=0; i < num_rects; ++i) { 577 | rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL); 578 | if (!rects[i].was_packed) 579 | all_rects_packed = 0; 580 | } 581 | 582 | // return the all_rects_packed status 583 | return all_rects_packed; 584 | } 585 | #endif 586 | 587 | /* 588 | ------------------------------------------------------------------------------ 589 | This software is available under 2 licenses -- choose whichever you prefer. 590 | ------------------------------------------------------------------------------ 591 | ALTERNATIVE A - MIT License 592 | Copyright (c) 2017 Sean Barrett 593 | Permission is hereby granted, free of charge, to any person obtaining a copy of 594 | this software and associated documentation files (the "Software"), to deal in 595 | the Software without restriction, including without limitation the rights to 596 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 597 | of the Software, and to permit persons to whom the Software is furnished to do 598 | so, subject to the following conditions: 599 | The above copyright notice and this permission notice shall be included in all 600 | copies or substantial portions of the Software. 601 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 602 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 603 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 604 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 605 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 606 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 607 | SOFTWARE. 608 | ------------------------------------------------------------------------------ 609 | ALTERNATIVE B - Public Domain (www.unlicense.org) 610 | This is free and unencumbered software released into the public domain. 611 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 612 | software, either in source code form or as a compiled binary, for any purpose, 613 | commercial or non-commercial, and by any means. 614 | In jurisdictions that recognize copyright laws, the author or authors of this 615 | software dedicate any and all copyright interest in the software to the public 616 | domain. We make this dedication for the benefit of the public at large and to 617 | the detriment of our heirs and successors. We intend this dedication to be an 618 | overt act of relinquishment in perpetuity of all present and future rights to 619 | this software under copyright law. 620 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 621 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 622 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 623 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 624 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 625 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 626 | ------------------------------------------------------------------------------ 627 | */ 628 | -------------------------------------------------------------------------------- /cs2-external-cheat/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "overlay.h" 3 | #include "offsets.h" 4 | #include "imgui.h" 5 | #include "options.h" 6 | #include "gui.h" 7 | #include "cheat.h" 8 | #include "overlay.h" 9 | #include "config.h" 10 | 11 | 12 | int main() { 13 | system("title Vireless output"); 14 | 15 | if (config.initialize()) { 16 | printf("[cheat]: Succesfly initialized configs\n"); 17 | } 18 | else { 19 | printf("[cheat]: Failed to initialize configs\n"); 20 | } 21 | 22 | if (config.downloadOffsetsFromGithub()) { 23 | std::cout << "[cheat]: Succesfly downloaded offsets" << '\n'; 24 | } 25 | else { 26 | return 0; 27 | } 28 | 29 | if (offsets.initialize()) { 30 | printf("[cheat]: Succesfly initialized offsets\n"); 31 | } 32 | else { 33 | printf("[cheat]: Failed to initialize offsets\n"); 34 | return 0; 35 | } 36 | 37 | if (overlay.CreateOverlay()) { 38 | printf("[cheat]: Succesfly created overlay\n"); 39 | } 40 | else { 41 | printf("[cheat]: Failed to create overlay\n"); 42 | return 0; 43 | } 44 | 45 | ImGui::CreateContext(); 46 | SetupFonts(); 47 | setImguiStyle(); 48 | overlay.imguiInit(); 49 | 50 | printf("[cheat]: Starting main loop\n\n"); 51 | 52 | MSG msg; 53 | while (overlay.done == false) 54 | { 55 | while (::PeekMessage(&msg, nullptr, 0U, 0U, PM_REMOVE)) 56 | { 57 | ::TranslateMessage(&msg); 58 | ::DispatchMessage(&msg); 59 | 60 | if (msg.message == WM_QUIT) 61 | { 62 | overlay.done = true; 63 | break; 64 | } 65 | } 66 | 67 | if (overlay.done == true || GetAsyncKeyState(menu::bEndButton) & 1) break; 68 | 69 | if (GetAsyncKeyState(menu::bToggleButton) & 1) menu::bMenuVisible = !menu::bMenuVisible; 70 | 71 | overlay.MakeNewFrame(); 72 | 73 | if (menu::bMenuVisible) 74 | { 75 | guiStart(); 76 | SetWindowLong(overlay.hwnd, GWL_EXSTYLE, WS_EX_TOPMOST); 77 | } 78 | else 79 | { 80 | SetWindowLong(overlay.hwnd, GWL_EXSTYLE, WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED); 81 | } 82 | 83 | startCheat(); 84 | overlay.RenderGui(); 85 | } 86 | 87 | overlay.ReleaseOverlay(); 88 | 89 | return 1; 90 | } 91 | -------------------------------------------------------------------------------- /cs2-external-cheat/math.cpp: -------------------------------------------------------------------------------- 1 | #include "DataTypes.h" 2 | #include 3 | #include "offsets.h" 4 | 5 | bool WorldToScreen(const Vec3& VecOrigin, Vec2& VecScreen, float* Matrix) { 6 | float W = VecOrigin.x * Matrix[12] + VecOrigin.y * Matrix[13] + VecOrigin.z * Matrix[14] + Matrix[15]; 7 | 8 | if (W < 0.01f) 9 | return false; 10 | 11 | Vec2 clipCoords; 12 | clipCoords.x = VecOrigin.x * Matrix[0] + VecOrigin.y * Matrix[1] + Matrix[3]; 13 | clipCoords.y = VecOrigin.x * Matrix[4] + VecOrigin.y * Matrix[5] + VecOrigin.z * Matrix[6] + Matrix[7]; 14 | 15 | Vec2 NDC; 16 | NDC.x = clipCoords.x / W; 17 | NDC.y = clipCoords.y / W; 18 | 19 | VecScreen.x = (offsets.windowWidth / 2 * NDC.x) + (NDC.x + offsets.windowWidth / 2); 20 | VecScreen.y = -(offsets.windowHeight / 2 * NDC.y) + (NDC.y + offsets.windowHeight / 2); 21 | 22 | return true; 23 | } 24 | 25 | float getDistanceToEnemy3D(const Vec3& absCoords) { 26 | return sqrt(absCoords.x * absCoords.x + absCoords.y * absCoords.y + absCoords.z * absCoords.z); 27 | } 28 | 29 | float getDistanceToCenter(const Vec2& screenPos) { 30 | return sqrt( 31 | (offsets.windowWidth / 2 - screenPos.x) * (offsets.windowWidth / 2 - screenPos.x) + 32 | (offsets.windowHeight / 2 - screenPos.y) * (offsets.windowHeight / 2 - screenPos.y) 33 | ); 34 | } -------------------------------------------------------------------------------- /cs2-external-cheat/math.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataTypes.h" 4 | 5 | bool WorldToScreen(const Vec3& VecOrigin, Vec2& VecScreen, float* Matrix); 6 | float getDistanceToEnemy3D(const Vec3& absCoords); 7 | float getDistanceToCenter(const Vec2& screenPos); -------------------------------------------------------------------------------- /cs2-external-cheat/memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | class Memory 11 | { 12 | public: 13 | std::uintptr_t processId = 0; 14 | void* processHandle = nullptr; 15 | 16 | // Constructor that finds the process id 17 | // and opens a handle 18 | Memory() {} 19 | 20 | // Destructor that frees the opened handle 21 | ~Memory() 22 | { 23 | if (processHandle) 24 | ::CloseHandle(processHandle); 25 | } 26 | 27 | const void attachProcess(const wchar_t* processName) noexcept { 28 | ::PROCESSENTRY32 entry = { }; 29 | entry.dwSize = sizeof(::PROCESSENTRY32); 30 | 31 | const auto snapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 32 | 33 | while (::Process32Next(snapShot, &entry)) 34 | { 35 | if (!_wcsicmp(entry.szExeFile, processName)) 36 | { 37 | processId = entry.th32ProcessID; 38 | processHandle = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId); 39 | break; 40 | } 41 | } 42 | 43 | // Free handle 44 | if (snapShot) 45 | ::CloseHandle(snapShot); 46 | } 47 | 48 | // Returns the base address of a module by name 49 | const std::uintptr_t GetModuleAddress(const wchar_t* moduleName) const noexcept 50 | { 51 | ::MODULEENTRY32 entry = { }; 52 | entry.dwSize = sizeof(::MODULEENTRY32); 53 | 54 | const auto snapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId); 55 | 56 | std::uintptr_t result = 0; 57 | 58 | while (::Module32Next(snapShot, &entry)) 59 | { 60 | if (!_wcsicmp(entry.szModule, moduleName)) 61 | { 62 | result = reinterpret_cast(entry.modBaseAddr); 63 | break; 64 | } 65 | } 66 | 67 | if (snapShot) 68 | ::CloseHandle(snapShot); 69 | 70 | return result; 71 | } 72 | 73 | const HMODULE GetModuleAddressHandle(const wchar_t* moduleName) const noexcept 74 | { 75 | ::MODULEENTRY32 entry = { }; 76 | entry.dwSize = sizeof(::MODULEENTRY32); 77 | 78 | const auto snapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId); 79 | 80 | HMODULE result = nullptr; 81 | 82 | while (::Module32Next(snapShot, &entry)) 83 | { 84 | if (!_wcsicmp(entry.szModule, moduleName)) 85 | { 86 | result = entry.hModule;; 87 | break; 88 | } 89 | } 90 | 91 | if (snapShot) 92 | ::CloseHandle(snapShot); 93 | 94 | return result; 95 | } 96 | 97 | const std::uintptr_t FindDMAAddy(uintptr_t ptr, std::vector offsets) const noexcept 98 | { 99 | uintptr_t address = ptr; 100 | 101 | for (unsigned int i = 0; i < offsets.size(); ++i) { 102 | BOOL rpmReturn = ReadProcessMemory(processHandle, (LPVOID)address, &address, sizeof(address), 0); 103 | 104 | address += offsets[i]; 105 | } 106 | 107 | return address; 108 | } 109 | 110 | void ReadRaw(const std::uintptr_t& address, char* buffer, size_t size) const noexcept 111 | { 112 | ::ReadProcessMemory(processHandle, reinterpret_cast(address), buffer, size, NULL); 113 | } 114 | 115 | template 116 | constexpr const T Read(const std::uintptr_t& address) const noexcept 117 | { 118 | T value = { }; 119 | ::ReadProcessMemory(processHandle, reinterpret_cast(address), &value, sizeof(T), NULL); 120 | return value; 121 | } 122 | 123 | template 124 | constexpr void Write(const std::uintptr_t& address, const T& value) const noexcept 125 | { 126 | ::WriteProcessMemory(processHandle, reinterpret_cast(address), &value, sizeof(T), NULL); 127 | } 128 | }; 129 | 130 | inline Memory mem; -------------------------------------------------------------------------------- /cs2-external-cheat/offsets.cpp: -------------------------------------------------------------------------------- 1 | #include "offsets.h" 2 | #include 3 | #include 4 | #include "math.h" 5 | #include "memory.h" 6 | #include 7 | #include "datatypes.h" 8 | #include 9 | #include 10 | #include "json.h" 11 | #include "config.h" 12 | 13 | using json = nlohmann::json; 14 | 15 | json clientJson; 16 | 17 | bool game::baseOffsets::initialize() { 18 | printf("[cheat]: Waiting for cs2.exe...\n"); 19 | 20 | while (true) { 21 | mem.attachProcess(L"cs2.exe"); 22 | 23 | if (mem.processId == 0) { 24 | std::this_thread::sleep_for(std::chrono::seconds(2)); 25 | continue; 26 | } 27 | else { 28 | printf("[cheat]: Attached cs2.exe\n"); 29 | break; 30 | } 31 | } 32 | 33 | json offsetsJson; 34 | 35 | std::ifstream offsetsFile(config.offsetsPath + "\\offsetsDump.json"); 36 | std::ifstream clientFile(config.offsetsPath + "\\clientDump.json"); 37 | 38 | if (offsetsFile.is_open() && clientFile.is_open()) { 39 | offsetsFile >> offsetsJson; 40 | clientFile >> clientJson; 41 | 42 | offsetsFile.close(); 43 | clientFile.close(); 44 | } 45 | 46 | uintptr_t clientDll = mem.GetModuleAddress(L"client.dll"); 47 | uintptr_t engineDll = mem.GetModuleAddress(L"engine2.dll"); 48 | 49 | if (clientDll == 0 || engineDll == 0) { 50 | printf("[cheat]: Unable to read client.dll or engine.dll\n"); 51 | return false; 52 | } 53 | 54 | this->clientDll = clientDll; 55 | this->engineDll = engineDll; 56 | 57 | uintptr_t temp = 0; 58 | 59 | temp = mem.Read(offsetsJson["engine2.dll"]["dwWindowWidth"] + engineDll); 60 | if (temp == 0) { 61 | printf("[cheat]: Unable to read window width\n"); 62 | return false; 63 | } 64 | 65 | this->windowWidth = temp; 66 | 67 | temp = mem.Read(offsetsJson["engine2.dll"]["dwWindowHeight"] + engineDll); 68 | if (temp == 0) { 69 | printf("[cheat]: Unable to read window height\n"); 70 | return false; 71 | } 72 | 73 | this->windowHeight = temp; 74 | 75 | temp = mem.Read(offsetsJson["client.dll"]["dwEntityList"] + clientDll); 76 | if (temp == 0) { 77 | printf("[cheat]: Unable to read entity list\n"); 78 | return false; 79 | } 80 | 81 | this->entityList = temp; 82 | 83 | temp = mem.Read(offsetsJson["client.dll"]["dwLocalPlayerController"] + clientDll); 84 | if (temp == 0) { 85 | printf("[cheat]: Unable to read local player\n"); 86 | return false; 87 | } 88 | temp = offsetsJson["client.dll"]["dwLocalPlayerController"] + clientDll; 89 | 90 | this->localController = temp; 91 | 92 | temp = mem.Read(offsetsJson["client.dll"]["dwViewMatrix"] + clientDll); 93 | if (temp == 0) { 94 | printf("[cheat]: Unable to read view matrix\n"); 95 | return false; 96 | } 97 | 98 | temp = offsetsJson["client.dll"]["dwViewMatrix"] + clientDll; 99 | 100 | this->viewMatrix = temp; 101 | 102 | while (true) { 103 | temp = mem.Read(offsetsJson["client.dll"]["dwViewAngles"] + clientDll); 104 | if (temp == 0) { 105 | printf("[cheat]: Unable to read view angles, start game\n"); 106 | std::this_thread::sleep_for(std::chrono::seconds(2)); 107 | } 108 | else { 109 | break; 110 | } 111 | } 112 | 113 | temp = offsetsJson["client.dll"]["dwViewAngles"] + clientDll; 114 | 115 | this->viewAngle = temp; 116 | 117 | temp = mem.Read(offsetsJson["client.dll"]["dwLocalPlayerPawn"] + clientDll); 118 | if (temp == 0) { 119 | printf("[cheat]: Unable to read local pawn\n"); 120 | return false; 121 | } 122 | temp = offsetsJson["client.dll"]["dwLocalPlayerPawn"] + clientDll; 123 | 124 | this->localPawn = temp; 125 | 126 | return true; 127 | } 128 | 129 | uintptr_t game::baseOffsets::getListEntry() { 130 | this->listEntry = mem.Read(offsets.entityList + 0x10); 131 | return listEntry; 132 | } 133 | 134 | int game::CSplayerPawn::getSpotted() { 135 | this->spotted = mem.Read(this->pawn + clientJson["client.dll"]["classes"]["C_CSPlayerPawn"]["fields"]["m_entitySpottedState"] + clientJson["client.dll"]["classes"]["EntitySpottedState_t"]["fields"]["m_bSpottedByMask"]); 136 | return spotted; 137 | } 138 | 139 | uint8_t game::CSplayerPawn::getTeamNum() { 140 | this->teamNum = mem.Read(this->pawn + clientJson["client.dll"]["classes"]["C_BaseEntity"]["fields"]["m_iTeamNum"]); 141 | return teamNum; 142 | } 143 | 144 | bool game::CSplayerController::getIsAlive() { 145 | this->isPawnAlive = mem.Read(this->controller + clientJson["client.dll"]["classes"]["CCSPlayerController"]["fields"]["m_bPawnIsAlive"]); 146 | return isPawnAlive; 147 | } 148 | 149 | uintptr_t game::CSplayerPawn::getPawn() { 150 | this->pawn = mem.Read(offsets.listEntry + 0x78 * (this->value & 0x1FF)); 151 | return pawn; 152 | } 153 | 154 | uintptr_t game::CSplayerController::getController() { 155 | this->controller = mem.Read(offsets.listEntry + 0x78 * (uintptr_t)(this->num & 0x1FF)); 156 | return controller; 157 | } 158 | 159 | uintptr_t game::CSplayerController::get_CSPlayerPawn() { 160 | return mem.Read(this->controller + clientJson["client.dll"]["classes"]["CCSPlayerController"]["fields"]["m_hPlayerPawn"]); 161 | } 162 | 163 | int game::CSplayerPawn::getPlayerHealth() { 164 | this->playerHealth = mem.Read(this->pawn + clientJson["client.dll"]["classes"]["C_BaseEntity"]["fields"]["m_iHealth"]); 165 | return playerHealth; 166 | } 167 | 168 | Vec3 game::CSplayerPawn::getFeetPos() { 169 | this->feetPos = mem.Read(this->pawn + clientJson["client.dll"]["classes"]["C_BasePlayerPawn"]["fields"]["m_vOldOrigin"]); 170 | return feetPos; 171 | } 172 | 173 | Vec2 game::CSplayerPawn::getViewAngles() { 174 | this->viewAngles = mem.Read(this->pawn + clientJson["client.dll"]["classes"]["C_CSPlayerPawnBase"]["fields"]["m_angEyeAngles"]); 175 | return viewAngles; 176 | } 177 | 178 | Vec3 game::CSplayerPawn::getHeadPos() { 179 | this->headPos.x = this->feetPos.x; 180 | this->headPos.y = this->feetPos.y; 181 | this->headPos.z = this->feetPos.z + 72.f; 182 | 183 | return headPos; 184 | } 185 | 186 | int game::CSplayerPawn::getIndex(){ 187 | this->crossHairID = mem.Read(this->pawn + clientJson["client.dll"]["classes"]["C_CSPlayerPawnBase"]["fields"]["m_iIDEntIndex"]); 188 | return crossHairID; 189 | } 190 | 191 | uintptr_t game::CSplayerPawn::getPlayerPawnByCrossHairID(int crossHairEntity) { 192 | uintptr_t crosshairEntityEntry = mem.Read(this->value + 0x8 * (crossHairEntity >> 9) + 0x10); 193 | this->pawn = mem.Read(crosshairEntityEntry + 0x78 * (crossHairEntity & 0x1FF)); 194 | return pawn; 195 | } 196 | 197 | std::string game::CSplayerController::getName() { 198 | uintptr_t temp = mem.Read(controller + clientJson["client.dll"]["classes"]["CCSPlayerController"]["fields"]["m_sSanitizedPlayerName"]); 199 | if (temp) { 200 | char buff[50]{}; 201 | mem.ReadRaw(temp, buff, 50); 202 | this->name = std::string(buff); 203 | } 204 | else { 205 | this->name = "unknown"; 206 | } 207 | return name; 208 | } 209 | 210 | bool game::CSplayerPawn::updateBones(Matrix& viewMatrix) { 211 | 212 | uintptr_t GameSceneNode = mem.Read(this->pawn + clientJson["client.dll"]["classes"]["C_BaseEntity"]["fields"]["m_pGameSceneNode"]); 213 | 214 | if (GameSceneNode == 0) return false; 215 | 216 | uintptr_t boneMatrix = mem.Read(GameSceneNode + clientJson["client.dll"]["classes"]["CSkeletonInstance"]["fields"]["m_modelState"] + 0x80); 217 | 218 | if (boneMatrix == 0) return false; 219 | 220 | BoneJointData BoneArray[30]{}; 221 | 222 | mem.ReadRaw(boneMatrix, reinterpret_cast(BoneArray), 30 * sizeof(BoneJointData)); 223 | 224 | for (int i = 0; i < 30; i++) 225 | { 226 | Vec2 ScreenPos; 227 | bool IsVisible = false; 228 | 229 | if (WorldToScreen(BoneArray[i].Pos, ScreenPos, viewMatrix.VMatrix)) 230 | IsVisible = true; 231 | 232 | this->BonePosList.push_back({ BoneArray[i].Pos ,ScreenPos,IsVisible }); 233 | } 234 | 235 | return this->BonePosList.size() > 0; 236 | } -------------------------------------------------------------------------------- /cs2-external-cheat/offsets.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lityrgia/cs2-external-cheat/ad54f8af1ca7180d01f5bdb53cfaefc3443b2525/cs2-external-cheat/offsets.h -------------------------------------------------------------------------------- /cs2-external-cheat/offsetsDump.h: -------------------------------------------------------------------------------- 1 | // Generated using https://github.com/a2x/cs2-dumper 2 | // 2024-07-26 01:00:19.071522800 UTC 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace cs2_dumper { 9 | namespace offsets { 10 | // Module: client.dll 11 | namespace client_dll { 12 | constexpr std::ptrdiff_t dwCSGOInput = 0x1A28E50; 13 | constexpr std::ptrdiff_t dwEntityList = 0x19BEED0; 14 | constexpr std::ptrdiff_t dwGameEntitySystem = 0x1ADDBE8; 15 | constexpr std::ptrdiff_t dwGameEntitySystem_highestEntityIndex = 0x1510; 16 | constexpr std::ptrdiff_t dwGameRules = 0x1A1C688; 17 | constexpr std::ptrdiff_t dwGlobalVars = 0x1818648; 18 | constexpr std::ptrdiff_t dwGlowManager = 0x1A1BD70; 19 | constexpr std::ptrdiff_t dwLocalPlayerController = 0x1A0E9C8; 20 | constexpr std::ptrdiff_t dwLocalPlayerPawn = 0x1824A18; 21 | constexpr std::ptrdiff_t dwPlantedC4 = 0x1A261C8; 22 | constexpr std::ptrdiff_t dwPrediction = 0x18248D0; 23 | constexpr std::ptrdiff_t dwSensitivity = 0x1A1D358; 24 | constexpr std::ptrdiff_t dwSensitivity_sensitivity = 0x40; 25 | constexpr std::ptrdiff_t dwViewAngles = 0x1A2E268; 26 | constexpr std::ptrdiff_t dwViewMatrix = 0x1A20CF0; 27 | constexpr std::ptrdiff_t dwViewRender = 0x1A21488; 28 | constexpr std::ptrdiff_t dwWeaponC4 = 0x19C2960; 29 | } 30 | // Module: engine2.dll 31 | namespace engine2_dll { 32 | constexpr std::ptrdiff_t dwBuildNumber = 0x52F834; 33 | constexpr std::ptrdiff_t dwNetworkGameClient = 0x52EBA0; 34 | constexpr std::ptrdiff_t dwNetworkGameClient_clientTickCount = 0x178; 35 | constexpr std::ptrdiff_t dwNetworkGameClient_deltaTick = 0x278; 36 | constexpr std::ptrdiff_t dwNetworkGameClient_isBackgroundMap = 0x281477; 37 | constexpr std::ptrdiff_t dwNetworkGameClient_localPlayer = 0xF0; 38 | constexpr std::ptrdiff_t dwNetworkGameClient_maxClients = 0x270; 39 | constexpr std::ptrdiff_t dwNetworkGameClient_serverTickCount = 0x174; 40 | constexpr std::ptrdiff_t dwNetworkGameClient_signOnState = 0x260; 41 | constexpr std::ptrdiff_t dwWindowHeight = 0x5F0424; 42 | constexpr std::ptrdiff_t dwWindowWidth = 0x5F0420; 43 | } 44 | // Module: inputsystem.dll 45 | namespace inputsystem_dll { 46 | constexpr std::ptrdiff_t dwInputSystem = 0x387F0; 47 | } 48 | // Module: matchmaking.dll 49 | namespace matchmaking_dll { 50 | constexpr std::ptrdiff_t dwGameTypes = 0x1A41C0; 51 | constexpr std::ptrdiff_t dwGameTypes_mapName = 0x120; 52 | } 53 | // Module: soundsystem.dll 54 | namespace soundsystem_dll { 55 | constexpr std::ptrdiff_t dwSoundSystem = 0x334E40; 56 | constexpr std::ptrdiff_t dwSoundSystem_engineViewData = 0x7C; 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /cs2-external-cheat/options.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imgui/imgui.h" 3 | 4 | namespace menu { 5 | inline bool bMenuVisible{ true }; 6 | 7 | inline bool bEnableAim{ false }; 8 | inline bool bFOV{ false }; 9 | inline bool bSmooth{ false }; 10 | inline bool bEnableTriggerbot{ false }; 11 | 12 | inline bool bEnableLines{ false }; 13 | inline bool bEnableESP{ false }; 14 | inline bool bEnableBox2D{ false }; 15 | inline bool bEnableBox2DFill{ false }; 16 | inline bool bEnableBox2DTeam{ false }; 17 | inline bool bEnableBox2DLines{ true }; 18 | inline bool bEnableBox3D{ false }; 19 | inline bool bEnableBox3DAnim{ false }; 20 | inline bool bEnableHealth{ false }; 21 | inline bool bEnableSkeletonTeam{ false }; 22 | inline bool bEnableDirection{ false }; 23 | inline bool bEnableBox3DTeam{ false }; 24 | inline bool bEnableName{ false }; 25 | inline bool bEnableJoints{ false }; 26 | inline bool bEnableSkeleton{ false }; 27 | inline bool bTeamVisible{ false }; 28 | 29 | inline unsigned short bToggleButton{ 0x2d }; 30 | inline unsigned short bEndButton{0x23}; 31 | } 32 | 33 | namespace options { 34 | inline ImVec4 boxes2DFillColor = ImVec4(1.0f, 0.0f, 0.0f, 0.4f); 35 | inline ImVec4 boxes2DLinesColor = ImVec4(1.0f, 0.0f, 0.0f, 0.4f); 36 | inline ImVec4 boxes2DFillColorTeam = ImVec4(0.0f, 0.0f, 1.0f, 0.4f); 37 | inline ImVec4 boxes2DLinesColorTeam = ImVec4(0.0f, 0.0f, 1.0f, 0.4f); 38 | 39 | inline ImVec4 snapLinesColorTeam = ImVec4(0.f, 0.f, 1.f, 1.f); 40 | 41 | inline ImVec4 boxes3DLinesColor = ImVec4(1.0f, 0.0f, 0.0f, 0.4f); 42 | inline ImVec4 boxes3DLinesColorTeam = ImVec4(0.0f, 0.0f, 1.0f, 0.4f); 43 | 44 | inline ImVec4 skeletonColor = ImVec4(1.0f, 0.0f, 0.0f, 0.4f); 45 | inline ImVec4 skeletonColorTeam = ImVec4(0.0f, 0.0f, 1.0f, 0.4f); 46 | 47 | inline ImVec4 snapLinesColor = ImVec4(1.0f, 0.0f, 0.0f, 0.4f); 48 | inline ImVec4 directionColor = ImVec4(1.0f, 0.0f, 0.0f, 0.4f); 49 | 50 | inline float radiusJoints = 40.f; 51 | inline float smoothness = 1.0f; 52 | inline float radiusFOV = 40.f; 53 | inline int triggerbotDelay = 1; 54 | inline int aimingType = 0; 55 | inline int aimButton{ 0 }; 56 | inline float box2DRounding = { 2.f }; 57 | } -------------------------------------------------------------------------------- /cs2-external-cheat/overlay.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "imgui_impl_dx11.h" 6 | #include "imgui_impl_win32.h" 7 | #include "overlay.h" 8 | 9 | LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 10 | 11 | bool Overlay::CreateOverlay() 12 | { 13 | wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr }; 14 | ::RegisterClassExW(&wc); 15 | hwnd = ::CreateWindowExW(WS_EX_TOPMOST, wc.lpszClassName, L"DjdasdaDH", WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), nullptr, nullptr, wc.hInstance, nullptr); 16 | 17 | SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 255, LWA_ALPHA); 18 | MARGINS margin = { -1 }; 19 | DwmExtendFrameIntoClientArea(hwnd, &margin); 20 | 21 | if (!CreateDeviceD3D()) 22 | { 23 | CleanupDeviceD3D(); 24 | ::UnregisterClassW(wc.lpszClassName, wc.hInstance); 25 | return false; 26 | } 27 | 28 | ::ShowWindow(hwnd, SW_SHOWDEFAULT); 29 | ::UpdateWindow(hwnd); 30 | 31 | return true; 32 | } 33 | 34 | void Overlay::imguiInit() { 35 | ImGui_ImplWin32_Init(hwnd); 36 | ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); 37 | } 38 | 39 | void Overlay::MakeNewFrame() { 40 | ImGui_ImplDX11_NewFrame(); 41 | ImGui_ImplWin32_NewFrame(); 42 | ImGui::NewFrame(); 43 | } 44 | 45 | void Overlay::RenderGui(){ 46 | ImGui::Render(); 47 | g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, nullptr); 48 | g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, clear_color_with_alpha); 49 | ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); 50 | 51 | g_pSwapChain->Present(1, 0); 52 | } 53 | 54 | void Overlay::ReleaseOverlay(){ 55 | ImGui_ImplDX11_Shutdown(); 56 | ImGui_ImplWin32_Shutdown(); 57 | ImGui::DestroyContext(); 58 | 59 | CleanupDeviceD3D(); 60 | ::DestroyWindow(hwnd); 61 | ::UnregisterClassW(wc.lpszClassName, wc.hInstance); 62 | } 63 | 64 | bool Overlay::CreateDeviceD3D() 65 | { 66 | DXGI_SWAP_CHAIN_DESC sd; 67 | ZeroMemory(&sd, sizeof(sd)); 68 | sd.BufferCount = 2; 69 | sd.BufferDesc.Width = 0; 70 | sd.BufferDesc.Height = 0; 71 | sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 72 | sd.BufferDesc.RefreshRate.Numerator = 60; 73 | sd.BufferDesc.RefreshRate.Denominator = 1; 74 | sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; 75 | sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 76 | sd.OutputWindow = hwnd; 77 | sd.SampleDesc.Count = 1; 78 | sd.SampleDesc.Quality = 0; 79 | sd.Windowed = TRUE; 80 | sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; 81 | 82 | UINT createDeviceFlags = 0; 83 | D3D_FEATURE_LEVEL featureLevel; 84 | const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, }; 85 | HRESULT res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext); 86 | if (res == DXGI_ERROR_UNSUPPORTED) 87 | res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_WARP, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext); 88 | if (res != S_OK) 89 | return false; 90 | 91 | CreateRenderTarget(); 92 | return true; 93 | } 94 | 95 | void Overlay::CleanupDeviceD3D() 96 | { 97 | CleanupRenderTarget(); 98 | if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = nullptr; } 99 | if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = nullptr; } 100 | if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = nullptr; } 101 | } 102 | 103 | void Overlay::CreateRenderTarget() 104 | { 105 | ID3D11Texture2D* pBackBuffer; 106 | g_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); 107 | g_pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &g_mainRenderTargetView); 108 | pBackBuffer->Release(); 109 | } 110 | 111 | void Overlay::CleanupRenderTarget() 112 | { 113 | if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = nullptr; } 114 | } 115 | 116 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 117 | 118 | LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 119 | { 120 | if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) 121 | { 122 | return true; 123 | } 124 | 125 | switch (msg) 126 | { 127 | case WM_SIZE: 128 | if (wParam == SIZE_MINIMIZED) 129 | return 0; 130 | overlay.g_ResizeWidth = (UINT)LOWORD(lParam); 131 | overlay.g_ResizeHeight = (UINT)HIWORD(lParam); 132 | return 0; 133 | case WM_SYSCOMMAND: 134 | if ((wParam & 0xfff0) == SC_KEYMENU) 135 | return 0; 136 | break; 137 | case WM_DESTROY: 138 | ::PostQuitMessage(0); 139 | return 0; 140 | } 141 | 142 | return ::DefWindowProcW(hWnd, msg, wParam, lParam); 143 | } -------------------------------------------------------------------------------- /cs2-external-cheat/overlay.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "imgui.h" 5 | 6 | class Overlay { 7 | public: 8 | WNDCLASSEXW wc; 9 | bool done = false; 10 | ImVec4 clear_color = ImVec4(0.f, 0.f, 0.f, 0.f); 11 | float clear_color_with_alpha[4] = { 0.f, 0.f, 0.f, 0.f }; 12 | HWND hwnd; 13 | 14 | ID3D11Device* g_pd3dDevice = nullptr; 15 | ID3D11DeviceContext* g_pd3dDeviceContext = nullptr; 16 | IDXGISwapChain* g_pSwapChain = nullptr; 17 | UINT g_ResizeWidth = 0, g_ResizeHeight = 0; 18 | ID3D11RenderTargetView* g_mainRenderTargetView = nullptr; 19 | public: 20 | bool CreateOverlay(); 21 | bool CreateDeviceD3D(); 22 | void CleanupDeviceD3D(); 23 | void CreateRenderTarget(); 24 | void CleanupRenderTarget(); 25 | void ReleaseOverlay(); 26 | void RenderGui(); 27 | void MakeNewFrame(); 28 | void imguiInit(); 29 | }; 30 | 31 | inline Overlay overlay; -------------------------------------------------------------------------------- /cs2-external-cheat/visuals.cpp: -------------------------------------------------------------------------------- 1 | #include "imgui.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "visuals.h" 7 | #include "math.h" 8 | #include "options.h" 9 | #include "memory.h" 10 | #include "datatypes.h" 11 | #include "offsets.h" 12 | #include "visuals.h" 13 | 14 | #define M_PI 3.14159265358979323846 15 | 16 | ImColor colorHealth(50, 205, 50, 255); 17 | 18 | void startEsp(Matrix& viewMatrix, game::CSplayerPawn& playerPawn, std::string& entityName, bool teammate) { 19 | 20 | Vec2 screenFeetCoords; 21 | Vec2 screenHeadCoords; 22 | 23 | if (!WorldToScreen(playerPawn.headPos, screenHeadCoords, viewMatrix.VMatrix)) return; 24 | if (!WorldToScreen(playerPawn.feetPos, screenFeetCoords, viewMatrix.VMatrix)) return; 25 | 26 | ImU32 lineColor; 27 | ImU32 boxFillColor; 28 | ImU32 boxLineColor; 29 | ImU32 box3DLineColor; 30 | ImU32 skeletonColor; 31 | 32 | if (teammate) { 33 | if (menu::bTeamVisible) { 34 | lineColor = ImColor(options::snapLinesColorTeam); 35 | boxFillColor = ImColor(options::boxes2DFillColorTeam); 36 | boxLineColor = ImColor(options::boxes2DLinesColorTeam); 37 | box3DLineColor = ImColor(options::boxes3DLinesColorTeam); 38 | skeletonColor = ImColor(options::skeletonColorTeam); 39 | } 40 | else { 41 | boxFillColor = ImColor(0.f, 0.f, 0.f, 0.f); 42 | lineColor = ImColor(0.f, 0.f, 0.f, 0.f); 43 | boxLineColor = ImColor(0.f, 0.f, 0.f, 0.f); 44 | box3DLineColor = ImColor(0.f, 0.f, 0.f, 0.f); 45 | skeletonColor = ImColor(0.f, 0.f, 0.f, 0.f); 46 | } 47 | } 48 | else { 49 | lineColor = ImColor(options::snapLinesColor); 50 | boxFillColor = ImColor(options::boxes2DFillColor); 51 | boxLineColor = ImColor(options::boxes2DLinesColor); 52 | box3DLineColor = ImColor(options::boxes3DLinesColor); 53 | skeletonColor = ImColor(options::skeletonColor); 54 | } 55 | 56 | if (menu::bEnableLines) { 57 | drawLines(screenFeetCoords, lineColor); 58 | } 59 | if (menu::bEnableBox2D) { 60 | drawBox2D(screenHeadCoords, screenFeetCoords, boxFillColor, boxLineColor); 61 | } 62 | if (menu::bEnableBox3D) { 63 | drawBox3D(viewMatrix, playerPawn.feetPos, playerPawn.headPos, box3DLineColor); 64 | } 65 | if (menu::bEnableSkeleton) { 66 | drawSkeleton(playerPawn, skeletonColor); 67 | } 68 | 69 | if (teammate && !menu::bTeamVisible) return; 70 | 71 | if (menu::bEnableHealth) { 72 | drawHealth(screenHeadCoords, screenFeetCoords, playerPawn.playerHealth); 73 | } 74 | if (menu::bEnableDirection) { 75 | drawViewDirection(playerPawn.BonePosList[head].ScreenPos, playerPawn.viewAngles, playerPawn.headPos, viewMatrix, options::directionColor); 76 | } 77 | if (menu::bEnableName) { 78 | drawName(screenHeadCoords, entityName); 79 | } 80 | } 81 | 82 | void drawLines(Vec2& end, ImColor color) { 83 | ImGui::GetBackgroundDrawList()->AddLine(ImVec2(offsets.windowWidth / 2, offsets.windowHeight), end, color, 2.f); 84 | } 85 | 86 | void drawBox2D(Vec2& coordsHead, Vec2& coordsFeet, ImColor colorFill, ImColor colorLines) { 87 | float boxHeight = coordsFeet.y - coordsHead.y; 88 | float boxWidth = boxHeight / 4.5f; 89 | 90 | ImVec2 startPos = { coordsHead.x - boxWidth, coordsHead.y }; 91 | ImVec2 endPos = { coordsHead.x + boxWidth, coordsFeet.y }; 92 | 93 | if (menu::bEnableBox2DFill) { 94 | ImGui::GetBackgroundDrawList()->AddRectFilled(startPos, endPos, colorFill, options::box2DRounding); 95 | } 96 | 97 | if (menu::bEnableBox2DLines) { 98 | ImGui::GetBackgroundDrawList()->AddRect(startPos, endPos, colorLines, options::box2DRounding, 0, 1.4f); 99 | } 100 | } 101 | 102 | void drawBox3D(Matrix& viewMatrix, Vec3& entityLocationFeet, Vec3& entityLocationHead, ImColor colorLines) { 103 | float h = entityLocationHead.z - entityLocationFeet.z; 104 | float w = h / 3.5f; 105 | 106 | float cx = (entityLocationHead.x + entityLocationFeet.x) / 2.0f; 107 | float cy = (entityLocationHead.y + entityLocationFeet.y) / 2.0f; 108 | float cz = (entityLocationHead.z + entityLocationFeet.z) / 2.0f; 109 | 110 | Vec3 vertices[8] = { 111 | {cx - w / 2, cy - w / 2, cz - h / 2}, 112 | {cx + w / 2, cy - w / 2, cz - h / 2}, 113 | {cx + w / 2, cy + w / 2, cz - h / 2}, 114 | {cx - w / 2, cy + w / 2, cz - h / 2}, 115 | {cx - w / 2, cy - w / 2, cz + h / 2}, 116 | {cx + w / 2, cy - w / 2, cz + h / 2}, 117 | {cx + w / 2, cy + w / 2, cz + h / 2}, 118 | {cx - w / 2, cy + w / 2, cz + h / 2} 119 | }; 120 | 121 | Vec2 screenCoord3DParts[8]; 122 | 123 | for (int i = 0; i < 8; ++i) { 124 | WorldToScreen(vertices[i], screenCoord3DParts[i], viewMatrix.VMatrix); 125 | } 126 | 127 | Vec2 tempLines[4] = { 128 | screenCoord3DParts[4] - screenCoord3DParts[0], 129 | screenCoord3DParts[5] - screenCoord3DParts[1], 130 | screenCoord3DParts[6] - screenCoord3DParts[2], 131 | screenCoord3DParts[7] - screenCoord3DParts[3], 132 | }; 133 | 134 | //animation lines 135 | 136 | static float counter = 0; 137 | static float speed = 0.01; 138 | 139 | counter += speed; 140 | 141 | float sineValue = (sin(counter) + 1) / 2; 142 | sineValue = sineValue * sineValue * (10 - 2 * sineValue); 143 | sineValue = sineValue * 8 + 1; 144 | 145 | //down 146 | 147 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[0], screenCoord3DParts[1], colorLines, 2.5f); 148 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[1], screenCoord3DParts[2], colorLines, 2.5f); 149 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[2], screenCoord3DParts[3], colorLines, 2.5f); 150 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[3], screenCoord3DParts[0], colorLines, 2.5f); 151 | 152 | ////up 153 | 154 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[4], screenCoord3DParts[5], colorLines, 2.5f); 155 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[5], screenCoord3DParts[6], colorLines, 2.5f); 156 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[6], screenCoord3DParts[7], colorLines, 2.5f); 157 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[7], screenCoord3DParts[4], colorLines, 2.5f); 158 | 159 | ////tempLines 160 | 161 | if (menu::bEnableBox3DAnim) { 162 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[4] - tempLines[0] / sineValue, screenCoord3DParts[5] - tempLines[1] / sineValue, colorLines, 2.5f); 163 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[5] - tempLines[1] / sineValue, screenCoord3DParts[6] - tempLines[2] / sineValue, colorLines, 2.5f); 164 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[6] - tempLines[2] / sineValue, screenCoord3DParts[7] - tempLines[3] / sineValue, colorLines, 2.5f); 165 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[7] - tempLines[3] / sineValue, screenCoord3DParts[4] - tempLines[0] / sineValue, colorLines, 2.5f); 166 | } 167 | 168 | ////central 169 | 170 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[0], screenCoord3DParts[4], colorLines, 2.5f); 171 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[1], screenCoord3DParts[5], colorLines, 2.5f); 172 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[2], screenCoord3DParts[6], colorLines, 2.5f); 173 | ImGui::GetBackgroundDrawList()->AddLine(screenCoord3DParts[3], screenCoord3DParts[7], colorLines, 2.5f); 174 | } 175 | 176 | void drawViewDirection(Vec2& coordsHead, Vec2& entityViewAngles, Vec3& entityLocationHead, Matrix& viewMatrix, ImColor color) { 177 | float viewDistance = 40.0f; 178 | 179 | float LineLength = cos(entityViewAngles.x * M_PI / 180) * viewDistance; 180 | 181 | Vec3 endPoint; 182 | endPoint.x = entityLocationHead.x + cos(entityViewAngles.y * M_PI / 180) * LineLength; 183 | endPoint.y = entityLocationHead.y + sin(entityViewAngles.y * M_PI / 180) * LineLength; 184 | endPoint.z = entityLocationHead.z - sin(entityViewAngles.x * M_PI / 180) * viewDistance; 185 | 186 | Vec2 screenCoordEnd; 187 | WorldToScreen(endPoint, screenCoordEnd, viewMatrix.VMatrix); 188 | 189 | ImGui::GetBackgroundDrawList()->AddLine(coordsHead, screenCoordEnd, color, 2.0f); 190 | } 191 | 192 | void drawHealth(Vec2& coordsHead, Vec2& coordsFeet, short entityHealth) { 193 | float boxHeight = coordsHead.y - coordsFeet.y; 194 | 195 | float boxWidth = boxHeight / 4.4f; 196 | float boxWidth2 = boxWidth * 1.07f; 197 | 198 | float healthBarHeight = boxHeight * (entityHealth / 100.0f); 199 | float healthBarTopY = coordsFeet.y + healthBarHeight; 200 | 201 | ImVec2 start{ coordsHead.x + boxWidth, coordsFeet.y}; 202 | ImVec2 end{ coordsHead.x + boxWidth2, healthBarTopY }; 203 | 204 | ImGui::GetBackgroundDrawList()->AddRectFilled(start, end, colorHealth, 0.f); 205 | } 206 | 207 | void drawName(Vec2& coordsHead, std::string& entityName) { 208 | ImFont* font = ImGui::GetFont(); 209 | float fontSize = ImGui::GetFontSize(); 210 | 211 | ImVec2 textSize = ImGui::CalcTextSize(entityName.c_str(), nullptr, false, fontSize); 212 | 213 | ImVec2 centeredPos = ImVec2(coordsHead.x - textSize.x / 2.f, coordsHead.y - textSize.y / 3.f); 214 | 215 | ImGui::GetBackgroundDrawList()->AddText(font, fontSize, centeredPos, ImColor(255, 255, 255, 255), entityName.c_str()); 216 | } 217 | 218 | void drawSkeleton(game::CSplayerPawn& entityPawn, ImColor colorSkeleton) { 219 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[head].ScreenPos, entityPawn.BonePosList[neck_0].ScreenPos, colorSkeleton); 220 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[neck_0].ScreenPos, entityPawn.BonePosList[arm_upper_L].ScreenPos, colorSkeleton); 221 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[neck_0].ScreenPos, entityPawn.BonePosList[arm_upper_R].ScreenPos, colorSkeleton); 222 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[neck_0].ScreenPos, entityPawn.BonePosList[spine_1].ScreenPos, colorSkeleton); 223 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[spine_1].ScreenPos, entityPawn.BonePosList[spine_2].ScreenPos, colorSkeleton); 224 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[arm_lower_L].ScreenPos, entityPawn.BonePosList[arm_upper_L].ScreenPos, colorSkeleton); 225 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[arm_lower_R].ScreenPos, entityPawn.BonePosList[arm_upper_R].ScreenPos, colorSkeleton); 226 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[spine_2].ScreenPos, entityPawn.BonePosList[pelvis].ScreenPos, colorSkeleton); 227 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[pelvis].ScreenPos, entityPawn.BonePosList[leg_upper_L ].ScreenPos, colorSkeleton); 228 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[pelvis].ScreenPos, entityPawn.BonePosList[leg_upper_R].ScreenPos, colorSkeleton); 229 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[arm_lower_L].ScreenPos, entityPawn.BonePosList[hand_L].ScreenPos, colorSkeleton); 230 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[arm_lower_R].ScreenPos, entityPawn.BonePosList[hand_R].ScreenPos, colorSkeleton); 231 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[leg_upper_L].ScreenPos, entityPawn.BonePosList[leg_lower_L].ScreenPos, colorSkeleton); 232 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[leg_upper_R].ScreenPos, entityPawn.BonePosList[leg_lower_R].ScreenPos, colorSkeleton); 233 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[leg_lower_R].ScreenPos, entityPawn.BonePosList[ankle_R].ScreenPos, colorSkeleton); 234 | ImGui::GetBackgroundDrawList()->AddLine(entityPawn.BonePosList[leg_lower_L].ScreenPos, entityPawn.BonePosList[ankle_L].ScreenPos, colorSkeleton); 235 | } -------------------------------------------------------------------------------- /cs2-external-cheat/visuals.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imgui/imgui.h" 3 | #include "datatypes.h" 4 | #include "offsets.h" 5 | 6 | void startEsp(Matrix& viewMatrix, game::CSplayerPawn& playerPawn, std::string& entityName, bool teammate); 7 | void drawLines(Vec2& end, ImColor color); 8 | void drawBox2D(Vec2& coordsHead, Vec2& coordsFeet, ImColor colorFill, ImColor colorLines); 9 | void drawBox3D(Matrix& viewMatrix, Vec3& playerLocationFeet, Vec3& playerLocationHead, ImColor colorLines); 10 | void drawHealth(Vec2& coordsHead, Vec2& coordsFeet, short entityHealth); 11 | void drawViewDirection(Vec2& coordsHead, Vec2& entityViewAngles, Vec3& entityLocationHead, Matrix& viewMatrix, ImColor color); 12 | void drawName(Vec2& coordsHead, std::string& entityName); 13 | void drawSkeleton(game::CSplayerPawn& entityPawn, ImColor colorSkeleton); --------------------------------------------------------------------------------