Compare commits

...

1 Commits

Author SHA1 Message Date
DubbleClick a7e36fc965 rename to gmod, drop gui (#1)
* remove GUI parts as those will not be updated

* move to header/source

* add cmakelist to create solution

* Change Readme

* Implement modlist.txt loading

* Setup versioning and CD pipeline

* Setup DirectX in pipeline

* Make uMod load from uMod.dll directory

* Fix file loading

* Remove break

* Fix CD pipeline (#1)

* Test cd pipeline

* See what's in Lib directory

* See inside lib/x86

* Manually adjust the build environment

* Disable CD pipeline in PRs
Create CI pipeline

* Fix slashes in path

* Fix build call

* Attempt to fix paths

* Copy dx headers inside the /header folder

* Use ps

* Change cache location

* Path changes

* Improve CMake to look for lib and header files

* Fix missing Lib folder

* Move changes to CD pipeline

* Disable CI on merge and fix CD (#2)

* Fix CD tag (#4)

* Hijack existing DirectX calls (#5)

* Create a dll without listener (#6)

* Fix asset creation in CD pipeline (#7)

* Setup file loading

* create necessary files

* merge latest changes, set output dir

* Change main to master in pipelines
Add fallback for DX libs in CMakeLists

* Setup new generator

* formatting

* remove listener

* Change CD to pick the dll from bin
Change release name to gMod

* more formatting

* add editorconfig

* Setup versioning

* Remove CODEOWNERS

---------

Co-authored-by: Alex Macocian <amacocian@yahoo.com>
2023-11-10 17:40:30 +01:00
120 changed files with 15004 additions and 21714 deletions
-59
View File
@@ -1,59 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="org.eclipse.cdt.msvc.toolchain.dll.debug.1265470207">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="org.eclipse.cdt.msvc.toolchain.dll.debug.1265470207" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="uMod" buildProperties="" description="" id="org.eclipse.cdt.msvc.toolchain.dll.debug.1265470207" name="Debug" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="org.eclipse.cdt.msvc.toolchain.dll.debug.1265470207.1198697062" name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.msvc.toolchain.dll.debug.819029430" name="org.eclipse.cdt.msvc.toolchain.dll.debug" superClass="org.eclipse.cdt.msvc.toolchain.dll.debug">
<targetPlatform id="org.eclipse.cdt.msvc.targetPlatform.dll.debug.988168225" superClass="org.eclipse.cdt.msvc.targetPlatform.dll.debug"/>
<builder buildPath="${workspace_loc:/uMod/Debug}" id="org.eclipse.cdt.msvc.builder.611532519" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="CDT Internal Builder" superClass="org.eclipse.cdt.msvc.builder"/>
<tool id="org.eclipse.cdt.msvc.cl.dll.debug.971252395" name="C/C++ Compiler (cl)" superClass="org.eclipse.cdt.msvc.cl.dll.debug">
<option id="org.eclipse.cdt.msvc.cl.option.includes.1468714055" name="Include Path (/I)" superClass="org.eclipse.cdt.msvc.cl.option.includes" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include&quot;"/>
<listOptionValue builtIn="false" value="&quot;D:\Programme\wxWidgets-2.9.2\include&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include&quot;"/>
</option>
<inputType id="org.eclipse.cdt.msvc.cl.inputType.370712665" superClass="org.eclipse.cdt.msvc.cl.inputType"/>
</tool>
<tool id="org.eclipse.cdt.msvc.rc.dll.debug.1079503691" name="Resource Compiler (rc)" superClass="org.eclipse.cdt.msvc.rc.dll.debug">
<inputType id="org.eclipse.cdt.msvc.rc.inputType.1577630195" superClass="org.eclipse.cdt.msvc.rc.inputType"/>
</tool>
<tool id="org.eclipse.cdt.msvc.link.dll.debug.617161498" name="Linker (link)" superClass="org.eclipse.cdt.msvc.link.dll.debug">
<inputType id="org.eclipse.cdt.msvc.link.inputType.1391138218" superClass="org.eclipse.cdt.msvc.link.inputType"/>
</tool>
<tool id="org.eclipse.cdt.msvc.lib.1963448406" name="Library Manager (lib)" superClass="org.eclipse.cdt.msvc.lib"/>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="uMod.null.2056766171" name="uMod"/>
</storageModule>
<storageModule moduleId="refreshScope" versionNumber="1">
<resource resourceType="PROJECT" workspacePath="/uMod"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="org.eclipse.cdt.msvc.toolchain.dll.debug.1265470207;org.eclipse.cdt.msvc.toolchain.dll.debug.1265470207.1198697062;org.eclipse.cdt.msvc.cl.dll.debug.971252395;org.eclipse.cdt.msvc.cl.inputType.370712665">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.msw.build.clScannerInfo"/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings">
<doc-comment-owner id="org.eclipse.cdt.ui.doxygen">
<path value=""/>
</doc-comment-owner>
</storageModule>
</cproject>
+7
View File
@@ -0,0 +1,7 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
-81
View File
@@ -1,81 +0,0 @@
* text=auto !eol
/.cproject -text
/.project -text
.settings/org.eclipse.cdt.codan.core.prefs -text
/README.txt -text
uMod_DX9/makefile.gcc -text
uMod_DX9/makefile.vc -text
uMod_DX9/uMod_ArrayHandler.cpp -text
uMod_DX9/uMod_ArrayHandler.h -text
uMod_DX9/uMod_DX9_dll.cpp -text
uMod_DX9/uMod_DX9_dll.h -text
uMod_DX9/uMod_DX9_dll_DIRECT_INJECTION.def -text
uMod_DX9/uMod_DX9_dll_HOOK_INJECTION.def -text
uMod_DX9/uMod_DX9_dll_NO_INJECTION.def -text
uMod_DX9/uMod_Defines.h -text
uMod_DX9/uMod_IDirect3D9.cpp -text
uMod_DX9/uMod_IDirect3D9.h -text
uMod_DX9/uMod_IDirect3D9Ex.cpp -text
uMod_DX9/uMod_IDirect3D9Ex.h -text
uMod_DX9/uMod_IDirect3DCubeTexture9.cpp -text
uMod_DX9/uMod_IDirect3DCubeTexture9.h -text
uMod_DX9/uMod_IDirect3DDevice9.cpp -text
uMod_DX9/uMod_IDirect3DDevice9.h -text
uMod_DX9/uMod_IDirect3DDevice9Ex.cpp -text
uMod_DX9/uMod_IDirect3DDevice9Ex.h -text
uMod_DX9/uMod_IDirect3DTexture9.cpp -text
uMod_DX9/uMod_IDirect3DTexture9.h -text
uMod_DX9/uMod_IDirect3DVolumeTexture9.cpp -text
uMod_DX9/uMod_IDirect3DVolumeTexture9.h -text
uMod_DX9/uMod_Main.h -text
uMod_DX9/uMod_TextureClient.cpp -text
uMod_DX9/uMod_TextureClient.h -text
uMod_DX9/uMod_TextureFunction.cpp -text
uMod_DX9/uMod_TextureFunction.h -text
uMod_DX9/uMod_TextureServer.cpp -text
uMod_DX9/uMod_TextureServer.h -text
/uMod_Error.h -text
uMod_GUI/bin/README_Deutsch.txt -text
uMod_GUI/bin/README_English.txt -text
uMod_GUI/bin/README_French.txt -text
uMod_GUI/bin/languages/Example_uMod_LanguagePack_English.txt -text
uMod_GUI/bin/languages/uMod_LanguagePackU_Deutsch.txt -text
uMod_GUI/bin/languages/uMod_LanguagePackU_French.txt -text
uMod_GUI/bin/languages/uMod_LanguagePackU_Russian.txt -text
uMod_GUI/bin/languages/uMod_LanguagePack_Italian.txt -text
uMod_GUI/config.gcc -text
uMod_GUI/config.vc -text
uMod_GUI/makefile.gcc -text
uMod_GUI/makefile.vc -text
uMod_GUI/uMod.ico -text
uMod_GUI/uMod.rc -text
uMod_GUI/uMod_AddTexture.cpp -text
uMod_GUI/uMod_AddTexture.h -text
uMod_GUI/uMod_Client.cpp -text
uMod_GUI/uMod_Client.h -text
uMod_GUI/uMod_DirectInjection.cpp -text
uMod_GUI/uMod_DirectInjection.h -text
uMod_GUI/uMod_Event.cpp -text
uMod_GUI/uMod_Event.h -text
uMod_GUI/uMod_File.cpp -text
uMod_GUI/uMod_File.h -text
uMod_GUI/uMod_GUI.cpp -text
uMod_GUI/uMod_GUI.h -text
uMod_GUI/uMod_GameInfo.cpp -text
uMod_GUI/uMod_GameInfo.h -text
uMod_GUI/uMod_GamePage.cpp -text
uMod_GUI/uMod_GamePage.h -text
uMod_GUI/uMod_Language.cpp -text
uMod_GUI/uMod_Language.h -text
uMod_GUI/uMod_Main.h -text
uMod_GUI/uMod_Sender.cpp -text
uMod_GUI/uMod_Sender.h -text
uMod_GUI/uMod_Server.cpp -text
uMod_GUI/uMod_Server.h -text
uMod_GUI/uMod_Settings.cpp -text
uMod_GUI/uMod_Settings.h -text
uMod_GUI/unzip.cpp -text
uMod_GUI/unzip.h -text
uMod_GUI/zip.cpp -text
uMod_GUI/zip.h -text
/uMod_GlobalDefines.h -text
+117
View File
@@ -0,0 +1,117 @@
# This continuous integration pipeline is triggered anytime a user pushes code to the repo.
# This pipeline builds the Wpf project, runs unit tests, then saves the MSIX build artifact.
name: uMod CD Pipeline
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
strategy:
matrix:
targetplatform: [x86]
runs-on: windows-latest
env:
Configuration: Release
Actions_Allow_Unsecure_Commands: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Config
run: echo "DXSDK_DIR=DXSDK" >> $GITHUB_ENV
shell: bash
- name: Cache
id: cache
uses: actions/cache@v1
with:
path: DXSDK
key: DXSDK
- name: Cache create
if: steps.cache.outputs.cache-hit != 'true'
run: |
curl -L https://download.microsoft.com/download/a/e/7/ae743f1f-632b-4809-87a9-aa1bb3458e31/DXSDK_Jun10.exe -o _DX2010_.exe
7z x _DX2010_.exe DXSDK/Include
7z x _DX2010_.exe DXSDK/Lib/x86
shell: bash
- name: Echo cache
run: echo ${{ env.DXSDK_DIR }}
- name: List dxsdk files
run: |
cd DXSDK
ls
cd Include
ls
cd ../Lib/x86
ls
- name: Copy DirectX headers to project include directory
run: Copy-Item -Path "${{ env.DXSDK_DIR }}/Include/*" -Destination header/ -Recurse -Force
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
shell: pwsh
- name: Ensure Lib directory exists and copy DirectX libraries
run: |
$libDir = "Lib/"
if (-Not (Test-Path -Path $libDir)) {
New-Item -ItemType Directory -Path $libDir
}
Copy-Item -Path "${{ env.DXSDK_DIR }}/Lib/x86/*" -Destination $libDir -Recurse -Force
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
shell: pwsh
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.3.1
- name: Build CMake Files
run: cmake -S . -B build -A Win32
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
- name: Build binaries
run: cmake --build build --config Release
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
- name: Retrieve version
id: set_version
run: |
$fileVersionInfo = (Get-Item -Path .\bin\Release\gMod.dll).VersionInfo.FileVersion
if ([string]::IsNullOrEmpty($fileVersionInfo)) {
Write-Host "The DLL file version information could not be retrieved."
exit 1
} else {
Write-Host "FileVersionInfo: $fileVersionInfo"
echo "::set-output name=version::$fileVersionInfo"
}
shell: pwsh
- name: Publish release
uses: Xotl/cool-github-releases@v1.1.8
with:
mode: update
tag_name: v${{ steps.set_version.outputs.version }}
release_name: gMod v${{ steps.set_version.outputs.version }}
assets: .\bin\Release\gMod.dll
github_token: ${{ env.GITHUB_TOKEN }}
replace_assets: true
body_mrkdwn: ${{ env.Changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+92
View File
@@ -0,0 +1,92 @@
# This continuous integration pipeline is triggered anytime a user pushes code to the repo.
# This pipeline builds the Wpf project, runs unit tests, then saves the MSIX build artifact.
name: uMod CI Pipeline
on:
pull_request:
branches:
- master
workflow_dispatch:
jobs:
build:
strategy:
matrix:
targetplatform: [x86]
runs-on: windows-latest
env:
Configuration: Release
Actions_Allow_Unsecure_Commands: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
#https://stackoverflow.com/questions/61037714/how-to-install-an-old-version-of-the-direct-x-api-in-github-actions
- name: Config
run: echo "DXSDK_DIR=DXSDK" >> $GITHUB_ENV
shell: bash
- name: Cache
id: cache
uses: actions/cache@v1
with:
path: DXSDK
key: DXSDK
- name: Cache create
if: steps.cache.outputs.cache-hit != 'true'
run: |
curl -L https://download.microsoft.com/download/a/e/7/ae743f1f-632b-4809-87a9-aa1bb3458e31/DXSDK_Jun10.exe -o _DX2010_.exe
7z x _DX2010_.exe DXSDK/Include
7z x _DX2010_.exe DXSDK/Lib/x86
shell: bash
- name: Echo cache
run: echo ${{ env.DXSDK_DIR }}
- name: List dxsdk files
run: |
cd DXSDK
ls
cd Include
ls
cd ../Lib/x86
ls
- name: Copy DirectX headers to project include directory
run: Copy-Item -Path "${{ env.DXSDK_DIR }}/Include/*" -Destination header/ -Recurse -Force
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
shell: pwsh
- name: Ensure Lib directory exists and copy DirectX libraries
run: |
$libDir = "Lib/"
if (-Not (Test-Path -Path $libDir)) {
New-Item -ItemType Directory -Path $libDir
}
Copy-Item -Path "${{ env.DXSDK_DIR }}/Lib/x86/*" -Destination $libDir -Recurse -Force
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
shell: pwsh
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.3.1
- name: Build CMake Files
run: cmake -S . -B build -A Win32
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
- name: Build binaries
run: cmake --build build --config Release
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
+52
View File
@@ -0,0 +1,52 @@
# IDE
*.vs
*.user
*.settings
*.vscode
*.project
*.cproject
# Build directories
Release
Debug
bin/
*/Debug
*/Release
*/bin
*/obj
# Bloated Windows Databases
*.sdf
*.opensdf
*.suo
*.exp
*.db
*.pdb
*.idb
*.ilk
*.opendb
*.log
*.lastbuildstate
# Compiled files
*.slo
*.lo
*.o
*.obj
*.exe
*.wxs
*.wixobj
*.msi
# Precompiled Headers
*.gch
*.pch
*.idb
*.pdb
*.opendb
*.wixpdb
/out
/build
.idea
-71
View File
@@ -1,71 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>uMod 1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>?name?</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>make</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildLocation</key>
<value>${workspace_loc:/uMod/Debug}</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>true</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
@@ -1,66 +0,0 @@
#Sun Mar 11 21:51:23 CET 2012
eclipse.preferences.version=1
org.eclipse.cdt.codan.checkers.errnoreturn=Warning
org.eclipse.cdt.codan.checkers.errnoreturn.params={implicit\=>false}
org.eclipse.cdt.codan.checkers.errreturnvalue=Error
org.eclipse.cdt.codan.checkers.errreturnvalue.params={}
org.eclipse.cdt.codan.checkers.noreturn=Error
org.eclipse.cdt.codan.checkers.noreturn.params={implicit\=>false}
org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error
org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error
org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning
org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={}
org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error
org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={}
org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning
org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={no_break_comment\=>"no break",last_case_param\=>true,empty_case_param\=>false}
org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning
org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={unknown\=>false,exceptions\=>()}
org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error
org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error
org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error
org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error
org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error
org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info
org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={pattern\=>"^[a-z]",macro\=>true,exceptions\=>()}
org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning
org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={}
org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error
org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error
org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error
org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning
org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={}
org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning
org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={}
org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning
org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={macro\=>true,exceptions\=>()}
org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning
org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={paramNot\=>false}
org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning
org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={else\=>false,afterelse\=>false}
org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning
org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={}
org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning
org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={}
org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning
org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={exceptions\=>("@(\#)","$Id")}
org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error
org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+64
View File
@@ -0,0 +1,64 @@
cmake_minimum_required(VERSION 3.16)
set(CMAKE_GENERATOR_PLATFORM win32)
project(gMod)
if(NOT(CMAKE_SIZEOF_VOID_P EQUAL 4))
message(FATAL_ERROR "You are configuring a non 32-bit build, this is not supported. Run cmake with `-A Win32`")
endif()
set(VERSION_MAJOR 1)
set(VERSION_MINOR 5)
set(VERSION_PATCH 3)
set(VERSION_TWEAK 0)
set(VERSION_RC "${CMAKE_CURRENT_BINARY_DIR}/version.rc")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${VERSION_RC}" @ONLY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin/")
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
add_compile_options(/MP /permissive-)
find_library(D3D9_LIB NAMES d3d9 PATHS $ENV{DXSDK_DIR}/lib/x86 NO_DEFAULT_PATH)
find_library(D3DX9_LIB NAMES d3dx9 PATHS $ENV{DXSDK_DIR}/lib/x86 NO_DEFAULT_PATH)
find_library(DXGUID_LIB NAMES dxguid PATHS $ENV{DXSDK_DIR}/lib/x86 NO_DEFAULT_PATH)
if(NOT D3D9_LIB)
find_library(D3D9_LIB NAMES d3d9 PATHS ${CMAKE_SOURCE_DIR}/Lib)
endif()
if(NOT D3DX9_LIB)
find_library(D3DX9_LIB NAMES d3dx9 PATHS ${CMAKE_SOURCE_DIR}/Lib)
endif()
if(NOT DXGUID_LIB)
find_library(DXGUID_LIB NAMES dxguid PATHS ${CMAKE_SOURCE_DIR}/Lib)
endif()
add_library(gMod SHARED)
file(GLOB SOURCES
"header/*.h"
"source/*.cpp"
${VERSION_RC}
)
target_link_libraries(gMod PRIVATE ${D3D9_LIB} ${D3DX9_LIB} ${DXGUID_LIB})
target_include_directories(gMod PRIVATE $ENV{DXSDK_DIR}/Include)
target_include_directories(gMod PUBLIC "header")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${SOURCES})
target_sources(gMod PRIVATE ${SOURCES})
target_compile_definitions(gMod PRIVATE
"NOMINMAX"
"_WIN32_WINNT=_WIN32_WINNT_WIN7"
"WIN32_LEAN_AND_MEAN"
"VC_EXTRALEAN"
DIRECT_INJECTION
LOG_MESSAGE
)
+26
View File
@@ -0,0 +1,26 @@
{
"configurations": [
{
"name": "x86-Debug",
"generator": "Visual Studio 17 2022",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x86" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x86-Release",
"generator": "Visual Studio 17 2022",
"configurationType": "Release",
"inheritEnvironments": [ "msvc_x86" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
}
]
}
+9 -58
View File
@@ -1,58 +1,9 @@
The licence is set for each file separately.
1) How to compile the GUI:
1.1) You need:
- wxWidgets 2.9. (an earlier version won't work, cause I use wxString functions only available in 2.9., I use atm 2.9.2)
In the package a makefile for the gcc (makefile.gcc) and a makefile for the MS Visual C Compiler (makefile.vc) is included, but you can generate your own makefile for the compiler of your choice.
Compiling wxWidgets:
- Compile it with BUILD=release otherwise the executable will be very large.
- The vc compiler somehow generates a smaller executable.
- Set the linkage to static (in the config.gcc or config.vc) before you compile the wxWidgets, to ensure, that also on other PC's your executable will run.
If you use my makefiles, you have to change the WX_DIR Variable to your wxWidgets directory. This Variable is nearly at the beginning of the makefiles.
note: I have set the linkage to static in the corresponding config.* files, if you have not compiled you wxWidgets with static linkage the compiler will fail, when linking the GUI.
1.2) Using gcc:
change in the uMod_GUI Directory and type:
mingw32-make -f makefile.gcc BUILD=release
(note: with the options -j 4 you compile simultaneously with 4 threads)
1.3) Using vc:
change in the uMod_GUI Directory and type:
nmake -f makefile.vc BUILD=release
(note: you need to use the special MS Visual prompt)
2) How to compile the dll:
2.1) You need:
- The DirectX SDK (I use June 2010)
- MS Visual C Compiler (I use the free Express 2010 version)
- maybe the Microsoft Windows SDK
There exist two makefiles, one for the mingw32-make.exe (makefile.gcc) which call the vc compiler and one for the nmake.exe (makefile.vc) which also calls the vc compiler. I have created the makefile.gcc only to use the -j 4 option of the gnu make.
You have to compile the 3 dll's separately (one for each injection method). The dll will be copied after successful compilation in the uMod_GUI/bin directory.
If you want to use the logging mode of the dll you have to parse LOG_MESSAGE=1
2.2) Using gcc (BUT you need the vc compiler!):
change in the uMod_DX9 Directory and type:
mingw32-make -f makefile.gcc
mingw32-make -f makefile.gcc DI=1
mingw32-make -f makefile.gcc NI=1
(note: you need to use the special MS Visual prompt)
(note: with the options -j 4 you compile simultaneously with 4 threads)
2.3) Using vc:
change in the uMod_DX9 Directory and type:
nmake -f makefile.vc
nmake -f makefile.vc DI=1
nmake -f makefile.vc NI=1
(note: you need to use the special MS Visual prompt)
Requirements:
- The DirectX SDK (I use June 2010)
- Visual Studio (2010+)
(- Maybe CMake if you don't want to use Visual Studio)
Usage:
Create a file in the root GuildWars folder (where gw.exe is located) called modlist.txt
Each line in the modlist.txt is the full path to a mod you want to load (eg. D:Games\uMod\Mods\Borderless Cartography Made Easy 2015 1.3.tpf)
uMod will load all these files on startup
+165
View File
@@ -0,0 +1,165 @@
#pragma once
#include "uMod_GlobalDefines.h"
#include "uMod_IDirect3DTexture9.h"
extern unsigned int gl_ErrorState;
using TextureFileStruct = struct {
bool ForceReload; // to force a reload of the texture (if it is already modded)
char* pData; // store texture file as file in memory
unsigned int Size; // size of file
int NumberOfTextures;
int Reference; // for a fast delete in the FileHandler
IDirect3DBaseTexture9** Textures; // pointer to the fake textures
MyTypeHash Hash; // hash value
};
class uMod_FileHandler // array to store TextureFileStruct
{
public:
uMod_FileHandler();
~uMod_FileHandler();
int Add(TextureFileStruct* file);
int Remove(TextureFileStruct* file);
int GetNumber() { return Number; }
TextureFileStruct* operator [](int i)
{
if (i < 0 || i >= Number) {
return nullptr;
}
return Files[i / FieldLength][i % FieldLength];
}
protected:
static constexpr int FieldLength = 1024;
long Number;
int FieldCounter;
TextureFileStruct*** Files;
};
template <class T>
class uMod_TextureHandler // array to store uMod_IDirect3DTexture9, uMod_IDirect3DVolumeTexture9 or uMod_IDirect3DCubeTexture9
{
public:
uMod_TextureHandler();
~uMod_TextureHandler();
int Add(T* texture);
int Remove(T* texture);
int GetNumber() { return Number; }
T* operator [](int i)
{
if (i < 0 || i >= Number) {
return nullptr;
}
return Textures[i / FieldLength][i % FieldLength];
}
private:
static constexpr int FieldLength = 1024;
long Number;
int FieldCounter;
T*** Textures;
};
template <class T>
uMod_TextureHandler<T>::uMod_TextureHandler()
{
Message("uMod_TextureHandler(): %lu\n", this);
Number = 0;
FieldCounter = 0;
Textures = NULL;
}
template <class T>
uMod_TextureHandler<T>::~uMod_TextureHandler()
{
Message("~uMod_TextureHandler(): %lu\n", this);
if (Textures != nullptr) {
for (int i = 0; i < FieldCounter; i++) {
delete [] Textures[i];
}
delete [] Textures;
}
}
template <class T>
int uMod_TextureHandler<T>::Add(T* pTexture)
{
Message("uMod_TextureHandler::Add( %lu): %lu\n", pTexture, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
if (pTexture->Reference >= 0) {
return RETURN_TEXTURE_ALLREADY_ADDED;
}
if (Number / FieldLength == FieldCounter) {
T*** temp = nullptr;
try { temp = new T**[FieldCounter + 10]; }
catch (...) {
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return RETURN_NO_MEMORY;
}
for (int i = 0; i < FieldCounter; i++) {
temp[i] = Textures[i];
}
for (int i = FieldCounter; i < FieldCounter + 10; i++) {
temp[i] = NULL;
}
FieldCounter += 10;
delete [] Textures;
Textures = temp;
}
if (Number % FieldLength == 0) {
try {
if (Textures[Number / FieldLength] == NULL) {
Textures[Number / FieldLength] = new T*[FieldLength];
}
}
catch (...) {
Textures[Number / FieldLength] = NULL;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return RETURN_NO_MEMORY;
}
}
Textures[Number / FieldLength][Number % FieldLength] = pTexture;
pTexture->Reference = Number++;
return RETURN_OK;
}
template <class T>
int uMod_TextureHandler<T>::Remove(T* pTexture) //will be called, if a texture is completely released
{
Message("uMod_TextureHandler::Remove( %lu): %lu\n", pTexture, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
int ref = pTexture->Reference;
if (ref < 0) {
return RETURN_OK; // returning if no TextureHandlerRef is set
}
if (ref < (--Number)) {
Textures[ref / FieldLength][ref % FieldLength] = Textures[Number / FieldLength][Number % FieldLength];
Textures[ref / FieldLength][ref % FieldLength]->Reference = ref;
}
return RETURN_OK;
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include <d3d9.h>
void InitInstance(HINSTANCE hModule);
void ExitInstance();
void LoadOriginalDll();
bool FindLoadedDll();
bool IsDesiredModule(HMODULE hModule, HANDLE hProcess);
bool HasDesiredMethods(HMODULE hModule, HANDLE hProcess);
bool HookThisProgram(char* ret);
DWORD WINAPI ServerThread(LPVOID lpParam);
void* DetourFunc(BYTE* src, const BYTE* dst, int len);
bool RetourFunc(BYTE* src, BYTE* restore, int len);
IDirect3D9*APIENTRY uMod_Direct3DCreate9(UINT SDKVersion);
HRESULT APIENTRY uMod_Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex** ppD3D);
#ifdef DIRECT_INJECTION
void Nothing();
#endif
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include <iostream>
#ifdef LOG_MESSAGE
extern FILE* gl_File;
#define Message(...) { printf(__VA_ARGS__); }
#ifdef HOOK_INJECTION
#define OpenMessage(...) {if (fopen_s( &gl_File, "uMod_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "HI R40: 0000000\n");}
#endif
#ifdef DIRECT_INJECTION
#define OpenMessage(...)
#endif
#ifdef NO_INJECTION
#define OpenMessage(...) {if (fopen_s( &gl_File, "uMod_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "NI R40: 0000000\n");}
#endif
#define CloseMessage(...)
#else
#define OpenMessage(...)
#define Message(...)
#define CloseMessage(...)
#endif
#ifdef __CDT_PARSER__
typedef unsigned long DWORD64;
typedef unsigned long DWORD32;
#define STDMETHOD(method) virtual HRESULT method
#define STDMETHOD_(ret, method) virtual ret method
#define sprintf_s(...)
#define fprintf(...)
#define fclose(...)
#define fseek(...)
#define ftell(...) 0
#define fflush(...)
typedef LONG HRESULT;
#define UNREFERENCED_PARAMETER(...)
#endif
+43 -73
View File
@@ -1,73 +1,43 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_ERROR_H_
#define uMod_ERROR_H_
// define return values, a value less than zero indicates an error
#define RETURN_OK 0
#define RETURN_FATAL_ERROR -1
#define RETURN_NO_MEMORY -2
#define RETURN_BAD_ARGUMENT -3
#define RETURN_NO_IDirect3DDevice9 -10
#define RETURN_TEXTURE_NOT_LOADED -20
#define RETURN_TEXTURE_NOT_SAVED -21
#define RETURN_TEXTURE_NOT_FOUND -22
#define RETURN_TEXTURE_ALLREADY_ADDED -23
#define RETURN_TEXTURE_NOT_SWITCHED -24
#define RETURN_LockRect_FAILED -30
#define RETURN_UnlockRect_FAILED -31
#define RETURN_GetLevelDesc_FAILED -32
#define RETURN_NO_MUTEX -40
#define RETURN_MUTEX_LOCK -41
#define RETURN_MUTEX_UNLOCK -42
#define RETURN_UPDATE_ALLREADY_ADDED -50
#define RETURN_FILE_NOT_LOADED -51
#define RETURN_PIPE_NOT_OPENED 60
// define error states
#define uMod_ERROR_FATAL 1u
#define uMod_ERROR_MUTEX 1u<<1
#define uMod_ERROR_PIPE 1u<<2
#define uMod_ERROR_MEMORY 1u<<3
#define uMod_ERROR_TEXTURE 1u<<4
#define uMod_ERROR_MULTIPLE_IDirect3D9 1u<<5
#define uMod_ERROR_MULTIPLE_IDirect3DDevice9 1u<<6
#define uMod_ERROR_UPDATE 1u<<7
#define uMod_ERROR_SERVER 1u<<8
#endif /* uMod_ERROR_H_ */
#pragma once
// define return values, a value less than zero indicates an error
#define RETURN_OK 0
#define RETURN_FATAL_ERROR -1
#define RETURN_NO_MEMORY -2
#define RETURN_BAD_ARGUMENT -3
#define RETURN_NO_IDirect3DDevice9 -10
#define RETURN_TEXTURE_NOT_LOADED -20
#define RETURN_TEXTURE_NOT_SAVED -21
#define RETURN_TEXTURE_NOT_FOUND -22
#define RETURN_TEXTURE_ALLREADY_ADDED -23
#define RETURN_TEXTURE_NOT_SWITCHED -24
#define RETURN_LockRect_FAILED -30
#define RETURN_UnlockRect_FAILED -31
#define RETURN_GetLevelDesc_FAILED -32
#define RETURN_NO_MUTEX -40
#define RETURN_MUTEX_LOCK -41
#define RETURN_MUTEX_UNLOCK -42
#define RETURN_UPDATE_ALLREADY_ADDED -50
#define RETURN_FILE_NOT_LOADED -51
#define RETURN_PIPE_NOT_OPENED 60
// define error states
#define uMod_ERROR_FATAL 1u
#define uMod_ERROR_MUTEX 1u<<1
#define uMod_ERROR_PIPE 1u<<2
#define uMod_ERROR_MEMORY 1u<<3
#define uMod_ERROR_TEXTURE 1u<<4
#define uMod_ERROR_MULTIPLE_IDirect3D9 1u<<5
#define uMod_ERROR_MULTIPLE_IDirect3DDevice9 1u<<6
#define uMod_ERROR_UPDATE 1u<<7
#define uMod_ERROR_SERVER 1u<<8
+56
View File
@@ -0,0 +1,56 @@
#pragma once
#include "uMod_Main.h"
#include <string>
#include <vector>
#include "uMod_Texture.h"
class uMod_File {
public:
uMod_File();
uMod_File(std::string file);
~uMod_File();
bool FileSupported();
bool PackageFile();
bool SingleFile();
//int AddSingleFileToNode( uMod_TreeViewNode* node);
int GetContentTemplate(const std::string& content);
/*
int GetComment( wxString &tool_tip);
int GetContent( AddTextureClass &tex, bool add);
*/
int GetContent();
int SetFile(const std::string file)
{
FileName = file;
Loaded = false;
return 0;
}
std::string GetFile() { return FileName; }
std::vector<UModTexture> Textures;
private:
int ReadFile();
int UnXOR();
/*
int GetCommentZip( wxString &tool_tip);
int GetCommentTpf( wxString &tool_tip);
*/
int AddFile();
int AddZip();
int AddTpf();
int AddContent(const char* pw);
std::string FileName;
bool Loaded;
bool XORed;
char* FileInMemory;
unsigned int MemoryLength;
unsigned int FileLen;
unsigned long long FileHash;
};
+45
View File
@@ -0,0 +1,45 @@
#pragma once
//#define MyTypeHash DWORD64
#define MyTypeHash DWORD32
#define BIG_BUFSIZE 1<<24
#define SMALL_BUFSIZE 1<<10
using MsgStruct = struct {
unsigned int Control;
unsigned int Value;
MyTypeHash Hash;
};
using PipeStruct = struct {
HANDLE In;
HANDLE Out;
};
#define uMod_APP_DX9 L"uMod_DX9.txt"
#define uMod_APP_DIR L"uMod"
#define uMod_VERSION L"uMod V 1.0"
#define PIPE_uMod2Game L"\\\\.\\pipe\\uMod2Game"
#define PIPE_Game2uMod L"\\\\.\\pipe\\Game2uMod"
#define CONTROL_ADD_TEXTURE 1
#define CONTROL_FORCE_RELOAD_TEXTURE 2
#define CONTROL_REMOVE_TEXTURE 3
#define CONTROL_FORCE_RELOAD_TEXTURE_DATA 4
#define CONTROL_ADD_TEXTURE_DATA 5
#define CONTROL_MORE_TEXTURES 6
#define CONTROL_SAVE_ALL 10
#define CONTROL_SAVE_SINGLE 11
#define CONTROL_SET_DIR 12
#define CONTROL_KEY_BACK 20
#define CONTROL_KEY_SAVE 21
#define CONTROL_KEY_NEXT 22
#define CONTROL_FONT_COLOUR 30
#define CONTROL_TEXTURE_COLOUR 31
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <d3d9.h>
#include "uMod_TextureServer.h"
class uMod_IDirect3D9 : public IDirect3D9 {
public:
uMod_IDirect3D9(IDirect3D9* pOriginal, uMod_TextureServer* server);
virtual ~uMod_IDirect3D9();
// The original DX9 function definitions
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) override;
ULONG __stdcall AddRef() override;
ULONG __stdcall Release() override;
HRESULT __stdcall RegisterSoftwareDevice(void* pInitializeFunction) override;
UINT __stdcall GetAdapterCount() override;
HRESULT __stdcall GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) override;
UINT __stdcall GetAdapterModeCount(UINT Adapter, D3DFORMAT Format) override;
HRESULT __stdcall EnumAdapterModes(UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) override;
HRESULT __stdcall GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE* pMode) override;
HRESULT __stdcall CheckDeviceType(UINT iAdapter, D3DDEVTYPE DevType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) override;
HRESULT __stdcall CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) override;
HRESULT __stdcall CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) override;
HRESULT __stdcall CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) override;
HRESULT __stdcall CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) override;
HRESULT __stdcall GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) override;
HMONITOR __stdcall GetAdapterMonitor(UINT Adapter) override;
HRESULT __stdcall CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface) override;
private:
IDirect3D9* m_pIDirect3D9;
uMod_TextureServer* uMod_Server;
};
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include <d3d9.h>
#include "uMod_TextureServer.h"
class uMod_IDirect3D9Ex : public IDirect3D9Ex {
public:
uMod_IDirect3D9Ex(IDirect3D9Ex* pOriginal, uMod_TextureServer* server);
virtual ~uMod_IDirect3D9Ex();
// The original DX9 function definitions
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) override;
ULONG __stdcall AddRef() override;
ULONG __stdcall Release() override;
HRESULT __stdcall RegisterSoftwareDevice(void* pInitializeFunction) override;
UINT __stdcall GetAdapterCount() override;
HRESULT __stdcall GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) override;
UINT __stdcall GetAdapterModeCount(UINT Adapter, D3DFORMAT Format) override;
HRESULT __stdcall EnumAdapterModes(UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) override;
HRESULT __stdcall GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE* pMode) override;
HRESULT __stdcall CheckDeviceType(UINT iAdapter, D3DDEVTYPE DevType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed) override;
HRESULT __stdcall CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) override;
HRESULT __stdcall CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) override;
HRESULT __stdcall CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) override;
HRESULT __stdcall CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) override;
HRESULT __stdcall GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) override;
HMONITOR __stdcall GetAdapterMonitor(UINT Adapter) override;
HRESULT __stdcall CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface) override;
HRESULT __stdcall CreateDeviceEx(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode,
IDirect3DDevice9Ex** ppReturnedDeviceInterface) override;
HRESULT __stdcall EnumAdapterModesEx(UINT Adapter, const D3DDISPLAYMODEFILTER* pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode) override;
HRESULT __stdcall GetAdapterDisplayModeEx(UINT Adapter, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) override;
HRESULT __stdcall GetAdapterLUID(UINT Adapter, LUID* pLUID) override;
UINT __stdcall GetAdapterModeCountEx(UINT Adapter, const D3DDISPLAYMODEFILTER* pFilter) override;
private:
IDirect3D9Ex* m_pIDirect3D9Ex;
uMod_TextureServer* uMod_Server;
};
+87
View File
@@ -0,0 +1,87 @@
#pragma once
#include <d3d9.h>
interface uMod_IDirect3DCubeTexture9 : IDirect3DCubeTexture9 {
uMod_IDirect3DCubeTexture9(IDirect3DCubeTexture9** ppTex, IDirect3DDevice9* pIDirect3DDevice9)
{
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
m_D3Ddev = pIDirect3DDevice9; //device pointer
CrossRef_D3Dtex = nullptr; //cross reference
// fake texture: store the pointer to the original uMod_IDirect3DCubeTexture9 object, needed if a fake texture is unselected
// original texture: stores the pointer to the fake texture object, is needed if original texture is deleted,
// thus the fake texture can also be deleted
Reference = -1; //need for fast deleting
Hash = 0u;
FAKE = false;
}
// callback interface
IDirect3DCubeTexture9* m_D3Dtex;
uMod_IDirect3DCubeTexture9* CrossRef_D3Dtex;
IDirect3DDevice9* m_D3Ddev;
int Reference;
MyTypeHash Hash;
bool FAKE;
// original interface
STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj) override;
STDMETHOD_(ULONG, AddRef)() override;
STDMETHOD_(ULONG, Release)() override;
STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice) override;
STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) override;
STDMETHOD(GetPrivateData)(REFGUID refguid, void* pData, DWORD* pSizeOfData) override;
STDMETHOD(FreePrivateData)(REFGUID refguid) override;
STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew) override;
STDMETHOD_(DWORD, GetPriority)() override;
STDMETHOD_(void, PreLoad)() override;
STDMETHOD_(D3DRESOURCETYPE, GetType)() override;
STDMETHOD_(DWORD, SetLOD)(DWORD LODNew) override;
STDMETHOD_(DWORD, GetLOD)() override;
STDMETHOD_(DWORD, GetLevelCount)() override;
STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType) override;
STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)() override;
STDMETHOD_(void, GenerateMipSubLevels)() override;
STDMETHOD(AddDirtyRect)(D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) override;
STDMETHOD(GetLevelDesc)(UINT Level, D3DSURFACE_DESC* pDesc) override;
STDMETHOD(GetCubeMapSurface)(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) override;
STDMETHOD(LockRect)(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect, DWORD Flags) override;
STDMETHOD(UnlockRect)(D3DCUBEMAP_FACES FaceType, UINT Level) override;
int GetHash(MyTypeHash& hash);
};
inline void UnswitchTextures(uMod_IDirect3DCubeTexture9* pTexture)
{
uMod_IDirect3DCubeTexture9* CrossRef = pTexture->CrossRef_D3Dtex;
if (CrossRef != nullptr) {
// switch textures back
IDirect3DCubeTexture9* cpy = pTexture->m_D3Dtex;
pTexture->m_D3Dtex = CrossRef->m_D3Dtex;
CrossRef->m_D3Dtex = cpy;
// cancel the link
CrossRef->CrossRef_D3Dtex = nullptr;
pTexture->CrossRef_D3Dtex = nullptr;
}
}
inline int SwitchTextures(uMod_IDirect3DCubeTexture9* pTexture1, uMod_IDirect3DCubeTexture9* pTexture2)
{
if (pTexture1->m_D3Ddev == pTexture2->m_D3Ddev && pTexture1->CrossRef_D3Dtex == nullptr && pTexture2->CrossRef_D3Dtex == nullptr) {
// make cross reference
pTexture1->CrossRef_D3Dtex = pTexture2;
pTexture2->CrossRef_D3Dtex = pTexture1;
// switch textures
IDirect3DCubeTexture9* cpy = pTexture2->m_D3Dtex;
pTexture2->m_D3Dtex = pTexture1->m_D3Dtex;
pTexture1->m_D3Dtex = cpy;
return RETURN_OK;
}
return RETURN_TEXTURE_NOT_SWITCHED;
}
+195
View File
@@ -0,0 +1,195 @@
#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DVolumeTexture9.h"
#include "uMod_IDirect3DCubeTexture9.h"
class uMod_IDirect3DDevice9 : public IDirect3DDevice9 {
public:
uMod_IDirect3DDevice9(IDirect3DDevice9* pOriginal, uMod_TextureServer* server, int back_buffer_count);
virtual ~uMod_IDirect3DDevice9();
// START: The original DX9 function definitions
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) override;
ULONG __stdcall AddRef() override;
ULONG __stdcall Release() override;
HRESULT __stdcall TestCooperativeLevel() override;
UINT __stdcall GetAvailableTextureMem() override;
HRESULT __stdcall EvictManagedResources() override;
HRESULT __stdcall GetDirect3D(IDirect3D9** ppD3D9) override;
HRESULT __stdcall GetDeviceCaps(D3DCAPS9* pCaps) override;
HRESULT __stdcall GetDisplayMode(UINT iSwapChain, D3DDISPLAYMODE* pMode) override;
HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS* pParameters) override;
HRESULT __stdcall SetCursorProperties(UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) override;
void __stdcall SetCursorPosition(int X, int Y, DWORD Flags) override;
BOOL __stdcall ShowCursor(BOOL bShow) override;
HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) override;
HRESULT __stdcall GetSwapChain(UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) override;
UINT __stdcall GetNumberOfSwapChains() override;
HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters) override;
HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect, HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) override;
HRESULT __stdcall GetBackBuffer(UINT iSwapChain, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) override;
HRESULT __stdcall GetRasterStatus(UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) override;
HRESULT __stdcall SetDialogBoxMode(BOOL bEnableDialogs) override;
void __stdcall SetGammaRamp(UINT iSwapChain, DWORD Flags,CONST D3DGAMMARAMP* pRamp) override;
void __stdcall GetGammaRamp(UINT iSwapChain, D3DGAMMARAMP* pRamp) override;
HRESULT __stdcall CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override;
HRESULT __stdcall UpdateSurface(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint) override;
HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) override;
HRESULT __stdcall GetRenderTargetData(IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) override;
HRESULT __stdcall GetFrontBufferData(UINT iSwapChain, IDirect3DSurface9* pDestSurface) override;
HRESULT __stdcall StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) override;
HRESULT __stdcall ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect, D3DCOLOR color) override;
HRESULT __stdcall CreateOffscreenPlainSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override;
HRESULT __stdcall SetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) override;
HRESULT __stdcall GetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget) override;
HRESULT __stdcall SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil) override;
HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface) override;
HRESULT __stdcall BeginScene() override;
HRESULT __stdcall EndScene() override;
HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) override;
HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) override;
HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) override;
HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) override;
HRESULT __stdcall SetViewport(CONST D3DVIEWPORT9* pViewport) override;
HRESULT __stdcall GetViewport(D3DVIEWPORT9* pViewport) override;
HRESULT __stdcall SetMaterial(CONST D3DMATERIAL9* pMaterial) override;
HRESULT __stdcall GetMaterial(D3DMATERIAL9* pMaterial) override;
HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT9* pLight) override;
HRESULT __stdcall GetLight(DWORD Index, D3DLIGHT9* pLight) override;
HRESULT __stdcall LightEnable(DWORD Index, BOOL Enable) override;
HRESULT __stdcall GetLightEnable(DWORD Index, BOOL* pEnable) override;
HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane) override;
HRESULT __stdcall GetClipPlane(DWORD Index, float* pPlane) override;
HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) override;
HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State, DWORD* pValue) override;
HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB) override;
HRESULT __stdcall BeginStateBlock() override;
HRESULT __stdcall EndStateBlock(IDirect3DStateBlock9** ppSB) override;
HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS9* pClipStatus) override;
HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS9* pClipStatus) override;
HRESULT __stdcall GetTexture(DWORD Stage, IDirect3DBaseTexture9** ppTexture) override;
HRESULT __stdcall SetTexture(DWORD Stage, IDirect3DBaseTexture9* pTexture) override;
HRESULT __stdcall GetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) override;
HRESULT __stdcall SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) override;
HRESULT __stdcall GetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) override;
HRESULT __stdcall SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) override;
HRESULT __stdcall ValidateDevice(DWORD* pNumPasses) override;
HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries) override;
HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY* pEntries) override;
HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber) override;
HRESULT __stdcall GetCurrentTexturePalette(UINT* PaletteNumber) override;
HRESULT __stdcall SetScissorRect(CONST RECT* pRect) override;
HRESULT __stdcall GetScissorRect(RECT* pRect) override;
HRESULT __stdcall SetSoftwareVertexProcessing(BOOL bSoftware) override;
BOOL __stdcall GetSoftwareVertexProcessing() override;
HRESULT __stdcall SetNPatchMode(float nSegments) override;
float __stdcall GetNPatchMode() override;
HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) override;
HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) override;
HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) override;
HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT PrimitiveCount,CONST void* pIndexData, D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
UINT VertexStreamZeroStride) override;
HRESULT __stdcall ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) override;
HRESULT __stdcall CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) override;
HRESULT __stdcall SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl) override;
HRESULT __stdcall GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl) override;
HRESULT __stdcall SetFVF(DWORD FVF) override;
HRESULT __stdcall GetFVF(DWORD* pFVF) override;
HRESULT __stdcall CreateVertexShader(CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) override;
HRESULT __stdcall SetVertexShader(IDirect3DVertexShader9* pShader) override;
HRESULT __stdcall GetVertexShader(IDirect3DVertexShader9** ppShader) override;
HRESULT __stdcall SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData, UINT Vector4fCount) override;
HRESULT __stdcall GetVertexShaderConstantF(UINT StartRegister, float* pConstantData, UINT Vector4fCount) override;
HRESULT __stdcall SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData, UINT Vector4iCount) override;
HRESULT __stdcall GetVertexShaderConstantI(UINT StartRegister, int* pConstantData, UINT Vector4iCount) override;
HRESULT __stdcall SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData, UINT BoolCount) override;
HRESULT __stdcall GetVertexShaderConstantB(UINT StartRegister, BOOL* pConstantData, UINT BoolCount) override;
HRESULT __stdcall SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) override;
HRESULT __stdcall GetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9** ppStreamData, UINT* OffsetInBytes, UINT* pStride) override;
HRESULT __stdcall SetStreamSourceFreq(UINT StreamNumber, UINT Divider) override;
HRESULT __stdcall GetStreamSourceFreq(UINT StreamNumber, UINT* Divider) override;
HRESULT __stdcall SetIndices(IDirect3DIndexBuffer9* pIndexData) override;
HRESULT __stdcall GetIndices(IDirect3DIndexBuffer9** ppIndexData) override;
HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) override;
HRESULT __stdcall SetPixelShader(IDirect3DPixelShader9* pShader) override;
HRESULT __stdcall GetPixelShader(IDirect3DPixelShader9** ppShader) override;
HRESULT __stdcall SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData, UINT Vector4fCount) override;
HRESULT __stdcall GetPixelShaderConstantF(UINT StartRegister, float* pConstantData, UINT Vector4fCount) override;
HRESULT __stdcall SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData, UINT Vector4iCount) override;
HRESULT __stdcall GetPixelShaderConstantI(UINT StartRegister, int* pConstantData, UINT Vector4iCount) override;
HRESULT __stdcall SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData, UINT BoolCount) override;
HRESULT __stdcall GetPixelShaderConstantB(UINT StartRegister, BOOL* pConstantData, UINT BoolCount) override;
HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) override;
HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) override;
HRESULT __stdcall DeletePatch(UINT Handle) override;
HRESULT __stdcall CreateQuery(D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) override;
// END: The original DX9 function definitions
uMod_TextureClient* GetuMod_Client() { return uMod_Client; }
uMod_IDirect3DTexture9* GetLastCreatedTexture() { return LastCreatedTexture; }
int SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture)
{
LastCreatedTexture = pTexture;
return RETURN_OK;
}
uMod_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture() { return LastCreatedVolumeTexture; }
int SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture)
{
LastCreatedVolumeTexture = pTexture;
return RETURN_OK;
}
uMod_IDirect3DCubeTexture9* GetLastCreatedCubeTexture() { return LastCreatedCubeTexture; }
int SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture)
{
LastCreatedCubeTexture = pTexture;
return RETURN_OK;
}
uMod_IDirect3DTexture9* GetSingleTexture() { return SingleTexture; }
uMod_IDirect3DVolumeTexture9* GetSingleVolumeTexture() { return SingleVolumeTexture; }
uMod_IDirect3DCubeTexture9* GetSingleCubeTexture() { return SingleCubeTexture; }
private:
int CreateSingleTexture();
IDirect3DDevice9* m_pIDirect3DDevice9;
int CounterSaveSingleTexture;
uMod_IDirect3DTexture9* SingleTexture;
uMod_IDirect3DVolumeTexture9* SingleVolumeTexture;
uMod_IDirect3DCubeTexture9* SingleCubeTexture;
char SingleTextureMod;
D3DCOLOR TextureColour;
ID3DXFont* OSD_Font;
//D3DCOLOR FontColour;
int BackBufferCount;
bool NormalRendering;
int uMod_Reference;
uMod_IDirect3DTexture9* LastCreatedTexture;
uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture;
uMod_IDirect3DCubeTexture9* LastCreatedCubeTexture;
uMod_TextureServer* uMod_Server;
uMod_TextureClient* uMod_Client;
};
+216
View File
@@ -0,0 +1,216 @@
#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DVolumeTexture9.h"
#include "uMod_IDirect3DCubeTexture9.h"
class uMod_IDirect3DDevice9Ex : public IDirect3DDevice9Ex {
public:
uMod_IDirect3DDevice9Ex(IDirect3DDevice9Ex* pOriginal, uMod_TextureServer* server, int back_buffer_count);
virtual ~uMod_IDirect3DDevice9Ex();
// START: The original DX9 function definitions
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) override;
ULONG __stdcall AddRef() override;
ULONG __stdcall Release() override;
HRESULT __stdcall TestCooperativeLevel() override;
UINT __stdcall GetAvailableTextureMem() override;
HRESULT __stdcall EvictManagedResources() override;
HRESULT __stdcall GetDirect3D(IDirect3D9** ppD3D9) override;
HRESULT __stdcall GetDeviceCaps(D3DCAPS9* pCaps) override;
HRESULT __stdcall GetDisplayMode(UINT iSwapChain, D3DDISPLAYMODE* pMode) override;
HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS* pParameters) override;
HRESULT __stdcall SetCursorProperties(UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) override;
void __stdcall SetCursorPosition(int X, int Y, DWORD Flags) override;
BOOL __stdcall ShowCursor(BOOL bShow) override;
HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) override;
HRESULT __stdcall GetSwapChain(UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) override;
UINT __stdcall GetNumberOfSwapChains() override;
HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters) override;
HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect, HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) override;
HRESULT __stdcall GetBackBuffer(UINT iSwapChain, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) override;
HRESULT __stdcall GetRasterStatus(UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) override;
HRESULT __stdcall SetDialogBoxMode(BOOL bEnableDialogs) override;
void __stdcall SetGammaRamp(UINT iSwapChain, DWORD Flags,CONST D3DGAMMARAMP* pRamp) override;
void __stdcall GetGammaRamp(UINT iSwapChain, D3DGAMMARAMP* pRamp) override;
HRESULT __stdcall CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override;
HRESULT __stdcall CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override;
HRESULT __stdcall UpdateSurface(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint) override;
HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) override;
HRESULT __stdcall GetRenderTargetData(IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) override;
HRESULT __stdcall GetFrontBufferData(UINT iSwapChain, IDirect3DSurface9* pDestSurface) override;
HRESULT __stdcall StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) override;
HRESULT __stdcall ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect, D3DCOLOR color) override;
HRESULT __stdcall CreateOffscreenPlainSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle) override;
HRESULT __stdcall SetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) override;
HRESULT __stdcall GetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget) override;
HRESULT __stdcall SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil) override;
HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface) override;
HRESULT __stdcall BeginScene() override;
HRESULT __stdcall EndScene() override;
HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) override;
HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) override;
HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) override;
HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) override;
HRESULT __stdcall SetViewport(CONST D3DVIEWPORT9* pViewport) override;
HRESULT __stdcall GetViewport(D3DVIEWPORT9* pViewport) override;
HRESULT __stdcall SetMaterial(CONST D3DMATERIAL9* pMaterial) override;
HRESULT __stdcall GetMaterial(D3DMATERIAL9* pMaterial) override;
HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT9* pLight) override;
HRESULT __stdcall GetLight(DWORD Index, D3DLIGHT9* pLight) override;
HRESULT __stdcall LightEnable(DWORD Index, BOOL Enable) override;
HRESULT __stdcall GetLightEnable(DWORD Index, BOOL* pEnable) override;
HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane) override;
HRESULT __stdcall GetClipPlane(DWORD Index, float* pPlane) override;
HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) override;
HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State, DWORD* pValue) override;
HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB) override;
HRESULT __stdcall BeginStateBlock() override;
HRESULT __stdcall EndStateBlock(IDirect3DStateBlock9** ppSB) override;
HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS9* pClipStatus) override;
HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS9* pClipStatus) override;
HRESULT __stdcall GetTexture(DWORD Stage, IDirect3DBaseTexture9** ppTexture) override;
HRESULT __stdcall SetTexture(DWORD Stage, IDirect3DBaseTexture9* pTexture) override;
HRESULT __stdcall GetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) override;
HRESULT __stdcall SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) override;
HRESULT __stdcall GetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) override;
HRESULT __stdcall SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) override;
HRESULT __stdcall ValidateDevice(DWORD* pNumPasses) override;
HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries) override;
HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY* pEntries) override;
HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber) override;
HRESULT __stdcall GetCurrentTexturePalette(UINT* PaletteNumber) override;
HRESULT __stdcall SetScissorRect(CONST RECT* pRect) override;
HRESULT __stdcall GetScissorRect(RECT* pRect) override;
HRESULT __stdcall SetSoftwareVertexProcessing(BOOL bSoftware) override;
BOOL __stdcall GetSoftwareVertexProcessing() override;
HRESULT __stdcall SetNPatchMode(float nSegments) override;
float __stdcall GetNPatchMode() override;
HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) override;
HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) override;
HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) override;
HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT PrimitiveCount,CONST void* pIndexData, D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
UINT VertexStreamZeroStride) override;
HRESULT __stdcall ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) override;
HRESULT __stdcall CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) override;
HRESULT __stdcall SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl) override;
HRESULT __stdcall GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl) override;
HRESULT __stdcall SetFVF(DWORD FVF) override;
HRESULT __stdcall GetFVF(DWORD* pFVF) override;
HRESULT __stdcall CreateVertexShader(CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) override;
HRESULT __stdcall SetVertexShader(IDirect3DVertexShader9* pShader) override;
HRESULT __stdcall GetVertexShader(IDirect3DVertexShader9** ppShader) override;
HRESULT __stdcall SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData, UINT Vector4fCount) override;
HRESULT __stdcall GetVertexShaderConstantF(UINT StartRegister, float* pConstantData, UINT Vector4fCount) override;
HRESULT __stdcall SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData, UINT Vector4iCount) override;
HRESULT __stdcall GetVertexShaderConstantI(UINT StartRegister, int* pConstantData, UINT Vector4iCount) override;
HRESULT __stdcall SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData, UINT BoolCount) override;
HRESULT __stdcall GetVertexShaderConstantB(UINT StartRegister, BOOL* pConstantData, UINT BoolCount) override;
HRESULT __stdcall SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) override;
HRESULT __stdcall GetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9** ppStreamData, UINT* OffsetInBytes, UINT* pStride) override;
HRESULT __stdcall SetStreamSourceFreq(UINT StreamNumber, UINT Divider) override;
HRESULT __stdcall GetStreamSourceFreq(UINT StreamNumber, UINT* Divider) override;
HRESULT __stdcall SetIndices(IDirect3DIndexBuffer9* pIndexData) override;
HRESULT __stdcall GetIndices(IDirect3DIndexBuffer9** ppIndexData) override;
HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) override;
HRESULT __stdcall SetPixelShader(IDirect3DPixelShader9* pShader) override;
HRESULT __stdcall GetPixelShader(IDirect3DPixelShader9** ppShader) override;
HRESULT __stdcall SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData, UINT Vector4fCount) override;
HRESULT __stdcall GetPixelShaderConstantF(UINT StartRegister, float* pConstantData, UINT Vector4fCount) override;
HRESULT __stdcall SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData, UINT Vector4iCount) override;
HRESULT __stdcall GetPixelShaderConstantI(UINT StartRegister, int* pConstantData, UINT Vector4iCount) override;
HRESULT __stdcall SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData, UINT BoolCount) override;
HRESULT __stdcall GetPixelShaderConstantB(UINT StartRegister, BOOL* pConstantData, UINT BoolCount) override;
HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) override;
HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) override;
HRESULT __stdcall DeletePatch(UINT Handle) override;
HRESULT __stdcall CreateQuery(D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) override;
HRESULT __stdcall CheckDeviceState(HWND hWindow) override;
HRESULT __stdcall CheckResourceResidency(IDirect3DResource9** pResourceArray, UINT32 NumResources) override;
HRESULT __stdcall ComposeRects(IDirect3DSurface9* pSource, IDirect3DSurface9* pDestination, IDirect3DVertexBuffer9* pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9* pDstRectDescriptors, D3DCOMPOSERECTSOP Operation, INT XOffset,
INT YOffset) override;
HRESULT __stdcall CreateDepthStencilSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) override;
HRESULT __stdcall CreateOffscreenPlainSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) override;
HRESULT __stdcall CreateRenderTargetEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage) override;
HRESULT __stdcall GetDisplayModeEx(UINT iSwapChain, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) override;
HRESULT __stdcall GetGPUThreadPriority(INT* pPriority) override;
HRESULT __stdcall GetMaximumFrameLatency(UINT* pMaxLatency) override;
HRESULT __stdcall PresentEx(const RECT* pSourceRect, const RECT* pDestRect, HWND hDestWindowOverride, const RGNDATA* pDirtyRegion, DWORD dwFlags) override;
HRESULT __stdcall ResetEx(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode) override;
HRESULT __stdcall SetConvolutionMonoKernel(UINT Width, UINT Height, float* RowWeights, float* ColumnWeights) override;
HRESULT __stdcall SetGPUThreadPriority(INT pPriority) override;
HRESULT __stdcall SetMaximumFrameLatency(UINT pMaxLatency) override;
//HRESULT __stdcall TestCooperativeLevel();
HRESULT __stdcall WaitForVBlank(UINT SwapChainIndex) override;
// END: The original DX9 function definitions
uMod_TextureClient* GetuMod_Client() { return uMod_Client; }
uMod_IDirect3DTexture9* GetLastCreatedTexture() { return LastCreatedTexture; }
int SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture)
{
LastCreatedTexture = pTexture;
return RETURN_OK;
}
uMod_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture() { return LastCreatedVolumeTexture; }
int SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture)
{
LastCreatedVolumeTexture = pTexture;
return RETURN_OK;
}
uMod_IDirect3DCubeTexture9* GetLastCreatedCubeTexture() { return LastCreatedCubeTexture; }
int SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture)
{
LastCreatedCubeTexture = pTexture;
return RETURN_OK;
}
uMod_IDirect3DTexture9* GetSingleTexture() { return SingleTexture; }
uMod_IDirect3DVolumeTexture9* GetSingleVolumeTexture() { return SingleVolumeTexture; }
uMod_IDirect3DCubeTexture9* GetSingleCubeTexture() { return SingleCubeTexture; }
private:
int CreateSingleTexture();
IDirect3DDevice9Ex* m_pIDirect3DDevice9Ex;
int CounterSaveSingleTexture;
uMod_IDirect3DTexture9* SingleTexture;
uMod_IDirect3DVolumeTexture9* SingleVolumeTexture;
uMod_IDirect3DCubeTexture9* SingleCubeTexture;
char SingleTextureMod;
D3DCOLOR TextureColour;
ID3DXFont* OSD_Font;
//D3DCOLOR FontColour;
int BackBufferCount;
bool NormalRendering;
int uMod_Reference;
uMod_IDirect3DTexture9* LastCreatedTexture;
uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture;
uMod_IDirect3DCubeTexture9* LastCreatedCubeTexture;
uMod_TextureServer* uMod_Server;
uMod_TextureClient* uMod_Client;
};
+87
View File
@@ -0,0 +1,87 @@
#pragma once
#include <d3d9.h>
interface uMod_IDirect3DTexture9 : public IDirect3DTexture9 {
uMod_IDirect3DTexture9(IDirect3DTexture9** ppTex, IDirect3DDevice9* pIDirect3DDevice9)
{
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
m_D3Ddev = pIDirect3DDevice9; //device pointer
CrossRef_D3Dtex = nullptr; //cross reference
// fake texture: store the pointer to the original uMod_IDirect3DTexture9 object, needed if a fake texture is unselected
// original texture: stores the pointer to the fake texture object, is needed if original texture is deleted,
// thus the fake texture can also be deleted
Reference = -1; //need for fast deleting
Hash = 0u;
FAKE = false;
}
// callback interface
IDirect3DTexture9* m_D3Dtex;
uMod_IDirect3DTexture9* CrossRef_D3Dtex;
IDirect3DDevice9* m_D3Ddev;
int Reference;
MyTypeHash Hash;
bool FAKE;
// original interface
STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj) override;
STDMETHOD_(ULONG, AddRef)() override;
STDMETHOD_(ULONG, Release)() override;
STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice) override;
STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) override;
STDMETHOD(GetPrivateData)(REFGUID refguid, void* pData, DWORD* pSizeOfData) override;
STDMETHOD(FreePrivateData)(REFGUID refguid) override;
STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew) override;
STDMETHOD_(DWORD, GetPriority)() override;
STDMETHOD_(void, PreLoad)() override;
STDMETHOD_(D3DRESOURCETYPE, GetType)() override;
STDMETHOD_(DWORD, SetLOD)(DWORD LODNew) override;
STDMETHOD_(DWORD, GetLOD)() override;
STDMETHOD_(DWORD, GetLevelCount)() override;
STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType) override;
STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)() override;
STDMETHOD_(void, GenerateMipSubLevels)() override;
STDMETHOD(GetLevelDesc)(UINT Level, D3DSURFACE_DESC* pDesc) override;
STDMETHOD(GetSurfaceLevel)(UINT Level, IDirect3DSurface9** ppSurfaceLevel) override;
STDMETHOD(LockRect)(UINT Level, D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect, DWORD Flags) override;
STDMETHOD(UnlockRect)(UINT Level) override;
STDMETHOD(AddDirtyRect)(CONST RECT* pDirtyRect) override;
int GetHash(MyTypeHash& hash);
};
inline void UnswitchTextures(uMod_IDirect3DTexture9* pTexture)
{
uMod_IDirect3DTexture9* CrossRef = pTexture->CrossRef_D3Dtex;
if (CrossRef != nullptr) {
// switch textures back
IDirect3DTexture9* cpy = pTexture->m_D3Dtex;
pTexture->m_D3Dtex = CrossRef->m_D3Dtex;
CrossRef->m_D3Dtex = cpy;
// cancel the link
CrossRef->CrossRef_D3Dtex = nullptr;
pTexture->CrossRef_D3Dtex = nullptr;
}
}
inline int SwitchTextures(uMod_IDirect3DTexture9* pTexture1, uMod_IDirect3DTexture9* pTexture2)
{
if (pTexture1->m_D3Ddev == pTexture2->m_D3Ddev && pTexture1->CrossRef_D3Dtex == nullptr && pTexture2->CrossRef_D3Dtex == nullptr) {
// make cross reference
pTexture1->CrossRef_D3Dtex = pTexture2;
pTexture2->CrossRef_D3Dtex = pTexture1;
// switch textures
IDirect3DTexture9* cpy = pTexture2->m_D3Dtex;
pTexture2->m_D3Dtex = pTexture1->m_D3Dtex;
pTexture1->m_D3Dtex = cpy;
return RETURN_OK;
}
return RETURN_TEXTURE_NOT_SWITCHED;
}
+87
View File
@@ -0,0 +1,87 @@
#pragma once
#include <d3d9.h>
interface uMod_IDirect3DVolumeTexture9 : IDirect3DVolumeTexture9 {
uMod_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9** ppTex, IDirect3DDevice9* pIDirect3DDevice9)
{
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
m_D3Ddev = pIDirect3DDevice9; //device pointer
CrossRef_D3Dtex = nullptr; //cross reference
// fake texture: store the pointer to the original uMod_IDirect3DVolumeTexture9 object, needed if a fake texture is unselected
// original texture: stores the pointer to the fake texture object, is needed if original texture is deleted,
// thus the fake texture can also be deleted
Reference = -1; //need for fast deleting
Hash = 0u;
FAKE = false;
}
// callback interface
IDirect3DVolumeTexture9* m_D3Dtex;
uMod_IDirect3DVolumeTexture9* CrossRef_D3Dtex;
IDirect3DDevice9* m_D3Ddev;
int Reference;
MyTypeHash Hash;
bool FAKE;
// original interface
STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj) override;
STDMETHOD_(ULONG, AddRef)() override;
STDMETHOD_(ULONG, Release)() override;
STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice) override;
STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags) override;
STDMETHOD(GetPrivateData)(REFGUID refguid, void* pData, DWORD* pSizeOfData) override;
STDMETHOD(FreePrivateData)(REFGUID refguid) override;
STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew) override;
STDMETHOD_(DWORD, GetPriority)() override;
STDMETHOD_(void, PreLoad)() override;
STDMETHOD_(D3DRESOURCETYPE, GetType)() override;
STDMETHOD_(DWORD, SetLOD)(DWORD LODNew) override;
STDMETHOD_(DWORD, GetLOD)() override;
STDMETHOD_(DWORD, GetLevelCount)() override;
STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType) override;
STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)() override;
STDMETHOD_(void, GenerateMipSubLevels)() override;
STDMETHOD(AddDirtyBox)(CONST D3DBOX* pDirtyBox) override;
STDMETHOD(GetLevelDesc)(UINT Level, D3DVOLUME_DESC* pDesc) override;
STDMETHOD(GetVolumeLevel)(UINT Level, IDirect3DVolume9** ppVolumeLevel) override;
STDMETHOD(LockBox)(UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) override;
STDMETHOD(UnlockBox)(UINT Level) override;
int GetHash(MyTypeHash& hash);
};
inline void UnswitchTextures(uMod_IDirect3DVolumeTexture9* pTexture)
{
uMod_IDirect3DVolumeTexture9* CrossRef = pTexture->CrossRef_D3Dtex;
if (CrossRef != nullptr) {
// switch textures back
IDirect3DVolumeTexture9* cpy = pTexture->m_D3Dtex;
pTexture->m_D3Dtex = CrossRef->m_D3Dtex;
CrossRef->m_D3Dtex = cpy;
// cancel the link
CrossRef->CrossRef_D3Dtex = nullptr;
pTexture->CrossRef_D3Dtex = nullptr;
}
}
inline int SwitchTextures(uMod_IDirect3DVolumeTexture9* pTexture1, uMod_IDirect3DVolumeTexture9* pTexture2)
{
if (pTexture1->m_D3Ddev == pTexture2->m_D3Ddev && pTexture1->CrossRef_D3Dtex == nullptr && pTexture2->CrossRef_D3Dtex == nullptr) {
// make cross reference
pTexture1->CrossRef_D3Dtex = pTexture2;
pTexture2->CrossRef_D3Dtex = pTexture1;
// switch textures
IDirect3DVolumeTexture9* cpy = pTexture2->m_D3Dtex;
pTexture2->m_D3Dtex = pTexture1->m_D3Dtex;
pTexture1->m_D3Dtex = cpy;
return RETURN_OK;
}
return RETURN_TEXTURE_NOT_SWITCHED;
}
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <windows.h>
#include <cstdlib>
#include <cstdio>
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_GlobalDefines.h"
#include "uMod_Error.h"
#include "uMod_Defines.h"
#include "uMod_DX9_dll.h"
#include "uMod_TextureFunction.h"
#include "uMod_IDirect3D9.h"
#include "uMod_IDirect3D9Ex.h"
#include "uMod_IDirect3DDevice9.h"
#include "uMod_IDirect3DDevice9Ex.h"
#include "uMod_IDirect3DCubeTexture9.h"
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DVolumeTexture9.h"
#include "uMod_ArrayHandler.h"
#include "uMod_TextureServer.h"
#include "uMod_TextureClient.h"
#pragma warning(disable : 4477)
extern unsigned int gl_ErrorState;
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include <string>
#include <vector>
#include <Windows.h>
struct UModTexture {
std::vector<char> data;
std::string name;
DWORD64 hash;
};
+123
View File
@@ -0,0 +1,123 @@
#pragma once
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DDevice9.h"
#include "uMod_Error.h"
#include "uMod_ArrayHandler.h"
class uMod_TextureServer;
/*
* An object of this class is owned by each d3d9 device.
* functions called by the Server are called from the server thread instance.
* All other functions are called from the render thread instance of the game itself.
*/
class uMod_TextureClient {
public:
uMod_TextureClient(uMod_TextureServer* server, IDirect3DDevice9* device);
~uMod_TextureClient();
int AddTexture(uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DDevice9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
int AddTexture(uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
int AddTexture(uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
int RemoveTexture(uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DTexture9::Release()
int RemoveTexture(uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::Release()
int RemoveTexture(uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::Release()
int SaveAllTextures(bool val); //called from the Server
int SaveSingleTexture(bool val); //called from the Server
int SetSaveDirectory(wchar_t* dir); //called from the Server
int SetGameName(wchar_t* dir); //called from the Server
int SaveTexture(uMod_IDirect3DTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
int SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
int SaveTexture(uMod_IDirect3DCubeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
int SetKeyBack(int key)
{
if (key > 0) {
KeyBack = key;
}
return RETURN_OK;
} //called from the Server
int SetKeySave(int key)
{
if (key > 0) {
KeySave = key;
}
return RETURN_OK;
} //called from the Server
int SetKeyNext(int key)
{
if (key > 0) {
KeyNext = key;
}
return RETURN_OK;
} //called from the Server
int SetFontColour(DWORD r, DWORD g, DWORD b)
{
FontColour = D3DCOLOR_ARGB(255, r, g, b);
return RETURN_OK;
} //called from the Server
int SetTextureColour(DWORD r, DWORD g, DWORD b)
{
TextureColour = D3DCOLOR_ARGB(255, r, g, b);
return RETURN_OK;
} //called from the Server
int AddUpdate(TextureFileStruct* update, int number); //called from the Server, client object must delete update array
int MergeUpdate(); //called from uMod_IDirect3DDevice9::BeginScene()
int LookUpToMod(uMod_IDirect3DTexture9* pTexture, int num_index_list = 0, int* index_list = nullptr); // called at the end AddTexture(...) and from Device->UpdateTexture(...)
int LookUpToMod(uMod_IDirect3DVolumeTexture9* pTexture, int num_index_list = 0, int* index_list = nullptr); // called at the end AddTexture(...) and from Device->UpdateTexture(...)
int LookUpToMod(uMod_IDirect3DCubeTexture9* pTexture, int num_index_list = 0, int* index_list = nullptr); // called at the end AddTexture(...) and from Device->UpdateTexture(...)
uMod_TextureHandler<uMod_IDirect3DTexture9> OriginalTextures; // stores the pointer to the uMod_IDirect3DTexture9 objects created by the game
uMod_TextureHandler<uMod_IDirect3DVolumeTexture9> OriginalVolumeTextures; // stores the pointer to the uMod_IDirect3DVolumeTexture9 objects created by the game
uMod_TextureHandler<uMod_IDirect3DCubeTexture9> OriginalCubeTextures; // stores the pointer to the uMod_IDirect3DCubeTexture9 objects created by the game
bool BoolSaveAllTextures;
bool BoolSaveSingleTexture;
int KeyBack;
int KeySave;
int KeyNext;
D3DCOLOR FontColour;
D3DCOLOR TextureColour;
private:
uMod_TextureServer* Server;
IDirect3DDevice9* D3D9Device;
wchar_t SavePath[MAX_PATH];
wchar_t GameName[MAX_PATH];
TextureFileStruct* Update;
int NumberOfUpdate;
int LockMutex();
int UnlockMutex();
HANDLE Mutex;
int NumberToMod; // number of texture to be modded
TextureFileStruct* FileToMod; // array which stores the file in memory and the hash of each texture to be modded
int LookUpToMod(MyTypeHash hash, int num_index_list, int* index_list); // called from LookUpToMod(...);
int LoadTexture(TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9** ppTexture); // called if a target texture is found
int LoadTexture(TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9** ppTexture); // called if a target texture is found
int LoadTexture(TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9** ppTexture); // called if a target texture is found
// and the corresponding fake texture should be loaded
//MyTypeHash GetHash(unsigned char *str, int len);
//unsigned int GetCRC32(char *pcDatabuf, unsigned int ulDatalen);
};
+124
View File
@@ -0,0 +1,124 @@
#pragma once
unsigned int GetCRC32(char* pcDatabuf, unsigned int ulDatalen);
/*
case D3DFMT_MULTI2_ARGB8:
case D3DFMT_VERTEXDATA:
*/
inline int GetBitsFromFormat(D3DFORMAT format)
{
switch (format) //switch trough the formats to calculate the size of the raw data
{
case D3DFMT_A1: // 1-bit monochrome.
{
return 1;
break;
}
case D3DFMT_R3G3B2: // 8-bit RGB texture format using 3 bits for red, 3 bits for green, and 2 bits for blue.
case D3DFMT_A8: // 8-bit alpha only.
case D3DFMT_A8P8: // 8-bit color indexed with 8 bits of alpha.
case D3DFMT_P8: // 8-bit color indexed.
case D3DFMT_L8: // 8-bit luminance only.
case D3DFMT_A4L4: // 8-bit using 4 bits each for alpha and luminance.
case D3DFMT_FORCE_DWORD:
case D3DFMT_S8_LOCKABLE: // A lockable 8-bit stencil buffer.
{
return 8;
break;
}
case D3DFMT_D16_LOCKABLE: //16-bit z-buffer bit depth.
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.
case D3DFMT_L6V5U5: // 16-bit bump-map format with luminance using 6 bits for luminance, and 5 bits each for v and u.
case D3DFMT_V8U8: // 16-bit bump-map format using 8 bits each for u and v data.
case D3DFMT_CxV8U8: // 16-bit normal compression format. The texture sampler computes the C channel from: C = sqrt(1 - U2 - V2).
case D3DFMT_R5G6B5: // 16-bit RGB pixel format with 5 bits for red, 6 bits for green, and 5 bits for blue.
case D3DFMT_X1R5G5B5: // 16-bit pixel format where 5 bits are reserved for each color.
case D3DFMT_A1R5G5B5: // 16-bit pixel format where 5 bits are reserved for each color and 1 bit is reserved for alpha.
case D3DFMT_A4R4G4B4: // 16-bit ARGB pixel format with 4 bits for each channel.
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.
case D3DFMT_X4R4G4B4: // 16-bit RGB pixel format using 4 bits for each color.
case D3DFMT_L16: // 16-bit luminance only.
case D3DFMT_R16F: // 16-bit float format using 16 bits for the red channel.
case D3DFMT_A8L8: // 16-bit using 8 bits each for alpha and luminance.
case D3DFMT_D16: // 16-bit z-buffer bit depth.
case D3DFMT_INDEX16: // 16-bit index buffer bit depth.
case D3DFMT_G8R8_G8B8: // ??
case D3DFMT_R8G8_B8G8: // ??
case D3DFMT_UYVY: // ??
case D3DFMT_YUY2: // ??
{
return 16;
break;
}
case D3DFMT_R8G8B8: //24-bit RGB pixel format with 8 bits per channel.
{
return 24;
break;
}
case D3DFMT_R32F: // 32-bit float format using 32 bits for the red channel.
case D3DFMT_X8L8V8U8: // 32-bit bump-map format with luminance using 8 bits for each channel.
case D3DFMT_A2W10V10U10: // 32-bit bump-map format using 2 bits for alpha and 10 bits each for w, v, and u.
case D3DFMT_Q8W8V8U8: // 32-bit bump-map format using 8 bits for each channel.
case D3DFMT_V16U16: // 32-bit bump-map format using 16 bits for each channel.
case D3DFMT_A8R8G8B8: // 32-bit ARGB pixel format with alpha, using 8 bits per channel.
case D3DFMT_X8R8G8B8: // 32-bit RGB pixel format, where 8 bits are reserved for each color.
case D3DFMT_A2B10G10R10: // 32-bit pixel format using 10 bits for each color and 2 bits for alpha.
case D3DFMT_A8B8G8R8: // 32-bit ARGB pixel format with alpha, using 8 bits per channel.
case D3DFMT_X8B8G8R8: // 32-bit RGB pixel format, where 8 bits are reserved for each color.
case D3DFMT_G16R16: // 32-bit pixel format using 16 bits each for green and red.
case D3DFMT_G16R16F: // 32-bit float format using 16 bits for the red channel and 16 bits for the green channel.
case D3DFMT_A2R10G10B10: // 32-bit pixel format using 10 bits each for red, green, and blue, and 2 bits for alpha.
case D3DFMT_D32: // 32-bit z-buffer bit depth.
case D3DFMT_D24S8: // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel.
case D3DFMT_D24X8: //32-bit z-buffer bit depth using 24 bits for the depth channel.
case D3DFMT_D24X4S4: // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel.
case D3DFMT_D32F_LOCKABLE: // A lockable format where the depth value is represented as a standard IEEE floating-point number.
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.
case D3DFMT_D32_LOCKABLE: // A lockable 32-bit depth buffer.
case D3DFMT_INDEX32: // 32-bit index buffer bit depth.
//case : //
//case : //
//case : //
//case : //
{
return 32;
break;
}
case D3DFMT_G32R32F: // 64-bit float format using 32 bits for the red channel and 32 bits for the green channel.
case D3DFMT_Q16W16V16U16: // 64-bit bump-map format using 16 bits for each component.
case D3DFMT_A16B16G16R16: // 64-bit pixel format using 16 bits for each component.
case D3DFMT_A16B16G16R16F: // 64-bit float format using 16 bits for the each channel (alpha, blue, green, red).
{
return 64;
break;
}
case D3DFMT_A32B32G32R32F: // 128-bit float format using 32 bits for the each channel (alpha, blue, green, red).
{
return 128;
break;
}
case D3DFMT_DXT2:
case D3DFMT_DXT3:
case D3DFMT_DXT4:
case D3DFMT_DXT5: {
return 8;
break;
}
case D3DFMT_DXT1: {
return 4;
break;
}
default: //compressed formats
{
return 4;
break;
}
}
}
+86
View File
@@ -0,0 +1,86 @@
#pragma once
#include "uMod_GlobalDefines.h"
#include "uMod_ArrayHandler.h"
/*
* An object of this class is created only once.
* The Mainloop functions is executed by a server thread,
* which listen on a pipe.
*
* Functions called by the Client are called from the a thread instance of the game itself.
* Nearly all other functions are called from the server thread instance.
*/
class uMod_TextureClient;
class uMod_TextureServer {
public:
uMod_TextureServer(char* name, char* uModName);
~uMod_TextureServer();
int AddClient(uMod_TextureClient* client, TextureFileStruct** update, int* number); // called from a Client
int RemoveClient(uMod_TextureClient* client); // called from a Client
int MainLoop(); // is executed in a server thread
// following functions are only public for testing purpose !!
// they should be private and only be called from the Mainloop
int AddFile(char* buffer, unsigned int size, MyTypeHash hash, bool force); // called from Mainloop(), if the content of the texture is sent
int AddFile(wchar_t* file_name, MyTypeHash hash, bool force); // called from Mainloop(), if the name and the path to the file is sent
int RemoveFile(MyTypeHash hash); // called from Mainloop()
int SaveAllTextures(bool val); // called from Mainloop()
int SaveSingleTexture(bool val); // called from Mainloop()
int SetSaveDirectory(wchar_t* dir); // called from Mainloop()
int SetKeyBack(int key); // called from Mainloop()
int SetKeySave(int key); // called from Mainloop()
int SetKeyNext(int key); // called from Mainloop()
int SetFontColour(DWORD colour); // called from Mainloop()
int SetTextureColour(DWORD colour); // called from Mainloop()
private:
bool BoolSaveAllTextures;
bool BoolSaveSingleTexture;
wchar_t SavePath[MAX_PATH];
wchar_t GameName[MAX_PATH];
char UModName[MAX_PATH];
void LoadModsFromFile(char* source);
int PropagateUpdate(uMod_TextureClient* client = nullptr); // called from Mainloop() if texture are loaded or removed
int PrepareUpdate(TextureFileStruct** update, int* number); // called from PropagateUpdate() and AddClient()
// generate a copy of the current texture to be modded
// the file content of the textures are not copied, the clients get the pointer to the file content
// but the arrays allocate by this function, must be deleted by the client
int LockMutex();
int UnlockMutex();
HANDLE Mutex;
int KeyBack;
int KeySave;
int KeyNext;
DWORD FontColour;
DWORD TextureColour;
PipeStruct Pipe;
uMod_TextureClient** Clients;
int NumberOfClients;
int LenghtOfClients;
uMod_FileHandler CurrentMod; // hold the file content of texture
uMod_FileHandler OldMod; // hold the file content of texture which were added previously but are not needed any more
// this is needed, because a texture clients might not have merged the last update and thus hold pointers to the file content of old textures
};
+214 -214
View File
@@ -1,214 +1,214 @@
#ifndef _unzip_H
#define _unzip_H
//#define TCHAR char
// UNZIPPING functions -- for unzipping.
// This file is a repackaged form of extracts from the zlib code available
// at www.gzip.org/zlib, by Jean-Loup Gailly and Mark Adler. The original
// copyright notice may be found in unzip.cpp. The repackaging was done
// by Lucian Wischik to simplify and extend its use in Windows/C++. Also
// encryption and unicode filenames have been added.
#ifndef _zip_H
DECLARE_HANDLE(HZIP);
#endif
// An HZIP identifies a zip file that has been opened
typedef DWORD ZRESULT;
// return codes from any of the zip functions. Listed later.
typedef struct
{ int index; // index of this file within the zip
TCHAR name[MAX_PATH]; // filename within the zip
DWORD attr; // attributes, as in GetFileAttributes.
FILETIME atime,ctime,mtime;// access, create, modify filetimes
long comp_size; // sizes of item, compressed and uncompressed. These
long unc_size; // may be -1 if not yet known (e.g. being streamed in)
} ZIPENTRY;
HZIP OpenZip(const TCHAR *fn, const char *password);
HZIP OpenZip(void *z,unsigned int len, const char *password);
HZIP OpenZipHandle(HANDLE h, const char *password);
// OpenZip - opens a zip file and returns a handle with which you can
// subsequently examine its contents. You can open a zip file from:
// from a pipe: OpenZipHandle(hpipe_read,0);
// from a file (by handle): OpenZipHandle(hfile,0);
// from a file (by name): OpenZip("c:\\test.zip","password");
// from a memory block: OpenZip(bufstart, buflen,0);
// If the file is opened through a pipe, then items may only be
// accessed in increasing order, and an item may only be unzipped once,
// although GetZipItem can be called immediately before and after unzipping
// it. If it's opened in any other way, then full random access is possible.
// Note: pipe input is not yet implemented.
// Note: zip passwords are ascii, not unicode.
// Note: for windows-ce, you cannot close the handle until after CloseZip.
// but for real windows, the zip makes its own copy of your handle, so you
// can close yours anytime.
ZRESULT GetZipItem(HZIP hz, int index, ZIPENTRY *ze);
// GetZipItem - call this to get information about an item in the zip.
// If index is -1 and the file wasn't opened through a pipe,
// then it returns information about the whole zipfile
// (and in particular ze.index returns the number of index items).
// Note: the item might be a directory (ze.attr & FILE_ATTRIBUTE_DIRECTORY)
// See below for notes on what happens when you unzip such an item.
// Note: if you are opening the zip through a pipe, then random access
// is not possible and GetZipItem(-1) fails and you can't discover the number
// of items except by calling GetZipItem on each one of them in turn,
// starting at 0, until eventually the call fails. Also, in the event that
// you are opening through a pipe and the zip was itself created into a pipe,
// then then comp_size and sometimes unc_size as well may not be known until
// after the item has been unzipped.
ZRESULT FindZipItem(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRY *ze);
// FindZipItem - finds an item by name. ic means 'insensitive to case'.
// It returns the index of the item, and returns information about it.
// If nothing was found, then index is set to -1 and the function returns
// an error code.
ZRESULT UnzipItem(HZIP hz, int index, const TCHAR *fn);
ZRESULT UnzipItem(HZIP hz, int index, void *z,unsigned int len);
ZRESULT UnzipItemHandle(HZIP hz, int index, HANDLE h);
// UnzipItem - given an index to an item, unzips it. You can unzip to:
// to a pipe: UnzipItemHandle(hz,i, hpipe_write);
// to a file (by handle): UnzipItemHandle(hz,i, hfile);
// to a file (by name): UnzipItem(hz,i, ze.name);
// to a memory block: UnzipItem(hz,i, buf,buflen);
// In the final case, if the buffer isn't large enough to hold it all,
// then the return code indicates that more is yet to come. If it was
// large enough, and you want to know precisely how big, GetZipItem.
// Note: zip files are normally stored with relative pathnames. If you
// unzip with ZIP_FILENAME a relative pathname then the item gets created
// relative to the current directory - it first ensures that all necessary
// subdirectories have been created. Also, the item may itself be a directory.
// If you unzip a directory with ZIP_FILENAME, then the directory gets created.
// If you unzip it to a handle or a memory block, then nothing gets created
// and it emits 0 bytes.
ZRESULT SetUnzipBaseDir(HZIP hz, const TCHAR *dir);
// if unzipping to a filename, and it's a relative filename, then it will be relative to here.
// (defaults to current-directory).
ZRESULT CloseZip(HZIP hz);
// CloseZip - the zip handle must be closed with this function.
unsigned int FormatZipMessage(ZRESULT code, TCHAR *buf,unsigned int len);
// FormatZipMessage - given an error code, formats it as a string.
// It returns the length of the error message. If buf/len points
// to a real buffer, then it also writes as much as possible into there.
// These are the result codes:
#define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
#define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
// The following come from general system stuff (e.g. files not openable)
#define ZR_GENMASK 0x0000FF00
#define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
#define ZR_NOFILE 0x00000200 // couldn't create/open the file
#define ZR_NOALLOC 0x00000300 // failed to allocate some resource
#define ZR_WRITE 0x00000400 // a general error writing to the file
#define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
#define ZR_MORE 0x00000600 // there's still more data to be unzipped
#define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
#define ZR_READ 0x00000800 // a general error reading the file
#define ZR_PASSWORD 0x00001000 // we didn't get the right password to unzip the file
// The following come from mistakes on the part of the caller
#define ZR_CALLERMASK 0x00FF0000
#define ZR_ARGS 0x00010000 // general mistake with the arguments
#define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
#define ZR_MEMSIZE 0x00030000 // the memory size is too small
#define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
#define ZR_ENDED 0x00050000 // the zip creation has already been closed
#define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
#define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
#define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
// The following come from bugs within the zip library itself
#define ZR_BUGMASK 0xFF000000
#define ZR_NOTINITED 0x01000000 // initialisation didn't work
#define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
#define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
#define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
// e.g.
//
// SetCurrentDirectory("c:\\docs\\stuff");
// HZIP hz = OpenZip("c:\\stuff.zip",0);
// ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
// for (int i=0; i<numitems; i++)
// { GetZipItem(hz,i,&ze);
// UnzipItem(hz,i,ze.name);
// }
// CloseZip(hz);
//
//
// HRSRC hrsrc = FindResource(hInstance,MAKEINTRESOURCE(1),RT_RCDATA);
// HANDLE hglob = LoadResource(hInstance,hrsrc);
// void *zipbuf=LockResource(hglob);
// unsigned int ziplen=SizeofResource(hInstance,hrsrc);
// HZIP hz = OpenZip(zipbuf, ziplen, 0);
// - unzip to a membuffer -
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",true,&i,&ze);
// char *ibuf = new char[ze.unc_size];
// UnzipItem(hz,i, ibuf, ze.unc_size);
// delete[] ibuf;
// - unzip to a fixed membuff -
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",true,&i,&ze);
// char ibuf[1024]; ZRESULT zr=ZR_MORE; unsigned long totsize=0;
// while (zr==ZR_MORE)
// { zr = UnzipItem(hz,i, ibuf,1024);
// unsigned long bufsize=1024; if (zr==ZR_OK) bufsize=ze.unc_size-totsize;
// totsize+=bufsize;
// }
// - unzip to a pipe -
// HANDLE hwrite; HANDLE hthread=CreateWavReaderThread(&hwrite);
// int i; ZIPENTRY ze; FindZipItem(hz,"sound.wav",true,&i,&ze);
// UnzipItemHandle(hz,i, hwrite);
// CloseHandle(hwrite);
// WaitForSingleObject(hthread,INFINITE);
// CloseHandle(hwrite); CloseHandle(hthread);
// - finished -
// CloseZip(hz);
// // note: no need to free resources obtained through Find/Load/LockResource
//
//
// SetCurrentDirectory("c:\\docs\\pipedzipstuff");
// HANDLE hread,hwrite; CreatePipe(&hread,&hwrite,0,0);
// CreateZipWriterThread(hwrite);
// HZIP hz = OpenZipHandle(hread,0);
// for (int i=0; ; i++)
// { ZIPENTRY ze;
// ZRESULT zr=GetZipItem(hz,i,&ze); if (zr!=ZR_OK) break; // no more
// UnzipItem(hz,i, ze.name);
// }
// CloseZip(hz);
//
//
// Now we indulge in a little skullduggery so that the code works whether
// the user has included just zip or both zip and unzip.
// Idea: if header files for both zip and unzip are present, then presumably
// the cpp files for zip and unzip are both present, so we will call
// one or the other of them based on a dynamic choice. If the header file
// for only one is present, then we will bind to that particular one.
ZRESULT CloseZipU(HZIP hz);
unsigned int FormatZipMessageU(ZRESULT code, TCHAR *buf,unsigned int len);
bool IsZipHandleU(HZIP hz);
#ifdef _zip_H
#undef CloseZip
#define CloseZip(hz) (IsZipHandleU(hz)?CloseZipU(hz):CloseZipZ(hz))
#else
#define CloseZip CloseZipU
#define FormatZipMessage FormatZipMessageU
#endif
#endif // _unzip_H
#ifndef _unzip_H
#define _unzip_H
//#define TCHAR char
// UNZIPPING functions -- for unzipping.
// This file is a repackaged form of extracts from the zlib code available
// at www.gzip.org/zlib, by Jean-Loup Gailly and Mark Adler. The original
// copyright notice may be found in unzip.cpp. The repackaging was done
// by Lucian Wischik to simplify and extend its use in Windows/C++. Also
// encryption and unicode filenames have been added.
#ifndef _zip_H
DECLARE_HANDLE(HZIP);
#endif
// An HZIP identifies a zip file that has been opened
typedef DWORD ZRESULT;
// return codes from any of the zip functions. Listed later.
typedef struct {
int index; // index of this file within the zip
TCHAR name[MAX_PATH]; // filename within the zip
DWORD attr; // attributes, as in GetFileAttributes.
FILETIME atime, ctime, mtime;// access, create, modify filetimes
long comp_size; // sizes of item, compressed and uncompressed. These
long unc_size; // may be -1 if not yet known (e.g. being streamed in)
} ZIPENTRY;
HZIP OpenZip(const TCHAR* fn, const char* password);
HZIP OpenZip(void* z, unsigned int len, const char* password);
HZIP OpenZipHandle(HANDLE h, const char* password);
// OpenZip - opens a zip file and returns a handle with which you can
// subsequently examine its contents. You can open a zip file from:
// from a pipe: OpenZipHandle(hpipe_read,0);
// from a file (by handle): OpenZipHandle(hfile,0);
// from a file (by name): OpenZip("c:\\test.zip","password");
// from a memory block: OpenZip(bufstart, buflen,0);
// If the file is opened through a pipe, then items may only be
// accessed in increasing order, and an item may only be unzipped once,
// although GetZipItem can be called immediately before and after unzipping
// it. If it's opened in any other way, then full random access is possible.
// Note: pipe input is not yet implemented.
// Note: zip passwords are ascii, not unicode.
// Note: for windows-ce, you cannot close the handle until after CloseZip.
// but for real windows, the zip makes its own copy of your handle, so you
// can close yours anytime.
ZRESULT GetZipItem(HZIP hz, int index, ZIPENTRY* ze);
// GetZipItem - call this to get information about an item in the zip.
// If index is -1 and the file wasn't opened through a pipe,
// then it returns information about the whole zipfile
// (and in particular ze.index returns the number of index items).
// Note: the item might be a directory (ze.attr & FILE_ATTRIBUTE_DIRECTORY)
// See below for notes on what happens when you unzip such an item.
// Note: if you are opening the zip through a pipe, then random access
// is not possible and GetZipItem(-1) fails and you can't discover the number
// of items except by calling GetZipItem on each one of them in turn,
// starting at 0, until eventually the call fails. Also, in the event that
// you are opening through a pipe and the zip was itself created into a pipe,
// then then comp_size and sometimes unc_size as well may not be known until
// after the item has been unzipped.
ZRESULT FindZipItem(HZIP hz, const TCHAR* name, bool ic, int* index, ZIPENTRY* ze);
// FindZipItem - finds an item by name. ic means 'insensitive to case'.
// It returns the index of the item, and returns information about it.
// If nothing was found, then index is set to -1 and the function returns
// an error code.
ZRESULT UnzipItem(HZIP hz, int index, const TCHAR* fn);
ZRESULT UnzipItem(HZIP hz, int index, void* z, unsigned int len);
ZRESULT UnzipItemHandle(HZIP hz, int index, HANDLE h);
// UnzipItem - given an index to an item, unzips it. You can unzip to:
// to a pipe: UnzipItemHandle(hz,i, hpipe_write);
// to a file (by handle): UnzipItemHandle(hz,i, hfile);
// to a file (by name): UnzipItem(hz,i, ze.name);
// to a memory block: UnzipItem(hz,i, buf,buflen);
// In the final case, if the buffer isn't large enough to hold it all,
// then the return code indicates that more is yet to come. If it was
// large enough, and you want to know precisely how big, GetZipItem.
// Note: zip files are normally stored with relative pathnames. If you
// unzip with ZIP_FILENAME a relative pathname then the item gets created
// relative to the current directory - it first ensures that all necessary
// subdirectories have been created. Also, the item may itself be a directory.
// If you unzip a directory with ZIP_FILENAME, then the directory gets created.
// If you unzip it to a handle or a memory block, then nothing gets created
// and it emits 0 bytes.
ZRESULT SetUnzipBaseDir(HZIP hz, const TCHAR* dir);
// if unzipping to a filename, and it's a relative filename, then it will be relative to here.
// (defaults to current-directory).
ZRESULT CloseZip(HZIP hz);
// CloseZip - the zip handle must be closed with this function.
unsigned int FormatZipMessage(ZRESULT code, TCHAR* buf, unsigned int len);
// FormatZipMessage - given an error code, formats it as a string.
// It returns the length of the error message. If buf/len points
// to a real buffer, then it also writes as much as possible into there.
// These are the result codes:
#define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
#define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
// The following come from general system stuff (e.g. files not openable)
#define ZR_GENMASK 0x0000FF00
#define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
#define ZR_NOFILE 0x00000200 // couldn't create/open the file
#define ZR_NOALLOC 0x00000300 // failed to allocate some resource
#define ZR_WRITE 0x00000400 // a general error writing to the file
#define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
#define ZR_MORE 0x00000600 // there's still more data to be unzipped
#define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
#define ZR_READ 0x00000800 // a general error reading the file
#define ZR_PASSWORD 0x00001000 // we didn't get the right password to unzip the file
// The following come from mistakes on the part of the caller
#define ZR_CALLERMASK 0x00FF0000
#define ZR_ARGS 0x00010000 // general mistake with the arguments
#define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
#define ZR_MEMSIZE 0x00030000 // the memory size is too small
#define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
#define ZR_ENDED 0x00050000 // the zip creation has already been closed
#define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
#define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
#define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
// The following come from bugs within the zip library itself
#define ZR_BUGMASK 0xFF000000
#define ZR_NOTINITED 0x01000000 // initialisation didn't work
#define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
#define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
#define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
// e.g.
//
// SetCurrentDirectory("c:\\docs\\stuff");
// HZIP hz = OpenZip("c:\\stuff.zip",0);
// ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
// for (int i=0; i<numitems; i++)
// { GetZipItem(hz,i,&ze);
// UnzipItem(hz,i,ze.name);
// }
// CloseZip(hz);
//
//
// HRSRC hrsrc = FindResource(hInstance,MAKEINTRESOURCE(1),RT_RCDATA);
// HANDLE hglob = LoadResource(hInstance,hrsrc);
// void *zipbuf=LockResource(hglob);
// unsigned int ziplen=SizeofResource(hInstance,hrsrc);
// HZIP hz = OpenZip(zipbuf, ziplen, 0);
// - unzip to a membuffer -
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",true,&i,&ze);
// char *ibuf = new char[ze.unc_size];
// UnzipItem(hz,i, ibuf, ze.unc_size);
// delete[] ibuf;
// - unzip to a fixed membuff -
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",true,&i,&ze);
// char ibuf[1024]; ZRESULT zr=ZR_MORE; unsigned long totsize=0;
// while (zr==ZR_MORE)
// { zr = UnzipItem(hz,i, ibuf,1024);
// unsigned long bufsize=1024; if (zr==ZR_OK) bufsize=ze.unc_size-totsize;
// totsize+=bufsize;
// }
// - unzip to a pipe -
// HANDLE hwrite; HANDLE hthread=CreateWavReaderThread(&hwrite);
// int i; ZIPENTRY ze; FindZipItem(hz,"sound.wav",true,&i,&ze);
// UnzipItemHandle(hz,i, hwrite);
// CloseHandle(hwrite);
// WaitForSingleObject(hthread,INFINITE);
// CloseHandle(hwrite); CloseHandle(hthread);
// - finished -
// CloseZip(hz);
// // note: no need to free resources obtained through Find/Load/LockResource
//
//
// SetCurrentDirectory("c:\\docs\\pipedzipstuff");
// HANDLE hread,hwrite; CreatePipe(&hread,&hwrite,0,0);
// CreateZipWriterThread(hwrite);
// HZIP hz = OpenZipHandle(hread,0);
// for (int i=0; ; i++)
// { ZIPENTRY ze;
// ZRESULT zr=GetZipItem(hz,i,&ze); if (zr!=ZR_OK) break; // no more
// UnzipItem(hz,i, ze.name);
// }
// CloseZip(hz);
//
//
// Now we indulge in a little skullduggery so that the code works whether
// the user has included just zip or both zip and unzip.
// Idea: if header files for both zip and unzip are present, then presumably
// the cpp files for zip and unzip are both present, so we will call
// one or the other of them based on a dynamic choice. If the header file
// for only one is present, then we will bind to that particular one.
ZRESULT CloseZipU(HZIP hz);
unsigned int FormatZipMessageU(ZRESULT code, TCHAR* buf, unsigned int len);
bool IsZipHandleU(HZIP hz);
#ifdef _zip_H
#undef CloseZip
#define CloseZip(hz) (IsZipHandleU(hz)?CloseZipU(hz):CloseZipZ(hz))
#else
#define CloseZip CloseZipU
#define FormatZipMessage FormatZipMessageU
#endif
#endif // _unzip_H
+157
View File
@@ -0,0 +1,157 @@
#pragma once
#include <string>
#include <Windows.h>
void ReplaceAll(std::wstring& str, const std::wstring& from, const std::wstring& to)
{
if (from.empty()) {
return;
}
size_t startPos = 0;
while ((startPos = str.find(from, startPos)) != std::wstring::npos) {
str.replace(startPos, from.length(), to);
startPos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
void ReplaceAll(std::string& str, const std::string& from, const std::string& to)
{
if (from.empty()) {
return;
}
size_t startPos = 0;
while ((startPos = str.find(from, startPos)) != std::string::npos) {
str.replace(startPos, from.length(), to);
startPos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
std::wstring AfterFirst(const std::wstring& str, wchar_t delimiter)
{
const size_t pos = str.find(delimiter);
if (pos != std::wstring::npos) {
// Return the substring after the delimiter
return str.substr(pos + 1);
}
// If the delimiter is not found, return an empty string
return L"";
}
std::string AfterFirst(const std::string& str, char delimiter)
{
const size_t pos = str.find(delimiter);
if (pos != std::string::npos) {
// Return the substring after the delimiter
return str.substr(pos + 1);
}
// If the delimiter is not found, return an empty string
return "";
}
std::wstring BeforeFirst(const std::wstring& str, wchar_t delimiter)
{
const size_t pos = str.find(delimiter);
return pos != std::wstring::npos ? str.substr(0, pos) : str;
}
std::string BeforeFirst(const std::string& str, char delimiter)
{
const size_t pos = str.find(delimiter);
return pos != std::string::npos ? str.substr(0, pos) : str;
}
std::string BeforeLast(const std::string& file_path, char separator)
{
// Find the last occurrence of '.'
const std::size_t last_dot_pos = file_path.find_last_of(separator);
// If there is a dot, and it is not at the beginning of the filename
if (last_dot_pos != std::string::npos && last_dot_pos != 0) {
// Extract the substring from the dot to the end of the string
return file_path.substr(0, last_dot_pos);
}
// If the dot is not found, or is the first character, return an empty string
return "";
}
std::wstring BeforeLast(const std::wstring& file_path, wchar_t separator)
{
// Find the last occurrence of '.'
const std::size_t last_dot_pos = file_path.find_last_of(separator);
// If there is a dot, and it is not at the beginning of the filename
if (last_dot_pos != std::wstring::npos && last_dot_pos != 0) {
// Extract the substring from the dot to the end of the string
return file_path.substr(0, last_dot_pos);
}
// If the dot is not found, or is the first character, return an empty string
return L"";
}
std::string AfterLast(const std::string& file_path, char separator)
{
// Find the last occurrence of '.'
const std::size_t last_dot_pos = file_path.find_last_of(separator);
// If there is a dot, and it is not at the beginning of the filename
if (last_dot_pos != std::string::npos && last_dot_pos != 0) {
// Extract the substring from the dot to the end of the string
return file_path.substr(last_dot_pos + 1);
}
// If the dot is not found, or is the first character, return an empty string
return "";
}
std::wstring AfterLast(const std::wstring& file_path, wchar_t separator)
{
// Find the last occurrence of '.'
const std::size_t last_dot_pos = file_path.find_last_of(separator);
// If there is a dot, and it is not at the beginning of the filename
if (last_dot_pos != std::wstring::npos && last_dot_pos != 0) {
// Extract the substring from the dot to the end of the string
return file_path.substr(last_dot_pos + 1);
}
// If the dot is not found, or is the first character, return an empty string
return L"";
}
std::string GetFileExtension(const std::string& file_path)
{
// Find the last occurrence of '.'
const std::size_t last_dot_pos = file_path.find_last_of(".");
// If there is a dot, and it is not at the beginning of the filename
if (last_dot_pos != std::string::npos && last_dot_pos != 0) {
// Extract the substring from the dot to the end of the string
return file_path.substr(last_dot_pos + 1);
}
// If the dot is not found, or is the first character, return an empty string
return "";
}
std::string WideStringToString(const std::wstring& wstr)
{
if (wstr.empty()) {
return std::string();
}
const int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast<int>(wstr.size()), nullptr, 0, nullptr, nullptr);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast<int>(wstr.size()), &strTo[0], size_needed, nullptr, nullptr);
return strTo;
}
std::wstring StringToWString(const std::string& str)
{
if (str.empty()) {
return std::wstring();
}
const int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast<int>(str.size()), nullptr, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast<int>(str.size()), &wstrTo[0], size_needed);
return wstrTo;
}
+205 -203
View File
@@ -1,203 +1,205 @@
#ifndef _zip_H
#define _zip_H
// ZIP functions -- for creating zip files
// This file is a repackaged form of the Info-Zip source code available
// at www.info-zip.org. The original copyright notice may be found in
// zip.cpp. The repackaging was done by Lucian Wischik to simplify and
// extend its use in Windows/C++. Also to add encryption and unicode.
#ifndef _unzip_H
DECLARE_HANDLE(HZIP);
#endif
// An HZIP identifies a zip file that is being created
typedef DWORD ZRESULT;
// return codes from any of the zip functions. Listed later.
HZIP CreateZip(const TCHAR *fn, const char *password);
HZIP CreateZip(void *buf,unsigned int len, const char *password);
HZIP CreateZipHandle(HANDLE h, const char *password);
// CreateZip - call this to start the creation of a zip file.
// As the zip is being created, it will be stored somewhere:
// to a pipe: CreateZipHandle(hpipe_write);
// in a file (by handle): CreateZipHandle(hfile);
// in a file (by name): CreateZip("c:\\test.zip");
// in memory: CreateZip(buf, len);
// or in pagefile memory: CreateZip(0, len);
// The final case stores it in memory backed by the system paging file,
// where the zip may not exceed len bytes. This is a bit friendlier than
// allocating memory with new[]: it won't lead to fragmentation, and the
// memory won't be touched unless needed. That means you can give very
// large estimates of the maximum-size without too much worry.
// As for the password, it lets you encrypt every file in the archive.
// (This api doesn't support per-file encryption.)
// Note: because pipes don't allow random access, the structure of a zipfile
// created into a pipe is slightly different from that created into a file
// or memory. In particular, the compressed-size of the item cannot be
// stored in the zipfile until after the item itself. (Also, for an item added
// itself via a pipe, the uncompressed-size might not either be known until
// after.) This is not normally a problem. But if you try to unzip via a pipe
// as well, then the unzipper will not know these things about the item until
// after it has been unzipped. Therefore: for unzippers which don't just write
// each item to disk or to a pipe, but instead pre-allocate memory space into
// which to unzip them, then either you have to create the zip not to a pipe,
// or you have to add items not from a pipe, or at least when adding items
// from a pipe you have to specify the length.
// Note: for windows-ce, you cannot close the handle until after CloseZip.
// but for real windows, the zip makes its own copy of your handle, so you
// can close yours anytime.
ZRESULT ZipAdd(HZIP hz,const TCHAR *dstzn, const TCHAR *fn);
ZRESULT ZipAdd(HZIP hz,const TCHAR *dstzn, void *src,unsigned int len);
ZRESULT ZipAddHandle(HZIP hz,const TCHAR *dstzn, HANDLE h);
ZRESULT ZipAddHandle(HZIP hz,const TCHAR *dstzn, HANDLE h, unsigned int len);
ZRESULT ZipAddFolder(HZIP hz,const TCHAR *dstzn);
// ZipAdd - call this for each file to be added to the zip.
// dstzn is the name that the file will be stored as in the zip file.
// The file to be added to the zip can come
// from a pipe: ZipAddHandle(hz,"file.dat", hpipe_read);
// from a file: ZipAddHandle(hz,"file.dat", hfile);
// from a filen: ZipAdd(hz,"file.dat", "c:\\docs\\origfile.dat");
// from memory: ZipAdd(hz,"subdir\\file.dat", buf,len);
// (folder): ZipAddFolder(hz,"subdir");
// Note: if adding an item from a pipe, and if also creating the zip file itself
// to a pipe, then you might wish to pass a non-zero length to the ZipAddHandle
// function. This will let the zipfile store the item's size ahead of the
// compressed item itself, which in turn makes it easier when unzipping the
// zipfile from a pipe.
ZRESULT ZipGetMemory(HZIP hz, void **buf, unsigned long *len);
// ZipGetMemory - If the zip was created in memory, via ZipCreate(0,len),
// then this function will return information about that memory block.
// buf will receive a pointer to its start, and len its length.
// Note: you can't add any more after calling this.
ZRESULT CloseZip(HZIP hz);
// CloseZip - the zip handle must be closed with this function.
unsigned int FormatZipMessage(ZRESULT code, TCHAR *buf,unsigned int len);
// FormatZipMessage - given an error code, formats it as a string.
// It returns the length of the error message. If buf/len points
// to a real buffer, then it also writes as much as possible into there.
// These are the result codes:
#define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
#define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
// The following come from general system stuff (e.g. files not openable)
#define ZR_GENMASK 0x0000FF00
#define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
#define ZR_NOFILE 0x00000200 // couldn't create/open the file
#define ZR_NOALLOC 0x00000300 // failed to allocate some resource
#define ZR_WRITE 0x00000400 // a general error writing to the file
#define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
#define ZR_MORE 0x00000600 // there's still more data to be unzipped
#define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
#define ZR_READ 0x00000800 // a general error reading the file
// The following come from mistakes on the part of the caller
#define ZR_CALLERMASK 0x00FF0000
#define ZR_ARGS 0x00010000 // general mistake with the arguments
#define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
#define ZR_MEMSIZE 0x00030000 // the memory size is too small
#define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
#define ZR_ENDED 0x00050000 // the zip creation has already been closed
#define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
#define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
#define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
// The following come from bugs within the zip library itself
#define ZR_BUGMASK 0xFF000000
#define ZR_NOTINITED 0x01000000 // initialisation didn't work
#define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
#define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
#define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
// e.g.
//
// (1) Traditional use, creating a zipfile from existing files
// HZIP hz = CreateZip("c:\\simple1.zip",0);
// ZipAdd(hz,"znsimple.bmp", "c:\\simple.bmp");
// ZipAdd(hz,"znsimple.txt", "c:\\simple.txt");
// CloseZip(hz);
//
// (2) Memory use, creating an auto-allocated mem-based zip file from various sources
// HZIP hz = CreateZip(0,100000, 0);
// // adding a conventional file...
// ZipAdd(hz,"src1.txt", "c:\\src1.txt");
// // adding something from memory...
// char buf[1000]; for (int i=0; i<1000; i++) buf[i]=(char)(i&0x7F);
// ZipAdd(hz,"file.dat", buf,1000);
// // adding something from a pipe...
// HANDLE hread,hwrite; CreatePipe(&hread,&hwrite,NULL,0);
// HANDLE hthread = CreateThread(0,0,ThreadFunc,(void*)hwrite,0,0);
// ZipAdd(hz,"unz3.dat", hread,1000); // the '1000' is optional.
// WaitForSingleObject(hthread,INFINITE);
// CloseHandle(hthread); CloseHandle(hread);
// ... meanwhile DWORD WINAPI ThreadFunc(void *dat)
// { HANDLE hwrite = (HANDLE)dat;
// char buf[1000]={17};
// DWORD writ; WriteFile(hwrite,buf,1000,&writ,NULL);
// CloseHandle(hwrite);
// return 0;
// }
// // and now that the zip is created, let's do something with it:
// void *zbuf; unsigned long zlen; ZipGetMemory(hz,&zbuf,&zlen);
// HANDLE hfz = CreateFile("test2.zip",GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
// DWORD writ; WriteFile(hfz,zbuf,zlen,&writ,NULL);
// CloseHandle(hfz);
// CloseZip(hz);
//
// (3) Handle use, for file handles and pipes
// HANDLE hzread,hzwrite; CreatePipe(&hzread,&hzwrite,0,0);
// HANDLE hthread = CreateThread(0,0,ZipReceiverThread,(void*)hzread,0,0);
// HZIP hz = CreateZipHandle(hzwrite,0);
// // ... add to it
// CloseZip(hz);
// CloseHandle(hzwrite);
// WaitForSingleObject(hthread,INFINITE);
// CloseHandle(hthread);
// ... meanwhile DWORD WINAPI ZipReceiverThread(void *dat)
// { HANDLE hread = (HANDLE)dat;
// char buf[1000];
// while (true)
// { DWORD red; ReadFile(hread,buf,1000,&red,NULL);
// // ... and do something with this zip data we're receiving
// if (red==0) break;
// }
// CloseHandle(hread);
// return 0;
// }
// Now we indulge in a little skullduggery so that the code works whether
// the user has included just zip or both zip and unzip.
// Idea: if header files for both zip and unzip are present, then presumably
// the cpp files for zip and unzip are both present, so we will call
// one or the other of them based on a dynamic choice. If the header file
// for only one is present, then we will bind to that particular one.
ZRESULT CloseZipZ(HZIP hz);
unsigned int FormatZipMessageZ(ZRESULT code, char *buf,unsigned int len);
bool IsZipHandleZ(HZIP hz);
#ifdef _unzip_H
#undef CloseZip
#define CloseZip(hz) (IsZipHandleZ(hz)?CloseZipZ(hz):CloseZipU(hz))
#else
#define CloseZip CloseZipZ
#define FormatZipMessage FormatZipMessageZ
#endif
#endif
#include <Windows.h>
#include <cstdlib>
#ifndef _zip_H
#define _zip_H
// ZIP functions -- for creating zip files
// This file is a repackaged form of the Info-Zip source code available
// at www.info-zip.org. The original copyright notice may be found in
// zip.cpp. The repackaging was done by Lucian Wischik to simplify and
// extend its use in Windows/C++. Also to add encryption and unicode.
#ifndef _unzip_H
DECLARE_HANDLE(HZIP);
#endif
// An HZIP identifies a zip file that is being created
typedef DWORD ZRESULT;
// return codes from any of the zip functions. Listed later.
HZIP CreateZip(const TCHAR* fn, const char* password);
HZIP CreateZip(void* buf, unsigned int len, const char* password);
HZIP CreateZipHandle(HANDLE h, const char* password);
// CreateZip - call this to start the creation of a zip file.
// As the zip is being created, it will be stored somewhere:
// to a pipe: CreateZipHandle(hpipe_write);
// in a file (by handle): CreateZipHandle(hfile);
// in a file (by name): CreateZip("c:\\test.zip");
// in memory: CreateZip(buf, len);
// or in pagefile memory: CreateZip(0, len);
// The final case stores it in memory backed by the system paging file,
// where the zip may not exceed len bytes. This is a bit friendlier than
// allocating memory with new[]: it won't lead to fragmentation, and the
// memory won't be touched unless needed. That means you can give very
// large estimates of the maximum-size without too much worry.
// As for the password, it lets you encrypt every file in the archive.
// (This api doesn't support per-file encryption.)
// Note: because pipes don't allow random access, the structure of a zipfile
// created into a pipe is slightly different from that created into a file
// or memory. In particular, the compressed-size of the item cannot be
// stored in the zipfile until after the item itself. (Also, for an item added
// itself via a pipe, the uncompressed-size might not either be known until
// after.) This is not normally a problem. But if you try to unzip via a pipe
// as well, then the unzipper will not know these things about the item until
// after it has been unzipped. Therefore: for unzippers which don't just write
// each item to disk or to a pipe, but instead pre-allocate memory space into
// which to unzip them, then either you have to create the zip not to a pipe,
// or you have to add items not from a pipe, or at least when adding items
// from a pipe you have to specify the length.
// Note: for windows-ce, you cannot close the handle until after CloseZip.
// but for real windows, the zip makes its own copy of your handle, so you
// can close yours anytime.
ZRESULT ZipAdd(HZIP hz, const TCHAR* dstzn, const TCHAR* fn);
ZRESULT ZipAdd(HZIP hz, const TCHAR* dstzn, void* src, unsigned int len);
ZRESULT ZipAddHandle(HZIP hz, const TCHAR* dstzn, HANDLE h);
ZRESULT ZipAddHandle(HZIP hz, const TCHAR* dstzn, HANDLE h, unsigned int len);
ZRESULT ZipAddFolder(HZIP hz, const TCHAR* dstzn);
// ZipAdd - call this for each file to be added to the zip.
// dstzn is the name that the file will be stored as in the zip file.
// The file to be added to the zip can come
// from a pipe: ZipAddHandle(hz,"file.dat", hpipe_read);
// from a file: ZipAddHandle(hz,"file.dat", hfile);
// from a filen: ZipAdd(hz,"file.dat", "c:\\docs\\origfile.dat");
// from memory: ZipAdd(hz,"subdir\\file.dat", buf,len);
// (folder): ZipAddFolder(hz,"subdir");
// Note: if adding an item from a pipe, and if also creating the zip file itself
// to a pipe, then you might wish to pass a non-zero length to the ZipAddHandle
// function. This will let the zipfile store the item's size ahead of the
// compressed item itself, which in turn makes it easier when unzipping the
// zipfile from a pipe.
ZRESULT ZipGetMemory(HZIP hz, void** buf, unsigned long* len);
// ZipGetMemory - If the zip was created in memory, via ZipCreate(0,len),
// then this function will return information about that memory block.
// buf will receive a pointer to its start, and len its length.
// Note: you can't add any more after calling this.
ZRESULT CloseZip(HZIP hz);
// CloseZip - the zip handle must be closed with this function.
unsigned int FormatZipMessage(ZRESULT code, TCHAR* buf, unsigned int len);
// FormatZipMessage - given an error code, formats it as a string.
// It returns the length of the error message. If buf/len points
// to a real buffer, then it also writes as much as possible into there.
// These are the result codes:
#define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
#define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
// The following come from general system stuff (e.g. files not openable)
#define ZR_GENMASK 0x0000FF00
#define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
#define ZR_NOFILE 0x00000200 // couldn't create/open the file
#define ZR_NOALLOC 0x00000300 // failed to allocate some resource
#define ZR_WRITE 0x00000400 // a general error writing to the file
#define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
#define ZR_MORE 0x00000600 // there's still more data to be unzipped
#define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
#define ZR_READ 0x00000800 // a general error reading the file
// The following come from mistakes on the part of the caller
#define ZR_CALLERMASK 0x00FF0000
#define ZR_ARGS 0x00010000 // general mistake with the arguments
#define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
#define ZR_MEMSIZE 0x00030000 // the memory size is too small
#define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
#define ZR_ENDED 0x00050000 // the zip creation has already been closed
#define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
#define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
#define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
// The following come from bugs within the zip library itself
#define ZR_BUGMASK 0xFF000000
#define ZR_NOTINITED 0x01000000 // initialisation didn't work
#define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
#define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
#define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
// e.g.
//
// (1) Traditional use, creating a zipfile from existing files
// HZIP hz = CreateZip("c:\\simple1.zip",0);
// ZipAdd(hz,"znsimple.bmp", "c:\\simple.bmp");
// ZipAdd(hz,"znsimple.txt", "c:\\simple.txt");
// CloseZip(hz);
//
// (2) Memory use, creating an auto-allocated mem-based zip file from various sources
// HZIP hz = CreateZip(0,100000, 0);
// // adding a conventional file...
// ZipAdd(hz,"src1.txt", "c:\\src1.txt");
// // adding something from memory...
// char buf[1000]; for (int i=0; i<1000; i++) buf[i]=(char)(i&0x7F);
// ZipAdd(hz,"file.dat", buf,1000);
// // adding something from a pipe...
// HANDLE hread,hwrite; CreatePipe(&hread,&hwrite,NULL,0);
// HANDLE hthread = CreateThread(0,0,ThreadFunc,(void*)hwrite,0,0);
// ZipAdd(hz,"unz3.dat", hread,1000); // the '1000' is optional.
// WaitForSingleObject(hthread,INFINITE);
// CloseHandle(hthread); CloseHandle(hread);
// ... meanwhile DWORD WINAPI ThreadFunc(void *dat)
// { HANDLE hwrite = (HANDLE)dat;
// char buf[1000]={17};
// DWORD writ; WriteFile(hwrite,buf,1000,&writ,NULL);
// CloseHandle(hwrite);
// return 0;
// }
// // and now that the zip is created, let's do something with it:
// void *zbuf; unsigned long zlen; ZipGetMemory(hz,&zbuf,&zlen);
// HANDLE hfz = CreateFile("test2.zip",GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
// DWORD writ; WriteFile(hfz,zbuf,zlen,&writ,NULL);
// CloseHandle(hfz);
// CloseZip(hz);
//
// (3) Handle use, for file handles and pipes
// HANDLE hzread,hzwrite; CreatePipe(&hzread,&hzwrite,0,0);
// HANDLE hthread = CreateThread(0,0,ZipReceiverThread,(void*)hzread,0,0);
// HZIP hz = CreateZipHandle(hzwrite,0);
// // ... add to it
// CloseZip(hz);
// CloseHandle(hzwrite);
// WaitForSingleObject(hthread,INFINITE);
// CloseHandle(hthread);
// ... meanwhile DWORD WINAPI ZipReceiverThread(void *dat)
// { HANDLE hread = (HANDLE)dat;
// char buf[1000];
// while (true)
// { DWORD red; ReadFile(hread,buf,1000,&red,NULL);
// // ... and do something with this zip data we're receiving
// if (red==0) break;
// }
// CloseHandle(hread);
// return 0;
// }
// Now we indulge in a little skullduggery so that the code works whether
// the user has included just zip or both zip and unzip.
// Idea: if header files for both zip and unzip are present, then presumably
// the cpp files for zip and unzip are both present, so we will call
// one or the other of them based on a dynamic choice. If the header file
// for only one is present, then we will bind to that particular one.
ZRESULT CloseZipZ(HZIP hz);
unsigned int FormatZipMessageZ(ZRESULT code, char* buf, unsigned int len);
bool IsZipHandleZ(HZIP hz);
#ifdef _unzip_H
#undef CloseZip
#define CloseZip(hz) (IsZipHandleZ(hz)?CloseZipZ(hz):CloseZipU(hz))
#else
#define CloseZip CloseZipZ
#define FormatZipMessage FormatZipMessageZ
#endif
#endif
+99
View File
@@ -0,0 +1,99 @@
#include "uMod_Main.h"
uMod_FileHandler::uMod_FileHandler()
{
Message("uMod_FileHandler(): %lu\n", this);
Number = 0;
FieldCounter = 0;
Files = nullptr;
}
uMod_FileHandler::~uMod_FileHandler()
{
Message("~uMod_FileHandler(): %lu\n", this);
if (Files != nullptr) {
for (int i = 0; i < FieldCounter; i++) {
delete [] Files[i];
}
delete [] Files;
}
}
int uMod_FileHandler::Add(TextureFileStruct* file)
{
Message("uMod_FileHandler::Add(%lu): %lu\n", file, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
if (file->Reference >= 0) {
return RETURN_UPDATE_ALLREADY_ADDED;
}
if (Number / FieldLength == FieldCounter) // get more memory
{
TextureFileStruct*** temp = nullptr;
try { temp = new TextureFileStruct**[FieldCounter + 10]; }
catch (...) {
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return RETURN_NO_MEMORY;
}
for (int i = 0; i < FieldCounter; i++) {
temp[i] = Files[i]; //copy to new allocated memory
}
for (int i = FieldCounter; i < FieldCounter + 10; i++) {
temp[i] = nullptr; // initialize unused parts to zero
}
FieldCounter += 10;
delete [] Files;
Files = temp;
}
if (Number % FieldLength == 0) // maybe we need to get more memory
{
try {
if (Files[Number / FieldLength] == nullptr) {
Files[Number / FieldLength] = new TextureFileStruct*[FieldLength];
}
}
catch (...) {
Files[Number / FieldLength] = nullptr;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return RETURN_NO_MEMORY;
}
}
Files[Number / FieldLength][Number % FieldLength] = file;
file->Reference = Number++; //set the reference for a fast deleting
return RETURN_OK;
}
int uMod_FileHandler::Remove(TextureFileStruct* file)
{
Message("uMod_FileHandler::Remove(%lu): %lu\n", file, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
const int ref = file->Reference;
if (ref < 0) {
return RETURN_OK; // returning if no Reference is set
}
file->Reference = -1; //set reference outside of bound
if (ref < (--Number)) //if reference is unequal to Number-1 we copy the last entry to the index "ref"
{
Files[ref / FieldLength][ref % FieldLength] = Files[Number / FieldLength][Number % FieldLength];
Files[ref / FieldLength][ref % FieldLength]->Reference = ref; //set the new reference entry
}
return RETURN_OK;
}
+365
View File
@@ -0,0 +1,365 @@
#include "uMod_DX9_dll.h"
#include "uMod_Main.h"
#include <Windows.h>
#include <Psapi.h>
#include <TlHelp32.h>
#pragma comment(lib, "Psapi.lib")
//#include "detours.h"
//#include "detourxs/detourxs/detourxs.h"
/*
#include "detourxs/detourxs/ADE32.cpp"
#include "detourxs/detourxs/detourxs.cpp"
*/
/*
* global variable which are not linked external
*/
HINSTANCE gl_hOriginalDll = nullptr;
HINSTANCE gl_hThisInstance = nullptr;
uMod_TextureServer* gl_TextureServer = nullptr;
HANDLE gl_ServerThread = nullptr;
using Direct3DCreate9_type = IDirect3D9* (APIENTRY*)(UINT);
using Direct3DCreate9Ex_type = HRESULT(APIENTRY*)(UINT SDKVersion, IDirect3D9Ex** ppD3D);
Direct3DCreate9_type Direct3DCreate9_fn; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
Direct3DCreate9Ex_type Direct3DCreate9Ex_fn; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
HHOOK gl_hHook = nullptr;
static FILE* stdout_proxy;
static FILE* stderr_proxy;
/*
* global variable which are linked external
*/
unsigned int gl_ErrorState = 0u;
#ifdef LOG_MESSAGE
FILE* gl_File = nullptr;
#endif
#ifdef DIRECT_INJECTION
void Nothing() { (void)NULL; }
#endif
/*
* dll entry routine, here we initialize or clean up
*/
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
UNREFERENCED_PARAMETER(lpReserved);
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH: {
#ifdef BUILD_TYPE_DEBUG
AllocConsole();
SetConsoleTitleA("uMod Console");
freopen_s(&stdout_proxy, "CONOUT$", "w", stdout);
freopen_s(&stderr_proxy, "CONOUT$", "w", stderr);
#endif
InitInstance(hModule);
break;
}
case DLL_PROCESS_DETACH: {
ExitInstance();
break;
}
default: break;
}
return true;
}
DWORD WINAPI ServerThread(LPVOID lpParam)
{
UNREFERENCED_PARAMETER(lpParam);
if (gl_TextureServer != nullptr) {
gl_TextureServer->MainLoop(); //This is and endless mainloop, it sleep till something is written into the pipe.
}
return 0;
}
void InitInstance(HINSTANCE hModule)
{
DisableThreadLibraryCalls(hModule); //reduce overhead
gl_hThisInstance = hModule;
char game[MAX_PATH];
if (HookThisProgram(game)) //ask if we need to hook this program
{
OpenMessage();
Message("InitInstance: %lu\n", hModule);
char uMod[MAX_PATH];
for (auto i = 0; i < MAX_PATH; i++) {
uMod[i] = 0;
}
GetModuleFileNameA(hModule, uMod, MAX_PATH);
Message("InitInstance: %s\n", uMod);
gl_TextureServer = new uMod_TextureServer(game, uMod); //create the server which listen on the pipe and prepare the update for the texture clients
LoadOriginalDll();
if (gl_hOriginalDll) {
Direct3DCreate9_fn = (Direct3DCreate9_type)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9");
if (Direct3DCreate9_fn != nullptr) {
Message("Detour: Direct3DCreate9\n");
Direct3DCreate9_fn = static_cast<Direct3DCreate9_type>(DetourFunc((BYTE*)Direct3DCreate9_fn, (BYTE*)uMod_Direct3DCreate9, 5));
}
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9Ex");
if (Direct3DCreate9Ex_fn != nullptr) {
Message("Detour: Direct3DCreate9Ex\n");
Direct3DCreate9Ex_fn = static_cast<Direct3DCreate9Ex_type>(DetourFunc((BYTE*)Direct3DCreate9Ex_fn, (BYTE*)uMod_Direct3DCreate9Ex, 7));
}
}
gl_ServerThread = CreateThread(nullptr, 0, ServerThread, nullptr, 0, nullptr); //creating a thread for the mainloop
if (gl_ServerThread == nullptr) { Message("InitInstance: Serverthread not started\n"); }
}
}
bool HasDesiredMethods(HMODULE hModule, HANDLE hProcess)
{
const auto d3dcreate9Addr = GetProcAddress(hModule, "Direct3DCreate9");
if (!d3dcreate9Addr) {
return false;
}
const auto d3dcreate9ExAddr = GetProcAddress(hModule, "Direct3DCreate9Ex");
if (!d3dcreate9ExAddr) {
return false;
}
return true;
}
bool IsDesiredModule(HMODULE hModule, HANDLE hProcess)
{
TCHAR szModuleName[MAX_PATH];
GetModuleBaseName(hProcess, hModule, szModuleName, sizeof(szModuleName) / sizeof(TCHAR));
return strcmp(szModuleName, TEXT("d3d9.dll")) == 0;
}
bool FindLoadedDll()
{
HMODULE hModules[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i;
// Get a handle to the current process.
hProcess = GetCurrentProcess();
if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded)) {
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) {
if (IsDesiredModule(hModules[i], hProcess)) {
// If the module is d3d9.dll, store the handle or do your hooking here.
gl_hOriginalDll = hModules[i];
break;
}
if (HasDesiredMethods(hModules[i], hProcess)) {
// If the module has the two specific methods, store the handle or do your hooking here.
gl_hOriginalDll = hModules[i];
break;
}
}
}
if (gl_hOriginalDll) {
return true;
}
return false;
}
void LoadOriginalDll()
{
if (FindLoadedDll()) {
return;
}
char buffer[MAX_PATH];
GetSystemDirectory(buffer, MAX_PATH); //get the system directory, we need to open the original d3d9.dll
// Append dll name
strcat_s(buffer, MAX_PATH, "\\d3d9.dll");
// try to load the system's d3d9.dll, if pointer empty
if (!gl_hOriginalDll) {
gl_hOriginalDll = LoadLibrary(buffer);
}
if (!gl_hOriginalDll) {
ExitProcess(0); // exit the hard way
}
}
void ExitInstance()
{
if (gl_ServerThread != nullptr) {
CloseHandle(gl_ServerThread); // kill the server thread
gl_ServerThread = nullptr;
}
if (gl_TextureServer != nullptr) {
delete gl_TextureServer; //delete the texture server
gl_TextureServer = nullptr;
}
// Release the system's d3d9.dll
if (gl_hOriginalDll != nullptr) {
FreeLibrary(gl_hOriginalDll);
gl_hOriginalDll = nullptr;
}
#ifdef BUILD_TYPE_DEBUG
if (stdout_proxy)
fclose(stdout_proxy);
if (stderr_proxy)
fclose(stderr_proxy);
FreeConsole();
#endif
CloseMessage();
}
/*
* We inject the dll into the game, thus we retour the original Direct3DCreate9 function to our MyDirect3DCreate9 function
*/
IDirect3D9* APIENTRY uMod_Direct3DCreate9(UINT SDKVersion)
{
Message("uMod_Direct3DCreate9: original %lu, uMod %lu\n", Direct3DCreate9_fn, uMod_Direct3DCreate9);
// in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines
// but somehow, for me it only works, if I retour the function and calling afterward the original function
// BEGIN
LoadOriginalDll();
RetourFunc((BYTE*)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9"), (BYTE*)Direct3DCreate9_fn, 5);
Direct3DCreate9_fn = (Direct3DCreate9_type)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9");
/*
if (Direct3DCreate9Ex_fn!=NULL)
{
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex"), (BYTE*)Direct3DCreate9Ex_fn, 7);
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex");
}
*/
// END
IDirect3D9* pIDirect3D9_orig = nullptr;
if (Direct3DCreate9_fn) {
pIDirect3D9_orig = Direct3DCreate9_fn(SDKVersion); //creating the original IDirect3D9 object
}
else {
return nullptr;
}
uMod_IDirect3D9* pIDirect3D9;
if (pIDirect3D9_orig) {
pIDirect3D9 = new uMod_IDirect3D9(pIDirect3D9_orig, gl_TextureServer); //creating our uMod_IDirect3D9 object
}
// we detour again
Direct3DCreate9_fn = static_cast<Direct3DCreate9_type>(DetourFunc((BYTE*)Direct3DCreate9_fn, (BYTE*)uMod_Direct3DCreate9, 5));
/*
if (Direct3DCreate9Ex_fn!=NULL)
{
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*) Direct3DCreate9Ex_fn, (BYTE*)uMod_Direct3DCreate9Ex,7);
}
*/
return pIDirect3D9; //return our object instead of the "real one"
}
HRESULT APIENTRY uMod_Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex** ppD3D)
{
Message("uMod_Direct3DCreate9Ex: original %lu, uMod %lu\n", Direct3DCreate9Ex_fn, uMod_Direct3DCreate9Ex);
// in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines
// but somehow, for me it only works, if I retour the function and calling afterward the original function
// BEGIN
LoadOriginalDll();
/*
if (Direct3DCreate9_fn!=NULL)
{
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9"), (BYTE*)Direct3DCreate9_fn, 5);
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
}
*/
RetourFunc((BYTE*)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9Ex"), (BYTE*)Direct3DCreate9Ex_fn, 7);
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9Ex");
// END
IDirect3D9Ex* pIDirect3D9Ex_orig = nullptr;
HRESULT ret;
if (Direct3DCreate9Ex_fn) {
ret = Direct3DCreate9Ex_fn(SDKVersion, &pIDirect3D9Ex_orig); //creating the original IDirect3D9 object
}
else {
return D3DERR_NOTAVAILABLE;
}
if (ret != S_OK) {
return ret;
}
uMod_IDirect3D9Ex* pIDirect3D9Ex;
if (pIDirect3D9Ex_orig) {
pIDirect3D9Ex = new uMod_IDirect3D9Ex(pIDirect3D9Ex_orig, gl_TextureServer); //creating our uMod_IDirect3D9 object
}
// we detour again
/*
if (Direct3DCreate9_fn!=NULL)
{
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*) Direct3DCreate9_fn, (BYTE*)uMod_Direct3DCreate9,5);
}
*/
Direct3DCreate9Ex_fn = static_cast<Direct3DCreate9Ex_type>(DetourFunc((BYTE*)Direct3DCreate9Ex_fn, (BYTE*)uMod_Direct3DCreate9Ex, 7));
ppD3D = (IDirect3D9Ex**)&pIDirect3D9Ex; //return our object instead of the "real one"
return ret;
}
bool HookThisProgram(char* ret)
{
char Game[MAX_PATH];
GetModuleFileName(GetModuleHandle(nullptr), Game, MAX_PATH); //ask for name and path of this executable
// we inject directly
int i = 0;
while (Game[i]) {
ret[i] = Game[i];
i++;
}
ret[i] = 0;
return true;
}
void* DetourFunc(BYTE* src, const BYTE* dst, const int len)
{
auto jmp = static_cast<BYTE*>(malloc(len + 5));
DWORD dwback = 0;
VirtualProtect(jmp, len + 5, PAGE_EXECUTE_READWRITE, &dwback); //This is the addition needed for Windows 7 RC
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len);
jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp + 1) = static_cast<DWORD>(src + len - jmp) - 5;
memset(src, 0x90, len);
src[0] = 0xE9;
*(DWORD*)(src + 1) = static_cast<DWORD>(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return jmp - len;
}
bool RetourFunc(BYTE* src, BYTE* restore, const int len)
{
DWORD dwback;
if (!VirtualProtect(src, len, PAGE_READWRITE, &dwback)) { return false; }
if (!memcpy(src, restore, len)) { return false; }
restore[0] = 0xE9;
*(DWORD*)(restore + 1) = static_cast<DWORD>(src - restore) - 5;
if (!VirtualProtect(src, len, dwback, &dwback)) { return false; }
return true;
}
+485
View File
@@ -0,0 +1,485 @@
#include "uMod_Main.h"
#include "unzip.h"
#include "uMod_File.h"
#include "utils.h"
#include "uMod_Texture.h"
#include <fstream>
#include <sstream>
#include <vector>
#ifdef __CDT_PARSER__
#define FindZipItem(...) 0
#define UnzipItem(...) 0
#define CloseZip(...) 0
#define GetZipItem(...) 0
#endif
uMod_File::uMod_File()
{
Loaded = false;
XORed = false;
FileInMemory = static_cast<char*>(nullptr);
MemoryLength = 0u;
FileLen = 0u;
}
uMod_File::uMod_File(const std::string file)
{
Loaded = false;
XORed = false;
FileInMemory = static_cast<char*>(nullptr);
MemoryLength = 0u;
FileLen = 0u;
SetFile(file);
}
uMod_File::~uMod_File()
{
if (FileInMemory != static_cast<char*>(nullptr)) {
delete[] FileInMemory;
}
}
bool uMod_File::FileSupported()
{
const std::string file_type = GetFileExtension(FileName);
if (file_type == "zip") {
return true;
}
if (file_type == "tpf") {
return true;
}
if (file_type == "bmp") {
return true;
}
if (file_type == "jpg") {
return true;
}
if (file_type == "tga") {
return true;
}
if (file_type == "png") {
return true;
}
if (file_type == "dds") {
return true;
}
if (file_type == "ppm") {
return true;
}
return false;
}
bool uMod_File::PackageFile()
{
const std::string file_type = GetFileExtension(FileName);
if (file_type == "zip") {
return true;
}
if (file_type == "tpf") {
return true;
}
return false;
}
bool uMod_File::SingleFile()
{
const std::string file_type = GetFileExtension(FileName);
if (file_type == "bmp") {
return true;
}
if (file_type == "jpg") {
return true;
}
if (file_type == "tga") {
return true;
}
if (file_type == "png") {
return true;
}
if (file_type == "dds") {
return true;
}
if (file_type == "ppm") {
return true;
}
return false;
}
int uMod_File::GetContent()
{
const std::string file_type = GetFileExtension(FileName);
if (file_type == "zip") {
AddZip();
}
else if (file_type == "tpf") {
AddTpf();
}
else if (SingleFile()) {
AddFile();
}
else {
printf(FileName.c_str());
printf(" Not supported\n");
return -1;
}
return 0;
}
int uMod_File::ReadFile()
{
if (Loaded) {
return 0;
}
XORed = false;
const auto name = FileName;
std::ifstream inputFile(name, std::ios::binary);
if (!inputFile ||
!inputFile.is_open()) {
printf(name.c_str());
printf(" Could not open\n");
return -1;
}
const std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile), {});
if (FileInMemory) {
delete[] FileInMemory;
}
FileInMemory = new char[buffer.size()];
for (auto i = 0; i < buffer.size(); i++) {
FileInMemory[i] = buffer[i];
}
FileLen = buffer.size();
inputFile.close();
FileInMemory[FileLen] = 0;
printf(name.c_str());
printf("%d\n", FileLen);
Loaded = true;
return 0;
}
int uMod_File::UnXOR()
{
if (XORed) {
return 0;
}
/*
*
* BIG THANKS TO Tonttu
* (TPFcreate 1.5)
*
*/
const auto buff = (unsigned int*)FileInMemory;
const unsigned int TPF_XOR = 0x3FA43FA4u;
const unsigned int size = FileLen / 4u;
for (unsigned int i = 0; i < size; i++) {
buff[i] ^= TPF_XOR;
}
for (unsigned int i = size * 4u; i < size * 4u + FileLen % 4u; i++) {
((unsigned char*)FileInMemory)[i] ^= static_cast<unsigned char>(TPF_XOR);
}
unsigned int pos = FileLen - 1;
while (pos > 0u && FileInMemory[pos]) {
pos--;
}
if (pos > 0u && pos < FileLen - 1) {
FileLen = pos + 1;
}
XORed = true;
/*
* original code by Tonttu
* The last bytes are not revealed correctly
unsigned int j=0;
while ( j <= result - 4 )
{
*( unsigned int* )( &buffer[j] ) ^= TPF_XOR;
j += 4;
}
while ( j < result )
{
buffer[j] ^= (unsigned char )( TPF_XOR >> 24 );
TPF_XOR <<= 4;
j++;
}
*/
return 0;
}
int uMod_File::AddFile()
{
DWORD64 temp_hash;
std::string name = AfterLast(FileName, '_');
name = BeforeLast(name, '.');
try {
// Convert hexadecimal string to unsigned long long
temp_hash = std::stoull(name, nullptr, 16);
}
catch (const std::invalid_argument& e) {
printf("Encountered error");
printf(e.what());
}
catch (const std::out_of_range& e) {
printf("Encountered error");
printf(e.what());
}
if (const int ret = ReadFile()) {
return ret;
}
FileHash = temp_hash;
return 0;
}
int uMod_File::AddZip()
{
if (const int ret = ReadFile()) {
return ret;
}
return AddContent(nullptr);
}
int uMod_File::AddTpf()
{
if (const int ret = ReadFile()) {
return ret;
}
UnXOR();
constexpr char pw[] = {
0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, static_cast<char>(0xA6), static_cast<char>(0xBD),
0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F,
0x74, 0x61, 0x67, 0x5B, 0x60, 0x70, 0x45, 0x74,
0x5C, 0x22, 0x74, 0x5D, 0x6E, 0x6A, 0x73, 0x41,
0x77, 0x6E, 0x46, 0x47, 0x77, 0x49, 0x0C, 0x4B,
0x46, 0x6F, '\0'
};
return AddContent(pw);
}
int uMod_File::AddContent(const char* pw)
{
// Thats is really nasty code, but atm I am happy that it works. I should try an other unzip api,
// This one seems to behave very strange.
// I know, that also a bug in my code could be reason for the crashes, but UnzipItem( ... ) unzipes wrong files
// and GetZipItem( ... ) returns garbage as file names, and the next call of GetZipItem( ... ) blows up the program.
//
// I have commented line 3519 in unzip.cpp.
// It was stated this is a bug, but it did not solve my problems.
//
// closing and reopen the zip handle did the trick.
//
const auto& name = FileName;
HZIP ZIP_Handle = OpenZip(FileInMemory, FileLen, pw);
if (ZIP_Handle == static_cast<HZIP>(nullptr)) {
printf(name.c_str());
printf(" Failed to unzip file\n");
return -1;
}
ZIPENTRY ze;
int index;
FindZipItem(ZIP_Handle, "texmod.def", false, &index, &ze);
if (index >= 0) //if texmod.def is present in the zip file
{
printf(name.c_str());
printf(" Unzipping based on texmod.def of size %d\n", ze.unc_size);
char* def;
int len = ze.unc_size;
try { def = new char[len + 1]; }
catch (...) {
printf(name.c_str());
printf(" Memory error\n");
return -1;
}
ZRESULT zr = UnzipItem(ZIP_Handle, index, def, len);
if (zr != ZR_OK && zr != ZR_MORE) {
delete[] def;
return -1;
}
def[len] = 0;
std::stringstream tokenStream(def);
std::string token;
DWORD64 temp_hash;
std::string entry;
std::string file;
while (std::getline(tokenStream, token)) {
entry = token;
printf(name.c_str());
printf(" Parsing token %s\n", token.c_str());
file = BeforeFirst(token, '|');
try {
temp_hash = std::stoull(file, nullptr, 16);
// Successful conversion; can continue processing...
}
catch (const std::invalid_argument&) {
// Handle invalid argument
printf(name.c_str());
printf(" Invalid hash\n");
continue; // Skip the rest of the current loop iteration
}
catch (const std::out_of_range&) {
// Handle out of range
printf(name.c_str());
printf(" Invalid hash\n");
continue; // Skip the rest of the current loop iteration
}
file = AfterFirst(entry, '|');
ReplaceAll(file, "\r", "");
while ((!file.empty() && file[0] == '.' && (file.size() > 1 && (file[1] == '/' || file[1] == '\\')))
|| (!file.empty() && (file[0] == '/' || file[0] == '\\'))) {
file.erase(0, 1);
}
FindZipItem(ZIP_Handle, file.c_str(), false, &index, &ze); // look for texture
if (index >= 0) {
std::vector<char> data;
UModTexture texture;
data.resize(ze.unc_size);
ZRESULT rz = UnzipItem(ZIP_Handle, index, data.data(), ze.unc_size);
if (rz != ZR_OK && rz != ZR_MORE) {
printf(name.c_str());
printf(" Unzip error\n");
}
else {
texture.hash = temp_hash;
texture.data = data;
texture.name = file;
Textures.push_back(texture);
printf(name.c_str());
printf(" Added texture of size %d %s\n", data.size(), file.c_str());
}
}
else {
printf(name.c_str());
printf(" Unzip error\n");
CloseZip(ZIP_Handle); //somehow we need to close and to reopen the zip handle, otherwise the program crashes
ZIP_Handle = OpenZip(FileInMemory, FileLen, pw);
}
}
delete[] def;
CloseZip(ZIP_Handle);
if (Textures.size() == 0) {
printf(name.c_str());
printf(" No textures parsed\n");
return -1;
}
return 0;
}
//we load each dds file
{
printf(name.c_str());
printf(" Unzipping without texmode.def\n");
CloseZip(ZIP_Handle); //somehow we need to close and to reopen the zip handle, otherwise the program crashes
ZIP_Handle = OpenZip(FileInMemory, FileLen, pw);
if (ZIP_Handle == static_cast<HZIP>(nullptr)) {
printf(name.c_str());
printf(" Failed to unzip file");
return -1;
}
std::string file;
GetZipItem(ZIP_Handle, -1, &ze); //ask for number of entries
int num = ze.index;
DWORD64 temp_hash;
for (int i = 0; i < num; i++) {
if (GetZipItem(ZIP_Handle, i, &ze) != ZR_OK) {
continue; //ask for name and size
}
int len = ze.unc_size;
printf(name.c_str());
printf(" Parsing token %s\n", ze.name);
std::vector<char> data;
UModTexture texture;
data.resize(ze.unc_size);
ZRESULT rz = UnzipItem(ZIP_Handle, i, data.data(), len);
if (rz != ZR_OK && rz != ZR_MORE) {
printf(name.c_str());
printf(" Unzip error\n");
continue;
}
file = ze.name;
if (file.size() == 0) {
continue;
}
if (file == "Comment.txt") // skip comment
{
continue;
}
auto entryName = AfterLast(file, '.');
if (entryName != "dds") {
continue;
}
entryName = AfterLast(file, L'_');
entryName = BeforeLast(entryName, L'.');
try {
temp_hash = std::stoull(entryName, nullptr, 16); // Convert hex string to number
}
catch (const std::invalid_argument& e) {
printf(name.c_str());
printf(" Invalid hash\n");
continue;
}
catch (const std::out_of_range& e) {
printf(name.c_str());
printf(" Invalid hash\n");
continue;
}
texture.hash = temp_hash;
texture.name = entryName;
texture.data = data;
Textures.push_back(texture);
printf(name.c_str());
printf(" Added texture of size %d %s\n", data.size(), entryName.c_str());
}
CloseZip(ZIP_Handle);
if (Textures.size() == 0) {
printf(name.c_str());
printf(" No textures parsed\n");
return -1;
}
return 0;
}
return 0;
}
+135
View File
@@ -0,0 +1,135 @@
#include "uMod_Main.h"
#ifndef PRE_MESSAGE
#define PRE_MESSAGE "uMod_IDirect3D9"
#endif
uMod_IDirect3D9::uMod_IDirect3D9(IDirect3D9* pOriginal, uMod_TextureServer* server)
{
Message(PRE_MESSAGE "::" PRE_MESSAGE "( %lu, %lu): %lu\n", pOriginal, server, this);
m_pIDirect3D9 = pOriginal;
uMod_Server = server;
}
uMod_IDirect3D9::~uMod_IDirect3D9()
{
Message(PRE_MESSAGE "::~" PRE_MESSAGE "(): %lu\n", this);
}
HRESULT __stdcall uMod_IDirect3D9::QueryInterface(REFIID riid, void** ppvObj)
{
*ppvObj = nullptr;
// call this to increase AddRef at original object
// and to check if such an interface is there
const HRESULT hRes = m_pIDirect3D9->QueryInterface(riid, ppvObj);
if (hRes == NOERROR) // if OK, send our "fake" address
{
*ppvObj = this;
}
return hRes;
}
ULONG __stdcall uMod_IDirect3D9::AddRef()
{
return m_pIDirect3D9->AddRef();
}
ULONG __stdcall uMod_IDirect3D9::Release()
{
// call original routine
const ULONG count = m_pIDirect3D9->Release();
// in case no further Ref is there, the Original Object has deleted itself
if (count == 0) {
delete this;
}
return count;
}
HRESULT __stdcall uMod_IDirect3D9::RegisterSoftwareDevice(void* pInitializeFunction)
{
return m_pIDirect3D9->RegisterSoftwareDevice(pInitializeFunction);
}
UINT __stdcall uMod_IDirect3D9::GetAdapterCount()
{
return m_pIDirect3D9->GetAdapterCount();
}
HRESULT __stdcall uMod_IDirect3D9::GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier)
{
return m_pIDirect3D9->GetAdapterIdentifier(Adapter, Flags, pIdentifier);
}
UINT __stdcall uMod_IDirect3D9::GetAdapterModeCount(UINT Adapter, D3DFORMAT Format)
{
return m_pIDirect3D9->GetAdapterModeCount(Adapter, Format);
}
HRESULT __stdcall uMod_IDirect3D9::EnumAdapterModes(UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode)
{
return m_pIDirect3D9->EnumAdapterModes(Adapter, Format, Mode, pMode);
}
HRESULT __stdcall uMod_IDirect3D9::GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE* pMode)
{
return m_pIDirect3D9->GetAdapterDisplayMode(Adapter, pMode);
}
HRESULT __stdcall uMod_IDirect3D9::CheckDeviceType(UINT iAdapter, D3DDEVTYPE DevType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed)
{
return m_pIDirect3D9->CheckDeviceType(iAdapter, DevType, DisplayFormat, BackBufferFormat, bWindowed);
}
HRESULT __stdcall uMod_IDirect3D9::CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
{
return m_pIDirect3D9->CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
}
HRESULT __stdcall uMod_IDirect3D9::CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels)
{
return m_pIDirect3D9->CheckDeviceMultiSampleType(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
}
HRESULT __stdcall uMod_IDirect3D9::CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
{
return m_pIDirect3D9->CheckDepthStencilMatch(Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
}
HRESULT __stdcall uMod_IDirect3D9::CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat)
{
return m_pIDirect3D9->CheckDeviceFormatConversion(Adapter, DeviceType, SourceFormat, TargetFormat);
}
HRESULT __stdcall uMod_IDirect3D9::GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps)
{
return m_pIDirect3D9->GetDeviceCaps(Adapter, DeviceType, pCaps);
}
HMONITOR __stdcall uMod_IDirect3D9::GetAdapterMonitor(UINT Adapter)
{
return m_pIDirect3D9->GetAdapterMonitor(Adapter);
}
HRESULT __stdcall uMod_IDirect3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface)
{
Message(PRE_MESSAGE "::CreateDevice(): %lu\n", this);
// we intercept this call and provide our own "fake" Device Object
const HRESULT hres = m_pIDirect3D9->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
int count = 1;
if (pPresentationParameters != nullptr) {
count = pPresentationParameters->BackBufferCount;
}
const auto pIDirect3DDevice9 = new uMod_IDirect3DDevice9(*ppReturnedDeviceInterface, uMod_Server, count);
// store our pointer (the fake one) for returning it to the calling program
*ppReturnedDeviceInterface = pIDirect3DDevice9;
return hres;
}
+48
View File
@@ -0,0 +1,48 @@
#include "uMod_Main.h"
#define IDirect3D9 IDirect3D9Ex
#define uMod_IDirect3D9 uMod_IDirect3D9Ex
#define m_pIDirect3D9 m_pIDirect3D9Ex
#define PRE_MESSAGE "uMod_IDirect3D9Ex"
// ReSharper disable once CppUnusedIncludeDirective
#include "uMod_IDirect3D9.cpp"
HRESULT __stdcall uMod_IDirect3D9Ex::CreateDeviceEx(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode,
IDirect3DDevice9Ex** ppReturnedDeviceInterface)
{
Message("uMod_IDirect3D9Ex::CreateDeviceEx: %lu\n", this);
// we intercept this call and provide our own "fake" Device Object
const HRESULT hres = m_pIDirect3D9Ex->CreateDeviceEx(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface);
int count = 1;
if (pPresentationParameters != nullptr) {
count = pPresentationParameters->BackBufferCount;
}
const auto pIDirect3DDevice9Ex = new uMod_IDirect3DDevice9Ex(*ppReturnedDeviceInterface, uMod_Server, count);
// store our pointer (the fake one) for returning it to the calling program
*ppReturnedDeviceInterface = pIDirect3DDevice9Ex;
return hres;
}
HRESULT __stdcall uMod_IDirect3D9Ex::EnumAdapterModesEx(UINT Adapter, const D3DDISPLAYMODEFILTER* pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode)
{
return m_pIDirect3D9Ex->EnumAdapterModesEx(Adapter, pFilter, Mode, pMode);
}
HRESULT __stdcall uMod_IDirect3D9Ex::GetAdapterDisplayModeEx(UINT Adapter, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation)
{
return m_pIDirect3D9Ex->GetAdapterDisplayModeEx(Adapter, pMode, pRotation);
}
HRESULT __stdcall uMod_IDirect3D9Ex::GetAdapterLUID(UINT Adapter, LUID* pLUID)
{
return m_pIDirect3D9Ex->GetAdapterLUID(Adapter, pLUID);
}
UINT __stdcall uMod_IDirect3D9Ex::GetAdapterModeCountEx(UINT Adapter, const D3DDISPLAYMODEFILTER* pFilter)
{
return m_pIDirect3D9Ex->GetAdapterModeCountEx(Adapter, pFilter);
}
+360
View File
@@ -0,0 +1,360 @@
#include "uMod_Main.h"
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::QueryInterface(REFIID riid, void** ppvObj)
{
if (riid == IID_IDirect3D9) {
// This function should never be called with IID_IDirect3D9 by the game
// thus this call comes from our own dll to ask for the texture type
// 0x01000000L == uMod_IDirect3DTexture9
// 0x01000001L == uMod_IDirect3DVolumeTexture9
// 0x01000002L == uMod_IDirect3DCubeTexture9
*ppvObj = this;
return 0x01000002L;
}
HRESULT hRes;
if (CrossRef_D3Dtex != nullptr) {
hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj == CrossRef_D3Dtex->m_D3Dtex) {
*ppvObj = this;
}
}
else {
hRes = m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj == m_D3Dtex) {
*ppvObj = this;
}
}
return hRes;
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DCubeTexture9::AddRef()
{
if (FAKE) {
return 1; //bug, this case should never happen
}
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->AddRef();
}
return m_D3Dtex->AddRef();
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DCubeTexture9::Release()
{
Message("uMod_IDirect3DCubeTexture9::Release(): %lu\n", this);
void* cpy;
const long ret = m_D3Ddev->QueryInterface(IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE) {
UnswitchTextures(this);
count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures
}
else {
if (CrossRef_D3Dtex != nullptr) //if this texture is switched with a fake texture
{
uMod_IDirect3DCubeTexture9* fake_texture = CrossRef_D3Dtex;
count = fake_texture->m_D3Dtex->Release(); //release the original texture
if (count == 0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (ret == 0x01000000L) {
if (static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetSingleCubeTexture() != fake_texture) {
fake_texture->Release(); // we release the fake texture
}
}
else {
if (static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetSingleCubeTexture() != fake_texture) {
fake_texture->Release(); // we release the fake texture
}
}
}
}
else {
count = m_D3Dtex->Release();
}
}
if (count == 0) //if this texture is released, we clean up
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (ret == 0x01000000L) {
if (static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetLastCreatedCubeTexture() == this) {
static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->SetLastCreatedCubeTexture(nullptr);
}
else {
static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
}
else {
if (static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetLastCreatedCubeTexture() == this) {
static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->SetLastCreatedCubeTexture(nullptr);
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
}
delete(this);
}
return count;
}
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetDevice(IDirect3DDevice9** ppDevice)
{
*ppDevice = m_D3Ddev;
return D3D_OK;
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::SetPrivateData(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
return m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData);
}
return m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::FreePrivateData(REFGUID refguid)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid);
}
return m_D3Dtex->FreePrivateData(refguid);
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::SetPriority(DWORD PriorityNew)
{
return m_D3Dtex->SetPriority(PriorityNew);
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetPriority()
{
return m_D3Dtex->GetPriority();
}
void APIENTRY uMod_IDirect3DCubeTexture9::PreLoad()
{
m_D3Dtex->PreLoad();
}
D3DRESOURCETYPE APIENTRY uMod_IDirect3DCubeTexture9::GetType()
{
return m_D3Dtex->GetType();
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::SetLOD(DWORD LODNew)
{
return m_D3Dtex->SetLOD(LODNew);
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetLOD()
{
return m_D3Dtex->GetLOD();
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetLevelCount()
{
return m_D3Dtex->GetLevelCount();
}
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType)
{
return m_D3Dtex->SetAutoGenFilterType(FilterType);
}
D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DCubeTexture9::GetAutoGenFilterType()
{
return m_D3Dtex->GetAutoGenFilterType();
}
void APIENTRY uMod_IDirect3DCubeTexture9::GenerateMipSubLevels()
{
m_D3Dtex->GenerateMipSubLevels();
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::AddDirtyRect(D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->AddDirtyRect(FaceType, pDirtyRect);
}
return m_D3Dtex->AddDirtyRect(FaceType, pDirtyRect);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetLevelDesc(UINT Level, D3DSURFACE_DESC* pDesc)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc);
}
return m_D3Dtex->GetLevelDesc(Level, pDesc);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetCubeMapSurface(FaceType, Level, ppCubeMapSurface);
}
return m_D3Dtex->GetCubeMapSurface(FaceType, Level, ppCubeMapSurface);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect, DWORD Flags)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->LockRect(FaceType, Level, pLockedRect, pRect, Flags);
}
return m_D3Dtex->LockRect(FaceType, Level, pLockedRect, pRect, Flags);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->UnlockRect(FaceType, Level);
}
return m_D3Dtex->UnlockRect(FaceType, Level);
}
int uMod_IDirect3DCubeTexture9::GetHash(MyTypeHash& hash)
{
hash = 0u;
if (FAKE) {
return RETURN_BAD_ARGUMENT;
}
IDirect3DCubeTexture9* pTexture = m_D3Dtex;
if (CrossRef_D3Dtex != nullptr) {
pTexture = CrossRef_D3Dtex->m_D3Dtex;
}
//IDirect3DSurface9 *pOffscreenSurface = NULL;
//IDirect3DCubeTexture9 *pOffscreenTexture = NULL;
IDirect3DSurface9* pResolvedSurface = nullptr;
D3DLOCKED_RECT d3dlr;
D3DSURFACE_DESC desc;
if (pTexture->GetLevelDesc(0, &desc) != D3D_OK) //get the format and the size of the texture
{
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetLevelDesc \n");
return RETURN_GetLevelDesc_FAILED;
}
Message("uMod_IDirect3DCubeTexture9::GetHash() (%d %d) %d\n", desc.Width, desc.Height, desc.Format);
/*
if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture
{
//Message("uMod_IDirect3DCubeTexture9::GetHash() (D3DPOOL_DEFAULT)\n");
IDirect3DSurface9 *pSurfaceLevel_orig = NULL;
if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK)
{
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE)
{
//Message("uMod_IDirect3DCubeTexture9::GetHash() MultiSampleType\n");
if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig = pResolvedSurface;
}
if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n");
return RETURN_TEXTURE_NOT_LOADED);
}
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig->Release();
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
}
else
*/
if (pTexture->LockRect(D3DCUBEMAP_FACE_POSITIVE_X, 0, &d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) {
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 1\n");
if (pTexture->GetCubeMapSurface(D3DCUBEMAP_FACE_POSITIVE_X, 0, &pResolvedSurface) != D3D_OK) {
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel\n");
return RETURN_LockRect_FAILED;
}
if (pResolvedSurface->LockRect(&d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) {
pResolvedSurface->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 2\n");
return RETURN_LockRect_FAILED;
}
}
const int size = (GetBitsFromFormat(desc.Format) * desc.Width * desc.Height) / 8;
hash = GetCRC32(static_cast<char*>(d3dlr.pBits), size); //calculate the crc32 of the texture
/*
if (pOffscreenSurface!=NULL)
{
pOffscreenSurface->UnlockRect();
pOffscreenSurface->Release();
//pOffscreenTexture->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
}
else
*/
if (pResolvedSurface != nullptr) {
pResolvedSurface->UnlockRect();
pResolvedSurface->Release();
}
else {
pTexture->UnlockRect(D3DCUBEMAP_FACE_POSITIVE_X, 0); //unlock the raw data
}
Message("uMod_IDirect3DCubeTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
return RETURN_OK;
}
File diff suppressed because it is too large Load Diff
+95
View File
@@ -0,0 +1,95 @@
#include "uMod_Main.h"
#define uMod_IDirect3DDevice9 uMod_IDirect3DDevice9Ex
#define IDirect3DDevice9 IDirect3DDevice9Ex
#define m_pIDirect3DDevice9 m_pIDirect3DDevice9Ex
#define RETURN_QueryInterface 0x01000001L
#define PRE_MESSAGE "uMod_IDirect3DDevice9Ex"
// ReSharper disable once CppUnusedIncludeDirective
#include "uMod_IDirect3DDevice9.cpp"
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CheckDeviceState(HWND hWindow)
{
return m_pIDirect3DDevice9Ex->CheckDeviceState(hWindow);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CheckResourceResidency(IDirect3DResource9** ppResourceArray, UINT32 NumResources)
{
return m_pIDirect3DDevice9Ex->CheckResourceResidency(ppResourceArray, NumResources);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::ComposeRects(IDirect3DSurface9* pSource, IDirect3DSurface9* pDestination, IDirect3DVertexBuffer9* pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9* pDstRectDescriptors, D3DCOMPOSERECTSOP Operation,
INT XOffset, INT YOffset)
{
return m_pIDirect3DDevice9Ex->ComposeRects(pSource, pDestination, pSrcRectDescriptors, NumRects, pDstRectDescriptors, Operation, XOffset, YOffset);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateDepthStencilSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage)
{
return m_pIDirect3DDevice9Ex->CreateDepthStencilSurfaceEx(Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle, Usage);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateOffscreenPlainSurfaceEx(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage)
{
return m_pIDirect3DDevice9Ex->CreateOffscreenPlainSurfaceEx(Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateRenderTargetEx(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage)
{
return m_pIDirect3DDevice9Ex->CreateRenderTargetEx(Width, Height, Format, MultiSample, MultisampleQuality, Lockable, ppSurface, pSharedHandle, Usage);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetDisplayModeEx(UINT iSwapChain, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation)
{
return m_pIDirect3DDevice9Ex->GetDisplayModeEx(iSwapChain, pMode, pRotation);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetGPUThreadPriority(INT* pPriority)
{
return m_pIDirect3DDevice9Ex->GetGPUThreadPriority(pPriority);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetMaximumFrameLatency(UINT* pMaxLatency)
{
return m_pIDirect3DDevice9Ex->GetMaximumFrameLatency(pMaxLatency);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::PresentEx(const RECT* pSourceRect, const RECT* pDestRect, HWND hDestWindowOverride, const RGNDATA* pDirtyRegion, DWORD dwFlags)
{
return m_pIDirect3DDevice9Ex->PresentEx(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::ResetEx(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode)
{
return m_pIDirect3DDevice9Ex->ResetEx(pPresentationParameters, pFullscreenDisplayMode);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetConvolutionMonoKernel(UINT Width, UINT Height, float* RowWeights, float* ColumnWeights)
{
return m_pIDirect3DDevice9Ex->SetConvolutionMonoKernel(Width, Height, RowWeights, ColumnWeights);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetGPUThreadPriority(INT pPriority)
{
return m_pIDirect3DDevice9Ex->SetGPUThreadPriority(pPriority);
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetMaximumFrameLatency(UINT pMaxLatency)
{
return m_pIDirect3DDevice9Ex->SetMaximumFrameLatency(pMaxLatency);
}
/*
HRESULT __stdcall uMod_IDirect3DDevice9Ex::TestCooperativeLevel()
{
return(m_pIDirect3DDevice9Ex->TestCooperativeLevel();
}
*/
HRESULT __stdcall uMod_IDirect3DDevice9Ex::WaitForVBlank(UINT SwapChainIndex)
{
return m_pIDirect3DDevice9Ex->WaitForVBlank(SwapChainIndex);
}
+354
View File
@@ -0,0 +1,354 @@
#include "uMod_Main.h"
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::QueryInterface(REFIID riid, void** ppvObj)
{
if (riid == IID_IDirect3D9) {
// This function should never be called with IID_IDirect3D9 by the game
// thus this call comes from our own dll to ask for the texture type
// 0x01000000L == uMod_IDirect3DTexture9
// 0x01000001L == uMod_IDirect3DVolumeTexture9
// 0x01000002L == uMod_IDirect3DCubeTexture9
*ppvObj = this;
return 0x01000000L;
}
HRESULT hRes;
if (CrossRef_D3Dtex != nullptr) {
hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj == CrossRef_D3Dtex->m_D3Dtex) {
*ppvObj = this;
}
}
else {
hRes = m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj == m_D3Dtex) {
*ppvObj = this;
}
}
return hRes;
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DTexture9::AddRef()
{
if (FAKE) {
return 1; //bug, this case should never happen
}
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->AddRef();
}
return m_D3Dtex->AddRef();
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DTexture9::Release()
{
Message("uMod_IDirect3DTexture9::Release(): %lu\n", this);
void* cpy;
const long ret = m_D3Ddev->QueryInterface(IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE) {
UnswitchTextures(this);
count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures
}
else {
if (CrossRef_D3Dtex != nullptr) //if this texture is switched with a fake texture
{
uMod_IDirect3DTexture9* fake_texture = CrossRef_D3Dtex;
count = fake_texture->m_D3Dtex->Release(); //release the original texture
if (count == 0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (ret == 0x01000000L) {
if (static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetSingleTexture() != fake_texture) {
fake_texture->Release(); // we release the fake texture
}
}
else {
if (static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetSingleTexture() != fake_texture) {
fake_texture->Release(); // we release the fake texture
}
}
}
}
else {
count = m_D3Dtex->Release();
}
}
if (count == 0) //if this texture is released, we clean up
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (ret == 0x01000000L) {
if (static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetLastCreatedTexture() == this) {
static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->SetLastCreatedTexture(nullptr);
}
else {
static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
}
else {
if (static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetLastCreatedTexture() == this) {
static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->SetLastCreatedTexture(nullptr);
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
}
delete(this);
}
Message("uMod_IDirect3DTexture9::Release() end: %lu\n", this);
return count;
}
HRESULT APIENTRY uMod_IDirect3DTexture9::GetDevice(IDirect3DDevice9** ppDevice)
{
*ppDevice = m_D3Ddev;
return D3D_OK;
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::SetPrivateData(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
return m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData);
}
return m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::FreePrivateData(REFGUID refguid)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid);
}
return m_D3Dtex->FreePrivateData(refguid);
}
DWORD APIENTRY uMod_IDirect3DTexture9::SetPriority(DWORD PriorityNew)
{
return m_D3Dtex->SetPriority(PriorityNew);
}
DWORD APIENTRY uMod_IDirect3DTexture9::GetPriority()
{
return m_D3Dtex->GetPriority();
}
void APIENTRY uMod_IDirect3DTexture9::PreLoad()
{
m_D3Dtex->PreLoad();
}
D3DRESOURCETYPE APIENTRY uMod_IDirect3DTexture9::GetType()
{
return m_D3Dtex->GetType();
}
DWORD APIENTRY uMod_IDirect3DTexture9::SetLOD(DWORD LODNew)
{
return m_D3Dtex->SetLOD(LODNew);
}
DWORD APIENTRY uMod_IDirect3DTexture9::GetLOD()
{
return m_D3Dtex->GetLOD();
}
DWORD APIENTRY uMod_IDirect3DTexture9::GetLevelCount()
{
return m_D3Dtex->GetLevelCount();
}
HRESULT APIENTRY uMod_IDirect3DTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType)
{
return m_D3Dtex->SetAutoGenFilterType(FilterType);
}
D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DTexture9::GetAutoGenFilterType()
{
return m_D3Dtex->GetAutoGenFilterType();
}
void APIENTRY uMod_IDirect3DTexture9::GenerateMipSubLevels()
{
m_D3Dtex->GenerateMipSubLevels();
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::GetLevelDesc(UINT Level, D3DSURFACE_DESC* pDesc)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc);
}
return m_D3Dtex->GetLevelDesc(Level, pDesc);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::GetSurfaceLevel(UINT Level, IDirect3DSurface9** ppSurfaceLevel)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetSurfaceLevel(Level, ppSurfaceLevel);
}
return m_D3Dtex->GetSurfaceLevel(Level, ppSurfaceLevel);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::LockRect(UINT Level, D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect, DWORD Flags)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->LockRect(Level, pLockedRect, pRect, Flags);
}
return m_D3Dtex->LockRect(Level, pLockedRect, pRect, Flags);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::UnlockRect(UINT Level)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->UnlockRect(Level);
}
return m_D3Dtex->UnlockRect(Level);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::AddDirtyRect(CONST RECT* pDirtyRect)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->AddDirtyRect(pDirtyRect);
}
return m_D3Dtex->AddDirtyRect(pDirtyRect);
}
int uMod_IDirect3DTexture9::GetHash(MyTypeHash& hash)
{
hash = 0u;
if (FAKE) {
return RETURN_BAD_ARGUMENT;
}
IDirect3DTexture9* pTexture = m_D3Dtex;
if (CrossRef_D3Dtex != nullptr) {
pTexture = CrossRef_D3Dtex->m_D3Dtex;
}
IDirect3DSurface9* pOffscreenSurface = nullptr;
//IDirect3DTexture9 *pOffscreenTexture = NULL;
IDirect3DSurface9* pResolvedSurface = nullptr;
D3DLOCKED_RECT d3dlr;
D3DSURFACE_DESC desc;
if (pTexture->GetLevelDesc(0, &desc) != D3D_OK) //get the format and the size of the texture
{
Message("uMod_IDirect3DTexture9::GetHash() Failed: GetLevelDesc \n");
return RETURN_GetLevelDesc_FAILED;
}
Message("uMod_IDirect3DTexture9::GetHash() (%d %d) %d\n", desc.Width, desc.Height, desc.Format);
if (desc.Pool == D3DPOOL_DEFAULT) //get the raw data of the texture
{
//Message("uMod_IDirect3DTexture9::GetHash() (D3DPOOL_DEFAULT)\n");
IDirect3DSurface9* pSurfaceLevel_orig = nullptr;
if (pTexture->GetSurfaceLevel(0, &pSurfaceLevel_orig) != D3D_OK) {
Message("uMod_IDirect3DTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED;
}
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) {
//Message("uMod_IDirect3DTexture9::GetHash() MultiSampleType\n");
if (D3D_OK != m_D3Ddev->CreateRenderTarget(desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, nullptr)) {
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED;
}
if (D3D_OK != m_D3Ddev->StretchRect(pSurfaceLevel_orig, nullptr, pResolvedSurface, nullptr, D3DTEXF_NONE)) {
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED;
}
pSurfaceLevel_orig = pResolvedSurface;
}
if (D3D_OK != m_D3Ddev->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, nullptr)) {
pSurfaceLevel_orig->Release();
if (pResolvedSurface != nullptr) {
pResolvedSurface->Release();
}
Message("uMod_IDirect3DTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n");
return RETURN_TEXTURE_NOT_LOADED;
}
if (D3D_OK != m_D3Ddev->GetRenderTargetData(pSurfaceLevel_orig, pOffscreenSurface)) {
pSurfaceLevel_orig->Release();
if (pResolvedSurface != nullptr) {
pResolvedSurface->Release();
}
pOffscreenSurface->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED;
}
pSurfaceLevel_orig->Release();
if (pOffscreenSurface->LockRect(&d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) {
if (pResolvedSurface != nullptr) {
pResolvedSurface->Release();
}
pOffscreenSurface->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED;
}
}
else if (pTexture->LockRect(0, &d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) {
Message("uMod_IDirect3DTexture9::GetHash() Failed: LockRect 1\n");
if (pTexture->GetSurfaceLevel(0, &pResolvedSurface) != D3D_OK) {
Message("uMod_IDirect3DTexture9::GetHash() Failed: GetSurfaceLevel\n");
return RETURN_LockRect_FAILED;
}
if (pResolvedSurface->LockRect(&d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) {
pResolvedSurface->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: LockRect 2\n");
return RETURN_LockRect_FAILED;
}
}
const int size = (GetBitsFromFormat(desc.Format) * desc.Width * desc.Height) / 8;
hash = GetCRC32(static_cast<char*>(d3dlr.pBits), size); //calculate the crc32 of the texture
if (pOffscreenSurface != nullptr) {
pOffscreenSurface->UnlockRect();
pOffscreenSurface->Release();
if (pResolvedSurface != nullptr) {
pResolvedSurface->Release();
}
}
else if (pResolvedSurface != nullptr) {
pResolvedSurface->UnlockRect();
pResolvedSurface->Release();
}
else {
pTexture->UnlockRect(0);
}
Message("uMod_IDirect3DTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
return RETURN_OK;
}
+386
View File
@@ -0,0 +1,386 @@
#include "uMod_Main.h"
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::QueryInterface(REFIID riid, void** ppvObj)
{
if (riid == IID_IDirect3D9) {
// This function should never be called with IID_IDirect3D9 by the game
// thus this call comes from our own dll to ask for the texture type
// 0x01000000L == uMod_IDirect3DTexture9
// 0x01000001L == uMod_IDirect3DVolumeTexture9
// 0x01000002L == uMod_IDirect3DCubeTexture9
*ppvObj = this;
return 0x01000001L;
}
HRESULT hRes;
if (CrossRef_D3Dtex != nullptr) {
hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj == CrossRef_D3Dtex->m_D3Dtex) {
*ppvObj = this;
}
}
else {
hRes = m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj == m_D3Dtex) {
*ppvObj = this;
}
}
return hRes;
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DVolumeTexture9::AddRef()
{
if (FAKE) {
return 1; //bug, this case should never happen
}
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->AddRef();
}
return m_D3Dtex->AddRef();
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DVolumeTexture9::Release()
{
Message("uMod_IDirect3DVolumeTexture9::Release(): %lu\n", this);
void* cpy;
const long ret = m_D3Ddev->QueryInterface(IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE) {
UnswitchTextures(this);
count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures
}
else {
if (CrossRef_D3Dtex != nullptr) //if this texture is switched with a fake texture
{
uMod_IDirect3DVolumeTexture9* fake_texture = CrossRef_D3Dtex;
count = fake_texture->m_D3Dtex->Release(); //release the original texture
if (count == 0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (ret == 0x01000000L) {
if (static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetSingleVolumeTexture() != fake_texture) {
fake_texture->Release(); // we release the fake texture
}
}
else {
if (static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetSingleVolumeTexture() != fake_texture) {
fake_texture->Release(); // we release the fake texture
}
}
}
}
else {
count = m_D3Dtex->Release();
}
}
if (count == 0) //if this texture is released, we clean up
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (ret == 0x01000000L) {
if (static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetLastCreatedVolumeTexture() == this) {
static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->SetLastCreatedVolumeTexture(nullptr);
}
else {
static_cast<uMod_IDirect3DDevice9*>(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
}
else {
if (static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetLastCreatedVolumeTexture() == this) {
static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->SetLastCreatedVolumeTexture(nullptr);
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
}
delete(this);
}
return count;
}
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetDevice(IDirect3DDevice9** ppDevice)
{
*ppDevice = m_D3Ddev;
return D3D_OK;
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::SetPrivateData(REFGUID refguid,CONST void* pData, DWORD SizeOfData, DWORD Flags)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
return m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData);
}
return m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::FreePrivateData(REFGUID refguid)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid);
}
return m_D3Dtex->FreePrivateData(refguid);
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::SetPriority(DWORD PriorityNew)
{
return m_D3Dtex->SetPriority(PriorityNew);
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetPriority()
{
return m_D3Dtex->GetPriority();
}
void APIENTRY uMod_IDirect3DVolumeTexture9::PreLoad()
{
m_D3Dtex->PreLoad();
}
D3DRESOURCETYPE APIENTRY uMod_IDirect3DVolumeTexture9::GetType()
{
return m_D3Dtex->GetType();
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::SetLOD(DWORD LODNew)
{
return m_D3Dtex->SetLOD(LODNew);
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetLOD()
{
return m_D3Dtex->GetLOD();
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetLevelCount()
{
return m_D3Dtex->GetLevelCount();
}
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType)
{
return m_D3Dtex->SetAutoGenFilterType(FilterType);
}
D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DVolumeTexture9::GetAutoGenFilterType()
{
return m_D3Dtex->GetAutoGenFilterType();
}
void APIENTRY uMod_IDirect3DVolumeTexture9::GenerateMipSubLevels()
{
m_D3Dtex->GenerateMipSubLevels();
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::AddDirtyBox(CONST D3DBOX* pDirtyBox)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->AddDirtyBox(pDirtyBox);
}
return m_D3Dtex->AddDirtyBox(pDirtyBox);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetLevelDesc(UINT Level, D3DVOLUME_DESC* pDesc)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc);
}
return m_D3Dtex->GetLevelDesc(Level, pDesc);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetVolumeLevel(UINT Level, IDirect3DVolume9** ppVolumeLevel)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->GetVolumeLevel(Level, ppVolumeLevel);
}
return m_D3Dtex->GetVolumeLevel(Level, ppVolumeLevel);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::LockBox(UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->LockBox(Level, pLockedVolume, pBox, Flags);
}
return m_D3Dtex->LockBox(Level, pLockedVolume, pBox, Flags);
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::UnlockBox(UINT Level)
{
if (CrossRef_D3Dtex != nullptr) {
return CrossRef_D3Dtex->m_D3Dtex->UnlockBox(Level);
}
return m_D3Dtex->UnlockBox(Level);
}
int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash& hash)
{
hash = 0u;
if (FAKE) {
return RETURN_BAD_ARGUMENT;
}
IDirect3DVolumeTexture9* pTexture = m_D3Dtex;
if (CrossRef_D3Dtex != nullptr) {
pTexture = CrossRef_D3Dtex->m_D3Dtex;
}
//IDirect3DVolume9 *pOffscreenSurface = NULL;
//IDirect3DVolumeTexture9 *pOffscreenTexture = NULL;
IDirect3DVolume9* pResolvedSurface = nullptr;
D3DLOCKED_BOX d3dlr;
D3DVOLUME_DESC desc;
if (pTexture->GetLevelDesc(0, &desc) != D3D_OK) //get the format and the size of the texture
{
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetLevelDesc \n");
return RETURN_GetLevelDesc_FAILED;
}
Message("uMod_IDirect3DVolumeTexture9::GetHash() (%d %d %d) %d\n", desc.Width, desc.Height, desc.Depth, desc.Format);
/*
if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture
{
//Message("uMod_IDirect3DVolumeTexture9::GetHash() (D3DPOOL_DEFAULT)\n");
IDirect3DSurface9 *pSurfaceLevel_orig = NULL;
if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK)
{
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
/*
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE)
{
//Message("uMod_IDirect3DVolumeTexture9::GetHash() MultiSampleType\n");
if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig = pResolvedSurface;
}
*/
//CreateTexture(8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DVolumeTexture9**) &SingleTexture, NULL)
/*
if (D3D_OK!=m_D3Ddev->CreateTexture( desc.Width, desc.Height, 1, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenTexture, NULL))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateTexture (D3DPOOL_DEFAULT)\n");
return RETURN_TEXTURE_NOT_LOADED);
}
if (pOffscreenTexture->GetSurfaceLevel( 0, &pOffscreenSurface)!=D3D_OK)
{
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel 2 (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
pOffscreenTexture->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig->Release();
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
pOffscreenTexture->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
*/
/*
if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n");
return RETURN_TEXTURE_NOT_LOADED);
}
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig->Release();
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
return RETURN_LockRect_FAILED);
}
}
else
*/
if (pTexture->LockBox(0, &d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) {
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect 1\n");
if (pTexture->GetVolumeLevel(0, &pResolvedSurface) != D3D_OK) {
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel\n");
return RETURN_LockRect_FAILED;
}
if (pResolvedSurface->LockBox(&d3dlr, nullptr, D3DLOCK_READONLY) != D3D_OK) {
pResolvedSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect 2\n");
return RETURN_LockRect_FAILED;
}
}
const int size = (GetBitsFromFormat(desc.Format) * desc.Width * desc.Height * desc.Depth) / 8;
hash = GetCRC32(static_cast<char*>(d3dlr.pBits), size); //calculate the crc32 of the texture
if (pResolvedSurface != nullptr) {
pResolvedSurface->UnlockBox();
pResolvedSurface->Release();
}
else {
pTexture->UnlockBox(0);
}
Message("uMod_IDirect3DVolumeTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
return RETURN_OK;
}
+995
View File
@@ -0,0 +1,995 @@
#include "uMod_Main.h"
uMod_TextureClient::uMod_TextureClient(uMod_TextureServer* server, IDirect3DDevice9* device)
{
Message("uMod_TextureClient::uMod_TextureClient(): %lu\n", this);
Server = server;
D3D9Device = device;
BoolSaveAllTextures = false;
BoolSaveSingleTexture = false;
KeyBack = 0;
KeySave = 0;
KeyNext = 0;
SavePath[0] = 0;
GameName[0] = 0;
NumberToMod = 0;
FileToMod = nullptr;
if (Server != nullptr) {
if (Server->AddClient(this, &FileToMod, &NumberToMod)) {
Server = nullptr;
NumberToMod = 0;
FileToMod = nullptr;
}
else {
for (int i = 0; i < NumberToMod; i++) {
FileToMod[i].NumberOfTextures = 0;
FileToMod[i].Textures = nullptr;
}
}
}
Mutex = CreateMutex(nullptr, false, nullptr);
Update = nullptr;
NumberOfUpdate = -1;
FontColour = D3DCOLOR_ARGB(255, 255, 0, 0);
TextureColour = D3DCOLOR_ARGB(255, 0, 255, 0);
}
uMod_TextureClient::~uMod_TextureClient()
{
Message("uMod_TextureClient::~uMod_TextureClient(): %lu\n", this);
if (Server != nullptr) {
Server->RemoveClient(this);
}
if (Mutex != nullptr) {
CloseHandle(Mutex);
}
delete [] Update;
if (FileToMod != nullptr) {
for (int i = 0; i < NumberToMod; i++) {
delete [] FileToMod[i].Textures;
}
delete [] FileToMod;
}
}
int uMod_TextureClient::AddTexture(uMod_IDirect3DTexture9* pTexture)
{
void* cpy;
const long ret = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) {
static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->SetLastCreatedTexture(nullptr); //this texture must no be added twice
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->SetLastCreatedTexture(nullptr); //this texture must no be added twice
}
if (pTexture->FAKE) {
return RETURN_OK; // this is a fake texture
}
Message("uMod_TextureClient::AddTexture( %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
MyTypeHash hash;
if (const int ret = pTexture->GetHash(hash)) {
return ret;
}
pTexture->Hash = hash;
if (BoolSaveAllTextures) {
SaveTexture(pTexture);
}
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
OriginalTextures.Add(pTexture); // add the texture to the list of original texture
return LookUpToMod(pTexture); // check if this texture should be modded
}
int uMod_TextureClient::AddTexture(uMod_IDirect3DVolumeTexture9* pTexture)
{
void* cpy;
const long ret = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) {
static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->SetLastCreatedVolumeTexture(nullptr); //this texture must no be added twice
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->SetLastCreatedVolumeTexture(nullptr); //this texture must no be added twice
}
if (pTexture->FAKE) {
return RETURN_OK; // this is a fake texture
}
Message("uMod_TextureClient::AddTexture( Volume: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
MyTypeHash hash;
if (const int ret = pTexture->GetHash(hash)) {
return ret;
}
pTexture->Hash = hash;
if (BoolSaveAllTextures) {
SaveTexture(pTexture);
}
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
OriginalVolumeTextures.Add(pTexture); // add the texture to the list of original texture
return LookUpToMod(pTexture); // check if this texture should be modded
}
int uMod_TextureClient::AddTexture(uMod_IDirect3DCubeTexture9* pTexture)
{
void* cpy;
const long ret = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) {
static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->SetLastCreatedCubeTexture(nullptr); //this texture must no be added twice
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->SetLastCreatedCubeTexture(nullptr); //this texture must no be added twice
}
if (pTexture->FAKE) {
return RETURN_OK; // this is a fake texture
}
Message("uMod_TextureClient::AddTexture( Cube: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
MyTypeHash hash;
if (const int ret = pTexture->GetHash(hash)) {
return ret;
}
pTexture->Hash = hash;
if (BoolSaveAllTextures) {
SaveTexture(pTexture);
}
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
OriginalCubeTextures.Add(pTexture); // add the texture to the list of original texture
return LookUpToMod(pTexture); // check if this texture should be modded
}
int uMod_TextureClient::RemoveTexture(uMod_IDirect3DTexture9* pTexture) // is called from a texture, if it is finally released
{
Message("uMod_TextureClient::RemoveTexture( %lu, %#lX): %lu\n", pTexture, pTexture->Hash, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
if (pTexture->FAKE) {
// we need to set the corresponding FileToMod[X].pTexture to NULL, to avoid a link to a non existing texture object
const int ref = pTexture->Reference;
if (ref >= 0 && ref < NumberToMod) {
for (int i = 0; i < FileToMod[ref].NumberOfTextures; i++) {
if (FileToMod[ref].Textures[i] == pTexture) {
FileToMod[ref].NumberOfTextures--;
for (int j = i; j < FileToMod[ref].NumberOfTextures; j++) {
FileToMod[ref].Textures[j] = FileToMod[ref].Textures[j + 1];
}
FileToMod[ref].Textures[FileToMod[ref].NumberOfTextures] = nullptr;
break;
}
}
}
}
else {
return OriginalTextures.Remove(pTexture); //remove this texture form the list
}
return RETURN_OK;
}
int uMod_TextureClient::RemoveTexture(uMod_IDirect3DVolumeTexture9* pTexture) // is called from a texture, if it is finally released
{
Message("uMod_TextureClient::RemoveTexture( Volume %lu, %#lX): %lu\n", pTexture, pTexture->Hash, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
if (pTexture->FAKE) {
// we need to set the corresponding FileToMod[X].pTexture to NULL, to avoid a link to a non existing texture object
const int ref = pTexture->Reference;
if (ref >= 0 && ref < NumberToMod) {
for (int i = 0; i < FileToMod[ref].NumberOfTextures; i++) {
if (FileToMod[ref].Textures[i] == pTexture) {
FileToMod[ref].NumberOfTextures--;
for (int j = i; j < FileToMod[ref].NumberOfTextures; j++) {
FileToMod[ref].Textures[j] = FileToMod[ref].Textures[j + 1];
}
FileToMod[ref].Textures[FileToMod[ref].NumberOfTextures] = nullptr;
break;
}
}
}
}
else {
return OriginalVolumeTextures.Remove(pTexture); //remove this texture form the list
}
return RETURN_OK;
}
int uMod_TextureClient::RemoveTexture(uMod_IDirect3DCubeTexture9* pTexture) // is called from a texture, if it is finally released
{
Message("uMod_TextureClient::RemoveTexture( Cube %lu, %#lX): %lu\n", pTexture, pTexture->Hash, this);
if (gl_ErrorState & uMod_ERROR_FATAL) {
return RETURN_FATAL_ERROR;
}
if (pTexture->FAKE) {
// we need to set the corresponding FileToMod[X].pTexture to NULL, to avoid a link to a non existing texture object
const int ref = pTexture->Reference;
if (ref >= 0 && ref < NumberToMod) {
for (int i = 0; i < FileToMod[ref].NumberOfTextures; i++) {
if (FileToMod[ref].Textures[i] == pTexture) {
FileToMod[ref].NumberOfTextures--;
for (int j = i; j < FileToMod[ref].NumberOfTextures; j++) {
FileToMod[ref].Textures[j] = FileToMod[ref].Textures[j + 1];
}
FileToMod[ref].Textures[FileToMod[ref].NumberOfTextures] = nullptr;
break;
}
}
}
}
else {
return OriginalCubeTextures.Remove(pTexture); //remove this texture form the list
}
return RETURN_OK;
}
int uMod_TextureClient::SaveAllTextures(bool val)
{
Message("uMod_TextureClient::SaveAllTextures( %d): %lu\n", val, this);
BoolSaveAllTextures = val;
return RETURN_OK;
}
int uMod_TextureClient::SaveSingleTexture(bool val)
{
Message("uMod_TextureClient::SaveSingleTexture( %d): %lu\n", val, this);
if (BoolSaveSingleTexture && !val) //if BoolSaveSingleTexture is set to false and was previously true we switch the SingleTexture back
{
uMod_IDirect3DTexture9* pTexture;
void* cpy;
const long ret = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) {
pTexture = static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->GetSingleTexture(); //this texture must no be added twice
}
else {
pTexture = static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->GetSingleTexture(); //this texture must no be added twice
}
if (pTexture != nullptr) {
UnswitchTextures(pTexture);
}
}
BoolSaveSingleTexture = val;
return RETURN_OK;
}
int uMod_TextureClient::SetSaveDirectory(wchar_t* dir)
{
Message("uMod_TextureClient::SetSaveDirectory( %ls): %lu\n", dir, this);
int i = 0;
for (i = 0; i < MAX_PATH && (dir[i]); i++) {
SavePath[i] = dir[i];
}
if (i == MAX_PATH) {
SavePath[0] = 0;
return RETURN_BAD_ARGUMENT;
}
SavePath[i] = 0;
return RETURN_OK;
}
int uMod_TextureClient::SetGameName(wchar_t* name)
{
Message("uMod_TextureClient::SetGameName( %ls): %lu\n", name, this);
int i = 0;
for (i = 0; i < MAX_PATH && (name[i]); i++) {
GameName[i] = name[i];
}
if (i == MAX_PATH) {
GameName[0] = 0;
return RETURN_BAD_ARGUMENT;
}
GameName[i] = 0;
return RETURN_OK;
}
int uMod_TextureClient::SaveTexture(uMod_IDirect3DTexture9* pTexture)
{
if (pTexture == nullptr) {
return RETURN_BAD_ARGUMENT;
}
if (SavePath[0] == 0) {
Message("uMod_TextureClient::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this);
return RETURN_TEXTURE_NOT_SAVED;
}
wchar_t file[MAX_PATH];
if (GameName[0]) {
swprintf_s(file, MAX_PATH, L"%ls\\%ls_T_%#lX.dds", SavePath, GameName, pTexture->Hash);
}
else {
swprintf_s(file, MAX_PATH, L"%ls\\T_%#lX.dds", SavePath, pTexture->Hash);
}
Message("uMod_TextureClient::SaveTexture( %ls): %lu\n", file, this);
if (D3D_OK != D3DXSaveTextureToFileW(file, D3DXIFF_DDS, pTexture->m_D3Dtex, nullptr)) {
return RETURN_TEXTURE_NOT_SAVED;
}
return RETURN_OK;
}
int uMod_TextureClient::SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture)
{
if (pTexture == nullptr) {
return RETURN_BAD_ARGUMENT;
}
if (SavePath[0] == 0) {
Message("uMod_TextureClient::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this);
return RETURN_TEXTURE_NOT_SAVED;
}
wchar_t file[MAX_PATH];
if (GameName[0]) {
swprintf_s(file, MAX_PATH, L"%ls\\%ls_V_%#lX.dds", SavePath, GameName, pTexture->Hash);
}
else {
swprintf_s(file, MAX_PATH, L"%ls\\V_%#lX.dds", SavePath, pTexture->Hash);
}
Message("uMod_TextureClient::SaveTexture( %ls): %lu\n", file, this);
if (D3D_OK != D3DXSaveTextureToFileW(file, D3DXIFF_DDS, pTexture->m_D3Dtex, nullptr)) {
return RETURN_TEXTURE_NOT_SAVED;
}
return RETURN_OK;
}
int uMod_TextureClient::SaveTexture(uMod_IDirect3DCubeTexture9* pTexture)
{
if (pTexture == nullptr) {
return RETURN_BAD_ARGUMENT;
}
if (SavePath[0] == 0) {
Message("uMod_TextureClient::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this);
return RETURN_TEXTURE_NOT_SAVED;
}
wchar_t file[MAX_PATH];
if (GameName[0]) {
swprintf_s(file, MAX_PATH, L"%ls\\%ls_C_%#lX.dds", SavePath, GameName, pTexture->Hash);
}
else {
swprintf_s(file, MAX_PATH, L"%ls\\C_%#lX.dds", SavePath, pTexture->Hash);
}
Message("uMod_TextureClient::SaveTexture( %ls): %lu\n", file, this);
if (D3D_OK != D3DXSaveTextureToFileW(file, D3DXIFF_DDS, pTexture->m_D3Dtex, nullptr)) {
return RETURN_TEXTURE_NOT_SAVED;
}
return RETURN_OK;
}
int uMod_TextureClient::AddUpdate(TextureFileStruct* update, int number) //client must delete the update array
{
Message("AddUpdate( %lu, %d): %lu\n", update, number, this);
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_TEXTURE;
return ret;
}
delete [] Update;
Update = update;
NumberOfUpdate = number;
return UnlockMutex();
}
int uMod_TextureClient::MergeUpdate()
{
if (NumberOfUpdate < 0) { return RETURN_OK; }
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_TEXTURE;
return ret;
}
Message("MergeUpdate(): %lu\n", this);
for (int i = 0; i < NumberOfUpdate; i++) {
Update[i].NumberOfTextures = 0;
Update[i].Textures = nullptr;
} // this is already done, but safety comes first ^^
int pos_old = 0;
int pos_new = 0;
int* to_lookup = nullptr;
if (NumberOfUpdate > 0) {
to_lookup = new int[NumberOfUpdate];
}
int num_to_lookup = 0;
/*
* FileToMod contains the old files (textures) which should replace the target textures (if they are loaded by the game)
* Update contains the new files (textures) which should replace the target textures (if they are loaded by the game)
*
* Both arrays (FileToMod and Update) are sorted according to their hash values.
*
* First we go through both arrays linearly and
* 1) take over the old entry if the hash is the same,
* 2) release old fake texture (if target texture exist and is not in the Update)
* 3) or mark newly added fake texture (if they are not in FileToMod)
*/
while (pos_old < NumberToMod && pos_new < NumberOfUpdate) {
if (FileToMod[pos_old].Hash > Update[pos_new].Hash) // this fake texture is new
{
to_lookup[num_to_lookup++] = pos_new++; // keep this fake texture in mind, we must search later for it through all original textures
// we increase only the new counter by one
}
else if (FileToMod[pos_old].Hash < Update[pos_new].Hash) // this fake texture is not in the update
{
for (int i = FileToMod[pos_old].NumberOfTextures - 1; i >= 0; i--) {
FileToMod[pos_old].Textures[i]->Release(); // we release the fake textures
}
delete [] FileToMod[pos_old].Textures; // we delete the memory
FileToMod[pos_old].NumberOfTextures = 0;
FileToMod[pos_old].Textures = nullptr;
pos_old++; // we increase only the old counter by one
}
else // the hash value is the same, thus this texture is in the array FileToMod as well as in the array Update
{
if (Update[pos_new].ForceReload) {
if (FileToMod[pos_old].NumberOfTextures > 0) {
Update[pos_new].Textures = new IDirect3DBaseTexture9*[FileToMod[pos_old].NumberOfTextures];
}
for (int i = 0; i < FileToMod[pos_old].NumberOfTextures; i++) {
IDirect3DBaseTexture9* base_texture;
int ret = FileToMod[pos_old].Textures[i]->QueryInterface(IID_IDirect3D9, (void**)&base_texture);
switch (ret) {
case 0x01000000L: {
auto pTexture = static_cast<uMod_IDirect3DTexture9*>(FileToMod[pos_old].Textures[i]);//
uMod_IDirect3DTexture9* pRefTexture = pTexture->CrossRef_D3Dtex;
pTexture->Release();
i--; //after the Release of the old fake texture FileToMod[pos_old].Textures[i] is overwritten by entries with index greater than i
uMod_IDirect3DTexture9* fake_Texture;
if (int ret = LoadTexture(&(Update[pos_new]), &fake_Texture)) {
return ret;
}
if (SwitchTextures(fake_Texture, pRefTexture)) {
Message("MergeUpdate(): textures not switched %#lX\n", pRefTexture->Hash);
fake_Texture->Release();
}
else {
Update[pos_new].Textures[Update[pos_new].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = pos_new;
}
break;
}
case 0x01000001L: {
auto pTexture = static_cast<uMod_IDirect3DVolumeTexture9*>(FileToMod[pos_old].Textures[i]);//
uMod_IDirect3DVolumeTexture9* pRefTexture = pTexture->CrossRef_D3Dtex;
pTexture->Release();
i--; //after the Release of the old fake texture FileToMod[pos_old].Textures[i] is overwritten by entries with index greater than i
uMod_IDirect3DVolumeTexture9* fake_Texture;
if (int ret = LoadTexture(&(Update[pos_new]), &fake_Texture)) {
return ret;
}
if (SwitchTextures(fake_Texture, pRefTexture)) {
Message("MergeUpdate(): textures not switched %#lX\n", pRefTexture->Hash);
fake_Texture->Release();
}
else {
Update[pos_new].Textures[Update[pos_new].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = pos_new;
}
break;
}
case 0x01000002L: {
auto pTexture = static_cast<uMod_IDirect3DCubeTexture9*>(FileToMod[pos_old].Textures[i]);//
uMod_IDirect3DCubeTexture9* pRefTexture = pTexture->CrossRef_D3Dtex;
pTexture->Release();
i--; //after the Release of the old fake texture FileToMod[pos_old].Textures[i] is overwritten by entries with index greater than i
uMod_IDirect3DCubeTexture9* fake_Texture;
if (int ret = LoadTexture(&Update[pos_new], &fake_Texture)) {
return ret;
}
if (SwitchTextures(fake_Texture, pRefTexture)) {
Message("MergeUpdate(): textures not switched %#lX\n", pRefTexture->Hash);
fake_Texture->Release();
}
else {
Update[pos_new].Textures[Update[pos_new].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = pos_new;
}
break;
}
default:
break; // this is no fake texture and QueryInterface failed, because IDirect3DBaseTexture9 object cannot be a IDirect3D9 object ;)
}
}
}
else // the texture might be loaded or not
{
Update[pos_new].NumberOfTextures = FileToMod[pos_old].NumberOfTextures;
Update[pos_new].Textures = FileToMod[pos_old].Textures;
FileToMod[pos_old].NumberOfTextures = 0;
FileToMod[pos_old].Textures = nullptr;
}
// we increase both counters by one
pos_old++;
pos_new++;
}
}
while (pos_old < NumberToMod) //this fake textures are not in the Update
{
for (int i = FileToMod[pos_old].NumberOfTextures - 1; i >= 0; i--) {
FileToMod[pos_old].Textures[i]->Release(); // we release the fake textures
}
//for (int i=0; i<FileToMod[pos_old].NumberOfTextures; i++) FileToMod[pos_old].Textures[i]->Release(); // we release the fake textures
delete [] FileToMod[pos_old].Textures; // we delete the memory
FileToMod[pos_old].Textures = nullptr;
pos_old++;
}
while (pos_new < NumberOfUpdate) //this fake textures are newly added
{
to_lookup[num_to_lookup++] = pos_new++; //keep this fake texture in mind, we must search later for it through all original textures
}
/*
* if (num_to_lookup>0) we need to look through all original textures
* because there were newly added textures and we don't know
* if the corresponding target textures are loaded by the game or not.
*
* Note: to_lookup[num_to_lookup++] = pos_new++; is in ascending order,
* thus Update[to_lookup[pos]].Hash is also sorted ascending!
*/
/*
uMod_IDirect3DTexture9 *single_texture = ((uMod_IDirect3DDevice9*)D3D9Device)->GetSingleTexture();
if (num_to_lookup>0)
{
int num = OriginalTextures.GetNumber();
for (int i=0; i<num; i++)
if (OriginalTextures[i]->CrossRef_D3Dtex==NULL || OriginalTextures[i]->CrossRef_D3Dtex==single_texture)
// We need look only for textures, that are not switched or switched with the single_texture.
// The single_texture is a special texture, which you can toggle through all original texture, if save single texture is turned on.
{
MyTypeHash hash = OriginalTextures[i]->Hash;
if (hash<Update[to_lookup[0]].Hash || hash>Update[to_lookup[num_to_lookup-1]].Hash) continue;
int index = -1;
int pos = num_to_lookup/2;
int begin = 0;
int end = num_to_lookup-1;
// We look in the middle of the interval and each step we halve the interval,
// unless we find the texture or the size of the interval is less than 3.
// Note: contradicting to normal C-code here the interval includes the index "begin" and "end"!
while (begin+1<end) // as long as the interval is longer than two
{
if (hash > Update[to_lookup[pos]].Hash) // the new interval is the right half of the actual interval
{
begin = pos+1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new intervall
}
else if (hash < Update[to_lookup[pos]].Hash) // the new interval is the left half of the actual interval
{
end = pos-1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new intervall
}
else {index = to_lookup[pos]; break;} // we hit the correct hash
}
if (index<0) // if we did not find the hash, it might be in the last interval
{
for (int i=begin; i<=end; i++) if (Update[to_lookup[i]].Hash==hash) index = to_lookup[i];
}
if (index>=0) // target texture is loaded by the game
{
if (OriginalTextures[i]->CrossRef_D3Dtex!=NULL) UnswitchTextures(OriginalTextures[i]); // this texture was switched with the single texture
uMod_IDirect3DTexture9 *fake_Texture;
if (int ret = LoadTexture( & (Update[index]), &fake_Texture)) return ret;
if (SwitchTextures( fake_Texture, OriginalTextures[i]))
{
Message("uMod_TextureClient::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
fake_Texture->Release();
}
else
{
IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[Update[index].NumberOfTextures+1];
for (int j=0; j<Update[index].NumberOfTextures; j++) temp[j] = Update[index].Textures[j];
if (Update[index].Textures!=NULL) delete [] Update[index].Textures;
Update[index].Textures = temp;
Update[index].Textures[Update[index].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = index;
}
}
}
}
*/
//for (int i=0; i<NumberToMod; i++) if (FileToMod[i].Textures!=NULL) delete [] FileToMod[i].Textures;
delete [] FileToMod;
FileToMod = Update;
NumberToMod = NumberOfUpdate;
NumberOfUpdate = -1;
Update = nullptr;
if (num_to_lookup > 0) {
uMod_IDirect3DTexture9* single_texture;
void* cpy;
const long ret = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) {
single_texture = static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->GetSingleTexture(); //this texture must no be added twice
}
else {
single_texture = static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->GetSingleTexture(); //this texture must no be added twice
}
int num = OriginalTextures.GetNumber();
for (int i = 0; i < num; i++) {
if (OriginalTextures[i]->CrossRef_D3Dtex == nullptr || OriginalTextures[i]->CrossRef_D3Dtex == single_texture) {
UnswitchTextures(OriginalTextures[i]); //this we can do always, so we unswitch the single texture
LookUpToMod(OriginalTextures[i], num_to_lookup, to_lookup);
}
}
uMod_IDirect3DVolumeTexture9* single_volume_texture;
if (ret == 0x01000000L) {
single_volume_texture = static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->GetSingleVolumeTexture(); //this texture must no be added twice
}
else {
single_volume_texture = static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->GetSingleVolumeTexture(); //this texture must no be added twice
}
num = OriginalVolumeTextures.GetNumber();
for (int i = 0; i < num; i++) {
if (OriginalVolumeTextures[i]->CrossRef_D3Dtex == nullptr || OriginalVolumeTextures[i]->CrossRef_D3Dtex == single_volume_texture) {
UnswitchTextures(OriginalVolumeTextures[i]); //this we can do always, so we unswitch the single texture
LookUpToMod(OriginalVolumeTextures[i], num_to_lookup, to_lookup);
}
}
uMod_IDirect3DCubeTexture9* single_cube_texture;
if (ret == 0x01000000L) {
single_cube_texture = static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->GetSingleCubeTexture(); //this texture must no be added twice
}
else {
single_cube_texture = static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->GetSingleCubeTexture(); //this texture must no be added twice
}
num = OriginalCubeTextures.GetNumber();
for (int i = 0; i < num; i++) {
if (OriginalCubeTextures[i]->CrossRef_D3Dtex == nullptr || OriginalCubeTextures[i]->CrossRef_D3Dtex == single_cube_texture) {
UnswitchTextures(OriginalCubeTextures[i]); //this we can do always, so we unswitch the single texture
LookUpToMod(OriginalCubeTextures[i], num_to_lookup, to_lookup);
}
}
}
delete [] to_lookup;
return UnlockMutex();
}
int uMod_TextureClient::LockMutex()
{
if ((gl_ErrorState & (uMod_ERROR_FATAL | uMod_ERROR_MUTEX))) {
return RETURN_NO_MUTEX;
}
if (WAIT_OBJECT_0 != WaitForSingleObject(Mutex, 100)) {
return RETURN_MUTEX_LOCK; //waiting 100ms, to wait infinite pass INFINITE
}
return RETURN_OK;
}
int uMod_TextureClient::UnlockMutex()
{
if (ReleaseMutex(Mutex) == 0) {
return RETURN_MUTEX_UNLOCK;
}
return RETURN_OK;
}
int uMod_TextureClient::LookUpToMod(MyTypeHash hash, int num_index_list, int* index_list)
{
if (NumberToMod > 0) {
if (index_list == nullptr || num_index_list == 0) {
if (hash < FileToMod[0].Hash || hash > FileToMod[NumberToMod - 1].Hash) {
return -1;
}
int pos = NumberToMod / 2;
int begin = 0;
int end = NumberToMod - 1;
// We look in the middle of the interval and each step we halve the interval,
// unless we find the texture or the size of the interval is less than 3.
// Note: contradicting to normal C-code here the interval includes the index "begin" and "end"!
while (begin + 1 < end) // as long as the interval is longer than two
{
if (hash > FileToMod[pos].Hash) // the new interval is the right half of the actual interval
{
begin = pos + 1; // the new interval does not contain the index "pos"
pos = (begin + end) / 2; // set "pos" somewhere inside the new interval
}
else if (hash < FileToMod[pos].Hash) // the new interval is the left half of the actual interval
{
end = pos - 1; // the new interval does not contain the index "pos"
pos = (begin + end) / 2; // set "pos" somewhere inside the new interval
}
else {
return pos;
break;
} // we hit the correct hash
}
for (pos = begin; pos <= end; pos++) {
if (FileToMod[pos].Hash == hash) {
return pos;
}
}
}
else {
if (hash < FileToMod[index_list[0]].Hash || hash > FileToMod[index_list[num_index_list - 1]].Hash) {
return -1;
}
int pos = num_index_list / 2;
int begin = 0;
int end = num_index_list - 1;
// We look in the middle of the interval and each step we halve the interval,
// unless we find the texture or the size of the interval is less than 3.
// Note: contradicting to normal C-code here the interval includes the index "begin" and "end"!
while (begin + 1 < end) // as long as the interval is longer than two
{
if (hash > FileToMod[index_list[pos]].Hash) // the new interval is the right half of the actual interval
{
begin = pos + 1; // the new interval does not contain the index "pos"
pos = (begin + end) / 2; // set "pos" somewhere inside the new interval
}
else if (hash < FileToMod[index_list[pos]].Hash) // the new interval is the left half of the actual interval
{
end = pos - 1; // the new interval does not contain the index "pos"
pos = (begin + end) / 2; // set "pos" somewhere inside the new interval
}
else {
return index_list[pos];
break;
} // we hit the correct hash
}
for (pos = begin; pos <= end; pos++) {
if (FileToMod[index_list[pos]].Hash == hash) {
return index_list[pos];
}
}
}
}
return -1;
}
int uMod_TextureClient::LookUpToMod(uMod_IDirect3DTexture9* pTexture, int num_index_list, int* index_list) // should only be called for original textures
{
Message("uMod_TextureClient::LookUpToMod( %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
if (pTexture->CrossRef_D3Dtex != nullptr) {
return RETURN_OK; // bug, this texture is already switched
}
const int index = LookUpToMod(pTexture->Hash, num_index_list, index_list);
if (index >= 0) {
uMod_IDirect3DTexture9* fake_Texture;
if (const int ret = LoadTexture(&(FileToMod[index]), &fake_Texture)) {
return ret;
}
if (SwitchTextures(fake_Texture, pTexture)) {
Message("uMod_TextureClient::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
fake_Texture->Release();
}
else {
const auto temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures + 1];
for (int j = 0; j < FileToMod[index].NumberOfTextures; j++) {
temp[j] = FileToMod[index].Textures[j];
}
delete [] FileToMod[index].Textures;
FileToMod[index].Textures = temp;
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = index;
}
}
return RETURN_OK;
}
int uMod_TextureClient::LookUpToMod(uMod_IDirect3DVolumeTexture9* pTexture, int num_index_list, int* index_list) // should only be called for original textures
{
Message("uMod_TextureClient::LookUpToMod( Volume %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
if (pTexture->CrossRef_D3Dtex != nullptr) {
return RETURN_OK; // bug, this texture is already switched
}
const int index = LookUpToMod(pTexture->Hash, num_index_list, index_list);
if (index >= 0) {
uMod_IDirect3DVolumeTexture9* fake_Texture;
if (const int ret = LoadTexture(&(FileToMod[index]), &fake_Texture)) {
return ret;
}
if (SwitchTextures(fake_Texture, pTexture)) {
Message("uMod_TextureClient::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
fake_Texture->Release();
}
else {
const auto temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures + 1];
for (int j = 0; j < FileToMod[index].NumberOfTextures; j++) {
temp[j] = FileToMod[index].Textures[j];
}
delete [] FileToMod[index].Textures;
FileToMod[index].Textures = temp;
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = index;
}
}
return RETURN_OK;
}
int uMod_TextureClient::LookUpToMod(uMod_IDirect3DCubeTexture9* pTexture, int num_index_list, int* index_list) // should only be called for original textures
{
Message("uMod_TextureClient::LookUpToMod( Cube %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
if (pTexture->CrossRef_D3Dtex != nullptr) {
return RETURN_OK; // bug, this texture is already switched
}
const int index = LookUpToMod(pTexture->Hash, num_index_list, index_list);
if (index >= 0) {
uMod_IDirect3DCubeTexture9* fake_Texture;
if (const int ret = LoadTexture(&(FileToMod[index]), &fake_Texture)) {
return ret;
}
if (SwitchTextures(fake_Texture, pTexture)) {
Message("uMod_TextureClient::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
fake_Texture->Release();
}
else {
const auto temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures + 1];
for (int j = 0; j < FileToMod[index].NumberOfTextures; j++) {
temp[j] = FileToMod[index].Textures[j];
}
delete [] FileToMod[index].Textures;
FileToMod[index].Textures = temp;
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = index;
}
}
return RETURN_OK;
}
int uMod_TextureClient::LoadTexture(TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9** ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateTextureFromFileInMemoryEx(D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, nullptr, nullptr,
(IDirect3DTexture9**)ppTexture))
//if (D3D_OK != D3DXCreateTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DTexture9 **) ppTexture))
{
*ppTexture = nullptr;
return RETURN_TEXTURE_NOT_LOADED;
}
(*ppTexture)->FAKE = true;
void* cpy;
const long ret = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) {
static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->SetLastCreatedTexture(nullptr); //this texture must no be added twice
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->SetLastCreatedTexture(nullptr); //this texture must no be added twice
}
Message("LoadTexture( %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return RETURN_OK;
}
int uMod_TextureClient::LoadTexture(TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9** ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( Volume %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemoryEx(D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, nullptr,
nullptr,
(IDirect3DVolumeTexture9**)ppTexture))
//if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DVolumeTexture9 **) ppTexture))
{
*ppTexture = nullptr;
return RETURN_TEXTURE_NOT_LOADED;
}
(*ppTexture)->FAKE = true;
void* cpy;
const long ret = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) {
static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->SetLastCreatedVolumeTexture(nullptr); //this texture must no be added twice
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->SetLastCreatedVolumeTexture(nullptr); //this texture must no be added twice
}
Message("LoadTexture( Volume %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return RETURN_OK;
}
int uMod_TextureClient::LoadTexture(TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9** ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( Cube %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateCubeTextureFromFileInMemoryEx(D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, nullptr, nullptr,
(IDirect3DCubeTexture9**)ppTexture))
//if (D3D_OK != D3DXCreateCubeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DCubeTexture9 **) ppTexture))
{
*ppTexture = nullptr;
return RETURN_TEXTURE_NOT_LOADED;
}
(*ppTexture)->FAKE = true;
void* cpy;
const long ret = D3D9Device->QueryInterface(IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) {
static_cast<uMod_IDirect3DDevice9*>(D3D9Device)->SetLastCreatedCubeTexture(nullptr); //this texture must no be added twice
}
else {
static_cast<uMod_IDirect3DDevice9Ex*>(D3D9Device)->SetLastCreatedCubeTexture(nullptr); //this texture must no be added twice
}
Message("LoadTexture( Cube %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return RETURN_OK;
}
+40
View File
@@ -0,0 +1,40 @@
#include "uMod_Main.h"
/*
MyTypeHash GetHash(unsigned char *str, int len) // estimate the hash
{
MyTypeHash hash = 0;
for (int i=0; i<len; i++) hash = str[i] + (hash << 6) + (hash << 16) - hash;
return hash);
}
*/
/*
*
* BIG THANKS TO RS !!
*
* who gave me his hashing algorithm (well or crc32 algorithm^^)
*
The hash function is CRC32 using polynomial 0xEDB88320.
However, the hashed data is calculated incorrectly in TexMod: it's simply BytesPerPixel * Width * Height, from the beginning of the data (that is mapped using LockRect).
The problem is that it doesn't take the pitch into account and BytesPerPixel may be wrong for some rare formats (not sure about that).
*/
#define CRC32POLY 0xEDB88320u /* CRC-32 Polynom */
#define ulCrc_in 0xffffffff
unsigned int GetCRC32(char* pcDatabuf, unsigned int ulDatalen)
{
unsigned int crc = ulCrc_in;
for (unsigned int idx = 0u; idx < ulDatalen; idx++) {
unsigned int data = *pcDatabuf++;
for (unsigned int bit = 0u; bit < 8u; bit++, data >>= 1) {
crc = crc >> 1 ^ ((crc ^ data) & 1 ? CRC32POLY : 0);
}
}
return crc;
}
+680
View File
@@ -0,0 +1,680 @@
#include "uMod_Main.h"
#include "uMod_File.h"
uMod_TextureServer::uMod_TextureServer(char* game, char* uModName)
{
Message("uMod_TextureServer(): %lu\n", this);
Mutex = CreateMutex(nullptr, false, nullptr);
Clients = nullptr;
NumberOfClients = 0;
LenghtOfClients = 0;
BoolSaveAllTextures = false;
BoolSaveSingleTexture = false;
SavePath[0] = 0;
int len = 0;
int path_pos = 0;
int dot_pos = 0;
for (len = 0; len < MAX_PATH && (game[len]); len++) {
if (game[len] == '\\' || game[len] == '/') {
path_pos = len + 1;
}
else if (game[len] == '.') {
dot_pos = len;
}
}
if (dot_pos > path_pos) {
len = dot_pos - path_pos;
}
else {
len -= path_pos;
}
for (int i = 0; i < len; i++) {
GameName[i] = game[i + path_pos];
}
if (len < MAX_PATH) {
GameName[len] = 0;
}
else {
GameName[0] = 0;
}
for (len = 0; len < MAX_PATH; len++) {
UModName[len] = uModName[len];
}
KeyBack = 0;
KeySave = 0;
KeyNext = 0;
FontColour = 0u;
TextureColour = 0u;
Pipe.In = INVALID_HANDLE_VALUE;
Pipe.Out = INVALID_HANDLE_VALUE;
}
uMod_TextureServer::~uMod_TextureServer()
{
Message("~uMod_TextureServer(): %lu\n", this);
if (Mutex != nullptr) {
CloseHandle(Mutex);
}
//delete the files in memory
int num = CurrentMod.GetNumber();
for (int i = 0; i < num; i++) {
delete[] CurrentMod[i]->pData; //delete the file content of the texture
}
num = OldMod.GetNumber();
for (int i = 0; i < num; i++) {
delete[] OldMod[i]->pData; //delete the file content of the texture
}
if (Pipe.In != INVALID_HANDLE_VALUE) {
CloseHandle(Pipe.In);
}
Pipe.In = INVALID_HANDLE_VALUE;
if (Pipe.Out != INVALID_HANDLE_VALUE) {
CloseHandle(Pipe.Out);
}
Pipe.Out = INVALID_HANDLE_VALUE;
}
int uMod_TextureServer::AddClient(uMod_TextureClient* client, TextureFileStruct** update, int* number) // called from a client
{
Message("AddClient(%lu): %lu\n", client, this);
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
// the following functions must not change the original uMod_IDirect3DDevice9 object
// somehow on game start some uMod_IDirect3DDevice9 object are created, which must rest unchanged!!
// these objects are released and are not used for rendering
client->SetGameName(GameName);
client->SaveAllTextures(BoolSaveAllTextures);
client->SaveSingleTexture(BoolSaveSingleTexture);
client->SetSaveDirectory(SavePath);
if (KeyBack > 0) {
client->SetKeyBack(KeyBack);
}
if (KeySave > 0) {
client->SetKeySave(KeySave);
}
if (KeyNext > 0) {
client->SetKeyNext(KeyNext);
}
if (FontColour > 0u) {
const DWORD r = FontColour >> 16 & 0xFF;
const DWORD g = FontColour >> 8 & 0xFF;
const DWORD b = FontColour & 0xFF;
client->SetFontColour(r, g, b);
}
if (TextureColour > 0u) {
const DWORD r = TextureColour >> 16 & 0xFF;
const DWORD g = TextureColour >> 8 & 0xFF;
const DWORD b = TextureColour & 0xFF;
client->SetTextureColour(r, g, b);
}
if (const int ret = PrepareUpdate(update, number)) {
return ret; // get a copy of all texture to be modded
}
if (NumberOfClients == LenghtOfClients) //allocate more memory
{
uMod_TextureClient** temp = nullptr;
try { temp = new uMod_TextureClient*[LenghtOfClients + 10]; }
catch (...) {
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER;
if (const int ret = UnlockMutex()) {
return ret;
}
return RETURN_NO_MEMORY;
}
for (int i = 0; i < LenghtOfClients; i++) {
temp[i] = Clients[i];
}
delete[] Clients;
Clients = temp;
LenghtOfClients += 10;
}
Clients[NumberOfClients++] = client;
return UnlockMutex();
}
int uMod_TextureServer::RemoveClient(uMod_TextureClient* client) // called from a client
{
Message("RemoveClient(): %lu\n", client);
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
for (int i = 0; i < NumberOfClients; i++) {
if (client == Clients[i]) {
NumberOfClients--;
Clients[i] = Clients[NumberOfClients];
break;
}
}
return UnlockMutex();
}
int uMod_TextureServer::AddFile(char* buffer, unsigned int size, MyTypeHash hash, bool force) // called from Mainloop()
{
Message("uMod_TextureServer::AddFile( %lu %lu, %#lX, %d): %lu\n", buffer, size, hash, force, this);
TextureFileStruct* temp = nullptr;
int num = CurrentMod.GetNumber();
for (int i = 0; i < num; i++) {
if (CurrentMod[i]->Hash == hash) //look through all current textures
{
if (force) {
temp = CurrentMod[i];
break;
} // we need to reload it
return RETURN_OK; // we still have added this texture
}
}
if (temp == nullptr) // if not found, look through all old textures
{
num = OldMod.GetNumber();
for (int i = 0; i < num; i++) {
if (OldMod[i]->Hash == hash) {
temp = OldMod[i];
OldMod.Remove(temp);
CurrentMod.Add(temp);
if (force) {
break; // we must reload it
}
return RETURN_OK; // we should not reload it
}
}
}
bool new_file = true;
if (temp != nullptr) //if it was found, we delete the old file content
{
new_file = false;
delete[] temp->pData;
temp->pData = nullptr;
}
else //if it was not found, we need to create a new object
{
new_file = true;
temp = new TextureFileStruct;
temp->Reference = -1;
}
try {
temp->pData = new char[size];
}
catch (...) {
if (!new_file) {
CurrentMod.Remove(temp); // if this is a not a new file it is in the list of the CurrentMod
}
delete temp;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER;
return RETURN_NO_MEMORY;
}
for (unsigned int i = 0; i < size; i++) {
temp->pData[i] = buffer[i];
}
temp->Size = size;
temp->NumberOfTextures = 0;
temp->Textures = nullptr;
temp->Hash = hash;
//if (new_file) temp->ForceReload = false; // no need to force a load of the texture
//else
temp->ForceReload = force;
Message("End AddFile(%#lX)\n", hash);
if (new_file) {
return CurrentMod.Add(temp); // new files must be added to the list of the CurrentMod
}
return RETURN_OK;
}
int uMod_TextureServer::AddFile(wchar_t* file_name, MyTypeHash hash, bool force) // called from Mainloop
// this functions does the same, but loads the file content from disk
{
Message("uMod_TextureServer::AddFile( %ls, %#lX, %d): %lu\n", file_name, hash, force, this);
TextureFileStruct* temp = nullptr;
int num = CurrentMod.GetNumber();
for (int i = 0; i < num; i++) {
if (CurrentMod[i]->Hash == hash) {
if (force) {
temp = CurrentMod[i];
break;
}
return RETURN_OK;
}
}
if (temp == nullptr) {
num = OldMod.GetNumber();
for (int i = 0; i < num; i++) {
if (OldMod[i]->Hash == hash) {
temp = OldMod[i];
OldMod.Remove(temp);
CurrentMod.Add(temp);
if (force) {
break;
}
return RETURN_OK;
}
}
}
FILE* file;
if (_wfopen_s(&file, file_name, L"rb") != 0) {
Message("AddFile( ): file not found\n");
return RETURN_FILE_NOT_LOADED;
}
fseek(file, 0, SEEK_END);
const unsigned int size = ftell(file);
fseek(file, 0, SEEK_SET);
bool new_file = true;
if (temp != nullptr) {
new_file = false;
delete[] temp->pData;
temp->pData = nullptr;
}
else {
new_file = true;
temp = new TextureFileStruct;
temp->Reference = -1;
}
try {
temp->pData = new char[size];
}
catch (...) {
if (!new_file) {
CurrentMod.Remove(temp);
}
delete temp;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER;
return RETURN_NO_MEMORY;
}
const int result = fread(temp->pData, 1, size, file);
fclose(file);
if (result != size) {
delete[] temp->pData;
if (!new_file) {
CurrentMod.Remove(temp);
}
delete temp;
return RETURN_FILE_NOT_LOADED;
}
temp->Size = size;
temp->NumberOfTextures = 0;
temp->Textures = nullptr;
temp->Hash = hash;
if (new_file) {
temp->ForceReload = false;
}
else {
temp->ForceReload = force;
}
Message("End AddFile(%#lX)\n", hash);
if (new_file) {
return CurrentMod.Add(temp);
}
return RETURN_OK;
}
int uMod_TextureServer::RemoveFile(MyTypeHash hash) // called from Mainloop()
{
Message("RemoveFile( %lu): %lu\n", hash, this);
const int num = CurrentMod.GetNumber();
for (int i = 0; i < num; i++) {
if (CurrentMod[i]->Hash == hash) {
TextureFileStruct* temp = CurrentMod[i];
CurrentMod.Remove(temp);
return OldMod.Add(temp);
}
}
return RETURN_OK;
}
int uMod_TextureServer::SaveAllTextures(bool val) // called from Mainloop()
{
if (BoolSaveAllTextures == val) {
return RETURN_OK;
}
BoolSaveAllTextures = val;
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
for (int i = 0; i < NumberOfClients; i++) {
Clients[i]->SaveAllTextures(BoolSaveAllTextures);
}
return UnlockMutex();
}
int uMod_TextureServer::SaveSingleTexture(bool val) // called from Mainloop()
{
if (BoolSaveSingleTexture == val) {
return RETURN_OK;
}
BoolSaveSingleTexture = val;
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
for (int i = 0; i < NumberOfClients; i++) {
Clients[i]->SaveSingleTexture(BoolSaveSingleTexture);
}
return UnlockMutex();
}
int uMod_TextureServer::SetSaveDirectory(wchar_t* dir) // called from Mainloop()
{
Message("uMod_TextureServer::SetSaveDirectory( %ls): %lu\n", dir, this);
int i = 0;
for (i = 0; i < MAX_PATH && dir[i]; i++) {
SavePath[i] = dir[i];
}
if (i == MAX_PATH) {
SavePath[0] = 0;
return RETURN_BAD_ARGUMENT;
}
SavePath[i] = 0;
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
for (int i = 0; i < NumberOfClients; i++) {
Clients[i]->SetSaveDirectory(SavePath);
}
return UnlockMutex();
}
int uMod_TextureServer::SetKeyBack(int key) // called from Mainloop()
{
if (KeyBack == key || KeySave == key || KeyNext == key) {
return RETURN_OK;
}
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
KeyBack = key;
for (int i = 0; i < NumberOfClients; i++) {
Clients[i]->SetKeyBack(key);
}
return UnlockMutex();
}
int uMod_TextureServer::SetKeySave(int key) // called from Mainloop()
{
if (KeyBack == key || KeySave == key || KeyNext == key) {
return RETURN_OK;
}
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
KeySave = key;
for (int i = 0; i < NumberOfClients; i++) {
Clients[i]->SetKeySave(key);
}
return UnlockMutex();
}
int uMod_TextureServer::SetKeyNext(int key) // called from Mainloop()
{
if (KeyBack == key || KeySave == key || KeyNext == key) {
return RETURN_OK;
}
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
KeyNext = key;
for (int i = 0; i < NumberOfClients; i++) {
Clients[i]->SetKeyNext(key);
}
return UnlockMutex();
}
int uMod_TextureServer::SetFontColour(DWORD colour) // called from Mainloop()
{
if (colour == 0u) {
return RETURN_OK;
}
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
FontColour = colour;
const DWORD r = (FontColour >> 16) & 0xFF;
const DWORD g = (FontColour >> 8) & 0xFF;
const DWORD b = (FontColour) & 0xFF;
Message("uMod_TextureServer::SetFontColour( %u %u %u): %lu\n", r, g, b, this);
for (int i = 0; i < NumberOfClients; i++) {
Clients[i]->SetFontColour(r, g, b);
}
return UnlockMutex();
}
int uMod_TextureServer::SetTextureColour(DWORD colour) // called from Mainloop()
{
if (colour == 0u) {
return RETURN_OK;
}
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_SERVER;
return ret;
}
TextureColour = colour;
const DWORD r = (TextureColour >> 16) & 0xFF;
const DWORD g = (TextureColour >> 8) & 0xFF;
const DWORD b = (TextureColour) & 0xFF;
Message("uMod_TextureServer::SetTextureColour( %u %u %u): %lu\n", r, g, b, this);
for (int i = 0; i < NumberOfClients; i++) {
Clients[i]->SetTextureColour(r, g, b);
}
return UnlockMutex();
}
int uMod_TextureServer::PropagateUpdate(uMod_TextureClient* client) // called from Mainloop(), send the update to all clients
{
Message("PropagateUpdate(%lu): %lu\n", client, this);
if (const int ret = LockMutex()) {
gl_ErrorState |= uMod_ERROR_TEXTURE;
return ret;
}
if (client != nullptr) {
TextureFileStruct* update;
int number;
if (const int ret = PrepareUpdate(&update, &number)) {
return ret;
}
client->AddUpdate(update, number);
}
else {
for (int i = 0; i < NumberOfClients; i++) {
TextureFileStruct* update;
int number;
if (const int ret = PrepareUpdate(&update, &number)) {
return ret;
}
Clients[i]->AddUpdate(update, number);
}
}
return UnlockMutex();
}
#define cpy_file_struct( a, b) \
{ \
a.ForceReload = b.ForceReload; \
a.pData = b.pData; \
a.Size = b.Size; \
a.NumberOfTextures = b.NumberOfTextures; \
a.Reference = b.Reference; \
a.Textures = b.Textures; \
a.Hash = b.Hash; }
int TextureFileStruct_Compare(const void* elem1, const void* elem2)
{
const auto tex1 = (TextureFileStruct*)elem1;
const auto tex2 = (TextureFileStruct*)elem2;
if (tex1->Hash < tex2->Hash) {
return -1;
}
if (tex1->Hash > tex2->Hash) {
return +1;
}
return 0;
}
int uMod_TextureServer::PrepareUpdate(TextureFileStruct** update, int* number) // called from the PropagateUpdate() and AddClient.
// Prepare an update for one client. The allocated memory must deleted by the client.
{
Message("PrepareUpdate(%lu, %d): %lu\n", update, number, this);
TextureFileStruct* temp = nullptr;
const int num = CurrentMod.GetNumber();
if (num > 0) {
try { temp = new TextureFileStruct[num]; }
catch (...) {
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER;
return RETURN_NO_MEMORY;
}
for (int i = 0; i < num; i++) cpy_file_struct(temp[i], (*(CurrentMod[i])));
qsort(temp, num, sizeof(TextureFileStruct), TextureFileStruct_Compare);
}
*update = temp;
*number = num;
return RETURN_OK;
}
#undef cpy_file_struct
int uMod_TextureServer::LockMutex()
{
if ((gl_ErrorState & (uMod_ERROR_FATAL | uMod_ERROR_MUTEX))) {
return RETURN_NO_MUTEX;
}
if (WAIT_OBJECT_0 != WaitForSingleObject(Mutex, 100)) {
return RETURN_MUTEX_LOCK; //waiting 100ms, to wait infinite pass INFINITE
}
return RETURN_OK;
}
int uMod_TextureServer::UnlockMutex()
{
if (ReleaseMutex(Mutex) == 0) {
return RETURN_MUTEX_UNLOCK;
}
return RETURN_OK;
}
void uMod_TextureServer::LoadModsFromFile(char* source)
{
Message("MainLoop: searching in %s\n", source);
// Attempt to open the file
FILE* file = fopen(source, "r");
if (file) {
Message("MainLoop: found modlist.txt. Reading\n");
// Read each line from the file
char line[MAX_PATH];
while (fgets(line, sizeof(line), file) != nullptr) {
Message("MainLoop: loading file %s\n", line);
for (auto i = 0; i < MAX_PATH; i++) {
if (line[i] == '\n') {
line[i] = 0;
}
}
const auto file = new uMod_File(line);
const auto result = file->GetContent();
if (file->Textures.size() > 0) {
if (!result) {
Message("MainLoop: WARNING! GetContent returned failure, but some textures have been loaded for %s\n", line);
}
Message("MainLoop: Texture count %d %s\n", file->Textures.size(), line);
for (auto& texture : file->Textures) {
AddFile(texture.data.data(), texture.data.size(), texture.hash, true);
}
PropagateUpdate(nullptr);
}
else {
Message("MainLoop: Failed to load any textures for %s\n", line);
}
}
}
}
int uMod_TextureServer::MainLoop() // run as a separated thread
{
Message("MainLoop: searching for modlist.txt\n");
char gwpath[MAX_PATH];
GetModuleFileName(GetModuleHandle(nullptr), gwpath, MAX_PATH); //ask for name and path of this executable
char* last_backslash = strrchr(gwpath, '\\');
if (last_backslash != nullptr) {
// Terminate the string at the last backslash to remove the executable name
*last_backslash = '\0';
}
strcat(gwpath, "\\modlist.txt");
LoadModsFromFile(gwpath);
char umodpath[MAX_PATH];
strcpy(umodpath, UModName);
last_backslash = strrchr(umodpath, '\\');
if (last_backslash != nullptr) {
// Terminate the string at the last backslash to remove the executable name
*last_backslash = '\0';
}
strcat(umodpath, "\\modlist.txt");
LoadModsFromFile(umodpath);
Message("MainLoop: begin\n");
for (auto i = 0; i < 10; i++) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return RETURN_OK;
}
File diff suppressed because it is too large Load Diff
+3152
View File
File diff suppressed because it is too large Load Diff
-117
View File
@@ -1,117 +0,0 @@
ifdef NI
ifdef LOG_MESSAGE
precompiler_flag = /D "LOG_MESSAGE" /D "NO_INJECTION"
else
precompiler_flag = /D "NO_INJECTION"
endif
def_file = /DEF:"uMod_DX9_dll_NO_INJECTION.def"
obj_suff = NI.obj
dll = d3d9.dll
else
ifdef DI
ifdef LOG_MESSAGE
precompiler_flag = /D "LOG_MESSAGE" /D "DIRECT_INJECTION"
else
precompiler_flag = /D "DIRECT_INJECTION"
endif
def_file = /DEF:"uMod_DX9_dll_DIRECT_INJECTION.def"
obj_suff = DI.obj
dll = uMod_d3d9_DI.dll
else
ifdef LOG_MESSAGE
precompiler_flag = /D "LOG_MESSAGE" /D "HOOK_INJECTION"
else
precompiler_flag = /D "HOOK_INJECTION"
endif
def_file = /DEF:"uMod_DX9_dll_HOOK_INJECTION.def"
obj_suff = HI.obj
dll = uMod_d3d9_HI.dll
endif
endif
CXX = cl
CLINK = link.exe
DEFINES = /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS"
CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 ${DEFINES} ${precompiler_flag} /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t
LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" /DLL "Winmm.lib" "d3dx9.lib" "dxguid.lib" "user32.lib" "Kernel32.lib" ${def_file} /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE:NO /NXCOMPAT:NO /MACHINE:X86
obj = obj
bin = bin
objects = ${obj}\uMod_DX9_dll.${obj_suff} \
${obj}\uMod_IDirect3D9.${obj_suff} \
${obj}\uMod_IDirect3D9Ex.${obj_suff} \
${obj}\uMod_IDirect3DDevice9.${obj_suff} \
${obj}\uMod_IDirect3DDevice9Ex.${obj_suff} \
${obj}\uMod_TextureFunction.${obj_suff} \
${obj}\uMod_IDirect3DTexture9.${obj_suff} \
${obj}\uMod_IDirect3DVolumeTexture9.${obj_suff} \
${obj}\uMod_IDirect3DCubeTexture9.${obj_suff} \
${obj}\uMod_ArrayHandler.${obj_suff} \
${obj}\uMod_TextureClient.${obj_suff} \
${obj}\uMod_TextureServer.${obj_suff}
headers = uMod_Main.h \
uMod_Defines.h \
uMod_DX9_dll.h \
uMod_IDirect3D9.h \
uMod_IDirect3DDevice9.h \
uMod_TextureFunction.h \
uMod_IDirect3DTexture9.h \
uMod_IDirect3DVolumeTexture9.h \
uMod_IDirect3DCubeTexture9.h \
uMod_ArrayHandler.h \
uMod_TextureClient.h \
uMod_TextureServer.h
${bin}\d3d9.dll: ${objects}
${CLINK} ${LFLAGS} ${objects} /OUT:${bin}\${dll}
copy ${bin}\${dll} ..\uMod_GUI\bin\${dll}
${obj}\uMod_DX9_dll.${obj_suff}: uMod_DX9_dll.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_IDirect3D9.${obj_suff}: uMod_IDirect3D9.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_IDirect3D9Ex.${obj_suff}: uMod_IDirect3D9Ex.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_IDirect3DDevice9.${obj_suff}: uMod_IDirect3DDevice9.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_IDirect3DDevice9Ex.${obj_suff}: uMod_IDirect3DDevice9Ex.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_TextureFunction.${obj_suff}: uMod_TextureFunction.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_IDirect3DTexture9.${obj_suff}: uMod_IDirect3DTexture9.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_IDirect3DVolumeTexture9.${obj_suff}: uMod_IDirect3DVolumeTexture9.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_IDirect3DCubeTexture9.${obj_suff}: uMod_IDirect3DCubeTexture9.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_ArrayHandler.${obj_suff}: uMod_ArrayHandler.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_TextureClient.${obj_suff}: uMod_TextureClient.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_TextureServer.${obj_suff}: uMod_TextureServer.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
clean:
del ${objects} ${bin}\${dll}
-117
View File
@@ -1,117 +0,0 @@
!IFDEF NI
!IFDEF LOG_MESSAGE
precompiler_flag = /D "LOG_MESSAGE" /D "NO_INJECTION"
!ELSE
precompiler_flag = /D "NO_INJECTION"
!ENDIF
def_file = /DEF:"uMod_DX9_dll_NO_INJECTION.def"
obj_suff = NI.obj
dll = d3d9.dll
!ELSE
!IFDEF DI
!IFDEF LOG_MESSAGE
precompiler_flag = /D "LOG_MESSAGE" /D "DIRECT_INJECTION"
!ELSE
precompiler_flag = /D "DIRECT_INJECTION"
!ENDIF
def_file = /DEF:"uMod_DX9_dll_DIRECT_INJECTION.def"
obj_suff = DI.obj
dll = uMod_d3d9_DI.dll
!ELSE
!IFDEF LOG_MESSAGE
precompiler_flag = /D "LOG_MESSAGE" /D "HOOK_INJECTION"
!ELSE
precompiler_flag = /D "HOOK_INJECTION"
!ENDIF
def_file = /DEF:"uMod_DX9_dll_HOOK_INJECTION.def"
obj_suff = HI.obj
dll = uMod_d3d9_HI.dll
!ENDIF
CXX = cl
CLINK = link.exe
DEFINES = /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS"
CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 $(DEFINES) $(precompiler_flag) /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t
LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" /DLL "Winmm.lib" "d3dx9.lib" "dxguid.lib" "user32.lib" "Kernel32.lib" $(def_file) /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE:NO /NXCOMPAT:NO /MACHINE:X86
obj = obj
bin = bin
objects = $(obj)\uMod_DX9_dll.$(obj_suff) \
$(obj)\uMod_IDirect3D9.$(obj_suff) \
$(obj)\uMod_IDirect3D9Ex.$(obj_suff) \
$(obj)\uMod_IDirect3DDevice9.$(obj_suff) \
$(obj)\uMod_IDirect3DDevice9Ex.$(obj_suff) \
$(obj)\uMod_TextureFunction.$(obj_suff) \
$(obj)\uMod_IDirect3DTexture9.$(obj_suff) \
$(obj)\uMod_IDirect3DVolumeTexture9.$(obj_suff) \
$(obj)\uMod_IDirect3DCubeTexture9.$(obj_suff) \
$(obj)\uMod_ArrayHandler.$(obj_suff) \
$(obj)\uMod_TextureClient.$(obj_suff) \
$(obj)\uMod_TextureServer.$(obj_suff)
headers = uMod_Main.h \
uMod_Defines.h \
uMod_DX9_dll.h \
uMod_IDirect3D9.h \
uMod_IDirect3DDevice9.h \
uMod_TextureFunction.h \
uMod_IDirect3DTexture9.h \
uMod_IDirect3DVolumeTexture9.h \
uMod_IDirect3DCubeTexture9.h \
uMod_ArrayHandler.h \
uMod_TextureClient.h \
uMod_TextureServer.h
$(bin)\d3d9.dll: $(objects)
$(CLINK) $(LFLAGS) $(objects) /OUT:$(bin)\$(dll)
copy $(bin)\$(dll) ..\uMod_GUI\bin\$(dll)
$(obj)\uMod_DX9_dll.$(obj_suff): uMod_DX9_dll.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_DX9_dll.cpp
$(obj)\uMod_IDirect3D9.$(obj_suff): uMod_IDirect3D9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3D9.cpp
$(obj)\uMod_IDirect3D9Ex.$(obj_suff): uMod_IDirect3D9Ex.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3D9Ex.cpp
$(obj)\uMod_IDirect3DDevice9.$(obj_suff): uMod_IDirect3DDevice9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DDevice9.cpp
$(obj)\uMod_IDirect3DDevice9Ex.$(obj_suff): uMod_IDirect3DDevice9Ex.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DDevice9Ex.cpp
$(obj)\uMod_TextureFunction.$(obj_suff): uMod_TextureFunction.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_TextureFunction.cpp
$(obj)\uMod_IDirect3DTexture9.$(obj_suff): uMod_IDirect3DTexture9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DTexture9.cpp
$(obj)\uMod_IDirect3DVolumeTexture9.$(obj_suff): uMod_IDirect3DVolumeTexture9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DVolumeTexture9.cpp
$(obj)\uMod_IDirect3DCubeTexture9.$(obj_suff): uMod_IDirect3DCubeTexture9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DCubeTexture9.cpp
$(obj)\uMod_ArrayHandler.$(obj_suff): uMod_ArrayHandler.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_ArrayHandler.cpp
$(obj)\uMod_TextureClient.$(obj_suff): uMod_TextureClient.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_TextureClient.cpp
$(obj)\uMod_TextureServer.$(obj_suff): uMod_TextureServer.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ uMod_TextureServer.cpp
clean:
del $(objects) $(bin)\$(dll)
-106
View File
@@ -1,106 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
uMod_FileHandler::uMod_FileHandler(void)
{
Message("uMod_FileHandler(void): %lu\n", this);
Number = 0;
FieldCounter = 0;
Files = NULL;
}
uMod_FileHandler::~uMod_FileHandler(void)
{
Message("~uMod_FileHandler(void): %lu\n", this);
if (Files!=NULL)
{
for (int i=0; i<FieldCounter; i++) if (Files[i] != NULL) delete [] Files[i];
delete [] Files;
}
}
int uMod_FileHandler::Add(TextureFileStruct* file)
{
Message("uMod_FileHandler::Add(%lu): %lu\n", file, this);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
if (file->Reference>=0) return (RETURN_UPDATE_ALLREADY_ADDED);
if (Number/FieldLength==FieldCounter) // get more memory
{
TextureFileStruct*** temp = NULL;
try {temp = new TextureFileStruct**[FieldCounter+10];}
catch (...)
{
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return (RETURN_NO_MEMORY);
}
for (int i=0; i<FieldCounter; i++) temp[i] = Files[i]; //copy to new allocated memory
for (int i=FieldCounter; i<FieldCounter+10; i++) temp[i] = NULL; // initialize unused parts to zero
FieldCounter += 10;
if (Files!=NULL) delete [] Files;
Files = temp;
}
if (Number%FieldLength==0) // maybe we need to get more memory
{
try {if (Files[Number/FieldLength]==NULL) Files[Number/FieldLength] = new TextureFileStruct*[FieldLength];}
catch (...)
{
Files[Number/FieldLength] = NULL;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return (RETURN_NO_MEMORY);
}
}
Files[Number/FieldLength][Number%FieldLength] = file;
file->Reference = Number++; //set the reference for a fast deleting
return (RETURN_OK);
}
int uMod_FileHandler::Remove(TextureFileStruct* file)
{
Message("uMod_FileHandler::Remove(%lu): %lu\n", file, this);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
int ref = file->Reference;
if (ref<0) return (RETURN_OK); // returning if no Reference is set
file->Reference = -1; //set reference outside of bound
if (ref<(--Number)) //if reference is unequal to Number-1 we copy the last entry to the index "ref"
{
Files[ref/FieldLength][ref%FieldLength] = Files[Number/FieldLength][Number%FieldLength];
Files[ref/FieldLength][ref%FieldLength]->Reference = ref; //set the new reference entry
}
return (RETURN_OK);
}
-183
View File
@@ -1,183 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_FIELDHANDLER_H_
#define uMod_FIELDHANDLER_H_
#include "..\uMod_GlobalDefines.h"
#include "uMod_IDirect3DTexture9.h"
typedef struct
{
bool ForceReload; // to force a reload of the texture (if it is already modded)
char* pData; // store texture file as file in memory
unsigned int Size; // size of file
int NumberOfTextures;
int Reference; // for a fast delete in the FileHandler
IDirect3DBaseTexture9 **Textures; // pointer to the fake textures
MyTypeHash Hash; // hash value
} TextureFileStruct;
class uMod_FileHandler // array to store TextureFileStruct
{
public:
uMod_FileHandler(void);
~uMod_FileHandler(void);
int Add( TextureFileStruct* file);
int Remove( TextureFileStruct* file);
int GetNumber(void) {return (Number);}
TextureFileStruct *operator [] (int i) {if (i<0||i>=Number) return (NULL); else return (Files[i/FieldLength][i%FieldLength]);}
protected:
static const int FieldLength = 1024;
long Number;
int FieldCounter;
TextureFileStruct*** Files;
};
template <class T>
class uMod_TextureHandler // array to store uMod_IDirect3DTexture9, uMod_IDirect3DVolumeTexture9 or uMod_IDirect3DCubeTexture9
{
public:
uMod_TextureHandler(void);
~uMod_TextureHandler(void);
int Add( T* texture);
int Remove( T* texture);
int GetNumber(void) {return (Number);}
T *operator [] (int i) {if (i<0||i>=Number) return (NULL); else return (Textures[i/FieldLength][i%FieldLength]);}
private:
static const int FieldLength = 1024;
long Number;
int FieldCounter;
T*** Textures;
};
template <class T>
uMod_TextureHandler<T>::uMod_TextureHandler(void)
{
Message("uMod_TextureHandler(void): %lu\n", this);
Number = 0;
FieldCounter = 0;
Textures = NULL;
}
template <class T>
uMod_TextureHandler<T>::~uMod_TextureHandler(void)
{
Message("~uMod_TextureHandler(void): %lu\n", this);
if (Textures!=NULL)
{
for (int i=0; i<FieldCounter; i++) if (Textures[i] != NULL) delete [] Textures[i];
delete [] Textures;
}
}
template <class T>
int uMod_TextureHandler<T>::Add(T* pTexture)
{
Message("uMod_TextureHandler::Add( %lu): %lu\n", pTexture, this);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
if (pTexture->Reference>=0) return (RETURN_TEXTURE_ALLREADY_ADDED);
if (Number/FieldLength==FieldCounter)
{
T*** temp = NULL;
try {temp = new T**[FieldCounter+10];}
catch (...)
{
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return (RETURN_NO_MEMORY);
}
for (int i=0; i<FieldCounter; i++) temp[i] = Textures[i];
for (int i=FieldCounter; i<FieldCounter+10; i++) temp[i] = NULL;
FieldCounter += 10;
if (Textures!=NULL) delete [] Textures;
Textures = temp;
}
if (Number%FieldLength==0)
{
try {if (Textures[Number/FieldLength]==NULL) Textures[Number/FieldLength] = new T*[FieldLength];}
catch (...)
{
Textures[Number/FieldLength]=NULL;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
return (RETURN_NO_MEMORY);
}
}
Textures[Number/FieldLength][Number%FieldLength] = pTexture;
pTexture->Reference = Number++;
return (RETURN_OK);
}
template <class T>
int uMod_TextureHandler<T>::Remove(T* pTexture) //will be called, if a texture is completely released
{
Message("uMod_TextureHandler::Remove( %lu): %lu\n", pTexture, this);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
int ref = pTexture->Reference;
if (ref<0) return (RETURN_OK); // returning if no TextureHandlerRef is set
if (ref<(--Number))
{
Textures[ref/FieldLength][ref%FieldLength] = Textures[Number/FieldLength][Number%FieldLength];
Textures[ref/FieldLength][ref%FieldLength]->Reference = ref;
}
return (RETURN_OK);
}
#endif /* uMod_FIELDHANDLER_H_ */
-463
View File
@@ -1,463 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
NEVER USE THIS CODE FOR ILLEGAL PURPOSE
*/
#include "uMod_Main.h"
//#include "detours.h"
//#include "detourxs/detourxs/detourxs.h"
/*
#include "detourxs/detourxs/ADE32.cpp"
#include "detourxs/detourxs/detourxs.cpp"
*/
/*
* global variable which are not linked external
*/
HINSTANCE gl_hOriginalDll = NULL;
HINSTANCE gl_hThisInstance = NULL;
uMod_TextureServer* gl_TextureServer = NULL;
HANDLE gl_ServerThread = NULL;
typedef IDirect3D9 *(APIENTRY *Direct3DCreate9_type)(UINT);
typedef HRESULT (APIENTRY *Direct3DCreate9Ex_type)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
#ifndef NO_INJECTION
Direct3DCreate9_type Direct3DCreate9_fn; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
Direct3DCreate9Ex_type Direct3DCreate9Ex_fn; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
HHOOK gl_hHook = NULL;
#endif
/*
* global variable which are linked external
*/
unsigned int gl_ErrorState = 0u;
#ifdef LOG_MESSAGE
FILE* gl_File = NULL;
#endif
#ifdef DIRECT_INJECTION
void Nothing(void) {(void)NULL;}
#endif
/*
* dll entry routine, here we initialize or clean up
*/
BOOL WINAPI DllMain( HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
UNREFERENCED_PARAMETER(lpReserved);
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
InitInstance(hModule);
break;
}
case DLL_PROCESS_DETACH:
{
ExitInstance();
break;
}
default: break;
}
return (true);
}
DWORD WINAPI ServerThread( LPVOID lpParam )
{
UNREFERENCED_PARAMETER(lpParam);
if (gl_TextureServer!=NULL) gl_TextureServer->MainLoop(); //This is and endless mainloop, it sleep till something is written into the pipe.
return (0);
}
void InitInstance(HINSTANCE hModule)
{
DisableThreadLibraryCalls( hModule ); //reduce overhead
gl_hThisInstance = (HINSTANCE) hModule;
wchar_t game[MAX_PATH];
if (HookThisProgram( game)) //ask if we need to hook this program
{
OpenMessage();
Message("InitInstance: %lu\n", hModule);
gl_TextureServer = new uMod_TextureServer(game); //create the server which listen on the pipe and prepare the update for the texture clients
LoadOriginalDll();
#ifndef NO_INJECTION
// we detour the original Direct3DCreate9 to our MyDirect3DCreate9
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress(gl_hOriginalDll, "Direct3DCreate9");
if (Direct3DCreate9_fn!=NULL)
{
Message("Detour: Direct3DCreate9\n");
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*)Direct3DCreate9_fn, (BYTE*)uMod_Direct3DCreate9, 5);
}
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress(gl_hOriginalDll, "Direct3DCreate9Ex");
if (Direct3DCreate9Ex_fn!=NULL)
{
Message("Detour: Direct3DCreate9Ex\n");
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*)Direct3DCreate9Ex_fn, (BYTE*)uMod_Direct3DCreate9Ex, 7);
}
#endif
if (gl_TextureServer->OpenPipe(game)) //open the pipe and send the name+path of this executable
{
Message("InitInstance: Pipe not opened\n");
return;
}
gl_ServerThread = CreateThread( NULL, 0, ServerThread, NULL, 0, NULL); //creating a thread for the mainloop
if (gl_ServerThread==NULL) {Message("InitInstance: Serverthread not started\n");}
}
}
void LoadOriginalDll(void)
{
char buffer[MAX_PATH];
GetSystemDirectory(buffer,MAX_PATH); //get the system directory, we need to open the original d3d9.dll
// Append dll name
strcat_s( buffer, MAX_PATH,"\\d3d9.dll");
// try to load the system's d3d9.dll, if pointer empty
if (!gl_hOriginalDll) gl_hOriginalDll = LoadLibrary(buffer);
if (!gl_hOriginalDll)
{
ExitProcess(0); // exit the hard way
}
}
void ExitInstance()
{
if (gl_TextureServer!=NULL)
{
gl_TextureServer->ClosePipe(); //This must be done before the server thread is killed, because the server thread will endless wait on the ReadFile()
}
if (gl_ServerThread!=NULL)
{
CloseHandle(gl_ServerThread); // kill the server thread
gl_ServerThread = NULL;
}
if (gl_TextureServer!=NULL)
{
delete gl_TextureServer; //delete the texture server
gl_TextureServer = NULL;
}
// Release the system's d3d9.dll
if (gl_hOriginalDll!=NULL)
{
FreeLibrary(gl_hOriginalDll);
gl_hOriginalDll = NULL;
}
CloseMessage();
}
#ifdef NO_INJECTION
/*
* We do not inject, the game loads this dll by itself thus we must include the Direct3DCreate9 function
*/
IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
{
Message("WINAPI Direct3DCreate9\n");
if (!gl_hOriginalDll) LoadOriginalDll(); // looking for the "right d3d9.dll"
// find original function in original d3d9.dll
Direct3DCreate9_type D3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
if (!D3DCreate9_fn)
{
Message("Direct3DCreate9: original function not found in dll\n");
return (NULL);
}
//Create originale IDirect3D9 object
IDirect3D9 *pIDirect3D9_orig = D3DCreate9_fn(SDKVersion);
//create our uMod_IDirect3D9 object
uMod_IDirect3D9 *pIDirect3D9 = new uMod_IDirect3D9( pIDirect3D9_orig, gl_TextureServer);
// Return pointer to our object instead of "real one"
return (pIDirect3D9);
}
HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **ppD3D)
{
Message("WINAPI Direct3DCreate9Ex\n");
if (!gl_hOriginalDll) LoadOriginalDll(); // looking for the "right d3d9.dll"
// find original function in original d3d9.dll
Direct3DCreate9Ex_type D3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex");
if (!D3DCreate9Ex_fn)
{
Message("Direct3DCreate9Ex: original function not found in dll\n");
return (D3DERR_NOTAVAILABLE);
}
//Create originale IDirect3D9 object
IDirect3D9Ex *pIDirect3D9Ex_orig;
HRESULT ret = D3DCreate9Ex_fn( SDKVersion, &pIDirect3D9Ex_orig);
if (ret!=S_OK) return (ret);
//create our uMod_IDirect3D9 object
uMod_IDirect3D9Ex *pIDirect3D9Ex = new uMod_IDirect3D9Ex( pIDirect3D9Ex_orig, gl_TextureServer);
ppD3D = &pIDirect3D9Ex_orig; // Return pointer to our object instead of "real one"
return (ret);
}
bool HookThisProgram( wchar_t *ret) //this function always return true, it is needed for the name and path of the executable
{
wchar_t Executable[MAX_PATH];
GetModuleFileNameW( GetModuleHandle( NULL ), Executable, MAX_PATH ); //ask for name and path of this executable
int len = 0;
while (Executable[len]) {ret[len] = Executable[len]; len++;}
ret[len] = 0;
return (true);
}
#else
/*
* We inject the dll into the game, thus we retour the original Direct3DCreate9 function to our MyDirect3DCreate9 function
*/
IDirect3D9 *APIENTRY uMod_Direct3DCreate9(UINT SDKVersion)
{
Message("uMod_Direct3DCreate9: original %lu, uMod %lu\n", Direct3DCreate9_fn, uMod_Direct3DCreate9);
// in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines
// but somehow, for me it only works, if I retour the function and calling afterward the original function
// BEGIN
LoadOriginalDll();
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9"), (BYTE*)Direct3DCreate9_fn, 5);
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
/*
if (Direct3DCreate9Ex_fn!=NULL)
{
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex"), (BYTE*)Direct3DCreate9Ex_fn, 7);
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex");
}
*/
// END
IDirect3D9 *pIDirect3D9_orig = NULL;
if (Direct3DCreate9_fn)
{
pIDirect3D9_orig = Direct3DCreate9_fn(SDKVersion); //creating the original IDirect3D9 object
}
else return (NULL);
uMod_IDirect3D9 *pIDirect3D9;
if (pIDirect3D9_orig)
{
pIDirect3D9 = new uMod_IDirect3D9( pIDirect3D9_orig, gl_TextureServer); //creating our uMod_IDirect3D9 object
}
// we detour again
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*) Direct3DCreate9_fn, (BYTE*)uMod_Direct3DCreate9,5);
/*
if (Direct3DCreate9Ex_fn!=NULL)
{
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*) Direct3DCreate9Ex_fn, (BYTE*)uMod_Direct3DCreate9Ex,7);
}
*/
return (pIDirect3D9); //return our object instead of the "real one"
}
HRESULT APIENTRY uMod_Direct3DCreate9Ex( UINT SDKVersion, IDirect3D9Ex **ppD3D)
{
Message( "uMod_Direct3DCreate9Ex: original %lu, uMod %lu\n", Direct3DCreate9Ex_fn, uMod_Direct3DCreate9Ex);
// in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines
// but somehow, for me it only works, if I retour the function and calling afterward the original function
// BEGIN
LoadOriginalDll();
/*
if (Direct3DCreate9_fn!=NULL)
{
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9"), (BYTE*)Direct3DCreate9_fn, 5);
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
}
*/
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex"), (BYTE*)Direct3DCreate9Ex_fn, 7);
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex");
// END
IDirect3D9Ex *pIDirect3D9Ex_orig = NULL;
HRESULT ret;
if (Direct3DCreate9Ex_fn)
{
ret = Direct3DCreate9Ex_fn(SDKVersion, &pIDirect3D9Ex_orig); //creating the original IDirect3D9 object
}
else return (D3DERR_NOTAVAILABLE);
if (ret!=S_OK) return (ret);
uMod_IDirect3D9Ex *pIDirect3D9Ex;
if (pIDirect3D9Ex_orig)
{
pIDirect3D9Ex = new uMod_IDirect3D9Ex( pIDirect3D9Ex_orig, gl_TextureServer); //creating our uMod_IDirect3D9 object
}
// we detour again
/*
if (Direct3DCreate9_fn!=NULL)
{
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*) Direct3DCreate9_fn, (BYTE*)uMod_Direct3DCreate9,5);
}
*/
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*) Direct3DCreate9Ex_fn, (BYTE*)uMod_Direct3DCreate9Ex,7);
ppD3D = (IDirect3D9Ex**) &pIDirect3D9Ex; //return our object instead of the "real one"
return (ret);
}
bool HookThisProgram( wchar_t *ret)
{
wchar_t Executable[MAX_PATH];
wchar_t Game[MAX_PATH];
GetModuleFileNameW( GetModuleHandle( NULL ), Executable, MAX_PATH ); //ask for name and path of this executable
#ifdef HOOK_INJECTION
//we use the gloabal hook
FILE* file;
wchar_t *app_path = _wgetenv( L"APPDATA"); //asc for the user application directory
wchar_t file_name[MAX_PATH];
swprintf_s( file_name, MAX_PATH, L"%ls\\%ls\\%ls", app_path, uMod_APP_DIR, uMod_APP_DX9);
if (_wfopen_s( &file, file_name, L"rt,ccs=UTF-16LE")) return (false); // open the file in utf-16 LE mode
//MessageBoxW( NULL, Executable, L"test", 0);
while (!feof(file))
{
if ( fgetws( Game, MAX_PATH, file) != NULL ) //get each line of the file
{
//MessageBoxW( NULL, Game, L"test", 0);
int len = 0;
while (Game[len])
{
if (Game[len]==L'\r' || Game[len]==L'\n') {Game[len]=0; break;} //removing the new line symbols
len++;
}
if ( _wcsicmp( Executable, Game ) == 0 ) //compare both strings
{
for (int i=0; i<len; i++) ret[i] = Game[i];
ret[len] = 0;
fclose(file);
return (true);
}
}
}
fclose(file);
return (false);
#endif
#ifdef DIRECT_INJECTION
// we inject directly
int i=0;
while ( Game[i]) {ret[i]=Game[i]; i++;}
ret[i]=0;
return true;
#endif
}
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback = 0;
VirtualProtect(jmp, len+5, PAGE_EXECUTE_READWRITE, &dwback); //This is the addition needed for Windows 7 RC
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
memset(src, 0x90, len);
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
}
bool RetourFunc(BYTE *src, BYTE *restore, const int len)
{
DWORD dwback;
if(!VirtualProtect(src, len, PAGE_READWRITE, &dwback)) { return (false); }
if(!memcpy(src, restore, len)) { return (false); }
restore[0] = 0xE9;
*(DWORD*)(restore+1) = (DWORD)(src - restore) - 5;
if(!VirtualProtect(src, len, dwback, &dwback)) { return (false); }
return (true);
}
#ifdef HOOK_INJECTION
/*
* We do not change something, if our hook function is called.
* We need this hook only to get our dll loaded into a starting program.
*/
LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return (CallNextHookEx( gl_hHook, nCode, wParam, lParam));
}
void InstallHook(void)
{
gl_hHook = SetWindowsHookEx( WH_CBT, HookProc, gl_hThisInstance, 0 );
}
void RemoveHook(void)
{
UnhookWindowsHookEx( gl_hHook );
}
#endif
#endif
-52
View File
@@ -1,52 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_DX9_DLL_H_
#define uMod_DX9_DLL_H_
void InitInstance(HINSTANCE hModule);
void ExitInstance(void);
void LoadOriginalDll(void);
bool HookThisProgram( wchar_t *ret);
DWORD WINAPI ServerThread( LPVOID lpParam);
#ifndef NO_INJECTION
void *DetourFunc(BYTE *src, const BYTE *dst, const int len);
bool RetourFunc(BYTE *src, BYTE *restore, const int len);
IDirect3D9 *APIENTRY uMod_Direct3DCreate9(UINT SDKVersion);
HRESULT APIENTRY uMod_Direct3DCreate9Ex( UINT SDKVersion, IDirect3D9Ex **ppD3D);
#ifdef HOOK_INJECTION
LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam);
void InstallHook(void);
void RemoveHook(void);
#endif
#ifdef DIRECT_INJECTION
void Nothing(void);
#endif
#endif
#endif
@@ -1,5 +0,0 @@
LIBRARY "uMod_d3d9_DI"
EXPORTS
uMod_Direct3DCreate9 @1
uMod_Direct3DCreate9Ex @2
Nothing @3
-6
View File
@@ -1,6 +0,0 @@
LIBRARY "uMod_d3d9_Hook"
EXPORTS
uMod_Direct3DCreate9 @1
uMod_Direct3DCreate9Ex @2
InstallHook @3
RemoveHook @4
-4
View File
@@ -1,4 +0,0 @@
LIBRARY "d3d9"
EXPORTS
Direct3DCreate9 @1
Direct3DCreate9Ex @2
-70
View File
@@ -1,70 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_DEFINES_H_
#define uMod_DEFINES_H_
#ifdef LOG_MESSAGE
extern FILE *gl_File;
#define Message(...) {if (gl_File!=NULL) {fprintf( gl_File, __VA_ARGS__); fflush(gl_File);}}
#ifdef HOOK_INJECTION
#define OpenMessage(...) {if (fopen_s( &gl_File, "uMod_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "HI R40: 0000000\n");}
#endif
#ifdef DIRECT_INJECTION
#define OpenMessage(...) {if (fopen_s( &gl_File, "uMod_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "DI 40: 0000000\n");}
#endif
#ifdef NO_INJECTION
#define OpenMessage(...) {if (fopen_s( &gl_File, "uMod_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "NI R40: 0000000\n");}
#endif
#define CloseMessage(...) {if (gl_File!=NULL) fclose(gl_File);}
#else
#define OpenMessage(...)
#define Message(...)
#define CloseMessage(...)
#endif
#ifdef __CDT_PARSER__
typedef unsigned long DWORD64;
typedef unsigned long DWORD32;
#define STDMETHOD(method) virtual HRESULT method
#define STDMETHOD_(ret, method) virtual ret method
#define sprintf_s(...)
#define fprintf(...)
#define fclose(...)
#define fseek(...)
#define ftell(...) 0
#define fflush(...)
typedef LONG HRESULT;
#define UNREFERENCED_PARAMETER(...)
#endif
#endif /* uMod_DEFINES_H_ */
-156
View File
@@ -1,156 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
#ifndef PRE_MESSAGE
#define PRE_MESSAGE "uMod_IDirect3D9"
#endif
uMod_IDirect3D9::uMod_IDirect3D9( IDirect3D9 *pOriginal, uMod_TextureServer* server)
{
Message( PRE_MESSAGE "::" PRE_MESSAGE "( %lu, %lu): %lu\n", pOriginal, server, this);
m_pIDirect3D9 = pOriginal;
uMod_Server = server;
}
uMod_IDirect3D9::~uMod_IDirect3D9(void)
{
Message( PRE_MESSAGE "::~" PRE_MESSAGE "(): %lu\n", this);
}
HRESULT __stdcall uMod_IDirect3D9::QueryInterface(REFIID riid, void** ppvObj)
{
*ppvObj = NULL;
// call this to increase AddRef at original object
// and to check if such an interface is there
HRESULT hRes = m_pIDirect3D9->QueryInterface(riid, ppvObj);
if (hRes == NOERROR) // if OK, send our "fake" address
{
*ppvObj = this;
}
return (hRes);
}
ULONG __stdcall uMod_IDirect3D9::AddRef(void)
{
return(m_pIDirect3D9->AddRef());
}
ULONG __stdcall uMod_IDirect3D9::Release(void)
{
// call original routine
ULONG count = m_pIDirect3D9->Release();
// in case no further Ref is there, the Original Object has deleted itself
if (count == 0)
{
delete(this);
}
return(count);
}
HRESULT __stdcall uMod_IDirect3D9::RegisterSoftwareDevice(void* pInitializeFunction)
{
return(m_pIDirect3D9->RegisterSoftwareDevice(pInitializeFunction));
}
UINT __stdcall uMod_IDirect3D9::GetAdapterCount(void)
{
return(m_pIDirect3D9->GetAdapterCount());
}
HRESULT __stdcall uMod_IDirect3D9::GetAdapterIdentifier(UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier)
{
return(m_pIDirect3D9->GetAdapterIdentifier(Adapter,Flags,pIdentifier));
}
UINT __stdcall uMod_IDirect3D9::GetAdapterModeCount(UINT Adapter, D3DFORMAT Format)
{
return(m_pIDirect3D9->GetAdapterModeCount(Adapter, Format));
}
HRESULT __stdcall uMod_IDirect3D9::EnumAdapterModes(UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode)
{
return(m_pIDirect3D9->EnumAdapterModes(Adapter,Format,Mode,pMode));
}
HRESULT __stdcall uMod_IDirect3D9::GetAdapterDisplayMode( UINT Adapter,D3DDISPLAYMODE* pMode)
{
return(m_pIDirect3D9->GetAdapterDisplayMode(Adapter,pMode));
}
HRESULT __stdcall uMod_IDirect3D9::CheckDeviceType(UINT iAdapter,D3DDEVTYPE DevType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed)
{
return(m_pIDirect3D9->CheckDeviceType(iAdapter,DevType,DisplayFormat,BackBufferFormat,bWindowed));
}
HRESULT __stdcall uMod_IDirect3D9::CheckDeviceFormat(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat)
{
return(m_pIDirect3D9->CheckDeviceFormat(Adapter,DeviceType,AdapterFormat,Usage,RType,CheckFormat));
}
HRESULT __stdcall uMod_IDirect3D9::CheckDeviceMultiSampleType(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels)
{
return(m_pIDirect3D9->CheckDeviceMultiSampleType(Adapter,DeviceType,SurfaceFormat,Windowed,MultiSampleType,pQualityLevels));
}
HRESULT __stdcall uMod_IDirect3D9::CheckDepthStencilMatch(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat)
{
return(m_pIDirect3D9->CheckDepthStencilMatch(Adapter,DeviceType,AdapterFormat,RenderTargetFormat,DepthStencilFormat));
}
HRESULT __stdcall uMod_IDirect3D9::CheckDeviceFormatConversion(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat)
{
return(m_pIDirect3D9->CheckDeviceFormatConversion(Adapter,DeviceType,SourceFormat,TargetFormat));
}
HRESULT __stdcall uMod_IDirect3D9::GetDeviceCaps(UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps)
{
return(m_pIDirect3D9->GetDeviceCaps(Adapter,DeviceType,pCaps));
}
HMONITOR __stdcall uMod_IDirect3D9::GetAdapterMonitor(UINT Adapter)
{
return(m_pIDirect3D9->GetAdapterMonitor(Adapter));
}
HRESULT __stdcall uMod_IDirect3D9::CreateDevice(UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface)
{
Message( PRE_MESSAGE "::CreateDevice(): %lu\n", this);
// we intercept this call and provide our own "fake" Device Object
HRESULT hres = m_pIDirect3D9->CreateDevice( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
int count = 1;
if (pPresentationParameters!=NULL) count = pPresentationParameters->BackBufferCount;
uMod_IDirect3DDevice9 *pIDirect3DDevice9 = new uMod_IDirect3DDevice9(*ppReturnedDeviceInterface, uMod_Server, count);
// store our pointer (the fake one) for returning it to the calling program
*ppReturnedDeviceInterface = pIDirect3DDevice9;
return(hres);
}
-66
View File
@@ -1,66 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* BIG THANKS TO Michael Koch
* (proxydll_9.zip)
*
*/
#ifndef uMod_IDirect3D9_H_
#define uMod_IDirect3D9_H_
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_TextureServer.h"
#include "uMod_TextureClient.h"
class uMod_IDirect3D9 : public IDirect3D9
{
public:
uMod_IDirect3D9(IDirect3D9 *pOriginal, uMod_TextureServer *server);
virtual ~uMod_IDirect3D9(void);
// The original DX9 function definitions
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj);
ULONG __stdcall AddRef(void);
ULONG __stdcall Release(void);
HRESULT __stdcall RegisterSoftwareDevice(void* pInitializeFunction);
UINT __stdcall GetAdapterCount(void);
HRESULT __stdcall GetAdapterIdentifier(UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier) ;
UINT __stdcall GetAdapterModeCount(UINT Adapter, D3DFORMAT Format);
HRESULT __stdcall EnumAdapterModes(UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode) ;
HRESULT __stdcall GetAdapterDisplayMode( UINT Adapter,D3DDISPLAYMODE* pMode) ;
HRESULT __stdcall CheckDeviceType(UINT iAdapter,D3DDEVTYPE DevType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed) ;
HRESULT __stdcall CheckDeviceFormat(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat) ;
HRESULT __stdcall CheckDeviceMultiSampleType(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels) ;
HRESULT __stdcall CheckDepthStencilMatch(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) ;
HRESULT __stdcall CheckDeviceFormatConversion(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat);
HRESULT __stdcall GetDeviceCaps(UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps) ;
HMONITOR __stdcall GetAdapterMonitor(UINT Adapter) ;
HRESULT __stdcall CreateDevice(UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface) ;
private:
IDirect3D9 *m_pIDirect3D9;
uMod_TextureServer* uMod_Server;
};
#endif
-71
View File
@@ -1,71 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
#define IDirect3D9 IDirect3D9Ex
#define uMod_IDirect3D9 uMod_IDirect3D9Ex
#define m_pIDirect3D9 m_pIDirect3D9Ex
#define PRE_MESSAGE "uMod_IDirect3D9Ex"
#include "uMod_IDirect3D9.cpp"
HRESULT __stdcall uMod_IDirect3D9Ex::CreateDeviceEx( UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode, IDirect3DDevice9Ex **ppReturnedDeviceInterface)
{
Message( "uMod_IDirect3D9Ex::CreateDeviceEx: %lu\n", this);
// we intercept this call and provide our own "fake" Device Object
HRESULT hres = m_pIDirect3D9Ex->CreateDeviceEx( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface);
int count = 1;
if (pPresentationParameters!=NULL) count = pPresentationParameters->BackBufferCount;
uMod_IDirect3DDevice9Ex *pIDirect3DDevice9Ex = new uMod_IDirect3DDevice9Ex(*ppReturnedDeviceInterface, uMod_Server, count);
// store our pointer (the fake one) for returning it to the calling program
*ppReturnedDeviceInterface = pIDirect3DDevice9Ex;
return(hres);
return (m_pIDirect3D9Ex->CreateDeviceEx( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface));
}
HRESULT __stdcall uMod_IDirect3D9Ex::EnumAdapterModesEx( UINT Adapter, const D3DDISPLAYMODEFILTER *pFilter, UINT Mode, D3DDISPLAYMODEEX *pMode)
{
return (m_pIDirect3D9Ex->EnumAdapterModesEx( Adapter, pFilter, Mode, pMode));
}
HRESULT __stdcall uMod_IDirect3D9Ex::GetAdapterDisplayModeEx( UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation)
{
return (m_pIDirect3D9Ex->GetAdapterDisplayModeEx( Adapter, pMode, pRotation));
}
HRESULT __stdcall uMod_IDirect3D9Ex::GetAdapterLUID( UINT Adapter, LUID *pLUID)
{
return (m_pIDirect3D9Ex->GetAdapterLUID( Adapter, pLUID));
}
UINT __stdcall uMod_IDirect3D9Ex::GetAdapterModeCountEx( UINT Adapter, const D3DDISPLAYMODEFILTER *pFilter)
{
return (m_pIDirect3D9Ex->GetAdapterModeCountEx( Adapter, pFilter));
}
-73
View File
@@ -1,73 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* BIG THANKS TO Michael Koch
* (proxydll_9.zip)
*
*/
#ifndef uMod_IDirect3D9Ex_H_
#define uMod_IDirect3D9Ex_H_
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_TextureServer.h"
#include "uMod_TextureClient.h"
class uMod_IDirect3D9Ex : public IDirect3D9Ex
{
public:
uMod_IDirect3D9Ex( IDirect3D9Ex *pOriginal, uMod_TextureServer *server);
virtual ~uMod_IDirect3D9Ex(void);
// The original DX9 function definitions
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj);
ULONG __stdcall AddRef(void);
ULONG __stdcall Release(void);
HRESULT __stdcall RegisterSoftwareDevice(void* pInitializeFunction);
UINT __stdcall GetAdapterCount(void);
HRESULT __stdcall GetAdapterIdentifier(UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier) ;
UINT __stdcall GetAdapterModeCount(UINT Adapter, D3DFORMAT Format);
HRESULT __stdcall EnumAdapterModes(UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode) ;
HRESULT __stdcall GetAdapterDisplayMode( UINT Adapter,D3DDISPLAYMODE* pMode) ;
HRESULT __stdcall CheckDeviceType(UINT iAdapter,D3DDEVTYPE DevType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed) ;
HRESULT __stdcall CheckDeviceFormat(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat) ;
HRESULT __stdcall CheckDeviceMultiSampleType(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels) ;
HRESULT __stdcall CheckDepthStencilMatch(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) ;
HRESULT __stdcall CheckDeviceFormatConversion(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat);
HRESULT __stdcall GetDeviceCaps(UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps) ;
HMONITOR __stdcall GetAdapterMonitor(UINT Adapter) ;
HRESULT __stdcall CreateDevice(UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface) ;
HRESULT __stdcall CreateDeviceEx( UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode, IDirect3DDevice9Ex **ppReturnedDeviceInterface);
HRESULT __stdcall EnumAdapterModesEx( UINT Adapter, const D3DDISPLAYMODEFILTER *pFilter, UINT Mode, D3DDISPLAYMODEEX *pMode);
HRESULT __stdcall GetAdapterDisplayModeEx( UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation);
HRESULT __stdcall GetAdapterLUID( UINT Adapter, LUID *pLUID);
UINT __stdcall GetAdapterModeCountEx( UINT Adapter, const D3DDISPLAYMODEFILTER *pFilter);
private:
IDirect3D9Ex *m_pIDirect3D9Ex;
uMod_TextureServer* uMod_Server;
};
#endif
-364
View File
@@ -1,364 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* some function (e.g. AddReff()) are presumed to work on the texture object which belong to them
* if this texture was switched, we must redirect this calls to the CrossRef_D3Dtex texture object
*/
#include "uMod_Main.h"
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::QueryInterface(REFIID riid, void** ppvObj)
{
if (riid==IID_IDirect3D9)
{
// This function should never be called with IID_IDirect3D9 by the game
// thus this call comes from our own dll to ask for the texture type
// 0x01000000L == uMod_IDirect3DTexture9
// 0x01000001L == uMod_IDirect3DVolumeTexture9
// 0x01000002L == uMod_IDirect3DCubeTexture9
*ppvObj = this;
return (0x01000002L);
}
HRESULT hRes;
if (CrossRef_D3Dtex!=NULL)
{
hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj==CrossRef_D3Dtex->m_D3Dtex) *ppvObj=this;
}
else
{
hRes = m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj==m_D3Dtex) *ppvObj=this;
}
return (hRes);
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DCubeTexture9::AddRef()
{
if (FAKE) return (1); //bug, this case should never happen
if (CrossRef_D3Dtex!=NULL)
{
return (CrossRef_D3Dtex->m_D3Dtex->AddRef());
}
else return (m_D3Dtex->AddRef());
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DCubeTexture9::Release()
{
Message("uMod_IDirect3DCubeTexture9::Release(): %lu\n", this);
void *cpy;
long ret = m_D3Ddev->QueryInterface( IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE)
{
UnswitchTextures( this);
count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures
}
else
{
if (CrossRef_D3Dtex!=NULL) //if this texture is switched with a fake texture
{
uMod_IDirect3DCubeTexture9 *fake_texture = CrossRef_D3Dtex;
count = fake_texture->m_D3Dtex->Release(); //release the original texture
if (count==0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (ret == 0x01000000L)
{
if (((uMod_IDirect3DDevice9*) m_D3Ddev)->GetSingleCubeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
else
{
if (((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetSingleCubeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
}
}
else
{
count = m_D3Dtex->Release();
}
}
if (count==0) //if this texture is released, we clean up
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (ret == 0x01000000L)
{
if (((uMod_IDirect3DDevice9*) m_D3Ddev)->GetLastCreatedCubeTexture()==this) ((uMod_IDirect3DDevice9*) m_D3Ddev)->SetLastCreatedCubeTexture( NULL);
else ((uMod_IDirect3DDevice9*) m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
else
{
if (((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetLastCreatedCubeTexture()==this) ((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->SetLastCreatedCubeTexture( NULL);
else ((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
delete(this);
}
return (count);
}
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetDevice(IDirect3DDevice9** ppDevice)
{
*ppDevice = m_D3Ddev;
return D3D_OK;
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::SetPrivateData(REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags));
return (m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetPrivateData(REFGUID refguid,void* pData,DWORD* pSizeOfData)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData));
return (m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::FreePrivateData(REFGUID refguid)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid));
return (m_D3Dtex->FreePrivateData(refguid));
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::SetPriority(DWORD PriorityNew)
{
return (m_D3Dtex->SetPriority(PriorityNew));
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetPriority()
{
return (m_D3Dtex->GetPriority());
}
void APIENTRY uMod_IDirect3DCubeTexture9::PreLoad()
{
m_D3Dtex->PreLoad();
}
D3DRESOURCETYPE APIENTRY uMod_IDirect3DCubeTexture9::GetType()
{
return (m_D3Dtex->GetType());
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::SetLOD(DWORD LODNew)
{
return (m_D3Dtex->SetLOD(LODNew));
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetLOD()
{
return (m_D3Dtex->GetLOD());
}
DWORD APIENTRY uMod_IDirect3DCubeTexture9::GetLevelCount()
{
return (m_D3Dtex->GetLevelCount());
}
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType)
{
return (m_D3Dtex->SetAutoGenFilterType(FilterType));
}
D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DCubeTexture9::GetAutoGenFilterType()
{
return (m_D3Dtex->GetAutoGenFilterType());
}
void APIENTRY uMod_IDirect3DCubeTexture9::GenerateMipSubLevels()
{
m_D3Dtex->GenerateMipSubLevels();
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::AddDirtyRect(D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->AddDirtyRect( FaceType, pDirtyRect));
return (m_D3Dtex->AddDirtyRect( FaceType, pDirtyRect));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc));
return (m_D3Dtex->GetLevelDesc(Level, pDesc));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9 **ppCubeMapSurface)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetCubeMapSurface( FaceType, Level, ppCubeMapSurface));
return (m_D3Dtex->GetCubeMapSurface( FaceType, Level, ppCubeMapSurface));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::LockRect( D3DCUBEMAP_FACES FaceType, UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->LockRect( FaceType, Level, pLockedRect, pRect, Flags));
return (m_D3Dtex->LockRect( FaceType, Level, pLockedRect, pRect, Flags));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DCubeTexture9::UnlockRect( D3DCUBEMAP_FACES FaceType, UINT Level)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->UnlockRect( FaceType, Level));
return (m_D3Dtex->UnlockRect( FaceType, Level));
}
int uMod_IDirect3DCubeTexture9::GetHash(MyTypeHash &hash)
{
hash=0u;
if (FAKE) return (RETURN_BAD_ARGUMENT);
IDirect3DCubeTexture9 *pTexture = m_D3Dtex;
if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex;
//IDirect3DSurface9 *pOffscreenSurface = NULL;
//IDirect3DCubeTexture9 *pOffscreenTexture = NULL;
IDirect3DSurface9 *pResolvedSurface = NULL;
D3DLOCKED_RECT d3dlr;
D3DSURFACE_DESC desc;
if (pTexture->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture
{
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetLevelDesc \n");
return (RETURN_GetLevelDesc_FAILED);
}
Message("uMod_IDirect3DCubeTexture9::GetHash() (%d %d) %d\n", desc.Width, desc.Height, desc.Format);
/*
if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture
{
//Message("uMod_IDirect3DCubeTexture9::GetHash() (D3DPOOL_DEFAULT)\n");
IDirect3DSurface9 *pSurfaceLevel_orig = NULL;
if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK)
{
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE)
{
//Message("uMod_IDirect3DCubeTexture9::GetHash() MultiSampleType\n");
if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig = pResolvedSurface;
}
if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n");
return (RETURN_TEXTURE_NOT_LOADED);
}
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig->Release();
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
}
else
*/
if (pTexture->LockRect( D3DCUBEMAP_FACE_POSITIVE_X, 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 1\n");
if (pTexture->GetCubeMapSurface( D3DCUBEMAP_FACE_POSITIVE_X, 0, &pResolvedSurface)!=D3D_OK)
{
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel\n");
return (RETURN_LockRect_FAILED);
}
if (pResolvedSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
pResolvedSurface->Release();
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 2\n");
return (RETURN_LockRect_FAILED);
}
}
int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height)/8;
hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
/*
if (pOffscreenSurface!=NULL)
{
pOffscreenSurface->UnlockRect();
pOffscreenSurface->Release();
//pOffscreenTexture->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
}
else
*/
if (pResolvedSurface!=NULL)
{
pResolvedSurface->UnlockRect();
pResolvedSurface->Release();
}
else
{
pTexture->UnlockRect( D3DCUBEMAP_FACE_POSITIVE_X, 0); //unlock the raw data
}
Message("uMod_IDirect3DCubeTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
return (RETURN_OK);
}
-126
View File
@@ -1,126 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* BIG THANKS TO Matthew L (Azorbix)
* (Direct3D StarterKit v3.0)
*
*/
#ifndef uMod_IDirect3DCubeTexture9_H
#define uMod_IDirect3DCubeTexture9_H
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_Defines.h"
interface uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9
{
uMod_IDirect3DCubeTexture9(IDirect3DCubeTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9)
{
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
m_D3Ddev = pIDirect3DDevice9; //device pointer
CrossRef_D3Dtex = NULL; //cross reference
// fake texture: store the pointer to the original uMod_IDirect3DCubeTexture9 object, needed if a fake texture is unselected
// original texture: stores the pointer to the fake texture object, is needed if original texture is deleted,
// thus the fake texture can also be deleted
Reference = -1; //need for fast deleting
Hash = 0u;
FAKE = false;
}
// callback interface
IDirect3DCubeTexture9 *m_D3Dtex;
uMod_IDirect3DCubeTexture9 *CrossRef_D3Dtex;
IDirect3DDevice9 *m_D3Ddev;
int Reference;
MyTypeHash Hash;
bool FAKE;
// original interface
STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj);
STDMETHOD_(ULONG,AddRef)();
STDMETHOD_(ULONG,Release)();
STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice);
STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags);
STDMETHOD(GetPrivateData)(REFGUID refguid,void* pData,DWORD* pSizeOfData);
STDMETHOD(FreePrivateData)(REFGUID refguid);
STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew);
STDMETHOD_(DWORD, GetPriority)();
STDMETHOD_(void, PreLoad)();
STDMETHOD_(D3DRESOURCETYPE, GetType)();
STDMETHOD_(DWORD, SetLOD)(DWORD LODNew);
STDMETHOD_(DWORD, GetLOD)();
STDMETHOD_(DWORD, GetLevelCount)();
STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType);
STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)();
STDMETHOD_(void, GenerateMipSubLevels)();
STDMETHOD(AddDirtyRect)(D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect);
STDMETHOD(GetLevelDesc)(UINT Level, D3DSURFACE_DESC *pDesc);
STDMETHOD(GetCubeMapSurface)(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9 **ppCubeMapSurface);
STDMETHOD(LockRect)( D3DCUBEMAP_FACES FaceType, UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
STDMETHOD(UnlockRect)(D3DCUBEMAP_FACES FaceType, UINT Level);
int GetHash(MyTypeHash &hash);
};
inline void UnswitchTextures(uMod_IDirect3DCubeTexture9 *pTexture)
{
uMod_IDirect3DCubeTexture9* CrossRef = pTexture->CrossRef_D3Dtex;
if (CrossRef!=NULL)
{
// switch textures back
IDirect3DCubeTexture9* cpy = pTexture->m_D3Dtex;
pTexture->m_D3Dtex = CrossRef->m_D3Dtex;
CrossRef->m_D3Dtex = cpy;
// cancel the link
CrossRef->CrossRef_D3Dtex = NULL;
pTexture->CrossRef_D3Dtex = NULL;
}
}
inline int SwitchTextures( uMod_IDirect3DCubeTexture9 *pTexture1, uMod_IDirect3DCubeTexture9 *pTexture2)
{
if (pTexture1->m_D3Ddev == pTexture2->m_D3Ddev && pTexture1->CrossRef_D3Dtex == NULL && pTexture2->CrossRef_D3Dtex == NULL)
{
// make cross reference
pTexture1->CrossRef_D3Dtex = pTexture2;
pTexture2->CrossRef_D3Dtex = pTexture1;
// switch textures
IDirect3DCubeTexture9* cpy = pTexture2->m_D3Dtex;
pTexture2->m_D3Dtex = pTexture1->m_D3Dtex;
pTexture1->m_D3Dtex = cpy;
return (RETURN_OK);
}
else return (RETURN_TEXTURE_NOT_SWITCHED);
}
#endif
File diff suppressed because it is too large Load Diff
-212
View File
@@ -1,212 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* BIG THANKS TO Michael Koch
* (proxydll_9.zip)
*
*/
#ifndef uMod_IDirect3DDevice9_H_
#define uMod_IDirect3DDevice9_H_
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DVolumeTexture9.h"
#include "uMod_IDirect3DCubeTexture9.h"
class uMod_IDirect3DDevice9 : public IDirect3DDevice9
{
public:
uMod_IDirect3DDevice9(IDirect3DDevice9* pOriginal, uMod_TextureServer* server, int back_buffer_count);
virtual ~uMod_IDirect3DDevice9(void);
// START: The original DX9 function definitions
HRESULT __stdcall QueryInterface (REFIID riid, void** ppvObj);
ULONG __stdcall AddRef(void);
ULONG __stdcall Release(void);
HRESULT __stdcall TestCooperativeLevel(void);
UINT __stdcall GetAvailableTextureMem(void);
HRESULT __stdcall EvictManagedResources(void);
HRESULT __stdcall GetDirect3D(IDirect3D9** ppD3D9);
HRESULT __stdcall GetDeviceCaps(D3DCAPS9* pCaps);
HRESULT __stdcall GetDisplayMode(UINT iSwapChain,D3DDISPLAYMODE* pMode);
HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters);
HRESULT __stdcall SetCursorProperties(UINT XHotSpot,UINT YHotSpot,IDirect3DSurface9* pCursorBitmap);
void __stdcall SetCursorPosition(int X,int Y,DWORD Flags);
BOOL __stdcall ShowCursor(BOOL bShow);
HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain9** pSwapChain) ;
HRESULT __stdcall GetSwapChain(UINT iSwapChain,IDirect3DSwapChain9** pSwapChain);
UINT __stdcall GetNumberOfSwapChains(void);
HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters);
HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
HRESULT __stdcall GetBackBuffer(UINT iSwapChain,UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer);
HRESULT __stdcall GetRasterStatus(UINT iSwapChain,D3DRASTER_STATUS* pRasterStatus);
HRESULT __stdcall SetDialogBoxMode(BOOL bEnableDialogs);
void __stdcall SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp);
void __stdcall GetGammaRamp(UINT iSwapChain,D3DGAMMARAMP* pRamp);
HRESULT __stdcall CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,HANDLE* pSharedHandle);
HRESULT __stdcall CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,HANDLE* pSharedHandle);
HRESULT __stdcall CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall UpdateSurface(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint);
HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture9* pSourceTexture,IDirect3DBaseTexture9* pDestinationTexture);
HRESULT __stdcall GetRenderTargetData(IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface);
HRESULT __stdcall GetFrontBufferData(UINT iSwapChain,IDirect3DSurface9* pDestSurface);
HRESULT __stdcall StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter);
HRESULT __stdcall ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect,D3DCOLOR color);
HRESULT __stdcall CreateOffscreenPlainSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall SetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget);
HRESULT __stdcall GetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget);
HRESULT __stdcall SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil);
HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface);
HRESULT __stdcall BeginScene(void);
HRESULT __stdcall EndScene(void);
HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix);
HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
HRESULT __stdcall SetViewport(CONST D3DVIEWPORT9* pViewport);
HRESULT __stdcall GetViewport(D3DVIEWPORT9* pViewport);
HRESULT __stdcall SetMaterial(CONST D3DMATERIAL9* pMaterial);
HRESULT __stdcall GetMaterial(D3DMATERIAL9* pMaterial);
HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT9* pLight);
HRESULT __stdcall GetLight(DWORD Index,D3DLIGHT9* pLight);
HRESULT __stdcall LightEnable(DWORD Index,BOOL Enable);
HRESULT __stdcall GetLightEnable(DWORD Index,BOOL* pEnable);
HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane);
HRESULT __stdcall GetClipPlane(DWORD Index,float* pPlane);
HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State,DWORD Value);
HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State,DWORD* pValue);
HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type,IDirect3DStateBlock9** ppSB);
HRESULT __stdcall BeginStateBlock(void);
HRESULT __stdcall EndStateBlock(IDirect3DStateBlock9** ppSB);
HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS9* pClipStatus);
HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS9* pClipStatus);
HRESULT __stdcall GetTexture(DWORD Stage,IDirect3DBaseTexture9** ppTexture);
HRESULT __stdcall SetTexture(DWORD Stage,IDirect3DBaseTexture9* pTexture);
HRESULT __stdcall GetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue);
HRESULT __stdcall SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value);
HRESULT __stdcall GetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD* pValue);
HRESULT __stdcall SetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value);
HRESULT __stdcall ValidateDevice(DWORD* pNumPasses);
HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries);
HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber,PALETTEENTRY* pEntries);
HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber);
HRESULT __stdcall GetCurrentTexturePalette(UINT *PaletteNumber);
HRESULT __stdcall SetScissorRect(CONST RECT* pRect);
HRESULT __stdcall GetScissorRect( RECT* pRect);
HRESULT __stdcall SetSoftwareVertexProcessing(BOOL bSoftware);
BOOL __stdcall GetSoftwareVertexProcessing(void);
HRESULT __stdcall SetNPatchMode(float nSegments);
float __stdcall GetNPatchMode(void);
HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount);
HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
HRESULT __stdcall ProcessVertices(UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer9* pDestBuffer,IDirect3DVertexDeclaration9* pVertexDecl,DWORD Flags);
HRESULT __stdcall CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl);
HRESULT __stdcall SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl);
HRESULT __stdcall GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl);
HRESULT __stdcall SetFVF(DWORD FVF);
HRESULT __stdcall GetFVF(DWORD* pFVF);
HRESULT __stdcall CreateVertexShader(CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader);
HRESULT __stdcall SetVertexShader(IDirect3DVertexShader9* pShader);
HRESULT __stdcall GetVertexShader(IDirect3DVertexShader9** ppShader);
HRESULT __stdcall SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall GetVertexShaderConstantF(UINT StartRegister,float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall GetVertexShaderConstantI(UINT StartRegister,int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall GetVertexShaderConstantB(UINT StartRegister,BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
HRESULT __stdcall GetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9** ppStreamData,UINT* OffsetInBytes,UINT* pStride);
HRESULT __stdcall SetStreamSourceFreq(UINT StreamNumber,UINT Divider);
HRESULT __stdcall GetStreamSourceFreq(UINT StreamNumber,UINT* Divider);
HRESULT __stdcall SetIndices(IDirect3DIndexBuffer9* pIndexData);
HRESULT __stdcall GetIndices(IDirect3DIndexBuffer9** ppIndexData);
HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader);
HRESULT __stdcall SetPixelShader(IDirect3DPixelShader9* pShader);
HRESULT __stdcall GetPixelShader(IDirect3DPixelShader9** ppShader);
HRESULT __stdcall SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall GetPixelShaderConstantF(UINT StartRegister,float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall GetPixelShaderConstantI(UINT StartRegister,int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall GetPixelShaderConstantB(UINT StartRegister,BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo);
HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo);
HRESULT __stdcall DeletePatch(UINT Handle);
HRESULT __stdcall CreateQuery(D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery);
// END: The original DX9 function definitions
uMod_TextureClient* GetuMod_Client(void) {return (uMod_Client);}
uMod_IDirect3DTexture9* GetLastCreatedTexture(void) {return (LastCreatedTexture);}
int SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture) {LastCreatedTexture=pTexture; return (RETURN_OK);}
uMod_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture(void) {return (LastCreatedVolumeTexture);}
int SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture) {LastCreatedVolumeTexture=pTexture; return (RETURN_OK);}
uMod_IDirect3DCubeTexture9* GetLastCreatedCubeTexture(void) {return (LastCreatedCubeTexture);}
int SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture) {LastCreatedCubeTexture=pTexture; return (RETURN_OK);}
uMod_IDirect3DTexture9* GetSingleTexture(void) {return (SingleTexture);}
uMod_IDirect3DVolumeTexture9* GetSingleVolumeTexture(void) {return (SingleVolumeTexture);}
uMod_IDirect3DCubeTexture9* GetSingleCubeTexture(void) {return (SingleCubeTexture);}
private:
int CreateSingleTexture(void);
IDirect3DDevice9* m_pIDirect3DDevice9;
int CounterSaveSingleTexture;
uMod_IDirect3DTexture9* SingleTexture;
uMod_IDirect3DVolumeTexture9* SingleVolumeTexture;
uMod_IDirect3DCubeTexture9* SingleCubeTexture;
char SingleTextureMod;
D3DCOLOR TextureColour;
ID3DXFont *OSD_Font;
//D3DCOLOR FontColour;
int BackBufferCount;
bool NormalRendering;
int uMod_Reference;
uMod_IDirect3DTexture9* LastCreatedTexture;
uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture;
uMod_IDirect3DCubeTexture9* LastCreatedCubeTexture;
uMod_TextureServer* uMod_Server;
uMod_TextureClient* uMod_Client;
};
#endif
-116
View File
@@ -1,116 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
#define uMod_IDirect3DDevice9 uMod_IDirect3DDevice9Ex
#define IDirect3DDevice9 IDirect3DDevice9Ex
#define m_pIDirect3DDevice9 m_pIDirect3DDevice9Ex
#define RETURN_QueryInterface 0x01000001L
#define PRE_MESSAGE "uMod_IDirect3DDevice9Ex"
#include "uMod_IDirect3DDevice9.cpp"
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CheckDeviceState( HWND hWindow)
{
return(m_pIDirect3DDevice9Ex->CheckDeviceState( hWindow));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CheckResourceResidency( IDirect3DResource9 **ppResourceArray, UINT32 NumResources)
{
return(m_pIDirect3DDevice9Ex->CheckResourceResidency( ppResourceArray, NumResources));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::ComposeRects( IDirect3DSurface9 *pSource, IDirect3DSurface9 *pDestination, IDirect3DVertexBuffer9 *pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescriptors, D3DCOMPOSERECTSOP Operation, INT XOffset, INT YOffset)
{
return(m_pIDirect3DDevice9Ex->ComposeRects( pSource, pDestination, pSrcRectDescriptors, NumRects, pDstRectDescriptors, Operation, XOffset, YOffset));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateDepthStencilSurfaceEx( UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage)
{
return(m_pIDirect3DDevice9Ex->CreateDepthStencilSurfaceEx( Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle, Usage));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateOffscreenPlainSurfaceEx( UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage)
{
return(m_pIDirect3DDevice9Ex->CreateOffscreenPlainSurfaceEx( Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::CreateRenderTargetEx( UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage)
{
return(m_pIDirect3DDevice9Ex->CreateRenderTargetEx( Width, Height, Format, MultiSample, MultisampleQuality, Lockable, ppSurface, pSharedHandle, Usage));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetDisplayModeEx( UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation)
{
return(m_pIDirect3DDevice9Ex->GetDisplayModeEx( iSwapChain, pMode, pRotation));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetGPUThreadPriority( INT *pPriority)
{
return(m_pIDirect3DDevice9Ex->GetGPUThreadPriority( pPriority));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::GetMaximumFrameLatency( UINT *pMaxLatency)
{
return(m_pIDirect3DDevice9Ex->GetMaximumFrameLatency( pMaxLatency));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::PresentEx( const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion, DWORD dwFlags)
{
return(m_pIDirect3DDevice9Ex->PresentEx( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::ResetEx( D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode)
{
return(m_pIDirect3DDevice9Ex->ResetEx( pPresentationParameters, pFullscreenDisplayMode));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetConvolutionMonoKernel( UINT Width, UINT Height, float *RowWeights, float *ColumnWeights)
{
return(m_pIDirect3DDevice9Ex->SetConvolutionMonoKernel( Width, Height, RowWeights, ColumnWeights));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetGPUThreadPriority( INT pPriority)
{
return(m_pIDirect3DDevice9Ex->SetGPUThreadPriority( pPriority));
}
HRESULT __stdcall uMod_IDirect3DDevice9Ex::SetMaximumFrameLatency( UINT pMaxLatency)
{
return(m_pIDirect3DDevice9Ex->SetMaximumFrameLatency( pMaxLatency));
}
/*
HRESULT __stdcall uMod_IDirect3DDevice9Ex::TestCooperativeLevel()
{
return(m_pIDirect3DDevice9Ex->TestCooperativeLevel());
}
*/
HRESULT __stdcall uMod_IDirect3DDevice9Ex::WaitForVBlank( UINT SwapChainIndex)
{
return(m_pIDirect3DDevice9Ex->WaitForVBlank( SwapChainIndex));
}
-225
View File
@@ -1,225 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_IDirect3DDevice9Ex_H_
#define uMod_IDirect3DDevice9Ex_H_
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DVolumeTexture9.h"
#include "uMod_IDirect3DCubeTexture9.h"
class uMod_IDirect3DDevice9Ex : public IDirect3DDevice9Ex
{
public:
uMod_IDirect3DDevice9Ex( IDirect3DDevice9Ex* pOriginal, uMod_TextureServer* server, int back_buffer_count);
virtual ~uMod_IDirect3DDevice9Ex(void);
// START: The original DX9 function definitions
HRESULT __stdcall QueryInterface (REFIID riid, void** ppvObj);
ULONG __stdcall AddRef(void);
ULONG __stdcall Release(void);
HRESULT __stdcall TestCooperativeLevel(void);
UINT __stdcall GetAvailableTextureMem(void);
HRESULT __stdcall EvictManagedResources(void);
HRESULT __stdcall GetDirect3D(IDirect3D9** ppD3D9);
HRESULT __stdcall GetDeviceCaps(D3DCAPS9* pCaps);
HRESULT __stdcall GetDisplayMode(UINT iSwapChain,D3DDISPLAYMODE* pMode);
HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters);
HRESULT __stdcall SetCursorProperties(UINT XHotSpot,UINT YHotSpot,IDirect3DSurface9* pCursorBitmap);
void __stdcall SetCursorPosition(int X,int Y,DWORD Flags);
BOOL __stdcall ShowCursor(BOOL bShow);
HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain9** pSwapChain) ;
HRESULT __stdcall GetSwapChain(UINT iSwapChain,IDirect3DSwapChain9** pSwapChain);
UINT __stdcall GetNumberOfSwapChains(void);
HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters);
HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
HRESULT __stdcall GetBackBuffer(UINT iSwapChain,UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer);
HRESULT __stdcall GetRasterStatus(UINT iSwapChain,D3DRASTER_STATUS* pRasterStatus);
HRESULT __stdcall SetDialogBoxMode(BOOL bEnableDialogs);
void __stdcall SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp);
void __stdcall GetGammaRamp(UINT iSwapChain,D3DGAMMARAMP* pRamp);
HRESULT __stdcall CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,HANDLE* pSharedHandle);
HRESULT __stdcall CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,HANDLE* pSharedHandle);
HRESULT __stdcall CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall UpdateSurface(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint);
HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture9* pSourceTexture,IDirect3DBaseTexture9* pDestinationTexture);
HRESULT __stdcall GetRenderTargetData(IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface);
HRESULT __stdcall GetFrontBufferData(UINT iSwapChain,IDirect3DSurface9* pDestSurface);
HRESULT __stdcall StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter);
HRESULT __stdcall ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect,D3DCOLOR color);
HRESULT __stdcall CreateOffscreenPlainSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall SetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget);
HRESULT __stdcall GetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget);
HRESULT __stdcall SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil);
HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface);
HRESULT __stdcall BeginScene(void);
HRESULT __stdcall EndScene(void);
HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix);
HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
HRESULT __stdcall SetViewport(CONST D3DVIEWPORT9* pViewport);
HRESULT __stdcall GetViewport(D3DVIEWPORT9* pViewport);
HRESULT __stdcall SetMaterial(CONST D3DMATERIAL9* pMaterial);
HRESULT __stdcall GetMaterial(D3DMATERIAL9* pMaterial);
HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT9* pLight);
HRESULT __stdcall GetLight(DWORD Index,D3DLIGHT9* pLight);
HRESULT __stdcall LightEnable(DWORD Index,BOOL Enable);
HRESULT __stdcall GetLightEnable(DWORD Index,BOOL* pEnable);
HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane);
HRESULT __stdcall GetClipPlane(DWORD Index,float* pPlane);
HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State,DWORD Value);
HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State,DWORD* pValue);
HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type,IDirect3DStateBlock9** ppSB);
HRESULT __stdcall BeginStateBlock(void);
HRESULT __stdcall EndStateBlock(IDirect3DStateBlock9** ppSB);
HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS9* pClipStatus);
HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS9* pClipStatus);
HRESULT __stdcall GetTexture(DWORD Stage,IDirect3DBaseTexture9** ppTexture);
HRESULT __stdcall SetTexture(DWORD Stage,IDirect3DBaseTexture9* pTexture);
HRESULT __stdcall GetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue);
HRESULT __stdcall SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value);
HRESULT __stdcall GetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD* pValue);
HRESULT __stdcall SetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value);
HRESULT __stdcall ValidateDevice(DWORD* pNumPasses);
HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries);
HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber,PALETTEENTRY* pEntries);
HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber);
HRESULT __stdcall GetCurrentTexturePalette(UINT *PaletteNumber);
HRESULT __stdcall SetScissorRect(CONST RECT* pRect);
HRESULT __stdcall GetScissorRect( RECT* pRect);
HRESULT __stdcall SetSoftwareVertexProcessing(BOOL bSoftware);
BOOL __stdcall GetSoftwareVertexProcessing(void);
HRESULT __stdcall SetNPatchMode(float nSegments);
float __stdcall GetNPatchMode(void);
HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount);
HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
HRESULT __stdcall ProcessVertices(UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer9* pDestBuffer,IDirect3DVertexDeclaration9* pVertexDecl,DWORD Flags);
HRESULT __stdcall CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl);
HRESULT __stdcall SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl);
HRESULT __stdcall GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl);
HRESULT __stdcall SetFVF(DWORD FVF);
HRESULT __stdcall GetFVF(DWORD* pFVF);
HRESULT __stdcall CreateVertexShader(CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader);
HRESULT __stdcall SetVertexShader(IDirect3DVertexShader9* pShader);
HRESULT __stdcall GetVertexShader(IDirect3DVertexShader9** ppShader);
HRESULT __stdcall SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall GetVertexShaderConstantF(UINT StartRegister,float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall GetVertexShaderConstantI(UINT StartRegister,int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall GetVertexShaderConstantB(UINT StartRegister,BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
HRESULT __stdcall GetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9** ppStreamData,UINT* OffsetInBytes,UINT* pStride);
HRESULT __stdcall SetStreamSourceFreq(UINT StreamNumber,UINT Divider);
HRESULT __stdcall GetStreamSourceFreq(UINT StreamNumber,UINT* Divider);
HRESULT __stdcall SetIndices(IDirect3DIndexBuffer9* pIndexData);
HRESULT __stdcall GetIndices(IDirect3DIndexBuffer9** ppIndexData);
HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader);
HRESULT __stdcall SetPixelShader(IDirect3DPixelShader9* pShader);
HRESULT __stdcall GetPixelShader(IDirect3DPixelShader9** ppShader);
HRESULT __stdcall SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall GetPixelShaderConstantF(UINT StartRegister,float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall GetPixelShaderConstantI(UINT StartRegister,int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall GetPixelShaderConstantB(UINT StartRegister,BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo);
HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo);
HRESULT __stdcall DeletePatch(UINT Handle);
HRESULT __stdcall CreateQuery(D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery);
HRESULT __stdcall CheckDeviceState( HWND hWindow);
HRESULT __stdcall CheckResourceResidency( IDirect3DResource9 **pResourceArray, UINT32 NumResources);
HRESULT __stdcall ComposeRects( IDirect3DSurface9 *pSource, IDirect3DSurface9 *pDestination, IDirect3DVertexBuffer9 *pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescriptors, D3DCOMPOSERECTSOP Operation, INT XOffset, INT YOffset);
HRESULT __stdcall CreateDepthStencilSurfaceEx( UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage);
HRESULT __stdcall CreateOffscreenPlainSurfaceEx( UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage);
HRESULT __stdcall CreateRenderTargetEx( UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage);
HRESULT __stdcall GetDisplayModeEx( UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation);
HRESULT __stdcall GetGPUThreadPriority( INT *pPriority);
HRESULT __stdcall GetMaximumFrameLatency( UINT *pMaxLatency);
HRESULT __stdcall PresentEx( const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion, DWORD dwFlags);
HRESULT __stdcall ResetEx( D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode);
HRESULT __stdcall SetConvolutionMonoKernel( UINT Width, UINT Height, float *RowWeights, float *ColumnWeights);
HRESULT __stdcall SetGPUThreadPriority( INT pPriority);
HRESULT __stdcall SetMaximumFrameLatency( UINT pMaxLatency);
//HRESULT __stdcall TestCooperativeLevel();
HRESULT __stdcall WaitForVBlank( UINT SwapChainIndex);
// END: The original DX9 function definitions
uMod_TextureClient* GetuMod_Client(void) {return (uMod_Client);}
uMod_IDirect3DTexture9* GetLastCreatedTexture(void) {return (LastCreatedTexture);}
int SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture) {LastCreatedTexture=pTexture; return (RETURN_OK);}
uMod_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture(void) {return (LastCreatedVolumeTexture);}
int SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture) {LastCreatedVolumeTexture=pTexture; return (RETURN_OK);}
uMod_IDirect3DCubeTexture9* GetLastCreatedCubeTexture(void) {return (LastCreatedCubeTexture);}
int SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture) {LastCreatedCubeTexture=pTexture; return (RETURN_OK);}
uMod_IDirect3DTexture9* GetSingleTexture(void) {return (SingleTexture);}
uMod_IDirect3DVolumeTexture9* GetSingleVolumeTexture(void) {return (SingleVolumeTexture);}
uMod_IDirect3DCubeTexture9* GetSingleCubeTexture(void) {return (SingleCubeTexture);}
private:
int CreateSingleTexture(void);
IDirect3DDevice9Ex* m_pIDirect3DDevice9Ex;
int CounterSaveSingleTexture;
uMod_IDirect3DTexture9* SingleTexture;
uMod_IDirect3DVolumeTexture9* SingleVolumeTexture;
uMod_IDirect3DCubeTexture9* SingleCubeTexture;
char SingleTextureMod;
D3DCOLOR TextureColour;
ID3DXFont *OSD_Font;
//D3DCOLOR FontColour;
int BackBufferCount;
bool NormalRendering;
int uMod_Reference;
uMod_IDirect3DTexture9* LastCreatedTexture;
uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture;
uMod_IDirect3DCubeTexture9* LastCreatedCubeTexture;
uMod_TextureServer* uMod_Server;
uMod_TextureClient* uMod_Client;
};
#endif
-353
View File
@@ -1,353 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* some function (e.g. AddReff()) are presumed to work on the texture object which belong to them
* if this texture was switched, we must redirect this calls to the CrossRef_D3Dtex texture object
*/
#include "uMod_Main.h"
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::QueryInterface(REFIID riid, void** ppvObj)
{
if (riid==IID_IDirect3D9)
{
// This function should never be called with IID_IDirect3D9 by the game
// thus this call comes from our own dll to ask for the texture type
// 0x01000000L == uMod_IDirect3DTexture9
// 0x01000001L == uMod_IDirect3DVolumeTexture9
// 0x01000002L == uMod_IDirect3DCubeTexture9
*ppvObj = this;
return (0x01000000L);
}
HRESULT hRes;
if (CrossRef_D3Dtex!=NULL)
{
hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj==CrossRef_D3Dtex->m_D3Dtex) *ppvObj=this;
}
else
{
hRes = m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj==m_D3Dtex) *ppvObj=this;
}
return (hRes);
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DTexture9::AddRef()
{
if (FAKE) return (1); //bug, this case should never happen
if (CrossRef_D3Dtex!=NULL)
{
return (CrossRef_D3Dtex->m_D3Dtex->AddRef());
}
else return (m_D3Dtex->AddRef());
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DTexture9::Release()
{
Message("uMod_IDirect3DTexture9::Release(): %lu\n", this);
void *cpy;
long ret = m_D3Ddev->QueryInterface( IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE)
{
UnswitchTextures( this);
count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures
}
else
{
if (CrossRef_D3Dtex!=NULL) //if this texture is switched with a fake texture
{
uMod_IDirect3DTexture9 *fake_texture = CrossRef_D3Dtex;
count = fake_texture->m_D3Dtex->Release(); //release the original texture
if (count==0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (ret == 0x01000000L)
{
if (((uMod_IDirect3DDevice9*) m_D3Ddev)->GetSingleTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
else
{
if (((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetSingleTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
}
}
else
{
count = m_D3Dtex->Release();
}
}
if (count==0) //if this texture is released, we clean up
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (ret == 0x01000000L)
{
if (((uMod_IDirect3DDevice9*) m_D3Ddev)->GetLastCreatedTexture()==this) ((uMod_IDirect3DDevice9*) m_D3Ddev)->SetLastCreatedTexture( NULL);
else ((uMod_IDirect3DDevice9*) m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
else
{
if (((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetLastCreatedTexture()==this) ((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->SetLastCreatedTexture( NULL);
else ((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
delete(this);
}
Message("uMod_IDirect3DTexture9::Release() end: %lu\n", this);
return (count);
}
HRESULT APIENTRY uMod_IDirect3DTexture9::GetDevice(IDirect3DDevice9** ppDevice)
{
*ppDevice = m_D3Ddev;
return D3D_OK;
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::SetPrivateData(REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags));
return (m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::GetPrivateData(REFGUID refguid,void* pData,DWORD* pSizeOfData)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData));
return (m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::FreePrivateData(REFGUID refguid)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid));
return (m_D3Dtex->FreePrivateData(refguid));
}
DWORD APIENTRY uMod_IDirect3DTexture9::SetPriority(DWORD PriorityNew)
{
return (m_D3Dtex->SetPriority(PriorityNew));
}
DWORD APIENTRY uMod_IDirect3DTexture9::GetPriority()
{
return (m_D3Dtex->GetPriority());
}
void APIENTRY uMod_IDirect3DTexture9::PreLoad()
{
m_D3Dtex->PreLoad();
}
D3DRESOURCETYPE APIENTRY uMod_IDirect3DTexture9::GetType()
{
return (m_D3Dtex->GetType());
}
DWORD APIENTRY uMod_IDirect3DTexture9::SetLOD(DWORD LODNew)
{
return (m_D3Dtex->SetLOD(LODNew));
}
DWORD APIENTRY uMod_IDirect3DTexture9::GetLOD()
{
return (m_D3Dtex->GetLOD());
}
DWORD APIENTRY uMod_IDirect3DTexture9::GetLevelCount()
{
return (m_D3Dtex->GetLevelCount());
}
HRESULT APIENTRY uMod_IDirect3DTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType)
{
return (m_D3Dtex->SetAutoGenFilterType(FilterType));
}
D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DTexture9::GetAutoGenFilterType()
{
return (m_D3Dtex->GetAutoGenFilterType());
}
void APIENTRY uMod_IDirect3DTexture9::GenerateMipSubLevels()
{
m_D3Dtex->GenerateMipSubLevels();
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc));
return (m_D3Dtex->GetLevelDesc(Level, pDesc));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::GetSurfaceLevel(UINT Level,IDirect3DSurface9** ppSurfaceLevel)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetSurfaceLevel(Level, ppSurfaceLevel));
return (m_D3Dtex->GetSurfaceLevel(Level, ppSurfaceLevel));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::LockRect(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->LockRect(Level, pLockedRect, pRect, Flags));
return (m_D3Dtex->LockRect(Level, pLockedRect, pRect, Flags));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::UnlockRect(UINT Level)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->UnlockRect(Level));
return (m_D3Dtex->UnlockRect(Level));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DTexture9::AddDirtyRect(CONST RECT* pDirtyRect)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->AddDirtyRect(pDirtyRect));
return (m_D3Dtex->AddDirtyRect(pDirtyRect));
}
int uMod_IDirect3DTexture9::GetHash(MyTypeHash &hash)
{
hash=0u;
if (FAKE) return (RETURN_BAD_ARGUMENT);
IDirect3DTexture9 *pTexture = m_D3Dtex;
if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex;
IDirect3DSurface9 *pOffscreenSurface = NULL;
//IDirect3DTexture9 *pOffscreenTexture = NULL;
IDirect3DSurface9 *pResolvedSurface = NULL;
D3DLOCKED_RECT d3dlr;
D3DSURFACE_DESC desc;
if (pTexture->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture
{
Message("uMod_IDirect3DTexture9::GetHash() Failed: GetLevelDesc \n");
return (RETURN_GetLevelDesc_FAILED);
}
Message("uMod_IDirect3DTexture9::GetHash() (%d %d) %d\n", desc.Width, desc.Height, desc.Format);
if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture
{
//Message("uMod_IDirect3DTexture9::GetHash() (D3DPOOL_DEFAULT)\n");
IDirect3DSurface9 *pSurfaceLevel_orig = NULL;
if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK)
{
Message("uMod_IDirect3DTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE)
{
//Message("uMod_IDirect3DTexture9::GetHash() MultiSampleType\n");
if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig = pResolvedSurface;
}
if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n");
return (RETURN_TEXTURE_NOT_LOADED);
}
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig->Release();
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
}
else if (pTexture->LockRect( 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
Message("uMod_IDirect3DTexture9::GetHash() Failed: LockRect 1\n");
if (pTexture->GetSurfaceLevel(0, &pResolvedSurface)!=D3D_OK)
{
Message("uMod_IDirect3DTexture9::GetHash() Failed: GetSurfaceLevel\n");
return (RETURN_LockRect_FAILED);
}
if (pResolvedSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
pResolvedSurface->Release();
Message("uMod_IDirect3DTexture9::GetHash() Failed: LockRect 2\n");
return (RETURN_LockRect_FAILED);
}
}
int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height)/8;
hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
if (pOffscreenSurface!=NULL)
{
pOffscreenSurface->UnlockRect();
pOffscreenSurface->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
}
else if (pResolvedSurface!=NULL)
{
pResolvedSurface->UnlockRect();
pResolvedSurface->Release();
}
else pTexture->UnlockRect(0);
Message("uMod_IDirect3DTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
return (RETURN_OK);
}
-124
View File
@@ -1,124 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* BIG THANKS TO Matthew L (Azorbix)
* (Direct3D StarterKit v3.0)
*
*/
#ifndef uMod_IDirect3DTexture9_H
#define uMod_IDirect3DTexture9_H
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_Defines.h"
interface uMod_IDirect3DTexture9 : public IDirect3DTexture9
{
uMod_IDirect3DTexture9(IDirect3DTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9)
{
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
m_D3Ddev = pIDirect3DDevice9; //device pointer
CrossRef_D3Dtex = NULL; //cross reference
// fake texture: store the pointer to the original uMod_IDirect3DTexture9 object, needed if a fake texture is unselected
// original texture: stores the pointer to the fake texture object, is needed if original texture is deleted,
// thus the fake texture can also be deleted
Reference = -1; //need for fast deleting
Hash = 0u;
FAKE = false;
}
// callback interface
IDirect3DTexture9 *m_D3Dtex;
uMod_IDirect3DTexture9 *CrossRef_D3Dtex;
IDirect3DDevice9 *m_D3Ddev;
int Reference;
MyTypeHash Hash;
bool FAKE;
// original interface
STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj);
STDMETHOD_(ULONG,AddRef)();
STDMETHOD_(ULONG,Release)();
STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice);
STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags);
STDMETHOD(GetPrivateData)(REFGUID refguid,void* pData,DWORD* pSizeOfData);
STDMETHOD(FreePrivateData)(REFGUID refguid);
STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew);
STDMETHOD_(DWORD, GetPriority)();
STDMETHOD_(void, PreLoad)();
STDMETHOD_(D3DRESOURCETYPE, GetType)();
STDMETHOD_(DWORD, SetLOD)(DWORD LODNew);
STDMETHOD_(DWORD, GetLOD)();
STDMETHOD_(DWORD, GetLevelCount)();
STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType);
STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)();
STDMETHOD_(void, GenerateMipSubLevels)();
STDMETHOD(GetLevelDesc)(UINT Level,D3DSURFACE_DESC *pDesc);
STDMETHOD(GetSurfaceLevel)(UINT Level,IDirect3DSurface9** ppSurfaceLevel);
STDMETHOD(LockRect)(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
STDMETHOD(UnlockRect)(UINT Level);
STDMETHOD(AddDirtyRect)(CONST RECT* pDirtyRect);
int GetHash(MyTypeHash &hash);
};
inline void UnswitchTextures(uMod_IDirect3DTexture9 *pTexture)
{
uMod_IDirect3DTexture9* CrossRef = pTexture->CrossRef_D3Dtex;
if (CrossRef!=NULL)
{
// switch textures back
IDirect3DTexture9* cpy = pTexture->m_D3Dtex;
pTexture->m_D3Dtex = CrossRef->m_D3Dtex;
CrossRef->m_D3Dtex = cpy;
// cancel the link
CrossRef->CrossRef_D3Dtex = NULL;
pTexture->CrossRef_D3Dtex = NULL;
}
}
inline int SwitchTextures( uMod_IDirect3DTexture9 *pTexture1, uMod_IDirect3DTexture9 *pTexture2)
{
if (pTexture1->m_D3Ddev == pTexture2->m_D3Ddev && pTexture1->CrossRef_D3Dtex == NULL && pTexture2->CrossRef_D3Dtex == NULL)
{
// make cross reference
pTexture1->CrossRef_D3Dtex = pTexture2;
pTexture2->CrossRef_D3Dtex = pTexture1;
// switch textures
IDirect3DTexture9* cpy = pTexture2->m_D3Dtex;
pTexture2->m_D3Dtex = pTexture1->m_D3Dtex;
pTexture1->m_D3Dtex = cpy;
return (RETURN_OK);
}
else return (RETURN_TEXTURE_NOT_SWITCHED);
}
#endif
-385
View File
@@ -1,385 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* some function (e.g. AddReff()) are presumed to work on the texture object which belong to them
* if this texture was switched, we must redirect this calls to the CrossRef_D3Dtex texture object
*/
#include "uMod_Main.h"
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::QueryInterface(REFIID riid, void** ppvObj)
{
if (riid==IID_IDirect3D9)
{
// This function should never be called with IID_IDirect3D9 by the game
// thus this call comes from our own dll to ask for the texture type
// 0x01000000L == uMod_IDirect3DTexture9
// 0x01000001L == uMod_IDirect3DVolumeTexture9
// 0x01000002L == uMod_IDirect3DCubeTexture9
*ppvObj = this;
return (0x01000001L);
}
HRESULT hRes;
if (CrossRef_D3Dtex!=NULL)
{
hRes = CrossRef_D3Dtex->m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj==CrossRef_D3Dtex->m_D3Dtex) *ppvObj=this;
}
else
{
hRes = m_D3Dtex->QueryInterface(riid, ppvObj);
if (*ppvObj==m_D3Dtex) *ppvObj=this;
}
return (hRes);
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DVolumeTexture9::AddRef()
{
if (FAKE) return (1); //bug, this case should never happen
if (CrossRef_D3Dtex!=NULL)
{
return (CrossRef_D3Dtex->m_D3Dtex->AddRef());
}
else return (m_D3Dtex->AddRef());
}
//this function yields for the non switched texture object
ULONG APIENTRY uMod_IDirect3DVolumeTexture9::Release()
{
Message("uMod_IDirect3DVolumeTexture9::Release(): %lu\n", this);
void *cpy;
long ret = m_D3Ddev->QueryInterface( IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE)
{
UnswitchTextures( this);
count = m_D3Dtex->Release(); //count must be zero, cause we don't call AddRef of fake_textures
}
else
{
if (CrossRef_D3Dtex!=NULL) //if this texture is switched with a fake texture
{
uMod_IDirect3DVolumeTexture9 *fake_texture = CrossRef_D3Dtex;
count = fake_texture->m_D3Dtex->Release(); //release the original texture
if (count==0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (ret == 0x01000000L)
{
if (((uMod_IDirect3DDevice9*) m_D3Ddev)->GetSingleVolumeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
else
{
if (((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetSingleVolumeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
}
}
else
{
count = m_D3Dtex->Release();
}
}
if (count==0) //if this texture is released, we clean up
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (ret == 0x01000000L)
{
if (((uMod_IDirect3DDevice9*) m_D3Ddev)->GetLastCreatedVolumeTexture()==this) ((uMod_IDirect3DDevice9*) m_D3Ddev)->SetLastCreatedVolumeTexture( NULL);
else ((uMod_IDirect3DDevice9*) m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
else
{
if (((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetLastCreatedVolumeTexture()==this) ((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->SetLastCreatedVolumeTexture( NULL);
else ((uMod_IDirect3DDevice9Ex*) m_D3Ddev)->GetuMod_Client()->RemoveTexture(this); // remove this texture from the texture client
}
delete(this);
}
return (count);
}
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetDevice(IDirect3DDevice9** ppDevice)
{
*ppDevice = m_D3Ddev;
return D3D_OK;
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::SetPrivateData(REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags));
return (m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetPrivateData(REFGUID refguid,void* pData,DWORD* pSizeOfData)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData));
return (m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::FreePrivateData(REFGUID refguid)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->FreePrivateData(refguid));
return (m_D3Dtex->FreePrivateData(refguid));
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::SetPriority(DWORD PriorityNew)
{
return (m_D3Dtex->SetPriority(PriorityNew));
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetPriority()
{
return (m_D3Dtex->GetPriority());
}
void APIENTRY uMod_IDirect3DVolumeTexture9::PreLoad()
{
m_D3Dtex->PreLoad();
}
D3DRESOURCETYPE APIENTRY uMod_IDirect3DVolumeTexture9::GetType()
{
return (m_D3Dtex->GetType());
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::SetLOD(DWORD LODNew)
{
return (m_D3Dtex->SetLOD(LODNew));
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetLOD()
{
return (m_D3Dtex->GetLOD());
}
DWORD APIENTRY uMod_IDirect3DVolumeTexture9::GetLevelCount()
{
return (m_D3Dtex->GetLevelCount());
}
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType)
{
return (m_D3Dtex->SetAutoGenFilterType(FilterType));
}
D3DTEXTUREFILTERTYPE APIENTRY uMod_IDirect3DVolumeTexture9::GetAutoGenFilterType()
{
return (m_D3Dtex->GetAutoGenFilterType());
}
void APIENTRY uMod_IDirect3DVolumeTexture9::GenerateMipSubLevels()
{
m_D3Dtex->GenerateMipSubLevels();
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::AddDirtyBox(CONST D3DBOX *pDirtyBox)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->AddDirtyBox(pDirtyBox));
return (m_D3Dtex->AddDirtyBox(pDirtyBox));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetLevelDesc(UINT Level, D3DVOLUME_DESC *pDesc)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetLevelDesc(Level, pDesc));
return (m_D3Dtex->GetLevelDesc(Level, pDesc));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::GetVolumeLevel(UINT Level, IDirect3DVolume9 **ppVolumeLevel)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->GetVolumeLevel(Level, ppVolumeLevel));
return (m_D3Dtex->GetVolumeLevel(Level, ppVolumeLevel));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::LockBox(UINT Level, D3DLOCKED_BOX *pLockedVolume, CONST D3DBOX *pBox ,DWORD Flags)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->LockBox(Level, pLockedVolume, pBox, Flags));
return (m_D3Dtex->LockBox(Level, pLockedVolume, pBox, Flags));
}
//this function yields for the non switched texture object
HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::UnlockBox(UINT Level)
{
if (CrossRef_D3Dtex!=NULL) return (CrossRef_D3Dtex->m_D3Dtex->UnlockBox(Level));
return (m_D3Dtex->UnlockBox(Level));
}
int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash &hash)
{
hash=0u;
if (FAKE) return (RETURN_BAD_ARGUMENT);
IDirect3DVolumeTexture9 *pTexture = m_D3Dtex;
if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex;
//IDirect3DVolume9 *pOffscreenSurface = NULL;
//IDirect3DVolumeTexture9 *pOffscreenTexture = NULL;
IDirect3DVolume9 *pResolvedSurface = NULL;
D3DLOCKED_BOX d3dlr;
D3DVOLUME_DESC desc;
if (pTexture->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture
{
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetLevelDesc \n");
return (RETURN_GetLevelDesc_FAILED);
}
Message("uMod_IDirect3DVolumeTexture9::GetHash() (%d %d %d) %d\n", desc.Width, desc.Height, desc.Depth, desc.Format);
/*
if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture
{
//Message("uMod_IDirect3DVolumeTexture9::GetHash() (D3DPOOL_DEFAULT)\n");
IDirect3DSurface9 *pSurfaceLevel_orig = NULL;
if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK)
{
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
/*
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE)
{
//Message("uMod_IDirect3DVolumeTexture9::GetHash() MultiSampleType\n");
if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE ))
{
pSurfaceLevel_orig->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig = pResolvedSurface;
}
*/
//CreateTexture(8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DVolumeTexture9**) &SingleTexture, NULL)
/*
if (D3D_OK!=m_D3Ddev->CreateTexture( desc.Width, desc.Height, 1, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenTexture, NULL))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateTexture (D3DPOOL_DEFAULT)\n");
return (RETURN_TEXTURE_NOT_LOADED);
}
if (pOffscreenTexture->GetSurfaceLevel( 0, &pOffscreenSurface)!=D3D_OK)
{
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel 2 (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
pOffscreenTexture->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig->Release();
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
pOffscreenTexture->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
*/
/*
if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n");
return (RETURN_TEXTURE_NOT_LOADED);
}
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
{
pSurfaceLevel_orig->Release();
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
pSurfaceLevel_orig->Release();
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
pOffscreenSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
return (RETURN_LockRect_FAILED);
}
}
else
*/
if (pTexture->LockBox( 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect 1\n");
if (pTexture->GetVolumeLevel(0, &pResolvedSurface)!=D3D_OK)
{
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel\n");
return (RETURN_LockRect_FAILED);
}
if (pResolvedSurface->LockBox( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
{
pResolvedSurface->Release();
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect 2\n");
return (RETURN_LockRect_FAILED);
}
}
int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height*desc.Depth)/8;
hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
if (pResolvedSurface!=NULL)
{
pResolvedSurface->UnlockBox();
pResolvedSurface->Release();
}
else pTexture->UnlockBox(0);
Message("uMod_IDirect3DVolumeTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
return (RETURN_OK);
}
-125
View File
@@ -1,125 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* BIG THANKS TO Matthew L (Azorbix)
* (Direct3D StarterKit v3.0)
*
*/
#ifndef uMod_IDirect3DVolumeTexture9_H
#define uMod_IDirect3DVolumeTexture9_H
#include <d3d9.h>
#include <d3dx9.h>
#include "uMod_Defines.h"
interface uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9
{
uMod_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9)
{
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
m_D3Ddev = pIDirect3DDevice9; //device pointer
CrossRef_D3Dtex = NULL; //cross reference
// fake texture: store the pointer to the original uMod_IDirect3DVolumeTexture9 object, needed if a fake texture is unselected
// original texture: stores the pointer to the fake texture object, is needed if original texture is deleted,
// thus the fake texture can also be deleted
Reference = -1; //need for fast deleting
Hash = 0u;
FAKE = false;
}
// callback interface
IDirect3DVolumeTexture9 *m_D3Dtex;
uMod_IDirect3DVolumeTexture9 *CrossRef_D3Dtex;
IDirect3DDevice9 *m_D3Ddev;
int Reference;
MyTypeHash Hash;
bool FAKE;
// original interface
STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj);
STDMETHOD_(ULONG,AddRef)();
STDMETHOD_(ULONG,Release)();
STDMETHOD(GetDevice)(IDirect3DDevice9** ppDevice);
STDMETHOD(SetPrivateData)(REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags);
STDMETHOD(GetPrivateData)(REFGUID refguid,void* pData,DWORD* pSizeOfData);
STDMETHOD(FreePrivateData)(REFGUID refguid);
STDMETHOD_(DWORD, SetPriority)(DWORD PriorityNew);
STDMETHOD_(DWORD, GetPriority)();
STDMETHOD_(void, PreLoad)();
STDMETHOD_(D3DRESOURCETYPE, GetType)();
STDMETHOD_(DWORD, SetLOD)(DWORD LODNew);
STDMETHOD_(DWORD, GetLOD)();
STDMETHOD_(DWORD, GetLevelCount)();
STDMETHOD(SetAutoGenFilterType)(D3DTEXTUREFILTERTYPE FilterType);
STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)();
STDMETHOD_(void, GenerateMipSubLevels)();
STDMETHOD(AddDirtyBox)(CONST D3DBOX *pDirtyBox);
STDMETHOD(GetLevelDesc)(UINT Level, D3DVOLUME_DESC *pDesc);
STDMETHOD(GetVolumeLevel)(UINT Level, IDirect3DVolume9 **ppVolumeLevel);
STDMETHOD(LockBox)(UINT Level, D3DLOCKED_BOX *pLockedVolume, CONST D3DBOX *pBox, DWORD Flags);
STDMETHOD(UnlockBox)(UINT Level);
int GetHash(MyTypeHash &hash);
};
inline void UnswitchTextures(uMod_IDirect3DVolumeTexture9 *pTexture)
{
uMod_IDirect3DVolumeTexture9* CrossRef = pTexture->CrossRef_D3Dtex;
if (CrossRef!=NULL)
{
// switch textures back
IDirect3DVolumeTexture9* cpy = pTexture->m_D3Dtex;
pTexture->m_D3Dtex = CrossRef->m_D3Dtex;
CrossRef->m_D3Dtex = cpy;
// cancel the link
CrossRef->CrossRef_D3Dtex = NULL;
pTexture->CrossRef_D3Dtex = NULL;
}
}
inline int SwitchTextures( uMod_IDirect3DVolumeTexture9 *pTexture1, uMod_IDirect3DVolumeTexture9 *pTexture2)
{
if (pTexture1->m_D3Ddev == pTexture2->m_D3Ddev && pTexture1->CrossRef_D3Dtex == NULL && pTexture2->CrossRef_D3Dtex == NULL)
{
// make cross reference
pTexture1->CrossRef_D3Dtex = pTexture2;
pTexture2->CrossRef_D3Dtex = pTexture1;
// switch textures
IDirect3DVolumeTexture9* cpy = pTexture2->m_D3Dtex;
pTexture2->m_D3Dtex = pTexture1->m_D3Dtex;
pTexture1->m_D3Dtex = cpy;
return (RETURN_OK);
}
else return (RETURN_TEXTURE_NOT_SWITCHED);
}
#endif
-66
View File
@@ -1,66 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_MAIN_H_
#define uMod_MAIN_H_
#define WINVER _WIN32_WINNT_WINXP
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define _WIN32_WINDOWS _WIN32_WINNT_WINXP
#define NTDDI_VERSION NTDDI_WINXP
//#define NTDDI_LONGHORN NTDDI_WINXP
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <cstdlib>
#include <cstdio>
#include <d3d9.h>
#include <d3dx9.h>
#include "../uMod_GlobalDefines.h"
#include "../uMod_Error.h"
#include "uMod_Defines.h"
#include "uMod_DX9_dll.h"
#include "uMod_TextureFunction.h"
#include "uMod_IDirect3D9.h"
#include "uMod_IDirect3D9Ex.h"
#include "uMod_IDirect3DDevice9.h"
#include "uMod_IDirect3DDevice9Ex.h"
#include "uMod_IDirect3DCubeTexture9.h"
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DVolumeTexture9.h"
#include "uMod_ArrayHandler.h"
#include "uMod_TextureServer.h"
#include "uMod_TextureClient.h"
extern unsigned int gl_ErrorState;
#endif
-863
View File
@@ -1,863 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
uMod_TextureClient::uMod_TextureClient(uMod_TextureServer* server, IDirect3DDevice9* device)
{
Message("uMod_TextureClient::uMod_TextureClient(void): %lu\n", this);
Server = server;
D3D9Device = device;
BoolSaveAllTextures = false;
BoolSaveSingleTexture = false;
KeyBack = 0;
KeySave = 0;
KeyNext = 0;
SavePath[0]=0;
GameName[0]=0;
NumberToMod = 0;
FileToMod = NULL;
if (Server!=NULL)
{
if (Server->AddClient( this, &FileToMod, &NumberToMod))
{
Server=NULL;
NumberToMod = 0;
FileToMod = NULL;
}
else
{
for (int i=0; i<NumberToMod; i++) {FileToMod[i].NumberOfTextures=0; FileToMod[i].Textures = NULL;}
}
}
Mutex = CreateMutex(NULL, false, NULL);
Update = NULL;
NumberOfUpdate = -1;
FontColour = D3DCOLOR_ARGB(255,255,0,0);
TextureColour = D3DCOLOR_ARGB(255,0,255,0);
}
uMod_TextureClient::~uMod_TextureClient(void)
{
Message("uMod_TextureClient::~uMod_TextureClient(void): %lu\n", this);
if (Server!=NULL) Server->RemoveClient(this);
if (Mutex!=NULL) CloseHandle(Mutex);
if (Update!=NULL) delete [] Update;
if (FileToMod!=NULL)
{
for (int i=0; i<NumberToMod; i++) if (FileToMod[i].Textures!=NULL) delete [] FileToMod[i].Textures;
delete [] FileToMod;
}
}
int uMod_TextureClient::AddTexture( uMod_IDirect3DTexture9* pTexture)
{
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
if (pTexture->FAKE) return (RETURN_OK); // this is a fake texture
Message("uMod_TextureClient::AddTexture( %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
MyTypeHash hash;
if (int ret = pTexture->GetHash( hash)) return (ret);
pTexture->Hash = hash;
if (BoolSaveAllTextures) SaveTexture(pTexture);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
OriginalTextures.Add( pTexture); // add the texture to the list of original texture
return (LookUpToMod(pTexture)); // check if this texture should be modded
}
int uMod_TextureClient::AddTexture( uMod_IDirect3DVolumeTexture9* pTexture)
{
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
if (pTexture->FAKE) return (RETURN_OK); // this is a fake texture
Message("uMod_TextureClient::AddTexture( Volume: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
MyTypeHash hash;
if (int ret = pTexture->GetHash( hash)) return (ret);
pTexture->Hash = hash;
if (BoolSaveAllTextures) SaveTexture(pTexture);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
OriginalVolumeTextures.Add( pTexture); // add the texture to the list of original texture
return (LookUpToMod(pTexture)); // check if this texture should be modded
}
int uMod_TextureClient::AddTexture( uMod_IDirect3DCubeTexture9* pTexture)
{
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
if (pTexture->FAKE) return (RETURN_OK); // this is a fake texture
Message("uMod_TextureClient::AddTexture( Cube: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
MyTypeHash hash;
if (int ret = pTexture->GetHash( hash)) return (ret);
pTexture->Hash = hash;
if (BoolSaveAllTextures) SaveTexture(pTexture);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
OriginalCubeTextures.Add( pTexture); // add the texture to the list of original texture
return (LookUpToMod(pTexture)); // check if this texture should be modded
}
int uMod_TextureClient::RemoveTexture( uMod_IDirect3DTexture9* pTexture) // is called from a texture, if it is finally released
{
Message("uMod_TextureClient::RemoveTexture( %lu, %#lX): %lu\n", pTexture, pTexture->Hash, this);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
if (pTexture->FAKE)
{
// we need to set the corresponding FileToMod[X].pTexture to NULL, to avoid a link to a non existing texture object
int ref = pTexture->Reference;
if (ref>=0 && ref<NumberToMod)
{
for (int i=0; i<FileToMod[ref].NumberOfTextures; i++) if (FileToMod[ref].Textures[i] == pTexture)
{
FileToMod[ref].NumberOfTextures--;
for (int j=i; j<FileToMod[ref].NumberOfTextures; j++) FileToMod[ref].Textures[j] = FileToMod[ref].Textures[j+1];
FileToMod[ref].Textures[FileToMod[ref].NumberOfTextures] = NULL;
break;
}
}
}
else
{
return (OriginalTextures.Remove( pTexture)); //remove this texture form the list
}
return (RETURN_OK);
}
int uMod_TextureClient::RemoveTexture( uMod_IDirect3DVolumeTexture9* pTexture) // is called from a texture, if it is finally released
{
Message("uMod_TextureClient::RemoveTexture( Volume %lu, %#lX): %lu\n", pTexture, pTexture->Hash, this);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
if (pTexture->FAKE)
{
// we need to set the corresponding FileToMod[X].pTexture to NULL, to avoid a link to a non existing texture object
int ref = pTexture->Reference;
if (ref>=0 && ref<NumberToMod)
{
for (int i=0; i<FileToMod[ref].NumberOfTextures; i++) if (FileToMod[ref].Textures[i] == pTexture)
{
FileToMod[ref].NumberOfTextures--;
for (int j=i; j<FileToMod[ref].NumberOfTextures; j++) FileToMod[ref].Textures[j] = FileToMod[ref].Textures[j+1];
FileToMod[ref].Textures[FileToMod[ref].NumberOfTextures] = NULL;
break;
}
}
}
else
{
return (OriginalVolumeTextures.Remove( pTexture)); //remove this texture form the list
}
return (RETURN_OK);
}
int uMod_TextureClient::RemoveTexture( uMod_IDirect3DCubeTexture9* pTexture) // is called from a texture, if it is finally released
{
Message("uMod_TextureClient::RemoveTexture( Cube %lu, %#lX): %lu\n", pTexture, pTexture->Hash, this);
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
if (pTexture->FAKE)
{
// we need to set the corresponding FileToMod[X].pTexture to NULL, to avoid a link to a non existing texture object
int ref = pTexture->Reference;
if (ref>=0 && ref<NumberToMod)
{
for (int i=0; i<FileToMod[ref].NumberOfTextures; i++) if (FileToMod[ref].Textures[i] == pTexture)
{
FileToMod[ref].NumberOfTextures--;
for (int j=i; j<FileToMod[ref].NumberOfTextures; j++) FileToMod[ref].Textures[j] = FileToMod[ref].Textures[j+1];
FileToMod[ref].Textures[FileToMod[ref].NumberOfTextures] = NULL;
break;
}
}
}
else
{
return (OriginalCubeTextures.Remove( pTexture)); //remove this texture form the list
}
return (RETURN_OK);
}
int uMod_TextureClient::SaveAllTextures(bool val)
{
Message("uMod_TextureClient::SaveAllTextures( %d): %lu\n", val, this);
BoolSaveAllTextures=val;
return (RETURN_OK);
}
int uMod_TextureClient::SaveSingleTexture(bool val)
{
Message("uMod_TextureClient::SaveSingleTexture( %d): %lu\n", val, this);
if (BoolSaveSingleTexture && !val) //if BoolSaveSingleTexture is set to false and was previously true we switch the SingleTexture back
{
uMod_IDirect3DTexture9* pTexture;
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) pTexture = ((uMod_IDirect3DDevice9*)D3D9Device)->GetSingleTexture(); //this texture must no be added twice
else pTexture = ((uMod_IDirect3DDevice9Ex*) D3D9Device)->GetSingleTexture(); //this texture must no be added twice
if (pTexture!=NULL) UnswitchTextures(pTexture);
}
BoolSaveSingleTexture = val;
return (RETURN_OK);
}
int uMod_TextureClient::SetSaveDirectory( wchar_t *dir)
{
Message("uMod_TextureClient::SetSaveDirectory( %ls): %lu\n", dir, this);
int i = 0;
for (i=0; i<MAX_PATH && (dir[i]); i++) SavePath[i] = dir[i];
if (i==MAX_PATH)
{
SavePath[0]=0;
return (RETURN_BAD_ARGUMENT);
}
else SavePath[i]=0;
return (RETURN_OK);
}
int uMod_TextureClient::SetGameName( wchar_t *name)
{
Message("uMod_TextureClient::SetGameName( %ls): %lu\n", name, this);
int i = 0;
for (i=0; i<MAX_PATH && (name[i]); i++) GameName[i] = name[i];
if (i==MAX_PATH)
{
GameName[0]=0;
return (RETURN_BAD_ARGUMENT);
}
else GameName[i]=0;
return (RETURN_OK);
}
int uMod_TextureClient::SaveTexture(uMod_IDirect3DTexture9* pTexture)
{
if (pTexture==NULL) return (RETURN_BAD_ARGUMENT);
if (SavePath[0]==0) {Message("uMod_TextureClient::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);}
wchar_t file[MAX_PATH];
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_T_%#lX.dds", SavePath, GameName, pTexture->Hash);
else swprintf_s( file, MAX_PATH, L"%ls\\T_%#lX.dds", SavePath, pTexture->Hash);
Message("uMod_TextureClient::SaveTexture( %ls): %lu\n", file, this);
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
return (RETURN_OK);
}
int uMod_TextureClient::SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture)
{
if (pTexture==NULL) return (RETURN_BAD_ARGUMENT);
if (SavePath[0]==0) {Message("uMod_TextureClient::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);}
wchar_t file[MAX_PATH];
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_V_%#lX.dds", SavePath, GameName, pTexture->Hash);
else swprintf_s( file, MAX_PATH, L"%ls\\V_%#lX.dds", SavePath, pTexture->Hash);
Message("uMod_TextureClient::SaveTexture( %ls): %lu\n", file, this);
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
return (RETURN_OK);
}
int uMod_TextureClient::SaveTexture(uMod_IDirect3DCubeTexture9* pTexture)
{
if (pTexture==NULL) return (RETURN_BAD_ARGUMENT);
if (SavePath[0]==0) {Message("uMod_TextureClient::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);}
wchar_t file[MAX_PATH];
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_C_%#lX.dds", SavePath, GameName, pTexture->Hash);
else swprintf_s( file, MAX_PATH, L"%ls\\C_%#lX.dds", SavePath, pTexture->Hash);
Message("uMod_TextureClient::SaveTexture( %ls): %lu\n", file, this);
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
return (RETURN_OK);
}
int uMod_TextureClient::AddUpdate(TextureFileStruct* update, int number) //client must delete the update array
{
Message("AddUpdate( %lu, %d): %lu\n", update, number, this);
if (int ret = LockMutex()) {gl_ErrorState |= uMod_ERROR_TEXTURE; return (ret);}
if (Update!=NULL) delete [] Update;
Update = update;
NumberOfUpdate = number;
return (UnlockMutex());
}
int uMod_TextureClient::MergeUpdate(void)
{
if (NumberOfUpdate<0) {return (RETURN_OK);}
if (int ret = LockMutex()) {gl_ErrorState |= uMod_ERROR_TEXTURE ; return (ret);}
Message("MergeUpdate(): %lu\n", this);
for (int i=0; i<NumberOfUpdate; i++) {Update[i].NumberOfTextures=0; Update[i].Textures = NULL;} // this is already done, but safety comes first ^^
int pos_old=0;
int pos_new=0;
int *to_lookup = NULL;
if (NumberOfUpdate>0) to_lookup = new int[NumberOfUpdate];
int num_to_lookup = 0;
/*
* FileToMod contains the old files (textures) which should replace the target textures (if they are loaded by the game)
* Update contains the new files (textures) which should replace the target textures (if they are loaded by the game)
*
* Both arrays (FileToMod and Update) are sorted according to their hash values.
*
* First we go through both arrays linearly and
* 1) take over the old entry if the hash is the same,
* 2) release old fake texture (if target texture exist and is not in the Update)
* 3) or mark newly added fake texture (if they are not in FileToMod)
*/
while (pos_old<NumberToMod && pos_new<NumberOfUpdate)
{
if (FileToMod[pos_old].Hash > Update[pos_new].Hash) // this fake texture is new
{
to_lookup[num_to_lookup++] = pos_new++; // keep this fake texture in mind, we must search later for it through all original textures
// we increase only the new counter by one
}
else if (FileToMod[pos_old].Hash < Update[pos_new].Hash) // this fake texture is not in the update
{
for (int i=FileToMod[pos_old].NumberOfTextures-1; i>=0; i--) FileToMod[pos_old].Textures[i]->Release(); // we release the fake textures
if (FileToMod[pos_old].Textures!=NULL) delete [] FileToMod[pos_old].Textures; // we delete the memory
FileToMod[pos_old].NumberOfTextures = 0;
FileToMod[pos_old].Textures = NULL;
pos_old++; // we increase only the old counter by one
}
else // the hash value is the same, thus this texture is in the array FileToMod as well as in the array Update
{
if (Update[pos_new].ForceReload)
{
if (FileToMod[pos_old].NumberOfTextures>0)
{
Update[pos_new].Textures = new IDirect3DBaseTexture9*[FileToMod[pos_old].NumberOfTextures];
}
for (int i=0; i<FileToMod[pos_old].NumberOfTextures; i++)
{
IDirect3DBaseTexture9 *base_texture;
int ret = FileToMod[pos_old].Textures[i]->QueryInterface( IID_IDirect3D9, (void**)&base_texture);
switch (ret)
{
case 0x01000000L:
{
uMod_IDirect3DTexture9 *pTexture = (uMod_IDirect3DTexture9*) FileToMod[pos_old].Textures[i];//
uMod_IDirect3DTexture9 *pRefTexture = pTexture->CrossRef_D3Dtex;
pTexture->Release();
i--; //after the Release of the old fake texture FileToMod[pos_old].Textures[i] is overwritten by entries with index greater than i
uMod_IDirect3DTexture9 *fake_Texture;
if (int ret = LoadTexture( & (Update[pos_new]), &fake_Texture)) return (ret);
if (SwitchTextures( fake_Texture, pRefTexture))
{
Message("MergeUpdate(): textures not switched %#lX\n", pRefTexture->Hash);
fake_Texture->Release();
}
else
{
Update[pos_new].Textures[Update[pos_new].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = pos_new;
}
break;
}
case 0x01000001L:
{
uMod_IDirect3DVolumeTexture9 *pTexture = (uMod_IDirect3DVolumeTexture9*) FileToMod[pos_old].Textures[i];//
uMod_IDirect3DVolumeTexture9 *pRefTexture = pTexture->CrossRef_D3Dtex;
pTexture->Release();
i--; //after the Release of the old fake texture FileToMod[pos_old].Textures[i] is overwritten by entries with index greater than i
uMod_IDirect3DVolumeTexture9 *fake_Texture;
if (int ret = LoadTexture( & (Update[pos_new]), &fake_Texture)) return (ret);
if (SwitchTextures( fake_Texture, pRefTexture))
{
Message("MergeUpdate(): textures not switched %#lX\n", pRefTexture->Hash);
fake_Texture->Release();
}
else
{
Update[pos_new].Textures[Update[pos_new].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = pos_new;
}
break;
}
case 0x01000002L:
{
uMod_IDirect3DCubeTexture9 *pTexture = (uMod_IDirect3DCubeTexture9*) FileToMod[pos_old].Textures[i];//
uMod_IDirect3DCubeTexture9 *pRefTexture = pTexture->CrossRef_D3Dtex;
pTexture->Release();
i--; //after the Release of the old fake texture FileToMod[pos_old].Textures[i] is overwritten by entries with index greater than i
uMod_IDirect3DCubeTexture9 *fake_Texture;
if (int ret = LoadTexture( & (Update[pos_new]), &fake_Texture)) return (ret);
if (SwitchTextures( fake_Texture, pRefTexture))
{
Message("MergeUpdate(): textures not switched %#lX\n", pRefTexture->Hash);
fake_Texture->Release();
}
else
{
Update[pos_new].Textures[Update[pos_new].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = pos_new;
}
break;
}
default:
break; // this is no fake texture and QueryInterface failed, because IDirect3DBaseTexture9 object cannot be a IDirect3D9 object ;)
}
}
}
else // the texture might be loaded or not
{
Update[pos_new].NumberOfTextures = FileToMod[pos_old].NumberOfTextures;
Update[pos_new].Textures = FileToMod[pos_old].Textures;
FileToMod[pos_old].NumberOfTextures = 0;
FileToMod[pos_old].Textures = NULL;
}
// we increase both counters by one
pos_old++;
pos_new++;
}
}
while (pos_old<NumberToMod) //this fake textures are not in the Update
{
for (int i=FileToMod[pos_old].NumberOfTextures-1; i>=0; i--) FileToMod[pos_old].Textures[i]->Release(); // we release the fake textures
//for (int i=0; i<FileToMod[pos_old].NumberOfTextures; i++) FileToMod[pos_old].Textures[i]->Release(); // we release the fake textures
if (FileToMod[pos_old].Textures!=NULL) delete [] FileToMod[pos_old].Textures; // we delete the memory
FileToMod[pos_old].Textures = NULL;
pos_old++;
}
while (pos_new<NumberOfUpdate) //this fake textures are newly added
{
to_lookup[num_to_lookup++] = pos_new++; //keep this fake texture in mind, we must search later for it through all original textures
}
/*
* if (num_to_lookup>0) we need to look through all original textures
* because there were newly added textures and we don't know
* if the corresponding target textures are loaded by the game or not.
*
* Note: to_lookup[num_to_lookup++] = pos_new++; is in ascending order,
* thus Update[to_lookup[pos]].Hash is also sorted ascending!
*/
/*
uMod_IDirect3DTexture9 *single_texture = ((uMod_IDirect3DDevice9*)D3D9Device)->GetSingleTexture();
if (num_to_lookup>0)
{
int num = OriginalTextures.GetNumber();
for (int i=0; i<num; i++)
if (OriginalTextures[i]->CrossRef_D3Dtex==NULL || OriginalTextures[i]->CrossRef_D3Dtex==single_texture)
// We need look only for textures, that are not switched or switched with the single_texture.
// The single_texture is a special texture, which you can toggle through all original texture, if save single texture is turned on.
{
MyTypeHash hash = OriginalTextures[i]->Hash;
if (hash<Update[to_lookup[0]].Hash || hash>Update[to_lookup[num_to_lookup-1]].Hash) continue;
int index = -1;
int pos = num_to_lookup/2;
int begin = 0;
int end = num_to_lookup-1;
// We look in the middle of the interval and each step we halve the interval,
// unless we find the texture or the size of the interval is less than 3.
// Note: contradicting to normal C-code here the interval includes the index "begin" and "end"!
while (begin+1<end) // as long as the interval is longer than two
{
if (hash > Update[to_lookup[pos]].Hash) // the new interval is the right half of the actual interval
{
begin = pos+1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new intervall
}
else if (hash < Update[to_lookup[pos]].Hash) // the new interval is the left half of the actual interval
{
end = pos-1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new intervall
}
else {index = to_lookup[pos]; break;} // we hit the correct hash
}
if (index<0) // if we did not find the hash, it might be in the last interval
{
for (int i=begin; i<=end; i++) if (Update[to_lookup[i]].Hash==hash) index = to_lookup[i];
}
if (index>=0) // target texture is loaded by the game
{
if (OriginalTextures[i]->CrossRef_D3Dtex!=NULL) UnswitchTextures(OriginalTextures[i]); // this texture was switched with the single texture
uMod_IDirect3DTexture9 *fake_Texture;
if (int ret = LoadTexture( & (Update[index]), &fake_Texture)) return (ret);
if (SwitchTextures( fake_Texture, OriginalTextures[i]))
{
Message("uMod_TextureClient::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
fake_Texture->Release();
}
else
{
IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[Update[index].NumberOfTextures+1];
for (int j=0; j<Update[index].NumberOfTextures; j++) temp[j] = Update[index].Textures[j];
if (Update[index].Textures!=NULL) delete [] Update[index].Textures;
Update[index].Textures = temp;
Update[index].Textures[Update[index].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = index;
}
}
}
}
*/
if (FileToMod!=NULL)
{
//for (int i=0; i<NumberToMod; i++) if (FileToMod[i].Textures!=NULL) delete [] FileToMod[i].Textures;
delete [] FileToMod;
}
FileToMod = Update;
NumberToMod = NumberOfUpdate;
NumberOfUpdate = -1;
Update = NULL;
if (num_to_lookup>0)
{
uMod_IDirect3DTexture9* single_texture;
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) single_texture = ((uMod_IDirect3DDevice9*)D3D9Device)->GetSingleTexture(); //this texture must no be added twice
else single_texture = ((uMod_IDirect3DDevice9Ex*) D3D9Device)->GetSingleTexture(); //this texture must no be added twice
int num = OriginalTextures.GetNumber();
for (int i=0; i<num; i++) if (OriginalTextures[i]->CrossRef_D3Dtex==NULL || OriginalTextures[i]->CrossRef_D3Dtex==single_texture)
{
UnswitchTextures(OriginalTextures[i]); //this we can do always, so we unswitch the single texture
LookUpToMod( OriginalTextures[i], num_to_lookup, to_lookup);
}
uMod_IDirect3DVolumeTexture9 *single_volume_texture;
if (ret == 0x01000000L) single_volume_texture = ((uMod_IDirect3DDevice9*)D3D9Device)->GetSingleVolumeTexture(); //this texture must no be added twice
else single_volume_texture = ((uMod_IDirect3DDevice9Ex*) D3D9Device)->GetSingleVolumeTexture(); //this texture must no be added twice
num = OriginalVolumeTextures.GetNumber();
for (int i=0; i<num; i++) if (OriginalVolumeTextures[i]->CrossRef_D3Dtex==NULL || OriginalVolumeTextures[i]->CrossRef_D3Dtex==single_volume_texture)
{
UnswitchTextures(OriginalVolumeTextures[i]); //this we can do always, so we unswitch the single texture
LookUpToMod( OriginalVolumeTextures[i], num_to_lookup, to_lookup);
}
uMod_IDirect3DCubeTexture9 *single_cube_texture;
if (ret == 0x01000000L) single_cube_texture = ((uMod_IDirect3DDevice9*)D3D9Device)->GetSingleCubeTexture(); //this texture must no be added twice
else single_cube_texture = ((uMod_IDirect3DDevice9Ex*) D3D9Device)->GetSingleCubeTexture(); //this texture must no be added twice
num = OriginalCubeTextures.GetNumber();
for (int i=0; i<num; i++) if (OriginalCubeTextures[i]->CrossRef_D3Dtex==NULL || OriginalCubeTextures[i]->CrossRef_D3Dtex==single_cube_texture)
{
UnswitchTextures(OriginalCubeTextures[i]); //this we can do always, so we unswitch the single texture
LookUpToMod( OriginalCubeTextures[i], num_to_lookup, to_lookup);
}
}
if (to_lookup != NULL) delete [] to_lookup;
return (UnlockMutex());
}
int uMod_TextureClient::LockMutex(void)
{
if (( gl_ErrorState & (uMod_ERROR_FATAL | uMod_ERROR_MUTEX) )) return (RETURN_NO_MUTEX);
if (WAIT_OBJECT_0!=WaitForSingleObject( Mutex, 100)) return (RETURN_MUTEX_LOCK); //waiting 100ms, to wait infinite pass INFINITE
return (RETURN_OK);
}
int uMod_TextureClient::UnlockMutex(void)
{
if (ReleaseMutex(Mutex)==0) return (RETURN_MUTEX_UNLOCK);
return (RETURN_OK);
}
int uMod_TextureClient::LookUpToMod( MyTypeHash hash, int num_index_list, int *index_list)
{
if(NumberToMod>0)
{
if (index_list==NULL || num_index_list==0)
{
if (hash<FileToMod[0].Hash || hash>FileToMod[NumberToMod-1].Hash) return (-1);
int pos = NumberToMod/2;
int begin = 0;
int end = NumberToMod-1;
// We look in the middle of the interval and each step we halve the interval,
// unless we find the texture or the size of the interval is less than 3.
// Note: contradicting to normal C-code here the interval includes the index "begin" and "end"!
while (begin+1<end) // as long as the interval is longer than two
{
if (hash > FileToMod[pos].Hash) // the new interval is the right half of the actual interval
{
begin = pos+1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new interval
}
else if (hash < FileToMod[pos].Hash) // the new interval is the left half of the actual interval
{
end = pos-1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new interval
}
else {return (pos); break;} // we hit the correct hash
}
for ( pos=begin; pos<=end; pos++) if (FileToMod[pos].Hash==hash) return (pos);
}
else
{
if (hash<FileToMod[index_list[0]].Hash || hash>FileToMod[index_list[num_index_list-1]].Hash) return (-1);
int pos = num_index_list/2;
int begin = 0;
int end = num_index_list-1;
// We look in the middle of the interval and each step we halve the interval,
// unless we find the texture or the size of the interval is less than 3.
// Note: contradicting to normal C-code here the interval includes the index "begin" and "end"!
while (begin+1<end) // as long as the interval is longer than two
{
if (hash > FileToMod[index_list[pos]].Hash) // the new interval is the right half of the actual interval
{
begin = pos+1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new interval
}
else if (hash < FileToMod[index_list[pos]].Hash) // the new interval is the left half of the actual interval
{
end = pos-1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new interval
}
else {return (index_list[pos]); break;} // we hit the correct hash
}
for ( pos=begin; pos<=end; pos++) if (FileToMod[index_list[pos]].Hash==hash) return (index_list[pos]);
}
}
return (-1);
}
int uMod_TextureClient::LookUpToMod( uMod_IDirect3DTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures
{
Message("uMod_TextureClient::LookUpToMod( %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched
int index = LookUpToMod( pTexture->Hash, num_index_list, index_list);
if (index>=0)
{
uMod_IDirect3DTexture9 *fake_Texture;
if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret);
if (SwitchTextures( fake_Texture, pTexture))
{
Message("uMod_TextureClient::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
fake_Texture->Release();
}
else
{
IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1];
for (int j=0; j<FileToMod[index].NumberOfTextures; j++) temp[j] = FileToMod[index].Textures[j];
if (FileToMod[index].Textures!=NULL) delete [] FileToMod[index].Textures;
FileToMod[index].Textures = temp;
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = index;
}
}
return (RETURN_OK);
}
int uMod_TextureClient::LookUpToMod( uMod_IDirect3DVolumeTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures
{
Message("uMod_TextureClient::LookUpToMod( Volume %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched
int index = LookUpToMod( pTexture->Hash, num_index_list, index_list);
if (index>=0)
{
uMod_IDirect3DVolumeTexture9 *fake_Texture;
if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret);
if (SwitchTextures( fake_Texture, pTexture))
{
Message("uMod_TextureClient::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
fake_Texture->Release();
}
else
{
IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1];
for (int j=0; j<FileToMod[index].NumberOfTextures; j++) temp[j] = FileToMod[index].Textures[j];
if (FileToMod[index].Textures!=NULL) delete [] FileToMod[index].Textures;
FileToMod[index].Textures = temp;
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = index;
}
}
return (RETURN_OK);
}
int uMod_TextureClient::LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures
{
Message("uMod_TextureClient::LookUpToMod( Cube %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched
int index = LookUpToMod( pTexture->Hash, num_index_list, index_list);
if (index>=0)
{
uMod_IDirect3DCubeTexture9 *fake_Texture;
if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret);
if (SwitchTextures( fake_Texture, pTexture))
{
Message("uMod_TextureClient::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
fake_Texture->Release();
}
else
{
IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1];
for (int j=0; j<FileToMod[index].NumberOfTextures; j++) temp[j] = FileToMod[index].Textures[j];
if (FileToMod[index].Textures!=NULL) delete [] FileToMod[index].Textures;
FileToMod[index].Textures = temp;
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
fake_Texture->Reference = index;
}
}
return (RETURN_OK);
}
int uMod_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9 **ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DTexture9 **) ppTexture))
//if (D3D_OK != D3DXCreateTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DTexture9 **) ppTexture))
{
*ppTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
(*ppTexture)->FAKE = true;
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
Message("LoadTexture( %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return (RETURN_OK);
}
int uMod_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9 **ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( Volume %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DVolumeTexture9 **) ppTexture))
//if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DVolumeTexture9 **) ppTexture))
{
*ppTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
(*ppTexture)->FAKE = true;
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
Message("LoadTexture( Volume %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return (RETURN_OK);
}
int uMod_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9 **ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( Cube %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateCubeTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DCubeTexture9 **) ppTexture))
//if (D3D_OK != D3DXCreateCubeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DCubeTexture9 **) ppTexture))
{
*ppTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
(*ppTexture)->FAKE = true;
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
Message("LoadTexture( Cube %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return (RETURN_OK);
}
-121
View File
@@ -1,121 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_TEXTUREHANDLER_HPP
#define uMod_TEXTUREHANDLER_HPP
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DDevice9.h"
#include "..\uMod_Error.h"
class uMod_TextureServer;
/*
* An object of this class is owned by each d3d9 device.
* functions called by the Server are called from the server thread instance.
* All other functions are called from the render thread instance of the game itself.
*/
class uMod_TextureClient
{
public:
uMod_TextureClient(uMod_TextureServer* server, IDirect3DDevice9* device);
~uMod_TextureClient(void);
int AddTexture( uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DDevice9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
int AddTexture( uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
int AddTexture( uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
int RemoveTexture( uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DTexture9::Release()
int RemoveTexture( uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::Release()
int RemoveTexture( uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::Release()
int SaveAllTextures(bool val); //called from the Server
int SaveSingleTexture(bool val); //called from the Server
int SetSaveDirectory( wchar_t *dir); //called from the Server
int SetGameName( wchar_t *dir); //called from the Server
int SaveTexture(uMod_IDirect3DTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
int SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
int SaveTexture(uMod_IDirect3DCubeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
int SetKeyBack( int key) {if (key>0) KeyBack = key; return (RETURN_OK);} //called from the Server
int SetKeySave( int key) {if (key>0) KeySave = key; return (RETURN_OK);} //called from the Server
int SetKeyNext( int key) {if (key>0) KeyNext = key; return (RETURN_OK);} //called from the Server
int SetFontColour( DWORD r, DWORD g, DWORD b) {FontColour = D3DCOLOR_ARGB(255, r,g,b); return (RETURN_OK);} //called from the Server
int SetTextureColour( DWORD r, DWORD g, DWORD b) {TextureColour = D3DCOLOR_ARGB(255, r,g,b); return (RETURN_OK);} //called from the Server
int AddUpdate(TextureFileStruct* update, int number); //called from the Server, client object must delete update array
int MergeUpdate(void); //called from uMod_IDirect3DDevice9::BeginScene()
int LookUpToMod( uMod_IDirect3DTexture9* pTexture, int num_index_list=0, int *index_list=NULL); // called at the end AddTexture(...) and from Device->UpdateTexture(...)
int LookUpToMod( uMod_IDirect3DVolumeTexture9* pTexture, int num_index_list=0, int *index_list=NULL); // called at the end AddTexture(...) and from Device->UpdateTexture(...)
int LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, int num_index_list=0, int *index_list=NULL); // called at the end AddTexture(...) and from Device->UpdateTexture(...)
uMod_TextureHandler<uMod_IDirect3DTexture9> OriginalTextures; // stores the pointer to the uMod_IDirect3DTexture9 objects created by the game
uMod_TextureHandler<uMod_IDirect3DVolumeTexture9> OriginalVolumeTextures; // stores the pointer to the uMod_IDirect3DVolumeTexture9 objects created by the game
uMod_TextureHandler<uMod_IDirect3DCubeTexture9> OriginalCubeTextures; // stores the pointer to the uMod_IDirect3DCubeTexture9 objects created by the game
bool BoolSaveAllTextures;
bool BoolSaveSingleTexture;
int KeyBack;
int KeySave;
int KeyNext;
D3DCOLOR FontColour;
D3DCOLOR TextureColour;
private:
uMod_TextureServer* Server;
IDirect3DDevice9* D3D9Device;
wchar_t SavePath[MAX_PATH];
wchar_t GameName[MAX_PATH];
TextureFileStruct* Update;
int NumberOfUpdate;
int LockMutex();
int UnlockMutex();
HANDLE Mutex;
int NumberToMod; // number of texture to be modded
TextureFileStruct* FileToMod; // array which stores the file in memory and the hash of each texture to be modded
int LookUpToMod( MyTypeHash hash, int num_index_list, int *index_list); // called from LookUpToMod(...);
int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9 **ppTexture); // called if a target texture is found
int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9 **ppTexture); // called if a target texture is found
int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9 **ppTexture); // called if a target texture is found
// and the corresponding fake texture should be loaded
//MyTypeHash GetHash(unsigned char *str, int len);
//unsigned int GetCRC32(char *pcDatabuf, unsigned int ulDatalen);
};
#endif /* uMod_TEXTUREHANDLER_HPP_ */
-62
View File
@@ -1,62 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
/*
MyTypeHash GetHash(unsigned char *str, int len) // estimate the hash
{
MyTypeHash hash = 0;
for (int i=0; i<len; i++) hash = str[i] + (hash << 6) + (hash << 16) - hash;
return (hash);
}
*/
/*
*
* BIG THANKS TO RS !!
*
* who gave me his hashing algorithm (well or crc32 algorithm^^)
*
The hash function is CRC32 using polynomial 0xEDB88320.
However, the hashed data is calculated incorrectly in TexMod: it's simply BytesPerPixel * Width * Height, from the beginning of the data (that is mapped using LockRect).
The problem is that it doesn't take the pitch into account and BytesPerPixel may be wrong for some rare formats (not sure about that).
*/
#define CRC32POLY 0xEDB88320u /* CRC-32 Polynom */
#define ulCrc_in 0xffffffff
unsigned int GetCRC32( char *pcDatabuf, unsigned int ulDatalen)
{
unsigned int crc = ulCrc_in;
for (unsigned int idx = 0u; idx<ulDatalen; idx++)
{
unsigned int data = *pcDatabuf++;
for (unsigned int bit = 0u; bit<8u; bit++, data >>=1)
{
crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CRC32POLY : 0);
}
}
return (crc);
}
-147
View File
@@ -1,147 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_TEXTUREFUNCTION_H_
#define uMod_TEXTUREFUNCTION_H_
unsigned int GetCRC32( char *pcDatabuf, unsigned int ulDatalen);
/*
case D3DFMT_MULTI2_ARGB8:
case D3DFMT_VERTEXDATA:
*/
inline int GetBitsFromFormat(D3DFORMAT format)
{
switch(format) //switch trough the formats to calculate the size of the raw data
{
case D3DFMT_A1: // 1-bit monochrome.
{
return (1);
break;
}
case D3DFMT_R3G3B2: // 8-bit RGB texture format using 3 bits for red, 3 bits for green, and 2 bits for blue.
case D3DFMT_A8: // 8-bit alpha only.
case D3DFMT_A8P8: // 8-bit color indexed with 8 bits of alpha.
case D3DFMT_P8: // 8-bit color indexed.
case D3DFMT_L8: // 8-bit luminance only.
case D3DFMT_A4L4: // 8-bit using 4 bits each for alpha and luminance.
case D3DFMT_FORCE_DWORD:
case D3DFMT_S8_LOCKABLE: // A lockable 8-bit stencil buffer.
{
return (8);
break;
}
case D3DFMT_D16_LOCKABLE: //16-bit z-buffer bit depth.
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.
case D3DFMT_L6V5U5: // 16-bit bump-map format with luminance using 6 bits for luminance, and 5 bits each for v and u.
case D3DFMT_V8U8: // 16-bit bump-map format using 8 bits each for u and v data.
case D3DFMT_CxV8U8: // 16-bit normal compression format. The texture sampler computes the C channel from: C = sqrt(1 - U2 - V2).
case D3DFMT_R5G6B5: // 16-bit RGB pixel format with 5 bits for red, 6 bits for green, and 5 bits for blue.
case D3DFMT_X1R5G5B5: // 16-bit pixel format where 5 bits are reserved for each color.
case D3DFMT_A1R5G5B5: // 16-bit pixel format where 5 bits are reserved for each color and 1 bit is reserved for alpha.
case D3DFMT_A4R4G4B4: // 16-bit ARGB pixel format with 4 bits for each channel.
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.
case D3DFMT_X4R4G4B4: // 16-bit RGB pixel format using 4 bits for each color.
case D3DFMT_L16: // 16-bit luminance only.
case D3DFMT_R16F: // 16-bit float format using 16 bits for the red channel.
case D3DFMT_A8L8: // 16-bit using 8 bits each for alpha and luminance.
case D3DFMT_D16: // 16-bit z-buffer bit depth.
case D3DFMT_INDEX16: // 16-bit index buffer bit depth.
case D3DFMT_G8R8_G8B8: // ??
case D3DFMT_R8G8_B8G8: // ??
case D3DFMT_UYVY: // ??
case D3DFMT_YUY2: // ??
{
return (16);
break;
}
case D3DFMT_R8G8B8: //24-bit RGB pixel format with 8 bits per channel.
{
return (24);
break;
}
case D3DFMT_R32F: // 32-bit float format using 32 bits for the red channel.
case D3DFMT_X8L8V8U8: // 32-bit bump-map format with luminance using 8 bits for each channel.
case D3DFMT_A2W10V10U10: // 32-bit bump-map format using 2 bits for alpha and 10 bits each for w, v, and u.
case D3DFMT_Q8W8V8U8: // 32-bit bump-map format using 8 bits for each channel.
case D3DFMT_V16U16: // 32-bit bump-map format using 16 bits for each channel.
case D3DFMT_A8R8G8B8: // 32-bit ARGB pixel format with alpha, using 8 bits per channel.
case D3DFMT_X8R8G8B8: // 32-bit RGB pixel format, where 8 bits are reserved for each color.
case D3DFMT_A2B10G10R10: // 32-bit pixel format using 10 bits for each color and 2 bits for alpha.
case D3DFMT_A8B8G8R8: // 32-bit ARGB pixel format with alpha, using 8 bits per channel.
case D3DFMT_X8B8G8R8: // 32-bit RGB pixel format, where 8 bits are reserved for each color.
case D3DFMT_G16R16: // 32-bit pixel format using 16 bits each for green and red.
case D3DFMT_G16R16F: // 32-bit float format using 16 bits for the red channel and 16 bits for the green channel.
case D3DFMT_A2R10G10B10: // 32-bit pixel format using 10 bits each for red, green, and blue, and 2 bits for alpha.
case D3DFMT_D32: // 32-bit z-buffer bit depth.
case D3DFMT_D24S8: // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel.
case D3DFMT_D24X8: //32-bit z-buffer bit depth using 24 bits for the depth channel.
case D3DFMT_D24X4S4: // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel.
case D3DFMT_D32F_LOCKABLE: // A lockable format where the depth value is represented as a standard IEEE floating-point number.
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.
case D3DFMT_D32_LOCKABLE: // A lockable 32-bit depth buffer.
case D3DFMT_INDEX32: // 32-bit index buffer bit depth.
//case : //
//case : //
//case : //
//case : //
{
return (32);
break;
}
case D3DFMT_G32R32F: // 64-bit float format using 32 bits for the red channel and 32 bits for the green channel.
case D3DFMT_Q16W16V16U16: // 64-bit bump-map format using 16 bits for each component.
case D3DFMT_A16B16G16R16: // 64-bit pixel format using 16 bits for each component.
case D3DFMT_A16B16G16R16F: // 64-bit float format using 16 bits for the each channel (alpha, blue, green, red).
{
return (64);
break;
}
case D3DFMT_A32B32G32R32F: // 128-bit float format using 32 bits for the each channel (alpha, blue, green, red).
{
return (128);
break;
}
case D3DFMT_DXT2:
case D3DFMT_DXT3:
case D3DFMT_DXT4:
case D3DFMT_DXT5:
{
return (8);
break;
}
case D3DFMT_DXT1:
{
return (4);
break;
}
default: //compressed formats
{
return (4);
break;
}
}
}
#endif /* uMod_TEXTUREFUNCTION_H_ */
-768
View File
@@ -1,768 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
uMod_TextureServer::uMod_TextureServer(wchar_t *game)
{
Message("uMod_TextureServer(void): %lu\n", this);
Mutex = CreateMutex(NULL, false, NULL);
Clients = NULL;
NumberOfClients = 0;
LenghtOfClients = 0;
BoolSaveAllTextures = false;
BoolSaveSingleTexture = false;
SavePath[0] = 0;
int len=0;
int path_pos=0;
int dot_pos=0;
for (len=0; len<MAX_PATH && (game[len]); len++)
{
if (game[len]==L'\\' || game[len]==L'/') path_pos=len+1;
else if (game[len]==L'.') dot_pos=len;
}
if (dot_pos>path_pos) len = dot_pos - path_pos;
else len -= path_pos;
for (int i=0; i<len; i++) GameName[i] = game[i+path_pos];
if (len<MAX_PATH) GameName[len] = 0;
else GameName[0] = 0;
KeyBack = 0;
KeySave = 0;
KeyNext = 0;
FontColour = 0u;
TextureColour = 0u;
Pipe.In = INVALID_HANDLE_VALUE;
Pipe.Out = INVALID_HANDLE_VALUE;
}
uMod_TextureServer::~uMod_TextureServer(void)
{
Message("~uMod_TextureServer(void): %lu\n", this);
if (Mutex != NULL) CloseHandle(Mutex);
//delete the files in memory
int num = CurrentMod.GetNumber();
for (int i = 0; i < num; i++) delete[] CurrentMod[i]->pData; //delete the file content of the texture
num = OldMod.GetNumber();
for (int i = 0; i < num; i++) delete[] OldMod[i]->pData; //delete the file content of the texture
if (Pipe.In != INVALID_HANDLE_VALUE ) CloseHandle(Pipe.In);
Pipe.In = INVALID_HANDLE_VALUE;
if (Pipe.Out != INVALID_HANDLE_VALUE) CloseHandle(Pipe.Out);
Pipe.Out = INVALID_HANDLE_VALUE;
}
int uMod_TextureServer::AddClient(uMod_TextureClient *client, TextureFileStruct** update, int* number) // called from a client
{
Message("AddClient(%lu): %lu\n", client, this);
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
// the following functions must not change the original uMod_IDirect3DDevice9 object
// somehow on game start some uMod_IDirect3DDevice9 object are created, which must rest unchanged!!
// these objects are released and are not used for rendering
client->SetGameName(GameName);
client->SaveAllTextures(BoolSaveAllTextures);
client->SaveSingleTexture(BoolSaveSingleTexture);
client->SetSaveDirectory(SavePath);
if (KeyBack > 0) client->SetKeyBack(KeyBack);
if (KeySave > 0) client->SetKeySave(KeySave);
if (KeyNext > 0) client->SetKeyNext(KeyNext);
if (FontColour>0u)
{
DWORD r = (FontColour>>16)&0xFF;
DWORD g = (FontColour>>8)&0xFF;
DWORD b = (FontColour)&0xFF;
client->SetFontColour( r, g, b);
}
if (TextureColour>0u)
{
DWORD r = (TextureColour>>16)&0xFF;
DWORD g = (TextureColour>>8)&0xFF;
DWORD b = (TextureColour)&0xFF;
client->SetTextureColour( r, g, b);
}
if (int ret = PrepareUpdate( update, number)) return (ret); // get a copy of all texture to be modded
if (NumberOfClients == LenghtOfClients) //allocate more memory
{
uMod_TextureClient** temp = NULL;
try {temp = new uMod_TextureClient*[LenghtOfClients + 10];}
catch (...)
{
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER;
if (int ret = UnlockMutex()) return (ret);
return (RETURN_NO_MEMORY);
}
for (int i=0; i<LenghtOfClients; i++) temp[i] = Clients[i];
if (Clients!=NULL) delete [] Clients;
Clients = temp;
LenghtOfClients += 10;
}
Clients[NumberOfClients++] = client;
return (UnlockMutex());
}
int uMod_TextureServer::RemoveClient(uMod_TextureClient *client) // called from a client
{
Message("RemoveClient(%lu): %lu\n", client);
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
for (int i = 0; i < NumberOfClients; i++) if (client == Clients[i])
{
NumberOfClients--;
Clients[i] = Clients[NumberOfClients];
break;
}
return (UnlockMutex());
}
int uMod_TextureServer::AddFile( char* buffer, unsigned int size, MyTypeHash hash, bool force) // called from Mainloop()
{
Message("uMod_TextureServer::AddFile( %lu %lu, %#lX, %d): %lu\n", buffer, size, hash, force, this);
TextureFileStruct* temp = NULL;
int num = CurrentMod.GetNumber();
for (int i=0; i<num; i++) if (CurrentMod[i]->Hash == hash) //look through all current textures
{
if (force) {temp = CurrentMod[i]; break;} // we need to reload it
else return (RETURN_OK); // we still have added this texture
}
if (temp==NULL) // if not found, look through all old textures
{
num = OldMod.GetNumber();
for (int i=0; i<num; i++) if (OldMod[i]->Hash == hash)
{
temp = OldMod[i];
OldMod.Remove(temp);
CurrentMod.Add(temp);
if (force) break; // we must reload it
else return (RETURN_OK); // we should not reload it
}
}
bool new_file = true;
if (temp!=NULL) //if it was found, we delete the old file content
{
new_file = false;
if (temp->pData!=NULL) delete [] temp->pData;
temp->pData = NULL;
}
else //if it was not found, we need to create a new object
{
new_file = true;
temp = new TextureFileStruct;
temp->Reference = -1;
}
try
{
temp->pData = new char[size];
}
catch (...)
{
if (!new_file) CurrentMod.Remove( temp); // if this is a not a new file it is in the list of the CurrentMod
delete temp;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER;
return (RETURN_NO_MEMORY);
}
for (unsigned int i=0; i<size; i++) temp->pData[i] = buffer[i];
temp->Size = size;
temp->NumberOfTextures = 0;
temp->Textures = NULL;
temp->Hash = hash;
//if (new_file) temp->ForceReload = false; // no need to force a load of the texture
//else
temp->ForceReload = force;
Message("End AddFile(%#lX)\n", hash);
if (new_file) return (CurrentMod.Add(temp)); // new files must be added to the list of the CurrentMod
else return (RETURN_OK);
}
int uMod_TextureServer::AddFile(wchar_t* file_name, MyTypeHash hash, bool force) // called from Mainloop
// this functions does the same, but loads the file content from disk
{
Message("uMod_TextureServer::AddFile( %ls, %#lX, %d): %lu\n", file_name, hash, force, this);
TextureFileStruct* temp = NULL;
int num = CurrentMod.GetNumber();
for (int i = 0; i < num; i++) if (CurrentMod[i]->Hash == hash)
{
if (force) {temp = CurrentMod[i]; break;}
else return (RETURN_OK);
}
if (temp==NULL)
{
num = OldMod.GetNumber();
for (int i = 0; i < num; i++) if (OldMod[i]->Hash == hash)
{
temp = OldMod[i];
OldMod.Remove(temp);
CurrentMod.Add(temp);
if (force) break;
else return (RETURN_OK);
}
}
FILE* file;
if (_wfopen_s(&file, file_name, L"rb") != 0)
{
Message("AddFile( ): file not found\n");
return (RETURN_FILE_NOT_LOADED);
}
fseek (file, 0, SEEK_END);
unsigned int size = ftell(file);
fseek (file, 0, SEEK_SET);
bool new_file = true;
if (temp!=NULL)
{
new_file = false;
if (temp->pData!=NULL) delete [] temp->pData;
temp->pData = NULL;
}
else
{
new_file = true;
temp = new TextureFileStruct;
temp->Reference = -1;
}
try
{
temp->pData = new char[size];
}
catch (...)
{
if (!new_file) CurrentMod.Remove( temp);
delete temp;
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER;
return (RETURN_NO_MEMORY);
}
int result = fread(temp->pData, 1, size, file);
fclose(file);
if (result != size)
{
delete[] temp->pData;
if (!new_file) CurrentMod.Remove( temp);
delete temp;
return (RETURN_FILE_NOT_LOADED);
}
temp->Size = size;
temp->NumberOfTextures = 0;
temp->Textures = NULL;
temp->Hash = hash;
if (new_file) temp->ForceReload = false;
else temp->ForceReload = force;
Message("End AddFile(%#lX)\n", hash);
if (new_file) return (CurrentMod.Add(temp));
else return (RETURN_OK);
}
int uMod_TextureServer::RemoveFile(MyTypeHash hash) // called from Mainloop()
{
Message("RemoveFile( %lu): %lu\n", hash, this);
int num = CurrentMod.GetNumber();
for (int i = 0; i < num; i++) if (CurrentMod[i]->Hash == hash)
{
TextureFileStruct* temp = CurrentMod[i];
CurrentMod.Remove(temp);
return (OldMod.Add(temp));
}
return (RETURN_OK);
}
int uMod_TextureServer::SaveAllTextures(bool val) // called from Mainloop()
{
if (BoolSaveAllTextures == val) return (RETURN_OK);
BoolSaveAllTextures = val;
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
for (int i = 0; i < NumberOfClients; i++)
{
Clients[i]->SaveAllTextures(BoolSaveAllTextures);
}
return (UnlockMutex());
}
int uMod_TextureServer::SaveSingleTexture(bool val) // called from Mainloop()
{
if (BoolSaveSingleTexture == val) return (RETURN_OK);
BoolSaveSingleTexture = val;
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
for (int i = 0; i < NumberOfClients; i++)
{
Clients[i]->SaveSingleTexture(BoolSaveSingleTexture);
}
return (UnlockMutex());
}
int uMod_TextureServer::SetSaveDirectory(wchar_t *dir) // called from Mainloop()
{
Message("uMod_TextureServer::SetSaveDirectory( %ls): %lu\n", dir, this);
int i = 0;
for (i = 0; i < MAX_PATH && (dir[i]); i++) SavePath[i] = dir[i];
if (i == MAX_PATH)
{
SavePath[0] = 0;
return (RETURN_BAD_ARGUMENT);
}
else SavePath[i] = 0;
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
for (int i = 0; i < NumberOfClients; i++)
{
Clients[i]->SetSaveDirectory(SavePath);
}
return (UnlockMutex());
}
int uMod_TextureServer::SetKeyBack(int key) // called from Mainloop()
{
if (KeyBack == key || KeySave == key || KeyNext == key) return (RETURN_OK);
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
KeyBack = key;
for (int i = 0; i < NumberOfClients; i++)
{
Clients[i]->SetKeyBack(key);
}
return (UnlockMutex());
}
int uMod_TextureServer::SetKeySave(int key) // called from Mainloop()
{
if (KeyBack == key || KeySave == key || KeyNext == key) return (RETURN_OK);
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
KeySave = key;
for (int i = 0; i < NumberOfClients; i++)
{
Clients[i]->SetKeySave(key);
}
return (UnlockMutex());
}
int uMod_TextureServer::SetKeyNext(int key) // called from Mainloop()
{
if (KeyBack == key || KeySave == key || KeyNext == key) return (RETURN_OK);
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
KeyNext = key;
for (int i = 0; i < NumberOfClients; i++)
{
Clients[i]->SetKeyNext(key);
}
return (UnlockMutex());
}
int uMod_TextureServer::SetFontColour(DWORD colour) // called from Mainloop()
{
if (colour==0u) return (RETURN_OK);
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
FontColour = colour;
DWORD r = (FontColour>>16)&0xFF;
DWORD g = (FontColour>>8)&0xFF;
DWORD b = (FontColour)&0xFF;
Message("uMod_TextureServer::SetFontColour( %u %u %u): %lu\n", r ,g ,b, this);
for (int i = 0; i < NumberOfClients; i++)
{
Clients[i]->SetFontColour( r, g, b);
}
return (UnlockMutex());
}
int uMod_TextureServer::SetTextureColour(DWORD colour) // called from Mainloop()
{
if (colour==0u) return (RETURN_OK);
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_SERVER;
return (ret);
}
TextureColour = colour;
DWORD r = (TextureColour>>16)&0xFF;
DWORD g = (TextureColour>>8)&0xFF;
DWORD b = (TextureColour)&0xFF;
Message("uMod_TextureServer::SetTextureColour( %u %u %u): %lu\n", r ,g ,b, this);
for (int i = 0; i < NumberOfClients; i++)
{
Clients[i]->SetTextureColour( r, g, b);
}
return (UnlockMutex());
}
int uMod_TextureServer::PropagateUpdate(uMod_TextureClient* client) // called from Mainloop(), send the update to all clients
{
Message("PropagateUpdate(%lu): %lu\n", client, this);
if (int ret = LockMutex())
{
gl_ErrorState |= uMod_ERROR_TEXTURE;
return (ret);
}
if (client != NULL)
{
TextureFileStruct* update;
int number;
if (int ret = PrepareUpdate( &update, &number)) return (ret);
client->AddUpdate(update, number);
}
else
{
for (int i=0; i<NumberOfClients; i++)
{
TextureFileStruct* update;
int number;
if (int ret = PrepareUpdate( &update, &number)) return (ret);
Clients[i]->AddUpdate(update, number);
}
}
return (UnlockMutex());
}
#define cpy_file_struct( a, b) \
{ \
a.ForceReload = b.ForceReload; \
a.pData = b.pData; \
a.Size = b.Size; \
a.NumberOfTextures = b.NumberOfTextures; \
a.Reference = b.Reference; \
a.Textures = b.Textures; \
a.Hash = b.Hash; }
int TextureFileStruct_Compare( const void * elem1, const void * elem2 )
{
TextureFileStruct *tex1 = (TextureFileStruct*)elem1;
TextureFileStruct *tex2 = (TextureFileStruct*)elem2;
if (tex1->Hash < tex2->Hash) return (-1);
if (tex1->Hash > tex2->Hash) return (+1);
return (0);
}
int uMod_TextureServer::PrepareUpdate(TextureFileStruct** update, int* number) // called from the PropagateUpdate() and AddClient.
// Prepare an update for one client. The allocated memory must deleted by the client.
{
Message("PrepareUpdate(%lu, %d): %lu\n", update, number, this);
TextureFileStruct* temp = NULL;
int num = CurrentMod.GetNumber();
if (num>0)
{
try {temp = new TextureFileStruct[num];}
catch (...)
{
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER;
return (RETURN_NO_MEMORY);
}
for (int i=0; i<num; i++) cpy_file_struct(temp[i], (*(CurrentMod[i])));
qsort( temp, num, sizeof(TextureFileStruct), TextureFileStruct_Compare);
}
*update = temp;
*number = num;
return (RETURN_OK);
}
#undef cpy_file_struct
int uMod_TextureServer::LockMutex(void)
{
if (( gl_ErrorState & (uMod_ERROR_FATAL | uMod_ERROR_MUTEX) )) return (RETURN_NO_MUTEX);
if (WAIT_OBJECT_0!=WaitForSingleObject( Mutex, 100)) return (RETURN_MUTEX_LOCK); //waiting 100ms, to wait infinite pass INFINITE
return (RETURN_OK);
}
int uMod_TextureServer::UnlockMutex(void)
{
if (ReleaseMutex( Mutex) == 0) return (RETURN_MUTEX_UNLOCK);
return (RETURN_OK);
}
int uMod_TextureServer::MainLoop(void) // run as a separated thread
{
Message("MainLoop: begin\n");
if (Pipe.In == INVALID_HANDLE_VALUE) return (RETURN_PIPE_NOT_OPENED);
char *buffer;
try {buffer = new char[BIG_BUFSIZE];}
catch (...) {return (RETURN_NO_MEMORY);}
unsigned long num;
Message("MainLoop: started\n");
bool update_textures = false;
bool more_textures = false;
while (1)
{
Message("MainLoop: run\n");
bool ret = ReadFile(Pipe.In, // pipe handle
buffer, // buffer to receive reply
BIG_BUFSIZE, // size of buffer
&num, // number of bytes read
NULL); // not overlapped
Message("MainLoop: read something (%lu)\n", num);
if (ret || GetLastError() == ERROR_MORE_DATA)
{
unsigned int pos = 0;
MsgStruct *commands;
more_textures = false;
while (pos <= num - sizeof(MsgStruct))
{
commands = (MsgStruct*) &buffer[pos];
unsigned int size = 0u;
bool force = false;
switch (commands->Control)
{
case CONTROL_MORE_TEXTURES:
{
more_textures=true;
break;
}
case CONTROL_FORCE_RELOAD_TEXTURE: force=true;
case CONTROL_ADD_TEXTURE:
{
size = commands->Value;
Message("MainLoop: CONTROL_ADD_TEXTURE (%#lX %u, %u %u): %lu\n", commands->Hash, size, sizeof(MsgStruct), sizeof(char), this);
if (pos + sizeof(MsgStruct) + size <= num) AddFile( (wchar_t*) &buffer[pos + sizeof(MsgStruct)], commands->Hash, force);
update_textures = true;
force = false;
break;
}
case CONTROL_FORCE_RELOAD_TEXTURE_DATA: force=true;
case CONTROL_ADD_TEXTURE_DATA:
{
size = commands->Value;
Message("MainLoop: CONTROL_FORCE_RELOAD_TEXTURE_DATA (%#lX %u, %u %u): %lu\n", commands->Hash, size, sizeof(MsgStruct), sizeof(char), this);
if (pos + sizeof(MsgStruct) + size <= num) AddFile( &buffer[pos + sizeof(MsgStruct)], size, commands->Hash, force);
update_textures = true;
force = false;
break;
}
case CONTROL_REMOVE_TEXTURE:
{
Message("MainLoop: CONTROL_REMOVE_TEXTURE (%#lX): %lu\n", commands->Hash, this);
RemoveFile(commands->Hash);
update_textures = true;
break;
}
case CONTROL_SAVE_SINGLE:
{
Message("MainLoop: CONTROL_SAVE_SINGLE (%d): %lu\n", commands->Value, this);
if (commands->Value == 0) SaveSingleTexture(false);
else SaveSingleTexture(true);
break;
}
case CONTROL_SAVE_ALL:
{
Message("MainLoop: CONTROL_SAVE_ALL (%d): %lu\n", commands->Value, this);
if (commands->Value == 0) SaveAllTextures(false);
else SaveAllTextures(true);
break;
}
case CONTROL_SET_DIR:
{
size = commands->Value;
if (pos + sizeof(MsgStruct) +size <= num) SetSaveDirectory( (wchar_t*) &buffer[pos + sizeof(MsgStruct)]);
break;
}
case CONTROL_KEY_BACK:
{
Message("MainLoop: CONTROL_KEY_BACK (%#X): %lu\n", commands->Value, this);
SetKeyBack(commands->Value);
break;
}
case CONTROL_KEY_SAVE:
{
Message("MainLoop: CONTROL_KEY_SAVE (%#X): %lu\n", commands->Value, this);
SetKeySave(commands->Value);
break;
}
case CONTROL_KEY_NEXT:
{
Message("MainLoop: CONTROL_KEY_NEXT (%#X): %lu\n", commands->Value, this);
SetKeyNext(commands->Value);
break;
}
case CONTROL_FONT_COLOUR:
{
Message("MainLoop: CONTROL_FONT_COLOUR (%#X): %lu\n", commands->Value, this);
SetFontColour(commands->Value);
break;
}
case CONTROL_TEXTURE_COLOUR:
{
Message("MainLoop: CONTROL_TEXTURE_COLOUR (%#X): %lu\n", commands->Value, this);
SetTextureColour(commands->Value);
break;
}
default:
{
Message("MainLoop: DEFAULT: %lu %lu %#lX\n", commands->Control, commands->Value, commands->Hash, this);
break;
}
}
pos += sizeof(MsgStruct) + size;
}
if (!more_textures && update_textures) {PropagateUpdate(); update_textures=false;}
}
else
{
Message("MainLoop: error in ReadFile()\n");
delete [] buffer;
ClosePipe();
return (RETURN_OK);
}
}
delete [] buffer;
return (RETURN_OK);
}
int uMod_TextureServer::OpenPipe(wchar_t *game) // called from InitInstance()
{
Message("OpenPipe: Out\n")
// open first outgoing pipe !!
Pipe.Out = CreateFileW(PIPE_Game2uMod, // pipe name
GENERIC_WRITE, // write access
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file
// Exit if an error other than ERROR_PIPE_BUSY occurs.
if (Pipe.Out == INVALID_HANDLE_VALUE) return (RETURN_PIPE_NOT_OPENED);
unsigned int len = 0u;
while (game[len]) len++;
len++; //to send also the zero
unsigned long num;
//send name of this game to uMod_GUI
WriteFile(Pipe.Out, (const void*) game, len * sizeof(wchar_t), &num, NULL);
// now we can open the pipe for reading
Message("OpenPipe: In\n");
Pipe.In = CreateFileW(PIPE_uMod2Game, // pipe name
GENERIC_READ, // read access
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file
if (Pipe.In == INVALID_HANDLE_VALUE)
{
CloseHandle(Pipe.In);
Pipe.In = INVALID_HANDLE_VALUE;
return (RETURN_PIPE_NOT_OPENED);
}
Message("OpenPipe: Done\n");
return (RETURN_OK);
}
int uMod_TextureServer::ClosePipe(void) //called from ExitInstance, this must be done, otherwise the Mainloop will wait endless on the ReadFile()
{
Message("ClosePipe:\n");
// We close the outgoing pipe first.
// The GUI will notice that the opposite side of it incoming pipe is closed
// and closes it outgoing (our incoming) pipe and thus cancel the ReadFile() in the Mainloop()
if (Pipe.Out != INVALID_HANDLE_VALUE)
{
DisconnectNamedPipe(Pipe.Out);
CloseHandle(Pipe.Out);
Pipe.Out = INVALID_HANDLE_VALUE;
}
if (Pipe.In != INVALID_HANDLE_VALUE)
{
DisconnectNamedPipe(Pipe.In);
CloseHandle(Pipe.In);
Pipe.In = INVALID_HANDLE_VALUE;
}
return (RETURN_OK);
}
-110
View File
@@ -1,110 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_TEXTURESERVER_H_
#define uMod_TEXTURESERVER_H_
#include "../uMod_GlobalDefines.h"
#include "uMod_ArrayHandler.h"
/*
* An object of this class is created only once.
* The Mainloop functions is executed by a server thread,
* which listen on a pipe.
*
* Functions called by the Client are called from the a thread instance of the game itself.
* Nearly all other functions are called from the server thread instance.
*/
class uMod_TextureClient;
class uMod_TextureServer
{
public:
uMod_TextureServer(wchar_t *name);
~uMod_TextureServer(void);
int AddClient(uMod_TextureClient *client, TextureFileStruct** update, int* number); // called from a Client
int RemoveClient(uMod_TextureClient *client); // called from a Client
int OpenPipe(wchar_t *name); // called on initialization of our d3d9 fake dll
int ClosePipe(void); // called on exit of our d3d9 fake dll
int MainLoop(void); // is executed in a server thread
// following functions are only public for testing purpose !!
// they should be private and only be called from the Mainloop
int AddFile( char* buffer, unsigned int size, MyTypeHash hash, bool force); // called from Mainloop(), if the content of the texture is sent
int AddFile( wchar_t* file_name, MyTypeHash hash, bool force); // called from Mainloop(), if the name and the path to the file is sent
int RemoveFile( MyTypeHash hash); // called from Mainloop()
int SaveAllTextures(bool val); // called from Mainloop()
int SaveSingleTexture(bool val); // called from Mainloop()
int SetSaveDirectory( wchar_t *dir); // called from Mainloop()
int SetKeyBack( int key); // called from Mainloop()
int SetKeySave( int key); // called from Mainloop()
int SetKeyNext( int key); // called from Mainloop()
int SetFontColour(DWORD colour); // called from Mainloop()
int SetTextureColour(DWORD colour); // called from Mainloop()
private:
bool BoolSaveAllTextures;
bool BoolSaveSingleTexture;
wchar_t SavePath[MAX_PATH];
wchar_t GameName[MAX_PATH];
int PropagateUpdate(uMod_TextureClient* client=NULL); // called from Mainloop() if texture are loaded or removed
int PrepareUpdate(TextureFileStruct** update, int* number); // called from PropagateUpdate() and AddClient()
// generate a copy of the current texture to be modded
// the file content of the textures are not copied, the clients get the pointer to the file content
// but the arrays allocate by this function, must be deleted by the client
int LockMutex();
int UnlockMutex();
HANDLE Mutex;
int KeyBack;
int KeySave;
int KeyNext;
DWORD FontColour;
DWORD TextureColour;
PipeStruct Pipe;
uMod_TextureClient** Clients;
int NumberOfClients;
int LenghtOfClients;
uMod_FileHandler CurrentMod; // hold the file content of texture
uMod_FileHandler OldMod; // hold the file content of texture which were added previously but are not needed any more
// this is needed, because a texture clients might not have merged the last update and thus hold pointers to the file content of old textures
};
#endif /* uMod_TEXTURESERVER_H_ */
-116
View File
@@ -1,116 +0,0 @@
Warnung: Du verwendest diese Programm auf eigene Gefahr hin!
1) Wenn das Programm abstürzt, wirst du wahrscheinlich keinen Support
vom Spielehersteller bekommen. Aber du kannst den Fehler gerne
angeben unter: http://code.google.com/p/texmod/issues/list
2) Spiele können detektieren, ob sie verändert werden, daher riskierst du
einen Bann deines online Accounts.
3) Dies ist eine open-source Projekt. Der Code kann von jedem erhalten, verändert
und kompiliert werden. Lade Universal Modding Engine nur von offiziellen Quellen runter,
denen du vertraust. Lade es selbst runter und verwende keine Versionen,
die du von Team- oder Gildenmitgliedern geschickt bekommen hast.
http://code.google.com/p/texmod/downloads/list
Universal Modding Engine verwendet die D3DX9_43.dll (32bit). Wegen den EULA kann
diese dll nicht mit Universal Modding Engine mit geliefert werden. Wenn diese dll auf
deinem System nicht installiert ist, wird dich Universal Modding Engine darauf hinweisen.
Was kann Universal Modding Engine (uMod) V1.0?
-einzelne Texturen aus einem Spiel extrahieren und speichern (Die Zieltextur kann im Spiel geändert werden.)
-alle Texturen aus einem Spiel extrahieren und speichern
-Texturen in ein Spiel laden und Zieltexturen ersetzen
-Support einzelner dds Texturen
-Support von zip-Dateien
-Support der originalen TexMod *.tpf Datein
Alle diese Optionen können während des Spieles an und aus geschaltet werden!
Du kannst also nach einer Textur suchen, diese speichern, sie anschließend
editieren, sie in das Spiel laden, sie nach bearbeiten und wieder in das
Spiel laden, ... oder Mods aktivieren und deaktivieren
und das alles ohne das Spiel neu starten zu müssen.
Randbemerkung: Wenn alle Texturen gespeichert werden sollen, so geschieht das nur,
wenn die Texturen vom Spiel geladen werden und auch nur in dem Moment, wenn sie
geladen werden. Stellst du diese Option an, während die Map bereits geladen ist, wird
wahrscheinlich nichts geschehen, da alle Texturen für diese Map bereits geladen sind.
Wechsle also die Map oder lade erneut.
Zip Dateien können eine "texmod.def" Datei enthalten, welche die Hash-Werte und
Dateinamen enthält. Jede Zeile sollte dem Format "hash|filename.dds" entsprechen.
Wenn es keine "texmod.def" Datei enthält, wird jede Datei entpackt und jene, deren
Namen auf das Wildcard "*_hash.dds" zutrifft, werden benutzt.
Die Zip Datei kann eine "Comment.txt" Datei enthalten. Der Inhalte wird als Kommentar
in der GUI angezeigt.
Wenn du einzelne Dateien lädst, sollten diese dem Wildcard "*_hash.dds" entsprechen.
Wie interagiert Universal Modding Engine mit den Spielen?
Universal Modding Engine klingt sich zwischen die Verbindung vom Spiel und DirectX ein.
Das verlangt, dass Universal Modding Engine bereits vor dem Spiel gestartet wird.
Die GUI von Universal Modding Engine fungiert als Server. Ein Spiel, in das sich erfolgreich
eingeklingt wurde, verbindet sich beim Programmstart mit dem Server.
Die GUI von Universal Modding Engine kann mehrere Spiele gleichzeitig verwalten.
Jede Instanz eines Spieles wird auch separat gehandhabt (wenn ein Spiel
mehrfach gestartet wird).
Wie bekomme ich Universal Modding Engine zum laufen?
Es gibt drei Wege wie uMod sich in die DirectX Verbindung einklinken kann:
(Benutze NICHT mehrere Methoden gleichzeitig!)
1) Füge die Spiel-exe über das Menü "Einstellungen->Spiel hinzufügen" hinzu.
Für Steam siehe unten.
bekannte Probleme: Guild Wars (Win XP)
2) Starte das Spiel direkt durch OTM über das Menü
"Einstellungen->Sarte Spiel durch OTM" oder
"Einstellungen->Sarte Spiel durch OTM (mit Kommandozeile)".
Das Spiel startet sofort.
3) Kopiere die d3d9.dll (vom uMod Verzeichnis) in das Spiele Verzeichnis.
Einige Spiele laden eine dll zuerst aus dem eigenen Verzeichnis bevor sie im
Systemverzeichnis suchen. Nur für diese Spiele wird diese Methode funktionieren.
WARNUNG: Kopiere diese dll niemals in das Systemverzeichnis!!
bekannte Probleme: Guild Wars
Wenn du dich für die erste oder dritte Methode entschieden hast, starte einfach
Universal Modding Engine und danach das Spiel. Starte das Spiel in beiden Fällen NICHT über
Universal Modding Engine .
Wenn das Spiel startet und alles glatt läuft, öffnet sich sofort ein neuer Tab in uMod.
In diesem Tab kannst du nun das Spiel modden. Drücke den "Update" Button um
die Einstellungen an das Spiel zu senden. Du kannst deine aktuellen Einstellungen auch
als ein Template speichern. Ein Template kann auch als Standard eingestellt werden.
Es wird dann automatisch geladen und an das Spiel gesendet, wenn
dieses Spiel das nächste Mal gestartet wird.
Um einen Mod zu laden, musst du das Häkchen vor den Namen setzen. Wenn du
den Mod entladen willst, entferne das Häkchen und klicke auf "Update".
Der Update Button lädt nur Veränderungen (wenn 1) Pakete aus der Liste entfernt
wurden, 2) du die Häkchen verändert hast oder 3) sich die Reihenfolge geändert hat)
Der "neu laden" Button erzwingt das Neuladen von Festplatte (z.B. wenn du die
Texturen verändert hast).
Weil verschiedene Mods die gleiche Ziel-Textur verändern könnten, wird nur die
Mod-Textur des ersten Mods berücksichtigt. Die Aktion dieses Mods (also Laden oder
Entladen) wird durchgeführt, ungeachtet dessen, was die restlichen Mods mit der
Ziel-Textur machen sollen.
Wie bekommt man Universal Modding Engine mit Steam zum Laufen?
uMod schaut auf den Namen und auf das Verzeichnis der ausgeführten Spiel-exe.
Daher solltest du nicht die steam.exe sondern die Spiel.exe hinzufügen.
z.B.: C:\Steam\SteamApps\acoount_name\portal\hl2.exe
Wenn du die entsprechende exe nicht findest, kannst du das Spiel normal starten und
über den TaskManager die entsprechende exe suchen. Über Rechstklick->Eigenschaften
erfährst du dann auch den Pfad der exe.
-107
View File
@@ -1,107 +0,0 @@
WARNING: You use this program at your own risk!
1) If the program crash, you won't get probably any support from the game developer,
but you can report the bug under http://code.google.com/p/texmod/issues/list
2) Games can detected if they are modified, so you might risk a ban
of your online account!
3) This is an open-source project. The code can be retrieved, modified and compiled
by everyone. Download Universal Modding Engine only from sources you trust!
Download it by your self and don't use versions, send to you by team or guild members!
http://code.google.com/p/texmod/downloads/list
Universal Modding Engine uses the D3DX9_43.dll (32bit). Due to the EULA this dll
cannot be delivered together with Universal Modding Engine . If D3DX9_43.dll is not
installed on your system, Universal Modding Engine will give you a hint at program start.
What can Universal Modding Engine (uMod) V1.0?
-extract and save single textures from a DX9 game (the target texture can be toggled in the game)
-extract and save all textures from a DX9 game
-load textures into a game to replace target textures
-support single dds texture
-support zip-files as whole mod package
-support the original TexMod *.tpf files
All these options can be switched on or off, while the game is already running!
So you can search for a texture in the game, save it to disk, edit it,
load it into the game, edit it again and load it into the game again, ...,
actiavate or deactivate mods and all without a restart of the game.
side note: If "save all textures" is switched on, the texture will only be saved, if
the textures are loaded by the game and only in the moment they are loaded.
If you switch this option on, while a map is loaded, probably nothing will hapen,
because all textures are loaded for this map. Change the Map or reload it again.
Zip files can include a "texmod.def" file which contains the hash and the file name.
Each line should be in the format "hash|filename.dds"
If it does not contain a "texmod.def" each file will be unpacked and those which match
the wildcard "*_hash.dds" will be used.
The zip file can include a "Comment.txt" file. The content will be shown as comment
in the GUI.
If you load single files, they should match the wildcard "*_hash.dds"
How does Universal Modding Engine interact with the game?
Universal Modding Engine intercept the connection between the game and DirectX.
It is required, that Universal Modding Engine is running before the game is started.
The GUI of Universal Modding Engine act as a server. A game which is successfully
intercepted with the Universal Modding Engine-dll will connect on program start to the server.
The GUI of Universal Modding Engine can handle multiple games at the same time. It will
also process each instance of a game as separate process (if the same game
was started more than once).
How to get Universal Modding Engine work?
There are three ways how Universal Modding Engine can intercept the DirectX connection:
(Do NOT use more than one method simultaneously!)
1) Add the games-binary through the menu "Main->Add game"
For Steam see below.
known problems: Guild Wars (Win XP)
2) Start the game directly through uMod though the menu
"Main->Start game through uMod" or
"Main->Start game through uMod (with command line)".
The game start immediately.
3) Copy the d3d9.dll (from the Universal Modding Engine directory) into the game directory.
Some games load a dll first from their own directory before they look up the system directory.
Only for these games this method will work.
WARNING: never copy this dll into your system directory!!
known problems: Guild Wars
If you have chosen the first or third method, you simply start Universal Modding Engine
and afterwards the game. Do NOT start the game through Universal Modding Engine.
If the game starts and all works fine, a new tab opens immediately in uMod.
In this tab you can now mod the game. Press the "update" button to commit
the changes to the game. You can also save your current settings as a template.
One template can be set as default for a game, which will be loaded and
and committed automatically when you start this game the next time.
To load a mod, you must set the check mark of the file. If you wish to unload a mod,
just remove the check mark and click on update again.
Clicking on update will only update the differences (if packages have been
removed from the list, you toggled check marks or changed the order). The reload
button forces to reload from disk (if you have edited the texture itself).
Due to the fact that different mods can modify the same target texture, only the
mod-texture of the first file in the list is taken into account. The action of this file
(load or unload) is proceeded regardless of what the following mods are opposed
to do with their mod-textures.
How to get Universal Modding Engine work together with Steam?
Universal Modding Engine looks for the name and the path of the executed binary.
Thus you shall not add the steam.exe but rather the game.exe
e.g.: C:\Steam\SteamApps\acoount_name\portal\hl2.exe
If you cannot find the exe, just start the game and use the TaskManager
to search for it. You can figure out the path through right click->properties.
-110
View File
@@ -1,110 +0,0 @@
ATTENTION : Vous utilisez ce programme à vous risque !
1) Si le programme plante, vous n'aurez probablement aucune aide des développeurs,
mais vous pouvez envoyer le bogue sur http://code.google.com/p/texmod/issues/list
2) Les jeux peuvent détecter les modifications de uMod, vous prenez le risque de bannir
votre compte en ligne !
3) C'est un projet open-source. Le code peut être récupéré, modifié et compilé
par tout le monde. Téléchargez Universal Modding Engine seulement sur des sources sûres !
Ne télécharger pas et n'utiliser pas d'autres versions modifiées de ce logiciel,
par exemple des versions envoyées par votre équipe ou votre guilde !
Le site officiel : http://code.google.com/p/texmod/downloads/list
Universal Modding Engine utilise le D3DX9_43.dll (32bit). En raison de la licence CLUF cette dll
ne peut pas être livrée avec Universal Modding Engine . Si vous n'avez pas D3DX9_43.dll
d'installé sur votre système, Universal Modding Engine va vous afficher un message
au démarrage du programme.
Que fait Universal Modding Engine (uMod) V1.0 ?
-Extraire et sauvegarder des textures d'un jeu DX9 (la texture d'origine peut se modifier)
-Extraire et sauvegarder toutes les textures d'un jeu DX9
-Charger des textures dans un jeu pour remplacer les textures d'origines
-Supporte les textures DDS
-Supporte les fichiers compressés (ZIP) pour faire un MOD (modifier plusieurs textures à la fois)
-Supporte les fichiers de TexMod *.tpf
Toutes les options peuvent s'activer ou se désactiver, pendant que le jeu est lancé !
Ainsi, vous pouvez rechercher une texture dans le jeu, l'enregistrer sur disque, la modifier,
la charger dans le jeu, éditer une autre texture, la charger dans le jeu, etc...,
Activer ou désactiver des MODs sans aucun redémarrage du jeu.
Remarque : Si vous cochez "Sauvegarder toutes les textures", les textures qui seront enregistrées,
sont les textures chargées dans le jeu après le moment où vous avez coché la case.
Si vous activez cette option, pendant qu'une carte est chargée, vous n'allez probablement rien enregistrer,
parce que toutes les textures sont déjà chargées. Changez de Carte ou rechargez-là.
Les fichiers compressés peuvent inclure le fichier "texmod.def" qui contient le hash et le nom du fichier.
Chaque ligne doit avoir le format "hash|filename.dds"
Si elle ne contient pas un "texmod.def" chaque fichier sera décompressé et seuls les fichiers ayant
le format "*_hash.dds" seront utilisés.
Le fichier zip peut inclure un fichier "Comment.txt". Le contenu sera affiché comme commentaire
dans l'interface graphique.
Si vous chargez des textures seules, elles doivent correspondre au format "*_hash.dds"
Comment Universal Modding Engine interagit avec les jeux ?
Universal Modding Engine intercepte la connexion entre le jeu et DirectX.
Il est nécessaire, que Universal Modding Engine soit lancé avant le jeu.
L'interface graphique de Universal Modding Engine est comme un serveur.
Un jeu correctement intercepté par Universal Modding Engine-dll se connectera au démarrage sur le serveur.
L'interface graphique de Universal Modding Engine peut gérer plusieurs jeux en même temps. Il sera
également traiter chaque jeu en tant que processus indépendant (si le même jeu
a été lancé plus d'une fois).
Comment Universal Modding Engine fonctionne ?
Il y a trois façon pour que Universal Modding Engine intercepte la connexion à DirectX :
(Ne PAS utiliser plus d'une méthode à la fois !)
1) Ajouter l'exécutable du jeu dans le menu "Réglages->Ajouter un jeu"
Pour Steam, voir plus bas.
Problèmes connus : Guild Wars (Win XP)
2) Lancer le jeu directement via le menu uMod
"Réglages->Lancer le jeu avec uMod" ou
"Réglages->Lancer le jeu avec uMod (en ligne de commande)".
Le jeu se lance directement.
3) Copier le d3d9.dll (depuis le répertoire de Universal Modding Engine) dans votre dossier de jeu.
Certain jeu recherche les DLLs dans leur répertoire avant d'aller chercher les DLLs dans
le dossier du système.
Cette méthode ne fonctionne que sur certain jeu.
ATTENTION : Ne jamais copier ce fichier DLL dans votre répertoire système !!!
Problèmes connus : Guild Wars
Si vous avez choisi la première ou la troisième méthode, il vous suffit de lancer Universal Modding Engine
et de lancer le jeu séparément. Ne PAS lancer le jeu via uMod.
Si le jeu se lance et tout fonctionne, un nouveau onglet va s'ouvrir directement dans uMod.
Dans cet onglet vous pouvez modifier le jeu. Appuyer sur "Mettre à jour"
pour envoyer les changements au jeu. Vous pouvez sauvegarder vos paramètres actuels comme thème.
Un thème peut être lancé par défaut au démarrage d'un jeu.
Pour charger une texture ou un mod, vous devez cocher la case du fichier. Si vous voulez décharger un mod,
il faut simplement décocher la case et cliquer sur "Mettre à jour".
En cliquant sur "Mettre à jour", seules les textures chargées dans uMod seront misent à jour
(si une texture chargée est supprimée de la liste, cela va juste décocher la texture).
Cliquez sur "Mettre à jour (Recharger)" pour recharger les fichiers de texture sur le disque dur.
(Si vous venez de modifier une texture déjà chargée par exemple).
En raison du fait que plusieurs mods peuvent modifier la même texture, seuls le mod / la texture
du premier fichier de la liste est pris en compte pour la modification. L'action de ce mod
(c'est à dire le chargement ou le déchargement) est effectuée, indépendamment des autres mods.
Comment faire pour que Universal Modding Engine fonctionne avec Steam ?
Universal Modding Engine cherche le nom et le chemin du fichier binaire exécuté.
Ainsi vous ne devez pas ajouter Steam.exe mais plutôt le game.exe
exemple : C:\Steam\SteamApps\acoount_name\portal\hl2.exe
Si vous ne trouvez pas l'exécutable, il suffit de commencer le jeu et
d'utiliser "le Gestionnaire des tâches" pour rechercher dans quel dossier il se trouve en
faisant un clique droit sur le nom de l'exécutable "Propriétés"->"Emplacement".
@@ -1,152 +0,0 @@
If you have created a language package and would like to add to the officially download, please send it to me.
Email address and support can be found at http://code.google.com/p/texmod/
The file name must match the wildcard uMod_LanguagePack_NAMEOFLANGUAGE.txt
Format of an entry is divided into 3 parts: 1) Keyword directly followed by a colon, 2) message, and 3) end symbol "|"
Restriction of the the message: do not use "|" within a message!!
You can also use utf-16LE encoding, but you have to label the file as uMod_LanguagePackU_NAMEOFLANGUAGE.txt
comments must start with an "#" and must end with |
e.g.
#
this is a comment
|
Keyword:
Message1 line1
Message1 line2
|
Keyword2:Message2|
Keyword3:Message3 line1
Message3 line2|
There is no need to include all keywords, since English is loaded each time as default and afterwards the entries are replaced.
English itself is compiled into the uMod_GUI.exe, thus there exists no uMod_LanguagePack_English.txt.
The following list is an example of how an English package would look like (maybe not all keywords are present).
MenuHelp:
Help|
MenuAbout:
About|
MenuAcknowledgement:Acknowledgement|
MenuStartGame:Start game through uMod|
MenuStartGameCMD :Start game through uMod (with command line)|
MenuUseHook:Use global hook|
MenuAddGame:
Add game|
MenuDeleteGame:
Delete Game|
MenuLoadTemplate:Load template|
MenuSaveTemplate:Save template|
MenuSaveTemplateAs:Save template as ...|
MenuSetDefaultTemplate:Set template as default|
MenuLanguage:Change language|
MenuExit:Exit|
MainMenuMain:Main|
MainMenuHelp:
Help|
ButtonOpen:
Open texture|
ButtonDirectory:
save directory|
ButtonUpdate:
Update|
ButtonReload:Update (reload)|
ChooseFile:Choose a file|
ChooseDir:
Choose a directory|
CheckBoxSaveSingleTexture:
Save single texture|
TextCtrlTemplate:Template: |
CheckBoxSaveAllTextures:
Save all textures|
TextCtrlSavePath:
Save path: |
SelectLanguage:
Select a language|
StartGame:Select the game to start.|
CommandLine:Set command line arguments.|
ChooseGame:
Select a game binary.
DeleteGame:
Select the games to be deleted.|
GameAlreadyAdded:
Game has been already added.|
ExitGameAnyway:
Closing Universal Modding Engine while a game is running might lead to a crash of the game.
Exit anyway?|
NoComment:
No comment.|
Author:
Author: |
Error_GameIsHooked:The global hook is active and this game will be injected! Please delete the game from the list or disable the hook.|
Error_ProcessNotStarted:The game could not be started.|
Error_RemoveHook:Removing the Hook while a game is running might lead to crash.|
Error_FileNotSupported:
This file type is not supported:|
Error_DLLNotFound:
Could not load the dll.
The dll injection won't work.
This might happen if D3DX9_43.dll is not installed on your system.
Please install the newest DirectX End-User Runtime Web Installer.|
Error_FktNotFound:
Could not load function out of dll.
The dll injection won't work.|
Error_AlreadyRunning:An other instance of Universal Modding Engine is already running.|
Error_Send:
Could not send to game.|
Error_KeyTwice:
You assigned a key twice.|
Error_NoSavePath:
You did not set a save path.|
Error_KeyNotSet:
At least one key is not set.|
Error_SaveFile:
Could not save to file.|
Error_NoPipe:
Pipe is not opened.|
Error_WritePipe:
Could not write in pipe.|
Error_FlushPipe:
Could not flush pipe buffer.|
Error_Hash:
Could not find hash, maybe file is not named as *_HASH.dds|
Error_FileOpen:
Could not open file.|
Error_FileRead:
Could not read file.|
Error_Memory:
Could not allocate enough memory|
Error_Unzip:
Could not unzip.|
Error_ZipEntry:
Could not find zip entry.|
KeyBack:
Back|
KeySave:
Save|
KeyNext:
Next|
FontColour:
Font colour (RGB):|
TextureColour:
Texture colour (RGB):|
Binary file not shown.
@@ -1,75 +0,0 @@
# by mirHL|
MenuHelp:Aiuto|
MenuAbout:Informazioni|
MenuAcknowledgement:Riconoscimenti|
MenuStartGame:Avvia il gioco da uMod|
MenuStartGameCMD:Avvia il gioco da uMod (con riga di comando)|
MenuUseHook:Usa hook globale|
MenuAddGame:Aggiungi gioco|
MenuDeleteGame:Rimuovi gioco|
MenuLoadTemplate:Carica template|
MenuSaveTemplate:Salva template|
MenuSaveTemplateAs:Salva template come...|
MenuSetDefaultTemplate:Imposta template come predefinito|
MenuLanguage:Cambia lingua (Change language)|
MenuExit:Esci|
MainMenuMain:Comandi|
MainMenuHelp:Aiuto|
ButtonOpen:Apri texture/archivio|
ButtonDirectory:Imposta cartella lavoro|
ButtonUpdate:Aggiorna|
ButtonReload:Aggiorna (ricarica)|
ChooseFile:Seleziona un file|
ChooseDir:Seleziona una cartella|
CheckBoxSaveSingleTexture:Salva singole texture|
TextCtrlTemplate:Template: |
CheckBoxSaveAllTextures:Salva tutte le texture|
TextCtrlSavePath:Percorso lavori: |
SelectLanguage:Seleziona una lingua|
StartGame:Seleziona il gioco da far partire.|
CommandLine:Imposta opzioni da riga di comando.|
ChooseGame:Seleziona un eseguibile di un gioco.|
DeleteGame:Seleziona i giochi da rimuovere.|
GameAlreadyAdded:Il gioco è già stato aggiunto.|
ExitGameAnyway:Chiudere uMod mentre il gioco è in esecuzione potrebbe farlo crashare.
Uscire comunque?|
NoComment:Nessun commento.|
Author:Autore: |
Error_GameIsHooked:L'hook globale è attivo e questo è in conflitto col lancio! Per favore rimuovi il gioco dalla lista o spegni l'hook.|
Error_ProcessNotStarted:Il gioco non è potuto essere avviato.|
Error_RemoveHook:Rimuovere l'Hook mentre il gioco è in esecuzione potrebbe farlo crashare.|
Error_FileNotSupported:Questo tipo di file non è supportato:|
Error_DLLNotFound:
Impossibile caricare la dll.
La dll injection non funzionerà.
Questo accade perchè D3DX9_43.dll non è installato nel sistema.
Installa DirectX End-User Runtime Web Installer.|
Error_FktNotFound:Impossibile caricare una funzione fuori della dll.
La dll injection non funzionerà.|
Error_AlreadyRunning:Un altro processo di uMod è in esecuzione.|
Error_Send:Impossibile arrivare al gioco.|
Error_KeyTwice:Hai assegnato due volte lo stesso tasto.|
Error_NoSavePath:Non hai selezionato un percorso di salvataggio.|
Error_KeyNotSet:Qualche tasto non è assegnato.|
Error_SaveFile:Impossibile salvare il file.|
Error_NoPipe:Pipe non è aperto.|
Error_WritePipe:impossibile scrivere in pipe.|
Error_FlushPipe:Impossibile ripulire pipe buffer.|
Error_Hash:Impossibile trovare l'hash, forse il file non è chiamato *_HASH.dds|
Error_FileOpen:Impossibile aprire il file.|
Error_FileRead:Impossibile leggere il file.|
Error_Memory:Impossibile allocare abbastanza memoria|
Error_Unzip:Impossibile scomprimere.|
Error_ZipEntry:Impossibile trovare Zip entry.|
KeyBack:Precedente|
KeySave:Salva|
KeyNext:Successivo|
FontColour:Colore caratteri (RGB):|
TextureColour:Colore texture (RGB):|
-149
View File
@@ -1,149 +0,0 @@
# =========================================================================
# This configuration file was generated by
# Bakefile 0.2.8 (http://www.bakefile.org)
# Beware that all changes made to this file will be overwritten next
# time you run Bakefile!
# =========================================================================
# -------------------------------------------------------------------------
# These are configurable options:
# -------------------------------------------------------------------------
# Compiler flags to link shared library
#LINK_DLL_FLAGS ?= -shared
LINK_DLL_FLAGS ?=
# Compiler flags to link loadable module
#LINK_MODULE_FLAGS ?= -shared
LINK_MODULE_FLAGS ?=
# C compiler
CC = gcc
# C++ compiler
CXX = g++
# Standard flags for CC
CFLAGS ?=
# Standard flags for C++
CXXFLAGS ?= -Wno-unused
# Standard preprocessor flags (common for CC and CXX)
CPPFLAGS ?=
# Standard linker flags
LDFLAGS ?= -static-libgcc -static-libstdc++
# The C preprocessor
CPP ?= $(CC) -E
# What type of library to build? [0,1]
SHARED ?= 0
# Build wxUniversal instead of native port? [0,1]
WXUNIV ?= 0
# Compile Unicode build of wxWidgets? [0,1]
UNICODE ?= 1
# Use MSLU library when building Unicode version. [0,1]
MSLU ?= 0
# Type of compiled binaries [debug,release]
BUILD ?= release
# Should debugging info be included in the executables? The default value
# "default" means that debug info will be included if BUILD=debug
# and not included if BUILD=release. [0,1,default]
DEBUG_INFO ?= 0
# Value of wxDEBUG_LEVEL. The default value is the same as 1 and means that all
# but expensive assert checks are enabled, use 0 to completely remove debugging
# code. [0,1,default]
DEBUG_FLAG ?= 0
# Multiple libraries or single huge monolithic one? [0,1]
MONOLITHIC ?= 0
# Build GUI libraries? [0,1]
USE_GUI ?= 1
# Build wxHTML library (USE_GUI must be 1)? [0,1]
USE_HTML ?= 1
# Build multimedia library (USE_GUI must be 1)? [0,1]
USE_MEDIA ?= 1
# Build wxXRC library (USE_GUI must be 1)? [0,1]
USE_XRC ?= 1
# Build wxAUI library (USE_GUI must be 1)? [0,1]
USE_AUI ?= 1
# Build wxRibbon library (USE_GUI must be 1)? [0,1]
USE_RIBBON ?= 1
# Build wxPropertyGrid library (USE_GUI must be 1)? [0,1]
USE_PROPGRID ?= 1
# Build wxRichTextCtrl library (USE_GUI must be 1)? [0,1]
USE_RICHTEXT ?= 1
# Build wxStyledTextCtrl library (USE_GUI must be 1)? [0,1]
USE_STC ?= 1
# Build OpenGL canvas library (USE_GUI must be 1)? [0,1]
USE_OPENGL ?= 1
# Build quality assurance classes library (USE_GUI must be 1)? [0,1]
USE_QA ?= 0
# Enable exceptions in compiled code. [0,1]
USE_EXCEPTIONS ?= 1
# Enable run-time type information (RTTI) in compiled code. [0,1]
USE_RTTI ?= 1
# Enable threading in compiled code. [0,1]
USE_THREADS ?= 1
# Enable wxCairoContext for platforms other than Linux/GTK. [0,1]
USE_CAIRO ?= 0
# Is this official build by wxWidgets developers? [0,1]
OFFICIAL_BUILD ?= 0
# Use this to name your customized DLLs differently
VENDOR ?= custom
#
WX_FLAVOUR ?=
#
WX_LIB_FLAVOUR ?=
# Name of your custom configuration. This affects directory
# where object files are stored as well as the location of
# compiled .lib files and setup.h under the lib/ toplevel directory.
CFG ?=
# Compiler flags needed to compile test suite in tests directory. If you want
# to run the tests, set it so that the compiler can find CppUnit headers.
CPPUNIT_CFLAGS ?=
# Linker flags needed to link test suite in tests directory. If you want
# to run the tests, include CppUnit library here.
CPPUNIT_LIBS ?=
# Version of C runtime library to use. You can change this to
# static if SHARED=0, but it is highly recommended to not do
# it if SHARED=1 unless you know what you are doing. [dynamic,static]
RUNTIME_LIBS ?= static
# Set the version of your Mingw installation here.
# "3" ...... this is for Mingw 2.0 or newer (comes with gcc3)
# "2.95" ... for Mingw 1.1 or any of the older versions [3,2.95]
GCC_VERSION ?= 3
-149
View File
@@ -1,149 +0,0 @@
# =========================================================================
# This configuration file was generated by
# Bakefile 0.2.8 (http://www.bakefile.org)
# Beware that all changes made to this file will be overwritten next
# time you run Bakefile!
# =========================================================================
# -------------------------------------------------------------------------
# These are configurable options:
# -------------------------------------------------------------------------
# C compiler
CC = cl
# C++ compiler
CXX = cl
# Standard flags for CC
CFLAGS =
# Standard flags for C++
CXXFLAGS =
# Standard preprocessor flags (common for CC and CXX)
CPPFLAGS =
# Standard linker flags
LDFLAGS =
# The C preprocessor
CPP = $(CC) /EP /nologo
# What type of library to build? [0,1]
SHARED = 0
# Build wxUniversal instead of native port? [0,1]
WXUNIV = 0
# Compile Unicode build of wxWidgets? [0,1]
UNICODE = 1
# Use MSLU library when building Unicode version. [0,1]
MSLU = 0
# Type of compiled binaries [debug,release]
BUILD = release
# The target processor architecture must be specified when it is not X86.
# This does not affect the compiler output, so you still need to make sure
# your environment is set up appropriately with the correct compiler in the
# PATH. Rather it affects some options passed to some of the common build
# utilities such as the resource compiler and the linker.
#
# Accepted values: AMD64, IA64.
TARGET_CPU = $(CPU)
# Should debugging info be included in the executables? The default value
# "default" means that debug info will be included if BUILD=debug
# and not included if BUILD=release. [0,1,default]
DEBUG_INFO = 1
# Value of wxDEBUG_LEVEL. The default value is the same as 1 and means that all
# but expensive assert checks are enabled, use 0 to completely remove debugging
# code. [0,1,default]
DEBUG_FLAG = 0
# Link against debug (e.g. msvcrtd.dll) or release (msvcrt.dll) RTL?
# Default is to use debug CRT if and only if BUILD==debug. [0,1,default]
DEBUG_RUNTIME_LIBS = default
# Multiple libraries or single huge monolithic one? [0,1]
MONOLITHIC = 0
# Build GUI libraries? [0,1]
USE_GUI = 1
# Build wxHTML library (USE_GUI must be 1)? [0,1]
USE_HTML = 1
# Build multimedia library (USE_GUI must be 1)? [0,1]
USE_MEDIA = 1
# Build wxXRC library (USE_GUI must be 1)? [0,1]
USE_XRC = 1
# Build wxAUI library (USE_GUI must be 1)? [0,1]
USE_AUI = 1
# Build wxRibbon library (USE_GUI must be 1)? [0,1]
USE_RIBBON = 1
# Build wxPropertyGrid library (USE_GUI must be 1)? [0,1]
USE_PROPGRID = 1
# Build wxRichTextCtrl library (USE_GUI must be 1)? [0,1]
USE_RICHTEXT = 1
# Build wxStyledTextCtrl library (USE_GUI must be 1)? [0,1]
USE_STC = 1
# Build OpenGL canvas library (USE_GUI must be 1)? [0,1]
USE_OPENGL = 1
# Build quality assurance classes library (USE_GUI must be 1)? [0,1]
USE_QA = 1
# Enable exceptions in compiled code. [0,1]
USE_EXCEPTIONS = 1
# Enable run-time type information (RTTI) in compiled code. [0,1]
USE_RTTI = 1
# Enable threading in compiled code. [0,1]
USE_THREADS = 1
# Enable wxCairoContext for platforms other than Linux/GTK. [0,1]
USE_CAIRO = 0
# Is this official build by wxWidgets developers? [0,1]
OFFICIAL_BUILD = 0
# Use this to name your customized DLLs differently
VENDOR = custom
#
WX_FLAVOUR =
#
WX_LIB_FLAVOUR =
# Name of your custom configuration. This affects directory
# where object files are stored as well as the location of
# compiled .lib files and setup.h under the lib/ toplevel directory.
CFG =
# Compiler flags needed to compile test suite in tests directory. If you want
# to run the tests, set it so that the compiler can find CppUnit headers.
CPPUNIT_CFLAGS =
# Linker flags needed to link test suite in tests directory. If you want
# to run the tests, include CppUnit library here.
CPPUNIT_LIBS =
# Version of C runtime library to use. You can change this to
# static if SHARED=0, but it is highly recommended to not do
# it if SHARED=1 unless you know what you are doing. [dynamic,static]
RUNTIME_LIBS = static
-284
View File
@@ -1,284 +0,0 @@
# =========================================================================
# This makefile was generated by
# Bakefile 0.2.1 (http://bakefile.sourceforge.net)
# Do not modify, all changes will be overwritten!
# =========================================================================
include config.gcc
# -------------------------------------------------------------------------
# Do not modify the rest of this file!
# -------------------------------------------------------------------------
### Variables: ###
CPPDEPS = -MT$@ -MF$@.d -MD
WX_RELEASE_NODOT = 29
OBJS = \
obj
OBJS_exe = \
bin
WX_DIR = D:\Programme\wxWidgets-2.9.2
LIBDIRNAME = $(WX_DIR)\lib\gcc_$(LIBTYPE_SUFFIX)$(CFG)
SETUPHDIR = \
$(LIBDIRNAME)\$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)
MINIMAL_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG_2) $(__THREADSFLAG) \
$(GCCFLAGS) -DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
$(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \
$(__THREAD_DEFINE_p) $(__UNICODE_DEFINE_p) $(__MSLU_DEFINE_p) \
$(__GFXCTX_DEFINE_p) -I$(SETUPHDIR) -I$(WX_DIR)\include -W -Wall -Wextra -I. \
$(__DLLFLAG_p) -DNOPCH $(__RTTIFLAG_5) \
$(__EXCEPTIONSFLAG_6) -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)
MINIMAL_OBJECTS = \
$(OBJS)\uMod_rc.o \
$(OBJS)\unzip.o \
$(OBJS)\uMod_DirectInjection.o \
$(OBJS)\uMod_GUI.o \
$(OBJS)\uMod_GameInfo.o \
$(OBJS)\uMod_GamePage.o \
$(OBJS)\uMod_Server.o \
$(OBJS)\uMod_Client.o \
$(OBJS)\uMod_File.o \
$(OBJS)\uMod_Sender.o \
$(OBJS)\uMod_Settings.o \
$(OBJS)\uMod_AddTexture.o \
$(OBJS)\uMod_Language.o
### Conditionally set variables: ###
ifeq ($(GCC_VERSION),2.95)
GCCFLAGS = -fvtable-thunks
endif
ifeq ($(USE_GUI),0)
PORTNAME = base
endif
ifeq ($(USE_GUI),1)
PORTNAME = msw
endif
ifeq ($(BUILD),debug)
ifeq ($(DEBUG_FLAG),default)
WXDEBUGFLAG = d
endif
endif
ifeq ($(DEBUG_FLAG),1)
WXDEBUGFLAG = d
endif
ifeq ($(UNICODE),1)
WXUNICODEFLAG = u
endif
ifeq ($(WXUNIV),1)
WXUNIVNAME = univ
endif
ifeq ($(SHARED),1)
WXDLLFLAG = dll
endif
ifeq ($(SHARED),0)
LIBTYPE_SUFFIX = lib
endif
ifeq ($(SHARED),1)
LIBTYPE_SUFFIX = dll
endif
ifeq ($(MONOLITHIC),0)
EXTRALIBS_FOR_BASE =
endif
ifeq ($(MONOLITHIC),1)
EXTRALIBS_FOR_BASE =
endif
ifeq ($(BUILD),debug)
__OPTIMIZEFLAG_2 = -O0 -g
endif
ifeq ($(BUILD),release)
__OPTIMIZEFLAG_2 = -O2
endif
ifeq ($(USE_RTTI),0)
__RTTIFLAG_5 = -fno-rtti
endif
ifeq ($(USE_RTTI),1)
__RTTIFLAG_5 =
endif
ifeq ($(USE_EXCEPTIONS),0)
__EXCEPTIONSFLAG_6 = -fno-exceptions
endif
ifeq ($(USE_EXCEPTIONS),1)
__EXCEPTIONSFLAG_6 =
endif
ifeq ($(WXUNIV),1)
__WXUNIV_DEFINE_p = -D__WXUNIVERSAL__
endif
ifeq ($(WXUNIV),1)
__WXUNIV_DEFINE_p_1 = --define __WXUNIVERSAL__
endif
ifeq ($(BUILD),debug)
ifeq ($(DEBUG_FLAG),default)
__DEBUG_DEFINE_p = -D__WXDEBUG__
endif
endif
ifeq ($(DEBUG_FLAG),1)
__DEBUG_DEFINE_p = -D__WXDEBUG__
endif
ifeq ($(BUILD),debug)
ifeq ($(DEBUG_FLAG),default)
__DEBUG_DEFINE_p_1 = --define __WXDEBUG__
endif
endif
ifeq ($(DEBUG_FLAG),1)
__DEBUG_DEFINE_p_1 = --define __WXDEBUG__
endif
ifeq ($(USE_EXCEPTIONS),0)
__EXCEPTIONS_DEFINE_p = -DwxNO_EXCEPTIONS
endif
ifeq ($(USE_EXCEPTIONS),0)
__EXCEPTIONS_DEFINE_p_1 = --define wxNO_EXCEPTIONS
endif
ifeq ($(USE_RTTI),0)
__RTTI_DEFINE_p = -DwxNO_RTTI
endif
ifeq ($(USE_RTTI),0)
__RTTI_DEFINE_p_1 = --define wxNO_RTTI
endif
ifeq ($(USE_THREADS),0)
__THREAD_DEFINE_p = -DwxNO_THREADS
endif
ifeq ($(USE_THREADS),0)
__THREAD_DEFINE_p_1 = --define wxNO_THREADS
endif
ifeq ($(UNICODE),1)
__UNICODE_DEFINE_p = -D_UNICODE
endif
ifeq ($(UNICODE),1)
__UNICODE_DEFINE_p_1 = --define _UNICODE
endif
ifeq ($(MSLU),1)
__MSLU_DEFINE_p = -DwxUSE_UNICODE_MSLU=1
endif
ifeq ($(MSLU),1)
__MSLU_DEFINE_p_1 = --define wxUSE_UNICODE_MSLU=1
endif
ifeq ($(USE_GDIPLUS),1)
__GFXCTX_DEFINE_p = -DwxUSE_GRAPHICS_CONTEXT=1
endif
ifeq ($(USE_GDIPLUS),1)
__GFXCTX_DEFINE_p_1 = --define wxUSE_GRAPHICS_CONTEXT=1
endif
ifeq ($(SHARED),1)
__DLLFLAG_p = -DWXUSINGDLL
endif
ifeq ($(SHARED),1)
__DLLFLAG_p_1 = --define WXUSINGDLL
endif
ifeq ($(MONOLITHIC),0)
__WXLIB_CORE_p = \
-lwx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core
endif
ifeq ($(MONOLITHIC),0)
__WXLIB_BASE_p = \
-lwxbase$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)
endif
ifeq ($(MONOLITHIC),1)
__WXLIB_MONO_p = \
-lwx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)
endif
ifeq ($(USE_GUI),1)
__LIB_TIFF_p = -lwxtiff$(WXDEBUGFLAG)
endif
ifeq ($(USE_GUI),1)
__LIB_JPEG_p = -lwxjpeg$(WXDEBUGFLAG)
endif
ifeq ($(USE_GUI),1)
__LIB_PNG_p = -lwxpng$(WXDEBUGFLAG)
endif
ifeq ($(MSLU),1)
__UNICOWS_LIB_p = -lunicows
endif
ifeq ($(USE_GDIPLUS),1)
__GDIPLUS_LIB_p = -lgdiplus
endif
ifeq ($(BUILD),debug)
ifeq ($(DEBUG_INFO),default)
__DEBUGINFO = -g
endif
endif
ifeq ($(BUILD),release)
ifeq ($(DEBUG_INFO),default)
__DEBUGINFO =
endif
endif
ifeq ($(DEBUG_INFO),0)
__DEBUGINFO =
endif
ifeq ($(DEBUG_INFO),1)
__DEBUGINFO = -g
endif
ifeq ($(USE_THREADS),0)
__THREADSFLAG =
endif
ifeq ($(USE_THREADS),1)
__THREADSFLAG = -mthreads
endif
all: $(OBJS)
$(OBJS):
-if not exist $(OBJS) mkdir $(OBJS)
all: $(OBJS_exe)
$(OBJS_exe):
-if not exist $(OBJS_exe) mkdir $(OBJS_exe)
### Targets: ###
all: $(OBJS_exe)\uMod.exe
clean:
-if exist $(OBJS)\*.o del $(OBJS)\*.o
-if exist $(OBJS)\*.d del $(OBJS)\*.d
-if exist $(OBJS_exe)\uMod.exe del $(OBJS_exe)\uMod.exe
$(OBJS_exe)\uMod.exe: $(MINIMAL_OBJECTS) $(OBJS)\uMod_rc.o
$(CXX) -o $@ $(MINIMAL_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) $(__THREADSFLAG) -L$(LIBDIRNAME) -Wl,--subsystem,windows -mwindows $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG) -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) $(__GDIPLUS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32
$(OBJS)\uMod_rc.o: uMod.rc uMod.ico
windres --use-temp-file -i $< -o $@
$(OBJS)\unzip.o: ./unzip.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_DirectInjection.o: ./uMod_DirectInjection.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_GUI.o: ./uMod_GUI.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_GameInfo.o: ./uMod_GameInfo.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_GamePage.o: ./uMod_GamePage.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_Server.o: ./uMod_Server.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_Client.o: ./uMod_Client.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_File.o: ./uMod_File.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_Sender.o: ./uMod_Sender.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_Settings.o: ./uMod_Settings.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_AddTexture.o: ./uMod_AddTexture.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\uMod_Language.o: ./uMod_Language.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
.PHONY: all clean
# Dependencies tracking:
-include $(OBJS)/*.d
-401
View File
@@ -1,401 +0,0 @@
# =========================================================================
# This makefile was generated by
# Bakefile 0.2.8 (http://www.bakefile.org)
# Do not modify, all changes will be overwritten!
# =========================================================================
!include <config.vc>
# -------------------------------------------------------------------------
# Do not modify the rest of this file!
# -------------------------------------------------------------------------
### Variables: ###
WX_RELEASE_NODOT = 29
COMPILER_PREFIX = vc
OBJS = \
obj
OBJS_exe = \
bin
WX_DIR = D:\Programme\wxWidgets-2.9.2
LIBDIRNAME = \
$(WX_DIR)\lib\$(COMPILER_PREFIX)$(DIR_SUFFIX_CPU)_$(LIBTYPE_SUFFIX)$(CFG)
SETUPHDIR = \
$(LIBDIRNAME)\$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)
MINIMAL_CXXFLAGS = /M$(__RUNTIME_LIBS_10)$(__DEBUGRUNTIME_4) /DWIN32 \
$(__DEBUGINFO_0) /Fd$(OBJS)\uMod_GUI.pdb $(____DEBUGRUNTIME_3_p) \
$(__OPTIMIZEFLAG_6) $(__NO_VC_CRTDBG_p) /D__WXMSW__ $(__WXUNIV_DEFINE_p) \
$(__DEBUG_DEFINE_p) $(__NDEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) \
$(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) $(__UNICODE_DEFINE_p) \
$(__MSLU_DEFINE_p) /I$(SETUPHDIR) /I$(WX_DIR)\include \
$(____CAIRO_INCLUDEDIR_FILENAMES_p) /W4 /I. $(__DLLFLAG_p) /D_WINDOWS \
/DNOPCH $(__RTTIFLAG_11) $(__EXCEPTIONSFLAG_12) \
$(CPPFLAGS) $(CXXFLAGS)
MINIMAL_OBJECTS = \
$(OBJS)\unzip.obj \
$(OBJS)\uMod_DirectInjection.obj \
$(OBJS)\uMod_GUI.obj \
$(OBJS)\uMod_GameInfo.obj \
$(OBJS)\uMod_GamePage.obj \
$(OBJS)\uMod_Server.obj \
$(OBJS)\uMod_Client.obj \
$(OBJS)\uMod_File.obj \
$(OBJS)\uMod_Sender.obj \
$(OBJS)\uMod_Settings.obj \
$(OBJS)\uMod_AddTexture.obj \
$(OBJS)\uMod_Language.obj
MINIMAL_RESOURCES = \
$(OBJS)\uMod_GUI.res
### Conditionally set variables: ###
!if "$(USE_GUI)" == "0"
PORTNAME = base
!endif
!if "$(USE_GUI)" == "1"
PORTNAME = msw
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "default"
WXDEBUGFLAG = d
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "1"
WXDEBUGFLAG = d
!endif
!if "$(UNICODE)" == "1"
WXUNICODEFLAG = u
!endif
!if "$(WXUNIV)" == "1"
WXUNIVNAME = univ
!endif
!if "$(TARGET_CPU)" == "AMD64"
DIR_SUFFIX_CPU = _amd64
!endif
!if "$(TARGET_CPU)" == "IA64"
DIR_SUFFIX_CPU = _ia64
!endif
!if "$(TARGET_CPU)" == "amd64"
DIR_SUFFIX_CPU = _amd64
!endif
!if "$(TARGET_CPU)" == "ia64"
DIR_SUFFIX_CPU = _ia64
!endif
!if "$(SHARED)" == "1"
WXDLLFLAG = dll
!endif
!if "$(SHARED)" == "0"
LIBTYPE_SUFFIX = lib
!endif
!if "$(SHARED)" == "1"
LIBTYPE_SUFFIX = dll
!endif
!if "$(TARGET_CPU)" == "AMD64"
LINK_TARGET_CPU = /MACHINE:X64
!endif
!if "$(TARGET_CPU)" == "IA64"
LINK_TARGET_CPU = /MACHINE:IA64
!endif
!if "$(TARGET_CPU)" == "amd64"
LINK_TARGET_CPU = /MACHINE:X64
!endif
!if "$(TARGET_CPU)" == "ia64"
LINK_TARGET_CPU = /MACHINE:IA64
!endif
!if "$(MONOLITHIC)" == "0"
EXTRALIBS_FOR_BASE =
!endif
!if "$(MONOLITHIC)" == "1"
EXTRALIBS_FOR_BASE =
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_INFO)" == "default"
__DEBUGINFO_0 = /Zi
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_INFO)" == "default"
__DEBUGINFO_0 =
!endif
!if "$(DEBUG_INFO)" == "0"
__DEBUGINFO_0 =
!endif
!if "$(DEBUG_INFO)" == "1"
__DEBUGINFO_0 = /Zi
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_INFO)" == "default"
__DEBUGINFO_1 = /DEBUG
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_INFO)" == "default"
__DEBUGINFO_1 =
!endif
!if "$(DEBUG_INFO)" == "0"
__DEBUGINFO_1 =
!endif
!if "$(DEBUG_INFO)" == "1"
__DEBUGINFO_1 = /DEBUG
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_INFO)" == "default"
__DEBUGINFO_2 = $(__DEBUGRUNTIME_5)
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_INFO)" == "default"
__DEBUGINFO_2 =
!endif
!if "$(DEBUG_INFO)" == "0"
__DEBUGINFO_2 =
!endif
!if "$(DEBUG_INFO)" == "1"
__DEBUGINFO_2 = $(__DEBUGRUNTIME_5)
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "default"
____DEBUGRUNTIME_3_p = /D_DEBUG
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_RUNTIME_LIBS)" == "default"
____DEBUGRUNTIME_3_p =
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "0"
____DEBUGRUNTIME_3_p =
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "1"
____DEBUGRUNTIME_3_p = /D_DEBUG
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "default"
____DEBUGRUNTIME_3_p_1 = /d _DEBUG
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_RUNTIME_LIBS)" == "default"
____DEBUGRUNTIME_3_p_1 =
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "0"
____DEBUGRUNTIME_3_p_1 =
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "1"
____DEBUGRUNTIME_3_p_1 = /d _DEBUG
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "default"
__DEBUGRUNTIME_4 = d
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_RUNTIME_LIBS)" == "default"
__DEBUGRUNTIME_4 =
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "0"
__DEBUGRUNTIME_4 =
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "1"
__DEBUGRUNTIME_4 = d
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "default"
__DEBUGRUNTIME_5 =
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_RUNTIME_LIBS)" == "default"
__DEBUGRUNTIME_5 = /opt:ref /opt:icf
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "0"
__DEBUGRUNTIME_5 = /opt:ref /opt:icf
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "1"
__DEBUGRUNTIME_5 =
!endif
!if "$(BUILD)" == "debug"
__OPTIMIZEFLAG_6 = /Od
!endif
!if "$(BUILD)" == "release"
__OPTIMIZEFLAG_6 = /O2
!endif
!if "$(USE_THREADS)" == "0"
__THREADSFLAG_9 = L
!endif
!if "$(USE_THREADS)" == "1"
__THREADSFLAG_9 = T
!endif
!if "$(RUNTIME_LIBS)" == "dynamic"
__RUNTIME_LIBS_10 = D
!endif
!if "$(RUNTIME_LIBS)" == "static"
__RUNTIME_LIBS_10 = $(__THREADSFLAG_9)
!endif
!if "$(USE_RTTI)" == "0"
__RTTIFLAG_11 =
!endif
!if "$(USE_RTTI)" == "1"
__RTTIFLAG_11 = /GR
!endif
!if "$(USE_EXCEPTIONS)" == "0"
__EXCEPTIONSFLAG_12 =
!endif
!if "$(USE_EXCEPTIONS)" == "1"
__EXCEPTIONSFLAG_12 = /EHsc
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "0"
__NO_VC_CRTDBG_p = /D__NO_VC_CRTDBG__
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_FLAG)" == "1"
__NO_VC_CRTDBG_p = /D__NO_VC_CRTDBG__
!endif
!if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "0"
__NO_VC_CRTDBG_p_1 = /d __NO_VC_CRTDBG__
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_FLAG)" == "1"
__NO_VC_CRTDBG_p_1 = /d __NO_VC_CRTDBG__
!endif
!if "$(WXUNIV)" == "1"
__WXUNIV_DEFINE_p = /D__WXUNIVERSAL__
!endif
!if "$(WXUNIV)" == "1"
__WXUNIV_DEFINE_p_1 = /d __WXUNIVERSAL__
!endif
!if "$(DEBUG_FLAG)" == "0"
__DEBUG_DEFINE_p = /DwxDEBUG_LEVEL=0
!endif
!if "$(DEBUG_FLAG)" == "0"
__DEBUG_DEFINE_p_1 = /d wxDEBUG_LEVEL=0
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_RUNTIME_LIBS)" == "default"
__NDEBUG_DEFINE_p = /DNDEBUG
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "0"
__NDEBUG_DEFINE_p = /DNDEBUG
!endif
!if "$(BUILD)" == "release" && "$(DEBUG_RUNTIME_LIBS)" == "default"
__NDEBUG_DEFINE_p_1 = /d NDEBUG
!endif
!if "$(DEBUG_RUNTIME_LIBS)" == "0"
__NDEBUG_DEFINE_p_1 = /d NDEBUG
!endif
!if "$(USE_EXCEPTIONS)" == "0"
__EXCEPTIONS_DEFINE_p = /DwxNO_EXCEPTIONS
!endif
!if "$(USE_EXCEPTIONS)" == "0"
__EXCEPTIONS_DEFINE_p_1 = /d wxNO_EXCEPTIONS
!endif
!if "$(USE_RTTI)" == "0"
__RTTI_DEFINE_p = /DwxNO_RTTI
!endif
!if "$(USE_RTTI)" == "0"
__RTTI_DEFINE_p_1 = /d wxNO_RTTI
!endif
!if "$(USE_THREADS)" == "0"
__THREAD_DEFINE_p = /DwxNO_THREADS
!endif
!if "$(USE_THREADS)" == "0"
__THREAD_DEFINE_p_1 = /d wxNO_THREADS
!endif
!if "$(UNICODE)" == "0"
__UNICODE_DEFINE_p = /DwxUSE_UNICODE=0
!endif
!if "$(UNICODE)" == "1"
__UNICODE_DEFINE_p = /D_UNICODE
!endif
!if "$(UNICODE)" == "0"
__UNICODE_DEFINE_p_1 = /d wxUSE_UNICODE=0
!endif
!if "$(UNICODE)" == "1"
__UNICODE_DEFINE_p_1 = /d _UNICODE
!endif
!if "$(MSLU)" == "1"
__MSLU_DEFINE_p = /DwxUSE_UNICODE_MSLU=1
!endif
!if "$(MSLU)" == "1"
__MSLU_DEFINE_p_1 = /d wxUSE_UNICODE_MSLU=1
!endif
!if "$(USE_CAIRO)" == "1"
____CAIRO_INCLUDEDIR_FILENAMES_p = /I$(CAIRO_ROOT)\include\cairo
!endif
!if "$(USE_CAIRO)" == "1"
____CAIRO_INCLUDEDIR_FILENAMES_1_p = /i $(CAIRO_ROOT)\include\cairo
!endif
!if "$(SHARED)" == "1"
__DLLFLAG_p = /DWXUSINGDLL
!endif
!if "$(SHARED)" == "1"
__DLLFLAG_p_1 = /d WXUSINGDLL
!endif
!if "$(MONOLITHIC)" == "0"
__WXLIB_CORE_p = \
wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core.lib
!endif
!if "$(MONOLITHIC)" == "0"
__WXLIB_BASE_p = \
wxbase$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR).lib
!endif
!if "$(MONOLITHIC)" == "1"
__WXLIB_MONO_p = \
wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR).lib
!endif
!if "$(USE_GUI)" == "1"
__LIB_TIFF_p = wxtiff$(WXDEBUGFLAG).lib
!endif
!if "$(USE_GUI)" == "1"
__LIB_JPEG_p = wxjpeg$(WXDEBUGFLAG).lib
!endif
!if "$(USE_GUI)" == "1"
__LIB_PNG_p = wxpng$(WXDEBUGFLAG).lib
!endif
!if "$(MSLU)" == "1"
__UNICOWS_LIB_p = unicows.lib
!endif
!if "$(USE_CAIRO)" == "1"
__CAIRO_LIB_p = cairo.lib
!endif
!if "$(USE_CAIRO)" == "1"
____CAIRO_LIBDIR_FILENAMES_p = /LIBPATH:$(CAIRO_ROOT)\lib
!endif
all: $(OBJS)
$(OBJS):
-if not exist $(OBJS) mkdir $(OBJS)
### Targets: ###
all: $(OBJS_exe)\uMod.exe
clean:
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
-if exist $(OBJS)\*.res del $(OBJS)\*.res
-if exist $(OBJS)\*.pch del $(OBJS)\*.pch
-if exist $(OBJS_exe)\uMod_GUI.exe del $(OBJS_exe)\uMod.exe
-if exist $(OBJS_exe)\uMod_GUI.ilk del $(OBJS_exe)\uMod_GUI.ilk
-if exist $(OBJS_exe)\uMod_GUI.pdb del $(OBJS_exe)\uMod_GUI.pdb
$(OBJS_exe)\uMod.exe: $(MINIMAL_OBJECTS) $(OBJS)\uMod_GUI.res
link /NOLOGO /OUT:$@ $(__DEBUGINFO_1) /pdb:"$(OBJS)\uMod_GUI.pdb" $(__DEBUGINFO_2) $(LINK_TARGET_CPU) /LIBPATH:$(LIBDIRNAME) /SUBSYSTEM:WINDOWS $(____CAIRO_LIBDIR_FILENAMES_p) $(LDFLAGS) @<<
$(MINIMAL_OBJECTS) $(MINIMAL_RESOURCES) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) $(__CAIRO_LIB_p) kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib wininet.lib
<<
$(OBJS)\uMod_GUI.res: uMod.rc
rc /fo$@ /d WIN32 $(____DEBUGRUNTIME_3_p_1) $(__NO_VC_CRTDBG_p_1) /d __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) $(__MSLU_DEFINE_p_1) /i $(SETUPHDIR) /i . $(__DLLFLAG_p_1) /d _WINDOWS /d NOPCH uMod.rc
#$(OBJS)\display_display.obj: .\display.cpp
# $(CXX) /c /nologo /TP /Fo$@ $(DISPLAY_CXXFLAGS) .\display.cpp
$(OBJS)\unzip.obj: .\unzip.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\unzip.cpp
$(OBJS)\uMod_DirectInjection.obj: .\uMod_DirectInjection.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_DirectInjection.cpp
$(OBJS)\uMod_GUI.obj: .\uMod_GUI.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_GUI.cpp
$(OBJS)\uMod_GameInfo.obj: .\uMod_GameInfo.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_GameInfo.cpp
$(OBJS)\uMod_GamePage.obj: .\uMod_GamePage.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_GamePage.cpp
$(OBJS)\uMod_Server.obj: .\uMod_Server.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Server.cpp
$(OBJS)\uMod_Client.obj: .\uMod_Client.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Client.cpp
$(OBJS)\uMod_File.obj: .\uMod_File.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_File.cpp
$(OBJS)\uMod_Sender.obj: .\uMod_Sender.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Sender.cpp
$(OBJS)\uMod_Settings.obj: .\uMod_Settings.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Settings.cpp
$(OBJS)\uMod_AddTexture.obj: .\uMod_AddTexture.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_AddTexture.cpp
$(OBJS)\uMod_Language.obj: .\uMod_Language.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Language.cpp
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

-1
View File
@@ -1 +0,0 @@
MAINICON ICON "uMod.ico"
-112
View File
@@ -1,112 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
AddTextureClass::AddTextureClass(void)
{
Num = 0;
Textures = NULL;
Size = NULL;
Hash = NULL;
WasAdded = NULL;
Len=0;
Add = false;
Force = false;
Loaded = false;
OwnMemory = false;
}
AddTextureClass::~AddTextureClass(void)
{
ReleaseMemory();
}
int AddTextureClass::ReleaseMemory(void)
{
if (OwnMemory)
{
if (Size!=NULL) delete [] Size;
if (Hash!=NULL) delete [] Hash;
if (WasAdded!=NULL) delete [] WasAdded;
if (Textures!=NULL)
{
for (unsigned int i=0; i<Num && i<Len; i++) if (Textures[i]!=NULL) delete [] Textures[i];
delete [] Textures;
}
}
return 0;
}
int AddTextureClass::SetSize(int num)
{
Num = 0;
if (GetMemory( Size, num, 0u)) return -1;
if (GetMemory( Hash, num)) return -1;
if (GetMemory( WasAdded, num, false)) return -1;
if (GetMemory( Textures, num, (char*)0)) return -1;
OwnMemory = true;
Len = num;
return 0;
}
int AddTextureClass::InheriteMemory(AddTextureClass &tex)
{
if (!tex.OwnMemory)
{
if (SetSize(tex.Len)) return -1;
for (unsigned int i=0u; i<tex.Len; i++) Hash[i] = tex.Hash[i];
for (unsigned int i=0u; i<tex.Len; i++) WasAdded[i] = tex.WasAdded[i];
for (unsigned int i=0u; i<tex.Len; i++) Size[i] = tex.Size[i];
for (unsigned int i=0u; i<tex.Num; i++) if (tex.Textures[i]!=NULL && tex.Size[i]>0)
{
if (GetMemory( Textures[i], tex.Size[i])) return -1;
for (unsigned int j=0u; j<tex.Size[i]; j++) Textures[i][j] = tex.Textures[i][j];
Size[i] = tex.Size[i];
}
Len = tex.Len;
Num = tex.Num;
}
else
{
ReleaseMemory();
Hash = tex.Hash;
WasAdded = tex.WasAdded;
Size = tex.Size;
Textures = tex.Textures;
Len = tex.Len;
Num = tex.Num;
OwnMemory = true;
tex.OwnMemory = false;
}
Add = tex.Add;
Force = tex.Force;
Loaded = tex.Loaded;
File = tex.File;
Comment = tex.Comment;
return 0;
}
-54
View File
@@ -1,54 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_ADDTEXTURE_H_
#define uMod_ADDTEXTURE_H_
#include "uMod_Main.h"
class AddTextureClass
{
public:
AddTextureClass(void);
~AddTextureClass(void);
int ReleaseMemory(void);
int SetSize(int num);
int InheriteMemory(AddTextureClass &tex);
unsigned int Num;
char **Textures;
unsigned int *Size;
unsigned long *Hash;
bool *WasAdded;
unsigned int Len;
bool Add;
bool Force;
bool Loaded;
bool OwnMemory;
wxString File;
wxString Comment;
};
#endif /* uMod_ADDTEXTURE_H_ */
-93
View File
@@ -1,93 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
uMod_Client::uMod_Client( PipeStruct &pipe, uMod_Frame *frame) : wxThread(wxTHREAD_JOINABLE)
{
Pipe.In = pipe.In;
Pipe.Out = pipe.Out;
MainFrame = frame;
}
uMod_Client::~uMod_Client(void)
{
if (Pipe.Out != INVALID_HANDLE_VALUE)
{
DisconnectNamedPipe(Pipe.Out);
CloseHandle(Pipe.Out);
Pipe.Out = INVALID_HANDLE_VALUE;
}
if (Pipe.In != INVALID_HANDLE_VALUE)
{
DisconnectNamedPipe(Pipe.In);
CloseHandle(Pipe.In);
Pipe.In = INVALID_HANDLE_VALUE;
}
}
void* uMod_Client::Entry(void)
{
char buffer[SMALL_BUFSIZE];
while (1)
{
unsigned long size;
bool ret = ReadFile(
Pipe.In, // handle to pipe
buffer, // buffer to receive data
SMALL_BUFSIZE, // size of buffer
&size, // number of bytes read
NULL); // not overlapped I/O
if (ret || GetLastError()==ERROR_MORE_DATA)
{
unsigned int pos=0;
MsgStruct *commands;
bool update_textures = false;
while (pos<size-sizeof(MsgStruct))
{
commands = (MsgStruct*) &buffer[pos];
//unsigned int add_length = 0;
/*
switch (commands->Control)
{
}
*/
pos+=sizeof(MsgStruct);// + add_length;
}
}
else
{
break;
}
}
CloseHandle(Pipe.In);
Pipe.In = INVALID_HANDLE_VALUE;
CloseHandle(Pipe.Out);
Pipe.Out = INVALID_HANDLE_VALUE;
uMod_Event event( uMod_EVENT_TYPE, ID_Delete_Game);
event.SetClient(this);
wxPostEvent( MainFrame, event);
return NULL;
}
-45
View File
@@ -1,45 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_CLIENT_H_
#define uMod_CLIENT_H_
#include "uMod_Main.h"
// an object of this class is created for each running game
// it reads out of the incoming pipe (it must run as thread)
// if the pipe is closed (Game is canceled) it send a messeage to the main thread
// it should read the error state from the dll, but this is not yet implemented
class uMod_Client : public wxThread
{
public:
uMod_Client( PipeStruct &pipe, uMod_Frame *frame);
virtual ~uMod_Client(void);
void* Entry(void);
PipeStruct Pipe;
private:
uMod_Frame *MainFrame;
};
#endif /* uMod_CLIENT_H_ */
-519
View File
@@ -1,519 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* Drew_Benton
* http://www.codeproject.com/KB/threads/completeinject.aspx
*
*/
#include "uMod_Main.h"
/***************************************************************************************************/
// Function:
// Inject
//
// Parameters:
// HANDLE hProcess - The handle to the process to inject the DLL into.
//
// const char* dllname - The name of the DLL to inject into the process.
//
// const char* funcname - The name of the function to call once the DLL has been injected.
//
// Description:
// This function will inject a DLL into a process and execute an exported function
// from the DLL to "initialize" it. The function should be in the format shown below,
// not parameters and no return type. Do not forget to prefix extern "C" if you are in C++
//
// __declspec(dllexport) void FunctionName(void)
//
// The function that is called in the injected DLL
// -MUST- return, the loader waits for the thread to terminate before removing the
// allocated space and returning control to the Loader. This method of DLL injection
// also adds error handling, so the end user knows if something went wrong.
/***************************************************************************************************/
void Inject(HANDLE hProcess, const wchar_t* dllname, const char* funcname)
{
//------------------------------------------//
// Function variables. //
//------------------------------------------//
// Main DLL we will need to load
HMODULE kernel32 = NULL;
// Main functions we will need to import
FARPROC loadlibrary = NULL;
FARPROC getprocaddress = NULL;
FARPROC exitprocess = NULL;
FARPROC exitthread = NULL;
FARPROC freelibraryandexitthread = NULL;
// The workspace we will build the codecave on locally
LPBYTE workspace = NULL;
DWORD workspaceIndex = 0;
// The memory in the process we write to
LPVOID codecaveAddress = NULL;
DWORD dwCodecaveAddress = 0;
// Strings we have to write into the process
char injectDllName[MAX_PATH + 1] = {0};
char injectFuncName[MAX_PATH + 1] = {0};
char injectError0[MAX_PATH + 1] = {0};
char injectError1[MAX_PATH + 1] = {0};
char injectError2[MAX_PATH + 1] = {0};
char user32Name[MAX_PATH + 1] = {0};
char msgboxName[MAX_PATH + 1] = {0};
// Placeholder addresses to use the strings
DWORD user32NameAddr = 0;
DWORD user32Addr = 0;
DWORD msgboxNameAddr = 0;
DWORD msgboxAddr = 0;
DWORD dllAddr = 0;
DWORD dllNameAddr = 0;
DWORD funcNameAddr = 0;
DWORD error0Addr = 0;
DWORD error1Addr = 0;
DWORD error2Addr = 0;
// Where the codecave execution should begin at
DWORD codecaveExecAddr = 0;
// Handle to the thread we create in the process
HANDLE hThread = NULL;
// Temp variables
DWORD dwTmpSize = 0;
// Old protection on page we are writing to in the process and the bytes written
DWORD oldProtect = 0;
DWORD bytesRet = 0;
//------------------------------------------//
// Variable initialization. //
//------------------------------------------//
// Get the address of the main DLL
kernel32 = LoadLibraryW(L"kernel32.dll");
// Get our functions
loadlibrary = GetProcAddress(kernel32, "LoadLibraryA");
getprocaddress = GetProcAddress(kernel32, "GetProcAddress");
exitprocess = GetProcAddress(kernel32, "ExitProcess");
exitthread = GetProcAddress(kernel32, "ExitThread");
freelibraryandexitthread = GetProcAddress(kernel32, "FreeLibraryAndExitThread");
// This section will cause compiler warnings on VS8,
// you can upgrade the functions or ignore them
// Build names
_snprintf(injectDllName, MAX_PATH, "%ls", dllname);
_snprintf(injectFuncName, MAX_PATH, "%s", funcname);
_snprintf(user32Name, MAX_PATH, "user32.dll");
_snprintf(msgboxName, MAX_PATH, "MessageBoxA");
// Build error messages
_snprintf(injectError0, MAX_PATH, "Error");
_snprintf(injectError1, MAX_PATH, "Could not load the dll: %s", injectDllName);
_snprintf(injectError2, MAX_PATH, "Could not load the function: %s", injectFuncName);
// Create the workspace
workspace = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1024);
// Allocate space for the codecave in the process
codecaveAddress = VirtualAllocEx(hProcess, 0, 1024, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
dwCodecaveAddress = PtrToUlong(codecaveAddress);
// Note there is no error checking done above for any functions that return a pointer/handle.
// I could have added them, but it'd just add more messiness to the code and not provide any real
// benefit. It's up to you though in your final code if you want it there or not.
//------------------------------------------//
// Data and string writing. //
//------------------------------------------//
// Write out the address for the user32 dll address
user32Addr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = 0;
memcpy(workspace + workspaceIndex, &dwTmpSize, 4);
workspaceIndex += 4;
// Write out the address for the MessageBoxA address
msgboxAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = 0;
memcpy(workspace + workspaceIndex, &dwTmpSize, 4);
workspaceIndex += 4;
// Write out the address for the injected DLL's module
dllAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = 0;
memcpy(workspace + workspaceIndex, &dwTmpSize, 4);
workspaceIndex += 4;
// User32 Dll Name
user32NameAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(user32Name) + 1;
memcpy(workspace + workspaceIndex, user32Name, dwTmpSize);
workspaceIndex += dwTmpSize;
// MessageBoxA name
msgboxNameAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(msgboxName) + 1;
memcpy(workspace + workspaceIndex, msgboxName, dwTmpSize);
workspaceIndex += dwTmpSize;
// Dll Name
dllNameAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectDllName) + 1;
memcpy(workspace + workspaceIndex, injectDllName, dwTmpSize);
workspaceIndex += dwTmpSize;
// Function Name
funcNameAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectFuncName) + 1;
memcpy(workspace + workspaceIndex, injectFuncName, dwTmpSize);
workspaceIndex += dwTmpSize;
// Error Message 1
error0Addr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectError0) + 1;
memcpy(workspace + workspaceIndex, injectError0, dwTmpSize);
workspaceIndex += dwTmpSize;
// Error Message 2
error1Addr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectError1) + 1;
memcpy(workspace + workspaceIndex, injectError1, dwTmpSize);
workspaceIndex += dwTmpSize;
// Error Message 3
error2Addr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectError2) + 1;
memcpy(workspace + workspaceIndex, injectError2, dwTmpSize);
workspaceIndex += dwTmpSize;
// Pad a few INT3s after string data is written for seperation
workspace[workspaceIndex++] = 0xCC;
workspace[workspaceIndex++] = 0xCC;
workspace[workspaceIndex++] = 0xCC;
// Store where the codecave execution should begin
codecaveExecAddr = workspaceIndex + dwCodecaveAddress;
// For debugging - infinite loop, attach onto process and step over
//workspace[workspaceIndex++] = 0xEB;
//workspace[workspaceIndex++] = 0xFE;
//------------------------------------------//
// User32.dll loading. //
//------------------------------------------//
// User32 DLL Loading
// PUSH 0x00000000 - Push the address of the DLL name to use in LoadLibraryA
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &user32NameAddr, 4);
workspaceIndex += 4;
// MOV EAX, ADDRESS - Move the address of LoadLibraryA into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &loadlibrary, 4);
workspaceIndex += 4;
// CALL EAX - Call LoadLibraryA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// MessageBoxA Loading
// PUSH 0x000000 - Push the address of the function name to load
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &msgboxNameAddr, 4);
workspaceIndex += 4;
// Push EAX, module to use in GetProcAddress
workspace[workspaceIndex++] = 0x50;
// MOV EAX, ADDRESS - Move the address of GetProcAddress into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &getprocaddress, 4);
workspaceIndex += 4;
// CALL EAX - Call GetProcAddress
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// MOV [ADDRESS], EAX - Save the address to our variable
workspace[workspaceIndex++] = 0xA3;
memcpy(workspace + workspaceIndex, &msgboxAddr, 4);
workspaceIndex += 4;
//------------------------------------------//
// Injected dll loading. //
//------------------------------------------//
/*
// This is the way the following assembly code would look like in C/C++
// Load the injected DLL into this process
HMODULE h = LoadLibrary("mydll.dll");
if(!h)
{
MessageBox(0, "Could not load the dll: mydll.dll", "Error", MB_ICONERROR);
ExitProcess(0);
}
// Get the address of the export function
FARPROC p = GetProcAddress(h, "Initialize");
if(!p)
{
MessageBox(0, "Could not load the function: Initialize", "Error", MB_ICONERROR);
ExitProcess(0);
}
// So we do not need a function pointer interface
__asm call p
// Exit the thread so the loader continues
ExitThread(0);
*/
// DLL Loading
// PUSH 0x00000000 - Push the address of the DLL name to use in LoadLibraryA
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &dllNameAddr, 4);
workspaceIndex += 4;
// MOV EAX, ADDRESS - Move the address of LoadLibraryA into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &loadlibrary, 4);
workspaceIndex += 4;
// CALL EAX - Call LoadLibraryA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// Error Checking
// CMP EAX, 0
workspace[workspaceIndex++] = 0x83;
workspace[workspaceIndex++] = 0xF8;
workspace[workspaceIndex++] = 0x00;
// JNZ EIP + 0x1E to skip over eror code
workspace[workspaceIndex++] = 0x75;
workspace[workspaceIndex++] = 0x1E;
// Error Code 1
// MessageBox
// PUSH 0x10 (MB_ICONHAND)
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x10;
// PUSH 0x000000 - Push the address of the MessageBox title
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &error0Addr, 4);
workspaceIndex += 4;
// PUSH 0x000000 - Push the address of the MessageBox message
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &error1Addr, 4);
workspaceIndex += 4;
// Push 0
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, [ADDRESS] - Move the address of MessageBoxA into EAX
workspace[workspaceIndex++] = 0xA1;
memcpy(workspace + workspaceIndex, &msgboxAddr, 4);
workspaceIndex += 4;
// CALL EAX - Call MessageBoxA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// ExitProcess
// Push 0
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, ADDRESS - Move the address of ExitProcess into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &exitprocess, 4);
workspaceIndex += 4;
// CALL EAX - Call MessageBoxA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// Now we have the address of the injected DLL, so save the handle
// MOV [ADDRESS], EAX - Save the address to our variable
workspace[workspaceIndex++] = 0xA3;
memcpy(workspace + workspaceIndex, &dllAddr, 4);
workspaceIndex += 4;
// Load the initilize function from it
// PUSH 0x000000 - Push the address of the function name to load
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &funcNameAddr, 4);
workspaceIndex += 4;
// Push EAX, module to use in GetProcAddress
workspace[workspaceIndex++] = 0x50;
// MOV EAX, ADDRESS - Move the address of GetProcAddress into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &getprocaddress, 4);
workspaceIndex += 4;
// CALL EAX - Call GetProcAddress
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// Error Checking
// CMP EAX, 0
workspace[workspaceIndex++] = 0x83;
workspace[workspaceIndex++] = 0xF8;
workspace[workspaceIndex++] = 0x00;
// JNZ EIP + 0x1C to skip eror code
workspace[workspaceIndex++] = 0x75;
workspace[workspaceIndex++] = 0x1C;
// Error Code 2
// MessageBox
// PUSH 0x10 (MB_ICONHAND)
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x10;
// PUSH 0x000000 - Push the address of the MessageBox title
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &error0Addr, 4);
workspaceIndex += 4;
// PUSH 0x000000 - Push the address of the MessageBox message
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &error2Addr, 4);
workspaceIndex += 4;
// Push 0
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, ADDRESS - Move the address of MessageBoxA into EAX
workspace[workspaceIndex++] = 0xA1;
memcpy(workspace + workspaceIndex, &msgboxAddr, 4);
workspaceIndex += 4;
// CALL EAX - Call MessageBoxA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// ExitProcess
// Push 0
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, ADDRESS - Move the address of ExitProcess into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &exitprocess, 4);
workspaceIndex += 4;
// Now that we have the address of the function, we cam call it,
// if there was an error, the messagebox would be called as well.
// CALL EAX - Call ExitProcess -or- the Initialize function
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// If we get here, the Initialize function has been called,
// so it's time to close this thread and optionally unload the DLL.
//------------------------------------------//
// Exiting from the injected dll. //
//------------------------------------------//
// Call ExitThread to leave the DLL loaded
#if 1
// Push 0 (exit code)
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, ADDRESS - Move the address of ExitThread into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &exitthread, 4);
workspaceIndex += 4;
// CALL EAX - Call ExitThread
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
#endif
// Call FreeLibraryAndExitThread to unload DLL
#if 0
// Push 0 (exit code)
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// PUSH [0x000000] - Push the address of the DLL module to unload
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0x35;
memcpy(workspace + workspaceIndex, &dllAddr, 4);
workspaceIndex += 4;
// MOV EAX, ADDRESS - Move the address of FreeLibraryAndExitThread into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &freelibraryandexitthread, 4);
workspaceIndex += 4;
// CALL EAX - Call FreeLibraryAndExitThread
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
#endif
//------------------------------------------//
// Code injection and cleanup. //
//------------------------------------------//
// Change page protection so we can write executable code
VirtualProtectEx(hProcess, codecaveAddress, workspaceIndex, PAGE_EXECUTE_READWRITE, &oldProtect);
// Write out the patch
WriteProcessMemory(hProcess, codecaveAddress, workspace, workspaceIndex, &bytesRet);
// Restore page protection
VirtualProtectEx(hProcess, codecaveAddress, workspaceIndex, oldProtect, &oldProtect);
// Make sure our changes are written right away
FlushInstructionCache(hProcess, codecaveAddress, workspaceIndex);
// Free the workspace memory
HeapFree(GetProcessHeap(), 0, workspace);
// Execute the thread now and wait for it to exit, note we execute where the code starts, and not the codecave start
// (since we wrote strings at the start of the codecave) -- NOTE: void* used for VC6 compatibility instead of UlongToPtr
hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)((void*)codecaveExecAddr), 0, 0, NULL);
WaitForSingleObject(hThread, INFINITE);
// Free the memory in the process that we allocated
VirtualFreeEx(hProcess, codecaveAddress, 0, MEM_RELEASE);
}
-27
View File
@@ -1,27 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_INJECTDIRECTLY_H_
#define uMod_INJECTDIRECTLY_H_
void Inject(HANDLE hProcess, const wchar_t* dllname, const char* funcname);
#endif /* uMod_INJECTDIRECTLY_H_ */
-23
View File
@@ -1,23 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uMod_Main.h"
-70
View File
@@ -1,70 +0,0 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_EVENTTYPE_H_
#define uMod_EVENTTYPE_H_
#include "uMod_Client.h"
#include "uMod_Main.h"
//we need our own event to pass send some arguments from the server or the client thread to the main thread
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE( uMod_EVENT_TYPE, -1)
END_DECLARE_EVENT_TYPES()
class uMod_Event : public wxCommandEvent
{
public:
uMod_Event( wxEventType commandType = uMod_EVENT_TYPE, int id = 0 )
: wxCommandEvent(commandType, id) { }
virtual ~uMod_Event(void) {}
// You *must* copy here the data to be transported
uMod_Event( const uMod_Event &event )
: wxCommandEvent(event) { this->SetText( event.GetText()); PipeIn=((uMod_Event&)event).GetPipeIn(); PipeOut=((uMod_Event&)event).GetPipeOut(); Name=((uMod_Event&)event).GetName(); Client=((uMod_Event&)event).GetClient();}
// Required for sending with wxPostEvent()
wxEvent* Clone() const { return new uMod_Event(*this); }
wxString GetText() const { return m_Text; }
void SetText( const wxString& text ) { m_Text = text; }
wxString GetName(void) {return Name;}
HANDLE GetPipeIn(void) {return PipeIn;}
HANDLE GetPipeOut(void) {return PipeOut;}
uMod_Client * GetClient(void) {return Client;}
void SetName( wxString name) {Name=name;}
void SetPipeIn( HANDLE pipe) {PipeIn=pipe;}
void SetPipeOut( HANDLE pipe) {PipeOut=pipe;}
void SetClient( uMod_Client *client) {Client=client;}
private:
wxString Name;
HANDLE PipeIn;
HANDLE PipeOut;
uMod_Client *Client;
wxString m_Text;
};
#endif /* uMod_EVENTTYPE_H_ */

Some files were not shown because too many files have changed in this diff Show More