├── .gitattributes ├── .gitignore ├── CS2_External.sln ├── CS2_External ├── AimBot.hpp ├── AntiFlashbang.hpp ├── Bone.cpp ├── Bone.h ├── Bunnyhop.hpp ├── CS2_External.vcxproj ├── CS2_External.vcxproj.filters ├── Cheats.cpp ├── Cheats.h ├── Entity.cpp ├── Entity.h ├── Game.cpp ├── Game.h ├── GlobalVars.cpp ├── GlobalVars.h ├── Globals.hpp ├── MenuConfig.hpp ├── OS-ImGui │ ├── OS-ImGui.cpp │ ├── OS-ImGui.h │ ├── OS-ImGui_Base.cpp │ ├── OS-ImGui_Base.h │ ├── OS-ImGui_Exception.hpp │ ├── OS-ImGui_External.cpp │ ├── OS-ImGui_External.h │ ├── OS-ImGui_Struct.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 ├── Offsets.cpp ├── Offsets.h ├── Radar │ ├── Radar.cpp │ └── Radar.h ├── Render.hpp ├── TriggerBot.cpp ├── TriggerBot.h ├── Utils │ ├── ConfigMenu.cpp │ ├── ConfigMenu.hpp │ ├── ConfigSaver.cpp │ ├── ConfigSaver.hpp │ ├── Format.hpp │ ├── MemorySearch.cpp │ └── ProcessManager.hpp ├── View.hpp └── main.cpp ├── Image2.png ├── LICENSE.txt └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd 364 | /CS2_External/imgui.ini 365 | -------------------------------------------------------------------------------- /CS2_External.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33815.320 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CS2_External", "CS2_External\CS2_External.vcxproj", "{82688835-FBA1-418A-9AD2-9A2D94C0FD47}" 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 | {82688835-FBA1-418A-9AD2-9A2D94C0FD47}.Debug|x64.ActiveCfg = Debug|x64 17 | {82688835-FBA1-418A-9AD2-9A2D94C0FD47}.Debug|x64.Build.0 = Debug|x64 18 | {82688835-FBA1-418A-9AD2-9A2D94C0FD47}.Debug|x86.ActiveCfg = Debug|Win32 19 | {82688835-FBA1-418A-9AD2-9A2D94C0FD47}.Debug|x86.Build.0 = Debug|Win32 20 | {82688835-FBA1-418A-9AD2-9A2D94C0FD47}.Release|x64.ActiveCfg = Release|x64 21 | {82688835-FBA1-418A-9AD2-9A2D94C0FD47}.Release|x64.Build.0 = Release|x64 22 | {82688835-FBA1-418A-9AD2-9A2D94C0FD47}.Release|x86.ActiveCfg = Release|Win32 23 | {82688835-FBA1-418A-9AD2-9A2D94C0FD47}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {F91FE735-0543-4348-A2BB-1C18621BA7FF} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /CS2_External/AimBot.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define _USE_MATH_DEFINES 3 | #include 4 | #include "Game.h" 5 | #include "Entity.h" 6 | #include 7 | 8 | 9 | namespace AimControl 10 | { 11 | inline int HotKey = VK_LBUTTON; 12 | inline float AimFov = 5; 13 | inline float Smooth = 0.7; 14 | inline Vec2 RCSScale = { 1.f,1.f }; 15 | inline int RCSBullet = 1; 16 | inline std::vector HotKeyList{VK_LBUTTON, VK_LMENU, VK_RBUTTON, VK_XBUTTON1, VK_XBUTTON2, VK_CAPITAL, VK_LSHIFT, VK_LCONTROL};// added new button VK_LBUTTON 17 | 18 | inline void SetHotKey(int Index) 19 | { 20 | HotKey = HotKeyList.at(Index); 21 | } 22 | 23 | inline void AimBot(const CEntity& Local, Vec3 LocalPos, Vec3 AimPos) 24 | { 25 | float Yaw, Pitch; 26 | float Distance, Norm; 27 | Vec3 OppPos; 28 | 29 | OppPos = AimPos - LocalPos; 30 | 31 | Distance = sqrt(pow(OppPos.x, 2) + pow(OppPos.y, 2)); 32 | 33 | Yaw = atan2f(OppPos.y, OppPos.x) * 57.295779513 - Local.Pawn.ViewAngle.y; 34 | Pitch = -atan(OppPos.z / Distance) * 57.295779513 - Local.Pawn.ViewAngle.x; 35 | Norm = sqrt(pow(Yaw, 2) + pow(Pitch, 2)); 36 | if (Norm > AimFov) 37 | return; 38 | 39 | Yaw = Yaw * (1 - Smooth) + Local.Pawn.ViewAngle.y; 40 | Pitch = Pitch * (1 - Smooth) + Local.Pawn.ViewAngle.x; 41 | 42 | // Recoil control 43 | if (Local.Pawn.ShotsFired > RCSBullet) 44 | { 45 | Vec2 PunchAngle; 46 | if (Local.Pawn.AimPunchCache.Count <= 0 && Local.Pawn.AimPunchCache.Count > 0xFFFF) 47 | return; 48 | if (!ProcessMgr.ReadMemory(Local.Pawn.AimPunchCache.Data + (Local.Pawn.AimPunchCache.Count - 1) * sizeof(Vec3), PunchAngle)) 49 | return; 50 | 51 | Yaw = Yaw - PunchAngle.y * RCSScale.x; 52 | Pitch = Pitch - PunchAngle.x * RCSScale.y; 53 | } 54 | 55 | gGame.SetViewAngle(Yaw, Pitch); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CS2_External/AntiFlashbang.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Entity.h" 4 | 5 | namespace AntiFlashbang 6 | { 7 | inline void Run(const CEntity &aLocalPlayer) noexcept 8 | { 9 | float duration{}; 10 | ProcessMgr.WriteMemory(aLocalPlayer.Pawn.Address + Offset::Pawn.flFlashDuration, duration); 11 | } 12 | } // namespace AntiFlashbang 13 | -------------------------------------------------------------------------------- /CS2_External/Bone.cpp: -------------------------------------------------------------------------------- 1 | #include "Bone.h" 2 | 3 | bool CBone::UpdateAllBoneData(const DWORD64& EntityPawnAddress) 4 | { 5 | if (EntityPawnAddress == 0) 6 | return false; 7 | this->EntityPawnAddress = EntityPawnAddress; 8 | 9 | DWORD64 GameSceneNode = 0; 10 | DWORD64 BoneArrayAddress = 0; 11 | if (!ProcessMgr.ReadMemory(EntityPawnAddress + Offset::Pawn.GameSceneNode, GameSceneNode)) 12 | return false; 13 | if (!ProcessMgr.ReadMemory(GameSceneNode + Offset::Pawn.BoneArray, BoneArrayAddress)) 14 | return false; 15 | 16 | BoneJointData BoneArray[30]{}; 17 | if (!ProcessMgr.ReadMemory(BoneArrayAddress, BoneArray, 30 * sizeof(BoneJointData))) 18 | return false; 19 | 20 | for (int i = 0; i < 30; i++) 21 | { 22 | Vec2 ScreenPos; 23 | bool IsVisible = false; 24 | 25 | if (gGame.View.WorldToScreen(BoneArray[i].Pos, ScreenPos)) 26 | IsVisible = true; 27 | 28 | this->BonePosList.push_back({ BoneArray[i].Pos ,ScreenPos,IsVisible }); 29 | } 30 | 31 | return this->BonePosList.size() > 0; 32 | } -------------------------------------------------------------------------------- /CS2_External/Bone.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/Bone.h -------------------------------------------------------------------------------- /CS2_External/Bunnyhop.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MenuConfig.hpp" 3 | #include "Entity.h" 4 | #include 5 | #include 6 | 7 | namespace Bunnyhop 8 | { 9 | inline bool AirCheck(const CEntity& Local) 10 | { 11 | const bool hasFlagInAir = Local.Pawn.HasFlag(PlayerPawn::Flags::IN_AIR); 12 | return hasFlagInAir; 13 | } 14 | 15 | inline void Run(const CEntity& Local) 16 | { 17 | if (!MenuConfig::BunnyHop) 18 | return; 19 | 20 | int ForceJump = 0; 21 | bool spacePressed = GetAsyncKeyState(VK_SPACE); 22 | bool isInAir = AirCheck(Local); 23 | gGame.SetForceJump(ForceJump); 24 | 25 | if (spacePressed && isInAir) 26 | { 27 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); // milliseconds 28 | gGame.SetForceJump(65537); 29 | } 30 | else if (spacePressed && !isInAir) 31 | { 32 | gGame.SetForceJump(256); 33 | } 34 | else if (!spacePressed && ForceJump == 65537) 35 | { 36 | gGame.SetForceJump(256); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CS2_External/CS2_External.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 | {82688835-fba1-418a-9ad2-9a2d94c0fd47} 25 | CS2External 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 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 | 75 | Level3 76 | true 77 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 78 | true 79 | 80 | 81 | Console 82 | true 83 | 84 | 85 | 86 | 87 | Level3 88 | true 89 | true 90 | true 91 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 92 | true 93 | 94 | 95 | Console 96 | true 97 | true 98 | true 99 | 100 | 101 | 102 | 103 | Level3 104 | true 105 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 106 | true 107 | stdcpp17 108 | 109 | 110 | Console 111 | true 112 | RequireAdministrator 113 | 114 | 115 | 116 | 117 | Level3 118 | true 119 | true 120 | true 121 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 122 | true 123 | stdcpp17 124 | Speed 125 | AdvancedVectorExtensions2 126 | Fast 127 | 128 | 129 | Console 130 | true 131 | true 132 | true 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /CS2_External/CS2_External.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {b2e13447-07ee-4738-973e-dff75512b687} 6 | 7 | 8 | {5e80ef5d-5f4b-49ee-b443-120bb14cf27a} 9 | 10 | 11 | {ab218404-3f90-49c1-936f-945331e62f77} 12 | 13 | 14 | {dc44f983-6ac1-4cd3-892d-2e8877ec0950} 15 | 16 | 17 | {6d31e8d7-d8c1-4306-ab66-a79fab5a28b7} 18 | 19 | 20 | {3d76d523-ebe1-46aa-982f-99e167ac6724} 21 | 22 | 23 | {ecf8f725-5819-4b5b-9e16-3ada7ee8c84f} 24 | 25 | 26 | {0af61bf5-c236-403c-a0f8-48488f87bfcf} 27 | 28 | 29 | {4ee44a79-e9da-483b-8c8c-46209c06c557} 30 | 31 | 32 | {e372b7a9-eba4-42de-9802-b1368314d465} 33 | 34 | 35 | {aa25e002-e95d-4db7-a900-3cd9edf6338f} 36 | 37 | 38 | 39 | 40 | OS-ImGui\imgui 41 | 42 | 43 | OS-ImGui\imgui 44 | 45 | 46 | OS-ImGui\imgui 47 | 48 | 49 | OS-ImGui\imgui 50 | 51 | 52 | OS-ImGui\imgui 53 | 54 | 55 | OS-ImGui\imgui 56 | 57 | 58 | OS-ImGui\imgui 59 | 60 | 61 | OS-ImGui\imgui 62 | 63 | 64 | OS-ImGui 65 | 66 | 67 | OS-ImGui 68 | 69 | 70 | OS-ImGui 71 | 72 | 73 | OS-ImGui 74 | 75 | 76 | OS-ImGui 77 | 78 | 79 | Utils 80 | 81 | 82 | Cheats\View 83 | 84 | 85 | Cheats\Data 86 | 87 | 88 | Cheats\Data 89 | 90 | 91 | Cheats 92 | 93 | 94 | Cheats\Data 95 | 96 | 97 | Cheats 98 | 99 | 100 | Cheats 101 | 102 | 103 | Cheats\Offsets 104 | 105 | 106 | Cheats\MenuConfig 107 | 108 | 109 | Cheats\Radar 110 | 111 | 112 | Cheats 113 | 114 | 115 | Utils\ConfigSaver 116 | 117 | 118 | Utils\ConfigSaver 119 | 120 | 121 | Cheats 122 | 123 | 124 | Utils 125 | 126 | 127 | Cheats\Data 128 | 129 | 130 | Cheats 131 | 132 | 133 | Cheats 134 | 135 | 136 | 137 | 138 | OS-ImGui\imgui 139 | 140 | 141 | OS-ImGui\imgui 142 | 143 | 144 | OS-ImGui\imgui 145 | 146 | 147 | OS-ImGui\imgui 148 | 149 | 150 | OS-ImGui\imgui 151 | 152 | 153 | OS-ImGui\imgui 154 | 155 | 156 | OS-ImGui\imgui 157 | 158 | 159 | OS-ImGui 160 | 161 | 162 | OS-ImGui 163 | 164 | 165 | OS-ImGui 166 | 167 | 168 | Entry 169 | 170 | 171 | Cheats\Data 172 | 173 | 174 | Cheats\Data 175 | 176 | 177 | Cheats 178 | 179 | 180 | Cheats\Data 181 | 182 | 183 | Cheats\Offsets 184 | 185 | 186 | Utils 187 | 188 | 189 | Cheats\Radar 190 | 191 | 192 | Cheats 193 | 194 | 195 | Utils\ConfigSaver 196 | 197 | 198 | Utils\ConfigSaver 199 | 200 | 201 | Cheats\Data 202 | 203 | 204 | -------------------------------------------------------------------------------- /CS2_External/Cheats.cpp: -------------------------------------------------------------------------------- 1 | #include "Cheats.h" 2 | #include "Render.hpp" 3 | #include "MenuConfig.hpp" 4 | #include "Utils/ConfigMenu.hpp" 5 | #include "Utils/ConfigSaver.hpp" 6 | 7 | void Cheats::Menu() 8 | { 9 | static bool IsMenuInit = false; 10 | if (!IsMenuInit) 11 | { 12 | ImGui::GetStyle().Colors[ImGuiCol_WindowBg].w = 0.75; 13 | IsMenuInit = true; 14 | } 15 | 16 | ImGui::Begin("Menu",nullptr,ImGuiWindowFlags_AlwaysAutoResize); 17 | { 18 | ImGui::BeginTabBar("Cheat"); 19 | // esp menu 20 | if (ImGui::BeginTabItem("ESP")) 21 | { 22 | Gui.MyCheckBox("BoxESP", &MenuConfig::ShowBoxESP); 23 | ImGui::SameLine(); 24 | ImGui::ColorEdit4("##BoxColor", reinterpret_cast(&MenuConfig::BoxColor), ImGuiColorEditFlags_NoInputs); 25 | 26 | ImGui::Combo("BoxType", &MenuConfig::BoxType, "Normal\0Dynamic"); 27 | 28 | Gui.MyCheckBox("BoneESP", &MenuConfig::ShowBoneESP); 29 | ImGui::SameLine(); 30 | ImGui::ColorEdit4("##BoneColor", reinterpret_cast(&MenuConfig::BoneColor), ImGuiColorEditFlags_NoInputs); 31 | 32 | Gui.MyCheckBox("EyeRay", &MenuConfig::ShowEyeRay); 33 | ImGui::SameLine(); 34 | ImGui::ColorEdit4("##EyeRay", reinterpret_cast(&MenuConfig::EyeRayColor), ImGuiColorEditFlags_NoInputs); 35 | 36 | Gui.MyCheckBox("HealthBar", &MenuConfig::ShowHealthBar); 37 | ImGui::Combo("HealthBarType", &MenuConfig::HealthBarType, "Vetical\0Horizontal"); 38 | 39 | Gui.MyCheckBox("WeaponText", &MenuConfig::ShowWeaponESP); 40 | Gui.MyCheckBox("Distance", &MenuConfig::ShowDistance); 41 | Gui.MyCheckBox("PlayerName", &MenuConfig::ShowPlayerName); 42 | 43 | Gui.MyCheckBox("HeadShootLine", &MenuConfig::ShowHeadShootLine); 44 | ImGui::SameLine(); 45 | ImGui::ColorEdit4("##HeadShootLineColor", reinterpret_cast(&MenuConfig::HeadShootLineColor), ImGuiColorEditFlags_NoInputs); 46 | 47 | Gui.MyCheckBox("FovLine", &MenuConfig::ShowFovLine); 48 | ImGui::SameLine(); 49 | ImGui::ColorEdit4("##FovLineColor", reinterpret_cast(&MenuConfig::FovLineColor), ImGuiColorEditFlags_NoInputs); 50 | float FovLineSizeMin = 20.f, FovLineSizeMax = 120.f; 51 | Gui.SliderScalarEx1("FovLineSize", ImGuiDataType_Float, &MenuConfig::FovLineSize, &FovLineSizeMin, &FovLineSizeMax, "%.1f", ImGuiSliderFlags_None); 52 | 53 | Gui.MyCheckBox("LineToEnemy", &MenuConfig::ShowLineToEnemy); 54 | ImGui::SameLine(); 55 | ImGui::ColorEdit4("##LineToEnemyColor", reinterpret_cast(&MenuConfig::LineToEnemyColor), ImGuiColorEditFlags_NoInputs); 56 | 57 | Gui.MyCheckBox("CrossHair", &MenuConfig::ShowCrossHair); 58 | ImGui::SameLine(); 59 | ImGui::ColorEdit4("##CrossHairColor", reinterpret_cast(&MenuConfig::CrossHairColor), ImGuiColorEditFlags_NoInputs); 60 | float CrossHairSizeMin = 15, CrossHairSizeMax = 200; 61 | Gui.SliderScalarEx1("CrossHairSize", ImGuiDataType_Float, &MenuConfig::CrossHairSize, &CrossHairSizeMin, &CrossHairSizeMax, "%.1f", ImGuiSliderFlags_None); 62 | 63 | ImGui::EndTabItem(); 64 | } 65 | 66 | // aimbot menu 67 | if (ImGui::BeginTabItem("AimBot ")) 68 | { 69 | Gui.MyCheckBox("AimBot", &MenuConfig::AimBot); 70 | 71 | if (ImGui::Combo("AimKey", &MenuConfig::AimBotHotKey, "LBUTTON\0MENU\0RBUTTON\0XBUTTON1\0XBUTTON2\0CAPITAL\0SHIFT\0CONTROL"))// added LBUTTON 72 | { 73 | AimControl::SetHotKey(MenuConfig::AimBotHotKey); 74 | } 75 | 76 | float FovMin = 0.1f, FovMax = 89.f; 77 | float SmoothMin = 0.f, SmoothMax = 0.9f; 78 | Gui.SliderScalarEx1("AimFov", ImGuiDataType_Float, &AimControl::AimFov, &FovMin, &FovMax, "%.1f", ImGuiSliderFlags_None); 79 | Gui.MyCheckBox("FovCircle", &MenuConfig::ShowAimFovRange); 80 | ImGui::SameLine(); 81 | ImGui::ColorEdit4("##FovCircleColor", reinterpret_cast(&MenuConfig::AimFovRangeColor), ImGuiColorEditFlags_NoInputs); 82 | 83 | Gui.SliderScalarEx1("Smooth", ImGuiDataType_Float, &AimControl::Smooth, &SmoothMin, &SmoothMax, "%.1f", ImGuiSliderFlags_None); 84 | if (ImGui::Combo("AimPos", &MenuConfig::AimPosition, "Head\0Neck\0Spine")) 85 | { 86 | switch (MenuConfig::AimPosition) 87 | { 88 | case 0: 89 | MenuConfig::AimPositionIndex = BONEINDEX::head; 90 | break; 91 | case 1: 92 | MenuConfig::AimPositionIndex = BONEINDEX::neck_0; 93 | break; 94 | case 2: 95 | MenuConfig::AimPositionIndex = BONEINDEX::spine_1; 96 | break; 97 | default: 98 | break; 99 | } 100 | } 101 | int BulletMin = 1, BulletMax = 6; 102 | float RecoilMin = 0.f, RecoilMax = 2.f; 103 | Gui.SliderScalarEx1("Start Bullet", ImGuiDataType_U32, &AimControl::RCSBullet, &BulletMin, &BulletMax, "%d", ImGuiSliderFlags_None); 104 | Gui.SliderScalarEx1("RCS Yaw", ImGuiDataType_Float, &AimControl::RCSScale.x, &RecoilMin, &RecoilMax, "%.1f", ImGuiSliderFlags_None); 105 | Gui.SliderScalarEx1("RCS Pitch", ImGuiDataType_Float, &AimControl::RCSScale.y, &RecoilMin, &RecoilMax, "%.1f", ImGuiSliderFlags_None); 106 | Gui.MyCheckBox("VisibleCheck", &MenuConfig::VisibleCheck); 107 | 108 | ImGui::EndTabItem(); 109 | } 110 | 111 | // Radar menu 112 | if (ImGui::BeginTabItem("Radar ")) 113 | { 114 | Gui.MyCheckBox("Radar", &MenuConfig::ShowRadar); 115 | ImGui::Combo("RadarType", &MenuConfig::RadarType, "Circle\0Arrow\0CircleWithArrow"); 116 | 117 | Gui.MyCheckBox("CrossLine", &MenuConfig::ShowRadarCrossLine); 118 | ImGui::SameLine(); 119 | ImGui::ColorEdit4("##CrossLineColor", reinterpret_cast(&MenuConfig::RadarCrossLineColor), ImGuiColorEditFlags_NoInputs); 120 | 121 | float ProportionMin = 500.f, ProportionMax = 3300.f; 122 | float RadarRangeMin = 100.f, RadarRangeMax = 300.f; 123 | float RadarPointSizeProportionMin = 0.8f, RadarPointSizeProportionMax = 2.f; 124 | Gui.SliderScalarEx1("PointSize", ImGuiDataType_Float, &MenuConfig::RadarPointSizeProportion, &RadarPointSizeProportionMin, &RadarPointSizeProportionMax, "%.1f", ImGuiSliderFlags_None); 125 | Gui.SliderScalarEx1("Proportion", ImGuiDataType_Float, &MenuConfig::Proportion, &ProportionMin, &ProportionMax, "%.1f", ImGuiSliderFlags_None); 126 | Gui.SliderScalarEx1("RadarRange", ImGuiDataType_Float, &MenuConfig::RadarRange, &RadarRangeMin, &RadarRangeMax, "%.1f", ImGuiSliderFlags_None); 127 | 128 | ImGui::EndTabItem(); 129 | } 130 | 131 | // TriggerBot 132 | if (ImGui::BeginTabItem("TriggerBot ")) 133 | { 134 | Gui.MyCheckBox("TriggerBot", &MenuConfig::TriggerBot); 135 | 136 | if (ImGui::Combo("TriggerKey", &MenuConfig::TriggerHotKey, "MENU\0RBUTTON\0XBUTTON1\0XBUTTON2\0CAPITAL\0SHIFT\0CONTROL")) 137 | { 138 | TriggerBot::SetHotKey(MenuConfig::TriggerHotKey); 139 | } 140 | if (ImGui::Combo("TriggerMode", &MenuConfig::TriggerMode, "Hold\0Toggle")) 141 | { 142 | TriggerBot::SetMode(MenuConfig::TriggerMode); 143 | } 144 | 145 | DWORD TriggerDelayMin = 15, TriggerDelayMax = 170; 146 | Gui.SliderScalarEx1("Delay", ImGuiDataType_U32, &TriggerBot::TriggerDelay, &TriggerDelayMin, &TriggerDelayMax, "%d", ImGuiSliderFlags_None); 147 | 148 | ImGui::EndTabItem(); 149 | } 150 | 151 | if (ImGui::BeginTabItem("Misc ")) 152 | { 153 | // moved to misc 154 | Gui.MyCheckBox("AntiFlashbang", &MenuConfig::AntiFlashbang); 155 | // TeamCheck 156 | Gui.MyCheckBox("TeamCheck", &MenuConfig::TeamCheck); 157 | 158 | ImGui::SameLine(); 159 | // OBS Bypass 160 | Gui.MyCheckBox("OBSBypass", &MenuConfig::OBSBypass); 161 | 162 | //Bunnyhopping 163 | Gui.MyCheckBox("Bunnyhop ", &MenuConfig::BunnyHop); 164 | ImGui::SameLine(); 165 | Gui.MyCheckBox("ShowWhenSpec", &MenuConfig::ShowWhenSpec); 166 | 167 | ImGui::EndTabItem(); 168 | 169 | } 170 | 171 | // Render config saver 172 | ConfigMenu::RenderConfigMenu(); 173 | 174 | ImGui::Separator(); 175 | 176 | ImGui::Text("[HOME] HideMenu"); 177 | 178 | ImGui::EndTabBar(); 179 | }ImGui::End(); 180 | } 181 | 182 | void Cheats::RadarSetting(Base_Radar& Radar) 183 | { 184 | // Radar window 185 | ImGui::SetNextWindowBgAlpha(0.1f); 186 | ImGui::Begin("Radar", 0, ImGuiWindowFlags_NoResize); 187 | ImGui::SetWindowSize({ MenuConfig::RadarRange * 2,MenuConfig::RadarRange * 2 }); 188 | 189 | // Radar.SetPos({ Gui.Window.Size.x / 2,Gui.Window.Size.y / 2 }); 190 | Radar.SetDrawList(ImGui::GetWindowDrawList()); 191 | Radar.SetPos({ ImGui::GetWindowPos().x + MenuConfig::RadarRange, ImGui::GetWindowPos().y + MenuConfig::RadarRange }); 192 | Radar.SetProportion(MenuConfig::Proportion); 193 | Radar.SetRange(MenuConfig::RadarRange); 194 | Radar.SetSize(MenuConfig::RadarRange * 2); 195 | Radar.SetCrossColor(MenuConfig::RadarCrossLineColor); 196 | 197 | Radar.ArcArrowSize *= MenuConfig::RadarPointSizeProportion; 198 | Radar.ArrowSize *= MenuConfig::RadarPointSizeProportion; 199 | Radar.CircleSize *= MenuConfig::RadarPointSizeProportion; 200 | 201 | Radar.ShowCrossLine = MenuConfig::ShowRadarCrossLine; 202 | Radar.Opened = true; 203 | } 204 | 205 | void Cheats::Run() 206 | { 207 | // Show menu 208 | static std::chrono::time_point LastTimePoint = std::chrono::steady_clock::now(); 209 | auto CurTimePoint = std::chrono::steady_clock::now(); 210 | 211 | if (GetAsyncKeyState(VK_HOME) 212 | && CurTimePoint - LastTimePoint >= std::chrono::milliseconds(150)) 213 | { 214 | // Check key state per 150ms once to avoid loop. 215 | MenuConfig::ShowMenu = !MenuConfig::ShowMenu; 216 | LastTimePoint = CurTimePoint; 217 | } 218 | 219 | if (MenuConfig::ShowMenu) 220 | Menu(); 221 | 222 | // Update matrix 223 | if (!ProcessMgr.ReadMemory(gGame.GetMatrixAddress(), gGame.View.Matrix, 64)) 224 | return; 225 | 226 | // Update EntityList Entry 227 | gGame.UpdateEntityListEntry(); 228 | 229 | DWORD64 LocalControllerAddress = 0; 230 | DWORD64 LocalPawnAddress = 0; 231 | 232 | if (!ProcessMgr.ReadMemory(gGame.GetLocalControllerAddress(), LocalControllerAddress)) 233 | return; 234 | if (!ProcessMgr.ReadMemory(gGame.GetLocalPawnAddress(), LocalPawnAddress)) 235 | return; 236 | 237 | // LocalEntity 238 | CEntity LocalEntity; 239 | static int LocalPlayerControllerIndex = 1; 240 | if (!LocalEntity.UpdateController(LocalControllerAddress)) 241 | return; 242 | if (!LocalEntity.UpdatePawn(LocalPawnAddress) && !MenuConfig::ShowWhenSpec) 243 | return; 244 | 245 | // HealthBar Map 246 | static std::map HealthBarMap; 247 | 248 | // AimBot data 249 | float DistanceToSight = 0; 250 | float MaxAimDistance = 100000; 251 | Vec3 HeadPos{ 0,0,0 }; 252 | Vec3 AimPos{ 0,0,0 }; 253 | 254 | // Radar Data 255 | Base_Radar Radar; 256 | if (MenuConfig::ShowRadar) 257 | RadarSetting(Radar); 258 | 259 | for (int i = 0; i < 64; i++) 260 | { 261 | CEntity Entity; 262 | DWORD64 EntityAddress = 0; 263 | if (!ProcessMgr.ReadMemory(gGame.GetEntityListEntry() + (i + 1) * 0x78, EntityAddress)) 264 | continue; 265 | 266 | if (EntityAddress == LocalEntity.Controller.Address) 267 | { 268 | LocalPlayerControllerIndex = i; 269 | continue; 270 | } 271 | 272 | if (!Entity.UpdateController(EntityAddress)) 273 | continue; 274 | 275 | if (!Entity.UpdatePawn(Entity.Pawn.Address)) 276 | continue; 277 | 278 | if (MenuConfig::TeamCheck && Entity.Controller.TeamID == LocalEntity.Controller.TeamID) 279 | continue; 280 | 281 | if (!Entity.IsAlive()) 282 | continue; 283 | 284 | // Add entity to radar 285 | if (MenuConfig::ShowRadar) 286 | Radar.AddPoint(LocalEntity.Pawn.Pos, LocalEntity.Pawn.ViewAngle.y, Entity.Pawn.Pos, ImColor(237, 85, 106, 200), MenuConfig::RadarType, Entity.Pawn.ViewAngle.y); 287 | 288 | if (!Entity.IsInScreen()) 289 | continue; 290 | 291 | // Bone Debug 292 | /* for (int BoneIndex = 0; BoneIndex < Entity.BoneData.BonePosList.size(); BoneIndex++) 293 | { 294 | Vec2 ScreenPos{}; 295 | if (gGame.View.WorldToScreen(Entity.BoneData.BonePosList[BoneIndex].Pos, ScreenPos)) 296 | { 297 | Gui.Text(std::to_string(BoneIndex), ScreenPos, ImColor(255, 255, 255, 255)); 298 | } 299 | }*/ 300 | 301 | DistanceToSight = Entity.GetBone().BonePosList[BONEINDEX::head].ScreenPos.DistanceTo({ Gui.Window.Size.x / 2,Gui.Window.Size.y / 2 }); 302 | 303 | 304 | if (DistanceToSight < MaxAimDistance) 305 | { 306 | MaxAimDistance = DistanceToSight; 307 | // From: https://github.com/redbg/CS2-Internal/blob/fc8e64430176a62f8800b7467884806708a865bb/src/include/Cheats.hpp#L129 308 | if (!MenuConfig::VisibleCheck || 309 | Entity.Pawn.bSpottedByMask & (DWORD64(1) << (LocalPlayerControllerIndex)) || 310 | LocalEntity.Pawn.bSpottedByMask & (DWORD64(1) << (i))) 311 | { 312 | AimPos = Entity.GetBone().BonePosList[MenuConfig::AimPositionIndex].Pos; 313 | if (MenuConfig::AimPositionIndex == BONEINDEX::head) 314 | AimPos.z -= 1.f; 315 | } 316 | } 317 | 318 | // Draw Bone 319 | if (MenuConfig::ShowBoneESP) 320 | Render::DrawBone(Entity, MenuConfig::BoneColor, 1.3); 321 | 322 | // Draw eyeRay 323 | if (MenuConfig::ShowEyeRay) 324 | Render::ShowLosLine(Entity, 50, MenuConfig::EyeRayColor, 1.3); 325 | 326 | // Box 327 | ImVec4 Rect; 328 | switch (MenuConfig::BoxType) 329 | { 330 | case 0: 331 | Rect = Render::Get2DBox(Entity); 332 | break; 333 | case 1: 334 | Rect = Render::Get2DBoneRect(Entity); 335 | break; 336 | default: 337 | break; 338 | } 339 | 340 | // Line to enemy 341 | if (MenuConfig::ShowLineToEnemy) 342 | Render::LineToEnemy(Rect, MenuConfig::LineToEnemyColor, 1.2); 343 | 344 | // Draw Box 345 | if (MenuConfig::ShowBoxESP) 346 | Gui.Rectangle({ Rect.x,Rect.y }, { Rect.z,Rect.w }, MenuConfig::BoxColor, 1.3); 347 | 348 | // Draw HealthBar 349 | if (MenuConfig::ShowHealthBar) 350 | { 351 | ImVec2 HealthBarPos, HealthBarSize; 352 | if (MenuConfig::HealthBarType == 0) 353 | { 354 | // Vertical 355 | HealthBarPos = { Rect.x - 7.f,Rect.y }; 356 | HealthBarSize = { 7 ,Rect.w }; 357 | } 358 | else 359 | { 360 | // Horizontal 361 | HealthBarPos = { Rect.x + Rect.z / 2 - 70 / 2,Rect.y - 13 }; 362 | HealthBarSize = { 70,8 }; 363 | } 364 | Render::DrawHealthBar(EntityAddress, 100, Entity.Pawn.Health, HealthBarPos, HealthBarSize, MenuConfig::HealthBarType); 365 | } 366 | 367 | // Draw weaponName 368 | if (MenuConfig::ShowWeaponESP) 369 | Gui.StrokeText(Entity.Pawn.WeaponName, { Rect.x,Rect.y + Rect.w }, ImColor(255, 255, 255, 255), 14); 370 | 371 | if (MenuConfig::ShowDistance) 372 | Render::DrawDistance(LocalEntity, Entity, Rect); 373 | 374 | if (MenuConfig::ShowPlayerName) 375 | { 376 | if (MenuConfig::HealthBarType == 0) 377 | Gui.StrokeText(Entity.Controller.PlayerName, { Rect.x + Rect.z / 2,Rect.y - 14 }, ImColor(255, 255, 255, 255), 14, true); 378 | else 379 | Gui.StrokeText(Entity.Controller.PlayerName, { Rect.x + Rect.z / 2,Rect.y - 13 - 14 }, ImColor(255, 255, 255, 255), 14, true); 380 | } 381 | 382 | } 383 | 384 | // Fov line 385 | if (MenuConfig::ShowFovLine) 386 | Render::DrawFov(LocalEntity, MenuConfig::FovLineSize, MenuConfig::FovLineColor, 1); 387 | 388 | // Radar render 389 | if (MenuConfig::ShowRadar) 390 | { 391 | Radar.Render(); 392 | //End for radar window 393 | ImGui::End(); 394 | } 395 | 396 | // TriggerBot 397 | if (MenuConfig::TriggerMode == 1 && MenuConfig::TriggerBot && GetAsyncKeyState(TriggerBot::HotKey) && MenuConfig::Pressed&& CurTimePoint - LastTimePoint >= std::chrono::milliseconds(150)) 398 | { 399 | MenuConfig::Pressed = false; 400 | LastTimePoint = CurTimePoint; 401 | } 402 | else if (MenuConfig::TriggerMode == 1 && MenuConfig::TriggerBot && GetAsyncKeyState(TriggerBot::HotKey)&& !MenuConfig::Pressed&& CurTimePoint - LastTimePoint >= std::chrono::milliseconds(150)) 403 | { 404 | MenuConfig::Pressed = true; 405 | LastTimePoint = CurTimePoint; 406 | } 407 | 408 | if (MenuConfig::TriggerMode == 0 && MenuConfig::TriggerBot && GetAsyncKeyState(TriggerBot::HotKey)) 409 | { 410 | MenuConfig::Shoot = true; 411 | TriggerBot::Run(LocalEntity); 412 | MenuConfig::Shoot = false; 413 | } 414 | else if (MenuConfig::TriggerMode == 1 && MenuConfig::TriggerBot && MenuConfig::Pressed) 415 | { 416 | MenuConfig::Shoot = true; 417 | TriggerBot::Run(LocalEntity); 418 | MenuConfig::Shoot = false; 419 | } 420 | 421 | 422 | 423 | // HeadShoot Line 424 | if(MenuConfig::ShowHeadShootLine) 425 | Render::HeadShootLine(LocalEntity, MenuConfig::HeadShootLineColor); 426 | 427 | // CrossHair 428 | if (MenuConfig::ShowCrossHair) 429 | Render::DrawCrossHair(); 430 | 431 | // Fov circle 432 | if(MenuConfig::ShowAimFovRange) 433 | Render::DrawFovCircle(LocalEntity); 434 | 435 | if (MenuConfig::BunnyHop) 436 | Bunnyhop::Run(LocalEntity); 437 | 438 | if (MenuConfig::AntiFlashbang) 439 | AntiFlashbang::Run(LocalEntity); 440 | 441 | if (MenuConfig::AimBot && GetAsyncKeyState(AimControl::HotKey)) 442 | { 443 | if (AimPos != Vec3(0, 0, 0)) 444 | { 445 | AimControl::AimBot(LocalEntity, LocalEntity.Pawn.CameraPos, AimPos); 446 | } 447 | } 448 | } 449 | -------------------------------------------------------------------------------- /CS2_External/Cheats.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Game.h" 3 | #include "Entity.h" 4 | #include "AimBot.hpp" 5 | #include "Radar/Radar.h" 6 | #include "TriggerBot.h" 7 | #include "Bunnyhop.hpp" 8 | #include "AntiFlashbang.hpp" 9 | 10 | namespace Cheats 11 | { 12 | void Menu(); 13 | void RadarSetting(Base_Radar& Radar); 14 | void Run(); 15 | } -------------------------------------------------------------------------------- /CS2_External/Entity.cpp: -------------------------------------------------------------------------------- 1 | #include "Entity.h" 2 | 3 | bool CEntity::UpdateController(const DWORD64& PlayerControllerAddress) 4 | { 5 | if (PlayerControllerAddress == 0) 6 | return false; 7 | this->Controller.Address = PlayerControllerAddress; 8 | 9 | if (!this->Controller.GetHealth()) 10 | return false; 11 | if (!this->Controller.GetIsAlive()) 12 | return false; 13 | if (!this->Controller.GetTeamID()) 14 | return false; 15 | if (!this->Controller.GetPlayerName()) 16 | return false; 17 | 18 | this->Pawn.Address = this->Controller.GetPlayerPawnAddress(); 19 | 20 | return true; 21 | } 22 | 23 | bool CEntity::UpdatePawn(const DWORD64& PlayerPawnAddress) 24 | { 25 | if (PlayerPawnAddress == 0) 26 | return false; 27 | this->Pawn.Address = PlayerPawnAddress; 28 | 29 | if (!this->Pawn.GetCameraPos()) 30 | return false; 31 | if (!this->Pawn.GetPos()) 32 | return false; 33 | if (!this->Pawn.GetViewAngle()) 34 | return false; 35 | if (!this->Pawn.GetWeaponName()) 36 | return false; 37 | if (!this->Pawn.GetAimPunchAngle()) 38 | return false; 39 | if (!this->Pawn.GetShotsFired()) 40 | return false; 41 | if (!this->Pawn.GetHealth()) 42 | return false; 43 | if (!this->Pawn.GetTeamID()) 44 | return false; 45 | if (!this->Pawn.GetFov()) 46 | return false; 47 | if (!this->Pawn.GetSpotted()) 48 | return false; 49 | if (!this->Pawn.GetFFlags()) 50 | return false; 51 | if (!this->Pawn.GetAimPunchCache()) 52 | return false; 53 | if (!this->Pawn.BoneData.UpdateAllBoneData(PlayerPawnAddress)) 54 | return false; 55 | 56 | return true; 57 | } 58 | 59 | bool PlayerController::GetTeamID() 60 | { 61 | return GetDataAddressWithOffset(Address, Offset::Entity.TeamID, this->TeamID); 62 | } 63 | 64 | bool PlayerController::GetHealth() 65 | { 66 | return GetDataAddressWithOffset(Address, Offset::Entity.Health, this->Health); 67 | } 68 | 69 | bool PlayerController::GetIsAlive() 70 | { 71 | return GetDataAddressWithOffset(Address, Offset::Entity.IsAlive, this->AliveStatus); 72 | } 73 | 74 | bool PlayerController::GetPlayerName() 75 | { 76 | char Buffer[MAX_PATH]{}; 77 | 78 | if (!ProcessMgr.ReadMemory(Address + Offset::Entity.iszPlayerName, Buffer, MAX_PATH)) 79 | return false; 80 | 81 | this->PlayerName = Buffer; 82 | if (this->PlayerName.empty()) 83 | this->PlayerName = "Name_None"; 84 | 85 | return true; 86 | } 87 | 88 | bool PlayerPawn::GetViewAngle() 89 | { 90 | return GetDataAddressWithOffset(Address, Offset::Pawn.angEyeAngles, this->ViewAngle); 91 | } 92 | 93 | bool PlayerPawn::GetCameraPos() 94 | { 95 | return GetDataAddressWithOffset(Address, Offset::Pawn.vecLastClipCameraPos, this->CameraPos); 96 | } 97 | 98 | bool PlayerPawn::GetSpotted() 99 | { 100 | return GetDataAddressWithOffset(Address, Offset::Pawn.bSpottedByMask, this->bSpottedByMask); 101 | } 102 | 103 | bool PlayerPawn::GetWeaponName() 104 | { 105 | DWORD64 WeaponNameAddress = 0; 106 | char Buffer[40]{}; 107 | 108 | WeaponNameAddress = ProcessMgr.TraceAddress(this->Address + Offset::Pawn.pClippingWeapon, { 0x10,0x20 ,0x0 }); 109 | if (WeaponNameAddress == 0) 110 | return false; 111 | 112 | if (!ProcessMgr.ReadMemory(WeaponNameAddress, Buffer, 40)) 113 | return false; 114 | 115 | WeaponName = std::string(Buffer); 116 | std::size_t Index = WeaponName.find("_"); 117 | if (Index == std::string::npos || WeaponName.empty()) 118 | { 119 | WeaponName = "Weapon_None"; 120 | } 121 | else 122 | { 123 | WeaponName = WeaponName.substr(Index + 1, WeaponName.size() - Index - 1); 124 | } 125 | 126 | return true; 127 | } 128 | 129 | bool PlayerPawn::GetShotsFired() 130 | { 131 | return GetDataAddressWithOffset(Address, Offset::Pawn.iShotsFired, this->ShotsFired); 132 | } 133 | 134 | bool PlayerPawn::GetAimPunchAngle() 135 | { 136 | return GetDataAddressWithOffset(Address, Offset::Pawn.aimPunchAngle, this->AimPunchAngle); 137 | } 138 | 139 | bool PlayerPawn::GetTeamID() 140 | { 141 | return GetDataAddressWithOffset(Address, Offset::Pawn.iTeamNum, this->TeamID); 142 | } 143 | 144 | bool PlayerPawn::GetAimPunchCache() 145 | { 146 | return GetDataAddressWithOffset(Address, Offset::Pawn.aimPunchCache, this->AimPunchCache); 147 | } 148 | 149 | DWORD64 PlayerController::GetPlayerPawnAddress() 150 | { 151 | DWORD64 EntityPawnListEntry = 0; 152 | DWORD64 EntityPawnAddress = 0; 153 | 154 | if (!GetDataAddressWithOffset(Address, Offset::Entity.PlayerPawn, this->Pawn)) 155 | return 0; 156 | 157 | if (!ProcessMgr.ReadMemory(gGame.GetEntityListAddress(), EntityPawnListEntry)) 158 | return 0; 159 | 160 | if (!ProcessMgr.ReadMemory(EntityPawnListEntry + 0x10 + 8 * ((Pawn & 0x7FFF) >> 9), EntityPawnListEntry)) 161 | return 0; 162 | 163 | if (!ProcessMgr.ReadMemory(EntityPawnListEntry + 0x78 * (Pawn & 0x1FF), EntityPawnAddress)) 164 | return 0; 165 | 166 | return EntityPawnAddress; 167 | } 168 | 169 | bool PlayerPawn::GetPos() 170 | { 171 | return GetDataAddressWithOffset(Address, Offset::Pawn.Pos, this->Pos); 172 | } 173 | 174 | bool PlayerPawn::GetHealth() 175 | { 176 | return GetDataAddressWithOffset(Address, Offset::Pawn.CurrentHealth, this->Health); 177 | } 178 | 179 | bool PlayerPawn::GetFov() 180 | { 181 | DWORD64 CameraServices = 0; 182 | if (!ProcessMgr.ReadMemory(Address + Offset::Pawn.CameraServices, CameraServices)) 183 | return false; 184 | return GetDataAddressWithOffset(CameraServices, Offset::Pawn.iFovStart, this->Fov); 185 | } 186 | 187 | bool PlayerPawn::GetFFlags() 188 | { 189 | return GetDataAddressWithOffset(Address, Offset::Pawn.fFlags, this->fFlags); 190 | } 191 | 192 | bool CEntity::IsAlive() 193 | { 194 | return this->Controller.AliveStatus == 1 && this->Pawn.Health > 0; 195 | } 196 | 197 | bool CEntity::IsInScreen() 198 | { 199 | return gGame.View.WorldToScreen(this->Pawn.Pos, this->Pawn.ScreenPos); 200 | } 201 | 202 | CBone CEntity::GetBone() const 203 | { 204 | if (this->Pawn.Address == 0) 205 | return CBone{}; 206 | return this->Pawn.BoneData; 207 | } 208 | -------------------------------------------------------------------------------- /CS2_External/Entity.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/Entity.h -------------------------------------------------------------------------------- /CS2_External/Game.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | 3 | bool CGame::InitAddress() 4 | { 5 | this->Address.ClientDLL = reinterpret_cast(ProcessMgr.GetProcessModuleHandle("client.dll")); 6 | 7 | this->Address.EntityList = GetClientDLLAddress() + Offset::EntityList; 8 | this->Address.Matrix = GetClientDLLAddress() + Offset::Matrix; 9 | this->Address.ViewAngle = GetClientDLLAddress() + Offset::ViewAngle; 10 | this->Address.LocalController = GetClientDLLAddress() + Offset::LocalPlayerController; 11 | this->Address.LocalPawn = GetClientDLLAddress() + Offset::LocalPlayerPawn; 12 | this->Address.ForceJump = GetClientDLLAddress() + Offset::ForceJump; 13 | this->Address.GlobalVars = GetClientDLLAddress() + Offset::GlobalVars; 14 | 15 | return this->Address.ClientDLL != 0; 16 | } 17 | 18 | DWORD64 CGame::GetClientDLLAddress() 19 | { 20 | return this->Address.ClientDLL; 21 | } 22 | 23 | DWORD64 CGame::GetEntityListAddress() 24 | { 25 | return this->Address.EntityList; 26 | } 27 | 28 | DWORD64 CGame::GetMatrixAddress() 29 | { 30 | return this->Address.Matrix; 31 | } 32 | 33 | DWORD64 CGame::GetViewAngleAddress() 34 | { 35 | return this->Address.ViewAngle; 36 | } 37 | 38 | DWORD64 CGame::GetEntityListEntry() 39 | { 40 | return this->Address.EntityListEntry; 41 | } 42 | 43 | DWORD64 CGame::GetLocalControllerAddress() 44 | { 45 | return this->Address.LocalController; 46 | } 47 | 48 | DWORD64 CGame::GetLocalPawnAddress() 49 | { 50 | return this->Address.LocalPawn; 51 | } 52 | 53 | DWORD64 CGame::GetGlobalVarsAddress() 54 | { 55 | return this->Address.GlobalVars; 56 | } 57 | 58 | bool CGame::UpdateEntityListEntry() 59 | { 60 | DWORD64 EntityListEntry = 0; 61 | if (!ProcessMgr.ReadMemory(gGame.GetEntityListAddress(), EntityListEntry)) 62 | return false; 63 | if (!ProcessMgr.ReadMemory(EntityListEntry + 0x10, EntityListEntry)) 64 | return false; 65 | 66 | this->Address.EntityListEntry = EntityListEntry; 67 | 68 | return this->Address.EntityListEntry != 0; 69 | } 70 | 71 | bool CGame::SetViewAngle(float Yaw, float Pitch) 72 | { 73 | Vec2 Angle{ Pitch,Yaw }; 74 | 75 | if (!ProcessMgr.WriteMemory(this->Address.ViewAngle, Angle)) 76 | return false; 77 | 78 | return true; 79 | } 80 | 81 | bool CGame::SetForceJump(int value) 82 | { 83 | if (!ProcessMgr.WriteMemory(this->Address.ForceJump, value)) 84 | return false; 85 | 86 | return true; 87 | } -------------------------------------------------------------------------------- /CS2_External/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Utils/ProcessManager.hpp" 4 | #include "Offsets.h" 5 | #include "View.hpp" 6 | 7 | class CGame 8 | { 9 | private: 10 | struct 11 | { 12 | DWORD64 ClientDLL; 13 | DWORD64 EntityList; 14 | DWORD64 Matrix; 15 | DWORD64 ViewAngle; 16 | DWORD64 EntityListEntry; 17 | DWORD64 LocalController; 18 | DWORD64 LocalPawn; 19 | DWORD64 ForceJump; 20 | DWORD64 GlobalVars; 21 | }Address; 22 | 23 | public: 24 | CView View; 25 | 26 | public: 27 | 28 | bool InitAddress(); 29 | 30 | DWORD64 GetClientDLLAddress(); 31 | 32 | DWORD64 GetEntityListAddress(); 33 | 34 | DWORD64 GetMatrixAddress(); 35 | 36 | DWORD64 GetViewAngleAddress(); 37 | 38 | DWORD64 GetEntityListEntry(); 39 | 40 | DWORD64 GetLocalControllerAddress(); 41 | 42 | DWORD64 GetLocalPawnAddress(); 43 | 44 | DWORD64 GetGlobalVarsAddress(); 45 | 46 | bool UpdateEntityListEntry(); 47 | 48 | bool SetViewAngle(float Yaw, float Pitch); 49 | 50 | bool SetForceJump(int Value); 51 | }; 52 | 53 | inline CGame gGame; -------------------------------------------------------------------------------- /CS2_External/GlobalVars.cpp: -------------------------------------------------------------------------------- 1 | #include "globalvars.h" 2 | 3 | bool globalvars::UpdateGlobalvars() 4 | { 5 | DWORD64 m_DglobalVars = 0; 6 | if (!ProcessMgr.ReadMemory(gGame.GetGlobalVarsAddress(), m_DglobalVars)) 7 | return false; 8 | 9 | this->address = m_DglobalVars; 10 | 11 | if (!this->GetRealTime()) 12 | return false; 13 | if (!this->GetFrameCount()) 14 | return false; 15 | if (!this->GetMaxClients()) 16 | return false; 17 | if (!this->GetTickCount()) 18 | return false; 19 | if (!this->GetIntervalPerTick()) 20 | return false; 21 | if (!this->GetIntervalPerTick2()) 22 | return false; 23 | if (!this->GetcurrentTime()) 24 | return false; 25 | if (!this->GetcurrentTime2()) 26 | return false; 27 | if (!this->GetCurrentNetchan()) 28 | return false; 29 | if (!this->GetCurrentMap()) 30 | return false; 31 | if (!this->GetCurrentMapName()) 32 | return false; 33 | 34 | return true; 35 | } 36 | 37 | bool globalvars::GetRealTime() 38 | { 39 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.RealTime, this->g_fRealTime); 40 | } 41 | 42 | bool globalvars::GetFrameCount() 43 | { 44 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.FrameCount, this->g_iFrameCount); 45 | } 46 | 47 | bool globalvars::GetMaxClients() 48 | { 49 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.MaxClients, this->g_iMaxClients); 50 | } 51 | 52 | bool globalvars::GetTickCount() 53 | { 54 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.TickCount, this->g_iTickCount); 55 | } 56 | 57 | bool globalvars::GetIntervalPerTick() 58 | { 59 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.IntervalPerTick, this->g_fIntervalPerTick); 60 | } 61 | 62 | bool globalvars::GetIntervalPerTick2() 63 | { 64 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.IntervalPerTick2, this->g_fIntervalPerTick2); 65 | } 66 | 67 | bool globalvars::GetcurrentTime() 68 | { 69 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.CurrentTime, this->g_fCurrentTime); 70 | } 71 | 72 | bool globalvars::GetcurrentTime2() 73 | { 74 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.CurrentTime2, this->g_fCurrentTime2); 75 | } 76 | 77 | bool globalvars::GetCurrentNetchan() 78 | { 79 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.CurrentNetchan, this->g_vCurrentNetchan); 80 | } 81 | 82 | bool globalvars::GetCurrentMap() 83 | { 84 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.CurrentMap, this->g_cCurrentMap); 85 | } 86 | 87 | bool globalvars::GetCurrentMapName() 88 | { 89 | return GetDataAddressWithOffset(this->address, Offset::GlobalVar.CurrentMapName, this->g_cCurrentMapName); 90 | } -------------------------------------------------------------------------------- /CS2_External/GlobalVars.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Game.h" 3 | #include "Globals.hpp" 4 | 5 | class globalvars 6 | { 7 | public: 8 | DWORD64 address = 0; 9 | public: 10 | float g_fRealTime; 11 | int g_iFrameCount; 12 | int g_iMaxClients; 13 | float g_fIntervalPerTick; 14 | float g_fCurrentTime; 15 | float g_fCurrentTime2; 16 | int g_iTickCount; 17 | float g_fIntervalPerTick2; 18 | void* g_vCurrentNetchan; // ? 19 | char* g_cCurrentMap; // ? https://www.unknowncheats.me/forum/counter-strike-2-a/603800-check-empty-mapname-globalvars.html 20 | char* g_cCurrentMapName; // ? https://www.unknowncheats.me/forum/counter-strike-2-a/603800-check-empty-mapname-globalvars.html 21 | public: 22 | bool UpdateGlobalvars(); 23 | bool GetRealTime(); 24 | bool GetFrameCount(); 25 | bool GetMaxClients(); 26 | bool GetIntervalPerTick(); 27 | bool GetcurrentTime(); 28 | bool GetcurrentTime2(); 29 | bool GetTickCount(); 30 | bool GetIntervalPerTick2(); 31 | bool GetCurrentNetchan(); 32 | bool GetCurrentMap(); 33 | bool GetCurrentMapName(); 34 | private: 35 | }; -------------------------------------------------------------------------------- /CS2_External/Globals.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Utils/ProcessManager.hpp" 4 | 5 | template 6 | inline bool GetDataAddressWithOffset(const DWORD64& Address, DWORD Offset, T& Data) 7 | { 8 | if (Address == 0) 9 | return false; 10 | 11 | if (!ProcessMgr.ReadMemory(Address + Offset, Data)) 12 | return false; 13 | 14 | return true; 15 | } -------------------------------------------------------------------------------- /CS2_External/MenuConfig.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/MenuConfig.hpp -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/OS-ImGui.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/OS-ImGui/OS-ImGui.cpp -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/OS-ImGui.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/OS-ImGui/OS-ImGui.h -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/OS-ImGui_Base.cpp: -------------------------------------------------------------------------------- 1 | #include "OS-ImGui_Base.h" 2 | 3 | /**************************************************** 4 | * Copyright (C) : Liv 5 | * @file : OS-ImGui_Base.cpp 6 | * @author : Liv 7 | * @email : 1319923129@qq.com 8 | * @version : 1.0 9 | * @date : 2023/6/18 11:21 10 | ****************************************************/ 11 | 12 | namespace OSImGui 13 | { 14 | bool OSImGui_Base::InitImGui(ID3D11Device* device, ID3D11DeviceContext* device_context) 15 | { 16 | ImGui::CreateContext(); 17 | ImGuiIO& io = ImGui::GetIO(); (void)io; 18 | 19 | ImGui::StyleColorsDark(); 20 | io.LogFilename = nullptr; 21 | 22 | if (!ImGui_ImplWin32_Init(Window.hWnd)) 23 | throw OSException("ImGui_ImplWin32_Init() call failed."); 24 | if (!ImGui_ImplDX11_Init(device, device_context)) 25 | throw OSException("ImGui_ImplDX11_Init() call failed."); 26 | 27 | return true; 28 | } 29 | 30 | void OSImGui_Base::CleanImGui() 31 | { 32 | ImGui_ImplDX11_Shutdown(); 33 | ImGui_ImplWin32_Shutdown(); 34 | ImGui::DestroyContext(); 35 | 36 | g_Device.CleanupDeviceD3D(); 37 | DestroyWindow(Window.hWnd); 38 | UnregisterClassA(Window.ClassName.c_str(), Window.hInstance); 39 | } 40 | 41 | std::wstring OSImGui_Base::StringToWstring(std::string& str) 42 | { 43 | std::wstring_convert> converter; 44 | return converter.from_bytes(str); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/OS-ImGui_Base.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/OS-ImGui/OS-ImGui_Base.h -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/OS-ImGui_Exception.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING 4 | 5 | #if !_HAS_CXX17 6 | #error "The Os-ImGui are available only with C++17 or later." 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | /**************************************************** 13 | * Copyright (C) : Liv 14 | * @file : OS-ImGui_Exception.hpp 15 | * @author : Liv 16 | * @email : 1319923129@qq.com 17 | * @version : 1.0 18 | * @date : 2023/4/2 12:53 19 | ****************************************************/ 20 | 21 | namespace OSImGui 22 | { 23 | class OSException : public std::exception 24 | { 25 | public: 26 | OSException():Error_("[OS-Exception] Unkown Error") {} 27 | OSException(std::string Error):Error_("[OS-Exception] " + Error){} 28 | char const* what() const throw() 29 | { 30 | return Error_.c_str(); 31 | } 32 | private: 33 | std::string Error_ = ""; 34 | }; 35 | } -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/OS-ImGui_External.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/OS-ImGui/OS-ImGui_External.cpp -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/OS-ImGui_External.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/OS-ImGui/OS-ImGui_External.h -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/OS-ImGui_Struct.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imgui/imgui.h" 3 | #include "imgui/imgui_impl_win32.h" 4 | #include "imgui/imgui_impl_dx11.h" 5 | #include "imgui/imgui_internal.h" 6 | #pragma comment(lib,"d3d11.lib") 7 | #pragma comment(lib,"d3dcompiler.lib") 8 | #pragma comment(lib,"dxgi.lib") 9 | #include 10 | 11 | /**************************************************** 12 | * Copyright (C) : Liv 13 | * @file : OS-ImGui_Struct.h 14 | * @author : Liv 15 | * @email : 1319923129@qq.com 16 | * @version : 1.0 17 | * @date : 2023/9/17 11:30 18 | ****************************************************/ 19 | 20 | extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 21 | 22 | class Vec2 23 | { 24 | public: 25 | float x, y; 26 | public: 27 | Vec2() :x(0.f), y(0.f) {} 28 | Vec2(float x_, float y_) :x(x_), y(y_) {} 29 | Vec2(ImVec2 ImVec2_) :x(ImVec2_.x), y(ImVec2_.y) {} 30 | Vec2 operator=(ImVec2 ImVec2_) 31 | { 32 | x = ImVec2_.x; 33 | y = ImVec2_.y; 34 | return *this; 35 | } 36 | Vec2 operator+(Vec2 Vec2_) 37 | { 38 | return { x + Vec2_.x,y + Vec2_.y }; 39 | } 40 | Vec2 operator-(Vec2 Vec2_) 41 | { 42 | return { x - Vec2_.x,y - Vec2_.y }; 43 | } 44 | Vec2 operator*(Vec2 Vec2_) 45 | { 46 | return { x * Vec2_.x,y * Vec2_.y }; 47 | } 48 | Vec2 operator/(Vec2 Vec2_) 49 | { 50 | return { x / Vec2_.x,y / Vec2_.y }; 51 | } 52 | Vec2 operator*(float n) 53 | { 54 | return { x / n,y / n }; 55 | } 56 | Vec2 operator/(float n) 57 | { 58 | return { x / n,y / n }; 59 | } 60 | bool operator==(Vec2 Vec2_) 61 | { 62 | return x == Vec2_.x && y == Vec2_.y; 63 | } 64 | bool operator!=(Vec2 Vec2_) 65 | { 66 | return x != Vec2_.x || y != Vec2_.y; 67 | } 68 | ImVec2 ToImVec2() 69 | { 70 | return ImVec2(x, y); 71 | } 72 | float Length() 73 | { 74 | return sqrtf(powf(x, 2) + powf(y, 2)); 75 | } 76 | float DistanceTo(const Vec2& Pos) 77 | { 78 | return sqrtf(powf(Pos.x - x, 2) + powf(Pos.y - y, 2)); 79 | } 80 | }; 81 | 82 | class Vec3 83 | { 84 | public: 85 | float x, y, z; 86 | public: 87 | Vec3() :x(0.f), y(0.f), z(0.f) {} 88 | Vec3(float x_, float y_, float z_) :x(x_), y(y_), z(z_) {} 89 | Vec3 operator+(Vec3 Vec3_) 90 | { 91 | return { x + Vec3_.x,y + Vec3_.y,z + Vec3_.z }; 92 | } 93 | Vec3 operator-(Vec3 Vec3_) 94 | { 95 | return { x - Vec3_.x,y - Vec3_.y,z - Vec3_.z }; 96 | } 97 | Vec3 operator*(Vec3 Vec3_) 98 | { 99 | return { x * Vec3_.x,y * Vec3_.y,z * Vec3_.z }; 100 | } 101 | Vec3 operator/(Vec3 Vec3_) 102 | { 103 | return { x / Vec3_.x,y / Vec3_.y,z / Vec3_.z }; 104 | } 105 | Vec3 operator*(float n) 106 | { 107 | return { x * n,y * n,z * n }; 108 | } 109 | Vec3 operator/(float n) 110 | { 111 | return { x / n,y / n,z / n }; 112 | } 113 | bool operator==(Vec3 Vec3_) 114 | { 115 | return x == Vec3_.x && y == Vec3_.y && z == Vec3_.z; 116 | } 117 | bool operator!=(Vec3 Vec3_) 118 | { 119 | return x != Vec3_.x || y != Vec3_.y || z != Vec3_.z; 120 | } 121 | float Length() 122 | { 123 | return sqrtf(powf(x, 2) + powf(y, 2) + powf(z, 2)); 124 | } 125 | float DistanceTo(const Vec3& Pos) 126 | { 127 | return sqrtf(powf(Pos.x - x, 2) + powf(Pos.y - y, 2) + powf(Pos.z - z, 2)); 128 | } 129 | }; 130 | 131 | template 132 | class Singleton 133 | { 134 | public: 135 | static T& get() 136 | { 137 | static T instance; 138 | return instance; 139 | } 140 | }; 141 | 142 | 143 | -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 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 files 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 avoid using soon-to-be 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 will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. 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 ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88). 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 | //#define IMGUI_INCLUDE_IMGUI_USER_H 54 | 55 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 56 | //#define IMGUI_USE_BGRA_PACKED_COLOR 57 | 58 | //---- 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...) 59 | //#define IMGUI_USE_WCHAR32 60 | 61 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 62 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 63 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 64 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 65 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled 66 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 67 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 68 | 69 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 70 | // 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. 71 | //#define IMGUI_USE_STB_SPRINTF 72 | 73 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 74 | // 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). 75 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 76 | //#define IMGUI_ENABLE_FREETYPE 77 | 78 | //---- Use stb_truetype to build and rasterize the font atlas (default) 79 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 80 | //#define IMGUI_ENABLE_STB_TRUETYPE 81 | 82 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 83 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 84 | /* 85 | #define IM_VEC2_CLASS_EXTRA \ 86 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 87 | operator MyVec2() const { return MyVec2(x,y); } 88 | 89 | #define IM_VEC4_CLASS_EXTRA \ 90 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 91 | operator MyVec4() const { return MyVec4(x,y,z,w); } 92 | */ 93 | //---- ...Or use Dear ImGui's own very basic math operators. 94 | //#define IMGUI_DEFINE_MATH_OPERATORS 95 | 96 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 97 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 98 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 99 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 100 | //#define ImDrawIdx unsigned int 101 | 102 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 103 | //struct ImDrawList; 104 | //struct ImDrawCmd; 105 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 106 | //#define ImDrawCallback MyImDrawCallback 107 | 108 | //---- Debug Tools: Macro to break in Debugger 109 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 110 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 111 | //#define IM_DEBUG_BREAK __debugbreak() 112 | 113 | //---- Debug Tools: Enable slower asserts 114 | //#define IMGUI_DEBUG_PARANOID 115 | 116 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 117 | /* 118 | namespace ImGui 119 | { 120 | void MyFunction(const char* name, const MyMatrix44& v); 121 | } 122 | */ 123 | -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/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 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 11 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 12 | 13 | // CHANGELOG 14 | // (minor and older changes stripped away, please see git history for details) 15 | // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. 16 | // 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). 17 | // 2021-05-19: DirectX11: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) 18 | // 2021-02-18: DirectX11: Change blending equation to preserve alpha in output buffer. 19 | // 2019-08-01: DirectX11: Fixed code querying the Geometry Shader state (would generally error with Debug layer enabled). 20 | // 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. 21 | // 2019-05-29: DirectX11: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. 22 | // 2019-04-30: DirectX11: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. 23 | // 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile(). 24 | // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window. 25 | // 2018-08-01: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility. 26 | // 2018-07-13: DirectX11: Fixed unreleased resources in Init and Shutdown functions. 27 | // 2018-06-08: Misc: Extracted imgui_impl_dx11.cpp/.h away from the old combined DX11+Win32 example. 28 | // 2018-06-08: DirectX11: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. 29 | // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX11_RenderDrawData() in the .h file so you can call it yourself. 30 | // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. 31 | // 2016-05-07: DirectX11: Disabling depth-write. 32 | 33 | #include "imgui.h" 34 | #include "imgui_impl_dx11.h" 35 | 36 | // DirectX 37 | #include 38 | #include 39 | #include 40 | #ifdef _MSC_VER 41 | #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. 42 | #endif 43 | 44 | // DirectX11 data 45 | struct ImGui_ImplDX11_Data 46 | { 47 | ID3D11Device* pd3dDevice; 48 | ID3D11DeviceContext* pd3dDeviceContext; 49 | IDXGIFactory* pFactory; 50 | ID3D11Buffer* pVB; 51 | ID3D11Buffer* pIB; 52 | ID3D11VertexShader* pVertexShader; 53 | ID3D11InputLayout* pInputLayout; 54 | ID3D11Buffer* pVertexConstantBuffer; 55 | ID3D11PixelShader* pPixelShader; 56 | ID3D11SamplerState* pFontSampler; 57 | ID3D11ShaderResourceView* pFontTextureView; 58 | ID3D11RasterizerState* pRasterizerState; 59 | ID3D11BlendState* pBlendState; 60 | ID3D11DepthStencilState* pDepthStencilState; 61 | int VertexBufferSize; 62 | int IndexBufferSize; 63 | 64 | ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; } 65 | }; 66 | 67 | struct VERTEX_CONSTANT_BUFFER_DX11 68 | { 69 | float mvp[4][4]; 70 | }; 71 | 72 | // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts 73 | // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. 74 | static ImGui_ImplDX11_Data* ImGui_ImplDX11_GetBackendData() 75 | { 76 | return ImGui::GetCurrentContext() ? (ImGui_ImplDX11_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; 77 | } 78 | 79 | // Functions 80 | static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceContext* ctx) 81 | { 82 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 83 | 84 | // Setup viewport 85 | D3D11_VIEWPORT vp; 86 | memset(&vp, 0, sizeof(D3D11_VIEWPORT)); 87 | vp.Width = draw_data->DisplaySize.x; 88 | vp.Height = draw_data->DisplaySize.y; 89 | vp.MinDepth = 0.0f; 90 | vp.MaxDepth = 1.0f; 91 | vp.TopLeftX = vp.TopLeftY = 0; 92 | ctx->RSSetViewports(1, &vp); 93 | 94 | // Setup shader and vertex buffers 95 | unsigned int stride = sizeof(ImDrawVert); 96 | unsigned int offset = 0; 97 | ctx->IASetInputLayout(bd->pInputLayout); 98 | ctx->IASetVertexBuffers(0, 1, &bd->pVB, &stride, &offset); 99 | ctx->IASetIndexBuffer(bd->pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); 100 | ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 101 | ctx->VSSetShader(bd->pVertexShader, nullptr, 0); 102 | ctx->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer); 103 | ctx->PSSetShader(bd->pPixelShader, nullptr, 0); 104 | ctx->PSSetSamplers(0, 1, &bd->pFontSampler); 105 | ctx->GSSetShader(nullptr, nullptr, 0); 106 | ctx->HSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 107 | ctx->DSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 108 | ctx->CSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 109 | 110 | // Setup blend state 111 | const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; 112 | ctx->OMSetBlendState(bd->pBlendState, blend_factor, 0xffffffff); 113 | ctx->OMSetDepthStencilState(bd->pDepthStencilState, 0); 114 | ctx->RSSetState(bd->pRasterizerState); 115 | } 116 | 117 | // Render function 118 | void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) 119 | { 120 | // Avoid rendering when minimized 121 | if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f) 122 | return; 123 | 124 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 125 | ID3D11DeviceContext* ctx = bd->pd3dDeviceContext; 126 | 127 | // Create and grow vertex/index buffers if needed 128 | if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount) 129 | { 130 | if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } 131 | bd->VertexBufferSize = draw_data->TotalVtxCount + 5000; 132 | D3D11_BUFFER_DESC desc; 133 | memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); 134 | desc.Usage = D3D11_USAGE_DYNAMIC; 135 | desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert); 136 | desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; 137 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 138 | desc.MiscFlags = 0; 139 | if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVB) < 0) 140 | return; 141 | } 142 | if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount) 143 | { 144 | if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } 145 | bd->IndexBufferSize = draw_data->TotalIdxCount + 10000; 146 | D3D11_BUFFER_DESC desc; 147 | memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); 148 | desc.Usage = D3D11_USAGE_DYNAMIC; 149 | desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx); 150 | desc.BindFlags = D3D11_BIND_INDEX_BUFFER; 151 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 152 | if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pIB) < 0) 153 | return; 154 | } 155 | 156 | // Upload vertex/index data into a single contiguous GPU buffer 157 | D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource; 158 | if (ctx->Map(bd->pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK) 159 | return; 160 | if (ctx->Map(bd->pIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &idx_resource) != S_OK) 161 | return; 162 | ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData; 163 | ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource.pData; 164 | for (int n = 0; n < draw_data->CmdListsCount; n++) 165 | { 166 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 167 | memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); 168 | memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); 169 | vtx_dst += cmd_list->VtxBuffer.Size; 170 | idx_dst += cmd_list->IdxBuffer.Size; 171 | } 172 | ctx->Unmap(bd->pVB, 0); 173 | ctx->Unmap(bd->pIB, 0); 174 | 175 | // Setup orthographic projection matrix into our constant buffer 176 | // 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. 177 | { 178 | D3D11_MAPPED_SUBRESOURCE mapped_resource; 179 | if (ctx->Map(bd->pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) 180 | return; 181 | VERTEX_CONSTANT_BUFFER_DX11* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX11*)mapped_resource.pData; 182 | float L = draw_data->DisplayPos.x; 183 | float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; 184 | float T = draw_data->DisplayPos.y; 185 | float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y; 186 | float mvp[4][4] = 187 | { 188 | { 2.0f/(R-L), 0.0f, 0.0f, 0.0f }, 189 | { 0.0f, 2.0f/(T-B), 0.0f, 0.0f }, 190 | { 0.0f, 0.0f, 0.5f, 0.0f }, 191 | { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, 192 | }; 193 | memcpy(&constant_buffer->mvp, mvp, sizeof(mvp)); 194 | ctx->Unmap(bd->pVertexConstantBuffer, 0); 195 | } 196 | 197 | // Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!) 198 | struct BACKUP_DX11_STATE 199 | { 200 | UINT ScissorRectsCount, ViewportsCount; 201 | D3D11_RECT ScissorRects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; 202 | D3D11_VIEWPORT Viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; 203 | ID3D11RasterizerState* RS; 204 | ID3D11BlendState* BlendState; 205 | FLOAT BlendFactor[4]; 206 | UINT SampleMask; 207 | UINT StencilRef; 208 | ID3D11DepthStencilState* DepthStencilState; 209 | ID3D11ShaderResourceView* PSShaderResource; 210 | ID3D11SamplerState* PSSampler; 211 | ID3D11PixelShader* PS; 212 | ID3D11VertexShader* VS; 213 | ID3D11GeometryShader* GS; 214 | UINT PSInstancesCount, VSInstancesCount, GSInstancesCount; 215 | ID3D11ClassInstance *PSInstances[256], *VSInstances[256], *GSInstances[256]; // 256 is max according to PSSetShader documentation 216 | D3D11_PRIMITIVE_TOPOLOGY PrimitiveTopology; 217 | ID3D11Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer; 218 | UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset; 219 | DXGI_FORMAT IndexBufferFormat; 220 | ID3D11InputLayout* InputLayout; 221 | }; 222 | BACKUP_DX11_STATE old = {}; 223 | old.ScissorRectsCount = old.ViewportsCount = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; 224 | ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects); 225 | ctx->RSGetViewports(&old.ViewportsCount, old.Viewports); 226 | ctx->RSGetState(&old.RS); 227 | ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask); 228 | ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef); 229 | ctx->PSGetShaderResources(0, 1, &old.PSShaderResource); 230 | ctx->PSGetSamplers(0, 1, &old.PSSampler); 231 | old.PSInstancesCount = old.VSInstancesCount = old.GSInstancesCount = 256; 232 | ctx->PSGetShader(&old.PS, old.PSInstances, &old.PSInstancesCount); 233 | ctx->VSGetShader(&old.VS, old.VSInstances, &old.VSInstancesCount); 234 | ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer); 235 | ctx->GSGetShader(&old.GS, old.GSInstances, &old.GSInstancesCount); 236 | 237 | ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology); 238 | ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset); 239 | ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); 240 | ctx->IAGetInputLayout(&old.InputLayout); 241 | 242 | // Setup desired DX state 243 | ImGui_ImplDX11_SetupRenderState(draw_data, ctx); 244 | 245 | // Render command lists 246 | // (Because we merged all buffers into a single one, we maintain our own offset into them) 247 | int global_idx_offset = 0; 248 | int global_vtx_offset = 0; 249 | ImVec2 clip_off = draw_data->DisplayPos; 250 | for (int n = 0; n < draw_data->CmdListsCount; n++) 251 | { 252 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 253 | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) 254 | { 255 | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; 256 | if (pcmd->UserCallback != nullptr) 257 | { 258 | // User callback, registered via ImDrawList::AddCallback() 259 | // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) 260 | if (pcmd->UserCallback == ImDrawCallback_ResetRenderState) 261 | ImGui_ImplDX11_SetupRenderState(draw_data, ctx); 262 | else 263 | pcmd->UserCallback(cmd_list, pcmd); 264 | } 265 | else 266 | { 267 | // Project scissor/clipping rectangles into framebuffer space 268 | ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y); 269 | ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y); 270 | if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) 271 | continue; 272 | 273 | // Apply scissor/clipping rectangle 274 | const D3D11_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y }; 275 | ctx->RSSetScissorRects(1, &r); 276 | 277 | // Bind texture, Draw 278 | ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->GetTexID(); 279 | ctx->PSSetShaderResources(0, 1, &texture_srv); 280 | ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset); 281 | } 282 | } 283 | global_idx_offset += cmd_list->IdxBuffer.Size; 284 | global_vtx_offset += cmd_list->VtxBuffer.Size; 285 | } 286 | 287 | // Restore modified DX state 288 | ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects); 289 | ctx->RSSetViewports(old.ViewportsCount, old.Viewports); 290 | ctx->RSSetState(old.RS); if (old.RS) old.RS->Release(); 291 | ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release(); 292 | ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release(); 293 | ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release(); 294 | ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release(); 295 | ctx->PSSetShader(old.PS, old.PSInstances, old.PSInstancesCount); if (old.PS) old.PS->Release(); 296 | for (UINT i = 0; i < old.PSInstancesCount; i++) if (old.PSInstances[i]) old.PSInstances[i]->Release(); 297 | ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount); if (old.VS) old.VS->Release(); 298 | ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release(); 299 | ctx->GSSetShader(old.GS, old.GSInstances, old.GSInstancesCount); if (old.GS) old.GS->Release(); 300 | for (UINT i = 0; i < old.VSInstancesCount; i++) if (old.VSInstances[i]) old.VSInstances[i]->Release(); 301 | ctx->IASetPrimitiveTopology(old.PrimitiveTopology); 302 | ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release(); 303 | ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release(); 304 | ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); 305 | } 306 | 307 | static void ImGui_ImplDX11_CreateFontsTexture() 308 | { 309 | // Build texture atlas 310 | ImGuiIO& io = ImGui::GetIO(); 311 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 312 | unsigned char* pixels; 313 | int width, height; 314 | io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); 315 | 316 | // Upload texture to graphics system 317 | { 318 | D3D11_TEXTURE2D_DESC desc; 319 | ZeroMemory(&desc, sizeof(desc)); 320 | desc.Width = width; 321 | desc.Height = height; 322 | desc.MipLevels = 1; 323 | desc.ArraySize = 1; 324 | desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 325 | desc.SampleDesc.Count = 1; 326 | desc.Usage = D3D11_USAGE_DEFAULT; 327 | desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 328 | desc.CPUAccessFlags = 0; 329 | 330 | ID3D11Texture2D* pTexture = nullptr; 331 | D3D11_SUBRESOURCE_DATA subResource; 332 | subResource.pSysMem = pixels; 333 | subResource.SysMemPitch = desc.Width * 4; 334 | subResource.SysMemSlicePitch = 0; 335 | bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); 336 | IM_ASSERT(pTexture != nullptr); 337 | 338 | // Create texture view 339 | D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; 340 | ZeroMemory(&srvDesc, sizeof(srvDesc)); 341 | srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 342 | srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; 343 | srvDesc.Texture2D.MipLevels = desc.MipLevels; 344 | srvDesc.Texture2D.MostDetailedMip = 0; 345 | bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &bd->pFontTextureView); 346 | pTexture->Release(); 347 | } 348 | 349 | // Store our identifier 350 | io.Fonts->SetTexID((ImTextureID)bd->pFontTextureView); 351 | 352 | // Create texture sampler 353 | // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling) 354 | { 355 | D3D11_SAMPLER_DESC desc; 356 | ZeroMemory(&desc, sizeof(desc)); 357 | desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; 358 | desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; 359 | desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; 360 | desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; 361 | desc.MipLODBias = 0.f; 362 | desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; 363 | desc.MinLOD = 0.f; 364 | desc.MaxLOD = 0.f; 365 | bd->pd3dDevice->CreateSamplerState(&desc, &bd->pFontSampler); 366 | } 367 | } 368 | 369 | bool ImGui_ImplDX11_CreateDeviceObjects() 370 | { 371 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 372 | if (!bd->pd3dDevice) 373 | return false; 374 | if (bd->pFontSampler) 375 | ImGui_ImplDX11_InvalidateDeviceObjects(); 376 | 377 | // By using D3DCompile() from / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) 378 | // If you would like to use this DX11 sample code but remove this dependency you can: 379 | // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution] 380 | // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL. 381 | // See https://github.com/ocornut/imgui/pull/638 for sources and details. 382 | 383 | // Create the vertex shader 384 | { 385 | static const char* vertexShader = 386 | "cbuffer vertexBuffer : register(b0) \ 387 | {\ 388 | float4x4 ProjectionMatrix; \ 389 | };\ 390 | struct VS_INPUT\ 391 | {\ 392 | float2 pos : POSITION;\ 393 | float4 col : COLOR0;\ 394 | float2 uv : TEXCOORD0;\ 395 | };\ 396 | \ 397 | struct PS_INPUT\ 398 | {\ 399 | float4 pos : SV_POSITION;\ 400 | float4 col : COLOR0;\ 401 | float2 uv : TEXCOORD0;\ 402 | };\ 403 | \ 404 | PS_INPUT main(VS_INPUT input)\ 405 | {\ 406 | PS_INPUT output;\ 407 | output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ 408 | output.col = input.col;\ 409 | output.uv = input.uv;\ 410 | return output;\ 411 | }"; 412 | 413 | ID3DBlob* vertexShaderBlob; 414 | if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr))) 415 | return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! 416 | if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), nullptr, &bd->pVertexShader) != S_OK) 417 | { 418 | vertexShaderBlob->Release(); 419 | return false; 420 | } 421 | 422 | // Create the input layout 423 | D3D11_INPUT_ELEMENT_DESC local_layout[] = 424 | { 425 | { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 426 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 427 | { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)IM_OFFSETOF(ImDrawVert, col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 428 | }; 429 | if (bd->pd3dDevice->CreateInputLayout(local_layout, 3, vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pInputLayout) != S_OK) 430 | { 431 | vertexShaderBlob->Release(); 432 | return false; 433 | } 434 | vertexShaderBlob->Release(); 435 | 436 | // Create the constant buffer 437 | { 438 | D3D11_BUFFER_DESC desc; 439 | desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER_DX11); 440 | desc.Usage = D3D11_USAGE_DYNAMIC; 441 | desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 442 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 443 | desc.MiscFlags = 0; 444 | bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVertexConstantBuffer); 445 | } 446 | } 447 | 448 | // Create the pixel shader 449 | { 450 | static const char* pixelShader = 451 | "struct PS_INPUT\ 452 | {\ 453 | float4 pos : SV_POSITION;\ 454 | float4 col : COLOR0;\ 455 | float2 uv : TEXCOORD0;\ 456 | };\ 457 | sampler sampler0;\ 458 | Texture2D texture0;\ 459 | \ 460 | float4 main(PS_INPUT input) : SV_Target\ 461 | {\ 462 | float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \ 463 | return out_col; \ 464 | }"; 465 | 466 | ID3DBlob* pixelShaderBlob; 467 | if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr))) 468 | return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! 469 | if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), nullptr, &bd->pPixelShader) != S_OK) 470 | { 471 | pixelShaderBlob->Release(); 472 | return false; 473 | } 474 | pixelShaderBlob->Release(); 475 | } 476 | 477 | // Create the blending setup 478 | { 479 | D3D11_BLEND_DESC desc; 480 | ZeroMemory(&desc, sizeof(desc)); 481 | desc.AlphaToCoverageEnable = false; 482 | desc.RenderTarget[0].BlendEnable = true; 483 | desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; 484 | desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; 485 | desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; 486 | desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; 487 | desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; 488 | desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; 489 | desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; 490 | bd->pd3dDevice->CreateBlendState(&desc, &bd->pBlendState); 491 | } 492 | 493 | // Create the rasterizer state 494 | { 495 | D3D11_RASTERIZER_DESC desc; 496 | ZeroMemory(&desc, sizeof(desc)); 497 | desc.FillMode = D3D11_FILL_SOLID; 498 | desc.CullMode = D3D11_CULL_NONE; 499 | desc.ScissorEnable = true; 500 | desc.DepthClipEnable = true; 501 | bd->pd3dDevice->CreateRasterizerState(&desc, &bd->pRasterizerState); 502 | } 503 | 504 | // Create depth-stencil State 505 | { 506 | D3D11_DEPTH_STENCIL_DESC desc; 507 | ZeroMemory(&desc, sizeof(desc)); 508 | desc.DepthEnable = false; 509 | desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; 510 | desc.DepthFunc = D3D11_COMPARISON_ALWAYS; 511 | desc.StencilEnable = false; 512 | desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; 513 | desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; 514 | desc.BackFace = desc.FrontFace; 515 | bd->pd3dDevice->CreateDepthStencilState(&desc, &bd->pDepthStencilState); 516 | } 517 | 518 | ImGui_ImplDX11_CreateFontsTexture(); 519 | 520 | return true; 521 | } 522 | 523 | void ImGui_ImplDX11_InvalidateDeviceObjects() 524 | { 525 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 526 | if (!bd->pd3dDevice) 527 | return; 528 | 529 | if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = nullptr; } 530 | 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. 531 | if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } 532 | if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } 533 | if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; } 534 | if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = nullptr; } 535 | if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = nullptr; } 536 | if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = nullptr; } 537 | if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = nullptr; } 538 | if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = nullptr; } 539 | if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = nullptr; } 540 | } 541 | 542 | bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context) 543 | { 544 | ImGuiIO& io = ImGui::GetIO(); 545 | IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); 546 | 547 | // Setup backend capabilities flags 548 | ImGui_ImplDX11_Data* bd = IM_NEW(ImGui_ImplDX11_Data)(); 549 | io.BackendRendererUserData = (void*)bd; 550 | io.BackendRendererName = "imgui_impl_dx11"; 551 | io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. 552 | 553 | // Get factory from device 554 | IDXGIDevice* pDXGIDevice = nullptr; 555 | IDXGIAdapter* pDXGIAdapter = nullptr; 556 | IDXGIFactory* pFactory = nullptr; 557 | 558 | if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK) 559 | if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK) 560 | if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK) 561 | { 562 | bd->pd3dDevice = device; 563 | bd->pd3dDeviceContext = device_context; 564 | bd->pFactory = pFactory; 565 | } 566 | if (pDXGIDevice) pDXGIDevice->Release(); 567 | if (pDXGIAdapter) pDXGIAdapter->Release(); 568 | bd->pd3dDevice->AddRef(); 569 | bd->pd3dDeviceContext->AddRef(); 570 | 571 | return true; 572 | } 573 | 574 | void ImGui_ImplDX11_Shutdown() 575 | { 576 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 577 | IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); 578 | ImGuiIO& io = ImGui::GetIO(); 579 | 580 | ImGui_ImplDX11_InvalidateDeviceObjects(); 581 | if (bd->pFactory) { bd->pFactory->Release(); } 582 | if (bd->pd3dDevice) { bd->pd3dDevice->Release(); } 583 | if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); } 584 | io.BackendRendererName = nullptr; 585 | io.BackendRendererUserData = nullptr; 586 | io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; 587 | IM_DELETE(bd); 588 | } 589 | 590 | void ImGui_ImplDX11_NewFrame() 591 | { 592 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 593 | IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX11_Init()?"); 594 | 595 | if (!bd->pFontSampler) 596 | ImGui_ImplDX11_CreateDeviceObjects(); 597 | } 598 | -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/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 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 11 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 12 | 13 | #pragma once 14 | #include "imgui.h" // IMGUI_IMPL_API 15 | 16 | struct ID3D11Device; 17 | struct ID3D11DeviceContext; 18 | 19 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 20 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 21 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 22 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 23 | 24 | // Use if you want to reset your rendering device without losing Dear ImGui state. 25 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 26 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 27 | -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/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 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 14 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 15 | 16 | #include "imgui.h" 17 | #include "imgui_impl_win32.h" 18 | #ifndef WIN32_LEAN_AND_MEAN 19 | #define WIN32_LEAN_AND_MEAN 20 | #endif 21 | #include 22 | #include // GET_X_LPARAM(), GET_Y_LPARAM() 23 | #include 24 | #include 25 | 26 | // Configuration flags to add in your imconfig.h file: 27 | //#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. 28 | 29 | // Using XInput for gamepad (will load DLL dynamically) 30 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 31 | #include 32 | typedef DWORD (WINAPI *PFN_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES*); 33 | typedef DWORD (WINAPI *PFN_XInputGetState)(DWORD, XINPUT_STATE*); 34 | #endif 35 | 36 | // CHANGELOG 37 | // (minor and older changes stripped away, please see git history for details) 38 | // 2023-04-19: Added ImGui_ImplWin32_InitForOpenGL() to facilitate combining raw Win32/Winapi with OpenGL. (#3218) 39 | // 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen. (#2702) 40 | // 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) 41 | // 2023-02-02: Inputs: Flipping WM_MOUSEHWHEEL (horizontal mouse-wheel) value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463) 42 | // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. 43 | // 2022-09-28: Inputs: Convert WM_CHAR values with MultiByteToWideChar() when window class was registered as MBCS (not Unicode). 44 | // 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). 45 | // 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. 46 | // 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[]. 47 | // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). 48 | // 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. 49 | // 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. 50 | // 2022-01-12: Inputs: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted. 51 | // 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range. 52 | // 2021-12-16: Inputs: Fill VK_LCONTROL/VK_RCONTROL/VK_LSHIFT/VK_RSHIFT/VK_LMENU/VK_RMENU for completeness. 53 | // 2021-08-17: Calling io.AddFocusEvent() on WM_SETFOCUS/WM_KILLFOCUS messages. 54 | // 2021-08-02: Inputs: Fixed keyboard modifiers being reported when host window doesn't have focus. 55 | // 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). 56 | // 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). 57 | // 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). 58 | // 2021-03-23: Inputs: Clearing keyboard down array when losing focus (WM_KILLFOCUS). 59 | // 2021-02-18: Added ImGui_ImplWin32_EnableAlphaCompositing(). Non Visual Studio users will need to link with dwmapi.lib (MinGW/gcc: use -ldwmapi). 60 | // 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. 61 | // 2021-01-25: Inputs: Dynamically loading XInput DLL. 62 | // 2020-12-04: Misc: Fixed setting of io.DisplaySize to invalid/uninitialized data when after hwnd has been closed. 63 | // 2020-03-03: Inputs: Calling AddInputCharacterUTF16() to support surrogate pairs leading to codepoint >= 0x10000 (for more complete CJK inputs) 64 | // 2020-02-17: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helper functions. 65 | // 2020-01-14: Inputs: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD/IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT. 66 | // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. 67 | // 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter(). 68 | // 2019-01-17: Misc: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created in a different thread or parent. 69 | // 2019-01-17: Inputs: Added support for mouse buttons 4 and 5 via WM_XBUTTON* messages. 70 | // 2019-01-15: Inputs: Added support for XInput gamepads (if ImGuiConfigFlags_NavEnableGamepad is set by user application). 71 | // 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window. 72 | // 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor. 73 | // 2018-06-10: Inputs: Fixed handling of mouse wheel messages to support fine position messages (typically sent by track-pads). 74 | // 2018-06-08: Misc: Extracted imgui_impl_win32.cpp/.h away from the old combined DX9/DX10/DX11/DX12 examples. 75 | // 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors and ImGuiBackendFlags_HasSetMousePos flags + honor ImGuiConfigFlags_NoMouseCursorChange flag. 76 | // 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value and WM_SETCURSOR message handling). 77 | // 2018-02-06: Inputs: Added mapping for ImGuiKey_Space. 78 | // 2018-02-06: Inputs: Honoring the io.WantSetMousePos by repositioning the mouse (when using navigation and ImGuiConfigFlags_NavMoveMouse is set). 79 | // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. 80 | // 2018-01-20: Inputs: Added Horizontal Mouse Wheel support. 81 | // 2018-01-08: Inputs: Added mapping for ImGuiKey_Insert. 82 | // 2018-01-05: Inputs: Added WM_LBUTTONDBLCLK double-click handlers for window classes with the CS_DBLCLKS flag. 83 | // 2017-10-23: Inputs: Added WM_SYSKEYDOWN / WM_SYSKEYUP handlers so e.g. the VK_MENU key can be read. 84 | // 2017-10-23: Inputs: Using Win32 ::SetCapture/::GetCapture() to retrieve mouse positions outside the client area when dragging. 85 | // 2016-11-12: Inputs: Only call Win32 ::SetCursor(nullptr) when io.MouseDrawCursor is set. 86 | 87 | struct ImGui_ImplWin32_Data 88 | { 89 | HWND hWnd; 90 | HWND MouseHwnd; 91 | int MouseTrackedArea; // 0: not tracked, 1: client are, 2: non-client area 92 | int MouseButtonsDown; 93 | INT64 Time; 94 | INT64 TicksPerSecond; 95 | ImGuiMouseCursor LastMouseCursor; 96 | 97 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 98 | bool HasGamepad; 99 | bool WantUpdateHasGamepad; 100 | HMODULE XInputDLL; 101 | PFN_XInputGetCapabilities XInputGetCapabilities; 102 | PFN_XInputGetState XInputGetState; 103 | #endif 104 | 105 | ImGui_ImplWin32_Data() { memset((void*)this, 0, sizeof(*this)); } 106 | }; 107 | 108 | // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts 109 | // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. 110 | // FIXME: multi-context support is not well tested and probably dysfunctional in this backend. 111 | // FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context. 112 | static ImGui_ImplWin32_Data* ImGui_ImplWin32_GetBackendData() 113 | { 114 | return ImGui::GetCurrentContext() ? (ImGui_ImplWin32_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr; 115 | } 116 | 117 | // Functions 118 | static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc) 119 | { 120 | ImGuiIO& io = ImGui::GetIO(); 121 | IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); 122 | 123 | INT64 perf_frequency, perf_counter; 124 | if (!::QueryPerformanceFrequency((LARGE_INTEGER*)&perf_frequency)) 125 | return false; 126 | if (!::QueryPerformanceCounter((LARGE_INTEGER*)&perf_counter)) 127 | return false; 128 | 129 | // Setup backend capabilities flags 130 | ImGui_ImplWin32_Data* bd = IM_NEW(ImGui_ImplWin32_Data)(); 131 | io.BackendPlatformUserData = (void*)bd; 132 | io.BackendPlatformName = "imgui_impl_win32"; 133 | io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) 134 | io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) 135 | 136 | bd->hWnd = (HWND)hwnd; 137 | bd->TicksPerSecond = perf_frequency; 138 | bd->Time = perf_counter; 139 | bd->LastMouseCursor = ImGuiMouseCursor_COUNT; 140 | 141 | // Set platform dependent data in viewport 142 | ImGui::GetMainViewport()->PlatformHandleRaw = (void*)hwnd; 143 | IM_UNUSED(platform_has_own_dc); // Used in 'docking' branch 144 | 145 | // Dynamically load XInput library 146 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 147 | bd->WantUpdateHasGamepad = true; 148 | const char* xinput_dll_names[] = 149 | { 150 | "xinput1_4.dll", // Windows 8+ 151 | "xinput1_3.dll", // DirectX SDK 152 | "xinput9_1_0.dll", // Windows Vista, Windows 7 153 | "xinput1_2.dll", // DirectX SDK 154 | "xinput1_1.dll" // DirectX SDK 155 | }; 156 | for (int n = 0; n < IM_ARRAYSIZE(xinput_dll_names); n++) 157 | if (HMODULE dll = ::LoadLibraryA(xinput_dll_names[n])) 158 | { 159 | bd->XInputDLL = dll; 160 | bd->XInputGetCapabilities = (PFN_XInputGetCapabilities)::GetProcAddress(dll, "XInputGetCapabilities"); 161 | bd->XInputGetState = (PFN_XInputGetState)::GetProcAddress(dll, "XInputGetState"); 162 | break; 163 | } 164 | #endif // IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 165 | 166 | return true; 167 | } 168 | 169 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd) 170 | { 171 | return ImGui_ImplWin32_InitEx(hwnd, false); 172 | } 173 | 174 | IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd) 175 | { 176 | // OpenGL needs CS_OWNDC 177 | return ImGui_ImplWin32_InitEx(hwnd, true); 178 | } 179 | 180 | void ImGui_ImplWin32_Shutdown() 181 | { 182 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 183 | IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); 184 | ImGuiIO& io = ImGui::GetIO(); 185 | 186 | // Unload XInput library 187 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 188 | if (bd->XInputDLL) 189 | ::FreeLibrary(bd->XInputDLL); 190 | #endif // IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 191 | 192 | io.BackendPlatformName = nullptr; 193 | io.BackendPlatformUserData = nullptr; 194 | io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad); 195 | IM_DELETE(bd); 196 | } 197 | 198 | static bool ImGui_ImplWin32_UpdateMouseCursor() 199 | { 200 | ImGuiIO& io = ImGui::GetIO(); 201 | if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) 202 | return false; 203 | 204 | ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor(); 205 | if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor) 206 | { 207 | // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor 208 | ::SetCursor(nullptr); 209 | } 210 | else 211 | { 212 | // Show OS mouse cursor 213 | LPTSTR win32_cursor = IDC_ARROW; 214 | switch (imgui_cursor) 215 | { 216 | case ImGuiMouseCursor_Arrow: win32_cursor = IDC_ARROW; break; 217 | case ImGuiMouseCursor_TextInput: win32_cursor = IDC_IBEAM; break; 218 | case ImGuiMouseCursor_ResizeAll: win32_cursor = IDC_SIZEALL; break; 219 | case ImGuiMouseCursor_ResizeEW: win32_cursor = IDC_SIZEWE; break; 220 | case ImGuiMouseCursor_ResizeNS: win32_cursor = IDC_SIZENS; break; 221 | case ImGuiMouseCursor_ResizeNESW: win32_cursor = IDC_SIZENESW; break; 222 | case ImGuiMouseCursor_ResizeNWSE: win32_cursor = IDC_SIZENWSE; break; 223 | case ImGuiMouseCursor_Hand: win32_cursor = IDC_HAND; break; 224 | case ImGuiMouseCursor_NotAllowed: win32_cursor = IDC_NO; break; 225 | } 226 | ::SetCursor(::LoadCursor(nullptr, win32_cursor)); 227 | } 228 | return true; 229 | } 230 | 231 | static bool IsVkDown(int vk) 232 | { 233 | return (::GetKeyState(vk) & 0x8000) != 0; 234 | } 235 | 236 | static void ImGui_ImplWin32_AddKeyEvent(ImGuiKey key, bool down, int native_keycode, int native_scancode = -1) 237 | { 238 | ImGuiIO& io = ImGui::GetIO(); 239 | io.AddKeyEvent(key, down); 240 | io.SetKeyEventNativeData(key, native_keycode, native_scancode); // To support legacy indexing (<1.87 user code) 241 | IM_UNUSED(native_scancode); 242 | } 243 | 244 | static void ImGui_ImplWin32_ProcessKeyEventsWorkarounds() 245 | { 246 | // Left & right Shift keys: when both are pressed together, Windows tend to not generate the WM_KEYUP event for the first released one. 247 | if (ImGui::IsKeyDown(ImGuiKey_LeftShift) && !IsVkDown(VK_LSHIFT)) 248 | ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftShift, false, VK_LSHIFT); 249 | if (ImGui::IsKeyDown(ImGuiKey_RightShift) && !IsVkDown(VK_RSHIFT)) 250 | ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightShift, false, VK_RSHIFT); 251 | 252 | // Sometimes WM_KEYUP for Win key is not passed down to the app (e.g. for Win+V on some setups, according to GLFW). 253 | if (ImGui::IsKeyDown(ImGuiKey_LeftSuper) && !IsVkDown(VK_LWIN)) 254 | ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftSuper, false, VK_LWIN); 255 | if (ImGui::IsKeyDown(ImGuiKey_RightSuper) && !IsVkDown(VK_RWIN)) 256 | ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightSuper, false, VK_RWIN); 257 | } 258 | 259 | static void ImGui_ImplWin32_UpdateKeyModifiers() 260 | { 261 | ImGuiIO& io = ImGui::GetIO(); 262 | io.AddKeyEvent(ImGuiMod_Ctrl, IsVkDown(VK_CONTROL)); 263 | io.AddKeyEvent(ImGuiMod_Shift, IsVkDown(VK_SHIFT)); 264 | io.AddKeyEvent(ImGuiMod_Alt, IsVkDown(VK_MENU)); 265 | io.AddKeyEvent(ImGuiMod_Super, IsVkDown(VK_APPS)); 266 | } 267 | 268 | static void ImGui_ImplWin32_UpdateMouseData() 269 | { 270 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 271 | ImGuiIO& io = ImGui::GetIO(); 272 | IM_ASSERT(bd->hWnd != 0); 273 | 274 | HWND focused_window = ::GetForegroundWindow(); 275 | const bool is_app_focused = (focused_window == bd->hWnd); 276 | if (is_app_focused) 277 | { 278 | // (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) 279 | if (io.WantSetMousePos) 280 | { 281 | POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; 282 | if (::ClientToScreen(bd->hWnd, &pos)) 283 | ::SetCursorPos(pos.x, pos.y); 284 | } 285 | 286 | // (Optional) Fallback to provide mouse position when focused (WM_MOUSEMOVE already provides this when hovered or captured) 287 | // This also fills a short gap when clicking non-client area: WM_NCMOUSELEAVE -> modal OS move -> gap -> WM_NCMOUSEMOVE 288 | if (!io.WantSetMousePos && bd->MouseTrackedArea == 0) 289 | { 290 | POINT pos; 291 | if (::GetCursorPos(&pos) && ::ScreenToClient(bd->hWnd, &pos)) 292 | io.AddMousePosEvent((float)pos.x, (float)pos.y); 293 | } 294 | } 295 | } 296 | 297 | // Gamepad navigation mapping 298 | static void ImGui_ImplWin32_UpdateGamepads() 299 | { 300 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 301 | ImGuiIO& io = ImGui::GetIO(); 302 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 303 | //if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. 304 | // return; 305 | 306 | // Calling XInputGetState() every frame on disconnected gamepads is unfortunately too slow. 307 | // Instead we refresh gamepad availability by calling XInputGetCapabilities() _only_ after receiving WM_DEVICECHANGE. 308 | if (bd->WantUpdateHasGamepad) 309 | { 310 | XINPUT_CAPABILITIES caps = {}; 311 | bd->HasGamepad = bd->XInputGetCapabilities ? (bd->XInputGetCapabilities(0, XINPUT_FLAG_GAMEPAD, &caps) == ERROR_SUCCESS) : false; 312 | bd->WantUpdateHasGamepad = false; 313 | } 314 | 315 | io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; 316 | XINPUT_STATE xinput_state; 317 | XINPUT_GAMEPAD& gamepad = xinput_state.Gamepad; 318 | if (!bd->HasGamepad || bd->XInputGetState == nullptr || bd->XInputGetState(0, &xinput_state) != ERROR_SUCCESS) 319 | return; 320 | io.BackendFlags |= ImGuiBackendFlags_HasGamepad; 321 | 322 | #define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V) 323 | #define MAP_BUTTON(KEY_NO, BUTTON_ENUM) { io.AddKeyEvent(KEY_NO, (gamepad.wButtons & BUTTON_ENUM) != 0); } 324 | #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)); } 325 | MAP_BUTTON(ImGuiKey_GamepadStart, XINPUT_GAMEPAD_START); 326 | MAP_BUTTON(ImGuiKey_GamepadBack, XINPUT_GAMEPAD_BACK); 327 | MAP_BUTTON(ImGuiKey_GamepadFaceLeft, XINPUT_GAMEPAD_X); 328 | MAP_BUTTON(ImGuiKey_GamepadFaceRight, XINPUT_GAMEPAD_B); 329 | MAP_BUTTON(ImGuiKey_GamepadFaceUp, XINPUT_GAMEPAD_Y); 330 | MAP_BUTTON(ImGuiKey_GamepadFaceDown, XINPUT_GAMEPAD_A); 331 | MAP_BUTTON(ImGuiKey_GamepadDpadLeft, XINPUT_GAMEPAD_DPAD_LEFT); 332 | MAP_BUTTON(ImGuiKey_GamepadDpadRight, XINPUT_GAMEPAD_DPAD_RIGHT); 333 | MAP_BUTTON(ImGuiKey_GamepadDpadUp, XINPUT_GAMEPAD_DPAD_UP); 334 | MAP_BUTTON(ImGuiKey_GamepadDpadDown, XINPUT_GAMEPAD_DPAD_DOWN); 335 | MAP_BUTTON(ImGuiKey_GamepadL1, XINPUT_GAMEPAD_LEFT_SHOULDER); 336 | MAP_BUTTON(ImGuiKey_GamepadR1, XINPUT_GAMEPAD_RIGHT_SHOULDER); 337 | MAP_ANALOG(ImGuiKey_GamepadL2, gamepad.bLeftTrigger, XINPUT_GAMEPAD_TRIGGER_THRESHOLD, 255); 338 | MAP_ANALOG(ImGuiKey_GamepadR2, gamepad.bRightTrigger, XINPUT_GAMEPAD_TRIGGER_THRESHOLD, 255); 339 | MAP_BUTTON(ImGuiKey_GamepadL3, XINPUT_GAMEPAD_LEFT_THUMB); 340 | MAP_BUTTON(ImGuiKey_GamepadR3, XINPUT_GAMEPAD_RIGHT_THUMB); 341 | MAP_ANALOG(ImGuiKey_GamepadLStickLeft, gamepad.sThumbLX, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 342 | MAP_ANALOG(ImGuiKey_GamepadLStickRight, gamepad.sThumbLX, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 343 | MAP_ANALOG(ImGuiKey_GamepadLStickUp, gamepad.sThumbLY, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 344 | MAP_ANALOG(ImGuiKey_GamepadLStickDown, gamepad.sThumbLY, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 345 | MAP_ANALOG(ImGuiKey_GamepadRStickLeft, gamepad.sThumbRX, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 346 | MAP_ANALOG(ImGuiKey_GamepadRStickRight, gamepad.sThumbRX, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 347 | MAP_ANALOG(ImGuiKey_GamepadRStickUp, gamepad.sThumbRY, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767); 348 | MAP_ANALOG(ImGuiKey_GamepadRStickDown, gamepad.sThumbRY, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768); 349 | #undef MAP_BUTTON 350 | #undef MAP_ANALOG 351 | #endif // #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 352 | } 353 | 354 | void ImGui_ImplWin32_NewFrame() 355 | { 356 | ImGuiIO& io = ImGui::GetIO(); 357 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 358 | IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplWin32_Init()?"); 359 | 360 | // Setup display size (every frame to accommodate for window resizing) 361 | RECT rect = { 0, 0, 0, 0 }; 362 | ::GetClientRect(bd->hWnd, &rect); 363 | io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); 364 | 365 | // Setup time step 366 | INT64 current_time = 0; 367 | ::QueryPerformanceCounter((LARGE_INTEGER*)¤t_time); 368 | io.DeltaTime = (float)(current_time - bd->Time) / bd->TicksPerSecond; 369 | bd->Time = current_time; 370 | 371 | // Update OS mouse position 372 | ImGui_ImplWin32_UpdateMouseData(); 373 | 374 | // Process workarounds for known Windows key handling issues 375 | ImGui_ImplWin32_ProcessKeyEventsWorkarounds(); 376 | 377 | // Update OS mouse cursor with the cursor requested by imgui 378 | ImGuiMouseCursor mouse_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor(); 379 | if (bd->LastMouseCursor != mouse_cursor) 380 | { 381 | bd->LastMouseCursor = mouse_cursor; 382 | ImGui_ImplWin32_UpdateMouseCursor(); 383 | } 384 | 385 | // Update game controllers (if enabled and available) 386 | ImGui_ImplWin32_UpdateGamepads(); 387 | } 388 | 389 | // 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) 390 | #define IM_VK_KEYPAD_ENTER (VK_RETURN + 256) 391 | 392 | // Map VK_xxx to ImGuiKey_xxx. 393 | static ImGuiKey ImGui_ImplWin32_VirtualKeyToImGuiKey(WPARAM wParam) 394 | { 395 | switch (wParam) 396 | { 397 | case VK_TAB: return ImGuiKey_Tab; 398 | case VK_LEFT: return ImGuiKey_LeftArrow; 399 | case VK_RIGHT: return ImGuiKey_RightArrow; 400 | case VK_UP: return ImGuiKey_UpArrow; 401 | case VK_DOWN: return ImGuiKey_DownArrow; 402 | case VK_PRIOR: return ImGuiKey_PageUp; 403 | case VK_NEXT: return ImGuiKey_PageDown; 404 | case VK_HOME: return ImGuiKey_Home; 405 | case VK_END: return ImGuiKey_End; 406 | case VK_INSERT: return ImGuiKey_Insert; 407 | case VK_DELETE: return ImGuiKey_Delete; 408 | case VK_BACK: return ImGuiKey_Backspace; 409 | case VK_SPACE: return ImGuiKey_Space; 410 | case VK_RETURN: return ImGuiKey_Enter; 411 | case VK_ESCAPE: return ImGuiKey_Escape; 412 | case VK_OEM_7: return ImGuiKey_Apostrophe; 413 | case VK_OEM_COMMA: return ImGuiKey_Comma; 414 | case VK_OEM_MINUS: return ImGuiKey_Minus; 415 | case VK_OEM_PERIOD: return ImGuiKey_Period; 416 | case VK_OEM_2: return ImGuiKey_Slash; 417 | case VK_OEM_1: return ImGuiKey_Semicolon; 418 | case VK_OEM_PLUS: return ImGuiKey_Equal; 419 | case VK_OEM_4: return ImGuiKey_LeftBracket; 420 | case VK_OEM_5: return ImGuiKey_Backslash; 421 | case VK_OEM_6: return ImGuiKey_RightBracket; 422 | case VK_OEM_3: return ImGuiKey_GraveAccent; 423 | case VK_CAPITAL: return ImGuiKey_CapsLock; 424 | case VK_SCROLL: return ImGuiKey_ScrollLock; 425 | case VK_NUMLOCK: return ImGuiKey_NumLock; 426 | case VK_SNAPSHOT: return ImGuiKey_PrintScreen; 427 | case VK_PAUSE: return ImGuiKey_Pause; 428 | case VK_NUMPAD0: return ImGuiKey_Keypad0; 429 | case VK_NUMPAD1: return ImGuiKey_Keypad1; 430 | case VK_NUMPAD2: return ImGuiKey_Keypad2; 431 | case VK_NUMPAD3: return ImGuiKey_Keypad3; 432 | case VK_NUMPAD4: return ImGuiKey_Keypad4; 433 | case VK_NUMPAD5: return ImGuiKey_Keypad5; 434 | case VK_NUMPAD6: return ImGuiKey_Keypad6; 435 | case VK_NUMPAD7: return ImGuiKey_Keypad7; 436 | case VK_NUMPAD8: return ImGuiKey_Keypad8; 437 | case VK_NUMPAD9: return ImGuiKey_Keypad9; 438 | case VK_DECIMAL: return ImGuiKey_KeypadDecimal; 439 | case VK_DIVIDE: return ImGuiKey_KeypadDivide; 440 | case VK_MULTIPLY: return ImGuiKey_KeypadMultiply; 441 | case VK_SUBTRACT: return ImGuiKey_KeypadSubtract; 442 | case VK_ADD: return ImGuiKey_KeypadAdd; 443 | case IM_VK_KEYPAD_ENTER: return ImGuiKey_KeypadEnter; 444 | case VK_LSHIFT: return ImGuiKey_LeftShift; 445 | case VK_LCONTROL: return ImGuiKey_LeftCtrl; 446 | case VK_LMENU: return ImGuiKey_LeftAlt; 447 | case VK_LWIN: return ImGuiKey_LeftSuper; 448 | case VK_RSHIFT: return ImGuiKey_RightShift; 449 | case VK_RCONTROL: return ImGuiKey_RightCtrl; 450 | case VK_RMENU: return ImGuiKey_RightAlt; 451 | case VK_RWIN: return ImGuiKey_RightSuper; 452 | case VK_APPS: return ImGuiKey_Menu; 453 | case '0': return ImGuiKey_0; 454 | case '1': return ImGuiKey_1; 455 | case '2': return ImGuiKey_2; 456 | case '3': return ImGuiKey_3; 457 | case '4': return ImGuiKey_4; 458 | case '5': return ImGuiKey_5; 459 | case '6': return ImGuiKey_6; 460 | case '7': return ImGuiKey_7; 461 | case '8': return ImGuiKey_8; 462 | case '9': return ImGuiKey_9; 463 | case 'A': return ImGuiKey_A; 464 | case 'B': return ImGuiKey_B; 465 | case 'C': return ImGuiKey_C; 466 | case 'D': return ImGuiKey_D; 467 | case 'E': return ImGuiKey_E; 468 | case 'F': return ImGuiKey_F; 469 | case 'G': return ImGuiKey_G; 470 | case 'H': return ImGuiKey_H; 471 | case 'I': return ImGuiKey_I; 472 | case 'J': return ImGuiKey_J; 473 | case 'K': return ImGuiKey_K; 474 | case 'L': return ImGuiKey_L; 475 | case 'M': return ImGuiKey_M; 476 | case 'N': return ImGuiKey_N; 477 | case 'O': return ImGuiKey_O; 478 | case 'P': return ImGuiKey_P; 479 | case 'Q': return ImGuiKey_Q; 480 | case 'R': return ImGuiKey_R; 481 | case 'S': return ImGuiKey_S; 482 | case 'T': return ImGuiKey_T; 483 | case 'U': return ImGuiKey_U; 484 | case 'V': return ImGuiKey_V; 485 | case 'W': return ImGuiKey_W; 486 | case 'X': return ImGuiKey_X; 487 | case 'Y': return ImGuiKey_Y; 488 | case 'Z': return ImGuiKey_Z; 489 | case VK_F1: return ImGuiKey_F1; 490 | case VK_F2: return ImGuiKey_F2; 491 | case VK_F3: return ImGuiKey_F3; 492 | case VK_F4: return ImGuiKey_F4; 493 | case VK_F5: return ImGuiKey_F5; 494 | case VK_F6: return ImGuiKey_F6; 495 | case VK_F7: return ImGuiKey_F7; 496 | case VK_F8: return ImGuiKey_F8; 497 | case VK_F9: return ImGuiKey_F9; 498 | case VK_F10: return ImGuiKey_F10; 499 | case VK_F11: return ImGuiKey_F11; 500 | case VK_F12: return ImGuiKey_F12; 501 | default: return ImGuiKey_None; 502 | } 503 | } 504 | 505 | // Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions. 506 | #ifndef WM_MOUSEHWHEEL 507 | #define WM_MOUSEHWHEEL 0x020E 508 | #endif 509 | #ifndef DBT_DEVNODES_CHANGED 510 | #define DBT_DEVNODES_CHANGED 0x0007 511 | #endif 512 | 513 | // Win32 message handler (process Win32 mouse/keyboard inputs, etc.) 514 | // Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. 515 | // When implementing your own backend, you can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if Dear ImGui wants to use your inputs. 516 | // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. 517 | // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. 518 | // Generally you may always pass all inputs to Dear ImGui, and hide them from your application based on those two flags. 519 | // 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. 520 | // 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. 521 | #if 0 522 | // Copy this line into your .cpp file to forward declare the function. 523 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 524 | #endif 525 | 526 | // See https://learn.microsoft.com/en-us/windows/win32/tablet/system-events-and-mouse-messages 527 | // Prefer to call this at the top of the message handler to avoid the possibility of other Win32 calls interfering with this. 528 | static ImGuiMouseSource GetMouseSourceFromMessageExtraInfo() 529 | { 530 | LPARAM extra_info = ::GetMessageExtraInfo(); 531 | if ((extra_info & 0xFFFFFF80) == 0xFF515700) 532 | return ImGuiMouseSource_Pen; 533 | if ((extra_info & 0xFFFFFF80) == 0xFF515780) 534 | return ImGuiMouseSource_TouchScreen; 535 | return ImGuiMouseSource_Mouse; 536 | } 537 | 538 | IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 539 | { 540 | if (ImGui::GetCurrentContext() == nullptr) 541 | return 0; 542 | 543 | ImGuiIO& io = ImGui::GetIO(); 544 | ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); 545 | 546 | switch (msg) 547 | { 548 | case WM_MOUSEMOVE: 549 | case WM_NCMOUSEMOVE: 550 | { 551 | // We need to call TrackMouseEvent in order to receive WM_MOUSELEAVE events 552 | ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); 553 | const int area = (msg == WM_MOUSEMOVE) ? 1 : 2; 554 | bd->MouseHwnd = hwnd; 555 | if (bd->MouseTrackedArea != area) 556 | { 557 | TRACKMOUSEEVENT tme_cancel = { sizeof(tme_cancel), TME_CANCEL, hwnd, 0 }; 558 | TRACKMOUSEEVENT tme_track = { sizeof(tme_track), (DWORD)((area == 2) ? (TME_LEAVE | TME_NONCLIENT) : TME_LEAVE), hwnd, 0 }; 559 | if (bd->MouseTrackedArea != 0) 560 | ::TrackMouseEvent(&tme_cancel); 561 | ::TrackMouseEvent(&tme_track); 562 | bd->MouseTrackedArea = area; 563 | } 564 | POINT mouse_pos = { (LONG)GET_X_LPARAM(lParam), (LONG)GET_Y_LPARAM(lParam) }; 565 | if (msg == WM_NCMOUSEMOVE && ::ScreenToClient(hwnd, &mouse_pos) == FALSE) // WM_NCMOUSEMOVE are provided in absolute coordinates. 566 | break; 567 | io.AddMouseSourceEvent(mouse_source); 568 | io.AddMousePosEvent((float)mouse_pos.x, (float)mouse_pos.y); 569 | break; 570 | } 571 | case WM_MOUSELEAVE: 572 | case WM_NCMOUSELEAVE: 573 | { 574 | const int area = (msg == WM_MOUSELEAVE) ? 1 : 2; 575 | if (bd->MouseTrackedArea == area) 576 | { 577 | if (bd->MouseHwnd == hwnd) 578 | bd->MouseHwnd = nullptr; 579 | bd->MouseTrackedArea = 0; 580 | io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); 581 | } 582 | break; 583 | } 584 | case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: 585 | case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: 586 | case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: 587 | case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: 588 | { 589 | ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); 590 | int button = 0; 591 | if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) { button = 0; } 592 | if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) { button = 1; } 593 | if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) { button = 2; } 594 | if (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONDBLCLK) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; } 595 | if (bd->MouseButtonsDown == 0 && ::GetCapture() == nullptr) 596 | ::SetCapture(hwnd); 597 | bd->MouseButtonsDown |= 1 << button; 598 | io.AddMouseSourceEvent(mouse_source); 599 | io.AddMouseButtonEvent(button, true); 600 | return 0; 601 | } 602 | case WM_LBUTTONUP: 603 | case WM_RBUTTONUP: 604 | case WM_MBUTTONUP: 605 | case WM_XBUTTONUP: 606 | { 607 | ImGuiMouseSource mouse_source = GetMouseSourceFromMessageExtraInfo(); 608 | int button = 0; 609 | if (msg == WM_LBUTTONUP) { button = 0; } 610 | if (msg == WM_RBUTTONUP) { button = 1; } 611 | if (msg == WM_MBUTTONUP) { button = 2; } 612 | if (msg == WM_XBUTTONUP) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; } 613 | bd->MouseButtonsDown &= ~(1 << button); 614 | if (bd->MouseButtonsDown == 0 && ::GetCapture() == hwnd) 615 | ::ReleaseCapture(); 616 | io.AddMouseSourceEvent(mouse_source); 617 | io.AddMouseButtonEvent(button, false); 618 | return 0; 619 | } 620 | case WM_MOUSEWHEEL: 621 | io.AddMouseWheelEvent(0.0f, (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA); 622 | return 0; 623 | case WM_MOUSEHWHEEL: 624 | io.AddMouseWheelEvent(-(float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA, 0.0f); 625 | return 0; 626 | case WM_KEYDOWN: 627 | case WM_KEYUP: 628 | case WM_SYSKEYDOWN: 629 | case WM_SYSKEYUP: 630 | { 631 | const bool is_key_down = (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN); 632 | if (wParam < 256) 633 | { 634 | // Submit modifiers 635 | ImGui_ImplWin32_UpdateKeyModifiers(); 636 | 637 | // Obtain virtual key code 638 | // (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.) 639 | int vk = (int)wParam; 640 | if ((wParam == VK_RETURN) && (HIWORD(lParam) & KF_EXTENDED)) 641 | vk = IM_VK_KEYPAD_ENTER; 642 | 643 | // Submit key event 644 | const ImGuiKey key = ImGui_ImplWin32_VirtualKeyToImGuiKey(vk); 645 | const int scancode = (int)LOBYTE(HIWORD(lParam)); 646 | if (key != ImGuiKey_None) 647 | ImGui_ImplWin32_AddKeyEvent(key, is_key_down, vk, scancode); 648 | 649 | // Submit individual left/right modifier events 650 | if (vk == VK_SHIFT) 651 | { 652 | // Important: Shift keys tend to get stuck when pressed together, missing key-up events are corrected in ImGui_ImplWin32_ProcessKeyEventsWorkarounds() 653 | if (IsVkDown(VK_LSHIFT) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftShift, is_key_down, VK_LSHIFT, scancode); } 654 | if (IsVkDown(VK_RSHIFT) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightShift, is_key_down, VK_RSHIFT, scancode); } 655 | } 656 | else if (vk == VK_CONTROL) 657 | { 658 | if (IsVkDown(VK_LCONTROL) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftCtrl, is_key_down, VK_LCONTROL, scancode); } 659 | if (IsVkDown(VK_RCONTROL) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightCtrl, is_key_down, VK_RCONTROL, scancode); } 660 | } 661 | else if (vk == VK_MENU) 662 | { 663 | if (IsVkDown(VK_LMENU) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_LeftAlt, is_key_down, VK_LMENU, scancode); } 664 | if (IsVkDown(VK_RMENU) == is_key_down) { ImGui_ImplWin32_AddKeyEvent(ImGuiKey_RightAlt, is_key_down, VK_RMENU, scancode); } 665 | } 666 | } 667 | return 0; 668 | } 669 | case WM_SETFOCUS: 670 | case WM_KILLFOCUS: 671 | io.AddFocusEvent(msg == WM_SETFOCUS); 672 | return 0; 673 | case WM_CHAR: 674 | if (::IsWindowUnicode(hwnd)) 675 | { 676 | // You can also use ToAscii()+GetKeyboardState() to retrieve characters. 677 | if (wParam > 0 && wParam < 0x10000) 678 | io.AddInputCharacterUTF16((unsigned short)wParam); 679 | } 680 | else 681 | { 682 | wchar_t wch = 0; 683 | ::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (char*)&wParam, 1, &wch, 1); 684 | io.AddInputCharacter(wch); 685 | } 686 | return 0; 687 | case WM_SETCURSOR: 688 | // This is required to restore cursor when transitioning from e.g resize borders to client area. 689 | if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor()) 690 | return 1; 691 | return 0; 692 | case WM_DEVICECHANGE: 693 | #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 694 | if ((UINT)wParam == DBT_DEVNODES_CHANGED) 695 | bd->WantUpdateHasGamepad = true; 696 | #endif 697 | return 0; 698 | } 699 | return 0; 700 | } 701 | 702 | 703 | //-------------------------------------------------------------------------------------------------------- 704 | // DPI-related helpers (optional) 705 | //-------------------------------------------------------------------------------------------------------- 706 | // - Use to enable DPI awareness without having to create an application manifest. 707 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 708 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 709 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 710 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 711 | //--------------------------------------------------------------------------------------------------------- 712 | // This is the scheme successfully used by GLFW (from which we borrowed some of the code) and other apps aiming to be highly portable. 713 | // ImGui_ImplWin32_EnableDpiAwareness() is just a helper called by main.cpp, we don't call it automatically. 714 | // If you are trying to implement your own backend for your own engine, you may ignore that noise. 715 | //--------------------------------------------------------------------------------------------------------- 716 | 717 | // Perform our own check with RtlVerifyVersionInfo() instead of using functions from as they 718 | // require a manifest to be functional for checks above 8.1. See https://github.com/ocornut/imgui/issues/4200 719 | static BOOL _IsWindowsVersionOrGreater(WORD major, WORD minor, WORD) 720 | { 721 | typedef LONG(WINAPI* PFN_RtlVerifyVersionInfo)(OSVERSIONINFOEXW*, ULONG, ULONGLONG); 722 | static PFN_RtlVerifyVersionInfo RtlVerifyVersionInfoFn = nullptr; 723 | if (RtlVerifyVersionInfoFn == nullptr) 724 | if (HMODULE ntdllModule = ::GetModuleHandleA("ntdll.dll")) 725 | RtlVerifyVersionInfoFn = (PFN_RtlVerifyVersionInfo)GetProcAddress(ntdllModule, "RtlVerifyVersionInfo"); 726 | if (RtlVerifyVersionInfoFn == nullptr) 727 | return FALSE; 728 | 729 | RTL_OSVERSIONINFOEXW versionInfo = { }; 730 | ULONGLONG conditionMask = 0; 731 | versionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); 732 | versionInfo.dwMajorVersion = major; 733 | versionInfo.dwMinorVersion = minor; 734 | VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); 735 | VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); 736 | return (RtlVerifyVersionInfoFn(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask) == 0) ? TRUE : FALSE; 737 | } 738 | 739 | #define _IsWindowsVistaOrGreater() _IsWindowsVersionOrGreater(HIBYTE(0x0600), LOBYTE(0x0600), 0) // _WIN32_WINNT_VISTA 740 | #define _IsWindows8OrGreater() _IsWindowsVersionOrGreater(HIBYTE(0x0602), LOBYTE(0x0602), 0) // _WIN32_WINNT_WIN8 741 | #define _IsWindows8Point1OrGreater() _IsWindowsVersionOrGreater(HIBYTE(0x0603), LOBYTE(0x0603), 0) // _WIN32_WINNT_WINBLUE 742 | #define _IsWindows10OrGreater() _IsWindowsVersionOrGreater(HIBYTE(0x0A00), LOBYTE(0x0A00), 0) // _WIN32_WINNT_WINTHRESHOLD / _WIN32_WINNT_WIN10 743 | 744 | #ifndef DPI_ENUMS_DECLARED 745 | typedef enum { PROCESS_DPI_UNAWARE = 0, PROCESS_SYSTEM_DPI_AWARE = 1, PROCESS_PER_MONITOR_DPI_AWARE = 2 } PROCESS_DPI_AWARENESS; 746 | typedef enum { MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2, MDT_DEFAULT = MDT_EFFECTIVE_DPI } MONITOR_DPI_TYPE; 747 | #endif 748 | #ifndef _DPI_AWARENESS_CONTEXTS_ 749 | DECLARE_HANDLE(DPI_AWARENESS_CONTEXT); 750 | #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE (DPI_AWARENESS_CONTEXT)-3 751 | #endif 752 | #ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 753 | #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (DPI_AWARENESS_CONTEXT)-4 754 | #endif 755 | typedef HRESULT(WINAPI* PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS); // Shcore.lib + dll, Windows 8.1+ 756 | typedef HRESULT(WINAPI* PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); // Shcore.lib + dll, Windows 8.1+ 757 | typedef DPI_AWARENESS_CONTEXT(WINAPI* PFN_SetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); // User32.lib + dll, Windows 10 v1607+ (Creators Update) 758 | 759 | // Helper function to enable DPI awareness without setting up a manifest 760 | void ImGui_ImplWin32_EnableDpiAwareness() 761 | { 762 | if (_IsWindows10OrGreater()) 763 | { 764 | static HINSTANCE user32_dll = ::LoadLibraryA("user32.dll"); // Reference counted per-process 765 | if (PFN_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContextFn = (PFN_SetThreadDpiAwarenessContext)::GetProcAddress(user32_dll, "SetThreadDpiAwarenessContext")) 766 | { 767 | SetThreadDpiAwarenessContextFn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); 768 | return; 769 | } 770 | } 771 | if (_IsWindows8Point1OrGreater()) 772 | { 773 | static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process 774 | if (PFN_SetProcessDpiAwareness SetProcessDpiAwarenessFn = (PFN_SetProcessDpiAwareness)::GetProcAddress(shcore_dll, "SetProcessDpiAwareness")) 775 | { 776 | SetProcessDpiAwarenessFn(PROCESS_PER_MONITOR_DPI_AWARE); 777 | return; 778 | } 779 | } 780 | #if _WIN32_WINNT >= 0x0600 781 | ::SetProcessDPIAware(); 782 | #endif 783 | } 784 | 785 | #if defined(_MSC_VER) && !defined(NOGDI) 786 | #pragma comment(lib, "gdi32") // Link with gdi32.lib for GetDeviceCaps(). MinGW will require linking with '-lgdi32' 787 | #endif 788 | 789 | float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor) 790 | { 791 | UINT xdpi = 96, ydpi = 96; 792 | if (_IsWindows8Point1OrGreater()) 793 | { 794 | static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process 795 | static PFN_GetDpiForMonitor GetDpiForMonitorFn = nullptr; 796 | if (GetDpiForMonitorFn == nullptr && shcore_dll != nullptr) 797 | GetDpiForMonitorFn = (PFN_GetDpiForMonitor)::GetProcAddress(shcore_dll, "GetDpiForMonitor"); 798 | if (GetDpiForMonitorFn != nullptr) 799 | { 800 | GetDpiForMonitorFn((HMONITOR)monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi); 801 | IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert! 802 | return xdpi / 96.0f; 803 | } 804 | } 805 | #ifndef NOGDI 806 | const HDC dc = ::GetDC(nullptr); 807 | xdpi = ::GetDeviceCaps(dc, LOGPIXELSX); 808 | ydpi = ::GetDeviceCaps(dc, LOGPIXELSY); 809 | IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert! 810 | ::ReleaseDC(nullptr, dc); 811 | #endif 812 | return xdpi / 96.0f; 813 | } 814 | 815 | float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd) 816 | { 817 | HMONITOR monitor = ::MonitorFromWindow((HWND)hwnd, MONITOR_DEFAULTTONEAREST); 818 | return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); 819 | } 820 | 821 | //--------------------------------------------------------------------------------------------------------- 822 | // Transparency related helpers (optional) 823 | //-------------------------------------------------------------------------------------------------------- 824 | 825 | #if defined(_MSC_VER) 826 | #pragma comment(lib, "dwmapi") // Link with dwmapi.lib. MinGW will require linking with '-ldwmapi' 827 | #endif 828 | 829 | // [experimental] 830 | // Borrowed from GLFW's function updateFramebufferTransparency() in src/win32_window.c 831 | // (the Dwm* functions are Vista era functions but we are borrowing logic from GLFW) 832 | void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd) 833 | { 834 | if (!_IsWindowsVistaOrGreater()) 835 | return; 836 | 837 | BOOL composition; 838 | if (FAILED(::DwmIsCompositionEnabled(&composition)) || !composition) 839 | return; 840 | 841 | BOOL opaque; 842 | DWORD color; 843 | if (_IsWindows8OrGreater() || (SUCCEEDED(::DwmGetColorizationColor(&color, &opaque)) && !opaque)) 844 | { 845 | HRGN region = ::CreateRectRgn(0, 0, -1, -1); 846 | DWM_BLURBEHIND bb = {}; 847 | bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; 848 | bb.hRgnBlur = region; 849 | bb.fEnable = TRUE; 850 | ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); 851 | ::DeleteObject(region); 852 | } 853 | else 854 | { 855 | DWM_BLURBEHIND bb = {}; 856 | bb.dwFlags = DWM_BB_ENABLE; 857 | ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); 858 | } 859 | } 860 | 861 | //--------------------------------------------------------------------------------------------------------- 862 | -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/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 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 14 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 15 | 16 | #pragma once 17 | #include "imgui.h" // IMGUI_IMPL_API 18 | 19 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 20 | IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); 21 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 22 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 23 | 24 | // Win32 message handler your application need to call. 25 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 26 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 27 | // - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. 28 | 29 | #if 0 30 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 31 | #endif 32 | 33 | // DPI-related helpers (optional) 34 | // - Use to enable DPI awareness without having to create an application manifest. 35 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 36 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 37 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 38 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 39 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 40 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 41 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 42 | 43 | // Transparency related helpers (optional) [experimental] 44 | // - Use to enable alpha compositing transparency with the desktop. 45 | // - Use together with e.g. clearing your framebuffer with zero-alpha. 46 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd); // HWND hwnd 47 | -------------------------------------------------------------------------------- /CS2_External/OS-ImGui/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/Offsets.cpp: -------------------------------------------------------------------------------- 1 | #include "Offsets.h" 2 | 3 | DWORD64 SearchOffsets(std::string Signature, DWORD64 ModuleAddress) 4 | { 5 | std::vector TempAddressList; 6 | DWORD64 Address = 0; 7 | DWORD Offsets = 0; 8 | 9 | TempAddressList = ProcessMgr.SearchMemory(Signature, ModuleAddress, ModuleAddress + 0x4000000); 10 | 11 | if (TempAddressList.size() <= 0) 12 | return 0; 13 | 14 | if (!ProcessMgr.ReadMemory(TempAddressList.at(0) + 3, Offsets)) 15 | return 0; 16 | 17 | Address = TempAddressList.at(0) + Offsets + 7; 18 | return Address; 19 | } 20 | 21 | bool Offset::UpdateOffsets() 22 | { 23 | DWORD64 ClientDLL = reinterpret_cast(ProcessMgr.GetProcessModuleHandle("client.dll")); 24 | if (ClientDLL == 0) 25 | return false; 26 | 27 | DWORD64 TempAddress = 0; 28 | 29 | TempAddress = SearchOffsets(Offset::Signatures::EntityList, ClientDLL); 30 | if (TempAddress == 0) 31 | return false; 32 | 33 | Offset::EntityList = TempAddress - ClientDLL; 34 | 35 | TempAddress = SearchOffsets(Offset::Signatures::LocalPlayerController, ClientDLL); 36 | if (TempAddress == 0) 37 | return false; 38 | 39 | Offset::LocalPlayerController = TempAddress - ClientDLL; 40 | 41 | TempAddress = SearchOffsets(Offset::Signatures::ViewMatrix, ClientDLL); 42 | if (TempAddress == 0) 43 | return false; 44 | 45 | Offset::Matrix = TempAddress - ClientDLL; 46 | 47 | TempAddress = SearchOffsets(Offset::Signatures::GlobalVars, ClientDLL); 48 | if (TempAddress == 0) 49 | return false; 50 | 51 | Offset::GlobalVars = TempAddress - ClientDLL; 52 | 53 | TempAddress = SearchOffsets(Offset::Signatures::ViewAngles, ClientDLL); 54 | if (TempAddress == 0) 55 | return false; 56 | if (!ProcessMgr.ReadMemory(TempAddress, TempAddress)) 57 | return false; 58 | 59 | Offset::ViewAngle = TempAddress + 0x6140 - ClientDLL; 60 | 61 | TempAddress = SearchOffsets(Offset::Signatures::LocalPlayerPawn, ClientDLL); 62 | if (TempAddress == 0) 63 | return false; 64 | 65 | Offset::LocalPlayerPawn = TempAddress + 0x138 - ClientDLL; 66 | 67 | TempAddress = SearchOffsets(Offset::Signatures::ForceJump, ClientDLL); 68 | if (TempAddress == 0) 69 | return false; 70 | 71 | Offset::ForceJump = TempAddress + 0x30 - ClientDLL; 72 | return true; 73 | } 74 | -------------------------------------------------------------------------------- /CS2_External/Offsets.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Utils/ProcessManager.hpp" 4 | 5 | // From: https://github.com/a2x/cs2-dumper/blob/main/generated/client.dll.hpp 6 | namespace Offset 7 | { 8 | inline DWORD EntityList; 9 | inline DWORD Matrix; 10 | inline DWORD ViewAngle; 11 | inline DWORD LocalPlayerController; 12 | inline DWORD LocalPlayerPawn; 13 | inline DWORD ForceJump; 14 | inline DWORD GlobalVars; 15 | 16 | struct 17 | { 18 | DWORD Health = 0x32C; 19 | DWORD TeamID = 0x3BF; 20 | DWORD IsAlive = 0x7DC; 21 | DWORD PlayerPawn = 0x5F4; 22 | DWORD iszPlayerName = 0x628; 23 | }Entity; 24 | 25 | struct 26 | { 27 | DWORD Pos = 0x1224; 28 | DWORD MaxHealth = 0x328; 29 | DWORD CurrentHealth = 0x32C; 30 | DWORD GameSceneNode = 0x310; 31 | DWORD BoneArray = 0x1E0; 32 | DWORD angEyeAngles = 0x1510; 33 | DWORD vecLastClipCameraPos = 0x128C; 34 | DWORD pClippingWeapon = 0x12A8; 35 | DWORD iShotsFired = 0x1418; 36 | DWORD flFlashDuration = 0x1468; 37 | DWORD aimPunchAngle = 0x1714; 38 | DWORD aimPunchCache = 0x1738; 39 | DWORD iIDEntIndex = 0x153C; 40 | DWORD iTeamNum = 0x3BF; 41 | DWORD CameraServices = 0x10E0; 42 | DWORD iFovStart = 0x214; 43 | DWORD fFlags = 0x3C8; 44 | DWORD bSpottedByMask = 0x1630 + 0xC; // entitySpottedState + bSpottedByMask 45 | }Pawn; 46 | 47 | struct 48 | { 49 | DWORD RealTime = 0x00; 50 | DWORD FrameCount = 0x04; 51 | DWORD MaxClients = 0x10; 52 | DWORD IntervalPerTick = 0x14; 53 | DWORD CurrentTime = 0x2C; 54 | DWORD CurrentTime2 = 0x30; 55 | DWORD TickCount = 0x40; 56 | DWORD IntervalPerTick2 = 0x44; 57 | DWORD CurrentNetchan = 0x0048; 58 | DWORD CurrentMap = 0x0180; 59 | DWORD CurrentMapName = 0x0188; 60 | } GlobalVar; 61 | 62 | namespace Signatures 63 | { 64 | const std::string GlobalVars = "48 89 0D ?? ?? ?? ?? 48 89 41"; 65 | const std::string ViewMatrix = "48 8D 0D ?? ?? ?? ?? 48 C1 E0 06"; 66 | const std::string ViewAngles = "48 8B 0D ?? ?? ?? ?? E9 ?? ?? ?? ?? CC CC CC CC 40 55"; 67 | const std::string EntityList = "48 8B 0D ?? ?? ?? ?? 48 89 7C 24 ?? 8B FA C1"; 68 | const std::string LocalPlayerController = "48 8B 05 ?? ?? ?? ?? 48 85 C0 74 4F"; 69 | const std::string ForceJump = "48 8B 05 ?? ?? ?? ?? 48 8D 1D ?? ?? ?? ?? 48 89 45"; 70 | const std::string LocalPlayerPawn = "48 8D 05 ?? ?? ?? ?? C3 CC CC CC CC CC CC CC CC 48 83 EC ?? 8B 0D"; 71 | } 72 | 73 | bool UpdateOffsets(); 74 | } 75 | -------------------------------------------------------------------------------- /CS2_External/Radar/Radar.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/Radar/Radar.cpp -------------------------------------------------------------------------------- /CS2_External/Radar/Radar.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/Radar/Radar.h -------------------------------------------------------------------------------- /CS2_External/Render.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/Render.hpp -------------------------------------------------------------------------------- /CS2_External/TriggerBot.cpp: -------------------------------------------------------------------------------- 1 | #include "TriggerBot.h" 2 | 3 | void TriggerBot::Run(const CEntity& LocalEntity) 4 | { 5 | DWORD uHandle = 0; 6 | if (!ProcessMgr.ReadMemory(LocalEntity.Pawn.Address + Offset::Pawn.iIDEntIndex, uHandle)) 7 | return; 8 | if (uHandle == -1) 9 | return; 10 | 11 | DWORD64 ListEntry = 0; 12 | ListEntry = ProcessMgr.TraceAddress(gGame.GetEntityListAddress(), { 0x8 * (uHandle >> 9) + 0x10,0x0 }); 13 | if (ListEntry == 0) 14 | return; 15 | 16 | DWORD64 PawnAddress = 0; 17 | if (!ProcessMgr.ReadMemory(ListEntry + 0x78 * (uHandle & 0x1FF), PawnAddress)) 18 | return; 19 | 20 | CEntity Entity; 21 | if (!Entity.UpdatePawn(PawnAddress)) 22 | return; 23 | 24 | bool AllowShoot = false; 25 | 26 | if (MenuConfig::TeamCheck) 27 | AllowShoot = LocalEntity.Pawn.TeamID != Entity.Pawn.TeamID && Entity.Pawn.Health > 0; 28 | else 29 | AllowShoot = Entity.Pawn.Health > 0; 30 | 31 | if (!AllowShoot) 32 | return; 33 | 34 | static std::chrono::time_point LastTimePoint = std::chrono::steady_clock::now(); 35 | auto CurTimePoint = std::chrono::steady_clock::now(); 36 | if (CurTimePoint - LastTimePoint >= std::chrono::milliseconds(TriggerDelay)) 37 | { 38 | const bool isAlreadyShooting = GetAsyncKeyState(VK_LBUTTON) < 0; 39 | if (!isAlreadyShooting) 40 | { 41 | mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); 42 | mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); 43 | } 44 | 45 | LastTimePoint = CurTimePoint; 46 | } 47 | } -------------------------------------------------------------------------------- /CS2_External/TriggerBot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Game.h" 3 | #include "Entity.h" 4 | #include "MenuConfig.hpp" 5 | #include 6 | 7 | namespace TriggerBot 8 | { 9 | inline DWORD TriggerDelay = 90; // ms 10 | inline int HotKey = VK_LMENU; 11 | inline std::vector HotKeyList{VK_LMENU, VK_RBUTTON, VK_XBUTTON1, VK_XBUTTON2, VK_CAPITAL, VK_LSHIFT, VK_LCONTROL}; 12 | inline int Mode = 0; 13 | 14 | inline void SetHotKey(int Index) 15 | { 16 | HotKey = HotKeyList.at(Index); 17 | } 18 | inline void SetMode(int Index) 19 | { 20 | Mode = Index; 21 | } 22 | 23 | // Triggerbot 24 | void Run(const CEntity& LocalEntity); 25 | } -------------------------------------------------------------------------------- /CS2_External/Utils/ConfigMenu.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfigMenu.hpp" 2 | #include "../MenuConfig.hpp" 3 | #include "ConfigSaver.hpp" 4 | #include "../TriggerBot.h" 5 | #include "../AimBot.hpp" 6 | #include 7 | 8 | namespace ConfigMenu { 9 | 10 | void RenderConfigMenu() { 11 | // Config 12 | if (ImGui::BeginTabItem("Config ")) 13 | { 14 | static char configNameBuffer[128] = ""; 15 | 16 | ImGui::InputText("New Config Name", configNameBuffer, sizeof(configNameBuffer)); 17 | 18 | if (ImGui::Button("Create Config")) 19 | { 20 | std::string configFileName = std::string(configNameBuffer) + ".config"; 21 | MyConfigSaver::SaveConfig(configFileName); 22 | } 23 | 24 | ImGui::Separator(); 25 | 26 | static int selectedConfig = -1; 27 | 28 | const std::string configDir = MenuConfig::path; 29 | static std::vector configFiles; 30 | 31 | configFiles.clear(); 32 | for (const auto& entry : std::filesystem::directory_iterator(configDir)) 33 | { 34 | if (entry.is_regular_file() && entry.path().extension() == ".config") 35 | { 36 | configFiles.push_back(entry.path().filename().string()); 37 | } 38 | } 39 | 40 | for (int i = 0; i < configFiles.size(); ++i) 41 | { 42 | if (ImGui::Selectable(configFiles[i].c_str(), selectedConfig == i)) 43 | { 44 | selectedConfig = i; 45 | } 46 | } 47 | 48 | if (selectedConfig != -1) 49 | { 50 | ImGui::Text("Selected Config: %s", configFiles[selectedConfig].c_str()); 51 | } 52 | 53 | if (ImGui::Button("Load Selected") && selectedConfig >= 0 && selectedConfig < configFiles.size()) 54 | { 55 | std::string selectedConfigFile = configFiles[selectedConfig]; 56 | MyConfigSaver::LoadConfig(selectedConfigFile); 57 | } 58 | 59 | if (ImGui::Button("Save Selected") && selectedConfig >= 0 && selectedConfig < configFiles.size()) 60 | { 61 | std::string selectedConfigFile = configFiles[selectedConfig]; 62 | MyConfigSaver::SaveConfig(selectedConfigFile); 63 | } 64 | 65 | ImGui::Separator(); 66 | 67 | if (ImGui::Button("Delete Selected") && selectedConfig >= 0 && selectedConfig < configFiles.size()) 68 | { 69 | std::string selectedConfigFile = configFiles[selectedConfig]; 70 | std::string fullPath = configDir + "/" + selectedConfigFile; 71 | if (std::remove(fullPath.c_str()) == 0) 72 | { 73 | configFiles.erase(configFiles.begin() + selectedConfig); 74 | selectedConfig = -1; 75 | } 76 | else 77 | { 78 | } 79 | } 80 | 81 | if (ImGui::Button("Reset to Default")) 82 | { 83 | ConfigMenu::ResetToDefault(); 84 | } 85 | 86 | ImGui::EndTabItem(); 87 | } 88 | } 89 | 90 | void ResetToDefault() { 91 | MenuConfig::ShowBoneESP = true; 92 | MenuConfig::ShowBoxESP = true; 93 | MenuConfig::ShowHealthBar = true; 94 | MenuConfig::ShowWeaponESP = true; 95 | MenuConfig::ShowDistance = true; 96 | MenuConfig::ShowEyeRay = true; 97 | MenuConfig::ShowPlayerName = true; 98 | MenuConfig::AimBot = true; 99 | MenuConfig::AimPosition = 0; 100 | MenuConfig::AimPositionIndex = BONEINDEX::head; 101 | MenuConfig::BoxType = 0; 102 | MenuConfig::HealthBarType = 0; 103 | MenuConfig::BoneColor = ImVec4(255, 255, 255, 255); 104 | MenuConfig::BoxColor = ImVec4(255, 255, 255, 255); 105 | MenuConfig::EyeRayColor = ImVec4(255, 0, 0, 255); 106 | MenuConfig::ShowMenu = true; 107 | MenuConfig::ShowRadar = true; 108 | MenuConfig::RadarRange = 150; 109 | MenuConfig::ShowRadarCrossLine = true; 110 | MenuConfig::RadarCrossLineColor = ImVec4(34, 34, 34, 180); 111 | MenuConfig::RadarType = 2; 112 | MenuConfig::RadarPointSizeProportion = 1.f; 113 | MenuConfig::Proportion = 2230; 114 | MenuConfig::TriggerBot = true; 115 | MenuConfig::TeamCheck = true; 116 | MenuConfig::VisibleCheck = true; 117 | MenuConfig::ShowHeadShootLine = true; 118 | MenuConfig::HeadShootLineColor = ImVec4(255, 255, 255, 255); 119 | MenuConfig::AimBotHotKey = 0; 120 | AimControl::SetHotKey(MenuConfig::AimBotHotKey); 121 | MenuConfig::ShowLineToEnemy = false; 122 | MenuConfig::FovLineSize = 60.0f; 123 | TriggerBot::TriggerDelay = 90; 124 | AimControl::RCSBullet = 1; 125 | MenuConfig::TriggerHotKey = 0; 126 | TriggerBot::SetHotKey(MenuConfig::TriggerHotKey); 127 | MenuConfig::TriggerMode = 0; 128 | TriggerBot::SetMode(MenuConfig::TriggerMode);//TriggerMode 129 | AimControl::RCSScale = ImVec2(1.2f, 1.4f); 130 | MenuConfig::FovLineColor = ImVec4(55, 55, 55, 220); 131 | MenuConfig::LineToEnemyColor = ImVec4(255, 255, 255, 220); 132 | MenuConfig::ShowCrossHair = true; 133 | MenuConfig::CrossHairColor = ImColor(45, 45, 45, 255); 134 | MenuConfig::CrossHairSize = 150; 135 | MenuConfig::ShowAimFovRange = true; 136 | MenuConfig::AimFovRangeColor= ImColor(230, 230, 230, 255); 137 | MenuConfig::OBSBypass = true; 138 | MenuConfig::BunnyHop = false; 139 | MenuConfig::ShowWhenSpec = true; 140 | MenuConfig::AntiFlashbang = true; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /CS2_External/Utils/ConfigMenu.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ConfigMenu { 4 | void RenderConfigMenu(); 5 | void ResetToDefault(); 6 | // Define other configuration-related functions and variables here. 7 | } 8 | -------------------------------------------------------------------------------- /CS2_External/Utils/ConfigSaver.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "ConfigSaver.hpp" 6 | #include "../MenuConfig.hpp" // Include your global settings header 7 | #include "../TriggerBot.h" 8 | #include "../AimBot.hpp" 9 | 10 | namespace MyConfigSaver { 11 | 12 | // Function to save the configuration to a file 13 | void SaveConfig(const std::string& filename) { 14 | std::ofstream configFile(MenuConfig::path+'/'+filename); 15 | if (!configFile.is_open()) { 16 | std::cerr << "Error: Could not open the configuration file." << std::endl; 17 | return; 18 | } 19 | 20 | // Example: Save global settings to the file 21 | configFile << "ShowBoneESP " << MenuConfig::ShowBoneESP << std::endl; 22 | configFile << "TriggerDelay " << TriggerBot::TriggerDelay << std::endl; 23 | configFile << "ShowBoxESP " << MenuConfig::ShowBoxESP << std::endl; 24 | configFile << "TriggerHotKey " << MenuConfig::TriggerHotKey << std::endl; 25 | configFile << "TriggerMode " << MenuConfig::TriggerMode << std::endl;//TriggerMode 26 | configFile << "RCSBullet " << AimControl::RCSBullet << std::endl; 27 | configFile << "ShowHealthBar " << MenuConfig::ShowHealthBar << std::endl; 28 | configFile << "AimFov " << AimControl::AimFov << std::endl; 29 | configFile << "FovLineSize " << MenuConfig::FovLineSize << std::endl; 30 | configFile << "AimBotHotKey " << MenuConfig::AimBotHotKey << std::endl; 31 | configFile << "ShowLineToEnemy " << MenuConfig::ShowLineToEnemy << std::endl; 32 | configFile << "RCSScale.x " << AimControl::RCSScale.x << std::endl; 33 | configFile << "RCSScale.y " << AimControl::RCSScale.y << std::endl; 34 | configFile << "ShowWeaponESP " << MenuConfig::ShowWeaponESP << std::endl; 35 | configFile << "ShowDistance " << MenuConfig::ShowDistance << std::endl; 36 | configFile << "Smooth " << AimControl::Smooth << std::endl; 37 | configFile << "ShowFovLine " << MenuConfig::ShowFovLine << std::endl; 38 | configFile << "ShowEyeRay " << MenuConfig::ShowEyeRay << std::endl; 39 | configFile << "ShowPlayerName " << MenuConfig::ShowPlayerName << std::endl; 40 | configFile << "AimBot " << MenuConfig::AimBot << std::endl; 41 | configFile << "AimPosition " << MenuConfig::AimPosition << std::endl; 42 | configFile << "AimPositionIndex " << MenuConfig::AimPositionIndex << std::endl; 43 | configFile << "HealthBarType " << MenuConfig::HealthBarType << std::endl; 44 | configFile << "BoneColor " << MenuConfig::BoneColor.Value.x << " " << MenuConfig::BoneColor.Value.y << " " << MenuConfig::BoneColor.Value.z << " " << MenuConfig::BoneColor.Value.w << std::endl; 45 | configFile << "FovLineColor " << MenuConfig::FovLineColor.Value.x << " " << MenuConfig::FovLineColor.Value.y << " " << MenuConfig::FovLineColor.Value.z << " " << MenuConfig::FovLineColor.Value.w << std::endl; 46 | configFile << "LineToEnemyColor " << MenuConfig::LineToEnemyColor.Value.x << " " << MenuConfig::LineToEnemyColor.Value.y << " " << MenuConfig::LineToEnemyColor.Value.z << " " << MenuConfig::LineToEnemyColor.Value.w << std::endl; 47 | configFile << "BoxColor " << MenuConfig::BoxColor.Value.x << " " << MenuConfig::BoxColor.Value.y << " " << MenuConfig::BoxColor.Value.z << " " << MenuConfig::BoxColor.Value.w << std::endl; 48 | configFile << "EyeRayColor " << MenuConfig::EyeRayColor.Value.x << " " << MenuConfig::EyeRayColor.Value.y << " " << MenuConfig::EyeRayColor.Value.z << " " << MenuConfig::EyeRayColor.Value.w << std::endl; 49 | configFile << "RadarCrossLineColor " << MenuConfig::RadarCrossLineColor.Value.x << " " << MenuConfig::RadarCrossLineColor.Value.y << " " << MenuConfig::RadarCrossLineColor.Value.z << " " << MenuConfig::RadarCrossLineColor.Value.w << std::endl; 50 | configFile << "HeadShootLineColor " << MenuConfig::HeadShootLineColor.Value.x << " " << MenuConfig::HeadShootLineColor.Value.y << " " << MenuConfig::HeadShootLineColor.Value.z << " " << MenuConfig::HeadShootLineColor.Value.w << std::endl; 51 | configFile << "ShowMenu " << MenuConfig::ShowMenu << std::endl; 52 | configFile << "ShowRadar " << MenuConfig::ShowRadar << std::endl; 53 | configFile << "RadarRange " << MenuConfig::RadarRange << std::endl; 54 | configFile << "RadarPointSizeProportion " << MenuConfig::RadarPointSizeProportion << std::endl; 55 | configFile << "ShowCrossLine " << MenuConfig::ShowRadarCrossLine << std::endl; 56 | configFile << "RadarType " << MenuConfig::RadarType << std::endl; 57 | configFile << "Proportion " << MenuConfig::Proportion << std::endl; 58 | configFile << "BoxType " << MenuConfig::BoxType << std::endl; 59 | configFile << "TriggerBot " << MenuConfig::TriggerBot << std::endl; 60 | configFile << "TeamCheck " << MenuConfig::TeamCheck << std::endl; 61 | configFile << "VisibleCheck " << MenuConfig::VisibleCheck << std::endl; 62 | configFile << "ShowHeadShootLine " << MenuConfig::ShowHeadShootLine << std::endl; 63 | configFile << "ShowCrossHair " << MenuConfig::ShowCrossHair << std::endl; 64 | configFile << "CrossHairColor " << MenuConfig::CrossHairColor.Value.x << " " << MenuConfig::CrossHairColor.Value.y << " " << MenuConfig::CrossHairColor.Value.z << " " << MenuConfig::CrossHairColor.Value.w << std::endl; 65 | configFile << "CrossHairSize " << MenuConfig::CrossHairSize << std::endl; 66 | configFile << "ShowAimFovRange " << MenuConfig::ShowAimFovRange << std::endl; 67 | configFile << "AimFovRangeColor " << MenuConfig::AimFovRangeColor.Value.x << " " << MenuConfig::AimFovRangeColor.Value.y << " " << MenuConfig::AimFovRangeColor.Value.z << " " << MenuConfig::AimFovRangeColor.Value.w << std::endl; 68 | configFile << "OBSBypass " << MenuConfig::OBSBypass; 69 | configFile << "BunnyHop " << MenuConfig::BunnyHop; 70 | configFile << "ShowWhenSpec " << MenuConfig::ShowWhenSpec; 71 | configFile << "AntiFlashbang " << MenuConfig::AntiFlashbang; 72 | configFile.close(); 73 | std::cout << "Configuration saved to " << MenuConfig::path + '/' + filename << std::endl; 74 | } 75 | 76 | // Function to load the configuration from a file 77 | void LoadConfig(const std::string& filename) { 78 | std::ifstream configFile(MenuConfig::path + '/' + filename); 79 | if (!configFile.is_open()) { 80 | std::cerr << "Error: Could not open the configuration file." << std::endl; 81 | return; 82 | } 83 | 84 | std::string line; 85 | while (std::getline(configFile, line)) { 86 | std::istringstream iss(line); 87 | std::string key; 88 | if (iss >> key) { 89 | if (key == "ShowBoneESP") iss >> MenuConfig::ShowBoneESP; 90 | else if (key == "TriggerDelay") iss >> TriggerBot::TriggerDelay; 91 | else if (key == "ShowBoxESP") iss >> MenuConfig::ShowBoxESP; 92 | else if (key == "TriggerHotKey") { iss >> MenuConfig::TriggerHotKey; TriggerBot::SetHotKey(MenuConfig::TriggerHotKey); } 93 | else if (key == "TriggerMode") { iss >> MenuConfig::TriggerMode; TriggerBot::SetMode(MenuConfig::TriggerMode); }//TriggerMode 94 | else if (key == "RCSBullet") iss >> AimControl::RCSBullet; 95 | else if (key == "ShowHealthBar") iss >> MenuConfig::ShowHealthBar; 96 | else if (key == "AimFov") iss >> AimControl::AimFov; 97 | else if (key == "FovLineSize") iss >> MenuConfig::FovLineSize; 98 | else if (key == "AimBotHotKey") { iss >> MenuConfig::AimBotHotKey; AimControl::SetHotKey(MenuConfig::AimBotHotKey); } 99 | else if (key == "ShowLineToEnemy") iss >> MenuConfig::ShowLineToEnemy; 100 | else if (key == "RCSScale.x") iss >> AimControl::RCSScale.x; 101 | else if (key == "RCSScale.y") iss >> AimControl::RCSScale.y; 102 | else if (key == "ShowWeaponESP") iss >> MenuConfig::ShowWeaponESP; 103 | else if (key == "ShowDistance") iss >> MenuConfig::ShowDistance; 104 | else if (key == "Smooth") iss >> AimControl::Smooth; 105 | else if (key == "ShowFovLine") iss >> MenuConfig::ShowFovLine; 106 | else if (key == "ShowEyeRay") iss >> MenuConfig::ShowEyeRay; 107 | else if (key == "ShowPlayerName") iss >> MenuConfig::ShowPlayerName; 108 | else if (key == "AimBot") iss >> MenuConfig::AimBot; 109 | else if (key == "AimPosition") iss >> MenuConfig::AimPosition; 110 | else if (key == "AimPositionIndex") iss >> MenuConfig::AimPositionIndex; 111 | else if (key == "HealthBarType") iss >> MenuConfig::HealthBarType; 112 | else if (key == "BoneColor") iss >> MenuConfig::BoneColor.Value.x >> MenuConfig::BoneColor.Value.y >> MenuConfig::BoneColor.Value.z >> MenuConfig::BoneColor.Value.w; 113 | else if (key == "FovLineColor") iss >> MenuConfig::FovLineColor.Value.x >> MenuConfig::FovLineColor.Value.y >> MenuConfig::FovLineColor.Value.z >> MenuConfig::FovLineColor.Value.w; 114 | else if (key == "LineToEnemyColor") iss >> MenuConfig::LineToEnemyColor.Value.x >> MenuConfig::LineToEnemyColor.Value.y >> MenuConfig::LineToEnemyColor.Value.z >> MenuConfig::LineToEnemyColor.Value.w; 115 | else if (key == "BoxColor") iss >> MenuConfig::BoxColor.Value.x >> MenuConfig::BoxColor.Value.y >> MenuConfig::BoxColor.Value.z >> MenuConfig::BoxColor.Value.w; 116 | else if (key == "EyeRayColor") iss >> MenuConfig::EyeRayColor.Value.x >> MenuConfig::EyeRayColor.Value.y >> MenuConfig::EyeRayColor.Value.z >> MenuConfig::EyeRayColor.Value.w; 117 | else if (key == "CrossLineColor") iss >> MenuConfig::RadarCrossLineColor.Value.x >> MenuConfig::RadarCrossLineColor.Value.y >> MenuConfig::RadarCrossLineColor.Value.z >> MenuConfig::RadarCrossLineColor.Value.w; 118 | else if (key == "HeadShootLineColor") iss >> MenuConfig::HeadShootLineColor.Value.x >> MenuConfig::HeadShootLineColor.Value.y >> MenuConfig::HeadShootLineColor.Value.z >> MenuConfig::HeadShootLineColor.Value.w; 119 | else if (key == "ShowMenu") iss >> MenuConfig::ShowMenu; 120 | else if (key == "ShowRadar") iss >> MenuConfig::ShowRadar; 121 | else if (key == "RadarRange") iss >> MenuConfig::RadarRange; 122 | else if (key == "RadarPointSizeProportion") iss >> MenuConfig::RadarPointSizeProportion; 123 | else if (key == "ShowCrossLine") iss >> MenuConfig::ShowRadarCrossLine; 124 | else if (key == "RadarType") iss >> MenuConfig::RadarType; 125 | else if (key == "Proportion") iss >> MenuConfig::Proportion; 126 | else if (key == "BoxType") iss >> MenuConfig::BoxType; 127 | else if (key == "TriggerBot") iss >> MenuConfig::TriggerBot; 128 | else if (key == "TeamCheck") iss >> MenuConfig::TeamCheck; 129 | else if (key == "VisibleCheck") iss >> MenuConfig::VisibleCheck; 130 | else if (key == "ShowHeadShootLine") iss >> MenuConfig::ShowHeadShootLine; 131 | else if (key == "ShowCrossHair") iss >> MenuConfig::ShowCrossHair; 132 | else if (key == "CrossHairColor") iss >> MenuConfig::CrossHairColor.Value.x >> MenuConfig::CrossHairColor.Value.y >> MenuConfig::CrossHairColor.Value.z >> MenuConfig::CrossHairColor.Value.w; 133 | else if (key == "CrossHairSize") iss >> MenuConfig::CrossHairSize; 134 | else if (key == "ShowAimFovRange") iss >> MenuConfig::ShowAimFovRange; 135 | else if (key == "AimFovRangeColor") iss >> MenuConfig::AimFovRangeColor.Value.x >> MenuConfig::AimFovRangeColor.Value.y >> MenuConfig::AimFovRangeColor.Value.z >> MenuConfig::AimFovRangeColor.Value.w; 136 | else if (key == "OBSBypass") iss >> MenuConfig::OBSBypass; 137 | else if (key == "BunnyHop") iss >> MenuConfig::BunnyHop; 138 | else if (key == "ShowWhenSpec") iss >> MenuConfig::ShowWhenSpec; 139 | else if (key == "AntiFlashbang") iss >> MenuConfig::AntiFlashbang; 140 | } 141 | } 142 | 143 | configFile.close(); 144 | std::cout << "Configuration loaded from " << MenuConfig::path + '/' + filename << std::endl; 145 | } 146 | } // namespace ConfigSaver 147 | -------------------------------------------------------------------------------- /CS2_External/Utils/ConfigSaver.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MyConfigSaver { 6 | extern void SaveConfig(const std::string& filename); 7 | extern void LoadConfig(const std::string& filename); 8 | } 9 | -------------------------------------------------------------------------------- /CS2_External/Utils/Format.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | template 5 | inline std::string Format(const char* pFormat, Args...args) 6 | { 7 | int Length = std::snprintf(nullptr, 0, pFormat, args...); 8 | if (Length <= 0) 9 | return ""; 10 | char* Str = new char[Length + 1]; 11 | std::string Result; 12 | std::snprintf(Str, Length + 1, pFormat, args...); 13 | Result = std::string(Str); 14 | delete[] Str; 15 | return Result; 16 | } -------------------------------------------------------------------------------- /CS2_External/Utils/MemorySearch.cpp: -------------------------------------------------------------------------------- 1 | #include "ProcessManager.hpp" 2 | #include 3 | 4 | inline const DWORD BLOCKMAXSIZE = 409600; 5 | 6 | 7 | int GetSignatureArray(const std::string& Signature, std::vector& SignatureArray) 8 | { 9 | std::string Sig = Signature; 10 | Sig.erase(std::remove(Sig.begin(), Sig.end(), ' '), Sig.end()); 11 | 12 | std::size_t Size = Sig.size(); 13 | 14 | if (Size % 2 != 0) 15 | return 0; 16 | 17 | for (int i = 0; i < Size; i += 2) 18 | { 19 | std::string ByteString = Sig.substr(i, 2); 20 | WORD Byte = (ByteString == "??") ? 256 : std::stoi(ByteString, nullptr, 16); 21 | SignatureArray.push_back(Byte); 22 | } 23 | return SignatureArray.size(); 24 | } 25 | 26 | void GetNextArray(std::vector& NextArray, const std::vector& SignatureArray) 27 | { 28 | std::size_t Size = SignatureArray.size(); 29 | for (int i = 0; i < Size; i++) 30 | NextArray[SignatureArray[i]] = i; 31 | } 32 | 33 | void SearchMemoryBlock(byte* MemoryBuffer, const std::vector& NextArray, const std::vector& SignatureArray, DWORD64 StartAddress, DWORD Size, std::vector& ResultArray) 34 | { 35 | if (!ProcessMgr.ReadMemory(StartAddress, *MemoryBuffer, Size)) 36 | return; 37 | 38 | int SignatureLength = SignatureArray.size(); 39 | 40 | for (int i = 0, j, k; i < Size;) 41 | { 42 | j = i; k = 0; 43 | 44 | for (; k < SignatureLength && j < Size && (SignatureArray[k] == MemoryBuffer[j] || SignatureArray[k] == 256); k++, j++); 45 | 46 | if (k == SignatureLength) 47 | ResultArray.push_back(StartAddress + i); 48 | 49 | if ((i + SignatureLength) >= Size) 50 | return; 51 | 52 | int Num = NextArray[MemoryBuffer[i + SignatureLength]]; 53 | if (Num == -1) 54 | i += (SignatureLength - NextArray[256]); 55 | else 56 | i += (SignatureLength - Num); 57 | } 58 | } 59 | 60 | std::vector ProcessManager::SearchMemory(const std::string& Signature, DWORD64 StartAddress, DWORD64 EndAddress, int SearchNum) 61 | { 62 | std::vector ResultArray; 63 | std::vector SignatureArray; 64 | std::vector NextArray(260, -1); 65 | 66 | byte* MemoryBuffer = new byte[BLOCKMAXSIZE]; 67 | 68 | if (GetSignatureArray(Signature, SignatureArray) <= 0) 69 | return ResultArray; 70 | 71 | GetNextArray(NextArray, SignatureArray); 72 | 73 | MEMORY_BASIC_INFORMATION mbi; 74 | int Count; 75 | while (VirtualQueryEx(hProcess, reinterpret_cast(StartAddress), &mbi, sizeof(mbi)) != 0) 76 | { 77 | Count = 0; 78 | auto BlockSize = mbi.RegionSize; 79 | 80 | while (BlockSize >= BLOCKMAXSIZE) 81 | { 82 | if (ResultArray.size() >= SearchNum) 83 | goto END; 84 | 85 | SearchMemoryBlock(MemoryBuffer, NextArray, SignatureArray, StartAddress + (BLOCKMAXSIZE * Count), BLOCKMAXSIZE, ResultArray); 86 | 87 | BlockSize -= BLOCKMAXSIZE; 88 | Count++; 89 | } 90 | 91 | SearchMemoryBlock(MemoryBuffer, NextArray, SignatureArray, StartAddress + (BLOCKMAXSIZE * Count), BlockSize, ResultArray); 92 | 93 | StartAddress += mbi.RegionSize; 94 | 95 | if (ResultArray.size() >= SearchNum || EndAddress != 0 && StartAddress > EndAddress) 96 | break; 97 | } 98 | 99 | END: 100 | 101 | delete[] MemoryBuffer; 102 | return ResultArray; 103 | } 104 | -------------------------------------------------------------------------------- /CS2_External/Utils/ProcessManager.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/Utils/ProcessManager.hpp -------------------------------------------------------------------------------- /CS2_External/View.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/CS2_External/View.hpp -------------------------------------------------------------------------------- /CS2_External/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Offsets.h" 2 | #include "Cheats.h" 3 | #include "Utils/Format.hpp" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace fs = std::filesystem; 12 | 13 | int main() 14 | { 15 | auto ProcessStatus = ProcessMgr.Attach("cs2.exe"); 16 | char documentsPath[MAX_PATH]; 17 | if (SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, documentsPath) != S_OK) { 18 | std::cerr << "Failed to get the Documents folder path." << std::endl; 19 | goto END; 20 | } 21 | MenuConfig::path = documentsPath; 22 | MenuConfig::path += "/CS2_External"; 23 | 24 | if (ProcessStatus != StatusCode::SUCCEED) 25 | { 26 | std::cout << "[ERROR] Failed to attach process, StatusCode:" << ProcessStatus << std::endl; 27 | goto END; 28 | } 29 | 30 | if (!Offset::UpdateOffsets()) 31 | { 32 | std::cout << "[ERROR] Failed to update offsets." << std::endl; 33 | goto END; 34 | } 35 | 36 | if (!gGame.InitAddress()) 37 | { 38 | std::cout << "[ERROR] Failed to call InitAddress()."<< std::endl; 39 | goto END; 40 | } 41 | 42 | std::cout << Format("[Game] Pid:%d\n", ProcessMgr.ProcessID); 43 | std::cout << Format("[Game] Client:%llX\n", gGame.GetClientDLLAddress()); 44 | 45 | std::cout << "Offset:" << std::endl; 46 | std::cout << Format("--EntityList:%llX\n", Offset::EntityList); 47 | std::cout << Format("--Matrix:%llX\n", Offset::Matrix); 48 | std::cout << Format("--LocalPlayerController:%llX\n", Offset::LocalPlayerController); 49 | std::cout << Format("--ViewAngles:%llX\n", Offset::ViewAngle); 50 | std::cout << Format("--LocalPlayerPawn:%llX\n", Offset::LocalPlayerPawn); 51 | std::cout << Format("--ForceJump:%llX\n", Offset::ForceJump); 52 | 53 | 54 | if (fs::exists(MenuConfig::path)) 55 | std::cout << "Config folder connected: "<< MenuConfig::path << std::endl; 56 | else 57 | { 58 | if (fs::create_directory(MenuConfig::path)) 59 | std::cout << "Config folder created: " << MenuConfig::path << std::endl; 60 | else 61 | { 62 | std::cerr << "Failed to create the config directory." << std::endl; 63 | goto END; 64 | } 65 | } 66 | 67 | std::cout << "Runing..." << std::endl; 68 | 69 | try 70 | { 71 | Gui.AttachAnotherWindow("Counter-Strike 2", "SDL_app", Cheats::Run); 72 | } 73 | catch (OSImGui::OSException& e) 74 | { 75 | std::cout << e.what() << std::endl; 76 | } 77 | 78 | END: 79 | system("pause"); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /Image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TKazer/CS2_External/b7e3b41687ce6ba798975741d9a9755249d1b65c/Image2.png -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [year] [fullname] 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 | # CS2_External 2 | CS2 external cheat. 3 | 4 | 5 | Analysis and implementation of CS2 external silent aimbot 6 | 7 | EN -> [SilentAimbot - en](https://github.com/TKazer/CS2-External-Silent-AimBot) 8 | 9 | CN -> [SilentAimbot - cn](https://bbs.kanxue.com/thread-282616.htm) 10 | 11 | ## ImGui library -> [OS-ImGui](https://github.com/TKazer/OS-ImGui) 12 | 13 | ## Derivative projects 14 | 1. AimStar -> [AimStar](https://github.com/CowNowK/AimStar) (By CowNow.) 15 | 2. Aeonix -> [Aeonix](https://github.com/Fr0go1/Aeonix-Cs2) (By Fr0go1.) 16 | 17 | ## NOTICE 18 | 19 | This source just used to study how to code a simple CS2 external hack systematically. 20 | 21 | 这个源码仅供学习如何系统的写一套CS2外部辅助程序。 22 | 23 | The offsets will not be updated in the future, please update it by self. 24 | 25 | 后续偏移数据将不在提供更新,请自行更新。 26 | 27 | 28 | 29 | ## Functions 30 | 31 | > 1. BoneESP 32 | > 33 | > 2. BoxESP 34 | > 35 | > 3. AimBot (With rcs) 36 | > 37 | > 4. EyeLine 38 | > 39 | > 5. Auto update offsets 40 | > 41 | > 6. weaponESP 42 | > 43 | > 7. Radar 44 | > 45 | > 8. TriggerBot 46 | > 47 | > 9. HeadShoot Line 48 | > 49 | > 10. Fov Line 50 | > 51 | > 11. Visibility Check 52 | > 53 | > 12. OBS Bypass 54 | > 55 | > 13. Bhop 56 | --------------------------------------------------------------------------------