From 7f3c2d00acfbecad1418ecd7a2d5adaca6d2bc40 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 28 Jan 2007 05:01:38 +0000 Subject: [PATCH] fixed bug am50501 --- dlls/fakemeta/fakemeta_amxx.cpp | 12 +++++++++--- dlls/fakemeta/forward.cpp | 18 ++++++++++++++---- dlls/fakemeta/forward.h | 2 ++ dlls/fakemeta/forwardmacros.h | 4 ++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/dlls/fakemeta/fakemeta_amxx.cpp b/dlls/fakemeta/fakemeta_amxx.cpp index 13194d77..dbcd433c 100755 --- a/dlls/fakemeta/fakemeta_amxx.cpp +++ b/dlls/fakemeta/fakemeta_amxx.cpp @@ -34,19 +34,25 @@ void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) g_pFunctionTable->pfn##tcall =0; \ g_pFunctionTable_Post->pfn##tcall =NULL; \ Engine[FM_##tcall].clear(); \ - EnginePost[FM_##tcall].clear() + EnginePost[FM_##tcall].clear(); \ + EngineAddrs[FM_##tcall] = NULL; \ + EngineAddrsPost[FM_##tcall] = NULL; #define RESETE(call) \ g_pengfuncsTable->pfn##call = NULL; \ g_pengfuncsTable_Post->pfn##call = NULL; \ Engine[FM_##call].clear(); \ - EnginePost[FM_##call].clear() + EnginePost[FM_##call].clear(); \ + EngineAddrs[FM_##call] = NULL; \ + EngineAddrsPost[FM_##call] = NULL; #define RESETN(call) \ g_pNewFunctionsTable->pfn##call = NULL; \ g_pNewFunctionsTable_Post->pfn##call = NULL; \ Engine[FM_##call].clear(); \ - EnginePost[FM_##call].clear(); + EnginePost[FM_##call].clear(); \ + EngineAddrs[FM_##call] = NULL; \ + EngineAddrsPost[FM_##call] = NULL; void FMH_ServerDeactivate_Post() { diff --git a/dlls/fakemeta/forward.cpp b/dlls/fakemeta/forward.cpp index fda60542..72609751 100755 --- a/dlls/fakemeta/forward.cpp +++ b/dlls/fakemeta/forward.cpp @@ -2,6 +2,8 @@ CVector Engine[ENGFUNC_NUM+10]; CVector EnginePost[ENGFUNC_NUM+10]; +void *EngineAddrs[ENGFUNC_NUM+10]; +void *EngineAddrsPost[ENGFUNC_NUM+10]; cell mCellResult; cell mlCellResult; float mFloatResult; @@ -819,11 +821,17 @@ static cell AMX_NATIVE_CALL unregister_forward(AMX *amx, cell *params) return 0; } + void *patchAddr = NULL; + CVector *peng = NULL; if (post) + { peng = &(EnginePost[func]); - else + patchAddr = EngineAddrsPost[func]; + } else { peng = &(Engine[func]); + patchAddr = EngineAddrs[func]; + } CVector::iterator begin, end=peng->end(); @@ -832,10 +840,12 @@ static cell AMX_NATIVE_CALL unregister_forward(AMX *amx, cell *params) if ((*begin) == func_id) { peng->erase(begin); - if (!peng->size()) + if (!peng->size() + && patchAddr != NULL + && func != FM_ServerDeactivate) { - //:TODO: we should probably clear this here! - //but, we have no reverse lookup possible. + /* Clear out this forward if we no longer need it */ + *(void **)patchAddr = NULL; } return 1; } diff --git a/dlls/fakemeta/forward.h b/dlls/fakemeta/forward.h index bb722a4b..43361a4c 100755 --- a/dlls/fakemeta/forward.h +++ b/dlls/fakemeta/forward.h @@ -169,6 +169,8 @@ enum { extern CVector Engine[]; extern CVector EnginePost[]; +extern void *EngineAddrs[ENGFUNC_NUM+10]; +extern void *EngineAddrsPost[ENGFUNC_NUM+10]; extern cell mCellResult; extern float mFloatResult; extern const char *mStringResult; diff --git a/dlls/fakemeta/forwardmacros.h b/dlls/fakemeta/forwardmacros.h index 586e4bc4..3f263648 100755 --- a/dlls/fakemeta/forwardmacros.h +++ b/dlls/fakemeta/forwardmacros.h @@ -810,11 +810,13 @@ #define ENGHOOK(pfnCall) \ if (post) \ { \ + EngineAddrsPost[FM_##pfnCall] = &engtable->pfn##pfnCall; \ if (engtable->pfn##pfnCall == NULL) \ engtable->pfn##pfnCall = pfnCall##_post; \ } \ else \ { \ + EngineAddrs[FM_##pfnCall] = &engtable->pfn##pfnCall; \ if (engtable->pfn##pfnCall == NULL) \ engtable->pfn##pfnCall = pfnCall; \ } @@ -822,11 +824,13 @@ #define DLLHOOK(pfnCall) \ if (post) \ { \ + EngineAddrsPost[FM_##pfnCall] = &dlltable->pfn##pfnCall; \ if (dlltable->pfn##pfnCall == NULL) \ dlltable->pfn##pfnCall = pfnCall##_post; \ } \ else \ { \ + EngineAddrs[FM_##pfnCall] = &dlltable->pfn##pfnCall; \ if (dlltable->pfn##pfnCall == NULL) \ dlltable->pfn##pfnCall = pfnCall; \ }