diff --git a/amxmodx/CModule.cpp b/amxmodx/CModule.cpp index 77486406..2692b516 100755 --- a/amxmodx/CModule.cpp +++ b/amxmodx/CModule.cpp @@ -39,6 +39,7 @@ // New typedef void* (*PFN_REQ_FNPTR)(const char * /*name*/); typedef int (FAR *QUERYMOD_NEW)(int * /*ifvers*/, amxx_module_info_s * /*modInfo*/); +typedef int (FAR *CHECKGAME_NEW)(const char *); typedef int (FAR *ATTACHMOD_NEW)(PFN_REQ_FNPTR /*reqFnptrFunc*/); typedef int (FAR *DETACHMOD_NEW)(void); typedef void (FAR *PLUGINSLOADED_NEW)(void); @@ -296,6 +297,33 @@ bool CModule::queryModule() return false; } + + // Lastly, check to see if this module is able to load on this game mod + CHECKGAME_NEW checkGame_New = (CHECKGAME_NEW)DLPROC(m_Handle, "AMXX_CheckGame"); + + if (checkGame_New) + { + // This is an optional check; do not fail modules that do not have it + int ret = checkGame_New(g_mod_name.c_str()); + + if (ret != AMXX_GAME_OK) + { + switch (ret) + { + case AMXX_GAME_BAD: + AMXXLOG_Log("[AMXX] Module \"%s\" (version \"%s\") reported that it cannot load on game \"%s\"", m_Filename.c_str(), getVersion(), g_mod_name.c_str()); + m_Status = MODULE_BADGAME; + break; + default: + AMXXLOG_Log("[AMXX] Module \"%s\" (version \"%s\") returned an unknown CheckGame code (value: %d)", m_Filename.c_str(), getVersion(), ret); + m_Status = MODULE_BADLOAD; + break; + } + + return false; + } + } + m_Status = MODULE_QUERY; return true; } else { @@ -403,6 +431,7 @@ const char* CModule::getStatus() const case MODULE_NEWER: return "newer"; case MODULE_INTERROR: return "internal err"; case MODULE_NOT64BIT: return "not 64bit"; + case MODULE_BADGAME: return "bad game"; default: break; } diff --git a/amxmodx/CModule.h b/amxmodx/CModule.h index 5f7c2030..32b80d62 100755 --- a/amxmodx/CModule.h +++ b/amxmodx/CModule.h @@ -49,7 +49,8 @@ enum MODULE_STATUS MODULE_NEWER, // newer interface MODULE_INTERROR, // Internal error MODULE_FUNCNOTPRESENT, // Function not present - MODULE_NOT64BIT // Not 64 bit compatible + MODULE_NOT64BIT, // Not 64 bit compatible + MODULE_BADGAME, // Module cannot load on the current game mod }; struct amxx_module_info_s @@ -68,6 +69,9 @@ struct amxx_module_info_s #define AMXX_PARAM 2 /* Invalid parameter */ #define AMXX_FUNC_NOT_PRESENT 3 /* Function not present */ +#define AMXX_GAME_OK 0 /* Module can load on this game. */ +#define AMXX_GAME_BAD 1 /* Module cannot load on this game. */ + #define AMXX_INTERFACE_VERSION 4 class CModule diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 4bcd4ae2..f8a88727 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -958,6 +958,9 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no case MODULE_NOT64BIT: report_error(1, "[AMXX] Module \"%s\" is not 64 bit compatible.", path.c_str()); break; + case MODULE_BADGAME: + report_error(1, "[AMXX] Module \"%s\" cannot load on game \"%s\"", path.c_str(), g_mod_name.c_str()); + break; default: error = false; break; diff --git a/amxmodx/sdk/amxxmodule.cpp b/amxmodx/sdk/amxxmodule.cpp index 3a6a2a00..a634e9ac 100755 --- a/amxmodx/sdk/amxxmodule.cpp +++ b/amxmodx/sdk/amxxmodule.cpp @@ -2548,6 +2548,14 @@ C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo // request optional function #define REQFUNC_OPT(name, fptr, type) fptr = (type)reqFnptrFunc(name) +C_DLLEXPORT int AMXX_CheckGame(const char *game) +{ +#ifdef FN_AMXX_CHECKGAME + return FN_AMXX_CHECKGAME(game); +#else + return AMXX_GAME_OK; +#endif +} C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) { // Check pointer diff --git a/amxmodx/sdk/amxxmodule.h b/amxmodx/sdk/amxxmodule.h index a99c1fca..97454e9b 100755 --- a/amxmodx/sdk/amxxmodule.h +++ b/amxmodx/sdk/amxxmodule.h @@ -55,6 +55,9 @@ struct amxx_module_info_s #define AMXX_PARAM 2 /* Invalid parameter */ #define AMXX_FUNC_NOT_PRESENT 3 /* Function not present */ +#define AMXX_GAME_OK 0 /* This module can load on the current game mod. */ +#define AMXX_GAME_BAD 1 /* This module can not load on the current game mod. */ + // *** Small stuff *** // The next section is copied from the amx.h file // Copyright (c) ITB CompuPhase, 1997-2005 @@ -2023,6 +2026,10 @@ int FN_ShouldCollide_Post(edict_t *pentTouched, edict_t *pentOther); void FN_AMXX_QUERY(void); #endif // FN_AMXX_QUERY +#ifdef FN_AMXX_CHECKGAME +int FN_AMXX_CHECKGAME(const char *); +#endif // FN_AMXX_CHECKGAME + #ifdef FN_AMXX_ATTACH void FN_AMXX_ATTACH(void); #endif // FN_AMXX_ATTACH diff --git a/amxmodx/sdk/moduleconfig.h b/amxmodx/sdk/moduleconfig.h index 9ef5e232..34677bec 100755 --- a/amxmodx/sdk/moduleconfig.h +++ b/amxmodx/sdk/moduleconfig.h @@ -54,6 +54,12 @@ /** AMXX query */ //#define FN_AMXX_QUERY OnAmxxQuery +/** AMXX Check Game - module API is NOT available here. + * Return AMXX_GAME_OK if this module can load on the game, AMXX_GAME_BAD if it cannot. + * syntax: int AmxxCheckGame(const char *game) + */ +//#define FN_AMXX_CHECKGAME AmxxCheckGame + /** AMXX attach * Do native functions init here (MF_AddNatives) */ diff --git a/dlls/cstrike/cstrike/cstrike.cpp b/dlls/cstrike/cstrike/cstrike.cpp index 933fae18..5745d662 100755 --- a/dlls/cstrike/cstrike/cstrike.cpp +++ b/dlls/cstrike/cstrike/cstrike.cpp @@ -1905,6 +1905,15 @@ void PlayerPreThink(edict_t *pPlayer) RETURN_META(MRES_IGNORED); } +int AmxxCheckGame(const char *game) +{ + if (strcasecmp(game, "cstrike") == 0 || + strcasecmp(game, "czero") == 0) + { + return AMXX_GAME_OK; + } + return AMXX_GAME_BAD; +} void OnAmxxAttach() { MF_AddNatives(cstrike_Exports); diff --git a/dlls/cstrike/cstrike/sdk/amxxmodule.cpp b/dlls/cstrike/cstrike/sdk/amxxmodule.cpp index 3a6a2a00..a634e9ac 100755 --- a/dlls/cstrike/cstrike/sdk/amxxmodule.cpp +++ b/dlls/cstrike/cstrike/sdk/amxxmodule.cpp @@ -2548,6 +2548,14 @@ C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo // request optional function #define REQFUNC_OPT(name, fptr, type) fptr = (type)reqFnptrFunc(name) +C_DLLEXPORT int AMXX_CheckGame(const char *game) +{ +#ifdef FN_AMXX_CHECKGAME + return FN_AMXX_CHECKGAME(game); +#else + return AMXX_GAME_OK; +#endif +} C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) { // Check pointer diff --git a/dlls/cstrike/cstrike/sdk/amxxmodule.h b/dlls/cstrike/cstrike/sdk/amxxmodule.h index a99c1fca..97454e9b 100755 --- a/dlls/cstrike/cstrike/sdk/amxxmodule.h +++ b/dlls/cstrike/cstrike/sdk/amxxmodule.h @@ -55,6 +55,9 @@ struct amxx_module_info_s #define AMXX_PARAM 2 /* Invalid parameter */ #define AMXX_FUNC_NOT_PRESENT 3 /* Function not present */ +#define AMXX_GAME_OK 0 /* This module can load on the current game mod. */ +#define AMXX_GAME_BAD 1 /* This module can not load on the current game mod. */ + // *** Small stuff *** // The next section is copied from the amx.h file // Copyright (c) ITB CompuPhase, 1997-2005 @@ -2023,6 +2026,10 @@ int FN_ShouldCollide_Post(edict_t *pentTouched, edict_t *pentOther); void FN_AMXX_QUERY(void); #endif // FN_AMXX_QUERY +#ifdef FN_AMXX_CHECKGAME +int FN_AMXX_CHECKGAME(const char *); +#endif // FN_AMXX_CHECKGAME + #ifdef FN_AMXX_ATTACH void FN_AMXX_ATTACH(void); #endif // FN_AMXX_ATTACH diff --git a/dlls/cstrike/cstrike/sdk/moduleconfig.h b/dlls/cstrike/cstrike/sdk/moduleconfig.h index 0f6a2a86..144e75e8 100755 --- a/dlls/cstrike/cstrike/sdk/moduleconfig.h +++ b/dlls/cstrike/cstrike/sdk/moduleconfig.h @@ -46,6 +46,12 @@ /** AMXX query */ //#define FN_AMXX_QUERY OnAmxxQuery +/** AMXX Check Game - module API is NOT available here. + * Return AMXX_GAME_OK if this module can load on the game, AMXX_GAME_BAD if it cannot. + * syntax: int AmxxCheckGame(const char *game) + */ +#define FN_AMXX_CHECKGAME AmxxCheckGame + /** AMXX attach * Do native functions init here (MF_AddNatives) */ diff --git a/dlls/cstrike/csx/meta_api.cpp b/dlls/cstrike/csx/meta_api.cpp index 8900f5de..eccc97af 100755 --- a/dlls/cstrike/csx/meta_api.cpp +++ b/dlls/cstrike/csx/meta_api.cpp @@ -379,6 +379,15 @@ void OnMetaAttach() { csstats_pause = CVAR_GET_POINTER(init_csstats_pause.name); } +int AmxxCheckGame(const char *game) +{ + if (strcasecmp(game, "cstrike") == 0 || + strcasecmp(game, "czero") == 0) + { + return AMXX_GAME_OK; + } + return AMXX_GAME_BAD; +} void OnAmxxAttach(){ MF_AddNatives(stats_Natives); const char* path = get_localinfo("csstats_score"); diff --git a/dlls/cstrike/csx/sdk/amxxmodule.cpp b/dlls/cstrike/csx/sdk/amxxmodule.cpp index 3a6a2a00..a634e9ac 100755 --- a/dlls/cstrike/csx/sdk/amxxmodule.cpp +++ b/dlls/cstrike/csx/sdk/amxxmodule.cpp @@ -2548,6 +2548,14 @@ C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo // request optional function #define REQFUNC_OPT(name, fptr, type) fptr = (type)reqFnptrFunc(name) +C_DLLEXPORT int AMXX_CheckGame(const char *game) +{ +#ifdef FN_AMXX_CHECKGAME + return FN_AMXX_CHECKGAME(game); +#else + return AMXX_GAME_OK; +#endif +} C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) { // Check pointer diff --git a/dlls/cstrike/csx/sdk/amxxmodule.h b/dlls/cstrike/csx/sdk/amxxmodule.h index a99c1fca..97454e9b 100755 --- a/dlls/cstrike/csx/sdk/amxxmodule.h +++ b/dlls/cstrike/csx/sdk/amxxmodule.h @@ -55,6 +55,9 @@ struct amxx_module_info_s #define AMXX_PARAM 2 /* Invalid parameter */ #define AMXX_FUNC_NOT_PRESENT 3 /* Function not present */ +#define AMXX_GAME_OK 0 /* This module can load on the current game mod. */ +#define AMXX_GAME_BAD 1 /* This module can not load on the current game mod. */ + // *** Small stuff *** // The next section is copied from the amx.h file // Copyright (c) ITB CompuPhase, 1997-2005 @@ -2023,6 +2026,10 @@ int FN_ShouldCollide_Post(edict_t *pentTouched, edict_t *pentOther); void FN_AMXX_QUERY(void); #endif // FN_AMXX_QUERY +#ifdef FN_AMXX_CHECKGAME +int FN_AMXX_CHECKGAME(const char *); +#endif // FN_AMXX_CHECKGAME + #ifdef FN_AMXX_ATTACH void FN_AMXX_ATTACH(void); #endif // FN_AMXX_ATTACH diff --git a/dlls/cstrike/csx/sdk/moduleconfig.h b/dlls/cstrike/csx/sdk/moduleconfig.h index 2fa954a6..cce28f8d 100755 --- a/dlls/cstrike/csx/sdk/moduleconfig.h +++ b/dlls/cstrike/csx/sdk/moduleconfig.h @@ -46,6 +46,12 @@ /** AMXX query */ //#define FN_AMXX_QUERY OnAmxxQuery +/** AMXX Check Game - module API is NOT available here. + * Return AMXX_GAME_OK if this module can load on the game, AMXX_GAME_BAD if it cannot. + * syntax: int AmxxCheckGame(const char *game) + */ +#define FN_AMXX_CHECKGAME AmxxCheckGame + /** AMXX attach * Do native functions init here (MF_AddNatives) */ diff --git a/dlls/ns/amxxapi.cpp b/dlls/ns/amxxapi.cpp index 881ff29f..5ac5f1e9 100644 --- a/dlls/ns/amxxapi.cpp +++ b/dlls/ns/amxxapi.cpp @@ -90,7 +90,15 @@ void OnPluginsLoaded() - +int AmxxCheckGame(const char *game) +{ + if (strcasecmp(game, "ns") == 0 || + strcasecmp(game, "nsp") == 0) + { + return AMXX_GAME_OK; + } + return AMXX_GAME_BAD; +} // Module is attaching to AMXX void OnAmxxAttach() { diff --git a/dlls/ns/sdk/amxxmodule.cpp b/dlls/ns/sdk/amxxmodule.cpp index ab2cbdb6..a634e9ac 100755 --- a/dlls/ns/sdk/amxxmodule.cpp +++ b/dlls/ns/sdk/amxxmodule.cpp @@ -2284,7 +2284,7 @@ C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_ } #ifdef FN_META_QUERY - return FN_META_QUERY(); + FN_META_QUERY(); #endif // FN_META_QUERY return 1; @@ -2327,7 +2327,7 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) } #ifdef FN_META_DETACH - return FN_META_DETACH(); + FN_META_DETACH(); #endif // FN_META_DETACH return TRUE; } @@ -2374,7 +2374,7 @@ C_DLLEXPORT void __stdcall GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, gpGlobals = pGlobals; // NOTE! Have to call logging function _after_ copying into g_engfuncs, so // that g_engfuncs.pfnAlertMessage() can be resolved properly, heh. :) - UTIL_LogPrintf("[%s] dev: called: GiveFnptrsToDll\n", Plugin_info.logtag); + // UTIL_LogPrintf("[%s] dev: called: GiveFnptrsToDll\n", Plugin_info.logtag); // --> ** Function core #ifdef _MSC_VER @@ -2548,6 +2548,14 @@ C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo // request optional function #define REQFUNC_OPT(name, fptr, type) fptr = (type)reqFnptrFunc(name) +C_DLLEXPORT int AMXX_CheckGame(const char *game) +{ +#ifdef FN_AMXX_CHECKGAME + return FN_AMXX_CHECKGAME(game); +#else + return AMXX_GAME_OK; +#endif +} C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) { // Check pointer diff --git a/dlls/ns/sdk/amxxmodule.h b/dlls/ns/sdk/amxxmodule.h index 964ad53b..97454e9b 100755 --- a/dlls/ns/sdk/amxxmodule.h +++ b/dlls/ns/sdk/amxxmodule.h @@ -55,6 +55,9 @@ struct amxx_module_info_s #define AMXX_PARAM 2 /* Invalid parameter */ #define AMXX_FUNC_NOT_PRESENT 3 /* Function not present */ +#define AMXX_GAME_OK 0 /* This module can load on the current game mod. */ +#define AMXX_GAME_BAD 1 /* This module can not load on the current game mod. */ + // *** Small stuff *** // The next section is copied from the amx.h file // Copyright (c) ITB CompuPhase, 1997-2005 @@ -1077,7 +1080,7 @@ void FN_AlertMessage(ALERT_TYPE atype, char *szFmt, ...); #endif // FN_AlertMessage #ifdef FN_EngineFprintf -void FN_EngineFprintf(FILE *pfile, char *szFmt, ...); +void FN_EngineFprintf(void *pfile, char *szFmt, ...); #endif // FN_EngineFprintf #ifdef FN_PvAllocEntPrivateData @@ -1141,11 +1144,11 @@ void FN_GetBonePosition(const edict_t *pEdict, int iBone, float *rgflOrigin, flo #endif // FN_GetBonePosition #ifdef FN_FunctionFromName -unsigned long FN_FunctionFromName(const char *pName); +uint32 FN_FunctionFromName(const char *pName); #endif // FN_FunctionFromName #ifdef FN_NameForFunction -const char *FN_NameForFunction(unsigned long function); +const char *FN_NameForFunction(uint32); #endif // FN_NameForFunction #ifdef FN_ClientPrintf @@ -1189,7 +1192,7 @@ CRC32_t FN_CRC32_Final(CRC32_t pulCRC); #endif // FN_CRC32_Final #ifdef FN_RandomLong -long FN_RandomLong(long lLow, long lHigh); +int32 FN_RandomLong(int32 lLow, int32 lHigh); #endif // FN_RandomLong #ifdef FN_RandomFloat @@ -1658,11 +1661,11 @@ void FN_AlertMessage_Post(ALERT_TYPE atype, char *szFmt, ...); #endif // FN_AlertMessage_Post #ifdef FN_EngineFprintf_Post -void FN_EngineFprintf_Post(FILE *pfile, char *szFmt, ...); +void FN_EngineFprintf_Post(void *pfile, char *szFmt, ...); #endif // FN_EngineFprintf_Post #ifdef FN_PvAllocEntPrivateData_Post -void *FN_PvAllocEntPrivateData_Post(edict_t *pEdict, long cb); +void *FN_PvAllocEntPrivateData_Post(edict_t *pEdict, int32 cb); #endif // FN_PvAllocEntPrivateData_Post #ifdef FN_PvEntPrivateData_Post @@ -1722,11 +1725,11 @@ void FN_GetBonePosition_Post(const edict_t *pEdict, int iBone, float *rgflOrigin #endif // FN_GetBonePosition_Post #ifdef FN_FunctionFromName_Post -unsigned long FN_FunctionFromName_Post(const char *pName); +uint32 FN_FunctionFromName_Post(const char *pName); #endif // FN_FunctionFromName_Post #ifdef FN_NameForFunction_Post -const char *FN_NameForFunction_Post(unsigned long function); +const char *FN_NameForFunction_Post(uint32); #endif // FN_NameForFunction_Post #ifdef FN_ClientPrintf_Post @@ -1770,7 +1773,7 @@ CRC32_t FN_CRC32_Final_Post(CRC32_t pulCRC); #endif // FN_CRC32_Final_Post #ifdef FN_RandomLong_Post -long FN_RandomLong_Post(long lLow, long lHigh); +int32 FN_RandomLong_Post(int32 lLow, int32 lHigh); #endif // FN_RandomLong_Post #ifdef FN_RandomFloat_Post @@ -2023,6 +2026,10 @@ int FN_ShouldCollide_Post(edict_t *pentTouched, edict_t *pentOther); void FN_AMXX_QUERY(void); #endif // FN_AMXX_QUERY +#ifdef FN_AMXX_CHECKGAME +int FN_AMXX_CHECKGAME(const char *); +#endif // FN_AMXX_CHECKGAME + #ifdef FN_AMXX_ATTACH void FN_AMXX_ATTACH(void); #endif // FN_AMXX_ATTACH diff --git a/dlls/ns/sdk/moduleconfig.h b/dlls/ns/sdk/moduleconfig.h index 5373ffcd..d1c297b3 100755 --- a/dlls/ns/sdk/moduleconfig.h +++ b/dlls/ns/sdk/moduleconfig.h @@ -46,6 +46,12 @@ /** AMXX query */ //#define FN_AMXX_QUERY OnAmxxQuery +/** AMXX Check Game - module API is NOT available here. + * Return AMXX_GAME_OK if this module can load on the game, AMXX_GAME_BAD if it cannot. + * syntax: int AmxxCheckGame(const char *game) + */ +#define FN_AMXX_CHECKGAME AmxxCheckGame + /** AMXX attach * Do native functions init here (MF_AddNatives) */