├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── helldiversmenu.filters ├── helldiversmenu.sln ├── helldiversmenu.vcxproj ├── helldiversmenu.vcxproj.filters ├── screenshot.png └── src ├── dllmain.cpp ├── framework ├── SignatureScan.hpp ├── app-functions.cpp ├── app-functions.h ├── version.cpp ├── version.def └── version.h ├── gui ├── menu.cpp └── menu.h ├── hooks ├── _hooks.cpp ├── _hooks.h ├── app.cpp ├── directx.cpp ├── user32.cpp └── winuser.cpp ├── include ├── detours │ ├── detours.cpp │ ├── detours.h │ ├── disasm.cpp │ └── modules.cpp ├── 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 └── oxorany │ ├── oxorany.cpp │ ├── oxorany.h │ └── oxorany_include.h └── user ├── globals.cpp ├── globals.h ├── main.cpp └── main.hpp /.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 | [Rr]elease_[Xx]input/ 21 | [Rr]elease_[Vv]ersion/ 22 | [Dd]ebug_[Xx]input/ 23 | [Dd]ebug_[Vv]ersion/ 24 | [Dd]ebug/ 25 | [Dd]ebugPublic/ 26 | [Rr]elease/ 27 | [Rr]eleases/ 28 | x64/ 29 | x86/ 30 | [Aa][Rr][Mm]/ 31 | [Aa][Rr][Mm]64/ 32 | bld/ 33 | [Bb]in/ 34 | [Oo]bj/ 35 | [Ll]og/ 36 | [Ll]ogs/ 37 | 38 | # Visual Studio 2015/2017 cache/options directory 39 | .vs/ 40 | # Uncomment if you have tasks that create the project's static files in wwwroot 41 | #wwwroot/ 42 | 43 | # Visual Studio 2017 auto generated files 44 | Generated\ Files/ 45 | 46 | # MSTest test Results 47 | [Tt]est[Rr]esult*/ 48 | [Bb]uild[Ll]og.* 49 | 50 | # NUnit 51 | *.VisualState.xml 52 | TestResult.xml 53 | nunit-*.xml 54 | 55 | # Build Results of an ATL Project 56 | [Dd]ebugPS/ 57 | [Rr]eleasePS/ 58 | dlldata.c 59 | 60 | # Benchmark Results 61 | BenchmarkDotNet.Artifacts/ 62 | 63 | # .NET Core 64 | project.lock.json 65 | project.fragment.lock.json 66 | artifacts/ 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.vspscc 94 | *.vssscc 95 | .builds 96 | *.pidb 97 | *.svclog 98 | *.scc 99 | 100 | # Chutzpah Test files 101 | _Chutzpah* 102 | 103 | # Visual C++ cache files 104 | ipch/ 105 | *.aps 106 | *.ncb 107 | *.opendb 108 | *.opensdf 109 | *.sdf 110 | *.cachefile 111 | *.VC.db 112 | *.VC.VC.opendb 113 | 114 | # Visual Studio profiler 115 | *.psess 116 | *.vsp 117 | *.vspx 118 | *.sap 119 | 120 | # Visual Studio Trace Files 121 | *.e2e 122 | 123 | # TFS 2012 Local Workspace 124 | $tf/ 125 | 126 | # Guidance Automation Toolkit 127 | *.gpState 128 | 129 | # ReSharper is a .NET coding add-in 130 | _ReSharper*/ 131 | *.[Rr]e[Ss]harper 132 | *.DotSettings.user 133 | 134 | # TeamCity is a build add-in 135 | _TeamCity* 136 | 137 | # DotCover is a Code Coverage Tool 138 | *.dotCover 139 | 140 | # AxoCover is a Code Coverage Tool 141 | .axoCover/* 142 | !.axoCover/settings.json 143 | 144 | # Visual Studio code coverage results 145 | *.coverage 146 | *.coveragexml 147 | 148 | # NCrunch 149 | _NCrunch_* 150 | .*crunch*.local.xml 151 | nCrunchTemp_* 152 | 153 | # MightyMoose 154 | *.mm.* 155 | AutoTest.Net/ 156 | 157 | # Web workbench (sass) 158 | .sass-cache/ 159 | 160 | # Installshield output folder 161 | [Ee]xpress/ 162 | 163 | # DocProject is a documentation generator add-in 164 | DocProject/buildhelp/ 165 | DocProject/Help/*.HxT 166 | DocProject/Help/*.HxC 167 | DocProject/Help/*.hhc 168 | DocProject/Help/*.hhk 169 | DocProject/Help/*.hhp 170 | DocProject/Help/Html2 171 | DocProject/Help/html 172 | 173 | # Click-Once directory 174 | publish/ 175 | 176 | # Publish Web Output 177 | *.[Pp]ublish.xml 178 | *.azurePubxml 179 | # Note: Comment the next line if you want to checkin your web deploy settings, 180 | # but database connection strings (with potential passwords) will be unencrypted 181 | *.pubxml 182 | *.publishproj 183 | 184 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 185 | # checkin your Azure Web App publish settings, but sensitive information contained 186 | # in these scripts will be unencrypted 187 | PublishScripts/ 188 | 189 | # NuGet Packages 190 | *.nupkg 191 | # NuGet Symbol Packages 192 | *.snupkg 193 | # The packages folder can be ignored because of Package Restore 194 | **/[Pp]ackages/* 195 | # except build/, which is used as an MSBuild target. 196 | !**/[Pp]ackages/build/ 197 | # Uncomment if necessary however generally it will be regenerated when needed 198 | #!**/[Pp]ackages/repositories.config 199 | # NuGet v3's project.json files produces more ignorable files 200 | *.nuget.props 201 | *.nuget.targets 202 | 203 | # Microsoft Azure Build Output 204 | csx/ 205 | *.build.csdef 206 | 207 | # Microsoft Azure Emulator 208 | ecf/ 209 | rcf/ 210 | 211 | # Windows Store app package directories and files 212 | AppPackages/ 213 | BundleArtifacts/ 214 | Package.StoreAssociation.xml 215 | _pkginfo.txt 216 | *.appx 217 | *.appxbundle 218 | *.appxupload 219 | 220 | # Visual Studio cache files 221 | # files ending in .cache can be ignored 222 | *.[Cc]ache 223 | # but keep track of directories ending in .cache 224 | !?*.[Cc]ache/ 225 | 226 | # Others 227 | ClientBin/ 228 | ~$* 229 | *~ 230 | *.dbmdl 231 | *.dbproj.schemaview 232 | *.jfm 233 | *.pfx 234 | *.publishsettings 235 | orleans.codegen.cs 236 | 237 | # Including strong name files can present a security risk 238 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 239 | #*.snk 240 | 241 | # Since there are multiple workflows, uncomment next line to ignore bower_components 242 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 243 | #bower_components/ 244 | 245 | # RIA/Silverlight projects 246 | Generated_Code/ 247 | 248 | # Backup & report files from converting an old project file 249 | # to a newer Visual Studio version. Backup files are not needed, 250 | # because we have git ;-) 251 | _UpgradeReport_Files/ 252 | Backup*/ 253 | UpgradeLog*.XML 254 | UpgradeLog*.htm 255 | ServiceFabricBackup/ 256 | *.rptproj.bak 257 | 258 | # SQL Server files 259 | *.mdf 260 | *.ldf 261 | *.ndf 262 | 263 | # Business Intelligence projects 264 | *.rdl.data 265 | *.bim.layout 266 | *.bim_*.settings 267 | *.rptproj.rsuser 268 | *- [Bb]ackup.rdl 269 | *- [Bb]ackup ([0-9]).rdl 270 | *- [Bb]ackup ([0-9][0-9]).rdl 271 | 272 | # Microsoft Fakes 273 | FakesAssemblies/ 274 | 275 | # GhostDoc plugin setting file 276 | *.GhostDoc.xml 277 | 278 | # Node.js Tools for Visual Studio 279 | .ntvs_analysis.dat 280 | node_modules/ 281 | 282 | # Visual Studio 6 build log 283 | *.plg 284 | 285 | # Visual Studio 6 workspace options file 286 | *.opt 287 | 288 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 289 | *.vbw 290 | 291 | # Visual Studio LightSwitch build output 292 | **/*.HTMLClient/GeneratedArtifacts 293 | **/*.DesktopClient/GeneratedArtifacts 294 | **/*.DesktopClient/ModelManifest.xml 295 | **/*.Server/GeneratedArtifacts 296 | **/*.Server/ModelManifest.xml 297 | _Pvt_Extensions 298 | 299 | # Paket dependency manager 300 | .paket/paket.exe 301 | paket-files/ 302 | 303 | # FAKE - F# Make 304 | .fake/ 305 | 306 | # CodeRush personal settings 307 | .cr/personal 308 | 309 | # Python Tools for Visual Studio (PTVS) 310 | __pycache__/ 311 | *.pyc 312 | 313 | # Cake - Uncomment if you are using it 314 | # tools/** 315 | # !tools/packages.config 316 | 317 | # Tabs Studio 318 | *.tss 319 | 320 | # Telerik's JustMock configuration file 321 | *.jmconfig 322 | 323 | # BizTalk build output 324 | *.btp.cs 325 | *.btm.cs 326 | *.odx.cs 327 | *.xsd.cs 328 | 329 | # OpenCover UI analysis results 330 | OpenCover/ 331 | 332 | # Azure Stream Analytics local run output 333 | ASALocalRun/ 334 | 335 | # MSBuild Binary and Structured Log 336 | *.binlog 337 | 338 | # NVidia Nsight GPU debugger configuration file 339 | *.nvuser 340 | 341 | # MFractors (Xamarin productivity tool) working folder 342 | .mfractor/ 343 | 344 | # Local History for Visual Studio 345 | .localhistory/ 346 | 347 | # BeatPulse healthcheck temp database 348 | healthchecksdb 349 | 350 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 351 | MigrationBackup/ 352 | 353 | # Ionide (cross platform F# VS Code tools) working folder 354 | .ionide/ 355 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Helldivers2Menu 2 | 3 |

4 | Helldivers2Menu is a Cheat Menu for the popular Game Helldivers 2. 5 |

6 | 7 | ## Disclaimer 8 | This project is for Educational Use only. We do not condone this software being used to gain an advantage against other people. I made this project for my university project to show how cheating software works and how it is possible to block these manipulations in the future. 9 | 10 | ## Compile (Configurations) 11 | Please compile the project in **Release** mode. Debug does not work properly and gets detected by GG. 12 | 13 | ### Version Proxy (version.dll) 14 | Will automatically be loaded by the Game itself if the dll is in the game directory. 15 | 16 | ### How to Run 17 | 1. Move the `version.dll` into the game directory in `/bin` 18 | 2. Change the Launch Options in Steam for the game into `--use-d3d11` 19 | 3. Start the game 20 | 4. Press DELETE to show the menu 21 | 5. For performance increase, change into fullscreen mode (Dx11 being funky in HD2) 22 | 23 | ### Running on Proton (Version Proxy Only) 24 | First you will need protontricks, you can install it with your packager of choice. 25 | 26 | 1. Make sure you are running Helddivers 2 under Proton 27 | You can check by going to **Properties -> Compatibility** 28 | 3. Put version.dll into Helldivers 2 bin folder 29 | 4. Run `protontricks --gui` 30 | 5. Choose **HELLDIVERS 2** 31 | 6. Click on **Select the default wineprefix** and then **OK** 32 | 7. Click on **Run winecfg** and then **OK** 33 | 8. In the configuration window, click on **Libraries** 34 | 9. Type `version` into the **New override for library** input 35 | 10. Click **Add** and then **Apply** 36 | 11. Helldivers2Menu should now work properly in the game 37 | 38 | ### Default Hotkeys 39 | - Show Menu - DELETE 40 | 41 | ## Screenshot 42 |

43 | 44 |

