diff --git a/build/dxwnd.dll b/build/dxwnd.dll index 455008c..4954745 100644 --- a/build/dxwnd.dll +++ b/build/dxwnd.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8b63cb25a2b2f543143293943a740859894c0a8b2ff156428c40376380a47a13 +oid sha256:95762cfc50b158119d3bcb3d7a613dd13ae5abc3555c4c8153d9560bdafad4e6 size 577536 diff --git a/build/dxwnd.ini b/build/dxwnd.ini deleted file mode 100644 index 7f729a0..0000000 --- a/build/dxwnd.ini +++ /dev/null @@ -1,5 +0,0 @@ -[window] -posx=50 -posy=50 -sizx=320 -sizy=200 diff --git a/build/exports/Abomination.dxw b/build/exports/Abomination.dxw index 1f8215f..8c3bfa4 100644 --- a/build/exports/Abomination.dxw +++ b/build/exports/Abomination.dxw @@ -5,10 +5,10 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=134218272 -flagg0=134217728 +flag0=134217762 +flagg0=1207959552 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=0 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Ancient Evil demo.dxw b/build/exports/Ancient Evil demo.dxw index c6ad005..c702448 100644 --- a/build/exports/Ancient Evil demo.dxw +++ b/build/exports/Ancient Evil demo.dxw @@ -5,11 +5,11 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=150994976 +flag0=136331298 flagg0=1207959552 -flagh0=25165844 -flagi0=0 -tflag0=259 +flagh0=20 +flagi0=4194304 +tflag0=0 initx0=0 inity0=0 minx0=0 @@ -22,3 +22,10 @@ sizx0=800 sizy0=600 maxfps0=0 initts0=0 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +winver0=0 +maxres0=0 +swapeffect0=0 diff --git a/build/exports/Army Men RTS.dxw b/build/exports/Army Men RTS.dxw index 163d2cf..e89ee1b 100644 --- a/build/exports/Army Men RTS.dxw +++ b/build/exports/Army Men RTS.dxw @@ -5,10 +5,10 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=671088676 +flag0=671088678 flagg0=1207959552 flagh0=20 -flagi0=0 +flagi0=4194304 tflag0=0 initx0=0 inity0=0 @@ -22,3 +22,10 @@ sizx0=800 sizy0=600 maxfps0=0 initts0=0 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +winver0=0 +maxres0=0 +swapeffect0=0 diff --git a/build/exports/Cave Story.dxw b/build/exports/Cave Story.dxw index 32eed40..7019150 100644 --- a/build/exports/Cave Story.dxw +++ b/build/exports/Cave Story.dxw @@ -8,7 +8,7 @@ coord0=0 flag0=134217762 flagg0=1207959552 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=0 initx0=0 inity0=0 @@ -22,3 +22,10 @@ sizx0=800 sizy0=600 maxfps0=0 initts0=0 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +winver0=0 +maxres0=0 +swapeffect0=0 diff --git a/build/exports/Chicago 1930.dxw b/build/exports/Chicago 1930.dxw index 629f5b5..212fb87 100644 --- a/build/exports/Chicago 1930.dxw +++ b/build/exports/Chicago 1930.dxw @@ -5,8 +5,8 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=134234660 -flagg0=134217728 +flag0=134234150 +flagg0=1207959552 flagh0=20 flagi0=4325380 tflag0=64 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Colin McRae Rally 2.0.dxw b/build/exports/Colin McRae Rally 2.0.dxw index 377decb..6dcc9ef 100644 --- a/build/exports/Colin McRae Rally 2.0.dxw +++ b/build/exports/Colin McRae Rally 2.0.dxw @@ -6,7 +6,7 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=134217760 +flag0=134217762 flagg0=1207959552 flagh0=20 flagi0=138412036 @@ -25,3 +25,7 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +notes0= +flagj0=4224 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Earthworm Jim 3D.dxw b/build/exports/Earthworm Jim 3D.dxw index 06a6bfc..cdc01c8 100644 --- a/build/exports/Earthworm Jim 3D.dxw +++ b/build/exports/Earthworm Jim 3D.dxw @@ -5,11 +5,11 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=134217760 +flag0=134217762 flagg0=1212153856 flagh0=65556 -flagi0=4 -tflag0=6211 +flagi0=4194308 +tflag0=6147 initx0=0 inity0=0 minx0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=1 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Ed Hunter.dxw b/build/exports/Ed Hunter.dxw index 17f36dd..743b133 100644 --- a/build/exports/Ed Hunter.dxw +++ b/build/exports/Ed Hunter.dxw @@ -8,7 +8,7 @@ coord0=0 flag0=134217762 flagg0=1208025088 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=0 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=2 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Empire Earth.dxw b/build/exports/Empire Earth.dxw index ef00b0e..0fb0433 100644 --- a/build/exports/Empire Earth.dxw +++ b/build/exports/Empire Earth.dxw @@ -5,10 +5,10 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=671088673 +flag0=671088675 flagg0=1207959552 flagh0=20 -flagi0=131076 +flagi0=4325380 tflag0=6147 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Empire of the Ants.dxw b/build/exports/Empire of the Ants.dxw index 183ef48..3971d7b 100644 --- a/build/exports/Empire of the Ants.dxw +++ b/build/exports/Empire of the Ants.dxw @@ -5,10 +5,10 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=402669604 -flagg0=134217728 +flag0=402669606 +flagg0=1207959552 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=64 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Fallout.dxw b/build/exports/Fallout.dxw index 2a26179..a74e5df 100644 --- a/build/exports/Fallout.dxw +++ b/build/exports/Fallout.dxw @@ -5,10 +5,10 @@ module0= opengllib0= ver0=1 coord0=0 -flag0=134218272 -flagg0=134217728 +flag0=134217762 +flagg0=1207959552 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=0 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Fifa 99 (Direct3D).dxw b/build/exports/Fifa 99 (Direct3D).dxw index e44d1d0..f8c3673 100644 --- a/build/exports/Fifa 99 (Direct3D).dxw +++ b/build/exports/Fifa 99 (Direct3D).dxw @@ -6,8 +6,8 @@ module0= opengllib0= ver0=7 coord0=0 -flag0=671105312 -flagg0=-937410560 +flag0=671105058 +flagg0=1207959552 flagh0=20 flagi0=138412036 flagj0=128 @@ -26,3 +26,6 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +notes0= +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Final Odyssey.dxw b/build/exports/Final Odyssey.dxw index 9686a8a..f2b827a 100644 --- a/build/exports/Final Odyssey.dxw +++ b/build/exports/Final Odyssey.dxw @@ -5,10 +5,10 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=134267425 -flagg0=134217728 +flag0=134266915 +flagg0=1207959552 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=6146 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Forsaken (HW).dxw b/build/exports/Forsaken (HW).dxw index f5ba94d..ad3c252 100644 --- a/build/exports/Forsaken (HW).dxw +++ b/build/exports/Forsaken (HW).dxw @@ -26,4 +26,6 @@ winver0=0 maxres0=-1 launchpath0= notes0= -flagj0=8388736 +flagj0=262272 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Galapagos.dxw b/build/exports/Galapagos.dxw index be8b55b..7bddc2e 100644 --- a/build/exports/Galapagos.dxw +++ b/build/exports/Galapagos.dxw @@ -8,7 +8,7 @@ notes0= ver0=7 coord0=0 flag0=746602528 -flagg0=1207959552 +flagg0=1209008128 flagh0=16 flagi0=138412036 flagj0=142610600 @@ -27,3 +27,5 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Genocide (ORIGINAL).dxw b/build/exports/Genocide (ORIGINAL).dxw index 8dcd06c..bb51d25 100644 --- a/build/exports/Genocide (ORIGINAL).dxw +++ b/build/exports/Genocide (ORIGINAL).dxw @@ -8,7 +8,7 @@ coord0=0 flag0=134218272 flagg0=1207959552 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=0 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Genocide (REMIXED VERSION).dxw b/build/exports/Genocide (REMIXED VERSION).dxw index 796cbf1..7a5c76f 100644 --- a/build/exports/Genocide (REMIXED VERSION).dxw +++ b/build/exports/Genocide (REMIXED VERSION).dxw @@ -5,10 +5,10 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=134218272 +flag0=134217762 flagg0=1207959552 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=6402 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Grand Prix World.dxw b/build/exports/Grand Prix World.dxw index 744e871..f96743d 100644 --- a/build/exports/Grand Prix World.dxw +++ b/build/exports/Grand Prix World.dxw @@ -6,7 +6,7 @@ opengllib0= ver0=0 coord0=0 flag0=134283430 -flagg0=134217856 +flagg0=1207959680 flagh0=29 flagi0=4194308 tflag0=0 @@ -25,3 +25,7 @@ initts0=0 launchpath0= winver0=0 maxres0=0 +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Hamsterball.dxw b/build/exports/Hamsterball.dxw index e4bdc3e..7dd32cf 100644 --- a/build/exports/Hamsterball.dxw +++ b/build/exports/Hamsterball.dxw @@ -8,8 +8,8 @@ coord0=0 flag0=134217762 flagg0=1207959552 flagh0=20 -flagi0=0 -tflag0=323 +flagi0=4194304 +tflag0=64 initx0=0 inity0=0 minx0=0 @@ -22,3 +22,10 @@ sizx0=800 sizy0=600 maxfps0=0 initts0=0 +launchpath0= +notes0= +flagj0=0 +flagk0=0 +winver0=0 +maxres0=0 +swapeffect0=0 diff --git a/build/exports/House of the Dead 2.dxw b/build/exports/House of the Dead 2.dxw index aadf8b6..7fdf9f6 100644 --- a/build/exports/House of the Dead 2.dxw +++ b/build/exports/House of the Dead 2.dxw @@ -5,10 +5,10 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=738197536 +flag0=738197538 flagg0=1207959552 flagh0=20 -flagi0=4 +flagi0=4194308 tflag0=0 initx0=0 inity0=0 @@ -24,3 +24,8 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +launchpath0= +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Magic & Mayhem.dxw b/build/exports/Magic & Mayhem.dxw index e07a544..acf7575 100644 --- a/build/exports/Magic & Mayhem.dxw +++ b/build/exports/Magic & Mayhem.dxw @@ -6,7 +6,7 @@ opengllib0= ver0=0 coord0=0 flag0=138428450 -flagg0=201326592 +flagg0=1275068416 flagh0=20 flagi0=4194304 tflag0=259 @@ -25,3 +25,7 @@ initts0=0 launchpath0= winver0=0 maxres0=0 +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Nocturne.dxw b/build/exports/Nocturne.dxw index c39b35b..8222345 100644 --- a/build/exports/Nocturne.dxw +++ b/build/exports/Nocturne.dxw @@ -6,7 +6,7 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=134218272 +flag0=134217762 flagg0=1476395008 flagh0=20 flagi0=138412036 @@ -25,3 +25,7 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/exports/Outlaws.dxw b/build/exports/Outlaws.dxw index d54d468..e33cca1 100644 --- a/build/exports/Outlaws.dxw +++ b/build/exports/Outlaws.dxw @@ -6,7 +6,7 @@ module0= opengllib0= ver0=0 coord0=0 -flag0=671105568 +flag0=671105058 flagg0=1207959552 flagh0=20 flagi0=138412036 @@ -25,3 +25,7 @@ maxfps0=0 initts0=0 winver0=0 maxres0=-1 +notes0= +flagj0=128 +flagk0=0 +swapeffect0=0 diff --git a/build/readme-relnotes.txt b/build/readme-relnotes.txt index 1184fe0..ea3413c 100644 --- a/build/readme-relnotes.txt +++ b/build/readme-relnotes.txt @@ -801,4 +801,8 @@ fix: texture handling for texture dump/hack/highlight add: "Reserve legacy memory segments" compatibility flag, needed for "Crusaders of Might & Magic" add: preliminary support for ddraw7 DirectDrawCreateClipper api add: "Suppress main window destruction" flag, to make "Prince of Persia 3D" playable -fix: fully revised ddraw surface handling in d3d1-7 versions. Now "Might & Magic IX" is supported \ No newline at end of file +fix: fully revised ddraw surface handling in d3d1-7 versions. Now "Might & Magic IX" is supported + +v2.03.21: +fix: full re-design of ddraw "special" surface management (primary & backbuffer): greater compatibility for emulation mode +fix: GDI edit window positioning for "Imperialism" city name selection \ No newline at end of file diff --git a/dll/ddblit.cpp b/dll/ddblit.cpp index 15f61e5..1b1c146 100644 --- a/dll/ddblit.cpp +++ b/dll/ddblit.cpp @@ -8,7 +8,7 @@ #include "hddraw.h" #include "dxhelper.h" -extern LPDIRECTDRAWSURFACE lpDDSBack; +//extern LPDIRECTDRAWSURFACE lpDDSBack; extern LPDIRECTDRAWSURFACE lpDDSEmu_Prim; extern LPDIRECTDRAW lpPrimaryDD; extern Blt_Type pBlt; @@ -47,6 +47,8 @@ static HRESULT sBltNoPrimary(char *api, LPDIRECTDRAWSURFACE lpdds, LPRECT lpdest // is fixed no matter how the window/primary surface is scaled. // In "The Sims" there is no quality loss, but some scrolling artifact. if(lpsrcrect && FromScreen){ + LPDIRECTDRAWSURFACE lpDDSBack; + lpDDSBack = dxw.GetBackBufferSurface(); if(lpDDSBack && (dxw.dwFlags1 & BLITFROMBACKBUFFER)){ lpddssrc=lpDDSBack; srcrect=dxw.GetScreenRect(); @@ -151,7 +153,8 @@ static HRESULT sBltToPrimary(char *api, LPDIRECTDRAWSURFACE lpdds, LPRECT lpdest if(!lpddssrc) { if (isFlipping){ // handle the flipping chain ... - lpddssrc=lpDDSBack; + //lpddssrc=lpDDSBack; + lpddssrc = dxw.GetBackBufferSurface(); OutTraceDW("Flip: setting flip chain to lpdds=%x\n", lpddssrc); } } @@ -258,11 +261,12 @@ static HRESULT sBltToPrimary(char *api, LPDIRECTDRAWSURFACE lpdds, LPRECT lpdest V2.03.15: The same thing happens with "Silent Hunter III", but with DDERR_INVALIDRECT error code. */ if((res==DDERR_UNSUPPORTED) || (res==DDERR_EXCEPTION) || (res==DDERR_INVALIDRECT)){ - RECT targetrect; + //RECT targetrect; dxw.ShowOverlay(lpddssrc); if (IsDebug) BlitTrace("UNSUPP", &emurect, &destrect, __LINE__); - targetrect=dxw.MapWindowRect(&destrect); // v2.03.18 - res=(*pBlt)(lpDDSEmu_Prim, &targetrect, lpddssrc, lpsrcrect, dwflags, lpddbltfx); + //targetrect=dxw.MapWindowRect(&destrect); // v2.03.18 + //res=(*pBlt)(lpDDSEmu_Prim, &targetrect, lpddssrc, lpsrcrect, dwflags, lpddbltfx); + res=(*pBlt)(lpDDSEmu_Prim, &destrect, lpddssrc, lpsrcrect, dwflags, lpddbltfx); if (res) BlitError(res, lpsrcrect, &destrect, __LINE__); } diff --git a/dll/ddraw.cpp b/dll/ddraw.cpp index 72e540a..b5193b1 100644 --- a/dll/ddraw.cpp +++ b/dll/ddraw.cpp @@ -18,7 +18,6 @@ #include "syslibs.h" extern BOOL IsChangeDisplaySettingsHotPatched; -BOOL bIsWithinD3DCreateDevice = FALSE; DWORD dwBackBufferCaps; extern void TextureHandling(LPDIRECTDRAWSURFACE); ColorConversion_Type pColorConversion = NULL; @@ -252,13 +251,10 @@ GammaRamp_Type pDDSetGammaRamp; LPDIRECTDRAWSURFACE lpDDSEmu_Prim=NULL; LPDIRECTDRAWSURFACE lpDDSEmu_Back=NULL; -LPDIRECTDRAWSURFACE lpDDSBack=NULL; LPDIRECTDRAWSURFACE lpDDZBuffer=NULL; -LPDIRECTDRAWSURFACE lpDDTexture=NULL; // v2.1.87: lpPrimaryDD is the DIRECTDRAW object to which the primary surface and all // the service objects (emulated backbuffer, emulater primary, ....) are attached. LPDIRECTDRAW lpPrimaryDD=NULL; -LPDIRECTDRAW lpBackBufferDD=NULL; int iBakBufferVersion; LPDIRECTDRAWPALETTE lpDDP=NULL; @@ -1883,25 +1879,17 @@ HRESULT WINAPI extQueryInterfaceS(void *lpdds, REFIID riid, LPVOID *obp) dxw.dwDDVersion=dwLocalDDVersion; if(IsPrim){ OutTraceDW("QueryInterface(S): primary=%x new=%x\n", lpdds, *obp); - dxw.MarkPrimarySurface((LPDIRECTDRAWSURFACE)*obp); + dxw.MarkPrimarySurface((LPDIRECTDRAWSURFACE)*obp, dwLocalDDVersion); HookDDSurfacePrim((LPDIRECTDRAWSURFACE *)obp, dxw.dwDDVersion); } else{ - if(IsBack) dxw.MarkBackBufferSurface((LPDIRECTDRAWSURFACE)*obp); + if(IsBack) dxw.MarkBackBufferSurface((LPDIRECTDRAWSURFACE)*obp, dwLocalDDVersion); else dxw.MarkRegularSurface((LPDIRECTDRAWSURFACE)*obp); // v2.02.13: seems that hooking inconditionally gives troubles. What is the proper safe hook condition? HookDDSurfaceGeneric((LPDIRECTDRAWSURFACE *)obp, dxw.dwDDVersion); } break; } - if(lpdds == lpDDSBack) { - // assume that you always use the newer interface version, if available. - if(dwLocalDDVersion > (UINT)iBakBufferVersion){ - OutTraceDW("QueryInterface(S): switching backbuffer %x -> %x\n", lpDDSBack, *obp); - lpDDSBack = (LPDIRECTDRAWSURFACE)*obp; - iBakBufferVersion = dwLocalDDVersion; - } - } } if(dwLocalTexVersion) { @@ -2400,7 +2388,6 @@ static HRESULT BuildBackBufferEmu(LPDIRECTDRAW lpdd, CreateSurface_Type pCreateS OutTraceDW("CreateSurface: created BACK DDSBack=%x\n", *lplpdds); if(IsDebug) DescribeSurface(*lplpdds, dxversion, "DDSBack", __LINE__); HookDDSurfaceGeneric(lplpdds, dxversion); // added !!! - lpBackBufferDD = lpdd; // v2.02.31 iBakBufferVersion=dxversion; // v2.02.31 return DD_OK; @@ -2455,7 +2442,6 @@ static HRESULT BuildBackBufferDir(LPDIRECTDRAW lpdd, CreateSurface_Type pCreateS OutTraceDW("CreateSurface: created BACK DDSBack=%x\n", *lplpdds); if(IsDebug) DescribeSurface(*lplpdds, dxversion, "DDSBack", __LINE__); HookDDSurfaceGeneric(lplpdds, dxversion); // added !!! - lpBackBufferDD = lpdd; // v2.02.31 iBakBufferVersion=dxversion; // v2.02.31 return DD_OK; @@ -2547,6 +2533,7 @@ static HRESULT WINAPI extCreateSurface(int dxversion, CreateSurface_Type pCreate HRESULT res; DDSURFACEDESC2 ddsd; LPDIRECTDRAWSURFACE lpDDSPrim; + LPDIRECTDRAWSURFACE lpDDSBack = NULL; DWORD CurFlags; int TargetSize; typedef HRESULT (*BuildSurface_Type)(LPDIRECTDRAW, CreateSurface_Type, LPDDSURFACEDESC2, int, LPDIRECTDRAWSURFACE *, void *); @@ -2611,8 +2598,12 @@ static HRESULT WINAPI extCreateSurface(int dxversion, CreateSurface_Type pCreate if (lpDDSEmu_Back) while(lpDDSEmu_Back->Release()); if (lpDDSEmu_Prim) while(lpDDSEmu_Prim->Release()); if (ddsd.dwFlags & DDSD_BACKBUFFERCOUNT) { // Praetorians !!!! - if (lpDDSBack) while(lpDDSBack->Release()); - lpBackBufferDD = NULL; + lpDDSBack = dxw.GetBackBufferSurface(); + if (lpDDSBack) { + while(lpDDSBack->Release()); + dxw.MarkRegularSurface(lpDDSBack); + lpDDSBack = NULL; + } } } lpDDSEmu_Back=NULL; @@ -2639,14 +2630,14 @@ static HRESULT WINAPI extCreateSurface(int dxversion, CreateSurface_Type pCreate res=BuildPrimary(lpdd, pCreateSurface, lpddsd, dxversion, lplpdds, NULL); if(res) return res; lpDDSPrim = *lplpdds; - dxw.MarkPrimarySurface(lpDDSPrim); + dxw.MarkPrimarySurface(lpDDSPrim, dxversion); RegisterPixelFormat(lpDDSPrim); if (BBCount){ // build emulated backbuffer surface res=BuildBackBuffer(lpdd, pCreateSurface, lpddsd, dxversion, &lpDDSBack, NULL); if(res) return res; - dxw.MarkBackBufferSurface(lpDDSBack); + dxw.MarkBackBufferSurface(lpDDSBack, dxversion); // V2.1.85/V2.2.34: tricky !!!! // When a real backbuffer is created, it has a reference to its frontbuffer. @@ -2687,8 +2678,7 @@ static HRESULT WINAPI extCreateSurface(int dxversion, CreateSurface_Type pCreate } res=BuildBackBuffer(lpdd, pCreateSurface, lpddsd, dxversion, lplpdds, NULL); - lpDDSBack = *lplpdds; - dxw.MarkBackBufferSurface(lpDDSBack); + if(res == DD_OK) dxw.MarkBackBufferSurface(*lplpdds, dxversion); return res; } @@ -2742,15 +2732,6 @@ HRESULT WINAPI extGetAttachedSurface(int dxversion, GetAttachedSurface_Type pGet OutTraceDDRAW("GetAttachedSurface(%d): lpdds=%x%s caps=%x(%s)\n", dxversion, lpdds, (IsPrim?"(PRIM)":(IsBack ? "(BACK)":"")), lpddsc->dwCaps, ExplainDDSCaps(lpddsc->dwCaps)); - // this is yet to be proven utility..... - // v2.02.45: No - it prevents "Praetorians" to work!!! -> commented out. - // - //if (IsBack && (lpddsc->dwCaps & DDSCAPS_ZBUFFER) && lpDDZBuffer){ - // *lplpddas = lpDDZBuffer; - // OutTraceDW("GetAttachedSurface(%d): emulating ZBUFFER attach on BACKBUFFER lpddsadd=%x\n", dxversion, *lplpddas); - // return 0; - //} - // v2.1.81: fix to make "Silver" working: if the primary surface was created with // backbuffercount == 2, the game expects some more surface to be attached to // the attached backbuffer. Since there would be no use for it, just return @@ -2759,16 +2740,15 @@ HRESULT WINAPI extGetAttachedSurface(int dxversion, GetAttachedSurface_Type pGet // the primary surface was created with back buffer count == 1. // v2.2.62 fix: a check to implement doublebuffer emulation only in case of DDSCAPS_BACKBUFFER // requests. A call to GetAttachedSurface can be made to retrieve DDSCAPS_ZBUFFER surfaces, and in - // this case the lpDDSBack surface can't be returned. + // this case the BackBuffer surface can't be returned. if (IsBack && (DDSD_Prim.dwBackBufferCount > 1) && (lpddsc->dwCaps & DDSCAPS_BACKBUFFER)){ - //if (IsBack && (DDSD_Prim.dwBackBufferCount > 1)){ - *lplpddas = lpDDSBack; - OutTraceDW("GetAttachedSurface(%d): DOUBLEBUFFER attached to BACK=%x\n", dxversion, *lplpddas); + *lplpddas = lpdds; + OutTraceDW("GetAttachedSurface(%d): DOUBLEBUFFER attached to BACK=%x\n", dxversion, lpdds); return DD_OK; } - // on primary surface return the lpDDSBack surface coming from either an explicit + // on primary surface return the backbuffer surface coming from either an explicit // AddAttachedSurface, or a primary complex surface creation otherwise.... if(IsPrim && (lpddsc->dwCaps & (DDSCAPS_BACKBUFFER|DDSCAPS_FLIP))) { // v2.02.42 added DDSCAPS_FLIP for Empire Earth @@ -3155,6 +3135,7 @@ HRESULT WINAPI extFlip(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWSURFACE lpddssrc, HRESULT res; DDSURFACEDESC2 ddsd; LPDIRECTDRAWSURFACE lpddsTmp; + LPDIRECTDRAWSURFACE lpDDSBack; IsPrim=dxw.IsAPrimarySurface(lpdds); OutTraceDDRAW("Flip: lpdds=%x%s, src=%x, flags=%x(%s)\n", @@ -3197,6 +3178,8 @@ HRESULT WINAPI extFlip(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWSURFACE lpddssrc, if((dwflags & DDFLIP_WAIT) || (dxw.dwFlags1 & SAVELOAD)) lpPrimaryDD->WaitForVerticalBlank(DDWAITVB_BLOCKEND , 0); + lpDDSBack = dxw.GetBackBufferSurface(); + if(dxw.dwFlags4 & NOFLIPEMULATION){ HRESULT res2; // create a temporary working surface @@ -3245,8 +3228,6 @@ HRESULT WINAPI extFlip(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWSURFACE lpddssrc, res=sBlt("Flip", lpdds, NULL, lpddssrc, NULL, DDBLT_WAIT, 0, TRUE); } else{ - //v2.02.38: look for a valid BackBuffer surface - if(!lpDDSBack) lpDDSBack=dxw.GetBackBufferSurface(); if(!lpDDSBack){ OutTraceE("Flip: no backbuffer\n"); return DDERR_INVALIDPARAMS; @@ -3437,6 +3418,7 @@ HRESULT WINAPI extSetPalette(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWPALETTE lpdd if((dxw.dwFlags1 & EMULATESURFACE) && isPrim){ OutTraceDW("SetPalette: register PRIMARY palette lpDDP=%x\n", lpddp); lpDDP = lpddp; + LPDIRECTDRAWSURFACE lpDDSBack; if(lpddp){ HRESULT res2; lpentries = (LPPALETTEENTRY)PaletteEntries; @@ -3445,6 +3427,7 @@ HRESULT WINAPI extSetPalette(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWPALETTE lpdd mySetPalette(0, 256, lpentries); // v2.02.76: necessary for "Requiem Avenging Angel" in SURFACEEMULATION mode } // Apply palette to backbuffer surface. This is necessary on some games: "Duckman private dick", "Total Soccer 2000", ... + lpDDSBack = dxw.GetBackBufferSurface(); if (lpDDSBack){ OutTraceDW("SetPalette: apply PRIMARY palette lpDDP=%x to DDSBack=%x\n", lpddp, lpDDSBack); res=(*pSetPalette)(lpDDSBack, lpddp); @@ -3504,7 +3487,7 @@ HRESULT WINAPI extSetClipper(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWCLIPPER lpdd if(dxw.dwFlags1 & (EMULATESURFACE|EMULATEBUFFER)){ if ((isPrim && lpDDSEmu_Prim) || - ((lpdds == lpDDSBack) && lpDDSEmu_Back)){ + (dxw.IsABackBufferSurface(lpdds) && lpDDSEmu_Back)){ OutTraceDW("SetClipper: skip primary/backbuffer lpdds=%x\n", lpdds); res=0; } @@ -4139,7 +4122,7 @@ HRESULT WINAPI extReleaseS(LPDIRECTDRAWSURFACE lpdds) // erase surface from primary or backbuffer list // v2-03-20: d3d 1-7 play a dirty trick: it Release the surface passed as argument until refcount == 0, // but then rebuilds it with the original attributes! So, better not forget them. - if(!bIsWithinD3DCreateDevice && (IsPrim || IsBack)) dxw.MarkRegularSurface(lpdds); + if(IsPrim || IsBack) dxw.UnrefSurface(lpdds); // when releasing primary surface, erase clipping region if(IsPrim && (dxw.dwFlags1 & CLIPCURSOR)) dxw.EraseClipCursor(); @@ -4154,15 +4137,11 @@ HRESULT WINAPI extReleaseS(LPDIRECTDRAWSURFACE lpdds) OutTraceDW("Release(S): Clearing lpDDSEmu_Back pointer\n"); lpDDSEmu_Back=NULL; } - if(lpdds==dxw.lpDDSPrimHDC) { - OutTraceDW("Release(S): Clearing lpDDSPrimHDC pointer\n"); + if(lpdds==dxw.lpDDSPrimary) { + OutTraceDW("Release(S): Clearing lpDDSPrimary pointer\n"); dxw.ResetPrimarySurface(); } } - if(lpdds==lpDDSBack) { // v2.02.38 - OutTraceDW("Release(S): Clearing lpDDSBack pointer\n"); - lpDDSBack = NULL; - } } if(dxw.dwFlags4 & RETURNNULLREF) return 0; @@ -4215,6 +4194,7 @@ HRESULT WINAPI extEnumAttachedSurfaces(LPDIRECTDRAWSURFACE lpdds, LPVOID lpConte lpdds, (IsPrim ? "(PRIM)":""), lpContext, lpEnumSurfacesCallback); if (IsPrim){ + LPDIRECTDRAWSURFACE lpDDSBack; // A Primary surface has not backbuffer attached surfaces actually, // so don't rely on ddraw and call the callback function directly. // Needed to make Nox working. @@ -4223,7 +4203,7 @@ HRESULT WINAPI extEnumAttachedSurfaces(LPDIRECTDRAWSURFACE lpdds, LPVOID lpConte res=(*pEnumAttachedSurfaces)(lpdds, lpContext, lpEnumSurfacesCallback); if (res) OutTraceE("EnumAttachedSurfaces: ERROR %x(%s) at %d\n", res, ExplainDDError(res), __LINE__); - if(lpDDSBack){ + if(lpDDSBack = dxw.GetBackBufferSurface()){ ddsd.dwSize=Set_dwSize_From_Surface(lpDDSBack); res=lpDDSBack->GetSurfaceDesc((LPDDSURFACEDESC)&ddsd); if(res){ @@ -4276,7 +4256,7 @@ HRESULT WINAPI extAddAttachedSurface(LPDIRECTDRAWSURFACE lpdds, LPDIRECTDRAWSURF if ((dxw.dwFlags1 & EMULATESURFACE) && (res==DDERR_CANNOTATTACHSURFACE) || (res==DDERR_NOEXCLUSIVEMODE)) OutTraceDW("AddAttachedSurface: emulating BACKBUFFER attach on PRIMARY\n"); - lpDDSBack=lpddsadd; + dxw.MarkBackBufferSurface(lpddsadd, 1); if (pAddRefS) (*pAddRefS)(lpdds); res=DD_OK; } @@ -4302,11 +4282,9 @@ HRESULT WINAPI extDeleteAttachedSurface(LPDIRECTDRAWSURFACE lpdds, DWORD dwflag OutTraceDDRAW("DeleteAttachedSurface: lpdds=%x flags=%x lpddsdel=%x\n", lpdds, dwflags, lpddsdel); res=(*pDeleteAttachedSurface)(lpdds, dwflags, lpddsdel); if(res) OutTraceE("DeleteAttachedSurface: ERROR %x(%s)\n", res, ExplainDDError(res)); - if (res && (lpddsdel==lpDDSBack)){ + if (res && dxw.IsABackBufferSurface(lpddsdel)){ OutTraceDW("DeleteAttachedSurface: emulating surface detach lpdds=%x\n", lpddsdel); - lpDDSBack->Release(); // GHO TRY - lpDDSBack=NULL; - res=0; + res = DD_OK; } return res; } @@ -4406,7 +4384,7 @@ ULONG WINAPI extReleaseD(LPDIRECTDRAW lpdd) if(dxw.dwFlags4 & FIXREFCOUNTER){ // v2.02.41: fix the ref counter to sumulate the unwindowed original situation --VirtualRef; // why ???? - if(lpDDSBack) --VirtualRef; + if(dxw.GetBackBufferSurface()) --VirtualRef; if(dxw.dwFlags1 & EMULATESURFACE){ if(lpDDSEmu_Prim) --VirtualRef; if(lpDDSEmu_Back) --VirtualRef; @@ -4421,10 +4399,6 @@ ULONG WINAPI extReleaseD(LPDIRECTDRAW lpdd) lpDDSEmu_Back=NULL; lpDDP=NULL; lpPrimaryDD=NULL; // v2.02.31 - if(lpBackBufferDD==lpdd){ - lpBackBufferDD=NULL; - lpDDSBack=NULL; // beware: Silent Hunter II seems to require the backbuffer .... - } } } diff --git a/dll/ddshot.cpp b/dll/ddshot.cpp index 99bc908..e3c0e49 100644 --- a/dll/ddshot.cpp +++ b/dll/ddshot.cpp @@ -39,8 +39,7 @@ void DDrawScreenShot() } if(dxw.dwFlags5 & GDIMODE){ - extern LPDIRECTDRAWSURFACE lpDDSBack; - s = lpDDSBack; + s = dxw.GetBackBufferSurface(); } else{ s = dxw.GetPrimarySurface(); diff --git a/dll/ddtexture.cpp b/dll/ddtexture.cpp index 287b416..b1bfc13 100644 --- a/dll/ddtexture.cpp +++ b/dll/ddtexture.cpp @@ -114,8 +114,7 @@ void TextureHighlight(LPDIRECTDRAWSURFACE s) OutTraceE("TextureHigh: Lock ERROR res=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__); return; } - extern LPDIRECTDRAWSURFACE lpDDSBack; - if((ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE) && (s != lpDDSBack)) { + if((ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE) && !dxw.IsABackBufferSurface(s)) { OutTrace("TextureHigh: lpdds=%x BitCount=%d size=(%dx%d)\n", s, ddsd.ddpfPixelFormat.dwRGBBitCount, ddsd.dwWidth, ddsd.dwHeight); w = ddsd.dwWidth; @@ -205,8 +204,7 @@ static void TextureDump(LPDIRECTDRAWSURFACE s) return; } - extern LPDIRECTDRAWSURFACE lpDDSBack; - if((ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE) && (s != lpDDSBack)) while (TRUE) { + if((ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE) && !dxw.IsABackBufferSurface(s)) while (TRUE) { OutTrace("TextureDump: lpdds=%x BitCount=%d size=(%dx%d)\n", s, ddsd.ddpfPixelFormat.dwRGBBitCount, ddsd.dwWidth, ddsd.dwHeight); w = ddsd.dwWidth; @@ -320,8 +318,7 @@ static void TextureHack(LPDIRECTDRAWSURFACE s) OutTraceE("TextureHack: Lock ERROR res=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__); return; } - extern LPDIRECTDRAWSURFACE lpDDSBack; - if((ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE) && (s != lpDDSBack)) while (TRUE) { // fake loop to ensure final Unlock + if((ddsd.ddsCaps.dwCaps & DDSCAPS_TEXTURE) && !dxw.IsABackBufferSurface(s)) while (TRUE) { // fake loop to ensure final Unlock OutTrace("TextureHack: lpdds=%x BitCount=%d size=(%dx%d)\n", s, ddsd.ddpfPixelFormat.dwRGBBitCount, ddsd.dwWidth, ddsd.dwHeight); w = ddsd.dwWidth; diff --git a/dll/dxhook.cpp b/dll/dxhook.cpp index 6bccee1..904865e 100644 --- a/dll/dxhook.cpp +++ b/dll/dxhook.cpp @@ -1983,7 +1983,7 @@ void HookLibrary(HMODULE hModule, HookEntry_Type *Hooks, char *DLLName) } Hooks->OriginalAddress=(*pGetProcAddress)(hDLL, Hooks->APIName); if(!Hooks->OriginalAddress) { - OutTrace("HookLibrary: GetProcAddress failed on API=%s err=%x\n", Hooks->APIName, GetLastError()); + OutTraceB("HookLibrary: GetProcAddress failed on API=%s err=%x\n", Hooks->APIName, GetLastError()); continue; } } diff --git a/dll/dxwcore.cpp b/dll/dxwcore.cpp index a04b9bc..9d22e18 100644 --- a/dll/dxwcore.cpp +++ b/dll/dxwcore.cpp @@ -8,6 +8,12 @@ #include "resource.h" #include "d3d9.h" +#if 1 +#define OutTraceSDB OutTrace +#else +#define OutTraceSDB if(0) OutTrace +#endif + /* ------------------------------------------------------------------ */ // Internal function pointers /* ------------------------------------------------------------------ */ @@ -40,8 +46,8 @@ dxwCore::dxwCore() bActive = TRUE; bDInputAbs = 0; TimeShift = 0; - lpDDSPrimHDC = NULL; - memset(PrimSurfaces, 0, sizeof(PrimSurfaces)); + lpDDSPrimary = NULL; + memset(SurfaceDB, 0, sizeof(SurfaceDB)); ResetEmulatedDC(); MustShowOverlay=FALSE; TimerEvent.dwTimerType = TIMER_TYPE_NONE; @@ -228,16 +234,57 @@ void dxwCore::DumpDesktopStatus() // Primary surfaces auxiliary functions /* ------------------------------------------------------------------ */ +//#define DXW_SURFACE_STACK_TRACING + +static char *sRole(USHORT role) +{ + char *s; + switch (role){ + case 0: s="(NULL)"; break; // should never happen ... + case SURFACE_ROLE_PRIMARY: s="(PRIM)"; break; + case SURFACE_ROLE_BACKBUFFER: s="(BACK)"; break; + default: s="??"; break; // should never happen ... + } + return s; +} + +#ifdef DXW_SURFACE_STACK_TRACING +static void CheckSurfaceList(SurfaceDB_Type *SurfaceDB) +{ + char sMsg[81]; + int iPCount = 0; + int iBCount = 0; + for (int i=0;i 1) { + sprintf(sMsg, "Primary count = %d", iPCount); + MessageBox(0, sMsg, "DxWnd SurfaceList", MB_OK | MB_ICONEXCLAMATION); + } + if(iBCount > 1) { + sprintf(sMsg, "Backbuffer count = %d", iPCount); + MessageBox(0, sMsg, "DxWnd SurfaceList", MB_OK | MB_ICONEXCLAMATION); + } +} + +static void DumpSurfaceList(SurfaceDB_Type *SurfaceDB) +{ + for (int i=0;i>> SURFACELIST CLEAR ALL\n"); +#endif + for (int i=0;i>> SURFACELIST UNREF: lpdds=%x%s ref=%x vers=%d\n", ps, sRole(SurfaceDB[i].uRole), SurfaceDB[i].uRef, SurfaceDB[i].uVersion); +#endif + SurfaceDB[i].uRef = FALSE; } +#ifdef DXW_SURFACE_STACK_TRACING + DumpSurfaceList(SurfaceDB); +#endif } -void dxwCore::MarkPrimarySurface(LPDIRECTDRAWSURFACE ps) +void dxwCore::MarkSurfaceByRole(LPDIRECTDRAWSURFACE ps, USHORT role, USHORT version) { int i; - // OutTraceDW("PRIMARYSURFACE add %x\n",ps); + SurfaceDB_Type *e; +#ifdef DXW_SURFACE_STACK_TRACING + OutTraceSDB(">>> SURFACELIST MARK: lpdds=%x%s vers=%d\n", ps, sRole(role), version); +#endif for (i=0;ilpdds==ps) || (e->lpdds==(DWORD)0)) break; // got matching entry or end of the list } - PrimSurfaces[i]=(DWORD)ps; - UnmarkBackBufferSurface(ps); + if(i == DDSQLEN) { + MessageBox(0, "Surface stack is full", "DxWnd SurfaceList", MB_OK | MB_ICONEXCLAMATION); + return; + } + e->lpdds=ps; + e->uRole = role; + e->uRef = TRUE; + e->uVersion = version; +#ifdef DXW_SURFACE_STACK_TRACING + DumpSurfaceList(SurfaceDB); +#endif +} + +void dxwCore::MarkPrimarySurface(LPDIRECTDRAWSURFACE ps, int version) +{ + MarkSurfaceByRole(ps, SURFACE_ROLE_PRIMARY, (USHORT)version); } -void dxwCore::MarkBackBufferSurface(LPDIRECTDRAWSURFACE ps) +void dxwCore::MarkBackBufferSurface(LPDIRECTDRAWSURFACE ps, int version) { - int i; - // OutTraceDW("PRIMARYSURFACE add %x\n",ps); - for (i=0;i>> SURFACELIST CLEAR: i=%d lpdds=%x%s ref=%x vers=%d\n", + i, ps, sRole(SurfaceDB[i].uRole), SurfaceDB[i].uRef, SurfaceDB[i].uVersion); +#endif + for (; ix; +// r.right = lpPoint->x + *SizX; +// r.top = lpPoint->y; +// r.bottom = lpPoint->y + *SizY; +// r = MapClientRect(&r); +// lpPoint->x = r.left; +// lpPoint->y = r.top; +// *SizX = r.right - r.left; +// *SizY = r.bottom - r.top; +// return NULL; +//} + void dxwCore::MapClient(LPRECT rect) { RECT client; diff --git a/dll/dxwcore.hpp b/dll/dxwcore.hpp index d20e47a..373774e 100644 --- a/dll/dxwcore.hpp +++ b/dll/dxwcore.hpp @@ -1,7 +1,7 @@ #include #include "syslibs.h" -#define DDSQLEN 0x10 +#define DDSQLEN 0x20 typedef struct { DWORD dwTimerType; @@ -23,6 +23,18 @@ typedef struct { } t; } TimerEvent_Type; +typedef struct { + LPDIRECTDRAWSURFACE lpdds; + USHORT uRef; + USHORT uRole; + USHORT uVersion; +} SurfaceDB_Type; + +typedef enum { + SURFACE_ROLE_PRIMARY = 1, + SURFACE_ROLE_BACKBUFFER +} Enum_Surface_Role_Type; + class dxwCore { // Construction/destruction @@ -80,10 +92,12 @@ public: // methods BOOL ishWndFPS(HWND); DWORD GetTickCount(void); char *ExplainSurfaceRole(LPDIRECTDRAWSURFACE); - void MarkPrimarySurface(LPDIRECTDRAWSURFACE); + void ClearSurfaceList(); + void MarkPrimarySurface(LPDIRECTDRAWSURFACE, int); BOOL IsAPrimarySurface(LPDIRECTDRAWSURFACE); + void UnrefSurface(LPDIRECTDRAWSURFACE); LPDIRECTDRAWSURFACE GetPrimarySurface(void); - void MarkBackBufferSurface(LPDIRECTDRAWSURFACE); + void MarkBackBufferSurface(LPDIRECTDRAWSURFACE, int); BOOL IsABackBufferSurface(LPDIRECTDRAWSURFACE); LPDIRECTDRAWSURFACE GetBackBufferSurface(void); void MarkRegularSurface(LPDIRECTDRAWSURFACE); @@ -150,7 +164,7 @@ public: // simple data variables DWORD SwapEffect; char *gsModules; int TimeShift; - LPDIRECTDRAWSURFACE lpDDSPrimHDC; + LPDIRECTDRAWSURFACE lpDDSPrimary; short iPosX; short iPosY; short iSizX; @@ -173,14 +187,16 @@ protected: DWORD dwScreenHeight; BOOL FullScreen; HWND hWnd, hWndFPS; - DWORD PrimSurfaces[DDSQLEN+1]; - DWORD BackSurfaces[DDSQLEN+1]; + SurfaceDB_Type SurfaceDB[DDSQLEN+1]; + //DWORD PrimSurfaces[DDSQLEN+1]; + //DWORD BackSurfaces[DDSQLEN+1]; HBITMAP VirtualPic; RECT VirtualPicRect; private: - void UnmarkPrimarySurface(LPDIRECTDRAWSURFACE); - void UnmarkBackBufferSurface(LPDIRECTDRAWSURFACE); + void MarkSurfaceByRole(LPDIRECTDRAWSURFACE, USHORT, USHORT); + LPDIRECTDRAWSURFACE GetSurfaceByRole(USHORT); + void SetSurfaceEntry(LPDIRECTDRAWSURFACE, USHORT, USHORT); BOOL MustShowOverlay; void ShowFPS(HDC, int, int); void ShowTimeStretching(HDC, int, int); diff --git a/dll/dxwnd.cpp b/dll/dxwnd.cpp index e648d73..6d67180 100644 --- a/dll/dxwnd.cpp +++ b/dll/dxwnd.cpp @@ -27,7 +27,7 @@ along with this program. If not, see . #include "TlHelp32.h" -#define VERSION "2.03.20" +#define VERSION "2.03.21" #define DDTHREADLOCK 1 //#define LOCKTHREADS diff --git a/dll/dxwnd.vs2008.suo b/dll/dxwnd.vs2008.suo index 38ac928..7606983 100644 Binary files a/dll/dxwnd.vs2008.suo and b/dll/dxwnd.vs2008.suo differ diff --git a/dll/gdi32.cpp b/dll/gdi32.cpp index 5b54315..2a33432 100644 --- a/dll/gdi32.cpp +++ b/dll/gdi32.cpp @@ -655,13 +655,13 @@ HDC WINAPI extDDCreateCompatibleDC(HDC hdc) if(dxw.IsDesktop(WindowFromDC(hdc)) && dxw.IsFullScreen()) { dxw.SetPrimarySurface(); - if(!PrimHDC && dxw.lpDDSPrimHDC){ + if(!PrimHDC && dxw.lpDDSPrimary){ HRESULT res; STOPPER("null PrimHDC"); - res=(*pGetDC)(dxw.lpDDSPrimHDC, &PrimHDC); - if(res) OutTraceE("GDI.CreateCompatibleDC ERROR: GetDC lpdds=%x err=%d(%s) at %d\n", dxw.lpDDSPrimHDC, res, ExplainDDError(res), __LINE__); + res=(*pGetDC)(dxw.lpDDSPrimary, &PrimHDC); + if(res) OutTraceE("GDI.CreateCompatibleDC ERROR: GetDC lpdds=%x err=%d(%s) at %d\n", dxw.lpDDSPrimary, res, ExplainDDError(res), __LINE__); } - OutTraceDW("GDI.CreateCompatibleDC: duplicating primary surface HDC lpDDSPrimHDC=%x SrcHdc=%x\n", dxw.lpDDSPrimHDC, PrimHDC); + OutTraceDW("GDI.CreateCompatibleDC: duplicating primary surface HDC lpDDSPrimary=%x SrcHdc=%x\n", dxw.lpDDSPrimary, PrimHDC); RetHdc=(*pGDICreateCompatibleDC)(PrimHDC); } else @@ -698,21 +698,21 @@ static HDC WINAPI winDDGetDC(HWND hwnd, char *api) dxw.SetPrimarySurface(); if(dxw.IsRealDesktop(hwnd)) hwnd=dxw.GethWnd(); - if(dxw.lpDDSPrimHDC){ + if(dxw.lpDDSPrimary){ if (PrimHDC){ OutTraceDW("%s: reusing primary hdc\n", api); - (*pUnlockMethod(dxw.lpDDSPrimHDC))(dxw.lpDDSPrimHDC, NULL); + (*pUnlockMethod(dxw.lpDDSPrimary))(dxw.lpDDSPrimary, NULL); hdc=PrimHDC; } else{ - OutTraceDW("%s: get hdc from PRIMARY surface lpdds=%x\n", api, dxw.lpDDSPrimHDC); - res=extGetDC(dxw.lpDDSPrimHDC,&hdc); + OutTraceDW("%s: get hdc from PRIMARY surface lpdds=%x\n", api, dxw.lpDDSPrimary); + res=extGetDC(dxw.lpDDSPrimary,&hdc); if(res) { - OutTraceE("%s: GetDC(%x) ERROR %x(%s) at %d\n", api, dxw.lpDDSPrimHDC, res, ExplainDDError(res), __LINE__); + OutTraceE("%s: GetDC(%x) ERROR %x(%s) at %d\n", api, dxw.lpDDSPrimary, res, ExplainDDError(res), __LINE__); if(res==DDERR_DCALREADYCREATED){ // try recovery.... - (*pReleaseDC)(dxw.lpDDSPrimHDC,NULL); - res=extGetDC(dxw.lpDDSPrimHDC,&hdc); + (*pReleaseDC)(dxw.lpDDSPrimary,NULL); + res=extGetDC(dxw.lpDDSPrimary,&hdc); } if(res)return 0; } @@ -787,9 +787,9 @@ int WINAPI extDDReleaseDC(HWND hwnd, HDC hDC) res=0; if ((hDC == PrimHDC) || (hwnd==0)){ dxw.SetPrimarySurface(); - OutTraceDW("GDI.ReleaseDC(DD): refreshing primary surface lpdds=%x\n",dxw.lpDDSPrimHDC); - if(!dxw.lpDDSPrimHDC) return 0; - extReleaseDC(dxw.lpDDSPrimHDC, hDC); + OutTraceDW("GDI.ReleaseDC(DD): refreshing primary surface lpdds=%x\n",dxw.lpDDSPrimary); + if(!dxw.lpDDSPrimary) return 0; + extReleaseDC(dxw.lpDDSPrimary, hDC); PrimHDC=NULL; res=1; // 1 = OK } @@ -817,7 +817,7 @@ BOOL WINAPI extDDBitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHe if(hdcDest==0) { dxw.ResetPrimarySurface(); dxw.SetPrimarySurface(); - extGetDC(dxw.lpDDSPrimHDC, &PrimHDC); + extGetDC(dxw.lpDDSPrimary, &PrimHDC); hdcDest=PrimHDC; } res=(*pGDIBitBlt)(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop); @@ -847,7 +847,7 @@ BOOL WINAPI extDDStretchBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int // if(hdcDest==0) { // dxw.ResetPrimarySurface(); // dxw.SetPrimarySurface(); - // extGetDC(dxw.lpDDSPrimHDC, &PrimHDC); + // extGetDC(dxw.lpDDSPrimary, &PrimHDC); // hdcDest=PrimHDC; // } //} @@ -861,9 +861,9 @@ BOOL WINAPI extDDStretchBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int } } //dxw.SetPrimarySurface(); - //OutTraceDW("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); + //OutTraceDW("GDI.StretchBlt: refreshing primary surface lpdds=%x\n",dxw.lpDDSPrimary); + //sBlt("GDI.StretchBlt", dxw.lpDDSPrimary, NULL, dxw.lpDDSPrimary, NULL, 0, NULL, 0); + //res=(*pUnlockMethod(dxw.lpDDSPrimary))(dxw.lpDDSPrimary, NULL); return ret; } diff --git a/dll/hd3d7.cpp b/dll/hd3d7.cpp index 04869a2..2b81865 100644 --- a/dll/hd3d7.cpp +++ b/dll/hd3d7.cpp @@ -927,26 +927,18 @@ HRESULT WINAPI extCreateDevice7(void *lpd3d, REFCLSID Guid, LPDIRECTDRAWSURFACE7 { // v2.02.83: D3D CreateDevice (version 7? all versions?) internally calls the Release method upon the backbuffer // surface, and this has to be avoided since it causes a crash. - // The bIsWithinD3DCreateDevice boolean tells extReleaseS NOT to perform an actual release operation. - // v2.03.20: also, D3D CreateDevice internally Release the primary surface lpdds and builds a new primary - // using the same lpdds value, but issuing a QueryInterface call upon a zero-referenced object! HRESULT res; - extern BOOL bIsWithinD3DCreateDevice; OutTraceD3D("CreateDevice(D3D7): d3d=%x GUID=%x(%s) lpdds=%x%s\n", lpd3d, Guid.Data1, ExplainGUID((GUID *)&Guid), lpdds, dxw.ExplainSurfaceRole((LPDIRECTDRAWSURFACE)lpdds)); - bIsWithinD3DCreateDevice = TRUE; res=(*pCreateDevice7)(lpd3d, Guid, lpdds, lplpd3dd); - bIsWithinD3DCreateDevice = FALSE; if(res) { OutTraceE("CreateDevice(D3D7) ERROR: err=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__); if((dxw.dwFlags1 & AUTOMATIC) && (dxw.dwFlags1 & EMULATESURFACE)) { dxw.dwFlags1 &= ~EMULATESURFACE; dxw.dwFlags1 |= LOCKEDSURFACE; - bIsWithinD3DCreateDevice = TRUE; res=(*pCreateDevice7)(lpd3d, Guid, lpdds, lplpd3dd); - bIsWithinD3DCreateDevice = FALSE; if (res) OutTraceE("CreateDevice(D3D7) ERROR: err=%x(%s) at %d\n", res, ExplainDDError(res), __LINE__); else OutTraceD3D("CreateDevice(D3D7): Emulation OFF\n"); } diff --git a/dll/user32.cpp b/dll/user32.cpp index 7e1262c..f045db9 100644 --- a/dll/user32.cpp +++ b/dll/user32.cpp @@ -741,15 +741,45 @@ BOOL WINAPI extSetWindowPos(HWND hwnd, HWND hWndInsertAfter, int X, int Y, int c OutTraceDW("SetWindowPos: hwnd=%x%s pos=(%d,%d) dim=(%d,%d) Flags=%x\n", hwnd, dxw.IsFullScreen()?"(FULLSCREEN)":"", X, Y, cx, cy, uFlags); - //if ((hwnd != dxw.GethWnd()) || !dxw.IsFullScreen()){ - if (!dxw.IsDesktop(hwnd) || !dxw.IsFullScreen()){ - // just proxy + // when not in fullscreen mode, just proxy the call + if (!dxw.IsFullScreen()){ res=(*pSetWindowPos)(hwnd, hWndInsertAfter, X, Y, cx, cy, uFlags); if(!res)OutTraceE("SetWindowPos: ERROR err=%d at %d\n", GetLastError(), __LINE__); return res; } - if ((dxw.dwFlags1 & LOCKWINPOS) && dxw.IsFullScreen()){ + // in fullscreen, but a child window inside ..... + if (!dxw.IsDesktop(hwnd)){ + RECT r; + r.left = X; + r.right = X + cx; + r.top = Y; + r.bottom = Y + cy; + if ((*pGetWindowLongA)(hwnd, GWL_STYLE) & WS_CHILD){ + r = dxw.MapClientRect(&r); + } + else { + //r = dxw.MapWindowRect(&r); + } + X = r.left; + Y = r.top; + cx = r.right - r.left; + cy = r.bottom - r.top; + + res=(*pSetWindowPos)(hwnd, hWndInsertAfter, X, Y, cx, cy, uFlags); + if(!res)OutTraceE("SetWindowPos: ERROR err=%d at %d\n", GetLastError(), __LINE__); + + //HFONT hFont; + //hFont=CreateFont ( + // 30, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, + // FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + // DEFAULT_PITCH | FF_SWISS, NULL); // "Arial"); + //SendMessage (hwnd, WM_SETFONT, WPARAM (hFont), TRUE); + + return res; + } + + if (dxw.dwFlags1 & LOCKWINPOS){ // Note: any attempt to change the window position, no matter where and how, through the // SetWindowPos API is causing resizing to the default 1:1 pixed size in Commandos. // in such cases, there is incompatibility between LOCKWINPOS and LOCKWINSTYLE. @@ -2019,7 +2049,7 @@ HDC WINAPI extBeginPaint(HWND hwnd, LPPAINTSTRUCT lpPaint) break; case GDIMODE_DIRECTDRAW: (*pGDIReleaseDC)(hwnd, lpPaint->hdc); - (*pGetDC)(dxw.lpDDSPrimHDC,&PrimHDC); + (*pGetDC)(dxw.lpDDSPrimary,&PrimHDC); lpPaint->hdc=PrimHDC; // resize the paint area to virtual screen size (see CivIII clipped panels...) lpPaint->rcPaint=dxw.GetScreenRect(); @@ -2050,7 +2080,7 @@ HDC WINAPI extDDBeginPaint(HWND hwnd, LPPAINTSTRUCT lpPaint) // on MAPGDITOPRIMARY, return the PrimHDC handle instead of the window DC // if a primary surface has not been created yet, do it - if(!pGetDC || !dxw.lpDDSPrimHDC){ + if(!pGetDC || !dxw.lpDDSPrimary){ extern HRESULT WINAPI extDirectDrawCreate(GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *); HRESULT res; LPDIRECTDRAW lpDD; @@ -2067,11 +2097,11 @@ HDC WINAPI extDDBeginPaint(HWND hwnd, LPPAINTSTRUCT lpPaint) ddsd.dwHeight = dxw.GetScreenHeight(); ddsd.dwWidth = dxw.GetScreenWidth(); res=lpDD->CreateSurface(&ddsd, &lpDDS, NULL); - dxw.lpDDSPrimHDC = lpDDS; + dxw.lpDDSPrimary = lpDDS; OutTraceDW("GDI.BeginPaint(MAPGDITOPRIMARY): dd=%x ddsPrim=%x\n", lpDD, lpDDS); } - extGetDC(dxw.lpDDSPrimHDC,&PrimHDC); + extGetDC(dxw.lpDDSPrimary,&PrimHDC); lpPaint->hdc=PrimHDC; // resize the paint area to virtual screen size (see CivIII clipped panels...) lpPaint->rcPaint=dxw.GetScreenRect(); @@ -2131,7 +2161,7 @@ BOOL WINAPI extDDEndPaint(HWND hwnd, const PAINTSTRUCT *lpPaint) RECT Rect; LPRECT lpRect; ret=(*pEndPaint)(hwnd, lpPaint); - dxw.lpDDSPrimHDC->Unlock(NULL); + dxw.lpDDSPrimary->Unlock(NULL); //dxw.ScreenRefresh(); if(dxw.IsDesktop(hwnd)) lpRect=NULL; @@ -2152,7 +2182,7 @@ BOOL WINAPI extDDEndPaint(HWND hwnd, const PAINTSTRUCT *lpPaint) Rect = dxw.MapClientRect(lpRect); #endif } - extBlt(dxw.lpDDSPrimHDC, lpRect, dxw.lpDDSPrimHDC, NULL, 0, NULL); + extBlt(dxw.lpDDSPrimary, lpRect, dxw.lpDDSPrimary, NULL, 0, NULL); return TRUE; }