1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Removed the GetDDInterface override

Fixes a crash in UEFA Challenge (issue #50).
This commit is contained in:
narzoul 2019-08-11 12:48:02 +02:00
parent bb6092e0bd
commit 9b24a9b306
12 changed files with 31 additions and 96 deletions

View File

@ -384,7 +384,7 @@ namespace D3dDdi
{
lastDisplaySettingsUniqueness = currentDisplaySettingsUniqueness;
CompatPtr<IUnknown> ddUnk;
primary.get()->lpVtbl->GetDDInterface(primary, reinterpret_cast<void**>(&ddUnk.getRef()));
primary->GetDDInterface(primary, reinterpret_cast<void**>(&ddUnk.getRef()));
CompatPtr<IDirectDraw7> dd7(ddUnk);
DDDEVICEIDENTIFIER2 di = {};

View File

@ -7,17 +7,6 @@
namespace DDraw
{
template <typename TDirectDraw>
void* getDdObject(TDirectDraw& dd)
{
return reinterpret_cast<void**>(&dd)[1];
}
template void* getDdObject(IDirectDraw&);
template void* getDdObject(IDirectDraw2&);
template void* getDdObject(IDirectDraw4&);
template void* getDdObject(IDirectDraw7&);
DDSURFACEDESC2 getDisplayMode(CompatRef<IDirectDraw7> dd)
{
DDSURFACEDESC2 dm = {};

View File

@ -9,9 +9,6 @@
namespace DDraw
{
template <typename TDirectDraw>
void* getDdObject(TDirectDraw& dd);
DDSURFACEDESC2 getDisplayMode(CompatRef<IDirectDraw7> dd);
DDPIXELFORMAT getRgbPixelFormat(DWORD bpp);
void suppressEmulatedDirectDraw(GUID*& guid);

View File

@ -70,19 +70,6 @@ namespace DDraw
SET_COMPAT_METHOD(Restore);
SET_COMPAT_METHOD(SetPalette);
SET_COMPAT_METHOD(Unlock);
setCompatVtable2(vtable);
}
template <typename TSurface>
void DirectDrawSurface<TSurface>::setCompatVtable2(Vtable<TSurface>& vtable)
{
SET_COMPAT_METHOD(GetDDInterface);
}
template <>
void DirectDrawSurface<IDirectDrawSurface>::setCompatVtable2(Vtable<IDirectDrawSurface>&)
{
}
template DirectDrawSurface<IDirectDrawSurface>;

View File

@ -31,9 +31,6 @@ namespace DDraw
typedef typename Types<TSurface>::TSurfaceDesc TSurfaceDesc;
static void setCompatVtable(Vtable<TSurface>& vtable);
private:
static void setCompatVtable2(Vtable<TSurface>& vtable);
};
}

View File

@ -110,11 +110,11 @@ namespace DDraw
void PrimarySurface::createImpl()
{
m_impl.reset(new PrimarySurfaceImpl<IDirectDrawSurface>());
m_impl2.reset(new PrimarySurfaceImpl<IDirectDrawSurface2>());
m_impl3.reset(new PrimarySurfaceImpl<IDirectDrawSurface3>());
m_impl4.reset(new PrimarySurfaceImpl<IDirectDrawSurface4>());
m_impl7.reset(new PrimarySurfaceImpl<IDirectDrawSurface7>());
m_impl.reset(new PrimarySurfaceImpl<IDirectDrawSurface>(this));
m_impl2.reset(new PrimarySurfaceImpl<IDirectDrawSurface2>(this));
m_impl3.reset(new PrimarySurfaceImpl<IDirectDrawSurface3>(this));
m_impl4.reset(new PrimarySurfaceImpl<IDirectDrawSurface4>(this));
m_impl7.reset(new PrimarySurfaceImpl<IDirectDrawSurface7>(this));
}
HRESULT PrimarySurface::flipToGdiSurface()

View File

@ -73,6 +73,12 @@ namespace
namespace DDraw
{
template <typename TSurface>
PrimarySurfaceImpl<TSurface>::PrimarySurfaceImpl(Surface* data)
: SurfaceImpl(data)
{
}
template <typename TSurface>
HRESULT PrimarySurfaceImpl<TSurface>::Blt(
TSurface* This, LPRECT lpDestRect, TSurface* lpDDSrcSurface, LPRECT lpSrcRect,

View File

@ -13,6 +13,8 @@ namespace DDraw
class PrimarySurfaceImpl : public SurfaceImpl<TSurface>
{
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,

View File

@ -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<IUnknown> ddUnk;
dds.get().lpVtbl->GetDDInterface(&dds, reinterpret_cast<void**>(&ddUnk.getRef()));
CompatPtr<IDirectDraw7> 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<IDirectDrawSurface>());
m_impl2.reset(new SurfaceImpl<IDirectDrawSurface2>());
m_impl3.reset(new SurfaceImpl<IDirectDrawSurface3>());
m_impl4.reset(new SurfaceImpl<IDirectDrawSurface4>());
m_impl7.reset(new SurfaceImpl<IDirectDrawSurface7>());
m_impl.reset(new SurfaceImpl<IDirectDrawSurface>(this));
m_impl2.reset(new SurfaceImpl<IDirectDrawSurface2>(this));
m_impl3.reset(new SurfaceImpl<IDirectDrawSurface3>(this));
m_impl4.reset(new SurfaceImpl<IDirectDrawSurface4>(this));
m_impl7.reset(new SurfaceImpl<IDirectDrawSurface7>(this));
}
template <>

View File

@ -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 <typename TSurface>
SurfaceImpl<TSurface>::SurfaceImpl(Surface* data)
: m_data(data)
{
}
template <typename TSurface>
SurfaceImpl<TSurface>::~SurfaceImpl()
{
@ -83,16 +76,6 @@ namespace DDraw
return result;
}
template <typename TSurface>
HRESULT SurfaceImpl2<TSurface>::GetDDInterface(TSurface* /*This*/, LPVOID* lplpDD)
{
DirectDrawInterface dd = {};
dd.vtable = static_cast<const void*>(CompatVtable<IDirectDraw7Vtbl>::s_origVtablePtr);
dd.ddObject = m_data->m_ddObject;
return CompatVtable<IDirectDrawVtbl>::s_origVtable.QueryInterface(
reinterpret_cast<IDirectDraw*>(&dd), IID_IDirectDraw, lplpDD);
}
template <typename TSurface>
HRESULT SurfaceImpl<TSurface>::GetFlipStatus(TSurface* This, DWORD dwFlags)
{

View File

@ -12,27 +12,14 @@ namespace DDraw
class Surface;
template <typename TSurface>
class SurfaceImpl2
{
public:
SurfaceImpl2() : m_data(nullptr) {}
virtual HRESULT GetDDInterface(TSurface* This, LPVOID* lplpDD);
protected:
friend class Surface;
Surface* m_data;
};
template <typename TSurface>
class SurfaceImpl : public SurfaceImpl2<TSurface>
class SurfaceImpl
{
public:
typedef typename Types<TSurface>::TSurfaceDesc TSurfaceDesc;
typedef typename Types<TSurface>::TDdsCaps TDdsCaps;
typedef typename Types<TSurface>::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;
};
}

View File

@ -131,7 +131,7 @@ namespace Gdi
auto primary(DDraw::PrimarySurface::getPrimary());
CompatPtr<IUnknown> ddUnk;
primary.get()->lpVtbl->GetDDInterface(primary, reinterpret_cast<void**>(&ddUnk.getRef()));
primary->GetDDInterface(primary, reinterpret_cast<void**>(&ddUnk.getRef()));
CompatPtr<IDirectDraw7> dd(ddUnk);
CompatPtr<IDirectDrawSurface7> surface;