From eb2aea96acb84e40cc1997b35154d885a2321f5e Mon Sep 17 00:00:00 2001 From: AyuanX Date: Thu, 7 Apr 2022 21:31:23 +1000 Subject: [PATCH] Format cleanup --- README.md | 4 +- classfactory.cpp | 26 +++---- clipper.cpp | 34 ++++----- color.cpp | 28 +++---- dd.cpp | 102 +++++++++++++------------- dds.cpp | 179 ++++++++++++++++++++++----------------------- dllmain.cpp | 110 ++++++++++++---------------- gama.cpp | 24 +++--- header.h | 2 - log.cpp | 31 ++++---- log.h | 5 +- palette.cpp | 22 +++--- resource/ddraw.ini | 3 + unknwn.cpp | 24 +++--- wrap.cpp | 83 +++++++++------------ wrap.h | 12 +-- 16 files changed, 321 insertions(+), 368 deletions(-) diff --git a/README.md b/README.md index a30cee0..a425e99 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ Tip: If the game is not utilizing DirectDraw 8-bit (256 colors) palette mode, th # Revisions: -v.2022.04.06: -- Configurable flip and throttle. +v.2022.04.07: +- Configurable flip, buffer and throttle. - Improve performance. - Improve compatibility. - Proper release sequence. diff --git a/classfactory.cpp b/classfactory.cpp index f9b9dcb..051b1ec 100644 --- a/classfactory.cpp +++ b/classfactory.cpp @@ -4,29 +4,29 @@ namespace classfactory { struct XVTBL { - HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); - ULONG (__stdcall * AddRef)( WRAP* This ); - ULONG (__stdcall * Release)( WRAP* This ); + HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); + ULONG (__stdcall * AddRef)( WRAP* This ); + ULONG (__stdcall * Release)( WRAP* This ); HRESULT (__stdcall * CreateInstance)( WRAP* This, IUnknown *pUnkOuter, REFIID riid, void **ppvObject ); HRESULT (__stdcall * LockServer)( WRAP* This, BOOL fLock ); }; - HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) - { + HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) + { PROLOGUE; HRESULT hResult = This->cf->lpVtbl->QueryInterface( This->cf, riid, ppvObject ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( riid ), ppvObject ); EPILOGUE( hResult ); } - ULONG __stdcall AddRef( WRAP* This ) - { + ULONG __stdcall AddRef( WRAP* This ) + { PROLOGUE; ULONG dwCount = This->cf->lpVtbl->AddRef( This->cf ); EPILOGUE( dwCount ); } - ULONG __stdcall Release( WRAP* This ) + ULONG __stdcall Release( WRAP* This ) { PROLOGUE; ULONG dwCount = WrapRelease( This ); @@ -46,14 +46,14 @@ namespace classfactory PROLOGUE; HRESULT hResult = This->cf->lpVtbl->LockServer( This->cf, fLock ); EPILOGUE( hResult ); - } + } - const XVTBL xVtbl = - { + const XVTBL xVtbl = + { QueryInterface, // 0x00 AddRef, // 0x04 Release, // 0x08 CreateInstance, // 0x0C - LockServer // 0x10 + LockServer, // 0x10 }; -}; \ No newline at end of file +}; diff --git a/clipper.cpp b/clipper.cpp index 64a457d..3715e38 100644 --- a/clipper.cpp +++ b/clipper.cpp @@ -4,9 +4,9 @@ namespace clipper { struct XVTBL { - HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); - ULONG (__stdcall * AddRef)( WRAP* This ); - ULONG (__stdcall * Release)( WRAP* This ); + HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); + ULONG (__stdcall * AddRef)( WRAP* This ); + ULONG (__stdcall * Release)( WRAP* This ); HRESULT (__stdcall * GetClipList)( WRAP* This, LPRECT lpRect, LPRGNDATA lpClipList, LPDWORD lpdwSize ); HRESULT (__stdcall * GetHWnd)( WRAP* This, HWND* lphWnd ); HRESULT (__stdcall * Initialize)( WRAP* This, LPDIRECTDRAW lpDD, DWORD dwFlags ); @@ -15,72 +15,72 @@ namespace clipper HRESULT (__stdcall * SetHWnd)( WRAP* This, DWORD dwFlags, HWND hWnd ); }; - HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) - { + HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) + { PROLOGUE; HRESULT hResult = This->clip->lpVtbl->QueryInterface( This->clip, riid, ppvObject ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( riid ), ppvObject ); EPILOGUE( hResult ); } - ULONG __stdcall AddRef( WRAP* This ) - { + ULONG __stdcall AddRef( WRAP* This ) + { PROLOGUE; ULONG dwCount = This->clip->lpVtbl->AddRef( This->clip ); EPILOGUE( dwCount ); } - ULONG __stdcall Release( WRAP* This ) + ULONG __stdcall Release( WRAP* This ) { PROLOGUE; ULONG dwCount = WrapRelease( This ); EPILOGUE( dwCount ); } - HRESULT __stdcall GetClipList( WRAP* This, LPRECT lpRect, LPRGNDATA lpClipList, LPDWORD lpdwSize ) + HRESULT __stdcall GetClipList( WRAP* This, LPRECT lpRect, LPRGNDATA lpClipList, LPDWORD lpdwSize ) { PROLOGUE; HRESULT hResult = This->clip->lpVtbl->GetClipList( This->clip, lpRect, lpClipList, lpdwSize ); EPILOGUE( hResult ); } - HRESULT __stdcall GetHWnd( WRAP* This, HWND* lphWnd ) + HRESULT __stdcall GetHWnd( WRAP* This, HWND* lphWnd ) { PROLOGUE; HRESULT hResult = This->clip->lpVtbl->GetHWnd( This->clip, lphWnd ); EPILOGUE( hResult ); } - HRESULT __stdcall Initialize( WRAP* This, LPDIRECTDRAW lpDD, DWORD dwFlags ) + HRESULT __stdcall Initialize( WRAP* This, LPDIRECTDRAW lpDD, DWORD dwFlags ) { PROLOGUE; HRESULT hResult = This->clip->lpVtbl->Initialize( This->clip, GetInnerInterface( lpDD ), dwFlags ); EPILOGUE( hResult ); } - HRESULT __stdcall IsClipListChanged( WRAP* This, BOOL* lpbChanged ) + HRESULT __stdcall IsClipListChanged( WRAP* This, BOOL* lpbChanged ) { PROLOGUE; HRESULT hResult = This->clip->lpVtbl->IsClipListChanged( This->clip, lpbChanged ); EPILOGUE( hResult ); } - HRESULT __stdcall SetClipList( WRAP* This, LPRGNDATA lpClipList, DWORD dwFlags ) + HRESULT __stdcall SetClipList( WRAP* This, LPRGNDATA lpClipList, DWORD dwFlags ) { PROLOGUE; HRESULT hResult = This->clip->lpVtbl->SetClipList( This->clip, lpClipList, dwFlags ); EPILOGUE( hResult ); } - HRESULT __stdcall SetHWnd( WRAP* This, DWORD dwFlags, HWND hWnd ) + HRESULT __stdcall SetHWnd( WRAP* This, DWORD dwFlags, HWND hWnd ) { PROLOGUE; HRESULT hResult = This->clip->lpVtbl->SetHWnd( This->clip, dwFlags, hWnd ); EPILOGUE( hResult ); } - const XVTBL xVtbl = - { + const XVTBL xVtbl = + { QueryInterface, // 0x00 AddRef, // 0x04 Release, // 0x08 @@ -89,6 +89,6 @@ namespace clipper Initialize, // 0x14 IsClipListChanged, // 0x18 SetClipList, // 0x1C - SetHWnd // 0x20 + SetHWnd, // 0x20 }; }; diff --git a/color.cpp b/color.cpp index 6b562cb..e6018a0 100644 --- a/color.cpp +++ b/color.cpp @@ -4,29 +4,29 @@ namespace color { struct XVTBL { - HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); - ULONG (__stdcall * AddRef)( WRAP* This ); - ULONG (__stdcall * Release)( WRAP* This ); + HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); + ULONG (__stdcall * AddRef)( WRAP* This ); + ULONG (__stdcall * Release)( WRAP* This ); HRESULT (__stdcall * GetColorControls)( WRAP* This, LPDDCOLORCONTROL lpColorControl ); HRESULT (__stdcall * SetColorControls)( WRAP* This, LPDDCOLORCONTROL lpColorControl ); }; - HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) - { + HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) + { PROLOGUE; HRESULT hResult = This->color->lpVtbl->QueryInterface( This->color, riid, ppvObject ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( riid ), ppvObject ); EPILOGUE( hResult ); } - ULONG __stdcall AddRef( WRAP* This ) - { + ULONG __stdcall AddRef( WRAP* This ) + { PROLOGUE; ULONG dwCount = This->color->lpVtbl->AddRef( This->color ); EPILOGUE( dwCount ); } - ULONG __stdcall Release( WRAP* This ) + ULONG __stdcall Release( WRAP* This ) { PROLOGUE; ULONG dwCount = WrapRelease( This ); @@ -34,25 +34,25 @@ namespace color } HRESULT __stdcall GetColorControls( WRAP* This, LPDDCOLORCONTROL lpColorControl ) - { + { PROLOGUE; HRESULT hResult = This->color->lpVtbl->GetColorControls( This->color, lpColorControl ); EPILOGUE( hResult ); } - + HRESULT __stdcall SetColorControls( WRAP* This, LPDDCOLORCONTROL lpColorControl ) - { + { PROLOGUE; HRESULT hResult = This->color->lpVtbl->SetColorControls( This->color, lpColorControl ); EPILOGUE( hResult ); } - const XVTBL xVtbl = - { + const XVTBL xVtbl = + { QueryInterface, // 0x00 AddRef, // 0x04 Release, // 0x08 GetColorControls, // 0x0C SetColorControls, // 0x10 }; -}; \ No newline at end of file +}; diff --git a/dd.cpp b/dd.cpp index 1d8a42a..195bf71 100644 --- a/dd.cpp +++ b/dd.cpp @@ -44,22 +44,22 @@ namespace dd HRESULT (__stdcall * EvaluateMode)( WRAP* This, DWORD dwFlags, DWORD *pTimeout ); }; - HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) - { + HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->QueryInterface( This->dd1, riid, ppvObject ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( riid ), ppvObject ); EPILOGUE( hResult ); } - ULONG __stdcall AddRef( WRAP* This ) - { + ULONG __stdcall AddRef( WRAP* This ) + { PROLOGUE; ULONG dwCount = This->dd1->lpVtbl->AddRef( This->dd1 ); - EPILOGUE( dwCount ); + EPILOGUE( dwCount ); } - ULONG __stdcall Release( WRAP* This ) + ULONG __stdcall Release( WRAP* This ) { PROLOGUE; ULONG dwCount = WrapRelease( This ); @@ -70,11 +70,11 @@ namespace dd { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->Compact( This->dd1 ); - EPILOGUE( hResult ); + EPILOGUE( hResult ); } HRESULT __stdcall CreateClipper( WRAP* This, DWORD dwFlags, LPDIRECTDRAWCLIPPER *lplpDDClipper, IUnknown *pUnkOuter ) - { + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->CreateClipper( This->dd1, dwFlags, lplpDDClipper, pUnkOuter ); if( SUCCEEDED( hResult ) ) @@ -84,8 +84,8 @@ namespace dd EPILOGUE( hResult ); } - HRESULT __stdcall CreatePalette( WRAP* This, DWORD dwFlags, LPPALETTEENTRY lpColorTable, LPDIRECTDRAWPALETTE *lplpDDPalette, IUnknown *pUnkOuter ) - { + HRESULT __stdcall CreatePalette( WRAP* This, DWORD dwFlags, LPPALETTEENTRY lpColorTable, LPDIRECTDRAWPALETTE *lplpDDPalette, IUnknown *pUnkOuter ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->CreatePalette( This->dd1, dwFlags, lpColorTable, lplpDDPalette, pUnkOuter ); if( SUCCEEDED( hResult ) ) @@ -95,8 +95,8 @@ namespace dd EPILOGUE( hResult ); } - HRESULT __stdcall CreateSurface( WRAP* This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE *lplpDDSurface, IUnknown *pUnkOuter ) - { + HRESULT __stdcall CreateSurface( WRAP* This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE *lplpDDSurface, IUnknown *pUnkOuter ) + { PROLOGUE; HRESULT hResult; if (dx::enabled) { @@ -162,7 +162,7 @@ namespace dd } HRESULT __stdcall DuplicateSurface( WRAP* This, LPDIRECTDRAWSURFACE lpDDSurface, LPDIRECTDRAWSURFACE *lplpDupDDSurface ) - { + { PROLOGUE; lpDDSurface = GetInnerInterface(lpDDSurface); HRESULT hResult = This->dd1->lpVtbl->DuplicateSurface(This->dd1, lpDDSurface, lplpDupDDSurface); @@ -171,15 +171,15 @@ namespace dd EPILOGUE( hResult ); } - HRESULT __stdcall EnumDisplayModes( WRAP* This, DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback ) - { + HRESULT __stdcall EnumDisplayModes( WRAP* This, DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback ) + { PROLOGUE; - HRESULT hResult = This->dd1->lpVtbl->EnumDisplayModes( This->dd1, dwFlags, lpDDSurfaceDesc, lpContext, lpEnumModesCallback ); + HRESULT hResult = This->dd1->lpVtbl->EnumDisplayModes( This->dd1, dwFlags, lpDDSurfaceDesc, lpContext, lpEnumModesCallback ); EPILOGUE( hResult ); } - HRESULT __stdcall EnumSurfaces( WRAP* This, DWORD dwFlags, LPDDSURFACEDESC lpDDSD, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback ) - { + HRESULT __stdcall EnumSurfaces( WRAP* This, DWORD dwFlags, LPDDSURFACEDESC lpDDSD, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback ) + { PROLOGUE; EnumStruct e; e.callback = (void*)lpEnumSurfacesCallback; @@ -191,36 +191,36 @@ namespace dd EPILOGUE( hResult ); } - HRESULT __stdcall FlipToGDISurface( WRAP* This ) - { + HRESULT __stdcall FlipToGDISurface( WRAP* This ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->FlipToGDISurface( This->dd1 ); EPILOGUE( hResult ); } - HRESULT __stdcall GetCaps( WRAP* This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps ) - { + HRESULT __stdcall GetCaps( WRAP* This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->GetCaps( This->dd1, lpDDDriverCaps, lpDDHELCaps ); EPILOGUE( hResult ); } - HRESULT __stdcall GetDisplayMode( WRAP* This, LPDDSURFACEDESC lpDDSurfaceDesc ) - { + HRESULT __stdcall GetDisplayMode( WRAP* This, LPDDSURFACEDESC lpDDSurfaceDesc ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->GetDisplayMode( This->dd1, lpDDSurfaceDesc ); EPILOGUE( hResult ); } - HRESULT __stdcall GetFourCCCodes( WRAP* This, LPDWORD lpNumCodes, LPDWORD lpCodes ) - { + HRESULT __stdcall GetFourCCCodes( WRAP* This, LPDWORD lpNumCodes, LPDWORD lpCodes ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->GetFourCCCodes( This->dd1, lpNumCodes, lpCodes ); EPILOGUE( hResult ); } HRESULT __stdcall GetGDISurface( WRAP* This, LPDIRECTDRAWSURFACE *lplpGDIDDSurface ) - { + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->GetGDISurface( This->dd1, lplpGDIDDSurface ); INFO("GetGDISurface %08X\n", *lplpGDIDDSurface); @@ -228,42 +228,42 @@ namespace dd EPILOGUE( hResult ); } - HRESULT __stdcall GetMonitorFrequency( WRAP* This, LPDWORD lpdwFrequency ) - { + HRESULT __stdcall GetMonitorFrequency( WRAP* This, LPDWORD lpdwFrequency ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->GetMonitorFrequency( This->dd1, lpdwFrequency ); EPILOGUE( hResult ); } - HRESULT __stdcall GetScanLine( WRAP* This, LPDWORD lpdwScanLine ) - { + HRESULT __stdcall GetScanLine( WRAP* This, LPDWORD lpdwScanLine ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->GetScanLine( This->dd1, lpdwScanLine ); EPILOGUE( hResult ); } - HRESULT __stdcall GetVerticalBlankStatus( WRAP* This, BOOL *lpbIsInVB ) - { + HRESULT __stdcall GetVerticalBlankStatus( WRAP* This, BOOL *lpbIsInVB ) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->GetVerticalBlankStatus( This->dd1, lpbIsInVB ); EPILOGUE( hResult ); } - HRESULT __stdcall Initialize( WRAP* This, GUID *lpGUID ) + HRESULT __stdcall Initialize( WRAP* This, GUID *lpGUID ) { PROLOGUE; - HRESULT hResult = This->dd1->lpVtbl->Initialize( This->dd1, lpGUID ); + HRESULT hResult = This->dd1->lpVtbl->Initialize( This->dd1, lpGUID ); EPILOGUE( hResult ); } HRESULT __stdcall RestoreDisplayMode( WRAP* This ) - { + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->RestoreDisplayMode( This->dd1 ); EPILOGUE( hResult ); } - HRESULT __stdcall SetCooperativeLevel( WRAP* This, HWND hWnd, DWORD dwFlags ) + HRESULT __stdcall SetCooperativeLevel( WRAP* This, HWND hWnd, DWORD dwFlags ) { PROLOGUE; if (dx::NoFlip) dx::caps = 0; @@ -279,8 +279,8 @@ namespace dd } // The signature of SetDisplayMode is different between v1 and v2 - HRESULT __stdcall SetDisplayMode1( WRAP* This, DWORD dwWidth, DWORD dwHeight, DWORD dwBPP ) - { + HRESULT __stdcall SetDisplayMode1( WRAP* This, DWORD dwWidth, DWORD dwHeight, DWORD dwBPP ) + { PROLOGUE; if (dwBPP == 8) { HDC dc = GetDC(NULL); @@ -296,8 +296,8 @@ namespace dd EPILOGUE( hResult ); } - HRESULT __stdcall SetDisplayMode2( WRAP* This, DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwRefreshRate, DWORD dwFlags ) - { + HRESULT __stdcall SetDisplayMode2( WRAP* This, DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwRefreshRate, DWORD dwFlags ) + { PROLOGUE; if (dwBPP == 8) { HDC dc = GetDC(NULL); @@ -313,8 +313,8 @@ namespace dd EPILOGUE( hResult ); } - HRESULT __stdcall WaitForVerticalBlank( WRAP* This, DWORD dwFlags, HANDLE hEvent) - { + HRESULT __stdcall WaitForVerticalBlank( WRAP* This, DWORD dwFlags, HANDLE hEvent) + { PROLOGUE; HRESULT hResult = This->dd1->lpVtbl->WaitForVerticalBlank( This->dd1, dwFlags, hEvent ); EPILOGUE( hResult ); @@ -398,7 +398,7 @@ namespace dd Initialize, // 0x48 RestoreDisplayMode, // 0x4C SetCooperativeLevel, // 0x50 - (void*)SetDisplayMode1, // 0x54 + (void*)SetDisplayMode1, // 0x54 WaitForVerticalBlank, // 0x58 0, // 0x5C 0, // 0x60 @@ -406,7 +406,7 @@ namespace dd 0, // 0x68 0, // 0x6C 0, // 0x70 - 0 // 0x74 + 0, // 0x74 }; const XVTBL xVtbl2 = { @@ -431,7 +431,7 @@ namespace dd Initialize, // 0x48 RestoreDisplayMode, // 0x4C SetCooperativeLevel, // 0x50 - (void*)SetDisplayMode2, // 0x54 + (void*)SetDisplayMode2, // 0x54 WaitForVerticalBlank, // 0x58 GetAvailableVidMem, // 0x5C 0, // 0x60 @@ -439,7 +439,7 @@ namespace dd 0, // 0x68 0, // 0x6C 0, // 0x70 - 0 // 0x74 + 0, // 0x74 }; const XVTBL xVtbl4 = { @@ -464,7 +464,7 @@ namespace dd Initialize, // 0x48 RestoreDisplayMode, // 0x4C SetCooperativeLevel, // 0x50 - (void*)SetDisplayMode2, // 0x54 + (void*)SetDisplayMode2, // 0x54 WaitForVerticalBlank, // 0x58 GetAvailableVidMem, // 0x5C GetSurfaceFromDC, // 0x60 @@ -472,7 +472,7 @@ namespace dd TestCooperativeLevel, // 0x68 GetDeviceIdentifier, // 0x6C 0, // 0x70 - 0 // 0x74 + 0, // 0x74 }; const XVTBL xVtbl7 = { @@ -497,7 +497,7 @@ namespace dd Initialize, // 0x48 RestoreDisplayMode, // 0x4C SetCooperativeLevel, // 0x50 - (void*)SetDisplayMode2, // 0x54 + (void*)SetDisplayMode2, // 0x54 WaitForVerticalBlank, // 0x58 GetAvailableVidMem, // 0x5C GetSurfaceFromDC, // 0x60 @@ -505,6 +505,6 @@ namespace dd TestCooperativeLevel, // 0x68 GetDeviceIdentifier, // 0x6C StartModeTest, // 0x70 - EvaluateMode // 0x74 + EvaluateMode, // 0x74 }; }; diff --git a/dds.cpp b/dds.cpp index cf432e0..e80513c 100644 --- a/dds.cpp +++ b/dds.cpp @@ -4,8 +4,8 @@ namespace dds { struct XVTBL { - HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); - ULONG (__stdcall * AddRef)( WRAP* This ); + HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); + ULONG (__stdcall * AddRef)( WRAP* This ); ULONG (__stdcall * Release)( WRAP* This ); HRESULT (__stdcall * AddAttachedSurface)( WRAP* This, LPDIRECTDRAWSURFACE lpDDSAttachedSurface ); HRESULT (__stdcall * AddOverlayDirtyRect)( WRAP* This, LPRECT lpRect ); @@ -16,7 +16,7 @@ namespace dds HRESULT (__stdcall * EnumAttachedSurfaces)( WRAP* This, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback ); HRESULT (__stdcall * EnumOverlayZOrders)( WRAP* This, DWORD dwFlags, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpfnCallback ); HRESULT (__stdcall * Flip)( WRAP* This, LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DWORD dwFlags ); - HRESULT (__stdcall * GetAttachedSurface)( WRAP* This, LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE *lplpDDAttachedSurface ); + HRESULT (__stdcall * GetAttachedSurface)( WRAP* This, LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE *lplpDDAttachedSurface ); HRESULT (__stdcall * GetBltStatus)( WRAP* This, DWORD dwFlags ); HRESULT (__stdcall * GetCaps)( WRAP* This, LPDDSCAPS lpDDSCaps ); HRESULT (__stdcall * GetClipper)( WRAP* This, LPDIRECTDRAWCLIPPER *lplpDDClipper ); @@ -41,7 +41,7 @@ namespace dds HRESULT (__stdcall * UpdateOverlayDisplay)( WRAP* This, DWORD dwFlags ); HRESULT (__stdcall * UpdateOverlayZOrder)( WRAP* This, DWORD dwFlags, LPDIRECTDRAWSURFACE lpDDSReference ); // added in v2 - HRESULT (__stdcall * GetDDInterface)( WRAP* This, LPVOID *lplpDD ); + HRESULT (__stdcall * GetDDInterface)( WRAP* This, LPVOID *lplpDD ); HRESULT (__stdcall * PageLock)( WRAP* This, DWORD dwFlags ); HRESULT (__stdcall * PageUnlock)( WRAP* This, DWORD dwFlags ); // added in v3 @@ -59,22 +59,22 @@ namespace dds HRESULT (__stdcall * GetLOD)( WRAP* This, LPDWORD lod ); }; - HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) - { + HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->QueryInterface( This->dds1, riid, ppvObject ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( riid ), ppvObject ); EPILOGUE( hResult ); } - ULONG __stdcall AddRef( WRAP* This ) - { + ULONG __stdcall AddRef( WRAP* This ) + { PROLOGUE; ULONG dwCount = This->dds1->lpVtbl->AddRef( This->dds1 ); - EPILOGUE( dwCount ); + EPILOGUE( dwCount ); } - ULONG __stdcall Release( WRAP* This ) + ULONG __stdcall Release( WRAP* This ) { PROLOGUE; ULONG dwCount = WrapRelease(This); @@ -94,8 +94,8 @@ namespace dds EPILOGUE( dwCount ); } - HRESULT __stdcall AddAttachedSurface( WRAP* This, LPDIRECTDRAWSURFACE lpDDSAttachedSurface ) - { + HRESULT __stdcall AddAttachedSurface( WRAP* This, LPDIRECTDRAWSURFACE lpDDSAttachedSurface ) + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->AddAttachedSurface( This->dds1, GetInnerInterface( lpDDSAttachedSurface ) ); if( SUCCEEDED( hResult ) ) @@ -112,7 +112,6 @@ namespace dds EPILOGUE( hResult ); } - HRESULT __stdcall Blt( WRAP* This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx ) { PROLOGUE; @@ -149,7 +148,7 @@ namespace dds LPDIRECTDRAWSURFACE src = dx::MatchFlip(lpDDSrcSurface); LPDIRECTDRAWSURFACE sf = dx::MatchFlip(This->dds1); - hResult = sf->lpVtbl->Blt(sf, lpDestRect, src, lpSrcRect, dwFlags, lpDDBltFx); + hResult = sf->lpVtbl->Blt(sf, lpDestRect, src, lpSrcRect, dwFlags, lpDDBltFx); INFO("Blt %08X (%08X) <- %08X (%08X) : %08X\n", This->dds1, sf, lpDDSrcSurface, src, dwFlags); if (SUCCEEDED(hResult) && This->dds1 == dx::fake[0]) { // Front dx::Flush(sf); @@ -158,7 +157,7 @@ namespace dds EPILOGUE( hResult ); } - HRESULT __stdcall BltBatch( WRAP* This, LPDDBLTBATCH lpDDBltBatch, DWORD dwCount, DWORD dwFlags ) + HRESULT __stdcall BltBatch( WRAP* This, LPDDBLTBATCH lpDDBltBatch, DWORD dwCount, DWORD dwFlags ) { // This method was never implemented by ddraw? PROLOGUE; UNREFERENCED_PARAMETER( This ); @@ -166,10 +165,10 @@ namespace dds UNREFERENCED_PARAMETER( dwCount ); UNREFERENCED_PARAMETER( dwFlags ); WARN( "E_NOTIMPL" ); - EPILOGUE( E_NOTIMPL ); + EPILOGUE( E_NOTIMPL ); } - HRESULT __stdcall BltFast( WRAP* This, DWORD dwX, DWORD dwY, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwTrans ) + HRESULT __stdcall BltFast( WRAP* This, DWORD dwX, DWORD dwY, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwTrans ) { PROLOGUE; lpDDSrcSurface = GetInnerInterface(lpDDSrcSurface); @@ -180,7 +179,7 @@ namespace dds if (SUCCEEDED(hResult) && This->dds1 == dx::fake[0]) { // Front dx::Flush(sf); } - EPILOGUE( hResult ); + EPILOGUE( hResult ); } HRESULT __stdcall DeleteAttachedSurface( WRAP* This, DWORD dwFlags, LPDIRECTDRAWSURFACE lpDDSAttachedSurface) @@ -191,12 +190,12 @@ namespace dds { lpDDSAttachedSurface->lpVtbl->Release( lpDDSAttachedSurface ); } - EPILOGUE( hResult ); + EPILOGUE( hResult ); } - HRESULT __stdcall EnumAttachedSurfaces( WRAP* This, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback ) - { + HRESULT __stdcall EnumAttachedSurfaces( WRAP* This, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback ) + { PROLOGUE; EnumStruct e; e.callback = (void*)lpEnumSurfacesCallback; @@ -205,10 +204,10 @@ namespace dds e.xVtbl = This->xVtbl; e.must_exist = true; HRESULT hResult = This->dds1->lpVtbl->EnumAttachedSurfaces( This->dds1, &e, &WrapEnumSurfacesCallback ); - EPILOGUE( hResult ); + EPILOGUE( hResult ); } - HRESULT __stdcall EnumOverlayZOrders( WRAP* This, DWORD dwFlags, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpfnCallback ) + HRESULT __stdcall EnumOverlayZOrders( WRAP* This, DWORD dwFlags, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpfnCallback ) { PROLOGUE; EnumStruct e; @@ -218,11 +217,11 @@ namespace dds e.xVtbl = This->xVtbl; e.must_exist = true; HRESULT hResult = This->dds1->lpVtbl->EnumOverlayZOrders( This->dds1, dwFlags, &e, &WrapEnumSurfacesCallback ); - EPILOGUE( hResult ); + EPILOGUE( hResult ); } - HRESULT __stdcall Flip( WRAP* This, LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DWORD dwFlags ) - { + HRESULT __stdcall Flip( WRAP* This, LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DWORD dwFlags ) + { PROLOGUE; HRESULT hResult; if (dx::enabled) { @@ -232,11 +231,11 @@ namespace dds } else { hResult = This->dds1->lpVtbl->Flip( This->dds1, GetInnerInterface( lpDDSurfaceTargetOverride ), dwFlags ); } - EPILOGUE( hResult ); + EPILOGUE( hResult ); } - HRESULT __stdcall GetAttachedSurface( WRAP* This, LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE* lplpDDAttachedSurface ) - { + HRESULT __stdcall GetAttachedSurface( WRAP* This, LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE* lplpDDAttachedSurface ) + { PROLOGUE; HRESULT hResult = DD_OK; if (This->dds1 == dx::fake[0]) { // Front @@ -249,37 +248,37 @@ namespace dds EPILOGUE( hResult ); } - HRESULT __stdcall GetBltStatus( WRAP* This, DWORD dwFlags ) + HRESULT __stdcall GetBltStatus( WRAP* This, DWORD dwFlags ) { PROLOGUE; - HRESULT hResult = This->dds1->lpVtbl->GetBltStatus( This->dds1, dwFlags ); + HRESULT hResult = This->dds1->lpVtbl->GetBltStatus( This->dds1, dwFlags ); EPILOGUE( hResult ); } - HRESULT __stdcall GetCaps( WRAP* This, LPDDSCAPS lpDDSCaps ) - { + HRESULT __stdcall GetCaps( WRAP* This, LPDDSCAPS lpDDSCaps ) + { PROLOGUE; - HRESULT hResult = This->dds1->lpVtbl->GetCaps( This->dds1, lpDDSCaps ); + HRESULT hResult = This->dds1->lpVtbl->GetCaps( This->dds1, lpDDSCaps ); EPILOGUE( hResult ); } - HRESULT __stdcall GetClipper( WRAP* This, LPDIRECTDRAWCLIPPER *lplpDDClipper ) - { + HRESULT __stdcall GetClipper( WRAP* This, LPDIRECTDRAWCLIPPER *lplpDDClipper ) + { PROLOGUE; - HRESULT hResult = This->dds1->lpVtbl->GetClipper( This->dds1, lplpDDClipper ); + HRESULT hResult = This->dds1->lpVtbl->GetClipper( This->dds1, lplpDDClipper ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( IID_IDirectDrawClipper ), (void**)lplpDDClipper ); EPILOGUE( hResult ); } - HRESULT __stdcall GetColorKey( WRAP* This, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey ) - { + HRESULT __stdcall GetColorKey( WRAP* This, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey ) + { PROLOGUE; - HRESULT hResult = This->dds1->lpVtbl->GetColorKey( This->dds1, dwFlags, lpDDColorKey ); + HRESULT hResult = This->dds1->lpVtbl->GetColorKey( This->dds1, dwFlags, lpDDColorKey ); EPILOGUE( hResult ); } HRESULT __stdcall GetDC( WRAP* This, HDC *lphDC ) - { + { PROLOGUE; LPDIRECTDRAWSURFACE sf = dx::MatchFlip(This->dds1); HRESULT hResult = sf->lpVtbl->GetDC(sf, lphDC); @@ -288,21 +287,21 @@ namespace dds } HRESULT __stdcall GetFlipStatus( WRAP* This, DWORD dwFlags ) - { + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->GetFlipStatus( This->dds1, dwFlags ); EPILOGUE( hResult ); } HRESULT __stdcall GetOverlayPosition( WRAP* This, LPLONG lplX, LPLONG lplY ) - { + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->GetOverlayPosition( This->dds1, lplX, lplY ); EPILOGUE( hResult ); } HRESULT __stdcall GetPalette( WRAP* This, LPDIRECTDRAWPALETTE *lplpDDPalette ) - { + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->GetPalette( This->dds1, lplpDDPalette ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( IID_IDirectDrawPalette ), (void**)lplpDDPalette ); @@ -312,26 +311,26 @@ namespace dds HRESULT __stdcall GetPixelFormat( WRAP* This, LPDDPIXELFORMAT lpDDPixelFormat ) { PROLOGUE; - HRESULT hResult = This->dds1->lpVtbl->GetPixelFormat( This->dds1, lpDDPixelFormat ); + HRESULT hResult = This->dds1->lpVtbl->GetPixelFormat( This->dds1, lpDDPixelFormat ); EPILOGUE( hResult ); } - HRESULT __stdcall GetSurfaceDesc( WRAP* This, LPDDSURFACEDESC lpDDSurfaceDesc ) - { + HRESULT __stdcall GetSurfaceDesc( WRAP* This, LPDDSURFACEDESC lpDDSurfaceDesc ) + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->GetSurfaceDesc( This->dds1, lpDDSurfaceDesc ); EPILOGUE( hResult ); } HRESULT __stdcall Initialize( WRAP* This, LPDIRECTDRAW lpDD, LPDDSURFACEDESC lpDDSurfaceDesc ) - { + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->Initialize( This->dds1, GetInnerInterface( lpDD ), lpDDSurfaceDesc ); EPILOGUE( hResult ); } HRESULT __stdcall IsLost( WRAP* This ) - { + { PROLOGUE; LPDIRECTDRAWSURFACE sf = dx::MatchFlip(This->dds1); HRESULT hResult = sf->lpVtbl->IsLost(sf); @@ -339,7 +338,7 @@ namespace dds } HRESULT __stdcall Lock( WRAP* This, LPRECT lpDestRect, LPDDSURFACEDESC lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent ) - { + { PROLOGUE; LPDIRECTDRAWSURFACE sf = dx::MatchFlip(This->dds1); HRESULT hResult = sf->lpVtbl->Lock(sf, lpDestRect, lpDDSurfaceDesc, dwFlags, hEvent); @@ -349,7 +348,7 @@ namespace dds } HRESULT __stdcall ReleaseDC( WRAP* This, HDC hDC ) - { + { PROLOGUE; LPDIRECTDRAWSURFACE sf = dx::MatchFlip(This->dds1); HRESULT hResult = sf->lpVtbl->ReleaseDC(sf, hDC); @@ -361,7 +360,7 @@ namespace dds } HRESULT __stdcall Restore( WRAP* This ) - { + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->Restore(This->dds1); INFO("Restore %08X\n", This->dds1); @@ -370,17 +369,17 @@ namespace dds EPILOGUE( hResult ); } - HRESULT __stdcall SetClipper( WRAP* This, LPDIRECTDRAWCLIPPER lpDDClipper ) - { + HRESULT __stdcall SetClipper( WRAP* This, LPDIRECTDRAWCLIPPER lpDDClipper ) + { PROLOGUE; HRESULT hResult; LPDIRECTDRAWCLIPPER old_clipper = NULL; - hResult = This->dds1->lpVtbl->GetClipper( This->dds1, &old_clipper ); + hResult = This->dds1->lpVtbl->GetClipper( This->dds1, &old_clipper ); if( SUCCEEDED( hResult ) ) { Wrap( This->dd_parent, iid_to_vtbl( IID_IDirectDrawClipper ), (void**)&old_clipper ); } - hResult = This->dds1->lpVtbl->SetClipper( This->dds1, GetInnerInterface( lpDDClipper ) ); + hResult = This->dds1->lpVtbl->SetClipper( This->dds1, GetInnerInterface( lpDDClipper ) ); if( old_clipper != NULL ) { old_clipper->lpVtbl->Release( old_clipper ); @@ -389,7 +388,7 @@ namespace dds } HRESULT __stdcall SetColorKey( WRAP* This, DWORD dwFlags, LPDDCOLORKEY lpDDColorKey ) - { + { PROLOGUE; HRESULT hResult = This->dds1->lpVtbl->SetColorKey( This->dds1, dwFlags, lpDDColorKey ); INFO("SetColorKey L:%08X H:%08X to %08X : %08X\n", lpDDColorKey->dwColorSpaceLowValue, lpDDColorKey->dwColorSpaceHighValue, This->dds1, dwFlags); @@ -406,11 +405,11 @@ namespace dds } HRESULT __stdcall SetPalette( WRAP* This, LPDIRECTDRAWPALETTE lpDDPalette ) - { + { PROLOGUE; HRESULT hResult; LPDIRECTDRAWPALETTE old_palette = NULL; - hResult = This->dds1->lpVtbl->GetPalette( This->dds1, &old_palette ); + hResult = This->dds1->lpVtbl->GetPalette( This->dds1, &old_palette ); if( SUCCEEDED( hResult ) ) { Wrap( This->dd_parent, iid_to_vtbl( IID_IDirectDrawPalette ), (void**)&old_palette ); @@ -433,11 +432,11 @@ namespace dds // lpData is ddsd.lpSurface in version 1, 2, and 3 // lpData is lpRect in versions 4 and 7 - HRESULT __stdcall Unlock( WRAP* This, LPVOID lpData ) - { + HRESULT __stdcall Unlock( WRAP* This, LPVOID lpData ) + { PROLOGUE; LPDIRECTDRAWSURFACE sf = dx::MatchFlip(This->dds1); - HRESULT hResult = sf->lpVtbl->Unlock(sf, lpData); + HRESULT hResult = sf->lpVtbl->Unlock(sf, lpData); INFO("Unlock %08X (%08X)\n", This->dds1, sf); if (SUCCEEDED(hResult) && This->dds1 == dx::fake[0] && dx::write) { // Front dx::write = 0; @@ -447,14 +446,14 @@ namespace dds } HRESULT __stdcall UpdateOverlay( WRAP* This, LPRECT lpSrcRect, LPDIRECTDRAWSURFACE lpDDDestSurface, LPRECT lpDestRect, DWORD dwFlags, LPDDOVERLAYFX lpDDOverlayFx ) - { + { PROLOGUE; DDOVERLAYFX fx; // unwrap interfaces in the DDOVERLAYFX structure if used // if( dwFlags & ( DDOVER_ALPHADESTSURFACEOVERRIDE | DDOVER_ALPHASRCSURFACEOVERRIDE ) ) { - if( ( lpDDOverlayFx != NULL ) && ( sizeof( fx ) <= lpDDOverlayFx->dwSize ) ) + if( ( lpDDOverlayFx != NULL ) && ( sizeof( fx ) <= lpDDOverlayFx->dwSize ) ) { memcpy( &fx, lpDDOverlayFx, sizeof(fx) ); if( dwFlags & DDOVER_ALPHADESTSURFACEOVERRIDE ) fx.lpDDSAlphaDest = GetInnerInterface( fx.lpDDSAlphaDest ); @@ -469,30 +468,30 @@ namespace dds } HRESULT __stdcall UpdateOverlayDisplay( WRAP* This, DWORD dwFlags ) - { + { PROLOGUE; - HRESULT hResult = This->dds1->lpVtbl->UpdateOverlayDisplay( This->dds1, dwFlags ); + HRESULT hResult = This->dds1->lpVtbl->UpdateOverlayDisplay( This->dds1, dwFlags ); EPILOGUE( hResult ); } HRESULT __stdcall UpdateOverlayZOrder( WRAP* This, DWORD dwFlags, LPDIRECTDRAWSURFACE lpDDSReference ) - { + { PROLOGUE; //if( dwFlags & ( DDOVERZ_INSERTINBACKOF | DDOVERZ_INSERTINFRONTOF ) ) lpDDSReference = GetInnerInterface( lpDDSReference ); - HRESULT hResult = This->dds1->lpVtbl->UpdateOverlayZOrder( This->dds1, dwFlags, lpDDSReference ); + HRESULT hResult = This->dds1->lpVtbl->UpdateOverlayZOrder( This->dds1, dwFlags, lpDDSReference ); EPILOGUE( hResult ); } // v2 // - HRESULT __stdcall GetDDInterface( WRAP* This, LPVOID* lplpDD ) - { + HRESULT __stdcall GetDDInterface( WRAP* This, LPVOID* lplpDD ) + { // theoretically returns IUnknown but some programs may cast it to a different interface pointer... // instead of querying for the interface. PROLOGUE; HRESULT hResult = This->dds2->lpVtbl->GetDDInterface( This->dds2, lplpDD ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, dds_to_dd_vtbl( This ), (void**)lplpDD ); - EPILOGUE( hResult ); + EPILOGUE( hResult ); } HRESULT __stdcall PageLock( WRAP* This, DWORD dwFlags ) @@ -506,7 +505,7 @@ namespace dds { PROLOGUE; HRESULT hResult = This->dds2->lpVtbl->PageUnlock( This->dds2, dwFlags ); - EPILOGUE( hResult ); + EPILOGUE( hResult ); } // v3 // @@ -521,7 +520,7 @@ namespace dds // v4 // HRESULT __stdcall SetPrivateData( WRAP* This, const GUID & tag, LPVOID pData, DWORD cbSize, DWORD dwFlags ) - { + { PROLOGUE; HRESULT hResult = This->dds4->lpVtbl->SetPrivateData( This->dds4, tag, pData, cbSize, dwFlags ); EPILOGUE( hResult ); @@ -544,12 +543,12 @@ namespace dds HRESULT __stdcall GetUniquenessValue( WRAP* This, LPDWORD pValue ) { PROLOGUE; - HRESULT hResult = This->dds4->lpVtbl->GetUniquenessValue( This->dds4, pValue ); + HRESULT hResult = This->dds4->lpVtbl->GetUniquenessValue( This->dds4, pValue ); EPILOGUE( hResult ); } HRESULT __stdcall ChangeUniquenessValue( WRAP* This ) - { + { PROLOGUE; HRESULT hResult = This->dds4->lpVtbl->ChangeUniquenessValue( This->dds4 ); EPILOGUE( hResult ); @@ -628,13 +627,13 @@ namespace dds 0, // 0x9C 0, // 0xA0 0, // 0xA4 - 0, // 0xA8 - 0, // 0xAC + 0, // 0xA8 + 0, // 0xAC 0, // 0xB0 0, // 0xB4 0, // 0xB8 0, // 0xBC - 0 // 0xC0 + 0, // 0xC0 }; const XVTBL xVtbl2 = { @@ -680,13 +679,13 @@ namespace dds 0, // 0x9C 0, // 0xA0 0, // 0xA4 - 0, // 0xA8 - 0, // 0xAC + 0, // 0xA8 + 0, // 0xAC 0, // 0xB0 0, // 0xB4 0, // 0xB8 0, // 0xBC - 0 // 0xC0 + 0, // 0xC0 }; const XVTBL xVtbl3 = { @@ -732,13 +731,13 @@ namespace dds SetSurfaceDesc, // 0x9C 0, // 0xA0 0, // 0xA4 - 0, // 0xA8 - 0, // 0xAC + 0, // 0xA8 + 0, // 0xAC 0, // 0xB0 0, // 0xB4 0, // 0xB8 0, // 0xBC - 0 // 0xC0 + 0, // 0xC0 }; const XVTBL xVtbl4 = { @@ -784,13 +783,13 @@ namespace dds SetSurfaceDesc, // 0x9C SetPrivateData, // 0xA0 GetPrivateData, // 0xA4 - FreePrivateData, // 0xA8 - GetUniquenessValue, // 0xAC + FreePrivateData, // 0xA8 + GetUniquenessValue, // 0xAC ChangeUniquenessValue, // 0xB0 0, // 0xB4 0, // 0xB8 0, // 0xBC - 0 // 0xC0 + 0, // 0xC0 }; const XVTBL xVtbl7 = { @@ -836,12 +835,12 @@ namespace dds SetSurfaceDesc, // 0x9C SetPrivateData, // 0xA0 GetPrivateData, // 0xA4 - FreePrivateData, // 0xA8 - GetUniquenessValue, // 0xAC + FreePrivateData, // 0xA8 + GetUniquenessValue, // 0xAC ChangeUniquenessValue, // 0xB0 SetPriority, // 0xB4 GetPriority, // 0xB8 SetLOD, // 0xBC - GetLOD // 0xC0 + GetLOD, // 0xC0 }; }; diff --git a/dllmain.cpp b/dllmain.cpp index 091455d..4a3458c 100644 --- a/dllmain.cpp +++ b/dllmain.cpp @@ -14,8 +14,8 @@ typedef HRESULT (__stdcall* D3DParseUnknownCommand_t )( LPVOID lpCmd, LPVOID *l typedef HRESULT (__stdcall* DllCanUnloadNow_t)(); // // undocumented -typedef DWORD (__stdcall* AcquireDDThreadLock_t )(); -typedef DWORD (__stdcall* ReleaseDDThreadLock_t )(); +typedef DWORD (__stdcall* AcquireDDThreadLock_t )(); +typedef DWORD (__stdcall* ReleaseDDThreadLock_t )(); typedef DWORD (__stdcall* GetOLEThunkData_t )( DWORD index ); typedef DWORD (__stdcall* SetAppCompatData_t )( DWORD index, DWORD data ); typedef DWORD (__stdcall* CompleteCreateSysmemSurface_t )( DWORD ); @@ -27,28 +27,28 @@ typedef HRESULT (__stdcall* GetDDSurfaceLocal_t )( DWORD, DWORD, DWORD typedef HRESULT (__stdcall* GetSurfaceFromDC_t )( DWORD, DWORD, DWORD ); typedef HRESULT (__stdcall* RegisterSpecialCase_t )( DWORD, DWORD, DWORD, DWORD ); -HMODULE hRealDDraw; -DirectDrawCreate_t pDirectDrawCreate; +HMODULE hRealDDraw; +DirectDrawCreate_t pDirectDrawCreate; DirectDrawCreateEx_t pDirectDrawCreateEx; -DirectDrawCreateClipper_t pDirectDrawCreateClipper; +DirectDrawCreateClipper_t pDirectDrawCreateClipper; DirectDrawEnumerateA_t pDirectDrawEnumerateA; -DirectDrawEnumerateExA_t pDirectDrawEnumerateExA; -DirectDrawEnumerateExW_t pDirectDrawEnumerateExW; +DirectDrawEnumerateExA_t pDirectDrawEnumerateExA; +DirectDrawEnumerateExW_t pDirectDrawEnumerateExW; DirectDrawEnumerateW_t pDirectDrawEnumerateW; -D3DParseUnknownCommand_t pD3DParseUnknownCommand; -DllGetClassObject_t pDllGetClassObject; -DllCanUnloadNow_t pDllCanUnloadNow; +D3DParseUnknownCommand_t pD3DParseUnknownCommand; +DllGetClassObject_t pDllGetClassObject; +DllCanUnloadNow_t pDllCanUnloadNow; AcquireDDThreadLock_t pAcquireDDThreadLock; ReleaseDDThreadLock_t pReleaseDDThreadLock; -GetOLEThunkData_t pGetOLEThunkData; -SetAppCompatData_t pSetAppCompatData; -CompleteCreateSysmemSurface_t pCompleteCreateSysmemSurface; -DDGetAttachedSurfaceLcl_t pDDGetAttachedSurfaceLcl; -DDInternalLock_t pDDInternalLock; -DDInternalUnlock_t pDDInternalUnlock; +GetOLEThunkData_t pGetOLEThunkData; +SetAppCompatData_t pSetAppCompatData; +CompleteCreateSysmemSurface_t pCompleteCreateSysmemSurface; +DDGetAttachedSurfaceLcl_t pDDGetAttachedSurfaceLcl; +DDInternalLock_t pDDInternalLock; +DDInternalUnlock_t pDDInternalUnlock; DSoundHelp_t pDSoundHelp; -GetDDSurfaceLocal_t pGetDDSurfaceLocal; -GetSurfaceFromDC_t pGetSurfaceFromDC; +GetDDSurfaceLocal_t pGetDDSurfaceLocal; +GetSurfaceFromDC_t pGetSurfaceFromDC; RegisterSpecialCase_t pRegisterSpecialCase; BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved) @@ -57,7 +57,7 @@ BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved) UNREFERENCED_PARAMETER( lpvReserved ); switch(dwReason) { - case DLL_PROCESS_ATTACH: + case DLL_PROCESS_ATTACH: { InitializeCriticalSection(&cs); GetSystemInfo(&sSysInfo); @@ -137,7 +137,6 @@ HRESULT __stdcall DirectDrawCreate( GUID* lpGUID, LPDIRECTDRAW* lplpDD, IUnknown EPILOGUE( hResult ); } - HRESULT __stdcall DirectDrawCreateEx( GUID* lpGUID, LPVOID* lplpDD, REFIID iid, IUnknown* pUnkOuter ) { PROLOGUE; @@ -153,7 +152,6 @@ HRESULT __stdcall DirectDrawCreateEx( GUID* lpGUID, LPVOID* lplpDD, REFIID iid, EPILOGUE( hResult ); } - HRESULT __stdcall DirectDrawCreateClipper( DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter ) { PROLOGUE; @@ -162,14 +160,13 @@ HRESULT __stdcall DirectDrawCreateClipper( DWORD dwFlags, LPDIRECTDRAWCLIPPER FA { hResult = pDirectDrawCreateClipper( dwFlags, lplpDDClipper, pUnkOuter ); if( SUCCEEDED( hResult) ) - { + { Wrap( NULL, iid_to_vtbl( IID_IDirectDrawClipper ), (void**)lplpDDClipper ); } } EPILOGUE( hResult ); } - // do we care what the CLSID is ?? or do we just look at riid... // CLSID_DirectDraw, CLSID_DirectDraw7, CLSID_DirectDrawClipper HRESULT __stdcall DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID* ppvObject ) @@ -180,14 +177,13 @@ HRESULT __stdcall DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID* ppvOb { hResult = pDllGetClassObject( rclsid, riid, ppvObject ); if( SUCCEEDED( hResult) ) - { + { Wrap( NULL, iid_to_vtbl( riid ), ppvObject ); } } EPILOGUE( hResult ); } - //////////////////////////////////////////// // // Every thing below here is just pass-thru @@ -196,7 +192,7 @@ HRESULT __stdcall DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID* ppvOb // returns void / no return value DWORD __stdcall AcquireDDThreadLock() -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; if( pAcquireDDThreadLock != NULL ) @@ -220,9 +216,8 @@ DWORD __stdcall ReleaseDDThreadLock() EPILOGUE( hResult ); } - HRESULT __stdcall DirectDrawEnumerateA( LPDDENUMCALLBACK lpCallback, LPVOID lpContext ) -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; if( pDirectDrawEnumerateA != NULL ) @@ -232,33 +227,30 @@ HRESULT __stdcall DirectDrawEnumerateA( LPDDENUMCALLBACK lpCallback, LPVOID lpCo EPILOGUE( hResult ); } - HRESULT __stdcall DirectDrawEnumerateExA( LPDDENUMCALLBACK lpCallback, LPVOID lpContext, DWORD dwFlags ) -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; - if( pDirectDrawEnumerateExA != NULL ) + if( pDirectDrawEnumerateExA != NULL ) { hResult = pDirectDrawEnumerateExA( lpCallback, lpContext, dwFlags ); } EPILOGUE( hResult ); } - HRESULT __stdcall DirectDrawEnumerateExW( LPDDENUMCALLBACK lpCallback, LPVOID lpContext, DWORD dwFlags ) -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; - if( pDirectDrawEnumerateExW != NULL ) + if( pDirectDrawEnumerateExW != NULL ) { hResult = pDirectDrawEnumerateExW( lpCallback, lpContext, dwFlags ); } EPILOGUE( hResult ); } - HRESULT __stdcall DirectDrawEnumerateW( LPDDENUMCALLBACK lpCallback, LPVOID lpContext ) -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; if( pDirectDrawEnumerateW != NULL ) @@ -268,9 +260,8 @@ HRESULT __stdcall DirectDrawEnumerateW( LPDDENUMCALLBACK lpCallback, LPVOID lpCo EPILOGUE( hResult ); } - HRESULT __stdcall D3DParseUnknownCommand( LPVOID lpCmd, LPVOID *lpRetCmd ) -{ +{ PROLOGUE; HRESULT hResult = D3DERR_COMMAND_UNPARSED; if( pD3DParseUnknownCommand != NULL ) @@ -280,9 +271,8 @@ HRESULT __stdcall D3DParseUnknownCommand( LPVOID lpCmd, LPVOID *lpRetCmd ) EPILOGUE( hResult ); } - HRESULT __stdcall DllCanUnloadNow() -{ +{ PROLOGUE; HRESULT hResult = S_FALSE; if( pDllCanUnloadNow != NULL ) @@ -292,10 +282,9 @@ HRESULT __stdcall DllCanUnloadNow() EPILOGUE( hResult ); } - DWORD __stdcall GetOLEThunkData( DWORD index ) -{ - // switch( index ) +{ + // switch( index ) // { // case 1: return _dwLastFrameRate; // case 2: return _lpDriverObjectList; @@ -313,10 +302,9 @@ DWORD __stdcall GetOLEThunkData( DWORD index ) EPILOGUE( dwResult ); } - DWORD __stdcall SetAppCompatData( DWORD index, DWORD data ) { - // switch( index ) + // switch( index ) // { // case 1: _g_bDWMOffForPrimaryLock = 0; return 0; // case 2: _g_bDWMOffForPrimaryBlt = 0; return 0; @@ -327,16 +315,15 @@ DWORD __stdcall SetAppCompatData( DWORD index, DWORD data ) // } PROLOGUE; DWORD dwResult = 0; - if( pSetAppCompatData != NULL ) + if( pSetAppCompatData != NULL ) { dwResult = pSetAppCompatData( index, data ); } EPILOGUE( dwResult ); } - DWORD __stdcall CompleteCreateSysmemSurface( DWORD arg1 ) -{ +{ PROLOGUE; DWORD dwResult = 0; if( pCompleteCreateSysmemSurface != NULL ) @@ -346,9 +333,8 @@ DWORD __stdcall CompleteCreateSysmemSurface( DWORD arg1 ) EPILOGUE( dwResult ); } - HRESULT __stdcall DDGetAttachedSurfaceLcl( DWORD arg1, DWORD arg2, DWORD arg3 ) -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; if( pDDGetAttachedSurfaceLcl != NULL ) @@ -358,9 +344,8 @@ HRESULT __stdcall DDGetAttachedSurfaceLcl( DWORD arg1, DWORD arg2, DWORD arg3 ) EPILOGUE( hResult ); } - DWORD __stdcall DDInternalLock( DWORD arg1, DWORD arg2 ) -{ +{ PROLOGUE; DWORD dwResult = 0xFFFFFFFF; if( pDDInternalLock != NULL ) @@ -370,7 +355,6 @@ DWORD __stdcall DDInternalLock( DWORD arg1, DWORD arg2 ) EPILOGUE( dwResult ); } - DWORD __stdcall DDInternalUnlock( DWORD arg1 ) { PROLOGUE; @@ -380,16 +364,16 @@ DWORD __stdcall DDInternalUnlock( DWORD arg1 ) dwResult = pDDInternalUnlock( arg1 ); } EPILOGUE( dwResult ); -} +} /* - If SetCooperativeLevel is called once in a process, a binding is established between the process and the window. - If it is called again in the same process with a different non-null window handle, it returns the DDERR_HWNDALREADYSET + If SetCooperativeLevel is called once in a process, a binding is established between the process and the window. + If it is called again in the same process with a different non-null window handle, it returns the DDERR_HWNDALREADYSET error value. Some applications may receive this error value when DirectSound(R) specifies a different window handle than DirectDraw(R)—they should specify the same, top-level application window handle. */ HRESULT __stdcall DSoundHelp( DWORD arg1, DWORD arg2, DWORD arg3 ) -{ +{ // _internalSetAppHWnd( 0, arg1, 0, 0, arg2, arg3 ); PROLOGUE; HRESULT hResult = E_NOTIMPL; @@ -398,12 +382,11 @@ HRESULT __stdcall DSoundHelp( DWORD arg1, DWORD arg2, DWORD arg3 ) hResult = pDSoundHelp( arg1, arg2, arg3 ); } EPILOGUE( hResult ); -} - +} // assume HRESULT... HRESULT __stdcall GetDDSurfaceLocal( DWORD arg1, DWORD arg2, DWORD arg3 ) -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; if( pGetDDSurfaceLocal != NULL ) @@ -415,7 +398,7 @@ HRESULT __stdcall GetDDSurfaceLocal( DWORD arg1, DWORD arg2, DWORD arg3 ) // assume HRESULT... HRESULT __stdcall GetSurfaceFromDC_export( DWORD arg1, DWORD arg2, DWORD arg3 ) -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; if( pGetSurfaceFromDC != NULL ) @@ -423,12 +406,11 @@ HRESULT __stdcall GetSurfaceFromDC_export( DWORD arg1, DWORD arg2, DWORD arg3 ) hResult = pGetSurfaceFromDC( arg1, arg2, arg3 ); } EPILOGUE( hResult ); -} - +} // setup for HEL BLT ??? HRESULT __stdcall RegisterSpecialCase( DWORD arg1, DWORD arg2, DWORD arg3, DWORD arg4 ) -{ +{ PROLOGUE; HRESULT hResult = E_NOTIMPL; if( pRegisterSpecialCase != NULL ) diff --git a/gama.cpp b/gama.cpp index 2c602e7..bafeb48 100644 --- a/gama.cpp +++ b/gama.cpp @@ -4,29 +4,29 @@ namespace gama { struct XVTBL { - HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); - ULONG (__stdcall * AddRef)( WRAP* This ); - ULONG (__stdcall * Release)( WRAP* This ); + HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); + ULONG (__stdcall * AddRef)( WRAP* This ); + ULONG (__stdcall * Release)( WRAP* This ); HRESULT (__stdcall * GetGammaRamp)( WRAP* This, DWORD dwFlags, LPDDGAMMARAMP lpRampData ); HRESULT (__stdcall * SetGammaRamp)( WRAP* This, DWORD dwFlags, LPDDGAMMARAMP lpRampData ); }; - HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) - { + HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) + { PROLOGUE; HRESULT hResult = This->gama->lpVtbl->QueryInterface( This->gama, riid, ppvObject ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( riid ), ppvObject ); EPILOGUE( hResult ); } - ULONG __stdcall AddRef( WRAP* This ) - { + ULONG __stdcall AddRef( WRAP* This ) + { PROLOGUE; ULONG dwCount = This->gama->lpVtbl->AddRef( This->gama ); EPILOGUE( dwCount ); } - ULONG __stdcall Release( WRAP* This ) + ULONG __stdcall Release( WRAP* This ) { PROLOGUE; ULONG dwCount = WrapRelease( This ); @@ -34,21 +34,21 @@ namespace gama } HRESULT __stdcall GetGammaRamp( WRAP* This, DWORD dwFlags, LPDDGAMMARAMP lpRampData ) - { + { PROLOGUE; HRESULT hResult = This->gama->lpVtbl->GetGammaRamp( This->gama, dwFlags, lpRampData ); EPILOGUE( hResult ); } HRESULT __stdcall SetGammaRamp( WRAP* This, DWORD dwFlags, LPDDGAMMARAMP lpRampData ) - { + { PROLOGUE; HRESULT hResult = This->gama->lpVtbl->SetGammaRamp( This->gama, dwFlags, lpRampData ); EPILOGUE( hResult ); } - const XVTBL xVtbl = - { + const XVTBL xVtbl = + { QueryInterface, // 0x00 AddRef, // 0x04 Release, // 0x08 diff --git a/header.h b/header.h index a3eb3af..017ac76 100644 --- a/header.h +++ b/header.h @@ -1,5 +1,3 @@ -#pragma once - #define INITGUID #define CINTERFACE diff --git a/log.cpp b/log.cpp index b9fba1a..4672e89 100644 --- a/log.cpp +++ b/log.cpp @@ -4,7 +4,6 @@ DEFINE_GUID( _IID_IDDVideoPortContainer, 0x6C142760,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60 ); DEFINE_GUID( _IID_IDirectDrawVideoPort, 0xB36D93E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 ); DEFINE_GUID( _IID_IDirectDrawVideoPortNotify, 0xA655FB94,0x0589,0x4E57,0xB3,0x33,0x56,0x7A,0x89,0x46,0x8C,0x88); - HANDLE file = INVALID_HANDLE_VALUE; CRITICAL_SECTION log_lock; @@ -25,8 +24,8 @@ void __cdecl Log( const char* fmt, ... ) if( file == INVALID_HANDLE_VALUE ) { file = CreateFile("ddraw.log", GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 - ); + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 + ); LeaveCriticalSection(&log_lock); if( file == INVALID_HANDLE_VALUE ){ return; } } @@ -35,14 +34,14 @@ void __cdecl Log( const char* fmt, ... ) EnterCriticalSection(&log_lock); va_list args; - va_start(args,fmt); - len = wvsprintf( buf, fmt, args ); + va_start(args,fmt); + len = wvsprintf( buf, fmt, args ); va_end(args); ol.Offset = pos; ol.OffsetHigh = 0; ol.hEvent = NULL; - + if( WriteFile(file, buf, len, &bytes_written, &ol) ) { pos += bytes_written; @@ -54,7 +53,6 @@ void __cdecl Log( const char* fmt, ... ) LeaveCriticalSection(&log_lock); } - void dds32_to_bmp( IDirectDrawSurface* pDDSurface, char* szFileName ) { BITMAPFILEHEADER bmfh; @@ -63,8 +61,8 @@ void dds32_to_bmp( IDirectDrawSurface* pDDSurface, char* szFileName ) OVERLAPPED ol; DDSURFACEDESC ddsd; - ddsd.dwSize = sizeof( ddsd ); - if( FAILED( pDDSurface->lpVtbl->Lock( pDDSurface, NULL, &ddsd, DDLOCK_WAIT, NULL) ) ) return; + ddsd.dwSize = sizeof( ddsd ); + if( FAILED( pDDSurface->lpVtbl->Lock( pDDSurface, NULL, &ddsd, DDLOCK_WAIT, NULL) ) ) return; bmfh.bfType = 0x4d42; // "BM" bmfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO) + ( ddsd.dwWidth * ddsd.dwHeight * 4 ); // 4 bytes per pixel @@ -80,7 +78,7 @@ void dds32_to_bmp( IDirectDrawSurface* pDDSurface, char* szFileName ) bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; - + hFile = CreateFile( szFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); if( hFile != NULL ) { @@ -98,11 +96,10 @@ void dds32_to_bmp( IDirectDrawSurface* pDDSurface, char* szFileName ) } CloseHandle(hFile); } - + pDDSurface->lpVtbl->Unlock( pDDSurface, NULL ); } - void LogDDSD( LPDDSURFACEDESC lpDDSurfaceDesc ) { if( lpDDSurfaceDesc->dwSize >= sizeof( DDSURFACEDESC2 ) ) Log( "DDSD2:\n"); @@ -213,7 +210,6 @@ void LogDDSD( LPDDSURFACEDESC lpDDSurfaceDesc ) Log( " }\n" ); } } - void LogGUID(const GUID& riid) { @@ -232,7 +228,7 @@ void LogGUID(const GUID& riid) else if ( riid == IID_IDirectDrawPalette ) Log( "IID_IDirectDrawPalette\n" ); else if ( riid == IID_IDirectDrawColorControl ) Log( "IID_IDirectDrawColorControl\n" ); else if ( riid == IID_IDirectDrawGammaControl ) Log( "IID_IDirectDrawGammaControl\n" ); - + // unsupported // else if ( riid == _IID_IDDVideoPortContainer ) Log( "IID_IDDVideoPortContainer\n" ); else if ( riid == _IID_IDirectDrawVideoPort ) Log( "IID_IDirectDrawVideoPort\n" ); @@ -267,10 +263,9 @@ void LogGUID(const GUID& riid) else { Log( ">>>> Unknown GUID: 0x%08X,0x%04X,0x%04X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X <<<<\n", - riid.Data1, riid.Data2, riid.Data3, riid.Data4[0], riid.Data4[1], riid.Data4[2], riid.Data4[3], riid.Data4[4], - riid.Data4[5], riid.Data4[6], riid.Data4[7] - ); + riid.Data1, riid.Data2, riid.Data3, riid.Data4[0], riid.Data4[1], riid.Data4[2], riid.Data4[3], riid.Data4[4], + riid.Data4[5], riid.Data4[6], riid.Data4[7] + ); } } - diff --git a/log.h b/log.h index b7e98a9..a49c60f 100644 --- a/log.h +++ b/log.h @@ -14,9 +14,6 @@ they exist in case someone wants them for debugging */ -//extern "C" void * _ReturnAddress( void ); -//#pragma intrinsic( _ReturnAddress ) - void __cdecl Log( const char* fmt, ... ); void LogDDSD( LPDDSURFACEDESC lpDDSurfaceDesc ); void LogGUID( const GUID& riid ); @@ -38,7 +35,7 @@ void dds32_to_bmp( IDirectDrawSurface* pDDSurface, char* szFileName ); #undef INFO #define EPILOGUE(x) if(FAILED(x)){Log( "%08X %08X %s\n", x, __builtin_return_address(0), __FUNCTION__ );} return(x) #define LOG_GUID(x) LogGUID( x ) -#define WARN(x) Log( "WARNING: %s\n", x ) +#define WARN(x) Log( "WARNING: %s\n", x ) #define INFO(...) Log(__VA_ARGS__) */ diff --git a/palette.cpp b/palette.cpp index 95dadbf..5f94a72 100644 --- a/palette.cpp +++ b/palette.cpp @@ -4,31 +4,31 @@ namespace palette { struct XVTBL { - HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); - ULONG (__stdcall * AddRef)( WRAP* This ); - ULONG (__stdcall * Release)( WRAP* This ); + HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); + ULONG (__stdcall * AddRef)( WRAP* This ); + ULONG (__stdcall * Release)( WRAP* This ); HRESULT (__stdcall * GetCaps)( WRAP* This, LPDWORD lpdwCaps ); HRESULT (__stdcall * GetEntries)( WRAP* This, DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries ); HRESULT (__stdcall * Initialize)( WRAP* This, LPDIRECTDRAW lpDD, DWORD dwFlags, LPPALETTEENTRY lpDDColorTable ); HRESULT (__stdcall * SetEntries)( WRAP* This, DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries ); }; - HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) - { + HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) + { PROLOGUE; HRESULT hResult = This->pal->lpVtbl->QueryInterface( This->pal, riid, ppvObject ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( riid ), ppvObject ); EPILOGUE( hResult ); } - ULONG __stdcall AddRef( WRAP* This ) - { + ULONG __stdcall AddRef( WRAP* This ) + { PROLOGUE; ULONG dwCount = This->pal->lpVtbl->AddRef( This->pal ); EPILOGUE( dwCount ); } - ULONG __stdcall Release( WRAP* This ) + ULONG __stdcall Release( WRAP* This ) { PROLOGUE; ULONG dwCount = WrapRelease( This ); @@ -72,14 +72,14 @@ namespace palette EPILOGUE( hResult ); } - const XVTBL xVtbl = - { + const XVTBL xVtbl = + { QueryInterface, // 0x00 AddRef, // 0x04 Release, // 0x08 GetCaps, // 0x0C GetEntries, // 0x10 Initialize, // 0x14 - SetEntries // 0x18 + SetEntries, // 0x18 }; }; diff --git a/resource/ddraw.ini b/resource/ddraw.ini index 5832f99..a2c0f95 100644 --- a/resource/ddraw.ini +++ b/resource/ddraw.ini @@ -5,5 +5,8 @@ ; 0: Use Flip if available; 1: Do not use Flip even if available (may flicker). NoFlip = 0 +; 0: Use mem buffer; 1: Do not use mem buffer (may speed up or slow down depending on hardware). +NoBuffer = 0 + ; 0: Throttle frame rate; 1: Do not throttle frame rate (may slow down). NoThrottle = 0 diff --git a/unknwn.cpp b/unknwn.cpp index 992a173..d5f64b2 100644 --- a/unknwn.cpp +++ b/unknwn.cpp @@ -4,37 +4,37 @@ namespace unknwn { struct XVTBL { - HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); - ULONG (__stdcall * AddRef)( WRAP* This ); - ULONG (__stdcall * Release)( WRAP* This ); + HRESULT (__stdcall * QueryInterface)( WRAP* This, const IID& riid, void** ppvObject ); + ULONG (__stdcall * AddRef)( WRAP* This ); + ULONG (__stdcall * Release)( WRAP* This ); }; - HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) - { + HRESULT __stdcall QueryInterface( WRAP* This, const IID& riid, void** ppvObject ) + { PROLOGUE; HRESULT hResult = This->color->lpVtbl->QueryInterface( This->color, riid, ppvObject ); if( SUCCEEDED( hResult ) ) Wrap( This->dd_parent, iid_to_vtbl( riid ), ppvObject ); EPILOGUE( hResult ); } - ULONG __stdcall AddRef( WRAP* This ) - { + ULONG __stdcall AddRef( WRAP* This ) + { PROLOGUE; ULONG dwCount = This->color->lpVtbl->AddRef( This->color ); EPILOGUE( dwCount ); } - ULONG __stdcall Release( WRAP* This ) + ULONG __stdcall Release( WRAP* This ) { PROLOGUE; ULONG dwCount = WrapRelease( This ); EPILOGUE( dwCount ); } - const XVTBL xVtbl = - { + const XVTBL xVtbl = + { QueryInterface, // 0x00 AddRef, // 0x04 - Release // 0x08 + Release, // 0x08 }; -}; \ No newline at end of file +}; diff --git a/wrap.cpp b/wrap.cpp index 164cf3a..f1122cd 100644 --- a/wrap.cpp +++ b/wrap.cpp @@ -1,12 +1,9 @@ #include "header.h" -SYSTEM_INFO sSysInfo; -WRAP* wrap_list; -WRAP* wrap_freelist; -DD_LIFETIME* ddlt_list; -DD_LIFETIME* ddlt_freelist; CRITICAL_SECTION cs; - +SYSTEM_INFO sSysInfo; +WRAP *wrap_list = NULL, *wrap_freelist = NULL; +DD_LIFETIME *ddlt_list = NULL, *ddlt_freelist = NULL; const void* iid_to_vtbl( const GUID& riid ) { @@ -20,7 +17,7 @@ const void* iid_to_vtbl( const GUID& riid ) else if ( riid == IID_IDirectDraw4 ) xVtbl = &dd::xVtbl4; else if ( riid == IID_IDirectDraw7 ) xVtbl = &dd::xVtbl7; else if ( riid == IID_IDirectDrawSurface ) xVtbl = &dds::xVtbl1; - else if ( riid == IID_IDirectDrawSurface2 ) xVtbl = &dds::xVtbl2; + else if ( riid == IID_IDirectDrawSurface2 ) xVtbl = &dds::xVtbl2; else if ( riid == IID_IDirectDrawSurface3 ) xVtbl = &dds::xVtbl3; else if ( riid == IID_IDirectDrawSurface4 ) xVtbl = &dds::xVtbl4; else if ( riid == IID_IDirectDrawSurface7 ) xVtbl = &dds::xVtbl7; @@ -40,11 +37,11 @@ const void* iid_to_vtbl( const GUID& riid ) void* micro_alloc( int size ) { TRACE( ">" ); - static BYTE* end_region = 0; - static BYTE* end_page = 0; + static BYTE* end_region = 0; + static BYTE* end_page = 0; static BYTE* alloc_ptr = 0; - if( ( alloc_ptr + size ) >= end_page ) + if( ( alloc_ptr + size ) >= end_page ) { alloc_ptr = end_page; @@ -56,7 +53,7 @@ void* micro_alloc( int size ) } if( alloc_ptr != NULL ) - { + { TRACE( "commit a page of the reserved region" ); alloc_ptr = (BYTE*) VirtualAlloc( alloc_ptr, sSysInfo.dwPageSize, MEM_COMMIT, PAGE_READWRITE ); end_page = alloc_ptr + sSysInfo.dwPageSize; @@ -65,8 +62,8 @@ void* micro_alloc( int size ) if( alloc_ptr == NULL ) { WARN( "Allocation FAILED" ); - end_region = 0; - end_page = 0; + end_region = 0; + end_page = 0; } } @@ -76,36 +73,33 @@ void* micro_alloc( int size ) return p; } - // find existing or add a new wrapper for *ppvInterface // returns true if a new wrapper is created bool Wrap( DD_LIFETIME* dd_parent, const void* xVtbl, void** ppvInterface ) { TRACE( ">" ); - WRAP* w; + WRAP* w = wrap_list; bool bNew = false; // validate args if( ( xVtbl != NULL ) && ( ppvInterface != NULL ) && ( *ppvInterface != NULL ) ) { EnterCriticalSection( &cs ); - // search list - for( w = wrap_list; ( w != NULL ) && ( w->inner_iface != *ppvInterface ); w = w->next ); + while( ( w != NULL ) && ( w->inner_iface != *ppvInterface ) ) w = w->next; if( w != NULL ) { TRACE( "found existing wrapper" ); - if( w->xVtbl != xVtbl ){ WARN("existing wrapper is for a different type"); } *((WRAP**)ppvInterface) = w; } - else + else { TRACE( "creating new wrapper" ); if( wrap_freelist != NULL ) { // pop - w = wrap_freelist; - wrap_freelist = w->next; + w = wrap_freelist; + wrap_freelist = wrap_freelist->next; } else { @@ -113,12 +107,11 @@ bool Wrap( DD_LIFETIME* dd_parent, const void* xVtbl, void** ppvInterface ) } if( w != NULL ) { - // dd obj lifetime tracker // if( ( dd_parent != NULL )) { - if( ( ( xVtbl == &unknwn::xVtbl ) && ( dd_parent->obj == ((IUnknown*)(*ppvInterface)) ) ) || - ( ( xVtbl == &dd::xVtbl1 ) || ( xVtbl == &dd::xVtbl2 ) || ( xVtbl == &dd::xVtbl4 ) || ( xVtbl == &dd::xVtbl7 ) ) ) + if( ( xVtbl == &dd::xVtbl1 ) || ( xVtbl == &dd::xVtbl2 ) || ( xVtbl == &dd::xVtbl4 ) || ( xVtbl == &dd::xVtbl7 ) || + ( ( xVtbl == &unknwn::xVtbl ) && ( dd_parent->obj == ((IUnknown*)(*ppvInterface)) ) ) ) { TRACE( "new interface of existing dd obj" ); dd_parent->iface_cnt++; @@ -132,8 +125,8 @@ bool Wrap( DD_LIFETIME* dd_parent, const void* xVtbl, void** ppvInterface ) if( ddlt_freelist != NULL ) { // pop - dd_parent = ddlt_freelist; - ddlt_freelist = dd_parent->next; + dd_parent = ddlt_freelist; + ddlt_freelist = ddlt_freelist->next; } else { @@ -149,12 +142,11 @@ bool Wrap( DD_LIFETIME* dd_parent, const void* xVtbl, void** ppvInterface ) } } } - // construct w->xVtbl = xVtbl; w->inner_iface = *ppvInterface; w->dd_parent = dd_parent; - w->next = wrap_list; + w->next = wrap_list; wrap_list = w; // push *((WRAP**)ppvInterface) = w; // hook it ! bNew = true; @@ -165,7 +157,6 @@ bool Wrap( DD_LIFETIME* dd_parent, const void* xVtbl, void** ppvInterface ) return bNew; } - ULONG WrapRelease( WRAP* This ) { TRACE( ">" ); @@ -176,22 +167,21 @@ ULONG WrapRelease( WRAP* This ) TRACE( "interface destroyed" ); WRAP* w = wrap_list; WRAP* prev = NULL; - DD_LIFETIME* dd_parent = This->dd_parent; // if dd interface was destroyed - if( ( dd_parent != NULL ) && - ( (( This->xVtbl == &unknwn::xVtbl ) && ( This->unknwn == dd_parent->obj )) || + if( ( This->dd_parent != NULL ) && ( This->xVtbl == &dd::xVtbl1 ) || ( This->xVtbl == &dd::xVtbl2 ) || - ( This->xVtbl == &dd::xVtbl4 ) || ( This->xVtbl == &dd::xVtbl7 ) ) ) + ( This->xVtbl == &dd::xVtbl4 ) || ( This->xVtbl == &dd::xVtbl7 ) || + (( This->xVtbl == &unknwn::xVtbl ) && ( This->unknwn == This->dd_parent->obj )) ) { - dd_parent->iface_cnt--; - if( dd_parent->iface_cnt == 0 ) + This->dd_parent->iface_cnt--; + if( This->dd_parent->iface_cnt == 0 ) { TRACE( "dd obj destroyed" ); // destroy ALL wraps that have a matching dd_parent while( w != NULL ) { - if( w->dd_parent == dd_parent ) // if match + if( w->dd_parent == This->dd_parent ) // if match { TRACE( "destroyed child\n" ); // move to freelist @@ -202,7 +192,7 @@ ULONG WrapRelease( WRAP* This ) wrap_freelist = w; // push w = prev->next; // continue } - else + else { wrap_list = w->next; w->next = wrap_freelist; @@ -211,18 +201,16 @@ ULONG WrapRelease( WRAP* This ) } } else // else continue search - { + { prev = w; w = w->next; } } - // move dd_parent to the freelist + DD_LIFETIME* d = ddlt_list; DD_LIFETIME* d_prev = NULL; - DD_LIFETIME* d; - for( d = ddlt_list; ( d != NULL ) && ( d != dd_parent ); d = d->next ) d_prev = d; // find previons link - if( d == NULL ){ WARN( "wrap not in list" ); } - else + while( ( d != NULL ) && ( d != This->dd_parent ) ) d_prev = d, d = d->next; // find previons link + if( d != NULL ) { if( d_prev != NULL ) d_prev->next = d->next; else ddlt_list = d->next; @@ -234,9 +222,8 @@ ULONG WrapRelease( WRAP* This ) else { // move This to the freelist - for( w = wrap_list; ( w != NULL ) && ( w != This ); w = w->next ) prev = w; // find previons link - if( w == NULL ){ WARN( "wrap not in list" ); } - else + while( ( w != NULL ) && ( w != This ) ) prev = w, w = w->next; // find previons link + if( w != NULL ) { if( prev != NULL ) prev->next = w->next; else wrap_list = w->next; @@ -249,7 +236,6 @@ ULONG WrapRelease( WRAP* This ) return dwCount; } - HRESULT __stdcall WrapEnumSurfacesCallback( LPDIRECTDRAWSURFACE lpDDSurface, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext ) { PROLOGUE; @@ -260,7 +246,6 @@ HRESULT __stdcall WrapEnumSurfacesCallback( LPDIRECTDRAWSURFACE lpDDSurface, LPD EPILOGUE( hResult ); } - // all versions of dd interfaces share the same functions ... ( for ease-of-use ) // // all versions of dds interfaces share the same functions ... ( for ease-of-use ) // // ... so a little extra work is needed to distinguish between different versions // @@ -280,7 +265,6 @@ const void* dds_to_dd_vtbl( WRAP* This ) return &dd::xVtbl2; } - // There are no guarantees that an interface passed as argument is wrapped or not NULL // IDirectDraw* GetInnerInterface( IDirectDraw* iface ) { @@ -345,4 +329,3 @@ IDirectDrawPalette* GetInnerInterface( IDirectDrawPalette* iface ) return iface; } - diff --git a/wrap.h b/wrap.h index 4d8ab5f..19b95f9 100644 --- a/wrap.h +++ b/wrap.h @@ -1,13 +1,11 @@ -#pragma once - // when a dd object is destroyed all children are also destroyed ( surfaces, etc. ) // we've got no good way to known if an dd obj is destroyed -// a dd obj is destroyed when it has no active interfaces... +// a dd obj is destroyed when it has no active interfaces... // a dd object can have many interfaces at once... IDirectDraw, IDirectDraw2, IDirectDraw4, IDirectDraw7 and IUnknown struct DD_LIFETIME { IUnknown* obj; - unsigned long iface_cnt; + unsigned long iface_cnt; DD_LIFETIME* next; }; @@ -37,7 +35,6 @@ struct WRAP WRAP* next; // for use in unordered hash map }; - struct EnumStruct { const void* xVtbl; @@ -50,16 +47,15 @@ struct EnumStruct extern CRITICAL_SECTION cs; extern SYSTEM_INFO sSysInfo; -bool Wrap( DD_LIFETIME* dd_parent, const void* xVtbl, void** ppvInterface ); const void* dd_to_dds_vtbl( WRAP* This ); const void* dds_to_dd_vtbl( WRAP* This ); const void* iid_to_vtbl( const GUID& riid ); +bool Wrap( DD_LIFETIME* dd_parent, const void* xVtbl, void** ppvInterface ); ULONG WrapRelease( WRAP* This ); HRESULT __stdcall WrapEnumSurfacesCallback( LPDIRECTDRAWSURFACE lpDDSurface, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext ); -// + IDirectDraw* GetInnerInterface( IDirectDraw* iface ); IDirectDrawSurface* GetInnerInterface( IDirectDrawSurface* iface ); IDirectDrawClipper* GetInnerInterface( IDirectDrawClipper* iface ); IDirectDrawPalette* GetInnerInterface( IDirectDrawPalette* iface ); -