diff --git a/.gitattributes b/.gitattributes
index 8e948c5..a72d5de 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,50 @@
* text=auto !eol
+OTM_DX9/.cproject -text
+OTM_DX9/.project -text
+OTM_DX9/.settings/org.eclipse.cdt.codan.core.prefs -text
+OTM_DX9/.settings/org.eclipse.cdt.managedbuilder.core.prefs -text
+OTM_DX9/OTM_ArrayHandler.cpp -text
+OTM_DX9/OTM_ArrayHandler.h -text
+OTM_DX9/OTM_DX9_dll.cpp -text
+OTM_DX9/OTM_DX9_dll.def -text
+OTM_DX9/OTM_DX9_dll.h -text
+OTM_DX9/OTM_DX9_dll_NO_INJECTION.def -text
+OTM_DX9/OTM_Defines.h -text
+OTM_DX9/OTM_IDirect3D9.cpp -text
+OTM_DX9/OTM_IDirect3D9.h -text
+OTM_DX9/OTM_IDirect3DDevice9.cpp -text
+OTM_DX9/OTM_IDirect3DDevice9.h -text
+OTM_DX9/OTM_IDirect3DTexture9.cpp -text
+OTM_DX9/OTM_IDirect3DTexture9.h -text
+OTM_DX9/OTM_Main.h -text
+OTM_DX9/OTM_TextureClient.cpp -text
+OTM_DX9/OTM_TextureClient.h -text
+OTM_DX9/OTM_TextureServer.cpp -text
+OTM_DX9/OTM_TextureServer.h -text
+OTM_DX9/makefile -text
+/OTM_Error.h -text
+OTM_GUI/.cproject -text
+OTM_GUI/.project -text
+OTM_GUI/OTM.ico -text
+OTM_GUI/OTM.rc -text
+OTM_GUI/OTM_Client.cpp -text
+OTM_GUI/OTM_Client.h -text
+OTM_GUI/OTM_Event.cpp -text
+OTM_GUI/OTM_Event.h -text
+OTM_GUI/OTM_GUI.cpp -text
+OTM_GUI/OTM_GUI.h -text
+OTM_GUI/OTM_GUI.ico -text
+OTM_GUI/OTM_GameInfo.cpp -text
+OTM_GUI/OTM_GameInfo.h -text
+OTM_GUI/OTM_GamePage.cpp -text
+OTM_GUI/OTM_GamePage.h -text
+OTM_GUI/OTM_Language.cpp -text
+OTM_GUI/OTM_Language.h -text
+OTM_GUI/OTM_Main.h -text
+OTM_GUI/OTM_Sender.cpp -text
+OTM_GUI/OTM_Sender.h -text
+OTM_GUI/OTM_Server.cpp -text
+OTM_GUI/OTM_Server.h -text
+OTM_GUI/config.gcc -text
+OTM_GUI/makefile -text
+/OTM_GlobalDefines.h -text
diff --git a/OTM_DX9/.cproject b/OTM_DX9/.cproject
new file mode 100644
index 0000000..11576fa
--- /dev/null
+++ b/OTM_DX9/.cproject
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OTM_DX9/.project b/OTM_DX9/.project
new file mode 100644
index 0000000..fc3fd60
--- /dev/null
+++ b/OTM_DX9/.project
@@ -0,0 +1,70 @@
+
+
+ OTM_DX9
+
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+
+
+ ?name?
+
+
+
+ org.eclipse.cdt.make.core.append_environment
+ true
+
+
+ org.eclipse.cdt.make.core.buildArguments
+
+
+
+ org.eclipse.cdt.make.core.buildCommand
+ make
+
+
+ org.eclipse.cdt.make.core.buildLocation
+ ${workspace_loc:/OTM_DX9/Default}
+
+
+ org.eclipse.cdt.make.core.contents
+ org.eclipse.cdt.make.core.activeConfigSettings
+
+
+ org.eclipse.cdt.make.core.enableAutoBuild
+ true
+
+
+ org.eclipse.cdt.make.core.enableCleanBuild
+ true
+
+
+ org.eclipse.cdt.make.core.enableFullBuild
+ true
+
+
+ org.eclipse.cdt.make.core.stopOnError
+ true
+
+
+ org.eclipse.cdt.make.core.useDefaultBuildCmd
+ true
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.core.ccnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
diff --git a/OTM_DX9/.settings/org.eclipse.cdt.codan.core.prefs b/OTM_DX9/.settings/org.eclipse.cdt.codan.core.prefs
new file mode 100644
index 0000000..0722ad0
--- /dev/null
+++ b/OTM_DX9/.settings/org.eclipse.cdt.codan.core.prefs
@@ -0,0 +1,67 @@
+#Mon Aug 22 20:44:58 CEST 2011
+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}}
+useParentScope=false
diff --git a/OTM_DX9/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/OTM_DX9/.settings/org.eclipse.cdt.managedbuilder.core.prefs
new file mode 100644
index 0000000..1229533
--- /dev/null
+++ b/OTM_DX9/.settings/org.eclipse.cdt.managedbuilder.core.prefs
@@ -0,0 +1,14 @@
+#Sun Aug 21 14:35:07 CEST 2011
+eclipse.preferences.version=1
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/CPATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/CPATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/CPLUS_INCLUDE_PATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/CPLUS_INCLUDE_PATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/C_INCLUDE_PATH/delimiter=;
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/C_INCLUDE_PATH/operation=remove
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/append=true
+environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/appendContributed=true
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/LIBRARY_PATH/delimiter=;
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/LIBRARY_PATH/operation=remove
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/append=true
+environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1686594558/appendContributed=true
diff --git a/OTM_DX9/OTM_ArrayHandler.cpp b/OTM_DX9/OTM_ArrayHandler.cpp
new file mode 100644
index 0000000..14ea10c
--- /dev/null
+++ b/OTM_DX9/OTM_ArrayHandler.cpp
@@ -0,0 +1,224 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+
+#include "OTM_Main.h"
+
+
+
+
+
+OTM_FileHandler::OTM_FileHandler(void)
+{
+ Message("OTM_FileHandler(void): %lu\n", this);
+ Number = 0;
+ FieldCounter = 0;
+ Files = NULL;
+}
+
+OTM_FileHandler::~OTM_FileHandler(void)
+{
+ Message("~OTM_FileHandler(void): %lu\n", this);
+ if (Files!=NULL)
+ {
+ for (int i=0; iReference>=0) return (RETURN_UPDATE_ALLREADY_ADDED);
+
+ if (Number/FieldLength==FieldCounter)
+ {
+ TextureFileStruct*** temp = NULL;
+ try {temp = new TextureFileStruct**[FieldCounter+10];}
+ catch (...)
+ {
+ gl_ErrorState |= OTM_ERROR_MEMORY | OTM_ERROR_TEXTURE;
+ return (RETURN_NO_MEMORY);
+ }
+
+ for (int i=0; iReference = Number++;
+
+ return (RETURN_OK);
+}
+
+
+int OTM_FileHandler::Remove(TextureFileStruct* file)
+{
+ Message("OTM_FileHandler::Remove(%lu): %lu\n", file, this);
+ if (gl_ErrorState & OTM_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;
+ if (ref<--Number)
+ {
+ Files[ref/FieldLength][ref%FieldLength] = Files[Number/FieldLength][Number%FieldLength];
+ }
+ return (RETURN_OK);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+OTM_TextureHandler::OTM_TextureHandler(void)
+{
+ Message("OTM_TextureHandler(void): %lu\n", this);
+ Number = 0;
+ FieldCounter = 0;
+
+ Textures = NULL;
+}
+
+OTM_TextureHandler::~OTM_TextureHandler(void)
+{
+ Message("~OTM_TextureHandler(void): %lu\n", this);
+ if (Textures!=NULL)
+ {
+ for (int i=0; iTextureHandlerRef>=0) return (RETURN_TEXTURE_ALLREADY_ADDED);
+
+ if (Number/FieldLength==FieldCounter)
+ {
+ OTM_IDirect3DTexture9*** temp = NULL;
+ try {temp = new OTM_IDirect3DTexture9**[FieldCounter+10];}
+ catch (...)
+ {
+ gl_ErrorState |= OTM_ERROR_MEMORY | OTM_ERROR_TEXTURE;
+ return (RETURN_NO_MEMORY);
+ }
+
+ for (int i=0; iTextureHandlerRef = Number++;
+
+ return (RETURN_OK);
+}
+
+
+int OTM_TextureHandler::Remove(OTM_IDirect3DTexture9* pTexture) //will be called, if a texture is completely released
+{
+ Message("OTM_TextureHandler::Remove( %lu): %lu\n", pTexture, this);
+ if (gl_ErrorState & OTM_ERROR_FATAL) return (RETURN_FATAL_ERROR);
+
+ int ref = pTexture->TextureHandlerRef;
+ if (ref<0) return (RETURN_OK); // returning if no TextureHandlerRef is set
+
+ UnswitchTextures( pTexture);
+
+ if (ref<(--Number))
+ {
+ Textures[ref/FieldLength][ref%FieldLength] = Textures[Number/FieldLength][Number%FieldLength];
+ }
+ return (RETURN_OK);
+}
+
+int OTM_TextureHandler::RemoveAll(void) //only for deleting all fake textures
+{
+ Message("OTM_TextureHandler::RemoveAll() %d: %lu\n", Number, this);
+ for (int i=0; iRelease();
+ Number=0;
+ return (RETURN_OK);
+}
diff --git a/OTM_DX9/OTM_ArrayHandler.h b/OTM_DX9/OTM_ArrayHandler.h
new file mode 100644
index 0000000..f685e07
--- /dev/null
+++ b/OTM_DX9/OTM_ArrayHandler.h
@@ -0,0 +1,81 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_FIELDHANDLER_H_
+#define OTM_FIELDHANDLER_H_
+
+#include "..\OTM_GlobalDefines.h"
+#include "OTM_IDirect3DTexture9.h"
+
+typedef struct
+{
+ bool Checked; // to check if texture was already update; used by TextureClient::MergeUpdate()
+ 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 Reference; // for a fast delete in the FileHandler
+ OTM_IDirect3DTexture9 *pTexture; // pointer to the fake texture
+ MyTypeHash Hash; // hash value
+} TextureFileStruct;
+
+
+
+class OTM_FileHandler // array to store TextureFileStruct
+{
+public:
+ OTM_FileHandler(void);
+ ~OTM_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;
+};
+
+class OTM_TextureHandler // array to store OTM_IDirect3DTexture9
+{
+public:
+ OTM_TextureHandler(void);
+ ~OTM_TextureHandler(void);
+
+ int Add( OTM_IDirect3DTexture9* texture);
+ int Remove( OTM_IDirect3DTexture9* texture);
+ int RemoveAll(void); //only for deleting all fake textures
+
+ int GetNumber(void) {return (Number);}
+ OTM_IDirect3DTexture9 *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;
+ OTM_IDirect3DTexture9*** Textures;
+};
+
+
+#endif /* OTM_FIELDHANDLER_H_ */
diff --git a/OTM_DX9/OTM_DX9_dll.cpp b/OTM_DX9/OTM_DX9_dll.cpp
new file mode 100644
index 0000000..089efbd
--- /dev/null
+++ b/OTM_DX9/OTM_DX9_dll.cpp
@@ -0,0 +1,324 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+/*
+
+
+ NEVER USE THIS CODE FOR ILLEGAL PURPOSE
+
+
+*/
+
+
+#include "OTM_Main.h"
+#include
+
+#pragma comment(lib, "Shlwapi.lib")
+
+
+OTM_IDirect3DDevice9* gl_pIDirect3DDevice9 = NULL;
+OTM_IDirect3D9* gl_pIDirect3D9 = NULL;
+HINSTANCE gl_hOriginalDll = NULL;
+HINSTANCE gl_hThisInstance = NULL;
+unsigned int gl_ErrorState = 0u;
+OTM_TextureServer* gl_TextureServer = NULL;
+FILE* gl_File =NULL;
+HANDLE gl_ServerThread = NULL;
+
+BOOL APIENTRY 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;
+ }
+ case DLL_THREAD_ATTACH: break;
+ case DLL_THREAD_DETACH: break;
+ }
+
+ return (true);
+}
+
+
+
+#ifdef NO_INJECTION
+IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
+{
+ Message("WINAPI Direct3DCreate9\n");
+ //MessageBox( NULL, TEXT( "Create 3D" ), TEXT( "Timer" ), MB_OK );
+ if (!gl_hOriginalDll) LoadOriginalDll(); // looking for the "right d3d9.dll"
+
+ // Hooking IDirect3D Object from Original Library
+ typedef IDirect3D9 *(WINAPI* D3D9_Type)(UINT SDKVersion);
+ D3D9_Type D3DCreate9_fn = (D3D9_Type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
+
+ // Debug
+ if (!D3DCreate9_fn)
+ {
+ OutputDebugString("PROXYDLL: Pointer to original D3DCreate9 function not received ERROR ****\r\n");
+ ::ExitProcess(0); // exit the hard way
+ }
+
+
+ if (gl_pIDirect3D9!=NULL) gl_ErrorState |= OTM_ERROR_MULTIPLE_IDirect3D9;
+ // Request pointer from Original Dll.
+ IDirect3D9 *pIDirect3D9_orig = D3DCreate9_fn(SDKVersion);
+ gl_pIDirect3D9 = new OTM_IDirect3D9( pIDirect3D9_orig, gl_TextureServer);
+
+ //MessageBeep( MB_ICONINFORMATION );
+
+
+ //MessageBox( NULL, TEXT( "Create 3D" ), TEXT( "Timer" ), MB_OK );
+ // Create my IDirect3D8 object and store pointer to original object there.
+ // note: the object will delete itself once Ref count is zero (similar to COM objects)
+
+ // Return pointer to hooking Object instead of "real one"
+ return (gl_pIDirect3D9);
+}
+#else
+
+
+typedef IDirect3D9 *(APIENTRY *Direct3DCreate9_type)(UINT);
+Direct3DCreate9_type Direct3DCreate9_fn;
+
+bool RetourFunc(BYTE *src, BYTE *restore, const int len);
+void *DetourFunc(BYTE *src, const BYTE *dst, const int len);
+
+IDirect3D9 *APIENTRY MyDirect3DCreate9(UINT SDKVersion)
+{
+ Message("Direct3DCreate9_fn %lu, my %lu\n", Direct3DCreate9_fn ,MyDirect3DCreate9);
+
+ // in the Internet are many tutorials for detouring functions and all of them will work without the following 3 marked lines
+ // but somehow, for me it only works, if I detour 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");
+ // END
+
+ IDirect3D9 *pIDirect3D9_orig = NULL;
+ if (Direct3DCreate9_fn)
+ {
+ pIDirect3D9_orig = Direct3DCreate9_fn(SDKVersion);
+ }
+ else return (NULL);
+ if (pIDirect3D9_orig)
+ {
+ gl_pIDirect3D9 = new OTM_IDirect3D9( pIDirect3D9_orig, gl_TextureServer);
+ }
+ return (gl_pIDirect3D9);
+}
+#endif
+
+bool HookThisProgramm( wchar_t *ret)
+{
+ //This method should be changed. Maybe the directory should be the user application directory.
+ FILE* file;
+ if (_wfopen_s( &file, L"D:\\OTM.txt", L"rt")) return (false);
+
+ wchar_t Executable[MAX_PATH];
+ wchar_t Game[MAX_PATH];
+ GetModuleFileNameW( GetModuleHandle( NULL ), Executable, MAX_PATH );
+ PathStripPathW( Executable );
+
+ while (!feof(file))
+ {
+ if ( fgetws ( Game, MAX_PATH, file) != NULL )
+ {
+ int len = 0;
+ while (Game[len])
+ {
+ if (Game[len]=='\r' || Game[len]=='\n') {Game[len]=0; break;}
+ len++;
+ }
+ if ( _wcsicmp( Executable, Game ) == 0 )
+ {
+ for (int i=0; iMainLoop();
+ return (0);
+}
+
+void InitInstance(HINSTANCE hModule)
+{
+ DisableThreadLibraryCalls( hModule );
+
+ gl_hThisInstance = (HINSTANCE) hModule;
+
+ wchar_t game[MAX_PATH];
+ if (HookThisProgramm( game))
+ {
+ OpenMessage();
+ Message("InitInstance: %lu\n", hModule);
+
+ gl_TextureServer = new OTM_TextureServer();
+ if (gl_TextureServer!=NULL)
+ {
+ if (gl_TextureServer->OpenPipe( game))
+ {
+ Message("InitInstance: Pipe not opened\n");
+ return;
+ }
+ gl_ServerThread = CreateThread( NULL, 0, ServerThread, NULL, 0, NULL);
+ if (gl_ServerThread==NULL) Message("InitInstance: Serverthread not started\n");
+
+ //this is for testing purpose, these function should be called from the server thread, provoked by the OTM_GUI
+ //gl_TextureServer->SaveAllTextures(true);
+ //gl_TextureServer->SetSaveDirectory("tex\\");
+ /*
+ gl_TextureServer->AddFile("BF_0xbc2a9196.dds", 0xbc2a9196ul);
+ gl_TextureServer->AddFile("0X1FD33669.dds", 0X1FD33669ul);
+ gl_TextureServer->AddFile("0X26D19B9A.dds", 0X26D19B9Aul);
+ gl_TextureServer->AddFile("0X72E92068.dds", 0X72E92068ul);
+ gl_TextureServer->AddFile("0X714DFA26.dds", 0X714DFA26ul);
+ gl_TextureServer->AddFile("0X74499208.dds", 0X74499208ul);
+ gl_TextureServer->AddFile("0XA3BFD8EA.dds", 0XA3BFD8EAul);
+ */
+ }
+ LoadOriginalDll();
+
+ // we detour the original Direct3DCreate9 to our MyDirect3DCreate9
+ Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc(
+ (BYTE*)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9"),
+ (BYTE*)MyDirect3DCreate9,
+ 5);
+ }
+}
+
+
+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);
+
+ // Debug
+ 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();
+}
+
+
+#ifndef NO_INJECTION
+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);
+}
+
+
+
+
+
+
+
+
+
+HHOOK gl_hHook = NULL;
+LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
+{
+ return (CallNextHookEx( gl_hHook, nCode, wParam, lParam));
+}
+
+void InstallHook()
+{
+ gl_hHook = SetWindowsHookEx( WH_CBT, HookProc, gl_hThisInstance, 0 );
+}
+
+void RemoveHook()
+{
+ UnhookWindowsHookEx( gl_hHook );
+}
+#endif
diff --git a/OTM_DX9/OTM_DX9_dll.def b/OTM_DX9/OTM_DX9_dll.def
new file mode 100644
index 0000000..cf5a4bb
--- /dev/null
+++ b/OTM_DX9/OTM_DX9_dll.def
@@ -0,0 +1,5 @@
+LIBRARY "d3d9"
+EXPORTS
+ MyDirect3DCreate9 @1
+ InstallHook @2
+ RemoveHook @3
\ No newline at end of file
diff --git a/OTM_DX9/OTM_DX9_dll.h b/OTM_DX9/OTM_DX9_dll.h
new file mode 100644
index 0000000..1ca8add
--- /dev/null
+++ b/OTM_DX9/OTM_DX9_dll.h
@@ -0,0 +1,28 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_DX9_DLL_H_
+#define OTM_DX9_DLL_H_
+
+void InitInstance(HINSTANCE hModule);
+void ExitInstance(void);
+void LoadOriginalDll(void);
+
+#endif
diff --git a/OTM_DX9/OTM_DX9_dll_NO_INJECTION.def b/OTM_DX9/OTM_DX9_dll_NO_INJECTION.def
new file mode 100644
index 0000000..ccb49e6
--- /dev/null
+++ b/OTM_DX9/OTM_DX9_dll_NO_INJECTION.def
@@ -0,0 +1,3 @@
+LIBRARY "d3d9"
+EXPORTS
+ Direct3DCreate9 @1
\ No newline at end of file
diff --git a/OTM_DX9/OTM_Defines.h b/OTM_DX9/OTM_Defines.h
new file mode 100644
index 0000000..0aafa1f
--- /dev/null
+++ b/OTM_DX9/OTM_Defines.h
@@ -0,0 +1,51 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_DEFINES_H_
+#define OTM_DEFINES_H_
+
+
+#define Message(...) {if (gl_File!=NULL) {fprintf( gl_File, __VA_ARGS__); fflush(gl_File);}}
+#define OpenMessage(...) {if (fopen_s( &gl_File, "OTM_log.txt", "wt")) gl_File=NULL;}
+#define CloseMessage(...) {if (gl_File!=NULL) fclose(gl_File);}
+
+//#define OpenMessage(...)
+//#define Message(...)
+//#define CloseMessage(...)
+
+#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 /* OTM_DEFINES_H_ */
diff --git a/OTM_DX9/OTM_IDirect3D9.cpp b/OTM_DX9/OTM_IDirect3D9.cpp
new file mode 100644
index 0000000..e611ea3
--- /dev/null
+++ b/OTM_DX9/OTM_IDirect3D9.cpp
@@ -0,0 +1,176 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+
+
+#include "OTM_Main.h"
+
+OTM_IDirect3D9::OTM_IDirect3D9(IDirect3D9 *pOriginal, OTM_TextureServer* server)
+{
+ Message("OTM_IDirect3D9( %lu, %lu): %lu\n", pOriginal, server, this);
+ //MessageBox( NULL, TEXT( "Init OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ m_pIDirect3D9 = pOriginal;
+ OTM_Server = server;
+}
+
+OTM_IDirect3D9::~OTM_IDirect3D9(void)
+{
+}
+
+HRESULT __stdcall OTM_IDirect3D9::QueryInterface(REFIID riid, void** ppvObj)
+{
+ //MessageBox( NULL, TEXT( "QueryInterface OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ *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 OTM_IDirect3D9::AddRef(void)
+{
+ //MessageBox( NULL, TEXT( "AddRef OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->AddRef());
+}
+
+ULONG __stdcall OTM_IDirect3D9::Release(void)
+{
+ //MessageBox( NULL, TEXT( "Release OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+
+ // call original routine
+ ULONG count = m_pIDirect3D9->Release();
+
+ // in case no further Ref is there, the Original Object has deleted itself
+ // so do we here
+ if (count == 0)
+ {
+ //MessageBox( NULL, TEXT( "Release everything" ), TEXT( "Timer" ), MB_OK );
+ //extern OTM_IDirect3D9* gl_pOTM_IDirect3D9;
+ gl_pIDirect3D9 = NULL;
+ delete(this);
+ }
+
+ return(count);
+}
+
+HRESULT __stdcall OTM_IDirect3D9::RegisterSoftwareDevice(void* pInitializeFunction)
+{
+ //MessageBox( NULL, TEXT( "RegisterSoftwareDevice OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->RegisterSoftwareDevice(pInitializeFunction));
+}
+
+UINT __stdcall OTM_IDirect3D9::GetAdapterCount(void)
+{
+ //MessageBox( NULL, TEXT( "GetAdapterCount OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->GetAdapterCount());
+}
+
+HRESULT __stdcall OTM_IDirect3D9::GetAdapterIdentifier(UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier)
+{
+ //MessageBox( NULL, TEXT( "GetAdapterIdentifier OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->GetAdapterIdentifier(Adapter,Flags,pIdentifier));
+}
+
+UINT __stdcall OTM_IDirect3D9::GetAdapterModeCount(UINT Adapter, D3DFORMAT Format)
+{
+ //MessageBox( NULL, TEXT( "GetAdapterModeCount OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->GetAdapterModeCount(Adapter, Format));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::EnumAdapterModes(UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode)
+{
+ //MessageBox( NULL, TEXT( "QueryInterface OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->EnumAdapterModes(Adapter,Format,Mode,pMode));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::GetAdapterDisplayMode( UINT Adapter,D3DDISPLAYMODE* pMode)
+{
+ //MessageBox( NULL, TEXT( "EnumAdapterModes OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->GetAdapterDisplayMode(Adapter,pMode));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::CheckDeviceType(UINT iAdapter,D3DDEVTYPE DevType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed)
+{
+ //MessageBox( NULL, TEXT( "CheckDeviceType OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->CheckDeviceType(iAdapter,DevType,DisplayFormat,BackBufferFormat,bWindowed));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::CheckDeviceFormat(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat)
+{
+ //MessageBox( NULL, TEXT( "CheckDeviceFormat OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->CheckDeviceFormat(Adapter,DeviceType,AdapterFormat,Usage,RType,CheckFormat));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::CheckDeviceMultiSampleType(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels)
+{
+ //MessageBox( NULL, TEXT( "CheckDeviceMultiSampleType OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->CheckDeviceMultiSampleType(Adapter,DeviceType,SurfaceFormat,Windowed,MultiSampleType,pQualityLevels));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::CheckDepthStencilMatch(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat)
+{
+ //MessageBox( NULL, TEXT( "CheckDepthStencilMatch OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->CheckDepthStencilMatch(Adapter,DeviceType,AdapterFormat,RenderTargetFormat,DepthStencilFormat));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::CheckDeviceFormatConversion(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat)
+{
+ //MessageBox( NULL, TEXT( "CheckDeviceFormatConversion OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->CheckDeviceFormatConversion(Adapter,DeviceType,SourceFormat,TargetFormat));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::GetDeviceCaps(UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps)
+{
+ //MessageBox( NULL, TEXT( "GetDeviceCaps OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->GetDeviceCaps(Adapter,DeviceType,pCaps));
+}
+
+HMONITOR __stdcall OTM_IDirect3D9::GetAdapterMonitor(UINT Adapter)
+{
+ //MessageBox( NULL, TEXT( "GetAdapterMonitor OTM_IDirect3D9" ), TEXT( "Timer" ), MB_OK );
+ return(m_pIDirect3D9->GetAdapterMonitor(Adapter));
+}
+
+HRESULT __stdcall OTM_IDirect3D9::CreateDevice(UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface)
+{
+
+ // we intercept this call and provide our own "fake" Device Object
+ HRESULT hres = m_pIDirect3D9->CreateDevice( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
+
+ // Create our own Device object and store it in global pointer
+ // note: the object will delete itself once Ref count is zero (similar to COM objects)
+
+ if (gl_pIDirect3DDevice9!=NULL) gl_ErrorState |= OTM_ERROR_MULTIPLE_IDirect3DDevice9;
+ gl_pIDirect3DDevice9 = new OTM_IDirect3DDevice9(*ppReturnedDeviceInterface, OTM_Server);
+
+
+ // store our pointer (the fake one) for returning it to the calling progam
+ *ppReturnedDeviceInterface = gl_pIDirect3DDevice9;
+
+ return(hres);
+}
diff --git a/OTM_DX9/OTM_IDirect3D9.h b/OTM_DX9/OTM_IDirect3D9.h
new file mode 100644
index 0000000..4826900
--- /dev/null
+++ b/OTM_DX9/OTM_IDirect3D9.h
@@ -0,0 +1,61 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_IDirect3D9_H_
+#define OTM_IDirect3D9_H_
+
+
+#include
+#include
+#include "OTM_TextureServer.h"
+#include "OTM_TextureClient.h"
+
+class OTM_IDirect3D9 : public IDirect3D9
+{
+public:
+ OTM_IDirect3D9(IDirect3D9 *pOriginal, OTM_TextureServer *server);
+ virtual ~OTM_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) ;
+ // The original DX9 function definitions
+
+//private:
+ IDirect3D9 *m_pIDirect3D9;
+ OTM_TextureServer* OTM_Server;
+};
+
+#endif
diff --git a/OTM_DX9/OTM_IDirect3DDevice9.cpp b/OTM_DX9/OTM_IDirect3DDevice9.cpp
new file mode 100644
index 0000000..b6e1101
--- /dev/null
+++ b/OTM_DX9/OTM_IDirect3DDevice9.cpp
@@ -0,0 +1,788 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#include "OTM_Main.h"
+
+
+int OTM_IDirect3DDevice9::SaveSingleTexture(bool val)
+{
+ if (val==BoolSaveSingleTexture) return (RETURN_OK);
+ if (val && SingleTexture==NULL) //Create green texture
+ {
+ if( D3D_OK != CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, (IDirect3DTexture9**) &SingleTexture, NULL)) return (RETURN_TEXTURE_NOT_LOADED);
+
+ DWORD colour32 = D3DCOLOR_ARGB(255,0,255,0); //green
+ WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
+ |(WORD)(((colour32>>20)&0xF)<<8)
+ |(WORD)(((colour32>>12)&0xF)<<4)
+ |(WORD)(((colour32>>4)&0xF)<<0);
+
+ D3DLOCKED_RECT d3dlr;
+ IDirect3DTexture9 *pD3Dtex = SingleTexture->m_D3Dtex;
+
+ if (D3D_OK!=pD3Dtex->LockRect(0, &d3dlr, 0, 0))
+ {
+ SingleTexture->Release();
+ SingleTexture=NULL;
+ return (RETURN_TEXTURE_NOT_LOADED);
+ }
+ WORD *pDst16 = (WORD*)d3dlr.pBits;
+
+ for (int xy=0; xy < 8*8; xy++) *(pDst16++) = colour16;
+ pD3Dtex->UnlockRect(0);
+ }
+ else if (!val && SingleTexture!=NULL)
+ {
+ UnswitchTextures(SingleTexture);
+ }
+
+ BoolSaveSingleTexture = val;
+ return (RETURN_OK);
+}
+
+OTM_IDirect3DDevice9::OTM_IDirect3DDevice9(IDirect3DDevice9* pOriginal, OTM_TextureServer* server)
+{
+ Message("OTM_IDirect3DDevice9( %lu, %lu): %lu\n", pOriginal, server, this);
+ OTM_Server = server;
+ OTM_Client = new OTM_TextureClient( OTM_Server, this);
+ LastCreatedTexture = NULL;
+ m_pIDirect3DDevice9 = pOriginal; // store the pointer to original object
+
+ KeyBack = 0;
+ KeySave = 0;
+ KeyNext = 0;
+ BoolSaveSingleTexture = false;
+ CounterSaveSingleTexture = 0;
+ SingleTexture = NULL;
+ //Message("end OTM_IDirect3DDevice9( %lu, %lu): %lu\n", pOriginal, server, this);
+}
+
+OTM_IDirect3DDevice9::~OTM_IDirect3DDevice9(void)
+{
+}
+
+HRESULT OTM_IDirect3DDevice9::QueryInterface (REFIID riid, void** ppvObj)
+{
+ // check if original dll can provide interface. then send *our* address
+ *ppvObj = NULL;
+
+ HRESULT hRes = m_pIDirect3DDevice9->QueryInterface(riid, ppvObj);
+
+ if (hRes == NOERROR)
+ {
+ *ppvObj = this;
+ }
+
+ return (hRes);
+}
+
+ULONG OTM_IDirect3DDevice9::AddRef(void)
+{
+ return (m_pIDirect3DDevice9->AddRef());
+}
+
+ULONG OTM_IDirect3DDevice9::Release(void)
+{
+ // ATTENTION: This is a booby-trap ! Watch out !
+ // If we create our own sprites, surfaces, etc. (thus increasing the ref counter
+ // by external action), we need to delete that objects before calling the original
+ // Release function
+
+
+ // release/delete own objects
+ // .....
+
+ // Calling original function now
+ ULONG count = m_pIDirect3DDevice9->Release();
+ Message("%d = Release(): %lu\n", count, this);
+
+ if (count==0)
+ {
+ // now, the Original Object has deleted itself, so do we here
+ if (OTM_Client!=NULL)
+ {
+ OTM_Client->ReleaseAllFakeTexture();
+ delete OTM_Client;
+ OTM_Client = NULL;
+ }
+
+ //if (gl_pTextureHandler!=NULL) gl_pTextureHandler->ReleaseAllFakeTexture(); // release all fake textures
+ //gl_pIDirect3DDevice9 = NULL;
+ delete(this); // destructor will be called automatically
+ }
+
+ return (count);
+}
+
+HRESULT OTM_IDirect3DDevice9::TestCooperativeLevel(void)
+{
+ return(m_pIDirect3DDevice9->TestCooperativeLevel());
+}
+
+UINT OTM_IDirect3DDevice9::GetAvailableTextureMem(void)
+{
+ return(m_pIDirect3DDevice9->GetAvailableTextureMem());
+}
+
+HRESULT OTM_IDirect3DDevice9::EvictManagedResources(void)
+{
+ return(m_pIDirect3DDevice9->EvictManagedResources());
+}
+
+HRESULT OTM_IDirect3DDevice9::GetDirect3D(IDirect3D9** ppD3D9)
+{
+ return(m_pIDirect3DDevice9->GetDirect3D(ppD3D9));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetDeviceCaps(D3DCAPS9* pCaps)
+{
+ return(m_pIDirect3DDevice9->GetDeviceCaps(pCaps));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetDisplayMode(UINT iSwapChain,D3DDISPLAYMODE* pMode)
+{
+ return(m_pIDirect3DDevice9->GetDisplayMode(iSwapChain, pMode));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters)
+{
+ return(m_pIDirect3DDevice9->GetCreationParameters(pParameters));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetCursorProperties(UINT XHotSpot,UINT YHotSpot,IDirect3DSurface9* pCursorBitmap)
+{
+ return(m_pIDirect3DDevice9->SetCursorProperties(XHotSpot,YHotSpot,pCursorBitmap));
+}
+
+void OTM_IDirect3DDevice9::SetCursorPosition(int X,int Y,DWORD Flags)
+{
+ m_pIDirect3DDevice9->SetCursorPosition(X,Y,Flags);
+}
+
+BOOL OTM_IDirect3DDevice9::ShowCursor(BOOL bShow)
+{
+ return(m_pIDirect3DDevice9->ShowCursor(bShow));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain9** pSwapChain)
+{
+ return(m_pIDirect3DDevice9->CreateAdditionalSwapChain(pPresentationParameters,pSwapChain));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetSwapChain(UINT iSwapChain,IDirect3DSwapChain9** pSwapChain)
+{
+ return(m_pIDirect3DDevice9->GetSwapChain(iSwapChain,pSwapChain));
+}
+
+UINT OTM_IDirect3DDevice9::GetNumberOfSwapChains(void)
+{
+ return(m_pIDirect3DDevice9->GetNumberOfSwapChains());
+}
+
+HRESULT OTM_IDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParameters)
+{
+ return(m_pIDirect3DDevice9->Reset(pPresentationParameters));
+}
+
+HRESULT OTM_IDirect3DDevice9::Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
+{
+ // we may want to draw own things here before flipping surfaces
+ // ... draw own stuff ...
+ //this->ShowWeAreHere();
+
+ // call original routine
+ HRESULT hres = m_pIDirect3DDevice9->Present( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
+
+ return (hres);
+}
+
+HRESULT OTM_IDirect3DDevice9::GetBackBuffer(UINT iSwapChain,UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer)
+{
+ return(m_pIDirect3DDevice9->GetBackBuffer(iSwapChain,iBackBuffer,Type,ppBackBuffer));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetRasterStatus(UINT iSwapChain,D3DRASTER_STATUS* pRasterStatus)
+{
+ return(m_pIDirect3DDevice9->GetRasterStatus(iSwapChain,pRasterStatus));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetDialogBoxMode(BOOL bEnableDialogs)
+{
+ return(m_pIDirect3DDevice9->SetDialogBoxMode(bEnableDialogs));
+}
+
+void OTM_IDirect3DDevice9::SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp)
+{
+ (m_pIDirect3DDevice9->SetGammaRamp(iSwapChain,Flags,pRamp));
+}
+
+void OTM_IDirect3DDevice9::GetGammaRamp(UINT iSwapChain,D3DGAMMARAMP* pRamp)
+{
+ (m_pIDirect3DDevice9->GetGammaRamp(iSwapChain,pRamp));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,HANDLE* pSharedHandle)
+{
+ //Message("CreateTexture( ): %lu\n", this);
+ HRESULT ret = (m_pIDirect3DDevice9->CreateTexture(Width,Height,Levels,Usage,Format,Pool,ppTexture,pSharedHandle));
+ if(ret != D3D_OK) return (ret);
+
+ OTM_IDirect3DTexture9 *texture = new OTM_IDirect3DTexture9(ppTexture, this, Width, Height, Format);
+ if (texture) *ppTexture = texture;
+
+
+ if (LastCreatedTexture!=NULL)
+ {
+ if ( OTM_Client!=NULL) OTM_Client->AddTexture( LastCreatedTexture);
+ }
+
+ LastCreatedTexture = texture;
+
+ //Message("end CreateTexture( ): %lu\n", this);
+ return (ret);
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,HANDLE* pSharedHandle)
+{
+ return (m_pIDirect3DDevice9->CreateVolumeTexture(Width,Height,Depth,Levels,Usage,Format,Pool,ppVolumeTexture,pSharedHandle));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle)
+{
+ return(m_pIDirect3DDevice9->CreateCubeTexture(EdgeLength,Levels,Usage,Format,Pool,ppCubeTexture,pSharedHandle));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,HANDLE* pSharedHandle)
+{
+ return(m_pIDirect3DDevice9->CreateVertexBuffer(Length,Usage,FVF,Pool,ppVertexBuffer,pSharedHandle));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,HANDLE* pSharedHandle)
+{
+ return(m_pIDirect3DDevice9->CreateIndexBuffer(Length,Usage,Format,Pool,ppIndexBuffer,pSharedHandle));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle)
+{
+ return(m_pIDirect3DDevice9->CreateRenderTarget(Width,Height,Format,MultiSample,MultisampleQuality,Lockable,ppSurface,pSharedHandle));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle)
+{
+ return(m_pIDirect3DDevice9->CreateDepthStencilSurface(Width,Height,Format,MultiSample,MultisampleQuality,Discard,ppSurface,pSharedHandle));
+}
+
+HRESULT OTM_IDirect3DDevice9::UpdateSurface(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint)
+{
+ return(m_pIDirect3DDevice9->UpdateSurface(pSourceSurface,pSourceRect,pDestinationSurface,pDestPoint));
+}
+
+HRESULT OTM_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTexture,IDirect3DBaseTexture9* pDestinationTexture)
+{
+ return(m_pIDirect3DDevice9->UpdateTexture(pSourceTexture,pDestinationTexture));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetRenderTargetData(IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface)
+{
+ return(m_pIDirect3DDevice9->GetRenderTargetData(pRenderTarget,pDestSurface));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetFrontBufferData(UINT iSwapChain,IDirect3DSurface9* pDestSurface)
+{
+ return(m_pIDirect3DDevice9->GetFrontBufferData(iSwapChain,pDestSurface));
+}
+
+HRESULT OTM_IDirect3DDevice9::StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter)
+{
+ return(m_pIDirect3DDevice9->StretchRect(pSourceSurface,pSourceRect,pDestSurface,pDestRect,Filter));
+}
+
+HRESULT OTM_IDirect3DDevice9::ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect,D3DCOLOR color)
+{
+ return(m_pIDirect3DDevice9->ColorFill(pSurface,pRect,color));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateOffscreenPlainSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle)
+{
+ return(m_pIDirect3DDevice9->CreateOffscreenPlainSurface(Width,Height,Format,Pool,ppSurface,pSharedHandle));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget)
+{
+ return(m_pIDirect3DDevice9->SetRenderTarget(RenderTargetIndex,pRenderTarget));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget)
+{
+ return(m_pIDirect3DDevice9->GetRenderTarget(RenderTargetIndex,ppRenderTarget));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil)
+{
+ return(m_pIDirect3DDevice9->SetDepthStencilSurface(pNewZStencil));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface)
+{
+ return(m_pIDirect3DDevice9->GetDepthStencilSurface(ppZStencilSurface));
+}
+
+HRESULT OTM_IDirect3DDevice9::BeginScene(void)
+{
+ //Message("BeginScene(): %lu\n", this);
+ if ( OTM_Client!=NULL)
+ {
+ OTM_Client->MergeUpdate();
+ if (LastCreatedTexture!=NULL)
+ {
+ OTM_Client->AddTexture( LastCreatedTexture);
+ LastCreatedTexture = NULL;
+ }
+ }
+ if (BoolSaveSingleTexture && KeyBack && KeySave && KeyNext)
+ {
+ if (GetAsyncKeyState( KeyBack ) &1 )
+ {
+ UnswitchTextures( SingleTexture);
+ if (--CounterSaveSingleTexture<0) CounterSaveSingleTexture = OTM_Client->OriginalTextures.GetNumber() - 1;
+ if (CounterSaveSingleTexture >= 0) SwitchTextures( SingleTexture, OTM_Client->OriginalTextures[CounterSaveSingleTexture]);
+ }
+ if (GetAsyncKeyState( KeySave ) &1 )
+ {
+ SingleTexture->Hash = SingleTexture->CrossRef_D3Dtex->Hash;
+ OTM_Client->SaveTexture( SingleTexture);
+ SingleTexture->Hash = 0u;
+ }
+ if (GetAsyncKeyState( KeyNext ) &1 )
+ {
+ UnswitchTextures( SingleTexture);
+ if (++CounterSaveSingleTexture>=OTM_Client->OriginalTextures.GetNumber()) CounterSaveSingleTexture = 0;
+ if (CounterSaveSingleTexture < OTM_Client->OriginalTextures.GetNumber()) SwitchTextures( SingleTexture, OTM_Client->OriginalTextures[CounterSaveSingleTexture]);
+ }
+ }
+
+ /*
+ if (( gl_ErrorState & (OTM_ERROR_FATAL | OTM_ERROR_MUTEX) )) return(m_pIDirect3DDevice9->BeginScene()); //senseless to wait
+ if (LastCreatedTexture!=NULL)
+ {
+ gl_pTextureHandler->AddOriginalTexture( LastCreatedTexture);
+ LastCreatedTexture = NULL;
+ }
+ if (WAIT_OBJECT_0!=WaitForSingleObject( gl_MutexTexture, 100)) gl_ErrorState |= OTM_ERROR_FATAL; //waiting 100ms, to wait infinite pass INFINITE
+ */
+ return(m_pIDirect3DDevice9->BeginScene());
+}
+
+HRESULT OTM_IDirect3DDevice9::EndScene(void)
+{
+ //Message("EndScene(): %lu\n", this);
+ /*
+ ReleaseMutex(gl_MutexTexture);
+ */
+ return(m_pIDirect3DDevice9->EndScene());
+}
+
+HRESULT OTM_IDirect3DDevice9::Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil)
+{
+ return(m_pIDirect3DDevice9->Clear(Count,pRects,Flags,Color,Z,Stencil));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix)
+{
+ return(m_pIDirect3DDevice9->SetTransform(State,pMatrix));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetTransform(D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix)
+{
+ return(m_pIDirect3DDevice9->GetTransform(State,pMatrix));
+}
+
+HRESULT OTM_IDirect3DDevice9::MultiplyTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix)
+{
+ return(m_pIDirect3DDevice9->MultiplyTransform(State,pMatrix));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetViewport(CONST D3DVIEWPORT9* pViewport)
+{
+ return(m_pIDirect3DDevice9->SetViewport(pViewport));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetViewport(D3DVIEWPORT9* pViewport)
+{
+ return(m_pIDirect3DDevice9->GetViewport(pViewport));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetMaterial(CONST D3DMATERIAL9* pMaterial)
+{
+ return(m_pIDirect3DDevice9->SetMaterial(pMaterial));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetMaterial(D3DMATERIAL9* pMaterial)
+{
+ return(m_pIDirect3DDevice9->GetMaterial(pMaterial));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetLight(DWORD Index,CONST D3DLIGHT9* pLight)
+{
+ return(m_pIDirect3DDevice9->SetLight(Index,pLight));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetLight(DWORD Index,D3DLIGHT9* pLight)
+{
+ return(m_pIDirect3DDevice9->GetLight(Index,pLight));
+}
+
+HRESULT OTM_IDirect3DDevice9::LightEnable(DWORD Index,BOOL Enable)
+{
+ return(m_pIDirect3DDevice9->LightEnable(Index,Enable));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetLightEnable(DWORD Index,BOOL* pEnable)
+{
+ return(m_pIDirect3DDevice9->GetLightEnable(Index, pEnable));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetClipPlane(DWORD Index,CONST float* pPlane)
+{
+ return(m_pIDirect3DDevice9->SetClipPlane(Index, pPlane));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetClipPlane(DWORD Index,float* pPlane)
+{
+ return(m_pIDirect3DDevice9->GetClipPlane(Index,pPlane));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetRenderState(D3DRENDERSTATETYPE State,DWORD Value)
+{
+ return(m_pIDirect3DDevice9->SetRenderState(State, Value));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetRenderState(D3DRENDERSTATETYPE State,DWORD* pValue)
+{
+ return(m_pIDirect3DDevice9->GetRenderState(State, pValue));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateStateBlock(D3DSTATEBLOCKTYPE Type,IDirect3DStateBlock9** ppSB)
+{
+ return(m_pIDirect3DDevice9->CreateStateBlock(Type,ppSB));
+}
+
+HRESULT OTM_IDirect3DDevice9::BeginStateBlock(void)
+{
+ return(m_pIDirect3DDevice9->BeginStateBlock());
+}
+
+HRESULT OTM_IDirect3DDevice9::EndStateBlock(IDirect3DStateBlock9** ppSB)
+{
+ return(m_pIDirect3DDevice9->EndStateBlock(ppSB));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetClipStatus(CONST D3DCLIPSTATUS9* pClipStatus)
+{
+ return(m_pIDirect3DDevice9->SetClipStatus(pClipStatus));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetClipStatus(D3DCLIPSTATUS9* pClipStatus)
+{
+ return(m_pIDirect3DDevice9->GetClipStatus( pClipStatus));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetTexture(DWORD Stage,IDirect3DBaseTexture9** ppTexture)
+{
+ return(m_pIDirect3DDevice9->GetTexture(Stage,ppTexture));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetTexture(DWORD Stage, IDirect3DBaseTexture9* pTexture)
+{
+
+ IDirect3DDevice9 *dev = NULL;
+ if (pTexture != NULL && ((OTM_IDirect3DTexture9*)(pTexture))->GetDevice(&dev) == D3D_OK)
+ {
+ if(dev == this) return (m_pIDirect3DDevice9->SetTexture(Stage, ((OTM_IDirect3DTexture9*)(pTexture))->m_D3Dtex));
+ }
+ return (m_pIDirect3DDevice9->SetTexture(Stage, pTexture));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue)
+{
+ return(m_pIDirect3DDevice9->GetTextureStageState(Stage,Type, pValue));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value)
+{
+ return(m_pIDirect3DDevice9->SetTextureStageState(Stage,Type,Value));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD* pValue)
+{
+ return(m_pIDirect3DDevice9->GetSamplerState(Sampler,Type, pValue));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value)
+{
+ return(m_pIDirect3DDevice9->SetSamplerState(Sampler,Type,Value));
+}
+
+HRESULT OTM_IDirect3DDevice9::ValidateDevice(DWORD* pNumPasses)
+{
+ return(m_pIDirect3DDevice9->ValidateDevice( pNumPasses));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries)
+{
+ return(m_pIDirect3DDevice9->SetPaletteEntries(PaletteNumber, pEntries));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetPaletteEntries(UINT PaletteNumber,PALETTEENTRY* pEntries)
+{
+ return(m_pIDirect3DDevice9->GetPaletteEntries(PaletteNumber, pEntries));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetCurrentTexturePalette(UINT PaletteNumber)
+{
+ return(m_pIDirect3DDevice9->SetCurrentTexturePalette(PaletteNumber));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetCurrentTexturePalette(UINT *PaletteNumber)
+{
+ return(m_pIDirect3DDevice9->GetCurrentTexturePalette(PaletteNumber));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetScissorRect(CONST RECT* pRect)
+{
+ return(m_pIDirect3DDevice9->SetScissorRect( pRect));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetScissorRect( RECT* pRect)
+{
+ return(m_pIDirect3DDevice9->GetScissorRect( pRect));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetSoftwareVertexProcessing(BOOL bSoftware)
+{
+ return(m_pIDirect3DDevice9->SetSoftwareVertexProcessing(bSoftware));
+}
+
+BOOL OTM_IDirect3DDevice9::GetSoftwareVertexProcessing(void)
+{
+ return(m_pIDirect3DDevice9->GetSoftwareVertexProcessing());
+}
+
+HRESULT OTM_IDirect3DDevice9::SetNPatchMode(float nSegments)
+{
+ return(m_pIDirect3DDevice9->SetNPatchMode(nSegments));
+}
+
+float OTM_IDirect3DDevice9::GetNPatchMode(void)
+{
+ return(m_pIDirect3DDevice9->GetNPatchMode());
+}
+
+HRESULT OTM_IDirect3DDevice9::DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount)
+{
+ return(m_pIDirect3DDevice9->DrawPrimitive(PrimitiveType,StartVertex,PrimitiveCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
+{
+ return(m_pIDirect3DDevice9->DrawIndexedPrimitive(PrimitiveType,BaseVertexIndex,MinVertexIndex,NumVertices,startIndex,primCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride)
+{
+ return(m_pIDirect3DDevice9->DrawPrimitiveUP(PrimitiveType,PrimitiveCount,pVertexStreamZeroData,VertexStreamZeroStride));
+}
+
+HRESULT OTM_IDirect3DDevice9::DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride)
+{
+ return(m_pIDirect3DDevice9->DrawIndexedPrimitiveUP(PrimitiveType,MinVertexIndex,NumVertices,PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData,VertexStreamZeroStride));
+}
+
+HRESULT OTM_IDirect3DDevice9::ProcessVertices(UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer9* pDestBuffer,IDirect3DVertexDeclaration9* pVertexDecl,DWORD Flags)
+{
+ return(m_pIDirect3DDevice9->ProcessVertices( SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl)
+{
+ return(m_pIDirect3DDevice9->CreateVertexDeclaration( pVertexElements,ppDecl));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl)
+{
+ return(m_pIDirect3DDevice9->SetVertexDeclaration(pDecl));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl)
+{
+ return(m_pIDirect3DDevice9->GetVertexDeclaration(ppDecl));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetFVF(DWORD FVF)
+{
+ return(m_pIDirect3DDevice9->SetFVF(FVF));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetFVF(DWORD* pFVF)
+{
+ return(m_pIDirect3DDevice9->GetFVF(pFVF));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateVertexShader(CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader)
+{
+ return(m_pIDirect3DDevice9->CreateVertexShader(pFunction,ppShader));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetVertexShader(IDirect3DVertexShader9* pShader)
+{
+ return(m_pIDirect3DDevice9->SetVertexShader(pShader));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetVertexShader(IDirect3DVertexShader9** ppShader)
+{
+ return(m_pIDirect3DDevice9->GetVertexShader(ppShader));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount)
+{
+ return(m_pIDirect3DDevice9->SetVertexShaderConstantF(StartRegister,pConstantData, Vector4fCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetVertexShaderConstantF(UINT StartRegister,float* pConstantData,UINT Vector4fCount)
+{
+ return(m_pIDirect3DDevice9->GetVertexShaderConstantF(StartRegister,pConstantData,Vector4fCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount)
+{
+ return(m_pIDirect3DDevice9->SetVertexShaderConstantI(StartRegister,pConstantData,Vector4iCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetVertexShaderConstantI(UINT StartRegister,int* pConstantData,UINT Vector4iCount)
+{
+ return(m_pIDirect3DDevice9->GetVertexShaderConstantI(StartRegister,pConstantData,Vector4iCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount)
+{
+ return(m_pIDirect3DDevice9->SetVertexShaderConstantB(StartRegister,pConstantData,BoolCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetVertexShaderConstantB(UINT StartRegister,BOOL* pConstantData,UINT BoolCount)
+{
+ return(m_pIDirect3DDevice9->GetVertexShaderConstantB(StartRegister,pConstantData,BoolCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride)
+{
+ return(m_pIDirect3DDevice9->SetStreamSource(StreamNumber,pStreamData,OffsetInBytes,Stride));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9** ppStreamData,UINT* OffsetInBytes,UINT* pStride)
+{
+ return(m_pIDirect3DDevice9->GetStreamSource(StreamNumber,ppStreamData,OffsetInBytes,pStride));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetStreamSourceFreq(UINT StreamNumber,UINT Divider)
+{
+ return(m_pIDirect3DDevice9->SetStreamSourceFreq(StreamNumber,Divider));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetStreamSourceFreq(UINT StreamNumber,UINT* Divider)
+{
+ return(m_pIDirect3DDevice9->GetStreamSourceFreq(StreamNumber,Divider));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetIndices(IDirect3DIndexBuffer9* pIndexData)
+{
+ return(m_pIDirect3DDevice9->SetIndices(pIndexData));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetIndices(IDirect3DIndexBuffer9** ppIndexData)
+{
+ return(m_pIDirect3DDevice9->GetIndices(ppIndexData));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreatePixelShader(CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader)
+{
+ return(m_pIDirect3DDevice9->CreatePixelShader(pFunction,ppShader));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetPixelShader(IDirect3DPixelShader9* pShader)
+{
+ return(m_pIDirect3DDevice9->SetPixelShader(pShader));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetPixelShader(IDirect3DPixelShader9** ppShader)
+{
+ return(m_pIDirect3DDevice9->GetPixelShader(ppShader));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount)
+{
+ return(m_pIDirect3DDevice9->SetPixelShaderConstantF(StartRegister,pConstantData,Vector4fCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetPixelShaderConstantF(UINT StartRegister,float* pConstantData,UINT Vector4fCount)
+{
+ return(m_pIDirect3DDevice9->GetPixelShaderConstantF(StartRegister,pConstantData,Vector4fCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount)
+{
+ return(m_pIDirect3DDevice9->SetPixelShaderConstantI(StartRegister,pConstantData,Vector4iCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetPixelShaderConstantI(UINT StartRegister,int* pConstantData,UINT Vector4iCount)
+{
+ return(m_pIDirect3DDevice9->GetPixelShaderConstantI(StartRegister,pConstantData,Vector4iCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount)
+{
+ return(m_pIDirect3DDevice9->SetPixelShaderConstantB(StartRegister,pConstantData,BoolCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::GetPixelShaderConstantB(UINT StartRegister,BOOL* pConstantData,UINT BoolCount)
+{
+ return(m_pIDirect3DDevice9->GetPixelShaderConstantB(StartRegister,pConstantData,BoolCount));
+}
+
+HRESULT OTM_IDirect3DDevice9::DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo)
+{
+ return(m_pIDirect3DDevice9->DrawRectPatch(Handle,pNumSegs, pRectPatchInfo));
+}
+
+HRESULT OTM_IDirect3DDevice9::DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo)
+{
+ return(m_pIDirect3DDevice9->DrawTriPatch(Handle, pNumSegs, pTriPatchInfo));
+}
+
+HRESULT OTM_IDirect3DDevice9::DeletePatch(UINT Handle)
+{
+ return(m_pIDirect3DDevice9->DeletePatch(Handle));
+}
+
+HRESULT OTM_IDirect3DDevice9::CreateQuery(D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery)
+{
+ return(m_pIDirect3DDevice9->CreateQuery(Type,ppQuery));
+}
+
+
diff --git a/OTM_DX9/OTM_IDirect3DDevice9.h b/OTM_DX9/OTM_IDirect3DDevice9.h
new file mode 100644
index 0000000..b618926
--- /dev/null
+++ b/OTM_DX9/OTM_IDirect3DDevice9.h
@@ -0,0 +1,181 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_IDirect3DDevice9_H_
+#define OTM_IDirect3DDevice9_H_
+
+#include
+#include
+#include "OTM_IDirect3DTexture9.h"
+
+class OTM_IDirect3DDevice9 : public IDirect3DDevice9
+{
+public:
+ OTM_IDirect3DDevice9(IDirect3DDevice9* pOriginal, OTM_TextureServer* server);
+ virtual ~OTM_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
+
+ OTM_TextureClient* GetOTM_Client(void) {return (OTM_Client);}
+ OTM_IDirect3DTexture9* GetLastCreatedTexture(void) {return (LastCreatedTexture);}
+ int SetLastCreatedTexture(OTM_IDirect3DTexture9* pTexture) {LastCreatedTexture=pTexture; return (RETURN_OK);}
+
+ int SaveSingleTexture(bool val);
+ int SetKeyBack( int key) {if (key>0) KeyBack=key; return (0);}
+ int SetKeySave( int key) {if (key>0) KeySave=key; return (0);}
+ int SetKeyNext( int key) {if (key>0) KeyNext=key; return (0);}
+
+ private:
+
+ bool BoolSaveSingleTexture;
+ int CounterSaveSingleTexture;
+ int KeyBack;
+ int KeySave;
+ int KeyNext;
+ OTM_IDirect3DTexture9* SingleTexture;
+
+ IDirect3DDevice9* m_pIDirect3DDevice9;
+ OTM_IDirect3DTexture9* LastCreatedTexture;
+ OTM_TextureServer* OTM_Server;
+ OTM_TextureClient* OTM_Client;
+};
+
+#endif
+
diff --git a/OTM_DX9/OTM_IDirect3DTexture9.cpp b/OTM_DX9/OTM_IDirect3DTexture9.cpp
new file mode 100644
index 0000000..bf14927
--- /dev/null
+++ b/OTM_DX9/OTM_IDirect3DTexture9.cpp
@@ -0,0 +1,168 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+
+#include "OTM_Main.h"
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::QueryInterface(REFIID riid, void** ppvObj)
+{
+ return (m_D3Dtex->QueryInterface(riid, ppvObj));
+}
+
+ULONG APIENTRY OTM_IDirect3DTexture9::AddRef()
+{
+ return (m_D3Dtex->AddRef());
+}
+
+ULONG APIENTRY OTM_IDirect3DTexture9::Release()
+{
+ ULONG count = m_D3Dtex->Release();
+ if (count==0)
+ {
+ if (((OTM_IDirect3DDevice9*)m_D3Ddev)->GetLastCreatedTexture()==this) ((OTM_IDirect3DDevice9*)m_D3Ddev)->SetLastCreatedTexture( NULL); // this texture is deleted before it was added to the client!!
+ // we must set LastCreatedTexture to NULL, otherwise we would load later a non existing texture an try to compute their hash
+ else
+ {
+ ((OTM_IDirect3DDevice9*) m_D3Ddev)-> GetOTM_Client()->RemoveTexture(this);
+ }
+ delete(this);
+ }
+ return (count);
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::GetDevice(IDirect3DDevice9** ppDevice)
+{
+ *ppDevice = m_D3Ddev;
+ return D3D_OK;
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::SetPrivateData(REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags)
+{
+ return (m_D3Dtex->SetPrivateData(refguid, pData, SizeOfData, Flags));
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::GetPrivateData(REFGUID refguid,void* pData,DWORD* pSizeOfData)
+{
+ return (m_D3Dtex->GetPrivateData(refguid, pData, pSizeOfData));
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::FreePrivateData(REFGUID refguid)
+{
+ return (m_D3Dtex->FreePrivateData(refguid));
+}
+
+DWORD APIENTRY OTM_IDirect3DTexture9::SetPriority(DWORD PriorityNew)
+{
+ return (m_D3Dtex->SetPriority(PriorityNew));
+}
+
+DWORD APIENTRY OTM_IDirect3DTexture9::GetPriority()
+{
+ return (m_D3Dtex->GetPriority());
+}
+
+void APIENTRY OTM_IDirect3DTexture9::PreLoad()
+{
+ m_D3Dtex->PreLoad();
+}
+
+D3DRESOURCETYPE APIENTRY OTM_IDirect3DTexture9::GetType()
+{
+ return (m_D3Dtex->GetType());
+}
+
+DWORD APIENTRY OTM_IDirect3DTexture9::SetLOD(DWORD LODNew)
+{
+ return (m_D3Dtex->SetLOD(LODNew));
+}
+
+DWORD APIENTRY OTM_IDirect3DTexture9::GetLOD()
+{
+ return (m_D3Dtex->GetLOD());
+}
+
+DWORD APIENTRY OTM_IDirect3DTexture9::GetLevelCount()
+{
+ return (m_D3Dtex->GetLevelCount());
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE FilterType)
+{
+ return (m_D3Dtex->SetAutoGenFilterType(FilterType));
+}
+
+D3DTEXTUREFILTERTYPE APIENTRY OTM_IDirect3DTexture9::GetAutoGenFilterType()
+{
+ return (m_D3Dtex->GetAutoGenFilterType());
+}
+
+void APIENTRY OTM_IDirect3DTexture9::GenerateMipSubLevels()
+{
+ m_D3Dtex->GenerateMipSubLevels();
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc)
+{
+ return (m_D3Dtex->GetLevelDesc(Level, pDesc));
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::GetSurfaceLevel(UINT Level,IDirect3DSurface9** ppSurfaceLevel)
+{
+ return (m_D3Dtex->GetSurfaceLevel(Level, ppSurfaceLevel));
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::LockRect(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
+{
+ return (m_D3Dtex->LockRect(Level, pLockedRect, pRect, Flags));
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::UnlockRect(UINT Level)
+{
+ return (m_D3Dtex->UnlockRect(Level));
+}
+
+HRESULT APIENTRY OTM_IDirect3DTexture9::AddDirtyRect(CONST RECT* pDirtyRect)
+{
+ return (m_D3Dtex->AddDirtyRect(pDirtyRect));
+}
+
+/*
+//////////////////////////////
+// Useful Functions
+//////////////////////////////
+DWORD QuickChecksum(DWORD *pData, int size)
+{
+ if(!pData) { return (0x0); }
+
+ DWORD sum;
+ DWORD tmp;
+ sum = *pData;
+
+ for(int i = 1; i < (size/4); i++)
+ {
+ tmp = pData[i];
+ tmp = (DWORD)(sum >> 29) + tmp;
+ tmp = (DWORD)(sum >> 17) + tmp;
+ sum = (DWORD)(sum << 3) ^ tmp;
+ }
+
+ return sum;
+}
+*/
diff --git a/OTM_DX9/OTM_IDirect3DTexture9.h b/OTM_DX9/OTM_IDirect3DTexture9.h
new file mode 100644
index 0000000..5ddbb6f
--- /dev/null
+++ b/OTM_DX9/OTM_IDirect3DTexture9.h
@@ -0,0 +1,118 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_IDirect3DTexture9_H
+#define OTM_IDirect3DTexture9_H
+
+#include
+#include
+
+#include "OTM_Defines.h"
+
+
+
+
+//DWORD QuickChecksum(DWORD *pData, int size);
+
+interface OTM_IDirect3DTexture9 : public IDirect3DTexture9
+{
+ OTM_IDirect3DTexture9(IDirect3DTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9, UINT Width, UINT Height, D3DFORMAT Format)
+ {
+ //Message("OTM_IDirect3DTexture9( %lu, %lu): %lu\n", ppTex, pIDirect3DDevice9, this);
+ 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 OTM_IDirect3DTexture9 object, needed if a fake texture is deselected
+ // original texture: stores the pointer to the fake texture object, is needed if original texture is deleted (that fake texture can be replaced, if original texture is loaded again)
+ TextureHandlerRef = -1; //need for fast deleting
+ Hash = 0u;
+ FAKE = false;
+ }
+
+ // callback interface
+ IDirect3DTexture9 *m_D3Dtex;
+ OTM_IDirect3DTexture9 *CrossRef_D3Dtex;
+ IDirect3DDevice9 *m_D3Ddev;
+ int TextureHandlerRef;
+ 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);
+};
+
+
+
+inline void UnswitchTextures(OTM_IDirect3DTexture9 *pTexture)
+{
+ OTM_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( OTM_IDirect3DTexture9 *pTexture1, OTM_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
diff --git a/OTM_DX9/OTM_Main.h b/OTM_DX9/OTM_Main.h
new file mode 100644
index 0000000..6556207
--- /dev/null
+++ b/OTM_DX9/OTM_Main.h
@@ -0,0 +1,57 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_MAIN_H_
+#define OTM_MAIN_H_
+
+
+
+#define WIN32_LEAN_AND_MEAN
+#include
+
+#include
+#include
+
+#include
+#include
+
+
+
+#include "../OTM_GlobalDefines.h"
+#include "../OTM_Error.h"
+#include "OTM_Defines.h"
+#include "OTM_DX9_dll.h"
+#include "OTM_IDirect3D9.h"
+#include "OTM_IDirect3DDevice9.h"
+#include "OTM_IDirect3DTexture9.h"
+#include "OTM_ArrayHandler.h"
+#include "OTM_TextureServer.h"
+#include "OTM_TextureClient.h"
+
+
+
+extern OTM_IDirect3DDevice9 *gl_pIDirect3DDevice9;
+extern OTM_IDirect3D9 *gl_pIDirect3D9;
+extern HINSTANCE gl_hOriginalDll;
+extern HINSTANCE gl_hThisInstance;
+extern unsigned int gl_ErrorState;
+extern FILE *gl_File;
+
+#endif
diff --git a/OTM_DX9/OTM_TextureClient.cpp b/OTM_DX9/OTM_TextureClient.cpp
new file mode 100644
index 0000000..06f7a13
--- /dev/null
+++ b/OTM_DX9/OTM_TextureClient.cpp
@@ -0,0 +1,418 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#include "OTM_Main.h"
+
+FILE *file;
+
+
+
+
+OTM_TextureClient::OTM_TextureClient(OTM_TextureServer* server, IDirect3DDevice9* device)
+{
+ Message("OTM_TextureClient(void): %lu\n", this);
+ Server = server;
+ D3D9Device = device;
+ BoolSaveAllTextures = false;
+ SavePath[0]=0;
+ if (Server!=NULL)
+ {
+ if (Server->AddClient( this, &FileToMod, &NumberToMod))
+ {
+ Server=NULL;
+ NumberToMod = 0;
+ FileToMod = NULL;
+ }
+ }
+ Mutex = NULL;//CreateMutex(NULL, false, NULL);
+
+ Update = NULL;
+ NumberOfUpdate = -1;
+
+ //Message("end OTM_TextureClient(void): %lu\n", this);
+}
+
+OTM_TextureClient::~OTM_TextureClient(void)
+{
+ Message("~OTM_TextureClient(void): %lu\n", this);
+ if (Server!=NULL) Server->RemoveClient(this);
+
+ //Message("after Server ~OTM_TextureClient(void): %lu\n", this);
+
+ if (Mutex!=NULL) CloseHandle(Mutex);
+ //Message("after CloseHandle ~OTM_TextureClient(void): %lu\n", this);
+
+ if (Update!=NULL) delete [] Update;
+ //Message("after Update ~OTM_TextureClient(void): %lu\n", this);
+
+ if (FileToMod!=NULL) delete [] FileToMod;
+ //Message("end ~OTM_TextureClient(void): %lu\n", this);
+}
+
+int OTM_TextureClient::AddTexture( OTM_IDirect3DTexture9* pTexture)
+{
+ if (pTexture->FAKE) return (RETURN_OK); // this is a fake texture
+ Message("AddTexture( %lu): %lu (%lu)\n", pTexture, this, GetCurrentThread());
+
+ D3DLOCKED_RECT d3dlr;
+ if (pTexture->LockRect( 0, &d3dlr, NULL, 0)!=D3D_OK)
+ {
+ return (RETURN_LockRect_FAILED);
+ }
+ D3DSURFACE_DESC desc;
+ if (pTexture->GetLevelDesc(0, &desc)!=D3D_OK)
+ {
+ pTexture->UnlockRect(0);
+ return (RETURN_GetLevelDesc_FAILED);
+ }
+
+ int size=0;
+ switch(desc.Format)
+ {
+ case D3DFMT_A1: // 1-bit monochrome.
+ {
+ size = desc.Width*desc.Height/8;
+ 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:
+ {
+ size = desc.Width*desc.Height;
+ break;
+ }
+
+ 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_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_A8L8: // 16-bit using 8 bits each for alpha and luminance.
+ {
+ size = 2*desc.Width*desc.Height;
+ break;
+ }
+
+
+ case D3DFMT_R8G8B8: //24-bit RGB pixel format with 8 bits per channel.
+ {
+ size = 3*desc.Width*desc.Height;
+ 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_A2R10G10B10: // 32-bit pixel format using 10 bits each for red, green, and blue, and 2 bits for alpha.
+ {
+ size = 4*desc.Width*desc.Height;
+ 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.
+ {
+ size = 8*desc.Width*desc.Height;
+ break;
+ }
+
+ case D3DFMT_A32B32G32R32F: // 128-bit float format using 32 bits for the each channel (alpha, blue, green, red).
+ {
+ size = 16*desc.Width*desc.Height;
+ break;
+ }
+ default: //compressed formats
+ {
+ size = desc.Width*desc.Height/2;
+ break;
+ }
+ }
+ MyTypeHash hash = GetHash( (unsigned char*) d3dlr.pBits, size);
+
+ if (pTexture->UnlockRect(0)!=D3D_OK)
+ {
+ return (RETURN_UnlockRect_FAILED);
+ }
+ pTexture->Hash = hash; // note: this will only be done for original textures
+ if (BoolSaveAllTextures) SaveTexture(pTexture);
+
+ if (gl_ErrorState & OTM_ERROR_FATAL) return (RETURN_FATAL_ERROR);
+
+ OriginalTextures.Add( pTexture);
+
+ return (LookUpToMod(pTexture)); // check if this texture should be modded
+}
+
+
+
+int OTM_TextureClient::RemoveTexture( OTM_IDirect3DTexture9* pTexture) // is called from a texture, if it is finally released
+{
+ Message("RemoveTexture( %lu): %lu\n", pTexture, this);
+
+ IDirect3DDevice9 *dev = NULL;
+ if (pTexture != NULL && pTexture->GetDevice(&dev) == D3D_OK)
+ {
+ if (dev == D3D9Device)
+ {
+ if (gl_ErrorState & OTM_ERROR_FATAL) return (RETURN_FATAL_ERROR);
+ if (pTexture->FAKE)
+ {
+ for (int i=0; iSaveSingleTexture(val));
+ else return (RETURN_NO_IDirect3DDevice9);
+}
+
+
+int OTM_TextureClient::SetSaveDirectory( wchar_t *dir)
+{
+ Message("SetSaveDirectory( %ls): %lu\n", dir, this);
+ int i = 0;
+ for (i=0; iHash);
+
+ if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
+ return (RETURN_OK);
+}
+
+
+
+int OTM_TextureClient::AddUpdate(TextureFileStruct* update, int number) //client must delete the temp array
+{
+ Message("AddUpdate( %lu, %d): %lu\n", update, number, this);
+ //if (update==NULL || number<=0) return (RETURN_OK);
+ if (int ret = LockMutex()) {gl_ErrorState |= OTM_ERROR_TEXTURE; return (ret);}
+ if (Update!=NULL) delete [] Update;
+ Update = update;
+ NumberOfUpdate = number;
+ return (UnlockMutex());
+}
+
+
+
+int OTM_TextureClient::MergeUpdate(void)
+{
+ if (NumberOfUpdate<0) {Update=NULL; return (RETURN_OK);}
+ if (int ret = LockMutex()) {gl_ErrorState |= OTM_ERROR_TEXTURE ; return (ret);}
+
+ Message("MergeUpdate(): %lu\n", this);
+
+ for (int i=0; iCrossRef_D3Dtex;
+ RemoveTexture( Update[u].pTexture);
+ Update[u].pTexture = NULL;
+ if (pTexture!=NULL) //should always be the case
+ {
+ OTM_IDirect3DTexture9 *fake_Texture;
+ if (int ret = LoadTexture( & (Update[u]), &fake_Texture)) return (ret);
+ if (SwitchTextures( fake_Texture, pTexture))
+ {
+ Message("MergeUpdate(): textures not switched %#lX\n", hash);
+ fake_Texture->Release();
+ }
+ else
+ {
+ FakeTextures.Add(fake_Texture);
+ Update[u].pTexture = fake_Texture;
+ }
+ }
+ }
+ break;
+ }
+ }
+ if (!found)
+ {
+ FakeTextures.Remove(FileToMod[i].pTexture);
+ }
+ }
+
+ // looking through the update and switch the textures if they are currently used in the game
+ int num = OriginalTextures.GetNumber();
+ for (int u=0; uHash && OriginalTextures[i]->CrossRef_D3Dtex==NULL)
+ {
+ Update[u].Checked = true;
+ OTM_IDirect3DTexture9 *pTexture = OriginalTextures[i];
+ OTM_IDirect3DTexture9 *fake_Texture;
+ if (RETURN_OK == LoadTexture( & (Update[u]), &fake_Texture))
+ {
+ if (SwitchTextures( fake_Texture, pTexture))
+ {
+ Message("MergeUpdate(): textures not switched %#lX\n", hash);
+ fake_Texture->Release();
+ }
+ else
+ {
+ Update[u].pTexture = fake_Texture;
+ FakeTextures.Add(fake_Texture);
+ }
+ }
+ }
+ }
+
+ if (FileToMod!=NULL) delete [] FileToMod;
+ FileToMod = Update;
+ NumberToMod = NumberOfUpdate;
+
+ NumberOfUpdate = -1;
+ Update = NULL;
+ return (UnlockMutex());
+}
+
+
+
+int OTM_TextureClient::LockMutex(void)
+{
+ //if (( gl_ErrorState & (OTM_ERROR_FATAL | OTM_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 OTM_TextureClient::UnlockMutex(void)
+{
+ //if (ReleaseMutex(Mutex)==0) return (RETURN_MUTEX_UNLOCK);
+ return (RETURN_OK);
+}
+
+
+
+
+
+int OTM_TextureClient::LookUpToMod( OTM_IDirect3DTexture9* pTexture) // should only be called for original textures
+{
+ Message("LookUpToMod( %lu): hash: %lu, %lu\n", pTexture, pTexture->Hash, this);
+ if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // to avoid broken links
+ MyTypeHash hash = pTexture->Hash;
+ for (int i=0; iRelease();
+ }
+ else
+ {
+ FakeTextures.Add(fake_Texture);
+ FileToMod[i].pTexture = fake_Texture;
+ }
+ }
+ }
+ return (RETURN_OK);
+}
+
+
+int OTM_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, OTM_IDirect3DTexture9 **ppTexture) // to load fake texture from file in memory
+{
+ Message("LoadTexture( %lu, %lu): %lu\n", file_in_memory, ppTexture, this);
+
+ 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;
+ Message("LoadTexture(): DONE\n", file_in_memory, ppTexture, this);
+ return (RETURN_OK);
+}
+
+
+MyTypeHash OTM_TextureClient::GetHash(unsigned char *str, int len) // estimate the hash
+{
+ MyTypeHash hash = 0;
+ for (int i=0; i.
+*/
+
+
+
+#ifndef OTM_TEXTUREHANDLER_HPP
+#define OTM_TEXTUREHANDLER_HPP
+
+#include "OTM_IDirect3DTexture9.h"
+#include "OTM_IDirect3DDevice9.h"
+#include "..\OTM_Error.h"
+
+
+class OTM_TextureServer;
+
+
+
+class OTM_TextureClient
+{
+public:
+ OTM_TextureClient(OTM_TextureServer* server, IDirect3DDevice9* device);
+ ~OTM_TextureClient(void);
+
+ int AddTexture( OTM_IDirect3DTexture9* tex); //called from OTM_IDirect3DDevice9::CreateTexture(...)
+ int RemoveTexture( OTM_IDirect3DTexture9* tex); //called from OTM_IDirect3DTexture9::Release()
+
+ int ReleaseAllFakeTexture(void); // called when the Game is closed
+
+ 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 SaveTexture(OTM_IDirect3DTexture9* pTexture);
+
+
+ int SetKeyBack( int key) {if (D3D9Device!=NULL) return (((OTM_IDirect3DDevice9*)D3D9Device)->SetKeyBack(key)); else return (RETURN_NO_IDirect3DDevice9);}
+ int SetKeySave( int key) {if (D3D9Device!=NULL) return (((OTM_IDirect3DDevice9*)D3D9Device)->SetKeySave(key)); else return (RETURN_NO_IDirect3DDevice9);}
+ int SetKeyNext( int key) {if (D3D9Device!=NULL) return (((OTM_IDirect3DDevice9*)D3D9Device)->SetKeyNext(key)); else return (RETURN_NO_IDirect3DDevice9);}
+
+ int AddUpdate(TextureFileStruct* update, int number); //client must delete the temp array
+ int MergeUpdate(void);
+
+
+ OTM_TextureHandler FakeTextures;
+ OTM_TextureHandler OriginalTextures;
+
+private:
+ OTM_TextureServer* Server;
+ IDirect3DDevice9* D3D9Device;
+ bool BoolSaveAllTextures;
+ wchar_t SavePath[MAX_PATH];
+
+ TextureFileStruct* Update;
+ int NumberOfUpdate;
+
+ int LockMutex();
+ int UnlockMutex();
+ HANDLE Mutex;
+
+ int NumberToMod;
+ TextureFileStruct* FileToMod;
+
+
+ int LookUpToMod( OTM_IDirect3DTexture9* pTexture);
+ int LoadTexture( TextureFileStruct* file_in_memory, OTM_IDirect3DTexture9 **ppTexture);
+ MyTypeHash GetHash(unsigned char *str, int len);
+
+
+};
+
+
+
+#endif /* OTM_TEXTUREHANDLER_HPP_ */
diff --git a/OTM_DX9/OTM_TextureServer.cpp b/OTM_DX9/OTM_TextureServer.cpp
new file mode 100644
index 0000000..a19af57
--- /dev/null
+++ b/OTM_DX9/OTM_TextureServer.cpp
@@ -0,0 +1,602 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#include "OTM_Main.h"
+
+OTM_TextureServer::OTM_TextureServer(void)
+{
+ Message("OTM_TextureServer(void): %lu\n", this);
+ Message("sizeof(unsigned long)=%lu\n", sizeof(unsigned long));
+ Message("sizeof(DWORDLONG)=%lu\n", sizeof(DWORDLONG));
+ Mutex = CreateMutex(NULL, false, NULL);
+
+ Clients = NULL;
+ NumberOfClients = 0;
+ LenghtOfClients = 0;
+ BoolSaveAllTextures = false;
+ SavePath[0] = 0;
+
+ KeyBack = 0;
+ KeySave = 0;
+ KeyNext = 0;
+
+ Pipe.In = INVALID_HANDLE_VALUE;
+ Pipe.Out = INVALID_HANDLE_VALUE;
+}
+
+OTM_TextureServer::~OTM_TextureServer(void)
+{
+ Message("~OTM_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;
+
+ num = OldMod.GetNumber();
+ for (int i = 0; i < num; i++) delete[] OldMod[i]->pData;
+
+ 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 OTM_TextureServer::AddClient(OTM_TextureClient *client, TextureFileStruct** update, int* number) // called from a client
+{
+ Message("AddClient(%lu): %lu\n", client, this);
+ if (int ret = LockMutex())
+ {
+ gl_ErrorState |= OTM_ERROR_SERVER;
+ return (ret);
+ }
+
+ /*
+ DO NOT UNCOMMENT THIS
+ some games create special devices before the rendering device is created. those device should not receive SaveSingleTexture(...)
+ client->SaveAllTextures(BoolSaveAllTextures);
+ client->SaveSingleTexture(BoolSaveSingleTexture);
+ client->SetSaveDirectory(SavePath);
+ if (KeyBack > 0)
+ client->SetKeySave(KeyBack);
+ if (KeySave > 0)
+ client->SetKeySave(KeySave);
+ if (KeyNext > 0)
+ client->SetKeySave(KeyNext);
+*/
+
+ if (int ret = PrepareUpdate( update, number)) return (ret);
+
+ OTM_TextureClient** temp = NULL;
+
+ if (NumberOfClients == LenghtOfClients)
+ {
+ try {temp = new OTM_TextureClient*[LenghtOfClients + 10];}
+ catch (...)
+ {
+ gl_ErrorState |= OTM_ERROR_MEMORY | OTM_ERROR_SERVER;
+ if (int ret = UnlockMutex()) return (ret);
+ return (RETURN_NO_MEMORY);
+ }
+ for (int i=0; iHash == 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 |= OTM_ERROR_MEMORY | OTM_ERROR_SERVER;
+ return (RETURN_NO_MEMORY);
+ }
+ //Message("Read AddFile( %lu)\n", hash, this);
+ int result = fread(temp->pData, 1, size, file);
+ fclose(file);
+ if (result != size)
+ {
+ //Message("Read Failed AddFile( %lu): %lu\n", hash, this);
+ delete[] temp->pData;
+ if (!new_file) CurrentMod.Remove( temp);
+ delete temp;
+ return (RETURN_FILE_NOT_LOADED);
+ }
+
+ temp->Checked = false;
+ temp->Size = size;
+ temp->pTexture = NULL;
+ temp->Hash = hash;
+
+ if (new_file) temp->ForceReload = false;
+ else temp->ForceReload = force;
+
+ Message("End AddFile( %lu)\n", hash);
+ if (new_file) return (CurrentMod.Add(temp));
+ else return (RETURN_OK);
+}
+
+int OTM_TextureServer::RemoveFile(MyTypeHash hash) // called from the server
+{
+ 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 OTM_TextureServer::SaveAllTextures(bool val) // called from the server
+{
+ if (BoolSaveAllTextures == val) return (RETURN_OK);
+ BoolSaveAllTextures = val;
+
+ if (int ret = LockMutex())
+ {
+ gl_ErrorState |= OTM_ERROR_SERVER;
+ return (ret);
+ }
+ for (int i = 0; i < NumberOfClients; i++)
+ {
+ Clients[i]->SaveAllTextures(BoolSaveAllTextures);
+ }
+ return (UnlockMutex());
+}
+
+int OTM_TextureServer::SaveSingleTexture(bool val) // called from the server
+{
+ if (BoolSaveSingleTexture == val) return (RETURN_OK);
+ BoolSaveSingleTexture = val;
+
+ if (int ret = LockMutex())
+ {
+ gl_ErrorState |= OTM_ERROR_SERVER;
+ return (ret);
+ }
+ for (int i = 0; i < NumberOfClients; i++)
+ {
+ Clients[i]->SaveSingleTexture(BoolSaveSingleTexture);
+ }
+ return (UnlockMutex());
+}
+
+int OTM_TextureServer::SetSaveDirectory(wchar_t *dir) // called from the server
+{
+ Message("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 (int ret = LockMutex())
+ {
+ gl_ErrorState |= OTM_ERROR_SERVER;
+ return (ret);
+ }
+ for (int i = 0; i < NumberOfClients; i++)
+ {
+ Clients[i]->SetSaveDirectory(SavePath);
+ }
+ return (UnlockMutex());
+}
+
+int OTM_TextureServer::SetKeyBack(int key) // called from the server
+{
+ if (KeyBack == key || KeySave == key || KeyNext == key) return (RETURN_OK);
+ if (int ret = LockMutex())
+ {
+ gl_ErrorState |= OTM_ERROR_SERVER;
+ return (ret);
+ }
+ KeyBack = key;
+ for (int i = 0; i < NumberOfClients; i++)
+ {
+ Clients[i]->SetKeyBack(key);
+ }
+ return (UnlockMutex());
+}
+
+int OTM_TextureServer::SetKeySave(int key) // called from the server
+{
+ if (KeyBack == key || KeySave == key || KeyNext == key) return (RETURN_OK);
+ if (int ret = LockMutex())
+ {
+ gl_ErrorState |= OTM_ERROR_SERVER;
+ return (ret);
+ }
+ KeySave = key;
+ for (int i = 0; i < NumberOfClients; i++)
+ {
+ Clients[i]->SetKeySave(key);
+ }
+ return (UnlockMutex());
+}
+
+int OTM_TextureServer::SetKeyNext(int key) // called from the server
+{
+ if (KeyBack == key || KeySave == key || KeyNext == key) return (RETURN_OK);
+ if (int ret = LockMutex())
+ {
+ gl_ErrorState |= OTM_ERROR_SERVER;
+ return (ret);
+ }
+ KeyNext = key;
+ for (int i = 0; i < NumberOfClients; i++)
+ {
+ Clients[i]->SetKeyNext(key);
+ }
+ return (UnlockMutex());
+}
+
+int OTM_TextureServer::PropagateUpdate(OTM_TextureClient* client) // called from the server, send the update to all clients
+{
+ Message("PropagateUpdate(%lu): %lu\n", client, this);
+ if (int ret = LockMutex())
+ {
+ gl_ErrorState |= OTM_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.Checked = b.Checked; \
+ a.ForceReload = b.ForceReload; \
+ a.pData = b.pData; \
+ a.Size = b.Size; \
+ a.Reference = b.Reference; \
+ a.pTexture = b.pTexture; \
+ a.Hash = b.Hash; }
+
+int OTM_TextureServer::PrepareUpdate(TextureFileStruct** update, int* number) // called from the server, 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 |= OTM_ERROR_MEMORY | OTM_ERROR_SERVER;
+ return (RETURN_NO_MEMORY);
+ }
+ }
+
+ for (int i = 0; i < num; i++) cpy_file_struct(temp[i], (*(CurrentMod[i])));
+
+ *update = temp;
+ *number = num;
+ return (RETURN_OK);
+}
+#undef cpy_file_struct
+
+int OTM_TextureServer::LockMutex(void)
+{
+ //if (( gl_ErrorState & (OTM_ERROR_FATAL | OTM_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 OTM_TextureServer::UnlockMutex(void)
+{
+ //if (ReleaseMutex(Mutex)==0) return (RETURN_MUTEX_UNLOCK);
+ return (RETURN_OK);
+}
+
+int OTM_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[BUFSIZE];
+ unsigned long size;
+
+ Message("MainLoop: started\n");
+ while (1)
+ {
+ Message("MainLoop: run\n");
+ bool ret = ReadFile(Pipe.In, // pipe handle
+ buffer, // buffer to receive reply
+ BUFSIZE, // size of buffer
+ &size, // number of bytes read
+ NULL); // not overlapped
+
+ Message("MainLoop: read something (%lu)\n", size);
+ //for (int i=0; iControl)
+ {
+ case CONTROL_FORCE_RELOAD_TEXTURE: force=true;
+ case CONTROL_ADD_TEXTURE:
+ {
+ int temp_pos = pos + sizeof(MsgStruct);
+ file = (wchar_t*) &buffer[temp_pos];
+ while (temp_pos < BUFSIZE && file[add_length])
+ {
+ add_length++;
+ temp_pos += sizeof(wchar_t);
+ }
+ add_length++;
+ temp_pos += sizeof(wchar_t); //to add the zero
+ Message("MainLoop: CONTROL_ADD_TEXTURE (%#lX %u, %u %u): %lu\n", commands->Hash, add_length, sizeof(MsgStruct), sizeof(char), this);
+
+ if (temp_pos < BUFSIZE)
+ {
+ AddFile(file, commands->Hash, force);
+ update_textures = true;
+ }
+ else add_length = 0;
+ 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:
+ {
+ int temp_pos = pos + sizeof(MsgStruct);
+ file = (wchar_t*) &buffer[temp_pos];
+ while (temp_pos < BUFSIZE && file[add_length])
+ {
+ add_length++;
+ temp_pos += sizeof(wchar_t);
+ }
+ add_length++;
+ temp_pos += sizeof(wchar_t); //to add the zero
+ Message("MainLoop: CONTROL_SET_DIR (%u): %lu\n", add_length, this);
+
+ if (temp_pos < BUFSIZE) SetSaveDirectory(file);
+ else add_length = 0;
+ 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;
+ }
+ default:
+ {
+ Message("MainLoop: DEFAULT: %lu %lu %#lX\n", commands->Control, commands->Value, commands->Hash, this);
+ break;
+ }
+ }
+ pos += sizeof(MsgStruct) + add_length * sizeof(wchar_t);
+ }
+ if (update_textures) PropagateUpdate();
+ }
+ else
+ {
+ Message("MainLoop: error in ReadFile()\n");
+ ClosePipe();
+ return (RETURN_OK);
+ }
+ }
+ return (RETURN_OK);
+}
+
+int OTM_TextureServer::OpenPipe(wchar_t *game) // called from InitInstance()
+{
+ Message("OpenPipe: Out\n")
+ // open first outgoing pipe !!
+ Pipe.Out = CreateFileW(PIPE_Game2OTM, // 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 OTM_GUI
+ WriteFile(Pipe.Out, (const void*) game, len * sizeof(wchar_t), &num, NULL);
+
+ Message("OpenPipe: In\n");
+ Pipe.In = CreateFileW(PIPE_OTM2Game, // 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 OTM_TextureServer::ClosePipe(void) //called from ExitInstance, this must be done, otherwise the Mainloop will wait endless on the ReadFile()
+{
+ Message("ClosePipe:\n");
+
+ 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);
+}
diff --git a/OTM_DX9/OTM_TextureServer.h b/OTM_DX9/OTM_TextureServer.h
new file mode 100644
index 0000000..3178ab8
--- /dev/null
+++ b/OTM_DX9/OTM_TextureServer.h
@@ -0,0 +1,90 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_TEXTURESERVER_H_
+#define OTM_TEXTURESERVER_H_
+
+#include "../OTM_GlobalDefines.h"
+#include "OTM_ArrayHandler.h"
+
+
+
+
+class OTM_TextureClient;
+
+class OTM_TextureServer
+{
+public:
+ OTM_TextureServer(void);
+ ~OTM_TextureServer(void);
+
+ int AddClient(OTM_TextureClient *client, TextureFileStruct** update, int* number);
+ int RemoveClient(OTM_TextureClient *client);
+
+ int OpenPipe( wchar_t *game);
+ int ClosePipe(void);
+ int MainLoop(void);
+
+
+ //following functions are public for testing purpose !!
+ int AddFile( wchar_t* file_name, MyTypeHash hash, bool force);
+ int RemoveFile( MyTypeHash hash);
+
+ int SaveAllTextures(bool val);
+ int SaveSingleTexture(bool val);
+
+ int SetSaveDirectory( wchar_t *dir);
+ int SaveTexture(OTM_IDirect3DTexture9* pTexture);
+
+
+ int SetKeyBack( int key);
+ int SetKeySave( int key);
+ int SetKeyNext( int key);
+
+private:
+ bool BoolSaveAllTextures;
+ bool BoolSaveSingleTexture;
+ wchar_t SavePath[MAX_PATH];
+
+ int PropagateUpdate(OTM_TextureClient* client=NULL);
+ int PrepareUpdate(TextureFileStruct** update, int* number);
+
+ int LockMutex();
+ int UnlockMutex();
+
+
+ int KeyBack;
+ int KeySave;
+ int KeyNext;
+
+ HANDLE Mutex;
+
+ PipeStruct Pipe;
+
+ OTM_TextureClient** Clients;
+ int NumberOfClients;
+ int LenghtOfClients;
+
+ OTM_FileHandler CurrentMod;
+ OTM_FileHandler OldMod;
+};
+
+
+#endif /* OTM_TEXTURESERVER_H_ */
diff --git a/OTM_DX9/makefile b/OTM_DX9/makefile
new file mode 100644
index 0000000..28c2fb2
--- /dev/null
+++ b/OTM_DX9/makefile
@@ -0,0 +1,64 @@
+ifdef NO_INJECTION
+prcompiler_flag = /D "NO_INJECTION"
+def_file = /DEF:"OTM_DX9_dll_NO_INJECTION.def"
+else
+prcompiler_flag =
+def_file = /DEF:"OTM_DX9_dll.def"
+endif
+
+
+CXX = cl
+CLINK = link.exe
+
+CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PROXYDLL_EXPORTS" /D "_WINDLL" /D "_MBCS" /D "_AFXDLL" ${prcompiler_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" "user32.lib" "Kernel32.lib" ${def_file} /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86
+
+obj = obj
+bin = bin
+obj_suff = obj
+
+objects = ${obj}\OTM_DX9_dll.${obj_suff} \
+ ${obj}\OTM_IDirect3D9.${obj_suff} \
+ ${obj}\OTM_IDirect3DDevice9.${obj_suff} \
+ ${obj}\OTM_IDirect3DTexture9.${obj_suff} \
+ ${obj}\OTM_ArrayHandler.${obj_suff} \
+ ${obj}\OTM_TextureClient.${obj_suff} \
+ ${obj}\OTM_TextureServer.${obj_suff}
+
+headers = OTM_Main.h \
+ OTM_Defines.h \
+ OTM_DX9_dll.h \
+ OTM_IDirect3D9.h \
+ OTM_IDirect3DDevice9.h \
+ OTM_IDirect3DTexture9.h \
+ OTM_ArrayHandler.h \
+ OTM_TextureClient.h \
+ OTM_TextureServer.h
+
+${bin}\d3d9.dll: ${objects}
+ ${CLINK} ${LFLAGS} ${objects} /OUT:${bin}\d3d9.dll
+ copy ${bin}\d3d9.dll ..\OTM_GUI\bin\OTM_d3d9.dll
+
+${obj}\OTM_DX9_dll.${obj_suff}: OTM_DX9_dll.cpp ${headers}
+ ${CXX} ${CFLAGS} /c $< /Fo$@
+
+${obj}\OTM_IDirect3D9.${obj_suff}: OTM_IDirect3D9.cpp ${headers}
+ ${CXX} ${CFLAGS} /c $< /Fo$@
+
+${obj}\OTM_IDirect3DDevice9.${obj_suff}: OTM_IDirect3DDevice9.cpp ${headers}
+ ${CXX} ${CFLAGS} /c $< /Fo$@
+
+${obj}\OTM_IDirect3DTexture9.${obj_suff}: OTM_IDirect3DTexture9.cpp ${headers}
+ ${CXX} ${CFLAGS} /c $< /Fo$@
+
+${obj}\OTM_ArrayHandler.${obj_suff}: OTM_ArrayHandler.cpp ${headers}
+ ${CXX} ${CFLAGS} /c $< /Fo$@
+
+${obj}\OTM_TextureClient.${obj_suff}: OTM_TextureClient.cpp ${headers}
+ ${CXX} ${CFLAGS} /c $< /Fo$@
+
+${obj}\OTM_TextureServer.${obj_suff}: OTM_TextureServer.cpp ${headers}
+ ${CXX} ${CFLAGS} /c $< /Fo$@
+
+clean:
+ del ${objects} ${bin}\d3d9.dll
\ No newline at end of file
diff --git a/OTM_Error.h b/OTM_Error.h
new file mode 100644
index 0000000..50dc31a
--- /dev/null
+++ b/OTM_Error.h
@@ -0,0 +1,54 @@
+#ifndef OTM_ERROR_H_
+#define OTM_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 OTM_ERROR_FATAL 1u
+#define OTM_ERROR_MUTEX 1u<<1
+#define OTM_ERROR_PIPE 1u<<2
+#define OTM_ERROR_MEMORY 1u<<3
+#define OTM_ERROR_TEXTURE 1u<<4
+#define OTM_ERROR_MULTIPLE_IDirect3D9 1u<<5
+#define OTM_ERROR_MULTIPLE_IDirect3DDevice9 1u<<6
+#define OTM_ERROR_UPDATE 1u<<7
+#define OTM_ERROR_SERVER 1u<<8
+
+
+
+
+
+
+#endif /* OTM_ERROR_H_ */
diff --git a/OTM_GUI/.cproject b/OTM_GUI/.cproject
new file mode 100644
index 0000000..b7587e2
--- /dev/null
+++ b/OTM_GUI/.cproject
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OTM_GUI/.project b/OTM_GUI/.project
new file mode 100644
index 0000000..cff2c88
--- /dev/null
+++ b/OTM_GUI/.project
@@ -0,0 +1,71 @@
+
+
+ OTM_GUI
+
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+ ?name?
+
+
+
+ org.eclipse.cdt.make.core.append_environment
+ true
+
+
+ org.eclipse.cdt.make.core.buildArguments
+
+
+
+ org.eclipse.cdt.make.core.buildCommand
+ make
+
+
+ org.eclipse.cdt.make.core.buildLocation
+ ${workspace_loc:/OTM_GUI/Default}
+
+
+ org.eclipse.cdt.make.core.contents
+ org.eclipse.cdt.make.core.activeConfigSettings
+
+
+ org.eclipse.cdt.make.core.enableAutoBuild
+ false
+
+
+ org.eclipse.cdt.make.core.enableCleanBuild
+ true
+
+
+ org.eclipse.cdt.make.core.enableFullBuild
+ true
+
+
+ org.eclipse.cdt.make.core.stopOnError
+ true
+
+
+ org.eclipse.cdt.make.core.useDefaultBuildCmd
+ true
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.core.ccnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
diff --git a/OTM_GUI/OTM.ico b/OTM_GUI/OTM.ico
new file mode 100644
index 0000000..d04d250
Binary files /dev/null and b/OTM_GUI/OTM.ico differ
diff --git a/OTM_GUI/OTM.rc b/OTM_GUI/OTM.rc
new file mode 100644
index 0000000..bd6ec5f
--- /dev/null
+++ b/OTM_GUI/OTM.rc
@@ -0,0 +1 @@
+MAINICON ICON "OTM.ico"
\ No newline at end of file
diff --git a/OTM_GUI/OTM_Client.cpp b/OTM_GUI/OTM_Client.cpp
new file mode 100644
index 0000000..08cf5ed
--- /dev/null
+++ b/OTM_GUI/OTM_Client.cpp
@@ -0,0 +1,91 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#include "OTM_Main.h"
+
+OTM_Client::OTM_Client( PipeStruct &pipe, OTM_Frame *frame) : wxThread(wxTHREAD_JOINABLE)
+{
+ Pipe.In = pipe.In;
+ Pipe.Out = pipe.Out;
+ MainFrame = frame;
+}
+
+OTM_Client::~OTM_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* OTM_Client::Entry(void)
+{
+ char buffer[BUFSIZE];
+ while (1)
+ {
+ unsigned long size;
+ bool ret = ReadFile(
+ Pipe.In, // handle to pipe
+ buffer, // buffer to receive data
+ 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 (posControl)
+ {
+
+ }
+ pos+=sizeof(MsgStruct);// + add_length;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ CloseHandle(Pipe.In);
+ Pipe.In = INVALID_HANDLE_VALUE;
+ CloseHandle(Pipe.Out);
+ Pipe.Out = INVALID_HANDLE_VALUE;
+
+ OTM_Event event( OTM_EVENT_TYPE, ID_Delete_Game);
+ event.SetClient(this);
+ wxPostEvent( MainFrame, event);
+
+ return NULL;
+}
+
diff --git a/OTM_GUI/OTM_Client.h b/OTM_GUI/OTM_Client.h
new file mode 100644
index 0000000..22f26fe
--- /dev/null
+++ b/OTM_GUI/OTM_Client.h
@@ -0,0 +1,45 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_CLIENT_H_
+#define OTM_CLIENT_H_
+
+#include "OTM_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 OTM_Client : public wxThread
+{
+public:
+ OTM_Client( PipeStruct &pipe, OTM_Frame *frame);
+ virtual ~OTM_Client(void);
+
+ void* Entry(void);
+
+
+ PipeStruct Pipe;
+
+private:
+ OTM_Frame *MainFrame;
+};
+
+#endif /* OTM_CLIENT_H_ */
diff --git a/OTM_GUI/OTM_Event.cpp b/OTM_GUI/OTM_Event.cpp
new file mode 100644
index 0000000..1bfb958
--- /dev/null
+++ b/OTM_GUI/OTM_Event.cpp
@@ -0,0 +1,23 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#include "OTM_Main.h"
+
+
diff --git a/OTM_GUI/OTM_Event.h b/OTM_GUI/OTM_Event.h
new file mode 100644
index 0000000..d5b853f
--- /dev/null
+++ b/OTM_GUI/OTM_Event.h
@@ -0,0 +1,70 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_EVENTTYPE_H_
+#define OTM_EVENTTYPE_H_
+#include "OTM_Client.h"
+#include "OTM_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( OTM_EVENT_TYPE, -1)
+END_DECLARE_EVENT_TYPES()
+
+class OTM_Event : public wxCommandEvent
+{
+public:
+ OTM_Event( wxEventType commandType = OTM_EVENT_TYPE, int id = 0 )
+ : wxCommandEvent(commandType, id) { }
+ virtual ~OTM_Event(void) {}
+
+ // You *must* copy here the data to be transported
+ OTM_Event( const OTM_Event &event )
+ : wxCommandEvent(event) { this->SetText( event.GetText()); PipeIn=((OTM_Event&)event).GetPipeIn(); PipeOut=((OTM_Event&)event).GetPipeOut(); Name=((OTM_Event&)event).GetName(); Client=((OTM_Event&)event).GetClient();}
+
+ // Required for sending with wxPostEvent()
+ wxEvent* Clone() const { return new OTM_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;}
+ OTM_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( OTM_Client *client) {Client=client;}
+
+private:
+
+ wxString Name;
+ HANDLE PipeIn;
+ HANDLE PipeOut;
+ OTM_Client *Client;
+
+ wxString m_Text;
+};
+
+
+#endif /* OTM_EVENTTYPE_H_ */
diff --git a/OTM_GUI/OTM_GUI.cpp b/OTM_GUI/OTM_GUI.cpp
new file mode 100644
index 0000000..93fc1f3
--- /dev/null
+++ b/OTM_GUI/OTM_GUI.cpp
@@ -0,0 +1,262 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+
+
+#include "OTM_Main.h"
+
+
+
+
+
+#ifndef __CDT_PARSER__
+
+DEFINE_EVENT_TYPE(OTM_EVENT_TYPE)
+
+BEGIN_EVENT_TABLE(OTM_Frame, wxFrame)
+ EVT_CLOSE(OTM_Frame::OnClose)
+
+ EVT_BUTTON(ID_Button_Open, OTM_Frame::OnButtonOpen)
+ EVT_BUTTON(ID_Button_Path, OTM_Frame::OnButtonPath)
+ EVT_BUTTON(ID_Button_Update, OTM_Frame::OnButtonUpdate)
+
+ EVT_MENU(ID_Menu_Pref, OTM_Frame::OnMenuPref)
+ EVT_MENU(ID_Menu_Quit, OTM_Frame::OnMenuQuit)
+ EVT_MENU(ID_Menu_Help, OTM_Frame::OnMenuHelp)
+ EVT_MENU(ID_Menu_About, OTM_Frame::OnMenuAbout)
+
+ EVT_COMMAND (ID_Add_Game, OTM_EVENT_TYPE, OTM_Frame::OnAddGame)
+ EVT_COMMAND (ID_Delete_Game, OTM_EVENT_TYPE, OTM_Frame::OnDeleteGame)
+END_EVENT_TABLE()
+
+IMPLEMENT_APP(MyApp)
+#endif
+
+bool MyApp::OnInit(void)
+{
+
+ OTM_Frame *frame = new OTM_Frame( "OpenTexMod", wxDefaultPosition, wxSize(600,400));
+ SetTopWindow( frame );
+
+ return true;
+}
+
+
+OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& size)
+ : wxFrame((wxFrame *)NULL, -1, title, pos, size)
+{
+ SetIcon(wxICON(MAINICON));
+ if (Language.LoadLanguage(1)!=0)
+ {
+ wxMessageBox("Could not load language", "Error", wxOK);
+ Destroy();
+ }
+ Server = new OTM_Server( this);
+ Server->Create();
+ Server->Run();
+
+ MenuBar = new wxMenuBar;
+ MenuMain = new wxMenu;
+ MenuHelp = new wxMenu;
+
+ MenuMain->Append( ID_Menu_Pref, Language.MenuPref, Language.MenuPref );
+ MenuMain->Append( ID_Menu_Quit, Language.MenuQuit, Language.MenuQuit );
+
+ MenuHelp->Append( ID_Menu_Help, Language.MenuHelp, Language.MenuHelp );
+ MenuHelp->Append( ID_Menu_About, Language.MenuAbout, Language.MenuAbout );
+
+ MenuBar->Append( MenuMain, Language.MainMenuStart );
+ MenuBar->Append( MenuHelp, Language.MainMenuHelp );
+
+ SetMenuBar(MenuBar);
+
+
+ MainSizer = new wxBoxSizer(wxVERTICAL);
+
+ Notebook = new wxNotebook( this, wxID_ANY);
+ MainSizer->Add( Notebook, 1, wxEXPAND , 0 );
+
+ ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
+
+ OpenButton = new wxButton( this, ID_Button_Open, Language.ButtonOpen, wxDefaultPosition, wxSize(100,24));
+ DirectoryButton = new wxButton( this, ID_Button_Path, Language.ButtonDirectory, wxDefaultPosition, wxSize(100,24));
+ UpdateButton = new wxButton( this, ID_Button_Update, Language.ButtonUpdate, wxDefaultPosition, wxSize(100,24));
+ ButtonSizer->Add( OpenButton, 1, wxEXPAND, 0);
+ ButtonSizer->Add( DirectoryButton, 1, wxEXPAND, 0);
+ ButtonSizer->Add( UpdateButton, 1, wxEXPAND, 0);
+ MainSizer->Add( ButtonSizer, 0, wxEXPAND , 0 );
+
+
+ SetSizer( MainSizer);
+
+ NumberOfGames = 0;
+ MaxNumberOfGames = 10;
+ Games = new OTM_GameInfo*[MaxNumberOfGames];
+ Clients = new OTM_Client*[MaxNumberOfGames];
+
+ Show( true );
+
+
+ HMODULE hMod = LoadLibraryW(OTM_d3d9_dll);
+ typedef void (*fkt_typ)(void);
+ fkt_typ InstallHook = (fkt_typ) GetProcAddress( hMod, "InstallHook");
+ InstallHook();
+
+}
+
+OTM_Frame::~OTM_Frame(void)
+{
+ if (Server!=(OTM_Server*)0)
+ {
+ KillServer();
+ Server->Wait();
+ delete Server;
+ Server = NULL;
+ }
+
+ HMODULE hMod = LoadLibraryW( OTM_d3d9_dll);
+ typedef void (*fkt_typ)(void);
+ fkt_typ RemoveHook = (fkt_typ) GetProcAddress( hMod, "RemoveHook");
+ RemoveHook();
+ FreeLibrary(hMod);
+}
+
+int OTM_Frame::KillServer(void)
+{
+ HANDLE pipe = CreateFileW( PIPE_Game2OTM,// pipe name
+ GENERIC_WRITE,
+ 0, // no sharing
+ NULL, // default security attributes
+ OPEN_EXISTING, // opens existing pipe
+ 0, // default attributes
+ NULL); // no template file
+
+ if (pipe == INVALID_HANDLE_VALUE) return -1;
+
+ const wchar_t *str = ABORT_SERVER;
+ unsigned int len=0u;
+ while (str[len]) len++;
+ len++; //to send also the zero
+ unsigned long num;
+ WriteFile( pipe, (const void*) str, len*sizeof(wchar_t), &num, NULL);
+ CloseHandle(pipe);
+ return 0;
+}
+
+
+
+void OTM_Frame::OnAddGame( wxCommandEvent &event)
+{
+ if (NumberOfGames>=MaxNumberOfGames) return;
+
+ wxString name = ((OTM_Event&)event).GetName();
+ PipeStruct pipe;
+
+ pipe.In = ((OTM_Event&)event).GetPipeIn();
+ pipe.Out = ((OTM_Event&)event).GetPipeOut();
+
+ OTM_GameInfo *game = new OTM_GameInfo( name);
+ OTM_Client *client = new OTM_Client( pipe, this);
+ client->Create();
+ client->Run();
+
+ OTM_GamePage *page = new OTM_GamePage( Notebook, game, client->Pipe, Language);
+
+ Notebook->AddPage( page, name, true);
+
+ Games[NumberOfGames] = game;
+ Clients[NumberOfGames] = client;
+ NumberOfGames++;
+}
+
+void OTM_Frame::OnDeleteGame( wxCommandEvent &event)
+{
+ OTM_Client *client = ((OTM_Event&)event).GetClient();
+ int index = -1;
+ for (int i=0; iDeletePage(i);
+ //Games[i]->Wait();
+ Clients[i]->Delete();
+ delete Clients[i];
+ delete Games[i];
+ NumberOfGames--;
+ for (int j=i; j0)
+ {
+ event.Veto();
+ wxMessageBox("Very bad idea to close OpenTexMod before closing the hooked Games!", "ERROR", wxOK);
+ return;
+ }
+ event.Skip();
+ Destroy();
+}
+
+void OTM_Frame::OnButtonOpen(wxCommandEvent& WXUNUSED(event))
+{
+ if (Notebook->GetPageCount()==0) return;
+ OTM_GamePage *page = (OTM_GamePage*) Notebook->GetCurrentPage();
+ if (page==NULL) return;
+
+ wxString file_name = wxFileSelector( Language.ChooseFile, TexturePath, "", "dds", "textures (*.dds)|*.dds", wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
+ if ( !file_name.empty() )
+ {
+ TexturePath = file_name.BeforeLast( '/');
+ page->AddTexture( file_name);
+ }
+}
+
+void OTM_Frame::OnButtonPath(wxCommandEvent& WXUNUSED(event))
+{
+ if (Notebook->GetPageCount()==0) return;
+ OTM_GamePage *page = (OTM_GamePage*) Notebook->GetCurrentPage();
+ if (page==NULL) return;
+
+ wxString dir = wxDirSelector(Language.ChooseDir);
+ if ( !dir.empty() )
+ {
+ page->SetPath( dir);
+ }
+}
+
+void OTM_Frame::OnButtonUpdate(wxCommandEvent& WXUNUSED(event))
+{
+ if (Notebook->GetPageCount()==0) return;
+ OTM_GamePage *page = (OTM_GamePage*) Notebook->GetCurrentPage();
+ if (page==NULL) return;
+ page->UpdateGame();
+}
+
+void OTM_Frame::OnMenuPref(wxCommandEvent& WXUNUSED(event)) {}
+void OTM_Frame::OnMenuQuit(wxCommandEvent& WXUNUSED(event)) {Destroy();}
+void OTM_Frame::OnMenuHelp(wxCommandEvent& WXUNUSED(event)) {}
+
+void OTM_Frame::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
+{
+ wxMessageBox("OpenTexMod V0.0 by ROTA", "Info", wxOK);
+};
diff --git a/OTM_GUI/OTM_GUI.h b/OTM_GUI/OTM_GUI.h
new file mode 100644
index 0000000..6c218e3
--- /dev/null
+++ b/OTM_GUI/OTM_GUI.h
@@ -0,0 +1,91 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_GUI_H_
+#define OTM_GUI_H_
+
+
+#include "OTM_Main.h"
+
+class OTM_Frame : public wxFrame
+{
+public:
+ OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& size);
+ ~OTM_Frame(void);
+
+
+ void OnAddGame( wxCommandEvent &event);
+ void OnDeleteGame( wxCommandEvent &event);
+
+ void OnClose(wxCloseEvent& WXUNUSED(event));
+
+
+ void OnButtonOpen(wxCommandEvent& WXUNUSED(event));
+ void OnButtonPath(wxCommandEvent& WXUNUSED(event));
+ void OnButtonUpdate(wxCommandEvent& WXUNUSED(event));
+
+
+ void OnMenuPref(wxCommandEvent& WXUNUSED(event));
+ void OnMenuQuit(wxCommandEvent& WXUNUSED(event));
+ void OnMenuHelp(wxCommandEvent& WXUNUSED(event));
+ void OnMenuAbout(wxCommandEvent& WXUNUSED(event));
+
+private:
+ int KillServer(void);
+
+ OTM_Server *Server;
+
+ OTM_Language Language;
+ wxNotebook *Notebook;
+
+
+ wxButton *OpenButton;
+ wxButton *DirectoryButton;
+ wxButton *UpdateButton;
+
+
+ wxMenuBar *MenuBar;
+ wxMenu *MenuMain;
+ wxMenu *MenuHelp;
+
+ wxBoxSizer *MainSizer;
+ wxBoxSizer *ButtonSizer;
+
+ wxString TexturePath;
+
+
+ int NumberOfGames;
+ int MaxNumberOfGames;
+ OTM_GameInfo **Games;
+ OTM_Client **Clients;
+
+ DECLARE_EVENT_TABLE();
+};
+
+class MyApp : public wxApp
+{
+public:
+ virtual bool OnInit();
+};
+
+
+
+
+#endif
diff --git a/OTM_GUI/OTM_GUI.ico b/OTM_GUI/OTM_GUI.ico
new file mode 100644
index 0000000..d551aa3
Binary files /dev/null and b/OTM_GUI/OTM_GUI.ico differ
diff --git a/OTM_GUI/OTM_GameInfo.cpp b/OTM_GUI/OTM_GameInfo.cpp
new file mode 100644
index 0000000..dce39f3
--- /dev/null
+++ b/OTM_GUI/OTM_GameInfo.cpp
@@ -0,0 +1,69 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#include "OTM_Main.h"
+
+
+
+OTM_GameInfo::OTM_GameInfo(const wxString &name)
+{
+ Name = name;
+ SaveSingleTexture = false;
+ SaveAllTextures = false;
+
+ KeyBack = 0;
+ KeySave = 0;
+ KeyNext = 0;
+}
+
+
+OTM_GameInfo::~OTM_GameInfo(void)
+{
+}
+
+int OTM_GameInfo::SetSaveSingleTexture(bool val)
+{
+ SaveSingleTexture = val;
+ return 0;
+}
+
+int OTM_GameInfo::SetSaveAllTextures(bool val)
+{
+ SaveAllTextures = val;
+ return 0;
+}
+
+void OTM_GameInfo::SetTextures(const wxArrayString &textures)
+{
+ Textures = textures;
+}
+
+void OTM_GameInfo::GetTextures( wxArrayString &textures)
+{
+ textures = Textures;
+}
+
+void OTM_GameInfo::AddTexture( const wxString &textures)
+{
+ Textures.Add(textures);
+}
+
+
+
diff --git a/OTM_GUI/OTM_GameInfo.h b/OTM_GUI/OTM_GameInfo.h
new file mode 100644
index 0000000..c4edcf4
--- /dev/null
+++ b/OTM_GUI/OTM_GameInfo.h
@@ -0,0 +1,73 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_GAME_H_
+#define OTM_GAME_H_
+#include "OTM_Main.h"
+
+//this class is intended as a storing object for each game
+// one should ad an assignment operator, loading and saving default values, ...
+class OTM_GameInfo
+{
+public:
+ OTM_GameInfo(const wxString &name);
+ ~OTM_GameInfo(void);
+
+ wxString Name;
+
+
+ int SetSaveSingleTexture(bool val);
+ bool GetSaveSingleTexture(void) {return SaveSingleTexture;}
+
+ int SetSaveAllTextures(bool val);
+ bool GetSaveAllTextures(void) {return SaveAllTextures;}
+
+ void SetTextures(const wxArrayString &textures);
+ void GetTextures( wxArrayString &textures);
+ void AddTexture( const wxString &textures);
+
+ int SendTextures(void);
+
+ int GetKeyBack() {return KeyBack;}
+ int SetKeyBack(int key) {KeyBack=key; return 0;}
+
+ int GetKeySave() {return KeySave;}
+ int SetKeySave(int key) {KeySave=key; return 0;}
+
+ int GetKeyNext() {return KeyNext;}
+ int SetKeyNext(int key) {KeyNext=key; return 0;}
+
+ int SetPath(const wxString &path) {Path=path; return 0;}
+ wxString GetPath(void) {return Path;}
+
+private:
+ bool SaveSingleTexture;
+ bool SaveAllTextures;
+ wxArrayString Textures;
+
+ int KeyBack;
+ int KeySave;
+ int KeyNext;
+
+ wxString Path;
+};
+
+
+#endif /* OTM_SERVER_H_ */
diff --git a/OTM_GUI/OTM_GamePage.cpp b/OTM_GUI/OTM_GamePage.cpp
new file mode 100644
index 0000000..108c1ed
--- /dev/null
+++ b/OTM_GUI/OTM_GamePage.cpp
@@ -0,0 +1,178 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+
+#include "OTM_Main.h"
+
+OTM_GamePage::OTM_GamePage( wxNotebook *parent, OTM_GameInfo *game, PipeStruct &pipe, OTM_Language &lang) : wxPanel(parent), Language(lang), Sender(pipe)
+{
+ MainSizer = new wxBoxSizer(wxVERTICAL);
+ Game = game;
+
+ wxArrayString array;
+
+ array = Language.Keys;
+ array[0] = Language.KeyBack;
+ ChoiceKeyBack = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, array);
+ MainSizer->Add( ChoiceKeyBack, 1, wxEXPAND, 0);
+
+ array = Language.Keys;
+ array[0] = Language.KeySave;
+ ChoiceKeySave = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, array);
+ MainSizer->Add( ChoiceKeySave, 1, wxEXPAND, 0);
+
+ array = Language.Keys;
+ array[0] = Language.KeyNext;
+ ChoiceKeyNext = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, array);
+ MainSizer->Add( ChoiceKeyNext, 1, wxEXPAND, 0);
+
+
+ Game->GetTextures( array);
+
+ NumberOfEntry = array.GetCount()+2;
+ MaxNumberOfEntry = NumberOfEntry+100;
+ CheckBoxes = new wxCheckBox*[MaxNumberOfEntry];
+
+
+ CheckBoxes[0] = new wxCheckBox( this, -1, Language.CheckBoxSaveSingleTexture);
+ CheckBoxes[0]->SetValue( Game->GetSaveSingleTexture());
+ MainSizer->Add( CheckBoxes[0], 1, wxEXPAND, 0);
+
+ CheckBoxes[1] = new wxCheckBox( this, -1, Language.CheckBoxSaveAllTextures);
+ CheckBoxes[1]->SetValue( Game->GetSaveAllTextures());
+ MainSizer->Add( CheckBoxes[1], 1, wxEXPAND, 0);
+
+
+
+ wxString name;
+ for (int i=2; iSetValue( true);
+ MainSizer->Add( CheckBoxes[i], 1, wxEXPAND, 0);
+ }
+ SetSizer(MainSizer);
+}
+
+OTM_GamePage::~OTM_GamePage(void)
+{
+
+}
+
+void OTM_GamePage::SetPath( const wxString &path)
+{
+ if (path!=Game->GetPath())
+ {
+ Game->SetPath( path);
+ Sender.SendPath( path);
+ }
+}
+void OTM_GamePage::AddTexture( const wxString &file_name)
+{
+ if (NumberOfEntry>=MaxNumberOfEntry) return;
+ Game->AddTexture( file_name);
+
+ wxString file = file_name.AfterLast( '/');
+ CheckBoxes[NumberOfEntry] = new wxCheckBox( this, -1, file);
+ CheckBoxes[NumberOfEntry]->SetValue( true);
+ MainSizer->Add( CheckBoxes[NumberOfEntry], 1, wxEXPAND, 0);
+ NumberOfEntry++;
+
+ MainSizer->Layout();
+}
+
+int OTM_GamePage::UpdateGame(void)
+{
+ bool save_tex = CheckBoxes[0]->GetValue();
+ if (save_tex != Game->GetSaveSingleTexture())
+ {
+ Sender.SendSaveSingleTexture(save_tex);
+ Game->SetSaveSingleTexture(save_tex);
+ if (save_tex)
+ {
+ //to add get choices
+ int key_back = VK_DIVIDE;
+ int key_save = VK_MULTIPLY;
+ int key_next = VK_SUBTRACT;
+
+ if (key_back!=Game->GetKeyBack())
+ {
+ Game->SetKeyBack( key_back);
+ Sender.SendKeyBack(key_back);
+ }
+ if (key_save!=Game->GetKeySave())
+ {
+ Game->SetKeySave( key_save);
+ Sender.SendKeySave(key_save);
+ }
+ if (key_next!=Game->GetKeyNext())
+ {
+ Game->SetKeyNext( key_next);
+ Sender.SendKeyNext(key_next);
+ }
+ }
+ }
+
+ save_tex = CheckBoxes[1]->GetValue();
+ if (save_tex != Game->GetSaveAllTextures())
+ {
+ Sender.SendSaveAllTextures(save_tex);
+ Game->SetSaveAllTextures(save_tex);
+ }
+
+ if (NumberOfEntry<=2) return 0;
+
+ wxArrayString textures;
+ wxArrayString send_tex;
+ Game->GetTextures( textures);
+ int num = textures.GetCount();
+ unsigned long hash [num];
+ bool add[num];
+ bool force[num];
+ if (num!=NumberOfEntry-2) return -1;
+
+ wxString name;
+ unsigned long temp_hash;
+ int count = 0;
+ for (int i=0; iGetValue();
+ force[count] = true;
+ hash[count++] = temp_hash;
+ }
+ else wxMessageBox("UpdateGame(): no Ulong", "Info", wxOK);
+
+ }
+ if (count) return Sender.SendTextures( send_tex, hash, add, force);
+
+ return 0;
+}
+
+
+
diff --git a/OTM_GUI/OTM_GamePage.h b/OTM_GUI/OTM_GamePage.h
new file mode 100644
index 0000000..0a20110
--- /dev/null
+++ b/OTM_GUI/OTM_GamePage.h
@@ -0,0 +1,53 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_GAMEPAGE_H_
+#define OTM_GAMEPAGE_H_
+#include "OTM_Main.h"
+
+
+// this page is opened if a game is started.
+class OTM_GamePage : public wxPanel
+{
+public:
+ OTM_GamePage( wxNotebook *parent, OTM_GameInfo *game, PipeStruct &pipe, OTM_Language &lang);
+ virtual ~OTM_GamePage(void);
+
+ void AddTexture( const wxString &file_name);
+ void SetPath( const wxString &file_name);
+ int UpdateGame(void);
+
+private:
+ wxChoice *ChoiceKeyBack;
+ wxChoice *ChoiceKeySave;
+ wxChoice *ChoiceKeyNext;
+
+ wxBoxSizer *MainSizer;
+ wxCheckBox **CheckBoxes;
+ int NumberOfEntry;
+ int MaxNumberOfEntry;
+ OTM_Language &Language;
+
+ OTM_GameInfo *Game;
+
+ OTM_Sender Sender;
+};
+
+#endif /* OTM_GAMEPAGE_H_ */
diff --git a/OTM_GUI/OTM_Language.cpp b/OTM_GUI/OTM_Language.cpp
new file mode 100644
index 0000000..4f93170
--- /dev/null
+++ b/OTM_GUI/OTM_Language.cpp
@@ -0,0 +1,330 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#include "OTM_Main.h"
+
+
+OTM_Language::OTM_Language(void)
+{
+ LoadLanguage(0); //English
+}
+
+int OTM_Language::LoadLanguage(int lang)
+{
+ if (lang==0) //English
+ {
+ MenuPref = L"Preferences";
+ MenuQuit = L"Quit";
+ MenuHelp = L"Help";
+ MenuAbout = L"About";
+
+ MainMenuStart = L"Start";
+ MainMenuHelp = L"Help";
+
+ ButtonOpen = L"Open texture";
+ ButtonDirectory = L"Set save directory";
+ ButtonUpdate = L"Update";
+
+ ChooseFile = L"Choose a texture file";
+ ChooseDir = L"Choose a directory";
+
+ CheckBoxSaveSingleTexture = L"Save single texture";
+ CheckBoxSaveAllTextures = L"Save all textures";
+ }
+
+ LoadKeys(lang);
+ return 0;
+}
+
+int OTM_Language::LoadKeys(int lang)
+{
+ if (lang==0) //English
+ {
+ KeyBack = L"Back";
+ KeySave = L"Save";
+ KeyNext = L"Next";
+ }
+
+ Keys.Empty();
+ Keys.Add(L"Default");
+ return 0;
+/*
+
+#define VK_LBUTTON 0x01
+#define VK_RBUTTON 0x02
+#define VK_CANCEL 0x03
+#define VK_MBUTTON 0x04 // NOT contiguous with L & RBUTTON
+
+#if(_WIN32_WINNT >= 0x0500)
+#define VK_XBUTTON1 0x05 // NOT contiguous with L & RBUTTON
+#define VK_XBUTTON2 0x06 // NOT contiguous with L & RBUTTON
+#endif // _WIN32_WINNT >= 0x0500
+
+
+// * 0x07 : unassigned
+
+
+#define VK_BACK 0x08
+#define VK_TAB 0x09
+
+
+// 0x0A - 0x0B : reserved
+
+
+#define VK_CLEAR 0x0C
+#define VK_RETURN 0x0D
+
+#define VK_SHIFT 0x10
+#define VK_CONTROL 0x11
+#define VK_MENU 0x12
+#define VK_PAUSE 0x13
+#define VK_CAPITAL 0x14
+
+#define VK_KANA 0x15
+#define VK_HANGEUL 0x15 // old name - should be here for compatibility
+#define VK_HANGUL 0x15
+#define VK_JUNJA 0x17
+#define VK_FINAL 0x18
+#define VK_HANJA 0x19
+#define VK_KANJI 0x19
+
+#define VK_ESCAPE 0x1B
+
+#define VK_CONVERT 0x1C
+#define VK_NONCONVERT 0x1D
+#define VK_ACCEPT 0x1E
+#define VK_MODECHANGE 0x1F
+
+#define VK_SPACE 0x20
+#define VK_PRIOR 0x21
+#define VK_NEXT 0x22
+#define VK_END 0x23
+#define VK_HOME 0x24
+#define VK_LEFT 0x25
+#define VK_UP 0x26
+#define VK_RIGHT 0x27
+#define VK_DOWN 0x28
+#define VK_SELECT 0x29
+#define VK_PRINT 0x2A
+#define VK_EXECUTE 0x2B
+#define VK_SNAPSHOT 0x2C
+#define VK_INSERT 0x2D
+#define VK_DELETE 0x2E
+#define VK_HELP 0x2F
+
+
+// * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
+// * 0x40 : unassigned
+// * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)
+
+
+#define VK_LWIN 0x5B
+#define VK_RWIN 0x5C
+#define VK_APPS 0x5D
+
+
+// 0x5E : reserved
+
+
+#define VK_SLEEP 0x5F
+
+#define VK_NUMPAD0 0x60
+#define VK_NUMPAD1 0x61
+#define VK_NUMPAD2 0x62
+#define VK_NUMPAD3 0x63
+#define VK_NUMPAD4 0x64
+#define VK_NUMPAD5 0x65
+#define VK_NUMPAD6 0x66
+#define VK_NUMPAD7 0x67
+#define VK_NUMPAD8 0x68
+#define VK_NUMPAD9 0x69
+#define VK_MULTIPLY 0x6A
+#define VK_ADD 0x6B
+#define VK_SEPARATOR 0x6C
+#define VK_SUBTRACT 0x6D
+#define VK_DECIMAL 0x6E
+#define VK_DIVIDE 0x6F
+#define VK_F1 0x70
+#define VK_F2 0x71
+#define VK_F3 0x72
+#define VK_F4 0x73
+#define VK_F5 0x74
+#define VK_F6 0x75
+#define VK_F7 0x76
+#define VK_F8 0x77
+#define VK_F9 0x78
+#define VK_F10 0x79
+#define VK_F11 0x7A
+#define VK_F12 0x7B
+#define VK_F13 0x7C
+#define VK_F14 0x7D
+#define VK_F15 0x7E
+#define VK_F16 0x7F
+#define VK_F17 0x80
+#define VK_F18 0x81
+#define VK_F19 0x82
+#define VK_F20 0x83
+#define VK_F21 0x84
+#define VK_F22 0x85
+#define VK_F23 0x86
+#define VK_F24 0x87
+
+
+// 0x88 - 0x8F : unassigned
+
+
+#define VK_NUMLOCK 0x90
+#define VK_SCROLL 0x91
+
+
+// NEC PC-9800 kbd definitions
+
+#define VK_OEM_NEC_EQUAL 0x92 // '=' key on numpad
+
+
+// Fujitsu/OASYS kbd definitions
+
+#define VK_OEM_FJ_JISHO 0x92 // 'Dictionary' key
+#define VK_OEM_FJ_MASSHOU 0x93 // 'Unregister word' key
+#define VK_OEM_FJ_TOUROKU 0x94 // 'Register word' key
+#define VK_OEM_FJ_LOYA 0x95 // 'Left OYAYUBI' key
+#define VK_OEM_FJ_ROYA 0x96 // 'Right OYAYUBI' key
+
+//
+// 0x97 - 0x9F : unassigned
+//
+
+//
+// VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
+// Used only as parameters to GetAsyncKeyState() and GetKeyState().
+// No other API or message will distinguish left and right keys in this way.
+
+#define VK_LSHIFT 0xA0
+#define VK_RSHIFT 0xA1
+#define VK_LCONTROL 0xA2
+#define VK_RCONTROL 0xA3
+#define VK_LMENU 0xA4
+#define VK_RMENU 0xA5
+
+#if(_WIN32_WINNT >= 0x0500)
+#define VK_BROWSER_BACK 0xA6
+#define VK_BROWSER_FORWARD 0xA7
+#define VK_BROWSER_REFRESH 0xA8
+#define VK_BROWSER_STOP 0xA9
+#define VK_BROWSER_SEARCH 0xAA
+#define VK_BROWSER_FAVORITES 0xAB
+#define VK_BROWSER_HOME 0xAC
+
+#define VK_VOLUME_MUTE 0xAD
+#define VK_VOLUME_DOWN 0xAE
+#define VK_VOLUME_UP 0xAF
+#define VK_MEDIA_NEXT_TRACK 0xB0
+#define VK_MEDIA_PREV_TRACK 0xB1
+#define VK_MEDIA_STOP 0xB2
+#define VK_MEDIA_PLAY_PAUSE 0xB3
+#define VK_LAUNCH_MAIL 0xB4
+#define VK_LAUNCH_MEDIA_SELECT 0xB5
+#define VK_LAUNCH_APP1 0xB6
+#define VK_LAUNCH_APP2 0xB7
+
+#endif // _WIN32_WINNT >= 0x0500
+
+
+// 0xB8 - 0xB9 : reserved
+
+
+#define VK_OEM_1 0xBA // ';:' for US
+#define VK_OEM_PLUS 0xBB // '+' any country
+#define VK_OEM_COMMA 0xBC // ',' any country
+#define VK_OEM_MINUS 0xBD // '-' any country
+#define VK_OEM_PERIOD 0xBE // '.' any country
+#define VK_OEM_2 0xBF // '/?' for US
+#define VK_OEM_3 0xC0 // '`~' for US
+
+
+// 0xC1 - 0xD7 : reserved
+
+
+// 0xD8 - 0xDA : unassigned
+
+
+#define VK_OEM_4 0xDB // '[{' for US
+#define VK_OEM_5 0xDC // '\|' for US
+#define VK_OEM_6 0xDD // ']}' for US
+#define VK_OEM_7 0xDE // ''"' for US
+#define VK_OEM_8 0xDF
+
+
+// 0xE0 : reserved
+
+
+/
+// Various extended or enhanced keyboards
+
+#define VK_OEM_AX 0xE1 // 'AX' key on Japanese AX kbd
+#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd.
+#define VK_ICO_HELP 0xE3 // Help key on ICO
+#define VK_ICO_00 0xE4 // 00 key on ICO
+
+#if(WINVER >= 0x0400)
+#define VK_PROCESSKEY 0xE5
+#endif // WINVER >= 0x0400
+
+#define VK_ICO_CLEAR 0xE6
+
+
+#if(_WIN32_WINNT >= 0x0500)
+#define VK_PACKET 0xE7
+#endif // _WIN32_WINNT >= 0x0500
+
+
+// 0xE8 : unassigned
+
+
+//Nokia/Ericsson definitions
+
+#define VK_OEM_RESET 0xE9
+#define VK_OEM_JUMP 0xEA
+#define VK_OEM_PA1 0xEB
+#define VK_OEM_PA2 0xEC
+#define VK_OEM_PA3 0xED
+#define VK_OEM_WSCTRL 0xEE
+#define VK_OEM_CUSEL 0xEF
+#define VK_OEM_ATTN 0xF0
+#define VK_OEM_FINISH 0xF1
+#define VK_OEM_COPY 0xF2
+#define VK_OEM_AUTO 0xF3
+#define VK_OEM_ENLW 0xF4
+#define VK_OEM_BACKTAB 0xF5
+
+#define VK_ATTN 0xF6
+#define VK_CRSEL 0xF7
+#define VK_EXSEL 0xF8
+#define VK_EREOF 0xF9
+#define VK_PLAY 0xFA
+#define VK_ZOOM 0xFB
+#define VK_NONAME 0xFC
+#define VK_PA1 0xFD
+#define VK_OEM_CLEAR 0xFE
+
+
+ */
+}
+
diff --git a/OTM_GUI/OTM_Language.h b/OTM_GUI/OTM_Language.h
new file mode 100644
index 0000000..219f002
--- /dev/null
+++ b/OTM_GUI/OTM_Language.h
@@ -0,0 +1,64 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_LANGUAGE_H_
+#define OTM_LANGUAGE_H_
+
+class OTM_Language
+{
+public:
+ OTM_Language(void);
+
+
+ int LoadLanguage(int lang);
+
+ wxString MenuPref;
+ wxString MenuQuit;
+ wxString MenuHelp;
+ wxString MenuAbout;
+
+ wxString MainMenuStart;
+ wxString MainMenuHelp;
+
+ wxString ButtonOpen;
+ wxString ButtonDirectory;
+ wxString ButtonUpdate;
+
+ wxString ChooseFile;
+ wxString ChooseDir;
+
+ wxString CheckBoxSaveSingleTexture;
+ wxString CheckBoxSaveAllTextures;
+
+
+ wxString KeyBack;
+ wxString KeySave;
+ wxString KeyNext;
+ wxArrayString Keys;
+
+private:
+ int LoadKeys(int lang);
+};
+
+
+
+
+
+#endif /* OTM_LANGUAGE_H_ */
diff --git a/OTM_GUI/OTM_Main.h b/OTM_GUI/OTM_Main.h
new file mode 100644
index 0000000..163c522
--- /dev/null
+++ b/OTM_GUI/OTM_Main.h
@@ -0,0 +1,86 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_MAIN_H_
+#define OTM_MAIN_H_
+
+
+// I use eclipse and somehow i need these define or many of the wx classes are unknown to the CDT parser
+#ifdef __CDT_PARSER__
+#define HAVE_W32API_H
+#define __WXMSW__
+#define NOPCH
+#define _UNICODE
+#define wxUSE_NOTEBOOK 1
+#define wxUSE_CHECKBOX 1
+#define wxUSE_THREADS 1
+#define wxUSE_MSGDLG 1
+#define wxUSE_MENUS 1
+#define wxUSE_BUTTON 1
+#define wxUSE_FILEDLG 1
+#define wxUSE_DIRDLG 1
+#define wxUSE_CHOICE 1
+#endif
+
+
+#include "wx\wx.h"
+#include "wx\notebook.h"
+//#include
+//#include "wx/checkbox.h"
+//#include
+//#include
+//#include
+//#include
+//#include
+
+#include
+
+#include "../OTM_GlobalDefines.h"
+#include "../OTM_Error.h"
+
+
+class OTM_Frame;
+
+enum
+{
+ ID_Button_Open = wxID_HIGHEST,
+ ID_Button_Path,
+ ID_Button_Update,
+ ID_Menu_Pref,
+ ID_Menu_Quit,
+ ID_Menu_Help,
+ ID_Menu_About,
+ ID_Add_Game,
+ ID_Delete_Game
+};
+
+#define ABORT_SERVER L"OTM_Abort_Server"
+#define OTM_d3d9_dll L"OTM_d3d9.dll"
+
+#include "OTM_Language.h"
+#include "OTM_Event.h"
+#include "OTM_Sender.h"
+#include "OTM_Client.h"
+#include "OTM_GameInfo.h"
+#include "OTM_Server.h"
+#include "OTM_GamePage.h"
+#include "OTM_GUI.h"
+
+#endif
diff --git a/OTM_GUI/OTM_Sender.cpp b/OTM_GUI/OTM_Sender.cpp
new file mode 100644
index 0000000..6bf78fa
--- /dev/null
+++ b/OTM_GUI/OTM_Sender.cpp
@@ -0,0 +1,155 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#include "OTM_Main.h"
+
+OTM_Sender::OTM_Sender(PipeStruct &pipe) : Pipe(pipe)
+{
+}
+
+OTM_Sender::~OTM_Sender(void)
+{
+}
+
+int OTM_Sender::SendSaveAllTextures(bool val)
+{
+ MsgStruct msg;
+ msg.Control = CONTROL_SAVE_ALL;
+ if (val) msg.Value = 1;
+ else msg.Value = 0;
+ msg.Hash = 0u;
+
+ return SendToGame( (void*) &msg, sizeof(MsgStruct));
+}
+
+int OTM_Sender::SendSaveSingleTexture(bool val)
+{
+ MsgStruct msg;
+ msg.Control = CONTROL_SAVE_SINGLE;
+ if (val) msg.Value = 1;
+ else msg.Value = 0;
+ msg.Hash = 0u;
+
+ return SendToGame( (void*) &msg, sizeof(MsgStruct));
+}
+
+
+int OTM_Sender::SendTextures(const wxArrayString &textures, unsigned long *hash, bool *add, bool *force)
+{
+ char buffer[BUFSIZE];
+ int num = textures.GetCount();
+ MsgStruct *msg;
+ int pos = 0;
+ int old_pos = 0;
+ for (int i=0; iHash = hash[i];
+ if (add[i])
+ {
+ if (force[i]) msg->Control = CONTROL_FORCE_RELOAD_TEXTURE;
+ else msg->Control = CONTROL_ADD_TEXTURE;
+ }
+ else msg->Control = CONTROL_REMOVE_TEXTURE;
+ msg->Value = 0;
+ pos += sizeof(MsgStruct);
+
+ if (add[i] && pos=BUFSIZE)
+ {
+ if (int ret = SendToGame( buffer, old_pos)) return ret;
+ pos = 0; old_pos = 0; i--;
+ }
+ else old_pos = pos;
+ }
+ if (old_pos) if (int ret = SendToGame( buffer, old_pos)) return ret;
+ return 0;
+}
+
+
+int OTM_Sender::SendKeyBack(int key)
+{
+ MsgStruct msg;
+ msg.Control = CONTROL_KEY_BACK;
+ msg.Value = key;
+ msg.Hash = 0u;
+
+ return SendToGame( (void*) &msg, sizeof(MsgStruct));
+}
+
+int OTM_Sender::SendKeySave(int key)
+{
+ MsgStruct msg;
+ msg.Control = CONTROL_KEY_SAVE;
+ msg.Value = key;
+ msg.Hash = 0u;
+
+ return SendToGame( (void*) &msg, sizeof(MsgStruct));
+}
+
+int OTM_Sender::SendKeyNext(int key)
+{
+ MsgStruct msg;
+ msg.Control = CONTROL_KEY_NEXT;
+ msg.Value = key;
+ msg.Hash = 0u;
+
+ return SendToGame( (void*) &msg, sizeof(MsgStruct));
+}
+
+
+
+int OTM_Sender::SendPath( const wxString &path)
+{
+ char buffer[BUFSIZE];
+ MsgStruct *msg = (MsgStruct*) buffer;
+
+ msg->Hash = 0u;
+ msg->Control = CONTROL_SET_DIR;
+ msg->Value = 0;
+
+ const wchar_t *file = path.wc_str();
+ wchar_t *buff_file = (wchar_t*) &buffer[sizeof(MsgStruct)];
+ int len = 0;
+ while (file[len] && (sizeof(MsgStruct)+len*sizeof(wchar_t)).
+*/
+
+
+
+#ifndef OTM_SENDER_H_
+#define OTM_SENDER_H_
+#include "OTM_Main.h"
+
+// an object of this class is owned by each OTM_GamePage object. It act as sender ^^
+class OTM_Sender
+{
+public:
+ OTM_Sender(PipeStruct &pipe);
+ ~OTM_Sender(void);
+
+ int SendSaveAllTextures(bool val);
+ int SendSaveSingleTexture(bool val);
+
+ int SendTextures(const wxArrayString &textures, unsigned long *hash, bool *add, bool *force);
+
+ int SendKeyBack(int key);
+ int SendKeySave(int key);
+ int SendKeyNext(int key);
+
+ int SendPath( const wxString &path);
+
+private:
+
+ int SendToGame( void* msg, unsigned long len);
+ PipeStruct &Pipe;
+};
+
+
+#endif /* OTM_SENDER_H_ */
diff --git a/OTM_GUI/OTM_Server.cpp b/OTM_GUI/OTM_Server.cpp
new file mode 100644
index 0000000..aceca75
--- /dev/null
+++ b/OTM_GUI/OTM_Server.cpp
@@ -0,0 +1,133 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+
+#include "OTM_Main.h"
+
+
+OTM_Server::OTM_Server(OTM_Frame *frame) : wxThread(wxTHREAD_JOINABLE)
+{
+ MainFrame = frame;
+}
+
+
+OTM_Server::~OTM_Server(void)
+{
+}
+
+
+void* OTM_Server::Entry(void)
+{
+ bool fConnected = false;
+ HANDLE pipe_in;
+ HANDLE pipe_out;
+ char buffer[BUFSIZE];
+ wxString abort = ABORT_SERVER;
+
+ while(1)
+ {
+/*
+ Beep(300,100);
+ Beep(600,100);
+*/
+ pipe_in = CreateNamedPipeW(
+ PIPE_Game2OTM, // pipe name
+ PIPE_ACCESS_INBOUND, // read access
+ PIPE_TYPE_BYTE | // byte type pipe
+ PIPE_WAIT, // blocking mode
+ PIPE_UNLIMITED_INSTANCES, // max. instances
+ BUFSIZE, // output buffer size
+ BUFSIZE, // input buffer size
+ 0, // client time-out
+ NULL); // default security attribute
+ if (pipe_in == INVALID_HANDLE_VALUE) return NULL;
+
+ pipe_out = CreateNamedPipeW(
+ PIPE_OTM2Game, // pipe name
+ PIPE_ACCESS_OUTBOUND, // write access
+ PIPE_TYPE_BYTE | // byte type pipe
+ PIPE_WAIT, // blocking mode
+ PIPE_UNLIMITED_INSTANCES, // max. instances
+ BUFSIZE, // output buffer size
+ BUFSIZE, // input buffer size
+ 0, // client time-out
+ NULL); // default security attribute
+ if (pipe_out == INVALID_HANDLE_VALUE) return NULL;
+
+
+ // at first connect to the incoming pipe !!!
+ fConnected = ConnectNamedPipe(pipe_in, NULL) ?
+ true : (GetLastError() == ERROR_PIPE_CONNECTED);
+ /*
+ Beep(900,100);
+ Beep(600,100);
+ Beep(300,100);
+ */
+ if (fConnected)
+ {
+ unsigned long num = 0;
+ //read the name of the game
+ bool fSuccess = ReadFile(
+ pipe_in, // handle to pipe
+ buffer, // buffer to receive data
+ BUFSIZE, // size of buffer
+ &num, // number of bytes read
+ NULL); // not overlapped I/O
+
+ if (fSuccess)
+ {
+ if (num>2)
+ {
+ buffer[num]=0;
+ buffer[num-1]=0;
+ wxString name = (wchar_t*) buffer;
+
+ if (name==abort) // kill this server thread
+ {
+ //Beep(1200,300);
+ CloseHandle(pipe_in);
+ return NULL;
+ }
+
+
+ fConnected = ConnectNamedPipe(pipe_out, NULL) ?
+ true : (GetLastError() == ERROR_PIPE_CONNECTED);
+ if (fConnected)
+ {
+ OTM_Event event( OTM_EVENT_TYPE, ID_Add_Game);
+ event.SetName(name);
+ event.SetPipeIn(pipe_in);
+ event.SetPipeOut(pipe_out);
+ wxPostEvent( MainFrame, event);
+ }
+ else
+ {
+ CloseHandle(pipe_in);
+ CloseHandle(pipe_out);
+ return NULL;
+ }
+ }
+ }
+ }
+ else CloseHandle(pipe_in);
+ }
+ return NULL;
+}
+
diff --git a/OTM_GUI/OTM_Server.h b/OTM_GUI/OTM_Server.h
new file mode 100644
index 0000000..8ab81c8
--- /dev/null
+++ b/OTM_GUI/OTM_Server.h
@@ -0,0 +1,45 @@
+/*
+This file is part of OpenTexMod.
+
+
+OpenTexMod 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.
+
+OpenTexMod 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 FooOpenTexMod. If not, see .
+*/
+
+
+
+#ifndef OTM_SERVER_H_
+#define OTM_SERVER_H_
+#include "OTM_Main.h"
+
+// an object of this class should be created only once
+// it waits for incomming connections (a starting game)
+// and if so, it send a message to the mainthread
+
+// Note the server thread can only be killed, if one connect to it and send "OTM_ABORT" as game name
+class OTM_Server : public wxThread
+{
+public:
+ OTM_Server(OTM_Frame *frame);
+ virtual ~OTM_Server(void);
+
+
+ void* Entry(void);
+
+private:
+
+ OTM_Frame *MainFrame;
+};
+
+
+#endif /* OTM_SERVER_H_ */
diff --git a/OTM_GUI/config.gcc b/OTM_GUI/config.gcc
new file mode 100644
index 0000000..2c05b6d
--- /dev/null
+++ b/OTM_GUI/config.gcc
@@ -0,0 +1,149 @@
+# =========================================================================
+# 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 ?= dynamic
+
+# 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
+
diff --git a/OTM_GUI/makefile b/OTM_GUI/makefile
new file mode 100644
index 0000000..57c5d79
--- /dev/null
+++ b/OTM_GUI/makefile
@@ -0,0 +1,267 @@
+# =========================================================================
+# 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\wx
+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 -I. \
+ $(__DLLFLAG_p) -DNOPCH $(__RTTIFLAG_5) \
+ $(__EXCEPTIONSFLAG_6) -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)
+MINIMAL_OBJECTS = \
+ $(OBJS)\OTM_rc.o \
+ $(OBJS)\OTM_GUI.o \
+ $(OBJS)\OTM_GameInfo.o \
+ $(OBJS)\OTM_GamePage.o \
+ $(OBJS)\OTM_Server.o \
+ $(OBJS)\OTM_Client.o \
+ $(OBJS)\OTM_Sender.o \
+ $(OBJS)\OTM_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
+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)\OTM_GUI.exe
+
+clean:
+ -if exist $(OBJS)\*.o del $(OBJS)\*.o
+ -if exist $(OBJS)\*.d del $(OBJS)\*.d
+ -if exist $(OBJS_exe)\SeriesReminder.exe del $(OBJS_exe)\SeriesReminder.exe
+
+$(OBJS_exe)\OTM_GUI.exe: $(MINIMAL_OBJECTS) $(OBJS)\OTM_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)\SR_rc.o: SR.rc
+# windres --use-temp-file -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) $(__MSLU_DEFINE_p_1) $(__GFXCTX_DEFINE_p_1) --include-dir $(SETUPHDIR) --include-dir $(WX_DIR)/include --include-dir . $(__DLLFLAG_p_1)
+
+$(OBJS)\OTM_rc.o: OTM.rc OTM.ico
+ windres --use-temp-file -i $< -o $@
+
+$(OBJS)\OTM_GUI.o: ./OTM_GUI.cpp
+ $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
+
+$(OBJS)\OTM_GameInfo.o: ./OTM_GameInfo.cpp
+ $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
+
+$(OBJS)\OTM_GamePage.o: ./OTM_GamePage.cpp
+ $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
+
+$(OBJS)\OTM_Server.o: ./OTM_Server.cpp
+ $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
+
+$(OBJS)\OTM_Client.o: ./OTM_Client.cpp
+ $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
+
+$(OBJS)\OTM_Sender.o: ./OTM_Sender.cpp
+ $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
+
+$(OBJS)\OTM_Language.o: ./OTM_Language.cpp
+ $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
+
+
+.PHONY: all clean
+
+
+# Dependencies tracking:
+-include $(OBJS)/*.d
diff --git a/OTM_GlobalDefines.h b/OTM_GlobalDefines.h
new file mode 100644
index 0000000..4857741
--- /dev/null
+++ b/OTM_GlobalDefines.h
@@ -0,0 +1,43 @@
+#ifndef OTM_GlobalDefines_H_
+#define OTM_GlobalDefines_H_
+
+//#define MyTypeHash DWORD64
+#define MyTypeHash DWORD32
+
+//define the buffer to 131072 byte, note that the array is in the stack, don't over do this
+#define BUFSIZE 1<<17
+
+typedef struct
+{
+ unsigned int Control;
+ unsigned int Value;
+ MyTypeHash Hash;
+} MsgStruct;
+
+typedef struct
+{
+ HANDLE In;
+ HANDLE Out;
+} PipeStruct;
+
+#define PIPE_OTM2Game L"\\\\.\\pipe\\OTM2Game"
+#define PIPE_Game2OTM L"\\\\.\\pipe\\Game2OTM"
+
+#define CONTROL_ADD_TEXTURE 1
+#define CONTROL_FORCE_RELOAD_TEXTURE 2
+#define CONTROL_REMOVE_TEXTURE 3
+
+
+#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
+
+
+
+
+
+#endif