Improvements:

- Added a new way of dll injection. The game is started through OTM, thus OTM inject the dll directly.
This commit is contained in:
code@koerner-de.net
2011-11-18 10:28:13 +00:00
parent fab93611c1
commit 199383dacb
38 changed files with 1851 additions and 225 deletions
+8 -1
View File
@@ -2,16 +2,21 @@
OTM_DX9/OTM_ArrayHandler.cpp -text
OTM_DX9/OTM_ArrayHandler.h -text
OTM_DX9/OTM_DX9_dll.cpp -text
OTM_DX9/OTM_DX9_dll.def -text
OTM_DX9/OTM_DX9_dll.h -text
OTM_DX9/OTM_DX9_dll_DIRECT_INJECTION.def -text
OTM_DX9/OTM_DX9_dll_HOOK_INJECTION.def -text
OTM_DX9/OTM_DX9_dll_NO_INJECTION.def -text
OTM_DX9/OTM_Defines.h -text
OTM_DX9/OTM_IDirect3D9.cpp -text
OTM_DX9/OTM_IDirect3D9.h -text
OTM_DX9/OTM_IDirect3D9Ex.cpp -text
OTM_DX9/OTM_IDirect3D9Ex.h -text
OTM_DX9/OTM_IDirect3DCubeTexture9.cpp -text
OTM_DX9/OTM_IDirect3DCubeTexture9.h -text
OTM_DX9/OTM_IDirect3DDevice9.cpp -text
OTM_DX9/OTM_IDirect3DDevice9.h -text
OTM_DX9/OTM_IDirect3DDevice9Ex.cpp -text
OTM_DX9/OTM_IDirect3DDevice9Ex.h -text
OTM_DX9/OTM_IDirect3DTexture9.cpp -text
OTM_DX9/OTM_IDirect3DTexture9.h -text
OTM_DX9/OTM_IDirect3DVolumeTexture9.cpp -text
@@ -32,6 +37,8 @@ OTM_GUI/OTM_AddTexture.cpp -text
OTM_GUI/OTM_AddTexture.h -text
OTM_GUI/OTM_Client.cpp -text
OTM_GUI/OTM_Client.h -text
OTM_GUI/OTM_DirectInjection.cpp -text
OTM_GUI/OTM_DirectInjection.h -text
OTM_GUI/OTM_Event.cpp -text
OTM_GUI/OTM_Event.h -text
OTM_GUI/OTM_File.cpp -text
+155 -43
View File
@@ -26,8 +26,13 @@ along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
#include "OTM_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
*/
@@ -36,9 +41,12 @@ HINSTANCE gl_hThisInstance = NULL;
OTM_TextureServer* gl_TextureServer = NULL;
HANDLE gl_ServerThread = NULL;
#ifndef NO_INJECTION
typedef IDirect3D9 *(APIENTRY *Direct3DCreate9_type)(UINT);
typedef HRESULT (APIENTRY *Direct3DCreate9Ex_type)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
#ifndef NO_INJECTION
Direct3DCreate9_type Direct3DCreate9_fn; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
Direct3DCreate9Ex_type Direct3DCreate9Ex_fn; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
HHOOK gl_hHook = NULL;
#endif
@@ -55,6 +63,9 @@ FILE* gl_File = NULL;
#endif
#ifdef DIRECT_INJECTION
void Nothing(void) {(void)NULL;}
#endif
/*
* dll entry routine, here we initialize or clean up
*/
@@ -90,6 +101,7 @@ DWORD WINAPI ServerThread( LPVOID lpParam )
void InitInstance(HINSTANCE hModule)
{
DisableThreadLibraryCalls( hModule ); //reduce overhead
gl_hThisInstance = (HINSTANCE) hModule;
@@ -101,43 +113,35 @@ void InitInstance(HINSTANCE hModule)
Message("InitInstance: %lu\n", hModule);
gl_TextureServer = new OTM_TextureServer(game); //create the server which listen on the pipe and prepare the update for the texture clients
if (gl_TextureServer!=NULL)
{
if (gl_TextureServer->OpenPipe(game)) //open the pipe and send the name+path of this executable
{
Message("InitInstance: Pipe not opened\n");
return;
}
gl_ServerThread = CreateThread( NULL, 0, ServerThread, NULL, 0, NULL); //creating a thread for the mainloop
if (gl_ServerThread==NULL) {Message("InitInstance: Serverthread not started\n");}
/*
//
//this is for testing purpose, these functions should be called from the server thread, provoked by the OTM_GUI
//
gl_TextureServer->SaveAllTextures(true);
gl_TextureServer->SetSaveDirectory("tex\\");
gl_TextureServer->AddFile("BF_0xbc2a9196.dds", 0xbc2a9196ul);
gl_TextureServer->AddFile("0X1FD33669.dds", 0X1FD33669ul);
gl_TextureServer->AddFile("0X26D19B9A.dds", 0X26D19B9Aul);
gl_TextureServer->AddFile("0X72E92068.dds", 0X72E92068ul);
gl_TextureServer->AddFile("0X714DFA26.dds", 0X714DFA26ul);
gl_TextureServer->AddFile("0X74499208.dds", 0X74499208ul);
gl_TextureServer->AddFile("0XA3BFD8EA.dds", 0XA3BFD8EAul);
*/
}
LoadOriginalDll();
#ifndef NO_INJECTION
// we detour the original Direct3DCreate9 to our MyDirect3DCreate9
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc(
(BYTE*)GetProcAddress(gl_hOriginalDll, "Direct3DCreate9"),
(BYTE*)MyDirect3DCreate9,
5);
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress(gl_hOriginalDll, "Direct3DCreate9");
if (Direct3DCreate9_fn!=NULL)
{
Message("Detour: Direct3DCreate9\n");
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*)Direct3DCreate9_fn, (BYTE*)OTM_Direct3DCreate9, 5);
}
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress(gl_hOriginalDll, "Direct3DCreate9Ex");
if (Direct3DCreate9Ex_fn!=NULL)
{
Message("Detour: Direct3DCreate9Ex\n");
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*)Direct3DCreate9Ex_fn, (BYTE*)OTM_Direct3DCreate9Ex, 7);
}
#endif
if (gl_TextureServer->OpenPipe(game)) //open the pipe and send the name+path of this executable
{
Message("InitInstance: Pipe not opened\n");
return;
}
gl_ServerThread = CreateThread( NULL, 0, ServerThread, NULL, 0, NULL); //creating a thread for the mainloop
if (gl_ServerThread==NULL) {Message("InitInstance: Serverthread not started\n");}
}
}
@@ -197,14 +201,13 @@ IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
if (!gl_hOriginalDll) LoadOriginalDll(); // looking for the "right d3d9.dll"
// find original function in original d3d9.dll
typedef IDirect3D9 *(WINAPI* D3D9_Type)(UINT SDKVersion);
D3D9_Type D3DCreate9_fn = (D3D9_Type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
Direct3DCreate9_type D3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
if (!D3DCreate9_fn)
{
Message("Direct3DCreate9: original function not found in dll\n");
ExitProcess(0); // exit the hard way
return (NULL);
}
@@ -218,6 +221,35 @@ IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
return (pIDirect3D9);
}
HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **ppD3D)
{
Message("WINAPI Direct3DCreate9Ex\n");
if (!gl_hOriginalDll) LoadOriginalDll(); // looking for the "right d3d9.dll"
// find original function in original d3d9.dll
Direct3DCreate9Ex_type D3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex");
if (!D3DCreate9Ex_fn)
{
Message("Direct3DCreate9Ex: original function not found in dll\n");
return (D3DERR_NOTAVAILABLE);
}
//Create originale IDirect3D9 object
IDirect3D9Ex *pIDirect3D9Ex_orig;
HRESULT ret = D3DCreate9Ex_fn( SDKVersion, &pIDirect3D9Ex_orig);
if (ret!=S_OK) return (ret);
//create our OTM_IDirect3D9 object
OTM_IDirect3D9Ex *pIDirect3D9Ex = new OTM_IDirect3D9Ex( pIDirect3D9Ex_orig, gl_TextureServer);
ppD3D = &pIDirect3D9Ex_orig; // Return pointer to our object instead of "real one"
return (ret);
}
bool HookThisProgram( wchar_t *ret) //this function always return true, it is needed for the name and path of the executable
{
wchar_t Executable[MAX_PATH];
@@ -237,19 +269,27 @@ bool HookThisProgram( wchar_t *ret) //this function always return true, it is ne
* We inject the dll into the game, thus we retour the original Direct3DCreate9 function to our MyDirect3DCreate9 function
*/
IDirect3D9 *APIENTRY MyDirect3DCreate9(UINT SDKVersion)
IDirect3D9 *APIENTRY OTM_Direct3DCreate9(UINT SDKVersion)
{
Message("Direct3DCreate9_fn %lu, my %lu\n", Direct3DCreate9_fn ,MyDirect3DCreate9);
Message("OTM_Direct3DCreate9: original %lu, OTM %lu\n", Direct3DCreate9_fn, OTM_Direct3DCreate9);
// in the Internet are many tutorials for detouring functions and all of them will work without the following 3 marked lines
// in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines
// but somehow, for me it only works, if I retour the function and calling afterward the original function
// BEGIN
LoadOriginalDll();
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9"), (BYTE*)Direct3DCreate9_fn, 5);
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
/*
if (Direct3DCreate9Ex_fn!=NULL)
{
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex"), (BYTE*)Direct3DCreate9Ex_fn, 7);
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex");
}
*/
// END
IDirect3D9 *pIDirect3D9_orig = NULL;
@@ -263,20 +303,82 @@ IDirect3D9 *APIENTRY MyDirect3DCreate9(UINT SDKVersion)
{
pIDirect3D9 = new OTM_IDirect3D9( pIDirect3D9_orig, gl_TextureServer); //creating our OTM_IDirect3D9 object
}
// we detour again
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*) Direct3DCreate9_fn, (BYTE*)OTM_Direct3DCreate9,5);
/*
if (Direct3DCreate9Ex_fn!=NULL)
{
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*) Direct3DCreate9Ex_fn, (BYTE*)OTM_Direct3DCreate9Ex,7);
}
*/
return (pIDirect3D9); //return our object instead of the "real one"
}
HRESULT APIENTRY OTM_Direct3DCreate9Ex( UINT SDKVersion, IDirect3D9Ex **ppD3D)
{
Message( "OTM_Direct3DCreate9Ex: original %lu, OTM %lu\n", Direct3DCreate9Ex_fn, OTM_Direct3DCreate9Ex);
// in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines
// but somehow, for me it only works, if I retour the function and calling afterward the original function
// BEGIN
LoadOriginalDll();
/*
if (Direct3DCreate9_fn!=NULL)
{
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9"), (BYTE*)Direct3DCreate9_fn, 5);
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9");
}
*/
RetourFunc((BYTE*) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex"), (BYTE*)Direct3DCreate9Ex_fn, 7);
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginalDll, "Direct3DCreate9Ex");
// END
IDirect3D9Ex *pIDirect3D9Ex_orig = NULL;
HRESULT ret;
if (Direct3DCreate9Ex_fn)
{
ret = Direct3DCreate9Ex_fn(SDKVersion, &pIDirect3D9Ex_orig); //creating the original IDirect3D9 object
}
else return (D3DERR_NOTAVAILABLE);
if (ret!=S_OK) return (ret);
OTM_IDirect3D9Ex *pIDirect3D9Ex;
if (pIDirect3D9Ex_orig)
{
pIDirect3D9Ex = new OTM_IDirect3D9Ex( pIDirect3D9Ex_orig, gl_TextureServer); //creating our OTM_IDirect3D9 object
}
// we detour again
/*
if (Direct3DCreate9_fn!=NULL)
{
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*) Direct3DCreate9_fn, (BYTE*)OTM_Direct3DCreate9,5);
}
*/
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*) Direct3DCreate9Ex_fn, (BYTE*)OTM_Direct3DCreate9Ex,7);
ppD3D = (IDirect3D9Ex**) &pIDirect3D9Ex; //return our object instead of the "real one"
return (ret);
}
bool HookThisProgram( wchar_t *ret)
{
wchar_t Executable[MAX_PATH];
wchar_t Game[MAX_PATH];
GetModuleFileNameW( GetModuleHandle( NULL ), Executable, MAX_PATH ); //ask for name and path of this executable
#ifdef HOOK_INJECTION
//we use the gloabal hook
FILE* file;
wchar_t *app_path = _wgetenv( L"APPDATA"); //asc for the user application directory
wchar_t file_name[MAX_PATH];
swprintf_s( file_name, MAX_PATH, L"%ls\\%ls\\%ls", app_path, OTM_APP_DIR, OTM_APP_DX9);
if (_wfopen_s( &file, file_name, L"rt,ccs=UTF-16LE")) return (false); // open the file in utf-16 LE mode
wchar_t Executable[MAX_PATH];
wchar_t Game[MAX_PATH];
GetModuleFileNameW( GetModuleHandle( NULL ), Executable, MAX_PATH ); //ask for name and path of this executable
//MessageBoxW( NULL, Executable, L"test", 0);
while (!feof(file))
@@ -301,6 +403,14 @@ bool HookThisProgram( wchar_t *ret)
}
fclose(file);
return (false);
#endif
#ifdef DIRECT_INJECTION
// we inject directly
int i=0;
while ( Game[i]) {ret[i]=Game[i]; i++;}
ret[i]=0;
return true;
#endif
}
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
@@ -330,6 +440,7 @@ bool RetourFunc(BYTE *src, BYTE *restore, const int len)
return (true);
}
#ifdef HOOK_INJECTION
/*
* We do not change something, if our hook function is called.
* We need this hook only to get our dll loaded into a starting program.
@@ -349,3 +460,4 @@ void RemoveHook(void)
UnhookWindowsHookEx( gl_hHook );
}
#endif
#endif
-5
View File
@@ -1,5 +0,0 @@
LIBRARY "OTM_d3d9"
EXPORTS
MyDirect3DCreate9 @1
InstallHook @2
RemoveHook @3
+9 -1
View File
@@ -33,11 +33,19 @@ DWORD WINAPI ServerThread( LPVOID lpParam);
void *DetourFunc(BYTE *src, const BYTE *dst, const int len);
bool RetourFunc(BYTE *src, BYTE *restore, const int len);
IDirect3D9 *APIENTRY MyDirect3DCreate9(UINT SDKVersion);
IDirect3D9 *APIENTRY OTM_Direct3DCreate9(UINT SDKVersion);
HRESULT APIENTRY OTM_Direct3DCreate9Ex( UINT SDKVersion, IDirect3D9Ex **ppD3D);
#ifdef HOOK_INJECTION
LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam);
void InstallHook(void);
void RemoveHook(void);
#endif
#ifdef DIRECT_INJECTION
void Nothing(void);
#endif
#endif
+5
View File
@@ -0,0 +1,5 @@
LIBRARY "OTM_d3d9_DI"
EXPORTS
OTM_Direct3DCreate9 @1
OTM_Direct3DCreate9Ex @2
Nothing @3
+6
View File
@@ -0,0 +1,6 @@
LIBRARY "OTM_d3d9_Hook"
EXPORTS
OTM_Direct3DCreate9 @1
OTM_Direct3DCreate9Ex @2
InstallHook @3
RemoveHook @4
+2 -1
View File
@@ -1,3 +1,4 @@
LIBRARY "d3d9"
EXPORTS
Direct3DCreate9 @1
Direct3DCreate9 @1
Direct3DCreate9Ex @2
+1 -1
View File
@@ -28,7 +28,7 @@ along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
extern FILE *gl_File;
#define Message(...) {if (gl_File!=NULL) {fprintf( gl_File, __VA_ARGS__); fflush(gl_File);}}
#define OpenMessage(...) {if (fopen_s( &gl_File, "OTM_log.txt", "wt")) gl_File=NULL;}
#define OpenMessage(...) {if (fopen_s( &gl_File, "OTM_log.txt", "wt")) gl_File=NULL; else fprintf( gl_File, "R21: 0000000\n");}
#define CloseMessage(...) {if (gl_File!=NULL) fclose(gl_File);}
+8 -3
View File
@@ -22,16 +22,20 @@ along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
#include "OTM_Main.h"
OTM_IDirect3D9::OTM_IDirect3D9(IDirect3D9 *pOriginal, OTM_TextureServer* server)
#ifndef PRE_MESSAGE
#define PRE_MESSAGE "OTM_IDirect3D9"
#endif
OTM_IDirect3D9::OTM_IDirect3D9( IDirect3D9 *pOriginal, OTM_TextureServer* server)
{
Message("OTM_IDirect3D9::OTM_IDirect3D9( %lu, %lu): %lu\n", pOriginal, server, this);
Message( PRE_MESSAGE "::" PRE_MESSAGE "( %lu, %lu): %lu\n", pOriginal, server, this);
m_pIDirect3D9 = pOriginal;
OTM_Server = server;
}
OTM_IDirect3D9::~OTM_IDirect3D9(void)
{
Message("OTM_IDirect3D9::~OTM_IDirect3D9(): %lu\n", this);
Message( PRE_MESSAGE "::~" PRE_MESSAGE "(): %lu\n", this);
}
HRESULT __stdcall OTM_IDirect3D9::QueryInterface(REFIID riid, void** ppvObj)
@@ -137,6 +141,7 @@ HMONITOR __stdcall OTM_IDirect3D9::GetAdapterMonitor(UINT Adapter)
HRESULT __stdcall OTM_IDirect3D9::CreateDevice(UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface)
{
Message( PRE_MESSAGE "::CreateDevice(): %lu\n", this);
// we intercept this call and provide our own "fake" Device Object
HRESULT hres = m_pIDirect3D9->CreateDevice( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
+69
View File
@@ -0,0 +1,69 @@
/*
This file is part of OpenTexMod.
OpenTexMod is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenTexMod is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
*/
#include "OTM_Main.h"
#define IDirect3D9 IDirect3D9Ex
#define OTM_IDirect3D9 OTM_IDirect3D9Ex
#define m_pIDirect3D9 m_pIDirect3D9Ex
#define PRE_MESSAGE "OTM_IDirect3D9Ex"
#include "OTM_IDirect3D9.cpp"
HRESULT __stdcall OTM_IDirect3D9Ex::CreateDeviceEx( UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode, IDirect3DDevice9Ex **ppReturnedDeviceInterface)
{
Message( "OTM_IDirect3D9Ex::CreateDeviceEx: %lu\n", this);
// we intercept this call and provide our own "fake" Device Object
HRESULT hres = m_pIDirect3D9Ex->CreateDeviceEx( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface);
OTM_IDirect3DDevice9Ex *pIDirect3DDevice9Ex = new OTM_IDirect3DDevice9Ex(*ppReturnedDeviceInterface, OTM_Server);
// store our pointer (the fake one) for returning it to the calling program
*ppReturnedDeviceInterface = pIDirect3DDevice9Ex;
return(hres);
return (m_pIDirect3D9Ex->CreateDeviceEx( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface));
}
HRESULT __stdcall OTM_IDirect3D9Ex::EnumAdapterModesEx( UINT Adapter, const D3DDISPLAYMODEFILTER *pFilter, UINT Mode, D3DDISPLAYMODEEX *pMode)
{
return (m_pIDirect3D9Ex->EnumAdapterModesEx( Adapter, pFilter, Mode, pMode));
}
HRESULT __stdcall OTM_IDirect3D9Ex::GetAdapterDisplayModeEx( UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation)
{
return (m_pIDirect3D9Ex->GetAdapterDisplayModeEx( Adapter, pMode, pRotation));
}
HRESULT __stdcall OTM_IDirect3D9Ex::GetAdapterLUID( UINT Adapter, LUID *pLUID)
{
return (m_pIDirect3D9Ex->GetAdapterLUID( Adapter, pLUID));
}
UINT __stdcall OTM_IDirect3D9Ex::GetAdapterModeCountEx( UINT Adapter, const D3DDISPLAYMODEFILTER *pFilter)
{
return (m_pIDirect3D9Ex->GetAdapterModeCountEx( Adapter, pFilter));
}
+73
View File
@@ -0,0 +1,73 @@
/*
This file is part of OpenTexMod.
OpenTexMod is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenTexMod is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* BIG THANKS TO Michael Koch
* (proxydll_9.zip)
*
*/
#ifndef OTM_IDirect3D9Ex_H_
#define OTM_IDirect3D9Ex_H_
#include <d3d9.h>
#include <d3dx9.h>
#include "OTM_TextureServer.h"
#include "OTM_TextureClient.h"
class OTM_IDirect3D9Ex : public IDirect3D9Ex
{
public:
OTM_IDirect3D9Ex( IDirect3D9Ex *pOriginal, OTM_TextureServer *server);
virtual ~OTM_IDirect3D9Ex(void);
// The original DX9 function definitions
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj);
ULONG __stdcall AddRef(void);
ULONG __stdcall Release(void);
HRESULT __stdcall RegisterSoftwareDevice(void* pInitializeFunction);
UINT __stdcall GetAdapterCount(void);
HRESULT __stdcall GetAdapterIdentifier(UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier) ;
UINT __stdcall GetAdapterModeCount(UINT Adapter, D3DFORMAT Format);
HRESULT __stdcall EnumAdapterModes(UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode) ;
HRESULT __stdcall GetAdapterDisplayMode( UINT Adapter,D3DDISPLAYMODE* pMode) ;
HRESULT __stdcall CheckDeviceType(UINT iAdapter,D3DDEVTYPE DevType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed) ;
HRESULT __stdcall CheckDeviceFormat(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat) ;
HRESULT __stdcall CheckDeviceMultiSampleType(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels) ;
HRESULT __stdcall CheckDepthStencilMatch(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) ;
HRESULT __stdcall CheckDeviceFormatConversion(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat);
HRESULT __stdcall GetDeviceCaps(UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps) ;
HMONITOR __stdcall GetAdapterMonitor(UINT Adapter) ;
HRESULT __stdcall CreateDevice(UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface) ;
HRESULT __stdcall CreateDeviceEx( UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode, IDirect3DDevice9Ex **ppReturnedDeviceInterface);
HRESULT __stdcall EnumAdapterModesEx( UINT Adapter, const D3DDISPLAYMODEFILTER *pFilter, UINT Mode, D3DDISPLAYMODEEX *pMode);
HRESULT __stdcall GetAdapterDisplayModeEx( UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation);
HRESULT __stdcall GetAdapterLUID( UINT Adapter, LUID *pLUID);
UINT __stdcall GetAdapterModeCountEx( UINT Adapter, const D3DDISPLAYMODEFILTER *pFilter);
private:
IDirect3D9Ex *m_pIDirect3D9Ex;
OTM_TextureServer* OTM_Server;
};
#endif
+23 -3
View File
@@ -66,6 +66,11 @@ ULONG APIENTRY OTM_IDirect3DCubeTexture9::AddRef()
//this function yields for the non switched texture object
ULONG APIENTRY OTM_IDirect3DCubeTexture9::Release()
{
Message("OTM_IDirect3DCubeTexture9::Release(): %lu\n", this);
void *cpy;
long ret = m_D3Ddev->QueryInterface( IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE)
{
@@ -81,7 +86,14 @@ ULONG APIENTRY OTM_IDirect3DCubeTexture9::Release()
if (count==0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (((OTM_IDirect3DDevice9*)m_D3Ddev)->GetSingleCubeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
if (ret == 0x01000000L)
{
if (((OTM_IDirect3DDevice9*) m_D3Ddev)->GetSingleCubeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
else
{
if (((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetSingleCubeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
}
}
else
@@ -94,8 +106,16 @@ ULONG APIENTRY OTM_IDirect3DCubeTexture9::Release()
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (((OTM_IDirect3DDevice9*)m_D3Ddev)->GetLastCreatedCubeTexture()==this) ((OTM_IDirect3DDevice9*)m_D3Ddev)->SetLastCreatedCubeTexture( NULL);
else ((OTM_IDirect3DDevice9*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
if (ret == 0x01000000L)
{
if (((OTM_IDirect3DDevice9*) m_D3Ddev)->GetLastCreatedCubeTexture()==this) ((OTM_IDirect3DDevice9*) m_D3Ddev)->SetLastCreatedCubeTexture( NULL);
else ((OTM_IDirect3DDevice9*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
}
else
{
if (((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetLastCreatedCubeTexture()==this) ((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->SetLastCreatedCubeTexture( NULL);
else ((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
}
delete(this);
}
+31 -17
View File
@@ -20,6 +20,13 @@ along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
#include "OTM_Main.h"
#ifndef RETURN_QueryInterface
#define RETURN_QueryInterface 0x01000000L
#endif
#ifndef PRE_MESSAGE
#define PRE_MESSAGE "OTM_IDirect3DDevice9"
#endif
int OTM_IDirect3DDevice9::CreateSingleTexture(void)
@@ -30,7 +37,7 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
{
if( D3D_OK != CreateTexture(8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DTexture9**) &SingleTexture, NULL))
{
Message("OTM_IDirect3DDevice9::CreateSingleTexture(): CreateTexture Failed\n");
Message( PRE_MESSAGE "::CreateSingleTexture(): CreateTexture Failed\n");
SingleTexture = NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
@@ -45,7 +52,7 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
if (D3D_OK!=pD3Dtex->LockRect(0, &d3dlr, 0, 0))
{
Message("OTM_IDirect3DDevice9::CreateSingleTexture(): LockRect Failed\n");
Message( PRE_MESSAGE "::CreateSingleTexture(): LockRect Failed\n");
SingleTexture->Release();
SingleTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
@@ -60,7 +67,7 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
{
if( D3D_OK != CreateVolumeTexture(8, 8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DVolumeTexture9**) &SingleVolumeTexture, NULL))
{
Message("OTM_IDirect3DDevice9::CreateSingleTexture(): CreateVolumeTexture Failed\n");
Message( PRE_MESSAGE "::CreateSingleTexture(): CreateVolumeTexture Failed\n");
SingleVolumeTexture = NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
@@ -75,7 +82,7 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
//LockBox)(UINT Level, D3DLOCKED_BOX *pLockedVolume, CONST D3DBOX *pBox,
if (D3D_OK!=pD3Dtex->LockBox(0, &d3dlr, 0, 0))
{
Message("OTM_IDirect3DDevice9::CreateSingleTexture(): LockBox Failed\n");
Message( PRE_MESSAGE "::CreateSingleTexture(): LockBox Failed\n");
SingleVolumeTexture->Release();
SingleVolumeTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
@@ -89,7 +96,7 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
{
if( D3D_OK != CreateCubeTexture(8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DCubeTexture9**) &SingleCubeTexture, NULL))
{
Message("OTM_IDirect3DDevice9::CreateSingleTexture(): CreateCubeTexture Failed\n");
Message( PRE_MESSAGE "::CreateSingleTexture(): CreateCubeTexture Failed\n");
SingleCubeTexture = NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
@@ -106,7 +113,7 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
{
if (D3D_OK!=pD3Dtex->LockRect( (D3DCUBEMAP_FACES) c, 0, &d3dlr, 0, 0))
{
Message("OTM_IDirect3DDevice9::CreateSingleTexture(): LockRect (Cube) Failed\n");
Message( PRE_MESSAGE "::CreateSingleTexture(): LockRect (Cube) Failed\n");
SingleCubeTexture->Release();
SingleCubeTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
@@ -121,9 +128,9 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
return (RETURN_OK);
}
OTM_IDirect3DDevice9::OTM_IDirect3DDevice9(IDirect3DDevice9* pOriginal, OTM_TextureServer* server)
OTM_IDirect3DDevice9::OTM_IDirect3DDevice9( IDirect3DDevice9* pOriginal, OTM_TextureServer* server)
{
Message("OTM_IDirect3DDevice9( %lu, %lu): %lu\n", pOriginal, server, this);
Message( PRE_MESSAGE "::" PRE_MESSAGE "( %lu, %lu): %lu\n", pOriginal, server, this);
OTM_Server = server;
OTM_Client = new OTM_TextureClient( OTM_Server, this); //get a new texture client for this device
@@ -146,14 +153,21 @@ OTM_IDirect3DDevice9::OTM_IDirect3DDevice9(IDirect3DDevice9* pOriginal, OTM_Text
OTM_IDirect3DDevice9::~OTM_IDirect3DDevice9(void)
{
Message( PRE_MESSAGE "::~" PRE_MESSAGE "(): %lu\n", this);
}
HRESULT OTM_IDirect3DDevice9::QueryInterface(REFIID riid, void** ppvObj)
{
// check if original dll can provide interface. then send *our* address
*ppvObj = NULL;
// check if original dll can provide interface. then send *our* address
if (riid==IID_IDirect3DTexture9)
{
// This function should never be called with IDirect3DTexture9 by the game
*ppvObj = this;
return (RETURN_QueryInterface);
}
Message("IDirect3DDevice9::QueryInterface(): %lu\n", this);
*ppvObj = NULL;
Message( PRE_MESSAGE "::QueryInterface(): %lu\n", this);
HRESULT hRes = m_pIDirect3DDevice9->QueryInterface(riid, ppvObj);
if (*ppvObj == m_pIDirect3DDevice9)
@@ -168,7 +182,7 @@ HRESULT OTM_IDirect3DDevice9::QueryInterface(REFIID riid, void** ppvObj)
ULONG OTM_IDirect3DDevice9::AddRef(void)
{
OTM_Reference++; //increasing our counter
Message("%lu = IDirect3DDevice9::AddRef(): %lu\n", OTM_Reference, this);
Message("%lu = " PRE_MESSAGE "::AddRef(): %lu\n", OTM_Reference, this);
return (m_pIDirect3DDevice9->AddRef());
}
@@ -192,10 +206,10 @@ ULONG OTM_IDirect3DDevice9::Release(void)
}
ULONG count = m_pIDirect3DDevice9->Release();
Message("%lu = IDirect3DDevice9::Release(): %lu\n", count, this);
Message("%lu = " PRE_MESSAGE "::Release(): %lu\n", count, this);
if (OTM_Reference!=count) //bug
{
Message("Error in IDirect3DDevice9::Release(): %lu!=%lu\n", OTM_Reference, count);
Message("Error in " PRE_MESSAGE "::Release(): %lu!=%lu\n", OTM_Reference, count);
}
if (count==0u) delete(this);
@@ -311,7 +325,7 @@ HRESULT OTM_IDirect3DDevice9::CreateTexture(UINT Width,UINT Height,UINT Levels,D
if(ret != D3D_OK) return (ret);
//create fake texture
OTM_IDirect3DTexture9 *texture = new OTM_IDirect3DTexture9(ppTexture, this);
OTM_IDirect3DTexture9 *texture = new OTM_IDirect3DTexture9( ppTexture, this);
if (texture) *ppTexture = texture;
if (LastCreatedTexture!=NULL) //if a texture was loaded before, hopefully this texture contains now the data, so we can add it
@@ -330,7 +344,7 @@ HRESULT OTM_IDirect3DDevice9::CreateVolumeTexture(UINT Width,UINT Height,UINT De
if(ret != D3D_OK) return (ret);
//create fake texture
OTM_IDirect3DVolumeTexture9 *texture = new OTM_IDirect3DVolumeTexture9(ppVolumeTexture, this);
OTM_IDirect3DVolumeTexture9 *texture = new OTM_IDirect3DVolumeTexture9( ppVolumeTexture, this);
if (texture) *ppVolumeTexture = texture;
if (LastCreatedVolumeTexture!=NULL) //if a texture was loaded before, hopefully this texture contains now the data, so we can add it
@@ -387,7 +401,7 @@ HRESULT OTM_IDirect3DDevice9::UpdateSurface(IDirect3DSurface9* pSourceSurface,CO
HRESULT OTM_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTexture,IDirect3DBaseTexture9* pDestinationTexture)
{
Message("OTM_IDirect3DDevice9::UpdateTexture( %lu, %lu): %lu\n", pSourceTexture, pDestinationTexture, this);
Message( PRE_MESSAGE "::UpdateTexture( %lu, %lu): %lu\n", pSourceTexture, pDestinationTexture, this);
// we must pass the real texture objects
+10 -7
View File
@@ -34,6 +34,7 @@ along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
#include "OTM_IDirect3DVolumeTexture9.h"
#include "OTM_IDirect3DCubeTexture9.h"
class OTM_IDirect3DDevice9 : public IDirect3DDevice9
{
public:
@@ -164,9 +165,9 @@ public:
OTM_TextureClient* GetOTM_Client(void) {return (OTM_Client);}
OTM_TextureClient* GetOTM_Client(void) {return (OTM_Client);}
OTM_IDirect3DTexture9* GetLastCreatedTexture(void) {return (LastCreatedTexture);}
OTM_IDirect3DTexture9* GetLastCreatedTexture(void) {return (LastCreatedTexture);}
int SetLastCreatedTexture(OTM_IDirect3DTexture9* pTexture) {LastCreatedTexture=pTexture; return (RETURN_OK);}
OTM_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture(void) {return (LastCreatedVolumeTexture);}
@@ -180,8 +181,11 @@ public:
OTM_IDirect3DVolumeTexture9* GetSingleVolumeTexture(void) {return (SingleVolumeTexture);}
OTM_IDirect3DCubeTexture9* GetSingleCubeTexture(void) {return (SingleCubeTexture);}
private:
int CreateSingleTexture(void);
int CreateSingleTexture(void);
IDirect3DDevice9* m_pIDirect3DDevice9;
int CounterSaveSingleTexture;
OTM_IDirect3DTexture9* SingleTexture;
OTM_IDirect3DVolumeTexture9* SingleVolumeTexture;
@@ -193,14 +197,13 @@ public:
//D3DCOLOR FontColour;
int OTM_Reference;
IDirect3DDevice9* m_pIDirect3DDevice9;
OTM_IDirect3DTexture9* LastCreatedTexture;
OTM_IDirect3DTexture9* LastCreatedTexture;
OTM_IDirect3DVolumeTexture9* LastCreatedVolumeTexture;
OTM_IDirect3DCubeTexture9* LastCreatedCubeTexture;
OTM_TextureServer* OTM_Server;
OTM_TextureClient* OTM_Client;
OTM_TextureServer* OTM_Server;
OTM_TextureClient* OTM_Client;
};
#endif
+116
View File
@@ -0,0 +1,116 @@
/*
This file is part of OpenTexMod.
OpenTexMod is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenTexMod is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
*/
#include "OTM_Main.h"
#define OTM_IDirect3DDevice9 OTM_IDirect3DDevice9Ex
#define IDirect3DDevice9 IDirect3DDevice9Ex
#define m_pIDirect3DDevice9 m_pIDirect3DDevice9Ex
#define RETURN_QueryInterface 0x01000001L
#define PRE_MESSAGE "OTM_IDirect3DDevice9Ex"
#include "OTM_IDirect3DDevice9.cpp"
HRESULT __stdcall OTM_IDirect3DDevice9Ex::CheckDeviceState( HWND hWindow)
{
return(m_pIDirect3DDevice9Ex->CheckDeviceState( hWindow));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::CheckResourceResidency( IDirect3DResource9 **ppResourceArray, UINT32 NumResources)
{
return(m_pIDirect3DDevice9Ex->CheckResourceResidency( ppResourceArray, NumResources));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::ComposeRects( IDirect3DSurface9 *pSource, IDirect3DSurface9 *pDestination, IDirect3DVertexBuffer9 *pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescriptors, D3DCOMPOSERECTSOP Operation, INT XOffset, INT YOffset)
{
return(m_pIDirect3DDevice9Ex->ComposeRects( pSource, pDestination, pSrcRectDescriptors, NumRects, pDstRectDescriptors, Operation, XOffset, YOffset));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::CreateDepthStencilSurfaceEx( UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage)
{
return(m_pIDirect3DDevice9Ex->CreateDepthStencilSurfaceEx( Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle, Usage));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::CreateOffscreenPlainSurfaceEx( UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage)
{
return(m_pIDirect3DDevice9Ex->CreateOffscreenPlainSurfaceEx( Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::CreateRenderTargetEx( UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage)
{
return(m_pIDirect3DDevice9Ex->CreateRenderTargetEx( Width, Height, Format, MultiSample, MultisampleQuality, Lockable, ppSurface, pSharedHandle, Usage));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::GetDisplayModeEx( UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation)
{
return(m_pIDirect3DDevice9Ex->GetDisplayModeEx( iSwapChain, pMode, pRotation));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::GetGPUThreadPriority( INT *pPriority)
{
return(m_pIDirect3DDevice9Ex->GetGPUThreadPriority( pPriority));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::GetMaximumFrameLatency( UINT *pMaxLatency)
{
return(m_pIDirect3DDevice9Ex->GetMaximumFrameLatency( pMaxLatency));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::PresentEx( const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion, DWORD dwFlags)
{
return(m_pIDirect3DDevice9Ex->PresentEx( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::ResetEx( D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode)
{
return(m_pIDirect3DDevice9Ex->ResetEx( pPresentationParameters, pFullscreenDisplayMode));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::SetConvolutionMonoKernel( UINT Width, UINT Height, float *RowWeights, float *ColumnWeights)
{
return(m_pIDirect3DDevice9Ex->SetConvolutionMonoKernel( Width, Height, RowWeights, ColumnWeights));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::SetGPUThreadPriority( INT pPriority)
{
return(m_pIDirect3DDevice9Ex->SetGPUThreadPriority( pPriority));
}
HRESULT __stdcall OTM_IDirect3DDevice9Ex::SetMaximumFrameLatency( UINT pMaxLatency)
{
return(m_pIDirect3DDevice9Ex->SetMaximumFrameLatency( pMaxLatency));
}
/*
HRESULT __stdcall OTM_IDirect3DDevice9Ex::TestCooperativeLevel()
{
return(m_pIDirect3DDevice9Ex->TestCooperativeLevel());
}
*/
HRESULT __stdcall OTM_IDirect3DDevice9Ex::WaitForVBlank( UINT SwapChainIndex)
{
return(m_pIDirect3DDevice9Ex->WaitForVBlank( SwapChainIndex));
}
+223
View File
@@ -0,0 +1,223 @@
/*
This file is part of OpenTexMod.
OpenTexMod is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenTexMod is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OTM_IDirect3DDevice9Ex_H_
#define OTM_IDirect3DDevice9Ex_H_
#include <d3d9.h>
#include <d3dx9.h>
#include "OTM_IDirect3DTexture9.h"
#include "OTM_IDirect3DVolumeTexture9.h"
#include "OTM_IDirect3DCubeTexture9.h"
class OTM_IDirect3DDevice9Ex : public IDirect3DDevice9Ex
{
public:
OTM_IDirect3DDevice9Ex( IDirect3DDevice9Ex* pOriginal, OTM_TextureServer* server);
virtual ~OTM_IDirect3DDevice9Ex(void);
// START: The original DX9 function definitions
HRESULT __stdcall QueryInterface (REFIID riid, void** ppvObj);
ULONG __stdcall AddRef(void);
ULONG __stdcall Release(void);
HRESULT __stdcall TestCooperativeLevel(void);
UINT __stdcall GetAvailableTextureMem(void);
HRESULT __stdcall EvictManagedResources(void);
HRESULT __stdcall GetDirect3D(IDirect3D9** ppD3D9);
HRESULT __stdcall GetDeviceCaps(D3DCAPS9* pCaps);
HRESULT __stdcall GetDisplayMode(UINT iSwapChain,D3DDISPLAYMODE* pMode);
HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters);
HRESULT __stdcall SetCursorProperties(UINT XHotSpot,UINT YHotSpot,IDirect3DSurface9* pCursorBitmap);
void __stdcall SetCursorPosition(int X,int Y,DWORD Flags);
BOOL __stdcall ShowCursor(BOOL bShow);
HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain9** pSwapChain) ;
HRESULT __stdcall GetSwapChain(UINT iSwapChain,IDirect3DSwapChain9** pSwapChain);
UINT __stdcall GetNumberOfSwapChains(void);
HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters);
HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
HRESULT __stdcall GetBackBuffer(UINT iSwapChain,UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer);
HRESULT __stdcall GetRasterStatus(UINT iSwapChain,D3DRASTER_STATUS* pRasterStatus);
HRESULT __stdcall SetDialogBoxMode(BOOL bEnableDialogs);
void __stdcall SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp);
void __stdcall GetGammaRamp(UINT iSwapChain,D3DGAMMARAMP* pRamp);
HRESULT __stdcall CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle);
HRESULT __stdcall CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,HANDLE* pSharedHandle);
HRESULT __stdcall CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,HANDLE* pSharedHandle);
HRESULT __stdcall CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall UpdateSurface(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint);
HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture9* pSourceTexture,IDirect3DBaseTexture9* pDestinationTexture);
HRESULT __stdcall GetRenderTargetData(IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface);
HRESULT __stdcall GetFrontBufferData(UINT iSwapChain,IDirect3DSurface9* pDestSurface);
HRESULT __stdcall StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter);
HRESULT __stdcall ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect,D3DCOLOR color);
HRESULT __stdcall CreateOffscreenPlainSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle);
HRESULT __stdcall SetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget);
HRESULT __stdcall GetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget);
HRESULT __stdcall SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil);
HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface);
HRESULT __stdcall BeginScene(void);
HRESULT __stdcall EndScene(void);
HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix);
HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
HRESULT __stdcall SetViewport(CONST D3DVIEWPORT9* pViewport);
HRESULT __stdcall GetViewport(D3DVIEWPORT9* pViewport);
HRESULT __stdcall SetMaterial(CONST D3DMATERIAL9* pMaterial);
HRESULT __stdcall GetMaterial(D3DMATERIAL9* pMaterial);
HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT9* pLight);
HRESULT __stdcall GetLight(DWORD Index,D3DLIGHT9* pLight);
HRESULT __stdcall LightEnable(DWORD Index,BOOL Enable);
HRESULT __stdcall GetLightEnable(DWORD Index,BOOL* pEnable);
HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane);
HRESULT __stdcall GetClipPlane(DWORD Index,float* pPlane);
HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State,DWORD Value);
HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State,DWORD* pValue);
HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type,IDirect3DStateBlock9** ppSB);
HRESULT __stdcall BeginStateBlock(void);
HRESULT __stdcall EndStateBlock(IDirect3DStateBlock9** ppSB);
HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS9* pClipStatus);
HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS9* pClipStatus);
HRESULT __stdcall GetTexture(DWORD Stage,IDirect3DBaseTexture9** ppTexture);
HRESULT __stdcall SetTexture(DWORD Stage,IDirect3DBaseTexture9* pTexture);
HRESULT __stdcall GetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue);
HRESULT __stdcall SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value);
HRESULT __stdcall GetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD* pValue);
HRESULT __stdcall SetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value);
HRESULT __stdcall ValidateDevice(DWORD* pNumPasses);
HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries);
HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber,PALETTEENTRY* pEntries);
HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber);
HRESULT __stdcall GetCurrentTexturePalette(UINT *PaletteNumber);
HRESULT __stdcall SetScissorRect(CONST RECT* pRect);
HRESULT __stdcall GetScissorRect( RECT* pRect);
HRESULT __stdcall SetSoftwareVertexProcessing(BOOL bSoftware);
BOOL __stdcall GetSoftwareVertexProcessing(void);
HRESULT __stdcall SetNPatchMode(float nSegments);
float __stdcall GetNPatchMode(void);
HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount);
HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
HRESULT __stdcall ProcessVertices(UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer9* pDestBuffer,IDirect3DVertexDeclaration9* pVertexDecl,DWORD Flags);
HRESULT __stdcall CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl);
HRESULT __stdcall SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl);
HRESULT __stdcall GetVertexDeclaration(IDirect3DVertexDeclaration9** ppDecl);
HRESULT __stdcall SetFVF(DWORD FVF);
HRESULT __stdcall GetFVF(DWORD* pFVF);
HRESULT __stdcall CreateVertexShader(CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader);
HRESULT __stdcall SetVertexShader(IDirect3DVertexShader9* pShader);
HRESULT __stdcall GetVertexShader(IDirect3DVertexShader9** ppShader);
HRESULT __stdcall SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall GetVertexShaderConstantF(UINT StartRegister,float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall GetVertexShaderConstantI(UINT StartRegister,int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall GetVertexShaderConstantB(UINT StartRegister,BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
HRESULT __stdcall GetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9** ppStreamData,UINT* OffsetInBytes,UINT* pStride);
HRESULT __stdcall SetStreamSourceFreq(UINT StreamNumber,UINT Divider);
HRESULT __stdcall GetStreamSourceFreq(UINT StreamNumber,UINT* Divider);
HRESULT __stdcall SetIndices(IDirect3DIndexBuffer9* pIndexData);
HRESULT __stdcall GetIndices(IDirect3DIndexBuffer9** ppIndexData);
HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader);
HRESULT __stdcall SetPixelShader(IDirect3DPixelShader9* pShader);
HRESULT __stdcall GetPixelShader(IDirect3DPixelShader9** ppShader);
HRESULT __stdcall SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall GetPixelShaderConstantF(UINT StartRegister,float* pConstantData,UINT Vector4fCount);
HRESULT __stdcall SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall GetPixelShaderConstantI(UINT StartRegister,int* pConstantData,UINT Vector4iCount);
HRESULT __stdcall SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall GetPixelShaderConstantB(UINT StartRegister,BOOL* pConstantData,UINT BoolCount);
HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo);
HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo);
HRESULT __stdcall DeletePatch(UINT Handle);
HRESULT __stdcall CreateQuery(D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery);
HRESULT __stdcall CheckDeviceState( HWND hWindow);
HRESULT __stdcall CheckResourceResidency( IDirect3DResource9 **pResourceArray, UINT32 NumResources);
HRESULT __stdcall ComposeRects( IDirect3DSurface9 *pSource, IDirect3DSurface9 *pDestination, IDirect3DVertexBuffer9 *pSrcRectDescriptors, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescriptors, D3DCOMPOSERECTSOP Operation, INT XOffset, INT YOffset);
HRESULT __stdcall CreateDepthStencilSurfaceEx( UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage);
HRESULT __stdcall CreateOffscreenPlainSurfaceEx( UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage);
HRESULT __stdcall CreateRenderTargetEx( UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage);
HRESULT __stdcall GetDisplayModeEx( UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation);
HRESULT __stdcall GetGPUThreadPriority( INT *pPriority);
HRESULT __stdcall GetMaximumFrameLatency( UINT *pMaxLatency);
HRESULT __stdcall PresentEx( const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion, DWORD dwFlags);
HRESULT __stdcall ResetEx( D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode);
HRESULT __stdcall SetConvolutionMonoKernel( UINT Width, UINT Height, float *RowWeights, float *ColumnWeights);
HRESULT __stdcall SetGPUThreadPriority( INT pPriority);
HRESULT __stdcall SetMaximumFrameLatency( UINT pMaxLatency);
//HRESULT __stdcall TestCooperativeLevel();
HRESULT __stdcall WaitForVBlank( UINT SwapChainIndex);
// END: The original DX9 function definitions
OTM_TextureClient* GetOTM_Client(void) {return (OTM_Client);}
OTM_IDirect3DTexture9* GetLastCreatedTexture(void) {return (LastCreatedTexture);}
int SetLastCreatedTexture(OTM_IDirect3DTexture9* pTexture) {LastCreatedTexture=pTexture; return (RETURN_OK);}
OTM_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture(void) {return (LastCreatedVolumeTexture);}
int SetLastCreatedVolumeTexture(OTM_IDirect3DVolumeTexture9* pTexture) {LastCreatedVolumeTexture=pTexture; return (RETURN_OK);}
OTM_IDirect3DCubeTexture9* GetLastCreatedCubeTexture(void) {return (LastCreatedCubeTexture);}
int SetLastCreatedCubeTexture(OTM_IDirect3DCubeTexture9* pTexture) {LastCreatedCubeTexture=pTexture; return (RETURN_OK);}
OTM_IDirect3DTexture9* GetSingleTexture(void) {return (SingleTexture);}
OTM_IDirect3DVolumeTexture9* GetSingleVolumeTexture(void) {return (SingleVolumeTexture);}
OTM_IDirect3DCubeTexture9* GetSingleCubeTexture(void) {return (SingleCubeTexture);}
private:
int CreateSingleTexture(void);
IDirect3DDevice9Ex* m_pIDirect3DDevice9Ex;
int CounterSaveSingleTexture;
OTM_IDirect3DTexture9* SingleTexture;
OTM_IDirect3DVolumeTexture9* SingleVolumeTexture;
OTM_IDirect3DCubeTexture9* SingleCubeTexture;
char SingleTextureMod;
D3DCOLOR TextureColour;
ID3DXFont *OSD_Font;
//D3DCOLOR FontColour;
int OTM_Reference;
OTM_IDirect3DTexture9* LastCreatedTexture;
OTM_IDirect3DVolumeTexture9* LastCreatedVolumeTexture;
OTM_IDirect3DCubeTexture9* LastCreatedCubeTexture;
OTM_TextureServer* OTM_Server;
OTM_TextureClient* OTM_Client;
};
#endif
+25 -3
View File
@@ -66,6 +66,11 @@ ULONG APIENTRY OTM_IDirect3DTexture9::AddRef()
//this function yields for the non switched texture object
ULONG APIENTRY OTM_IDirect3DTexture9::Release()
{
Message("OTM_IDirect3DTexture9::Release(): %lu\n", this);
void *cpy;
long ret = m_D3Ddev->QueryInterface( IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE)
{
@@ -81,7 +86,14 @@ ULONG APIENTRY OTM_IDirect3DTexture9::Release()
if (count==0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (((OTM_IDirect3DDevice9*)m_D3Ddev)->GetSingleTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
if (ret == 0x01000000L)
{
if (((OTM_IDirect3DDevice9*) m_D3Ddev)->GetSingleTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
else
{
if (((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetSingleTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
}
}
else
@@ -94,11 +106,21 @@ ULONG APIENTRY OTM_IDirect3DTexture9::Release()
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (((OTM_IDirect3DDevice9*)m_D3Ddev)->GetLastCreatedTexture()==this) ((OTM_IDirect3DDevice9*)m_D3Ddev)->SetLastCreatedTexture( NULL);
else ((OTM_IDirect3DDevice9*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
if (ret == 0x01000000L)
{
if (((OTM_IDirect3DDevice9*) m_D3Ddev)->GetLastCreatedTexture()==this) ((OTM_IDirect3DDevice9*) m_D3Ddev)->SetLastCreatedTexture( NULL);
else ((OTM_IDirect3DDevice9*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
}
else
{
if (((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetLastCreatedTexture()==this) ((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->SetLastCreatedTexture( NULL);
else ((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
}
delete(this);
}
Message("OTM_IDirect3DTexture9::Release() end: %lu\n", this);
return (count);
}
+23 -3
View File
@@ -65,6 +65,11 @@ ULONG APIENTRY OTM_IDirect3DVolumeTexture9::AddRef()
//this function yields for the non switched texture object
ULONG APIENTRY OTM_IDirect3DVolumeTexture9::Release()
{
Message("OTM_IDirect3DVolumeTexture9::Release(): %lu\n", this);
void *cpy;
long ret = m_D3Ddev->QueryInterface( IID_IDirect3DTexture9, &cpy);
ULONG count;
if (FAKE)
{
@@ -80,7 +85,14 @@ ULONG APIENTRY OTM_IDirect3DVolumeTexture9::Release()
if (count==0) //if texture is released we switch the textures back
{
UnswitchTextures(this);
if (((OTM_IDirect3DDevice9*)m_D3Ddev)->GetSingleVolumeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
if (ret == 0x01000000L)
{
if (((OTM_IDirect3DDevice9*) m_D3Ddev)->GetSingleVolumeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
else
{
if (((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetSingleVolumeTexture()!=fake_texture) fake_texture->Release(); // we release the fake texture
}
}
}
else
@@ -93,8 +105,16 @@ ULONG APIENTRY OTM_IDirect3DVolumeTexture9::Release()
{
// if this texture is the LastCreatedTexture, the next time LastCreatedTexture would be added,
// the hash of a non existing texture would be calculated
if (((OTM_IDirect3DDevice9*)m_D3Ddev)->GetLastCreatedVolumeTexture()==this) ((OTM_IDirect3DDevice9*)m_D3Ddev)->SetLastCreatedVolumeTexture( NULL);
else ((OTM_IDirect3DDevice9*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
if (ret == 0x01000000L)
{
if (((OTM_IDirect3DDevice9*) m_D3Ddev)->GetLastCreatedVolumeTexture()==this) ((OTM_IDirect3DDevice9*) m_D3Ddev)->SetLastCreatedVolumeTexture( NULL);
else ((OTM_IDirect3DDevice9*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
}
else
{
if (((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetLastCreatedVolumeTexture()==this) ((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->SetLastCreatedVolumeTexture( NULL);
else ((OTM_IDirect3DDevice9Ex*) m_D3Ddev)->GetOTM_Client()->RemoveTexture(this); // remove this texture from the texture client
}
delete(this);
}
+6
View File
@@ -45,11 +45,17 @@ along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
#include "OTM_Defines.h"
#include "OTM_DX9_dll.h"
#include "OTM_TextureFunction.h"
#include "OTM_IDirect3D9.h"
#include "OTM_IDirect3D9Ex.h"
#include "OTM_IDirect3DDevice9.h"
#include "OTM_IDirect3DDevice9Ex.h"
#include "OTM_IDirect3DCubeTexture9.h"
#include "OTM_IDirect3DTexture9.h"
#include "OTM_IDirect3DVolumeTexture9.h"
#include "OTM_ArrayHandler.h"
#include "OTM_TextureServer.h"
#include "OTM_TextureClient.h"
+65 -19
View File
@@ -23,7 +23,7 @@ along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
OTM_TextureClient::OTM_TextureClient(OTM_TextureServer* server, IDirect3DDevice9* device)
{
Message("OTM_TextureClient(void): %lu\n", this);
Message("OTM_TextureClient::OTM_TextureClient(void): %lu\n", this);
Server = server;
D3D9Device = device;
BoolSaveAllTextures = false;
@@ -60,7 +60,7 @@ OTM_TextureClient::OTM_TextureClient(OTM_TextureServer* server, IDirect3DDevice9
OTM_TextureClient::~OTM_TextureClient(void)
{
Message("~OTM_TextureClient(void): %lu\n", this);
Message("OTM_TextureClient::~OTM_TextureClient(void): %lu\n", this);
if (Server!=NULL) Server->RemoveClient(this);
if (Mutex!=NULL) CloseHandle(Mutex);
@@ -76,7 +76,11 @@ OTM_TextureClient::~OTM_TextureClient(void)
int OTM_TextureClient::AddTexture( OTM_IDirect3DTexture9* pTexture)
{
((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
else ((OTM_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
if (pTexture->FAKE) return (RETURN_OK); // this is a fake texture
Message("OTM_TextureClient::AddTexture( %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
@@ -97,7 +101,11 @@ int OTM_TextureClient::AddTexture( OTM_IDirect3DTexture9* pTexture)
int OTM_TextureClient::AddTexture( OTM_IDirect3DVolumeTexture9* pTexture)
{
((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
else ((OTM_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
if (pTexture->FAKE) return (RETURN_OK); // this is a fake texture
Message("OTM_TextureClient::AddTexture( Volume: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
@@ -118,7 +126,11 @@ int OTM_TextureClient::AddTexture( OTM_IDirect3DVolumeTexture9* pTexture)
int OTM_TextureClient::AddTexture( OTM_IDirect3DCubeTexture9* pTexture)
{
((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
else ((OTM_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
if (pTexture->FAKE) return (RETURN_OK); // this is a fake texture
Message("OTM_TextureClient::AddTexture( Cube: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
@@ -233,7 +245,12 @@ int OTM_TextureClient::SaveSingleTexture(bool val)
Message("OTM_TextureClient::SaveSingleTexture( %d): %lu\n", val, this);
if (BoolSaveSingleTexture && !val) //if BoolSaveSingleTexture is set to false and was previously true we switch the SingleTexture back
{
OTM_IDirect3DTexture9* pTexture = ((OTM_IDirect3DDevice9*)D3D9Device)->GetSingleTexture();
OTM_IDirect3DTexture9* pTexture;
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) pTexture = ((OTM_IDirect3DDevice9*)D3D9Device)->GetSingleTexture(); //this texture must no be added twice
else pTexture = ((OTM_IDirect3DDevice9Ex*) D3D9Device)->GetSingleTexture(); //this texture must no be added twice
if (pTexture!=NULL) UnswitchTextures(pTexture);
}
BoolSaveSingleTexture = val;
@@ -571,21 +588,32 @@ int OTM_TextureClient::MergeUpdate(void)
if (num_to_lookup>0)
{
OTM_IDirect3DTexture9 *single_texture = ((OTM_IDirect3DDevice9*)D3D9Device)->GetSingleTexture();
OTM_IDirect3DTexture9* single_texture;
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) single_texture = ((OTM_IDirect3DDevice9*)D3D9Device)->GetSingleTexture(); //this texture must no be added twice
else single_texture = ((OTM_IDirect3DDevice9Ex*) D3D9Device)->GetSingleTexture(); //this texture must no be added twice
int num = OriginalTextures.GetNumber();
for (int i=0; i<num; i++) if (OriginalTextures[i]->CrossRef_D3Dtex==NULL || OriginalTextures[i]->CrossRef_D3Dtex==single_texture)
{
UnswitchTextures(OriginalTextures[i]); //this we can do always, so we unswitch the single texture
LookUpToMod( OriginalTextures[i], num_to_lookup, to_lookup);
}
OTM_IDirect3DVolumeTexture9 *single_volume_texture = ((OTM_IDirect3DDevice9*)D3D9Device)->GetSingleVolumeTexture();
OTM_IDirect3DVolumeTexture9 *single_volume_texture;
if (ret == 0x01000000L) single_volume_texture = ((OTM_IDirect3DDevice9*)D3D9Device)->GetSingleVolumeTexture(); //this texture must no be added twice
else single_volume_texture = ((OTM_IDirect3DDevice9Ex*) D3D9Device)->GetSingleVolumeTexture(); //this texture must no be added twice
num = OriginalVolumeTextures.GetNumber();
for (int i=0; i<num; i++) if (OriginalVolumeTextures[i]->CrossRef_D3Dtex==NULL || OriginalVolumeTextures[i]->CrossRef_D3Dtex==single_volume_texture)
{
UnswitchTextures(OriginalVolumeTextures[i]); //this we can do always, so we unswitch the single texture
LookUpToMod( OriginalVolumeTextures[i], num_to_lookup, to_lookup);
}
OTM_IDirect3DCubeTexture9 *single_cube_texture = ((OTM_IDirect3DDevice9*)D3D9Device)->GetSingleCubeTexture();
OTM_IDirect3DCubeTexture9 *single_cube_texture;
if (ret == 0x01000000L) single_cube_texture = ((OTM_IDirect3DDevice9*)D3D9Device)->GetSingleCubeTexture(); //this texture must no be added twice
else single_cube_texture = ((OTM_IDirect3DDevice9Ex*) D3D9Device)->GetSingleCubeTexture(); //this texture must no be added twice
num = OriginalCubeTextures.GetNumber();
for (int i=0; i<num; i++) if (OriginalCubeTextures[i]->CrossRef_D3Dtex==NULL || OriginalCubeTextures[i]->CrossRef_D3Dtex==single_cube_texture)
{
@@ -639,12 +667,12 @@ int OTM_TextureClient::LookUpToMod( MyTypeHash hash, int num_index_list, int *in
if (hash > FileToMod[pos].Hash) // the new interval is the right half of the actual interval
{
begin = pos+1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new intervall
pos = (begin + end)/2; // set "pos" somewhere inside the new interval
}
else if (hash < FileToMod[pos].Hash) // the new interval is the left half of the actual interval
{
end = pos-1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new intervall
pos = (begin + end)/2; // set "pos" somewhere inside the new interval
}
else {return (pos); break;} // we hit the correct hash
}
@@ -665,12 +693,12 @@ int OTM_TextureClient::LookUpToMod( MyTypeHash hash, int num_index_list, int *in
if (hash > FileToMod[index_list[pos]].Hash) // the new interval is the right half of the actual interval
{
begin = pos+1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new intervall
pos = (begin + end)/2; // set "pos" somewhere inside the new interval
}
else if (hash < FileToMod[index_list[pos]].Hash) // the new interval is the left half of the actual interval
{
end = pos-1; // the new interval does not contain the index "pos"
pos = (begin + end)/2; // set "pos" somewhere inside the new intervall
pos = (begin + end)/2; // set "pos" somewhere inside the new interval
}
else {return (index_list[pos]); break;} // we hit the correct hash
}
@@ -773,13 +801,19 @@ int OTM_TextureClient::LookUpToMod( OTM_IDirect3DCubeTexture9* pTexture, int num
int OTM_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, OTM_IDirect3DTexture9 **ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DTexture9 **) ppTexture))
if (D3D_OK != D3DXCreateTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DTexture9 **) ppTexture))
//if (D3D_OK != D3DXCreateTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DTexture9 **) ppTexture))
{
*ppTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
(*ppTexture)->FAKE = true;
((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //this texture is a fake texture and must not be added
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
else ((OTM_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
Message("LoadTexture( %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return (RETURN_OK);
}
@@ -787,13 +821,19 @@ int OTM_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, OTM_IDire
int OTM_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, OTM_IDirect3DVolumeTexture9 **ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( Volume %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DVolumeTexture9 **) ppTexture))
if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DVolumeTexture9 **) ppTexture))
//if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DVolumeTexture9 **) ppTexture))
{
*ppTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
(*ppTexture)->FAKE = true;
((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture is a fake texture and must not be added
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
else ((OTM_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
Message("LoadTexture( Volume %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return (RETURN_OK);
}
@@ -801,13 +841,19 @@ int OTM_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, OTM_IDire
int OTM_TextureClient::LoadTexture( TextureFileStruct* file_in_memory, OTM_IDirect3DCubeTexture9 **ppTexture) // to load fake texture from a file in memory
{
Message("LoadTexture( Cube %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
if (D3D_OK != D3DXCreateCubeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DCubeTexture9 **) ppTexture))
if (D3D_OK != D3DXCreateCubeTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DCubeTexture9 **) ppTexture))
//if (D3D_OK != D3DXCreateCubeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DCubeTexture9 **) ppTexture))
{
*ppTexture=NULL;
return (RETURN_TEXTURE_NOT_LOADED);
}
(*ppTexture)->FAKE = true;
((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture is a fake texture and must not be added
void *cpy;
long ret = D3D9Device->QueryInterface( IID_IDirect3DTexture9, &cpy);
if (ret == 0x01000000L) ((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
else ((OTM_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
Message("LoadTexture( Cube %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
return (RETURN_OK);
}
+27 -5
View File
@@ -12,15 +12,29 @@ dll = d3d9.dll
else
ifdef DIRECT_INJECTION
ifdef ALPHA
precompiler_flag = /D "ALPHA"
precompiler_flag = /D "ALPHA" /D "DIRECT_INJECTION"
else
precompiler_flag =
precompiler_flag = /D "DIRECT_INJECTION"
endif
def_file = /DEF:"OTM_DX9_dll.def"
obj_suff = obj
dll = OTM_d3d9.dll
def_file = /DEF:"OTM_DX9_dll_DIRECT_INJECTION.def"
obj_suff = DI.obj
dll = OTM_d3d9_DI.dll
else
ifdef ALPHA
precompiler_flag = /D "ALPHA" /D "HOOK_INJECTION"
else
precompiler_flag = /D "HOOK_INJECTION"
endif
def_file = /DEF:"OTM_DX9_dll_HOOK_INJECTION.def"
obj_suff = HOOK.obj
dll = OTM_d3d9_Hook.dll
endif
endif
@@ -35,7 +49,9 @@ bin = bin
objects = ${obj}\OTM_DX9_dll.${obj_suff} \
${obj}\OTM_IDirect3D9.${obj_suff} \
${obj}\OTM_IDirect3D9Ex.${obj_suff} \
${obj}\OTM_IDirect3DDevice9.${obj_suff} \
${obj}\OTM_IDirect3DDevice9Ex.${obj_suff} \
${obj}\OTM_TextureFunction.${obj_suff} \
${obj}\OTM_IDirect3DTexture9.${obj_suff} \
${obj}\OTM_IDirect3DVolumeTexture9.${obj_suff} \
@@ -67,9 +83,15 @@ ${obj}\OTM_DX9_dll.${obj_suff}: OTM_DX9_dll.cpp ${headers}
${obj}\OTM_IDirect3D9.${obj_suff}: OTM_IDirect3D9.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\OTM_IDirect3D9Ex.${obj_suff}: OTM_IDirect3D9Ex.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\OTM_IDirect3DDevice9.${obj_suff}: OTM_IDirect3DDevice9.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\OTM_IDirect3DDevice9Ex.${obj_suff}: OTM_IDirect3DDevice9Ex.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\OTM_TextureFunction.${obj_suff}: OTM_TextureFunction.cpp ${headers}
${CXX} ${CFLAGS} /c $< /Fo$@
+30 -8
View File
@@ -12,15 +12,29 @@ dll = d3d9.dll
!ELSE
!IFDEF DIRECT_INJECTION
!IFDEF ALPHA
precompiler_flag = /D "ALPHA"
precompiler_flag = /D "ALPHA" /D "DIRECT_INJECTION"
!ELSE
precompiler_flag =
precompiler_flag = /D "DIRECT_INJECTION"
!ENDIF
def_file = /DEF:"OTM_DX9_dll.def"
obj_suff = obj
dll = OTM_d3d9.dll
def_file = /DEF:"OTM_DX9_dll_DIRECT_INJECTION.def"
obj_suff = DI.obj
dll = OTM_d3d9_DI.dll
!ELSE
!IFDEF ALPHA
precompiler_flag = /D "ALPHA" /D "HOOK_INJECTION"
!ELSE
precompiler_flag = /D "HOOK_INJECTION"
!ENDIF
def_file = /DEF:"OTM_DX9_dll_HOOK_INJECTION.def"
obj_suff = HOOK.obj
dll = OTM_d3d9_Hook.dll
!ENDIF
@@ -35,7 +49,9 @@ bin = bin
objects = $(obj)\OTM_DX9_dll.$(obj_suff) \
$(obj)\OTM_IDirect3D9.$(obj_suff) \
$(obj)\OTM_IDirect3D9Ex.$(obj_suff) \
$(obj)\OTM_IDirect3DDevice9.$(obj_suff) \
$(obj)\OTM_IDirect3DDevice9Ex.$(obj_suff) \
$(obj)\OTM_TextureFunction.$(obj_suff) \
$(obj)\OTM_IDirect3DTexture9.$(obj_suff) \
$(obj)\OTM_IDirect3DVolumeTexture9.$(obj_suff) \
@@ -63,18 +79,24 @@ $(bin)\d3d9.dll: $(objects)
$(obj)\OTM_DX9_dll.$(obj_suff): OTM_DX9_dll.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ OTM_DX9_dll.cpp
$(obj)\OTM_IDirect3D9.$(obj_suff): OTM_IDirect3D9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ OTM_IDirect3D9.cpp
$(obj)\OTM_IDirect3D9Ex.$(obj_suff): OTM_IDirect3D9Ex.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ OTM_IDirect3D9Ex.cpp
$(obj)\OTM_IDirect3DDevice9.$(obj_suff): OTM_IDirect3DDevice9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ OTM_IDirect3DDevice9.cpp
$(obj)\OTM_IDirect3DDevice9Ex.$(obj_suff): OTM_IDirect3DDevice9Ex.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ OTM_IDirect3DDevice9Ex.cpp
$(obj)\OTM_TextureFunction.$(obj_suff): OTM_TextureFunction.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ OTM_TextureFunction.cpp
$(CXX) $(CFLAGS) /c /Fo$@ OTM_TextureFunction.cpp
$(obj)\OTM_IDirect3DTexture9.$(obj_suff): OTM_IDirect3DTexture9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ OTM_IDirect3DTexture9.cpp
$(CXX) $(CFLAGS) /c /Fo$@ OTM_IDirect3DTexture9.cpp
$(obj)\OTM_IDirect3DVolumeTexture9.$(obj_suff): OTM_IDirect3DVolumeTexture9.cpp $(headers)
$(CXX) $(CFLAGS) /c /Fo$@ OTM_IDirect3DVolumeTexture9.cpp
+518
View File
@@ -0,0 +1,518 @@
/*
This file is part of OpenTexMod.
OpenTexMod is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenTexMod is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* Drew_Benton
* http://www.codeproject.com/KB/threads/completeinject.aspx
*
*/
#include "OTM_Main.h"
/***************************************************************************************************/
// Function:
// Inject
//
// Parameters:
// HANDLE hProcess - The handle to the process to inject the DLL into.
//
// const char* dllname - The name of the DLL to inject into the process.
//
// const char* funcname - The name of the function to call once the DLL has been injected.
//
// Description:
// This function will inject a DLL into a process and execute an exported function
// from the DLL to "initialize" it. The function should be in the format shown below,
// not parameters and no return type. Do not forget to prefix extern "C" if you are in C++
//
// __declspec(dllexport) void FunctionName(void)
//
// The function that is called in the injected DLL
// -MUST- return, the loader waits for the thread to terminate before removing the
// allocated space and returning control to the Loader. This method of DLL injection
// also adds error handling, so the end user knows if something went wrong.
/***************************************************************************************************/
void Inject(HANDLE hProcess, const wchar_t* dllname, const char* funcname)
{
//------------------------------------------//
// Function variables. //
//------------------------------------------//
// Main DLL we will need to load
HMODULE kernel32 = NULL;
// Main functions we will need to import
FARPROC loadlibrary = NULL;
FARPROC getprocaddress = NULL;
FARPROC exitprocess = NULL;
FARPROC exitthread = NULL;
FARPROC freelibraryandexitthread = NULL;
// The workspace we will build the codecave on locally
LPBYTE workspace = NULL;
DWORD workspaceIndex = 0;
// The memory in the process we write to
LPVOID codecaveAddress = NULL;
DWORD dwCodecaveAddress = 0;
// Strings we have to write into the process
char injectDllName[MAX_PATH + 1] = {0};
char injectFuncName[MAX_PATH + 1] = {0};
char injectError0[MAX_PATH + 1] = {0};
char injectError1[MAX_PATH + 1] = {0};
char injectError2[MAX_PATH + 1] = {0};
char user32Name[MAX_PATH + 1] = {0};
char msgboxName[MAX_PATH + 1] = {0};
// Placeholder addresses to use the strings
DWORD user32NameAddr = 0;
DWORD user32Addr = 0;
DWORD msgboxNameAddr = 0;
DWORD msgboxAddr = 0;
DWORD dllAddr = 0;
DWORD dllNameAddr = 0;
DWORD funcNameAddr = 0;
DWORD error0Addr = 0;
DWORD error1Addr = 0;
DWORD error2Addr = 0;
// Where the codecave execution should begin at
DWORD codecaveExecAddr = 0;
// Handle to the thread we create in the process
HANDLE hThread = NULL;
// Temp variables
DWORD dwTmpSize = 0;
// Old protection on page we are writing to in the process and the bytes written
DWORD oldProtect = 0;
DWORD bytesRet = 0;
//------------------------------------------//
// Variable initialization. //
//------------------------------------------//
// Get the address of the main DLL
kernel32 = LoadLibraryW(L"kernel32.dll");
// Get our functions
loadlibrary = GetProcAddress(kernel32, "LoadLibraryA");
getprocaddress = GetProcAddress(kernel32, "GetProcAddress");
exitprocess = GetProcAddress(kernel32, "ExitProcess");
exitthread = GetProcAddress(kernel32, "ExitThread");
freelibraryandexitthread = GetProcAddress(kernel32, "FreeLibraryAndExitThread");
// This section will cause compiler warnings on VS8,
// you can upgrade the functions or ignore them
// Build names
_snprintf(injectDllName, MAX_PATH, "%ls", dllname);
_snprintf(injectFuncName, MAX_PATH, "%s", funcname);
_snprintf(user32Name, MAX_PATH, "user32.dll");
_snprintf(msgboxName, MAX_PATH, "MessageBoxA");
// Build error messages
_snprintf(injectError0, MAX_PATH, "Error");
_snprintf(injectError1, MAX_PATH, "Could not load the dll: %s", injectDllName);
_snprintf(injectError2, MAX_PATH, "Could not load the function: %s", injectFuncName);
// Create the workspace
workspace = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1024);
// Allocate space for the codecave in the process
codecaveAddress = VirtualAllocEx(hProcess, 0, 1024, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
dwCodecaveAddress = PtrToUlong(codecaveAddress);
// Note there is no error checking done above for any functions that return a pointer/handle.
// I could have added them, but it'd just add more messiness to the code and not provide any real
// benefit. It's up to you though in your final code if you want it there or not.
//------------------------------------------//
// Data and string writing. //
//------------------------------------------//
// Write out the address for the user32 dll address
user32Addr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = 0;
memcpy(workspace + workspaceIndex, &dwTmpSize, 4);
workspaceIndex += 4;
// Write out the address for the MessageBoxA address
msgboxAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = 0;
memcpy(workspace + workspaceIndex, &dwTmpSize, 4);
workspaceIndex += 4;
// Write out the address for the injected DLL's module
dllAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = 0;
memcpy(workspace + workspaceIndex, &dwTmpSize, 4);
workspaceIndex += 4;
// User32 Dll Name
user32NameAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(user32Name) + 1;
memcpy(workspace + workspaceIndex, user32Name, dwTmpSize);
workspaceIndex += dwTmpSize;
// MessageBoxA name
msgboxNameAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(msgboxName) + 1;
memcpy(workspace + workspaceIndex, msgboxName, dwTmpSize);
workspaceIndex += dwTmpSize;
// Dll Name
dllNameAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectDllName) + 1;
memcpy(workspace + workspaceIndex, injectDllName, dwTmpSize);
workspaceIndex += dwTmpSize;
// Function Name
funcNameAddr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectFuncName) + 1;
memcpy(workspace + workspaceIndex, injectFuncName, dwTmpSize);
workspaceIndex += dwTmpSize;
// Error Message 1
error0Addr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectError0) + 1;
memcpy(workspace + workspaceIndex, injectError0, dwTmpSize);
workspaceIndex += dwTmpSize;
// Error Message 2
error1Addr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectError1) + 1;
memcpy(workspace + workspaceIndex, injectError1, dwTmpSize);
workspaceIndex += dwTmpSize;
// Error Message 3
error2Addr = workspaceIndex + dwCodecaveAddress;
dwTmpSize = (DWORD)strlen(injectError2) + 1;
memcpy(workspace + workspaceIndex, injectError2, dwTmpSize);
workspaceIndex += dwTmpSize;
// Pad a few INT3s after string data is written for seperation
workspace[workspaceIndex++] = 0xCC;
workspace[workspaceIndex++] = 0xCC;
workspace[workspaceIndex++] = 0xCC;
// Store where the codecave execution should begin
codecaveExecAddr = workspaceIndex + dwCodecaveAddress;
// For debugging - infinite loop, attach onto process and step over
//workspace[workspaceIndex++] = 0xEB;
//workspace[workspaceIndex++] = 0xFE;
//------------------------------------------//
// User32.dll loading. //
//------------------------------------------//
// User32 DLL Loading
// PUSH 0x00000000 - Push the address of the DLL name to use in LoadLibraryA
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &user32NameAddr, 4);
workspaceIndex += 4;
// MOV EAX, ADDRESS - Move the address of LoadLibraryA into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &loadlibrary, 4);
workspaceIndex += 4;
// CALL EAX - Call LoadLibraryA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// MessageBoxA Loading
// PUSH 0x000000 - Push the address of the function name to load
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &msgboxNameAddr, 4);
workspaceIndex += 4;
// Push EAX, module to use in GetProcAddress
workspace[workspaceIndex++] = 0x50;
// MOV EAX, ADDRESS - Move the address of GetProcAddress into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &getprocaddress, 4);
workspaceIndex += 4;
// CALL EAX - Call GetProcAddress
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// MOV [ADDRESS], EAX - Save the address to our variable
workspace[workspaceIndex++] = 0xA3;
memcpy(workspace + workspaceIndex, &msgboxAddr, 4);
workspaceIndex += 4;
//------------------------------------------//
// Injected dll loading. //
//------------------------------------------//
/*
// This is the way the following assembly code would look like in C/C++
// Load the injected DLL into this process
HMODULE h = LoadLibrary("mydll.dll");
if(!h)
{
MessageBox(0, "Could not load the dll: mydll.dll", "Error", MB_ICONERROR);
ExitProcess(0);
}
// Get the address of the export function
FARPROC p = GetProcAddress(h, "Initialize");
if(!p)
{
MessageBox(0, "Could not load the function: Initialize", "Error", MB_ICONERROR);
ExitProcess(0);
}
// So we do not need a function pointer interface
__asm call p
// Exit the thread so the loader continues
ExitThread(0);
*/
// DLL Loading
// PUSH 0x00000000 - Push the address of the DLL name to use in LoadLibraryA
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &dllNameAddr, 4);
workspaceIndex += 4;
// MOV EAX, ADDRESS - Move the address of LoadLibraryA into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &loadlibrary, 4);
workspaceIndex += 4;
// CALL EAX - Call LoadLibraryA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// Error Checking
// CMP EAX, 0
workspace[workspaceIndex++] = 0x83;
workspace[workspaceIndex++] = 0xF8;
workspace[workspaceIndex++] = 0x00;
// JNZ EIP + 0x1E to skip over eror code
workspace[workspaceIndex++] = 0x75;
workspace[workspaceIndex++] = 0x1E;
// Error Code 1
// MessageBox
// PUSH 0x10 (MB_ICONHAND)
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x10;
// PUSH 0x000000 - Push the address of the MessageBox title
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &error0Addr, 4);
workspaceIndex += 4;
// PUSH 0x000000 - Push the address of the MessageBox message
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &error1Addr, 4);
workspaceIndex += 4;
// Push 0
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, [ADDRESS] - Move the address of MessageBoxA into EAX
workspace[workspaceIndex++] = 0xA1;
memcpy(workspace + workspaceIndex, &msgboxAddr, 4);
workspaceIndex += 4;
// CALL EAX - Call MessageBoxA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// ExitProcess
// Push 0
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, ADDRESS - Move the address of ExitProcess into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &exitprocess, 4);
workspaceIndex += 4;
// CALL EAX - Call MessageBoxA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// Now we have the address of the injected DLL, so save the handle
// MOV [ADDRESS], EAX - Save the address to our variable
workspace[workspaceIndex++] = 0xA3;
memcpy(workspace + workspaceIndex, &dllAddr, 4);
workspaceIndex += 4;
// Load the initilize function from it
// PUSH 0x000000 - Push the address of the function name to load
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &funcNameAddr, 4);
workspaceIndex += 4;
// Push EAX, module to use in GetProcAddress
workspace[workspaceIndex++] = 0x50;
// MOV EAX, ADDRESS - Move the address of GetProcAddress into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &getprocaddress, 4);
workspaceIndex += 4;
// CALL EAX - Call GetProcAddress
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// Error Checking
// CMP EAX, 0
workspace[workspaceIndex++] = 0x83;
workspace[workspaceIndex++] = 0xF8;
workspace[workspaceIndex++] = 0x00;
// JNZ EIP + 0x1C to skip eror code
workspace[workspaceIndex++] = 0x75;
workspace[workspaceIndex++] = 0x1C;
// Error Code 2
// MessageBox
// PUSH 0x10 (MB_ICONHAND)
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x10;
// PUSH 0x000000 - Push the address of the MessageBox title
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &error0Addr, 4);
workspaceIndex += 4;
// PUSH 0x000000 - Push the address of the MessageBox message
workspace[workspaceIndex++] = 0x68;
memcpy(workspace + workspaceIndex, &error2Addr, 4);
workspaceIndex += 4;
// Push 0
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, ADDRESS - Move the address of MessageBoxA into EAX
workspace[workspaceIndex++] = 0xA1;
memcpy(workspace + workspaceIndex, &msgboxAddr, 4);
workspaceIndex += 4;
// CALL EAX - Call MessageBoxA
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// ExitProcess
// Push 0
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, ADDRESS - Move the address of ExitProcess into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &exitprocess, 4);
workspaceIndex += 4;
// Now that we have the address of the function, we cam call it,
// if there was an error, the messagebox would be called as well.
// CALL EAX - Call ExitProcess -or- the Initialize function
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
// If we get here, the Initialize function has been called,
// so it's time to close this thread and optionally unload the DLL.
//------------------------------------------//
// Exiting from the injected dll. //
//------------------------------------------//
// Call ExitThread to leave the DLL loaded
#if 1
// Push 0 (exit code)
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// MOV EAX, ADDRESS - Move the address of ExitThread into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &exitthread, 4);
workspaceIndex += 4;
// CALL EAX - Call ExitThread
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
#endif
// Call FreeLibraryAndExitThread to unload DLL
#if 0
// Push 0 (exit code)
workspace[workspaceIndex++] = 0x6A;
workspace[workspaceIndex++] = 0x00;
// PUSH [0x000000] - Push the address of the DLL module to unload
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0x35;
memcpy(workspace + workspaceIndex, &dllAddr, 4);
workspaceIndex += 4;
// MOV EAX, ADDRESS - Move the address of FreeLibraryAndExitThread into EAX
workspace[workspaceIndex++] = 0xB8;
memcpy(workspace + workspaceIndex, &freelibraryandexitthread, 4);
workspaceIndex += 4;
// CALL EAX - Call FreeLibraryAndExitThread
workspace[workspaceIndex++] = 0xFF;
workspace[workspaceIndex++] = 0xD0;
#endif
//------------------------------------------//
// Code injection and cleanup. //
//------------------------------------------//
// Change page protection so we can write executable code
VirtualProtectEx(hProcess, codecaveAddress, workspaceIndex, PAGE_EXECUTE_READWRITE, &oldProtect);
// Write out the patch
WriteProcessMemory(hProcess, codecaveAddress, workspace, workspaceIndex, &bytesRet);
// Restore page protection
VirtualProtectEx(hProcess, codecaveAddress, workspaceIndex, oldProtect, &oldProtect);
// Make sure our changes are written right away
FlushInstructionCache(hProcess, codecaveAddress, workspaceIndex);
// Free the workspace memory
HeapFree(GetProcessHeap(), 0, workspace);
// Execute the thread now and wait for it to exit, note we execute where the code starts, and not the codecave start
// (since we wrote strings at the start of the codecave) -- NOTE: void* used for VC6 compatibility instead of UlongToPtr
hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)((void*)codecaveExecAddr), 0, 0, NULL);
WaitForSingleObject(hThread, INFINITE);
// Free the memory in the process that we allocated
VirtualFreeEx(hProcess, codecaveAddress, 0, MEM_RELEASE);
}
+27
View File
@@ -0,0 +1,27 @@
/*
This file is part of OpenTexMod.
OpenTexMod is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenTexMod is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OTM_INJECTDIRECTLY_H_
#define OTM_INJECTDIRECTLY_H_
void Inject(HANDLE hProcess, const wchar_t* dllname, const char* funcname);
#endif /* OTM_INJECTDIRECTLY_H_ */
+249 -46
View File
@@ -43,8 +43,12 @@ BEGIN_EVENT_TABLE(OTM_Frame, wxFrame)
EVT_MENU(ID_Menu_Acknowledgement, OTM_Frame::OnMenuAcknowledgement)
EVT_MENU(ID_Menu_StartGame, OTM_Frame::OnMenuStartGame)
EVT_MENU(ID_Menu_StartGameCMD, OTM_Frame::OnMenuStartGame)
EVT_MENU(ID_Menu_AddGame, OTM_Frame::OnMenuAddGame)
EVT_MENU(ID_Menu_DeleteGame, OTM_Frame::OnMenuDeleteGame)
EVT_MENU(ID_Menu_UseHook, OTM_Frame::OnMenuUseHook)
EVT_MENU(ID_Menu_LoadTemplate, OTM_Frame::OnMenuOpenTemplate)
EVT_MENU(ID_Menu_SaveTemplate, OTM_Frame::OnMenuSaveTemplate)
@@ -79,17 +83,18 @@ bool MyApp::OnInit(void)
wxMessageBox( Language->Error_AlreadyRunning, "ERROR", wxOK|wxICON_ERROR);
return false;
}
OTM_Frame *frame = new OTM_Frame( OTM_VERSION, wxPoint(set.XPos,set.YPos), wxSize(set.XSize,set.YSize));
OTM_Frame *frame = new OTM_Frame( OTM_VERSION, set);
SetTopWindow( frame );
return true;
}
OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
OTM_Frame::OTM_Frame(const wxString& title, OTM_Settings &set)
: wxFrame((wxFrame *)NULL, -1, title, wxPoint(set.XPos,set.YPos), wxSize(set.XSize,set.YSize)), Settings(set)
{
SetIcon(wxICON(MAINICON));
H_DX9_DLL = NULL;
Server = new OTM_Server( this);
Server->Create();
@@ -100,9 +105,15 @@ OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& si
MenuMain = new wxMenu;
MenuHelp = new wxMenu;
MenuMain->Append ( ID_Menu_StartGame, Language->MenuStartGame);
MenuMain->Append ( ID_Menu_StartGameCMD, Language->MenuStartGameCMD);
MenuMain->AppendSeparator();
MenuMain->Append( ID_Menu_AddGame, Language->MenuAddGame );
MenuMain->Append( ID_Menu_DeleteGame, Language->MenuDeleteGame );
MenuMain->AppendCheckItem ( ID_Menu_UseHook, Language->MenuUseHook);
MenuMain->Check( ID_Menu_UseHook, Settings.UseHook);
MenuMain->AppendSeparator();
MenuMain->Append( ID_Menu_LoadTemplate, Language->MenuLoadTemplate );
MenuMain->Append( ID_Menu_SaveTemplate, Language->MenuSaveTemplate );
@@ -154,36 +165,7 @@ OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& si
LoadTemplate();
Show( true );
H_DX9_DLL = LoadLibraryW(OTM_d3d9_dll);
if (H_DX9_DLL!=NULL)
{
typedef void (*fkt_typ)(void);
fkt_typ InstallHook = (fkt_typ) GetProcAddress( H_DX9_DLL, "InstallHook");
if (InstallHook!=NULL) InstallHook();
else
{
DWORD error = GetLastError();
wchar_t *error_msg;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error_msg, 0, NULL );
wxString temp = Language->Error_DLLNotFound;
temp << "\n" << OTM_d3d9_dll;
temp << "\n" << error_msg << "Code: " << error;
wxMessageBox( temp, "ERROR", wxOK);
}
}
else
{
DWORD error = GetLastError();
wchar_t *error_msg;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error_msg, 0, NULL );
wxString temp = Language->Error_DLLNotFound;
temp << "\n" << OTM_d3d9_dll;
temp << "\n" << error_msg << "Code: " << error;
wxMessageBox(temp, "ERROR", wxOK|wxICON_ERROR);
}
if (Settings.UseHook) InstallHook();
}
OTM_Frame::~OTM_Frame(void)
@@ -196,21 +178,14 @@ OTM_Frame::~OTM_Frame(void)
Server = NULL;
}
if (H_DX9_DLL!=NULL)
{
typedef void (*fkt_typ)(void);
fkt_typ RemoveHook = (fkt_typ) GetProcAddress( H_DX9_DLL, "RemoveHook");
if (RemoveHook!=NULL) RemoveHook();
FreeLibrary(H_DX9_DLL);
}
RemoveHook();
if (Clients!=NULL) delete [] Clients;
OTM_Settings set;
set.Language = Language->GetCurrentLanguage();
GetSize( &set.XSize, &set.YSize);
GetPosition( &set.XPos, &set.YPos);
set.Save();
Settings.Language = Language->GetCurrentLanguage();
GetSize( &Settings.XSize, &Settings.YSize);
GetPosition( &Settings.XPos, &Settings.YPos);
Settings.Save();
}
int OTM_Frame::KillServer(void)
@@ -477,8 +452,12 @@ void OTM_Frame::OnMenuLanguage(wxCommandEvent& WXUNUSED(event))
return;
}
MenuBar->SetMenuLabel( 0, Language->MainMenuMain);
MenuMain->SetLabel( ID_Menu_StartGame, Language->MenuStartGame);
MenuMain->SetLabel( ID_Menu_StartGameCMD, Language->MenuStartGameCMD);
MenuMain->SetLabel( ID_Menu_AddGame, Language->MenuAddGame);
MenuMain->SetLabel( ID_Menu_DeleteGame, Language->MenuDeleteGame);
MenuMain->SetLabel( ID_Menu_UseHook, Language->MenuUseHook);
MenuMain->SetLabel( ID_Menu_LoadTemplate, Language->MenuLoadTemplate );
MenuMain->SetLabel( ID_Menu_SaveTemplate, Language->MenuSaveTemplate );
@@ -539,10 +518,117 @@ void OTM_Frame::OnMenuAcknowledgement(wxCommandEvent& WXUNUSED(event))
title << OTM_VERSION << " by ROTA";
wxString msg;
msg << "RS for coding the original TexMod and for information about the used hashing algorithm\n";
msg << "EvilAlex for translation into Russian and bug fixing";
msg << "EvilAlex for translation into Russian and bug fixing\n";
msg << "King Brace Blane for a tutorial video on YouTube and bug fixing";
wxMessageBox( msg, title, wxOK);
}
void OTM_Frame::OnMenuStartGame(wxCommandEvent& event)
{
bool use_cmd = false;
if (event.GetId() == ID_Menu_StartGameCMD) use_cmd = true;
wxArrayString games, cmd, choices;
GetInjectedGames( games, cmd);
int num = games.GetCount();
choices = games;
choices.Add( Language->StartGame);
int index = wxGetSingleChoiceIndex( Language->MenuStartGame, Language->MenuStartGame, choices);
if (index < 0) return;
else if (index==num)
{
wxString file_name = wxFileSelector( Language->ChooseGame, "", "", "exe", "binary (*.exe)|*.exe", wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
if ( !file_name.empty() )
{
bool hit = false;
for (int i=0; i<num; i++) if (file_name==games[i]) {hit=true; index=i; break;}
if (!hit)
{
games.Add(file_name);
cmd.Add("");
}
}
else return;
}
wxString command_line;
if (use_cmd)
{
command_line = cmd[index];
command_line = wxGetTextFromUser( Language->CommandLine, Language->CommandLine, command_line);
if (!command_line.IsEmpty()) cmd[index] = command_line;
}
SetInjectedGames( games, cmd);
if (Settings.UseHook)
{
wxArrayString array;
if (GetHookedGames( array)) array.Empty();
int num = array.GetCount();
for (int i=0; i<num; i++) if (array[i] == games[index])
{
wxMessageBox(Language->Error_GameIsHooked, "ERROR", wxOK|wxICON_ERROR);
return;
}
}
STARTUPINFOW si = {0};
si.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi = {0};
wxString path = games[index].BeforeLast('\\');
wxString exe;
if (use_cmd) exe << "\"" << games[index] << "\" " << command_line;
else exe = games[index];
bool result = CreateProcess(NULL, (wchar_t*) exe.wc_str(), NULL, NULL, FALSE,
CREATE_SUSPENDED, NULL, path.wc_str(), &si, &pi);
if(!result)
{
wxMessageBox( Language->Error_ProcessNotStarted, "ERROR", wxOK|wxICON_ERROR);
return ;
}
wxString dll = wxGetCwd();
dll.Append( L"\\" OTM_d3d9_DI_dll);
Inject(pi.hProcess, dll.wc_str(), "Nothing");
ResumeThread(pi.hThread);
}
void OTM_Frame::OnMenuUseHook(wxCommandEvent& WXUNUSED(event))
{
bool use_hook = MenuMain->IsChecked(ID_Menu_UseHook);
if (Settings.UseHook!=use_hook)
{
if (Settings.UseHook)
{
if (NumberOfGames>0)
{
MenuMain->Check(ID_Menu_UseHook, true);
wxMessageBox(Language->Error_RemoveHook, "ERROR", wxOK|wxICON_ERROR);
return;
}
RemoveHook();
}
else
{
InstallHook();
}
Settings.UseHook=use_hook;
}
}
void OTM_Frame::OnMenuAddGame(wxCommandEvent& WXUNUSED(event))
{
@@ -667,6 +753,73 @@ int OTM_Frame::SetHookedGames( const wxArrayString &array)
return 0;
}
#define DI_FILE "OTM_DI_Games.txt"
int OTM_Frame::GetInjectedGames( wxArrayString &games, wxArrayString &cmd)
{
wxFile file;
if (!file.Access( DI_FILE, wxFile::read)) {LastError << Language->Error_FileOpen << "\n" << DI_FILE; return -1;}
file.Open( DI_FILE, wxFile::read);
if (!file.IsOpened()) {LastError << Language->Error_FileOpen << "\n" << DI_FILE ; return -1;}
unsigned len = file.Length();
unsigned char* buffer;
try {buffer = new unsigned char [len+2];}
catch (...) {LastError << Language->Error_Memory; return -1;}
unsigned int result = file.Read( buffer, len);
file.Close();
if (result != len) {delete [] buffer; LastError << Language->Error_FileRead<<"\n" << DI_FILE; return -1;}
wchar_t *buff = (wchar_t*)buffer;
len/=2;
buff[len]=0;
wxString content;
content = buff;
delete [] buffer;
wxStringTokenizer token( content, "\n");
int num = token.CountTokens();
games.Empty();
games.Alloc(num);
cmd.Empty();
cmd.Alloc(num);
wxString entry;
for (int i=0; i<num; i++)
{
entry = token.GetNextToken();
games.Add( entry.BeforeFirst('|'));
cmd.Add( entry.AfterFirst('|'));
}
return 0;
}
int OTM_Frame::SetInjectedGames( wxArrayString &games, wxArrayString &cmd)
{
wxFile file;
file.Open( DI_FILE, wxFile::write);
if (!file.IsOpened()) {LastError << Language->Error_FileOpen << "\n" << DI_FILE ; return -1;}
wxString content;
int num = games.GetCount();
for (int i=0; i<num; i++)
{
content = games[i];
content << "|" << cmd[i] << "\n";
file.Write( content.wc_str(), content.Len()*2);
}
file.Close();
return 0;
}
#define SAVE_FILE "OTM_SaveFiles.txt"
int OTM_Frame::LoadTemplate(void)
@@ -736,3 +889,53 @@ int OTM_Frame::SaveTemplate(void)
file.Close();
return 0;
}
void OTM_Frame::InstallHook(void)
{
if (H_DX9_DLL==NULL)
{
H_DX9_DLL = LoadLibraryW(OTM_d3d9_Hook_dll);
if (H_DX9_DLL!=NULL)
{
typedef void (*fkt_typ)(void);
fkt_typ install_hook = (fkt_typ) GetProcAddress( H_DX9_DLL, "InstallHook");
if (install_hook!=NULL) install_hook();
else
{
DWORD error = GetLastError();
wchar_t *error_msg;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error_msg, 0, NULL );
wxString temp = Language->Error_DLLNotFound;
temp << "\n" << OTM_d3d9_Hook_dll;
temp << "\n" << error_msg << "Code: " << error;
wxMessageBox( temp, "ERROR", wxOK);
}
}
else
{
DWORD error = GetLastError();
wchar_t *error_msg;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error_msg, 0, NULL );
wxString temp = Language->Error_DLLNotFound;
temp << "\n" << OTM_d3d9_Hook_dll;
temp << "\n" << error_msg << "Code: " << error;
wxMessageBox(temp, "ERROR", wxOK|wxICON_ERROR);
}
}
}
void OTM_Frame::RemoveHook(void)
{
if (H_DX9_DLL!=NULL)
{
typedef void (*fkt_typ)(void);
fkt_typ remove_hook = (fkt_typ) GetProcAddress( H_DX9_DLL, "RemoveHook");
if (remove_hook!=NULL) remove_hook();
FreeLibrary(H_DX9_DLL);
}
H_DX9_DLL = NULL;
}
+14 -1
View File
@@ -27,10 +27,11 @@ along with OpenTexMod. If not, see <http://www.gnu.org/licenses/>.
class OTM_Frame : public wxFrame
{
public:
OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& size);
OTM_Frame(const wxString& title, OTM_Settings &set);
~OTM_Frame(void);
void OnAddGame( wxCommandEvent &event);
void OnDeleteGame( wxCommandEvent &event);
@@ -42,6 +43,9 @@ public:
void OnButtonUpdate(wxCommandEvent& WXUNUSED(event));
void OnButtonReload(wxCommandEvent& WXUNUSED(event));
void OnMenuStartGame( wxCommandEvent &event);
void OnMenuUseHook( wxCommandEvent &event);
void OnMenuAddGame(wxCommandEvent& WXUNUSED(event));
void OnMenuDeleteGame(wxCommandEvent& WXUNUSED(event));
@@ -58,10 +62,15 @@ public:
void OnMenuAcknowledgement(wxCommandEvent& WXUNUSED(event));
private:
OTM_Settings Settings;
int KillServer(void);
int GetHookedGames( wxArrayString &array);
int SetHookedGames( const wxArrayString &array);
int GetInjectedGames( wxArrayString &games, wxArrayString &cmd);
int SetInjectedGames( wxArrayString &games, wxArrayString &cmd);
OTM_Server *Server;
@@ -91,6 +100,10 @@ private:
wxArrayString SaveFile_Exe;
wxArrayString SaveFile_Name;
void InstallHook(void);
void RemoveHook(void);
HMODULE H_DX9_DLL;
wxString LastError;
+20 -36
View File
@@ -35,42 +35,6 @@ OTM_Language::OTM_Language(const wxString &name)
LastError.Empty();
}
//#define LAST_USED_LANGUAGE_FILE "OTM_LastUsedLanguage.txt"
/*
int OTM_Language::LoadCurrentLanguage(void)
{
wxFile file;
if (!file.Access( LAST_USED_LANGUAGE_FILE, wxFile::read)) return -1;
file.Open( LAST_USED_LANGUAGE_FILE, wxFile::read);
if (!file.IsOpened()) return -1;
unsigned len = file.Length();
char* buffer;
try {buffer = new char [len+1];}
catch (...) {return -1;}
unsigned int result = file.Read( buffer, len);
file.Close();
if (result != len) return -1;
buffer[len]=0;
wxString lang = buffer;
delete [] buffer;
return LoadLanguage( lang, false);
}
int OTM_Language::SaveCurrentLanguage(void)
{
wxFile file;
//if (!file.Access( LAST_USED_LANGUAGE_FILE, wxFile::write)) return -1;
file.Open( LAST_USED_LANGUAGE_FILE, wxFile::write);
if (!file.IsOpened()) return -1;
file.Write( CurrentLanguage.char_str(), CurrentLanguage.Len());
return 0;
}
*/
int OTM_Language::GetLanguages(wxArrayString &lang)
{
@@ -222,6 +186,9 @@ int OTM_Language::LoadLanguage(const wxString &name)
CheckEntry( command, msg, MenuHelp)
CheckEntry( command, msg, MenuAbout)
CheckEntry( command, msg, MenuAcknowledgement)
CheckEntry( command, msg, MenuStartGame)
CheckEntry( command, msg, MenuStartGameCMD)
CheckEntry( command, msg, MenuUseHook)
CheckEntry( command, msg, MenuAddGame)
CheckEntry( command, msg, MenuDeleteGame)
CheckEntry( command, msg, MenuLoadTemplate)
@@ -242,12 +209,17 @@ int OTM_Language::LoadLanguage(const wxString &name)
CheckEntry( command, msg, CheckBoxSaveAllTextures)
CheckEntry( command, msg, TextCtrlSavePath)
CheckEntry( command, msg, SelectLanguage)
CheckEntry( command, msg, StartGame)
CheckEntry( command, msg, CommandLine)
CheckEntry( command, msg, ChooseGame)
CheckEntry( command, msg, DeleteGame)
CheckEntry( command, msg, GameAlreadyAdded)
CheckEntry( command, msg, ExitGameAnyway)
CheckEntry( command, msg, NoComment)
CheckEntry( command, msg, Author)
CheckEntry( command, msg, Error_GameIsHooked)
CheckEntry( command, msg, Error_ProcessNotStarted)
CheckEntry( command, msg, Error_RemoveHook)
CheckEntry( command, msg, Error_FileNotSupported)
CheckEntry( command, msg, Error_FktNotFound)
CheckEntry( command, msg, Error_DLLNotFound)
@@ -288,6 +260,11 @@ int OTM_Language::LoadDefault(void)
MenuHelp = "Help";
MenuAbout = "About";
MenuAcknowledgement = "Acknowledgement";
MenuStartGame = "Start game through OTM";
MenuStartGameCMD = "Start game through OTM (with command line)";
MenuUseHook = "Use global hook";
MenuAddGame = "Add game";
MenuDeleteGame = "Delete game";
MenuLoadTemplate = "Load template";
@@ -314,6 +291,9 @@ int OTM_Language::LoadDefault(void)
SelectLanguage = "Select a language.";
StartGame = "Select the game to start.";
CommandLine = "Set command line arguments.";
ChooseGame = "Select a game binary.";
DeleteGame = "Select the games to be deleted.";
GameAlreadyAdded = "Game has been already added.";
@@ -321,6 +301,10 @@ int OTM_Language::LoadDefault(void)
NoComment = "No comment.";
Author = "Author: ";
Error_GameIsHooked = "The global hook is active and this game will be injected! Please delete the game from the list or disable the hook.";
Error_ProcessNotStarted = "The game could not be started.";
Error_RemoveHook = "Removing the Hook while a game is running might lead to crash.";
Error_FileNotSupported = "This file type is not supported:\n";
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.";
+10
View File
@@ -37,6 +37,9 @@ public:
wxString MenuHelp;
wxString MenuAbout;
wxString MenuAcknowledgement;
wxString MenuStartGame;
wxString MenuStartGameCMD;
wxString MenuUseHook;
wxString MenuAddGame;
wxString MenuDeleteGame;
wxString MenuLoadTemplate;
@@ -63,6 +66,9 @@ public:
wxString SelectLanguage;
wxString StartGame;
wxString CommandLine;
wxString ChooseGame;
wxString DeleteGame;
wxString GameAlreadyAdded;
@@ -70,6 +76,10 @@ public:
wxString NoComment;
wxString Author;
wxString Error_GameIsHooked;
wxString Error_ProcessNotStarted;
wxString Error_RemoveHook;
wxString Error_FileNotSupported;
wxString Error_FktNotFound;
wxString Error_DLLNotFound;
+6 -1
View File
@@ -87,6 +87,9 @@ enum
ID_Menu_Help,
ID_Menu_About,
ID_Menu_Acknowledgement,
ID_Menu_StartGame,
ID_Menu_StartGameCMD,
ID_Menu_UseHook,
ID_Menu_AddGame,
ID_Menu_DeleteGame,
ID_Menu_LoadTemplate,
@@ -99,7 +102,8 @@ enum
};
#define ABORT_SERVER L"OTM_Abort_Server"
#define OTM_d3d9_dll L"OTM_d3d9.dll"
#define OTM_d3d9_Hook_dll L"OTM_d3d9_Hook.dll"
#define OTM_d3d9_DI_dll L"OTM_d3d9_DI.dll"
#include "OTM_AddTexture.h"
#include "OTM_Settings.h"
@@ -111,6 +115,7 @@ enum
#include "OTM_Sender.h"
#include "OTM_Server.h"
#include "OTM_GamePage.h"
#include "OTM_DirectInjection.h"
#include "OTM_GUI.h"
+28
View File
@@ -27,9 +27,21 @@ OTM_Settings::OTM_Settings(void)
YSize = 400;
XPos = -1;
YPos = -1;
UseHook = true;
Language = "English";
}
OTM_Settings::OTM_Settings(OTM_Settings &set)
{
XSize = set.XSize;
YSize = set.YSize;
XPos = set.XPos;
YPos = set.YPos;
UseHook = set.UseHook;
Language = set.Language;
}
#define SETTINGS_FILE "OTM_Settings.txt"
int OTM_Settings::Load(void)
@@ -65,6 +77,8 @@ int OTM_Settings::Load(void)
wxString line;
wxString command;
wxString value;
UseHook = false;
for (int i=0; i<num; i++)
{
line = token.GetNextToken();
@@ -93,6 +107,15 @@ int OTM_Settings::Load(void)
long y;
if (value.ToLong( &y)) YPos=y;
}
else if (command == "UseHook")
{
long use;
if (value.ToLong( &use))
{
if (use) UseHook = true;
else UseHook = false;
}
}
}
return 0;
@@ -121,6 +144,11 @@ int OTM_Settings::Save(void)
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";
file.Write( content.wc_str(), content.Len()*2);
file.Close();
return 0;
+2
View File
@@ -27,10 +27,12 @@ class OTM_Settings
{
public:
OTM_Settings(void);
OTM_Settings(OTM_Settings &set);
int XSize, YSize;
int XPos, YPos;
bool UseHook;
wxString Language;
int Load(void);
+17 -7
View File
@@ -61,19 +61,29 @@ mehrfach gestartet wird).
Wie bekomme ich OpenTexMod zum laufen?
Es gibt zwei Wege wie OpenTexMod sich in die DirectX Verbindung einklinken kann:
Es gibt drei Wege wie OpenTexMod sich in die DirectX Verbindung einklinken kann:
(Benutze NICHT mehrere Methoden gleichzeitig!)
1) (bevorzugt) Füge die Spiel-exe über das Menü Spiele->"Spiel hinzufügen" hinzu.
1) Füge die Spiel-exe über das Menü "Einstellungen->Spiel hinzufügen" hinzu.
Für Steam siehe unten.
2) Kopiere die d3d9.dll (vom OpenTexMod Verzeichnis) in das Spiele Verzeichnis.
bekannte Probleme: Guild Wars (Win XP)
2) Starte das Spiel direkt durch OTM über das Menü
"Einstellungen->Sarte Spiel durch OTM" oder
"Einstellungen->Sarte Spiel durch OTM (mit Kommandozeile)".
Das Spiel startet sofort.
3) Kopiere die d3d9.dll (vom OpenTexMod Verzeichnis) in das Spiele Verzeichnis.
Einige Spiele laden eine dll zuerst aus dem eigenen Verzeichnis bevor sie im
Systemverzeichnis suchen. Nur für diese Spiele wird diese Methode funktionieren.
WARNUNG: Kopiere diese dll niemals in das Systemverzeichnis!!
bekannte Probleme: Guild Wars
Wenn du dich für eine Methode entschieden hast, starte einfach OpenTexMod
und danach das Spiel. Es ist nicht nötig (du kannst auch nicht) das Spiel über
OpenTexMod zu starten.
Wenn du dich für die erste oder dritte Methode entschieden hast, starte einfach
OpenTexMod und danach das Spiel. Starte das Spiel in beiden Fällen NICHT über
OpenTexMod .
Wenn das Spiel startet und alles glatt läuft, öffnet sich sofort ein neuer Tab in OpenTexMod.
In diesem Tab kannst du nun das Spiel modden. Drücke den "Update" Button um
+15 -6
View File
@@ -55,19 +55,28 @@ was started more than once).
How to get OpenTexMod work?
There are two ways how OpenTexMod can intercept the DirectX connection:
There are three ways how OpenTexMod can intercept the DirectX connection:
(Do NOT use more than one method simultaneously!)
1) (recommended) Add the games-binary through the menu Games->"Add game"
1) Add the games-binary through the menu "Main->Add game"
For Steam see below.
known problems: Guild Wars (Win XP)
2) Start the game directly through OTM though the menu
"Main->Start game through OTM" or
"Main->Start game through OTM (with command line)".
The game start immediately.
2) Copy the d3d9.dll (from the OpenTexMod directory) into the game directory.
3) Copy the d3d9.dll (from the OpenTexMod directory) into the game directory.
Some games load a dll first from their own directory before they look up the system directory.
Only for these games this method will work.
WARNING: never copy this dll into your system directory!!
known problems: Guild Wars
If you have chosen one of the two methods, you simply start OpenTexMod
and afterwards the game. There is no need to (and either you can't) start
the game through OpenTexMod.
If you have chosen the first or third method, you simply start OpenTexMod
and afterwards the game. Do NOT start the game through OpenTexMod.
If the game starts and all works fine, a new tab opens immediately in OpenTexMod.
In this tab you can now mod the game. Press the "update" button to commit
@@ -18,8 +18,6 @@ this is a comment
|
Example:
Keyword:
Message1 line1
@@ -37,11 +35,16 @@ English itself is compiled into the OTM_GUI.exe, thus there exists no OTM_Langua
The following list is an example of how an English package would look like (maybe not all keywords are present).
MenuHelp:
Help|
MenuAbout:
About|
MenuAcknowledgement:Acknowledgement|
MenuStartGame:Start game through OTM|
MenuStartGameCMD :Start game through OTM (with command line)|
MenuUseHook:Use global hook|
MenuAddGame:
Add game|
MenuDeleteGame:
@@ -55,6 +58,8 @@ MenuExit:Exit|
MainMenuMain:Main|
MainMenuHelp:
Help|
ButtonOpen:
Open texture|
ButtonDirectory:
@@ -62,6 +67,8 @@ save directory|
ButtonUpdate:
Update|
ButtonReload:Update (reload)|
ChooseFile:Choose a file|
ChooseDir:
Choose a directory|
@@ -74,6 +81,8 @@ TextCtrlSavePath:
Save path: |
SelectLanguage:
Select a language|
StartGame:Select the game to start.|
CommandLine:Set command line arguments.|
ChooseGame:
Select a game binary.
DeleteGame:
@@ -87,6 +96,11 @@ NoComment:
No comment.|
Author:
Author: |
Error_GameIsHooked:The global hook is active and this game will be injected! Please delete the game from the list or disable the hook.|
Error_ProcessNotStarted:The game could not be started.|
Error_RemoveHook:Removing the Hook while a game is running might lead to crash.|
Error_FileNotSupported:
This file type is not supported:|
Error_DLLNotFound:
Binary file not shown.
Binary file not shown.
+7 -3
View File
@@ -32,6 +32,7 @@ MINIMAL_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG_2) $(__THREADSFLAG) \
MINIMAL_OBJECTS = \
$(OBJS)\OTM_rc.o \
$(OBJS)\unzip.o \
$(OBJS)\OTM_DirectInjection.o \
$(OBJS)\OTM_GUI.o \
$(OBJS)\OTM_GameInfo.o \
$(OBJS)\OTM_GamePage.o \
@@ -226,14 +227,14 @@ $(OBJS_exe):
### Targets: ###
all: $(OBJS_exe)\OTM_GUI.exe
all: $(OBJS_exe)\OpenTexMod.exe
clean:
-if exist $(OBJS)\*.o del $(OBJS)\*.o
-if exist $(OBJS)\*.d del $(OBJS)\*.d
-if exist $(OBJS_exe)\SeriesReminder.exe del $(OBJS_exe)\SeriesReminder.exe
-if exist $(OBJS_exe)\OpenTexMod.exe del $(OBJS_exe)\OpenTexMod.exe
$(OBJS_exe)\OTM_GUI.exe: $(MINIMAL_OBJECTS) $(OBJS)\OTM_rc.o
$(OBJS_exe)\OpenTexMod.exe: $(MINIMAL_OBJECTS) $(OBJS)\OTM_rc.o
$(CXX) -o $@ $(MINIMAL_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) $(__THREADSFLAG) -L$(LIBDIRNAME) -Wl,--subsystem,windows -mwindows $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG) -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) $(__GDIPLUS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32
$(OBJS)\OTM_rc.o: OTM.rc OTM.ico
@@ -242,6 +243,9 @@ $(OBJS)\OTM_rc.o: OTM.rc OTM.ico
$(OBJS)\unzip.o: ./unzip.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\OTM_DirectInjection.o: ./OTM_DirectInjection.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\OTM_GUI.o: ./OTM_GUI.cpp
$(CXX) -c -o $@ $(MINIMAL_CXXFLAGS) $(CPPDEPS) $<
+7 -3
View File
@@ -34,6 +34,7 @@ MINIMAL_CXXFLAGS = /M$(__RUNTIME_LIBS_10)$(__DEBUGRUNTIME_4) /DWIN32 \
$(CPPFLAGS) $(CXXFLAGS)
MINIMAL_OBJECTS = \
$(OBJS)\unzip.obj \
$(OBJS)\OTM_DirectInjection.obj \
$(OBJS)\OTM_GUI.obj \
$(OBJS)\OTM_GameInfo.obj \
$(OBJS)\OTM_GamePage.obj \
@@ -342,17 +343,17 @@ $(OBJS):
### Targets: ###
all: $(OBJS_exe)\OTM_GUI.exe
all: $(OBJS_exe)\OpenTexMod.exe
clean:
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
-if exist $(OBJS)\*.res del $(OBJS)\*.res
-if exist $(OBJS)\*.pch del $(OBJS)\*.pch
-if exist $(OBJS_exe)\OTM_GUI.exe del $(OBJS_exe)\OTM_GUI.exe
-if exist $(OBJS_exe)\OTM_GUI.exe del $(OBJS_exe)\OpenTexMod.exe
-if exist $(OBJS_exe)\OTM_GUI.ilk del $(OBJS_exe)\OTM_GUI.ilk
-if exist $(OBJS_exe)\OTM_GUI.pdb del $(OBJS_exe)\OTM_GUI.pdb
$(OBJS_exe)\OTM_GUI.exe: $(MINIMAL_OBJECTS) $(OBJS)\OTM_GUI.res
$(OBJS_exe)\OpenTexMod.exe: $(MINIMAL_OBJECTS) $(OBJS)\OTM_GUI.res
link /NOLOGO /OUT:$@ $(__DEBUGINFO_1) /pdb:"$(OBJS)\OTM_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
<<
@@ -366,6 +367,9 @@ $(OBJS)\OTM_GUI.res: OTM.rc
$(OBJS)\unzip.obj: .\unzip.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\unzip.cpp
$(OBJS)\OTM_DirectInjection.obj: .\OTM_DirectInjection.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\OTM_DirectInjection.cpp
$(OBJS)\OTM_GUI.obj: .\OTM_GUI.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MINIMAL_CXXFLAGS) .\OTM_GUI.cpp