preliminary result

This commit is contained in:
code@koerner-de.net
2012-04-04 19:10:38 +00:00
parent 56844968e4
commit d99107a919
11 changed files with 622 additions and 82 deletions
+3
View File
@@ -3,6 +3,8 @@
/.project -text
.settings/org.eclipse.cdt.codan.core.prefs -text
/README.txt -text
uMod_DX10/uMod_DX10_dll.cpp -text
uMod_DX10/uMod_DX10_dll.h -text
uMod_DX9/uMod_DX9_dll.cpp -text
uMod_DX9/uMod_DX9_dll.h -text
uMod_DX9/uMod_IDirect3D9.cpp -text
@@ -25,6 +27,7 @@ uMod_DXMain/makefile.gcc -text
uMod_DXMain/makefile.vc -text
uMod_DXMain/uMod_ArrayHandler.cpp -text
uMod_DXMain/uMod_ArrayHandler.h -text
uMod_DXMain/uMod_DX10_dll_HOOK_INJECTION.def -text
uMod_DXMain/uMod_DX9_dll_DIRECT_INJECTION.def -text
uMod_DXMain/uMod_DX9_dll_HOOK_INJECTION.def -text
uMod_DXMain/uMod_DX9_dll_NO_INJECTION.def -text
+405
View File
@@ -0,0 +1,405 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
/*
NEVER USE THIS CODE FOR ILLEGAL PURPOSE
*/
#define number_of_byte 5
#include "uMod_DX10_dll.h"
//#include "disasm-lib/cpu.c"
//#include "disasm-lib/disasm.c"
//#include "disasm-lib/disasm_x86.c"
//#include "disasm-lib/misc.c"
//#include "mhook-lib/mhook.cpp"
//#include "mhook-lib/mhook.h"
//#include "uMod_ID3D10Device.h"
//#include "uMod_ID3D10Device1.h"
//#include "uMod_IDXGISwapChain.h"
//#include "detours.h"
//#include "detourxs/detourxs/detourxs.h"
/*
#include "detourxs/detourxs/ADE32.cpp"
#include "detourxs/detourxs/detourxs.cpp"
*/
/*
* global variable which are not linked external
*/
HINSTANCE gl_hOriginal_DX10_Dll = NULL;
HINSTANCE gl_hOriginal_DX101_Dll = NULL;
typedef HRESULT (APIENTRY *D3D10CreateDeviceAndSwapChain_type)( IDXGIAdapter*, D3D10_DRIVER_TYPE, HMODULE, UINT, UINT, DXGI_SWAP_CHAIN_DESC*, IDXGISwapChain**, ID3D10Device**);
typedef HRESULT (APIENTRY *D3D10CreateDeviceAndSwapChain1_type)( IDXGIAdapter*, D3D10_DRIVER_TYPE, HMODULE, UINT, D3D10_FEATURE_LEVEL1, UINT, DXGI_SWAP_CHAIN_DESC*, IDXGISwapChain**, ID3D10Device1**);
#ifndef NO_INJECTION
D3D10CreateDeviceAndSwapChain_type D3D10CreateDeviceAndSwapChain_fn = NULL;
D3D10CreateDeviceAndSwapChain1_type D3D10CreateDeviceAndSwapChain1_fn = NULL;
#endif
/*
* global variable which are linked external
*/
void InitDX10(void)
{
LoadOriginal_DX10_Dll();
/*
HRESULT ret = E_OUTOFMEMORY;
//IDXGIAdapter Adap;#
D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain");
IDXGISwapChain *pIDXGISwapChain_orig = NULL;
ID3D10Device *pID3D10Device_orig = NULL;
if (D3D10CreateDeviceAndSwapChain_fn!=NULL)
{
Message("PRE: create original device\n");
ret = D3D10CreateDeviceAndSwapChain_fn( NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_SINGLETHREADED,
D3D10_SDK_VERSION, NULL, &pIDXGISwapChain_orig, &pID3D10Device_orig);
if (ret == S_OK )
{
Message("PRE: created\n");
pIDXGISwapChain_orig->Release();
pID3D10Device_orig->Release();
Message("PRE: released\n");
}
else
{
Message("PRE: failed\n");
}
}
else
{
Message("PRE: no function\n");
}
*/
#ifndef NO_INJECTION
// we detour the original D3D10CreateDeviceAndSwapChain to our uMod_D3D10CreateDeviceAndSwapChain
if (gl_hOriginal_DX10_Dll!=NULL)
{
D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) GetProcAddress(gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain");
if (D3D10CreateDeviceAndSwapChain_fn!=NULL)
{
Message("Detour: D3D10CreateDeviceAndSwapChain\n");
//D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain, number_of_byte);
//Mhook_SetHook((PVOID*)&D3D10CreateDeviceAndSwapChain_fn, uMod_D3D10CreateDeviceAndSwapChain);
D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) DetourFunction( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain);
//DetourTransactionBegin();
//Messagebox_orig = (Messagebox_typ)DetourAttach(&(PVOID&)MessageBoxA, (PVOID)MyMessageBox);
//D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) DetourAttach( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain);
//DetourTransactionCommit();
}
}
if (gl_hOriginal_DX101_Dll!=NULL)
{
//D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type) GetProcAddress(gl_hOriginal_DX101_Dll, "D3D10CreateDeviceAndSwapChain1");
if (D3D10CreateDeviceAndSwapChain1_fn!=NULL)
{
Message("Detour: D3D10CreateDeviceAndSwapChain1\n");
D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain1_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain1, 5);
}
}
#endif
}
void ExitDX10(void)
{
// Release the system's d3d9.dll
if (gl_hOriginal_DX10_Dll!=NULL)
{
FreeLibrary(gl_hOriginal_DX10_Dll);
gl_hOriginal_DX10_Dll = NULL;
}
if (gl_hOriginal_DX101_Dll!=NULL)
{
FreeLibrary(gl_hOriginal_DX101_Dll);
gl_hOriginal_DX101_Dll = NULL;
}
}
void LoadOriginal_DX10_Dll(void)
{
char buffer[MAX_PATH];
if (gl_hOriginal_DX10_Dll==NULL)
{
GetSystemDirectory(buffer,MAX_PATH); //get the system directory, we need to open the original d3d10.dll
// Append dll name
strcat_s( buffer, MAX_PATH,"\\d3d10.dll");
// try to load the system's d3d10.dll
gl_hOriginal_DX10_Dll = LoadLibrary(buffer);
}
if (gl_hOriginal_DX101_Dll==NULL)
{
GetSystemDirectory(buffer,MAX_PATH);
strcat_s( buffer, MAX_PATH,"\\d3d10_1.dll");
gl_hOriginal_DX101_Dll = LoadLibrary(buffer);
}
}
#ifdef NO_INJECTION
/*
* We do not inject, the game loads this dll by itself thus we must include the Direct3DCreate9 function
*/
/*
IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
{
Message("WINAPI Direct3DCreate9\n");
if (!gl_hOriginal_DX9_Dll) LoadOriginal_DX9_Dll(); // looking for the "right d3d9.dll"
// find original function in original d3d9.dll
Direct3DCreate9_type D3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginal_DX9_Dll, "Direct3DCreate9");
if (!D3DCreate9_fn)
{
Message("Direct3DCreate9: original function not found in dll\n");
return (NULL);
}
//Create originale IDirect3D9 object
IDirect3D9 *pIDirect3D9_orig = D3DCreate9_fn(SDKVersion);
//create our uMod_IDirect3D9 object
uMod_IDirect3D9 *pIDirect3D9 = new uMod_IDirect3D9( pIDirect3D9_orig, gl_TextureServer);
// Return pointer to our object instead of "real one"
return (pIDirect3D9);
}
HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **ppD3D)
{
Message("WINAPI Direct3DCreate9Ex\n");
if (!gl_hOriginal_DX9_Dll) LoadOriginal_DX9_Dll(); // looking for the "right d3d9.dll"
// find original function in original d3d9.dll
Direct3DCreate9Ex_type D3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginal_DX9_Dll, "Direct3DCreate9Ex");
if (!D3DCreate9Ex_fn)
{
Message("Direct3DCreate9Ex: original function not found in dll\n");
return (D3DERR_NOTAVAILABLE);
}
//Create originale IDirect3D9 object
IDirect3D9Ex *pIDirect3D9Ex_orig;
HRESULT ret = D3DCreate9Ex_fn( SDKVersion, &pIDirect3D9Ex_orig);
if (ret!=S_OK) return (ret);
//create our uMod_IDirect3D9 object
uMod_IDirect3D9Ex *pIDirect3D9Ex = new uMod_IDirect3D9Ex( pIDirect3D9Ex_orig, gl_TextureServer);
ppD3D = &pIDirect3D9Ex_orig; // Return pointer to our object instead of "real one"
return (ret);
}
typedef IDirect3D9 *(APIENTRY *Direct3DCreate9_type)(UINT);
typedef HRESULT (APIENTRY *Direct3DCreate9Ex_type)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
typedef int (WINAPI *D3DPERF_BeginEvent_type)( D3DCOLOR , LPCWSTR );
int WINAPI D3DPERF_BeginEvent( D3DCOLOR col, LPCWSTR wszName )
{
D3DPERF_BeginEvent_type fn = (D3DPERF_BeginEvent_type) GetProcAddress( gl_hOriginal_DX9_Dll, "D3DPERF_BeginEvent");
return fn( col, wszName);
}
typedef int (WINAPI *D3DPERF_EndEvent_type)( void );
int WINAPI D3DPERF_EndEvent( void )
{
D3DPERF_EndEvent_type fn = (D3DPERF_EndEvent_type) GetProcAddress( gl_hOriginal_DX9_Dll, "D3DPERF_EndEvent");
return fn();
}
typedef void (WINAPI *D3DPERF_SetMarker_type)( D3DCOLOR , LPCWSTR );
void WINAPI D3DPERF_SetMarker( D3DCOLOR col, LPCWSTR wszName )
{
D3DPERF_SetMarker_type fn = (D3DPERF_SetMarker_type) GetProcAddress( gl_hOriginal_DX9_Dll, "D3DPERF_SetMarker");
return fn( col, wszName);
}
typedef void (WINAPI *D3DPERF_SetRegion_type)( D3DCOLOR, LPCWSTR );
void WINAPI D3DPERF_SetRegion( D3DCOLOR col, LPCWSTR wszName )
{
D3DPERF_SetRegion_type fn = (D3DPERF_SetRegion_type) GetProcAddress( gl_hOriginal_DX9_Dll, "D3DPERF_SetRegion");
return fn( col, wszName);
}
typedef BOOL (WINAPI *D3DPERF_QueryRepeatFrame_type)( void );
BOOL WINAPI D3DPERF_QueryRepeatFrame( void )
{
D3DPERF_QueryRepeatFrame_type fn = (D3DPERF_QueryRepeatFrame_type) GetProcAddress( gl_hOriginal_DX9_Dll, "D3DPERF_QueryRepeatFrame");
return fn( );
}
typedef void (WINAPI *D3DPERF_SetOptions_type)( DWORD );
void WINAPI D3DPERF_SetOptions( DWORD dwOptions )
{
D3DPERF_SetOptions_type fn = (D3DPERF_SetOptions_type) GetProcAddress( gl_hOriginal_DX9_Dll, "D3DPERF_SetOptions");
return fn( dwOptions);
}
typedef DWORD (WINAPI *D3DPERF_GetStatus_type)( void );
DWORD WINAPI D3DPERF_GetStatus( void )
{
D3DPERF_GetStatus_type fn = (D3DPERF_GetStatus_type) GetProcAddress( gl_hOriginal_DX9_Dll, "D3DPERF_GetStatus");
return fn( );
}
*/
#else
/*
* We inject the dll into the game, thus we retour the original Direct3DCreate9 function to our MyDirect3DCreate9 function
*/
HRESULT uMod_D3D10CreateDeviceAndSwapChain(
IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
IDXGISwapChain **ppSwapChain,
ID3D10Device **ppDevice
)
{
Message("uMod_D3D10CreateDeviceAndSwapChain: bla original %lu, uMod %lu\n", D3D10CreateDeviceAndSwapChain_fn, uMod_D3D10CreateDeviceAndSwapChain);
// in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines
// but somehow, for me it only works, if I retour the function and calling afterward the original function
// BEGIN
//LoadOriginal_DX10_Dll();
//RetourFunc((BYTE*) GetProcAddress( gl_hOriginal_DX9_Dll, "Direct3DCreate9"), (BYTE*)Direct3DCreate9_fn, 5);
//Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginal_DX9_Dll, "Direct3DCreate9");
RetourFunc((BYTE*) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain"), (BYTE*)D3D10CreateDeviceAndSwapChain_fn, number_of_byte);
D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain");
// END
//DetourRemove( (BYTE*) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain"), (BYTE*)D3D10CreateDeviceAndSwapChain_fn);
//D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type) GetProcAddress( gl_hOriginal_DX10_Dll, "D3D10CreateDeviceAndSwapChain");
HRESULT ret = E_OUTOFMEMORY;
IDXGISwapChain *pIDXGISwapChain_orig = NULL;
ID3D10Device *pID3D10Device_orig = NULL;
if (D3D10CreateDeviceAndSwapChain_fn)
{
Message("create original device\n");
ret = D3D10CreateDeviceAndSwapChain_fn(pAdapter,DriverType,Software,Flags,SDKVersion,pSwapChainDesc, &pIDXGISwapChain_orig, &pID3D10Device_orig);
}
/*
uMod_IDirect3D9 *pIDirect3D9;
if (pIDirect3D9_orig)
{
pIDirect3D9 = new uMod_IDirect3D9( pIDirect3D9_orig, gl_TextureServer); //creating our uMod_IDirect3D9 object
}
*/
// we detour again
Message("detour again\n");
//D3D10CreateDeviceAndSwapChain_fn = (D3D10CreateDeviceAndSwapChain_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain, number_of_byte);
//*ppSwapChain = pIDXGISwapChain_orig;
//*ppDevice = pID3D10Device_orig;
Message("Fine\n");
return (ret);
}
HRESULT uMod_D3D10CreateDeviceAndSwapChain1(
IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
D3D10_FEATURE_LEVEL1 HardwareLevel,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
IDXGISwapChain **ppSwapChain,
ID3D10Device1 **ppDevice
)
{
Message("uMod_D3D10CreateDeviceAndSwapChain1: original %lu, uMod %lu\n", D3D10CreateDeviceAndSwapChain1_fn, uMod_D3D10CreateDeviceAndSwapChain1);
// in the Internet are many tutorials for detouring functions and all of them will work without the following 5 marked lines
// but somehow, for me it only works, if I retour the function and calling afterward the original function
// BEGIN
//LoadOriginal_DX10_Dll();
RetourFunc((BYTE*) GetProcAddress( gl_hOriginal_DX101_Dll, "D3D10CreateDeviceAndSwapChain1"), (BYTE*)D3D10CreateDeviceAndSwapChain1_fn, 5);
D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type) GetProcAddress( gl_hOriginal_DX101_Dll, "D3D10CreateDeviceAndSwapChain1");
// END
HRESULT ret = E_OUTOFMEMORY;
IDXGISwapChain *pIDXGISwapChain_orig = NULL;
ID3D10Device1 *pID3D10Device1_orig = NULL;
if (D3D10CreateDeviceAndSwapChain1_fn)
{
ret = D3D10CreateDeviceAndSwapChain1_fn(pAdapter,DriverType,Software,Flags,HardwareLevel,SDKVersion,pSwapChainDesc, &pIDXGISwapChain_orig, &pID3D10Device1_orig);
}
/*
uMod_IDirect3D9 *pIDirect3D9;
if (pIDirect3D9_orig)
{
pIDirect3D9 = new uMod_IDirect3D9( pIDirect3D9_orig, gl_TextureServer); //creating our uMod_IDirect3D9 object
}
*/
// we detour again
D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain1_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain1, 5);
//D3D10CreateDeviceAndSwapChain1_fn = (D3D10CreateDeviceAndSwapChain1_type)DetourFunc( (BYTE*)D3D10CreateDeviceAndSwapChain1_fn, (BYTE*)uMod_D3D10CreateDeviceAndSwapChain1, 5);
*ppSwapChain = pIDXGISwapChain_orig;
*ppDevice = pID3D10Device1_orig;
return (ret);
}
#endif
+57
View File
@@ -0,0 +1,57 @@
/*
This file is part of Universal Modding Engine.
Universal Modding Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Universal Modding Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef uMod_DX10_DLL_H_
#define uMod_DX10_DLL_H_
#include "../uMod_DXMain/uMod_Main.h"
void LoadOriginal_DX10_Dll(void);
void InitDX10();
void ExitDX10();
#ifndef NO_INJECTION
HRESULT uMod_D3D10CreateDeviceAndSwapChain(
IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
IDXGISwapChain **ppSwapChain,
ID3D10Device **ppDevice
);
HRESULT uMod_D3D10CreateDeviceAndSwapChain1(
IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
D3D10_FEATURE_LEVEL1 HardwareLevel,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
IDXGISwapChain **ppSwapChain,
ID3D10Device1 **ppDevice
);
#endif
#endif
+27 -24
View File
@@ -44,8 +44,8 @@ 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
Direct3DCreate9_type Direct3DCreate9_fn = NULL; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
Direct3DCreate9Ex_type Direct3DCreate9Ex_fn = NULL; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
#endif
@@ -61,18 +61,21 @@ void InitDX9(void)
#ifndef NO_INJECTION
// we detour the original Direct3DCreate9 to our MyDirect3DCreate9
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress(gl_hOriginal_DX9_Dll, "Direct3DCreate9");
if (Direct3DCreate9_fn!=NULL)
if (gl_hOriginal_DX9_Dll!=NULL)
{
Message("Detour: Direct3DCreate9\n");
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*)Direct3DCreate9_fn, (BYTE*)uMod_Direct3DCreate9, 5);
}
Direct3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress(gl_hOriginal_DX9_Dll, "Direct3DCreate9");
if (Direct3DCreate9_fn!=NULL)
{
Message("Detour: Direct3DCreate9\n");
Direct3DCreate9_fn = (Direct3DCreate9_type)DetourFunc( (BYTE*)Direct3DCreate9_fn, (BYTE*)uMod_Direct3DCreate9, 5);
}
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress(gl_hOriginal_DX9_Dll, "Direct3DCreate9Ex");
if (Direct3DCreate9Ex_fn!=NULL)
{
Message("Detour: Direct3DCreate9Ex\n");
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*)Direct3DCreate9Ex_fn, (BYTE*)uMod_Direct3DCreate9Ex, 7);
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress(gl_hOriginal_DX9_Dll, "Direct3DCreate9Ex");
if (Direct3DCreate9Ex_fn!=NULL)
{
Message("Detour: Direct3DCreate9Ex\n");
Direct3DCreate9Ex_fn = (Direct3DCreate9Ex_type)DetourFunc( (BYTE*)Direct3DCreate9Ex_fn, (BYTE*)uMod_Direct3DCreate9Ex, 7);
}
}
#endif
}
@@ -89,17 +92,15 @@ void ExitDX9(void)
void LoadOriginal_DX9_Dll(void)
{
char buffer[MAX_PATH];
GetSystemDirectory(buffer,MAX_PATH); //get the system directory, we need to open the original d3d9.dll
// Append dll name
strcat_s( buffer, MAX_PATH,"\\d3d9.dll");
// try to load the system's d3d9.dll, if pointer empty
if (!gl_hOriginal_DX9_Dll) gl_hOriginal_DX9_Dll = LoadLibrary(buffer);
if (!gl_hOriginal_DX9_Dll)
if (gl_hOriginal_DX9_Dll==NULL)
{
ExitProcess(0); // exit the hard way
GetSystemDirectory(buffer,MAX_PATH); //get the system directory, we need to open the original d3d9.dll
// Append dll name
strcat_s( buffer, MAX_PATH,"\\d3d9.dll");
// try to load the system's d3d9.dll
gl_hOriginal_DX9_Dll = LoadLibrary(buffer);
}
}
@@ -113,7 +114,8 @@ IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
{
Message("WINAPI Direct3DCreate9\n");
if (!gl_hOriginal_DX9_Dll) LoadOriginal_DX9_Dll(); // looking for the "right d3d9.dll"
if (gl_hOriginal_DX9_Dll==NULL) LoadOriginal_DX9_Dll(); // looking for the "original d3d9.dll"
if (gl_hOriginal_DX9_Dll==NULL) return (NULL);
// find original function in original d3d9.dll
Direct3DCreate9_type D3DCreate9_fn = (Direct3DCreate9_type) GetProcAddress( gl_hOriginal_DX9_Dll, "Direct3DCreate9");
@@ -140,7 +142,8 @@ HRESULT WINAPI Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **ppD3D)
{
Message("WINAPI Direct3DCreate9Ex\n");
if (!gl_hOriginal_DX9_Dll) LoadOriginal_DX9_Dll(); // looking for the "right d3d9.dll"
if (gl_hOriginal_DX9_Dll==NULL) LoadOriginal_DX9_Dll(); // looking for the "original d3d9.dll"
if (gl_hOriginal_DX9_Dll==NULL) return (NULL);
// find original function in original d3d9.dll
Direct3DCreate9Ex_type D3DCreate9Ex_fn = (Direct3DCreate9Ex_type) GetProcAddress( gl_hOriginal_DX9_Dll, "Direct3DCreate9Ex");
+19 -4
View File
@@ -59,9 +59,10 @@ endif
CXX = cl
CLINK = link.exe
DEFINES = /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS" $(DX_XX_Flag)
CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 ${DEFINES} ${precompiler_flag} /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t
#CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 ${DEFINES} ${precompiler_flag} /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t
CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 /Oi /Oy- /GL ${DEFINES} ${precompiler_flag} /Gm- /EHsc /MT /Gy- /fp:precise /Zc:wchar_t /Zc:forScope /Gd /TP /analyze-
LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" /DLL "Winmm.lib" "d3dx9.lib" "d3dx10.lib" "dxguid.lib" "user32.lib" "Kernel32.lib" ${def_file} /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE:NO /NXCOMPAT:NO /MACHINE:X86
#/nologo /W3 /WX- /O2 /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _WINDOWS /D _USRDLL /D D3DSTARTERKIT_EXPORTS /D _WINDLL /D _UNICODE /D UNICODE /Gm- /EHsc /MT /GS- /Gy- /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TP /analyze-
obj = obj
bin = bin
@@ -80,7 +81,16 @@ objects = \
${obj}\uMod_IDirect3DDevice9Ex.${obj_suff} \
${obj}\uMod_IDirect3DTexture9.${obj_suff} \
${obj}\uMod_IDirect3DVolumeTexture9.${obj_suff} \
${obj}\uMod_IDirect3DCubeTexture9.${obj_suff}
${obj}\uMod_IDirect3DCubeTexture9.${obj_suff} \
\
${obj}\uMod_DX10_dll.${obj_suff}
#\
#${obj}\cpu.obj \
#${obj}\disasm.obj \
#${obj}\disasm_x86.obj \
#${obj}\mhook.obj \
#${obj}\misc.obj
headers = uMod_Main.h \
uMod_DXMain_dll.h \
@@ -98,7 +108,9 @@ DX9_headers = \
..\uMod_DX9\uMod_IDirect3DTexture9.h \
..\uMod_DX9\uMod_IDirect3DVolumeTexture9.h \
..\uMod_DX9\uMod_IDirect3DCubeTexture9.h
DX10_headers = \
..\uMod_DX10\uMod_DX10_dll.h
${bin}\d3d9.dll: ${objects}
${CLINK} ${LFLAGS} ${objects} /OUT:${bin}\${dll}
@@ -149,5 +161,8 @@ ${obj}\uMod_IDirect3DCubeTexture9.${obj_suff}: ..\uMod_DX9\uMod_IDirect3DCubeTex
${CXX} ${CFLAGS} /c $< /Fo$@
${obj}\uMod_DX10_dll.${obj_suff}: ..\uMod_DX10\uMod_DX10_dll.cpp ${headers} ${DX10_headers}
${CXX} ${CFLAGS} /c $< /Fo$@
clean:
del ${objects} ${bin}\${dll}
@@ -0,0 +1,6 @@
LIBRARY "uMod_d3d10_Hook"
EXPORTS
uMod_D3D10CreateDeviceAndSwapChain @1
uMod_D3D10CreateDeviceAndSwapChain1 @2
InstallHook @3
RemoveHook @4
+88 -14
View File
@@ -97,7 +97,7 @@ void InitInstance(HINSTANCE hModule)
gl_hThisInstance = (HINSTANCE) hModule;
wchar_t game[MAX_PATH];
if (HookThisProgram( game)) //ask if we need to hook this program
if (HookThisProgram( game, MAX_PATH)) //ask if we need to hook this program
{
OpenMessage();
Message("InitInstance: %lu\n", hModule);
@@ -107,6 +107,9 @@ void InitInstance(HINSTANCE hModule)
#ifdef DEF_USE_DX9
InitDX9();
#endif
#ifdef DEF_USE_DX10
InitDX10();
#endif
if (gl_TextureServer->OpenPipe(game)) //open the pipe and send the name+path of this executable
@@ -141,25 +144,47 @@ void ExitInstance()
#ifdef DEF_USE_DX9
ExitDX9();
#endif
#ifdef DEF_USE_DX10
ExitDX10();
#endif
CloseMessage();
}
bool HookThisProgram( wchar_t *ret)
bool HookThisProgram( wchar_t *ret, const int ret_len)
{
wchar_t Executable[MAX_PATH];
wchar_t Game[MAX_PATH];
GetModuleFileNameW( GetModuleHandle( NULL ), Executable, MAX_PATH ); //ask for name and path of this executable
const unsigned int max_len = ret_len < MAX_PATH ? MAX_PATH : ret_len;
wchar_t *Executable = NULL;
wchar_t *Game = NULL;
if (GetMemory( Executable, max_len))
{
ret[0]=0;
return false;
}
if (GetMemory( Game, max_len))
{
delete [] Executable;
ret[0]=0;
return false;
}
GetModuleFileNameW( GetModuleHandle( NULL ), Executable, max_len ); //ask for name and path of this executable
#ifdef HOOK_INJECTION
//we use the gloabal hook
FILE* file;
wchar_t *app_path = _wgetenv( L"APPDATA"); //asc for the user application directory
wchar_t file_name[MAX_PATH];
swprintf_s( file_name, MAX_PATH, L"%ls\\%ls\\%ls", app_path, uMod_APP_DIR, uMod_APP_DX9);
wchar_t *file_name = NULL;
if (GetMemory( file_name, max_len))
{
delete [] Executable;
delete [] Game;
ret[0]=0;
return false;
}
swprintf_s( file_name, max_len, L"%ls\\%ls\\%ls", app_path, uMod_APP_DIR, uMod_APP_DX9);
if (_wfopen_s( &file, file_name, L"rt,ccs=UTF-16LE")) return (false); // open the file in utf-16 LE mode
@@ -170,48 +195,97 @@ bool HookThisProgram( wchar_t *ret)
{
//MessageBoxW( NULL, Game, L"test", 0);
int len = 0;
while (Game[len])
while (len<max_len-1 &&Game[len])
{
if (Game[len]==L'\r' || Game[len]==L'\n') {Game[len]=0; break;} //removing the new line symbols
len++;
}
if ( _wcsicmp( Executable, Game ) == 0 ) //compare both strings
{
for (int i=0; i<len; i++) ret[i] = Game[i];
for (int i=0; i<len && i<ret_len-1; i++) ret[i] = Game[i];
ret[len] = 0;
fclose(file);
delete [] Executable;
delete [] Game;
return (true);
}
}
}
delete [] Executable;
delete [] Game;
fclose(file);
return (false);
#else
// we inject directly
int i=0;
while ( Game[i]) {ret[i]=Game[i]; i++;}
while (i<max_len && i<ret_len-1 && Game[i]) {ret[i]=Game[i]; i++;}
ret[i]=0;
delete [] Executable;
delete [] Game;
return true;
#endif
}
#ifndef NO_INJECTION
/*
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback = 0;
VirtualProtect(jmp, len+5, PAGE_EXECUTE_READWRITE, &dwback); //This is the addition needed for Windows 7 RC
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
memset(src, 0x90, len);
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
}
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
}
*/
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback = 0;
//VirtualProtect(jmp, len+5, PAGE_EXECUTE_READWRITE, &dwback); //This is the addition needed for Windows 7 RC
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
//memset(src, 0x90, len);
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
}
/*
bool RetourFunc( BYTE *src, BYTE *restore, const int len )
{
DWORD dwback;
if(!VirtualProtect(src, len, PAGE_READWRITE, &dwback)) { return false; }
if(!memcpy(src, restore, len)) { return false; }
restore[0] = 0xE9;
*(DWORD*)(restore+1) = (DWORD)(src - restore) - 5;
if(!VirtualProtect(src, len, dwback, &dwback)) { return false; }
return true;
}
*/
bool RetourFunc(BYTE *src, BYTE *restore, const int len)
{
DWORD dwback;
+5 -1
View File
@@ -25,10 +25,14 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
#include "../uMod_DX9/uMod_DX9_dll.h"
#endif
#ifdef DEF_USE_DX10
#include "../uMod_DX10/uMod_DX10_dll.h"
#endif
void InitInstance(HINSTANCE hModule);
void ExitInstance(void);
bool HookThisProgram( wchar_t *ret);
bool HookThisProgram( wchar_t *ret, const int max_len);
DWORD WINAPI ServerThread( LPVOID lpParam);
+7 -1
View File
@@ -37,11 +37,17 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
#include <d3d9.h>
#include <d3dx9.h>
#include <d3d10_1.h>
#include <d3d10.h>
#include <D3D10Misc.h>
#include <d3dx10.h>
//#include "detours.h"
#include "../uMod_GlobalDefines.h"
#include "../uMod_Error.h"
#include "../uMod_Utils.h"
#include "uMod_Defines.h"
#include "uMod_DXMain_dll.h"
//#include "uMod_TextureFunction.h"
+4 -2
View File
@@ -636,7 +636,8 @@ void uMod_Frame::OnMenuStartGame(wxCommandEvent& event)
wxString dll = wxGetCwd();
dll.Append( L"\\" uMod_d3d9_DI_dll);
//dll.Append( L"\\" uMod_d3d9_DI_dll);
dll.Append( L"\\uMod_d3d10_DI.dll");
Inject(pi.hProcess, dll.wc_str(), "Nothing");
ResumeThread(pi.hThread);
@@ -962,7 +963,8 @@ void uMod_Frame::InstallHook(void)
{
if (H_DX9_DLL==NULL)
{
H_DX9_DLL = LoadLibraryW(uMod_d3d9_Hook_dll);
//H_DX9_DLL = LoadLibraryW(uMod_d3d9_Hook_dll);
H_DX9_DLL = LoadLibraryW(L"uMod_d3d10_HI.dll");
if (H_DX9_DLL!=NULL)
{
typedef void (*fkt_typ)(void);
+1 -36
View File
@@ -69,6 +69,7 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
#include "../uMod_GlobalDefines.h"
#include "../uMod_Error.h"
#include "../uMod_Utils.h"
class uMod_Frame;
@@ -120,40 +121,4 @@ enum
#include "uMod_DirectInjection.h"
#include "uMod_GUI.h"
template <class T>
int GetMemory(T* &array, int num)
{
if (array!=(T*)0) delete [] array;
try {array = new T[num];}
catch (...) {array = (T*) 0; return -1;}
return 0;
}
template <class T>
int GetMemory(T* &array, int num, T init)
{
if (array!=(T*)0) delete [] array;
try {array = new T[num];}
catch (...) {array = (T*) 0; return -1;}
for (int i=0; i<num; i++) array[i]=init;
return 0;
}
template <class T>
int GetMoreMemory(T* &old_array, int old_num, int new_num)
{
if (new_num<=old_num) return 0;
T* new_array;
try {new_array = new T[new_num];}
catch (...) {return -1;}
if (old_array!=(T*)0)
{
for (int i=0; i<old_num; i++) new_array[i]=old_array[i];
delete [] old_array;
}
old_array = new_array;
return 0;
}
#endif