mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Extended hooking to all methods in debug mode
All methods of all hooked interfaces are now hooked in debug mode. This provides more function entry/exit logs.
This commit is contained in:
parent
a0d3459e42
commit
3610edb117
@ -47,10 +47,8 @@ public:
|
|||||||
s_vtablePtr = intf.lpVtbl;
|
s_vtablePtr = intf.lpVtbl;
|
||||||
s_origVtable = *intf.lpVtbl;
|
s_origVtable = *intf.lpVtbl;
|
||||||
|
|
||||||
DetourTransactionBegin();
|
|
||||||
InitVisitor visitor;
|
InitVisitor visitor;
|
||||||
forEach<Vtable<Interface>>(visitor);
|
forEach<Vtable<Interface>>(visitor);
|
||||||
DetourTransactionCommit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +65,13 @@ private:
|
|||||||
|
|
||||||
if (!(s_compatVtable.*ptr))
|
if (!(s_compatVtable.*ptr))
|
||||||
{
|
{
|
||||||
s_compatVtable.*ptr = s_origVtable.*ptr;
|
#ifdef _DEBUG
|
||||||
|
s_threadSafeVtable.*ptr = getThreadSafeFuncPtr<MemberDataPtr, ptr>(s_compatVtable.*ptr);
|
||||||
|
hookMethod(reinterpret_cast<void*&>(s_origVtable.*ptr), s_threadSafeVtable.*ptr);
|
||||||
|
#else
|
||||||
s_threadSafeVtable.*ptr = s_origVtable.*ptr;
|
s_threadSafeVtable.*ptr = s_origVtable.*ptr;
|
||||||
|
#endif
|
||||||
|
s_compatVtable.*ptr = s_origVtable.*ptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -105,10 +108,12 @@ private:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DetourAttach(&origMethodPtr, newMethodPtr);
|
|
||||||
s_vtablePtrToCompatVtable[s_vtablePtr] = &s_compatVtable;
|
s_vtablePtrToCompatVtable[s_vtablePtr] = &s_compatVtable;
|
||||||
Compat::detouredMethods.emplace(origMethodPtr,
|
Compat::detouredMethods.emplace(origMethodPtr,
|
||||||
Compat::DetouredMethodInfo(origMethodPtr, s_vtablePtrToCompatVtable));
|
Compat::DetouredMethodInfo(origMethodPtr, s_vtablePtrToCompatVtable));
|
||||||
|
DetourTransactionBegin();
|
||||||
|
DetourAttach(&origMethodPtr, newMethodPtr);
|
||||||
|
DetourTransactionCommit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,8 +135,8 @@ private:
|
|||||||
result = (s_origVtable.*ptr)(This, params...);
|
result = (s_origVtable.*ptr)(This, params...);
|
||||||
}
|
}
|
||||||
|
|
||||||
Compat::origProcs.ReleaseDDThreadLock();
|
|
||||||
Compat::LogLeave(s_funcNames[getKey<MemberDataPtr, ptr>()].c_str(), This, params...) << result;
|
Compat::LogLeave(s_funcNames[getKey<MemberDataPtr, ptr>()].c_str(), This, params...) << result;
|
||||||
|
Compat::origProcs.ReleaseDDThreadLock();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -44,7 +44,8 @@ namespace
|
|||||||
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
|
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
|
||||||
|
|
||||||
IDirectDrawSurface* surface = nullptr;
|
IDirectDrawSurface* surface = nullptr;
|
||||||
if (SUCCEEDED(dd.lpVtbl->CreateSurface(&dd, &desc, &surface, nullptr)))
|
HRESULT result = CompatDirectDraw<IDirectDraw>::s_origVtable.CreateSurface(&dd, &desc, &surface, nullptr);
|
||||||
|
if (SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
IUnknown& surfaceUnk = reinterpret_cast<IUnknown&>(*surface);
|
IUnknown& surfaceUnk = reinterpret_cast<IUnknown&>(*surface);
|
||||||
hookVtable<CompatDirectDrawSurface<IDirectDrawSurface>>(IID_IDirectDrawSurface, surfaceUnk);
|
hookVtable<CompatDirectDrawSurface<IDirectDrawSurface>>(IID_IDirectDrawSurface, surfaceUnk);
|
||||||
@ -54,17 +55,27 @@ namespace
|
|||||||
hookVtable<CompatDirectDrawSurface<IDirectDrawSurface7>>(IID_IDirectDrawSurface7, surfaceUnk);
|
hookVtable<CompatDirectDrawSurface<IDirectDrawSurface7>>(IID_IDirectDrawSurface7, surfaceUnk);
|
||||||
surface->lpVtbl->Release(surface);
|
surface->lpVtbl->Release(surface);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Compat::Log() << "Failed to create a DirectDraw surface for hooking: " << result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hookDirectDrawPalette(IDirectDraw& dd)
|
void hookDirectDrawPalette(IDirectDraw& dd)
|
||||||
{
|
{
|
||||||
PALETTEENTRY paletteEntries[2] = {};
|
PALETTEENTRY paletteEntries[2] = {};
|
||||||
IDirectDrawPalette* palette = nullptr;
|
IDirectDrawPalette* palette = nullptr;
|
||||||
if (SUCCEEDED(dd.lpVtbl->CreatePalette(&dd, DDPCAPS_1BIT, paletteEntries, &palette, nullptr)))
|
HRESULT result = CompatDirectDraw<IDirectDraw>::s_origVtable.CreatePalette(
|
||||||
|
&dd, DDPCAPS_1BIT, paletteEntries, &palette, nullptr);
|
||||||
|
if (SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
CompatDirectDrawPalette::hookVtable(*palette);
|
CompatDirectDrawPalette::hookVtable(*palette);
|
||||||
palette->lpVtbl->Release(palette);
|
palette->lpVtbl->Release(palette);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Compat::Log() << "Failed to create a DirectDraw palette for hooking: " << result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void installHooks()
|
void installHooks()
|
||||||
@ -74,7 +85,8 @@ namespace
|
|||||||
{
|
{
|
||||||
Compat::Log() << "Installing DirectDraw hooks";
|
Compat::Log() << "Installing DirectDraw hooks";
|
||||||
IDirectDraw* dd = nullptr;
|
IDirectDraw* dd = nullptr;
|
||||||
if (SUCCEEDED(CALL_ORIG_DDRAW(DirectDrawCreate, nullptr, &dd, nullptr)))
|
HRESULT result = CALL_ORIG_DDRAW(DirectDrawCreate, nullptr, &dd, nullptr);
|
||||||
|
if (SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
dd->lpVtbl->SetCooperativeLevel(dd, nullptr, DDSCL_NORMAL);
|
dd->lpVtbl->SetCooperativeLevel(dd, nullptr, DDSCL_NORMAL);
|
||||||
|
|
||||||
@ -87,6 +99,10 @@ namespace
|
|||||||
|
|
||||||
dd->lpVtbl->Release(dd);
|
dd->lpVtbl->Release(dd);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Compat::Log() << "Failed to create a DirectDraw object for hooking" << result;
|
||||||
|
}
|
||||||
Compat::Log() << "Finished installing hooks";
|
Compat::Log() << "Finished installing hooks";
|
||||||
isAlreadyInstalled = true;
|
isAlreadyInstalled = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user