2021-02-20 13:39:18 +01:00
|
|
|
#include <Common/CompatRef.h>
|
|
|
|
#include <Common/Log.h>
|
|
|
|
#include <DDraw/DirectDraw.h>
|
|
|
|
#include <DDraw/DirectDrawClipper.h>
|
|
|
|
#include <DDraw/DirectDrawGammaControl.h>
|
|
|
|
#include <DDraw/DirectDrawPalette.h>
|
|
|
|
#include <DDraw/DirectDrawSurface.h>
|
|
|
|
#include <DDraw/Hooks.h>
|
|
|
|
#include <DDraw/RealPrimarySurface.h>
|
2021-03-14 18:48:26 +01:00
|
|
|
#include <DDraw/ScopedThreadLock.h>
|
2021-02-20 13:39:18 +01:00
|
|
|
#include <Win32/Registry.h>
|
2016-06-08 23:23:25 +02:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2019-01-12 12:32:57 +01:00
|
|
|
void hookDirectDraw(CompatPtr<IDirectDraw7> dd)
|
2016-06-08 23:23:25 +02:00
|
|
|
{
|
2021-03-14 18:48:26 +01:00
|
|
|
DDraw::DirectDraw::hookVtable(*CompatPtr<IDirectDraw>(dd).get()->lpVtbl);
|
|
|
|
DDraw::DirectDraw::hookVtable(*CompatPtr<IDirectDraw2>(dd).get()->lpVtbl);
|
|
|
|
DDraw::DirectDraw::hookVtable(*CompatPtr<IDirectDraw4>(dd).get()->lpVtbl);
|
|
|
|
DDraw::DirectDraw::hookVtable(*CompatPtr<IDirectDraw7>(dd).get()->lpVtbl);
|
2016-06-08 23:23:25 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 12:50:45 +01:00
|
|
|
void hookDirectDrawClipper(CompatRef<IDirectDraw7> dd)
|
|
|
|
{
|
|
|
|
CompatPtr<IDirectDrawClipper> clipper;
|
|
|
|
HRESULT result = dd->CreateClipper(&dd, 0, &clipper.getRef(), nullptr);
|
|
|
|
if (SUCCEEDED(result))
|
|
|
|
{
|
2021-03-14 18:48:26 +01:00
|
|
|
DDraw::DirectDrawClipper::hookVtable(*clipper.get()->lpVtbl);
|
2017-03-05 12:50:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-10 22:16:23 +01:00
|
|
|
Compat::Log() << "ERROR: Failed to create a DirectDraw clipper for hooking: " << result;
|
2017-03-05 12:50:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 23:23:25 +02:00
|
|
|
void hookDirectDrawPalette(CompatRef<IDirectDraw7> dd)
|
|
|
|
{
|
|
|
|
PALETTEENTRY paletteEntries[2] = {};
|
|
|
|
CompatPtr<IDirectDrawPalette> palette;
|
2021-03-14 18:48:26 +01:00
|
|
|
HRESULT result = dd->CreatePalette(&dd, DDPCAPS_1BIT, paletteEntries, &palette.getRef(), nullptr);
|
2016-06-08 23:23:25 +02:00
|
|
|
if (SUCCEEDED(result))
|
|
|
|
{
|
2021-03-14 18:48:26 +01:00
|
|
|
DDraw::DirectDrawPalette::hookVtable(*palette.get()->lpVtbl);
|
2016-06-08 23:23:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-10 22:16:23 +01:00
|
|
|
Compat::Log() << "ERROR: Failed to create a DirectDraw palette for hooking: " << result;
|
2016-06-08 23:23:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void hookDirectDrawSurface(CompatRef<IDirectDraw7> dd)
|
|
|
|
{
|
|
|
|
DDSURFACEDESC2 desc = {};
|
|
|
|
desc.dwSize = sizeof(desc);
|
|
|
|
desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
|
|
|
|
desc.dwWidth = 1;
|
|
|
|
desc.dwHeight = 1;
|
|
|
|
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
|
|
|
|
|
|
|
|
CompatPtr<IDirectDrawSurface7> surface;
|
|
|
|
HRESULT result = dd->CreateSurface(&dd, &desc, &surface.getRef(), nullptr);
|
|
|
|
if (SUCCEEDED(result))
|
|
|
|
{
|
2021-03-14 18:48:26 +01:00
|
|
|
CompatVtable<IDirectDrawSurface7Vtbl>::s_origVtable = *surface.get()->lpVtbl;
|
|
|
|
DDraw::DirectDrawSurface::hookVtable(*CompatPtr<IDirectDrawSurface>(surface).get()->lpVtbl);
|
|
|
|
DDraw::DirectDrawSurface::hookVtable(*CompatPtr<IDirectDrawSurface2>(surface).get()->lpVtbl);
|
|
|
|
DDraw::DirectDrawSurface::hookVtable(*CompatPtr<IDirectDrawSurface3>(surface).get()->lpVtbl);
|
|
|
|
DDraw::DirectDrawSurface::hookVtable(*CompatPtr<IDirectDrawSurface4>(surface).get()->lpVtbl);
|
|
|
|
DDraw::DirectDrawSurface::hookVtable(*CompatPtr<IDirectDrawSurface7>(surface).get()->lpVtbl);
|
|
|
|
|
|
|
|
CompatPtr<IDirectDrawGammaControl> gammaControl(surface);
|
|
|
|
DDraw::DirectDrawGammaControl::hookVtable(*gammaControl.get()->lpVtbl);
|
2016-06-08 23:23:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-10 22:16:23 +01:00
|
|
|
Compat::Log() << "ERROR: Failed to create a DirectDraw surface for hooking: " << result;
|
2016-06-08 23:23:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 22:39:28 +02:00
|
|
|
namespace DDraw
|
2016-06-08 23:23:25 +02:00
|
|
|
{
|
2019-01-12 12:32:57 +01:00
|
|
|
void installHooks(CompatPtr<IDirectDraw7> dd7)
|
2016-06-08 23:23:25 +02:00
|
|
|
{
|
2018-07-17 20:46:38 +02:00
|
|
|
RealPrimarySurface::init();
|
|
|
|
|
2016-12-26 16:17:20 +01:00
|
|
|
Win32::Registry::unsetValue(
|
|
|
|
HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\DirectDraw", "EmulationOnly");
|
|
|
|
Win32::Registry::unsetValue(
|
|
|
|
HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Microsoft\\DirectDraw", "EmulationOnly");
|
|
|
|
|
2019-01-12 12:32:57 +01:00
|
|
|
hookDirectDraw(dd7);
|
2017-03-05 12:50:45 +01:00
|
|
|
hookDirectDrawClipper(*dd7);
|
2016-06-08 23:23:25 +02:00
|
|
|
hookDirectDrawPalette(*dd7);
|
2017-03-05 12:50:45 +01:00
|
|
|
hookDirectDrawSurface(*dd7);
|
2016-06-08 23:23:25 +02:00
|
|
|
}
|
|
|
|
}
|