mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-21 01:49:31 +00:00
BugFix:
-BoolSaveSingleTexture was not initialized on start of OTM_TextureServer Improvements: -add error handling for all operations in the GUI -colour support for font an switched texture (if save single texture is enabled)
This commit is contained in:
@@ -40,11 +40,15 @@ OTM_TextureServer* gl_TextureServer = NULL;
|
||||
FILE* gl_File =NULL;
|
||||
HANDLE gl_ServerThread = NULL;
|
||||
|
||||
BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
BOOL WINAPI DllMain( HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(lpReserved);
|
||||
|
||||
|
||||
/*
|
||||
Beep(300, 50);
|
||||
Beep(600, 50);
|
||||
Beep(900, 50);
|
||||
Beep(1200, 50);
|
||||
*/
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
|
||||
@@ -26,16 +26,13 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
|
||||
{
|
||||
if (SingleTexture==NULL) //Create green texture
|
||||
{
|
||||
if( D3D_OK != CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, (IDirect3DTexture9**) &SingleTexture, NULL)) return (RETURN_TEXTURE_NOT_LOADED);
|
||||
if( D3D_OK != CreateTexture(8, 8, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DTexture9**) &SingleTexture, NULL)) return (RETURN_TEXTURE_NOT_LOADED);
|
||||
LastCreatedTexture = NULL;
|
||||
SingleTexture->FAKE = true;
|
||||
SingleTexture->Reference = -2;
|
||||
|
||||
DWORD colour32 = D3DCOLOR_ARGB(255,0,255,0); //green
|
||||
WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
|
||||
|(WORD)(((colour32>>20)&0xF)<<8)
|
||||
|(WORD)(((colour32>>12)&0xF)<<4)
|
||||
|(WORD)(((colour32>>4)&0xF)<<0);
|
||||
|
||||
OTM_Client->TextureColour;
|
||||
TextureColour = OTM_Client->TextureColour;
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
IDirect3DTexture9 *pD3Dtex = SingleTexture->m_D3Dtex;
|
||||
|
||||
@@ -45,12 +42,11 @@ int OTM_IDirect3DDevice9::CreateSingleTexture(void)
|
||||
SingleTexture=NULL;
|
||||
return (RETURN_TEXTURE_NOT_LOADED);
|
||||
}
|
||||
WORD *pDst16 = (WORD*)d3dlr.pBits;
|
||||
DWORD *pDst = (DWORD*)d3dlr.pBits;
|
||||
|
||||
for (int xy=0; xy < 8*8; xy++) *(pDst16++) = colour16;
|
||||
for (int xy=0; xy < 8*8; xy++) *(pDst++) = TextureColour;
|
||||
pD3Dtex->UnlockRect(0);
|
||||
}
|
||||
|
||||
return (RETURN_OK);
|
||||
}
|
||||
|
||||
@@ -61,9 +57,12 @@ OTM_IDirect3DDevice9::OTM_IDirect3DDevice9(IDirect3DDevice9* pOriginal, OTM_Text
|
||||
OTM_Client = new OTM_TextureClient( OTM_Server, this);
|
||||
LastCreatedTexture = NULL;
|
||||
m_pIDirect3DDevice9 = pOriginal; // store the pointer to original object
|
||||
TextureColour = D3DCOLOR_ARGB(255,0,255,0);
|
||||
|
||||
CounterSaveSingleTexture = 0;
|
||||
CounterSaveSingleTexture = -1;
|
||||
SingleTexture = NULL;
|
||||
OSD_Font = NULL;
|
||||
FontColour = D3DCOLOR_ARGB(255,255,0,0);
|
||||
//Message("end OTM_IDirect3DDevice9( %lu, %lu): %lu\n", pOriginal, server, this);
|
||||
}
|
||||
|
||||
@@ -113,6 +112,7 @@ ULONG OTM_IDirect3DDevice9::Release(void)
|
||||
{
|
||||
//OTM_Client->ReleaseAllFakeTexture();
|
||||
if (SingleTexture!=NULL) SingleTexture->Release();
|
||||
if (OSD_Font!=NULL) OSD_Font->Release();
|
||||
delete OTM_Client;
|
||||
OTM_Client = NULL;
|
||||
}
|
||||
@@ -192,7 +192,8 @@ UINT OTM_IDirect3DDevice9::GetNumberOfSwapChains(void)
|
||||
|
||||
HRESULT OTM_IDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParameters)
|
||||
{
|
||||
return(m_pIDirect3DDevice9->Reset(pPresentationParameters));
|
||||
if(OSD_Font!=NULL) {OSD_Font->Release(); OSD_Font=NULL;} //the game will crashes if the font is not released before the game is minimized!
|
||||
return(m_pIDirect3DDevice9->Reset(pPresentationParameters));
|
||||
}
|
||||
|
||||
HRESULT OTM_IDirect3DDevice9::Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
|
||||
@@ -355,10 +356,26 @@ HRESULT OTM_IDirect3DDevice9::BeginScene(void)
|
||||
|
||||
if (SingleTexture!=NULL)
|
||||
{
|
||||
if (TextureColour!=OTM_Client->TextureColour)
|
||||
{
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
IDirect3DTexture9 *pD3Dtex;
|
||||
if (SingleTexture->CrossRef_D3Dtex==NULL) pD3Dtex = SingleTexture->m_D3Dtex;
|
||||
else pD3Dtex = SingleTexture->CrossRef_D3Dtex->m_D3Dtex;
|
||||
|
||||
if (D3D_OK==pD3Dtex->LockRect(0, &d3dlr, 0, 0))
|
||||
{
|
||||
DWORD *pDst = (DWORD*)d3dlr.pBits;
|
||||
TextureColour = OTM_Client->TextureColour;
|
||||
for (int xy=0; xy < 8*8; xy++) *(pDst++) = TextureColour;
|
||||
pD3Dtex->UnlockRect(0);
|
||||
}
|
||||
}
|
||||
if (OTM_Client->KeyBack>0 && (GetAsyncKeyState( OTM_Client->KeyBack ) &1) )
|
||||
{
|
||||
UnswitchTextures( SingleTexture);
|
||||
if (--CounterSaveSingleTexture<0) CounterSaveSingleTexture = OTM_Client->OriginalTextures.GetNumber() - 1;
|
||||
if (CounterSaveSingleTexture<0) CounterSaveSingleTexture = 0; //first initialization
|
||||
else if (--CounterSaveSingleTexture<0) CounterSaveSingleTexture = OTM_Client->OriginalTextures.GetNumber() - 1;
|
||||
if (CounterSaveSingleTexture >= 0) SwitchTextures( SingleTexture, OTM_Client->OriginalTextures[CounterSaveSingleTexture]);
|
||||
}
|
||||
if (OTM_Client->KeySave>0 && (GetAsyncKeyState( OTM_Client->KeySave ) &1) )
|
||||
@@ -370,17 +387,45 @@ HRESULT OTM_IDirect3DDevice9::BeginScene(void)
|
||||
if (OTM_Client->KeyNext>0 && (GetAsyncKeyState( OTM_Client->KeyNext ) &1) )
|
||||
{
|
||||
UnswitchTextures( SingleTexture);
|
||||
if (++CounterSaveSingleTexture>=OTM_Client->OriginalTextures.GetNumber()) CounterSaveSingleTexture = 0;
|
||||
if (CounterSaveSingleTexture<0) CounterSaveSingleTexture = 0; //first initialization
|
||||
else if (++CounterSaveSingleTexture>=OTM_Client->OriginalTextures.GetNumber()) CounterSaveSingleTexture = 0;
|
||||
if (CounterSaveSingleTexture < OTM_Client->OriginalTextures.GetNumber()) SwitchTextures( SingleTexture, OTM_Client->OriginalTextures[CounterSaveSingleTexture]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(m_pIDirect3DDevice9->BeginScene());
|
||||
Return_BeginScene = m_pIDirect3DDevice9->BeginScene();
|
||||
return (Return_BeginScene);
|
||||
//return (m_pIDirect3DDevice9->BeginScene());
|
||||
}
|
||||
|
||||
HRESULT OTM_IDirect3DDevice9::EndScene(void)
|
||||
{
|
||||
if ( Return_BeginScene==D3D_OK && OTM_Client!=NULL && OTM_Client->BoolSaveSingleTexture && SingleTexture!=NULL && SingleTexture->CrossRef_D3Dtex!=NULL)
|
||||
{
|
||||
if (OSD_Font==NULL || FontColour != OTM_Client->FontColour)
|
||||
{
|
||||
FontColour = OTM_Client->FontColour;
|
||||
if (OSD_Font!=NULL) OSD_Font->Release();
|
||||
if (D3D_OK!=D3DXCreateFontA( m_pIDirect3DDevice9, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &OSD_Font))
|
||||
{
|
||||
OSD_Font=NULL;
|
||||
return(m_pIDirect3DDevice9->EndScene());
|
||||
}
|
||||
}
|
||||
|
||||
char buffer[100];
|
||||
sprintf( buffer, "Actual texture: %4d (1..%d): %#lX", CounterSaveSingleTexture+1, OTM_Client->OriginalTextures.GetNumber(), SingleTexture->CrossRef_D3Dtex->Hash);
|
||||
D3DVIEWPORT9 viewport;
|
||||
GetViewport( &viewport);
|
||||
RECT rct;
|
||||
rct.left=viewport.X + 10;
|
||||
rct.right=0;
|
||||
rct.top=viewport.Y + 10;
|
||||
rct.bottom=0;
|
||||
OSD_Font->DrawTextA(NULL, buffer, -1, &rct, DT_NOCLIP, FontColour);
|
||||
|
||||
}
|
||||
//Message("EndScene(): %lu\n", this);
|
||||
return(m_pIDirect3DDevice9->EndScene());
|
||||
}
|
||||
|
||||
@@ -171,10 +171,14 @@ public:
|
||||
*/
|
||||
private:
|
||||
int CreateSingleTexture(void);
|
||||
|
||||
int CounterSaveSingleTexture;
|
||||
OTM_IDirect3DTexture9* SingleTexture;
|
||||
D3DCOLOR TextureColour;
|
||||
ID3DXFont *OSD_Font;
|
||||
D3DCOLOR FontColour;
|
||||
|
||||
|
||||
HRESULT Return_BeginScene;
|
||||
IDirect3DDevice9* m_pIDirect3DDevice9;
|
||||
OTM_IDirect3DTexture9* LastCreatedTexture;
|
||||
OTM_TextureServer* OTM_Server;
|
||||
|
||||
@@ -49,7 +49,7 @@ ULONG APIENTRY OTM_IDirect3DTexture9::Release()
|
||||
if (CrossRef_D3Dtex!=NULL)
|
||||
{
|
||||
OTM_IDirect3DTexture9 *fake_texture = CrossRef_D3Dtex;
|
||||
count = fake_texture->m_D3Dtex->Release();
|
||||
count = fake_texture->m_D3Dtex->Release(); //release the original texture
|
||||
if (count==0)
|
||||
{
|
||||
UnswitchTextures(this);
|
||||
|
||||
+6
-1
@@ -21,9 +21,14 @@ along with FooOpenTexMod. If not, see <http://www.gnu.org/licenses/>.
|
||||
#ifndef OTM_MAIN_H_
|
||||
#define OTM_MAIN_H_
|
||||
|
||||
#define WINVER _WIN32_WINNT_WINXP
|
||||
#define _WIN32_WINNT _WIN32_WINNT_WINXP
|
||||
#define _WIN32_WINDOWS _WIN32_WINNT_WINXP
|
||||
#define NTDDI_VERSION NTDDI_WINXP
|
||||
//#define NTDDI_LONGHORN NTDDI_WINXP
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
@@ -50,6 +50,8 @@ OTM_TextureClient::OTM_TextureClient(OTM_TextureServer* server, IDirect3DDevice9
|
||||
|
||||
Update = NULL;
|
||||
NumberOfUpdate = -1;
|
||||
FontColour = D3DCOLOR_ARGB(255,255,0,0);
|
||||
TextureColour = D3DCOLOR_ARGB(255,0,255,0);
|
||||
//Message("end OTM_TextureClient(void): %lu\n", this);
|
||||
}
|
||||
|
||||
@@ -75,7 +77,7 @@ int OTM_TextureClient::AddTexture( OTM_IDirect3DTexture9* pTexture)
|
||||
{
|
||||
((OTM_IDirect3DDevice9*)D3D9Device)->SetLastCreatedTexture(NULL); //a loop would arise if a texture would be switched
|
||||
if (pTexture->FAKE) return (RETURN_OK); // this is a fake texture
|
||||
Message("AddTexture( %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThread());
|
||||
Message("OTM_TextureClient::AddTexture( %lu): %lu (thread: %lu)\n", pTexture, this, GetCurrentThread());
|
||||
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
if (pTexture->LockRect( 0, &d3dlr, NULL, 0)!=D3D_OK)
|
||||
|
||||
@@ -54,6 +54,10 @@ public:
|
||||
int SetKeySave( int key) {if (key>0) KeySave = key; return (RETURN_OK);}
|
||||
int SetKeyNext( int key) {if (key>0) KeyNext = key; return (RETURN_OK);}
|
||||
|
||||
int SetFontColour( DWORD r, DWORD g, DWORD b) {FontColour = D3DCOLOR_ARGB(255, r,g,b); return (RETURN_OK);}
|
||||
int SetTextureColour( DWORD r, DWORD g, DWORD b) {TextureColour = D3DCOLOR_ARGB(255, r,g,b); return (RETURN_OK);}
|
||||
|
||||
|
||||
int AddUpdate(TextureFileStruct* update, int number); //client must delete the temp array
|
||||
int MergeUpdate(void);
|
||||
|
||||
@@ -66,6 +70,9 @@ public:
|
||||
int KeySave;
|
||||
int KeyNext;
|
||||
|
||||
D3DCOLOR FontColour;
|
||||
D3DCOLOR TextureColour;
|
||||
|
||||
private:
|
||||
OTM_TextureServer* Server;
|
||||
IDirect3DDevice9* D3D9Device;
|
||||
|
||||
@@ -31,6 +31,7 @@ OTM_TextureServer::OTM_TextureServer(wchar_t *game)
|
||||
NumberOfClients = 0;
|
||||
LenghtOfClients = 0;
|
||||
BoolSaveAllTextures = false;
|
||||
BoolSaveSingleTexture = false;
|
||||
SavePath[0] = 0;
|
||||
int i=0;
|
||||
for (i=0; i<MAX_PATH && (game[i]) && (game[i]!='.'); i++) GameName[i] = game[i];
|
||||
@@ -41,6 +42,9 @@ OTM_TextureServer::OTM_TextureServer(wchar_t *game)
|
||||
KeySave = 0;
|
||||
KeyNext = 0;
|
||||
|
||||
FontColour = 0u;
|
||||
TextureColour = 0u;
|
||||
|
||||
Pipe.In = INVALID_HANDLE_VALUE;
|
||||
Pipe.Out = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
@@ -83,6 +87,21 @@ int OTM_TextureServer::AddClient(OTM_TextureClient *client, TextureFileStruct**
|
||||
if (KeySave > 0) client->SetKeySave(KeySave);
|
||||
if (KeyNext > 0) client->SetKeyNext(KeyNext);
|
||||
|
||||
if (FontColour>0u)
|
||||
{
|
||||
DWORD r = (FontColour>>16)&0xFF;
|
||||
DWORD g = (FontColour>>8)&0xFF;
|
||||
DWORD b = (FontColour)&0xFF;
|
||||
client->SetFontColour( r, g, b);
|
||||
}
|
||||
if (TextureColour>0u)
|
||||
{
|
||||
DWORD r = (TextureColour>>16)&0xFF;
|
||||
DWORD g = (TextureColour>>8)&0xFF;
|
||||
DWORD b = (TextureColour)&0xFF;
|
||||
client->SetTextureColour( r, g, b);
|
||||
}
|
||||
|
||||
|
||||
if (int ret = PrepareUpdate( update, number)) return (ret);
|
||||
|
||||
@@ -397,6 +416,46 @@ int OTM_TextureServer::SetKeyNext(int key) // called from the server
|
||||
return (UnlockMutex());
|
||||
}
|
||||
|
||||
int OTM_TextureServer::SetFontColour(DWORD colour) // called from the server
|
||||
{
|
||||
if (colour==0u) return (RETURN_OK);
|
||||
if (int ret = LockMutex())
|
||||
{
|
||||
gl_ErrorState |= OTM_ERROR_SERVER;
|
||||
return (ret);
|
||||
}
|
||||
FontColour = colour;
|
||||
DWORD r = (FontColour>>16)&0xFF;
|
||||
DWORD g = (FontColour>>8)&0xFF;
|
||||
DWORD b = (FontColour)&0xFF;
|
||||
Message("OTM_TextureServer::SetFontColour( %u %u %u): %lu\n", r ,g ,b, this);
|
||||
for (int i = 0; i < NumberOfClients; i++)
|
||||
{
|
||||
Clients[i]->SetFontColour( r, g, b);
|
||||
}
|
||||
return (UnlockMutex());
|
||||
}
|
||||
|
||||
int OTM_TextureServer::SetTextureColour(DWORD colour) // called from the server
|
||||
{
|
||||
if (colour==0u) return (RETURN_OK);
|
||||
if (int ret = LockMutex())
|
||||
{
|
||||
gl_ErrorState |= OTM_ERROR_SERVER;
|
||||
return (ret);
|
||||
}
|
||||
TextureColour = colour;
|
||||
DWORD r = (TextureColour>>16)&0xFF;
|
||||
DWORD g = (TextureColour>>8)&0xFF;
|
||||
DWORD b = (TextureColour)&0xFF;
|
||||
Message("OTM_TextureServer::SetTextureColour( %u %u %u): %lu\n", r ,g ,b, this);
|
||||
for (int i = 0; i < NumberOfClients; i++)
|
||||
{
|
||||
Clients[i]->SetTextureColour( r, g, b);
|
||||
}
|
||||
return (UnlockMutex());
|
||||
}
|
||||
|
||||
int OTM_TextureServer::PropagateUpdate(OTM_TextureClient* client) // called from the server, send the update to all clients
|
||||
{
|
||||
Message("PropagateUpdate(%lu): %lu\n", client, this);
|
||||
@@ -575,6 +634,18 @@ int OTM_TextureServer::MainLoop(void) // run as a separated thread !!
|
||||
SetKeyNext(commands->Value);
|
||||
break;
|
||||
}
|
||||
case CONTROL_FONT_COLOUR:
|
||||
{
|
||||
Message("MainLoop: CONTROL_FONT_COLOUR (%#X): %lu\n", commands->Value, this);
|
||||
SetFontColour(commands->Value);
|
||||
break;
|
||||
}
|
||||
case CONTROL_TEXTURE_COLOUR:
|
||||
{
|
||||
Message("MainLoop: CONTROL_TEXTURE_COLOUR (%#X): %lu\n", commands->Value, this);
|
||||
SetTextureColour(commands->Value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Message("MainLoop: DEFAULT: %lu %lu %#lX\n", commands->Control, commands->Value, commands->Hash, this);
|
||||
|
||||
@@ -59,6 +59,9 @@ public:
|
||||
int SetKeySave( int key);
|
||||
int SetKeyNext( int key);
|
||||
|
||||
int SetFontColour(DWORD colour);
|
||||
int SetTextureColour(DWORD colour);
|
||||
|
||||
private:
|
||||
bool BoolSaveAllTextures;
|
||||
bool BoolSaveSingleTexture;
|
||||
@@ -76,6 +79,9 @@ private:
|
||||
int KeySave;
|
||||
int KeyNext;
|
||||
|
||||
DWORD FontColour;
|
||||
DWORD TextureColour;
|
||||
|
||||
HANDLE Mutex;
|
||||
|
||||
PipeStruct Pipe;
|
||||
|
||||
+4
-4
@@ -13,9 +13,9 @@ endif
|
||||
|
||||
CXX = cl
|
||||
CLINK = link.exe
|
||||
|
||||
CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PROXYDLL_EXPORTS" /D "_WINDLL" /D "_MBCS" /D "_AFXDLL" ${prcompiler_flag} /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t
|
||||
LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" /DLL "Winmm.lib" "d3dx9.lib" "user32.lib" "Kernel32.lib" ${def_file} /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86
|
||||
DEFINES = /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_MBCS"
|
||||
CFLAGS = /I "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include" /nologo /W3 /WX- /O2 ${DEFINES} ${prcompiler_flag} /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t
|
||||
LFLAGS = /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" /DLL "Winmm.lib" "d3dx9.lib" "user32.lib" "Kernel32.lib" ${def_file} /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE:NO /NXCOMPAT:NO /MACHINE:X86
|
||||
|
||||
obj = obj
|
||||
bin = bin
|
||||
@@ -64,4 +64,4 @@ ${obj}\OTM_TextureServer.${obj_suff}: OTM_TextureServer.cpp ${headers}
|
||||
${CXX} ${CFLAGS} /c $< /Fo$@
|
||||
|
||||
clean:
|
||||
del ${objects} ${bin}\d3d9.dll
|
||||
del ${objects} ${bin}\${dll}
|
||||
+57
-12
@@ -123,11 +123,47 @@ OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& si
|
||||
|
||||
Show( true );
|
||||
|
||||
/*
|
||||
wxString dx_dll;
|
||||
wchar_t buffer[MAX_PATH];
|
||||
if (NULL!=_wgetcwd( buffer, MAX_PATH))
|
||||
{
|
||||
dx_dll = buffer;
|
||||
dx_dll << "\\";
|
||||
}
|
||||
dx_dll << OTM_d3d9_dll;
|
||||
//dx_dll = "kernel32.dll";
|
||||
*/
|
||||
|
||||
HMODULE hMod = LoadLibraryW(OTM_d3d9_dll);
|
||||
typedef void (*fkt_typ)(void);
|
||||
fkt_typ InstallHook = (fkt_typ) GetProcAddress( hMod, "InstallHook");
|
||||
InstallHook();
|
||||
H_DX9_DLL = LoadLibraryW(OTM_d3d9_dll);
|
||||
if (H_DX9_DLL!=NULL)
|
||||
{
|
||||
typedef void (*fkt_typ)(void);
|
||||
fkt_typ InstallHook = (fkt_typ) GetProcAddress( H_DX9_DLL, "InstallHook");
|
||||
if (InstallHook!=NULL) InstallHook();
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
wchar_t *error_msg;
|
||||
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error_msg, 0, NULL );
|
||||
wxString temp = Language.Error_DLLNotFound;
|
||||
temp << "\n" << OTM_d3d9_dll;
|
||||
temp << "\n" << error_msg << "Code: " << error;
|
||||
wxMessageBox( temp, "ERROR", wxOK);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
wchar_t *error_msg;
|
||||
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error_msg, 0, NULL );
|
||||
wxString temp = Language.Error_DLLNotFound;
|
||||
temp << "\n" << OTM_d3d9_dll;
|
||||
temp << "\n" << error_msg << "Code: " << error;
|
||||
wxMessageBox(temp, "ERROR", wxOK);
|
||||
}
|
||||
}
|
||||
|
||||
OTM_Frame::~OTM_Frame(void)
|
||||
@@ -140,11 +176,13 @@ OTM_Frame::~OTM_Frame(void)
|
||||
Server = NULL;
|
||||
}
|
||||
|
||||
HMODULE hMod = LoadLibraryW( OTM_d3d9_dll);
|
||||
typedef void (*fkt_typ)(void);
|
||||
fkt_typ RemoveHook = (fkt_typ) GetProcAddress( hMod, "RemoveHook");
|
||||
RemoveHook();
|
||||
FreeLibrary(hMod);
|
||||
if (H_DX9_DLL!=NULL)
|
||||
{
|
||||
typedef void (*fkt_typ)(void);
|
||||
fkt_typ RemoveHook = (fkt_typ) GetProcAddress( H_DX9_DLL, "RemoveHook");
|
||||
if (RemoveHook!=NULL) RemoveHook();
|
||||
FreeLibrary(H_DX9_DLL);
|
||||
}
|
||||
|
||||
if (Clients!=NULL) delete [] Clients;
|
||||
}
|
||||
@@ -215,7 +253,6 @@ void OTM_Frame::OnClose(wxCloseEvent& event)
|
||||
{
|
||||
if (event.CanVeto() && NumberOfGames>0)
|
||||
{
|
||||
|
||||
if (wxMessageBox(Language.ExitGameAnyway, "ERROR", wxYES_NO)!=wxYES) {event.Veto(); return;}
|
||||
}
|
||||
event.Skip();
|
||||
@@ -254,7 +291,11 @@ void OTM_Frame::OnButtonUpdate(wxCommandEvent& WXUNUSED(event))
|
||||
if (Notebook->GetPageCount()==0) return;
|
||||
OTM_GamePage *page = (OTM_GamePage*) Notebook->GetCurrentPage();
|
||||
if (page==NULL) return;
|
||||
page->UpdateGame();
|
||||
if (page->UpdateGame())
|
||||
{
|
||||
wxMessageBox(page->LastError, "ERROR", wxOK);
|
||||
page->LastError.Empty();
|
||||
}
|
||||
}
|
||||
|
||||
void OTM_Frame::OnButtonSave(wxCommandEvent& WXUNUSED(event))
|
||||
@@ -262,7 +303,11 @@ void OTM_Frame::OnButtonSave(wxCommandEvent& WXUNUSED(event))
|
||||
if (Notebook->GetPageCount()==0) return;
|
||||
OTM_GamePage *page = (OTM_GamePage*) Notebook->GetCurrentPage();
|
||||
if (page==NULL) return;
|
||||
page->SaveToFile();
|
||||
if (page->SaveToFile())
|
||||
{
|
||||
wxMessageBox(page->LastError, "ERROR", wxOK);
|
||||
page->LastError.Empty();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -79,6 +79,7 @@ private:
|
||||
int NumberOfGames;
|
||||
int MaxNumberOfGames;
|
||||
OTM_Client **Clients;
|
||||
HMODULE H_DX9_DLL;
|
||||
|
||||
DECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
||||
@@ -45,6 +45,8 @@ void OTM_GameInfo::Init(void)
|
||||
KeyBack = -1;
|
||||
KeySave = -1;
|
||||
KeyNext = -1;
|
||||
FontColour[0]=255;FontColour[1]=0;FontColour[2]=0;
|
||||
TextureColour[0]=0;TextureColour[1]=255;TextureColour[2]=0;
|
||||
NumberOfChecked = 0;
|
||||
SavePath.Empty();
|
||||
OpenPath.Empty();
|
||||
@@ -74,7 +76,7 @@ int OTM_GameInfo::SaveToFile( const wxString &file_name)
|
||||
file.Write( content.char_str(), content.Len());
|
||||
}
|
||||
|
||||
content.Printf( L"SaveAllTextures:%d\nSaveSingeTexture:%d\n", SaveAllTextures, SaveSingleTexture);
|
||||
content.Printf( L"SaveAllTextures:%d\nSaveSingleTexture:%d\n", SaveAllTextures, SaveSingleTexture);
|
||||
file.Write( content.char_str(), content.Len());
|
||||
|
||||
if (KeyBack>=0)
|
||||
@@ -93,6 +95,11 @@ int OTM_GameInfo::SaveToFile( const wxString &file_name)
|
||||
file.Write( content.char_str(), content.Len());
|
||||
}
|
||||
|
||||
content.Printf( L"FontColour:%d,%d,%d\n", FontColour[0], FontColour[1], FontColour[2]);
|
||||
file.Write( content.char_str(), content.Len());
|
||||
content.Printf( L"TextureColour:%d,%d,%d\n", TextureColour[0], TextureColour[1], TextureColour[2]);
|
||||
file.Write( content.char_str(), content.Len());
|
||||
|
||||
int num = Textures.GetCount();
|
||||
|
||||
for (int i=0; i<num; i++)
|
||||
@@ -206,6 +213,40 @@ int OTM_GameInfo::LoadFromFile( const wxString &file_name)
|
||||
if (temp.ToLong( &key)) KeyNext = key;
|
||||
else KeyNext = -1;
|
||||
}
|
||||
else if (command == L"FontColour")
|
||||
{
|
||||
temp = line.AfterFirst(':');
|
||||
temp = temp.BeforeFirst(',');
|
||||
long colour;
|
||||
if (temp.ToLong( &colour)) FontColour[0] = colour;
|
||||
else FontColour[0] = 255;
|
||||
temp = line.AfterFirst(':');
|
||||
temp = temp.AfterFirst(',');
|
||||
temp = temp.BeforeFirst(',');
|
||||
if (temp.ToLong( &colour)) FontColour[1] = colour;
|
||||
else FontColour[1] = 0;
|
||||
temp = line.AfterFirst(':');
|
||||
temp = temp.AfterLast(',');
|
||||
if (temp.ToLong( &colour)) FontColour[2] = colour;
|
||||
else FontColour[2] = 0;
|
||||
}
|
||||
else if (command == L"TextureColour")
|
||||
{
|
||||
temp = line.AfterFirst(':');
|
||||
temp = temp.BeforeFirst(',');
|
||||
long colour;
|
||||
if (temp.ToLong( &colour)) TextureColour[0] = colour;
|
||||
else TextureColour[0] = 0;
|
||||
temp = line.AfterFirst(':');
|
||||
temp = temp.AfterFirst(',');
|
||||
temp = temp.BeforeFirst(',');
|
||||
if (temp.ToLong( &colour)) TextureColour[1] = colour;
|
||||
else TextureColour[1] = 255;
|
||||
temp = line.AfterFirst(':');
|
||||
temp = temp.AfterLast(',');
|
||||
if (temp.ToLong( &colour)) TextureColour[2] = colour;
|
||||
else TextureColour[2] = 0;
|
||||
}
|
||||
|
||||
|
||||
if (NumberOfChecked>=LengthOfChecked)
|
||||
@@ -291,6 +332,9 @@ OTM_GameInfo& OTM_GameInfo::operator = (const OTM_GameInfo &rhs)
|
||||
OpenPath = rhs.OpenPath;
|
||||
Textures = rhs.Textures;
|
||||
|
||||
for (int i=0; i<3; i++) FontColour[i]=rhs.FontColour[i];
|
||||
for (int i=0; i<3; i++) TextureColour[i]=rhs.TextureColour[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,12 @@ public:
|
||||
int GetKeyNext() const {return KeyNext;}
|
||||
int SetKeyNext(int key) {KeyNext=key; return 0;}
|
||||
|
||||
int SetFontColour(const int *colour) {FontColour[0]=colour[0];FontColour[1]=colour[1];FontColour[2]=colour[2];return 0;}
|
||||
int GetFontColour(int *colour) const {colour[0]=FontColour[0];colour[1]=FontColour[1];colour[2]=FontColour[2];return 0;}
|
||||
|
||||
int SetTextureColour(const int *colour) {TextureColour[0]=colour[0];TextureColour[1]=colour[1];TextureColour[2]=colour[2];return 0;}
|
||||
int GetTextureColour(int *colour) const {colour[0]=TextureColour[0];colour[1]=TextureColour[1];colour[2]=TextureColour[2];return 0;}
|
||||
|
||||
int SetOpenPath(const wxString &path) {OpenPath=path; return 0;}
|
||||
wxString GetOpenPath(void) const {return OpenPath;}
|
||||
|
||||
@@ -86,6 +92,9 @@ private:
|
||||
int KeySave;
|
||||
int KeyNext;
|
||||
|
||||
int FontColour[3];
|
||||
int TextureColour[3];
|
||||
|
||||
wxString OpenPath;
|
||||
wxString SavePath;
|
||||
};
|
||||
|
||||
@@ -55,6 +55,25 @@ OTM_GamePage::OTM_GamePage( wxNotebook *parent, const wxString &name, PipeStruct
|
||||
MainSizer->Add( SizerKeys[0], 0, wxEXPAND, 0);
|
||||
MainSizer->Add( SizerKeys[1], 0, wxEXPAND, 0);
|
||||
|
||||
|
||||
FontColourSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
FontColour[0] = new wxTextCtrl(this, wxID_ANY, Language.FontColour, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
|
||||
FontColour[1] = new wxTextCtrl(this, wxID_ANY, "255", wxDefaultPosition, wxDefaultSize);
|
||||
FontColour[2] = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize);
|
||||
FontColour[3] = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize);
|
||||
for (int i=0; i<4; i++) FontColourSizer->Add( (wxWindow*) FontColour[i], 1, wxEXPAND, 0);
|
||||
|
||||
TextureColourSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
TextureColour[0] = new wxTextCtrl(this, wxID_ANY, Language.TextureColour, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
|
||||
TextureColour[1] = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize);
|
||||
TextureColour[2] = new wxTextCtrl(this, wxID_ANY, "255", wxDefaultPosition, wxDefaultSize);
|
||||
TextureColour[3] = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize);
|
||||
for (int i=0; i<4; i++) TextureColourSizer->Add( (wxWindow*) TextureColour[i], 1, wxEXPAND, 0);
|
||||
|
||||
|
||||
MainSizer->Add( FontColourSizer, 0, wxEXPAND, 0);
|
||||
MainSizer->Add( TextureColourSizer, 0, wxEXPAND, 0);
|
||||
|
||||
SaveSingleTexture = new wxCheckBox( this, -1, Language.CheckBoxSaveSingleTexture);
|
||||
MainSizer->Add( (wxWindow*) SaveSingleTexture, 0, wxEXPAND, 0);
|
||||
|
||||
@@ -92,6 +111,12 @@ OTM_GamePage::OTM_GamePage( wxNotebook *parent, const wxString &name, PipeStruct
|
||||
key = Game.GetKeyNext();
|
||||
if (key>=0) ChoiceKeyNext->SetSelection( key);
|
||||
|
||||
int colour[3];
|
||||
Game.GetFontColour( colour);
|
||||
SetColour( &FontColour[1], colour);
|
||||
Game.GetTextureColour( colour);
|
||||
SetColour( &TextureColour[1], colour);
|
||||
|
||||
SaveSingleTexture->SetValue( Game.GetSaveSingleTexture());
|
||||
SaveAllTextures->SetValue( Game.GetSaveAllTextures());
|
||||
|
||||
@@ -213,16 +238,59 @@ int OTM_GamePage::UpdateGame(void)
|
||||
key = ChoiceKeyNext->GetSelection();
|
||||
if (key!=wxNOT_FOUND) Game.SetKeyNext(key);
|
||||
|
||||
int colour[3];
|
||||
colour[0] = GetColour( FontColour[1], 255);
|
||||
colour[1] = GetColour( FontColour[2], 0);
|
||||
colour[2] = GetColour( FontColour[3], 0);
|
||||
SetColour( &FontColour[1], colour);
|
||||
Game.SetFontColour(colour);
|
||||
|
||||
colour[0] = GetColour( TextureColour[1], 0);
|
||||
colour[1] = GetColour( TextureColour[2], 255);
|
||||
colour[2] = GetColour( TextureColour[3], 0);
|
||||
SetColour( &TextureColour[1], colour);
|
||||
Game.SetTextureColour(colour);
|
||||
|
||||
bool *checked = new bool[NumberOfEntry];
|
||||
for (int i=0; i<NumberOfEntry; i++) checked[i] = CheckBoxes[i]->GetValue();
|
||||
Game.SetChecked( checked, NumberOfEntry);
|
||||
delete [] checked;
|
||||
|
||||
if (int ret = Sender.Send( Game, GameOld)) return ret;
|
||||
if (int ret = Sender.Send( Game, GameOld))
|
||||
{
|
||||
LastError = Language.Error_Send;
|
||||
LastError << "\n" << Sender.LastError;
|
||||
Sender.LastError.Empty();
|
||||
return ret;
|
||||
}
|
||||
|
||||
GameOld = Game;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int OTM_GamePage::SetColour( wxTextCtrl** txt, int *colour)
|
||||
{
|
||||
wxString temp;
|
||||
for (int i=0; i<3; i++)
|
||||
{
|
||||
temp.Empty();
|
||||
temp << colour[i];
|
||||
txt[i]->SetValue( temp);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int OTM_GamePage::GetColour( wxTextCtrl* txt, int def)
|
||||
{
|
||||
wxString temp = txt->GetValue();
|
||||
long colour;
|
||||
if (temp.ToLong(&colour))
|
||||
{
|
||||
if (colour<0) colour=0;
|
||||
else if (colour>255) colour=255;
|
||||
}
|
||||
else colour = def;
|
||||
return colour;
|
||||
}
|
||||
|
||||
int OTM_GamePage::SaveToFile( const wxString &file_name)
|
||||
{
|
||||
@@ -238,12 +306,31 @@ int OTM_GamePage::SaveToFile( const wxString &file_name)
|
||||
key = ChoiceKeyNext->GetSelection();
|
||||
if (key!=wxNOT_FOUND) Game.SetKeyNext(key);
|
||||
|
||||
int colour[3];
|
||||
colour[0] = GetColour( FontColour[1], 255);
|
||||
colour[1] = GetColour( FontColour[2], 0);
|
||||
colour[2] = GetColour( FontColour[3], 0);
|
||||
SetColour( &FontColour[1], colour);
|
||||
Game.SetFontColour(colour);
|
||||
|
||||
colour[0] = GetColour( TextureColour[1], 0);
|
||||
colour[1] = GetColour( TextureColour[2], 255);
|
||||
colour[2] = GetColour( TextureColour[3], 0);
|
||||
SetColour( &TextureColour[1], colour);
|
||||
Game.SetTextureColour(colour);
|
||||
|
||||
bool *checked = new bool[NumberOfEntry];
|
||||
for (int i=0; i<NumberOfEntry; i++) checked[i] = CheckBoxes[i]->GetValue();
|
||||
Game.SetChecked( checked, NumberOfEntry);
|
||||
delete [] checked;
|
||||
|
||||
return Game.SaveToFile( file_name);
|
||||
if (int ret = Game.SaveToFile( file_name))
|
||||
{
|
||||
LastError = Language.Error_SaveFile;
|
||||
LastError <<"\n" << file_name;
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,11 @@ public:
|
||||
void OnButtonDown(wxCommandEvent& WXUNUSED(event));
|
||||
void OnButtonDelete(wxCommandEvent& WXUNUSED(event));
|
||||
|
||||
wxString LastError;
|
||||
|
||||
private:
|
||||
int SetColour( wxTextCtrl** txt, int *colour);
|
||||
int GetColour( wxTextCtrl* txt, int def);
|
||||
|
||||
wxBoxSizer *SizerKeys[2];
|
||||
wxTextCtrl *TextKeyBack;
|
||||
@@ -60,6 +64,11 @@ private:
|
||||
wxChoice *ChoiceKeySave;
|
||||
wxChoice *ChoiceKeyNext;
|
||||
|
||||
wxBoxSizer *FontColourSizer;
|
||||
wxTextCtrl *FontColour[4];
|
||||
wxBoxSizer *TextureColourSizer;
|
||||
wxTextCtrl *TextureColour[4];
|
||||
|
||||
wxBoxSizer *MainSizer;
|
||||
wxCheckBox *SaveAllTextures;
|
||||
wxCheckBox *SaveSingleTexture;
|
||||
|
||||
@@ -58,6 +58,25 @@ int OTM_Language::LoadLanguage(int lang)
|
||||
GameAlreadyAdded = L"Game has been already added.";
|
||||
FileNotSupported = L"This file type is not supported:\n";
|
||||
ExitGameAnyway = L"Closing OpenTexMod while a game is running might lead to a crash of the game.\nExit anyway?";
|
||||
|
||||
Error_DLLNotFound = L"Could not load the dll.\nThe dll injection won't work.\nThis might happen if D3DX9_43.dll is not installed on your system.\nPlease install the newest DirectX End-User Runtime Web Installer.";
|
||||
Error_FktNotFound = L"Could not load function out of dll.\nThe dll injection won't work.";
|
||||
|
||||
Error_Send = L"Could not send to game.";
|
||||
Error_SaveFile = L"Could not save to file.";
|
||||
Error_NoPipe = L"Pipe is not opened.";
|
||||
Error_WritePipe = L"Could not write in pipe.";
|
||||
Error_FlushPipe = L"Could not flush pipe buffer.";
|
||||
Error_Hash = L"Could not find hash, maybe file is not named as *_HASH.dds";
|
||||
Error_FileOpen = L"Could not open file.";
|
||||
Error_FileRead = L"Could not read file.";
|
||||
Error_Memory = L"Could not allocate enough memory";
|
||||
Error_FileformatNotSupported = L"This file format is not supported.";
|
||||
Error_Unzip = L"Could not unzip.";
|
||||
Error_ZipEntry = L"Could not find zip entry.";
|
||||
|
||||
FontColour = L"Font colour (RGB):";
|
||||
TextureColour = L"Texture colour (RGB):";
|
||||
}
|
||||
|
||||
LoadKeys(lang);
|
||||
|
||||
@@ -58,6 +58,20 @@ public:
|
||||
wxString FileNotSupported;
|
||||
wxString ExitGameAnyway;
|
||||
|
||||
wxString Error_FktNotFound;
|
||||
wxString Error_DLLNotFound;
|
||||
wxString Error_Send;
|
||||
wxString Error_SaveFile;
|
||||
wxString Error_NoPipe;
|
||||
wxString Error_WritePipe;
|
||||
wxString Error_FlushPipe;
|
||||
wxString Error_Hash;
|
||||
wxString Error_FileOpen;
|
||||
wxString Error_FileRead;
|
||||
wxString Error_Memory;
|
||||
wxString Error_FileformatNotSupported;
|
||||
wxString Error_Unzip;
|
||||
wxString Error_ZipEntry;
|
||||
|
||||
wxString KeyBack;
|
||||
wxString KeySave;
|
||||
@@ -65,6 +79,10 @@ public:
|
||||
wxArrayString KeyStrings;
|
||||
wxArrayInt KeyValues;
|
||||
|
||||
|
||||
wxString FontColour;
|
||||
wxString TextureColour;
|
||||
|
||||
private:
|
||||
int LoadKeys(int lang);
|
||||
};
|
||||
|
||||
+8
-1
@@ -41,6 +41,12 @@ along with FooOpenTexMod. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define wxUSE_TEXTCTRL 1
|
||||
#define wxUSE_CHOICEDLG 1
|
||||
#endif
|
||||
#define wxUSE_DYNLIB_CLASS 1
|
||||
|
||||
#define WINVER _WIN32_WINNT_WINXP
|
||||
#define _WIN32_WINNT _WIN32_WINNT_WINXP
|
||||
#define NTDDI_VERSION NTDDI_WINXP
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
|
||||
#include "wx\wx.h"
|
||||
@@ -48,6 +54,7 @@ along with FooOpenTexMod. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <wx/file.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/tokenzr.h>
|
||||
#include <wx/dynlib.h>
|
||||
//#include <wx/thread.h>
|
||||
//#include "wx/checkbox.h"
|
||||
//#include <wx/msgdlg.h>
|
||||
@@ -58,7 +65,7 @@ along with FooOpenTexMod. If not, see <http://www.gnu.org/licenses/>.
|
||||
//#include <wx/textctrl.h>
|
||||
//#include <wx/choicdlg.h>
|
||||
|
||||
#include <windows.h>
|
||||
//#include <windows.h>
|
||||
|
||||
#include "../OTM_GlobalDefines.h"
|
||||
#include "../OTM_Error.h"
|
||||
|
||||
+66
-24
@@ -83,6 +83,7 @@ OTM_Sender::~OTM_Sender(void)
|
||||
|
||||
int OTM_Sender::Send( const OTM_GameInfo &game, const OTM_GameInfo &game_old)
|
||||
{
|
||||
LastError.Empty();
|
||||
int key = game.GetKeyBack();
|
||||
if (key>=0 && key!=game_old.GetKeyBack())
|
||||
{
|
||||
@@ -102,6 +103,24 @@ int OTM_Sender::Send( const OTM_GameInfo &game, const OTM_GameInfo &game_old)
|
||||
SendKey( key, CONTROL_KEY_NEXT);
|
||||
}
|
||||
|
||||
int colour[3], colour_old[3];
|
||||
game.GetFontColour( colour);
|
||||
game_old.GetFontColour( colour_old);
|
||||
for (int i=0; i<3; i++) if (colour[i]!=colour_old[i])
|
||||
{
|
||||
SendColour( colour, CONTROL_FONT_COLOUR);
|
||||
break;
|
||||
}
|
||||
|
||||
game.GetTextureColour( colour);
|
||||
game_old.GetTextureColour( colour_old);
|
||||
for (int i=0; i<3; i++) if (colour[i]!=colour_old[i])
|
||||
{
|
||||
SendColour( colour, CONTROL_TEXTURE_COLOUR);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ( game.GetSaveSingleTexture() != game_old.GetSaveSingleTexture() ) SendSaveSingleTexture( game.GetSaveSingleTexture());
|
||||
if ( game.GetSaveAllTextures() != game_old.GetSaveAllTextures() ) SendSaveAllTextures(game.GetSaveAllTextures());
|
||||
|
||||
@@ -111,7 +130,11 @@ int OTM_Sender::Send( const OTM_GameInfo &game, const OTM_GameInfo &game_old)
|
||||
|
||||
|
||||
// the rest of this function is not optimized !!
|
||||
if (game.GetNumberOfTextures()<=0) return 0;
|
||||
if (game.GetNumberOfTextures()<=0)
|
||||
{
|
||||
if (LastError.Len()>0) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
wxArrayString textures;
|
||||
|
||||
@@ -149,7 +172,10 @@ int OTM_Sender::Send( const OTM_GameInfo &game, const OTM_GameInfo &game_old)
|
||||
wxMessageBox(msg, "ERROR", wxOK);
|
||||
}
|
||||
}
|
||||
return SendTextures( num, tex);
|
||||
SendTextures( num, tex);
|
||||
|
||||
if (LastError.Len()>0) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +249,8 @@ int OTM_Sender::SendTextures(unsigned int num, AddTextureClass *tex)
|
||||
delete [] hash;
|
||||
if (pos) if (int ret = SendToGame( Buffer, pos)) return ret;
|
||||
|
||||
return 0;
|
||||
if (LastError.Len()>0) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +264,18 @@ int OTM_Sender::SendKey(int key, int ctr)
|
||||
return SendToGame( (void*) &msg, sizeof(MsgStruct));
|
||||
}
|
||||
|
||||
#define D3DCOLOR_ARGB(a,r,g,b) ((DWORD)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
|
||||
|
||||
int OTM_Sender::SendColour( int* colour, int ctr)
|
||||
{
|
||||
MsgStruct msg;
|
||||
msg.Control = ctr;
|
||||
msg.Value = D3DCOLOR_ARGB( 255, colour[0], colour[1], colour[2]);
|
||||
msg.Hash = 0u;
|
||||
|
||||
return SendToGame( (void*) &msg, sizeof(MsgStruct));
|
||||
}
|
||||
#undef D3DCOLOR_ARGB
|
||||
|
||||
|
||||
int OTM_Sender::SendPath( const wxString &path)
|
||||
@@ -263,10 +301,10 @@ int OTM_Sender::SendToGame( void *msg, unsigned long len)
|
||||
{
|
||||
if (len==0) return (RETURN_BAD_ARGUMENT);
|
||||
unsigned long num;
|
||||
if (Pipe.Out==INVALID_HANDLE_VALUE) return -1;
|
||||
if (Pipe.Out==INVALID_HANDLE_VALUE) {LastError << Language.Error_NoPipe; return -1;}
|
||||
bool ret = WriteFile( Pipe.Out, (const void*) msg, len, &num, NULL);
|
||||
if (!ret || len!=num) return -1;
|
||||
if (!FlushFileBuffers(Pipe.Out)) return -1;
|
||||
if (!ret || len!=num) {LastError << Language.Error_WritePipe; return -1;}
|
||||
if (!FlushFileBuffers(Pipe.Out)) {LastError << Language.Error_FlushPipe; return -1;}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -278,24 +316,24 @@ int OTM_Sender::AddFile( AddTextureClass *tex, wxString file, bool add, bool for
|
||||
|
||||
wxString name = file.AfterLast( '_');
|
||||
name = name.BeforeLast( '.');
|
||||
if (!name.ToULong( &temp_hash, 16)) return -1; // return if hash could not be extracted
|
||||
if (!name.ToULong( &temp_hash, 16)) {LastError << Language.Error_Hash <<"\n" << file; return -1;} // return if hash could not be extracted
|
||||
|
||||
tex->Add[0] = add;
|
||||
if (add)
|
||||
{
|
||||
wxFile dat;
|
||||
if (!dat.Access(name, wxFile::read)) return -1;
|
||||
if (!dat.Access(name, wxFile::read)) {LastError << Language.Error_FileOpen <<"\n" << file; return -1;}
|
||||
dat.Open(file, wxFile::read);
|
||||
if (!dat.IsOpened()) {return -1;}
|
||||
if (!dat.IsOpened()) {LastError << Language.Error_FileOpen <<"\n" << file; return -1;}
|
||||
unsigned len = file.Length();
|
||||
|
||||
try {tex->Textures[0] = new char [len];}
|
||||
catch (...) {tex->Textures[0] = NULL; return -1;}
|
||||
catch (...) {tex->Textures[0] = NULL; LastError << Language.Error_Memory; return -1;}
|
||||
|
||||
unsigned int result = dat.Read( (void*) tex->Textures[0], len);
|
||||
dat.Close();
|
||||
|
||||
if (result != len) return -1;
|
||||
if (result != len) {LastError << Language.Error_FileRead <<"\n" << file; return -1;}
|
||||
tex->Size[0] = len;
|
||||
}
|
||||
else {tex->Size[0] = 0; tex->Textures[0] = NULL;}
|
||||
@@ -309,19 +347,19 @@ int OTM_Sender::AddFile( AddTextureClass *tex, wxString file, bool add, bool for
|
||||
int OTM_Sender::AddZip( AddTextureClass *tex, wxString file, bool add, bool force, bool tpf)
|
||||
{
|
||||
wxFile dat;
|
||||
if (!dat.Access(file, wxFile::read)) return -1;
|
||||
if (!dat.Access(file, wxFile::read)) {LastError << Language.Error_FileOpen <<"\n" << file; return -1;}
|
||||
dat.Open(file, wxFile::read);
|
||||
if (!dat.IsOpened()) {return -1;}
|
||||
if (!dat.IsOpened()) {LastError << Language.Error_FileOpen <<"\n" << file; return -1;}
|
||||
unsigned len = dat.Length();
|
||||
|
||||
unsigned char* buffer;
|
||||
try {buffer = new unsigned char [len];}
|
||||
catch (...) {return -1;}
|
||||
catch (...) {LastError << Language.Error_Memory; return -1;}
|
||||
|
||||
unsigned int result = dat.Read( buffer, len);
|
||||
dat.Close();
|
||||
|
||||
if (result != len) return -1;
|
||||
if (result != len) {LastError << Language.Error_FileRead<<"\n" << file; return -1;}
|
||||
|
||||
if (tpf)
|
||||
{
|
||||
@@ -379,7 +417,7 @@ int OTM_Sender::AddContent( char* buffer, unsigned int len, const char* pw, AddT
|
||||
char* def;
|
||||
int len = ze.unc_size;
|
||||
try {def=new char[len+1];}
|
||||
catch(...) {CloseZip(hz); return -1;}
|
||||
catch(...) {CloseZip(hz); LastError << Language.Error_Memory; return -1;}
|
||||
ZRESULT zr = UnzipItem( hz,index, def, len);
|
||||
|
||||
if (zr!=ZR_OK && zr!=ZR_MORE) {delete [] def; CloseZip(hz); return -1;}
|
||||
@@ -396,32 +434,34 @@ int OTM_Sender::AddContent( char* buffer, unsigned int len, const char* pw, AddT
|
||||
int pos = 0;
|
||||
int count = 0;
|
||||
wxString entry;
|
||||
wxString conv;
|
||||
wxString file;
|
||||
|
||||
for (int i=0; i<num; i++)
|
||||
{
|
||||
entry = token.GetNextToken();
|
||||
conv = entry.BeforeFirst( '|');
|
||||
if (!conv.ToULong( &temp_hash, 16)) continue;
|
||||
file = entry.BeforeFirst( '|');
|
||||
if (!file.ToULong( &temp_hash, 16)) {LastError << Language.Error_Hash <<"\nTPF:" << file; continue;}
|
||||
|
||||
conv = entry.AfterFirst( '|');
|
||||
conv.Replace( "\r", "");
|
||||
file = entry.AfterFirst( '|');
|
||||
file.Replace( "\r", "");
|
||||
|
||||
if (add)
|
||||
{
|
||||
FindZipItem( hz, conv.wc_str(), false, &index, &ze); // look for texture
|
||||
FindZipItem( hz, file.wc_str(), false, &index, &ze); // look for texture
|
||||
if (index>=0)
|
||||
{
|
||||
try {tex->Textures[count] = new char[ze.unc_size];}
|
||||
catch(...)
|
||||
{
|
||||
tex->Textures[count] = NULL;
|
||||
LastError << Language.Error_Memory;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ZR_OK!=UnzipItem( hz, index, tex->Textures[count], ze.unc_size))
|
||||
{
|
||||
delete [] tex->Textures[count];
|
||||
LastError << Language.Error_Unzip <<"\nTPF:" << file;
|
||||
tex->Textures[count] = NULL;
|
||||
}
|
||||
else
|
||||
@@ -461,11 +501,11 @@ int OTM_Sender::AddContent( char* buffer, unsigned int len, const char* pw, AddT
|
||||
file = ze.name;
|
||||
|
||||
name = file.AfterLast( '.');
|
||||
if (name!="dds") continue; //if this is not texture file, continue
|
||||
if (name!="dds") {LastError << Language.Error_FileformatNotSupported <<"\nZIP: " << file; continue;} //if this is not texture file, continue
|
||||
|
||||
name = file.AfterLast( '_');
|
||||
name = name.BeforeLast( '.');
|
||||
if (!name.ToULong( &temp_hash, 16)) continue; //if hash couldt not be extracted
|
||||
if (!name.ToULong( &temp_hash, 16)) {LastError << Language.Error_Hash <<"\nZIP:" << file; continue;} //if hash couldt not be extracted
|
||||
|
||||
if (add)
|
||||
{
|
||||
@@ -473,6 +513,7 @@ int OTM_Sender::AddContent( char* buffer, unsigned int len, const char* pw, AddT
|
||||
catch(...)
|
||||
{
|
||||
tex->Textures[count] = NULL;
|
||||
LastError << Language.Error_Memory;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -480,6 +521,7 @@ int OTM_Sender::AddContent( char* buffer, unsigned int len, const char* pw, AddT
|
||||
if (ZR_OK!=rz)
|
||||
{
|
||||
delete [] tex->Textures[count];
|
||||
LastError << Language.Error_Unzip <<"\nZIP:" << file;
|
||||
tex->Textures[count] = NULL;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -49,6 +49,9 @@ public:
|
||||
|
||||
int Send( const OTM_GameInfo &game, const OTM_GameInfo &game_old);
|
||||
|
||||
wxString LastError;
|
||||
|
||||
private:
|
||||
int SendSaveAllTextures(bool val);
|
||||
int SendSaveSingleTexture(bool val);
|
||||
|
||||
@@ -58,7 +61,7 @@ public:
|
||||
|
||||
int SendPath( const wxString &path);
|
||||
|
||||
private:
|
||||
int SendColour( int* colour, int ctr);
|
||||
|
||||
char *Buffer;
|
||||
int SendToGame( void* msg, unsigned long len);
|
||||
|
||||
@@ -8,7 +8,8 @@ WARNING: You use this program at your own risk!
|
||||
Download it by your self and don't use versions, send to you by team or guild members!
|
||||
http://code.google.com/p/texmod/downloads/list
|
||||
|
||||
|
||||
OpenTexMod uses the D3DX9_43.dll. Due to the EULA this dll cannot be deliviered together with OpenTexMod .
|
||||
If D3DX9_43.dll is not installed on your system, OpenTexMod will give you a hint at program start.
|
||||
|
||||
What can OpenTexMod alpha V0.1?
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ typedef struct
|
||||
#define CONTROL_KEY_SAVE 21
|
||||
#define CONTROL_KEY_NEXT 22
|
||||
|
||||
#define CONTROL_FONT_COLOUR 30
|
||||
#define CONTROL_TEXTURE_COLOUR 31
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user