Skip to content

Commit eb7ed31

Browse files
committed
VT(F)Hook: provide unhook result
1 parent 1ad10c4 commit eb7ed31

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

include/dynlibutils/vthook.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ class CVTHook : public CMemory
143143
public:
144144
using Function_t = R (*)(Args...); // Is the pointer‐to‐function type matching the signature of the virtual method.
145145

146-
~CVTHook() { Unhook(); }
146+
~CVTHook()
147+
{
148+
if (IsHooked())
149+
{
150+
UnhookImpl();
151+
}
152+
}
147153

148154
bool IsHooked() const noexcept { return IsValid(); } // Returns true if a hook is currently installed (i.e., we have a valid vtable slot pointer).
149155
void Clear() noexcept { SetPtr(nullptr); m_pOriginalFn = nullptr; }
@@ -251,10 +257,13 @@ class CVTFHook : public CVTHook<R, Args...>
251257
CBase::Hook(pVTable, nIndex, +[](Args... args) -> R { return sm_callback(args...); });
252258
}
253259

254-
void Unhook()
260+
bool Unhook()
255261
{
256-
CBase::Unhook();
262+
bool bResult = CBase::Unhook();
263+
257264
sm_callback = nullptr;
265+
266+
return bResult;
258267
}
259268

260269
protected:

0 commit comments

Comments
 (0)