mirror of
https://github.com/DxWnd/DxWnd.reloaded
synced 2024-12-30 09:25:35 +01:00
v2_02_14_src
Former-commit-id: 6064dd3ba4a0a86d4ef365d51a3f26ccb81697d0
This commit is contained in:
parent
3fc3334d07
commit
54516626d3
@ -39,7 +39,7 @@
|
||||
#define SWITCHVIDEOMEMORY 0x04000000 // when VIDEO memory is over, switches to SYSTEM memory
|
||||
#define CLIENTREMAPPING 0x08000000 // hooks CLientToRect, RectToClient, GetClientRect, GetWinRect
|
||||
#define HANDLEALTF4 0x10000000 // forces quitting the program when receiving Alt-F4 key
|
||||
#define LOCKWINPOS 0x20000000 // prevent the origram to change its own windows properties
|
||||
#define LOCKWINPOS 0x20000000 // prevent the program to change its own windows properties
|
||||
#define HOOKCHILDWIN 0x40000000 // hook CHILD windows to alter placement coordinates (UNUSED)
|
||||
#define MESSAGEPROC 0x80000000 // process peek/get messages
|
||||
|
||||
@ -73,6 +73,7 @@
|
||||
#define NOBANNER 0x04000000 // suppress fancy logo & banneer effects
|
||||
#define WINDOWIZE 0x08000000 // Run in a Window (default TRUE)
|
||||
#define LIMITRESOURCES 0x10000000 // Limit resources to fit an old program's expectations
|
||||
#define STARTDEBUG 0x20000000 // Start in DEBUG mode
|
||||
|
||||
// logging Tflags DWORD:
|
||||
#define OUTTRACE 0x00000001 // enables tracing to dxwnd.log in general
|
||||
@ -141,7 +142,7 @@ int HookInit(TARGETMAP *, HWND);
|
||||
void *SetHook(void *, void *);
|
||||
void SetHook(void *, void *, void **, char *);
|
||||
void OutTrace(const char *, ...);
|
||||
void *HookAPI(const char *, char *, void *, const char *, void *);
|
||||
void *HookAPI(HMODULE, char *, void *, const char *, void *);
|
||||
void AdjustWindowFrame(HWND, DWORD, DWORD);
|
||||
LRESULT CALLBACK extWindowProc(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e57051bb941d5540bc3ff00785953fc614543989bd451522af2759f240fb2298
|
||||
size 297984
|
||||
oid sha256:9530b7fe842a87f99d093ae348d625f39f995d6c316d74a904f62991389ab035
|
||||
size 302592
|
||||
|
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:deb192e6aa9d77b5a60a663c39fe0d39a6ca3c100179a9e0c71e6f11d85d18b4
|
||||
size 498688
|
||||
oid sha256:7d35bac3ab4fe4d695e7f1cc08777c28664740d8994a72c27b92898273434e4d
|
||||
size 500736
|
||||
|
4422
build/dxwnd.ini
Normal file
4422
build/dxwnd.ini
Normal file
File diff suppressed because it is too large
Load Diff
@ -60,3 +60,15 @@ GUI: Tabbed setup panel. More space for more future options.
|
||||
DLL: (optional) splash screen
|
||||
probably, some regression bugs....
|
||||
|
||||
v2.02.13
|
||||
Added decoding of WINDOWPOS.flags field in trace log
|
||||
revised whole hooking procedures to use HMODULE handle instead of module name
|
||||
Added WM_GETMINMAXINFO and WM_NCCALCSIZE handling in WinProcess hook
|
||||
Attempt to handle double buffering through surface attach to backbuffer (???)
|
||||
Fixed CHILD window positioning for BIG windows in CreateWindowExA hook
|
||||
Added GlobalMemoryStatus hook to fix huge values when value exceeds DWORD range. Fixes Nocturne intro warning message.
|
||||
|
||||
V2.02.14
|
||||
Started dll injection to handle startup code
|
||||
Fixed directx CreateSurface hook to fix "Wargames" error in emulated mode
|
||||
Fixed directx SetClipper hook to properly handle backbuffer clipping and fix "Wargames" clipping problems
|
||||
|
@ -961,3 +961,24 @@ char *ExplainDDEnumerateFlags(DWORD c)
|
||||
return "???";
|
||||
}
|
||||
|
||||
char *ExplainWPFlags(DWORD c)
|
||||
{
|
||||
static char eb[256];
|
||||
unsigned int l;
|
||||
strcpy(eb,"SWP_");
|
||||
if (c & SWP_NOSIZE) strcat(eb, "NOSIZE+");
|
||||
if (c & SWP_NOMOVE) strcat(eb, "NOMOVE+");
|
||||
if (c & SWP_NOZORDER) strcat(eb, "NOZORDER+");
|
||||
if (c & SWP_NOREDRAW) strcat(eb, "NOREDRAW+");
|
||||
if (c & SWP_NOACTIVATE) strcat(eb, "NOACTIVATE+");
|
||||
if (c & SWP_FRAMECHANGED) strcat(eb, "FRAMECHANGED+");
|
||||
if (c & SWP_SHOWWINDOW) strcat(eb, "SHOWWINDOW+");
|
||||
if (c & SWP_HIDEWINDOW) strcat(eb, "HIDEWINDOW+");
|
||||
if (c & SWP_NOCOPYBITS) strcat(eb, "NOCOPYBITS+");
|
||||
if (c & SWP_NOOWNERZORDER) strcat(eb, "NOOWNERZORDER+");
|
||||
if (c & SWP_NOSENDCHANGING) strcat(eb, "NOSENDCHANGING+");
|
||||
l=strlen(eb);
|
||||
if (l>strlen("SWP_")) eb[l-1]=0; // delete last '+' if any
|
||||
else strcpy(eb,"NULL");
|
||||
return(eb);
|
||||
}
|
||||
|
@ -28,3 +28,4 @@ extern char *ExplainROP(DWORD);
|
||||
extern char *ExplainNChitTest(DWORD);
|
||||
extern char *ExplainDDEnumerateFlags(DWORD);
|
||||
extern char *ExplainsSystemMetrics(DWORD);
|
||||
extern char *ExplainWPFlags(DWORD);
|
||||
|
151
dll/dxhook.cpp
151
dll/dxhook.cpp
@ -122,23 +122,18 @@ static void dx_ToggleLogging()
|
||||
GetHookInfo()->isLogging=(dxw.dwTFlags & OUTTRACE);
|
||||
}
|
||||
|
||||
void DumpImportTable(char *module)
|
||||
void DumpImportTable(HMODULE module)
|
||||
{
|
||||
DWORD base;
|
||||
PIMAGE_NT_HEADERS pnth;
|
||||
PIMAGE_IMPORT_DESCRIPTOR pidesc;
|
||||
DWORD rva;
|
||||
DWORD base, rva;
|
||||
PSTR impmodule;
|
||||
PIMAGE_THUNK_DATA ptaddr;
|
||||
PIMAGE_THUNK_DATA ptname;
|
||||
PIMAGE_IMPORT_BY_NAME piname;
|
||||
|
||||
base = (DWORD)GetModuleHandle(module);
|
||||
base=(DWORD)module;
|
||||
OutTrace("DumpImportTable: base=%x\n", base);
|
||||
if(!base) {
|
||||
OutTrace("DumpImportTable: GetModuleHandle failed, err=%d at %d\n",GetLastError(), __LINE__);
|
||||
return;
|
||||
}
|
||||
__try{
|
||||
pnth = PIMAGE_NT_HEADERS(PBYTE(base) + PIMAGE_DOS_HEADER(base)->e_lfanew);
|
||||
if(!pnth) {
|
||||
@ -214,12 +209,11 @@ void SetHook(void *target, void *hookproc, void **hookedproc, char *hookname)
|
||||
*hookedproc = tmp;
|
||||
}
|
||||
|
||||
void *HookAPI(const char *module, char *dll, void *apiproc, const char *apiname, void *hookproc)
|
||||
void *HookAPI(HMODULE module, char *dll, void *apiproc, const char *apiname, void *hookproc)
|
||||
{
|
||||
DWORD base;
|
||||
PIMAGE_NT_HEADERS pnth;
|
||||
PIMAGE_IMPORT_DESCRIPTOR pidesc;
|
||||
DWORD rva;
|
||||
DWORD base, rva;
|
||||
PSTR impmodule;
|
||||
PIMAGE_THUNK_DATA ptaddr;
|
||||
PIMAGE_THUNK_DATA ptname;
|
||||
@ -234,11 +228,7 @@ void *HookAPI(const char *module, char *dll, void *apiproc, const char *apiname,
|
||||
return 0;
|
||||
}
|
||||
|
||||
base = (DWORD)GetModuleHandle(module);
|
||||
if(!base) {
|
||||
OutTraceD("HookAPI: GetModuleHandle failed, error=%d\n",GetLastError());
|
||||
return 0;
|
||||
}
|
||||
base = (DWORD)module;
|
||||
__try{
|
||||
pnth = PIMAGE_NT_HEADERS(PBYTE(base) + PIMAGE_DOS_HEADER(base)->e_lfanew);
|
||||
if(!pnth) {
|
||||
@ -301,7 +291,7 @@ void *HookAPI(const char *module, char *dll, void *apiproc, const char *apiname,
|
||||
OutTraceD("HookAPI: FlushInstructionCache error %d at %d\n", GetLastError(), __LINE__);
|
||||
return 0;
|
||||
}
|
||||
if(IsDebug) OutTrace("HookAPI hook=%s.%s address=%x->%x\n", module, apiname, org, hookproc);
|
||||
if(IsDebug) OutTrace("HookAPI hook=%s address=%x->%x\n", apiname, org, hookproc);
|
||||
}
|
||||
__except(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
@ -566,6 +556,48 @@ LRESULT CALLBACK extWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
|
||||
#endif
|
||||
|
||||
switch(message){
|
||||
// v2.02.13: added WM_GETMINMAXINFO/WM_NCCALCSIZE interception - (see Actua Soccer 3 problems...)
|
||||
case WM_GETMINMAXINFO:
|
||||
if(dxw.dwFlags1 & LOCKWINPOS){
|
||||
extern void dxwFixMinMaxInfo(char *, HWND, LPARAM);
|
||||
dxwFixMinMaxInfo("WindowProc", hwnd, lparam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_NCCALCSIZE:
|
||||
if(dxw.dwFlags1 & LOCKWINPOS){
|
||||
OutTraceD("WindowProc: WS_NCCALCSIZE wparam=%x\n", wparam);
|
||||
if(wparam){
|
||||
// nothing so far ....
|
||||
if (IsDebug){
|
||||
NCCALCSIZE_PARAMS *ncp;
|
||||
ncp = (NCCALCSIZE_PARAMS *) lparam;
|
||||
OutTraceD("WindowProc: WS_NCCALCSIZE rect[0]=(%d,%d)-(%d,%d)\n",
|
||||
ncp->rgrc[0].left, ncp->rgrc[0].top, ncp->rgrc[0].right, ncp->rgrc[0].bottom);
|
||||
OutTraceD("WindowProc: WS_NCCALCSIZE rect[1]=(%d,%d)-(%d,%d)\n",
|
||||
ncp->rgrc[1].left, ncp->rgrc[1].top, ncp->rgrc[1].right, ncp->rgrc[1].bottom);
|
||||
OutTraceD("WindowProc: WS_NCCALCSIZE rect[2]=(%d,%d)-(%d,%d)\n",
|
||||
ncp->rgrc[2].left, ncp->rgrc[2].top, ncp->rgrc[2].right, ncp->rgrc[2].bottom);
|
||||
OutTraceD("WindowProc: WS_NCCALCSIZE winrect=(%d,%d)-(%d,%d)\n",
|
||||
ncp->lppos->x, ncp->lppos->y, ncp->lppos->cx, ncp->lppos->cy);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// enforce win coordinates and return 0xF0 = WVR_ALIGNTOP|WVR_ALIGNLEFT|WVR_ALIGNBOTTOM|WVR_ALIGNRIGHT;
|
||||
LPRECT rect;
|
||||
rect=(LPRECT)lparam;
|
||||
OutTraceB("WindowProc: WS_NCCALCSIZE proposed rect=(%d,%d)-(%d,%d)\n",
|
||||
rect->left, rect->top, rect->right, rect->bottom);
|
||||
rect->left=dxw.iPosX;
|
||||
rect->top=dxw.iPosY;
|
||||
rect->right=dxw.iPosX+dxw.iSizX;
|
||||
rect->bottom=dxw.iPosY+dxw.iSizY;
|
||||
OutTraceB("WindowProc: WS_NCCALCSIZE fixed rect=(%d,%d)-(%d,%d)\n",
|
||||
rect->left, rect->top, rect->right, rect->bottom);
|
||||
return WVR_ALIGNTOP|WVR_ALIGNLEFT|WVR_ALIGNBOTTOM|WVR_ALIGNRIGHT;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_NCCREATE:
|
||||
if(dxw.dwFlags2 & SUPPRESSIME){
|
||||
OutTraceD("WindowProc: SUPPRESS IME\n");
|
||||
@ -749,10 +781,7 @@ LRESULT CALLBACK extWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (dxw.dwFlags1 & AUTOREFRESH)
|
||||
{
|
||||
dxw.ScreenRefresh();
|
||||
}
|
||||
if (dxw.dwFlags1 & AUTOREFRESH) dxw.ScreenRefresh();
|
||||
|
||||
pWindowProc=WhndGetWindowProc(hwnd);
|
||||
if(pWindowProc) {
|
||||
@ -852,7 +881,7 @@ void HookSysLibsInit()
|
||||
pSetTimer=SetTimer;
|
||||
}
|
||||
|
||||
void HookGDILib(char *module)
|
||||
void HookGDILib(HMODULE module)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
@ -921,7 +950,7 @@ void HookGDILib(char *module)
|
||||
}
|
||||
}
|
||||
|
||||
void HookSysLibs(char *module)
|
||||
void HookSysLibs(HMODULE module)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
@ -1047,10 +1076,11 @@ void HookSysLibs(char *module)
|
||||
tmp = HookAPI(module, "user32.dll", MoveWindow, "MoveWindow", extMoveWindow);
|
||||
if(tmp) pMoveWindow = (MoveWindow_Type)tmp;
|
||||
|
||||
#define TRAPLOWRESOURCES 0
|
||||
if(TRAPLOWRESOURCES){
|
||||
if(dxw.dwFlags2 & LIMITRESOURCES){
|
||||
tmp = HookAPI(module, "kernel32.dll", GetDiskFreeSpaceA, "GetDiskFreeSpaceA", extGetDiskFreeSpaceA);
|
||||
if(tmp) pGetDiskFreeSpaceA = (GetDiskFreeSpaceA_Type)tmp;
|
||||
tmp = HookAPI(module, "kernel32.dll", GlobalMemoryStatus, "GlobalMemoryStatus", extGlobalMemoryStatus);
|
||||
if(tmp) pGlobalMemoryStatus = (GlobalMemoryStatus_Type)tmp;
|
||||
}
|
||||
|
||||
if(dxw.dwFlags2 & TIMESTRETCH){
|
||||
@ -1142,15 +1172,17 @@ LONG WINAPI myUnhandledExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo)
|
||||
void HookExceptionHandler(void)
|
||||
{
|
||||
void *tmp;
|
||||
HMODULE base;
|
||||
|
||||
OutTraceD("Set exception handlers\n");
|
||||
base=GetModuleHandle(NULL);
|
||||
pSetUnhandledExceptionFilter = SetUnhandledExceptionFilter;
|
||||
//v2.1.75 override default exception handler, if any....
|
||||
LONG WINAPI myUnhandledExceptionFilter(LPEXCEPTION_POINTERS);
|
||||
tmp = HookAPI(NULL, "KERNEL32.dll", UnhandledExceptionFilter, "UnhandledExceptionFilter", myUnhandledExceptionFilter);
|
||||
tmp = HookAPI(base, "KERNEL32.dll", UnhandledExceptionFilter, "UnhandledExceptionFilter", myUnhandledExceptionFilter);
|
||||
// so far, no need to save the previous handler.
|
||||
//if(tmp) pUnhandledExceptionFilter = (UnhandledExceptionFilter_Type)tmp;
|
||||
tmp = HookAPI(NULL, "KERNEL32.dll", SetUnhandledExceptionFilter, "SetUnhandledExceptionFilter", extSetUnhandledExceptionFilter);
|
||||
tmp = HookAPI(base, "KERNEL32.dll", SetUnhandledExceptionFilter, "SetUnhandledExceptionFilter", extSetUnhandledExceptionFilter);
|
||||
//tmp = HookAPI("KERNEL32.dll", SetUnhandledExceptionFilter, "SetUnhandledExceptionFilter", myUnhandledExceptionFilter);
|
||||
if(tmp) pSetUnhandledExceptionFilter = (SetUnhandledExceptionFilter_Type)tmp;
|
||||
|
||||
@ -1159,34 +1191,17 @@ void HookExceptionHandler(void)
|
||||
//(*pSetUnhandledExceptionFilter)(NULL);
|
||||
}
|
||||
|
||||
void HookModule(char *module, int dxversion)
|
||||
void HookModule(HMODULE base, int dxversion)
|
||||
{
|
||||
HookSysLibs(module);
|
||||
HookSysLibs(base);
|
||||
//if(dxw.dwFlags2 & SUPPRESSIME) HookImeLib(module);
|
||||
if(dxw.dwFlags2 & HOOKGDI) HookGDILib(module);
|
||||
if(dxw.dwFlags1 & HOOKDI) HookDirectInput(module, dxversion);
|
||||
HookDirectDraw(module, dxversion);
|
||||
HookDirect3D(module, dxversion);
|
||||
HookOle32(module, dxversion); // unfinished business
|
||||
if(dxw.dwFlags2 & HOOKOPENGL) HookOpenGLLibs(module, dxw.CustomOpenGLLib);
|
||||
}
|
||||
|
||||
void ForceHookOpenGL() // to do .....
|
||||
{
|
||||
HMODULE hGlLib;
|
||||
//hGlLib=(*pLoadLibraryA)("OpenGL32.dll");
|
||||
hGlLib=LoadLibrary("OpenGL32.dll");
|
||||
OutTrace("hGlLib=%x\n",hGlLib);
|
||||
pglViewport=(glViewport_Type)GetProcAddress(hGlLib, "glViewport");
|
||||
if(pglViewport)
|
||||
HookAPI(NULL, "OpenGL32.dll", pglViewport, "glViewport", extglViewport);
|
||||
//SetHook(void *target, void *hookproc, void **hookedproc, char *hookname);
|
||||
pglScissor=(glScissor_Type)GetProcAddress(hGlLib, "glScissor");
|
||||
if(pglScissor) HookAPI(NULL, "OpenGL32.dll", pglScissor, "glScissor", extglScissor);
|
||||
pglGetIntegerv=(glGetIntegerv_Type)GetProcAddress(hGlLib, "glGetIntegerv");
|
||||
if(pglGetIntegerv) HookAPI(NULL, "OpenGL32.dll", pglGetIntegerv, "glGetIntegerv", extglGetIntegerv);
|
||||
pglDrawBuffer=(glDrawBuffer_Type)GetProcAddress(hGlLib, "glDrawBuffer");
|
||||
if(pglDrawBuffer) HookAPI(NULL, "OpenGL32.dll", pglDrawBuffer, "glDrawBuffer", extglDrawBuffer);
|
||||
if(dxw.dwFlags2 & HOOKGDI) HookGDILib(base);
|
||||
if(dxw.dwFlags1 & HOOKDI) HookDirectInput(base, dxversion);
|
||||
HookDirectDraw(base, dxversion);
|
||||
HookDirect3D(base, dxversion);
|
||||
HookOle32(base, dxversion); // unfinished business
|
||||
if(dxw.dwFlags2 & HOOKOPENGL) HookOpenGLLibs(base, dxw.CustomOpenGLLib);
|
||||
//ForceHookOpenGL(base);
|
||||
}
|
||||
|
||||
void DisableIME()
|
||||
@ -1224,10 +1239,12 @@ void DisableIME()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int HookInit(TARGETMAP *target, HWND hwnd)
|
||||
{
|
||||
BOOL res;
|
||||
WINDOWPOS wp;
|
||||
HMODULE base;
|
||||
char *sModule;
|
||||
static char *dxversions[14]={
|
||||
"Automatic", "DirectX1~6", "", "", "", "", "",
|
||||
@ -1253,17 +1270,16 @@ int HookInit(TARGETMAP *target, HWND hwnd)
|
||||
OutTrace("HookInit: dxw.hParentWnd style=%x(%s) exstyle=%x(%s)\n", dwStyle, ExplainStyle(dwStyle), dwExStyle, ExplainExStyle(dwExStyle));
|
||||
}
|
||||
|
||||
base=GetModuleHandle(NULL);
|
||||
if(dxw.dwFlags1 & HANDLEEXCEPTIONS) HookExceptionHandler();
|
||||
if (dxw.dwTFlags & OUTIMPORTTABLE) DumpImportTable(NULL);
|
||||
if (dxw.dwTFlags & OUTIMPORTTABLE) DumpImportTable(base);
|
||||
//if(dxw.dwFlags2 & SUPPRESSIME) DisableIME();
|
||||
|
||||
if (dxw.dwTFlags & DXPROXED){
|
||||
HookDDProxy(NULL, dxw.dwTargetDDVersion);
|
||||
HookDDProxy(base, dxw.dwTargetDDVersion);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//ForceHookOpenGL();
|
||||
|
||||
// make InitPosition used for both DInput and DDraw
|
||||
InitPosition(target->initx, target->inity,
|
||||
target->minx, target->miny, target->maxx, target->maxy);
|
||||
@ -1271,17 +1287,26 @@ int HookInit(TARGETMAP *target, HWND hwnd)
|
||||
|
||||
HookSysLibsInit(); // this just once...
|
||||
|
||||
HookModule(NULL, dxw.dwTargetDDVersion);
|
||||
if(IsDebug) OutTrace("HookInit: base hmodule=%x\n", base);
|
||||
HookModule(base, dxw.dwTargetDDVersion);
|
||||
if(IsDebug){
|
||||
extern BOOL ListProcessModules(BOOL);
|
||||
ListProcessModules(true);
|
||||
}
|
||||
sModule=strtok(dxw.gsModules," ");
|
||||
while (sModule) {
|
||||
HMODULE hm;
|
||||
hm=(*pLoadLibraryA)(sModule);
|
||||
OutTraceD("HookInit: hooking additional module=%s\n", sModule);
|
||||
if (dxw.dwTFlags & OUTIMPORTTABLE) DumpImportTable(sModule);
|
||||
HookModule(sModule, dxw.dwTargetDDVersion);
|
||||
base=(*pLoadLibraryA)(sModule);
|
||||
if(!base){
|
||||
OutTraceE("HookInit: LoadLibrary ERROR module=%s err=%d\n", sModule, GetLastError());
|
||||
continue;
|
||||
}
|
||||
OutTraceD("HookInit: hooking additional module=%s base=%x\n", sModule, base);
|
||||
if (dxw.dwTFlags & OUTIMPORTTABLE) DumpImportTable(base);
|
||||
HookModule(base, dxw.dwTargetDDVersion);
|
||||
sModule=strtok(NULL," ");
|
||||
}
|
||||
|
||||
|
||||
if(dxw.dwFlags2 & RECOVERSCREENMODE) RecoverScreenMode();
|
||||
|
||||
InitScreenParameters();
|
||||
|
12
dll/dxhook.h
12
dll/dxhook.h
@ -1,9 +1,9 @@
|
||||
extern int HookDirectDraw(char *, int);
|
||||
extern int HookDDProxy(char *, int);
|
||||
extern int HookDirect3D(char *, int);
|
||||
extern int HookOle32(char *, int);
|
||||
extern int HookDirectInput(char *, int);
|
||||
extern void HookImeLib(char *);
|
||||
extern int HookDirectDraw(HMODULE, int);
|
||||
extern int HookDDProxy(HMODULE, int);
|
||||
extern int HookDirect3D(HMODULE, int);
|
||||
extern int HookOle32(HMODULE, int);
|
||||
extern int HookDirectInput(HMODULE, int);
|
||||
extern void HookImeLib(HMODULE);
|
||||
extern void InitPosition(int, int, int, int, int, int);
|
||||
//void InitWindowPos(int, int, int, int);
|
||||
extern LPCSTR ProcToString(LPCSTR proc);
|
||||
|
@ -26,13 +26,13 @@ dxwCore::dxwCore()
|
||||
|
||||
memset(PrimSurfaces, 0, sizeof(PrimSurfaces));
|
||||
|
||||
// preserved syslibs pointers
|
||||
pClientToScreen=ClientToScreen;
|
||||
pClipCursor=ClipCursor;
|
||||
pGetClientRect=GetClientRect;
|
||||
pGetCursorPos=GetCursorPos;
|
||||
pInvalidateRect=InvalidateRect;
|
||||
pScreenToClient=ScreenToClient;
|
||||
//// preserved syslibs pointers
|
||||
//pClientToScreen=ClientToScreen;
|
||||
//pClipCursor=ClipCursor;
|
||||
//pGetClientRect=GetClientRect;
|
||||
//pGetCursorPos=GetCursorPos;
|
||||
//pInvalidateRect=InvalidateRect;
|
||||
//pScreenToClient=ScreenToClient;
|
||||
}
|
||||
|
||||
dxwCore::~dxwCore()
|
||||
@ -201,6 +201,16 @@ POINT dxwCore::FixCursorPos(HWND hwnd, POINT prev)
|
||||
return curr;
|
||||
}
|
||||
|
||||
POINT dxwCore::ScreenToClient(POINT point)
|
||||
{
|
||||
// convert absolute screen coordinates to frame relative
|
||||
if (!(*pScreenToClient)(hWnd, &point)) {
|
||||
OutTraceE("ScreenToClient(%x) ERROR %d at %d\n", hWnd, GetLastError(), __LINE__);
|
||||
point.x =0; point.y=0;
|
||||
}
|
||||
return point;
|
||||
}
|
||||
|
||||
void dxwCore::FixNCHITCursorPos(LPPOINT lppoint)
|
||||
{
|
||||
RECT rect;
|
||||
|
@ -51,6 +51,7 @@ public: // methods
|
||||
char *GetTSCaption(void);
|
||||
void DoSlow(int);
|
||||
void ShowBanner(HWND);
|
||||
POINT ScreenToClient(POINT);
|
||||
|
||||
public: // simple data variables
|
||||
DDPIXELFORMAT ActualPixelFormat;
|
||||
@ -90,12 +91,6 @@ protected:
|
||||
BOOL FullScreen;
|
||||
HWND hWnd;
|
||||
DWORD PrimSurfaces[DDSQLEN+1];
|
||||
ClientToScreen_Type pClientToScreen;
|
||||
ClipCursor_Type pClipCursor;
|
||||
GetClientRect_Type pGetClientRect;
|
||||
GetCursorPos_Type pGetCursorPos;
|
||||
InvalidateRect_Type pInvalidateRect;
|
||||
ScreenToClient_Type pScreenToClient;
|
||||
};
|
||||
|
||||
extern dxwCore dxw;
|
||||
|
BIN
dll/dxwnd.aps
BIN
dll/dxwnd.aps
Binary file not shown.
@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <stdio.h>
|
||||
#include "dxwnd.h"
|
||||
|
||||
#define VERSION "2.02.12"
|
||||
#define VERSION "2.02.14"
|
||||
|
||||
LRESULT CALLBACK HookProc(int ncode, WPARAM wparam, LPARAM lparam);
|
||||
|
||||
|
Binary file not shown.
@ -352,6 +352,10 @@
|
||||
RelativePath=".\syslibs.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\walkmod.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\wndproc.cpp"
|
||||
>
|
||||
|
@ -34,21 +34,67 @@ FARPROC Remap_gl_ProcAddress(LPCSTR proc, HMODULE hModule)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void HookOpenGLLibs(char *module, char *customlib)
|
||||
void ForceHookOpenGL(HMODULE base) // to do .....
|
||||
{
|
||||
HMODULE hGlLib;
|
||||
hGlLib=(*pLoadLibraryA)("OpenGL32.dll");
|
||||
//hGlLib=LoadLibrary("OpenGL32.dll");
|
||||
OutTrace("hGlLib=%x\n",hGlLib);
|
||||
if(!hGlLib){
|
||||
OutTraceE("LoadLibrary(\"OpenGL32.dll\") ERROR: err=%d at %d\n", GetLastError(), __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
pglViewport=(glViewport_Type)GetProcAddress(hGlLib, "glViewport");
|
||||
if(pglViewport) {
|
||||
HookAPI(base, "opengl32", pglViewport, "glViewport", extglViewport);
|
||||
extglViewport(dxw.iPosX,dxw.iPosY,dxw.iSizX,dxw.iSizY);
|
||||
}
|
||||
pglScissor=(glScissor_Type)GetProcAddress(hGlLib, "glScissor");
|
||||
if(pglScissor) {
|
||||
HookAPI(base, "opengl32", pglScissor, "glScissor", extglScissor);
|
||||
//extglScissor(dxw.iPosX,dxw.iPosY,dxw.iSizX,dxw.iSizY);
|
||||
}
|
||||
pglGetIntegerv=(glGetIntegerv_Type)GetProcAddress(hGlLib, "glGetIntegerv");
|
||||
if(pglGetIntegerv) {
|
||||
HookAPI(base, "opengl32", pglGetIntegerv, "glGetIntegerv", extglGetIntegerv);
|
||||
//extglGetIntegerv(0, NULL);
|
||||
}
|
||||
pglDrawBuffer=(glDrawBuffer_Type)GetProcAddress(hGlLib, "glDrawBuffer");
|
||||
if(pglDrawBuffer) {
|
||||
HookAPI(base, "opengl32", pglDrawBuffer, "glDrawBuffer", extglDrawBuffer);
|
||||
//extglDrawBuffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void HookOpenGLLibs(HMODULE module, char *customlib)
|
||||
{
|
||||
void *tmp;
|
||||
char *DefOpenGLModule="OpenGL32.dll";
|
||||
int HookMode;
|
||||
|
||||
if (!customlib) customlib=DefOpenGLModule;
|
||||
|
||||
tmp = HookAPI(module, customlib, NULL, "glViewport", extglViewport);
|
||||
if(tmp) pglViewport = (glViewport_Type)tmp;
|
||||
tmp = HookAPI(module, customlib, NULL, "glScissor", extglScissor);
|
||||
if(tmp) pglScissor = (glScissor_Type)tmp;
|
||||
tmp = HookAPI(module, customlib, NULL, "glGetIntegerv", extglGetIntegerv);
|
||||
if(tmp) pglGetIntegerv = (glGetIntegerv_Type)tmp;
|
||||
tmp = HookAPI(module, customlib, NULL, "glDrawBuffer", extglDrawBuffer);
|
||||
if(tmp) pglDrawBuffer = (glDrawBuffer_Type)tmp;
|
||||
HookMode=0; // temporary ...
|
||||
switch(HookMode){
|
||||
case 0:
|
||||
tmp = HookAPI(module, customlib, NULL, "glViewport", extglViewport);
|
||||
if(tmp) pglViewport = (glViewport_Type)tmp;
|
||||
tmp = HookAPI(module, customlib, NULL, "glScissor", extglScissor);
|
||||
if(tmp) pglScissor = (glScissor_Type)tmp;
|
||||
tmp = HookAPI(module, customlib, NULL, "glGetIntegerv", extglGetIntegerv);
|
||||
if(tmp) pglGetIntegerv = (glGetIntegerv_Type)tmp;
|
||||
tmp = HookAPI(module, customlib, NULL, "glDrawBuffer", extglDrawBuffer);
|
||||
if(tmp) pglDrawBuffer = (glDrawBuffer_Type)tmp;
|
||||
break;
|
||||
case 1:
|
||||
static int DoOnce=TRUE;
|
||||
if(DoOnce){
|
||||
ForceHookOpenGL(module);
|
||||
DoOnce=FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "gl.h"
|
||||
|
||||
extern FARPROC Remap_gl_ProcAddress(LPCSTR, HMODULE);
|
||||
extern void HookOpenGLLibs(char *, char *);
|
||||
extern void HookOpenGLLibs(HMODULE, char *);
|
||||
|
||||
typedef void (WINAPI *glViewport_Type)(GLint, GLint, GLsizei, GLsizei);
|
||||
typedef void (WINAPI *glScissor_Type)(GLint, GLint, GLsizei, GLsizei);
|
||||
|
@ -37,7 +37,7 @@ Present_Type pPresent;
|
||||
|
||||
DWORD dwD3DVersion;
|
||||
|
||||
int HookDirect3D(char *module, int version){
|
||||
int HookDirect3D(HMODULE module, int version){
|
||||
HINSTANCE hinst;
|
||||
void *tmp;
|
||||
LPDIRECT3D9 lpd3d;
|
||||
|
@ -273,7 +273,7 @@ FARPROC WINAPI extGetProcAddressProxy(HMODULE hModule, LPCSTR proc)
|
||||
//
|
||||
// ------------------------------------------------------------------------------------------ //
|
||||
|
||||
int HookDDProxy(char *module, int dxVersion)
|
||||
int HookDDProxy(HMODULE module, int dxVersion)
|
||||
{
|
||||
HINSTANCE hinst;
|
||||
void *tmp;
|
||||
|
127
dll/hddraw.cpp
127
dll/hddraw.cpp
@ -486,8 +486,8 @@ HRESULT STDAPICALLTYPE extCoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter,
|
||||
OutTraceD("CoCreateInstance: CLSID_FilterGraph RIID=%x\n", *(DWORD *)&riid);
|
||||
qlib=(*pLoadLibraryA)("quartz.dll");
|
||||
OutTraceD("CoCreateInstance: quartz lib handle=%x\n", qlib);
|
||||
extern void HookSysLibs(char *);
|
||||
HookSysLibs("quartz");
|
||||
extern void HookSysLibs(HMODULE);
|
||||
HookSysLibs(qlib);
|
||||
}
|
||||
|
||||
res=(*pCoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv);
|
||||
@ -533,7 +533,7 @@ HRESULT STDAPICALLTYPE extCoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter,
|
||||
return res;
|
||||
}
|
||||
|
||||
int HookOle32(char *module, int version)
|
||||
int HookOle32(HMODULE module, int version)
|
||||
{
|
||||
// used by Axis & Allies ....
|
||||
void *tmp;
|
||||
@ -544,7 +544,7 @@ int HookOle32(char *module, int version)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HookDirectDraw(char *module, int version)
|
||||
int HookDirectDraw(HMODULE module, int version)
|
||||
{
|
||||
HINSTANCE hinst;
|
||||
void *tmp;
|
||||
@ -1466,7 +1466,10 @@ HRESULT WINAPI extQueryInterfaceS(void *lpdds, REFIID riid, LPVOID *obp)
|
||||
}
|
||||
else{
|
||||
dxw.UnmarkPrimarySurface((LPDIRECTDRAWSURFACE)*obp);
|
||||
HookDDSurfaceGeneric((LPDIRECTDRAWSURFACE *)obp, dxw.dwDDVersion);
|
||||
// v2.02.13: seems that hooking inconditionally gives troubles. What is the proper hook condition?
|
||||
// maybe when in emulation mode?
|
||||
//ASSERT TO BE FINISHED
|
||||
if(dxw.dwFlags1 & EMULATESURFACE) HookDDSurfaceGeneric((LPDIRECTDRAWSURFACE *)obp, dxw.dwDDVersion);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -1834,11 +1837,13 @@ HRESULT WINAPI extCreateSurfaceEmu(int dxversion, CreateSurface_Type pCreateSurf
|
||||
// not primary emulated surface ....
|
||||
if(((ddsd.dwFlags & DDSD_WIDTH) && !(ddsd.dwFlags & DDSD_HEIGHT)) ||
|
||||
(ddsd.dwFlags & DDSD_ZBUFFERBITDEPTH) ||
|
||||
(ddsd.dwFlags & DDSD_PIXELFORMAT) ||
|
||||
//(ddsd.dwFlags & DDSD_PIXELFORMAT) ||
|
||||
((ddsd.dwFlags & DDSD_PIXELFORMAT) && !(ddsd.dwFlags & DDSD_PITCH)) || // fix good for "Wargames"
|
||||
//((ddsd.dwFlags & DDSD_CAPS) && (ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE)) ||
|
||||
((ddsd.dwFlags & DDSD_CAPS) && (ddsd.ddsCaps.dwCaps & DDSCAPS_3DDEVICE))){
|
||||
// don't alter pixel format
|
||||
//ddsd.dwFlags &= ~DDSD_PIXELFORMAT; // Warhammer Dark Omen
|
||||
ddsd.dwFlags &= ~DDSD_PIXELFORMAT; // Wargames ???
|
||||
pfmt="(none)";
|
||||
}
|
||||
else {
|
||||
@ -1851,6 +1856,7 @@ HRESULT WINAPI extCreateSurfaceEmu(int dxversion, CreateSurface_Type pCreateSurf
|
||||
}
|
||||
|
||||
DumpSurfaceAttributes((LPDDSURFACEDESC)&ddsd, "[Emu Generic]" , __LINE__);
|
||||
//OutTrace("pCreateSurface=%x lpdd=%x &ddsd=%x lplpdds=%x pu=%x\n",pCreateSurface, lpdd, &ddsd, lplpdds, pu);
|
||||
res=(*pCreateSurface)(lpdd, &ddsd, lplpdds, pu);
|
||||
if(res){
|
||||
// v2.1.81: retry on system memory may fix not only the DDERR_OUTOFVIDEOMEMORY
|
||||
@ -2102,8 +2108,8 @@ HRESULT WINAPI extCreateSurface(int dxversion, CreateSurface_Type pCreateSurface
|
||||
{
|
||||
HRESULT res;
|
||||
|
||||
//GHO: beware: incomplete trace line - must be line terminated below!
|
||||
if(IsTraceD){
|
||||
// beware: incomplete trace lines - must be line terminated below!
|
||||
OutTrace("CreateSurface: Version=%d lpdd=%x Flags=%x(%s)", dxversion, lpdd, lpddsd->dwFlags, ExplainFlags(lpddsd->dwFlags));
|
||||
if (lpddsd->dwFlags & DDSD_CAPS && lpddsd->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) OutTrace(" VirtualScreen=(%d,%d)", dxw.GetScreenWidth(), dxw.GetScreenHeight());
|
||||
if (lpddsd->dwFlags & DDSD_BACKBUFFERCOUNT) OutTrace(" BackBufferCount=%d", lpddsd->dwBackBufferCount);
|
||||
@ -2117,7 +2123,7 @@ HRESULT WINAPI extCreateSurface(int dxversion, CreateSurface_Type pCreateSurface
|
||||
OutTrace("\n");
|
||||
}
|
||||
|
||||
//GHO workaround (needed for WarWind):
|
||||
//GHO workaround (needed for WarWind, Rogue Spear):
|
||||
if (lpddsd->dwFlags && !(lpddsd->dwFlags & 0x1)){
|
||||
OutTraceD("CreateSurface: fixing illegal dwFlags value: %x -> %x\n",
|
||||
lpddsd->dwFlags, lpddsd->dwFlags+1);
|
||||
@ -2551,6 +2557,7 @@ HRESULT WINAPI extBlt(LPDIRECTDRAWSURFACE lpdds, LPRECT lpdestrect,
|
||||
lpsrcrect=NULL;
|
||||
lpdestrect=NULL;
|
||||
}
|
||||
|
||||
return sBlt("Blt", lpdds, lpdestrect, lpddssrc, lpsrcrect, dwflags, lpddbltfx, FALSE);
|
||||
}
|
||||
|
||||
@ -2794,15 +2801,25 @@ HRESULT WINAPI extSetClipper(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWCLIPPER lpdd
|
||||
// clipping ON & OFF affects blitting on primary surface.
|
||||
if(dxw.dwFlags1 & SUPPRESSCLIPPING) return 0;
|
||||
|
||||
if(isPrim && (dxw.dwFlags1 & (EMULATESURFACE|EMULATEBUFFER)) && lpDDSEmu_Prim){
|
||||
res=(*pSetClipper)(lpDDSEmu_Prim, lpddc);
|
||||
if(res) OutTraceE("CreateSurface: SetClipper ERROR: res=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__);
|
||||
lpDDC = lpddc;
|
||||
// n.b. SetHWnd was not wrapped, so pSetHWnd is not usable (NULL) !!!
|
||||
if(lpDDC) res=lpDDC->SetHWnd( 0, dxw.GethWnd());
|
||||
//res=(*pSetHWnd)(lpDDC, 0, dxw.GethWnd());
|
||||
if(res) OutTraceE("CreateSurface: SetHWnd ERROR: res=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__);
|
||||
//res = 0;
|
||||
if(dxw.dwFlags1 & (EMULATESURFACE|EMULATEBUFFER)){
|
||||
if (isPrim && lpDDSEmu_Prim) {
|
||||
res=(*pSetClipper)(lpDDSEmu_Prim, lpddc);
|
||||
if(res) OutTraceE("CreateSurface: SetClipper ERROR: res=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__);
|
||||
lpDDC = lpddc;
|
||||
// n.b. SetHWnd was not wrapped, so pSetHWnd is not usable (NULL) !!!
|
||||
if(lpDDC) res=lpDDC->SetHWnd( 0, dxw.GethWnd());
|
||||
if(res) OutTraceE("CreateSurface: SetHWnd ERROR: res=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__);
|
||||
}
|
||||
else if ((lpdds == lpDDSBack) && lpDDSEmu_Back) {
|
||||
res=(*pSetClipper)(lpDDSEmu_Back, lpddc);
|
||||
if(res) OutTraceE("CreateSurface: SetClipper ERROR: res=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__);
|
||||
lpDDC = lpddc;
|
||||
// n.b. SetHWnd was not wrapped, so pSetHWnd is not usable (NULL) !!!
|
||||
if(lpDDC) res=lpDDC->SetHWnd( 0, dxw.GethWnd());
|
||||
if(res) OutTraceE("CreateSurface: SetHWnd ERROR: res=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__);
|
||||
}
|
||||
else
|
||||
res=(*pSetClipper)(lpdds, lpddc);
|
||||
}
|
||||
else
|
||||
// just proxy ...
|
||||
@ -3322,9 +3339,11 @@ HRESULT WINAPI extReleaseS(LPDIRECTDRAWSURFACE lpdds)
|
||||
__try{
|
||||
HRESULT dw=(DWORD)(*pReleaseS);
|
||||
if ((dw & 0xF0000000) == 0xF0000000) IsClosed=1;
|
||||
if ((*(DWORD *)lpdds & 0xF0000000) == 0xF0000000) IsClosed=1;
|
||||
if(IsClosed) OutTraceE("Release(S): ASSERT got closed surface lpdds=%x\n", lpdds);
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER){
|
||||
OutTraceD("Exception at %d\n",__LINE__);
|
||||
OutTraceE("Exception at %d\n",__LINE__);
|
||||
IsClosed=1;
|
||||
};
|
||||
|
||||
@ -3450,28 +3469,35 @@ HRESULT WINAPI extAddAttachedSurface(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWSURF
|
||||
OutTraceD("AddAttachedSurface: lpdds=%x%s lpddsadd=%x\n", lpdds, IsPrim?"(PRIM)":"", lpddsadd);
|
||||
res=(*pAddAttachedSurface)(lpdds, lpddsadd);
|
||||
if (res) {
|
||||
HRESULT sdres;
|
||||
DDSURFACEDESC2 sd;
|
||||
sd.dwSize=Set_dwSize_From_Surface(lpddsadd);
|
||||
sdres=lpddsadd->GetSurfaceDesc((DDSURFACEDESC *)&sd);
|
||||
if (sdres)
|
||||
OutTraceE("AddAttachedSurface: GetSurfaceDesc ERROR res=%x at %d\n", sdres, __LINE__);
|
||||
else
|
||||
OutTraceD("AddAttachedSurface: GetSurfaceDesc dwCaps=%x(%s)\n",
|
||||
sd.ddsCaps.dwCaps, ExplainDDSCaps(sd.ddsCaps.dwCaps));
|
||||
if (IsPrim){
|
||||
HRESULT sdres;
|
||||
DDSURFACEDESC2 sd;
|
||||
sd.dwSize=Set_dwSize_From_Surface(lpddsadd);
|
||||
sdres=lpddsadd->GetSurfaceDesc((DDSURFACEDESC *)&sd);
|
||||
if (sdres)
|
||||
OutTraceE("AddAttachedSurface: GetSurfaceDesc ERROR res=%x at %d\n", sdres, __LINE__);
|
||||
else
|
||||
OutTraceD("AddAttachedSurface: GetSurfaceDesc dwCaps=%x(%s)\n",
|
||||
sd.ddsCaps.dwCaps, ExplainDDSCaps(sd.ddsCaps.dwCaps));
|
||||
if (sd.ddsCaps.dwCaps & DDSCAPS_BACKBUFFER)
|
||||
if ((dxw.dwFlags1 & EMULATESURFACE) && (res==DDERR_CANNOTATTACHSURFACE) ||
|
||||
(res==DDERR_NOEXCLUSIVEMODE))
|
||||
OutTraceD("AddAttachedSurface: emulating surface attach on PRIMARY\n");
|
||||
OutTraceD("AddAttachedSurface: emulating BACKBUFFER attach on PRIMARY\n");
|
||||
lpDDSBack=lpddsadd;
|
||||
res=0;
|
||||
(*pAddRefS)(lpdds);
|
||||
res=DD_OK;
|
||||
}
|
||||
else if (lpdds == lpDDSBack) {
|
||||
// v2.02.13: emulate ZBUFFER attach to backbuffer: do nothing and return OK
|
||||
// this trick makes at least "Nocturne" work also in emulated mode when hardware acceleration
|
||||
// is set in the game "Options" menu.
|
||||
if (sd.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) // DDSCAPS_BACKBUFFER for double buffering ???
|
||||
if ((dxw.dwFlags1 & EMULATESURFACE) && (res==DDERR_CANNOTATTACHSURFACE)){
|
||||
OutTraceD("AddAttachedSurface: emulating ZBUFFER attach on BACKBUFFER\n");
|
||||
(*pAddRefS)(lpdds);
|
||||
res=DD_OK;
|
||||
}
|
||||
}
|
||||
//// v2.1.73: Alien Cabal 95 in EMU mode
|
||||
//if((lpdds==lpDDSBack) && (dxw.dwFlags1 & EMULATESURFACE)){
|
||||
// OutTraceD("AddAttachedSurface: ignoring err=%x(%s) on BACKBUFFER surface attach\n", res, ExplainDDError(res));
|
||||
// res=DD_OK;
|
||||
//}
|
||||
}
|
||||
if (res) OutTraceE("AddAttachedSurface: ERROR %x(%s)\n", res, ExplainDDError(res));
|
||||
return res;
|
||||
@ -3550,11 +3576,24 @@ ULONG WINAPI extReleaseD(LPDIRECTDRAW lpdd)
|
||||
{
|
||||
ULONG ref;
|
||||
int dxversion;
|
||||
BOOL IsClosed;
|
||||
|
||||
dxversion=lpddHookedVersion(lpdd); // must be called BEFORE releasing the session!!
|
||||
OutTraceD("Release(D): lpdd=%x\n", lpdd);
|
||||
|
||||
ref=(*pReleaseD)(lpdd);
|
||||
IsClosed=0;
|
||||
__try{
|
||||
HRESULT dw=(DWORD)(*pReleaseD);
|
||||
if ((dw & 0xF0000000) == 0xF0000000) IsClosed=1;
|
||||
if ((*(DWORD *)lpdd & 0xF0000000) == 0xF0000000) IsClosed=1;
|
||||
if(IsClosed) OutTraceE("Release(D): ASSERT got closed session lpdd=%x\n", lpdd);
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER){
|
||||
OutTraceE("Exception at %d\n",__LINE__);
|
||||
IsClosed=1;
|
||||
};
|
||||
|
||||
ref=IsClosed?0:(*pReleaseD)(lpdd);
|
||||
|
||||
if (lpdd == lpServiceDD) { // v2.1.87: fix for Dungeon Keeper II
|
||||
OutTraceD("Release(D): service lpdd=%x version=%d\n", lpdd, dxversion);
|
||||
@ -3708,8 +3747,24 @@ HRESULT WINAPI extReleaseP(LPDIRECTDRAWPALETTE lpddPalette)
|
||||
// returning a ref 0 without actually releasing the object.
|
||||
//v2.02.08: Better fix: to avoid the problem, just remember to NULL-ify the global main
|
||||
// palette pointer lpDDP
|
||||
//v2.02.13: still problems in Virtua Fighter 2 in emu mode. Added try catch protection.
|
||||
ULONG ref;
|
||||
ref=(*pReleaseP)(lpddPalette);
|
||||
BOOL IsClosed;
|
||||
|
||||
// handling of service closed surfaces
|
||||
IsClosed=0;
|
||||
__try{
|
||||
HRESULT dw=(DWORD)(*pReleaseP);
|
||||
if ((dw & 0xF0000000) == 0xF0000000) IsClosed=1;
|
||||
if ((*(DWORD*)lpddPalette & 0xF0000000) == 0xF0000000) IsClosed=1;
|
||||
if(IsClosed) OutTraceE("Release(P): ASSERT got closed palette lpddPalette=%x\n", lpddPalette);
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER){
|
||||
OutTraceE("Exception at %d\n",__LINE__);
|
||||
IsClosed=1;
|
||||
};
|
||||
|
||||
ref=IsClosed ? 0 :(*pReleaseP)(lpddPalette);
|
||||
OutTraceD("Release(P): lpddPalette=%x ref=%x\n", lpddPalette, ref);
|
||||
if(lpddPalette==lpDDP && ref==0){
|
||||
OutTraceD("Release(P): clearing lpDDP=%x->NULL\n", lpDDP);
|
||||
|
@ -46,7 +46,7 @@ int iCurMinY;
|
||||
int iCurMaxX;
|
||||
int iCurMaxY;
|
||||
|
||||
int HookDirectInput(char *module, int version)
|
||||
int HookDirectInput(HMODULE module, int version)
|
||||
{
|
||||
HINSTANCE hinst;
|
||||
void *tmp;
|
||||
|
@ -58,7 +58,7 @@ BOOL WINAPI extImmGetOpenStatus(HIMC hIMC)
|
||||
return(*pImmGetOpenStatus)(hIMC);
|
||||
}
|
||||
|
||||
void HookImeLib(char *module)
|
||||
void HookImeLib(HMODULE module)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
|
243
dll/syslibs.cpp
243
dll/syslibs.cpp
@ -184,6 +184,7 @@ HWND WINAPI extCreateWindowExA(
|
||||
// v2.1.100: fixes for "The Grinch": this game creates a new main window for OpenGL
|
||||
// rendering using CW_USEDEFAULT placement and 800x600 size while the previous
|
||||
// main win was 640x480 only!
|
||||
// v2.02.13: if it's a WS_CHILD window, don't reposition the x,y, placement for BIG win.
|
||||
if (
|
||||
(
|
||||
((x==0)&&(y==0)) || ((x==CW_USEDEFAULT)&&(y==CW_USEDEFAULT))
|
||||
@ -206,8 +207,10 @@ HWND WINAPI extCreateWindowExA(
|
||||
isValidHandle = TRUE;
|
||||
} while(FALSE);
|
||||
if (isValidHandle){
|
||||
x=upleft.x;
|
||||
y=upleft.y;
|
||||
if (!(dwStyle & WS_CHILD)){
|
||||
x=upleft.x;
|
||||
y=upleft.y;
|
||||
}
|
||||
nWidth=screen.right;
|
||||
nHeight=screen.bottom;
|
||||
OutTraceD("CreateWindowEx: fixed BIG win pos=(%d,%d) size=(%d,%d)\n", x, y, nWidth, nHeight);
|
||||
@ -215,8 +218,10 @@ HWND WINAPI extCreateWindowExA(
|
||||
else {
|
||||
// invalid parent coordinates: use initial placement, but leave the size.
|
||||
// should also fix the window style and compensate for borders here?
|
||||
x=dxw.iPosX;
|
||||
y=dxw.iPosY;
|
||||
if (!(dwStyle & WS_CHILD)){
|
||||
x=dxw.iPosX;
|
||||
y=dxw.iPosY;
|
||||
}
|
||||
nWidth=dxw.iSizX;
|
||||
nHeight=dxw.iSizY;
|
||||
OutTraceD("CreateWindowEx: renewed BIG win pos=(%d,%d) size=(%d,%d)\n", x, y, nWidth, nHeight);
|
||||
@ -422,72 +427,8 @@ BOOL WINAPI extGetCursorPos(LPPOINT lppoint)
|
||||
res=1;
|
||||
}
|
||||
|
||||
if(dxw.dwFlags2 & DIFFERENTIALMOUSE){
|
||||
int NewX, NewY;
|
||||
RECT client;
|
||||
POINT corner={0,0};
|
||||
|
||||
// get win placement
|
||||
(*pGetClientRect)(dxw.GethWnd(), &client);
|
||||
(*pClientToScreen)(dxw.GethWnd(), &corner);
|
||||
NewX = lppoint->x - PrevX + LastCurPosX;
|
||||
NewY = lppoint->y - PrevY + LastCurPosY;
|
||||
// handle virtual clipping
|
||||
if(lppoint->x <= corner.x) NewX--;
|
||||
if(lppoint->x >= corner.x+client.right-1) NewX++;
|
||||
if(lppoint->y <= corner.y) NewY--;
|
||||
if(lppoint->y >= corner.y+client.bottom-1) NewY++;
|
||||
|
||||
// swap coordinates...
|
||||
PrevX=lppoint->x;
|
||||
PrevY=lppoint->y;
|
||||
lppoint->x = NewX;
|
||||
lppoint->y = NewY;
|
||||
OutTraceC("GetCursorPos: DIFF pos=(%d,%d) delta=(%d,%d)->(%d,%d)\n",
|
||||
PrevX, PrevY, LastCurPosX, LastCurPosY, NewX, NewY);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
PrevX=lppoint->x;
|
||||
PrevY=lppoint->y;
|
||||
|
||||
if(dxw.dwFlags1 & MODIFYMOUSE){
|
||||
RECT rect;
|
||||
|
||||
// find window metrics
|
||||
if (!(*pGetClientRect)(dxw.GethWnd(), &rect)){
|
||||
OutTraceE("GetClientRect(%x) ERROR %d at %d\n", dxw.GethWnd(), GetLastError(), __LINE__);
|
||||
lppoint->x =0; lppoint->y=0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// convert absolute screen coordinates to frame relative
|
||||
if (!(*pScreenToClient)(dxw.GethWnd(), lppoint)) {
|
||||
OutTraceE("ScreenToClient(%x) ERROR %d at %d\n", dxw.GethWnd(), GetLastError(), __LINE__);
|
||||
lppoint->x =0; lppoint->y=0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// divide by zero check
|
||||
if (rect.right==0 || rect.bottom==0){
|
||||
OutTraceC("avoiding divide by zero for (x,y)=(%d,%d) at %d\n", rect.right, rect.bottom, __LINE__);
|
||||
lppoint->x=0; lppoint->y=0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ensure you stay within borders
|
||||
// and avoid trusting arithmetic operations on negative integers!!!
|
||||
if (lppoint->x < 0) lppoint->x=0;
|
||||
if (lppoint->y < 0) lppoint->y=0;
|
||||
if (lppoint->x > rect.right) lppoint->x=rect.right;
|
||||
if (lppoint->y > rect.bottom) lppoint->y=rect.bottom;
|
||||
|
||||
lppoint->x = (lppoint->x * dxw.GetScreenWidth()) / rect.right;
|
||||
lppoint->y = (lppoint->y * dxw.GetScreenHeight()) / rect.bottom;
|
||||
|
||||
OutTraceC("GetCursorPos: hwnd=%x res=%x XY=(%d,%d)->(%d,%d)\n",
|
||||
dxw.GethWnd(), res, PrevX, PrevY, lppoint->x, lppoint->y);
|
||||
}
|
||||
*lppoint=dxw.ScreenToClient(*lppoint);
|
||||
*lppoint=dxw.FixCursorPos(*lppoint);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -716,6 +657,12 @@ LONG WINAPI extSetWindowLong(HWND hwnd, int nIndex, LONG dwNewLong)
|
||||
|
||||
if (nIndex==GWL_WNDPROC){
|
||||
long lres;
|
||||
// GPL fix
|
||||
if(hwnd==0) {
|
||||
hwnd=dxw.GethWnd();
|
||||
OutTrace("SetWindowLong: NULL hwnd, FIXING hwnd=%x\n",hwnd);
|
||||
}
|
||||
// end of GPL fix
|
||||
res=(LONG)WhndGetWindowProc(hwnd);
|
||||
WhndStackPush(hwnd, (WNDPROC)dwNewLong);
|
||||
SetLastError(0);
|
||||
@ -841,10 +788,11 @@ void dxwFixWindowPos(char *ApiName, HWND hwnd, LPARAM lParam)
|
||||
static int BorderY=-1;
|
||||
int cx, cy;
|
||||
|
||||
OutTraceD("%s: GOT hwnd=%x pos=(%d,%d) dim=(%d,%d) Flags=%x\n",
|
||||
ApiName, hwnd, wp->x, wp->y, wp->cx, wp->cy, wp->flags);
|
||||
OutTraceD("%s: GOT hwnd=%x pos=(%d,%d) dim=(%d,%d) Flags=%x(%s)\n",
|
||||
ApiName, hwnd, wp->x, wp->y, wp->cx, wp->cy, wp->flags, ExplainWPFlags(wp->flags));
|
||||
|
||||
if (wp->flags & (SWP_NOMOVE|SWP_NOSIZE)) return; //v2.02.10
|
||||
if ((wp->flags & (SWP_NOMOVE|SWP_NOSIZE))==(SWP_NOMOVE|SWP_NOSIZE)) return; //v2.02.13
|
||||
//if (wp->flags & (SWP_NOMOVE|SWP_NOSIZE)) return; //v2.02.10
|
||||
|
||||
if ((dxw.dwFlags1 & LOCKWINPOS) && dxw.IsFullScreen() && (hwnd==dxw.GethWnd())){
|
||||
extern void CalculateWindowPos(HWND, DWORD, DWORD, LPWINDOWPOS);
|
||||
@ -1352,6 +1300,7 @@ BOOL WINAPI extScreenToClient(HWND hwnd, LPPOINT lppoint)
|
||||
|
||||
BOOL WINAPI extGetClientRect(HWND hwnd, LPRECT lpRect)
|
||||
{
|
||||
BOOL ret;
|
||||
OutTraceD("GetClientRect: whnd=%x FullScreen=%x\n", hwnd, dxw.IsFullScreen());
|
||||
if (lpRect && dxw.IsFullScreen() && (hwnd == dxw.GethWnd())){
|
||||
lpRect->left=0;
|
||||
@ -1375,7 +1324,9 @@ BOOL WINAPI extGetClientRect(HWND hwnd, LPRECT lpRect)
|
||||
}
|
||||
|
||||
// proxed call
|
||||
return (*pGetClientRect)(hwnd, lpRect);
|
||||
ret=(*pGetClientRect)(hwnd, lpRect);
|
||||
OutTraceB("GetClientRect: rect=(%d,%d)-(%d,%d) ret=%d\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL WINAPI extGetWindowRect(HWND hwnd, LPRECT lpRect)
|
||||
@ -1529,16 +1480,20 @@ char *SysNames2[SYSLIBIDX_MAX]={
|
||||
"ddraw",
|
||||
"opengl32"
|
||||
};
|
||||
extern void HookModule(char *, int);
|
||||
extern void HookSysLibs(char *);
|
||||
extern void HookModule(HMODULE, int);
|
||||
extern void HookSysLibs(HMODULE);
|
||||
|
||||
HMODULE WINAPI extLoadLibraryA(LPCTSTR lpFileName)
|
||||
{
|
||||
HMODULE ret;
|
||||
HMODULE libhandle;
|
||||
int idx;
|
||||
char *lpName, *lpNext;
|
||||
ret=(*pLoadLibraryA)(lpFileName);
|
||||
OutTraceD("LoadLibraryA: FileName=%s hmodule=%x\n", lpFileName, ret);
|
||||
libhandle=(*pLoadLibraryA)(lpFileName);
|
||||
OutTraceD("LoadLibraryA: FileName=%s hmodule=%x\n", lpFileName, libhandle);
|
||||
if(!libhandle){
|
||||
OutTraceE("LoadLibraryExA: ERROR FileName=%s err=%d\n", lpFileName, GetLastError());
|
||||
return libhandle;
|
||||
}
|
||||
lpName=(char *)lpFileName;
|
||||
while (lpNext=strchr(lpName,'\\')) lpName=lpNext+1;
|
||||
for(idx=0; idx<SYSLIBIDX_MAX; idx++){
|
||||
@ -1546,27 +1501,25 @@ HMODULE WINAPI extLoadLibraryA(LPCTSTR lpFileName)
|
||||
(!lstrcmpi(lpName,SysNames[idx])) ||
|
||||
(!lstrcmpi(lpName,SysNames2[idx]))
|
||||
){
|
||||
OutTraceD("LoadLibraryA: registered hmodule=%x->FileName=%s\n", ret, lpFileName);
|
||||
SysLibs[idx]=ret;
|
||||
OutTraceD("LoadLibraryA: registered hmodule=%x->FileName=%s\n", libhandle, lpFileName);
|
||||
SysLibs[idx]=libhandle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// handle custom OpenGL library
|
||||
if(!lstrcmpi(lpName,dxw.CustomOpenGLLib)){
|
||||
idx=SYSLIBIDX_OPENGL;
|
||||
SysLibs[idx]=ret;
|
||||
SysLibs[idx]=libhandle;
|
||||
}
|
||||
//if(idx==SYSLIBIDX_MAX) {
|
||||
// OutTraceD("LoadLibraryA: hook %s\n", lpName);
|
||||
// HookModule((char *)lpName, 0);
|
||||
//}
|
||||
//HookSysLibs(NULL);
|
||||
HookModule(NULL, 0);
|
||||
return ret;
|
||||
|
||||
// don't hook target libraries, hook all the remaining ones!
|
||||
if(idx==SYSLIBIDX_MAX) HookModule(libhandle, 0);
|
||||
return libhandle;
|
||||
}
|
||||
|
||||
HMODULE WINAPI extLoadLibraryW(LPCWSTR lpFileName)
|
||||
{
|
||||
#if 0
|
||||
HMODULE ret;
|
||||
int idx;
|
||||
LPCWSTR lpName, lpNext;
|
||||
@ -1589,22 +1542,28 @@ HMODULE WINAPI extLoadLibraryW(LPCWSTR lpFileName)
|
||||
idx=SYSLIBIDX_OPENGL;
|
||||
SysLibs[idx]=ret;
|
||||
}
|
||||
//if(idx==SYSLIBIDX_MAX) {
|
||||
// OutTraceD("LoadLibraryW: hook %s\n", lpName);
|
||||
// HookModule((char *)lpName, 0);
|
||||
//}
|
||||
//HookSysLibs(NULL);
|
||||
HookModule(NULL, 0);
|
||||
char sName[81];
|
||||
wcstombs(sName, lpName, 80);
|
||||
HookModule(sName, 0);
|
||||
return ret;
|
||||
#else
|
||||
char sFileName[256+1];
|
||||
wcstombs(sFileName, lpFileName, 80);
|
||||
return extLoadLibraryA(sFileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
HMODULE WINAPI extLoadLibraryExA(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags)
|
||||
{
|
||||
HMODULE ret;
|
||||
HMODULE libhandle;
|
||||
int idx;
|
||||
char *lpName, *lpNext;
|
||||
ret=(*pLoadLibraryExA)(lpFileName, hFile, dwFlags);
|
||||
OutTraceD("LoadLibraryExA: FileName=%s hFile=%x Flags=%x hmodule=%x\n", lpFileName, hFile, dwFlags, ret);
|
||||
libhandle=(*pLoadLibraryExA)(lpFileName, hFile, dwFlags);
|
||||
OutTraceD("LoadLibraryExA: FileName=%s hFile=%x Flags=%x hmodule=%x\n", lpFileName, hFile, dwFlags, libhandle);
|
||||
if(!libhandle){
|
||||
OutTraceE("LoadLibraryExA: ERROR FileName=%s err=%d\n", lpFileName, GetLastError());
|
||||
return libhandle;
|
||||
}
|
||||
lpName=(char *)lpFileName;
|
||||
while (lpNext=strchr(lpName,'\\')) lpName=lpNext+1;
|
||||
for(idx=0; idx<SYSLIBIDX_MAX; idx++){
|
||||
@ -1612,27 +1571,23 @@ HMODULE WINAPI extLoadLibraryExA(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags
|
||||
(!lstrcmpi(lpName,SysNames[idx])) ||
|
||||
(!lstrcmpi(lpName,SysNames2[idx]))
|
||||
){
|
||||
OutTraceD("LoadLibraryExA: registered hmodule=%x->FileName=%s\n", ret, lpFileName);
|
||||
SysLibs[idx]=ret;
|
||||
OutTraceD("LoadLibraryExA: registered hmodule=%x->FileName=%s\n", libhandle, lpFileName);
|
||||
SysLibs[idx]=libhandle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// handle custom OpenGL library
|
||||
if(!lstrcmpi(lpName,dxw.CustomOpenGLLib)){
|
||||
idx=SYSLIBIDX_OPENGL;
|
||||
SysLibs[idx]=ret;
|
||||
SysLibs[idx]=libhandle;
|
||||
}
|
||||
//if(idx==SYSLIBIDX_MAX) {
|
||||
// OutTraceD("LoadLibraryExA: hook %s\n", lpName);
|
||||
// HookModule((char *)lpName, 0);
|
||||
//}
|
||||
//HookSysLibs(NULL);
|
||||
HookModule(NULL, 0);
|
||||
return ret;
|
||||
HookModule(libhandle, 0);
|
||||
return libhandle;
|
||||
}
|
||||
|
||||
HMODULE WINAPI extLoadLibraryExW(LPCWSTR lpFileName, HANDLE hFile, DWORD dwFlags)
|
||||
{
|
||||
#if 0
|
||||
HMODULE ret;
|
||||
int idx;
|
||||
LPCWSTR lpName, lpNext;
|
||||
@ -1655,13 +1610,15 @@ HMODULE WINAPI extLoadLibraryExW(LPCWSTR lpFileName, HANDLE hFile, DWORD dwFlags
|
||||
idx=SYSLIBIDX_OPENGL;
|
||||
SysLibs[idx]=ret;
|
||||
}
|
||||
//if(idx==SYSLIBIDX_MAX) {
|
||||
// OutTraceD("LoadLibraryExW: hook %s\n", lpName);
|
||||
// HookModule((char *)lpName, 0);
|
||||
//}
|
||||
//HookSysLibs(NULL);
|
||||
HookModule(NULL, 0);
|
||||
char sName[81];
|
||||
wcstombs(sName, lpName, 80);
|
||||
HookModule(sName, 0);
|
||||
return ret;
|
||||
#else
|
||||
char sFileName[256+1];
|
||||
wcstombs(sFileName, lpFileName, 80);
|
||||
return extLoadLibraryExA(sFileName, hFile, dwFlags);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern DirectDrawCreate_Type pDirectDrawCreate;
|
||||
@ -2680,8 +2637,10 @@ DWORD WINAPI extSleepEx(DWORD dwMilliseconds, BOOL bAlertable)
|
||||
|
||||
DWORD WINAPI exttimeGetTime(void)
|
||||
{
|
||||
if (IsDebug) OutTrace("timeGetTime\n");
|
||||
return dxw.GetTickCount();
|
||||
DWORD ret;
|
||||
ret = dxw.GetTickCount();
|
||||
if (IsDebug) OutTrace("timeGetTime: time=%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void WINAPI extGetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
|
||||
@ -2695,23 +2654,23 @@ int WINAPI extShowCursor(BOOL bShow)
|
||||
static int iFakeCounter;
|
||||
int ret;
|
||||
|
||||
OutTraceD("ShowCursor: bShow=%x\n", bShow);
|
||||
OutTraceC("ShowCursor: bShow=%x\n", bShow);
|
||||
if (bShow){
|
||||
if (dxw.dwFlags1 & HIDEHWCURSOR){
|
||||
iFakeCounter++;
|
||||
OutTraceD("ShowCursor: HIDEHWCURSOR ret=%x\n", iFakeCounter);
|
||||
OutTraceC("ShowCursor: HIDEHWCURSOR ret=%x\n", iFakeCounter);
|
||||
return iFakeCounter;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (dxw.dwFlags2 & SHOWHWCURSOR){
|
||||
iFakeCounter--;
|
||||
OutTraceD("ShowCursor: SHOWHWCURSOR ret=%x\n", iFakeCounter);
|
||||
OutTraceC("ShowCursor: SHOWHWCURSOR ret=%x\n", iFakeCounter);
|
||||
return iFakeCounter;
|
||||
}
|
||||
}
|
||||
ret=(*pShowCursor)(bShow);
|
||||
OutTraceD("ShowCursor: ret=%x\n", ret);
|
||||
OutTraceC("ShowCursor: ret=%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2730,10 +2689,17 @@ Windows Server 2003 5.2 5 2 GetSystemMetrics(SM_SERVERR2) == 0
|
||||
Windows XP Pro x64 Ed. 5.2 5 2 (OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION) && (SYSTEM_INFO.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
|
||||
Windows XP 5.1 5 1 Not applicable
|
||||
Windows 2000 5.0 5 0 Not applicable
|
||||
From http://delphi.about.com/cs/adptips2000/a/bltip1100_2.htm
|
||||
Windows 95 4.0 4 0
|
||||
Windows 98/SE" 4.10 4 10 if osVerInfo.szCSDVersion[1] = 'A' then Windows98SE
|
||||
Windows ME 4.90 4 90
|
||||
*/
|
||||
|
||||
static struct {char bMajor; char bMinor; char *sName;} WinVersions[6]=
|
||||
static struct {char bMajor; char bMinor; char *sName;} WinVersions[9]=
|
||||
{
|
||||
{4, 0, "Windows 95"},
|
||||
{4,10, "Windows 98/SE"},
|
||||
{4,90, "Windows ME"},
|
||||
{5, 0, "Windows 2000"},
|
||||
{5, 1, "Windows XP"},
|
||||
{5, 2, "Windows Server 2003"},
|
||||
@ -2800,3 +2766,38 @@ DWORD WINAPI extGetVersion(void)
|
||||
return dwVersion;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------------
|
||||
|
||||
GlobalMemoryStatus: MSDN documents that on modern PCs that have more than DWORD
|
||||
memory values the GlobalMemoryStatus sets the fields to -1 (0xFFFFFFFF) and you
|
||||
should use GlobalMemoryStatusEx instead.
|
||||
But in some cases the value is less that DWORD max, but greater that DWORD>>1, that
|
||||
is the calling application may get a big value and see it as a signed negative
|
||||
value, as it happened to Nocturne on my PC. That's why it's not adviseable to write:
|
||||
if(lpBuffer->dwTotalPhys== -1) ...
|
||||
but this way:
|
||||
if ((int)lpBuffer->dwTotalPhys < 0) ...
|
||||
and also don't set
|
||||
BIGENOUGH 0x80000000 // possibly negative!!!
|
||||
but:
|
||||
BIGENOUGH 0x20000000 // surely positive !!!
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
#define BIGENOUGH 0x20000000
|
||||
|
||||
void WINAPI extGlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
|
||||
{
|
||||
(*pGlobalMemoryStatus)(lpBuffer);
|
||||
OutTraceD("GlobalMemoryStatus: Length=%x MemoryLoad=%x "
|
||||
"TotalPhys=%x AvailPhys=%x TotalPageFile=%x AvailPageFile=%x TotalVirtual=%x AvailVirtual=%x\n",
|
||||
lpBuffer->dwMemoryLoad, lpBuffer->dwTotalPhys, lpBuffer->dwAvailPhys,
|
||||
lpBuffer->dwTotalPageFile, lpBuffer->dwAvailPageFile, lpBuffer->dwTotalVirtual, lpBuffer->dwAvailVirtual);
|
||||
if(lpBuffer->dwLength==sizeof(MEMORYSTATUS)){
|
||||
if ((int)lpBuffer->dwTotalPhys < 0) lpBuffer->dwTotalPhys = BIGENOUGH;
|
||||
if ((int)lpBuffer->dwAvailPhys < 0) lpBuffer->dwAvailPhys = BIGENOUGH;
|
||||
if ((int)lpBuffer->dwTotalPageFile < 0) lpBuffer->dwTotalPageFile = BIGENOUGH;
|
||||
if ((int)lpBuffer->dwAvailPageFile < 0) lpBuffer->dwAvailPageFile = BIGENOUGH;
|
||||
if ((int)lpBuffer->dwTotalVirtual < 0) lpBuffer->dwTotalVirtual = BIGENOUGH;
|
||||
if ((int)lpBuffer->dwAvailVirtual < 0) lpBuffer->dwAvailVirtual = BIGENOUGH;
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ typedef void (WINAPI *GetSystemTimeAsFileTime_Type)(LPFILETIME);
|
||||
typedef DWORD (WINAPI *GetTickCount_Type)(void);
|
||||
typedef DWORD (WINAPI *GetVersion_Type)(void);
|
||||
typedef BOOL (WINAPI *GetVersionEx_Type)(LPOSVERSIONINFO);
|
||||
typedef void (WINAPI *GlobalMemoryStatus_Type)(LPMEMORYSTATUS);
|
||||
typedef HMODULE (WINAPI *LoadLibraryA_Type)(LPCTSTR);
|
||||
typedef HMODULE (WINAPI *LoadLibraryExA_Type)(LPCTSTR, HANDLE, DWORD);
|
||||
typedef HMODULE (WINAPI *LoadLibraryW_Type)(LPCWSTR);
|
||||
@ -169,6 +170,7 @@ DXWEXTERN GetSystemTimeAsFileTime_Type pGetSystemTimeAsFileTime DXWINITIALIZED;
|
||||
DXWEXTERN GetTickCount_Type pGetTickCount DXWINITIALIZED;
|
||||
DXWEXTERN GetVersion_Type pGetVersion DXWINITIALIZED;
|
||||
DXWEXTERN GetVersionEx_Type pGetVersionEx DXWINITIALIZED;
|
||||
DXWEXTERN GlobalMemoryStatus_Type pGlobalMemoryStatus DXWINITIALIZED;
|
||||
DXWEXTERN LoadLibraryA_Type pLoadLibraryA DXWINITIALIZED;
|
||||
DXWEXTERN LoadLibraryExA_Type pLoadLibraryExA DXWINITIALIZED;
|
||||
DXWEXTERN LoadLibraryW_Type pLoadLibraryW DXWINITIALIZED;
|
||||
@ -275,6 +277,7 @@ extern void WINAPI extGetSystemTimeAsFileTime(LPFILETIME);
|
||||
extern DWORD WINAPI extGetTickCount(void);
|
||||
extern DWORD WINAPI extGetVersion(void);
|
||||
extern BOOL WINAPI extGetVersionEx(LPOSVERSIONINFO);
|
||||
extern void WINAPI extGlobalMemoryStatus(LPMEMORYSTATUS);
|
||||
extern HMODULE WINAPI extLoadLibraryA(LPCTSTR);
|
||||
extern HMODULE WINAPI extLoadLibraryExA(LPCTSTR, HANDLE, DWORD);
|
||||
extern HMODULE WINAPI extLoadLibraryW(LPCWSTR);
|
||||
|
77
dll/walkmod.cpp
Normal file
77
dll/walkmod.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "dxwnd.h"
|
||||
#include "dxwcore.hpp"
|
||||
|
||||
//#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
//#include <tchar.h>
|
||||
//#include "dxwnd.h"
|
||||
|
||||
extern void HookModule(HMODULE, int);
|
||||
extern void HookOpenGLLibs(HMODULE, char *);
|
||||
extern void DumpImportTable(HMODULE);
|
||||
|
||||
BOOL ListProcessModules(BOOL hook)
|
||||
{
|
||||
HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
|
||||
MODULEENTRY32 me32;
|
||||
|
||||
// Take a snapshot of all modules in the specified process.
|
||||
hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
|
||||
if( hModuleSnap == INVALID_HANDLE_VALUE){
|
||||
OutTraceD("CreateToolhelp32Snapshot ERROR: err=%d\n", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
me32.dwSize = sizeof( MODULEENTRY32 );
|
||||
|
||||
// Retrieve information about the first module,
|
||||
// and exit if unsuccessful
|
||||
if( !Module32First(hModuleSnap, &me32)){
|
||||
OutTraceE("Module32First ERROR: err=%d\n", GetLastError()); // Show cause of failure
|
||||
CloseHandle(hModuleSnap); // Must clean up the snapshot object!
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now walk the module list of the process,
|
||||
// and display information about each module
|
||||
do {
|
||||
if(IsDebug){
|
||||
OutTraceD("MODULE NAME:%s\n", me32.szModule );
|
||||
OutTraceD(" executable = %s\n", me32.szExePath );
|
||||
OutTraceD(" process ID = 0x%08X\n", me32.th32ProcessID );
|
||||
OutTraceD(" ref count (g) = 0x%04X\n", me32.GlblcntUsage );
|
||||
OutTraceD(" ref count (p) = 0x%04X\n", me32.ProccntUsage );
|
||||
OutTraceD(" base address = 0x%08X\n", (DWORD) me32.modBaseAddr );
|
||||
OutTraceD(" base size = %d\n", me32.modBaseSize );
|
||||
}
|
||||
|
||||
extern void HookSysLibs(HMODULE);
|
||||
if(hook) HookSysLibs((HMODULE)me32.modBaseAddr);
|
||||
|
||||
// if(strcmp("kernel32.dll", me32.szModule) && ("user32.dll", me32.szModule))
|
||||
// HookSysLibs((HMODULE)me32.modBaseAddr);
|
||||
//}
|
||||
//DO NOT COMPILE THIS !!!!
|
||||
//if(hook){
|
||||
// //HookModule((HMODULE)me32.modBaseAddr, dxw.dwTargetDDVersion);
|
||||
// if(!lstrcmpi("OpenGl32.dll", me32.szModule)){
|
||||
// MessageBox(0, "Got OpenGl", me32.szModule, MB_OK | MB_ICONEXCLAMATION);
|
||||
// //HookOpenGLLibs((HMODULE)me32.modBaseAddr, dxw.CustomOpenGLLib);
|
||||
// }
|
||||
//}
|
||||
//if(!strcmp(me32.szModule, "ref_gl.dll")) {
|
||||
// HookOpenGLLibs((HMODULE)me32.modBaseAddr, dxw.CustomOpenGLLib);
|
||||
// DumpImportTable((HMODULE)me32.modBaseAddr);
|
||||
//}
|
||||
|
||||
if (IsDebug) DumpImportTable((HMODULE)me32.modBaseAddr);
|
||||
} while( Module32Next( hModuleSnap, &me32 ) );
|
||||
// Do not forget to clean up the snapshot object.
|
||||
CloseHandle( hModuleSnap );
|
||||
return true;
|
||||
}
|
||||
|
63
host/Inject.cpp
Normal file
63
host/Inject.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "stdafx.h"
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <shlwapi.h>
|
||||
#include <conio.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
BOOL Inject(DWORD pID, const char * DLL_NAME)
|
||||
{
|
||||
HANDLE Proc;
|
||||
char buf[50] = {0};
|
||||
LPVOID RemoteString, LoadLibAddy;
|
||||
if(!pID) return false;
|
||||
//Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID); // not working on Win XP
|
||||
Proc = OpenProcess(PROCESS_CREATE_THREAD|PROCESS_QUERY_INFORMATION|PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE, FALSE, pID);
|
||||
if(!Proc)
|
||||
{
|
||||
sprintf(buf, "OpenProcess() failed: pid=%x err=%d", pID, GetLastError());
|
||||
MessageBox(NULL, buf, "Loader", MB_OK);
|
||||
printf(buf);
|
||||
return false;
|
||||
}
|
||||
LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
|
||||
// Allocate space in the process for our DLL
|
||||
RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_NAME), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||
// Write the string name of our DLL in the memory allocated
|
||||
WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME, strlen(DLL_NAME), NULL);
|
||||
// Load our DLL
|
||||
CreateRemoteThread(Proc, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, 0, NULL);
|
||||
CloseHandle(Proc);
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD GetTargetThreadIDFromProcName(const char * ProcName)
|
||||
{
|
||||
PROCESSENTRY32 pe;
|
||||
HANDLE thSnapShot;
|
||||
BOOL retval, ProcFound = false;
|
||||
thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if(thSnapShot == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
MessageBox(NULL, "Error: Unable to create toolhelp snapshot!", "2MLoader", MB_OK);
|
||||
//printf("Error: Unable to create toolhelp snapshot!");
|
||||
return false;
|
||||
}
|
||||
pe.dwSize = sizeof(PROCESSENTRY32);
|
||||
retval = Process32First(thSnapShot, &pe);
|
||||
while(retval)
|
||||
{
|
||||
if(StrStrI(pe.szExeFile, ProcName))
|
||||
{
|
||||
return pe.th32ProcessID;
|
||||
}
|
||||
retval = Process32Next(thSnapShot, &pe);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -145,6 +145,8 @@
|
||||
#define IDC_TABPANEL 1090
|
||||
#define IDC_WINDOWIZE 1091
|
||||
#define IDC_NOBANNER 1092
|
||||
#define IDC_NOBANNER2 1093
|
||||
#define IDC_STARTDEBUG 1093
|
||||
#define ID_MODIFY 32771
|
||||
#define ID_DELETE 32772
|
||||
#define ID_ADD 32773
|
||||
|
@ -43,8 +43,11 @@ END_MESSAGE_MAP()
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTabCompat message handlers
|
||||
|
||||
static struct {char bMajor; char bMinor; char *sName;} WinVersions[6]=
|
||||
static struct {char bMajor; char bMinor; char *sName;} WinVersions[9]=
|
||||
{
|
||||
{4, 0, "Windows 95"},
|
||||
{4,10, "Windows 98/SE"},
|
||||
{4,90, "Windows ME"},
|
||||
{5, 0, "Windows 2000"},
|
||||
{5, 1, "Windows XP"},
|
||||
{5, 2, "Windows Server 2003"},
|
||||
@ -61,7 +64,7 @@ BOOL CTabCompat::OnInitDialog()
|
||||
int i;
|
||||
List=(CListBox *)this->GetDlgItem(IDC_LISTFAKE);
|
||||
List->ResetContent();
|
||||
for(i=0; i<6; i++) List->AddString(WinVersions[i].sName);
|
||||
for(i=0; i<9; i++) List->AddString(WinVersions[i].sName);
|
||||
List->SetCurSel(cTarget->m_FakeVersion);
|
||||
CDialog::OnInitDialog();
|
||||
return TRUE;
|
||||
|
@ -33,6 +33,7 @@ void CTabProgram::DoDataExchange(CDataExchange* pDX)
|
||||
DDX_Check(pDX, IDC_UNNOTIFY, cTarget->m_UnNotify);
|
||||
DDX_Check(pDX, IDC_WINDOWIZE, cTarget->m_Windowize);
|
||||
DDX_Check(pDX, IDC_NOBANNER, cTarget->m_NoBanner);
|
||||
DDX_Check(pDX, IDC_STARTDEBUG, cTarget->m_StartDebug);
|
||||
DDX_Check(pDX, IDC_SAVELOAD, cTarget->m_SaveLoad);
|
||||
DDX_Check(pDX, IDC_HANDLEALTF4, cTarget->m_HandleAltF4);
|
||||
DDX_Text(pDX, IDC_POSX, cTarget->m_PosX);
|
||||
|
@ -39,6 +39,7 @@ CTargetDlg::CTargetDlg(CWnd* pParent /*=NULL*/)
|
||||
m_UnNotify = FALSE;
|
||||
m_Windowize = TRUE;
|
||||
m_NoBanner = FALSE;
|
||||
m_StartDebug = FALSE;
|
||||
m_FilePath = _T("");
|
||||
m_Module = _T("");
|
||||
m_SaveLoad = FALSE;
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
BOOL m_UnNotify;
|
||||
BOOL m_Windowize;
|
||||
BOOL m_NoBanner;
|
||||
BOOL m_StartDebug;
|
||||
CString m_FilePath;
|
||||
CString m_Module;
|
||||
CString m_Title;
|
||||
|
Binary file not shown.
@ -256,8 +256,9 @@ BEGIN
|
||||
CONTROL "Optimize CPU (DirectX1 - 7)",IDC_SAVELOAD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,122,123,12
|
||||
CONTROL "Intercept Alt-F4 key",IDC_HANDLEALTF4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,132,109,12
|
||||
CONTROL "Run in Window",IDC_WINDOWIZE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,142,124,12
|
||||
GROUPBOX "Generic",IDC_STATIC,7,103,140,72
|
||||
GROUPBOX "Generic",IDC_STATIC,7,103,140,75
|
||||
CONTROL "No banner",IDC_NOBANNER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,152,124,12
|
||||
CONTROL "use DLL Injection",IDC_STARTDEBUG,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,16,162,124,12
|
||||
END
|
||||
|
||||
IDD_TAB_LOG DIALOGEX 0, 0, 300, 240
|
||||
|
Binary file not shown.
@ -148,7 +148,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../Include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS; PSAPI_VERSION=1"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
@ -179,6 +179,7 @@
|
||||
OutputFile="../Debug/dxwnd.exe"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="true"
|
||||
AddModuleNamesToAssembly=""
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile=".\Debug/dxwnd.pdb"
|
||||
SubSystem="2"
|
||||
@ -302,6 +303,14 @@
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\getfname.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Inject.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="MainFrm.cpp"
|
||||
>
|
||||
|
@ -374,6 +374,7 @@ void CDxwndhostView::OnModify()
|
||||
dlg.m_UnNotify = TargetMaps[i].flags & UNNOTIFY ? 1 : 0;
|
||||
dlg.m_Windowize = TargetMaps[i].flags2 & WINDOWIZE ? 1 : 0;
|
||||
dlg.m_NoBanner = TargetMaps[i].flags2 & NOBANNER ? 1 : 0;
|
||||
dlg.m_StartDebug = TargetMaps[i].flags2 & STARTDEBUG ? 1 : 0;
|
||||
dlg.m_EmulateSurface = TargetMaps[i].flags & EMULATESURFACE ? 1 : 0;
|
||||
dlg.m_NoEmulateSurface = TargetMaps[i].flags & EMULATEFLAGS ? 0 : 1;
|
||||
dlg.m_EmulateBuffer = TargetMaps[i].flags & EMULATEBUFFER ? 1 : 0;
|
||||
@ -465,6 +466,7 @@ void CDxwndhostView::OnModify()
|
||||
if(dlg.m_UnNotify) TargetMaps[i].flags |= UNNOTIFY;
|
||||
if(dlg.m_Windowize) TargetMaps[i].flags2 |= WINDOWIZE;
|
||||
if(dlg.m_NoBanner) TargetMaps[i].flags2 |= NOBANNER;
|
||||
if(dlg.m_StartDebug) TargetMaps[i].flags2 |= STARTDEBUG;
|
||||
if(dlg.m_NoEmulateSurface) {
|
||||
dlg.m_EmulateSurface = FALSE;
|
||||
dlg.m_EmulateBuffer = FALSE;
|
||||
@ -763,6 +765,7 @@ void CDxwndhostView::OnAdd()
|
||||
if(dlg.m_UnNotify) TargetMaps[i].flags |= UNNOTIFY;
|
||||
if(dlg.m_Windowize) TargetMaps[i].flags2 |= WINDOWIZE;
|
||||
if(dlg.m_NoBanner) TargetMaps[i].flags2 |= NOBANNER;
|
||||
if(dlg.m_StartDebug) TargetMaps[i].flags2 |= STARTDEBUG;
|
||||
if(dlg.m_NoEmulateSurface) {
|
||||
dlg.m_EmulateSurface = FALSE;
|
||||
dlg.m_EmulateBuffer = FALSE;
|
||||
@ -1144,6 +1147,107 @@ void CDxwndhostView::OnRButtonDown(UINT nFlags, CPoint point)
|
||||
CListView::OnRButtonDown(nFlags, point);
|
||||
}
|
||||
|
||||
// For thread messaging
|
||||
#define DEBUG_EVENT_MESSAGE WM_APP + 0x100
|
||||
|
||||
HWND Ghwnd;
|
||||
|
||||
DWORD WINAPI StartDebug(void *p)
|
||||
{
|
||||
TARGETMAP *TargetMap;
|
||||
STARTUPINFO sinfo;
|
||||
PROCESS_INFORMATION pinfo, *pi;
|
||||
CREATE_THREAD_DEBUG_INFO *ti;
|
||||
LOAD_DLL_DEBUG_INFO *li;
|
||||
char path[MAX_PATH];
|
||||
BOOL step=FALSE; // initialize to TRUE to enable
|
||||
extern char *GetFileNameFromHandle(HANDLE);
|
||||
|
||||
TargetMap=(TARGETMAP *)p;
|
||||
ZeroMemory(&sinfo, sizeof(sinfo));
|
||||
sinfo.cb = sizeof(sinfo);
|
||||
strcpy_s(path, sizeof(path), TargetMap->path);
|
||||
PathRemoveFileSpec(path);
|
||||
CreateProcess(NULL, TargetMap->path, 0, 0, false, DEBUG_ONLY_THIS_PROCESS, NULL, path, &sinfo, &pinfo);
|
||||
CString strEventMessage;
|
||||
DEBUG_EVENT debug_event ={0};
|
||||
bool bContinueDebugging = true;
|
||||
DWORD dwContinueStatus = DBG_CONTINUE;
|
||||
while(bContinueDebugging)
|
||||
{
|
||||
int res;
|
||||
char DebugMessage[256+1];
|
||||
if (!WaitForDebugEvent(&debug_event, INFINITE)) return TRUE;
|
||||
switch(debug_event.dwDebugEventCode){
|
||||
case EXIT_PROCESS_DEBUG_EVENT:
|
||||
SetWindowText(Ghwnd, "EXIT PROCESS");
|
||||
bContinueDebugging=false;
|
||||
break;
|
||||
case CREATE_PROCESS_DEBUG_EVENT:
|
||||
if(step){
|
||||
pi=(PROCESS_INFORMATION *)&debug_event.u;
|
||||
sprintf(DebugMessage, "CREATE PROCESS hProcess=%x dwProcessId=%x path=%s",
|
||||
pi->hProcess, pi->dwProcessId, GetFileNameFromHandle(pi->hProcess));
|
||||
res=MessageBoxEx(0, DebugMessage, "Continue stepping?", MB_YESNO | MB_ICONQUESTION, NULL);
|
||||
if(res!=IDYES) step=FALSE;
|
||||
}
|
||||
if(1){
|
||||
// DLL injection:
|
||||
char buf[MAX_PATH] = {0};
|
||||
BOOL Injected;
|
||||
extern BOOL Inject(DWORD, const char *);
|
||||
GetFullPathName("dxinj.dll", MAX_PATH, buf, NULL);
|
||||
Injected=Inject(pinfo.dwProcessId, buf);
|
||||
if(!Injected){
|
||||
sprintf(DebugMessage,"Injection error: pid=%x dll=%s", pinfo.dwProcessId, buf);
|
||||
MessageBoxEx(0, DebugMessage, "Injection", MB_ICONEXCLAMATION, NULL);
|
||||
}
|
||||
// end of DLL injection
|
||||
}
|
||||
break;
|
||||
case CREATE_THREAD_DEBUG_EVENT:
|
||||
if(step){
|
||||
ti=(CREATE_THREAD_DEBUG_INFO *)&debug_event.u;
|
||||
sprintf(DebugMessage, "CREATE THREAD hThread=%x lpThreadLocalBase=%x lpStartAddress=%x",
|
||||
ti->hThread, ti->lpThreadLocalBase, ti->lpStartAddress);
|
||||
res=MessageBoxEx(0, DebugMessage, "Continue stepping?", MB_YESNO | MB_ICONQUESTION, NULL);
|
||||
if(res!=IDYES) step=FALSE;
|
||||
}
|
||||
break;
|
||||
case EXIT_THREAD_DEBUG_EVENT:
|
||||
SetWindowText(Ghwnd, "EXIT THREAD");
|
||||
break;
|
||||
case LOAD_DLL_DEBUG_EVENT:
|
||||
if(step){
|
||||
li=(LOAD_DLL_DEBUG_INFO *)&debug_event.u;
|
||||
sprintf(DebugMessage, "LOAD DLL hFile=%x path=%s",
|
||||
li->hFile, GetFileNameFromHandle(li->hFile));
|
||||
res=MessageBoxEx(0, DebugMessage, "Continue stepping?", MB_YESNO | MB_ICONQUESTION, NULL);
|
||||
if(res!=IDYES) step=FALSE;
|
||||
}
|
||||
break;
|
||||
case UNLOAD_DLL_DEBUG_EVENT:
|
||||
SetWindowText(Ghwnd, "UNLOAD DLL");
|
||||
break;
|
||||
case OUTPUT_DEBUG_STRING_EVENT:
|
||||
SetWindowText(Ghwnd, "OUT STRING");
|
||||
break;
|
||||
case EXCEPTION_DEBUG_EVENT:
|
||||
SetWindowText(Ghwnd, "EXCEPTION");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
SendMessage(Ghwnd, DEBUG_EVENT_MESSAGE, (WPARAM) &strEventMessage, debug_event.dwDebugEventCode);
|
||||
ContinueDebugEvent(debug_event.dwProcessId,
|
||||
debug_event.dwThreadId,
|
||||
dwContinueStatus);
|
||||
// Reset
|
||||
dwContinueStatus = DBG_CONTINUE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CDxwndhostView::OnRun()
|
||||
{
|
||||
CListCtrl& listctrl = GetListCtrl();
|
||||
@ -1152,6 +1256,7 @@ void CDxwndhostView::OnRun()
|
||||
STARTUPINFO sinfo;
|
||||
PROCESS_INFORMATION pinfo;
|
||||
char path[MAX_PATH];
|
||||
//extern CString GetFileNameFromHandle(HANDLE);
|
||||
|
||||
if(!listctrl.GetSelectedCount()) return;
|
||||
pos = listctrl.GetFirstSelectedItemPosition();
|
||||
@ -1160,5 +1265,11 @@ void CDxwndhostView::OnRun()
|
||||
sinfo.cb = sizeof(sinfo);
|
||||
strcpy_s(path, sizeof(path), TargetMaps[i].path);
|
||||
PathRemoveFileSpec(path);
|
||||
CreateProcess(0, TargetMaps[i].path, 0, 0, 0, CREATE_DEFAULT_ERROR_MODE, 0, path, &sinfo, &pinfo);
|
||||
if(TargetMaps[i].flags2 & STARTDEBUG){
|
||||
Ghwnd=this->m_hWnd;
|
||||
CreateThread( NULL, 0, StartDebug, &TargetMaps[i], 0, NULL);
|
||||
}
|
||||
else{
|
||||
CreateProcess(NULL, TargetMaps[i].path, 0, 0, false, CREATE_DEFAULT_ERROR_MODE, NULL, path, &sinfo, &pinfo);
|
||||
}
|
||||
}
|
||||
|
78
host/getfname.cpp
Normal file
78
host/getfname.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
#include "stdafx.h"
|
||||
#include <map>
|
||||
#include<Dbghelp.h>
|
||||
#include <psapi.h>
|
||||
|
||||
#include "shlwapi.h"
|
||||
|
||||
#define BUFSIZE 512
|
||||
|
||||
//Cstring GetFileNameFromHandle(HANDLE hFile)
|
||||
char *GetFileNameFromHandle(HANDLE hFile)
|
||||
{
|
||||
BOOL bSuccess = FALSE;
|
||||
TCHAR pszFilename[MAX_PATH+1];
|
||||
HANDLE hFileMap;
|
||||
//CString strFilename;
|
||||
static char strFilename[MAX_PATH+1];
|
||||
// Get the file size.
|
||||
DWORD dwFileSizeHi = 0;
|
||||
DWORD dwFileSizeLo = GetFileSize(hFile, &dwFileSizeHi);
|
||||
if( dwFileSizeLo == 0 && dwFileSizeHi == 0 ) return FALSE;
|
||||
typedef DWORD (WINAPI *GetMappedFileName_Type)(HANDLE, LPVOID, LPTSTR, DWORD);
|
||||
static GetMappedFileName_Type pGetMappedFileName = NULL;
|
||||
|
||||
if(!pGetMappedFileName) do { // fake loop
|
||||
HMODULE lib;
|
||||
// Psapi.dll (if PSAPI_VERSION=1) on Windows 7 and Windows Server 2008 R2;
|
||||
// Psapi.dll on Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP
|
||||
lib=LoadLibrary("Psapi.dll");
|
||||
pGetMappedFileName=(GetMappedFileName_Type)GetProcAddress(lib,"GetMappedFileNameA");
|
||||
if(pGetMappedFileName) break;
|
||||
// Kernel32.dll on Windows 7 and Windows Server 2008 R2;
|
||||
FreeLibrary(lib);
|
||||
lib=LoadLibrary("Kernel32.dll");
|
||||
pGetMappedFileName=(GetMappedFileName_Type)GetProcAddress(lib,"GetMappedFileNameA");
|
||||
if(!pGetMappedFileName) return NULL;
|
||||
} while(FALSE);
|
||||
|
||||
// Create a file mapping object.
|
||||
hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 1, NULL);
|
||||
if (hFileMap) {
|
||||
// Create a file mapping to get the file name.
|
||||
void* pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1);
|
||||
if (pMem) {
|
||||
if ((*pGetMappedFileName) (GetCurrentProcess(), pMem, pszFilename, MAX_PATH)){
|
||||
// Translate path with device name to drive letters.
|
||||
TCHAR szTemp[BUFSIZE];
|
||||
szTemp[0] = '\0';
|
||||
if (GetLogicalDriveStrings(BUFSIZE-1, szTemp)) {
|
||||
TCHAR szName[MAX_PATH];
|
||||
TCHAR szDrive[3] = TEXT(" :");
|
||||
BOOL bFound = FALSE;
|
||||
TCHAR* p = szTemp;
|
||||
do {
|
||||
// Copy the drive letter to the template string
|
||||
*szDrive = *p;
|
||||
// Look up each device name
|
||||
if (QueryDosDevice(szDrive, szName, MAX_PATH)){
|
||||
size_t uNameLen = _tcslen(szName);
|
||||
if (uNameLen < MAX_PATH) {
|
||||
bFound = _tcsnicmp(pszFilename, szName, uNameLen) == 0;
|
||||
//if (bFound) strFilename.Format(L"%s%s",szDrive, pszFilename+uNameLen);
|
||||
if (bFound) sprintf(strFilename, "%s%s", szDrive, pszFilename+uNameLen);
|
||||
}
|
||||
}
|
||||
// Go to the next NULL character.
|
||||
while (*p++);
|
||||
} while (!bFound && *p); // end of string
|
||||
}
|
||||
}
|
||||
bSuccess = TRUE;
|
||||
UnmapViewOfFile(pMem);
|
||||
}
|
||||
CloseHandle(hFileMap);
|
||||
}
|
||||
return(strFilename);
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
del dll\dxwnd.*.user
|
||||
del dll\dxwnd.*.ncb
|
||||
|
||||
del host\dxwndhost.*.user
|
||||
del host\dxwndhost.*.ncb
|
||||
|
||||
copy Release\dxwnd.exe build
|
||||
copy Release\dxwnd.dll build
|
||||
|
||||
del dll\Debug\*.*
|
||||
del dll\Release\*.*
|
||||
|
||||
del host\Debug\*.*
|
||||
del host\Release\*.*
|
||||
|
||||
echo build done
|
||||
pause
|
Loading…
x
Reference in New Issue
Block a user