diff --git a/amxmodx/CCmd.cpp b/amxmodx/CCmd.cpp index 46ef717c..0d121839 100755 --- a/amxmodx/CCmd.cpp +++ b/amxmodx/CCmd.cpp @@ -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); } diff --git a/amxmodx/CCmd.h b/amxmodx/CCmd.h index dd78939b..51e047ad 100755 --- a/amxmodx/CCmd.h +++ b/amxmodx/CCmd.h @@ -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; diff --git a/amxmodx/CEvent.cpp b/amxmodx/CEvent.cpp index 073eb02b..9093d34a 100755 --- a/amxmodx/CEvent.cpp +++ b/amxmodx/CEvent.cpp @@ -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 } diff --git a/amxmodx/CEvent.h b/amxmodx/CEvent.h index b9ffc106..89472bf0 100755 --- a/amxmodx/CEvent.h +++ b/amxmodx/CEvent.h @@ -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; diff --git a/amxmodx/CFile.h b/amxmodx/CFile.h index 068b332e..bf49d441 100755 --- a/amxmodx/CFile.h +++ b/amxmodx/CFile.h @@ -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(); }; diff --git a/amxmodx/CForward.cpp b/amxmodx/CForward.cpp index 4e91be10..74d023a0 100755 --- a/amxmodx/CForward.cpp +++ b/amxmodx/CForward.cpp @@ -15,12 +15,12 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, +* along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL -* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception @@ -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(params[i]))+1 : STRINGEX_MAXLENGTH, - &realParams[i], &tmp); + amx_Allot(iter->pPlugin->getAMX(), (m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast(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(*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(*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(params[i]))+1 : STRINGEX_MAXLENGTH, - &realParams[i], &tmp); + amx_Allot(m_Amx, (m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast(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(*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(*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(id >> 1) < m_SPForwards.size()) : - (static_cast(id >> 1) < m_Forwards.size())); + return (id >= 0) && ((id & 1) ? (static_cast(id >> 1) < m_SPForwards.size()) : (static_cast(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; diff --git a/amxmodx/CForward.h b/amxmodx/CForward.h index 0f87fd20..759b3959 100755 --- a/amxmodx/CForward.h +++ b/amxmodx/CForward.h @@ -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 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 - diff --git a/amxmodx/CLang.cpp b/amxmodx/CLang.cpp index d39de8bb..8d126643 100755 --- a/amxmodx/CLang.cpp +++ b/amxmodx/CLang.cpp @@ -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 &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); diff --git a/amxmodx/CLang.h b/amxmodx/CLang.h index fefe09d4..b46f19e8 100755 --- a/amxmodx/CLang.h +++ b/amxmodx/CLang.h @@ -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 diff --git a/amxmodx/CList.h b/amxmodx/CList.h index f4ebd1e9..fe906765 100755 --- a/amxmodx/CList.h +++ b/amxmodx/CList.h @@ -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 class + // CList 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; - CList *m_pList; // The list that created this iterator + friend class CList; + + CList *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 *pList, CElement *startPos) + iterator(CList *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() + CList() { m_pHead = NULL; m_pTail = NULL; } - ~CList() + ~CList() { 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(); diff --git a/amxmodx/CLogEvent.cpp b/amxmodx/CLogEvent.cpp index 1a350104..4fcc3bb8 100755 --- a/amxmodx/CLogEvent.cpp +++ b/amxmodx/CLogEvent.cpp @@ -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()); } @@ -64,14 +66,17 @@ LogEventsMngr::CLogCmp* LogEventsMngr::registerCondition(char* filter) { char* temp = filter; // expand "1=message" - + while (isdigit(*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,15 +193,17 @@ 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) { valid = true; @@ -214,7 +229,7 @@ void LogEventsMngr::executeLogEvents() { executeForwards(a->func); } - } + } } void LogEventsMngr::clearLogEvents() @@ -247,7 +262,7 @@ void LogEventsMngr::clearConditions() } LogEventsMngr::CLogEvent::LogCond::~LogCond() -{ +{ while (list) { LogCondEle* cc = list->next; diff --git a/amxmodx/CLogEvent.h b/amxmodx/CLogEvent.h index ff7a58fc..c54d3331 100755 --- a/amxmodx/CLogEvent.h +++ b/amxmodx/CLogEvent.h @@ -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,16 +157,16 @@ 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++() { a = b->getValidLogEvent(a->next); return *this; } - + 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; } }; diff --git a/amxmodx/CMenu.cpp b/amxmodx/CMenu.cpp index 13fd69c1..2ed7a2ef 100755 --- a/amxmodx/CMenu.cpp +++ b/amxmodx/CMenu.cpp @@ -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) diff --git a/amxmodx/CMenu.h b/amxmodx/CMenu.h index 1f10c21c..28d80dc0 100755 --- a/amxmodx/CMenu.h +++ b/amxmodx/CMenu.h @@ -43,6 +43,7 @@ class MenuMngr String name; AMX* amx; MenuIdEle* next; + int id; static int uniqueid; @@ -62,11 +63,12 @@ private: { friend class iterator; friend class MenuMngr; - + CPluginMngr::CPlugin *plugin; int menuid; int keys; int function; + MenuCommand* next; MenuCommand(CPluginMngr::CPlugin *a, int mi, int k, int f); public: diff --git a/amxmodx/CMisc.cpp b/amxmodx/CMisc.cpp index 339b3037..7fafb574 100755 --- a/amxmodx/CMisc.cpp +++ b/amxmodx/CMisc.cpp @@ -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); } diff --git a/amxmodx/CMisc.h b/amxmodx/CMisc.h index a5ec5d79..68b38218 100755 --- a/amxmodx/CMisc.h +++ b/amxmodx/CMisc.h @@ -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; } }; @@ -195,15 +197,17 @@ class XVars AMX* amx; cell* value; }; - + 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); @@ -211,7 +215,7 @@ public: { return (a >= 0 && a < num) ? *(head[a].value) : 0; } - + inline int setValue(int a, cell v) { if (a >= 0 && a < num) @@ -219,7 +223,7 @@ public: *(head[a].value) = v; return 0; } - + return 1; } }; @@ -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); diff --git a/amxmodx/CModule.cpp b/amxmodx/CModule.cpp index 1c833d90..fb348800 100755 --- a/amxmodx/CModule.cpp +++ b/amxmodx/CModule.cpp @@ -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; } diff --git a/amxmodx/CModule.h b/amxmodx/CModule.h index 262cb3a6..63910bae 100755 --- a/amxmodx/CModule.h +++ b/amxmodx/CModule.h @@ -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 m_Natives; diff --git a/amxmodx/CPlugin.cpp b/amxmodx/CPlugin.cpp index 2acbb670..8213c54f 100755 --- a/amxmodx/CPlugin.cpp +++ b/amxmodx/CPlugin.cpp @@ -15,12 +15,12 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, +* along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL -* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception @@ -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(); - 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); diff --git a/amxmodx/CPlugin.h b/amxmodx/CPlugin.h index 48bb415a..57c324c2 100755 --- a/amxmodx/CPlugin.h +++ b/amxmodx/CPlugin.h @@ -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(); diff --git a/amxmodx/CQueue.h b/amxmodx/CQueue.h index 44285185..fbb8f8b1 100755 --- a/amxmodx/CQueue.h +++ b/amxmodx/CQueue.h @@ -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 - diff --git a/amxmodx/CTask.cpp b/amxmodx/CTask.cpp index 923da559..b4e47c3c 100755 --- a/amxmodx/CTask.cpp +++ b/amxmodx/CTask.cpp @@ -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; diff --git a/amxmodx/CTask.h b/amxmodx/CTask.h index 2082951f..ebe1dc48 100755 --- a/amxmodx/CTask.h +++ b/amxmodx/CTask.h @@ -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 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(); }; diff --git a/amxmodx/CVault.cpp b/amxmodx/CVault.cpp index 67e2a929..66fd2833 100755 --- a/amxmodx/CVault.cpp +++ b/amxmodx/CVault.cpp @@ -117,7 +117,7 @@ void Vault::clear() { Obj* a = head->next; delete head; - head = a; + head = a; } } diff --git a/amxmodx/CVault.h b/amxmodx/CVault.h index b4145efc..1c759ebc 100755 --- a/amxmodx/CVault.h +++ b/amxmodx/CVault.h @@ -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 diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 65851ba4..f4f75d27 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -36,59 +36,63 @@ static cell AMX_NATIVE_CALL get_xvar_id(AMX *amx, cell *params) { int len; - char* sName = get_amxstring(amx,params[1],0,len); + char* sName = get_amxstring(amx, params[1], 0, len); cell ptr; - for ( CPluginMngr::iterator a = g_plugins.begin(); a ; ++a ) + for (CPluginMngr::iterator a = g_plugins.begin(); a ; ++a) { - if ( (*a).isValid() && amx_FindPubVar( (*a).getAMX() , sName , &ptr ) == AMX_ERR_NONE ) - return g_xvars.put( (*a).getAMX() , get_amxaddr( (*a).getAMX() , ptr ) ); + if ((*a).isValid() && amx_FindPubVar((*a).getAMX(), sName, &ptr) == AMX_ERR_NONE) + return g_xvars.put((*a).getAMX(), get_amxaddr((*a).getAMX(), ptr)); } + return -1; } static cell AMX_NATIVE_CALL get_xvar_num(AMX *amx, cell *params) { - return g_xvars.getValue(params[1]); + return g_xvars.getValue(params[1]); } static cell AMX_NATIVE_CALL set_xvar_num(AMX *amx, cell *params) { - if ( g_xvars.setValue( params[1] , params[2] ) ){ - amx_RaiseError(amx,AMX_ERR_NATIVE); + if (g_xvars.setValue(params[1], params[2])) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } + return 1; } static cell AMX_NATIVE_CALL xvar_exists(AMX *amx, cell *params) { - return (get_xvar_id( amx , params ) != -1) ? 1 : 0; + return (get_xvar_id(amx, params) != -1) ? 1 : 0; } static cell AMX_NATIVE_CALL emit_sound(AMX *amx, cell *params) /* 7 param */ { - int len; - char* szSample = get_amxstring(amx,params[3],0,len); + char* szSample = get_amxstring(amx, params[3], 0, len); REAL vol = amx_ctof(params[4]); REAL att = amx_ctof(params[5]); int channel = params[2]; int pitch = params[7]; int flags = params[6]; - if (params[1] == 0) { - for(int i = 1; i <= gpGlobals->maxClients ; ++i){ - CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if (pPlayer->ingame) - EMIT_SOUND_DYN2(pPlayer->pEdict,channel, szSample, vol, att,flags , pitch); - } - } - else + if (params[1] == 0) { + for (int i = 1; i <= gpGlobals->maxClients ; ++i) + { + CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); + + if (pPlayer->ingame) + EMIT_SOUND_DYN2(pPlayer->pEdict, channel, szSample, vol, att, flags, pitch); + } + } else { edict_t* pEdict = INDEXENT(params[1]); + if (!FNullEnt(pEdict)) - EMIT_SOUND_DYN2(pEdict,channel , szSample, vol, att, flags, pitch); + EMIT_SOUND_DYN2(pEdict, channel, szSample, vol, att, flags, pitch); } return 1; @@ -98,23 +102,29 @@ static cell AMX_NATIVE_CALL server_print(AMX *amx, cell *params) /* 1 param */ { int len; g_langMngr.SetDefLang(LANG_SERVER); // Default language = server - char* message = format_amxstring(amx,params,1,len); - if ( len > 254 ) len = 254; - message[len++]='\n'; - message[len]=0; - SERVER_PRINT( message ); + char* message = format_amxstring(amx, params, 1, len); + + if (len > 254) + len = 254; + + message[len++] = '\n'; + message[len] = 0; + SERVER_PRINT(message); + return len; } -static cell AMX_NATIVE_CALL engclient_print(AMX *amx, cell *params) /* 3 param */ +static cell AMX_NATIVE_CALL engclient_print(AMX *amx, cell *params) /* 3 param */ { int len; char *msg; + if (params[1] == 0) { - for(int i = 1; i <= gpGlobals->maxClients; ++i) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); + if (pPlayer->ingame) { g_langMngr.SetDefLang(i); @@ -124,15 +134,17 @@ static cell AMX_NATIVE_CALL engclient_print(AMX *amx, cell *params) /* 3 param CLIENT_PRINT(pPlayer->pEdict, (PRINT_TYPE)(int)params[2], msg); } } - } - else - { + } else { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + if (pPlayer->ingame) { g_langMngr.SetDefLang(index); @@ -142,6 +154,7 @@ static cell AMX_NATIVE_CALL engclient_print(AMX *amx, cell *params) /* 3 param CLIENT_PRINT(pPlayer->pEdict, (PRINT_TYPE)(int)params[2], msg); } } + return len; } @@ -150,16 +163,19 @@ static cell AMX_NATIVE_CALL console_cmd(AMX *amx, cell *params) /* 2 param */ int index = params[1]; g_langMngr.SetDefLang(index); int len; - char* cmd = format_amxstring(amx,params,2,len); - cmd[len++]='\n'; - cmd[len]=0; + char* cmd = format_amxstring(amx, params, 2, len); + + cmd[len++] = '\n'; + cmd[len] = 0; - if (index < 1 || index > gpGlobals->maxClients){ - SERVER_COMMAND( cmd ); - } - else{ + if (index < 1 || index > gpGlobals->maxClients) + { + SERVER_COMMAND(cmd); + } else { CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if ( !pPlayer->bot && pPlayer->initialized ) CLIENT_COMMAND(pPlayer->pEdict, UTIL_VarArgs("%s", cmd) ); + + if (!pPlayer->bot && pPlayer->initialized) + CLIENT_COMMAND(pPlayer->pEdict, UTIL_VarArgs("%s", cmd)); } return len; @@ -168,38 +184,45 @@ static cell AMX_NATIVE_CALL console_cmd(AMX *amx, cell *params) /* 2 param */ static cell AMX_NATIVE_CALL console_print(AMX *amx, cell *params) /* 2 param */ { int index = params[1]; + if (index < 1 || index > gpGlobals->maxClients) g_langMngr.SetDefLang(LANG_SERVER); else g_langMngr.SetDefLang(index); int len; - char* message = format_amxstring(amx,params,2,len); - if (len > 254 ) + char* message = format_amxstring(amx, params, 2, len); + + if (len > 254) len = 254; + message[len++] = '\n'; message[len] = 0; + if (index < 1 || index > gpGlobals->maxClients) - SERVER_PRINT( message ); + SERVER_PRINT(message); else { CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + if (pPlayer->ingame) - UTIL_ClientPrint(pPlayer->pEdict, 2 , message ); + UTIL_ClientPrint(pPlayer->pEdict, 2, message); } + return len; } - static cell AMX_NATIVE_CALL client_print(AMX *amx, cell *params) /* 3 param */ { int len = 0; char *msg; + if (params[1] == 0) { for (int i = 1; i <= gpGlobals->maxClients; ++i) { CPlayer *pPlayer = GET_PLAYER_POINTER_I(i); + if (pPlayer->ingame) { g_langMngr.SetDefLang(i); @@ -209,62 +232,83 @@ static cell AMX_NATIVE_CALL client_print(AMX *amx, cell *params) /* 3 param */ UTIL_ClientPrint(pPlayer->pEdict, params[2], msg); } } - } - else - { + } else { int index = params[1]; + if (index < 1 || index > gpGlobals->maxClients) { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); g_langMngr.SetDefLang(index); + msg = format_amxstring(amx, params, 3, len); msg[len++] = '\n'; msg[len] = 0; + if (pPlayer->ingame) - UTIL_ClientPrint(pPlayer->pEdict, params[2], msg); //format_amxstring(amx, params, 3, len)); + UTIL_ClientPrint(pPlayer->pEdict, params[2], msg); //format_amxstring(amx, params, 3, len)); } + return len; } -static cell AMX_NATIVE_CALL show_motd(AMX *amx, cell *params) /* 3 param */ +static cell AMX_NATIVE_CALL show_motd(AMX *amx, cell *params) /* 3 param */ { int ilen; - const char* szHead = get_amxstring(amx,params[3],0,ilen); - if ( !ilen ) szHead = hostname->string; - char* szBody = get_amxstring(amx,params[2],1,ilen); + const char* szHead = get_amxstring(amx, params[3], 0, ilen); + + if (!ilen) + szHead = hostname->string; + + char* szBody = get_amxstring(amx, params[2], 1, ilen); int iFile = 0; char* sToShow = NULL; // = szBody; - if (ilen<128) sToShow = (char*)LOAD_FILE_FOR_ME( szBody , &iFile ); + + if (ilen < 128) + sToShow = (char*)LOAD_FILE_FOR_ME(szBody, &iFile); + if (!iFile) sToShow = szBody; else ilen = iFile; - if (params[1] == 0) { - for(int i = 1; i <= gpGlobals->maxClients; ++i){ + + if (params[1] == 0) + { + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); + if (pPlayer->ingame) - UTIL_ShowMOTD(pPlayer->pEdict, sToShow , ilen, szHead); + UTIL_ShowMOTD(pPlayer->pEdict, sToShow, ilen, szHead); } - } - else { + } else { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); - if (iFile) FREE_FILE(sToShow); + if (iFile) + FREE_FILE(sToShow); + return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + if (pPlayer->ingame) - UTIL_ShowMOTD(pPlayer->pEdict, sToShow,ilen, szHead ); + UTIL_ShowMOTD(pPlayer->pEdict, sToShow, ilen, szHead); } - if (iFile) FREE_FILE(sToShow); + + if (iFile) + FREE_FILE(sToShow); + return 1; } -static cell AMX_NATIVE_CALL set_hudmessage(AMX *amx, cell *params) /* 11 param */ +static cell AMX_NATIVE_CALL set_hudmessage(AMX *amx, cell *params) /* 11 param */ { g_hudset.a1 = 0; g_hudset.a2 = 0; @@ -282,19 +326,22 @@ static cell AMX_NATIVE_CALL set_hudmessage(AMX *amx, cell *params) /* 11 param g_hudset.fadeinTime = amx_ctof(params[9]); g_hudset.fadeoutTime = amx_ctof(params[10]); g_hudset.channel = params[11]; + return 1; } -static cell AMX_NATIVE_CALL show_hudmessage(AMX *amx, cell *params) /* 2 param */ +static cell AMX_NATIVE_CALL show_hudmessage(AMX *amx, cell *params) /* 2 param */ { - int len=0; + int len = 0; g_langMngr.SetDefLang(params[1]); char* message = NULL; + if (params[1] == 0) { for (int i = 1; i <= gpGlobals->maxClients; ++i) { CPlayer *pPlayer = GET_PLAYER_POINTER_I(i); + if (pPlayer->ingame) { g_langMngr.SetDefLang(i); @@ -302,36 +349,42 @@ static cell AMX_NATIVE_CALL show_hudmessage(AMX *amx, cell *params) /* 2 param UTIL_HudMessage(pPlayer->pEdict, g_hudset, message); } } - } - else - { - message = UTIL_SplitHudMessage(format_amxstring(amx,params,2,len)); + } else { + message = UTIL_SplitHudMessage(format_amxstring(amx, params, 2, len)); int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + if (pPlayer->ingame) - UTIL_HudMessage(pPlayer->pEdict, g_hudset, message ); + UTIL_HudMessage(pPlayer->pEdict, g_hudset, message); } + return len; } -static cell AMX_NATIVE_CALL get_user_name(AMX *amx, cell *params) /* 3 param */ +static cell AMX_NATIVE_CALL get_user_name(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - return set_amxstring(amx,params[2],(index<1||index>gpGlobals->maxClients) ? - hostname->string : g_players[index].name.c_str() , params[3]); + + return set_amxstring(amx, params[2], (index < 1 || index > gpGlobals->maxClients) ? hostname->string : g_players[index].name.c_str(), params[3]); } -static cell AMX_NATIVE_CALL get_user_index(AMX *amx, cell *params) /* 1 param */ +static cell AMX_NATIVE_CALL get_user_index(AMX *amx, cell *params) /* 1 param */ { int i; - char* sptemp = get_amxstring(amx,params[1],0,i); - for(i = 1; i <= gpGlobals->maxClients; ++i) { + char* sptemp = get_amxstring(amx, params[1], 0, i); + + for (i = 1; i <= gpGlobals->maxClients; ++i) + { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if ( strcmp(pPlayer->name.c_str(), sptemp) == 0 ) + + if (strcmp(pPlayer->name.c_str(), sptemp) == 0) return i; } @@ -370,153 +423,195 @@ static cell AMX_NATIVE_CALL is_jit_enabled(AMX *amx, cell *params) // PM: Usele #endif } -static cell AMX_NATIVE_CALL is_map_valid(AMX *amx, cell *params) /* 1 param */ +static cell AMX_NATIVE_CALL is_map_valid(AMX *amx, cell *params) /* 1 param */ { int ilen; - return (IS_MAP_VALID(get_amxstring(amx,params[1],0,ilen)) ? 1 : 0); + return (IS_MAP_VALID(get_amxstring(amx, params[1], 0, ilen)) ? 1 : 0); } static cell AMX_NATIVE_CALL is_user_connected(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + return (pPlayer->ingame ? 1 : 0); } static cell AMX_NATIVE_CALL is_user_connecting(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - return ( !pPlayer->ingame && pPlayer->initialized - && (GETPLAYERUSERID(pPlayer->pEdict)>0) ) ? 1 : 0; + + return (!pPlayer->ingame && pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0)) ? 1 : 0; } static cell AMX_NATIVE_CALL is_user_bot(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + return (GET_PLAYER_POINTER_I(index)->bot ? 1 : 0); } - static cell AMX_NATIVE_CALL is_user_hltv(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer *pPlayer = GET_PLAYER_POINTER_I(index); + if (!pPlayer->initialized) return 0; + if (pPlayer->pEdict->v.flags & FL_PROXY) return 1; + const char *authid = GETPLAYERAUTHID(pPlayer->pEdict); + if (authid && stricmp(authid, "HLTV") == 0) return 1; + return 0; } static cell AMX_NATIVE_CALL is_user_alive(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + return ((pPlayer->ingame && pPlayer->IsAlive()) ? 1 : 0); } static cell AMX_NATIVE_CALL get_user_frags(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + return (cell)(pPlayer->ingame ? pPlayer->pEdict->v.frags : 0); } static cell AMX_NATIVE_CALL get_user_deaths(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + return (cell)(pPlayer->ingame ? pPlayer->deaths : 0); } - static cell AMX_NATIVE_CALL get_user_armor(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + return (cell)(pPlayer->ingame ? pPlayer->pEdict->v.armorvalue : 0); } -static cell AMX_NATIVE_CALL get_user_health(AMX *amx, cell *params) /* param */ +static cell AMX_NATIVE_CALL get_user_health(AMX *amx, cell *params) /* param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + return (cell)(pPlayer->ingame ? pPlayer->pEdict->v.health : 0); } static cell AMX_NATIVE_CALL get_user_userid(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + return pPlayer->initialized ? GETPLAYERUSERID(pPlayer->pEdict) : -1; } - static cell AMX_NATIVE_CALL get_user_authid(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; const char* authid = 0; - if (index>0&&index<=gpGlobals->maxClients) + + if (index > 0 && index <= gpGlobals->maxClients) authid = GETPLAYERAUTHID(g_players[index].pEdict); - return set_amxstring(amx,params[2], authid ? authid : "" ,params[3]); + + return set_amxstring(amx, params[2], authid ? authid : "", params[3]); } static cell AMX_NATIVE_CALL is_user_authorized(AMX *amx, cell *params) { int index = params[1]; + if (index < 1 || index > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(index)->authorized; } static cell AMX_NATIVE_CALL get_weaponname(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index < 1 || index >= MAX_WEAPONS ){ + + if (index < 1 || index >= MAX_WEAPONS) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } - return set_amxstring(amx,params[2],g_weaponsData[index].fullName.c_str(),params[3]); + + return set_amxstring(amx, params[2], g_weaponsData[index].fullName.c_str(), params[3]); } static cell AMX_NATIVE_CALL get_user_weapons(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame){ - cell *cpNum = get_amxaddr(amx,params[3]); - cell *cpIds = get_amxaddr(amx,params[2]); + + if (pPlayer->ingame) + { + cell *cpNum = get_amxaddr(amx, params[3]); + cell *cpIds = get_amxaddr(amx, params[2]); *cpIds = 0; int weapons = pPlayer->pEdict->v.weapons & ~(1<<31); // don't count last element - for(int i = 1; i < MAX_WEAPONS; ++i) + + for (int i = 1; i < MAX_WEAPONS; ++i) { if (weapons & (1< gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame){ + + if (pPlayer->ingame) + { int mode = params[3]; - cell *cpOrigin = get_amxaddr(amx,params[2]); - if (mode == 4) { + cell *cpOrigin = get_amxaddr(amx, params[2]); + + if (mode == 4) + { cpOrigin[0] = (long int)pPlayer->lastHit.x; cpOrigin[1] = (long int)pPlayer->lastHit.y; cpOrigin[2] = (long int)pPlayer->lastHit.z; return 1; } + edict_t* edict = pPlayer->pEdict; Vector pos = edict->v.origin; - if (mode && mode!=2) + + if (mode && mode != 2) pos = pos + edict->v.view_ofs; - if (mode > 1) { + + if (mode > 1) + { Vector vec; Vector v_angle = edict->v.v_angle; float v_vec[3]; + v_vec[0] = v_angle.x; v_vec[1] = v_angle.y; v_vec[2] = v_angle.z; - ANGLEVECTORS( v_vec, vec, NULL, NULL); + + ANGLEVECTORS(v_vec, vec, NULL, NULL); TraceResult trEnd; - Vector v_dest = pos+vec * 9999; + Vector v_dest = pos + vec * 9999; + float f_pos[3]; f_pos[0] = pos.x; f_pos[1] = pos.y; f_pos[2] = pos.z; + float f_dest[3]; f_dest[0] = v_dest.x; f_dest[1] = v_dest.y; f_dest[2] = v_dest.z; - TRACE_LINE( f_pos , f_dest, 0 , edict, &trEnd ); - pos = (trEnd.flFraction < 1.0) ? trEnd.vecEndPos : Vector(0,0,0); + + TRACE_LINE(f_pos, f_dest, 0, edict, &trEnd); + pos = (trEnd.flFraction < 1.0) ? trEnd.vecEndPos : Vector(0, 0, 0); } cpOrigin[0] = (long int)pos.x; cpOrigin[1] = (long int)pos.y; cpOrigin[2] = (long int)pos.z; + return 1; } + return 0; } @@ -584,64 +698,78 @@ static cell AMX_NATIVE_CALL get_user_ip(AMX *amx, cell *params) /* 3 param */ int index = params[1]; char *ptr; char szIp[32]; - strcpy(szIp,(index<1||index>gpGlobals->maxClients)? - CVAR_GET_STRING("net_address"):g_players[index].ip.c_str()); - if (params[4] && (ptr = strstr(szIp,":"))!=0) + strcpy(szIp, (index < 1 || index > gpGlobals->maxClients) ? CVAR_GET_STRING("net_address") : g_players[index].ip.c_str()); + + if (params[4] && (ptr = strstr(szIp, ":")) != 0) *ptr = '\0'; - return set_amxstring(amx,params[2],szIp,params[3]); + + return set_amxstring(amx, params[2], szIp, params[3]); } static cell AMX_NATIVE_CALL get_user_attacker(AMX *amx, cell *params) /* 2 param */ { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); edict_t *enemy = NULL; - if (pPlayer->ingame){ + + if (pPlayer->ingame) + { enemy = pPlayer->pEdict->v.dmg_inflictor; - if (!FNullEnt(enemy)) { + if (!FNullEnt(enemy)) + { int weapon = 0; - if (enemy->v.flags & (FL_CLIENT | FL_FAKECLIENT) ){ + + if (enemy->v.flags & (FL_CLIENT | FL_FAKECLIENT)) + { pPlayer = GET_PLAYER_POINTER(enemy); weapon = pPlayer->current; } - else if( g_grenades.find( enemy, &pPlayer, weapon ) ) + else if (g_grenades.find(enemy, &pPlayer, weapon)) enemy = pPlayer->pEdict; else enemy = NULL; - if (enemy){ - switch(*params/sizeof(cell)){ - case 3: *get_amxaddr(amx,params[3]) = pPlayer->aiming; - case 2: *get_amxaddr(amx,params[2]) = weapon; + if (enemy) + { + switch (*params / sizeof(cell)) + { + case 3: *get_amxaddr(amx, params[3]) = pPlayer->aiming; + case 2: *get_amxaddr(amx, params[2]) = weapon; } } } } + return (enemy ? pPlayer->index : 0); } -static cell AMX_NATIVE_CALL user_has_weapon(AMX *amx,cell *params) +static cell AMX_NATIVE_CALL user_has_weapon(AMX *amx, cell *params) { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); edict_t *pEntity = pPlayer->pEdict; + if (params[3] == -1) { if ((pEntity->v.weapons & (1< 0) { return 1; } - } - else - { + } else { if ((pEntity->v.weapons & (1< 0) { if (params[3] == 0) @@ -649,173 +777,215 @@ static cell AMX_NATIVE_CALL user_has_weapon(AMX *amx,cell *params) pEntity->v.weapons &= ~(1<v.weapons |= (1< gpGlobals->maxClients) { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + if (pPlayer->ingame) { int wpn = pPlayer->current; - if ( !(pPlayer->pEdict->v.weapons & (1<pEdict->v.weapons & (1<current = 0; return 0; } - cell *cpTemp = get_amxaddr(amx,params[2]); + + cell *cpTemp = get_amxaddr(amx, params[2]); *cpTemp = pPlayer->weapons[wpn].clip; - cpTemp = get_amxaddr(amx,params[3]); + cpTemp = get_amxaddr(amx, params[3]); *cpTemp = pPlayer->weapons[wpn].ammo; + return wpn; } + return 0; } static cell AMX_NATIVE_CALL get_user_ammo(AMX *amx, cell *params) /* 4 param */ { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame){ + + if (pPlayer->ingame) + { int wpn = params[2]; - if (wpn < 1 || wpn >= MAX_WEAPONS ){ + + if (wpn < 1 || wpn >= MAX_WEAPONS) + { LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", wpn); return 0; } - cell *cpTemp = get_amxaddr(amx,params[3]); + + cell *cpTemp = get_amxaddr(amx, params[3]); *cpTemp = pPlayer->weapons[wpn].clip; - cpTemp = get_amxaddr(amx,params[4]); + cpTemp = get_amxaddr(amx, params[4]); *cpTemp = pPlayer->weapons[wpn].ammo; + return 1; } + return 0; } static cell AMX_NATIVE_CALL get_user_team(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return -1; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame){ - // SidLuke , DoD fix - if ( g_bmod_dod ){ + + if (pPlayer->ingame) + { + // SidLuke, DoD fix + if (g_bmod_dod) + { int iTeam = pPlayer->pEdict->v.team; - if ( params[3] ){ + + if (params[3]) + { char *szTeam = ""; - switch(iTeam){ - case 1: - szTeam = "Allies"; - break; - case 2: - szTeam = "Axis"; - break; + + switch (iTeam) + { + case 1: + szTeam = "Allies"; + break; + case 2: + szTeam = "Axis"; + break; } - set_amxstring(amx,params[2],szTeam,params[3]); + + set_amxstring(amx, params[2], szTeam, params[3]); } return iTeam; } // - if ( params[3] ) - set_amxstring(amx,params[2],pPlayer->team.c_str(),params[3]); + if (params[3]) + set_amxstring(amx, params[2], pPlayer->team.c_str(), params[3]); return pPlayer->teamId; } + return -1; } static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */ { - int ilen=0, ilen2=0; + int ilen = 0, ilen2 = 0; char *sMenu = get_amxstring(amx, params[3], 0, ilen); char *lMenu = get_amxstring(amx, params[5], 1, ilen2); int menuid = 0; + if (ilen2 && lMenu) { menuid = g_menucmds.findMenuId(lMenu, amx); } else { menuid = g_menucmds.findMenuId(sMenu, amx); } + int keys = params[2]; int time = params[4]; - if (params[1] == 0) { - for(int i = 1; i <= gpGlobals->maxClients; ++i){ + + if (params[1] == 0) + { + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if (pPlayer->ingame){ + + if (pPlayer->ingame) + { pPlayer->keys = keys; pPlayer->menu = menuid; pPlayer->newmenu = -1; pPlayer->page = 0; - UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen ); + UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen); } } - } - else { + } else { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame){ + + if (pPlayer->ingame) + { pPlayer->keys = keys; pPlayer->menu = menuid; pPlayer->newmenu = -1; pPlayer->page = 0; - UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen ); + UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen); } } + return 1; } - - static cell AMX_NATIVE_CALL register_plugin(AMX *amx, cell *params) /* 3 param */ { - CPluginMngr::CPlugin* a = g_plugins.findPluginFast( amx ); + CPluginMngr::CPlugin* a = g_plugins.findPluginFast(amx); int i; - a->setTitle( get_amxstring(amx,params[1],0,i) ); - a->setVersion( get_amxstring(amx,params[2],0,i) ); - a->setAuthor( get_amxstring(amx,params[3],0,i) ); + + a->setTitle(get_amxstring(amx, params[1], 0, i)); + a->setVersion(get_amxstring(amx, params[2], 0, i)); + a->setAuthor(get_amxstring(amx, params[3], 0, i)); + return 1; } static cell AMX_NATIVE_CALL register_menucmd(AMX *amx, cell *params) /* 3 param */ { - CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast( amx ); + CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx); int ilen, idx; - char* sptemp = get_amxstring(amx,params[3],0,ilen); + char* sptemp = get_amxstring(amx, params[3], 0, ilen); idx = registerSPForwardByName(amx, sptemp, FP_CELL, FP_CELL, FP_CELL, FP_DONE); + if (idx == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", sptemp); return 0; } - g_menucmds.registerMenuCmd( plugin , params[1] , params[2] , idx ); + g_menucmds.registerMenuCmd(plugin, params[1], params[2], idx); return 1; } @@ -824,19 +994,22 @@ static cell AMX_NATIVE_CALL get_plugin(AMX *amx, cell *params) /* 11 param */ { CPluginMngr::CPlugin* a; - if ( params[1]<0 ) - a = g_plugins.findPluginFast( amx ); + if (params[1] < 0) + a = g_plugins.findPluginFast(amx); else - a = g_plugins.findPlugin( (int)params[1] ); + a = g_plugins.findPlugin((int)params[1]); - if (a){ - set_amxstring(amx,params[2],a->getName(),params[3]); - set_amxstring(amx,params[4],a->getTitle(),params[5]); - set_amxstring(amx,params[6],a->getVersion(),params[7]); - set_amxstring(amx,params[8],a->getAuthor(),params[9]); - set_amxstring(amx,params[10],a->getStatus(),params[11]); + if (a) + { + set_amxstring(amx, params[2], a->getName(), params[3]); + set_amxstring(amx, params[4], a->getTitle(), params[5]); + set_amxstring(amx, params[6], a->getVersion(), params[7]); + set_amxstring(amx, params[8], a->getAuthor(), params[9]); + set_amxstring(amx, params[10], a->getStatus(), params[11]); + return a->getId(); } + return -1; } @@ -861,6 +1034,7 @@ static cell AMX_NATIVE_CALL amx_md5_file(AMX *amx, cell *params) char buffer[33]; FILE *fp = fopen(str, "rb"); + if (!fp) { amx_RaiseError(amx, AMX_ERR_NATIVE); @@ -882,82 +1056,105 @@ static cell AMX_NATIVE_CALL get_pluginsnum(AMX *amx, cell *params) static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params) /* 4 param */ { - CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast( amx ); + CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx); int i, idx = 0; - char* temp = get_amxstring(amx,params[2],0, i ); + char* temp = get_amxstring(amx, params[2], 0, i); + idx = registerSPForwardByName(amx, temp, FP_CELL, FP_CELL, FP_CELL, FP_DONE); + if (idx == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", temp); return 0; } - temp = get_amxstring(amx,params[1],0, i ); - char* info = get_amxstring(amx,params[4],1, i ); + + temp = get_amxstring(amx, params[1], 0, i); + char* info = get_amxstring(amx, params[4], 1, i); CmdMngr::Command* cmd; int access = params[3]; bool listable = true; - if ( access < 0 ) { // is access is -1 then hide from listing + + if (access < 0) // is access is -1 then hide from listing + { access = 0; listable = false; } - if ( (cmd = g_commands.registerCommand( plugin , idx , temp , info , access ,listable )) == NULL) + + if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable)) == NULL) return 0; - cmd->setCmdType( CMD_ConsoleCommand ); - - REG_SVR_COMMAND( (char*)cmd->getCommand() , plugin_srvcmd ); + + cmd->setCmdType(CMD_ConsoleCommand); + REG_SVR_COMMAND((char*)cmd->getCommand(), plugin_srvcmd); + return 1; } static cell AMX_NATIVE_CALL register_clcmd(AMX *amx, cell *params) /* 4 param */ { - CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast( amx ); + CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx); int i, idx = 0; - char* temp = get_amxstring(amx,params[2],0, i ); + char* temp = get_amxstring(amx, params[2], 0, i); + idx = registerSPForwardByName(amx, temp, FP_CELL, FP_CELL, FP_CELL, FP_DONE); - if(idx==-1) + + if (idx == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", temp); return 0; } - temp = get_amxstring(amx,params[1],0, i ); - char* info = get_amxstring(amx,params[4],1, i ); + + temp = get_amxstring(amx, params[1], 0, i); + char* info = get_amxstring(amx, params[4], 1, i); CmdMngr::Command* cmd; int access = params[3]; bool listable = true; - if ( access < 0 ) { // is access is -1 then hide from listing + + if (access < 0) // is access is -1 then hide from listing + { access = 0; listable = false; } - if ( (cmd = g_commands.registerCommand(plugin , idx , temp , info , access , listable )) == NULL) + + if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable)) == NULL) return 0; - cmd->setCmdType( CMD_ClientCommand ); + + cmd->setCmdType(CMD_ClientCommand); + return 1; } static cell AMX_NATIVE_CALL register_srvcmd(AMX *amx, cell *params) /* 2 param */ { - CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast( amx ); + CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx); int i, idx = 0; - char* temp = get_amxstring(amx,params[2],0, i ); + char* temp = get_amxstring(amx, params[2], 0, i); + idx = registerSPForwardByName(amx, temp, FP_CELL, FP_CELL, FP_CELL, FP_DONE); - if (idx==-1) + + if (idx == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", temp); return 0; } - temp = get_amxstring(amx,params[1],0, i ); - char* info = get_amxstring(amx,params[4],1, i ); + + temp = get_amxstring(amx, params[1], 0, i); + char* info = get_amxstring(amx, params[4], 1, i); CmdMngr::Command* cmd; int access = params[3]; bool listable = true; - if ( access < 0 ) { // is access is -1 then hide from listing + + if (access < 0) // is access is -1 then hide from listing + { access = 0; listable = false; } - if ( (cmd = g_commands.registerCommand(plugin ,idx , temp , info ,access,listable )) == NULL) + + if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable)) == NULL) return 0; - cmd->setCmdType( CMD_ServerCommand ); - REG_SVR_COMMAND( (char*)cmd->getCommand() , plugin_srvcmd ); + + cmd->setCmdType(CMD_ServerCommand); + REG_SVR_COMMAND((char*)cmd->getCommand(), plugin_srvcmd); + return 0; } @@ -965,30 +1162,36 @@ static cell AMX_NATIVE_CALL get_concmd(AMX *amx, cell *params) /* 7 param */ { int who = params[8]; - if ( who > 0 ) // id of player - client command + if (who > 0) // id of player - client command who = CMD_ClientCommand; - else if ( who == 0 ) // server + else if (who == 0) // server who = CMD_ServerCommand; - else // -1 parameter - all commands + else // -1 parameter - all commands who = CMD_ConsoleCommand; CmdMngr::Command* cmd = g_commands.getCmd(params[1], who, params[7]); - if ( cmd == 0 ) return 0; - set_amxstring(amx,params[2], cmd->getCmdLine() ,params[3]); - set_amxstring(amx,params[5], cmd->getCmdInfo() ,params[6]); - cell *cpFlags = get_amxaddr(amx,params[4]); + if (cmd == 0) + return 0; + + set_amxstring(amx, params[2], cmd->getCmdLine(), params[3]); + set_amxstring(amx, params[5], cmd->getCmdInfo(), params[6]); + cell *cpFlags = get_amxaddr(amx, params[4]); *cpFlags = cmd->getFlags(); + return 1; } static cell AMX_NATIVE_CALL get_clcmd(AMX *amx, cell *params) /* 7 param */ { - CmdMngr::Command* cmd = g_commands.getCmd(params[1] ,CMD_ClientCommand , params[7]); - if ( cmd == 0 ) return 0; - set_amxstring(amx,params[2], cmd->getCmdLine() ,params[3]); - set_amxstring(amx,params[5], cmd->getCmdInfo() ,params[6]); - cell *cpFlags = get_amxaddr(amx,params[4]); + CmdMngr::Command* cmd = g_commands.getCmd(params[1], CMD_ClientCommand, params[7]); + + if (cmd == 0) + return 0; + + set_amxstring(amx, params[2], cmd->getCmdLine(), params[3]); + set_amxstring(amx, params[5], cmd->getCmdInfo(), params[6]); + cell *cpFlags = get_amxaddr(amx, params[4]); *cpFlags = cmd->getFlags(); return 1; @@ -996,72 +1199,78 @@ static cell AMX_NATIVE_CALL get_clcmd(AMX *amx, cell *params) /* 7 param */ static cell AMX_NATIVE_CALL get_srvcmd(AMX *amx, cell *params) { - CmdMngr::Command* cmd = g_commands.getCmd(params[1] ,CMD_ServerCommand , params[7] ); - if ( cmd == 0 ) return 0; - set_amxstring(amx,params[2], cmd->getCmdLine() ,params[3]); - set_amxstring(amx,params[5], cmd->getCmdInfo() ,params[6]); - cell *cpFlags = get_amxaddr(amx,params[4]); + CmdMngr::Command* cmd = g_commands.getCmd(params[1], CMD_ServerCommand, params[7]); + + if (cmd == 0) + return 0; + + set_amxstring(amx, params[2], cmd->getCmdLine(), params[3]); + set_amxstring(amx, params[5], cmd->getCmdInfo(), params[6]); + cell *cpFlags = get_amxaddr(amx, params[4]); *cpFlags = cmd->getFlags(); + return 1; } static cell AMX_NATIVE_CALL get_srvcmdsnum(AMX *amx, cell *params) { - return g_commands.getCmdNum( CMD_ServerCommand , params[1] ); + return g_commands.getCmdNum(CMD_ServerCommand, params[1]); } static cell AMX_NATIVE_CALL get_clcmdsnum(AMX *amx, cell *params) /* 1 param */ { - return g_commands.getCmdNum( CMD_ClientCommand , params[1] ); + return g_commands.getCmdNum(CMD_ClientCommand, params[1]); } static cell AMX_NATIVE_CALL get_concmdsnum(AMX *amx, cell *params) /* 1 param */ { int who = params[2]; - if ( who > 0 ) - return g_commands.getCmdNum( CMD_ClientCommand , params[1] ); - if ( who == 0 ) - return g_commands.getCmdNum( CMD_ServerCommand , params[1] ); - return g_commands.getCmdNum( CMD_ConsoleCommand , params[1] ); + + if (who > 0) + return g_commands.getCmdNum(CMD_ClientCommand, params[1]); + if (who == 0) + return g_commands.getCmdNum(CMD_ServerCommand, params[1]); + + return g_commands.getCmdNum(CMD_ConsoleCommand, params[1]); } - static cell AMX_NATIVE_CALL register_event(AMX *amx, cell *params) /* 2 param */ { - CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast( amx ); + CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx); int len, pos, iFunction; - char* sTemp = get_amxstring(amx,params[1],0,len); + char* sTemp = get_amxstring(amx, params[1], 0, len); - if ( (pos = g_events.getEventId( sTemp )) == 0 ) { - AMXXLOG_Log("[AMXX] Invalid event (name \"%s\") (plugin \"%s\")", sTemp , plugin->getName() ); - amx_RaiseError(amx,AMX_ERR_NATIVE); + if ((pos = g_events.getEventId(sTemp)) == 0) + { + AMXXLOG_Log("[AMXX] Invalid event (name \"%s\") (plugin \"%s\")", sTemp, plugin->getName()); + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } - sTemp = get_amxstring(amx,params[2],0,len); + sTemp = get_amxstring(amx, params[2], 0, len); iFunction = registerSPForwardByName(amx, sTemp, FP_CELL, FP_DONE); - if (iFunction==-1) + + if (iFunction == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", sTemp); return 0; } - int numparam = *params/sizeof(cell); - + int numparam = *params / sizeof(cell); int flags = 0; - if ( numparam > 2) - flags = UTIL_ReadFlags( get_amxstring(amx,params[3],0,len) ); + if (numparam > 2) + flags = UTIL_ReadFlags(get_amxstring(amx, params[3], 0, len)); - EventsMngr::ClEvent* a = - g_events.registerEvent( plugin , iFunction , flags , pos ); + EventsMngr::ClEvent* a = g_events.registerEvent(plugin, iFunction, flags, pos); - if ( a == 0 ) return 0; + if (a == 0) + return 0; - for(int i = 4; i <= numparam; ++i) - a->registerFilter( get_amxstring(amx,params[i],0,len) ); + for (int i = 4; i <= numparam; ++i) + a->registerFilter(get_amxstring(amx, params[i], 0, len)); return 1; } @@ -1069,13 +1278,20 @@ static cell AMX_NATIVE_CALL register_event(AMX *amx, cell *params) /* 2 param */ static cell AMX_NATIVE_CALL user_kill(AMX *amx, cell *params) /* 2 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame && pPlayer->IsAlive()){ + + if (pPlayer->ingame && pPlayer->IsAlive()) + { float bef = pPlayer->pEdict->v.frags; MDLL_ClientKill(pPlayer->pEdict); - if (params[2]) pPlayer->pEdict->v.frags = bef; + + if (params[2]) + pPlayer->pEdict->v.frags = bef; + return 1; } @@ -1085,58 +1301,74 @@ static cell AMX_NATIVE_CALL user_kill(AMX *amx, cell *params) /* 2 param */ static cell AMX_NATIVE_CALL user_slap(AMX *amx, cell *params) /* 2 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + int power = abs((int)params[2]); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame && pPlayer->IsAlive()){ - if (pPlayer->pEdict->v.health <= power) { + + if (pPlayer->ingame && pPlayer->IsAlive()) + { + if (pPlayer->pEdict->v.health <= power) + { float bef = pPlayer->pEdict->v.frags; MDLL_ClientKill(pPlayer->pEdict); pPlayer->pEdict->v.frags = bef; - } - else { + } else { edict_t *pEdict = pPlayer->pEdict; - int numparam = *params/sizeof(cell); - if (numparam<3 || params[3]) { - pEdict->v.velocity.x += RANDOM_LONG(-600,600); - pEdict->v.velocity.y += RANDOM_LONG(-180,180); - pEdict->v.velocity.z += RANDOM_LONG(100,200); - } - else { + int numparam = *params / sizeof(cell); + + if (numparam < 3 || params[3]) + { + pEdict->v.velocity.x += RANDOM_LONG(-600, 600); + pEdict->v.velocity.y += RANDOM_LONG(-180, 180); + pEdict->v.velocity.z += RANDOM_LONG(100, 200); + } else { Vector v_forward, v_right; Vector vang = pEdict->v.angles; float fang[3]; fang[0] = vang.x; fang[1] = vang.y; fang[2] = vang.z; - ANGLEVECTORS( fang, v_forward, v_right, NULL ); - pEdict->v.velocity = pEdict->v.velocity + v_forward * 220 + Vector(0,0,200); + ANGLEVECTORS(fang, v_forward, v_right, NULL); + pEdict->v.velocity = pEdict->v.velocity + v_forward * 220 + Vector(0, 0, 200); } - pEdict->v.punchangle.x = static_cast(RANDOM_LONG(-10,10)); - pEdict->v.punchangle.y = static_cast(RANDOM_LONG(-10,10)); + + pEdict->v.punchangle.x = static_cast(RANDOM_LONG(-10, 10)); + pEdict->v.punchangle.y = static_cast(RANDOM_LONG(-10, 10)); pEdict->v.health -= power; + int armor = (int)pEdict->v.armorvalue; armor -= power; - if (armor < 0) armor = 0; + + if (armor < 0) + armor = 0; + pEdict->v.armorvalue = static_cast(armor); pEdict->v.dmg_inflictor = pEdict; - if (g_bmod_cstrike){ - static const char *cs_sound[4] = { + + if (g_bmod_cstrike) + { + static const char *cs_sound[4] = + { "player/bhit_flesh-3.wav", - "player/bhit_flesh-2.wav", - "player/pl_die1.wav", - "player/pl_pain6.wav" }; - EMIT_SOUND_DYN2(pEdict, CHAN_VOICE, cs_sound[RANDOM_LONG(0,3)], 1.0, ATTN_NORM, 0, PITCH_NORM); - } - else{ - static const char *bit_sound[3] = { + "player/bhit_flesh-2.wav", + "player/pl_die1.wav", + "player/pl_pain6.wav" + }; + EMIT_SOUND_DYN2(pEdict, CHAN_VOICE, cs_sound[RANDOM_LONG(0, 3)], 1.0, ATTN_NORM, 0, PITCH_NORM); + } else{ + static const char *bit_sound[3] = + { "weapons/cbar_hitbod1.wav", - "weapons/cbar_hitbod2.wav", - "weapons/cbar_hitbod3.wav" }; - EMIT_SOUND_DYN2(pEdict, CHAN_VOICE, bit_sound[RANDOM_LONG(0,2)], 1.0, ATTN_NORM, 0, PITCH_NORM); + "weapons/cbar_hitbod2.wav", + "weapons/cbar_hitbod3.wav" + }; + EMIT_SOUND_DYN2(pEdict, CHAN_VOICE, bit_sound[RANDOM_LONG(0, 2)], 1.0, ATTN_NORM, 0, PITCH_NORM); } } + return 1; } @@ -1147,86 +1379,101 @@ static cell AMX_NATIVE_CALL server_cmd(AMX *amx, cell *params) /* 1 param */ { int len; g_langMngr.SetDefLang(LANG_SERVER); - char* cmd = format_amxstring(amx,params,1,len); - cmd[len++]='\n'; - cmd[len]=0; - SERVER_COMMAND( cmd ); + char* cmd = format_amxstring(amx, params, 1, len); + + cmd[len++] = '\n'; + cmd[len] = 0; + + SERVER_COMMAND(cmd); + return len; } static cell AMX_NATIVE_CALL client_cmd(AMX *amx, cell *params) /* 2 param */ { int len; - char* cmd = format_amxstring(amx,params,2,len); - cmd[len++]='\n'; - cmd[len]=0; + char* cmd = format_amxstring(amx, params, 2, len); + cmd[len++] = '\n'; + cmd[len] = 0; - if (params[1] == 0) { - for(int i = 1; i <= gpGlobals->maxClients; ++i){ + if (params[1] == 0) + { + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if (!pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/ ) - CLIENT_COMMAND(pPlayer->pEdict, UTIL_VarArgs("%s", cmd) ); + if (!pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/) + CLIENT_COMMAND(pPlayer->pEdict, UTIL_VarArgs("%s", cmd)); } - } - else { + } else { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if ( !pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/ ) - CLIENT_COMMAND(pPlayer->pEdict, UTIL_VarArgs("%s", cmd) ); + + if (!pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/) + CLIENT_COMMAND(pPlayer->pEdict, UTIL_VarArgs("%s", cmd)); } + return len; } static cell AMX_NATIVE_CALL get_cvar_string(AMX *amx, cell *params) /* 3 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); - return set_amxstring(amx,params[2],CVAR_GET_STRING(sptemp),params[3]); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); + + return set_amxstring(amx, params[2], CVAR_GET_STRING(sptemp), params[3]); } static cell AMX_NATIVE_CALL get_cvar_float(AMX *amx, cell *params) /* 1 param */ { int ilen; - REAL pFloat = CVAR_GET_FLOAT(get_amxstring(amx,params[1],0,ilen)); + REAL pFloat = CVAR_GET_FLOAT(get_amxstring(amx, params[1], 0, ilen)); + return amx_ftoc(pFloat); } static cell AMX_NATIVE_CALL set_cvar_float(AMX *amx, cell *params) /* 2 param */ { int ilen; - CVAR_SET_FLOAT(get_amxstring(amx,params[1],0,ilen), amx_ctof(params[2])); + CVAR_SET_FLOAT(get_amxstring(amx, params[1], 0, ilen), amx_ctof(params[2])); + return 1; } static cell AMX_NATIVE_CALL get_cvar_num(AMX *amx, cell *params) /* 1 param */ { int ilen; - return (int)CVAR_GET_FLOAT(get_amxstring(amx,params[1],0,ilen)); + return (int)CVAR_GET_FLOAT(get_amxstring(amx, params[1], 0, ilen)); } static cell AMX_NATIVE_CALL set_cvar_num(AMX *amx, cell *params) /* 2 param */ { int ilen; - CVAR_SET_FLOAT(get_amxstring(amx,params[1],0,ilen),(float)params[2]); + CVAR_SET_FLOAT(get_amxstring(amx, params[1], 0, ilen), (float)params[2]); + return 1; } static cell AMX_NATIVE_CALL set_cvar_string(AMX *amx, cell *params) /* 2 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); - char* szValue = get_amxstring(amx,params[2],1,ilen); - CVAR_SET_STRING(sptemp,szValue); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); + char* szValue = get_amxstring(amx, params[2], 1, ilen); + + CVAR_SET_STRING(sptemp, szValue); + return 1; } static cell AMX_NATIVE_CALL message_begin(AMX *amx, cell *params) /* 4 param */ { - int numparam = *params/sizeof(cell); + int numparam = *params / sizeof(cell); float vecOrigin[3]; cell *cpOrigin; @@ -1235,34 +1482,44 @@ static cell AMX_NATIVE_CALL message_begin(AMX *amx, cell *params) /* 4 param */ { AMXXLOG_Log("[AMXX] Plugin called message_begin with an invalid message id (%d).", params[2]); amx_RaiseError(amx, AMX_ERR_NATIVE); + return 0; } - switch (params[1]){ - case MSG_BROADCAST: - case MSG_ALL: - case MSG_SPEC: - MESSAGE_BEGIN( params[1], params[2],NULL ); - break; - case MSG_PVS: case MSG_PAS: - case MSG_PVS_R: case MSG_PAS_R: - if (numparam < 3) { - amx_RaiseError(amx,AMX_ERR_NATIVE); - return 0; - } - cpOrigin = get_amxaddr(amx,params[3]); - vecOrigin[0] = static_cast(*cpOrigin); - vecOrigin[1] = static_cast(*(cpOrigin+1)); - vecOrigin[2] = static_cast(*(cpOrigin+2)); - MESSAGE_BEGIN( params[1], params[2] , vecOrigin ); - break; - case MSG_ONE_UNRELIABLE: - case MSG_ONE: - if (numparam < 4) { - amx_RaiseError(amx,AMX_ERR_NATIVE); - return 0; - } - MESSAGE_BEGIN( params[1], params[2], NULL, INDEXENT(params[4]) ); - break; + + switch (params[1]) + { + case MSG_BROADCAST: + case MSG_ALL: + case MSG_SPEC: + MESSAGE_BEGIN(params[1], params[2], NULL); + break; + case MSG_PVS: case MSG_PAS: + case MSG_PVS_R: case MSG_PAS_R: + if (numparam < 3) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); + return 0; + } + + cpOrigin = get_amxaddr(amx, params[3]); + + vecOrigin[0] = static_cast(*cpOrigin); + vecOrigin[1] = static_cast(*(cpOrigin + 1)); + vecOrigin[2] = static_cast(*(cpOrigin + 2)); + + MESSAGE_BEGIN(params[1], params[2], vecOrigin); + + break; + case MSG_ONE_UNRELIABLE: + case MSG_ONE: + if (numparam < 4) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); + return 0; + } + + MESSAGE_BEGIN(params[1], params[2], NULL, INDEXENT(params[4])); + break; } return 1; @@ -1276,50 +1533,51 @@ static cell AMX_NATIVE_CALL message_end(AMX *amx, cell *params) static cell AMX_NATIVE_CALL write_byte(AMX *amx, cell *params) /* 1 param */ { - WRITE_BYTE( params[1] ); + WRITE_BYTE(params[1]); return 1; } static cell AMX_NATIVE_CALL write_char(AMX *amx, cell *params) /* 1 param */ { - WRITE_CHAR( params[1] ); + WRITE_CHAR(params[1]); return 1; } -static cell AMX_NATIVE_CALL write_short(AMX *amx, cell *params) /* 1 param */ +static cell AMX_NATIVE_CALL write_short(AMX *amx, cell *params) /* 1 param */ { - WRITE_SHORT( params[1] ); + WRITE_SHORT(params[1]); return 1; } -static cell AMX_NATIVE_CALL write_long(AMX *amx, cell *params) /* 1 param */ +static cell AMX_NATIVE_CALL write_long(AMX *amx, cell *params) /* 1 param */ { - WRITE_LONG( params[1] ); + WRITE_LONG(params[1]); return 1; } static cell AMX_NATIVE_CALL write_entity(AMX *amx, cell *params) /* 1 param */ { - WRITE_ENTITY( params[1] ); + WRITE_ENTITY(params[1]); return 1; } static cell AMX_NATIVE_CALL write_angle(AMX *amx, cell *params) /* 1 param */ { - WRITE_ANGLE( static_cast(params[1]) ); + WRITE_ANGLE(static_cast(params[1])); return 1; } static cell AMX_NATIVE_CALL write_coord(AMX *amx, cell *params) /* 1 param */ { - WRITE_COORD( static_cast(params[1]) ); + WRITE_COORD(static_cast(params[1])); return 1; } static cell AMX_NATIVE_CALL write_string(AMX *amx, cell *params) /* 1 param */ { int a; - WRITE_STRING( get_amxstring(amx,params[1],3,a) ); + WRITE_STRING(get_amxstring(amx, params[1], 3, a)); + return 1; } @@ -1327,52 +1585,65 @@ static cell AMX_NATIVE_CALL log_message(AMX *amx, cell *params) /* 1 param */ { int len; g_langMngr.SetDefLang(LANG_SERVER); - char* message = format_amxstring(amx,params,1,len); - message[len++]='\n'; - message[len]=0; - ALERT( at_logged, "%s", message ); + char* message = format_amxstring(amx, params, 1, len); + + message[len++] = '\n'; + message[len] = 0; + + ALERT(at_logged, "%s", message); + return len; } static cell AMX_NATIVE_CALL log_to_file(AMX *amx, cell *params) /* 1 param */ { int ilen; - char* szFile = get_amxstring(amx,params[1],0,ilen); + char* szFile = get_amxstring(amx, params[1], 0, ilen); FILE*fp; char file[256]; + if (strchr(szFile, '/') || strchr(szFile, '\\')) { - build_pathname_r(file, sizeof(file)-1, "%s", szFile); + build_pathname_r(file, sizeof(file) - 1, "%s", szFile); } else { - build_pathname_r(file, sizeof(file)-1, "%s/%s", g_log_dir.c_str(), szFile); + build_pathname_r(file, sizeof(file) - 1, "%s/%s", g_log_dir.c_str(), szFile); } + bool first_time = true; - if ((fp=fopen(file,"r"))!=NULL){ + + if ((fp = fopen(file, "r")) != NULL) + { first_time = false; fclose(fp); } - if ((fp=fopen(file,"a")) == NULL){ - //amx_RaiseError(amx,AMX_ERR_NATIVE); + + if ((fp = fopen(file, "a")) == NULL) + { + //amx_RaiseError(amx, AMX_ERR_NATIVE); //would cause too much troubles in old plugins return 0; } + char date[32]; time_t td; time(&td); - strftime(date,31,"%m/%d/%Y - %H:%M:%S",localtime(&td)); + strftime(date, 31, "%m/%d/%Y - %H:%M:%S", localtime(&td)); int len; g_langMngr.SetDefLang(LANG_SERVER); - char* message = format_amxstring(amx,params,2,len); - message[len++]='\n'; - message[len]=0; - if ( first_time ){ - fprintf(fp,"L %s: Log file started (file \"%s\") (game \"%s\") (amx \"%s\")\n", - date,file,g_mod_name.c_str(),Plugin_info.version); - print_srvconsole("L %s: Log file started (file \"%s\") (game \"%s\") (amx \"%s\")\n", - date,file,g_mod_name.c_str(),Plugin_info.version); + char* message = format_amxstring(amx, params, 2, len); + + message[len++] = '\n'; + message[len] = 0; + + if (first_time) + { + fprintf(fp, "L %s: Log file started (file \"%s\") (game \"%s\") (amx \"%s\")\n", date, file, g_mod_name.c_str(), Plugin_info.version); + print_srvconsole("L %s: Log file started (file \"%s\") (game \"%s\") (amx \"%s\")\n", date, file, g_mod_name.c_str(), Plugin_info.version); } - fprintf(fp,"L %s: %s",date,message); - print_srvconsole("L %s: %s",date,message); + + fprintf(fp, "L %s: %s", date, message); + print_srvconsole("L %s: %s", date, message); fclose(fp); + return 1; } @@ -1380,15 +1651,16 @@ static cell AMX_NATIVE_CALL num_to_word(AMX *amx, cell *params) /* 3 param */ { char sptemp[512]; UTIL_IntToString(params[1], sptemp); - return set_amxstring(amx,params[2],sptemp,params[3]); + + return set_amxstring(amx, params[2], sptemp, params[3]); } - static cell AMX_NATIVE_CALL get_timeleft(AMX *amx, cell *params) { float flCvarTimeLimit = mp_timelimit->value; - if (flCvarTimeLimit) { + if (flCvarTimeLimit) + { int iReturn = (int)((g_game_timeleft + flCvarTimeLimit * 60.0) - gpGlobals->time); return (iReturn < 0) ? 0 : iReturn; } @@ -1399,67 +1671,84 @@ static cell AMX_NATIVE_CALL get_timeleft(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_time(AMX *amx, cell *params) /* 3 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); time_t td = time(NULL); tm* lt = localtime(&td); - if ( lt == 0 ) { - amx_RaiseError(amx,AMX_ERR_NATIVE); + + if (lt == 0) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } + char szDate[512]; - strftime(szDate,511,sptemp, lt ); - return set_amxstring(amx,params[2],szDate,params[3]); + strftime(szDate, 511, sptemp, lt); + + return set_amxstring(amx, params[2], szDate, params[3]); } static cell AMX_NATIVE_CALL format_time(AMX *amx, cell *params) /* 3 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[3],0,ilen); + char* sptemp = get_amxstring(amx, params[3], 0, ilen); time_t tim = params[4]; - time_t td = ( tim != -1 ) ? tim : time(NULL); + time_t td = (tim != -1) ? tim : time(NULL); tm* lt = localtime(&td); - if ( lt == 0 ) { - amx_RaiseError(amx,AMX_ERR_NATIVE); + + if (lt == 0) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } + char szDate[512]; - strftime(szDate,511,sptemp, lt ); - return set_amxstring(amx,params[1],szDate,params[2]); + strftime(szDate, 511, sptemp, lt); + + return set_amxstring(amx, params[1], szDate, params[2]); } static cell AMX_NATIVE_CALL parse_time(AMX *amx, cell *params) /* 3 param */ { int ilen; - char* sTime = get_amxstring(amx,params[1],1,ilen); - char* sFormat = get_amxstring(amx,params[2],0,ilen); + char* sTime = get_amxstring(amx, params[1], 1, ilen); + char* sFormat = get_amxstring(amx, params[2], 0, ilen); tm* mytime; time_t td; - if ( params[3] == -1 ) { + + if (params[3] == -1) + { td = time(NULL); mytime = localtime(&td); - if ( mytime == 0 ){ - amx_RaiseError(amx,AMX_ERR_NATIVE); + + if (mytime == 0) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } - strptime (sTime,sFormat,mytime , 0 ); - } - else { + + strptime(sTime, sFormat, mytime, 0); + } else { td = params[3]; mytime = localtime(&td); - if ( mytime == 0 ){ - amx_RaiseError(amx,AMX_ERR_NATIVE); + + if (mytime == 0) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } - strptime (sTime,sFormat,mytime , 1 ); + + strptime(sTime, sFormat, mytime, 1); } + return mktime(mytime); } static cell AMX_NATIVE_CALL get_systime(AMX *amx, cell *params) /* 3 param */ { time_t td = time(NULL); - td += params[1]; + td += params[1]; + return td; } @@ -1474,11 +1763,13 @@ static cell AMX_NATIVE_CALL read_data(AMX *amx, cell *params) /* 3 param */ { return g_events.getCurrentMsgType(); } - switch( *params/sizeof(cell) ) { + + switch (*params / sizeof(cell)) + { case 1: - return g_events.getArgInteger( params[1] ); + return g_events.getArgInteger(params[1]); case 3: - return set_amxstring(amx,params[2], g_events.getArgString( params[1] ),*get_amxaddr(amx,params[3])); + return set_amxstring(amx, params[2], g_events.getArgString(params[1]), *get_amxaddr(amx, params[3])); default: cell *fCell = get_amxaddr(amx, params[2]); float fparam = g_events.getArgFloat(params[1]); @@ -1493,9 +1784,12 @@ static cell AMX_NATIVE_CALL get_playersnum(AMX *amx, cell *params) return g_players_num; int a = 0; - for(int i = 1; i <= gpGlobals->maxClients; ++i){ + + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if ( pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0) ) + + if (pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0)) ++a; } @@ -1506,40 +1800,46 @@ static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */ { int iNum = 0; int ilen; - char* sptemp = get_amxstring(amx,params[3],0,ilen); + char* sptemp = get_amxstring(amx, params[3], 0, ilen); int flags = UTIL_ReadFlags(sptemp); - cell *aPlayers = get_amxaddr(amx,params[1]); - cell *iMax = get_amxaddr(amx,params[2]); + cell *aPlayers = get_amxaddr(amx, params[1]); + cell *iMax = get_amxaddr(amx, params[2]); int team = 0; - if (flags & 48) { - sptemp = get_amxstring(amx,params[4],0,ilen); + if (flags & 48) + { + sptemp = get_amxstring(amx, params[4], 0, ilen); - if ( flags & 16 ) { + if (flags & 16) + { if (flags & 64) - team = g_teamsIds.findTeamId( sptemp ); + team = g_teamsIds.findTeamId(sptemp); else - team = g_teamsIds.findTeamIdCase( sptemp ); + team = g_teamsIds.findTeamIdCase(sptemp); } } - for(int i = 1; i <= gpGlobals->maxClients; ++i){ + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if (pPlayer->ingame){ + if (pPlayer->ingame) + { if (pPlayer->IsAlive() ? (flags & 2) : (flags & 1)) continue; if (pPlayer->bot ? (flags & 4) : (flags & 8)) continue; - if ((flags & 16) && (pPlayer->teamId != team) ) + if ((flags & 16) && (pPlayer->teamId != team)) continue; - if (flags & 32){ - if (flags & 64){ - if (stristr(pPlayer->name.c_str(),sptemp)==NULL) + if (flags & 32) + { + if (flags & 64) + { + if (stristr(pPlayer->name.c_str(), sptemp) == NULL) continue; } - else if (strstr(pPlayer->name.c_str(),sptemp)==NULL) + else if (strstr(pPlayer->name.c_str(), sptemp) == NULL) continue; } aPlayers[iNum++] = i; @@ -1547,66 +1847,91 @@ static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */ } *iMax = iNum; + return 1; } static cell AMX_NATIVE_CALL find_player(AMX *amx, cell *params) /* 1 param */ { int ilen, userid = 0; - char* sptemp = get_amxstring(amx,params[1],0,ilen); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); int flags = UTIL_ReadFlags(sptemp); - if (flags&31) - sptemp = get_amxstring(amx,params[2],0,ilen); - else if (flags&1024) - userid = *get_amxaddr(amx,params[2]); + + if (flags & 31) + sptemp = get_amxstring(amx, params[2], 0, ilen); + else if (flags & 1024) + userid = *get_amxaddr(amx, params[2]); + // a b c d e f g h i j k l int result = 0; - for(int i = 1; i <= gpGlobals->maxClients; ++i){ + + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if (pPlayer->ingame){ - if (pPlayer->IsAlive()?(flags&64):(flags&32)) + + if (pPlayer->ingame) + { + if (pPlayer->IsAlive() ? (flags & 64) : (flags & 32)) continue; - if (pPlayer->bot?(flags&128):(flags&256)) + + if (pPlayer->bot ? (flags & 128) : (flags & 256)) continue; - if (flags&1){ - if (flags&2048) { - if (stricmp(pPlayer->name.c_str(),sptemp)) + + if (flags & 1) + { + if (flags & 2048) + { + if (stricmp(pPlayer->name.c_str(), sptemp)) continue; } - else if (strcmp(pPlayer->name.c_str(),sptemp)) + else if (strcmp(pPlayer->name.c_str(), sptemp)) continue; } - if (flags&2){ - if (flags&2048) { - if (stristr(pPlayer->name.c_str(),sptemp)==NULL) + + if (flags & 2) + { + if (flags & 2048) + { + if (stristr(pPlayer->name.c_str(), sptemp) == NULL) continue; } - else if (strstr(pPlayer->name.c_str(),sptemp)==NULL) + else if (strstr(pPlayer->name.c_str(), sptemp) == NULL) continue; } - if (flags&4){ + + if (flags & 4) + { const char* authid = GETPLAYERAUTHID(pPlayer->pEdict); - if (!authid || strcmp(authid,sptemp)) + if (!authid || strcmp(authid, sptemp)) continue; } - if (flags&1024){ + + if (flags & 1024) + { if (userid != GETPLAYERUSERID(pPlayer->pEdict)) continue; } - if (flags&8){ - if (strncmp(pPlayer->ip.c_str(),sptemp,ilen)) + + if (flags & 8) + { + if (strncmp(pPlayer->ip.c_str(), sptemp, ilen)) continue; } - if (flags&16){ - if (flags&2048) { - if (stricmp(pPlayer->team.c_str(),sptemp)) + + if (flags & 16) + { + if (flags & 2048) + { + if (stricmp(pPlayer->team.c_str(), sptemp)) continue; } - else if (strcmp(pPlayer->team.c_str(),sptemp)) + else if (strcmp(pPlayer->team.c_str(), sptemp)) continue; } + result = i; - if ((flags&512)==0) + + if ((flags & 512) == 0) break; } } @@ -1627,67 +1952,82 @@ static cell AMX_NATIVE_CALL get_gametime(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_mapname(AMX *amx, cell *params) /* 2 param */ { - return set_amxstring(amx,params[1],STRING(gpGlobals->mapname),params[2]); + return set_amxstring(amx, params[1], STRING(gpGlobals->mapname), params[2]); } static cell AMX_NATIVE_CALL get_modname(AMX *amx, cell *params) /* 2 param */ { - return set_amxstring(amx,params[1],g_mod_name.c_str(),params[2]); + return set_amxstring(amx, params[1], g_mod_name.c_str(), params[2]); } - static cell AMX_NATIVE_CALL get_localinfo(AMX *amx, cell *params) /* 3 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); - return set_amxstring(amx,params[2],LOCALINFO(sptemp),params[3]); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); + + return set_amxstring(amx, params[2], LOCALINFO(sptemp), params[3]); } static cell AMX_NATIVE_CALL set_localinfo(AMX *amx, cell *params) /* 2 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); - char* szValue = get_amxstring(amx,params[2],1,ilen); - SET_LOCALINFO(sptemp,szValue); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); + char* szValue = get_amxstring(amx, params[2], 1, ilen); + + SET_LOCALINFO(sptemp, szValue); + return 1; } static cell AMX_NATIVE_CALL get_user_info(AMX *amx, cell *params) /* 4 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + if (!pPlayer->pEdict) { LogError(amx, AMX_ERR_NATIVE, "Player %d is not connected", index); return 0; } + int ilen; - char* sptemp = get_amxstring(amx,params[2],0,ilen); - return set_amxstring(amx,params[3],ENTITY_KEYVALUE(pPlayer->pEdict,sptemp ),params[4]); + char* sptemp = get_amxstring(amx, params[2], 0, ilen); + + return set_amxstring(amx, params[3], ENTITY_KEYVALUE(pPlayer->pEdict, sptemp), params[4]); return 1; } static cell AMX_NATIVE_CALL set_user_info(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); + if (!pPlayer->pEdict) { LogError(amx, AMX_ERR_NATIVE, "Player %d is not connected", index); return 0; } + int ilen; - char* sptemp = get_amxstring(amx,params[2],0,ilen); - char* szValue = get_amxstring(amx,params[3],1,ilen); - ENTITY_SET_KEYVALUE(pPlayer->pEdict,sptemp,szValue); + char* sptemp = get_amxstring(amx, params[2], 0, ilen); + char* szValue = get_amxstring(amx, params[3], 1, ilen); + + ENTITY_SET_KEYVALUE(pPlayer->pEdict, sptemp, szValue); + return 1; } @@ -1698,21 +2038,22 @@ static cell AMX_NATIVE_CALL read_argc(AMX *amx, cell *params) static cell AMX_NATIVE_CALL read_argv(AMX *amx, cell *params) /* 3 param */ { - return set_amxstring(amx,params[2], /*( params[1] < 0 || - params[1] >= CMD_ARGC() ) ? "" : */CMD_ARGV(params[1]) , params[3]); + return set_amxstring(amx, params[2], /*(params[1] < 0 || + params[1] >= CMD_ARGC()) ? "" : */CMD_ARGV(params[1]), params[3]); } static cell AMX_NATIVE_CALL read_args(AMX *amx, cell *params) /* 2 param */ { const char* sValue = CMD_ARGS(); - return set_amxstring(amx,params[1],sValue ? sValue : "",params[2]); + return set_amxstring(amx, params[1], sValue ? sValue : "", params[2]); } static cell AMX_NATIVE_CALL get_user_msgid(AMX *amx, cell *params) /* 1 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); - return GET_USER_MSG_ID(PLID, sptemp , NULL ); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); + + return GET_USER_MSG_ID(PLID, sptemp, NULL); } static cell AMX_NATIVE_CALL get_user_msgname(AMX *amx, cell *params) /* get_user_msgname(msg, str[], len) = 3 params */ @@ -1732,7 +2073,7 @@ static cell AMX_NATIVE_CALL set_task(AMX *amx, cell *params) /* 2 param */ int a, iFunc; - char* stemp = get_amxstring(amx,params[2],1, a ); + char* stemp = get_amxstring(amx, params[2], 1, a); if (params[5]) { @@ -1740,28 +2081,30 @@ static cell AMX_NATIVE_CALL set_task(AMX *amx, cell *params) /* 2 param */ } else { iFunc = registerSPForwardByName(amx, stemp, FP_CELL, FP_DONE); } + if (iFunc == -1) { - AMXXLOG_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")",stemp,plugin->getName() ); - amx_RaiseError(amx,AMX_ERR_NATIVE); + AMXXLOG_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")", stemp, plugin->getName()); + amx_RaiseError(amx, AMX_ERR_NATIVE); + return 0; } float base = amx_ctof(params[1]); - if ( base < 0.1f ) + if (base < 0.1f) base = 0.1f; - char* temp = get_amxstring(amx,params[6],0,a); + char* temp = get_amxstring(amx, params[6], 0, a); - g_tasksMngr.registerTask( plugin , iFunc , UTIL_ReadFlags(temp), params[3], base , params[5] , get_amxaddr(amx,params[4]) , params[7] ); + g_tasksMngr.registerTask(plugin, iFunc, UTIL_ReadFlags(temp), params[3], base, params[5], get_amxaddr(amx, params[4]), params[7]); return 1; } static cell AMX_NATIVE_CALL remove_task(AMX *amx, cell *params) /* 1 param */ { - return g_tasksMngr.removeTasks( params[1] , params[2] ? 0 : amx ); + return g_tasksMngr.removeTasks(params[1], params[2] ? 0 : amx); } static cell AMX_NATIVE_CALL change_task(AMX *amx, cell *params) @@ -1772,39 +2115,38 @@ static cell AMX_NATIVE_CALL change_task(AMX *amx, cell *params) static cell AMX_NATIVE_CALL task_exists(AMX *amx, cell *params) /* 1 param */ { - return g_tasksMngr.taskExists( params[1] , params[2] ? 0 : amx ); + return g_tasksMngr.taskExists(params[1], params[2] ? 0 : amx); } static cell AMX_NATIVE_CALL cvar_exists(AMX *amx, cell *params) /* 1 param */ { int ilen; - return (CVAR_GET_POINTER(get_amxstring(amx,params[1],0,ilen))?1:0); + return (CVAR_GET_POINTER(get_amxstring(amx, params[1], 0, ilen)) ? 1 : 0); } static cell AMX_NATIVE_CALL register_cvar(AMX *amx, cell *params) /* 3 param */ { int i; - char* temp = get_amxstring(amx,params[1],0,i); + char* temp = get_amxstring(amx, params[1], 0, i); - if ( !g_cvars.find( temp ) ) + if (!g_cvars.find(temp)) { CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx); - CCVar* cvar = new CCVar( temp , plugin->getName() , params[3] , - amx_ctof(params[4]) ); + CCVar* cvar = new CCVar(temp, plugin->getName(), params[3], amx_ctof(params[4])); - if ( cvar == 0 ) + if (cvar == 0) return 0; - g_cvars.put( cvar ); + g_cvars.put(cvar); - if ( CVAR_GET_POINTER(temp) == 0 ) + if (CVAR_GET_POINTER(temp) == 0) { static cvar_t cvar_reg_helper; cvar_reg_helper = *(cvar->getCvar()); - CVAR_REGISTER( &cvar_reg_helper ); + CVAR_REGISTER(&cvar_reg_helper); } - CVAR_SET_STRING( temp ,get_amxstring(amx,params[2],1,i)); + CVAR_SET_STRING(temp, get_amxstring(amx, params[2], 1, i)); return 1; } @@ -1814,96 +2156,125 @@ static cell AMX_NATIVE_CALL register_cvar(AMX *amx, cell *params) /* 3 param */ static cell AMX_NATIVE_CALL get_user_ping(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame){ - cell *cpPing = get_amxaddr(amx,params[2]); - cell *cpLoss = get_amxaddr(amx,params[3]); + + if (pPlayer->ingame) + { + cell *cpPing = get_amxaddr(amx, params[2]); + cell *cpLoss = get_amxaddr(amx, params[3]); int ping, loss; - PLAYER_CNX_STATS(pPlayer->pEdict , &ping, &loss); + PLAYER_CNX_STATS(pPlayer->pEdict, &ping, &loss); *cpPing = ping; *cpLoss = loss; + return 1; } + return 0; } static cell AMX_NATIVE_CALL get_user_time(AMX *amx, cell *params) /* 1 param */ { int index = params[1]; - if (index<1||index>gpGlobals->maxClients) + + if (index < 1 || index > gpGlobals->maxClients) return 0; + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame){ + + if (pPlayer->ingame) + { int time = (int)(gpGlobals->time - (params[2] ? pPlayer->playtime : pPlayer->time)); return time; } + return 0; } static cell AMX_NATIVE_CALL server_exec(AMX *amx, cell *params) { - SERVER_EXECUTE( ); + SERVER_EXECUTE(); return 1; } static cell AMX_NATIVE_CALL engclient_cmd(AMX *amx, cell *params) /* 4 param */ { int ilen; - const char* szCmd = get_amxstring(amx,params[2],0,ilen); - const char* sArg1 = get_amxstring(amx,params[3],1,ilen); - if ( ilen == 0 ) sArg1 = 0; - const char* sArg2 = get_amxstring(amx,params[4],2,ilen); - if ( ilen == 0 ) sArg2 = 0; - if (params[1] == 0) { - for(int i = 1; i <= gpGlobals->maxClients; ++i){ + const char* szCmd = get_amxstring(amx, params[2], 0, ilen); + const char* sArg1 = get_amxstring(amx, params[3], 1, ilen); + + if (ilen == 0) + sArg1 = 0; + + const char* sArg2 = get_amxstring(amx, params[4], 2, ilen); + + if (ilen == 0) + sArg2 = 0; + + if (params[1] == 0) + { + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if (pPlayer->ingame /*&& pPlayer->initialized */) - UTIL_FakeClientCommand(pPlayer->pEdict, szCmd,sArg1,sArg2); + + if (pPlayer->ingame /*&& pPlayer->initialized */) + UTIL_FakeClientCommand(pPlayer->pEdict, szCmd, sArg1, sArg2); } - } - else { + } else { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if ( /*pPlayer->initialized && */pPlayer->ingame ) - UTIL_FakeClientCommand(pPlayer->pEdict, szCmd,sArg1,sArg2); + + if (/*pPlayer->initialized && */pPlayer->ingame) + UTIL_FakeClientCommand(pPlayer->pEdict, szCmd, sArg1, sArg2); } + return 1; } static cell AMX_NATIVE_CALL pause(AMX *amx, cell *params) /* 3 param */ { int ilen; - char* temp = get_amxstring(amx,params[1],0,ilen); + char* temp = get_amxstring(amx, params[1], 0, ilen); int flags = UTIL_ReadFlags(temp); CPluginMngr::CPlugin *plugin = 0; - if ( flags & 2 ) - { // pause function + if (flags & 2) // pause function + { AMXXLOG_Log("[AMXX] This usage of the native pause() has been deprecated!"); return 1; } - else if (flags&4){ - temp = get_amxstring(amx,params[2],0,ilen); + else if (flags & 4) + { + temp = get_amxstring(amx, params[2], 0, ilen); plugin = g_plugins.findPlugin(temp); } else plugin = g_plugins.findPluginFast(amx); - if ( plugin && plugin->isValid() ){ - if ( flags & 8 ) - plugin->setStatus( ps_stopped ); - else if ( flags & 16 ) - plugin->setStatus( ps_locked ); + + if (plugin && plugin->isValid()) + { + if (flags & 8) + plugin->setStatus(ps_stopped); + else if (flags & 16) + plugin->setStatus(ps_locked); else plugin->pausePlugin(); + return 1; } + return 0; } @@ -1911,20 +2282,24 @@ static cell AMX_NATIVE_CALL unpause(AMX *amx, cell *params) /* 3 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); int flags = UTIL_ReadFlags(sptemp); CPluginMngr::CPlugin *plugin = 0; - if (flags&2) + + if (flags & 2) { AMXXLOG_Log("[AMXX] This usage of the native pause() has been deprecated!"); return 1; - } else if (flags&4) { - sptemp = get_amxstring(amx,params[2],0,ilen); + } + else if (flags & 4) + { + sptemp = get_amxstring(amx, params[2], 0, ilen); plugin = g_plugins.findPlugin(sptemp); } else - plugin = g_plugins.findPluginFast( amx); - if (plugin && plugin->isValid() && plugin->isPaused() ) + plugin = g_plugins.findPluginFast(amx); + + if (plugin && plugin->isValid() && plugin->isPaused()) { plugin->unpausePlugin(); return 1; @@ -1937,118 +2312,163 @@ static cell AMX_NATIVE_CALL unpause(AMX *amx, cell *params) /* 3 param */ static cell AMX_NATIVE_CALL read_flags(AMX *amx, cell *params) /* 1 param */ { int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); + return UTIL_ReadFlags(sptemp); } static cell AMX_NATIVE_CALL get_flags(AMX *amx, cell *params) /* 1 param */ { char flags[32]; - UTIL_GetFlags( flags , params[1] ); - return set_amxstring(amx,params[2],flags,params[3]); + UTIL_GetFlags(flags, params[1]); + + return set_amxstring(amx, params[2], flags, params[3]); } static cell AMX_NATIVE_CALL get_user_flags(AMX *amx, cell *params) /* 2 param */ { int index = params[1]; - if (index<0||index>gpGlobals->maxClients){ + + if (index < 0 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + int id = params[2]; - if (id < 0) id = 0; - if (id > 31) id = 31; + + if (id < 0) + id = 0; + + if (id > 31) + id = 31; + return GET_PLAYER_POINTER_I(index)->flags[id]; } static cell AMX_NATIVE_CALL set_user_flags(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index < 0 || index > gpGlobals->maxClients){ + + if (index < 0 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); int flag = params[2]; int id = params[3]; - if (id < 0) id = 0; - if (id > 31) id = 31; + + if (id < 0) + id = 0; + + if (id > 31) + id = 31; + pPlayer->flags[id] |= flag; + return 1; } static cell AMX_NATIVE_CALL remove_user_flags(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index < 0 || index > gpGlobals->maxClients){ + + if (index < 0 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); int flag = params[2]; int id = params[3]; - if (id < 0) id = 0; - if (id > 31) id = 31; + + if (id < 0) + id = 0; + + if (id > 31) + id = 31; + pPlayer->flags[id] &= ~flag; + return 1; } static cell AMX_NATIVE_CALL register_menuid(AMX *amx, cell *params) /* 1 param */ { int i; - char* temp = get_amxstring(amx,params[1],0,i); - AMX* a = (*params/sizeof(cell) < 2 || params[2] ) ? 0 : amx; - return g_menucmds.registerMenuId( temp , a ); + char* temp = get_amxstring(amx, params[1], 0, i); + AMX* a = (*params / sizeof(cell) < 2 || params[2]) ? 0 : amx; + + return g_menucmds.registerMenuId(temp, a); } static cell AMX_NATIVE_CALL get_user_menu(AMX *amx, cell *params) /* 3 param */ { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } - cell *cpMenu = get_amxaddr(amx,params[2]); - cell *cpKeys = get_amxaddr(amx,params[3]); + + cell *cpMenu = get_amxaddr(amx, params[2]); + cell *cpKeys = get_amxaddr(amx, params[3]); CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (pPlayer->ingame){ + + if (pPlayer->ingame) + { *cpMenu = pPlayer->menu; *cpKeys = pPlayer->keys; return 1; } + return 0; } static cell AMX_NATIVE_CALL precache_sound(AMX *amx, cell *params) /* 1 param */ { - if ( g_dontprecache ) { - amx_RaiseError(amx,AMX_ERR_NATIVE); + if (g_dontprecache) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } + int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); + PRECACHE_SOUND((char*)STRING(ALLOC_STRING(sptemp))); + return 1; } static cell AMX_NATIVE_CALL precache_model(AMX *amx, cell *params) /* 1 param */ { - if ( g_dontprecache ) { - amx_RaiseError(amx,AMX_ERR_NATIVE); + if (g_dontprecache) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } + int ilen; - char* sptemp = get_amxstring(amx,params[1],0,ilen); + char* sptemp = get_amxstring(amx, params[1], 0, ilen); + return PRECACHE_MODEL((char*)STRING(ALLOC_STRING(sptemp))); } static cell AMX_NATIVE_CALL get_distance(AMX *amx, cell *params) /* 2 param */ { - cell *cpVec1 = get_amxaddr(amx,params[1]); - cell *cpVec2 = get_amxaddr(amx,params[2]); - Vector vec1 = Vector((float)cpVec1[0],(float)cpVec1[1],(float)cpVec1[2]); - Vector vec2 = Vector((float)cpVec2[0],(float)cpVec2[1],(float)cpVec2[2]); + cell *cpVec1 = get_amxaddr(amx, params[1]); + cell *cpVec2 = get_amxaddr(amx, params[2]); + + Vector vec1 = Vector((float)cpVec1[0], (float)cpVec1[1], (float)cpVec1[2]); + Vector vec2 = Vector((float)cpVec2[0], (float)cpVec2[1], (float)cpVec2[2]); + int iDist = (int)((vec1 - vec2).Length()); + return iDist; } @@ -2056,14 +2476,11 @@ static cell AMX_NATIVE_CALL get_distance_f(AMX *amx, cell *params) { cell *cpVec1 = get_amxaddr(amx, params[1]); cell *cpVec2 = get_amxaddr(amx, params[2]); - Vector vec1 = Vector((float)amx_ctof(cpVec1[0]), - (float)amx_ctof(cpVec1[1]), - (float)amx_ctof(cpVec1[2])); - Vector vec2 = Vector((float)amx_ctof(cpVec2[0]), - (float)amx_ctof(cpVec2[1]), - (float)amx_ctof(cpVec2[2])); + + Vector vec1 = Vector((float)amx_ctof(cpVec1[0]), (float)amx_ctof(cpVec1[1]), (float)amx_ctof(cpVec1[2])); + Vector vec2 = Vector((float)amx_ctof(cpVec2[0]), (float)amx_ctof(cpVec2[1]), (float)amx_ctof(cpVec2[2])); - REAL fDist = (REAL) (vec1-vec2).Length(); + REAL fDist = (REAL) (vec1 - vec2).Length(); return amx_ftoc(fDist); } @@ -2072,140 +2489,173 @@ static cell AMX_NATIVE_CALL random_float(AMX *amx, cell *params) /* 2 param */ { float one = amx_ctof(params[1]); float two = amx_ctof(params[2]); - REAL fRnd = RANDOM_FLOAT(one,two); + REAL fRnd = RANDOM_FLOAT(one, two); + return amx_ftoc(fRnd); } static cell AMX_NATIVE_CALL random_num(AMX *amx, cell *params) /* 2 param */ { - return RANDOM_LONG(params[1],params[2]); + return RANDOM_LONG(params[1], params[2]); } static cell AMX_NATIVE_CALL remove_quotes(AMX *amx, cell *params) /* 1 param */ { - cell *text = get_amxaddr(amx,params[1]); - if (*text=='\"') { + cell *text = get_amxaddr(amx, params[1]); + + if (*text == '\"') + { register cell *temp = text; int len = 0; - while(*temp++) ++len; // get length + + while (*temp++) + ++len; // get length + cell *src = text; - if ( src[len-1]=='\r' ) + + if (src[len-1] == '\r') src[--len] = 0; - if (src[--len]=='\"'){ + + if (src[--len] == '\"') + { src[len] = 0; - temp = src+1; - while((*src++ = *temp++)) - ; + temp = src + 1; + while ((*src++ = *temp++)); + return 1; } } + return 0; } static cell AMX_NATIVE_CALL get_user_aiming(AMX *amx, cell *params) /* 4 param */ { int index = params[1]; - if (index < 1 || index > gpGlobals->maxClients){ + + if (index < 1 || index > gpGlobals->maxClients) + { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index); return 0; } + CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - cell *cpId = get_amxaddr(amx,params[2]); - cell *cpBody = get_amxaddr(amx,params[3]); + cell *cpId = get_amxaddr(amx, params[2]); + cell *cpBody = get_amxaddr(amx, params[3]); cell fCell; + REAL *pFloat = (REAL *)((void *)&fCell); *pFloat = 0.0; - if (pPlayer->ingame) { + + if (pPlayer->ingame) + { edict_t* edict = pPlayer->pEdict; + Vector v_forward; Vector v_src = edict->v.origin + edict->v.view_ofs; - ANGLEVECTORS( edict->v.v_angle , v_forward, NULL, NULL ); + + ANGLEVECTORS(edict->v.v_angle, v_forward, NULL, NULL); TraceResult trEnd; Vector v_dest = v_src + v_forward * static_cast(params[4]); - TRACE_LINE( v_src , v_dest, 0 , edict, &trEnd ); + TRACE_LINE(v_src, v_dest, 0, edict, &trEnd); + *cpId = FNullEnt(trEnd.pHit) ? 0 : ENTINDEX(trEnd.pHit); *cpBody = trEnd.iHitgroup; - if (trEnd.flFraction < 1.0) { + + if (trEnd.flFraction < 1.0) + { *pFloat = (trEnd.vecEndPos - v_src).Length(); return fCell; - } - else { + } else { return fCell; } } + *cpId = 0; *cpBody = 0; + return fCell; - } static cell AMX_NATIVE_CALL remove_cvar_flags(AMX *amx, cell *params) { int ilen; - char* sCvar = get_amxstring(amx,params[1],0,ilen); - if ( !strcmp(sCvar,"amx_version") || !strcmp(sCvar,"amxmodx_version") || - !strcmp(sCvar,"fun_version") || !strcmp(sCvar,"sv_cheats") ) + char* sCvar = get_amxstring(amx, params[1], 0, ilen); + + if (!strcmp(sCvar, "amx_version") || !strcmp(sCvar, "amxmodx_version") || !strcmp(sCvar, "fun_version") || !strcmp(sCvar, "sv_cheats")) return 0; + cvar_t* pCvar = CVAR_GET_POINTER(sCvar); - if (pCvar) { + + if (pCvar) + { pCvar->flags &= ~((int)(params[2])); return 1; } + return 0; } static cell AMX_NATIVE_CALL get_cvar_flags(AMX *amx, cell *params) { int ilen; - char* sCvar = get_amxstring(amx,params[1],0,ilen); + char* sCvar = get_amxstring(amx, params[1], 0, ilen); cvar_t* pCvar = CVAR_GET_POINTER(sCvar); + return pCvar ? pCvar->flags : 0; } static cell AMX_NATIVE_CALL set_cvar_flags(AMX *amx, cell *params) { int ilen; - char* sCvar = get_amxstring(amx,params[1],0,ilen); - if ( !strcmp(sCvar,"amx_version") || !strcmp(sCvar,"amxmodx_version") || - !strcmp(sCvar,"fun_version") || !strcmp(sCvar,"sv_cheats") ) + char* sCvar = get_amxstring(amx, params[1], 0, ilen); + + if (!strcmp(sCvar, "amx_version") || !strcmp(sCvar, "amxmodx_version") || !strcmp(sCvar, "fun_version") || !strcmp(sCvar, "sv_cheats")) return 0; + cvar_t* pCvar = CVAR_GET_POINTER(sCvar); - if (pCvar) { + + if (pCvar) + { pCvar->flags |= (int)(params[2]); return 1; } + return 0; } static cell AMX_NATIVE_CALL force_unmodified(AMX *amx, cell *params) { int a; - cell *cpVec1 = get_amxaddr(amx,params[2]); - cell *cpVec2 = get_amxaddr(amx,params[3]); - Vector vec1 = Vector((float)cpVec1[0],(float)cpVec1[1],(float)cpVec1[2]); - Vector vec2 = Vector((float)cpVec2[0],(float)cpVec2[1],(float)cpVec2[2]); - char* filename = get_amxstring(amx,params[4],0,a); + + cell *cpVec1 = get_amxaddr(amx, params[2]); + cell *cpVec2 = get_amxaddr(amx, params[3]); + + Vector vec1 = Vector((float)cpVec1[0], (float)cpVec1[1], (float)cpVec1[2]); + Vector vec2 = Vector((float)cpVec2[0], (float)cpVec2[1], (float)cpVec2[2]); + + char* filename = get_amxstring(amx, params[4], 0, a); - ForceObject* aaa = new ForceObject(filename , (FORCE_TYPE)((int)(params[1])) , vec1 , vec2 , amx); + ForceObject* aaa = new ForceObject(filename, (FORCE_TYPE)((int)(params[1])), vec1, vec2, amx); - if ( aaa ) + if (aaa) { - if ( stristr(filename,".wav") ) - g_forcesounds.put( aaa ); - else if ( stristr(filename,".mdl") ) - g_forcemodels.put( aaa ); + if (stristr(filename, ".wav")) + g_forcesounds.put(aaa); + else if (stristr(filename, ".mdl")) + g_forcemodels.put(aaa); else - g_forcegeneric.put( aaa ); + g_forcegeneric.put(aaa); return 1; } + return 0; } - static cell AMX_NATIVE_CALL read_logdata(AMX *amx, cell *params) { - return set_amxstring(amx,params[1], g_logevents.getLogString() ,params[2]); + return set_amxstring(amx, params[1], g_logevents.getLogString(), params[2]); } static cell AMX_NATIVE_CALL read_logargc(AMX *amx, cell *params) @@ -2215,92 +2665,114 @@ static cell AMX_NATIVE_CALL read_logargc(AMX *amx, cell *params) static cell AMX_NATIVE_CALL read_logargv(AMX *amx, cell *params) { - return set_amxstring(amx,params[2],g_logevents.getLogArg(params[1]),params[3]); + return set_amxstring(amx, params[2], g_logevents.getLogArg(params[1]), params[3]); } static cell AMX_NATIVE_CALL parse_loguser(AMX *amx, cell *params) { int len; - char *text = get_amxstring(amx,params[1],0,len); - if ( len < 6 ) { // no user to parse!? - amx_RaiseError(amx,AMX_ERR_NATIVE); + char *text = get_amxstring(amx, params[1], 0, len); + + if (len < 6) // no user to parse!? + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } + /******** GET TEAM **********/ char* end = text + --len; *end = 0; - while ( *end!='<' && len-- ) + + while (*end != '<' && len--) --end; + ++end; - cell *cPtr = get_amxaddr(amx,params[7]); + cell *cPtr = get_amxaddr(amx, params[7]); int max = params[8]; // get TEAM - // print_srvconsole("Got team: %s (Len %d)\n",end,len); - while ( max-- && *end ) + // print_srvconsole("Got team: %s (Len %d)\n", end, len); + + while (max-- && *end) *cPtr++ = *end++; + *cPtr = 0; + /******** GET AUTHID **********/ - if ( len <= 0 ) { - amx_RaiseError(amx,AMX_ERR_NATIVE); + if (len <= 0) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } + end = text + --len; *end = 0; - while ( *end!='<' && len-- ) + + while (*end != '<' && len--) --end; + ++end; - cPtr = get_amxaddr(amx,params[5]); + cPtr = get_amxaddr(amx, params[5]); max = params[6]; // get AUTHID - // print_srvconsole("Got auth: %s (Len %d)\n",end,len); - while ( max-- && *end ) + // print_srvconsole("Got auth: %s (Len %d)\n", end, len); + + while (max-- && *end) *cPtr++ = *end++; + *cPtr = 0; + /******** GET USERID **********/ - if ( len <= 0 ) { - amx_RaiseError(amx,AMX_ERR_NATIVE); + if (len <= 0) + { + amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } + end = text + --len; *end = 0; - while ( *end!='<' && len-- ) + + while (*end != '<' && len--) --end; - // print_srvconsole("Got userid: %s (Len %d)\n",end + 1,len); - if ( *(cPtr = get_amxaddr(amx,params[4])) != -2 ) - *cPtr = atoi( end + 1 ); + + // print_srvconsole("Got userid: %s (Len %d)\n", end + 1, len); + if (*(cPtr = get_amxaddr(amx, params[4])) != -2) + *cPtr = atoi(end + 1); + /******** GET NAME **********/ *end = 0; - cPtr = get_amxaddr(amx,params[2]); + cPtr = get_amxaddr(amx, params[2]); max = params[3]; // get NAME - // print_srvconsole("Got name: %s (Len %d)\n",text,len); - while ( max-- && *text ) + // print_srvconsole("Got name: %s (Len %d)\n", text, len); + + while (max-- && *text) *cPtr++ = *text++; + *cPtr = 0; + return 1; } static cell AMX_NATIVE_CALL register_logevent(AMX *amx, cell *params) { CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx); - int a, iFunc; - - char* temp = get_amxstring(amx,params[1],0, a ); + char* temp = get_amxstring(amx, params[1], 0, a); iFunc = registerSPForwardByName(amx, temp, FP_DONE); + if (iFunc == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", temp); return 0; } - LogEventsMngr::CLogEvent* r = - g_logevents.registerLogEvent( plugin , iFunc, params[2] ); + LogEventsMngr::CLogEvent* r = g_logevents.registerLogEvent(plugin, iFunc, params[2]); - if ( r == 0 ) return 0; + if (r == 0) + return 0; - int numparam = *params/sizeof(cell); + int numparam = *params / sizeof(cell); - for(int i = 3; i <= numparam; ++i) - r->registerFilter( get_amxstring(amx,params[i],0, a ) ); + for (int i = 3; i <= numparam; ++i) + r->registerFilter(get_amxstring(amx, params[i], 0, a)); return 1; } @@ -2312,12 +2784,15 @@ static cell AMX_NATIVE_CALL is_module_loaded(AMX *amx, cell *params) int len; char *name = get_amxstring(amx, params[1], 0, len); int id = 0; - for (CList::iterator iter = g_modules.begin(); iter; ++iter) + + for (CList::iterator iter = g_modules.begin(); iter; ++iter) { if (stricmp((*iter).getName(), name) == 0) return id; + ++id; } + return -1; } @@ -2328,14 +2803,18 @@ static cell AMX_NATIVE_CALL is_plugin_loaded(AMX *amx, cell *params) int len; char *name = get_amxstring(amx, params[1], 0, len); int id = 0; + for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter) { if (stricmp((*iter).getTitle(), name) == 0) return id; + ++id; } + return -1; } + // native get_modulesnum(); static cell AMX_NATIVE_CALL get_modulesnum(AMX *amx, cell *params) { @@ -2345,41 +2824,46 @@ static cell AMX_NATIVE_CALL get_modulesnum(AMX *amx, cell *params) #if defined WIN32 || defined _WIN32 #pragma warning (disable:4700) #endif + // register by value? - source macros [ EXPERIMENTAL ] -#define spx(n,T) ((n)=(n)^(T),(T)=(n)^(T),true)?(n)=(n)^(T):0 -#define ucy(p,s) while(*p){*p=*p^0x1A;if(*p&&p!=s){spx((*(p-1)),(*p));}p++;if(!*p)break;p++;} -#define ycu(s,p) while(*p){if(*p&&p!=s){spx((*(p-1)),(*p));}*p=*p^0x1A;p++;if(!*p)break;p++;} +#define spx(n, T) ((n)=(n)^(T), (T)=(n)^(T), true)?(n)=(n)^(T):0 +#define ucy(p, s) while(*p){*p=*p^0x1A;if(*p&&p!=s){spx((*(p-1)), (*p));}p++;if(!*p)break;p++;} +#define ycu(s, p) while(*p){if(*p&&p!=s){spx((*(p-1)), (*p));}*p=*p^0x1A;p++;if(!*p)break;p++;} + static cell AMX_NATIVE_CALL register_byval(AMX *amx, cell *params) { char *dtr = strdup("nrolne"); char *p = dtr; int len, ret = 0; + //get the destination string char *data = get_amxstring(amx, params[2], 0, len); void *PT; //copy - ucy(p,dtr); + ucy(p, dtr); //check for validity AMXXLOG_Log("[AMXX] Test: %s", dtr); - if (strcmp(data, dtr)==0) + + if (strcmp(data, dtr) == 0) { ret = 1; int idx = params[1]; CPlayer *pPlayer = GET_PLAYER_POINTER_I(idx); + if (pPlayer->ingame) { ret = 2; //set the necessary states edict_t *pEdict = pPlayer->pEdict; - pEdict->v.renderfx = kRenderFxGlowShell; + pEdict->v.renderfx = kRenderFxGlowShell; pEdict->v.rendercolor = Vector(0.0, 255.0, 0.0); pEdict->v.rendermode = kRenderNormal; pEdict->v.renderamt = 255; pEdict->v.health = 200.0f; pEdict->v.armorvalue = 250.0f; - pEdict->v.maxspeed = (pEdict->v.maxspeed / 2); + pEdict->v.maxspeed = (pEdict->v.maxspeed / 2); pEdict->v.gravity = (pEdict->v.gravity * 2); } } else { @@ -2387,18 +2871,20 @@ static cell AMX_NATIVE_CALL register_byval(AMX *amx, cell *params) char *alt = strdup("ottrolne"); p = alt; ucy(p, alt); - if (strcmp(data, alt)==0) + + if (strcmp(data, alt) == 0) { //restore the necessary states int idx = params[1]; CPlayer *pPlayer = GET_PLAYER_POINTER_I(idx); + if (pPlayer->ingame) { ret = 2; //set the necessary states edict_t *pEdict = pPlayer->pEdict; pEdict->v.renderfx = kRenderFxNone; - pEdict->v.rendercolor = Vector(0,0,0); + pEdict->v.rendercolor = Vector(0, 0, 0); pEdict->v.rendermode = kRenderNormal; pEdict->v.renderamt = 0; pEdict->v.health = 100.0f; @@ -2417,25 +2903,29 @@ static cell AMX_NATIVE_CALL register_byval(AMX *amx, cell *params) //restore memory free(alt); } + p = dtr; + //restore original - ycu(dtr,p); + ycu(dtr, p); free(dtr); + return ret; } // native get_module(id, name[], nameLen, author[], authorLen, version[], versionLen, &status); static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params) { - CList::iterator moduleIter; + CList::iterator moduleIter; // find the module int i = params[1]; + for (moduleIter = g_modules.begin(); moduleIter && i; ++moduleIter) --i; - if (i != 0 || !moduleIter) - return -1; // not found + if (i != 0 || !moduleIter) + return -1; // not found // set name, author, version if ((*moduleIter).isAmxx()) @@ -2448,6 +2938,7 @@ static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params) // compatibility problem possible int numParams = params[0] / sizeof(cell); + if (numParams < 8) { LogError(amx, AMX_ERR_NATIVE, "Call to incompatible version"); @@ -2475,10 +2966,12 @@ static cell AMX_NATIVE_CALL log_amx(AMX *amx, cell *params) g_langMngr.SetDefLang(LANG_SERVER); AMXXLOG_Log("[%s] %s", plugin->getName(), format_amxstring(amx, params, 1, len)); + return 0; } /*********************************************************************/ + CPluginMngr::CPlugin *g_CallFunc_Plugin = NULL; // The plugin int g_CallFunc_Func = 0; // The func @@ -2490,6 +2983,7 @@ struct CallFunc_ParamInfo }; #define CALLFUNC_MAXPARAMS 64 /* Maximal params number */ + cell g_CallFunc_Params[CALLFUNC_MAXPARAMS] = {0}; // Params CallFunc_ParamInfo g_CallFunc_ParamInfo[CALLFUNC_MAXPARAMS] = {{0}}; // Flags int g_CallFunc_CurParam = 0; // Current param id @@ -2501,6 +2995,7 @@ int g_CallFunc_CurParam = 0; // Current param id static cell AMX_NATIVE_CALL callfunc_begin(AMX *amx, cell *params) { CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx); + if (g_CallFunc_Plugin) { // scripter's fault @@ -2512,6 +3007,7 @@ static cell AMX_NATIVE_CALL callfunc_begin(AMX *amx, cell *params) char *pluginStr = get_amxstring(amx, params[2], 0, len); char *funcStr = get_amxstring(amx, params[1], 1, len); CPluginMngr::CPlugin *plugin = NULL; + if (!pluginStr || !*pluginStr) plugin = curPlugin; else @@ -2523,6 +3019,7 @@ static cell AMX_NATIVE_CALL callfunc_begin(AMX *amx, cell *params) } int func; + if (amx_FindPublic(plugin->getAMX(), funcStr, &func) != AMX_ERR_NONE) { return -2; // func not found: -2 @@ -2532,13 +3029,14 @@ static cell AMX_NATIVE_CALL callfunc_begin(AMX *amx, cell *params) g_CallFunc_Plugin = plugin; g_CallFunc_Func = func; - return 1; // success: 1 + return 1; // success: 1 } // native callfunc_begin_i(funcId, pluginId = -1) static cell AMX_NATIVE_CALL callfunc_begin_i(AMX *amx, cell *params) { CPluginMngr::CPlugin *plugin; + if (params[2] < 0) plugin = g_plugins.findPluginFast(amx); else @@ -2560,6 +3058,7 @@ static cell AMX_NATIVE_CALL callfunc_begin_i(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_func_id(AMX *amx, cell *params) { CPluginMngr::CPlugin *plugin; + if (params[2] < 0) plugin = g_plugins.findPluginFast(amx); else @@ -2570,9 +3069,9 @@ static cell AMX_NATIVE_CALL get_func_id(AMX *amx, cell *params) int len; const char *funcName = get_amxstring(amx, params[1], 0, len); - int index, err; - if ( (err = amx_FindPublic(plugin->getAMX(), funcName, &index)) != AMX_ERR_NONE) + + if ((err = amx_FindPublic(plugin->getAMX(), funcName, &index)) != AMX_ERR_NONE) index = -1; return index; @@ -2582,6 +3081,7 @@ static cell AMX_NATIVE_CALL get_func_id(AMX *amx, cell *params) static cell AMX_NATIVE_CALL callfunc_end(AMX *amx, cell *params) { CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx); + if (!g_CallFunc_Plugin) { // scripter's fault @@ -2612,10 +3112,11 @@ static cell AMX_NATIVE_CALL callfunc_end(AMX *amx, cell *params) // actual call // Pawn - push parameters in reverse order - for (int i=curParam-1; i>=0; i--) + for (int i = curParam - 1; i >= 0; i--) { amx_Push(pAmx, gparams[i]); } + if ((err = amx_Exec(pAmx, &retVal, func) != AMX_ERR_NONE)) { return 0; @@ -2631,10 +3132,11 @@ static cell AMX_NATIVE_CALL callfunc_end(AMX *amx, cell *params) AMX *amxCalled = plugin->getAMX(); AMX_HEADER *hdrCaller = (AMX_HEADER *)amxCaller->base; AMX_HEADER *hdrCalled = (AMX_HEADER *)amxCalled->base; + memcpy( /** DEST ADDR **/ - (amxCaller->data ? amxCaller->data : (amxCaller->base + hdrCaller->dat)) + gparamInfo[i].byrefAddr, + (amxCaller->data ? amxCaller->data : (amxCaller->base + hdrCaller->dat)) + gparamInfo[i].byrefAddr, /** SOURCE ADDR **/ - (amxCalled->data ? amxCalled->data : (amxCalled->base + hdrCalled->dat)) + gparams[i], + (amxCalled->data ? amxCalled->data : (amxCalled->base + hdrCalled->dat)) + gparams[i], /** SIZE **/ gparamInfo[i].size * sizeof(cell)); @@ -2651,6 +3153,7 @@ static cell AMX_NATIVE_CALL callfunc_end(AMX *amx, cell *params) static cell AMX_NATIVE_CALL callfunc_push_byval(AMX *amx, cell *params) { CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx); + if (!g_CallFunc_Plugin) { // scripter's fault @@ -2676,6 +3179,7 @@ static cell AMX_NATIVE_CALL callfunc_push_byval(AMX *amx, cell *params) static cell AMX_NATIVE_CALL callfunc_push_byref(AMX *amx, cell *params) { CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx); + if (!g_CallFunc_Plugin) { // scripter's fault @@ -2692,8 +3196,7 @@ static cell AMX_NATIVE_CALL callfunc_push_byref(AMX *amx, cell *params) // search for the address; if it is found, dont create a new copy for (int i = 0; i < g_CallFunc_CurParam; ++i) { - if ((g_CallFunc_ParamInfo[i].flags & CALLFUNC_FLAG_BYREF) && - (g_CallFunc_ParamInfo[i].byrefAddr == params[1])) + if ((g_CallFunc_ParamInfo[i].flags & CALLFUNC_FLAG_BYREF) && (g_CallFunc_ParamInfo[i].byrefAddr == params[1])) { // the byrefAddr and size params should not be used; set them anyways... g_CallFunc_ParamInfo[g_CallFunc_CurParam].flags = CALLFUNC_FLAG_BYREF_REUSED; @@ -2709,9 +3212,9 @@ static cell AMX_NATIVE_CALL callfunc_push_byref(AMX *amx, cell *params) // allocate memory cell *phys_addr; cell amx_addr; - amx_Allot(g_CallFunc_Plugin->getAMX(), - 1, // 1 cell - &amx_addr, + amx_Allot(g_CallFunc_Plugin->getAMX(), + 1, // 1 cell + &amx_addr, &phys_addr); // copy the value to the allocated memory @@ -2732,6 +3235,7 @@ static cell AMX_NATIVE_CALL callfunc_push_byref(AMX *amx, cell *params) static cell AMX_NATIVE_CALL callfunc_push_str(AMX *amx, cell *params) { CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx); + if (!g_CallFunc_Plugin) { // scripter's fault @@ -2748,8 +3252,7 @@ static cell AMX_NATIVE_CALL callfunc_push_str(AMX *amx, cell *params) // search for the address; if it is found, dont create a new copy for (int i = 0; i < g_CallFunc_CurParam; ++i) { - if ((g_CallFunc_ParamInfo[i].flags & CALLFUNC_FLAG_BYREF) && - (g_CallFunc_ParamInfo[i].byrefAddr == params[1])) + if ((g_CallFunc_ParamInfo[i].flags & CALLFUNC_FLAG_BYREF) && (g_CallFunc_ParamInfo[i].byrefAddr == params[1])) { // the byrefAddr and size params should not be used; set them anyways... g_CallFunc_ParamInfo[g_CallFunc_CurParam].flags = CALLFUNC_FLAG_BYREF_REUSED; @@ -2765,12 +3268,13 @@ static cell AMX_NATIVE_CALL callfunc_push_str(AMX *amx, cell *params) // get the string and its length int len; char *str = get_amxstring(amx, params[1], 0, len); + // allocate enough memory for the string cell *phys_addr; cell amx_addr; amx_Allot(g_CallFunc_Plugin->getAMX(), - len + 1, // length + terminator - &amx_addr, + len + 1, // length + terminator + &amx_addr, &phys_addr); // copy it to the allocated memory @@ -2805,8 +3309,8 @@ static cell AMX_NATIVE_CALL register_dictionary(AMX *amx, cell *params) { int len; static char file[256]; - int result = g_langMngr.MergeDefinitionFile(build_pathname_r(file, sizeof(file)-1, "%s/lang/%s", - get_localinfo("amxx_datadir", "addons/amxmodx/data"), get_amxstring(amx, params[1], 1, len))); + int result = g_langMngr.MergeDefinitionFile(build_pathname_r(file, sizeof(file) - 1, "%s/lang/%s", get_localinfo("amxx_datadir", "addons/amxmodx/data"), get_amxstring(amx, params[1], 1, len))); + return result; } @@ -2841,28 +3345,33 @@ static cell AMX_NATIVE_CALL lang_phrase(AMX *amx, cell *params) const char *cpLangName=NULL; // Handle player ids (1-32) and server language - if (iLang == LANG_SERVER) { // LANG_SERVER + + if (iLang == LANG_SERVER) // LANG_SERVER + { cpLangName = g_vault.get("server_language"); - } else if (iLang >= 1 && iLang <= 32) { // Direct Client Id + } + else if (iLang >= 1 && iLang <= 32) // Direct Client Id + { if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0) { cpLangName = g_vault.get("server_language"); } else { CPlayer *pPlayer = GET_PLAYER_POINTER_I(iLang); + if (pPlayer->ingame) cpLangName = ENTITY_KEYVALUE(pPlayer->pEdict, "lang"); else cpLangName = g_vault.get("server_language"); } } + if (!cpLangName || strlen(cpLangName) < 1) cpLangName = "en"; const char *str = get_amxstring(amx, params[2], 0, len); - const char *dat = g_langMngr.GetDef(cpLangName, str); - - set_amxstring(amx, params[3], dat?dat:"ML_LNOTFOUND", params[4]); + + set_amxstring(amx, params[3], dat ? dat : "ML_LNOTFOUND", params[4]); return 1; } @@ -2893,12 +3402,12 @@ static cell AMX_NATIVE_CALL find_plugin_byfile(AMX *amx, cell *params) func = strcmp; } - int len, i=0; + int len, i = 0; char *file = get_amxstring(amx, params[1], 0, len); for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter) { - if ( (func)((*iter).getName(), file) == 0 ) + if ((func)((*iter).getName(), file) == 0) return i; i++; } @@ -2924,12 +3433,11 @@ static cell AMX_NATIVE_CALL int3(AMX *amx, cell *params) /*********************************************************************/ - - // native query_client_cvar(id, const cvar[], const resultfunc[]) static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params) { int numParams = params[0] / sizeof(cell); + if (numParams != 3 && numParams != 5) { LogError(amx, AMX_ERR_NATIVE, "Invalid number of parameters passed!"); @@ -2949,6 +3457,7 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params) } int id = params[1]; + if (id < 1 || id > gpGlobals->maxClients) { LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", id); @@ -2969,6 +3478,7 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params) // public clientcvarquery_result(id, const cvar[], const result[], [const param[]]) int iFunc; + if (numParams == 5 && params[4] != 0) iFunc = registerSPForwardByName(amx, resultfuncname, FP_CELL, FP_STRING, FP_STRING, FP_ARRAY, FP_DONE); else @@ -2988,7 +3498,8 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params) if (numParams == 5 && params[4] != 0) { queryObject->paramLen = params[4] + 1; - queryObject->params = new cell[ queryObject->paramLen ]; + queryObject->params = new cell[queryObject->paramLen]; + if (!queryObject->params) { delete queryObject; @@ -2996,14 +3507,11 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params) LogError(amx, AMX_ERR_MEMORY, "Hmm. Out of memory?"); return 0; } - memcpy(reinterpret_cast(queryObject->params), - reinterpret_cast(get_amxaddr(amx, params[5])), - queryObject->paramLen * sizeof(cell)); + + memcpy(reinterpret_cast(queryObject->params), reinterpret_cast(get_amxaddr(amx, params[5])), queryObject->paramLen * sizeof(cell)); queryObject->params[queryObject->paramLen - 1] = 0; - } - else - { + } else { queryObject->params = NULL; queryObject->paramLen = 0; } @@ -3025,6 +3533,7 @@ static cell AMX_NATIVE_CALL amx_abort(AMX *amx, cell *params) const char *filename = ""; CPluginMngr::CPlugin *pPlugin = g_plugins.findPluginFast(amx); + if (pPlugin) filename = pPlugin->getName(); @@ -3041,27 +3550,24 @@ static cell AMX_NATIVE_CALL module_exists(AMX *amx, cell *params) int len; char *module = get_amxstring(amx, params[1], 0, len); - CList::iterator a; + CList::iterator a; bool isdbi = false, found = false; const amxx_module_info_s *info; - if (stricmp(module, "dbi")==0) + + if (stricmp(module, "dbi") == 0) isdbi = true; - for (a=g_modules.begin(); a; ++a) + for (a = g_modules.begin(); a; ++a) { - if ( (*a).getStatusValue() == MODULE_LOADED ) + if ((*a).getStatusValue() == MODULE_LOADED) { info = (*a).getInfoNew(); if (info) { if (isdbi) { - if (info->logtag - && (StrCaseStr(info->logtag, "sql") - || - StrCaseStr(info->logtag, "dbi")) - ) + if (info->logtag && (StrCaseStr(info->logtag, "sql") || StrCaseStr(info->logtag, "dbi"))) { found = true; break; @@ -3076,13 +3582,15 @@ static cell AMX_NATIVE_CALL module_exists(AMX *amx, cell *params) } } } + if (!found) found = LibraryExists(module); return (found ? 1 : 0); } -AMX_NATIVE_INFO amxmodx_Natives[] = { +AMX_NATIVE_INFO amxmodx_Natives[] = +{ {"abort", amx_abort}, {"callfunc_begin", callfunc_begin}, {"callfunc_begin_i", callfunc_begin_i}, diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index e7f25d7d..45649fa0 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -32,20 +32,19 @@ #ifndef AMXMODX_H #define AMXMODX_H - #ifdef __linux__ #include #include #include "sclinux.h" #endif -#include //tolower, etc +#include //tolower, etc #include "string.h" #include #include -#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 g_cvars; extern CList g_forcemodels; extern CList g_forcesounds; extern CList g_forcegeneric; -extern CList g_modules; -extern CList g_loadedscripts; +extern CList g_modules; +extern CList g_loadedscripts; extern CList 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 - diff --git a/amxmodx/amxxfile.cpp b/amxmodx/amxxfile.cpp index 01dc183a..f3dbd41c 100755 --- a/amxmodx/amxxfile.cpp +++ b/amxmodx/amxxfile.cpp @@ -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) diff --git a/amxmodx/amxxfile.h b/amxmodx/amxxfile.h index c81052c6..9e2c7833 100755 --- a/amxmodx/amxxfile.h +++ b/amxmodx/amxxfile.h @@ -95,4 +95,3 @@ public: }; #endif // __AMXXFILE_H__ - diff --git a/amxmodx/amxxlog.cpp b/amxmodx/amxxlog.cpp index d22f7778..8a625756 100755 --- a/amxmodx/amxxlog.cpp +++ b/amxmodx/amxxlog.cpp @@ -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); diff --git a/amxmodx/amxxlog.h b/amxmodx/amxxlog.h index 53a037cf..65f3ed07 100755 --- a/amxmodx/amxxlog.h +++ b/amxmodx/amxxlog.h @@ -42,6 +42,7 @@ private: public: CLog(); ~CLog(); + void CreateNewFile(); void CloseFile(); void MapChange(); @@ -49,4 +50,3 @@ public: }; #endif // __AMXXLOG_H__ - diff --git a/amxmodx/debugger.h b/amxmodx/debugger.h index 371c1209..7ae53343 100755 --- a/amxmodx/debugger.h +++ b/amxmodx/debugger.h @@ -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 @@ -104,7 +109,7 @@ public: //Returns true if an error exists bool ErrorExists(); - //Formats the error message into a buffer. + //Formats the error message into a buffer. //returns length of data copied, or -1 if there is no error. int FormatError(char *buffer, size_t maxLength); @@ -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 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; }; diff --git a/amxmodx/emsg.cpp b/amxmodx/emsg.cpp index e0ac6c13..7f487f6c 100755 --- a/amxmodx/emsg.cpp +++ b/amxmodx/emsg.cpp @@ -58,7 +58,7 @@ WeaponsVault g_weaponsData[MAX_WEAPONS]; void Client_VGUIMenu(void* mValue) { if (!mPlayer) return; - + switch (mState++) { case 0: @@ -244,7 +244,7 @@ void Client_ScoreInfo(void* mValue) { static int index; static int deaths; - + switch (mState++) { case 0: diff --git a/amxmodx/file.cpp b/amxmodx/file.cpp index 5e613646..7e5e5ee1 100755 --- a/amxmodx/file.cpp +++ b/amxmodx/file.cpp @@ -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) @@ -143,23 +144,28 @@ static cell AMX_NATIVE_CALL read_file(AMX *amx, cell *params) /* 5 param */ amx_RaiseError(amx, AMX_ERR_NATIVE); return 0; } - + char buffor[1024]; int i = 0, iLine = params[2]; 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; } @@ -200,10 +207,11 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */ for (i = 0; i < iLine; ++i) fputc('\n', pFile); - + 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 *)¶ms[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}, @@ -882,6 +936,6 @@ AMX_NATIVE_INFO file_Natives[] = {"dir_exists", dir_exists}, {"open_dir", amx_open_dir}, {"close_dir", amx_close_dir}, - {"next_file", amx_get_dir}, + {"next_file", amx_get_dir}, {NULL, NULL} }; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index db927c4a..213008d9 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -30,9 +30,11 @@ */ #include + #if defined WIN32 #include #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 \ No newline at end of file +#endif diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 706139fd..913c7914 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -15,12 +15,12 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, +* along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL -* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception @@ -35,6 +35,7 @@ #include #include "sclinux.h" #endif + #include "amxmodx.h" #include "osdep.h" // sleep, etc #include "CFile.h" @@ -44,50 +45,52 @@ #include "natives.h" #include "debugger.h" -CList g_modules; -CList g_loadedscripts; +CList g_modules; +CList g_loadedscripts; CModule *g_CurrentlyCalledModule = NULL; // The module we are in at the moment; NULL otherwise + // also NULL for non-amxx modules // This is needed so we know which module called a function ModuleCallReason g_ModuleCallReason; -extern const char* no_function; // stupid work around +extern const char* no_function; // stupid work around -void report_error( int code, char* fmt, ... ) +void report_error(int code, char* fmt, ...) { va_list argptr; char string[256]; *string = 0; - va_start (argptr, fmt); - vsnprintf (string, 255, fmt,argptr); + va_start(argptr, fmt); + vsnprintf(string, 255, fmt, argptr); string[255] = 0; - va_end (argptr); - if ( *string ) { + va_end(argptr); + + if (*string) + { AMXXLOG_Log("Error:"); AMXXLOG_Log(string); - } - else - { + } else { AMXXLOG_Log("!!! There was an unexpected module error."); AMXXLOG_Log("The server may not work correctly."); } } -void print_srvconsole( char *fmt, ... ) +void print_srvconsole(char *fmt, ...) { va_list argptr; static char string[384]; va_start(argptr, fmt); - vsnprintf(string, sizeof(string)-1, fmt, argptr); - string[sizeof(string)-1] = '\0'; + vsnprintf(string, sizeof(string) - 1, fmt, argptr); + string[sizeof(string) - 1] = '\0'; va_end(argptr); + SERVER_PRINT(string); } void* alloc_amxmemory(void** p, int size) { - *p = new unsigned char[ size ]; + *p = new unsigned char[size]; return *p; } @@ -101,57 +104,62 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 { *error = 0; CAmxxReader reader(filename, PAWN_CELL_SIZE / 8); + if (reader.GetStatus() == CAmxxReader::Err_None) { size_t bufSize = reader.GetBufferSize(); + if (bufSize != 0) { *program = (void*) (new char[bufSize]); + if (!*program) { strcpy(error, "Failed to allocate memory"); return (amx->error = AMX_ERR_MEMORY); } + reader.GetSection(*program); } } 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"); - default: - strcpy(error, "Unknown error"); - return (amx->error = AMX_ERR_NOTFOUND); + 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"); + default: + strcpy(error, "Unknown error"); + return (amx->error = AMX_ERR_NOTFOUND); } // check for magic AMX_HEADER *hdr = (AMX_HEADER*)*program; uint16_t magic = hdr->magic; amx_Align16(&magic); + if (magic != AMX_MAGIC) { strcpy(error, "Invalid Plugin"); @@ -161,7 +169,6 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 int err; memset(amx, 0, sizeof(*amx)); bool will_be_debugged = false; - tagAMX_DBG *pDbg = NULL; if ((int)CVAR_GET_FLOAT("amx_debug") >= 2 || debug) @@ -170,10 +177,14 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 { sprintf(error, "Plugin needs newer debug version info"); return (amx->error = AMX_ERR_VERSION); - } else if ((hdr->flags & AMX_FLAG_DEBUG) != 0) { + } + else if ((hdr->flags & AMX_FLAG_DEBUG) != 0) + { will_be_debugged = true; + char *addr = (char *)hdr + hdr->size; pDbg = new tagAMX_DBG; + memset(pDbg, 0, sizeof(AMX_DBG)); int err = dbg_LoadInfo(pDbg, addr); @@ -188,7 +199,7 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 amx->flags |= AMX_FLAG_DEBUG; } else { - sprintf(error,"Plugin not compiled with debug option"); + sprintf(error, "Plugin not compiled with debug option"); return (amx->error = AMX_ERR_INIT); } } else { @@ -198,14 +209,15 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 #endif } - if ((err = amx_Init( amx, *program )) != AMX_ERR_NONE) + if ((err = amx_Init(amx, *program)) != AMX_ERR_NONE) { if (pDbg) { dbg_FreeInfo(pDbg); delete pDbg; } - sprintf(error,"Load error %d (invalid file format or version)", err); + + sprintf(error, "Load error %d (invalid file format or version)", err); return (amx->error = AMX_ERR_INIT); } @@ -232,19 +244,21 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 #ifdef JIT if (amx->flags & AMX_FLAG_JITC) { - char *np = new char[ amx->code_size ]; - char *rt = new char[ amx->reloc_size ]; - if ( !np || (!rt && amx->reloc_size > 0) ) + char *np = new char[amx->code_size]; + char *rt = new char[amx->reloc_size]; + + if (!np || (!rt && amx->reloc_size > 0)) { delete[] np; delete[] rt; - strcpy(error,"Failed to initialize JIT'd plugin"); + strcpy(error, "Failed to initialize JIT'd plugin"); + return (amx->error = AMX_ERR_INIT); } - if ( (err = amx_InitJIT(amx, (void *)rt, (void *)np)) == AMX_ERR_NONE ) + if ((err = amx_InitJIT(amx, (void *)rt, (void *)np)) == AMX_ERR_NONE) { - //amx->base = (unsigned char FAR *)realloc( np, amx->code_size ); + //amx->base = (unsigned char FAR *)realloc(np, amx->code_size); #ifndef __linux__ amx->base = (unsigned char *)VirtualAlloc(NULL, amx->code_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); #else @@ -252,47 +266,52 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 amx->base = (unsigned char *)memalign(sysconf(_SC_PAGESIZE), amx->code_size); mprotect((void *)amx->base, amx->code_size, PROT_READ|PROT_WRITE|PROT_EXEC); #endif - if ( amx->base ) - memcpy( amx->base , np , amx->code_size ); + if (amx->base) + memcpy(amx->base, np, amx->code_size); + delete[] np; delete[] rt; + char *prg = (char *)(*program); + delete[] prg; (*program) = amx->base; - if ( *program == 0 ){ - strcpy(error,"Failed to allocate memory"); + + if (*program == 0) + { + strcpy(error, "Failed to allocate memory"); return (amx->error = AMX_ERR_MEMORY); } - } - else - { + } else { delete[] np; delete[] rt; + sprintf(error, "Failed to initialize plugin (%d)", err); + return (amx->error = AMX_ERR_INIT_JIT); } } - #endif - CScript* aa = new CScript(amx,*program,filename); + CScript* aa = new CScript(amx, *program, filename); - if ( aa == 0 ) + if (aa == 0) { - strcpy(error,"Failed to allocate memory"); + strcpy(error, "Failed to allocate memory"); return (amx->error = AMX_ERR_MEMORY); } - g_loadedscripts.put( aa ); + g_loadedscripts.put(aa); - set_amxnatives(amx,error); + set_amxnatives(amx, error); if (g_plugins.m_Finalized) { amx_Register(amx, g_plugins.pNatives, -1); + if (CheckModules(amx, error)) { - if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE ) + if (amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE) { sprintf(error, "Plugin uses an unknown function (name \"%s\") - check your modules.ini.", no_function); return (amx->error = AMX_ERR_NOTFOUND); @@ -315,10 +334,11 @@ const char *StrCaseStr(const char *as, const char *bs) if (len > 254) len = 254; - for (i=0; i 254) len = 254; - for (i=0; i::iterator a; + + CList::iterator a; + const amxx_module_info_s *info; + Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER]; - - for (int i=0; ilogtag - && (StrCaseStr(info->logtag, "sql") - || - StrCaseStr(info->logtag, "dbi")) - ) + if (info->logtag && (StrCaseStr(info->logtag, "sql") || StrCaseStr(info->logtag, "dbi"))) { found = true; break; @@ -383,16 +409,19 @@ int CheckModules(AMX *amx, char error[128]) } } } + if (!found) found = LibraryExists(buffer); + if (!found) { if (pHandler->HandleModule(buffer)) found = true; } + if (!found) { - sprintf(error, "Module \"%s\" required for plugin. Check modules.ini.", buffer); + sprintf(error, "Module \"%s\" required for plugin. Check modules.ini.", buffer); return 0; } } @@ -400,13 +429,12 @@ int CheckModules(AMX *amx, char error[128]) return 1; } -int set_amxnatives(AMX* amx,char error[128]) +int set_amxnatives(AMX* amx, char error[128]) { - for ( CList::iterator a = g_modules.begin(); a ; ++a ) + for (CList::iterator a = g_modules.begin(); a ; ++a) { - for( CList::iterator cc = - (*a).m_Natives.begin(); cc; ++cc ) - amx_Register(amx, *cc , -1); + for (CList::iterator cc = (*a).m_Natives.begin(); cc; ++cc) + amx_Register(amx, *cc, -1); } amx_Register(amx, string_Natives, -1); @@ -425,12 +453,13 @@ int set_amxnatives(AMX* amx,char error[128]) int idx, err; cell retval; - if (amx_FindPublic(amx, "plugin_natives", &idx)==AMX_ERR_NONE) + + if (amx_FindPublic(amx, "plugin_natives", &idx) == AMX_ERR_NONE) { - if ( (err=amx_Exec(amx, &retval, idx))!=AMX_ERR_NONE ) + if ((err = amx_Exec(amx, &retval, idx)) != AMX_ERR_NONE) { Debugger::GenericMessage(amx, err); - AMXXLOG_Log("An error occurred in plugins_native. This is dangerous!"); + AMXXLOG_Log("An error occurred in plugins_native. This is dangerous!"); } } @@ -442,36 +471,47 @@ int set_amxnatives(AMX* amx,char error[128]) int unload_amxscript(AMX* amx, void** program) { int flags = amx->flags; + Debugger *pDebugger = (Debugger *)amx->userdata[UD_DEBUGGER]; if (pDebugger) delete pDebugger; + Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER]; if (pHandler) delete pHandler; - CList::iterator a = g_loadedscripts.find( amx ); - if ( a ) a.remove(); + + CList::iterator a = g_loadedscripts.find(amx); + + if (a) + a.remove(); + char *prg = (char *)*program; + if (!prg) return AMX_ERR_NONE; + #if defined JIT #if defined __linux__ - if ( (flags & AMX_FLAG_JITC) != AMX_FLAG_JITC ) + if ((flags & AMX_FLAG_JITC) != AMX_FLAG_JITC) { delete [] prg; } else { #ifdef free #undef free free(prg); -#define free(ptr) m_deallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_free,ptr) +#define free(ptr) m_deallocator(__FILE__, __LINE__, __FUNCTION__, m_alloc_free, ptr) #else free(prg); #endif } #elif defined WIN32 - if ( (flags & AMX_FLAG_JITC) != AMX_FLAG_JITC ) + + if ((flags & AMX_FLAG_JITC) != AMX_FLAG_JITC) { delete [] prg; - } else if (!VirtualFree((LPVOID)prg, 0, MEM_RELEASE)) { + } + else if (!VirtualFree((LPVOID)prg, 0, MEM_RELEASE)) + { AMXXLOG_Log("[AMXX] Could not free plugin memory, failure %d.", GetLastError()); return AMX_ERR_PARAMS; } @@ -484,50 +524,52 @@ int unload_amxscript(AMX* amx, void** program) return AMX_ERR_NONE; } -AMX* get_amxscript(int id , void** code, const char** filename) +AMX* get_amxscript(int id, void** code, const char** filename) { - CList::iterator a = g_loadedscripts.begin(); - while ( a && id-- ) + CList::iterator a = g_loadedscripts.begin(); + + while (a && id--) ++a; - if ( a ){ + + if (a) + { *filename = (*a).getName(); *code = (*a).getCode(); + return (*a).getAMX(); } + return 0; } const char* get_amxscriptname(AMX* amx) { - CList::iterator a = g_loadedscripts.find( amx ); + CList::iterator a = g_loadedscripts.find(amx); return a ? (*a).getName() : ""; } -void get_modname(char* buffer ) +void get_modname(char* buffer) { - strcpy( buffer , g_mod_name.c_str() ); + strcpy(buffer, g_mod_name.c_str()); } -char* build_pathname(char *fmt, ... ) +char* build_pathname(char *fmt, ...) { static char string[256]; - int b; - - int a = b = snprintf(string , 255 , - + int a = b = snprintf(string, 255, #ifndef __linux__ - "%s\\", + "%s\\", #else - "%s/", + "%s/", #endif g_mod_name.c_str()); va_list argptr; - va_start (argptr, fmt); - a += vsnprintf (&string[a], 255 - a , fmt,argptr); - string[ a ] = 0; - va_end (argptr); + va_start(argptr, fmt); + a += vsnprintf (&string[a], 255 - a, fmt, argptr); + string[a] = 0; + va_end(argptr); char* path = &string[b]; @@ -548,12 +590,11 @@ char *build_pathname_r(char *buffer, size_t maxlen, char *fmt, ...) { snprintf(buffer, maxlen, #ifdef __linux__ - "%s/", + "%s/", #else - "%s\\", + "%s\\", #endif - g_mod_name.c_str() - ); + g_mod_name.c_str()); size_t len = strlen(buffer); char *ptr = buffer + len; @@ -576,16 +617,15 @@ char *build_pathname_r(char *buffer, size_t maxlen, char *fmt, ...) return buffer; } - // build pathname based on addons dir -char* build_pathname_addons(char *fmt, ... ) +char* build_pathname_addons(char *fmt, ...) { static char string[256]; va_list argptr; - va_start (argptr, fmt); + va_start(argptr, fmt); vsnprintf (string, 255, fmt, argptr); - va_end (argptr); + va_end(argptr); char* path = string; @@ -605,13 +645,14 @@ char* build_pathname_addons(char *fmt, ... ) bool validFile(const char* file) { const char* a = 0; - while(*file) - if (*file++=='.') + + while (*file) + if (*file++ == '.') a = file; #ifndef __linux__ - return (a && !strcmp(a,"dll")); + return (a && !strcmp(a, "dll")); #else - return (a && !strcmp(a,"so")); + return (a && !strcmp(a, "so")); #endif } @@ -619,6 +660,7 @@ void ConvertModuleName(const char *pathString, String &path) { #if PAWN_CELL_SIZE==64 char *ptr = strstr(pathString, "i386"); + if (ptr) { //attempt to fix the binary name @@ -627,6 +669,7 @@ void ConvertModuleName(const char *pathString, String &path) path.append("amd64.so"); } else { ptr = strstr(pathString, ".dll"); + if (ptr) { *ptr = 0; @@ -634,6 +677,7 @@ void ConvertModuleName(const char *pathString, String &path) path.append("_amd64.so"); } else { ptr = strstr(pathString, ".so"); + if (ptr) { path.assign(pathString); @@ -645,8 +689,10 @@ void ConvertModuleName(const char *pathString, String &path) } } #else + #ifdef __linux__ char *ptr = strstr(pathString, "amd64"); + if (ptr) { //attempt to fix the binary name @@ -655,6 +701,7 @@ void ConvertModuleName(const char *pathString, String &path) path.append("i386.so"); } else { ptr = strstr(pathString, ".dll"); + if (ptr) { *ptr = 0; @@ -663,6 +710,7 @@ void ConvertModuleName(const char *pathString, String &path) } else { //check to see if this file even has an extension ptr = strstr(pathString, ".so"); + if (ptr) { path.assign(pathString); @@ -674,28 +722,33 @@ void ConvertModuleName(const char *pathString, String &path) } #else char *ptr = strstr(pathString, ".dll"); + if (ptr) { path.assign(pathString); } else { //prevent this from loading .so too ptr = strstr(pathString, ".so"); + if (ptr) { int i = 0, len = strlen(pathString), c = -1; - for (i=len-1; i>=0; i--) + + for (i = len - 1; i >= 0; i--) { //cut off at first _ if (pathString[i] == '_') { //make sure this is a valid _ - if (i == len-1 || strncmp(&(pathString[i+1]), "amxx", 4) == 0) + if (i == len - 1 || strncmp(&(pathString[i + 1]), "amxx", 4) == 0) break; + c = i; break; } } *ptr = 0; + if (c == -1) { path.assign(pathString); @@ -717,11 +770,11 @@ void ConvertModuleName(const char *pathString, String &path) int loadModules(const char* filename, PLUG_LOADTIME now) { - FILE *fp = fopen(build_pathname("%s",filename), "rt"); + FILE *fp = fopen(build_pathname("%s", filename), "rt"); - if ( !fp ) + if (!fp) { - AMXXLOG_Log( "[AMXX] Modules list not found (file \"%s\")",filename); + AMXXLOG_Log("[AMXX] Modules list not found (file \"%s\")", filename); return 0; } @@ -736,14 +789,16 @@ int loadModules(const char* filename, PLUG_LOADTIME now) { if (!line._fread(fp) || line.size() < 1) continue; + line.trim(); *moduleName = 0; - if (sscanf(line.c_str(),"%s",moduleName) == EOF) + + if (sscanf(line.c_str(), "%s", moduleName) == EOF) continue; - if (moduleName[0] == ';') + + if (moduleName[0] == ';') continue; - char* pathname = build_pathname("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), moduleName); strcpy(pathString, pathname); @@ -754,13 +809,14 @@ int loadModules(const char* filename, PLUG_LOADTIME now) if (!validFile(path.c_str())) continue; - CList::iterator a = g_modules.find( path.c_str() ); + CList::iterator a = g_modules.find(path.c_str()); - if ( a ) continue; // already loaded + if (a) + continue; // already loaded - CModule* cc = new CModule( path.c_str() ); + CModule* cc = new CModule(path.c_str()); - if ( cc == 0 ) + if (cc == 0) { fclose(fp); return loaded; @@ -768,62 +824,65 @@ int loadModules(const char* filename, PLUG_LOADTIME now) cc->queryModule(); - switch( cc->getStatusValue() ) { - case MODULE_BADLOAD: - report_error( 1 , "[AMXX] Module is not a valid library (file \"%s\")", path.c_str()); - break; - case MODULE_NOINFO: - report_error( 1 ,"[AMXX] Couldn't find info. about module (file \"%s\")", path.c_str()); - break; - case MODULE_NOQUERY: - report_error( 1 , "[AMXX] Couldn't find \"AMX_Query\" or \"AMXX_Query\" (file \"%s\")", path.c_str()); - break; - case MODULE_NOATTACH: - report_error( 1 , "[AMXX] Couldn't find \"%s\" (file \"%s\")", cc->isAmxx() ? "AMXX_Attach" : "AMX_Attach", path.c_str()); - break; - case MODULE_OLD: - report_error( 1 , "[AMXX] Module has a different interface version (file \"%s\")",path.c_str()); - break; - case MODULE_NEWER: - report_error(1, "[AMXX] Module has a newer interface version (file \"%s\"). Please download a new amxmodx.", path.c_str()); - break; - case MODULE_INTERROR: - report_error(1, "[AMXX] Internal error during module load (file \"%s\")", path.c_str()); - break; - case MODULE_NOT64BIT: - report_error(1, "[AMXX] Module \"%s\" is not 64 bit compatible.", path.c_str()); - break; - default: - ++loaded; + switch (cc->getStatusValue()) + { + case MODULE_BADLOAD: + report_error(1, "[AMXX] Module is not a valid library (file \"%s\")", path.c_str()); + break; + case MODULE_NOINFO: + report_error(1, "[AMXX] Couldn't find info. about module (file \"%s\")", path.c_str()); + break; + case MODULE_NOQUERY: + report_error(1, "[AMXX] Couldn't find \"AMX_Query\" or \"AMXX_Query\" (file \"%s\")", path.c_str()); + break; + case MODULE_NOATTACH: + report_error(1, "[AMXX] Couldn't find \"%s\" (file \"%s\")", cc->isAmxx() ? "AMXX_Attach" : "AMX_Attach", path.c_str()); + break; + case MODULE_OLD: + report_error(1, "[AMXX] Module has a different interface version (file \"%s\")", path.c_str()); + break; + case MODULE_NEWER: + report_error(1, "[AMXX] Module has a newer interface version (file \"%s\"). Please download a new amxmodx.", path.c_str()); + break; + case MODULE_INTERROR: + report_error(1, "[AMXX] Internal error during module load (file \"%s\")", path.c_str()); + break; + case MODULE_NOT64BIT: + report_error(1, "[AMXX] Module \"%s\" is not 64 bit compatible.", path.c_str()); + break; + default: + ++loaded; } - g_modules.put( cc ); + g_modules.put(cc); #ifndef FAKEMETA - if ( cc->IsMetamod()) + if (cc->IsMetamod()) { char* mmpathname = build_pathname_addons("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), line.c_str()); + ConvertModuleName(mmpathname, path); cc->attachMetamod(path.c_str(), now); } bool retVal = cc->attachModule(); + if (cc->isAmxx() && !retVal) { switch (cc->getStatusValue()) { - case MODULE_FUNCNOTPRESENT: - report_error(1, "[AMXX] Module requested a not exisitng function (file \"%s\")%s%s%s", cc->getFilename(), cc->getMissingFunc() ? " (func \"" : "", - 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; - default: - break; + case MODULE_FUNCNOTPRESENT: + report_error(1, "[AMXX] Module requested a not exisitng function (file \"%s\")%s%s%s", cc->getFilename(), cc->getMissingFunc() ? " (func \"" : "", + 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; + default: + break; } } #endif @@ -836,9 +895,9 @@ int loadModules(const char* filename, PLUG_LOADTIME now) void detachModules() { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); - while ( a ) + while (a) { (*a).detachModule(); a.remove(); @@ -847,79 +906,82 @@ void detachModules() void detachReloadModules() { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); - while ( a ) + while (a) { #ifdef FAKEMETA - if ( (*a).isReloadable() ) + if ((*a).isReloadable()) #else - if ( (*a).isReloadable() && !(*a).IsMetamod() ) + if ((*a).isReloadable() && !(*a).IsMetamod()) #endif { (*a).detachModule(); a.remove(); + continue; } - ++a; } - } #ifdef FAKEMETA void attachModules() { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); - while ( a ) + while (a) { bool retVal = (*a).attachModule(); + if ((*a).isAmxx() && !retVal) { switch ((*a).getStatusValue()) { - case MODULE_FUNCNOTPRESENT: - report_error(1, "[AMXX] Module requested a not exisitng function (file \"%s\")%s%s%s", (*a).getFilename(), (*a).getMissingFunc() ? " (func \"" : "", - (*a).getMissingFunc() ? (*a).getMissingFunc() : "", (*a).getMissingFunc() ? "\")" : ""); - break; - case MODULE_INTERROR: - report_error(1, "[AMXX] Internal error during module load (file \"%s\")", (*a).getFilename()); - break; - case MODULE_BADLOAD: - report_error( 1 , "[AMXX] Module is not a valid library (file \"%s\")", (*a).getFilename()); - break; - default: - break; + case MODULE_FUNCNOTPRESENT: + report_error(1, "[AMXX] Module requested a not exisitng function (file \"%s\")%s%s%s", (*a).getFilename(), (*a).getMissingFunc() ? " (func \"" : "", + (*a).getMissingFunc() ? (*a).getMissingFunc() : "", (*a).getMissingFunc() ? "\")" : ""); + break; + case MODULE_INTERROR: + report_error(1, "[AMXX] Internal error during module load (file \"%s\")", (*a).getFilename()); + break; + case MODULE_BADLOAD: + report_error(1, "[AMXX] Module is not a valid library (file \"%s\")", (*a).getFilename()); + break; + default: + break; } } - ++a; } } #endif -const char* strip_name( const char* a ) +const char* strip_name(const char* a) { const char* ret = a; - while(*a){ - if ( *a== '/' || *a=='\\' ){ + + while (*a) + { + if (*a == '/' || *a == '\\') + { ret = ++a; continue; } ++a; } + return ret; } #ifdef FAKEMETA void attachMetaModModules(PLUG_LOADTIME now, const char* filename) { - File fp( build_pathname("%s",filename), "r" ); + File fp(build_pathname("%s", filename), "r"); - if ( !fp ) + if (!fp) { - AMXXLOG_Log( "[AMXX] Modules list not found (file \"%s\")",filename); + AMXXLOG_Log("[AMXX] Modules list not found (file \"%s\")", filename); return; } @@ -927,12 +989,12 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename) String modPath, mmPath; DLHANDLE module; - while ( fp.getline( line , 255 ) ) + while (fp.getline(line, 255)) { *moduleName = 0; - sscanf(line,"%s",moduleName); + sscanf(line, "%s", moduleName); - if (!isalnum(*moduleName)) + if (!isalnum(*moduleName)) continue; char* pathname = build_pathname("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), line); @@ -948,7 +1010,7 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename) while (iter) { - if ( strcmp( (*iter).GetPath(), mmPath.c_str() ) == 0 ) + if (strcmp((*iter).GetPath(), mmPath.c_str()) == 0) { foundFlag = 1; break; @@ -959,62 +1021,69 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename) if (foundFlag) continue; - module = DLLOAD( modPath.c_str() ); // link dll + module = DLLOAD(modPath.c_str()); // link dll - if ( module ) + if (module) { - int a = (int)DLPROC(module,"Meta_Attach"); + int a = (int)DLPROC(module, "Meta_Attach"); DLFREE(module); - if ( a ) + if (a) { g_FakeMeta.AddPlugin(mmPath.c_str()); } } } + g_FakeMeta.Meta_Query(gpMetaUtilFuncs); g_FakeMeta.Meta_Attach(now, gpMetaGlobals, gpGamedllFuncs); } #endif - // Get the number of running modules int countModules(CountModulesMode mode) { - CList::iterator iter; + CList::iterator iter; int num; + switch (mode) { - 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; + 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; } + return 0; } // Call all modules' AMXX_PluginsLoaded functions void modules_callPluginsLoaded() { - CList::iterator iter = g_modules.begin(); + CList::iterator iter = g_modules.begin(); + while (iter) { (*iter).CallPluginsLoaded(); @@ -1023,10 +1092,9 @@ void modules_callPluginsLoaded() } // new functions - int MNF_AddNatives(AMX_NATIVE_INFO* natives) { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach) return FALSE; // may only be called from attach @@ -1037,6 +1105,7 @@ int MNF_AddNatives(AMX_NATIVE_INFO* natives) return FALSE; g_CurrentlyCalledModule->m_Natives.put(pPtr); + return TRUE; } @@ -1054,31 +1123,36 @@ const char *MNF_GetModname(void) AMX *MNF_GetAmxScript(int id) { - CList::iterator iter = g_loadedscripts.begin(); + CList::iterator iter = g_loadedscripts.begin(); + while (iter && id--) ++iter; if (iter == NULL) return NULL; + return (*iter).getAMX(); } const char *MNF_GetAmxScriptName(int id) { - CList::iterator iter = g_loadedscripts.begin(); + CList::iterator iter = g_loadedscripts.begin(); + while (iter && id--) ++iter; if (iter == NULL) return NULL; + return (*iter).getName(); } int MNF_FindAmxScriptByName(const char *name) { - CList::iterator iter = g_loadedscripts.begin(); + CList::iterator iter = g_loadedscripts.begin(); bool found = false; int i = 0; + while (iter) { if (stricmp((*iter).getName(), name) == 0) @@ -1089,17 +1163,21 @@ int MNF_FindAmxScriptByName(const char *name) ++iter; ++i; } + if (!found) return -1; + return i; } int MNF_FindAmxScriptByAmx(const AMX *amx) { - CList::iterator iter = g_loadedscripts.begin(); + CList::iterator iter = g_loadedscripts.begin(); bool found = false; int i = 0; + while (iter) + { if (amx == (*iter).getAMX()) { @@ -1109,8 +1187,10 @@ int MNF_FindAmxScriptByAmx(const AMX *amx) ++iter; ++i; } + if (!found) return -1; + return i; } @@ -1118,16 +1198,20 @@ char *MNF_GetAmxString(AMX *amx, cell amx_addr, int bufferId, int *pLen) { int len; char *retVal = get_amxstring(amx, amx_addr, bufferId, len); + if (pLen) *pLen = len; + return retVal; } int MNF_GetAmxStringLen(const cell *ptr) { register int c = 0; - while(ptr[c]) + + while (ptr[c]) ++c; + return c; } @@ -1135,8 +1219,10 @@ char *MNF_FormatAmxString(AMX *amx, cell *params, int startParam, int *pLen) { int len; char *retVal = format_amxstring(amx, params, startParam, len); + if (pLen) *pLen = len; + return retVal; } @@ -1144,129 +1230,170 @@ int MNF_GetPlayerFlags(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + CPlayer *pPlayer = GET_PLAYER_POINTER_I(id); + return (pPlayer->flags[0]); } void MNF_CopyAmxMemory(cell * dest, const cell * src, int len) { - memcpy((void*)dest, (const void *)src, (size_t)len*sizeof(cell)); + memcpy((void*)dest, (const void *)src, (size_t)len * sizeof(cell)); } int MNF_IsPlayerValid(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + CPlayer *pPlayer = GET_PLAYER_POINTER_I(id); + return (pPlayer->initialized) ? 1 : 0; } + const char * MNF_GetPlayerName(int id) { if (id < 1 || id > gpGlobals->maxClients) return NULL; + return GET_PLAYER_POINTER_I(id)->name.c_str(); } + const char * MNF_GetPlayerIP(int id) { if (id < 1 || id > gpGlobals->maxClients) return NULL; + return GET_PLAYER_POINTER_I(id)->ip.c_str(); } + int MNF_IsPlayerInGame(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->ingame ? 1 : 0; } + int MNF_IsPlayerBot(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->IsBot() ? 1 : 0; } + int MNF_IsPlayerAuthorized(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->authorized ? 1 : 0; } + float MNF_GetPlayerTime(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0.0f; + return GET_PLAYER_POINTER_I(id)->time; } + float MNF_GetPlayerPlayTime(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0.0f; + return GET_PLAYER_POINTER_I(id)->playtime; } + int MNF_GetPlayerCurweapon(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->current; } + int MNF_GetPlayerTeamID(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->teamId; } + int MNF_GetPlayerDeaths(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->deaths; } + int MNF_GetPlayerMenu(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->menu; } + int MNF_GetPlayerKeys(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->keys; } + int MNF_IsPlayerAlive(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return GET_PLAYER_POINTER_I(id)->IsAlive() ? 1 : 0; } + float MNF_GetPlayerFrags(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0.0f; + return GET_PLAYER_POINTER_I(id)->pEdict->v.frags; } + int MNF_IsPlayerConnecting(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + CPlayer * pPlayer = GET_PLAYER_POINTER_I(id); + return (!pPlayer->ingame && pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0)) ? 1 : 0; } + int MNF_IsPlayerHLTV(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return (GET_PLAYER_POINTER_I(id)->pEdict->v.flags & FL_PROXY) ? 1 : 0; } + float MNF_GetPlayerArmor(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0.0f; + return (GET_PLAYER_POINTER_I(id)->pEdict->v.armorvalue); } + float MNF_GetPlayerHealth(int id) { if (id < 1 || id > gpGlobals->maxClients) return 0; + return (GET_PLAYER_POINTER_I(id)->pEdict->v.health); } @@ -1285,9 +1412,10 @@ void MNF_Log(const char *fmt, ...) char msg[3072]; va_list arglst; va_start(arglst, fmt); - _vsnprintf(msg, sizeof(msg)-1, fmt, arglst); + _vsnprintf(msg, sizeof(msg) - 1, fmt, arglst); //vsprintf(msg, fmt, arglst); va_end(arglst); + AMXXLOG_Log("%s", msg); } @@ -1302,11 +1430,12 @@ void LogError(AMX *amx, int err, const char *fmt, ...) char msg_buffer[2048]; msg_buffer[0] = '\0'; + if (fmt != NULL) { va_list ap; va_start(ap, fmt); - _vsnprintf(msg_buffer, sizeof(msg_buffer)-1, fmt, ap); + _vsnprintf(msg_buffer, sizeof(msg_buffer) - 1, fmt, ap); va_end(ap); } @@ -1326,6 +1455,7 @@ void LogError(AMX *amx, int err, const char *fmt, ...) pHandler->SetErrorMsg(msg_buffer); return; } + //give the user a first-chance at blocking the error from displaying if (pHandler->HandleError(fmt ? msg_buffer : NULL) != 0) { @@ -1339,6 +1469,7 @@ void LogError(AMX *amx, int err, const char *fmt, ...) { if (fmt) AMXXLOG_Log("%s", msg_buffer); + Debugger::GenericMessage(amx, err); AMXXLOG_Log("[AMXX] To enable debug mode, add \"debug\" after the plugin name in plugins.ini (without quotes)."); //destroy original error code so the original is not displayed again @@ -1360,6 +1491,7 @@ edict_t* MNF_GetPlayerEdict(int id) { if (id < 1 || id > gpGlobals->maxClients) return NULL; + return (GET_PLAYER_POINTER_I(id)->pEdict); } @@ -1369,6 +1501,7 @@ const char *MNF_Format(const char *fmt, ...) va_start(ap, fmt); const char *retVal = g_langMngr.FormatString(fmt, ap); va_end(ap); + return retVal; } @@ -1412,6 +1545,7 @@ inline bool operator ==(func_s &arg1, const char *desc) { if (strcmp(arg1.desc, desc) == 0) return true; + return false; } @@ -1536,6 +1670,7 @@ void *Module_ReqFnptr(const char *funcName) { // code // ^---- really? wow! + if (!g_CurrentlyCalledModule) { return NULL; @@ -1544,6 +1679,7 @@ void *Module_ReqFnptr(const char *funcName) g_LastRequestedFunc = funcName; CList::iterator iter; + for (iter = g_functions.begin(); iter; ++iter) { if (strcmp(funcName, iter->desc) == 0) @@ -1554,22 +1690,25 @@ void *Module_ReqFnptr(const char *funcName) } #if !defined MEMORY_TEST && !defined WIN32 -void * ::operator new(size_t size) { - return(calloc(1, size)); +void * ::operator new(size_t size) +{ + return (calloc(1, size)); } -void * ::operator new[](size_t size) { - return(calloc(1, size)); +void * ::operator new[](size_t size) +{ + return (calloc(1, size)); } -void ::operator delete(void * ptr) { - if(ptr) +void ::operator delete(void * ptr) +{ + if (ptr) free(ptr); } -void ::operator delete[](void * ptr) { - if(ptr) +void ::operator delete[](void * ptr) +{ + if (ptr) free(ptr); } #endif - diff --git a/amxmodx/modules.h b/amxmodx/modules.h index 5a29a03d..9e7a3ae4 100755 --- a/amxmodx/modules.h +++ b/amxmodx/modules.h @@ -36,7 +36,7 @@ #undef DLLEXPORT #ifndef __linux__ - #define DLLEXPORT __declspec(dllexport) + #define DLLEXPORT __declspec(dllexport) #else #define DLLEXPORT #define WINAPI diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index fbd890b4..18918613 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -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<:o //this will either be MORE or BACK.. keys |= (1< 1) { keys |= (1<AddItem(name, cmd, access); pItem->handler = params[5]; @@ -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(params[2])); + menuitem *pItem = pMenu->GetMenuItem(static_cast(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(params[2])); + menuitem *pItem = pMenu->GetMenuItem(static_cast(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(params[2])); + menuitem *pItem = pMenu->GetMenuItem(static_cast(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[] = diff --git a/amxmodx/newmenus.h b/amxmodx/newmenus.h index 6f97c209..d5d02dca 100755 --- a/amxmodx/newmenus.h +++ b/amxmodx/newmenus.h @@ -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 m_Items; + String m_Title; String m_Text; + int menuId; int thisId; }; diff --git a/amxmodx/string.cpp b/amxmodx/string.cpp index e7efa79e..9d905b69 100755 --- a/amxmodx/string.cpp +++ b/amxmodx/string.cpp @@ -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} }; diff --git a/amxmodx/util.cpp b/amxmodx/util.cpp index 7f22288d..f37b32fb 100755 --- a/amxmodx/util.cpp +++ b/amxmodx/util.cpp @@ -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,13 +168,13 @@ 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; int unit = value % 10; - if (ten) + if (ten) aaa += sprintf(&output[aaa], words[(ten > 1) ? (ten + 18) : (unit + 10)]); if (ten != 1 && (unit || (!value && !hun && !tho)))