mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2025-02-20 13:54:14 +01:00
Added SH_GET_ORIG_VFNPTR_ENTRY
--HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40471
This commit is contained in:
parent
070b841c94
commit
53b48bab94
@ -391,6 +391,14 @@ namespace SourceHook
|
||||
*/
|
||||
virtual void ResetIgnoreHooks(void *vfnptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Finds the original entry of a virtual function pointer
|
||||
*
|
||||
* @param vfnptr The virtual function pointer
|
||||
* @return The original entry if the virtual function pointer has been patched; NULL otherwise.
|
||||
*/
|
||||
virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For hook managers
|
||||
@ -466,6 +474,20 @@ namespace SourceHook
|
||||
return &ref;
|
||||
}
|
||||
};
|
||||
|
||||
template <class X, class MFP>
|
||||
void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
|
||||
{
|
||||
SourceHook::MemFuncInfo info = {true, -1, 0, 0};
|
||||
SourceHook::GetFuncInfo(pInstance, mfp, info);
|
||||
|
||||
void *vfnptr = reinterpret_cast<void*>(
|
||||
*reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
|
||||
|
||||
void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
|
||||
|
||||
return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
@ -588,6 +610,8 @@ SourceHook::CallClass<T> *SH_GET_CALLCLASS(T *p)
|
||||
SH_MFHCls(hookname)::ms_MFI.vtbloffs = pvtbloffs; \
|
||||
} while (0)
|
||||
|
||||
#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
|
||||
|
||||
// New ADD / REMOVE macros.
|
||||
#define SH_STATIC(func) fastdelegate::MakeDelegate(func)
|
||||
#define SH_MEMBER(inst, func) fastdelegate::MakeDelegate(inst, func)
|
||||
|
@ -391,6 +391,14 @@ namespace SourceHook
|
||||
*/
|
||||
virtual void ResetIgnoreHooks(void *vfnptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Finds the original entry of a virtual function pointer
|
||||
*
|
||||
* @param vfnptr The virtual function pointer
|
||||
* @return The original entry if the virtual function pointer has been patched; NULL otherwise.
|
||||
*/
|
||||
virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For hook managers
|
||||
@ -466,6 +474,20 @@ namespace SourceHook
|
||||
return &ref;
|
||||
}
|
||||
};
|
||||
|
||||
template <class X, class MFP>
|
||||
void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
|
||||
{
|
||||
SourceHook::MemFuncInfo info = {true, -1, 0, 0};
|
||||
SourceHook::GetFuncInfo(pInstance, mfp, info);
|
||||
|
||||
void *vfnptr = reinterpret_cast<void*>(
|
||||
*reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
|
||||
|
||||
void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
|
||||
|
||||
return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
@ -588,6 +610,8 @@ SourceHook::CallClass<T> *SH_GET_CALLCLASS(T *p)
|
||||
SH_MFHCls(hookname)::ms_MFI.vtbloffs = pvtbloffs; \
|
||||
} while (0)
|
||||
|
||||
#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
|
||||
|
||||
// New ADD / REMOVE macros.
|
||||
#define SH_STATIC(func) fastdelegate::MakeDelegate(func)
|
||||
#define SH_MEMBER(inst, func) fastdelegate::MakeDelegate(inst, func)
|
||||
|
@ -733,6 +733,25 @@ namespace SourceHook
|
||||
m_ContextStack.pop();
|
||||
}
|
||||
|
||||
void *CSourceHookImpl::GetOrigVfnPtrEntry(void *vfnptr)
|
||||
{
|
||||
for (CHookManContainerList::iterator hmcl_iter = m_HookManContainers.begin();
|
||||
hmcl_iter != m_HookManContainers.end(); ++hmcl_iter)
|
||||
{
|
||||
for (CHookManagerContainer::iterator hookmaniter = hmcl_iter->begin();
|
||||
hookmaniter != hmcl_iter->end(); ++hookmaniter)
|
||||
{
|
||||
for (List<CVfnPtr>::iterator vfnptr_iter = hookmaniter->GetVfnPtrList().begin();
|
||||
vfnptr_iter != hookmaniter->GetVfnPtrList().end(); ++vfnptr_iter)
|
||||
{
|
||||
if (vfnptr_iter->GetPtr() == vfnptr)
|
||||
return vfnptr_iter->GetOrigEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CSourceHookImpl::DoRecall()
|
||||
{
|
||||
CHookContext newCtx;
|
||||
|
@ -391,6 +391,14 @@ namespace SourceHook
|
||||
*/
|
||||
virtual void ResetIgnoreHooks(void *vfnptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Finds the original entry of a virtual function pointer
|
||||
*
|
||||
* @param vfnptr The virtual function pointer
|
||||
* @return The original entry if the virtual function pointer has been patched; NULL otherwise.
|
||||
*/
|
||||
virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For hook managers
|
||||
@ -466,6 +474,20 @@ namespace SourceHook
|
||||
return &ref;
|
||||
}
|
||||
};
|
||||
|
||||
template <class X, class MFP>
|
||||
void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
|
||||
{
|
||||
SourceHook::MemFuncInfo info = {true, -1, 0, 0};
|
||||
SourceHook::GetFuncInfo(pInstance, mfp, info);
|
||||
|
||||
void *vfnptr = reinterpret_cast<void*>(
|
||||
*reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
|
||||
|
||||
void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
|
||||
|
||||
return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
@ -588,6 +610,8 @@ SourceHook::CallClass<T> *SH_GET_CALLCLASS(T *p)
|
||||
SH_MFHCls(hookname)::ms_MFI.vtbloffs = pvtbloffs; \
|
||||
} while (0)
|
||||
|
||||
#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
|
||||
|
||||
// New ADD / REMOVE macros.
|
||||
#define SH_STATIC(func) fastdelegate::MakeDelegate(func)
|
||||
#define SH_MEMBER(inst, func) fastdelegate::MakeDelegate(inst, func)
|
||||
|
@ -314,6 +314,8 @@ namespace SourceHook
|
||||
|
||||
void EndContext(IHookContext *pCtx);
|
||||
|
||||
void *GetOrigVfnPtrEntry(void *vfnptr);
|
||||
|
||||
/**
|
||||
* @brief Shut down the whole system, unregister all hook managers
|
||||
*/
|
||||
|
@ -419,6 +419,8 @@ bool TestBasic(std::string &error)
|
||||
Test test;
|
||||
Test *pTest = &test;
|
||||
|
||||
void *pOrigVfnPtrF1 = (*reinterpret_cast<void***>(pTest))[0];
|
||||
|
||||
// 1) Get a call class and call the member through it and normally
|
||||
SourceHook::CallClass<Test> *cc = SH_GET_CALLCLASS(pTest);
|
||||
|
||||
@ -433,6 +435,8 @@ bool TestBasic(std::string &error)
|
||||
new State_F1_Called,
|
||||
NULL), "Part 1");
|
||||
|
||||
CHECK_COND(SH_GET_ORIG_VFNPTR_ENTRY(pTest, &Test::F1) == pOrigVfnPtrF1, "Part S1");
|
||||
|
||||
// 2) Request a call class again
|
||||
SourceHook::CallClass<Test> *cc2 = SH_GET_CALLCLASS(pTest);
|
||||
ADD_STATE(State_F1_CallClassGenerated);
|
||||
@ -471,6 +475,8 @@ bool TestBasic(std::string &error)
|
||||
new State_F1_PreHandler_Called(&f1_handlers),
|
||||
NULL), "Part 3");
|
||||
|
||||
CHECK_COND(SH_GET_ORIG_VFNPTR_ENTRY(pTest, &Test::F1) == pOrigVfnPtrF1, "Part S3");
|
||||
|
||||
// 4) Rerequest the callclass
|
||||
SH_RELEASE_CALLCLASS(cc);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user