From 9b24a9b306aa22c3a8f4d55525cf80bf63bc0c6b Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 11 Aug 2019 12:48:02 +0200 Subject: [PATCH] Removed the GetDDInterface override Fixes a crash in UEFA Challenge (issue #50). --- DDrawCompat/D3dDdi/KernelModeThunks.cpp | 2 +- DDrawCompat/DDraw/DirectDraw.cpp | 11 ------- DDrawCompat/DDraw/DirectDraw.h | 3 -- DDrawCompat/DDraw/DirectDrawSurface.cpp | 13 --------- DDrawCompat/DDraw/DirectDrawSurface.h | 3 -- DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp | 10 +++---- .../DDraw/Surfaces/PrimarySurfaceImpl.cpp | 6 ++++ .../DDraw/Surfaces/PrimarySurfaceImpl.h | 2 ++ DDrawCompat/DDraw/Surfaces/Surface.cpp | 27 ++++------------- DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp | 29 ++++--------------- DDrawCompat/DDraw/Surfaces/SurfaceImpl.h | 19 +++--------- DDrawCompat/Gdi/VirtualScreen.cpp | 2 +- 12 files changed, 31 insertions(+), 96 deletions(-) diff --git a/DDrawCompat/D3dDdi/KernelModeThunks.cpp b/DDrawCompat/D3dDdi/KernelModeThunks.cpp index c0aa293..8c14394 100644 --- a/DDrawCompat/D3dDdi/KernelModeThunks.cpp +++ b/DDrawCompat/D3dDdi/KernelModeThunks.cpp @@ -384,7 +384,7 @@ namespace D3dDdi { lastDisplaySettingsUniqueness = currentDisplaySettingsUniqueness; CompatPtr ddUnk; - primary.get()->lpVtbl->GetDDInterface(primary, reinterpret_cast(&ddUnk.getRef())); + primary->GetDDInterface(primary, reinterpret_cast(&ddUnk.getRef())); CompatPtr dd7(ddUnk); DDDEVICEIDENTIFIER2 di = {}; diff --git a/DDrawCompat/DDraw/DirectDraw.cpp b/DDrawCompat/DDraw/DirectDraw.cpp index 833769d..6e55120 100644 --- a/DDrawCompat/DDraw/DirectDraw.cpp +++ b/DDrawCompat/DDraw/DirectDraw.cpp @@ -7,17 +7,6 @@ namespace DDraw { - template - void* getDdObject(TDirectDraw& dd) - { - return reinterpret_cast(&dd)[1]; - } - - template void* getDdObject(IDirectDraw&); - template void* getDdObject(IDirectDraw2&); - template void* getDdObject(IDirectDraw4&); - template void* getDdObject(IDirectDraw7&); - DDSURFACEDESC2 getDisplayMode(CompatRef dd) { DDSURFACEDESC2 dm = {}; diff --git a/DDrawCompat/DDraw/DirectDraw.h b/DDrawCompat/DDraw/DirectDraw.h index 98aa794..8387b9f 100644 --- a/DDrawCompat/DDraw/DirectDraw.h +++ b/DDrawCompat/DDraw/DirectDraw.h @@ -9,9 +9,6 @@ namespace DDraw { - template - void* getDdObject(TDirectDraw& dd); - DDSURFACEDESC2 getDisplayMode(CompatRef dd); DDPIXELFORMAT getRgbPixelFormat(DWORD bpp); void suppressEmulatedDirectDraw(GUID*& guid); diff --git a/DDrawCompat/DDraw/DirectDrawSurface.cpp b/DDrawCompat/DDraw/DirectDrawSurface.cpp index 61b7aba..51cc642 100644 --- a/DDrawCompat/DDraw/DirectDrawSurface.cpp +++ b/DDrawCompat/DDraw/DirectDrawSurface.cpp @@ -70,19 +70,6 @@ namespace DDraw SET_COMPAT_METHOD(Restore); SET_COMPAT_METHOD(SetPalette); SET_COMPAT_METHOD(Unlock); - - setCompatVtable2(vtable); - } - - template - void DirectDrawSurface::setCompatVtable2(Vtable& vtable) - { - SET_COMPAT_METHOD(GetDDInterface); - } - - template <> - void DirectDrawSurface::setCompatVtable2(Vtable&) - { } template DirectDrawSurface; diff --git a/DDrawCompat/DDraw/DirectDrawSurface.h b/DDrawCompat/DDraw/DirectDrawSurface.h index a13ab94..91c8f18 100644 --- a/DDrawCompat/DDraw/DirectDrawSurface.h +++ b/DDrawCompat/DDraw/DirectDrawSurface.h @@ -31,9 +31,6 @@ namespace DDraw typedef typename Types::TSurfaceDesc TSurfaceDesc; static void setCompatVtable(Vtable& vtable); - - private: - static void setCompatVtable2(Vtable& vtable); }; } diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index 0d10534..59e2e25 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -110,11 +110,11 @@ namespace DDraw void PrimarySurface::createImpl() { - m_impl.reset(new PrimarySurfaceImpl()); - m_impl2.reset(new PrimarySurfaceImpl()); - m_impl3.reset(new PrimarySurfaceImpl()); - m_impl4.reset(new PrimarySurfaceImpl()); - m_impl7.reset(new PrimarySurfaceImpl()); + m_impl.reset(new PrimarySurfaceImpl(this)); + m_impl2.reset(new PrimarySurfaceImpl(this)); + m_impl3.reset(new PrimarySurfaceImpl(this)); + m_impl4.reset(new PrimarySurfaceImpl(this)); + m_impl7.reset(new PrimarySurfaceImpl(this)); } HRESULT PrimarySurface::flipToGdiSurface() diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp index 44a3aa8..a3fd69c 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp @@ -73,6 +73,12 @@ namespace namespace DDraw { + template + PrimarySurfaceImpl::PrimarySurfaceImpl(Surface* data) + : SurfaceImpl(data) + { + } + template HRESULT PrimarySurfaceImpl::Blt( TSurface* This, LPRECT lpDestRect, TSurface* lpDDSrcSurface, LPRECT lpSrcRect, diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.h b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.h index c35d06d..b6bcb61 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.h +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.h @@ -13,6 +13,8 @@ namespace DDraw class PrimarySurfaceImpl : public SurfaceImpl { public: + PrimarySurfaceImpl(Surface* data); + virtual HRESULT Blt(TSurface* This, LPRECT lpDestRect, TSurface* lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx) override; virtual HRESULT BltFast(TSurface* This, DWORD dwX, DWORD dwY, diff --git a/DDrawCompat/DDraw/Surfaces/Surface.cpp b/DDrawCompat/DDraw/Surfaces/Surface.cpp index b964f43..f0584f1 100644 --- a/DDrawCompat/DDraw/Surfaces/Surface.cpp +++ b/DDrawCompat/DDraw/Surfaces/Surface.cpp @@ -3,11 +3,9 @@ #include "Common/CompatPtr.h" #include "D3dDdi/Device.h" #include "D3dDdi/Resource.h" -#include "DDraw/DirectDraw.h" #include "DDraw/DirectDrawSurface.h" #include "DDraw/Surfaces/Surface.h" #include "DDraw/Surfaces/SurfaceImpl.h" -#include "Win32/DisplayMode.h" // {C62D8849-DFAC-4454-A1E8-DA67446426BA} DEFINE_GUID(IID_CompatSurfacePrivateData, @@ -36,8 +34,7 @@ namespace DDraw } Surface::Surface(Surface* rootSurface) - : m_ddObject(nullptr) - , m_refCount(0) + : m_refCount(0) , m_rootSurface(rootSurface ? rootSurface : this) { } @@ -83,20 +80,8 @@ namespace DDraw if (SUCCEEDED(dds->SetPrivateData(&dds, IID_CompatSurfacePrivateData, privateData.get(), sizeof(privateData.get()), DDSPD_IUNKNOWNPOINTER))) { - CompatPtr ddUnk; - dds.get().lpVtbl->GetDDInterface(&dds, reinterpret_cast(&ddUnk.getRef())); - CompatPtr dd(ddUnk); - privateData->createImpl(); - privateData->m_impl->m_data = privateData.get(); - privateData->m_impl2->m_data = privateData.get(); - privateData->m_impl3->m_data = privateData.get(); - privateData->m_impl4->m_data = privateData.get(); - privateData->m_impl7->m_data = privateData.get(); - privateData->m_surface = &dds; - privateData->m_ddObject = DDraw::getDdObject(*dd); - privateData.release(); } } @@ -181,11 +166,11 @@ namespace DDraw void Surface::createImpl() { - m_impl.reset(new SurfaceImpl()); - m_impl2.reset(new SurfaceImpl()); - m_impl3.reset(new SurfaceImpl()); - m_impl4.reset(new SurfaceImpl()); - m_impl7.reset(new SurfaceImpl()); + m_impl.reset(new SurfaceImpl(this)); + m_impl2.reset(new SurfaceImpl(this)); + m_impl3.reset(new SurfaceImpl(this)); + m_impl4.reset(new SurfaceImpl(this)); + m_impl7.reset(new SurfaceImpl(this)); } template <> diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp index 1d24750..6abb61a 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp @@ -6,21 +6,14 @@ #include "DDraw/Surfaces/Surface.h" #include "DDraw/Surfaces/SurfaceImpl.h" -namespace -{ - struct DirectDrawInterface - { - const void* vtable; - void* ddObject; - DirectDrawInterface* next; - DWORD refCount; - DWORD unknown1; - DWORD unknown2; - }; -} - namespace DDraw { + template + SurfaceImpl::SurfaceImpl(Surface* data) + : m_data(data) + { + } + template SurfaceImpl::~SurfaceImpl() { @@ -83,16 +76,6 @@ namespace DDraw return result; } - template - HRESULT SurfaceImpl2::GetDDInterface(TSurface* /*This*/, LPVOID* lplpDD) - { - DirectDrawInterface dd = {}; - dd.vtable = static_cast(CompatVtable::s_origVtablePtr); - dd.ddObject = m_data->m_ddObject; - return CompatVtable::s_origVtable.QueryInterface( - reinterpret_cast(&dd), IID_IDirectDraw, lplpDD); - } - template HRESULT SurfaceImpl::GetFlipStatus(TSurface* This, DWORD dwFlags) { diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.h b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.h index c57bdd7..97b332c 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.h +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.h @@ -12,27 +12,14 @@ namespace DDraw class Surface; template - class SurfaceImpl2 - { - public: - SurfaceImpl2() : m_data(nullptr) {} - - virtual HRESULT GetDDInterface(TSurface* This, LPVOID* lplpDD); - - protected: - friend class Surface; - - Surface* m_data; - }; - - template - class SurfaceImpl : public SurfaceImpl2 + class SurfaceImpl { public: typedef typename Types::TSurfaceDesc TSurfaceDesc; typedef typename Types::TDdsCaps TDdsCaps; typedef typename Types::TUnlockParam TUnlockParam; + SurfaceImpl(Surface* data); virtual ~SurfaceImpl(); virtual HRESULT Blt(TSurface* This, LPRECT lpDestRect, TSurface* lpDDSrcSurface, LPRECT lpSrcRect, @@ -58,5 +45,7 @@ namespace DDraw private: bool waitForFlip(TSurface* This, DWORD flags, DWORD waitFlag, DWORD doNotWaitFlag); + + Surface* m_data; }; } diff --git a/DDrawCompat/Gdi/VirtualScreen.cpp b/DDrawCompat/Gdi/VirtualScreen.cpp index a7fbb2a..3e9c29f 100644 --- a/DDrawCompat/Gdi/VirtualScreen.cpp +++ b/DDrawCompat/Gdi/VirtualScreen.cpp @@ -131,7 +131,7 @@ namespace Gdi auto primary(DDraw::PrimarySurface::getPrimary()); CompatPtr ddUnk; - primary.get()->lpVtbl->GetDDInterface(primary, reinterpret_cast(&ddUnk.getRef())); + primary->GetDDInterface(primary, reinterpret_cast(&ddUnk.getRef())); CompatPtr dd(ddUnk); CompatPtr surface;