mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-24 03:56:34 +00:00
uMod2 Alpha Version: known bugs: I disabled the remove device function inside the gui, because something in the event handling goes terrible wrong.
Implemented a some new features.
This commit is contained in:
@@ -28,13 +28,8 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "uMod_DX9_dll.h"
|
||||
#include "uMod_IDirect3D9.h"
|
||||
#include "uMod_IDirect3D9Ex.h"
|
||||
//#include "detours.h"
|
||||
//#include "detourxs/detourxs/detourxs.h"
|
||||
|
||||
/*
|
||||
#include "detourxs/detourxs/ADE32.cpp"
|
||||
#include "detourxs/detourxs/detourxs.cpp"
|
||||
*/
|
||||
|
||||
/*
|
||||
* global variable which are not linked external
|
||||
*/
|
||||
@@ -43,7 +38,7 @@ HINSTANCE gl_hOriginal_DX9_Dll = NULL;
|
||||
typedef IDirect3D9 *(APIENTRY *Direct3DCreate9_type)(UINT);
|
||||
typedef HRESULT (APIENTRY *Direct3DCreate9Ex_type)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
|
||||
|
||||
#ifndef NO_INJECTION
|
||||
#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION
|
||||
Direct3DCreate9_type Direct3DCreate9_fn = NULL; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
|
||||
Direct3DCreate9Ex_type Direct3DCreate9Ex_fn = NULL; // we need to store the pointer to the original Direct3DCreate9 function after we have done a detour
|
||||
#endif
|
||||
@@ -59,7 +54,7 @@ void InitDX9(void)
|
||||
{
|
||||
LoadOriginal_DX9_Dll();
|
||||
|
||||
#ifndef NO_INJECTION
|
||||
#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION
|
||||
// we detour the original Direct3DCreate9 to our MyDirect3DCreate9
|
||||
if (gl_hOriginal_DX9_Dll!=NULL)
|
||||
{
|
||||
@@ -89,6 +84,7 @@ void ExitDX9(void)
|
||||
gl_hOriginal_DX9_Dll = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadOriginal_DX9_Dll(void)
|
||||
{
|
||||
char buffer[MAX_PATH];
|
||||
@@ -105,7 +101,7 @@ void LoadOriginal_DX9_Dll(void)
|
||||
}
|
||||
|
||||
|
||||
#ifdef NO_INJECTION
|
||||
#if INJECTION_METHOD==NO_INJECTION
|
||||
/*
|
||||
* We do not inject, the game loads this dll by itself thus we must include the Direct3DCreate9 function
|
||||
*/
|
||||
@@ -220,8 +216,9 @@ DWORD WINAPI D3DPERF_GetStatus( void )
|
||||
return fn( );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION
|
||||
|
||||
/*
|
||||
* We inject the dll into the game, thus we retour the original Direct3DCreate9 function to our MyDirect3DCreate9 function
|
||||
|
||||
+19
-1
@@ -23,13 +23,31 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "../uMod_DXMain/uMod_Main.h"
|
||||
|
||||
/**
|
||||
* Load the official d3d9.dll from the system path.
|
||||
*/
|
||||
void LoadOriginal_DX9_Dll(void);
|
||||
|
||||
/**
|
||||
* Initialize dx9 -> loads d3d9.dll and set detour if this dll is compiled for "Direct Injection" or "Hook Injection"
|
||||
*/
|
||||
void InitDX9();
|
||||
|
||||
/**
|
||||
* Unload the d3d9.dll
|
||||
*/
|
||||
void ExitDX9();
|
||||
|
||||
#ifndef NO_INJECTION
|
||||
#if INJECTION_METHOD==DIRECT_INJECTION || INJECTION_METHOD==HOOK_INJECTION
|
||||
|
||||
/**
|
||||
* Direct3DCreate9 function must be exported if compiled for "No Injection"
|
||||
*/
|
||||
IDirect3D9 *APIENTRY uMod_Direct3DCreate9(UINT SDKVersion);
|
||||
|
||||
/**
|
||||
* Direct3DCreate9Ex function must be exported if compiled for "No Injection"
|
||||
*/
|
||||
HRESULT APIENTRY uMod_Direct3DCreate9Ex( UINT SDKVersion, IDirect3D9Ex **ppD3D);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -239,15 +239,12 @@ HRESULT APIENTRY uMod_IDirect3DCubeTexture9::UnlockRect( D3DCUBEMAP_FACES FaceTy
|
||||
|
||||
|
||||
|
||||
int uMod_IDirect3DCubeTexture9::GetHash(MyTypeHash &hash)
|
||||
int uMod_IDirect3DCubeTexture9::ComputetHash( bool compute_crc)
|
||||
{
|
||||
hash=0u;
|
||||
if (FAKE) return (RETURN_BAD_ARGUMENT);
|
||||
IDirect3DCubeTexture9 *pTexture = m_D3Dtex;
|
||||
if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex;
|
||||
|
||||
//IDirect3DSurface9 *pOffscreenSurface = NULL;
|
||||
//IDirect3DCubeTexture9 *pOffscreenTexture = NULL;
|
||||
IDirect3DSurface9 *pResolvedSurface = NULL;
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
D3DSURFACE_DESC desc;
|
||||
@@ -257,110 +254,72 @@ int uMod_IDirect3DCubeTexture9::GetHash(MyTypeHash &hash)
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetLevelDesc \n");
|
||||
return (RETURN_GetLevelDesc_FAILED);
|
||||
}
|
||||
int bits_per_pixel = GetBitsFromFormat( desc.Format);
|
||||
unsigned int size;
|
||||
unsigned int h_max = desc.Height;
|
||||
if (desc.Format == D3DFMT_DXT1) // 8 bytes per block
|
||||
{
|
||||
h_max /= 4; // divided by block size
|
||||
size = desc.Width*2; // desc.Width/4 * 8
|
||||
}
|
||||
else if ( desc.Format==D3DFMT_DXT2 || desc.Format==D3DFMT_DXT3 || desc.Format==D3DFMT_DXT4 || desc.Format==D3DFMT_DXT5 ) // 16 bytes per block
|
||||
{
|
||||
h_max /= 4; // divided by block size
|
||||
size = desc.Width*4; // desc.Width/4 * 16
|
||||
}
|
||||
else size = (bits_per_pixel * desc.Width)/8;
|
||||
|
||||
Hash = HASH_INIT_VALUE;
|
||||
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() (%d %d) %d\n", desc.Width, desc.Height, desc.Format);
|
||||
|
||||
/*
|
||||
if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture
|
||||
for (int site = 0; site<6; site++)
|
||||
{
|
||||
//Message("uMod_IDirect3DCubeTexture9::GetHash() (D3DPOOL_DEFAULT)\n");
|
||||
|
||||
IDirect3DSurface9 *pSurfaceLevel_orig = NULL;
|
||||
if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK)
|
||||
if (pTexture->LockRect( ( _D3DCUBEMAP_FACES) site, 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
|
||||
{
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
|
||||
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE)
|
||||
{
|
||||
//Message("uMod_IDirect3DCubeTexture9::GetHash() MultiSampleType\n");
|
||||
if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL ))
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 1\n");
|
||||
if (pTexture->GetCubeMapSurface( ( _D3DCUBEMAP_FACES) site, 0, &pResolvedSurface)!=D3D_OK)
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n");
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE ))
|
||||
if (pResolvedSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n");
|
||||
pResolvedSurface->Release();
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 2\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
|
||||
pSurfaceLevel_orig = pResolvedSurface;
|
||||
}
|
||||
|
||||
|
||||
if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL))
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_TEXTURE_NOT_LOADED);
|
||||
unsigned char *data = (unsigned char*) d3dlr.pBits;
|
||||
|
||||
for (unsigned int h=0; h<h_max; h++)
|
||||
{
|
||||
GetHash( data, size, Hash);
|
||||
data += d3dlr.Pitch;
|
||||
}
|
||||
}
|
||||
|
||||
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
|
||||
if (compute_crc && site==0)
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
pOffscreenSurface->Release();
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
int size = (bits_per_pixel * desc.Width*desc.Height)/8;
|
||||
CRC = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
|
||||
}
|
||||
pSurfaceLevel_orig->Release();
|
||||
|
||||
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
|
||||
{
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
pOffscreenSurface->Release();
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
if (pTexture->LockRect( D3DCUBEMAP_FACE_POSITIVE_X, 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
|
||||
{
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 1\n");
|
||||
if (pTexture->GetCubeMapSurface( D3DCUBEMAP_FACE_POSITIVE_X, 0, &pResolvedSurface)!=D3D_OK)
|
||||
{
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: GetSurfaceLevel\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
if (pResolvedSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
|
||||
if (pResolvedSurface!=NULL)
|
||||
{
|
||||
pResolvedSurface->UnlockRect();
|
||||
pResolvedSurface->Release();
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() Failed: LockRect 2\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
pResolvedSurface=NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
pTexture->UnlockRect( ( _D3DCUBEMAP_FACES) site, 0); //unlock the raw data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height)/8;
|
||||
|
||||
hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
|
||||
/*
|
||||
if (pOffscreenSurface!=NULL)
|
||||
{
|
||||
pOffscreenSurface->UnlockRect();
|
||||
pOffscreenSurface->Release();
|
||||
//pOffscreenTexture->Release();
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
}
|
||||
else
|
||||
*/
|
||||
if (pResolvedSurface!=NULL)
|
||||
{
|
||||
pResolvedSurface->UnlockRect();
|
||||
pResolvedSurface->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
pTexture->UnlockRect( D3DCUBEMAP_FACE_POSITIVE_X, 0); //unlock the raw data
|
||||
}
|
||||
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
|
||||
Message("uMod_IDirect3DCubeTexture9::GetHash() %#llX %#LX (%d %d) %d\n", Hash, CRC, desc.Width, desc.Height, desc.Format);
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "..\uMod_DXMain\uMod_Defines.h"
|
||||
|
||||
|
||||
|
||||
interface uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9
|
||||
class uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9
|
||||
{
|
||||
public:
|
||||
uMod_IDirect3DCubeTexture9(IDirect3DCubeTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9)
|
||||
{
|
||||
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
|
||||
@@ -47,16 +47,17 @@ interface uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9
|
||||
// thus the fake texture can also be deleted
|
||||
Reference = -1; //need for fast deleting
|
||||
Hash = 0u;
|
||||
CRC = 0u;
|
||||
FAKE = false;
|
||||
}
|
||||
|
||||
// callback interface
|
||||
IDirect3DCubeTexture9 *m_D3Dtex;
|
||||
uMod_IDirect3DCubeTexture9 *CrossRef_D3Dtex;
|
||||
IDirect3DDevice9 *m_D3Ddev;
|
||||
int Reference;
|
||||
MyTypeHash Hash;
|
||||
bool FAKE;
|
||||
IDirect3DCubeTexture9 *m_D3Dtex; //!< pointer to the real IDirect3DCubeTexture9 object
|
||||
uMod_IDirect3DCubeTexture9 *CrossRef_D3Dtex; //!< cross reference from the fake texture to the game texture and vice versa
|
||||
IDirect3DDevice9 *m_D3Ddev; //!< pointer to the device
|
||||
int Reference; //!< Index in the vector (needed for a fast delete).
|
||||
DWORD64 Hash; //!< computed hash value for this game texture.
|
||||
DWORD32 CRC; //!< computed crc32 value for this game texture.
|
||||
bool FAKE; //!< True if this texture is was loaded by uMod (fake texture)
|
||||
|
||||
// original interface
|
||||
STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj);
|
||||
@@ -84,7 +85,7 @@ interface uMod_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9
|
||||
STDMETHOD(UnlockRect)(D3DCUBEMAP_FACES FaceType, UINT Level);
|
||||
|
||||
|
||||
int GetHash(MyTypeHash &hash);
|
||||
int ComputetHash( bool compute_crc);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -62,9 +62,15 @@ int uMod_IDirect3DDevice9::CreateSingleTexture(void)
|
||||
SingleTexture=NULL;
|
||||
return (RETURN_TEXTURE_NOT_LOADED);
|
||||
}
|
||||
DWORD *pDst = (DWORD*)d3dlr.pBits;
|
||||
|
||||
for (int i=0; i<8*8; i++) pDst[i] = TextureColour;
|
||||
Message( PRE_MESSAGE "::CreateSingleTexture(): Set IDirect3DTexture9 Colour to %#X\n", TextureColour);
|
||||
BYTE *pImage = (BYTE*)d3dlr.pBits;
|
||||
for (int i=0; i<8; i++)
|
||||
{
|
||||
DWORD *pDst = (DWORD*)pImage;
|
||||
for (int j=0;j<8; j++) pDst[j] = TextureColour;
|
||||
pImage += d3dlr.Pitch;
|
||||
}
|
||||
pD3Dtex->UnlockRect(0);
|
||||
}
|
||||
|
||||
@@ -92,9 +98,14 @@ int uMod_IDirect3DDevice9::CreateSingleTexture(void)
|
||||
SingleVolumeTexture=NULL;
|
||||
return (RETURN_TEXTURE_NOT_LOADED);
|
||||
}
|
||||
DWORD *pDst = (DWORD*)d3dlr.pBits;
|
||||
|
||||
for (int i=0; i<8*8*8; i++) pDst[i] = TextureColour;
|
||||
Message( PRE_MESSAGE "::CreateSingleTexture(): Set IDirect3DVolumeTexture9 Colour to %#X\n", TextureColour);
|
||||
DWORD *pDst = (DWORD*)d3dlr.pBits;
|
||||
for (int i=0; i<8; i++) for (int ii=0; ii<8; ii++)
|
||||
{
|
||||
DWORD *pDst = (DWORD*) ((char*) d3dlr.pBits)[ i*d3dlr.SlicePitch + ii*d3dlr.RowPitch];
|
||||
//for (int j=0;j<8; j++) pDst[j] = TextureColour;
|
||||
}
|
||||
pD3Dtex->UnlockBox(0);
|
||||
}
|
||||
if (SingleCubeTexture==NULL) //create texture
|
||||
@@ -114,6 +125,7 @@ int uMod_IDirect3DDevice9::CreateSingleTexture(void)
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
IDirect3DCubeTexture9 *pD3Dtex = SingleCubeTexture->m_D3Dtex;
|
||||
|
||||
Message( PRE_MESSAGE "::CreateSingleTexture(): Set IDirect3DCubeTexture9 Colour to %#X\n", TextureColour);
|
||||
for (int c=0; c<6; c++)
|
||||
{
|
||||
if (D3D_OK!=pD3Dtex->LockRect( (D3DCUBEMAP_FACES) c, 0, &d3dlr, 0, 0))
|
||||
@@ -123,9 +135,14 @@ int uMod_IDirect3DDevice9::CreateSingleTexture(void)
|
||||
SingleCubeTexture=NULL;
|
||||
return (RETURN_TEXTURE_NOT_LOADED);
|
||||
}
|
||||
DWORD *pDst = (DWORD*)d3dlr.pBits;
|
||||
|
||||
for (int i=0; i<8*8; i++) pDst[i] = TextureColour;
|
||||
BYTE *pImage = (BYTE*)d3dlr.pBits;
|
||||
for (int i=0; i<8; i++)
|
||||
{
|
||||
DWORD *pDst = (DWORD*)pImage;
|
||||
for (int j=0;j<8; j++) pDst[j] = TextureColour;
|
||||
pImage += d3dlr.Pitch;
|
||||
}
|
||||
pD3Dtex->UnlockRect((D3DCUBEMAP_FACES)c, 0);
|
||||
}
|
||||
}
|
||||
@@ -148,7 +165,6 @@ uMod_IDirect3DDevice9::uMod_IDirect3DDevice9( IDirect3DDevice9* pOriginal, uMod_
|
||||
LastCreatedVolumeTexture = NULL;
|
||||
LastCreatedCubeTexture = NULL;
|
||||
m_pIDirect3DDevice9 = pOriginal; // store the pointer to original object
|
||||
TextureColour = D3DCOLOR_ARGB(255,0,255,0);
|
||||
|
||||
CounterSaveSingleTexture = -20;
|
||||
|
||||
@@ -425,13 +441,13 @@ HRESULT uMod_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTextu
|
||||
{
|
||||
case 0x01000000L:
|
||||
{
|
||||
MyTypeHash hash;
|
||||
pSource = (uMod_IDirect3DTexture9*)(pSourceTexture);
|
||||
if (pSource->GetHash( hash) == RETURN_OK)
|
||||
DWORD64 hash = pSource->Hash;
|
||||
DWORD32 crc = pSource->CRC;
|
||||
if (pSource->ComputetHash( crc>0 ) == RETURN_OK)
|
||||
{
|
||||
if (hash != pSource->Hash) // this hash has changed !!
|
||||
if (hash != pSource->Hash || (crc>0 && crc != pSource->CRC) ) // this hash has changed !!
|
||||
{
|
||||
pSource->Hash = hash;
|
||||
if (pSource->CrossRef_D3Dtex!=NULL) UnswitchTextures(pSource);
|
||||
uMod_Client->LookUpToMod( pSource);
|
||||
}
|
||||
@@ -445,11 +461,12 @@ HRESULT uMod_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTextu
|
||||
}
|
||||
case 0x01000001L:
|
||||
{
|
||||
MyTypeHash hash;
|
||||
pSourceVolume = (uMod_IDirect3DVolumeTexture9*)(pSourceTexture);
|
||||
if (pSourceVolume->GetHash( hash) == RETURN_OK)
|
||||
DWORD64 hash = pSourceVolume->Hash;
|
||||
DWORD32 crc = pSourceVolume->CRC;
|
||||
if (pSourceVolume->ComputetHash( crc>0 ) == RETURN_OK)
|
||||
{
|
||||
if (hash != pSourceVolume->Hash) // this hash has changed !!
|
||||
if (hash != pSourceVolume->Hash || (crc>0 && crc != pSource->CRC) ) // this hash has changed !!
|
||||
{
|
||||
pSourceVolume->Hash = hash;
|
||||
if (pSourceVolume->CrossRef_D3Dtex!=NULL) UnswitchTextures(pSourceVolume);
|
||||
@@ -465,11 +482,12 @@ HRESULT uMod_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTextu
|
||||
}
|
||||
case 0x01000002L:
|
||||
{
|
||||
MyTypeHash hash;
|
||||
pSourceCube = (uMod_IDirect3DCubeTexture9*)(pSourceTexture);
|
||||
if (pSourceCube->GetHash( hash) == RETURN_OK)
|
||||
DWORD64 hash = pSourceCube->Hash;
|
||||
DWORD32 crc = pSourceCube->CRC;
|
||||
if (pSourceCube->ComputetHash( crc>0 ) == RETURN_OK)
|
||||
{
|
||||
if (hash != pSourceCube->Hash) // this hash has changed !!
|
||||
if (hash != pSourceCube->Hash || (crc>0 && crc != pSource->CRC) ) // this hash has changed !!
|
||||
{
|
||||
pSourceCube->Hash = hash;
|
||||
if (pSourceCube->CrossRef_D3Dtex!=NULL) UnswitchTextures(pSourceCube);
|
||||
@@ -491,7 +509,7 @@ HRESULT uMod_IDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTextu
|
||||
|
||||
if (pDestinationTexture != NULL)
|
||||
{
|
||||
long int ret = pSourceTexture->QueryInterface( IID_IDirect3D9, (void**) &cpy);
|
||||
long int ret = pDestinationTexture->QueryInterface( IID_IDirect3D9, (void**) &cpy);
|
||||
switch (ret)
|
||||
{
|
||||
case 0x01000000L:
|
||||
@@ -763,7 +781,7 @@ HRESULT uMod_IDirect3DDevice9::BeginScene(void)
|
||||
|
||||
HRESULT uMod_IDirect3DDevice9::EndScene(void)
|
||||
{
|
||||
if ( NormalRendering && uMod_Client->BoolSaveSingleTexture && SingleTexture!=NULL && SingleVolumeTexture!=NULL && SingleCubeTexture!=NULL)
|
||||
if ( NormalRendering && uMod_Client->BoolShowTextureString && uMod_Client->BoolSaveSingleTexture && SingleTexture!=NULL && SingleVolumeTexture!=NULL && SingleCubeTexture!=NULL)
|
||||
{
|
||||
if (OSD_Font==NULL) // create the font
|
||||
{
|
||||
@@ -780,7 +798,7 @@ HRESULT uMod_IDirect3DDevice9::EndScene(void)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (SingleTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "normal texture: %4d (1..%d): %#lX", CounterSaveSingleTexture+1, uMod_Client->OriginalTextures.GetNumber(), SingleTexture->Hash);
|
||||
if (SingleTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "normal texture: %4d (1..%d): %#llX", CounterSaveSingleTexture+1, uMod_Client->OriginalTextures.GetNumber(), SingleTexture->Hash);
|
||||
else
|
||||
{
|
||||
if (uMod_Client->OriginalTextures.GetNumber()>0) sprintf_s( buffer, 100, "normal texture: nothing selected (1..%d)", uMod_Client->OriginalTextures.GetNumber());
|
||||
@@ -790,7 +808,7 @@ HRESULT uMod_IDirect3DDevice9::EndScene(void)
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if (SingleVolumeTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "volume texture: %4d (1..%d): %#lX", CounterSaveSingleTexture+1, uMod_Client->OriginalVolumeTextures.GetNumber(), SingleVolumeTexture->Hash);
|
||||
if (SingleVolumeTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "volume texture: %4d (1..%d): %#llX", CounterSaveSingleTexture+1, uMod_Client->OriginalVolumeTextures.GetNumber(), SingleVolumeTexture->Hash);
|
||||
else
|
||||
{
|
||||
if (uMod_Client->OriginalVolumeTextures.GetNumber()>0) sprintf_s( buffer, 100, "volume texture: nothing selected (1..%d)", uMod_Client->OriginalVolumeTextures.GetNumber());
|
||||
@@ -800,7 +818,7 @@ HRESULT uMod_IDirect3DDevice9::EndScene(void)
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (SingleCubeTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "cube texture: %4d (1..%d): %#lX", CounterSaveSingleTexture+1, uMod_Client->OriginalCubeTextures.GetNumber(), SingleCubeTexture->Hash);
|
||||
if (SingleCubeTexture->CrossRef_D3Dtex!=NULL) sprintf_s( buffer, 100, "cube texture: %4d (1..%d): %#llX", CounterSaveSingleTexture+1, uMod_Client->OriginalCubeTextures.GetNumber(), SingleCubeTexture->Hash);
|
||||
else
|
||||
{
|
||||
if (uMod_Client->OriginalCubeTextures.GetNumber()>0) sprintf_s( buffer, 100, "cube texture: nothing selected (1..%d)", uMod_Client->OriginalCubeTextures.GetNumber());
|
||||
|
||||
@@ -240,9 +240,8 @@ HRESULT APIENTRY uMod_IDirect3DTexture9::AddDirtyRect(CONST RECT* pDirtyRect)
|
||||
}
|
||||
|
||||
|
||||
int uMod_IDirect3DTexture9::GetHash(MyTypeHash &hash)
|
||||
int uMod_IDirect3DTexture9::ComputetHash( bool compute_crc)
|
||||
{
|
||||
hash=0u;
|
||||
if (FAKE) return (RETURN_BAD_ARGUMENT);
|
||||
IDirect3DTexture9 *pTexture = m_D3Dtex;
|
||||
if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex;
|
||||
@@ -342,9 +341,37 @@ int uMod_IDirect3DTexture9::GetHash(MyTypeHash &hash)
|
||||
}
|
||||
}
|
||||
|
||||
int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height)/8;
|
||||
int bits_per_pixel = GetBitsFromFormat( desc.Format);
|
||||
|
||||
hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
|
||||
{
|
||||
Hash = HASH_INIT_VALUE;
|
||||
unsigned char *data = (unsigned char*) d3dlr.pBits;
|
||||
unsigned int size;
|
||||
unsigned int h_max = desc.Height;
|
||||
if (desc.Format == D3DFMT_DXT1) // 8 bytes per block
|
||||
{
|
||||
h_max /= 4; // divided by block size
|
||||
size = desc.Width*2; // desc.Width/4 * 8
|
||||
}
|
||||
else if ( desc.Format==D3DFMT_DXT2 || desc.Format==D3DFMT_DXT3 || desc.Format==D3DFMT_DXT4 || desc.Format==D3DFMT_DXT5 ) // 16 bytes per block
|
||||
{
|
||||
h_max /= 4; // divided by block size
|
||||
size = desc.Width*4; // desc.Width/4 * 16
|
||||
}
|
||||
else size = (bits_per_pixel * desc.Width)/8;
|
||||
|
||||
for (unsigned int h=0; h<h_max; h++)
|
||||
{
|
||||
GetHash( data, size, Hash);
|
||||
data += d3dlr.Pitch;
|
||||
}
|
||||
}
|
||||
|
||||
if (compute_crc)
|
||||
{
|
||||
int size = (bits_per_pixel * desc.Width*desc.Height)/8;
|
||||
CRC = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
|
||||
}
|
||||
|
||||
if (pOffscreenSurface!=NULL)
|
||||
{
|
||||
@@ -359,6 +386,6 @@ int uMod_IDirect3DTexture9::GetHash(MyTypeHash &hash)
|
||||
}
|
||||
else pTexture->UnlockRect(0);
|
||||
|
||||
Message("uMod_IDirect3DTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
|
||||
Message("uMod_IDirect3DTexture9::GetHash() %#llX %#LX (%d %d) %d\n", Hash, CRC, desc.Width, desc.Height, desc.Format);
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
@@ -35,8 +35,9 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
|
||||
|
||||
interface uMod_IDirect3DTexture9 : public IDirect3DTexture9
|
||||
class uMod_IDirect3DTexture9 : public IDirect3DTexture9
|
||||
{
|
||||
public:
|
||||
uMod_IDirect3DTexture9(IDirect3DTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9)
|
||||
{
|
||||
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
|
||||
@@ -47,16 +48,17 @@ interface uMod_IDirect3DTexture9 : public IDirect3DTexture9
|
||||
// thus the fake texture can also be deleted
|
||||
Reference = -1; //need for fast deleting
|
||||
Hash = 0u;
|
||||
CRC = 0u;
|
||||
FAKE = false;
|
||||
}
|
||||
|
||||
// callback interface
|
||||
IDirect3DTexture9 *m_D3Dtex;
|
||||
uMod_IDirect3DTexture9 *CrossRef_D3Dtex;
|
||||
IDirect3DDevice9 *m_D3Ddev;
|
||||
int Reference;
|
||||
MyTypeHash Hash;
|
||||
bool FAKE;
|
||||
IDirect3DTexture9 *m_D3Dtex; //!< pointer to the real IDirect3DCubeTexture9 object
|
||||
uMod_IDirect3DTexture9 *CrossRef_D3Dtex; //!< cross reference from the fake texture to the game texture and vice versa
|
||||
IDirect3DDevice9 *m_D3Ddev; //!< pointer to the device
|
||||
int Reference; //!< Index in the vector (needed for a fast delete).
|
||||
DWORD64 Hash; //!< computed hash value for this game texture.
|
||||
DWORD32 CRC; //!< computed crc32 value for this game texture.
|
||||
bool FAKE; //!< True if this texture is was loaded by uMod (fake texture)
|
||||
|
||||
// original interface
|
||||
STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj);
|
||||
@@ -82,7 +84,7 @@ interface uMod_IDirect3DTexture9 : public IDirect3DTexture9
|
||||
STDMETHOD(UnlockRect)(UINT Level);
|
||||
STDMETHOD(AddDirtyRect)(CONST RECT* pDirtyRect);
|
||||
|
||||
int GetHash(MyTypeHash &hash);
|
||||
int ComputetHash( bool compute_crc);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -239,9 +239,8 @@ HRESULT APIENTRY uMod_IDirect3DVolumeTexture9::UnlockBox(UINT Level)
|
||||
}
|
||||
|
||||
|
||||
int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash &hash)
|
||||
int uMod_IDirect3DVolumeTexture9::ComputetHash( bool compute_crc)
|
||||
{
|
||||
hash=0u;
|
||||
if (FAKE) return (RETURN_BAD_ARGUMENT);
|
||||
IDirect3DVolumeTexture9 *pTexture = m_D3Dtex;
|
||||
if (CrossRef_D3Dtex!=NULL) pTexture = CrossRef_D3Dtex->m_D3Dtex;
|
||||
@@ -260,101 +259,7 @@ int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash &hash)
|
||||
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() (%d %d %d) %d\n", desc.Width, desc.Height, desc.Depth, desc.Format);
|
||||
|
||||
/*
|
||||
if (desc.Pool==D3DPOOL_DEFAULT) //get the raw data of the texture
|
||||
{
|
||||
//Message("uMod_IDirect3DVolumeTexture9::GetHash() (D3DPOOL_DEFAULT)\n");
|
||||
|
||||
IDirect3DSurface9 *pSurfaceLevel_orig = NULL;
|
||||
if (pTexture->GetSurfaceLevel( 0, &pSurfaceLevel_orig)!=D3D_OK)
|
||||
{
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel 1 (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
/*
|
||||
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE)
|
||||
{
|
||||
//Message("uMod_IDirect3DVolumeTexture9::GetHash() MultiSampleType\n");
|
||||
if (D3D_OK!=m_D3Ddev->CreateRenderTarget( desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pResolvedSurface, NULL ))
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateRenderTarget (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
if (D3D_OK!=m_D3Ddev->StretchRect( pSurfaceLevel_orig, NULL, pResolvedSurface, NULL, D3DTEXF_NONE ))
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: StretchRect (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
|
||||
pSurfaceLevel_orig = pResolvedSurface;
|
||||
}
|
||||
*/
|
||||
//CreateTexture(8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DVolumeTexture9**) &SingleTexture, NULL)
|
||||
/*
|
||||
if (D3D_OK!=m_D3Ddev->CreateTexture( desc.Width, desc.Height, 1, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenTexture, NULL))
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateTexture (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_TEXTURE_NOT_LOADED);
|
||||
}
|
||||
if (pOffscreenTexture->GetSurfaceLevel( 0, &pOffscreenSurface)!=D3D_OK)
|
||||
{
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetSurfaceLevel 2 (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
|
||||
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
pOffscreenSurface->Release();
|
||||
pOffscreenTexture->Release();
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
pSurfaceLevel_orig->Release();
|
||||
|
||||
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
|
||||
{
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
pOffscreenSurface->Release();
|
||||
pOffscreenTexture->Release();
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (D3D_OK!=m_D3Ddev->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pOffscreenSurface, NULL))
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: CreateOffscreenPlainSurface (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_TEXTURE_NOT_LOADED);
|
||||
}
|
||||
|
||||
if (D3D_OK!=m_D3Ddev->GetRenderTargetData( pSurfaceLevel_orig, pOffscreenSurface))
|
||||
{
|
||||
pSurfaceLevel_orig->Release();
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
pOffscreenSurface->Release();
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: GetRenderTargetData (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
pSurfaceLevel_orig->Release();
|
||||
|
||||
if (pOffscreenSurface->LockRect( &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
|
||||
{
|
||||
if (pResolvedSurface!=NULL) pResolvedSurface->Release();
|
||||
pOffscreenSurface->Release();
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect (D3DPOOL_DEFAULT)\n");
|
||||
return (RETURN_LockRect_FAILED);
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
if (pTexture->LockBox( 0, &d3dlr, NULL, D3DLOCK_READONLY)!=D3D_OK)
|
||||
{
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() Failed: LockRect 1\n");
|
||||
@@ -371,9 +276,45 @@ int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash &hash)
|
||||
}
|
||||
}
|
||||
|
||||
int size = (GetBitsFromFormat( desc.Format) * desc.Width*desc.Height*desc.Depth)/8;
|
||||
|
||||
hash = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
|
||||
int bits_per_pixel = GetBitsFromFormat( desc.Format);
|
||||
|
||||
{
|
||||
Hash = HASH_INIT_VALUE;
|
||||
unsigned char *data = (unsigned char*) d3dlr.pBits;
|
||||
|
||||
unsigned int size;
|
||||
unsigned int h_max = desc.Height;
|
||||
if (desc.Format == D3DFMT_DXT1) // 8 bytes per block
|
||||
{
|
||||
h_max /= 4; // divide by block size
|
||||
size = desc.Width*2; // desc.Width/4 * 8
|
||||
}
|
||||
else if ( desc.Format==D3DFMT_DXT2 || desc.Format==D3DFMT_DXT3 || desc.Format==D3DFMT_DXT4 || desc.Format==D3DFMT_DXT5 ) // 16 bytes per block
|
||||
{
|
||||
h_max /= 4; // divide by block size
|
||||
size = desc.Width*4; // desc.Width/4 * 16
|
||||
}
|
||||
else size = (bits_per_pixel * desc.Width)/8;
|
||||
|
||||
//int size = (bits_per_pixel * desc.Width)/8;
|
||||
for (unsigned int d=0; d<desc.Depth; d++)
|
||||
{
|
||||
unsigned char* data_inner_loop = data;
|
||||
for (unsigned int h=0; h<h_max; h++)
|
||||
{
|
||||
GetHash( data_inner_loop, size, Hash);
|
||||
data_inner_loop += d3dlr.RowPitch;
|
||||
}
|
||||
data += d3dlr.SlicePitch;
|
||||
}
|
||||
}
|
||||
|
||||
if (compute_crc)
|
||||
{
|
||||
int size = (bits_per_pixel * desc.Width*desc.Height*desc.Depth)/8;
|
||||
CRC = GetCRC32( (char*) d3dlr.pBits, size); //calculate the crc32 of the texture
|
||||
}
|
||||
|
||||
|
||||
if (pResolvedSurface!=NULL)
|
||||
@@ -383,6 +324,6 @@ int uMod_IDirect3DVolumeTexture9::GetHash(MyTypeHash &hash)
|
||||
}
|
||||
else pTexture->UnlockBox(0);
|
||||
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() %#lX (%d %d) %d = %d\n", hash, desc.Width, desc.Height, desc.Format, size);
|
||||
Message("uMod_IDirect3DVolumeTexture9::GetHash() %#llX %#LX (%d %d %d) %d\n", Hash, CRC, desc.Width, desc.Height, desc.Depth, desc.Format);
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
@@ -35,8 +35,9 @@ along with Universal Modding Engine. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
|
||||
|
||||
interface uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9
|
||||
class uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9
|
||||
{
|
||||
public:
|
||||
uMod_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9 **ppTex, IDirect3DDevice9 *pIDirect3DDevice9)
|
||||
{
|
||||
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
|
||||
@@ -47,16 +48,17 @@ interface uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9
|
||||
// thus the fake texture can also be deleted
|
||||
Reference = -1; //need for fast deleting
|
||||
Hash = 0u;
|
||||
CRC = 0u;
|
||||
FAKE = false;
|
||||
}
|
||||
|
||||
// callback interface
|
||||
IDirect3DVolumeTexture9 *m_D3Dtex;
|
||||
uMod_IDirect3DVolumeTexture9 *CrossRef_D3Dtex;
|
||||
IDirect3DDevice9 *m_D3Ddev;
|
||||
int Reference;
|
||||
MyTypeHash Hash;
|
||||
bool FAKE;
|
||||
IDirect3DVolumeTexture9 *m_D3Dtex; //!< pointer to the real IDirect3DCubeTexture9 object
|
||||
uMod_IDirect3DVolumeTexture9 *CrossRef_D3Dtex; //!< cross reference from the fake texture to the game texture and vice versa
|
||||
IDirect3DDevice9 *m_D3Ddev; //!< pointer to the device
|
||||
int Reference; //!< Index in the vector (needed for a fast delete).
|
||||
DWORD64 Hash; //!< computed hash value for this game texture.
|
||||
DWORD32 CRC; //!< computed crc32 value for this game texture.
|
||||
bool FAKE; //!< True if this texture is was loaded by uMod (fake texture)
|
||||
|
||||
// original interface
|
||||
STDMETHOD(QueryInterface) (REFIID riid, void** ppvObj);
|
||||
@@ -83,7 +85,7 @@ interface uMod_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9
|
||||
STDMETHOD(UnlockBox)(UINT Level);
|
||||
|
||||
|
||||
int GetHash(MyTypeHash &hash);
|
||||
int ComputetHash( bool compute_crc);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -33,16 +33,6 @@ uMod_TextureClient_DX9::uMod_TextureClient_DX9( IDirect3DDevice9* device, const
|
||||
uMod_TextureClient_DX9::~uMod_TextureClient_DX9(void)
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::~uMod_TextureClient(void): %lu\n", this);
|
||||
if (Server!=NULL) Server->RemoveClient( this, Version);
|
||||
|
||||
if (Mutex!=NULL) CloseHandle(Mutex);
|
||||
|
||||
if (Update!=NULL) delete [] Update;
|
||||
if (FileToMod!=NULL)
|
||||
{
|
||||
for (int i=0; i<NumberToMod; i++) if (FileToMod[i].Textures!=NULL) delete [] FileToMod[i].Textures;
|
||||
delete [] FileToMod;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,17 +47,14 @@ int uMod_TextureClient_DX9::AddTexture( uMod_IDirect3DTexture9* pTexture)
|
||||
|
||||
Message("uMod_TextureClient_DX9::AddTexture( %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
|
||||
|
||||
MyTypeHash hash;
|
||||
if (int ret = pTexture->GetHash( hash))
|
||||
if (int ret = pTexture->ComputetHash( BoolComputeCRC))
|
||||
{
|
||||
Bool_CheckAgainNonAdded = true;
|
||||
NonAdded_OriginalTextures.Add( pTexture);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
pTexture->Hash = hash;
|
||||
|
||||
if (BoolSaveAllTextures) SaveTexture(pTexture);
|
||||
if (BoolSaveAllTextures) SaveTexture(pTexture, true);
|
||||
|
||||
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
|
||||
|
||||
@@ -87,17 +74,14 @@ int uMod_TextureClient_DX9::AddTexture( uMod_IDirect3DVolumeTexture9* pTexture)
|
||||
|
||||
Message("uMod_TextureClient_DX9::AddTexture( Volume: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
|
||||
|
||||
MyTypeHash hash;
|
||||
if (int ret = pTexture->GetHash( hash))
|
||||
if (int ret = pTexture->ComputetHash( BoolComputeCRC))
|
||||
{
|
||||
Bool_CheckAgainNonAdded = true;
|
||||
NonAdded_OriginalVolumeTextures.Add( pTexture);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
pTexture->Hash = hash;
|
||||
|
||||
if (BoolSaveAllTextures) SaveTexture(pTexture);
|
||||
if (BoolSaveAllTextures) SaveTexture(pTexture, true);
|
||||
|
||||
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
|
||||
|
||||
@@ -117,17 +101,14 @@ int uMod_TextureClient_DX9::AddTexture( uMod_IDirect3DCubeTexture9* pTexture)
|
||||
|
||||
Message("uMod_TextureClient_DX9::AddTexture( Cube: %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThreadId());
|
||||
|
||||
MyTypeHash hash;
|
||||
if (int ret = pTexture->GetHash( hash))
|
||||
if (int ret = pTexture->ComputetHash( BoolComputeCRC))
|
||||
{
|
||||
Bool_CheckAgainNonAdded = true;
|
||||
NonAdded_OriginalCubeTextures.Add( pTexture);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
pTexture->Hash = hash;
|
||||
|
||||
if (BoolSaveAllTextures) SaveTexture(pTexture);
|
||||
if (BoolSaveAllTextures) SaveTexture(pTexture, true);
|
||||
|
||||
if (gl_ErrorState & uMod_ERROR_FATAL) return (RETURN_FATAL_ERROR);
|
||||
|
||||
@@ -149,8 +130,7 @@ int uMod_TextureClient_DX9::CheckAgainNonAdded(void)
|
||||
{
|
||||
uMod_IDirect3DTexture9* pTexture = NonAdded_OriginalTextures[i];
|
||||
|
||||
MyTypeHash hash;
|
||||
if (pTexture->GetHash( hash) == 0)
|
||||
if (pTexture->ComputetHash( BoolComputeCRC) == RETURN_OK)
|
||||
{
|
||||
NonAdded_OriginalTextures.Remove(pTexture);
|
||||
OriginalTextures.Add( pTexture); // add the texture to the list of original texture
|
||||
@@ -163,8 +143,7 @@ int uMod_TextureClient_DX9::CheckAgainNonAdded(void)
|
||||
{
|
||||
uMod_IDirect3DVolumeTexture9* pTexture = NonAdded_OriginalVolumeTextures[i];
|
||||
|
||||
MyTypeHash hash;
|
||||
if (pTexture->GetHash( hash) == 0)
|
||||
if (pTexture->ComputetHash( BoolComputeCRC) == RETURN_OK)
|
||||
{
|
||||
NonAdded_OriginalVolumeTextures.Remove(pTexture);
|
||||
OriginalVolumeTextures.Add( pTexture); // add the texture to the list of original texture
|
||||
@@ -177,8 +156,7 @@ int uMod_TextureClient_DX9::CheckAgainNonAdded(void)
|
||||
{
|
||||
uMod_IDirect3DCubeTexture9* pTexture = NonAdded_OriginalCubeTextures[i];
|
||||
|
||||
MyTypeHash hash;
|
||||
if (pTexture->GetHash( hash) == 0)
|
||||
if (pTexture->ComputetHash( BoolComputeCRC) == RETURN_OK)
|
||||
{
|
||||
NonAdded_OriginalCubeTextures.Remove(pTexture);
|
||||
OriginalCubeTextures.Add( pTexture); // add the texture to the list of original texture
|
||||
@@ -299,49 +277,248 @@ int uMod_TextureClient_DX9::SaveSingleTexture(bool val)
|
||||
}
|
||||
|
||||
|
||||
int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DTexture9* pTexture)
|
||||
int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DTexture9* pTexture, bool save_all)
|
||||
{
|
||||
if (pTexture==NULL) return (RETURN_BAD_ARGUMENT);
|
||||
if (SavePath[0]==0)
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this);
|
||||
return (RETURN_TEXTURE_NOT_SAVED);
|
||||
}
|
||||
D3DSURFACE_DESC desc;
|
||||
if (pTexture->m_D3Dtex->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::SaveTexture() Failed: GetLevelDesc \n");
|
||||
return (RETURN_GetLevelDesc_FAILED);
|
||||
}
|
||||
|
||||
if (save_all)
|
||||
{
|
||||
if (WidthFilter)
|
||||
{
|
||||
unsigned int min = WidthFilter >> 32;
|
||||
unsigned int max = (WidthFilter<<32) >> 32;
|
||||
if (desc.Width<min || desc.Width> max) return (RETURN_OK);
|
||||
}
|
||||
if (HeightFilter)
|
||||
{
|
||||
unsigned int min = HeightFilter >> 32;
|
||||
unsigned int max = (HeightFilter<<32) >> 32;
|
||||
if (desc.Height<min || desc.Height> max) return (RETURN_OK);
|
||||
}
|
||||
if (!SaveTextureFilterFormat(desc.Format)) return (RETURN_OK);
|
||||
}
|
||||
|
||||
|
||||
wchar_t file[MAX_PATH];
|
||||
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_W%u_H%u_F%u_T_%#llX", SavePath, GameName, desc.Width, desc.Height,desc.Format, pTexture->Hash);
|
||||
else swprintf_s( file, MAX_PATH, L"%ls\\W%u_H%u_F%u_T_%#llX", SavePath, desc.Width, desc.Height, desc.Format, pTexture->Hash);
|
||||
Message("uMod_TextureClient_DX9::SaveTexture( %ls): %lu\n", file, this);
|
||||
|
||||
return (SaveTexture( pTexture->m_D3Dtex, file));
|
||||
}
|
||||
|
||||
int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture, bool save_all)
|
||||
{
|
||||
if (pTexture==NULL) return (RETURN_BAD_ARGUMENT);
|
||||
if (SavePath[0]==0) {Message("uMod_TextureClient_DX9::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);}
|
||||
|
||||
D3DVOLUME_DESC desc;
|
||||
if (pTexture->m_D3Dtex->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::SaveTexture() Failed: GetLevelDesc \n");
|
||||
return (RETURN_GetLevelDesc_FAILED);
|
||||
}
|
||||
|
||||
if (save_all)
|
||||
{
|
||||
if (WidthFilter)
|
||||
{
|
||||
unsigned int min = WidthFilter >> 32;
|
||||
unsigned int max = (WidthFilter<<32) >> 32;
|
||||
if (desc.Width<min || desc.Width> max) return (RETURN_OK);
|
||||
}
|
||||
if (HeightFilter)
|
||||
{
|
||||
unsigned int min = HeightFilter >> 32;
|
||||
unsigned int max = (HeightFilter<<32) >> 32;
|
||||
if (desc.Height<min || desc.Height> max) return (RETURN_OK);
|
||||
}
|
||||
if (DepthFilter)
|
||||
{
|
||||
unsigned int min = DepthFilter >> 32;
|
||||
unsigned int max = (DepthFilter<<32) >> 32;
|
||||
if (desc.Depth<min || desc.Depth> max) return (RETURN_OK);
|
||||
}
|
||||
if (!SaveTextureFilterFormat(desc.Format)) return (RETURN_OK);
|
||||
}
|
||||
|
||||
wchar_t file[MAX_PATH];
|
||||
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_T_%#lX.dds", SavePath, GameName, pTexture->Hash);
|
||||
else swprintf_s( file, MAX_PATH, L"%ls\\T_%#lX.dds", SavePath, pTexture->Hash);
|
||||
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_W%u_H%u_D%u_F%u_V_%#llX", SavePath, GameName, desc.Width, desc.Height, desc.Depth, desc.Format, pTexture->Hash);
|
||||
else swprintf_s( file, MAX_PATH, L"%ls\\W%u_H%u_D%u_F%u_V_%#llX", SavePath, desc.Width, desc.Height, desc.Depth, desc.Format, pTexture->Hash);
|
||||
Message("uMod_TextureClient_DX9::SaveTexture( %ls): %lu\n", file, this);
|
||||
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
return (RETURN_OK);
|
||||
return (SaveTexture( pTexture->m_D3Dtex, file));
|
||||
}
|
||||
|
||||
int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture)
|
||||
int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DCubeTexture9* pTexture, bool save_all)
|
||||
{
|
||||
if (pTexture==NULL) return (RETURN_BAD_ARGUMENT);
|
||||
if (SavePath[0]==0) {Message("uMod_TextureClient_DX9::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);}
|
||||
|
||||
D3DSURFACE_DESC desc;
|
||||
if (pTexture->m_D3Dtex->GetLevelDesc(0, &desc)!=D3D_OK) //get the format and the size of the texture
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::SaveTexture() Failed: GetLevelDesc \n");
|
||||
return (RETURN_GetLevelDesc_FAILED);
|
||||
}
|
||||
|
||||
if (save_all)
|
||||
{
|
||||
if (WidthFilter)
|
||||
{
|
||||
unsigned int min = WidthFilter >> 32;
|
||||
unsigned int max = (WidthFilter<<32) >> 32;
|
||||
if (desc.Width<min || desc.Width> max) return (RETURN_OK);
|
||||
}
|
||||
if (!SaveTextureFilterFormat(desc.Format)) return (RETURN_OK);
|
||||
}
|
||||
|
||||
wchar_t file[MAX_PATH];
|
||||
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_V_%#lX.dds", SavePath, GameName, pTexture->Hash);
|
||||
else swprintf_s( file, MAX_PATH, L"%ls\\V_%#lX.dds", SavePath, pTexture->Hash);
|
||||
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_W%u_F%u_C_%#llX.dds", SavePath, GameName, desc.Width, desc.Format, pTexture->Hash);
|
||||
else swprintf_s( file, MAX_PATH, L"%ls\\W%u_F%u_C_%#llX.dds", SavePath, desc.Width, desc.Format, pTexture->Hash);
|
||||
Message("uMod_TextureClient_DX9::SaveTexture( %ls): %lu\n", file, this);
|
||||
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
return (RETURN_OK);
|
||||
|
||||
return (SaveTexture( pTexture->m_D3Dtex, file));
|
||||
}
|
||||
|
||||
int uMod_TextureClient_DX9::SaveTexture(uMod_IDirect3DCubeTexture9* pTexture)
|
||||
|
||||
int uMod_TextureClient_DX9::SaveTexture(IDirect3DBaseTexture9* pTexture, wchar_t *file)
|
||||
{
|
||||
if (pTexture==NULL) return (RETURN_BAD_ARGUMENT);
|
||||
if (SavePath[0]==0) {Message("uMod_TextureClient_DX9::SaveTexture( %#lX, %lu): %lu, SavePath not set\n", pTexture->Hash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);}
|
||||
|
||||
wchar_t file[MAX_PATH];
|
||||
if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_C_%#lX.dds", SavePath, GameName, pTexture->Hash);
|
||||
else swprintf_s( file, MAX_PATH, L"%ls\\C_%#lX.dds", SavePath, pTexture->Hash);
|
||||
Message("uMod_TextureClient_DX9::SaveTexture( %ls): %lu\n", file, this);
|
||||
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
unsigned int len=0;
|
||||
while (file[len]) len++;
|
||||
if (FileFormat & uMod_D3DXIFF_BMP)
|
||||
{
|
||||
file[len] = '.';file[len+1] = 'b';file[len+2] = 'm';file[len+3] = 'p';file[len+4] = '\0';
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_BMP, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
}
|
||||
if (FileFormat & uMod_D3DXIFF_JPG)
|
||||
{
|
||||
file[len] = '.';file[len+1] = 'j';file[len+2] = 'p';file[len+3] = 'g';file[len+4] = '\0';
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_JPG, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
}
|
||||
if (FileFormat & uMod_D3DXIFF_TGA)
|
||||
{
|
||||
file[len] = '.';file[len+1] = 't';file[len+2] = 'g';file[len+3] = 'a';file[len+4] = '\0';
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_TGA, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
}
|
||||
if (FileFormat & uMod_D3DXIFF_PNG)
|
||||
{
|
||||
file[len] = '.';file[len+1] = 'p';file[len+2] = 'n';file[len+3] = 'g';file[len+4] = '\0';
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_PNG, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
}
|
||||
if (FileFormat & uMod_D3DXIFF_DDS)
|
||||
{
|
||||
file[len] = '.';file[len+1] = 'd';file[len+2] = 'd';file[len+3] = 's';file[len+4] = '\0';
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
}
|
||||
if (FileFormat & uMod_D3DXIFF_PPM)
|
||||
{
|
||||
file[len] = '.';file[len+1] = 'p';file[len+2] = 'p';file[len+3] = 'm';file[len+4] = '\0';
|
||||
if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_PPM, pTexture, NULL)) return (RETURN_TEXTURE_NOT_SAVED);
|
||||
}
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
#define DEF_FormatCheck( format ) \
|
||||
case format: \
|
||||
{ \
|
||||
if (FormatFilter & uMod_ ## format) return (true); \
|
||||
else return (false); \
|
||||
}
|
||||
|
||||
|
||||
bool uMod_TextureClient_DX9::SaveTextureFilterFormat(D3DFORMAT format)
|
||||
{
|
||||
if (FormatFilter == 0u) return (true);
|
||||
switch(format) //switch trough the formats to calculate the size of the raw data
|
||||
{
|
||||
DEF_FormatCheck( D3DFMT_A1) // 1-bit monochrome.
|
||||
DEF_FormatCheck( D3DFMT_R3G3B2) // 8-bit RGB texture format using 3 bits for red, 3 bits for green, and 2 bits for blue.
|
||||
DEF_FormatCheck( D3DFMT_A8) // 8-bit alpha only.
|
||||
|
||||
DEF_FormatCheck( D3DFMT_A8P8) // 8-bit color indexed with 8 bits of alpha.
|
||||
DEF_FormatCheck( D3DFMT_P8) // 8-bit color indexed.
|
||||
DEF_FormatCheck( D3DFMT_L8) // 8-bit luminance only.
|
||||
DEF_FormatCheck( D3DFMT_A4L4) // 8-bit using 4 bits each for alpha and luminance.
|
||||
|
||||
//DEF_FormatCheck( D3DFMT_FORCE_DWORD)
|
||||
DEF_FormatCheck( D3DFMT_S8_LOCKABLE) // A lockable 8-bit stencil buffer.
|
||||
|
||||
DEF_FormatCheck( D3DFMT_D16_LOCKABLE) //16-bit z-buffer bit depth.
|
||||
DEF_FormatCheck( D3DFMT_D15S1) // 16-bit z-buffer bit depth where 15 bits are reserved for the depth channel and 1 bit is reserved for the stencil channel.
|
||||
DEF_FormatCheck( D3DFMT_L6V5U5) // 16-bit bump-map format with luminance using 6 bits for luminance, and 5 bits each for v and u.
|
||||
DEF_FormatCheck( D3DFMT_V8U8) // 16-bit bump-map format using 8 bits each for u and v data.
|
||||
DEF_FormatCheck( D3DFMT_CxV8U8) // 16-bit normal compression format. The texture sampler computes the C channel from) C = sqrt(1 - U2 - V2).
|
||||
DEF_FormatCheck( D3DFMT_R5G6B5) // 16-bit RGB pixel format with 5 bits for red, 6 bits for green, and 5 bits for blue.
|
||||
DEF_FormatCheck( D3DFMT_X1R5G5B5) // 16-bit pixel format where 5 bits are reserved for each color.
|
||||
DEF_FormatCheck( D3DFMT_A1R5G5B5) // 16-bit pixel format where 5 bits are reserved for each color and 1 bit is reserved for alpha.
|
||||
DEF_FormatCheck( D3DFMT_A4R4G4B4) // 16-bit ARGB pixel format with 4 bits for each channel.
|
||||
DEF_FormatCheck( D3DFMT_A8R3G3B2) // 16-bit ARGB texture format using 8 bits for alpha, 3 bits each for red and green, and 2 bits for blue.
|
||||
DEF_FormatCheck( D3DFMT_X4R4G4B4) // 16-bit RGB pixel format using 4 bits for each color.
|
||||
DEF_FormatCheck( D3DFMT_L16) // 16-bit luminance only.
|
||||
DEF_FormatCheck( D3DFMT_R16F) // 16-bit float format using 16 bits for the red channel.
|
||||
DEF_FormatCheck( D3DFMT_A8L8) // 16-bit using 8 bits each for alpha and luminance.
|
||||
DEF_FormatCheck( D3DFMT_D16) // 16-bit z-buffer bit depth.
|
||||
DEF_FormatCheck( D3DFMT_INDEX16) // 16-bit index buffer bit depth.
|
||||
DEF_FormatCheck( D3DFMT_G8R8_G8B8) // ??
|
||||
DEF_FormatCheck( D3DFMT_R8G8_B8G8) // ??
|
||||
DEF_FormatCheck( D3DFMT_UYVY) // ??
|
||||
DEF_FormatCheck( D3DFMT_YUY2) // ??
|
||||
|
||||
DEF_FormatCheck( D3DFMT_R8G8B8) //24-bit RGB pixel format with 8 bits per channel.
|
||||
|
||||
DEF_FormatCheck( D3DFMT_R32F) // 32-bit float format using 32 bits for the red channel.
|
||||
DEF_FormatCheck( D3DFMT_X8L8V8U8) // 32-bit bump-map format with luminance using 8 bits for each channel.
|
||||
DEF_FormatCheck( D3DFMT_A2W10V10U10) // 32-bit bump-map format using 2 bits for alpha and 10 bits each for w, v, and u.
|
||||
DEF_FormatCheck( D3DFMT_Q8W8V8U8) // 32-bit bump-map format using 8 bits for each channel.
|
||||
DEF_FormatCheck( D3DFMT_V16U16) // 32-bit bump-map format using 16 bits for each channel.
|
||||
DEF_FormatCheck( D3DFMT_A8R8G8B8) // 32-bit ARGB pixel format with alpha, using 8 bits per channel.
|
||||
DEF_FormatCheck( D3DFMT_X8R8G8B8) // 32-bit RGB pixel format, where 8 bits are reserved for each color.
|
||||
DEF_FormatCheck( D3DFMT_A2B10G10R10) // 32-bit pixel format using 10 bits for each color and 2 bits for alpha.
|
||||
DEF_FormatCheck( D3DFMT_A8B8G8R8) // 32-bit ARGB pixel format with alpha, using 8 bits per channel.
|
||||
DEF_FormatCheck( D3DFMT_X8B8G8R8) // 32-bit RGB pixel format, where 8 bits are reserved for each color.
|
||||
DEF_FormatCheck( D3DFMT_G16R16) // 32-bit pixel format using 16 bits each for green and red.
|
||||
DEF_FormatCheck( D3DFMT_G16R16F) // 32-bit float format using 16 bits for the red channel and 16 bits for the green channel.
|
||||
DEF_FormatCheck( D3DFMT_A2R10G10B10) // 32-bit pixel format using 10 bits each for red, green, and blue, and 2 bits for alpha.
|
||||
DEF_FormatCheck( D3DFMT_D32) // 32-bit z-buffer bit depth.
|
||||
DEF_FormatCheck( D3DFMT_D24S8) // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel.
|
||||
DEF_FormatCheck( D3DFMT_D24X8) //32-bit z-buffer bit depth using 24 bits for the depth channel.
|
||||
DEF_FormatCheck( D3DFMT_D24X4S4) // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel.
|
||||
DEF_FormatCheck( D3DFMT_D32F_LOCKABLE) // A lockable format where the depth value is represented as a standard IEEE floating-point number.
|
||||
DEF_FormatCheck( D3DFMT_D24FS8) // A non-lockable format that contains 24 bits of depth (in a 24-bit floating point format - 20e4) and 8 bits of stencil.
|
||||
DEF_FormatCheck( D3DFMT_D32_LOCKABLE) // A lockable 32-bit depth buffer.
|
||||
DEF_FormatCheck( D3DFMT_INDEX32) // 32-bit index buffer bit depth.
|
||||
|
||||
DEF_FormatCheck( D3DFMT_G32R32F) // 64-bit float format using 32 bits for the red channel and 32 bits for the green channel.
|
||||
DEF_FormatCheck( D3DFMT_Q16W16V16U16) // 64-bit bump-map format using 16 bits for each component.
|
||||
DEF_FormatCheck( D3DFMT_A16B16G16R16) // 64-bit pixel format using 16 bits for each component.
|
||||
DEF_FormatCheck( D3DFMT_A16B16G16R16F) // 64-bit float format using 16 bits for the each channel (alpha, blue, green, red).
|
||||
|
||||
DEF_FormatCheck( D3DFMT_A32B32G32R32F) // 128-bit float format using 32 bits for the each channel (alpha, blue, green, red).
|
||||
DEF_FormatCheck( D3DFMT_DXT2)
|
||||
DEF_FormatCheck( D3DFMT_DXT3)
|
||||
DEF_FormatCheck( D3DFMT_DXT4)
|
||||
DEF_FormatCheck( D3DFMT_DXT5)
|
||||
DEF_FormatCheck( D3DFMT_DXT1)
|
||||
default: //compressed formats
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
int uMod_TextureClient_DX9::MergeUpdate(void)
|
||||
{
|
||||
if (NumberOfUpdate<0) {return (RETURN_OK);}
|
||||
@@ -548,7 +725,7 @@ int uMod_TextureClient_DX9::MergeUpdate(void)
|
||||
|
||||
if (to_lookup != NULL) delete [] to_lookup;
|
||||
|
||||
Message("uMod_TextureClient_DX9::MergeUpdate() END: %lu\n", this);
|
||||
Message("uMod_TextureClient_DX9::MergeUpdate() END: %p\n", this);
|
||||
|
||||
CheckAgainNonAdded();
|
||||
return (UnlockMutex());
|
||||
@@ -558,7 +735,7 @@ int uMod_TextureClient_DX9::MergeUpdate(void)
|
||||
|
||||
int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod( %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod( %p): hash: %#llX, %p\n", pTexture, pTexture->Hash, this);
|
||||
if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched
|
||||
int index = GetIndex( pTexture->Hash, num_index_list, index_list);
|
||||
if (index>=0)
|
||||
@@ -582,12 +759,37 @@ int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DTexture9* pTexture, int n
|
||||
fake_Texture->Reference = index;
|
||||
}
|
||||
}
|
||||
else if (BoolComputeCRC && pTexture->CRC>0)
|
||||
{
|
||||
index = GetIndex( pTexture->CRC, num_index_list, index_list);
|
||||
if (index>=0)
|
||||
{
|
||||
uMod_IDirect3DTexture9 *fake_Texture;
|
||||
if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret);
|
||||
if (SwitchTextures( fake_Texture, pTexture))
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
|
||||
fake_Texture->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1];
|
||||
for (int j=0; j<FileToMod[index].NumberOfTextures; j++) temp[j] = (IDirect3DBaseTexture9*) FileToMod[index].Textures[j];
|
||||
|
||||
if (FileToMod[index].Textures!=NULL) delete [] FileToMod[index].Textures;
|
||||
FileToMod[index].Textures = (void**) temp;
|
||||
|
||||
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
|
||||
fake_Texture->Reference = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DVolumeTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod( Volume %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod( Volume %p): hash: %#llX, %p\n", pTexture, pTexture->Hash, this);
|
||||
if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched
|
||||
int index = GetIndex( pTexture->Hash, num_index_list, index_list);
|
||||
if (index>=0)
|
||||
@@ -611,12 +813,37 @@ int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DVolumeTexture9* pTexture,
|
||||
fake_Texture->Reference = index;
|
||||
}
|
||||
}
|
||||
else if (BoolComputeCRC && pTexture->CRC>0)
|
||||
{
|
||||
index = GetIndex( pTexture->CRC, num_index_list, index_list);
|
||||
if (index>=0)
|
||||
{
|
||||
uMod_IDirect3DVolumeTexture9 *fake_Texture;
|
||||
if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret);
|
||||
if (SwitchTextures( fake_Texture, pTexture))
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
|
||||
fake_Texture->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1];
|
||||
for (int j=0; j<FileToMod[index].NumberOfTextures; j++) temp[j] = (IDirect3DBaseTexture9*) FileToMod[index].Textures[j];
|
||||
|
||||
if (FileToMod[index].Textures!=NULL) delete [] FileToMod[index].Textures;
|
||||
FileToMod[index].Textures = (void**) temp;
|
||||
|
||||
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
|
||||
fake_Texture->Reference = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, int num_index_list, int *index_list) // should only be called for original textures
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod( Cube %lu): hash: %#lX, %lu\n", pTexture, pTexture->Hash, this);
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod( Cube %p): hash: %#llX, %p\n", pTexture, pTexture->Hash, this);
|
||||
if (pTexture->CrossRef_D3Dtex!=NULL) return (RETURN_OK); // bug, this texture is already switched
|
||||
int index = GetIndex( pTexture->Hash, num_index_list, index_list);
|
||||
if (index>=0)
|
||||
@@ -640,6 +867,31 @@ int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, i
|
||||
fake_Texture->Reference = index;
|
||||
}
|
||||
}
|
||||
else if (BoolComputeCRC && pTexture->CRC>0)
|
||||
{
|
||||
index = GetIndex( pTexture->CRC, num_index_list, index_list);
|
||||
if (index>=0)
|
||||
{
|
||||
uMod_IDirect3DCubeTexture9 *fake_Texture;
|
||||
if (int ret = LoadTexture( & (FileToMod[index]), &fake_Texture)) return (ret);
|
||||
if (SwitchTextures( fake_Texture, pTexture))
|
||||
{
|
||||
Message("uMod_TextureClient_DX9::LookUpToMod(): textures not switched %#lX\n", FileToMod[index].Hash);
|
||||
fake_Texture->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
IDirect3DBaseTexture9 **temp = new IDirect3DBaseTexture9*[FileToMod[index].NumberOfTextures+1];
|
||||
for (int j=0; j<FileToMod[index].NumberOfTextures; j++) temp[j] = (IDirect3DBaseTexture9*) FileToMod[index].Textures[j];
|
||||
|
||||
if (FileToMod[index].Textures!=NULL) delete [] FileToMod[index].Textures;
|
||||
FileToMod[index].Textures = (void**) temp;
|
||||
|
||||
FileToMod[index].Textures[FileToMod[index].NumberOfTextures++] = fake_Texture;
|
||||
fake_Texture->Reference = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
@@ -648,7 +900,7 @@ int uMod_TextureClient_DX9::LookUpToMod( uMod_IDirect3DCubeTexture9* pTexture, i
|
||||
|
||||
int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9 **ppTexture) // to load fake texture from a file in memory
|
||||
{
|
||||
Message("LoadTexture( %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
|
||||
Message("LoadTexture( %p, %p, %#llX): %p\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
|
||||
if (D3D_OK != D3DXCreateTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DTexture9 **) ppTexture))
|
||||
//if (D3D_OK != D3DXCreateTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DTexture9 **) ppTexture))
|
||||
{
|
||||
@@ -662,13 +914,13 @@ int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod
|
||||
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
|
||||
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedTexture(NULL); //this texture must no be added twice
|
||||
|
||||
Message("LoadTexture( %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
|
||||
Message("LoadTexture( %p, %#llX): DONE\n", *ppTexture, file_in_memory->Hash);
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9 **ppTexture) // to load fake texture from a file in memory
|
||||
{
|
||||
Message("LoadTexture( Volume %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
|
||||
Message("LoadTexture( Volume %p, %p, %#llX): %p\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
|
||||
if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DVolumeTexture9 **) ppTexture))
|
||||
//if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DVolumeTexture9 **) ppTexture))
|
||||
{
|
||||
@@ -682,13 +934,13 @@ int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod
|
||||
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
|
||||
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedVolumeTexture(NULL); //this texture must no be added twice
|
||||
|
||||
Message("LoadTexture( Volume %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
|
||||
Message("LoadTexture( Volume %p, %#llX): DONE\n", *ppTexture, file_in_memory->Hash);
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9 **ppTexture) // to load fake texture from a file in memory
|
||||
{
|
||||
Message("LoadTexture( Cube %lu, %lu, %#lX): %lu\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
|
||||
Message("LoadTexture( Cube %p, %p, %#llX): %p\n", file_in_memory, ppTexture, file_in_memory->Hash, this);
|
||||
if (D3D_OK != D3DXCreateCubeTextureFromFileInMemoryEx( D3D9Device, file_in_memory->pData, file_in_memory->Size, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DCubeTexture9 **) ppTexture))
|
||||
//if (D3D_OK != D3DXCreateCubeTextureFromFileInMemory( D3D9Device, file_in_memory->pData, file_in_memory->Size, (IDirect3DCubeTexture9 **) ppTexture))
|
||||
{
|
||||
@@ -702,7 +954,7 @@ int uMod_TextureClient_DX9::LoadTexture( TextureFileStruct* file_in_memory, uMod
|
||||
if (ret == 0x01000000L) ((uMod_IDirect3DDevice9*)D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
|
||||
else ((uMod_IDirect3DDevice9Ex*) D3D9Device)->SetLastCreatedCubeTexture(NULL); //this texture must no be added twice
|
||||
|
||||
Message("LoadTexture( Cube %lu, %#lX): DONE\n", *ppTexture, file_in_memory->Hash);
|
||||
Message("LoadTexture( Cube %p, %#llX): DONE\n", *ppTexture, file_in_memory->Hash);
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,20 +44,74 @@ public:
|
||||
uMod_TextureClient_DX9( IDirect3DDevice9* device, const int version);
|
||||
virtual ~uMod_TextureClient_DX9(void);
|
||||
|
||||
int AddTexture( uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DDevice9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
|
||||
int AddTexture( uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
|
||||
int AddTexture( uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
|
||||
/**
|
||||
* called from uMod_IDirect3DDevice9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
|
||||
* @param[in] tex texture to be added
|
||||
* @return
|
||||
*/
|
||||
int AddTexture( uMod_IDirect3DTexture9* tex);
|
||||
|
||||
int RemoveTexture( uMod_IDirect3DTexture9* tex); //called from uMod_IDirect3DTexture9::Release()
|
||||
int RemoveTexture( uMod_IDirect3DVolumeTexture9* tex); //called from uMod_IDirect3DVolumeTexture9::Release()
|
||||
int RemoveTexture( uMod_IDirect3DCubeTexture9* tex); //called from uMod_IDirect3DCubeTexture9::Release()
|
||||
/**
|
||||
* called from uMod_IDirect3DVolumeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
|
||||
* @param[in] tex texture to be added
|
||||
* @return
|
||||
*/
|
||||
int AddTexture( uMod_IDirect3DVolumeTexture9* tex);
|
||||
|
||||
/**
|
||||
* called from uMod_IDirect3DCubeTexture9::CreateTexture(...) or uMod_IDirect3DDevice9::BeginScene()
|
||||
* @param[in] tex texture to be added
|
||||
* @return
|
||||
*/
|
||||
int AddTexture( uMod_IDirect3DCubeTexture9* tex);
|
||||
|
||||
/**
|
||||
* called from uMod_IDirect3DTexture9::Release()
|
||||
* @param[in] tex
|
||||
* @return
|
||||
*/
|
||||
int RemoveTexture( uMod_IDirect3DTexture9* tex);
|
||||
|
||||
/**
|
||||
* called from uMod_IDirect3DVolumeTexture9::Release()
|
||||
* @param[in] tex
|
||||
* @return
|
||||
*/
|
||||
int RemoveTexture( uMod_IDirect3DVolumeTexture9* tex);
|
||||
|
||||
/**
|
||||
* called from uMod_IDirect3DCubeTexture9::Release()
|
||||
* @param[in] tex
|
||||
* @return
|
||||
*/
|
||||
int RemoveTexture( uMod_IDirect3DCubeTexture9* tex);
|
||||
|
||||
int SaveAllTextures(bool val); //called from the Server
|
||||
int SaveSingleTexture(bool val); //called from the Server
|
||||
|
||||
int SaveTexture(uMod_IDirect3DTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
|
||||
int SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
|
||||
int SaveTexture(uMod_IDirect3DCubeTexture9* pTexture); //called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
|
||||
/**
|
||||
* called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
|
||||
* @param[in] pTexture
|
||||
* @param[in] save_all true if called from AddTexture(...) -> (SaveAllTextures is true)
|
||||
* @return
|
||||
*/
|
||||
int SaveTexture(uMod_IDirect3DTexture9* pTexture, bool save_all=false); //
|
||||
|
||||
/**
|
||||
* called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
|
||||
* @param[in] pTexture
|
||||
* @param[in] save_all true if called from AddTexture(...) -> (SaveAllTextures is true)
|
||||
* @return
|
||||
*/
|
||||
int SaveTexture(uMod_IDirect3DVolumeTexture9* pTexture, bool save_all=false);
|
||||
|
||||
/**
|
||||
* called from uMod_IDirect3DDevice9::BeginScene() (save button) or from AddTexture(...) (SaveAllTextures)
|
||||
* @param[in] pTexture
|
||||
* @param[in] save_all true if called from AddTexture(...) -> (SaveAllTextures is true)
|
||||
* @return
|
||||
*/
|
||||
int SaveTexture(uMod_IDirect3DCubeTexture9* pTexture, bool save_all=false);
|
||||
|
||||
int MergeUpdate(void); //called from uMod_IDirect3DDevice9::BeginScene()
|
||||
|
||||
@@ -85,6 +139,22 @@ public:
|
||||
private:
|
||||
IDirect3DDevice9* D3D9Device;
|
||||
|
||||
|
||||
/**
|
||||
* Save the texture into a file (reagrding the various file formats.
|
||||
* @param[in] pTexture
|
||||
* @param[inout] file name without trailing format extension
|
||||
* @return
|
||||
*/
|
||||
int SaveTexture(IDirect3DBaseTexture9* pTexture, wchar_t *file);
|
||||
|
||||
/**
|
||||
* Return true if this texture has the right format to pass the FormatFilter and thus it is saved
|
||||
* @param format
|
||||
* @return
|
||||
*/
|
||||
bool SaveTextureFilterFormat(D3DFORMAT format);
|
||||
|
||||
int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DTexture9 **ppTexture); // called if a target texture is found
|
||||
int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DVolumeTexture9 **ppTexture); // called if a target texture is found
|
||||
int LoadTexture( TextureFileStruct* file_in_memory, uMod_IDirect3DCubeTexture9 **ppTexture); // called if a target texture is found
|
||||
|
||||
Reference in New Issue
Block a user