├── .gitignore ├── LICENSE ├── README.md ├── main.py ├── material_compression ├── VTFLibWrapper │ ├── VTFLib.py │ ├── VTFLibConstants.py │ ├── VTFLibEnums.py │ ├── VTFLibStructures.py │ └── bin │ │ └── VTFLib.x64.dll ├── resize_and_compress.py ├── resize_and_compress_singlefile.py ├── resize_png.py └── resizelib.py ├── requirements.txt ├── run.bat ├── sound_compression └── wav_to_mp3.py ├── unused_files ├── content.py └── modelformats.py └── utils └── formatting.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | venv -------------------------------------------------------------------------------- /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 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gm_addon_optimization_tricks 2 | Tips and Tricks to make your addon slim and fast 3 | 4 | # CLI Tool 5 | To install the required python packages run 6 | ```bash 7 | pip install -r .\requirements.txt 8 | ``` 9 | 10 | After that the CLI can be ran with: 11 | ```bash 12 | python main.py 13 | ``` 14 | ![image](https://github.com/user-attachments/assets/dd785285-0023-433f-be9b-8d816c030d84) 15 | 16 | 17 | ## All documentation is stored in the Wiki 18 | Please visit the Wiki to read more: https://github.com/CFC-Servers/gm_addon_optimization_tricks/wiki 19 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import questionary 2 | import os 3 | 4 | from utils.formatting import format_size 5 | from unused_files.modelformats import unused_model_formats 6 | from unused_files.content import unused_content 7 | from material_compression.resize_and_compress import resize_and_compress 8 | from material_compression.resize_png import clamp_pngs 9 | from sound_compression.wav_to_mp3 import wav_to_mp3 10 | 11 | FOLDER = "" 12 | 13 | def main(): 14 | global FOLDER 15 | 16 | if not FOLDER: 17 | FOLDER = questionary.text("Absolute path to folder:").ask() 18 | if not FOLDER: 19 | return 20 | 21 | action = questionary.select( "What do you want to do?", 22 | choices=["Unused model formats", "Find unused content (WIP)", "Compress VTF files", "Use DXT for VTFs", "Clamp PNG files", ".wav to .mp3 (lowers filesize) (skips looped/cued files)","Exit"], 23 | ).ask() 24 | 25 | if not action: 26 | return 27 | 28 | if action == "Exit": 29 | return 30 | 31 | if not os.path.exists(FOLDER): 32 | print("Folder does not exist") 33 | main() 34 | return 35 | 36 | if action == "Unused model formats": 37 | remove = questionary.confirm("Do you want to remove the models?").ask() 38 | size, count = unused_model_formats(FOLDER, remove) 39 | 40 | formatted_size = format_size(size) 41 | if remove: 42 | print(f"Removed {count} unused model formats, saving {formatted_size}") 43 | else: 44 | print(f"Found {count} unused model formats, taking up {formatted_size}") 45 | 46 | if action == "Find unused content (WIP)": 47 | remove = questionary.confirm("Do you want to remove the found unused files? This isn't 100% and can remove used files!").ask() 48 | size, count = unused_content(FOLDER, remove) 49 | if remove: 50 | print(f"Removed {count} unused files, saving {format_size(size)}") 51 | else: 52 | print(f"Found {count} unused files, taking up {format_size(size)}") 53 | 54 | if action == "Compress VTF files": 55 | size = questionary.text("Clamp size:", validate=lambda text: True if text.isdigit() else "Please enter a valid number").ask() 56 | resize_and_compress(FOLDER, int(size)) 57 | 58 | if action == "Use DXT for VTFs": 59 | resize_and_compress(FOLDER, 1000000) 60 | 61 | if action == "Clamp PNG files": 62 | size = questionary.text("Clamp size:", validate=lambda text: True if text.isdigit() else "Please enter a valid number").ask() 63 | clamp_pngs(FOLDER, int(size)) 64 | 65 | if action == ".wav to .mp3 (lowers filesize) (skips looped/cued files)": 66 | wav_to_mp3(FOLDER) 67 | 68 | main() 69 | 70 | if __name__ == "__main__": 71 | main() 72 | -------------------------------------------------------------------------------- /material_compression/VTFLibWrapper/VTFLib.py: -------------------------------------------------------------------------------- 1 | import os 2 | import platform 3 | import sys 4 | from ctypes import * 5 | 6 | try: 7 | from VTFWrapper.VTFLibEnums import ImageFlag 8 | import VTFLibEnums 9 | import VTFLibConstants 10 | import VTFLibStructures 11 | except Exception: 12 | from .VTFLibEnums import ImageFlag 13 | from . import (VTFLibEnums, 14 | VTFLibStructures, 15 | VTFLibConstants) 16 | 17 | platform_name = platform.system() 18 | full_path = os.path.join(os.path.dirname(__file__), 'bin') 19 | 20 | if platform_name == "Windows": 21 | is64bit = platform.architecture(executable=sys.executable, 22 | bits='', 23 | linkage='')[0] == "64bit" 24 | vtf_lib_name = "VTFLib.x64.dll" if is64bit else "VTFLib.x86.dll" 25 | vtf_lib_name = os.path.join(full_path, vtf_lib_name) 26 | elif platform_name == "Linux": 27 | # On linux we assume this lib is in a predictable location 28 | # VTFLib Linux: https://github.com/panzi/VTFLib 29 | # requires: libtxc_dxtn 30 | dxtn_lib_name = os.path.join(full_path, "libtxc_dxtn.so") 31 | vtf_lib_name = os.path.join(full_path, "libVTFLib13.so") 32 | else: 33 | raise NotImplementedError() 34 | 35 | # TODO: move to util? 36 | 37 | 38 | def pointer_to_array(poiter, size, type=c_ubyte): 39 | return cast(poiter, POINTER(type * size)) 40 | 41 | 42 | class VTFLib: 43 | if platform.system() == "Windows": 44 | vtflib_cdll = WinDLL(os.path.join(full_path, vtf_lib_name)) 45 | elif platform.system() == "Linux": 46 | dxtn_cdll = cdll.LoadLibrary(dxtn_lib_name) 47 | vtflib_cdll = cdll.LoadLibrary(vtf_lib_name) 48 | 49 | def __init__(self): 50 | self.initialize() 51 | self.image_buffer = c_int() 52 | self.create_image(byref(self.image_buffer)) 53 | self.bind_image(self.image_buffer) 54 | 55 | GetVersion = vtflib_cdll.vlGetVersion 56 | GetVersion.argtypes = [] 57 | GetVersion.restype = c_uint32 58 | 59 | def get_version(self): 60 | return self.GetVersion() 61 | 62 | Initialize = vtflib_cdll.vlInitialize 63 | Initialize.argtypes = [] 64 | Initialize.restype = c_bool 65 | 66 | def initialize(self): 67 | return self.Initialize() 68 | 69 | Shutdown = vtflib_cdll.vlShutdown 70 | Shutdown.argtypes = [] 71 | Shutdown.restype = c_bool 72 | 73 | def shutdown(self): 74 | return self.Shutdown() 75 | 76 | GetVersionString = vtflib_cdll.vlGetVersionString 77 | GetVersionString.argtypes = [] 78 | GetVersionString.restype = c_char_p 79 | 80 | def get_str_version(self): 81 | return self.GetVersionString().decode('utf') 82 | 83 | GetLastError = vtflib_cdll.vlGetLastError 84 | GetLastError.argtypes = [] 85 | GetLastError.restype = c_char_p 86 | 87 | def get_last_error(self): 88 | bytes().decode() 89 | error = self.GetLastError().decode('utf', "replace") 90 | return error if error else "No errors" 91 | 92 | GetBoolean = vtflib_cdll.vlGetBoolean 93 | GetBoolean.argtypes = [VTFLibEnums.Option] 94 | GetBoolean.restype = c_bool 95 | 96 | def get_boolean(self, option): 97 | return self.GetBoolean(option) 98 | 99 | SetBoolean = vtflib_cdll.vlSetBoolean 100 | SetBoolean.argtypes = [VTFLibEnums.Option, c_bool] 101 | SetBoolean.restype = None 102 | 103 | def set_boolean(self, option, value): 104 | self.SetBoolean(option, value) 105 | 106 | GetInteger = vtflib_cdll.vlGetInteger 107 | GetInteger.argtypes = [c_int32] 108 | GetInteger.restype = c_int32 109 | 110 | def get_integer(self, option): 111 | return self.GetInteger(option) 112 | 113 | SetInteger = vtflib_cdll.vlSetInteger 114 | SetInteger.argtypes = [VTFLibEnums.Option, c_int32] 115 | SetInteger.restype = None 116 | 117 | def set_integer(self, option, value): 118 | self.SetInteger(option, value) 119 | 120 | GetFloat = vtflib_cdll.vlGetFloat 121 | GetFloat.argtypes = [c_int32] 122 | GetFloat.restype = c_float 123 | 124 | def get_float(self, option): 125 | return self.GetFloat(option) 126 | 127 | SetFloat = vtflib_cdll.vlSetFloat 128 | SetFloat.argtypes = [VTFLibEnums.Option, c_float] 129 | SetFloat.restype = None 130 | 131 | def set_float(self, option, value): 132 | self.SetFloat(option, value) 133 | 134 | ImageIsBound = vtflib_cdll.vlImageIsBound 135 | ImageIsBound.argtypes = [] 136 | ImageIsBound.restype = c_bool 137 | 138 | def image_is_bound(self): 139 | return self.ImageIsBound() 140 | 141 | BindImage = vtflib_cdll.vlBindImage 142 | BindImage.argtypes = [c_int32] 143 | BindImage.restype = c_bool 144 | 145 | def bind_image(self, image): 146 | return self.BindImage(image) 147 | 148 | CreateImage = vtflib_cdll.vlCreateImage 149 | CreateImage.argtypes = [POINTER(c_int)] 150 | CreateImage.restype = c_bool 151 | 152 | def create_image(self, image): 153 | return self.CreateImage(image) 154 | 155 | DeleteImage = vtflib_cdll.vlDeleteImage 156 | DeleteImage.argtypes = [POINTER(c_int32)] 157 | DeleteImage.restype = None 158 | 159 | def delete_image(self, image): 160 | self.DeleteImage(image) 161 | 162 | ImageCreateDefaultCreateStructure = vtflib_cdll.vlImageCreateDefaultCreateStructure 163 | ImageCreateDefaultCreateStructure.argtypes = [ 164 | POINTER(VTFLibStructures.CreateOptions)] 165 | ImageCreateDefaultCreateStructure.restype = None 166 | 167 | def create_default_params_structure(self): 168 | create_oprions = VTFLibStructures.CreateOptions() 169 | self.ImageCreateDefaultCreateStructure(byref(create_oprions)) 170 | return create_oprions 171 | 172 | ImageCreate = vtflib_cdll.vlImageCreate 173 | ImageCreate.argtypes = [c_int32, c_int32, c_int32, c_int32, c_int32, VTFLibEnums.ImageFormat, c_bool, c_bool, 174 | c_bool] 175 | ImageCreate.restype = c_byte 176 | 177 | def image_create(self, width, height, frames, faces, slices, 178 | image_format, thumbnail, mipmaps, nulldata): 179 | return self.ImageCreate(width, height, frames, faces, 180 | slices, image_format, thumbnail, mipmaps, nulldata) 181 | 182 | ImageCreateSingle = vtflib_cdll.vlImageCreateSingle 183 | ImageCreateSingle.argtypes = [ 184 | c_int32, c_int32, POINTER(c_byte), POINTER( 185 | VTFLibStructures.CreateOptions)] 186 | ImageCreateSingle.restype = c_bool 187 | 188 | def image_create_single(self, width, height, image_data, options): 189 | image_data = cast(image_data, POINTER(c_byte)) 190 | return self.ImageCreateSingle(width, height, image_data, options) 191 | 192 | ImageDestroy = vtflib_cdll.vlImageDestroy 193 | ImageDestroy.argtypes = [] 194 | ImageDestroy.restype = None 195 | 196 | def image_destroy(self): 197 | self.ImageDestroy() 198 | 199 | ImageIsLoaded = vtflib_cdll.vlImageIsLoaded 200 | ImageIsLoaded.argtypes = [] 201 | ImageIsLoaded.restype = c_bool 202 | 203 | def image_is_loaded(self): 204 | return self.ImageIsLoaded() 205 | 206 | ImageLoad = vtflib_cdll.vlImageLoad 207 | ImageLoad.argtypes = [c_char_p, c_bool] 208 | ImageLoad.restype = c_bool 209 | 210 | def image_load(self, filename, header_only=False): 211 | return self.ImageLoad(create_string_buffer( 212 | filename.encode('ascii')), header_only) 213 | 214 | ImageSave = vtflib_cdll.vlImageSave 215 | ImageSave.argtypes = [c_char_p] 216 | ImageSave.restype = c_bool 217 | 218 | def image_save(self, filename): 219 | return self.ImageSave(create_string_buffer(filename.encode('ascii'))) 220 | 221 | ImageGetSize = vtflib_cdll.vlImageGetSize 222 | ImageGetSize.argtypes = [] 223 | ImageGetSize.restype = c_int32 224 | 225 | def get_size(self): 226 | return self.ImageGetSize() 227 | 228 | ImageGetWidth = vtflib_cdll.vlImageGetWidth 229 | ImageGetWidth.argtypes = [] 230 | ImageGetWidth.restype = c_int32 231 | 232 | def width(self): 233 | return self.ImageGetWidth() 234 | 235 | ImageGetHeight = vtflib_cdll.vlImageGetHeight 236 | ImageGetHeight.argtypes = [] 237 | ImageGetHeight.restype = c_int32 238 | 239 | def height(self): 240 | return self.ImageGetHeight() 241 | 242 | ImageGetDepth = vtflib_cdll.vlImageGetDepth 243 | ImageGetDepth.argtypes = [] 244 | ImageGetDepth.restype = c_int32 245 | 246 | def depth(self): 247 | return self.ImageGetDepth() 248 | 249 | ImageGetFrameCount = vtflib_cdll.vlImageGetFrameCount 250 | ImageGetFrameCount.argtypes = [] 251 | ImageGetFrameCount.restype = c_int32 252 | 253 | def frame_count(self): 254 | return self.ImageGetFrameCount() 255 | 256 | ImageGetFaceCount = vtflib_cdll.vlImageGetFaceCount 257 | ImageGetFaceCount.argtypes = [] 258 | ImageGetFaceCount.restype = c_int32 259 | 260 | def face_count(self): 261 | return self.ImageGetFaceCount() 262 | 263 | ImageGetMipmapCount = vtflib_cdll.vlImageGetMipmapCount 264 | ImageGetMipmapCount.argtypes = [] 265 | ImageGetMipmapCount.restype = c_int32 266 | 267 | def mipmap_count(self): 268 | return self.ImageGetMipmapCount() 269 | 270 | ImageGetStartFrame = vtflib_cdll.vlImageGetStartFrame 271 | ImageGetStartFrame.argtypes = [] 272 | ImageGetStartFrame.restype = c_int32 273 | 274 | def get_start_frame(self): 275 | return self.ImageGetStartFrame() 276 | 277 | ImageSetStartFrame = vtflib_cdll.vlImageSetStartFrame 278 | ImageSetStartFrame.argtypes = [c_int32] 279 | ImageSetStartFrame.restype = None 280 | 281 | def set_start_frame(self, start_frame): 282 | return self.ImageSetStartFrame(start_frame) 283 | 284 | ImageGetFlags = vtflib_cdll.vlImageGetFlags 285 | ImageGetFlags.argtypes = [] 286 | ImageGetFlags.restype = c_int32 287 | 288 | def get_image_flags(self): 289 | return ImageFlag(self.ImageGetFlags()) 290 | 291 | ImageSetFlags = vtflib_cdll.vlImageSetFlags 292 | ImageSetFlags.argtypes = [c_float] 293 | ImageSetFlags.restype = None 294 | 295 | def set_image_flags(self, flags): 296 | return self.ImageSetFlags(flags) 297 | 298 | ImageGetFormat = vtflib_cdll.vlImageGetFormat 299 | ImageGetFormat.argtypes = [] 300 | ImageGetFormat.restype = VTFLibEnums.ImageFormat 301 | 302 | def image_format(self): 303 | return self.ImageGetFormat() 304 | 305 | ImageGetData = vtflib_cdll.vlImageGetData 306 | ImageGetData.argtypes = [c_uint32, c_uint32, c_uint32, c_uint32] 307 | ImageGetData.restype = POINTER(c_byte) 308 | 309 | def get_image_data(self, frame=0, face=0, slice=0, mipmap_level=0): 310 | size = self.compute_image_size(self.width(), self.height(), self.depth(), self.mipmap_count(), 311 | self.image_format().value) 312 | buff = self.ImageGetData(frame, face, slice, mipmap_level) 313 | return pointer_to_array(buff, size) 314 | 315 | def get_rgba8888(self): 316 | size = self.compute_image_size(self.width(), self.height(), self.depth(), self.mipmap_count(), 317 | VTFLibEnums.ImageFormat.ImageFormatRGBA8888) 318 | if self.image_format() == VTFLibEnums.ImageFormat.ImageFormatRGBA8888: 319 | return pointer_to_array(self.get_image_data(0, 0, 0, 0), size) 320 | 321 | return pointer_to_array(self.convert_to_rgba8888(), size) 322 | 323 | ImageSetData = vtflib_cdll.vlImageSetData 324 | ImageSetData.argtypes = [ 325 | c_uint32, 326 | c_uint32, 327 | c_uint32, 328 | c_uint32, 329 | POINTER(c_byte)] 330 | ImageSetData.restype = None 331 | 332 | def set_image_data(self, frame, face, slice, mipmap_level, data): 333 | return self.ImageSetData(frame, face, slice, mipmap_level, data) 334 | 335 | ImageGetHasThumbnail = vtflib_cdll.vlImageGetHasThumbnail 336 | ImageGetHasThumbnail.argtypes = [] 337 | ImageGetHasThumbnail.restype = c_bool 338 | 339 | def has_thumbnail(self): 340 | return self.ImageGetHasThumbnail() 341 | 342 | ImageGetThumbnailWidth = vtflib_cdll.vlImageGetThumbnailWidth 343 | ImageGetThumbnailWidth.argtypes = [] 344 | ImageGetThumbnailWidth.restype = c_int32 345 | 346 | def thumbnail_width(self): 347 | return self.ImageGetThumbnailWidth() 348 | 349 | ImageGetThumbnailHeight = vtflib_cdll.vlImageGetThumbnailHeight 350 | ImageGetThumbnailHeight.argtypes = [] 351 | ImageGetThumbnailHeight.restype = c_int32 352 | 353 | def thumbnail_height(self): 354 | return self.ImageGetThumbnailHeight() 355 | 356 | ImageGetThumbnailFormat = vtflib_cdll.vlImageGetThumbnailFormat 357 | ImageGetThumbnailFormat.argtypes = [] 358 | ImageGetThumbnailFormat.restype = VTFLibEnums.ImageFormat 359 | 360 | def thumbnail_format(self): 361 | return self.ImageGetThumbnailFormat() 362 | 363 | ImageGetThumbnailData = vtflib_cdll.vlImageGetThumbnailData 364 | ImageGetThumbnailData.argtypes = [] 365 | ImageGetThumbnailData.restype = POINTER(c_byte) 366 | 367 | def get_thumbnail_format_data(self): 368 | return self.ImageGetThumbnailData() 369 | 370 | ImageSetThumbnailData = vtflib_cdll.vlImageSetThumbnailData 371 | ImageSetThumbnailData.argtypes = [POINTER(c_byte)] 372 | ImageSetThumbnailData.restype = None 373 | 374 | def set_thumbnail_format_data(self, data): 375 | return self.ImageSetThumbnailData(data) 376 | 377 | ImageGenerateMipmaps = vtflib_cdll.vlImageGenerateMipmaps 378 | ImageGenerateMipmaps.argtypes = [c_uint32, c_uint32, c_uint32, c_uint32] 379 | ImageGenerateMipmaps.restype = c_bool 380 | 381 | def generate_mipmaps(self, face, frame, mipmap_filter, sharpness_filter): 382 | return self.ImageGenerateMipmaps( 383 | face, frame, mipmap_filter, sharpness_filter) 384 | 385 | ImageGenerateAllMipmaps = vtflib_cdll.vlImageGenerateAllMipmaps 386 | ImageGenerateAllMipmaps.argtypes = [c_uint32, c_uint32] 387 | ImageGenerateAllMipmaps.restype = c_bool 388 | 389 | def generate_all_mipmaps(self, mipmap_filter, sharpness_filter): 390 | return self.ImageGenerateAllMipmaps(mipmap_filter, sharpness_filter) 391 | 392 | ImageGenerateThumbnail = vtflib_cdll.vlImageGenerateThumbnail 393 | ImageGenerateThumbnail.argtypes = [] 394 | ImageGenerateThumbnail.restype = c_bool 395 | 396 | def generate_thumbnail(self): 397 | return self.ImageGenerateThumbnail() 398 | 399 | ImageGenerateNormalMap = vtflib_cdll.vlImageGenerateNormalMap 400 | ImageGenerateNormalMap.argtypes = [c_uint32, c_uint32, c_uint32, c_uint32] 401 | ImageGenerateNormalMap.restype = c_bool 402 | 403 | def generate_normal_maps(self, frame, kernel_filter, 404 | height_conversion_method, normal_alpha_result): 405 | return self.ImageGenerateNormalMap( 406 | frame, kernel_filter, height_conversion_method, normal_alpha_result) 407 | 408 | ImageGenerateAllNormalMaps = vtflib_cdll.vlImageGenerateAllNormalMaps 409 | ImageGenerateAllNormalMaps.argtypes = [ 410 | c_uint32, c_uint32, c_uint32, c_uint32] 411 | ImageGenerateAllNormalMaps.restype = c_bool 412 | 413 | def generate_all_normal_maps( 414 | self, kernel_filter, height_conversion_method, normal_alpha_result): 415 | return self.ImageGenerateAllNormalMaps( 416 | kernel_filter, height_conversion_method, normal_alpha_result) 417 | 418 | ImageGenerateSphereMap = vtflib_cdll.vlImageGenerateSphereMap 419 | ImageGenerateSphereMap.argtypes = [] 420 | ImageGenerateSphereMap.restype = c_bool 421 | 422 | def generate_sphere_map(self): 423 | return self.ImageGenerateSphereMap() 424 | 425 | ImageComputeReflectivity = vtflib_cdll.vlImageComputeReflectivity 426 | ImageComputeReflectivity.argtypes = [] 427 | ImageComputeReflectivity.restype = c_bool 428 | 429 | def compute_reflectivity(self): 430 | return self.ImageComputeReflectivity() 431 | 432 | ImageComputeImageSize = vtflib_cdll.vlImageComputeImageSize 433 | ImageComputeImageSize.argtypes = [ 434 | c_int32, c_uint32, c_int32, c_uint32, c_int32] 435 | ImageComputeImageSize.restype = c_uint32 436 | 437 | def compute_image_size(self, width, height, depth, mipmaps, image_format): 438 | return self.ImageComputeImageSize( 439 | width, height, depth, mipmaps, image_format) 440 | 441 | ImageFlipImage = vtflib_cdll.vlImageFlipImage 442 | ImageFlipImage.argtypes = [POINTER(c_byte), c_uint32, c_int32] 443 | ImageFlipImage.restype = None 444 | 445 | def flip_image(self, image_data, width=None, 446 | height=None, depth=1, mipmaps=-1): 447 | width = width or self.width() 448 | height = height or self.height() 449 | depth = depth or self.depth() 450 | mipmaps = mipmaps or self.mipmap_count() 451 | if self.image_format() != VTFLibEnums.ImageFormat.ImageFormatRGBA8888: 452 | print('To RGBA8888') 453 | image_data = self.convert_to_rgba8888() 454 | image_data = cast(image_data, POINTER(c_byte)) 455 | self.ImageFlipImage(image_data, width, height) 456 | size = self.compute_image_size(width, height, depth, mipmaps, 457 | VTFLibEnums.ImageFormat.ImageFormatRGBA8888) 458 | 459 | return pointer_to_array(image_data, size) 460 | 461 | def flip_image_external(self, image_data, width=None, height=None): 462 | width = width or self.width() 463 | height = height or self.height() 464 | image_data_p = cast(image_data, POINTER(c_byte)) 465 | self.ImageFlipImage(image_data_p, width, height) 466 | size = width * height * 4 467 | 468 | return pointer_to_array(image_data, size) 469 | 470 | ImageMirrorImage = vtflib_cdll.vlImageMirrorImage 471 | ImageMirrorImage.argtypes = [POINTER(c_byte), c_uint32, c_int32] 472 | ImageMirrorImage.restype = None 473 | 474 | def mirror_image(self, image_data): 475 | if self.image_format() != VTFLibEnums.ImageFormat.ImageFormatRGBA8888: 476 | image_data = self.convert_to_rgba8888() 477 | image_data = cast(image_data, POINTER(c_byte)) 478 | self.ImageMirrorImage(image_data, self.width(), self.height()) 479 | size = self.compute_image_size(self.width(), self.height(), self.depth(), self.mipmap_count(), 480 | VTFLibEnums.ImageFormat.ImageFormatRGBA8888) 481 | 482 | return pointer_to_array(image_data, size) 483 | 484 | ImageConvertToRGBA8888 = vtflib_cdll.vlImageConvertToRGBA8888 485 | ImageConvertToRGBA8888.argtypes = [ 486 | POINTER(c_byte), 487 | POINTER(c_byte), 488 | c_uint32, 489 | c_int32, 490 | c_uint32] 491 | ImageConvertToRGBA8888.restype = None 492 | 493 | def convert_to_rgba8888(self): 494 | new_size = self.compute_image_size(self.width(), self.height(), self.depth(), self.mipmap_count(), 495 | VTFLibEnums.ImageFormat.ImageFormatRGBA8888) 496 | new_buffer = cast(create_string_buffer(init=new_size), POINTER(c_byte)) 497 | if not self.ImageConvertToRGBA8888(self.ImageGetData(0, 0, 0, 0), new_buffer, self.width(), self.height(), 498 | self.image_format().value): 499 | return pointer_to_array(new_buffer, new_size) 500 | else: 501 | sys.stderr.write('CAN\'T CONVERT IMAGE\n') 502 | return 0 503 | 504 | ImageConvert = vtflib_cdll.vlImageConvert 505 | ImageConvert.argtypes = [ 506 | POINTER(c_byte), 507 | POINTER(c_byte), 508 | c_uint32, 509 | c_int32, 510 | c_uint32, 511 | c_int32] 512 | ImageConvert.restype = None 513 | 514 | def convert(self, format): 515 | print( 516 | "Converting from {} to {}".format( 517 | self.image_format().name, 518 | VTFLibEnums.ImageFormat(format).name)) 519 | new_size = self.compute_image_size( 520 | self.width(), 521 | self.height(), 522 | self.depth(), 523 | self.mipmap_count(), 524 | format) 525 | new_buffer = cast((c_byte * new_size)(), POINTER(c_byte)) 526 | if not self.ImageConvert(self.ImageGetData(0, 0, 0, 0), new_buffer, self.width(), self.height(), 527 | self.image_format().value, format): 528 | return pointer_to_array(new_buffer, new_size) 529 | else: 530 | sys.stderr.write('CAN\'T CONVERT IMAGE\n') 531 | return 0 532 | 533 | GetProc = vtflib_cdll.vlGetProc 534 | GetProc.argtypes = [VTFLibEnums.Proc] 535 | GetProc.restype = POINTER(c_int32) 536 | 537 | def get_proc(self, proc): 538 | try: 539 | return self.GetProc(proc).contents.value 540 | except BaseException: 541 | sys.stderr.write("ERROR IN GetProc\n") 542 | return -1 543 | 544 | SetProc = vtflib_cdll.vlSetProc 545 | SetProc.argtypes = [VTFLibEnums.Proc, POINTER(c_int32)] 546 | SetProc.restype = None 547 | 548 | def set_proc(self, proc, value): 549 | self.SetProc(proc, value) 550 | 551 | 552 | if __name__ == '__main__': 553 | a = VTFLib() 554 | print(a.create_default_params_structure()) 555 | # a.image_load( 556 | # r"G:\SteamLibrary\SteamApps\common\SourceFilmmaker\game\usermod\materials\models\skuddbutt\mavis\body_clothed.vtf", 557 | # False) 558 | print(a.image_format()) 559 | # print(a.get_image_flags()).get_flag(ImageFlag.ImageFlagBorder) 560 | # a.image_save("G:\\SteamLibrary\\SteamApps\\common\\SourceFilmmaker\\game\\usermod\\materials\\models\\Red_eye\\Endless\\Feline\\Body2.vtf") 561 | print(a.get_last_error()) 562 | -------------------------------------------------------------------------------- /material_compression/VTFLibWrapper/VTFLibConstants.py: -------------------------------------------------------------------------------- 1 | class Constants: 2 | uiMaximumResources = 32 3 | -------------------------------------------------------------------------------- /material_compression/VTFLibWrapper/VTFLibEnums.py: -------------------------------------------------------------------------------- 1 | from ctypes import c_uint32 2 | 3 | 4 | class EnumerationType(type(c_uint32)): 5 | def __new__(metacls, name, bases, dict): 6 | if not "_members_" in dict: 7 | _members_ = {} 8 | for key, value in dict.items(): 9 | if not key.startswith("_"): 10 | _members_[key] = value 11 | 12 | dict["_members_"] = _members_ 13 | else: 14 | _members_ = dict["_members_"] 15 | 16 | dict["_reverse_map_"] = {v: k for k, v in _members_.items()} 17 | cls = type(c_uint32).__new__(metacls, name, bases, dict) 18 | for key, value in cls._members_.items(): 19 | globals()[key] = value 20 | return cls 21 | 22 | def __repr__(self): 23 | return "" % self.__name__ 24 | 25 | 26 | class CEnumeration(c_uint32, metaclass=EnumerationType): 27 | _members_ = {} 28 | 29 | def __repr__(self): 30 | value = self.value 31 | return "<{} {}>".format(self.__class__.__name__, self.name) 32 | 33 | @property 34 | def name(self): 35 | return self._reverse_map_.get(self.value, '(unknown)') 36 | 37 | def __eq__(self, other): 38 | if isinstance(other, int): 39 | return self.value == other 40 | 41 | return isinstance(self, type(other)) and self.value == other.value 42 | 43 | @classmethod 44 | def from_param(self, value): 45 | 46 | # print('lel',value) 47 | self.value = value 48 | 49 | 50 | class CFlag(c_uint32, metaclass=EnumerationType): 51 | _members_ = {} 52 | 53 | def __repr__(self): 54 | value = self.value 55 | keys = [] 56 | for val, name in self._reverse_map_.items(): 57 | if value & val: 58 | keys.append(name) 59 | return "<{} {}>".format(self.__class__.__name__, " | ".join(keys)) 60 | 61 | def get_flag(self, flag): 62 | return bool(self.value & flag) 63 | 64 | @property 65 | def name(self): 66 | return self._reverse_map_.get(self.value, '(unknown)') 67 | 68 | def __eq__(self, other): 69 | if isinstance(other, int): 70 | return self.value == other 71 | 72 | return isinstance(self, type(other)) and self.value == other.value 73 | 74 | @classmethod 75 | def from_param(self, value): 76 | 77 | # print('lel',value) 78 | self.value = value 79 | 80 | 81 | class Option(CEnumeration): 82 | OptionDXTQuality = 0 83 | 84 | OptionLuminanceWeightR = 1 85 | OptionLuminanceWeightG = 2 86 | OptionLuminanceWeightB = 3 87 | 88 | OptionBlueScreenMaskR = 4 89 | OptionBlueScreenMaskG = 5 90 | OptionBlueScreenMaskB = 6 91 | 92 | OptionBlueScreenClearR = 7 93 | OptionBlueScreenClearG = 8 94 | OptionBlueScreenClearB = 9 95 | 96 | OptionFP16HDRKey = 10 97 | OptionFP16HDRShift = 11 98 | OptionFP16HDRGamma = 12 99 | 100 | OptionUnsharpenRadius = 13 101 | OptionUnsharpenAmount = 14 102 | OptionUnsharpenThreshold = 15 103 | 104 | OptionXSharpenStrength = 16 105 | OptionXSharpenThreshold = 17 106 | 107 | OptionVMTParseMode = 18 108 | 109 | 110 | class ImageFormat(CEnumeration): 111 | ImageFormatRGBA8888 = 0 112 | ImageFormatABGR8888 = 1 113 | ImageFormatRGB888 = 2 114 | ImageFormatBGR888 = 3 115 | ImageFormatRGB565 = 4 116 | ImageFormatI8 = 5 117 | ImageFormatIA88 = 6 118 | ImageFormatP8 = 7 119 | ImageFormatA8 = 8 120 | ImageFormatRGB888BlueScreen = 9 121 | ImageFormatBGR888BlueScreen = 10 122 | ImageFormatARGB8888 = 11 123 | ImageFormatBGRA8888 = 12 124 | ImageFormatDXT1 = 13 125 | ImageFormatDXT3 = 14 126 | ImageFormatDXT5 = 15 127 | ImageFormatBGRX8888 = 16 128 | ImageFormatBGR565 = 17 129 | ImageFormatBGRX5551 = 18 130 | ImageFormatBGRA4444 = 19 131 | ImageFormatDXT1OneBitAlpha = 20 132 | ImageFormatBGRA5551 = 21 133 | ImageFormatUV88 = 22 134 | ImageFormatUVWQ8888 = 23 135 | ImageFormatRGBA16161616F = 24 136 | ImageFormatRGBA16161616 = 25 137 | ImageFormatUVLX8888 = 26 138 | ImageFormatI32F = 27 139 | ImageFormatRGB323232F = 28 140 | ImageFormatRGBA32323232F = 29 141 | ImageFormatCount = 30 142 | ImageFormatNone = -1 143 | 144 | 145 | class ImageFlag(CFlag): 146 | ImageFlagNone = 0x00000000 147 | ImageFlagPointSample = 0x00000001 148 | ImageFlagTrilinear = 0x00000002 149 | ImageFlagClampS = 0x00000004 150 | ImageFlagClampT = 0x00000008 151 | ImageFlagAnisotropic = 0x00000010 152 | ImageFlagHintDXT5 = 0x00000020 153 | ImageFlagSRGB = 0x00000040 154 | ImageFlagNormal = 0x00000080 155 | ImageFlagNoMIP = 0x00000100 156 | ImageFlagNoLOD = 0x00000200 157 | ImageFlagMinMIP = 0x00000400 158 | ImageFlagProcedural = 0x00000800 159 | ImageFlagOneBitAlpha = 0x00001000 160 | ImageFlagEightBitAlpha = 0x00002000 161 | ImageFlagEnviromentMap = 0x00004000 162 | ImageFlagRenderTarget = 0x00008000 163 | ImageFlagDepthRenderTarget = 0x00010000 164 | ImageFlagNoDebugOverride = 0x00020000 165 | ImageFlagSingleCopy = 0x00040000 166 | ImageFlagUnused0 = 0x00080000 167 | ImageFlagUnused1 = 0x00100000 168 | ImageFlagUnused2 = 0x00200000 169 | ImageFlagUnused3 = 0x00400000 170 | ImageFlagNoDepthBuffer = 0x00800000 171 | ImageFlagUnused4 = 0x01000000 172 | ImageFlagClampU = 0x02000000 173 | ImageFlagVertexTexture = 0x04000000 174 | ImageFlagSSBump = 0x08000000 175 | ImageFlagUnused5 = 0x10000000 176 | ImageFlagBorder = 0x20000000 177 | ImageFlagCount = 30 178 | 179 | 180 | class CubemapFace(CEnumeration): 181 | CubemapFaceRight = 0 182 | CubemapFaceLeft = 1 183 | CubemapFaceBack = 2 184 | CubemapFaceFront = 3 185 | CubemapFaceUp = 4 186 | CubemapFaceDown = 5 187 | CubemapFaceSphereMap = 6 188 | CubemapFaceCount = 7 189 | 190 | 191 | class MipmapFilter(CEnumeration): 192 | MipmapFilterPoint = 0 193 | MipmapFilterBox = 1 194 | MipmapFilterTriangle = 2 195 | MipmapFilterQuadratic = 3 196 | MipmapFilterCubic = 4 197 | MipmapFilterCatrom = 5 198 | MipmapFilterMitchell = 6 199 | MipmapFilterGaussian = 7 200 | MipmapFilterSinC = 8 201 | MipmapFilterBessel = 9 202 | MipmapFilterHanning = 10 203 | MipmapFilterHamming = 11 204 | MipmapFilterBlackman = 12 205 | MipmapFilterKaiser = 13 206 | MipmapFilterCount = 14 207 | 208 | 209 | class SharpenFilter(CEnumeration): 210 | SharpenFilterNone = 0 211 | SharpenFilterNegative = 1 212 | SharpenFilterLighter = 2 213 | SharpenFilterDarker = 3 214 | SharpenFilterContrastMore = 4 215 | SharpenFilterContrastLess = 5 216 | SharpenFilterSmoothen = 6 217 | SharpenFilterSharpenSoft = 7 218 | SharpenFilterSharpenMeium = 8 219 | SharpenFilterSharpenStrong = 9 220 | SharpenFilterFindEdges = 10 221 | SharpenFilterContour = 11 222 | SharpenFilterEdgeDetect = 12 223 | SharpenFilterEdgeDetectSoft = 13 224 | SharpenFilterEmboss = 14 225 | SharpenFilterMeanRemoval = 15 226 | SharpenFilterUnsharp = 16 227 | SharpenFilterXSharpen = 17 228 | SharpenFilterWarpSharp = 18 229 | SharpenFilterCount = 19 230 | 231 | 232 | class DXTQuality(CEnumeration): 233 | DXTQualityLow = 0 234 | DXTQualityMedium = 1 235 | DXTQualityHigh = 2 236 | DXTQualityHighest = 3 237 | DXTQualityCount = 4 238 | 239 | 240 | class KernelFilter(CEnumeration): 241 | KernelFilter4x = 0 242 | KernelFilter3x3 = 1 243 | KernelFilter5x5 = 2 244 | KernelFilter7x7 = 3 245 | KernelFilter9x9 = 4 246 | KernelFilterDuDv = 5 247 | KernelFilterCount = 6 248 | 249 | 250 | class HeightConversionMethod(CEnumeration): 251 | HeightConversionMethodAlpha = 0 252 | HeightConversionMethodAverageRGB = 1 253 | HeightConversionMethodBiasedRGB = 2 254 | HeightConversionMethodRed = 3 255 | HeightConversionMethodGreed = 4 256 | HeightConversionMethodBlue = 5 257 | HeightConversionMethodMaxRGB = 6 258 | HeightConversionMethodColorSspace = 7 259 | # HeightConversionMethodNormalize = auto() 260 | HeightConversionMethodCount = 8 261 | 262 | 263 | class NormalAlphaResult(CEnumeration): 264 | NormalAlphaResultNoChange = 0 265 | NormalAlphaResultHeight = 1 266 | NormalAlphaResultBlack = 2 267 | NormalAlphaResultWhite = 3 268 | NormalAlphaResultCount = 4 269 | 270 | 271 | class ResizeMethod(CEnumeration): 272 | ResizeMethodNearestPowerTwo = 0 273 | ResizeMethodBiggestPowerTwo = 1 274 | ResizeMethodSmallestPowerTwo = 2 275 | ResizeMethodSet = 3 276 | ResizeMethodCount = 4 277 | 278 | 279 | class ResourceFlag(CEnumeration): 280 | ResourceFlagNoDataChunk = 0x02 281 | ResourceFlagCount = 1 282 | 283 | 284 | class ResourceType(CEnumeration): 285 | ResourceTypeLowResolutionImage = 0x01 286 | ResourceTypeImage = 0x30 287 | ResourceTypeSheet = 0x10 288 | ResourceTypeCRC = ord('C') | ( 289 | ord('R') << 8) | ( 290 | ord('C') << 24) | ( 291 | ResourceFlag.ResourceFlagNoDataChunk << 32) 292 | ResourceTypeLODControl = ord('L') | (ord('O') << 8) | (ord('D') << 24) | ( 293 | ResourceFlag.ResourceFlagNoDataChunk << 32) 294 | ResourceTypeTextureSettingsEx = ord('T') | (ord('S') << 8) | (ord('O') << 24) | ( 295 | ResourceFlag.ResourceFlagNoDataChunk << 32) 296 | ResourceTypeKeyValueData = ord('K') | (ord('V') << 8) | (ord('D') << 24) 297 | 298 | 299 | class Proc(CEnumeration): 300 | ProcReadClose = 0 301 | ProcReadOpen = 1 302 | ProcReadRead = 2 303 | ProcReadSeek = 3 304 | ProcReadTell = 4 305 | ProcReadSize = 5 306 | ProcWriteClose = 6 307 | ProcWriteOpen = 7 308 | ProcWriteWrite = 8 309 | ProcWriteSeek = 9 310 | ProcWriteSize = 10 311 | ProcWriteTell = 11 312 | 313 | 314 | class SeekMode(CEnumeration): 315 | Begin = 0 316 | Current = 1 317 | End = 2 318 | 319 | 320 | if __name__ == '__main__': 321 | a = Proc(5) 322 | print(a) 323 | a.value = a.ProcWriteTell 324 | print(a) 325 | print(a.ProcWriteTell) 326 | -------------------------------------------------------------------------------- /material_compression/VTFLibWrapper/VTFLibStructures.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | try: 3 | from VTFLibEnums import * 4 | except BaseException: 5 | from .VTFLibEnums import * 6 | 7 | 8 | class ImageFormatInfo(Structure): 9 | def get_name(self): 10 | return self.name.value if self.name != 0 else "NONE" 11 | 12 | 13 | ImageFormatInfo._fields_ = [ 14 | ('name', c_char_p), 15 | ('BitsPerPixel', c_uint32), 16 | ('BytesPerPixel', c_uint32), 17 | ('RedBitsPerPixel', c_uint32), 18 | ('GreenBitsPerPixel', c_uint32), 19 | ('BlueBitsPerPixel', c_uint32), 20 | ('AlphaBitsPerPixel', c_uint32), 21 | ('IsCompressed', c_bool), 22 | ('IsSupported', c_bool), 23 | ] 24 | 25 | 26 | class CreateOptions(Structure): 27 | def __repr__(self): 28 | template = "CreateOptions (\n{}" 29 | mem_template = "\t{}: {}\n" 30 | mems = [] 31 | for name, tp in self._fields_: 32 | mems.append(mem_template.format(name, getattr(self, name))) 33 | return template.format(''.join(mems)) + ')' 34 | 35 | 36 | CreateOptions._pack_ = 1 37 | CreateOptions._fields_ = [ 38 | ('VersionMajor', c_uint32), 39 | ('VersionMinor', c_uint32), 40 | ('ImageFormat', ImageFormat), 41 | ('Flags', c_uint32), 42 | ('StartFrame', c_uint32), 43 | ('BumpScale', c_float), 44 | ('RefectivityX', c_float), 45 | ('RefectivityY', c_float), 46 | ('RefectivityZ', c_float), 47 | ('Mipmaps', c_byte), 48 | ('MipmapFilter', MipmapFilter), 49 | ('SharpenFilter', SharpenFilter), 50 | ('Thumbnail', c_byte), 51 | ('Reflectivity', c_byte), 52 | ('Resize', c_byte), 53 | ('ResizeMethod', ResizeMethod), 54 | ('ResizeFilter', MipmapFilter), 55 | ('ResizeSharpenFilter', SharpenFilter), 56 | ('ResizeWidth', c_uint), 57 | ('ResizeHeight', c_uint), 58 | ('ResizeClamp', c_byte), 59 | ('ResizeClampWidth', c_uint), 60 | ('ResizeClampHeight', c_uint), 61 | ('DoGammaCorrection', c_byte), 62 | ('GammaCorrection', c_float), 63 | ('NormalMap', c_bool), 64 | ('KernelFilter', KernelFilter), 65 | ('HeightConversionMethod', HeightConversionMethod), 66 | ('NormalAlphaResult', NormalAlphaResult), 67 | ('NormalMinimumZ', c_byte), 68 | ('NormalScale', c_float), 69 | ('NormalWrap', c_bool), 70 | ('NormalInvertX', c_bool), 71 | ('NormalInvertY', c_bool), 72 | ('NormalInvertZ', c_bool), 73 | ('SphereMap', c_bool), 74 | ] 75 | 76 | 77 | class LODControlResource(Structure): 78 | pass 79 | 80 | 81 | LODControlResource._fields_ = [ 82 | ('ResolutionClampU', c_byte), 83 | ('ResolutionClampV', c_byte), 84 | ('Padding0', c_byte), 85 | ('Padding1', c_byte), 86 | 87 | ] 88 | -------------------------------------------------------------------------------- /material_compression/VTFLibWrapper/bin/VTFLib.x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CFC-Servers/gm_addon_optimization_tricks/44ae4ed6ace194202584cffad77344131f4af36d/material_compression/VTFLibWrapper/bin/VTFLib.x64.dll -------------------------------------------------------------------------------- /material_compression/resize_and_compress.py: -------------------------------------------------------------------------------- 1 | import os 2 | import signal 3 | import time 4 | from material_compression.resizelib import resizeVTF 5 | 6 | def resize_and_compress(folder, size): 7 | old_size = 0 8 | new_size = 0 9 | replace_count = 0 10 | startime = time.time() 11 | 12 | 13 | def signal_handler(sig, frame): 14 | if os.path.exists("crashfile.txt"): 15 | os.remove("crashfile.txt") 16 | 17 | print("Time taken:", round(time.time() - startime, 2), "seconds") 18 | print("Cancelled by user.") 19 | exit() 20 | 21 | 22 | signal.signal(signal.SIGINT, signal_handler) 23 | 24 | if os.path.exists("crashfile.txt"): 25 | with open("crashfile.txt", "r") as f: 26 | print("Crash/exit detected! Last file processed:", f.read()) 27 | print("Try importing and exporting the VTF with VTFEdit to fix it.") 28 | 29 | os.remove("crashfile.txt") 30 | 31 | for path, subdirs, files in os.walk(folder): 32 | for name in files: 33 | if not name.endswith(".vtf"): 34 | continue 35 | 36 | with open("crashfile.txt", "w") as f: 37 | f.write(os.path.join(path, name)) 38 | 39 | old_size_temp = os.path.getsize(os.path.join(path, name)) 40 | converted = resizeVTF(os.path.join(path, name), size) 41 | if converted: 42 | replace_count += 1 43 | new_size += os.path.getsize(os.path.join(path, name)) 44 | old_size += old_size_temp 45 | else: 46 | new_size += old_size_temp 47 | old_size += old_size_temp 48 | 49 | if os.path.exists("crashfile.txt"): 50 | os.remove("crashfile.txt") 51 | 52 | print("Replaced", replace_count, "files.") 53 | if replace_count == 0: 54 | print("No files were replaced.") 55 | else: 56 | print("Clamped to", size, "resolution.") 57 | print("Reduced size by ", round((1 - new_size / old_size) * 100, 2), "%") 58 | print("Reduced size by ", round((old_size - new_size) / 1000000, 2), "mbs") 59 | print("Time taken:", round(time.time() - startime, 2), "seconds") 60 | -------------------------------------------------------------------------------- /material_compression/resize_and_compress_singlefile.py: -------------------------------------------------------------------------------- 1 | import os 2 | from resizelib import resizeVTF 3 | 4 | # Edit these variables 5 | PATH_TO_FILE = r"garrysmod\addons\addon_name\materials\material_name.vtf" 6 | CLAMP_SIZE = 512 7 | # End of variables 8 | 9 | old_size = 0 10 | new_size = 0 11 | replace_count = 0 12 | 13 | if not os.path.exists(PATH_TO_FILE): 14 | print("File does not exist:", PATH_TO_FILE) 15 | exit() 16 | 17 | name = os.path.basename(PATH_TO_FILE) 18 | 19 | filetype = name.split(".")[-1] 20 | if filetype == "vtf": 21 | old_size = os.path.getsize(PATH_TO_FILE) 22 | resizeVTF(PATH_TO_FILE, CLAMP_SIZE) 23 | new_size = os.path.getsize(PATH_TO_FILE) 24 | 25 | print("Clamped to", CLAMP_SIZE, "pixels.") 26 | if replace_count == 0: 27 | print("No files were replaced.") 28 | else: 29 | print("Reduced size by ", round((1 - new_size / old_size) * 100, 2), "%") 30 | print("Reduced size by ", round((old_size - new_size) / 1000000, 2), "mbs") 31 | -------------------------------------------------------------------------------- /material_compression/resize_png.py: -------------------------------------------------------------------------------- 1 | # Lowers png resolution to under the specified size, useful for animated textures that were exported as pngs. 2 | 3 | import os 4 | from PIL import Image 5 | 6 | def clamp_pngs(folder, max_size): 7 | total_size = 0 8 | total_resized = 0 9 | total_files = 0 10 | 11 | for path, subdirs, files in os.walk(folder): 12 | for name in files: 13 | filepath = os.path.join(path, name) 14 | filetype = name.split(".")[-1] 15 | if filetype == "png": 16 | total_files += 1 17 | total_size += os.path.getsize(filepath) 18 | image = Image.open(filepath) 19 | w, h = image.size 20 | if w > max_size or h > max_size: 21 | maxd = max(w, h) 22 | scale = max_size / maxd 23 | neww = int(w * scale) 24 | newh = int(h * scale) 25 | image = image.resize((neww, newh)) 26 | image.save(filepath, quality=95) 27 | total_resized += os.path.getsize(filepath) 28 | print(f"Resized {filepath} from {w}x{h} to {neww}x{newh}") 29 | 30 | total_saved_mb = round((total_size - total_resized) / 1000000, 2) 31 | print(f"Resized {total_files} files, {total_saved_mb} mb saved") 32 | -------------------------------------------------------------------------------- /material_compression/resizelib.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import material_compression.VTFLibWrapper.VTFLib as VTFLib 3 | import material_compression.VTFLibWrapper.VTFLibEnums as VTFLibEnums 4 | from ctypes import create_string_buffer 5 | 6 | from material_compression.VTFLibWrapper.VTFLibEnums import ImageFormat 7 | 8 | vtf_lib = VTFLib.VTFLib() 9 | 10 | 11 | def resizeVTFImage(path, max_size): 12 | w = vtf_lib.width() 13 | h = vtf_lib.height() 14 | neww = w 15 | newh = h 16 | format = vtf_lib.image_format() 17 | 18 | scale = 1 19 | if w > max_size or h > max_size: 20 | maxd = max(w, h) 21 | scale = max_size / maxd 22 | neww *= scale 23 | newh *= scale 24 | 25 | if scale != 1 or format != ImageFormat.ImageFormatDXT1: 26 | vtf_lib.image_load(path, False) 27 | def_options = vtf_lib.create_default_params_structure() 28 | image_data = vtf_lib.get_rgba8888() 29 | image_data = bytes(image_data.contents) 30 | 31 | image = Image.frombytes("RGBA", (w, h), image_data) 32 | r, g, b, a = image.split() 33 | 34 | method = ImageFormat.ImageFormatDXT5 35 | if a.getextrema()[1] == 255 and a.getextrema()[0] == 255: 36 | method = ImageFormat.ImageFormatDXT1 37 | 38 | if scale == 1 and format == method: 39 | return False 40 | 41 | if scale != 1: 42 | image = image.convert("RGB") 43 | image_scaled = image.resize((int(neww), int(newh))) 44 | image_a_scaled = a.resize((int(neww), int(newh))) 45 | r, g, b = image_scaled.split() 46 | colorImage = (r, g, b, image_a_scaled) 47 | image = Image.merge('RGBA', colorImage) 48 | 49 | new_image_data = image.tobytes() 50 | 51 | def_options.ImageFormat = method 52 | def_options.Flags |= VTFLibEnums.ImageFlag.ImageFlagEightBitAlpha 53 | def_options.Resize = 1 54 | 55 | vtf_lib.image_create_single(int(neww), int(newh), new_image_data, def_options) 56 | 57 | vtf_lib.image_save(path) 58 | 59 | print(scale != 1 and "Resized" or "Converted", path, "successfully:", w, "x", h, "->", int(neww), "x", int(newh)) 60 | return True 61 | return False 62 | 63 | 64 | def resizeVTF(path, max_size) -> bool: 65 | if not path.endswith(".vtf"): 66 | return False 67 | 68 | vtf_lib.image_load(path, True) 69 | 70 | if vtf_lib.frame_count() == 1: 71 | return resizeVTFImage(path, max_size) 72 | else: 73 | print("Skipping", path, "because it has multiple frames.") 74 | return False 75 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | questionary 2 | pydub 3 | pillow 4 | audioop-lts; python_version>='3.13' 5 | srctools 6 | wavinfo >= 3.1.0 7 | -------------------------------------------------------------------------------- /run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Create a virtual env in a folder called "venv" if it doesn't exist 4 | if not exist venv ( 5 | echo Creating virtual environment... 6 | py -m venv venv 7 | ) 8 | 9 | REM Activate the virtual env 10 | call venv\Scripts\activate.bat 11 | 12 | REM Install required packages for the env 13 | pip install -r requirements.txt 14 | 15 | REM Run script 16 | py main.py 17 | -------------------------------------------------------------------------------- /sound_compression/wav_to_mp3.py: -------------------------------------------------------------------------------- 1 | import pydub 2 | import os 3 | from wavinfo import WavInfoReader 4 | 5 | # Requires ffmpeg to be installed and added to PATH 6 | # https://github.com/jiaaro/pydub?tab=readme-ov-file#getting-ffmpeg-set-up 7 | 8 | def wav_to_mp3(folder): 9 | replaced_files = {} 10 | old_size = 0 11 | new_size = 0 12 | replace_count = 0 13 | 14 | for path, subdirs, files in os.walk(folder): 15 | for name in files: 16 | filepath = os.path.join(path, name) 17 | filetype = name.split(".")[-1] 18 | if filetype == "wav": 19 | wav_info = WavInfoReader(filepath) 20 | if wav_info.cues == None: 21 | continue 22 | 23 | if len(wav_info.cues.cues) > 0: 24 | print("File", filepath, "contains cues skipping.") 25 | continue 26 | 27 | if wav_info.smpl != None and len(wav_info.smpl.sample_loops) > 0: 28 | print("File", filepath, "contains loops skipping.") 29 | continue 30 | 31 | old_size += os.path.getsize(filepath) 32 | sound = pydub.AudioSegment.from_wav(filepath) 33 | 34 | new_filepath = filepath.replace(".wav", ".mp3") 35 | sound.export(new_filepath, format="mp3") 36 | new_size += os.path.getsize(new_filepath) 37 | 38 | file_name = os.path.basename(filepath) 39 | replace_count += 1 40 | replaced_files[file_name] = file_name.replace(".wav", ".mp3") 41 | os.remove(filepath) 42 | 43 | print("Converted", filepath, "to mp3 successfully.") 44 | 45 | for path, subdirs, files in os.walk(folder): 46 | for name in files: 47 | filepath = os.path.join(path, name) 48 | filetype = name.split(".")[-1] 49 | if filetype == "lua" or filetype == "txt" or filetype == "json": 50 | with open(filepath, "r", encoding="utf-8") as f: 51 | contents = f.read() 52 | 53 | replaced = False 54 | for old, new in replaced_files.items(): 55 | new_contents = contents.replace(old, new) 56 | if new_contents != contents: 57 | replaced = True 58 | contents = new_contents 59 | 60 | if not replaced: 61 | continue 62 | 63 | with open(filepath, "w", encoding="utf-8") as f: 64 | f.write(contents) 65 | print("Replaced", filepath, "successfully.") 66 | 67 | print("Done.") 68 | print("Replaced", replace_count, "files.") 69 | if replace_count == 0: 70 | print("No files were replaced.") 71 | else: 72 | print("Reduced size by ", round((1 - new_size / old_size) * 100, 2), "%") 73 | print("Reduced size by ", round((old_size - new_size) / 1000000, 2), "mbs") 74 | -------------------------------------------------------------------------------- /unused_files/content.py: -------------------------------------------------------------------------------- 1 | import os 2 | from srctools.mdl import Model 3 | from srctools.vmt import Material 4 | from srctools.filesys import RawFileSystem 5 | 6 | model_formats = [ 7 | ".mdl", 8 | ".vvd", 9 | ".phy", 10 | ".vtx", 11 | ".ani", 12 | ".sw.vtx", 13 | ".dx80.vtx", 14 | ".dx90.vtx", 15 | ".xbox.vtx", 16 | ] 17 | 18 | def unused_content(path, remove=False): 19 | unused_sizes = 0 20 | unused_count = 0 21 | fs = RawFileSystem(path) 22 | 23 | # Find all the models in the filesystem 24 | all_models = [] 25 | all_model_vmts = {} 26 | vmt_used_count = {} 27 | vmf_used_count = {} 28 | for file in fs.walk_folder(''): 29 | if file.path.endswith('.mdl'): 30 | all_models.append(file.path) 31 | 32 | all_model_vmts[file.path] = all_model_vmts.get(file.path, []) 33 | model = Model(fs, fs[file.path]) 34 | for tex in model.iter_textures(): 35 | # append path relative to the input path 36 | all_model_vmts[file.path].append(tex) 37 | vmt_used_count[tex] = vmt_used_count.get(tex, 0) + 1 38 | 39 | # Find all the vtfs of the all_model_vmts vmts 40 | all_model_vtfs = {} 41 | all_vtfs = [] 42 | for model, vmts in all_model_vmts.items(): 43 | for vmt_path in vmts: 44 | with open( os.path.join(path, vmt_path), "r", encoding="utf-8") as f: 45 | vmt = Material.parse(f, filename=vmt_path) 46 | for vmtfield in vmt.items(): 47 | if vmtfield[0].startswith("$basetexture"): 48 | vtf = os.path.normpath(vmtfield[1]) 49 | all_model_vtfs[model] = all_model_vtfs.get(model, []) 50 | all_model_vtfs[model].append(vtf) 51 | all_vtfs.append(vtf) 52 | vmf_used_count[vtf] = vmf_used_count.get(vtf, 0) + 1 53 | 54 | # Find all the models used in lua files 55 | all_lua_used_models = [] 56 | for file in fs.walk_folder('lua'): 57 | if file.path.endswith('.lua'): 58 | with open( os.path.join(path, file.path), "r", encoding="utf-8") as f: 59 | lua_contents = f.read() 60 | lua_contents = lua_contents.lower() 61 | for model in all_models: 62 | if model in lua_contents: 63 | all_lua_used_models.append(model) 64 | 65 | # print not used models 66 | print("Unused models:") 67 | unused_models = [] 68 | for model in all_models: 69 | if model not in all_lua_used_models: 70 | no_ext_model = os.path.splitext(model)[0] 71 | for ext in model_formats: 72 | format_path = os.path.join(path, no_ext_model + ext) 73 | if os.path.exists(format_path): 74 | if ext == ".mdl": 75 | unused_models.append(model) 76 | 77 | for vmt in all_model_vmts[model]: 78 | vmt_used_count[vmt] -= 1 79 | 80 | for vtf in all_model_vtfs.get(model, []): 81 | vmf_used_count[vtf] -= 1 82 | 83 | print("Found unused file:", format_path) 84 | unused_sizes += os.path.getsize(format_path) 85 | unused_count += 1 86 | if remove: 87 | os.remove(format_path) 88 | print("Removed", format_path) 89 | 90 | # Find all the vmts that no longer get used 91 | unused_vmts = [] 92 | for vmt_used in vmt_used_count: 93 | if vmt_used_count[vmt_used] == 0: 94 | unused_vmts.append(vmt_used) 95 | unused_sizes += os.path.getsize(os.path.join(path, vmt_used)) 96 | unused_count += 1 97 | print("Found unused file:", os.path.join(path, vmt_used)) 98 | if remove: 99 | os.remove(os.path.join(path, vmt_used)) 100 | print("Removed", vmt_used) 101 | 102 | unused_vtfs = [] 103 | for vtf_used in vmf_used_count: 104 | if vmf_used_count[vtf_used] == 0: 105 | vtf_used = "materials/" + vtf_used + ".vtf" 106 | if os.path.exists(os.path.join(path, vtf_used)): 107 | unused_vtfs.append(vtf_used) 108 | unused_sizes += os.path.getsize(os.path.join(path, vtf_used)) 109 | unused_count += 1 110 | print("Found unused file:", os.path.join(path, vtf_used)) 111 | if remove: 112 | os.remove(os.path.join(path, vtf_used)) 113 | print("Removed", vtf_used) 114 | 115 | return unused_sizes, unused_count 116 | -------------------------------------------------------------------------------- /unused_files/modelformats.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # Removes unused model formats from a directory, such as .dx80.vtx, .xbox.vtx, .sw.vtx 4 | # These are effectively not used in gmod and can take up a lot of space 5 | 6 | def unused_model_formats(folder, remove=True): 7 | total_size = 0 8 | count = 0 9 | 10 | formats_to_remove = [ 11 | ".dx80.vtx", 12 | ".xbox.vtx", 13 | ".sw.vtx", 14 | ".360.vtx" 15 | ] 16 | 17 | for root, dirs, files in os.walk(folder): 18 | for file in files: 19 | _, ext = os.path.splitext(file) 20 | relative_path = os.path.relpath(root, folder) 21 | 22 | for format in formats_to_remove: 23 | if file.endswith(format): 24 | total_size += os.path.getsize(os.path.join(root, file)) 25 | if remove: 26 | os.remove(os.path.join(root, file)) 27 | print("Removed", os.path.join(root, file)) 28 | else: 29 | print("Found unused file:", os.path.join(root, file)) 30 | 31 | count += 1 32 | 33 | 34 | return total_size, count 35 | -------------------------------------------------------------------------------- /utils/formatting.py: -------------------------------------------------------------------------------- 1 | def format_size(size): 2 | if size < 1000: 3 | return f"{size} B" 4 | 5 | if size < 1000000: 6 | kbs = size / 1000 7 | rounded = round(kbs, 2) 8 | return f"{rounded} KB" 9 | 10 | mbs = size / 1000000 11 | rounded = round(mbs, 2) 12 | return f"{rounded} MB" 13 | --------------------------------------------------------------------------------