1
0
mirror of https://github.com/DxWnd/DxWnd.reloaded synced 2024-12-30 09:25:35 +01:00

v2_02_27_src

Former-commit-id: 13f45f31d8d226c1f07c92f4e2dc65f9ab7d5400
This commit is contained in:
gho tik 2013-07-21 12:38:09 -04:00 committed by Refael ACkermann
parent 1e8566300a
commit 6762295239
34 changed files with 8116 additions and 3252 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:89c569d050fd740aedc07bce2d7c3708b13aa127300a83332e8a0d1dde02fdb1
size 344064
oid sha256:cebe66cab28374f902eeeecc7aa8db65b794c728a3857488cdb26860ef3976c8
size 342528

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:62dacd099414e7a8a4cfa4a1623aa5d55f7728bab0c61ea2a5ab5dfe1c7a43c2
size 524800
oid sha256:445871f8075154ab63a9ef75f3b7ffcfe0b96ffec47887290a22d037b0dc50e8
size 523264

File diff suppressed because it is too large Load Diff

View File

@ -151,3 +151,20 @@ Added Kill process by name functionality (right click menu on program's list)
Fixed GUI initial position: now checks for desktop size to fit GUI within visible borders
Added single cpu process affinity checkbox in compatibility tab
v2.02.26
CORE:
Fixed Black&White mode for 16BPP color depth
Revised hooking code, now more compact and clear....
Fixed DxWnd splash screen, for those who love it
Increased child win table - now 688 hunter killer works perfectly
GUI:
Added /debug flag to enable debugging options
Revised hooking code, now more compact and clear....
Restored Hook child win option
v2.02.27
CORE:
fixed GetDC/ReleaseDC ddraw implementation to refresh GDI operation on primary surface. Warlords 3 text is now visible.
preliminary implementation of MapWindowPoints - to be tested
GUI:
Fixed log flags wrong initialization

3797
dll/ddraw.cpp Normal file

File diff suppressed because it is too large Load Diff

304
dll/dinput.cpp Normal file
View File

@ -0,0 +1,304 @@
#include <windows.h>
#include <dinput.h>
#include "dxwnd.h"
#include "dxwcore.hpp"
#include "syslibs.h"
typedef HRESULT (WINAPI *QueryInterface_Type)(void *, REFIID, LPVOID *);
typedef HRESULT (WINAPI *DirectInputCreate_Type)(HINSTANCE, DWORD, LPDIRECTINPUT *, LPUNKNOWN);
typedef HRESULT (WINAPI *DirectInputCreateEx_Type)(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN);
typedef HRESULT (WINAPI *DICreateDevice_Type)(LPDIRECTINPUT, REFGUID, LPDIRECTINPUTDEVICE *, LPUNKNOWN);
typedef HRESULT (WINAPI *DICreateDeviceEx_Type)(LPDIRECTINPUT, REFGUID, REFIID, LPVOID *, LPUNKNOWN);
typedef HRESULT (WINAPI *GetDeviceData_Type)(LPDIRECTINPUTDEVICE, DWORD, LPVOID, LPDWORD, DWORD);
typedef HRESULT (WINAPI *GetDeviceState_Type)(LPDIRECTINPUTDEVICE, DWORD, LPDIMOUSESTATE);
typedef HRESULT (WINAPI *DISetCooperativeLevel_Type)(LPDIRECTINPUTDEVICE, HWND, DWORD);
typedef HRESULT (WINAPI *SetDataFormat_Type)(LPDIRECTINPUTDEVICE, LPCDIDATAFORMAT);
HRESULT WINAPI extDirectInputCreate(HINSTANCE, DWORD, LPDIRECTINPUT *, LPUNKNOWN);
HRESULT WINAPI extDirectInputCreateEx(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN);
HRESULT WINAPI extDirectInput8Create(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN);
HRESULT WINAPI extDICreateDevice(LPDIRECTINPUT, REFGUID, LPDIRECTINPUTDEVICE *, LPUNKNOWN);
HRESULT WINAPI extDICreateDeviceEx(LPDIRECTINPUT, REFGUID, REFIID, LPVOID *, LPUNKNOWN);
HRESULT WINAPI extGetDeviceData(LPDIRECTINPUTDEVICE, DWORD, LPVOID, LPDWORD, DWORD);
HRESULT WINAPI extGetDeviceState(LPDIRECTINPUTDEVICE, DWORD, LPDIMOUSESTATE);
HRESULT WINAPI extDISetCooperativeLevel(LPDIRECTINPUTDEVICE, HWND, DWORD);
HRESULT WINAPI extSetDataFormat(LPDIRECTINPUTDEVICE, LPCDIDATAFORMAT);
HRESULT WINAPI extQueryInterfaceI(void *, REFIID, LPVOID *);
void GetMousePosition(int *, int *);
void InitPosition(int, int, int, int, int, int);
DirectInputCreate_Type pDirectInputCreate = 0;
DirectInputCreateEx_Type pDirectInputCreateEx = 0;
DICreateDevice_Type pDICreateDevice = 0;
DICreateDeviceEx_Type pDICreateDeviceEx = 0;
GetDeviceData_Type pGetDeviceData;
GetDeviceState_Type pGetDeviceState;
DISetCooperativeLevel_Type pDISetCooperativeLevel;
SetDataFormat_Type pSetDataFormat;
QueryInterface_Type pQueryInterfaceI;
int iCursorX;
int iCursorY;
int iCursorXBuf;
int iCursorYBuf;
int iCurMinX;
int iCurMinY;
int iCurMaxX;
int iCurMaxY;
int HookDirectInput(HMODULE module, int version)
{
HINSTANCE hinst;
void *tmp;
LPDIRECTINPUT lpdi;
const GUID di7 = {0x9A4CB684,0x236D,0x11D3,0x8E,0x9D,0x00,0xC0,0x4F,0x68,0x44,0xAE};
const GUID di8 = {0xBF798030,0x483A,0x4DA2,0xAA,0x99,0x5D,0x64,0xED,0x36,0x97,0x00};
tmp = HookAPI(module, "dinput.dll", NULL, "DirectInputCreateA", extDirectInputCreate);
if(tmp) pDirectInputCreate = (DirectInputCreate_Type)tmp;
tmp = HookAPI(module, "dinput.dll", NULL, "DirectInputCreateW", extDirectInputCreate);
if(tmp) pDirectInputCreate = (DirectInputCreate_Type)tmp;
tmp = HookAPI(module, "dinput.dll", NULL, "DirectInputCreateEx", extDirectInputCreateEx);
if(tmp) pDirectInputCreateEx = (DirectInputCreateEx_Type)tmp;
tmp = HookAPI(module, "dinput8.dll", NULL, "DirectInput8Create", extDirectInput8Create);
if(tmp) pDirectInputCreateEx = (DirectInputCreateEx_Type)tmp;
if(!pDirectInputCreate && !pDirectInputCreateEx){
if(version < 8){
hinst = LoadLibrary("dinput.dll");
pDirectInputCreate =
(DirectInputCreate_Type)GetProcAddress(hinst, "DirectInputCreateA");
if(pDirectInputCreate)
if(!extDirectInputCreate(GetModuleHandle(0), DIRECTINPUT_VERSION,
&lpdi, 0)) lpdi->Release();
pDirectInputCreateEx =
(DirectInputCreateEx_Type)GetProcAddress(hinst, "DirectInputCreateEx");
if(pDirectInputCreateEx)
if(!extDirectInputCreateEx(GetModuleHandle(0), DIRECTINPUT_VERSION,
di7, (void **)&lpdi, 0)) lpdi->Release();
}
else{
hinst = LoadLibrary("dinput8.dll");
pDirectInputCreateEx =
(DirectInputCreateEx_Type)GetProcAddress(hinst, "DirectInput8Create");
if(pDirectInputCreateEx)
if(!extDirectInputCreateEx(GetModuleHandle(0), DIRECTINPUT_VERSION,
di8, (void **)&lpdi, 0)) lpdi->Release();
}
}
if(pDirectInputCreate || pDirectInputCreateEx) return 1;
return 0;
}
HRESULT WINAPI extDirectInputCreate(HINSTANCE hinst,
DWORD dwversion, LPDIRECTINPUT *lplpdi, LPUNKNOWN pu)
{
HRESULT res;
OutTraceD("DirectInputCreate: dwVersion = %x\n",
dwversion);
res = (*pDirectInputCreate)(hinst, dwversion, lplpdi, pu);
if(res) return res;
SetHook((void *)(**(DWORD **)lplpdi + 12), extDICreateDevice, (void **)&pDICreateDevice, "CreateDevice(I)");
SetHook((void *)(**(DWORD **)lplpdi), extQueryInterfaceI, (void **)&pQueryInterfaceI, "QueryInterface(I)");
return 0;
}
HRESULT WINAPI extDirectInputCreateEx(HINSTANCE hinst,
DWORD dwversion, REFIID riidltf, LPVOID *ppvout, LPUNKNOWN pu)
{
HRESULT res;
OutTraceD("DirectInputCreateEx: dwVersion = %x REFIID = %x\n",
dwversion, riidltf.Data1);
res = (*pDirectInputCreateEx)(hinst, dwversion, riidltf, ppvout, pu);
if(res) return res;
SetHook((void *)(**(DWORD **)ppvout + 12), extDICreateDevice, (void **)&pDICreateDevice, "CreateDevice(I)");
SetHook((void *)(**(DWORD **)ppvout + 36), extDICreateDeviceEx, (void **)pDICreateDeviceEx, "DICreateDeviceEx(I)");
return 0;
}
HRESULT WINAPI extQueryInterfaceI(void * lpdi, REFIID riid, LPVOID *obp)
{
HRESULT res;
OutTraceD("lpDI->QueryInterface: REFIID = %x\n",
riid.Data1);
res = (*pQueryInterfaceI)(lpdi, riid, obp);
if(res) return res;
switch(riid.Data1){
case 0x5944E662: //DirectInput2A
case 0x5944E663: //DirectInput2W
SetHook((void *)(**(DWORD **)obp + 12), extDICreateDevice, (void **)pDICreateDevice, "CreateDevice(I)");
break;
}
return 0;
}
HRESULT WINAPI extDirectInput8Create(HINSTANCE hinst,
DWORD dwversion, REFIID riidltf, LPVOID *ppvout, LPUNKNOWN pu)
{
HRESULT res;
OutTraceD("DirectInput8Create: dwVersion = %x REFIID = %x\n",
dwversion, riidltf.Data1);
res = (*pDirectInputCreateEx)(hinst, dwversion, riidltf, ppvout, pu);
if(res) return res;
SetHook((void *)(**(DWORD **)ppvout + 12), extDICreateDevice, (void **)&pDICreateDevice, "CreateDevice(I8)");
return 0;
}
HRESULT WINAPI extDICreateDevice(LPDIRECTINPUT lpdi, REFGUID rguid,
LPDIRECTINPUTDEVICE *lplpdid, LPUNKNOWN pu)
{
HRESULT res;
OutTraceD("lpDI->CreateDevice: REFGUID = %x\n",
rguid.Data1);
res = (*pDICreateDevice)(lpdi, rguid, lplpdid, pu);
if(res) return res;
SetHook((void *)(**(DWORD **)lplpdid + 36), extGetDeviceState, (void **)&pGetDeviceState, "GetDeviceState(I)");
SetHook((void *)(**(DWORD **)lplpdid + 40), extGetDeviceData, (void **)&pGetDeviceData, "GetDeviceData(I)");
SetHook((void *)(**(DWORD **)lplpdid + 44), extSetDataFormat, (void **)&pSetDataFormat, "SetDataFormat(I)");
SetHook((void *)(**(DWORD **)lplpdid + 52), extDISetCooperativeLevel, (void **)&pDISetCooperativeLevel, "SetCooperativeLevel(I)");
return 0;
}
HRESULT WINAPI extDICreateDeviceEx(LPDIRECTINPUT lpdi, REFGUID rguid,
REFIID riid, LPVOID *pvout, LPUNKNOWN pu)
{
HRESULT res;
OutTraceD("lpDI->CreateDeviceEx: GUID = %x REFIID = %x\n",
rguid.Data1, riid.Data1);
res = (*pDICreateDeviceEx)(lpdi, rguid, riid, pvout, pu);
if(res) return res;
SetHook((void *)(**(DWORD **)pvout + 36), extGetDeviceState, (void **)&pGetDeviceState, "GetDeviceState(I)");
SetHook((void *)(**(DWORD **)pvout + 40), extGetDeviceData, (void **)&pGetDeviceData, "GetDeviceData(I)");
SetHook((void *)(**(DWORD **)pvout + 44), extSetDataFormat, (void **)&pSetDataFormat, "SetDataFormat(I)");
SetHook((void *)(**(DWORD **)pvout + 52), extDISetCooperativeLevel, (void **)&pDISetCooperativeLevel, "SetCooperativeLevel(I)");
return 0;
}
HRESULT WINAPI extGetDeviceData(LPDIRECTINPUTDEVICE lpdid, DWORD cbdata, LPVOID rgdod, LPDWORD pdwinout, DWORD dwflags)
{
HRESULT res;
BYTE *tmp;
unsigned int i;
POINT p;
OutTraceD("GetDeviceData cbdata:%i\n", cbdata);
res = (*pGetDeviceData)(lpdid, cbdata, rgdod, pdwinout, dwflags);
if(res) return res;
if(!dxw.bActive) *pdwinout = 0;
GetMousePosition((int *)&p.x, (int *)&p.y);
if(cbdata == 20 || cbdata == 24){
tmp = (BYTE *)rgdod;
for(i = 0; i < *pdwinout; i ++){
if(((LPDIDEVICEOBJECTDATA)tmp)->dwOfs == DIMOFS_X){
((LPDIDEVICEOBJECTDATA)tmp)->dwData = p.x;
if(!dxw.bDInputAbs){
if(p.x < iCurMinX) p.x = iCurMinX;
if(p.x > iCurMaxX) p.x = iCurMaxX;
((LPDIDEVICEOBJECTDATA)tmp)->dwData = p.x - iCursorXBuf;
iCursorXBuf = p.x;
}
}
if(((LPDIDEVICEOBJECTDATA)tmp)->dwOfs == DIMOFS_Y){
((LPDIDEVICEOBJECTDATA)tmp)->dwData = p.y;
if(!dxw.bDInputAbs){
if(p.y < iCurMinY) p.y = iCurMinY;
if(p.y > iCurMaxY) p.y = iCurMaxY;
((LPDIDEVICEOBJECTDATA)tmp)->dwData = p.y - iCursorYBuf;
iCursorYBuf = p.y;
}
}
tmp += cbdata;
}
OutTraceD("DEBUG: directinput mousedata=(%d,%d)\n", p.x, p.y);
}
return 0;
}
HRESULT WINAPI extGetDeviceState(LPDIRECTINPUTDEVICE lpdid, DWORD cbdata, LPDIMOUSESTATE lpvdata)
{
HRESULT res;
POINT p = {0, 0};
OutTraceD("GetDeviceState cbData:%i %i\n", cbdata, dxw.bActive);
res = (*pGetDeviceState)(lpdid, cbdata, lpvdata);
if(res) return res;
if(cbdata == sizeof(DIMOUSESTATE) || cbdata == sizeof(DIMOUSESTATE2)){
GetMousePosition((int *)&p.x, (int *)&p.y);
lpvdata->lX = p.x;
lpvdata->lY = p.y;
if(!dxw.bDInputAbs){
if(p.x < iCurMinX) p.x = iCurMinX;
if(p.x > iCurMaxX) p.x = iCurMaxX;
if(p.y < iCurMinY) p.y = iCurMinY;
if(p.y > iCurMaxY) p.y = iCurMaxY;
lpvdata->lX = p.x - iCursorX;
lpvdata->lY = p.y - iCursorY;
iCursorX = p.x;
iCursorY = p.y;
}
if(!dxw.bActive){
lpvdata->lZ = 0;
*(DWORD *)lpvdata->rgbButtons = 0;
}
OutTraceD("DEBUG: directinput mousestate=(%d,%d)\n", p.x, p.y);
}
if(cbdata == 256 && !dxw.bActive) ZeroMemory(lpvdata, 256);
return 0;
}
HRESULT WINAPI extSetDataFormat(LPDIRECTINPUTDEVICE lpdid, LPCDIDATAFORMAT lpdf)
{
OutTraceD("SetDataFormat: flags = 0x%x\n", lpdf->dwFlags);
if(lpdf->dwFlags & DIDF_ABSAXIS) dxw.bDInputAbs = 1;
if(lpdf->dwFlags & DIDF_RELAXIS) dxw.bDInputAbs = 0;
return (*pSetDataFormat)(lpdid, lpdf);
}
HRESULT WINAPI extDISetCooperativeLevel(LPDIRECTINPUTDEVICE lpdid, HWND hwnd, DWORD dwflags)
{
OutTraceD("lpDI->SetCooperativeLevel\n");
dwflags = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
return (*pDISetCooperativeLevel)(lpdid, hwnd, dwflags);
}
// Simplified version, taking in proper account the GetCursorPos API hooking & coordinate processing
void GetMousePosition(int *x, int *y)
{
POINT p;
//GetCursorPos(&p);
extern BOOL WINAPI extGetCursorPos(LPPOINT);
extGetCursorPos(&p);
*x = p.x;
*y = p.y;
OutTraceD("GetMousePosition: x,y=(%d,%d)\n", *x, *y);
}
void InitPosition(int x, int y, int minx, int miny, int maxx, int maxy)
{
iCursorX = x;
iCursorY = y;
iCursorXBuf = x;
iCursorYBuf = y;
iCurMinX = minx;
iCurMinY = miny;
iCurMaxX = maxx;
iCurMaxY = maxy;
}

View File

@ -193,21 +193,31 @@ static HRESULT WINAPI EmuBlt_16_to_32(LPDIRECTDRAWSURFACE lpddsdst, LPRECT lpdes
if (!Palette16BPP) { // first time through .....
unsigned int pi;
Palette16BPP = (DWORD *)malloc(0x10000 * sizeof(DWORD));
if (dxw.dwFlags1 & USERGB565){
for (pi=0; pi<0x10000; pi++) {
Palette16BPP[pi]=(pi & 0x1F)<<3 | (pi & 0x7E0)<<5 | (pi & 0xF800)<<8; // RGB565
if (dxw.dwFlags3 & BLACKWHITE){
DWORD grey;
if (dxw.dwFlags1 & USERGB565){
for (pi=0; pi<0x10000; pi++) {
grey = ((((pi & 0x1F)<<3) + ((pi & 0x7E0)>>3) + ((pi & 0xF800)>>8)) / 3) & 0xFF;
Palette16BPP[pi] = (grey) + (grey<<8) + (grey<<16);
}
}
else {
for (pi=0; pi<0x10000; pi++) {
grey = ((((pi & 0x1F)<<3) + ((pi & 0x3E0)>>2) + ((pi & 0x7C00)>>7)) / 3) & 0xFF;
Palette16BPP[pi] = grey + (grey<<8) + (grey<<16);
}
}
}
else {
for (pi=0; pi<0x10000; pi++) {
Palette16BPP[pi]=(pi & 0x1F)<<3 | (pi & 0x3E0)<<6 | (pi & 0x7C00)<<9; // RGB555
if (dxw.dwFlags1 & USERGB565){
for (pi=0; pi<0x10000; pi++) {
Palette16BPP[pi]=(pi & 0x1F)<<3 | (pi & 0x7E0)<<5 | (pi & 0xF800)<<8; // RGB565
}
}
}
if (dxw.dwFlags3 & BLACKWHITE){
for (pi=0; pi<0x10000; pi++) {
DWORD grey;
grey=((pi & 0xFF) + ((pi & 0xFF00)>>8) + ((pi & 0xFF0000)>>16)) / 3;
Palette16BPP[pi] = grey + (grey<<8) + (grey<<16);
else {
for (pi=0; pi<0x10000; pi++) {
Palette16BPP[pi]=(pi & 0x1F)<<3 | (pi & 0x3E0)<<6 | (pi & 0x7C00)<<9; // RGB555
}
}
}
}

View File

@ -23,6 +23,8 @@ extern void InitScreenParameters();
void HookModule(HMODULE, int);
static void RecoverScreenMode();
static void LockScreenMode(DWORD, DWORD, DWORD);
DEVMODE SetDevMode;
DEVMODE *pSetDevMode=NULL;
extern HANDLE hTraceMutex;
@ -305,6 +307,144 @@ void SetHook(void *target, void *hookproc, void **hookedproc, char *hookname)
*hookedproc = tmp;
}
#ifdef HOOKBYIAT
PIMAGE_SECTION_HEADER ImageRVA2Section(PIMAGE_NT_HEADERS pimage_nt_headers,DWORD dwRVA)
{
int i;
PIMAGE_SECTION_HEADER pimage_section_header=(PIMAGE_SECTION_HEADER)((PCHAR(pimage_nt_headers)) + sizeof(IMAGE_NT_HEADERS));
for(i=0;i<pimage_nt_headers->FileHeader.NumberOfSections;i++)
{
if((pimage_section_header->VirtualAddress) && (dwRVA<=(pimage_section_header->VirtualAddress+pimage_section_header->SizeOfRawData)))
{
return ((PIMAGE_SECTION_HEADER)pimage_section_header);
}
pimage_section_header++;
}
return(NULL);
}
DWORD RVA2Offset(PCHAR pImageBase,DWORD dwRVA)
{
DWORD _offset;
PIMAGE_SECTION_HEADER section;
PIMAGE_DOS_HEADER pimage_dos_header;
PIMAGE_NT_HEADERS pimage_nt_headers;
pimage_dos_header = PIMAGE_DOS_HEADER(pImageBase);
pimage_nt_headers = (PIMAGE_NT_HEADERS)(pImageBase+pimage_dos_header->e_lfanew);
section=ImageRVA2Section(pimage_nt_headers,dwRVA);
if(section==NULL)
{
return(0);
}
_offset=dwRVA+section->PointerToRawData-section->VirtualAddress;
return(_offset);
}
void *HookAPI(HMODULE module, char *dll, void *apiproc, const char *apiname, void *hookproc)
{
PIMAGE_NT_HEADERS pnth;
PIMAGE_IMPORT_DESCRIPTOR pidesc;
DWORD base, rva;
PSTR impmodule;
PIMAGE_THUNK_DATA ptaddr;
PIMAGE_THUNK_DATA ptname;
PIMAGE_IMPORT_BY_NAME piname;
DWORD oldprotect;
void *org;
PCHAR pThunk;
DWORD dwThunk;
PCHAR pDllName;
OutTraceB("HookAPI: module=%x dll=%s apiproc=%x apiname=%s hookproc=%x\n",
module, dll, apiproc, apiname, hookproc);
if(!*apiname) { // check
char *sMsg="HookAPI: NULL api name\n";
OutTraceE(sMsg);
if (IsAssertEnabled) MessageBox(0, sMsg, "HookAPI", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
base = (DWORD)module;
__try{
pnth = PIMAGE_NT_HEADERS(PBYTE(base) + PIMAGE_DOS_HEADER(base)->e_lfanew);
if(!pnth) {
OutTraceE("HookAPI: ERROR no PNTH at %d\n", __LINE__);
return 0;
}
rva = pnth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress;
if(!rva) {
OutTraceE("HookAPI: ERROR no IAT at %d\n", __LINE__);
return 0;
}
pidesc = (PIMAGE_IMPORT_DESCRIPTOR)(base + rva);
OutTraceD("HookAPI: pidesc=%x\n", pidesc);
while(pidesc->Name){
pThunk=(PCHAR)base+pidesc->FirstThunk;
dwThunk = pidesc->FirstThunk;
pDllName=(PSTR)base+pidesc->Name;
OutTraceD("HookAPI: pDllName=%s Name=%s\n", pDllName, pidesc->Name);
//impmodule = (PSTR)(base + pidesc->Name);
//if(!lstrcmpi(dll, impmodule)) break;
pidesc ++;
}
if(!pidesc->FirstThunk) {
OutTraceB("HookAPI: PE unreferenced dll=%s\n", dll);
return 0;
}
ptaddr = (PIMAGE_THUNK_DATA)(base + (DWORD)pidesc->FirstThunk);
ptname = (pidesc->OriginalFirstThunk) ? (PIMAGE_THUNK_DATA)(base + (DWORD)pidesc->OriginalFirstThunk) : NULL;
if((apiproc==NULL) && (ptname==NULL)){
if (IsDebug) OutTraceD("HookAPI: unreacheable api=%s dll=%s\n", apiname, dll);
return 0;
}
while(ptaddr->u1.Function){
if (ptname){
if(!IMAGE_SNAP_BY_ORDINAL(ptname->u1.Ordinal)){
piname = (PIMAGE_IMPORT_BY_NAME)(base + (DWORD)ptname->u1.AddressOfData);
if(!lstrcmpi(apiname, (char *)piname->Name)) break;
}
}
if (apiproc){
if(ptaddr->u1.Function == (DWORD)apiproc) break;
}
ptaddr ++;
if (ptname) ptname ++;
}
if(!ptaddr->u1.Function) return 0;
org = (void *)ptaddr->u1.Function;
if(org == hookproc) return 0; // already hooked
if(!VirtualProtect(&ptaddr->u1.Function, 4, PAGE_EXECUTE_READWRITE, &oldprotect)) {
OutTraceD("HookAPI: VirtualProtect error %d at %d\n", GetLastError(), __LINE__);
return 0;
}
ptaddr->u1.Function = (DWORD)hookproc;
if(!VirtualProtect(&ptaddr->u1.Function, 4, oldprotect, &oldprotect)) {
OutTraceD("HookAPI: VirtualProtect error %d at %d\n", GetLastError(), __LINE__);
return 0;
}
if (!FlushInstructionCache(GetCurrentProcess(), &ptaddr->u1.Function, 4)) {
OutTraceD("HookAPI: FlushInstructionCache error %d at %d\n", GetLastError(), __LINE__);
return 0;
}
if(IsDebug) OutTrace("HookAPI hook=%s address=%x->%x\n", apiname, org, hookproc);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
OutTraceD("HookAPI: EXCEPTION hook=%s:%s Hook Failed.\n", dll, apiname);
org = 0;
}
return org;
}
#else
void *HookAPI(HMODULE module, char *dll, void *apiproc, const char *apiname, void *hookproc)
{
PIMAGE_NT_HEADERS pnth;
@ -331,12 +471,12 @@ void *HookAPI(HMODULE module, char *dll, void *apiproc, const char *apiname, voi
__try{
pnth = PIMAGE_NT_HEADERS(PBYTE(base) + PIMAGE_DOS_HEADER(base)->e_lfanew);
if(!pnth) {
OutTraceE("HookAPI: ERROR no pnth at %d\n", __LINE__);
OutTraceE("HookAPI: ERROR no PNTH at %d\n", __LINE__);
return 0;
}
rva = pnth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
if(!rva) {
OutTraceE("HookAPI: ERROR no rva at %d\n", __LINE__);
OutTraceE("HookAPI: ERROR no RVA at %d\n", __LINE__);
return 0;
}
pidesc = (PIMAGE_IMPORT_DESCRIPTOR)(base + rva);
@ -391,7 +531,7 @@ void *HookAPI(HMODULE module, char *dll, void *apiproc, const char *apiname, voi
return 0;
}
if(IsDebug) OutTrace("HookAPI hook=%s address=%x->%x\n", apiname, org, hookproc);
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
OutTraceD("HookAPI: EXCEPTION hook=%s:%s Hook Failed.\n", dll, apiname);
@ -400,6 +540,8 @@ void *HookAPI(HMODULE module, char *dll, void *apiproc, const char *apiname, voi
return org;
}
#endif
// v.2.1.80: unified positioning logic into CalculateWindowPos routine
// now taking in account for window menus (see "Alien Cabal")
@ -580,7 +722,7 @@ LRESULT CALLBACK extChildWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPAR
// Cybermercs: it seems that all game menus are conveniently handled by the WindowProc routine,
// while the action screen get messages processed by the ChildWindowProc, that needs some different
// setting ..........
// Beware: Cybermercs handles some static info about curror position handling, so that if you resize
// Beware: Cybermercs handles some static info about cursor position handling, so that if you resize
// a menu it doesn't work correctly until you don't change screen.
case WM_MOUSEMOVE:
case WM_MOUSEWHEEL:
@ -968,134 +1110,9 @@ void HookSysLibsInit()
if(DoOnce) return;
DoOnce=TRUE;
pLoadLibraryA = LoadLibraryA;
pLoadLibraryExA = LoadLibraryExA;
pLoadLibraryW = LoadLibraryW;
pLoadLibraryExW = LoadLibraryExW;
pGetProcAddress = (GetProcAddress_Type)GetProcAddress;
pGDICreateCompatibleDC=CreateCompatibleDC;
pGDIDeleteDC=DeleteDC;
pGDIGetDC=GetDC;
pGDIGetWindowDC=GetWindowDC;
pGDIReleaseDC=ReleaseDC;
pGDICreateDC=CreateDC;
pGDIBitBlt=BitBlt;
pGDIStretchBlt=StretchBlt;
pBeginPaint=BeginPaint;
pEndPaint=EndPaint;
pInvalidateRect=InvalidateRect;
pScreenToClient = ScreenToClient;
pClientToScreen = ClientToScreen;
pGetClientRect = GetClientRect;
pGetWindowRect = GetWindowRect;
pMapWindowPoints= MapWindowPoints;
pChangeDisplaySettings=ChangeDisplaySettingsA;
pChangeDisplaySettingsEx=ChangeDisplaySettingsExA;
pClipCursor = ClipCursor;
pFillRect = FillRect;
pPeekMessage = PeekMessage;
pGetMessage = GetMessage;
pDefWindowProc = DefWindowProc;
pGDIGetDeviceCaps = GetDeviceCaps;
pGDITextOutA = TextOutA;
pGDIScaleWindowExtEx = ScaleWindowExtEx;
pCreateWindowExA = CreateWindowExA;
pRegisterClassExA = (RegisterClassExA_Type)RegisterClassExA;
pGDIRectangle = Rectangle;
pSetWindowPos=SetWindowPos;
pGDIDeferWindowPos=DeferWindowPos;
pSetWindowLong=SetWindowLongA;
pGetWindowLong=GetWindowLongA;
pCallWindowProc=CallWindowProcA;
pShowWindow=ShowWindow;
pGDISetTextColor = SetTextColor;
pGDISetBkColor = SetBkColor;
pGDICreateFont = CreateFont;
pGDICreateFontIndirect = CreateFontIndirect;
pGetSystemMetrics = GetSystemMetrics;
pGetCursorPos = GetCursorPos;
pSetCursorPos = SetCursorPos;
pSetCursor = SetCursor;
pCreateDialogIndirectParam=CreateDialogIndirectParamA;
pCreateDialogParam=CreateDialogParamA;
pMoveWindow=MoveWindow;
pGetDesktopWindow=GetDesktopWindow;
pShowCursor=ShowCursor;
pGetTickCount=GetTickCount;
pSleep=Sleep;
pSleepEx=SleepEx;
pGetSystemTime=GetSystemTime;
pGetLocalTime=GetLocalTime;
pSetTimer=SetTimer;
}
void HookGDILib(HMODULE module)
{
void *tmp;
if(dxw.dwFlags1 & MAPGDITOPRIMARY){
tmp = HookAPI(module, "GDI32.dll", CreateCompatibleDC, "CreateCompatibleDC", extDDCreateCompatibleDC);
if(tmp) pGDICreateCompatibleDC = (CreateCompatibleDC_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", DeleteDC, "DeleteDC", extDDDeleteDC);
if(tmp) pGDIDeleteDC = (DeleteDC_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", CreateDCA, "CreateDCA", extDDCreateDC);
if(tmp) pGDICreateDC = (CreateDC_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", BitBlt, "BitBlt", extDDBitBlt);
if(tmp) pGDIBitBlt = (BitBlt_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", StretchBlt, "StretchBlt", extDDStretchBlt);
if(tmp) pGDIStretchBlt = (StretchBlt_Type)tmp;
}
else {
tmp = HookAPI(module, "GDI32.dll", CreateCompatibleDC, "CreateCompatibleDC", extGDICreateCompatibleDC);
if(tmp) pGDICreateCompatibleDC = (CreateCompatibleDC_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", DeleteDC, "DeleteDC", extGDIDeleteDC);
if(tmp) pGDIDeleteDC = (DeleteDC_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", CreateDCA, "CreateDCA", extGDICreateDC);
if(tmp) pGDICreateDC = (CreateDC_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", BitBlt, "BitBlt", extGDIBitBlt);
if(tmp) pGDIBitBlt = (BitBlt_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", StretchBlt, "StretchBlt", extGDIStretchBlt);
if(tmp) pGDIStretchBlt = (StretchBlt_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", PatBlt, "PatBlt", extGDIPatBlt);
if(tmp) pGDIPatBlt = (PatBlt_Type)tmp;
}
tmp = HookAPI(module, "GDI32.dll", GetDeviceCaps, "GetDeviceCaps", extGetDeviceCaps); // GHO: added for caesar3
if(tmp) pGDIGetDeviceCaps = (GetDeviceCaps_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", TextOutA, "TextOutA", extTextOutA);
if(tmp) pGDITextOutA = (TextOut_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", ScaleWindowExtEx, "ScaleWindowExtEx", extScaleWindowExtEx);
if(tmp) pGDIScaleWindowExtEx = (ScaleWindowExtEx_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", Rectangle, "Rectangle", extRectangle);
if(tmp) pGDIRectangle = (Rectangle_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", SaveDC, "SaveDC", extGDISaveDC);
if(tmp) pGDISaveDC = (SaveDC_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", RestoreDC, "RestoreDC", extGDIRestoreDC);
if(tmp) pGDIRestoreDC = (RestoreDC_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", CreatePalette, "CreatePalette", extGDICreatePalette);
if(tmp) pGDICreatePalette = (GDICreatePalette_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", SelectPalette, "SelectPalette", extSelectPalette);
if(tmp) pGDISelectPalette = (SelectPalette_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", RealizePalette, "RealizePalette", extRealizePalette);
if(tmp) pGDIRealizePalette = (RealizePalette_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", GetSystemPaletteEntries, "GetSystemPaletteEntries", extGetSystemPaletteEntries);
if(tmp) pGDIGetSystemPaletteEntries = (GetSystemPaletteEntries_Type)tmp;
if ((dxw.dwFlags1 & EMULATESURFACE) && (dxw.dwFlags1 & HANDLEDC)){
tmp = HookAPI(module, "GDI32.dll", SetTextColor, "SetTextColor", extSetTextColor);
if(tmp) pGDISetTextColor = (SetTextColor_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", SetBkColor, "SetBkColor", extSetBkColor);
if(tmp) pGDISetBkColor = (SetBkColor_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", CreateFont, "CreateFont", extCreateFont);
if(tmp) pGDICreateFont = (CreateFont_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", CreateFontIndirectA, "CreateFontIndirectA", extCreateFontIndirect);
if(tmp) pGDICreateFontIndirect = (CreateFontIndirect_Type)tmp;
}
if(dxw.dwFlags2 & DISABLEGAMMARAMP){
tmp = HookAPI(module, "GDI32.dll", SetDeviceGammaRamp, "SetDeviceGammaRamp", extSetDeviceGammaRamp);
if(tmp) pGDISetDeviceGammaRamp = (SetDeviceGammaRamp_Type)tmp;
tmp = HookAPI(module, "GDI32.dll", GetDeviceGammaRamp, "GetDeviceGammaRamp", extGetDeviceGammaRamp);
if(tmp) pGDIGetDeviceGammaRamp = (GetDeviceGammaRamp_Type)tmp;
}
HookKernel32Init();
HookUser32Init();
HookGDI32Init();
}
static void RecoverScreenMode()
@ -1184,6 +1201,13 @@ LONG WINAPI myUnhandledExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo)
}
}
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI extSetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
{
OutTraceD("SetUnhandledExceptionFilter: lpExceptionFilter=%x\n", lpTopLevelExceptionFilter);
extern LONG WINAPI myUnhandledExceptionFilter(LPEXCEPTION_POINTERS);
return (*pSetUnhandledExceptionFilter)(myUnhandledExceptionFilter);
}
void HookExceptionHandler(void)
{
void *tmp;
@ -1210,13 +1234,13 @@ void HookModule(HMODULE base, int dxversion)
{
HookKernel32(base);
HookUser32(base);
HookOle32(base);
HookWinMM(base);
//if(dxw.dwFlags2 & SUPPRESSIME) HookImeLib(module);
if(dxw.dwFlags2 & HOOKGDI) HookGDILib(base);
if(dxw.dwFlags2 & HOOKGDI) HookGDI32(base);
if(dxw.dwFlags1 & HOOKDI) HookDirectInput(base, dxversion);
HookDirectDraw(base, dxversion);
HookDirect3D(base, dxversion);
HookOle32(base);
if(dxw.dwFlags2 & HOOKOPENGL) HookOpenGLLibs(base, dxw.CustomOpenGLLib);
HookMSV4WLibs(base);
}
@ -1308,6 +1332,8 @@ int HookInit(TARGETMAP *target, HWND hwnd)
OutTrace("HookInit: dxw.hParentWnd style=%x(%s) exstyle=%x(%s)\n", dwStyle, ExplainStyle(dwStyle), dwExStyle, ExplainExStyle(dwExStyle));
}
HookSysLibsInit(); // this just once...
base=GetModuleHandle(NULL);
if(dxw.dwFlags3 & SINGLEPROCAFFINITY) SetSingleProcessAffinity();
if(dxw.dwFlags1 & HANDLEEXCEPTIONS) HookExceptionHandler();
@ -1324,8 +1350,6 @@ int HookInit(TARGETMAP *target, HWND hwnd)
target->minx, target->miny, target->maxx, target->maxy);
dxw.InitWindowPos(target->posx, target->posy, target->sizx, target->sizy);
HookSysLibsInit(); // this just once...
OutTraceB("HookInit: base hmodule=%x\n", base);
HookModule(base, dxw.dwTargetDDVersion);
if (dxw.dwFlags3 & HOOKDLLS) HookDlls(base);
@ -1361,23 +1385,6 @@ int HookInit(TARGETMAP *target, HWND hwnd)
return 0;
}
HWND WINAPI extGetDesktopWindow(void)
{
// V2.1.73: correct ???
HWND res;
OutTraceD("GetDesktopWindow: FullScreen=%x\n", dxw.IsFullScreen());
if (dxw.IsFullScreen()){
OutTraceD("GetDesktopWindow: returning main window hwnd=%x\n", dxw.GethWnd());
return dxw.GethWnd();
}
else{
res=(*pGetDesktopWindow)();
OutTraceD("GetDesktopWindow: returning desktop window hwnd=%x\n", res);
return res;
}
}
LPCSTR ProcToString(LPCSTR proc)
{
static char sBuf[24+1];
@ -1391,14 +1398,11 @@ LPCSTR ProcToString(LPCSTR proc)
FARPROC RemapLibrary(LPCSTR proc, HMODULE hModule, HookEntry_Type *Hooks)
{
int i;
HookEntry_Type *Hook;
for(i=0; Hooks[i].APIName; i++){
Hook=&Hooks[i];
if (!strcmp(proc,Hook->APIName)){
if (Hook->StoreAddress) *(Hook->StoreAddress)=(*pGetProcAddress)(hModule, proc);
OutTraceD("GetProcAddress: hooking proc=%s at addr=%x\n", ProcToString(proc), (Hook->StoreAddress) ? *(Hook->StoreAddress) : 0);
return Hook->HookerAddress;
for(; Hooks->APIName; Hooks++){
if (!strcmp(proc,Hooks->APIName)){
if (Hooks->StoreAddress) *(Hooks->StoreAddress)=(*pGetProcAddress)(hModule, proc);
OutTraceD("GetProcAddress: hooking proc=%s at addr=%x\n", ProcToString(proc), (Hooks->StoreAddress) ? *(Hooks->StoreAddress) : 0);
return Hooks->HookerAddress;
}
}
return NULL;
@ -1406,12 +1410,15 @@ FARPROC RemapLibrary(LPCSTR proc, HMODULE hModule, HookEntry_Type *Hooks)
void HookLibrary(HMODULE hModule, HookEntry_Type *Hooks, char *DLLName)
{
int i;
void *tmp;
HookEntry_Type *Hook;
for(i=0; Hooks[i].APIName; i++){
Hook=&Hooks[i];
tmp = HookAPI(hModule, DLLName, Hook->OriginalAddress, Hook->APIName, Hook->HookerAddress);
if(tmp) *(Hook->StoreAddress) = (FARPROC)tmp;
for(; Hooks->APIName; Hooks++){
tmp = HookAPI(hModule, DLLName, Hooks->OriginalAddress, Hooks->APIName, Hooks->HookerAddress);
if(tmp) *(Hooks->StoreAddress) = (FARPROC)tmp;
}
}
void HookLibInit(HookEntry_Type *Hooks)
{
for(; Hooks->APIName; Hooks++)
if (Hooks->StoreAddress) *(Hooks->StoreAddress) = Hooks->OriginalAddress;
}

View File

@ -2,6 +2,7 @@ extern int HookDirectDraw(HMODULE, int);
extern int HookDDProxy(HMODULE, int);
extern int HookDirect3D(HMODULE, int);
extern void HookOle32(HMODULE);
extern void HookGDI32(HMODULE);
extern int HookDirectInput(HMODULE, int);
extern void HookImeLib(HMODULE);
extern void HookKernel32(HMODULE);
@ -27,6 +28,7 @@ extern FARPROC Remap_ole32_ProcAddress(LPCSTR, HMODULE);
extern FARPROC Remap_trust_ProcAddress(LPCSTR, HMODULE);
extern FARPROC Remap_WinMM_ProcAddress(LPCSTR, HMODULE);
extern FARPROC Remap_ImeLib_ProcAddress(LPCSTR, HMODULE);
extern FARPROC Remap_vfw_ProcAddress(LPCSTR, HMODULE);
typedef struct {
char *APIName;
@ -37,3 +39,4 @@ typedef struct {
extern FARPROC RemapLibrary(LPCSTR, HMODULE, HookEntry_Type *);
extern void HookLibrary(HMODULE, HookEntry_Type *, char *);
extern void HookLibInit(HookEntry_Type *);

View File

@ -293,6 +293,21 @@ RECT dxwCore::MapWindowRect(LPRECT lpRect)
}
else {
RetRect=ClientRect;
if ((dxw.Coordinates == DXW_DESKTOP_WORKAREA) && (dwFlags2 & KEEPASPECTRATIO)){
int w, h, b; // width, height and border
w = RetRect.right - RetRect.left;
h = RetRect.bottom - RetRect.top;
if ((w * 600) > (h * 800)){
b = (w - (h * 800 / 600))/2;
RetRect.left = ClientRect.left + b;
RetRect.right = ClientRect.right - b;
}
else {
b = (h - (w * 600 / 800))/2;
RetRect.top = ClientRect.top + b;
RetRect.bottom = ClientRect.bottom - b;
}
}
}
if(!(*pClientToScreen)(hWnd, &UpLeft)){
OutTraceE("ClientToScreen ERROR: err=%d hwnd=%x at %d\n", GetLastError(), hWnd, __LINE__);
@ -748,13 +763,12 @@ void dxwCore::ShowBanner(HWND hwnd)
HBITMAP g_hbmBall;
RECT client;
JustOnce=TRUE;
hClientDC=GetDC(hwnd);
(*pGetClientRect)(hwnd, &client);
BitBlt(hClientDC, 0, 0, client.right, client.bottom, NULL, 0, 0, BLACKNESS);
if(JustOnce || (dwFlags2 & NOBANNER)) return;
JustOnce=TRUE;
g_hbmBall = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BANNER));
HDC hdcMem = CreateCompatibleDC(hClientDC);

Binary file not shown.

View File

@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "dxwnd.h"
#include "dxwcore.hpp"
#define VERSION "2.02.25"
#define VERSION "2.02.27"
LRESULT CALLBACK HookProc(int ncode, WPARAM wparam, LPARAM lparam);

Binary file not shown.

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Version="9.00"
Name="dxwnd"
ProjectGUID="{579E7FE7-2745-4100-A802-23511711FCDE}"
RootNamespace="dxwnd"
@ -216,6 +216,46 @@
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath=".\ddraw.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\dinput.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\dxdiaghook.cpp"
>
@ -248,18 +288,6 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\dxkernel32.cpp"
>
</File>
<File
RelativePath=".\dxole32.cpp"
>
</File>
<File
RelativePath=".\dxuser32.cpp"
>
</File>
<File
RelativePath=".\dxwcore.cpp"
>
@ -293,7 +321,7 @@
>
</File>
<File
RelativePath=".\glhook.cpp"
RelativePath=".\gdi32.cpp"
>
</File>
<File
@ -320,52 +348,24 @@
RelativePath=".\hddproxy.cpp"
>
</File>
<File
RelativePath="hddraw.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="hdinput.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\imelib.cpp"
>
</File>
<File
RelativePath=".\msvfwhook.cpp"
RelativePath=".\kernel32.cpp"
>
</File>
<File
RelativePath=".\msvfw.cpp"
>
</File>
<File
RelativePath=".\ole32.cpp"
>
</File>
<File
RelativePath=".\opengl.cpp"
>
</File>
<File
@ -373,7 +373,7 @@
>
</File>
<File
RelativePath=".\syslibs.cpp"
RelativePath=".\user32.cpp"
>
</File>
<File

845
dll/gdi32.cpp Normal file
View File

@ -0,0 +1,845 @@
#include "dxwnd.h"
#include "dxwcore.hpp"
#include "syslibs.h"
#include "hddraw.h"
#include "dxhook.h"
#include "dxhelper.h"
static HookEntry_Type Hooks[]={
{"GetDeviceCaps", (FARPROC)GetDeviceCaps, (FARPROC *)&pGDIGetDeviceCaps, (FARPROC)extGetDeviceCaps},
{"TextOutA", (FARPROC)TextOutA, (FARPROC *)&pGDITextOutA, (FARPROC)extTextOutA},
{"TabbedTextOutA", (FARPROC)TabbedTextOutA, (FARPROC *)&pTabbedTextOutA, (FARPROC)extTabbedTextOutA},
{"ScaleWindowExtEx", (FARPROC)ScaleWindowExtEx, (FARPROC *)&pGDIScaleWindowExtEx, (FARPROC)extScaleWindowExtEx},
{"Rectangle", (FARPROC)Rectangle, (FARPROC *)&pGDIRectangle, (FARPROC)extRectangle},
{"SaveDC", (FARPROC)SaveDC, (FARPROC *)&pGDISaveDC, (FARPROC)extGDISaveDC},
{"RestoreDC", (FARPROC)RestoreDC, (FARPROC *)&pGDIRestoreDC, (FARPROC)extGDIRestoreDC},
{"CreatePalette", (FARPROC)CreatePalette, (FARPROC *)&pGDICreatePalette, (FARPROC)extGDICreatePalette},
{"SelectPalette", (FARPROC)SelectPalette, (FARPROC *)&pGDISelectPalette, (FARPROC)extSelectPalette},
{"RealizePalette", (FARPROC)RealizePalette, (FARPROC *)&pGDIRealizePalette, (FARPROC)extRealizePalette},
{"GetSystemPaletteEntries", (FARPROC)GetSystemPaletteEntries, (FARPROC *)&pGDIGetSystemPaletteEntries, (FARPROC)extGetSystemPaletteEntries},
{0, NULL, 0, 0} // terminator
};
static HookEntry_Type DDHooks[]={
{"CreateCompatibleDC", (FARPROC)CreateCompatibleDC, (FARPROC *)&pGDICreateCompatibleDC, (FARPROC)extDDCreateCompatibleDC},
{"DeleteDC", (FARPROC)DeleteDC, (FARPROC *)&pGDIDeleteDC, (FARPROC)extDDDeleteDC},
{"CreateDCA", (FARPROC)CreateDCA, (FARPROC *)&pGDICreateDC, (FARPROC)extDDCreateDC},
{"BitBlt", (FARPROC)BitBlt, (FARPROC *)&pGDIBitBlt, (FARPROC)extDDBitBlt},
{"StretchBlt", (FARPROC)StretchBlt, (FARPROC *)&pGDIStretchBlt, (FARPROC)extDDStretchBlt},
// {"PatBlt", (FARPROC)PatBlt, (FARPROC *)&pGDIPatBlt, (FARPROC)extDDPatBlt}, // missing one ...
{0, NULL, 0, 0} // terminator
};
static HookEntry_Type GDIHooks[]={
{"CreateCompatibleDC", (FARPROC)CreateCompatibleDC, (FARPROC *)&pGDICreateCompatibleDC, (FARPROC)extGDICreateCompatibleDC},
{"DeleteDC", (FARPROC)DeleteDC, (FARPROC *)&pGDIDeleteDC, (FARPROC)extGDIDeleteDC},
{"CreateDCA", (FARPROC)CreateDCA, (FARPROC *)&pGDICreateDC, (FARPROC)extGDICreateDC},
{"BitBlt", (FARPROC)BitBlt, (FARPROC *)&pGDIBitBlt, (FARPROC)extGDIBitBlt},
{"StretchBlt", (FARPROC)StretchBlt, (FARPROC *)&pGDIStretchBlt, (FARPROC)extGDIStretchBlt},
{"PatBlt", (FARPROC)PatBlt, (FARPROC *)&pGDIPatBlt, (FARPROC)extGDIPatBlt},
{0, NULL, 0, 0} // terminator
};
static HookEntry_Type EmuHooks[]={
{"SetTextColor", (FARPROC)SetTextColor, (FARPROC *)&pGDISetTextColor, (FARPROC)extSetTextColor},
{"SetBkColor", (FARPROC)SetBkColor, (FARPROC *)&pGDISetBkColor, (FARPROC)extSetBkColor},
{"CreateFont", (FARPROC)CreateFont, (FARPROC *)&pGDICreateFont, (FARPROC)extCreateFont},
{"CreateFontIndirectA", (FARPROC)CreateFontIndirectA, (FARPROC *)&pGDICreateFontIndirect, (FARPROC)extCreateFontIndirect},
{0, NULL, 0, 0} // terminator
};
static HookEntry_Type GammaHooks[]={
{"SetDeviceGammaRamp", (FARPROC)SetDeviceGammaRamp, (FARPROC *)&pGDISetDeviceGammaRamp, (FARPROC)extSetDeviceGammaRamp},
{"GetDeviceGammaRamp", (FARPROC)GetDeviceGammaRamp, (FARPROC *)&pGDIGetDeviceGammaRamp, (FARPROC)extGetDeviceGammaRamp},
{0, NULL, 0, 0} // terminator
};
extern HRESULT WINAPI extDirectDrawCreate(GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *);
extern HRESULT WINAPI extDirectDrawCreateEx(GUID FAR *, LPDIRECTDRAW FAR *, REFIID, IUnknown FAR *);
static char *libname = "gdi32.dll";
void HookGDI32(HMODULE module)
{
HookLibrary(module, Hooks, libname);
if(dxw.dwFlags1 & MAPGDITOPRIMARY)
HookLibrary(module, DDHooks, libname);
else
HookLibrary(module, GDIHooks, libname);
if ((dxw.dwFlags1 & EMULATESURFACE) && (dxw.dwFlags1 & HANDLEDC))
HookLibrary(module, EmuHooks, libname);
if(dxw.dwFlags2 & DISABLEGAMMARAMP)
HookLibrary(module, GammaHooks, libname);
}
void HookGDI32Init()
{
HookLibInit(Hooks);
HookLibInit(DDHooks);
HookLibInit(EmuHooks);
HookLibInit(GammaHooks);
}
FARPROC Remap_GDI32_ProcAddress(LPCSTR proc, HMODULE hModule)
{
FARPROC addr;
if (addr=RemapLibrary(proc, hModule, Hooks)) return addr;
if(dxw.dwFlags1 & MAPGDITOPRIMARY)
if(addr=RemapLibrary(proc, hModule, DDHooks)) return addr;
else
if(addr=RemapLibrary(proc, hModule, GDIHooks)) return addr;
if ((dxw.dwFlags1 & EMULATESURFACE) && (dxw.dwFlags1 & HANDLEDC))
if(addr=RemapLibrary(proc, hModule, EmuHooks)) return addr;
if(dxw.dwFlags2 & DISABLEGAMMARAMP)
if(addr=RemapLibrary(proc, hModule, GammaHooks)) return addr;
return NULL;
}
//--------------------------------------------------------------------------------------------
//
// extern and common functions
//
//--------------------------------------------------------------------------------------------
extern DEVMODE *pSetDevMode;
extern DWORD PaletteEntries[256];
extern Unlock4_Type pUnlockMethod(LPDIRECTDRAWSURFACE);
extern HRESULT WINAPI sBlt(char *, LPDIRECTDRAWSURFACE, LPRECT, LPDIRECTDRAWSURFACE, LPRECT, DWORD, LPDDBLTFX, BOOL);
extern GetDC_Type pGetDC;
extern ReleaseDC_Type pReleaseDC;
static COLORREF GetMatchingColor(COLORREF crColor)
{
int iDistance, iMinDistance;
int iColorIndex, iMinColorIndex;
COLORREF PalColor;
iMinDistance=0xFFFFFF;
iMinColorIndex=0;
for(iColorIndex=0; iColorIndex<256; iColorIndex++){
int iDist;
iDistance=0;
PalColor=PaletteEntries[iColorIndex];
switch(dxw.ActualPixelFormat.dwRGBBitCount){
case 32:
PalColor = ((PalColor & 0x00FF0000) >> 16) | (PalColor & 0x0000FF00) | ((PalColor & 0x000000FF) << 16);
break;
case 16:
if(dxw.ActualPixelFormat.dwGBitMask==0x03E0){
// RGB555 screen settings
PalColor = ((PalColor & 0x7C00) >> 7) | ((PalColor & 0x03E0) << 6) | ((PalColor & 0x001F) << 19);
}
else {
// RGB565 screen settings
PalColor = ((PalColor & 0xF800) >> 8) | ((PalColor & 0x07E0) << 5) | ((PalColor & 0x001F) << 19);
}
break;
}
iDist = (crColor & 0x00FF0000) - (PalColor & 0x00FF0000);
iDist >>= 16;
if (iDist<0) iDist=-iDist;
iDist *= iDist;
iDistance += iDist;
iDist = (crColor & 0x0000FF00) - (PalColor & 0x0000FF00);
iDist >>= 8;
if (iDist<0) iDist=-iDist;
iDist *= iDist;
iDistance += iDist;
iDist = (crColor & 0x000000FF) - (PalColor & 0x000000FF);
// iDist >>= 0;
if (iDist<0) iDist=-iDist;
iDist *= iDist;
iDistance += iDist;
if (iDistance < iMinDistance) {
iMinDistance = iDistance;
iMinColorIndex = iColorIndex;
}
if (iMinDistance==0) break; // got the perfect match!
}
OutTraceD("GetMatchingColor: color=%x matched with palette[%d]=%x dist=%d\n",
crColor, iMinColorIndex, PaletteEntries[iMinColorIndex], iDistance);
PalColor=PaletteEntries[iMinColorIndex];
switch(dxw.ActualPixelFormat.dwRGBBitCount){
case 32:
crColor = ((PalColor & 0x00FF0000) >> 16) | (PalColor & 0x0000FF00) | ((PalColor & 0x000000FF) << 16);
break;
case 16:
if(dxw.ActualPixelFormat.dwGBitMask==0x03E0){
// RGB555 screen settings
crColor = ((PalColor & 0x7C00) >> 7) | ((PalColor & 0x03E0) << 6) | ((PalColor & 0x001F) << 19);
}
else {
// RGB565 screen settings
crColor = ((PalColor & 0xF800) >> 8) | ((PalColor & 0x07E0) << 5) | ((PalColor & 0x001F) << 19);
}
break;
}
return crColor;
}
//--------------------------------------------------------------------------------------------
//
// API hookers
//
//--------------------------------------------------------------------------------------------
int WINAPI extGetDeviceCaps(HDC hdc, int nindex)
{
DWORD res;
res = (*pGDIGetDeviceCaps)(hdc, nindex);
OutTraceD("GetDeviceCaps: hdc=%x index=%x(%s) res=%x\n",
hdc, nindex, ExplainDeviceCaps(nindex), res);
// if you have a bypassed setting, use it first!
if(pSetDevMode){
switch(nindex){
case BITSPIXEL:
case COLORRES:
res = pSetDevMode->dmBitsPerPel;
OutTraceD("GetDeviceCaps: fix BITSPIXEL/COLORRES cap=%x\n",res);
return res;
case HORZRES:
res = pSetDevMode->dmPelsWidth;
OutTraceD("GetDeviceCaps: fix HORZRES cap=%d\n", res);
return res;
case VERTRES:
res = pSetDevMode->dmPelsHeight;
OutTraceD("GetDeviceCaps: fix VERTRES cap=%d\n", res);
return res;
}
}
switch(nindex){
case VERTRES:
res= dxw.GetScreenHeight();
OutTraceD("GetDeviceCaps: fix VERTRES cap=%d\n", res);
break;
case HORZRES:
res= dxw.GetScreenWidth();
OutTraceD("GetDeviceCaps: fix HORZRES cap=%d\n", res);
break;
// WARNING: in no-emu mode, the INIT8BPP and INIT16BPP flags expose capabilities that
// are NOT implemented and may cause later troubles!
case RASTERCAPS:
if(dxw.dwFlags2 & INIT8BPP) {
res |= RC_PALETTE; // v2.02.12
OutTraceD("GetDeviceCaps: fix RASTERCAPS setting RC_PALETTE cap=%x\n",res);
}
break;
case BITSPIXEL:
case COLORRES:
if(dxw.dwFlags2 & INIT8BPP|INIT16BPP){
if(dxw.dwFlags2 & INIT8BPP) res = 8;
if(dxw.dwFlags2 & INIT16BPP) res = 16;
OutTraceD("GetDeviceCaps: fix BITSPIXEL/COLORRES cap=%d\n",res);
}
break;
}
if(dxw.dwFlags1 & EMULATESURFACE){
switch(nindex){
case RASTERCAPS:
if((dxw.VirtualPixelFormat.dwRGBBitCount==8) || (dxw.dwFlags2 & INIT8BPP)){
res = RC_PALETTE;
OutTraceD("GetDeviceCaps: fix RASTERCAPS setting RC_PALETTE cap=%x\n",res);
}
break;
case BITSPIXEL:
case COLORRES:
int PrevRes;
PrevRes=res;
if(dxw.VirtualPixelFormat.dwRGBBitCount!=0) res = dxw.VirtualPixelFormat.dwRGBBitCount;
if(dxw.dwFlags2 & INIT8BPP) res = 8;
if(dxw.dwFlags2 & INIT16BPP) res = 16;
if(PrevRes != res) OutTraceD("GetDeviceCaps: fix BITSPIXEL/COLORRES cap=%d\n",res);
break;
case SIZEPALETTE:
res = 256;
OutTraceD("GetDeviceCaps: fix SIZEPALETTE cap=%x\n",res);
break;
case NUMRESERVED:
res = 0;
OutTraceD("GetDeviceCaps: fix NUMRESERVED cap=%x\n",res);
break;
}
}
return res;
}
BOOL WINAPI extTextOutA(HDC hdc, int nXStart, int nYStart, LPCTSTR lpString, int cchString)
{
BOOL res;
OutTraceD("TextOut: hdc=%x xy=(%d,%d) str=(%d)\"%s\"\n", hdc, nXStart, nYStart, cchString, lpString);
if (dxw.dwFlags1 & FIXTEXTOUT) {
POINT anchor;
anchor.x=nXStart;
anchor.y=nYStart;
(*pClientToScreen)(dxw.GethWnd(), &anchor);
nXStart=anchor.x;
nYStart=anchor.y;
}
res=(*pGDITextOutA)(hdc, nXStart, nYStart, lpString, cchString);
return res;
}
LONG WINAPI extTabbedTextOutA(HDC hDC, int X, int Y, LPCTSTR lpString, int nCount, int nTabPositions, const LPINT lpnTabStopPositions, int nTabOrigin)
{
BOOL res;
OutTraceD("TabbedTextOut: hdc=%x xy=(%d,%d) nCount=%d nTP=%d nTOS=%d str=(%d)\"%s\"\n",
hDC, X, Y, nCount, nTabPositions, nTabOrigin, lpString);
if (dxw.dwFlags1 & FIXTEXTOUT) {
POINT anchor;
anchor.x=X;
anchor.y=Y;
(*pClientToScreen)(dxw.GethWnd(), &anchor);
X=anchor.x;
Y=anchor.y;
}
res=(*pTabbedTextOutA)(hDC, X, Y, lpString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin);
return res;
}
BOOL WINAPI extScaleWindowExtEx(HDC hdc, int Xnum, int Xdenom, int Ynum, int Ydenom, LPSIZE lpSize)
{
OutTraceD("ScaleWindowExtEx: hdc=%x num=(%d,%d) denom=(%d,%d) lpSize=%d\n",
hdc, Xnum, Ynum, Xdenom, Ydenom, lpSize);
if ((dxw.dwFlags1 & LOCKWINPOS) && dxw.IsFullScreen()) return 1;
return (*pGDIScaleWindowExtEx)(hdc, Xnum, Xdenom, Ynum, Ydenom, lpSize);
}
BOOL WINAPI extRectangle(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
{
OutTraceD("Rectangle: hdc=%x xy=(%d,%d)-(%d,%d)\n", hdc, nLeftRect, nTopRect, nRightRect, nBottomRect);
if (dxw.dwFlags1 & FIXTEXTOUT) {
POINT anchor;
anchor.x=nLeftRect;
anchor.y=nTopRect;
(*pClientToScreen)(dxw.GethWnd(), &anchor);
nLeftRect=anchor.x;
nTopRect=anchor.y;
anchor.x=nRightRect;
anchor.y=nBottomRect;
(*pClientToScreen)(dxw.GethWnd(), &anchor);
nRightRect=anchor.x;
nBottomRect=anchor.y;
}
return (*pGDIRectangle)(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect);
}
int WINAPI extGDISaveDC(HDC hdc)
{
int ret;
ret=(*pGDISaveDC)(hdc);
OutTraceD("GDI.SaveDC: hdc=%x ret=%x\n", hdc, ret);
//AutoRefreshThread=CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AutoRefresh, (LPVOID)hdc, 0, &dwThrdId);
return ret;
}
BOOL WINAPI extGDIRestoreDC(HDC hdc, int nSavedDC)
{
BOOL ret;
ret=(*pGDIRestoreDC)(hdc, nSavedDC);
OutTraceD("GDI.RestoreDC: hdc=%x nSavedDC=%x ret=%x\n", hdc, nSavedDC, ret);
//TerminateThread(AutoRefreshThread, 0);
return ret;
}
/* --------------------------------------------------------------------------- */
// v2.1.75: Hooking for GDI32 CreatePalette, SelectPalette, RealizePalette:
// maps the GDI palette to the buffered DirectDraw one. This fixes the screen
// output for "Dementia" (a.k.a. "Armed & Delirious").
HPALETTE WINAPI extGDICreatePalette(CONST LOGPALETTE *plpal)
{
HPALETTE ret;
int idx;
dxw.IsGDIPalette=TRUE;
OutTraceD("GDI.CreatePalette: plpal=%x version=%x NumEntries=%x\n", plpal, plpal->palVersion, plpal->palNumEntries);
ret=(*pGDICreatePalette)(plpal);
if(IsDebug){
OutTraceD("PalEntry[%x]= ", plpal->palNumEntries);
for(idx=0; idx<plpal->palNumEntries; idx++) OutTraceD("(%x)", plpal->palPalEntry[idx]);
OutTraceD("\n");
}
dxw.palVersion=plpal->palVersion;
dxw.palNumEntries=plpal->palNumEntries;
if(dxw.palNumEntries>256) dxw.palNumEntries=256;
for(idx=0; idx<dxw.palNumEntries; idx++) dxw.palPalEntry[idx]=plpal->palPalEntry[idx];
OutTraceD("GDI.CreatePalette: hPalette=%x\n", ret);
return ret;
}
HPALETTE WINAPI extSelectPalette(HDC hdc, HPALETTE hpal, BOOL bForceBackground)
{
HPALETTE ret;
ret=(*pGDISelectPalette)(hdc, hpal, bForceBackground);
OutTraceD("GDI.SelectPalette: hdc=%x hpal=%x ForceBackground=%x ret=%x\n", hdc, hpal, bForceBackground, ret);
return ret;
}
UINT WINAPI extRealizePalette(HDC hdc)
{
UINT ret;
extern void mySetPalette(int, int, LPPALETTEENTRY);
ret=(*pGDIRealizePalette)(hdc);
OutTraceD("GDI.RealizePalette: hdc=%x ret=%x\n", hdc, ret);
if(!dxw.IsGDIPalette) return ret;
// quick & dirty implementation through a nasty global:
// if the SelectPalette didn't force to the background (arg bForceBackground==FALSE)
// then don't override the current palette set by the DirectDrawPalette class.
// should be cleaned up a little....
// maybe not: now both Diablo & Dementia colors are working...
if(dxw.dwFlags1 & EMULATESURFACE)
mySetPalette(0, dxw.palNumEntries, dxw.palPalEntry);
// DEBUGGING
if(IsDebug){
int idx;
OutTraceD("PaletteEntries[%x]= ", dxw.palNumEntries);
for(idx=0; idx<dxw.palNumEntries; idx++) OutTraceD("(%x)", PaletteEntries[idx]);
OutTraceD("\n");
}
return ret;
}
// In emulated mode (when color depyth is 8BPP ?) it may happen that the game
// expects to get the requested system palette entries, while the 32BPP screen
// returns 0. "Mission Frce Cyberstorm" is one of these. Returning the same
// value as nEntries, even though lppe is untouched, fixes the problem.
UINT WINAPI extGetSystemPaletteEntries(HDC hdc, UINT iStartIndex, UINT nEntries, LPPALETTEENTRY lppe)
{
int ret;
OutTraceD("GetSystemPaletteEntries: hdc=%x start=%d num=%d\n", hdc, iStartIndex, nEntries);
ret=(*pGDIGetSystemPaletteEntries)(hdc, iStartIndex, nEntries, lppe);
OutTraceD("GetSystemPaletteEntries: ret=%d\n", ret);
if((ret == 0) && (dxw.dwFlags1 & EMULATESURFACE)) {
OutTraceD("GetSystemPaletteEntries: fixing ret=%d\n", nEntries);
ret = nEntries;
}
return ret;
}
/* -------------------------------------------------------------------- */
// directdraw supported GDI calls
/* -------------------------------------------------------------------- */
// PrimHDC: DC handle of the selected DirectDraw primary surface. NULL when invalid.
extern HDC PrimHDC;
HDC WINAPI extDDCreateCompatibleDC(HDC hdc)
{
HDC RetHdc, SrcHdc;
extern GetDC_Type pGetDC;
OutTraceD("GDI.CreateCompatibleDC: hdc=%x\n", hdc);
if(hdc==0 && pGetDC && dxw.IsFullScreen()){
dxw.SetPrimarySurface();
(*pGetDC)(dxw.lpDDSPrimHDC,&SrcHdc);
OutTraceD("GDI.CreateCompatibleDC: duplicating screen HDC lpDDSPrimHDC=%x\n", dxw.lpDDSPrimHDC);
RetHdc=(*pGDICreateCompatibleDC)(SrcHdc);
(*pReleaseDC)(dxw.lpDDSPrimHDC,SrcHdc);
}
else
RetHdc=(*pGDICreateCompatibleDC)(hdc);
if(RetHdc)
OutTraceD("GDI.CreateCompatibleDC: returning HDC=%x\n", RetHdc);
else
OutTraceE("GDI.CreateCompatibleDC ERROR: err=%d at %d\n", GetLastError(), __LINE__);
return RetHdc;
}
BOOL WINAPI extDDDeleteDC(HDC hdc)
{
BOOL res;
OutTraceD("GDI.DeleteDC: hdc=%x\n", hdc);
res=(*pGDIDeleteDC)(hdc);
if(!res) OutTraceE("GDI.DeleteDC: ERROR err=%d at %d\n", GetLastError(), __LINE__);
return res;
}
static HDC WINAPI winDDGetDC(HWND hwnd, char *api)
{
HDC hdc;
HRESULT res;
extern HRESULT WINAPI extGetDC(LPDIRECTDRAWSURFACE, HDC FAR *);
OutTraceD("%s: hwnd=%x\n", api, hwnd);
dxw.ResetPrimarySurface();
dxw.SetPrimarySurface();
if(dxw.IsDesktop(hwnd)) hwnd=dxw.GethWnd();
if(dxw.lpDDSPrimHDC){
if (PrimHDC){
OutTraceD("%s: reusing primary hdc\n", api);
(*pUnlockMethod(dxw.lpDDSPrimHDC))(dxw.lpDDSPrimHDC, NULL);
hdc=PrimHDC;
}
else{
OutTraceD("%s: get hdc from PRIMARY surface lpdds=%x\n", api, dxw.lpDDSPrimHDC);
res=extGetDC(dxw.lpDDSPrimHDC,&hdc);
if(res) {
OutTraceE("%s: GetDC(%x) ERROR %x(%s) at %d\n", api, dxw.lpDDSPrimHDC, res, ExplainDDError(res), __LINE__);
if(res==DDERR_DCALREADYCREATED){
// try recovery....
(*pReleaseDC)(dxw.lpDDSPrimHDC,NULL);
res=extGetDC(dxw.lpDDSPrimHDC,&hdc);
}
if(res)return 0;
}
PrimHDC=hdc;
}
}
else {
hdc=(*pGDIGetDC)(hwnd ? hwnd : dxw.GethWnd());
OutTraceD("%s: returning window DC handle hwnd=%x hdc=%x\n", api, hwnd, hdc);
PrimHDC=NULL;
}
if(hdc)
OutTraceD("%s: hwnd=%x hdc=%x\n", api, hwnd, hdc);
else
OutTraceE("%s: ERROR err=%d at %d\n", api, GetLastError, __LINE__);
return(hdc);
}
HDC WINAPI extDDCreateDC(LPSTR Driver, LPSTR Device, LPSTR Output, CONST DEVMODE *InitData)
{
HDC RetHDC;
OutTraceD("GDI.CreateDC: Driver=%s Device=%s Output=%s InitData=%x\n",
Driver?Driver:"(NULL)", Device?Device:"(NULL)", Output?Output:"(NULL)", InitData);
if (!Driver || !strncmp(Driver,"DISPLAY",7)) {
//HDC PrimHDC;
LPDIRECTDRAWSURFACE lpdds;
OutTraceD("GDI.CreateDC: returning primary surface DC\n");
lpdds=dxw.GetPrimarySurface();
(*pGetDC)(lpdds, &PrimHDC);
RetHDC=(*pGDICreateCompatibleDC)(PrimHDC);
(*pReleaseDC)(lpdds, PrimHDC);
}
else{
RetHDC=(*pGDICreateDC)(Driver, Device, Output, InitData);
}
if(RetHDC)
OutTraceD("GDI.CreateDC: returning HDC=%x\n", RetHDC);
else
OutTraceE("GDI.CreateDC ERROR: err=%d at %d\n", GetLastError(), __LINE__);
return RetHDC;
}
HDC WINAPI extDDGetDC(HWND hwnd)
{
HDC ret;
ret=winDDGetDC(hwnd, "GDI.GetDC");
return ret;
}
HDC WINAPI extDDGetWindowDC(HWND hwnd)
{
HDC ret;
ret=winDDGetDC(hwnd, "GDI.GetWindowDC");
return ret;
}
int WINAPI extDDReleaseDC(HWND hwnd, HDC hDC)
{
int res;
extern HRESULT WINAPI extReleaseDC(LPDIRECTDRAWSURFACE, HDC);
OutTraceD("GDI.ReleaseDC: hwnd=%x hdc=%x\n", hwnd, hDC);
res=0;
if ((hDC == PrimHDC) || (hwnd==0)){
dxw.SetPrimarySurface();
OutTraceD("GDI.ReleaseDC: refreshing primary surface lpdds=%x\n",dxw.lpDDSPrimHDC);
if(!dxw.lpDDSPrimHDC) return 0;
extReleaseDC(dxw.lpDDSPrimHDC, hDC);
PrimHDC=NULL;
res=1; // 1 = OK
}
else {
res=(*pGDIReleaseDC)(hwnd, hDC);
if (!res) OutTraceE("GDI.ReleaseDC: ERROR err=%d at %d\n", GetLastError(), __LINE__);
}
return(res);
}
BOOL WINAPI extDDBitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop)
{
BOOL ret;
HRESULT res;
extern HRESULT WINAPI extGetDC(LPDIRECTDRAWSURFACE, HDC FAR *);
OutTraceD("GDI.BitBlt: HDC=%x nXDest=%d nYDest=%d nWidth=%d nHeight=%d hdcSrc=%x nXSrc=%d nYSrc=%d dwRop=%x(%s)\n",
hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop, ExplainROP(dwRop));
ret=1; // OK
if(hdcDest==0) hdcDest=PrimHDC;
if(hdcDest==0) {
dxw.ResetPrimarySurface();
dxw.SetPrimarySurface();
res=extGetDC(dxw.lpDDSPrimHDC, &PrimHDC);
hdcDest=PrimHDC;
}
res=(*pGDIBitBlt)(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop);
if(!res) OutTraceE("GDI.BitBlt: ERROR err=%d at %d\n", GetLastError(), __LINE__);
res=(*pGDIBitBlt)(NULL, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop);
if(!res) ret=0;
return ret;
}
BOOL WINAPI extDDStretchBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
HDC hdcSrc, int nXSrc, int nYSrc, int nWSrc, int nHSrc, DWORD dwRop)
{
BOOL ret;
HRESULT res;
RECT ClientRect;
OutTraceD("GDI.StretchBlt: HDC=%x nXDest=%d nYDest=%d nWidth=%d nHeight=%d hdcSrc=%x nXSrc=%d nYSrc=%d nWSrc=%x nHSrc=%x dwRop=%x\n",
hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, nWSrc, nHSrc, dwRop);
if(hdcDest != hdcSrc){
(*pGetClientRect)(dxw.GethWnd(),&ClientRect);
ret=(*pGDIStretchBlt)(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, nWidth, nHeight, dwRop);
if(!ret) {
OutTraceE("GDI.StretchBlt: ERROR err=%d at %d\n", GetLastError(), __LINE__);
return ret;
}
}
dxw.SetPrimarySurface();
OutTraceD("GDI.StretchBlt: refreshing primary surface lpdds=%x\n",dxw.lpDDSPrimHDC);
sBlt("GDI.StretchBlt", dxw.lpDDSPrimHDC, NULL, dxw.lpDDSPrimHDC, NULL, 0, NULL, 0);
res=(*pUnlockMethod(dxw.lpDDSPrimHDC))(dxw.lpDDSPrimHDC, NULL);
return ret;
}
HDC WINAPI extGDICreateDC(LPSTR Driver, LPSTR Device, LPSTR Output, CONST DEVMODE *InitData)
{
HDC WinHDC, RetHDC;
OutTraceD("GDI.CreateDC: Driver=%s Device=%s Output=%s InitData=%x\n",
Driver?Driver:"(NULL)", Device?Device:"(NULL)", Output?Output:"(NULL)", InitData);
if (!Driver || !strncmp(Driver,"DISPLAY",7)) {
OutTraceD("GDI.CreateDC: returning window surface DC\n");
WinHDC=(*pGDIGetDC)(dxw.GethWnd());
RetHDC=(*pGDICreateCompatibleDC)(WinHDC);
(*pGDIReleaseDC)(dxw.GethWnd(), WinHDC);
}
else{
RetHDC=(*pGDICreateDC)(Driver, Device, Output, InitData);
}
if(RetHDC)
OutTraceD("GDI.CreateDC: returning HDC=%x\n", RetHDC);
else
OutTraceE("GDI.CreateDC ERROR: err=%d at %d\n", GetLastError(), __LINE__);
return RetHDC;
}
HDC WINAPI extGDICreateCompatibleDC(HDC hdc)
{
HDC RetHdc, SrcHdc;
extern LPDIRECTDRAWSURFACE lpDDSHDC;
extern GetDC_Type pGetDC;
DWORD LastError;
OutTraceD("GDI.CreateCompatibleDC: hdc=%x\n", hdc);
if(hdc==0){
SrcHdc=(*pGDIGetDC)(dxw.GethWnd());
OutTraceD("GDI.CreateCompatibleDC: duplicating win HDC hWnd=%x\n", dxw.GethWnd());
}
// eliminated error message for errorcode 0.
SetLastError(0);
RetHdc=(*pGDICreateCompatibleDC)(hdc);
LastError=GetLastError();
if(!LastError)
OutTraceD("GDI.CreateCompatibleDC: returning HDC=%x\n", RetHdc);
else
OutTraceE("GDI.CreateCompatibleDC ERROR: err=%d at %d\n", LastError, __LINE__);
return RetHdc;
}
BOOL WINAPI extGDIBitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop)
{
BOOL res;
extern BOOL isWithinDialog;
OutTraceD("GDI.BitBlt: HDC=%x nXDest=%d nYDest=%d nWidth=%d nHeight=%d hdcSrc=%x nXSrc=%d nYSrc=%d dwRop=%x(%s)\n",
hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop, ExplainROP(dwRop));
if (dxw.HandleFPS()) return TRUE;
// beware: HDC could refer to screen DC that are written directly on screen, or memory DC that will be scaled to
// the screen surface later on, on ReleaseDC or ddraw Blit / Flip operation. Scaling of rect coordinates is
// needed only in the first case, and must be avoided on the second, otherwise the image would be scaled twice!
if (dxw.IsFullScreen() && (OBJ_DC == GetObjectType(hdcDest))){
int nWDest, nHDest;
nWDest= nWidth;
nHDest= nHeight;
dxw.MapClient(&nXDest, &nYDest, &nWDest, &nHDest);
if (dxw.dwFlags2 & SHOWFPSOVERLAY) dxw.ShowFPS(hdcDest);
res=(*pGDIStretchBlt)(hdcDest, nXDest, nYDest, nWDest, nHDest, hdcSrc, nXSrc, nYSrc, nWidth, nHeight, dwRop);
}
else {
res=(*pGDIBitBlt)(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop);
}
if(!res) OutTraceE("GDI.BitBlt: ERROR err=%d at %d\n", GetLastError(), __LINE__);
return res;
}
BOOL WINAPI extGDIPatBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, DWORD dwRop)
{
BOOL res;
OutTraceD("GDI.PatBlt: HDC=%x nXDest=%d nYDest=%d nWidth=%d nHeight=%d dwRop=%x(%s)\n",
hdcDest, nXDest, nYDest, nWidth, nHeight, dwRop, ExplainROP(dwRop));
if (dxw.HandleFPS()) return TRUE;
if (dxw.IsFullScreen() && (OBJ_DC == GetObjectType(hdcDest))){
int nWDest, nHDest;
dxw.MapClient(&nXDest, &nYDest, &nWDest, &nHDest);
if (dxw.dwFlags2 & SHOWFPSOVERLAY) dxw.ShowFPS(hdcDest);
res=(*pGDIPatBlt)(hdcDest, nXDest, nYDest, nWDest, nHDest, dwRop);
}
else {
res=(*pGDIPatBlt)(hdcDest, nXDest, nYDest, nWidth, nHeight, dwRop);
}
if(!res) OutTraceE("GDI.PatBlt: ERROR err=%d at %d\n", GetLastError(), __LINE__);
return res;
}
BOOL WINAPI extGDIStretchBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
HDC hdcSrc, int nXSrc, int nYSrc, int nWSrc, int nHSrc, DWORD dwRop)
{
BOOL res;
OutTraceD("GDI.StretchBlt: HDC=%x nXDest=%d nYDest=%d nWidth=%d nHeight=%d hdcSrc=%x nXSrc=%d nYSrc=%d nWSrc=%d nHSrc=%d dwRop=%x(%s)\n",
hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, nWSrc, nHSrc, dwRop, ExplainROP(dwRop));
if (dxw.HandleFPS()) return TRUE;
// to do: what happend if StretchBlt is applied on screen DC ?
if (dxw.dwFlags2 & SHOWFPSOVERLAY) dxw.ShowFPS(hdcDest);
res=(*pGDIStretchBlt)(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, nWSrc, nHSrc, dwRop);
if(!res) OutTraceE("GDI.StretchBlt: ERROR err=%d at %d\n", GetLastError(), __LINE__);
return res;
}
BOOL WINAPI extGDIDeleteDC(HDC hdc)
{
BOOL res;
OutTraceD("GDI.DeleteDC: hdc=%x\n", hdc);
res=(*pGDIDeleteDC)(hdc);
if(!res) OutTraceE("GDI.DeleteDC: ERROR err=%d at %d\n", GetLastError(), __LINE__);
return res;
}
COLORREF WINAPI extSetTextColor(HDC hdc, COLORREF crColor)
{
COLORREF res;
if ((dxw.dwFlags1 & EMULATESURFACE) && (dxw.dwFlags1 & HANDLEDC) && (dxw.VirtualPixelFormat.dwRGBBitCount==8))
crColor=GetMatchingColor(crColor);
res=(*pGDISetTextColor)(hdc, crColor);
OutTraceD("SetTextColor: color=%x res=%x%s\n", crColor, res, (res==CLR_INVALID)?"(CLR_INVALID)":"");
return res;
}
COLORREF WINAPI extSetBkColor(HDC hdc, COLORREF crColor)
{
COLORREF res;
if ((dxw.dwFlags1 & EMULATESURFACE) && (dxw.dwFlags1 & HANDLEDC) && (dxw.VirtualPixelFormat.dwRGBBitCount==8))
crColor=GetMatchingColor(crColor);
res=(*pGDISetBkColor)(hdc, crColor);
OutTraceD("SetBkColor: color=%x res=%x%s\n", crColor, res, (res==CLR_INVALID)?"(CLR_INVALID)":"");
return res;
}
HFONT WINAPI extCreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight,
DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet,
DWORD fdwOutputPrecision, DWORD fdwClipPrecision, DWORD fdwQuality,
DWORD fdwPitchAndFamily, LPCTSTR lpszFace)
{
OutTraceD("CreateFont: h=%d w=%d face=\"%s\"\n", nHeight, nWidth, lpszFace);
return (*pGDICreateFont)(nHeight, nWidth, nEscapement, nOrientation, fnWeight,
fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet,
fdwOutputPrecision, fdwClipPrecision, NONANTIALIASED_QUALITY,
fdwPitchAndFamily, lpszFace);
}
// CreateFontIndirect hook routine to avoid font aliasing that prevents reverse blitting working on palettized surfaces
HFONT WINAPI extCreateFontIndirect(const LOGFONT* lplf)
{
LOGFONT lf;
HFONT retHFont;
OutTraceD("CreateFontIndirect: h=%d w=%d face=\"%s\"\n", lplf->lfHeight, lplf->lfWidth, lplf->lfFaceName);
memcpy((char *)&lf, (char *)lplf, sizeof(LOGFONT));
lf.lfQuality=NONANTIALIASED_QUALITY;
retHFont=((*pGDICreateFontIndirect)(&lf));
if(retHFont)
OutTraceD("CreateFontIndirect: hfont=%x\n", retHFont);
else
OutTraceD("CreateFontIndirect: error=%d at %d\n", GetLastError(), __LINE__);
return retHFont;
}
BOOL WINAPI extSetDeviceGammaRamp(HDC hDC, LPVOID lpRamp)
{
BOOL ret;
OutTraceD("SetDeviceGammaRamp: hdc=%x\n", hDC);
if(dxw.dwFlags2 & DISABLEGAMMARAMP) {
OutTraceD("SetDeviceGammaRamp: SUPPRESSED\n");
return TRUE;
}
ret=(*pGDISetDeviceGammaRamp)(hDC, lpRamp);
if(!ret) OutTraceE("SetDeviceGammaRamp: ERROR err=%d\n", GetLastError());
return ret;
}
BOOL WINAPI extGetDeviceGammaRamp(HDC hDC, LPVOID lpRamp)
{
BOOL ret;
OutTraceD("GetDeviceGammaRamp: hdc=%x\n", hDC);
ret=(*pGDIGetDeviceGammaRamp)(hDC, lpRamp);
if(!ret) OutTraceE("GetDeviceGammaRamp: ERROR err=%d\n", GetLastError());
return ret;
}

View File

@ -591,7 +591,7 @@ int HookDirectDraw(HMODULE module, int version)
FreeLibrary(hinst);
}
OutTraceD("HookDirectDraw version=%d\n", version); //GHO
OutTraceB("HookDirectDraw version=%d\n", version); //GHO
switch(version){
case 0: // automatic
tmp = HookAPI(module, "ddraw.dll", NULL, "DirectDrawCreate", extDirectDrawCreate);
@ -1735,7 +1735,7 @@ static char *FixSurfaceCaps(LPDDSURFACEDESC2 lpddsd)
if(((lpddsd->dwFlags & (DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT)) == (DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT)) &&
(lpddsd->ddsCaps.dwCaps & DDSCAPS_ZBUFFER)){
OutTraceB("FixSurfaceCaps: Experimental pixelformat for ZBUFFER case\n");
OutTraceB("FixSurfaceCaps: Experimental pixelformat for ZBUFFER case\n");
lpddsd->ddsCaps.dwCaps &= ~DDSCAPS_VIDEOMEMORY; // Evany
lpddsd->ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
return "ZBUFFER";

486
dll/kernel32.cpp Normal file
View File

@ -0,0 +1,486 @@
#include "dxwnd.h"
#include "dxwcore.hpp"
#include "syslibs.h"
#include "dxhook.h"
#include "dxhelper.h"
#include "hddraw.h"
#include "hddproxy.h"
static HookEntry_Type Hooks[]={
{"IsDebuggerPresent", (FARPROC)NULL, (FARPROC *)NULL, (FARPROC)extIsDebuggerPresent},
{"GetProcAddress", (FARPROC)GetProcAddress, (FARPROC *)&pGetProcAddress, (FARPROC)extGetProcAddress},
{"LoadLibraryA", (FARPROC)LoadLibraryA, (FARPROC *)&pLoadLibraryA, (FARPROC)extLoadLibraryA},
{"LoadLibraryExA", (FARPROC)LoadLibraryExA, (FARPROC *)&pLoadLibraryExA, (FARPROC)extLoadLibraryExA},
{"LoadLibraryW", (FARPROC)LoadLibraryW, (FARPROC *)&pLoadLibraryW, (FARPROC)extLoadLibraryW},
{"LoadLibraryExW", (FARPROC)LoadLibraryExW, (FARPROC *)&pLoadLibraryExW, (FARPROC)extLoadLibraryExW},
{0, NULL, 0, 0} // terminator
};
static HookEntry_Type LimitHooks[]={
{"GetDiskFreeSpaceA", (FARPROC)GetDiskFreeSpaceA, (FARPROC *)&pGetDiskFreeSpaceA, (FARPROC)extGetDiskFreeSpaceA},
{"GlobalMemoryStatus", (FARPROC)GlobalMemoryStatus, (FARPROC *)&pGlobalMemoryStatus, (FARPROC)extGlobalMemoryStatus},
{0, NULL, 0, 0} // terminator
};
static HookEntry_Type TimeHooks[]={
{"GetTickCount", (FARPROC)GetTickCount, (FARPROC *)&pGetTickCount, (FARPROC)extGetTickCount},
{"GetLocalTime", (FARPROC)GetLocalTime, (FARPROC *)&pGetLocalTime, (FARPROC)extGetLocalTime},
{"GetSystemTime", (FARPROC)GetSystemTime, (FARPROC *)&pGetSystemTime, (FARPROC)extGetSystemTime},
{"GetSystemTimeAsFileTime", (FARPROC)GetSystemTimeAsFileTime, (FARPROC *)&pGetSystemTimeAsFileTime, (FARPROC)extGetSystemTimeAsFileTime},
{"Sleep", (FARPROC)Sleep, (FARPROC *)&pSleep, (FARPROC)extSleep},
{"SleepEx", (FARPROC)SleepEx, (FARPROC *)&pSleepEx, (FARPROC)extSleepEx},
{"SetTimer", (FARPROC)SetTimer, (FARPROC *)&pSetTimer, (FARPROC)extSetTimer},
{0, NULL, 0, 0} // terminator
};
static HookEntry_Type VersionHooks[]={
{"GetVersion", (FARPROC)GetVersion, (FARPROC *)&pGetVersion, (FARPROC)extGetVersion},
{"GetVersionEx", (FARPROC)GetVersionEx, (FARPROC *)&pGetVersionEx, (FARPROC)extGetVersionEx},
{0, NULL, 0, 0} // terminator
};
static char *libname = "kernel32.dll";
void HookKernel32(HMODULE module)
{
HookLibrary(module, Hooks, libname);
if(dxw.dwFlags2 & LIMITRESOURCES) HookLibrary(module, LimitHooks, libname);
if(dxw.dwFlags2 & TIMESTRETCH) HookLibrary(module, TimeHooks, libname);
if(dxw.dwFlags2 & FAKEVERSION) HookLibrary(module, VersionHooks, libname);
}
void HookKernel32Init()
{
HookLibInit(Hooks);
HookLibInit(LimitHooks);
HookLibInit(TimeHooks);
HookLibInit(VersionHooks);
}
FARPROC Remap_kernel32_ProcAddress(LPCSTR proc, HMODULE hModule)
{
FARPROC addr;
if (addr=RemapLibrary(proc, hModule, Hooks)) return addr;
if(dxw.dwFlags2 & LIMITRESOURCES)
if (addr=RemapLibrary(proc, hModule, LimitHooks)) return addr;
if(dxw.dwFlags2 & TIMESTRETCH)
if (addr=RemapLibrary(proc, hModule, TimeHooks)) return addr;
if(dxw.dwFlags2 & FAKEVERSION)
if (addr=RemapLibrary(proc, hModule, VersionHooks)) return addr;
return NULL;
}
extern DirectDrawEnumerate_Type pDirectDrawEnumerate;
extern DirectDrawEnumerateEx_Type pDirectDrawEnumerateEx;
extern void HookModule(HMODULE, int);
int WINAPI extIsDebuggerPresent(void)
{
OutTraceD("extIsDebuggerPresent: return FALSE\n");
return FALSE;
}
BOOL WINAPI extGetDiskFreeSpaceA(LPCSTR lpRootPathName, LPDWORD lpSectorsPerCluster, LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters, LPDWORD lpTotalNumberOfClusters)
{
BOOL ret;
OutTraceD("GetDiskFreeSpace: RootPathName=\"%s\"\n", lpRootPathName);
ret=(*pGetDiskFreeSpaceA)(lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters);
if(!ret) OutTraceE("GetDiskFreeSpace: ERROR err=%d at %d\n", GetLastError(), __LINE__);
*lpNumberOfFreeClusters = 16000;
return ret;
}
/* -------------------------------------------------------------------------------
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;
}
}
/*
From MSDN:
Operating system Version number dwMajorVersion dwMinorVersion Other
Windows 8 6.2 6 2 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
Windows Server 2012 6.2 6 2 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
Windows 7 6.1 6 1 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
Windows Server 2008 R2 6.1 6 1 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
Windows Server 2008 6.0 6 0 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
Windows Vista 6.0 6 0 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
Windows Server 2003 R2 5.2 5 2 GetSystemMetrics(SM_SERVERR2) != 0
Windows Home Server 5.2 5 2 OSVERSIONINFOEX.wSuiteMask & VER_SUITE_WH_SERVER
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[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"},
{6, 0, "Windows Vista"},
{6, 1, "Windows 7"},
{6, 2, "Windows 8"}
};
BOOL WINAPI extGetVersionEx(LPOSVERSIONINFO lpVersionInfo)
{
BOOL ret;
ret=(*pGetVersionEx)(lpVersionInfo);
if(!ret) {
OutTraceE("GetVersionEx: ERROR err=%d\n", GetLastError());
return ret;
}
OutTraceD("GetVersionEx: version=%d.%d build=(%d)\n",
lpVersionInfo->dwMajorVersion, lpVersionInfo->dwMinorVersion, lpVersionInfo->dwBuildNumber);
if(dxw.dwFlags2 & FAKEVERSION) {
// fake Win XP build 0
lpVersionInfo->dwMajorVersion = WinVersions[dxw.FakeVersionId].bMajor;
lpVersionInfo->dwMinorVersion = WinVersions[dxw.FakeVersionId].bMinor;
lpVersionInfo->dwBuildNumber = 0;
OutTraceD("GetVersionEx: FIXED version=%d.%d build=(%d) os=\"%s\"\n",
lpVersionInfo->dwMajorVersion, lpVersionInfo->dwMinorVersion, lpVersionInfo->dwBuildNumber,
WinVersions[dxw.FakeVersionId].sName);
}
return TRUE;
}
DWORD WINAPI extGetVersion(void)
{
DWORD dwVersion;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuild = 0;
dwVersion = (*pGetVersion)();
// Get the Windows version.
dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
// Get the build number.
if (dwVersion < 0x80000000)
dwBuild = (DWORD)(HIWORD(dwVersion));
OutTraceD("GetVersion: version=%d.%d build=(%d)\n", dwMajorVersion, dwMinorVersion, dwBuild);
if(dxw.dwFlags2 & FAKEVERSION) {
dwVersion = WinVersions[dxw.FakeVersionId].bMajor | (WinVersions[dxw.FakeVersionId].bMinor << 8);
dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
dwBuild = (DWORD)(HIWORD(dwVersion));
OutTraceD("GetVersion: FIXED version=%d.%d build=(%d) os=\"%s\"\n",
dwMajorVersion, dwMinorVersion, dwBuild, WinVersions[dxw.FakeVersionId].sName);
}
return dwVersion;
}
/* -------------------------------------------------------------------------------
time related APIs
/* ---------------------------------------------------------------------------- */
DWORD WINAPI extGetTickCount(void)
{
return dxw.GetTickCount();
}
void WINAPI extGetSystemTime(LPSYSTEMTIME lpSystemTime)
{
dxw.GetSystemTime(lpSystemTime);
if (IsDebug) OutTrace("GetSystemTime: %02d:%02d:%02d.%03d\n",
lpSystemTime->wHour, lpSystemTime->wMinute, lpSystemTime->wSecond, lpSystemTime->wMilliseconds);
}
void WINAPI extGetLocalTime(LPSYSTEMTIME lpLocalTime)
{
SYSTEMTIME SystemTime;
dxw.GetSystemTime(&SystemTime);
SystemTimeToTzSpecificLocalTime(NULL, &SystemTime, lpLocalTime);
if (IsDebug) OutTrace("GetLocalTime: %02d:%02d:%02d.%03d\n",
lpLocalTime->wHour, lpLocalTime->wMinute, lpLocalTime->wSecond, lpLocalTime->wMilliseconds);
}
UINT_PTR WINAPI extSetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc)
{
UINT uShiftedElapse;
// beware: the quicker the time flows, the more the time clicks are incremented,
// and the lesser the pauses must be lasting! Shift operations are reverted in
// GetSystemTime vs. Sleep or SetTimer
uShiftedElapse = dxw.StretchTime(uElapse);
if (IsDebug) OutTrace("SetTimer: elapse=%d->%d timeshift=%d\n", uElapse, uShiftedElapse, dxw.TimeShift);
return (*pSetTimer)(hWnd, nIDEvent, uShiftedElapse, lpTimerFunc);
}
VOID WINAPI extSleep(DWORD dwMilliseconds)
{
DWORD dwNewDelay;
dwNewDelay=dwMilliseconds;
if (dwMilliseconds!=INFINITE && dwMilliseconds!=0){
dwNewDelay = dxw.StretchTime(dwMilliseconds);
if (dwNewDelay==0){ // oh oh! troubles...
if (dxw.TimeShift > 0) dwNewDelay=1; // minimum allowed...
else dwNewDelay = INFINITE-1; // maximum allowed !!!
}
}
if (IsDebug) OutTrace("Sleep: msec=%d->%d timeshift=%d\n", dwMilliseconds, dwNewDelay, dxw.TimeShift);
(*pSleep)(dwNewDelay);
}
DWORD WINAPI extSleepEx(DWORD dwMilliseconds, BOOL bAlertable)
{
DWORD dwNewDelay;
dwNewDelay=dwMilliseconds;
if (dwMilliseconds!=INFINITE && dwMilliseconds!=0){
dwNewDelay = dxw.StretchTime(dwMilliseconds);
if (dwNewDelay==0){ // oh oh! troubles...
if (dxw.TimeShift > 0) dwNewDelay=1; // minimum allowed...
else dwNewDelay = INFINITE-1; // maximum allowed !!!
}
}
if (IsDebug) OutTrace("SleepEx: msec=%d->%d alertable=%x, timeshift=%d\n", dwMilliseconds, dwNewDelay, bAlertable, dxw.TimeShift);
return (*pSleepEx)(dwNewDelay, bAlertable);
}
void WINAPI extGetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
{
if (IsDebug) OutTrace("GetSystemTimeAsFileTime\n");
dxw.GetSystemTimeAsFileTime(lpSystemTimeAsFileTime);
}
HMODULE SysLibs[SYSLIBIDX_MAX];
HMODULE WINAPI LoadLibraryExWrapper(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags, char *api)
{
HMODULE libhandle;
int idx;
//if(!strcmp(lpFileName, "d3d9.dll") && GetModuleHandle(lpFileName)) return GetModuleHandle(lpFileName); // attempt to avoid loading same dll twice....
libhandle=(*pLoadLibraryExA)(lpFileName, hFile, dwFlags);
OutTraceD("%s: FileName=%s hFile=%x Flags=%x(%s) hmodule=%x\n", api, lpFileName, hFile, dwFlags, ExplainLoadLibFlags(dwFlags), libhandle);
if(!libhandle){
OutTraceE("%s: ERROR FileName=%s err=%d\n", api, lpFileName, GetLastError());
return libhandle;
}
// when loaded with LOAD_LIBRARY_AS_DATAFILE or LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE flags,
// there's no symbol map, then itìs no possible to hook function calls.
if(dwFlags & (LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE|LOAD_LIBRARY_AS_DATAFILE)) return libhandle;
idx=dxw.GetDLLIndex((char *)lpFileName);
if(idx != -1) SysLibs[idx]=libhandle;
// handle custom OpenGL library
if(!lstrcmpi(lpFileName,dxw.CustomOpenGLLib)){
idx=SYSLIBIDX_OPENGL;
SysLibs[idx]=libhandle;
}
if (idx == -1) HookModule(libhandle, 0);
return libhandle;
}
HMODULE WINAPI extLoadLibraryA(LPCTSTR lpFileName)
{
return LoadLibraryExWrapper(lpFileName, NULL, 0, "LoadLibraryA");
}
HMODULE WINAPI extLoadLibraryW(LPCWSTR lpFileName)
{
char sFileName[256+1];
wcstombs_s(NULL, sFileName, lpFileName, 80);
return LoadLibraryExWrapper(sFileName, NULL, 0, "LoadLibraryW");;
}
HMODULE WINAPI extLoadLibraryExA(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags)
{
return LoadLibraryExWrapper(lpFileName, hFile, dwFlags, "LoadLibraryExA");
}
HMODULE WINAPI extLoadLibraryExW(LPCWSTR lpFileName, HANDLE hFile, DWORD dwFlags)
{
char sFileName[256+1];
wcstombs_s(NULL, sFileName, lpFileName, 80);
return LoadLibraryExWrapper(sFileName, hFile, dwFlags, "LoadLibraryExW");;
}
extern DirectDrawCreate_Type pDirectDrawCreate;
extern DirectDrawCreateEx_Type pDirectDrawCreateEx;
extern HRESULT WINAPI extDirectDrawCreate(GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *);
extern HRESULT WINAPI extDirectDrawCreateEx(GUID FAR *, LPDIRECTDRAW FAR *, REFIID, IUnknown FAR *);
extern GetProcAddress_Type pGetProcAddress;
//extern HRESULT STDAPICALLTYPE extCoCreateInstance(REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID FAR*);
FARPROC WINAPI extGetProcAddress(HMODULE hModule, LPCSTR proc)
{
FARPROC ret;
int idx;
// WARNING: seems to be called with bad LPCSTR value....
// from MSDN:
// The function or variable name, or the function's ordinal value.
// If this parameter is an ordinal value, it must be in the low-order word;
// the high-order word must be zero.
OutTraceD("GetProcAddress: hModule=%x proc=%s\n", hModule, ProcToString(proc));
for(idx=0; idx<SYSLIBIDX_MAX; idx++){
if(SysLibs[idx]==hModule) break;
}
// to do: the else condition: the program COULD load addresses by ordinal value ... done ??
// to do: CoCreateInstanceEx
if((DWORD)proc & 0xFFFF0000){
FARPROC remap;
switch(idx){
case SYSLIBIDX_DIRECTDRAW:
if (remap=Remap_ddraw_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_USER32:
if (remap=Remap_user32_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_KERNEL32:
if (remap=Remap_kernel32_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_IMELIB:
if (remap=Remap_ImeLib_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_WINMM:
if (remap=Remap_WinMM_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_OLE32:
if (remap=Remap_ole32_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_DIRECT3D8:
if (remap=Remap_d3d8_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_DIRECT3D9:
if (remap=Remap_d3d9_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_DIRECT3D10:
if (remap=Remap_d3d10_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_DIRECT3D10_1:
if (remap=Remap_d3d10_1_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_DIRECT2D11:
if (remap=Remap_d3d11_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_OPENGL:
if (remap=Remap_gl_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_MSVFW:
if (remap=Remap_vfw_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_SMACK:
if (remap=Remap_smack_ProcAddress(proc, hModule)) return remap;
break;
case SYSLIBIDX_WINTRUST:
if (remap=Remap_trust_ProcAddress(proc, hModule)) return remap;
break;
default:
break;
}
}
else {
switch(idx){
case SYSLIBIDX_DIRECTDRAW:
switch((DWORD)proc){
case 0x0008: // DirectDrawCreate
pDirectDrawCreate=(DirectDrawCreate_Type)(*pGetProcAddress)(hModule, proc);
OutTraceD("GetProcAddress: hooking proc=%s at addr=%x\n", ProcToString(proc), pDirectDrawCreate);
return (FARPROC)extDirectDrawCreate;
break;
case 0x000A: // DirectDrawCreateEx
pDirectDrawCreateEx=(DirectDrawCreateEx_Type)(*pGetProcAddress)(hModule, proc);
OutTraceD("GetProcAddress: hooking proc=%s at addr=%x\n", ProcToString(proc), pDirectDrawCreateEx);
return (FARPROC)extDirectDrawCreateEx;
break;
case 0x000B: // DirectDrawEnumerateA
pDirectDrawEnumerate=(DirectDrawEnumerate_Type)(*pGetProcAddress)(hModule, proc);
OutTraceP("GetProcAddress: hooking proc=%s at addr=%x\n", proc, pDirectDrawEnumerate);
return (FARPROC)extDirectDrawEnumerateProxy;
break;
case 0x000C: // DirectDrawEnumerateExA
pDirectDrawEnumerateEx=(DirectDrawEnumerateEx_Type)(*pGetProcAddress)(hModule, proc);
OutTraceP("GetProcAddress: hooking proc=%s at addr=%x\n", proc, pDirectDrawEnumerateEx);
return (FARPROC)extDirectDrawEnumerateExProxy;
break;
}
break;
case SYSLIBIDX_USER32:
if ((DWORD)proc == 0x0020){ // ChangeDisplaySettingsA
pChangeDisplaySettings=(ChangeDisplaySettings_Type)(*pGetProcAddress)(hModule, proc);
OutTraceD("GetProcAddress: hooking proc=%s at addr=%x\n", ProcToString(proc), pChangeDisplaySettings);
return (FARPROC)extChangeDisplaySettings;
}
break;
#ifndef ANTICHEATING
case SYSLIBIDX_KERNEL32:
if ((DWORD)proc == 0x022D){ // "IsDebuggerPresent"
OutTraceD("GetProcAddress: hooking proc=%s at addr=%x\n", ProcToString(proc), extIsDebuggerPresent);
return (FARPROC)extIsDebuggerPresent;
}
#endif
case SYSLIBIDX_OLE32:
if ((DWORD)proc == 0x0011){ // "CoCreateInstance"
pCoCreateInstance=(CoCreateInstance_Type)(*pGetProcAddress)(hModule, proc);
OutTraceD("GetProcAddress: hooking proc=%s at addr=%x\n", ProcToString(proc), pCoCreateInstance);
return (FARPROC)extCoCreateInstance;
}
break;
}
}
ret=(*pGetProcAddress)(hModule, proc);
OutTraceD("GetProcAddress: ret=%x\n", ret);
return ret;
}

97
dll/ole32.cpp Normal file
View File

@ -0,0 +1,97 @@
#include <dxdiag.h>
#include "dxwnd.h"
#include "dxwcore.hpp"
#include "syslibs.h"
#include "dxhook.h"
#include "dxhelper.h"
static HookEntry_Type Hooks[]={
{"CoCreateInstance", NULL, (FARPROC *)&pCoCreateInstance, (FARPROC)extCoCreateInstance},
// {"CoCreateInstanceEx", NULL, (FARPROC *)&pCoCreateInstanceEx, (FARPROC)extCoCreateInstanceEx}, remote object creation....
{0, NULL, 0, 0} // terminator
};
extern HRESULT WINAPI extDirectDrawCreate(GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *);
extern HRESULT WINAPI extDirectDrawCreateEx(GUID FAR *, LPDIRECTDRAW FAR *, REFIID, IUnknown FAR *);
void HookOle32(HMODULE module)
{
HookLibrary(module, Hooks, "ole32.dll");
}
FARPROC Remap_ole32_ProcAddress(LPCSTR proc, HMODULE hModule)
{
FARPROC addr;
if (addr=RemapLibrary(proc, hModule, Hooks)) return addr;
return NULL;
}
// -------------------------------------------------------------------------------------
// Ole32 CoCreateInstance handling: you can create DirectDraw objects through it!
// utilized so far in a single game: Axiz & Allies
// -------------------------------------------------------------------------------------
static void HookDDSession(LPDIRECTDRAW *, int);
HRESULT STDAPICALLTYPE extCoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID FAR* ppv)
{
HRESULT res;
OutTraceD("CoCreateInstance: rclsid=%x UnkOuter=%x ClsContext=%x refiid=%x\n",
rclsid, pUnkOuter, dwClsContext, riid);
// CLSID e436ebb3 implies loading quartz.dll to play movies through dshow:
// quartz.dll must be hooked.
if (*(DWORD *)&rclsid==0xe436ebb3){
HMODULE qlib;
OutTraceD("CoCreateInstance: CLSID_FilterGraph RIID=%x\n", *(DWORD *)&riid);
qlib=(*pLoadLibraryA)("quartz.dll");
OutTraceD("CoCreateInstance: quartz lib handle=%x\n", qlib);
HookKernel32(qlib);
HookUser32(qlib);
HookWinMM(qlib);
}
res=(*pCoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv);
if(res)
OutTraceE("CoCreateInstance: ERROR res=%x\n", res);
else
OutTraceD("CoCreateInstance: ppv=%x->%x\n", *ppv, *(DWORD *)*ppv);
if (*(DWORD *)&rclsid==*(DWORD *)&CLSID_DirectDraw){
LPDIRECTDRAW lpOldDDraw;
OutTraceD("CoCreateInstance: CLSID_DirectDraw object\n");
switch (*(DWORD *)&riid){
case 0x6C14DB80:
OutTraceD("DirectDrawCreate: IID_DirectDraw RIID\n");
res=extDirectDrawCreate(NULL, (LPDIRECTDRAW *)&ppv, 0);
if(res)OutTraceD("DirectDrawCreate: res=%x(%s)\n", res, ExplainDDError(res));
break;
case 0xB3A6F3E0:
OutTraceD("DirectDrawCreate: IID_DirectDraw2 RIID\n");
res=extDirectDrawCreate(NULL, &lpOldDDraw, 0);
if(res)OutTraceD("DirectDrawCreate: res=%x(%s)\n", res, ExplainDDError(res));
res=lpOldDDraw->QueryInterface(IID_IDirectDraw2, (LPVOID *)&ppv);
if(res)OutTraceD("QueryInterface: res=%x(%s)\n", res, ExplainDDError(res));
lpOldDDraw->Release();
break;
case 0x9c59509a:
OutTraceD("DirectDrawCreate: IID_DirectDraw4 RIID\n");
res=extDirectDrawCreate(NULL, &lpOldDDraw, 0);
if(res)OutTraceD("DirectDrawCreate: res=%x(%s)\n", res, ExplainDDError(res));
res=lpOldDDraw->QueryInterface(IID_IDirectDraw4, (LPVOID *)&ppv);
if(res)OutTraceD("QueryInterface: res=%x(%s)\n", res, ExplainDDError(res));
lpOldDDraw->Release();
case 0x15e65ec0:
OutTraceD("CoCreateInstance: IID_DirectDraw7 RIID\n");
res=extDirectDrawCreateEx(NULL, (LPDIRECTDRAW *)&ppv, IID_IDirectDraw7, 0);
if(res)OutTraceD("DirectDrawCreateEx: res=%x(%s)\n", res, ExplainDDError(res));
break;
case 0xe436ebb3:
break;
}
}
else
if (*(DWORD *)&rclsid==*(DWORD *)&CLSID_DxDiagProvider) res=HookDxDiag(riid, ppv);
return res;
}

View File

@ -2,7 +2,6 @@
// Microsoft Visual C++ generated include file.
// Used by dxwnd.rc
//
#define IDB_BITMAP1 101
#define IDB_BANNER 101
// Next default values for new objects

View File

@ -45,6 +45,7 @@ typedef COLORREF (WINAPI *SetBkColor_Type)(HDC, COLORREF);
typedef BOOL (WINAPI *SetDeviceGammaRamp_Type)(HDC, LPVOID);
typedef COLORREF(WINAPI *SetTextColor_Type)(HDC, COLORREF);
typedef BOOL (WINAPI *StretchBlt_Type)(HDC, int, int, int, int, HDC, int, int, int, int, DWORD);
typedef LONG (WINAPI *TabbedTextOutA_Type)(HDC, int, int, LPCTSTR, int, int, const LPINT, int);
typedef BOOL (WINAPI *TextOut_Type)(HDC, int, int, LPCTSTR, int);
// Kernel32.dll:
@ -159,6 +160,7 @@ DXWEXTERN SetBkColor_Type pGDISetBkColor DXWINITIALIZED;
DXWEXTERN SetDeviceGammaRamp_Type pGDISetDeviceGammaRamp DXWINITIALIZED;
DXWEXTERN SetTextColor_Type pGDISetTextColor DXWINITIALIZED;
DXWEXTERN StretchBlt_Type pGDIStretchBlt DXWINITIALIZED;
DXWEXTERN TabbedTextOutA_Type pTabbedTextOutA DXWINITIALIZED;
DXWEXTERN TextOut_Type pGDITextOutA DXWINITIALIZED;
// Kernel32.dll:
@ -266,6 +268,7 @@ extern BOOL WINAPI extSetDeviceGammaRamp(HDC, LPVOID);
extern COLORREF WINAPI extSetTextColor(HDC, COLORREF);
extern BOOL WINAPI extGDIStretchBlt(HDC, int, int, int, int, HDC, int, int, int, int, DWORD);
extern BOOL WINAPI extDDStretchBlt(HDC, int, int, int, int, HDC, int, int, int, int, DWORD);
extern LONG WINAPI extTabbedTextOutA(HDC, int, int, LPCTSTR, int, int, const LPINT, int);
extern BOOL WINAPI extTextOutA(HDC, int, int, LPCTSTR, int);
// Kernel32.dll:
@ -337,4 +340,10 @@ extern BOOL WINAPI extShowWindow(HWND, int);
// Winmm.dll:
extern DWORD WINAPI exttimeGetTime(void);
// extern function declaration
extern void HookKernel32Init();
extern void HookUser32Init();
extern void HookGDI32Init();
/* eof */

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ typedef struct {
WNDPROC wndproc;
} wndstack_entry;
#define MAXWNDHSTACK 80
#define MAXWNDHSTACK 256
wndstack_entry WhndStack[MAXWNDHSTACK];
static int WhndTOS = 0;
@ -37,7 +37,12 @@ void WhndStackPush(HWND hwnd, WNDPROC wndproc)
return;
}
// push if not already there.
if(WhndTOS>=MAXWNDHSTACK) return;
if(WhndTOS>=MAXWNDHSTACK) {
char sMsg[80];
sprintf(sMsg, "Table overflow: %d entries used", MAXWNDHSTACK);
MessageBox(0, sMsg, "WhndStackPush", MB_OK | MB_ICONEXCLAMATION);
return;
}
WhndStack[WhndTOS].hwnd=hwnd;
WhndStack[WhndTOS].wndproc=wndproc;
WhndTOS++;

View File

@ -22,19 +22,31 @@ CTabLogs::CTabLogs(CWnd* pParent /*=NULL*/)
//}}AFX_DATA_INIT
}
BOOL CTabLogs::OnInitDialog()
{
extern BOOL gbDebug;
CDialog::OnInitDialog();
(CButton *)(this->GetDlgItem(IDC_DXPROXED))->EnableWindow(gbDebug ? TRUE : FALSE);
(CButton *)(this->GetDlgItem(IDC_ASSERT))->EnableWindow(gbDebug ? TRUE : FALSE);
return TRUE;
}
void CTabLogs::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
CTargetDlg *cTarget = ((CTargetDlg *)(this->GetParent()->GetParent()));
extern BOOL gbDebug;
DDX_Check(pDX, IDC_OUTTRACE, cTarget->m_OutTrace);
DDX_Check(pDX, IDC_OUTDEBUG, cTarget->m_OutDebug);
DDX_Check(pDX, IDC_CURSORTRACE, cTarget->m_CursorTrace);
DDX_Check(pDX, IDC_LOGENABLED, cTarget->m_LogEnabled);
DDX_Check(pDX, IDC_OUTWINMESSAGES, cTarget->m_OutWinMessages);
DDX_Check(pDX, IDC_OUTDXTRACE, cTarget->m_OutDXTrace);
DDX_Check(pDX, IDC_DXPROXED, cTarget->m_DXProxed);
DDX_Check(pDX, IDC_ASSERT, cTarget->m_AssertDialog);
DDX_Check(pDX, IDC_IMPORTTABLE, cTarget->m_ImportTable);
if(gbDebug){
DDX_Check(pDX, IDC_DXPROXED, cTarget->m_DXProxed);
DDX_Check(pDX, IDC_ASSERT, cTarget->m_AssertDialog);
}
}
BEGIN_MESSAGE_MAP(CTabLogs, CDialog)

View File

@ -16,6 +16,7 @@ class CTabLogs : public CDialog
// Construction
public:
CTabLogs(CWnd* pParent = NULL); // standard constructor
virtual BOOL OnInitDialog();
// Dialog Data
//{{AFX_DATA(CTabLogs)

View File

@ -34,6 +34,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_HOOKDLLS, cTarget->m_HookDLLs);
DDX_Check(pDX, IDC_HOOKCHILDWIN, cTarget->m_HookChildWin);
DDX_Check(pDX, IDC_HOOKENABLED, cTarget->m_HookEnabled);
DDX_Check(pDX, IDC_NOBANNER, cTarget->m_NoBanner);
DDX_Check(pDX, IDC_STARTDEBUG, cTarget->m_StartDebug);
@ -73,7 +74,7 @@ void CTabProgram::OnBnClickedCoordinates()
{
// TODO: Add your control notification handler code here
//CWnd *cTarget = ((CTargetDlg *)(this->GetParent());
//(CEdBoxEditor *)(cTarget->GetDlgItem(IDC_POSX))
//(CButton*)(cTarget->GetDlgItem(IDC_POSX))
}
void CTabProgram::OnBnClickedDesktopworkarea()

View File

@ -38,7 +38,6 @@ void CTabWindow::DoDataExchange(CDataExchange* pDX)
DDX_Check(pDX, IDC_FORCEWINRESIZE, cTarget->m_ForceWinResize);
DDX_Check(pDX, IDC_HIDEMULTIMONITOR, cTarget->m_HideMultiMonitor);
DDX_Check(pDX, IDC_WALLPAPERMODE, cTarget->m_WallpaperMode);
DDX_Check(pDX, IDC_HOOKCHILDWIN, cTarget->m_HookChildWin);
DDX_Check(pDX, IDC_RECOVERSCREENMODE, cTarget->m_RecoverScreenMode);
DDX_Check(pDX, IDC_REFRESHONRESIZE, cTarget->m_RefreshOnResize);
DDX_Check(pDX, IDC_FIXD3DFRAME, cTarget->m_FixD3DFrame);

28
host/dxwnd.ini Normal file
View File

@ -0,0 +1,28 @@
[window]
posx=1104
posy=310
sizx=303
sizy=138
[target]
title0=speeddemo.exe
path0=D:\Games\Need For Speed Underground Demo\speeddemo.exe
module0=
opengllib0=
ver0=0
flag0=0
flagg0=134217728
flagh0=-842150435
flagi0=-842150451
tflag0=0
initx0=0
inity0=0
minx0=0
miny0=0
maxx0=0
maxy0=0
posx0=0
posy0=0
sizx0=800
sizy0=600
maxfps0=0
initts0=0

Binary file not shown.

View File

@ -35,6 +35,7 @@ END_MESSAGE_MAP()
// too do: eliminate nasty global variables....
UINT m_StartToTray = FALSE;
UINT m_InitialState = DXW_ACTIVE;
BOOL gbDebug = FALSE;
extern char m_ConfigFileName[20+1] = "dxwnd.ini";
class CNewCommandLineInfo : public CCommandLineInfo
@ -58,6 +59,10 @@ void CNewCommandLineInfo::ParseParam(LPCTSTR lpszParam, BOOL bFlag, BOOL bLast)
m_InitialState=DXW_IDLE;
return;
}
if (sParam.MakeLower() == "debug"){
gbDebug = TRUE;
return;
}
if (sParam.Left(2).MakeLower() == "c:"){
strcpy_s(m_ConfigFileName, sizeof(m_ConfigFileName)-1, sParam.Mid(2,sizeof(m_ConfigFileName)-1));
return;

View File

@ -272,22 +272,24 @@ BEGIN
CONTROL "X,Y coordinates",IDC_COORDINATES,"Button",BS_AUTORADIOBUTTON | WS_GROUP,170,198,95,10
CONTROL "Desktop work area",IDC_DESKTOPWORKAREA,"Button",BS_AUTORADIOBUTTON,170,208,95,10
CONTROL "Desktop center",IDC_DESKTOPCENTER,"Button",BS_AUTORADIOBUTTON,170,218,95,10
CONTROL "Hook child WindowProc",IDC_HOOKCHILDWIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,142,124,10
END
IDD_TAB_LOG DIALOGEX 0, 0, 300, 240
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
GROUPBOX "Logs",IDC_STATIC,7,3,87,133
CONTROL "Win Events",IDC_OUTWINMESSAGES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,69,73,12
CONTROL "DirectX ",IDC_OUTDXTRACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,81,73,12
CONTROL "DxWnd",IDC_OUTTRACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,58,73,12
CONTROL "Assert Dialog",IDC_ASSERT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,47,73,12
CONTROL "ddraw Proxy",IDC_DXPROXED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,35,73,12
CONTROL "Cursor/Mouse",IDC_CURSORTRACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,93,73,12
CONTROL "Import Table",IDC_IMPORTTABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,104,73,12
CONTROL "Debug",IDC_OUTDEBUG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,116,73,12
CONTROL "Enable Trace",IDC_LOGENABLED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,13,73,12
GROUPBOX "dxwnd.log logs",IDC_STATIC,7,3,129,131
CONTROL "Win Events",IDC_OUTWINMESSAGES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,70,73,12
CONTROL "DirectX trace",IDC_OUTDXTRACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,58,73,12
CONTROL "DxWnd",IDC_OUTTRACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,46,73,12
CONTROL "Assert Dialog",IDC_ASSERT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,152,73,12
CONTROL "ddraw Proxy",IDC_DXPROXED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,164,73,12
CONTROL "Cursor/Mouse",IDC_CURSORTRACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,82,73,12
CONTROL "Import Table",IDC_IMPORTTABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,94,73,12
CONTROL "Debug",IDC_OUTDEBUG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,106,73,12
CONTROL "Enable Trace",IDC_LOGENABLED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,25,73,12
GROUPBOX "debug mode only",IDC_STATIC,7,139,130,94
END
IDD_TAB_DIRECTX DIALOGEX 0, 0, 300, 240
@ -381,17 +383,16 @@ BEGIN
CONTROL "Prevent Win Maximize",IDC_PREVENTMAXIMIZE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,28,115,10
GROUPBOX "Windows handling",IDC_STATIC,6,4,140,229
CONTROL "Lock win coordinates",IDC_LOCKWINPOS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,40,115,10
CONTROL "Hook CHILD windows",IDC_HOOKCHILDWIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,64,115,10
CONTROL "Recover screen mode",IDC_RECOVERSCREENMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,76,115,10
CONTROL "Refresh on win resize",IDC_REFRESHONRESIZE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,88,115,10
CONTROL "Recover screen mode",IDC_RECOVERSCREENMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,64,115,10
CONTROL "Refresh on win resize",IDC_REFRESHONRESIZE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,76,115,10
CONTROL "Lock win style",IDC_LOCKWINSTYLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,52,115,10
CONTROL "Fix Parent Window",IDC_FIXPARENTWIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,100,115,10
CONTROL "Modal Style",IDC_MODALSTYLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,112,115,10
CONTROL "Keep aspect ratio",IDC_KEEPASPECTRATIO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,124,115,10
CONTROL "Force win resize",IDC_FORCEWINRESIZE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,136,115,10
CONTROL "Hide multi-monitor config.",IDC_HIDEMULTIMONITOR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,148,115,10
CONTROL "Wallpaper mode",IDC_WALLPAPERMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,160,115,10
CONTROL "Fix Windows Frame in D3D",IDC_FIXD3DFRAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,172,115,10
CONTROL "Fix Parent Window",IDC_FIXPARENTWIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,88,115,10
CONTROL "Modal Style",IDC_MODALSTYLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,100,115,10
CONTROL "Keep aspect ratio",IDC_KEEPASPECTRATIO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,112,115,10
CONTROL "Force win resize",IDC_FORCEWINRESIZE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,124,115,10
CONTROL "Hide multi-monitor config.",IDC_HIDEMULTIMONITOR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,136,115,10
CONTROL "Wallpaper mode",IDC_WALLPAPERMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,148,115,10
CONTROL "Fix Windows Frame in D3D",IDC_FIXD3DFRAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,160,115,10
END
IDD_TAB_EMPTY DIALOGEX 0, 0, 300, 240

Binary file not shown.

View File

@ -95,6 +95,235 @@ static void RevertScreenChanges(DEVMODE *InitDevMode)
}
}
static void SetTargetFromDlg(TARGETMAP *t, CTargetDlg *dlg)
{
strcpy_s(t->path, sizeof(t->path), dlg->m_FilePath);
strcpy_s(t->module, sizeof(t->module), dlg->m_Module);
strcpy_s(t->OpenGLLib, sizeof(t->OpenGLLib), dlg->m_OpenGLLib);
if(dlg->m_DXVersion > 1) dlg->m_DXVersion += 5;
t->dxversion = dlg->m_DXVersion;
t->coordinates = dlg->m_Coordinates;
t->flags = 0;
t->flags2 = 0;
t->flags3 = 0;
t->flags4 = 0;
t->tflags = 0;
if(dlg->m_UnNotify) t->flags |= UNNOTIFY;
if(dlg->m_Windowize) t->flags2 |= WINDOWIZE;
if(dlg->m_HookDLLs) t->flags3 |= HOOKDLLS;
if(dlg->m_HookEnabled) t->flags3 |= HOOKENABLED;
if(dlg->m_NoBanner) t->flags2 |= NOBANNER;
if(dlg->m_StartDebug) t->flags2 |= STARTDEBUG;
if(dlg->m_NoEmulateSurface) {
dlg->m_EmulateSurface = FALSE;
dlg->m_EmulateBuffer = FALSE;
t->flags &= ~EMULATEFLAGS;
}
if(dlg->m_EmulateSurface) {
dlg->m_NoEmulateSurface = FALSE;
dlg->m_EmulateBuffer = FALSE;
t->flags &= ~EMULATEFLAGS;
t->flags |= EMULATESURFACE;
}
if(dlg->m_EmulateBuffer) {
dlg->m_NoEmulateSurface = FALSE;
dlg->m_EmulateSurface = FALSE;
t->flags &= ~EMULATEFLAGS;
t->flags |= EMULATEBUFFER;
}
if(dlg->m_HookDI) t->flags |= HOOKDI;
if(dlg->m_ModifyMouse) t->flags |= MODIFYMOUSE;
if(dlg->m_OutTrace) t->tflags |= OUTDDRAWTRACE;
if(dlg->m_OutDebug) t->tflags |= OUTDEBUG;
if(dlg->m_CursorTrace) t->tflags |= OUTCURSORTRACE;
if(dlg->m_LogEnabled) t->tflags |= OUTTRACE;
if(dlg->m_OutWinMessages) t->tflags |= OUTWINMESSAGES;
if(dlg->m_OutDXTrace) t->tflags |= OUTPROXYTRACE;
if(dlg->m_DXProxed) t->tflags |= DXPROXED;
if(dlg->m_AssertDialog) t->tflags |= ASSERTDIALOG;
if(dlg->m_ImportTable) t->tflags |= OUTIMPORTTABLE;
if(dlg->m_HandleDC) t->flags |= HANDLEDC;
if(dlg->m_HandleExceptions) t->flags |= HANDLEEXCEPTIONS;
if(dlg->m_LimitResources) t->flags2 |= LIMITRESOURCES;
if(dlg->m_SuppressIME) t->flags2 |= SUPPRESSIME;
if(dlg->m_SuppressD3DExt) t->flags3 |= SUPPRESSD3DEXT;
if(dlg->m_SetCompatibility) t->flags2 |= SETCOMPATIBILITY;
if(dlg->m_SaveCaps) t->flags3 |= SAVECAPS;
if(dlg->m_SingleProcAffinity) t->flags3 |= SINGLEPROCAFFINITY;
if(dlg->m_SaveLoad) t->flags |= SAVELOAD;
if(dlg->m_SlowDown) t->flags |= SLOWDOWN;
if(dlg->m_BlitFromBackBuffer) t->flags |= BLITFROMBACKBUFFER;
if(dlg->m_SuppressClipping) t->flags |= SUPPRESSCLIPPING;
if(dlg->m_DisableGammaRamp) t->flags2 |= DISABLEGAMMARAMP;
if(dlg->m_AutoRefresh) t->flags |= AUTOREFRESH;
if(dlg->m_FixWinFrame) t->flags |= FIXWINFRAME;
if(dlg->m_HideHwCursor) t->flags |= HIDEHWCURSOR;
if(dlg->m_ShowHwCursor) t->flags2 |= SHOWHWCURSOR;
if(dlg->m_EnableClipping) t->flags |= ENABLECLIPPING;
if(dlg->m_CursorClipping) t->flags |= CLIPCURSOR;
if(dlg->m_VideoToSystemMem) t->flags |= SWITCHVIDEOMEMORY;
if(dlg->m_FixTextOut) t->flags |= FIXTEXTOUT;
if(dlg->m_KeepCursorWithin) t->flags |= KEEPCURSORWITHIN;
if(dlg->m_KeepCursorFixed) t->flags2 |= KEEPCURSORFIXED;
if(dlg->m_UseRGB565) t->flags |= USERGB565;
if(dlg->m_SuppressDXErrors) t->flags |= SUPPRESSDXERRORS;
if(dlg->m_MarkBlit) t->flags3 |= MARKBLIT;
if(dlg->m_PreventMaximize) t->flags |= PREVENTMAXIMIZE;
if(dlg->m_ClientRemapping) t->flags |= CLIENTREMAPPING;
if(dlg->m_MapGDIToPrimary) t->flags |= MAPGDITOPRIMARY;
if(dlg->m_LockWinPos) t->flags |= LOCKWINPOS;
if(dlg->m_LockWinStyle) t->flags |= LOCKWINSTYLE;
if(dlg->m_FixParentWin) t->flags |= FIXPARENTWIN;
if(dlg->m_ModalStyle) t->flags2 |= MODALSTYLE;
if(dlg->m_KeepAspectRatio) t->flags2 |= KEEPASPECTRATIO;
if(dlg->m_ForceWinResize) t->flags2 |= FORCEWINRESIZE;
if(dlg->m_HookGDI) t->flags2 |= HOOKGDI;
if(dlg->m_HideMultiMonitor) t->flags2 |= HIDEMULTIMONITOR;
if(dlg->m_WallpaperMode) t->flags2 |= WALLPAPERMODE;
if(dlg->m_FixD3DFrame) t->flags3 |= FIXD3DFRAME;
if(dlg->m_Force16BPP) t->flags3 |= FORCE16BPP;
if(dlg->m_HookChildWin) t->flags |= HOOKCHILDWIN;
if(dlg->m_MessageProc) t->flags |= MESSAGEPROC;
if(dlg->m_FixNCHITTEST) t->flags2 |= FIXNCHITTEST;
if(dlg->m_RecoverScreenMode) t->flags2 |= RECOVERSCREENMODE;
if(dlg->m_RefreshOnResize) t->flags2 |= REFRESHONRESIZE;
if(dlg->m_Init8BPP) t->flags2 |= INIT8BPP;
if(dlg->m_Init16BPP) t->flags2 |= INIT16BPP;
if(dlg->m_BackBufAttach) t->flags2 |= BACKBUFATTACH;
if(dlg->m_HandleAltF4) t->flags |= HANDLEALTF4;
if(dlg->m_LimitFPS) t->flags2 |= LIMITFPS;
if(dlg->m_SkipFPS) t->flags2 |= SKIPFPS;
if(dlg->m_ShowFPS) t->flags2 |= SHOWFPS;
if(dlg->m_ShowFPSOverlay) t->flags2 |= SHOWFPSOVERLAY;
if(dlg->m_TimeStretch) t->flags2 |= TIMESTRETCH;
if(dlg->m_HookOpenGL) t->flags2 |= HOOKOPENGL;
if(dlg->m_ForceHookOpenGL) t->flags3 |= FORCEHOOKOPENGL;
if(dlg->m_WireFrame) t->flags2 |= WIREFRAME;
if(dlg->m_BlackWhite) t->flags3 |= BLACKWHITE;
if(dlg->m_FakeVersion) t->flags2 |= FAKEVERSION;
if(dlg->m_FullRectBlt) t->flags2 |= FULLRECTBLT;
if(dlg->m_NoPaletteUpdate) t->flags2 |= NOPALETTEUPDATE;
t->initx = dlg->m_InitX;
t->inity = dlg->m_InitY;
t->minx = dlg->m_MinX;
t->miny = dlg->m_MinY;
t->maxx = dlg->m_MaxX;
t->maxy = dlg->m_MaxY;
t->posx = dlg->m_PosX;
t->posy = dlg->m_PosY;
t->sizx = dlg->m_SizX;
t->sizy = dlg->m_SizY;
t->MaxFPS = dlg->m_MaxFPS;
t->InitTS = dlg->m_InitTS-8;
t->FakeVersionId = dlg->m_FakeVersionId;
strcpy_s(t->module, sizeof(t->module), dlg->m_Module);
strcpy_s(t->OpenGLLib, sizeof(t->OpenGLLib), dlg->m_OpenGLLib);
}
static void SetDlgFromTarget(TARGETMAP *t, CTargetDlg *dlg)
{
dlg->m_DXVersion = t->dxversion;
if(dlg->m_DXVersion > 6) dlg->m_DXVersion -= 5;
dlg->m_Coordinates = t->coordinates;
dlg->m_FilePath = t->path;
dlg->m_Module = t->module;
dlg->m_OpenGLLib = t->OpenGLLib;
dlg->m_UnNotify = t->flags & UNNOTIFY ? 1 : 0;
dlg->m_Windowize = t->flags2 & WINDOWIZE ? 1 : 0;
dlg->m_HookDLLs = t->flags3 & HOOKDLLS ? 1 : 0;
dlg->m_HookEnabled = t->flags3 & HOOKENABLED ? 1 : 0;
dlg->m_NoBanner = t->flags2 & NOBANNER ? 1 : 0;
dlg->m_StartDebug = t->flags2 & STARTDEBUG ? 1 : 0;
dlg->m_EmulateSurface = t->flags & EMULATESURFACE ? 1 : 0;
dlg->m_NoEmulateSurface = t->flags & EMULATEFLAGS ? 0 : 1;
dlg->m_EmulateBuffer = t->flags & EMULATEBUFFER ? 1 : 0;
dlg->m_HookDI = t->flags & HOOKDI ? 1 : 0;
dlg->m_ModifyMouse = t->flags & MODIFYMOUSE ? 1 : 0;
dlg->m_OutTrace = t->tflags & OUTDDRAWTRACE ? 1 : 0;
dlg->m_OutDebug = t->tflags & OUTDEBUG ? 1 : 0;
dlg->m_CursorTrace = t->tflags & OUTCURSORTRACE ? 1 : 0;
dlg->m_LogEnabled = t->tflags & OUTTRACE ? 1 : 0;
dlg->m_OutWinMessages = t->tflags & OUTWINMESSAGES ? 1 : 0;
dlg->m_OutDXTrace = t->tflags & OUTPROXYTRACE ? 1 : 0;
dlg->m_DXProxed = t->tflags & DXPROXED ? 1 : 0;
dlg->m_AssertDialog = t->tflags & ASSERTDIALOG ? 1 : 0;
dlg->m_ImportTable = t->tflags & OUTIMPORTTABLE ? 1 : 0;
dlg->m_HandleDC = t->flags & HANDLEDC ? 1 : 0;
dlg->m_HandleExceptions = t->flags & HANDLEEXCEPTIONS ? 1 : 0;
dlg->m_SuppressIME = t->flags2 & SUPPRESSIME ? 1 : 0;
dlg->m_SuppressD3DExt = t->flags3 & SUPPRESSD3DEXT ? 1 : 0;
dlg->m_SetCompatibility = t->flags2 & SETCOMPATIBILITY ? 1 : 0;
dlg->m_SaveCaps = t->flags3 & SAVECAPS ? 1 : 0;
dlg->m_SingleProcAffinity = t->flags3 & SINGLEPROCAFFINITY ? 1 : 0;
dlg->m_LimitResources = t->flags2 & LIMITRESOURCES ? 1 : 0;
dlg->m_SaveLoad = t->flags & SAVELOAD ? 1 : 0;
dlg->m_SlowDown = t->flags & SLOWDOWN ? 1 : 0;
dlg->m_BlitFromBackBuffer = t->flags & BLITFROMBACKBUFFER ? 1 : 0;
dlg->m_SuppressClipping = t->flags & SUPPRESSCLIPPING ? 1 : 0;
dlg->m_DisableGammaRamp = t->flags2 & DISABLEGAMMARAMP ? 1 : 0;
dlg->m_AutoRefresh = t->flags & AUTOREFRESH ? 1 : 0;
dlg->m_FixWinFrame = t->flags & FIXWINFRAME ? 1 : 0;
dlg->m_HideHwCursor = t->flags & HIDEHWCURSOR ? 1 : 0;
dlg->m_ShowHwCursor = t->flags2 & SHOWHWCURSOR ? 1 : 0;
dlg->m_EnableClipping = t->flags & ENABLECLIPPING ? 1 : 0;
dlg->m_CursorClipping = t->flags & CLIPCURSOR ? 1 : 0;
dlg->m_VideoToSystemMem = t->flags & SWITCHVIDEOMEMORY ? 1 : 0;
dlg->m_FixTextOut = t->flags & FIXTEXTOUT ? 1 : 0;
dlg->m_KeepCursorWithin = t->flags & KEEPCURSORWITHIN ? 1 : 0;
dlg->m_KeepCursorFixed = t->flags2 & KEEPCURSORFIXED ? 1 : 0;
dlg->m_UseRGB565 = t->flags & USERGB565 ? 1 : 0;
dlg->m_SuppressDXErrors = t->flags & SUPPRESSDXERRORS ? 1 : 0;
dlg->m_MarkBlit = t->flags3 & MARKBLIT ? 1 : 0;
dlg->m_PreventMaximize = t->flags & PREVENTMAXIMIZE ? 1 : 0;
dlg->m_ClientRemapping = t->flags & CLIENTREMAPPING ? 1 : 0;
dlg->m_MapGDIToPrimary = t->flags & MAPGDITOPRIMARY ? 1 : 0;
dlg->m_LockWinPos = t->flags & LOCKWINPOS ? 1 : 0;
dlg->m_LockWinStyle = t->flags & LOCKWINSTYLE ? 1 : 0;
dlg->m_FixParentWin = t->flags & FIXPARENTWIN ? 1 : 0;
dlg->m_ModalStyle = t->flags2 & MODALSTYLE ? 1 : 0;
dlg->m_KeepAspectRatio = t->flags2 & KEEPASPECTRATIO ? 1 : 0;
dlg->m_ForceWinResize = t->flags2 & FORCEWINRESIZE ? 1 : 0;
dlg->m_HookGDI = t->flags2 & HOOKGDI ? 1 : 0;
dlg->m_HideMultiMonitor = t->flags2 & HIDEMULTIMONITOR ? 1 : 0;
dlg->m_WallpaperMode = t->flags2 & WALLPAPERMODE ? 1 : 0;
dlg->m_FixD3DFrame = t->flags3 & FIXD3DFRAME ? 1 : 0;
dlg->m_Force16BPP = t->flags3 & FORCE16BPP ? 1 : 0;
dlg->m_HookChildWin = t->flags & HOOKCHILDWIN ? 1 : 0;
dlg->m_MessageProc = t->flags & MESSAGEPROC ? 1 : 0;
dlg->m_FixNCHITTEST = t->flags2 & FIXNCHITTEST ? 1 : 0;
dlg->m_RecoverScreenMode = t->flags2 & RECOVERSCREENMODE ? 1 : 0;
dlg->m_RefreshOnResize = t->flags2 & REFRESHONRESIZE ? 1 : 0;
dlg->m_Init8BPP = t->flags2 & INIT8BPP ? 1 : 0;
dlg->m_Init16BPP = t->flags2 & INIT16BPP ? 1 : 0;
dlg->m_BackBufAttach = t->flags2 & BACKBUFATTACH ? 1 : 0;
dlg->m_HandleAltF4 = t->flags & HANDLEALTF4 ? 1 : 0;
dlg->m_LimitFPS = t->flags2 & LIMITFPS ? 1 : 0;
dlg->m_SkipFPS = t->flags2 & SKIPFPS ? 1 : 0;
dlg->m_ShowFPS = t->flags2 & SHOWFPS ? 1 : 0;
dlg->m_ShowFPSOverlay = t->flags2 & SHOWFPSOVERLAY ? 1 : 0;
dlg->m_TimeStretch = t->flags2 & TIMESTRETCH ? 1 : 0;
dlg->m_HookOpenGL = t->flags2 & HOOKOPENGL ? 1 : 0;
dlg->m_ForceHookOpenGL = t->flags3 & FORCEHOOKOPENGL ? 1 : 0;
dlg->m_WireFrame = t->flags2 & WIREFRAME ? 1 : 0;
dlg->m_BlackWhite = t->flags3 & BLACKWHITE ? 1 : 0;
dlg->m_FakeVersion = t->flags2 & FAKEVERSION ? 1 : 0;
dlg->m_FullRectBlt = t->flags2 & FULLRECTBLT ? 1 : 0;
dlg->m_NoPaletteUpdate = t->flags2 & NOPALETTEUPDATE ? 1 : 0;
dlg->m_InitX = t->initx;
dlg->m_InitY = t->inity;
dlg->m_MinX = t->minx;
dlg->m_MinY = t->miny;
dlg->m_MaxX = t->maxx;
dlg->m_MaxY = t->maxy;
dlg->m_PosX = t->posx;
dlg->m_PosY = t->posy;
dlg->m_SizX = t->sizx;
dlg->m_SizY = t->sizy;
dlg->m_MaxFPS = t->MaxFPS;
dlg->m_InitTS = t->InitTS+8;
dlg->m_FakeVersionId = t->FakeVersionId;
}
static void SaveConfigItem(TARGETMAP *TargetMap, char *Title, int i, char *InitPath)
{
char key[32], val[32];
@ -494,231 +723,11 @@ void CDxwndhostView::OnModify()
if(!listctrl.GetSelectedCount()) return;
pos = listctrl.GetFirstSelectedItemPosition();
i = listctrl.GetNextSelectedItem(pos);
dlg.m_DXVersion = TargetMaps[i].dxversion;
if(dlg.m_DXVersion > 6) dlg.m_DXVersion -= 5;
dlg.m_Coordinates = TargetMaps[i].coordinates;
dlg.m_FilePath = TargetMaps[i].path;
dlg.m_Module = TargetMaps[i].module;
dlg.m_OpenGLLib = TargetMaps[i].OpenGLLib;
dlg.m_Title = TitleMaps[i].title;
dlg.m_UnNotify = TargetMaps[i].flags & UNNOTIFY ? 1 : 0;
dlg.m_Windowize = TargetMaps[i].flags2 & WINDOWIZE ? 1 : 0;
dlg.m_HookDLLs = TargetMaps[i].flags3 & HOOKDLLS ? 1 : 0;
dlg.m_HookEnabled = TargetMaps[i].flags3 & HOOKENABLED ? 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;
dlg.m_HookDI = TargetMaps[i].flags & HOOKDI ? 1 : 0;
dlg.m_ModifyMouse = TargetMaps[i].flags & MODIFYMOUSE ? 1 : 0;
dlg.m_OutTrace = TargetMaps[i].tflags & OUTDDRAWTRACE ? 1 : 0;
dlg.m_OutDebug = TargetMaps[i].tflags & OUTDEBUG ? 1 : 0;
dlg.m_CursorTrace = TargetMaps[i].tflags & OUTCURSORTRACE ? 1 : 0;
dlg.m_LogEnabled = TargetMaps[i].tflags & OUTTRACE ? 1 : 0;
dlg.m_OutWinMessages = TargetMaps[i].tflags & OUTWINMESSAGES ? 1 : 0;
dlg.m_OutDXTrace = TargetMaps[i].tflags & OUTPROXYTRACE ? 1 : 0;
dlg.m_DXProxed = TargetMaps[i].tflags & DXPROXED ? 1 : 0;
dlg.m_AssertDialog = TargetMaps[i].tflags & ASSERTDIALOG ? 1 : 0;
dlg.m_ImportTable = TargetMaps[i].tflags & OUTIMPORTTABLE ? 1 : 0;
dlg.m_HandleDC = TargetMaps[i].flags & HANDLEDC ? 1 : 0;
dlg.m_HandleExceptions = TargetMaps[i].flags & HANDLEEXCEPTIONS ? 1 : 0;
dlg.m_SuppressIME = TargetMaps[i].flags2 & SUPPRESSIME ? 1 : 0;
dlg.m_SuppressD3DExt = TargetMaps[i].flags3 & SUPPRESSD3DEXT ? 1 : 0;
dlg.m_SetCompatibility = TargetMaps[i].flags2 & SETCOMPATIBILITY ? 1 : 0;
dlg.m_SaveCaps = TargetMaps[i].flags3 & SAVECAPS ? 1 : 0;
dlg.m_SingleProcAffinity = TargetMaps[i].flags3 & SINGLEPROCAFFINITY ? 1 : 0;
dlg.m_LimitResources = TargetMaps[i].flags2 & LIMITRESOURCES ? 1 : 0;
dlg.m_SaveLoad = TargetMaps[i].flags & SAVELOAD ? 1 : 0;
dlg.m_SlowDown = TargetMaps[i].flags & SLOWDOWN ? 1 : 0;
dlg.m_BlitFromBackBuffer = TargetMaps[i].flags & BLITFROMBACKBUFFER ? 1 : 0;
dlg.m_SuppressClipping = TargetMaps[i].flags & SUPPRESSCLIPPING ? 1 : 0;
dlg.m_DisableGammaRamp = TargetMaps[i].flags2 & DISABLEGAMMARAMP ? 1 : 0;
dlg.m_AutoRefresh = TargetMaps[i].flags & AUTOREFRESH ? 1 : 0;
dlg.m_FixWinFrame = TargetMaps[i].flags & FIXWINFRAME ? 1 : 0;
dlg.m_HideHwCursor = TargetMaps[i].flags & HIDEHWCURSOR ? 1 : 0;
dlg.m_ShowHwCursor = TargetMaps[i].flags2 & SHOWHWCURSOR ? 1 : 0;
dlg.m_EnableClipping = TargetMaps[i].flags & ENABLECLIPPING ? 1 : 0;
dlg.m_CursorClipping = TargetMaps[i].flags & CLIPCURSOR ? 1 : 0;
dlg.m_VideoToSystemMem = TargetMaps[i].flags & SWITCHVIDEOMEMORY ? 1 : 0;
dlg.m_FixTextOut = TargetMaps[i].flags & FIXTEXTOUT ? 1 : 0;
dlg.m_KeepCursorWithin = TargetMaps[i].flags & KEEPCURSORWITHIN ? 1 : 0;
dlg.m_KeepCursorFixed = TargetMaps[i].flags2 & KEEPCURSORFIXED ? 1 : 0;
dlg.m_UseRGB565 = TargetMaps[i].flags & USERGB565 ? 1 : 0;
dlg.m_SuppressDXErrors = TargetMaps[i].flags & SUPPRESSDXERRORS ? 1 : 0;
dlg.m_MarkBlit = TargetMaps[i].flags3 & MARKBLIT ? 1 : 0;
dlg.m_PreventMaximize = TargetMaps[i].flags & PREVENTMAXIMIZE ? 1 : 0;
dlg.m_ClientRemapping = TargetMaps[i].flags & CLIENTREMAPPING ? 1 : 0;
dlg.m_MapGDIToPrimary = TargetMaps[i].flags & MAPGDITOPRIMARY ? 1 : 0;
dlg.m_LockWinPos = TargetMaps[i].flags & LOCKWINPOS ? 1 : 0;
dlg.m_LockWinStyle = TargetMaps[i].flags & LOCKWINSTYLE ? 1 : 0;
dlg.m_FixParentWin = TargetMaps[i].flags & FIXPARENTWIN ? 1 : 0;
dlg.m_ModalStyle = TargetMaps[i].flags2 & MODALSTYLE ? 1 : 0;
dlg.m_KeepAspectRatio = TargetMaps[i].flags2 & KEEPASPECTRATIO ? 1 : 0;
dlg.m_ForceWinResize = TargetMaps[i].flags2 & FORCEWINRESIZE ? 1 : 0;
dlg.m_HookGDI = TargetMaps[i].flags2 & HOOKGDI ? 1 : 0;
dlg.m_HideMultiMonitor = TargetMaps[i].flags2 & HIDEMULTIMONITOR ? 1 : 0;
dlg.m_WallpaperMode = TargetMaps[i].flags2 & WALLPAPERMODE ? 1 : 0;
dlg.m_FixD3DFrame = TargetMaps[i].flags3 & FIXD3DFRAME ? 1 : 0;
dlg.m_Force16BPP = TargetMaps[i].flags3 & FORCE16BPP ? 1 : 0;
dlg.m_HookChildWin = TargetMaps[i].flags & HOOKCHILDWIN ? 1 : 0;
dlg.m_MessageProc = TargetMaps[i].flags & MESSAGEPROC ? 1 : 0;
dlg.m_FixNCHITTEST = TargetMaps[i].flags2 & FIXNCHITTEST ? 1 : 0;
dlg.m_RecoverScreenMode = TargetMaps[i].flags2 & RECOVERSCREENMODE ? 1 : 0;
dlg.m_RefreshOnResize = TargetMaps[i].flags2 & REFRESHONRESIZE ? 1 : 0;
dlg.m_Init8BPP = TargetMaps[i].flags2 & INIT8BPP ? 1 : 0;
dlg.m_Init16BPP = TargetMaps[i].flags2 & INIT16BPP ? 1 : 0;
dlg.m_BackBufAttach = TargetMaps[i].flags2 & BACKBUFATTACH ? 1 : 0;
dlg.m_HandleAltF4 = TargetMaps[i].flags & HANDLEALTF4 ? 1 : 0;
dlg.m_LimitFPS = TargetMaps[i].flags2 & LIMITFPS ? 1 : 0;
dlg.m_SkipFPS = TargetMaps[i].flags2 & SKIPFPS ? 1 : 0;
dlg.m_ShowFPS = TargetMaps[i].flags2 & SHOWFPS ? 1 : 0;
dlg.m_ShowFPSOverlay = TargetMaps[i].flags2 & SHOWFPSOVERLAY ? 1 : 0;
dlg.m_TimeStretch = TargetMaps[i].flags2 & TIMESTRETCH ? 1 : 0;
dlg.m_HookOpenGL = TargetMaps[i].flags2 & HOOKOPENGL ? 1 : 0;
dlg.m_ForceHookOpenGL = TargetMaps[i].flags3 & FORCEHOOKOPENGL ? 1 : 0;
dlg.m_WireFrame = TargetMaps[i].flags2 & WIREFRAME ? 1 : 0;
dlg.m_BlackWhite = TargetMaps[i].flags3 & BLACKWHITE ? 1 : 0;
dlg.m_FakeVersion = TargetMaps[i].flags2 & FAKEVERSION ? 1 : 0;
dlg.m_FullRectBlt = TargetMaps[i].flags2 & FULLRECTBLT ? 1 : 0;
dlg.m_NoPaletteUpdate = TargetMaps[i].flags2 & NOPALETTEUPDATE ? 1 : 0;
dlg.m_InitX = TargetMaps[i].initx;
dlg.m_InitY = TargetMaps[i].inity;
dlg.m_MinX = TargetMaps[i].minx;
dlg.m_MinY = TargetMaps[i].miny;
dlg.m_MaxX = TargetMaps[i].maxx;
dlg.m_MaxY = TargetMaps[i].maxy;
dlg.m_PosX = TargetMaps[i].posx;
dlg.m_PosY = TargetMaps[i].posy;
dlg.m_SizX = TargetMaps[i].sizx;
dlg.m_SizY = TargetMaps[i].sizy;
dlg.m_MaxFPS = TargetMaps[i].MaxFPS;
dlg.m_InitTS = TargetMaps[i].InitTS+8;
dlg.m_FakeVersionId = TargetMaps[i].FakeVersionId;
SetDlgFromTarget(&TargetMaps[i], &dlg);
if(dlg.DoModal() == IDOK && dlg.m_FilePath.GetLength()){
strcpy_s(TargetMaps[i].path, sizeof(TargetMaps[i].path), dlg.m_FilePath);
strcpy_s(TargetMaps[i].module, sizeof(TargetMaps[i].module), dlg.m_Module);
strcpy_s(TargetMaps[i].OpenGLLib, sizeof(TargetMaps[i].OpenGLLib), dlg.m_OpenGLLib);
strcpy_s(TitleMaps[i].title, sizeof(TitleMaps[i].title), dlg.m_Title);
if(dlg.m_DXVersion > 1) dlg.m_DXVersion += 5;
TargetMaps[i].dxversion = dlg.m_DXVersion;
TargetMaps[i].coordinates = dlg.m_Coordinates;
TargetMaps[i].flags = 0;
TargetMaps[i].flags2 = 0;
TargetMaps[i].flags3 = 0;
TargetMaps[i].flags4 = 0;
TargetMaps[i].tflags = 0;
if(dlg.m_UnNotify) TargetMaps[i].flags |= UNNOTIFY;
if(dlg.m_Windowize) TargetMaps[i].flags2 |= WINDOWIZE;
if(dlg.m_HookDLLs) TargetMaps[i].flags3 |= HOOKDLLS;
if(dlg.m_HookEnabled) TargetMaps[i].flags3 |= HOOKENABLED;
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;
TargetMaps[i].flags &= ~EMULATEFLAGS;
}
if(dlg.m_EmulateSurface) {
dlg.m_NoEmulateSurface = FALSE;
dlg.m_EmulateBuffer = FALSE;
TargetMaps[i].flags &= ~EMULATEFLAGS;
TargetMaps[i].flags |= EMULATESURFACE;
}
if(dlg.m_EmulateBuffer) {
dlg.m_NoEmulateSurface = FALSE;
dlg.m_EmulateSurface = FALSE;
TargetMaps[i].flags &= ~EMULATEFLAGS;
TargetMaps[i].flags |= EMULATEBUFFER;
}
if(dlg.m_HookDI) TargetMaps[i].flags |= HOOKDI;
if(dlg.m_ModifyMouse) TargetMaps[i].flags |= MODIFYMOUSE;
if(dlg.m_OutTrace) TargetMaps[i].tflags |= OUTDDRAWTRACE;
if(dlg.m_OutDebug) TargetMaps[i].tflags |= OUTDEBUG;
if(dlg.m_CursorTrace) TargetMaps[i].tflags |= OUTCURSORTRACE;
if(dlg.m_LogEnabled) TargetMaps[i].tflags |= OUTTRACE;
if(dlg.m_OutWinMessages) TargetMaps[i].tflags |= OUTWINMESSAGES;
if(dlg.m_OutDXTrace) TargetMaps[i].tflags |= OUTPROXYTRACE;
if(dlg.m_DXProxed) TargetMaps[i].tflags |= DXPROXED;
if(dlg.m_AssertDialog) TargetMaps[i].tflags |= ASSERTDIALOG;
if(dlg.m_ImportTable) TargetMaps[i].tflags |= OUTIMPORTTABLE;
if(dlg.m_HandleDC) TargetMaps[i].flags |= HANDLEDC;
if(dlg.m_HandleExceptions) TargetMaps[i].flags |= HANDLEEXCEPTIONS;
if(dlg.m_LimitResources) TargetMaps[i].flags2 |= LIMITRESOURCES;
if(dlg.m_SuppressIME) TargetMaps[i].flags2 |= SUPPRESSIME;
if(dlg.m_SuppressD3DExt) TargetMaps[i].flags3 |= SUPPRESSD3DEXT;
if(dlg.m_SetCompatibility) TargetMaps[i].flags2 |= SETCOMPATIBILITY;
if(dlg.m_SaveCaps) TargetMaps[i].flags3 |= SAVECAPS;
if(dlg.m_SingleProcAffinity) TargetMaps[i].flags3 |= SINGLEPROCAFFINITY;
if(dlg.m_SaveLoad) TargetMaps[i].flags |= SAVELOAD;
if(dlg.m_SlowDown) TargetMaps[i].flags |= SLOWDOWN;
if(dlg.m_BlitFromBackBuffer) TargetMaps[i].flags |= BLITFROMBACKBUFFER;
if(dlg.m_SuppressClipping) TargetMaps[i].flags |= SUPPRESSCLIPPING;
if(dlg.m_DisableGammaRamp) TargetMaps[i].flags2 |= DISABLEGAMMARAMP;
if(dlg.m_AutoRefresh) TargetMaps[i].flags |= AUTOREFRESH;
if(dlg.m_FixWinFrame) TargetMaps[i].flags |= FIXWINFRAME;
if(dlg.m_HideHwCursor) TargetMaps[i].flags |= HIDEHWCURSOR;
if(dlg.m_ShowHwCursor) TargetMaps[i].flags2 |= SHOWHWCURSOR;
if(dlg.m_EnableClipping) TargetMaps[i].flags |= ENABLECLIPPING;
if(dlg.m_CursorClipping) TargetMaps[i].flags |= CLIPCURSOR;
if(dlg.m_VideoToSystemMem) TargetMaps[i].flags |= SWITCHVIDEOMEMORY;
if(dlg.m_FixTextOut) TargetMaps[i].flags |= FIXTEXTOUT;
if(dlg.m_KeepCursorWithin) TargetMaps[i].flags |= KEEPCURSORWITHIN;
if(dlg.m_KeepCursorFixed) TargetMaps[i].flags2 |= KEEPCURSORFIXED;
if(dlg.m_UseRGB565) TargetMaps[i].flags |= USERGB565;
if(dlg.m_SuppressDXErrors) TargetMaps[i].flags |= SUPPRESSDXERRORS;
if(dlg.m_MarkBlit) TargetMaps[i].flags3 |= MARKBLIT;
if(dlg.m_PreventMaximize) TargetMaps[i].flags |= PREVENTMAXIMIZE;
if(dlg.m_ClientRemapping) TargetMaps[i].flags |= CLIENTREMAPPING;
if(dlg.m_MapGDIToPrimary) TargetMaps[i].flags |= MAPGDITOPRIMARY;
if(dlg.m_LockWinPos) TargetMaps[i].flags |= LOCKWINPOS;
if(dlg.m_LockWinStyle) TargetMaps[i].flags |= LOCKWINSTYLE;
if(dlg.m_FixParentWin) TargetMaps[i].flags |= FIXPARENTWIN;
if(dlg.m_ModalStyle) TargetMaps[i].flags2 |= MODALSTYLE;
if(dlg.m_KeepAspectRatio) TargetMaps[i].flags2 |= KEEPASPECTRATIO;
if(dlg.m_ForceWinResize) TargetMaps[i].flags2 |= FORCEWINRESIZE;
if(dlg.m_HookGDI) TargetMaps[i].flags2 |= HOOKGDI;
if(dlg.m_HideMultiMonitor) TargetMaps[i].flags2 |= HIDEMULTIMONITOR;
if(dlg.m_WallpaperMode) TargetMaps[i].flags2 |= WALLPAPERMODE;
if(dlg.m_FixD3DFrame) TargetMaps[i].flags3 |= FIXD3DFRAME;
if(dlg.m_Force16BPP) TargetMaps[i].flags3 |= FORCE16BPP;
if(dlg.m_HookChildWin) TargetMaps[i].flags |= HOOKCHILDWIN;
if(dlg.m_MessageProc) TargetMaps[i].flags |= MESSAGEPROC;
if(dlg.m_FixNCHITTEST) TargetMaps[i].flags2 |= FIXNCHITTEST;
if(dlg.m_RecoverScreenMode) TargetMaps[i].flags2 |= RECOVERSCREENMODE;
if(dlg.m_RefreshOnResize) TargetMaps[i].flags2 |= REFRESHONRESIZE;
if(dlg.m_Init8BPP) TargetMaps[i].flags2 |= INIT8BPP;
if(dlg.m_Init16BPP) TargetMaps[i].flags2 |= INIT16BPP;
if(dlg.m_BackBufAttach) TargetMaps[i].flags2 |= BACKBUFATTACH;
if(dlg.m_HandleAltF4) TargetMaps[i].flags |= HANDLEALTF4;
if(dlg.m_LimitFPS) TargetMaps[i].flags2 |= LIMITFPS;
if(dlg.m_SkipFPS) TargetMaps[i].flags2 |= SKIPFPS;
if(dlg.m_ShowFPS) TargetMaps[i].flags2 |= SHOWFPS;
if(dlg.m_ShowFPSOverlay) TargetMaps[i].flags2 |= SHOWFPSOVERLAY;
if(dlg.m_TimeStretch) TargetMaps[i].flags2 |= TIMESTRETCH;
if(dlg.m_HookOpenGL) TargetMaps[i].flags2 |= HOOKOPENGL;
if(dlg.m_ForceHookOpenGL) TargetMaps[i].flags3 |= FORCEHOOKOPENGL;
if(dlg.m_WireFrame) TargetMaps[i].flags2 |= WIREFRAME;
if(dlg.m_BlackWhite) TargetMaps[i].flags3 |= BLACKWHITE;
if(dlg.m_FakeVersion) TargetMaps[i].flags2 |= FAKEVERSION;
if(dlg.m_FullRectBlt) TargetMaps[i].flags2 |= FULLRECTBLT;
if(dlg.m_NoPaletteUpdate) TargetMaps[i].flags2 |= NOPALETTEUPDATE;
TargetMaps[i].initx = dlg.m_InitX;
TargetMaps[i].inity = dlg.m_InitY;
TargetMaps[i].minx = dlg.m_MinX;
TargetMaps[i].miny = dlg.m_MinY;
TargetMaps[i].maxx = dlg.m_MaxX;
TargetMaps[i].maxy = dlg.m_MaxY;
TargetMaps[i].posx = dlg.m_PosX;
TargetMaps[i].posy = dlg.m_PosY;
TargetMaps[i].sizx = dlg.m_SizX;
TargetMaps[i].sizy = dlg.m_SizY;
TargetMaps[i].MaxFPS = dlg.m_MaxFPS;
TargetMaps[i].InitTS = dlg.m_InitTS-8;
TargetMaps[i].FakeVersionId = dlg.m_FakeVersionId;
strcpy_s(TargetMaps[i].module, sizeof(TargetMaps[i].module), dlg.m_Module);
strcpy_s(TargetMaps[i].OpenGLLib, sizeof(TargetMaps[i].OpenGLLib), dlg.m_OpenGLLib);
strcpy_s(TitleMaps[i].title, sizeof(TitleMaps[i].title), dlg.m_Title);
strncpy(TitleMaps[i].title, dlg.m_Title, 40);
SetTargetFromDlg(&TargetMaps[i], &dlg);
CListCtrl& listctrl = GetListCtrl();
listitem.mask = LVIF_TEXT | LVIF_IMAGE;
listitem.iItem = i;
@ -1018,127 +1027,8 @@ void CDxwndhostView::OnAdd()
return;
}
if(dlg.DoModal() == IDOK && dlg.m_FilePath.GetLength()){
strcpy_s(TargetMaps[i].path,sizeof(TargetMaps[i].path),dlg.m_FilePath);
strcpy_s(TargetMaps[i].module,sizeof(TargetMaps[i].module),dlg.m_Module);
strcpy_s(TargetMaps[i].OpenGLLib,sizeof(TargetMaps[i].OpenGLLib),dlg.m_OpenGLLib);
strcpy_s(TitleMaps[i].title, sizeof(TitleMaps[i].title), dlg.m_Title);
if(dlg.m_DXVersion > 1) dlg.m_DXVersion += 5;
TargetMaps[i].dxversion = dlg.m_DXVersion;
TargetMaps[i].coordinates = dlg.m_Coordinates;
TargetMaps[i].flags = 0;
TargetMaps[i].flags2 = 0;
TargetMaps[i].tflags = 0;
if(dlg.m_UnNotify) TargetMaps[i].flags |= UNNOTIFY;
if(dlg.m_Windowize) TargetMaps[i].flags2 |= WINDOWIZE;
if(dlg.m_HookDLLs) TargetMaps[i].flags3 |= HOOKDLLS;
if(dlg.m_HookEnabled) TargetMaps[i].flags3 |= HOOKENABLED;
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;
TargetMaps[i].flags &= ~EMULATEFLAGS;
}
if(dlg.m_EmulateSurface) {
dlg.m_NoEmulateSurface = FALSE;
dlg.m_EmulateBuffer = FALSE;
TargetMaps[i].flags &= ~EMULATEFLAGS;
TargetMaps[i].flags |= EMULATESURFACE;
}
if(dlg.m_EmulateBuffer) {
dlg.m_NoEmulateSurface = FALSE;
dlg.m_EmulateSurface = FALSE;
TargetMaps[i].flags &= ~EMULATEFLAGS;
TargetMaps[i].flags |= EMULATEBUFFER;
}
if(dlg.m_HookDI) TargetMaps[i].flags |= HOOKDI;
if(dlg.m_ModifyMouse) TargetMaps[i].flags |= MODIFYMOUSE;
if(dlg.m_OutTrace) TargetMaps[i].tflags |= OUTDDRAWTRACE;
if(dlg.m_OutDebug) TargetMaps[i].tflags |= OUTDEBUG;
if(dlg.m_CursorTrace) TargetMaps[i].tflags |= OUTCURSORTRACE;
if(dlg.m_LogEnabled) TargetMaps[i].tflags |= OUTTRACE;
if(dlg.m_OutWinMessages) TargetMaps[i].tflags |= OUTWINMESSAGES;
if(dlg.m_OutDXTrace) TargetMaps[i].tflags |= OUTPROXYTRACE;
if(dlg.m_DXProxed) TargetMaps[i].tflags |= DXPROXED;
if(dlg.m_AssertDialog) TargetMaps[i].tflags |= ASSERTDIALOG;
if(dlg.m_ImportTable) TargetMaps[i].tflags |= OUTIMPORTTABLE;
if(dlg.m_HandleDC) TargetMaps[i].flags |= HANDLEDC;
if(dlg.m_HandleExceptions) TargetMaps[i].flags |= HANDLEEXCEPTIONS;
if(dlg.m_SuppressIME) TargetMaps[i].flags2 |= SUPPRESSIME;
if(dlg.m_SuppressD3DExt) TargetMaps[i].flags3 |= SUPPRESSD3DEXT;
if(dlg.m_SetCompatibility) TargetMaps[i].flags2 |= SETCOMPATIBILITY;
if(dlg.m_SaveCaps) TargetMaps[i].flags3 |= SAVECAPS;
if(dlg.m_SingleProcAffinity) TargetMaps[i].flags3 |= SINGLEPROCAFFINITY;
if(dlg.m_LimitResources) TargetMaps[i].flags2 |= LIMITRESOURCES;
if(dlg.m_SaveLoad) TargetMaps[i].flags |= SAVELOAD;
if(dlg.m_SlowDown) TargetMaps[i].flags |= SLOWDOWN;
if(dlg.m_BlitFromBackBuffer) TargetMaps[i].flags |= BLITFROMBACKBUFFER;
if(dlg.m_SuppressClipping) TargetMaps[i].flags |= SUPPRESSCLIPPING;
if(dlg.m_DisableGammaRamp) TargetMaps[i].flags2 |= DISABLEGAMMARAMP;
if(dlg.m_AutoRefresh) TargetMaps[i].flags |= AUTOREFRESH;
if(dlg.m_FixWinFrame) TargetMaps[i].flags |= FIXWINFRAME;
if(dlg.m_HideHwCursor) TargetMaps[i].flags |= HIDEHWCURSOR;
if(dlg.m_ShowHwCursor) TargetMaps[i].flags2 |= SHOWHWCURSOR;
if(dlg.m_EnableClipping) TargetMaps[i].flags |= ENABLECLIPPING;
if(dlg.m_CursorClipping) TargetMaps[i].flags |= CLIPCURSOR;
if(dlg.m_VideoToSystemMem) TargetMaps[i].flags |= SWITCHVIDEOMEMORY;
if(dlg.m_FixTextOut) TargetMaps[i].flags |= FIXTEXTOUT;
if(dlg.m_KeepCursorWithin) TargetMaps[i].flags |= KEEPCURSORWITHIN;
if(dlg.m_KeepCursorFixed) TargetMaps[i].flags2 |= KEEPCURSORFIXED;
if(dlg.m_UseRGB565) TargetMaps[i].flags |= USERGB565;
if(dlg.m_SuppressDXErrors) TargetMaps[i].flags |= SUPPRESSDXERRORS;
if(dlg.m_MarkBlit) TargetMaps[i].flags3 |= MARKBLIT;
if(dlg.m_PreventMaximize) TargetMaps[i].flags |= PREVENTMAXIMIZE;
if(dlg.m_ClientRemapping) TargetMaps[i].flags |= CLIENTREMAPPING;
if(dlg.m_MapGDIToPrimary) TargetMaps[i].flags |= MAPGDITOPRIMARY;
if(dlg.m_LockWinPos) TargetMaps[i].flags |= LOCKWINPOS;
if(dlg.m_LockWinStyle) TargetMaps[i].flags |= LOCKWINSTYLE;
if(dlg.m_FixParentWin) TargetMaps[i].flags |= FIXPARENTWIN;
if(dlg.m_ModalStyle) TargetMaps[i].flags2 |= MODALSTYLE;
if(dlg.m_KeepAspectRatio) TargetMaps[i].flags2 |= KEEPASPECTRATIO;
if(dlg.m_ForceWinResize) TargetMaps[i].flags2 |= FORCEWINRESIZE;
if(dlg.m_HookGDI) TargetMaps[i].flags2 |= HOOKGDI;
if(dlg.m_HideMultiMonitor) TargetMaps[i].flags2 |= HIDEMULTIMONITOR;
if(dlg.m_WallpaperMode) TargetMaps[i].flags2 |= WALLPAPERMODE;
if(dlg.m_FixD3DFrame) TargetMaps[i].flags3 |= FIXD3DFRAME;
if(dlg.m_Force16BPP) TargetMaps[i].flags3 |= FORCE16BPP;
if(dlg.m_HookChildWin) TargetMaps[i].flags |= HOOKCHILDWIN;
if(dlg.m_MessageProc) TargetMaps[i].flags |= MESSAGEPROC;
if(dlg.m_FixNCHITTEST) TargetMaps[i].flags2 |= FIXNCHITTEST;
if(dlg.m_RecoverScreenMode) TargetMaps[i].flags2 |= RECOVERSCREENMODE;
if(dlg.m_RefreshOnResize) TargetMaps[i].flags2 |= REFRESHONRESIZE;
if(dlg.m_Init8BPP) TargetMaps[i].flags2 |= INIT8BPP;
if(dlg.m_Init16BPP) TargetMaps[i].flags2 |= INIT16BPP;
if(dlg.m_BackBufAttach) TargetMaps[i].flags2 |= BACKBUFATTACH;
if(dlg.m_HandleAltF4) TargetMaps[i].flags |= HANDLEALTF4;
if(dlg.m_LimitFPS) TargetMaps[i].flags2 |= LIMITFPS;
if(dlg.m_SkipFPS) TargetMaps[i].flags2 |= SKIPFPS;
if(dlg.m_ShowFPS) TargetMaps[i].flags2 |= SHOWFPS;
if(dlg.m_ShowFPSOverlay) TargetMaps[i].flags2 |= SHOWFPSOVERLAY;
if(dlg.m_TimeStretch) TargetMaps[i].flags2 |= TIMESTRETCH;
if(dlg.m_HookOpenGL) TargetMaps[i].flags2 |= HOOKOPENGL;
if(dlg.m_ForceHookOpenGL) TargetMaps[i].flags3 |= FORCEHOOKOPENGL;
if(dlg.m_WireFrame) TargetMaps[i].flags2 |= WIREFRAME;
if(dlg.m_BlackWhite) TargetMaps[i].flags3 |= BLACKWHITE;
if(dlg.m_FakeVersion) TargetMaps[i].flags2 |= FAKEVERSION;
if(dlg.m_FullRectBlt) TargetMaps[i].flags2 |= FULLRECTBLT;
if(dlg.m_NoPaletteUpdate) TargetMaps[i].flags2 |= NOPALETTEUPDATE;
TargetMaps[i].initx = dlg.m_InitX;
TargetMaps[i].inity = dlg.m_InitY;
TargetMaps[i].minx = dlg.m_MinX;
TargetMaps[i].miny = dlg.m_MinY;
TargetMaps[i].maxx = dlg.m_MaxX;
TargetMaps[i].maxy = dlg.m_MaxY;
TargetMaps[i].posx = dlg.m_PosX;
TargetMaps[i].posy = dlg.m_PosY;
TargetMaps[i].sizx = dlg.m_SizX;
TargetMaps[i].sizy = dlg.m_SizY;
TargetMaps[i].MaxFPS = dlg.m_MaxFPS;
TargetMaps[i].FakeVersionId = dlg.m_FakeVersionId;
if (dlg.m_InitTS>=-8 && dlg.m_InitTS<=8)
TargetMaps[i].InitTS = dlg.m_InitTS-8;
else
MessageBoxEx(0, "Bad InitTS", "Warning", MB_OK, NULL);
strncpy(TitleMaps[i].title, dlg.m_Title, 40);
SetTargetFromDlg(&TargetMaps[i], &dlg);
CListCtrl& listctrl = GetListCtrl();
listitem.mask = LVIF_TEXT | LVIF_IMAGE;
listitem.iItem = i;