2014-08-04 08:36:20 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2013-02-13 07:14:37 +00:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
|
|
|
#if defined(__linux__)
|
2004-10-30 09:42:54 +00:00
|
|
|
#include <malloc.h>
|
2013-02-13 07:14:37 +00:00
|
|
|
#endif
|
|
|
|
|
2004-10-30 09:42:54 +00:00
|
|
|
#include <stdlib.h>
|
2004-10-29 20:35:23 +00:00
|
|
|
#include <sys/mman.h>
|
2005-07-27 16:24:14 +00:00
|
|
|
#include "sclinux.h"
|
2004-10-29 20:35:23 +00:00
|
|
|
#endif
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-03-24 01:35:44 +00:00
|
|
|
#include "amxmodx.h"
|
2004-01-31 20:56:22 +00:00
|
|
|
#include "osdep.h" // sleep, etc
|
2004-07-21 20:00:10 +00:00
|
|
|
#include "amxxfile.h"
|
2005-07-26 21:31:21 +00:00
|
|
|
#include "amxdbg.h"
|
2005-07-29 06:33:57 +00:00
|
|
|
#include "newmenus.h"
|
2005-07-31 20:11:58 +00:00
|
|
|
#include "natives.h"
|
2005-09-09 03:23:31 +00:00
|
|
|
#include "debugger.h"
|
2006-02-10 15:43:27 +00:00
|
|
|
#include "optimizer.h"
|
2006-03-16 06:36:01 +00:00
|
|
|
#include "binlog.h"
|
2006-05-07 09:56:06 +00:00
|
|
|
#include "libraries.h"
|
2006-05-11 08:35:21 +00:00
|
|
|
#include "messages.h"
|
2008-04-14 19:52:11 +00:00
|
|
|
#include "trie_natives.h"
|
2014-04-11 20:57:42 +00:00
|
|
|
#include "CDataPack.h"
|
2015-06-23 18:04:17 +00:00
|
|
|
#include "CGameConfigs.h"
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CModule, const char*> g_modules;
|
|
|
|
CList<CScript, AMX*> g_loadedscripts;
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
CModule *g_CurrentlyCalledModule = NULL; // The module we are in at the moment; NULL otherwise
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-29 17:16:28 +00:00
|
|
|
// also NULL for non-amxx modules
|
|
|
|
// This is needed so we know which module called a function
|
2004-04-03 19:15:06 +00:00
|
|
|
ModuleCallReason g_ModuleCallReason;
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
extern const char* no_function; // stupid work around
|
2004-03-31 18:02:37 +00:00
|
|
|
|
2013-02-13 07:14:37 +00:00
|
|
|
void report_error(int code, const char* fmt, ...)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[256];
|
|
|
|
*string = 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
va_start(argptr, fmt);
|
|
|
|
vsnprintf(string, 255, fmt, argptr);
|
2004-01-31 20:56:22 +00:00
|
|
|
string[255] = 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
va_end(argptr);
|
|
|
|
|
|
|
|
if (*string)
|
|
|
|
{
|
2004-06-28 18:12:26 +00:00
|
|
|
AMXXLOG_Log("Error:");
|
2004-03-31 18:02:37 +00:00
|
|
|
AMXXLOG_Log(string);
|
2005-09-16 23:48:51 +00:00
|
|
|
} else {
|
2004-06-28 18:12:26 +00:00
|
|
|
AMXXLOG_Log("!!! There was an unexpected module error.");
|
|
|
|
AMXXLOG_Log("The server may not work correctly.");
|
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 07:14:37 +00:00
|
|
|
void print_srvconsole(const char *fmt, ...)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2004-04-29 17:16:28 +00:00
|
|
|
va_list argptr;
|
2005-07-08 05:05:06 +00:00
|
|
|
static char string[384];
|
|
|
|
va_start(argptr, fmt);
|
2005-09-16 23:48:51 +00:00
|
|
|
vsnprintf(string, sizeof(string) - 1, fmt, argptr);
|
|
|
|
string[sizeof(string) - 1] = '\0';
|
2005-07-08 05:05:06 +00:00
|
|
|
va_end(argptr);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-29 17:16:28 +00:00
|
|
|
SERVER_PRINT(string);
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void* alloc_amxmemory(void** p, int size)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
*p = new unsigned char[size];
|
2004-01-31 20:56:22 +00:00
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_amxmemory(void **ptr)
|
|
|
|
{
|
2005-07-26 21:31:21 +00:00
|
|
|
delete[] (unsigned char *)(*ptr);
|
2004-01-31 20:56:22 +00:00
|
|
|
*ptr = 0;
|
|
|
|
}
|
|
|
|
|
2006-03-16 06:36:01 +00:00
|
|
|
#if defined BINLOG_ENABLED
|
|
|
|
void BinLog_LogNative(AMX *amx, int native, int params)
|
|
|
|
{
|
|
|
|
CPluginMngr::CPlugin *pl = g_plugins.findPluginFast(amx);
|
|
|
|
if (pl)
|
|
|
|
g_BinLog.WriteOp(BinLog_NativeCall, pl->getId(), native, params);
|
|
|
|
}
|
|
|
|
void BinLog_LogReturn(AMX *amx, cell retval)
|
|
|
|
{
|
|
|
|
CPluginMngr::CPlugin *pl = g_plugins.findPluginFast(amx);
|
|
|
|
if (pl)
|
|
|
|
g_BinLog.WriteOp(BinLog_NativeRet, pl->getId(), retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinLog_LogParams(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
if (g_binlog_level & 8)
|
|
|
|
{
|
|
|
|
CPluginMngr::CPlugin *pl = g_plugins.findPluginFast(amx);
|
|
|
|
if (pl)
|
|
|
|
g_BinLog.WriteOp(BinLog_NativeParams, pl->getId(), params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static binlogfuncs_t logfuncs =
|
|
|
|
{
|
|
|
|
BinLog_LogNative,
|
|
|
|
BinLog_LogReturn,
|
|
|
|
BinLog_LogParams
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2004-09-08 07:05:16 +00:00
|
|
|
int load_amxscript(AMX *amx, void **program, const char *filename, char error[64], int debug)
|
2004-07-21 20:00:10 +00:00
|
|
|
{
|
|
|
|
*error = 0;
|
2006-05-07 21:16:00 +00:00
|
|
|
size_t bufSize;
|
|
|
|
*program = (void *)g_plugins.ReadIntoOrFromCache(filename, bufSize);
|
|
|
|
if (!*program)
|
2004-07-21 20:00:10 +00:00
|
|
|
{
|
2006-05-07 21:16:00 +00:00
|
|
|
CAmxxReader reader(filename, PAWN_CELL_SIZE / 8);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2006-05-07 21:16:00 +00:00
|
|
|
if (reader.GetStatus() == CAmxxReader::Err_None)
|
2004-07-21 20:00:10 +00:00
|
|
|
{
|
2006-05-07 21:16:00 +00:00
|
|
|
bufSize = reader.GetBufferSize();
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2006-05-07 21:16:00 +00:00
|
|
|
if (bufSize != 0)
|
2004-07-21 20:00:10 +00:00
|
|
|
{
|
2006-05-07 21:16:00 +00:00
|
|
|
*program = (void*) (new char[bufSize]);
|
|
|
|
|
|
|
|
if (!*program)
|
|
|
|
{
|
|
|
|
strcpy(error, "Failed to allocate memory");
|
|
|
|
return (amx->error = AMX_ERR_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
reader.GetSection(*program);
|
2004-07-21 20:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-07 21:16:00 +00:00
|
|
|
|
|
|
|
switch (reader.GetStatus())
|
|
|
|
{
|
|
|
|
case CAmxxReader::Err_None:
|
|
|
|
break;
|
|
|
|
case CAmxxReader::Err_FileOpen:
|
|
|
|
strcpy(error, "Plugin file open error");
|
|
|
|
return (amx->error = AMX_ERR_NOTFOUND);
|
|
|
|
case CAmxxReader::Err_FileRead:
|
|
|
|
strcpy(error, "Plugin file read error");
|
|
|
|
return (amx->error = AMX_ERR_NOTFOUND);
|
|
|
|
case CAmxxReader::Err_InvalidParam:
|
|
|
|
strcpy(error, "Internal error: Invalid parameter");
|
|
|
|
return (amx->error = AMX_ERR_NOTFOUND);
|
|
|
|
case CAmxxReader::Err_FileInvalid:
|
|
|
|
strcpy(error, "Invalid Plugin");
|
|
|
|
return (amx->error = AMX_ERR_FORMAT);
|
|
|
|
case CAmxxReader::Err_SectionNotFound:
|
|
|
|
strcpy(error, "Searched section not found (.amxx)");
|
|
|
|
return (amx->error = AMX_ERR_NOTFOUND);
|
|
|
|
case CAmxxReader::Err_DecompressorInit:
|
|
|
|
strcpy(error, "Decompressor initialization failed");
|
|
|
|
return (amx->error = AMX_ERR_INIT);
|
|
|
|
case CAmxxReader::Err_Decompress:
|
|
|
|
strcpy(error, "Internal error: Decompress");
|
|
|
|
return (amx->error = AMX_ERR_NOTFOUND);
|
|
|
|
case CAmxxReader::Err_OldFile:
|
|
|
|
strcpy(error, "Plugin uses deprecated format. Update compiler");
|
2015-07-30 12:59:01 +00:00
|
|
|
return (amx->error = AMX_ERR_FORMAT);
|
2006-05-07 21:16:00 +00:00
|
|
|
default:
|
|
|
|
strcpy(error, "Unknown error");
|
|
|
|
return (amx->error = AMX_ERR_NOTFOUND);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
g_plugins.InvalidateFileInCache(filename, false);
|
2004-07-21 20:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for magic
|
|
|
|
AMX_HEADER *hdr = (AMX_HEADER*)*program;
|
|
|
|
uint16_t magic = hdr->magic;
|
|
|
|
amx_Align16(&magic);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-07-21 20:00:10 +00:00
|
|
|
if (magic != AMX_MAGIC)
|
|
|
|
{
|
|
|
|
strcpy(error, "Invalid Plugin");
|
|
|
|
return (amx->error = AMX_ERR_FORMAT);
|
|
|
|
}
|
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
int err;
|
|
|
|
memset(amx, 0, sizeof(*amx));
|
2005-07-26 21:31:21 +00:00
|
|
|
bool will_be_debugged = false;
|
|
|
|
tagAMX_DBG *pDbg = NULL;
|
2005-07-25 06:03:43 +00:00
|
|
|
|
|
|
|
if ((int)CVAR_GET_FLOAT("amx_debug") >= 2 || debug)
|
2004-09-08 07:05:16 +00:00
|
|
|
{
|
2005-07-26 21:31:21 +00:00
|
|
|
if ((hdr->file_version < CUR_FILE_VERSION))
|
2005-07-25 06:03:43 +00:00
|
|
|
{
|
2005-07-26 21:31:21 +00:00
|
|
|
sprintf(error, "Plugin needs newer debug version info");
|
|
|
|
return (amx->error = AMX_ERR_VERSION);
|
2005-09-16 23:48:51 +00:00
|
|
|
}
|
|
|
|
else if ((hdr->flags & AMX_FLAG_DEBUG) != 0)
|
|
|
|
{
|
2005-07-26 21:31:21 +00:00
|
|
|
will_be_debugged = true;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-26 21:31:21 +00:00
|
|
|
char *addr = (char *)hdr + hdr->size;
|
|
|
|
pDbg = new tagAMX_DBG;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-26 21:31:21 +00:00
|
|
|
memset(pDbg, 0, sizeof(AMX_DBG));
|
|
|
|
|
|
|
|
int err = dbg_LoadInfo(pDbg, addr);
|
|
|
|
|
|
|
|
if (err != AMX_ERR_NONE)
|
|
|
|
{
|
|
|
|
dbg_FreeInfo(pDbg);
|
|
|
|
delete pDbg;
|
|
|
|
sprintf(error, "Debug loading error %d", err);
|
|
|
|
return (amx->error = AMX_ERR_INIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
amx->flags |= AMX_FLAG_DEBUG;
|
|
|
|
} else {
|
2005-09-16 23:48:51 +00:00
|
|
|
sprintf(error, "Plugin not compiled with debug option");
|
2005-07-26 21:31:21 +00:00
|
|
|
return (amx->error = AMX_ERR_INIT);
|
2005-07-25 06:03:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#ifdef JIT
|
|
|
|
//if (hdr->file_version == CUR_FILE_VERSION)
|
|
|
|
amx->flags |= AMX_FLAG_JITC;
|
|
|
|
#endif
|
2004-09-08 07:05:16 +00:00
|
|
|
}
|
|
|
|
|
2006-03-17 22:50:13 +00:00
|
|
|
if (g_opt_level != 65536)
|
|
|
|
{
|
|
|
|
SetupOptimizer(amx);
|
|
|
|
}
|
2006-02-10 15:43:27 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
if ((err = amx_Init(amx, *program)) != AMX_ERR_NONE)
|
2004-04-29 17:16:28 +00:00
|
|
|
{
|
2005-07-26 21:31:21 +00:00
|
|
|
if (pDbg)
|
|
|
|
{
|
|
|
|
dbg_FreeInfo(pDbg);
|
|
|
|
delete pDbg;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
|
|
|
sprintf(error, "Load error %d (invalid file format or version)", err);
|
2004-04-29 17:16:28 +00:00
|
|
|
return (amx->error = AMX_ERR_INIT);
|
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2005-09-09 23:13:34 +00:00
|
|
|
Handler *pHandler = new Handler(amx);
|
|
|
|
amx->userdata[UD_HANDLER] = (void *)pHandler;
|
|
|
|
|
2006-03-16 06:36:01 +00:00
|
|
|
#if defined BINLOG_ENABLED
|
|
|
|
amx->usertags[UT_BINLOGS] = (void *)&logfuncs;
|
|
|
|
#endif
|
|
|
|
|
2005-07-26 21:31:21 +00:00
|
|
|
if (will_be_debugged)
|
|
|
|
{
|
|
|
|
amx->flags |= AMX_FLAG_DEBUG;
|
2005-09-09 03:23:31 +00:00
|
|
|
amx->flags &= (~AMX_FLAG_JITC);
|
|
|
|
amx_SetDebugHook(amx, &Debugger::DebugHook);
|
|
|
|
|
|
|
|
Debugger *pDebugger = new Debugger(amx, pDbg);
|
|
|
|
amx->userdata[UD_DEBUGGER] = pDebugger;
|
2005-07-26 21:31:21 +00:00
|
|
|
} else {
|
2005-07-31 22:16:54 +00:00
|
|
|
#ifdef JIT
|
2005-09-09 03:23:31 +00:00
|
|
|
//set this again because amx_Init() erases it!
|
2005-07-26 21:31:21 +00:00
|
|
|
amx->flags |= AMX_FLAG_JITC;
|
2005-09-09 03:23:31 +00:00
|
|
|
amx->flags &= (~AMX_FLAG_DEBUG);
|
2006-08-17 16:41:41 +00:00
|
|
|
amx->sysreq_d = 0;
|
2005-07-31 22:16:54 +00:00
|
|
|
#endif
|
2005-07-26 21:31:21 +00:00
|
|
|
}
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
#ifdef JIT
|
|
|
|
if (amx->flags & AMX_FLAG_JITC)
|
2004-04-29 17:16:28 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
char *np = new char[amx->code_size];
|
|
|
|
char *rt = new char[amx->reloc_size];
|
|
|
|
|
|
|
|
if (!np || (!rt && amx->reloc_size > 0))
|
2005-07-25 06:03:43 +00:00
|
|
|
{
|
|
|
|
delete[] np;
|
|
|
|
delete[] rt;
|
2005-09-16 23:48:51 +00:00
|
|
|
strcpy(error, "Failed to initialize JIT'd plugin");
|
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
return (amx->error = AMX_ERR_INIT);
|
|
|
|
}
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
if ((err = amx_InitJIT(amx, (void *)rt, (void *)np)) == AMX_ERR_NONE)
|
2005-07-25 06:03:43 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
//amx->base = (unsigned char FAR *)realloc(np, amx->code_size);
|
2013-02-13 07:14:37 +00:00
|
|
|
#if defined(_WIN32)
|
2005-08-21 19:30:27 +00:00
|
|
|
amx->base = (unsigned char *)VirtualAlloc(NULL, amx->code_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
2013-02-13 07:14:37 +00:00
|
|
|
#elif defined(__GNUC__)
|
|
|
|
# if defined(__APPLE__)
|
|
|
|
amx->base = (unsigned char *)valloc(amx->code_size);
|
|
|
|
# else
|
2005-07-25 06:03:43 +00:00
|
|
|
amx->base = (unsigned char *)memalign(sysconf(_SC_PAGESIZE), amx->code_size);
|
2013-02-13 07:14:37 +00:00
|
|
|
# endif
|
2005-07-25 06:03:43 +00:00
|
|
|
mprotect((void *)amx->base, amx->code_size, PROT_READ|PROT_WRITE|PROT_EXEC);
|
2004-10-29 20:35:23 +00:00
|
|
|
#endif
|
2005-09-16 23:48:51 +00:00
|
|
|
if (amx->base)
|
|
|
|
memcpy(amx->base, np, amx->code_size);
|
|
|
|
|
2006-05-07 21:16:00 +00:00
|
|
|
delete [] np;
|
|
|
|
delete [] rt;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
char *prg = (char *)(*program);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2006-05-07 21:16:00 +00:00
|
|
|
delete [] prg;
|
2005-07-25 06:03:43 +00:00
|
|
|
(*program) = amx->base;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
|
|
|
if (*program == 0)
|
|
|
|
{
|
|
|
|
strcpy(error, "Failed to allocate memory");
|
2005-07-25 06:03:43 +00:00
|
|
|
return (amx->error = AMX_ERR_MEMORY);
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
} else {
|
2005-07-25 06:03:43 +00:00
|
|
|
delete[] np;
|
|
|
|
delete[] rt;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
sprintf(error, "Failed to initialize plugin (%d)", err);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
return (amx->error = AMX_ERR_INIT_JIT);
|
2004-04-29 17:16:28 +00:00
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
CScript* aa = new CScript(amx, *program, filename);
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
g_loadedscripts.put(aa);
|
2005-07-31 20:11:58 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
set_amxnatives(amx, error);
|
2005-07-31 20:11:58 +00:00
|
|
|
|
|
|
|
if (g_plugins.m_Finalized)
|
|
|
|
{
|
|
|
|
amx_Register(amx, g_plugins.pNatives, -1);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-31 20:11:58 +00:00
|
|
|
if (CheckModules(amx, error))
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
if (amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE)
|
2005-07-31 20:11:58 +00:00
|
|
|
{
|
|
|
|
sprintf(error, "Plugin uses an unknown function (name \"%s\") - check your modules.ini.", no_function);
|
|
|
|
return (amx->error = AMX_ERR_NOTFOUND);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return (amx->error = AMX_ERR_NOTFOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (amx->error = AMX_ERR_NONE);
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2004-09-12 04:03:54 +00:00
|
|
|
const char *StrCaseStr(const char *as, const char *bs)
|
|
|
|
{
|
|
|
|
static char a[256];
|
|
|
|
static char b[256];
|
|
|
|
unsigned int i = 0;
|
|
|
|
unsigned int len = strlen(as);
|
|
|
|
|
|
|
|
if (len > 254)
|
|
|
|
len = 254;
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2004-09-12 04:03:54 +00:00
|
|
|
{
|
|
|
|
a[i] = tolower(as[i]);
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-09-12 04:03:54 +00:00
|
|
|
a[len] = 0;
|
|
|
|
|
|
|
|
len = strlen(bs);
|
|
|
|
|
|
|
|
if (len > 254)
|
|
|
|
len = 254;
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2004-09-12 04:03:54 +00:00
|
|
|
{
|
|
|
|
b[i] = tolower(bs[i]);
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-09-12 04:03:54 +00:00
|
|
|
b[len] = 0;
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
return strstr(a, b);
|
2004-09-12 04:03:54 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 19:15:58 +00:00
|
|
|
//returns 0 for module not found, 1 for "everything's okay"
|
|
|
|
int CheckModules(AMX *amx, char error[128])
|
2004-09-09 05:16:53 +00:00
|
|
|
{
|
2005-07-15 19:15:58 +00:00
|
|
|
int numLibraries = amx_GetLibraries(amx);
|
2006-05-07 09:56:06 +00:00
|
|
|
char buffer[64];
|
2006-05-10 02:32:34 +00:00
|
|
|
LibType expect;
|
|
|
|
bool found;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-09-11 03:58:38 +00:00
|
|
|
Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2006-05-10 02:32:34 +00:00
|
|
|
/** decode old style plugins */
|
2005-09-16 23:48:51 +00:00
|
|
|
for (int i = 0; i < numLibraries; i++)
|
2004-09-09 05:16:53 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
amx_GetLibrary(amx, i, buffer, sizeof(buffer) - 1);
|
|
|
|
|
|
|
|
if (stricmp(buffer, "float") == 0)
|
2005-07-15 19:15:58 +00:00
|
|
|
continue;
|
2006-05-07 09:56:06 +00:00
|
|
|
|
2006-05-10 02:32:34 +00:00
|
|
|
if (stricmp(buffer, "dbi") == 0)
|
2004-09-09 05:16:53 +00:00
|
|
|
{
|
2006-05-07 09:56:06 +00:00
|
|
|
expect = LibType_Class;
|
2006-05-10 02:32:34 +00:00
|
|
|
} else {
|
|
|
|
expect = LibType_Library;
|
2004-09-09 05:16:53 +00:00
|
|
|
}
|
2006-05-07 09:56:06 +00:00
|
|
|
|
2006-05-10 02:32:34 +00:00
|
|
|
found = FindLibrary(buffer, expect);
|
2006-05-10 12:40:44 +00:00
|
|
|
|
|
|
|
/* for binary compat */
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
CList<CModule, const char *>::iterator a = g_modules.begin();
|
|
|
|
while (a)
|
|
|
|
{
|
|
|
|
CModule &cm = (*a);
|
2006-06-05 08:06:57 +00:00
|
|
|
if (cm.getStatusValue() != MODULE_LOADED)
|
|
|
|
{
|
|
|
|
++a;
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-10 12:40:44 +00:00
|
|
|
if (cm.getInfoNew() &&
|
|
|
|
cm.getInfoNew()->logtag &&
|
|
|
|
!strcasecmp(cm.getInfoNew()->logtag, buffer))
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-15 19:15:58 +00:00
|
|
|
if (!found)
|
2005-09-11 03:58:38 +00:00
|
|
|
{
|
2006-06-07 05:21:03 +00:00
|
|
|
if (expect == LibType_Library)
|
2006-06-05 18:48:01 +00:00
|
|
|
{
|
2006-06-07 19:09:48 +00:00
|
|
|
if (!LoadModule(buffer, PT_ANYTIME, true, true))
|
2006-06-07 05:21:03 +00:00
|
|
|
{
|
|
|
|
if (pHandler->HandleModule(buffer, (expect == LibType_Class)))
|
|
|
|
found = true;
|
|
|
|
} else {
|
2006-06-05 18:48:01 +00:00
|
|
|
found = true;
|
2006-06-07 05:21:03 +00:00
|
|
|
}
|
2006-06-05 18:48:01 +00:00
|
|
|
}
|
2005-09-11 03:58:38 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-09-11 03:58:38 +00:00
|
|
|
if (!found)
|
2005-07-15 19:15:58 +00:00
|
|
|
{
|
2006-05-07 09:56:06 +00:00
|
|
|
const char *type = "Module/Library";
|
|
|
|
if (expect == LibType_Class)
|
|
|
|
type = "Module/Library Class";
|
2006-05-10 02:32:34 +00:00
|
|
|
sprintf(error, "%s \"%s\" required for plugin. Check modules.ini.", type, buffer);
|
2005-07-15 19:15:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-09-09 05:16:53 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 02:32:34 +00:00
|
|
|
/** decode new style plugins */
|
|
|
|
amx_NumTags(amx, &numLibraries);
|
|
|
|
cell notused;
|
|
|
|
LibDecoder dec;
|
|
|
|
LibError err;
|
|
|
|
for (int i=0; i<numLibraries; i++)
|
|
|
|
{
|
|
|
|
amx_GetTag(amx, i, buffer, ¬used);
|
|
|
|
if (buffer[0] != '?')
|
|
|
|
continue;
|
|
|
|
if (DecodeLibCmdString(buffer, &dec))
|
|
|
|
{
|
|
|
|
if (dec.cmd == LibCmd_ReqClass || dec.cmd == LibCmd_ReqLib)
|
|
|
|
{
|
|
|
|
if ( (err=RunLibCommand(&dec)) != LibErr_None )
|
|
|
|
{
|
2006-06-05 19:08:01 +00:00
|
|
|
if (!pHandler->HandleModule(dec.param1, (err == LibErr_NoClass)))
|
2006-05-10 02:32:34 +00:00
|
|
|
{
|
|
|
|
const char *type = "Module/Library";
|
|
|
|
if (err == LibErr_NoClass)
|
|
|
|
type = "Module/Library Class";
|
2006-05-10 03:43:53 +00:00
|
|
|
sprintf(error, "%s \"%s\" required for plugin. Check modules.ini.", type, dec.param1);
|
2006-05-10 02:32:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-15 19:15:58 +00:00
|
|
|
return 1;
|
2004-09-09 05:16:53 +00:00
|
|
|
}
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
int set_amxnatives(AMX* amx, char error[128])
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2006-05-10 11:23:08 +00:00
|
|
|
CModule *cm;
|
2005-09-16 23:48:51 +00:00
|
|
|
for (CList<CModule, const char *>::iterator a = g_modules.begin(); a ; ++a)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2006-05-10 11:23:08 +00:00
|
|
|
cm = &(*a);
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t i=0; i<cm->m_Natives.length(); i++)
|
2006-05-10 11:23:08 +00:00
|
|
|
{
|
|
|
|
amx_Register(amx, cm->m_Natives[i], -1);
|
|
|
|
}
|
2006-09-01 03:29:27 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t i = 0; i < cm->m_NewNatives.length(); i++)
|
2006-09-01 03:29:27 +00:00
|
|
|
{
|
2014-06-05 20:00:47 +00:00
|
|
|
amx_Register(amx, cm->m_NewNatives[i], -1);
|
2006-09-01 03:29:27 +00:00
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
amx_Register(amx, string_Natives, -1);
|
|
|
|
amx_Register(amx, float_Natives, -1);
|
|
|
|
amx_Register(amx, file_Natives, -1);
|
2005-09-11 03:58:38 +00:00
|
|
|
amx_Register(amx, amxmodx_Natives, -1);
|
2004-01-31 20:56:22 +00:00
|
|
|
amx_Register(amx, power_Natives, -1);
|
|
|
|
amx_Register(amx, time_Natives, -1);
|
|
|
|
amx_Register(amx, vault_Natives, -1);
|
2005-07-29 06:33:57 +00:00
|
|
|
amx_Register(amx, g_NewMenuNatives, -1);
|
2005-07-31 20:11:58 +00:00
|
|
|
amx_Register(amx, g_NativeNatives, -1);
|
2005-09-09 23:13:34 +00:00
|
|
|
amx_Register(amx, g_DebugNatives, -1);
|
2006-05-11 08:35:21 +00:00
|
|
|
amx_Register(amx, msg_Natives, -1);
|
2006-06-05 07:48:54 +00:00
|
|
|
amx_Register(amx, vector_Natives, -1);
|
2006-08-20 04:46:34 +00:00
|
|
|
amx_Register(amx, g_SortNatives, -1);
|
2007-04-24 16:38:36 +00:00
|
|
|
amx_Register(amx, g_DataStructNatives, -1);
|
2008-04-14 19:52:11 +00:00
|
|
|
amx_Register(amx, trie_Natives, -1);
|
2014-04-11 20:57:42 +00:00
|
|
|
amx_Register(amx, g_DatapackNatives, -1);
|
2014-07-23 16:51:57 +00:00
|
|
|
amx_Register(amx, g_StackNatives, -1);
|
2014-07-21 19:12:35 +00:00
|
|
|
amx_Register(amx, g_TextParserNatives, -1);
|
2015-01-21 22:58:01 +00:00
|
|
|
amx_Register(amx, g_CvarNatives, -1);
|
2015-06-24 15:45:12 +00:00
|
|
|
amx_Register(amx, g_GameConfigNatives, -1);
|
2014-07-21 19:12:35 +00:00
|
|
|
|
2005-07-31 20:11:58 +00:00
|
|
|
//we're not actually gonna check these here anymore
|
|
|
|
amx->flags |= AMX_FLAG_PRENIT;
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2005-09-09 23:13:34 +00:00
|
|
|
int idx, err;
|
2005-07-31 20:11:58 +00:00
|
|
|
cell retval;
|
2005-10-25 20:38:00 +00:00
|
|
|
|
2006-01-06 04:59:39 +00:00
|
|
|
Debugger *pd;
|
|
|
|
pd = DisableDebugHandler(amx);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
|
|
|
if (amx_FindPublic(amx, "plugin_natives", &idx) == AMX_ERR_NONE)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
if ((err = amx_Exec(amx, &retval, idx)) != AMX_ERR_NONE)
|
2004-09-09 05:16:53 +00:00
|
|
|
{
|
2005-09-09 23:13:34 +00:00
|
|
|
Debugger::GenericMessage(amx, err);
|
2006-11-03 13:27:17 +00:00
|
|
|
AMXXLOG_Log("An error occurred in plugin_natives. This is dangerous!");
|
2004-09-09 05:16:53 +00:00
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2006-01-06 04:59:39 +00:00
|
|
|
EnableDebugHandler(amx, pd);
|
2005-10-25 20:38:00 +00:00
|
|
|
|
2005-07-31 20:11:58 +00:00
|
|
|
amx->flags &= ~(AMX_FLAG_PRENIT);
|
|
|
|
|
|
|
|
return (amx->error = AMX_ERR_NONE);
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int unload_amxscript(AMX* amx, void** program)
|
2006-08-27 04:50:20 +00:00
|
|
|
{
|
2013-02-14 10:00:29 +00:00
|
|
|
#if defined JIT
|
2006-08-27 04:56:27 +00:00
|
|
|
int flags = amx->flags;
|
|
|
|
#endif
|
|
|
|
|
2005-09-09 03:23:31 +00:00
|
|
|
Debugger *pDebugger = (Debugger *)amx->userdata[UD_DEBUGGER];
|
|
|
|
if (pDebugger)
|
|
|
|
delete pDebugger;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-09-09 23:13:34 +00:00
|
|
|
Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];
|
|
|
|
if (pHandler)
|
|
|
|
delete pHandler;
|
2006-02-27 10:10:52 +00:00
|
|
|
|
|
|
|
optimizer_s *opt = (optimizer_s *)amx->usertags[UT_OPTIMIZER];
|
|
|
|
if (opt)
|
|
|
|
delete opt;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
|
|
|
CList<CScript, AMX*>::iterator a = g_loadedscripts.find(amx);
|
|
|
|
|
|
|
|
if (a)
|
|
|
|
a.remove();
|
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
char *prg = (char *)*program;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-08-21 19:30:27 +00:00
|
|
|
if (!prg)
|
|
|
|
return AMX_ERR_NONE;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-08-21 19:30:27 +00:00
|
|
|
#if defined JIT
|
2013-02-13 07:14:37 +00:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
2005-09-16 23:48:51 +00:00
|
|
|
if ((flags & AMX_FLAG_JITC) != AMX_FLAG_JITC)
|
2005-08-21 21:54:14 +00:00
|
|
|
{
|
|
|
|
delete [] prg;
|
|
|
|
} else {
|
2005-08-30 07:15:27 +00:00
|
|
|
#ifdef free
|
|
|
|
#undef free
|
2005-08-21 21:54:14 +00:00
|
|
|
free(prg);
|
2005-09-16 23:48:51 +00:00
|
|
|
#define free(ptr) m_deallocator(__FILE__, __LINE__, __FUNCTION__, m_alloc_free, ptr)
|
2005-08-30 07:15:27 +00:00
|
|
|
#else
|
|
|
|
free(prg);
|
|
|
|
#endif
|
|
|
|
}
|
2005-08-21 19:30:27 +00:00
|
|
|
#elif defined WIN32
|
2005-09-16 23:48:51 +00:00
|
|
|
|
|
|
|
if ((flags & AMX_FLAG_JITC) != AMX_FLAG_JITC)
|
2005-08-21 19:30:27 +00:00
|
|
|
{
|
|
|
|
delete [] prg;
|
2005-09-16 23:48:51 +00:00
|
|
|
}
|
|
|
|
else if (!VirtualFree((LPVOID)prg, 0, MEM_RELEASE))
|
|
|
|
{
|
2005-08-21 19:30:27 +00:00
|
|
|
AMXXLOG_Log("[AMXX] Could not free plugin memory, failure %d.", GetLastError());
|
|
|
|
return AMX_ERR_PARAMS;
|
|
|
|
}
|
|
|
|
#endif //OS support
|
2005-08-15 21:38:03 +00:00
|
|
|
#else
|
2005-08-21 19:30:27 +00:00
|
|
|
//delete normally
|
2005-08-30 07:15:27 +00:00
|
|
|
delete [] prg;
|
2005-08-15 21:38:03 +00:00
|
|
|
#endif
|
2004-04-29 17:16:28 +00:00
|
|
|
*program = 0;
|
|
|
|
return AMX_ERR_NONE;
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
AMX* get_amxscript(int id, void** code, const char** filename)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CScript, AMX*>::iterator a = g_loadedscripts.begin();
|
|
|
|
|
|
|
|
while (a && id--)
|
2004-01-31 20:56:22 +00:00
|
|
|
++a;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
|
|
|
if (a)
|
|
|
|
{
|
2004-01-31 20:56:22 +00:00
|
|
|
*filename = (*a).getName();
|
|
|
|
*code = (*a).getCode();
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
return (*a).getAMX();
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-20 00:00:33 +00:00
|
|
|
const char* GetFileName(AMX *amx)
|
|
|
|
{
|
|
|
|
const char *filename = "";
|
|
|
|
CPluginMngr::CPlugin *pl = g_plugins.findPluginFast(amx);
|
|
|
|
|
|
|
|
if (pl)
|
|
|
|
{
|
|
|
|
filename = pl->getName();
|
|
|
|
} else {
|
|
|
|
CList<CScript,AMX*>::iterator a = g_loadedscripts.find(amx);
|
|
|
|
if (a)
|
|
|
|
filename = (*a).getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
const char* get_amxscriptname(AMX* amx)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CScript, AMX*>::iterator a = g_loadedscripts.find(amx);
|
2004-01-31 20:56:22 +00:00
|
|
|
return a ? (*a).getName() : "";
|
|
|
|
}
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
void get_modname(char* buffer)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
strcpy(buffer, g_mod_name.chars());
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 07:14:37 +00:00
|
|
|
char* build_pathname(const char *fmt, ...)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
|
|
|
static char string[256];
|
|
|
|
int b;
|
2015-10-01 09:06:04 +00:00
|
|
|
int a = b = ke::SafeSprintf(string, 255, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR);
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
va_list argptr;
|
2005-09-16 23:48:51 +00:00
|
|
|
va_start(argptr, fmt);
|
|
|
|
a += vsnprintf (&string[a], 255 - a, fmt, argptr);
|
|
|
|
string[a] = 0;
|
|
|
|
va_end(argptr);
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
char* path = &string[b];
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
while (*path)
|
|
|
|
{
|
2007-05-04 01:11:01 +00:00
|
|
|
if (*path == ALT_SEP_CHAR)
|
|
|
|
{
|
|
|
|
*path = PATH_SEP_CHAR;
|
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
++path;
|
|
|
|
}
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2013-02-13 07:14:37 +00:00
|
|
|
char *build_pathname_r(char *buffer, size_t maxlen, const char *fmt, ...)
|
2005-07-08 05:05:06 +00:00
|
|
|
{
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer, maxlen, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR);
|
2005-07-08 05:05:06 +00:00
|
|
|
|
|
|
|
size_t len = strlen(buffer);
|
|
|
|
char *ptr = buffer + len;
|
|
|
|
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, fmt);
|
|
|
|
vsnprintf (ptr, maxlen-len, fmt, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
while (*ptr)
|
|
|
|
{
|
2007-05-04 01:11:01 +00:00
|
|
|
if (*ptr == ALT_SEP_CHAR)
|
|
|
|
{
|
|
|
|
*ptr = PATH_SEP_CHAR;
|
|
|
|
}
|
2005-07-08 05:05:06 +00:00
|
|
|
++ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:32:29 +00:00
|
|
|
// build pathname based on addons dir
|
2013-02-13 07:14:37 +00:00
|
|
|
char* build_pathname_addons(const char *fmt, ...)
|
2004-03-05 18:32:29 +00:00
|
|
|
{
|
|
|
|
static char string[256];
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-03-05 18:32:29 +00:00
|
|
|
va_list argptr;
|
2005-09-16 23:48:51 +00:00
|
|
|
va_start(argptr, fmt);
|
2004-03-05 18:32:29 +00:00
|
|
|
vsnprintf (string, 255, fmt, argptr);
|
2005-09-16 23:48:51 +00:00
|
|
|
va_end(argptr);
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-03-05 18:32:29 +00:00
|
|
|
char* path = string;
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-03-05 18:32:29 +00:00
|
|
|
while (*path)
|
|
|
|
{
|
2007-05-04 01:11:01 +00:00
|
|
|
if (*path == ALT_SEP_CHAR)
|
|
|
|
{
|
|
|
|
*path = PATH_SEP_CHAR;
|
|
|
|
}
|
2004-03-05 18:32:29 +00:00
|
|
|
++path;
|
|
|
|
}
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2004-03-05 18:32:29 +00:00
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
bool ConvertModuleName(const char *pathString, char *path)
|
2004-09-12 03:48:21 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
char local[PLATFORM_MAX_PATH];
|
2006-05-07 09:56:06 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
strncopy(local, pathString, sizeof(local));
|
|
|
|
char *tmpname = local;
|
2006-05-07 09:56:06 +00:00
|
|
|
char *orig_path = tmpname;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
*path = '\0';
|
2006-05-07 09:56:06 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
size_t len = strlen(local);
|
2006-05-07 09:56:06 +00:00
|
|
|
if (!len)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* run to filename instead of dir */
|
|
|
|
char *ptr = tmpname;
|
|
|
|
ptr = tmpname + len - 1;
|
2007-05-04 01:11:01 +00:00
|
|
|
while (ptr >= tmpname && *ptr != PATH_SEP_CHAR)
|
2006-05-07 09:56:06 +00:00
|
|
|
ptr--;
|
|
|
|
if (ptr >= tmpname)
|
2004-09-12 03:48:21 +00:00
|
|
|
{
|
2006-05-07 09:56:06 +00:00
|
|
|
*ptr++ = '\0';
|
|
|
|
tmpname = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool foundAmxx = false;
|
|
|
|
int iDigit = '3';
|
|
|
|
ptr = tmpname;
|
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
while (*ptr && *ptr != '_')
|
|
|
|
ptr++;
|
|
|
|
if (strncmp(ptr, "_amxx", 5) == 0)
|
2004-09-12 03:48:21 +00:00
|
|
|
{
|
2006-05-07 09:56:06 +00:00
|
|
|
char *p = ptr + 5;
|
2013-02-24 06:45:53 +00:00
|
|
|
if (strncmp(p, ".dll", 4) == 0 || strncmp(p, ".dylib", 6) == 0)
|
2004-09-12 03:48:21 +00:00
|
|
|
{
|
2006-05-07 09:56:06 +00:00
|
|
|
foundAmxx = true;
|
|
|
|
break;
|
|
|
|
} else if (p[0] == '_') {
|
|
|
|
p++;
|
|
|
|
if (strncmp(p, "amd64.so", 8) == 0)
|
|
|
|
{
|
|
|
|
foundAmxx = true;
|
|
|
|
break;
|
|
|
|
} else if (p[0] == 'i') {
|
|
|
|
p++;
|
|
|
|
if (isdigit(p[0]) && p[1] == '8' && p[2] == '6')
|
|
|
|
{
|
|
|
|
iDigit = p[0];
|
|
|
|
foundAmxx = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (p[0] == '\0') {
|
|
|
|
foundAmxx = true;
|
|
|
|
break;
|
2004-09-12 03:48:21 +00:00
|
|
|
}
|
2006-05-07 09:56:06 +00:00
|
|
|
} else {
|
|
|
|
while (*ptr && *ptr == '_')
|
|
|
|
ptr++;
|
2004-09-12 03:48:21 +00:00
|
|
|
}
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2006-05-07 09:56:06 +00:00
|
|
|
if (!foundAmxx)
|
2004-09-12 03:48:21 +00:00
|
|
|
{
|
2006-05-07 17:27:24 +00:00
|
|
|
ptr = tmpname + strlen(tmpname) - 1;
|
2006-05-07 09:56:06 +00:00
|
|
|
while (ptr >= tmpname && *ptr != '.')
|
|
|
|
ptr--;
|
|
|
|
if (ptr > tmpname && *ptr == '.')
|
2004-09-12 03:48:21 +00:00
|
|
|
{
|
2006-05-07 09:56:06 +00:00
|
|
|
*ptr = '\0';
|
2004-09-12 03:48:21 +00:00
|
|
|
}
|
2006-05-07 09:56:06 +00:00
|
|
|
} else {
|
|
|
|
*ptr = '\0';
|
2004-09-12 03:48:21 +00:00
|
|
|
}
|
2006-05-07 09:56:06 +00:00
|
|
|
|
2015-10-01 09:06:04 +00:00
|
|
|
size_t length = ke::SafeSprintf(path, PLATFORM_MAX_PATH, "%s%c%s_amxx", orig_path, PATH_SEP_CHAR, tmpname);
|
2015-07-11 08:37:36 +00:00
|
|
|
|
|
|
|
#if defined PLATFORM_LINUX
|
|
|
|
# if defined AMD64 || PAWN_CELL_SIZE == 64
|
|
|
|
length += strncopy(path + length, "_amd64", PLATFORM_MAX_PATH - length);
|
|
|
|
# else
|
2015-10-01 09:06:04 +00:00
|
|
|
length += ke::SafeSprintf(path + length, PLATFORM_MAX_PATH - length, "_i%c86", iDigit);
|
2015-07-11 08:37:36 +00:00
|
|
|
# endif
|
2006-05-07 09:56:06 +00:00
|
|
|
#endif
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(path + length, PLATFORM_MAX_PATH - length, ".%s", PLATFORM_LIB_EXT);
|
2006-05-07 09:56:06 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-05-11 10:19:09 +00:00
|
|
|
bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool noFileBail)
|
2006-05-07 09:56:06 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
char pathString[PLATFORM_MAX_PATH];
|
|
|
|
char path[PLATFORM_MAX_PATH];
|
2006-05-07 09:56:06 +00:00
|
|
|
|
|
|
|
build_pathname_r(
|
|
|
|
pathString,
|
|
|
|
sizeof(pathString)-1,
|
|
|
|
"%s/%s",
|
|
|
|
get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"),
|
|
|
|
shortname);
|
|
|
|
|
2006-05-07 10:05:04 +00:00
|
|
|
if (simplify)
|
|
|
|
{
|
|
|
|
if (!ConvertModuleName(pathString, path))
|
|
|
|
return false;
|
|
|
|
} else {
|
2015-07-11 08:37:36 +00:00
|
|
|
strncopy(path, pathString, sizeof(path));
|
2006-05-07 10:05:04 +00:00
|
|
|
}
|
2006-05-07 09:56:06 +00:00
|
|
|
|
2006-05-11 10:19:09 +00:00
|
|
|
if (noFileBail)
|
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
FILE *fp = fopen(path, "rb");
|
2006-05-11 10:19:09 +00:00
|
|
|
if (!fp)
|
|
|
|
return false;
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
CList<CModule, const char *>::iterator a = g_modules.find(path);
|
2006-05-07 09:56:06 +00:00
|
|
|
|
|
|
|
if (a)
|
|
|
|
return false;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
CModule* cc = new CModule(path);
|
2006-05-07 09:56:06 +00:00
|
|
|
|
|
|
|
cc->queryModule();
|
|
|
|
|
2006-06-07 05:21:03 +00:00
|
|
|
bool error = true;
|
|
|
|
|
2006-05-07 09:56:06 +00:00
|
|
|
switch (cc->getStatusValue())
|
2004-09-12 07:18:54 +00:00
|
|
|
{
|
2006-05-07 09:56:06 +00:00
|
|
|
case MODULE_BADLOAD:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Module is not a valid library (file \"%s\")", path);
|
2006-05-07 09:56:06 +00:00
|
|
|
break;
|
|
|
|
case MODULE_NOINFO:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Couldn't find info about module (file \"%s\")", path);
|
2006-05-07 09:56:06 +00:00
|
|
|
break;
|
|
|
|
case MODULE_NOQUERY:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Couldn't find \"AMX_Query\" or \"AMXX_Query\" (file \"%s\")", path);
|
2006-05-07 09:56:06 +00:00
|
|
|
break;
|
|
|
|
case MODULE_NOATTACH:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Couldn't find \"%s\" (file \"%s\")", cc->isAmxx() ? "AMXX_Attach" : "AMX_Attach", path);
|
2006-05-07 09:56:06 +00:00
|
|
|
break;
|
|
|
|
case MODULE_OLD:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Module has a different interface version (file \"%s\")", path);
|
2006-05-07 09:56:06 +00:00
|
|
|
break;
|
|
|
|
case MODULE_NEWER:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Module has a newer interface version (file \"%s\"). Please download a new amxmodx.", path);
|
2006-05-07 09:56:06 +00:00
|
|
|
break;
|
|
|
|
case MODULE_INTERROR:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Internal error during module load (file \"%s\")", path);
|
2006-05-07 09:56:06 +00:00
|
|
|
break;
|
|
|
|
case MODULE_NOT64BIT:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Module \"%s\" is not 64 bit compatible.", path);
|
2006-05-07 09:56:06 +00:00
|
|
|
break;
|
2008-04-27 00:07:06 +00:00
|
|
|
case MODULE_BADGAME:
|
2015-07-11 08:37:36 +00:00
|
|
|
report_error(1, "[AMXX] Module \"%s\" cannot load on game \"%s\"", path, g_mod_name.chars());
|
2008-04-27 00:07:06 +00:00
|
|
|
break;
|
2006-06-07 05:21:03 +00:00
|
|
|
default:
|
|
|
|
error = false;
|
|
|
|
break;
|
2006-05-07 09:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_modules.put(cc);
|
|
|
|
|
2006-06-07 05:21:03 +00:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-05-07 09:56:06 +00:00
|
|
|
if (cc->IsMetamod())
|
|
|
|
{
|
|
|
|
char *mmpathname = build_pathname_addons(
|
|
|
|
"%s/%s",
|
|
|
|
get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"),
|
|
|
|
shortname);
|
|
|
|
ConvertModuleName(mmpathname, path);
|
2015-07-11 08:37:36 +00:00
|
|
|
cc->attachMetamod(path, now);
|
2006-05-07 09:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool retVal = cc->attachModule();
|
|
|
|
|
|
|
|
if (cc->isAmxx() && !retVal)
|
|
|
|
{
|
|
|
|
switch (cc->getStatusValue())
|
2004-09-12 07:18:54 +00:00
|
|
|
{
|
2006-05-07 09:56:06 +00:00
|
|
|
case MODULE_FUNCNOTPRESENT:
|
2014-09-20 00:45:44 +00:00
|
|
|
report_error(1, "[AMXX] Module requested a not existing function (file \"%s\")%s%s%s", cc->getFilename(), cc->getMissingFunc() ? " (func \"" : "",
|
2006-05-07 09:56:06 +00:00
|
|
|
cc->getMissingFunc() ? cc->getMissingFunc() : "", cc->getMissingFunc() ? "\")" : "");
|
|
|
|
break;
|
|
|
|
case MODULE_INTERROR:
|
|
|
|
report_error(1, "[AMXX] Internal error during module load (file \"%s\")", cc->getFilename());
|
|
|
|
break;
|
|
|
|
case MODULE_BADLOAD:
|
|
|
|
report_error(1, "[AMXX] Module is not a valid library (file \"%s\")", cc->getFilename());
|
|
|
|
break;
|
2004-09-12 07:18:54 +00:00
|
|
|
}
|
2006-05-07 09:56:06 +00:00
|
|
|
|
|
|
|
return false;
|
2004-09-12 07:18:54 +00:00
|
|
|
}
|
2006-05-07 09:56:06 +00:00
|
|
|
|
|
|
|
return true;
|
2004-09-12 03:48:21 +00:00
|
|
|
}
|
|
|
|
|
2005-07-22 19:32:16 +00:00
|
|
|
int loadModules(const char* filename, PLUG_LOADTIME now)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
FILE *fp = fopen(build_pathname("%s", filename), "rt");
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
if (!fp)
|
2004-04-29 17:16:28 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
AMXXLOG_Log("[AMXX] Modules list not found (file \"%s\")", filename);
|
2004-04-29 17:16:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
char line[256];
|
2006-05-07 10:05:04 +00:00
|
|
|
char moduleName[256];
|
|
|
|
char buffer[255];
|
2004-04-29 17:16:28 +00:00
|
|
|
int loaded = 0;
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-09-12 03:48:21 +00:00
|
|
|
while (!feof(fp))
|
2004-04-29 17:16:28 +00:00
|
|
|
{
|
2006-06-06 07:00:27 +00:00
|
|
|
buffer[0] = '\0';
|
2006-05-07 10:05:04 +00:00
|
|
|
fgets(buffer, sizeof(buffer)-1, fp);
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
UTIL_TrimLeft(buffer);
|
|
|
|
UTIL_TrimRight(buffer);
|
|
|
|
|
|
|
|
if (!buffer[0] || buffer[0] == ';' || buffer[0] == '\n')
|
2004-09-12 03:48:21 +00:00
|
|
|
continue;
|
2006-05-07 10:05:04 +00:00
|
|
|
|
|
|
|
bool simplify = true;
|
2015-07-11 08:37:36 +00:00
|
|
|
|
2006-05-07 10:05:04 +00:00
|
|
|
if (buffer[0] == '>')
|
|
|
|
{
|
|
|
|
simplify = false;
|
2015-07-11 08:37:36 +00:00
|
|
|
strncopy(line, &buffer[1], sizeof(line));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strncopy(line, buffer, sizeof(line));
|
2006-05-07 10:05:04 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
*moduleName = '\0';
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
if (sscanf(line, "%s", moduleName) == EOF)
|
2004-09-12 03:48:21 +00:00
|
|
|
continue;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2006-05-07 10:05:04 +00:00
|
|
|
if (LoadModule(moduleName, now, simplify))
|
2006-05-07 09:56:06 +00:00
|
|
|
loaded++;
|
2004-04-29 17:16:28 +00:00
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-09-12 03:48:21 +00:00
|
|
|
fclose(fp);
|
|
|
|
|
2004-04-29 17:16:28 +00:00
|
|
|
return loaded;
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2004-06-30 04:27:55 +00:00
|
|
|
void detachModules()
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CModule, const char *>::iterator a = g_modules.begin();
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
while (a)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
|
|
|
(*a).detachModule();
|
|
|
|
a.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-30 04:27:55 +00:00
|
|
|
void detachReloadModules()
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CModule, const char *>::iterator a = g_modules.begin();
|
2004-04-29 17:16:28 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
while (a)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
if ((*a).isReloadable() && !(*a).IsMetamod())
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
|
|
|
(*a).detachModule();
|
|
|
|
a.remove();
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
const char* strip_name(const char* a)
|
2004-01-31 20:56:22 +00:00
|
|
|
{
|
2004-04-29 17:16:28 +00:00
|
|
|
const char* ret = a;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
|
|
|
while (*a)
|
|
|
|
{
|
|
|
|
if (*a == '/' || *a == '\\')
|
|
|
|
{
|
2004-04-29 17:16:28 +00:00
|
|
|
ret = ++a;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++a;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-29 17:16:28 +00:00
|
|
|
return ret;
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2004-03-27 17:01:18 +00:00
|
|
|
// Get the number of running modules
|
|
|
|
int countModules(CountModulesMode mode)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CModule, const char *>::iterator iter;
|
2004-03-27 17:01:18 +00:00
|
|
|
int num;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-03-27 17:01:18 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
case CountModules_All:
|
|
|
|
return g_modules.size();
|
|
|
|
case CountModules_Running:
|
|
|
|
iter = g_modules.begin();
|
|
|
|
num = 0;
|
|
|
|
|
|
|
|
while (iter)
|
|
|
|
{
|
|
|
|
if ((*iter).getStatusValue() == MODULE_LOADED)
|
|
|
|
++num;
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
case CountModules_Stopped:
|
|
|
|
iter = g_modules.begin();
|
|
|
|
num = 0;
|
|
|
|
|
|
|
|
while (iter)
|
|
|
|
{
|
|
|
|
if ((*iter).getStatusValue() != MODULE_LOADED)
|
|
|
|
++num;
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
2004-03-27 17:01:18 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-03-27 17:01:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-03-31 18:02:37 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
// Call all modules' AMXX_PluginsLoaded functions
|
|
|
|
void modules_callPluginsLoaded()
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CModule, const char *>::iterator iter = g_modules.begin();
|
|
|
|
|
2004-05-03 19:46:49 +00:00
|
|
|
while (iter)
|
2004-04-03 19:15:06 +00:00
|
|
|
{
|
|
|
|
(*iter).CallPluginsLoaded();
|
2004-05-03 19:46:49 +00:00
|
|
|
++iter;
|
2004-04-03 19:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-07 09:56:06 +00:00
|
|
|
//same for unloaded
|
|
|
|
void modules_callPluginsUnloaded()
|
|
|
|
{
|
|
|
|
CList<CModule, const char *>::iterator iter = g_modules.begin();
|
|
|
|
|
|
|
|
while (iter)
|
|
|
|
{
|
|
|
|
(*iter).CallPluginsUnloaded();
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void modules_callPluginsUnloading()
|
|
|
|
{
|
|
|
|
CList<CModule, const char *>::iterator iter = g_modules.begin();
|
|
|
|
|
|
|
|
while (iter)
|
|
|
|
{
|
|
|
|
(*iter).CallPluginsUnloading();
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-31 18:02:37 +00:00
|
|
|
// new functions
|
|
|
|
int MNF_AddNatives(AMX_NATIVE_INFO* natives)
|
|
|
|
{
|
2004-04-03 19:15:06 +00:00
|
|
|
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
|
|
|
|
return FALSE; // may only be called from attach
|
2004-03-31 18:02:37 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
g_CurrentlyCalledModule->m_Natives.append(natives);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-09-01 03:29:27 +00:00
|
|
|
int MNF_AddNewNatives(AMX_NATIVE_INFO *natives)
|
|
|
|
{
|
|
|
|
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
|
|
|
|
return FALSE; // may only be called from attach
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
g_CurrentlyCalledModule->m_NewNatives.append(natives);
|
2006-09-01 03:29:27 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
const char *MNF_GetModname(void)
|
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
return g_mod_name.chars();
|
2004-04-03 19:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AMX *MNF_GetAmxScript(int id)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CScript, AMX*>::iterator iter = g_loadedscripts.begin();
|
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
while (iter && id--)
|
|
|
|
++iter;
|
|
|
|
|
2006-08-27 02:17:18 +00:00
|
|
|
if (iter == 0)
|
2004-08-13 11:05:38 +00:00
|
|
|
return NULL;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
return (*iter).getAMX();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MNF_GetAmxScriptName(int id)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CScript, AMX*>::iterator iter = g_loadedscripts.begin();
|
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
while (iter && id--)
|
|
|
|
++iter;
|
|
|
|
|
2006-08-27 02:17:18 +00:00
|
|
|
if (iter == 0)
|
2004-08-13 10:46:13 +00:00
|
|
|
return NULL;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
return (*iter).getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MNF_FindAmxScriptByName(const char *name)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CScript, AMX*>::iterator iter = g_loadedscripts.begin();
|
2004-04-03 19:15:06 +00:00
|
|
|
bool found = false;
|
|
|
|
int i = 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
while (iter)
|
|
|
|
{
|
|
|
|
if (stricmp((*iter).getName(), name) == 0)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
++i;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
if (!found)
|
|
|
|
return -1;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MNF_FindAmxScriptByAmx(const AMX *amx)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
CList<CScript, AMX*>::iterator iter = g_loadedscripts.begin();
|
2004-04-03 19:15:06 +00:00
|
|
|
bool found = false;
|
|
|
|
int i = 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
while (iter)
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
{
|
|
|
|
if (amx == (*iter).getAMX())
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
++i;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
if (!found)
|
|
|
|
return -1;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2006-02-14 12:01:22 +00:00
|
|
|
extern "C" char *MNF_GetAmxString(AMX *amx, cell amx_addr, int bufferId, int *pLen)
|
2004-04-03 19:15:06 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *retVal = get_amxstring(amx, amx_addr, bufferId, len);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
if (pLen)
|
|
|
|
*pLen = len;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
return retVal;
|
2004-03-31 18:02:37 +00:00
|
|
|
}
|
2004-04-03 19:15:06 +00:00
|
|
|
|
2015-05-06 09:57:31 +00:00
|
|
|
extern "C" char *MNF_GetAmxStringNull(AMX *amx, cell amx_addr, int bufferId, int *pLen)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *retVal = get_amxstring_null(amx, amx_addr, bufferId, len);
|
|
|
|
|
|
|
|
if (pLen && retVal)
|
|
|
|
*pLen = len;
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
int MNF_GetAmxStringLen(const cell *ptr)
|
|
|
|
{
|
|
|
|
register int c = 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
|
|
|
while (ptr[c])
|
2004-04-03 19:15:06 +00:00
|
|
|
++c;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2006-02-28 09:59:03 +00:00
|
|
|
List<AUTHORIZEFUNC> g_auth_funcs;
|
|
|
|
void MNF_RegAuthorizeFunc(AUTHORIZEFUNC fn)
|
|
|
|
{
|
|
|
|
g_auth_funcs.push_back(fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MNF_UnregAuthorizeFunc(AUTHORIZEFUNC fn)
|
|
|
|
{
|
|
|
|
g_auth_funcs.remove(fn);
|
|
|
|
}
|
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
char *MNF_FormatAmxString(AMX *amx, cell *params, int startParam, int *pLen)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *retVal = format_amxstring(amx, params, startParam, len);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
if (pLen)
|
|
|
|
*pLen = len;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2004-09-01 21:13:30 +00:00
|
|
|
int MNF_GetPlayerFlags(int id)
|
|
|
|
{
|
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-09-01 21:13:30 +00:00
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER_I(id);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-09-01 21:13:30 +00:00
|
|
|
return (pPlayer->flags[0]);
|
|
|
|
}
|
|
|
|
|
2004-04-03 19:15:06 +00:00
|
|
|
void MNF_CopyAmxMemory(cell * dest, const cell * src, int len)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
memcpy((void*)dest, (const void *)src, (size_t)len * sizeof(cell));
|
2004-04-03 19:15:06 +00:00
|
|
|
}
|
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_IsPlayerValid(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
2004-04-21 19:11:20 +00:00
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER_I(id);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return (pPlayer->initialized) ? 1 : 0;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
const char * MNF_GetPlayerName(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return NULL;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->name.chars();
|
2004-04-21 19:11:20 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2006-06-03 21:34:43 +00:00
|
|
|
void MNF_OverrideNatives(AMX_NATIVE_INFO *natives, const char *name)
|
2006-05-10 11:23:08 +00:00
|
|
|
{
|
|
|
|
//HACKHACK - we should never have had to do this
|
|
|
|
//find a better solution for SourceMod!!!
|
|
|
|
for (CList<CModule, const char *>::iterator a = g_modules.begin(); a ; ++a)
|
|
|
|
{
|
|
|
|
CModule &cm = (*a);
|
2006-06-03 21:34:43 +00:00
|
|
|
if (cm.getStatusValue() != MODULE_LOADED)
|
|
|
|
continue;
|
|
|
|
const amxx_module_info_s *p = cm.getInfoNew();
|
|
|
|
if (!p || !p->name)
|
|
|
|
continue;
|
|
|
|
if (strcmp(p->name, name)==0)
|
|
|
|
continue;
|
2006-05-10 11:23:08 +00:00
|
|
|
cm.rewriteNativeLists(natives);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
const char * MNF_GetPlayerIP(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return NULL;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->ip.chars();
|
2004-04-21 19:11:20 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_IsPlayerInGame(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->ingame ? 1 : 0;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_IsPlayerBot(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->IsBot() ? 1 : 0;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_IsPlayerAuthorized(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->authorized ? 1 : 0;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
float MNF_GetPlayerTime(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0.0f;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->time;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
float MNF_GetPlayerPlayTime(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0.0f;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->playtime;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_GetPlayerCurweapon(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->current;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_GetPlayerTeamID(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->teamId;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_GetPlayerDeaths(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->deaths;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_GetPlayerMenu(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->menu;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_GetPlayerKeys(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->keys;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_IsPlayerAlive(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->IsAlive() ? 1 : 0;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
float MNF_GetPlayerFrags(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0.0f;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return GET_PLAYER_POINTER_I(id)->pEdict->v.frags;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_IsPlayerConnecting(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
CPlayer * pPlayer = GET_PLAYER_POINTER_I(id);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return (!pPlayer->ingame && pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0)) ? 1 : 0;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
int MNF_IsPlayerHLTV(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return (GET_PLAYER_POINTER_I(id)->pEdict->v.flags & FL_PROXY) ? 1 : 0;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
float MNF_GetPlayerArmor(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0.0f;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return (GET_PLAYER_POINTER_I(id)->pEdict->v.armorvalue);
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
float MNF_GetPlayerHealth(int id)
|
|
|
|
{
|
2004-05-28 11:27:50 +00:00
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
return (GET_PLAYER_POINTER_I(id)->pEdict->v.health);
|
|
|
|
}
|
|
|
|
|
2004-04-29 17:16:28 +00:00
|
|
|
cell MNF_RealToCell(REAL x)
|
|
|
|
{
|
|
|
|
return *(cell*)&x;
|
|
|
|
}
|
|
|
|
|
|
|
|
REAL MNF_CellToReal(cell x)
|
|
|
|
{
|
|
|
|
return *(REAL*)&x;
|
|
|
|
}
|
|
|
|
|
2004-07-08 16:02:01 +00:00
|
|
|
void MNF_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char msg[3072];
|
|
|
|
va_list arglst;
|
|
|
|
va_start(arglst, fmt);
|
2005-09-16 23:48:51 +00:00
|
|
|
_vsnprintf(msg, sizeof(msg) - 1, fmt, arglst);
|
2005-07-25 06:03:43 +00:00
|
|
|
//vsprintf(msg, fmt, arglst);
|
2004-07-08 16:02:01 +00:00
|
|
|
va_end(arglst);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-07-08 16:02:01 +00:00
|
|
|
AMXXLOG_Log("%s", msg);
|
|
|
|
}
|
2004-07-28 19:28:36 +00:00
|
|
|
|
2004-09-15 21:21:46 +00:00
|
|
|
//by BAILOPAN
|
|
|
|
// debugger engine front end
|
2006-02-14 12:01:22 +00:00
|
|
|
extern "C" void LogError(AMX *amx, int err, const char *fmt, ...)
|
2004-09-15 21:21:46 +00:00
|
|
|
{
|
2005-09-09 03:23:31 +00:00
|
|
|
Debugger *pDebugger = (Debugger *)amx->userdata[UD_DEBUGGER];
|
|
|
|
|
|
|
|
amx->error = err;
|
|
|
|
|
2005-09-09 16:04:44 +00:00
|
|
|
char msg_buffer[2048];
|
2005-07-26 21:31:21 +00:00
|
|
|
|
2005-09-09 16:04:44 +00:00
|
|
|
msg_buffer[0] = '\0';
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-09-09 03:23:31 +00:00
|
|
|
if (fmt != NULL)
|
2005-07-26 21:31:21 +00:00
|
|
|
{
|
2005-09-09 03:23:31 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2005-09-16 23:48:51 +00:00
|
|
|
_vsnprintf(msg_buffer, sizeof(msg_buffer) - 1, fmt, ap);
|
2005-09-09 03:23:31 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2005-07-26 21:31:21 +00:00
|
|
|
|
2006-03-16 06:36:01 +00:00
|
|
|
#if defined BINLOG_ENABLED
|
|
|
|
CPluginMngr::CPlugin *pl = g_plugins.findPluginFast(amx);
|
|
|
|
if (pl)
|
2006-08-18 19:02:37 +00:00
|
|
|
{
|
2006-03-16 06:36:01 +00:00
|
|
|
g_BinLog.WriteOp(BinLog_NativeError, pl->getId(), err, msg_buffer);
|
2006-08-18 19:02:37 +00:00
|
|
|
}
|
2006-03-16 06:36:01 +00:00
|
|
|
#endif
|
|
|
|
|
2005-09-09 16:04:44 +00:00
|
|
|
//give the plugin first chance to handle any sort of error
|
|
|
|
Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];
|
2005-09-11 03:58:38 +00:00
|
|
|
|
|
|
|
if (pHandler->InNativeFilter())
|
2005-09-09 16:04:44 +00:00
|
|
|
{
|
2005-09-11 03:58:38 +00:00
|
|
|
if (pDebugger)
|
2006-08-18 19:02:37 +00:00
|
|
|
{
|
2005-09-11 03:58:38 +00:00
|
|
|
pDebugger->EndExec();
|
2006-08-18 19:02:37 +00:00
|
|
|
}
|
2005-09-11 03:58:38 +00:00
|
|
|
} else {
|
|
|
|
if (pHandler)
|
2005-09-09 23:13:34 +00:00
|
|
|
{
|
2005-09-11 03:58:38 +00:00
|
|
|
if (pHandler->IsHandling())
|
|
|
|
{
|
|
|
|
if (fmt != NULL)
|
2006-08-18 19:02:37 +00:00
|
|
|
{
|
2005-09-11 03:58:38 +00:00
|
|
|
pHandler->SetErrorMsg(msg_buffer);
|
2006-08-18 19:02:37 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 03:58:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-09-11 03:58:38 +00:00
|
|
|
//give the user a first-chance at blocking the error from displaying
|
|
|
|
if (pHandler->HandleError(fmt ? msg_buffer : NULL) != 0)
|
|
|
|
{
|
|
|
|
amx->error = -1;
|
|
|
|
return;
|
|
|
|
}
|
2005-09-09 23:13:34 +00:00
|
|
|
}
|
2005-09-09 16:04:44 +00:00
|
|
|
}
|
2005-07-26 21:31:21 +00:00
|
|
|
|
2005-09-09 03:23:31 +00:00
|
|
|
if (!pDebugger)
|
|
|
|
{
|
2005-09-09 23:13:34 +00:00
|
|
|
if (fmt)
|
2006-08-18 19:02:37 +00:00
|
|
|
{
|
2006-04-13 16:29:01 +00:00
|
|
|
AMXXLOG_Error("%s", msg_buffer);
|
2006-08-18 19:02:37 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-09-09 23:13:34 +00:00
|
|
|
Debugger::GenericMessage(amx, err);
|
2006-08-18 19:02:37 +00:00
|
|
|
if (err != AMX_ERR_EXIT)
|
|
|
|
{
|
|
|
|
AMXXLOG_Error("[AMXX] To enable debug mode, add \"debug\" after the plugin name in plugins.ini (without quotes).");
|
|
|
|
}
|
2005-09-09 03:23:31 +00:00
|
|
|
//destroy original error code so the original is not displayed again
|
2005-09-09 16:04:44 +00:00
|
|
|
} else {
|
|
|
|
pDebugger->SetTracedError(err);
|
|
|
|
//we can display error now
|
|
|
|
pDebugger->DisplayTrace(fmt ? msg_buffer : NULL);
|
2005-09-09 03:23:31 +00:00
|
|
|
}
|
2005-09-09 23:13:34 +00:00
|
|
|
|
|
|
|
amx->error = -1;
|
2004-09-15 21:21:46 +00:00
|
|
|
}
|
|
|
|
|
2004-07-28 19:28:36 +00:00
|
|
|
void MNF_MergeDefinitionFile(const char *file)
|
|
|
|
{
|
|
|
|
g_langMngr.MergeDefinitionFile(file);
|
|
|
|
}
|
|
|
|
|
2006-05-07 09:56:06 +00:00
|
|
|
int MNF_FindLibrary(const char *name, LibType type)
|
|
|
|
{
|
|
|
|
return FindLibrary(name, type) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MFN_AddLibraries(const char *name, LibType type, void *parent)
|
|
|
|
{
|
|
|
|
return AddLibrariesFromString(name, type, LibSource_Module, parent) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MNF_RemoveLibraries(void *parent)
|
|
|
|
{
|
|
|
|
return RemoveLibraries(parent);
|
|
|
|
}
|
|
|
|
|
2004-09-05 22:09:45 +00:00
|
|
|
edict_t* MNF_GetPlayerEdict(int id)
|
|
|
|
{
|
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return NULL;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-09-05 22:09:45 +00:00
|
|
|
return (GET_PLAYER_POINTER_I(id)->pEdict);
|
|
|
|
}
|
|
|
|
|
2004-09-10 20:58:55 +00:00
|
|
|
const char *MNF_Format(const char *fmt, ...)
|
|
|
|
{
|
2006-03-19 19:26:29 +00:00
|
|
|
return "";
|
2004-09-10 20:58:55 +00:00
|
|
|
}
|
|
|
|
|
2004-09-14 16:18:52 +00:00
|
|
|
const char *MNF_GetPlayerTeam(int id)
|
|
|
|
{
|
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return NULL;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
return (GET_PLAYER_POINTER_I(id)->team.chars());
|
2004-09-14 16:18:52 +00:00
|
|
|
}
|
|
|
|
|
2004-09-11 21:52:18 +00:00
|
|
|
#ifndef MEMORY_TEST
|
|
|
|
void *MNF_Allocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, const unsigned int allocationType, const size_t reportedSize)
|
|
|
|
{
|
|
|
|
return malloc(reportedSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *MNF_Reallocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, const unsigned int reallocationType, const size_t reportedSize, void *reportedAddress)
|
|
|
|
{
|
|
|
|
return realloc(reportedAddress, reportedSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MNF_Deallocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, const unsigned int deallocationType, void *reportedAddress)
|
|
|
|
{
|
|
|
|
free(reportedAddress);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-18 13:37:46 +00:00
|
|
|
// 09/18/2004 : added these two funcs that default to copyBack=false so we don't break all modules
|
|
|
|
cell MNF_PrepareCellArray(cell *ptr, unsigned int size)
|
|
|
|
{
|
|
|
|
return prepareCellArray(ptr, size, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
cell MNF_PrepareCharArray(char *ptr, unsigned int size)
|
|
|
|
{
|
|
|
|
return prepareCharArray(ptr, size, false);
|
|
|
|
}
|
|
|
|
|
2005-07-05 22:01:29 +00:00
|
|
|
inline bool operator ==(func_s &arg1, const char *desc)
|
|
|
|
{
|
|
|
|
if (strcmp(arg1.desc, desc) == 0)
|
|
|
|
return true;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-05 22:01:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CList<func_s, const char *> g_functions;
|
2004-09-18 13:37:46 +00:00
|
|
|
|
2004-03-31 18:02:37 +00:00
|
|
|
// Fnptr Request function for the new interface
|
|
|
|
const char *g_LastRequestedFunc = NULL;
|
2005-07-05 22:01:29 +00:00
|
|
|
#define REGISTER_FUNC(name, func) \
|
|
|
|
{ \
|
|
|
|
pFunc = new func_s; \
|
2005-07-25 06:03:43 +00:00
|
|
|
pFunc->pfn = (void *)func; \
|
2005-07-05 22:01:29 +00:00
|
|
|
pFunc->desc = name; \
|
|
|
|
g_functions.put(pFunc); \
|
|
|
|
}
|
|
|
|
|
|
|
|
void MNF_RegisterFunction(void *pfn, const char *description)
|
|
|
|
{
|
|
|
|
func_s *pFunc;
|
|
|
|
|
|
|
|
REGISTER_FUNC(description, pfn);
|
|
|
|
}
|
|
|
|
|
2006-05-19 01:54:51 +00:00
|
|
|
void *MNF_RegisterFunctionEx(void *pfn, const char *description)
|
|
|
|
{
|
|
|
|
func_s *pFunc;
|
|
|
|
CList<func_s, const char *>::iterator iter;
|
|
|
|
|
|
|
|
for (iter = g_functions.begin(); iter; ++iter)
|
|
|
|
{
|
|
|
|
pFunc = &(*iter);
|
|
|
|
if (strcmp(description, pFunc->desc) == 0)
|
|
|
|
{
|
|
|
|
void *pOld = pFunc->pfn;
|
|
|
|
pFunc->pfn = pfn;
|
|
|
|
return pOld;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-03 23:14:09 +00:00
|
|
|
MNF_RegisterFunction(pfn, description);
|
|
|
|
|
2006-05-19 01:54:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
void Module_UncacheFunctions()
|
|
|
|
{
|
|
|
|
g_functions.clear();
|
|
|
|
}
|
|
|
|
|
2005-10-30 14:17:32 +00:00
|
|
|
int MNF_SetPlayerTeamInfo(int player, int teamid, const char *teamname)
|
|
|
|
{
|
|
|
|
if (player < 1 || player > gpGlobals->maxClients)
|
|
|
|
return 0;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER_I(player);
|
2005-10-30 14:17:32 +00:00
|
|
|
|
|
|
|
if (!pPlayer->ingame)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pPlayer->teamId = teamid;
|
|
|
|
if (teamname != NULL)
|
2014-05-14 22:01:28 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
pPlayer->team = teamname;
|
2005-10-30 14:17:32 +00:00
|
|
|
|
2014-05-14 22:01:28 +00:00
|
|
|
// Make sure team is registered, otherwise
|
|
|
|
// natives relying on team id will return wrong result.
|
|
|
|
g_teamsIds.registerTeam(teamname, teamid);
|
|
|
|
}
|
|
|
|
|
2005-10-30 14:17:32 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-05-10 12:40:44 +00:00
|
|
|
const char *MNF_GetLocalInfo(char *name, const char *def)
|
|
|
|
{
|
|
|
|
return get_localinfo(name, def);
|
|
|
|
}
|
|
|
|
|
2006-08-28 11:08:18 +00:00
|
|
|
void MNF_MessageBlock(int mode, int msg, int *opt)
|
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case MSGBLOCK_SET:
|
|
|
|
{
|
|
|
|
if (msg < 0 || msg > MAX_MESSAGES || opt == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int _opt = msgBlocks[msg];
|
|
|
|
msgBlocks[msg] = *opt;
|
|
|
|
*opt = _opt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MSGBLOCK_GET:
|
|
|
|
{
|
|
|
|
if (msg < 0 || msg > MAX_MESSAGES || opt == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*opt = msgBlocks[msg];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-28 09:59:03 +00:00
|
|
|
void *MNF_PlayerPropAddr(int id, int prop)
|
2005-11-19 00:33:51 +00:00
|
|
|
{
|
|
|
|
if (id < 1 || id > gpGlobals->maxClients)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER_I(id);
|
|
|
|
|
|
|
|
switch (prop)
|
|
|
|
{
|
|
|
|
case Player_Name:
|
|
|
|
return &pPlayer->name;
|
|
|
|
case Player_Ip:
|
|
|
|
return &pPlayer->ip;
|
|
|
|
case Player_Team:
|
|
|
|
return &pPlayer->team;
|
|
|
|
case Player_Ingame:
|
|
|
|
return &pPlayer->ingame;
|
|
|
|
case Player_Authorized:
|
|
|
|
return &pPlayer->authorized;
|
|
|
|
case Player_Vgui:
|
|
|
|
return &pPlayer->vgui;
|
|
|
|
case Player_Time:
|
|
|
|
return &pPlayer->time;
|
|
|
|
case Player_Playtime:
|
|
|
|
return &pPlayer->playtime;
|
|
|
|
case Player_MenuExpire:
|
|
|
|
return &pPlayer->menuexpire;
|
|
|
|
case Player_Weapons:
|
|
|
|
return &pPlayer->weapons[0];
|
|
|
|
case Player_CurrentWeapon:
|
|
|
|
return &pPlayer->current;
|
|
|
|
case Player_TeamID:
|
|
|
|
return &pPlayer->teamId;
|
|
|
|
case Player_Deaths:
|
|
|
|
return &pPlayer->deaths;
|
|
|
|
case Player_Aiming:
|
|
|
|
return &pPlayer->aiming;
|
|
|
|
case Player_Menu:
|
|
|
|
return &pPlayer->menu;
|
|
|
|
case Player_Keys:
|
|
|
|
return &pPlayer->keys;
|
|
|
|
case Player_Flags:
|
|
|
|
return &pPlayer->flags[0];
|
|
|
|
case Player_Newmenu:
|
|
|
|
return &pPlayer->newmenu;
|
|
|
|
case Player_NewmenuPage:
|
|
|
|
return &pPlayer->page;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-25 06:03:43 +00:00
|
|
|
int amx_Execv()
|
|
|
|
{
|
|
|
|
return AMX_ERR_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
2015-06-23 18:04:17 +00:00
|
|
|
IGameConfigManager *MNF_GetConfigManager()
|
|
|
|
{
|
|
|
|
return &ConfigManager;
|
|
|
|
}
|
|
|
|
|
2005-07-05 22:01:29 +00:00
|
|
|
void Module_CacheFunctions()
|
|
|
|
{
|
|
|
|
func_s *pFunc;
|
|
|
|
|
|
|
|
REGISTER_FUNC("BuildPathname", build_pathname)
|
2005-07-08 05:05:06 +00:00
|
|
|
REGISTER_FUNC("BuildPathnameR", build_pathname_r)
|
2005-07-05 22:01:29 +00:00
|
|
|
REGISTER_FUNC("PrintSrvConsole", print_srvconsole)
|
|
|
|
REGISTER_FUNC("GetModname", MNF_GetModname)
|
|
|
|
REGISTER_FUNC("Log", MNF_Log)
|
|
|
|
REGISTER_FUNC("LogError", LogError)
|
|
|
|
REGISTER_FUNC("MergeDefinitionFile", MNF_MergeDefinitionFile)
|
|
|
|
REGISTER_FUNC("Format", MNF_Format)
|
|
|
|
REGISTER_FUNC("RegisterFunction", MNF_RegisterFunction);
|
2006-05-19 01:54:51 +00:00
|
|
|
REGISTER_FUNC("RegisterFunctionEx", MNF_RegisterFunctionEx);
|
2015-06-23 18:04:17 +00:00
|
|
|
REGISTER_FUNC("GetConfigManager", MNF_GetConfigManager);
|
2005-07-05 22:01:29 +00:00
|
|
|
|
|
|
|
// Amx scripts loading / unloading / managing
|
|
|
|
REGISTER_FUNC("GetAmxScript", MNF_GetAmxScript)
|
|
|
|
REGISTER_FUNC("GetAmxScriptName", MNF_GetAmxScriptName)
|
|
|
|
REGISTER_FUNC("FindAmxScriptByName", MNF_FindAmxScriptByName)
|
|
|
|
REGISTER_FUNC("FindAmxScriptByAmx", MNF_FindAmxScriptByAmx)
|
|
|
|
REGISTER_FUNC("LoadAmxScript", load_amxscript)
|
|
|
|
REGISTER_FUNC("UnloadAmxScript", unload_amxscript)
|
|
|
|
|
|
|
|
// String / mem in amx scripts support
|
|
|
|
REGISTER_FUNC("SetAmxString", set_amxstring)
|
2014-08-02 11:42:14 +00:00
|
|
|
REGISTER_FUNC("SetAmxStringUTF8Char", set_amxstring_utf8_char)
|
|
|
|
REGISTER_FUNC("SetAmxStringUTF8Cell", set_amxstring_utf8_cell)
|
2005-07-05 22:01:29 +00:00
|
|
|
REGISTER_FUNC("GetAmxString", MNF_GetAmxString)
|
2015-05-06 09:57:31 +00:00
|
|
|
REGISTER_FUNC("GetAmxStringNull", MNF_GetAmxStringNull)
|
2005-07-05 22:01:29 +00:00
|
|
|
REGISTER_FUNC("GetAmxStringLen", MNF_GetAmxStringLen)
|
|
|
|
REGISTER_FUNC("FormatAmxString", MNF_FormatAmxString)
|
|
|
|
REGISTER_FUNC("CopyAmxMemory", MNF_CopyAmxMemory)
|
|
|
|
REGISTER_FUNC("GetAmxAddr", get_amxaddr)
|
2015-05-06 09:57:31 +00:00
|
|
|
REGISTER_FUNC("GetAmxVectorNull", get_amxvector_null)
|
2006-05-19 01:54:51 +00:00
|
|
|
REGISTER_FUNC("AmxReregister", amx_Reregister);
|
2005-07-05 22:01:29 +00:00
|
|
|
|
|
|
|
// other amx stuff
|
|
|
|
REGISTER_FUNC("amx_Exec", amx_Exec)
|
2005-08-02 07:01:25 +00:00
|
|
|
REGISTER_FUNC("amx_Push", amx_Push)
|
2005-07-25 06:03:43 +00:00
|
|
|
REGISTER_FUNC("amx_Execv", amx_Execv) //I HOPE NO ONE USES THIS!!!!
|
2005-07-05 22:01:29 +00:00
|
|
|
REGISTER_FUNC("amx_Allot", amx_Allot)
|
|
|
|
REGISTER_FUNC("amx_FindPublic", amx_FindPublic)
|
|
|
|
REGISTER_FUNC("amx_FindNative", amx_FindNative)
|
|
|
|
|
|
|
|
// Natives / Forwards
|
|
|
|
REGISTER_FUNC("AddNatives", MNF_AddNatives)
|
2006-09-01 03:29:27 +00:00
|
|
|
REGISTER_FUNC("AddNewNatives", MNF_AddNewNatives)
|
2005-07-05 22:01:29 +00:00
|
|
|
REGISTER_FUNC("RaiseAmxError", amx_RaiseError)
|
|
|
|
REGISTER_FUNC("RegisterForward", registerForward)
|
|
|
|
REGISTER_FUNC("RegisterSPForward", registerSPForward)
|
|
|
|
REGISTER_FUNC("RegisterSPForwardByName", registerSPForwardByName)
|
|
|
|
REGISTER_FUNC("UnregisterSPForward", unregisterSPForward)
|
|
|
|
REGISTER_FUNC("ExecuteForward", executeForwards)
|
|
|
|
REGISTER_FUNC("PrepareCellArray", MNF_PrepareCellArray)
|
|
|
|
REGISTER_FUNC("PrepareCharArray", MNF_PrepareCharArray)
|
|
|
|
REGISTER_FUNC("PrepareCellArrayA", prepareCellArray)
|
|
|
|
REGISTER_FUNC("PrepareCharArrayA", prepareCharArray)
|
|
|
|
|
|
|
|
// Player
|
|
|
|
REGISTER_FUNC("GetPlayerFlags", MNF_GetPlayerFlags)
|
|
|
|
REGISTER_FUNC("IsPlayerValid", MNF_IsPlayerValid)
|
|
|
|
REGISTER_FUNC("GetPlayerName", MNF_GetPlayerName)
|
|
|
|
REGISTER_FUNC("GetPlayerIP", MNF_GetPlayerIP)
|
|
|
|
REGISTER_FUNC("IsPlayerInGame", MNF_IsPlayerInGame)
|
|
|
|
REGISTER_FUNC("IsPlayerBot", MNF_IsPlayerBot)
|
|
|
|
REGISTER_FUNC("IsPlayerAuthorized", MNF_IsPlayerAuthorized)
|
|
|
|
REGISTER_FUNC("GetPlayerTime", MNF_GetPlayerTime)
|
|
|
|
REGISTER_FUNC("GetPlayerPlayTime", MNF_GetPlayerPlayTime)
|
|
|
|
REGISTER_FUNC("GetPlayerCurweapon", MNF_GetPlayerCurweapon)
|
|
|
|
REGISTER_FUNC("GetPlayerTeamID", MNF_GetPlayerTeamID)
|
|
|
|
REGISTER_FUNC("GetPlayerTeam", MNF_GetPlayerTeam)
|
|
|
|
REGISTER_FUNC("GetPlayerDeaths", MNF_GetPlayerDeaths)
|
|
|
|
REGISTER_FUNC("GetPlayerFrags", MNF_GetPlayerFrags)
|
|
|
|
REGISTER_FUNC("GetPlayerMenu", MNF_GetPlayerMenu)
|
|
|
|
REGISTER_FUNC("GetPlayerKeys", MNF_GetPlayerKeys)
|
|
|
|
REGISTER_FUNC("IsPlayerAlive", MNF_IsPlayerAlive)
|
|
|
|
REGISTER_FUNC("IsPlayerConnecting", MNF_IsPlayerConnecting)
|
|
|
|
REGISTER_FUNC("IsPlayerHLTV", MNF_IsPlayerHLTV)
|
|
|
|
REGISTER_FUNC("GetPlayerArmor", MNF_GetPlayerArmor)
|
|
|
|
REGISTER_FUNC("GetPlayerHealth", MNF_GetPlayerHealth)
|
|
|
|
REGISTER_FUNC("GetPlayerEdict", MNF_GetPlayerEdict)
|
|
|
|
REGISTER_FUNC("CellToReal", MNF_CellToReal)
|
|
|
|
REGISTER_FUNC("RealToCell", MNF_RealToCell)
|
2005-10-30 14:17:32 +00:00
|
|
|
REGISTER_FUNC("SetPlayerTeamInfo", MNF_SetPlayerTeamInfo)
|
2006-02-28 09:59:03 +00:00
|
|
|
REGISTER_FUNC("PlayerPropAddr", MNF_PlayerPropAddr)
|
|
|
|
|
|
|
|
REGISTER_FUNC("RegAuthFunc", MNF_RegAuthorizeFunc);
|
|
|
|
REGISTER_FUNC("UnregAuthFunc", MNF_UnregAuthorizeFunc);
|
2004-04-21 19:11:20 +00:00
|
|
|
|
2006-05-07 09:56:06 +00:00
|
|
|
REGISTER_FUNC("FindLibrary", MNF_FindLibrary);
|
|
|
|
REGISTER_FUNC("AddLibraries", MFN_AddLibraries);
|
|
|
|
REGISTER_FUNC("RemoveLibraries", MNF_RemoveLibraries);
|
2006-05-10 11:23:08 +00:00
|
|
|
REGISTER_FUNC("OverrideNatives", MNF_OverrideNatives);
|
2006-05-10 12:40:44 +00:00
|
|
|
REGISTER_FUNC("GetLocalInfo", MNF_GetLocalInfo);
|
2006-05-07 09:56:06 +00:00
|
|
|
|
2006-08-28 11:08:18 +00:00
|
|
|
REGISTER_FUNC("MessageBlock", MNF_MessageBlock);
|
|
|
|
|
2004-04-21 19:11:20 +00:00
|
|
|
#ifdef MEMORY_TEST
|
2005-07-05 22:01:29 +00:00
|
|
|
REGISTER_FUNC("Allocator", m_allocator)
|
|
|
|
REGISTER_FUNC("Deallocator", m_deallocator)
|
|
|
|
REGISTER_FUNC("Reallocator", m_reallocator)
|
2004-09-11 21:52:18 +00:00
|
|
|
#else
|
2005-07-05 22:01:29 +00:00
|
|
|
REGISTER_FUNC("Allocator", MNF_Allocator)
|
|
|
|
REGISTER_FUNC("Deallocator", MNF_Deallocator)
|
|
|
|
REGISTER_FUNC("Reallocator", MNF_Reallocator)
|
2004-04-21 19:11:20 +00:00
|
|
|
#endif // MEMORY_TEST
|
2005-07-05 22:01:29 +00:00
|
|
|
}
|
2004-03-31 18:02:37 +00:00
|
|
|
|
2005-07-05 22:01:29 +00:00
|
|
|
void *Module_ReqFnptr(const char *funcName)
|
|
|
|
{
|
2004-03-31 18:02:37 +00:00
|
|
|
// code
|
2005-07-05 22:01:29 +00:00
|
|
|
// ^---- really? wow!
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-03-31 18:02:37 +00:00
|
|
|
g_LastRequestedFunc = funcName;
|
2005-07-05 22:01:29 +00:00
|
|
|
|
|
|
|
CList<func_s, const char *>::iterator iter;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-05 22:01:29 +00:00
|
|
|
for (iter = g_functions.begin(); iter; ++iter)
|
2004-03-31 18:02:37 +00:00
|
|
|
{
|
2005-07-05 22:01:29 +00:00
|
|
|
if (strcmp(funcName, iter->desc) == 0)
|
|
|
|
return iter->pfn;
|
2004-03-31 18:02:37 +00:00
|
|
|
}
|
2005-07-05 22:01:29 +00:00
|
|
|
|
2004-03-31 18:02:37 +00:00
|
|
|
return NULL;
|
2004-09-02 02:16:38 +00:00
|
|
|
}
|
2005-08-18 06:34:34 +00:00
|
|
|
|
2006-01-06 04:59:39 +00:00
|
|
|
Debugger *DisableDebugHandler(AMX *amx)
|
2005-10-25 20:38:00 +00:00
|
|
|
{
|
2006-01-06 04:59:39 +00:00
|
|
|
Debugger *pd = static_cast<Debugger *>(amx->userdata[UD_DEBUGGER]);
|
|
|
|
|
|
|
|
amx->userdata[UD_DEBUGGER] = NULL;
|
|
|
|
amx->flags &= ~(AMX_FLAG_DEBUG);
|
2005-10-25 20:38:00 +00:00
|
|
|
amx_SetDebugHook(amx, NULL);
|
2006-01-06 04:59:39 +00:00
|
|
|
|
|
|
|
return pd;
|
2005-10-25 20:38:00 +00:00
|
|
|
}
|
|
|
|
|
2006-01-06 04:59:39 +00:00
|
|
|
void EnableDebugHandler(AMX *amx, Debugger *pd)
|
2005-10-25 20:38:00 +00:00
|
|
|
{
|
2006-01-06 04:59:39 +00:00
|
|
|
if (pd)
|
|
|
|
amx->flags |= AMX_FLAG_DEBUG;
|
|
|
|
|
|
|
|
amx->userdata[UD_DEBUGGER] = pd;
|
|
|
|
amx_SetDebugHook(amx, &Debugger::DebugHook);
|
2005-10-25 20:38:00 +00:00
|
|
|
}
|
|
|
|
|
2005-08-18 06:37:05 +00:00
|
|
|
#if !defined MEMORY_TEST && !defined WIN32
|
2005-11-19 21:52:56 +00:00
|
|
|
void * operator new(size_t size)
|
2005-09-16 23:48:51 +00:00
|
|
|
{
|
|
|
|
return (calloc(1, size));
|
2005-08-18 06:34:34 +00:00
|
|
|
}
|
|
|
|
|
2005-11-19 21:52:56 +00:00
|
|
|
void * operator new[](size_t size)
|
2005-09-16 23:48:51 +00:00
|
|
|
{
|
|
|
|
return (calloc(1, size));
|
2005-08-18 06:34:34 +00:00
|
|
|
}
|
|
|
|
|
2005-11-19 21:52:56 +00:00
|
|
|
void operator delete(void * ptr)
|
2005-09-16 23:48:51 +00:00
|
|
|
{
|
|
|
|
if (ptr)
|
2005-08-18 06:34:34 +00:00
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
|
2005-11-19 21:52:56 +00:00
|
|
|
void operator delete[](void * ptr)
|
2005-09-16 23:48:51 +00:00
|
|
|
{
|
|
|
|
if (ptr)
|
2005-08-18 06:34:34 +00:00
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
#endif
|