1
0
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:
narzoul 2015-12-28 13:01:09 +01:00
parent a0d3459e42
commit 3610edb117
2 changed files with 29 additions and 8 deletions

View File

@ -47,10 +47,8 @@ public:
s_vtablePtr = intf.lpVtbl;
s_origVtable = *intf.lpVtbl;
DetourTransactionBegin();
InitVisitor visitor;
forEach<Vtable<Interface>>(visitor);
DetourTransactionCommit();
}
}
@ -67,8 +65,13 @@ private:
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;
#endif
s_compatVtable.*ptr = s_origVtable.*ptr;
}
else
{
@ -105,10 +108,12 @@ private:
}
else
{
DetourAttach(&origMethodPtr, newMethodPtr);
s_vtablePtrToCompatVtable[s_vtablePtr] = &s_compatVtable;
Compat::detouredMethods.emplace(origMethodPtr,
Compat::DetouredMethodInfo(origMethodPtr, s_vtablePtrToCompatVtable));
DetourTransactionBegin();
DetourAttach(&origMethodPtr, newMethodPtr);
DetourTransactionCommit();
}
}
@ -130,8 +135,8 @@ private:
result = (s_origVtable.*ptr)(This, params...);
}
Compat::origProcs.ReleaseDDThreadLock();
Compat::LogLeave(s_funcNames[getKey<MemberDataPtr, ptr>()].c_str(), This, params...) << result;
Compat::origProcs.ReleaseDDThreadLock();
return result;
}
};

View File

@ -44,7 +44,8 @@ namespace
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
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);
hookVtable<CompatDirectDrawSurface<IDirectDrawSurface>>(IID_IDirectDrawSurface, surfaceUnk);
@ -54,17 +55,27 @@ namespace
hookVtable<CompatDirectDrawSurface<IDirectDrawSurface7>>(IID_IDirectDrawSurface7, surfaceUnk);
surface->lpVtbl->Release(surface);
}
else
{
Compat::Log() << "Failed to create a DirectDraw surface for hooking: " << result;
}
}
void hookDirectDrawPalette(IDirectDraw& dd)
{
PALETTEENTRY paletteEntries[2] = {};
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);
palette->lpVtbl->Release(palette);
}
else
{
Compat::Log() << "Failed to create a DirectDraw palette for hooking: " << result;
}
}
void installHooks()
@ -74,7 +85,8 @@ namespace
{
Compat::Log() << "Installing DirectDraw hooks";
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);
@ -87,6 +99,10 @@ namespace
dd->lpVtbl->Release(dd);
}
else
{
Compat::Log() << "Failed to create a DirectDraw object for hooking" << result;
}
Compat::Log() << "Finished installing hooks";
isAlreadyInstalled = true;
}