Added check for mod game when a module loads: If the module has the optional function, and reports that it is not an expected game, the module will not load.
This should fix how some people seem to think the counter strike modules will work on games other than counter strike.
This commit is contained in:
parent
4049a0c3be
commit
1d7cbd4203
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
*/
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
*/
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user