diff --git a/DDrawCompat/CompatDirectDraw.cpp b/DDrawCompat/CompatDirectDraw.cpp index 4e946a5..d7eb1b6 100644 --- a/DDrawCompat/CompatDirectDraw.cpp +++ b/DDrawCompat/CompatDirectDraw.cpp @@ -53,10 +53,15 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw::CreateSurface( (lpDDSurfaceDesc->ddsCaps.dwCaps & (DDSCAPS_3DDEVICE | DDSCAPS_BACKBUFFER | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_OVERLAY | DDSCAPS_TEXTURE))) { - lpDDSurfaceDesc->dwFlags |= DDSD_PIXELFORMAT; - lpDDSurfaceDesc->ddpfPixelFormat = CompatPrimarySurface::displayMode.pixelFormat; + TSurfaceDesc desc = *lpDDSurfaceDesc; + desc.dwFlags |= DDSD_PIXELFORMAT; + desc.ddpfPixelFormat = CompatPrimarySurface::displayMode.pixelFormat; + result = s_origVtable.CreateSurface(This, &desc, lplpDDSurface, pUnkOuter); + } + else + { + result = s_origVtable.CreateSurface(This, lpDDSurfaceDesc, lplpDDSurface, pUnkOuter); } - result = s_origVtable.CreateSurface(This, lpDDSurfaceDesc, lplpDDSurface, pUnkOuter); } if (SUCCEEDED(result)) diff --git a/DDrawCompat/CompatDirectDrawSurface.cpp b/DDrawCompat/CompatDirectDrawSurface.cpp index 3018ed0..b313a16 100644 --- a/DDrawCompat/CompatDirectDrawSurface.cpp +++ b/DDrawCompat/CompatDirectDrawSurface.cpp @@ -47,7 +47,8 @@ namespace DDBLTFX fx = {}; fx.dwSize = sizeof(fx); - surface.lpVtbl->Blt(&surface, nullptr, nullptr, nullptr, DDBLT_COLORFILL | DDBLT_WAIT, &fx); + CompatDirectDrawSurface::s_origVtable.Blt( + &surface, nullptr, nullptr, nullptr, DDBLT_COLORFILL | DDBLT_WAIT, &fx); } HRESULT WINAPI enumSurfacesCallback( @@ -55,16 +56,17 @@ namespace LPDDSURFACEDESC2 lpDDSurfaceDesc, LPVOID lpContext) { - auto visitedSurfaces = *static_cast*>(lpContext); + auto& visitedSurfaces = *static_cast*>(lpContext); if (visitedSurfaces.find(lpDDSurface) == visitedSurfaces.end()) { visitedSurfaces.insert(lpDDSurface); fixSurfacePtr(*lpDDSurface, *lpDDSurfaceDesc); - lpDDSurface->lpVtbl->EnumAttachedSurfaces(lpDDSurface, &visitedSurfaces, &enumSurfacesCallback); + CompatDirectDrawSurface::s_origVtable.EnumAttachedSurfaces( + lpDDSurface, lpContext, &enumSurfacesCallback); } - lpDDSurface->lpVtbl->Release(lpDDSurface); + CompatDirectDrawSurface::s_origVtable.Release(lpDDSurface); return DDENUMRET_OK; } @@ -72,11 +74,12 @@ namespace { DDSURFACEDESC2 desc = {}; desc.dwSize = sizeof(desc); - surface.lpVtbl->GetSurfaceDesc(&surface, &desc); + CompatDirectDrawSurface::s_origVtable.GetSurfaceDesc(&surface, &desc); fixSurfacePtr(surface, desc); std::set visitedSurfaces{ &surface }; - surface.lpVtbl->EnumAttachedSurfaces(&surface, &visitedSurfaces, &enumSurfacesCallback); + CompatDirectDrawSurface::s_origVtable.EnumAttachedSurfaces( + &surface, &visitedSurfaces, &enumSurfacesCallback); } IDirectDrawSurface7* getMirroredSurface(IDirectDrawSurface7& surface, RECT* srcRect, DWORD mirrorFx) diff --git a/DDrawCompat/CompatPrimarySurface.cpp b/DDrawCompat/CompatPrimarySurface.cpp index 29e5fa8..d570042 100644 --- a/DDrawCompat/CompatPrimarySurface.cpp +++ b/DDrawCompat/CompatPrimarySurface.cpp @@ -8,6 +8,8 @@ namespace { void onRelease() { + Compat::LogEnter("CompatPrimarySurface::onRelease"); + CompatPrimarySurface::surface = nullptr; CompatPrimarySurface::palette = nullptr; CompatPrimarySurface::width = 0; @@ -23,6 +25,8 @@ namespace CompatDirectDrawSurface::resetPrimarySurfacePtr(); RealPrimarySurface::release(); + + Compat::LogLeave("CompatPrimarySurface::onRelease"); } } diff --git a/DDrawCompat/RealPrimarySurface.cpp b/DDrawCompat/RealPrimarySurface.cpp index 4ef6683..7aa95a0 100644 --- a/DDrawCompat/RealPrimarySurface.cpp +++ b/DDrawCompat/RealPrimarySurface.cpp @@ -85,13 +85,14 @@ namespace desc.ddpfPixelFormat = CompatPrimarySurface::displayMode.pixelFormat; desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; - typename Types::TCreatedSurface* surface = nullptr; - HRESULT result = dd.lpVtbl->CreateSurface(&dd, &desc, &surface, nullptr); + typedef typename Types::TCreatedSurface TCreatedSurface; + TCreatedSurface* surface = nullptr; + HRESULT result = CompatDirectDraw::s_origVtable.CreateSurface(&dd, &desc, &surface, nullptr); if (SUCCEEDED(result)) { - surface->lpVtbl->QueryInterface( + CompatDirectDrawSurface::s_origVtable.QueryInterface( surface, IID_IDirectDrawSurface7, reinterpret_cast(&g_paletteConverterSurface)); - surface->lpVtbl->Release(surface); + CompatDirectDrawSurface::s_origVtable.Release(surface); } return result; @@ -106,6 +107,8 @@ namespace void onRelease() { + Compat::LogEnter("RealPrimarySurface::onRelease"); + g_frontBuffer = nullptr; g_backBuffer = nullptr; if (g_paletteConverterSurface) @@ -118,6 +121,8 @@ namespace g_updateEvent = nullptr; ZeroMemory(&RealPrimarySurface::s_surfaceDesc, sizeof(RealPrimarySurface::s_surfaceDesc)); + + Compat::LogLeave("RealPrimarySurface::onRelease"); } void updateNow() @@ -336,9 +341,11 @@ void RealPrimarySurface::setClipper(LPDIRECTDRAWCLIPPER clipper) void RealPrimarySurface::setPalette(LPDIRECTDRAWPALETTE palette) { + auto& origVtable = CompatDirectDrawSurface::s_origVtable; + if (g_paletteConverterSurface && CompatPrimarySurface::pixelFormat.dwRGBBitCount <= 8) { - HRESULT result = g_paletteConverterSurface->lpVtbl->SetPalette(g_paletteConverterSurface, palette); + HRESULT result = origVtable.SetPalette(g_paletteConverterSurface, palette); if (FAILED(result)) { LOG_ONCE("Failed to set the palette on the converter surface: " << result); @@ -347,14 +354,17 @@ void RealPrimarySurface::setPalette(LPDIRECTDRAWPALETTE palette) if (s_surfaceDesc.ddpfPixelFormat.dwRGBBitCount <= 8) { - HRESULT result = g_frontBuffer->lpVtbl->SetPalette(g_frontBuffer, palette); + HRESULT result = origVtable.SetPalette(g_frontBuffer, palette); if (FAILED(result) && DDERR_NOPALETTEATTACHED != result) { LOG_ONCE("Failed to set the palette on the real primary surface: " << result); } } - updatePalette(); + if (palette) + { + updatePalette(); + } } void RealPrimarySurface::update()