final cleaned revision (I hope)

This commit is contained in:
Borja Ferrer 2005-09-16 23:48:51 +00:00
parent 4b1769f457
commit ebd4974c75
41 changed files with 2308 additions and 1339 deletions

View File

@ -52,7 +52,7 @@ CmdMngr::CmdMngr()
}
CmdMngr::Command::Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags,
int pfunc, bool pviewable, CmdMngr* pparent) : commandline(pcmd), info(pinfo)
int pfunc, bool pviewable, CmdMngr* pparent) : commandline(pcmd), info(pinfo)
{
char szCmd[64], szArg[64];
*szCmd = 0; *szArg = 0;
@ -193,6 +193,7 @@ void CmdMngr::Command::setCmdType(int a)
if (cmdtype & 1) // ClientCommand
{
parent->setCmdLink(&parent->sortedlists[1], this);
if (!parent->registerCmdPrefix(this))
parent->setCmdLink(&parent->clcmdlist, this, false);
}

View File

@ -52,12 +52,14 @@ public:
class Command
{
friend class CmdMngr;
CPluginMngr::CPlugin* plugin;
CmdMngr* parent;
String command;
String argument;
String commandline;
String info;
bool listable;
int function;
int flags;
@ -65,6 +67,7 @@ public:
int cmdtype;
int prefix;
static int uniqueid;
Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags, int pfunc, bool pviewable, CmdMngr* pparent);
~Command();
public:
@ -72,7 +75,7 @@ public:
inline const char* getArgument() { return argument.c_str(); }
inline const char* getCmdInfo() { return info.c_str(); }
inline const char* getCmdLine() { return commandline.c_str(); }
inline bool matchCommandLine(const char* cmd, const char* arg) { return (!stricmp(command.c_str()+prefix, cmd+prefix) && (argument.empty() || !stricmp(argument.c_str(), arg))); }
inline bool matchCommandLine(const char* cmd, const char* arg) { return (!stricmp(command.c_str() + prefix, cmd + prefix) && (argument.empty() || !stricmp(argument.c_str(), arg))); }
inline bool matchCommand(const char* cmd) { return (!strcmp(command.c_str(), cmd)); }
inline int getFunction() const { return function; }
inline bool gotAccess(int f) const { return (!flags || ((flags & f) == flags)); }
@ -80,6 +83,7 @@ public:
inline bool isViewable() const { return listable; }
inline int getFlags() const { return flags; }
inline long int getId() const { return (long int)id; }
const char* getCmdType() const;
void setCmdType(int a);
};
@ -105,7 +109,7 @@ private:
CmdMngr* parent;
CmdLink* list;
CmdPrefix* next;
CmdPrefix(const char* nn, CmdMngr* pp) : name(nn), parent(pp), list(0), next(0){}
CmdPrefix(const char* nn, CmdMngr* pp): name(nn), parent(pp), list(0), next(0) {}
~CmdPrefix() { parent->clearCmdLink(&list); }
} *prefixHead;
@ -123,9 +127,11 @@ public:
// Interface
void registerPrefix(const char* nn);
Command* registerCommand(CPluginMngr::CPlugin* plugin, int func, char* cmd, char* info, int level, bool listable);
Command* getCmd(long int id, int type, int access);
int getCmdNum(int type, int access);
void clearBufforedInfo();
void clear();
@ -156,6 +162,7 @@ private:
int buf_cmdid;
int buf_cmdtype;
int buf_cmdaccess;
iterator buf_cmdptr;
int buf_id;

View File

@ -135,7 +135,6 @@ EventsMngr::~EventsMngr()
clearEvents();
}
CPluginMngr::CPlugin * EventsMngr::ClEvent::getPlugin()
{
return m_Plugin;
@ -311,6 +310,7 @@ void EventsMngr::parseValue(int iValue)
break;
}
}
if (anyConditions && !execute)
(*iter).m_Done = true; // don't execute
}
@ -352,10 +352,12 @@ void EventsMngr::parseValue(float fValue)
case '<': if (fValue < condIter->fValue) execute = true; break;
case '>': if (fValue > condIter->fValue) execute = true; break;
}
if (execute)
break;
}
}
if (anyConditions && !execute)
(*iter).m_Done = true; // don't execute
}
@ -396,10 +398,12 @@ void EventsMngr::parseValue(const char *sz)
case '!': if (strcmp(sz, condIter->sValue.c_str())) execute = true; break;
case '&': if (strstr(sz, condIter->sValue.c_str())) execute = true; break;
}
if (execute)
break;
}
}
if (anyConditions && !execute)
(*iter).m_Done = true; // don't execute
}

View File

@ -32,7 +32,7 @@
#ifndef __CEVENTS_H__
#define __CEVENTS_H__
#define MAX_AMX_REG_MSG MAX_REG_MSGS+16
#define MAX_AMX_REG_MSG MAX_REG_MSGS + 16
enum
{
@ -142,12 +142,14 @@ public:
// Interface
ClEvent* registerEvent(CPluginMngr::CPlugin* plugin, int func, int flags, int msgid);
void parserInit(int msg_type, float* timer, CPlayer* pPlayer, int index);
void parseValue(int iValue);
void parseValue(float fValue);
void parseValue(const char *sz);
void executeEvents();
int getArgNum() const; //{ return (parsePos+1); }
int getArgNum() const; //{ return (parsePos + 1); }
const char* getArgString(int a) const;
int getArgInteger(int a) const;
float getArgFloat(int a) const;

View File

@ -43,13 +43,17 @@ class File
public:
File(const char* n, const char* m);
~File();
operator bool () const;
friend File& operator<<(File& f, const String& n);
friend File& operator<<(File& f, const char* n);
friend File& operator<<(File& f, const char& c);
friend File& operator<<(File& f, int n);
friend File& operator>>(File& f, String& n);
friend File& operator>>(File& f, char* n);
int getline(char* buf, int sz);
File& skipWs();
};

View File

