├── .editorconfig ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── NOTICE ├── README.md ├── cmake └── platform.cmake ├── src ├── CMakeLists.txt └── main │ ├── CMakeLists.txt │ ├── appframework.cpp │ ├── appframework.h │ ├── application.h │ ├── dumpers │ ├── concommands │ │ ├── concommands.cpp │ │ └── concommands.h │ └── schemas │ │ ├── metadata_stringifier.cpp │ │ ├── metadata_stringifier.h │ │ ├── metadatalist.h │ │ ├── schemas.cpp │ │ └── schemas.h │ ├── globalvariables.h │ ├── interfaces.h │ ├── main.cpp │ ├── main.h │ ├── modules.h │ ├── network_connection.pb.h │ └── utils │ ├── common.cpp │ ├── common.h │ ├── module.h │ ├── oslink.h │ ├── plat.h │ ├── plat_unix.cpp │ ├── plat_win.cpp │ ├── plat_win.h │ └── virtual.h └── vendor └── CMakeLists.txt /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset = utf-8 3 | indent_style = tab 4 | indent_size = 2 5 | trim_trailing_whitespace = true 6 | 7 | [*.yml] 8 | indent_style = space 9 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | build: 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest, windows-latest] 12 | 13 | runs-on: ${{ matrix.os }} 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | submodules: 'true' 19 | 20 | - name: Setup CMake 21 | uses: lukka/get-cmake@latest 22 | 23 | - name: Create build directory 24 | run: mkdir build 25 | 26 | - name: Configure CMake 27 | run: cmake -B build -S . 28 | 29 | - name: Build 30 | run: cmake --build build --parallel 4 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.vs/ 2 | /build/ 3 | /linuxbuild/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/hl2sdk-cs"] 2 | path = vendor/hl2sdk-cs2 3 | url = https://github.com/alliedmodders/hl2sdk 4 | branch = cs2 5 | shallow = true 6 | [submodule "vendor/hl2sdk-dota"] 7 | path = vendor/hl2sdk-dota 8 | url = https://github.com/alliedmodders/hl2sdk 9 | branch = dota 10 | shallow = true 11 | [submodule "vendor/hl2sdk-deadlock"] 12 | path = vendor/hl2sdk-deadlock 13 | url = https://github.com/alliedmodders/hl2sdk 14 | branch = deadlock 15 | shallow = true 16 | [submodule "vendor/spdlog"] 17 | path = vendor/spdlog 18 | url = https://github.com/gabime/spdlog 19 | shallow = true 20 | [submodule "vendor/fmt"] 21 | path = vendor/fmt 22 | url = https://github.com/fmtlib/fmt 23 | shallow = true 24 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(DumpSource2 C CXX) 3 | 4 | set(CMAKE_CXX_STANDARD 20) 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 7 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 9 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 10 | 11 | include(${PROJECT_SOURCE_DIR}/cmake/platform.cmake) 12 | include_directories(src/main) 13 | include_directories(src) 14 | 15 | # Include all vendor libraries, also sets up HL2SDK and Metamod 16 | add_subdirectory(vendor) 17 | 18 | # Source 19 | add_subdirectory(src) 20 | -------------------------------------------------------------------------------- /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 | . -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | List of 3rd party code used in this project and their licenses. 2 | 3 | # DynLibUtils 4 | 5 | MIT License 6 | 7 | Copyright (c) 2023 komashchenko (Phoenix) 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 | # source2gen - Source2 games SDK generator 28 | 29 | Copyright 2024 neverlosecc 30 | 31 | Licensed under the Apache License, Version 2.0 (the "License"); 32 | you may not use this file except in compliance with the License. 33 | You may obtain a copy of the License at 34 | 35 | http://www.apache.org/licenses/LICENSE-2.0 36 | 37 | Unless required by applicable law or agreed to in writing, software 38 | distributed under the License is distributed on an "AS IS" BASIS, 39 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40 | See the License for the specific language governing permissions and 41 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DumpSource2 2 | 3 | A C++ Application that offline dumps schema bindings and convars/commands for [GameTracking](https://github.com/SteamDatabase/GameTracking) purposes. 4 | 5 | [See this file in GameTracking on how its used.](https://github.com/SteamDatabase/GameTracking/blob/master/tools/dump_source2.sh) 6 | 7 | ## Usage 8 | 9 | Run DumpSource2 from the rootbin folder of a source 2 game. `game/bin/win64` 10 | 11 | `DumpSource2 ` 12 | 13 | - `output path` - absolute or relative path to a folder where output should be stored 14 | 15 | 16 | # Compilation 17 | 18 | ## Windows 19 | 20 | ```sh 21 | mkdir build 22 | cd build 23 | cmake .. 24 | # Open VS solution and compile from VS 25 | ``` 26 | 27 | ## Linux 28 | ```sh 29 | mkdir build 30 | cd build 31 | cmake .. 32 | make 33 | ``` 34 | -------------------------------------------------------------------------------- /cmake/platform.cmake: -------------------------------------------------------------------------------- 1 | add_definitions(-DMETA_IS_SOURCE2 -D_ITERATOR_DEBUG_LEVEL=0) 2 | 3 | if(UNIX) 4 | add_definitions( 5 | -D_LINUX -DPOSIX -DLINUX -DGNUC -DCOMPILER_GCC -DPLATFORM_64BITS -D_GLIBCXX_USE_CXX11_ABI=0 -Dstricmp=strcasecmp 6 | -D_stricmp=strcasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -DHAVE_STDINT_H 7 | ) 8 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++") 9 | elseif(WIN32) 10 | add_definitions( 11 | -DCOMPILER_MSVC -DCOMPILER_MSVC64 -DPLATFORM_64BITS -DWIN32 -DWINDOWS -DCRT_SECURE_NO_WARNINGS 12 | -DCRT_SECURE_NO_DEPRECATE -DCRT_NONSTDC_NO_DEPRECATE -DNOMINMAX 13 | ) 14 | 15 | add_definitions(/MP) 16 | endif() -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(main) -------------------------------------------------------------------------------- /src/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE SOURCES_LIST 2 | "*.cpp" 3 | ) 4 | 5 | file(GLOB_RECURSE HEADERS_LIST 6 | "*.h" 7 | ) 8 | 9 | function(BUILD_GAME GAME GAME_PATH) 10 | add_executable(DumpSource2-${GAME} ${SOURCES_LIST} ${HEADERS_LIST}) 11 | 12 | target_link_libraries(DumpSource2-${GAME} PRIVATE 13 | HL2SDK-${GAME} 14 | fmt::fmt 15 | spdlog 16 | ${CMAKE_DL_LIBS} 17 | ) 18 | 19 | target_compile_definitions(DumpSource2-${GAME} PRIVATE GAME_${GAME} GAME_PATH="${GAME_PATH}") 20 | endfunction() 21 | 22 | build_game(CS2 csgo) 23 | build_game(DOTA dota) 24 | build_game(DEADLOCK deadlock) 25 | 26 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Source Files" FILES ${SOURCES_LIST}) 27 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Header Files" FILES ${HEADERS_LIST}) -------------------------------------------------------------------------------- /src/main/appframework.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #include "appframework.h" 21 | #include "utils/module.h" 22 | #include "modules.h" 23 | #include "interfaces.h" 24 | #include "application.h" 25 | #include "globalvariables.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | static DumperApplication g_Application; 32 | 33 | #define CS2_ONLY (1<<0) 34 | 35 | struct AppSystemInfo 36 | { 37 | bool gameBin; 38 | const char* moduleName; 39 | std::string interfaceVersion; 40 | bool connect = true; 41 | uint64_t flags = 0; 42 | }; 43 | 44 | std::vector g_appSystems{ 45 | { false, "filesystem_stdio", FILESYSTEM_INTERFACE_VERSION }, 46 | { false, "resourcesystem", RESOURCESYSTEM_INTERFACE_VERSION }, 47 | { true, "client", "Source2ClientConfig001" }, 48 | { false, "engine2", SOURCE2ENGINETOSERVER_INTERFACE_VERSION }, 49 | { true, "host", "GameSystem2HostHook" }, 50 | { true, "matchmaking", MATCHFRAMEWORK_INTERFACE_VERSION, true, CS2_ONLY }, 51 | { true, "server", SOURCE2SERVERCONFIG_INTERFACE_VERSION }, 52 | { false, "animationsystem", ANIMATIONSYSTEM_INTERFACE_VERSION }, 53 | { false, "materialsystem2", TEXTLAYOUT_INTERFACE_VERSION }, 54 | { false, "meshsystem", MESHSYSTEM_INTERFACE_VERSION, false }, 55 | { false, "networksystem", NETWORKSYSTEM_INTERFACE_VERSION, false}, // can't connect on linux cuz of missing gameinfo in IApplication 56 | { false, "panorama", PANORAMAUIENGINE_INTERFACE_VERSION }, 57 | { false, "particles", PARTICLESYSTEMMGR_INTERFACE_VERSION, false }, // needs renderdevice interface 58 | { false, "pulse_system", PULSESYSTEM_INTERFACE_VERSION }, 59 | #ifdef _WIN32 60 | { false, "rendersystemdx11", RENDER_UTILS_INTERFACE_VERSION }, 61 | #else 62 | { false, "rendersystemvulkan", RENDER_UTILS_INTERFACE_VERSION }, 63 | #endif 64 | { false, "scenefilecache", "SceneFileCache002" }, 65 | { false, "scenesystem", SCENEUTILS_INTERFACE_VERSION }, 66 | { false, "soundsystem", SOUNDOPSYSTEMEDIT_INTERFACE_VERSION }, 67 | { false, "vphysics2", VPHYSICS2HANDLE_INTERFACE_VERSION }, 68 | { false, "worldrenderer", WORLD_RENDERER_MGR_INTERFACE_VERSION }, 69 | }; 70 | 71 | std::map g_factoryMap; 72 | 73 | void* AppSystemFactory(const char* pName, int* pReturnCode) 74 | { 75 | if (!strcmp(pName, CVAR_INTERFACE_VERSION)) 76 | return Interfaces::cvar; 77 | 78 | if (!strcmp(pName, SCHEMASYSTEM_INTERFACE_VERSION)) 79 | return Interfaces::schemaSystem; 80 | 81 | if (!strcmp(pName, APPLICATION_INTERFACE_VERSION)) 82 | return &g_Application; 83 | 84 | if (g_factoryMap.find(pName) != g_factoryMap.end()) 85 | { 86 | spdlog::trace("Connected {} interface", pName); 87 | return g_factoryMap.at(pName); 88 | } 89 | 90 | return nullptr; 91 | } 92 | 93 | // SceneUtils_001 tries to set convars on init 94 | // which then calls convar change handlers that try to load main scenesystem appsystem 95 | void SetConvarValueStub(ICvar* icvar, ConVarRef ref) 96 | { 97 | ConVarRefAbstract cvar(ref); 98 | if (!cvar.IsConVarDataValid()) 99 | return; 100 | 101 | // it also crashes if r_dopixelvisibility is true 102 | if (!strcmp("r_dopixelvisibility", cvar.GetName())) 103 | { 104 | cvar.SetBool(false); 105 | } 106 | } 107 | 108 | void InitializeCoreModules() 109 | { 110 | spdlog::info("Initializing core modules"); 111 | // Load modules (dlopen) 112 | Modules::schemaSystem = std::make_unique("", "schemasystem"); 113 | Modules::tier0 = std::make_unique("", "tier0"); 114 | 115 | // Find interfaces 116 | Interfaces::cvar = Modules::tier0->FindInterface(CVAR_INTERFACE_VERSION); 117 | g_pCVar = Interfaces::cvar; 118 | Interfaces::schemaSystem = Modules::schemaSystem->FindInterface(SCHEMASYSTEM_INTERFACE_VERSION); 119 | 120 | // Manually connect interfaces 121 | Interfaces::cvar->Connect(Modules::tier0->GetFactory()); 122 | Interfaces::cvar->Init(); 123 | 124 | Interfaces::schemaSystem->Connect(&AppSystemFactory); 125 | Interfaces::schemaSystem->Init(); 126 | 127 | auto vtb = *((void***)Interfaces::cvar); 128 | 129 | #ifdef _WIN32 130 | DWORD _; 131 | VirtualProtect(vtb + 14, 8, PAGE_EXECUTE_READWRITE, &_); 132 | *(vtb + 14) = &SetConvarValueStub; 133 | #else 134 | void* patchBytes = (void*)&SetConvarValueStub; 135 | Plat_WriteMemory(vtb + 14, (uint8_t*)&patchBytes, 8); 136 | #endif 137 | } 138 | 139 | void InitializeAppSystems() 140 | { 141 | spdlog::info("Initializing app systems"); 142 | for (const auto& appSystem : g_appSystems) 143 | { 144 | #ifndef GAME_CS2 145 | if ((appSystem.flags & CS2_ONLY) != 0) 146 | continue; 147 | #endif // !GAME_CS2 148 | 149 | std::string path = appSystem.gameBin ? fmt::format("../../{}/bin/{}", GAME_PATH, PLATFORM_FOLDER) : ""; 150 | 151 | CModule module(path.c_str(), appSystem.moduleName); 152 | 153 | auto interface = module.FindInterface(appSystem.interfaceVersion.c_str()); 154 | 155 | g_factoryMap[appSystem.interfaceVersion] = interface; 156 | if (appSystem.connect) 157 | { 158 | interface->Connect(&AppSystemFactory); 159 | interface->Init(); 160 | } 161 | else 162 | { 163 | // We can't connect this interface, let's at least dump schemas 164 | typedef void* (*InstallSchemaBindings)(const char* interfaceName, void* pSchemaSystem); 165 | InstallSchemaBindings fn = (InstallSchemaBindings)dlsym(module.m_hModule, "InstallSchemaBindings"); 166 | 167 | fn(SCHEMASYSTEM_INTERFACE_VERSION, Interfaces::schemaSystem); 168 | } 169 | } 170 | } -------------------------------------------------------------------------------- /src/main/appframework.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | #pragma once 20 | 21 | void InitializeCoreModules(); 22 | void InitializeAppSystems(); -------------------------------------------------------------------------------- /src/main/application.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include "appframework/IAppSystem.h" 22 | 23 | class DumperApplication : public CTier0AppSystem 24 | { 25 | virtual void Destructor() {}; 26 | #ifndef _WIN32 27 | virtual void Destructor2() {}; 28 | #endif 29 | virtual void PreShutdown() {}; 30 | virtual BuildType_t GetBuildType() { return kBuildTypeRelease; }; 31 | virtual void Reconnect(CreateInterfaceFn factory, const char* interfaceName) {}; 32 | 33 | 34 | virtual int AddSystem(IAppSystem* pAppSystem, const char* interfaceName, bool errorOut) { return 0; }; 35 | virtual int AddSystem(const char* unk, const char* interfaceName, bool errorOut) { return 0; }; 36 | virtual int AddSystem(IAppSystem* pAppSystem, const char* interfaceName) { return 0; }; 37 | virtual void RemoveSystem(IAppSystem* pAppSystem) { }; 38 | virtual int AddSystems(int count, void** pAppSystems) { return 0; }; 39 | virtual void* FindSystem(const char* interfaceName) { return nullptr; }; 40 | virtual void* GetGameInfo() { 41 | printf("called getgameinfo\n"); 42 | return nullptr; 43 | }; 44 | virtual unsigned int unk1() { return -1; }; 45 | virtual int GetUILanguage(int languageType) { return 0; }; 46 | virtual int GetAudioLanguage(int languageType) { return 0; }; 47 | virtual bool IsInToolsMode() { return false; }; 48 | virtual bool unk2() { return false; }; 49 | virtual bool unk3() { return false; }; 50 | virtual bool unk4() { return false; }; 51 | virtual void* unk5() { return nullptr; }; 52 | virtual void* unk6() { return nullptr; }; 53 | virtual void* unk7() { return nullptr; }; 54 | virtual void* unk8() { return nullptr; }; 55 | virtual void* unk9() { return nullptr; }; 56 | virtual void* unk10(void* a) { return a; }; 57 | virtual void* unk11() { return nullptr; }; 58 | virtual void* AddSystemDontLoadStartupManifests(const char* a, const char* b) { return nullptr; }; 59 | virtual void* unk12() { return nullptr; }; 60 | }; -------------------------------------------------------------------------------- /src/main/dumpers/concommands/concommands.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | 21 | // Yes this is shit, no we can't make it better. 22 | #define _ALLOW_KEYWORD_MACROS 1 23 | #define private public 24 | #include 25 | #undef private 26 | #undef _ALLOW_KEYWORD_MACROS 27 | 28 | #include "concommands.h" 29 | #include "interfaces.h" 30 | #include "globalvariables.h" 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace Dumpers::ConCommands 38 | { 39 | 40 | #define MINMAXVALUEPRINT(typeName) \ 41 | stream << " " << value->typeName; \ 42 | \ 43 | bool hasMinValue = cvar.HasMin(); \ 44 | bool hasMaxValue = cvar.HasMax(); \ 45 | \ 46 | stream << " ("; \ 47 | \ 48 | if (hasMinValue) \ 49 | stream << "min: " << conVarData->MinValue()->typeName; \ 50 | \ 51 | if (hasMaxValue) \ 52 | { \ 53 | if (hasMinValue) \ 54 | stream << ", "; \ 55 | stream << "max: " << conVarData->MaxValue()->typeName; \ 56 | } \ 57 | \ 58 | if (hasMinValue || hasMaxValue) \ 59 | stream << ", "; \ 60 | \ 61 | WriteFlags(cvar.GetFlags(), stream); \ 62 | \ 63 | stream << ")"; 64 | 65 | #define FCVAR_MISSING1 (1ull<<30) 66 | #define FCVAR_MISSING2 (1ull<<31) 67 | 68 | std::vector> g_flagMap{ 69 | {FCVAR_LINKED_CONCOMMAND, "linked_concommand"}, 70 | {FCVAR_DEVELOPMENTONLY, "developmentonly"}, 71 | {FCVAR_GAMEDLL, "gamedll"}, 72 | {FCVAR_CLIENTDLL, "clientdll"}, 73 | {FCVAR_HIDDEN, "hidden"}, 74 | {FCVAR_PROTECTED, "protected"}, 75 | {FCVAR_SPONLY, "sponly"}, 76 | {FCVAR_ARCHIVE, "archive"}, 77 | {FCVAR_NOTIFY, "notify"}, 78 | {FCVAR_USERINFO, "userinfo"}, 79 | {FCVAR_REFERENCE, "reference"}, 80 | {FCVAR_UNLOGGED, "unlogged"}, 81 | {FCVAR_INITIAL_SETVALUE, "initial_setvalue"}, 82 | {FCVAR_REPLICATED, "replicated"}, 83 | {FCVAR_CHEAT, "cheat"}, 84 | {FCVAR_PER_USER, "per_user"}, 85 | {FCVAR_DEMO, "demo"}, 86 | {FCVAR_DONTRECORD, "dontrecord"}, 87 | {FCVAR_PERFORMING_CALLBACKS, "performing_Callbacks"}, 88 | {FCVAR_RELEASE, "release"}, 89 | {FCVAR_MENUBAR_ITEM, "menubar_item"}, 90 | {FCVAR_COMMANDLINE_ENFORCED, "commandline_enforced"}, 91 | {FCVAR_NOT_CONNECTED, "notconnected"}, 92 | {FCVAR_VCONSOLE_FUZZY_MATCHING, "vconsole_fuzzy_matching"}, 93 | {FCVAR_SERVER_CAN_EXECUTE, "server_can_execute"}, 94 | {FCVAR_CLIENT_CAN_EXECUTE, "client_can_execute"}, 95 | {FCVAR_SERVER_CANNOT_QUERY, "server_cannot_query"}, 96 | {FCVAR_VCONSOLE_SET_FOCUS, "vconsole_set_focus"}, 97 | {FCVAR_CLIENTCMD_CAN_EXECUTE, "clientcmd_can_execute"}, 98 | {FCVAR_EXECUTE_PER_TICK, "execute_per_tick"}, 99 | {FCVAR_MISSING1, "missing1"}, 100 | {FCVAR_MISSING2, "missing2"}, 101 | {FCVAR_DEFENSIVE, "defensive"} 102 | }; 103 | 104 | void WriteFlags(uint64_t flags, std::ofstream& stream) 105 | { 106 | bool found = false; 107 | for (const auto& [value, name] : g_flagMap) 108 | { 109 | if (flags & value) 110 | { 111 | stream << (found ? " " : "") << name; 112 | found = true; 113 | } 114 | } 115 | } 116 | void WriteValueLine(ConVarRefAbstract cvar, std::ofstream& stream) 117 | { 118 | auto conVarData = cvar.GetConVarData(); 119 | auto value = cvar.GetConVarData()->DefaultValue(); 120 | 121 | switch (cvar.GetType()) 122 | { 123 | case EConVarType_Bool: 124 | { 125 | stream << " " << (value->m_bValue ? "true" : "false") << " ("; 126 | WriteFlags(cvar.GetFlags(), stream); 127 | stream << ")"; 128 | break; 129 | } 130 | case EConVarType_Int16: 131 | { 132 | MINMAXVALUEPRINT(m_i16Value); 133 | break; 134 | } 135 | case EConVarType_Int32: 136 | { 137 | MINMAXVALUEPRINT(m_i32Value); 138 | break; 139 | } 140 | case EConVarType_UInt32: 141 | { 142 | MINMAXVALUEPRINT(m_u32Value); 143 | break; 144 | } 145 | case EConVarType_Int64: 146 | { 147 | MINMAXVALUEPRINT(m_i64Value); 148 | break; 149 | } 150 | case EConVarType_UInt64: 151 | { 152 | MINMAXVALUEPRINT(m_u64Value); 153 | break; 154 | } 155 | case EConVarType_Float32: 156 | { 157 | MINMAXVALUEPRINT(m_fl32Value); 158 | break; 159 | } 160 | case EConVarType_Float64: 161 | { 162 | MINMAXVALUEPRINT(m_fl64Value); 163 | break; 164 | } 165 | case EConVarType_String: 166 | { 167 | stream << " \"" << (value->m_StringValue.m_pString ? value->m_StringValue.m_pString : "") << "\"" << " ("; 168 | WriteFlags(cvar.GetFlags(), stream); 169 | stream << ")"; 170 | break; 171 | } 172 | case EConVarType_Color: 173 | { 174 | stream << " [" << value->m_clrValue.r() << ", " << value->m_clrValue.g() << ", " << value->m_clrValue.b() << ", " << value->m_clrValue.a() << "]" << " ("; 175 | WriteFlags(cvar.GetFlags(), stream); 176 | stream << ")"; 177 | break; 178 | } 179 | case EConVarType_Vector2: 180 | { 181 | stream << " [" << value->m_vec2Value.x << ", " << value->m_vec2Value.y << "]" << " ("; 182 | WriteFlags(cvar.GetFlags(), stream); 183 | stream << ")"; 184 | break; 185 | } 186 | case EConVarType_Vector3: 187 | { 188 | stream << " [" << value->m_vec3Value.x << ", " << value->m_vec3Value.y << ", " << value->m_vec3Value.x << "]" << " ("; 189 | WriteFlags(cvar.GetFlags(), stream); 190 | stream << ")"; 191 | break; 192 | } 193 | case EConVarType_Vector4: 194 | { 195 | stream << " [" << value->m_vec4Value.x << ", " << value->m_vec4Value.y << ", " << value->m_vec4Value.x << ", " << value->m_vec4Value.w << "]" << " ("; 196 | WriteFlags(cvar.GetFlags(), stream); 197 | stream << ")"; 198 | break; 199 | } 200 | case EConVarType_Qangle: 201 | { 202 | stream << " [" << value->m_angValue.x << ", " << value->m_angValue.y << ", " << value->m_angValue.x << "]" << " ("; 203 | WriteFlags(cvar.GetFlags(), stream); 204 | stream << ")"; 205 | break; 206 | } 207 | default: 208 | stream << " UNKNOWN VALUE TYPE"; 209 | break; 210 | } 211 | } 212 | 213 | void FixNewlineTabbing(std::string& str) 214 | { 215 | auto it = str.begin(); 216 | while ((it = std::find(it, str.end(), '\n')) != str.end()) 217 | { 218 | if (it + 1 == str.end() || *(it + 1) != '\t') 219 | it = str.insert(it + 1, '\t') + 1; 220 | else 221 | it++; 222 | } 223 | 224 | // trim end of string 225 | if (str.back() == '\t') 226 | str.pop_back(); 227 | 228 | if (str.back() == '\n') 229 | str.pop_back(); 230 | } 231 | 232 | std::string EscapeDescription(std::string str) 233 | { 234 | for (auto it = str.begin(); it != str.end(); it++) { 235 | if (*it == '\n') 236 | { 237 | *it = '\\'; 238 | it = str.insert(it + 1, 'n'); 239 | } 240 | else if (*it == '\t') 241 | { 242 | *it = '\\'; 243 | it = str.insert(it + 1, 't'); 244 | } 245 | } 246 | 247 | return str; 248 | } 249 | 250 | 251 | void DumpConVars() 252 | { 253 | spdlog::info("Dumping convars"); 254 | std::vector convars; 255 | // there's always gonna be a lot of convars, let's save some reallocations 256 | convars.reserve(1000); 257 | 258 | for (ConVarRefAbstract ref(ConVarRef((uint16)0)); ref.IsValidRef(); ref = ConVarRefAbstract(ConVarRef(ref.GetAccessIndex() + 1))) 259 | { 260 | convars.push_back(ref); 261 | } 262 | 263 | std::sort(convars.begin(), convars.end(), [](const ConVarRefAbstract a, const ConVarRefAbstract b) { 264 | return strcmp(a.GetName(), b.GetName()) < 0; 265 | }); 266 | 267 | std::ofstream output(Globals::outputPath / "convars.txt"); 268 | 269 | for (const auto cvar : convars) 270 | { 271 | std::string helpString = ""; 272 | if (cvar.HasHelpText()) 273 | { 274 | helpString = cvar.GetHelpText(); 275 | Globals::stringsIgnoreStream << EscapeDescription(helpString) << "\n"; 276 | FixNewlineTabbing(helpString); 277 | } 278 | 279 | output << cvar.GetName(); 280 | WriteValueLine(cvar, output); 281 | output << "\n\t" << helpString; 282 | output << "\n" << std::endl; 283 | 284 | Globals::stringsIgnoreStream << cvar.GetName() << "\n"; 285 | } 286 | } 287 | 288 | void DumpCommands() 289 | { 290 | spdlog::info("Dumping commands"); 291 | std::vector commands; 292 | // there's always gonna be a lot of commands, let's save some reallocations 293 | commands.reserve(1000); 294 | ConCommandData* data = Interfaces::cvar->GetConCommandData(ConCommandRef()); 295 | for (ConCommandRef ref = ConCommandRef((uint16)0); ref.GetRawData() != data; ref = ConCommandRef(ref.GetAccessIndex() + 1)) 296 | { 297 | commands.push_back(ref); 298 | } 299 | 300 | std::sort(commands.begin(), commands.end(), [](const ConCommandRef a, const ConCommandRef b) { 301 | return strcmp(a.GetName(), b.GetName()) < 0; 302 | }); 303 | 304 | std::ofstream output(Globals::outputPath / "commands.txt"); 305 | 306 | for (const auto command : commands) 307 | { 308 | std::string helpString = ""; 309 | if (command.HasHelpText()) 310 | { 311 | helpString = command.GetHelpText(); 312 | Globals::stringsIgnoreStream << EscapeDescription(helpString) << "\n"; 313 | FixNewlineTabbing(helpString); 314 | } 315 | 316 | output << command.GetName() << " ("; 317 | WriteFlags(command.GetFlags(), output); 318 | output << ")\n\t" << helpString; 319 | output << "\n" << std::endl; 320 | 321 | Globals::stringsIgnoreStream << command.GetName() << "\n"; 322 | } 323 | } 324 | 325 | void Dump() 326 | { 327 | spdlog::debug("Removing default value from cl_color"); 328 | // cl_color has a random default value on each start. 329 | if (ConVarRefAbstract cvar("cl_color"); cvar.IsValidRef()) 330 | { 331 | cvar.GetConVarData()->RemoveDefaultValue(); 332 | } 333 | 334 | DumpConVars(); 335 | DumpCommands(); 336 | } 337 | 338 | } // namespace Dumpers::ConCommands -------------------------------------------------------------------------------- /src/main/dumpers/concommands/concommands.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | #pragma once 20 | 21 | namespace Dumpers::ConCommands 22 | { 23 | 24 | void Dump(); 25 | 26 | } // namespace Dumpers::ConCommands -------------------------------------------------------------------------------- /src/main/dumpers/schemas/metadata_stringifier.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * 6 | * source2gen 7 | * Copyright 2024 neverlosecc 8 | * ============================================================================= 9 | * 10 | * This program is free software; you can redistribute it and/or modify it under 11 | * the terms of the GNU General Public License, version 3.0, as published by the 12 | * Free Software Foundation. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * this program. If not, see . 21 | */ 22 | 23 | #include "schemas.h" 24 | #include "globalvariables.h" 25 | #include "interfaces.h" 26 | #include "schemasystem/schemasystem.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "metadatalist.h" 33 | #include 34 | #include 35 | #include 36 | #include "metadata_stringifier.h" 37 | 38 | 39 | namespace Dumpers::Schemas 40 | { 41 | 42 | // Determine how and if to output metadata entry value based on it's type. 43 | std::optional GetMetadataValue(const SchemaMetadataEntryData_t& entry) 44 | { 45 | if (g_mapMetadataNameToValue.find(entry.m_pszName) != g_mapMetadataNameToValue.end()) 46 | { 47 | auto valueType = g_mapMetadataNameToValue.at(entry.m_pszName); 48 | switch (valueType) 49 | { 50 | case MetadataValueType::STRING: 51 | { 52 | auto value = *static_cast(entry.m_pData); 53 | Globals::stringsIgnoreStream << value << "\n"; 54 | return fmt::format("\"{}\"", value); 55 | } 56 | case MetadataValueType::INTEGER: 57 | return std::to_string(*static_cast(entry.m_pData)); 58 | case MetadataValueType::FLOAT: 59 | return std::to_string(*static_cast(entry.m_pData)); 60 | case MetadataValueType::INLINE_STRING: 61 | { 62 | // max 8 characters. Also check for null term. 63 | char* result = static_cast(entry.m_pData); 64 | for (uint8_t i = 0; i < 8; ++i) { 65 | if (result[i] == '\0') { 66 | return fmt::format("\"{}\"", std::string(result, i)); 67 | } 68 | } 69 | return fmt::format("\"{}\"", std::string(result, 8)); 70 | } 71 | case MetadataValueType::VARNAME: 72 | { 73 | auto value = static_cast(entry.m_pData); 74 | 75 | const auto check_ptr = [](const char* ptr) -> bool { 76 | // Authored: source2gen 77 | // @note: hotfix for the deadlock 14/09/24 update, 78 | // where they filled some ptrs with -1 instead of nullptr 79 | return ptr != nullptr && ptr != reinterpret_cast(-1); 80 | }; 81 | 82 | std::stringstream stringStream; 83 | auto hasType = check_ptr(value->m_pszType); 84 | auto hasName = check_ptr(value->m_pszName); 85 | 86 | stringStream << "\""; 87 | 88 | if (hasType) 89 | stringStream << value->m_pszType; 90 | 91 | if (hasName) 92 | { 93 | if (hasType) 94 | stringStream << " "; 95 | stringStream << value->m_pszName; 96 | } 97 | 98 | stringStream << "\""; 99 | 100 | return stringStream.str(); 101 | } 102 | } 103 | } 104 | 105 | return {}; 106 | } 107 | 108 | } // namespace Dumpers::Schemas -------------------------------------------------------------------------------- /src/main/dumpers/schemas/metadata_stringifier.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * 6 | * source2gen 7 | * Copyright 2024 neverlosecc 8 | * ============================================================================= 9 | * 10 | * This program is free software; you can redistribute it and/or modify it under 11 | * the terms of the GNU General Public License, version 3.0, as published by the 12 | * Free Software Foundation. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * this program. If not, see . 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | 27 | struct CSchemaVarName { 28 | const char* m_pszName; 29 | const char* m_pszType; 30 | }; 31 | 32 | namespace Dumpers::Schemas 33 | { 34 | 35 | std::optional GetMetadataValue(const SchemaMetadataEntryData_t& entry); 36 | 37 | } // namespace Dumpers::Schemas -------------------------------------------------------------------------------- /src/main/dumpers/schemas/metadatalist.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * 6 | * Source2Gen 7 | * Copyright (C) 2024 neverlosecc 8 | * ============================================================================= 9 | * 10 | * This program is free software; you can redistribute it and/or modify it under 11 | * the terms of the GNU General Public License, version 3.0, as published by the 12 | * Free Software Foundation. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * this program. If not, see . 21 | */ 22 | #pragma once 23 | #include 24 | 25 | // List of printable metadata entries that are not tied to any structures. 26 | // These are used to determine if we can include the corresponding metadata entry value in the dump. 27 | // Original list sourced from Source2Gen project. 28 | namespace Dumpers::Schemas 29 | { 30 | 31 | enum class MetadataValueType { 32 | STRING, 33 | INLINE_STRING, 34 | INTEGER, 35 | FLOAT, 36 | VARNAME 37 | }; 38 | 39 | inline std::map g_mapMetadataNameToValue 40 | { 41 | // STRING 42 | { "MCellForDomain", MetadataValueType::STRING }, 43 | { "MCustomFGDMetadata", MetadataValueType::STRING }, 44 | { "MFieldVerificationName", MetadataValueType::STRING }, 45 | { "MKV3TransferName", MetadataValueType::STRING }, 46 | { "MNetworkAlias", MetadataValueType::STRING }, 47 | { "MNetworkChangeCallback", MetadataValueType::STRING }, 48 | { "MNetworkEncoder", MetadataValueType::STRING }, 49 | { "MNetworkExcludeByName", MetadataValueType::STRING }, 50 | { "MNetworkExcludeByUserGroup", MetadataValueType::STRING }, 51 | { "MNetworkIncludeByName", MetadataValueType::STRING }, 52 | { "MNetworkIncludeByUserGroup", MetadataValueType::STRING }, 53 | { "MNetworkReplayCompatField", MetadataValueType::STRING }, 54 | { "MNetworkSerializer", MetadataValueType::STRING }, 55 | { "MNetworkTypeAlias", MetadataValueType::STRING }, 56 | { "MNetworkUserGroup", MetadataValueType::STRING }, 57 | { "MNetworkUserGroupProxy", MetadataValueType::STRING }, 58 | { "MParticleReplacementOp", MetadataValueType::STRING }, 59 | { "MPropertyArrayElementNameKey", MetadataValueType::STRING }, 60 | { "MPropertyAttributeChoiceName", MetadataValueType::STRING }, 61 | { "MPropertyAttributeEditor", MetadataValueType::STRING }, 62 | { "MPropertyAttributeRange", MetadataValueType::STRING }, 63 | { "MPropertyAttributeSuggestionName", MetadataValueType::STRING }, 64 | { "MPropertyCustomEditor", MetadataValueType::STRING }, 65 | { "MPropertyCustomFGDType", MetadataValueType::STRING }, 66 | { "MPropertyDescription", MetadataValueType::STRING }, 67 | { "MPropertyExtendedEditor", MetadataValueType::STRING }, 68 | { "MPropertyFriendlyName", MetadataValueType::STRING }, 69 | { "MPropertyFriendlyName", MetadataValueType::STRING }, 70 | { "MPropertyGroupName", MetadataValueType::STRING }, 71 | { "MPropertyIconName", MetadataValueType::STRING }, 72 | { "MPropertyStartGroup", MetadataValueType::STRING }, 73 | { "MPropertySuppressExpr", MetadataValueType::STRING }, 74 | { "MPulseEditorHeaderIcon", MetadataValueType::STRING }, 75 | { "MResourceBlockType", MetadataValueType::STRING }, 76 | { "MScriptDescription", MetadataValueType::STRING }, 77 | { "MSrc1ImportAttributeName", MetadataValueType::STRING }, 78 | { "MSrc1ImportDmElementType", MetadataValueType::STRING }, 79 | { "MVDataOutlinerIcon", MetadataValueType::STRING }, 80 | { "MVDataOutlinerIconExpr", MetadataValueType::STRING }, 81 | { "MVDataUniqueMonotonicInt", MetadataValueType::STRING }, 82 | { "MVectorIsSometimesCoordinate", MetadataValueType::STRING }, 83 | // INLINE STRING 84 | { "MResourceTypeForInfoType", MetadataValueType::INLINE_STRING }, 85 | { "MDiskDataForResourceType", MetadataValueType::INLINE_STRING }, 86 | // INTEGER 87 | { "MResourceTypeForInfoType", MetadataValueType::INTEGER }, 88 | { "MDiskDataForResourceType", MetadataValueType::INTEGER }, 89 | { "MNetworkVarEmbeddedFieldOffsetDelta", MetadataValueType::INTEGER }, 90 | { "MNetworkBitCount", MetadataValueType::INTEGER }, 91 | { "MNetworkPriority", MetadataValueType::INTEGER }, 92 | { "MParticleOperatorType", MetadataValueType::INTEGER }, 93 | { "MPropertySortPriority", MetadataValueType::INTEGER }, 94 | { "MParticleMinVersion", MetadataValueType::INTEGER }, 95 | { "MParticleMaxVersion", MetadataValueType::INTEGER }, 96 | { "MNetworkEncodeFlags", MetadataValueType::INTEGER }, 97 | { "MResourceVersion", MetadataValueType::INTEGER }, 98 | { "MVDataNodeType", MetadataValueType::INTEGER }, 99 | { "MVDataOverlayType", MetadataValueType::INTEGER }, 100 | { "MAlignment", MetadataValueType::INTEGER }, 101 | { "MGenerateArrayKeynamesFirstIndex", MetadataValueType::INTEGER }, 102 | // FLOAT 103 | { "MNetworkMinValue", MetadataValueType::FLOAT }, 104 | { "MNetworkMaxValue", MetadataValueType::FLOAT }, 105 | // VARNAME 106 | { "MNetworkVarNames", MetadataValueType::VARNAME }, 107 | { "MNetworkOverride", MetadataValueType::VARNAME }, 108 | { "MNetworkVarTypeOverride", MetadataValueType::VARNAME }, 109 | { "MScriptDescription", MetadataValueType::VARNAME }, 110 | { "MParticleDomainTag", MetadataValueType::VARNAME }, 111 | }; 112 | 113 | } // namespace Dumpers::Schemas -------------------------------------------------------------------------------- /src/main/dumpers/schemas/schemas.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #include "schemas.h" 21 | #include "globalvariables.h" 22 | #include "interfaces.h" 23 | #include "schemasystem/schemasystem.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "metadatalist.h" 30 | #include 31 | #include 32 | #include 33 | #include "metadata_stringifier.h" 34 | #include 35 | 36 | namespace Dumpers::Schemas 37 | { 38 | void OutputMetadataEntry(const SchemaMetadataEntryData_t& entry, std::ofstream& output, bool tabulate) 39 | { 40 | output << (tabulate ? "\t" : "") << "// " << entry.m_pszName; 41 | if (entry.m_pData) 42 | { 43 | const auto metadataValue = GetMetadataValue(entry); 44 | if (metadataValue) 45 | output << " = " << *metadataValue; 46 | else 47 | output << " (UNKNOWN FOR PARSER)"; 48 | } 49 | 50 | output << "\n"; 51 | } 52 | 53 | void DumpClasses(CSchemaSystemTypeScope* typeScope, std::filesystem::path schemaPath, std::map>& foundFiles) 54 | { 55 | const auto& classes = typeScope->m_ClassBindings; 56 | 57 | UtlTSHashHandle_t* handles = new UtlTSHashHandle_t[classes.Count()]; 58 | classes.GetElements(0, classes.Count(), handles); 59 | 60 | for (int j = 0; j < classes.Count(); ++j) { 61 | const auto classInfo = classes[handles[j]]; 62 | 63 | if (!std::filesystem::is_directory(schemaPath / classInfo->m_pszProjectName)) 64 | if (!std::filesystem::create_directory(schemaPath / classInfo->m_pszProjectName)) 65 | return; 66 | 67 | // Some classes have :: in them which we can't save. 68 | auto sanitizedFileName = std::string(classInfo->m_pszName); 69 | std::replace(sanitizedFileName.begin(), sanitizedFileName.end(), ':', '_'); 70 | 71 | // We save the file in a map so that we know which files are outdated and should be removed 72 | foundFiles[classInfo->m_pszProjectName].insert(sanitizedFileName); 73 | 74 | std::ofstream output((schemaPath / classInfo->m_pszProjectName / sanitizedFileName).replace_extension(".h")); 75 | 76 | // Output metadata entries as comments before the class definition 77 | for (uint16_t k = 0; k < classInfo->m_nStaticMetadataCount; k++) 78 | { 79 | const auto& metadataEntry = classInfo->m_pStaticMetadata[k]; 80 | OutputMetadataEntry(metadataEntry, output, false); 81 | } 82 | 83 | output << "class " << classInfo->m_pszName; 84 | Globals::stringsIgnoreStream << classInfo->m_pszName << "\n"; 85 | 86 | if (classInfo->m_nBaseClassCount > 0) 87 | output << " : public " << classInfo->m_pBaseClasses[0].m_pClass->m_pszName; 88 | 89 | output << "\n{\n"; 90 | 91 | for (uint16_t k = 0; k < classInfo->m_nFieldCount; k++) 92 | { 93 | const auto& field = classInfo->m_pFields[k]; 94 | // Output metadata entires as comments before the field definition 95 | for (uint16_t l = 0; l < field.m_nStaticMetadataCount; l++) 96 | { 97 | const auto& metadataEntry = field.m_pStaticMetadata[l]; 98 | OutputMetadataEntry(metadataEntry, output, true); 99 | } 100 | 101 | output << "\t" << field.m_pType->m_sTypeName.String() << " " << field.m_pszName << ";\n"; 102 | Globals::stringsIgnoreStream << field.m_pszName << "\n"; 103 | } 104 | 105 | output << "};\n"; 106 | } 107 | } 108 | 109 | void DumpEnums(CSchemaSystemTypeScope* typeScope, std::filesystem::path schemaPath, std::map>& foundFiles) 110 | { 111 | const auto& enums = typeScope->m_EnumBindings; 112 | 113 | UtlTSHashHandle_t* handles = new UtlTSHashHandle_t[enums.Count()]; 114 | enums.GetElements(0, enums.Count(), handles); 115 | 116 | for (int j = 0; j < enums.Count(); ++j) { 117 | const auto enumInfo = enums[handles[j]]; 118 | 119 | if (!std::filesystem::is_directory(schemaPath / enumInfo->m_pszProjectName)) 120 | if (!std::filesystem::create_directory(schemaPath / enumInfo->m_pszProjectName)) 121 | return; 122 | 123 | // Some classes have :: in them which we can't save. 124 | auto sanitizedFileName = std::string(enumInfo->m_pszName); 125 | std::replace(sanitizedFileName.begin(), sanitizedFileName.end(), ':', '_'); 126 | 127 | // We save the file in a map so that we know which files are outdated and should be removed 128 | foundFiles[enumInfo->m_pszProjectName].insert(sanitizedFileName); 129 | 130 | std::ofstream output((schemaPath / enumInfo->m_pszProjectName / sanitizedFileName).replace_extension(".h")); 131 | 132 | for (uint16_t k = 0; k < enumInfo->m_nStaticMetadataCount; k++) 133 | { 134 | const auto& metadataEntry = enumInfo->m_pStaticMetadata[k]; 135 | OutputMetadataEntry(metadataEntry, output, false); 136 | } 137 | 138 | output << "enum " << enumInfo->m_pszName << " : "; 139 | Globals::stringsIgnoreStream << enumInfo->m_pszName << "\n"; 140 | 141 | switch (enumInfo->m_nAlignment) 142 | { 143 | case 1: 144 | output << "uint8_t"; 145 | break; 146 | case 2: 147 | output << "uint16_t"; 148 | break; 149 | case 4: 150 | output << "uint32_t"; 151 | break; 152 | case 8: 153 | output << "uint64_t"; 154 | break; 155 | default: 156 | output << "unknown alignment type"; 157 | } 158 | 159 | output << "\n{\n"; 160 | 161 | for (uint16_t k = 0; k < enumInfo->m_nEnumeratorCount; k++) 162 | { 163 | const auto& field = enumInfo->m_pEnumerators[k]; 164 | // Output metadata entires as comments before the field definition 165 | for (uint16_t l = 0; l < field.m_nStaticMetadataCount; l++) 166 | { 167 | const auto& metadataEntry = field.m_pStaticMetadata[l]; 168 | OutputMetadataEntry(metadataEntry, output, true); 169 | } 170 | 171 | output << "\t" << field.m_pszName << " = " << field.m_nValue << ",\n"; 172 | Globals::stringsIgnoreStream << field.m_pszName << "\n"; 173 | } 174 | 175 | output << "};\n"; 176 | } 177 | } 178 | 179 | 180 | void DumpTypeScope(CSchemaSystemTypeScope* typeScope, std::filesystem::path schemaPath, std::map>& foundFiles) 181 | { 182 | DumpClasses(typeScope, schemaPath, foundFiles); 183 | DumpEnums(typeScope, schemaPath, foundFiles); 184 | } 185 | 186 | void Dump() 187 | { 188 | spdlog::info("Dumping schemasystem"); 189 | auto schemaSystem = Interfaces::schemaSystem; 190 | 191 | const auto& typeScopes = schemaSystem->m_TypeScopes; 192 | const auto schemaPath = Globals::outputPath / "schemas"; 193 | 194 | if (!std::filesystem::is_directory(schemaPath)) 195 | if (!std::filesystem::create_directory(schemaPath)) 196 | return; 197 | 198 | std::map> foundFiles; 199 | 200 | for (auto i = 0; i < typeScopes.GetNumStrings(); ++i) 201 | DumpTypeScope(typeScopes[i], schemaPath, foundFiles); 202 | 203 | DumpTypeScope(schemaSystem->GlobalTypeScope(), schemaPath, foundFiles); 204 | 205 | for (const auto& entry : std::filesystem::directory_iterator(schemaPath)) 206 | { 207 | auto projectName = entry.path().filename().string(); 208 | bool isInMap = foundFiles.find(projectName) != foundFiles.end(); 209 | 210 | if (entry.is_directory() && !isInMap) 211 | { 212 | spdlog::info("Removing orphan schema folder {}", entry.path().generic_string()); 213 | std::filesystem::remove_all(entry.path()); 214 | } 215 | else if (isInMap) 216 | { 217 | 218 | for (const auto& typeScopePath : std::filesystem::directory_iterator(entry.path())) 219 | { 220 | auto& filesSet = foundFiles[projectName]; 221 | 222 | if (filesSet.find(typeScopePath.path().stem().string()) == filesSet.end()) 223 | { 224 | spdlog::info("Removing orphan schema file {}", typeScopePath.path().generic_string()); 225 | std::filesystem::remove(typeScopePath.path()); 226 | } 227 | } 228 | } 229 | } 230 | } 231 | 232 | } // namespace Dumpers::Schemas -------------------------------------------------------------------------------- /src/main/dumpers/schemas/schemas.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | #pragma once 20 | 21 | namespace Dumpers::Schemas 22 | { 23 | 24 | void Dump(); 25 | 26 | } // namespace Dumpers::Schemas -------------------------------------------------------------------------------- /src/main/globalvariables.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace Globals { 26 | 27 | inline std::filesystem::path outputPath; 28 | inline std::ofstream stringsIgnoreStream; 29 | 30 | } // namespace Interfaces -------------------------------------------------------------------------------- /src/main/interfaces.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | #pragma once 20 | 21 | #include 22 | 23 | class CSchemaSystem; 24 | 25 | namespace Interfaces { 26 | 27 | inline CSchemaSystem* schemaSystem = nullptr; 28 | inline ICvar* cvar = nullptr; 29 | 30 | } // namespace Interfaces -------------------------------------------------------------------------------- /src/main/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #include "main.h" 21 | #include "utils/common.h" 22 | #include "interfaces.h" 23 | #include "globalvariables.h" 24 | #include "appframework.h" 25 | #include 26 | #include 27 | 28 | #include "dumpers/concommands/concommands.h" 29 | #include "dumpers/schemas/schemas.h" 30 | 31 | void Usage() 32 | { 33 | printf("Usage: DumpSource2 \n"); 34 | } 35 | 36 | 37 | int main(int argc, char** argv) 38 | { 39 | spdlog::cfg::load_env_levels("LOGLEVEL"); 40 | 41 | if (argc <= 1) 42 | { 43 | Usage(); 44 | return 0; 45 | } 46 | 47 | Globals::outputPath = argv[1]; 48 | 49 | if (!std::filesystem::is_directory(Globals::outputPath)) 50 | { 51 | printf("Output path is not a valid folder\n"); 52 | return 0; 53 | } 54 | 55 | Globals::stringsIgnoreStream = std::ofstream(Globals::outputPath / ".stringsignore"); 56 | spdlog::info("Starting Source2Dumper"); 57 | 58 | InitializeCoreModules(); 59 | InitializeAppSystems(); 60 | 61 | Dumpers::ConCommands::Dump(); 62 | Dumpers::Schemas::Dump(); 63 | 64 | spdlog::info("Dumped successfully"); 65 | 66 | // skips atexit calls that cause a segfault on dota only while unregistering cvar callbacks 67 | _Exit(0); 68 | } -------------------------------------------------------------------------------- /src/main/main.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | -------------------------------------------------------------------------------- /src/main/modules.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * DumpSource2 4 | * Copyright (C) 2024 ValveResourceFormat Contributors 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include "utils/module.h" 23 | 24 | namespace Modules { 25 | 26 | inline std::unique_ptr schemaSystem = nullptr; 27 | inline std::unique_ptr tier0 = nullptr; 28 | 29 | } // namespace Modules -------------------------------------------------------------------------------- /src/main/network_connection.pb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef int ENetworkDisconnectionReason; -------------------------------------------------------------------------------- /src/main/utils/common.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "threadtools.h" 5 | #include "utlstring.h" 6 | #include "bufferstring.h" 7 | #include "utlbuffer.h" 8 | #include 9 | 10 | void ExitError(const char* pMsg, ...) 11 | { 12 | static char szBuffer[2048]; 13 | va_list params; 14 | va_start(params, pMsg); 15 | vsnprintf(szBuffer, sizeof(szBuffer), pMsg, params); 16 | va_end(params); 17 | spdlog::critical("{}", szBuffer); 18 | 19 | exit(1); 20 | } 21 | 22 | /* tier0 stub */ 23 | 24 | void CThreadSpinRWLock::LockForRead(const char* pFileName, int nLine) 25 | { 26 | // STUB 27 | } 28 | 29 | void CThreadSpinRWLock::UnlockRead(const char* pFileName, int nLine) 30 | { 31 | // STUB 32 | } 33 | 34 | LoggingResponse_t LoggingSystem_LogAssert(const char* pMessageFormat, ...) 35 | { 36 | return LR_ABORT; 37 | } 38 | 39 | bool CUtlString::operator==(const CUtlString& src) const { 40 | // STUB 41 | return false; 42 | } 43 | 44 | const char* CBufferString::Insert(int, char const *, int, bool) { 45 | // STUB 46 | return nullptr; 47 | } 48 | 49 | int CBufferString::AppendFormat(char const*, ...) { 50 | // STUB 51 | return 0; 52 | } 53 | 54 | int CBufferString::Format(char const*, ...) { 55 | // STUB 56 | return 0; 57 | } 58 | 59 | void CBufferString::Purge(int) { 60 | // STUB 61 | } 62 | 63 | int CUtlBuffer::ParseToken(struct characterset_t const*, char*, int, bool) { 64 | // STUB 65 | return 0; 66 | } 67 | 68 | void CUtlString::Purge() { 69 | // STUB 70 | } 71 | 72 | void CUtlString::Set(const char*) { 73 | // STUB 74 | } 75 | 76 | void CUtlString::SetDirect(const char*, int) { 77 | // STUB 78 | } 79 | 80 | void CUtlString::Trim(const char*) { 81 | // STUB 82 | } 83 | 84 | CUtlBuffer::CUtlBuffer(void const*, int, int) { 85 | // STUB 86 | } 87 | 88 | void ConMsg(const char*, ...) { 89 | // STUB 90 | } 91 | 92 | // STUB 93 | IMemAlloc* g_pMemAlloc = nullptr; 94 | 95 | void Plat_ExitProcess(int) { 96 | // STUB 97 | } 98 | 99 | #ifdef GAME_CS2 100 | void Plat_FatalErrorFunc(const tchar* pMsg, ...) { 101 | // STUB 102 | } 103 | #endif 104 | 105 | bool Plat_IsInDebugSession() { 106 | // STUB 107 | return false; 108 | } 109 | 110 | void* UtlMemory_Alloc(void*, bool, int, int) { 111 | // STUB 112 | return nullptr; 113 | } 114 | 115 | int UtlMemory_CalcNewAllocationCount(int, int, int, int) 116 | { 117 | // STUB 118 | return 0; 119 | } 120 | 121 | void UtlMemory_FailedAllocation(int, int) { 122 | // STUB 123 | } 124 | 125 | int64 V_atoi(const char*) 126 | { 127 | // STUB 128 | return 0; 129 | } 130 | 131 | int V_stricmp_fast(const char*, const char*) 132 | { 133 | // STUB 134 | return 0; 135 | } 136 | 137 | bool V_StringToBool(const char*, bool, bool*, char**, uint, IParsingErrorListener*) 138 | { 139 | // STUB 140 | return false; 141 | } 142 | 143 | void V_StringToColor(const char*, Color&, bool*, char**, uint, IParsingErrorListener*) 144 | { 145 | // STUB 146 | } 147 | 148 | float32 V_StringToFloat32(const char*, float32, bool*, char**, uint, IParsingErrorListener*) 149 | { 150 | // STUB 151 | return 0; 152 | } 153 | 154 | float64 V_StringToFloat64(const char*, float64, bool*, char**, uint, IParsingErrorListener*) 155 | { 156 | // STUB 157 | return 0; 158 | } 159 | 160 | int16 V_StringToInt16(const char*, int16, bool*, char**, uint, IParsingErrorListener*) 161 | { 162 | // STUB 163 | return 0; 164 | } 165 | 166 | int32 V_StringToInt32(const char*, int32, bool*, char**, uint, IParsingErrorListener*) 167 | { 168 | // STUB 169 | return 0; 170 | } 171 | 172 | int64 V_StringToInt64(const char*, int64, bool*, char**, uint, IParsingErrorListener*) 173 | { 174 | // STUB 175 | return 0; 176 | } 177 | 178 | void V_StringToQAngle(const char*, QAngle&, bool*, char**, uint, IParsingErrorListener*) { 179 | // STUB 180 | } 181 | 182 | uint16 V_StringToUint16(const char*, uint16, bool*, char**, uint, IParsingErrorListener*) { 183 | // STUB 184 | return 0; 185 | } 186 | 187 | uint32 V_StringToUint32(const char*, uint32, bool*, char**, uint, IParsingErrorListener*) { 188 | // STUB 189 | return 0; 190 | } 191 | 192 | uint64 V_StringToUint64(const char*, uint64, bool*, char**, uint, IParsingErrorListener*) { 193 | // STUB 194 | return 0; 195 | } 196 | 197 | void V_StringToVector(const char*, Vector&, bool*, char**, uint, IParsingErrorListener*) 198 | { 199 | // STUB 200 | } 201 | 202 | void V_StringToVector2D(const char*, Vector2D&, bool*, char**, uint, IParsingErrorListener*) 203 | { 204 | // STUB 205 | } 206 | 207 | void V_StringToVector4D(const char*, Vector4D&, bool*, char**, uint, IParsingErrorListener*) 208 | { 209 | // STUB 210 | } 211 | 212 | int V_tier0_strlen(const char*) { 213 | // STUB 214 | return 0; 215 | } 216 | 217 | void Warning(const char*, ...) { 218 | // STUB 219 | } -------------------------------------------------------------------------------- /src/main/utils/common.h: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | #define PLATFORM_FOLDER "win64" 3 | #else 4 | #define PLATFORM_FOLDER "linuxsteamrt64" 5 | #endif 6 | 7 | void ExitError(const char* pMsg, ...); -------------------------------------------------------------------------------- /src/main/utils/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023-2024 Source2ZE 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include "oslink.h" 22 | #include "dbg.h" 23 | #include "interface.h" 24 | #include "strtools.h" 25 | #include "plat.h" 26 | #include 27 | #include "common.h" 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef _WIN32 33 | #include 34 | #endif 35 | 36 | enum SigError 37 | { 38 | SIG_OK, 39 | SIG_NOT_FOUND, 40 | SIG_FOUND_MULTIPLE, 41 | }; 42 | 43 | // equivalent to FindSignature, but allows for multiple signatures to be found and iterated over 44 | class SignatureIterator 45 | { 46 | public: 47 | SignatureIterator(void* pBase, size_t iSize, const byte* pSignature, size_t iSigLength) : 48 | m_pBase((byte*)pBase), m_iSize(iSize), m_pSignature(pSignature), m_iSigLength(iSigLength) 49 | { 50 | m_pCurrent = m_pBase; 51 | } 52 | 53 | void* FindNext(bool allowWildcard) 54 | { 55 | for (size_t i = 0; i < m_iSize; i++) 56 | { 57 | size_t Matches = 0; 58 | while (*(m_pCurrent + i + Matches) == m_pSignature[Matches] || (allowWildcard && m_pSignature[Matches] == '\x2A')) 59 | { 60 | Matches++; 61 | if (Matches == m_iSigLength) 62 | { 63 | m_pCurrent += i + 1; 64 | return m_pCurrent - 1; 65 | } 66 | } 67 | } 68 | 69 | return nullptr; 70 | } 71 | private: 72 | byte* m_pBase; 73 | size_t m_iSize; 74 | const byte* m_pSignature; 75 | size_t m_iSigLength; 76 | byte* m_pCurrent; 77 | }; 78 | 79 | class CModule 80 | { 81 | public: 82 | CModule(const char *path, const char *module) : 83 | m_pszModule(module), m_pszPath(path) 84 | { 85 | spdlog::debug("Loading \"{}\" module", m_pszModule); 86 | auto szModule = (std::filesystem::current_path() / path / (MODULE_PREFIX + std::string(m_pszModule) + MODULE_EXT)).lexically_normal().generic_string(); 87 | 88 | m_hModule = dlmount(szModule.c_str()); 89 | 90 | if (!m_hModule) 91 | { 92 | #ifdef _WIN32 93 | ExitError("Failed to load %s", szModule.c_str()); 94 | #else 95 | ExitError("Failed to load %s\n%s", szModule.c_str(), dlerror()); 96 | #endif 97 | return; 98 | } 99 | 100 | #ifdef _WIN32 101 | MODULEINFO m_hModuleInfo; 102 | GetModuleInformation(GetCurrentProcess(), m_hModule, &m_hModuleInfo, sizeof(m_hModuleInfo)); 103 | 104 | m_base = (void *)m_hModuleInfo.lpBaseOfDll; 105 | m_size = m_hModuleInfo.SizeOfImage; 106 | InitializeSections(); 107 | #else 108 | if (int e = GetModuleInformation(m_hModule, &m_base, &m_size, m_sections)) 109 | ExitError("Failed to get module info for %s, error %d", szModule, e); 110 | #endif 111 | 112 | spdlog::trace("Initialized module {} base: {:p}, size: {:x}", m_pszModule, m_base, m_size); 113 | } 114 | 115 | void *FindSignature(const byte *pData, size_t iSigLength, int &error) 116 | { 117 | unsigned char *pMemory; 118 | void *return_addr = nullptr; 119 | error = 0; 120 | 121 | pMemory = (byte*)m_base; 122 | 123 | for (size_t i = 0; i < m_size; i++) 124 | { 125 | size_t Matches = 0; 126 | while (*(pMemory + i + Matches) == pData[Matches] || pData[Matches] == '\x2A') 127 | { 128 | Matches++; 129 | if (Matches == iSigLength) 130 | { 131 | if (return_addr) 132 | { 133 | error = SIG_FOUND_MULTIPLE; 134 | return return_addr; 135 | } 136 | 137 | return_addr = (void *)(pMemory + i); 138 | break; 139 | } 140 | } 141 | } 142 | 143 | if (!return_addr) 144 | error = SIG_NOT_FOUND; 145 | 146 | return return_addr; 147 | } 148 | 149 | CreateInterfaceFn GetFactory() 150 | { 151 | CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(m_hModule, "CreateInterface"); 152 | 153 | if (!fn) 154 | ExitError("Could not find CreateInterface in %s", m_pszModule); 155 | 156 | return fn; 157 | } 158 | 159 | template 160 | T FindInterface(const char *name) 161 | { 162 | CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(m_hModule, "CreateInterface"); 163 | 164 | if (!fn) 165 | ExitError("Could not find CreateInterface in %s", m_pszModule); 166 | 167 | void *pInterface = fn(name, nullptr); 168 | 169 | if (!pInterface) 170 | { 171 | ExitError("Could not find %s in %s", name, m_pszModule); 172 | } 173 | 174 | return (T)pInterface; 175 | } 176 | 177 | Section* GetSection(const std::string_view name) 178 | { 179 | for (auto& section : m_sections) 180 | { 181 | if (section.m_szName == name) 182 | return §ion; 183 | } 184 | 185 | return nullptr; 186 | } 187 | #ifdef _WIN32 188 | void InitializeSections(); 189 | #endif 190 | void* FindVirtualTable(const std::string& name); 191 | public: 192 | const char *m_pszModule; 193 | const char* m_pszPath; 194 | HINSTANCE m_hModule; 195 | void* m_base = 0; 196 | size_t m_size = 0; 197 | std::vector
m_sections; 198 | }; -------------------------------------------------------------------------------- /src/main/utils/oslink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 sw=4 tw=99 noet : 3 | * ====================================================== 4 | * Metamod:Source 5 | * Copyright (C) 2004-2009 AlliedModders LLC and authors. 6 | * All rights reserved. 7 | * ====================================================== 8 | * 9 | * This software is provided 'as-is', without any express or implied warranty. 10 | * In no event will the authors be held liable for any damages arising from 11 | * the use of this software. 12 | * 13 | * Permission is granted to anyone to use this software for any purpose, 14 | * including commercial applications, and to alter it and redistribute it 15 | * freely, subject to the following restrictions: 16 | * 17 | * 1. The origin of this software must not be misrepresented; you must not 18 | * claim that you wrote the original software. If you use this software in a 19 | * product, an acknowledgment in the product documentation would be 20 | * appreciated but is not required. 21 | * 2. Altered source versions must be plainly marked as such, and must not be 22 | * misrepresented as being the original software. 23 | * 3. This notice may not be removed or altered from any source distribution. 24 | */ 25 | 26 | #ifndef _INCLUDE_OSLINK_H 27 | #define _INCLUDE_OSLINK_H 28 | 29 | /** 30 | * @brief Defines OS-independent information 31 | * @file oslink.h 32 | */ 33 | 34 | #if defined __WIN32__ || defined _WIN32 || defined WIN32 35 | #define WIN32_LEAN_AND_MEAN 36 | #define OS_WIN32 37 | #if defined _MSC_VER && _MSC_VER >= 1400 38 | #undef ARRAYSIZE 39 | #else 40 | #define mkdir(a) _mkdir(a) 41 | #endif 42 | #include 43 | #include 44 | #include 45 | #define dlmount(x) LoadLibrary(x) 46 | #define dlsym(x, s) GetProcAddress(x, s) 47 | #define dlclose(x) FreeLibrary(x) 48 | const char* dlerror(); 49 | #define abspath(x, s) _fullpath(x, s, sizeof(x)) 50 | #define PATH_SEP_STR "\\" 51 | #define PATH_SEP_CHAR '\\' 52 | #define ALT_SEP_CHAR '/' 53 | #define PATH_SIZE MAX_PATH 54 | #define strcasecmp stricmp 55 | inline bool _IsPathSepChar(char c) { return (c == '/' || c == '\\'); } 56 | #elif defined __linux__ || defined __APPLE__ 57 | #if defined __linux__ 58 | #define OS_LINUX 59 | #elif defined __APPLE__ 60 | #define OS_DARWIN 61 | #include 62 | #endif 63 | #include 64 | #include 65 | #include 66 | #include 67 | typedef void* HINSTANCE; 68 | #define dlmount(x) dlopen(x,RTLD_NOW) 69 | #define abspath(x, s) realpath(s, x) 70 | #define PATH_SEP_STR "/" 71 | #define PATH_SEP_CHAR '/' 72 | #define ALT_SEP_CHAR '\\' 73 | #define PATH_SIZE PATH_MAX 74 | #ifndef stricmp 75 | #define stricmp strcasecmp 76 | #endif 77 | #ifndef strnicmp 78 | #define strnicmp strncasecmp 79 | #endif 80 | inline bool _IsPathSepChar(char c) { return (c == '/'); } 81 | #endif 82 | 83 | #if defined __linux__ || defined __APPLE__ 84 | #include 85 | int GetLastError(); 86 | #endif 87 | 88 | bool GetFileOfAddress(void* pAddr, char* buffer, size_t maxlength); 89 | 90 | #if defined __WIN32__ || defined _WIN32 || defined WIN32 91 | #define SMM_API extern "C" __declspec(dllexport) 92 | #elif defined __GNUC__ 93 | #define SMM_API extern "C" __attribute__ ((visibility("default"))) 94 | #endif 95 | 96 | #if defined __WIN32__ || defined _WIN32 || defined WIN32 97 | typedef __int64 int64_t; 98 | typedef unsigned __int64 uint64_t; 99 | typedef __int32 int32_t; 100 | typedef unsigned __int32 uint32_t; 101 | #elif defined __GNUC__ 102 | #include 103 | #endif 104 | 105 | #endif //_INCLUDE_OSLINK_H -------------------------------------------------------------------------------- /src/main/utils/plat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023-2024 Source2ZE 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include 22 | #include 23 | #include 24 | 25 | struct Section 26 | { 27 | std::string m_szName; 28 | void* m_pBase; 29 | size_t m_iSize; 30 | }; 31 | 32 | #if defined(_WIN32) 33 | #define FASTCALL __fastcall 34 | #define THISCALL __thiscall 35 | #else 36 | #define FASTCALL 37 | #define THISCALL 38 | #define strtok_s strtok_r 39 | #endif 40 | 41 | struct Module 42 | { 43 | #ifndef _WIN32 44 | void* pHandle; 45 | #endif 46 | uint8_t* pBase; 47 | unsigned int nSize; 48 | }; 49 | 50 | #ifndef _WIN32 51 | int GetModuleInformation(HINSTANCE module, void** base, size_t* length, std::vector
& m_sections); 52 | #endif 53 | 54 | #ifdef _WIN32 55 | #define MODULE_PREFIX "" 56 | #define MODULE_EXT ".dll" 57 | #else 58 | #define MODULE_PREFIX "lib" 59 | #define MODULE_EXT ".so" 60 | #endif 61 | 62 | void Plat_WriteMemory(void* pPatchAddress, uint8_t *pPatch, int iPatchSize); -------------------------------------------------------------------------------- /src/main/utils/plat_unix.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023-2024 Source2ZE 5 | * 6 | * DynLibUtils 7 | * Copyright (C) 2023 komashchenko (Phoenix) 8 | * ============================================================================= 9 | * 10 | * This program is free software; you can redistribute it and/or modify it under 11 | * the terms of the GNU General Public License, version 3.0, as published by the 12 | * Free Software Foundation. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * this program. If not, see . 21 | */ 22 | 23 | #ifdef __linux__ 24 | #include "module.h" 25 | #include "plat.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "sys/mman.h" 31 | #include 32 | #include 33 | #include 34 | #include "dbg.h" 35 | #include 36 | #include 37 | #include 38 | 39 | #include "tier0/memdbgon.h" 40 | 41 | #define PAGE_SIZE 4096 42 | #define PAGE_ALIGN_UP(x) ((x + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) 43 | 44 | struct ModuleInfo 45 | { 46 | const char* path; // in 47 | uint8_t* base; // out 48 | uint size; // out 49 | }; 50 | 51 | // https://github.com/alliedmodders/sourcemod/blob/master/core/logic/MemoryUtils.cpp#L502-L587 52 | // https://github.com/komashchenko/DynLibUtils/blob/5eb95475170becfcc64fd5d32d14ec2b76dcb6d4/module_linux.cpp#L95 53 | int GetModuleInformation(HINSTANCE hModule, void** base, size_t* length, std::vector
& m_sections) 54 | { 55 | 56 | link_map* lmap; 57 | if (dlinfo(hModule, RTLD_DI_LINKMAP, &lmap) != 0) 58 | { 59 | dlclose(hModule); 60 | return 1; 61 | } 62 | 63 | int fd = open(lmap->l_name, O_RDONLY); 64 | if (fd == -1) 65 | { 66 | dlclose(hModule); 67 | return 2; 68 | } 69 | 70 | struct stat st; 71 | if (fstat(fd, &st) == 0) 72 | { 73 | void* map = mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 74 | if (map != MAP_FAILED) 75 | { 76 | ElfW(Ehdr)* ehdr = static_cast(map); 77 | ElfW(Shdr)* shdrs = reinterpret_cast(reinterpret_cast(ehdr) + ehdr->e_shoff); 78 | const char* strTab = reinterpret_cast(reinterpret_cast(ehdr) + shdrs[ehdr->e_shstrndx].sh_offset); 79 | 80 | for (auto i = 0; i < ehdr->e_phnum; ++i) 81 | { 82 | ElfW(Phdr)* phdr = reinterpret_cast(reinterpret_cast(ehdr) + ehdr->e_phoff + i * ehdr->e_phentsize); 83 | if (phdr->p_type == PT_LOAD && phdr->p_flags & PF_X) 84 | { 85 | *base = reinterpret_cast(lmap->l_addr + phdr->p_vaddr); 86 | *length = phdr->p_filesz; 87 | break; 88 | } 89 | } 90 | 91 | for (auto i = 0; i < ehdr->e_shnum; ++i) 92 | { 93 | ElfW(Shdr)* shdr = reinterpret_cast(reinterpret_cast(shdrs) + i * ehdr->e_shentsize); 94 | if (*(strTab + shdr->sh_name) == '\0') 95 | continue; 96 | 97 | Section section; 98 | section.m_szName = strTab + shdr->sh_name; 99 | section.m_pBase = reinterpret_cast(lmap->l_addr + shdr->sh_addr); 100 | section.m_iSize = shdr->sh_size; 101 | m_sections.push_back(section); 102 | } 103 | 104 | munmap(map, st.st_size); 105 | } 106 | } 107 | 108 | close(fd); 109 | 110 | return 0; 111 | } 112 | 113 | static int parse_prot(const char* s) 114 | { 115 | int prot = 0; 116 | 117 | for (; *s; s++) 118 | { 119 | switch (*s) 120 | { 121 | case '-': 122 | break; 123 | case 'r': 124 | prot |= PROT_READ; 125 | break; 126 | case 'w': 127 | prot |= PROT_WRITE; 128 | break; 129 | case 'x': 130 | prot |= PROT_EXEC; 131 | break; 132 | case 's': 133 | break; 134 | case 'p': 135 | break; 136 | default: 137 | break; 138 | } 139 | } 140 | 141 | return prot; 142 | } 143 | 144 | static int get_prot(void* pAddr, size_t nSize) 145 | { 146 | FILE* f = fopen("/proc/self/maps", "r"); 147 | 148 | uintptr_t nAddr = (uintptr_t)pAddr; 149 | 150 | char line[512]; 151 | while (fgets(line, sizeof(line), f)) 152 | { 153 | char start[16]; 154 | char end[16]; 155 | char prot[16]; 156 | 157 | const char* src = line; 158 | 159 | char* dst = start; 160 | while (*src != '-') 161 | *dst++ = *src++; 162 | *dst = 0; 163 | 164 | src++; // skip "-"" 165 | 166 | dst = end; 167 | while (!isspace(*src)) 168 | *dst++ = *src++; 169 | *dst = 0; 170 | 171 | src++; // skip space 172 | 173 | dst = prot; 174 | while (!isspace(*src)) 175 | *dst++ = *src++; 176 | *dst = 0; 177 | 178 | uintptr_t nStart = (uintptr_t)strtoul(start, nullptr, 16); 179 | uintptr_t nEnd = (uintptr_t)strtoul(end, nullptr, 16); 180 | 181 | if (nStart < nAddr && nEnd >(nAddr + nSize)) 182 | { 183 | fclose(f); 184 | return parse_prot(prot); 185 | } 186 | } 187 | 188 | fclose(f); 189 | return 0; 190 | } 191 | 192 | void Plat_WriteMemory(void* pPatchAddress, uint8_t* pPatch, int iPatchSize) 193 | { 194 | int old_prot = get_prot(pPatchAddress, iPatchSize); 195 | 196 | uintptr_t page_size = sysconf(_SC_PAGESIZE); 197 | uint8_t* align_addr = (uint8_t*)((uintptr_t)pPatchAddress & ~(page_size - 1)); 198 | 199 | uint8_t* end = (uint8_t*)pPatchAddress + iPatchSize; 200 | uintptr_t align_size = end - align_addr; 201 | 202 | int result = mprotect(align_addr, align_size, PROT_READ | PROT_WRITE); 203 | 204 | memcpy(pPatchAddress, pPatch, iPatchSize); 205 | 206 | result = mprotect(align_addr, align_size, old_prot); 207 | } 208 | 209 | void* CModule::FindVirtualTable(const std::string& name) 210 | { 211 | auto readOnlyData = GetSection(".rodata"); 212 | auto readOnlyRelocations = GetSection(".data.rel.ro"); 213 | 214 | if (!readOnlyData || !readOnlyRelocations) 215 | { 216 | printf("Failed to find .rodata or .data.rel.ro section\n"); 217 | return nullptr; 218 | } 219 | 220 | std::string decoratedTableName = std::to_string(name.length()) + name; 221 | 222 | SignatureIterator sigIt(readOnlyData->m_pBase, readOnlyData->m_iSize, (const byte*)decoratedTableName.c_str(), decoratedTableName.size() + 1); 223 | void* classNameString = sigIt.FindNext(false); 224 | 225 | if (!classNameString) 226 | { 227 | printf("Failed to find type descriptor for %s\n", name.c_str()); 228 | return nullptr; 229 | } 230 | 231 | SignatureIterator sigIt2(readOnlyRelocations->m_pBase, readOnlyRelocations->m_iSize, (const byte*)&classNameString, sizeof(void*)); 232 | void* typeName = sigIt2.FindNext(false); 233 | 234 | if (!typeName) 235 | { 236 | printf("Failed to find type name for %s\n", name.c_str()); 237 | return nullptr; 238 | } 239 | 240 | void* typeInfo = (void*)((uintptr_t)typeName - 0x8); 241 | 242 | for (const auto& sectionName : { std::string_view(".data.rel.ro"), std::string_view(".data.rel.ro.local") }) 243 | { 244 | auto section = GetSection(sectionName); 245 | if (!section) 246 | continue; 247 | 248 | SignatureIterator sigIt3(section->m_pBase, section->m_iSize, (const byte*)&typeInfo, sizeof(void*)); 249 | 250 | while (void* vtable = sigIt3.FindNext(false)) 251 | { 252 | if(*(int64_t*)((uintptr_t)vtable - 0x8) == 0) 253 | return (void*)((uintptr_t)vtable + 0x8); 254 | } 255 | } 256 | 257 | printf("Failed to find vtable for %s\n", name.c_str()); 258 | return nullptr; 259 | } 260 | #endif 261 | 262 | -------------------------------------------------------------------------------- /src/main/utils/plat_win.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023-2024 Source2ZE 5 | * 6 | * DynLibUtils 7 | * Copyright (C) 2023 komashchenko (Phoenix) 8 | * ============================================================================= 9 | * 10 | * This program is free software; you can redistribute it and/or modify it under 11 | * the terms of the GNU General Public License, version 3.0, as published by the 12 | * Free Software Foundation. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU General Public License along with 20 | * this program. If not, see . 21 | */ 22 | 23 | #include "module.h" 24 | #include "plat.h" 25 | 26 | #include "tier0/memdbgon.h" 27 | 28 | #ifdef WIN32 29 | 30 | void Plat_WriteMemory(void* pPatchAddress, uint8_t* pPatch, int iPatchSize) 31 | { 32 | WriteProcessMemory(GetCurrentProcess(), pPatchAddress, (void*)pPatch, iPatchSize, nullptr); 33 | } 34 | 35 | void CModule::InitializeSections() 36 | { 37 | IMAGE_DOS_HEADER* pDosHeader = reinterpret_cast(m_hModule); 38 | IMAGE_NT_HEADERS* pNtHeader = reinterpret_cast(reinterpret_cast(m_hModule) + pDosHeader->e_lfanew); 39 | 40 | IMAGE_SECTION_HEADER* pSectionHeader = IMAGE_FIRST_SECTION(pNtHeader); 41 | 42 | for (int i = 0; i < pNtHeader->FileHeader.NumberOfSections; i++) 43 | { 44 | Section section; 45 | section.m_szName = (char*)pSectionHeader[i].Name; 46 | section.m_pBase = (void*)((uint8_t*)m_base + pSectionHeader[i].VirtualAddress); 47 | section.m_iSize = pSectionHeader[i].SizeOfRawData; 48 | 49 | m_sections.push_back(std::move(section)); 50 | } 51 | } 52 | 53 | void* CModule::FindVirtualTable(const std::string& name) 54 | { 55 | auto runTimeData = GetSection(".data"); 56 | auto readOnlyData = GetSection(".rdata"); 57 | 58 | if (!runTimeData || !readOnlyData) 59 | { 60 | //Warning("Failed to find .data or .rdata section\n"); 61 | return nullptr; 62 | } 63 | 64 | std::string decoratedTableName = ".?AV" + name + "@@"; 65 | 66 | SignatureIterator sigIt(runTimeData->m_pBase, runTimeData->m_iSize, (const byte*)decoratedTableName.c_str(), decoratedTableName.size() + 1); 67 | void* typeDescriptor = sigIt.FindNext(false); 68 | 69 | if (!typeDescriptor) 70 | { 71 | //Warning("Failed to find type descriptor for %s\n", name.c_str()); 72 | return nullptr; 73 | } 74 | 75 | typeDescriptor = (void*)((uintptr_t)typeDescriptor - 0x10); 76 | 77 | const uint32_t rttiTDRva = (uintptr_t)typeDescriptor - (uintptr_t)m_base; 78 | 79 | //ConMsg("RTTI Type Descriptor RVA: 0x%p\n", rttiTDRva); 80 | 81 | SignatureIterator sigIt2(readOnlyData->m_pBase, readOnlyData->m_iSize, (const byte*)&rttiTDRva, sizeof(uint32_t)); 82 | 83 | while (void* completeObjectLocator = sigIt2.FindNext(false)) 84 | { 85 | auto completeObjectLocatorHeader = (uintptr_t)completeObjectLocator - 0xC; 86 | // check RTTI Complete Object Locator header, always 0x1 87 | if(*(int32_t*)(completeObjectLocatorHeader) != 1) 88 | continue; 89 | 90 | // check RTTI Complete Object Locator vtable offset 91 | if (*(int32_t*)((uintptr_t)completeObjectLocator - 0x8) != 0) 92 | continue; 93 | 94 | SignatureIterator sigIt3(readOnlyData->m_pBase, readOnlyData->m_iSize, (const byte*)&completeObjectLocatorHeader, sizeof(void*)); 95 | void* vtable = sigIt3.FindNext(false); 96 | 97 | if (!vtable) 98 | { 99 | //Warning("Failed to find vtable for %s\n", name.c_str()); 100 | return nullptr; 101 | } 102 | 103 | return (void*)((uintptr_t)vtable + 0x8); 104 | } 105 | 106 | //Warning("Failed to find RTTI Complete Object Locator for %s\n", name.c_str()); 107 | return nullptr; 108 | } 109 | 110 | #endif // WIN32 -------------------------------------------------------------------------------- /src/main/utils/plat_win.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | -------------------------------------------------------------------------------- /src/main/utils/virtual.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ============================================================================= 3 | * CS2Fixes 4 | * Copyright (C) 2023-2024 Source2ZE 5 | * ============================================================================= 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU General Public License, version 3.0, as published by the 9 | * Free Software Foundation. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | * details. 15 | * 16 | * You should have received a copy of the GNU General Public License along with 17 | * this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include "platform.h" 22 | 23 | #define CALL_VIRTUAL(retType, idx, ...) \ 24 | vmt::CallVirtual(idx, __VA_ARGS__) 25 | 26 | namespace vmt 27 | { 28 | template 29 | inline T GetVMethod(uint32 uIndex, void *pClass) 30 | { 31 | if (!pClass) 32 | { 33 | printf("Tried getting virtual function from a null class.\n"); 34 | return T(); 35 | } 36 | 37 | void **pVTable = *static_cast(pClass); 38 | if (!pVTable) 39 | { 40 | printf("Tried getting virtual function from a null vtable.\n"); 41 | return T(); 42 | } 43 | 44 | return reinterpret_cast(pVTable[uIndex]); 45 | } 46 | 47 | template 48 | inline T CallVirtual(uint32 uIndex, void *pClass, Args... args) 49 | { 50 | #ifdef _WIN32 51 | auto pFunc = GetVMethod(uIndex, pClass); 52 | #else 53 | auto pFunc = GetVMethod(uIndex, pClass); 54 | #endif 55 | if (!pFunc) 56 | { 57 | printf("Tried calling a null virtual function.\n"); 58 | return T(); 59 | } 60 | 61 | return pFunc(pClass, args...); 62 | } 63 | } -------------------------------------------------------------------------------- /vendor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # HL2SDK/METAMOD SETUP 2 | # --- 3 | 4 | function(BUILD_HL2SDK GAME GAME_PATH) 5 | SET(HL2SDK_INCLUDES 6 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH} 7 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/common 8 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/game/shared 9 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/game/server 10 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/public 11 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/public/engine 12 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/public/mathlib 13 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/public/tier0 14 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/public/tier1 15 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/public/entity2 16 | ${PROJECT_SOURCE_DIR}/vendor/${GAME_PATH}/public/game/server 17 | ) 18 | 19 | add_library(HL2SDK-${GAME} STATIC 20 | ${GAME_PATH}/tier1/convar.cpp 21 | ${GAME_PATH}/tier1/generichash.cpp 22 | ${GAME_PATH}/tier1/keyvalues3.cpp 23 | ) 24 | 25 | target_include_directories(HL2SDK-${GAME} PUBLIC ${HL2SDK_INCLUDES}) 26 | 27 | if(WIN32) 28 | target_link_libraries(HL2SDK-${GAME} PUBLIC 29 | ${CMAKE_CURRENT_SOURCE_DIR}/${GAME_PATH}/lib/public/win64/tier1.lib 30 | ${CMAKE_CURRENT_SOURCE_DIR}/${GAME_PATH}/lib/public/win64/interfaces.lib 31 | ${CMAKE_CURRENT_SOURCE_DIR}/${GAME_PATH}/lib/public/win64/mathlib.lib 32 | ) 33 | elseif(UNIX) 34 | target_link_libraries(HL2SDK-${GAME} PUBLIC 35 | ${CMAKE_CURRENT_SOURCE_DIR}/${GAME_PATH}/lib/linux64/tier1.a 36 | ${CMAKE_CURRENT_SOURCE_DIR}/${GAME_PATH}/lib/linux64/interfaces.a 37 | ${CMAKE_CURRENT_SOURCE_DIR}/${GAME_PATH}/lib/linux64/mathlib.a 38 | ) 39 | endif() 40 | message(STATUS "Setting up HL2SDK-${GAME}") # What does this print? 41 | endfunction() 42 | 43 | build_hl2sdk(CS2 hl2sdk-cs2) 44 | build_hl2sdk(DOTA hl2sdk-deadlock) 45 | build_hl2sdk(DEADLOCK hl2sdk-deadlock) 46 | 47 | # EXTERNAL LIBRARIES 48 | # --- 49 | 50 | set(SPDLOG_FMT_EXTERNAL ON) 51 | 52 | add_subdirectory(fmt) 53 | add_subdirectory(spdlog) 54 | 55 | set_target_properties( 56 | HL2SDK-CS2 57 | HL2SDK-DOTA 58 | HL2SDK-DEADLOCK 59 | PROPERTIES FOLDER SDK 60 | ) 61 | 62 | set_target_properties( 63 | fmt 64 | spdlog 65 | PROPERTIES FOLDER Libraries 66 | ) --------------------------------------------------------------------------------