├── .editorconfig ├── .github └── workflows │ ├── cd.yaml │ └── ci.yaml ├── .gitignore ├── CMakeLists.txt ├── CMakePresets.json ├── CMakeSettings.json ├── LICENSE ├── README.md ├── TpfConvert ├── CMakeLists.txt └── src │ ├── ModfileLoader.ixx │ ├── ModfileLoader_TpfReader.ixx │ └── TpfConvert.ixx ├── cmake └── dxtk.cmake ├── header ├── Defines.h ├── Error.h ├── Main.h ├── Utils.h ├── uMod_IDirect3D9.h ├── uMod_IDirect3D9Ex.h ├── uMod_IDirect3DCubeTexture9.h ├── uMod_IDirect3DDevice9.h ├── uMod_IDirect3DDevice9Ex.h ├── uMod_IDirect3DTexture9.h └── uMod_IDirect3DVolumeTexture9.h ├── modules ├── ModfileLoader.ixx ├── ModfileLoader_TpfReader.ixx ├── TextureClient.ixx └── TextureFunction.ixx ├── source ├── Error.cpp ├── dll_main.cpp ├── uMod_IDirect3D9.cpp ├── uMod_IDirect3D9Ex.cpp ├── uMod_IDirect3DCubeTexture9.cpp ├── uMod_IDirect3DDevice9.cpp ├── uMod_IDirect3DDevice9Ex.cpp ├── uMod_IDirect3DTexture9.cpp └── uMod_IDirect3DVolumeTexture9.cpp ├── triplets └── x86-windows-mixed.cmake ├── vcpkg-configuration.json ├── vcpkg.json └── version.rc.in /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | charset = utf-8 7 | indent_style = space -------------------------------------------------------------------------------- /.github/workflows/cd.yaml: -------------------------------------------------------------------------------- 1 | name: gMod CD Pipeline 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | workflow_dispatch: 8 | 9 | jobs: 10 | 11 | build: 12 | 13 | strategy: 14 | matrix: 15 | targetplatform: [x86] 16 | 17 | runs-on: windows-latest 18 | 19 | env: 20 | Configuration: Release 21 | Actions_Allow_Unsecure_Commands: true 22 | 23 | steps: 24 | - name: Checkout 25 | uses: actions/checkout@v4 26 | with: 27 | fetch-depth: 0 28 | 29 | - name: Setup MSBuild.exe 30 | uses: microsoft/setup-msbuild@v1.3.1 31 | 32 | - name: Install vcpkg 33 | run: | 34 | git clone https://github.com/microsoft/vcpkg.git 35 | .\vcpkg\bootstrap-vcpkg.bat 36 | 37 | - name: Set VCPKG_ROOT 38 | run: | 39 | echo "VCPKG_ROOT=$(Get-Location)\vcpkg" >> $env:GITHUB_ENV 40 | shell: powershell 41 | 42 | - name: Build CMake Files with vcpkg toolchain 43 | run: cmake --preset=vcpkg 44 | env: 45 | VCPKG_ROOT: ${{ env.VCPKG_ROOT }} 46 | 47 | - name: Build binaries 48 | run: cmake --build build --config Release 49 | 50 | - name: Retrieve version 51 | id: set_version 52 | run: | 53 | $fileVersionInfo = (Get-Item -Path .\bin\Release\gMod.dll).VersionInfo.FileVersion 54 | if ([string]::IsNullOrEmpty($fileVersionInfo)) { 55 | Write-Host "The DLL file version information could not be retrieved." 56 | exit 1 57 | } else { 58 | Write-Host "FileVersionInfo: $fileVersionInfo" 59 | echo "::set-output name=version::$fileVersionInfo" 60 | } 61 | shell: pwsh 62 | 63 | - name: Publish release 64 | uses: Xotl/cool-github-releases@v1.1.8 65 | with: 66 | mode: update 67 | tag_name: v${{ steps.set_version.outputs.version }} 68 | release_name: gMod v${{ steps.set_version.outputs.version }} 69 | assets: .\bin\Release\gMod.dll;.\bin\Release\TpfConvert.exe;.\bin\Release\d3dx9_43.dll 70 | github_token: ${{ env.GITHUB_TOKEN }} 71 | replace_assets: true 72 | body_mrkdwn: ${{ env.Changelog }} 73 | env: 74 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 75 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: gMod CI Pipeline 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | push: 8 | branches: 9 | - dev 10 | workflow_dispatch: 11 | 12 | jobs: 13 | build: 14 | 15 | strategy: 16 | matrix: 17 | targetplatform: [x86] 18 | 19 | runs-on: windows-latest 20 | 21 | env: 22 | Configuration: Release 23 | Actions_Allow_Unsecure_Commands: true 24 | 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@v4 28 | with: 29 | fetch-depth: 0 30 | 31 | - name: Setup MSBuild.exe 32 | uses: microsoft/setup-msbuild@v1.3.1 33 | 34 | - name: Install vcpkg 35 | run: | 36 | git clone https://github.com/microsoft/vcpkg.git 37 | .\vcpkg\bootstrap-vcpkg.bat 38 | 39 | - name: Set VCPKG_ROOT 40 | run: | 41 | echo "VCPKG_ROOT=$(Get-Location)\vcpkg" >> $env:GITHUB_ENV 42 | shell: powershell 43 | 44 | - name: Build CMake Files with vcpkg toolchain 45 | run: cmake --preset=vcpkg 46 | env: 47 | VCPKG_ROOT: ${{ env.VCPKG_ROOT }} 48 | 49 | - name: Build binaries 50 | run: cmake --build build --config Release 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDE 2 | *.vs 3 | *.user 4 | *.settings 5 | *.vscode 6 | *.project 7 | *.cproject 8 | *.vcproj 9 | *.vcxproj 10 | *.vcxproj.filters 11 | **/CMakeFiles/** 12 | cmake_install.cmake 13 | CMakeCache.txt 14 | *.sln 15 | *.rc 16 | /*.dir 17 | 18 | # Build directories 19 | Release 20 | Debug 21 | bin/ 22 | */Debug 23 | */Release 24 | */bin 25 | */obj 26 | vcpkg 27 | vcpkg_installed 28 | 29 | # Bloated Windows Databases 30 | *.sdf 31 | *.opensdf 32 | *.suo 33 | *.exp 34 | *.db 35 | *.pdb 36 | *.idb 37 | *.ilk 38 | *.opendb 39 | *.log 40 | *.lastbuildstate 41 | 42 | # Compiled files 43 | *.slo 44 | *.lo 45 | *.o 46 | *.obj 47 | *.exe 48 | *.wxs 49 | *.wixobj 50 | *.msi 51 | 52 | # Precompiled Headers 53 | *.gch 54 | *.pch 55 | *.idb 56 | *.pdb 57 | *.opendb 58 | *.wixpdb 59 | 60 | **/RelWithDebInfo/ 61 | **/Debug/ 62 | /bin 63 | /win32 64 | /out 65 | /build 66 | /_deps 67 | 68 | .idea -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.29) 2 | 3 | set(CMAKE_GENERATOR_PLATFORM win32) 4 | 5 | project(gMod) 6 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 7 | 8 | if(NOT(CMAKE_SIZEOF_VOID_P EQUAL 4)) 9 | message(FATAL_ERROR "You are configuring a non 32-bit build, this is not supported. Run cmake with `-A Win32`") 10 | endif() 11 | 12 | set(VERSION_MAJOR 1) 13 | set(VERSION_MINOR 7) 14 | set(VERSION_PATCH 0) 15 | set(VERSION_TWEAK 2) 16 | 17 | set(VERSION_RC "${CMAKE_CURRENT_BINARY_DIR}/version.rc") 18 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${VERSION_RC}" @ONLY) 19 | 20 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin") 21 | set(CMAKE_CXX_STANDARD 23) 22 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 23 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 24 | 25 | add_compile_options(/MP /permissive-) 26 | 27 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 28 | find_package(libzippp CONFIG REQUIRED) 29 | find_package(minhook CONFIG REQUIRED) 30 | find_package(Microsoft.GSL CONFIG REQUIRED) 31 | include(dxtk) 32 | 33 | add_library(gMod SHARED) 34 | 35 | file(GLOB SOURCES 36 | "header/*.h" 37 | "source/*.cpp" 38 | "modules/*.ixx" 39 | ${VERSION_RC} 40 | ) 41 | 42 | target_include_directories(gMod PRIVATE 43 | "header" 44 | ${CMAKE_INSTALL_PREFIX}/include 45 | ) 46 | source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${SOURCES}) 47 | target_sources(gMod PRIVATE ${SOURCES}) 48 | target_compile_options(gMod PRIVATE /W4 /WX) 49 | 50 | target_link_libraries(gMod PRIVATE 51 | dxguid 52 | libzippp::libzippp 53 | psapi 54 | minhook::minhook 55 | directxtex 56 | Microsoft.GSL::GSL 57 | ) 58 | target_link_options(gMod PRIVATE 59 | "$<$:/NODEFAULTLIB:LIBCMT>" 60 | "/LARGEADDRESSAWARE" 61 | ) 62 | source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${SOURCES}) 63 | target_sources(gMod PRIVATE ${SOURCES}) 64 | target_compile_definitions(gMod PRIVATE 65 | "NOMINMAX" 66 | "_WIN32_WINNT=_WIN32_WINNT_WIN7" 67 | "WIN32_LEAN_AND_MEAN" 68 | "VC_EXTRALEAN" 69 | DIRECT_INJECTION 70 | LOG_MESSAGE 71 | ) 72 | 73 | add_subdirectory(TpfConvert) 74 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "configurePresets": [ 4 | { 5 | "name": "vcpkg", 6 | "generator": "Visual Studio 17 2022", 7 | "architecture": "Win32", 8 | "binaryDir": "${sourceDir}/build", 9 | "cacheVariables": { 10 | "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/triplets", 11 | "VCPKG_TARGET_TRIPLET": "x86-windows-mixed", 12 | "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "x86-Debug", 5 | "generator": "Visual Studio 17 2022", 6 | "configurationType": "Debug", 7 | "inheritEnvironments": [ "msvc_x86" ], 8 | "buildRoot": "${projectDir}\\out\\build\\${name}", 9 | "installRoot": "${projectDir}\\out\\install\\${name}", 10 | "cmakeCommandArgs": "", 11 | "buildCommandArgs": "", 12 | "ctestCommandArgs": "" 13 | }, 14 | { 15 | "name": "x86-Release", 16 | "generator": "Visual Studio 17 2022", 17 | "configurationType": "Release", 18 | "inheritEnvironments": [ "msvc_x86" ], 19 | "buildRoot": "${projectDir}\\out\\build\\${name}", 20 | "installRoot": "${projectDir}\\out\\install\\${name}", 21 | "cmakeCommandArgs": "", 22 | "buildCommandArgs": "", 23 | "ctestCommandArgs": "" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /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 | ***gMod*** 2 | 3 | Continuation of the uMod project to improve performance and stability. Integrated with [Guild Wars Launcher](https://github.com/gwdevhub/gwlauncher) and [Daybreak](https://github.com/gwdevhub/Daybreak). 4 | 5 | *Usage is primarily intended with GW Launcher or Daybreak, but it can be used without.* 6 | 7 | **Usage with manual gMod.dll injection:** 8 | - Create a file called modlist.txt in either the Guild Wars (Gw.exe) folder, or the gMod.dll folder. 9 | - Inject gMod.dll before d3d9.dll is loaded. 10 | 11 | **Usage without dll injection:** 12 | - Create a file called modlist.txt in the Guild Wars (Gw.exe) folder. 13 | - Place gMod.dll in the Guild Wars folder 14 | - Rename gMod.dll to d3d9.dll 15 | - Launch Guild Wars 16 | 17 | **Format of the modlist.txt file:** 18 | 19 | Each line in the modlist.txt is the full path to a mod you want to load (eg. `D:\uMod\Borderless Cartography Made Easy 2015 1.3.tpf`) 20 | gMod will load all these files on startup 21 | 22 | **Disclaimer about [Reshade](https://github.com/crosire/reshade)** 23 | 24 | Reshade in versions > 5.0.1 is known to cause glitches with TexMod, uMod and also gMod. 25 | If you would like to use Reshade in combination with gMod, we recommend running version [5.0.1](https://github.com/crosire/reshade/releases/tag/v5.0.1) or [4.9.1](https://github.com/crosire/reshade/releases/tag/v4.9.1). 26 | 27 | **Build from source** 28 | 29 | Requirements: 30 | - Visual Studio 2022 31 | - CMake 3.29+, integrated into the Developer Powershell for VS 2022 32 | - vcpkg, integrated into the Developer Powershell for VS 2022 33 | 34 | Compile: 35 | - cmake --preset=vcpkg 36 | - cmake --open build 37 | - compile 38 | 39 | **TpfConvert** 40 | Small utility to convert old .tpf files with invalid images into .zip files with working images. 41 | Usage: 42 | - Put TpfConvert.exe and d3dx9.dll in the folder where you have your old, broken texmods with invalid images. 43 | - Run TpfConvert.exe, all *.tpf and *.zip files are processed. The originals are saved into a newly created backup folder. 44 | - Done. 45 | -------------------------------------------------------------------------------- /TpfConvert/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(TpfConvert) 2 | 3 | # Find all .ixx files in the TpfConvert folder 4 | file(GLOB TPF_SOURCES "src/*.ixx") 5 | 6 | # Add the .ixx files to the TpfConvert target 7 | target_sources(TpfConvert PRIVATE ${TPF_SOURCES}) 8 | 9 | set_target_properties(TpfConvert PROPERTIES 10 | CXX_STANDARD 23 11 | CXX_STANDARD_REQUIRED ON 12 | ) 13 | 14 | target_compile_definitions(TpfConvert PRIVATE 15 | "NOMINMAX" 16 | "_WIN32_WINNT=_WIN32_WINNT_WIN7" 17 | "WIN32_LEAN_AND_MEAN" 18 | "VC_EXTRALEAN" 19 | ) 20 | 21 | if(DEFINED ENV{VCPKG_ROOT}) 22 | message(STATUS "VCPKG_ROOT: $ENV{VCPKG_ROOT}") 23 | else() 24 | message(STATUS "VCPKG_ROOT is not set") 25 | endif() 26 | 27 | if(DEFINED CMAKE_TOOLCHAIN_FILE) 28 | message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") 29 | else() 30 | message(STATUS "CMAKE_TOOLCHAIN_FILE is not set") 31 | endif() 32 | 33 | find_package(dxsdk-d3dx CONFIG REQUIRED) 34 | 35 | target_link_libraries(TpfConvert PRIVATE 36 | libzippp::libzippp 37 | Microsoft::D3DX9 38 | d3d9 39 | ) 40 | -------------------------------------------------------------------------------- /TpfConvert/src/ModfileLoader.ixx: -------------------------------------------------------------------------------- 1 | export module ModfileLoader; 2 | 3 | import std; 4 | import ; 5 | import ModfileLoader.TpfReader; 6 | 7 | export using HashType = uint64_t; 8 | 9 | export struct TexEntry { 10 | std::vector data{}; 11 | HashType crc_hash = 0; // hash value 12 | std::string ext{}; 13 | }; 14 | 15 | namespace { 16 | HashType GetCrcFromFilename(const std::string& filename) { 17 | const static std::regex re(R"(0x[0-9a-f]{4,16})", std::regex::optimize | std::regex::icase); 18 | std::smatch match; 19 | if (!std::regex_search(filename, match, re)) { 20 | return 0; 21 | } 22 | 23 | uint64_t crc64_hash = 0; 24 | const auto number_str = match.str(); 25 | try { 26 | crc64_hash = std::stoull(number_str, nullptr, 16); 27 | } 28 | catch (const std::invalid_argument&) { 29 | std::print(stderr, "Failed to parse {} as a hash\n", filename); 30 | return 0; 31 | } 32 | catch (const std::out_of_range&) { 33 | std::print(stderr, "Out of range while parsing {} as a hash\n", filename); 34 | return 0; 35 | } 36 | return crc64_hash; 37 | } 38 | } 39 | 40 | export class ModfileLoader { 41 | std::filesystem::path file_name; 42 | const std::string TPF_PASSWORD{ 43 | 0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, static_cast(0xA6), static_cast(0xBD), 44 | 0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F, 45 | 0x74, 0x61, 0x67, 0x5B, 0x60, 0x70, 0x45, 0x74, 46 | 0x5C, 0x22, 0x74, 0x5D, 0x6E, 0x6A, 0x73, 0x41, 47 | 0x77, 0x6E, 0x46, 0x47, 0x77, 0x49, 0x0C, 0x4B, 48 | 0x46, 0x6F 49 | }; 50 | 51 | public: 52 | ModfileLoader(const std::filesystem::path& fileName); 53 | 54 | std::vector GetContents() const; 55 | 56 | private: 57 | 58 | std::vector GetTpfContents() const; 59 | 60 | std::vector GetFileContents() const; 61 | 62 | static void LoadEntries(libzippp::ZipArchive& archive, std::vector& entries); 63 | }; 64 | 65 | ModfileLoader::ModfileLoader(const std::filesystem::path& fileName) 66 | { 67 | file_name = std::filesystem::absolute(fileName); 68 | } 69 | 70 | std::vector ModfileLoader::GetContents() const 71 | { 72 | try { 73 | return file_name.wstring().ends_with(L".tpf") ? GetTpfContents() : GetFileContents(); 74 | } 75 | catch (const std::exception&) { 76 | std::print(stderr, "Failed to open mod file: {}\n", file_name.string().c_str()); 77 | } 78 | return {}; 79 | } 80 | 81 | std::vector ModfileLoader::GetTpfContents() const 82 | { 83 | std::vector entries; 84 | auto tpf_reader = TpfReader(file_name); 85 | const auto buffer = tpf_reader.ReadToEnd(); 86 | const auto zip_archive = libzippp::ZipArchive::fromBuffer(buffer.data(), buffer.size(), false, TPF_PASSWORD); 87 | if (!zip_archive) { 88 | std::print(stderr, "Failed to open tpf file: {} - {} uint8_ts!\n", file_name.string(), buffer.size()); 89 | return {}; 90 | } 91 | zip_archive->setErrorHandlerCallback( 92 | [](const std::string& message, const std::string& strerror, int zip_error_code, int system_error_code) -> void { 93 | std::print(stderr, "GetTpfContents: {} {} {} {}\n", message, strerror, zip_error_code, system_error_code); 94 | }); 95 | zip_archive->open(); 96 | LoadEntries(*zip_archive, entries); 97 | zip_archive->close(); 98 | libzippp::ZipArchive::free(zip_archive); 99 | 100 | return entries; 101 | } 102 | 103 | std::vector ModfileLoader::GetFileContents() const 104 | { 105 | std::vector entries; 106 | 107 | libzippp::ZipArchive zip_archive(file_name.string()); 108 | zip_archive.open(); 109 | LoadEntries(zip_archive, entries); 110 | zip_archive.close(); 111 | 112 | return entries; 113 | } 114 | 115 | void ParseSimpleArchive(const libzippp::ZipArchive& archive, std::vector& entries) 116 | { 117 | for (const auto& entry : archive.getEntries()) { 118 | if (!entry.isFile()) 119 | continue; 120 | const auto crc_hash = GetCrcFromFilename(entry.getName()); 121 | if (!crc_hash) 122 | continue; 123 | const auto data_ptr = static_cast(entry.readAsBinary()); 124 | const auto size = entry.getSize(); 125 | std::vector vec(data_ptr, data_ptr + size); 126 | std::filesystem::path tex_name(entry.getName()); 127 | entries.emplace_back(std::move(vec), crc_hash, tex_name.extension().string()); 128 | delete[] data_ptr; 129 | } 130 | } 131 | 132 | void ParseTexmodArchive(std::vector& lines, libzippp::ZipArchive& archive, std::vector& entries) 133 | { 134 | for (const auto& line : lines) { 135 | // 0xC57D73F7|GW.EXE_0xC57D73F7.tga\r\n 136 | // match[1] | match[2] 137 | const static auto address_file_regex = std::regex(R"(^[\\/.]*([^|]+)\|([^\r\n]+))", std::regex::optimize); 138 | std::smatch match; 139 | if (!std::regex_search(line, match, address_file_regex)) 140 | continue; 141 | const auto address_string = match[1].str(); 142 | const auto file_path = match[2].str(); 143 | 144 | const auto crc_hash = GetCrcFromFilename(address_string); 145 | if (!crc_hash) 146 | continue; 147 | 148 | const auto entry = archive.getEntry(file_path); 149 | if (entry.isNull() || !entry.isFile()) 150 | continue; 151 | 152 | const auto data_ptr = static_cast(entry.readAsBinary()); 153 | const auto size = static_cast(entry.getSize()); 154 | std::vector vec(data_ptr, data_ptr + size); 155 | const auto tex_name = std::filesystem::path(entry.getName()); 156 | entries.emplace_back(std::move(vec), crc_hash, tex_name.extension().string()); 157 | delete[] data_ptr; 158 | } 159 | } 160 | 161 | void ModfileLoader::LoadEntries(libzippp::ZipArchive& archive, std::vector& entries) 162 | { 163 | const auto def_file = archive.getEntry("texmod.def"); 164 | if (def_file.isNull() || !def_file.isFile()) { 165 | ParseSimpleArchive(archive, entries); 166 | } 167 | else { 168 | const auto def = def_file.readAsText(); 169 | std::istringstream iss(def); 170 | std::vector lines; 171 | std::string line; 172 | 173 | while (std::getline(iss, line)) { 174 | lines.push_back(line); 175 | } 176 | 177 | ParseTexmodArchive(lines, archive, entries); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /TpfConvert/src/ModfileLoader_TpfReader.ixx: -------------------------------------------------------------------------------- 1 | export module ModfileLoader.TpfReader; 2 | 3 | import std; 4 | 5 | export class TpfReader { 6 | public: 7 | TpfReader(const std::filesystem::path& path) 8 | { 9 | file_stream = std::ifstream(path, std::ios::binary); 10 | if (!file_stream.seekg(0, std::ios::end).good() || !file_stream.seekg(0, std::ios::beg).good()) { 11 | throw std::invalid_argument("Provided stream needs to have SEEK set to True"); 12 | } 13 | } 14 | 15 | ~TpfReader() 16 | { 17 | file_stream.close(); 18 | } 19 | 20 | std::vector ReadToEnd() 21 | { 22 | file_stream.seekg(0, std::ios::end); 23 | line_length = file_stream.tellg(); 24 | file_stream.seekg(0, std::ios::beg); // Go to the beginning of the stream 25 | 26 | std::vector data(line_length); 27 | file_stream.read(data.data(), line_length); 28 | for (auto i = 0; i < data.size(); i++) { 29 | data[i] = XOR(data[i], i); 30 | } 31 | 32 | for (int i = data.size() - 1; i > 0 && data[i] != 0; i--) { 33 | data[i] = 0; 34 | } 35 | 36 | // in the other zip libraries, these had to be cut off, with libzip we need to zero them out 37 | // cutting them off makes the archive invalid 38 | //data.resize(last_zero); 39 | 40 | return data; 41 | } 42 | 43 | private: 44 | std::ifstream file_stream; 45 | long line_length = 0; 46 | 47 | [[nodiscard]] char XOR(const char b, const long position) const 48 | { 49 | if (position > line_length - 4) { 50 | return b ^ TPF_XOREven; 51 | } 52 | 53 | return position % 2 == 0 ? b ^ TPF_XOREven : b ^ TPF_XOROdd; 54 | } 55 | 56 | static constexpr char TPF_XOROdd = 0x3F; 57 | static constexpr char TPF_XOREven = static_cast(0xA4); 58 | }; 59 | -------------------------------------------------------------------------------- /TpfConvert/src/TpfConvert.ixx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | import std; 7 | import ModfileLoader; 8 | import ; 9 | 10 | struct TexEntry; 11 | 12 | namespace { 13 | IDirect3D9* pD3D = nullptr; 14 | IDirect3DDevice9* pDevice = nullptr; 15 | 16 | bool InitializeDirect3D() 17 | { 18 | pD3D = Direct3DCreate9(D3D_SDK_VERSION); 19 | if (pD3D == nullptr) { 20 | std::print(stderr, "Failed to create Direct3D9 object\n"); 21 | return false; 22 | } 23 | 24 | D3DPRESENT_PARAMETERS d3dpp = {}; 25 | d3dpp.Windowed = TRUE; 26 | d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; 27 | d3dpp.hDeviceWindow = GetDesktopWindow(); 28 | 29 | if (FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetDesktopWindow(), 30 | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) { 31 | std::print(stderr, "Failed to create Direct3D9 device\n"); 32 | pD3D->Release(); 33 | return false; 34 | } 35 | 36 | return true; 37 | } 38 | 39 | void CleanupDirect3D() 40 | { 41 | if (pDevice) pDevice->Release(); 42 | if (pD3D) pD3D->Release(); 43 | } 44 | 45 | std::pair> SaveAsDDS(const TexEntry& entry) 46 | { 47 | IDirect3DTexture9* pTexture = nullptr; 48 | ID3DXBuffer* pBuffer = nullptr; 49 | 50 | HRESULT hr = D3DXCreateTextureFromFileInMemoryEx(pDevice, 51 | entry.data.data(), entry.data.size(), 52 | D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 53 | D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, 54 | D3DX_FILTER_NONE, 0, NULL, NULL, &pTexture); 55 | 56 | if (FAILED(hr)) { 57 | std::print(stderr, "Failed to create texture from memory\n"); 58 | return {}; 59 | } 60 | 61 | hr = D3DXSaveTextureToFileInMemory(&pBuffer, D3DXIFF_DDS, pTexture, NULL); 62 | if (FAILED(hr)) { 63 | std::print(stderr, "Failed to save texture to DDS memory buffer\n"); 64 | pTexture->Release(); 65 | return {}; 66 | } 67 | 68 | std::string dds_filename = std::format("0x{:x}.dds", entry.crc_hash); 69 | std::vector dds_data(pBuffer->GetBufferSize()); 70 | std::memcpy(dds_data.data(), pBuffer->GetBufferPointer(), pBuffer->GetBufferSize()); 71 | 72 | pTexture->Release(); 73 | pBuffer->Release(); 74 | 75 | return {dds_filename, dds_data}; 76 | } 77 | 78 | std::filesystem::path GetExecutablePath() 79 | { 80 | char buffer[MAX_PATH]; 81 | GetModuleFileNameA(NULL, buffer, MAX_PATH); 82 | return std::filesystem::path(buffer).parent_path(); 83 | } 84 | } 85 | 86 | int main(int argc, char* argv[]) 87 | { 88 | const std::filesystem::path path = argc > 1 ? argv[1] : GetExecutablePath(); 89 | const auto backup_path = path / "backup"; 90 | 91 | if (!InitializeDirect3D()) { 92 | return -1; 93 | } 94 | 95 | if (!std::filesystem::exists(path)) { 96 | return 1; 97 | } 98 | 99 | if (!std::filesystem::exists(backup_path)) { 100 | std::filesystem::create_directory(backup_path); 101 | } 102 | 103 | for (const auto& modfile : std::filesystem::directory_iterator(path)) { 104 | if (modfile.is_regular_file() && (modfile.path().extension() == ".tpf" || modfile.path().extension() == ".zip")) { 105 | const auto mod_path = modfile.path(); 106 | const auto backup_file = backup_path / mod_path.filename(); 107 | 108 | if (std::filesystem::exists( backup_file)) { 109 | std::print("Skipping previous TpfConvert output: {}\n", mod_path.filename().string()); 110 | continue; 111 | } 112 | else { 113 | std::print("Processing: {}\n", mod_path.filename().string()); 114 | std::error_code ec; 115 | std::filesystem::rename(mod_path, backup_file, ec); 116 | } 117 | 118 | const auto zip_filename = path / (mod_path.stem().string() + ".zip"); 119 | if (std::filesystem::exists(zip_filename)) { 120 | std::filesystem::remove(zip_filename); 121 | } 122 | 123 | ModfileLoader loader(backup_file); 124 | std::vector>> data_entries; 125 | const auto entries = loader.GetContents(); 126 | 127 | libzippp::ZipArchive zip_archive(zip_filename.string()); 128 | zip_archive.open(libzippp::ZipArchive::Write); 129 | 130 | for (const auto& entry : entries) { 131 | auto [dds_filename, dds_data] = SaveAsDDS(entry); 132 | if (!dds_filename.empty()) { 133 | data_entries.emplace_back(dds_filename, std::move(dds_data)); 134 | } 135 | } 136 | 137 | for (const auto& [filename, data] : data_entries) { 138 | const auto success = zip_archive.addData(filename, data.data(), data.size()); 139 | if (!success) { 140 | std::print(stderr, "Failed to add data to ZIP: {}\n", filename); 141 | } 142 | } 143 | 144 | zip_archive.close(); 145 | std::print("Saved to ZIP: {}\n", zip_filename.string()); 146 | } 147 | } 148 | 149 | CleanupDirect3D(); 150 | 151 | return 0; 152 | } 153 | -------------------------------------------------------------------------------- /cmake/dxtk.cmake: -------------------------------------------------------------------------------- 1 | include_guard() 2 | include(FetchContent) 3 | 4 | FetchContent_Declare( 5 | DirectXTex 6 | GIT_REPOSITORY https://github.com/microsoft/DirectXTex 7 | GIT_TAG oct2023) 8 | FetchContent_GetProperties(directxtex) 9 | if (directxtex_POPULATED) 10 | return() 11 | endif() 12 | 13 | FetchContent_Populate(directxtex) 14 | 15 | add_library(directxtex) 16 | file(GLOB SOURCES 17 | "${directxtex_SOURCE_DIR}/DDSTextureLoader/DDSTextureLoader9.h" 18 | "${directxtex_SOURCE_DIR}/DDSTextureLoader/DDSTextureLoader9.cpp" 19 | "${directxtex_SOURCE_DIR}/WICTextureLoader/WICTextureLoader9.h" 20 | "${directxtex_SOURCE_DIR}/WICTextureLoader/WICTextureLoader9.cpp" 21 | "${directxtex_SOURCE_DIR}/DirectXTex/*.h" 22 | "${directxtex_SOURCE_DIR}/DirectXTex/*.cpp" 23 | ) 24 | list(REMOVE_ITEM SOURCES 25 | "${directxtex_SOURCE_DIR}/DirectXTex/BCDirectCompute.cpp" 26 | ) 27 | source_group(TREE ${directxtex_SOURCE_DIR} FILES ${SOURCES}) 28 | target_sources(directxtex PRIVATE ${SOURCES}) 29 | target_include_directories(directxtex PUBLIC "${directxtex_SOURCE_DIR}") 30 | 31 | set_target_properties(directxtex PROPERTIES FOLDER "Dependencies/") 32 | -------------------------------------------------------------------------------- /header/Defines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //using HashType = DWORD32; 4 | using HashType = DWORD64; 5 | 6 | struct HashTuple { 7 | HashType crc32; 8 | HashType crc64; 9 | 10 | bool operator==(const HashTuple& other) const noexcept 11 | { 12 | return (other.crc32 == crc32) || (other.crc64 == crc64); 13 | } 14 | 15 | explicit operator bool() const noexcept 16 | { 17 | return crc32 != 0 || crc64 != 0; 18 | } 19 | 20 | explicit operator HashType() const noexcept 21 | { 22 | return crc32 ? crc32 : crc64; 23 | } 24 | }; 25 | 26 | struct TexEntry { 27 | std::vector data{}; 28 | HashType crc_hash = 0; // hash value 29 | std::string ext{}; 30 | }; 31 | 32 | struct TextureFileStruct { 33 | std::vector data{}; 34 | HashType crc_hash = 0; // hash value 35 | }; 36 | 37 | inline void Message([[maybe_unused]] const char* format, ...) 38 | { 39 | #ifdef _DEBUG 40 | #if 0 41 | va_list args; 42 | va_start(args, format); 43 | vprintf(format, args); 44 | va_end(args); 45 | #endif 46 | #endif 47 | } 48 | 49 | inline void Info([[maybe_unused]] const char* format, ...) 50 | { 51 | #ifdef _DEBUG 52 | const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 53 | [[maybe_unused]] const auto success = SetConsoleTextAttribute(hConsole, 0); // white 54 | va_list args; 55 | va_start(args, format); 56 | vprintf(format, args); 57 | va_end(args); 58 | #endif 59 | } 60 | 61 | inline void Warning([[maybe_unused]] const char* format, ...) 62 | { 63 | #ifdef _DEBUG 64 | const HANDLE hConsole = GetStdHandle(STD_ERROR_HANDLE); 65 | [[maybe_unused]] const auto success = SetConsoleTextAttribute(hConsole, 6); // yellow 66 | va_list args; 67 | va_start(args, format); 68 | vfprintf(stderr, format, args); 69 | va_end(args); 70 | #endif 71 | } 72 | -------------------------------------------------------------------------------- /header/Error.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // define return values, a value less than zero indicates an error 4 | #define RETURN_OK 0 5 | #define RETURN_EXISTS -70 6 | 7 | #define RETURN_FATAL_ERROR -1 8 | #define RETURN_NO_MEMORY -2 9 | #define RETURN_BAD_ARGUMENT -3 10 | 11 | #define RETURN_NO_IDirect3DDevice9 -10 12 | 13 | #define RETURN_TEXTURE_NOT_LOADED -20 14 | #define RETURN_TEXTURE_NOT_SAVED -21 15 | #define RETURN_TEXTURE_NOT_FOUND -22 16 | #define RETURN_TEXTURE_ALLREADY_ADDED -23 17 | #define RETURN_TEXTURE_NOT_SWITCHED -24 18 | 19 | #define RETURN_LockRect_FAILED -30 20 | #define RETURN_UnlockRect_FAILED -31 21 | #define RETURN_GetLevelDesc_FAILED -32 22 | 23 | 24 | #define RETURN_NO_MUTEX -40 25 | #define RETURN_MUTEX_LOCK -41 26 | #define RETURN_MUTEX_UNLOCK -42 27 | 28 | #define RETURN_UPDATE_ALLREADY_ADDED -50 29 | #define RETURN_FILE_NOT_LOADED -51 30 | 31 | #define RETURN_PIPE_NOT_OPENED 60 32 | 33 | 34 | // define error states 35 | #define uMod_ERROR_FATAL 1u 36 | #define uMod_ERROR_MUTEX 1u<<1 37 | #define uMod_ERROR_PIPE 1u<<2 38 | #define uMod_ERROR_MEMORY 1u<<3 39 | #define uMod_ERROR_TEXTURE 1u<<4 40 | #define uMod_ERROR_MULTIPLE_IDirect3D9 1u<<5 41 | #define uMod_ERROR_MULTIPLE_IDirect3DDevice9 1u<<6 42 | #define uMod_ERROR_UPDATE 1u<<7 43 | #define uMod_ERROR_SERVER 1u<<8 44 | 45 | __declspec(noreturn) void FatalAssert( 46 | const char* expr, 47 | const char* file, 48 | unsigned int line, 49 | const char* function); 50 | 51 | #define ASSERT(expr) ((void)(!!(expr) || (FatalAssert(#expr, __FILE__, (unsigned)__LINE__, __FUNCTION__), 0))) 52 | 53 | -------------------------------------------------------------------------------- /header/Main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "Utils.h" 13 | 14 | #include 15 | #include 16 | 17 | #include "Defines.h" 18 | #include "Error.h" 19 | #include "Defines.h" 20 | 21 | #include "uMod_IDirect3D9.h" 22 | #include "uMod_IDirect3D9Ex.h" 23 | 24 | #include "uMod_IDirect3DDevice9.h" 25 | #include "uMod_IDirect3DDevice9Ex.h" 26 | 27 | #include "uMod_IDirect3DCubeTexture9.h" 28 | #include "uMod_IDirect3DTexture9.h" 29 | #include "uMod_IDirect3DVolumeTexture9.h" 30 | 31 | #pragma warning(disable : 4477) 32 | 33 | extern unsigned int gl_ErrorState; 34 | extern HINSTANCE gl_hThisInstance; 35 | -------------------------------------------------------------------------------- /header/Utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace utils 6 | { 7 | template 8 | void erase_first(std::vector& vec, const T& elem) 9 | { 10 | const auto found = std::ranges::find(vec, elem); 11 | if (found != std::ranges::end(vec)) { 12 | vec.erase(found); 13 | } 14 | } 15 | 16 | inline std::wstring utf8_to_wstring(const std::string& utf8str) { 17 | if (utf8str.empty()) return {}; 18 | 19 | // Calculate the number of wide characters needed for the conversion 20 | const int count = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1, nullptr, 0); 21 | if (count == 0) throw std::runtime_error("Failed to convert UTF-8 to UTF-16"); 22 | 23 | std::wstring wstr(count, 0); 24 | MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1, wstr.data(), count); 25 | 26 | return wstr; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /header/uMod_IDirect3D9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class uMod_IDirect3D9 : public IDirect3D9 { 6 | public: 7 | uMod_IDirect3D9(IDirect3D9* pOriginal); 8 | virtual ~uMod_IDirect3D9(); 9 | 10 | // The original DX9 function definitions 11 | HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) override; 12 | ULONG __stdcall AddRef() override; 13 | ULONG __stdcall Release() override; 14 | HRESULT __stdcall RegisterSoftwareDevice(void* pInitializeFunction) override; 15 | UINT __stdcall GetAdapterCount() override; 16 | HRESULT __stdcall GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) override; 17 | UINT __stdcall GetAdapterModeCount(UINT Adapter, D3DFORMAT Format) override; 18 | HRESULT __stdcall EnumAdapterModes(UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) override; 19 | HRESULT __stdcall GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE* pMode) override; 20 | HRESULT __stdcall CheckDeviceType(UINT iAdapter, D3DDEVTYPE DevType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) override; 21 | HRESULT __stdcall CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) override; 22 | HRESULT __stdcall CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) override; 23 | HRESULT __stdcall CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) override; 24 | HRESULT __stdcall CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) override; 25 | HRESULT __stdcall GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) override; 26 | HMONITOR __stdcall GetAdapterMonitor(UINT Adapter) override; 27 | HRESULT __stdcall CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface) override; 28 | 29 | private: 30 | IDirect3D9* m_pIDirect3D9; 31 | }; 32 | -------------------------------------------------------------------------------- /header/uMod_IDirect3D9Ex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class uMod_IDirect3D9Ex : public IDirect3D9Ex { 6 | public: 7 | uMod_IDirect3D9Ex(IDirect3D9Ex* pOriginal); 8 | virtual ~uMod_IDirect3D9Ex(); 9 | 10 | // The original DX9 function definitions 11 | HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) override; 12 | ULONG __stdcall AddRef() override; 13 | ULONG __stdcall Release() override; 14 | HRESULT __stdcall RegisterSoftwareDevice(void* pInitializeFunction) override; 15 | UINT __stdcall GetAdapterCount() override; 16 | HRESULT __stdcall GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) override; 17 | UINT __stdcall GetAdapterModeCount(UINT Adapter, D3DFORMAT Format) override; 18 | HRESULT __stdcall EnumAdapterModes(UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) override; 19 | HRESULT __stdcall GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE* pMode) override; 20 | HRESULT __stdcall CheckDeviceType(UINT iAdapter, D3DDEVTYPE DevType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) override; 21 | HRESULT __stdcall CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) override; 22 | HRESULT __stdcall CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) override; 23 | HRESULT __stdcall CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) override; 24 | HRESULT __stdcall CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) override; 25 | HRESULT __stdcall GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) override; 26 | HMONITOR __stdcall GetAdapterMonitor(UINT Adapter) override; 27 | HRESULT __stdcall CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface) override; 28 | 29 | HRESULT __stdcall CreateDeviceEx(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, 30 | IDirect3DDevice9Ex** ppReturnedDeviceInterface) override; 31 | HRESULT __stdcall EnumAdapterModesEx(UINT Adapter, const D3DDISPLAYMODEFILTER* pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode) override; 32 | HRESULT __stdcall GetAdapterDisplayModeEx(UINT Adapter, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) override; 33 | HRESULT __stdcall GetAdapterLUID(UINT Adapter, LUID* pLUID) override; 34 | UINT __stdcall GetAdapterModeCountEx(UINT Adapter, const D3DDISPLAYMODEFILTER* pFilter) override; 35 | 36 | private: 37 | IDirect3D9Ex* m_pIDirect3D9Ex; 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /header/uMod_IDirect3DCubeTexture9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | interface uMod_IDirect3DCubeTexture9 : IDirect3DCubeTexture9 { 6 | uMod_IDirect3DCubeTexture9(IDirect3DCubeTexture9** ppTex, IDirect3DDevice9* pIDirect3DDevice9) 7 | : m_D3Dtex(*ppTex), 8 | m_D3Ddev(pIDirect3DDevice9) 9 | {} 10 | 11 | virtual ~uMod_IDirect3DCubeTexture9() = default; 12 | 13 | // callback interface 14 | IDirect3DCubeTexture9* m_D3Dtex = nullptr; 15 | uMod_IDirect3DCubeTexture9* CrossRef_D3Dtex = nullptr; 16 | IDirect3DDevice9* m_D3Ddev = nullptr; 17 | TextureFileStruct* Reference = nullptr; 18 | HashTuple Hash = {}; 19 | bool FAKE = false; 20 | 21 | // original interface 22 | STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj) override; 23 | STDMETHOD_(ULONG, AddRef)() override; 24 | STDMETHOD_(ULONG, Release)() override; 25 | STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice) override; 26 | STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) override; 27 | STDMETHOD(GetPrivateData)(REFGUID refguid, void* pData, DWORD* pSizeOfData) override; 28 | STDMETHOD(FreePrivateData)(REFGUID refguid) override; 29 | STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew) override; 30 | STDMETHOD_(DWORD, GetPriority)() override; 31 | STDMETHOD_(void, PreLoad)() override; 32 | STDMETHOD_(D3DRESOURCETYPE, GetType)() override; 33 | STDMETHOD_(DWORD, SetLOD)(DWORD LODNew) override; 34 | STDMETHOD_(DWORD, GetLOD)() override; 35 | STDMETHOD_(DWORD, GetLevelCount)() override; 36 | STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType) override; 37 | STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)() override; 38 | STDMETHOD_(void, GenerateMipSubLevels)() override; 39 | 40 | STDMETHOD(AddDirtyRect)(D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) override; 41 | STDMETHOD(GetLevelDesc)(UINT Level, D3DSURFACE_DESC* pDesc) override; 42 | STDMETHOD(GetCubeMapSurface)(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) override; 43 | STDMETHOD(LockRect)(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect, DWORD Flags) override; 44 | STDMETHOD(UnlockRect)(D3DCUBEMAP_FACES FaceType, UINT Level) override; 45 | 46 | 47 | [[nodiscard]] HashTuple GetHash() const; 48 | }; 49 | -------------------------------------------------------------------------------- /header/uMod_IDirect3DDevice9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "uMod_IDirect3DTexture9.h" 5 | #include "uMod_IDirect3DVolumeTexture9.h" 6 | #include "uMod_IDirect3DCubeTexture9.h" 7 | 8 | class TextureClient; 9 | 10 | class uMod_IDirect3DDevice9 : public IDirect3DDevice9 { 11 | public: 12 | uMod_IDirect3DDevice9(IDirect3DDevice9* pOriginal, int back_buffer_count); 13 | virtual ~uMod_IDirect3DDevice9(); 14 | 15 | // START: The original DX9 function definitions 16 | HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) override; 17 | ULONG __stdcall AddRef() override; 18 | ULONG __stdcall Release() override; 19 | HRESULT __stdcall TestCooperativeLevel() override; 20 | UINT __stdcall GetAvailableTextureMem() override; 21 | HRESULT __stdcall EvictManagedResources() override; 22 | HRESULT __stdcall GetDirect3D(IDirect3D9** ppD3D9) override; 23 | HRESULT __stdcall GetDeviceCaps(D3DCAPS9* pCaps) override; 24 | HRESULT __stdcall GetDisplayMode(UINT iSwapChain, D3DDISPLAYMODE* pMode) override; 25 | HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS* pParameters) override; 26 | HRESULT __stdcall SetCursorProperties(UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) override; 27 | void __stdcall SetCursorPosition(int X, int Y, DWORD Flags) override; 28 | BOOL __stdcall ShowCursor(BOOL bShow) override; 29 | HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) override; 30 | HRESULT __stdcall GetSwapChain(UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) override; 31 | UINT __stdcall GetNumberOfSwapChains() override; 32 | HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters) override; 33 | HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect, HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) override; 34 | HRESULT __stdcall GetBackBuffer(UINT iSwapChain, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) override; 35 | HRESULT __stdcall GetRasterStatus(UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) override; 36 | HRESULT __stdcall SetDialogBoxMode(BOOL bEnableDialogs) override; 37 | void __stdcall SetGammaRamp(UINT iSwapChain, DWORD Flags,CONST D3DGAMMARAMP* pRamp) override; 38 | void __stdcall GetGammaRamp(UINT iSwapChain, D3DGAMMARAMP* pRamp) override; 39 | HRESULT __stdcall CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) override; 40 | HRESULT __stdcall CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) override; 41 | HRESULT __stdcall CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) override; 42 | HRESULT __stdcall CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) override; 43 | HRESULT __stdcall CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) override; 44 | HRESULT __stdcall CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override; 45 | HRESULT __stdcall CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override; 46 | HRESULT __stdcall UpdateSurface(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint) override; 47 | HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) override; 48 | HRESULT __stdcall GetRenderTargetData(IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) override; 49 | HRESULT __stdcall GetFrontBufferData(UINT iSwapChain, IDirect3DSurface9* pDestSurface) override; 50 | HRESULT __stdcall StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) override; 51 | HRESULT __stdcall ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect, D3DCOLOR color) override; 52 | HRESULT __stdcall CreateOffscreenPlainSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override; 53 | HRESULT __stdcall SetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) override; 54 | HRESULT __stdcall GetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget) override; 55 | HRESULT __stdcall SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil) override; 56 | HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface) override; 57 | HRESULT __stdcall BeginScene() override; 58 | HRESULT __stdcall EndScene() override; 59 | HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) override; 60 | HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) override; 61 | HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) override; 62 | HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) override; 63 | HRESULT __stdcall SetViewport(CONST D3DVIEWPORT9* pViewport) override; 64 | HRESULT __stdcall GetViewport(D3DVIEWPORT9* pViewport) override; 65 | HRESULT __stdcall SetMaterial(CONST D3DMATERIAL9* pMaterial) override; 66 | HRESULT __stdcall GetMaterial(D3DMATERIAL9* pMaterial) override; 67 | HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT9* pLight) override; 68 | HRESULT __stdcall GetLight(DWORD Index, D3DLIGHT9* pLight) override; 69 | HRESULT __stdcall LightEnable(DWORD Index, BOOL Enable) override; 70 | HRESULT __stdcall GetLightEnable(DWORD Index, BOOL* pEnable) override; 71 | HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane) override; 72 | HRESULT __stdcall GetClipPlane(DWORD Index, float* pPlane) override; 73 | HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) override; 74 | HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State, DWORD* pValue) override; 75 | HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB) override; 76 | HRESULT __stdcall BeginStateBlock() override; 77 | HRESULT __stdcall EndStateBlock(IDirect3DStateBlock9** ppSB) override; 78 | HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS9* pClipStatus) override; 79 | HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS9* pClipStatus) override; 80 | HRESULT __stdcall GetTexture(DWORD Stage, IDirect3DBaseTexture9** ppTexture) override; 81 | HRESULT __stdcall SetTexture(DWORD Stage, IDirect3DBaseTexture9* pTexture) override; 82 | HRESULT __stdcall GetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) override; 83 | HRESULT __stdcall SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) override; 84 | HRESULT __stdcall GetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) override; 85 | HRESULT __stdcall SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) override; 86 | HRESULT __stdcall ValidateDevice(DWORD* pNumPasses) override; 87 | HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries) override; 88 | HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY* pEntries) override; 89 | HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber) override; 90 | HRESULT __stdcall GetCurrentTexturePalette(UINT* PaletteNumber) override; 91 | HRESULT __stdcall SetScissorRect(CONST RECT* pRect) override; 92 | HRESULT __stdcall GetScissorRect(RECT* pRect) override; 93 | HRESULT __stdcall SetSoftwareVertexProcessing(BOOL bSoftware) override; 94 | BOOL __stdcall GetSoftwareVertexProcessing() override; 95 | HRESULT __stdcall SetNPatchMode(float nSegments) override; 96 | float __stdcall GetNPatchMode() override; 97 | HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) override; 98 | HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) override; 99 | HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) override; 100 | HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT PrimitiveCount,CONST void* pIndexData, D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData, 101 | UINT VertexStreamZeroStride) override; 102 | HRESULT __stdcall ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) override; 103 | HRESULT __stdcall CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) override; 104 | HRESULT __stdcall SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl) override; 105 | HRESULT __stdcall GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl) override; 106 | HRESULT __stdcall SetFVF(DWORD FVF) override; 107 | HRESULT __stdcall GetFVF(DWORD* pFVF) override; 108 | HRESULT __stdcall CreateVertexShader(CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) override; 109 | HRESULT __stdcall SetVertexShader(IDirect3DVertexShader9* pShader) override; 110 | HRESULT __stdcall GetVertexShader(IDirect3DVertexShader9** ppShader) override; 111 | HRESULT __stdcall SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData, UINT Vector4fCount) override; 112 | HRESULT __stdcall GetVertexShaderConstantF(UINT StartRegister, float* pConstantData, UINT Vector4fCount) override; 113 | HRESULT __stdcall SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData, UINT Vector4iCount) override; 114 | HRESULT __stdcall GetVertexShaderConstantI(UINT StartRegister, int* pConstantData, UINT Vector4iCount) override; 115 | HRESULT __stdcall SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData, UINT BoolCount) override; 116 | HRESULT __stdcall GetVertexShaderConstantB(UINT StartRegister, BOOL* pConstantData, UINT BoolCount) override; 117 | HRESULT __stdcall SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) override; 118 | HRESULT __stdcall GetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9** ppStreamData, UINT* OffsetInBytes, UINT* pStride) override; 119 | HRESULT __stdcall SetStreamSourceFreq(UINT StreamNumber, UINT Divider) override; 120 | HRESULT __stdcall GetStreamSourceFreq(UINT StreamNumber, UINT* Divider) override; 121 | HRESULT __stdcall SetIndices(IDirect3DIndexBuffer9* pIndexData) override; 122 | HRESULT __stdcall GetIndices(IDirect3DIndexBuffer9** ppIndexData) override; 123 | HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) override; 124 | HRESULT __stdcall SetPixelShader(IDirect3DPixelShader9* pShader) override; 125 | HRESULT __stdcall GetPixelShader(IDirect3DPixelShader9** ppShader) override; 126 | HRESULT __stdcall SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData, UINT Vector4fCount) override; 127 | HRESULT __stdcall GetPixelShaderConstantF(UINT StartRegister, float* pConstantData, UINT Vector4fCount) override; 128 | HRESULT __stdcall SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData, UINT Vector4iCount) override; 129 | HRESULT __stdcall GetPixelShaderConstantI(UINT StartRegister, int* pConstantData, UINT Vector4iCount) override; 130 | HRESULT __stdcall SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData, UINT BoolCount) override; 131 | HRESULT __stdcall GetPixelShaderConstantB(UINT StartRegister, BOOL* pConstantData, UINT BoolCount) override; 132 | HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) override; 133 | HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) override; 134 | HRESULT __stdcall DeletePatch(UINT Handle) override; 135 | HRESULT __stdcall CreateQuery(D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) override; 136 | // END: The original DX9 function definitions 137 | 138 | TextureClient* GetuMod_Client() { return uMod_Client; } 139 | 140 | uMod_IDirect3DTexture9* GetLastCreatedTexture() { return LastCreatedTexture; } 141 | 142 | void SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture) 143 | { 144 | LastCreatedTexture = pTexture; 145 | } 146 | 147 | uMod_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture() { return LastCreatedVolumeTexture; } 148 | 149 | void SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture) 150 | { 151 | LastCreatedVolumeTexture = pTexture; 152 | } 153 | 154 | uMod_IDirect3DCubeTexture9* GetLastCreatedCubeTexture() { return LastCreatedCubeTexture; } 155 | 156 | void SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture) 157 | { 158 | LastCreatedCubeTexture = pTexture; 159 | } 160 | 161 | private: 162 | IDirect3DDevice9* m_pIDirect3DDevice9 = nullptr; 163 | 164 | int BackBufferCount; 165 | bool NormalRendering = true; 166 | int uMod_Reference = 1; 167 | 168 | uMod_IDirect3DTexture9* LastCreatedTexture = nullptr; 169 | uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture = nullptr; 170 | uMod_IDirect3DCubeTexture9* LastCreatedCubeTexture = nullptr; 171 | 172 | TextureClient* uMod_Client; 173 | }; 174 | -------------------------------------------------------------------------------- /header/uMod_IDirect3DDevice9Ex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "uMod_IDirect3DTexture9.h" 5 | #include "uMod_IDirect3DVolumeTexture9.h" 6 | #include "uMod_IDirect3DCubeTexture9.h" 7 | 8 | class TextureClient; 9 | 10 | class uMod_IDirect3DDevice9Ex : public IDirect3DDevice9Ex { 11 | public: 12 | uMod_IDirect3DDevice9Ex(IDirect3DDevice9Ex* pOriginal, int back_buffer_count); 13 | virtual ~uMod_IDirect3DDevice9Ex(); 14 | 15 | // START: The original DX9 function definitions 16 | HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) override; 17 | ULONG __stdcall AddRef() override; 18 | ULONG __stdcall Release() override; 19 | HRESULT __stdcall TestCooperativeLevel() override; 20 | UINT __stdcall GetAvailableTextureMem() override; 21 | HRESULT __stdcall EvictManagedResources() override; 22 | HRESULT __stdcall GetDirect3D(IDirect3D9** ppD3D9) override; 23 | HRESULT __stdcall GetDeviceCaps(D3DCAPS9* pCaps) override; 24 | HRESULT __stdcall GetDisplayMode(UINT iSwapChain, D3DDISPLAYMODE* pMode) override; 25 | HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS* pParameters) override; 26 | HRESULT __stdcall SetCursorProperties(UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) override; 27 | void __stdcall SetCursorPosition(int X, int Y, DWORD Flags) override; 28 | BOOL __stdcall ShowCursor(BOOL bShow) override; 29 | HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) override; 30 | HRESULT __stdcall GetSwapChain(UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) override; 31 | UINT __stdcall GetNumberOfSwapChains() override; 32 | HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters) override; 33 | HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect, HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) override; 34 | HRESULT __stdcall GetBackBuffer(UINT iSwapChain, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) override; 35 | HRESULT __stdcall GetRasterStatus(UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) override; 36 | HRESULT __stdcall SetDialogBoxMode(BOOL bEnableDialogs) override; 37 | void __stdcall SetGammaRamp(UINT iSwapChain, DWORD Flags,CONST D3DGAMMARAMP* pRamp) override; 38 | void __stdcall GetGammaRamp(UINT iSwapChain, D3DGAMMARAMP* pRamp) override; 39 | HRESULT __stdcall CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) override; 40 | HRESULT __stdcall CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) override; 41 | HRESULT __stdcall CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) override; 42 | HRESULT __stdcall CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) override; 43 | HRESULT __stdcall CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) override; 44 | HRESULT __stdcall CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override; 45 | HRESULT __stdcall CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override; 46 | HRESULT __stdcall UpdateSurface(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint) override; 47 | HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) override; 48 | HRESULT __stdcall GetRenderTargetData(IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) override; 49 | HRESULT __stdcall GetFrontBufferData(UINT iSwapChain, IDirect3DSurface9* pDestSurface) override; 50 | HRESULT __stdcall StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) override; 51 | HRESULT __stdcall ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect, D3DCOLOR color) override; 52 | HRESULT __stdcall CreateOffscreenPlainSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override; 53 | HRESULT __stdcall SetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) override; 54 | HRESULT __stdcall GetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget) override; 55 | HRESULT __stdcall SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil) override; 56 | HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface) override; 57 | HRESULT __stdcall BeginScene() override; 58 | HRESULT __stdcall EndScene() override; 59 | HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) override; 60 | HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) override; 61 | HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) override; 62 | HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) override; 63 | HRESULT __stdcall SetViewport(CONST D3DVIEWPORT9* pViewport) override; 64 | HRESULT __stdcall GetViewport(D3DVIEWPORT9* pViewport) override; 65 | HRESULT __stdcall SetMaterial(CONST D3DMATERIAL9* pMaterial) override; 66 | HRESULT __stdcall GetMaterial(D3DMATERIAL9* pMaterial) override; 67 | HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT9* pLight) override; 68 | HRESULT __stdcall GetLight(DWORD Index, D3DLIGHT9* pLight) override; 69 | HRESULT __stdcall LightEnable(DWORD Index, BOOL Enable) override; 70 | HRESULT __stdcall GetLightEnable(DWORD Index, BOOL* pEnable) override; 71 | HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane) override; 72 | HRESULT __stdcall GetClipPlane(DWORD Index, float* pPlane) override; 73 | HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) override; 74 | HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State, DWORD* pValue) override; 75 | HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB) override; 76 | HRESULT __stdcall BeginStateBlock() override; 77 | HRESULT __stdcall EndStateBlock(IDirect3DStateBlock9** ppSB) override; 78 | HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS9* pClipStatus) override; 79 | HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS9* pClipStatus) override; 80 | HRESULT __stdcall GetTexture(DWORD Stage, IDirect3DBaseTexture9** ppTexture) override; 81 | HRESULT __stdcall SetTexture(DWORD Stage, IDirect3DBaseTexture9* pTexture) override; 82 | HRESULT __stdcall GetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) override; 83 | HRESULT __stdcall SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) override; 84 | HRESULT __stdcall GetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) override; 85 | HRESULT __stdcall SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) override; 86 | HRESULT __stdcall ValidateDevice(DWORD* pNumPasses) override; 87 | HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries) override; 88 | HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY* pEntries) override; 89 | HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber) override; 90 | HRESULT __stdcall GetCurrentTexturePalette(UINT* PaletteNumber) override; 91 | HRESULT __stdcall SetScissorRect(CONST RECT* pRect) override; 92 | HRESULT __stdcall GetScissorRect(RECT* pRect) override; 93 | HRESULT __stdcall SetSoftwareVertexProcessing(BOOL bSoftware) override; 94 | BOOL __stdcall GetSoftwareVertexProcessing() override; 95 | HRESULT __stdcall SetNPatchMode(float nSegments) override; 96 | float __stdcall GetNPatchMode() override; 97 | HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) override; 98 | HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) override; 99 | HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) override; 100 | HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT PrimitiveCount,CONST void* pIndexData, D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData, 101 | UINT VertexStreamZeroStride) override; 102 | HRESULT __stdcall ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) override; 103 | HRESULT __stdcall CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) override; 104 | HRESULT __stdcall SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl) override; 105 | HRESULT __stdcall GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl) override; 106 | HRESULT __stdcall SetFVF(DWORD FVF) override; 107 | HRESULT __stdcall GetFVF(DWORD* pFVF) override; 108 | HRESULT __stdcall CreateVertexShader(CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) override; 109 | HRESULT __stdcall SetVertexShader(IDirect3DVertexShader9* pShader) override; 110 | HRESULT __stdcall GetVertexShader(IDirect3DVertexShader9** ppShader) override; 111 | HRESULT __stdcall SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData, UINT Vector4fCount) override; 112 | HRESULT __stdcall GetVertexShaderConstantF(UINT StartRegister, float* pConstantData, UINT Vector4fCount) override; 113 | HRESULT __stdcall SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData, UINT Vector4iCount) override; 114 | HRESULT __stdcall GetVertexShaderConstantI(UINT StartRegister, int* pConstantData, UINT Vector4iCount) override; 115 | HRESULT __stdcall SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData, UINT BoolCount) override; 116 | HRESULT __stdcall GetVertexShaderConstantB(UINT StartRegister, BOOL* pConstantData, UINT BoolCount) override; 117 | HRESULT __stdcall SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) override; 118 | HRESULT __stdcall GetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9** ppStreamData, UINT* OffsetInBytes, UINT* pStride) override; 119 | HRESULT __stdcall SetStreamSourceFreq(UINT StreamNumber, UINT Divider) override; 120 | HRESULT __stdcall GetStreamSourceFreq(UINT StreamNumber, UINT* Divider) override; 121 | HRESULT __stdcall SetIndices(IDirect3DIndexBuffer9* pIndexData) override; 122 | HRESULT __stdcall GetIndices(IDirect3DIndexBuffer9** ppIndexData) override; 123 | HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) override; 124 | HRESULT __stdcall SetPixelShader(IDirect3DPixelShader9* pShader) override; 125 | HRESULT __stdcall GetPixelShader(IDirect3DPixelShader9** ppShader) override; 126 | HRESULT __stdcall SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData, UINT Vector4fCount) override; 127 | HRESULT __stdcall GetPixelShaderConstantF(UINT StartRegister, float* pConstantData, UINT Vector4fCount) override; 128 | HRESULT __stdcall SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData, UINT Vector4iCount) override; 129 | HRESULT __stdcall GetPixelShaderConstantI(UINT StartRegister, int* pConstantData, UINT Vector4iCount) override; 130 | HRESULT __stdcall SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData, UINT BoolCount) override; 131 | HRESULT __stdcall GetPixelShaderConstantB(UINT StartRegister, BOOL* pConstantData, UINT BoolCount) override; 132 | HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) override; 133 | HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) override; 134 | HRESULT __stdcall DeletePatch(UINT Handle) override; 135 | HRESULT __stdcall CreateQuery(D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) override; 136 | 137 | 138 | 139 | HRESULT __stdcall CheckDeviceState(HWND hWindow) override; 140 | HRESULT __stdcall CheckResourceResidency(IDirect3DResource9** pResourceArray, UINT32 NumResources) override; 141 | HRESULT __stdcall ComposeRects(IDirect3DSurface9* pSource, IDirect3DSurface9* pDestination, IDirect3DVertexBuffer9* pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9* pDstRectDescriptors, D3DCOMPOSERECTSOP Operation, INT XOffset, 142 | INT YOffset) override; 143 | HRESULT __stdcall CreateDepthStencilSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) override; 144 | HRESULT __stdcall CreateOffscreenPlainSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) override; 145 | HRESULT __stdcall CreateRenderTargetEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) override; 146 | HRESULT __stdcall GetDisplayModeEx(UINT iSwapChain, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) override; 147 | HRESULT __stdcall GetGPUThreadPriority(INT* pPriority) override; 148 | HRESULT __stdcall GetMaximumFrameLatency(UINT* pMaxLatency) override; 149 | HRESULT __stdcall PresentEx(const RECT* pSourceRect, const RECT* pDestRect, HWND hDestWindowOverride, const RGNDATA* pDirtyRegion, DWORD dwFlags) override; 150 | HRESULT __stdcall ResetEx(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode) override; 151 | HRESULT __stdcall SetConvolutionMonoKernel(UINT Width, UINT Height, float* RowWeights, float* ColumnWeights) override; 152 | HRESULT __stdcall SetGPUThreadPriority(INT pPriority) override; 153 | HRESULT __stdcall SetMaximumFrameLatency(UINT pMaxLatency) override; 154 | //HRESULT __stdcall TestCooperativeLevel(); 155 | HRESULT __stdcall WaitForVBlank(UINT SwapChainIndex) override; 156 | 157 | 158 | // END: The original DX9 function definitions 159 | 160 | TextureClient* GetuMod_Client() { return uMod_Client; } 161 | 162 | uMod_IDirect3DTexture9* GetLastCreatedTexture() { return LastCreatedTexture; } 163 | 164 | void SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture) 165 | { 166 | LastCreatedTexture = pTexture; 167 | } 168 | 169 | uMod_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture() { return LastCreatedVolumeTexture; } 170 | 171 | void SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture) 172 | { 173 | LastCreatedVolumeTexture = pTexture; 174 | } 175 | 176 | uMod_IDirect3DCubeTexture9* GetLastCreatedCubeTexture() { return LastCreatedCubeTexture; } 177 | 178 | void SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture) 179 | { 180 | LastCreatedCubeTexture = pTexture; 181 | } 182 | 183 | private: 184 | IDirect3DDevice9Ex* m_pIDirect3DDevice9Ex; 185 | 186 | int BackBufferCount; 187 | bool NormalRendering = true; 188 | 189 | int uMod_Reference = 1; 190 | 191 | uMod_IDirect3DTexture9* LastCreatedTexture = nullptr; 192 | uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture = nullptr; 193 | uMod_IDirect3DCubeTexture9* LastCreatedCubeTexture = nullptr; 194 | 195 | TextureClient* uMod_Client = nullptr; 196 | }; 197 | -------------------------------------------------------------------------------- /header/uMod_IDirect3DTexture9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Defines.h" 5 | 6 | struct TextureFileStruct; 7 | interface uMod_IDirect3DTexture9 : IDirect3DTexture9 { 8 | uMod_IDirect3DTexture9(IDirect3DTexture9** ppTex, IDirect3DDevice9* pIDirect3DDevice9) 9 | : m_D3Dtex(*ppTex), 10 | m_D3Ddev(pIDirect3DDevice9) 11 | {} 12 | 13 | virtual ~uMod_IDirect3DTexture9() = default; 14 | 15 | // callback interface 16 | IDirect3DTexture9* m_D3Dtex = nullptr; 17 | uMod_IDirect3DTexture9* CrossRef_D3Dtex = nullptr; 18 | IDirect3DDevice9* m_D3Ddev = nullptr; 19 | TextureFileStruct* Reference = nullptr; 20 | HashTuple Hash = {}; 21 | bool FAKE = false; 22 | 23 | // original interface 24 | STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj) override; 25 | STDMETHOD_(ULONG, AddRef)() override; 26 | STDMETHOD_(ULONG, Release)() override; 27 | STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice) override; 28 | STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) override; 29 | STDMETHOD(GetPrivateData)(REFGUID refguid, void* pData, DWORD* pSizeOfData) override; 30 | STDMETHOD(FreePrivateData)(REFGUID refguid) override; 31 | STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew) override; 32 | STDMETHOD_(DWORD, GetPriority)() override; 33 | STDMETHOD_(void, PreLoad)() override; 34 | STDMETHOD_(D3DRESOURCETYPE, GetType)() override; 35 | STDMETHOD_(DWORD, SetLOD)(DWORD LODNew) override; 36 | STDMETHOD_(DWORD, GetLOD)() override; 37 | STDMETHOD_(DWORD, GetLevelCount)() override; 38 | STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType) override; 39 | STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)() override; 40 | STDMETHOD_(void, GenerateMipSubLevels)() override; 41 | STDMETHOD(GetLevelDesc)(UINT Level, D3DSURFACE_DESC* pDesc) override; 42 | STDMETHOD(GetSurfaceLevel)(UINT Level, IDirect3DSurface9** ppSurfaceLevel) override; 43 | STDMETHOD(LockRect)(UINT Level, D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect, DWORD Flags) override; 44 | STDMETHOD(UnlockRect)(UINT Level) override; 45 | STDMETHOD(AddDirtyRect)(CONST RECT* pDirtyRect) override; 46 | 47 | [[nodiscard]] HashTuple GetHash() const; 48 | }; 49 | -------------------------------------------------------------------------------- /header/uMod_IDirect3DVolumeTexture9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | interface uMod_IDirect3DVolumeTexture9 : IDirect3DVolumeTexture9 { 6 | uMod_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9** ppTex, IDirect3DDevice9* pIDirect3DDevice9) 7 | : m_D3Dtex(*ppTex), 8 | m_D3Ddev(pIDirect3DDevice9) 9 | {} 10 | 11 | virtual ~uMod_IDirect3DVolumeTexture9() = default; 12 | 13 | // callback interface 14 | IDirect3DVolumeTexture9* m_D3Dtex = nullptr; 15 | uMod_IDirect3DVolumeTexture9* CrossRef_D3Dtex = nullptr; 16 | IDirect3DDevice9* m_D3Ddev = nullptr; 17 | TextureFileStruct* Reference = nullptr; 18 | HashTuple Hash = {}; 19 | bool FAKE = false; 20 | 21 | // original interface 22 | STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj) override; 23 | STDMETHOD_(ULONG, AddRef)() override; 24 | STDMETHOD_(ULONG, Release)() override; 25 | STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice) override; 26 | STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) override; 27 | STDMETHOD(GetPrivateData)(REFGUID refguid, void* pData, DWORD* pSizeOfData) override; 28 | STDMETHOD(FreePrivateData)(REFGUID refguid) override; 29 | STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew) override; 30 | STDMETHOD_(DWORD, GetPriority)() override; 31 | STDMETHOD_(void, PreLoad)() override; 32 | STDMETHOD_(D3DRESOURCETYPE, GetType)() override; 33 | STDMETHOD_(DWORD, SetLOD)(DWORD LODNew) override; 34 | STDMETHOD_(DWORD, GetLOD)() override; 35 | STDMETHOD_(DWORD, GetLevelCount)() override; 36 | STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType) override; 37 | STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)() override; 38 | STDMETHOD_(void, GenerateMipSubLevels)() override; 39 | STDMETHOD(AddDirtyBox)(CONST D3DBOX* pDirtyBox) override; 40 | STDMETHOD(GetLevelDesc)(UINT Level, D3DVOLUME_DESC* pDesc) override; 41 | STDMETHOD(GetVolumeLevel)(UINT Level, IDirect3DVolume9** ppVolumeLevel) override; 42 | STDMETHOD(LockBox)(UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) override; 43 | STDMETHOD(UnlockBox)(UINT Level) override; 44 | 45 | 46 | [[nodiscard]] HashTuple GetHash() const; 47 | }; 48 | -------------------------------------------------------------------------------- /modules/ModfileLoader.ixx: -------------------------------------------------------------------------------- 1 | module; 2 | 3 | #include "Main.h" 4 | #include "Defines.h" 5 | 6 | export module ModfileLoader; 7 | 8 | import std; 9 | import ; 10 | import ModfileLoader.TpfReader; 11 | import TextureFunction; 12 | 13 | namespace { 14 | bool use_64_bit_crc = false; 15 | 16 | HashType GetCrcFromFilename(const std::string& filename) { 17 | const static std::regex re(R"(0x[0-9a-f]{4,16})", std::regex::optimize | std::regex::icase); 18 | std::smatch match; 19 | if (!std::regex_search(filename, match, re)) { 20 | return 0; 21 | } 22 | 23 | uint64_t crc64_hash = 0; 24 | const auto number_str = match.str(); 25 | try { 26 | crc64_hash = std::stoull(number_str, nullptr, 16); 27 | } 28 | catch (const std::invalid_argument&) { 29 | Warning("Failed to parse %s as a hash\n", filename.c_str()); 30 | return 0; 31 | } 32 | catch (const std::out_of_range&) { 33 | Warning("Out of range while parsing %s as a hash\n", filename.c_str()); 34 | return 0; 35 | } 36 | use_64_bit_crc = use_64_bit_crc || crc64_hash > 0xFFFFFFFF; 37 | return crc64_hash; 38 | } 39 | } 40 | 41 | namespace HashCheck { 42 | export bool Use64BitCrc() { 43 | return use_64_bit_crc; 44 | } 45 | } 46 | 47 | export class ModfileLoader { 48 | std::filesystem::path file_name; 49 | const std::string TPF_PASSWORD{ 50 | 0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, static_cast(0xA6), static_cast(0xBD), 51 | 0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F, 52 | 0x74, 0x61, 0x67, 0x5B, 0x60, 0x70, 0x45, 0x74, 53 | 0x5C, 0x22, 0x74, 0x5D, 0x6E, 0x6A, 0x73, 0x41, 54 | 0x77, 0x6E, 0x46, 0x47, 0x77, 0x49, 0x0C, 0x4B, 55 | 0x46, 0x6F 56 | }; 57 | 58 | public: 59 | ModfileLoader(const std::filesystem::path& fileName); 60 | 61 | std::vector GetContents() const; 62 | 63 | private: 64 | 65 | std::vector GetTpfContents() const; 66 | 67 | std::vector GetFileContents() const; 68 | 69 | static void LoadEntries(libzippp::ZipArchive& archive, std::vector& entries); 70 | }; 71 | 72 | ModfileLoader::ModfileLoader(const std::filesystem::path& fileName) 73 | { 74 | file_name = std::filesystem::absolute(fileName); 75 | } 76 | 77 | std::vector ModfileLoader::GetContents() const 78 | { 79 | try { 80 | return file_name.wstring().ends_with(L".tpf") ? GetTpfContents() : GetFileContents(); 81 | } 82 | catch (const std::exception&) { 83 | Warning("Failed to open mod file: %s\n", file_name.c_str()); 84 | } 85 | return {}; 86 | } 87 | 88 | std::vector ModfileLoader::GetTpfContents() const 89 | { 90 | std::vector entries; 91 | auto tpf_reader = TpfReader(file_name); 92 | const auto buffer = tpf_reader.ReadToEnd(); 93 | const auto zip_archive = libzippp::ZipArchive::fromBuffer(buffer.data(), buffer.size(), false, TPF_PASSWORD); 94 | if (!zip_archive) { 95 | Warning("Failed to open tpf file: %s - %u bytes!", file_name.c_str(), buffer.size()); 96 | return {}; 97 | } 98 | zip_archive->setErrorHandlerCallback( 99 | [](const std::string& message, const std::string& strerror, int zip_error_code, int system_error_code) -> void { 100 | Message("GetTpfContents: %s %s %d %d\n", message.c_str(), strerror.c_str(), zip_error_code, system_error_code); 101 | }); 102 | zip_archive->open(); 103 | LoadEntries(*zip_archive, entries); 104 | zip_archive->close(); 105 | libzippp::ZipArchive::free(zip_archive); 106 | 107 | return entries; 108 | } 109 | 110 | std::vector ModfileLoader::GetFileContents() const 111 | { 112 | std::vector entries; 113 | 114 | libzippp::ZipArchive zip_archive(file_name.string()); 115 | zip_archive.open(); 116 | LoadEntries(zip_archive, entries); 117 | zip_archive.close(); 118 | 119 | return entries; 120 | } 121 | 122 | void ParseSimpleArchive(const libzippp::ZipArchive& archive, std::vector& entries) 123 | { 124 | for (const auto& entry : archive.getEntries()) { 125 | if (!entry.isFile()) 126 | continue; 127 | const auto crc_hash = GetCrcFromFilename(entry.getName()); 128 | if (!crc_hash) 129 | continue; 130 | const auto data_ptr = static_cast(entry.readAsBinary()); 131 | const auto size = entry.getSize(); 132 | std::vector vec(data_ptr, data_ptr + size); 133 | std::filesystem::path tex_name(entry.getName()); 134 | entries.emplace_back(std::move(vec), crc_hash, tex_name.extension().string()); 135 | delete[] data_ptr; 136 | } 137 | } 138 | 139 | void ParseTexmodArchive(std::vector& lines, libzippp::ZipArchive& archive, std::vector& entries) 140 | { 141 | for (const auto& line : lines) { 142 | // 0xC57D73F7|GW.EXE_0xC57D73F7.tga\r\n 143 | // match[1] | match[2] 144 | const static auto address_file_regex = std::regex(R"(^[\\/.]*([^|]+)\|([^\r\n]+))", std::regex::optimize); 145 | std::smatch match; 146 | if (!std::regex_search(line, match, address_file_regex)) 147 | continue; 148 | const auto address_string = match[1].str(); 149 | const auto file_path = match[2].str(); 150 | 151 | const auto crc_hash = GetCrcFromFilename(address_string); 152 | if (!crc_hash) 153 | continue; 154 | 155 | const auto entry = archive.getEntry(file_path); 156 | if (entry.isNull() || !entry.isFile()) 157 | continue; 158 | 159 | const auto data_ptr = static_cast(entry.readAsBinary()); 160 | const auto size = static_cast(entry.getSize()); 161 | std::vector vec(data_ptr, data_ptr + size); 162 | const auto tex_name = std::filesystem::path(entry.getName()); 163 | entries.emplace_back(std::move(vec), crc_hash, tex_name.extension().string()); 164 | delete[] data_ptr; 165 | } 166 | } 167 | 168 | void ModfileLoader::LoadEntries(libzippp::ZipArchive& archive, std::vector& entries) 169 | { 170 | const auto def_file = archive.getEntry("texmod.def"); 171 | if (def_file.isNull() || !def_file.isFile()) { 172 | ParseSimpleArchive(archive, entries); 173 | } 174 | else { 175 | const auto def = def_file.readAsText(); 176 | std::istringstream iss(def); 177 | std::vector lines; 178 | std::string line; 179 | 180 | while (std::getline(iss, line)) { 181 | lines.push_back(line); 182 | } 183 | 184 | ParseTexmodArchive(lines, archive, entries); 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /modules/ModfileLoader_TpfReader.ixx: -------------------------------------------------------------------------------- 1 | export module ModfileLoader.TpfReader; 2 | 3 | import std; 4 | 5 | export class TpfReader { 6 | public: 7 | TpfReader(const std::filesystem::path& path) 8 | { 9 | file_stream = std::ifstream(path, std::ios::binary); 10 | if (!file_stream.seekg(0, std::ios::end).good() || !file_stream.seekg(0, std::ios::beg).good()) { 11 | throw std::invalid_argument("Provided stream needs to have SEEK set to True"); 12 | } 13 | } 14 | 15 | ~TpfReader() 16 | { 17 | file_stream.close(); 18 | } 19 | 20 | std::vector ReadToEnd() 21 | { 22 | file_stream.seekg(0, std::ios::end); 23 | line_length = file_stream.tellg(); 24 | file_stream.seekg(0, std::ios::beg); // Go to the beginning of the stream 25 | 26 | std::vector data(static_cast(line_length)); 27 | file_stream.read(data.data(), line_length); 28 | for (auto i = 0u; i < data.size(); i++) { 29 | data[i] = XOR(data[i], i); 30 | } 31 | 32 | for (auto i = data.size() - 1; i > 0 && data[i] != 0; i--) { 33 | data[i] = 0; 34 | } 35 | 36 | // in the other zip libraries, these had to be cut off, with libzip we need to zero them out 37 | // cutting them off makes the archive invalid 38 | //data.resize(last_zero); 39 | 40 | return data; 41 | } 42 | 43 | private: 44 | std::ifstream file_stream; 45 | std::streamoff line_length = 0; 46 | 47 | [[nodiscard]] char XOR(const char b, const long position) const 48 | { 49 | if (position > line_length - 4) { 50 | return b ^ TPF_XOREven; 51 | } 52 | 53 | return position % 2 == 0 ? b ^ TPF_XOREven : b ^ TPF_XOROdd; 54 | } 55 | 56 | static constexpr char TPF_XOROdd = 0x3F; 57 | static constexpr char TPF_XOREven = static_cast(0xA4); 58 | }; 59 | -------------------------------------------------------------------------------- /modules/TextureClient.ixx: -------------------------------------------------------------------------------- 1 | module; 2 | 3 | #include "Main.h" 4 | #include "Error.h" 5 | #include "uMod_IDirect3DTexture9.h" 6 | #include 7 | #include 8 | 9 | export module TextureClient; 10 | import TextureFunction; 11 | import ModfileLoader; 12 | 13 | export std::vector> modlists_contents; 14 | /* 15 | * An object of this class is owned by each d3d9 device. 16 | * All other functions are called from the render thread instance of the game itself. 17 | */ 18 | export class TextureClient { 19 | public: 20 | TextureClient(IDirect3DDevice9* device); 21 | ~TextureClient(); 22 | 23 | int AddTexture(uModTexturePtr auto pTexture); 24 | int RemoveTexture(uModTexturePtr auto pTexture); //called from uMod_IDirect3DTexture9::Release() 25 | int LookUpToMod(uModTexturePtr auto pTexture); 26 | // called at the end AddTexture(...) and from Device->UpdateTexture(...) 27 | 28 | int MergeUpdate(); //called from uMod_IDirect3DDevice9::BeginScene() 29 | void Initialize(); 30 | 31 | std::vector OriginalTextures; 32 | // stores the pointer to the uMod_IDirect3DTexture9 objects created by the game 33 | std::vector OriginalVolumeTextures; 34 | // stores the pointer to the uMod_IDirect3DVolumeTexture9 objects created by the game 35 | std::vector OriginalCubeTextures; 36 | // stores the pointer to the uMod_IDirect3DCubeTexture9 objects created by the game 37 | 38 | private: 39 | IDirect3DDevice9* D3D9Device; 40 | // Cached info about whether this id a dx9ex device or not; used for proxy functions 41 | bool isDirectXExDevice = false; 42 | 43 | // DX9 proxy functions 44 | void SetLastCreatedTexture(uMod_IDirect3DTexture9*); 45 | void SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9*); 46 | void SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9*); 47 | 48 | bool should_update = false; 49 | 50 | int LockMutex(); 51 | int UnlockMutex(); 52 | HANDLE hMutex; 53 | 54 | std::unordered_map> modded_textures; 55 | // array which stores the file in memory and the hash of each texture to be modded 56 | 57 | // called if a target texture is found 58 | int LoadTexture(TextureFileStruct* file_in_memory, uModTexturePtrPtr auto ppTexture); 59 | 60 | void LoadModsFromModlist(std::pair modfile_tuple); 61 | std::filesystem::path dll_path; // path to gmod dll 62 | }; 63 | 64 | TextureClient::TextureClient(IDirect3DDevice9* device) 65 | { 66 | Message("TextureClient::TextureClient(): %p\n", this); 67 | D3D9Device = device; 68 | 69 | void* cpy; 70 | isDirectXExDevice = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy) == 0x01000001L; 71 | 72 | hMutex = CreateMutex(nullptr, false, nullptr); 73 | } 74 | 75 | TextureClient::~TextureClient() 76 | { 77 | Message("TextureClient::~TextureClient(): %p\n", this); 78 | if (hMutex != nullptr) { 79 | CloseHandle(hMutex); 80 | } 81 | for (const auto texture_file_struct : modded_textures | std::views::values) { 82 | delete texture_file_struct; 83 | } 84 | modded_textures.clear(); 85 | } 86 | 87 | int TextureClient::MergeUpdate() 88 | { 89 | if (!should_update) return RETURN_OK; 90 | should_update = false; 91 | if (const int ret = LockMutex()) { 92 | gl_ErrorState |= uMod_ERROR_TEXTURE; 93 | return ret; 94 | } 95 | 96 | Message("MergeUpdate(): %p\n", this); 97 | 98 | for (const auto pTexture : OriginalTextures) { 99 | if (pTexture->CrossRef_D3Dtex == nullptr) { 100 | LookUpToMod(pTexture); 101 | } 102 | } 103 | for (const auto pTexture : OriginalVolumeTextures) { 104 | if (pTexture->CrossRef_D3Dtex == nullptr) { 105 | LookUpToMod(pTexture); 106 | } 107 | } 108 | for (const auto pTexture : OriginalCubeTextures) { 109 | if (pTexture->CrossRef_D3Dtex == nullptr) { 110 | LookUpToMod(pTexture); 111 | } 112 | } 113 | 114 | return UnlockMutex(); 115 | } 116 | 117 | void TextureClient::SetLastCreatedTexture(uMod_IDirect3DTexture9* texture) 118 | { 119 | if (isDirectXExDevice) 120 | return static_cast(D3D9Device)->SetLastCreatedTexture(texture); 121 | return static_cast(D3D9Device)->SetLastCreatedTexture(texture); 122 | } 123 | 124 | void TextureClient::SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* texture) 125 | { 126 | if (isDirectXExDevice) 127 | return static_cast(D3D9Device)->SetLastCreatedVolumeTexture(texture); 128 | return static_cast(D3D9Device)->SetLastCreatedVolumeTexture(texture); 129 | } 130 | 131 | void TextureClient::SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* texture) 132 | { 133 | if (isDirectXExDevice) 134 | return static_cast(D3D9Device)->SetLastCreatedCubeTexture(texture); 135 | return static_cast(D3D9Device)->SetLastCreatedCubeTexture(texture); 136 | } 137 | 138 | int TextureClient::LockMutex() 139 | { 140 | if ((gl_ErrorState & (uMod_ERROR_FATAL | uMod_ERROR_MUTEX))) { 141 | return RETURN_NO_MUTEX; 142 | } 143 | if (WAIT_OBJECT_0 != WaitForSingleObject(hMutex, 100)) { 144 | return RETURN_MUTEX_LOCK; //waiting 100ms, to wait infinite pass INFINITE 145 | } 146 | return RETURN_OK; 147 | } 148 | 149 | int TextureClient::UnlockMutex() 150 | { 151 | if (ReleaseMutex(hMutex) == 0) { 152 | return RETURN_MUTEX_UNLOCK; 153 | } 154 | return RETURN_OK; 155 | } 156 | 157 | gsl::owner AddFile(TexEntry& entry, const bool compress, const std::filesystem::path& dll_path) 158 | { 159 | const auto texture_file_struct = new TextureFileStruct(); 160 | texture_file_struct->crc_hash = entry.crc_hash; 161 | const auto dds_blob = TextureFunction::ConvertToCompressedDDS(entry, compress, dll_path); 162 | texture_file_struct->data.assign(static_cast(dds_blob.GetBufferPointer()), static_cast(dds_blob.GetBufferPointer()) + dds_blob.GetBufferSize()); 163 | return texture_file_struct; 164 | } 165 | 166 | std::vector> ProcessModfile(const std::filesystem::path& modfile, const std::filesystem::path& dll_path, const bool compress) 167 | { 168 | const auto hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 169 | if (FAILED(hr)) return {}; 170 | Message("Initialize: loading file %s... ", modfile.c_str()); 171 | auto file_loader = ModfileLoader(modfile); 172 | auto entries = file_loader.GetContents(); 173 | if (entries.empty()) { 174 | Message("No entries found.\n"); 175 | return {}; 176 | } 177 | Message("%zu textures... ", entries.size()); 178 | std::vector> texture_file_structs; 179 | texture_file_structs.reserve(entries.size()); 180 | unsigned file_bytes_loaded = 0; 181 | for (auto& tpf_entry : entries) { 182 | const auto tex_file_struct = AddFile(tpf_entry, compress, dll_path); 183 | texture_file_structs.push_back(tex_file_struct); 184 | file_bytes_loaded += texture_file_structs.back()->data.size(); 185 | } 186 | entries.clear(); 187 | Message("%d bytes loaded.\n", file_bytes_loaded); 188 | CoUninitialize(); 189 | return texture_file_structs; 190 | } 191 | 192 | void TextureClient::LoadModsFromModlist(std::pair modfile_tuple) 193 | { 194 | static std::vector loaded_modfiles{}; 195 | 196 | std::locale::global(std::locale("")); 197 | std::istringstream file(modfile_tuple.second); 198 | std::string line; 199 | std::vector modfiles; 200 | while (std::getline(file, line)) { 201 | // Remove newline character 202 | line.erase(std::ranges::remove(line, '\r').begin(), line.end()); 203 | line.erase(std::ranges::remove(line, '\n').begin(), line.end()); 204 | 205 | const auto wline = utils::utf8_to_wstring(line); 206 | const auto fsline = std::filesystem::path(wline); 207 | 208 | if (!std::ranges::contains(loaded_modfiles, fsline)) { 209 | modfiles.push_back(fsline); 210 | loaded_modfiles.push_back(fsline); 211 | } 212 | } 213 | auto files_size = 0ull; 214 | for (const auto modfile : modfiles) { 215 | if (std::filesystem::exists(modfile)) { 216 | files_size += std::filesystem::file_size(modfile); 217 | } 218 | } 219 | std::vector>>> futures; 220 | for (const auto modfile : modfiles) { 221 | futures.emplace_back(std::async(std::launch::async, ProcessModfile, modfile, dll_path, files_size > 400'000'000)); 222 | } 223 | auto loaded_size = 0u; 224 | for (auto& future : futures) { 225 | const auto texture_file_structs = future.get(); 226 | for (const auto texture_file_struct : texture_file_structs) { 227 | if (!texture_file_struct->crc_hash) continue; 228 | if (!modded_textures.contains(texture_file_struct->crc_hash)) { 229 | modded_textures.emplace(texture_file_struct->crc_hash, texture_file_struct); 230 | loaded_size += texture_file_struct->data.size(); 231 | } 232 | else { 233 | delete texture_file_struct; 234 | } 235 | } 236 | should_update = true; 237 | } 238 | Message("Finished loading mods from %s: Loaded %u bytes (%u mb)", modfile_tuple.first.c_str(), loaded_size, loaded_size / 1024 / 1024); 239 | } 240 | 241 | void TextureClient::Initialize() 242 | { 243 | const auto t1 = std::chrono::high_resolution_clock::now(); 244 | Info("Initialize: begin\n"); 245 | for (const auto& modlists_content : modlists_contents) { 246 | LoadModsFromModlist(modlists_content); 247 | } 248 | const auto t2 = std::chrono::high_resolution_clock::now(); 249 | const auto ms = duration_cast(t2 - t1); 250 | Info("Initialize: end, took %d ms\n", ms); 251 | } 252 | 253 | int TextureClient::AddTexture(uModTexturePtr auto pTexture) 254 | { 255 | if constexpr (std::same_as) { 256 | SetLastCreatedTexture(nullptr); 257 | } 258 | else if constexpr (std::same_as) { 259 | SetLastCreatedVolumeTexture(nullptr); 260 | } 261 | else if constexpr (std::same_as) { 262 | SetLastCreatedCubeTexture(nullptr); 263 | } 264 | 265 | if (pTexture->FAKE) { 266 | return RETURN_OK; // this is a fake texture 267 | } 268 | 269 | if (gl_ErrorState & uMod_ERROR_FATAL) { 270 | return RETURN_FATAL_ERROR; 271 | } 272 | 273 | Message("TextureClient::AddTexture( Cube: %p): %p (thread: %u)\n", pTexture, this, GetCurrentThreadId()); 274 | 275 | pTexture->Hash = pTexture->GetHash(); 276 | if (!pTexture->Hash) { 277 | return RETURN_FATAL_ERROR; 278 | } 279 | 280 | if constexpr (std::same_as) { 281 | OriginalTextures.push_back(pTexture); 282 | } 283 | else if constexpr (std::same_as) { 284 | OriginalVolumeTextures.push_back(pTexture); 285 | } 286 | else if constexpr (std::same_as) { 287 | OriginalCubeTextures.push_back(pTexture); 288 | } 289 | 290 | return LookUpToMod(pTexture); // check if this texture should be modded 291 | } 292 | 293 | int TextureClient::RemoveTexture(uModTexturePtr auto pTexture) 294 | { 295 | Message("TextureClient::RemoveTexture( %p, %#lX): %p\n", pTexture, pTexture->Hash, this); 296 | 297 | if (gl_ErrorState & uMod_ERROR_FATAL) { 298 | return RETURN_FATAL_ERROR; 299 | } 300 | 301 | if (!pTexture->FAKE) { 302 | if constexpr (std::same_as) { 303 | utils::erase_first(OriginalTextures, pTexture); 304 | } 305 | else if constexpr (std::same_as) { 306 | utils::erase_first(OriginalVolumeTextures, pTexture); 307 | } 308 | else if constexpr (std::same_as) { 309 | utils::erase_first(OriginalCubeTextures, pTexture); 310 | } 311 | } 312 | if (!pTexture->Reference) 313 | return RETURN_OK; // Should this ever happen? 314 | return RETURN_OK; 315 | } 316 | 317 | int TextureClient::LookUpToMod(uModTexturePtr auto pTexture) 318 | { 319 | Message("TextureClient::LookUpToMod( %p): hash: %#lX, %p\n", pTexture, pTexture->Hash, this); 320 | int ret = RETURN_OK; 321 | 322 | if (pTexture->CrossRef_D3Dtex != nullptr) 323 | return ret; // bug, this texture is already switched 324 | 325 | auto found = modded_textures.find(pTexture->Hash.crc32); 326 | if (found == modded_textures.end()) 327 | if (found = modded_textures.find(pTexture->Hash.crc64), !pTexture->Hash.crc64 || found == modded_textures.end()) 328 | return ret; 329 | 330 | const auto textureFileStruct = found->second; 331 | 332 | decltype(pTexture) fake_Texture; 333 | ret = LoadTexture(textureFileStruct, &fake_Texture); 334 | if (ret != RETURN_OK) 335 | return ret; 336 | 337 | ret = SwitchTextures(fake_Texture, pTexture); 338 | if (ret != RETURN_OK) { 339 | Message("TextureClient::LookUpToMod(): textures not switched %#lX\n", textureFileStruct->crc_hash); 340 | fake_Texture->Release(); 341 | return ret; 342 | } 343 | fake_Texture->Reference = textureFileStruct; 344 | return ret; 345 | } 346 | 347 | int TextureClient::LoadTexture(TextureFileStruct* file_in_memory, uModTexturePtrPtr auto ppTexture) 348 | { 349 | Message("LoadTexture( %p, %p, %#lX): %p\n", file_in_memory, ppTexture, file_in_memory->crc_hash, this); 350 | if (const auto ret = DirectX::CreateDDSTextureFromMemoryEx( 351 | D3D9Device, 352 | file_in_memory->data.data(), 353 | file_in_memory->data.size(), 354 | 0, D3DPOOL_MANAGED, false, 355 | reinterpret_cast(ppTexture)); ret != D3D_OK) { 356 | *ppTexture = nullptr; 357 | Warning("LoadDDSTexture (%p, %#lX): FAILED ret: \n", file_in_memory->data.data(), file_in_memory->crc_hash, ret); 358 | return RETURN_TEXTURE_NOT_LOADED; 359 | } 360 | if constexpr (std::same_as) { 361 | SetLastCreatedTexture(nullptr); 362 | } 363 | else if constexpr (std::same_as) { 364 | SetLastCreatedVolumeTexture(nullptr); 365 | } 366 | else if constexpr (std::same_as) { 367 | SetLastCreatedCubeTexture(nullptr); 368 | } 369 | (*ppTexture)->FAKE = true; 370 | 371 | Message("LoadTexture (%p, %#lX): DONE\n", *ppTexture, file_in_memory->crc_hash); 372 | return RETURN_OK; 373 | } 374 | -------------------------------------------------------------------------------- /modules/TextureFunction.ixx: -------------------------------------------------------------------------------- 1 | module; 2 | 3 | #include "Main.h" 4 | #include 5 | #include 6 | 7 | export module TextureFunction; 8 | 9 | export template 10 | concept uModTexturePtr = requires(T a) 11 | { 12 | std::same_as || 13 | std::same_as || 14 | std::same_as; 15 | }; 16 | 17 | export template 18 | concept uModTexturePtrPtr = uModTexturePtr>; 19 | 20 | export template requires uModTexturePtr 21 | void UnswitchTextures(T pTexture) 22 | { 23 | decltype(pTexture) CrossRef = pTexture->CrossRef_D3Dtex; 24 | if (CrossRef != nullptr) { 25 | std::swap(pTexture->m_D3Dtex, CrossRef->m_D3Dtex); 26 | 27 | // cancel the link 28 | CrossRef->CrossRef_D3Dtex = nullptr; 29 | pTexture->CrossRef_D3Dtex = nullptr; 30 | } 31 | } 32 | 33 | export template requires uModTexturePtr 34 | int SwitchTextures(T pTexture1, T pTexture2) 35 | { 36 | if (pTexture1->m_D3Ddev == pTexture2->m_D3Ddev && pTexture1->CrossRef_D3Dtex == nullptr && pTexture2->CrossRef_D3Dtex == nullptr) { 37 | // make cross reference 38 | pTexture1->CrossRef_D3Dtex = pTexture2; 39 | pTexture2->CrossRef_D3Dtex = pTexture1; 40 | 41 | // switch textures 42 | std::swap(pTexture1->m_D3Dtex, pTexture2->m_D3Dtex); 43 | return RETURN_OK; 44 | } 45 | return RETURN_TEXTURE_NOT_SWITCHED; 46 | } 47 | 48 | constexpr auto crctab64 = std::to_array({ 49 | 0x0000000000000000ULL, 0x7ad870c830358979ULL, 0xf5b0e190606b12f2ULL, 50 | 0x8f689158505e9b8bULL, 0xc038e5739841b68fULL, 0xbae095bba8743ff6ULL, 51 | 0x358804e3f82aa47dULL, 0x4f50742bc81f2d04ULL, 0xab28ecb46814fe75ULL, 52 | 0xd1f09c7c5821770cULL, 0x5e980d24087fec87ULL, 0x24407dec384a65feULL, 53 | 0x6b1009c7f05548faULL, 0x11c8790fc060c183ULL, 0x9ea0e857903e5a08ULL, 54 | 0xe478989fa00bd371ULL, 0x7d08ff3b88be6f81ULL, 0x07d08ff3b88be6f8ULL, 55 | 0x88b81eabe8d57d73ULL, 0xf2606e63d8e0f40aULL, 0xbd301a4810ffd90eULL, 56 | 0xc7e86a8020ca5077ULL, 0x4880fbd87094cbfcULL, 0x32588b1040a14285ULL, 57 | 0xd620138fe0aa91f4ULL, 0xacf86347d09f188dULL, 0x2390f21f80c18306ULL, 58 | 0x594882d7b0f40a7fULL, 0x1618f6fc78eb277bULL, 0x6cc0863448deae02ULL, 59 | 0xe3a8176c18803589ULL, 0x997067a428b5bcf0ULL, 0xfa11fe77117cdf02ULL, 60 | 0x80c98ebf2149567bULL, 0x0fa11fe77117cdf0ULL, 0x75796f2f41224489ULL, 61 | 0x3a291b04893d698dULL, 0x40f16bccb908e0f4ULL, 0xcf99fa94e9567b7fULL, 62 | 0xb5418a5cd963f206ULL, 0x513912c379682177ULL, 0x2be1620b495da80eULL, 63 | 0xa489f35319033385ULL, 0xde51839b2936bafcULL, 0x9101f7b0e12997f8ULL, 64 | 0xebd98778d11c1e81ULL, 0x64b116208142850aULL, 0x1e6966e8b1770c73ULL, 65 | 0x8719014c99c2b083ULL, 0xfdc17184a9f739faULL, 0x72a9e0dcf9a9a271ULL, 66 | 0x08719014c99c2b08ULL, 0x4721e43f0183060cULL, 0x3df994f731b68f75ULL, 67 | 0xb29105af61e814feULL, 0xc849756751dd9d87ULL, 0x2c31edf8f1d64ef6ULL, 68 | 0x56e99d30c1e3c78fULL, 0xd9810c6891bd5c04ULL, 0xa3597ca0a188d57dULL, 69 | 0xec09088b6997f879ULL, 0x96d1784359a27100ULL, 0x19b9e91b09fcea8bULL, 70 | 0x636199d339c963f2ULL, 0xdf7adabd7a6e2d6fULL, 0xa5a2aa754a5ba416ULL, 71 | 0x2aca3b2d1a053f9dULL, 0x50124be52a30b6e4ULL, 0x1f423fcee22f9be0ULL, 72 | 0x659a4f06d21a1299ULL, 0xeaf2de5e82448912ULL, 0x902aae96b271006bULL, 73 | 0x74523609127ad31aULL, 0x0e8a46c1224f5a63ULL, 0x81e2d7997211c1e8ULL, 74 | 0xfb3aa75142244891ULL, 0xb46ad37a8a3b6595ULL, 0xceb2a3b2ba0eececULL, 75 | 0x41da32eaea507767ULL, 0x3b024222da65fe1eULL, 0xa2722586f2d042eeULL, 76 | 0xd8aa554ec2e5cb97ULL, 0x57c2c41692bb501cULL, 0x2d1ab4dea28ed965ULL, 77 | 0x624ac0f56a91f461ULL, 0x1892b03d5aa47d18ULL, 0x97fa21650afae693ULL, 78 | 0xed2251ad3acf6feaULL, 0x095ac9329ac4bc9bULL, 0x7382b9faaaf135e2ULL, 79 | 0xfcea28a2faafae69ULL, 0x8632586aca9a2710ULL, 0xc9622c4102850a14ULL, 80 | 0xb3ba5c8932b0836dULL, 0x3cd2cdd162ee18e6ULL, 0x460abd1952db919fULL, 81 | 0x256b24ca6b12f26dULL, 0x5fb354025b277b14ULL, 0xd0dbc55a0b79e09fULL, 82 | 0xaa03b5923b4c69e6ULL, 0xe553c1b9f35344e2ULL, 0x9f8bb171c366cd9bULL, 83 | 0x10e3202993385610ULL, 0x6a3b50e1a30ddf69ULL, 0x8e43c87e03060c18ULL, 84 | 0xf49bb8b633338561ULL, 0x7bf329ee636d1eeaULL, 0x012b592653589793ULL, 85 | 0x4e7b2d0d9b47ba97ULL, 0x34a35dc5ab7233eeULL, 0xbbcbcc9dfb2ca865ULL, 86 | 0xc113bc55cb19211cULL, 0x5863dbf1e3ac9decULL, 0x22bbab39d3991495ULL, 87 | 0xadd33a6183c78f1eULL, 0xd70b4aa9b3f20667ULL, 0x985b3e827bed2b63ULL, 88 | 0xe2834e4a4bd8a21aULL, 0x6debdf121b863991ULL, 0x1733afda2bb3b0e8ULL, 89 | 0xf34b37458bb86399ULL, 0x8993478dbb8deae0ULL, 0x06fbd6d5ebd3716bULL, 90 | 0x7c23a61ddbe6f812ULL, 0x3373d23613f9d516ULL, 0x49aba2fe23cc5c6fULL, 91 | 0xc6c333a67392c7e4ULL, 0xbc1b436e43a74e9dULL, 0x95ac9329ac4bc9b5ULL, 92 | 0xef74e3e19c7e40ccULL, 0x601c72b9cc20db47ULL, 0x1ac40271fc15523eULL, 93 | 0x5594765a340a7f3aULL, 0x2f4c0692043ff643ULL, 0xa02497ca54616dc8ULL, 94 | 0xdafce7026454e4b1ULL, 0x3e847f9dc45f37c0ULL, 0x445c0f55f46abeb9ULL, 95 | 0xcb349e0da4342532ULL, 0xb1eceec59401ac4bULL, 0xfebc9aee5c1e814fULL, 96 | 0x8464ea266c2b0836ULL, 0x0b0c7b7e3c7593bdULL, 0x71d40bb60c401ac4ULL, 97 | 0xe8a46c1224f5a634ULL, 0x927c1cda14c02f4dULL, 0x1d148d82449eb4c6ULL, 98 | 0x67ccfd4a74ab3dbfULL, 0x289c8961bcb410bbULL, 0x5244f9a98c8199c2ULL, 99 | 0xdd2c68f1dcdf0249ULL, 0xa7f41839ecea8b30ULL, 0x438c80a64ce15841ULL, 100 | 0x3954f06e7cd4d138ULL, 0xb63c61362c8a4ab3ULL, 0xcce411fe1cbfc3caULL, 101 | 0x83b465d5d4a0eeceULL, 0xf96c151de49567b7ULL, 0x76048445b4cbfc3cULL, 102 | 0x0cdcf48d84fe7545ULL, 0x6fbd6d5ebd3716b7ULL, 0x15651d968d029fceULL, 103 | 0x9a0d8ccedd5c0445ULL, 0xe0d5fc06ed698d3cULL, 0xaf85882d2576a038ULL, 104 | 0xd55df8e515432941ULL, 0x5a3569bd451db2caULL, 0x20ed197575283bb3ULL, 105 | 0xc49581ead523e8c2ULL, 0xbe4df122e51661bbULL, 0x3125607ab548fa30ULL, 106 | 0x4bfd10b2857d7349ULL, 0x04ad64994d625e4dULL, 0x7e7514517d57d734ULL, 107 | 0xf11d85092d094cbfULL, 0x8bc5f5c11d3cc5c6ULL, 0x12b5926535897936ULL, 108 | 0x686de2ad05bcf04fULL, 0xe70573f555e26bc4ULL, 0x9ddd033d65d7e2bdULL, 109 | 0xd28d7716adc8cfb9ULL, 0xa85507de9dfd46c0ULL, 0x273d9686cda3dd4bULL, 110 | 0x5de5e64efd965432ULL, 0xb99d7ed15d9d8743ULL, 0xc3450e196da80e3aULL, 111 | 0x4c2d9f413df695b1ULL, 0x36f5ef890dc31cc8ULL, 0x79a59ba2c5dc31ccULL, 112 | 0x037deb6af5e9b8b5ULL, 0x8c157a32a5b7233eULL, 0xf6cd0afa9582aa47ULL, 113 | 0x4ad64994d625e4daULL, 0x300e395ce6106da3ULL, 0xbf66a804b64ef628ULL, 114 | 0xc5bed8cc867b7f51ULL, 0x8aeeace74e645255ULL, 0xf036dc2f7e51db2cULL, 115 | 0x7f5e4d772e0f40a7ULL, 0x05863dbf1e3ac9deULL, 0xe1fea520be311aafULL, 116 | 0x9b26d5e88e0493d6ULL, 0x144e44b0de5a085dULL, 0x6e963478ee6f8124ULL, 117 | 0x21c640532670ac20ULL, 0x5b1e309b16452559ULL, 0xd476a1c3461bbed2ULL, 118 | 0xaeaed10b762e37abULL, 0x37deb6af5e9b8b5bULL, 0x4d06c6676eae0222ULL, 119 | 0xc26e573f3ef099a9ULL, 0xb8b627f70ec510d0ULL, 0xf7e653dcc6da3dd4ULL, 120 | 0x8d3e2314f6efb4adULL, 0x0256b24ca6b12f26ULL, 0x788ec2849684a65fULL, 121 | 0x9cf65a1b368f752eULL, 0xe62e2ad306bafc57ULL, 0x6946bb8b56e467dcULL, 122 | 0x139ecb4366d1eea5ULL, 0x5ccebf68aecec3a1ULL, 0x2616cfa09efb4ad8ULL, 123 | 0xa97e5ef8cea5d153ULL, 0xd3a62e30fe90582aULL, 0xb0c7b7e3c7593bd8ULL, 124 | 0xca1fc72bf76cb2a1ULL, 0x45775673a732292aULL, 0x3faf26bb9707a053ULL, 125 | 0x70ff52905f188d57ULL, 0x0a2722586f2d042eULL, 0x854fb3003f739fa5ULL, 126 | 0xff97c3c80f4616dcULL, 0x1bef5b57af4dc5adULL, 0x61372b9f9f784cd4ULL, 127 | 0xee5fbac7cf26d75fULL, 0x9487ca0fff135e26ULL, 0xdbd7be24370c7322ULL, 128 | 0xa10fceec0739fa5bULL, 0x2e675fb4576761d0ULL, 0x54bf2f7c6752e8a9ULL, 129 | 0xcdcf48d84fe75459ULL, 0xb71738107fd2dd20ULL, 0x387fa9482f8c46abULL, 130 | 0x42a7d9801fb9cfd2ULL, 0x0df7adabd7a6e2d6ULL, 0x772fdd63e7936bafULL, 131 | 0xf8474c3bb7cdf024ULL, 0x829f3cf387f8795dULL, 0x66e7a46c27f3aa2cULL, 132 | 0x1c3fd4a417c62355ULL, 0x935745fc4798b8deULL, 0xe98f353477ad31a7ULL, 133 | 0xa6df411fbfb21ca3ULL, 0xdc0731d78f8795daULL, 0x536fa08fdfd90e51ULL, 134 | 0x29b7d047efec8728ULL 135 | }); 136 | 137 | export namespace TextureFunction { 138 | 139 | uint64_t get_crc64(const char* data, unsigned int length) { 140 | uint64_t crc = 0xFFFFFFFFFFFFFFFFULL; 141 | 142 | while (length--) { 143 | crc = crctab64[(crc ^ *data++) & 0xFF] ^ (crc >> 8); 144 | } 145 | 146 | return crc; 147 | } 148 | 149 | uint32_t get_crc32(const char* data_ptr, const unsigned int length) 150 | { 151 | constexpr static auto crc32_poly = 0xEDB88320u; 152 | constexpr static auto ul_crc_in = 0xffffffff; 153 | unsigned int crc = ul_crc_in; 154 | for (unsigned int idx = 0u; idx < length; idx++) { 155 | unsigned int data = *data_ptr++; 156 | for (unsigned int bit = 0u; bit < 8u; bit++, data >>= 1) { 157 | crc = crc >> 1 ^ ((crc ^ data) & 1 ? crc32_poly : 0); 158 | } 159 | } 160 | return crc; 161 | } 162 | 163 | int GetBitsFromFormat(D3DFORMAT format) 164 | { 165 | switch (format) //switch trough the formats to calculate the size of the raw data 166 | { 167 | case D3DFMT_A1: // 1-bit monochrome. 168 | { 169 | return 1; 170 | } 171 | 172 | case D3DFMT_R3G3B2: // 8-bit RGB texture format using 3 bits for red, 3 bits for green, and 2 bits for blue. 173 | case D3DFMT_A8: // 8-bit alpha only. 174 | case D3DFMT_A8P8: // 8-bit color indexed with 8 bits of alpha. 175 | case D3DFMT_P8: // 8-bit color indexed. 176 | case D3DFMT_L8: // 8-bit luminance only. 177 | case D3DFMT_A4L4: // 8-bit using 4 bits each for alpha and luminance. 178 | case D3DFMT_FORCE_DWORD: 179 | case D3DFMT_S8_LOCKABLE: // A lockable 8-bit stencil buffer. 180 | { 181 | return 8; 182 | } 183 | 184 | case D3DFMT_D16_LOCKABLE: //16-bit z-buffer bit depth. 185 | case D3DFMT_D15S1: // 16-bit z-buffer bit depth where 15 bits are reserved for the depth channel and 1 bit is reserved for the stencil channel. 186 | case D3DFMT_L6V5U5: // 16-bit bump-map format with luminance using 6 bits for luminance, and 5 bits each for v and u. 187 | case D3DFMT_V8U8: // 16-bit bump-map format using 8 bits each for u and v data. 188 | case D3DFMT_CxV8U8: // 16-bit normal compression format. The texture sampler computes the C channel from: C = sqrt(1 - U2 - V2). 189 | case D3DFMT_R5G6B5: // 16-bit RGB pixel format with 5 bits for red, 6 bits for green, and 5 bits for blue. 190 | case D3DFMT_X1R5G5B5: // 16-bit pixel format where 5 bits are reserved for each color. 191 | case D3DFMT_A1R5G5B5: // 16-bit pixel format where 5 bits are reserved for each color and 1 bit is reserved for alpha. 192 | case D3DFMT_A4R4G4B4: // 16-bit ARGB pixel format with 4 bits for each channel. 193 | case D3DFMT_A8R3G3B2: // 16-bit ARGB texture format using 8 bits for alpha, 3 bits each for red and green, and 2 bits for blue. 194 | case D3DFMT_X4R4G4B4: // 16-bit RGB pixel format using 4 bits for each color. 195 | case D3DFMT_L16: // 16-bit luminance only. 196 | case D3DFMT_R16F: // 16-bit float format using 16 bits for the red channel. 197 | case D3DFMT_A8L8: // 16-bit using 8 bits each for alpha and luminance. 198 | case D3DFMT_D16: // 16-bit z-buffer bit depth. 199 | case D3DFMT_INDEX16: // 16-bit index buffer bit depth. 200 | case D3DFMT_G8R8_G8B8: // ?? 201 | case D3DFMT_R8G8_B8G8: // ?? 202 | case D3DFMT_UYVY: // ?? 203 | case D3DFMT_YUY2: // ?? 204 | { 205 | return 16; 206 | } 207 | 208 | 209 | case D3DFMT_R8G8B8: //24-bit RGB pixel format with 8 bits per channel. 210 | { 211 | return 24; 212 | } 213 | 214 | case D3DFMT_R32F: // 32-bit float format using 32 bits for the red channel. 215 | case D3DFMT_X8L8V8U8: // 32-bit bump-map format with luminance using 8 bits for each channel. 216 | case D3DFMT_A2W10V10U10: // 32-bit bump-map format using 2 bits for alpha and 10 bits each for w, v, and u. 217 | case D3DFMT_Q8W8V8U8: // 32-bit bump-map format using 8 bits for each channel. 218 | case D3DFMT_V16U16: // 32-bit bump-map format using 16 bits for each channel. 219 | case D3DFMT_A8R8G8B8: // 32-bit ARGB pixel format with alpha, using 8 bits per channel. 220 | case D3DFMT_X8R8G8B8: // 32-bit RGB pixel format, where 8 bits are reserved for each color. 221 | case D3DFMT_A2B10G10R10: // 32-bit pixel format using 10 bits for each color and 2 bits for alpha. 222 | case D3DFMT_A8B8G8R8: // 32-bit ARGB pixel format with alpha, using 8 bits per channel. 223 | case D3DFMT_X8B8G8R8: // 32-bit RGB pixel format, where 8 bits are reserved for each color. 224 | case D3DFMT_G16R16: // 32-bit pixel format using 16 bits each for green and red. 225 | case D3DFMT_G16R16F: // 32-bit float format using 16 bits for the red channel and 16 bits for the green channel. 226 | case D3DFMT_A2R10G10B10: // 32-bit pixel format using 10 bits each for red, green, and blue, and 2 bits for alpha. 227 | case D3DFMT_D32: // 32-bit z-buffer bit depth. 228 | case D3DFMT_D24S8: // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel. 229 | case D3DFMT_D24X8: //32-bit z-buffer bit depth using 24 bits for the depth channel. 230 | case D3DFMT_D24X4S4: // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel. 231 | case D3DFMT_D32F_LOCKABLE: // A lockable format where the depth value is represented as a standard IEEE floating-point number. 232 | case D3DFMT_D24FS8: // A non-lockable format that contains 24 bits of depth (in a 24-bit floating point format - 20e4) and 8 bits of stencil. 233 | case D3DFMT_D32_LOCKABLE: // A lockable 32-bit depth buffer. 234 | case D3DFMT_INDEX32: // 32-bit index buffer bit depth. 235 | { 236 | return 32; 237 | } 238 | 239 | case D3DFMT_G32R32F: // 64-bit float format using 32 bits for the red channel and 32 bits for the green channel. 240 | case D3DFMT_Q16W16V16U16: // 64-bit bump-map format using 16 bits for each component. 241 | case D3DFMT_A16B16G16R16: // 64-bit pixel format using 16 bits for each component. 242 | case D3DFMT_A16B16G16R16F: // 64-bit float format using 16 bits for the each channel (alpha, blue, green, red). 243 | { 244 | return 64; 245 | } 246 | 247 | case D3DFMT_A32B32G32R32F: // 128-bit float format using 32 bits for the each channel (alpha, blue, green, red). 248 | { 249 | return 128; 250 | } 251 | case D3DFMT_DXT2: 252 | case D3DFMT_DXT3: 253 | case D3DFMT_DXT4: 254 | case D3DFMT_DXT5: { 255 | return 8; 256 | } 257 | case D3DFMT_DXT1: { 258 | return 4; 259 | } 260 | default: //compressed formats 261 | { 262 | return 4; 263 | } 264 | } 265 | } 266 | 267 | DirectX::ScratchImage ImageConvertToBGRA(DirectX::ScratchImage& image, const TexEntry& entry) 268 | { 269 | if (image.GetMetadata().format == DXGI_FORMAT_B8G8R8A8_UNORM || 270 | image.GetMetadata().format == DXGI_FORMAT_BC1_UNORM || 271 | image.GetMetadata().format == DXGI_FORMAT_BC2_UNORM || 272 | image.GetMetadata().format == DXGI_FORMAT_BC3_UNORM || 273 | image.GetMetadata().format == DXGI_FORMAT_BC4_UNORM || 274 | image.GetMetadata().format == DXGI_FORMAT_BC5_UNORM) { 275 | return std::move(image); 276 | } 277 | DirectX::ScratchImage bgra_image; 278 | const HRESULT hr = DirectX::Convert( 279 | image.GetImages(), 280 | image.GetImageCount(), 281 | image.GetMetadata(), 282 | DXGI_FORMAT_B8G8R8A8_UNORM, 283 | DirectX::TEX_FILTER_DEFAULT, 284 | DirectX::TEX_THRESHOLD_DEFAULT, 285 | bgra_image); 286 | if (FAILED(hr)) { 287 | Warning("ImageConvertToBGRA (%#lX%s): FAILED\n", entry.crc_hash, entry.ext.c_str()); 288 | bgra_image = std::move(image); 289 | } 290 | image.Release(); 291 | return bgra_image; 292 | } 293 | 294 | DirectX::ScratchImage ImageGenerateMipMaps(DirectX::ScratchImage& image, const TexEntry& entry) 295 | { 296 | if (entry.ext == ".dds") { 297 | return std::move(image); 298 | } 299 | DirectX::ScratchImage mipmapped_image; 300 | const auto hr = DirectX::GenerateMipMaps( 301 | image.GetImages(), 302 | image.GetImageCount(), 303 | image.GetMetadata(), 304 | DirectX::TEX_FILTER_DEFAULT, 305 | 0, 306 | mipmapped_image); 307 | if (FAILED(hr)) { 308 | Warning("GenerateMipMaps (%#lX%s): FAILED\n", entry.crc_hash, entry.ext.c_str()); 309 | mipmapped_image = std::move(image); 310 | } 311 | image.Release(); 312 | return mipmapped_image; 313 | } 314 | 315 | DirectX::ScratchImage ImageCompress(DirectX::ScratchImage& image, const TexEntry& entry) 316 | { 317 | if (image.GetMetadata().format == DXGI_FORMAT_BC1_UNORM || 318 | image.GetMetadata().format == DXGI_FORMAT_BC2_UNORM || 319 | image.GetMetadata().format == DXGI_FORMAT_BC3_UNORM || 320 | image.GetMetadata().format == DXGI_FORMAT_BC4_UNORM || 321 | image.GetMetadata().format == DXGI_FORMAT_BC5_UNORM) { 322 | return std::move(image); 323 | } 324 | DirectX::ScratchImage compressed_image; 325 | const auto hr = DirectX::Compress( 326 | image.GetImages(), 327 | image.GetImageCount(), 328 | image.GetMetadata(), 329 | DXGI_FORMAT_BC3_UNORM, 330 | DirectX::TEX_COMPRESS_DEFAULT, 331 | DirectX::TEX_THRESHOLD_DEFAULT, 332 | compressed_image); 333 | if (FAILED(hr)) { 334 | Warning("ImageCompress (%#lX%s): FAILED\n", entry.crc_hash, entry.ext.c_str()); 335 | compressed_image = std::move(image); 336 | } 337 | image.Release(); 338 | return compressed_image; 339 | } 340 | 341 | void ImageSave(const DirectX::ScratchImage& image, const TexEntry& entry, const std::filesystem::path& dll_path) 342 | { 343 | const auto file_name = std::format("0x{:x}.dds", entry.crc_hash); 344 | const auto file_out = dll_path / "textures" / file_name; 345 | try { 346 | if (std::filesystem::exists(file_out)) { 347 | return; 348 | } 349 | if (!std::filesystem::exists(file_out.parent_path())) { 350 | std::filesystem::create_directory(file_out.parent_path()); 351 | } 352 | const auto hr = DirectX::SaveToDDSFile( 353 | image.GetImages(), 354 | image.GetImageCount(), 355 | image.GetMetadata(), 356 | DirectX::DDS_FLAGS_NONE, 357 | file_out.c_str()); 358 | if (FAILED(hr)) { 359 | Warning("SaveDDSImageToDisk (%#lX%s): FAILED\n", entry.crc_hash, entry.ext.c_str()); 360 | } 361 | } 362 | catch (const std::exception& e) { 363 | Warning("SaveDDSImageToDisk (%#lX%s): %s\n", entry.crc_hash, entry.ext.c_str(), e.what()); 364 | return; 365 | } 366 | } 367 | 368 | DirectX::Blob ConvertToCompressedDDS(TexEntry& entry, const bool compress, [[maybe_unused]] const std::filesystem::path& dll_path) 369 | { 370 | DirectX::ScratchImage image; 371 | HRESULT hr = 0; 372 | 373 | if (entry.ext == ".dds") { 374 | hr = DirectX::LoadFromDDSMemory(entry.data.data(), entry.data.size(), DirectX::DDS_FLAGS_NONE, nullptr, image); 375 | } 376 | else if (entry.ext == ".tga") { 377 | hr = DirectX::LoadFromTGAMemory(entry.data.data(), entry.data.size(), DirectX::TGA_FLAGS_BGR, nullptr, image); 378 | } 379 | else if (entry.ext == ".hdr") { 380 | hr = DirectX::LoadFromHDRMemory(entry.data.data(), entry.data.size(), nullptr, image); 381 | } 382 | else { 383 | hr = DirectX::LoadFromWICMemory(entry.data.data(), entry.data.size(), DirectX::WIC_FLAGS_NONE, nullptr, image); 384 | if (image.GetMetadata().format == DXGI_FORMAT_B8G8R8X8_UNORM) { 385 | image.OverrideFormat(DXGI_FORMAT_B8G8R8A8_UNORM); 386 | } 387 | } 388 | entry.data.clear(); 389 | if (FAILED(hr)) { 390 | Warning("LoadImageFromMemory (%#lX%s): FAILED\n", entry.crc_hash, entry.ext.c_str()); 391 | return {}; 392 | } 393 | 394 | auto bgra_image = ImageConvertToBGRA(image, entry); 395 | auto mipmapped_image = ImageGenerateMipMaps(bgra_image, entry); 396 | const auto compressed_image = compress ? ImageCompress(mipmapped_image, entry) : std::move(mipmapped_image); 397 | 398 | DirectX::Blob dds_blob; 399 | hr = DirectX::SaveToDDSMemory( 400 | compressed_image.GetImages(), 401 | compressed_image.GetImageCount(), 402 | compressed_image.GetMetadata(), 403 | DirectX::DDS_FLAGS_NONE, 404 | dds_blob); 405 | if (FAILED(hr)) { 406 | Warning("SaveDDSImageToMemory (%#lX%s): FAILED\n", entry.crc_hash, entry.ext.c_str()); 407 | return {}; 408 | } 409 | 410 | #ifdef _DEBUG 411 | ImageSave(compressed_image, entry, dll_path); 412 | #endif 413 | return dds_blob; 414 | } 415 | } 416 | -------------------------------------------------------------------------------- /source/Error.cpp: -------------------------------------------------------------------------------- 1 | #include "Error.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | __declspec(noreturn) void FatalAssert( 9 | const char *expr, 10 | const char *file, 11 | unsigned int line, 12 | const char *function) 13 | { 14 | char module_path[MAX_PATH]{}; 15 | if (gl_hThisInstance) { 16 | GetModuleFileName(gl_hThisInstance, module_path, _countof(module_path)); 17 | } 18 | if (!*module_path) { 19 | strcpy_s(module_path, "Unknown"); 20 | } 21 | const char* fmt = "Module: %s\n\nExpr: %s\n\nFile: %s\n\nFunction: %s, line %d"; 22 | int len = snprintf(NULL, 0, fmt, module_path, expr, file, function, line); 23 | char* buf = new char[len + 1]; 24 | snprintf(buf,len + 1, fmt, module_path, expr, file, function, line); 25 | 26 | 27 | MessageBox(0, buf, "uMod Assertion Failure", MB_OK | MB_ICONERROR); 28 | 29 | delete[] buf; 30 | abort(); 31 | } 32 | -------------------------------------------------------------------------------- /source/dll_main.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | #include 3 | #include "MinHook.h" 4 | 5 | import TextureClient; 6 | 7 | void ExitInstance(); 8 | void InitInstance(HINSTANCE hModule); 9 | 10 | namespace { 11 | 12 | #define DISABLE_HOOK(var) if(var) { MH_DisableHook(var);} 13 | 14 | using Direct3DCreate9_type = IDirect3D9* (APIENTRY*)(UINT); 15 | using Direct3DCreate9Ex_type = HRESULT(APIENTRY*)(UINT SDKVersion, IDirect3D9Ex** ppD3D); 16 | using GetProcAddress_type = FARPROC(APIENTRY*)(HMODULE, LPCSTR); 17 | 18 | // Pointer to original address of Direct3DCreate9 19 | Direct3DCreate9_type Direct3DCreate9_ret = nullptr; 20 | 21 | // Pointer to original address of Direct3DCreate9 22 | Direct3DCreate9Ex_type Direct3DCreate9Ex_ret = nullptr; 23 | 24 | GetProcAddress_type GetProcAddress_fn = nullptr; 25 | GetProcAddress_type GetProcAddress_ret = nullptr; 26 | 27 | FILE* stdout_proxy; 28 | FILE* stderr_proxy; 29 | 30 | HMODULE gMod_Loaded_d3d9_Module_Handle = nullptr; 31 | 32 | HMODULE FindLoadedModuleByName(const char* name, bool include_this_module = false) 33 | { 34 | HMODULE hModules[1024]; 35 | HANDLE hProcess; 36 | DWORD cbNeeded; 37 | unsigned int i; 38 | 39 | // Get a handle to the current process. 40 | hProcess = GetCurrentProcess(); 41 | if (!EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded)) 42 | return nullptr; 43 | for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { 44 | if (hModules[i] == gl_hThisInstance && !include_this_module) 45 | continue; 46 | TCHAR szModuleName[MAX_PATH]; 47 | ASSERT(GetModuleFileName(hModules[i], szModuleName, _countof(szModuleName)) > 0); 48 | const auto basename = strrchr(szModuleName, '\\'); 49 | if (basename && _stricmp(basename + 1, name) == 0) 50 | return hModules[i]; 51 | } 52 | return nullptr; 53 | } 54 | 55 | HMODULE LoadD3d9Dll() 56 | { 57 | HMODULE found = FindLoadedModuleByName("d3d9.dll"); 58 | if (!found) { 59 | char executable_path[MAX_PATH]{}; 60 | ASSERT(GetModuleFileName(GetModuleHandle(nullptr), executable_path, _countof(executable_path)) > 0); 61 | 62 | char dll_path[MAX_PATH]{}; 63 | ASSERT(GetModuleFileName(gl_hThisInstance, dll_path, _countof(dll_path)) > 0); 64 | 65 | const auto exe_path = std::filesystem::path(executable_path); 66 | const auto gmod_path = std::filesystem::path(dll_path); 67 | 68 | if (exe_path.parent_path() != gmod_path.parent_path() 69 | || gmod_path.filename() != "d3d9.dll") { 70 | // Call basic LoadLibrary function; we're not in the same directory as the exe. 71 | gMod_Loaded_d3d9_Module_Handle = LoadLibrary("d3d9.dll"); 72 | } 73 | if (!gMod_Loaded_d3d9_Module_Handle) { 74 | // Tried resolving d3d9.dll locally, didn't work. Try system directory 75 | char buffer[MAX_PATH]; 76 | ASSERT(GetSystemDirectory(buffer, _countof(buffer)) > 0); //get the system directory, we need to open the original d3d9.dll 77 | 78 | // Append dll name 79 | strcat_s(buffer, _countof(buffer), "\\d3d9.dll"); 80 | gMod_Loaded_d3d9_Module_Handle = LoadLibrary(buffer); 81 | } 82 | 83 | ASSERT(gMod_Loaded_d3d9_Module_Handle); 84 | 85 | found = FindLoadedModuleByName("d3d9.dll"); 86 | ASSERT(found && found == gMod_Loaded_d3d9_Module_Handle); 87 | } 88 | 89 | DISABLE_HOOK(GetProcAddress_fn); 90 | // GetProcAddress, hooked via OnGetProcAddress 91 | Direct3DCreate9_ret = reinterpret_cast(GetProcAddress(found, "Direct3DCreate9")); 92 | Direct3DCreate9Ex_ret = reinterpret_cast(GetProcAddress(found, "Direct3DCreate9Ex")); 93 | 94 | return found; 95 | } 96 | 97 | FARPROC APIENTRY OnGetProcAddress(HMODULE hModule, LPCSTR lpProcName) 98 | { 99 | ASSERT(GetProcAddress_ret); 100 | if ((int)lpProcName < 0xffff) 101 | return GetProcAddress_ret(hModule, lpProcName); // lpProcName is ordinal offset, not string 102 | 103 | if (strcmp(lpProcName, "Direct3DCreate9") == 0) { 104 | Direct3DCreate9_ret = reinterpret_cast(GetProcAddress_ret(hModule, lpProcName)); 105 | return reinterpret_cast(Direct3DCreate9); 106 | } 107 | if (strcmp(lpProcName, "Direct3DCreate9Ex") == 0) { 108 | Direct3DCreate9Ex_ret = reinterpret_cast(GetProcAddress_ret(hModule, lpProcName)); 109 | return reinterpret_cast(Direct3DCreate9Ex); 110 | } 111 | return GetProcAddress_ret(hModule, lpProcName); 112 | } 113 | 114 | // If the original d3d9 function is nullptr or points to gMod, load the actual d3d9 dll and redirect the addresses 115 | void CheckLoadD3d9Dll() 116 | { 117 | if (!(Direct3DCreate9_ret && Direct3DCreate9_ret != Direct3DCreate9)) { 118 | ASSERT(LoadD3d9Dll()); 119 | ASSERT(Direct3DCreate9_ret && Direct3DCreate9_ret != Direct3DCreate9); 120 | } 121 | if (!(Direct3DCreate9Ex_ret && Direct3DCreate9Ex_ret != Direct3DCreate9Ex)) { 122 | ASSERT(LoadD3d9Dll()); 123 | ASSERT(Direct3DCreate9Ex_ret && Direct3DCreate9Ex_ret != Direct3DCreate9Ex); 124 | } 125 | } 126 | 127 | // There may be a sitation where more than 1 gmod is loaded; avoid recursions! 128 | bool creating_d3d9 = false; 129 | } 130 | 131 | unsigned int gl_ErrorState = 0; 132 | HINSTANCE gl_hThisInstance = nullptr; 133 | 134 | IDirect3D9* APIENTRY Direct3DCreate9(UINT SDKVersion) 135 | { 136 | Message("uMod_Direct3DCreate9: uMod %p\n", Direct3DCreate9); 137 | 138 | ASSERT(!creating_d3d9); 139 | creating_d3d9 = true; 140 | 141 | DISABLE_HOOK(GetProcAddress_fn); 142 | CheckLoadD3d9Dll(); 143 | 144 | IDirect3D9* pIDirect3D9_orig = Direct3DCreate9_ret(SDKVersion); //creating the original IDirect3D9 object 145 | ASSERT(pIDirect3D9_orig); 146 | 147 | creating_d3d9 = false; 148 | 149 | return new uMod_IDirect3D9(pIDirect3D9_orig); //return our object instead of the "real one" 150 | } 151 | 152 | HRESULT APIENTRY Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex** ppD3D) 153 | { 154 | Message("uMod_Direct3DCreate9Ex: uMod %p\n", Direct3DCreate9Ex); 155 | 156 | ASSERT(!creating_d3d9); 157 | creating_d3d9 = true; 158 | 159 | 160 | DISABLE_HOOK(GetProcAddress_fn); 161 | CheckLoadD3d9Dll(); 162 | 163 | IDirect3D9Ex* pIDirect3D9Ex_orig = nullptr; 164 | HRESULT ret = Direct3DCreate9Ex_ret(SDKVersion, &pIDirect3D9Ex_orig); //creating the original IDirect3D9 object 165 | 166 | creating_d3d9 = false; 167 | 168 | if (ret != S_OK) 169 | return ret; 170 | 171 | // @Cleanup: should be we freeing pIDirect3D9Ex at the end of our own lifecycle? 172 | const auto pIDirect3D9Ex = new uMod_IDirect3D9Ex(pIDirect3D9Ex_orig); 173 | // original umod does not do this for some reason 174 | *ppD3D = static_cast(pIDirect3D9Ex); 175 | return ret; 176 | } 177 | 178 | /* 179 | * dll entry routine, here we initialize or clean up 180 | */ 181 | BOOL WINAPI DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 182 | { 183 | UNREFERENCED_PARAMETER(lpReserved); 184 | 185 | switch (ul_reason_for_call) { 186 | case DLL_PROCESS_ATTACH: { 187 | #ifdef _DEBUG 188 | AllocConsole(); 189 | SetConsoleTitleA("gMod Console"); 190 | freopen_s(&stdout_proxy, "CONOUT$", "w", stdout); 191 | freopen_s(&stderr_proxy, "CONOUT$", "w", stderr); 192 | #endif 193 | InitInstance(hModule); 194 | break; 195 | } 196 | case DLL_PROCESS_DETACH: { 197 | ExitInstance(); 198 | break; 199 | } 200 | default: break; 201 | } 202 | 203 | return true; 204 | } 205 | 206 | void LoadModlists() 207 | { 208 | Message("Initialize: searching for modlist.txt\n"); 209 | char gwpath[MAX_PATH]{}; 210 | GetModuleFileName(GetModuleHandle(nullptr), gwpath, MAX_PATH); //ask for name and path of this executable 211 | char dllpath[MAX_PATH]{}; 212 | GetModuleFileName(gl_hThisInstance, dllpath, MAX_PATH); //ask for name and path of this dll 213 | const auto exe_path = std::filesystem::path(gwpath).parent_path(); 214 | const auto dll_path = std::filesystem::path(dllpath).parent_path(); 215 | for (const auto& path : {exe_path, dll_path}) { 216 | const auto modlist = path / "modlist.txt"; 217 | if (std::filesystem::exists(modlist)) { 218 | Message("Initialize: found %s\n", modlist.string().c_str()); 219 | std::ifstream t(modlist, std::ios::binary); 220 | std::stringstream buffer; 221 | buffer << t.rdbuf(); 222 | modlists_contents.emplace_back(modlist.string(), buffer.str()); 223 | } 224 | } 225 | } 226 | 227 | void InitInstance(HINSTANCE hModule) 228 | { 229 | Message("InitInstance: %p\n", hModule); 230 | 231 | // Store the handle to this module 232 | gl_hThisInstance = hModule; 233 | 234 | LoadModlists(); 235 | DisableThreadLibraryCalls(hModule); //reduce overhead 236 | 237 | // d3d9.dll shouldn't be loaded at this point. 238 | [[maybe_unused]] const auto d3d9_loaded = FindLoadedModuleByName("d3d9.dll"); 239 | //ASSERT(!d3d9_loaded); 240 | 241 | MH_Initialize(); 242 | 243 | // Hook into LoadLibraryA - we'll do our hooks on the flip side 244 | GetProcAddress_fn = reinterpret_cast(GetProcAddress); 245 | ASSERT(GetProcAddress_fn); 246 | if (GetProcAddress_fn) { 247 | MH_CreateHook(GetProcAddress_fn, OnGetProcAddress, (void**)&GetProcAddress_ret); 248 | MH_EnableHook(GetProcAddress_fn); 249 | } 250 | } 251 | 252 | void ExitInstance() 253 | { 254 | DISABLE_HOOK(GetProcAddress_fn); 255 | 256 | MH_Uninitialize(); 257 | 258 | if (gMod_Loaded_d3d9_Module_Handle) 259 | FreeLibrary(gMod_Loaded_d3d9_Module_Handle); 260 | 261 | #ifdef _DEBUG 262 | if (stdout_proxy) 263 | fclose(stdout_proxy); 264 | if (stderr_proxy) 265 | fclose(stderr_proxy); 266 | __try { 267 | FreeConsole(); 268 | } 269 | __except (EXCEPTION_CONTINUE_EXECUTION) { } 270 | #endif 271 | } 272 | -------------------------------------------------------------------------------- /source/uMod_IDirect3D9.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | #ifndef PRE_MESSAGE 4 | #define PRE_MESSAGE "uMod_IDirect3D9" 5 | #endif 6 | 7 | uMod_IDirect3D9::uMod_IDirect3D9(IDirect3D9* pOriginal) 8 | { 9 | Message(PRE_MESSAGE "::" PRE_MESSAGE " (%p): %p\n", pOriginal, this); 10 | m_pIDirect3D9 = pOriginal; 11 | } 12 | 13 | uMod_IDirect3D9::~uMod_IDirect3D9() 14 | { 15 | Message(PRE_MESSAGE "::~" PRE_MESSAGE "(): %p\n", this); 16 | } 17 | 18 | HRESULT __stdcall uMod_IDirect3D9::QueryInterface(REFIID riid, void** ppvObj) 19 | { 20 | *ppvObj = nullptr; 21 | 22 | // call this to increase AddRef at original object 23 | // and to check if such an interface is there 24 | 25 | const HRESULT hRes = m_pIDirect3D9->QueryInterface(riid, ppvObj); 26 | 27 | if (hRes == NOERROR) // if OK, send our "fake" address 28 | { 29 | *ppvObj = this; 30 | } 31 | 32 | return hRes; 33 | } 34 | 35 | ULONG __stdcall uMod_IDirect3D9::AddRef() 36 | { 37 | return m_pIDirect3D9->AddRef(); 38 | } 39 | 40 | ULONG __stdcall uMod_IDirect3D9::Release() 41 | { 42 | // call original routine 43 | const ULONG count = m_pIDirect3D9->Release(); 44 | 45 | // in case no further Ref is there, the Original Object has deleted itself 46 | if (count == 0) { 47 | delete this; 48 | } 49 | 50 | return count; 51 | } 52 | 53 | HRESULT __stdcall uMod_IDirect3D9::RegisterSoftwareDevice(void* pInitializeFunction) 54 | { 55 | return m_pIDirect3D9->RegisterSoftwareDevice(pInitializeFunction); 56 | } 57 | 58 | UINT __stdcall uMod_IDirect3D9::GetAdapterCount() 59 | { 60 | return m_pIDirect3D9->GetAdapterCount(); 61 | } 62 | 63 | HRESULT __stdcall uMod_IDirect3D9::GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) 64 | { 65 | return m_pIDirect3D9->GetAdapterIdentifier(Adapter, Flags, pIdentifier); 66 | } 67 | 68 | UINT __stdcall uMod_IDirect3D9::GetAdapterModeCount(UINT Adapter, D3DFORMAT Format) 69 | { 70 | return m_pIDirect3D9->GetAdapterModeCount(Adapter, Format); 71 | } 72 | 73 | HRESULT __stdcall uMod_IDirect3D9::EnumAdapterModes(UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) 74 | { 75 | return m_pIDirect3D9->EnumAdapterModes(Adapter, Format, Mode, pMode); 76 | } 77 | 78 | HRESULT __stdcall uMod_IDirect3D9::GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE* pMode) 79 | { 80 | return m_pIDirect3D9->GetAdapterDisplayMode(Adapter, pMode); 81 | } 82 | 83 | HRESULT __stdcall uMod_IDirect3D9::CheckDeviceType(UINT iAdapter, D3DDEVTYPE DevType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) 84 | { 85 | return m_pIDirect3D9->CheckDeviceType(iAdapter, DevType, DisplayFormat, BackBufferFormat, bWindowed); 86 | } 87 | 88 | HRESULT __stdcall uMod_IDirect3D9::CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) 89 | { 90 | return m_pIDirect3D9->CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); 91 | } 92 | 93 | HRESULT __stdcall uMod_IDirect3D9::CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) 94 | { 95 | return m_pIDirect3D9->CheckDeviceMultiSampleType(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels); 96 | } 97 | 98 | HRESULT __stdcall uMod_IDirect3D9::CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) 99 | { 100 | return m_pIDirect3D9->CheckDepthStencilMatch(Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat); 101 | } 102 | 103 | HRESULT __stdcall uMod_IDirect3D9::CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) 104 | { 105 | return m_pIDirect3D9->CheckDeviceFormatConversion(Adapter, DeviceType, SourceFormat, TargetFormat); 106 | } 107 | 108 | HRESULT __stdcall uMod_IDirect3D9::GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) 109 | { 110 | return m_pIDirect3D9->GetDeviceCaps(Adapter, DeviceType, pCaps); 111 | } 112 | 113 | HMONITOR __stdcall uMod_IDirect3D9::GetAdapterMonitor(UINT Adapter) 114 | { 115 | return m_pIDirect3D9->GetAdapterMonitor(Adapter); 116 | } 117 | 118 | HRESULT __stdcall uMod_IDirect3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface) 119 | { 120 | Message(PRE_MESSAGE "::CreateDevice(): %p\n", this); 121 | // we intercept this call and provide our own "fake" Device Object 122 | const HRESULT hres = m_pIDirect3D9->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface); 123 | 124 | int count = 1; 125 | if (pPresentationParameters != nullptr) { 126 | count = pPresentationParameters->BackBufferCount; 127 | } 128 | const auto pIDirect3DDevice9 = new uMod_IDirect3DDevice9(*ppReturnedDeviceInterface, count); 129 | 130 | // store our pointer (the fake one) for returning it to the calling program 131 | *ppReturnedDeviceInterface = pIDirect3DDevice9; 132 | 133 | return hres; 134 | } 135 | -------------------------------------------------------------------------------- /source/uMod_IDirect3D9Ex.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | #define IDirect3D9 IDirect3D9Ex 4 | #define uMod_IDirect3D9 uMod_IDirect3D9Ex 5 | #define m_pIDirect3D9 m_pIDirect3D9Ex 6 | #define PRE_MESSAGE "uMod_IDirect3D9Ex" 7 | 8 | // ReSharper disable once CppUnusedIncludeDirective 9 | #include "uMod_IDirect3D9.cpp" 10 | 11 | HRESULT __stdcall uMod_IDirect3D9Ex::CreateDeviceEx(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, 12 | IDirect3DDevice9Ex** ppReturnedDeviceInterface) 13 | { 14 | Message("uMod_IDirect3D9Ex::CreateDeviceEx: %p\n", this); 15 | // we intercept this call and provide our own "fake" Device Object 16 | const HRESULT hres = m_pIDirect3D9Ex->CreateDeviceEx(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface); 17 | 18 | int count = 1; 19 | if (pPresentationParameters != nullptr) { 20 | count = pPresentationParameters->BackBufferCount; 21 | } 22 | const auto pIDirect3DDevice9Ex = new uMod_IDirect3DDevice9Ex(*ppReturnedDeviceInterface, count); 23 | 24 | // store our pointer (the fake one) for returning it to the calling program 25 | *ppReturnedDeviceInterface = pIDirect3DDevice9Ex; 26 | 27 | return hres; 28 | } 29 | 30 | HRESULT __stdcall uMod_IDirect3D9Ex::EnumAdapterModesEx(UINT Adapter, const D3DDISPLAYMODEFILTER* pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode) 31 | { 32 | return m_pIDirect3D9Ex->EnumAdapterModesEx(Adapter, pFilter, Mode, pMode); 33 | } 34 | 35 | HRESULT __stdcall uMod_IDirect3D9Ex::GetAdapterDisplayModeEx(UINT Adapter, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) 36 | { 37 | return m_pIDirect3D9Ex->GetAdapterDisplayModeEx(Adapter, pMode, pRotation); 38 | } 39 | 40 | HRESULT __stdcall uMod_IDirect3D9Ex::GetAdapterLUID(UINT Adapter, LUID* pLUID) 41 | { 42 | return m_pIDirect3D9Ex->GetAdapterLUID(Adapter, pLUID); 43 | } 44 | 45 | UINT __stdcall uMod_IDirect3D9Ex::GetAdapterModeCountEx(UINT Adapter, const D3DDISPLAYMODEFILTER* pFilter) 46 | { 47 | return m_pIDirect3D9Ex->GetAdapterModeCountEx(Adapter, pFilter); 48 | } 49 | -------------------------------------------------------------------------------- /source/uMod_IDirect3DCubeTexture9.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | import ModfileLoader; 4 | import TextureClient; 5 | import TextureFunction; 6 | 7 | //this function yields for the non switched texture object 8 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::QueryInterface(REFIID riid, void** ppvObj) 9 | { 10 | if (riid == IID_IDirect3D9) { 11 | // This function should never be called with IID_IDirect3D9 by the game 12 | // thus this call comes from our own dll to ask for the texture type 13 | // 0x01000000L == uMod_IDirect3DTexture9 14 | // 0x01000001L == uMod_IDirect3DVolumeTexture9 15 | // 0x01000002L == uMod_IDirect3DCubeTexture9 16 | 17 | *ppvObj = this; 18 | return 0x01000002L; 19 | } 20 | HRESULT hRes; 21 | if (CrossRef_D3Dtex != nullptr) { 22 | hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj); 23 | if (*ppvObj == CrossRef_D3Dtex->m_D3Dtex) { 24 | *ppvObj = this; 25 | } 26 | } 27 | else { 28 | hRes = m_D3Dtex->QueryInterface(riid, ppvObj); 29 | if (*ppvObj == m_D3Dtex) { 30 | *ppvObj = this; 31 | } 32 | } 33 | return hRes; 34 | } 35 | 36 | //this function yields for the non switched texture object 37 | ULONG APIENTRY uMod_IDirect3DCubeTexture9::AddRef() 38 | { 39 | if (FAKE) { 40 | return 1; //bug, this case should never happen 41 | } 42 | if (CrossRef_D3Dtex != nullptr) { 43 | return CrossRef_D3Dtex->m_D3Dtex->AddRef(); 44 | } 45 | return m_D3Dtex->AddRef(); 46 | } 47 | 48 | //this function yields for the non switched texture object 49 | ULONG APIENTRY uMod_IDirect3DCubeTexture9::Release() 50 | { 51 | Message("uMod_IDirect3DCubeTexture9::Release(): %p\n", this); 52 | 53 | void* cpy; 54 | const long ret = m_D3Ddev->QueryInterface(IID_IDirect3DTexture9, &cpy); 55 | 56 | ULONG count; 57 | if (FAKE) { 58 | UnswitchTextures(this); 59 | count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures 60 | } 61 | else { 62 | if (CrossRef_D3Dtex != nullptr) //if this texture is switched with a fake texture 63 | { 64 | uMod_IDirect3DCubeTexture9* fake_texture = CrossRef_D3Dtex; 65 | count = fake_texture->m_D3Dtex->Release(); //release the original texture 66 | if (count == 0) //if texture is released we switch the textures back 67 | { 68 | UnswitchTextures(this); 69 | fake_texture->Release(); // we release the fake texture 70 | } 71 | } 72 | else { 73 | count = m_D3Dtex->Release(); 74 | } 75 | } 76 | 77 | if (count == 0) //if this texture is released, we clean up 78 | { 79 | // if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added, 80 | // the hash of a non existing texture would be calculated 81 | if (ret == 0x01000000L) { 82 | if (static_cast(m_D3Ddev)->GetLastCreatedCubeTexture() == this) { 83 | static_cast(m_D3Ddev)->SetLastCreatedCubeTexture(nullptr); 84 | } 85 | else { 86 | static_cast(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client 87 | } 88 | } 89 | else { 90 | if (static_cast(m_D3Ddev)->GetLastCreatedCubeTexture() == this) { 91 | static_cast(m_D3Ddev)->SetLastCreatedCubeTexture(nullptr); 92 | } 93 | else { 94 | static_cast(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client 95 | } 96 | } 97 | 98 | delete this; 99 | } 100 | return count; 101 | } 102 | 103 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetDevice(IDirect3DDevice9** ppDevice) 104 | { 105 | *ppDevice = m_D3Ddev; 106 | return D3D_OK; 107 | } 108 | 109 | //this function yields for the non switched texture object 110 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::SetPrivateData(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) 111 | { 112 | if (CrossRef_D3Dtex != nullptr) { 113 | return CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags); 114 | } 115 | return m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags); 116 | } 117 | 118 | //this function yields for the non switched texture object 119 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData) 120 | { 121 | if (CrossRef_D3Dtex != nullptr) { 122 | return CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData); 123 | } 124 | return m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData); 125 | } 126 | 127 | //this function yields for the non switched texture object 128 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::FreePrivateData(REFGUID refguid) 129 | { 130 | if (CrossRef_D3Dtex != nullptr) { 131 | return CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid); 132 | } 133 | return m_D3Dtex->FreePrivateData(refguid); 134 | } 135 | 136 | DWORD APIENTRY uMod_IDirect3DCubeTexture9::SetPriority(DWORD PriorityNew) 137 | { 138 | return m_D3Dtex->SetPriority(PriorityNew); 139 | } 140 | 141 | DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetPriority() 142 | { 143 | return m_D3Dtex->GetPriority(); 144 | } 145 | 146 | void APIENTRY uMod_IDirect3DCubeTexture9::PreLoad() 147 | { 148 | m_D3Dtex->PreLoad(); 149 | } 150 | 151 | D3DRESOURCETYPE APIENTRY uMod_IDirect3DCubeTexture9::GetType() 152 | { 153 | return m_D3Dtex->GetType(); 154 | } 155 | 156 | DWORD APIENTRY uMod_IDirect3DCubeTexture9::SetLOD(DWORD LODNew) 157 | { 158 | return m_D3Dtex->SetLOD(LODNew); 159 | } 160 | 161 | DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetLOD() 162 | { 163 | return m_D3Dtex->GetLOD(); 164 | } 165 | 166 | DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetLevelCount() 167 | { 168 | return m_D3Dtex->GetLevelCount(); 169 | } 170 | 171 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType) 172 | { 173 | return m_D3Dtex->SetAutoGenFilterType(FilterType); 174 | } 175 | 176 | D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DCubeTexture9::GetAutoGenFilterType() 177 | { 178 | return m_D3Dtex->GetAutoGenFilterType(); 179 | } 180 | 181 | void APIENTRY uMod_IDirect3DCubeTexture9::GenerateMipSubLevels() 182 | { 183 | m_D3Dtex->GenerateMipSubLevels(); 184 | } 185 | 186 | //this function yields for the non switched texture object 187 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::AddDirtyRect(D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) 188 | { 189 | if (CrossRef_D3Dtex != nullptr) { 190 | return CrossRef_D3Dtex->m_D3Dtex->AddDirtyRect(FaceType, pDirtyRect); 191 | } 192 | return m_D3Dtex->AddDirtyRect(FaceType, pDirtyRect); 193 | } 194 | 195 | //this function yields for the non switched texture object 196 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetLevelDesc(UINT Level, D3DSURFACE_DESC* pDesc) 197 | { 198 | if (CrossRef_D3Dtex != nullptr) { 199 | return CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc); 200 | } 201 | return m_D3Dtex->GetLevelDesc(Level, pDesc); 202 | } 203 | 204 | //this function yields for the non switched texture object 205 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) 206 | { 207 | if (CrossRef_D3Dtex != nullptr) { 208 | return CrossRef_D3Dtex->m_D3Dtex->GetCubeMapSurface(FaceType, Level, ppCubeMapSurface); 209 | } 210 | return m_D3Dtex->GetCubeMapSurface(FaceType, Level, ppCubeMapSurface); 211 | } 212 | 213 | //this function yields for the non switched texture object 214 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect, DWORD Flags) 215 | { 216 | if (CrossRef_D3Dtex != nullptr) { 217 | return CrossRef_D3Dtex->m_D3Dtex->LockRect(FaceType, Level, pLockedRect, pRect, Flags); 218 | } 219 | return m_D3Dtex->LockRect(FaceType, Level, pLockedRect, pRect, Flags); 220 | } 221 | 222 | //this function yields for the non switched texture object 223 | HRESULT APIENTRY uMod_IDirect3DCubeTexture9::UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level) 224 | { 225 | if (CrossRef_D3Dtex != nullptr) { 226 | return CrossRef_D3Dtex->m_D3Dtex->UnlockRect(FaceType, Level); 227 | } 228 | return m_D3Dtex->UnlockRect(FaceType, Level); 229 | } 230 | 231 | HashTuple uMod_IDirect3DCubeTexture9::GetHash() const 232 | { 233 | if (FAKE) { 234 | return {}; 235 | } 236 | IDirect3DCubeTexture9* pTexture = m_D3Dtex; 237 | if (CrossRef_D3Dtex != nullptr) { 238 | pTexture = CrossRef_D3Dtex->m_D3Dtex; 239 | } 240 | 241 | IDirect3DSurface9* pResolvedSurface = nullptr; 242 | D3DLOCKED_RECT d3dlr; 243 | D3DSURFACE_DESC desc; 244 | 245 | if (pTexture->GetLevelDesc(0, &desc) != D3D_OK) //get the format and the size of the texture 246 | { 247 | Warning("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetLevelDesc \n"); 248 | return {}; 249 | } 250 | 251 | Message("uMod_IDirect3DCubeTexture9::GetHash() (%d %d) %d\n", desc.Width, desc.Height, desc.Format); 252 | 253 | if (pTexture->LockRect(D3DCUBEMAP_FACE_POSITIVE_X, 0, &d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) 254 | { 255 | Warning("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 1\n"); 256 | if (pTexture->GetCubeMapSurface(D3DCUBEMAP_FACE_POSITIVE_X, 0, &pResolvedSurface) != D3D_OK) { 257 | Warning("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel\n"); 258 | return {}; 259 | } 260 | if (pResolvedSurface->LockRect(&d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) { 261 | pResolvedSurface->Release(); 262 | Warning("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 2\n"); 263 | return {}; 264 | } 265 | } 266 | 267 | const auto size = (TextureFunction::GetBitsFromFormat(desc.Format) * desc.Width * desc.Height) / 8; 268 | const auto crc32 = TextureFunction::get_crc32(static_cast(d3dlr.pBits), size); 269 | const auto crc64 = HashCheck::Use64BitCrc() ? TextureFunction::get_crc64(static_cast(d3dlr.pBits), size) : 0; 270 | 271 | // Only release surfaces after we're finished with d3dlr 272 | if (pResolvedSurface != nullptr) { 273 | pResolvedSurface->UnlockRect(); 274 | pResolvedSurface->Release(); 275 | } 276 | else { 277 | pTexture->UnlockRect(D3DCUBEMAP_FACE_POSITIVE_X, 0); //unlock the raw data 278 | } 279 | 280 | Message("uMod_IDirect3DCubeTexture9::GetHash() %#lX (%d %d) %d = %d\n", crc32, desc.Width, desc.Height, desc.Format, size); 281 | Message("uMod_IDirect3DCubeTexture9::GetHash() %#llX (%d %d) %d = %d\n", crc64, desc.Width, desc.Height, desc.Format, size); 282 | return {crc32, crc64}; 283 | } 284 | -------------------------------------------------------------------------------- /source/uMod_IDirect3DDevice9Ex.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | #define uMod_IDirect3DDevice9 uMod_IDirect3DDevice9Ex 4 | #define IDirect3DDevice9 IDirect3DDevice9Ex 5 | #define m_pIDirect3DDevice9 m_pIDirect3DDevice9Ex 6 | 7 | #define RETURN_QueryInterface 0x01000001L 8 | #define PRE_MESSAGE "uMod_IDirect3DDevice9Ex" 9 | 10 | // ReSharper disable once CppUnusedIncludeDirective 11 | #include "uMod_IDirect3DDevice9.cpp" 12 | 13 | 14 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::CheckDeviceState(HWND hWindow) 15 | { 16 | return m_pIDirect3DDevice9Ex->CheckDeviceState(hWindow); 17 | } 18 | 19 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::CheckResourceResidency(IDirect3DResource9** ppResourceArray, UINT32 NumResources) 20 | { 21 | return m_pIDirect3DDevice9Ex->CheckResourceResidency(ppResourceArray, NumResources); 22 | } 23 | 24 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::ComposeRects(IDirect3DSurface9* pSource, IDirect3DSurface9* pDestination, IDirect3DVertexBuffer9* pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9* pDstRectDescriptors, D3DCOMPOSERECTSOP Operation, 25 | INT XOffset, INT YOffset) 26 | { 27 | return m_pIDirect3DDevice9Ex->ComposeRects(pSource, pDestination, pSrcRectDescriptors, NumRects, pDstRectDescriptors, Operation, XOffset, YOffset); 28 | } 29 | 30 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateDepthStencilSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) 31 | { 32 | return m_pIDirect3DDevice9Ex->CreateDepthStencilSurfaceEx(Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle, Usage); 33 | } 34 | 35 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateOffscreenPlainSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) 36 | { 37 | return m_pIDirect3DDevice9Ex->CreateOffscreenPlainSurfaceEx(Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage); 38 | } 39 | 40 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateRenderTargetEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) 41 | { 42 | return m_pIDirect3DDevice9Ex->CreateRenderTargetEx(Width, Height, Format, MultiSample, MultisampleQuality, Lockable, ppSurface, pSharedHandle, Usage); 43 | } 44 | 45 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetDisplayModeEx(UINT iSwapChain, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) 46 | { 47 | return m_pIDirect3DDevice9Ex->GetDisplayModeEx(iSwapChain, pMode, pRotation); 48 | } 49 | 50 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetGPUThreadPriority(INT* pPriority) 51 | { 52 | return m_pIDirect3DDevice9Ex->GetGPUThreadPriority(pPriority); 53 | } 54 | 55 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetMaximumFrameLatency(UINT* pMaxLatency) 56 | { 57 | return m_pIDirect3DDevice9Ex->GetMaximumFrameLatency(pMaxLatency); 58 | } 59 | 60 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::PresentEx(const RECT* pSourceRect, const RECT* pDestRect, HWND hDestWindowOverride, const RGNDATA* pDirtyRegion, DWORD dwFlags) 61 | { 62 | return m_pIDirect3DDevice9Ex->PresentEx(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags); 63 | } 64 | 65 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::ResetEx(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode) 66 | { 67 | return m_pIDirect3DDevice9Ex->ResetEx(pPresentationParameters, pFullscreenDisplayMode); 68 | } 69 | 70 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetConvolutionMonoKernel(UINT Width, UINT Height, float* RowWeights, float* ColumnWeights) 71 | { 72 | return m_pIDirect3DDevice9Ex->SetConvolutionMonoKernel(Width, Height, RowWeights, ColumnWeights); 73 | } 74 | 75 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetGPUThreadPriority(INT pPriority) 76 | { 77 | return m_pIDirect3DDevice9Ex->SetGPUThreadPriority(pPriority); 78 | } 79 | 80 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetMaximumFrameLatency(UINT pMaxLatency) 81 | { 82 | return m_pIDirect3DDevice9Ex->SetMaximumFrameLatency(pMaxLatency); 83 | } 84 | 85 | /* 86 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::TestCooperativeLevel() 87 | { 88 | return(m_pIDirect3DDevice9Ex->TestCooperativeLevel(); 89 | } 90 | */ 91 | 92 | HRESULT __stdcall uMod_IDirect3DDevice9Ex::WaitForVBlank(UINT SwapChainIndex) 93 | { 94 | return m_pIDirect3DDevice9Ex->WaitForVBlank(SwapChainIndex); 95 | } 96 | -------------------------------------------------------------------------------- /source/uMod_IDirect3DTexture9.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | import ModfileLoader; 4 | import TextureClient; 5 | import TextureFunction; 6 | 7 | //this function yields for the non switched texture object 8 | HRESULT APIENTRY uMod_IDirect3DTexture9::QueryInterface(REFIID riid, void** ppvObj) 9 | { 10 | if (riid == IID_IDirect3D9) { 11 | // This function should never be called with IID_IDirect3D9 by the game 12 | // thus this call comes from our own dll to ask for the texture type 13 | // 0x01000000L == uMod_IDirect3DTexture9 14 | // 0x01000001L == uMod_IDirect3DVolumeTexture9 15 | // 0x01000002L == uMod_IDirect3DCubeTexture9 16 | 17 | *ppvObj = this; 18 | return 0x01000000L; 19 | } 20 | HRESULT hRes; 21 | if (CrossRef_D3Dtex != nullptr) { 22 | hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj); 23 | if (*ppvObj == CrossRef_D3Dtex->m_D3Dtex) { 24 | *ppvObj = this; 25 | } 26 | } 27 | else { 28 | hRes = m_D3Dtex->QueryInterface(riid, ppvObj); 29 | if (*ppvObj == m_D3Dtex) { 30 | *ppvObj = this; 31 | } 32 | } 33 | return hRes; 34 | } 35 | 36 | //this function yields for the non switched texture object 37 | ULONG APIENTRY uMod_IDirect3DTexture9::AddRef() 38 | { 39 | if (FAKE) { 40 | return 1; //bug, this case should never happen 41 | } 42 | if (CrossRef_D3Dtex != nullptr) { 43 | return CrossRef_D3Dtex->m_D3Dtex->AddRef(); 44 | } 45 | return m_D3Dtex->AddRef(); 46 | } 47 | 48 | //this function yields for the non switched texture object 49 | ULONG APIENTRY uMod_IDirect3DTexture9::Release() 50 | { 51 | Message("uMod_IDirect3DTexture9::Release(): %p\n", this); 52 | 53 | void* cpy; 54 | const long ret = m_D3Ddev->QueryInterface(IID_IDirect3DTexture9, &cpy); 55 | 56 | ULONG count; 57 | if (FAKE) { 58 | UnswitchTextures(this); 59 | count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures 60 | } 61 | else { 62 | if (CrossRef_D3Dtex != nullptr) //if this texture is switched with a fake texture 63 | { 64 | uMod_IDirect3DTexture9* fake_texture = CrossRef_D3Dtex; 65 | count = fake_texture->m_D3Dtex->Release(); //release the original texture 66 | if (count == 0) //if texture is released we switch the textures back 67 | { 68 | UnswitchTextures(this); 69 | fake_texture->Release(); // we release the fake texture 70 | } 71 | } 72 | else { 73 | count = m_D3Dtex->Release(); 74 | } 75 | } 76 | 77 | if (count == 0) //if this texture is released, we clean up 78 | { 79 | // if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added, 80 | // the hash of a non existing texture would be calculated 81 | if (ret == 0x01000000L) { 82 | if (static_cast(m_D3Ddev)->GetLastCreatedTexture() == this) { 83 | static_cast(m_D3Ddev)->SetLastCreatedTexture(nullptr); 84 | } 85 | else { 86 | static_cast(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client 87 | } 88 | } 89 | else { 90 | if (static_cast(m_D3Ddev)->GetLastCreatedTexture() == this) { 91 | static_cast(m_D3Ddev)->SetLastCreatedTexture(nullptr); 92 | } 93 | else { 94 | static_cast(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client 95 | } 96 | } 97 | 98 | delete this; 99 | } 100 | 101 | Message("uMod_IDirect3DTexture9::Release() end: %p\n", this); 102 | return count; 103 | } 104 | 105 | HRESULT APIENTRY uMod_IDirect3DTexture9::GetDevice(IDirect3DDevice9** ppDevice) 106 | { 107 | *ppDevice = m_D3Ddev; 108 | return D3D_OK; 109 | } 110 | 111 | //this function yields for the non switched texture object 112 | HRESULT APIENTRY uMod_IDirect3DTexture9::SetPrivateData(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) 113 | { 114 | if (CrossRef_D3Dtex != nullptr) { 115 | return CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags); 116 | } 117 | return m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags); 118 | } 119 | 120 | //this function yields for the non switched texture object 121 | HRESULT APIENTRY uMod_IDirect3DTexture9::GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData) 122 | { 123 | if (CrossRef_D3Dtex != nullptr) { 124 | return CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData); 125 | } 126 | return m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData); 127 | } 128 | 129 | //this function yields for the non switched texture object 130 | HRESULT APIENTRY uMod_IDirect3DTexture9::FreePrivateData(REFGUID refguid) 131 | { 132 | if (CrossRef_D3Dtex != nullptr) { 133 | return CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid); 134 | } 135 | return m_D3Dtex->FreePrivateData(refguid); 136 | } 137 | 138 | DWORD APIENTRY uMod_IDirect3DTexture9::SetPriority(DWORD PriorityNew) 139 | { 140 | return m_D3Dtex->SetPriority(PriorityNew); 141 | } 142 | 143 | DWORD APIENTRY uMod_IDirect3DTexture9::GetPriority() 144 | { 145 | return m_D3Dtex->GetPriority(); 146 | } 147 | 148 | void APIENTRY uMod_IDirect3DTexture9::PreLoad() 149 | { 150 | m_D3Dtex->PreLoad(); 151 | } 152 | 153 | D3DRESOURCETYPE APIENTRY uMod_IDirect3DTexture9::GetType() 154 | { 155 | return m_D3Dtex->GetType(); 156 | } 157 | 158 | DWORD APIENTRY uMod_IDirect3DTexture9::SetLOD(DWORD LODNew) 159 | { 160 | return m_D3Dtex->SetLOD(LODNew); 161 | } 162 | 163 | DWORD APIENTRY uMod_IDirect3DTexture9::GetLOD() 164 | { 165 | return m_D3Dtex->GetLOD(); 166 | } 167 | 168 | DWORD APIENTRY uMod_IDirect3DTexture9::GetLevelCount() 169 | { 170 | return m_D3Dtex->GetLevelCount(); 171 | } 172 | 173 | HRESULT APIENTRY uMod_IDirect3DTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType) 174 | { 175 | return m_D3Dtex->SetAutoGenFilterType(FilterType); 176 | } 177 | 178 | D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DTexture9::GetAutoGenFilterType() 179 | { 180 | return m_D3Dtex->GetAutoGenFilterType(); 181 | } 182 | 183 | void APIENTRY uMod_IDirect3DTexture9::GenerateMipSubLevels() 184 | { 185 | m_D3Dtex->GenerateMipSubLevels(); 186 | } 187 | 188 | //this function yields for the non switched texture object 189 | HRESULT APIENTRY uMod_IDirect3DTexture9::GetLevelDesc(UINT Level, D3DSURFACE_DESC* pDesc) 190 | { 191 | if (CrossRef_D3Dtex != nullptr) { 192 | return CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc); 193 | } 194 | return m_D3Dtex->GetLevelDesc(Level, pDesc); 195 | } 196 | 197 | //this function yields for the non switched texture object 198 | HRESULT APIENTRY uMod_IDirect3DTexture9::GetSurfaceLevel(UINT Level, IDirect3DSurface9** ppSurfaceLevel) 199 | { 200 | if (CrossRef_D3Dtex != nullptr) { 201 | return CrossRef_D3Dtex->m_D3Dtex->GetSurfaceLevel(Level, ppSurfaceLevel); 202 | } 203 | return m_D3Dtex->GetSurfaceLevel(Level, ppSurfaceLevel); 204 | } 205 | 206 | //this function yields for the non switched texture object 207 | HRESULT APIENTRY uMod_IDirect3DTexture9::LockRect(UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) 208 | { 209 | if (CrossRef_D3Dtex != nullptr) { 210 | return CrossRef_D3Dtex->m_D3Dtex->LockRect(Level, pLockedRect, pRect, Flags); 211 | } 212 | return m_D3Dtex->LockRect(Level, pLockedRect, pRect, Flags); 213 | } 214 | 215 | //this function yields for the non switched texture object 216 | HRESULT APIENTRY uMod_IDirect3DTexture9::UnlockRect(UINT Level) 217 | { 218 | if (CrossRef_D3Dtex != nullptr) { 219 | return CrossRef_D3Dtex->m_D3Dtex->UnlockRect(Level); 220 | } 221 | return m_D3Dtex->UnlockRect(Level); 222 | } 223 | 224 | //this function yields for the non switched texture object 225 | HRESULT APIENTRY uMod_IDirect3DTexture9::AddDirtyRect(CONST RECT* pDirtyRect) 226 | { 227 | if (CrossRef_D3Dtex != nullptr) { 228 | return CrossRef_D3Dtex->m_D3Dtex->AddDirtyRect(pDirtyRect); 229 | } 230 | return m_D3Dtex->AddDirtyRect(pDirtyRect); 231 | } 232 | 233 | 234 | HashTuple uMod_IDirect3DTexture9::GetHash() const 235 | { 236 | ASSERT(!FAKE); 237 | IDirect3DTexture9* pTexture = m_D3Dtex; 238 | if (CrossRef_D3Dtex != nullptr) { 239 | pTexture = CrossRef_D3Dtex->m_D3Dtex; 240 | } 241 | 242 | IDirect3DSurface9* pOffscreenSurface = nullptr; 243 | //IDirect3DTexture9 *pOffscreenTexture = NULL; 244 | IDirect3DSurface9* pResolvedSurface = nullptr; 245 | D3DLOCKED_RECT d3dlr; 246 | D3DSURFACE_DESC desc; 247 | 248 | if (pTexture->GetLevelDesc(0, &desc) != D3D_OK) //get the format and the size of the texture 249 | { 250 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: GetLevelDesc \n"); 251 | return {}; 252 | } 253 | 254 | Message("uMod_IDirect3DTexture9::GetHash() (%d %d) %d\n", desc.Width, desc.Height, desc.Format); 255 | 256 | 257 | if (desc.Pool == D3DPOOL_DEFAULT) //get the raw data of the texture 258 | { 259 | //Message("uMod_IDirect3DTexture9::GetHash() (D3DPOOL_DEFAULT)\n"); 260 | 261 | IDirect3DSurface9* pSurfaceLevel_orig = nullptr; 262 | if (pTexture->GetSurfaceLevel(0, &pSurfaceLevel_orig) != D3D_OK) { 263 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n"); 264 | return {}; 265 | } 266 | 267 | if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) { 268 | //Message("uMod_IDirect3DTexture9::GetHash() MultiSampleType\n"); 269 | if (D3D_OK != m_D3Ddev->CreateRenderTarget(desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, nullptr)) { 270 | pSurfaceLevel_orig->Release(); 271 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n"); 272 | return {}; 273 | } 274 | if (D3D_OK != m_D3Ddev->StretchRect(pSurfaceLevel_orig, nullptr, pResolvedSurface, nullptr, D3DTEXF_NONE)) { 275 | pSurfaceLevel_orig->Release(); 276 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n"); 277 | return {}; 278 | } 279 | 280 | pSurfaceLevel_orig = pResolvedSurface; 281 | } 282 | 283 | if (D3D_OK != m_D3Ddev->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, nullptr)) { 284 | pSurfaceLevel_orig->Release(); 285 | if (pResolvedSurface != nullptr) { 286 | pResolvedSurface->Release(); 287 | } 288 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n"); 289 | return {}; 290 | } 291 | 292 | if (D3D_OK != m_D3Ddev->GetRenderTargetData(pSurfaceLevel_orig, pOffscreenSurface)) { 293 | pSurfaceLevel_orig->Release(); 294 | if (pResolvedSurface != nullptr) { 295 | pResolvedSurface->Release(); 296 | } 297 | pOffscreenSurface->Release(); 298 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n"); 299 | return {}; 300 | } 301 | pSurfaceLevel_orig->Release(); 302 | 303 | if (pOffscreenSurface->LockRect(&d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) { 304 | if (pResolvedSurface != nullptr) { 305 | pResolvedSurface->Release(); 306 | } 307 | pOffscreenSurface->Release(); 308 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n"); 309 | return {}; 310 | } 311 | } 312 | else if (pTexture->LockRect(0, &d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) { 313 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: LockRect 1\n"); 314 | if (pTexture->GetSurfaceLevel(0, &pResolvedSurface) != D3D_OK) { 315 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: GetSurfaceLevel\n"); 316 | return {}; 317 | } 318 | if (pResolvedSurface->LockRect(&d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) { 319 | pResolvedSurface->Release(); 320 | Warning("uMod_IDirect3DTexture9::GetHash() Failed: LockRect 2\n"); 321 | return {}; 322 | } 323 | } 324 | 325 | const int size = (TextureFunction::GetBitsFromFormat(desc.Format) * desc.Width * desc.Height) / 8; 326 | const auto crc32 = TextureFunction::get_crc32(static_cast(d3dlr.pBits), size); 327 | const auto crc64 = HashCheck::Use64BitCrc() ? TextureFunction::get_crc64(static_cast(d3dlr.pBits), size) : 0; 328 | 329 | // Only release surfaces after we're finished with d3dlr 330 | if (pOffscreenSurface != nullptr) { 331 | pOffscreenSurface->UnlockRect(); 332 | pOffscreenSurface->Release(); 333 | if (pResolvedSurface != nullptr) { 334 | pResolvedSurface->Release(); 335 | } 336 | } 337 | else if (pResolvedSurface != nullptr) { 338 | pResolvedSurface->UnlockRect(); 339 | pResolvedSurface->Release(); 340 | } 341 | else { 342 | pTexture->UnlockRect(0); 343 | } 344 | 345 | Message("uMod_IDirect3DTexture9::GetHash() crc32 %#lX (%d %d) %d = %d\n", crc32, desc.Width, desc.Height, desc.Format, size); 346 | Message("uMod_IDirect3DTexture9::GetHash() crc64 %#llX (%d %d) %d = %d\n", crc64, desc.Width, desc.Height, desc.Format, size); 347 | return {crc32, crc64}; 348 | } 349 | -------------------------------------------------------------------------------- /source/uMod_IDirect3DVolumeTexture9.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | import ModfileLoader; 4 | import TextureClient; 5 | import TextureFunction; 6 | 7 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::QueryInterface(REFIID riid, void** ppvObj) 8 | { 9 | if (riid == IID_IDirect3D9) { 10 | // This function should never be called with IID_IDirect3D9 by the game 11 | // thus this call comes from our own dll to ask for the texture type 12 | // 0x01000000L == uMod_IDirect3DTexture9 13 | // 0x01000001L == uMod_IDirect3DVolumeTexture9 14 | // 0x01000002L == uMod_IDirect3DCubeTexture9 15 | 16 | *ppvObj = this; 17 | return 0x01000001L; 18 | } 19 | HRESULT hRes; 20 | if (CrossRef_D3Dtex != nullptr) { 21 | hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj); 22 | if (*ppvObj == CrossRef_D3Dtex->m_D3Dtex) { 23 | *ppvObj = this; 24 | } 25 | } 26 | else { 27 | hRes = m_D3Dtex->QueryInterface(riid, ppvObj); 28 | if (*ppvObj == m_D3Dtex) { 29 | *ppvObj = this; 30 | } 31 | } 32 | return hRes; 33 | } 34 | 35 | //this function yields for the non switched texture object 36 | ULONG APIENTRY uMod_IDirect3DVolumeTexture9::AddRef() 37 | { 38 | if (FAKE) { 39 | return 1; //bug, this case should never happen 40 | } 41 | if (CrossRef_D3Dtex != nullptr) { 42 | return CrossRef_D3Dtex->m_D3Dtex->AddRef(); 43 | } 44 | return m_D3Dtex->AddRef(); 45 | } 46 | 47 | //this function yields for the non switched texture object 48 | ULONG APIENTRY uMod_IDirect3DVolumeTexture9::Release() 49 | { 50 | Message("uMod_IDirect3DVolumeTexture9::Release(): %p\n", this); 51 | 52 | void* cpy; 53 | const long ret = m_D3Ddev->QueryInterface(IID_IDirect3DTexture9, &cpy); 54 | 55 | ULONG count; 56 | if (FAKE) { 57 | UnswitchTextures(this); 58 | count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures 59 | } 60 | else { 61 | if (CrossRef_D3Dtex != nullptr) //if this texture is switched with a fake texture 62 | { 63 | uMod_IDirect3DVolumeTexture9* fake_texture = CrossRef_D3Dtex; 64 | count = fake_texture->m_D3Dtex->Release(); //release the original texture 65 | if (count == 0) //if texture is released we switch the textures back 66 | { 67 | UnswitchTextures(this); 68 | fake_texture->Release(); // we release the fake texture 69 | } 70 | } 71 | else { 72 | count = m_D3Dtex->Release(); 73 | } 74 | } 75 | 76 | if (count == 0) //if this texture is released, we clean up 77 | { 78 | // if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added, 79 | // the hash of a non existing texture would be calculated 80 | if (ret == 0x01000000L) { 81 | if (static_cast(m_D3Ddev)->GetLastCreatedVolumeTexture() == this) { 82 | static_cast(m_D3Ddev)->SetLastCreatedVolumeTexture(nullptr); 83 | } 84 | else { 85 | static_cast(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client 86 | } 87 | } 88 | else { 89 | if (static_cast(m_D3Ddev)->GetLastCreatedVolumeTexture() == this) { 90 | static_cast(m_D3Ddev)->SetLastCreatedVolumeTexture(nullptr); 91 | } 92 | else { 93 | static_cast(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client 94 | } 95 | } 96 | 97 | delete this; 98 | } 99 | return count; 100 | } 101 | 102 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetDevice(IDirect3DDevice9** ppDevice) 103 | { 104 | *ppDevice = m_D3Ddev; 105 | return D3D_OK; 106 | } 107 | 108 | //this function yields for the non switched texture object 109 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::SetPrivateData(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) 110 | { 111 | if (CrossRef_D3Dtex != nullptr) { 112 | return CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags); 113 | } 114 | return m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags); 115 | } 116 | 117 | //this function yields for the non switched texture object 118 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData) 119 | { 120 | if (CrossRef_D3Dtex != nullptr) { 121 | return CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData); 122 | } 123 | return m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData); 124 | } 125 | 126 | //this function yields for the non switched texture object 127 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::FreePrivateData(REFGUID refguid) 128 | { 129 | if (CrossRef_D3Dtex != nullptr) { 130 | return CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid); 131 | } 132 | return m_D3Dtex->FreePrivateData(refguid); 133 | } 134 | 135 | DWORD APIENTRY uMod_IDirect3DVolumeTexture9::SetPriority(DWORD PriorityNew) 136 | { 137 | return m_D3Dtex->SetPriority(PriorityNew); 138 | } 139 | 140 | DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetPriority() 141 | { 142 | return m_D3Dtex->GetPriority(); 143 | } 144 | 145 | void APIENTRY uMod_IDirect3DVolumeTexture9::PreLoad() 146 | { 147 | m_D3Dtex->PreLoad(); 148 | } 149 | 150 | D3DRESOURCETYPE APIENTRY uMod_IDirect3DVolumeTexture9::GetType() 151 | { 152 | return m_D3Dtex->GetType(); 153 | } 154 | 155 | DWORD APIENTRY uMod_IDirect3DVolumeTexture9::SetLOD(DWORD LODNew) 156 | { 157 | return m_D3Dtex->SetLOD(LODNew); 158 | } 159 | 160 | DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetLOD() 161 | { 162 | return m_D3Dtex->GetLOD(); 163 | } 164 | 165 | DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetLevelCount() 166 | { 167 | return m_D3Dtex->GetLevelCount(); 168 | } 169 | 170 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType) 171 | { 172 | return m_D3Dtex->SetAutoGenFilterType(FilterType); 173 | } 174 | 175 | D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DVolumeTexture9::GetAutoGenFilterType() 176 | { 177 | return m_D3Dtex->GetAutoGenFilterType(); 178 | } 179 | 180 | void APIENTRY uMod_IDirect3DVolumeTexture9::GenerateMipSubLevels() 181 | { 182 | m_D3Dtex->GenerateMipSubLevels(); 183 | } 184 | 185 | //this function yields for the non switched texture object 186 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::AddDirtyBox(CONST D3DBOX* pDirtyBox) 187 | { 188 | if (CrossRef_D3Dtex != nullptr) { 189 | return CrossRef_D3Dtex->m_D3Dtex->AddDirtyBox(pDirtyBox); 190 | } 191 | return m_D3Dtex->AddDirtyBox(pDirtyBox); 192 | } 193 | 194 | //this function yields for the non switched texture object 195 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetLevelDesc(UINT Level, D3DVOLUME_DESC* pDesc) 196 | { 197 | if (CrossRef_D3Dtex != nullptr) { 198 | return CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc); 199 | } 200 | return m_D3Dtex->GetLevelDesc(Level, pDesc); 201 | } 202 | 203 | //this function yields for the non switched texture object 204 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetVolumeLevel(UINT Level, IDirect3DVolume9** ppVolumeLevel) 205 | { 206 | if (CrossRef_D3Dtex != nullptr) { 207 | return CrossRef_D3Dtex->m_D3Dtex->GetVolumeLevel(Level, ppVolumeLevel); 208 | } 209 | return m_D3Dtex->GetVolumeLevel(Level, ppVolumeLevel); 210 | } 211 | 212 | //this function yields for the non switched texture object 213 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::LockBox(UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) 214 | { 215 | if (CrossRef_D3Dtex != nullptr) { 216 | return CrossRef_D3Dtex->m_D3Dtex->LockBox(Level, pLockedVolume, pBox, Flags); 217 | } 218 | return m_D3Dtex->LockBox(Level, pLockedVolume, pBox, Flags); 219 | } 220 | 221 | //this function yields for the non switched texture object 222 | HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::UnlockBox(UINT Level) 223 | { 224 | if (CrossRef_D3Dtex != nullptr) { 225 | return CrossRef_D3Dtex->m_D3Dtex->UnlockBox(Level); 226 | } 227 | return m_D3Dtex->UnlockBox(Level); 228 | } 229 | 230 | HashTuple uMod_IDirect3DVolumeTexture9::GetHash() const 231 | { 232 | if (FAKE) { 233 | return {}; 234 | } 235 | IDirect3DVolumeTexture9* pTexture = m_D3Dtex; 236 | if (CrossRef_D3Dtex != nullptr) { 237 | pTexture = CrossRef_D3Dtex->m_D3Dtex; 238 | } 239 | 240 | IDirect3DVolume9* pResolvedSurface = nullptr; 241 | D3DLOCKED_BOX d3dlr; 242 | D3DVOLUME_DESC desc; 243 | 244 | if (pTexture->GetLevelDesc(0, &desc) != D3D_OK) //get the format and the size of the texture 245 | { 246 | Warning("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetLevelDesc \n"); 247 | return {}; 248 | } 249 | 250 | Message("uMod_IDirect3DVolumeTexture9::GetHash() (%d %d %d) %d\n", desc.Width, desc.Height, desc.Depth, desc.Format); 251 | if (pTexture->LockBox(0, &d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) { 252 | Warning("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect 1\n"); 253 | if (pTexture->GetVolumeLevel(0, &pResolvedSurface) != D3D_OK) { 254 | Warning("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel\n"); 255 | return {}; 256 | } 257 | if (pResolvedSurface->LockBox(&d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) { 258 | pResolvedSurface->Release(); 259 | Warning("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect 2\n"); 260 | return {}; 261 | } 262 | } 263 | 264 | const int size = (TextureFunction::GetBitsFromFormat(desc.Format) * desc.Width * desc.Height * desc.Depth) / 8; 265 | const auto crc32 = TextureFunction::get_crc32(static_cast(d3dlr.pBits), size); 266 | const auto crc64 = HashCheck::Use64BitCrc() ? TextureFunction::get_crc64(static_cast(d3dlr.pBits), size) : 0; 267 | 268 | // Only release surfaces after we're finished with d3dlr 269 | if (pResolvedSurface != nullptr) { 270 | pResolvedSurface->UnlockBox(); 271 | pResolvedSurface->Release(); 272 | } 273 | else { 274 | pTexture->UnlockBox(0); 275 | } 276 | 277 | Message("uMod_IDirect3DVolumeTexture9::GetHash() crc32 %#lX (%d %d) %d = %d\n", crc32, desc.Width, desc.Height, desc.Format, size); 278 | Message("uMod_IDirect3DVolumeTexture9::GetHash() crc64 %#llX (%d %d) %d = %d\n", crc64, desc.Width, desc.Height, desc.Format, size); 279 | return {crc32, crc64}; 280 | } 281 | -------------------------------------------------------------------------------- /triplets/x86-windows-mixed.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x86) 2 | 3 | if(PORT MATCHES "dxsdk-d3dx") 4 | set(VCPKG_CRT_LINKAGE dynamic) 5 | set(VCPKG_LIBRARY_LINKAGE dynamic) 6 | else() 7 | set(VCPKG_CRT_LINKAGE static) 8 | set(VCPKG_LIBRARY_LINKAGE static) 9 | endif() 10 | -------------------------------------------------------------------------------- /vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "default-registry": { 3 | "kind": "git", 4 | "baseline": "7f9f0e44db287e8e67c0e888141bfa200ab45121", 5 | "repository": "https://github.com/microsoft/vcpkg" 6 | }, 7 | "registries": [ 8 | { 9 | "kind": "artifact", 10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", 11 | "name": "microsoft" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | "dxsdk-d3dx", 4 | { 5 | "name": "libzippp", 6 | "features": [ 7 | "encryption" 8 | ] 9 | }, 10 | "minhook", 11 | "ms-gsl" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /version.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,@VERSION_TWEAK@ 5 | PRODUCTVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,@VERSION_TWEAK@ 6 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 7 | #ifdef _DEBUG 8 | FILEFLAGS VS_FF_DEBUG 9 | #else 10 | FILEFLAGS 0x0L 11 | #endif 12 | FILEOS VOS_NT_WINDOWS32 13 | FILETYPE VFT_DLL 14 | FILESUBTYPE VFT2_UNKNOWN 15 | BEGIN 16 | BLOCK "StringFileInfo" 17 | BEGIN 18 | BLOCK "040904b0" 19 | BEGIN 20 | VALUE "CompanyName", "" 21 | VALUE "FileDescription", "gMod" 22 | VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@.@VERSION_TWEAK@" 23 | VALUE "InternalName", "gMod" 24 | VALUE "LegalCopyright", "" 25 | VALUE "OriginalFilename", "gMod.dll" 26 | VALUE "ProductName", "gMod" 27 | VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@.@VERSION_TWEAK@" 28 | END 29 | END 30 | BLOCK "VarFileInfo" 31 | BEGIN 32 | VALUE "Translation", 0x409, 0x4B0 33 | END 34 | END 35 | --------------------------------------------------------------------------------