@ -37,11 +37,14 @@ CForward::CForward(const char *name, ForwardExecType et, int numParams, const Fo
m_FuncName = name;
m_ExecType = et;
m_NumParams = numParams;
memcpy((void *)m_ParamTypes, paramTypes, numParams * sizeof(ForwardParam));
// find funcs
int func;
AMXForward *tmp = NULL;
m_Funcs.clear();
for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter)
{
if ((*iter).isValid() && amx_FindPublic((*iter).getAMX(), name, &func) == AMX_ERR_NONE)
@ -74,51 +77,52 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
// Get debug info
AMX *amx = (*iter).pPlugin->getAMX();
Debugger *pDebugger = (Debugger *)amx->userdata[UD_DEBUGGER];
if (pDebugger)
pDebugger->BeginExec();
// handle strings & arrays
int i, ax=0;
int i, ax = 0;
for (i = 0; i < m_NumParams; ++i)
{
if (m_ParamTypes[i] == FP_STRING || m_ParamTypes[i] == FP_STRINGEX)
{
cell *tmp;
amx_Allot(iter->pPlugin->getAMX(),
(m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i]))+1 : STRINGEX_MAXLENGTH,
&realParams[i], &tmp);
amx_Allot(iter->pPlugin->getAMX(), (m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i])) + 1 : STRINGEX_MAXLENGTH, &realParams[i], &tmp);
amx_SetStringOld(tmp, (const char *)(params[i]), 0, 0);
physAddrs[i] = tmp;
}
else if (m_ParamTypes[i] == FP_ARRAY)
{
cell *tmp;
amx_Allot(amx, preparedArrays[params[i]].size,
&realParams[i], &tmp);
amx_Allot(amx, preparedArrays[params[i]].size, &realParams[i], &tmp);
physAddrs[i] = tmp;
if (preparedArrays[params[i]].type == Type_Cell)
{
memcpy(tmp, preparedArrays[params[i]].ptr, preparedArrays[params[i]].size * sizeof(cell));
}
else
{
} else {
char *data = (char*)preparedArrays[params[i]].ptr;
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
*tmp++ = (static_cast<cell>(*data++)) & 0xFF;
}
}
else
{
} else {
realParams[i] = params[i];
}
}
//Push the parameters in reverse order. Weird, unfriendly part of Small 3.0!
for (i=m_NumParams-1; i>=0; i--)
//Push the parameters in reverse order. Weird, unfriendly part of Small 3.0!
for (i = m_NumParams-1; i >= 0; i--)
{
amx_Push(amx, realParams[i]);
}
// exec
cell retVal;
int err = amx_Exec(amx, &retVal, iter->func);
// log runtime error, if any
if (err != AMX_ERR_NONE)
{
@ -126,12 +130,16 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
if (pDebugger && pDebugger->ErrorExists())
{
//we don't care, something else logged the error.
} else if (err != -1) {
}
else if (err != -1)
{
//nothing logged the error so spit it out anyway
LogError(amx, err, NULL);
}
}
amx->error = AMX_ERR_NONE;
if (pDebugger)
pDebugger->EndExec();
@ -157,10 +165,9 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
if (preparedArrays[params[i]].type == Type_Cell)
{
memcpy(preparedArrays[params[i]].ptr, tmp, preparedArrays[params[i]].size * sizeof(cell));
}
else
{
} else {
char *data = (char*)preparedArrays[params[i]].ptr;
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
*data++ = static_cast<char>(*tmp++ & 0xFF);
}
@ -172,24 +179,25 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
// decide what to do (based on exectype and retval)
switch (m_ExecType)
{
case ET_IGNORE:
break;
case ET_STOP:
if (retVal > 0)
return retVal;
case ET_STOP2:
if (retVal == 1)
return 1;
else if (retVal > globRetVal)
globRetVal = retVal;
break;
case ET_CONTINUE:
if (retVal > globRetVal)
globRetVal = retVal;
break;
case ET_IGNORE:
break;
case ET_STOP:
if (retVal > 0)
return retVal;
case ET_STOP2:
if (retVal == 1)
return 1;
else if (retVal > globRetVal)
globRetVal = retVal;
break;
case ET_CONTINUE:
if (retVal > globRetVal)
globRetVal = retVal;
break;
}
}
}
return globRetVal;
}
@ -235,57 +243,60 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
// handle strings & arrays
int i;
for (i = 0; i < m_NumParams; ++i)
{
if (m_ParamTypes[i] == FP_STRING || m_ParamTypes[i] == FP_STRINGEX)
{
cell *tmp;
amx_Allot(m_Amx,
(m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i]))+1 : STRINGEX_MAXLENGTH,
&realParams[i], &tmp);
amx_Allot(m_Amx, (m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i])) + 1 : STRINGEX_MAXLENGTH, &realParams[i], &tmp);
amx_SetStringOld(tmp, (const char *)(params[i]), 0, 0);
physAddrs[i] = tmp;
}
else if (m_ParamTypes[i] == FP_ARRAY)
{
cell *tmp;
amx_Allot(m_Amx, preparedArrays[params[i]].size,
&realParams[i], &tmp);
amx_Allot(m_Amx, preparedArrays[params[i]].size, &realParams[i], &tmp);
physAddrs[i] = tmp;
if (preparedArrays[params[i]].type == Type_Cell)
{
memcpy(tmp, preparedArrays[params[i]].ptr, preparedArrays[params[i]].size * sizeof(cell));
}
else
{
} else {
char *data = (char*)preparedArrays[params[i]].ptr;
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
*tmp++ = (static_cast<cell>(*data++)) & 0xFF;
}
}
else
{
} else {
realParams[i] = params[i];
}
}
for (i=m_NumParams-1; i>=0; i--)
for (i = m_NumParams - 1; i >= 0; i--)
amx_Push(m_Amx, realParams[i]);
// exec
cell retVal;
int err = amx_Exec(m_Amx, &retVal, m_Func);
if (err != AMX_ERR_NONE)
{
//Did something else set an error?
if (pDebugger && pDebugger->ErrorExists())
{
//we don't care, something else logged the error.
} else if (err != -1) {
}
else if (err != -1)
{
//nothing logged the error so spit it out anyway
LogError(m_Amx, err, NULL);
}
}
if (pDebugger)
pDebugger->EndExec();
m_Amx->error = AMX_ERR_NONE;
// cleanup strings & arrays
@ -310,10 +321,9 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
if (preparedArrays[params[i]].type == Type_Cell)
{
memcpy(preparedArrays[params[i]].ptr, tmp, preparedArrays[params[i]].size * sizeof(cell));
}
else
{
} else {
char *data = (char*)preparedArrays[params[i]].ptr;
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
*data++ = static_cast<char>(*tmp++ & 0xFF);
}
@ -329,9 +339,12 @@ int CForwardMngr::registerForward(const char *funcName, ForwardExecType et, int
{
int retVal = m_Forwards.size() << 1;
CForward *tmp = new CForward(funcName, et, numParams, paramTypes);
if (!tmp)
return -1; // should be invalid
m_Forwards.push_back(tmp);
return retVal;
}
@ -339,22 +352,26 @@ int CForwardMngr::registerSPForward(int func, AMX *amx, int numParams, const For
{
int retVal = -1;
CSPForward *pForward;
if (!m_FreeSPForwards.empty())
{
retVal = m_FreeSPForwards.front();
pForward = m_SPForwards[retVal >> 1];
pForward->Set(func, amx, numParams, paramTypes);
if (pForward->getFuncsNum() == 0)
return -1;
m_FreeSPForwards.pop();
}
else
{
} else {
retVal = (m_SPForwards.size() << 1) | 1;
pForward = new CSPForward();
if (!pForward)
return -1;
pForward->Set(func, amx, numParams, paramTypes);
if (pForward->getFuncsNum() == 0)
{
return -1;
@ -363,6 +380,7 @@ int CForwardMngr::registerSPForward(int func, AMX *amx, int numParams, const For
m_SPForwards.push_back(pForward);
}
return retVal;
}
@ -370,56 +388,58 @@ int CForwardMngr::registerSPForward(const char *funcName, AMX *amx, int numParam
{
int retVal = (m_SPForwards.size() << 1) | 1;
CSPForward *pForward;
if (!m_FreeSPForwards.empty())
{
retVal = m_FreeSPForwards.front();
pForward = m_SPForwards[retVal>>1]; // >>1 because unregisterSPForward pushes the id which contains the sp flag
pForward = m_SPForwards[retVal>>1]; // >>1 because unregisterSPForward pushes the id which contains the sp flag
pForward->Set(funcName, amx, numParams, paramTypes);
if (pForward->getFuncsNum() == 0)
return -1;
m_FreeSPForwards.pop();
}
else
{
} else {
pForward = new CSPForward();
if (!pForward)
return -1;
pForward->Set(funcName, amx, numParams, paramTypes);
if (pForward->getFuncsNum() == 0)
{
delete pForward;
return -1;
}
m_SPForwards.push_back(pForward);
}
return retVal;
}
bool CForwardMngr::isIdValid(int id) const
{
return (id >= 0) && ((id & 1) ?
(static_cast<size_t>(id >> 1) < m_SPForwards.size()) :
(static_cast<size_t>(id >> 1) < m_Forwards.size()));
return (id >= 0) && ((id & 1) ? (static_cast<size_t>(id >> 1) < m_SPForwards.size()) : (static_cast<size_t>(id >> 1) < m_Forwards.size()));
}
cell CForwardMngr::executeForwards(int id, cell *params)
{
int retVal = (id & 1) ? m_SPForwards[id >> 1]->execute(params, m_TmpArrays) :
m_Forwards[id >> 1]->execute(params, m_TmpArrays);
int retVal = (id & 1) ? m_SPForwards[id >> 1]->execute(params, m_TmpArrays) : m_Forwards[id >> 1]->execute(params, m_TmpArrays);
m_TmpArraysNum = 0;
return retVal;
}
int CForwardMngr::getParamsNum(int id) const
{
return (id & 1) ? m_SPForwards[id >> 1]->getParamsNum() :
m_Forwards[id >> 1]->getParamsNum();
return (id & 1) ? m_SPForwards[id >> 1]->getParamsNum() : m_Forwards[id >> 1]->getParamsNum();
}
ForwardParam CForwardMngr::getParamType(int id, int paramNum) const
{
return (id & 1) ? m_SPForwards[id >> 1]->getParamType(paramNum) :
m_Forwards[id >> 1]->getParamType(paramNum);
return (id & 1) ? m_SPForwards[id >> 1]->getParamType(paramNum) : m_Forwards[id >> 1]->getParamType(paramNum);
}
void CForwardMngr::clear()
@ -428,7 +448,9 @@ void CForwardMngr::clear()
{
delete *iter;
}
SPForwardVec::iterator spIter;
for (spIter = m_SPForwards.begin(); spIter != m_SPForwards.end(); ++spIter)
{
delete (*spIter);
@ -436,8 +458,10 @@ void CForwardMngr::clear()
m_Forwards.clear();
m_SPForwards.clear();
while (!m_FreeSPForwards.empty())
m_FreeSPForwards.pop();
m_TmpArraysNum = 0;
}
@ -449,74 +473,97 @@ bool CForwardMngr::isSPForward(int id) const
void CForwardMngr::unregisterSPForward(int id)
{
//make sure the id is valid
if ( !isIdValid(id) || m_SPForwards.at(id >> 1)->isFree )
if (!isIdValid(id) || m_SPForwards.at(id >> 1)->isFree)
return;
m_SPForwards.at(id >> 1)->isFree = true;
m_FreeSPForwards.push(id);
}
int registerForward(const char *funcName, ForwardExecType et, ...)
{
int curParam = 0;
va_list argptr;
va_start(argptr, et);
ForwardParam params[FORWARD_MAX_PARAMS];
ForwardParam tmp;
while (true)
{
if (curParam == FORWARD_MAX_PARAMS)
break;
tmp = (ForwardParam)va_arg(argptr, int);
if (tmp == FP_DONE)
break;
params[curParam] = tmp;
++curParam;
}
va_end(argptr);
return g_forwards.registerForward(funcName, et, curParam, params);
}
int registerSPForwardByName(AMX *amx, const char *funcName, ...)
{
int curParam = 0;
va_list argptr;
va_start(argptr, funcName);
ForwardParam params[FORWARD_MAX_PARAMS];
ForwardParam tmp;
while (true)
{
if (curParam == FORWARD_MAX_PARAMS)
break;
tmp = (ForwardParam)va_arg(argptr, int);
if (tmp == FP_DONE)
break;
params[curParam] = tmp;
++curParam;
}
va_end(argptr);
return g_forwards.registerSPForward(funcName, amx, curParam, params);
}
int registerSPForward(AMX *amx, int func, ...)
{
int curParam = 0;
va_list argptr;
va_start(argptr, func);
ForwardParam params[FORWARD_MAX_PARAMS];
ForwardParam tmp;
while (true)
{
if (curParam == FORWARD_MAX_PARAMS)
break;
tmp = (ForwardParam)va_arg(argptr, int);
if (tmp == FP_DONE)
break;
params[curParam] = tmp;
++curParam;
}
va_end(argptr);
return g_forwards.registerSPForward(func, amx, curParam, params);
}
@ -526,9 +573,12 @@ cell executeForwards(int id, ...)
return -1;
cell params[FORWARD_MAX_PARAMS];
int paramsNum = g_forwards.getParamsNum(id);
va_list argptr;
va_start(argptr, id);
for (int i = 0; i < paramsNum && i < FORWARD_MAX_PARAMS; ++i)
{
if (g_forwards.getParamType(id, i) == FP_FLOAT)
@ -539,7 +589,9 @@ cell executeForwards(int id, ...)
else
params[i] = (cell)va_arg(argptr, cell);
}
va_end(argptr);
return g_forwards.executeForwards(id, params);
}
@ -547,13 +599,16 @@ cell CForwardMngr::prepareArray(void *ptr, unsigned int size, ForwardArrayElemTy
{
if (m_TmpArraysNum >= FORWARD_MAX_PARAMS)
{
#ifdef MEMORY_TEST
#ifdef MEMORY_TEST
m_validateAllAllocUnits();
#endif // MEMORY_TEST
#endif // MEMORY_TEST
AMXXLOG_Log("[AMXX] Forwards with more than 32 parameters are not supported (tried to prepare array # %d).", m_TmpArraysNum + 1);
m_TmpArraysNum = 0;
return -1;
}
m_TmpArrays[m_TmpArraysNum].ptr = ptr;
m_TmpArrays[m_TmpArraysNum].size = size;
m_TmpArrays[m_TmpArraysNum].type = type;

View File

@ -77,7 +77,9 @@ enum ForwardArrayElemType
struct ForwardPreparedArray
{
void *ptr;
ForwardArrayElemType type;
unsigned int size;
bool copyBack;
};
@ -96,13 +98,14 @@ class CForward
};
typedef CVector<AMXForward> AMXForwardList;
AMXForwardList m_Funcs;
ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS];
public:
CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes);
CForward()
{ } // leaves everything unitialized'
CForward() {} // leaves everything unitialized'
cell execute(cell *params, ForwardPreparedArray *preparedArrays);
int getParamsNum() const
@ -129,8 +132,10 @@ class CSPForward
{
const char *m_FuncName;
int m_NumParams;
ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS];
AMX *m_Amx;
int m_Func;
bool m_HasFunc;
@ -179,8 +184,7 @@ public:
CForwardMngr()
{ m_TmpArraysNum = 0; }
~CForwardMngr()
{ }
~CForwardMngr() {}
// Interface
// Register normal forward
@ -188,15 +192,19 @@ public:
// Register single plugin forward
int registerSPForward(const char *funcName, AMX *amx, int numParams, const ForwardParam * paramTypes);
int registerSPForward(int func, AMX *amx, int numParams, const ForwardParam * paramTypes);
// Unregister single plugin forward
void unregisterSPForward(int id);
// execute forward
cell executeForwards(int id, cell *params);
void clear(); // delete all forwards
bool isIdValid(int id) const; // check whether forward id is valid
bool isSPForward(int id) const; // check whether forward is single plugin
int getParamsNum(int id) const; // get num of params of a forward
int getFuncsNum(int id) const; // get num of found functions of a forward
ForwardParam getParamType(int id, int paramId) const;
cell prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type, bool copyBack); // prepare array
};
@ -214,4 +222,3 @@ cell prepareCellArray(cell *ptr, unsigned int size, bool copyBack = false);
cell prepareCharArray(char *ptr, unsigned int size, bool copyBack = false);
#endif //FORWARD_H

View File

@ -280,7 +280,7 @@ CLangMngr::CLang::CLang(const char *lang)
{
m_LookUpTable.clear();
strncpy(m_LanguageName, lang, 2);
m_LanguageName[2]=0;
m_LanguageName[2] = 0;
}
CLangMngr::CLang::LangEntry *CLangMngr::CLang::AddEntry(int pKey, uint32_t defHash, const char *def, bool cache)
@ -588,14 +588,14 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
{
def = GetDef(g_vault.get("server_language"), key);
}
if (strcmp(cpLangName, "en")!=0 && strcmp(g_vault.get("server_language"), "en")!=0)
if (strcmp(cpLangName, "en") != 0 && strcmp(g_vault.get("server_language"), "en") != 0)
{
def = GetDef("en", key);
}
if (!def)
{
static char buf[512];
CHECK_PTR((char*)(buf+17+strlen(key)), buf, sizeof(buf));
CHECK_PTR((char*)(buf + 17 + strlen(key)), buf, sizeof(buf));
sprintf(buf, "ML_LNOTFOUND: %s", key);
def = buf;
}
@ -613,7 +613,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
} else {
static char format[32];
format[0] = '%';
char *ptr = format+1;
char *ptr = format + 1;
while (ptr-format<sizeof(format) && !isalpha(*ptr++ = *def++))
/*nothing*/;
@ -655,7 +655,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
}
default:
{
CHECK_OUTPTR(strlen(format)+1);
CHECK_OUTPTR(strlen(format) + 1);
strcpy(outptr, format);
break;
}
@ -700,7 +700,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
char *tmpPtr = tmpString;
int tmpLen = 0;
static char format[32] = {'%'};
char *ptr = format+1;
char *ptr = format + 1;
if (*src != '%')
{
@ -740,7 +740,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
}
default:
{
CHECK_OUTPTR(strlen(format)+1);
CHECK_OUTPTR(strlen(format) + 1);
strcpy(outptr, format);
break;
}
@ -847,14 +847,14 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
{
def = GetDef(g_vault.get("server_language"), key);
}
if (strcmp(cpLangName, "en")!=0 && strcmp(g_vault.get("server_language"), "en")!=0)
if (strcmp(cpLangName, "en") != 0 && strcmp(g_vault.get("server_language"), "en") != 0)
{
def = GetDef("en", key);
}
if (!def)
{
static char buf[512];
CHECK_PTR((char*)(buf+17+strlen(key)), buf, sizeof(buf));
CHECK_PTR((char*)(buf + 17 + strlen(key)), buf, sizeof(buf));
sprintf(buf, "ML_LNOTFOUND: %s", key);
def = buf;
}
@ -867,7 +867,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
++def;
static char format[32];
format[0] = '%';
char *ptr = format+1;
char *ptr = format + 1;
while (ptr-format<sizeof(format) && !isalpha(*ptr++ = *def++))
/*nothing*/;
ZEROTERM(format);
@ -927,7 +927,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
}
} else {
static char format[32] = {'%'};
char *ptr = format+1;
char *ptr = format + 1;
if (*src != '%')
{
@ -973,6 +973,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
return outbuf;
}
void CLangMngr::MergeDefinitions(const char *lang, CQueue<sKeyDef*> &tmpVec)
{
CLang * language = GetLang(lang);
@ -1086,7 +1087,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
String key;
key.assign(buf.substr(0, pos).c_str());
String def;
def.assign(buf.substr(pos+1).c_str());
def.assign(buf.substr(pos + 1).c_str());
key.trim();
key.toLower();
int iKey = GetKeyEntry(key);
@ -1374,7 +1375,7 @@ bool CLangMngr::Load(const char *filename)
save = ftell(fp);
fseek(fp, keyoffset, SEEK_SET);
fread((void*)&keylen, sizeof(char), 1, fp);
char *data = new char[keylen+1];
char *data = new char[keylen + 1];
fread(data, sizeof(char), keylen, fp);
data[keylen] = 0;
e->key.assign(data);
@ -1402,7 +1403,7 @@ bool CLangMngr::Load(const char *filename)
save = ftell(fp);
fseek(fp, defoffset, SEEK_SET);
fread((void *)&deflen, sizeof(unsigned short), 1, fp);
char *data = new char[deflen+1];
char *data = new char[deflen + 1];
fread(data, sizeof(char), deflen, fp);
data[deflen] = 0;
m_Languages[i]->AddEntry(keynum, defhash, data, true);

View File

@ -51,6 +51,7 @@ struct sKeyDef
{
sKeyDef() { key = -1; def = 0; }
~sKeyDef() { if (def) delete def; }
int key;
String *def;
};
@ -77,7 +78,7 @@ class CLangMngr
// compare this language to a language name
friend bool operator == (const CLang &left, const char *right)
{
return strcmp(left.m_LanguageName, right)==0 ? true : false;
return strcmp(left.m_LanguageName, right) == 0 ? true : false;
}
// Get language name

View File

@ -66,8 +66,10 @@ private:
~CElement()
{
delete m_pObject;
if (m_pNext)
m_pNext->m_pPrev = m_pPrev;
if (m_pPrev)
m_pPrev->m_pNext = m_pNext;
}
@ -103,15 +105,16 @@ private:
}
};
// CList<T,F> class
// CList<T, F> class
CElement *m_pHead; // head of the linked list
CElement *m_pTail; // tail of the linked list
public:
// iterator class
class iterator
{
friend class CList<T,F>;
CList<T,F> *m_pList; // The list that created this iterator
friend class CList<T, F>;
CList<T, F> *m_pList; // The list that created this iterator
CElement *m_CurPos; // Current position in the list
public:
iterator()
@ -121,7 +124,7 @@ public:
}
// constructor based on list, element
iterator(CList<T,F> *pList, CElement *startPos)
iterator(CList<T, F> *pList, CElement *startPos)
{
m_pList = pList;
m_CurPos = startPos;
@ -148,7 +151,7 @@ public:
// validity check operator
inline operator bool () const
{
return m_pList!=NULL && m_CurPos!=NULL && m_CurPos->GetObj()!=NULL;
return m_pList != NULL && m_CurPos != NULL && m_CurPos->GetObj() != NULL;
}
// pre increment operator
@ -185,13 +188,13 @@ public:
}
};
CList<T,F>()
CList<T, F>()
{
m_pHead = NULL;
m_pTail = NULL;
}
~CList<T,F>()
~CList<T, F>()
{
clear();
}
@ -205,6 +208,7 @@ public:
if (where.m_CurPos == m_pHead)
m_pHead = where.m_CurPos->GetNext();
if (where.m_CurPos == m_pTail)
m_pTail = where.m_CurPos->GetPrev();

