diff --git a/DDrawCompat/Common/CompatQueryInterface.h b/DDrawCompat/Common/CompatQueryInterface.h index 2d445d6..cf1d977 100644 --- a/DDrawCompat/Common/CompatQueryInterface.h +++ b/DDrawCompat/Common/CompatQueryInterface.h @@ -91,7 +91,8 @@ namespace Compat template void queryInterface(IUnknown& origIntf, NewIntf*& newIntf) { - CompatVtableBase::getOrigVtable(reinterpret_cast(origIntf)).QueryInterface( + auto vtable(reinterpret_cast(origIntf).lpVtbl); + CompatVtable>::getOrigVtable(*vtable).QueryInterface( reinterpret_cast(&origIntf), getIntfId(), reinterpret_cast(&newIntf)); @@ -100,7 +101,7 @@ namespace Compat template void queryInterface(OrigIntf& origIntf, IUnknown*& newIntf) { - CompatVtableBase::getOrigVtable(origIntf).QueryInterface( + CompatVtable>::getOrigVtable(*origIntf.lpVtbl).QueryInterface( &origIntf, IID_IUnknown, reinterpret_cast(&newIntf)); } @@ -108,7 +109,7 @@ namespace Compat std::enable_if_t::value> queryInterface(OrigIntf& origIntf, NewIntf*& newIntf) { - CompatVtableBase::getOrigVtable(origIntf).QueryInterface( + CompatVtable>::getOrigVtable(*origIntf.lpVtbl).QueryInterface( &origIntf, getIntfId(), reinterpret_cast(&newIntf)); } diff --git a/DDrawCompat/Common/CompatRef.h b/DDrawCompat/Common/CompatRef.h index 38d2509..34e96b6 100644 --- a/DDrawCompat/Common/CompatRef.h +++ b/DDrawCompat/Common/CompatRef.h @@ -12,7 +12,7 @@ public: const Vtable* operator->() const { - return &CompatVtableBase::getOrigVtable(m_intf); + return &CompatVtable>::getOrigVtable(*m_intf.lpVtbl); } Intf* operator&() const diff --git a/DDrawCompat/Common/CompatVtable.h b/DDrawCompat/Common/CompatVtable.h index 301787f..ed45926 100644 --- a/DDrawCompat/Common/CompatVtable.h +++ b/DDrawCompat/Common/CompatVtable.h @@ -9,44 +9,46 @@ #include "Common/VtableVisitor.h" #include "DDraw/ScopedThreadLock.h" +#define SET_COMPAT_VTABLE(Vtable, CompatInterface) \ + namespace Compat \ + { \ + inline void setCompatVtable(Vtable& vtable) \ + { \ + CompatInterface::setCompatVtable(vtable); \ + } \ + } + template using Vtable = typename std::remove_pointer::type; -template -class CompatVtableBase +template +class CompatVtable { public: - typedef Interface Interface; - - static const Vtable& getOrigVtable(Interface& intf) + static const Vtable& getOrigVtable(const Vtable& vtable) { - return s_origVtable.AddRef ? s_origVtable : *intf.lpVtbl; + return s_origVtable.AddRef ? s_origVtable : vtable; } - static Vtable s_origVtable; - static const Vtable* s_origVtablePtr; -}; - -template -class CompatVtable : public CompatVtableBase -{ -public: - static void hookVtable(const Vtable* vtable) + static void hookVtable(const Vtable* vtable) { if (vtable && !s_origVtablePtr) { s_origVtablePtr = vtable; InitVisitor visitor(*vtable); - forEach>(visitor); + forEach(visitor); } } + static Vtable s_origVtable; + static const Vtable* s_origVtablePtr; + private: class InitVisitor { public: - InitVisitor(const Vtable& origVtable) : m_origVtable(origVtable) {} + InitVisitor(const Vtable& origVtable) : m_origVtable(origVtable) {} template void visit() @@ -137,38 +139,38 @@ private: #endif } - const Vtable& m_origVtable; + const Vtable& m_origVtable; }; - static Vtable createCompatVtable() + static Vtable createCompatVtable() { - Vtable vtable = {}; - CompatInterface::setCompatVtable(vtable); + Vtable vtable = {}; + Compat::setCompatVtable(vtable); return vtable; } - static Vtable& getCompatVtable() + static Vtable& getCompatVtable() { - static Vtable vtable(createCompatVtable()); + static Vtable vtable(createCompatVtable()); return vtable; } - static Vtable s_compatVtable; - static Vtable s_threadSafeVtable; + static Vtable s_compatVtable; + static Vtable s_threadSafeVtable; static std::map, std::string> s_funcNames; }; -template -Vtable CompatVtableBase::s_origVtable = {}; +template +Vtable CompatVtable::s_origVtable = {}; -template -const Vtable* CompatVtableBase::s_origVtablePtr = nullptr; +template +const Vtable* CompatVtable::s_origVtablePtr = nullptr; -template -Vtable CompatVtable::s_compatVtable(getCompatVtable()); +template +Vtable CompatVtable::s_compatVtable(getCompatVtable()); -template -Vtable CompatVtable::s_threadSafeVtable = {}; +template +Vtable CompatVtable::s_threadSafeVtable = {}; -template -std::map, std::string> CompatVtable::s_funcNames; +template +std::map, std::string> CompatVtable::s_funcNames; diff --git a/DDrawCompat/Common/CompatWeakPtr.h b/DDrawCompat/Common/CompatWeakPtr.h index 909d082..9c79cc0 100644 --- a/DDrawCompat/Common/CompatWeakPtr.h +++ b/DDrawCompat/Common/CompatWeakPtr.h @@ -17,7 +17,7 @@ public: const Vtable* operator->() const { - return &CompatVtableBase::getOrigVtable(*m_intf); + return &CompatVtable>::getOrigVtable(*m_intf->lpVtbl); } operator Intf*() const diff --git a/DDrawCompat/D3dDdi/AdapterCallbacks.h b/DDrawCompat/D3dDdi/AdapterCallbacks.h index 6e8743b..823bcca 100644 --- a/DDrawCompat/D3dDdi/AdapterCallbacks.h +++ b/DDrawCompat/D3dDdi/AdapterCallbacks.h @@ -5,10 +5,11 @@ namespace D3dDdi { - class AdapterCallbacks : - public CompatVtable + class AdapterCallbacks : public CompatVtable { public: static void setCompatVtable(D3DDDI_ADAPTERCALLBACKS& vtable); }; } + +SET_COMPAT_VTABLE(D3DDDI_ADAPTERCALLBACKS, D3dDdi::AdapterCallbacks); diff --git a/DDrawCompat/D3dDdi/AdapterFuncs.h b/DDrawCompat/D3dDdi/AdapterFuncs.h index 1b0c9e9..b6551d3 100644 --- a/DDrawCompat/D3dDdi/AdapterFuncs.h +++ b/DDrawCompat/D3dDdi/AdapterFuncs.h @@ -5,9 +5,11 @@ namespace D3dDdi { - class AdapterFuncs : public CompatVtable + class AdapterFuncs : public CompatVtable { public: static void setCompatVtable(D3DDDI_ADAPTERFUNCS& vtable); }; } + +SET_COMPAT_VTABLE(D3DDDI_ADAPTERFUNCS, D3dDdi::AdapterFuncs); diff --git a/DDrawCompat/D3dDdi/DeviceCallbacks.h b/DDrawCompat/D3dDdi/DeviceCallbacks.h index 110e4da..69c71ca 100644 --- a/DDrawCompat/D3dDdi/DeviceCallbacks.h +++ b/DDrawCompat/D3dDdi/DeviceCallbacks.h @@ -14,9 +14,11 @@ std::ostream& operator<<(std::ostream& os, const D3DDDICB_UNLOCK2& data); namespace D3dDdi { - class DeviceCallbacks : public CompatVtable + class DeviceCallbacks : public CompatVtable { public: static void setCompatVtable(D3DDDI_DEVICECALLBACKS& vtable); }; } + +SET_COMPAT_VTABLE(D3DDDI_DEVICECALLBACKS, D3dDdi::DeviceCallbacks); diff --git a/DDrawCompat/D3dDdi/DeviceFuncs.h b/DDrawCompat/D3dDdi/DeviceFuncs.h index 2c5810a..838584c 100644 --- a/DDrawCompat/D3dDdi/DeviceFuncs.h +++ b/DDrawCompat/D3dDdi/DeviceFuncs.h @@ -14,9 +14,11 @@ std::ostream& operator<<(std::ostream& os, const D3DDDIBOX& val); namespace D3dDdi { - class DeviceFuncs : public CompatVtable + class DeviceFuncs : public CompatVtable { public: static void setCompatVtable(D3DDDI_DEVICEFUNCS& vtable); }; } + +SET_COMPAT_VTABLE(D3DDDI_DEVICEFUNCS, D3dDdi::DeviceFuncs); diff --git a/DDrawCompat/DDraw/DirectDraw.h b/DDrawCompat/DDraw/DirectDraw.h index b1095bc..1f73aab 100644 --- a/DDrawCompat/DDraw/DirectDraw.h +++ b/DDrawCompat/DDraw/DirectDraw.h @@ -7,7 +7,7 @@ namespace DDraw { template - class DirectDraw: public CompatVtable, TDirectDraw> + class DirectDraw: public CompatVtable> { public: typedef typename Types::TCreatedSurface TSurface; @@ -34,3 +34,8 @@ namespace DDraw Params... params); }; } + +SET_COMPAT_VTABLE(IDirectDrawVtbl, DDraw::DirectDraw); +SET_COMPAT_VTABLE(IDirectDraw2Vtbl, DDraw::DirectDraw); +SET_COMPAT_VTABLE(IDirectDraw4Vtbl, DDraw::DirectDraw); +SET_COMPAT_VTABLE(IDirectDraw7Vtbl, DDraw::DirectDraw); diff --git a/DDrawCompat/DDraw/DirectDrawPalette.h b/DDrawCompat/DDraw/DirectDrawPalette.h index 7d3d0a5..cfaa4ff 100644 --- a/DDrawCompat/DDraw/DirectDrawPalette.h +++ b/DDrawCompat/DDraw/DirectDrawPalette.h @@ -5,7 +5,7 @@ namespace DDraw { - class DirectDrawPalette : public CompatVtable + class DirectDrawPalette : public CompatVtable { public: static void setCompatVtable(IDirectDrawPaletteVtbl& vtable); @@ -20,3 +20,5 @@ namespace DDraw static void waitForNextUpdate(); }; } + +SET_COMPAT_VTABLE(IDirectDrawPaletteVtbl, DDraw::DirectDrawPalette); diff --git a/DDrawCompat/DDraw/DirectDrawSurface.cpp b/DDrawCompat/DDraw/DirectDrawSurface.cpp index 7ff2123..4e94a57 100644 --- a/DDrawCompat/DDraw/DirectDrawSurface.cpp +++ b/DDrawCompat/DDraw/DirectDrawSurface.cpp @@ -14,7 +14,7 @@ namespace DDraw::Surface* surface = This ? DDraw::Surface::getSurface(*This) : nullptr; if (!surface) { - return (CompatVtableBase::s_origVtable.*origMethod)(This, params...); + return (CompatVtable>::s_origVtable.*origMethod)(This, params...); } return (surface->getImpl()->*compatMethod)(This, params...); } diff --git a/DDrawCompat/DDraw/DirectDrawSurface.h b/DDrawCompat/DDraw/DirectDrawSurface.h index 656a968..9b72a40 100644 --- a/DDrawCompat/DDraw/DirectDrawSurface.h +++ b/DDrawCompat/DDraw/DirectDrawSurface.h @@ -8,7 +8,7 @@ namespace DDraw { template - class DirectDrawSurface : public CompatVtable, TSurface> + class DirectDrawSurface : public CompatVtable> { public: typedef typename Types::TSurfaceDesc TSurfaceDesc; @@ -19,3 +19,9 @@ namespace DDraw static void setCompatVtable2(Vtable& vtable); }; } + +SET_COMPAT_VTABLE(IDirectDrawSurfaceVtbl, DDraw::DirectDrawSurface); +SET_COMPAT_VTABLE(IDirectDrawSurface2Vtbl, DDraw::DirectDrawSurface); +SET_COMPAT_VTABLE(IDirectDrawSurface3Vtbl, DDraw::DirectDrawSurface); +SET_COMPAT_VTABLE(IDirectDrawSurface4Vtbl, DDraw::DirectDrawSurface); +SET_COMPAT_VTABLE(IDirectDrawSurface7Vtbl, DDraw::DirectDrawSurface); diff --git a/DDrawCompat/DDraw/Hooks.cpp b/DDrawCompat/DDraw/Hooks.cpp index 3d30b0b..8d2f97e 100644 --- a/DDrawCompat/DDraw/Hooks.cpp +++ b/DDrawCompat/DDraw/Hooks.cpp @@ -16,17 +16,17 @@ namespace { - template - void hookVtable(const CompatPtr& intf); + template + void hookVtable(const CompatPtr& intf); void hookDirectDraw(CompatRef dd) { DDraw::DirectDraw::s_origVtable = *(&dd)->lpVtbl; CompatPtr dd7(&dd); - hookVtable>(dd7); - hookVtable>(dd7); - hookVtable>(dd7); - hookVtable>(dd7); + hookVtable(dd7); + hookVtable(dd7); + hookVtable(dd7); + hookVtable(dd7); dd7.detach(); } @@ -60,11 +60,11 @@ namespace if (SUCCEEDED(result)) { DDraw::DirectDrawSurface::s_origVtable = *surface.get()->lpVtbl; - hookVtable>(surface); - hookVtable>(surface); - hookVtable>(surface); - hookVtable>(surface); - hookVtable>(surface); + hookVtable(surface); + hookVtable(surface); + hookVtable(surface); + hookVtable(surface); + hookVtable(surface); } else { @@ -72,10 +72,10 @@ namespace } } - template - void hookVtable(const CompatPtr& intf) + template + void hookVtable(const CompatPtr& intf) { - CompatInterface::hookVtable(intf.get()->lpVtbl); + CompatVtable>::hookVtable(intf.get()->lpVtbl); } } diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index 413be66..f81282d 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -66,7 +66,7 @@ namespace DDraw ZeroMemory(&g_primarySurfaceDesc, sizeof(g_primarySurfaceDesc)); g_primarySurfaceDesc.dwSize = sizeof(g_primarySurfaceDesc); - CompatVtableBase::s_origVtable.GetSurfaceDesc(surface7, &g_primarySurfaceDesc); + CompatVtable::s_origVtable.GetSurfaceDesc(surface7, &g_primarySurfaceDesc); return DD_OK; } diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp index 58f9d0a..b90b3ff 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp @@ -63,7 +63,7 @@ namespace DDraw { TSurfaceDesc desc = {}; desc.dwSize = sizeof(desc); - CompatVtableBase::s_origVtable.GetSurfaceDesc(lpDDSrcSurface, &desc); + CompatVtable>::s_origVtable.GetSurfaceDesc(lpDDSrcSurface, &desc); destRect.right += desc.dwWidth; destRect.bottom += desc.dwHeight; } diff --git a/DDrawCompat/DDraw/Surfaces/Surface.cpp b/DDrawCompat/DDraw/Surfaces/Surface.cpp index dfb7768..b766e3a 100644 --- a/DDrawCompat/DDraw/Surfaces/Surface.cpp +++ b/DDrawCompat/DDraw/Surfaces/Surface.cpp @@ -35,19 +35,19 @@ namespace IID getDdIidFromVtablePtr(const void* vtablePtr) { - if (CompatVtableBase::s_origVtablePtr == vtablePtr) + if (CompatVtable::s_origVtablePtr == vtablePtr) { return IID_IDirectDraw; } - if (CompatVtableBase::s_origVtablePtr == vtablePtr) + if (CompatVtable::s_origVtablePtr == vtablePtr) { return IID_IDirectDraw2; } - if (CompatVtableBase::s_origVtablePtr == vtablePtr) + if (CompatVtable::s_origVtablePtr == vtablePtr) { return IID_IDirectDraw4; } - if (CompatVtableBase::s_origVtablePtr == vtablePtr) + if (CompatVtable::s_origVtablePtr == vtablePtr) { return IID_IDirectDraw7; } @@ -94,7 +94,7 @@ namespace DDraw privateData.get(), sizeof(privateData.get()), DDSPD_IUNKNOWNPOINTER))) { CompatPtr dd; - CompatVtableBase::s_origVtable.GetDDInterface( + CompatVtable::s_origVtable.GetDDInterface( &dds, reinterpret_cast(&dd.getRef())); privateData->createImpl(); @@ -122,7 +122,7 @@ namespace DDraw std::unique_ptr privateData(new Surface()); attach(*surface, privateData); - CompatVtableBase::s_origVtable.EnumAttachedSurfaces( + CompatVtable::s_origVtable.EnumAttachedSurfaces( surface, rootSurface, &attachToLinkedSurfaces); return DDENUMRET_OK; } @@ -144,7 +144,7 @@ namespace DDraw attach(*surface7, privateData); if (desc.ddsCaps.dwCaps & DDSCAPS_COMPLEX) { - CompatVtableBase::s_origVtable.EnumAttachedSurfaces( + CompatVtable::s_origVtable.EnumAttachedSurfaces( surface7, surface7, &attachToLinkedSurfaces); } } @@ -188,7 +188,7 @@ namespace DDraw DWORD surfacePtrSize = sizeof(surface); // This can get called during surface release so a proper QueryInterface would be dangerous - CompatVtableBase::s_origVtable.GetPrivateData( + CompatVtable::s_origVtable.GetPrivateData( reinterpret_cast(&dds), IID_CompatSurfacePrivateData, &surface, &surfacePtrSize); diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp index 5e289a4..0f1844a 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp @@ -248,10 +248,10 @@ namespace DDraw { DirectDrawInterface dd = {}; dd.vtable = IID_IDirectDraw7 == m_data->m_ddId - ? static_cast(CompatVtableBase::s_origVtablePtr) - : static_cast(CompatVtableBase::s_origVtablePtr); + ? static_cast(CompatVtable::s_origVtablePtr) + : static_cast(CompatVtable::s_origVtablePtr); dd.ddObject = m_data->m_ddObject; - return CompatVtableBase::s_origVtable.QueryInterface( + return CompatVtable::s_origVtable.QueryInterface( reinterpret_cast(&dd), m_data->m_ddId, lplpDD); } @@ -325,7 +325,8 @@ namespace DDraw } template - const Vtable& SurfaceImpl::s_origVtable = CompatVtableBase::s_origVtable; + const Vtable& SurfaceImpl::s_origVtable = + CompatVtable>::s_origVtable; template SurfaceImpl; template SurfaceImpl; diff --git a/DDrawCompat/Direct3d/Direct3d.cpp b/DDrawCompat/Direct3d/Direct3d.cpp index 1d3f9ca..0fae8ea 100644 --- a/DDrawCompat/Direct3d/Direct3d.cpp +++ b/DDrawCompat/Direct3d/Direct3d.cpp @@ -45,7 +45,7 @@ namespace { if (!lpEnumDevicesCallback) { - return CompatVtableBase::s_origVtable.EnumDevices( + return CompatVtable>::s_origVtable.EnumDevices( This, lpEnumDevicesCallback, lpUserArg); } @@ -53,7 +53,7 @@ namespace CompatPtr d3d(Compat::queryInterface(This)); EnumDevicesParams params = { d3d, lpEnumDevicesCallback, lpUserArg }; - return CompatVtableBase::s_origVtable.EnumDevices( + return CompatVtable>::s_origVtable.EnumDevices( This, &d3dEnumDevicesCallback, ¶ms); } } diff --git a/DDrawCompat/Direct3d/Direct3d.h b/DDrawCompat/Direct3d/Direct3d.h index 018f0e9..56a95ee 100644 --- a/DDrawCompat/Direct3d/Direct3d.h +++ b/DDrawCompat/Direct3d/Direct3d.h @@ -6,9 +6,14 @@ namespace Direct3d { template - class Direct3d : public CompatVtable, TDirect3d> + class Direct3d : public CompatVtable> { public: static void setCompatVtable(Vtable& vtable); }; } + +SET_COMPAT_VTABLE(IDirect3DVtbl, Direct3d::Direct3d); +SET_COMPAT_VTABLE(IDirect3D2Vtbl, Direct3d::Direct3d); +SET_COMPAT_VTABLE(IDirect3D3Vtbl, Direct3d::Direct3d); +SET_COMPAT_VTABLE(IDirect3D7Vtbl, Direct3d::Direct3d); diff --git a/DDrawCompat/Direct3d/Direct3dDevice.cpp b/DDrawCompat/Direct3d/Direct3dDevice.cpp index 8aa8bb5..6d80714 100644 --- a/DDrawCompat/Direct3d/Direct3dDevice.cpp +++ b/DDrawCompat/Direct3d/Direct3dDevice.cpp @@ -11,7 +11,7 @@ namespace { typedef typename Direct3d::Types::TDirect3d TDirect3d; CompatPtr d3d; - if (SUCCEEDED(CompatVtableBase::s_origVtable.GetDirect3D( + if (SUCCEEDED(CompatVtable>::s_origVtable.GetDirect3D( &d3dDevice, &d3d.getRef()))) { typedef typename Direct3d::Types::TDirect3dHighest TDirect3dHighest; @@ -25,7 +25,7 @@ namespace TD3dDeviceDesc* lpD3DHWDevDesc, Params... params) { - HRESULT result = CompatVtableBase::s_origVtable.GetCaps( + HRESULT result = CompatVtable>::s_origVtable.GetCaps( This, lpD3DHWDevDesc, params...); if (SUCCEEDED(result)) { diff --git a/DDrawCompat/Direct3d/Direct3dDevice.h b/DDrawCompat/Direct3d/Direct3dDevice.h index 0350339..f03bf4d 100644 --- a/DDrawCompat/Direct3d/Direct3dDevice.h +++ b/DDrawCompat/Direct3d/Direct3dDevice.h @@ -6,9 +6,14 @@ namespace Direct3d { template - class Direct3dDevice : public CompatVtable, TDirect3dDevice> + class Direct3dDevice : public CompatVtable> { public: static void setCompatVtable(Vtable& vtable); }; } + +SET_COMPAT_VTABLE(IDirect3DDeviceVtbl, Direct3d::Direct3dDevice); +SET_COMPAT_VTABLE(IDirect3DDevice2Vtbl, Direct3d::Direct3dDevice); +SET_COMPAT_VTABLE(IDirect3DDevice3Vtbl, Direct3d::Direct3dDevice); +SET_COMPAT_VTABLE(IDirect3DDevice7Vtbl, Direct3d::Direct3dDevice); diff --git a/DDrawCompat/Direct3d/Hooks.cpp b/DDrawCompat/Direct3d/Hooks.cpp index 18fe7a0..2ce3c9e 100644 --- a/DDrawCompat/Direct3d/Hooks.cpp +++ b/DDrawCompat/Direct3d/Hooks.cpp @@ -16,8 +16,8 @@ namespace void hookDirect3dDevice(CompatRef d3d, CompatRef renderTarget); void hookDirect3dDevice7(CompatRef d3d, CompatRef renderTarget); - template - void hookVtable(const CompatPtr& intf); + template + void hookVtable(const CompatPtr& intf); template CompatPtr createDirect3d(CompatRef dd) @@ -76,9 +76,9 @@ namespace CompatPtr d3d(createDirect3d(dd)); if (d3d) { - hookVtable>(d3d); - hookVtable>(d3d); - hookVtable>(d3d); + hookVtable(d3d); + hookVtable(d3d); + hookVtable(d3d); hookDirect3dDevice(*d3d, renderTarget); } } @@ -88,7 +88,7 @@ namespace CompatPtr d3d(createDirect3d(dd)); if (d3d) { - hookVtable>(d3d); + hookVtable(d3d); hookDirect3dDevice7(*d3d, renderTarget); } } @@ -98,9 +98,9 @@ namespace CompatPtr d3dDevice( createDirect3dDevice(d3d, renderTarget, nullptr)); - hookVtable>(d3dDevice); - hookVtable>(d3dDevice); - hookVtable>(d3dDevice); + hookVtable(d3dDevice); + hookVtable(d3dDevice); + hookVtable(d3dDevice); } void hookDirect3dDevice7(CompatRef d3d, CompatRef renderTarget) @@ -108,13 +108,13 @@ namespace CompatPtr d3dDevice( createDirect3dDevice(d3d, renderTarget)); - hookVtable>(d3dDevice); + hookVtable(d3dDevice); } - template - void hookVtable(const CompatPtr& intf) + template + void hookVtable(const CompatPtr& intf) { - CompatInterface::hookVtable(intf.get()->lpVtbl); + CompatVtable>::hookVtable(intf.get()->lpVtbl); } } diff --git a/DDrawCompat/Gdi/Gdi.cpp b/DDrawCompat/Gdi/Gdi.cpp index 877d42a..15c24a4 100644 --- a/DDrawCompat/Gdi/Gdi.cpp +++ b/DDrawCompat/Gdi/Gdi.cpp @@ -59,7 +59,7 @@ namespace DDSURFACEDESC2 desc = {}; desc.dwSize = sizeof(desc); auto primary(DDraw::PrimarySurface::getPrimary()); - if (FAILED(primary->Lock(primary, nullptr, &desc, lockFlags | DDLOCK_WAIT, nullptr))) + if (!primary || FAILED(primary->Lock(primary, nullptr, &desc, lockFlags | DDLOCK_WAIT, nullptr))) { return false; } @@ -80,11 +80,14 @@ namespace { GdiFlush(); auto primary(DDraw::PrimarySurface::getPrimary()); - primary->Unlock(primary, nullptr); - if (DDLOCK_READONLY != g_ddLockFlags) + if (primary) { - DDraw::RealPrimarySurface::invalidate(nullptr); - DDraw::RealPrimarySurface::update(); + primary->Unlock(primary, nullptr); + if (DDLOCK_READONLY != g_ddLockFlags) + { + DDraw::RealPrimarySurface::invalidate(nullptr); + DDraw::RealPrimarySurface::update(); + } } if (0 != g_ddLockFlags)