45 | 46 | ## Contributing 47 | 1. Fork it () 48 | 2. Create your feature branch (`git checkout -b feature/fooBar`) 49 | 3. Commit your changes (`git commit -am 'Add some fooBar'`) 50 | 4. Push to the branch (`git push origin feature/fooBar`) 51 | 5. Create a new Pull Request 52 | -------------------------------------------------------------------------------- /helldiversmenu.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {d7687751-5a1d-4d58-8f04-33897a366d64} 10 | 11 | 12 | 13 | 14 | src 15 | 16 | 17 | src 18 | 19 | 20 | src 21 | 22 | 23 | src 24 | 25 | 26 | src 27 | 28 | 29 | src 30 | 31 | 32 | src 33 | 34 | 35 | 36 | 37 | src 38 | 39 | 40 | 41 | 42 | headers 43 | 44 | 45 | headers 46 | 47 | 48 | headers 49 | 50 | 51 | headers 52 | 53 | 54 | headers 55 | 56 | 57 | headers 58 | 59 | 60 | -------------------------------------------------------------------------------- /helldiversmenu.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34714.143 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "helldiversmenu", "helldiversmenu.vcxproj", "{0BDA66A5-D969-4AB0-A424-760B8FB01F97}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0BDA66A5-D969-4AB0-A424-760B8FB01F97}.Debug|x64.ActiveCfg = Debug|x64 15 | {0BDA66A5-D969-4AB0-A424-760B8FB01F97}.Debug|x64.Build.0 = Debug|x64 16 | {0BDA66A5-D969-4AB0-A424-760B8FB01F97}.Release|x64.ActiveCfg = Release|x64 17 | {0BDA66A5-D969-4AB0-A424-760B8FB01F97}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {80506ECF-1BCA-40B1-880B-3F2C27F40BAB} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /helldiversmenu.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 16.0 63 | Win32Proj 64 | {0bda66a5-d969-4ab0-a424-760b8fb01f97} 65 | versionproxy 66 | 10.0 67 | HellDivers2Menu 68 | 69 | 70 | 71 | DynamicLibrary 72 | false 73 | v143 74 | MultiByte 75 | 76 | 77 | DynamicLibrary 78 | false 79 | v143 80 | true 81 | MultiByte 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | true 96 | version 97 | $(IncludePath);$(WindowsSDK_IncludePath); 98 | $(SolutionDir)bin\$(Configuration)\ 99 | 100 | 101 | false 102 | version 103 | $(IncludePath);$(WindowsSDK_IncludePath); 104 | $(SolutionDir)bin\$(Configuration)\ 105 | 106 | 107 | 108 | Level3 109 | true 110 | _DEBUG;VERSIONPROXY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 111 | true 112 | NotUsing 113 | 114 | 115 | stdcpp17 116 | stdc17 117 | $(ProjectDir)src\include;$(ProjectDir)src\include\detours;$(ProjectDir)src\include\oxorany;$(ProjectDir)src\include\imgui;$(ProjectDir)src\framework;$(ProjectDir)src\hooks;$(ProjectDir)src\user;$(ProjectDir)src\gui 118 | 119 | 120 | Windows 121 | true 122 | false 123 | src/framework/version.def 124 | true 125 | 126 | 127 | 128 | 129 | Level3 130 | true 131 | true 132 | true 133 | NDEBUG;VERSIONPROXY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 134 | true 135 | NotUsing 136 | 137 | 138 | stdcpp17 139 | stdc17 140 | $(ProjectDir)src\include;$(ProjectDir)src\include\detours;$(ProjectDir)src\include\oxorany;$(ProjectDir)src\include\imgui;$(ProjectDir)src\framework;$(ProjectDir)src\hooks;$(ProjectDir)src\user;$(ProjectDir)src\gui 141 | 142 | 143 | Windows 144 | true 145 | true 146 | false 147 | false 148 | src/framework/version.def 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /helldiversmenu.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | framework 7 | 8 | 9 | user 10 | 11 | 12 | include\detours 13 | 14 | 15 | include\detours 16 | 17 | 18 | include\detours 19 | 20 | 21 | include\oxorany 22 | 23 | 24 | hooks 25 | 26 | 27 | hooks 28 | 29 | 30 | user 31 | 32 | 33 | framework 34 | 35 | 36 | hooks 37 | 38 | 39 | include\imgui 40 | 41 | 42 | include\imgui 43 | 44 | 45 | include\imgui 46 | 47 | 48 | include\imgui 49 | 50 | 51 | include\imgui 52 | 53 | 54 | include\imgui 55 | 56 | 57 | include\imgui 58 | 59 | 60 | hooks 61 | 62 | 63 | gui 64 | 65 | 66 | hooks 67 | 68 | 69 | user 70 | 71 | 72 | 73 | 74 | {ebc59406-17ee-4758-87d1-73a480770097} 75 | 76 | 77 | {c0e0032a-5e93-4e3b-824f-719ceaeffa67} 78 | 79 | 80 | {eeb2d3f9-6e09-4248-897d-65959085307c} 81 | 82 | 83 | {3986fcd2-670c-425c-a81b-395d2c870e00} 84 | 85 | 86 | {f19cc276-726b-4f5a-a0d1-c1c3b486a753} 87 | 88 | 89 | {3bce2a74-80a9-42bf-8bdd-aaf71af07b37} 90 | 91 | 92 | {e2b6fe7b-32c6-4907-b193-66e723a0f174} 93 | 94 | 95 | {92e030b2-d408-4f02-aba0-3687d61cdccc} 96 | 97 | 98 | 99 | 100 | framework 101 | 102 | 103 | framework 104 | 105 | 106 | user 107 | 108 | 109 | include\detours 110 | 111 | 112 | include\oxorany 113 | 114 | 115 | include\oxorany 116 | 117 | 118 | hooks 119 | 120 | 121 | framework 122 | 123 | 124 | include\imgui 125 | 126 | 127 | include\imgui 128 | 129 | 130 | include\imgui 131 | 132 | 133 | include\imgui 134 | 135 | 136 | include\imgui 137 | 138 | 139 | include\imgui 140 | 141 | 142 | include\imgui 143 | 144 | 145 | include\imgui 146 | 147 | 148 | gui 149 | 150 | 151 | 152 | 153 | framework 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitCrackers/Helldivers2Menu/1cd6f6f6e2fce2366edd0ca4e91206e556ea587f/screenshot.png -------------------------------------------------------------------------------- /src/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "version.h" 2 | 3 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { 4 | switch (ul_reason_for_call) { 5 | case DLL_PROCESS_ATTACH: 6 | { 7 | DisableThreadLibraryCalls(hModule); 8 | HANDLE moduleHandle = CreateThread(NULL, 0, Load, hModule, NULL, NULL); 9 | } 10 | break; 11 | case DLL_PROCESS_DETACH: 12 | FreeLibrary(version_dll); 13 | break; 14 | } 15 | return TRUE; 16 | } 17 | -------------------------------------------------------------------------------- /src/framework/SignatureScan.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define INRANGE(x, a, b) (x >= a && x <= b) 8 | #define getBits(x) (INRANGE((x&(~0x20)),'A','F') ? ((x&(~0x20)) - 'A' + 0xa) : (INRANGE(x,'0','9') ? x - '0' : 0)) 9 | #define getByte(x) (getBits(x[0]) << 4 | getBits(x[1])) 10 | 11 | template 12 | class SignatureScan 13 | { 14 | SignatureScan() { 15 | pointer = NULL; 16 | moduleHandle = nullptr; 17 | } 18 | uintptr_t pointer; 19 | HMODULE moduleHandle; 20 | int SignatureSize(const char* signature) { 21 | int count = 0, i = 0; 22 | char ch = signature[0]; 23 | while (ch != ' ') { 24 | ch = signature[i]; 25 | if (isspace(ch)) 26 | count++; 27 | i++; 28 | } 29 | return count; 30 | } 31 | uintptr_t FindSignature(uintptr_t pStart, uintptr_t pEnd, const char* signature) { 32 | const char* pattern = signature; 33 | uintptr_t pFirstMatch = 0; 34 | for (uintptr_t i = pStart; i < pEnd; i++) { 35 | if (!*pattern) return pFirstMatch; 36 | if (*(PBYTE)pattern == '\?' || *(BYTE*)i == getByte(pattern)) 37 | { 38 | if (!pFirstMatch) pFirstMatch = i; 39 | if (!pattern[2]) return pFirstMatch; 40 | if (*(PWORD)pattern == '\?\?' || *(PBYTE)pattern != '\?') pattern += 3; 41 | else pattern += 2; 42 | } 43 | else 44 | { 45 | pattern = signature; 46 | pFirstMatch = 0; 47 | } 48 | } 49 | return 0; 50 | } 51 | uintptr_t FindSignatures(const char* signature, size_t index) { 52 | MODULEINFO moduleInfo; 53 | GetModuleInformation(GetCurrentProcess(), moduleHandle, &moduleInfo, sizeof(MODULEINFO)); 54 | uintptr_t pStart = uintptr_t(moduleInfo.lpBaseOfDll); 55 | uintptr_t pEnd = pStart + moduleInfo.SizeOfImage; 56 | 57 | std::vector results; 58 | int signatureSize = SignatureSize(signature); 59 | 60 | while (true) { 61 | uintptr_t result = FindSignature(pStart, pEnd, signature); 62 | if (result != 0) { 63 | results.push_back(result); 64 | pStart = result + signatureSize; 65 | } 66 | else 67 | break; 68 | 69 | if (results.size() > index) 70 | return results[index]; 71 | } 72 | 73 | return 0; 74 | } 75 | public: 76 | SignatureScan(const char* signature, size_t index, HMODULE module) { 77 | moduleHandle = module; 78 | pointer = FindSignatures(signature, index); 79 | } 80 | SignatureScan(const char* signature, HMODULE module) : SignatureScan(signature, 0, module) {} 81 | operator T () { 82 | return (T)pointer; 83 | } 84 | operator uintptr_t () { 85 | return pointer; 86 | } 87 | SignatureScan OffsetPointer(int32_t value) { 88 | SignatureScan result; 89 | if (this->pointer != 0) { 90 | result.pointer = this->pointer; 91 | return result.Offset(value).ResolvePointer(); 92 | } 93 | return result; 94 | } 95 | SignatureScan Offset(int32_t value) { 96 | SignatureScan result; 97 | if (this->pointer != 0) { 98 | result.pointer = this->pointer + value; 99 | } 100 | return result; 101 | } 102 | SignatureScan ResolveCall() { 103 | SignatureScan result; 104 | if (this->pointer != 0) { 105 | int32_t pOffset = *(int32_t*)(this->pointer + 0x01); 106 | result.pointer = this->pointer + pOffset + 0x05; 107 | } 108 | return result; 109 | } 110 | SignatureScan ResolvePointer() { 111 | SignatureScan result; 112 | if (this->pointer != 0) { 113 | result.pointer = *(uint32_t*)(this->pointer); 114 | } 115 | return result; 116 | } 117 | }; -------------------------------------------------------------------------------- /src/framework/app-functions.cpp: -------------------------------------------------------------------------------- 1 | #include "app-functions.h" 2 | 3 | SET_CURSOR_POS_FUNCTION SetSysCursorPos = nullptr; 4 | D3D_PRESENT_FUNCTION Present = nullptr; 5 | 6 | PICKUP_SAMPLE_FUNCTION PickupSample = nullptr; 7 | IS_STRATAGEM_UNLOCKED_FUNCTION IsStratagemUnlocked = nullptr; 8 | IS_ARMOR_UNLOCKED_FUNCTION IsArmorUnlocked = nullptr; 9 | IS_EQUIPMENT_UNLOCKED_FUNCTION IsEquipmentUnlocked = nullptr; 10 | ROUTINE_DEPLOYMENT_TIME_FUNCTION RoutineDeploymentTime = nullptr; 11 | WEAPON_AMMO_REDUCTION_FUNCTION WeaponAmmoReduction = nullptr; 12 | STRATAGEM_REDUCTION_FUNCTION StratagemReduction = nullptr; 13 | STAMINA_REDUCTION_FUNCTION StaminaReduction = nullptr; 14 | ENEMY_MELEE_DAMAGE_FUNCTION EnemyBasicDamage = nullptr; 15 | -------------------------------------------------------------------------------- /src/framework/app-functions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #pragma comment(lib, "d3d11.lib") 4 | 5 | typedef BOOL(WINAPI* SET_CURSOR_POS_FUNCTION)(int X, int Y); 6 | extern SET_CURSOR_POS_FUNCTION SetSysCursorPos; 7 | 8 | typedef HRESULT(__fastcall* D3D_PRESENT_FUNCTION)(IDXGISwapChain* __this, UINT SyncInterval, UINT Flags); 9 | extern D3D_PRESENT_FUNCTION Present; 10 | 11 | typedef void(__fastcall* PICKUP_SAMPLE_FUNCTION)(__int64 a1, int a2, int a3, int a4); 12 | extern PICKUP_SAMPLE_FUNCTION PickupSample; 13 | 14 | typedef bool(__fastcall* IS_STRATAGEM_UNLOCKED_FUNCTION)(__int64 a1, int a2); 15 | extern IS_STRATAGEM_UNLOCKED_FUNCTION IsStratagemUnlocked; 16 | 17 | typedef bool(__fastcall* IS_ARMOR_UNLOCKED_FUNCTION)(int* a1); 18 | extern IS_ARMOR_UNLOCKED_FUNCTION IsArmorUnlocked; 19 | 20 | typedef bool(__fastcall* IS_EQUIPMENT_UNLOCKED_FUNCTION)(DWORD* a1, int a2); 21 | extern IS_EQUIPMENT_UNLOCKED_FUNCTION IsEquipmentUnlocked; 22 | 23 | typedef void(__fastcall* ROUTINE_DEPLOYMENT_TIME_FUNCTION)(__int64* a1, float a2); 24 | extern ROUTINE_DEPLOYMENT_TIME_FUNCTION RoutineDeploymentTime; 25 | 26 | typedef __int64(__fastcall* WEAPON_AMMO_REDUCTION_FUNCTION)(__int64 a1, unsigned int a2); 27 | extern WEAPON_AMMO_REDUCTION_FUNCTION WeaponAmmoReduction; 28 | 29 | typedef __int64(__fastcall* STRATAGEM_REDUCTION_FUNCTION)(__int64 a1, unsigned int a2, char a3, __int64 a4); 30 | extern STRATAGEM_REDUCTION_FUNCTION StratagemReduction; 31 | 32 | typedef void(__fastcall* STAMINA_REDUCTION_FUNCTION)(__int64 a1, int a2, float a3); 33 | extern STAMINA_REDUCTION_FUNCTION StaminaReduction; 34 | 35 | typedef void(__fastcall* ENEMY_MELEE_DAMAGE_FUNCTION)(__int64 a1, __int64 a2, unsigned int a3, int a4, unsigned int a5); 36 | extern ENEMY_MELEE_DAMAGE_FUNCTION EnemyBasicDamage; 37 | -------------------------------------------------------------------------------- /src/framework/version.cpp: -------------------------------------------------------------------------------- 1 | #include "version.h" 2 | #include "main.hpp" 3 | #include 4 | #include "oxorany.h" 5 | #include 6 | 7 | HMODULE version_dll = nullptr; 8 | 9 | #define WRAPPER_FUNC(name) o##name = GetProcAddress(version_dll, ###name) 10 | 11 | #pragma warning (disable: 4081) 12 | #define STRINGIFY(name) #name 13 | #define EXPORT_FUNCTION comment(linker, oxorany("/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)) 14 | #define WRAPPER_GENFUNC(name) \ 15 | FARPROC o##name; \ 16 | __declspec(dllexport) void WINAPI _##name() \ 17 | { \ 18 | __pragma(STRINGIFY(EXPORT_FUNCTION)); \ 19 | o##name(); \ 20 | } 21 | 22 | WRAPPER_GENFUNC(GetFileVersionInfoA) 23 | WRAPPER_GENFUNC(GetFileVersionInfoByHandle) 24 | WRAPPER_GENFUNC(GetFileVersionInfoExW) 25 | WRAPPER_GENFUNC(GetFileVersionInfoExA) 26 | WRAPPER_GENFUNC(GetFileVersionInfoSizeA) 27 | WRAPPER_GENFUNC(GetFileVersionInfoSizeExA) 28 | WRAPPER_GENFUNC(GetFileVersionInfoSizeExW) 29 | WRAPPER_GENFUNC(GetFileVersionInfoSizeW) 30 | WRAPPER_GENFUNC(GetFileVersionInfoW) 31 | WRAPPER_GENFUNC(VerFindFileA) 32 | WRAPPER_GENFUNC(VerFindFileW) 33 | WRAPPER_GENFUNC(VerInstallFileA) 34 | WRAPPER_GENFUNC(VerInstallFileW) 35 | WRAPPER_GENFUNC(VerLanguageNameA) 36 | WRAPPER_GENFUNC(VerLanguageNameW) 37 | WRAPPER_GENFUNC(VerQueryValueA) 38 | WRAPPER_GENFUNC(VerQueryValueW) 39 | 40 | void load_proxy() { 41 | char systemPath[MAX_PATH]; 42 | GetSystemDirectoryA(systemPath, MAX_PATH); 43 | 44 | strcat_s(systemPath, oxorany("\\version.dll")); 45 | version_dll = LoadLibraryA(systemPath); 46 | 47 | if (!version_dll) { 48 | return; 49 | } 50 | 51 | WRAPPER_FUNC(GetFileVersionInfoA); 52 | WRAPPER_FUNC(GetFileVersionInfoByHandle); 53 | WRAPPER_FUNC(GetFileVersionInfoExW); 54 | WRAPPER_FUNC(GetFileVersionInfoExA); 55 | WRAPPER_FUNC(GetFileVersionInfoSizeA); 56 | WRAPPER_FUNC(GetFileVersionInfoSizeExW); 57 | WRAPPER_FUNC(GetFileVersionInfoSizeExA); 58 | WRAPPER_FUNC(GetFileVersionInfoSizeW); 59 | WRAPPER_FUNC(GetFileVersionInfoW); 60 | WRAPPER_FUNC(VerFindFileA); 61 | WRAPPER_FUNC(VerFindFileW); 62 | WRAPPER_FUNC(VerInstallFileA); 63 | WRAPPER_FUNC(VerInstallFileW); 64 | WRAPPER_FUNC(VerLanguageNameA); 65 | WRAPPER_FUNC(VerLanguageNameW); 66 | WRAPPER_FUNC(VerQueryValueA); 67 | WRAPPER_FUNC(VerQueryValueW); 68 | } 69 | 70 | DWORD WINAPI Load(LPVOID lpParam) { 71 | load_proxy(); 72 | if (!version_dll) { 73 | return 0; 74 | } 75 | 76 | Run(lpParam); 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /src/framework/version.def: -------------------------------------------------------------------------------- 1 | LIBRARY "VERSION" 2 | EXPORTS 3 | 4 | GetFileVersionInfoA = _GetFileVersionInfoA 5 | GetFileVersionInfoByHandle = _GetFileVersionInfoByHandle 6 | GetFileVersionInfoExA = _GetFileVersionInfoExA 7 | GetFileVersionInfoExW = _GetFileVersionInfoExW 8 | GetFileVersionInfoSizeA = _GetFileVersionInfoSizeA 9 | GetFileVersionInfoSizeExA = _GetFileVersionInfoSizeExA 10 | GetFileVersionInfoSizeExW = _GetFileVersionInfoSizeExW 11 | GetFileVersionInfoSizeW = _GetFileVersionInfoSizeW 12 | GetFileVersionInfoW = _GetFileVersionInfoW 13 | VerFindFileA = _VerFindFileA 14 | VerFindFileW = _VerFindFileW 15 | VerInstallFileA = _VerInstallFileA 16 | VerInstallFileW = _VerInstallFileW 17 | VerLanguageNameA = _VerLanguageNameA 18 | VerLanguageNameW = _VerLanguageNameW 19 | VerQueryValueA = _VerQueryValueA 20 | VerQueryValueW = _VerQueryValueW 21 | -------------------------------------------------------------------------------- /src/framework/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define WIN32_LEAN_AND_MEAN 3 | #include 4 | 5 | extern HMODULE version_dll; 6 | DWORD WINAPI Load(LPVOID lpParam); 7 | -------------------------------------------------------------------------------- /src/gui/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.h" 2 | #include "imgui.h" 3 | #include "globals.h" 4 | 5 | void Menu::Render() { 6 | ImGui::Begin("Helldivers2Menu", &ShowMenu, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar); 7 | ImGui::SetWindowSize(ImVec2(300, 300)); 8 | 9 | ImGui::Checkbox("Modify Sample Pickup Amount", &fManipulateSamplePickup); 10 | ImGui::DragInt("##sampleamount", &SampleAmount, 1.0f, 1, 50); 11 | 12 | ImGui::Separator(); 13 | 14 | ImGui::Checkbox("Unlock All Stratagems", &fStratagemUnlock); 15 | ImGui::Checkbox("Unlock All Armor", &fArmorUnlock); 16 | ImGui::Checkbox("Unlock All Equipments/Warbonds", &fEquipmentUnlock); 17 | 18 | ImGui::Separator(); 19 | 20 | ImGui::Checkbox("No Stratagem/Shuttle Timer", &fRoutineDeployment); 21 | ImGui::Checkbox("Unlimited Ammo", &fWeaponAmmoReduction); 22 | ImGui::Checkbox("Unlimited Stratagems", &fStratagemReduction); 23 | ImGui::Checkbox("Unlimited Stamina", &fStaminaReduction); 24 | ImGui::Checkbox("GodMode", &fEnemyBasicDamage); 25 | 26 | ImGui::End(); 27 | } 28 | -------------------------------------------------------------------------------- /src/gui/menu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Menu { 4 | void Render(); 5 | } -------------------------------------------------------------------------------- /src/hooks/_hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "_hooks.h" 2 | #include 3 | #include "detours.h" 4 | #include 5 | #include "oxorany.h" 6 | #include "globals.h" 7 | #include 8 | #include "SignatureScan.hpp" 9 | 10 | bool HookFunction(PVOID* ppPointer, PVOID pDetour, const char* functionName) { 11 | if (const auto error = DetourAttach(ppPointer, pDetour); error != NO_ERROR) { 12 | std::cout << oxorany("Failed to hook ") << functionName << oxorany(", error ") << error << std::endl; 13 | return false; 14 | } 15 | std::cout << oxorany("Hooked ") << functionName << " [" << std::hex << std::setw(16) << *ppPointer << "] -> [" << std::hex << std::setw(16) << pDetour << "]" << std::endl; 16 | return true; 17 | } 18 | 19 | #define HOOKFUNC(n) if (!HookFunction(&(PVOID&)n, d ## n, #n)) return; 20 | 21 | bool UnhookFunction(PVOID* ppPointer, PVOID pDetour, const char* functionName) { 22 | if (const auto error = DetourDetach(ppPointer, pDetour); error != NO_ERROR) { 23 | std::cout << oxorany("Failed to unhook ") << functionName << oxorany(", error ") << error << std::endl; 24 | return false; 25 | } 26 | std::cout << oxorany("Unhooked ") << functionName << std::endl; 27 | return true; 28 | } 29 | 30 | #define UNHOOKFUNC(n) if (!UnhookFunction(&(PVOID&)n, d ## n, #n)) return; 31 | 32 | void DetourInitilization() { 33 | DetourTransactionBegin(); 34 | DetourUpdateThread(GetCurrentThread()); 35 | 36 | SetSysCursorPos = (SET_CURSOR_POS_FUNCTION)GetProcAddress(GetModuleHandle(oxorany("user32.dll")), oxorany("SetCursorPos")); 37 | Present = SignatureScan(oxorany("48 89 6C 24 ? 48 89 74 24 ? 41 56 48 83 EC 20 41 8B E8"), GetModuleHandle(oxorany("gameoverlayrenderer64.dll"))); 38 | PickupSample = SignatureScan(oxorany("45 85 C9 0F 84 ? ? ? ? 48 89 6C 24 ? 41 56"), ModuleHandle); 39 | IsStratagemUnlocked = SignatureScan(oxorany("48 89 5C 24 ? 48 8B D9 85 D2 75 09"), ModuleHandle); 40 | IsArmorUnlocked = SignatureScan(oxorany("48 83 EC ?? 44 8B 49 ?? 45 33 C0"), ModuleHandle); 41 | IsEquipmentUnlocked = SignatureScan(oxorany("E8 ? ? ? ? EB 12 8B 48 08"), ModuleHandle).ResolveCall(); 42 | RoutineDeploymentTime = SignatureScan(oxorany("4C 8B DC 49 89 5B 18 55 56 57 41 54 41 55 41 56"), 0, ModuleHandle); 43 | WeaponAmmoReduction = SignatureScan(oxorany("48 89 4C 24 ? 53 55 56 57 41 57 48 83 EC 40"), 0, ModuleHandle); 44 | StratagemReduction = SignatureScan(oxorany("48 8B C4 44 88 40 18 53 55 41 54 41 55"), 0, ModuleHandle); 45 | StaminaReduction = SignatureScan(oxorany("E8 ? ? ? ? 48 8B 44 24 ? 0F 28 C6"), 0, ModuleHandle).ResolveCall(); 46 | EnemyBasicDamage = SignatureScan(oxorany("44 89 4C 24 ? 48 89 54 24 ? 53 41 54"), ModuleHandle); 47 | 48 | HOOKFUNC(SetSysCursorPos); 49 | HOOKFUNC(Present); 50 | HOOKFUNC(PickupSample); 51 | HOOKFUNC(IsStratagemUnlocked); 52 | HOOKFUNC(IsArmorUnlocked); 53 | HOOKFUNC(IsEquipmentUnlocked); 54 | HOOKFUNC(RoutineDeploymentTime); 55 | HOOKFUNC(WeaponAmmoReduction); 56 | HOOKFUNC(StratagemReduction); 57 | HOOKFUNC(StaminaReduction); 58 | HOOKFUNC(EnemyBasicDamage); 59 | 60 | DetourTransactionCommit(); 61 | } 62 | 63 | void DetourUninitilization() 64 | { 65 | DetourTransactionBegin(); 66 | DetourUpdateThread(GetCurrentThread()); 67 | 68 | UNHOOKFUNC(SetSysCursorPos); 69 | UNHOOKFUNC(Present); 70 | UNHOOKFUNC(PickupSample); 71 | UNHOOKFUNC(IsStratagemUnlocked); 72 | UNHOOKFUNC(IsArmorUnlocked); 73 | UNHOOKFUNC(IsEquipmentUnlocked); 74 | UNHOOKFUNC(RoutineDeploymentTime); 75 | UNHOOKFUNC(WeaponAmmoReduction); 76 | UNHOOKFUNC(StratagemReduction); 77 | UNHOOKFUNC(StaminaReduction); 78 | UNHOOKFUNC(EnemyBasicDamage); 79 | 80 | DetourTransactionCommit(); 81 | } 82 | -------------------------------------------------------------------------------- /src/hooks/_hooks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "app-functions.h" 3 | 4 | void DetourInitilization(); 5 | void DetourUninitilization(); 6 | 7 | BOOL APIENTRY dSetSysCursorPos(int X, int Y); 8 | HRESULT APIENTRY dPresent(IDXGISwapChain* __this, UINT SyncInterval, UINT Flags); 9 | LRESULT APIENTRY dWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 10 | 11 | void dPickupSample(__int64 a1, int a2, int amount, int sampleType); 12 | bool dIsStratagemUnlocked(__int64 a1, int StratagemId); 13 | bool dIsArmorUnlocked(int* armorObject); 14 | bool dIsEquipmentUnlocked(DWORD* a1, int equipmentId); 15 | void dRoutineDeploymentTime(__int64* a1, float timeSteps); 16 | __int64 dWeaponAmmoReduction(__int64 a1, unsigned int weaponId); 17 | __int64 dStratagemReduction(__int64 a1, unsigned int a2, char a3, __int64 a4); 18 | void dStaminaReduction(__int64 a1, int a2, float a3); 19 | void dEnemyBasicDamage(__int64 target, __int64 a2, unsigned int a3, int damage, unsigned int typeMaybe); 20 | -------------------------------------------------------------------------------- /src/hooks/app.cpp: -------------------------------------------------------------------------------- 1 | #include "_hooks.h" 2 | #include "globals.h" 3 | 4 | void dPickupSample(__int64 a1, int a2, int amount, int sampleType) { 5 | PickupSample(a1, a2, (fManipulateSamplePickup) ? SampleAmount : amount, sampleType); 6 | } 7 | 8 | bool dIsStratagemUnlocked(__int64 a1, int StratagemId) { 9 | if (fStratagemUnlock) 10 | return true; 11 | 12 | return IsStratagemUnlocked(a1, StratagemId); 13 | } 14 | 15 | bool dIsArmorUnlocked(int* armorObject) { 16 | if (fArmorUnlock) 17 | return true; 18 | 19 | return IsArmorUnlocked(armorObject); 20 | } 21 | 22 | bool dIsEquipmentUnlocked(DWORD* a1, int equipmentId) { 23 | if (fEquipmentUnlock) 24 | return true; 25 | 26 | return IsEquipmentUnlocked(a1, equipmentId); 27 | } 28 | 29 | void dRoutineDeploymentTime(__int64* a1, float timeSteps) { 30 | RoutineDeploymentTime(a1, (fRoutineDeployment) ? 100.f : timeSteps); 31 | } 32 | 33 | __int64 dWeaponAmmoReduction(__int64 a1, unsigned int weaponId) { 34 | if (fWeaponAmmoReduction) 35 | return NULL; 36 | 37 | return WeaponAmmoReduction(a1, weaponId); 38 | } 39 | 40 | __int64 dStratagemReduction(__int64 a1, unsigned int a2, char a3, __int64 a4) { 41 | if (fStratagemReduction) 42 | return NULL; 43 | 44 | return StratagemReduction(a1, a2, a3, a4); 45 | } 46 | 47 | void dStaminaReduction(__int64 a1, int a2, float a3) { 48 | if (fStaminaReduction) 49 | return; 50 | 51 | StaminaReduction(a1, a2, a3); 52 | } 53 | 54 | void dEnemyBasicDamage(__int64 target, __int64 a2, unsigned int a3, int damage, unsigned int typeMaybe) { 55 | EnemyBasicDamage(target, a2, a3, (fEnemyBasicDamage) ? 0 : damage, typeMaybe); 56 | } 57 | -------------------------------------------------------------------------------- /src/hooks/directx.cpp: -------------------------------------------------------------------------------- 1 | #include "_hooks.h" 2 | #include 3 | #include 4 | #include "oxorany.h" 5 | #include "imgui.h" 6 | #include "imgui_impl_dx11.h" 7 | #include "imgui_impl_win32.h" 8 | #include "globals.h" 9 | #include 10 | #include "menu.h" 11 | 12 | ID3D11DeviceContext* pContext = nullptr; 13 | ID3D11RenderTargetView* pRenderTargetView = nullptr; 14 | 15 | HRESULT dPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) { 16 | if (!IsGUIInitialized) 17 | { 18 | DXGI_SWAP_CHAIN_DESC desc; 19 | pSwapChain->GetDesc(&desc); 20 | 21 | ID3D11Device* pDevice = nullptr; 22 | if (FAILED(pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&pDevice) 23 | || !pDevice)) 24 | return Present(pSwapChain, SyncInterval, Flags); 25 | 26 | pDevice->GetImmediateContext(&pContext); 27 | 28 | if (!pContext) 29 | return Present(pSwapChain, SyncInterval, Flags); 30 | 31 | ID3D11Texture2D* pBackBuffer = nullptr; 32 | if (FAILED(pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer)) 33 | || !pBackBuffer) 34 | return Present(pSwapChain, SyncInterval, Flags); 35 | 36 | if (FAILED(pDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView) 37 | || !pRenderTargetView)) 38 | return Present(pSwapChain, SyncInterval, Flags); 39 | 40 | WindowProc = (WNDPROC)::SetWindowLongPtr((HWND)desc.OutputWindow, GWLP_WNDPROC, (LONG_PTR)dWndProc); 41 | 42 | ImGui::CreateContext(); 43 | ImGui::GetIO().ConfigFlags = ImGuiConfigFlags_NoMouseCursorChange; 44 | ImGui_ImplWin32_Init(desc.OutputWindow); 45 | ImGui_ImplDX11_Init(pDevice, pContext); 46 | 47 | IsGUIInitialized = true; 48 | } 49 | 50 | ImGui::GetIO().MouseDrawCursor = ShowMenu; 51 | 52 | ImGui_ImplDX11_NewFrame(); 53 | ImGui_ImplWin32_NewFrame(); 54 | ImGui::NewFrame(); 55 | 56 | if (ShowMenu) 57 | Menu::Render(); 58 | 59 | ImGui::EndFrame(); 60 | ImGui::Render(); 61 | 62 | pContext->OMSetRenderTargets(1, &pRenderTargetView, NULL); 63 | ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); 64 | 65 | return Present(pSwapChain, SyncInterval, Flags); 66 | } 67 | -------------------------------------------------------------------------------- /src/hooks/user32.cpp: -------------------------------------------------------------------------------- 1 | #include "_hooks.h" 2 | #include "globals.h" 3 | 4 | BOOL dSetSysCursorPos(int X, int Y) { 5 | if (ShowMenu) 6 | return TRUE; 7 | 8 | return SetSysCursorPos(X, Y); 9 | } 10 | -------------------------------------------------------------------------------- /src/hooks/winuser.cpp: -------------------------------------------------------------------------------- 1 | #include "_hooks.h" 2 | #include "imgui.h" 3 | #include "imgui_impl_dx11.h" 4 | #include "imgui_impl_win32.h" 5 | #include "globals.h" 6 | 7 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 8 | 9 | LRESULT APIENTRY dWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 10 | if (!IsGUIInitialized) 11 | return CallWindowProc(WindowProc, hWnd, uMsg, wParam, lParam); 12 | 13 | ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam); 14 | 15 | switch (uMsg) { 16 | case WM_SYSKEYDOWN: 17 | case WM_SYSKEYUP: 18 | CallWindowProc(WindowProc, hWnd, uMsg, wParam, lParam); 19 | break; 20 | 21 | case WM_KEYUP: 22 | if (wParam == VK_DELETE) { 23 | ShowMenu = !ShowMenu; 24 | } 25 | break; 26 | 27 | default: 28 | break; 29 | } 30 | 31 | ImGuiIO& io = ImGui::GetIO(); 32 | if (io.WantCaptureMouse || io.WantCaptureKeyboard) 33 | return DefWindowProc(hWnd, uMsg, wParam, lParam); 34 | 35 | if (ShowMenu) 36 | return true; 37 | 38 | return CallWindowProc(WindowProc, hWnd, uMsg, wParam, lParam); 39 | } 40 | -------------------------------------------------------------------------------- /src/include/detours/modules.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Module Enumeration Functions (modules.cpp of detours.lib) 4 | // 5 | // Microsoft Research Detours Package, Version 4.0.1 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | // 9 | // Module enumeration functions. 10 | // 11 | 12 | // #define DETOUR_DEBUG 1 13 | #define DETOURS_INTERNAL 14 | #include "detours.h" 15 | 16 | #if DETOURS_VERSION != 0x4c0c1 // 0xMAJORcMINORcPATCH 17 | #error detours.h version mismatch 18 | #endif 19 | 20 | #define CLR_DIRECTORY OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR] 21 | #define IAT_DIRECTORY OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT] 22 | 23 | ////////////////////////////////////////////////////////////////////////////// 24 | // 25 | const GUID DETOUR_EXE_RESTORE_GUID = { 26 | 0x2ed7a3ff, 0x3339, 0x4a8d, 27 | { 0x80, 0x5c, 0xd4, 0x98, 0x15, 0x3f, 0xc2, 0x8f }}; 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // 31 | PDETOUR_SYM_INFO DetourLoadImageHlp(VOID) 32 | { 33 | static DETOUR_SYM_INFO symInfo; 34 | static PDETOUR_SYM_INFO pSymInfo = NULL; 35 | static BOOL failed = false; 36 | 37 | if (failed) { 38 | return NULL; 39 | } 40 | if (pSymInfo != NULL) { 41 | return pSymInfo; 42 | } 43 | 44 | ZeroMemory(&symInfo, sizeof(symInfo)); 45 | // Create a real handle to the process. 46 | #if 0 47 | DuplicateHandle(GetCurrentProcess(), 48 | GetCurrentProcess(), 49 | GetCurrentProcess(), 50 | &symInfo.hProcess, 51 | 0, 52 | FALSE, 53 | DUPLICATE_SAME_ACCESS); 54 | #else 55 | symInfo.hProcess = GetCurrentProcess(); 56 | #endif 57 | 58 | symInfo.hDbgHelp = LoadLibraryExW(L"dbghelp.dll", NULL, 0); 59 | if (symInfo.hDbgHelp == NULL) { 60 | abort: 61 | failed = true; 62 | if (symInfo.hDbgHelp != NULL) { 63 | FreeLibrary(symInfo.hDbgHelp); 64 | } 65 | symInfo.pfImagehlpApiVersionEx = NULL; 66 | symInfo.pfSymInitialize = NULL; 67 | symInfo.pfSymSetOptions = NULL; 68 | symInfo.pfSymGetOptions = NULL; 69 | symInfo.pfSymLoadModule64 = NULL; 70 | symInfo.pfSymGetModuleInfo64 = NULL; 71 | symInfo.pfSymFromName = NULL; 72 | return NULL; 73 | } 74 | 75 | symInfo.pfImagehlpApiVersionEx 76 | = (PF_ImagehlpApiVersionEx)GetProcAddress(symInfo.hDbgHelp, 77 | "ImagehlpApiVersionEx"); 78 | symInfo.pfSymInitialize 79 | = (PF_SymInitialize)GetProcAddress(symInfo.hDbgHelp, "SymInitialize"); 80 | symInfo.pfSymSetOptions 81 | = (PF_SymSetOptions)GetProcAddress(symInfo.hDbgHelp, "SymSetOptions"); 82 | symInfo.pfSymGetOptions 83 | = (PF_SymGetOptions)GetProcAddress(symInfo.hDbgHelp, "SymGetOptions"); 84 | symInfo.pfSymLoadModule64 85 | = (PF_SymLoadModule64)GetProcAddress(symInfo.hDbgHelp, "SymLoadModule64"); 86 | symInfo.pfSymGetModuleInfo64 87 | = (PF_SymGetModuleInfo64)GetProcAddress(symInfo.hDbgHelp, "SymGetModuleInfo64"); 88 | symInfo.pfSymFromName 89 | = (PF_SymFromName)GetProcAddress(symInfo.hDbgHelp, "SymFromName"); 90 | 91 | API_VERSION av; 92 | ZeroMemory(&av, sizeof(av)); 93 | av.MajorVersion = API_VERSION_NUMBER; 94 | 95 | if (symInfo.pfImagehlpApiVersionEx == NULL || 96 | symInfo.pfSymInitialize == NULL || 97 | symInfo.pfSymLoadModule64 == NULL || 98 | symInfo.pfSymGetModuleInfo64 == NULL || 99 | symInfo.pfSymFromName == NULL) { 100 | goto abort; 101 | } 102 | 103 | symInfo.pfImagehlpApiVersionEx(&av); 104 | if (av.MajorVersion < API_VERSION_NUMBER) { 105 | goto abort; 106 | } 107 | 108 | if (!symInfo.pfSymInitialize(symInfo.hProcess, NULL, FALSE)) { 109 | // We won't retry the initialize if it fails. 110 | goto abort; 111 | } 112 | 113 | if (symInfo.pfSymGetOptions != NULL && symInfo.pfSymSetOptions != NULL) { 114 | DWORD dw = symInfo.pfSymGetOptions(); 115 | 116 | dw &= ~(SYMOPT_CASE_INSENSITIVE | 117 | SYMOPT_UNDNAME | 118 | SYMOPT_DEFERRED_LOADS | 119 | 0); 120 | dw |= ( 121 | #if defined(SYMOPT_EXACT_SYMBOLS) 122 | SYMOPT_EXACT_SYMBOLS | 123 | #endif 124 | #if defined(SYMOPT_NO_UNQUALIFIED_LOADS) 125 | SYMOPT_NO_UNQUALIFIED_LOADS | 126 | #endif 127 | SYMOPT_DEFERRED_LOADS | 128 | #if defined(SYMOPT_FAIL_CRITICAL_ERRORS) 129 | SYMOPT_FAIL_CRITICAL_ERRORS | 130 | #endif 131 | #if defined(SYMOPT_INCLUDE_32BIT_MODULES) 132 | SYMOPT_INCLUDE_32BIT_MODULES | 133 | #endif 134 | 0); 135 | symInfo.pfSymSetOptions(dw); 136 | } 137 | 138 | pSymInfo = &symInfo; 139 | return pSymInfo; 140 | } 141 | 142 | PVOID WINAPI DetourFindFunction(_In_ LPCSTR pszModule, 143 | _In_ LPCSTR pszFunction) 144 | { 145 | /////////////////////////////////////////////// First, try GetProcAddress. 146 | // 147 | #pragma prefast(suppress:28752, "We don't do the unicode conversion for LoadLibraryExA.") 148 | HMODULE hModule = LoadLibraryExA(pszModule, NULL, 0); 149 | if (hModule == NULL) { 150 | return NULL; 151 | } 152 | 153 | PBYTE pbCode = (PBYTE)GetProcAddress(hModule, pszFunction); 154 | if (pbCode) { 155 | return pbCode; 156 | } 157 | 158 | ////////////////////////////////////////////////////// Then try ImageHelp. 159 | // 160 | DETOUR_TRACE(("DetourFindFunction(%hs, %hs)\n", pszModule, pszFunction)); 161 | PDETOUR_SYM_INFO pSymInfo = DetourLoadImageHlp(); 162 | if (pSymInfo == NULL) { 163 | DETOUR_TRACE(("DetourLoadImageHlp failed: %d\n", 164 | GetLastError())); 165 | return NULL; 166 | } 167 | 168 | if (pSymInfo->pfSymLoadModule64(pSymInfo->hProcess, NULL, 169 | (PCHAR)pszModule, NULL, 170 | (DWORD64)hModule, 0) == 0) { 171 | if (ERROR_SUCCESS != GetLastError()) { 172 | DETOUR_TRACE(("SymLoadModule64(%p) failed: %d\n", 173 | pSymInfo->hProcess, GetLastError())); 174 | return NULL; 175 | } 176 | } 177 | 178 | HRESULT hrRet; 179 | CHAR szFullName[512]; 180 | IMAGEHLP_MODULE64 modinfo; 181 | ZeroMemory(&modinfo, sizeof(modinfo)); 182 | modinfo.SizeOfStruct = sizeof(modinfo); 183 | if (!pSymInfo->pfSymGetModuleInfo64(pSymInfo->hProcess, (DWORD64)hModule, &modinfo)) { 184 | DETOUR_TRACE(("SymGetModuleInfo64(%p, %p) failed: %d\n", 185 | pSymInfo->hProcess, hModule, GetLastError())); 186 | return NULL; 187 | } 188 | 189 | hrRet = StringCchCopyA(szFullName, sizeof(szFullName)/sizeof(CHAR), modinfo.ModuleName); 190 | if (FAILED(hrRet)) { 191 | DETOUR_TRACE(("StringCchCopyA failed: %08x\n", hrRet)); 192 | return NULL; 193 | } 194 | hrRet = StringCchCatA(szFullName, sizeof(szFullName)/sizeof(CHAR), "!"); 195 | if (FAILED(hrRet)) { 196 | DETOUR_TRACE(("StringCchCatA failed: %08x\n", hrRet)); 197 | return NULL; 198 | } 199 | hrRet = StringCchCatA(szFullName, sizeof(szFullName)/sizeof(CHAR), pszFunction); 200 | if (FAILED(hrRet)) { 201 | DETOUR_TRACE(("StringCchCatA failed: %08x\n", hrRet)); 202 | return NULL; 203 | } 204 | 205 | struct CFullSymbol : SYMBOL_INFO { 206 | CHAR szRestOfName[512]; 207 | } symbol; 208 | ZeroMemory(&symbol, sizeof(symbol)); 209 | //symbol.ModBase = (ULONG64)hModule; 210 | symbol.SizeOfStruct = sizeof(SYMBOL_INFO); 211 | #ifdef DBHLPAPI 212 | symbol.MaxNameLen = sizeof(symbol.szRestOfName)/sizeof(symbol.szRestOfName[0]); 213 | #else 214 | symbol.MaxNameLength = sizeof(symbol.szRestOfName)/sizeof(symbol.szRestOfName[0]); 215 | #endif 216 | 217 | if (!pSymInfo->pfSymFromName(pSymInfo->hProcess, szFullName, &symbol)) { 218 | DETOUR_TRACE(("SymFromName(%hs) failed: %d\n", szFullName, GetLastError())); 219 | return NULL; 220 | } 221 | 222 | #if defined(DETOURS_IA64) 223 | // On the IA64, we get a raw code pointer from the symbol engine 224 | // and have to convert it to a wrapped [code pointer, global pointer]. 225 | // 226 | PPLABEL_DESCRIPTOR pldEntry = (PPLABEL_DESCRIPTOR)DetourGetEntryPoint(hModule); 227 | PPLABEL_DESCRIPTOR pldSymbol = new PLABEL_DESCRIPTOR; 228 | 229 | pldSymbol->EntryPoint = symbol.Address; 230 | pldSymbol->GlobalPointer = pldEntry->GlobalPointer; 231 | return (PBYTE)pldSymbol; 232 | #elif defined(DETOURS_ARM) 233 | // On the ARM, we get a raw code pointer, which we must convert into a 234 | // valied Thumb2 function pointer. 235 | return DETOURS_PBYTE_TO_PFUNC(symbol.Address); 236 | #else 237 | return (PBYTE)symbol.Address; 238 | #endif 239 | } 240 | 241 | //////////////////////////////////////////////////// Module Image Functions. 242 | // 243 | 244 | HMODULE WINAPI DetourEnumerateModules(_In_opt_ HMODULE hModuleLast) 245 | { 246 | PBYTE pbLast = (PBYTE)hModuleLast + MM_ALLOCATION_GRANULARITY; 247 | 248 | MEMORY_BASIC_INFORMATION mbi; 249 | ZeroMemory(&mbi, sizeof(mbi)); 250 | 251 | // Find the next memory region that contains a mapped PE image. 252 | // 253 | for (;; pbLast = (PBYTE)mbi.BaseAddress + mbi.RegionSize) { 254 | if (VirtualQuery(pbLast, &mbi, sizeof(mbi)) <= 0) { 255 | break; 256 | } 257 | 258 | // Skip uncommitted regions and guard pages. 259 | // 260 | if ((mbi.State != MEM_COMMIT) || 261 | ((mbi.Protect & 0xff) == PAGE_NOACCESS) || 262 | (mbi.Protect & PAGE_GUARD)) { 263 | continue; 264 | } 265 | 266 | __try { 267 | PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)pbLast; 268 | if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE || 269 | (DWORD)pDosHeader->e_lfanew > mbi.RegionSize || 270 | (DWORD)pDosHeader->e_lfanew < sizeof(*pDosHeader)) { 271 | continue; 272 | } 273 | 274 | PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + 275 | pDosHeader->e_lfanew); 276 | if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { 277 | continue; 278 | } 279 | 280 | return (HMODULE)pDosHeader; 281 | } 282 | #pragma prefast(suppress:28940, "A bad pointer means this probably isn't a PE header.") 283 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 284 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 285 | continue; 286 | } 287 | } 288 | return NULL; 289 | } 290 | 291 | PVOID WINAPI DetourGetEntryPoint(_In_opt_ HMODULE hModule) 292 | { 293 | PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; 294 | if (hModule == NULL) { 295 | pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); 296 | } 297 | 298 | __try { 299 | #pragma warning(suppress:6011) // GetModuleHandleW(NULL) never returns NULL. 300 | if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { 301 | SetLastError(ERROR_BAD_EXE_FORMAT); 302 | return NULL; 303 | } 304 | 305 | PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + 306 | pDosHeader->e_lfanew); 307 | if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { 308 | SetLastError(ERROR_INVALID_EXE_SIGNATURE); 309 | return NULL; 310 | } 311 | if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { 312 | SetLastError(ERROR_EXE_MARKED_INVALID); 313 | return NULL; 314 | } 315 | 316 | PDETOUR_CLR_HEADER pClrHeader = NULL; 317 | if (pNtHeader->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { 318 | if (((PIMAGE_NT_HEADERS32)pNtHeader)->CLR_DIRECTORY.VirtualAddress != 0 && 319 | ((PIMAGE_NT_HEADERS32)pNtHeader)->CLR_DIRECTORY.Size != 0) { 320 | pClrHeader = (PDETOUR_CLR_HEADER) 321 | (((PBYTE)pDosHeader) 322 | + ((PIMAGE_NT_HEADERS32)pNtHeader)->CLR_DIRECTORY.VirtualAddress); 323 | } 324 | } 325 | else if (pNtHeader->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { 326 | if (((PIMAGE_NT_HEADERS64)pNtHeader)->CLR_DIRECTORY.VirtualAddress != 0 && 327 | ((PIMAGE_NT_HEADERS64)pNtHeader)->CLR_DIRECTORY.Size != 0) { 328 | pClrHeader = (PDETOUR_CLR_HEADER) 329 | (((PBYTE)pDosHeader) 330 | + ((PIMAGE_NT_HEADERS64)pNtHeader)->CLR_DIRECTORY.VirtualAddress); 331 | } 332 | } 333 | 334 | if (pClrHeader != NULL) { 335 | // For MSIL assemblies, we want to use the _Cor entry points. 336 | 337 | HMODULE hClr = GetModuleHandleW(L"MSCOREE.DLL"); 338 | if (hClr == NULL) { 339 | return NULL; 340 | } 341 | 342 | SetLastError(NO_ERROR); 343 | return GetProcAddress(hClr, "_CorExeMain"); 344 | } 345 | 346 | SetLastError(NO_ERROR); 347 | 348 | // Pure resource DLLs have neither an entry point nor CLR information 349 | // so handle them by returning NULL (LastError is NO_ERROR) 350 | if (pNtHeader->OptionalHeader.AddressOfEntryPoint == 0) { 351 | return NULL; 352 | } 353 | 354 | return ((PBYTE)pDosHeader) + 355 | pNtHeader->OptionalHeader.AddressOfEntryPoint; 356 | } 357 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 358 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 359 | SetLastError(ERROR_EXE_MARKED_INVALID); 360 | return NULL; 361 | } 362 | } 363 | 364 | ULONG WINAPI DetourGetModuleSize(_In_opt_ HMODULE hModule) 365 | { 366 | PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; 367 | if (hModule == NULL) { 368 | pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); 369 | } 370 | 371 | __try { 372 | #pragma warning(suppress:6011) // GetModuleHandleW(NULL) never returns NULL. 373 | if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { 374 | SetLastError(ERROR_BAD_EXE_FORMAT); 375 | return NULL; 376 | } 377 | 378 | PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + 379 | pDosHeader->e_lfanew); 380 | if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { 381 | SetLastError(ERROR_INVALID_EXE_SIGNATURE); 382 | return NULL; 383 | } 384 | if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { 385 | SetLastError(ERROR_EXE_MARKED_INVALID); 386 | return NULL; 387 | } 388 | SetLastError(NO_ERROR); 389 | 390 | return (pNtHeader->OptionalHeader.SizeOfImage); 391 | } 392 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 393 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 394 | SetLastError(ERROR_EXE_MARKED_INVALID); 395 | return NULL; 396 | } 397 | } 398 | 399 | HMODULE WINAPI DetourGetContainingModule(_In_ PVOID pvAddr) 400 | { 401 | MEMORY_BASIC_INFORMATION mbi; 402 | ZeroMemory(&mbi, sizeof(mbi)); 403 | 404 | __try { 405 | if (VirtualQuery(pvAddr, &mbi, sizeof(mbi)) <= 0) { 406 | SetLastError(ERROR_BAD_EXE_FORMAT); 407 | return NULL; 408 | } 409 | 410 | // Skip uncommitted regions and guard pages. 411 | // 412 | if ((mbi.State != MEM_COMMIT) || 413 | ((mbi.Protect & 0xff) == PAGE_NOACCESS) || 414 | (mbi.Protect & PAGE_GUARD)) { 415 | SetLastError(ERROR_BAD_EXE_FORMAT); 416 | return NULL; 417 | } 418 | 419 | PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)mbi.AllocationBase; 420 | if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { 421 | SetLastError(ERROR_BAD_EXE_FORMAT); 422 | return NULL; 423 | } 424 | 425 | PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + 426 | pDosHeader->e_lfanew); 427 | if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { 428 | SetLastError(ERROR_INVALID_EXE_SIGNATURE); 429 | return NULL; 430 | } 431 | if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { 432 | SetLastError(ERROR_EXE_MARKED_INVALID); 433 | return NULL; 434 | } 435 | SetLastError(NO_ERROR); 436 | 437 | return (HMODULE)pDosHeader; 438 | } 439 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 440 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 441 | SetLastError(ERROR_INVALID_EXE_SIGNATURE); 442 | return NULL; 443 | } 444 | } 445 | 446 | 447 | static inline PBYTE RvaAdjust(_Pre_notnull_ PIMAGE_DOS_HEADER pDosHeader, _In_ DWORD raddr) 448 | { 449 | if (raddr != NULL) { 450 | return ((PBYTE)pDosHeader) + raddr; 451 | } 452 | return NULL; 453 | } 454 | 455 | BOOL WINAPI DetourEnumerateExports(_In_ HMODULE hModule, 456 | _In_opt_ PVOID pContext, 457 | _In_ PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport) 458 | { 459 | PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; 460 | if (hModule == NULL) { 461 | pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); 462 | } 463 | 464 | __try { 465 | #pragma warning(suppress:6011) // GetModuleHandleW(NULL) never returns NULL. 466 | if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { 467 | SetLastError(ERROR_BAD_EXE_FORMAT); 468 | return NULL; 469 | } 470 | 471 | PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + 472 | pDosHeader->e_lfanew); 473 | if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { 474 | SetLastError(ERROR_INVALID_EXE_SIGNATURE); 475 | return FALSE; 476 | } 477 | if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { 478 | SetLastError(ERROR_EXE_MARKED_INVALID); 479 | return FALSE; 480 | } 481 | 482 | PIMAGE_EXPORT_DIRECTORY pExportDir 483 | = (PIMAGE_EXPORT_DIRECTORY) 484 | RvaAdjust(pDosHeader, 485 | pNtHeader->OptionalHeader 486 | .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); 487 | 488 | if (pExportDir == NULL) { 489 | SetLastError(ERROR_EXE_MARKED_INVALID); 490 | return FALSE; 491 | } 492 | 493 | PBYTE pExportDirEnd = (PBYTE)pExportDir + pNtHeader->OptionalHeader 494 | .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; 495 | PDWORD pdwFunctions = (PDWORD)RvaAdjust(pDosHeader, pExportDir->AddressOfFunctions); 496 | PDWORD pdwNames = (PDWORD)RvaAdjust(pDosHeader, pExportDir->AddressOfNames); 497 | PWORD pwOrdinals = (PWORD)RvaAdjust(pDosHeader, pExportDir->AddressOfNameOrdinals); 498 | 499 | for (DWORD nFunc = 0; nFunc < pExportDir->NumberOfFunctions; nFunc++) { 500 | PBYTE pbCode = (pdwFunctions != NULL) 501 | ? (PBYTE)RvaAdjust(pDosHeader, pdwFunctions[nFunc]) : NULL; 502 | PCHAR pszName = NULL; 503 | 504 | // if the pointer is in the export region, then it is a forwarder. 505 | if (pbCode > (PBYTE)pExportDir && pbCode < pExportDirEnd) { 506 | pbCode = NULL; 507 | } 508 | 509 | for (DWORD n = 0; n < pExportDir->NumberOfNames; n++) { 510 | if (pwOrdinals[n] == nFunc) { 511 | pszName = (pdwNames != NULL) 512 | ? (PCHAR)RvaAdjust(pDosHeader, pdwNames[n]) : NULL; 513 | break; 514 | } 515 | } 516 | ULONG nOrdinal = pExportDir->Base + nFunc; 517 | 518 | if (!pfExport(pContext, nOrdinal, pszName, pbCode)) { 519 | break; 520 | } 521 | } 522 | SetLastError(NO_ERROR); 523 | return TRUE; 524 | } 525 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 526 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 527 | SetLastError(ERROR_EXE_MARKED_INVALID); 528 | return NULL; 529 | } 530 | } 531 | 532 | BOOL WINAPI DetourEnumerateImportsEx(_In_opt_ HMODULE hModule, 533 | _In_opt_ PVOID pContext, 534 | _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, 535 | _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK_EX pfImportFunc) 536 | { 537 | PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; 538 | if (hModule == NULL) { 539 | pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); 540 | } 541 | 542 | __try { 543 | #pragma warning(suppress:6011) // GetModuleHandleW(NULL) never returns NULL. 544 | if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { 545 | SetLastError(ERROR_BAD_EXE_FORMAT); 546 | return FALSE; 547 | } 548 | 549 | PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + 550 | pDosHeader->e_lfanew); 551 | if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { 552 | SetLastError(ERROR_INVALID_EXE_SIGNATURE); 553 | return FALSE; 554 | } 555 | if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { 556 | SetLastError(ERROR_EXE_MARKED_INVALID); 557 | return FALSE; 558 | } 559 | 560 | PIMAGE_IMPORT_DESCRIPTOR iidp 561 | = (PIMAGE_IMPORT_DESCRIPTOR) 562 | RvaAdjust(pDosHeader, 563 | pNtHeader->OptionalHeader 564 | .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); 565 | 566 | if (iidp == NULL) { 567 | SetLastError(ERROR_EXE_MARKED_INVALID); 568 | return FALSE; 569 | } 570 | 571 | for (; iidp->OriginalFirstThunk != 0; iidp++) { 572 | 573 | PCSTR pszName = (PCHAR)RvaAdjust(pDosHeader, iidp->Name); 574 | if (pszName == NULL) { 575 | SetLastError(ERROR_EXE_MARKED_INVALID); 576 | return FALSE; 577 | } 578 | 579 | PIMAGE_THUNK_DATA pThunks = (PIMAGE_THUNK_DATA) 580 | RvaAdjust(pDosHeader, iidp->OriginalFirstThunk); 581 | PVOID * pAddrs = (PVOID *) 582 | RvaAdjust(pDosHeader, iidp->FirstThunk); 583 | 584 | HMODULE hFile = DetourGetContainingModule(pAddrs[0]); 585 | 586 | if (pfImportFile != NULL) { 587 | if (!pfImportFile(pContext, hFile, pszName)) { 588 | break; 589 | } 590 | } 591 | 592 | DWORD nNames = 0; 593 | if (pThunks) { 594 | for (; pThunks[nNames].u1.Ordinal; nNames++) { 595 | DWORD nOrdinal = 0; 596 | PCSTR pszFunc = NULL; 597 | 598 | if (IMAGE_SNAP_BY_ORDINAL(pThunks[nNames].u1.Ordinal)) { 599 | nOrdinal = (DWORD)IMAGE_ORDINAL(pThunks[nNames].u1.Ordinal); 600 | } 601 | else { 602 | pszFunc = (PCSTR)RvaAdjust(pDosHeader, 603 | (DWORD)pThunks[nNames].u1.AddressOfData + 2); 604 | } 605 | 606 | if (pfImportFunc != NULL) { 607 | if (!pfImportFunc(pContext, 608 | nOrdinal, 609 | pszFunc, 610 | &pAddrs[nNames])) { 611 | break; 612 | } 613 | } 614 | } 615 | if (pfImportFunc != NULL) { 616 | pfImportFunc(pContext, 0, NULL, NULL); 617 | } 618 | } 619 | } 620 | if (pfImportFile != NULL) { 621 | pfImportFile(pContext, NULL, NULL); 622 | } 623 | SetLastError(NO_ERROR); 624 | return TRUE; 625 | } 626 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 627 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 628 | SetLastError(ERROR_EXE_MARKED_INVALID); 629 | return FALSE; 630 | } 631 | } 632 | 633 | // Context for DetourEnumerateImportsThunk, which adapts "regular" callbacks for use with "Ex". 634 | struct _DETOUR_ENUMERATE_IMPORTS_THUNK_CONTEXT 635 | { 636 | PVOID pContext; 637 | PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc; 638 | }; 639 | 640 | // Callback for DetourEnumerateImportsEx that adapts DetourEnumerateImportsEx 641 | // for use with a DetourEnumerateImports callback -- derefence the IAT and pass the value on. 642 | 643 | static 644 | BOOL 645 | CALLBACK 646 | DetourEnumerateImportsThunk(_In_ PVOID VoidContext, 647 | _In_ DWORD nOrdinal, 648 | _In_opt_ PCSTR pszFunc, 649 | _In_opt_ PVOID* ppvFunc) 650 | { 651 | _DETOUR_ENUMERATE_IMPORTS_THUNK_CONTEXT const * const 652 | pContext = (_DETOUR_ENUMERATE_IMPORTS_THUNK_CONTEXT*)VoidContext; 653 | return pContext->pfImportFunc(pContext->pContext, nOrdinal, pszFunc, ppvFunc ? *ppvFunc : NULL); 654 | } 655 | 656 | BOOL WINAPI DetourEnumerateImports(_In_opt_ HMODULE hModule, 657 | _In_opt_ PVOID pContext, 658 | _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, 659 | _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc) 660 | { 661 | _DETOUR_ENUMERATE_IMPORTS_THUNK_CONTEXT const context = { pContext, pfImportFunc }; 662 | 663 | return DetourEnumerateImportsEx(hModule, 664 | (PVOID)&context, 665 | pfImportFile, 666 | &DetourEnumerateImportsThunk); 667 | } 668 | 669 | static PDETOUR_LOADED_BINARY WINAPI GetPayloadSectionFromModule(HMODULE hModule) 670 | { 671 | PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule; 672 | if (hModule == NULL) { 673 | pDosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL); 674 | } 675 | 676 | __try { 677 | #pragma warning(suppress:6011) // GetModuleHandleW(NULL) never returns NULL. 678 | if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) { 679 | SetLastError(ERROR_BAD_EXE_FORMAT); 680 | return NULL; 681 | } 682 | 683 | PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader + 684 | pDosHeader->e_lfanew); 685 | if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { 686 | SetLastError(ERROR_INVALID_EXE_SIGNATURE); 687 | return NULL; 688 | } 689 | if (pNtHeader->FileHeader.SizeOfOptionalHeader == 0) { 690 | SetLastError(ERROR_EXE_MARKED_INVALID); 691 | return NULL; 692 | } 693 | 694 | PIMAGE_SECTION_HEADER pSectionHeaders 695 | = (PIMAGE_SECTION_HEADER)((PBYTE)pNtHeader 696 | + sizeof(pNtHeader->Signature) 697 | + sizeof(pNtHeader->FileHeader) 698 | + pNtHeader->FileHeader.SizeOfOptionalHeader); 699 | 700 | for (DWORD n = 0; n < pNtHeader->FileHeader.NumberOfSections; n++) { 701 | if (strcmp((PCHAR)pSectionHeaders[n].Name, ".detour") == 0) { 702 | if (pSectionHeaders[n].VirtualAddress == 0 || 703 | pSectionHeaders[n].SizeOfRawData == 0) { 704 | 705 | break; 706 | } 707 | 708 | PBYTE pbData = (PBYTE)pDosHeader + pSectionHeaders[n].VirtualAddress; 709 | DETOUR_SECTION_HEADER *pHeader = (DETOUR_SECTION_HEADER *)pbData; 710 | if (pHeader->cbHeaderSize < sizeof(DETOUR_SECTION_HEADER) || 711 | pHeader->nSignature != DETOUR_SECTION_HEADER_SIGNATURE) { 712 | 713 | break; 714 | } 715 | 716 | if (pHeader->nDataOffset == 0) { 717 | pHeader->nDataOffset = pHeader->cbHeaderSize; 718 | } 719 | SetLastError(NO_ERROR); 720 | return (PBYTE)pHeader; 721 | } 722 | } 723 | SetLastError(ERROR_EXE_MARKED_INVALID); 724 | return NULL; 725 | } 726 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 727 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 728 | SetLastError(ERROR_EXE_MARKED_INVALID); 729 | return NULL; 730 | } 731 | } 732 | 733 | DWORD WINAPI DetourGetSizeOfPayloads(_In_opt_ HMODULE hModule) 734 | { 735 | PDETOUR_LOADED_BINARY pBinary = GetPayloadSectionFromModule(hModule); 736 | if (pBinary == NULL) { 737 | // Error set by GetPayloadSectionFromModule. 738 | return 0; 739 | } 740 | 741 | __try { 742 | DETOUR_SECTION_HEADER *pHeader = (DETOUR_SECTION_HEADER *)pBinary; 743 | if (pHeader->cbHeaderSize < sizeof(DETOUR_SECTION_HEADER) || 744 | pHeader->nSignature != DETOUR_SECTION_HEADER_SIGNATURE) { 745 | 746 | SetLastError(ERROR_INVALID_HANDLE); 747 | return 0; 748 | } 749 | SetLastError(NO_ERROR); 750 | return pHeader->cbDataSize; 751 | } 752 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 753 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 754 | SetLastError(ERROR_INVALID_HANDLE); 755 | return 0; 756 | } 757 | } 758 | 759 | _Writable_bytes_(*pcbData) 760 | _Readable_bytes_(*pcbData) 761 | _Success_(return != NULL) 762 | PVOID WINAPI DetourFindPayload(_In_opt_ HMODULE hModule, 763 | _In_ REFGUID rguid, 764 | _Out_ DWORD *pcbData) 765 | { 766 | PBYTE pbData = NULL; 767 | if (pcbData) { 768 | *pcbData = 0; 769 | } 770 | 771 | PDETOUR_LOADED_BINARY pBinary = GetPayloadSectionFromModule(hModule); 772 | if (pBinary == NULL) { 773 | // Error set by GetPayloadSectionFromModule. 774 | return NULL; 775 | } 776 | 777 | __try { 778 | DETOUR_SECTION_HEADER *pHeader = (DETOUR_SECTION_HEADER *)pBinary; 779 | if (pHeader->cbHeaderSize < sizeof(DETOUR_SECTION_HEADER) || 780 | pHeader->nSignature != DETOUR_SECTION_HEADER_SIGNATURE) { 781 | 782 | SetLastError(ERROR_INVALID_EXE_SIGNATURE); 783 | return NULL; 784 | } 785 | 786 | PBYTE pbBeg = ((PBYTE)pHeader) + pHeader->nDataOffset; 787 | PBYTE pbEnd = ((PBYTE)pHeader) + pHeader->cbDataSize; 788 | 789 | for (pbData = pbBeg; pbData < pbEnd;) { 790 | DETOUR_SECTION_RECORD *pSection = (DETOUR_SECTION_RECORD *)pbData; 791 | 792 | if (pSection->guid.Data1 == rguid.Data1 && 793 | pSection->guid.Data2 == rguid.Data2 && 794 | pSection->guid.Data3 == rguid.Data3 && 795 | pSection->guid.Data4[0] == rguid.Data4[0] && 796 | pSection->guid.Data4[1] == rguid.Data4[1] && 797 | pSection->guid.Data4[2] == rguid.Data4[2] && 798 | pSection->guid.Data4[3] == rguid.Data4[3] && 799 | pSection->guid.Data4[4] == rguid.Data4[4] && 800 | pSection->guid.Data4[5] == rguid.Data4[5] && 801 | pSection->guid.Data4[6] == rguid.Data4[6] && 802 | pSection->guid.Data4[7] == rguid.Data4[7]) { 803 | 804 | if (pcbData) { 805 | *pcbData = pSection->cbBytes - sizeof(*pSection); 806 | } 807 | SetLastError(NO_ERROR); 808 | return (PBYTE)(pSection + 1); 809 | } 810 | 811 | pbData = (PBYTE)pSection + pSection->cbBytes; 812 | } 813 | SetLastError(ERROR_INVALID_HANDLE); 814 | return NULL; 815 | } 816 | __except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? 817 | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 818 | SetLastError(ERROR_INVALID_HANDLE); 819 | return NULL; 820 | } 821 | } 822 | 823 | _Writable_bytes_(*pcbData) 824 | _Readable_bytes_(*pcbData) 825 | _Success_(return != NULL) 826 | PVOID WINAPI DetourFindPayloadEx(_In_ REFGUID rguid, 827 | _Out_ DWORD * pcbData) 828 | { 829 | for (HMODULE hMod = NULL; (hMod = DetourEnumerateModules(hMod)) != NULL;) { 830 | PVOID pvData; 831 | 832 | pvData = DetourFindPayload(hMod, rguid, pcbData); 833 | if (pvData != NULL) { 834 | return pvData; 835 | } 836 | } 837 | SetLastError(ERROR_MOD_NOT_FOUND); 838 | return NULL; 839 | } 840 | 841 | BOOL WINAPI DetourRestoreAfterWithEx(_In_reads_bytes_(cbData) PVOID pvData, 842 | _In_ DWORD cbData) 843 | { 844 | PDETOUR_EXE_RESTORE pder = (PDETOUR_EXE_RESTORE)pvData; 845 | 846 | if (pder->cb != sizeof(*pder) || pder->cb > cbData) { 847 | SetLastError(ERROR_BAD_EXE_FORMAT); 848 | return FALSE; 849 | } 850 | 851 | DWORD dwPermIdh = ~0u; 852 | DWORD dwPermInh = ~0u; 853 | DWORD dwPermClr = ~0u; 854 | DWORD dwIgnore; 855 | BOOL fSucceeded = FALSE; 856 | BOOL fUpdated32To64 = FALSE; 857 | 858 | if (pder->pclr != NULL && pder->clr.Flags != ((PDETOUR_CLR_HEADER)pder->pclr)->Flags) { 859 | // If we had to promote the 32/64-bit agnostic IL to 64-bit, we can't restore 860 | // that. 861 | fUpdated32To64 = TRUE; 862 | } 863 | 864 | if (DetourVirtualProtectSameExecute(pder->pidh, pder->cbidh, 865 | PAGE_EXECUTE_READWRITE, &dwPermIdh)) { 866 | if (DetourVirtualProtectSameExecute(pder->pinh, pder->cbinh, 867 | PAGE_EXECUTE_READWRITE, &dwPermInh)) { 868 | 869 | CopyMemory(pder->pidh, &pder->idh, pder->cbidh); 870 | CopyMemory(pder->pinh, &pder->inh, pder->cbinh); 871 | 872 | if (pder->pclr != NULL && !fUpdated32To64) { 873 | if (DetourVirtualProtectSameExecute(pder->pclr, pder->cbclr, 874 | PAGE_EXECUTE_READWRITE, &dwPermClr)) { 875 | CopyMemory(pder->pclr, &pder->clr, pder->cbclr); 876 | VirtualProtect(pder->pclr, pder->cbclr, dwPermClr, &dwIgnore); 877 | fSucceeded = TRUE; 878 | } 879 | } 880 | else { 881 | fSucceeded = TRUE; 882 | } 883 | VirtualProtect(pder->pinh, pder->cbinh, dwPermInh, &dwIgnore); 884 | } 885 | VirtualProtect(pder->pidh, pder->cbidh, dwPermIdh, &dwIgnore); 886 | } 887 | return fSucceeded; 888 | } 889 | 890 | BOOL WINAPI DetourRestoreAfterWith() 891 | { 892 | PVOID pvData; 893 | DWORD cbData; 894 | 895 | pvData = DetourFindPayloadEx(DETOUR_EXE_RESTORE_GUID, &cbData); 896 | 897 | if (pvData != NULL && cbData != 0) { 898 | return DetourRestoreAfterWithEx(pvData, cbData); 899 | } 900 | SetLastError(ERROR_MOD_NOT_FOUND); 901 | return FALSE; 902 | } 903 | 904 | // End of File 905 | -------------------------------------------------------------------------------- /src/include/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // DEAR IMGUI COMPILE-TIME OPTIONS 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty. 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | // May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included. 54 | //#define IMGUI_INCLUDE_IMGUI_USER_H 55 | //#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h" 56 | 57 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 58 | //#define IMGUI_USE_BGRA_PACKED_COLOR 59 | 60 | //---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 61 | //#define IMGUI_USE_WCHAR32 62 | 63 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 64 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 65 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 66 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 67 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined. 68 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 69 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 70 | //#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. 71 | 72 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 73 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 74 | //#define IMGUI_USE_STB_SPRINTF 75 | 76 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 77 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 78 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 79 | //#define IMGUI_ENABLE_FREETYPE 80 | 81 | //---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) 82 | // Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). 83 | // Only works in combination with IMGUI_ENABLE_FREETYPE. 84 | // (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) 85 | //#define IMGUI_ENABLE_FREETYPE_LUNASVG 86 | 87 | //---- Use stb_truetype to build and rasterize the font atlas (default) 88 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 89 | //#define IMGUI_ENABLE_STB_TRUETYPE 90 | 91 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 92 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 93 | /* 94 | #define IM_VEC2_CLASS_EXTRA \ 95 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 96 | operator MyVec2() const { return MyVec2(x,y); } 97 | 98 | #define IM_VEC4_CLASS_EXTRA \ 99 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 100 | operator MyVec4() const { return MyVec4(x,y,z,w); } 101 | */ 102 | //---- ...Or use Dear ImGui's own very basic math operators. 103 | //#define IMGUI_DEFINE_MATH_OPERATORS 104 | 105 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 106 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 107 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 108 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 109 | //#define ImDrawIdx unsigned int 110 | 111 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 112 | //struct ImDrawList; 113 | //struct ImDrawCmd; 114 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 115 | //#define ImDrawCallback MyImDrawCallback 116 | 117 | //---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) 118 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 119 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 120 | //#define IM_DEBUG_BREAK __debugbreak() 121 | 122 | //---- Debug Tools: Enable slower asserts 123 | //#define IMGUI_DEBUG_PARANOID 124 | 125 | //---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) 126 | /* 127 | namespace ImGui 128 | { 129 | void MyFunction(const char* name, MyMatrix44* mtx); 130 | } 131 | */ 132 | -------------------------------------------------------------------------------- /src/include/imgui/imgui_impl_dx11.cpp: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX11 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | 8 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 9 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 10 | // Learn about Dear ImGui: 11 | // - FAQ https://dearimgui.com/faq 12 | // - Getting Started https://dearimgui.com/getting-started 13 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 14 | // - Introduction, links and more at the top of imgui.cpp 15 | 16 | // CHANGELOG 17 | // (minor and older changes stripped away, please see git history for details) 18 | // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. 19 | // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). 20 | // 2021-05-19: DirectX11: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) 21 | // 2021-02-18: DirectX11: Change blending equation to preserve alpha in output buffer. 22 | // 2019-08-01: DirectX11: Fixed code querying the Geometry Shader state (would generally error with Debug layer enabled). 23 | // 2019-07-21: DirectX11: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData. Clearing Hull/Domain/Compute shaders without backup/restore. 24 | // 2019-05-29: DirectX11: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. 25 | // 2019-04-30: DirectX11: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. 26 | // 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile(). 27 | // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window. 28 | // 2018-08-01: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility. 29 | // 2018-07-13: DirectX11: Fixed unreleased resources in Init and Shutdown functions. 30 | // 2018-06-08: Misc: Extracted imgui_impl_dx11.cpp/.h away from the old combined DX11+Win32 example. 31 | // 2018-06-08: DirectX11: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. 32 | // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX11_RenderDrawData() in the .h file so you can call it yourself. 33 | // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. 34 | // 2016-05-07: DirectX11: Disabling depth-write. 35 | 36 | #include "imgui.h" 37 | #ifndef IMGUI_DISABLE 38 | #include "imgui_impl_dx11.h" 39 | 40 | // DirectX 41 | #include 42 | #include 43 | #include 44 | #ifdef _MSC_VER 45 | #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. 46 | #endif 47 | 48 | // DirectX11 data 49 | struct ImGui_ImplDX11_Data 50 | { 51 | ID3D11Device* pd3dDevice; 52 | ID3D11DeviceContext* pd3dDeviceContext; 53 | IDXGIFactory* pFactory; 54 | ID3D11Buffer* pVB; 55 | ID3D11Buffer* pIB; 56 | ID3D11VertexShader* pVertexShader; 57 | ID3D11InputLayout* pInputLayout; 58 | ID3D11Buffer* pVertexConstantBuffer; 59 | ID3D11PixelShader* pPixelShader; 60 | ID3D11SamplerState* pFontSampler; 61 | ID3D11ShaderResourceView* pFontTextureView; 62 | ID3D11RasterizerState* pRasterizerState; 63 | ID3D11BlendState* pBlendState; 64 | ID3D11DepthStencilState* pDepthStencilState; 65 | int VertexBufferSize; 66 | int IndexBufferSize; 67 | 68 | ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; } 69 | }; 70 | 71 | struct VERTEX_CONSTANT_BUFFER_DX11 72 | { 73 | float mvp[4][4]; 74 | }; 75 | 76 | // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts 77 | // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. 78 | static ImGui_ImplDX11_Data* ImGui_ImplDX11_GetBackendData() 79 | { 80 | return ImGui::GetCurrentContext() ? (ImGui_ImplDX11_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; 81 | } 82 | 83 | // Functions 84 | static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceContext* ctx) 85 | { 86 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 87 | 88 | // Setup viewport 89 | D3D11_VIEWPORT vp; 90 | memset(&vp, 0, sizeof(D3D11_VIEWPORT)); 91 | vp.Width = draw_data->DisplaySize.x; 92 | vp.Height = draw_data->DisplaySize.y; 93 | vp.MinDepth = 0.0f; 94 | vp.MaxDepth = 1.0f; 95 | vp.TopLeftX = vp.TopLeftY = 0; 96 | ctx->RSSetViewports(1, &vp); 97 | 98 | // Setup shader and vertex buffers 99 | unsigned int stride = sizeof(ImDrawVert); 100 | unsigned int offset = 0; 101 | ctx->IASetInputLayout(bd->pInputLayout); 102 | ctx->IASetVertexBuffers(0, 1, &bd->pVB, &stride, &offset); 103 | ctx->IASetIndexBuffer(bd->pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); 104 | ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 105 | ctx->VSSetShader(bd->pVertexShader, nullptr, 0); 106 | ctx->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer); 107 | ctx->PSSetShader(bd->pPixelShader, nullptr, 0); 108 | ctx->PSSetSamplers(0, 1, &bd->pFontSampler); 109 | ctx->GSSetShader(nullptr, nullptr, 0); 110 | ctx->HSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 111 | ctx->DSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 112 | ctx->CSSetShader(nullptr, nullptr, 0); // In theory we should backup and restore this as well.. very infrequently used.. 113 | 114 | // Setup blend state 115 | const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; 116 | ctx->OMSetBlendState(bd->pBlendState, blend_factor, 0xffffffff); 117 | ctx->OMSetDepthStencilState(bd->pDepthStencilState, 0); 118 | ctx->RSSetState(bd->pRasterizerState); 119 | } 120 | 121 | // Render function 122 | void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) 123 | { 124 | // Avoid rendering when minimized 125 | if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f) 126 | return; 127 | 128 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 129 | ID3D11DeviceContext* ctx = bd->pd3dDeviceContext; 130 | 131 | // Create and grow vertex/index buffers if needed 132 | if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount) 133 | { 134 | if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } 135 | bd->VertexBufferSize = draw_data->TotalVtxCount + 5000; 136 | D3D11_BUFFER_DESC desc; 137 | memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); 138 | desc.Usage = D3D11_USAGE_DYNAMIC; 139 | desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert); 140 | desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; 141 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 142 | desc.MiscFlags = 0; 143 | if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVB) < 0) 144 | return; 145 | } 146 | if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount) 147 | { 148 | if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } 149 | bd->IndexBufferSize = draw_data->TotalIdxCount + 10000; 150 | D3D11_BUFFER_DESC desc; 151 | memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); 152 | desc.Usage = D3D11_USAGE_DYNAMIC; 153 | desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx); 154 | desc.BindFlags = D3D11_BIND_INDEX_BUFFER; 155 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 156 | if (bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pIB) < 0) 157 | return; 158 | } 159 | 160 | // Upload vertex/index data into a single contiguous GPU buffer 161 | D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource; 162 | if (ctx->Map(bd->pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK) 163 | return; 164 | if (ctx->Map(bd->pIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &idx_resource) != S_OK) 165 | return; 166 | ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData; 167 | ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource.pData; 168 | for (int n = 0; n < draw_data->CmdListsCount; n++) 169 | { 170 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 171 | memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); 172 | memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); 173 | vtx_dst += cmd_list->VtxBuffer.Size; 174 | idx_dst += cmd_list->IdxBuffer.Size; 175 | } 176 | ctx->Unmap(bd->pVB, 0); 177 | ctx->Unmap(bd->pIB, 0); 178 | 179 | // Setup orthographic projection matrix into our constant buffer 180 | // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. 181 | { 182 | D3D11_MAPPED_SUBRESOURCE mapped_resource; 183 | if (ctx->Map(bd->pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) 184 | return; 185 | VERTEX_CONSTANT_BUFFER_DX11* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX11*)mapped_resource.pData; 186 | float L = draw_data->DisplayPos.x; 187 | float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; 188 | float T = draw_data->DisplayPos.y; 189 | float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y; 190 | float mvp[4][4] = 191 | { 192 | { 2.0f/(R-L), 0.0f, 0.0f, 0.0f }, 193 | { 0.0f, 2.0f/(T-B), 0.0f, 0.0f }, 194 | { 0.0f, 0.0f, 0.5f, 0.0f }, 195 | { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, 196 | }; 197 | memcpy(&constant_buffer->mvp, mvp, sizeof(mvp)); 198 | ctx->Unmap(bd->pVertexConstantBuffer, 0); 199 | } 200 | 201 | // Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!) 202 | struct BACKUP_DX11_STATE 203 | { 204 | UINT ScissorRectsCount, ViewportsCount; 205 | D3D11_RECT ScissorRects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; 206 | D3D11_VIEWPORT Viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; 207 | ID3D11RasterizerState* RS; 208 | ID3D11BlendState* BlendState; 209 | FLOAT BlendFactor[4]; 210 | UINT SampleMask; 211 | UINT StencilRef; 212 | ID3D11DepthStencilState* DepthStencilState; 213 | ID3D11ShaderResourceView* PSShaderResource; 214 | ID3D11SamplerState* PSSampler; 215 | ID3D11PixelShader* PS; 216 | ID3D11VertexShader* VS; 217 | ID3D11GeometryShader* GS; 218 | UINT PSInstancesCount, VSInstancesCount, GSInstancesCount; 219 | ID3D11ClassInstance *PSInstances[256], *VSInstances[256], *GSInstances[256]; // 256 is max according to PSSetShader documentation 220 | D3D11_PRIMITIVE_TOPOLOGY PrimitiveTopology; 221 | ID3D11Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer; 222 | UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset; 223 | DXGI_FORMAT IndexBufferFormat; 224 | ID3D11InputLayout* InputLayout; 225 | }; 226 | BACKUP_DX11_STATE old = {}; 227 | old.ScissorRectsCount = old.ViewportsCount = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; 228 | ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects); 229 | ctx->RSGetViewports(&old.ViewportsCount, old.Viewports); 230 | ctx->RSGetState(&old.RS); 231 | ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask); 232 | ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef); 233 | ctx->PSGetShaderResources(0, 1, &old.PSShaderResource); 234 | ctx->PSGetSamplers(0, 1, &old.PSSampler); 235 | old.PSInstancesCount = old.VSInstancesCount = old.GSInstancesCount = 256; 236 | ctx->PSGetShader(&old.PS, old.PSInstances, &old.PSInstancesCount); 237 | ctx->VSGetShader(&old.VS, old.VSInstances, &old.VSInstancesCount); 238 | ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer); 239 | ctx->GSGetShader(&old.GS, old.GSInstances, &old.GSInstancesCount); 240 | 241 | ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology); 242 | ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset); 243 | ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); 244 | ctx->IAGetInputLayout(&old.InputLayout); 245 | 246 | // Setup desired DX state 247 | ImGui_ImplDX11_SetupRenderState(draw_data, ctx); 248 | 249 | // Render command lists 250 | // (Because we merged all buffers into a single one, we maintain our own offset into them) 251 | int global_idx_offset = 0; 252 | int global_vtx_offset = 0; 253 | ImVec2 clip_off = draw_data->DisplayPos; 254 | for (int n = 0; n < draw_data->CmdListsCount; n++) 255 | { 256 | const ImDrawList* cmd_list = draw_data->CmdLists[n]; 257 | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) 258 | { 259 | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; 260 | if (pcmd->UserCallback != nullptr) 261 | { 262 | // User callback, registered via ImDrawList::AddCallback() 263 | // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) 264 | if (pcmd->UserCallback == ImDrawCallback_ResetRenderState) 265 | ImGui_ImplDX11_SetupRenderState(draw_data, ctx); 266 | else 267 | pcmd->UserCallback(cmd_list, pcmd); 268 | } 269 | else 270 | { 271 | // Project scissor/clipping rectangles into framebuffer space 272 | ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y); 273 | ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y); 274 | if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) 275 | continue; 276 | 277 | // Apply scissor/clipping rectangle 278 | const D3D11_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y }; 279 | ctx->RSSetScissorRects(1, &r); 280 | 281 | // Bind texture, Draw 282 | ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->GetTexID(); 283 | ctx->PSSetShaderResources(0, 1, &texture_srv); 284 | ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset); 285 | } 286 | } 287 | global_idx_offset += cmd_list->IdxBuffer.Size; 288 | global_vtx_offset += cmd_list->VtxBuffer.Size; 289 | } 290 | 291 | // Restore modified DX state 292 | ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects); 293 | ctx->RSSetViewports(old.ViewportsCount, old.Viewports); 294 | ctx->RSSetState(old.RS); if (old.RS) old.RS->Release(); 295 | ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release(); 296 | ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release(); 297 | ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release(); 298 | ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release(); 299 | ctx->PSSetShader(old.PS, old.PSInstances, old.PSInstancesCount); if (old.PS) old.PS->Release(); 300 | for (UINT i = 0; i < old.PSInstancesCount; i++) if (old.PSInstances[i]) old.PSInstances[i]->Release(); 301 | ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount); if (old.VS) old.VS->Release(); 302 | ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release(); 303 | ctx->GSSetShader(old.GS, old.GSInstances, old.GSInstancesCount); if (old.GS) old.GS->Release(); 304 | for (UINT i = 0; i < old.VSInstancesCount; i++) if (old.VSInstances[i]) old.VSInstances[i]->Release(); 305 | ctx->IASetPrimitiveTopology(old.PrimitiveTopology); 306 | ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release(); 307 | ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release(); 308 | ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); 309 | } 310 | 311 | static void ImGui_ImplDX11_CreateFontsTexture() 312 | { 313 | // Build texture atlas 314 | ImGuiIO& io = ImGui::GetIO(); 315 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 316 | unsigned char* pixels; 317 | int width, height; 318 | io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); 319 | 320 | // Upload texture to graphics system 321 | { 322 | D3D11_TEXTURE2D_DESC desc; 323 | ZeroMemory(&desc, sizeof(desc)); 324 | desc.Width = width; 325 | desc.Height = height; 326 | desc.MipLevels = 1; 327 | desc.ArraySize = 1; 328 | desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 329 | desc.SampleDesc.Count = 1; 330 | desc.Usage = D3D11_USAGE_DEFAULT; 331 | desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 332 | desc.CPUAccessFlags = 0; 333 | 334 | ID3D11Texture2D* pTexture = nullptr; 335 | D3D11_SUBRESOURCE_DATA subResource; 336 | subResource.pSysMem = pixels; 337 | subResource.SysMemPitch = desc.Width * 4; 338 | subResource.SysMemSlicePitch = 0; 339 | bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); 340 | IM_ASSERT(pTexture != nullptr); 341 | 342 | // Create texture view 343 | D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; 344 | ZeroMemory(&srvDesc, sizeof(srvDesc)); 345 | srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 346 | srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; 347 | srvDesc.Texture2D.MipLevels = desc.MipLevels; 348 | srvDesc.Texture2D.MostDetailedMip = 0; 349 | bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &bd->pFontTextureView); 350 | pTexture->Release(); 351 | } 352 | 353 | // Store our identifier 354 | io.Fonts->SetTexID((ImTextureID)bd->pFontTextureView); 355 | 356 | // Create texture sampler 357 | // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling) 358 | { 359 | D3D11_SAMPLER_DESC desc; 360 | ZeroMemory(&desc, sizeof(desc)); 361 | desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; 362 | desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; 363 | desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; 364 | desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; 365 | desc.MipLODBias = 0.f; 366 | desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; 367 | desc.MinLOD = 0.f; 368 | desc.MaxLOD = 0.f; 369 | bd->pd3dDevice->CreateSamplerState(&desc, &bd->pFontSampler); 370 | } 371 | } 372 | 373 | bool ImGui_ImplDX11_CreateDeviceObjects() 374 | { 375 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 376 | if (!bd->pd3dDevice) 377 | return false; 378 | if (bd->pFontSampler) 379 | ImGui_ImplDX11_InvalidateDeviceObjects(); 380 | 381 | // By using D3DCompile() from / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) 382 | // If you would like to use this DX11 sample code but remove this dependency you can: 383 | // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution] 384 | // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL. 385 | // See https://github.com/ocornut/imgui/pull/638 for sources and details. 386 | 387 | // Create the vertex shader 388 | { 389 | static const char* vertexShader = 390 | "cbuffer vertexBuffer : register(b0) \ 391 | {\ 392 | float4x4 ProjectionMatrix; \ 393 | };\ 394 | struct VS_INPUT\ 395 | {\ 396 | float2 pos : POSITION;\ 397 | float4 col : COLOR0;\ 398 | float2 uv : TEXCOORD0;\ 399 | };\ 400 | \ 401 | struct PS_INPUT\ 402 | {\ 403 | float4 pos : SV_POSITION;\ 404 | float4 col : COLOR0;\ 405 | float2 uv : TEXCOORD0;\ 406 | };\ 407 | \ 408 | PS_INPUT main(VS_INPUT input)\ 409 | {\ 410 | PS_INPUT output;\ 411 | output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ 412 | output.col = input.col;\ 413 | output.uv = input.uv;\ 414 | return output;\ 415 | }"; 416 | 417 | ID3DBlob* vertexShaderBlob; 418 | if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr))) 419 | return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! 420 | if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), nullptr, &bd->pVertexShader) != S_OK) 421 | { 422 | vertexShaderBlob->Release(); 423 | return false; 424 | } 425 | 426 | // Create the input layout 427 | D3D11_INPUT_ELEMENT_DESC local_layout[] = 428 | { 429 | { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 430 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 431 | { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)offsetof(ImDrawVert, col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, 432 | }; 433 | if (bd->pd3dDevice->CreateInputLayout(local_layout, 3, vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pInputLayout) != S_OK) 434 | { 435 | vertexShaderBlob->Release(); 436 | return false; 437 | } 438 | vertexShaderBlob->Release(); 439 | 440 | // Create the constant buffer 441 | { 442 | D3D11_BUFFER_DESC desc; 443 | desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER_DX11); 444 | desc.Usage = D3D11_USAGE_DYNAMIC; 445 | desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 446 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 447 | desc.MiscFlags = 0; 448 | bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVertexConstantBuffer); 449 | } 450 | } 451 | 452 | // Create the pixel shader 453 | { 454 | static const char* pixelShader = 455 | "struct PS_INPUT\ 456 | {\ 457 | float4 pos : SV_POSITION;\ 458 | float4 col : COLOR0;\ 459 | float2 uv : TEXCOORD0;\ 460 | };\ 461 | sampler sampler0;\ 462 | Texture2D texture0;\ 463 | \ 464 | float4 main(PS_INPUT input) : SV_Target\ 465 | {\ 466 | float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \ 467 | return out_col; \ 468 | }"; 469 | 470 | ID3DBlob* pixelShaderBlob; 471 | if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr))) 472 | return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! 473 | if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), nullptr, &bd->pPixelShader) != S_OK) 474 | { 475 | pixelShaderBlob->Release(); 476 | return false; 477 | } 478 | pixelShaderBlob->Release(); 479 | } 480 | 481 | // Create the blending setup 482 | { 483 | D3D11_BLEND_DESC desc; 484 | ZeroMemory(&desc, sizeof(desc)); 485 | desc.AlphaToCoverageEnable = false; 486 | desc.RenderTarget[0].BlendEnable = true; 487 | desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; 488 | desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; 489 | desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; 490 | desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; 491 | desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; 492 | desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; 493 | desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; 494 | bd->pd3dDevice->CreateBlendState(&desc, &bd->pBlendState); 495 | } 496 | 497 | // Create the rasterizer state 498 | { 499 | D3D11_RASTERIZER_DESC desc; 500 | ZeroMemory(&desc, sizeof(desc)); 501 | desc.FillMode = D3D11_FILL_SOLID; 502 | desc.CullMode = D3D11_CULL_NONE; 503 | desc.ScissorEnable = true; 504 | desc.DepthClipEnable = true; 505 | bd->pd3dDevice->CreateRasterizerState(&desc, &bd->pRasterizerState); 506 | } 507 | 508 | // Create depth-stencil State 509 | { 510 | D3D11_DEPTH_STENCIL_DESC desc; 511 | ZeroMemory(&desc, sizeof(desc)); 512 | desc.DepthEnable = false; 513 | desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; 514 | desc.DepthFunc = D3D11_COMPARISON_ALWAYS; 515 | desc.StencilEnable = false; 516 | desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; 517 | desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; 518 | desc.BackFace = desc.FrontFace; 519 | bd->pd3dDevice->CreateDepthStencilState(&desc, &bd->pDepthStencilState); 520 | } 521 | 522 | ImGui_ImplDX11_CreateFontsTexture(); 523 | 524 | return true; 525 | } 526 | 527 | void ImGui_ImplDX11_InvalidateDeviceObjects() 528 | { 529 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 530 | if (!bd->pd3dDevice) 531 | return; 532 | 533 | if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = nullptr; } 534 | if (bd->pFontTextureView) { bd->pFontTextureView->Release(); bd->pFontTextureView = nullptr; ImGui::GetIO().Fonts->SetTexID(0); } // We copied data->pFontTextureView to io.Fonts->TexID so let's clear that as well. 535 | if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; } 536 | if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; } 537 | if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; } 538 | if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = nullptr; } 539 | if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = nullptr; } 540 | if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = nullptr; } 541 | if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = nullptr; } 542 | if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = nullptr; } 543 | if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = nullptr; } 544 | } 545 | 546 | bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context) 547 | { 548 | ImGuiIO& io = ImGui::GetIO(); 549 | IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); 550 | 551 | // Setup backend capabilities flags 552 | ImGui_ImplDX11_Data* bd = IM_NEW(ImGui_ImplDX11_Data)(); 553 | io.BackendRendererUserData = (void*)bd; 554 | io.BackendRendererName = "imgui_impl_dx11"; 555 | io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. 556 | 557 | // Get factory from device 558 | IDXGIDevice* pDXGIDevice = nullptr; 559 | IDXGIAdapter* pDXGIAdapter = nullptr; 560 | IDXGIFactory* pFactory = nullptr; 561 | 562 | if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK) 563 | if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK) 564 | if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK) 565 | { 566 | bd->pd3dDevice = device; 567 | bd->pd3dDeviceContext = device_context; 568 | bd->pFactory = pFactory; 569 | } 570 | if (pDXGIDevice) pDXGIDevice->Release(); 571 | if (pDXGIAdapter) pDXGIAdapter->Release(); 572 | bd->pd3dDevice->AddRef(); 573 | bd->pd3dDeviceContext->AddRef(); 574 | 575 | return true; 576 | } 577 | 578 | void ImGui_ImplDX11_Shutdown() 579 | { 580 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 581 | IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); 582 | ImGuiIO& io = ImGui::GetIO(); 583 | 584 | ImGui_ImplDX11_InvalidateDeviceObjects(); 585 | if (bd->pFactory) { bd->pFactory->Release(); } 586 | if (bd->pd3dDevice) { bd->pd3dDevice->Release(); } 587 | if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); } 588 | io.BackendRendererName = nullptr; 589 | io.BackendRendererUserData = nullptr; 590 | io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; 591 | IM_DELETE(bd); 592 | } 593 | 594 | void ImGui_ImplDX11_NewFrame() 595 | { 596 | ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); 597 | IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX11_Init()?"); 598 | 599 | if (!bd->pFontSampler) 600 | ImGui_ImplDX11_CreateDeviceObjects(); 601 | } 602 | 603 | //----------------------------------------------------------------------------- 604 | 605 | #endif // #ifndef IMGUI_DISABLE 606 | -------------------------------------------------------------------------------- /src/include/imgui/imgui_impl_dx11.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX11 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | 8 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 9 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 10 | // Learn about Dear ImGui: 11 | // - FAQ https://dearimgui.com/faq 12 | // - Getting Started https://dearimgui.com/getting-started 13 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 14 | // - Introduction, links and more at the top of imgui.cpp 15 | 16 | #pragma once 17 | #include "imgui.h" // IMGUI_IMPL_API 18 | #ifndef IMGUI_DISABLE 19 | 20 | struct ID3D11Device; 21 | struct ID3D11DeviceContext; 22 | 23 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 24 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 25 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 26 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 27 | 28 | // Use if you want to reset your rendering device without losing Dear ImGui state. 29 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 30 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 31 | 32 | #endif // #ifndef IMGUI_DISABLE 33 | -------------------------------------------------------------------------------- /src/include/imgui/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for Windows (standard windows API for 32-bits AND 64-bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. 7 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 10 | 11 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 12 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 13 | // Learn about Dear ImGui: 14 | // - FAQ https://dearimgui.com/faq 15 | // - Getting Started https://dearimgui.com/getting-started 16 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 17 | // - Introduction, links and more at the top of imgui.cpp 18 | 19 | #pragma once 20 | #include "imgui.h" // IMGUI_IMPL_API 21 | #ifndef IMGUI_DISABLE 22 | 23 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 24 | IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); 25 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 26 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 27 | 28 | // Win32 message handler your application need to call. 29 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 30 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 31 | // - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. 32 | 33 | #if 0 34 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 35 | #endif 36 | 37 | // DPI-related helpers (optional) 38 | // - Use to enable DPI awareness without having to create an application manifest. 39 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 40 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 41 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 42 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 43 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 44 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 45 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 46 | 47 | // Transparency related helpers (optional) [experimental] 48 | // - Use to enable alpha compositing transparency with the desktop. 49 | // - Use together with e.g. clearing your framebuffer with zero-alpha. 50 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd); // HWND hwnd 51 | 52 | #endif // #ifndef IMGUI_DISABLE 53 | -------------------------------------------------------------------------------- /src/include/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 | -------------------------------------------------------------------------------- /src/include/oxorany/oxorany.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | @author llxiaoyuan https://github.com/llxiaoyuan/oxorany 4 | 5 | MIT License 6 | 7 | Copyright (c) 2021 Chase 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | */ 28 | 29 | 30 | #include "oxorany.h" 31 | 32 | size_t& _lxy_oxor_any_::X() { 33 | static size_t x = 0; 34 | return x; 35 | } 36 | 37 | size_t& _lxy_oxor_any_::Y() { 38 | static size_t y = 0; 39 | return y; 40 | } -------------------------------------------------------------------------------- /src/include/oxorany/oxorany.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | 4 | @author llxiaoyuan https://github.com/llxiaoyuan/oxorany 5 | 6 | MIT License 7 | 8 | Copyright (c) 2021 Chase 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | 28 | */ 29 | 30 | #ifndef OXORANY_H 31 | #define OXORANY_H 32 | 33 | #if _KERNEL_MODE 34 | #include 35 | typedef UINT8 _lxy__uint8_t; 36 | typedef UINT32 _lxy__uint32_t; 37 | typedef UINT64 _lxy__uint64_t; 38 | typedef SIZE_T _lxy__size_t; 39 | #else 40 | #include 41 | typedef uint8_t _lxy__uint8_t; 42 | typedef uint32_t _lxy__uint32_t; 43 | typedef uint64_t _lxy__uint64_t; 44 | typedef size_t _lxy__size_t; 45 | #endif 46 | 47 | #if _WIN32 || _WIN64 48 | #if _WIN64 49 | #define OXORANY_ENVIRONMENT64 50 | #else 51 | #define OXORANY_ENVIRONMENT32 52 | #endif 53 | #endif 54 | 55 | #if __GNUC__ 56 | #if __x86_64__ || __ppc64__ 57 | #define OXORANY_ENVIRONMENT64 58 | #else 59 | #define OXORANY_ENVIRONMENT32 60 | #endif 61 | #endif 62 | 63 | #ifdef _MSC_VER 64 | #define OXORANY_FORCEINLINE __forceinline 65 | #else 66 | #define OXORANY_FORCEINLINE __attribute__((always_inline)) inline 67 | #endif 68 | 69 | #ifdef _DEBUG 70 | #define oxorany 71 | #define oxorany_flt 72 | #else 73 | #define oxorany(any) _lxy_oxor_any_::oxor_any(any, _lxy_::make_index_sequence()).get() 74 | 75 | #ifdef OXORANY_USE_BIT_CAST 76 | #define oxorany_flt(any) _lxy_::_Bit_cast(oxorany((_lxy_::integral_constant::type,_lxy_::_Bit_cast::type>(any)>::value))) 77 | #endif // OXORANY_USE_BIT_CAST 78 | 79 | #endif 80 | 81 | namespace _lxy_ { 82 | 83 | template 84 | struct type_cast { using type = T; }; 85 | 86 | template<> 87 | struct type_cast { using type = _lxy__uint32_t; }; 88 | 89 | template<> 90 | struct type_cast { using type = _lxy__uint64_t; }; 91 | 92 | template 93 | struct integral_constant { 94 | static constexpr _Ty value = _Val; 95 | 96 | using value_type = _Ty; 97 | using type = integral_constant; 98 | 99 | constexpr operator value_type() const noexcept { 100 | return value; 101 | } 102 | 103 | /*_NODISCARD*/ constexpr value_type operator()() const noexcept { 104 | return value; 105 | } 106 | }; 107 | 108 | #ifdef OXORANY_USE_BIT_CAST 109 | template 110 | /*_NODISCARD*/ constexpr _To _Bit_cast(const _From& _Val) noexcept { 111 | return __builtin_bit_cast(_To, _Val); 112 | } 113 | #endif 114 | 115 | // https://stackoverflow.com/a/32223343/16602611 116 | 117 | template <_lxy__size_t... Ints> 118 | struct index_sequence { 119 | using type = index_sequence; 120 | using value_type = _lxy__size_t; 121 | static constexpr _lxy__size_t size() noexcept { return sizeof...(Ints); } 122 | }; 123 | 124 | // -------------------------------------------------------------------- 125 | 126 | template 127 | struct _merge_and_renumber; 128 | 129 | template <_lxy__size_t... I1, _lxy__size_t... I2> 130 | struct _merge_and_renumber, index_sequence> 131 | : index_sequence 132 | { }; 133 | 134 | // -------------------------------------------------------------------- 135 | 136 | template <_lxy__size_t N> 137 | struct make_index_sequence 138 | : _merge_and_renumber::type, 139 | typename make_index_sequence::type> 140 | { }; 141 | 142 | template<> struct make_index_sequence<0> : index_sequence<> { }; 143 | template<> struct make_index_sequence<1> : index_sequence<0> { }; 144 | } 145 | 146 | namespace _lxy_oxor_any_ { 147 | 148 | /* 149 | template <_lxy__size_t ...> 150 | struct indexSequence { 151 | }; 152 | 153 | template <_lxy__size_t N, _lxy__size_t ... Next> 154 | struct indexSequenceHelper : public indexSequenceHelper { 155 | }; 156 | 157 | template <_lxy__size_t ... Next> 158 | struct indexSequenceHelper<0U, Next ... > { 159 | using type = indexSequence; 160 | }; 161 | 162 | template <_lxy__size_t N> 163 | using makeIndexSequence = typename indexSequenceHelper::type; 164 | */ 165 | 166 | _lxy__size_t& X(); 167 | 168 | _lxy__size_t& Y(); 169 | 170 | static constexpr _lxy__size_t base_key = static_cast<_lxy__size_t>( 171 | ((_lxy__size_t)__TIME__[7] - '0') + 172 | ((_lxy__size_t)__TIME__[6] - '0') * 10 + 173 | ((_lxy__size_t)__TIME__[4] - '0') * 60 + 174 | ((_lxy__size_t)__TIME__[3] - '0') * 600 + 175 | ((_lxy__size_t)__TIME__[1] - '0') * 3600 + 176 | ((_lxy__size_t)__TIME__[0] - '0') * 36000); 177 | 178 | template<_lxy__uint32_t s, _lxy__size_t n> 179 | class random_constant_32 { 180 | static constexpr _lxy__uint32_t x = s ^ (s << 13); 181 | static constexpr _lxy__uint32_t y = x ^ (x >> 17); 182 | static constexpr _lxy__uint32_t z = y ^ (y << 5); 183 | public: 184 | static constexpr _lxy__uint32_t value = random_constant_32::value; 185 | }; 186 | 187 | template<_lxy__uint32_t s> 188 | class random_constant_32 { 189 | public: 190 | static constexpr _lxy__uint32_t value = s; 191 | }; 192 | 193 | template<_lxy__uint64_t s, _lxy__size_t n> 194 | class random_constant_64 { 195 | static constexpr _lxy__uint64_t x = s ^ (s << 13); 196 | static constexpr _lxy__uint64_t y = x ^ (x >> 7); 197 | static constexpr _lxy__uint64_t z = y ^ (y << 17); 198 | public: 199 | static constexpr _lxy__uint64_t value = random_constant_64::value; 200 | }; 201 | 202 | template<_lxy__uint64_t s> 203 | class random_constant_64 { 204 | public: 205 | static constexpr _lxy__uint64_t value = s; 206 | }; 207 | 208 | #ifdef OXORANY_ENVIRONMENT64 209 | #define random_constant random_constant_64 210 | #else 211 | #define random_constant random_constant_32 212 | #endif 213 | 214 | template 215 | static OXORANY_FORCEINLINE constexpr _lxy__size_t array_size(const T(&)[size]) { return size; } 216 | 217 | template 218 | static OXORANY_FORCEINLINE constexpr _lxy__size_t array_size(T) { return 0; } 219 | 220 | template 221 | static inline T typeofs(const T(&)[size]); 222 | 223 | template 224 | static inline T typeofs(T); 225 | 226 | template<_lxy__size_t key> 227 | static OXORANY_FORCEINLINE constexpr _lxy__uint8_t encrypt_byte(_lxy__uint8_t c, _lxy__size_t i) { 228 | return static_cast<_lxy__uint8_t>(((c + (key * 7)) ^ (i + key))); 229 | } 230 | 231 | template<_lxy__size_t key> 232 | static OXORANY_FORCEINLINE constexpr _lxy__uint8_t decrypt_byte(_lxy__uint8_t c, _lxy__size_t i) { 233 | //a ^ b == (a + b) - 2 * (a & b) 234 | _lxy__size_t a = c; 235 | _lxy__size_t b = i + key; 236 | //_lxy__size_t a_xor_b = (a + b) - 2 * (a & b); 237 | _lxy__size_t a_xor_b = (a + b) - ((a & b) + (b & a)); 238 | //_lxy__size_t a_xor_b = (a + b) - (a & b) - (b & a); 239 | return static_cast<_lxy__uint8_t>((a_xor_b)-(key * 7)); 240 | } 241 | 242 | template<_lxy__size_t key> 243 | static OXORANY_FORCEINLINE constexpr _lxy__size_t limit() { 244 | constexpr _lxy__size_t bcf_value[] = { 1,2,3,4,5, 6,8,9,10,16, 32,40,64,66,100, 128,512,1000,1024,4096, 'a','z','A','Z','*' }; 245 | return bcf_value[key % (sizeof(bcf_value) / sizeof(bcf_value[0]))]; 246 | } 247 | 248 | template 249 | static OXORANY_FORCEINLINE const return_type decrypt(_lxy__uint8_t(&buffer)[size]) { 250 | #ifndef OXORANY_DISABLE_OBFUSCATION 251 | 252 | _lxy__uint8_t source; 253 | _lxy__uint8_t decrypted; //do not assign initial value 254 | _lxy__size_t stack_x; 255 | _lxy__size_t stack_y; 256 | 257 | loc_start_1: 258 | stack_x = X(); 259 | stack_y = Y(); 260 | loc_start_2: 261 | for (_lxy__size_t i = 0; i < size; i++) { 262 | source = buffer[i]; 263 | loc_start_3: 264 | if (stack_x <= i) { 265 | if (stack_x < stack_y + limit()) { 266 | decrypted = decrypt_byte(source, i);//fake 267 | } 268 | else if (stack_x == stack_y + limit() % 1 + 1) { 269 | //unreachable 270 | decrypted = decrypt_byte(source, i); 271 | goto loc_unreachable_9; 272 | } 273 | else if (stack_x == stack_y + limit() % 2 + 1) { 274 | //unreachable 275 | decrypted = decrypt_byte(source, i); 276 | goto loc_unreachable_8; 277 | } 278 | else if (stack_x == stack_y + limit() % 3 + 1) { 279 | //unreachable 280 | decrypted = decrypt_byte(source, i); 281 | goto loc_unreachable_7; 282 | } 283 | else if (stack_x == stack_y + limit() % 4 + 1) { 284 | //unreachable 285 | decrypted = decrypt_byte(source, i); 286 | goto loc_unreachable_6; 287 | } 288 | else if (stack_x == stack_y + limit() % 5 + 1) { 289 | //unreachable 290 | decrypted = decrypt_byte(source, i); 291 | goto loc_unreachable_5; 292 | } 293 | else if (stack_x == stack_y + limit() % 6 + 1) { 294 | //unreachable 295 | decrypted = decrypt_byte(source, i); 296 | goto loc_unreachable_4; 297 | } 298 | else if (stack_x == stack_y + limit() % 7 + 1) { 299 | //unreachable 300 | decrypted = decrypt_byte(source, i); 301 | goto loc_unreachable_3; 302 | } 303 | else if (stack_x == stack_y + limit() % 8 + 1) { 304 | //unreachable 305 | decrypted = decrypt_byte(source, i); 306 | goto loc_unreachable_2; 307 | } 308 | else if (stack_x == stack_y + limit() % 9 + 1) { 309 | //unreachable 310 | decrypted = decrypt_byte(source, i); 311 | goto loc_unreachable_1; 312 | } 313 | loc_start_4: 314 | if (stack_y <= i) { 315 | if (stack_x < stack_y + limit()) { 316 | decrypted = decrypt_byte(source, i);//fake 317 | } 318 | else if (stack_x == stack_y + limit() % 1 + 1) { 319 | //unreachable 320 | decrypted = decrypt_byte(source, i); 321 | goto loc_unreachable_1; 322 | } 323 | else if (stack_x == stack_y + limit() % 2 + 1) { 324 | //unreachable 325 | decrypted = decrypt_byte(source, i); 326 | goto loc_unreachable_2; 327 | } 328 | else if (stack_x == stack_y + limit() % 3 + 1) { 329 | //unreachable 330 | decrypted = decrypt_byte(source, i); 331 | goto loc_unreachable_3; 332 | } 333 | else if (stack_x == stack_y + limit() % 4 + 1) { 334 | //unreachable 335 | decrypted = decrypt_byte(source, i); 336 | goto loc_unreachable_4; 337 | } 338 | else if (stack_x == stack_y + limit() % 5 + 1) { 339 | //unreachable 340 | decrypted = decrypt_byte(source, i); 341 | goto loc_unreachable_5; 342 | } 343 | else if (stack_x == stack_y + limit() % 6 + 1) { 344 | //unreachable 345 | decrypted = decrypt_byte(source, i); 346 | goto loc_unreachable_6; 347 | } 348 | else if (stack_x == stack_y + limit() % 7 + 1) { 349 | //unreachable 350 | decrypted = decrypt_byte(source, i); 351 | goto loc_unreachable_7; 352 | } 353 | else if (stack_x == stack_y + limit() % 8 + 1) { 354 | //unreachable 355 | decrypted = decrypt_byte(source, i); 356 | goto loc_unreachable_8; 357 | } 358 | else if (stack_x == stack_y + limit() % 9 + 1) { 359 | //unreachable 360 | decrypted = decrypt_byte(source, i); 361 | goto loc_unreachable_9; 362 | } 363 | loc_start_5: 364 | if (stack_x + stack_y <= i) { 365 | if (stack_x < stack_y + limit()) { 366 | decrypted = decrypt_byte(source, i);//real 367 | } 368 | else if (stack_x == stack_y + limit() % 1 + 1) { 369 | //unreachable 370 | decrypted = decrypt_byte(source, i); 371 | goto loc_unreachable_9; 372 | } 373 | else if (stack_x == stack_y + limit() % 2 + 1) { 374 | //unreachable 375 | decrypted = decrypt_byte(source, i); 376 | goto loc_unreachable_8; 377 | } 378 | else if (stack_x == stack_y + limit() % 3 + 1) { 379 | //unreachable 380 | decrypted = decrypt_byte(source, i); 381 | goto loc_unreachable_7; 382 | } 383 | else if (stack_x == stack_y + limit() % 4 + 1) { 384 | //unreachable 385 | decrypted = decrypt_byte(source, i); 386 | goto loc_unreachable_6; 387 | } 388 | else if (stack_x == stack_y + limit() % 5 + 1) { 389 | //unreachable 390 | decrypted = decrypt_byte(source, i); 391 | goto loc_unreachable_5; 392 | } 393 | else if (stack_x == stack_y + limit() % 6 + 1) { 394 | //unreachable 395 | decrypted = decrypt_byte(source, i); 396 | goto loc_unreachable_4; 397 | } 398 | else if (stack_x == stack_y + limit() % 7 + 1) { 399 | //unreachable 400 | decrypted = decrypt_byte(source, i); 401 | goto loc_unreachable_3; 402 | } 403 | else if (stack_x == stack_y + limit() % 8 + 1) { 404 | //unreachable 405 | decrypted = decrypt_byte(source, i); 406 | goto loc_unreachable_2; 407 | } 408 | else if (stack_x == stack_y + limit() % 9 + 1) { 409 | //unreachable 410 | decrypted = decrypt_byte(source, i); 411 | goto loc_unreachable_1; 412 | } 413 | loc_start_6: 414 | if (stack_x + stack_y != limit()) { 415 | if (stack_x > stack_y + limit()) { 416 | //unreachable 417 | decrypted = decrypt_byte(source, i); 418 | } 419 | else if (stack_x == stack_y + limit() % 1 + 1) { 420 | //unreachable 421 | decrypted = decrypt_byte(source, i); 422 | goto loc_unreachable_1; 423 | } 424 | else if (stack_x == stack_y + limit() % 2 + 1) { 425 | //unreachable 426 | decrypted = decrypt_byte(source, i); 427 | goto loc_unreachable_2; 428 | } 429 | else if (stack_x == stack_y + limit() % 3 + 1) { 430 | //unreachable 431 | decrypted = decrypt_byte(source, i); 432 | goto loc_unreachable_3; 433 | } 434 | else if (stack_x == stack_y + limit() % 4 + 1) { 435 | //unreachable 436 | decrypted = decrypt_byte(source, i); 437 | goto loc_unreachable_4; 438 | } 439 | else if (stack_x == stack_y + limit() % 5 + 1) { 440 | //unreachable 441 | decrypted = decrypt_byte(source, i); 442 | goto loc_unreachable_5; 443 | } 444 | else if (stack_x == stack_y + limit() % 6 + 1) { 445 | //unreachable 446 | decrypted = decrypt_byte(source, i); 447 | goto loc_unreachable_6; 448 | } 449 | else if (stack_x == stack_y + limit() % 7 + 1) { 450 | //unreachable 451 | decrypted = decrypt_byte(source, i); 452 | goto loc_unreachable_7; 453 | } 454 | else if (stack_x == stack_y + limit() % 8 + 1) { 455 | //unreachable 456 | decrypted = decrypt_byte(source, i); 457 | goto loc_unreachable_8; 458 | } 459 | else if (stack_x == stack_y + limit() % 9 + 1) { 460 | //unreachable 461 | decrypted = decrypt_byte(source, i); 462 | goto loc_unreachable_9; 463 | } 464 | loc_start_7: 465 | if (stack_x < limit()) { 466 | if (stack_x > stack_y + limit()) { 467 | //unreachable 468 | decrypted = decrypt_byte(source, i); 469 | } 470 | else if (stack_x == stack_y + limit() % 1 + 1) { 471 | //unreachable 472 | decrypted = decrypt_byte(source, i); 473 | goto loc_unreachable_9; 474 | } 475 | else if (stack_x == stack_y + limit() % 2 + 1) { 476 | //unreachable 477 | decrypted = decrypt_byte(source, i); 478 | goto loc_unreachable_8; 479 | } 480 | else if (stack_x == stack_y + limit() % 3 + 1) { 481 | //unreachable 482 | decrypted = decrypt_byte(source, i); 483 | goto loc_unreachable_7; 484 | } 485 | else if (stack_x == stack_y + limit() % 4 + 1) { 486 | //unreachable 487 | decrypted = decrypt_byte(source, i); 488 | goto loc_unreachable_6; 489 | } 490 | else if (stack_x == stack_y + limit() % 5 + 1) { 491 | //unreachable 492 | decrypted = decrypt_byte(source, i); 493 | goto loc_unreachable_5; 494 | } 495 | else if (stack_x == stack_y + limit() % 6 + 1) { 496 | //unreachable 497 | decrypted = decrypt_byte(source, i); 498 | goto loc_unreachable_4; 499 | } 500 | else if (stack_x == stack_y + limit() % 7 + 1) { 501 | //unreachable 502 | decrypted = decrypt_byte(source, i); 503 | goto loc_unreachable_3; 504 | } 505 | else if (stack_x == stack_y + limit() % 8 + 1) { 506 | //unreachable 507 | decrypted = decrypt_byte(source, i); 508 | goto loc_unreachable_2; 509 | } 510 | else if (stack_x == stack_y + limit() % 9 + 1) { 511 | //unreachable 512 | decrypted = decrypt_byte(source, i); 513 | goto loc_unreachable_1; 514 | } 515 | loc_start_8: 516 | if (stack_y < limit()) { 517 | loc_start_9: 518 | buffer[i] = decrypted;//assign 519 | } 520 | else { 521 | //unreachable 522 | decrypted = decrypt_byte(source, i); 523 | decrypted += decrypted; 524 | loc_unreachable_1: 525 | buffer[i] = decrypt_byte(source, i); 526 | loc_unreachable_2: 527 | stack_y++; 528 | loc_unreachable_3: 529 | i--; 530 | } 531 | } 532 | else { 533 | //unreachable 534 | decrypted = decrypt_byte(source, i); 535 | decrypted += buffer[i]; 536 | loc_unreachable_4: 537 | buffer[i] = decrypt_byte(source, i); 538 | buffer[i] += decrypted; 539 | loc_unreachable_5: 540 | stack_x += stack_y; 541 | loc_unreachable_6: 542 | i--; 543 | i -= decrypted; 544 | } 545 | } 546 | else { 547 | //unreachable 548 | decrypted = decrypt_byte(source, i); 549 | decrypted -= buffer[i]; 550 | loc_unreachable_7: 551 | buffer[i] = decrypt_byte(source, i); 552 | stack_y++; 553 | i -= buffer[i]; 554 | i -= stack_y; 555 | loc_unreachable_8: 556 | buffer[i] = decrypt_byte(source, i); 557 | stack_x++; 558 | i--; 559 | i -= stack_x; 560 | loc_unreachable_9: 561 | i += buffer[i]; 562 | i += stack_y; 563 | continue; 564 | } 565 | } 566 | else { 567 | //unreachable 568 | while (true) { 569 | if (stack_x == stack_y + limit()) { 570 | decrypted = decrypt_byte(source, i); 571 | goto loc_unreachable_1; 572 | } 573 | else if (stack_x == stack_y + limit()) { 574 | decrypted = decrypt_byte(source, i); 575 | goto loc_unreachable_2; 576 | } 577 | else if (stack_x == stack_y + limit()) { 578 | decrypted = decrypt_byte(source, i); 579 | goto loc_unreachable_3; 580 | } 581 | else if (stack_x == stack_y + limit()) { 582 | decrypted = decrypt_byte(source, i); 583 | goto loc_unreachable_4; 584 | } 585 | else if (stack_x == stack_y + limit()) { 586 | decrypted = decrypt_byte(source, i); 587 | goto loc_unreachable_5; 588 | } 589 | else if (stack_x == stack_y + limit()) { 590 | decrypted = decrypt_byte(source, i); 591 | goto loc_unreachable_6; 592 | } 593 | else if (stack_x == stack_y + limit()) { 594 | decrypted = decrypt_byte(source, i); 595 | goto loc_unreachable_7; 596 | } 597 | else if (stack_x == stack_y + limit()) { 598 | decrypted = decrypt_byte(source, i); 599 | goto loc_unreachable_8; 600 | } 601 | else if (stack_x == stack_y + limit()) { 602 | decrypted = decrypt_byte(source, i); 603 | goto loc_unreachable_9; 604 | } 605 | else if (stack_x == stack_y + limit()) { 606 | continue; 607 | } 608 | else { 609 | stack_x = stack_y + limit(); 610 | stack_y = stack_x + limit(); 611 | } 612 | 613 | if (stack_x < stack_y + limit()) { 614 | decrypted = decrypt_byte(source, i); 615 | goto loc_start_1; 616 | } 617 | else if (stack_x < stack_y + limit()) { 618 | decrypted = decrypt_byte(source, i); 619 | goto loc_start_2; 620 | } 621 | else if (stack_x < stack_y + limit()) { 622 | decrypted = decrypt_byte(source, i); 623 | goto loc_start_3; 624 | } 625 | else if (stack_x < stack_y + limit()) { 626 | decrypted = decrypt_byte(source, i); 627 | goto loc_start_4; 628 | } 629 | else if (stack_x < stack_y + limit()) { 630 | decrypted = decrypt_byte(source, i); 631 | goto loc_start_5; 632 | } 633 | else if (stack_x < stack_y + limit()) { 634 | decrypted = decrypt_byte(source, i); 635 | goto loc_start_6; 636 | } 637 | else if (stack_x < stack_y + limit()) { 638 | decrypted = decrypt_byte(source, i); 639 | goto loc_start_7; 640 | } 641 | else if (stack_x < stack_y + limit()) { 642 | decrypted = decrypt_byte(source, i); 643 | goto loc_start_8; 644 | } 645 | else if (stack_x < stack_y + limit()) { 646 | decrypted = decrypt_byte(source, i); 647 | goto loc_start_9; 648 | } 649 | else if (stack_x < stack_y + limit()) { 650 | continue; 651 | } 652 | else { 653 | stack_x = stack_y + limit(); 654 | stack_y = stack_x + limit(); 655 | } 656 | 657 | if (stack_x > stack_y + limit()) { 658 | decrypted = decrypt_byte(source, i); 659 | goto loc_unreachable_9; 660 | } 661 | else if (stack_x > stack_y + limit()) { 662 | decrypted = decrypt_byte(source, i); 663 | goto loc_unreachable_8; 664 | } 665 | else if (stack_x > stack_y + limit()) { 666 | decrypted = decrypt_byte(source, i); 667 | goto loc_unreachable_7; 668 | } 669 | else if (stack_x > stack_y + limit()) { 670 | decrypted = decrypt_byte(source, i); 671 | goto loc_unreachable_6; 672 | } 673 | else if (stack_x > stack_y + limit()) { 674 | decrypted = decrypt_byte(source, i); 675 | goto loc_unreachable_5; 676 | } 677 | else if (stack_x > stack_y + limit()) { 678 | decrypted = decrypt_byte(source, i); 679 | goto loc_unreachable_4; 680 | } 681 | else if (stack_x > stack_y + limit()) { 682 | decrypted = decrypt_byte(source, i); 683 | goto loc_unreachable_3; 684 | } 685 | else if (stack_x > stack_y + limit()) { 686 | decrypted = decrypt_byte(source, i); 687 | goto loc_unreachable_2; 688 | } 689 | else if (stack_x > stack_y + limit()) { 690 | decrypted = decrypt_byte(source, i); 691 | goto loc_unreachable_1; 692 | } 693 | else if (stack_x > stack_y + limit()) { 694 | continue; 695 | } 696 | else { 697 | stack_x = stack_y + limit(); 698 | stack_y = stack_x + limit(); 699 | } 700 | } 701 | } 702 | } 703 | else { 704 | //unreachable 705 | //Ooops, Decompilation failure: 706 | //401000: stack frame is too big 707 | return reinterpret_cast(buffer + ((key * __COUNTER__) % 0x400000 + 0x1400000)); 708 | } 709 | } 710 | else { 711 | //unreachable 712 | //Ooops, Decompilation failure: 713 | //401000: stack frame is too big 714 | return reinterpret_cast(buffer + ((key * __COUNTER__) % 0x1400000 + 0x400000)); 715 | } 716 | } 717 | 718 | #else 719 | for (volatile _lxy__size_t i = 0; i < size; i++) { 720 | buffer[i] = decrypt_byte(buffer[i], i); 721 | } 722 | #endif // OXORANY_DISABLE_OBFUSCATION 723 | return reinterpret_cast(buffer); 724 | } 725 | 726 | static OXORANY_FORCEINLINE constexpr _lxy__size_t align(_lxy__size_t n, _lxy__size_t a) { 727 | return (n + a - 1) & ~(a - 1); 728 | } 729 | 730 | template 731 | class oxor_any { 732 | 733 | static constexpr _lxy__size_t size = align(ary_size * sizeof(any_t), 16) 734 | + random_constant::value % (16 + 1); 735 | 736 | static constexpr _lxy__size_t key = random_constant::value; 737 | 738 | alignas(0x10) _lxy__uint8_t buffer[size]; 739 | 740 | public: 741 | 742 | template<_lxy__size_t... indices> 743 | OXORANY_FORCEINLINE constexpr oxor_any(const any_t(&any)[ary_size], _lxy_::index_sequence) : 744 | buffer{ encrypt_byte(((_lxy__uint8_t*)&any)[indices], indices)... } { 745 | } 746 | 747 | OXORANY_FORCEINLINE const any_t* get() { return decrypt(buffer); } 748 | }; 749 | 750 | template 751 | class oxor_any { 752 | 753 | static constexpr _lxy__size_t size = align(sizeof(any_t), 16) 754 | + random_constant::value % (16 + 1); 755 | 756 | static constexpr _lxy__size_t key = random_constant::value; 757 | 758 | alignas(0x10) _lxy__uint8_t buffer[size]; 759 | 760 | public: 761 | 762 | template<_lxy__size_t... indices> 763 | OXORANY_FORCEINLINE constexpr oxor_any(any_t any, _lxy_::index_sequence) : 764 | buffer{ encrypt_byte(reinterpret_cast<_lxy__uint8_t*>(&any)[indices], indices)... } { 765 | } 766 | 767 | OXORANY_FORCEINLINE const any_t get() { return *decrypt(buffer); } 768 | }; 769 | } 770 | 771 | #endif // OXORANY_H 772 | 773 | class oxorany 774 | { 775 | }; 776 | -------------------------------------------------------------------------------- /src/include/oxorany/oxorany_include.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef OXORANY_INCLUDE_H 3 | #define OXORANY_INCLUDE_H 4 | 5 | //disable /GL for warning C4307 in msvc 6 | #define OXORANY_DISABLE_OBFUSCATION 7 | //use OXORANY_USE_BIT_CAST for remove float double src data 8 | #define OXORANY_USE_BIT_CAST 9 | 10 | #include "oxorany.h" 11 | 12 | //to change Marco in a easy way 13 | #define WRAPPER_MARCO oxorany 14 | #define WRAPPER_MARCO_FLT oxorany_flt 15 | 16 | template 17 | static OXORANY_FORCEINLINE void copy_string_without_return(T* target, const T* source) 18 | { 19 | while (*source) { 20 | *target = *source; 21 | ++source; 22 | ++target; 23 | } 24 | *target = 0; 25 | } 26 | 27 | #define WRAPPER_MARCO_DEFINE_STRING_ARRAY(type,name,s) type name[sizeof(s)/sizeof(type)]; copy_string_without_return(name, WRAPPER_MARCO(s)) 28 | 29 | #endif -------------------------------------------------------------------------------- /src/user/globals.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | HWND WindowHwnd = nullptr; 4 | WNDPROC WindowProc = nullptr; 5 | HMODULE ModuleHandle = nullptr; 6 | 7 | bool IsGUIInitialized = false; 8 | bool ShowMenu = false; 9 | 10 | bool fManipulateSamplePickup = false; 11 | int SampleAmount = 1; 12 | bool fStratagemUnlock = false; 13 | bool fArmorUnlock = false; 14 | bool fEquipmentUnlock = false; 15 | bool fRoutineDeployment = false; 16 | bool fWeaponAmmoReduction = false; 17 | bool fStratagemReduction = false; 18 | bool fStaminaReduction = false; 19 | bool fEnemyBasicDamage = false; 20 | 21 | void InitializeConsole() { 22 | FILE* pFile = nullptr; 23 | AllocConsole(); 24 | freopen_s(&pFile, oxorany("CONOUT$"), oxorany("w"), stdout); 25 | } 26 | 27 | void DestroyConsole() 28 | { 29 | DestroyWindow(GetConsoleWindow()); 30 | FreeConsole(); 31 | } 32 | -------------------------------------------------------------------------------- /src/user/globals.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "oxorany.h" 8 | 9 | extern uint64_t* MethodsTable; 10 | extern HWND WindowHwnd; 11 | extern WNDPROC WindowProc; 12 | extern HMODULE ModuleHandle; 13 | 14 | extern bool IsGUIInitialized; 15 | extern bool ShowMenu; 16 | 17 | extern bool fManipulateSamplePickup; 18 | extern int SampleAmount; 19 | extern bool fStratagemUnlock; 20 | extern bool fArmorUnlock; 21 | extern bool fEquipmentUnlock; 22 | extern bool fRoutineDeployment; 23 | extern bool fWeaponAmmoReduction; 24 | extern bool fStratagemReduction; 25 | extern bool fStaminaReduction; 26 | extern bool fEnemyBasicDamage; 27 | 28 | void InitializeConsole(); 29 | void DestroyConsole(); 30 | -------------------------------------------------------------------------------- /src/user/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.hpp" 2 | #include "_hooks.h" 3 | #include "oxorany.h" 4 | #include "detours.h" 5 | #include 6 | #include "SignatureScan.hpp" 7 | #include "globals.h" 8 | 9 | void Run(LPVOID lpParam) 10 | { 11 | do 12 | { 13 | ModuleHandle = GetModuleHandle(oxorany("game.dll")); 14 | Sleep(1000); 15 | } while (!ModuleHandle); 16 | Sleep(100); 17 | 18 | InitializeConsole(); 19 | WindowHwnd = GetForegroundWindow(); 20 | DetourInitilization(); 21 | 22 | while(true) 23 | { 24 | Sleep(1000); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/user/main.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define WIN32_LEAN_AND_MEAN 3 | #include 4 | 5 | void Run(LPVOID lpParam); --------------------------------------------------------------------------------