From 35ed810775b474d846b6dac4758be2f91f79c5b3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 13 Jul 2005 02:37:32 +0000 Subject: [PATCH] Patch for ifvers 5:11 (new MM API), eliminates fakemeta like mm-pext --- amxmodx/amxmodx.h | 1 + amxmodx/amxxlog.cpp | 1 - amxmodx/fakemeta.cpp | 61 +++++++++++++++++++++++++++++++++----------- amxmodx/meta_api.cpp | 48 +++++++++++++++++++++++++--------- 4 files changed, 83 insertions(+), 28 deletions(-) diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 9d4a973b..c374905e 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -137,6 +137,7 @@ struct fakecmd_t { bool fake; }; +extern bool g_IsNewMM; extern pextension_funcs_t *gpMetaPExtFuncs; extern CLog g_log; extern CPluginMngr g_plugins; diff --git a/amxmodx/amxxlog.cpp b/amxmodx/amxxlog.cpp index 6d8fdd27..944b743d 100755 --- a/amxmodx/amxxlog.cpp +++ b/amxmodx/amxxlog.cpp @@ -92,7 +92,6 @@ void CLog::CreateNewFile() int i = 0; while (true) { - char file[256]; FILE *pTmpFile = fopen(m_LogFile.c_str(), "r"); // open for reading to check whether the file exists if (!pTmpFile) break; diff --git a/amxmodx/fakemeta.cpp b/amxmodx/fakemeta.cpp index bb7706e7..0240c421 100755 --- a/amxmodx/fakemeta.cpp +++ b/amxmodx/fakemeta.cpp @@ -2355,7 +2355,7 @@ void FakeMeta_New_CVarRegister(cvar_t *pCVar) int CFakeMeta::CFakeMetaPlugin::Query(mutil_funcs_t *pMetaUtilFuncs) { //using metamod p-extensions? - if(gpMetaPExtFuncs) + if(gpMetaPExtFuncs || g_IsNewMM) { //load plugins in meta_attach m_Status = PL_OPENED; @@ -2429,18 +2429,33 @@ int CFakeMeta::CFakeMetaPlugin::Attach(PLUG_LOADTIME now, meta_globals_t *pMGlob { // evilspy's patch: //using metamod p-extensions? - if(gpMetaPExtFuncs) { - if(PEXT_LOAD_PLUGIN_BY_NAME(PLID, m_Path.c_str(), now, (void**)&m_Handle) || !m_Handle) { + if (gpMetaPExtFuncs) + { + if(PEXT_LOAD_PLUGIN_BY_NAME(PLID, m_Path.c_str(), now, (void**)&m_Handle) || !m_Handle) + { + LOG_MESSAGE(PLID, "Can't Attach Module \"%s\".", m_Path.c_str()); m_Status = PL_FAILED; return 0; } + m_Status = PL_RUNNING; + return 1; + } else if (g_IsNewMM) { + int err = 0; + if ( (err = LOAD_PLUGIN(PLID, m_Path.c_str(), now, (void **)&m_Handle)) || !m_Handle) + { + LOG_MESSAGE(PLID, "Can't Attach Module \"%s\".", m_Path.c_str()); + m_Status = PL_FAILED; + return 0; + } + m_Status = PL_RUNNING; return 1; } if (!m_Handle) return 0; + META_ATTACH_FN attachFn = (META_ATTACH_FN)DLSYM(m_Handle, "Meta_Attach"); if (!attachFn) { @@ -2450,7 +2465,7 @@ int CFakeMeta::CFakeMetaPlugin::Attach(PLUG_LOADTIME now, meta_globals_t *pMGlob } if (attachFn(now, &m_MetaFuncTable, pMGlobals, pGameDllFuncs) != 1) { - AMXXLOG_Log("[AMXX] Can't Attach Module \"%s\" (\"%s\").", m_Info->name, m_Path.c_str()); + LOG_MESSAGE(PLID, "Can't Attach Module \"%s\".", m_Path.c_str()); m_Status = PL_FAILED; return 0; } @@ -2466,7 +2481,8 @@ int CFakeMeta::CFakeMetaPlugin::Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reaso // evilspy's patch: //using metamod p-extensions? - if (gpMetaPExtFuncs) { + if (gpMetaPExtFuncs) + { if(PEXT_UNLOAD_PLUGIN_BY_HANDLE(PLID, (void*)m_Handle, now, reason)) { m_Status = PL_FAILED; return 0; @@ -2474,6 +2490,15 @@ int CFakeMeta::CFakeMetaPlugin::Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reaso m_Status = PL_OPENED; m_Handle = NULL; return 1; + } else if (g_IsNewMM) { + if (UNLOAD_PLUGIN_BY_HANDLE(PLID, (void *)m_Handle, now, reason)) + { + m_Status = PL_FAILED; + return 0; + } + m_Status = PL_OPENED; + m_Handle = NULL; + return 1; } META_DETACH_FN detachFn = (META_DETACH_FN)DLSYM(m_Handle, "Meta_Detach"); @@ -2568,7 +2593,7 @@ bool CFakeMeta::AddCorePlugin() { // evilspy: // not needed when using metamod p-extensions - if(gpMetaPExtFuncs) + if(gpMetaPExtFuncs || g_IsNewMM) return true; // Check whether there already is a core plugin @@ -2595,7 +2620,7 @@ void CFakeMeta::Meta_Query(mutil_funcs_t *pMetaUtilFuncs) // evilspy: // using metamod p-extensions? - if(!gpMetaPExtFuncs) + if(!gpMetaPExtFuncs && !g_IsNewMM) ++iter; // Skip core for (; iter; ++iter) @@ -2613,7 +2638,7 @@ void CFakeMeta::Meta_Attach(PLUG_LOADTIME now, meta_globals_t *pMGlobals, gamedl CList::iterator iter = m_Plugins.begin(); // evilspy: // using metamod p-extensions? - if(!gpMetaPExtFuncs) + if(!gpMetaPExtFuncs && !g_IsNewMM) ++iter; // Skip core for (; iter; ++iter) @@ -2629,7 +2654,7 @@ void CFakeMeta::Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) CList::iterator iter = m_Plugins.begin(); // evilspy: // using metamod p-extensions? - if(!gpMetaPExtFuncs) + if(!gpMetaPExtFuncs && !g_IsNewMM) ++iter; // Skip core for (; iter; ++iter) @@ -2650,7 +2675,8 @@ int CFakeMeta::GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable /*from metamod*/, int // evilspy: //using metamod p-extensions? - if(gpMetaPExtFuncs) { + if(gpMetaPExtFuncs || g_IsNewMM) + { memcpy( pFunctionTable, pAMXXFunctionTable, sizeof( DLL_FUNCTIONS ) ); return TRUE; } @@ -2687,7 +2713,8 @@ int CFakeMeta::GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable /*from metamod*/ // evilspy //using metamod p-extensions? - if(gpMetaPExtFuncs) { + if(gpMetaPExtFuncs || g_IsNewMM) + { memcpy( pFunctionTable, pAMXXFunctionTable, sizeof( DLL_FUNCTIONS ) ); return TRUE; } @@ -2724,7 +2751,8 @@ int CFakeMeta::GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *inter // evilspy: //using metamod p-extensions? - if(gpMetaPExtFuncs) { + if(gpMetaPExtFuncs || g_IsNewMM) + { memcpy( pengfuncsFromEngine, pAMXXFunctionTable, sizeof( enginefuncs_t ) ); return TRUE; } @@ -2760,7 +2788,8 @@ int CFakeMeta::GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int * // evilspy: //using metamod p-extensions? - if(gpMetaPExtFuncs) { + if(gpMetaPExtFuncs || g_IsNewMM) + { memcpy( pengfuncsFromEngine, pAMXXFunctionTable, sizeof( enginefuncs_t ) ); return TRUE; } @@ -2803,7 +2832,8 @@ int CFakeMeta::GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *int // evilspy: //using metamod p-extensions? - if(gpMetaPExtFuncs) { + if(gpMetaPExtFuncs || g_IsNewMM) + { memcpy( pNewFunctionTable, pAMXXFunctionTable, sizeof( NEW_DLL_FUNCTIONS ) ); return TRUE; } @@ -2846,7 +2876,8 @@ int CFakeMeta::GetNewDLLFunctions_Post(NEW_DLL_FUNCTIONS *pNewFunctionTable, int // evilspy: //using metamod p-extensions? - if(gpMetaPExtFuncs) { + if(gpMetaPExtFuncs || g_IsNewMM) + { memcpy( pNewFunctionTable, pAMXXFunctionTable, sizeof( NEW_DLL_FUNCTIONS ) ); return TRUE; } diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index f7e23ab3..f7d74310 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -89,6 +89,7 @@ float g_game_timeleft; float g_task_time; float g_auth_time; bool g_initialized = false; +bool g_IsNewMM = false; #ifdef MEMORY_TEST float g_next_memreport_time; @@ -1025,26 +1026,44 @@ void C_AlertMessage_Post(ALERT_TYPE atype, char *szFmt, ...) RETURN_META(MRES_IGNORED); } -C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) { +C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) +{ gpMetaUtilFuncs=pMetaUtilFuncs; *pPlugInfo=&Plugin_info; - if(strcmp(ifvers, Plugin_info.ifvers)) { + if(strcmp(ifvers, Plugin_info.ifvers)) + { int mmajor=0, mminor=0, pmajor=0, pminor=0; LOG_MESSAGE(PLID, "WARNING: meta-interface version mismatch; requested=%s ours=%s", Plugin_info.logtag, ifvers); sscanf(ifvers, "%d:%d", &mmajor, &mminor); sscanf(META_INTERFACE_VERSION, "%d:%d", &pmajor, &pminor); - if(pmajor > mmajor || (pmajor==mmajor && pminor > mminor)) { + if(pmajor > mmajor) + { LOG_ERROR(PLID, "metamod version is too old for this plugin; update metamod"); return(FALSE); - } - else if(pmajor < mmajor) { + } else if(pmajor < mmajor) { LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin"); return(FALSE); - } - else if(pmajor==mmajor && pminor < mminor) + } else if (pmajor==mmajor) { + if (mminor == 10) + { + LOG_MESSAGE(PLID, "WARNING: metamod version is older than expected; consider finding a newer version"); + g_IsNewMM = false; + //hack! + Plugin_info.ifvers = "5:10"; + } else if (mminor == 11) { + g_IsNewMM = true; + } else if (pminor > mminor) { + LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin"); + return FALSE; + } else if (pminor < mminor) { + LOG_MESSAGE(PLID, "WARNING: metamod version is newer than expected; consider finding a newer version of this plugin"); + } LOG_MESSAGE(PLID, "WARNING: metamod version is newer than expected; consider finding a newer version of this plugin"); - else + } else { LOG_ERROR(PLID, "unexpected version comparison; metavers=%s, mmajor=%d, mminor=%d; plugvers=%s, pmajor=%d, pminor=%d", ifvers, mmajor, mminor, META_INTERFACE_VERSION, pmajor, pminor); + } + } else { + g_IsNewMM = true; } // We can set this to null here because Meta_PExtGiveFnptrs is called after this @@ -1056,8 +1075,10 @@ C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_ // evilspy's patch for mm-p ext support // this is called right after Meta_Query -C_DLLEXPORT int Meta_PExtGiveFnptrs(int interfaceVersion, pextension_funcs_t *pMetaPExtFuncs) { - if(interfaceVersion Plugin_info.loadable) { +C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs) +{ + if(now > Plugin_info.loadable) + { LOG_ERROR(PLID, "Can't load plugin right now"); return(FALSE); } + LOG_MESSAGE(PLID, "gpMetaPExtFuncs=%p, g_IsNewMM=%d", gpMetaPExtFuncs, g_IsNewMM); gpMetaGlobals=pMGlobals; gMetaFunctionTable.pfnGetEntityAPI2 = GetEntityAPI2; gMetaFunctionTable.pfnGetEntityAPI2_Post = GetEntityAPI2_Post;