View File

@ -55,7 +55,9 @@ int LogEventsMngr::CLogCmp::compareCondition(const char* string)
return result;
logid = parent->logCounter;
if (in) return result = strstr(string, text.c_str()) ? 0 : 1;
if (in)
return result = strstr(string, text.c_str()) ? 0 : 1;
return result = strcmp(string,text.c_str());
}
@ -69,9 +71,12 @@ LogEventsMngr::CLogCmp* LogEventsMngr::registerCondition(char* filter)
++filter;
bool in = (*filter=='&');
*filter++ = 0;
int pos = atoi(temp);
if (pos < 0 || pos >= MAX_LOGARGS) pos = 0;
*filter++ = 0;
int pos = atoi(temp);
if (pos < 0 || pos >= MAX_LOGARGS)
pos = 0;
CLogCmp* c = logcmplist;
while (c)
@ -99,7 +104,10 @@ void LogEventsMngr::CLogEvent::registerFilter(char* filter)
}
LogCondEle* aa = new LogCondEle(cmp, 0);
if (aa == 0) return;
if (aa == 0)
return;
filters = new LogCond(cmp->pos, aa, filters);
}
@ -114,7 +122,9 @@ void LogEventsMngr::setLogString(char* frmt, va_list& vaptr)
logString[len] = 0;
}
if (len) logString[--len] = 0;
if (len)
logString[--len] = 0;
logArgc = 0;
}
@ -132,7 +142,10 @@ void LogEventsMngr::setLogString(char* frmt, ...)
}
va_end(logArgPtr);
if (len) logString[--len] = 0;
if (len)
logString[--len] = 0;
logArgc = 0;
}
@ -180,14 +193,16 @@ LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent(CPluginMngr::CPlugin*
arelogevents = true;
CLogEvent** d = &logevents[pos];
while (*d) d = &(*d)->next;
while (*d)
d = &(*d)->next;
return *d = new CLogEvent(plugin, func, this);
}
void LogEventsMngr::executeLogEvents()
{
bool valid;
bool valid;
for (CLogEvent* a = logevents[logArgc]; a; a = a->next)
{
@ -214,7 +229,7 @@ void LogEventsMngr::executeLogEvents()
{
executeForwards(a->func);
}
}
}
}
void LogEventsMngr::clearLogEvents()

View File

@ -61,12 +61,15 @@ public:
{
friend class LogEventsMngr;
friend class CLogEvent;
LogEventsMngr* parent;
String text;
int logid;
int pos;
int result;
bool in;
CLogCmp *next;
CLogCmp(const char* s, bool r, int p, CLogCmp *n, LogEventsMngr* mg) : text(s)
@ -95,12 +98,13 @@ public:
{
CLogCmp *cmp;
LogCondEle *next;
LogCondEle(CLogCmp *c, LogCondEle *n): cmp(c), next(n) { }
LogCondEle(CLogCmp *c, LogCondEle *n): cmp(c), next(n) {}
};
struct LogCond
{
int argnum;
LogCondEle *list;
LogCond *next;
LogCond(int a, LogCondEle* ee, LogCond* n) : argnum(a), list(ee), next(n) {}
@ -108,11 +112,14 @@ public:
};
CPluginMngr::CPlugin *plugin;
int func;
LogCond *filters;
LogEventsMngr* parent;
CLogEvent *next;
CLogEvent(CPluginMngr::CPlugin *p, int f, LogEventsMngr* ppp) : plugin(p), func(f), filters(0), parent(ppp), next(0) { }
CLogEvent(CPluginMngr::CPlugin *p, int f, LogEventsMngr* ppp) : plugin(p), func(f), filters(0), parent(ppp), next(0) {}
~CLogEvent();
public:
inline CPluginMngr::CPlugin *getPlugin() { return plugin; }
@ -124,6 +131,7 @@ private:
CLogEvent *logevents[MAX_LOGARGS + 1];
CLogEvent *getValidLogEvent(CLogEvent * a);
CLogCmp* registerCondition(char* filter);
void clearConditions();
public:
LogEventsMngr();
@ -132,10 +140,12 @@ public:
// Interface
CLogEvent* registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos);
inline bool logEventsExist() { return arelogevents; }
void setLogString(char* frmt, va_list& vaptr);
void setLogString(char* frmt, ...);
void parseLogString();
void executeLogEvents();
inline const char* getLogString() { return logString; }
inline int getLogArgNum() { return logArgc; }
inline const char* getLogArg(int i) { return (i < 0 || i >= logArgc) ? "" : logArgs[i]; }
@ -147,7 +157,7 @@ public:
LogEventsMngr* b;
public:
inline iterator(CLogEvent*aa,LogEventsMngr* bb) : a(aa), b(bb) {}
inline iterator(CLogEvent*aa, LogEventsMngr* bb) : a(aa), b(bb) {}
inline iterator& operator++()
{
@ -156,7 +166,7 @@ public:
}
inline bool operator==(const iterator& c) const { return a == c.a; }
inline bool operator!=(const iterator& c) const { return !operator == (c); }
inline bool operator!=(const iterator& c) const { return !operator == (c); }
CLogEvent& operator*() { return *a; }
operator bool () const { return a ? true : false; }
};

View File

@ -63,7 +63,10 @@ int MenuMngr::findMenuId(const char* name, AMX* amx)
int MenuMngr::registerMenuId(const char* n, AMX* a)
{
int id = findMenuId(n, a);
if (id) return id;
if (id)
return id;
headid = new MenuIdEle(n, a, headid);
if (!headid)

View File

@ -43,6 +43,7 @@ class MenuMngr
String name;
AMX* amx;
MenuIdEle* next;
int id;
static int uniqueid;
@ -67,6 +68,7 @@ private:
int menuid;
int keys;
int function;
MenuCommand* next;
MenuCommand(CPluginMngr::CPlugin *a, int mi, int k, int f);
public:

View File

@ -89,8 +89,10 @@ bool CPlayer::Connect(const char* connectname, const char* ipaddress)
time = gpGlobals->time;
bot = IsBot();
death_killer = 0;
memset(flags, 0, sizeof(flags));
memset(weapons, 0, sizeof(weapons));
initialized = true;
authorized = false;
@ -180,6 +182,7 @@ int XVars::put(AMX* p, cell* v)
head[num].value = v;
head[num].amx = p;
return num++;
}
@ -237,7 +240,10 @@ void TeamIds::registerTeam(const char* n, int s)
}
*a = new TeamEle(n, s);
if (*a == 0) return;
if (*a == 0)
return;
newTeam |= (1<<(*a)->tid);
}

View File

@ -40,9 +40,9 @@
class CCVar
{
cvar_t cvar;
String name;
String plugin;
cvar_t cvar;
String name;
String plugin;
public:
CCVar(const char* pname, const char* pplugin, int pflags, float pvalue) : name(pname), plugin(pplugin)
@ -51,12 +51,12 @@ public:
cvar.flags = pflags;
cvar.string = "";
cvar.value = pvalue;
}
}
inline cvar_t* getCvar() { return &cvar; }
inline const char* getPluginName() { return plugin.c_str(); }
inline const char* getName() { return name.c_str(); }
inline bool operator == (const char* string) { return (strcmp(name.c_str(),string)==0); }
inline bool operator == (const char* string) { return (strcmp(name.c_str(), string) == 0); }
};
// *****************************************************
@ -157,6 +157,7 @@ class Grenades
public:
Grenades() { head = 0; }
~Grenades() { clear(); }
void put(edict_t* grenade, float time, int type, CPlayer* player);
bool find(edict_t* enemy, CPlayer** p, int& type);
void clear();
@ -168,19 +169,20 @@ public:
class ForceObject
{
String filename;
FORCE_TYPE type;
Vector mins;
Vector maxs;
AMX* amx;
String filename;
FORCE_TYPE type;
Vector mins;
Vector maxs;
AMX* amx;
public:
ForceObject(const char* n, FORCE_TYPE c, Vector& mi, Vector& ma, AMX* a) :
filename(n), type(c), mins(mi), maxs(ma), amx(a) {}
ForceObject(const char* n, FORCE_TYPE c, Vector& mi, Vector& ma, AMX* a) : filename(n), type(c), mins(mi), maxs(ma), amx(a) {}
inline const char* getFilename() { return filename.c_str(); }
inline AMX* getAMX() { return amx; }
Vector& getMin() { return mins; }
Vector& getMax() { return maxs; }
inline FORCE_TYPE getForceType() { return type; }
};
@ -197,13 +199,15 @@ class XVars
};
XVarEle* head;
int size;
int num;
int realloc_array(int nsize);
public:
XVars() { num = 0; size = 0; head = 0; }
XVars() { num = 0; size = 0; head = 0; }
~XVars() { clear(); }
void clear();
int put(AMX* a, cell* v);
@ -234,7 +238,7 @@ class CScript
AMX* amx;
void* code;
public:
CScript(AMX* aa, void* cc, const char* ff) : filename(ff), amx(aa), code(cc) { }
CScript(AMX* aa, void* cc, const char* ff) : filename(ff), amx(aa), code(cc) {}
inline AMX* getAMX() { return amx; }
inline const char* getName() { return filename.c_str(); }
@ -269,6 +273,7 @@ class TeamIds
public:
TeamIds();
~TeamIds();
void registerTeam(const char* n, int s);
int findTeamId(const char* n);
int findTeamIdCase(const char* n);

