From 8fd918f382aa47e1816c9ce67eabad4f1a82f144 Mon Sep 17 00:00:00 2001 From: "code@koerner-de.net" Date: Fri, 16 Sep 2011 12:48:41 +0000 Subject: [PATCH] BugFix: - UnlockRect(0) was uncommented Improvements: - game name will be add before the saved texture --- OTM_DX9/OTM_DX9_dll.cpp | 4 +- OTM_DX9/OTM_TextureClient.cpp | 93 +++++++++-------------------------- OTM_DX9/OTM_TextureClient.h | 2 + OTM_DX9/OTM_TextureServer.cpp | 16 +++--- OTM_DX9/OTM_TextureServer.h | 5 +- 5 files changed, 41 insertions(+), 79 deletions(-) diff --git a/OTM_DX9/OTM_DX9_dll.cpp b/OTM_DX9/OTM_DX9_dll.cpp index 4dd7714..5a4b3f2 100644 --- a/OTM_DX9/OTM_DX9_dll.cpp +++ b/OTM_DX9/OTM_DX9_dll.cpp @@ -201,10 +201,10 @@ void InitInstance(HINSTANCE hModule) OpenMessage(); Message("InitInstance: %lu\n", hModule); - gl_TextureServer = new OTM_TextureServer(); + gl_TextureServer = new OTM_TextureServer(game); if (gl_TextureServer!=NULL) { - if (gl_TextureServer->OpenPipe( game)) + if (gl_TextureServer->OpenPipe()) { Message("InitInstance: Pipe not opened\n"); return; diff --git a/OTM_DX9/OTM_TextureClient.cpp b/OTM_DX9/OTM_TextureClient.cpp index a344069..461479c 100644 --- a/OTM_DX9/OTM_TextureClient.cpp +++ b/OTM_DX9/OTM_TextureClient.cpp @@ -32,6 +32,7 @@ OTM_TextureClient::OTM_TextureClient(OTM_TextureServer* server, IDirect3DDevice9 D3D9Device = device; BoolSaveAllTextures = false; SavePath[0]=0; + GameName[0]=0; if (Server!=NULL) { if (Server->AddClient( this, &FileToMod, &NumberToMod)) @@ -165,78 +166,12 @@ int OTM_TextureClient::AddTexture( OTM_IDirect3DTexture9* pTexture) } //MyTypeHash hash = GetHash( (unsigned char*) d3dlr.pBits, size); MyTypeHash hash = GetCRC32( (char*) d3dlr.pBits, size); -/* - if (hash==0X1FD33669ul) - { - for (int i=0; iUnlockRect(0)!=D3D_OK) { return (RETURN_UnlockRect_FAILED); } - LPD3DXBUFFER buffer; - if (D3D_OK==D3DXSaveTextureToFileInMemory( &buffer, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) - { - DWORD* data = (DWORD*) buffer->GetBufferPointer(); - unsigned long int size = buffer->GetBufferSize(); - hash6 = QuickChecksum( (char*) data, size); - buffer->Release(); - } - - Message("Hash: %#lX %#lX %#lX %#lX %#lX %#lX\n", hash, hash2, hash3, hash4, hash5, hash6); - - DWORD XOR=0u; - switch (hash) - { - case 0X1FD33669ul: XOR = 0xDC00FEB1ul; break; - case 0X3B560BBFul: XOR = 0x2D1E4DBDul; break; - case 0X5D76CA77ul: XOR = 0xC1E8589Dul; break; - case 0X72E92068ul: XOR = 0x1A92B5F2ul; break; - case 0X9066971Eul: XOR = 0x3549742Dul; break; - case 0XB10C55B0ul: XOR = 0xF037EB98ul; break; - } - if (XOR) - { - Message("XOR: %#lX %#lX %#lX %#lX %#lX %#lX\n", hash, hash2^XOR, hash3^XOR, hash4^XOR, hash5^XOR, hash6^XOR); - } - -*/ - pTexture->Hash = hash; // note: this will only be done for original textures if (BoolSaveAllTextures) SaveTexture(pTexture); @@ -306,7 +241,7 @@ int OTM_TextureClient::SaveSingleTexture(bool val) int OTM_TextureClient::SetSaveDirectory( wchar_t *dir) { - Message("SetSaveDirectory( %ls): %lu\n", dir, this); + Message("OTM_TextureClient::SetSaveDirectory( %ls): %lu\n", dir, this); int i = 0; for (i=0; iHash, pTexture->m_D3Dtex, this); return (RETURN_TEXTURE_NOT_SAVED);} + Message("OTM_TextureClient::SaveTexture( %#lX, %lu): %lu\n", pTexture->Hash, pTexture->m_D3Dtex, this); + wchar_t file[MAX_PATH]; - swprintf_s( file, MAX_PATH, L"%ls\\%#lX.dds", SavePath, pTexture->Hash); + if (GameName[0]) swprintf_s( file, MAX_PATH, L"%ls\\%ls_%#lX.dds", SavePath, GameName, pTexture->Hash); + else swprintf_s( file, MAX_PATH, L"%ls\\%#lX.dds", SavePath, pTexture->Hash); + Message("OTM_TextureClient::SaveTexture( %ls ) \n", file); if (D3D_OK!=D3DXSaveTextureToFileW( file, D3DXIFF_DDS, pTexture->m_D3Dtex, NULL)) return (RETURN_TEXTURE_NOT_SAVED); + Message("OTM_TextureClient::SaveTexture( ) Done!\n", file); + return (RETURN_OK); } diff --git a/OTM_DX9/OTM_TextureClient.h b/OTM_DX9/OTM_TextureClient.h index 3676eca..95ad421 100644 --- a/OTM_DX9/OTM_TextureClient.h +++ b/OTM_DX9/OTM_TextureClient.h @@ -45,6 +45,7 @@ public: int SaveSingleTexture(bool val); //called from the Server int SetSaveDirectory( wchar_t *dir); //called from the Server + int SetGameName( wchar_t *dir); //called from the Server int SaveTexture(OTM_IDirect3DTexture9* pTexture); @@ -65,6 +66,7 @@ private: IDirect3DDevice9* D3D9Device; bool BoolSaveAllTextures; wchar_t SavePath[MAX_PATH]; + wchar_t GameName[MAX_PATH]; TextureFileStruct* Update; int NumberOfUpdate; diff --git a/OTM_DX9/OTM_TextureServer.cpp b/OTM_DX9/OTM_TextureServer.cpp index 45bb844..5288365 100644 --- a/OTM_DX9/OTM_TextureServer.cpp +++ b/OTM_DX9/OTM_TextureServer.cpp @@ -20,7 +20,7 @@ along with FooOpenTexMod. If not, see . #include "OTM_Main.h" -OTM_TextureServer::OTM_TextureServer(void) +OTM_TextureServer::OTM_TextureServer(wchar_t *game) { Message("OTM_TextureServer(void): %lu\n", this); Message("sizeof(unsigned long)=%lu\n", sizeof(unsigned long)); @@ -32,6 +32,10 @@ OTM_TextureServer::OTM_TextureServer(void) LenghtOfClients = 0; BoolSaveAllTextures = false; SavePath[0] = 0; + int i=0; + for (i=0; iSetGameName(GameName); /* DO NOT UNCOMMENT THIS some games create special devices before the rendering device is created. those device should not receive SaveSingleTexture(...) @@ -327,7 +331,7 @@ int OTM_TextureServer::SaveSingleTexture(bool val) // called from the server int OTM_TextureServer::SetSaveDirectory(wchar_t *dir) // called from the server { - Message("SetSaveDirectory( %ls): %lu\n", dir, this); + Message("OTM_TextureServer::SetSaveDirectory( %ls): %lu\n", dir, this); int i = 0; for (i = 0; i < MAX_PATH && (dir[i]); i++) SavePath[i] = dir[i]; if (i == MAX_PATH) @@ -598,7 +602,7 @@ int OTM_TextureServer::MainLoop(void) // run as a separated thread !! return (RETURN_OK); } -int OTM_TextureServer::OpenPipe(wchar_t *game) // called from InitInstance() +int OTM_TextureServer::OpenPipe(void) // called from InitInstance() { Message("OpenPipe: Out\n") // open first outgoing pipe !! @@ -614,11 +618,11 @@ int OTM_TextureServer::OpenPipe(wchar_t *game) // called from InitInstance() if (Pipe.Out == INVALID_HANDLE_VALUE) return (RETURN_PIPE_NOT_OPENED); unsigned int len = 0u; - while (game[len]) len++; + while (GameName[len]) len++; len++; //to send also the zero unsigned long num; //send name of this game to OTM_GUI - WriteFile(Pipe.Out, (const void*) game, len * sizeof(wchar_t), &num, NULL); + WriteFile(Pipe.Out, (const void*) GameName, len * sizeof(wchar_t), &num, NULL); Message("OpenPipe: In\n"); Pipe.In = CreateFileW(PIPE_OTM2Game, // pipe name diff --git a/OTM_DX9/OTM_TextureServer.h b/OTM_DX9/OTM_TextureServer.h index 03639a0..8b8155c 100644 --- a/OTM_DX9/OTM_TextureServer.h +++ b/OTM_DX9/OTM_TextureServer.h @@ -32,13 +32,13 @@ class OTM_TextureClient; class OTM_TextureServer { public: - OTM_TextureServer(void); + OTM_TextureServer(wchar_t *name); ~OTM_TextureServer(void); int AddClient(OTM_TextureClient *client, TextureFileStruct** update, int* number); int RemoveClient(OTM_TextureClient *client); - int OpenPipe( wchar_t *game); + int OpenPipe(void); int ClosePipe(void); int MainLoop(void); @@ -63,6 +63,7 @@ private: bool BoolSaveAllTextures; bool BoolSaveSingleTexture; wchar_t SavePath[MAX_PATH]; + wchar_t GameName[MAX_PATH]; int PropagateUpdate(OTM_TextureClient* client=NULL); int PrepareUpdate(TextureFileStruct** update, int* number);