From 0bc7eebedecb1707005fd33e2e3ef876d73a56b2 Mon Sep 17 00:00:00 2001 From: "code@koerner-de.net" Date: Sun, 15 Jul 2012 18:59:03 +0000 Subject: [PATCH] uMod2 Alpha Version: known bugs: I disabled the remove device function inside the gui, because something in the event handling goes terrible wrong. Implemented a some new features. --- .cproject | 2 +- .gitattributes | 22 +- uMod_DX10/uMod_DX10_dll.cpp | 172 +- uMod_DX10/uMod_DX10_dll.h | 6 +- uMod_DX10/uMod_ID3D10Device.cpp | 573 +++++++ uMod_DX10/uMod_ID3D10Device.h | 251 +++ uMod_DX10/uMod_ID3D10Device1.cpp | 54 + uMod_DX10/uMod_ID3D10Device1.h | 258 +++ uMod_DX10/uMod_ID3D10Texture1D.cpp | 96 ++ uMod_DX10/uMod_ID3D10Texture1D.h | 56 + uMod_DX10/uMod_ID3D10Texture2D.cpp | 96 ++ uMod_DX10/uMod_ID3D10Texture2D.h | 56 + uMod_DX10/uMod_ID3D10Texture3D.cpp | 96 ++ uMod_DX10/uMod_ID3D10Texture3D.h | 56 + uMod_DX10/uMod_IDXGISwapChain.cpp | 161 ++ uMod_DX10/uMod_IDXGISwapChain.h | 80 + uMod_DX10/uMod_TextureClient_DX10.h | 98 ++ uMod_DX9/uMod_DX9_dll.cpp | 17 +- uMod_DX9/uMod_DX9_dll.h | 20 +- uMod_DX9/uMod_IDirect3DCubeTexture9.cpp | 127 +- uMod_DX9/uMod_IDirect3DCubeTexture9.h | 21 +- uMod_DX9/uMod_IDirect3DDevice9.cpp | 62 +- uMod_DX9/uMod_IDirect3DTexture9.cpp | 37 +- uMod_DX9/uMod_IDirect3DTexture9.h | 20 +- uMod_DX9/uMod_IDirect3DVolumeTexture9.cpp | 139 +- uMod_DX9/uMod_IDirect3DVolumeTexture9.h | 20 +- uMod_DX9/uMod_TextureClient_DX9.cpp | 374 +++- uMod_DX9/uMod_TextureClient_DX9.h | 88 +- uMod_DXMain/makefile.gcc | 66 +- uMod_DXMain/makefile.vc | 235 ++- uMod_DXMain/uMod_ArrayHandler.h | 125 +- .../uMod_DX10_dll_DIRECT_INJECTION.def | 5 + uMod_DXMain/uMod_DXMain_dll.cpp | 115 +- uMod_DXMain/uMod_DXMain_dll.h | 56 +- uMod_DXMain/uMod_Defines.h | 15 +- uMod_DXMain/uMod_Main.h | 28 +- uMod_DXMain/uMod_TextureClient.cpp | 13 +- uMod_DXMain/uMod_TextureClient.h | 107 +- uMod_DXMain/uMod_TextureFunction.cpp | 26 +- uMod_DXMain/uMod_TextureFunction.h | 34 +- uMod_DXMain/uMod_TextureServer.cpp | 314 +++- uMod_DXMain/uMod_TextureServer.h | 159 +- uMod_GUI/makefile.gcc | 284 --- uMod_GUI/makefile.vc | 62 +- uMod_GUI/uMod_Client.cpp | 27 +- uMod_GUI/uMod_Event.h | 12 +- uMod_GUI/uMod_File.cpp | 633 +++++-- uMod_GUI/uMod_File.h | 18 +- uMod_GUI/uMod_GUI.cpp | 115 +- uMod_GUI/uMod_GUI.h | 10 +- uMod_GUI/uMod_GameInfo.cpp | 375 ++-- uMod_GUI/uMod_GameInfo.h | 89 +- uMod_GUI/uMod_GamePage.cpp | 1520 ++++++++++++----- uMod_GUI/uMod_GamePage.h | 186 +- uMod_GUI/uMod_Language.cpp | 144 +- uMod_GUI/uMod_Language.h | 35 +- uMod_GUI/uMod_Main.h | 72 +- uMod_GUI/uMod_MiniPanels.cpp | 355 ++++ uMod_GUI/uMod_MiniPanels.h | 174 ++ uMod_GUI/uMod_ModElement.cpp | 18 + uMod_GUI/uMod_ModElement.h | 165 ++ uMod_GUI/uMod_Sender.cpp | 443 +++-- uMod_GUI/uMod_Sender.h | 18 +- uMod_GUI/uMod_Server.cpp | 36 +- uMod_GUI/uMod_Settings.cpp | 41 +- uMod_GUI/uMod_TreeView.cpp | 762 +++++++++ uMod_GUI/uMod_TreeView.h | 136 ++ uMod_GlobalDefines.h | 221 ++- uMod_Utils.h | 61 + 69 files changed, 7975 insertions(+), 2393 deletions(-) create mode 100644 uMod_DX10/uMod_ID3D10Device.cpp create mode 100644 uMod_DX10/uMod_ID3D10Device.h create mode 100644 uMod_DX10/uMod_ID3D10Device1.cpp create mode 100644 uMod_DX10/uMod_ID3D10Device1.h create mode 100644 uMod_DX10/uMod_ID3D10Texture1D.cpp create mode 100644 uMod_DX10/uMod_ID3D10Texture1D.h create mode 100644 uMod_DX10/uMod_ID3D10Texture2D.cpp create mode 100644 uMod_DX10/uMod_ID3D10Texture2D.h create mode 100644 uMod_DX10/uMod_ID3D10Texture3D.cpp create mode 100644 uMod_DX10/uMod_ID3D10Texture3D.h create mode 100644 uMod_DX10/uMod_IDXGISwapChain.cpp create mode 100644 uMod_DX10/uMod_IDXGISwapChain.h create mode 100644 uMod_DX10/uMod_TextureClient_DX10.h create mode 100644 uMod_DXMain/uMod_DX10_dll_DIRECT_INJECTION.def delete mode 100644 uMod_GUI/makefile.gcc create mode 100644 uMod_GUI/uMod_MiniPanels.cpp create mode 100644 uMod_GUI/uMod_MiniPanels.h create mode 100644 uMod_GUI/uMod_ModElement.cpp create mode 100644 uMod_GUI/uMod_ModElement.h create mode 100644 uMod_GUI/uMod_TreeView.cpp create mode 100644 uMod_GUI/uMod_TreeView.h create mode 100644 uMod_Utils.h diff --git a/.cproject b/.cproject index 43ef20e..2832acd 100644 --- a/.cproject +++ b/.cproject @@ -20,7 +20,7 @@ diff --git a/.gitattributes b/.gitattributes index 0192a8d..a0944a5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,6 +5,19 @@ /README.txt -text uMod_DX10/uMod_DX10_dll.cpp -text uMod_DX10/uMod_DX10_dll.h -text +uMod_DX10/uMod_ID3D10Device.cpp -text +uMod_DX10/uMod_ID3D10Device.h -text +uMod_DX10/uMod_ID3D10Device1.cpp -text +uMod_DX10/uMod_ID3D10Device1.h -text +uMod_DX10/uMod_ID3D10Texture1D.cpp -text +uMod_DX10/uMod_ID3D10Texture1D.h -text +uMod_DX10/uMod_ID3D10Texture2D.cpp -text +uMod_DX10/uMod_ID3D10Texture2D.h -text +uMod_DX10/uMod_ID3D10Texture3D.cpp -text +uMod_DX10/uMod_ID3D10Texture3D.h -text +uMod_DX10/uMod_IDXGISwapChain.cpp -text +uMod_DX10/uMod_IDXGISwapChain.h -text +uMod_DX10/uMod_TextureClient_DX10.h -text uMod_DX9/uMod_DX9_dll.cpp -text uMod_DX9/uMod_DX9_dll.h -text uMod_DX9/uMod_IDirect3D9.cpp -text @@ -27,6 +40,7 @@ uMod_DXMain/makefile.gcc -text uMod_DXMain/makefile.vc -text uMod_DXMain/uMod_ArrayHandler.cpp -text uMod_DXMain/uMod_ArrayHandler.h -text +uMod_DXMain/uMod_DX10_dll_DIRECT_INJECTION.def -text uMod_DXMain/uMod_DX10_dll_HOOK_INJECTION.def -text uMod_DXMain/uMod_DX9_dll_DIRECT_INJECTION.def -text uMod_DXMain/uMod_DX9_dll_HOOK_INJECTION.def -text @@ -52,7 +66,6 @@ uMod_GUI/bin/languages/uMod_LanguagePackU_Russian.txt -text uMod_GUI/bin/languages/uMod_LanguagePack_Italian.txt -text uMod_GUI/config.gcc -text uMod_GUI/config.vc -text -uMod_GUI/makefile.gcc -text uMod_GUI/makefile.vc -text uMod_GUI/uMod.ico -text uMod_GUI/uMod.rc -text @@ -75,14 +88,21 @@ uMod_GUI/uMod_GamePage.h -text uMod_GUI/uMod_Language.cpp -text uMod_GUI/uMod_Language.h -text uMod_GUI/uMod_Main.h -text +uMod_GUI/uMod_MiniPanels.cpp -text +uMod_GUI/uMod_MiniPanels.h -text +uMod_GUI/uMod_ModElement.cpp -text +uMod_GUI/uMod_ModElement.h -text uMod_GUI/uMod_Sender.cpp -text uMod_GUI/uMod_Sender.h -text uMod_GUI/uMod_Server.cpp -text uMod_GUI/uMod_Server.h -text uMod_GUI/uMod_Settings.cpp -text uMod_GUI/uMod_Settings.h -text +uMod_GUI/uMod_TreeView.cpp -text +uMod_GUI/uMod_TreeView.h -text uMod_GUI/unzip.cpp -text uMod_GUI/unzip.h -text uMod_GUI/zip.cpp -text uMod_GUI/zip.h -text /uMod_GlobalDefines.h -text +/uMod_Utils.h -text diff --git a/uMod_DX10/uMod_DX10_dll.cpp b/uMod_DX10/uMod_DX10_dll.cpp index 15539b8..d74572e 100644 --- a/uMod_DX10/uMod_DX10_dll.cpp +++ b/uMod_DX10/uMod_DX10_dll.cpp @@ -27,26 +27,10 @@ along with Universal Modding Engine. If not, see #define number_of_byte 5 #include "uMod_DX10_dll.h" +#include "uMod_ID3D10Device.h" +#include "uMod_ID3D10Device1.h" +#include "uMod_IDXGISwapChain.h" -//#include "disasm-lib/cpu.c" -//#include "disasm-lib/disasm.c" -//#include "disasm-lib/disasm_x86.c" - -//#include "disasm-lib/misc.c" -//#include "mhook-lib/mhook.cpp" -//#include "mhook-lib/mhook.h" - -//#include "uMod_ID3D10Device.h" -//#include "uMod_ID3D10Device1.h" -//#include "uMod_IDXGISwapChain.h" - -//#include "detours.h" -//#include "detourxs/detourxs/detourxs.h" - -/* -#include "detourxs/detourxs/ADE32.cpp" -#include "detourxs/detourxs/detourxs.cpp" -*/ /* * global variable which are not linked external */ @@ -56,7 +40,7 @@ HINSTANCE gl_hOriginal_DX101_Dll = NULL; typedef HRESULT (APIENTRY *D3D10CreateDeviceAndSwapChain_type)( IDXGIAdapter*, D3D10_DRIVER_TYPE, HMODULE, UINT, UINT, DXGI_SWAP_CHAIN_DESC*, IDXGISwapChain**, ID3D10Device**); typedef HRESULT (APIENTRY *D3D10CreateDeviceAndSwapChain1_type)( IDXGIAdapter*, D3D10_DRIVER_TYPE, HMODULE, UINT, D3D10_FEATURE_LEVEL1, UINT, DXGI_SWAP_CHAIN_DESC*, IDXGISwapChain**, ID3D10Device1**); -#ifndef NO_INJECTION +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION D3D10CreateDeviceAndSwapChain_type D3D10CreateDeviceAndSwapChain_fn = NULL; D3D10CreateDeviceAndSwapChain1_type D3D10CreateDeviceAndSwapChain1_fn = NULL; #endif @@ -71,39 +55,9 @@ D3D10CreateDeviceAndSwapChain1_type D3D10CreateDeviceAndSwapChain1_fn = NULL; void InitDX10(void) { LoadOriginal_DX10_Dll(); -/* - HRESULT ret = E_OUTOFMEMORY; - //IDXGIAdapter Adap;# - D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain"); +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION - IDXGISwapChain *pIDXGISwapChain_orig = NULL; - ID3D10Device *pID3D10Device_orig = NULL; - if (D3D10CreateDeviceAndSwapChain_fn!=NULL) - { - Message("PRE: create original device\n"); - ret = D3D10CreateDeviceAndSwapChain_fn( NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_SINGLETHREADED, - D3D10_SDK_VERSION, NULL, &pIDXGISwapChain_orig, &pID3D10Device_orig); - if (ret == S_OK ) - { - Message("PRE: created\n"); - pIDXGISwapChain_orig->Release(); - pID3D10Device_orig->Release(); - Message("PRE: released\n"); - } - else - { - Message("PRE: failed\n"); - } - } - else - { - Message("PRE: no function\n"); - } -*/ - - -#ifndef NO_INJECTION // we detour the original D3D10CreateDeviceAndSwapChain to our uMod_D3D10CreateDeviceAndSwapChain if (gl_hOriginal_DX10_Dll!=NULL) { @@ -111,21 +65,12 @@ void InitDX10(void) if (D3D10CreateDeviceAndSwapChain_fn!=NULL) { Message("Detour: D3D10CreateDeviceAndSwapChain\n"); - //D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain, number_of_byte); - - - //Mhook_SetHook((PVOID*)&D3D10CreateDeviceAndSwapChain_fn, uMod_D3D10CreateDeviceAndSwapChain); - D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) DetourFunction( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain); - - //DetourTransactionBegin(); - //Messagebox_orig = (Messagebox_typ)DetourAttach(&(PVOID&)MessageBoxA, (PVOID)MyMessageBox); - //D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) DetourAttach( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain); - //DetourTransactionCommit(); + D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain, number_of_byte); } } if (gl_hOriginal_DX101_Dll!=NULL) { - //D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type) GetProcAddress(gl_hOriginal_DX101_Dll, "D3D10CreateDeviceAndSwapChain1"); + D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type) GetProcAddress(gl_hOriginal_DX101_Dll, "D3D10CreateDeviceAndSwapChain1"); if (D3D10CreateDeviceAndSwapChain1_fn!=NULL) { Message("Detour: D3D10CreateDeviceAndSwapChain1\n"); @@ -175,7 +120,7 @@ void LoadOriginal_DX10_Dll(void) } -#ifdef NO_INJECTION +#if INJECTION_METHOD==NO_INJECTION /* * We do not inject, the game loads this dll by itself thus we must include the Direct3DCreate9 function */ @@ -289,13 +234,16 @@ DWORD WINAPI D3DPERF_GetStatus( void ) } */ -#else +#endif + + +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION /* * We inject the dll into the game, thus we retour the original Direct3DCreate9 function to our MyDirect3DCreate9 function */ -HRESULT uMod_D3D10CreateDeviceAndSwapChain( +HRESULT APIENTRY uMod_D3D10CreateDeviceAndSwapChain( IDXGIAdapter *pAdapter, D3D10_DRIVER_TYPE DriverType, HMODULE Software, @@ -306,53 +254,27 @@ HRESULT uMod_D3D10CreateDeviceAndSwapChain( ID3D10Device **ppDevice ) { - Message("uMod_D3D10CreateDeviceAndSwapChain: bla original %lu, uMod %lu\n", D3D10CreateDeviceAndSwapChain_fn, uMod_D3D10CreateDeviceAndSwapChain); - - // in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines - // but somehow, for me it only works, if I retour the function and calling afterward the original function - - // BEGIN - - //LoadOriginal_DX10_Dll(); - - //RetourFunc((BYTE*) GetProcAddress( gl_hOriginal_DX9_Dll, "Direct3DCreate9"), (BYTE*)Direct3DCreate9_fn, 5); - //Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginal_DX9_Dll, "Direct3DCreate9"); - RetourFunc((BYTE*) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain"), (BYTE*)D3D10CreateDeviceAndSwapChain_fn, number_of_byte); D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain"); - // END - //DetourRemove( (BYTE*) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain"), (BYTE*)D3D10CreateDeviceAndSwapChain_fn); - //D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain"); - - HRESULT ret = E_OUTOFMEMORY; - IDXGISwapChain *pIDXGISwapChain_orig = NULL; - ID3D10Device *pID3D10Device_orig = NULL; - if (D3D10CreateDeviceAndSwapChain_fn) + HRESULT ret = D3D10CreateDeviceAndSwapChain_fn(pAdapter,DriverType,Software,Flags,SDKVersion,pSwapChainDesc, ppSwapChain, ppDevice); + if (ret==S_OK) { - Message("create original device\n"); - ret = D3D10CreateDeviceAndSwapChain_fn(pAdapter,DriverType,Software,Flags,SDKVersion,pSwapChainDesc, &pIDXGISwapChain_orig, &pID3D10Device_orig); + uMod_ID3D10Device *dev = new uMod_ID3D10Device( *ppDevice, gl_TextureServer); + *ppDevice = (ID3D10Device*) dev; + + if (ppSwapChain!=NULL) + { + uMod_IDXGISwapChain *swap = new uMod_IDXGISwapChain( *ppSwapChain, dev); + *ppSwapChain = swap; + } } - /* - uMod_IDirect3D9 *pIDirect3D9; - if (pIDirect3D9_orig) - { - pIDirect3D9 = new uMod_IDirect3D9( pIDirect3D9_orig, gl_TextureServer); //creating our uMod_IDirect3D9 object - } - */ - - // we detour again - Message("detour again\n"); - //D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain, number_of_byte); - - - //*ppSwapChain = pIDXGISwapChain_orig; - //*ppDevice = pID3D10Device_orig; - Message("Fine\n"); - return (ret); + else Message("D3D10CreateDeviceAndSwapChain: Failed\n"); + D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain, number_of_byte); + return ret; } -HRESULT uMod_D3D10CreateDeviceAndSwapChain1( +HRESULT APIENTRY uMod_D3D10CreateDeviceAndSwapChain1( IDXGIAdapter *pAdapter, D3D10_DRIVER_TYPE DriverType, HMODULE Software, @@ -364,41 +286,25 @@ HRESULT uMod_D3D10CreateDeviceAndSwapChain1( ID3D10Device1 **ppDevice ) { - Message("uMod_D3D10CreateDeviceAndSwapChain1: original %lu, uMod %lu\n", D3D10CreateDeviceAndSwapChain1_fn, uMod_D3D10CreateDeviceAndSwapChain1); - - // in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines - // but somehow, for me it only works, if I retour the function and calling afterward the original function - - // BEGIN - - //LoadOriginal_DX10_Dll(); - RetourFunc((BYTE*) GetProcAddress( gl_hOriginal_DX101_Dll, "D3D10CreateDeviceAndSwapChain1"), (BYTE*)D3D10CreateDeviceAndSwapChain1_fn, 5); D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type) GetProcAddress( gl_hOriginal_DX101_Dll, "D3D10CreateDeviceAndSwapChain1"); - // END - HRESULT ret = E_OUTOFMEMORY; - IDXGISwapChain *pIDXGISwapChain_orig = NULL; - ID3D10Device1 *pID3D10Device1_orig = NULL; - if (D3D10CreateDeviceAndSwapChain1_fn) + HRESULT ret = D3D10CreateDeviceAndSwapChain1_fn(pAdapter,DriverType,Software,Flags,HardwareLevel,SDKVersion,pSwapChainDesc, ppSwapChain, ppDevice); + if (ret==S_OK) { - ret = D3D10CreateDeviceAndSwapChain1_fn(pAdapter,DriverType,Software,Flags,HardwareLevel,SDKVersion,pSwapChainDesc, &pIDXGISwapChain_orig, &pID3D10Device1_orig); - } - /* - uMod_IDirect3D9 *pIDirect3D9; - if (pIDirect3D9_orig) - { - pIDirect3D9 = new uMod_IDirect3D9( pIDirect3D9_orig, gl_TextureServer); //creating our uMod_IDirect3D9 object - } - */ + uMod_ID3D10Device1 *dev = new uMod_ID3D10Device1( *ppDevice, gl_TextureServer); + *ppDevice = (ID3D10Device1*) dev; + + if (ppSwapChain!=NULL) + { + uMod_IDXGISwapChain *swap = new uMod_IDXGISwapChain( *ppSwapChain, (uMod_ID3D10Device*)dev); + *ppSwapChain = swap; + } + } + else Message("D3D10CreateDeviceAndSwapChain1: Failed\n"); - // we detour again D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain1_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain1, 5); - //D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain1_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain1, 5); - - *ppSwapChain = pIDXGISwapChain_orig; - *ppDevice = pID3D10Device1_orig; return (ret); } diff --git a/uMod_DX10/uMod_DX10_dll.h b/uMod_DX10/uMod_DX10_dll.h index c217ecf..14201cc 100644 --- a/uMod_DX10/uMod_DX10_dll.h +++ b/uMod_DX10/uMod_DX10_dll.h @@ -27,9 +27,9 @@ void LoadOriginal_DX10_Dll(void); void InitDX10(); void ExitDX10(); -#ifndef NO_INJECTION +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION -HRESULT uMod_D3D10CreateDeviceAndSwapChain( +HRESULT APIENTRY uMod_D3D10CreateDeviceAndSwapChain( IDXGIAdapter *pAdapter, D3D10_DRIVER_TYPE DriverType, HMODULE Software, @@ -40,7 +40,7 @@ HRESULT uMod_D3D10CreateDeviceAndSwapChain( ID3D10Device **ppDevice ); -HRESULT uMod_D3D10CreateDeviceAndSwapChain1( +HRESULT APIENTRY uMod_D3D10CreateDeviceAndSwapChain1( IDXGIAdapter *pAdapter, D3D10_DRIVER_TYPE DriverType, HMODULE Software, diff --git a/uMod_DX10/uMod_ID3D10Device.cpp b/uMod_DX10/uMod_ID3D10Device.cpp new file mode 100644 index 0000000..b0612ef --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Device.cpp @@ -0,0 +1,573 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine.If not, see . +*/ + +#include "../uMod_DXMain/uMod_Main.h" +#include "uMod_ID3D10Device.h" + +#ifndef PRE_MESSAGE +#define PRE_MESSAGE "uMod_ID3D10Device" +#endif + + +uMod_ID3D10Device::uMod_ID3D10Device( ID3D10Device* pOriginal, uMod_TextureServer* server) +{ + Message( PRE_MESSAGE "::" PRE_MESSAGE "( %lu, %lu): %lu\n", pOriginal, server, this); + m_ID3D10Device = pOriginal; + uMod_Server = server; + RefCounter = 1; +} + +uMod_ID3D10Device::~uMod_ID3D10Device() +{ + Message( PRE_MESSAGE "::~" PRE_MESSAGE "(): %lu\n", this); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::QueryInterface( REFIID riid, void** ppvObject) +{ + *ppvObject = NULL; + Message( PRE_MESSAGE "::QueryInterface(): %lu\n", this); + HRESULT hRes = m_ID3D10Device->QueryInterface(riid, ppvObject); + + if (ppvObject!=NULL) + {if (*ppvObject == m_ID3D10Device)// && (riid==IID_ID3D10Device || riid==IID_ID3D10Device1)) + { + RefCounter++; //increasing our counter + //*ppvObject = this; + Message("hit: %lu, %lu, %lu, %lu %lu\n", riid, IID_ID3D10Device, IID_ID3D10Device1, *ppvObject, this) + }} + + return (hRes); +} + +ULONG STDMETHODCALLTYPE uMod_ID3D10Device::AddRef(void) +{ + Message( PRE_MESSAGE "::AddRef(): %lu\n", this); + RefCounter++; + return m_ID3D10Device->AddRef(); +} + +ULONG STDMETHODCALLTYPE uMod_ID3D10Device::Release( void) +{ + Message( PRE_MESSAGE "::Release(): (%d) %lu\n", RefCounter, this); + if (--RefCounter==0) //if our counter drops to zero, the real device will be deleted, so we clean up before + { + // we must not release the fake textures, cause they are released if the target textures are released + // and the target textures are released by the game. + } + + // call original routine + ULONG count = m_ID3D10Device->Release(); + + // in case no further Ref is there, the Original Object has deleted itself + if (count == 0) + { + delete(this); + } + + return(count); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::VSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers) +{ + return m_ID3D10Device->VSSetConstantBuffers( StartSlot, NumBuffers, ppConstantBuffers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::PSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews) +{ + return m_ID3D10Device->PSSetShaderResources( StartSlot, NumViews, ppShaderResourceViews); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::PSSetShader( ID3D10PixelShader *pPixelShader) +{ + return m_ID3D10Device->PSSetShader( pPixelShader); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::PSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers) +{ + return m_ID3D10Device->PSSetSamplers( StartSlot, NumSamplers, ppSamplers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::VSSetShader( ID3D10VertexShader *pVertexShader) +{ + return m_ID3D10Device->VSSetShader( pVertexShader); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::DrawIndexed( UINT IndexCount,UINT StartIndexLocation, INT BaseVertexLocation) +{ + return m_ID3D10Device->DrawIndexed( IndexCount, StartIndexLocation, BaseVertexLocation); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::Draw( UINT VertexCount, UINT StartVertexLocation) +{ + return m_ID3D10Device->Draw( VertexCount, StartVertexLocation); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::PSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers) +{ + return m_ID3D10Device->PSSetConstantBuffers( StartSlot, NumBuffers, ppConstantBuffers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::IASetInputLayout( ID3D10InputLayout *pInputLayout) +{ + return m_ID3D10Device->IASetInputLayout( pInputLayout); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::IASetVertexBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppVertexBuffers, const UINT *pStrides, const UINT *pOffsets) +{ + return m_ID3D10Device->IASetVertexBuffers( StartSlot, NumBuffers, ppVertexBuffers, pStrides, pOffsets); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::IASetIndexBuffer( ID3D10Buffer *pIndexBuffer, DXGI_FORMAT Format, UINT Offset) +{ + return m_ID3D10Device->IASetIndexBuffer( pIndexBuffer, Format, Offset); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::DrawIndexedInstanced(UINT IndexCountPerInstance, UINT InstanceCount, UINT StartIndexLocation, INT BaseVertexLocation, UINT StartInstanceLocation) +{ + return m_ID3D10Device->DrawIndexedInstanced( IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::DrawInstanced( UINT VertexCountPerInstance, UINT InstanceCount, UINT StartVertexLocation, UINT StartInstanceLocation) +{ + return m_ID3D10Device->DrawInstanced( VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers) +{ + return m_ID3D10Device->GSSetConstantBuffers( StartSlot, NumBuffers, ppConstantBuffers); +} +void STDMETHODCALLTYPE uMod_ID3D10Device::GSSetShader( ID3D10GeometryShader *pShader) +{ + return m_ID3D10Device->GSSetShader( pShader); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY Topology) +{ + return m_ID3D10Device->IASetPrimitiveTopology( Topology); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::VSSetShaderResources(UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews) +{ + return m_ID3D10Device->VSSetShaderResources( StartSlot, NumViews, ppShaderResourceViews); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::VSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers) +{ + return m_ID3D10Device->VSSetSamplers( StartSlot, NumSamplers, ppSamplers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::SetPredication( ID3D10Predicate *pPredicate, BOOL PredicateValue) +{ + return m_ID3D10Device->SetPredication( pPredicate, PredicateValue); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews) +{ + return m_ID3D10Device->GSSetShaderResources( StartSlot, NumViews, ppShaderResourceViews); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GSSetSamplers(UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers) +{ + return m_ID3D10Device->GSSetSamplers( StartSlot, NumSamplers, ppSamplers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::OMSetRenderTargets( UINT NumViews, ID3D10RenderTargetView *const *ppRenderTargetViews, ID3D10DepthStencilView *pDepthStencilView) +{ + return m_ID3D10Device->OMSetRenderTargets( NumViews, ppRenderTargetViews, pDepthStencilView); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::OMSetBlendState( ID3D10BlendState *pBlendState, const FLOAT BlendFactor[ 4 ], UINT SampleMask) +{ + return m_ID3D10Device->OMSetBlendState( pBlendState, BlendFactor, SampleMask); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::OMSetDepthStencilState( ID3D10DepthStencilState *pDepthStencilState, UINT StencilRef) +{ + return m_ID3D10Device->OMSetDepthStencilState( pDepthStencilState, StencilRef); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::SOSetTargets(UINT NumBuffers, ID3D10Buffer *const *ppSOTargets, const UINT *pOffsets) +{ + return m_ID3D10Device->SOSetTargets( NumBuffers, ppSOTargets, pOffsets); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::DrawAuto(void) +{ + return m_ID3D10Device->DrawAuto(); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::RSSetState( ID3D10RasterizerState *pRasterizerState) +{ + return m_ID3D10Device->RSSetState( pRasterizerState); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::RSSetViewports( UINT NumViewports, const D3D10_VIEWPORT *pViewports) +{ + return m_ID3D10Device->RSSetViewports( NumViewports, pViewports); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::RSSetScissorRects( UINT NumRects, const D3D10_RECT *pRects) +{ + return m_ID3D10Device->RSSetScissorRects( NumRects, pRects); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::CopySubresourceRegion( ID3D10Resource *pDstResource, UINT DstSubresource, UINT DstX, UINT DstY, UINT DstZ, ID3D10Resource *pSrcResource, UINT SrcSubresource, const D3D10_BOX *pSrcBox) +{ + return m_ID3D10Device->CopySubresourceRegion( pDstResource, DstSubresource, DstX, DstY, DstZ, pSrcResource, SrcSubresource, pSrcBox); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::CopyResource( ID3D10Resource *pDstResource, ID3D10Resource *pSrcResource) +{ + return m_ID3D10Device->CopyResource( pDstResource, pSrcResource); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::UpdateSubresource( ID3D10Resource *pDstResource, UINT DstSubresource, const D3D10_BOX *pDstBox, const void *pSrcData, UINT SrcRowPitch, UINT SrcDepthPitch) +{ + return m_ID3D10Device->UpdateSubresource( pDstResource, DstSubresource, pDstBox, pSrcData, SrcRowPitch, SrcDepthPitch); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::ClearRenderTargetView( ID3D10RenderTargetView *pRenderTargetView, const FLOAT ColorRGBA[ 4 ]) +{ + return m_ID3D10Device->ClearRenderTargetView( pRenderTargetView, ColorRGBA); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::ClearDepthStencilView( ID3D10DepthStencilView *pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil) +{ + return m_ID3D10Device->ClearDepthStencilView( pDepthStencilView, ClearFlags, Depth, Stencil); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GenerateMips( ID3D10ShaderResourceView *pShaderResourceView) +{ + return m_ID3D10Device->GenerateMips( pShaderResourceView); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::ResolveSubresource( ID3D10Resource *pDstResource, UINT DstSubresource, ID3D10Resource *pSrcResource, UINT SrcSubresource, DXGI_FORMAT Format) +{ + return m_ID3D10Device->ResolveSubresource( pDstResource, DstSubresource, pSrcResource, SrcSubresource, Format); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::VSGetConstantBuffers( UINT StartSlot,UINT NumBuffers, ID3D10Buffer **ppConstantBuffers) +{ + return m_ID3D10Device->VSGetConstantBuffers( StartSlot, NumBuffers, ppConstantBuffers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::PSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews) +{ + return m_ID3D10Device->PSGetShaderResources( StartSlot, NumViews, ppShaderResourceViews); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::PSGetShader( ID3D10PixelShader **ppPixelShader) +{ + return m_ID3D10Device->PSGetShader( ppPixelShader); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::PSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers) +{ + return m_ID3D10Device->PSGetSamplers( StartSlot, NumSamplers, ppSamplers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::VSGetShader( ID3D10VertexShader **ppVertexShader) +{ + return m_ID3D10Device->VSGetShader( ppVertexShader); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::PSGetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppConstantBuffers) +{ + return m_ID3D10Device->PSGetConstantBuffers( StartSlot, NumBuffers, ppConstantBuffers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::IAGetInputLayout( ID3D10InputLayout **ppInputLayout) +{ + return m_ID3D10Device->IAGetInputLayout( ppInputLayout); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::IAGetVertexBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppVertexBuffers, UINT *pStrides, UINT *pOffsets) +{ + return m_ID3D10Device->IAGetVertexBuffers( StartSlot, NumBuffers, ppVertexBuffers, pStrides, pOffsets); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::IAGetIndexBuffer( ID3D10Buffer **pIndexBuffer, DXGI_FORMAT *Format, UINT *Offset) +{ + return m_ID3D10Device->IAGetIndexBuffer( pIndexBuffer, Format, Offset); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GSGetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppConstantBuffers) +{ + return m_ID3D10Device->GSGetConstantBuffers( StartSlot, NumBuffers, ppConstantBuffers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GSGetShader( ID3D10GeometryShader **ppGeometryShader) +{ + return m_ID3D10Device->GSGetShader( ppGeometryShader); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::IAGetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY *pTopology) +{ + return m_ID3D10Device->IAGetPrimitiveTopology( pTopology); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::VSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews) +{ + return m_ID3D10Device->VSGetShaderResources( StartSlot, NumViews, ppShaderResourceViews); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::VSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers) +{ + return m_ID3D10Device->VSGetSamplers( StartSlot, NumSamplers, ppSamplers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GetPredication( ID3D10Predicate **ppPredicate, BOOL *pPredicateValue) +{ + return m_ID3D10Device->GetPredication( ppPredicate, pPredicateValue); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews) +{ + return m_ID3D10Device->GSGetShaderResources( StartSlot, NumViews, ppShaderResourceViews); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers) +{ + return m_ID3D10Device->GSGetSamplers( StartSlot, NumSamplers, ppSamplers); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::OMGetRenderTargets( UINT NumViews, ID3D10RenderTargetView **ppRenderTargetViews, ID3D10DepthStencilView **ppDepthStencilView) +{ + return m_ID3D10Device->OMGetRenderTargets( NumViews, ppRenderTargetViews, ppDepthStencilView); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::OMGetBlendState( ID3D10BlendState **ppBlendState, FLOAT BlendFactor[ 4 ], UINT *pSampleMask) +{ + return m_ID3D10Device->OMGetBlendState( ppBlendState, BlendFactor, pSampleMask); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::OMGetDepthStencilState( ID3D10DepthStencilState **ppDepthStencilState, UINT *pStencilRef) +{ + return m_ID3D10Device->OMGetDepthStencilState( ppDepthStencilState, pStencilRef); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::SOGetTargets( UINT NumBuffers, ID3D10Buffer **ppSOTargets, UINT *pOffsets) +{ + return m_ID3D10Device->SOGetTargets( NumBuffers, ppSOTargets, pOffsets); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::RSGetState( ID3D10RasterizerState **ppRasterizerState) +{ + return m_ID3D10Device->RSGetState( ppRasterizerState); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::RSGetViewports( UINT *NumViewports, D3D10_VIEWPORT *pViewports) +{ + return m_ID3D10Device->RSGetViewports( NumViewports, pViewports); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::RSGetScissorRects( UINT *NumRects, D3D10_RECT *pRects) +{ + return m_ID3D10Device->RSGetScissorRects( NumRects, pRects); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::GetDeviceRemovedReason(void) +{ + return m_ID3D10Device->GetDeviceRemovedReason(); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::SetExceptionMode( UINT RaiseFlags) +{ + return m_ID3D10Device->SetExceptionMode( RaiseFlags); +} + +UINT STDMETHODCALLTYPE uMod_ID3D10Device::GetExceptionMode(void) +{ + return m_ID3D10Device->GetExceptionMode(); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::GetPrivateData( REFGUID guid, UINT *pDataSize, void *pData) +{ + return m_ID3D10Device->GetPrivateData( guid, pDataSize, pData); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::SetPrivateData( REFGUID guid, UINT DataSize, const void *pData) +{ + return m_ID3D10Device->SetPrivateData( guid, DataSize, pData); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::SetPrivateDataInterface( REFGUID guid, const IUnknown *pData) +{ + return m_ID3D10Device->SetPrivateDataInterface( guid, pData); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::ClearState( void) +{ + return m_ID3D10Device->ClearState(); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::Flush( void) +{ + return m_ID3D10Device->Flush(); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateBuffer( const D3D10_BUFFER_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Buffer **ppBuffer) +{ + return m_ID3D10Device->CreateBuffer( pDesc, pInitialData, ppBuffer); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateTexture1D( const D3D10_TEXTURE1D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture1D **ppTexture1D) +{ + HRESULT hRes = m_ID3D10Device->CreateTexture1D( pDesc, pInitialData, ppTexture1D); + if( SUCCEEDED( hRes ) ) + { + *ppTexture1D = new uMod_ID3D10Texture1D( *ppTexture1D); + } + return hRes; +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateTexture2D( const D3D10_TEXTURE2D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture2D **ppTexture2D) +{ + HRESULT hRes = m_ID3D10Device->CreateTexture2D( pDesc, pInitialData, ppTexture2D); + if( SUCCEEDED( hRes ) ) + { + *ppTexture2D = new uMod_ID3D10Texture2D( *ppTexture2D); + } + return hRes; +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateTexture3D( const D3D10_TEXTURE3D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture3D **ppTexture3D) +{ + HRESULT hRes = m_ID3D10Device->CreateTexture3D( pDesc, pInitialData, ppTexture3D); + if( SUCCEEDED( hRes ) ) + { + *ppTexture3D = new uMod_ID3D10Texture3D( *ppTexture3D); + } + return hRes; +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateShaderResourceView( ID3D10Resource *pResource, const D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc, ID3D10ShaderResourceView **ppSRView) +{ + return m_ID3D10Device->CreateShaderResourceView( pResource, pDesc, ppSRView); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateRenderTargetView( ID3D10Resource *pResource, const D3D10_RENDER_TARGET_VIEW_DESC *pDesc, ID3D10RenderTargetView **ppRTView) +{ + return m_ID3D10Device->CreateRenderTargetView( pResource, pDesc, ppRTView); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateDepthStencilView( ID3D10Resource *pResource, const D3D10_DEPTH_STENCIL_VIEW_DESC *pDesc, ID3D10DepthStencilView **ppDepthStencilView) +{ + return m_ID3D10Device->CreateDepthStencilView( pResource, pDesc, ppDepthStencilView); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateInputLayout( const D3D10_INPUT_ELEMENT_DESC *pInputElementDescs, UINT NumElements, const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, ID3D10InputLayout **ppInputLayout) +{ + return m_ID3D10Device->CreateInputLayout( pInputElementDescs, NumElements, pShaderBytecodeWithInputSignature, BytecodeLength, ppInputLayout); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateVertexShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10VertexShader **ppVertexShader) +{ + return m_ID3D10Device->CreateVertexShader( pShaderBytecode, BytecodeLength, ppVertexShader); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateGeometryShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10GeometryShader **ppGeometryShader) +{ + return m_ID3D10Device->CreateGeometryShader( pShaderBytecode, BytecodeLength, ppGeometryShader); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateGeometryShaderWithStreamOutput( const void *pShaderBytecode, SIZE_T BytecodeLength, const D3D10_SO_DECLARATION_ENTRY *pSODeclaration, UINT NumEntries, UINT OutputStreamStride, ID3D10GeometryShader **ppGeometryShader) +{ + return m_ID3D10Device->CreateGeometryShaderWithStreamOutput( pShaderBytecode, BytecodeLength, pSODeclaration, NumEntries, OutputStreamStride, ppGeometryShader); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreatePixelShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10PixelShader **ppPixelShader) +{ + return m_ID3D10Device->CreatePixelShader( pShaderBytecode, BytecodeLength, ppPixelShader); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateBlendState( const D3D10_BLEND_DESC *pBlendStateDesc, ID3D10BlendState **ppBlendState) +{ + return m_ID3D10Device->CreateBlendState( pBlendStateDesc, ppBlendState); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateDepthStencilState( const D3D10_DEPTH_STENCIL_DESC *pDepthStencilDesc, ID3D10DepthStencilState **ppDepthStencilState) +{ + return m_ID3D10Device->CreateDepthStencilState( pDepthStencilDesc, ppDepthStencilState); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateRasterizerState( const D3D10_RASTERIZER_DESC *pRasterizerDesc, ID3D10RasterizerState **ppRasterizerState) +{ + return m_ID3D10Device->CreateRasterizerState( pRasterizerDesc, ppRasterizerState); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateSamplerState( const D3D10_SAMPLER_DESC *pSamplerDesc, ID3D10SamplerState **ppSamplerState) +{ + return m_ID3D10Device->CreateSamplerState( pSamplerDesc, ppSamplerState); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateQuery( const D3D10_QUERY_DESC *pQueryDesc, ID3D10Query **ppQuery) +{ + return m_ID3D10Device->CreateQuery( pQueryDesc, ppQuery); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreatePredicate( const D3D10_QUERY_DESC *pPredicateDesc, ID3D10Predicate **ppPredicate) +{ + return m_ID3D10Device->CreatePredicate( pPredicateDesc, ppPredicate); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CreateCounter( const D3D10_COUNTER_DESC *pCounterDesc, ID3D10Counter **ppCounter) +{ + return m_ID3D10Device->CreateCounter( pCounterDesc, ppCounter); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CheckFormatSupport( DXGI_FORMAT Format, UINT *pFormatSupport) +{ + return m_ID3D10Device->CheckFormatSupport( Format, pFormatSupport); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CheckMultisampleQualityLevels( DXGI_FORMAT Format, UINT SampleCount, UINT *pNumQualityLevels) +{ + return m_ID3D10Device->CheckMultisampleQualityLevels( Format, SampleCount, pNumQualityLevels); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::CheckCounterInfo( D3D10_COUNTER_INFO *pCounterInfo) +{ + return m_ID3D10Device->CheckCounterInfo( pCounterInfo); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::CheckCounter( const D3D10_COUNTER_DESC *pDesc, D3D10_COUNTER_TYPE *pType, UINT *pActiveCounters, LPSTR szName, UINT *pNameLength, LPSTR szUnits, UINT *pUnitsLength, LPSTR szDescription, UINT *pDescriptionLength) +{ + return m_ID3D10Device->CheckCounter( pDesc, pType, pActiveCounters, szName, pNameLength, szUnits, pUnitsLength, szDescription, pDescriptionLength); +} + +UINT STDMETHODCALLTYPE uMod_ID3D10Device::GetCreationFlags( void) +{ + return m_ID3D10Device->GetCreationFlags(); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device::OpenSharedResource( HANDLE hResource, REFIID ReturnedInterface, void **ppResource) +{ + return m_ID3D10Device->OpenSharedResource( hResource, ReturnedInterface, ppResource); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::SetTextFilterSize( UINT Width, UINT Height) +{ + return m_ID3D10Device->SetTextFilterSize( Width, Height); +} + +void STDMETHODCALLTYPE uMod_ID3D10Device::GetTextFilterSize( UINT *pWidth, UINT *pHeight) +{ + return m_ID3D10Device->GetTextFilterSize( pWidth, pHeight); +} + diff --git a/uMod_DX10/uMod_ID3D10Device.h b/uMod_DX10/uMod_ID3D10Device.h new file mode 100644 index 0000000..4a92a27 --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Device.h @@ -0,0 +1,251 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + +#ifdef __CDT_PARSER__ +#undef UMOD_ID3D10DEVICE_H_ +#endif + +#ifndef UMOD_ID3D10DEVICE_H_ +#define UMOD_ID3D10DEVICE_H_ + + +#include +#include +#include +#include +#include "..\uMod_DXMain\uMod_TextureServer.h" +#include "uMod_TextureClient_DX10.h" +#include "uMod_ID3D10Texture1D.h" +#include "uMod_ID3D10Texture2D.h" +#include "uMod_ID3D10Texture3D.h" + + + + +class uMod_ID3D10Device : public ID3D10Device +{ +public: + uMod_ID3D10Device(ID3D10Device* pOriginal, uMod_TextureServer* server); + virtual ~uMod_ID3D10Device(); + + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject); + ULONG STDMETHODCALLTYPE AddRef(void); + ULONG STDMETHODCALLTYPE Release( void); + + void STDMETHODCALLTYPE VSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers); + + void STDMETHODCALLTYPE PSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews); + + void STDMETHODCALLTYPE PSSetShader( ID3D10PixelShader *pPixelShader); + + void STDMETHODCALLTYPE PSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers); + + void STDMETHODCALLTYPE VSSetShader( ID3D10VertexShader *pVertexShader); + + void STDMETHODCALLTYPE DrawIndexed( UINT IndexCount, UINT StartIndexLocation, INT BaseVertexLocation); + + void STDMETHODCALLTYPE Draw( UINT VertexCount, UINT StartVertexLocation); + + void STDMETHODCALLTYPE PSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers); + + void STDMETHODCALLTYPE IASetInputLayout( ID3D10InputLayout *pInputLayout); + + void STDMETHODCALLTYPE IASetVertexBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppVertexBuffers, const UINT *pStrides, const UINT *pOffsets); + + void STDMETHODCALLTYPE IASetIndexBuffer( ID3D10Buffer *pIndexBuffer, DXGI_FORMAT Format, UINT Offset); + + void STDMETHODCALLTYPE DrawIndexedInstanced( UINT IndexCountPerInstance, UINT InstanceCount, UINT StartIndexLocation, INT BaseVertexLocation, UINT StartInstanceLocation); + + void STDMETHODCALLTYPE DrawInstanced( UINT VertexCountPerInstance, UINT InstanceCount, UINT StartVertexLocation, UINT StartInstanceLocation); + + void STDMETHODCALLTYPE GSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers); + + void STDMETHODCALLTYPE GSSetShader( ID3D10GeometryShader *pShader); + + void STDMETHODCALLTYPE IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY Topology); + + void STDMETHODCALLTYPE VSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews); + + void STDMETHODCALLTYPE VSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers); + + void STDMETHODCALLTYPE SetPredication( ID3D10Predicate *pPredicate, BOOL PredicateValue); + + void STDMETHODCALLTYPE GSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews); + + void STDMETHODCALLTYPE GSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers); + + void STDMETHODCALLTYPE OMSetRenderTargets( UINT NumViews, ID3D10RenderTargetView *const *ppRenderTargetViews, ID3D10DepthStencilView *pDepthStencilView); + + void STDMETHODCALLTYPE OMSetBlendState( ID3D10BlendState *pBlendState, const FLOAT BlendFactor[ 4 ], UINT SampleMask); + + void STDMETHODCALLTYPE OMSetDepthStencilState( ID3D10DepthStencilState *pDepthStencilState, UINT StencilRef); + + void STDMETHODCALLTYPE SOSetTargets( UINT NumBuffers, ID3D10Buffer *const *ppSOTargets, const UINT *pOffsets); + + void STDMETHODCALLTYPE DrawAuto(void); + + void STDMETHODCALLTYPE RSSetState( ID3D10RasterizerState *pRasterizerState); + + void STDMETHODCALLTYPE RSSetViewports( UINT NumViewports, const D3D10_VIEWPORT *pViewports); + + void STDMETHODCALLTYPE RSSetScissorRects( UINT NumRects, const D3D10_RECT *pRects); + + void STDMETHODCALLTYPE CopySubresourceRegion( ID3D10Resource *pDstResource, UINT DstSubresource, UINT DstX, UINT DstY, UINT DstZ, ID3D10Resource *pSrcResource, UINT SrcSubresource, const D3D10_BOX *pSrcBox); + + void STDMETHODCALLTYPE CopyResource( ID3D10Resource *pDstResource, ID3D10Resource *pSrcResource); + + void STDMETHODCALLTYPE UpdateSubresource( ID3D10Resource *pDstResource, UINT DstSubresource, const D3D10_BOX *pDstBox, const void *pSrcData, UINT SrcRowPitch, UINT SrcDepthPitch); + + void STDMETHODCALLTYPE ClearRenderTargetView( ID3D10RenderTargetView *pRenderTargetView, const FLOAT ColorRGBA[ 4 ]); + + void STDMETHODCALLTYPE ClearDepthStencilView( ID3D10DepthStencilView *pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil); + + void STDMETHODCALLTYPE GenerateMips( ID3D10ShaderResourceView *pShaderResourceView); + + void STDMETHODCALLTYPE ResolveSubresource( ID3D10Resource *pDstResource, UINT DstSubresource, ID3D10Resource *pSrcResource, UINT SrcSubresource, DXGI_FORMAT Format); + + void STDMETHODCALLTYPE VSGetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppConstantBuffers); + + void STDMETHODCALLTYPE PSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews); + + void STDMETHODCALLTYPE PSGetShader( ID3D10PixelShader **ppPixelShader); + + void STDMETHODCALLTYPE PSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers); + + void STDMETHODCALLTYPE VSGetShader( ID3D10VertexShader **ppVertexShader); + + void STDMETHODCALLTYPE PSGetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppConstantBuffers); + + void STDMETHODCALLTYPE IAGetInputLayout( ID3D10InputLayout **ppInputLayout); + + void STDMETHODCALLTYPE IAGetVertexBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppVertexBuffers, UINT *pStrides, UINT *pOffsets); + + void STDMETHODCALLTYPE IAGetIndexBuffer( ID3D10Buffer **pIndexBuffer, DXGI_FORMAT *Format, UINT *Offset); + + void STDMETHODCALLTYPE GSGetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppConstantBuffers); + + void STDMETHODCALLTYPE GSGetShader( ID3D10GeometryShader **ppGeometryShader); + + void STDMETHODCALLTYPE IAGetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY *pTopology); + + void STDMETHODCALLTYPE VSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews); + + void STDMETHODCALLTYPE VSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers); + + void STDMETHODCALLTYPE GetPredication( ID3D10Predicate **ppPredicate, BOOL *pPredicateValue); + + void STDMETHODCALLTYPE GSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews); + + void STDMETHODCALLTYPE GSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers); + + void STDMETHODCALLTYPE OMGetRenderTargets( UINT NumViews, ID3D10RenderTargetView **ppRenderTargetViews, ID3D10DepthStencilView **ppDepthStencilView); + + void STDMETHODCALLTYPE OMGetBlendState( ID3D10BlendState **ppBlendState, FLOAT BlendFactor[ 4 ], UINT *pSampleMask); + + void STDMETHODCALLTYPE OMGetDepthStencilState( ID3D10DepthStencilState **ppDepthStencilState, UINT *pStencilRef); + + void STDMETHODCALLTYPE SOGetTargets( UINT NumBuffers, ID3D10Buffer **ppSOTargets, UINT *pOffsets); + + void STDMETHODCALLTYPE RSGetState( ID3D10RasterizerState **ppRasterizerState); + + void STDMETHODCALLTYPE RSGetViewports( UINT *NumViewports, D3D10_VIEWPORT *pViewports); + + void STDMETHODCALLTYPE RSGetScissorRects( UINT *NumRects, D3D10_RECT *pRects); + + HRESULT STDMETHODCALLTYPE GetDeviceRemovedReason(void); + + HRESULT STDMETHODCALLTYPE SetExceptionMode( UINT RaiseFlags); + + UINT STDMETHODCALLTYPE GetExceptionMode(void); + + HRESULT STDMETHODCALLTYPE GetPrivateData( REFGUID guid,UINT *pDataSize, void *pData); + + HRESULT STDMETHODCALLTYPE SetPrivateData( REFGUID guid, UINT DataSize, const void *pData); + + HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( REFGUID guid, const IUnknown *pData); + + void STDMETHODCALLTYPE ClearState( void); + + void STDMETHODCALLTYPE Flush( void); + + HRESULT STDMETHODCALLTYPE CreateBuffer( const D3D10_BUFFER_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Buffer **ppBuffer); + + HRESULT STDMETHODCALLTYPE CreateTexture1D( const D3D10_TEXTURE1D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture1D **ppTexture1D); + + HRESULT STDMETHODCALLTYPE CreateTexture2D( const D3D10_TEXTURE2D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture2D **ppTexture2D); + + HRESULT STDMETHODCALLTYPE CreateTexture3D( const D3D10_TEXTURE3D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture3D **ppTexture3D); + + HRESULT STDMETHODCALLTYPE CreateShaderResourceView( ID3D10Resource *pResource, const D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc, ID3D10ShaderResourceView **ppSRView); + + HRESULT STDMETHODCALLTYPE CreateRenderTargetView( ID3D10Resource *pResource, const D3D10_RENDER_TARGET_VIEW_DESC *pDesc, ID3D10RenderTargetView **ppRTView); + + HRESULT STDMETHODCALLTYPE CreateDepthStencilView( ID3D10Resource *pResource, const D3D10_DEPTH_STENCIL_VIEW_DESC *pDesc, ID3D10DepthStencilView **ppDepthStencilView); + + HRESULT STDMETHODCALLTYPE CreateInputLayout( const D3D10_INPUT_ELEMENT_DESC *pInputElementDescs, UINT NumElements, const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, ID3D10InputLayout **ppInputLayout); + + HRESULT STDMETHODCALLTYPE CreateVertexShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10VertexShader **ppVertexShader); + + HRESULT STDMETHODCALLTYPE CreateGeometryShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10GeometryShader **ppGeometryShader); + + HRESULT STDMETHODCALLTYPE CreateGeometryShaderWithStreamOutput( const void *pShaderBytecode, SIZE_T BytecodeLength, const D3D10_SO_DECLARATION_ENTRY *pSODeclaration, UINT NumEntries, UINT OutputStreamStride, ID3D10GeometryShader **ppGeometryShader); + + HRESULT STDMETHODCALLTYPE CreatePixelShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10PixelShader **ppPixelShader); + + HRESULT STDMETHODCALLTYPE CreateBlendState( const D3D10_BLEND_DESC *pBlendStateDesc, ID3D10BlendState **ppBlendState); + + HRESULT STDMETHODCALLTYPE CreateDepthStencilState( const D3D10_DEPTH_STENCIL_DESC *pDepthStencilDesc, ID3D10DepthStencilState **ppDepthStencilState); + + HRESULT STDMETHODCALLTYPE CreateRasterizerState( const D3D10_RASTERIZER_DESC *pRasterizerDesc, ID3D10RasterizerState **ppRasterizerState); + + HRESULT STDMETHODCALLTYPE CreateSamplerState( const D3D10_SAMPLER_DESC *pSamplerDesc, ID3D10SamplerState **ppSamplerState); + + HRESULT STDMETHODCALLTYPE CreateQuery( const D3D10_QUERY_DESC *pQueryDesc, ID3D10Query **ppQuery); + + HRESULT STDMETHODCALLTYPE CreatePredicate( const D3D10_QUERY_DESC *pPredicateDesc, ID3D10Predicate **ppPredicate); + + HRESULT STDMETHODCALLTYPE CreateCounter( const D3D10_COUNTER_DESC *pCounterDesc, ID3D10Counter **ppCounter); + + HRESULT STDMETHODCALLTYPE CheckFormatSupport( DXGI_FORMAT Format, UINT *pFormatSupport); + + HRESULT STDMETHODCALLTYPE CheckMultisampleQualityLevels( DXGI_FORMAT Format, UINT SampleCount, UINT *pNumQualityLevels); + + void STDMETHODCALLTYPE CheckCounterInfo( D3D10_COUNTER_INFO *pCounterInfo); + + HRESULT STDMETHODCALLTYPE CheckCounter( const D3D10_COUNTER_DESC *pDesc, D3D10_COUNTER_TYPE *pType, UINT *pActiveCounters, LPSTR szName, UINT *pNameLength, LPSTR szUnits, UINT *pUnitsLength, LPSTR szDescription, UINT *pDescriptionLength); + + UINT STDMETHODCALLTYPE GetCreationFlags( void); + + HRESULT STDMETHODCALLTYPE OpenSharedResource( HANDLE hResource, REFIID ReturnedInterface, void **ppResource); + + void STDMETHODCALLTYPE SetTextFilterSize( UINT Width, UINT Height); + + void STDMETHODCALLTYPE GetTextFilterSize( UINT *pWidth, UINT *pHeight); + + + ID3D10Device* m_ID3D10Device; + uMod_TextureServer* uMod_Server; + uMod_TextureClient_DX10* uMod_Client; + +private: + unsigned int RefCounter; +}; + + +#endif /* UMOD_ID3D10DEVICE_H_ */ diff --git a/uMod_DX10/uMod_ID3D10Device1.cpp b/uMod_DX10/uMod_ID3D10Device1.cpp new file mode 100644 index 0000000..823cc9c --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Device1.cpp @@ -0,0 +1,54 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + + +#define UMOD_ID3D10DEVICE_H_ + +#include "..\uMod_DXMain\uMod_Main.h" +#include "uMod_ID3D10Device1.h" + +#define uMod_ID3D10Device uMod_ID3D10Device1 +#define ID3D10Device ID3D10Device1 +#define m_ID3D10Device m_ID3D10Device1 + +//#define RETURN_QueryInterface 0x01000001L +#define PRE_MESSAGE "uMod_ID3D10Device1" +#define DEF_DX_VERSION VERSION_DX101 + + +#include "uMod_ID3D10Device.cpp" + + + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device1::CreateShaderResourceView1( ID3D10Resource *pResource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *pDesc, ID3D10ShaderResourceView1 **ppSRView) +{ + return m_ID3D10Device1->CreateShaderResourceView1( pResource, pDesc, ppSRView); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Device1::CreateBlendState1( const D3D10_BLEND_DESC1 *pBlendStateDesc, ID3D10BlendState1 **ppBlendState) +{ + return m_ID3D10Device1->CreateBlendState1( pBlendStateDesc, ppBlendState); +} + +D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE uMod_ID3D10Device1::GetFeatureLevel(void) +{ + return m_ID3D10Device1->GetFeatureLevel(); +} + + diff --git a/uMod_DX10/uMod_ID3D10Device1.h b/uMod_DX10/uMod_ID3D10Device1.h new file mode 100644 index 0000000..c2555ca --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Device1.h @@ -0,0 +1,258 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + + + +#ifndef UMOD_ID3D10DEVICE1_H_ +#define UMOD_ID3D10DEVICE1_H_ + + +#include +#include +#include +#include +#include "..\uMod_DXMain\uMod_TextureServer.h" +#include "uMod_TextureClient_DX10.h" +#include "uMod_ID3D10Texture1D.h" +#include "uMod_ID3D10Texture2D.h" +#include "uMod_ID3D10Texture3D.h" + + + + +class uMod_ID3D10Device1 : public ID3D10Device1 +{ +public: + uMod_ID3D10Device1(ID3D10Device1* pOriginal, uMod_TextureServer* server); + virtual ~uMod_ID3D10Device1(); + + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject); + ULONG STDMETHODCALLTYPE AddRef(void); + ULONG STDMETHODCALLTYPE Release( void); + + void STDMETHODCALLTYPE VSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers); + + void STDMETHODCALLTYPE PSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews); + + void STDMETHODCALLTYPE PSSetShader( ID3D10PixelShader *pPixelShader); + + void STDMETHODCALLTYPE PSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers); + + void STDMETHODCALLTYPE VSSetShader( ID3D10VertexShader *pVertexShader); + + void STDMETHODCALLTYPE DrawIndexed( UINT IndexCount, UINT StartIndexLocation, INT BaseVertexLocation); + + void STDMETHODCALLTYPE Draw( UINT VertexCount, UINT StartVertexLocation); + + void STDMETHODCALLTYPE PSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers); + + void STDMETHODCALLTYPE IASetInputLayout( ID3D10InputLayout *pInputLayout); + + void STDMETHODCALLTYPE IASetVertexBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppVertexBuffers, const UINT *pStrides, const UINT *pOffsets); + + void STDMETHODCALLTYPE IASetIndexBuffer( ID3D10Buffer *pIndexBuffer, DXGI_FORMAT Format, UINT Offset); + + void STDMETHODCALLTYPE DrawIndexedInstanced( UINT IndexCountPerInstance, UINT InstanceCount, UINT StartIndexLocation, INT BaseVertexLocation, UINT StartInstanceLocation); + + void STDMETHODCALLTYPE DrawInstanced( UINT VertexCountPerInstance, UINT InstanceCount, UINT StartVertexLocation, UINT StartInstanceLocation); + + void STDMETHODCALLTYPE GSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer *const *ppConstantBuffers); + + void STDMETHODCALLTYPE GSSetShader( ID3D10GeometryShader *pShader); + + void STDMETHODCALLTYPE IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY Topology); + + void STDMETHODCALLTYPE VSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews); + + void STDMETHODCALLTYPE VSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers); + + void STDMETHODCALLTYPE SetPredication( ID3D10Predicate *pPredicate, BOOL PredicateValue); + + void STDMETHODCALLTYPE GSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView *const *ppShaderResourceViews); + + void STDMETHODCALLTYPE GSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState *const *ppSamplers); + + void STDMETHODCALLTYPE OMSetRenderTargets( UINT NumViews, ID3D10RenderTargetView *const *ppRenderTargetViews, ID3D10DepthStencilView *pDepthStencilView); + + void STDMETHODCALLTYPE OMSetBlendState( ID3D10BlendState *pBlendState, const FLOAT BlendFactor[ 4 ], UINT SampleMask); + + void STDMETHODCALLTYPE OMSetDepthStencilState( ID3D10DepthStencilState *pDepthStencilState, UINT StencilRef); + + void STDMETHODCALLTYPE SOSetTargets( UINT NumBuffers, ID3D10Buffer *const *ppSOTargets, const UINT *pOffsets); + + void STDMETHODCALLTYPE DrawAuto(void); + + void STDMETHODCALLTYPE RSSetState( ID3D10RasterizerState *pRasterizerState); + + void STDMETHODCALLTYPE RSSetViewports( UINT NumViewports, const D3D10_VIEWPORT *pViewports); + + void STDMETHODCALLTYPE RSSetScissorRects( UINT NumRects, const D3D10_RECT *pRects); + + void STDMETHODCALLTYPE CopySubresourceRegion( ID3D10Resource *pDstResource, UINT DstSubresource, UINT DstX, UINT DstY, UINT DstZ, ID3D10Resource *pSrcResource, UINT SrcSubresource, const D3D10_BOX *pSrcBox); + + void STDMETHODCALLTYPE CopyResource( ID3D10Resource *pDstResource, ID3D10Resource *pSrcResource); + + void STDMETHODCALLTYPE UpdateSubresource( ID3D10Resource *pDstResource, UINT DstSubresource, const D3D10_BOX *pDstBox, const void *pSrcData, UINT SrcRowPitch, UINT SrcDepthPitch); + + void STDMETHODCALLTYPE ClearRenderTargetView( ID3D10RenderTargetView *pRenderTargetView, const FLOAT ColorRGBA[ 4 ]); + + void STDMETHODCALLTYPE ClearDepthStencilView( ID3D10DepthStencilView *pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil); + + void STDMETHODCALLTYPE GenerateMips( ID3D10ShaderResourceView *pShaderResourceView); + + void STDMETHODCALLTYPE ResolveSubresource( ID3D10Resource *pDstResource, UINT DstSubresource, ID3D10Resource *pSrcResource, UINT SrcSubresource, DXGI_FORMAT Format); + + void STDMETHODCALLTYPE VSGetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppConstantBuffers); + + void STDMETHODCALLTYPE PSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews); + + void STDMETHODCALLTYPE PSGetShader( ID3D10PixelShader **ppPixelShader); + + void STDMETHODCALLTYPE PSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers); + + void STDMETHODCALLTYPE VSGetShader( ID3D10VertexShader **ppVertexShader); + + void STDMETHODCALLTYPE PSGetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppConstantBuffers); + + void STDMETHODCALLTYPE IAGetInputLayout( ID3D10InputLayout **ppInputLayout); + + void STDMETHODCALLTYPE IAGetVertexBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppVertexBuffers, UINT *pStrides, UINT *pOffsets); + + void STDMETHODCALLTYPE IAGetIndexBuffer( ID3D10Buffer **pIndexBuffer, DXGI_FORMAT *Format, UINT *Offset); + + void STDMETHODCALLTYPE GSGetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D10Buffer **ppConstantBuffers); + + void STDMETHODCALLTYPE GSGetShader( ID3D10GeometryShader **ppGeometryShader); + + void STDMETHODCALLTYPE IAGetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY *pTopology); + + void STDMETHODCALLTYPE VSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews); + + void STDMETHODCALLTYPE VSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers); + + void STDMETHODCALLTYPE GetPredication( ID3D10Predicate **ppPredicate, BOOL *pPredicateValue); + + void STDMETHODCALLTYPE GSGetShaderResources( UINT StartSlot, UINT NumViews, ID3D10ShaderResourceView **ppShaderResourceViews); + + void STDMETHODCALLTYPE GSGetSamplers( UINT StartSlot, UINT NumSamplers, ID3D10SamplerState **ppSamplers); + + void STDMETHODCALLTYPE OMGetRenderTargets( UINT NumViews, ID3D10RenderTargetView **ppRenderTargetViews, ID3D10DepthStencilView **ppDepthStencilView); + + void STDMETHODCALLTYPE OMGetBlendState( ID3D10BlendState **ppBlendState, FLOAT BlendFactor[ 4 ], UINT *pSampleMask); + + void STDMETHODCALLTYPE OMGetDepthStencilState( ID3D10DepthStencilState **ppDepthStencilState, UINT *pStencilRef); + + void STDMETHODCALLTYPE SOGetTargets( UINT NumBuffers, ID3D10Buffer **ppSOTargets, UINT *pOffsets); + + void STDMETHODCALLTYPE RSGetState( ID3D10RasterizerState **ppRasterizerState); + + void STDMETHODCALLTYPE RSGetViewports( UINT *NumViewports, D3D10_VIEWPORT *pViewports); + + void STDMETHODCALLTYPE RSGetScissorRects( UINT *NumRects, D3D10_RECT *pRects); + + HRESULT STDMETHODCALLTYPE GetDeviceRemovedReason(void); + + HRESULT STDMETHODCALLTYPE SetExceptionMode( UINT RaiseFlags); + + UINT STDMETHODCALLTYPE GetExceptionMode(void); + + HRESULT STDMETHODCALLTYPE GetPrivateData( REFGUID guid,UINT *pDataSize, void *pData); + + HRESULT STDMETHODCALLTYPE SetPrivateData( REFGUID guid, UINT DataSize, const void *pData); + + HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( REFGUID guid, const IUnknown *pData); + + void STDMETHODCALLTYPE ClearState( void); + + void STDMETHODCALLTYPE Flush( void); + + HRESULT STDMETHODCALLTYPE CreateBuffer( const D3D10_BUFFER_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Buffer **ppBuffer); + + HRESULT STDMETHODCALLTYPE CreateTexture1D( const D3D10_TEXTURE1D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture1D **ppTexture1D); + + HRESULT STDMETHODCALLTYPE CreateTexture2D( const D3D10_TEXTURE2D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture2D **ppTexture2D); + + HRESULT STDMETHODCALLTYPE CreateTexture3D( const D3D10_TEXTURE3D_DESC *pDesc, const D3D10_SUBRESOURCE_DATA *pInitialData, ID3D10Texture3D **ppTexture3D); + + HRESULT STDMETHODCALLTYPE CreateShaderResourceView( ID3D10Resource *pResource, const D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc, ID3D10ShaderResourceView **ppSRView); + + HRESULT STDMETHODCALLTYPE CreateRenderTargetView( ID3D10Resource *pResource, const D3D10_RENDER_TARGET_VIEW_DESC *pDesc, ID3D10RenderTargetView **ppRTView); + + HRESULT STDMETHODCALLTYPE CreateDepthStencilView( ID3D10Resource *pResource, const D3D10_DEPTH_STENCIL_VIEW_DESC *pDesc, ID3D10DepthStencilView **ppDepthStencilView); + + HRESULT STDMETHODCALLTYPE CreateInputLayout( const D3D10_INPUT_ELEMENT_DESC *pInputElementDescs, UINT NumElements, const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, ID3D10InputLayout **ppInputLayout); + + HRESULT STDMETHODCALLTYPE CreateVertexShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10VertexShader **ppVertexShader); + + HRESULT STDMETHODCALLTYPE CreateGeometryShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10GeometryShader **ppGeometryShader); + + HRESULT STDMETHODCALLTYPE CreateGeometryShaderWithStreamOutput( const void *pShaderBytecode, SIZE_T BytecodeLength, const D3D10_SO_DECLARATION_ENTRY *pSODeclaration, UINT NumEntries, UINT OutputStreamStride, ID3D10GeometryShader **ppGeometryShader); + + HRESULT STDMETHODCALLTYPE CreatePixelShader( const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10PixelShader **ppPixelShader); + + HRESULT STDMETHODCALLTYPE CreateBlendState( const D3D10_BLEND_DESC *pBlendStateDesc, ID3D10BlendState **ppBlendState); + + HRESULT STDMETHODCALLTYPE CreateDepthStencilState( const D3D10_DEPTH_STENCIL_DESC *pDepthStencilDesc, ID3D10DepthStencilState **ppDepthStencilState); + + HRESULT STDMETHODCALLTYPE CreateRasterizerState( const D3D10_RASTERIZER_DESC *pRasterizerDesc, ID3D10RasterizerState **ppRasterizerState); + + HRESULT STDMETHODCALLTYPE CreateSamplerState( const D3D10_SAMPLER_DESC *pSamplerDesc, ID3D10SamplerState **ppSamplerState); + + HRESULT STDMETHODCALLTYPE CreateQuery( const D3D10_QUERY_DESC *pQueryDesc, ID3D10Query **ppQuery); + + HRESULT STDMETHODCALLTYPE CreatePredicate( const D3D10_QUERY_DESC *pPredicateDesc, ID3D10Predicate **ppPredicate); + + HRESULT STDMETHODCALLTYPE CreateCounter( const D3D10_COUNTER_DESC *pCounterDesc, ID3D10Counter **ppCounter); + + HRESULT STDMETHODCALLTYPE CheckFormatSupport( DXGI_FORMAT Format, UINT *pFormatSupport); + + HRESULT STDMETHODCALLTYPE CheckMultisampleQualityLevels( DXGI_FORMAT Format, UINT SampleCount, UINT *pNumQualityLevels); + + void STDMETHODCALLTYPE CheckCounterInfo( D3D10_COUNTER_INFO *pCounterInfo); + + HRESULT STDMETHODCALLTYPE CheckCounter( const D3D10_COUNTER_DESC *pDesc, D3D10_COUNTER_TYPE *pType, UINT *pActiveCounters, LPSTR szName, UINT *pNameLength, LPSTR szUnits, UINT *pUnitsLength, LPSTR szDescription, UINT *pDescriptionLength); + + UINT STDMETHODCALLTYPE GetCreationFlags( void); + + HRESULT STDMETHODCALLTYPE OpenSharedResource( HANDLE hResource, REFIID ReturnedInterface, void **ppResource); + + void STDMETHODCALLTYPE SetTextFilterSize( UINT Width, UINT Height); + + void STDMETHODCALLTYPE GetTextFilterSize( UINT *pWidth, UINT *pHeight); + + + + HRESULT STDMETHODCALLTYPE CreateShaderResourceView1( ID3D10Resource *pResource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *pDesc, ID3D10ShaderResourceView1 **ppSRView); + + HRESULT STDMETHODCALLTYPE CreateBlendState1( const D3D10_BLEND_DESC1 *pBlendStateDesc, ID3D10BlendState1 **ppBlendState); + + D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE GetFeatureLevel(void); + + + + ID3D10Device1* m_ID3D10Device1; + uMod_TextureServer* uMod_Server; + uMod_TextureClient_DX10* uMod_Client; + +private: + unsigned int RefCounter; +}; + + +#endif /* UMOD_ID3D10DEVICE1_H_ */ diff --git a/uMod_DX10/uMod_ID3D10Texture1D.cpp b/uMod_DX10/uMod_ID3D10Texture1D.cpp new file mode 100644 index 0000000..f47bf9d --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Texture1D.cpp @@ -0,0 +1,96 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + +#include "../uMod_DXMain/uMod_Main.h" +#include "uMod_ID3D10Texture1D.h" + + +uMod_ID3D10Texture1D::uMod_ID3D10Texture1D(ID3D10Texture1D *pOriginal) +{ + Message( "uMod_ID3D10Texture1D::uMod_ID3D10Texture1D( %lu): %lu\n", pOriginal, this); + m_ID3D10Texture1D = pOriginal; +} +uMod_ID3D10Texture1D::~uMod_ID3D10Texture1D() +{ +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture1D::QueryInterface( REFIID riid, void** ppvObject) +{ + return m_ID3D10Texture1D->QueryInterface( riid, ppvObject); +} + +ULONG STDMETHODCALLTYPE uMod_ID3D10Texture1D::AddRef(void) +{ + return m_ID3D10Texture1D->AddRef(); +} +ULONG STDMETHODCALLTYPE uMod_ID3D10Texture1D::Release( void) +{ + ULONG count = m_ID3D10Texture1D->Release(); + + // in case no further Ref is there, the Original Object has deleted itself + if (count == 0) + { + delete(this); + } + return(count); +} + +void STDMETHODCALLTYPE uMod_ID3D10Texture1D::GetDevice( ID3D10Device **ppDevice) +{ + return m_ID3D10Texture1D->GetDevice( ppDevice); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture1D::GetPrivateData( REFGUID guid, UINT *pDataSize, void *pData) +{ + return m_ID3D10Texture1D->GetPrivateData( guid, pDataSize, pData); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture1D::SetPrivateData( REFGUID guid, UINT DataSize, const void *pData) +{ + return m_ID3D10Texture1D->SetPrivateData( guid, DataSize, pData); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture1D::SetPrivateDataInterface( REFGUID guid, const IUnknown *pData) +{ + return m_ID3D10Texture1D->SetPrivateDataInterface( guid, pData); +} + +void STDMETHODCALLTYPE uMod_ID3D10Texture1D::GetType( D3D10_RESOURCE_DIMENSION *rType) +{ + return m_ID3D10Texture1D->GetType( rType); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture1D::SetEvictionPriority( UINT EvictionPriority) +{ + return m_ID3D10Texture1D->SetEvictionPriority( EvictionPriority); +} +UINT STDMETHODCALLTYPE uMod_ID3D10Texture1D::GetEvictionPriority(void) +{ + return m_ID3D10Texture1D->GetEvictionPriority(); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture1D::Map( UINT Subresource, D3D10_MAP MapType, UINT MapFlags, void **ppData) +{ + return m_ID3D10Texture1D->Map( Subresource, MapType, MapFlags, ppData); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture1D::Unmap( UINT Subresource) +{ + return m_ID3D10Texture1D->Unmap( Subresource); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture1D::GetDesc( D3D10_TEXTURE1D_DESC *pDesc) +{ + return m_ID3D10Texture1D->GetDesc( pDesc); +} + + diff --git a/uMod_DX10/uMod_ID3D10Texture1D.h b/uMod_DX10/uMod_ID3D10Texture1D.h new file mode 100644 index 0000000..f433100 --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Texture1D.h @@ -0,0 +1,56 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + +#ifndef UMOD_ID3D10TEXTURE1D_H_ +#define UMOD_ID3D10TEXTURE1D_H_ + +#include +#include +#include +#include + +class uMod_ID3D10Texture1D : public ID3D10Texture1D +{ +public: + uMod_ID3D10Texture1D(ID3D10Texture1D *pOriginal); + virtual ~uMod_ID3D10Texture1D(); + + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject); + ULONG STDMETHODCALLTYPE AddRef(void); + ULONG STDMETHODCALLTYPE Release( void); + + void STDMETHODCALLTYPE GetDevice( ID3D10Device **ppDevice); + HRESULT STDMETHODCALLTYPE GetPrivateData( REFGUID guid, UINT *pDataSize, void *pData); + HRESULT STDMETHODCALLTYPE SetPrivateData( REFGUID guid, UINT DataSize, const void *pData); + HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( REFGUID guid, const IUnknown *pData); + + void STDMETHODCALLTYPE GetType( D3D10_RESOURCE_DIMENSION *rType); + void STDMETHODCALLTYPE SetEvictionPriority( UINT EvictionPriority); + UINT STDMETHODCALLTYPE GetEvictionPriority(void); + + HRESULT STDMETHODCALLTYPE Map( UINT Subresource, D3D10_MAP MapType, UINT MapFlags, void **ppData); + void STDMETHODCALLTYPE Unmap( UINT Subresource); + void STDMETHODCALLTYPE GetDesc( D3D10_TEXTURE1D_DESC *pDesc); + + ID3D10Texture1D *m_ID3D10Texture1D; +}; + + + +#endif /* UMOD_ID3D10TEXTURE1D_H_ */ diff --git a/uMod_DX10/uMod_ID3D10Texture2D.cpp b/uMod_DX10/uMod_ID3D10Texture2D.cpp new file mode 100644 index 0000000..2c4148d --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Texture2D.cpp @@ -0,0 +1,96 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + +#include "../uMod_DXMain/uMod_Main.h" +#include "uMod_ID3D10Texture2D.h" + + +uMod_ID3D10Texture2D::uMod_ID3D10Texture2D(ID3D10Texture2D *pOriginal) +{ + Message( "uMod_ID3D10Texture1D::uMod_ID3D10Texture1D( %lu): %lu\n", pOriginal, this); + m_ID3D10Texture2D = pOriginal; +} +uMod_ID3D10Texture2D::~uMod_ID3D10Texture2D() +{ +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture2D::QueryInterface( REFIID riid, void** ppvObject) +{ + return m_ID3D10Texture2D->QueryInterface( riid, ppvObject); +} + +ULONG STDMETHODCALLTYPE uMod_ID3D10Texture2D::AddRef(void) +{ + return m_ID3D10Texture2D->AddRef(); +} +ULONG STDMETHODCALLTYPE uMod_ID3D10Texture2D::Release( void) +{ + ULONG count = m_ID3D10Texture2D->Release(); + + // in case no further Ref is there, the Original Object has deleted itself + if (count == 0) + { + delete(this); + } + return(count); +} + +void STDMETHODCALLTYPE uMod_ID3D10Texture2D::GetDevice( ID3D10Device **ppDevice) +{ + return m_ID3D10Texture2D->GetDevice( ppDevice); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture2D::GetPrivateData( REFGUID guid, UINT *pDataSize, void *pData) +{ + return m_ID3D10Texture2D->GetPrivateData( guid, pDataSize, pData); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture2D::SetPrivateData( REFGUID guid, UINT DataSize, const void *pData) +{ + return m_ID3D10Texture2D->SetPrivateData( guid, DataSize, pData); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture2D::SetPrivateDataInterface( REFGUID guid, const IUnknown *pData) +{ + return m_ID3D10Texture2D->SetPrivateDataInterface( guid, pData); +} + +void STDMETHODCALLTYPE uMod_ID3D10Texture2D::GetType( D3D10_RESOURCE_DIMENSION *rType) +{ + return m_ID3D10Texture2D->GetType( rType); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture2D::SetEvictionPriority( UINT EvictionPriority) +{ + return m_ID3D10Texture2D->SetEvictionPriority( EvictionPriority); +} +UINT STDMETHODCALLTYPE uMod_ID3D10Texture2D::GetEvictionPriority(void) +{ + return m_ID3D10Texture2D->GetEvictionPriority(); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture2D::Map( UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE2D *pMappedTex2D) +{ + return m_ID3D10Texture2D->Map( Subresource, MapType, MapFlags, pMappedTex2D); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture2D::Unmap( UINT Subresource) +{ + return m_ID3D10Texture2D->Unmap( Subresource); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture2D::GetDesc( D3D10_TEXTURE2D_DESC *pDesc) +{ + return m_ID3D10Texture2D->GetDesc( pDesc); +} + + diff --git a/uMod_DX10/uMod_ID3D10Texture2D.h b/uMod_DX10/uMod_ID3D10Texture2D.h new file mode 100644 index 0000000..817a286 --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Texture2D.h @@ -0,0 +1,56 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + +#ifndef UMOD_ID3D10TEXTURE2D_H_ +#define UMOD_ID3D10TEXTURE2D_H_ + +#include +#include +#include +#include + +class uMod_ID3D10Texture2D : public ID3D10Texture2D +{ +public: + uMod_ID3D10Texture2D(ID3D10Texture2D *pOriginal); + virtual ~uMod_ID3D10Texture2D(); + + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject); + ULONG STDMETHODCALLTYPE AddRef(void); + ULONG STDMETHODCALLTYPE Release( void); + + void STDMETHODCALLTYPE GetDevice( ID3D10Device **ppDevice); + HRESULT STDMETHODCALLTYPE GetPrivateData( REFGUID guid, UINT *pDataSize, void *pData); + HRESULT STDMETHODCALLTYPE SetPrivateData( REFGUID guid, UINT DataSize, const void *pData); + HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( REFGUID guid, const IUnknown *pData); + + void STDMETHODCALLTYPE GetType( D3D10_RESOURCE_DIMENSION *rType); + void STDMETHODCALLTYPE SetEvictionPriority( UINT EvictionPriority); + UINT STDMETHODCALLTYPE GetEvictionPriority(void); + + HRESULT STDMETHODCALLTYPE Map( UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE2D *ppData); + void STDMETHODCALLTYPE Unmap( UINT Subresource); + void STDMETHODCALLTYPE GetDesc( D3D10_TEXTURE2D_DESC *pDesc); + + ID3D10Texture2D *m_ID3D10Texture2D; +}; + + + +#endif /* UMOD_ID3D10TEXTURE2D_H_ */ diff --git a/uMod_DX10/uMod_ID3D10Texture3D.cpp b/uMod_DX10/uMod_ID3D10Texture3D.cpp new file mode 100644 index 0000000..2172a58 --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Texture3D.cpp @@ -0,0 +1,96 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + +#include "../uMod_DXMain/uMod_Main.h" +#include "uMod_ID3D10Texture3D.h" + + +uMod_ID3D10Texture3D::uMod_ID3D10Texture3D(ID3D10Texture3D *pOriginal) +{ + Message( "uMod_ID3D10Texture1D::uMod_ID3D10Texture1D( %lu): %lu\n", pOriginal, this); + m_ID3D10Texture3D = pOriginal; +} +uMod_ID3D10Texture3D::~uMod_ID3D10Texture3D() +{ +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture3D::QueryInterface( REFIID riid, void** ppvObject) +{ + return m_ID3D10Texture3D->QueryInterface( riid, ppvObject); +} + +ULONG STDMETHODCALLTYPE uMod_ID3D10Texture3D::AddRef(void) +{ + return m_ID3D10Texture3D->AddRef(); +} +ULONG STDMETHODCALLTYPE uMod_ID3D10Texture3D::Release( void) +{ + ULONG count = m_ID3D10Texture3D->Release(); + + // in case no further Ref is there, the Original Object has deleted itself + if (count == 0) + { + delete(this); + } + return(count); +} + +void STDMETHODCALLTYPE uMod_ID3D10Texture3D::GetDevice( ID3D10Device **ppDevice) +{ + return m_ID3D10Texture3D->GetDevice( ppDevice); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture3D::GetPrivateData( REFGUID guid, UINT *pDataSize, void *pData) +{ + return m_ID3D10Texture3D->GetPrivateData( guid, pDataSize, pData); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture3D::SetPrivateData( REFGUID guid, UINT DataSize, const void *pData) +{ + return m_ID3D10Texture3D->SetPrivateData( guid, DataSize, pData); +} +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture3D::SetPrivateDataInterface( REFGUID guid, const IUnknown *pData) +{ + return m_ID3D10Texture3D->SetPrivateDataInterface( guid, pData); +} + +void STDMETHODCALLTYPE uMod_ID3D10Texture3D::GetType( D3D10_RESOURCE_DIMENSION *rType) +{ + return m_ID3D10Texture3D->GetType( rType); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture3D::SetEvictionPriority( UINT EvictionPriority) +{ + return m_ID3D10Texture3D->SetEvictionPriority( EvictionPriority); +} +UINT STDMETHODCALLTYPE uMod_ID3D10Texture3D::GetEvictionPriority(void) +{ + return m_ID3D10Texture3D->GetEvictionPriority(); +} + +HRESULT STDMETHODCALLTYPE uMod_ID3D10Texture3D::Map( UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE3D *pMappedTex3D) +{ + return m_ID3D10Texture3D->Map( Subresource, MapType, MapFlags, pMappedTex3D); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture3D::Unmap( UINT Subresource) +{ + return m_ID3D10Texture3D->Unmap( Subresource); +} +void STDMETHODCALLTYPE uMod_ID3D10Texture3D::GetDesc( D3D10_TEXTURE3D_DESC *pDesc) +{ + return m_ID3D10Texture3D->GetDesc( pDesc); +} + + diff --git a/uMod_DX10/uMod_ID3D10Texture3D.h b/uMod_DX10/uMod_ID3D10Texture3D.h new file mode 100644 index 0000000..fbce98c --- /dev/null +++ b/uMod_DX10/uMod_ID3D10Texture3D.h @@ -0,0 +1,56 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + +#ifndef UMOD_ID3D10TEXTURE3D_H_ +#define UMOD_ID3D10TEXTURE3D_H_ + +#include +#include +#include +#include + +class uMod_ID3D10Texture3D : public ID3D10Texture3D +{ +public: + uMod_ID3D10Texture3D(ID3D10Texture3D *pOriginal); + virtual ~uMod_ID3D10Texture3D(); + + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject); + ULONG STDMETHODCALLTYPE AddRef(void); + ULONG STDMETHODCALLTYPE Release( void); + + void STDMETHODCALLTYPE GetDevice( ID3D10Device **ppDevice); + HRESULT STDMETHODCALLTYPE GetPrivateData( REFGUID guid, UINT *pDataSize, void *pData); + HRESULT STDMETHODCALLTYPE SetPrivateData( REFGUID guid, UINT DataSize, const void *pData); + HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( REFGUID guid, const IUnknown *pData); + + void STDMETHODCALLTYPE GetType( D3D10_RESOURCE_DIMENSION *rType); + void STDMETHODCALLTYPE SetEvictionPriority( UINT EvictionPriority); + UINT STDMETHODCALLTYPE GetEvictionPriority(void); + + HRESULT STDMETHODCALLTYPE Map( UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE3D *ppData); + void STDMETHODCALLTYPE Unmap( UINT Subresource); + void STDMETHODCALLTYPE GetDesc( D3D10_TEXTURE3D_DESC *pDesc); + + ID3D10Texture3D *m_ID3D10Texture3D; +}; + + + +#endif /* UMOD_ID3D10TEXTURE3D_H_ */ diff --git a/uMod_DX10/uMod_IDXGISwapChain.cpp b/uMod_DX10/uMod_IDXGISwapChain.cpp new file mode 100644 index 0000000..fd3c421 --- /dev/null +++ b/uMod_DX10/uMod_IDXGISwapChain.cpp @@ -0,0 +1,161 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine.If not, see . +*/ + +#include "../uMod_DXMain/uMod_Main.h" +#include "uMod_IDXGISwapChain.h" +#include "uMod_ID3D10Device.h" + + +uMod_IDXGISwapChain::uMod_IDXGISwapChain(IDXGISwapChain *pOriginal, uMod_ID3D10Device *dev) +{ + Message( "IDXGISwapChain::IDXGISwapChain( %lu, %lu): %lu\n", pOriginal, dev, this); + m_IDXGISwapChain = pOriginal; + u_ID3D10Device = dev; + RefCounter = 1; +} + +uMod_IDXGISwapChain::~uMod_IDXGISwapChain() +{ + Message( "IDXGISwapChain::~IDXGISwapChain(): %lu\n", this); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::QueryInterface( REFIID riid, void** ppvObject) +{ + *ppvObject = NULL; + Message( "IDXGISwapChain::QueryInterface(): %lu\n", this); + HRESULT hRes = m_IDXGISwapChain->QueryInterface(riid, ppvObject); + + if (*ppvObject == m_IDXGISwapChain) + { + RefCounter++; //increasing our counter + *ppvObject = this; + } + + return (hRes); +} + +ULONG STDMETHODCALLTYPE uMod_IDXGISwapChain::AddRef(void) +{ + RefCounter++; + return m_IDXGISwapChain->AddRef(); +} + +ULONG STDMETHODCALLTYPE uMod_IDXGISwapChain::Release( void) +{ + if (--RefCounter==0) //if our counter drops to zero, the real device will be deleted, so we clean up before + { + // we must not release the fake textures, cause they are released if the target textures are released + // and the target textures are released by the game. + } + + // call original routine + ULONG count = m_IDXGISwapChain->Release(); + + // in case no further Ref is there, the Original Object has deleted itself + if (count == 0) + { + delete(this); + } + + return(count); +} + + + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::SetPrivateData(REFGUID Name, UINT DataSize, const void *pData) +{ + return m_IDXGISwapChain->SetPrivateData( Name, DataSize, pData); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::SetPrivateDataInterface( REFGUID Name, const IUnknown *pUnknown) +{ + return m_IDXGISwapChain->SetPrivateDataInterface( Name, pUnknown); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetPrivateData( REFGUID Name, UINT *pDataSize, void *pData) +{ + return m_IDXGISwapChain->GetPrivateData( Name, pDataSize, pData); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetParent( REFIID riid, void **ppParent) +{ + return m_IDXGISwapChain->GetParent( riid, ppParent); +} + + + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetDevice( REFIID riid, void **ppDevice) +{ + // ToDO: + // Increas RefCounter from u_ID3D10Device but not from u_ID3D10Device->m_ID3D10Device ? ? ? ? ? + HRESULT hRes = m_IDXGISwapChain->GetDevice( riid, ppDevice); + if (*ppDevice == u_ID3D10Device->m_ID3D10Device) *ppDevice = u_ID3D10Device; + return hRes; +} + + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::Present( UINT SyncInterval, UINT Flags) +{ + return m_IDXGISwapChain->Present( SyncInterval, Flags); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetBuffer( UINT Buffer, REFIID riid, void **ppSurface) +{ + return m_IDXGISwapChain->GetBuffer( Buffer, riid, ppSurface); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::SetFullscreenState( BOOL Fullscreen, IDXGIOutput *pTarget) +{ + return m_IDXGISwapChain->SetFullscreenState( Fullscreen, pTarget); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetFullscreenState( BOOL *pFullscreen, IDXGIOutput **ppTarget) +{ + return m_IDXGISwapChain->GetFullscreenState( pFullscreen, ppTarget); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetDesc( DXGI_SWAP_CHAIN_DESC *pDesc) +{ + return m_IDXGISwapChain->GetDesc( pDesc); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::ResizeBuffers( UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags) +{ + return m_IDXGISwapChain->ResizeBuffers( BufferCount, Width, Height, NewFormat, SwapChainFlags); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::ResizeTarget( const DXGI_MODE_DESC *pNewTargetParameters) +{ + return m_IDXGISwapChain->ResizeTarget( pNewTargetParameters); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetContainingOutput( IDXGIOutput **ppOutput) +{ + return m_IDXGISwapChain->GetContainingOutput( ppOutput); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetFrameStatistics( DXGI_FRAME_STATISTICS *pStats) +{ + return m_IDXGISwapChain->GetFrameStatistics( pStats); +} + +HRESULT STDMETHODCALLTYPE uMod_IDXGISwapChain::GetLastPresentCount( UINT *pLastPresentCount) +{ + return m_IDXGISwapChain->GetLastPresentCount( pLastPresentCount); +} + diff --git a/uMod_DX10/uMod_IDXGISwapChain.h b/uMod_DX10/uMod_IDXGISwapChain.h new file mode 100644 index 0000000..b8759dc --- /dev/null +++ b/uMod_DX10/uMod_IDXGISwapChain.h @@ -0,0 +1,80 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + +#ifndef UMOD_IDXGISWAPCHAIN_H_ +#define UMOD_IDXGISWAPCHAIN_H_ + +#include +#include +#include +#include + +class uMod_ID3D10Device; + +class uMod_IDXGISwapChain : public IDXGISwapChain +{ +public: + uMod_IDXGISwapChain(IDXGISwapChain *pOriginal, uMod_ID3D10Device *dev); + virtual ~uMod_IDXGISwapChain(); + + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject); + ULONG STDMETHODCALLTYPE AddRef(void); + ULONG STDMETHODCALLTYPE Release( void); + + + HRESULT STDMETHODCALLTYPE SetPrivateData( REFGUID Name, UINT DataSize, const void *pData); + HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( REFGUID Name, const IUnknown *pUnknown); + HRESULT STDMETHODCALLTYPE GetPrivateData( REFGUID Name, UINT *pDataSize, void *pData); + HRESULT STDMETHODCALLTYPE GetParent( REFIID riid, void **ppParent); + + + HRESULT STDMETHODCALLTYPE GetDevice( REFIID riid, void **ppDevice); + + + + HRESULT STDMETHODCALLTYPE Present( UINT SyncInterval, UINT Flags); + + HRESULT STDMETHODCALLTYPE GetBuffer( UINT Buffer, REFIID riid, void **ppSurface); + + HRESULT STDMETHODCALLTYPE SetFullscreenState( BOOL Fullscreen, IDXGIOutput *pTarget); + + HRESULT STDMETHODCALLTYPE GetFullscreenState( BOOL *pFullscreen, IDXGIOutput **ppTarget); + + HRESULT STDMETHODCALLTYPE GetDesc( DXGI_SWAP_CHAIN_DESC *pDesc); + + HRESULT STDMETHODCALLTYPE ResizeBuffers( UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags); + + HRESULT STDMETHODCALLTYPE ResizeTarget( const DXGI_MODE_DESC *pNewTargetParameters); + + HRESULT STDMETHODCALLTYPE GetContainingOutput( IDXGIOutput **ppOutput); + + HRESULT STDMETHODCALLTYPE GetFrameStatistics( DXGI_FRAME_STATISTICS *pStats); + + HRESULT STDMETHODCALLTYPE GetLastPresentCount( UINT *pLastPresentCount); + + + IDXGISwapChain *m_IDXGISwapChain; + uMod_ID3D10Device *u_ID3D10Device; + +private: + unsigned int RefCounter; +}; + + +#endif /* UMOD_IDXGISWAPCHAIN_H_ */ diff --git a/uMod_DX10/uMod_TextureClient_DX10.h b/uMod_DX10/uMod_TextureClient_DX10.h new file mode 100644 index 0000000..cadbf2b --- /dev/null +++ b/uMod_DX10/uMod_TextureClient_DX10.h @@ -0,0 +1,98 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + + +#ifndef uMod_TEXTURECLIENT_DX10_HPP +#define uMod_TEXTURECLIENT_DX10_HPP + +#include "..\uMod_Error.h" +#include "..\uMod_DXMain\uMod_TextureClient.h" + +class uMod_TextureServer; +class uMod_ID3D10Device; + +/* + * An object of this class is owned by each d3d10 device. + * functions called by the Server are called from the server thread instance. + * All other functions are called from the render thread instance of the game itself. + */ + +class uMod_TextureClient_DX10 : public uMod_TextureClient +{ +public: + uMod_TextureClient_DX10( uMod_ID3D10Device* device, const int version); + virtual ~uMod_TextureClient_DX10(void); +/* + int AddTexture( uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DDevice9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() + int AddTexture( uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() + int AddTexture( uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() + + int RemoveTexture( uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DTexture9::Release() + int RemoveTexture( uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::Release() + int RemoveTexture( uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::Release() + + int SaveAllTextures(bool val); //called from the Server + int SaveSingleTexture(bool val); //called from the Server + + int SaveTexture(uMod_IDirect3DTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) + int SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) + int SaveTexture(uMod_IDirect3DCubeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) + + int MergeUpdate(void); //called from uMod_IDirect3DDevice9::BeginScene() + + + + int LookUpToMod( uMod_IDirect3DTexture9* pTexture, int num_index_list=0, int *index_list=(int*)0); // called at the end AddTexture(...) and from Device->UpdateTexture(...) + + int LookUpToMod( uMod_IDirect3DVolumeTexture9* pTexture, int num_index_list=0, int *index_list=(int*)0); // called at the end AddTexture(...) and from Device->UpdateTexture(...) + + int LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, int num_index_list=0, int *index_list=(int*)0); // called at the end AddTexture(...) and from Device->UpdateTexture(...) + + uMod_TextureHandler OriginalTextures; // stores the pointer to the uMod_IDirect3DTexture9 objects created by the game + uMod_TextureHandler OriginalVolumeTextures; // stores the pointer to the uMod_IDirect3DVolumeTexture9 objects created by the game + uMod_TextureHandler OriginalCubeTextures; // stores the pointer to the uMod_IDirect3DCubeTexture9 objects created by the game + + + // if the has could not be calculated for a texture it is not considered in the original texture list, + // but it is now added into the following lists and we try to calculate the hash once again later + int CheckAgainNonAdded(void); + bool Bool_CheckAgainNonAdded; + uMod_TextureHandler NonAdded_OriginalTextures; // stores the pointer to the uMod_IDirect3DTexture9 objects created by the game + uMod_TextureHandler NonAdded_OriginalVolumeTextures; // stores the pointer to the uMod_IDirect3DVolumeTexture9 objects created by the game + uMod_TextureHandler NonAdded_OriginalCubeTextures; // stores the pointer to the uMod_IDirect3DCubeTexture9 objects created by the game + +private: + IDirect3DDevice9* D3D9Device; + + int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9 **ppTexture); // called if a target texture is found + int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9 **ppTexture); // called if a target texture is found + int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9 **ppTexture); // called if a target texture is found + + // and the corresponding fake texture should be loaded + + //MyTypeHash GetHash(unsigned char *str, int len); + //unsigned int GetCRC32(char *pcDatabuf, unsigned int ulDatalen); + * + */ + +}; + + + +#endif /* uMod_TEXTUREHANDLER_HPP_ */ diff --git a/uMod_DX9/uMod_DX9_dll.cpp b/uMod_DX9/uMod_DX9_dll.cpp index 2096952..99254da 100644 --- a/uMod_DX9/uMod_DX9_dll.cpp +++ b/uMod_DX9/uMod_DX9_dll.cpp @@ -28,13 +28,8 @@ along with Universal Modding Engine. If not, see #include "uMod_DX9_dll.h" #include "uMod_IDirect3D9.h" #include "uMod_IDirect3D9Ex.h" -//#include "detours.h" -//#include "detourxs/detourxs/detourxs.h" -/* -#include "detourxs/detourxs/ADE32.cpp" -#include "detourxs/detourxs/detourxs.cpp" -*/ + /* * global variable which are not linked external */ @@ -43,7 +38,7 @@ HINSTANCE gl_hOriginal_DX9_Dll = NULL; typedef IDirect3D9 *(APIENTRY *Direct3DCreate9_type)(UINT); typedef HRESULT (APIENTRY *Direct3DCreate9Ex_type)(UINT SDKVersion, IDirect3D9Ex **ppD3D); -#ifndef NO_INJECTION +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION Direct3DCreate9_type Direct3DCreate9_fn = NULL; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour Direct3DCreate9Ex_type Direct3DCreate9Ex_fn = NULL; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour #endif @@ -59,7 +54,7 @@ void InitDX9(void) { LoadOriginal_DX9_Dll(); -#ifndef NO_INJECTION +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION // we detour the original Direct3DCreate9 to our MyDirect3DCreate9 if (gl_hOriginal_DX9_Dll!=NULL) { @@ -89,6 +84,7 @@ void ExitDX9(void) gl_hOriginal_DX9_Dll = NULL; } } + void LoadOriginal_DX9_Dll(void) { char buffer[MAX_PATH]; @@ -105,7 +101,7 @@ void LoadOriginal_DX9_Dll(void) } -#ifdef NO_INJECTION +#if INJECTION_METHOD==NO_INJECTION /* * We do not inject, the game loads this dll by itself thus we must include the Direct3DCreate9 function */ @@ -220,8 +216,9 @@ DWORD WINAPI D3DPERF_GetStatus( void ) return fn( ); } +#endif -#else +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION /* * We inject the dll into the game, thus we retour the original Direct3DCreate9 function to our MyDirect3DCreate9 function diff --git a/uMod_DX9/uMod_DX9_dll.h b/uMod_DX9/uMod_DX9_dll.h index 7cbc951..2175d64 100644 --- a/uMod_DX9/uMod_DX9_dll.h +++ b/uMod_DX9/uMod_DX9_dll.h @@ -23,13 +23,31 @@ along with Universal Modding Engine. If not, see #include "../uMod_DXMain/uMod_Main.h" +/** + * Load the official d3d9.dll from the system path. + */ void LoadOriginal_DX9_Dll(void); + +/** + * Initialize dx9 -> loads d3d9.dll and set detour if this dll is compiled for "Direct Injection" or "Hook Injection" + */ void InitDX9(); + +/** + * Unload the d3d9.dll + */ void ExitDX9(); -#ifndef NO_INJECTION +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION +/** + * Direct3DCreate9 function must be exported if compiled for "No Injection" + */ IDirect3D9 *APIENTRY uMod_Direct3DCreate9(UINT SDKVersion); + +/** + * Direct3DCreate9Ex function must be exported if compiled for "No Injection" + */ HRESULT APIENTRY uMod_Direct3DCreate9Ex( UINT SDKVersion, IDirect3D9Ex **ppD3D); #endif diff --git a/uMod_DX9/uMod_IDirect3DCubeTexture9.cpp b/uMod_DX9/uMod_IDirect3DCubeTexture9.cpp index 6898934..94c40be 100644 --- a/uMod_DX9/uMod_IDirect3DCubeTexture9.cpp +++ b/uMod_DX9/uMod_IDirect3DCubeTexture9.cpp @@ -239,15 +239,12 @@ HRESULT APIENTRY uMod_IDirect3DCubeTexture9::UnlockRect( D3DCUBEMAP_FACES FaceTy -int uMod_IDirect3DCubeTexture9::GetHash(MyTypeHash &hash) +int uMod_IDirect3DCubeTexture9::ComputetHash( bool compute_crc) { - hash=0u; if (FAKE) return (RETURN_BAD_ARGUMENT); IDirect3DCubeTexture9 *pTexture = m_D3Dtex; if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex; - //IDirect3DSurface9 *pOffscreenSurface = NULL; - //IDirect3DCubeTexture9 *pOffscreenTexture = NULL; IDirect3DSurface9 *pResolvedSurface = NULL; D3DLOCKED_RECT d3dlr; D3DSURFACE_DESC desc; @@ -257,110 +254,72 @@ int uMod_IDirect3DCubeTexture9::GetHash(MyTypeHash &hash) Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetLevelDesc \n"); return (RETURN_GetLevelDesc_FAILED); } + int bits_per_pixel = GetBitsFromFormat( desc.Format); + unsigned int size; + unsigned int h_max = desc.Height; + if (desc.Format == D3DFMT_DXT1) // 8 bytes per block + { + h_max /= 4; // divided by block size + size = desc.Width*2; // desc.Width/4 * 8 + } + else if ( desc.Format==D3DFMT_DXT2 || desc.Format==D3DFMT_DXT3 || desc.Format==D3DFMT_DXT4 || desc.Format==D3DFMT_DXT5 ) // 16 bytes per block + { + h_max /= 4; // divided by block size + size = desc.Width*4; // desc.Width/4 * 16 + } + else size = (bits_per_pixel * desc.Width)/8; + + Hash = HASH_INIT_VALUE; Message("uMod_IDirect3DCubeTexture9::GetHash() (%d %d) %d\n", desc.Width, desc.Height, desc.Format); -/* - if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture + for (int site = 0; site<6; site++) { - //Message("uMod_IDirect3DCubeTexture9::GetHash() (D3DPOOL_DEFAULT)\n"); - - IDirect3DSurface9 *pSurfaceLevel_orig = NULL; - if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK) + if (pTexture->LockRect( ( _D3DCUBEMAP_FACES) site, 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK) { - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - - if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) - { - //Message("uMod_IDirect3DCubeTexture9::GetHash() MultiSampleType\n"); - if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL )) + Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 1\n"); + if (pTexture->GetCubeMapSurface( ( _D3DCUBEMAP_FACES) site, 0, &pResolvedSurface)!=D3D_OK) { - pSurfaceLevel_orig->Release(); - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n"); + Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel\n"); return (RETURN_LockRect_FAILED); } - if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE )) + if (pResolvedSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK) { - pSurfaceLevel_orig->Release(); - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n"); + pResolvedSurface->Release(); + Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 2\n"); return (RETURN_LockRect_FAILED); } - - pSurfaceLevel_orig = pResolvedSurface; } - - if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL)) { - pSurfaceLevel_orig->Release(); - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n"); - return (RETURN_TEXTURE_NOT_LOADED); + unsigned char *data = (unsigned char*) d3dlr.pBits; + + for (unsigned int h=0; hGetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface)) + if (compute_crc && site==0) { - pSurfaceLevel_orig->Release(); - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - pOffscreenSurface->Release(); - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); + int size = (bits_per_pixel * desc.Width*desc.Height)/8; + CRC = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture } - pSurfaceLevel_orig->Release(); - if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK) - { - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - pOffscreenSurface->Release(); - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - } - else - */ - if (pTexture->LockRect( D3DCUBEMAP_FACE_POSITIVE_X, 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK) - { - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 1\n"); - if (pTexture->GetCubeMapSurface( D3DCUBEMAP_FACE_POSITIVE_X, 0, &pResolvedSurface)!=D3D_OK) - { - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel\n"); - return (RETURN_LockRect_FAILED); - } - if (pResolvedSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK) + if (pResolvedSurface!=NULL) { + pResolvedSurface->UnlockRect(); pResolvedSurface->Release(); - Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 2\n"); - return (RETURN_LockRect_FAILED); + pResolvedSurface=NULL; + } + else + { + pTexture->UnlockRect( ( _D3DCUBEMAP_FACES) site, 0); //unlock the raw data } } - - int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height)/8; - - hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture -/* - if (pOffscreenSurface!=NULL) - { - pOffscreenSurface->UnlockRect(); - pOffscreenSurface->Release(); - //pOffscreenTexture->Release(); - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - } - else - */ - if (pResolvedSurface!=NULL) - { - pResolvedSurface->UnlockRect(); - pResolvedSurface->Release(); - } - else - { - pTexture->UnlockRect( D3DCUBEMAP_FACE_POSITIVE_X, 0); //unlock the raw data - } - - Message("uMod_IDirect3DCubeTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size); + Message("uMod_IDirect3DCubeTexture9::GetHash() %#llX %#LX (%d %d) %d\n", Hash, CRC, desc.Width, desc.Height, desc.Format); return (RETURN_OK); } diff --git a/uMod_DX9/uMod_IDirect3DCubeTexture9.h b/uMod_DX9/uMod_IDirect3DCubeTexture9.h index 18862a5..3fda915 100644 --- a/uMod_DX9/uMod_IDirect3DCubeTexture9.h +++ b/uMod_DX9/uMod_IDirect3DCubeTexture9.h @@ -34,9 +34,9 @@ along with Universal Modding Engine. If not, see #include "..\uMod_DXMain\uMod_Defines.h" - -interface uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9 +class uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9 { +public: uMod_IDirect3DCubeTexture9(IDirect3DCubeTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9) { m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game @@ -47,16 +47,17 @@ interface uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9 // thus the fake texture can also be deleted Reference = -1; //need for fast deleting Hash = 0u; + CRC = 0u; FAKE = false; } - // callback interface - IDirect3DCubeTexture9 *m_D3Dtex; - uMod_IDirect3DCubeTexture9 *CrossRef_D3Dtex; - IDirect3DDevice9 *m_D3Ddev; - int Reference; - MyTypeHash Hash; - bool FAKE; + IDirect3DCubeTexture9 *m_D3Dtex; //!< pointer to the real IDirect3DCubeTexture9 object + uMod_IDirect3DCubeTexture9 *CrossRef_D3Dtex; //!< cross reference from the fake texture to the game texture and vice versa + IDirect3DDevice9 *m_D3Ddev; //!< pointer to the device + int Reference; //!< Index in the vector (needed for a fast delete). + DWORD64 Hash; //!< computed hash value for this game texture. + DWORD32 CRC; //!< computed crc32 value for this game texture. + bool FAKE; //!< True if this texture is was loaded by uMod (fake texture) // original interface STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj); @@ -84,7 +85,7 @@ interface uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9 STDMETHOD(UnlockRect)(D3DCUBEMAP_FACES FaceType, UINT Level); - int GetHash(MyTypeHash &hash); + int ComputetHash( bool compute_crc); }; diff --git a/uMod_DX9/uMod_IDirect3DDevice9.cpp b/uMod_DX9/uMod_IDirect3DDevice9.cpp index ac36b90..8541506 100644 --- a/uMod_DX9/uMod_IDirect3DDevice9.cpp +++ b/uMod_DX9/uMod_IDirect3DDevice9.cpp @@ -62,9 +62,15 @@ int uMod_IDirect3DDevice9::CreateSingleTexture(void) SingleTexture=NULL; return (RETURN_TEXTURE_NOT_LOADED); } - DWORD *pDst = (DWORD*)d3dlr.pBits; - for (int i=0; i<8*8; i++) pDst[i] = TextureColour; + Message( PRE_MESSAGE "::CreateSingleTexture(): Set IDirect3DTexture9 Colour to %#X\n", TextureColour); + BYTE *pImage = (BYTE*)d3dlr.pBits; + for (int i=0; i<8; i++) + { + DWORD *pDst = (DWORD*)pImage; + for (int j=0;j<8; j++) pDst[j] = TextureColour; + pImage += d3dlr.Pitch; + } pD3Dtex->UnlockRect(0); } @@ -92,9 +98,14 @@ int uMod_IDirect3DDevice9::CreateSingleTexture(void) SingleVolumeTexture=NULL; return (RETURN_TEXTURE_NOT_LOADED); } - DWORD *pDst = (DWORD*)d3dlr.pBits; - for (int i=0; i<8*8*8; i++) pDst[i] = TextureColour; + Message( PRE_MESSAGE "::CreateSingleTexture(): Set IDirect3DVolumeTexture9 Colour to %#X\n", TextureColour); + DWORD *pDst = (DWORD*)d3dlr.pBits; + for (int i=0; i<8; i++) for (int ii=0; ii<8; ii++) + { + DWORD *pDst = (DWORD*) ((char*) d3dlr.pBits)[ i*d3dlr.SlicePitch + ii*d3dlr.RowPitch]; + //for (int j=0;j<8; j++) pDst[j] = TextureColour; + } pD3Dtex->UnlockBox(0); } if (SingleCubeTexture==NULL) //create texture @@ -114,6 +125,7 @@ int uMod_IDirect3DDevice9::CreateSingleTexture(void) D3DLOCKED_RECT d3dlr; IDirect3DCubeTexture9 *pD3Dtex = SingleCubeTexture->m_D3Dtex; + Message( PRE_MESSAGE "::CreateSingleTexture(): Set IDirect3DCubeTexture9 Colour to %#X\n", TextureColour); for (int c=0; c<6; c++) { if (D3D_OK!=pD3Dtex->LockRect( (D3DCUBEMAP_FACES) c, 0, &d3dlr, 0, 0)) @@ -123,9 +135,14 @@ int uMod_IDirect3DDevice9::CreateSingleTexture(void) SingleCubeTexture=NULL; return (RETURN_TEXTURE_NOT_LOADED); } - DWORD *pDst = (DWORD*)d3dlr.pBits; - for (int i=0; i<8*8; i++) pDst[i] = TextureColour; + BYTE *pImage = (BYTE*)d3dlr.pBits; + for (int i=0; i<8; i++) + { + DWORD *pDst = (DWORD*)pImage; + for (int j=0;j<8; j++) pDst[j] = TextureColour; + pImage += d3dlr.Pitch; + } pD3Dtex->UnlockRect((D3DCUBEMAP_FACES)c, 0); } } @@ -148,7 +165,6 @@ uMod_IDirect3DDevice9::uMod_IDirect3DDevice9( IDirect3DDevice9* pOriginal, uMod_ LastCreatedVolumeTexture = NULL; LastCreatedCubeTexture = NULL; m_pIDirect3DDevice9 = pOriginal; // store the pointer to original object - TextureColour = D3DCOLOR_ARGB(255,0,255,0); CounterSaveSingleTexture = -20; @@ -425,13 +441,13 @@ HRESULT uMod_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTextu { case 0x01000000L: { - MyTypeHash hash; pSource = (uMod_IDirect3DTexture9*)(pSourceTexture); - if (pSource->GetHash( hash) == RETURN_OK) + DWORD64 hash = pSource->Hash; + DWORD32 crc = pSource->CRC; + if (pSource->ComputetHash( crc>0 ) == RETURN_OK) { - if (hash != pSource->Hash) // this hash has changed !! + if (hash != pSource->Hash || (crc>0 && crc != pSource->CRC) ) // this hash has changed !! { - pSource->Hash = hash; if (pSource->CrossRef_D3Dtex!=NULL) UnswitchTextures(pSource); uMod_Client->LookUpToMod( pSource); } @@ -445,11 +461,12 @@ HRESULT uMod_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTextu } case 0x01000001L: { - MyTypeHash hash; pSourceVolume = (uMod_IDirect3DVolumeTexture9*)(pSourceTexture); - if (pSourceVolume->GetHash( hash) == RETURN_OK) + DWORD64 hash = pSourceVolume->Hash; + DWORD32 crc = pSourceVolume->CRC; + if (pSourceVolume->ComputetHash( crc>0 ) == RETURN_OK) { - if (hash != pSourceVolume->Hash) // this hash has changed !! + if (hash != pSourceVolume->Hash || (crc>0 && crc != pSource->CRC) ) // this hash has changed !! { pSourceVolume->Hash = hash; if (pSourceVolume->CrossRef_D3Dtex!=NULL) UnswitchTextures(pSourceVolume); @@ -465,11 +482,12 @@ HRESULT uMod_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTextu } case 0x01000002L: { - MyTypeHash hash; pSourceCube = (uMod_IDirect3DCubeTexture9*)(pSourceTexture); - if (pSourceCube->GetHash( hash) == RETURN_OK) + DWORD64 hash = pSourceCube->Hash; + DWORD32 crc = pSourceCube->CRC; + if (pSourceCube->ComputetHash( crc>0 ) == RETURN_OK) { - if (hash != pSourceCube->Hash) // this hash has changed !! + if (hash != pSourceCube->Hash || (crc>0 && crc != pSource->CRC) ) // this hash has changed !! { pSourceCube->Hash = hash; if (pSourceCube->CrossRef_D3Dtex!=NULL) UnswitchTextures(pSourceCube); @@ -491,7 +509,7 @@ HRESULT uMod_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTextu if (pDestinationTexture != NULL) { - long int ret = pSourceTexture->QueryInterface( IID_IDirect3D9, (void**) &cpy); + long int ret = pDestinationTexture->QueryInterface( IID_IDirect3D9, (void**) &cpy); switch (ret) { case 0x01000000L: @@ -763,7 +781,7 @@ HRESULT uMod_IDirect3DDevice9::BeginScene(void) HRESULT uMod_IDirect3DDevice9::EndScene(void) { - if ( NormalRendering && uMod_Client->BoolSaveSingleTexture && SingleTexture!=NULL && SingleVolumeTexture!=NULL && SingleCubeTexture!=NULL) + if ( NormalRendering && uMod_Client->BoolShowTextureString && uMod_Client->BoolSaveSingleTexture && SingleTexture!=NULL && SingleVolumeTexture!=NULL && SingleCubeTexture!=NULL) { if (OSD_Font==NULL) // create the font { @@ -780,7 +798,7 @@ HRESULT uMod_IDirect3DDevice9::EndScene(void) { case 0: { - if (SingleTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "normal texture: %4d (1..%d): %#lX", CounterSaveSingleTexture+1, uMod_Client->OriginalTextures.GetNumber(), SingleTexture->Hash); + if (SingleTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "normal texture: %4d (1..%d): %#llX", CounterSaveSingleTexture+1, uMod_Client->OriginalTextures.GetNumber(), SingleTexture->Hash); else { if (uMod_Client->OriginalTextures.GetNumber()>0) sprintf_s( buffer, 100, "normal texture: nothing selected (1..%d)", uMod_Client->OriginalTextures.GetNumber()); @@ -790,7 +808,7 @@ HRESULT uMod_IDirect3DDevice9::EndScene(void) } case 1: { - if (SingleVolumeTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "volume texture: %4d (1..%d): %#lX", CounterSaveSingleTexture+1, uMod_Client->OriginalVolumeTextures.GetNumber(), SingleVolumeTexture->Hash); + if (SingleVolumeTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "volume texture: %4d (1..%d): %#llX", CounterSaveSingleTexture+1, uMod_Client->OriginalVolumeTextures.GetNumber(), SingleVolumeTexture->Hash); else { if (uMod_Client->OriginalVolumeTextures.GetNumber()>0) sprintf_s( buffer, 100, "volume texture: nothing selected (1..%d)", uMod_Client->OriginalVolumeTextures.GetNumber()); @@ -800,7 +818,7 @@ HRESULT uMod_IDirect3DDevice9::EndScene(void) } case 2: { - if (SingleCubeTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "cube texture: %4d (1..%d): %#lX", CounterSaveSingleTexture+1, uMod_Client->OriginalCubeTextures.GetNumber(), SingleCubeTexture->Hash); + if (SingleCubeTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "cube texture: %4d (1..%d): %#llX", CounterSaveSingleTexture+1, uMod_Client->OriginalCubeTextures.GetNumber(), SingleCubeTexture->Hash); else { if (uMod_Client->OriginalCubeTextures.GetNumber()>0) sprintf_s( buffer, 100, "cube texture: nothing selected (1..%d)", uMod_Client->OriginalCubeTextures.GetNumber()); diff --git a/uMod_DX9/uMod_IDirect3DTexture9.cpp b/uMod_DX9/uMod_IDirect3DTexture9.cpp index aabf1bd..5fb2260 100644 --- a/uMod_DX9/uMod_IDirect3DTexture9.cpp +++ b/uMod_DX9/uMod_IDirect3DTexture9.cpp @@ -240,9 +240,8 @@ HRESULT APIENTRY uMod_IDirect3DTexture9::AddDirtyRect(CONST RECT* pDirtyRect) } -int uMod_IDirect3DTexture9::GetHash(MyTypeHash &hash) +int uMod_IDirect3DTexture9::ComputetHash( bool compute_crc) { - hash=0u; if (FAKE) return (RETURN_BAD_ARGUMENT); IDirect3DTexture9 *pTexture = m_D3Dtex; if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex; @@ -342,9 +341,37 @@ int uMod_IDirect3DTexture9::GetHash(MyTypeHash &hash) } } - int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height)/8; + int bits_per_pixel = GetBitsFromFormat( desc.Format); - hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture + { + Hash = HASH_INIT_VALUE; + unsigned char *data = (unsigned char*) d3dlr.pBits; + unsigned int size; + unsigned int h_max = desc.Height; + if (desc.Format == D3DFMT_DXT1) // 8 bytes per block + { + h_max /= 4; // divided by block size + size = desc.Width*2; // desc.Width/4 * 8 + } + else if ( desc.Format==D3DFMT_DXT2 || desc.Format==D3DFMT_DXT3 || desc.Format==D3DFMT_DXT4 || desc.Format==D3DFMT_DXT5 ) // 16 bytes per block + { + h_max /= 4; // divided by block size + size = desc.Width*4; // desc.Width/4 * 16 + } + else size = (bits_per_pixel * desc.Width)/8; + + for (unsigned int h=0; hUnlockRect(0); - Message("uMod_IDirect3DTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size); + Message("uMod_IDirect3DTexture9::GetHash() %#llX %#LX (%d %d) %d\n", Hash, CRC, desc.Width, desc.Height, desc.Format); return (RETURN_OK); } diff --git a/uMod_DX9/uMod_IDirect3DTexture9.h b/uMod_DX9/uMod_IDirect3DTexture9.h index 9827677..1431a03 100644 --- a/uMod_DX9/uMod_IDirect3DTexture9.h +++ b/uMod_DX9/uMod_IDirect3DTexture9.h @@ -35,8 +35,9 @@ along with Universal Modding Engine. If not, see -interface uMod_IDirect3DTexture9 : public IDirect3DTexture9 +class uMod_IDirect3DTexture9 : public IDirect3DTexture9 { +public: uMod_IDirect3DTexture9(IDirect3DTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9) { m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game @@ -47,16 +48,17 @@ interface uMod_IDirect3DTexture9 : public IDirect3DTexture9 // thus the fake texture can also be deleted Reference = -1; //need for fast deleting Hash = 0u; + CRC = 0u; FAKE = false; } - // callback interface - IDirect3DTexture9 *m_D3Dtex; - uMod_IDirect3DTexture9 *CrossRef_D3Dtex; - IDirect3DDevice9 *m_D3Ddev; - int Reference; - MyTypeHash Hash; - bool FAKE; + IDirect3DTexture9 *m_D3Dtex; //!< pointer to the real IDirect3DCubeTexture9 object + uMod_IDirect3DTexture9 *CrossRef_D3Dtex; //!< cross reference from the fake texture to the game texture and vice versa + IDirect3DDevice9 *m_D3Ddev; //!< pointer to the device + int Reference; //!< Index in the vector (needed for a fast delete). + DWORD64 Hash; //!< computed hash value for this game texture. + DWORD32 CRC; //!< computed crc32 value for this game texture. + bool FAKE; //!< True if this texture is was loaded by uMod (fake texture) // original interface STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj); @@ -82,7 +84,7 @@ interface uMod_IDirect3DTexture9 : public IDirect3DTexture9 STDMETHOD(UnlockRect)(UINT Level); STDMETHOD(AddDirtyRect)(CONST RECT* pDirtyRect); - int GetHash(MyTypeHash &hash); + int ComputetHash( bool compute_crc); }; diff --git a/uMod_DX9/uMod_IDirect3DVolumeTexture9.cpp b/uMod_DX9/uMod_IDirect3DVolumeTexture9.cpp index 353b34d..317908b 100644 --- a/uMod_DX9/uMod_IDirect3DVolumeTexture9.cpp +++ b/uMod_DX9/uMod_IDirect3DVolumeTexture9.cpp @@ -239,9 +239,8 @@ HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::UnlockBox(UINT Level) } -int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash &hash) +int uMod_IDirect3DVolumeTexture9::ComputetHash( bool compute_crc) { - hash=0u; if (FAKE) return (RETURN_BAD_ARGUMENT); IDirect3DVolumeTexture9 *pTexture = m_D3Dtex; if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex; @@ -260,101 +259,7 @@ int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash &hash) Message("uMod_IDirect3DVolumeTexture9::GetHash() (%d %d %d) %d\n", desc.Width, desc.Height, desc.Depth, desc.Format); -/* - if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture - { - //Message("uMod_IDirect3DVolumeTexture9::GetHash() (D3DPOOL_DEFAULT)\n"); - IDirect3DSurface9 *pSurfaceLevel_orig = NULL; - if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK) - { - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } -/* - if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) - { - //Message("uMod_IDirect3DVolumeTexture9::GetHash() MultiSampleType\n"); - if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL )) - { - pSurfaceLevel_orig->Release(); - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE )) - { - pSurfaceLevel_orig->Release(); - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - - pSurfaceLevel_orig = pResolvedSurface; - } - */ -//CreateTexture(8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DVolumeTexture9**) &SingleTexture, NULL) - /* - if (D3D_OK!=m_D3Ddev->CreateTexture( desc.Width, desc.Height, 1, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenTexture, NULL)) - { - pSurfaceLevel_orig->Release(); - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateTexture (D3DPOOL_DEFAULT)\n"); - return (RETURN_TEXTURE_NOT_LOADED); - } - if (pOffscreenTexture->GetSurfaceLevel( 0, &pOffscreenSurface)!=D3D_OK) - { - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel 2 (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - - if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface)) - { - pSurfaceLevel_orig->Release(); - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - pOffscreenSurface->Release(); - pOffscreenTexture->Release(); - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - pSurfaceLevel_orig->Release(); - - if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK) - { - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - pOffscreenSurface->Release(); - pOffscreenTexture->Release(); - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - */ -/* - if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL)) - { - pSurfaceLevel_orig->Release(); - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n"); - return (RETURN_TEXTURE_NOT_LOADED); - } - - if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface)) - { - pSurfaceLevel_orig->Release(); - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - pOffscreenSurface->Release(); - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - pSurfaceLevel_orig->Release(); - - if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK) - { - if (pResolvedSurface!=NULL) pResolvedSurface->Release(); - pOffscreenSurface->Release(); - Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n"); - return (RETURN_LockRect_FAILED); - } - } - else - */ if (pTexture->LockBox( 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK) { Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect 1\n"); @@ -371,9 +276,45 @@ int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash &hash) } } - int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height*desc.Depth)/8; - hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture + int bits_per_pixel = GetBitsFromFormat( desc.Format); + + { + Hash = HASH_INIT_VALUE; + unsigned char *data = (unsigned char*) d3dlr.pBits; + + unsigned int size; + unsigned int h_max = desc.Height; + if (desc.Format == D3DFMT_DXT1) // 8 bytes per block + { + h_max /= 4; // divide by block size + size = desc.Width*2; // desc.Width/4 * 8 + } + else if ( desc.Format==D3DFMT_DXT2 || desc.Format==D3DFMT_DXT3 || desc.Format==D3DFMT_DXT4 || desc.Format==D3DFMT_DXT5 ) // 16 bytes per block + { + h_max /= 4; // divide by block size + size = desc.Width*4; // desc.Width/4 * 16 + } + else size = (bits_per_pixel * desc.Width)/8; + + //int size = (bits_per_pixel * desc.Width)/8; + for (unsigned int d=0; dUnlockBox(0); - Message("uMod_IDirect3DVolumeTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size); + Message("uMod_IDirect3DVolumeTexture9::GetHash() %#llX %#LX (%d %d %d) %d\n", Hash, CRC, desc.Width, desc.Height, desc.Depth, desc.Format); return (RETURN_OK); } diff --git a/uMod_DX9/uMod_IDirect3DVolumeTexture9.h b/uMod_DX9/uMod_IDirect3DVolumeTexture9.h index 262bfe1..39828d6 100644 --- a/uMod_DX9/uMod_IDirect3DVolumeTexture9.h +++ b/uMod_DX9/uMod_IDirect3DVolumeTexture9.h @@ -35,8 +35,9 @@ along with Universal Modding Engine. If not, see -interface uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9 +class uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9 { +public: uMod_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9) { m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game @@ -47,16 +48,17 @@ interface uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9 // thus the fake texture can also be deleted Reference = -1; //need for fast deleting Hash = 0u; + CRC = 0u; FAKE = false; } - // callback interface - IDirect3DVolumeTexture9 *m_D3Dtex; - uMod_IDirect3DVolumeTexture9 *CrossRef_D3Dtex; - IDirect3DDevice9 *m_D3Ddev; - int Reference; - MyTypeHash Hash; - bool FAKE; + IDirect3DVolumeTexture9 *m_D3Dtex; //!< pointer to the real IDirect3DCubeTexture9 object + uMod_IDirect3DVolumeTexture9 *CrossRef_D3Dtex; //!< cross reference from the fake texture to the game texture and vice versa + IDirect3DDevice9 *m_D3Ddev; //!< pointer to the device + int Reference; //!< Index in the vector (needed for a fast delete). + DWORD64 Hash; //!< computed hash value for this game texture. + DWORD32 CRC; //!< computed crc32 value for this game texture. + bool FAKE; //!< True if this texture is was loaded by uMod (fake texture) // original interface STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj); @@ -83,7 +85,7 @@ interface uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9 STDMETHOD(UnlockBox)(UINT Level); - int GetHash(MyTypeHash &hash); + int ComputetHash( bool compute_crc); }; diff --git a/uMod_DX9/uMod_TextureClient_DX9.cpp b/uMod_DX9/uMod_TextureClient_DX9.cpp index 52c5d3e..acc93a4 100644 --- a/uMod_DX9/uMod_TextureClient_DX9.cpp +++ b/uMod_DX9/uMod_TextureClient_DX9.cpp @@ -33,16 +33,6 @@ uMod_TextureClient_DX9::uMod_TextureClient_DX9( IDirect3DDevice9* device, const uMod_TextureClient_DX9::~uMod_TextureClient_DX9(void) { Message("uMod_TextureClient_DX9::~uMod_TextureClient(void): %lu\n", this); - if (Server!=NULL) Server->RemoveClient( this, Version); - - if (Mutex!=NULL) CloseHandle(Mutex); - - if (Update!=NULL) delete [] Update; - if (FileToMod!=NULL) - { - for (int i=0; iGetHash( hash)) + if (int ret = pTexture->ComputetHash( BoolComputeCRC)) { Bool_CheckAgainNonAdded = true; NonAdded_OriginalTextures.Add( pTexture); return (ret); } - pTexture->Hash = hash; - - if (BoolSaveAllTextures) SaveTexture(pTexture); + if (BoolSaveAllTextures) SaveTexture(pTexture, true); if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR); @@ -87,17 +74,14 @@ int uMod_TextureClient_DX9::AddTexture( uMod_IDirect3DVolumeTexture9* pTexture) Message("uMod_TextureClient_DX9::AddTexture( Volume: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId()); - MyTypeHash hash; - if (int ret = pTexture->GetHash( hash)) + if (int ret = pTexture->ComputetHash( BoolComputeCRC)) { Bool_CheckAgainNonAdded = true; NonAdded_OriginalVolumeTextures.Add( pTexture); return (ret); } - pTexture->Hash = hash; - - if (BoolSaveAllTextures) SaveTexture(pTexture); + if (BoolSaveAllTextures) SaveTexture(pTexture, true); if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR); @@ -117,17 +101,14 @@ int uMod_TextureClient_DX9::AddTexture( uMod_IDirect3DCubeTexture9* pTexture) Message("uMod_TextureClient_DX9::AddTexture( Cube: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId()); - MyTypeHash hash; - if (int ret = pTexture->GetHash( hash)) + if (int ret = pTexture->ComputetHash( BoolComputeCRC)) { Bool_CheckAgainNonAdded = true; NonAdded_OriginalCubeTextures.Add( pTexture); return (ret); } - pTexture->Hash = hash; - - if (BoolSaveAllTextures) SaveTexture(pTexture); + if (BoolSaveAllTextures) SaveTexture(pTexture, true); if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR); @@ -149,8 +130,7 @@ int uMod_TextureClient_DX9::CheckAgainNonAdded(void) { uMod_IDirect3DTexture9* pTexture = NonAdded_OriginalTextures[i]; - MyTypeHash hash; - if (pTexture->GetHash( hash) == 0) + if (pTexture->ComputetHash( BoolComputeCRC) == RETURN_OK) { NonAdded_OriginalTextures.Remove(pTexture); OriginalTextures.Add( pTexture); // add the texture to the list of original texture @@ -163,8 +143,7 @@ int uMod_TextureClient_DX9::CheckAgainNonAdded(void) { uMod_IDirect3DVolumeTexture9* pTexture = NonAdded_OriginalVolumeTextures[i]; - MyTypeHash hash; - if (pTexture->GetHash( hash) == 0) + if (pTexture->ComputetHash( BoolComputeCRC) == RETURN_OK) { NonAdded_OriginalVolumeTextures.Remove(pTexture); OriginalVolumeTextures.Add( pTexture); // add the texture to the list of original texture @@ -177,8 +156,7 @@ int uMod_TextureClient_DX9::CheckAgainNonAdded(void) { uMod_IDirect3DCubeTexture9* pTexture = NonAdded_OriginalCubeTextures[i]; - MyTypeHash hash; - if (pTexture->GetHash( hash) == 0) + if (pTexture->ComputetHash( BoolComputeCRC) == RETURN_OK) { NonAdded_OriginalCubeTextures.Remove(pTexture); OriginalCubeTextures.Add( pTexture); // add the texture to the list of original texture @@ -299,49 +277,248 @@ int uMod_TextureClient_DX9::SaveSingleTexture(bool val) } -int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DTexture9* pTexture) +int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DTexture9* pTexture, bool save_all) +{ + if (pTexture==NULL) return (RETURN_BAD_ARGUMENT); + if (SavePath[0]==0) + { + Message("uMod_TextureClient_DX9::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); + return (RETURN_TEXTURE_NOT_SAVED); + } + D3DSURFACE_DESC desc; + if (pTexture->m_D3Dtex->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture + { + Message("uMod_TextureClient_DX9::SaveTexture() Failed: GetLevelDesc \n"); + return (RETURN_GetLevelDesc_FAILED); + } + + if (save_all) + { + if (WidthFilter) + { + unsigned int min = WidthFilter >> 32; + unsigned int max = (WidthFilter<<32) >> 32; + if (desc.Width max) return (RETURN_OK); + } + if (HeightFilter) + { + unsigned int min = HeightFilter >> 32; + unsigned int max = (HeightFilter<<32) >> 32; + if (desc.Height max) return (RETURN_OK); + } + if (!SaveTextureFilterFormat(desc.Format)) return (RETURN_OK); + } + + + wchar_t file[MAX_PATH]; + if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_W%u_H%u_F%u_T_%#llX", SavePath, GameName, desc.Width, desc.Height,desc.Format, pTexture->Hash); + else swprintf_s( file, MAX_PATH, L"%ls\\W%u_H%u_F%u_T_%#llX", SavePath, desc.Width, desc.Height, desc.Format, pTexture->Hash); + Message("uMod_TextureClient_DX9::SaveTexture( %ls): %lu\n", file, this); + + return (SaveTexture( pTexture->m_D3Dtex, file)); +} + +int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture, bool save_all) { if (pTexture==NULL) return (RETURN_BAD_ARGUMENT); if (SavePath[0]==0) {Message("uMod_TextureClient_DX9::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);} + D3DVOLUME_DESC desc; + if (pTexture->m_D3Dtex->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture + { + Message("uMod_TextureClient_DX9::SaveTexture() Failed: GetLevelDesc \n"); + return (RETURN_GetLevelDesc_FAILED); + } + + if (save_all) + { + if (WidthFilter) + { + unsigned int min = WidthFilter >> 32; + unsigned int max = (WidthFilter<<32) >> 32; + if (desc.Width max) return (RETURN_OK); + } + if (HeightFilter) + { + unsigned int min = HeightFilter >> 32; + unsigned int max = (HeightFilter<<32) >> 32; + if (desc.Height max) return (RETURN_OK); + } + if (DepthFilter) + { + unsigned int min = DepthFilter >> 32; + unsigned int max = (DepthFilter<<32) >> 32; + if (desc.Depth max) return (RETURN_OK); + } + if (!SaveTextureFilterFormat(desc.Format)) return (RETURN_OK); + } + wchar_t file[MAX_PATH]; - if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_T_%#lX.dds", SavePath, GameName, pTexture->Hash); - else swprintf_s( file, MAX_PATH, L"%ls\\T_%#lX.dds", SavePath, pTexture->Hash); + if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_W%u_H%u_D%u_F%u_V_%#llX", SavePath, GameName, desc.Width, desc.Height, desc.Depth, desc.Format, pTexture->Hash); + else swprintf_s( file, MAX_PATH, L"%ls\\W%u_H%u_D%u_F%u_V_%#llX", SavePath, desc.Width, desc.Height, desc.Depth, desc.Format, pTexture->Hash); Message("uMod_TextureClient_DX9::SaveTexture( %ls): %lu\n", file, this); - if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED); - return (RETURN_OK); + return (SaveTexture( pTexture->m_D3Dtex, file)); } -int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture) +int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DCubeTexture9* pTexture, bool save_all) { if (pTexture==NULL) return (RETURN_BAD_ARGUMENT); if (SavePath[0]==0) {Message("uMod_TextureClient_DX9::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);} + D3DSURFACE_DESC desc; + if (pTexture->m_D3Dtex->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture + { + Message("uMod_TextureClient_DX9::SaveTexture() Failed: GetLevelDesc \n"); + return (RETURN_GetLevelDesc_FAILED); + } + + if (save_all) + { + if (WidthFilter) + { + unsigned int min = WidthFilter >> 32; + unsigned int max = (WidthFilter<<32) >> 32; + if (desc.Width max) return (RETURN_OK); + } + if (!SaveTextureFilterFormat(desc.Format)) return (RETURN_OK); + } + wchar_t file[MAX_PATH]; - if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_V_%#lX.dds", SavePath, GameName, pTexture->Hash); - else swprintf_s( file, MAX_PATH, L"%ls\\V_%#lX.dds", SavePath, pTexture->Hash); + if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_W%u_F%u_C_%#llX.dds", SavePath, GameName, desc.Width, desc.Format, pTexture->Hash); + else swprintf_s( file, MAX_PATH, L"%ls\\W%u_F%u_C_%#llX.dds", SavePath, desc.Width, desc.Format, pTexture->Hash); Message("uMod_TextureClient_DX9::SaveTexture( %ls): %lu\n", file, this); - if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED); - return (RETURN_OK); + + return (SaveTexture( pTexture->m_D3Dtex, file)); } -int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DCubeTexture9* pTexture) + +int uMod_TextureClient_DX9::SaveTexture(IDirect3DBaseTexture9* pTexture, wchar_t *file) { - if (pTexture==NULL) return (RETURN_BAD_ARGUMENT); - if (SavePath[0]==0) {Message("uMod_TextureClient_DX9::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);} - - wchar_t file[MAX_PATH]; - if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_C_%#lX.dds", SavePath, GameName, pTexture->Hash); - else swprintf_s( file, MAX_PATH, L"%ls\\C_%#lX.dds", SavePath, pTexture->Hash); - Message("uMod_TextureClient_DX9::SaveTexture( %ls): %lu\n", file, this); - - if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED); + unsigned int len=0; + while (file[len]) len++; + if (FileFormat & uMod_D3DXIFF_BMP) + { + file[len] = '.';file[len+1] = 'b';file[len+2] = 'm';file[len+3] = 'p';file[len+4] = '\0'; + if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_BMP, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED); + } + if (FileFormat & uMod_D3DXIFF_JPG) + { + file[len] = '.';file[len+1] = 'j';file[len+2] = 'p';file[len+3] = 'g';file[len+4] = '\0'; + if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_JPG, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED); + } + if (FileFormat & uMod_D3DXIFF_TGA) + { + file[len] = '.';file[len+1] = 't';file[len+2] = 'g';file[len+3] = 'a';file[len+4] = '\0'; + if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_TGA, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED); + } + if (FileFormat & uMod_D3DXIFF_PNG) + { + file[len] = '.';file[len+1] = 'p';file[len+2] = 'n';file[len+3] = 'g';file[len+4] = '\0'; + if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_PNG, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED); + } + if (FileFormat & uMod_D3DXIFF_DDS) + { + file[len] = '.';file[len+1] = 'd';file[len+2] = 'd';file[len+3] = 's';file[len+4] = '\0'; + if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED); + } + if (FileFormat & uMod_D3DXIFF_PPM) + { + file[len] = '.';file[len+1] = 'p';file[len+2] = 'p';file[len+3] = 'm';file[len+4] = '\0'; + if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_PPM, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED); + } return (RETURN_OK); } +#define DEF_FormatCheck( format ) \ + case format: \ + { \ + if (FormatFilter & uMod_ ## format) return (true); \ + else return (false); \ + } + +bool uMod_TextureClient_DX9::SaveTextureFilterFormat(D3DFORMAT format) +{ + if (FormatFilter == 0u) return (true); + switch(format) //switch trough the formats to calculate the size of the raw data + { + DEF_FormatCheck( D3DFMT_A1) // 1-bit monochrome. + DEF_FormatCheck( D3DFMT_R3G3B2) // 8-bit RGB texture format using 3 bits for red, 3 bits for green, and 2 bits for blue. + DEF_FormatCheck( D3DFMT_A8) // 8-bit alpha only. + + DEF_FormatCheck( D3DFMT_A8P8) // 8-bit color indexed with 8 bits of alpha. + DEF_FormatCheck( D3DFMT_P8) // 8-bit color indexed. + DEF_FormatCheck( D3DFMT_L8) // 8-bit luminance only. + DEF_FormatCheck( D3DFMT_A4L4) // 8-bit using 4 bits each for alpha and luminance. + + //DEF_FormatCheck( D3DFMT_FORCE_DWORD) + DEF_FormatCheck( D3DFMT_S8_LOCKABLE) // A lockable 8-bit stencil buffer. + + DEF_FormatCheck( D3DFMT_D16_LOCKABLE) //16-bit z-buffer bit depth. + DEF_FormatCheck( D3DFMT_D15S1) // 16-bit z-buffer bit depth where 15 bits are reserved for the depth channel and 1 bit is reserved for the stencil channel. + DEF_FormatCheck( D3DFMT_L6V5U5) // 16-bit bump-map format with luminance using 6 bits for luminance, and 5 bits each for v and u. + DEF_FormatCheck( D3DFMT_V8U8) // 16-bit bump-map format using 8 bits each for u and v data. + DEF_FormatCheck( D3DFMT_CxV8U8) // 16-bit normal compression format. The texture sampler computes the C channel from) C = sqrt(1 - U2 - V2). + DEF_FormatCheck( D3DFMT_R5G6B5) // 16-bit RGB pixel format with 5 bits for red, 6 bits for green, and 5 bits for blue. + DEF_FormatCheck( D3DFMT_X1R5G5B5) // 16-bit pixel format where 5 bits are reserved for each color. + DEF_FormatCheck( D3DFMT_A1R5G5B5) // 16-bit pixel format where 5 bits are reserved for each color and 1 bit is reserved for alpha. + DEF_FormatCheck( D3DFMT_A4R4G4B4) // 16-bit ARGB pixel format with 4 bits for each channel. + DEF_FormatCheck( D3DFMT_A8R3G3B2) // 16-bit ARGB texture format using 8 bits for alpha, 3 bits each for red and green, and 2 bits for blue. + DEF_FormatCheck( D3DFMT_X4R4G4B4) // 16-bit RGB pixel format using 4 bits for each color. + DEF_FormatCheck( D3DFMT_L16) // 16-bit luminance only. + DEF_FormatCheck( D3DFMT_R16F) // 16-bit float format using 16 bits for the red channel. + DEF_FormatCheck( D3DFMT_A8L8) // 16-bit using 8 bits each for alpha and luminance. + DEF_FormatCheck( D3DFMT_D16) // 16-bit z-buffer bit depth. + DEF_FormatCheck( D3DFMT_INDEX16) // 16-bit index buffer bit depth. + DEF_FormatCheck( D3DFMT_G8R8_G8B8) // ?? + DEF_FormatCheck( D3DFMT_R8G8_B8G8) // ?? + DEF_FormatCheck( D3DFMT_UYVY) // ?? + DEF_FormatCheck( D3DFMT_YUY2) // ?? + + DEF_FormatCheck( D3DFMT_R8G8B8) //24-bit RGB pixel format with 8 bits per channel. + + DEF_FormatCheck( D3DFMT_R32F) // 32-bit float format using 32 bits for the red channel. + DEF_FormatCheck( D3DFMT_X8L8V8U8) // 32-bit bump-map format with luminance using 8 bits for each channel. + DEF_FormatCheck( D3DFMT_A2W10V10U10) // 32-bit bump-map format using 2 bits for alpha and 10 bits each for w, v, and u. + DEF_FormatCheck( D3DFMT_Q8W8V8U8) // 32-bit bump-map format using 8 bits for each channel. + DEF_FormatCheck( D3DFMT_V16U16) // 32-bit bump-map format using 16 bits for each channel. + DEF_FormatCheck( D3DFMT_A8R8G8B8) // 32-bit ARGB pixel format with alpha, using 8 bits per channel. + DEF_FormatCheck( D3DFMT_X8R8G8B8) // 32-bit RGB pixel format, where 8 bits are reserved for each color. + DEF_FormatCheck( D3DFMT_A2B10G10R10) // 32-bit pixel format using 10 bits for each color and 2 bits for alpha. + DEF_FormatCheck( D3DFMT_A8B8G8R8) // 32-bit ARGB pixel format with alpha, using 8 bits per channel. + DEF_FormatCheck( D3DFMT_X8B8G8R8) // 32-bit RGB pixel format, where 8 bits are reserved for each color. + DEF_FormatCheck( D3DFMT_G16R16) // 32-bit pixel format using 16 bits each for green and red. + DEF_FormatCheck( D3DFMT_G16R16F) // 32-bit float format using 16 bits for the red channel and 16 bits for the green channel. + DEF_FormatCheck( D3DFMT_A2R10G10B10) // 32-bit pixel format using 10 bits each for red, green, and blue, and 2 bits for alpha. + DEF_FormatCheck( D3DFMT_D32) // 32-bit z-buffer bit depth. + DEF_FormatCheck( D3DFMT_D24S8) // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel. + DEF_FormatCheck( D3DFMT_D24X8) //32-bit z-buffer bit depth using 24 bits for the depth channel. + DEF_FormatCheck( D3DFMT_D24X4S4) // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel. + DEF_FormatCheck( D3DFMT_D32F_LOCKABLE) // A lockable format where the depth value is represented as a standard IEEE floating-point number. + DEF_FormatCheck( D3DFMT_D24FS8) // A non-lockable format that contains 24 bits of depth (in a 24-bit floating point format - 20e4) and 8 bits of stencil. + DEF_FormatCheck( D3DFMT_D32_LOCKABLE) // A lockable 32-bit depth buffer. + DEF_FormatCheck( D3DFMT_INDEX32) // 32-bit index buffer bit depth. + + DEF_FormatCheck( D3DFMT_G32R32F) // 64-bit float format using 32 bits for the red channel and 32 bits for the green channel. + DEF_FormatCheck( D3DFMT_Q16W16V16U16) // 64-bit bump-map format using 16 bits for each component. + DEF_FormatCheck( D3DFMT_A16B16G16R16) // 64-bit pixel format using 16 bits for each component. + DEF_FormatCheck( D3DFMT_A16B16G16R16F) // 64-bit float format using 16 bits for the each channel (alpha, blue, green, red). + + DEF_FormatCheck( D3DFMT_A32B32G32R32F) // 128-bit float format using 32 bits for the each channel (alpha, blue, green, red). + DEF_FormatCheck( D3DFMT_DXT2) + DEF_FormatCheck( D3DFMT_DXT3) + DEF_FormatCheck( D3DFMT_DXT4) + DEF_FormatCheck( D3DFMT_DXT5) + DEF_FormatCheck( D3DFMT_DXT1) + default: //compressed formats + { + return (false); + } + } + return (false); +} int uMod_TextureClient_DX9::MergeUpdate(void) { if (NumberOfUpdate<0) {return (RETURN_OK);} @@ -548,7 +725,7 @@ int uMod_TextureClient_DX9::MergeUpdate(void) if (to_lookup != NULL) delete [] to_lookup; - Message("uMod_TextureClient_DX9::MergeUpdate() END: %lu\n", this); + Message("uMod_TextureClient_DX9::MergeUpdate() END: %p\n", this); CheckAgainNonAdded(); return (UnlockMutex()); @@ -558,7 +735,7 @@ int uMod_TextureClient_DX9::MergeUpdate(void) int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures { - Message("uMod_TextureClient_DX9::LookUpToMod( %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this); + Message("uMod_TextureClient_DX9::LookUpToMod( %p): hash: %#llX, %p\n", pTexture, pTexture->Hash, this); if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched int index = GetIndex( pTexture->Hash, num_index_list, index_list); if (index>=0) @@ -582,12 +759,37 @@ int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DTexture9* pTexture, int n fake_Texture->Reference = index; } } + else if (BoolComputeCRC && pTexture->CRC>0) + { + index = GetIndex( pTexture->CRC, num_index_list, index_list); + if (index>=0) + { + uMod_IDirect3DTexture9 *fake_Texture; + if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret); + if (SwitchTextures( fake_Texture, pTexture)) + { + Message("uMod_TextureClient_DX9::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash); + fake_Texture->Release(); + } + else + { + IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1]; + for (int j=0; jReference = index; + } + } + } return (RETURN_OK); } int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DVolumeTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures { - Message("uMod_TextureClient_DX9::LookUpToMod( Volume %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this); + Message("uMod_TextureClient_DX9::LookUpToMod( Volume %p): hash: %#llX, %p\n", pTexture, pTexture->Hash, this); if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched int index = GetIndex( pTexture->Hash, num_index_list, index_list); if (index>=0) @@ -611,12 +813,37 @@ int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DVolumeTexture9* pTexture, fake_Texture->Reference = index; } } + else if (BoolComputeCRC && pTexture->CRC>0) + { + index = GetIndex( pTexture->CRC, num_index_list, index_list); + if (index>=0) + { + uMod_IDirect3DVolumeTexture9 *fake_Texture; + if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret); + if (SwitchTextures( fake_Texture, pTexture)) + { + Message("uMod_TextureClient_DX9::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash); + fake_Texture->Release(); + } + else + { + IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1]; + for (int j=0; jReference = index; + } + } + } return (RETURN_OK); } int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures { - Message("uMod_TextureClient_DX9::LookUpToMod( Cube %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this); + Message("uMod_TextureClient_DX9::LookUpToMod( Cube %p): hash: %#llX, %p\n", pTexture, pTexture->Hash, this); if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched int index = GetIndex( pTexture->Hash, num_index_list, index_list); if (index>=0) @@ -640,6 +867,31 @@ int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, i fake_Texture->Reference = index; } } + else if (BoolComputeCRC && pTexture->CRC>0) + { + index = GetIndex( pTexture->CRC, num_index_list, index_list); + if (index>=0) + { + uMod_IDirect3DCubeTexture9 *fake_Texture; + if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret); + if (SwitchTextures( fake_Texture, pTexture)) + { + Message("uMod_TextureClient_DX9::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash); + fake_Texture->Release(); + } + else + { + IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1]; + for (int j=0; jReference = index; + } + } + } return (RETURN_OK); } @@ -648,7 +900,7 @@ int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, i int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9 **ppTexture) // to load fake texture from a file in memory { - Message("LoadTexture( %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this); + Message("LoadTexture( %p, %p, %#llX): %p\n", file_in_memory, ppTexture, file_in_memory->Hash, this); if (D3D_OK != D3DXCreateTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DTexture9 **) ppTexture)) //if (D3D_OK != D3DXCreateTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DTexture9 **) ppTexture)) { @@ -662,13 +914,13 @@ int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice - Message("LoadTexture( %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash); + Message("LoadTexture( %p, %#llX): DONE\n", *ppTexture, file_in_memory->Hash); return (RETURN_OK); } int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9 **ppTexture) // to load fake texture from a file in memory { - Message("LoadTexture( Volume %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this); + Message("LoadTexture( Volume %p, %p, %#llX): %p\n", file_in_memory, ppTexture, file_in_memory->Hash, this); if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DVolumeTexture9 **) ppTexture)) //if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DVolumeTexture9 **) ppTexture)) { @@ -682,13 +934,13 @@ int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice - Message("LoadTexture( Volume %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash); + Message("LoadTexture( Volume %p, %#llX): DONE\n", *ppTexture, file_in_memory->Hash); return (RETURN_OK); } int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9 **ppTexture) // to load fake texture from a file in memory { - Message("LoadTexture( Cube %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this); + Message("LoadTexture( Cube %p, %p, %#llX): %p\n", file_in_memory, ppTexture, file_in_memory->Hash, this); if (D3D_OK != D3DXCreateCubeTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DCubeTexture9 **) ppTexture)) //if (D3D_OK != D3DXCreateCubeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DCubeTexture9 **) ppTexture)) { @@ -702,7 +954,7 @@ int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice - Message("LoadTexture( Cube %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash); + Message("LoadTexture( Cube %p, %#llX): DONE\n", *ppTexture, file_in_memory->Hash); return (RETURN_OK); } diff --git a/uMod_DX9/uMod_TextureClient_DX9.h b/uMod_DX9/uMod_TextureClient_DX9.h index b6912be..b1d314a 100644 --- a/uMod_DX9/uMod_TextureClient_DX9.h +++ b/uMod_DX9/uMod_TextureClient_DX9.h @@ -44,20 +44,74 @@ public: uMod_TextureClient_DX9( IDirect3DDevice9* device, const int version); virtual ~uMod_TextureClient_DX9(void); - int AddTexture( uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DDevice9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() - int AddTexture( uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() - int AddTexture( uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() + /** + * called from uMod_IDirect3DDevice9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() + * @param[in] tex texture to be added + * @return + */ + int AddTexture( uMod_IDirect3DTexture9* tex); - int RemoveTexture( uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DTexture9::Release() - int RemoveTexture( uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::Release() - int RemoveTexture( uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::Release() + /** + * called from uMod_IDirect3DVolumeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() + * @param[in] tex texture to be added + * @return + */ + int AddTexture( uMod_IDirect3DVolumeTexture9* tex); + + /** + * called from uMod_IDirect3DCubeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene() + * @param[in] tex texture to be added + * @return + */ + int AddTexture( uMod_IDirect3DCubeTexture9* tex); + + /** + * called from uMod_IDirect3DTexture9::Release() + * @param[in] tex + * @return + */ + int RemoveTexture( uMod_IDirect3DTexture9* tex); + + /** + * called from uMod_IDirect3DVolumeTexture9::Release() + * @param[in] tex + * @return + */ + int RemoveTexture( uMod_IDirect3DVolumeTexture9* tex); + + /** + * called from uMod_IDirect3DCubeTexture9::Release() + * @param[in] tex + * @return + */ + int RemoveTexture( uMod_IDirect3DCubeTexture9* tex); int SaveAllTextures(bool val); //called from the Server int SaveSingleTexture(bool val); //called from the Server - int SaveTexture(uMod_IDirect3DTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) - int SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) - int SaveTexture(uMod_IDirect3DCubeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) + /** + * called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) + * @param[in] pTexture + * @param[in] save_all true if called from AddTexture(...) -> (SaveAllTextures is true) + * @return + */ + int SaveTexture(uMod_IDirect3DTexture9* pTexture, bool save_all=false); // + + /** + * called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) + * @param[in] pTexture + * @param[in] save_all true if called from AddTexture(...) -> (SaveAllTextures is true) + * @return + */ + int SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture, bool save_all=false); + + /** + * called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures) + * @param[in] pTexture + * @param[in] save_all true if called from AddTexture(...) -> (SaveAllTextures is true) + * @return + */ + int SaveTexture(uMod_IDirect3DCubeTexture9* pTexture, bool save_all=false); int MergeUpdate(void); //called from uMod_IDirect3DDevice9::BeginScene() @@ -85,6 +139,22 @@ public: private: IDirect3DDevice9* D3D9Device; + + /** + * Save the texture into a file (reagrding the various file formats. + * @param[in] pTexture + * @param[inout] file name without trailing format extension + * @return + */ + int SaveTexture(IDirect3DBaseTexture9* pTexture, wchar_t *file); + + /** + * Return true if this texture has the right format to pass the FormatFilter and thus it is saved + * @param format + * @return + */ + bool SaveTextureFilterFormat(D3DFORMAT format); + int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9 **ppTexture); // called if a target texture is found int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9 **ppTexture); // called if a target texture is found int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9 **ppTexture); // called if a target texture is found diff --git a/uMod_DXMain/makefile.gcc b/uMod_DXMain/makefile.gcc index ec1f457..5ad02b7 100644 --- a/uMod_DXMain/makefile.gcc +++ b/uMod_DXMain/makefile.gcc @@ -19,9 +19,9 @@ endif ifdef NI ifdef LOG_MESSAGE -precompiler_flag = /D "LOG_MESSAGE" /D "NO_INJECTION" +precompiler_flag = /D "LOG_MESSAGE" /D "INJECTION_METHOD=3" else -precompiler_flag = /D "NO_INJECTION" +precompiler_flag = /D "INJECTION_METHOD=3" endif def_file = /DEF:"uMod_DX$(DX_XX_File)_dll_NO_INJECTION.def" @@ -32,9 +32,9 @@ else ifdef DI ifdef LOG_MESSAGE -precompiler_flag = /D "LOG_MESSAGE" /D "DIRECT_INJECTION" +precompiler_flag = /D "LOG_MESSAGE" /D "INJECTION_METHOD=2" else -precompiler_flag = /D "DIRECT_INJECTION" +precompiler_flag = /D "INJECTION_METHOD=2" endif def_file = /DEF:"uMod_DX$(DX_XX_File)_dll_DIRECT_INJECTION.def" @@ -44,9 +44,9 @@ dll = uMod_d3d$(DX_XX_File)_DI.dll else ifdef LOG_MESSAGE -precompiler_flag = /D "LOG_MESSAGE" /D "HOOK_INJECTION" +precompiler_flag = /D "LOG_MESSAGE" /D "INJECTION_METHOD=1" else -precompiler_flag = /D "HOOK_INJECTION" +precompiler_flag = /D "INJECTION_METHOD=1" endif def_file = /DEF:"uMod_DX$(DX_XX_File)_dll_HOOK_INJECTION.def" @@ -58,11 +58,19 @@ endif CXX = cl CLINK = link.exe -DEFINES = /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS" $(DX_XX_Flag) +DEFINES = /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS" /D "_UNICODE" "/D UNICODE" $(DX_XX_Flag) #CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 ${DEFINES} ${precompiler_flag} /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t -CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 /Oi /Oy- /GL ${DEFINES} ${precompiler_flag} /Gm- /EHsc /MT /Gy- /fp:precise /Zc:wchar_t /Zc:forScope /Gd /TP /analyze- -LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" /DLL "Winmm.lib" "d3dx9.lib" "d3dx10.lib" "dxguid.lib" "user32.lib" "Kernel32.lib" ${def_file} /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE:NO /NXCOMPAT:NO /MACHINE:X86 + +CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 /Oi /Oy- /GL \ + ${DEFINES} ${precompiler_flag} /Gm- /EHsc /MT /GS- /Gy- /fp:precise /Zc:wchar_t /Zc:forScope /Gd /TP /analyze- + +LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" \ + /DLL "Winmm.lib" "d3dx9.lib" "d3dx10.lib" "dxguid.lib" "user32.lib" "Kernel32.lib" ${def_file} /MANIFEST:NO \ + /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 + + #/nologo /W3 /WX- /O2 /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _WINDOWS /D _USRDLL /D D3DSTARTERKIT_EXPORTS /D _WINDLL /D _UNICODE /D UNICODE /Gm- /EHsc /MT /GS- /Gy- /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TP /analyze- + obj = obj bin = bin @@ -83,13 +91,13 @@ objects = \ ${obj}\uMod_IDirect3DVolumeTexture9.${obj_suff} \ ${obj}\uMod_IDirect3DCubeTexture9.${obj_suff} \ \ - ${obj}\uMod_DX10_dll.${obj_suff} - #\ - #${obj}\cpu.obj \ - #${obj}\disasm.obj \ - #${obj}\disasm_x86.obj \ - #${obj}\mhook.obj \ - #${obj}\misc.obj + ${obj}\uMod_DX10_dll.${obj_suff} \ + ${obj}\uMod_ID3D10Device.${obj_suff} \ + ${obj}\uMod_ID3D10Device1.${obj_suff} \ + ${obj}\uMod_ID3D10Texture1D.${obj_suff} \ + ${obj}\uMod_ID3D10Texture2D.${obj_suff} \ + ${obj}\uMod_ID3D10Texture3D.${obj_suff} \ + ${obj}\uMod_IDXGISwapChain.${obj_suff} headers = uMod_Main.h \ @@ -110,7 +118,13 @@ DX9_headers = \ ..\uMod_DX9\uMod_IDirect3DCubeTexture9.h DX10_headers = \ - ..\uMod_DX10\uMod_DX10_dll.h + ..\uMod_DX10\uMod_DX10_dll.h \ + ..\uMod_DX10\uMod_ID3D10Device.h \ + ..\uMod_DX10\uMod_ID3D10Device1.h \ + ..\uMod_DX10\uMod_ID3D10Texture1D.h \ + ..\uMod_DX10\uMod_ID3D10Texture2D.h \ + ..\uMod_DX10\uMod_ID3D10Texture3D.h \ + ..\uMod_DX10\uMod_IDXGISwapChain.h ${bin}\d3d9.dll: ${objects} ${CLINK} ${LFLAGS} ${objects} /OUT:${bin}\${dll} @@ -164,5 +178,23 @@ ${obj}\uMod_IDirect3DCubeTexture9.${obj_suff}: ..\uMod_DX9\uMod_IDirect3DCubeTex ${obj}\uMod_DX10_dll.${obj_suff}: ..\uMod_DX10\uMod_DX10_dll.cpp ${headers} ${DX10_headers} ${CXX} ${CFLAGS} /c $< /Fo$@ +${obj}\uMod_ID3D10Device.${obj_suff}: ..\uMod_DX10\uMod_ID3D10Device.cpp ${headers} ${DX10_headers} + ${CXX} ${CFLAGS} /c $< /Fo$@ + +${obj}\uMod_ID3D10Device1.${obj_suff}: ..\uMod_DX10\uMod_ID3D10Device1.cpp ${headers} ${DX10_headers} ..\uMod_DX10\uMod_ID3D10Device.cpp + ${CXX} ${CFLAGS} /c $< /Fo$@ + +${obj}\uMod_ID3D10Texture1D.${obj_suff}: ..\uMod_DX10\uMod_ID3D10Texture1D.cpp ${headers} ${DX10_headers} + ${CXX} ${CFLAGS} /c $< /Fo$@ + +${obj}\uMod_ID3D10Texture2D.${obj_suff}: ..\uMod_DX10\uMod_ID3D10Texture2D.cpp ${headers} ${DX10_headers} + ${CXX} ${CFLAGS} /c $< /Fo$@ + +${obj}\uMod_ID3D10Texture3D.${obj_suff}: ..\uMod_DX10\uMod_ID3D10Texture3D.cpp ${headers} ${DX10_headers} + ${CXX} ${CFLAGS} /c $< /Fo$@ + +${obj}\uMod_IDXGISwapChain.${obj_suff}: ..\uMod_DX10\uMod_IDXGISwapChain.cpp ${headers} ${DX10_headers} + ${CXX} ${CFLAGS} /c $< /Fo$@ + clean: del ${objects} ${bin}\${dll} \ No newline at end of file diff --git a/uMod_DXMain/makefile.vc b/uMod_DXMain/makefile.vc index 158175a..d1b3eba 100644 --- a/uMod_DXMain/makefile.vc +++ b/uMod_DXMain/makefile.vc @@ -1,117 +1,200 @@ -!IFDEF NI -!IFDEF LOG_MESSAGE -precompiler_flag = /D "LOG_MESSAGE" /D "NO_INJECTION" -!ELSE -precompiler_flag = /D "NO_INJECTION" -!ENDIF -def_file = /DEF:"uMod_DX9_dll_NO_INJECTION.def" +!ifdef DX10 +!ifdef DX9 +DX_XX_Flag = /D DEF_USE_DX9 /D DEF_USE_DX10 +DX_XX_File = 9_10 +!else +DX_XX_Flag = /D DEF_USE_DX10 +DX_XX_File = 10 +!endif + +!else +DX_XX_Flag = /D DEF_USE_DX9 +DX_XX_File = 9 +!endif + + + +!ifdef NI + +!ifdef LOG_MESSAGE +precompiler_flag = /D "LOG_MESSAGE" /D "INJECTION_METHOD=3" +!else +precompiler_flag = /D "INJECTION_METHOD=3" +!endif + +def_file = /DEF:"uMod_DX$(DX_XX_File)_dll_NO_INJECTION.def" obj_suff = NI.obj -dll = d3d9.dll +dll = d3d$(DX_XX_File).dll -!ELSE +!else -!IFDEF DI -!IFDEF LOG_MESSAGE -precompiler_flag = /D "LOG_MESSAGE" /D "DIRECT_INJECTION" -!ELSE -precompiler_flag = /D "DIRECT_INJECTION" -!ENDIF +!ifdef DI +!ifdef LOG_MESSAGE +precompiler_flag = /D "LOG_MESSAGE" /D "INJECTION_METHOD=2" +!else +precompiler_flag = /D "INJECTION_METHOD=2" +!endif -def_file = /DEF:"uMod_DX9_dll_DIRECT_INJECTION.def" +def_file = /DEF:"uMod_DX$(DX_XX_File)_dll_DIRECT_INJECTION.def" obj_suff = DI.obj -dll = uMod_d3d9_DI.dll +dll = uMod_d3d$(DX_XX_File)_DI.dll -!ELSE +!else -!IFDEF LOG_MESSAGE -precompiler_flag = /D "LOG_MESSAGE" /D "HOOK_INJECTION" -!ELSE -precompiler_flag = /D "HOOK_INJECTION" -!ENDIF +!ifdef LOG_MESSAGE +precompiler_flag = /D "LOG_MESSAGE" /D "INJECTION_METHOD=1" +!else +precompiler_flag = /D "INJECTION_METHOD=1" +!endif -def_file = /DEF:"uMod_DX9_dll_HOOK_INJECTION.def" +def_file = /DEF:"uMod_DX$(DX_XX_File)_dll_HOOK_INJECTION.def" obj_suff = HI.obj -dll = uMod_d3d9_HI.dll - -!ENDIF +dll = uMod_d3d$(DX_XX_File)_HI.dll +!endif +!endif CXX = cl CLINK = link.exe -DEFINES = /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS" -CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 $(DEFINES) $(precompiler_flag) /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t -LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" /DLL "Winmm.lib" "d3dx9.lib" "dxguid.lib" "user32.lib" "Kernel32.lib" $(def_file) /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE:NO /NXCOMPAT:NO /MACHINE:X86 +DEFINES = /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS" /D "_UNICODE" "/D UNICODE" $(DX_XX_Flag) +#CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 $(DEFINES) $(precompiler_flag) /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t + +CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 /Oi /Oy- /GL \ + $(DEFINES) $(precompiler_flag) /Gm- /EHsc /MT /GS- /Gy- /fp:precise /Zc:wchar_t /Zc:forScope /Gd /TP /analyze- + +LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" \ + /DLL "Winmm.lib" "d3dx9.lib" "d3dx10.lib" "dxguid.lib" "user32.lib" "Kernel32.lib" $(def_file) /MANIFEST:NO \ + /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 + + + #/nologo /W3 /WX- /O2 /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _WINDOWS /D _USRDLL /D D3DSTARTERKIT_EXPORTS /D _WINDLL /D _UNICODE /D UNICODE /Gm- /EHsc /MT /GS- /Gy- /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TP /analyze- obj = obj bin = bin -objects = $(obj)\uMod_DX9_dll.$(obj_suff) \ +objects = \ + $(obj)\uMod_TextureFunction.$(DX_XX_File).$(obj_suff) \ + $(obj)\uMod_ArrayHandler.$(DX_XX_File).$(obj_suff) \ + $(obj)\uMod_TextureClient.$(DX_XX_File).$(obj_suff) \ + $(obj)\uMod_TextureServer.$(DX_XX_File).$(obj_suff) \ + $(obj)\uMod_DXMain_dll.$(DX_XX_File).$(obj_suff) \ + \ + $(obj)\uMod_DX9_dll.$(obj_suff) \ + $(obj)\uMod_TextureClient_DX9.$(obj_suff) \ $(obj)\uMod_IDirect3D9.$(obj_suff) \ $(obj)\uMod_IDirect3D9Ex.$(obj_suff) \ $(obj)\uMod_IDirect3DDevice9.$(obj_suff) \ $(obj)\uMod_IDirect3DDevice9Ex.$(obj_suff) \ - $(obj)\uMod_TextureFunction.$(obj_suff) \ $(obj)\uMod_IDirect3DTexture9.$(obj_suff) \ $(obj)\uMod_IDirect3DVolumeTexture9.$(obj_suff) \ $(obj)\uMod_IDirect3DCubeTexture9.$(obj_suff) \ - $(obj)\uMod_ArrayHandler.$(obj_suff) \ - $(obj)\uMod_TextureClient.$(obj_suff) \ - $(obj)\uMod_TextureServer.$(obj_suff) + \ + $(obj)\uMod_DX10_dll.$(obj_suff) \ + $(obj)\uMod_ID3D10Device.$(obj_suff) \ + $(obj)\uMod_ID3D10Device1.$(obj_suff) \ + $(obj)\uMod_ID3D10Texture1D.$(obj_suff) \ + $(obj)\uMod_ID3D10Texture2D.$(obj_suff) \ + $(obj)\uMod_ID3D10Texture3D.$(obj_suff) \ + $(obj)\uMod_IDXGISwapChain.$(obj_suff) + headers = uMod_Main.h \ + uMod_DXMain_dll.h \ uMod_Defines.h \ - uMod_DX9_dll.h \ - uMod_IDirect3D9.h \ - uMod_IDirect3DDevice9.h \ uMod_TextureFunction.h \ - uMod_IDirect3DTexture9.h \ - uMod_IDirect3DVolumeTexture9.h \ - uMod_IDirect3DCubeTexture9.h \ uMod_ArrayHandler.h \ uMod_TextureClient.h \ uMod_TextureServer.h + +DX9_headers = \ + ..\uMod_DX9\uMod_DX9_dll.h \ + ..\uMod_DX9\uMod_TextureClient_DX9.h \ + ..\uMod_DX9\uMod_IDirect3D9.h \ + ..\uMod_DX9\uMod_IDirect3DDevice9.h \ + ..\uMod_DX9\uMod_IDirect3DTexture9.h \ + ..\uMod_DX9\uMod_IDirect3DVolumeTexture9.h \ + ..\uMod_DX9\uMod_IDirect3DCubeTexture9.h + +DX10_headers = \ + ..\uMod_DX10\uMod_DX10_dll.h \ + ..\uMod_DX10\uMod_ID3D10Device.h \ + ..\uMod_DX10\uMod_ID3D10Device1.h \ + ..\uMod_DX10\uMod_ID3D10Texture1D.h \ + ..\uMod_DX10\uMod_ID3D10Texture2D.h \ + ..\uMod_DX10\uMod_ID3D10Texture3D.h \ + ..\uMod_DX10\uMod_IDXGISwapChain.h $(bin)\d3d9.dll: $(objects) $(CLINK) $(LFLAGS) $(objects) /OUT:$(bin)\$(dll) copy $(bin)\$(dll) ..\uMod_GUI\bin\$(dll) -$(obj)\uMod_DX9_dll.$(obj_suff): uMod_DX9_dll.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_DX9_dll.cpp - -$(obj)\uMod_IDirect3D9.$(obj_suff): uMod_IDirect3D9.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3D9.cpp - -$(obj)\uMod_IDirect3D9Ex.$(obj_suff): uMod_IDirect3D9Ex.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3D9Ex.cpp - -$(obj)\uMod_IDirect3DDevice9.$(obj_suff): uMod_IDirect3DDevice9.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DDevice9.cpp - -$(obj)\uMod_IDirect3DDevice9Ex.$(obj_suff): uMod_IDirect3DDevice9Ex.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DDevice9Ex.cpp - -$(obj)\uMod_TextureFunction.$(obj_suff): uMod_TextureFunction.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_TextureFunction.cpp - -$(obj)\uMod_IDirect3DTexture9.$(obj_suff): uMod_IDirect3DTexture9.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DTexture9.cpp - -$(obj)\uMod_IDirect3DVolumeTexture9.$(obj_suff): uMod_IDirect3DVolumeTexture9.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DVolumeTexture9.cpp - -$(obj)\uMod_IDirect3DCubeTexture9.$(obj_suff): uMod_IDirect3DCubeTexture9.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_IDirect3DCubeTexture9.cpp - -$(obj)\uMod_ArrayHandler.$(obj_suff): uMod_ArrayHandler.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_ArrayHandler.cpp - -$(obj)\uMod_TextureClient.$(obj_suff): uMod_TextureClient.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_TextureClient.cpp - -$(obj)\uMod_TextureServer.$(obj_suff): uMod_TextureServer.cpp $(headers) - $(CXX) $(CFLAGS) /c /Fo$@ uMod_TextureServer.cpp + +$(obj)\uMod_DXMain_dll.$(DX_XX_File).$(obj_suff): uMod_DXMain_dll.cpp $(headers) + $(CXX) $(CFLAGS) /c uMod_DXMain_dll.cpp /Fo$@ + +$(obj)\uMod_ArrayHandler.$(DX_XX_File).$(obj_suff): uMod_ArrayHandler.cpp $(headers) + $(CXX) $(CFLAGS) /c uMod_ArrayHandler.cpp /Fo$@ + +$(obj)\uMod_TextureClient.$(DX_XX_File).$(obj_suff): uMod_TextureClient.cpp $(headers) + $(CXX) $(CFLAGS) /c uMod_TextureClient.cpp /Fo$@ + +$(obj)\uMod_TextureServer.$(DX_XX_File).$(obj_suff): uMod_TextureServer.cpp $(headers) + $(CXX) $(CFLAGS) /c uMod_TextureServer.cpp /Fo$@ + +$(obj)\uMod_TextureFunction.$(DX_XX_File).$(obj_suff): uMod_TextureFunction.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c uMod_TextureFunction.cpp /Fo$@ + + +$(obj)\uMod_DX9_dll.$(obj_suff): ..\uMod_DX9\uMod_DX9_dll.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_DX9_dll.cpp /Fo$@ + +$(obj)\uMod_TextureClient_DX9.$(obj_suff): ..\uMod_DX9\uMod_TextureClient_DX9.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_TextureClient_DX9.cpp /Fo$@ + +$(obj)\uMod_IDirect3D9.$(obj_suff): ..\uMod_DX9\uMod_IDirect3D9.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_IDirect3D9.cpp /Fo$@ + +$(obj)\uMod_IDirect3D9Ex.$(obj_suff): ..\uMod_DX9\uMod_IDirect3D9Ex.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_IDirect3D9Ex.cpp /Fo$@ + +$(obj)\uMod_IDirect3DDevice9.$(obj_suff): ..\uMod_DX9\uMod_IDirect3DDevice9.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_IDirect3DDevice9.cpp /Fo$@ + +$(obj)\uMod_IDirect3DDevice9Ex.$(obj_suff): ..\uMod_DX9\uMod_IDirect3DDevice9Ex.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_IDirect3DDevice9Ex.cpp /Fo$@ + +$(obj)\uMod_IDirect3DTexture9.$(obj_suff): ..\uMod_DX9\uMod_IDirect3DTexture9.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_IDirect3DTexture9.cpp /Fo$@ + +$(obj)\uMod_IDirect3DVolumeTexture9.$(obj_suff): ..\uMod_DX9\uMod_IDirect3DVolumeTexture9.cpp $(headers) $(DX9_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_IDirect3DVolumeTexture9.cpp /Fo$@ + +$(obj)\uMod_IDirect3DCubeTexture9.$(obj_suff): ..\uMod_DX9\uMod_IDirect3DCubeTexture9.cpp $(headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX9\uMod_IDirect3DCubeTexture9.cpp /Fo$@ + + +$(obj)\uMod_DX10_dll.$(obj_suff): ..\uMod_DX10\uMod_DX10_dll.cpp $(headers) $(DX10_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX10\uMod_DX10_dll.cpp /Fo$@ + +$(obj)\uMod_ID3D10Device.$(obj_suff): ..\uMod_DX10\uMod_ID3D10Device.cpp $(headers) $(DX10_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX10\uMod_ID3D10Device.cpp /Fo$@ + +$(obj)\uMod_ID3D10Device1.$(obj_suff): ..\uMod_DX10\uMod_ID3D10Device1.cpp $(headers) $(DX10_headers) ..\uMod_DX10\uMod_ID3D10Device.cpp + $(CXX) $(CFLAGS) /c ..\uMod_DX10\uMod_ID3D10Device1.cpp /Fo$@ + +$(obj)\uMod_ID3D10Texture1D.$(obj_suff): ..\uMod_DX10\uMod_ID3D10Texture1D.cpp $(headers) $(DX10_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX10\uMod_ID3D10Texture1D.cpp /Fo$@ + +$(obj)\uMod_ID3D10Texture2D.$(obj_suff): ..\uMod_DX10\uMod_ID3D10Texture2D.cpp $(headers) $(DX10_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX10\uMod_ID3D10Texture2D.cpp /Fo$@ + +$(obj)\uMod_ID3D10Texture3D.$(obj_suff): ..\uMod_DX10\uMod_ID3D10Texture3D.cpp $(headers) $(DX10_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX10\uMod_ID3D10Texture3D.cpp /Fo$@ + +$(obj)\uMod_IDXGISwapChain.$(obj_suff): ..\uMod_DX10\uMod_IDXGISwapChain.cpp $(headers) $(DX10_headers) + $(CXX) $(CFLAGS) /c ..\uMod_DX10\uMod_IDXGISwapChain.cpp /Fo$@ clean: del $(objects) $(bin)\$(dll) \ No newline at end of file diff --git a/uMod_DXMain/uMod_ArrayHandler.h b/uMod_DXMain/uMod_ArrayHandler.h index aa2a1db..7baebe2 100644 --- a/uMod_DXMain/uMod_ArrayHandler.h +++ b/uMod_DXMain/uMod_ArrayHandler.h @@ -23,61 +23,66 @@ along with Universal Modding Engine. If not, see #include "..\uMod_GlobalDefines.h" - +/** + * On entry hold the pointer to the fake texture data (file content) + * and the pointer to all game texture which are replaced by this texture. + */ typedef struct { - bool ForceReload; // to force a reload of the texture (if it is already modded) - char* pData; // store texture file as file in memory - unsigned int Size; // size of file - int NumberOfTextures; - int Reference; // for a fast delete in the FileHandler - void **Textures; // pointer to the fake textures - MyTypeHash Hash; // hash value + bool ForceReload; //!< to force a reload of the texture (only important, if it is already modded) + char* pData; //!< store texture file as file in memory + unsigned int Size; //!< size of file (\a pData) + int NumberOfTextures; //!< Number of textures loaded by the game, which match the hash and thus are switched + int Reference; //!< for a fast delete in the FileHandler + void **Textures; //!< pointer to all texture loade by the game, which match the hash and thus are switched + DWORD64 Hash; //!< hash value } TextureFileStruct; -/* - -class uMod_FileHandler // array to store TextureFileStruct -{ -public: - uMod_FileHandler(void); - ~uMod_FileHandler(void); - - int Add( TextureFileStruct* file); - int Remove( TextureFileStruct* file); - - int GetNumber(void) {return (Number);} - - TextureFileStruct *operator [] (int i) {if (i<0||i>=Number) return (NULL); else return (Files[i/FieldLength][i%FieldLength]);} - -protected: - static const int FieldLength = 1024; - long Number; - int FieldCounter; - TextureFileStruct*** Files; -}; -*/ - +/** + * A simple vector class for pointers. The Object or struct must have a member variable \a int \a Reference. + * This class stores the entries in chunks of memory. The address of each chunk is stored in \a Content. + */ template -class uMod_TextureHandler // array to store uMod_IDirect3DTexture9, uMod_IDirect3DVolumeTexture9 or uMod_IDirect3DCubeTexture9 +class uMod_TextureHandler { public: uMod_TextureHandler(void); ~uMod_TextureHandler(void); - int Add( T* texture); - int Remove( T* texture); + /** + * Append an entry at the end of the vector + * @param entry + * @return RETURN_OK on success + */ + int Add( T* entry); + /** + * Remove this entry from the vector + * @param entry + * @return RETURN_OK on success + */ + int Remove( T* entry); + + /** + * Returns the number of entries. + * @return + */ int GetNumber(void) {return (Number);} - T *operator [] (int i) {if (i<0||i>=Number) return (NULL); else return (Textures[i/FieldLength][i%FieldLength]);} + + /** + * Return the pointer to the \a i the object + * @param i index + * @return + */ + T *operator [] (int i) {if (i<0||i>=Number) return (NULL); else return (Content[i/FieldLength][i%FieldLength]);} private: - static const int FieldLength = 1024; - long Number; - int FieldCounter; - T*** Textures; + static const int FieldLength = 1024; //!< size of one chunk of memory + long Number; //!< Number of entries. + int FieldCounter; //!< Number of allocated chunks. + T*** Content;//!< vector of pointers, which point to the chunks }; @@ -100,27 +105,27 @@ uMod_TextureHandler::uMod_TextureHandler(void) Number = 0; FieldCounter = 0; - Textures = NULL; + Content = NULL; } template uMod_TextureHandler::~uMod_TextureHandler(void) { Message("~uMod_TextureHandler(void): %lu\n", this); - if (Textures!=NULL) + if (Content!=NULL) { - for (int i=0; i -int uMod_TextureHandler::Add(T* pTexture) +int uMod_TextureHandler::Add(T* entry) { - Message("uMod_TextureHandler::Add( %lu): %lu\n", pTexture, this); + Message("uMod_TextureHandler::Add( %lu): %lu\n", entry, this); if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR); - if (pTexture->Reference>=0) return (RETURN_TEXTURE_ALLREADY_ADDED); + if (entry->Reference>=0) return (RETURN_TEXTURE_ALLREADY_ADDED); if (Number/FieldLength==FieldCounter) { @@ -132,50 +137,50 @@ int uMod_TextureHandler::Add(T* pTexture) return (RETURN_NO_MEMORY); } - for (int i=0; iReference = Number++; + Content[Number/FieldLength][Number%FieldLength] = entry; + entry->Reference = Number++; return (RETURN_OK); } template -int uMod_TextureHandler::Remove(T* pTexture) //will be called, if a texture is completely released +int uMod_TextureHandler::Remove(T* entry) //will be called, if a texture is completely released { - Message("uMod_TextureHandler::Remove( %lu): %lu\n", pTexture, this); + Message("uMod_TextureHandler::Remove( %lu): %lu\n", entry, this); if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR); - int ref = pTexture->Reference; + int ref = entry->Reference; if (ref<0|| ref>=Number) return (RETURN_OK); // it is not in this list - if (Textures[ref/FieldLength][ref%FieldLength]!=pTexture) return (RETURN_OK); // it is not in this list + if (Content[ref/FieldLength][ref%FieldLength]!=entry) return (RETURN_OK); // it is not in this list if (ref<(--Number)) { - Textures[ref/FieldLength][ref%FieldLength] = Textures[Number/FieldLength][Number%FieldLength]; - Textures[ref/FieldLength][ref%FieldLength]->Reference = ref; + Content[ref/FieldLength][ref%FieldLength] = Content[Number/FieldLength][Number%FieldLength]; + Content[ref/FieldLength][ref%FieldLength]->Reference = ref; } - pTexture->Reference = -1; + entry->Reference = -1; return (RETURN_OK); } diff --git a/uMod_DXMain/uMod_DX10_dll_DIRECT_INJECTION.def b/uMod_DXMain/uMod_DX10_dll_DIRECT_INJECTION.def new file mode 100644 index 0000000..b81e974 --- /dev/null +++ b/uMod_DXMain/uMod_DX10_dll_DIRECT_INJECTION.def @@ -0,0 +1,5 @@ +LIBRARY "uMod_d3d10_DI" +EXPORTS + uMod_D3D10CreateDeviceAndSwapChain @1 + uMod_D3D10CreateDeviceAndSwapChain1 @2 + Nothing @3 \ No newline at end of file diff --git a/uMod_DXMain/uMod_DXMain_dll.cpp b/uMod_DXMain/uMod_DXMain_dll.cpp index c9eec1d..c025d55 100644 --- a/uMod_DXMain/uMod_DXMain_dll.cpp +++ b/uMod_DXMain/uMod_DXMain_dll.cpp @@ -24,16 +24,13 @@ along with Universal Modding Engine. If not, see */ +#ifdef __CDT_PARSER__ +#define INJECTION_METHOD 0 +#endif + + #include "uMod_Main.h" - -//#include "detours.h" -//#include "detourxs/detourxs/detourxs.h" - -/* -#include "detourxs/detourxs/ADE32.cpp" -#include "detourxs/detourxs/detourxs.cpp" -*/ /* * global variable which are not linked external */ @@ -52,10 +49,11 @@ unsigned int gl_ErrorState = 0u; FILE* gl_File = NULL; #endif - -#ifdef DIRECT_INJECTION +#if INJECTION_METHOD == DIRECT_INJECTION void Nothing(void) {(void)NULL;} #endif + + /* * dll entry routine, here we initialize or clean up */ @@ -96,11 +94,11 @@ void InitInstance(HINSTANCE hModule) gl_hThisInstance = (HINSTANCE) hModule; - wchar_t game[MAX_PATH]; - if (HookThisProgram( game, MAX_PATH)) //ask if we need to hook this program + wchar_t game[10*MAX_PATH]; + if (HookThisProgram( game, 10*MAX_PATH)) //ask if we need to hook this program { OpenMessage(); - Message("InitInstance: %lu\n", hModule); + Message("InitInstance: %lu (%ls)\n", hModule, game); gl_TextureServer = new uMod_TextureServer(game); //create the server which listen on the pipe and prepare the update for the texture clients @@ -112,7 +110,7 @@ void InitInstance(HINSTANCE hModule) #endif - if (gl_TextureServer->OpenPipe(game)) //open the pipe and send the name+path of this executable + if (gl_TextureServer->OpenPipe(game, INJECTION_METHOD)) //open the pipe and send the name+path of this executable { Message("InitInstance: Pipe not opened\n"); return; @@ -152,27 +150,35 @@ void ExitInstance() } - bool HookThisProgram( wchar_t *ret, const int ret_len) { - const unsigned int max_len = ret_len < MAX_PATH ? MAX_PATH : ret_len; + const int max_len = ret_len < MAX_PATH ? MAX_PATH : ret_len; wchar_t *Executable = NULL; - wchar_t *Game = NULL; if (GetMemory( Executable, max_len)) { ret[0]=0; return false; } + GetModuleFileNameW( GetModuleHandle( NULL ), Executable, max_len ); //ask for name and path of this executable + +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==NO_INJECTION + // we inject directly + int i=0; + while (i #include "../uMod_DX10/uMod_DX10_dll.h" #endif +/** + * This function is called during the dll load sequence (dll entry) + * @param[in] hModule + */ void InitInstance(HINSTANCE hModule); + +/** + * This function is called, when the dll gets unloaded. + */ void ExitInstance(void); +/** + * Returns true if this game shall be injected (DirectX hook). It returns also the name and path of the game executable. + * This function always return true, when compiled for "Direct Injection" of for "No Injection". + * @param[out] ret buffer where the name and path of the game executable should be stored + * @param[in] max_len length of the buffer + * @return + */ bool HookThisProgram( wchar_t *ret, const int max_len); + +/** + * This function is called, when the server thread is created. It only calls the mainloop function of the \a TextureServer. + * @param[in] lpParam Pointer to the \a TextureServer. + */ DWORD WINAPI ServerThread( LPVOID lpParam); -#ifndef NO_INJECTION - +#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION +/** + * Detour a function to another function. + * @param[in] src pointer to function which shall be detoured + * @param[in] dst pointer to function which shall be called instead + * @param[in] len number of byte to be stored + * @return trampoline = pointer to detoured function + */ void *DetourFunc(BYTE *src, const BYTE *dst, const int len); + +/** + * Retour the function. + * @param src pointer to the detoured function + * @param restore trampoline = pointer to the detoured function + * @param len number of saved bytes + * @return + */ bool RetourFunc(BYTE *src, BYTE *restore, const int len); +#endif -#ifdef HOOK_INJECTION +#if INJECTION_METHOD==HOOK_INJECTION +/** + * This function is insert into the hook. + */ LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam); +/** + * This function install the hook, our dll will be loaded into each running process (if we have sufficient permission). + */ void InstallHook(void); +/** + * This function remove the hook, our dll will get unloaded from each process. + */ void RemoveHook(void); #endif -#ifdef DIRECT_INJECTION +#if INJECTION_METHOD==DIRECT_INJECTION +/** + * Dummy function need for the "Direct Injection" mehtod. + */ void Nothing(void); #endif -#endif #endif diff --git a/uMod_DXMain/uMod_Defines.h b/uMod_DXMain/uMod_Defines.h index 2f54104..d6c0229 100644 --- a/uMod_DXMain/uMod_Defines.h +++ b/uMod_DXMain/uMod_Defines.h @@ -26,15 +26,15 @@ along with Universal Modding Engine. If not, see extern FILE *gl_File; #define Message(...) {if (gl_File!=NULL) {fprintf( gl_File, __VA_ARGS__); fflush(gl_File);}} -#ifdef HOOK_INJECTION +#if INJECTION_METHOD == HOOK_INJECTION #define OpenMessage(...) {if (fopen_s( &gl_File, "uMod_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "HI R40: 0000002\n");} #endif -#ifdef DIRECT_INJECTION +#if INJECTION_METHOD == DIRECT_INJECTION #define OpenMessage(...) {if (fopen_s( &gl_File, "uMod_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "DI R40: 0000002\n");} #endif -#ifdef NO_INJECTION +#if INJECTION_METHOD == NO_INJECTION #define OpenMessage(...) {if (fopen_s( &gl_File, "uMod_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "NI R40: 0000002\n");} #endif @@ -42,8 +42,17 @@ extern FILE *gl_File; #else +/** + * Open the file for logging (if LOG_MESSAGE=1 was passed during compilation) + */ #define OpenMessage(...) +/** + * Print a message (like printf) into the file ant flush the content to disk (if LOG_MESSAGE=1 was passed during compilation) + */ #define Message(...) +/** + * Close the file for logging (if LOG_MESSAGE=1 was passed during compilation) + */ #define CloseMessage(...) #endif diff --git a/uMod_DXMain/uMod_Main.h b/uMod_DXMain/uMod_Main.h index d4babe3..1c44994 100644 --- a/uMod_DXMain/uMod_Main.h +++ b/uMod_DXMain/uMod_Main.h @@ -50,28 +50,30 @@ along with Universal Modding Engine. If not, see #include "uMod_Defines.h" #include "uMod_DXMain_dll.h" -//#include "uMod_TextureFunction.h" -/* -#include "uMod_IDirect3D9.h" -#include "uMod_IDirect3D9Ex.h" - -#include "uMod_IDirect3DDevice9.h" -#include "uMod_IDirect3DDevice9Ex.h" - -#include "uMod_IDirect3DCubeTexture9.h" -#include "uMod_IDirect3DTexture9.h" -#include "uMod_IDirect3DVolumeTexture9.h" -*/ #include "uMod_ArrayHandler.h" #include "uMod_TextureServer.h" #include "uMod_TextureClient.h" - +/** + * global variable: HINSTANCE + */ extern HINSTANCE gl_hThisInstance; + +/** + * gloabal variable: pointer to TextureServer + */ extern uMod_TextureServer* gl_TextureServer; + +/** + * gloabal variable: pointer to the server thread + */ extern HANDLE gl_ServerThread; + +/** + * gloabal variable: error state. This is not supported at the moment. + */ extern unsigned int gl_ErrorState; #endif diff --git a/uMod_DXMain/uMod_TextureClient.cpp b/uMod_DXMain/uMod_TextureClient.cpp index 1b76330..47dff12 100644 --- a/uMod_DXMain/uMod_TextureClient.cpp +++ b/uMod_DXMain/uMod_TextureClient.cpp @@ -27,6 +27,9 @@ uMod_TextureClient::uMod_TextureClient(const int version) : Version(version) Server = NULL; BoolSaveAllTextures = false; BoolSaveSingleTexture = false; + BoolShowTextureString = false; + BoolComputeCRC = false; + KeyBack = 0; KeySave = 0; KeyNext = 0; @@ -42,6 +45,14 @@ uMod_TextureClient::uMod_TextureClient(const int version) : Version(version) NumberOfUpdate = -1; FontColour = D3DCOLOR_ARGB(255,255,0,0); TextureColour = D3DCOLOR_ARGB(255,0,255,0); + + WidthFilter = 0u; + HeightFilter = 0u; + DepthFilter = 0u; + + FormatFilter = 0u; + + FileFormat = uMod_D3DXIFF_DDS; } uMod_TextureClient::~uMod_TextureClient(void) @@ -135,7 +146,7 @@ int uMod_TextureClient::UnlockMutex(void) } -int uMod_TextureClient::GetIndex( MyTypeHash hash, int num_index_list, int *index_list) +int uMod_TextureClient::GetIndex( DWORD64 hash, int num_index_list, int *index_list) { if(NumberToMod>0) { diff --git a/uMod_DXMain/uMod_TextureClient.h b/uMod_DXMain/uMod_TextureClient.h index 499536f..8a86acc 100644 --- a/uMod_DXMain/uMod_TextureClient.h +++ b/uMod_DXMain/uMod_TextureClient.h @@ -29,7 +29,7 @@ along with Universal Modding Engine. If not, see class uMod_TextureServer; -/* +/** * An object of this class is owned by each d3dXX device. * functions called by the Server are called from the server thread instance. * All other functions are called from the render thread instance of the game itself. @@ -61,6 +61,21 @@ public: */ virtual int SaveSingleTexture(bool val) = 0; + + /** + * Enable/Disable the string in the left upper corner during save single texture mode (called from the mainloop). + * @param[in] val + * @return + */ + int ShowTextureString(bool val) {BoolShowTextureString = val; return (RETURN_OK);} + + /** + * Enable/Disable the hashing with CRC32, which is needed to support also tpf mods (called from the mainloop). + * @param[in] val + * @return + */ + int SupportTPF(bool val) {BoolComputeCRC = val; return (RETURN_OK);} + /** * Set the directory, wher the texture should be stored (called from the server) * @param dir @@ -96,21 +111,47 @@ public: /** * Set the font color "during save single" texture mode. (called from the server) - * @param r red value (0..255) - * @param g green value (0..255) - * @param b blue value (0..255) + * @param colour * @return */ - int SetFontColour( DWORD r, DWORD g, DWORD b) {FontColour = D3DCOLOR_ARGB(255, r,g,b); return (RETURN_OK);} + int SetFontColour( DWORD64 colour) {FontColour = (D3DCOLOR) colour; return (RETURN_OK);} + /** * Set the texture color "during save single" texture mode. (called from the server) - * @param r red value (0..255) - * @param g green value (0..255) - * @param b blue value (0..255) + * @param colour * @return RETURN_OK */ - int SetTextureColour( DWORD r, DWORD g, DWORD b) {TextureColour = D3DCOLOR_ARGB(255, r,g,b); return (RETURN_OK);} + int SetTextureColour( DWORD64 colour) {TextureColour = (D3DCOLOR) colour; return (RETURN_OK);} + /** + * @param[in] format + * @return + */ + int SetFileFormat(DWORD64 format) {FileFormat = format; return (RETURN_OK);} + + /** + * @param[in] format + * @return + */ + int SetFormatFilter(DWORD64 format) {FormatFilter = format; return (RETURN_OK);} + + /** + * @param[in] size + * @return + */ + int SetWidthFilter(DWORD64 size) {WidthFilter = size; return (RETURN_OK);} + + /** + * @param[in] size + * @return + */ + int SetHeightFilter(DWORD64 size) {HeightFilter = size; return (RETURN_OK);} + + /** + * @param[in] size + * @return + */ + int SetDepthFilter(DWORD64 size) {DepthFilter = size; return (RETURN_OK);} /** * The server add an update to the client.(called from server) @@ -128,23 +169,32 @@ public: virtual int MergeUpdate(void) = 0; - bool BoolSaveAllTextures; //< true if all textures should be saved - bool BoolSaveSingleTexture; //< true if "save single texture" mode is enabled - int KeyBack; //< key value for going to the previous texture - int KeySave; //< key value for saving the current texture - int KeyNext; //< key value for going to the next texture + bool BoolSaveAllTextures; //!< true if all textures should be saved + bool BoolSaveSingleTexture; //!< true if "save single texture" mode is enabled + bool BoolShowTextureString; //!< true if a string should be displayed during "save single texture" mode is enabled + bool BoolComputeCRC; //!< if true also the crc32 is calculated, which is need to support tpf - D3DCOLOR FontColour; //< color of the message ("save single texture" mode) - D3DCOLOR TextureColour; //< color of the texture ("save single texture" mode) + int KeyBack; //!< key value for going to the previous texture + int KeySave; //!< key value for saving the current texture + int KeyNext; //!< key value for going to the next texture + D3DCOLOR FontColour; //!< color of the message ("save single texture" mode) + D3DCOLOR TextureColour; //!< color of the texture ("save single texture" mode) + + + DWORD64 FileFormat; //!< file format to which the texture should be saved + DWORD64 FormatFilter; //!< texture format which should be saved (all==0, else bitwise 1=save,0=don't save) + DWORD64 WidthFilter; //!< filter min<<32 max, texture size must be min<=size<=max + DWORD64 HeightFilter; //!< filter min<<32 max, texture size must be min<=size<=max + DWORD64 DepthFilter; //!< filter min<<32 max, texture size must be min<=size<=max const int Version; - uMod_TextureServer* Server; //< Pointer to the server - wchar_t SavePath[MAX_PATH]; //< saving directory - wchar_t GameName[MAX_PATH]; //< game name + uMod_TextureServer* Server; //!< Pointer to the server + wchar_t SavePath[MAX_PATH]; //!< saving directory + wchar_t GameName[MAX_PATH]; //!< game name - TextureFileStruct* Update; //< array which stores the file in memory and the hash of each texture to be modded - int NumberOfUpdate; //< number of texture to be modded + TextureFileStruct* Update; //!< array which stores the file in memory and the hash of each texture to be modded + int NumberOfUpdate; //!< number of texture to be modded /** * Lock the mutex. The mutex protect the AddUpdate and MergeUpdate function to be called simultaneously. @@ -156,12 +206,19 @@ public: * @return RETURN_OK on success */ int UnlockMutex(); - HANDLE Mutex; //< The mutex protect the AddUpdate and MergeUpdate function to be called simultaneously. + HANDLE Mutex; //!< The mutex protect the AddUpdate and MergeUpdate function to be called simultaneously. - int NumberToMod; //< number of texture to be modded - TextureFileStruct* FileToMod; //< array which stores the file in memory and the hash of each texture to be modded + int NumberToMod; //!< number of texture to be modded + TextureFileStruct* FileToMod; //!< array which stores the file in memory and the hash of each texture to be modded - int GetIndex( MyTypeHash hash, int num_index_list=0, int *index_list=(int*)0); // called from LookUpToMod(...); + /** + * Find the given hash value in the \a FileToMod list. A vector with index can be passed. If so, only these index are considered in the search + * @param hash hash value + * @param num_index_list number of index vector + * @param index_list pointer to the index vector + * @return index or a negative value if the hash value was not found + */ + int GetIndex( DWORD64 hash, int num_index_list=0, int *index_list=(int*)0); // called from LookUpToMod(...); }; diff --git a/uMod_DXMain/uMod_TextureFunction.cpp b/uMod_DXMain/uMod_TextureFunction.cpp index 24a009a..8398f14 100644 --- a/uMod_DXMain/uMod_TextureFunction.cpp +++ b/uMod_DXMain/uMod_TextureFunction.cpp @@ -19,14 +19,23 @@ along with Universal Modding Engine. If not, see #include "uMod_Main.h" -/* -MyTypeHash GetHash(unsigned char *str, int len) // estimate the hash + +void GetHash( unsigned char *str, unsigned int len, DWORD64 &hash) // estimate the hash { - MyTypeHash hash = 0; - for (int i=0; i>32 & 0xFFFFFFFF; + + for (int i=0; i #define uMod_TEXTUREFUNCTION_H_ -unsigned int GetCRC32( char *pcDatabuf, unsigned int ulDatalen); + +// this value is simply the init value for the D.J. Bernsteins algorithm (djb2) +#define HASH_INIT_VALUE 5381 + +/** + * This hash function combines the djb2 and sdbm algorithm. Both are designed for hashing strings, + * but compared to many others they don't include a Hash*data[i] operation, which would reset the hash + * if data[i]==0. This is never the case while hashing text, but it is very often the case when hashing + * textures. Therefore many good algorithm cannot be used at this point. + * + * Here are two algorithm used to reduce the number of collision (collision == two different textures have + * the same hash value) + * + * @param[in] data pointer to the buffer + * @param[in] len length of buffer in bytes + * @param[in,out] hash in = initial value of the hash; out = returned hash + */ +void GetHash( unsigned char *str, unsigned int len, DWORD64 &hash); // estimate the hash + + +/** + * Caluclate the CRC32 value over a buffer. This function is used in texmod. Thanks to RS for given me this information! + * @param[in] data pointer to the buffer + * @param[in] len length of buffer in bytes + * @return CRC32 value + */ +DWORD32 GetCRC32( char *data, unsigned int len); /* case D3DFMT_MULTI2_ARGB8: case D3DFMT_VERTEXDATA: */ + +/** + * Returns the number of bits used per pixel. + * @param[in] format DX format. + * @return + */ inline int GetBitsFromFormat(D3DFORMAT format) { switch(format) //switch trough the formats to calculate the size of the raw data diff --git a/uMod_DXMain/uMod_TextureServer.cpp b/uMod_DXMain/uMod_TextureServer.cpp index 205d323..bd0abbc 100644 --- a/uMod_DXMain/uMod_TextureServer.cpp +++ b/uMod_DXMain/uMod_TextureServer.cpp @@ -31,6 +31,9 @@ uMod_TextureServer::uMod_TextureServer(wchar_t *game) LenghtOfClients = 0; BoolSaveAllTextures = false; BoolSaveSingleTexture = false; + BoolShowTextureString = false; + BoolSupportTPF = false; + SavePath[0] = 0; int len=0; @@ -54,8 +57,16 @@ uMod_TextureServer::uMod_TextureServer(wchar_t *game) KeySave = 0; KeyNext = 0; - FontColour = 0u; - TextureColour = 0u; + WidthFilter = 0u; + HeightFilter = 0u; + DepthFilter = 0u; + + FormatFilter = 0u; + + FileFormat = uMod_D3DXIFF_DDS; + + FontColour = D3DCOLOR_ARGB(255,255,0,0); + TextureColour = D3DCOLOR_ARGB(255,0,255,0); Pipe.In = INVALID_HANDLE_VALUE; Pipe.Out = INVALID_HANDLE_VALUE; @@ -94,27 +105,24 @@ int uMod_TextureServer::AddClient(uMod_TextureClient *client, TextureFileStruct* client->SetGameName(GameName); client->SaveAllTextures(BoolSaveAllTextures); client->SaveSingleTexture(BoolSaveSingleTexture); + client->ShowTextureString(BoolShowTextureString); + client->SupportTPF(BoolSupportTPF); client->SetSaveDirectory(SavePath); - if (KeyBack > 0) client->SetKeyBack(KeyBack); - if (KeySave > 0) client->SetKeySave(KeySave); - if (KeyNext > 0) client->SetKeyNext(KeyNext); + client->SetKeyBack(KeyBack); + client->SetKeySave(KeySave); + client->SetKeyNext(KeyNext); - if (FontColour>0u) - { - DWORD r = (FontColour>>16)&0xFF; - DWORD g = (FontColour>>8)&0xFF; - DWORD b = (FontColour)&0xFF; - client->SetFontColour( r, g, b); - } - if (TextureColour>0u) - { - DWORD r = (TextureColour>>16)&0xFF; - DWORD g = (TextureColour>>8)&0xFF; - DWORD b = (TextureColour)&0xFF; - client->SetTextureColour( r, g, b); - } + client->SetFontColour( FontColour); + client->SetTextureColour( TextureColour); + client->SetWidthFilter( WidthFilter); + client->SetHeightFilter( HeightFilter); + client->SetDepthFilter( DepthFilter); + client->SetFormatFilter(FormatFilter); + + + client->SetFileFormat(FileFormat); if (int ret = PrepareUpdate( update, number)) return (ret); // get a copy of all texture to be modded @@ -161,14 +169,17 @@ int uMod_TextureServer::RemoveClient(uMod_TextureClient *client, const int versi return (ret); } + bool hit = false; for (int i = 0; i < NumberOfClients; i++) if (client == Clients[i]) { + hit = true; NumberOfClients--; Clients[i] = Clients[NumberOfClients]; break; } int ret = UnlockMutex(); + if (!hit) return ret; if (ret!=RETURN_OK) return (ret); @@ -187,9 +198,9 @@ int uMod_TextureServer::RemoveClient(uMod_TextureClient *client, const int versi return (RETURN_OK); } -int uMod_TextureServer::AddFile( char* buffer, unsigned int size, MyTypeHash hash, bool force) // called from Mainloop() +int uMod_TextureServer::AddFile( char* buffer, DWORD64 size, DWORD64 hash, bool force) // called from Mainloop() { - Message("uMod_TextureServer::AddFile( %lu %lu, %#lX, %d): %lu\n", buffer, size, hash, force, this); + Message("uMod_TextureServer::AddFile( %p %llu, %#llX, %d): %lu\n", buffer, size, hash, force, this); TextureFileStruct* temp = NULL; @@ -236,23 +247,9 @@ int uMod_TextureServer::AddFile( char* buffer, unsigned int size, MyTypeHash ha temp->pData = buffer; - /* - try - { - temp->pData = new char[size]; - } - catch (...) - { - if (!new_file) CurrentMod.Remove( temp); // if this is a not a new file it is in the list of the CurrentMod - delete temp; - gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_SERVER; - return (RETURN_NO_MEMORY); - } - */ - for (unsigned int i=0; ipData[i] = buffer[i]; - temp->Size = size; + temp->Size = (unsigned int) size; temp->NumberOfTextures = 0; temp->Textures = NULL; temp->Hash = hash; @@ -261,7 +258,7 @@ int uMod_TextureServer::AddFile( char* buffer, unsigned int size, MyTypeHash ha //else temp->ForceReload = force; - Message("End AddFile(%#lX)\n", hash); + Message("uMod_TextureServer::End AddFile(%#lX)\n", hash); if (new_file) return (CurrentMod.Add(temp)); // new files must be added to the list of the CurrentMod else return (RETURN_OK); } @@ -352,7 +349,7 @@ int uMod_TextureServer::AddFile(wchar_t* file_name, MyTypeHash hash, bool force) } */ -int uMod_TextureServer::RemoveFile(MyTypeHash hash) // called from Mainloop() +int uMod_TextureServer::RemoveFile(DWORD64 hash) // called from Mainloop() { Message("RemoveFile( %lu): %lu\n", hash, this); @@ -400,6 +397,40 @@ int uMod_TextureServer::SaveSingleTexture(bool val) // called from Mainloop() return (UnlockMutex()); } +int uMod_TextureServer::ShowTextureString(bool val) // called from Mainloop() +{ + if (BoolShowTextureString == val) return (RETURN_OK); + BoolShowTextureString = val; + + if (int ret = LockMutex()) + { + gl_ErrorState |= uMod_ERROR_SERVER; + return (ret); + } + for (int i = 0; i < NumberOfClients; i++) + { + Clients[i]->ShowTextureString(BoolShowTextureString); + } + return (UnlockMutex()); +} + +int uMod_TextureServer::SupportTPF(bool val) // called from Mainloop() +{ + if (BoolSupportTPF == val) return (RETURN_OK); + BoolSupportTPF = val; + + if (int ret = LockMutex()) + { + gl_ErrorState |= uMod_ERROR_SERVER; + return (ret); + } + for (int i = 0; i < NumberOfClients; i++) + { + Clients[i]->SupportTPF(BoolSupportTPF); + } + return (UnlockMutex()); +} + int uMod_TextureServer::SetSaveDirectory(wchar_t *dir) // called from Mainloop() { Message("uMod_TextureServer::SetSaveDirectory( %ls): %lu\n", dir, this); @@ -472,7 +503,7 @@ int uMod_TextureServer::SetKeyNext(int key) // called from Mainloop() return (UnlockMutex()); } -int uMod_TextureServer::SetFontColour(DWORD colour) // called from Mainloop() +int uMod_TextureServer::SetFontColour(DWORD64 colour) // called from Mainloop() { if (colour==0u) return (RETURN_OK); if (int ret = LockMutex()) @@ -481,18 +512,15 @@ int uMod_TextureServer::SetFontColour(DWORD colour) // called from Mainloop() return (ret); } FontColour = colour; - DWORD r = (FontColour>>16)&0xFF; - DWORD g = (FontColour>>8)&0xFF; - DWORD b = (FontColour)&0xFF; - Message("uMod_TextureServer::SetFontColour( %u %u %u): %lu\n", r ,g ,b, this); + Message("uMod_TextureServer::SetFontColour( %#lX): %lu\n",colour, this); for (int i = 0; i < NumberOfClients; i++) { - Clients[i]->SetFontColour( r, g, b); + Clients[i]->SetFontColour( colour); } return (UnlockMutex()); } -int uMod_TextureServer::SetTextureColour(DWORD colour) // called from Mainloop() +int uMod_TextureServer::SetTextureColour(DWORD64 colour) // called from Mainloop() { if (colour==0u) return (RETURN_OK); if (int ret = LockMutex()) @@ -501,13 +529,90 @@ int uMod_TextureServer::SetTextureColour(DWORD colour) // called from Mainloop() return (ret); } TextureColour = colour; - DWORD r = (TextureColour>>16)&0xFF; - DWORD g = (TextureColour>>8)&0xFF; - DWORD b = (TextureColour)&0xFF; - Message("uMod_TextureServer::SetTextureColour( %u %u %u): %lu\n", r ,g ,b, this); + Message("uMod_TextureServer::SetTextureColour( %#lX): %lu\n", colour, this); for (int i = 0; i < NumberOfClients; i++) { - Clients[i]->SetTextureColour( r, g, b); + Clients[i]->SetTextureColour( colour); + } + return (UnlockMutex()); +} + +int uMod_TextureServer::SetFileFormat(DWORD64 format) // called from Mainloop() +{ + if (int ret = LockMutex()) + { + gl_ErrorState |= uMod_ERROR_SERVER; + return (ret); + } + FileFormat = format; + Message("uMod_TextureServer::SetFileFormat( %lu): %lu\n", format, this); + for (int i = 0; i < NumberOfClients; i++) + { + Clients[i]->SetFileFormat( format); + } + return (UnlockMutex()); +} + +int uMod_TextureServer::SetFormatFilter(DWORD64 format) // called from Mainloop() +{ + if (int ret = LockMutex()) + { + gl_ErrorState |= uMod_ERROR_SERVER; + return (ret); + } + FormatFilter = format; + Message("uMod_TextureServer::SetFormatFilter( %lu): %lu\n", format, this); + for (int i = 0; i < NumberOfClients; i++) + { + Clients[i]->SetFormatFilter( format); + } + return (UnlockMutex()); +} + +int uMod_TextureServer::SetWidthFilter(DWORD64 size) // called from Mainloop() +{ + if (int ret = LockMutex()) + { + gl_ErrorState |= uMod_ERROR_SERVER; + return (ret); + } + WidthFilter = size; + Message("uMod_TextureServer::SetWidthFilter( %lu): %lu\n", size, this); + for (int i = 0; i < NumberOfClients; i++) + { + Clients[i]->SetWidthFilter( size); + } + return (UnlockMutex()); +} + +int uMod_TextureServer::SetHeightFilter(DWORD64 size) // called from Mainloop() +{ + if (int ret = LockMutex()) + { + gl_ErrorState |= uMod_ERROR_SERVER; + return (ret); + } + HeightFilter = size; + Message("uMod_TextureServer::SetHeightFilter( %lu): %lu\n", size, this); + for (int i = 0; i < NumberOfClients; i++) + { + Clients[i]->SetHeightFilter( size); + } + return (UnlockMutex()); +} + +int uMod_TextureServer::SetDepthFilter(DWORD64 size) // called from Mainloop() +{ + if (int ret = LockMutex()) + { + gl_ErrorState |= uMod_ERROR_SERVER; + return (ret); + } + DepthFilter = size; + Message("uMod_TextureServer::SetDepthFilter( %lu): %lu\n", size, this); + for (int i = 0; i < NumberOfClients; i++) + { + Clients[i]->SetDepthFilter( size); } return (UnlockMutex()); } @@ -610,11 +715,11 @@ int uMod_TextureServer::MainLoop(void) // run as a separated thread unsigned long num = 0u; bool update_textures = false; - unsigned int texture_size = 0u; - unsigned int texture_received = 0u; + DWORD64 texture_size = 0u; + DWORD64 texture_received = 0u; char *texture_data = (char*)0; bool texture_force = false; - MyTypeHash texture_hash = 0u; + DWORD64 texture_hash = 0u; Message("MainLoop: started\n"); while (1) @@ -629,9 +734,9 @@ int uMod_TextureServer::MainLoop(void) // run as a separated thread Message("MainLoop: read something (%lu)\n", num); if (ret || GetLastError() == ERROR_MORE_DATA) { - unsigned int pos = 0; + DWORD64 pos = 0; MsgStruct *commands; - unsigned int size=0u; + DWORD64 size=0u; while (pos < num) { if (texture_receivedHash, this); + Message("MainLoop: CONTROL_REMOVE_TEXTURE (%#llX): %p\n", commands->Hash, this); RemoveFile(commands->Hash); //update_textures = true; break; } + case CONTROL_SAVE_ALL: + { + Message("MainLoop: CONTROL_SAVE_ALL (%#llX): %p\n", commands->Value, this); + if (commands->Value == 0) SaveAllTextures(false); + else SaveAllTextures(true); + break; + } case CONTROL_SAVE_SINGLE: { - Message("MainLoop: CONTROL_SAVE_SINGLE (%d): %lu\n", commands->Value, this); + Message("MainLoop: CONTROL_SAVE_SINGLE (%#llX): %p\n", commands->Value, this); if (commands->Value == 0) SaveSingleTexture(false); else SaveSingleTexture(true); break; } - case CONTROL_SAVE_ALL: + case CONTROL_SHOW_STRING: { - Message("MainLoop: CONTROL_SAVE_ALL (%d): %lu\n", commands->Value, this); - if (commands->Value == 0) SaveAllTextures(false); - else SaveAllTextures(true); + Message("MainLoop: CONTROL_SHOW_STRING (%#llX): %p\n", commands->Value, this); + if (commands->Value == 0) ShowTextureString(false); + else ShowTextureString(true); + break; + } + case CONTROL_SUPPORT_TPF: + { + Message("MainLoop: CONTROL_SUPPORT_TPF (%#llX): %p\n", commands->Value, this); + if (commands->Value == 0) SupportTPF(false); + else SupportTPF(true); break; } case CONTROL_SET_DIR: @@ -738,37 +857,68 @@ int uMod_TextureServer::MainLoop(void) // run as a separated thread case CONTROL_KEY_BACK: { - Message("MainLoop: CONTROL_KEY_BACK (%#X): %lu\n", commands->Value, this); - SetKeyBack(commands->Value); + Message("MainLoop: CONTROL_KEY_BACK (%#llX): %p\n", commands->Value, this); + SetKeyBack((int) commands->Value); break; } case CONTROL_KEY_SAVE: { - Message("MainLoop: CONTROL_KEY_SAVE (%#X): %lu\n", commands->Value, this); - SetKeySave(commands->Value); + Message("MainLoop: CONTROL_KEY_SAVE (%#llX): %p\n", commands->Value, this); + SetKeySave((int) commands->Value); break; } case CONTROL_KEY_NEXT: { - Message("MainLoop: CONTROL_KEY_NEXT (%#X): %lu\n", commands->Value, this); - SetKeyNext(commands->Value); + Message("MainLoop: CONTROL_KEY_NEXT (%#llX): %p\n", commands->Value, this); + SetKeyNext((int) commands->Value); break; } case CONTROL_FONT_COLOUR: { - Message("MainLoop: CONTROL_FONT_COLOUR (%#X): %lu\n", commands->Value, this); + Message("MainLoop: CONTROL_FONT_COLOUR (%#llX): %p\n", commands->Value, this); SetFontColour(commands->Value); break; } case CONTROL_TEXTURE_COLOUR: { - Message("MainLoop: CONTROL_TEXTURE_COLOUR (%#X): %lu\n", commands->Value, this); + Message("MainLoop: CONTROL_TEXTURE_COLOUR (%#llX): %p\n", commands->Value, this); SetTextureColour(commands->Value); break; } + case CONTROL_WIDTH_FILTER: + { + Message("MainLoop: CONTROL_WIDTH_FILTER (%#llX): %p\n", commands->Value, this); + SetWidthFilter(commands->Value); + break; + } + case CONTROL_HEIGHT_FILTER: + { + Message("MainLoop: CONTROL_HEIGHT_FILTER (%#llX): %p\n", commands->Value, this); + SetHeightFilter(commands->Value); + break; + } + case CONTROL_DEPTH_FILTER: + { + Message("MainLoop: CONTROL_DEPTH_FILTER (%#llX): %p\n", commands->Value, this); + SetDepthFilter(commands->Value); + break; + } + case CONTROL_FORMAT_FILTER: + { + Message("MainLoop: CONTROL_FORMAT_FILTER (%#llX): %p\n", commands->Value, this); + SetFormatFilter(commands->Value); + break; + } + case CONTROL_SAVE_FORMAT: + { + Message("MainLoop: CONTROL_SAVE_FORMAT (%#llX): %p\n", commands->Value, this); + SetFileFormat(commands->Value); + break; + } + default: { - Message("MainLoop: DEFAULT: %lu %lu %#lX\n", commands->Control, commands->Value, commands->Hash, this); + Message("MainLoop: DEFAULT: %lu %#llX %#llX\n", commands->Control, commands->Value, commands->Hash, this); break; } } @@ -790,7 +940,7 @@ int uMod_TextureServer::MainLoop(void) // run as a separated thread return (RETURN_OK); } -int uMod_TextureServer::OpenPipe(wchar_t *game) // called from InitInstance() +int uMod_TextureServer::OpenPipe(wchar_t *game, int injection_method) // called from InitInstance() { Message("OpenPipe: Out\n") // open first outgoing pipe !! @@ -810,7 +960,17 @@ int uMod_TextureServer::OpenPipe(wchar_t *game) // called from InitInstance() len++; //to send also the zero unsigned long num; //send name of this game to uMod_GUI - WriteFile(Pipe.Out, (const void*) game, len * sizeof(wchar_t), &num, NULL); + + char *buffer=(char*)0; + GetMemory(buffer, sizeof(int) + len * sizeof(wchar_t)); + *((int*) buffer) = injection_method; + char *p_game = (char*) game; + + for (unsigned int i=0; i #include "uMod_ArrayHandler.h" -/* +/** * An object of this class is created only once. * The Mainloop functions is executed by a server thread, * which listen on a pipe. @@ -41,34 +41,36 @@ class uMod_TextureServer public: /** * The server is created from the dll entry routine. - * @param name Name of the game executable (without the extension) + * @param[in] name Name of the game executable (without the extension) */ uMod_TextureServer(wchar_t *name); ~uMod_TextureServer(void); /** * Each client connect itself to the server via this function. - * @param client This-pointer of the client - * @param update Current texture to be modded - * @param number Number of modded textures - * @param Version Version of DirectX. + * @param[in] client This-pointer of the client + * @param[out] update Current texture to be modded + * @param[out] number Number of modded textures + * @param[in] version The device version (DX9, DX9EX, DX10, or DX101) * @return RETURN_OK on success */ int AddClient(uMod_TextureClient *client, TextureFileStruct* &update, int &number, const int version); // called from a Client /** * On destruction of client, it disconnect from the server. - * @param client This-pointer of the client + * @param[in] client This-pointer of the client + * @param[in] version The device version (DX9, DX9EX, DX10, or DX101) * @return RETURN_OK on success */ int RemoveClient(uMod_TextureClient *client, const int version); // called from a Client /** * Opens the pipe to the GUI (called from the dll entry routine) - * @param name Name of the game + * @param[in] name Name of the game + * @param[in] injection_method global hook=1, direct injection=2, no injection=3 * @return RETURN_OK on success */ - int OpenPipe(wchar_t *name); // called on initialization of our d3d9 fake dll + int OpenPipe(wchar_t *name, int injection_method); // called on initialization of our d3d9 fake dll /** * Close the Pipe to the GUI (called if dll entry is called to attach from the game) @@ -87,121 +89,184 @@ public: private: /** * Add a file to the list of texture to be modded (called from the mainloop). - * @param buffer hold the file content of the texture - * @param size size of the file content - * @param hash hash of the texture to be replaced - * @param force set to TRUE to force a reload of the texture + * @param[in] buffer hold the file content of the texture + * @param[in] size size of the file content + * @param[in] hash hash of the texture to be replaced + * @param[in] force set to TRUE to force a reload of the texture * @return RETURN_OK on success */ - int AddFile( char* buffer, unsigned int size, MyTypeHash hash, bool force); // called from Mainloop(), if the content of the texture is sent + int AddFile( char* buffer, DWORD64 size, DWORD64 hash, bool force); // called from Mainloop(), if the content of the texture is sent /** - * Add a file to the list of texture to be modded (called from the mainloop). - * @param file_name Name and path to the file to be loaded. - * @param hash hash of the texture to be replaced - * @param force set to TRUE to force a reload of the texture + * Add a file to the list of texture to be modded (called from the mainloop). Not supported anymore! + * @param[in] file_name Name and path to the file to be loaded. + * @param[in] hash hash of the texture to be replaced + * @param[in] force set to TRUE to force a reload of the texture * @return RETURN_OK on success */ - int AddFile( wchar_t* file_name, MyTypeHash hash, bool force); // called from Mainloop(), if the name and the path to the file is sent + int AddFile( wchar_t* file_name, DWORD64 hash, bool force); // called from Mainloop(), if the name and the path to the file is sent /** * Remove a texture (called from the mainloop). - * @param hash Hash of the target texture. + * @param[in] hash Hash of the target texture. * @return RETURN_OK on success */ - int RemoveFile( MyTypeHash hash); // called from Mainloop() + int RemoveFile( DWORD64 hash); // called from Mainloop() /** * Save all texture, which are loade by the game (called from the mainloop). - * @param val Set TRUE to enable the mode. + * @param[in] val Set TRUE to enable the mode. * @return */ int SaveAllTextures(bool val); // called from Mainloop() /** - * (called from the mainloop). - * @param val + * Enable/Disable the save single texture mode (called from the mainloop). + * @param[in] val * @return */ int SaveSingleTexture(bool val); // called from Mainloop() /** - * (called from the mainloop). - * @param dir + * Enable/Disable the string in the left upper corner during save single texture mode (called from the mainloop). + * @param[in] val + * @return + */ + int ShowTextureString(bool val); // called from Mainloop() + + /** + * Enable/Disable the hashing with CRC32, which is needed to support tpf mods (called from the mainloop). + * @param[in] val + * @return + */ + int SupportTPF(bool val); // called from Mainloop() + + /** + * Set saving directory (called from the mainloop). + * @param[in] dir * @return */ int SetSaveDirectory( wchar_t *dir); // called from Mainloop() /** * (called from the mainloop). - * @param key + * @param[in] key * @return */ int SetKeyBack( int key); // called from Mainloop() /** * (called from the mainloop). - * @param key + * @param[in] key * @return */ int SetKeySave( int key); // called from Mainloop() /** * (called from the mainloop). - * @param key + * @param[in] key * @return */ int SetKeyNext( int key); // called from Mainloop() /** * (called from the mainloop). - * @param colour + * @param[in] colour * @return */ - int SetFontColour(DWORD colour); // called from Mainloop() + int SetFontColour(DWORD64 colour); // called from Mainloop() /** * (called from the mainloop). - * @param colour + * @param[in] colour * @return */ - int SetTextureColour(DWORD colour); // called from Mainloop() + int SetTextureColour(DWORD64 colour); // called from Mainloop() - bool BoolSaveAllTextures; - bool BoolSaveSingleTexture; - wchar_t SavePath[MAX_PATH]; - wchar_t GameName[MAX_PATH]; + /** + * (called from the mainloop). + * @param[in] format + * @return + */ + int SetFileFormat(DWORD64 format); + + /** + * (called from the mainloop). + * @param[in] format + * @return + */ + int SetFormatFilter(DWORD64 format); + + /** + * (called from the mainloop). + * @param[in] size + * @return + */ + int SetWidthFilter(DWORD64 size); + + /** + * (called from the mainloop). + * @param[in] size + * @return + */ + int SetHeightFilter(DWORD64 size); + + /** + * (called from the mainloop). + * @param[in] size + * @return + */ + int SetDepthFilter(DWORD64 size); /** * Send the files to be modded (Update) to a client (called from the mainloop). - * @param client Pointer to a client (if NULL is passed, the data is send to all clients) + * @param[in] client Pointer to a client (if NULL is passed, the data is send to all clients) * @return */ int PropagateUpdate(uMod_TextureClient* client=NULL); // called from Mainloop() if texture are loaded or removed /** * Prepare the texture data for the clients (e.g. Load the texture from disk, sort the texture according the hash values) (called from the mainloop). - * @param update - * @param number + * @param[out] update + * @param[out] number * @return */ - int PrepareUpdate(TextureFileStruct* &update, int &number); // called from PropagateUpdate() and AddClient() - // generate a copy of the current texture to be modded - // the file content of the textures are not copied, the clients get the pointer to the file content - // but the arrays allocate by this function, must be deleted by the client + int PrepareUpdate(TextureFileStruct* &update, int &number); + /** + * Locks the mutex. + * @return + */ int LockMutex(); + /** + * Locks the mutex. + * @return + */ int UnlockMutex(); - HANDLE Mutex; + HANDLE Mutex; //!< Mutex protects the simultaneously add or remove of multiple clients. + + + bool BoolSaveAllTextures; + bool BoolSaveSingleTexture; + bool BoolShowTextureString; + bool BoolSupportTPF; + + wchar_t SavePath[MAX_PATH]; + wchar_t GameName[MAX_PATH]; int KeyBack; int KeySave; int KeyNext; - DWORD FontColour; - DWORD TextureColour; + DWORD64 FontColour; + DWORD64 TextureColour; + DWORD64 FileFormat; + DWORD64 FormatFilter; + DWORD64 WidthFilter; + DWORD64 HeightFilter; + DWORD64 DepthFilter; PipeStruct Pipe; diff --git a/uMod_GUI/makefile.gcc b/uMod_GUI/makefile.gcc deleted file mode 100644 index eb90f0c..0000000 --- a/uMod_GUI/makefile.gcc +++ /dev/null @@ -1,284 +0,0 @@ -# ========================================================================= -# This makefile was generated by -# Bakefile 0.2.1 (http://bakefile.sourceforge.net) -# Do not modify, all changes will be overwritten! -# ========================================================================= - -include config.gcc - -# ------------------------------------------------------------------------- -# Do not modify the rest of this file! -# ------------------------------------------------------------------------- - -### Variables: ### - -CPPDEPS = -MT$@ -MF$@.d -MD -WX_RELEASE_NODOT = 29 -OBJS = \ - obj -OBJS_exe = \ - bin -WX_DIR = D:\Programme\wxWidgets-2.9.2 -LIBDIRNAME = $(WX_DIR)\lib\gcc_$(LIBTYPE_SUFFIX)$(CFG) -SETUPHDIR = \ - $(LIBDIRNAME)\$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG) -MINIMAL_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG_2) $(__THREADSFLAG) \ - $(GCCFLAGS) -DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) \ - $(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) \ - $(__THREAD_DEFINE_p) $(__UNICODE_DEFINE_p) $(__MSLU_DEFINE_p) \ - $(__GFXCTX_DEFINE_p) -I$(SETUPHDIR) -I$(WX_DIR)\include -W -Wall -Wextra -I. \ - $(__DLLFLAG_p) -DNOPCH $(__RTTIFLAG_5) \ - $(__EXCEPTIONSFLAG_6) -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS) -MINIMAL_OBJECTS = \ - $(OBJS)\uMod_rc.o \ - $(OBJS)\unzip.o \ - $(OBJS)\uMod_DirectInjection.o \ - $(OBJS)\uMod_GUI.o \ - $(OBJS)\uMod_GameInfo.o \ - $(OBJS)\uMod_GamePage.o \ - $(OBJS)\uMod_Server.o \ - $(OBJS)\uMod_Client.o \ - $(OBJS)\uMod_File.o \ - $(OBJS)\uMod_Sender.o \ - $(OBJS)\uMod_Settings.o \ - $(OBJS)\uMod_AddTexture.o \ - $(OBJS)\uMod_Language.o - -### Conditionally set variables: ### - -ifeq ($(GCC_VERSION),2.95) -GCCFLAGS = -fvtable-thunks -endif -ifeq ($(USE_GUI),0) -PORTNAME = base -endif -ifeq ($(USE_GUI),1) -PORTNAME = msw -endif -ifeq ($(BUILD),debug) -ifeq ($(DEBUG_FLAG),default) -WXDEBUGFLAG = d -endif -endif -ifeq ($(DEBUG_FLAG),1) -WXDEBUGFLAG = d -endif -ifeq ($(UNICODE),1) -WXUNICODEFLAG = u -endif -ifeq ($(WXUNIV),1) -WXUNIVNAME = univ -endif -ifeq ($(SHARED),1) -WXDLLFLAG = dll -endif -ifeq ($(SHARED),0) -LIBTYPE_SUFFIX = lib -endif -ifeq ($(SHARED),1) -LIBTYPE_SUFFIX = dll -endif -ifeq ($(MONOLITHIC),0) -EXTRALIBS_FOR_BASE = -endif -ifeq ($(MONOLITHIC),1) -EXTRALIBS_FOR_BASE = -endif -ifeq ($(BUILD),debug) -__OPTIMIZEFLAG_2 = -O0 -g -endif -ifeq ($(BUILD),release) -__OPTIMIZEFLAG_2 = -O2 -endif -ifeq ($(USE_RTTI),0) -__RTTIFLAG_5 = -fno-rtti -endif -ifeq ($(USE_RTTI),1) -__RTTIFLAG_5 = -endif -ifeq ($(USE_EXCEPTIONS),0) -__EXCEPTIONSFLAG_6 = -fno-exceptions -endif -ifeq ($(USE_EXCEPTIONS),1) -__EXCEPTIONSFLAG_6 = -endif -ifeq ($(WXUNIV),1) -__WXUNIV_DEFINE_p = -D__WXUNIVERSAL__ -endif -ifeq ($(WXUNIV),1) -__WXUNIV_DEFINE_p_1 = --define __WXUNIVERSAL__ -endif -ifeq ($(BUILD),debug) -ifeq ($(DEBUG_FLAG),default) -__DEBUG_DEFINE_p = -D__WXDEBUG__ -endif -endif -ifeq ($(DEBUG_FLAG),1) -__DEBUG_DEFINE_p = -D__WXDEBUG__ -endif -ifeq ($(BUILD),debug) -ifeq ($(DEBUG_FLAG),default) -__DEBUG_DEFINE_p_1 = --define __WXDEBUG__ -endif -endif -ifeq ($(DEBUG_FLAG),1) -__DEBUG_DEFINE_p_1 = --define __WXDEBUG__ -endif -ifeq ($(USE_EXCEPTIONS),0) -__EXCEPTIONS_DEFINE_p = -DwxNO_EXCEPTIONS -endif -ifeq ($(USE_EXCEPTIONS),0) -__EXCEPTIONS_DEFINE_p_1 = --define wxNO_EXCEPTIONS -endif -ifeq ($(USE_RTTI),0) -__RTTI_DEFINE_p = -DwxNO_RTTI -endif -ifeq ($(USE_RTTI),0) -__RTTI_DEFINE_p_1 = --define wxNO_RTTI -endif -ifeq ($(USE_THREADS),0) -__THREAD_DEFINE_p = -DwxNO_THREADS -endif -ifeq ($(USE_THREADS),0) -__THREAD_DEFINE_p_1 = --define wxNO_THREADS -endif -ifeq ($(UNICODE),1) -__UNICODE_DEFINE_p = -D_UNICODE -endif -ifeq ($(UNICODE),1) -__UNICODE_DEFINE_p_1 = --define _UNICODE -endif -ifeq ($(MSLU),1) -__MSLU_DEFINE_p = -DwxUSE_UNICODE_MSLU=1 -endif -ifeq ($(MSLU),1) -__MSLU_DEFINE_p_1 = --define wxUSE_UNICODE_MSLU=1 -endif -ifeq ($(USE_GDIPLUS),1) -__GFXCTX_DEFINE_p = -DwxUSE_GRAPHICS_CONTEXT=1 -endif -ifeq ($(USE_GDIPLUS),1) -__GFXCTX_DEFINE_p_1 = --define wxUSE_GRAPHICS_CONTEXT=1 -endif -ifeq ($(SHARED),1) -__DLLFLAG_p = -DWXUSINGDLL -endif -ifeq ($(SHARED),1) -__DLLFLAG_p_1 = --define WXUSINGDLL -endif -ifeq ($(MONOLITHIC),0) -__WXLIB_CORE_p = \ - -lwx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core -endif -ifeq ($(MONOLITHIC),0) -__WXLIB_BASE_p = \ - -lwxbase$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR) -endif -ifeq ($(MONOLITHIC),1) -__WXLIB_MONO_p = \ - -lwx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR) -endif -ifeq ($(USE_GUI),1) -__LIB_TIFF_p = -lwxtiff$(WXDEBUGFLAG) -endif -ifeq ($(USE_GUI),1) -__LIB_JPEG_p = -lwxjpeg$(WXDEBUGFLAG) -endif -ifeq ($(USE_GUI),1) -__LIB_PNG_p = -lwxpng$(WXDEBUGFLAG) -endif -ifeq ($(MSLU),1) -__UNICOWS_LIB_p = -lunicows -endif -ifeq ($(USE_GDIPLUS),1) -__GDIPLUS_LIB_p = -lgdiplus -endif -ifeq ($(BUILD),debug) -ifeq ($(DEBUG_INFO),default) -__DEBUGINFO = -g -endif -endif -ifeq ($(BUILD),release) -ifeq ($(DEBUG_INFO),default) -__DEBUGINFO = -endif -endif -ifeq ($(DEBUG_INFO),0) -__DEBUGINFO = -endif -ifeq ($(DEBUG_INFO),1) -__DEBUGINFO = -g -endif -ifeq ($(USE_THREADS),0) -__THREADSFLAG = -endif -ifeq ($(USE_THREADS),1) -__THREADSFLAG = -mthreads -endif - - -all: $(OBJS) -$(OBJS): - -if not exist $(OBJS) mkdir $(OBJS) - -all: $(OBJS_exe) -$(OBJS_exe): - -if not exist $(OBJS_exe) mkdir $(OBJS_exe) - -### Targets: ### - -all: $(OBJS_exe)\uMod.exe - -clean: - -if exist $(OBJS)\*.o del $(OBJS)\*.o - -if exist $(OBJS)\*.d del $(OBJS)\*.d - -if exist $(OBJS_exe)\uMod.exe del $(OBJS_exe)\uMod.exe - -$(OBJS_exe)\uMod.exe: $(MINIMAL_OBJECTS) $(OBJS)\uMod_rc.o - $(CXX) -o $@ $(MINIMAL_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) $(__THREADSFLAG) -L$(LIBDIRNAME) -Wl,--subsystem,windows -mwindows $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG) -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) $(__GDIPLUS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 - -$(OBJS)\uMod_rc.o: uMod.rc uMod.ico - windres --use-temp-file -i $< -o $@ - -$(OBJS)\unzip.o: ./unzip.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_DirectInjection.o: ./uMod_DirectInjection.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_GUI.o: ./uMod_GUI.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_GameInfo.o: ./uMod_GameInfo.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_GamePage.o: ./uMod_GamePage.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_Server.o: ./uMod_Server.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_Client.o: ./uMod_Client.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_File.o: ./uMod_File.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_Sender.o: ./uMod_Sender.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_Settings.o: ./uMod_Settings.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_AddTexture.o: ./uMod_AddTexture.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - -$(OBJS)\uMod_Language.o: ./uMod_Language.cpp - $(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $< - - -.PHONY: all clean - - -# Dependencies tracking: --include $(OBJS)/*.d diff --git a/uMod_GUI/makefile.vc b/uMod_GUI/makefile.vc index 94e7dae..4d3b688 100644 --- a/uMod_GUI/makefile.vc +++ b/uMod_GUI/makefile.vc @@ -18,7 +18,7 @@ OBJS = \ obj OBJS_exe = \ bin -WX_DIR = D:\Programme\wxWidgets-2.9.2 +WX_DIR = D:\Programme\wxWidgets-2.9.3 LIBDIRNAME = \ $(WX_DIR)\lib\$(COMPILER_PREFIX)$(DIR_SUFFIX_CPU)_$(LIBTYPE_SUFFIX)$(CFG) SETUPHDIR = \ @@ -37,6 +37,7 @@ MINIMAL_OBJECTS = \ $(OBJS)\uMod_DirectInjection.obj \ $(OBJS)\uMod_GUI.obj \ $(OBJS)\uMod_GameInfo.obj \ + $(OBJS)\uMod_MiniPanels.obj \ $(OBJS)\uMod_GamePage.obj \ $(OBJS)\uMod_Server.obj \ $(OBJS)\uMod_Client.obj \ @@ -44,10 +45,30 @@ MINIMAL_OBJECTS = \ $(OBJS)\uMod_Sender.obj \ $(OBJS)\uMod_Settings.obj \ $(OBJS)\uMod_AddTexture.obj \ + $(OBJS)\uMod_TreeView.obj \ + $(OBJS)\uMod_ModElement.obj \ $(OBJS)\uMod_Language.obj MINIMAL_RESOURCES = \ $(OBJS)\uMod_GUI.res +HEADERS = \ + uMod_AddTexture.h \ + uMod_Client.h \ + uMod_DirectInjection.h \ + uMod_Event.h \ + uMod_File.h \ + uMod_GameInfo.h \ + uMod_MiniPanels.h \ + uMod_GamePage.h \ + uMod_GUI.h \ + uMod_Language.h \ + uMod_Main.h \ + uMod_ModElement.h \ + uMod_Sender.h \ + uMod_Server.h \ + uMod_Settings.h \ + uMod_TreeView.h + ### Conditionally set variables: ### !if "$(USE_GUI)" == "0" @@ -306,6 +327,10 @@ __DLLFLAG_p = /DWXUSINGDLL __DLLFLAG_p_1 = /d WXUSINGDLL !endif !if "$(MONOLITHIC)" == "0" +__WXLIB_ADV_p = \ + wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_adv.lib +!endif +!if "$(MONOLITHIC)" == "0" __WXLIB_CORE_p = \ wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_core.lib !endif @@ -355,47 +380,54 @@ clean: $(OBJS_exe)\uMod.exe: $(MINIMAL_OBJECTS) $(OBJS)\uMod_GUI.res link /NOLOGO /OUT:$@ $(__DEBUGINFO_1) /pdb:"$(OBJS)\uMod_GUI.pdb" $(__DEBUGINFO_2) $(LINK_TARGET_CPU) /LIBPATH:$(LIBDIRNAME) /SUBSYSTEM:WINDOWS $(____CAIRO_LIBDIR_FILENAMES_p) $(LDFLAGS) @<< - $(MINIMAL_OBJECTS) $(MINIMAL_RESOURCES) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) $(__CAIRO_LIB_p) kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib wininet.lib + $(MINIMAL_OBJECTS) $(MINIMAL_RESOURCES) $(__WXLIB_ADV_p) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) $(__CAIRO_LIB_p) kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib wininet.lib << $(OBJS)\uMod_GUI.res: uMod.rc rc /fo$@ /d WIN32 $(____DEBUGRUNTIME_3_p_1) $(__NO_VC_CRTDBG_p_1) /d __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) $(__MSLU_DEFINE_p_1) /i $(SETUPHDIR) /i . $(__DLLFLAG_p_1) /d _WINDOWS /d NOPCH uMod.rc -#$(OBJS)\display_display.obj: .\display.cpp -# $(CXX) /c /nologo /TP /Fo$@ $(DISPLAY_CXXFLAGS) .\display.cpp $(OBJS)\unzip.obj: .\unzip.cpp $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\unzip.cpp -$(OBJS)\uMod_DirectInjection.obj: .\uMod_DirectInjection.cpp +$(OBJS)\uMod_DirectInjection.obj: .\uMod_DirectInjection.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_DirectInjection.cpp -$(OBJS)\uMod_GUI.obj: .\uMod_GUI.cpp +$(OBJS)\uMod_GUI.obj: .\uMod_GUI.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_GUI.cpp -$(OBJS)\uMod_GameInfo.obj: .\uMod_GameInfo.cpp +$(OBJS)\uMod_GameInfo.obj: .\uMod_GameInfo.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_GameInfo.cpp -$(OBJS)\uMod_GamePage.obj: .\uMod_GamePage.cpp +$(OBJS)\uMod_MiniPanels.obj: .\uMod_MiniPanels.cpp $(HEADERS) + $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_MiniPanels.cpp + +$(OBJS)\uMod_GamePage.obj: .\uMod_GamePage.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_GamePage.cpp -$(OBJS)\uMod_Server.obj: .\uMod_Server.cpp +$(OBJS)\uMod_Server.obj: .\uMod_Server.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Server.cpp -$(OBJS)\uMod_Client.obj: .\uMod_Client.cpp +$(OBJS)\uMod_Client.obj: .\uMod_Client.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Client.cpp -$(OBJS)\uMod_File.obj: .\uMod_File.cpp +$(OBJS)\uMod_File.obj: .\uMod_File.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_File.cpp -$(OBJS)\uMod_Sender.obj: .\uMod_Sender.cpp +$(OBJS)\uMod_Sender.obj: .\uMod_Sender.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Sender.cpp -$(OBJS)\uMod_Settings.obj: .\uMod_Settings.cpp +$(OBJS)\uMod_Settings.obj: .\uMod_Settings.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Settings.cpp -$(OBJS)\uMod_AddTexture.obj: .\uMod_AddTexture.cpp +$(OBJS)\uMod_AddTexture.obj: .\uMod_AddTexture.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_AddTexture.cpp -$(OBJS)\uMod_Language.obj: .\uMod_Language.cpp +$(OBJS)\uMod_TreeView.obj: .\uMod_TreeView.cpp $(HEADERS) + $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_TreeView.cpp + +$(OBJS)\uMod_ModElement.obj: .\uMod_ModElement.cpp $(HEADERS) + $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_ModElement.cpp + +$(OBJS)\uMod_Language.obj: .\uMod_Language.cpp $(HEADERS) $(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\uMod_Language.cpp diff --git a/uMod_GUI/uMod_Client.cpp b/uMod_GUI/uMod_Client.cpp index bafe779..2c50705 100644 --- a/uMod_GUI/uMod_Client.cpp +++ b/uMod_GUI/uMod_Client.cpp @@ -61,7 +61,7 @@ void* uMod_Client::Entry(void) { unsigned int pos=0; MsgStruct *commands; - bool update_textures = false; + //bool update_textures = false; while (pos<=size-sizeof(MsgStruct)) { @@ -72,18 +72,20 @@ void* uMod_Client::Entry(void) { case CONTROL_ADD_CLIENT: { - uMod_Event event( uMod_EVENT_TYPE, ID_Add_Device); - event.SetValue(commands->Value); - event.SetClient(this); - wxPostEvent( MainFrame, event); + uMod_Event *event = new uMod_Event( uMod_EVENT_TYPE, ID_Add_Device); + event->SetValue(commands->Value); + event->SetClient(this); + wxQueueEvent( MainFrame, (wxEvent*) event); + //wxPostEvent( MainFrame, event); break; } case CONTROL_REMOVE_CLIENT: { - uMod_Event event( uMod_EVENT_TYPE, ID_Delete_Device); - event.SetValue(commands->Value); - event.SetClient(this); - wxPostEvent( MainFrame, event); + uMod_Event *event = new uMod_Event( uMod_EVENT_TYPE, ID_Delete_Device); + event->SetValue(commands->Value); + event->SetClient(this); + wxQueueEvent( MainFrame, (wxEvent*) event); + //wxPostEvent( MainFrame, event); break; } case CONTROL_GAME_EXIT: @@ -105,9 +107,10 @@ void* uMod_Client::Entry(void) CloseHandle(Pipe.Out); Pipe.Out = INVALID_HANDLE_VALUE; - uMod_Event event( uMod_EVENT_TYPE, ID_Delete_Game); - event.SetClient(this); - wxPostEvent( MainFrame, event); + uMod_Event *event = new uMod_Event( uMod_EVENT_TYPE, ID_Delete_Game); + event->SetClient(this); + wxQueueEvent( MainFrame, (wxEvent*) event); + //wxPostEvent( MainFrame, event); return NULL; } diff --git a/uMod_GUI/uMod_Event.h b/uMod_GUI/uMod_Event.h index 312da55..82b12a3 100644 --- a/uMod_GUI/uMod_Event.h +++ b/uMod_GUI/uMod_Event.h @@ -29,20 +29,20 @@ BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE( uMod_EVENT_TYPE, -1) END_DECLARE_EVENT_TYPES() -class uMod_Event : public wxCommandEvent +class uMod_Event : public wxThreadEvent { public: uMod_Event( wxEventType commandType = uMod_EVENT_TYPE, int id = 0 ) - : wxCommandEvent(commandType, id) { } + : wxThreadEvent(commandType, id) { } virtual ~uMod_Event(void) {} // You *must* copy here the data to be transported uMod_Event( const uMod_Event &event ) - : wxCommandEvent(event) - { this->SetText( event.GetText()); + : wxThreadEvent(event) + { this->SetText( event.GetText().c_str()); Value=((uMod_Event&)event).GetValue(); PipeIn=((uMod_Event&)event).GetPipeIn(); PipeOut=((uMod_Event&)event).GetPipeOut(); - Name=((uMod_Event&)event).GetName(); + Name=((uMod_Event&)event).GetName().c_str(); Client=((uMod_Event&)event).GetClient(); } @@ -59,7 +59,7 @@ public: uMod_Client * GetClient(void) {return Client;} void SetValue(int value) {Value=value;} - void SetName( wxString name) {Name=name;} + void SetName( wxString name) {Name=name.c_str();} void SetPipeIn( HANDLE pipe) {PipeIn=pipe;} void SetPipeOut( HANDLE pipe) {PipeOut=pipe;} void SetClient( uMod_Client *client) {Client=client;} diff --git a/uMod_GUI/uMod_File.cpp b/uMod_GUI/uMod_File.cpp index ff4ab77..5f37603 100644 --- a/uMod_GUI/uMod_File.cpp +++ b/uMod_GUI/uMod_File.cpp @@ -20,11 +20,19 @@ along with Universal Modding Engine. If not, see #include "unzip.h" +#ifdef __CDT_PARSER__ +#define FindZipItem(...) 0 +#define UnzipItem(...) 0 +#define CloseZip(...) 0 +#define GetZipItem(...) 0 +#endif + + uMod_File::uMod_File(void) { Loaded=false; XORed=false; - FileInMemory=NULL; + FileInMemory=(char*)0; MemoryLength=0u; FileLen=0u; } @@ -33,7 +41,7 @@ uMod_File::uMod_File(const wxString &file) { Loaded=false; XORed=false; - FileInMemory=NULL; + FileInMemory=(char*)0; MemoryLength=0u; FileLen=0u; SetFile(file); @@ -42,7 +50,7 @@ uMod_File::uMod_File(const wxString &file) uMod_File::~uMod_File(void) { - if (FileInMemory!=NULL) delete [] FileInMemory; + if (FileInMemory!=(char*)0) delete [] FileInMemory; } @@ -57,6 +65,14 @@ bool uMod_File::FileSupported(void) } +bool uMod_File::SingleFile(void) +{ + wxString file_type = FileName.AfterLast( '.'); + if (file_type == L"dds") return true; + return false; +} + +/* int uMod_File::GetComment( wxString &tool_tip) { wxString file_type = FileName.AfterLast( '.'); @@ -103,6 +119,32 @@ int uMod_File::GetContent( AddTextureClass &tex, bool add) return 0; } } +*/ + + +int uMod_File::GetContent( uMod_TreeViewNode* node) +{ + wxString file_type = FileName.AfterLast( '.'); + if (file_type == L"zip") + { + AddZip( node); + } + else if (file_type == L"tpf") + { + AddTpf( node); + } + else if (file_type == L"dds") + { + AddFile( node); + } + else + { + LastError << Language->Error_FileNotSupported; + LastError << "\n" << FileName; + } + if (LastError.Len()>0) return -1; + return 0; +} int uMod_File::ReadFile(void) { @@ -118,9 +160,9 @@ int uMod_File::ReadFile(void) if (FileLen>=MemoryLength) { - if (FileInMemory!=NULL) delete [] FileInMemory; + if (FileInMemory!=(char*)0) delete [] FileInMemory; try {FileInMemory = new char [FileLen+1];} - catch (...) {FileInMemory=NULL; MemoryLength=0; FileLen=0; LastError << Language->Error_Memory; return -1;} + catch (...) {FileInMemory=(char*)0; MemoryLength=0; FileLen=0; LastError << Language->Error_Memory; return -1;} MemoryLength = FileLen+1; } unsigned int result = dat.Read( FileInMemory, FileLen); @@ -178,103 +220,244 @@ int uMod_File::UnXOR(void) -int uMod_File::GetCommentZip( wxString &tool_tip) +/* +int uMod_File::AddFile( uMod_TreeViewNode* node) { + DWORD64 temp_hash; + + wxString name = FileName.AfterLast( '_'); + name = name.BeforeLast( '.'); + if (!name.ToULongLong( &temp_hash, 16)) {LastError << Language->Error_Hash <<"\n" << FileName << "\n"; return -1;} // return if hash could not be extracted + if (int ret = ReadFile()) return ret; - HZIP ZIP_Handle = OpenZip( FileInMemory, FileLen, NULL); - if (ZIP_Handle==NULL) {tool_tip = Language->NoComment; LastError << Language->Error_Unzip; return -1;} + uMod_TextureElement *texture = new uMod_TextureElement(); - ZIPENTRY ze; - int index; - FindZipItem( ZIP_Handle, L"Comment.txt", false, &index, &ze); - if (index>=0) //if Comment.txt is present in the zip file + if (texture->Content().SetSize(FileLen)) { - char* comment; - int len = ze.unc_size; - try {comment=new char[len+1];} - catch(...) {tool_tip = Language->NoComment; LastError << Language->Error_Memory; return -1;} - ZRESULT zr = UnzipItem( ZIP_Handle, index, comment, len); - - if (zr!=ZR_OK && zr!=ZR_MORE) {delete [] comment; tool_tip = Language->NoComment; LastError << Language->Error_Unzip <<"\nZIP:" << L"Comment.txt"; return -1;} - comment[len]=0; - tool_tip = comment; - delete [] comment; + LastError << Language->Error_Memory; + texture->Release(); + return -1; } - else tool_tip = Language->NoComment; + char *data = texture->Content().Data(); - CloseZip(ZIP_Handle); + for (unsigned int i=0; iHash() = temp_hash; + texture->Title() = FileName; + texture->Status() = uMod_TextureElement::Activate; + + uMod_ModElement *element = new uMod_ModElement(uMod_ModElement::Group, uMod_ModElement::NONE); + element->Title() = FileName; + node = new uMod_TreeViewNode( (uMod_TreeViewNode*)0, element); + uMod_TreeViewNode *texture_node = new uMod_TreeViewNode( node, texture); + node->Append(texture_node); + + texture->Release(); + element->Release(); + return 0; +} +*/ + +int uMod_File::AddFile( uMod_TreeViewNode* node) +{ + DWORD64 temp_hash; + + wxString name = FileName.AfterLast( '_'); + name = name.BeforeLast( '.'); + if (!name.ToULongLong( &temp_hash, 16)) {LastError << Language->Error_Hash <<"\n" << FileName << "\n"; return -1;} // return if hash could not be extracted + + if (int ret = ReadFile()) return ret; + + uMod_TextureElement *texture = new uMod_TextureElement(); + + if (texture->Content().SetSize(FileLen)) + { + LastError << Language->Error_Memory; + texture->Release(); + return -1; + } + char *data = texture->Content().Data(); + + for (unsigned int i=0; iHash() = temp_hash; + texture->File() = FileName; + texture->Status() = uMod_TextureElement::Activate; + + + uMod_TreeViewNode *texture_node = new uMod_TreeViewNode( node, texture); + node->Append(texture_node); + + texture->Release(); return 0; } -int uMod_File::GetCommentTpf( wxString &tool_tip) + +int uMod_File::GetContentTemplate(const wxString &content, uMod_TreeViewNode* node) +{ + uMod_TreeViewNode_ArrayPtr list_node; + + if (uMod_TreeViewModel::String2Node( content, node, &list_node)) + { + LastError << uMod_TreeViewModel::LastError << "\n" << FileName << "\n"; + uMod_TreeViewModel::LastError.Empty(); + return -1; + } + + if (node->myElement->File().IsEmpty()) + return GetContentTemplate_SF( list_node, node); + else + return GetContentTemplate_ZIP( list_node, node); +} + +int uMod_File::GetContentTemplate_ZIP( const uMod_TreeViewNode_ArrayPtr &list_node, uMod_TreeViewNode* node) +{ + SetFile(node->myElement->File()); + if (!FileSupported()) + { + LastError << Language->Error_FileNotSupported <<"\n" << FileName; + return -1; + } + if (int ret = ReadFile()) return ret; + wxString file_type = FileName.AfterLast( '.'); + bool tpf = false; + if (file_type == L"tpf") + { + tpf = true; + UnXOR(); + } + + const char pw[] = {0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, 0xA6, 0xBD, + 0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F, + 0x74, 0x61, 0x67, 0x5B, 0x60, 0x70, 0x45, 0x74, + 0x5C, 0x22, 0x74, 0x5D, 0x6E, 0x6A, 0x73, 0x41, + 0x77, 0x6E, 0x46, 0x47, 0x77, 0x49, 0x0C, 0x4B, + 0x46, 0x6F, '\0'}; + + ZIPENTRY ze; + int index = -1; + HZIP ZIP_Handle; + if (tpf) ZIP_Handle= OpenZip( FileInMemory, FileLen, pw); + else ZIP_Handle= OpenZip( FileInMemory, FileLen, (const char*)0); + + if (ZIP_Handle==(HZIP)0) + { + LastError << Language->Error_Unzip <<"\n" << FileName; + return -1; + } + + for (unsigned int i=0; imyElement->Type() == uMod_ModElement::Texture) + { + uMod_TextureElement *texture = (uMod_TextureElement*) list_node[i]->myElement; + + wxString file = texture->File(); + while ( (file[0]=='.' && (file[1]=='/' || file[1]=='\\')) || file[0]=='/' || file[0]=='\\') file.Remove(0,1); + + FindZipItem( ZIP_Handle, file.wc_str(), false, &index, &ze); // look for texture + if (index>=0) + { + if (texture->Content().SetSize(ze.unc_size)) + { + texture->Comment() = Language->Error_Memory; + continue; + } + char *data = texture->Content().Data(); + + ZRESULT rz = UnzipItem( ZIP_Handle, index, data, ze.unc_size); + if (rz!=ZR_OK && rz!=ZR_MORE) + { + texture->Content().SetSize(0); + texture->Comment() = Language->Error_Unzip; + texture->Comment() <<" : " << FileName << " ==>> " << file; + } + } + else + { + texture->Content().SetSize(0); + texture->Comment() = Language->Error_Unzip; + texture->Comment() << " : " << FileName << " -> " << file; + CloseZip(ZIP_Handle); //somehow we need to close and to reopen the zip handle, otherwise the program crashes + if (tpf) ZIP_Handle= OpenZip( FileInMemory, FileLen, pw); + else ZIP_Handle= OpenZip( FileInMemory, FileLen, (const char*)0); + } + } + } + + CloseZip(ZIP_Handle); + if (node->myChildren.GetCount()==0) + { + LastError << Language->Error_FileIsEmpty << FileName << "\n"; + return -1; + } + return 0; +} + + +int uMod_File::GetContentTemplate_SF( const uMod_TreeViewNode_ArrayPtr &list_node, uMod_TreeViewNode* node) +{ + DWORD64 temp_hash; + wxString name; + + for (unsigned int i=0; imyElement->Type() != uMod_ModElement::Texture) continue; + + uMod_TextureElement *texture = (uMod_TextureElement*) list_node[i]->myElement; + + SetFile( texture->File()); + if (int ret = ReadFile()) + { + texture->Comment() = Language->Error_FileRead; + texture->Comment() << " : " << texture->File(); + continue; + } + + if (texture->Content().SetSize(FileLen)) + { + texture->Comment() = Language->Error_Memory; + texture->Comment() << " : " << texture->File(); + continue; + } + char *data = texture->Content().Data(); + + for (unsigned int i=0; iHash() = temp_hash; + texture->Status() = uMod_TextureElement::Activate; + } + + return 0; +} + + + +int uMod_File::AddZip( uMod_TreeViewNode* node) +{ + if (int ret = ReadFile()) return ret; + return AddContent( (char*)0, node); +} + +int uMod_File::AddTpf( uMod_TreeViewNode* node) { if (int ret = ReadFile()) return ret; UnXOR(); - tool_tip = &FileInMemory[FileLen]; - tool_tip.Prepend( Language->Author); - return 0; + + const char pw[] = {0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, 0xA6, 0xBD, + 0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F, + 0x74, 0x61, 0x67, 0x5B, 0x60, 0x70, 0x45, 0x74, + 0x5C, 0x22, 0x74, 0x5D, 0x6E, 0x6A, 0x73, 0x41, + 0x77, 0x6E, 0x46, 0x47, 0x77, 0x49, 0x0C, 0x4B, + 0x46, 0x6F, '\0'}; + + return AddContent( pw, node); } - - - - - - - -int uMod_File::AddFile( AddTextureClass &tex, bool add) -{ - tex.SetSize(1); - unsigned long temp_hash; - - wxString name = FileName.AfterLast( '_'); - name = name.BeforeLast( '.'); - if (!name.ToULong( &temp_hash, 16)) {LastError << Language->Error_Hash <<"\n" << FileName << "\n"; return -1;} // return if hash could not be extracted - - if (add) - { - if (int ret = ReadFile()) return ret; - - try {tex.Textures[0] = new char[FileLen];} - catch (...) {tex.Textures[0]=NULL; LastError << Language->Error_Memory; return -1;} - for (unsigned int i=0; iError_Unzip; return -1;} + if (ZIP_Handle==(HZIP)0) {LastError << Language->Error_Unzip; return -1;} + + node->myElement->File() = FileName; ZIPENTRY ze; int index; @@ -308,11 +493,7 @@ int uMod_File::AddContent( const char* pw, AddTextureClass &tex, bool add) int num = token.CountTokens(); - - tex.SetSize(num); - - unsigned long temp_hash; - int count = 0; + DWORD64 temp_hash; wxString entry; wxString file; @@ -320,122 +501,256 @@ int uMod_File::AddContent( const char* pw, AddTextureClass &tex, bool add) { entry = token.GetNextToken(); file = entry.BeforeFirst( '|'); - if (!file.ToULong( &temp_hash, 16)) {LastError << Language->Error_Hash <<"\nTPF:" << entry << "\n"; continue;} + if (!file.ToULongLong( &temp_hash, 16)) {LastError << Language->Error_Hash <<"\nTPF:" << entry << "\n"; continue;} file = entry.AfterFirst( '|'); file.Replace( "\r", ""); while ( (file[0]=='.' && (file[1]=='/' || file[1]=='\\')) || file[0]=='/' || file[0]=='\\') file.Remove(0,1); - if (add) + FindZipItem( ZIP_Handle, file.wc_str(), false, &index, &ze); // look for texture + if (index>=0) { - FindZipItem( ZIP_Handle, file.wc_str(), false, &index, &ze); // look for texture - if (index>=0) - { - try {tex.Textures[count] = new char[ze.unc_size];} - catch(...) - { - tex.Textures[count] = NULL; - LastError << Language->Error_Memory; - continue; - } + uMod_TextureElement *texture = new uMod_TextureElement(); - ZRESULT rz = UnzipItem( ZIP_Handle, index, tex.Textures[count], ze.unc_size); - if (rz!=ZR_OK && rz!=ZR_MORE) - { - delete [] tex.Textures[count]; - LastError << Language->Error_Unzip <<"\nTPF:" << file << "\n"; - tex.Textures[count] = NULL; - } - else - { - tex.Hash[count] = temp_hash; - tex.Size[count] = ze.unc_size; - count++; - } + if (texture->Content().SetSize(ze.unc_size)) + { + LastError << Language->Error_Memory; + texture->Release(); + continue; + } + char *data = texture->Content().Data(); + + ZRESULT rz = UnzipItem( ZIP_Handle, index, data, ze.unc_size); + if (rz!=ZR_OK && rz!=ZR_MORE) + { + texture->Release(); + LastError << Language->Error_Unzip <<"\nTPF:" << file << "\n"; } else { - LastError << Language->Error_Unzip <<"\nTPF:" << file << "\n"; - CloseZip(ZIP_Handle); //somehow we need to close and to reopen the zip handle, otherwise the program crashes - ZIP_Handle = OpenZip( FileInMemory, FileLen, pw); + texture->Hash() = temp_hash; + texture->Title() = file; + texture->File() = file; + texture->Status() = uMod_TextureElement::Activate; + + uMod_TreeViewNode *node_texture = new uMod_TreeViewNode( node, texture); + node->Append(node_texture); + texture->Release(); } } else { - tex.Hash[count] = temp_hash; - tex.Size[count] = 0; - count++; + LastError << Language->Error_Unzip <<"\nTPF:" << file << "\n"; + CloseZip(ZIP_Handle); //somehow we need to close and to reopen the zip handle, otherwise the program crashes + ZIP_Handle = OpenZip( FileInMemory, FileLen, pw); } } delete [] def; - tex.Num = count; + + wxString temp = &FileInMemory[FileLen]; + node->myElement->Author() = temp.BeforeFirst('\n'); + node->myElement->Author().Replace("\r", "", true); + node->myElement->Author().Replace("\n", "", true); + + node->myElement->Comment() = temp.AfterFirst('\n'); + node->myElement->Comment().Replace("\r\n", " ; ", true); + node->myElement->Comment().Replace("\n", " ; ", true); + + CloseZip(ZIP_Handle); + + if (node->myChildren.GetCount()==0) + { + LastError << Language->Error_FileIsEmpty << FileName << "\n"; + return -1; + } + return 0; } - else // texmod.def is not present in the zip file + + + + + + CloseZip(ZIP_Handle); //somehow we need to close and to reopen the zip handle, otherwise the program crashes + ZIP_Handle = OpenZip( FileInMemory, FileLen, pw); + if (ZIP_Handle==(HZIP)0) {LastError << Language->Error_Unzip; return -1;} + FindZipItem( ZIP_Handle, L"content.txt", false, &index, &ze); + + + + + if (index>=0) //if content.txt is present in the zip file + { + char* def; + int len = ze.unc_size; + try {def=new char[len+1];} + catch(...) {LastError << Language->Error_Memory; return -1;} + ZRESULT zr = UnzipItem( ZIP_Handle, index, def, len); + + if (zr!=ZR_OK && zr!=ZR_MORE) {delete [] def; return -1;} + def[len]=0; + + wxString content = def; + + uMod_TreeViewNode_ArrayPtr list_node; + + if (uMod_TreeViewModel::String2Node( content, node, &list_node)) + { + LastError << uMod_TreeViewModel::LastError << "\n" << FileName << "\n"; + uMod_TreeViewModel::LastError.Empty(); + return -1; + } + + // overwrite file information + node->myElement->File() = FileName; + + for (unsigned int i=0; i< list_node.GetCount(); i++) + { + if (list_node[i]->myElement->Type() == uMod_ModElement::Texture) + { + uMod_TextureElement *texture = (uMod_TextureElement*) list_node[i]->myElement; + + wxString file = texture->File(); + while ( (file[0]=='.' && (file[1]=='/' || file[1]=='\\')) || file[0]=='/' || file[0]=='\\') file.Remove(0,1); + + FindZipItem( ZIP_Handle, file.wc_str(), false, &index, &ze); // look for texture + if (index>=0) + { + if (texture->Content().SetSize(ze.unc_size)) + { + texture->Comment() = Language->Error_Memory; + continue; + } + char *data = texture->Content().Data(); + + ZRESULT rz = UnzipItem( ZIP_Handle, index, data, ze.unc_size); + if (rz!=ZR_OK && rz!=ZR_MORE) + { + texture->Content().SetSize(0); + texture->Comment() = Language->Error_Unzip; + } + } + else + { + texture->Content().SetSize(0); + texture->Comment() = Language->Error_Unzip; + CloseZip(ZIP_Handle); //somehow we need to close and to reopen the zip handle, otherwise the program crashes + ZIP_Handle = OpenZip( FileInMemory, FileLen, pw); + } + } + } + + + CloseZip(ZIP_Handle); + if (node->myChildren.GetCount()==0) + { + LastError << Language->Error_FileIsEmpty << FileName << "\n"; + return -1; + } + return 0; + } + + + //we load each dds file { CloseZip(ZIP_Handle); //somehow we need to close and to reopen the zip handle, otherwise the program crashes ZIP_Handle = OpenZip( FileInMemory, FileLen, pw); - if (ZIP_Handle==NULL) {LastError << Language->Error_Unzip; return -1;} + if (ZIP_Handle==(HZIP)0) {LastError << Language->Error_Unzip; return -1;} wxString name; wxString file; GetZipItem( ZIP_Handle, -1, &ze); //ask for number of entries int num = ze.index; - tex.SetSize(num); - int count = 0; - unsigned long temp_hash; + DWORD64 temp_hash; for (int i=0; iContent().SetSize(ze.unc_size)) { + LastError << Language->Error_Memory; + texture->Release(); + continue; + } + char *data = texture->Content().Data(); + + ZRESULT rz = UnzipItem( ZIP_Handle, i, data, len); + if (rz!=ZR_OK && rz!=ZR_MORE) + { + texture->Release(); + LastError << Language->Error_Unzip <<"\nZIP:" << FileName << "\n"; continue; } - - ZRESULT rz = UnzipItem( ZIP_Handle, i, buffer, len); - if (rz!=ZR_OK && rz!=ZR_MORE) + file = ze.name; + if (file.Len()==0) { - delete [] buffer; - buffer = NULL; - LastError << Language->Error_Unzip <<"\nZIP:" << file << "\n"; + texture->Release(); + continue; } - file = ze.name; - if (file.Len()==0) continue; + if (file == "Comment.txt") // load comment + { + char *buffer; + try {buffer = new char [len+1];} + catch (...) + { + LastError << Language->Error_Memory; + texture->Release(); + continue; + } + for (int i=0; imyElement->Comment() = buffer; + + node->myElement->Comment().Replace("\r\n", " ; ", true); + node->myElement->Comment().Replace("\n", " ; ", true); + + delete [] buffer; + texture->Release(); + continue; + } name = file.AfterLast( '.'); - if (name!="dds") continue; //if this is not texture file, continue + if (name!="dds") + { + texture->Release(); + continue; + } name = file.AfterLast( '_'); name = name.BeforeLast( '.'); - if (!name.ToULong( &temp_hash, 16)) {LastError << Language->Error_Hash <<"\nZIP:" << file << "\n"; continue;} //if hash could not be extracted - - if (add) + if (!name.ToULongLong( &temp_hash, 16)) { - if (buffer==NULL) continue; + texture->Release(); + LastError << Language->Error_Hash <<"\nZIP:" << file << "\n"; + continue; + } //if hash could not be extracted - tex.Textures[count] = buffer; - tex.Hash[count] = temp_hash; - tex.Size[count] = len;//ze.unc_size; - count++; - } - else - { - if (buffer!=NULL) delete [] buffer; - tex.Hash[count] = temp_hash; - tex.Size[count] = 0; - count++; - } + + texture->Hash() = temp_hash; + texture->Title() = ze.name; + texture->File() = ze.name; + texture->Status() = uMod_TextureElement::Activate; + + uMod_TreeViewNode *node_texture = new uMod_TreeViewNode( node, texture); + node->Append(node_texture); + texture->Release(); } - tex.Num = count; - } - CloseZip(ZIP_Handle); + CloseZip(ZIP_Handle); + + if (node->myChildren.GetCount()==0) + { + LastError << Language->Error_FileIsEmpty << FileName << "\n"; + return -1; + } + return 0; + } return 0; } diff --git a/uMod_GUI/uMod_File.h b/uMod_GUI/uMod_File.h index f2e4ac2..7fed246 100644 --- a/uMod_GUI/uMod_File.h +++ b/uMod_GUI/uMod_File.h @@ -29,9 +29,15 @@ public: ~uMod_File(void); bool FileSupported(void); + bool SingleFile(void); + //int AddSingleFileToNode( uMod_TreeViewNode* node); + int GetContentTemplate(const wxString &content, uMod_TreeViewNode* node); + /* int GetComment( wxString &tool_tip); int GetContent( AddTextureClass &tex, bool add); +*/ + int GetContent( uMod_TreeViewNode* node); int SetFile(const wxString &file) {FileName=file;Loaded=false; return 0;} wxString GetFile(void) {return FileName;} @@ -43,12 +49,18 @@ private: int ReadFile(void); int UnXOR(void); + /* int GetCommentZip( wxString &tool_tip); int GetCommentTpf( wxString &tool_tip); +*/ + int AddFile( uMod_TreeViewNode* node); + int AddZip( uMod_TreeViewNode* node); + int AddTpf( uMod_TreeViewNode* node); - int AddFile( AddTextureClass &tex, bool add); - int AddZip( AddTextureClass &tex, bool add, bool tpf); - int AddContent( const char* pw, AddTextureClass &tex, bool add); + int AddContent( const char* pw, uMod_TreeViewNode* node); + + int GetContentTemplate_ZIP( const uMod_TreeViewNode_ArrayPtr &list_node, uMod_TreeViewNode* node); + int GetContentTemplate_SF( const uMod_TreeViewNode_ArrayPtr &list_node, uMod_TreeViewNode* node); wxString FileName; bool Loaded; diff --git a/uMod_GUI/uMod_GUI.cpp b/uMod_GUI/uMod_GUI.cpp index 19fa517..67d6012 100644 --- a/uMod_GUI/uMod_GUI.cpp +++ b/uMod_GUI/uMod_GUI.cpp @@ -33,10 +33,10 @@ DEFINE_EVENT_TYPE(uMod_EVENT_TYPE) BEGIN_EVENT_TABLE(uMod_Frame, wxFrame) EVT_CLOSE(uMod_Frame::OnClose) - EVT_BUTTON(ID_Button_Open, uMod_Frame::OnButtonOpen) - EVT_BUTTON(ID_Button_Path, uMod_Frame::OnButtonPath) - EVT_BUTTON(ID_Button_Update, uMod_Frame::OnButtonUpdate) - EVT_BUTTON(ID_Button_Reload, uMod_Frame::OnButtonReload) + //EVT_BUTTON(ID_Button_Open, uMod_Frame::OnButtonOpen) + //EVT_BUTTON(ID_Button_Path, uMod_Frame::OnButtonPath) + //EVT_BUTTON(ID_Button_Update, uMod_Frame::OnButtonUpdate) + //EVT_BUTTON(ID_Button_Reload, uMod_Frame::OnButtonReload) EVT_MENU(ID_Menu_Help, uMod_Frame::OnMenuHelp) EVT_MENU(ID_Menu_About, uMod_Frame::OnMenuAbout) @@ -137,23 +137,18 @@ uMod_Frame::uMod_Frame(const wxString& title, uMod_Settings &set) MainSizer = new wxBoxSizer(wxVERTICAL); - Notebook = new wxNotebook( this, wxID_ANY); + Notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE); Notebook->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENU)); MainSizer->Add( (wxWindow*) 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)); - ReloadButton = new wxButton( this, ID_Button_Reload, Language->ButtonReload, wxDefaultPosition, wxSize(100,24)); - - ButtonSizer->Add( (wxWindow*) OpenButton, 1, wxEXPAND, 0); - ButtonSizer->Add( (wxWindow*) DirectoryButton, 1, wxEXPAND, 0); - ButtonSizer->Add( (wxWindow*) UpdateButton, 1, wxEXPAND, 0); - ButtonSizer->Add( (wxWindow*) ReloadButton, 1, wxEXPAND, 0); - MainSizer->Add( ButtonSizer, 0, wxEXPAND , 0 ); - + PipeStruct pipe = {INVALID_HANDLE_VALUE,INVALID_HANDLE_VALUE}; + uMod_GamePage *page = new uMod_GamePage( Notebook, "uMod", INVALID_GAME_PAGE, "templates/uMod.txt", pipe); + if (page->LastError.Len()>0) + { + wxMessageBox(page->LastError, "ERROR", wxOK|wxICON_ERROR); + delete page; + } + else Notebook->AddPage( page, page->GetPageName(), true); SetSizer( MainSizer); @@ -213,12 +208,22 @@ int uMod_Frame::KillServer(void) if (pipe == INVALID_HANDLE_VALUE) return -1; + // prepend a zero int value as dummy injection method const wchar_t *str = ABORT_SERVER; unsigned int len=0u; while (str[len]) len++; len++; //to send also the zero + + char *buffer=(char*)0; + GetMemory(buffer, sizeof(int) + len * sizeof(wchar_t)); + *((int*) buffer) = 0; + char *p_game = (char*) str; + + for (unsigned int i=0; iCreate(); @@ -255,7 +261,7 @@ void uMod_Frame::OnAddGame( wxCommandEvent &event) break; } - uMod_GamePage *page = new uMod_GamePage( Notebook, name, save_file, client->Pipe); + uMod_GamePage *page = new uMod_GamePage( Notebook, name, injection_method, save_file, client->Pipe); if (page->LastError.Len()>0) { wxMessageBox(page->LastError, "ERROR", wxOK|wxICON_ERROR); @@ -274,7 +280,7 @@ void uMod_Frame::OnDeleteGame( wxCommandEvent &event) uMod_Client *client = ((uMod_Event&)event).GetClient(); for (int i=0; iDeletePage(i); + Notebook->DeletePage(i+1); Clients[i]->Wait(); delete Clients[i]; NumberOfGames--; @@ -287,45 +293,60 @@ void uMod_Frame::OnDeleteGame( wxCommandEvent &event) void uMod_Frame::OnAddDevice( wxCommandEvent &event) { + uMod_Client *client = ((uMod_Event&)event).GetClient(); for (int i=0; iGetPage(i); + uMod_GamePage *page = (uMod_GamePage*) Notebook->GetPage(i+1); page->AddDXDevice(((uMod_Event&)event).GetValue()); - Notebook->SetPageText( i, page->GetPageName()); return; } } void uMod_Frame::OnRemoveDevice( wxCommandEvent &event) { + /* uMod_Client *client = ((uMod_Event&)event).GetClient(); for (int i=0; iGetPage(i); + wxMessageBox("removed"); + uMod_GamePage *page = (uMod_GamePage*) Notebook->GetPage(i+1); page->RemoveDXDevice(((uMod_Event&)event).GetValue()); - Notebook->SetPageText( i, page->GetPageName()); return; } + */ } void uMod_Frame::OnClose(wxCloseEvent& event) { if (event.CanVeto() && NumberOfGames>0) { - if (wxMessageBox(Language->ExitGameAnyway, "ERROR", wxYES_NO|wxICON_ERROR)!=wxYES) {event.Veto(); return;} + if (wxMessageBox(Language->ExitGameAnyway, "ERROR", wxYES_NO|wxICON_ERROR)!=wxYES) + { + event.Veto(); + return; + } } - event.Skip(); + //event.Skip(); Destroy(); } - +/* void uMod_Frame::OnButtonOpen(wxCommandEvent& WXUNUSED(event)) { if (Notebook->GetPageCount()==0) return; uMod_GamePage *page = (uMod_GamePage*) Notebook->GetCurrentPage(); if (page==NULL) return; + wxString temp = "D:\\Code\\uMod\\temp\\bf.tpf"; + if (page->AddTexture( temp)) wxMessageBox(page->LastError); + temp = "D:\\Code\\uMod\\temp\\tex.zip"; + if (page->AddTexture( temp)) wxMessageBox(page->LastError); + + temp = "D:\\Code\\uMod\\temp\\test.zip"; + if (page->AddTexture( temp)) wxMessageBox(page->LastError); + + return; //wxString file_name = wxFileSelector( Language->ChooseFile, page->GetOpenPath(), "", "*.*", "textures (*.dds)|*.dds|zip (*.zip)|*.zip|tpf (*.tpf)|*.tpf", wxFD_OPEN | wxFD_FILE_MUST_EXIST, this); wxString file_name = wxFileSelector( Language->ChooseFile, page->GetOpenPath(), "", "", "", wxFD_OPEN | wxFD_FILE_MUST_EXIST, this); if ( !file_name.empty() ) @@ -375,7 +396,7 @@ void uMod_Frame::OnButtonReload(wxCommandEvent& WXUNUSED(event)) page->LastError.Empty(); } } - +*/ @@ -431,7 +452,6 @@ void uMod_Frame::OnMenuSaveTemplateAs(wxCommandEvent& WXUNUSED(event)) uMod_GamePage *page = (uMod_GamePage*) Notebook->GetCurrentPage(); if (page==NULL) return; - wxString dir = wxGetCwd(); dir << "/templates"; wxString file_name = wxFileSelector( Language->ChooseFile, dir, "", "*.txt", "text (*.txt)|*.txt", wxFD_SAVE | wxFD_OVERWRITE_PROMPT, this); @@ -450,6 +470,7 @@ void uMod_Frame::OnMenuSetDefaultTemplate(wxCommandEvent& WXUNUSED(event)) if (Notebook->GetPageCount()==0) return; uMod_GamePage *page = (uMod_GamePage*) Notebook->GetCurrentPage(); if (page==NULL) return; + if (page == (uMod_GamePage*) Notebook->GetPage(0)) return; wxString exe = page->GetExeName(); wxString file = page->GetTemplateName(); @@ -508,12 +529,12 @@ void uMod_Frame::OnMenuLanguage(wxCommandEvent& WXUNUSED(event)) MenuHelp->SetLabel( ID_Menu_About, Language->MenuAbout); MenuHelp->SetLabel( ID_Menu_Acknowledgement, Language->MenuAcknowledgement); - +/* OpenButton->SetLabel( Language->ButtonOpen); DirectoryButton->SetLabel( Language->ButtonDirectory); UpdateButton->SetLabel( Language->ButtonUpdate); ReloadButton->SetLabel( Language->ButtonReload); - +*/ int num = Notebook->GetPageCount(); for (int i=0; iMenuAcknowledgement, wxOK); } void uMod_Frame::OnMenuStartGame(wxCommandEvent& event) { + bool use_cmd = false; if (event.GetId() == ID_Menu_StartGameCMD) use_cmd = true; @@ -636,8 +659,8 @@ void uMod_Frame::OnMenuStartGame(wxCommandEvent& event) wxString dll = wxGetCwd(); - //dll.Append( L"\\" uMod_d3d9_DI_dll); - dll.Append( L"\\uMod_d3d10_DI.dll"); + dll.Append( L"\\" uMod_d3d9_DI_dll); + //dll.Append( L"\\uMod_d3d10_DI.dll"); Inject(pi.hProcess, dll.wc_str(), "Nothing"); ResumeThread(pi.hThread); @@ -720,32 +743,23 @@ void uMod_Frame::OnMenuDeleteGame(wxCommandEvent& WXUNUSED(event)) int uMod_Frame::ActivateGamesControl(void) { + /* MenuMain->Enable( ID_Menu_LoadTemplate, true); MenuMain->Enable( ID_Menu_SaveTemplate, true); MenuMain->Enable( ID_Menu_SaveTemplateAs, true); + */ MenuMain->Enable( ID_Menu_SetDefaultTemplate, true); - - - OpenButton->Enable( true); - DirectoryButton->Enable( true); - UpdateButton->Enable( true); - ReloadButton->Enable( true); - return 0; } int uMod_Frame::DeactivateGamesControl(void) { + /* MenuMain->Enable( ID_Menu_LoadTemplate, false); MenuMain->Enable( ID_Menu_SaveTemplate, false); MenuMain->Enable( ID_Menu_SaveTemplateAs, false); +*/ MenuMain->Enable( ID_Menu_SetDefaultTemplate, false); - - - OpenButton->Enable( false); - DirectoryButton->Enable( false); - UpdateButton->Enable( false); - ReloadButton->Enable( false); return 0; } @@ -963,8 +977,7 @@ void uMod_Frame::InstallHook(void) { if (H_DX9_DLL==NULL) { - //H_DX9_DLL = LoadLibraryW(uMod_d3d9_Hook_dll); - H_DX9_DLL = LoadLibraryW(L"uMod_d3d10_HI.dll"); + H_DX9_DLL = LoadLibraryW(uMod_d3d9_Hook_dll); if (H_DX9_DLL!=NULL) { typedef void (*fkt_typ)(void); diff --git a/uMod_GUI/uMod_GUI.h b/uMod_GUI/uMod_GUI.h index 4f74519..389fca9 100644 --- a/uMod_GUI/uMod_GUI.h +++ b/uMod_GUI/uMod_GUI.h @@ -60,12 +60,12 @@ public: */ void OnClose(wxCloseEvent& WXUNUSED(event)); - +/* void OnButtonOpen(wxCommandEvent& WXUNUSED(event)); void OnButtonPath(wxCommandEvent& WXUNUSED(event)); void OnButtonUpdate(wxCommandEvent& WXUNUSED(event)); void OnButtonReload(wxCommandEvent& WXUNUSED(event)); - +*/ void OnMenuStartGame( wxCommandEvent &event); void OnMenuUseHook( wxCommandEvent &event); @@ -101,19 +101,19 @@ private: wxNotebook *Notebook; - +/* wxButton *OpenButton; wxButton *DirectoryButton; wxButton *UpdateButton; wxButton *ReloadButton; - +*/ wxMenuBar *MenuBar; wxMenu *MenuMain; wxMenu *MenuHelp; wxBoxSizer *MainSizer; - wxBoxSizer *ButtonSizer; + //wxBoxSizer *ButtonSizer; int NumberOfGames; diff --git a/uMod_GUI/uMod_GameInfo.cpp b/uMod_GUI/uMod_GameInfo.cpp index 7a5699c..32a62eb 100644 --- a/uMod_GUI/uMod_GameInfo.cpp +++ b/uMod_GUI/uMod_GameInfo.cpp @@ -24,263 +24,296 @@ along with Universal Modding Engine. If not, see uMod_GameInfo::uMod_GameInfo(void) { - Checked = NULL; - NumberOfChecked = 0; - LengthOfChecked = 0; Init(); } uMod_GameInfo::~uMod_GameInfo(void) { - if (Checked!=NULL) delete [] Checked; } void uMod_GameInfo::Init(void) { + myShowCollPane = false; + SaveSingleTexture = false; SaveAllTextures = false; + myShowSingleTextureString = false; + mySupportTPF = false; KeyBack = -1; KeySave = -1; KeyNext = -1; - FontColour[0]=255;FontColour[1]=0;FontColour[2]=0; - TextureColour[0]=0;TextureColour[1]=255;TextureColour[2]=0; - NumberOfChecked = 0; + FontColour[0]=255;FontColour[1]=0;FontColour[2]=0;FontColour[3]=255; + TextureColour[0]=0;TextureColour[1]=255;TextureColour[2]=0;TextureColour[3]=255; + + myUseSizeFilter = false; + myHeightMin = 1; + myHeightMax = 1; + myWidthMin = 1; + myWidthMax = 1; + myDepthMin = 1; + myDepthMax = 1; + + myUseFormatFilter = false; + myFormatFilter = 0u; + myFileFormat = uMod_D3DXIFF_DDS; + SavePath.Empty(); OpenPath.Empty(); - Files.Empty(); } -int uMod_GameInfo::SaveToFile( const wxString &file_name) +int uMod_GameInfo::SaveToString( wxString &content ) { - wxFile file; + content.Empty(); - //if (!file.Access(name, wxFile::write)) return -1; - file.Open(file_name, wxFile::write); - if (!file.IsOpened()) {return -1;} + wxString temp; + + temp.Printf( "ShowCollPane:%d\n", myShowCollPane); + content << temp; - wxString content; if (SavePath.Len()>0) { - content.Printf( L"SavePath:%ls\n", SavePath.wc_str()); - file.Write( content.char_str(), content.Len()); + temp.Printf( "SavePath:%ls\n", SavePath.wc_str()); + content << temp; } if (OpenPath.Len()>0) { - content.Printf( L"OpenPath:%ls\n", OpenPath.wc_str()); - file.Write( content.char_str(), content.Len()); + temp.Printf( "OpenPath:%ls\n", OpenPath.wc_str()); + content << temp; } - content.Printf( L"SaveAllTextures:%d\nSaveSingleTexture:%d\n", SaveAllTextures, SaveSingleTexture); - file.Write( content.char_str(), content.Len()); + temp.Printf( "SaveAllTextures:%d\nSaveSingleTexture:%d\n", SaveAllTextures, SaveSingleTexture); + content << temp; + + temp.Printf( "ShowSingleTextureString:%d\n", myShowSingleTextureString); + content << temp; + + temp.Printf( "SupportTPF:%d\n", mySupportTPF); + content << temp; if (KeyBack>=0) { - content.Printf( L"KeyBack:%d\n", KeyBack); - file.Write( content.char_str(), content.Len()); + temp.Printf( "KeyBack:%d\n", KeyBack); + content << temp; } if (KeySave>=0) { - content.Printf( L"KeySave:%d\n", KeySave); - file.Write( content.char_str(), content.Len()); + temp.Printf( "KeySave:%d\n", KeySave); + content << temp; } if (KeyNext>=0) { - content.Printf( L"KeyNext:%d\n", KeyNext); - file.Write( content.char_str(), content.Len()); + temp.Printf( "KeyNext:%d\n", KeyNext); + content << temp; } + temp.Printf("UseSizeFilter:%d\n", myUseSizeFilter); + content << temp; + temp.Printf( "Height:%d,%d\n", myHeightMin, myHeightMax); + content << temp; + temp.Printf( "Width:%d,%d\n", myWidthMin, myWidthMax); + content << temp; + temp.Printf( "Depth:%d,%d\n", myDepthMin, myDepthMax); + content << temp; - content.Printf( L"FontColour:%d,%d,%d\n", FontColour[0], FontColour[1], FontColour[2]); - file.Write( content.char_str(), content.Len()); - content.Printf( L"TextureColour:%d,%d,%d\n", TextureColour[0], TextureColour[1], TextureColour[2]); - file.Write( content.char_str(), content.Len()); - int num = Files.GetCount(); - - for (int i=0; i0u) { - if (i0u) + { + temp.Printf( "FileFormat:%lu\n", myFileFormat); + content << temp; } - file.Close(); + temp.Printf( L"FontColour:%u,%u,%u,%u\n", FontColour[0], FontColour[1], FontColour[2],FontColour[3]); + content << temp; + temp.Printf( L"TextureColour:%u,%u,%u,%u\n", TextureColour[0], TextureColour[1], TextureColour[2], TextureColour[3]); + content << temp; return 0; } -int uMod_GameInfo::LoadFromFile( const wxString &file_name) +int uMod_GameInfo::LoadFromString( const wxString &content) { Init(); - if (file_name.Len()==0) return -1; - - wxFile file; - if (!file.Access(file_name, wxFile::read)) return -1; - file.Open(file_name, wxFile::read); - if (!file.IsOpened()) {return -1;} - - unsigned len = file.Length(); - - unsigned char* buffer; - try {buffer = new unsigned char [len+1];} - catch (...) {return -1;} - - unsigned int result = file.Read( buffer, len); - file.Close(); - - if (result != len) {delete [] buffer; return -1;} - - buffer[len]=0; - - wxString content; - content = buffer; - delete [] buffer; wxStringTokenizer token( content, "\n"); int num = token.CountTokens(); - if (LengthOfChecked0 && temp[0]=='0') myShowCollPane = false; + else myShowCollPane = true; + } + else if (command == "SavePath") SavePath = line.AfterFirst(':'); + else if (command == "OpenPath") OpenPath = line.AfterFirst(':'); + else if (command == "SaveAllTextures") + { + temp = line.AfterFirst(':'); + if (temp.Len()>0 && temp[0]=='0') SaveAllTextures = false; else SaveAllTextures = true; } - else if (command == L"SaveSingleTexture") + else if (command == "SaveSingleTexture") { temp = line.AfterFirst(':'); - if (temp[0]=='0') SaveSingleTexture = false; + if (temp.Len()>0 && temp[0]=='0') SaveSingleTexture = false; else SaveSingleTexture = true; } - else if (command == L"KeyBack") + else if (command == "ShowSingleTextureString") + { + temp = line.AfterFirst(':'); + if (temp.Len()>0 && temp[0]=='0') myShowSingleTextureString = false; + else myShowSingleTextureString = true; + } + else if (command == "SupportTPF") + { + temp = line.AfterFirst(':'); + if (temp.Len()>0 && temp[0]=='0') mySupportTPF = false; + else mySupportTPF = true; + } + else if (command == "KeyBack") { temp = line.AfterFirst(':'); long key; if (temp.ToLong( &key)) KeyBack = key; else KeyBack = -1; } - else if (command == L"KeySave") + else if (command == "KeySave") { temp = line.AfterFirst(':'); long key; if (temp.ToLong( &key)) KeySave = key; else KeySave = -1; } - else if (command == L"KeyNext") + else if (command == "KeyNext") { temp = line.AfterFirst(':'); long key; if (temp.ToLong( &key)) KeyNext = key; else KeyNext = -1; } - else if (command == L"FontColour") + else if (command == "UseSizeFilter") { temp = line.AfterFirst(':'); - temp = temp.BeforeFirst(','); - long colour; - if (temp.ToLong( &colour)) FontColour[0] = colour; - else FontColour[0] = 255; - temp = line.AfterFirst(':'); - temp = temp.AfterFirst(','); - temp = temp.BeforeFirst(','); - if (temp.ToLong( &colour)) FontColour[1] = colour; - else FontColour[1] = 0; - temp = line.AfterFirst(':'); - temp = temp.AfterLast(','); - if (temp.ToLong( &colour)) FontColour[2] = colour; - else FontColour[2] = 0; + if (temp.Len()>0 && temp[0]=='0') myUseSizeFilter = false; + else myUseSizeFilter = true; } - else if (command == L"TextureColour") + else if (command == "Height") + { + line = line.AfterFirst(':'); + temp = line.Before(','); + long val; + if (temp.ToLong( &val)) myHeightMin = val; + else myHeightMin = 1; + temp = line.After(','); + if (temp.ToLong( &val)) myHeightMax = val; + else myHeightMax = 1; + } + else if (command == "Width") + { + line = line.AfterFirst(':'); + temp = line.Before(','); + long val; + if (temp.ToLong( &val)) myWidthMin = val; + else myWidthMin = 1; + temp = line.After(','); + if (temp.ToLong( &val)) myWidthMax = val; + else myWidthMax = 1; + } + else if (command == "Depth") + { + line = line.AfterFirst(':'); + temp = line.Before(','); + long val; + if (temp.ToLong( &val)) myDepthMin = val; + else myDepthMin = 1; + temp = line.After(','); + if (temp.ToLong( &val)) myDepthMax = val; + else myDepthMax = 1; + } + else if (command == "UseFormatFilter") { temp = line.AfterFirst(':'); - temp = temp.BeforeFirst(','); - long colour; - if (temp.ToLong( &colour)) TextureColour[0] = colour; - else TextureColour[0] = 0; - temp = line.AfterFirst(':'); - temp = temp.AfterFirst(','); - temp = temp.BeforeFirst(','); - if (temp.ToLong( &colour)) TextureColour[1] = colour; - else TextureColour[1] = 255; - temp = line.AfterFirst(':'); - temp = temp.AfterLast(','); - if (temp.ToLong( &colour)) TextureColour[2] = colour; - else TextureColour[2] = 0; + if (temp.Len()>0 && temp[0]=='0') myUseFormatFilter = false; + else myUseFormatFilter = true; } + else if (command == "FormatFilter") + { + temp = line.AfterFirst(':'); + unsigned long val; + if (temp.ToULong( &val)) myFormatFilter = val; + else myFormatFilter = 0u; + } + else if (command == "FileFormat") + { + temp = line.AfterFirst(':'); + unsigned long val; + if (temp.ToULong( &val)) myFileFormat = val; + else myFileFormat = 0u; + } + else if (command == "ShowSingleTextureString") + { + temp = line.AfterFirst(':'); + if (temp.Len()>0 && temp[0]=='0') myShowSingleTextureString = false; + else myShowSingleTextureString = true; + } + else if (command == "FontColour") + { + temp = line.AfterFirst(':'); -/* - if (NumberOfChecked>=LengthOfChecked) - { - bool *t_bool; - try {t_bool = new bool [LengthOfChecked+100];} - catch (...) {return -1;} - for (int i=0; iLengthOfChecked) + if (SaveAllTextures && SaveSingleTexture) { - if (Checked!=NULL) delete [] Checked; - try {Checked = new bool [num+100];} - catch (...) {Checked=NULL; LengthOfChecked = 0; return -1;} - LengthOfChecked = num+100; + SaveAllTextures = false; + SaveSingleTexture = false; } - for (int i=0; i #ifndef uMod_GAME_H_ #define uMod_GAME_H_ + +#include "uMod_TreeView.h" #include "uMod_Main.h" //this class is intended as a storing object for each game @@ -32,11 +34,19 @@ public: void Init(void); - int SaveToFile( const wxString &file_name); - int LoadFromFile( const wxString &file_name); + int SaveToString( wxString &content); + int LoadFromString( const wxString &content); + + //int GetActiveTexture( uMod_TextureElement_SortedArrayPtr &texture); + + + + bool &ShowCollPane(void) {return myShowCollPane;} + + + bool &SupportTPF(void) {return mySupportTPF;} + const bool &SupportTPF(void) const {return mySupportTPF;} - int GetChecked( bool* array, int num) const; - int SetChecked( bool* array, int num); int SetSaveSingleTexture(bool val); bool GetSaveSingleTexture(void) const {return SaveSingleTexture;} @@ -44,13 +54,6 @@ public: int SetSaveAllTextures(bool val); bool GetSaveAllTextures(void) const {return SaveAllTextures;} - void SetFiles(const wxArrayString &files); - void GetFiles( wxArrayString &files) const; - //void AddTexture( const wxString &textures); - - int GetNumberOfFiles(void) const {return Files.GetCount();} - - int SendTextures(void); int GetKeyBack() const {return KeyBack;} int SetKeyBack(int key) {KeyBack=key; return 0;} @@ -61,11 +64,43 @@ public: int GetKeyNext() const {return KeyNext;} int SetKeyNext(int key) {KeyNext=key; return 0;} - int SetFontColour(const int *colour) {FontColour[0]=colour[0];FontColour[1]=colour[1];FontColour[2]=colour[2];return 0;} - int GetFontColour(int *colour) const {colour[0]=FontColour[0];colour[1]=FontColour[1];colour[2]=FontColour[2];return 0;} + bool &ShowSingleTextureString() {return myShowSingleTextureString;} + const bool &ShowSingleTextureString() const {return myShowSingleTextureString;} + + int SetFontColour(const unsigned char *colour) {FontColour[0]=colour[0];FontColour[1]=colour[1];FontColour[2]=colour[2];FontColour[3]=colour[3];return 0;} + int GetFontColour(unsigned char *colour) const {colour[0]=FontColour[0];colour[1]=FontColour[1];colour[2]=FontColour[2];colour[3]=FontColour[3];return 0;} + + int SetTextureColour(const unsigned char *colour) {TextureColour[0]=colour[0];TextureColour[1]=colour[1];TextureColour[2]=colour[2];TextureColour[3]=colour[3];return 0;} + int GetTextureColour(unsigned char *colour) const {colour[0]=TextureColour[0];colour[1]=TextureColour[1];colour[2]=TextureColour[2];colour[3]=TextureColour[3];return 0;} + + + bool &UseSizeFilter(void) {return myUseSizeFilter;} + const bool &UseSizeFilter(void) const {return myUseSizeFilter;} + + int &HeightMin(void) {return myHeightMin;} + const int &HeightMin(void) const {return myHeightMin;} + int &HeightMax(void) {return myHeightMax;} + const int &HeightMax(void) const {return myHeightMax;} + + int &WidthMin(void) {return myWidthMin;} + const int &WidthMin(void) const {return myWidthMin;} + int &WidthMax(void) {return myWidthMax;} + const int &WidthMax(void) const {return myWidthMax;} + + int &DepthMin(void) {return myDepthMin;} + const int &DepthMin(void) const {return myDepthMin;} + int &DepthMax(void) {return myDepthMax;} + const int &DepthMax(void) const {return myDepthMax;} + + bool &UseFormatFilter(void) {return myUseFormatFilter;} + const bool &UseFormatFilter(void) const {return myUseFormatFilter;} + + unsigned long &FormatFilter(void) {return myFormatFilter;} + const unsigned long &FormatFilter(void) const {return myFormatFilter;} + + unsigned long &FileFormat(void) {return myFileFormat;} + const unsigned long &FileFormat(void) const {return myFileFormat;} - int SetTextureColour(const int *colour) {TextureColour[0]=colour[0];TextureColour[1]=colour[1];TextureColour[2]=colour[2];return 0;} - int GetTextureColour(int *colour) const {colour[0]=TextureColour[0];colour[1]=TextureColour[1];colour[2]=TextureColour[2];return 0;} int SetOpenPath(const wxString &path) {OpenPath=path; return 0;} wxString GetOpenPath(void) const {return OpenPath;} @@ -76,22 +111,32 @@ public: uMod_GameInfo& operator = (const uMod_GameInfo &rhs); private: + bool myShowCollPane; - bool *Checked; - int NumberOfChecked; - int LengthOfChecked; + bool mySupportTPF; bool SaveSingleTexture; bool SaveAllTextures; - wxArrayString Files; - int KeyBack; int KeySave; int KeyNext; - int FontColour[3]; - int TextureColour[3]; + bool myUseSizeFilter; + int myHeightMin; + int myHeightMax; + int myWidthMin; + int myWidthMax; + int myDepthMin; + int myDepthMax; + + bool myUseFormatFilter; + unsigned long myFormatFilter; + unsigned long myFileFormat; + + bool myShowSingleTextureString; + unsigned char FontColour[4]; + unsigned char TextureColour[4]; wxString OpenPath; wxString SavePath; diff --git a/uMod_GUI/uMod_GamePage.cpp b/uMod_GUI/uMod_GamePage.cpp index 19a5fed..2214a40 100644 --- a/uMod_GUI/uMod_GamePage.cpp +++ b/uMod_GUI/uMod_GamePage.cpp @@ -19,114 +19,299 @@ along with Universal Modding Engine. If not, see #include "uMod_Main.h" -uMod_GamePage::uMod_GamePage( wxNotebook *parent, const wxString &exe, const wxString &save, PipeStruct &pipe) - : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL), Sender(pipe) + +#ifndef __CDT_PARSER__ + + +BEGIN_EVENT_TABLE(uMod_GamePage, wxPanel) + +EVT_COLLAPSIBLEPANE_CHANGED(ID_CollPane, uMod_GamePage::OnCollPane) + +EVT_CHECKBOX( ID_SaveSingleTexture, uMod_GamePage::OnCheckBox) +EVT_CHECKBOX( ID_SaveAllTexture, uMod_GamePage::OnCheckBox) + +EVT_CHECKBOX( ID_ShowSingleTextureString, uMod_GamePage::OnCheckBox) +EVT_CHECKBOX( ID_UseSizeFilter, uMod_GamePage::OnCheckBox) +EVT_CHECKBOX( ID_UseFormatFilter, uMod_GamePage::OnCheckBox) +EVT_BUTTON(ID_SetFormatFilter, uMod_GamePage::OnButtonFormatFilter) + +EVT_BUTTON(ID_Button_SavePath, uMod_GamePage::OnButtonSavePath) + + +EVT_BUTTON(ID_FontColour, uMod_GamePage::OnButtonColour) +EVT_BUTTON(ID_TextureColour, uMod_GamePage::OnButtonColour) + +EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_DataViewCtrl, uMod_GamePage::OnContextMenu) +//EVT_MENU(ID_RemovePackage, uMod_GamePage::OnRemovePackage) + + +EVT_DATAVIEW_ITEM_BEGIN_DRAG( ID_DataViewCtrl, uMod_GamePage::OnBeginDrag ) +EVT_DATAVIEW_ITEM_DROP_POSSIBLE( ID_DataViewCtrl, uMod_GamePage::OnDropPossible ) +EVT_DATAVIEW_ITEM_DROP( ID_DataViewCtrl, uMod_GamePage::OnDrop ) + +EVT_DROP_FILES(uMod_GamePage::OnDropFile) + +END_EVENT_TABLE() + +#endif + +uMod_GamePage::uMod_GamePage( wxNotebook *parent, const wxString &exe, int injection_method, const wxString &save, PipeStruct &pipe) + : wxPanel(parent, wxID_ANY)//, wxDefaultPosition, wxDefaultSize, wxVSCROLL) + , InjectionMethod(injection_method), Sender(pipe) { ExeName = exe; TemplateName = save; - + ViewCtrl = (wxDataViewCtrl*)0; CounterDX9 = 0; CounterDX9EX = 0; - CounterDX10 = 0; CounterDX10EX = 0; + CounterDX10 = 0; CounterDX101 = 0; //SetBackgroundColour( *wxLIGHT_GREY); //SetBackgroundColour( wxColour( "LIGHT GREY")); - CheckBoxHSizers = NULL; - CheckButtonUp = NULL; - CheckButtonDown = NULL; - CheckButtonDelete = NULL; - CheckBoxes = NULL; MainSizer = new wxBoxSizer(wxVERTICAL); + //initialize injection string + switch (InjectionMethod) + { + case HOOK_INJECTION: + DX_DLL_Info = new wxTextCtrl(this, wxID_ANY, Language->HookInjection, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); + break; + case DIRECT_INJECTION: + DX_DLL_Info = new wxTextCtrl(this, wxID_ANY, Language->DirectInjection, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); + break; + case NO_INJECTION: + DX_DLL_Info = new wxTextCtrl(this, wxID_ANY, Language->NoInjection, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); + break; + case INVALID_GAME_PAGE: + DX_DLL_Info = new wxTextCtrl(this, wxID_ANY, Language->InvalidGamePage, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); + break; + default: + DX_DLL_Info = new wxTextCtrl(this, wxID_ANY, "BUG^^ injection:", wxDefaultPosition, wxDefaultSize, wxTE_READONLY); + break; + } + MainSizer->Add( (wxWindow*) DX_DLL_Info, 0, wxEXPAND, 0); + // initialize template string TemplateFile = new wxTextCtrl(this, wxID_ANY, Language->TextCtrlTemplate, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); MainSizer->Add( (wxWindow*) TemplateFile, 0, wxEXPAND, 0); MainSizer->AddSpacer(10); - SizerKeys[0] = new wxBoxSizer(wxHORIZONTAL); - SizerKeys[1] = new wxBoxSizer(wxHORIZONTAL); + // + // capture texture part + // - TextKeyBack = new wxTextCtrl(this, wxID_ANY, Language->KeyBack, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); - SizerKeys[0]->Add( (wxWindow*) TextKeyBack, 1, wxEXPAND, 0); - ChoiceKeyBack = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, Language->KeyStrings); - SizerKeys[1]->Add( (wxWindow*) ChoiceKeyBack, 1, wxEXPAND, 0); - - TextKeySave = new wxTextCtrl(this, wxID_ANY, Language->KeySave, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); - SizerKeys[0]->Add( (wxWindow*) TextKeySave, 1, wxEXPAND, 0); - ChoiceKeySave = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, Language->KeyStrings); - SizerKeys[1]->Add( (wxWindow*) ChoiceKeySave, 1, wxEXPAND, 0); - - TextKeyNext = new wxTextCtrl(this, wxID_ANY, Language->KeyNext, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); - SizerKeys[0]->Add( (wxWindow*) TextKeyNext, 1, wxEXPAND, 0); - ChoiceKeyNext = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, Language->KeyStrings); - SizerKeys[1]->Add( (wxWindow*) ChoiceKeyNext, 1, wxEXPAND, 0); - - MainSizer->Add( SizerKeys[0], 0, wxEXPAND, 0); - MainSizer->Add( SizerKeys[1], 0, wxEXPAND, 0); + // create collapsible pane + CollPane = new wxCollapsiblePane(this, ID_CollPane, Language->CollapseTextureCapture,wxDefaultPosition,wxDefaultSize,wxCP_NO_TLW_RESIZE); - FontColourSizer = new wxBoxSizer(wxHORIZONTAL); - FontColour[0] = new wxTextCtrl(this, wxID_ANY, Language->FontColour, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); - FontColour[1] = new wxTextCtrl(this, wxID_ANY, "255", wxDefaultPosition, wxDefaultSize); - FontColour[2] = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize); - FontColour[3] = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize); - for (int i=0; i<4; i++) FontColourSizer->Add( (wxWindow*) FontColour[i], 1, wxEXPAND, 0); + CollSizer = new wxBoxSizer(wxVERTICAL); - TextureColourSizer = new wxBoxSizer(wxHORIZONTAL); - TextureColour[0] = new wxTextCtrl(this, wxID_ANY, Language->TextureColour, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); - TextureColour[1] = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize); - TextureColour[2] = new wxTextCtrl(this, wxID_ANY, "255", wxDefaultPosition, wxDefaultSize); - TextureColour[3] = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize); - for (int i=0; i<4; i++) TextureColourSizer->Add( (wxWindow*) TextureColour[i], 1, wxEXPAND, 0); + // get window inside the collapsible pane + wxWindow *win = CollPane->GetPane(); + + // this sizer contains the left save-single-texture part and the right save-all-texture part + TextureSizer = new wxBoxSizer(wxHORIZONTAL); - MainSizer->Add( FontColourSizer, 0, wxEXPAND, 0); - MainSizer->Add( TextureColourSizer, 0, wxEXPAND, 0); + // this sizer contains the left save-single-texture part + SingleTexturePanel = new wxPanel(win); + SingleTextureSizer = new wxBoxSizer(wxVERTICAL); - SaveSingleTexture = new wxCheckBox( this, -1, Language->CheckBoxSaveSingleTexture); - MainSizer->Add( (wxWindow*) SaveSingleTexture, 0, wxEXPAND, 0); + // check box for save-single-texture mode + SaveSingleTexture = new wxCheckBox( SingleTexturePanel, ID_SaveSingleTexture, Language->CheckBoxSaveSingleTexture); + SingleTextureSizer->Add( (wxWindow*) SaveSingleTexture, 0, wxEXPAND, 0); - SaveAllTextures = new wxCheckBox( this, -1, Language->CheckBoxSaveAllTextures); - MainSizer->Add( (wxWindow*) SaveAllTextures, 0, wxEXPAND, 0); + // check box for showing the string + ShowSingleTextureString = new wxCheckBox( SingleTexturePanel, ID_ShowSingleTextureString, Language->CheckBoxShowStringSaveSingleTexture); + SingleTextureSizer->Add( (wxWindow*) ShowSingleTextureString, 0, wxEXPAND|wxALL, 5); - SavePath = new wxTextCtrl(this, wxID_ANY, Language->TextCtrlSavePath, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); - MainSizer->Add( (wxWindow*) SavePath, 0, wxEXPAND, 0); + //set the two colour buttons into one horizontal sizer + wxBoxSizer *temp_sizer = new wxBoxSizer(wxHORIZONTAL); + FontColour = new wxButton( SingleTexturePanel, ID_FontColour, Language->FontColour, wxDefaultPosition, wxSize(100,24)); + FontColour->Enable(false); //siable the font color, per default ShowSingleTextureString is not checked + temp_sizer->Add( FontColour, 0, wxEXPAND, 0); + + temp_sizer->AddSpacer(10); + TextureColour = new wxButton( SingleTexturePanel, ID_TextureColour, Language->TextureColour, wxDefaultPosition, wxSize(100,24)); + temp_sizer->Add( TextureColour, 0, wxEXPAND, 0); + + temp_sizer->AddStretchSpacer(); + SingleTextureSizer->Add( temp_sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + // set the key selector + KeyBack = new uMod_KeyPanel(SingleTexturePanel, Language->KeyBack, -1); + SingleTextureSizer->Add( KeyBack, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); + KeySave = new uMod_KeyPanel(SingleTexturePanel, Language->KeySave, -1); + SingleTextureSizer->Add( KeySave, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); + KeyNext = new uMod_KeyPanel(SingleTexturePanel, Language->KeyNext, -1); + SingleTextureSizer->Add( KeyNext, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + // append an empty strechable sizer at the end + SingleTextureSizer->AddStretchSpacer(); + SingleTexturePanel->SetSizer(SingleTextureSizer); + + + + // this sizer contains the right save-all-texture part + AllTexturePanel = new wxPanel(win); + AllTextureSizer = new wxBoxSizer(wxVERTICAL); + + SaveAllTextures = new wxCheckBox( AllTexturePanel, ID_SaveAllTexture, Language->CheckBoxSaveAllTextures); + AllTextureSizer->Add( (wxWindow*) SaveAllTextures, 0, wxEXPAND, 0); + + + UseSizeFilter = new wxCheckBox( AllTexturePanel, ID_UseSizeFilter, Language->CheckBoxUseSizeFilter); + AllTextureSizer->Add( (wxWindow*) UseSizeFilter, 0, wxEXPAND|wxALL, 5); + + + //temp_sizer = new wxBoxSizer(wxVERTICAL); + SpinWidth = new uMod_SpinPanel(AllTexturePanel); + SpinWidth->SetLabel( Language->WidthSpin); + SpinWidth->SetValue( Game.WidthMin(), Game.WidthMax()); + SpinWidth->Enable(false); + //temp_sizer->Add( (wxWindow*) SpinWidth, 0, wxEXPAND, 0); + AllTextureSizer->Add( SpinWidth, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); + + SpinHeight = new uMod_SpinPanel(AllTexturePanel); + SpinHeight->SetLabel( Language->HeightSpin); + SpinHeight->SetValue( Game.HeightMin(), Game.HeightMax()); + SpinHeight->Enable(false); + //temp_sizer->Add( (wxWindow*) SpinHeight, 0, wxEXPAND, 0); + AllTextureSizer->Add( SpinHeight, 0, wxEXPAND | wxLEFT | wxRIGHT, 10); + + SpinDepth = new uMod_SpinPanel(AllTexturePanel); + SpinDepth->SetLabel( Language->DepthSpin); + SpinDepth->SetValue( Game.DepthMin(), Game.DepthMax()); + SpinDepth->Enable(false); + //temp_sizer->Add( (wxWindow*) SpinDepth, 0, wxEXPAND, 0); + AllTextureSizer->Add( SpinDepth, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + //AllTextureSizer->Add( temp_sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + + + //wxCheckBox *UseFormatFilter; + UseFormatFilter = new wxCheckBox( AllTexturePanel, ID_UseFormatFilter, Language->CheckBoxUseFormatFilter); + AllTextureSizer->Add( (wxWindow*) UseFormatFilter, 0, wxEXPAND, 0); + + temp_sizer = new wxBoxSizer(wxHORIZONTAL); + FormatFilter = new wxButton( AllTexturePanel, ID_SetFormatFilter, Language->SetFormatFilter, wxDefaultPosition, wxSize(100,24)); + FormatFilter->Enable(false); + temp_sizer->Add( (wxWindow*) FormatFilter, 0, wxEXPAND|wxALL, 5); + temp_sizer->AddStretchSpacer(); + AllTextureSizer->Add( temp_sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + + + AllTextureSizer->AddStretchSpacer(); + AllTexturePanel->SetSizer(AllTextureSizer); + + + + + //combine both texture sizer + TextureSizer->Add( SingleTexturePanel, 1, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + TextureSizer->Add( AllTexturePanel, 1, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + CollSizer->Add( TextureSizer, 1, wxEXPAND, 0); + + wxArrayString choices; + choices.Add("BMP"); + choices.Add("JPG"); + choices.Add("TGA"); + choices.Add("PNG"); + choices.Add("DDS"); + choices.Add("PPM"); + FileFormats = new uMod_CheckBoxArray( win, choices, -1); + FileFormats->SetValue( Game.FileFormat()); + CollSizer->Add( (wxWindow*) FileFormats, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + + + // add save path string + temp_sizer = new wxBoxSizer(wxHORIZONTAL); + SavePathButton = new wxButton( win, ID_Button_SavePath, Language->ButtonDirectory, wxDefaultPosition, wxSize(100,24)); + temp_sizer->Add( (wxWindow*) SavePathButton, 0, wxEXPAND|wxALL, 0); + + temp_sizer->AddSpacer(10); + SavePath = new wxTextCtrl(win, wxID_ANY, Language->TextCtrlSavePath, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); + temp_sizer->Add( (wxWindow*) SavePath, 1, wxEXPAND, 0); + CollSizer->Add( temp_sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + + win->SetSizer(CollSizer); + CollSizer->SetSizeHints(win); + + MainSizer->Add(CollPane, 0, wxEXPAND, 5); MainSizer->AddSpacer(10); - NumberOfEntry = 0; - MaxNumberOfEntry = 1024; - if (GetMemory( CheckBoxes, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return;} - if (GetMemory( CheckBoxHSizers, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return ;} - if (GetMemory( CheckButtonUp, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return;} - if (GetMemory( CheckButtonDown, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return;} - if (GetMemory( CheckButtonDelete, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return;} - SavePath->SetValue(Language->TextCtrlSavePath); + + // + // initialize the treeview for the mod packages + // + + ViewCtrl = new wxDataViewCtrl( (wxWindow*) this, ID_DataViewCtrl, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE); + ViewModel = new uMod_TreeViewModel(); + ViewCtrl->AssociateModel(ViewModel); + ViewModel->DecRef(); + + + //first row + wxDataViewTextRenderer *tr = + new wxDataViewTextRenderer( "string", wxDATAVIEW_CELL_INERT ); + wxDataViewColumn *column = + new wxDataViewColumn( Language->Title, tr, 0, 200, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE ); + ViewCtrl->AppendColumn( column ); + + + //second row + wxDataViewToggleRenderer *toglle = + new wxDataViewToggleRenderer( "bool", wxDATAVIEW_CELL_ACTIVATABLE); + column = new wxDataViewColumn( "A", toglle, 1, 20, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE ); + ViewCtrl->AppendColumn( column ); + + + //third row + toglle = new wxDataViewToggleRenderer("bool", wxDATAVIEW_CELL_ACTIVATABLE); + column = new wxDataViewColumn( "D", toglle, 2, 20, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE ); + ViewCtrl->AppendColumn( column ); + + + //4-th row + tr = new wxDataViewTextRenderer( "string", wxDATAVIEW_CELL_INERT ); + column = new wxDataViewColumn( Language->Author, tr, 3, 80, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE ); + ViewCtrl->AppendColumn( column ); + + + //5-th row + tr = new wxDataViewTextRenderer( "string", wxDATAVIEW_CELL_INERT ); + column = new wxDataViewColumn( Language->Comment, tr, 4, 400, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE ); + ViewCtrl->AppendColumn( column ); + + + //enable drag and drop inside the ViewCtrl (for the items of the ViewCtrl) + ViewCtrl->EnableDragSource( wxDF_UNICODETEXT); + ViewCtrl->EnableDropTarget(wxDF_UNICODETEXT ); + + //enables drag and drop for files + DragAcceptFiles(true); + MainSizer->Add(ViewCtrl, 1, wxEXPAND, 0); + SetSizer(MainSizer); - SetScrollRate(0, 20); - MainSizer->FitInside(this); - - if (TemplateName.Len()>0) LoadTemplate(TemplateName); + if (LastError.IsEmpty()) + { + if (TemplateName.Len()>0) LoadTemplate(TemplateName); + LastError.Empty(); + } } uMod_GamePage::~uMod_GamePage(void) { - for (int i=0; i=MaxNumberOfEntry) + if (ViewModel->AddPackage(file_name)) { - if (GetMoreMemory( CheckBoxes, MaxNumberOfEntry, MaxNumberOfEntry+1024)) {LastError = Language->Error_Memory; return -1;} - if (GetMoreMemory( CheckBoxHSizers, MaxNumberOfEntry, MaxNumberOfEntry+1024)) {LastError = Language->Error_Memory; return -1;} - if (GetMoreMemory( CheckButtonUp, MaxNumberOfEntry, MaxNumberOfEntry+1024)) {LastError = Language->Error_Memory; return -1;} - if (GetMoreMemory( CheckButtonDown, MaxNumberOfEntry, MaxNumberOfEntry+1024)) {LastError = Language->Error_Memory; return -1;} - if (GetMoreMemory( CheckButtonDelete, MaxNumberOfEntry, MaxNumberOfEntry+1024)) {LastError = Language->Error_Memory; return -1;} - MaxNumberOfEntry+=1024; + LastError << ViewModel->LastError; + return -1; } - uMod_File file( file_name); - if (!file.FileSupported()) {LastError << Language->Error_FileNotSupported << "\n" << file_name; return -1;} - - wxString tool_tip; - file.GetComment( tool_tip); - - CheckBoxHSizers[NumberOfEntry] = new wxBoxSizer(wxHORIZONTAL); - CheckBoxes[NumberOfEntry] = new wxCheckBox( this, -1, file_name); - CheckBoxes[NumberOfEntry]->SetValue( true); - CheckBoxes[NumberOfEntry]->SetToolTip( tool_tip); - - wchar_t button_txt[2]; - button_txt[0] = 8657; - button_txt[1] = 0; - CheckButtonUp[NumberOfEntry] = new wxButton( this, ID_Button_Texture+3*NumberOfEntry, button_txt, wxDefaultPosition, wxSize(24,24)); - Bind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonUp, this, ID_Button_Texture+3*NumberOfEntry); - - button_txt[0] = 8659; - CheckButtonDown[NumberOfEntry] = new wxButton( this, ID_Button_Texture+3*NumberOfEntry+1, button_txt, wxDefaultPosition, wxSize(24,24)); - Bind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonDown, this, ID_Button_Texture+3*NumberOfEntry+1); - - CheckButtonDelete[NumberOfEntry] = new wxButton( this, ID_Button_Texture+3*NumberOfEntry+2, L"X", wxDefaultPosition, wxSize(24,24)); - Bind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonDelete, this, ID_Button_Texture+3*NumberOfEntry+2); - - CheckBoxHSizers[NumberOfEntry]->Add( (wxWindow*) CheckBoxes[NumberOfEntry], 1, wxEXPAND, 0); - CheckBoxHSizers[NumberOfEntry]->Add( (wxWindow*) CheckButtonUp[NumberOfEntry], 0, wxEXPAND, 0); - CheckBoxHSizers[NumberOfEntry]->Add( (wxWindow*) CheckButtonDown[NumberOfEntry], 0, wxEXPAND, 0); - CheckBoxHSizers[NumberOfEntry]->Add( (wxWindow*) CheckButtonDelete[NumberOfEntry], 0, wxEXPAND, 0); - - MainSizer->Add( CheckBoxHSizers[NumberOfEntry], 0, wxEXPAND, 0); - Files.Add( file_name); - NumberOfEntry++; - MainSizer->Layout(); - MainSizer->FitInside(this); - - return UpdateGame(); + return 0; } +int uMod_GamePage::AddPackages(const wxString *files, int num) +{ + wxArrayString strings( num, files); + if (ViewModel->AddPackages( strings)) + { + LastError << ViewModel->LastError; + return -1; + } + return 0; +} + +int uMod_GamePage::AddPackages(const wxArrayString &files) +{ + if (ViewModel->AddPackages( files)) + { + LastError << ViewModel->LastError; + return -1; + } + return 0; +} wxString uMod_GamePage::GetPageName(void) { + if (InjectionMethod == INVALID_GAME_PAGE) return "uMod"; + wxString ret; ret = ExeName; ret = ret.AfterLast('\\'); ret = ret.AfterLast('/'); ret = ret.BeforeLast('.'); - if (CounterDX9 || CounterDX9EX || CounterDX10 || CounterDX10EX) - { - wxString temp; - ret.append(" ("); - if (CounterDX9) - { - temp.Printf("DX9: %d", CounterDX9); - ret.append(temp); - } - if (CounterDX9EX) - { - if (!temp.IsEmpty()) ret.append(","); - temp.Printf("DX9EX: %d", CounterDX9EX); - ret.append(temp); - } - if (CounterDX10) - { - if (!temp.IsEmpty()) ret.append(","); - temp.Printf("DX10: %d", CounterDX10); - ret.append(temp); - } - if (CounterDX10EX) - { - if (!temp.IsEmpty()) ret.append(","); - temp.Printf("DX10EX: %d", CounterDX10EX); - ret.append(temp); - } - ret.append(")"); - } return ret; } @@ -239,10 +377,10 @@ int uMod_GamePage::AddDXDevice(int version) CounterDX9EX++; break; case VERSION_DX10: CounterDX10++; break; - case VERSION_DX10EX: - CounterDX10EX++; break; + case VERSION_DX101: + CounterDX101++; break; } - return 0; + return SetInfo(); } int uMod_GamePage::RemoveDXDevice(int version) @@ -255,21 +393,80 @@ int uMod_GamePage::RemoveDXDevice(int version) if (CounterDX9EX>0) CounterDX9EX--; break; case VERSION_DX10: if (CounterDX10>0) CounterDX10--; break; - case VERSION_DX10EX: - if (CounterDX10EX>0) CounterDX10EX--; break; + case VERSION_DX101: + if (CounterDX101>0) CounterDX101--; break; } + return SetInfo(); +} + +int uMod_GamePage::SetInfo(void) +{ + wxString info; + switch (InjectionMethod) + { + case HOOK_INJECTION: + info = Language->HookInjection; + break; + case DIRECT_INJECTION: + info = Language->DirectInjection; + break; + case NO_INJECTION: + info = Language->NoInjection; + break; + default: + info = "BUG^^ injection:"; + break; + } + + if (CounterDX9 || CounterDX9EX || CounterDX10 || CounterDX101) + { + wxString temp; + info.append(" ("); + if (CounterDX9) + { + if (CounterDX9==1) temp.Printf("DX9"); + else temp.Printf("DX9: %d", CounterDX9); + info.append(temp); + } + if (CounterDX9EX) + { + if (!temp.IsEmpty()) info.append(","); + if (CounterDX9EX==1) temp.Printf("DX9EX"); + else temp.Printf("DX9EX: %d", CounterDX9EX); + info.append(temp); + } + if (CounterDX10) + { + if (!temp.IsEmpty()) info.append(","); + if (CounterDX10==1) temp.Printf("DX10"); + else temp.Printf("DX10: %d", CounterDX10); + info.append(temp); + } + if (CounterDX101) + { + if (!temp.IsEmpty()) info.append(","); + if (CounterDX101==1) temp.Printf("DX10.1"); + else temp.Printf("DX10.1: %d", CounterDX101); + info.append(temp); + } + info.append(")"); + } + DX_DLL_Info->SetValue(info); return 0; } int uMod_GamePage::GetSettings(void) { - int key_back = ChoiceKeyBack->GetSelection(); - int key_save = ChoiceKeySave->GetSelection(); - int key_next = ChoiceKeyNext->GetSelection(); + Game.ShowCollPane() = CollPane->IsExpanded(); + + int key_back = KeyBack->GetKey(); + int key_save = KeySave->GetKey(); + int key_next = KeyNext->GetKey(); + + if (key_back==key_save && key_back>=0) {LastError << Language->Error_KeyTwice; return 1;} + if (key_back==key_next && key_back>=0) {LastError << Language->Error_KeyTwice; return 1;} + if (key_save==key_next && key_save>=0) {LastError << Language->Error_KeyTwice; return 1;} - if (key_back==key_save && key_back!=wxNOT_FOUND) {LastError << Language->Error_KeyTwice; return 1;} - if (key_back==key_next && key_back!=wxNOT_FOUND) {LastError << Language->Error_KeyTwice; return 1;} - if (key_save==key_next && key_save!=wxNOT_FOUND) {LastError << Language->Error_KeyTwice; return 1;} bool save_single = SaveSingleTexture->GetValue(); bool save_all = SaveAllTextures->GetValue(); @@ -278,42 +475,34 @@ int uMod_GamePage::GetSettings(void) if ( save_single && ( key_back==wxNOT_FOUND || key_save==wxNOT_FOUND || key_next==wxNOT_FOUND) ) {LastError << Language->Error_KeyNotSet; return 1;} - if (key_back!=wxNOT_FOUND) Game.SetKeyBack(key_back); - if (key_save!=wxNOT_FOUND) Game.SetKeySave(key_save); - if (key_next!=wxNOT_FOUND) Game.SetKeyNext(key_next); + Game.SetKeyBack(key_back); + Game.SetKeySave(key_save); + Game.SetKeyNext(key_next); Game.SetSaveSingleTexture( save_single); Game.SetSaveAllTextures( save_all); - int colour[3]; - colour[0] = GetColour( FontColour[1], 255); - colour[1] = GetColour( FontColour[2], 0); - colour[2] = GetColour( FontColour[3], 0); - SetColour( &FontColour[1], colour); - Game.SetFontColour(colour); + Game.ShowSingleTextureString() = ShowSingleTextureString->GetValue(); - colour[0] = GetColour( TextureColour[1], 0); - colour[1] = GetColour( TextureColour[2], 255); - colour[2] = GetColour( TextureColour[3], 0); - SetColour( &TextureColour[1], colour); - Game.SetTextureColour(colour); - - Game.SetFiles( Files); - - bool *checked = NULL; - if (GetMemory( checked, NumberOfEntry)) {LastError = Language->Error_Memory; return -1;} - for (int i=0; iGetValue(); - Game.SetChecked( checked, NumberOfEntry); - delete [] checked; + Game.UseSizeFilter() = UseSizeFilter->GetValue(); + SpinHeight->GetValue( Game.HeightMin(), Game.HeightMax()); + SpinWidth->GetValue( Game.WidthMin(), Game.WidthMax()); + SpinDepth->GetValue( Game.DepthMin(), Game.DepthMax()); + Game.UseFormatFilter() = UseFormatFilter->GetValue(); + FileFormats->GetValue(Game.FileFormat()); return 0; } int uMod_GamePage::UpdateGame(void) { + if (InjectionMethod==INVALID_GAME_PAGE) return 0; if (int ret = GetSettings()) return ret; - if (int ret = Sender.Send( Game, GameOld, false)) + uMod_TextureElement_SortedArrayPtr* current_textures = new uMod_TextureElement_SortedArrayPtr(Compare_uMod_TextureElement); + + ViewModel->GetActiveTexture( *current_textures); + if (int ret = Sender.Send( Game, GameOld, current_textures, false)) { LastError = Language->Error_Send; LastError << "\n" << Sender.LastError; @@ -328,29 +517,31 @@ int uMod_GamePage::UpdateGame(void) int uMod_GamePage::ReloadGame(void) { + if (InjectionMethod==INVALID_GAME_PAGE) return 0; if (int ret = GetSettings()) return ret; - if (int ret = Sender.Send( Game, GameOld, true)) - { - LastError = Language->Error_Send; - LastError << "\n" << Sender.LastError; - Sender.LastError.Empty(); - return ret; - } - - GameOld = Game; - return 0; + wxString content; + SaveTemplateToString(content); + return LoadTemplateFromString(content); } int uMod_GamePage::SaveTemplate( const wxString &file_name) { - if (int ret = GetSettings()) return ret; - if (int ret = Game.SaveToFile( file_name)) + wxFile file; + + file.Open(file_name, wxFile::write); + if (!file.IsOpened()) { - LastError = Language->Error_SaveFile; - LastError <<"\n" << file_name; - return ret; + LastError = Language->Error_FileOpen << "\n" << file_name; + return -1; } + + wxString content; + if (int ret = SaveTemplateToString(content)) return ret; + + file.Write( content.char_str(), content.Len()); + file.Close(); + TemplateName = file_name; wxString path; path = Language->TextCtrlTemplate; @@ -360,239 +551,772 @@ int uMod_GamePage::SaveTemplate( const wxString &file_name) return 0; } +int uMod_GamePage::SaveTemplateToString( wxString &content) +{ + if (int ret = GetSettings()) return ret; + + Game.SaveToString( content ); + + content << "\n\n"; + + wxString temp; + for (unsigned int i=0; imyPackages.GetCount(); i++) + { + temp.Empty(); + ViewModel->Node2String( temp, ViewModel->myPackages[i]); + content << temp << "\n\n"; + } + return 0; +} + int uMod_GamePage::LoadTemplate( const wxString &file_name) { - if (Game.LoadFromFile(file_name)) return -1; + LastError.Empty(); + + if (file_name.Len()==0) return -1; + + wxFile file; + if (!file.Access(file_name, wxFile::read)) + { + LastError = Language->Error_FileOpen << "\n" << file_name; + return -1; + } + file.Open(file_name, wxFile::read); + if (!file.IsOpened()) + { + LastError = Language->Error_FileOpen << "\n" << file_name; + return -1; + } + + unsigned len = file.Length(); + + unsigned char* buffer = (unsigned char*)0; + if (GetMemory( buffer, len+1)) + { + LastError = Language->Error_Memory; + return -1; + } + unsigned int result = file.Read( buffer, len); + file.Close(); + + if (result != len) + { + LastError = Language->Error_FileRead << "\n" << file_name; + delete [] buffer; + return -1; + } + + buffer[len]=0; + + wxString content; + content = buffer; + delete [] buffer; + + if (int ret = LoadTemplateFromString(content)) return ret; + TemplateName = file_name; - wxArrayString comments; - - if (Sender.Send( Game, GameOld, true, &comments)==0) GameOld = Game; - wxString path; path = Language->TextCtrlTemplate; path << TemplateName; TemplateFile->SetValue( path); - int key = Game.GetKeyBack(); - if (key>=0) ChoiceKeyBack->SetSelection( key); - key = Game.GetKeySave(); - if (key>=0) ChoiceKeySave->SetSelection( key); - key = Game.GetKeyNext(); - if (key>=0) ChoiceKeyNext->SetSelection( key); + return 0; +} - int colour[3]; - Game.GetFontColour( colour); - SetColour( &FontColour[1], colour); - Game.GetTextureColour( colour); - SetColour( &TextureColour[1], colour); +int uMod_GamePage::LoadTemplateFromString( const wxString &content_orig) +{ + wxString content = content_orig; + wxArrayString packages; + int index = content.find("\nPACKAGE|"); + if (index!=wxNOT_FOUND) + { + Game.LoadFromString( content.Mid(0,index)); + content = content.Mid(index); + while (1) + { + index = content.find("\nPACKAGE|",10); + if (index==wxNOT_FOUND) + { + packages.Add(content); + break; + } + else + { + packages.Add(content.Mid(0,index)); + content = content.Mid(index); + } + } + } + else + { + Game.LoadFromString(content); + } - SaveSingleTexture->SetValue( Game.GetSaveSingleTexture()); - SaveAllTextures->SetValue( Game.GetSaveAllTextures()); + if (ViewModel->AddPackagesFromTemplate( packages)) + { + LastError << ViewModel->LastError; + } - path = Language->TextCtrlSavePath; + + //if (Sender.Send( Game, GameOld, true)==0) GameOld = Game; + + CollPane->Collapse( !Game.ShowCollPane()); + + + if (Game.ShowSingleTextureString()) + { + ShowSingleTextureString->SetValue(true); + FontColour->Enable(); + } + else + { + ShowSingleTextureString->SetValue(false); + FontColour->Enable(false); + } + + KeyBack->SetKey(Game.GetKeyBack()); + KeySave->SetKey(Game.GetKeySave()); + KeyNext->SetKey(Game.GetKeyNext()); + + SpinWidth->SetValue( Game.WidthMin(), Game.WidthMax()); + SpinHeight->SetValue( Game.HeightMin(), Game.HeightMax()); + SpinDepth->SetValue( Game.DepthMin(), Game.DepthMax()); + + if (Game.UseSizeFilter()) + { + UseSizeFilter->SetValue(true); + SpinWidth->Enable(); + SpinHeight->Enable(); + SpinDepth->Enable(); + } + else + { + UseSizeFilter->SetValue(false); + SpinWidth->Enable(false); + SpinHeight->Enable(false); + SpinDepth->Enable(false); + } + + if (Game.UseFormatFilter()) + { + UseFormatFilter->SetValue(true); + FormatFilter->Enable(); + } + else + { + UseFormatFilter->SetValue(false); + FormatFilter->Enable(false); + } + + + if (Game.GetSaveSingleTexture()) + { + SaveSingleTexture->SetValue( true); + SaveAllTextures->SetValue(false); + SingleTexturePanel->Enable(); + AllTexturePanel->Disable(); + } + else if (Game.GetSaveAllTextures()) + { + SaveSingleTexture->SetValue( false); + SaveAllTextures->SetValue( true); + SingleTexturePanel->Disable(); + AllTexturePanel->Enable(); + } + else + { + SaveSingleTexture->SetValue( false); + SaveAllTextures->SetValue(false); + SingleTexturePanel->Enable(); + AllTexturePanel->Enable(); + } + + FileFormats->SetValue(Game.FileFormat()); + + wxString path = Language->TextCtrlSavePath; path << Game.GetSavePath(); SavePath->SetValue( path); - int new_NumberOfEntry = Game.GetNumberOfFiles(); - - Game.GetFiles( Files); - - if (new_NumberOfEntry>=MaxNumberOfEntry) - { - MaxNumberOfEntry = ((NumberOfEntry/1024)+1)*1024; - if (GetMoreMemory( CheckBoxes, NumberOfEntry, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return -1;} - if (GetMoreMemory( CheckBoxHSizers, NumberOfEntry, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return -1;} - if (GetMoreMemory( CheckButtonUp, NumberOfEntry, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return -1;} - if (GetMoreMemory( CheckButtonDown, NumberOfEntry, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return -1;} - if (GetMoreMemory( CheckButtonDelete, NumberOfEntry, MaxNumberOfEntry)) {LastError = Language->Error_Memory; return -1;} - } - - bool *checked = NULL; - if (GetMemory( checked, new_NumberOfEntry)) {LastError = Language->Error_Memory; return -1;} - Game.GetChecked( checked, new_NumberOfEntry); - - - for (int i=0; iSetLabel( Files[i]); - CheckBoxes[i]->SetValue( checked[i]); - CheckBoxes[i]->SetToolTip( comments[i]); - } - - for (int i=new_NumberOfEntry; iDetach( (wxWindow*) CheckBoxes[i]); - CheckBoxHSizers[i]->Detach( (wxWindow*) CheckButtonUp[i]); - CheckBoxHSizers[i]->Detach( (wxWindow*) CheckButtonDown[i]); - CheckBoxHSizers[i]->Detach( (wxWindow*) CheckButtonDelete[i]); - - MainSizer->Detach( CheckBoxHSizers[i]); - - delete CheckBoxes[i]; - delete CheckButtonUp[i]; - delete CheckButtonDown[i]; - delete CheckButtonDelete[i]; - delete CheckBoxHSizers[i]; - } - for (int i=NumberOfEntry; iSetValue( checked[i]); - CheckBoxes[i]->SetToolTip( comments[i]); - - wchar_t button_txt[2]; - button_txt[0] = 8657; - button_txt[1] = 0; - - CheckButtonUp[i] = new wxButton( this, ID_Button_Texture+3*i, button_txt, wxDefaultPosition, wxSize(24,24)); - Bind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonUp, this, ID_Button_Texture+3*i); - - button_txt[0] = 8659; - CheckButtonDown[i] = new wxButton( this, ID_Button_Texture+3*i+1, button_txt, wxDefaultPosition, wxSize(24,24)); - Bind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonDown, this, ID_Button_Texture+3*i+1); - - CheckButtonDelete[i] = new wxButton( this, ID_Button_Texture+3*i+2, L"X", wxDefaultPosition, wxSize(24,24)); - Bind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonDelete, this, ID_Button_Texture+3*i+2); - - CheckBoxHSizers[i]->Add( (wxWindow*) CheckBoxes[i], 1, wxEXPAND, 0); - CheckBoxHSizers[i]->Add( (wxWindow*) CheckButtonUp[i], 0, wxEXPAND, 0); - CheckBoxHSizers[i]->Add( (wxWindow*) CheckButtonDown[i], 0, wxEXPAND, 0); - CheckBoxHSizers[i]->Add( (wxWindow*) CheckButtonDelete[i], 0, wxEXPAND, 0); - - MainSizer->Add( CheckBoxHSizers[i], 0, wxEXPAND, 0); - } - delete [] checked; - NumberOfEntry = new_NumberOfEntry; + // The wxCollapsiblePane could be hide/shown thus we must manually layout and refresh the sizer and the window + // let the main sizer refresh its content MainSizer->Layout(); - MainSizer->FitInside(this); - return 0; + + // VieCtrl must repaint otherwise some graphical glitches ocure + ViewCtrl->Refresh(); + + if (LastError.IsEmpty()) + { + return UpdateGame(); + } + else return -1; } -int uMod_GamePage::SetColour( wxTextCtrl** txt, int *colour) +void uMod_GamePage::OnCollPane(wxCollapsiblePaneEvent& WXUNUSED(event)) { + // let the main sizer refresh its content + MainSizer->Layout(); + + // VieCtrl must repaint otherwise some graphical glitches ocure + ViewCtrl->Refresh(); +} + +void uMod_GamePage::OnButtonColour(wxCommandEvent& event) +{ + int id = event.GetId(); + + unsigned char colour[4]; + if (id==ID_FontColour) + Game.GetFontColour(colour); + else if (id==ID_TextureColour) + Game.GetTextureColour(colour); + else return; + + wxColourData data; + data.SetColour(wxColour(colour[0],colour[1],colour[2],colour[3])); + + wxColourDialog *dialog = new wxColourDialog( this, &data); + if (dialog->ShowModal() == wxID_OK) + { + data = dialog->GetColourData(); + colour[0] = data.GetColour().Red(); + colour[1] = data.GetColour().Green(); + colour[2] = data.GetColour().Blue(); + colour[3] = data.GetColour().Alpha(); + + if (id==ID_FontColour) + Game.SetFontColour(colour); + else if (id==ID_TextureColour) + Game.SetTextureColour(colour); + } +} + +void uMod_GamePage::OnCheckBox(wxCommandEvent& event) +{ + int id = event.GetId(); + switch (id) + { + case ID_SaveSingleTexture: + { + if (SaveSingleTexture->GetValue()) + AllTexturePanel->Disable(); + else + AllTexturePanel->Enable(); + break; + } + case ID_SaveAllTexture: + { + if (SaveAllTextures->GetValue()) + SingleTexturePanel->Disable(); + else + SingleTexturePanel->Enable(); + break; + } + case ID_UseSizeFilter: + { + if (UseSizeFilter->GetValue()) + { + SpinWidth->Enable(); + SpinHeight->Enable(); + SpinDepth->Enable(); + } + else + { + SpinWidth->Enable(false); + SpinHeight->Enable(false); + SpinDepth->Enable(false); + } + break; + } + case ID_UseFormatFilter: + { + if (UseFormatFilter->GetValue()) + FormatFilter->Enable(); + else + FormatFilter->Enable(false); + break; + } + case ID_ShowSingleTextureString: + { + if (ShowSingleTextureString->GetValue()) + FontColour->Enable(); + else + FontColour->Enable(false); + break; + } + default: + break; + } +} + +void uMod_GamePage::OnButtonFormatFilter(wxCommandEvent& WXUNUSED(event)) +{ + wxArrayString choices; + choices.Add("D3DFMT_R8G8B8 (20)"); + choices.Add("D3DFMT_A8R8G8B8 (21)"); + choices.Add("D3DFMT_X8R8G8B8 (22)"); + choices.Add("D3DFMT_R5G6B5 (23)"); + choices.Add("D3DFMT_X1R5G5B5 (24)"); + choices.Add("D3DFMT_A1R5G5B5 (25)"); + choices.Add("D3DFMT_A4R4G4B4 (26)"); + choices.Add("D3DFMT_R3G3B2 (27)"); + choices.Add("D3DFMT_A8 (28)"); + choices.Add("D3DFMT_A8R3G3B2 (29)"); + choices.Add("D3DFMT_X4R4G4B4 (30)"); + choices.Add("D3DFMT_A2B10G10R10 (31)"); + choices.Add("D3DFMT_A8B8G8R8 (32)"); + choices.Add("D3DFMT_X8B8G8R8 (33)"); + choices.Add("D3DFMT_G16R16 (34)"); + choices.Add("D3DFMT_A2R10G10B10 (35)"); + choices.Add("D3DFMT_A16B16G16R16 (36)"); + + choices.Add("D3DFMT_A8P8 (40)"); + choices.Add("D3DFMT_P8 (41)"); + + choices.Add("D3DFMT_L8 (50)"); + choices.Add("D3DFMT_A8L8 (51)"); + choices.Add("D3DFMT_A4L4 (52)"); + + choices.Add("D3DFMT_V8U8 (60)"); + choices.Add("D3DFMT_L6V5U5 (61)"); + choices.Add("D3DFMT_X8L8V8U8 (62)"); + choices.Add("D3DFMT_Q8W8V8U8 (63)"); + choices.Add("D3DFMT_V16U16 (64)"); + choices.Add("D3DFMT_A2W10V10U10 (67)"); + + choices.Add("D3DFMT_D16_LOCKABLE (70)"); + choices.Add("D3DFMT_D32 (71)"); + choices.Add("D3DFMT_D15S1 (73)"); + choices.Add("D3DFMT_D24S8 (75)"); + choices.Add("D3DFMT_D24X8 (77)"); + choices.Add("D3DFMT_D24X4S4 (79)"); + choices.Add("D3DFMT_D16 (80)"); + + choices.Add("D3DFMT_D32F_LOCKABLE (82)"); + choices.Add("D3DFMT_D24FS8 (83)"); + + choices.Add("D3DFMT_D32_LOCKABLE (84)"); + choices.Add("D3DFMT_S8_LOCKABLE (85)"); + + choices.Add("D3DFMT_L16 (81)"); + + choices.Add("D3DFMT_VERTEXDATA (100)"); + choices.Add("D3DFMT_INDEX16 (101)"); + choices.Add("D3DFMT_INDEX32 (102)"); + + choices.Add("D3DFMT_Q16W16V16U16 (110)"); + + + choices.Add("D3DFMT_R16F (111)"); + choices.Add("D3DFMT_G16R16F (112)"); + choices.Add("D3DFMT_A16B16G16R16F (113)"); + + choices.Add("D3DFMT_R32F (114)"); + choices.Add("D3DFMT_G32R32F (115)"); + choices.Add("D3DFMT_A32B32G32R32F (116)"); + + choices.Add("D3DFMT_CxV8U8 (117)"); + + choices.Add("D3DFMT_A1 (118)"); + choices.Add("D3DFMT_A2B10G10R10_XR_BIAS (119)"); + choices.Add("D3DFMT_BINARYBUFFER (199)"); + +#define MAKEFOURCC(ch0, ch1, ch2, ch3) \ + ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \ + ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 )) + wxString temp; - for (int i=0; i<3; i++) + temp << "D3DFMT_DXT1 (" << MAKEFOURCC('D', 'X', 'T', '1') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_DXT2 (" << MAKEFOURCC('D', 'X', 'T', '2') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_DXT3 (" << MAKEFOURCC('D', 'X', 'T', '3') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_DXT4 (" << MAKEFOURCC('D', 'X', 'T', '4') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_DXT5 (" << MAKEFOURCC('D', 'X', 'T', '5') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_G8R8_G8B8 (" << MAKEFOURCC('G', 'R', 'G', 'B') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_R8G8_B8G8 (" << MAKEFOURCC('R', 'G', 'B', 'G') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_MULTI2_ARGB8 (" << MAKEFOURCC('M','E','T','1') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_UYVY (" << MAKEFOURCC('U', 'Y', 'V', 'Y') << ")"; + choices.Add(temp); + temp.Empty(); + + temp << "D3DFMT_YUY2 (" << MAKEFOURCC('Y', 'U', 'Y', '2') << ")"; + choices.Add(temp); + temp.Empty(); + /* + choices.Add("D3DFMT_DXT1 (827611204)"); 31545844 + choices.Add("D3DFMT_DXT2 (844388420)"); 32545844 + choices.Add("D3DFMT_DXT3 (861165636"); 33545844 + choices.Add("D3DFMT_DXT4 (877942852)"); 34545844 + choices.Add("D3DFMT_DXT5 (894720068)"); 35545844 + choices.Add("D3DFMT_G8R8_G8B8 (MAKEFOURCC('G', 'R', 'G', 'B')"); + choices.Add("D3DFMT_MULTI2_ARGB8 (MAKEFOURCC('M','E','T','1')"); 31 + choices.Add("D3DFMT_R8G8_B8G8 (MAKEFOURCC('R', 'G', 'B', 'G')"); + choices.Add("D3DFMT_UYVY (MAKEFOURCC('U', 'Y', 'V', 'Y')"); + choices.Add("D3DFMT_YUY2 (MAKEFOURCC('Y', 'U', 'Y', '2')"); +*/ +/* + choices.Add("R8G8B8"); + choices.Add("A8R8G8B8"); + choices.Add("X8R8G8B8"); + choices.Add("R5G6B"); + choices.Add("X1R5G5B5"); + choices.Add("A1R5G5B5"); + choices.Add("A4R4G4B4"); + choices.Add("R3G3B2"); + choices.Add("A8"); + choices.Add("A8R3G3B2"); + choices.Add("X4R4G4B4"); + choices.Add("A2B10G10R10"); + choices.Add("A8B8G8R8"); + choices.Add("X8B8G8R8"); + choices.Add("G16R16"); + choices.Add("A2R10G10B10"); + choices.Add("A16B16G16R16"); + + choices.Add("A8P8"); + choices.Add("P8"); + + choices.Add("L8"); + choices.Add("A8L8"); + choices.Add("A4L4"); + + choices.Add("V8U8"); + choices.Add("L6V5U5"); + choices.Add("X8L8V8U8"); + choices.Add("Q8W8V8U8"); + choices.Add("V16U16"); + choices.Add("A2W10V10U10"); + + choices.Add("UYVY"); + choices.Add("R8G8_B8G8"); + choices.Add("YUY2"); + choices.Add("G8R8_G8B8"); + choices.Add("DXT1"); + choices.Add("DXT2"); + choices.Add("DXT3"); + choices.Add("DXT4"); + choices.Add("DXT5"); + + choices.Add("D16_LOCKABLE"); + choices.Add("D32"); + choices.Add("D15S1"); + choices.Add("D24S8"); + choices.Add("D24X8"); + choices.Add("D24X4S4"); + choices.Add("D16"); + + choices.Add("D32F_LOCKABLE"); + choices.Add("D24FS8"); + + choices.Add("D32_LOCKABLE"); + choices.Add("S8_LOCKABLE"); + + choices.Add("L16"); + + choices.Add("VERTEXDATA"); + choices.Add("INDEX16"); + choices.Add("INDEX32"); + + choices.Add("Q16W16V16U16"); + + choices.Add("MULTI2_ARGB8"); + + choices.Add("R16F"); + choices.Add("G16R16F"); + choices.Add("A16B16G16R16F"); + + choices.Add("R32F"); + choices.Add("G32R32F"); + choices.Add("A32B32G32R32F"); + + choices.Add("CxV8U8"); + + choices.Add("A1"); + choices.Add("A2B10G10R10_XR_BIAS"); + choices.Add("BINARYBUFFER"); +*/ + wxArrayInt selections; + unsigned long selected = Game.FormatFilter(); + + for (unsigned int i=0; iSetValue( temp); + if (selected & 1ull<DeleteGame, Language->DeleteGame, choices)!=-1) + { + selected = 0u; + for (unsigned int i=0; iChooseDir, Game.GetSavePath()); + if ( !dir.empty() ) + { + Game.SetSavePath(dir); + + wxString path; + path = Language->TextCtrlSavePath; + path << dir; + SavePath->SetValue( path); + } +} + +void uMod_GamePage::OnBeginDrag( wxDataViewEvent &event) +{ + uMod_TreeViewNode *node = (uMod_TreeViewNode*) event.GetItem().GetID(); + // no item -> no drag and drop + if (node == (uMod_TreeViewNode*)0) + { + event.Veto(); + return; + } + // drag and drop only for root nodes + else if (node->GetParent() != (uMod_TreeViewNode*) 0 ) + { + event.Veto(); + return; + } + + wxString index; + index << ViewModel->myPackages.Index(node); + wxTextDataObject *obj = new wxTextDataObject; + obj->SetText( index ); + event.SetDataObject( obj ); +} + +void uMod_GamePage::OnDropPossible( wxDataViewEvent &event) +{ + // not our data format + if (event.GetDataFormat()!=wxDF_UNICODETEXT) + { + event.Veto(); + return; + } + + uMod_TreeViewNode *node = (uMod_TreeViewNode*) event.GetItem().GetID(); + // drag and drop only on root nodes + if (node!=(uMod_TreeViewNode*)0 && node->GetParent() != (uMod_TreeViewNode*) 0 ) + { + event.Veto(); + return; + } +} + +void uMod_GamePage::OnDrop( wxDataViewEvent &event) +{ + // not our data format + if (event.GetDataFormat()!=wxDF_UNICODETEXT) + { + event.Veto(); + return; + } + + uMod_TreeViewNode *node = (uMod_TreeViewNode*) event.GetItem().GetID(); + // drag and drop only on root nodes + if (node!=(uMod_TreeViewNode*)0 && node->GetParent() != (uMod_TreeViewNode*) 0 ) + { + event.Veto(); + return; + } + + wxTextDataObject obj; + obj.SetData( wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer() ); + wxString msg = obj.GetText(); + + //if we cannot convert the message into a number + long int drag_index; + if (!msg.ToLong( &drag_index)) + { + wxMessageBox("ToLong"); + event.Veto(); + return; + } + + // wrong index !! + if (drag_index<0 || drag_index>=(int) ViewModel->myPackages.GetCount()) + { + wxMessageBox("outside range"); + event.Veto(); + return; + } + + long int drop_index = ViewModel->myPackages.Index( node); + + // if this happens somehting went terrible wrong + if (drop_index==wxNOT_FOUND) + { + event.Veto(); + return; + } + + // get the draged node + uMod_TreeViewNode *draged_node = ViewModel->myPackages.Item(drag_index); + + //remove the draged node + ViewModel->myPackages.RemoveAt(drag_index); + + //no insert again at the drop index + ViewModel->myPackages.Insert(draged_node,drop_index); + + // set the model to cleared -> it rereads all data -> changes become effect + ViewModel->Cleared(); +} + + +void uMod_GamePage::OnDropFile(wxDropFilesEvent& event) +{ + wxString *files = event.GetFiles(); + int num = event.GetNumberOfFiles(); + + LastError.Empty(); + + AddPackages(files, num); + + if (!LastError.IsEmpty()) + { + wxMessageBox(LastError, "ERROR", wxOK|wxICON_ERROR); + LastError.Empty(); + } + if (num>0) UpdateGame(); +} + +void uMod_GamePage::OnContextMenu( wxDataViewEvent &event ) +{ + LastError.Empty(); + uMod_TreeViewNode *node = (uMod_TreeViewNode*) event.GetItem().GetID(); + + wxMenu menu; + menu.Append( ID_OpenPackage, Language->MenuOpenPackage); + menu.Append( ID_RemovePackage, Language->MenuRemovePackage); + menu.Append( ID_RemoveSelectedPackages, Language->MenuRemoveSelectedPackages); + menu.Append( ID_Update, Language->MenuUpdate); + menu.Append( ID_Reload, Language->MenuReload); + menu.AppendCheckItem( ID_SupportTPF, Language->MenuSupportTPF); + menu.Check(ID_SupportTPF, Game.SupportTPF()); + + // if no node is selected, there is nothing to delete ^^ + if (node == (uMod_TreeViewNode*) 0) + menu.Enable(ID_RemovePackage, false); + // only allow root-nodes to be deleted + else if (node->GetParent() != (uMod_TreeViewNode*) 0 ) + menu.Enable(ID_RemovePackage, false); + + // if nothing is selected, we cannot deleted selected packages ;) + if (ViewCtrl->GetSelectedItemsCount()<=0) + menu.Enable(ID_RemoveSelectedPackages, false); + + int id = ViewCtrl->GetPopupMenuSelectionFromUser(menu); + switch (id) + { + case ID_OpenPackage: + OpenPackage(); + break; + case ID_RemovePackage: + ViewModel->DeletePackage( event.GetItem()); + break; + case ID_RemoveSelectedPackages: + { + wxDataViewItemArray items; + ViewCtrl->GetSelections(items); + ViewModel->DeletePackages( items); + } + break; + case ID_Update: + UpdateGame(); + break; + case ID_Reload: + ReloadGame(); + break; + case ID_SupportTPF: + Game.SupportTPF() = menu.IsChecked(ID_SupportTPF); + break; + default: + break; + } + + if (!LastError.IsEmpty()) + { + wxMessageBox(LastError, "ERROR", wxOK|wxICON_ERROR); + LastError.Empty(); + } +} + + +int uMod_GamePage::OpenPackage(void) +{ + wxFileDialog *dialog = new wxFileDialog(this, Language->ChooseFile, Game.GetOpenPath(), wxEmptyString, + wxFileSelectorDefaultWildcardStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE); + + if (dialog->ShowModal() == wxID_OK) + { + wxMessageBox("here"); + wxArrayString files; + dialog->GetPaths( files); // get the filenames + the path + + if (files.GetCount()>0) + { + wxMessageBox("add"); + AddPackages(files); + if (!LastError.IsEmpty()) + { + wxMessageBox(LastError, "ERROR", wxOK|wxICON_ERROR); + LastError.Empty(); + } + UpdateGame(); + } } return 0; } -int uMod_GamePage::GetColour( wxTextCtrl* txt, int def) -{ - wxString temp = txt->GetValue(); - long colour; - if (temp.ToLong(&colour)) - { - if (colour<0) colour=0; - else if (colour>255) colour=255; - } - else colour = def; - return colour; -} - - -void uMod_GamePage::OnButtonUp(wxCommandEvent& event) -{ - int id = (event.GetId() - ID_Button_Texture)/3; - if (id <=0 || id>= NumberOfEntry) return; - - wxString cpy_str = Files[id]; - Files[id] = Files[id-1]; - Files[id-1] = cpy_str; - - CheckBoxes[id]->SetLabel(Files[id]); - CheckBoxes[id-1]->SetLabel(Files[id-1]); - - bool cpy_checked = CheckBoxes[id]->GetValue(); - CheckBoxes[id]->SetValue(CheckBoxes[id-1]->GetValue()); - CheckBoxes[id-1]->SetValue(cpy_checked); - - cpy_str = CheckBoxes[id]->GetToolTip()->GetTip(); - wxString cpy_str2 = CheckBoxes[id-1]->GetToolTip()->GetTip(); - CheckBoxes[id]->SetToolTip(cpy_str2); - CheckBoxes[id-1]->SetToolTip(cpy_str); - -} - -void uMod_GamePage::OnButtonDown(wxCommandEvent& event) -{ - int id = (event.GetId() - ID_Button_Texture-1)/3; - if (id <0 || id>= NumberOfEntry-1) return; - - wxString cpy_str = Files[id]; - Files[id] = Files[id+1]; - Files[id+1] = cpy_str; - - CheckBoxes[id]->SetLabel(Files[id]); - CheckBoxes[id+1]->SetLabel(Files[id+1]); - - bool cpy_checked = CheckBoxes[id]->GetValue(); - CheckBoxes[id]->SetValue(CheckBoxes[id+1]->GetValue()); - CheckBoxes[id+1]->SetValue(cpy_checked); - - cpy_str = CheckBoxes[id]->GetToolTip()->GetTip(); - wxString cpy_str2 = CheckBoxes[id+1]->GetToolTip()->GetTip(); - CheckBoxes[id]->SetToolTip(cpy_str2); - CheckBoxes[id+1]->SetToolTip(cpy_str); -} - -void uMod_GamePage::OnButtonDelete(wxCommandEvent& event) -{ - int id = (event.GetId() - ID_Button_Texture-2)/3; - if (id <0 || id>= NumberOfEntry) return; - - for (int i=id+1; iSetLabel(Files[i]); - for (int i=id+1; iSetValue(CheckBoxes[i]->GetValue()); - wxString cpy_str; - for (int i=id+1; iGetToolTip()->GetTip(); - CheckBoxes[i-1]->SetToolTip(cpy_str); - } - - Files.RemoveAt(id, 1); - NumberOfEntry--; - - - Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonUp, this, ID_Button_Texture+3*NumberOfEntry); - Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonDown, this, ID_Button_Texture+3*NumberOfEntry+1); - Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &uMod_GamePage::OnButtonDelete, this, ID_Button_Texture+3*NumberOfEntry+2); - - - CheckBoxHSizers[NumberOfEntry]->Detach( (wxWindow*) CheckBoxes[NumberOfEntry]); - CheckBoxHSizers[NumberOfEntry]->Detach( (wxWindow*) CheckButtonUp[NumberOfEntry]); - CheckBoxHSizers[NumberOfEntry]->Detach( (wxWindow*) CheckButtonDown[NumberOfEntry]); - CheckBoxHSizers[NumberOfEntry]->Detach( (wxWindow*) CheckButtonDelete[NumberOfEntry]); - - MainSizer->Detach( CheckBoxHSizers[NumberOfEntry]); - - delete CheckBoxes[NumberOfEntry]; - delete CheckButtonUp[NumberOfEntry]; - delete CheckButtonDown[NumberOfEntry]; - delete CheckButtonDelete[NumberOfEntry]; - delete CheckBoxHSizers[NumberOfEntry]; -} - int uMod_GamePage::UpdateLanguage(void) { - TextKeyBack->SetValue( Language->KeyBack); - TextKeySave->SetValue( Language->KeySave); - TextKeyNext->SetValue( Language->KeyNext); - FontColour[0]->SetValue( Language->FontColour); - TextureColour[0]->SetValue( Language->TextureColour); - SaveAllTextures->SetLabel( Language->CheckBoxSaveAllTextures); + CollPane->SetLabel(Language->CollapseTextureCapture); + SaveSingleTexture->SetLabel( Language->CheckBoxSaveSingleTexture); + ShowSingleTextureString->SetLabel( Language->CheckBoxShowStringSaveSingleTexture); + + KeyBack->SetLabel( Language->KeyBack); + KeySave->SetLabel( Language->KeySave); + KeyNext->SetLabel( Language->KeyNext); + FontColour->SetLabel( Language->FontColour); + TextureColour->SetLabel( Language->TextureColour); + + SpinWidth->SetLabel( Language->WidthSpin); + SpinHeight->SetLabel( Language->HeightSpin); + SpinDepth->SetLabel( Language->DepthSpin); + + SaveAllTextures->SetLabel( Language->CheckBoxSaveAllTextures); wxString temp = Language->TextCtrlSavePath; temp << Game.GetSavePath(); SavePath->SetValue( temp); diff --git a/uMod_GUI/uMod_GamePage.h b/uMod_GUI/uMod_GamePage.h index cfc2f8d..e34c803 100644 --- a/uMod_GUI/uMod_GamePage.h +++ b/uMod_GUI/uMod_GamePage.h @@ -23,19 +23,20 @@ along with Universal Modding Engine. If not, see #include "uMod_Main.h" // this page is opened if a game is started. -class uMod_GamePage : public wxScrolledWindow +class uMod_GamePage : public wxPanel { public: - uMod_GamePage( wxNotebook *parent, const wxString &exe, const wxString &save, PipeStruct &pipe); + uMod_GamePage( wxNotebook *parent, const wxString &exe, int injection_method, const wxString &save, PipeStruct &pipe); virtual ~uMod_GamePage(void); - int AddTexture( const wxString &file_name); - int UpdateGame(void); int ReloadGame(void); int SaveTemplate( const wxString &file_name); + int SaveTemplateToString( wxString &content); + int LoadTemplate( const wxString &file_name); + int LoadTemplateFromString( const wxString &content); wxString GetExeName(void) {return ExeName;} wxString GetTemplateName(void) {return TemplateName;} @@ -46,15 +47,86 @@ public: int SetSavePath(const wxString &path); wxString GetSavePath(void) {return Game.GetSavePath();} + /** + * User started drag + * @param event + */ + void OnBeginDrag( wxDataViewEvent &event); + /** + * Ask if drop position is valid + * @param event + */ + void OnDropPossible( wxDataViewEvent &event); + /** + * User dropped the item + * @param event + */ + void OnDrop( wxDataViewEvent &event); - void OnButtonUp(wxCommandEvent& WXUNUSED(event)); - void OnButtonDown(wxCommandEvent& WXUNUSED(event)); - void OnButtonDelete(wxCommandEvent& WXUNUSED(event)); + void OnDropFile(wxDropFilesEvent& event); + /** + * Gets called, when the capture texture panel is shown/hidden + * @param WXUNUSED + */ + void OnCollPane(wxCollapsiblePaneEvent& WXUNUSED(event)); + + /** + * Gets called, when the colour buttons are pressed + * @param event + */ + void OnButtonColour(wxCommandEvent& event); + + /** + * Gets called, when one of the check boxes gets checked/unchecked + * @param event + */ + void OnCheckBox(wxCommandEvent& event); + + /** + * Gets called, press the button to select the filtered texture formats. + * @param event + */ + void OnButtonFormatFilter(wxCommandEvent& event); + + /** + * Gets called, when the save-path button is pressed + * @param event + */ + void OnButtonSavePath(wxCommandEvent& event); + + + /** + * Gets called by a rigth click in the ViewCtrl + * @param event + */ + void OnContextMenu( wxDataViewEvent &event ); + int OpenPackage(void); + + + /** + * call to change the labels of all items to the actual language + * @return + */ int UpdateLanguage(void); + /** + * get the actual name of the page (displayed in the tab of the notebook window) + * @return + */ wxString GetPageName(void); + + /** + * The game has created a DirectX device. + * @param version device version (e.g. DX9, DX9Ex, DX10 DX10.1 + * @return + */ int AddDXDevice(int version); + /** + * The game hast destroyed a DirectX device. + * @param version + * @return + */ int RemoveDXDevice(int version); @@ -62,42 +134,96 @@ public: private: - int CounterDX9, CounterDX9EX; - int CounterDX10, CounterDX10EX; + /** + * Set the info text (which injection method is used and which kind of DirectX device is connected) + * @return + */ + int SetInfo(void); + const int InjectionMethod; + int CounterDX9, CounterDX9EX; + int CounterDX10, CounterDX101; + + /** + * add a single package (or file) + * @param file_name + * @return + */ + int AddPackage( const wxString &file_name); + + /** + * adds multiple packages (or files) + * @param files + * @param num + * @return + */ + int AddPackages(const wxString *files, int num); + + /** + * adds multiple packages (or files) + * @param files + * @return + */ + int AddPackages(const wxArrayString &files); + + /** + * ask for all values from the various control elements of this panel and updates \a Game + * @return + */ int GetSettings(void); - int SetColour( wxTextCtrl** txt, int *colour); - int GetColour( wxTextCtrl* txt, int def); + wxString ExeName; wxString TemplateName; - wxBoxSizer *SizerKeys[2]; - wxTextCtrl *TextKeyBack; - wxTextCtrl *TextKeySave; - wxTextCtrl *TextKeyNext; - wxChoice *ChoiceKeyBack; - wxChoice *ChoiceKeySave; - wxChoice *ChoiceKeyNext; - wxBoxSizer *FontColourSizer; - wxTextCtrl *FontColour[4]; - wxBoxSizer *TextureColourSizer; - wxTextCtrl *TextureColour[4]; wxBoxSizer *MainSizer; - + wxTextCtrl *DX_DLL_Info; wxTextCtrl *TemplateFile; - wxCheckBox *SaveAllTextures; + + wxCollapsiblePane *CollPane; + wxBoxSizer *CollSizer; + + wxBoxSizer *TextureSizer; + + wxPanel *SingleTexturePanel; + wxBoxSizer *SingleTextureSizer; wxCheckBox *SaveSingleTexture; + wxCheckBox *ShowSingleTextureString; + + + uMod_KeyPanel *KeyBack; + uMod_KeyPanel *KeySave; + uMod_KeyPanel *KeyNext; + + wxButton *FontColour; + wxButton *TextureColour; + + + wxPanel *AllTexturePanel; + wxBoxSizer *AllTextureSizer; + wxCheckBox *SaveAllTextures; + + wxCheckBox *UseSizeFilter; + + uMod_SpinPanel *SpinWidth; + uMod_SpinPanel *SpinHeight; + uMod_SpinPanel *SpinDepth; + + + wxCheckBox *UseFormatFilter; + wxButton *FormatFilter; + + + uMod_CheckBoxArray *FileFormats; + wxButton *SavePathButton; wxTextCtrl *SavePath; - wxBoxSizer **CheckBoxHSizers; - wxButton **CheckButtonUp; - wxButton **CheckButtonDown; - wxButton **CheckButtonDelete; + wxDataViewCtrl *ViewCtrl; + uMod_TreeViewModel *ViewModel; + wxDataViewItem *LastDataViewItem; - wxCheckBox **CheckBoxes; int NumberOfEntry; int MaxNumberOfEntry; @@ -109,7 +235,7 @@ private: uMod_Sender Sender; - //DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE(); }; #endif /* uMod_GAMEPAGE_H_ */ diff --git a/uMod_GUI/uMod_Language.cpp b/uMod_GUI/uMod_Language.cpp index 7fbc7f9..e526e39 100644 --- a/uMod_GUI/uMod_Language.cpp +++ b/uMod_GUI/uMod_Language.cpp @@ -179,8 +179,8 @@ int uMod_Language::LoadLanguage(const wxString &name) command.Replace( "\n", ""); msg = entry.AfterFirst(':'); - while (msg[0]=='\r' || msg[0]=='\n') msg.Remove(0,1); - while (msg.Last()=='\n' || msg.Last()=='\r') msg.RemoveLast(1); + while (msg.Len()>0 && (msg[0]=='\r' || msg[0]=='\n')) msg.Remove(0,1); + while (msg.Len()>0 && (msg.Last()=='\n' || msg.Last()=='\r')) msg.RemoveLast(1); CheckEntry( command, msg, MenuLanguage) CheckEntry( command, msg, MenuHelp) @@ -198,14 +198,25 @@ int uMod_Language::LoadLanguage(const wxString &name) CheckEntry( command, msg, MenuExit) CheckEntry( command, msg, MainMenuMain) CheckEntry( command, msg, MainMenuHelp) - CheckEntry( command, msg, ButtonOpen) - CheckEntry( command, msg, ButtonDirectory) + CheckEntry( command, msg, MenuOpenPackage) + CheckEntry( command, msg, MenuRemovePackage) + CheckEntry( command, msg, MenuRemoveSelectedPackages) + CheckEntry( command, msg, MenuUpdate) + CheckEntry( command, msg, MenuReload) + CheckEntry( command, msg, MenuSupportTPF) CheckEntry( command, msg, ButtonUpdate) - CheckEntry( command, msg, ButtonReload) + CheckEntry( command, msg, ButtonDirectory) CheckEntry( command, msg, ChooseFile) CheckEntry( command, msg, ChooseDir) + CheckEntry( command, msg, MultipleSingleFiles) + CheckEntry( command, msg, HookInjection) + CheckEntry( command, msg, DirectInjection) + CheckEntry( command, msg, NoInjection) + CheckEntry( command, msg, InvalidGamePage) CheckEntry( command, msg, TextCtrlTemplate) + CheckEntry( command, msg, CollapseTextureCapture) CheckEntry( command, msg, CheckBoxSaveSingleTexture) + CheckEntry( command, msg, CheckBoxShowStringSaveSingleTexture) CheckEntry( command, msg, CheckBoxSaveAllTextures) CheckEntry( command, msg, TextCtrlSavePath) CheckEntry( command, msg, SelectLanguage) @@ -215,12 +226,15 @@ int uMod_Language::LoadLanguage(const wxString &name) CheckEntry( command, msg, DeleteGame) CheckEntry( command, msg, GameAlreadyAdded) CheckEntry( command, msg, ExitGameAnyway) - CheckEntry( command, msg, NoComment) + CheckEntry( command, msg, Title) CheckEntry( command, msg, Author) + CheckEntry( command, msg, Comment) + CheckEntry( command, msg, SingleTextureNode) CheckEntry( command, msg, Error_GameIsHooked) CheckEntry( command, msg, Error_ProcessNotStarted) CheckEntry( command, msg, Error_RemoveHook) CheckEntry( command, msg, Error_FileNotSupported) + CheckEntry( command, msg, Error_FileIsEmpty) CheckEntry( command, msg, Error_FktNotFound) CheckEntry( command, msg, Error_D3DX9NotFound) CheckEntry( command, msg, Error_DLLNotFound) @@ -239,9 +253,15 @@ int uMod_Language::LoadLanguage(const wxString &name) CheckEntry( command, msg, Error_Memory) CheckEntry( command, msg, Error_Unzip) CheckEntry( command, msg, Error_ZipEntry) + CheckEntry( command, msg, CheckBoxUseSizeFilter) + CheckEntry( command, msg, CheckBoxUseFormatFilter) + CheckEntry( command, msg, SetFormatFilter) CheckEntry( command, msg, KeyBack) CheckEntry( command, msg, KeySave) CheckEntry( command, msg, KeyNext) + CheckEntry( command, msg, AskForKey) + CheckEntry( command, msg, KeyNotSet) + CheckEntry( command, msg, UnknownKey) CheckEntry( command, msg, FontColour) CheckEntry( command, msg, TextureColour) {} @@ -277,16 +297,30 @@ int uMod_Language::LoadDefault(void) MainMenuMain = "Main"; MainMenuHelp = "Help"; - ButtonOpen = "Open texture/package"; - ButtonDirectory = "Set save directory"; + MenuOpenPackage = "Open texture/package"; + MenuRemovePackage = "Remove package"; + MenuRemoveSelectedPackages = "Remove selected packages"; + + MenuUpdate = "Update"; + MenuReload = "Update (reload)"; + MenuSupportTPF = "Support TPF-Mods"; ButtonUpdate = "Update"; - ButtonReload = "Update (reload)"; + ButtonDirectory = "Set save directory"; ChooseFile = "Choose a file"; ChooseDir = "Choose a directory"; + MultipleSingleFiles = "Multiple single files"; + + HookInjection = "Hook Injection: "; + DirectInjection = "Direct Injection: "; + NoInjection = "No Injection: "; + InvalidGamePage = "default page"; TextCtrlTemplate = "Template: "; + + CollapseTextureCapture = "Capture textures"; CheckBoxSaveSingleTexture = "Save single texture"; + CheckBoxShowStringSaveSingleTexture = "Show message in the upper left corner"; CheckBoxSaveAllTextures = "Save all textures"; TextCtrlSavePath = "Save path:"; @@ -299,14 +333,17 @@ int uMod_Language::LoadDefault(void) DeleteGame = "Select the games to be deleted."; GameAlreadyAdded = "Game has been already added."; ExitGameAnyway = "Closing OpenTexMod while a game is running might lead to a crash of the game.\nExit anyway?"; - NoComment = "No comment."; - Author = "Author: "; + Title = "Title"; + Author = "Author"; + Comment = "Comment"; + SingleTextureNode = "Single Textures"; Error_GameIsHooked = "The global hook is active and this game will be injected! Please delete the game from the list or disable the hook."; Error_ProcessNotStarted = "The game could not be started."; Error_RemoveHook = "Removing the Hook while a game is running might lead to crash."; Error_FileNotSupported = "This file type is not supported:\n"; + Error_FileIsEmpty = "Could not retrieve textures from file:\n"; Error_D3DX9NotFound = "The D3DX9_43.dll (32bit) is not available on your system.\nPlease install the newest DirectX End-User Runtime Installer."; Error_DLLNotFound = "Could not load the dll.\nThe dll injection won't work.\nThis might happen if D3DX9_43.dll (32bit) is not installed on your system.\nPlease install the newest DirectX End-User Runtime Web Installer."; Error_FktNotFound = "Could not load function out of dll.\nThe dll injection won't work."; @@ -327,14 +364,23 @@ int uMod_Language::LoadDefault(void) Error_Unzip = "Could not unzip."; Error_ZipEntry = "Could not find zip entry."; + CheckBoxUseSizeFilter = "Use size filter"; + CheckBoxUseFormatFilter = "Use texture format filter"; + SetFormatFilter = "Set the filter"; + WidthSpin = "Width :"; + HeightSpin = "Height :"; + DepthSpin = "Depth :"; KeyBack = "Back"; KeySave = "Save"; KeyNext = "Next"; + AskForKey = "Pleas press a Key."; + KeyNotSet = "Not set"; + UnknownKey = "Unknown"; - FontColour = "Font colour (RGB):"; - TextureColour = "Texture colour (RGB):"; + FontColour = "Font colour"; + TextureColour = "Texture colour"; return 0; } @@ -453,44 +499,44 @@ int uMod_Language::LoadKeys(void) // * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A) */ int count = 0x30; - AddKey( "0", count++); - AddKey( "1", count++); - AddKey( "2", count++); - AddKey( "3", count++); - AddKey( "4", count++); - AddKey( "5", count++); - AddKey( "6", count++); - AddKey( "7", count++); - AddKey( "8", count++); - AddKey( "9", count++); + AddKey( "VK_0", count++); + AddKey( "VK_1", count++); + AddKey( "VK_2", count++); + AddKey( "VK_3", count++); + AddKey( "VK_4", count++); + AddKey( "VK_5", count++); + AddKey( "VK_6", count++); + AddKey( "VK_7", count++); + AddKey( "VK_8", count++); + AddKey( "VK_9", count++); count = 0x41; - AddKey( "a", count++); - AddKey( "b", count++); - AddKey( "c", count++); - AddKey( "d", count++); - AddKey( "e", count++); - AddKey( "f", count++); - AddKey( "g", count++); - AddKey( "h", count++); - AddKey( "i", count++); - AddKey( "j", count++); - AddKey( "k", count++); - AddKey( "l", count++); - AddKey( "m", count++); - AddKey( "n", count++); - AddKey( "o", count++); - AddKey( "p", count++); - AddKey( "q", count++); - AddKey( "r", count++); - AddKey( "s", count++); - AddKey( "t", count++); - AddKey( "u", count++); - AddKey( "v", count++); - AddKey( "w", count++); - AddKey( "x", count++); - AddKey( "y", count++); - AddKey( "z", count++); + AddKey( "VK_A", count++); + AddKey( "VK_B", count++); + AddKey( "VK_C", count++); + AddKey( "VK_D", count++); + AddKey( "VK_E", count++); + AddKey( "VK_F", count++); + AddKey( "VK_G", count++); + AddKey( "VK_H", count++); + AddKey( "VK_I", count++); + AddKey( "VK_J", count++); + AddKey( "VK_K", count++); + AddKey( "VK_L", count++); + AddKey( "VK_M", count++); + AddKey( "VK_N", count++); + AddKey( "VK_O", count++); + AddKey( "VK_P", count++); + AddKey( "VK_Q", count++); + AddKey( "VK_R", count++); + AddKey( "VK_S", count++); + AddKey( "VK_T", count++); + AddKey( "VK_U", count++); + AddKey( "VK_V", count++); + AddKey( "VK_W", count++); + AddKey( "VK_X", count++); + AddKey( "VK_Y", count++); + AddKey( "VK_Z", count++); /* diff --git a/uMod_GUI/uMod_Language.h b/uMod_GUI/uMod_Language.h index 3967d49..74d67fb 100644 --- a/uMod_GUI/uMod_Language.h +++ b/uMod_GUI/uMod_Language.h @@ -51,16 +51,29 @@ public: wxString MainMenuMain; wxString MainMenuHelp; - wxString ButtonOpen; - wxString ButtonDirectory; + wxString MenuOpenPackage; + wxString MenuRemovePackage; + wxString MenuRemoveSelectedPackages; + wxString MenuUpdate; + wxString MenuReload; + wxString MenuSupportTPF; wxString ButtonUpdate; - wxString ButtonReload; + wxString ButtonDirectory; wxString ChooseFile; wxString ChooseDir; + wxString MultipleSingleFiles; + + wxString HookInjection; + wxString DirectInjection; + wxString NoInjection; + wxString InvalidGamePage; wxString TextCtrlTemplate; + + wxString CollapseTextureCapture; wxString CheckBoxSaveSingleTexture; + wxString CheckBoxShowStringSaveSingleTexture; wxString CheckBoxSaveAllTextures; wxString TextCtrlSavePath; @@ -73,14 +86,17 @@ public: wxString DeleteGame; wxString GameAlreadyAdded; wxString ExitGameAnyway; - wxString NoComment; + wxString Title; wxString Author; + wxString Comment; + wxString SingleTextureNode; wxString Error_GameIsHooked; wxString Error_ProcessNotStarted; wxString Error_RemoveHook; wxString Error_FileNotSupported; + wxString Error_FileIsEmpty; wxString Error_FktNotFound; wxString Error_D3DX9NotFound; wxString Error_DLLNotFound; @@ -101,9 +117,20 @@ public: wxString Error_Unzip; wxString Error_ZipEntry; + wxString CheckBoxUseSizeFilter; + wxString CheckBoxUseFormatFilter; + wxString SetFormatFilter; + wxString WidthSpin; + wxString HeightSpin; + wxString DepthSpin; + wxString KeyBack; wxString KeySave; wxString KeyNext; + wxString AskForKey; + wxString KeyNotSet; + wxString UnknownKey; + wxArrayString KeyStrings; wxArrayInt KeyValues; diff --git a/uMod_GUI/uMod_Main.h b/uMod_GUI/uMod_Main.h index 4865e02..36c18f4 100644 --- a/uMod_GUI/uMod_Main.h +++ b/uMod_GUI/uMod_Main.h @@ -41,7 +41,11 @@ along with Universal Modding Engine. If not, see #define wxUSE_TEXTCTRL 1 #define wxUSE_CHOICEDLG 1 #define wxUSE_TOOLTIPS 1 +#define wxUSE_DATAVIEWCTRL 1 +#define wxUSE_COLLPANE 1 +#define wxUSE_COLOURDLG 1 #endif +#define wxUSE_SPINCTRL 1 #define WINVER _WIN32_WINNT_WINXP #define _WIN32_WINNT _WIN32_WINNT_WINXP @@ -49,22 +53,26 @@ along with Universal Modding Engine. If not, see #define WIN32_LEAN_AND_MEAN -#include "wx\wx.h" -#include "wx\notebook.h" +#include +#include #include #include #include #include -//#include -//#include "wx/checkbox.h" -//#include -//#include -//#include -//#include -//#include -//#include -//#include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //#include #include "../uMod_GlobalDefines.h" @@ -77,13 +85,7 @@ class uMod_Frame; #define MAX_TEXTURES 1024 enum { - ID_Button_Open = wxID_HIGHEST, - ID_Button_Path, - ID_Button_Update, - ID_Button_Reload, - //ID_Button_Save, - //ID_Menu_Pref, - ID_Menu_Exit, + ID_Menu_Exit = wxID_HIGHEST, ID_Menu_Lang, ID_Menu_Help, ID_Menu_About, @@ -101,15 +103,42 @@ enum ID_Delete_Game, ID_Add_Device, ID_Delete_Device, - ID_Button_Texture, //this entry must be the last!! + + ID_OpenPackage, + ID_RemovePackage, + ID_RemoveSelectedPackages, + ID_Update, + ID_Reload, + ID_SupportTPF, + ID_Button_Update, + + ID_CollPane, + ID_SaveSingleTexture, + ID_SaveAllTexture, + ID_ShowSingleTextureString, + ID_FontColour, + ID_TextureColour, + + ID_KeyPress, + + ID_UseSizeFilter, + ID_SpinMin, ID_SpinMax, + ID_UseFormatFilter, + ID_SetFormatFilter, + ID_Button_SavePath, + + ID_DataViewCtrl, + ID_ContextMenu, }; #define ABORT_SERVER L"uMod_Abort_Server" #define uMod_d3d9_Hook_dll L"uMod_d3d9_HI.dll" #define uMod_d3d9_DI_dll L"uMod_d3d9_DI.dll" -#include "uMod_AddTexture.h" #include "uMod_Settings.h" +#include "uMod_ModElement.h" +#include "uMod_TreeView.h" +#include "uMod_AddTexture.h" #include "uMod_Language.h" #include "uMod_Event.h" #include "uMod_Client.h" @@ -117,6 +146,7 @@ enum #include "uMod_File.h" #include "uMod_Sender.h" #include "uMod_Server.h" +#include "uMod_MiniPanels.h" #include "uMod_GamePage.h" #include "uMod_DirectInjection.h" #include "uMod_GUI.h" diff --git a/uMod_GUI/uMod_MiniPanels.cpp b/uMod_GUI/uMod_MiniPanels.cpp new file mode 100644 index 0000000..d9f7999 --- /dev/null +++ b/uMod_GUI/uMod_MiniPanels.cpp @@ -0,0 +1,355 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + +#include "uMod_Main.h" + +#ifndef __CDT_PARSER__ + +BEGIN_EVENT_TABLE(uMod_SpinPanel, wxPanel) +EVT_SPINCTRL(ID_SpinMin, uMod_SpinPanel::OnSpin) +EVT_SPINCTRL(ID_SpinMax, uMod_SpinPanel::OnSpin) +END_EVENT_TABLE() + +#endif + + +uMod_SpinPanel::uMod_SpinPanel(wxWindow *parent, int winid, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name) + : wxPanel( parent, winid, pos, size, style, name) +{ + + Text = new wxTextCtrl( this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_READONLY); + + Min = new wxSpinCtrl ( this, ID_SpinMin, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 65535, 1); + + Max = new wxSpinCtrl ( this, ID_SpinMax, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 65535, 1); + Max->SetRange( 1, 65535); + + wxBoxSizer* spin_sizer = new wxBoxSizer(wxHORIZONTAL); + spin_sizer->Add( (wxWindow*) Text, 0, wxEXPAND, 0); + + spin_sizer->Add( (wxWindow*) Min, 0, wxEXPAND, 0); + spin_sizer->Add( (wxWindow*) new wxTextCtrl(this, wxID_ANY, " -", wxDefaultPosition, wxSize(25,10), wxTE_READONLY), 0, wxEXPAND, 0); + spin_sizer->Add( (wxWindow*) Max, 0, wxEXPAND, 0); + spin_sizer->AddStretchSpacer(); + + SetSizer(spin_sizer); + +} + + +void uMod_SpinPanel::GetValue( int &min, int &max) +{ + min = Min->GetValue(); + max = Max->GetValue(); +} + +void uMod_SpinPanel::SetValue(int min, int max) +{ + if (maxSetValue( min); + Max->SetValue( max); +} + + +void uMod_SpinPanel::SetLabel( const wxString &label) +{ + Text->SetValue( label); +} + + +void uMod_SpinPanel::OnSpin(wxSpinEvent& event) +{ + int min = Min->GetValue(); + int max = Max->GetValue(); + + if (event.GetId() == ID_SpinMin) + { + if (maxSetValue(min); + } + else + { + if (min>max) Min->SetValue(max); + } +} + + + + + +uMod_CheckBoxArray::uMod_CheckBoxArray(wxWindow *parent, const wxArrayString &choices, int col, int winid, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name) +: wxPanel( parent, winid, pos, size, style, name) +{ + if (col>0) + { + wxGridSizer *sizer = new wxGridSizer( col, 0,0); + + for (unsigned int i=0; iAdd(check_box); + } + SetSizer(sizer); + } + else + { + wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + for (unsigned int i=0; iAdd(check_box, 0, wxEXPAND, 0); + } + sizer->AddStretchSpacer(); + SetSizer(sizer); + } +} + +void uMod_CheckBoxArray::SetChoices(const wxArrayShort &choices) +{ + for (unsigned int i=0; iSetValue(true); + else CheckBoxes[i]->SetValue(false); + } +} + +void uMod_CheckBoxArray::GetChoices(wxArrayShort &choices) +{ + choices.Empty(); + for (unsigned int i=0; iGetValue()) choices.Add(1); + else choices.Add(0); + } +} + + +void uMod_CheckBoxArray::SetValue( unsigned long val) +{ + for (unsigned int i=0; iSetValue(true); + else CheckBoxes[i]->SetValue(false); + } +} + +void uMod_CheckBoxArray::GetValue( unsigned long &val) +{ + val = 0; + for (unsigned int i=0; iGetValue()) val |= 1<Add( (wxWindow*) Button, 0, wxEXPAND, 0); + sizer->AddSpacer(10); + sizer->Add( (wxWindow*) KeyText, 0, wxEXPAND, 0); + sizer->AddStretchSpacer(); + + SetKeyLabel(); + SetSizer(sizer); +} + +void uMod_KeyPanel::SetLabel(const wxString &label) +{ + Button->SetLabel( label); +} + +void uMod_KeyPanel::OnButton(wxCommandEvent& WXUNUSED(event)) +{ + uMod_AskForKey *dialog = new uMod_AskForKey( Language->AskForKey); + dialog->ShowModal(); + myKey = dialog->Key(); + delete dialog; + + SetKeyLabel(); +} + + +void uMod_KeyPanel::SetKeyLabel() +{ + wxString temp; + if (myKey<0) + temp = Language->KeyNotSet; + else + { + int index = Language->KeyValues.Index( myKey); + if (index>=0) + temp = Language->KeyStrings[index]; + else + temp = Language->UnknownKey; + + wxString code; + code.Printf(" (%#X)", myKey); + temp << code; + } + KeyText->SetValue(temp); +} + + + + + +#ifndef __CDT_PARSER__ + +BEGIN_EVENT_TABLE(uMod_AskForKey, wxDialog) +//EVT_KEY_UP(uMod_AskForKey::OnKey) +EVT_CHAR_HOOK(uMod_AskForKey::OnKey) +END_EVENT_TABLE() + +#endif + +uMod_AskForKey::uMod_AskForKey(const wxString &title) +: wxDialog( (wxWindow*)0, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER) +{ + myKey = -1; +} + +void uMod_AskForKey::OnKey(wxKeyEvent& event) +{ + myKey = event.GetRawKeyCode();//GetKeyCode(); + EndModal(0); +} + +/* + +uMod_TextureFormat::uMod_TextureFormat(wxWindow *parent, const wxString &title) + : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER) +{ + wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); + wxArrayString choices; + + choices.Add("R8G8B8"); + choices.Add("A8R8G8B8"); + choices.Add("X8R8G8B8"); + choices.Add("R5G6B"); + choices.Add("X1R5G5B5"); + choices.Add("A1R5G5B5"); + choices.Add("A4R4G4B4"); + choices.Add("R3G3B2"); + choices.Add("A8"); + choices.Add("A8R3G3B2"); + choices.Add("X4R4G4B4"); + choices.Add("A2B10G10R10"); + choices.Add("A8B8G8R8"); + choices.Add("X8B8G8R8"); + choices.Add("G16R16"); + choices.Add("A2R10G10B10"); + choices.Add("A16B16G16R16"); + + choices.Add("A8P8"); + choices.Add("P8"); + + choices.Add("L8"); + choices.Add("A8L8"); + choices.Add("A4L4"); + + choices.Add("V8U8"); + choices.Add("L6V5U5"); + choices.Add("X8L8V8U8"); + choices.Add("Q8W8V8U8"); + choices.Add("V16U16"); + choices.Add("A2W10V10U10"); + + choices.Add("UYVY"); + choices.Add("R8G8_B8G8"); + choices.Add("YUY2"); + choices.Add("G8R8_G8B8"); + choices.Add("DXT1"); + choices.Add("DXT2"); + choices.Add("DXT3"); + choices.Add("DXT4"); + choices.Add("DXT5"); + + choices.Add("D16_LOCKABLE"); + choices.Add("D32"); + choices.Add("D15S1"); + choices.Add("D24S8"); + choices.Add("D24X8"); + choices.Add("D24X4S4"); + choices.Add("D16"); + + choices.Add("D32F_LOCKABLE"); + choices.Add("D24FS8"); + + choices.Add("D32_LOCKABLE"); + choices.Add("S8_LOCKABLE"); + + choices.Add("L16"); + + choices.Add("VERTEXDATA"); + choices.Add("INDEX16"); + choices.Add("INDEX32"); + + choices.Add("Q16W16V16U16"); + + choices.Add("MULTI2_ARGB8"); + + choices.Add("R16F"); + choices.Add("G16R16F"); + choices.Add("A16B16G16R16F"); + + choices.Add("R32F"); + choices.Add("G32R32F"); + choices.Add("A32B32G32R32F"); + + choices.Add("CxV8U8"); + + choices.Add("A1"); + choices.Add("A2B10G10R10_XR_BIAS"); + choices.Add("BINARYBUFFER"); + + TextureFormats = new uMod_CheckBoxArray( this, choices, 4); + sizer->Add( (wxWindow*) TextureFormats, 0, wxEXPAND, 0); + + SetSizer(sizer); + wxArrayInt selections; + wxGetSelectedChoices( selections, Language->DeleteGame, Language->DeleteGame, choices); +} +*/ diff --git a/uMod_GUI/uMod_MiniPanels.h b/uMod_GUI/uMod_MiniPanels.h new file mode 100644 index 0000000..6477f46 --- /dev/null +++ b/uMod_GUI/uMod_MiniPanels.h @@ -0,0 +1,174 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + +#include "uMod_Main.h" + +#ifndef UMOD_MINIPANELS_H_ +#define UMOD_MINIPANELS_H_ + + +class uMod_SpinPanel : public wxPanel +{ +public: + uMod_SpinPanel(wxWindow *parent, int winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = wxPanelNameStr); + + virtual ~uMod_SpinPanel() {} + + /** + * Get the min an max value + * @param[out] min + * @param[out] max + */ + void GetValue( int &min, int &max); + + /** + * Set the min and max value + * @param[in] min + * @param[in] max + */ + void SetValue(int min, int max); + + + /** + * Set the label of the text ctrl + * @param label + * @return + */ + void SetLabel( const wxString &label); + +protected: + + /** + * Gets called, when one of the spin boxes changes their value + * @param event + */ + void OnSpin(wxSpinEvent& event); + + wxTextCtrl *Text; + wxSpinCtrl *Min, *Max; + + DECLARE_EVENT_TABLE(); +}; + + +WX_DEFINE_ARRAY_PTR( wxCheckBox*, wxCheckBox_Array ); + +class uMod_CheckBoxArray : public wxPanel +{ +public: + uMod_CheckBoxArray(wxWindow *parent, const wxArrayString &choices, int col, int winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = wxPanelNameStr); + virtual ~uMod_CheckBoxArray() {} + + void SetChoices(const wxArrayShort &choices); + void GetChoices(wxArrayShort &choices); + + + void SetValue( unsigned long val); + void GetValue( unsigned long &val); + +private: + wxCheckBox_Array CheckBoxes; +}; + + + +/** + * this class is a mini panel with a set key button and string beside it which shows the actual set key + */ +class uMod_KeyPanel : public wxPanel +{ +public: + uMod_KeyPanel(wxWindow *parent, const wxString &label, int key, int winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = wxPanelNameStr); + virtual ~uMod_KeyPanel() {} + + int GetKey() {return myKey;} + void SetKey(int key) {myKey = key; SetKeyLabel();} + + /** + * set the label of the button (for changing the language) + * @param label + */ + void SetLabel(const wxString &label); +private: + + /** + * called if button was clicked + * @param event + */ + void OnButton(wxCommandEvent& event); + + void SetKeyLabel(); + + wxButton *Button; + wxTextCtrl *KeyText; + + int myKey; + DECLARE_EVENT_TABLE(); +}; + + +class uMod_AskForKey : public wxDialog +{ +public: + uMod_AskForKey(const wxString &title); + virtual ~uMod_AskForKey() {} + + + int Key() {return myKey;} + +private: + + /** + * called if a key was hit + * @param event + */ + void OnKey(wxKeyEvent& event); + + int myKey; + DECLARE_EVENT_TABLE(); +}; + +/* + +class uMod_TextureFormat : public wxDialog +{ +public: + uMod_TextureFormat(wxWindow *parent, const wxString &title); + virtual ~uMod_TextureFormat() {} + + void SetValue( unsigned long val) {TextureFormats->SetValue(val);} + void GetValue( unsigned long &val) {TextureFormats->GetValue(val);} +private: + + uMod_CheckBoxArray *TextureFormats; +}; + +*/ +#endif /* UMOD_MINIPANELS_H_ */ diff --git a/uMod_GUI/uMod_ModElement.cpp b/uMod_GUI/uMod_ModElement.cpp new file mode 100644 index 0000000..06eee25 --- /dev/null +++ b/uMod_GUI/uMod_ModElement.cpp @@ -0,0 +1,18 @@ +/* + * uMod_ModElement.cpp + * + * Created on: 26.06.2012 + * Author: marts + */ + + +#include "uMod_Main.h" + + +int Compare_uMod_TextureElement(uMod_TextureElement* a,uMod_TextureElement* b) +{ + if ( a->Hash() < b->Hash()) return -1; + else if ( a->Hash() == b->Hash()) return 0; + else return +1; +} + diff --git a/uMod_GUI/uMod_ModElement.h b/uMod_GUI/uMod_ModElement.h new file mode 100644 index 0000000..4674821 --- /dev/null +++ b/uMod_GUI/uMod_ModElement.h @@ -0,0 +1,165 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + +#include "uMod_Main.h" +#ifndef UMOD_MODELEMEMT_H_ +#define UMOD_MODELEMEMT_H_ + + +template +class uMod_Data +{ +public: + uMod_Data(void): myData((T*)0), myLen(0) {} + ~uMod_Data() {if (myData!=(T*)0) delete [] myData;} + + T* &Data(void) {return myData;} + const T* &Data(void) const {return myData;} + + unsigned int &Len(void) {return myLen;} + const unsigned int &Len(void) const {return myLen;} + + int SetSize(int size) + { + if (myData!=(T*)0) delete [] myData; + myData = (T*)0; + if (size<=0) return 0; + + try {myData = new T[size];} + catch (...) {myData=(T*)0;return -1;} + myLen = size; + return 0; + } + +private: + + T *myData; + unsigned int myLen; + +}; + + +/** + * This class is a representation of one element, to be modified (e.g. one texture) + */ + +class uMod_ModElement +{ +public: + + enum enumType + { + Group, + Texture + }; + + enum enumStatus + { + Activate, + Deactivate, + NONE + }; + + uMod_ModElement( enumType t, enumStatus s = NONE) : myType(t), myStatus(s), myCounter(1) {} + virtual ~uMod_ModElement() {} + + int AddRef(void) {return ++myCounter;} + int Release(void) {if (--myCounter==0) {delete this;} return myCounter;} + + + const wxString &File(void) const {return myFile;} + wxString &File(void) {return myFile;} + + const wxString &Title(void) const {return myTitle;} + wxString &Title(void) {return myTitle;} + + const wxString &Author(void) const {return myAuthor;} + wxString &Author(void) {return myAuthor;} + + const wxString &Comment(void) const {return myComment;} + wxString &Comment(void) {return myComment;} + + + enumType Type(void) const {return myType;} + //void SetType(Type type) {myType = type;} + + const enumStatus &Status(void) const {return myStatus;} + enumStatus &Status(void) {return myStatus;} + +private: + + wxString myFile; + wxString myTitle; + wxString myAuthor; + wxString myComment; + const enumType myType; + enumStatus myStatus; + int myCounter; + + +private: + /** + * forbid assignment! + * @param rh + * @return + */ + uMod_ModElement operator= (const uMod_ModElement & rh) {(void*) &rh; return *this;} +}; + + +class uMod_TextureElement : public uMod_ModElement +{ +public: + uMod_TextureElement() : uMod_ModElement(Texture) {} + virtual ~uMod_TextureElement() {} + + + uMod_Data &Content(void) {return myContent;} + + + const DWORD64 &Hash(void) const {return myHash;} + DWORD64 &Hash(void) {return myHash;} + +private: + uMod_Data myContent; + DWORD64 myHash; + + + + /** + * forbid assignment! + * @param rh + * @return + */ + uMod_TextureElement operator= (const uMod_TextureElement & rh) {(void*) &rh; return *this;} + +}; + + + + +//WX_DEFINE_ARRAY_PTR( uMod_ModElement*, uMod_ModElement_ArrayPtr ); + +WX_DEFINE_SORTED_ARRAY( uMod_TextureElement*, uMod_TextureElement_SortedArrayPtr ); +int Compare_uMod_TextureElement(uMod_TextureElement* a, uMod_TextureElement* b); + + + + + +#endif /* UMOD_MODELEMENT_H_ */ diff --git a/uMod_GUI/uMod_Sender.cpp b/uMod_GUI/uMod_Sender.cpp index 2e0521e..cbe0b41 100644 --- a/uMod_GUI/uMod_Sender.cpp +++ b/uMod_GUI/uMod_Sender.cpp @@ -23,45 +23,45 @@ along with Universal Modding Engine. If not, see uMod_Sender::uMod_Sender(PipeStruct &pipe) : Pipe(pipe) { - OldTextures = NULL; - OldTexturesNum = 0; try {Buffer = new char[BIG_BUFSIZE];} - catch (...) {Buffer=NULL;} + catch (...) {Buffer=(char*)0;} + OldTextures = (uMod_TextureElement_SortedArrayPtr*)0; } uMod_Sender::~uMod_Sender(void) { - if (Buffer!=NULL) delete [] Buffer; - if (OldTextures!=NULL) delete [] OldTextures; + if (Buffer!=(char*)0) delete [] Buffer; + if (OldTextures != (uMod_TextureElement_SortedArrayPtr*)0) + { + for (unsigned int t=0; tGetCount(); t++) + { + OldTextures->Item(t)->Release(); + } + delete OldTextures; + } } -int uMod_Sender::Send( const uMod_GameInfo &game, const uMod_GameInfo &game_old, bool force, wxArrayString *comments) +int uMod_Sender::Send( const uMod_GameInfo &game, const uMod_GameInfo &game_old, uMod_TextureElement_SortedArrayPtr* current_textures, bool force) { LastError.Empty(); + int key = game.GetKeyBack(); if (key>=0 && key!=game_old.GetKeyBack()) - { - key = Language->KeyValues[key]; SendKey( key, CONTROL_KEY_BACK); - } + key = game.GetKeySave(); if (key>=0 && key!=game_old.GetKeySave()) - { - key = Language->KeyValues[key]; SendKey( key, CONTROL_KEY_SAVE); - } + key = game.GetKeyNext(); if (key>=0 && key!=game_old.GetKeyNext()) - { - key = Language->KeyValues[key]; SendKey( key, CONTROL_KEY_NEXT); - } - int colour[3], colour_old[3]; + unsigned char colour[4], colour_old[4]; game.GetFontColour( colour); game_old.GetFontColour( colour_old); - for (int i=0; i<3; i++) if (colour[i]!=colour_old[i]) + for (int i=0; i<4; i++) if (colour[i]!=colour_old[i]) { SendColour( colour, CONTROL_FONT_COLOUR); break; @@ -69,182 +69,57 @@ int uMod_Sender::Send( const uMod_GameInfo &game, const uMod_GameInfo &game_old, game.GetTextureColour( colour); game_old.GetTextureColour( colour_old); - for (int i=0; i<3; i++) if (colour[i]!=colour_old[i]) + for (int i=0; i<4; i++) if (colour[i]!=colour_old[i]) { SendColour( colour, CONTROL_TEXTURE_COLOUR); break; } + SendDWORD64( game.FileFormat(), CONTROL_SAVE_FORMAT); - if ( game.GetSaveSingleTexture() != game_old.GetSaveSingleTexture() ) SendSaveSingleTexture( game.GetSaveSingleTexture()); - if ( game.GetSaveAllTextures() != game_old.GetSaveAllTextures() ) SendSaveAllTextures(game.GetSaveAllTextures()); + if (game.UseFormatFilter()) + SendDWORD64( game.FormatFilter(), CONTROL_FORMAT_FILTER); + else + SendDWORD64( 0u, CONTROL_FORMAT_FILTER); + + if (game.UseSizeFilter()) + { + SendMinMax( game.WidthMin(), game.WidthMax(), CONTROL_WIDTH_FILTER); + SendMinMax( game.HeightMin(), game.HeightMax(), CONTROL_HEIGHT_FILTER); + SendMinMax( game.DepthMin(), game.DepthMax(), CONTROL_DEPTH_FILTER); + } + else + { + SendMinMax( 0, 0, CONTROL_HEIGHT_FILTER); + SendMinMax( 0, 0, CONTROL_HEIGHT_FILTER); + SendMinMax( 0, 0, CONTROL_HEIGHT_FILTER); + } + + SendBool( game.ShowSingleTextureString(), CONTROL_SHOW_STRING); + SendBool( game.GetSaveSingleTexture(), CONTROL_SAVE_SINGLE); + SendBool(game.GetSaveAllTextures(), CONTROL_SAVE_ALL); + + SendBool(game.SupportTPF(), CONTROL_SUPPORT_TPF); wxString path; path = game.GetSavePath(); if (path!=game_old.GetSavePath()) SendPath(path); - if (game.GetNumberOfFiles()<=0 && OldTexturesNum==0 && OldTextures==NULL) + + + if ( OldTextures== (uMod_TextureElement_SortedArrayPtr*)0) OldTextures = new uMod_TextureElement_SortedArrayPtr( Compare_uMod_TextureElement ); + + //uMod_TextureElement_SortedArrayPtr* current_textures = new uMod_TextureElement_SortedArrayPtr( Compare_uMod_TextureElement ); + + SendTextures( *OldTextures, *current_textures, force); + + for (unsigned int t=0; tGetCount(); t++) { - if (LastError.Len()>0) return 1; - else return 0; + OldTextures->Item(t)->Release(); } - - wxArrayString files; - - game.GetFiles( files); - int num = files.GetCount(); - bool *checked = NULL; - if (num>0) - { - if (GetMemory(checked, num)) {LastError << Language->Error_Memory; return -1;} - game.GetChecked( checked, num); - } - - AddTextureClass *tex = NULL;//new AddTextureClass[num+OldTexturesNum]; - if (GetMemory( tex, num+OldTexturesNum)) {LastError << Language->Error_Memory; return -1;} - wxString comment; - - if (force || OldTexturesNum==0 || OldTextures==NULL) - { - //reload everything - for (int i=0; i0 && OldTextures!=NULL) - { - for (int i=0; iError_Memory; return -1;} - for (pos=0; pos looking brute force - for (int i=pos; i0) - { - comments->Empty(); - comments->Alloc(num); - for (int i=0; iAdd(tex[i].Comment); - } - - if (OldTextures!=NULL) delete [] OldTextures; - - OldTexturesNum = num; - OldTextures = tex; + delete OldTextures; + OldTextures = current_textures; if (LastError.Len()>0) return 1; else return 0; @@ -275,101 +150,132 @@ int uMod_Sender::SendSaveSingleTexture(bool val) } -int uMod_Sender::SendTextures(unsigned int num, AddTextureClass *tex) +int uMod_Sender::SendTextures(const uMod_TextureElement_SortedArrayPtr &old_tex, const uMod_TextureElement_SortedArrayPtr &new_tex, bool force) { - if (Buffer==NULL) return (RETURN_NO_MEMORY); + if (Buffer==(char*)0) return (RETURN_NO_MEMORY); + unsigned int old_pos=0; + unsigned int new_pos=0; MsgStruct *msg; - int pos = 0; - for (unsigned int i=0u; iHash() < new_tex[new_pos]->Hash()) { - bool hit = false; //we send only if this has was not send before - unsigned long temp_hash = tex[i].Hash[j]; - for (unsigned int ii=0u; ii=BIG_BUFSIZE) //the buffer is full - { - if (int ret = SendToGame( Buffer, pos)) return ret; - pos = 0; - } - - msg = (MsgStruct*) &Buffer[pos]; - msg->Hash = temp_hash; - msg->Value = size; - pos += sizeof(MsgStruct); - - if (tex[i].Add) - { - msg->Control = CONTROL_FORCE_RELOAD_TEXTURE_DATA; //we always force because whether force is true or not - //if (Add==true && WasAdded[j]!=true) the texture is loaded the first time, or in previous loads it could not be loaded - //because an other texture was send with the same hash, in all cases forcing is the best choice (atm) - char* temp = tex[i].Textures[j]; - if (temp!=NULL) - { - unsigned int l = 0u; - while (lControl = CONTROL_REMOVE_TEXTURE; - tex[i].WasAdded[j] = false; - } + RemoveTexture(old_tex[old_pos], buffer_pos); + old_pos++; } - else if (tex[i].Add && tex[i].WasAdded[j]) // this texture could be removed, due to a rearranging of the list + else if (old_tex[old_pos]->Hash() < new_tex[new_pos]->Hash()) { - bool hit = false; //we send only if this has was not send before - unsigned long temp_hash = tex[i].Hash[j]; - for (unsigned int ii=0u; ii=BIG_BUFSIZE) //the buffer is full + // add remaining texture in new_tex + while (new_pos=BIG_BUFSIZE) //the buffer is full + { + if (int ret = SendToGame( Buffer, buffer_pos)) return ret; + buffer_pos = 0; + } + + msg = (MsgStruct*) &Buffer[buffer_pos]; msg->Control = CONTROL_END_TEXTURES; //End of texture sending msg->Hash = 0u; msg->Value = 0; - pos += sizeof(MsgStruct); - if (int ret = SendToGame( Buffer, pos)) return ret; + buffer_pos += sizeof(MsgStruct); + if (int ret = SendToGame( Buffer, buffer_pos)) return ret; if (LastError.Len()>0) return 1; else return 0; } +int uMod_Sender::AddTexture( uMod_TextureElement *tex, int &buffer_pos) +{ + MsgStruct *msg; + unsigned int size = tex->Content().Len(); + if ((sizeof(MsgStruct) + buffer_pos) >=BIG_BUFSIZE) //the buffer is full + { + if (int ret = SendToGame( Buffer, buffer_pos)) return ret; + buffer_pos = 0; + } + + msg = (MsgStruct*) &Buffer[buffer_pos]; + msg->Hash = tex->Hash(); + msg->Value = size; + msg->Control = CONTROL_FORCE_RELOAD_TEXTURE_DATA; + + + buffer_pos += sizeof(MsgStruct); + + const char* temp = tex->Content().Data(); + if (temp!=(char*)0) + { + unsigned int l = 0u; + while (l0) return 1; + else return 0; +} + +int uMod_Sender::RemoveTexture( uMod_TextureElement *tex, int &buffer_pos) +{ + MsgStruct *msg; + //empty the buffer if it can't hold 1 MsgStruct anymore + if ((sizeof(MsgStruct) + buffer_pos) >=BIG_BUFSIZE) //the buffer is full + { + if (int ret = SendToGame( Buffer, buffer_pos)) return ret; + buffer_pos = 0; + } + + msg = (MsgStruct*) &Buffer[buffer_pos]; + msg->Hash = tex->Hash(); + msg->Control = CONTROL_REMOVE_TEXTURE; + buffer_pos += sizeof(MsgStruct); + + + if (LastError.Len()>0) return 1; + else return 0; +} int uMod_Sender::SendKey(int key, int ctr) { + if (key<0) key=0; MsgStruct msg; msg.Control = ctr; msg.Value = key; @@ -380,11 +286,11 @@ int uMod_Sender::SendKey(int key, int ctr) #define D3DCOLOR_ARGB(a,r,g,b) ((DWORD)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) -int uMod_Sender::SendColour( int* colour, int ctr) +int uMod_Sender::SendColour( unsigned char* colour, int ctr) { MsgStruct msg; msg.Control = ctr; - msg.Value = D3DCOLOR_ARGB( 255, colour[0], colour[1], colour[2]); + msg.Value = D3DCOLOR_ARGB( colour[3], colour[0], colour[1], colour[2]); msg.Hash = 0u; return SendToGame( (void*) &msg, sizeof(MsgStruct)); @@ -411,6 +317,39 @@ int uMod_Sender::SendPath( const wxString &path) } +int uMod_Sender::SendBool( bool val, int ctr) +{ + MsgStruct msg; + msg.Control = ctr; + if (val) msg.Value = 1; + else msg.Value = 0; + msg.Hash = 0u; + + return SendToGame( (void*) &msg, sizeof(MsgStruct)); +} +int uMod_Sender::SendDWORD64( DWORD64 val, int ctr) +{ + MsgStruct msg; + msg.Control = ctr; + msg.Value = val; + msg.Hash = 0u; + + return SendToGame( (void*) &msg, sizeof(MsgStruct)); +} + +int uMod_Sender::SendMinMax( unsigned long min, unsigned long max, int ctr) +{ + DWORD64 u_min = min, u_max = max; + MsgStruct msg; + msg.Control = ctr; + msg.Value = u_min<<32 | u_max; + msg.Hash = 0u; + + return SendToGame( (void*) &msg, sizeof(MsgStruct)); +} + + + int uMod_Sender::SendToGame( void *msg, unsigned long len) { if (len==0) return (RETURN_BAD_ARGUMENT); diff --git a/uMod_GUI/uMod_Sender.h b/uMod_GUI/uMod_Sender.h index 336b194..ad7ec78 100644 --- a/uMod_GUI/uMod_Sender.h +++ b/uMod_GUI/uMod_Sender.h @@ -31,7 +31,7 @@ public: uMod_Sender(PipeStruct &pipe); ~uMod_Sender(void); - int Send( const uMod_GameInfo &game, const uMod_GameInfo &game_old, bool force=false, wxArrayString *comments=NULL); + int Send( const uMod_GameInfo &game, const uMod_GameInfo &game_old, uMod_TextureElement_SortedArrayPtr* current_textures, bool force=false); wxString LastError; @@ -39,13 +39,22 @@ private: int SendSaveAllTextures(bool val); int SendSaveSingleTexture(bool val); - int SendTextures(unsigned int num, AddTextureClass *tex); + int SendTextures(const uMod_TextureElement_SortedArrayPtr &old_tex, const uMod_TextureElement_SortedArrayPtr &new_tex, bool force); + + int AddTexture( uMod_TextureElement *tex, int &buffer_pos); + int RemoveTexture( uMod_TextureElement *tex, int &buffer_pos); int SendKey(int key, int ctr); int SendPath( const wxString &path); - int SendColour( int* colour, int ctr); + int SendColour( unsigned char* colour, int ctr); + + + int SendBool( bool val, int ctr); + int SendDWORD64( DWORD64 val, int ctr); + + int SendMinMax( unsigned long min, unsigned long max, int ctr); char *Buffer; int SendToGame( void* msg, unsigned long len); @@ -55,8 +64,7 @@ private: int AddContent( char* buffer, unsigned int len, const char* pw, AddTextureClass *tex, bool add, bool force); PipeStruct &Pipe; - AddTextureClass *OldTextures; - int OldTexturesNum; + uMod_TextureElement_SortedArrayPtr *OldTextures; }; diff --git a/uMod_GUI/uMod_Server.cpp b/uMod_GUI/uMod_Server.cpp index 6aacf63..6f7b4c7 100644 --- a/uMod_GUI/uMod_Server.cpp +++ b/uMod_GUI/uMod_Server.cpp @@ -42,10 +42,6 @@ void* uMod_Server::Entry(void) while(1) { -/* - Beep(300,100); - Beep(600,100); -*/ pipe_in = CreateNamedPipeW( PIPE_Game2uMod, // pipe name PIPE_ACCESS_INBOUND, // read access @@ -74,11 +70,7 @@ void* uMod_Server::Entry(void) // 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; @@ -92,15 +84,15 @@ void* uMod_Server::Entry(void) if (fSuccess) { - if (num>2) + if (num>4) { buffer[num]=0; buffer[num-1]=0; - wxString name = (wchar_t*) buffer; + int injection_method = * ((int*)buffer); + wxString name = (wchar_t*) &buffer[sizeof(int)]; if (name==abort) // kill this server thread { - //Beep(1200,300); CloseHandle(pipe_in); return NULL; } @@ -110,11 +102,13 @@ void* uMod_Server::Entry(void) true : (GetLastError() == ERROR_PIPE_CONNECTED); if (fConnected) { - uMod_Event event( uMod_EVENT_TYPE, ID_Add_Game); - event.SetName(name); - event.SetPipeIn(pipe_in); - event.SetPipeOut(pipe_out); - wxPostEvent( MainFrame, event); + uMod_Event *event = new uMod_Event( uMod_EVENT_TYPE, ID_Add_Game); + event->SetName(name.c_str()); + event->SetValue(injection_method); + event->SetPipeIn(pipe_in); + event->SetPipeOut(pipe_out); + wxQueueEvent( MainFrame, (wxEvent*) event); + //wxPostEvent( MainFrame, event); } else { @@ -123,6 +117,14 @@ void* uMod_Server::Entry(void) return NULL; } } + else + { + wxMessageBox("less than 4 bytes"); + } + } + else + { + wxMessageBox("no success"); } } else CloseHandle(pipe_in); diff --git a/uMod_GUI/uMod_Settings.cpp b/uMod_GUI/uMod_Settings.cpp index f37a26e..5cf0fc1 100644 --- a/uMod_GUI/uMod_Settings.cpp +++ b/uMod_GUI/uMod_Settings.cpp @@ -118,6 +118,19 @@ int uMod_Settings::Load(void) } } + int width, height; + wxDisplaySize( &width, &height); + + if (XSize>width) XSize = width; + if (YSize>height) YSize = height; + if (XSize<50) XSize = 50; + if (YSize<50) YSize = 50; + + if (XPos>width-XSize) XPos = width-XSize; + if (YPos>height-YSize) YPos = height-YSize; + if (XPos<0) XPos = 0; + if (YPos<0) YPos = 0; + return 0; } @@ -133,17 +146,29 @@ int uMod_Settings::Save(void) content << Language << "\n"; file.Write( content.wc_str(), content.Len()*2); - content.Printf("x_size:%d\n", XSize); - file.Write( content.wc_str(), content.Len()*2); + if (XSize>0 && XSize<50000) + { + content.Printf("x_size:%d\n", XSize); + file.Write( content.wc_str(), content.Len()*2); + } - content.Printf("y_size:%d\n", YSize); - file.Write( content.wc_str(), content.Len()*2); + if (YSize>0 && YSize<50000) + { + content.Printf("y_size:%d\n", YSize); + file.Write( content.wc_str(), content.Len()*2); + } - content.Printf("x_pos:%d\n", XPos); - file.Write( content.wc_str(), content.Len()*2); + if (XPos>0 && XPos<50000) + { + content.Printf("x_pos:%d\n", XPos); + file.Write( content.wc_str(), content.Len()*2); + } - content.Printf("y_pos:%d\n", YPos); - file.Write( content.wc_str(), content.Len()*2); + if (YPos>0 && YPos<50000) + { + content.Printf("y_pos:%d\n", YPos); + file.Write( content.wc_str(), content.Len()*2); + } if (UseHook) content = "UseHook:1\n"; else content = "UseHook:0\n"; diff --git a/uMod_GUI/uMod_TreeView.cpp b/uMod_GUI/uMod_TreeView.cpp new file mode 100644 index 0000000..938393d --- /dev/null +++ b/uMod_GUI/uMod_TreeView.cpp @@ -0,0 +1,762 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + +#include "uMod_Main.h" + +wxString uMod_TreeViewModel::LastError = wxString(); + + +void uMod_TreeViewModel::GetValue( wxVariant &variant, + const wxDataViewItem &item, unsigned int col ) const +{ + wxASSERT(item.IsOk()); + + uMod_TreeViewNode *node = (uMod_TreeViewNode*) item.GetID(); + switch (col) + { + case 0: + if (node->myElement->Title().IsEmpty()) variant = node->myElement->File(); + else variant = node->myElement->Title(); + break; + case 1: + variant = (bool) (node->myElement->Status()==uMod_ModElement::Activate); + break; + case 2: + variant = (bool) (node->myElement->Status()==uMod_ModElement::Deactivate); + break; + case 3: + variant = node->myElement->Author(); + break; + case 4: + variant = node->myElement->Comment(); + break; + + default: + break; + } +} + +bool uMod_TreeViewModel::SetValue( const wxVariant &variant, + const wxDataViewItem &item, unsigned int col ) +{ + wxASSERT(item.IsOk()); + if (col<1 || col>2) return false; + + uMod_TreeViewNode *node = (uMod_TreeViewNode*) item.GetID(); + bool set; + variant.Convert( &set); + + uMod_ModElement::enumStatus status = uMod_ModElement::NONE; + if (set) + { + switch (col) + { + case 1: + status = uMod_ModElement::Activate; + break; + case 2: + status = uMod_ModElement::Deactivate; + break; + default: + return false; + break; + } + node->myElement->Status() = status; + } + else + { + if (node->myElement->Type() == uMod_ModElement::Group) + { + node->myElement->Status() = uMod_ModElement::NONE; + } + } + + return true; +} + +bool uMod_TreeViewModel::IsEnabled( const wxDataViewItem &item, + unsigned int col ) const +{ + //only the toggle are enabled + if (col<1 || col >3) return false; + + uMod_TreeViewNode *node = (uMod_TreeViewNode*) item.GetID(); + + //an item is only enabled if no one of the parents is set. + uMod_TreeViewNode *parent = node->GetParent(); + while (parent != (uMod_TreeViewNode*)0) + { + if (parent->myElement->Status()!=uMod_ModElement::NONE) return false; + parent = parent->GetParent(); + } + return true; +} + +wxDataViewItem uMod_TreeViewModel::GetParent( const wxDataViewItem &item ) const +{ + // the invisible root node has no parent + if (!item.IsOk()) + return wxDataViewItem(0); + + uMod_TreeViewNode *node = (uMod_TreeViewNode*) item.GetID(); + return wxDataViewItem( (void*) node->GetParent() ); +} + +bool uMod_TreeViewModel::HasContainerColumns( const wxDataViewItem &WXUNUSED(item) ) const +{ + return true; +} + +bool uMod_TreeViewModel::IsContainer( const wxDataViewItem &item ) const +{ + // the invisble root node can have children + if (!item.IsOk()) + return true; + + uMod_TreeViewNode *node = (uMod_TreeViewNode*) item.GetID(); + return node->IsContainer(); +} + +unsigned int uMod_TreeViewModel::GetChildren( const wxDataViewItem &parent, + wxDataViewItemArray &array ) const +{ + uMod_TreeViewNode *node = (uMod_TreeViewNode*) parent.GetID(); + if (!node) + { + + unsigned int count = myPackages.GetCount(); + for (unsigned int pos = 0; pos < count; pos++) + { + uMod_TreeViewNode *child = myPackages.Item( pos ); + array.Add( wxDataViewItem( (void*) child ) ); + } + return count; + } + + if (node->GetChildCount() == 0) + { + return 0; + } + + unsigned int count = node->GetChildren().GetCount(); + for (unsigned int pos = 0; pos < count; pos++) + { + uMod_TreeViewNode *child = node->GetChildren().Item( pos ); + array.Add( wxDataViewItem( (void*) child ) ); + } + return count; +} + +int uMod_TreeViewModel::CreateSingleNode() +{ + if (SingleTextureNode ==(uMod_TreeViewNode*)0) + { + uMod_ModElement *package = new uMod_ModElement(uMod_ModElement::Group, uMod_ModElement::Activate); + + SingleTextureNode = new uMod_TreeViewNode( (uMod_TreeViewNode*)0, package); + package->Release(); + package->Title() = Language->SingleTextureNode; + myPackages.Add( SingleTextureNode); + wxDataViewItem child( (void*) SingleTextureNode ); + wxDataViewItem parent( (void*) 0 ); + ItemAdded( parent, child ); + } + return 0; +} + +int uMod_TreeViewModel::AddPackage(const wxString &file_name) +{ + uMod_File file( file_name); + if (! file.FileSupported()) + { + LastError << Language->Error_FileNotSupported << "\n" << file_name; + return -1; + } + bool single_file = file.SingleFile(); + + uMod_TreeViewNode *node; + + if (single_file) + { + CreateSingleNode(); + node = SingleTextureNode; + } + else + { + uMod_ModElement *package = new uMod_ModElement(uMod_ModElement::Group, uMod_ModElement::Activate); + + node = new uMod_TreeViewNode( (uMod_TreeViewNode*)0, package); + package->Release(); + package->File() = file_name; + } + + if (int ret = file.GetContent(node)) + { + LastError = file.LastError; + if (node != SingleTextureNode) delete node; + return ret; + } + + if (node != SingleTextureNode) + { + myPackages.Add( node); + + wxDataViewItem child( (void*) node ); + wxDataViewItem parent( (void*) 0 ); + ItemAdded( parent, child ); + } + else if (SingleTextureNode != (uMod_TreeViewNode*)0) + { + wxDataViewItem child( (void*) SingleTextureNode->myChildren.Last() ); + wxDataViewItem parent( SingleTextureNode ); + ItemAdded( parent, child ); + } + + return 0; +} + +int uMod_TreeViewModel::AddPackages(const wxArrayString &files) +{ + LastError.Empty(); + uMod_File file; + wxDataViewItemArray added_items; + wxDataViewItemArray added_single_items; + /* + bool single_file = false; + + // detect if there are more than one single file + for (unsigned int i=0; i1) + { + uMod_ModElement *element = new uMod_ModElement(uMod_ModElement::Group, uMod_ModElement::NONE); + element->Title() = Language->MultipleSingleFiles; + single_file_node = new uMod_TreeViewNode( (uMod_TreeViewNode*)0, element); + element->Release(); + } +*/ + + for (unsigned int i=0; iError_FileNotSupported << "\n" << files[i] << "\n" ; + continue; + } + + if (file.SingleFile()) + { + CreateSingleNode(); + if (file.GetContent(SingleTextureNode)) + { + LastError << file.LastError ; + file.LastError.Empty(); + continue; + } + wxDataViewItem child( (void*) SingleTextureNode->myChildren.Last() ); + added_single_items.Add( child); + } + else + { + uMod_ModElement *package = new uMod_ModElement(uMod_ModElement::Group, uMod_ModElement::Activate); + uMod_TreeViewNode *node = new uMod_TreeViewNode( (uMod_TreeViewNode*)0, package); + package->Release(); + package->File() = files[i]; + + if (file.GetContent(node)) + { + LastError << file.LastError; + delete node; + file.LastError.Empty(); + continue; + } + myPackages.Add( node); + + wxDataViewItem child( (void*) node ); + added_items.Add( child); + } + } + + if (added_items.GetCount()>0) + { + wxDataViewItem parent( (void*) 0 ); + ItemsAdded( parent, added_items); + } + + if (added_single_items.GetCount()>0) + { + wxDataViewItem parent( SingleTextureNode ); + ItemsAdded( parent, added_single_items); + } + + if (LastError.IsEmpty()) return 0; + else return -1; +} + + +int uMod_TreeViewModel::AddPackagesFromTemplate(const wxArrayString &packages) +{ + LastError.Empty(); + + uMod_File file; + wxDataViewItemArray added_items; + + DeleteAllPackages(); + + for (unsigned int i=0; iRelease(); + + if (file.GetContentTemplate( packages[i], node)) + { + LastError << file.LastError; + file.LastError.Empty(); + delete node; + continue; + } + + myPackages.Add( node); + + wxDataViewItem child( (void*) node ); + added_items.Add( child); + + if (node->myElement->File().IsEmpty()) + { + SingleTextureNode = node; + SingleTextureNode->myElement->Title() = Language->SingleTextureNode; + } + } + + if (added_items.GetCount()>0) + { + wxDataViewItem parent( (void*) 0 ); + ItemsAdded( parent, added_items); + } + + if (LastError.IsEmpty()) return 0; + else return -1; +} + + +int uMod_TreeViewModel::DeletePackage( const wxDataViewItem &item) +{ + uMod_TreeViewNode *node = (uMod_TreeViewNode*) item.GetID(); + if (node) + { + if (node->GetParent()== (uMod_TreeViewNode*) 0 ) + { + myPackages.Remove( node); + delete node; + if (node == SingleTextureNode) SingleTextureNode = (uMod_TreeViewNode*) 0; + + + wxDataViewItem parent( (void*) 0 ); + ItemDeleted( parent, item ); + return 0; + } + return 1; + } + return 2; +} + +int uMod_TreeViewModel::DeletePackages( const wxDataViewItemArray &items) +{ + int num = items.GetCount(); + wxDataViewItemArray deleted_items; + for (int i=0; iGetParent()== (uMod_TreeViewNode*) 0 ) + { + myPackages.Remove( node); + delete node; + if (node == SingleTextureNode) SingleTextureNode = (uMod_TreeViewNode*) 0; + deleted_items.Add( items[i]); + } + } + } + wxDataViewItem parent( (void*) 0 ); + ItemsDeleted( parent, deleted_items); + return 0; +} + +int uMod_TreeViewModel::DeleteAllPackages(void) +{ + wxDataViewItemArray deleted_items; + for (unsigned int i=0; iparent1->parent2->current_group) + wxArrayInt counter; // this array store the actual index position for each group in the hierarchy + wxArrayInt active; // this array is need for the inherited active status of parent groups + + for (unsigned int p=0; pmyElement->Status()==uMod_ModElement::Deactivate) continue; + + + + if (myPackages.Item(p)->myElement->Type() == uMod_ModElement::Group) + { + buffer.Add(myPackages.Item(p)); + counter.Add(0); + if (myPackages.Item(p)->myElement->Status()==uMod_ModElement::Activate) active.Add(1); + else active.Add(0); + + while (!buffer.IsEmpty()) + { + int pos = buffer.GetCount()-1; + unsigned int index = counter[pos]; + if (index < buffer[pos]->myChildren.GetCount()) // it has still childrens + { + if (buffer[pos]->myChildren[index]->myElement->Type() == uMod_ModElement::Group) + { + if ((active[pos]>0) || (buffer[pos]->myChildren[index]->myElement->Status() != uMod_ModElement::Deactivate)) + { + buffer.Add(buffer[pos]->myChildren[index]); + counter.Add(0); + if (active[pos]>0 || buffer[pos]->myChildren[index]->myElement->Status()==uMod_ModElement::Activate) active.Add(1); + else active.Add(0); + } + } + else if (buffer[pos]->myChildren[index]->myElement->Type() == uMod_ModElement::Texture) + { + uMod_TextureElement *tex = (uMod_TextureElement*) buffer[pos]->myChildren[index]->myElement; + + if (tex->Content().Len()>0 && ((active[pos]>0) || (tex->Status()==uMod_ModElement::Activate))) + { + if( wxNOT_FOUND == texture.Index(tex)) + { + texture.Add(tex); + tex->AddRef(); + } + } + } + + counter[pos]++; + } + else // finished this group + { + buffer.RemoveAt(pos); + counter.RemoveAt(pos); + active.RemoveAt(pos); + } + } + } + else if (myPackages.Item(p)->myElement->Type()==uMod_ModElement::Texture) + { + uMod_TextureElement *tex = (uMod_TextureElement*) myPackages.Item(p)->myElement; + if (tex->Status()==uMod_ModElement::Activate) + if (wxNOT_FOUND == texture.Index(tex)) + { + texture.Add(tex); + tex->AddRef(); + } + } + } + + return 0; +} + +int uMod_TreeViewModel::String2Node( const wxString &input, uMod_TreeViewNode* node, uMod_TreeViewNode_ArrayPtr *list_node) +{ + if (list_node!=(uMod_TreeViewNode_ArrayPtr*)0) list_node->Empty(); + + wxStringTokenizer token( input, "\n"); + int num = token.CountTokens(); + + bool found_start = false; + + wxString entry; + + wxString command; + wxString file; + wxString action; + wxString hash; + uMod_TreeViewNode_ArrayPtr buffer; + buffer.Add(node); + + for (int i=0; imyElement->File() = entry_token.GetNextToken().Trim(true).Trim(false); + node->myElement->Title() = entry_token.GetNextToken().Trim(true).Trim(false); + action = entry_token.GetNextToken().Trim(true).Trim(false); + if (action=="D") node->myElement->Status() = uMod_ModElement::Deactivate; + else if (action=="A") node->myElement->Status() = uMod_ModElement::Activate; + else node->myElement->Status() = uMod_ModElement::NONE; + node->myElement->Author() = entry_token.GetNextToken().Trim(true).Trim(false); + node->myElement->Comment() = entry_token.GetNextToken().Trim(true).Trim(false); + } + continue; + } + + if (command=="BEGIN_GROUP") + { + uMod_ModElement *element = new uMod_ModElement(uMod_ModElement::Group, uMod_ModElement::NONE); + uMod_TreeViewNode *node_group = new uMod_TreeViewNode(buffer.Last(), element); + + element->Title() = entry_token.GetNextToken().Trim(true).Trim(false); + action = entry_token.GetNextToken().Trim(true).Trim(false); + if (action=="D") element->Status() = uMod_ModElement::Deactivate; + else if (action=="A") element->Status() = uMod_ModElement::Activate; + else element->Status() = uMod_ModElement::NONE; + element->Author() = entry_token.GetNextToken().Trim(true).Trim(false); + element->Comment() = entry_token.GetNextToken().Trim(true).Trim(false); + + + if (list_node != (uMod_TreeViewNode_ArrayPtr*)0) list_node->Add(node_group); + + // add node to the last group + buffer.Last()->Append( node_group); + element->Release(); + + //set this group to the last group + buffer.Add( node_group); + } + else if (command=="END_GROUP") + { + if (buffer.GetCount()==0) + { + LastError << "There is an END_GROUP without a previous BEGIN_GROUP"; + return -1; + } + buffer.RemoveAt(buffer.GetCount()-1); + } + else if (command=="TEXTURE") + { + if (buffer.GetCount()==0) continue; + + file = entry_token.GetNextToken().Trim(true).Trim(false); + hash = entry_token.GetNextToken().Trim(true).Trim(false); + + if (file.IsEmpty()) + continue; + if (hash.IsEmpty()) + continue; + + DWORD64 temp_hash; + if (!hash.ToULongLong( &temp_hash, 16)) + { + LastError << Language->Error_Hash << "\n"; + continue; + } + + uMod_TextureElement *texture = new uMod_TextureElement(); + + texture->File() = file; + texture->Hash() = temp_hash; + + texture->Title() = entry_token.GetNextToken().Trim(true).Trim(false); + action = entry_token.GetNextToken().Trim(true).Trim(false); + if (action=="D") texture->Status() = uMod_ModElement::Deactivate; + else texture->Status() = uMod_TextureElement::Activate; + texture->Author() = entry_token.GetNextToken().Trim(true).Trim(false); + texture->Comment() = entry_token.GetNextToken().Trim(true).Trim(false); + + uMod_TreeViewNode *node_texture = new uMod_TreeViewNode( buffer.Last(), texture); + + if (list_node != (uMod_TreeViewNode_ArrayPtr*)0) list_node->Add(node_texture); + + // add node to the last group + buffer.Last()->Append( node_texture); + texture->Release(); + } + } + + if (!found_start) + { + LastError = "Did not find 'PACKAGE' directive\n"; + return -1; + } + return 0; +} + + + +int uMod_TreeViewModel::Node2String( wxString &out, uMod_TreeViewNode* node) +{ + if (node==(uMod_TreeViewNode*)0) return -1; + out.Empty(); + uMod_TreeViewNode_ArrayPtr buffer; // this array store the "path" to the current group node (parent0->parent1->parent2->current_group) + wxArrayInt counter; // this array store the actual index position for each group in the hierarchy + + if (node->myElement->Type() != uMod_ModElement::Group) return -1; + + out << "\nPACKAGE|" << node->myElement->File() << "|"; + out << node->myElement->Title() << "|"; + if (node->myElement->Status() == uMod_ModElement::Activate) out << "A"; + else if (node->myElement->Status() == uMod_ModElement::Deactivate) out << "D"; + out << "|" << node->myElement->Author(); + out << "|" << node->myElement->Comment() << "\n\n"; + + buffer.Add( node); + counter.Add(0); + /* + + if (node->myElement->Type() == uMod_ModElement::Group) + { + buffer.Add(node); + counter.Add(0); + + out << "\nBEGIN_GROUP|"<myElement->Title() << "|"; + if (node->myElement->Status() == uMod_ModElement::Activate) out << "A"; + else if (node->myElement->Status() == uMod_ModElement::Deactivate) out << "D"; + out << "|" << node->myElement->Author(); + out << "|" << node->myElement->Comment(); + out << "\n\n"; +*/ + + while (!buffer.IsEmpty()) + { + int pos = buffer.GetCount()-1; + unsigned int index = counter[pos]; + if (index < buffer[pos]->myChildren.GetCount()) // it has still childrens + { + if (buffer[pos]->myChildren[index]->myElement->Type() == uMod_ModElement::Group) + { + uMod_TreeViewNode* node_child = buffer[pos]->myChildren[index]; + + out << "\nBEGIN_GROUP|"<< node_child->myElement->Title() << "|"; + if (node_child->myElement->Status() == uMod_ModElement::Activate) out << "A"; + else if (node_child->myElement->Status() == uMod_ModElement::Deactivate) out << "D"; + out << "|" << node_child->myElement->Author(); + out << "|" << node_child->myElement->Comment(); + out << "\n"; + + buffer.Add(node_child); + counter.Add(0); + } + else if (buffer[pos]->myChildren[index]->myElement->Type() == uMod_ModElement::Texture) + { + uMod_TextureElement *tex = (uMod_TextureElement*) buffer[pos]->myChildren[index]->myElement; + out << "TEXTURE|"<< tex->File() << "|" ; + out << wxString::Format("%#llX", tex->Hash()) << "|"; + out << tex->Title() << "|"; + if (tex->Status() == uMod_ModElement::Deactivate) out << "D"; + out << "|" << tex->Author(); + out << "|" << tex->Comment(); + out << "\n"; + } + + counter[pos]++; + } + else // finished this group + { + buffer.RemoveAt(pos); + counter.RemoveAt(pos); + + if (buffer.GetCount()>0) out << "END_GROUP\n"; + } + } + /* + } + else if (node->myElement->Type()==uMod_ModElement::Texture) + { + uMod_TextureElement *tex = (uMod_TextureElement*) node->myElement; + + out << "TEXTURE|"<< tex->File() << "|" ; + out << wxString::Format("%#lX", tex->Hash()) << "|"; + out << tex->Title() << "|"; + if (tex->Status() == uMod_ModElement::Deactivate) out << "D"; + out << "|" << tex->Author(); + out << "|" << tex->Comment(); + out << "\n\n"; + + } +*/ + return 0; +} + +/* +bool uMod_TreeViewModel::IsSameNod(uMod_TreeViewNode* a, uMod_TreeViewNode* b) +{ + // at first we test for object specific stats + if (a->myElement->Type()==uMod_ModElement::Group && b->myElement->Type()==uMod_ModElement::Group) + { + //title must be the same + if (a->myElement->Title() != b->myElement->Title()) return false; + } + else if (a->myElement->Type()==uMod_ModElement::Texture && b->myElement->Type()==uMod_ModElement::Texture) + { + uMod_TextureElement *tex_a = (uMod_TextureElement*) a->myElement; + uMod_TextureElement *tex_b = (uMod_TextureElement*) b->myElement; + + //Hash, Title, and File must be the same + if (tex_a->Hash() != tex_b->Hash()) return false; + if (tex_a->Title() != tex_b->Title()) return false; + if (tex_a->File() != tex_b->File()) return false; + } + else return false; //not the same objects + + + // now we compare their parents + // the title of their parents must be the same + if (a->GetParent()!=(uMod_TreeViewNode*)0) + { + if (b->GetParent()!=(uMod_TreeViewNode*)0) + { + if (a->GetParent()->myElement->Title() == b->GetParent()->myElement->Title()) return true; + else return false; + } + else return false; + } + else if (b->GetParent()!=(uMod_TreeViewNode*)0) return false; + else return true; //both are root textures +} +*/ diff --git a/uMod_GUI/uMod_TreeView.h b/uMod_GUI/uMod_TreeView.h new file mode 100644 index 0000000..8e816b8 --- /dev/null +++ b/uMod_GUI/uMod_TreeView.h @@ -0,0 +1,136 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + + + +#ifndef uMod_TREEVIEW_H_ +#define uMod_TREEVIEW_H_ + +#include "wx/dataview.h" +#include "uMod_ModElement.h" + +class uMod_TreeViewNode; +WX_DEFINE_ARRAY_PTR( uMod_TreeViewNode*, uMod_TreeViewNode_ArrayPtr ); + +class uMod_TreeViewNode +{ +public: + uMod_TreeViewNode( uMod_TreeViewNode* parent, uMod_ModElement *element) : myParent(parent), myElement(element) + { + myElement->AddRef(); + } + + ~uMod_TreeViewNode() + { + // free all our children nodes + size_t count = myChildren.GetCount(); + for (size_t i = 0; i < count; i++) + { + uMod_TreeViewNode *child = myChildren[i]; + delete child; + } + myElement->Release(); + } + + bool IsContainer() const {if (myElement->Type() == uMod_ModElement::Group) return true; else return false;} + + uMod_TreeViewNode* GetParent() {return myParent;} + + uMod_TreeViewNode_ArrayPtr& GetChildren() {return myChildren;} + + uMod_TreeViewNode* GetNthChild( unsigned int n ) {return myChildren.Item( n);} + + void Insert( uMod_TreeViewNode* child, unsigned int n) {myChildren.Insert( child, n);} + + void Append( uMod_TreeViewNode* child ) {myChildren.Add( child );} + + unsigned int GetChildCount() const {return myChildren.GetCount();} + +public: // public to avoid getters/setters + uMod_ModElement *myElement; + +//private: + uMod_TreeViewNode* myParent; + uMod_TreeViewNode_ArrayPtr myChildren; +}; + + + +class uMod_TreeViewModel : public wxDataViewModel +{ +public: + uMod_TreeViewModel() : SingleTextureNode((uMod_TreeViewNode*)0) {} + virtual ~uMod_TreeViewModel() {} + + // implementation of base class virtuals to define model + + virtual unsigned int GetColumnCount() const + { + return 5; + } + + virtual wxString GetColumnType( unsigned int col ) const + { + (void) col; + return wxT("string"); + } + + virtual void GetValue( wxVariant &variant, + const wxDataViewItem &item, unsigned int col ) const; + virtual bool SetValue( const wxVariant &variant, + const wxDataViewItem &item, unsigned int col ); + + virtual bool IsEnabled( const wxDataViewItem &item, + unsigned int col ) const; + + virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const; + virtual bool HasContainerColumns( const wxDataViewItem &item ) const; + virtual bool IsContainer( const wxDataViewItem &item ) const; + virtual unsigned int GetChildren( const wxDataViewItem &parent, + wxDataViewItemArray &array ) const; + + + // implementation of uMod functions + int CreateSingleNode(void); + + int AddPackage(const wxString &file_name); + int AddPackages(const wxArrayString &files); + int AddPackagesFromTemplate(const wxArrayString &packages); + + int DeletePackage( const wxDataViewItem &item); + int DeletePackages( const wxDataViewItemArray &item); + int DeleteAllPackages(void); + + + int GetActiveTexture( uMod_TextureElement_SortedArrayPtr &texture); + + static int String2Node( const wxString &input, uMod_TreeViewNode* node, uMod_TreeViewNode_ArrayPtr *list_node = (uMod_TreeViewNode_ArrayPtr*)0); + + static int Node2String( wxString &out, uMod_TreeViewNode* node); + +// static bool IsSameNod(uMod_TreeViewNode* a, uMod_TreeViewNode* b); + + static wxString LastError; + +//private: + uMod_TreeViewNode *SingleTextureNode; + uMod_TreeViewNode_ArrayPtr myPackages; + +}; + +#endif /* uMod_TREEVIEW_H_ */ diff --git a/uMod_GlobalDefines.h b/uMod_GlobalDefines.h index bad1377..cce574d 100644 --- a/uMod_GlobalDefines.h +++ b/uMod_GlobalDefines.h @@ -19,29 +19,37 @@ along with Universal Modding Engine. If not, see #ifndef uMod_GlobalDefines_H_ #define uMod_GlobalDefines_H_ -//#define MyTypeHash DWORD64 -#define MyTypeHash DWORD32 #define BIG_BUFSIZE 1<<24 #define SMALL_BUFSIZE 1<<10 +/** + * This struct is the basic of the communication between dll and GUI. For each command send through the pipe a control value is set to MsgStruct::Control. + * The MsgStruct::Value can store various information (e.g. key values, boolean, or length of data). + * + * If mor date should be send, Control is set to one of the intended values and value to the amount of data in byte. + * After the MsgStruct is send also the data is send through the pipe. + */ typedef struct { - unsigned int Control; - unsigned int Value; - MyTypeHash Hash; + DWORD32 Control; //!< stores the control value + DWORD64 Value; //!< various meanings + DWORD64 Hash; } MsgStruct; +/** + * + */ typedef struct { - HANDLE In; - HANDLE Out; + HANDLE In; //!< Incoming pipe + HANDLE Out; //!< Outgoning pipe } PipeStruct; #define uMod_APP_DX9 L"uMod_DX9.txt" #define uMod_APP_DIR L"uMod" -#define uMod_VERSION L"uMod V 1.0" +#define uMod_VERSION L"uMod V 2.0 alpha" #define PIPE_uMod2Game L"\\\\.\\pipe\\uMod2Game" #define PIPE_Game2uMod L"\\\\.\\pipe\\Game2uMod" @@ -57,7 +65,8 @@ typedef struct #define CONTROL_SAVE_ALL 10 #define CONTROL_SAVE_SINGLE 11 -#define CONTROL_SET_DIR 12 +#define CONTROL_SHOW_STRING 12 +#define CONTROL_SET_DIR 13 #define CONTROL_KEY_BACK 20 #define CONTROL_KEY_SAVE 21 @@ -66,16 +75,204 @@ typedef struct #define CONTROL_FONT_COLOUR 30 #define CONTROL_TEXTURE_COLOUR 31 +#define CONTROL_WIDTH_FILTER 40 +#define CONTROL_HEIGHT_FILTER 41 +#define CONTROL_DEPTH_FILTER 42 +#define CONTROL_FORMAT_FILTER 43 + +#define CONTROL_SAVE_FORMAT 50 + +#define CONTROL_SUPPORT_TPF 60 #define CONTROL_GAME_EXIT 100 #define CONTROL_ADD_CLIENT 101 #define CONTROL_REMOVE_CLIENT 102 +#define HOOK_INJECTION 1 +#define DIRECT_INJECTION 2 +#define NO_INJECTION 3 +#define INVALID_GAME_PAGE 4 + #define VERSION_DX9 90 #define VERSION_DX9EX 91 #define VERSION_DX10 100 -#define VERSION_DX10EX 101 -#define VERSION_DX11 110 -#define VERSION_DX11EX 111 +#define VERSION_DX101 101 + +#define uMod_D3DXIFF_BMP 1ull<<0 +#define uMod_D3DXIFF_JPG 1ull<<1 +#define uMod_D3DXIFF_TGA 1ull<<2 +#define uMod_D3DXIFF_PNG 1ull<<3 +#define uMod_D3DXIFF_DDS 1ull<<4 +#define uMod_D3DXIFF_PPM 1ull<<5 + + + + +#define uMod_D3DFMT_R8G8B8 1ull<<0 +#define uMod_D3DFMT_A8R8G8B8 1ull<<1 +#define uMod_D3DFMT_X8R8G8B8 1ull<<2 +#define uMod_D3DFMT_R5G6B5 1ull<<3 +#define uMod_D3DFMT_X1R5G5B5 1ull<<4 +#define uMod_D3DFMT_A1R5G5B5 1ull<<5 +#define uMod_D3DFMT_A4R4G4B4 1ull<<6 +#define uMod_D3DFMT_R3G3B2 1ull<<7 +#define uMod_D3DFMT_A8 1ull<<8 +#define uMod_D3DFMT_A8R3G3B2 1ull<<9 +#define uMod_D3DFMT_X4R4G4B4 1ull<<10 +#define uMod_D3DFMT_A2B10G10R10 1ull<<11 +#define uMod_D3DFMT_A8B8G8R8 1ull<<12 +#define uMod_D3DFMT_X8B8G8R8 1ull<<13 +#define uMod_D3DFMT_G16R16 1ull<<14 +#define uMod_D3DFMT_A2R10G10B10 1ull<<15 +#define uMod_D3DFMT_A16B16G16R16 1ull<<16 + +#define uMod_D3DFMT_A8P8 1ull<<17 +#define uMod_D3DFMT_P8 1ull<<18 + +#define uMod_D3DFMT_L8 1ull<<19 +#define uMod_D3DFMT_A8L8 1ull<<20 +#define uMod_D3DFMT_A4L4 1ull<<21 + +#define uMod_D3DFMT_V8U8 1ull<<22 +#define uMod_D3DFMT_L6V5U5 1ull<<23 +#define uMod_D3DFMT_X8L8V8U8 1ull<<24 +#define uMod_D3DFMT_Q8W8V8U8 1ull<<25 +#define uMod_D3DFMT_V16U16 1ull<<26 +#define uMod_D3DFMT_A2W10V10U10 1ull<<27 + + +#define uMod_D3DFMT_D16_LOCKABLE 1ull<<28 +#define uMod_D3DFMT_D32 1ull<<29 +#define uMod_D3DFMT_D15S1 1ull<<30 +#define uMod_D3DFMT_D24S8 1ull<<31 +#define uMod_D3DFMT_D24X8 1ull<<32 +#define uMod_D3DFMT_D24X4S4 1ull<<33 +#define uMod_D3DFMT_D16 1ull<<34 +#define uMod_D3DFMT_L16 1ull<<35 + +#define uMod_D3DFMT_D32F_LOCKABLE 1ull<<36 +#define uMod_D3DFMT_D24FS8 1ull<<37 + +#define uMod_D3DFMT_D32_LOCKABLE 1ull<<38 +#define uMod_D3DFMT_S8_LOCKABLE 1ull<<39 + + +#define uMod_D3DFMT_VERTEXDATA 1ull<<40 +#define uMod_D3DFMT_INDEX16 1ull<<41 +#define uMod_D3DFMT_INDEX32 1ull<<42 + +#define uMod_D3DFMT_Q16W16V16U16 1ull<<43 + + +#define uMod_D3DFMT_R16F 1ull<<44 +#define uMod_D3DFMT_G16R16F 1ull<<45 +#define uMod_D3DFMT_A16B16G16R16F 1ull<<46 + +#define uMod_D3DFMT_R32F 1ull<<47 +#define uMod_D3DFMT_G32R32F 1ull<<48 +#define uMod_D3DFMT_A32B32G32R32F 1ull<<49 + +#define uMod_D3DFMT_CxV8U8 1ull<<50 + +#define uMod_D3DFMT_A1 1ull<<51 +#define uMod_D3DFMT_A2B10G10R10_XR_BIAS 1ull<<52 +#define uMod_D3DFMT_BINARYBUFFER 1ull<<53 + + +#define uMod_D3DFMT_DXT1 1ull<<54 +#define uMod_D3DFMT_DXT2 1ull<<55 +#define uMod_D3DFMT_DXT3 1ull<<56 +#define uMod_D3DFMT_DXT4 1ull<<57 +#define uMod_D3DFMT_DXT5 1ull<<58 +#define uMod_D3DFMT_G8R8_G8B8 1ull<<59 +#define uMod_D3DFMT_R8G8_B8G8 1ull<<60 +#define uMod_D3DFMT_MULTI2_ARGB8 1ull<<61 +#define uMod_D3DFMT_UYVY 1ull<<62 +#define uMod_D3DFMT_YUY2 1ull<<63 + + /* + +#define uMod_D3DFMT_R8G8B8 1ull<<0 +#define uMod_D3DFMT_A8R8G8B8 1ull<<1 +#define uMod_D3DFMT_X8R8G8B8 1ull<<2 +#define uMod_D3DFMT_R5G6B5 1ull<<3 +#define uMod_D3DFMT_X1R5G5B5 1ull<<4 +#define uMod_D3DFMT_A1R5G5B5 1ull<<5 +#define uMod_D3DFMT_A4R4G4B4 1ull<<6 +#define uMod_D3DFMT_R3G3B2 1ull<<7 +#define uMod_D3DFMT_A8 1ull<<8 +#define uMod_D3DFMT_A8R3G3B2 1ull<<9 +#define uMod_D3DFMT_X4R4G4B4 1ull<<10 +#define uMod_D3DFMT_A2B10G10R10 1ull<<11 +#define uMod_D3DFMT_A8B8G8R8 1ull<<12 +#define uMod_D3DFMT_X8B8G8R8 1ull<<13 +#define uMod_D3DFMT_G16R16 1ull<<14 +#define uMod_D3DFMT_A2R10G10B10 1ull<<15 +#define uMod_D3DFMT_A16B16G16R16 1ull<<16 + +#define uMod_D3DFMT_A8P8 1ull<<17 +#define uMod_D3DFMT_P8 1ull<<18 + +#define uMod_D3DFMT_L8 1ull<<19 +#define uMod_D3DFMT_A8L8 1ull<<20 +#define uMod_D3DFMT_A4L4 1ull<<21 + +#define uMod_D3DFMT_V8U8 1ull<<22 +#define uMod_D3DFMT_L6V5U5 1ull<<23 +#define uMod_D3DFMT_X8L8V8U8 1ull<<24 +#define uMod_D3DFMT_Q8W8V8U8 1ull<<25 +#define uMod_D3DFMT_V16U16 1ull<<26 +#define uMod_D3DFMT_A2W10V10U10 1ull<<27 + +#define uMod_D3DFMT_UYVY 1ull<<28 +#define uMod_D3DFMT_R8G8_B8G8 1ull<<29 +#define uMod_D3DFMT_YUY2 1ull<<30 +#define uMod_D3DFMT_G8R8_G8B8 1ull<<31 +#define uMod_D3DFMT_DXT1 1ull<<32 +#define uMod_D3DFMT_DXT2 1ull<<33 +#define uMod_D3DFMT_DXT3 1ull<<34 +#define uMod_D3DFMT_DXT4 1ull<<35 +#define uMod_D3DFMT_DXT5 1ull<<36 + +#define uMod_D3DFMT_D16_LOCKABLE 1ull<<37 +#define uMod_D3DFMT_D32 1ull<<38 +#define uMod_D3DFMT_D15S1 1ull<<39 +#define uMod_D3DFMT_D24S8 1ull<<40 +#define uMod_D3DFMT_D24X8 1ull<<41 +#define uMod_D3DFMT_D24X4S4 1ull<<42 +#define uMod_D3DFMT_D16 1ull<<43 + +#define uMod_D3DFMT_D32F_LOCKABLE 1ull<<44 +#define uMod_D3DFMT_D24FS8 1ull<<45 + +#define uMod_D3DFMT_D32_LOCKABLE 1ull<<46 +#define uMod_D3DFMT_S8_LOCKABLE 1ull<<47 + +#define uMod_D3DFMT_L16 1ull<<48 + +#define uMod_D3DFMT_VERTEXDATA 1ull<<49 +#define uMod_D3DFMT_INDEX16 1ull<<50 +#define uMod_D3DFMT_INDEX32 1ull<<51 + +#define uMod_D3DFMT_Q16W16V16U16 1ull<<52 + +#define uMod_D3DFMT_MULTI2_ARGB8 1ull<<53 + +#define uMod_D3DFMT_R16F 1ull<<54 +#define uMod_D3DFMT_G16R16F 1ull<<55 +#define uMod_D3DFMT_A16B16G16R16F 1ull<<56 + +#define uMod_D3DFMT_R32F 1ull<<57 +#define uMod_D3DFMT_G32R32F 1ull<<58 +#define uMod_D3DFMT_A32B32G32R32F 1ull<<59 + +#define uMod_D3DFMT_CxV8U8 1ull<<60 + +#define uMod_D3DFMT_A1 1ull<<61 +#define uMod_D3DFMT_A2B10G10R10_XR_BIAS 1ull<<62 +#define uMod_D3DFMT_BINARYBUFFER 1ull<<63 + +//#define uMod_D3DFMT_FORCE_DWORD 1<<64 +*/ #endif diff --git a/uMod_Utils.h b/uMod_Utils.h new file mode 100644 index 0000000..af27c5d --- /dev/null +++ b/uMod_Utils.h @@ -0,0 +1,61 @@ +/* +This file is part of Universal Modding Engine. + + +Universal Modding Engine is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Universal Modding Engine is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Universal Modding Engine. If not, see . +*/ + +#ifndef UMOD_UTILS_H_ +#define UMOD_UTILS_H_ + + +template +int GetMemory(T* &array, int num) +{ + if (array!=(T*)0) delete [] array; + try {array = new T[num];} + catch (...) {array = (T*) 0; return -1;} + return 0; +} + +template +int GetMemory(T* &array, int num, T init) +{ + if (array!=(T*)0) delete [] array; + try {array = new T[num];} + catch (...) {array = (T*) 0; return -1;} + for (int i=0; i +int GetMoreMemory(T* &old_array, int old_num, int new_num) +{ + if (new_num<=old_num) return 0; + T* new_array; + try {new_array = new T[new_num];} + catch (...) {return -1;} + if (old_array!=(T*)0) + { + for (int i=0; i