View File

@ -136,7 +136,7 @@ bool CModule::attachModule()
m_MissingFunc = g_LastRequestedFunc;
return false;
default:
AMXXLOG_Log("[AMXX] Module \"%s\" (version \"%s\") returned an invalid code.", m_Filename.c_str(), getVersion());
AMXXLOG_Log("[AMXX] Module \"%s\" (version \"%s\") returned an invalid code.", m_Filename.c_str(), getVersion());
m_Status = MODULE_BADLOAD;
return false;
}
@ -191,7 +191,7 @@ bool CModule::queryModule()
case AMXX_OK:
break;
default:
AMXXLOG_Log("[AMXX] Module \"%s\" (version \"%s\") returned an invalid code.", m_Filename.c_str(), getVersion());
AMXXLOG_Log("[AMXX] Module \"%s\" (version \"%s\") returned an invalid code.", m_Filename.c_str(), getVersion());
m_Status = MODULE_BADLOAD;
return false;
}

View File

@ -71,8 +71,10 @@ struct amxx_module_info_s
class CModule
{
String m_Filename; // Filename
bool m_Metamod; // Using metamod?
bool m_Amxx; // Using new module interface?
amxx_module_info_s m_InfoNew; // module info (new module interface)
DLHANDLE m_Handle; // handle
MODULE_STATUS m_Status; // status
@ -100,12 +102,13 @@ public:
inline const char* getName() const { return m_InfoNew.name; }
inline const amxx_module_info_s* getInfoNew() const { return &m_InfoNew; } // new
inline int getStatusValue() { return m_Status; }
inline bool operator==(const char* fname) { return !strcmp(m_Filename.c_str(), fname); }
inline bool operator==(const char* fname) { return !strcmp(m_Filename.c_str(), fname); }
inline bool isReloadable() { return ((m_Status == MODULE_LOADED) && (m_InfoNew.reload != 0)); }
inline bool isAmxx() const { return m_Amxx; }
inline const char *getMissingFunc() const { return m_MissingFunc; }
inline const char *getFilename() { return m_Filename.c_str(); }
inline bool IsMetamod() { return m_Metamod; }
void CModule::CallPluginsLoaded();
CList<AMX_NATIVE_INFO*> m_Natives;

View File

@ -42,12 +42,17 @@ extern const char *no_function;
CPluginMngr::CPlugin* CPluginMngr::loadPlugin(const char* path, const char* name, char* error, int debug)
{
CPlugin** a = &head;
while( *a ) a = &(*a)->next;
while (*a)
a = &(*a)->next;
*a = new CPlugin(pCounter++, path, name, error, debug);
return (*a);
}
void CPluginMngr::unloadPlugin( CPlugin** a ) {
void CPluginMngr::unloadPlugin(CPlugin** a)
{
CPlugin* next = (*a)->next;
delete *a;
*a = next;
@ -58,9 +63,10 @@ void CPluginMngr::Finalize()
{
if (m_Finalized)
return;
pNatives = BuildNativeTable();
pNatives = BuildNativeTable();
CPlugin *a = head;
while (a)
{
if (a->getStatusCode() == ps_running)
@ -68,19 +74,20 @@ void CPluginMngr::Finalize()
amx_Register(a->getAMX(), pNatives, -1);
a->Finalize();
}
a=a->next;
a = a->next;
}
m_Finalized = true;
}
int CPluginMngr::loadPluginsFromFile( const char* filename )
int CPluginMngr::loadPluginsFromFile(const char* filename)
{
char file[256];
FILE *fp = fopen(build_pathname_r(file, sizeof(file)-1, "%s",filename) , "rt");
FILE *fp = fopen(build_pathname_r(file, sizeof(file) - 1, "%s", filename), "rt");
if ( !fp )
if (!fp)
{
AMXXLOG_Log( "[AMXX] Plugins list not found (file \"%s\")",filename);
AMXXLOG_Log("[AMXX] Plugins list not found (file \"%s\")", filename);
return 1;
}
@ -91,22 +98,26 @@ int CPluginMngr::loadPluginsFromFile( const char* filename )
String line;
while ( !feof(fp) )
while (!feof(fp))
{
pluginName[0] = '\0';
debug[0] = '\0';
debugFlag = 0;
line.clear();
line._fread(fp);
sscanf(line.c_str(),"%s %s",pluginName, debug);
if (!isalnum(*pluginName)) continue;
sscanf(line.c_str(), "%s %s", pluginName, debug);
if (!isalnum(*pluginName))
continue;
if (isalnum(*debug) && strcmp(debug, "debug") == 0)
{
debugFlag = 1;
}
CPlugin* plugin = loadPlugin( pluginsDir , pluginName , error, debugFlag);
CPlugin* plugin = loadPlugin(pluginsDir, pluginName, error, debugFlag);
if (plugin->getStatusCode() == ps_bad_load)
{
@ -122,11 +133,15 @@ int CPluginMngr::loadPluginsFromFile( const char* filename )
return pCounter;
}
void CPluginMngr::clear() {
void CPluginMngr::clear()
{
CPlugin**a = &head;
while ( *a )
while (*a)
unloadPlugin(a);
m_Finalized = false;
if (pNatives)
{
delete [] pNatives;
@ -139,74 +154,98 @@ CPluginMngr::CPlugin* CPluginMngr::findPluginFast(AMX *amx)
return (CPlugin*)(amx->userdata[UD_FINDPLUGIN]);
}
CPluginMngr::CPlugin* CPluginMngr::findPlugin(AMX *amx) {
CPluginMngr::CPlugin* CPluginMngr::findPlugin(AMX *amx)
{
CPlugin*a = head;
while ( a && &a->amx != amx )
a=a->next;
while (a && &a->amx != amx)
a = a->next;
return a;
}
CPluginMngr::CPlugin* CPluginMngr::findPlugin(int index){
CPluginMngr::CPlugin* CPluginMngr::findPlugin(int index)
{
CPlugin*a = head;
while ( a && index--)
a=a->next;
while (a && index--)
a = a->next;
return a;
}
CPluginMngr::CPlugin* CPluginMngr::findPlugin(const char* name) {
if (!name) return 0;
CPluginMngr::CPlugin* CPluginMngr::findPlugin(const char* name)
{
if (!name)
return 0;
int len = strlen(name);
if (!len) return 0;
if (!len)
return 0;
CPlugin*a = head;
while( a && strncmp(a->name.c_str(), name,len) )
a=a->next;
while (a && strncmp(a->name.c_str(), name, len))
a = a->next;
return a;
}
const char* CPluginMngr::CPlugin::getStatus() const {
switch(status){
case ps_running:
const char* CPluginMngr::CPlugin::getStatus() const
{
switch (status)
{
case ps_running:
{
if (m_Debug)
{
if (m_Debug)
{
return "debug";
} else {
return "running";
}
break;
return "debug";
} else {
return "running";
}
case ps_paused: return "paused";
case ps_bad_load: return "bad load";
case ps_stopped: return "stopped";
case ps_locked: return "locked";
break;
}
case ps_paused: return "paused";
case ps_bad_load: return "bad load";
case ps_stopped: return "stopped";
case ps_locked: return "locked";
}
return "error";
}
CPluginMngr::CPlugin::CPlugin(int i, const char* p,const char* n, char* e, int d) : name(n), title(n) {
CPluginMngr::CPlugin::CPlugin(int i, const char* p, const char* n, char* e, int d) : name(n), title(n)
{
const char* unk = "unknown";
title.assign(unk);
author.assign(unk);
version.assign(unk);
char file[256];
char* path = build_pathname_r(file, sizeof(file)-1, "%s/%s",p,n);
char* path = build_pathname_r(file, sizeof(file) - 1, "%s/%s", p, n);
code = 0;
memset(&amx, 0, sizeof(AMX));
int err = load_amxscript(&amx,&code,path,e, d);
if ( err == AMX_ERR_NONE )
int err = load_amxscript(&amx, &code, path, e, d);
if (err == AMX_ERR_NONE)
{
status = ps_running;
} else {
status = ps_bad_load;
}
amx.userdata[UD_FINDPLUGIN] = this;
paused_fun = 0;
next = 0;
id = i;
if (status == ps_running)
{
m_PauseFwd = registerSPForwardByName(&amx, "plugin_pause");
m_UnpauseFwd = registerSPForwardByName(&amx, "plugin_unpause");
if (amx.flags & AMX_FLAG_DEBUG)
{
m_Debug = true;
@ -216,16 +255,16 @@ CPluginMngr::CPlugin::CPlugin(int i, const char* p,const char* n, char* e, int d
}
}
CPluginMngr::CPlugin::~CPlugin( )
CPluginMngr::CPlugin::~CPlugin()
{
unload_amxscript( &amx, &code );
unload_amxscript(&amx, &code);
}
int AMXAPI native_handler(AMX *amx, int index)
{
Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];
char name[sNAMEMAX+1];
char name[sNAMEMAX + 1];
amx_GetNative(amx, index, name);
return pHandler->HandleNative(name, index, 0);
@ -253,7 +292,7 @@ static cell AMX_NATIVE_CALL invalid_native(AMX *amx, cell *params)
return 0;
}
char name[sNAMEMAX+1];
char name[sNAMEMAX + 1];
int native = amx->usertags[UT_NATIVE];
int err = amx_GetNative(amx, native, name);
@ -274,16 +313,18 @@ static cell AMX_NATIVE_CALL invalid_native(AMX *amx, cell *params)
void CPluginMngr::CPlugin::Finalize()
{
char buffer[128];
int old_status = status;
if (CheckModules(&amx, buffer))
{
if ( amx_Register(&amx, core_Natives, -1) != AMX_ERR_NONE )
if (amx_Register(&amx, core_Natives, -1) != AMX_ERR_NONE)
{
Handler *pHandler = (Handler *)amx.userdata[UD_HANDLER];
int res = 0;
if (pHandler->IsNativeFiltering())
res = amx_CheckNatives(&amx, native_handler);
if (!res)
{
status = ps_bad_load;
@ -299,21 +340,23 @@ void CPluginMngr::CPlugin::Finalize()
errorMsg.assign(buffer);
amx.error = AMX_ERR_NOTFOUND;
}
if (old_status != status)
{
AMXXLOG_Log("[AMXX] Plugin \"%s\" failed to load: %s", name.c_str(), errorMsg.c_str());
}
}
void CPluginMngr::CPlugin::pauseFunction( int id )
void CPluginMngr::CPlugin::pauseFunction(int id)
{
}
void CPluginMngr::CPlugin::unpauseFunction( int id )
void CPluginMngr::CPlugin::unpauseFunction(int id)
{
}
void CPluginMngr::CPlugin::setStatus( int a ) {
void CPluginMngr::CPlugin::setStatus(int a)
{
status = a;
g_commands.clearBufforedInfo(); // ugly way
}
@ -337,8 +380,8 @@ void CPluginMngr::CPlugin::unpausePlugin()
if (isValid())
{
// set status first so the function will be marked executable
setStatus(ps_running);
// call plugin_unpause if provided
if (m_UnpauseFwd != -1)
executeForwards(m_UnpauseFwd);

View File

@ -59,19 +59,23 @@ public:
AMX amx;
void* code;
String name;
String version;
String title;
String author;
String errorMsg;
int m_PauseFwd;
int m_UnpauseFwd;
int paused_fun;
int status;
CPlugin* next;
int id;
CPlugin(int i, const char* p, const char* n, char* e, int d);
~CPlugin();
bool m_Debug;
public:
inline const char* getName() { return name.c_str();}
@ -90,12 +94,14 @@ public:
inline bool isValid() const { return (status >= ps_paused); }
inline bool isPaused() const { return ((status == ps_paused) || (status == ps_stopped)); }
inline bool isExecutable(int id) const { return (isValid() && !isPaused()); }
void Finalize();
void pausePlugin();
void unpausePlugin();
void pauseFunction(int id);
void unpauseFunction(int id);
void setStatus(int a);
const char* getStatus() const;
inline bool isDebug() const { return m_Debug; }
};
@ -115,10 +121,12 @@ public:
CPlugin* loadPlugin(const char* path, const char* name, char* error, int debug);
void unloadPlugin(CPlugin** a);
int loadPluginsFromFile(const char* filename);
CPlugin* findPluginFast(AMX *amx);
CPlugin* findPlugin(AMX *amx);
CPlugin* findPlugin(int index);
CPlugin* findPlugin(const char* name);
inline int getPluginsNum() const { return pCounter; }
void Finalize();
void clear();

View File

@ -45,14 +45,17 @@ public:
item = i;
next = n;
}
CQueueItem *GetNext()
{
return next;
}
T & GetItem()
{
return item;
}
void SetNext(CQueueItem *n)
{
next = n;
@ -71,7 +74,7 @@ public:
bool empty()
{
return ((mSize==0)?true:false);
return ((mSize == 0) ? true : false);
}
void push(const T &v)
@ -119,8 +122,8 @@ public:
private:
CQueueItem *mFirst;
CQueueItem *mLast;
unsigned int mSize;
};
#endif //_INCLUDE_CQUEUE_H

View File

@ -102,10 +102,10 @@ void CTaskMngr::CTask::clear()
m_iId = 0;
m_fBase = 0.0f;
m_iRepeat = 0;
m_bLoop = false;
m_iRepeat = 0;
m_bLoop = false;
m_bAfterStart = false;
m_bBeforeEnd = false;
m_bBeforeEnd = false;
m_fNextExecTime = 0.0f;
}
@ -189,10 +189,10 @@ CTaskMngr::CTask::CTask()
m_iId = 0;
m_fBase = 0.0f;
m_iRepeat = 0;
m_bLoop = false;
m_iRepeat = 0;
m_bLoop = false;
m_bAfterStart = false;
m_bBeforeEnd = false;
m_bBeforeEnd = false;
m_fNextExecTime = 0.0f;

View File

@ -39,15 +39,18 @@ private:
class CTask
{
// task settings
CPluginMngr::CPlugin *m_pPlugin;
int m_iId;
int m_iFunc;
int m_iRepeat;
bool m_bLoop;
bool m_bAfterStart;
bool m_bBeforeEnd;
float m_fBase; // for normal tasks, stores the interval, for the others, stores the amount of time before start / after end
int m_iParamLen;
cell *m_pParams;
bool m_bFree;
@ -91,15 +94,16 @@ private:
if (right.m_bFree)
return left.isFree();
return !left.isFree() && (right.m_pAmx ? left.getPlugin()->getAMX() == right.m_pAmx : true) &&
left.getTaskId() == right.m_iId;
return !left.isFree() && (right.m_pAmx ? left.getPlugin()->getAMX() == right.m_pAmx : true) && left.getTaskId() == right.m_iId;
}
};
/*** CTaskMngr priv members ***/
typedef CList<CTask, CTaskDescriptor> TaskList;
typedef TaskList::iterator TaskListIter;
TaskList m_Tasks;
float *m_pTmr_CurrentTime;
float *m_pTmr_TimeLimit;
float *m_pTmr_TimeLeft;
@ -109,9 +113,11 @@ public:
void registerTimers(float *pCurrentTime, float *pTimeLimit, float *pTimeLeft); // The timers will always point to the right value
void registerTask(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlags, int iId, float fBase, int iParamsLen, const cell *pParams, int iRepeat);
int removeTasks(int iId, AMX *pAmx); // remove all tasks that match the id and amx
int changeTasks(int iId, AMX *pAmx, float fNewBase); // change all tasks that match the id and amx
bool taskExists(int iId, AMX *pAmx);
void startFrame();
void clear();
};

View File

@ -117,7 +117,7 @@ void Vault::clear()
{
Obj* a = head->next;
delete head;
head = a;
head = a;
}
}

View File

@ -45,6 +45,7 @@ class Vault
{
String key;
String value;
int number;
Obj *next;
Obj(const char* k, const char* v);
@ -56,19 +57,23 @@ class Vault
public:
Vault() {head=0;}
~Vault() { clear();}
Vault() { head = 0; }
~Vault() { clear(); }
// Interface
bool exists(const char* k);
void put(const char* k, const char* v);
void remove(const char* k);
const char* get(const char* n);
int get_number(const char* n);
void setSource(const char* n);
bool loadVault();
bool saveVault();
void clear();
class iterator

File diff suppressed because it is too large Load Diff

View File

@ -32,20 +32,19 @@
#ifndef AMXMODX_H
#define AMXMODX_H
#ifdef __linux__
#include <unistd.h>
#include <stdlib.h>
#include "sclinux.h"
#endif
#include <ctype.h> //tolower, etc
#include <ctype.h> //tolower, etc
#include "string.h"
#include <extdll.h>
#include <meta_api.h>
#include "mm_pextensions.h" // metamod-p extensions
#include "mm_pextensions.h" // metamod-p extensions
#ifdef MEMORY_TEST
#include "mmgr/mmgr.h"
#include "mmgr/mmgr.h"
#endif
#include "md5.h"
@ -69,11 +68,11 @@
#include "amxxlog.h"
#define AMXXLOG_Log g_log.Log
#define AMX_VERSION "1.56"
#define AMX_VERSION "1.56"
extern AMX_NATIVE_INFO core_Natives[];
extern AMX_NATIVE_INFO time_Natives[];
extern AMX_NATIVE_INFO power_Natives[];
extern AMX_NATIVE_INFO core_Natives[];
extern AMX_NATIVE_INFO time_Natives[];
extern AMX_NATIVE_INFO power_Natives[];
extern AMX_NATIVE_INFO amxmodx_Natives[];
extern AMX_NATIVE_INFO file_Natives[];
extern AMX_NATIVE_INFO float_Natives[];
@ -82,18 +81,18 @@ extern AMX_NATIVE_INFO vault_Natives[];
#ifndef __linux__
#define DLLOAD(path) (DLHANDLE)LoadLibrary(path)
#define DLPROC(m,func) GetProcAddress(m,func)
#define DLPROC(m, func) GetProcAddress(m, func)
#define DLFREE(m) FreeLibrary(m)
#else
#define DLLOAD(path) (DLHANDLE)dlopen(path, RTLD_NOW)
#define DLPROC(m,func) dlsym(m,func)
#define DLPROC(m, func) dlsym(m, func)
#define DLFREE(m) dlclose(m)
#endif
#ifndef __linux__
typedef HINSTANCE DLHANDLE;
typedef HINSTANCE DLHANDLE;
#else
typedef void* DLHANDLE;
typedef void* DLHANDLE;
#endif
#ifndef GETPLAYERAUTHID
@ -109,31 +108,35 @@ typedef void* DLHANDLE;
char* UTIL_SplitHudMessage(register const char *src);
int UTIL_ReadFlags(const char* c);
void UTIL_ClientPrint( edict_t *pEntity, int msg_dest, char *msg );
void UTIL_ClientPrint(edict_t *pEntity, int msg_dest, char *msg);
void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1 = NULL, const char *arg2 = NULL);
void UTIL_GetFlags(char* flags,int flag);
void UTIL_GetFlags(char* flags, int flag);
void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pMessage);
void UTIL_IntToString(int value, char *output);
void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name);
void UTIL_ShowMenu( edict_t* pEntity, int slots, int time, char *menu, int mlen );
void UTIL_ShowMOTD(edict_t *client, char *motd, int mlen, const char *name);
void UTIL_ShowMenu(edict_t* pEntity, int slots, int time, char *menu, int mlen);
char *UTIL_VarArgs(const char *fmt, ...);
#define GET_PLAYER_POINTER(e) (&g_players[ENTINDEX(e)])
//#define GET_PLAYER_POINTER(e) (&g_players[(((int)e-g_edict_point)/sizeof(edict_t ))])
//#define GET_PLAYER_POINTER(e) (&g_players[(((int)e-g_edict_point)/sizeof(edict_t))])
#define GET_PLAYER_POINTER_I(i) (&g_players[i])
struct WeaponsVault {
String fullName;
short int iId;
short int ammoSlot;
struct WeaponsVault
{
String fullName;
short int iId;
short int ammoSlot;
};
struct fakecmd_t {
char args[256];
const char *argv[3];
int argc;
bool fake;
struct fakecmd_t
{
char args[256];
const char *argv[3];
int argc;
bool fake;
};
extern bool g_IsNewMM;
@ -148,8 +151,8 @@ extern CList<CCVar> g_cvars;
extern CList<ForceObject> g_forcemodels;
extern CList<ForceObject> g_forcesounds;
extern CList<ForceObject> g_forcegeneric;
extern CList<CModule,const char *> g_modules;
extern CList<CScript,AMX*> g_loadedscripts;
extern CList<CModule, const char *> g_modules;
extern CList<CScript, AMX*> g_loadedscripts;
extern CList<CPlayer*> g_auth;
extern EventsMngr g_events;
extern Grenades g_grenades;
@ -160,7 +163,7 @@ extern String g_log_dir;
extern String g_mod_name;
extern TeamIds g_teamsIds;
extern Vault g_vault;
extern CForwardMngr g_forwards;
extern CForwardMngr g_forwards;
extern WeaponsVault g_weaponsData[MAX_WEAPONS];
extern XVars g_xvars;
extern bool g_bmod_cstrike;
@ -224,14 +227,15 @@ void Client_DeathMsg(void*);
void amx_command();
void plugin_srvcmd();
const char* stristr(const char* a,const char* b);
const char* stristr(const char* a, const char* b);
char *strptime(const char *buf, const char *fmt, struct tm *tm, short addthem);
int loadModules(const char* filename, PLUG_LOADTIME now);
void detachModules();
void detachReloadModules();
#ifdef FAKEMETA
void attachModules();
void attachModules();
#endif
// Count modules
@ -245,40 +249,43 @@ enum CountModulesMode
int countModules(CountModulesMode mode);
void modules_callPluginsLoaded();
cell* get_amxaddr(AMX *amx,cell amx_addr);
char* build_pathname(char *fmt, ... );
cell* get_amxaddr(AMX *amx, cell amx_addr);
char* build_pathname(char *fmt, ...);
char* build_pathname_r(char *buffer, size_t maxlen, char *fmt, ...);
char* format_amxstring(AMX *amx, cell *params, int parm,int& len);
AMX* get_amxscript(int, void**,const char**);
char* format_amxstring(AMX *amx, cell *params, int parm, int& len);
AMX* get_amxscript(int, void**, const char**);
const char* get_amxscriptname(AMX* amx);
char* get_amxstring(AMX *amx,cell amx_addr,int id,int& len);
char* get_amxstring(AMX *amx, cell amx_addr, int id, int& len);
int amxstring_len(cell* cstr);
int load_amxscript(AMX* amx, void** program, const char* path, char error[64], int debug);
int set_amxnatives(AMX* amx,char error[64]);
int set_amxstring(AMX *amx,cell amx_addr,const char *source,int max);
int unload_amxscript(AMX* amx,void** program);
void copy_amxmemory(cell* dest,cell* src,int len);
int set_amxnatives(AMX* amx, char error[64]);
int set_amxstring(AMX *amx, cell amx_addr, const char *source, int max);
int unload_amxscript(AMX* amx, void** program);
void copy_amxmemory(cell* dest, cell* src, int len);
void get_modname(char*);
void print_srvconsole( char *fmt, ... );
void report_error( int code, char* fmt, ... );
void print_srvconsole(char *fmt, ...);
void report_error(int code, char* fmt, ...);
void* alloc_amxmemory(void**, int size);
void free_amxmemory(void **ptr);
// get_localinfo
const char* get_localinfo( const char* name , const char* def );
const char* get_localinfo(const char* name, const char* def);
cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params);
void LogError(AMX *amx, int err, const char *fmt, ...);
enum ModuleCallReason
{
ModuleCall_NotCalled = 0, // nothing
ModuleCall_Query, // in Query func
ModuleCall_Attach, // in Attach func
ModuleCall_Detach, // in Detach func
ModuleCall_NotCalled = 0, // nothing
ModuleCall_Query, // in Query func
ModuleCall_Attach, // in Attach func
ModuleCall_Detach, // in Detach func
};
extern ModuleCallReason g_ModuleCallReason; // modules.cpp
extern CModule *g_CurrentlyCalledModule; // modules.cpp
extern const char *g_LastRequestedFunc; // modules.cpp
void Module_CacheFunctions();
void Module_UncacheFunctions();
@ -301,7 +308,7 @@ extern int FF_ClientAuthorized;
extern bool g_coloredmenus;
#ifdef FAKEMETA
extern CFakeMeta g_FakeMeta;
extern CFakeMeta g_FakeMeta;
#endif
struct func_s
@ -311,4 +318,3 @@ struct func_s
};
#endif // AMXMODX_H

View File

@ -83,7 +83,6 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
m_Status = Err_None;
m_CellSize = cellsize;
m_pFile = fopen(filename, "rb");
if (!m_pFile)
@ -115,6 +114,7 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
m_Status = Err_OldFile;
fclose(m_pFile);
m_pFile = NULL;
return;
}
@ -151,6 +151,7 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
m_Status = Err_SectionNotFound;
fclose(m_pFile);
m_pFile = NULL;
return;
}
@ -275,6 +276,7 @@ size_t CAmxxReader::GetBufferSize()
AMX_HEADER hdr;
DATAREAD(&hdr, sizeof(hdr), 1);
fseek(m_pFile, save, SEEK_SET);
return hdr.stp;
}
else if (m_AmxxFile)

View File

@ -95,4 +95,3 @@ public:
};
#endif // __AMXXFILE_H__

View File

@ -86,6 +86,7 @@ void CLog::CloseFile()
void CLog::CreateNewFile()
{
CloseFile();
// build filename
time_t td;
time(&td);
@ -128,9 +129,9 @@ void CLog::MapChange()
// create dir if not existing
char file[256];
#ifdef __linux
mkdir(build_pathname_r(file, sizeof(file)-1,"%s", g_log_dir.c_str()), 0700);
mkdir(build_pathname_r(file, sizeof(file)-1, "%s", g_log_dir.c_str()), 0700);
#else
mkdir(build_pathname_r(file, sizeof(file)-1,"%s", g_log_dir.c_str()));
mkdir(build_pathname_r(file, sizeof(file)-1, "%s", g_log_dir.c_str()));
#endif
m_LogType = atoi(get_localinfo("amxx_logging", "1"));
@ -197,6 +198,7 @@ void CLog::Log(const char *fmt, ...)
build_pathname_r(file, sizeof(file)-1, "%s/L%02d%02d.log", g_log_dir.c_str(), curTime->tm_mon + 1, curTime->tm_mday);
pF = fopen(file, "a+");
}
if (pF)
{
fprintf(pF, "L %s: %s\n", date, msg);

View File

@ -42,6 +42,7 @@ private:
public:
CLog();
~CLog();
void CreateNewFile();
void CloseFile();
void MapChange();
@ -49,4 +50,3 @@ public:
};
#endif // __AMXXLOG_H__

View File

@ -47,24 +47,28 @@ public:
class Tracer
{
public:
struct trace_info
{
trace_info() : cip(0), frm(0), used(false), next(NULL), prev(NULL)
{
};
trace_info() : cip(0), frm(0), used(false), next(NULL), prev(NULL) {};
cell cip;
cell frm;
trace_info *next;
trace_info *prev;
bool used;
};
public:
Tracer() : m_Error(0), m_pStart(NULL), m_pEnd(NULL), m_Reset(true) { };
Tracer() : m_Error(0), m_pStart(NULL), m_pEnd(NULL), m_Reset(true) {};
~Tracer();
public:
void StepI(cell frm, cell cip);
void Reset();
void Clear();
Debugger::Tracer::trace_info *GetStart() const;
Debugger::Tracer::trace_info *GetEnd() const;
public:
@ -72,14 +76,15 @@ public:
private:
trace_info *m_pStart;
trace_info *m_pEnd;
bool m_Reset;
};
public:
Debugger(AMX *pAmx, AMX_DBG *pAmxDbg) :
m_pAmx(pAmx), m_pAmxDbg(pAmxDbg), m_Top(-1)
{
_CacheAmxOpcodeList();
};
Debugger(AMX *pAmx, AMX_DBG *pAmxDbg) : m_pAmx(pAmx), m_pAmxDbg(pAmxDbg), m_Top(-1)
{
_CacheAmxOpcodeList();
};
~Debugger();
public:
//Begin a trace for a function
@ -123,19 +128,24 @@ public:
public:
//generic static opcode breaker
static int AMXAPI DebugHook(AMX *amx);
static void FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLength);
static void GenericMessage(AMX *amx, int error);
private:
void _CacheAmxOpcodeList();
int _GetOpcodeFromCip(cell cip, cell *&addr);
cell _CipAsVa(cell cip);
const char *_GetFilename();
public:
AMX *m_pAmx;
AMX_DBG *m_pAmxDbg;
int m_Top;
cell *m_pOpcodeList;
String m_FileName;
CVector<Tracer *> m_pCalls;
};
@ -148,11 +158,8 @@ typedef Debugger::Tracer::trace_info trace_info_t;
class Handler
{
public:
Handler(AMX *pAmx) : m_pAmx(pAmx),
m_iErrFunc(-1), m_iModFunc(-1), m_iNatFunc(-1),
m_Handling(false), m_InNativeFilter(false)
{ };
~Handler() { };
Handler(AMX *pAmx) : m_pAmx(pAmx), m_iErrFunc(-1), m_iModFunc(-1), m_iNatFunc(-1), m_Handling(false), m_InNativeFilter(false) {};
~Handler() {};
public:
int SetErrorHandler(const char *function);
int SetNativeFilter(const char *function);
@ -164,21 +171,28 @@ public:
public:
bool IsHandling() const { return m_Handling; }
void SetErrorMsg(const char *msg);
const char *GetLastMsg();
trace_info_t *GetTrace() const { return m_pTrace; }
const char *GetFmtCache() { return m_FmtCache.c_str(); }
bool IsNativeFiltering() { return (m_iNatFunc > 0); }
bool InNativeFilter() { return m_InNativeFilter; }
private:
AMX *m_pAmx;
int m_iErrFunc;
int m_iModFunc;
int m_iNatFunc;
bool m_Handling;
//in the future, make this a stack!
bool m_InNativeFilter;
String m_MsgCache;
String m_FmtCache;
trace_info_t *m_pTrace;
};

View File

@ -62,7 +62,7 @@ class AutoFilePtr
FILE *m_FP;
public:
AutoFilePtr(FILE *fp) : m_FP(fp)
{ }
{}
~AutoFilePtr()
{
@ -87,6 +87,7 @@ static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
if ((dp = opendir (dirname)) == NULL)
return 0;
seekdir(dp, a);
if ((ep = readdir (dp)) != NULL)
@ -149,17 +150,22 @@ static cell AMX_NATIVE_CALL read_file(AMX *amx, cell *params) /* 5 param */
while ((i <= iLine) && fgets(buffor, 1023, fp))
i++;
fclose(fp);
if (i > iLine)
{
int len = strlen(buffor);
if (buffor[len - 1] == '\n')
buffor[--len] = 0;
if (buffor[len - 1] == '\r')
buffor[--len] = 0;
cell *length = get_amxaddr(amx, params[5]);
*length = set_amxstring(amx, params[3], buffor, params[4]);
return i;
}
@ -186,6 +192,7 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
fputs(sText, pFile);
fputc('\n', pFile);
fclose(pFile);
return 1;
}
@ -204,6 +211,7 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
fputs(sText, pFile);
fputc('\n', pFile);
fclose(pFile);
return 1;
}
@ -233,7 +241,8 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
{
fputc('\n', pTemp);
}
else break;
else
break;
}
fclose(pFile);
@ -259,6 +268,7 @@ static cell AMX_NATIVE_CALL delete_file(AMX *amx, cell *params) /* 1 param */
{
int iLen;
char* sFile = get_amxstring(amx, params[1], 0, iLen);
return (unlink(build_pathname("%s", sFile)) ? 0 : 1);
}
@ -270,17 +280,23 @@ static cell AMX_NATIVE_CALL file_exists(AMX *amx, cell *params) /* 1 param */
#if defined WIN32 || defined _WIN32
DWORD attr = GetFileAttributes(file);
if (attr == INVALID_FILE_ATTRIBUTES)
return 0;
if (attr == FILE_ATTRIBUTE_DIRECTORY)
return 0;
return 1;
#else
struct stat s;
if (stat(file, &s) != 0)
return 0;
if (S_ISDIR(s.st_mode))
return 0;
return 1;
#endif
}
@ -293,17 +309,23 @@ static cell AMX_NATIVE_CALL dir_exists(AMX *amx, cell *params) /* 1 param */
#if defined WIN32 || defined _WIN32
DWORD attr = GetFileAttributes(file);
if (attr == INVALID_FILE_ATTRIBUTES)
return 0;
if (attr == FILE_ATTRIBUTE_DIRECTORY)
return 1;
return 0;
#else
struct stat s;
if (stat(file, &s) != 0)
return 0;
if (S_ISDIR(s.st_mode))
return 1;
return 0;
#endif
}
@ -320,6 +342,7 @@ static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
{
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
return size;
}
else if (params[2] == 1)
@ -347,6 +370,7 @@ static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
if (fgetc(fp) == '\n')
return 1;
return 0;
}
}
@ -359,11 +383,12 @@ static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
static cell AMX_NATIVE_CALL amx_fopen(AMX *amx, cell *params)
{
unsigned int i;
int len, j=-1;
int len, j = -1;
char *file = build_pathname("%s", get_amxstring(amx, params[1], 1, len));
char *flags = get_amxstring(amx, params[2], 0, len);
FILE *fp = fopen(file, flags);
if (fp == NULL)
{
// Failed
@ -396,6 +421,7 @@ static cell AMX_NATIVE_CALL amx_fclose(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
@ -412,6 +438,7 @@ static cell AMX_NATIVE_CALL amx_fread(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
char *buffer;
@ -422,6 +449,7 @@ static cell AMX_NATIVE_CALL amx_fread(AMX *amx, cell *params)
fread(buffer, sizeof(char), params[3], fp);
set_amxstring(amx, params[2], buffer, params[3]);
delete [] buffer;
return 1;
}
@ -435,6 +463,7 @@ static cell AMX_NATIVE_CALL amx_fgetc(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
@ -451,6 +480,7 @@ static cell AMX_NATIVE_CALL amx_fwrite(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
char *buf;
int len;
@ -470,6 +500,7 @@ static cell AMX_NATIVE_CALL amx_feof(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
@ -490,6 +521,7 @@ static cell AMX_NATIVE_CALL amx_fseek(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
@ -506,6 +538,7 @@ static cell AMX_NATIVE_CALL amx_fputc(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
@ -522,6 +555,7 @@ static cell AMX_NATIVE_CALL amx_rewind(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
@ -539,6 +573,7 @@ static cell AMX_NATIVE_CALL amx_fflush(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
@ -555,6 +590,7 @@ static cell AMX_NATIVE_CALL amx_fscanf(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
char *buf;
@ -575,6 +611,7 @@ static cell AMX_NATIVE_CALL amx_ftell(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
@ -591,12 +628,14 @@ static cell AMX_NATIVE_CALL amx_filesize(AMX *amx, cell *params)
int len;
char *file = build_pathname("%s", format_amxstring(amx, params, 1, len));
long size;
AutoFilePtr fp(fopen(file, "rb"));
if (fp)
{
fseek(fp, 0, SEEK_END);
size = ftell(fp);
return size;
}
@ -610,6 +649,7 @@ static cell AMX_NATIVE_CALL amx_fgetl(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
long t;
@ -629,6 +669,7 @@ static cell AMX_NATIVE_CALL amx_fgeti(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
int t;
@ -648,6 +689,7 @@ static cell AMX_NATIVE_CALL amx_fgets(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
short t;
@ -667,6 +709,7 @@ static cell AMX_NATIVE_CALL amx_fputs(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
short size = params[2];
@ -685,6 +728,7 @@ static cell AMX_NATIVE_CALL amx_fputl(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
long size = params[2];
@ -703,6 +747,7 @@ static cell AMX_NATIVE_CALL amx_fputi(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
int size = params[2];
@ -721,6 +766,7 @@ static cell AMX_NATIVE_CALL amx_fgetf(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
float t;
@ -740,6 +786,7 @@ static cell AMX_NATIVE_CALL amx_fputf(AMX *amx, cell *params)
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
float size = *(float *)((void *)&params[2]);
@ -757,6 +804,7 @@ static cell AMX_NATIVE_CALL amx_build_pathname(AMX *amx, cell *params)
{
int len;
char *szPath = get_amxstring(amx, params[1], 0, len);
return set_amxstring(amx, params[2], build_pathname("%s", szPath), params[3]);
}
@ -767,11 +815,13 @@ static cell AMX_NATIVE_CALL amx_open_dir(AMX *amx, cell *params)
#if defined WIN32 || defined _WIN32
char *dirname = build_pathname("%s\\*", path);
WIN32_FIND_DATA fd;
HANDLE hFile = FindFirstFile(dirname, &fd);
if (hFile == INVALID_HANDLE_VALUE)
return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]);
return (DWORD)hFile;
@ -802,6 +852,7 @@ static cell AMX_NATIVE_CALL amx_close_dir(AMX *amx, cell *params)
if (hFile == INVALID_HANDLE_VALUE || hFile == NULL)
return 0;
FindClose(hFile);
return 1;
@ -823,10 +874,12 @@ static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params)
if (hFile == INVALID_HANDLE_VALUE || hFile == NULL)
return 0;
WIN32_FIND_DATA fd;
if (!FindNextFile(hFile, &fd))
return 0;
return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]);
return 1;
@ -839,6 +892,7 @@ static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params)
if (!ep)
return 0;
set_amxstring(amx, params[2], ep->d_name, params[3]);
return 1;
@ -849,9 +903,9 @@ AMX_NATIVE_INFO file_Natives[] =
{
{"delete_file", delete_file},
{"file_exists", file_exists},
{"file_size", file_size},
{"read_dir", read_dir},
{"read_file", read_file},
{"file_size", file_size},
{"read_dir", read_dir},
{"read_file", read_file},
{"write_file", write_file},
//Sanji's File Natives
{"fopen", amx_fopen},

View File

@ -30,9 +30,11 @@
*/
#include <time.h>
#if defined WIN32
#include <direct.h>
#endif
#include "amxmodx.h"
#include "fakemeta.h"
#include "newmenus.h"
@ -60,6 +62,7 @@ pextension_funcs_t *gpMetaPExtFuncs;
funEventCall modMsgsEnd[MAX_REG_MSGS];
funEventCall modMsgs[MAX_REG_MSGS];
void (*function)(void*);
void (*endfunction)(void*);
@ -75,6 +78,7 @@ CPlayer* mPlayer;
CPluginMngr g_plugins;
CTaskMngr g_tasksMngr;
CmdMngr g_commands;
EventsMngr g_events;
Grenades g_grenades;
LogEventsMngr g_logevents;
@ -83,16 +87,20 @@ CLangMngr g_langMngr;
String g_log_dir;
String g_mod_name;
XVars g_xvars;
bool g_bmod_cstrike;
bool g_bmod_dod;
bool g_dontprecache;
bool g_forcedmodules;
bool g_forcedsounds;
fakecmd_t g_fakecmd;
float g_game_restarting;
float g_game_timeleft;
float g_task_time;
float g_auth_time;
bool g_initialized = false;
bool g_IsNewMM = false;
bool g_NeedsP = false;
@ -239,8 +247,8 @@ int C_Spawn(edict_t *pent)
// ###### Load lang
char file[256];
g_langMngr.LoadCache(build_pathname_r(file, sizeof(file)-1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.Load(build_pathname_r(file, sizeof(file)-1, "%s/languages.dat", get_localinfo("amxmodx_datadir", "addons/amxmodx/data")));
g_langMngr.LoadCache(build_pathname_r(file, sizeof(file) - 1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.Load(build_pathname_r(file, sizeof(file) - 1, "%s/languages.dat", get_localinfo("amxmodx_datadir", "addons/amxmodx/data")));
// ###### Initialize commands prefixes
g_commands.registerPrefix("amx");
@ -260,6 +268,7 @@ int C_Spawn(edict_t *pent)
// ###### Load modules
loadModules(get_localinfo("amxx_modules", "addons/amxmodx/configs/modules.ini"), PT_ANYTIME);
int loaded = countModules(CountModules_Running); // Call after attachModules so all modules don't have pending stat
// Set some info about amx version and modules
CVAR_SET_STRING(init_amxmodx_version.name, AMX_VERSION);
char buffer[32];
@ -267,7 +276,7 @@ int C_Spawn(edict_t *pent)
CVAR_SET_STRING(init_amxmodx_modules.name, buffer);
// ###### Load Vault
g_vault.setSource(build_pathname_r(file, sizeof(file)-1, "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini")));
g_vault.setSource(build_pathname_r(file, sizeof(file) - 1, "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini")));
g_vault.loadVault();
if (strlen(g_vault.get("server_language")) < 1)
@ -280,11 +289,9 @@ int C_Spawn(edict_t *pent)
g_game_timeleft = g_bmod_dod ? 1.0f : 0.0f;
g_task_time = gpGlobals->time + 99999.0f;
g_auth_time = gpGlobals->time + 99999.0f;
#ifdef MEMORY_TEST
g_next_memreport_time = gpGlobals->time + 99999.0f;
#endif
g_players_num = 0;
// Set server flags
@ -424,8 +431,8 @@ void C_ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax)
// ###### Save lang
char file[256];
g_langMngr.Save(build_pathname_r(file, sizeof(file)-1, "%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.SaveCache(build_pathname_r(file, sizeof(file)-1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.Save(build_pathname_r(file, sizeof(file) - 1, "%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.SaveCache(build_pathname_r(file, sizeof(file) - 1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
// Correct time in Counter-Strike and other mods (except DOD)
if (!g_bmod_dod)
@ -494,9 +501,11 @@ void C_ServerDeactivate_Post()
g_xvars.clear();
g_plugins.clear();
ClearPluginLibraries();
char file[256];
g_langMngr.Save(build_pathname_r(file, sizeof(file)-1, "%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.SaveCache(build_pathname_r(file, sizeof(file)-1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.Save(build_pathname_r(file, sizeof(file) - 1, "%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.SaveCache(build_pathname_r(file, sizeof(file) - 1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.Clear();
// last memreport
@ -540,12 +549,15 @@ void C_ServerDeactivate_Post()
}
}
g_memreport_dir.assign(buffer);
// g_memreport_dir should be valid now
break;
}
}
m_dumpMemoryReport(build_pathname("%s/r%03d.txt", g_memreport_dir.c_str(), g_memreport_count));
AMXXLOG_Log("Memreport #%d created (file \"%s/r%03d.txt\") (interval %f)", g_memreport_count + 1, g_memreport_dir.c_str(), g_memreport_count, MEMREPORT_INTERVAL);
g_memreport_count++;
}
#endif // MEMORY_TEST
@ -614,7 +626,7 @@ void C_ClientUserInfoChanged_Post(edict_t *pEntity, char *infobuffer)
// Emulate bot connection and putinserver
if (pPlayer->ingame)
{
pPlayer->name.assign(name); // Make sure player have name up to date
pPlayer->name.assign(name); // Make sure player have name up to date
}
else if (pPlayer->IsBot())
{
@ -637,8 +649,10 @@ void C_ClientUserInfoChanged_Post(edict_t *pEntity, char *infobuffer)
void C_ClientCommand(edict_t *pEntity)
{
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
META_RES result = MRES_IGNORED;
cell ret = 0;
const char* cmd = CMD_ARGV(0);
const char* arg = CMD_ARGV(1);
@ -649,6 +663,7 @@ void C_ClientCommand(edict_t *pEntity)
{
// Print version
static char buf[1024];
sprintf(buf, "%s %s\n", Plugin_info.name, Plugin_info.version);
CLIENT_PRINT(pEntity, print_console, buf);
sprintf(buf, "Authors: %s (%s)\n", "Felix \"SniperBeamer\" Geyer, David \"BAILOPAN\" Anderson, Pavol \"PM OnoTo\" Marko, Jonny \"Got His Gun\" Bergstrom, and Lukasz \"SidLuke\" Wlasinski.", Plugin_info.url);
@ -675,7 +690,9 @@ void C_ClientCommand(edict_t *pEntity)
/* check for command and if needed also for first argument and call proper function */
CmdMngr::iterator aa = g_commands.clcmdprefixbegin(cmd);
if (!aa) aa = g_commands.clcmdbegin();
if (!aa)
aa = g_commands.clcmdbegin();
while (aa)
{
@ -717,14 +734,15 @@ void C_ClientCommand(edict_t *pEntity)
int item = pMenu->PagekeyToItem(pPlayer->page, pressed_key);
ret = executeForwards((*a).getFunction(), pPlayer->index, menu, item);
if (ret & 2) result = MRES_SUPERCEDE;
else
if (ret & 1) RETURN_META(MRES_SUPERCEDE);
if (ret & 2)
result = MRES_SUPERCEDE;
else if (ret & 1)
RETURN_META(MRES_SUPERCEDE);
else
{
if (item == MENU_BACK)
{
pMenu->Display(pPlayer->index, pPlayer->page-1);
pMenu->Display(pPlayer->index, pPlayer->page - 1);
}
else if (item == MENU_MORE)
{
@ -774,6 +792,7 @@ void C_StartFrame_Post(void)
(*a)->Authorize();
executeForwards(FF_ClientAuthorized, (*a)->index);
a.remove();
continue;
}
++a;
@ -791,6 +810,7 @@ void C_StartFrame_Post(void)
time_t td;
time(&td);
tm *curTime = localtime(&td);
int i = 0;
#ifdef __linux__
mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")), 0700);
@ -826,8 +846,10 @@ void C_StartFrame_Post(void)
break;
}
}
m_dumpMemoryReport(build_pathname("%s/r%03d.txt", g_memreport_dir.c_str(), g_memreport_count));
AMXXLOG_Log("Memreport #%d created (file \"%s/r%03d.txt\") (interval %f)", g_memreport_count + 1, g_memreport_dir.c_str(), g_memreport_count, MEMREPORT_INTERVAL);
g_memreport_count++;
}
#endif // MEMORY_TEST
@ -836,7 +858,6 @@ void C_StartFrame_Post(void)
RETURN_META(MRES_IGNORED);
g_task_time = gpGlobals->time + 0.1f;
g_tasksMngr.startFrame();
// Dispatch client cvar queries
@ -870,6 +891,7 @@ void C_MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict
int *z = (int*)ptr + 0x16C;
#endif
int stop = (int)ed->v.armorvalue;
*z = stop;
ed->v.armorvalue = (float)stop;
}
@ -885,8 +907,9 @@ void C_MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict
msg_type = 0;
mState = 0;
function=modMsgs[msg_type];
endfunction=modMsgsEnd[msg_type];
function = modMsgs[msg_type];
endfunction = modMsgsEnd[msg_type];
g_events.parserInit(msg_type, &gpGlobals->time, mPlayer, mPlayerIndex);
RETURN_META(MRES_IGNORED);
@ -970,6 +993,7 @@ void C_ChangeLevel(char* s1, char* s2)
{
int retVal = 0;
char *map = s1;
retVal = executeForwards(FF_ChangeLevel, map);
if (retVal)
@ -1054,9 +1078,9 @@ void C_AlertMessage_Post(ALERT_TYPE atype, char *szFmt, ...)
if (g_logevents.logEventsExist() || FF_PluginLog >= 0)
{
va_list logArgPtr;
va_start (logArgPtr, szFmt);
va_start(logArgPtr, szFmt);
g_logevents.setLogString(szFmt, logArgPtr);
va_end (logArgPtr);
va_end(logArgPtr);
g_logevents.parseLogString();
if (g_logevents.logEventsExist())
@ -1107,14 +1131,15 @@ bool m_NeedsP = false;
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{
gpMetaUtilFuncs=pMetaUtilFuncs;
*pPlugInfo=&Plugin_info;
gpMetaUtilFuncs = pMetaUtilFuncs;
*pPlugInfo = &Plugin_info;
if (strcmp(ifvers, Plugin_info.ifvers))
{
int mmajor = 0, mminor = 0, pmajor = 0, pminor = 0;
LOG_MESSAGE(PLID, "WARNING: meta-interface version mismatch; requested=%s ours=%s", Plugin_info.logtag, ifvers);
sscanf(ifvers, "%d:%d", &mmajor, &mminor);
sscanf(META_INTERFACE_VERSION, "%d:%d", &pmajor, &pminor);
@ -1203,7 +1228,7 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
return (FALSE);
}
gpMetaGlobals=pMGlobals;
gpMetaGlobals = pMGlobals;
gMetaFunctionTable.pfnGetEntityAPI2 = GetEntityAPI2;
gMetaFunctionTable.pfnGetEntityAPI2_Post = GetEntityAPI2_Post;
gMetaFunctionTable.pfnGetEngineFunctions = GetEngineFunctions;
@ -1222,7 +1247,9 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
CVAR_REGISTER(&init_amxmodx_version);
CVAR_REGISTER(&init_amxmodx_modules);
CVAR_REGISTER(&init_amxmodx_debug);
amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name);
REG_SVR_COMMAND("amxx", amx_command);
char gameDir[512];
@ -1236,9 +1263,7 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
g_mod_name.assign(a);
if (g_mod_name.compare("cstrike") == 0 ||
g_mod_name.compare("czero") == 0 ||
g_mod_name.compare("dod") == 0)
if (g_mod_name.compare("cstrike") == 0 || g_mod_name.compare("czero") == 0 || g_mod_name.compare("dod") == 0)
g_coloredmenus = true;
else
g_coloredmenus = false;
@ -1499,9 +1524,7 @@ C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *in
#endif
}
#ifdef FAKEMETA
NEW_DLL_FUNCTIONS gNewDLLFunctionTable_Post;
C_DLLEXPORT int GetNewDLLFunctions_Post(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion)
{
@ -1509,5 +1532,4 @@ C_DLLEXPORT int GetNewDLLFunctions_Post(NEW_DLL_FUNCTIONS *pNewFunctionTable, in
memcpy(pNewFunctionTable, &gNewDLLFunctionTable_Post, sizeof(NEW_DLL_FUNCTIONS));
return 1;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,7 @@
#undef DLLEXPORT
#ifndef __linux__
#define DLLEXPORT __declspec(dllexport)
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#define WINAPI

View File

@ -37,6 +37,7 @@ void ClearMenus()
{
for (size_t i = 0; i < g_NewMenus.size(); i++)
delete g_NewMenus[i];
g_NewMenus.clear();
}
@ -51,6 +52,7 @@ Menu::~Menu()
{
for (size_t i = 0; i < m_Items.size(); i++)
delete m_Items[i];
m_Items.clear();
}
@ -110,6 +112,7 @@ int Menu::PagekeyToItem(page_t page, item_t key)
if (page == 0)
{
item_t rem = numItems >= 7 ? 7 : numItems;
if (key == rem)
{
if (pages > 1)
@ -188,6 +191,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
_snprintf(buffer, sizeof(buffer)-1, "\\y%s %d/%d\n\\w\n", m_Title.c_str(), page + 1, pages);
else
_snprintf(buffer, sizeof(buffer)-1, "%s %d/%d\n\n", m_Title.c_str(), page + 1, pages);
m_Text.append(buffer);
item_t start = page * 7;
@ -200,15 +204,19 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
}
menuitem *pItem = NULL;
int option = 0;
keys = 0;
bool enabled = true;
int ret = 0;
for (item_t i = start; i < end; i++)
{
pItem = m_Items[i];
if (pItem->access && !(pItem->access & g_players[player].flags[0]))
enabled = false;
if (pItem->handler != -1)
{
ret = executeForwards(pItem->handler, player, thisId, i);
@ -217,6 +225,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
else if (ret == ITEM_DISABLED)
enabled = false;
}
if (pItem->pfn)
{
ret = (pItem->pfn)(player, thisId, i);
@ -225,6 +234,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
else if (ret == ITEM_DISABLED)
enabled = false;
}
if (enabled)
{
keys |= (1<<option);
@ -240,6 +250,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
}
m_Text.append(buffer);
}
//now for a weird part >:o
//this will either be MORE or BACK..
keys |= (1<<option++);
@ -249,7 +260,9 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
} else {
_snprintf(buffer, sizeof(buffer)-1, "%d. %s\n", option, "Exit");
}
m_Text.append(buffer);
if (pages > 1)
{
keys |= (1<<option++);
@ -279,6 +292,7 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params)
char *handler = get_amxstring(amx, params[2], 1, len);
int func = registerSPForwardByName(amx, handler, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
if (func == -1)
{
LogError(amx, AMX_ERR_NOTFOUND, "Invalid function \"%s\"", handler);
@ -286,7 +300,7 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params)
}
int id = g_menucmds.registerMenuId(title, amx);
g_menucmds.registerMenuCmd( g_plugins.findPluginFast(amx), id, 1023, func );
g_menucmds.registerMenuCmd(g_plugins.findPluginFast(amx), id, 1023, func);
Menu *pMenu = new Menu(title, id, (int)g_NewMenus.size());
g_NewMenus.push_back(pMenu);
@ -403,54 +417,54 @@ static cell AMX_NATIVE_CALL menu_makecallback(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL menu_item_setname(AMX *amx, cell *params)
{
GETMENU(params[1]);
GETMENU(params[1]);
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
if (!pItem)
return 0;
if (!pItem)
return 0;
int len;
char *name;
int len;
char *name;
name = get_amxstring(amx, params[3], 0, len);
name = get_amxstring(amx, params[3], 0, len);
pItem->name.assign(name);
pItem->name.assign(name);
return 1;
return 1;
}
static cell AMX_NATIVE_CALL menu_item_setcmd(AMX *amx, cell *params)
{
GETMENU(params[1]);
GETMENU(params[1]);
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
if (!pItem)
return 0;
if (!pItem)
return 0;
int len;
char *cmd;
int len;
char *cmd;
cmd = get_amxstring(amx, params[3], 0, len);
cmd = get_amxstring(amx, params[3], 0, len);
pItem->cmd.assign(cmd);
pItem->cmd.assign(cmd);
return 1;
return 1;
}
static cell AMX_NATIVE_CALL menu_item_setcall(AMX *amx, cell *params)
{
GETMENU(params[1]);
GETMENU(params[1]);
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
if (!pItem)
return 0;
if (!pItem)
return 0;
pItem->handler = params[3];
pItem->handler = params[3];
return 1;
return 1;
}
AMX_NATIVE_INFO g_NewMenuNatives[] =

View File

@ -47,8 +47,10 @@ struct menuitem
{
String name;
String cmd;
int access;
int handler;
MENUITEM_CALLBACK pfn;
size_t id;
};
@ -62,18 +64,23 @@ class Menu
public:
Menu(const char *title, int menuId, int thisId);
~Menu();
menuitem *GetMenuItem(item_t item);
size_t GetPageCount();
size_t GetItemCount();
menuitem *AddItem(const char *name, const char *cmd, int access);
const char *GetTextString(int player, page_t page, int &keys);
bool Display(int player, page_t page);
int PagekeyToItem(page_t page, item_t key);
int GetMenuMenuid();
private:
CVector<menuitem * > m_Items;
String m_Title;
String m_Text;
int menuId;
int thisId;
};

View File

@ -107,7 +107,6 @@ void copy_amxmemory(cell* dest, cell* src, int len)
*dest++=*src++;
}
char* parse_arg(char** line, int& state)
{
static char arg[3072];
@ -150,9 +149,11 @@ char* parse_arg(char** line, int& state)
static cell AMX_NATIVE_CALL replace(AMX *amx, cell *params) /* 4 param */
{
static char buffor[3072];
cell *a = get_amxaddr(amx, params[1]);
cell *b = get_amxaddr(amx, params[3]);
cell *c = get_amxaddr(amx, params[4]);
int iMain = amxstring_len(a);
int iWhat = amxstring_len(b);
int iWith = amxstring_len(c);
@ -264,6 +265,7 @@ static cell AMX_NATIVE_CALL numtostr(AMX *amx, cell *params) /* 3 param */
{
char szTemp[32];
sprintf(szTemp, "%d", (int)params[1]);
return set_amxstring(amx, params[2], szTemp, params[3]);
}
@ -328,6 +330,7 @@ static cell AMX_NATIVE_CALL float_to_str(AMX *amx, cell *params)
{
char szTemp[32];
sprintf(szTemp, "%f", amx_ctof(params[1]));
return set_amxstring(amx, params[2], szTemp, params[3]);
}
@ -408,7 +411,7 @@ static cell AMX_NATIVE_CALL equal(AMX *amx, cell *params) /* 3 param */
{
while (--c && *a && (*a == *b))
++a, ++b;
return (*a-*b)?0:1;
return (*a-*b) ? 0 : 1;
}
int ret;
@ -511,6 +514,7 @@ int fo_numargs(AMX *amx)
{
unsigned char *data = amx->base + (int)((AMX_HEADER *)amx->base)->dat;
cell bytes= *(cell *)(data + (int)amx->frm + 2 * sizeof(cell));
return (int)(bytes / sizeof(cell));
}
@ -518,6 +522,7 @@ int fo_getargnum(AMX *amx, int pos)
{
unsigned char *data = amx->base + (int)((AMX_HEADER *)amx->base)->dat;
cell value = *(cell *)(data + (int)amx->frm + (pos + 3) * sizeof(cell));
return *(cell *)(data + (int)value);
}
@ -526,6 +531,7 @@ float fo_getargfloat(AMX *amx, int pos)
unsigned char *data = amx->base + (int)((AMX_HEADER *)amx->base)->dat;
cell value = *(cell *)(data + (int)amx->frm + (pos + 3) * sizeof(cell));
cell number = *(cell *)(data + (int)value);
return *(REAL *)((void *)&number);
}
@ -577,7 +583,7 @@ char* format_arguments(AMX *amx, int parm, int& len)
switch (*(ptr - 1))
{
case 's': sprintf(arg, format, fo_getargstr(amx, 1, parm++)); break;
case 's': sprintf(arg, format, fo_getargstr(amx, 1, parm++)); break;
case 'f': case 'g': sprintf(arg, format, fo_getargfloat(amx, parm++)); break;
default: sprintf(arg, format, fo_getargnum(amx, parm++));
}
@ -741,6 +747,7 @@ static cell AMX_NATIVE_CALL format_args(AMX *amx, cell *params)
}
char* string = format_arguments(amx, pos, len); // indexed from 0
return set_amxstring(amx, params[1], string, params[2]);
}
@ -878,37 +885,37 @@ static cell AMX_NATIVE_CALL n_strfind(AMX *amx, cell *params)
AMX_NATIVE_INFO string_Natives[] =
{
{"add", add},
{"contain", contain},
{"containi", containi},
{"copy", copy},
{"copyc", copyc},
{"equal", equal},
{"equali", equali},
{"format", format},
{"format_args", format_args},
{"isdigit", is_digit},
{"isalnum", is_alnum},
{"isspace", is_space},
{"isalpha", is_alpha},
{"num_to_str", numtostr},
{"numtostr", numtostr},
{"parse", parse},
{"replace", replace},
{"setc", setc},
{"strbreak", strbreak},
{"strtolower", strtolower},
{"strtoupper", strtoupper},
{"str_to_num", strtonum},
{"strtonum", strtonum},
{"trim", amx_trim},
{"ucfirst", amx_ucfirst},
{"strtok", amx_strtok},
{"strlen", amx_strlen},
{"strcat", n_strcat},
{"strfind", n_strfind},
{"strcmp", n_strcmp},
{"add", add},
{"contain", contain},
{"containi", containi},
{"copy", copy},
{"copyc", copyc},
{"equal", equal},
{"equali", equali},
{"format", format},
{"format_args", format_args},
{"isdigit", is_digit},
{"isalnum", is_alnum},
{"isspace", is_space},
{"isalpha", is_alpha},
{"num_to_str", numtostr},
{"numtostr", numtostr},
{"parse", parse},
{"replace", replace},
{"setc", setc},
{"strbreak", strbreak},
{"strtolower", strtolower},
{"strtoupper", strtoupper},
{"str_to_num", strtonum},
{"strtonum", strtonum},
{"trim", amx_trim},
{"ucfirst", amx_ucfirst},
{"strtok", amx_strtok},
{"strlen", amx_strlen},
{"strcat", n_strcat},
{"strfind", n_strfind},
{"strcmp", n_strcmp},
{"str_to_float", str_to_float},
{"float_to_str", float_to_str},
{NULL, NULL }
{NULL, NULL}
};

View File

@ -159,7 +159,7 @@ void UTIL_IntToString(int value, char *output)
{
aaa += sprintf(&output[aaa], words[tho]);
aaa += sprintf(&output[aaa], words[29]);
value = value % 1000;
value = value % 1000;
}
int hun = value / 100;
@ -168,7 +168,7 @@ void UTIL_IntToString(int value, char *output)
{
aaa += sprintf(&output[aaa], words[hun]);
aaa += sprintf(&output[aaa], words[28]);
value = value % 100;
value = value % 100;
}
int ten = value / 10;