diff --git a/dlls/dod2/dodfun/amxxmodule.cpp b/dlls/dod2/dodfun/amxxmodule.cpp index e22a1187..9f4e7ebb 100755 --- a/dlls/dod2/dodfun/amxxmodule.cpp +++ b/dlls/dod2/dodfun/amxxmodule.cpp @@ -2454,7 +2454,7 @@ PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; PFN_LOG g_fn_Log; -PFN_LOG_ERROR g_fn_LogError; +PFN_LOG_ERROR g_fn_LogErrorFunc; PFN_RAISE_AMXERROR g_fn_RaiseAmxError; PFN_REGISTER_FORWARD g_fn_RegisterForward; PFN_EXECUTE_FORWARD g_fn_ExecuteForward; @@ -2544,7 +2544,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("PrintSrvConsole", g_fn_PrintSrvConsole, PFN_PRINT_SRVCONSOLE); REQFUNC("GetModname", g_fn_GetModname, PFN_GET_MODNAME); REQFUNC("Log", g_fn_Log, PFN_LOG); - REQFUNC("LogError", g_fn_LogError, PFN_LOG_ERROR); + REQFUNC("LogError", g_fn_LogErrorFunc, PFN_LOG_ERROR); REQFUNC("MergeDefinitionFile", g_fn_MergeDefinition_File, PFN_MERGEDEFINITION_FILE); REQFUNC("Format", g_fn_Format, PFN_FORMAT); @@ -2651,6 +2651,18 @@ void MF_Log(const char *fmt, ...) g_fn_Log("[%s] %s", MODULE_NAME, msg); } +void MF_LogError(AMX *amx, int err, const char *fmt, ...) +{ + // :TODO: Overflow possible here + char msg[3072]; + va_list arglst; + va_start(arglst, fmt); + vsprintf(msg, fmt, arglst); + va_end(arglst); + + g_fn_LogErrorFunc(amx, err, "[%s] %s", MODULE_NAME, msg); +} + #ifdef _DEBUG // validate macros diff --git a/dlls/dod2/dodfun/amxxmodule.h b/dlls/dod2/dodfun/amxxmodule.h index 1863c829..e0b0e8fa 100755 --- a/dlls/dod2/dodfun/amxxmodule.h +++ b/dlls/dod2/dodfun/amxxmodule.h @@ -1990,7 +1990,7 @@ extern PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; extern PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; extern PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; extern PFN_LOG g_fn_Log; -extern PFN_LOG_ERROR g_fn_LogError; +extern PFN_LOG_ERROR g_fn_LogErrorFunc; extern PFN_RAISE_AMXERROR g_fn_RaiseAmxError; extern PFN_REGISTER_FORWARD g_fn_RegisterForward; extern PFN_EXECUTE_FORWARD g_fn_ExecuteForward; @@ -2106,7 +2106,7 @@ const char * MF_Format (const char *fmt, ...) { } #define MF_GetAmxStringLen g_fn_GetAmxStringLen #define MF_CopyAmxMemory g_fn_CopyAmxMemory void MF_Log(const char *fmt, ...); -#define MF_LogError g_fn_LogError +void MF_LogError(AMX *amx, int err, const char *fmt, ...); #define MF_RaiseAmxError g_fn_RaiseAmxError #define MF_RegisterForward g_fn_RegisterForward #define MF_ExecuteForward g_fn_ExecuteForward diff --git a/dlls/dod2/dodfun/dodfun.h b/dlls/dod2/dodfun/dodfun.h index 1d6362fd..766896d1 100755 --- a/dlls/dod2/dodfun/dodfun.h +++ b/dlls/dod2/dodfun/dodfun.h @@ -61,14 +61,17 @@ edict_t *FindEntityByClassname(edict_t *pentStart, const char *szName); #define CHECK_ENTITY(x) \ if (x < 0 || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \ + return 0; \ } else { \ if (x <= gpGlobals->maxClients) { \ if (!MF_IsPlayerIngame(x)) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \ + return 0; \ } \ } else { \ if (x != 0 && FNullEnt(INDEXENT(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ + return 0; \ } \ } \ } @@ -76,18 +79,22 @@ edict_t *FindEntityByClassname(edict_t *pentStart, const char *szName); #define CHECK_PLAYER(x) \ if (x < 1 || x > gpGlobals->maxClients) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + return 0; \ } else { \ if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \ + return 0; \ } \ } #define CHECK_NONPLAYER(x) \ if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \ + return 0; \ } else { \ if (FNullEnt(INDEXENT(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid non-player entity %d", x); \ + return 0; \ } \ } diff --git a/dlls/dod2/dodx/amxxmodule.cpp b/dlls/dod2/dodx/amxxmodule.cpp index e22a1187..9f4e7ebb 100755 --- a/dlls/dod2/dodx/amxxmodule.cpp +++ b/dlls/dod2/dodx/amxxmodule.cpp @@ -2454,7 +2454,7 @@ PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; PFN_LOG g_fn_Log; -PFN_LOG_ERROR g_fn_LogError; +PFN_LOG_ERROR g_fn_LogErrorFunc; PFN_RAISE_AMXERROR g_fn_RaiseAmxError; PFN_REGISTER_FORWARD g_fn_RegisterForward; PFN_EXECUTE_FORWARD g_fn_ExecuteForward; @@ -2544,7 +2544,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("PrintSrvConsole", g_fn_PrintSrvConsole, PFN_PRINT_SRVCONSOLE); REQFUNC("GetModname", g_fn_GetModname, PFN_GET_MODNAME); REQFUNC("Log", g_fn_Log, PFN_LOG); - REQFUNC("LogError", g_fn_LogError, PFN_LOG_ERROR); + REQFUNC("LogError", g_fn_LogErrorFunc, PFN_LOG_ERROR); REQFUNC("MergeDefinitionFile", g_fn_MergeDefinition_File, PFN_MERGEDEFINITION_FILE); REQFUNC("Format", g_fn_Format, PFN_FORMAT); @@ -2651,6 +2651,18 @@ void MF_Log(const char *fmt, ...) g_fn_Log("[%s] %s", MODULE_NAME, msg); } +void MF_LogError(AMX *amx, int err, const char *fmt, ...) +{ + // :TODO: Overflow possible here + char msg[3072]; + va_list arglst; + va_start(arglst, fmt); + vsprintf(msg, fmt, arglst); + va_end(arglst); + + g_fn_LogErrorFunc(amx, err, "[%s] %s", MODULE_NAME, msg); +} + #ifdef _DEBUG // validate macros diff --git a/dlls/dod2/dodx/amxxmodule.h b/dlls/dod2/dodx/amxxmodule.h index 1863c829..e0b0e8fa 100755 --- a/dlls/dod2/dodx/amxxmodule.h +++ b/dlls/dod2/dodx/amxxmodule.h @@ -1990,7 +1990,7 @@ extern PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; extern PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; extern PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; extern PFN_LOG g_fn_Log; -extern PFN_LOG_ERROR g_fn_LogError; +extern PFN_LOG_ERROR g_fn_LogErrorFunc; extern PFN_RAISE_AMXERROR g_fn_RaiseAmxError; extern PFN_REGISTER_FORWARD g_fn_RegisterForward; extern PFN_EXECUTE_FORWARD g_fn_ExecuteForward; @@ -2106,7 +2106,7 @@ const char * MF_Format (const char *fmt, ...) { } #define MF_GetAmxStringLen g_fn_GetAmxStringLen #define MF_CopyAmxMemory g_fn_CopyAmxMemory void MF_Log(const char *fmt, ...); -#define MF_LogError g_fn_LogError +void MF_LogError(AMX *amx, int err, const char *fmt, ...); #define MF_RaiseAmxError g_fn_RaiseAmxError #define MF_RegisterForward g_fn_RegisterForward #define MF_ExecuteForward g_fn_ExecuteForward diff --git a/dlls/dod2/dodx/dodx.h b/dlls/dod2/dodx/dodx.h index 622ce121..1b90cfa3 100755 --- a/dlls/dod2/dodx/dodx.h +++ b/dlls/dod2/dodx/dodx.h @@ -114,14 +114,17 @@ edict_t *FindEntityByClassname(edict_t *pentStart, const char *szName); #define CHECK_ENTITY(x) \ if (x < 0 || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \ + return 0; \ } else { \ if (x <= gpGlobals->maxClients) { \ if (!MF_IsPlayerIngame(x)) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \ + return 0; \ } \ } else { \ if (x != 0 && FNullEnt(INDEXENT(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ + return 0; \ } \ } \ } @@ -129,18 +132,22 @@ edict_t *FindEntityByClassname(edict_t *pentStart, const char *szName); #define CHECK_PLAYER(x) \ if (x < 1 || x > gpGlobals->maxClients) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + return 0; \ } else { \ if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \ + return 0; \ } \ } #define CHECK_NONPLAYER(x) \ if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \ + return 0; \ } else { \ if (FNullEnt(INDEXENT(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid non-player entity %d", x); \ + return 0; \ } \ } diff --git a/dlls/tfc/tfcx/amxxmodule.cpp b/dlls/tfc/tfcx/amxxmodule.cpp index e22a1187..9f4e7ebb 100755 --- a/dlls/tfc/tfcx/amxxmodule.cpp +++ b/dlls/tfc/tfcx/amxxmodule.cpp @@ -2454,7 +2454,7 @@ PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; PFN_LOG g_fn_Log; -PFN_LOG_ERROR g_fn_LogError; +PFN_LOG_ERROR g_fn_LogErrorFunc; PFN_RAISE_AMXERROR g_fn_RaiseAmxError; PFN_REGISTER_FORWARD g_fn_RegisterForward; PFN_EXECUTE_FORWARD g_fn_ExecuteForward; @@ -2544,7 +2544,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("PrintSrvConsole", g_fn_PrintSrvConsole, PFN_PRINT_SRVCONSOLE); REQFUNC("GetModname", g_fn_GetModname, PFN_GET_MODNAME); REQFUNC("Log", g_fn_Log, PFN_LOG); - REQFUNC("LogError", g_fn_LogError, PFN_LOG_ERROR); + REQFUNC("LogError", g_fn_LogErrorFunc, PFN_LOG_ERROR); REQFUNC("MergeDefinitionFile", g_fn_MergeDefinition_File, PFN_MERGEDEFINITION_FILE); REQFUNC("Format", g_fn_Format, PFN_FORMAT); @@ -2651,6 +2651,18 @@ void MF_Log(const char *fmt, ...) g_fn_Log("[%s] %s", MODULE_NAME, msg); } +void MF_LogError(AMX *amx, int err, const char *fmt, ...) +{ + // :TODO: Overflow possible here + char msg[3072]; + va_list arglst; + va_start(arglst, fmt); + vsprintf(msg, fmt, arglst); + va_end(arglst); + + g_fn_LogErrorFunc(amx, err, "[%s] %s", MODULE_NAME, msg); +} + #ifdef _DEBUG // validate macros diff --git a/dlls/tfc/tfcx/amxxmodule.h b/dlls/tfc/tfcx/amxxmodule.h index 1863c829..e0b0e8fa 100755 --- a/dlls/tfc/tfcx/amxxmodule.h +++ b/dlls/tfc/tfcx/amxxmodule.h @@ -1990,7 +1990,7 @@ extern PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; extern PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; extern PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; extern PFN_LOG g_fn_Log; -extern PFN_LOG_ERROR g_fn_LogError; +extern PFN_LOG_ERROR g_fn_LogErrorFunc; extern PFN_RAISE_AMXERROR g_fn_RaiseAmxError; extern PFN_REGISTER_FORWARD g_fn_RegisterForward; extern PFN_EXECUTE_FORWARD g_fn_ExecuteForward; @@ -2106,7 +2106,7 @@ const char * MF_Format (const char *fmt, ...) { } #define MF_GetAmxStringLen g_fn_GetAmxStringLen #define MF_CopyAmxMemory g_fn_CopyAmxMemory void MF_Log(const char *fmt, ...); -#define MF_LogError g_fn_LogError +void MF_LogError(AMX *amx, int err, const char *fmt, ...); #define MF_RaiseAmxError g_fn_RaiseAmxError #define MF_RegisterForward g_fn_RegisterForward #define MF_ExecuteForward g_fn_ExecuteForward diff --git a/dlls/tfc/tfcx/tfcx.h b/dlls/tfc/tfcx/tfcx.h index 0649cc98..0c4dc889 100755 --- a/dlls/tfc/tfcx/tfcx.h +++ b/dlls/tfc/tfcx/tfcx.h @@ -108,14 +108,17 @@ bool util_strncmp( const char *sz1, const char *sz2, int size); #define CHECK_ENTITY(x) \ if (x < 0 || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \ + return 0; \ } else { \ if (x <= gpGlobals->maxClients) { \ if (!MF_IsPlayerIngame(x)) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \ + return 0; \ } \ } else { \ if (x != 0 && FNullEnt(INDEXENT(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ + return 0; \ } \ } \ } @@ -123,18 +126,22 @@ bool util_strncmp( const char *sz1, const char *sz2, int size); #define CHECK_PLAYER(x) \ if (x < 1 || x > gpGlobals->maxClients) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + return 0; \ } else { \ if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \ + return 0; \ } \ } #define CHECK_NONPLAYER(x) \ if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \ + return 0; \ } else { \ if (FNullEnt(INDEXENT(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid non-player entity %d", x); \ + return 0; \ } \ } diff --git a/dlls/ts/tsx/amxxmodule.cpp b/dlls/ts/tsx/amxxmodule.cpp index e22a1187..9f4e7ebb 100755 --- a/dlls/ts/tsx/amxxmodule.cpp +++ b/dlls/ts/tsx/amxxmodule.cpp @@ -2454,7 +2454,7 @@ PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; PFN_LOG g_fn_Log; -PFN_LOG_ERROR g_fn_LogError; +PFN_LOG_ERROR g_fn_LogErrorFunc; PFN_RAISE_AMXERROR g_fn_RaiseAmxError; PFN_REGISTER_FORWARD g_fn_RegisterForward; PFN_EXECUTE_FORWARD g_fn_ExecuteForward; @@ -2544,7 +2544,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("PrintSrvConsole", g_fn_PrintSrvConsole, PFN_PRINT_SRVCONSOLE); REQFUNC("GetModname", g_fn_GetModname, PFN_GET_MODNAME); REQFUNC("Log", g_fn_Log, PFN_LOG); - REQFUNC("LogError", g_fn_LogError, PFN_LOG_ERROR); + REQFUNC("LogError", g_fn_LogErrorFunc, PFN_LOG_ERROR); REQFUNC("MergeDefinitionFile", g_fn_MergeDefinition_File, PFN_MERGEDEFINITION_FILE); REQFUNC("Format", g_fn_Format, PFN_FORMAT); @@ -2651,6 +2651,18 @@ void MF_Log(const char *fmt, ...) g_fn_Log("[%s] %s", MODULE_NAME, msg); } +void MF_LogError(AMX *amx, int err, const char *fmt, ...) +{ + // :TODO: Overflow possible here + char msg[3072]; + va_list arglst; + va_start(arglst, fmt); + vsprintf(msg, fmt, arglst); + va_end(arglst); + + g_fn_LogErrorFunc(amx, err, "[%s] %s", MODULE_NAME, msg); +} + #ifdef _DEBUG // validate macros diff --git a/dlls/ts/tsx/amxxmodule.h b/dlls/ts/tsx/amxxmodule.h index 1863c829..e0b0e8fa 100755 --- a/dlls/ts/tsx/amxxmodule.h +++ b/dlls/ts/tsx/amxxmodule.h @@ -1990,7 +1990,7 @@ extern PFN_GET_AMXSTRINGLEN g_fn_GetAmxStringLen; extern PFN_FORMAT_AMXSTRING g_fn_FormatAmxString; extern PFN_COPY_AMXMEMORY g_fn_CopyAmxMemory; extern PFN_LOG g_fn_Log; -extern PFN_LOG_ERROR g_fn_LogError; +extern PFN_LOG_ERROR g_fn_LogErrorFunc; extern PFN_RAISE_AMXERROR g_fn_RaiseAmxError; extern PFN_REGISTER_FORWARD g_fn_RegisterForward; extern PFN_EXECUTE_FORWARD g_fn_ExecuteForward; @@ -2106,7 +2106,7 @@ const char * MF_Format (const char *fmt, ...) { } #define MF_GetAmxStringLen g_fn_GetAmxStringLen #define MF_CopyAmxMemory g_fn_CopyAmxMemory void MF_Log(const char *fmt, ...); -#define MF_LogError g_fn_LogError +void MF_LogError(AMX *amx, int err, const char *fmt, ...); #define MF_RaiseAmxError g_fn_RaiseAmxError #define MF_RegisterForward g_fn_RegisterForward #define MF_ExecuteForward g_fn_ExecuteForward diff --git a/dlls/ts/tsx/tsx.h b/dlls/ts/tsx/tsx.h index 18720801..2d05888f 100755 --- a/dlls/ts/tsx/tsx.h +++ b/dlls/ts/tsx/tsx.h @@ -111,14 +111,17 @@ bool ignoreBots (edict_t *pEnt, edict_t *pOther = NULL); #define CHECK_ENTITY(x) \ if (x < 0 || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \ + return 0; \ } else { \ if (x <= gpGlobals->maxClients) { \ if (!MF_IsPlayerIngame(x)) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \ + return 0; \ } \ } else { \ if (x != 0 && FNullEnt(INDEXENT(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ + return 0; \ } \ } \ } @@ -126,18 +129,22 @@ bool ignoreBots (edict_t *pEnt, edict_t *pOther = NULL); #define CHECK_PLAYER(x) \ if (x < 1 || x > gpGlobals->maxClients) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ + return 0; \ } else { \ if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \ + return 0; \ } \ } #define CHECK_NONPLAYER(x) \ if (x < 1 || x <= gpGlobals->maxClients || x > gpGlobals->maxEntities) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Non-player entity %d out of range", x); \ + return 0; \ } else { \ if (FNullEnt(INDEXENT(x))) { \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid non-player entity %d", x); \ + return 0; \ } \ }