1 Commits

Author SHA1 Message Date
7b527c9c25 Tagged 1.50 2006-07-20 04:02:53 +00:00
383 changed files with 13973 additions and 51015 deletions

View File

@ -35,10 +35,8 @@
// *****************************************************
// class CmdMngr
// *****************************************************
CmdMngr::CmdMngr()
{
memset(sortedlists, 0, sizeof(sortedlists));
CmdMngr::CmdMngr() {
memset(sortedlists,0,sizeof(sortedlists));
srvcmdlist = 0;
clcmdlist = 0;
prefixHead = 0;
@ -51,12 +49,13 @@ 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)
{
CmdMngr::Command::Command( CPluginMngr::CPlugin* pplugin,const char* pcmd,
const char* pinfo , int pflags , int pfunc,
bool pviewable, CmdMngr* pparent ) : commandline(pcmd) , info(pinfo) {
char szCmd[64], szArg[64];
*szCmd = 0; *szArg = 0;
sscanf(pcmd, "%s %s", szCmd, szArg);
*szCmd = 0; *szArg=0;
sscanf(pcmd,"%s %s",szCmd,szArg);
command.assign(szCmd);
argument.assign(szArg);
plugin = pplugin;
@ -74,68 +73,75 @@ CmdMngr::Command::~Command()
++uniqueid;
}
CmdMngr::Command* CmdMngr::registerCommand(CPluginMngr::CPlugin* plugin, int func, char* cmd, char* info, int level, bool listable)
CmdMngr::Command* CmdMngr::registerCommand( CPluginMngr::CPlugin* plugin , int func , char* cmd , char* info , int level , bool listable )
{
Command* b = new Command(plugin, cmd, info, level, func, listable, this);
if (b == 0) return 0;
setCmdLink(&sortedlists[0], b);
Command* b = new Command( plugin , cmd , info , level , func , listable, this );
if ( b == 0 ) return 0;
setCmdLink( &sortedlists[0] , b );
return b;
}
CmdMngr::Command* CmdMngr::getCmd(long int id, int type, int access)
CmdMngr::Command* CmdMngr::getCmd( long int id ,int type, int access )
{
//if (id >= 1024 || id < 0) return (Command*)id;
if (id < 0)
{
for (CmdMngr::iterator a = begin(type); a ; ++a)
{
if ((*a).id == id)
//if ( id >= 1024 || id < 0 ) return (Command*)id;
if ( id < 0 ){
for (CmdMngr::iterator a = begin( type ); a ; ++a){
if ( (*a).id == id )
return &(*a);
}
return 0;
}
if ((id < buf_cmdid) || (access != buf_cmdaccess) || (type != buf_cmdtype))
if ( (id < buf_cmdid) || (access != buf_cmdaccess) || (type != buf_cmdtype) )
{
buf_cmdptr = begin(type);
buf_cmdptr = begin( type );
buf_cmdaccess = access;
buf_cmdtype = type;
buf_cmdid = id;
} else {
}
else
{
int a = id;
id -= buf_cmdid;
buf_cmdid = a;
}
while (buf_cmdptr)
while ( buf_cmdptr )
{
if ((*buf_cmdptr).gotAccess(access) && (*buf_cmdptr).getPlugin()->isExecutable((*buf_cmdptr).getFunction()) && (*buf_cmdptr).isViewable())
if ( (*buf_cmdptr).gotAccess( access ) &&
(*buf_cmdptr).getPlugin()->isExecutable( (*buf_cmdptr).getFunction() )
&& (*buf_cmdptr).isViewable() )
{
if (id-- == 0)
if ( id-- == 0 )
return &(*buf_cmdptr);
}
++buf_cmdptr;
}
return 0;
}
int CmdMngr::getCmdNum(int type, int access)
int CmdMngr::getCmdNum( int type, int access )
{
if ((access == buf_access) && (type == buf_type))
if ( (access == buf_access) && (type == buf_type) )
return buf_num; // once calculated don't have to be done again
buf_access = access;
buf_type = type;
buf_num = 0;
CmdMngr::iterator a = begin(type);
CmdMngr::iterator a = begin( type );
while (a)
while ( a )
{
if ((*a).gotAccess(access) && (*a).getPlugin()->isExecutable((*a).getFunction()) && (*a).isViewable())
if ( (*a).gotAccess( access ) &&
(*a).getPlugin()->isExecutable( (*a).getFunction() )
&& (*a).isViewable() )
++buf_num;
++a;
}
@ -143,19 +149,19 @@ int CmdMngr::getCmdNum(int type, int access)
return buf_num;
}
void CmdMngr::setCmdLink(CmdLink** a, Command* c, bool sorted)
void CmdMngr::setCmdLink( CmdLink** a , Command* c, bool sorted )
{
CmdLink* np = new CmdLink(c);
CmdLink* np = new CmdLink( c );
if (np == 0) return;
if ( np == 0 ) return;
if (sorted)
if ( sorted )
{
while (*a)
while( *a )
{
int i = strcmp(c->getCommand(), (*a)->cmd->getCommand());
int i = strcmp(c->getCommand(),(*a)->cmd->getCommand() );
if ((i < 0) || (i == 0) && (strcmp(c->getArgument(), (*a)->cmd->getArgument()) < 0))
if ( (i<0) || (i==0) && ( strcmp( c->getArgument() , (*a)->cmd->getArgument() ) < 0 ) )
break;
a = &(*a)->next;
@ -163,101 +169,84 @@ void CmdMngr::setCmdLink(CmdLink** a, Command* c, bool sorted)
np->next = *a;
*a = np;
} else {
while (*a) a = &(*a)->next;
}
else
{
while ( *a ) a = &(*a)->next;
*a = np;
}
}
void CmdMngr::clearCmdLink(CmdLink** phead, bool pclear)
void CmdMngr::clearCmdLink( CmdLink** phead, bool pclear )
{
while (*phead)
{
while( *phead ){
CmdLink* pp = (*phead)->next;
if (pclear) delete (*phead)->cmd;
if ( pclear ) delete (*phead)->cmd;
delete *phead;
*phead = pp;
}
}
void CmdMngr::Command::setCmdType(int a)
void CmdMngr::Command::setCmdType( int a )
{
switch (a)
{
switch(a){
case CMD_ConsoleCommand: cmdtype |= 3; break;
case CMD_ClientCommand: cmdtype |= 1; break;
case CMD_ServerCommand: cmdtype |= 2; break;
}
if (cmdtype & 1) // ClientCommand
{
parent->setCmdLink(&parent->sortedlists[1], this);
if (!parent->registerCmdPrefix(this))
parent->setCmdLink(&parent->clcmdlist, this, false);
if ( cmdtype & 1 ) { // ClientCommand
parent->setCmdLink( &parent->sortedlists[1] , this );
if ( !parent->registerCmdPrefix( this ) )
parent->setCmdLink( &parent->clcmdlist , this , false );
}
if (cmdtype & 2) // ServerCommand
{
parent->setCmdLink(&parent->sortedlists[2], this);
parent->setCmdLink(&parent->srvcmdlist, this, false);
if ( cmdtype & 2 ) { // ServerCommand
parent->setCmdLink( &parent->sortedlists[2] , this );
parent->setCmdLink( &parent->srvcmdlist , this , false );
}
}
const char* CmdMngr::Command::getCmdType() const
{
switch (cmdtype)
{
case 1: return "client";
const char* CmdMngr::Command::getCmdType() const {
switch( cmdtype ){
case 1: return"client";
case 2: return "server";
case 3: return "console";
}
return "unknown";
}
bool CmdMngr::registerCmdPrefix(Command* cc)
bool CmdMngr::registerCmdPrefix( Command* cc )
{
CmdPrefix** b = findPrefix(cc->getCommand());
if (*b)
{
setCmdLink(&(*b)->list, cc, false);
CmdPrefix** b = findPrefix( cc->getCommand() );
if (*b){
setCmdLink( &(*b)->list , cc , false );
cc->prefix = (*b)->name.size();
return true;
}
return false;
}
void CmdMngr::registerPrefix(const char* nn)
void CmdMngr::registerPrefix( const char* nn )
{
if (*nn == 0) return;
CmdPrefix** b = findPrefix(nn);
if ( *nn == 0 ) return;
CmdPrefix** b = findPrefix( nn );
if (*b) return;
*b = new CmdPrefix(nn, this);
*b = new CmdPrefix( nn , this );
}
CmdMngr::CmdPrefix** CmdMngr::findPrefix(const char* nn)
{
CmdMngr::CmdPrefix** CmdMngr::findPrefix( const char* nn ){
CmdPrefix** aa = &prefixHead;
while (*aa)
{
if (!strncmp((*aa)->name.c_str(), nn, (*aa)->name.size()))
while(*aa){
if ( !strncmp( (*aa)->name.c_str(), nn, (*aa)->name.size() ) )
break;
aa = &(*aa)->next;
aa=&(*aa)->next;
}
return aa;
}
void CmdMngr::clearPrefix()
{
while (prefixHead)
{
void CmdMngr::clearPrefix(){
while(prefixHead){
CmdPrefix* a = prefixHead->next;
delete prefixHead;
prefixHead = a;
@ -275,8 +264,7 @@ void CmdMngr::clear()
clearBufforedInfo();
}
void CmdMngr::clearBufforedInfo()
{
void CmdMngr::clearBufforedInfo() {
buf_type = -1;
buf_access = 0;
buf_id = -1;

View File

@ -36,8 +36,7 @@
// class CmdMngr
// *****************************************************
enum
{
enum {
CMD_ConsoleCommand,
CMD_ClientCommand,
CMD_ServerCommand
@ -49,17 +48,14 @@ public:
class Command;
friend class Command;
class Command
{
class Command {
friend class CmdMngr;
CPluginMngr::CPlugin* plugin;
CmdMngr* parent;
String command;
String argument;
String commandline;
String info;
bool listable;
int function;
int flags;
@ -67,33 +63,33 @@ 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( CPluginMngr::CPlugin* pplugin,const char* pcmd, const char* pinfo , int pflags , int pfunc, bool pviewable, CmdMngr* pparent );
~Command();
public:
inline const char* getCommand() { return command.c_str(); }
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 matchCommand(const char* cmd) { return (!strcmp(command.c_str(), cmd)); }
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)); }
inline bool gotAccess(int f) const { return (!flags||((flags & f)==flags)); }
inline CPluginMngr::CPlugin* getPlugin() { return plugin; }
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);
void setCmdType( int a );
};
private:
struct CmdPrefix;
friend struct CmdPrefix;
struct CmdLink
{
struct CmdLink {
Command* cmd;
CmdLink* next;
CmdLink(Command* c): cmd(c), next(0) {}
@ -103,40 +99,36 @@ private:
CmdLink* srvcmdlist;
CmdLink* clcmdlist;
struct CmdPrefix
{
struct CmdPrefix {
String name;
CmdMngr* parent;
CmdLink* list;
CmdPrefix* next;
CmdPrefix(const char* nn, CmdMngr* pp): name(nn), parent(pp), list(0), next(0) {}
~CmdPrefix() { parent->clearCmdLink(&list); }
CmdPrefix( const char* nn , CmdMngr* pp) : name(nn),parent(pp),list(0),next(0){}
~CmdPrefix(){ parent->clearCmdLink(&list); }
} *prefixHead;
bool registerCmdPrefix(Command* cc);
CmdPrefix** findPrefix(const char* nn);
bool registerCmdPrefix( Command* cc );
CmdPrefix** findPrefix( const char* nn );
void clearPrefix();
void setCmdLink(CmdLink** a, Command* c, bool sorted = true);
void clearCmdLink(CmdLink** phead, bool pclear = false);
void setCmdLink( CmdLink** a , Command* c, bool sorted = true );
void clearCmdLink( CmdLink** phead, bool pclear = false );
public:
CmdMngr();
~CmdMngr() { clear(); }
~CmdMngr() {clear();}
// 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 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();
class iterator
{
class iterator {
CmdLink *a;
public:
iterator(CmdLink*aa = 0) : a(aa) {}
@ -146,30 +138,28 @@ public:
operator bool () const { return a ? true : false; }
Command& operator*() { return *a->cmd; }
};
inline iterator clcmdprefixbegin(const char* nn)
{
inline iterator clcmdprefixbegin(const char* nn){
CmdPrefix* a = *findPrefix(nn);
return iterator(a ? a->list : 0);
return iterator( a ? a->list : 0 );
}
inline iterator clcmdbegin() const { return iterator(clcmdlist); }
inline iterator srvcmdbegin() const { return iterator(srvcmdlist); }
inline iterator begin(int type) const { return iterator(sortedlists[type]); }
inline iterator clcmdbegin() const {return iterator(clcmdlist);}
inline iterator srvcmdbegin() const {return iterator(srvcmdlist);}
inline iterator begin( int type ) const { return iterator(sortedlists[type]); }
inline iterator end() const { return iterator(0); }
private:
int buf_cmdid;
int buf_cmdtype;
int buf_cmdaccess;
iterator buf_cmdptr;
int buf_id;
int buf_type;
int buf_access;
int buf_num;
};
#endif //COMMANDS_H
#endif

View File

@ -48,7 +48,6 @@ EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
m_FlagWorld = (flags & 1) ? true : false; // flag a
m_FlagPlayer = (flags & 2) ? true : false; // flag b
m_FlagOnce = (flags & 4) ? true : false; // flag c
if (flags & 24)
{
m_FlagAlive = (flags & 16) ? true : false; // flag e
@ -65,14 +64,12 @@ EventsMngr::ClEvent::~ClEvent()
{
cond_t *tmp1 = m_Conditions;
cond_t *tmp2 = NULL;
while (tmp1)
{
tmp2 = tmp1->next;
delete tmp1;
tmp1 = tmp2;
}
m_Conditions = NULL;
}
@ -85,17 +82,14 @@ void EventsMngr::NextParam()
MsgDataEntry *tmp = NULL;
int tmpSize = 0;
if (m_ParseVault)
{
// copy to tmp
tmp = new MsgDataEntry[m_ParseVaultSize];
if (!tmp)
{
return; // :TODO: Error report !!
}
memcpy(tmp, m_ParseVault, m_ParseVaultSize * sizeof(MsgDataEntry));
tmpSize = m_ParseVaultSize;
delete [] m_ParseVault;
@ -108,7 +102,6 @@ void EventsMngr::NextParam()
m_ParseVaultSize = INITIAL_PARSEVAULT_SIZE;
m_ParseVault = new MsgDataEntry[m_ParseVaultSize];
if (tmp)
{
memcpy(m_ParseVault, tmp, tmpSize * sizeof(MsgDataEntry));
@ -135,6 +128,7 @@ EventsMngr::~EventsMngr()
clearEvents();
}
CPluginMngr::CPlugin * EventsMngr::ClEvent::getPlugin()
{
return m_Plugin;
@ -176,7 +170,7 @@ void EventsMngr::ClEvent::registerFilter(char *filter)
// rest of line
tmpCond->sValue.assign(value);
tmpCond->fValue = static_cast<float>(atof(value));
tmpCond->fValue = atof(value);
tmpCond->iValue = atoi(value);
tmpCond->next = NULL;
@ -184,11 +178,10 @@ void EventsMngr::ClEvent::registerFilter(char *filter)
if (m_Conditions)
{
cond_t *tmp = m_Conditions;
while (tmp->next)
tmp = tmp->next;
tmp->next = tmpCond;
}
else
m_Conditions = tmpCond;
@ -201,7 +194,6 @@ EventsMngr::ClEvent* EventsMngr::registerEvent(CPluginMngr::CPlugin* plugin, int
return NULL;
ClEvent *event = new ClEvent(plugin, func, flags);
if (!event)
return NULL;
@ -224,11 +216,12 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
if (!m_Events[msg_type].size())
return;
for (ClEventVecIter iter = m_Events[msg_type].begin(); iter; ++iter)
for(ClEventVecIter iter = m_Events[msg_type].begin(); iter; ++iter)
{
if ((*iter).m_Done)
continue;
if (!(*iter).m_Plugin->isExecutable((*iter).m_Func))
{
(*iter).m_Done = true;
@ -237,7 +230,7 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
if (pPlayer)
{
if (!(*iter).m_FlagPlayer || (pPlayer->IsAlive() ? !(*iter).m_FlagAlive : !(*iter).m_FlagDead))
if (!(*iter).m_FlagPlayer || (pPlayer->IsAlive() ? !(*iter).m_FlagAlive : !(*iter).m_FlagDead ) )
{
(*iter).m_Done = true;
continue;
@ -254,7 +247,6 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
(*iter).m_Done = true;
continue;
}
m_ParseNotDone = true;
}
@ -265,7 +257,6 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
m_ParseVault[0].type = MSG_INTEGER;
m_ParseVault[0].iValue = index;
}
m_ParseFun = &m_Events[msg_type];
}
@ -275,6 +266,7 @@ void EventsMngr::parseValue(int iValue)
if (!m_ParseNotDone || !m_ParseFun)
return;
// grow if needed
++m_ParsePos;
NextParam();
@ -292,25 +284,23 @@ void EventsMngr::parseValue(int iValue)
// loop through conditions
bool execute = false;
bool anyConditions = false;
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
{
if (condIter->paramId == m_ParsePos)
{
anyConditions = true;
switch (condIter->type)
switch(condIter->type)
{
case '=': if (condIter->iValue == iValue) execute = true; break;
case '!': if (condIter->iValue != iValue) execute = true; break;
case '&': if (iValue & condIter->iValue) execute = true; break;
case '<': if (iValue < condIter->iValue) execute = true; break;
case '>': if (iValue > condIter->iValue) execute = true; break;
case '=': if (condIter->iValue == iValue) execute=true; break;
case '!': if (condIter->iValue != iValue) execute=true; break;
case '&': if (iValue & condIter->iValue) execute=true; break;
case '<': if (iValue < condIter->iValue) execute=true; break;
case '>': if (iValue > condIter->iValue) execute=true; break;
}
if (execute)
break;
}
}
if (anyConditions && !execute)
(*iter).m_Done = true; // don't execute
}
@ -322,6 +312,7 @@ void EventsMngr::parseValue(float fValue)
if (!m_ParseNotDone || !m_ParseFun)
return;
// grow if needed
++m_ParsePos;
NextParam();
@ -339,25 +330,22 @@ void EventsMngr::parseValue(float fValue)
// loop through conditions
bool execute = false;
bool anyConditions = false;
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
{
if (condIter->paramId == m_ParsePos)
{
anyConditions = true;
switch (condIter->type)
switch(condIter->type)
{
case '=': if (condIter->fValue == fValue) execute = true; break;
case '!': if (condIter->fValue != fValue) execute = true; break;
case '<': if (fValue < condIter->fValue) execute = true; break;
case '>': if (fValue > condIter->fValue) execute = true; break;
case '=': if (condIter->fValue == fValue) execute=true; break;
case '!': if (condIter->fValue != fValue) execute=true; break;
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
}
@ -386,24 +374,21 @@ void EventsMngr::parseValue(const char *sz)
// loop through conditions
bool execute = false;
bool anyConditions = false;
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
{
if (condIter->paramId == m_ParsePos)
{
anyConditions = true;
switch (condIter->type)
switch(condIter->type)
{
case '=': if (!strcmp(sz, condIter->sValue.c_str())) execute = true; break;
case '!': if (strcmp(sz, condIter->sValue.c_str())) execute = true; break;
case '&': if (strstr(sz, condIter->sValue.c_str())) execute = true; break;
case '=': if (!strcmp(sz, condIter->sValue.c_str())) execute=true; break;
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
}
@ -418,12 +403,11 @@ void EventsMngr::executeEvents()
for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter)
{
if ((*iter).m_Done)
if ( (*iter).m_Done )
{
(*iter).m_Done = false;
continue;
}
(*iter).m_Stamp = (float)*m_Timer;
executeForwards((*iter).m_Func, m_ParseVault ? m_ParseVault[0].iValue : 0);
}
@ -439,30 +423,30 @@ int EventsMngr::getArgNum() const
const char* EventsMngr::getArgString(int a) const
{
if (a < 0 || a > m_ParsePos)
if ( a < 0 || a > m_ParsePos )
return "";
static char var[32];
switch (m_ParseVault[a].type)
switch(m_ParseVault[a].type)
{
case MSG_INTEGER:
sprintf(var, "%d", m_ParseVault[a].iValue);
sprintf( var, "%d", m_ParseVault[a].iValue );
return var;
case MSG_STRING:
return m_ParseVault[a].sValue;
default:
sprintf(var, "%g", m_ParseVault[a].fValue);
sprintf( var, "%g", m_ParseVault[a].fValue );
return var;
}
}
int EventsMngr::getArgInteger(int a) const
{
if (a < 0 || a > m_ParsePos)
if ( a < 0 || a > m_ParsePos )
return 0;
switch (m_ParseVault[a].type)
switch(m_ParseVault[a].type)
{
case MSG_INTEGER:
return m_ParseVault[a].iValue;
@ -475,15 +459,15 @@ int EventsMngr::getArgInteger(int a) const
float EventsMngr::getArgFloat(int a) const
{
if (a < 0 || a > m_ParsePos)
if ( a < 0 || a > m_ParsePos )
return 0.0f;
switch (m_ParseVault[a].type)
switch(m_ParseVault[a].type)
{
case MSG_INTEGER:
return static_cast<float>(m_ParseVault[a].iValue);
return m_ParseVault[a].iValue;
case MSG_STRING:
return static_cast<float>(atof(m_ParseVault[a].sValue));
return atof(m_ParseVault[a].sValue);
default:
return m_ParseVault[a].fValue;
}
@ -495,7 +479,6 @@ void EventsMngr::clearEvents(void)
{
m_Events[i].clear();
}
// delete parsevault
if (m_ParseVault)
{
@ -514,26 +497,25 @@ int EventsMngr::getEventId(const char* msg)
CS_EventsIds id;
} table[] =
{
{"CS_DeathMsg", CS_DeathMsg},
// {"CS_RoundEnd", CS_RoundEnd},
// {"CS_RoundStart", CS_RoundStart},
// {"CS_Restart", CS_Restart},
{"", CS_Null}
{ "CS_DeathMsg" , CS_DeathMsg },
// { "CS_RoundEnd" , CS_RoundEnd },
// { "CS_RoundStart" , CS_RoundStart },
// { "CS_Restart" , CS_Restart },
{ "" , CS_Null }
};
// if msg is a number, return it
int pos = atoi(msg);
if (pos != 0)
return pos;
// try to find in table first
for (pos = 0; table[pos].id != CS_Null; ++pos)
if (!strcmp(table[pos].name, msg))
return table[pos].id;
for (pos = 0; table[ pos ].id != CS_Null; ++pos )
if ( !strcmp( table[ pos ].name , msg ) )
return table[ pos ].id;
// find the id of the message
return pos = GET_USER_MSG_ID(PLID, msg, 0);
return pos = GET_USER_MSG_ID(PLID, msg , 0 );
}
int EventsMngr::getCurrentMsgType()

View File

@ -32,10 +32,9 @@
#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
{
enum {
CS_DEATHMSG = MAX_REG_MSGS,
// CS_ROUNDEND,
// CS_ROUNDSTART,
@ -117,7 +116,6 @@ private:
const char* sValue;
MsgParamType type;
};
MsgDataEntry *m_ParseVault;
int m_ParseVaultSize;
void NextParam(); // make sure a new parameter can be added
@ -132,7 +130,7 @@ private:
int m_ParsePos; // is args. num. - 1
float* m_Timer;
ClEvent* getValidEvent(ClEvent* a);
ClEvent* getValidEvent(ClEvent* a );
int m_CurrentMsgType;
public:
@ -142,20 +140,20 @@ 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;
void clearEvents(void);
static int getEventId(const char* msg);
static int getEventId( const char* msg );
int getCurrentMsgType();
};
#endif //__CEVENTS_H__
#endif // #ifdef __CEVENTS_H__

View File

@ -36,71 +36,70 @@
// *****************************************************
// class File
// *****************************************************
File::File(const char* n, const char* m)
File::File( const char* n, const char* m )
{
fp = fopen(n, m);
fp = fopen( n , m );
}
File::~File()
File::~File( )
{
if (fp)
fclose(fp);
if ( fp )
fclose( fp );
}
File::operator bool () const
File::operator bool ( ) const
{
return fp && !feof(fp);
}
File& operator<<(File& f, const String& n)
File& operator<<( File& f, const String& n )
{
if (f) fputs(n.c_str(), f.fp);
if ( f ) fputs( n.c_str() , f.fp ) ;
return f;
}
File& operator<<(File& f, const char* n)
File& operator<<( File& f, const char* n )
{
if (f) fputs(n, f.fp);
if ( f ) fputs( n , f.fp ) ;
return f;
}
File& operator<<(File& f, int n)
File& operator<<( File& f, int n )
{
if (f) fprintf(f.fp, "%d", n);
if ( f ) fprintf( f.fp , "%d" , n ) ;
return f;
}
File& operator<<(File& f, const char& c)
File& operator<<( File& f, const char& c )
{
if (f) fputc(c, f.fp);
if ( f ) fputc( c , f.fp ) ;
return f;
}
File& operator>>(File& f, String& n)
File& operator>>( File& f, String& n )
{
if (!f) return f;
if ( !f ) return f;
char temp[1024];
fscanf(f.fp, "%s", temp);
fscanf( f.fp , "%s", temp );
n.assign(temp);
return f;
}
File& operator>>(File& f, char* n)
File& operator>>( File& f, char* n )
{
if (f) fscanf(f.fp, "%s", n);
if ( f ) fscanf( f.fp , "%s", n );
return f;
}
int File::getline(char* buf, int sz)
int File::getline( char* buf, int sz )
{
int a = sz;
char *origBuf = buf;
if (*this)
if ( *this )
{
int c;
while (sz-- && (c = getc((*this).fp)) && c != EOF && c != '\n')
while ( sz-- && (c = getc( (*this).fp)) && c != EOF && c != '\n' )
*buf++ = c;
*buf = 0;
}
@ -116,11 +115,12 @@ int File::getline(char* buf, int sz)
return a - sz;
}
File& File::skipWs()
File& File::skipWs( )
{
if (!*this) return *this;
if ( !*this ) return *this;
int c;
while (isspace(c = getc(fp))) {};
ungetc(c, fp);
while( isspace( c = getc( fp ) ) ){};
ungetc( c , fp );
return *this;
}

View File

@ -41,19 +41,18 @@ class File
FILE* fp;
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();
File( const char* n, const char* m );
~File( );
operator bool ( ) const;
friend File& operator<<( File& f, const String& n );
friend File& operator<<( File& f, const char* n );
friend File& operator<<( File& f, const char& c );
friend File& operator<<( File& f, int n );
friend File& operator>>( File& f, String& n );
friend File& operator>>( File& f, char* n );
int getline( char* buf, int sz );
File& skipWs( );
};

View File

@ -30,21 +30,19 @@
*/
#include "amxmodx.h"
#include "debugger.h"
void AMXAPI amxx_InvalidateTrace(AMX *amx);
CForward::CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam *paramTypes)
{
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)
@ -76,73 +74,67 @@ 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();
AMX_DBGINFO *pInfo = (AMX_DBGINFO *)(amx->userdata[2]);
if (pInfo)
pInfo->error = AMX_ERR_NONE;
// handle strings & arrays
int i, ax = 0;
int i, ax=0;
for (i = 0; i < m_NumParams; ++i)
{
if (m_ParamTypes[i] == FP_STRING || m_ParamTypes[i] == FP_STRINGEX)
{
cell *tmp;
amx_Allot(iter->pPlugin->getAMX(), (m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i])) + 1 : STRINGEX_MAXLENGTH, &realParams[i], &tmp);
amx_Allot(iter->pPlugin->getAMX(),
(m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i]))+1 : STRINGEX_MAXLENGTH,
&realParams[i], &tmp);
amx_SetStringOld(tmp, (const char *)(params[i]), 0, 0);
physAddrs[i] = tmp;
}
else if (m_ParamTypes[i] == FP_ARRAY)
{
cell *tmp;
amx_Allot(amx, preparedArrays[params[i]].size, &realParams[i], &tmp);
amx_Allot(amx, preparedArrays[params[i]].size,
&realParams[i], &tmp);
physAddrs[i] = tmp;
if (preparedArrays[params[i]].type == Type_Cell)
{
memcpy(tmp, preparedArrays[params[i]].ptr, preparedArrays[params[i]].size * sizeof(cell));
} else {
}
else
{
char *data = (char*)preparedArrays[params[i]].ptr;
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
*tmp++ = (static_cast<cell>(*data++)) & 0xFF;
}
} else {
}
else
{
realParams[i] = params[i];
}
}
//Push the parameters in reverse order. Weird, unfriendly part of Small 3.0!
for (i = m_NumParams-1; i >= 0; i--)
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)
{
//Did something else set an error?
if (pDebugger && pDebugger->ErrorExists())
if (pInfo && pInfo->error != AMX_ERR_NONE)
{
//we don't care, something else logged the error.
}
else if (err != -1)
{
} else {
//nothing logged the error so spit it out anyway
LogError(amx, err, NULL);
LogError(amx, err, "");
}
}
amxx_InvalidateTrace(amx);
amx->error = AMX_ERR_NONE;
if (pDebugger)
pDebugger->EndExec();
// cleanup strings & arrays
for (i = 0; i < m_NumParams; ++i)
{
@ -165,9 +157,10 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
if (preparedArrays[params[i]].type == Type_Cell)
{
memcpy(preparedArrays[params[i]].ptr, tmp, preparedArrays[params[i]].size * sizeof(cell));
} else {
}
else
{
char *data = (char*)preparedArrays[params[i]].ptr;
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
*data++ = static_cast<char>(*tmp++ & 0xFF);
}
@ -197,7 +190,6 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
}
}
}
return globRetVal;
}
@ -237,66 +229,62 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
if (!pPlugin->isExecutable(m_Func))
return 0;
Debugger *pDebugger = (Debugger *)m_Amx->userdata[UD_DEBUGGER];
if (pDebugger)
pDebugger->BeginExec();
AMX_DBGINFO *pInfo = (AMX_DBGINFO *)(m_Amx->userdata[2]);
if (pInfo)
pInfo->error = AMX_ERR_NONE;
// handle strings & arrays
int i;
for (i = 0; i < m_NumParams; ++i)
{
if (m_ParamTypes[i] == FP_STRING || m_ParamTypes[i] == FP_STRINGEX)
{
cell *tmp;
amx_Allot(m_Amx, (m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i])) + 1 : STRINGEX_MAXLENGTH, &realParams[i], &tmp);
amx_Allot(m_Amx,
(m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i]))+1 : STRINGEX_MAXLENGTH,
&realParams[i], &tmp);
amx_SetStringOld(tmp, (const char *)(params[i]), 0, 0);
physAddrs[i] = tmp;
}
else if (m_ParamTypes[i] == FP_ARRAY)
{
cell *tmp;
amx_Allot(m_Amx, preparedArrays[params[i]].size, &realParams[i], &tmp);
amx_Allot(m_Amx, preparedArrays[params[i]].size,
&realParams[i], &tmp);
physAddrs[i] = tmp;
if (preparedArrays[params[i]].type == Type_Cell)
{
memcpy(tmp, preparedArrays[params[i]].ptr, preparedArrays[params[i]].size * sizeof(cell));
} else {
}
else
{
char *data = (char*)preparedArrays[params[i]].ptr;
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
*tmp++ = (static_cast<cell>(*data++)) & 0xFF;
}
} else {
}
else
{
realParams[i] = params[i];
}
}
for (i = m_NumParams - 1; i >= 0; i--)
for (i=m_NumParams-1; i>=0; i--)
amx_Push(m_Amx, realParams[i]);
// exec
cell retVal;
int err = amx_Exec(m_Amx, &retVal, m_Func);
if (err != AMX_ERR_NONE)
{
//Did something else set an error?
if (pDebugger && pDebugger->ErrorExists())
if (pInfo && pInfo->error != AMX_ERR_NONE)
{
//we don't care, something else logged the error.
}
else if (err != -1)
{
} else {
//nothing logged the error so spit it out anyway
LogError(m_Amx, err, NULL);
LogError(m_Amx, err, "");
}
}
if (pDebugger)
pDebugger->EndExec();
amxx_InvalidateTrace(m_Amx);
m_Amx->error = AMX_ERR_NONE;
// cleanup strings & arrays
@ -321,9 +309,10 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
if (preparedArrays[params[i]].type == Type_Cell)
{
memcpy(preparedArrays[params[i]].ptr, tmp, preparedArrays[params[i]].size * sizeof(cell));
} else {
}
else
{
char *data = (char*)preparedArrays[params[i]].ptr;
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
*data++ = static_cast<char>(*tmp++ & 0xFF);
}
@ -339,12 +328,9 @@ 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;
}
@ -352,26 +338,22 @@ 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;
@ -380,7 +362,6 @@ int CForwardMngr::registerSPForward(int func, AMX *amx, int numParams, const For
m_SPForwards.push_back(pForward);
}
return retVal;
}
@ -388,58 +369,56 @@ 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->Set(funcName, amx, numParams, paramTypes);
if (pForward->getFuncsNum() == 0)
return -1;
m_FreeSPForwards.pop();
} else {
}
else
{
pForward = new CSPForward();
if (!pForward)
return -1;
pForward->Set(funcName, amx, numParams, paramTypes);
if (pForward->getFuncsNum() == 0)
{
delete pForward;
return -1;
}
m_SPForwards.push_back(pForward);
}
return retVal;
}
bool CForwardMngr::isIdValid(int id) const
{
return (id >= 0) && ((id & 1) ? (static_cast<size_t>(id >> 1) < m_SPForwards.size()) : (static_cast<size_t>(id >> 1) < m_Forwards.size()));
return (id >= 0) && ((id & 1) ?
(static_cast<size_t>(id >> 1) < m_SPForwards.size()) :
(static_cast<size_t>(id >> 1) < m_Forwards.size()));
}
cell CForwardMngr::executeForwards(int id, cell *params)
{
int retVal = (id & 1) ? m_SPForwards[id >> 1]->execute(params, m_TmpArrays) : m_Forwards[id >> 1]->execute(params, m_TmpArrays);
int retVal = (id & 1) ? m_SPForwards[id >> 1]->execute(params, m_TmpArrays) :
m_Forwards[id >> 1]->execute(params, m_TmpArrays);
m_TmpArraysNum = 0;
return retVal;
}
int CForwardMngr::getParamsNum(int id) const
{
return (id & 1) ? m_SPForwards[id >> 1]->getParamsNum() : m_Forwards[id >> 1]->getParamsNum();
return (id & 1) ? m_SPForwards[id >> 1]->getParamsNum() :
m_Forwards[id >> 1]->getParamsNum();
}
ForwardParam CForwardMngr::getParamType(int id, int paramNum) const
{
return (id & 1) ? m_SPForwards[id >> 1]->getParamType(paramNum) : m_Forwards[id >> 1]->getParamType(paramNum);
return (id & 1) ? m_SPForwards[id >> 1]->getParamType(paramNum) :
m_Forwards[id >> 1]->getParamType(paramNum);
}
void CForwardMngr::clear()
@ -448,9 +427,7 @@ void CForwardMngr::clear()
{
delete *iter;
}
SPForwardVec::iterator spIter;
for (spIter = m_SPForwards.begin(); spIter != m_SPForwards.end(); ++spIter)
{
delete (*spIter);
@ -458,10 +435,8 @@ void CForwardMngr::clear()
m_Forwards.clear();
m_SPForwards.clear();
while (!m_FreeSPForwards.empty())
m_FreeSPForwards.pop();
m_TmpArraysNum = 0;
}
@ -473,97 +448,74 @@ 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);
}
@ -573,12 +525,9 @@ 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)
@ -589,9 +538,7 @@ cell executeForwards(int id, ...)
else
params[i] = (cell)va_arg(argptr, cell);
}
va_end(argptr);
return g_forwards.executeForwards(id, params);
}
@ -599,16 +546,13 @@ cell CForwardMngr::prepareArray(void *ptr, unsigned int size, ForwardArrayElemTy
{
if (m_TmpArraysNum >= FORWARD_MAX_PARAMS)
{
#ifdef MEMORY_TEST
#ifdef MEMORY_TEST
m_validateAllAllocUnits();
#endif // MEMORY_TEST
#endif // MEMORY_TEST
AMXXLOG_Log("[AMXX] Forwards with more than 32 parameters are not supported (tried to prepare array # %d).", m_TmpArraysNum + 1);
m_TmpArraysNum = 0;
return -1;
}
m_TmpArrays[m_TmpArraysNum].ptr = ptr;
m_TmpArrays[m_TmpArraysNum].size = size;
m_TmpArrays[m_TmpArraysNum].type = type;

View File

@ -77,9 +77,7 @@ enum ForwardArrayElemType
struct ForwardPreparedArray
{
void *ptr;
ForwardArrayElemType type;
unsigned int size;
bool copyBack;
};
@ -90,39 +88,31 @@ class CForward
const char *m_FuncName;
ForwardExecType m_ExecType;
int m_NumParams;
struct AMXForward
{
CPluginMngr::CPlugin *pPlugin;
int func;
};
typedef CVector<AMXForward> AMXForwardList;
AMXForwardList m_Funcs;
ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS];
public:
CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes);
CForward() {} // leaves everything unitialized'
CForward()
{ } // leaves everything unitialized'
cell execute(cell *params, ForwardPreparedArray *preparedArrays);
int getParamsNum() const
{
return m_NumParams;
}
int getFuncsNum() const
{
return m_Funcs.size();
}
ForwardParam getParamType(int paramId) const
{
if (paramId < 0 || paramId >= m_NumParams)
return FP_DONE;
return m_ParamTypes[paramId];
}
};
@ -132,13 +122,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;
public:
bool isFree;
public:
@ -147,22 +134,18 @@ public:
void Set(int func, AMX *amx, int numParams, const ForwardParam * paramTypes);
cell execute(cell *params, ForwardPreparedArray *preparedArrays);
int getParamsNum() const
{
return m_NumParams;
}
int getFuncsNum() const
{
return (m_HasFunc) ? 1 : 0;
}
ForwardParam getParamType(int paramId) const
{
if (paramId < 0 || paramId >= m_NumParams)
return FP_DONE;
return m_ParamTypes[paramId];
}
};
@ -184,7 +167,8 @@ public:
CForwardMngr()
{ m_TmpArraysNum = 0; }
~CForwardMngr() {}
~CForwardMngr()
{ }
// Interface
// Register normal forward
@ -192,21 +176,18 @@ 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
cell prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type,
bool copyBack); // prepare array
};
// (un)register forward
@ -221,4 +202,5 @@ cell executeForwards(int id, ...);
cell prepareCellArray(cell *ptr, unsigned int size, bool copyBack = false);
cell prepareCharArray(char *ptr, unsigned int size, bool copyBack = false);
#endif //FORWARD_H
#endif

View File

@ -157,7 +157,7 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower)
int flag = 0;
size_t strln = strlen(str);
for (i = strln - 1; i >= 0; i--)
for (i=strln-1; i>=0; i--)
{
if (str[i] == '\n' || str[i] == ' ' || str[i] == '\t')
{
@ -184,7 +184,6 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower)
}
newstr[pos] = 0;
return ptr - str + 1;
}
@ -280,7 +279,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)
@ -301,12 +300,11 @@ CLangMngr::CLang::~CLang()
void CLangMngr::CLang::Clear()
{
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
for (unsigned int i=0; i<m_LookUpTable.size(); i++)
{
if (m_LookUpTable[i])
delete m_LookUpTable[i];
}
m_LookUpTable.clear();
}
@ -314,7 +312,7 @@ CLangMngr::CLang::LangEntry * CLangMngr::CLang::GetEntry(int pkey)
{
unsigned int i;
for (i = 0; i < m_LookUpTable.size(); i++)
for (i=0; i<m_LookUpTable.size(); i++)
{
if (m_LookUpTable[i]->GetKey() == pkey)
{
@ -334,13 +332,11 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
{
const char *def = 0;
int key = -1;
while (!vec.empty())
{
key = vec.front()->key;
def = vec.front()->def->c_str();
LangEntry *entry = GetEntry(key);
if (entry->GetDefHash() != MakeHash(def))
{
if (entry->GetCache())
@ -352,7 +348,6 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
//AMXXLOG_Log("[AMXX] Language key %s[%s] defined twice", m_LMan->GetKey(key), m_LanguageName);
}
}
delete vec.front();
vec.pop();
}
@ -362,22 +357,20 @@ const char * CLangMngr::CLang::GetDef(const char *key)
{
static char nfind[1024] = "ML_NOTFOUND(KEY)";
int ikey = m_LMan->GetKeyEntry(key);
if (ikey == -1)
{
sprintf(nfind, "ML_NOTFOUND: %s", key);
return nfind;
}
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
{
if (m_LookUpTable[i]->GetKey() == ikey)
return m_LookUpTable[i]->GetDef();
}
return NULL;
}
struct OffsetPair
{
uint32_t defOffset;
@ -388,8 +381,7 @@ struct OffsetPair
bool CLangMngr::CLang::SaveDefinitions(FILE *fp, uint32_t &curOffset)
{
unsigned short defLen = 0;
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
{
defLen = m_LookUpTable[i]->GetDefLength();
fwrite((void *)&defLen, sizeof(unsigned short), 1, fp);
@ -411,7 +403,7 @@ bool CLangMngr::CLang::Save(FILE *fp, int &defOffset, uint32_t &curOffset)
fwrite((void*)&size, sizeof(uint32_t), 1, fp);
curOffset += sizeof(uint32_t);
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
{
keynum = m_LookUpTable[i]->GetKey();
defhash = m_LookUpTable[i]->GetDefHash();
@ -431,6 +423,7 @@ bool CLangMngr::CLang::Save(FILE *fp, int &defOffset, uint32_t &curOffset)
// assumes fp is set to the right position
bool CLangMngr::CLang::Load(FILE *fp)
{
return true;
}
@ -468,10 +461,9 @@ int CLangMngr::GetKeyEntry(const char *key)
return -1;
}
for (i = 0; i < KeyList.size(); i++)
for (i = 0; i<KeyList.size(); i++)
{
cmpKey = KeyList[i]->hash;
if (hKey == cmpKey)
{
return i;
@ -498,7 +490,7 @@ int CLangMngr::GetKeyEntry(String &key)
uint32_t hKey = MakeHash(key.c_str(), true);
unsigned int i = 0;
for (i = 0; i < KeyList.size(); i++)
for (i = 0; i<KeyList.size(); i++)
{
if (hKey == KeyList[i]->hash)
{
@ -529,7 +521,6 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
{
// number of parameters ( for NEXT_PARAM macro )
int paramCount = *params / sizeof(cell);
// the output buffer
static char outbuf[4096];
char *outptr = outbuf;
@ -540,14 +531,13 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
if (*src == '%')
{
++src;
if (*src == 'L')
if (*src=='L')
{
cell langName = params[parm]; // "en" case (langName contains the address to the string)
NEXT_PARAM();
cell *pAmxLangName = get_amxaddr(amx, params[parm++]); // other cases
const char *cpLangName=NULL;
// Handle player ids (1-32) and server language
if (*pAmxLangName == LANG_PLAYER) // LANG_PLAYER
{
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
@ -556,13 +546,9 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
} else {
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
}
}
else if (*pAmxLangName == LANG_SERVER) // LANG_SERVER
{
} else if (*pAmxLangName == LANG_SERVER) { // LANG_SERVER
cpLangName = g_vault.get("server_language");
}
else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) // Direct Client Id
{
} else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) { // Direct Client Id
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
{
cpLangName = g_vault.get("server_language");
@ -573,34 +559,30 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
int tmplen = 0;
cpLangName = get_amxstring(amx, langName, 2, tmplen);
}
if (!cpLangName || strlen(cpLangName) < 1)
cpLangName = "en";
int tmplen = 0;
NEXT_PARAM();
char *key = get_amxstring(amx, params[parm++], 1, tmplen);
const char *def = GetDef(cpLangName, key);
if (def == NULL)
{
if (*pAmxLangName != LANG_SERVER)
{
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;
}
}
while (*def)
{
if (*def == '%')
@ -610,18 +592,19 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
{
*outptr++ = '%';
++def;
} else {
}
else
{
static char format[32];
format[0] = '%';
char *ptr = format + 1;
char *ptr = format+1;
while (ptr-format<sizeof(format) && !isalpha(*ptr++ = *def++))
/*nothing*/;
ZEROTERM(format);
*ptr = 0;
switch (*(ptr - 1))
switch ( *(ptr-1) )
{
case 's':
{
@ -630,7 +613,8 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
NEXT_PARAM();
cell *tmpCell = get_amxaddr(amx, params[parm++]);
while (tmpPtr-tmpString < sizeof(tmpString) && *tmpCell)
*tmpPtr++ = static_cast<char>(*tmpCell++);
*tmpPtr++ = *tmpCell++;
*tmpPtr = 0;
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, tmpString);
ZEROTERM(outbuf);
@ -655,19 +639,17 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
}
default:
{
CHECK_OUTPTR(strlen(format) + 1);
CHECK_OUTPTR(strlen(format)+1);
strcpy(outptr, format);
break;
}
}
outptr += strlen(outptr);
}
}
else if (*def == '^')
{
++def;
switch (*def)
{
case 'n':
@ -688,36 +670,37 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
*outptr++ = *def;
break;
}
++def;
} else {
}
else
{
CHECK_OUTPTR(1);
*outptr++ = *def++;
}
}
} else {
}
else
{
static char tmpString[4096];
char *tmpPtr = tmpString;
int tmpLen = 0;
static char format[32] = {'%'};
char *ptr = format + 1;
char *ptr = format+1;
if (*src != '%')
{
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = static_cast<char>(*src++)))
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = *src++))
/*nothing*/;
*ptr = 0;
ZEROTERM(format);
--src;
switch (*(ptr - 1))
switch ( *(ptr-1) )
{
case 's':
{
NEXT_PARAM();
cell *tmpCell = get_amxaddr(amx, params[parm++]);
while (tmpPtr-tmpString<sizeof(tmpString) && *tmpCell)
*tmpPtr++ = static_cast<char>(*tmpCell++);
*tmpPtr++ = *tmpCell++;
*tmpPtr = 0;
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, tmpString);
ZEROTERM(outbuf);
@ -740,29 +723,28 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
}
default:
{
CHECK_OUTPTR(strlen(format) + 1);
CHECK_OUTPTR(strlen(format)+1);
strcpy(outptr, format);
break;
}
}
outptr += strlen(outptr);
} else {
CHECK_OUTPTR(1);
*outptr++ = '%';
}
}
} else {
}
else
{
CHECK_OUTPTR(1);
*outptr++ = static_cast<char>(*src);
*outptr++ = *src;
}
++src;
}
len = outptr - outbuf;
CHECK_OUTPTR(1);
*outptr++ = 0;
return outbuf;
}
@ -772,7 +754,6 @@ const char *CLangMngr::Format(const char *fmt, ...)
va_start(ap, fmt);
const char *retVal = FormatString(fmt, ap);
va_end(ap);
return retVal;
}
@ -801,13 +782,12 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
if (*src == '%')
{
++src;
if (*src == 'L')
if (*src=='L')
{
NEXT_PARAM();
const char *pAmxLangName = va_arg(ap, const char*);
const char *cpLangName=NULL;
// Handle player ids (1-32) and server language
if (pAmxLangName == (const char *)LANG_PLAYER) // LANG_PLAYER
{
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
@ -816,13 +796,9 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
} else {
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
}
}
else if (pAmxLangName == (const char *)LANG_SERVER) // LANG_SERVER
{
} else if (pAmxLangName == (const char *)LANG_SERVER) { // LANG_SERVER
cpLangName = g_vault.get("server_language");
}
else if (pAmxLangName >= (const char *)1 && pAmxLangName <= (const char *)32) // Direct Client Id
{
} else if (pAmxLangName >= (const char *)1 && pAmxLangName <= (const char *)32) { // Direct Client Id
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
{
cpLangName = g_vault.get("server_language");
@ -833,33 +809,29 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
int tmplen = 0;
cpLangName = pAmxLangName;
}
if (!cpLangName || strlen(cpLangName) < 1)
cpLangName = "en";
int tmplen = 0;
const char *key = va_arg(ap, const char *);
const char *def = GetDef(cpLangName, key);
if (def == NULL)
{
if (pAmxLangName != LANG_SERVER)
{
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;
}
}
while (*def)
{
if (*def == '%')
@ -867,7 +839,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
++def;
static char format[32];
format[0] = '%';
char *ptr = format + 1;
char *ptr = format+1;
while (ptr-format<sizeof(format) && !isalpha(*ptr++ = *def++))
/*nothing*/;
ZEROTERM(format);
@ -875,8 +847,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
*ptr = 0;
vsprintf(outptr, format, ap);
// vsprintf doesnt alter the ap, increment here
switch (*(ptr - 1))
switch (*(ptr-1))
{
case 'f':
va_arg(ap, double);
@ -891,13 +862,11 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
va_arg(ap, int);
break;
}
outptr += strlen(outptr);
}
else if (*def == '^')
{
++def;
switch (*def)
{
case 'n':
@ -918,28 +887,29 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
*outptr++ = *def;
break;
}
++def;
} else {
}
else
{
CHECK_OUTPTR(1);
*outptr++ = *def++;
}
}
} else {
}
else
{
static char format[32] = {'%'};
char *ptr = format + 1;
char *ptr = format+1;
if (*src != '%')
{
while (*src != 0 && ptr-format < sizeof(format) && !isalpha(*ptr++ = *src++))
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = *src++))
/*nothing*/;
*ptr = 0;
ZEROTERM(format);
--src;
vsprintf(outptr, format, ap);
// vsprintf doesnt alter the ap, increment here
switch (*(ptr - 1))
switch (*(ptr-1))
{
case 'f':
va_arg(ap, double);
@ -954,26 +924,24 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
va_arg(ap, int);
break;
}
outptr += strlen(outptr);
} else {
CHECK_OUTPTR(1);
*outptr++ = '%';
}
}
} else {
}
else
{
CHECK_OUTPTR(1);
*outptr++ = *src;
}
++src;
}
CHECK_OUTPTR(1);
*outptr++ = 0;
return outbuf;
}
void CLangMngr::MergeDefinitions(const char *lang, CQueue<sKeyDef*> &tmpVec)
{
CLang * language = GetLang(lang);
@ -989,9 +957,9 @@ int CLangMngr::MergeDefinitionFile(const char *file)
if (!fp)
{
CVector<md5Pair *>::iterator iter;
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
for (iter=FileList.begin(); iter!=FileList.end(); ++iter)
{
if ((*iter)->file.compare(file) == 0)
if ( (*iter)->file.compare(file) == 0 )
{
char buf[33] = {0};
(*iter)->val.assign(buf);
@ -1001,7 +969,6 @@ int CLangMngr::MergeDefinitionFile(const char *file)
AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file);
return 0;
}
MD5 md5;
md5.update(fp); // closes for us
md5.finalize();
@ -1010,11 +977,11 @@ int CLangMngr::MergeDefinitionFile(const char *file)
bool foundFlag = false;
CVector<md5Pair *>::iterator iter;
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
for (iter=FileList.begin(); iter!=FileList.end(); ++iter)
{
if ((*iter)->file.compare(file) == 0)
if ( (*iter)->file.compare(file) == 0 )
{
if ((*iter)->val.compare(md5buffer) == 0)
if ( (*iter)->val.compare(md5buffer) == 0 )
{
return -1;
} else {
@ -1055,9 +1022,6 @@ int CLangMngr::MergeDefinitionFile(const char *file)
buf.trim();
if (buf[0] == 0)
continue;
if ((buf[0] == ';') || (buf[0] == '/' && buf[1] == '/'))
continue;
if (buf[0] == '[' && buf.size() >= 3)
{
if (multiline)
@ -1067,12 +1031,10 @@ int CLangMngr::MergeDefinitionFile(const char *file)
delete tmpEntry;
tmpEntry = 0;
}
if (!Defq.empty())
{
MergeDefinitions(language, Defq);
}
language[0] = buf[1];
language[1] = buf[2];
language[2] = 0;
@ -1080,14 +1042,13 @@ int CLangMngr::MergeDefinitionFile(const char *file)
if (!multiline)
{
pos = buf.find('=');
if (pos > String::npos)
{
tmpEntry = new sKeyDef;
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);
@ -1101,7 +1062,6 @@ int CLangMngr::MergeDefinitionFile(const char *file)
tmpEntry = 0;
} else {
pos = buf.find(':');
if (pos > String::npos)
{
tmpEntry = new sKeyDef;
@ -1132,7 +1092,6 @@ int CLangMngr::MergeDefinitionFile(const char *file)
} // if !multiline
} //if - main
}
// merge last section
if (!Defq.empty())
{
@ -1146,9 +1105,9 @@ int CLangMngr::MergeDefinitionFile(const char *file)
CLangMngr::CLang * CLangMngr::GetLang(const char *name)
{
LangVecIter iter;
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
{
if (strcmp((*iter)->GetName(), name) == 0)
if ( strcmp((*iter)->GetName(), name)==0 )
return (*iter);
}
@ -1163,9 +1122,9 @@ CLangMngr::CLang * CLangMngr::GetLang(const char *name)
CLangMngr::CLang * CLangMngr::GetLangR(const char *name)
{
LangVecIter iter;
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
{
if (strcmp((*iter)->GetName(), name) == 0)
if ( strcmp((*iter)->GetName(), name)==0 )
return (*iter);
}
@ -1177,7 +1136,6 @@ const char *CLangMngr::GetDef(const char *langName, const char *key)
CLang *lang = GetLangR(langName);
if (lang)
return lang->GetDef(key);
return "ML_NOTFOUND(LANG)";
}
@ -1208,7 +1166,7 @@ bool CLangMngr::Save(const char *filename)
curOffset += sizeof(uint32_t);
uint32_t langOffset = curOffset + ktbSize + ltbSize;
for (unsigned int i = 0; i < m_Languages.size(); i++)
for (unsigned int i = 0; i<m_Languages.size(); i++)
{
langName = m_Languages[i]->GetName();
fwrite(langName, sizeof(char), 2, fp);
@ -1221,7 +1179,7 @@ bool CLangMngr::Save(const char *filename)
//Note - langOffset now points to the start of key lookup table
uint32_t keyHash = 0;
uint32_t keyOffset = langOffset;
for (unsigned int i = 0; i < KeyList.size(); i++)
for (unsigned int i = 0; i<KeyList.size(); i++)
{
keyHash = KeyList[i]->hash;
fwrite((void*)&keyHash, sizeof(uint32_t), 1, fp);
@ -1234,7 +1192,7 @@ bool CLangMngr::Save(const char *filename)
//Note - now keyOffset points toward the start of the def table
int defOffset = keyOffset;
for (unsigned int i = 0; i < m_Languages.size(); i++)
for (unsigned int i = 0; i<m_Languages.size(); i++)
{
m_Languages[i]->Save(fp, defOffset, curOffset);
}
@ -1242,7 +1200,7 @@ bool CLangMngr::Save(const char *filename)
//Now, defOffset points toward the END of the file
//curoffset should point toward the key table, so...
unsigned char keyLen = 0;
for (unsigned int i = 0; i < KeyList.size(); i++)
for (unsigned int i = 0; i<KeyList.size(); i++)
{
keyLen = KeyList[i]->key.size();
fwrite((void*)&keyLen, sizeof(unsigned char), 1, fp);
@ -1253,7 +1211,7 @@ bool CLangMngr::Save(const char *filename)
//Finally, write the def table
// It's assumed no orders changed...
for (unsigned int i = 0; i < m_Languages.size(); i++)
for (unsigned int i = 0; i<m_Languages.size(); i++)
{
m_Languages[i]->SaveDefinitions(fp, curOffset);
}
@ -1278,7 +1236,7 @@ bool CLangMngr::SaveCache(const char *filename)
fwrite((void *)&dictCount, sizeof(short), 1, fp);
for (i = FileList.begin(); i != FileList.end(); i++)
for (i=FileList.begin(); i!=FileList.end(); i++)
{
len = (*i)->file.size();
fwrite((void *)&len, sizeof(char), 1, fp);
@ -1306,7 +1264,8 @@ bool CLangMngr::LoadCache(const char *filename)
fread((void*)&dictCount, sizeof(short), 1, fp);
md5Pair *p = 0;
for (int i = 1; i <= dictCount; i++)
for (int i=1; i<=dictCount; i++)
{
fread((void*)&len, sizeof(char), 1, fp);
fread(buf, sizeof(char), len, fp);
@ -1352,8 +1311,7 @@ bool CLangMngr::Load(const char *filename)
uint32_t *LangOffsets = new uint32_t[langCount];
char langname[3];
for (unsigned int i = 0; i < langCount; i++)
for (unsigned int i=0; i<langCount; i++)
{
fread(langname, sizeof(char), 2, fp);
langname[2] = 0;
@ -1366,8 +1324,7 @@ bool CLangMngr::Load(const char *filename)
keyEntry *e = 0;
unsigned char keylen;
uint32_t keyoffset, save;
for (unsigned i = 0; i < keycount; i++)
for (unsigned i=0; i<keycount; i++)
{
e = new keyEntry;
fread((void*)&(e->hash), sizeof(uint32_t), 1, fp);
@ -1375,7 +1332,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);
@ -1390,12 +1347,10 @@ bool CLangMngr::Load(const char *filename)
uint32_t defhash;
uint32_t defoffset;
unsigned short deflen;
for (unsigned int i = 0; i < langCount; i++)
for (unsigned int i=0; i<langCount; i++)
{
fread((void*)&numentries, sizeof(uint32_t), 1, fp);
for (unsigned int j = 0; j < numentries; j++)
for (unsigned int j=0; j<numentries; j++)
{
fread((void *)&keynum, sizeof(uint32_t), 1, fp);
fread((void *)&defhash, sizeof(uint32_t), 1, fp);
@ -1403,7 +1358,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);
@ -1428,20 +1383,19 @@ CLangMngr::~CLangMngr()
void CLangMngr::Clear()
{
unsigned int i = 0;
for (i = 0; i < m_Languages.size(); i++)
for (i=0; i<m_Languages.size(); i++)
{
if (m_Languages[i])
delete m_Languages[i];
}
for (i = 0; i < FileList.size(); i++)
for (i=0; i<FileList.size(); i++)
{
if (FileList[i])
delete FileList[i];
}
for (i = 0; i < KeyList.size(); i++)
for (i=0; i<KeyList.size(); i++)
{
if (KeyList[i])
delete KeyList[i];
@ -1461,8 +1415,7 @@ const char *CLangMngr::GetLangName(int langId)
{
int i = 0;
LangVecIter iter;
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
{
if (i == langId)
{
@ -1470,15 +1423,13 @@ const char *CLangMngr::GetLangName(int langId)
}
i++;
}
return "";
}
bool CLangMngr::LangExists(const char *langName)
{
char buf[3] = {0};
char buf[3] = { 0 };
int i = 0;
while (buf[i] = tolower(*langName++))
{
if (++i == 2)
@ -1486,13 +1437,11 @@ bool CLangMngr::LangExists(const char *langName)
}
LangVecIter iter;
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
{
if (strcmp((*iter)->GetName(), buf) == 0)
if ( strcmp((*iter)->GetName(), buf)==0 )
return true;
}
return false;
}

View File

@ -51,7 +51,6 @@ struct sKeyDef
{
sKeyDef() { key = -1; def = 0; }
~sKeyDef() { if (def) delete def; }
int key;
String *def;
};
@ -78,9 +77,8 @@ 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
const char *GetName() { return m_LanguageName; }
// Save to file
@ -93,8 +91,8 @@ class CLangMngr
int Entries() { return m_LookUpTable.size(); }
// Make a hash from a string; convert to lowercase first if needed
static uint32_t MakeHash(const char *src, bool makeLower = false);
protected:
// An entry in the language
class LangEntry
{
@ -147,7 +145,7 @@ class CLangMngr
// Merge definitions into a language
void MergeDefinitions(const char *lang, CQueue <sKeyDef*> &tmpVec);
// strip lowercase; make lower if needed
static size_t strip(char *str, char *newstr, bool makelower = false);
static size_t strip(char *str, char *newstr, bool makelower=false);
typedef CVector<CLang*> LangVec;
typedef CVector<CLang*>::iterator LangVecIter;

View File

@ -35,7 +35,6 @@
// *****************************************************
// class CList
// *****************************************************
// Linked list
template <typename T, typename F = char* >
class CList
@ -66,10 +65,8 @@ private:
~CElement()
{
delete m_pObject;
if (m_pNext)
m_pNext->m_pPrev = m_pPrev;
if (m_pPrev)
m_pPrev->m_pNext = m_pNext;
}
@ -105,16 +102,15 @@ private:
}
};
// CList<T, F> class
// CList<T,F> class
CElement *m_pHead; // head of the linked list
CElement *m_pTail; // tail of the linked list
public:
// iterator class
class iterator
{
friend class CList<T, F>;
CList<T, F> *m_pList; // The list that created this iterator
friend class CList<T,F>;
CList<T,F> *m_pList; // The list that created this iterator
CElement *m_CurPos; // Current position in the list
public:
iterator()
@ -124,7 +120,7 @@ public:
}
// constructor based on list, element
iterator(CList<T, F> *pList, CElement *startPos)
iterator(CList<T,F> *pList, CElement *startPos)
{
m_pList = pList;
m_CurPos = startPos;
@ -151,7 +147,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
@ -166,7 +162,6 @@ public:
{
iterator tmp(*this);
m_CurPos = m_CurPos->next;
return tmp;
}
@ -181,20 +176,18 @@ public:
{
return m_pList->remove(*this);
}
iterator put(T *obj)
{
return m_pList->put(obj, *this);
}
};
CList<T, F>()
CList<T,F>()
{
m_pHead = NULL;
m_pTail = NULL;
}
~CList<T, F>()
~CList<T,F>()
{
clear();
}
@ -205,16 +198,12 @@ public:
iterator remove(iterator &where)
{
iterator tmp(where.GetNext());
if (where.m_CurPos == m_pHead)
m_pHead = where.m_CurPos->GetNext();
if (where.m_CurPos == m_pTail)
m_pTail = where.m_CurPos->GetPrev();
delete where.m_CurPos;
where = tmp;
return tmp;
}
@ -223,36 +212,36 @@ public:
iterator put_back(T *pObj)
{
CElement *pTmp = new CElement(pObj);
if (!m_pHead)
{
m_pHead = pTmp;
m_pTail = pTmp;
} else {
}
else
{
pTmp->SetNext(NULL);
pTmp->SetPrev(m_pTail);
m_pTail->SetNext(pTmp);
m_pTail = pTmp;
}
return iterator(this, pTmp);
}
iterator put_front(T *pObj)
{
CElement *pTmp = new CElement(pObj);
if (!m_pHead)
{
m_pHead = pTmp;
m_pTail = pTmp;
} else {
}
else
{
pTmp->SetNext(m_pHead);
pTmp->SetPrev(NULL);
m_pHead->SetPrev(pTmp);
m_pHead = pTmp;
}
return iterator(this, pTmp);
}
@ -268,7 +257,6 @@ public:
iterator put(T *pObj, iterator &where)
{
CElement *pTmp = new CElement(pObj);
if (where.m_CurPos->GetNext())
where.m_CurPos->GetNext()->SetPrev(pTmp);
else // where = tail
@ -278,7 +266,6 @@ public:
pTmp->SetNext(where.m_CurPos->GetNext());
where.m_CurPos->SetNext(pTmp);
return ++where;
}
@ -296,13 +283,12 @@ public:
iterator find(iterator startOn, const F &desc)
{
iterator iter = startOn;
while (iter)
while(iter)
{
if (*iter == desc)
break;
++iter;
}
return iter;
}
@ -314,16 +300,14 @@ public:
int size()
{
iterator iter = begin();
int i = 0;
int i=0;
while (iter)
{
++i;
++iter;
}
return i;
}
};
#endif
#endif //CLIST_H

View File

@ -35,192 +35,135 @@
// *****************************************************
// class LogEventsMngr
// *****************************************************
LogEventsMngr::LogEventsMngr()
{
LogEventsMngr::LogEventsMngr() {
logCurrent = logCounter = 0;
logcmplist = 0;
arelogevents = false;
memset(logevents, 0, sizeof(logevents));
memset( logevents, 0, sizeof(logevents) );
}
LogEventsMngr::~LogEventsMngr()
{
LogEventsMngr::~LogEventsMngr() {
clearLogEvents();
}
int LogEventsMngr::CLogCmp::compareCondition(const char* string)
{
if (logid == parent->logCounter)
int LogEventsMngr::CLogCmp::compareCondition(const char* string){
if ( logid == parent->logCounter )
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());
}
LogEventsMngr::CLogCmp* LogEventsMngr::registerCondition(char* filter)
{
LogEventsMngr::CLogCmp* LogEventsMngr::registerCondition(char* filter){
char* temp = filter;
// expand "1=message"
while (isdigit(*filter))
while ( isdigit(*filter) )
++filter;
bool in = (*filter=='&');
*filter++ = 0;
int pos = atoi(temp);
if (pos < 0 || pos >= MAX_LOGARGS)
pos = 0;
if ( pos < 0 || pos >= MAX_LOGARGS) pos = 0;
CLogCmp* c = logcmplist;
while (c)
{
if ((c->pos == pos) && (c->in == in) && !strcmp(c->text.c_str(), filter))
while( c ) {
if ( (c->pos==pos) && (c->in==in) && !strcmp(c->text.c_str(), filter))
return c;
c = c->next;
}
return logcmplist = new CLogCmp(filter, in, pos, logcmplist, this);
return logcmplist = new CLogCmp( filter , in , pos , logcmplist,this );
}
void LogEventsMngr::CLogEvent::registerFilter(char* filter)
{
CLogCmp *cmp = parent->registerCondition(filter);
if (cmp == 0) return;
for (LogCond* c = filters; c; c = c->next)
{
if (c->argnum == cmp->pos)
{
c->list = new LogCondEle(cmp, c->list);
void LogEventsMngr::CLogEvent::registerFilter( char* filter ){
CLogCmp *cmp = parent->registerCondition( filter );
if ( cmp == 0 ) return;
for(LogCond* c = filters; c ; c = c->next){
if ( c->argnum == cmp->pos ){
c->list = new LogCondEle( cmp , c->list );
return;
}
}
LogCondEle* aa = new LogCondEle(cmp, 0);
if (aa == 0)
return;
filters = new LogCond(cmp->pos, aa, filters);
LogCondEle* aa = new LogCondEle( cmp , 0 );
if ( aa == 0 ) return;
filters = new LogCond( cmp->pos , aa , filters );
}
void LogEventsMngr::setLogString(char* frmt, va_list& vaptr)
{
void LogEventsMngr::setLogString( char* frmt, va_list& vaptr ) {
++logCounter;
int len = vsnprintf(logString, 255, frmt, vaptr);
if (len == - 1)
{
int len = vsnprintf (logString, 255 , frmt, vaptr );
if ( len == - 1) {
len = 255;
logString[len] = 0;
}
if (len)
logString[--len] = 0;
if ( len ) logString[--len] = 0;
logArgc = 0;
}
void LogEventsMngr::setLogString(char* frmt, ...)
{
void LogEventsMngr::setLogString( char* frmt, ... ) {
++logCounter;
va_list logArgPtr;
va_start(logArgPtr, frmt);
int len = vsnprintf(logString, 255, frmt, logArgPtr);
if (len == - 1)
{
va_start ( logArgPtr , frmt );
int len = vsnprintf(logString, 255 , frmt, logArgPtr );
if ( len == - 1) {
len = 255;
logString[len] = 0;
}
va_end(logArgPtr);
if (len)
logString[--len] = 0;
va_end ( logArgPtr );
if ( len ) logString[--len] = 0;
logArgc = 0;
}
void LogEventsMngr::parseLogString()
{
void LogEventsMngr::parseLogString( ) {
register const char* b = logString;
register int a;
while (*b && logArgc < MAX_LOGARGS)
{
while( *b && logArgc < MAX_LOGARGS ){
a = 0;
if (*b == '"')
{
if ( *b == '"' ) {
++b;
while (*b && *b != '"' && a < 127)
while ( *b && *b != '"' && a < 127 )
logArgs[logArgc][a++] = *b++;
logArgs[logArgc++][a] = 0;
if (*b) b+=2; // thanks to double terminator
if ( *b) b+=2; // thanks to double terminator
}
else if (*b == '(')
{
else if ( *b == '(' ) {
++b;
while (*b && *b != ')' && a < 127)
while ( *b && *b != ')' && a < 127 )
logArgs[logArgc][a++] = *b++;
logArgs[logArgc++][a] = 0;
if (*b) b+=2;
} else {
while (*b && *b != '(' && *b != '"' && a < 127)
if ( *b) b+=2;
}
else {
while ( *b && *b != '(' && *b != '"' && a < 127 )
logArgs[logArgc][a++] = *b++;
if (*b) --a;
if ( *b ) --a;
logArgs[logArgc++][a] = 0;
}
}
}
LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos)
LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent( CPluginMngr::CPlugin* plugin, int func, int pos )
{
if (pos < 1 || pos > MAX_LOGARGS)
if ( pos < 1 || pos > MAX_LOGARGS)
return 0;
arelogevents = true;
CLogEvent** d = &logevents[pos];
while (*d)
d = &(*d)->next;
return *d = new CLogEvent(plugin, func, this);
while(*d) d = &(*d)->next;
return *d = new CLogEvent( plugin , func, this );
}
void LogEventsMngr::executeLogEvents()
{
bool valid;
for (CLogEvent* a = logevents[logArgc]; a; a = a->next)
for(CLogEvent* a = logevents[ logArgc ]; a ; a = a->next)
{
valid = true;
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
for( CLogEvent::LogCond* b = a->filters; b ; b = b->next)
{
valid = false;
for (CLogEvent::LogCondEle* c = b->list; c; c = c->next)
{
if (c->cmp->compareCondition(logArgs[b->argnum]) == 0)
{
for( CLogEvent::LogCondEle* c = b->list; c ; c = c->next) {
if ( c->cmp->compareCondition( logArgs[b->argnum] ) == 0 ){
valid = true;
break;
}
}
if (!valid)
break;
}
@ -232,87 +175,64 @@ void LogEventsMngr::executeLogEvents()
}
}
void LogEventsMngr::clearLogEvents()
{
void LogEventsMngr::clearLogEvents(){
logCurrent = logCounter = 0;
arelogevents = false;
for (int i = 0; i < MAX_LOGARGS + 1; ++i)
{
for(int i = 0; i < MAX_LOGARGS + 1; ++i){
CLogEvent **a = &logevents[i];
while (*a)
{
while(*a){
CLogEvent* bb = (*a)->next;
delete *a;
*a = bb;
}
}
clearConditions();
}
void LogEventsMngr::clearConditions()
{
while (logcmplist)
{
void LogEventsMngr::clearConditions() {
while (logcmplist){
CLogCmp* a = logcmplist->next;
delete logcmplist;
logcmplist = a;
}
}
LogEventsMngr::CLogEvent::LogCond::~LogCond()
{
while (list)
{
LogEventsMngr::CLogEvent::LogCond::~LogCond() {
while( list ) {
LogCondEle* cc = list->next;
delete list;
list = cc;
}
}
LogEventsMngr::CLogEvent::~CLogEvent()
{
while (filters)
{
LogEventsMngr::CLogEvent::~CLogEvent() {
while( filters ) {
LogCond* cc = filters->next;
delete filters;
filters = cc;
}
}
LogEventsMngr::CLogEvent *LogEventsMngr::getValidLogEvent(CLogEvent * a)
LogEventsMngr::CLogEvent *LogEventsMngr::getValidLogEvent( CLogEvent * a )
{
bool valid;
while (a)
{
while(a){
valid = true;
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
{
for( CLogEvent::LogCond* b = a->filters; b ; b = b->next){
valid = false;
for (CLogEvent::LogCondEle* c = b->list; c; c = c->next)
{
if (c->cmp->compareCondition(logArgs[b->argnum]) == 0)
{
for( CLogEvent::LogCondEle* c = b->list; c ; c = c->next) {
if ( c->cmp->compareCondition( logArgs[b->argnum] ) == 0 ){
valid = true;
break;
}
}
if (!valid) break;
}
if (!valid)
{
if (!valid){
a = a->next;
continue;
}
return a;
}
return 0;
}

View File

@ -40,8 +40,8 @@
// class LogEventsMngr
// *****************************************************
class LogEventsMngr
{
class LogEventsMngr {
char logString[256];
char logArgs[MAX_LOGARGS][128];
int logArgc;
@ -53,6 +53,7 @@ public:
class CLogCmp;
class iterator;
class CLogEvent;
friend class CLogEvent;
friend class CLogCmp;
friend class iterator;
@ -61,118 +62,104 @@ 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)
{
CLogCmp( const char* s, bool r, int p, CLogCmp *n, LogEventsMngr* mg ) : text(s) {
logid = result = 0;
pos = p;
parent = mg;
in = r;
next = n;
}
public:
int compareCondition(const char* string);
};
private:
CLogCmp *logcmplist;
public:
class CLogEvent
{
class CLogEvent {
friend class LogEventsMngr;
friend class iterator;
struct LogCondEle
{
struct LogCondEle {
CLogCmp *cmp;
LogCondEle *next;
LogCondEle(CLogCmp *c, LogCondEle *n): cmp(c), next(n) {}
LogCondEle(CLogCmp *c, LogCondEle *n): cmp(c) , next(n) { }
};
struct LogCond
{
struct LogCond {
int argnum;
LogCondEle *list;
LogCond *next;
LogCond(int a, LogCondEle* ee, LogCond* n) : argnum(a), list(ee), next(n) {}
LogCond( int a , LogCondEle* ee , LogCond* n ) : argnum(a) , list(ee), next(n) {}
~LogCond();
};
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; }
void registerFilter(char* filter);
void registerFilter( char* filter );
inline int getFunction() { return func; }
};
private:
CLogEvent *logevents[MAX_LOGARGS + 1];
CLogEvent *getValidLogEvent(CLogEvent * a);
CLogCmp* registerCondition(char* filter);
CLogEvent *logevents[MAX_LOGARGS+1];
CLogEvent *getValidLogEvent( CLogEvent * a );
CLogCmp* registerCondition(char* filter);
void clearConditions();
public:
LogEventsMngr();
~LogEventsMngr();
// Interface
CLogEvent* registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos);
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 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]; }
inline const char* getLogArg( int i ) { return ( i < 0 || i >= logArgc ) ? "" : logArgs[ i ]; }
void clearLogEvents();
class iterator
{
class iterator {
CLogEvent* a;
LogEventsMngr* b;
public:
inline iterator(CLogEvent*aa, LogEventsMngr* bb) : a(aa), b(bb) {}
inline iterator& operator++()
{
a = b->getValidLogEvent(a->next);
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; }
operator bool ( ) const { return a ? true : false; }
};
inline iterator begin() { return iterator(getValidLogEvent(logevents[logArgc]), this); }
inline iterator end() { return iterator(0, this); }
inline iterator begin() { return iterator(getValidLogEvent(logevents[ logArgc ]),this); }
inline iterator end() { return iterator(0,this); }
};
#endif //LOGEVENTS_H
#endif

View File

@ -35,8 +35,7 @@
// *****************************************************
// class MenuMngr
// *****************************************************
MenuMngr::MenuCommand::MenuCommand(CPluginMngr::CPlugin *a, int mi, int k, int f)
{
MenuMngr::MenuCommand::MenuCommand( CPluginMngr::CPlugin *a, int mi, int k, int f ) {
plugin = a;
keys = k;
menuid = mi;
@ -51,35 +50,28 @@ MenuMngr::~MenuMngr()
int MenuMngr::findMenuId(const char* name, AMX* amx)
{
for (MenuIdEle* b = headid; b; b = b->next)
{
if ((!amx || !b->amx || amx == b->amx) && strstr(name,b->name.c_str()))
for( MenuIdEle* b = headid; b ; b = b->next) {
if ( (!amx || !b->amx || amx == b->amx) && strstr(name,b->name.c_str()) )
return b->id;
}
return 0;
}
int MenuMngr::registerMenuId(const char* n, AMX* a)
int MenuMngr::registerMenuId(const char* n, AMX* a )
{
int id = findMenuId(n, a);
if (id)
return id;
headid = new MenuIdEle(n, a, headid);
int id = findMenuId( n, a );
if (id) return id;
headid = new MenuIdEle( n, a , headid );
if (!headid)
return 0; // :TODO: Better error report
return headid->id;
}
void MenuMngr::registerMenuCmd(CPluginMngr::CPlugin *a, int mi, int k, int f)
void MenuMngr::registerMenuCmd( CPluginMngr::CPlugin *a,int mi, int k , int f )
{
MenuCommand** temp = &headcmd;
while (*temp) temp = &(*temp)->next;
*temp = new MenuCommand(a, mi, k, f);
while(*temp) temp = &(*temp)->next;
*temp = new MenuCommand(a,mi, k,f);
}
void MenuMngr::clear()

View File

@ -43,20 +43,17 @@ class MenuMngr
String name;
AMX* amx;
MenuIdEle* next;
int id;
static int uniqueid;
MenuIdEle(const char* n, AMX* a, MenuIdEle* m) : name(n), amx(a), next(m)
{
MenuIdEle( const char* n, AMX* a, MenuIdEle* m ) : name( n ) , amx(a) , next( m ) {
id = ++uniqueid;
}
~MenuIdEle() { --uniqueid; }
} *headid;
public:
class iterator;
private:
class MenuCommand
@ -68,28 +65,28 @@ private:
int menuid;
int keys;
int function;
MenuCommand* next;
MenuCommand(CPluginMngr::CPlugin *a, int mi, int k, int f);
MenuCommand( CPluginMngr::CPlugin *a, int mi, int k, int f );
public:
inline int getFunction() { return function; }
inline CPluginMngr::CPlugin* getPlugin() { return plugin; }
inline bool matchCommand(int m, int k) { return ((m == menuid) && (keys & k)); }
inline bool matchCommand( int m, int k ) { return ((m == menuid) && (keys & k)); }
} *headcmd;
public:
MenuMngr() { headid = 0; headcmd = 0; }
~MenuMngr();
// Interface
int findMenuId(const char* name, AMX* a = 0);
int registerMenuId(const char* n, AMX* a);
int registerMenuId(const char* n, AMX* a );
void registerMenuCmd(CPluginMngr::CPlugin *a, int mi, int k, int f);
void clear();
class iterator
{
class iterator {
MenuCommand* a;
public:
iterator(MenuCommand*aa) : a(aa) {}
@ -99,9 +96,8 @@ public:
operator bool () const { return a ? true : false; }
MenuCommand& operator*() { return *a; }
};
inline iterator begin() const { return iterator(headcmd); }
inline iterator end() const { return iterator(0); }
};
#endif //MENUS_H
#endif

View File

@ -33,7 +33,7 @@
// class CPlayer
// *****************************************************
void CPlayer::Init(edict_t* e, int i)
void CPlayer::Init( edict_t* e , int i )
{
index = i;
pEdict = e;
@ -55,63 +55,46 @@ void CPlayer::Init(edict_t* e, int i)
team.clear();
}
void CPlayer::Disconnect()
{
void CPlayer::Disconnect() {
ingame = false;
initialized = false;
authorized = false;
while (!cvarQueryQueue.empty())
{
ClientCvarQuery_Info *pQuery = cvarQueryQueue.front();
unregisterSPForward(pQuery->resultFwd);
if (pQuery->params)
delete [] pQuery->params;
delete pQuery;
cvarQueryQueue.pop();
}
bot = 0;
}
void CPlayer::PutInServer()
{
void CPlayer::PutInServer() {
playtime = gpGlobals->time;
ingame = true;
}
bool CPlayer::Connect(const char* connectname, const char* ipaddress)
{
bool CPlayer::Connect(const char* connectname,const char* ipaddress) {
name.assign(connectname);
ip.assign(ipaddress);
time = gpGlobals->time;
bot = IsBot();
death_killer = 0;
memset(flags, 0, sizeof(flags));
memset(weapons, 0, sizeof(weapons));
memset(flags,0,sizeof(flags));
memset(weapons,0,sizeof(weapons));
initialized = true;
authorized = false;
const char* authid = GETPLAYERAUTHID(pEdict);
const char* authid = GETPLAYERAUTHID( pEdict );
if ((authid == 0) || (*authid == 0) || (strcmp(authid, "STEAM_ID_PENDING") == 0))
if ( (authid == 0) || (*authid == 0)
|| (strcmp( authid , "STEAM_ID_PENDING") == 0) )
return true;
return false;
}
// *****************************************************
// class Grenades
// *****************************************************
void Grenades::put(edict_t* grenade, float time, int type, CPlayer* player)
void Grenades::put( edict_t* grenade, float time, int type, CPlayer* player )
{
Obj* a = new Obj;
if (a == 0) return;
if ( a == 0 ) return;
a->player = player;
a->grenade = grenade;
a->time = gpGlobals->time + time;
@ -120,37 +103,34 @@ void Grenades::put(edict_t* grenade, float time, int type, CPlayer* player)
head = a;
}
bool Grenades::find(edict_t* enemy, CPlayer** p, int& type)
bool Grenades::find( edict_t* enemy, CPlayer** p, int& type )
{
bool found = false;
Obj** a = &head;
while (*a)
{
if ((*a)->time > gpGlobals->time)
{
if ((*a)->grenade == enemy)
{
while ( *a ){
if ( (*a)->time > gpGlobals->time ) {
if ( (*a)->grenade == enemy ) {
found = true;
(*p) = (*a)->player;
type = (*a)->type;
}
} else {
}
else {
Obj* b = (*a)->next;
delete *a;
*a = b;
continue;
}
a = &(*a)->next;
}
return found;
}
void Grenades::clear()
{
while (head)
{
while(head){
Obj* a = head->next;
delete head;
head = a;
@ -160,119 +140,93 @@ void Grenades::clear()
// *****************************************************
// class XVars
// *****************************************************
void XVars::clear()
{
void XVars::clear() {
delete[] head;
head = 0;
num = 0;
size = 0;
}
int XVars::put(AMX* p, cell* v)
int XVars::put( AMX* p, cell* v )
{
for (int a = 0; a < num; ++a)
{
if ((head[a].amx == p) && (head[a].value == v))
for(int a = 0; a < num; ++a) {
if ( (head[a].amx == p) && (head[a].value == v) )
return a;
}
if ((num >= size) && realloc_array(size ? (size * 2) : 8))
if ( (num >= size) && realloc_array( size ? (size * 2) : 8 ) )
return -1;
head[num].value = v;
head[num].amx = p;
return num++;
}
int XVars::realloc_array(int nsize)
int XVars::realloc_array( int nsize )
{
XVarEle* me = new XVarEle[nsize];
if (me)
{
for (int a = 0 ; a < num; ++a)
if ( me ){
for(int a = 0 ; a < num; ++a)
me[a] = head[a];
delete[] head;
head = me;
size = nsize;
return 0;
}
return 1;
}
// *****************************************************
// class TeamIds
// *****************************************************
TeamIds::TeamIds() { head = 0; newTeam = 0; }
TeamIds::~TeamIds()
{
while (head)
{
TeamIds::~TeamIds() {
while( head ) {
TeamEle* a = head->next;
delete head;
head = a;
}
}
void TeamIds::registerTeam(const char* n, int s)
void TeamIds::registerTeam( const char* n ,int s )
{
TeamEle** a = &head;
while (*a)
{
if (strcmp((*a)->name.c_str(),n) == 0)
{
if (s != -1)
{
while( *a ){
if ( strcmp((*a)->name.c_str(),n) == 0 ){
if (s != -1){
(*a)->id = s;
newTeam &= ~(1<<(*a)->tid);
}
return;
}
a = &(*a)->next;
}
*a = new TeamEle(n, s);
if (*a == 0)
return;
*a = new TeamEle( n , s );
if ( *a == 0 ) return;
newTeam |= (1<<(*a)->tid);
}
int TeamIds::findTeamId(const char* n)
int TeamIds::findTeamId( const char* n )
{
TeamEle* a = head;
while (a)
{
if (!stricmp(a->name.c_str(), n))
while( a ){
if ( !stricmp(a->name.c_str(),n) )
return a->id;
a = a->next;
}
return -1;
}
int TeamIds::findTeamIdCase(const char* n)
int TeamIds::findTeamIdCase( const char* n)
{
TeamEle* a = head;
while (a)
{
if (!strcmp(a->name.c_str(), n))
while( a ){
if ( !strcmp(a->name.c_str(), n) )
return a->id;
a = a->next;
}
return -1;
}
char TeamIds::TeamEle::uid = 0;

View File

@ -37,44 +37,34 @@
// *****************************************************
// class CCVar
// *****************************************************
class CCVar
{
cvar_t cvar;
String name;
String plugin;
public:
CCVar(const char* pname, const char* pplugin, int pflags, float pvalue) : name(pname), plugin(pplugin)
{
CCVar( const char* pname, const char* pplugin,
int pflags, float pvalue ) : name(pname) , plugin(pplugin ) {
cvar.name = (char*)name.c_str();
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); }
};
// *****************************************************
// class CPlayer
// *****************************************************
struct ClientCvarQuery_Info
{
bool querying; // Are we actually waiting for a response at the moment?
String cvarName;
int resultFwd;
int paramLen;
cell *params;
};
class CPlayer
{
public:
edict_t* pEdict;
@ -90,8 +80,7 @@ public:
float time;
float playtime;
struct
{
struct {
int ammo;
int clip;
} weapons[MAX_WEAPONS];
@ -117,22 +106,17 @@ public:
Vector thisTrace;
Vector lastHit;
CQueue<ClientCvarQuery_Info*> cvarQueryQueue;
void Init(edict_t* e, int i);
void Init( edict_t* e , int i );
void Disconnect();
void PutInServer();
bool Connect(const char* connectname,const char* ipaddress);
bool Connect(const char* connectname, const char* ipaddress);
inline bool IsBot()
{
return ((pEdict->v.flags & FL_FAKECLIENT) ? true : false);
inline bool IsBot(){
return ((pEdict->v.flags & FL_FAKECLIENT)?true:false);
}
inline bool IsAlive()
{
return ((pEdict->v.deadflag == DEAD_NO) && (pEdict->v.health > 0));
inline bool IsAlive(){
return ((pEdict->v.deadflag==DEAD_NO)&&(pEdict->v.health>0));
}
inline void Authorize() { authorized = true; }
@ -154,35 +138,31 @@ class Grenades
Obj* next;
} *head;
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 put( edict_t* grenade, float time, int type, CPlayer* player );
bool find( edict_t* enemy, CPlayer** p, int& type );
void clear();
};
// *****************************************************
// class ForceObject
// *****************************************************
class ForceObject
{
class ForceObject {
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; }
};
@ -192,38 +172,30 @@ public:
class XVars
{
struct XVarEle
{
struct XVarEle {
AMX* amx;
cell* value;
};
XVarEle* head;
int size;
int num;
int realloc_array(int nsize);
int realloc_array( int nsize );
public:
XVars() { num = 0; size = 0; head = 0; }
~XVars() { clear(); }
void clear();
int put(AMX* a, cell* v);
inline cell getValue(int a)
{
return (a >= 0 && a < num) ? *(head[a].value) : 0;
int put( AMX* a, cell* v );
inline cell getValue( int a ) {
return ( a >= 0 && a < num ) ? *(head[a].value) : 0;
}
inline int setValue(int a, cell v)
{
if (a >= 0 && a < num)
{
inline int setValue( int a, cell v ) {
if ( a >= 0 && a < num ){
*(head[a].value) = v;
return 0;
}
return 1;
}
};
@ -231,41 +203,34 @@ public:
// *****************************************************
// class CScript
// *****************************************************
class CScript
{
String filename;
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(); }
inline bool operator==(void* a) { return (amx == (AMX*)a); }
inline bool operator==( void* a ) { return (amx == (AMX*)a); }
inline void* getCode() { return code; }
};
// *****************************************************
// class TeamIds
// *****************************************************
class TeamIds
{
struct TeamEle
{
struct TeamEle {
String name;
int id;
char tid;
static char uid;
TeamEle* next;
TeamEle(const char* n, int& i) : name(n), id(i), next(0)
{
TeamEle(const char* n, int& i) : name(n) , id(i) , next(0) {
tid = uid++;
}
~TeamEle() { --uid; }
};
~TeamEle(){ --uid; }
} *head;
int newTeam;
@ -273,11 +238,15 @@ class TeamIds
public:
TeamIds();
~TeamIds();
void registerTeam(const char* n, int s);
int findTeamId(const char* n);
int findTeamIdCase(const char* n);
void registerTeam( const char* n ,int s );
int findTeamId( const char* n);
int findTeamIdCase( const char* n);
inline bool isNewTeam() { return newTeam ? true : false; }
};
#endif //CMISC_H
#endif

View File

@ -32,7 +32,7 @@
#include "amxmodx.h"
#ifndef FAR
#define FAR
#define FAR
#endif
// New
@ -55,7 +55,7 @@ CModule::CModule(const char* fname)
CModule::~CModule()
{
// old & new
if (m_Handle)
if ( m_Handle )
DLFREE(m_Handle);
clear();
@ -67,7 +67,6 @@ void CModule::clear(bool clearFilename)
m_Metamod = false;
m_Handle = NULL;
m_Status = MODULE_NONE;
if (clearFilename)
m_Filename.assign("unknown");
@ -115,7 +114,6 @@ bool CModule::attachModule()
if (!AttachFunc_New)
return false;
g_ModuleCallReason = ModuleCall_Attach;
g_CurrentlyCalledModule = this;
int retVal = (*AttachFunc_New)(Module_ReqFnptr);
@ -165,7 +163,6 @@ bool CModule::queryModule()
// Try new interface first
QUERYMOD_NEW queryFunc_New = (QUERYMOD_NEW)DLPROC(m_Handle, "AMXX_Query");
if (queryFunc_New)
{
m_Amxx = true;
@ -175,7 +172,6 @@ bool CModule::queryModule()
int retVal = (*queryFunc_New)(&ifVers, &m_InfoNew);
g_CurrentlyCalledModule = NULL;
g_ModuleCallReason = ModuleCall_NotCalled;
switch (retVal)
{
case AMXX_PARAM:
@ -205,7 +201,9 @@ bool CModule::queryModule()
m_Status = MODULE_QUERY;
return true;
} else {
}
else
{
m_Status = MODULE_NOQUERY;
m_Amxx = false;
return false;
@ -220,7 +218,6 @@ bool CModule::detachModule()
if (m_Amxx)
{
DETACHMOD_NEW detachFunc_New = (DETACHMOD_NEW)DLPROC(m_Handle, "AMXX_Detach");
if (detachFunc_New)
{
g_ModuleCallReason = ModuleCall_Detach;
@ -230,17 +227,14 @@ bool CModule::detachModule()
g_ModuleCallReason = ModuleCall_NotCalled;
}
}
#ifndef FAKEMETA
if (IsMetamod())
{
UnloadMetamodPlugin(m_Handle);
}
#endif
DLFREE(m_Handle);
clear();
return true;
}
@ -253,16 +247,14 @@ void CModule::CallPluginsLoaded()
return;
PLUGINSLOADED_NEW func = (PLUGINSLOADED_NEW)DLPROC(m_Handle, "AMXX_PluginsLoaded");
if (!func)
return;
func();
}
const char* CModule::getStatus() const
{
switch (m_Status)
switch(m_Status)
{
case MODULE_NONE: return "error";
case MODULE_QUERY: return "pending";
@ -278,6 +270,5 @@ const char* CModule::getStatus() const
case MODULE_NOT64BIT: return "not 64bit";
default: break;
}
return "unknown";
}

View File

@ -36,8 +36,7 @@
#ifndef CMODULE_H
#define CMODULE_H
enum MODULE_STATUS
{
enum MODULE_STATUS {
MODULE_NONE, // No module loaded
MODULE_QUERY, // Query failed
MODULE_BADLOAD, // Bad file or the module writer messed something up ;]
@ -61,6 +60,7 @@ struct amxx_module_info_s
const char *logtag; //added in version 2
};
#define AMXX_OK 0 /* no error */
#define AMXX_IFVERS 1 /* interface version */
#define AMXX_PARAM 2 /* Invalid parameter */
@ -71,10 +71,8 @@ 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
@ -86,15 +84,12 @@ public:
~CModule();
// Interface
bool attachModule();
bool queryModule();
bool detachModule();
#ifndef FAKEMETA
bool attachMetamod(const char *mmfile, PLUG_LOADTIME now);
#endif
const char* getStatus() const;
inline const char* getType() const { return m_Amxx ? "amxx" : (m_Metamod ? "amx&mm" : "amx"); }
inline const char* getAuthor() const { return m_InfoNew.author; }
@ -102,16 +97,18 @@ public:
inline const char* getName() const { return m_InfoNew.name; }
inline const amxx_module_info_s* getInfoNew() const { return &m_InfoNew; } // new
inline int getStatusValue() { return m_Status; }
inline bool operator==(const char* fname) { return !strcmp(m_Filename.c_str(), fname); }
inline bool operator==( const char* fname ) { return !strcmp( m_Filename.c_str() , fname ); }
inline bool isReloadable() { return ((m_Status == MODULE_LOADED) && (m_InfoNew.reload != 0)); }
inline bool isAmxx() const { return m_Amxx; }
inline const char *getMissingFunc() const { return m_MissingFunc; }
inline const char *getFilename() { return m_Filename.c_str(); }
inline bool IsMetamod() { return m_Metamod; }
void CModule::CallPluginsLoaded();
CList<AMX_NATIVE_INFO*> m_Natives;
};
#endif //CMODULE_H
#endif

View File

@ -35,24 +35,17 @@
#include "CFile.h"
#include "amx.h"
#include "natives.h"
#include "debugger.h"
extern const char *no_function;
CPluginMngr::CPlugin* CPluginMngr::loadPlugin(const char* path, const char* name, char* error, int debug)
{
CPluginMngr::CPlugin* CPluginMngr::loadPlugin(const char* path, const char* name, char* error, int debug) {
CPlugin** a = &head;
while (*a)
a = &(*a)->next;
*a = new CPlugin(pCounter++, path, name, error, debug);
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;
@ -63,10 +56,9 @@ void CPluginMngr::Finalize()
{
if (m_Finalized)
return;
pNatives = BuildNativeTable();
CPlugin *a = head;
CPlugin *a = head;
while (a)
{
if (a->getStatusCode() == ps_running)
@ -74,20 +66,19 @@ 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;
}
@ -98,26 +89,22 @@ 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)
{
@ -133,15 +120,11 @@ 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;
@ -151,51 +134,35 @@ void CPluginMngr::clear()
CPluginMngr::CPlugin* CPluginMngr::findPluginFast(AMX *amx)
{
return (CPlugin*)(amx->userdata[UD_FINDPLUGIN]);
return (CPlugin*)(amx->userdata[3]);
}
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)
{
const char* CPluginMngr::CPlugin::getStatus() const {
switch(status){
case ps_running:
{
if (m_Debug)
@ -211,41 +178,33 @@ const char* CPluginMngr::CPlugin::getStatus() const
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;
amx.userdata[3] = 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;
@ -255,108 +214,51 @@ CPluginMngr::CPlugin::CPlugin(int i, const char* p, const char* n, char* e, int
}
}
CPluginMngr::CPlugin::~CPlugin()
CPluginMngr::CPlugin::~CPlugin( )
{
unload_amxscript(&amx, &code);
}
int AMXAPI native_handler(AMX *amx, int index)
{
Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];
char name[sNAMEMAX + 1];
amx_GetNative(amx, index, name);
return pHandler->HandleNative(name, index, 0);
}
static cell AMX_NATIVE_CALL invalid_native(AMX *amx, cell *params)
{
//A script has accidentally called an invalid native! give them a
// first chance to block the resulting error.
Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];
//this should never happen
if (!pHandler)
{
LogError(amx, AMX_ERR_INVNATIVE, "Invalid native attempt");
return 0;
}
//this should never happen because this native won't be called
// if the plugin isn't filtering.
if (!pHandler->IsNativeFiltering())
{
LogError(amx, AMX_ERR_INVNATIVE, "Invalid native attempt");
return 0;
}
char name[sNAMEMAX + 1];
int native = amx->usertags[UT_NATIVE];
int err = amx_GetNative(amx, native, name);
if (err != AMX_ERR_NONE)
name[0] = '\0';
//1 - because we're trapping usage
if (!pHandler->HandleNative(name, native, 1))
{
LogError(amx, AMX_ERR_INVNATIVE, NULL);
return 0;
}
//Someday maybe allow native filters to write their own return value?
return 0;
unload_amxscript( &amx, &code );
}
void CPluginMngr::CPlugin::Finalize()
{
char buffer[128];
int old_status = status;
int old_status = status;
if (CheckModules(&amx, buffer))
{
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)
if ( amx_Register(&amx, core_Natives, -1) != AMX_ERR_NONE )
{
status = ps_bad_load;
sprintf(buffer, "Plugin uses an unknown function (name \"%s\") - check your modules.ini.", no_function);
errorMsg.assign(buffer);
amx.error = AMX_ERR_NOTFOUND;
} else {
amx_RegisterToAny(&amx, invalid_native);
}
}
} else {
status = ps_bad_load;
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 ) {
if (isValid()){
paused_fun |= (1<<id);
g_commands.clearBufforedInfo();
}
}
void CPluginMngr::CPlugin::unpauseFunction(int id)
{
void CPluginMngr::CPlugin::unpauseFunction( int id ) {
if (isValid()) {
paused_fun &= ~(1<<id);
g_commands.clearBufforedInfo();
}
}
void CPluginMngr::CPlugin::setStatus(int a)
{
void CPluginMngr::CPlugin::setStatus( int a ) {
status = a;
g_commands.clearBufforedInfo(); // ugly way
}
@ -380,8 +282,8 @@ void CPluginMngr::CPlugin::unpausePlugin()
if (isValid())
{
// set status first so the function will be marked executable
setStatus(ps_running);
setStatus(ps_running);
// call plugin_unpause if provided
if (m_UnpauseFwd != -1)
executeForwards(m_UnpauseFwd);

View File

@ -36,18 +36,18 @@
// class CPluginMngr
// *****************************************************
enum
{
enum {
ps_bad_load,
ps_error,
ps_locked,
ps_paused,
ps_stopped,
ps_running,
ps_stopped,
ps_locked,
};
class CPluginMngr
{
public:
class iterator;
@ -59,25 +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();
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();}
inline const char* getVersion() { return version.c_str();}
inline const char* getTitle() { return title.c_str();}
@ -87,21 +85,20 @@ public:
inline int getId() const { return id; }
inline AMX* getAMX() { return &amx; }
inline const AMX* getAMX() const { return &amx; }
inline void setTitle(const char* n) { title.assign(n); }
inline void setAuthor(const char* n) { author.assign(n); }
inline void setVersion(const char* n) { version.assign(n); }
inline void setError(const char* n) { errorMsg.assign(n); }
inline bool isValid() const { return (status >= ps_paused); }
inline bool isPaused() const { return ((status == ps_paused) || (status == ps_stopped)); }
inline void setTitle( const char* n ) { title.assign(n); }
inline void setAuthor( const char* n ) { author.assign(n); }
inline void setVersion( const char* n ) { version.assign(n); }
inline void setError( const char* n ) { errorMsg.assign(n); }
inline bool isValid() const { return ((status == ps_running) && (status != ps_locked)); }
inline bool isPaused() const { return ( (status == ps_paused) ); }
//inline bool isFunctionPaused( int id ) const { return (paused_fun & (1<<id)) ? true : false; }
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);
void pauseFunction( int id );
void unpauseFunction( int id );
void setStatus( int a );
const char* getStatus() const;
inline bool isDebug() const { return m_Debug; }
};
@ -109,6 +106,8 @@ public:
private:
CPlugin *head;
int pCounter;
public:
CPluginMngr() { head = 0; pCounter = 0; pNatives = NULL; m_Finalized=false;}
~CPluginMngr() { clear(); }
@ -119,20 +118,17 @@ public:
// Interface
CPlugin* loadPlugin(const char* path, const char* name, char* error, int debug);
void unloadPlugin(CPlugin** a);
int loadPluginsFromFile(const char* filename);
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();
class iterator
{
class iterator {
CPlugin *a;
public:
iterator(CPlugin*aa) : a(aa) {}
@ -142,9 +138,10 @@ public:
operator bool () const { return a ? true : false; }
CPlugin& operator*() { return *a; }
};
inline iterator begin() const { return iterator(head); }
inline iterator end() const { return iterator(0); }
};
#endif //PLUGIN_H
#endif

View File

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

View File

@ -43,32 +43,27 @@ public:
T item;
CStackItem *prev;
};
public:
CStack()
{
mSize = 0;
mStack = NULL;
}
~CStack()
{
CStackItem *p, *t;
p = mStack;
while (p)
{
t = p->prev;
delete p;
p = t;
}
mStack = NULL;
}
bool empty()
{
return (mSize == 0);
return (mSize==0);
}
void push(const T & v)
@ -103,3 +98,4 @@ private:
};
#endif //_INCLUDE_CQUEUE_H

View File

@ -33,7 +33,6 @@
#include "CTask.h"
/*********************** CTask ***********************/
int CTaskMngr::CTask::getTaskId() const
{
return m_iId;
@ -54,17 +53,8 @@ void CTaskMngr::CTask::set(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlags,
m_iId = iId;
m_fBase = fBase;
if (iFlags & 2)
{
m_bLoop = true;
m_iRepeat = -1;
}
else if (iFlags & 1)
{
m_bLoop = true;
m_iRepeat = iRepeat;
}
m_iRepeat = (iFlags & 1) ? iRepeat : 0;
m_bLoop = (iFlags & 2) ? true : false;
m_bAfterStart = (iFlags & 4) ? true : false;
m_bBeforeEnd = (iFlags & 8) ? true : false;
@ -127,9 +117,7 @@ void CTaskMngr::CTask::resetNextExecTime(float fCurrentTime)
void CTaskMngr::CTask::executeIfRequired(float fCurrentTime, float fTimeLimit, float fTimeLeft)
{
bool execute = false;
bool done = false;
bool execute=false;
if (m_bAfterStart)
{
if (fCurrentTime - fTimeLeft + 1.0f >= m_fBase)
@ -141,14 +129,9 @@ void CTaskMngr::CTask::executeIfRequired(float fCurrentTime, float fTimeLimit, f
execute = true;
}
else if (m_fNextExecTime <= fCurrentTime)
{
execute = true;
}
if (execute)
{
//only bother calling if we have something to call
if (!(m_bLoop && !m_iRepeat))
{
if (m_iParamLen) // call with parameters
{
@ -157,26 +140,19 @@ void CTaskMngr::CTask::executeIfRequired(float fCurrentTime, float fTimeLimit, f
} else {
executeForwards(m_iFunc, m_iId);
}
}
if (isFree())
return;
// set new exec time OR remove the task if needed
if (m_bLoop)
if (m_bLoop || (m_iRepeat-- > 0))
{
if (m_iRepeat != -1 && --m_iRepeat <= 0)
done = true;
} else {
done = true;
}
if (done)
{
clear();
} else {
m_fNextExecTime += m_fBase;
}
else
{
clear(); // hamster
}
}
}
@ -206,7 +182,6 @@ CTaskMngr::CTask::~CTask()
}
/*********************** CTaskMngr ***********************/
CTaskMngr::CTaskMngr()
{
m_pTmr_CurrentTime = NULL;
@ -230,18 +205,17 @@ void CTaskMngr::registerTask(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlag
{
// first, search for free tasks
TaskListIter iter = m_Tasks.find(CTaskDescriptor(0, NULL, true));
if (iter)
{
// found: reuse it
iter->set(pPlugin, iFunc, iFlags, iId, fBase, iParamsLen, pParams, iRepeat, *m_pTmr_CurrentTime);
} else {
}
else
{
// not found: make a new one
CTask *pTmp = new CTask;
if (!pTmp)
return;
pTmp->set(pPlugin, iFunc, iFlags, iId, fBase, iParamsLen, pParams, iRepeat, *m_pTmr_CurrentTime);
m_Tasks.put(pTmp);
}
@ -251,15 +225,13 @@ int CTaskMngr::removeTasks(int iId, AMX *pAmx)
{
CTaskDescriptor descriptor(iId, pAmx);
TaskListIter iter = m_Tasks.find(descriptor);
int i = 0;
int i=0;
while (iter)
{
iter->clear();
++i;
iter = m_Tasks.find(++iter, descriptor);
}
return i;
}
@ -267,8 +239,7 @@ int CTaskMngr::changeTasks(int iId, AMX *pAmx, float fNewBase)
{
CTaskDescriptor descriptor(iId, pAmx);
TaskListIter iter = m_Tasks.find(descriptor);
int i = 0;
int i=0;
while (iter)
{
iter->changeBase(fNewBase);
@ -276,7 +247,6 @@ int CTaskMngr::changeTasks(int iId, AMX *pAmx, float fNewBase)
++i;
iter = m_Tasks.find(++iter, descriptor);
}
return i;
}

View File

@ -39,18 +39,15 @@ 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;
@ -94,16 +91,16 @@ private:
if (right.m_bFree)
return left.isFree();
return !left.isFree() && (right.m_pAmx ? left.getPlugin()->getAMX() == right.m_pAmx : true) && left.getTaskId() == right.m_iId;
return !left.isFree() &&
(right.m_pAmx ? left.getPlugin()->getAMX() == right.m_pAmx : true) &&
left.getTaskId() == right.m_iId;
}
};
/*** CTaskMngr priv members ***/
typedef CList<CTask, CTaskDescriptor> TaskList;
typedef TaskList::iterator TaskListIter;
TaskList m_Tasks;
float *m_pTmr_CurrentTime;
float *m_pTmr_TimeLimit;
float *m_pTmr_TimeLeft;
@ -113,13 +110,13 @@ 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();
};
#endif //CTASK_H
#endif

View File

@ -39,47 +39,46 @@
// *****************************************************
// class Vault
// *****************************************************
bool Vault::exists(const char* k)
bool Vault::exists( const char* k )
{
if (*k == 0) return false;
if ( *k == 0 ) return false;
return *find(k) != 0;
return *find( k ) != 0;
}
void Vault::put(const char* k, const char* v)
void Vault::put( const char* k, const char* v )
{
if (*k == 0) return;
if ( *k == 0 ) return;
if (*v == 0)
if ( *v == 0 )
{
remove(k);
remove( k );
return;
}
Obj** a = find(k);
Obj** a = find( k );
if (*a)
if ( *a )
{
(*a)->value.assign(v);
(*a)->number = atoi(v);
(*a)->number = atoi( v );
}
else
*a = new Obj(k, v);
*a = new Obj( k , v );
}
Vault::Obj::Obj(const char* k, const char* v): key(k), value(v), next(0)
{
Vault::Obj::Obj( const char* k, const char* v): key(k) , value(v) , next(0) {
number = atoi(v);
}
Vault::Obj** Vault::find(const char* n)
Vault::Obj** Vault::find( const char* n )
{
Obj** a = &head;
while (*a)
while( *a )
{
if (strcmp((*a)->key.c_str(), n) == 0)
if ( strcmp((*a)->key.c_str(), n) == 0 )
return a;
a = &(*a)->next;
@ -89,31 +88,31 @@ Vault::Obj** Vault::find(const char* n)
}
int Vault::get_number(const char* n)
int Vault::get_number( const char* n )
{
if (*n == 0) return 0;
if ( *n == 0 ) return 0;
Obj* b = *find(n);
Obj* b = *find( n );
if (b == 0) return 0;
if ( b == 0 ) return 0;
return b->number;
}
const char* Vault::get(const char* n)
const char* Vault::get( const char* n )
{
if (*n == 0) return "";
if ( *n == 0 ) return "";
Obj* b = *find(n);
Obj* b = *find( n );
if (b == 0) return "";
if ( b == 0 ) return "";
return b->value.c_str();
}
void Vault::clear()
{
while (head)
while ( head )
{
Obj* a = head->next;
delete head;
@ -121,57 +120,58 @@ void Vault::clear()
}
}
void Vault::remove(const char* n)
void Vault::remove( const char* n )
{
Obj** b = find(n);
Obj** b = find( n );
if (*b == 0) return;
if ( *b == 0 ) return;
Obj* a = (*b)->next;
delete *b;
*b = a;
}
void Vault::setSource(const char* n)
void Vault::setSource( const char* n )
{
path.assign(n);
}
bool Vault::loadVault()
bool Vault::loadVault( )
{
if (path.empty()) return false;
if ( path.empty() ) return false;
clear();
File a(path.c_str(), "r");
File a( path.c_str() , "r" );
if (!a) return false;
if ( !a ) return false;
const int sz = 512;
char value[sz + 1];
char key[sz + 1];
char value[sz+1];
char key[sz+1];
while (a >> key && a.skipWs() && a.getline(value, sz))
while ( a >> key && a.skipWs() && a.getline( value , sz ) )
{
if (isalpha(*key))
put(key, value);
if ( isalpha ( *key ) )
put( key, value );
}
return true;
}
bool Vault::saveVault()
bool Vault::saveVault( )
{
if (path.empty()) return false;
if ( path.empty() ) return false;
File a(path.c_str(), "w");
File a( path.c_str() , "w" );
if (!a) return false;
if ( !a ) return false;
a << "; Don't modify!" << '\n';
for (Obj* b = head; b; b = b->next)
for (Obj* b = head; b ;b = b->next)
a << b->key << '\t' << b->value << '\n';
return true;

View File

@ -45,43 +45,38 @@ class Vault
{
String key;
String value;
int number;
Obj *next;
Obj(const char* k, const char* v);
Obj( const char* k, const char* v);
} *head;
String path;
Obj** find(const char* n);
Obj** find( const char* n );
public:
Vault() { head = 0; }
~Vault() { clear(); }
Vault() {head=0;}
~Vault() { clear();}
// Interface
bool exists(const char* k);
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 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
{
class iterator {
Obj * a;
public:
iterator(Obj* aa) : a(aa) {}
iterator& operator++() { if (a) a = a->next; return *this; }
iterator(Obj*aa) : a(aa) {}
iterator& operator++() { if ( a ) a = a->next; return *this; }
bool operator==(const iterator& b) const { return a == b.a; }
bool operator!=(const iterator& b) const { return !operator==(b); }
String& key() const { return a->key; }
@ -92,4 +87,7 @@ public:
inline iterator end() const { return iterator(0); }
};
#endif //VAULT_CUSTOM_H
#endif

View File

@ -70,58 +70,32 @@ template <class T> class CVector
// change size
if (size == m_Size)
return true;
if (!size)
{
if (m_Data)
{
delete [] m_Data;
m_Data = NULL;
m_Size = 0;
}
return true;
}
T *newData = new T[size];
if (!newData)
return false;
if (m_Data)
{
size_t end = (m_CurrentUsedSize < size) ? (m_CurrentUsedSize) : size;
size_t end = (m_Size < size) ? (m_Size) : size;
for (size_t i=0; i<end; i++)
newData[i] = m_Data[i];
delete [] m_Data;
}
if (m_Size < size)
m_CurrentSize = size;
m_Data = newData;
m_Size = size;
if (m_CurrentUsedSize > m_Size)
m_CurrentUsedSize = m_Size;
return true;
}
void FreeMemIfPossible()
{
if (!m_Data)
return;
if (!m_CurrentUsedSize)
{
ChangeSize(0);
return;
}
size_t newSize = m_Size;
while (m_CurrentUsedSize <= newSize / 2)
newSize /= 2;
if (newSize != m_Size)
ChangeSize(newSize);
}
protected:
T *m_Data;
size_t m_Size;
size_t m_CurrentUsedSize;
size_t m_CurrentSize;
public:
class iterator
{
@ -215,7 +189,7 @@ public:
iterator & operator-=(size_t offset)
{
m_Ptr -= offset;
m_Ptr += offset;
return (*this);
}
@ -229,7 +203,7 @@ public:
iterator operator-(size_t offset) const
{
iterator tmp(*this);
tmp.m_Ptr -= offset;
tmp.m_Ptr += offset;
return tmp;
}
@ -303,12 +277,12 @@ public:
return m_Size;
}
iterator begin() const
iterator begin()
{
return iterator(m_Data);
}
iterator end() const
iterator end()
{
return iterator(m_Data + m_CurrentUsedSize);
}
@ -322,9 +296,7 @@ public:
bool reserve(size_t newSize)
{
if (newSize > m_Size)
return ChangeSize(newSize);
return true;
}
bool push_back(const T & elem)
@ -345,15 +317,14 @@ public:
--m_CurrentUsedSize;
if (m_CurrentUsedSize < 0)
m_CurrentUsedSize = 0;
FreeMemIfPossible();
// :TODO: free memory sometimes
}
bool resize(size_t newSize)
{
if (!ChangeSize(newSize))
return false;
m_CurrentUsedSize = newSize;
FreeMemIfPossible();
return true;
}
@ -426,13 +397,15 @@ public:
return m_Data[m_CurrentUsedSize - 1];
}
iterator insert(iterator where, const T & value)
bool insert(iterator where, const T & value)
{
// we have to insert before
// if it is begin, don't decrement
if (where != m_Data)
--where;
// validate iter
if (where < m_Data || where > (m_Data + m_CurrentUsedSize))
return iterator(0);
size_t ofs = where - begin();
if (where < m_Data || where >= (m_Data + m_CurrentUsedSize))
return false;
++m_CurrentUsedSize;
if (!GrowIfNeeded())
@ -441,50 +414,34 @@ public:
return false;
}
where = begin() + ofs;
// Move subsequent entries
for (T *ptr = m_Data + m_CurrentUsedSize - 2; ptr >= where.base(); --ptr)
*(ptr + 1) = *ptr;
*where.base() = value;
return where;
memmove(where.base() + 1, where.base(), m_CurrentUsedSize - (where - m_Data));
memcpy(where.base(), &value, sizeof(T));
return true;
}
iterator erase(iterator where)
void erase(iterator where)
{
// validate iter
if (where < m_Data || where >= (m_Data + m_CurrentUsedSize))
return iterator(0);
size_t ofs = where - begin();
return false;
if (m_CurrentUsedSize > 1)
{
// move
T *theend = m_Data + m_CurrentUsedSize;
for (T *ptr = where.base() + 1; ptr < theend; ++ptr)
*(ptr - 1) = *ptr;
memmove(where.base(), where.base() + 1, m_CurrentUsedSize - 1);
}
--m_CurrentUsedSize;
FreeMemIfPossible();
return begin() + ofs;
// :TODO: free memory sometimes
}
void clear()
{
m_Size = 0;
m_CurrentUsedSize = 0;
if (m_Data)
{
delete [] m_Data;
m_Data = NULL;
}
}
};
#endif // __CVECTOR_H__

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,7 +6,7 @@ MM_ROOT = ../metamod/metamod
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O2 -funroll-loops -s -pipe
OPT_FLAGS = -O3 -fno-rtti -funroll-loops -s -pipe
DEBUG_FLAGS = -g -ggdb3
CPP = gcc
NAME = amxmodx_mm
@ -15,7 +15,7 @@ OBJECTS = meta_api.cpp CFile.cpp CVault.cpp vault.cpp float.cpp file.cpp modules
CMisc.cpp CTask.cpp string.cpp amxmodx.cpp CEvent.cpp CCmd.cpp CLogEvent.cpp \
srvcmd.cpp strptime.cpp amxcore.cpp amxtime.cpp power.cpp amxxlog.cpp fakemeta.cpp \
amxxfile.cpp CLang.cpp md5.cpp emsg.cpp CForward.cpp CPlugin.cpp CModule.cpp \
CMenu.cpp util.cpp amx.cpp amxdbg.cpp natives.cpp newmenus.cpp debugger.cpp
CMenu.cpp util.cpp amx.cpp amxdbg.cpp natives.cpp newmenus.cpp \
LINK = -lz
@ -31,16 +31,16 @@ else
endif
ifeq "$(MMGR)" "true"
OBJECTS += mmgr/mmgr.cpp
CFLAGS += -DMEMORY_TEST
OBJECTS += MMGR/MMGR.CPP
endif
CFLAGS += -DLINUX -DNDEBUG -fPIC -Wno-deprecated -DHAVE_STDINT_H -static-libgcc -fno-rtti -fno-exceptions
CFLAGS += -DLINUX -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H
ifeq "$(AMD64)" "true"
BINARY = $(NAME)_amd64.so
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64
OBJECTS += JIT/natives-amd64.o
LINK += -lstdc++
else
BINARY = $(NAME)_i386.so
OBJECTS += JIT/amxexecn.o JIT/amxjitsn.o JIT/natives-x86.o

View File

@ -10,7 +10,7 @@
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misreprfesented; you must not
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in
* a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
@ -425,7 +425,10 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params)
AMX_FUNCSTUB *func;
AMX_NATIVE f;
assert(amx!=NULL);
hdr=(AMX_HEADER *)amx->base;
assert(hdr!=NULL);
assert(hdr->magic==AMX_MAGIC);
assert(hdr->natives<=hdr->libraries);
#if defined AMX_NATIVETABLE
if (index<NULL) {
@ -441,10 +444,34 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params)
#endif
assert(f!=NULL);
/* As of AMX Mod X 1.56, we don't patch sysreq.c to sysreq.d anymore.
* Otherwise, we'd have no way of knowing the last native to be used.
/* Now that we have found the function, patch the program so that any
* subsequent call will call the function directly (bypassing this
* callback).
* This trick cannot work in the JIT, because the program would need to
* be re-JIT-compiled after patching a P-code instruction.
*/
amx->usertags[UT_NATIVE] = (long)index;
#if defined JIT && !defined NDEBUG
if ((amx->flags & AMX_FLAG_JITC)!=0)
assert(amx->sysreq_d==0);
#endif
if (amx->sysreq_d!=0) {
/* at the point of the call, the CIP pseudo-register points directly
* behind the SYSREQ instruction and its parameter.
*/
unsigned char *code=amx->base+(int)hdr->cod+(int)amx->cip-4;
assert(amx->cip >= 4 && amx->cip < (hdr->dat - hdr->cod));
assert(sizeof(f)<=sizeof(cell)); /* function pointer must fit in a cell */
#if defined __GNUC__ || defined ASM32
if (*(cell*)code==index) {
#else
if (*(cell*)code!=OP_SYSREQ_PRI) {
assert(*(cell*)(code-sizeof(cell))==OP_SYSREQ_C);
assert(*(cell*)code==index);
#endif
*(cell*)(code-sizeof(cell))=amx->sysreq_d;
*(cell*)code=(cell)f;
} /* if */
} /* if */
/* Note:
* params[0] == number of bytes for the additional parameters passed to the native function
@ -453,9 +480,7 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params)
*/
amx->error=AMX_ERR_NONE;
*result = f(amx,params);
return amx->error;
}
#endif /* defined AMX_INIT */
@ -522,7 +547,6 @@ static int amx_BrowseRelocate(AMX *amx)
*/
if ((amx->flags & AMX_FLAG_JITC)==0 && sizeof(AMX_NATIVE)<=sizeof(cell))
amx->sysreq_d=opcode_list[OP_SYSREQ_D];
amx->userdata[UD_OPCODELIST] = (void *)opcode_list;
#else
/* ANSI C
* to use direct system requests, a function pointer must fit in a cell;
@ -530,7 +554,6 @@ static int amx_BrowseRelocate(AMX *amx)
*/
if (sizeof(AMX_NATIVE)<=sizeof(cell))
amx->sysreq_d=OP_SYSREQ_D;
amx->userdata[UD_OPCODELIST] = (long)NULL;
#endif
/* start browsing code */
@ -1058,9 +1081,7 @@ int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code)
/* JIT rulz! (TM) */
/* MP: added check for correct compilation */
//Fixed bug (thanks T(+)rget)
if ((res = asm_runJIT(amx->base, reloc_table, native_code)) == 0)
{
if ((res = asm_runJIT(amx->base, reloc_table, native_code)) != 0) {
/* update the required memory size (the previous value was a
* conservative estimate, now we know the exact size)
*/
@ -1540,61 +1561,6 @@ static AMX_NATIVE findfunction(const char *name, const AMX_NATIVE_INFO *list, in
}
const char *no_function;
int AMXAPI amx_CheckNatives(AMX *amx, AMX_NATIVE_FILTER nf)
{
AMX_FUNCSTUB *func;
AMX_HEADER *hdr;
int i,numnatives,res=0;
hdr=(AMX_HEADER *)amx->base;
assert(hdr!=NULL);
assert(hdr->magic==AMX_MAGIC);
assert(hdr->natives<=hdr->libraries);
numnatives=NUMENTRIES(hdr,natives,libraries);
func=GETENTRY(hdr,natives,0);
for (i=0; i<numnatives; i++) {
if (func->address==0) {
/* this function is not yet located */
res=nf(amx,i);
if (!res)
{
no_function = GETENTRYNAME(hdr,func);
return 0;
}
} /* if */
func=(AMX_FUNCSTUB*)((unsigned char*)func+hdr->defsize);
} /* for */
return 1;
}
int AMXAPI amx_RegisterToAny(AMX *amx, AMX_NATIVE f)
{
AMX_FUNCSTUB *func;
AMX_HEADER *hdr;
int i,numnatives,err;
hdr=(AMX_HEADER *)amx->base;
assert(hdr!=NULL);
assert(hdr->magic==AMX_MAGIC);
assert(hdr->natives<=hdr->libraries);
numnatives=NUMENTRIES(hdr,natives,libraries);
err=AMX_ERR_NONE;
func=GETENTRY(hdr,natives,0);
for (i=0; i<numnatives; i++) {
if (func->address==0) {
/* this function is not yet located */
func->address=(ucell)f;
} /* if */
func=(AMX_FUNCSTUB*)((unsigned char*)func+hdr->defsize);
} /* for */
if (err==AMX_ERR_NONE)
amx->flags|=AMX_FLAG_NTVREG;
return err;
}
int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *list, int number)
{
AMX_FUNCSTUB *func;
@ -1708,13 +1674,7 @@ int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char
#define SKIPPARAM(n) ( cip=(cell *)cip+(n) )
#define PUSH(v) ( stk-=sizeof(cell), *(cell *)(data+(int)stk)=v )
#define POP(v) ( v=*(cell *)(data+(int)stk), stk+=sizeof(cell) )
#define ABORT(amx,v) { (amx)->stk=reset_stk; \
(amx)->hea=reset_hea; \
(amx)->cip=(cell)cip; \
(amx)->pri=pri; \
(amx)->alt=alt; \
return v; \
}
#define ABORT(amx,v) { (amx)->stk=reset_stk; (amx)->hea=reset_hea; return v; }
#define CHKMARGIN() if (hea+STKMARGIN>stk) return AMX_ERR_STACKERR
#define CHKSTACK() if (stk>amx->stp) return AMX_ERR_STACKLOW
@ -2509,8 +2469,6 @@ static const void * const amx_opcodelist[] = {
amx->hea=hea;
amx->frm=frm;
amx->stk=stk;
amx->pri=pri;
amx->alt=alt;
num=amx->callback(amx,pri,&pri,(cell *)(data+(int)stk));
if (num!=AMX_ERR_NONE) {
if (num==AMX_ERR_SLEEP) {
@ -2530,8 +2488,6 @@ static const void * const amx_opcodelist[] = {
amx->hea=hea;
amx->frm=frm;
amx->stk=stk;
amx->pri=pri;
amx->alt=alt;
num=amx->callback(amx,offs,&pri,(cell *)(data+(int)stk));
if (num!=AMX_ERR_NONE) {
if (num==AMX_ERR_SLEEP) {
@ -2551,8 +2507,6 @@ static const void * const amx_opcodelist[] = {
amx->hea=hea;
amx->frm=frm;
amx->stk=stk;
amx->pri=pri;
amx->alt=alt;
pri=((AMX_NATIVE)offs)(amx,(cell *)(data+(int)stk));
if (amx->error!=AMX_ERR_NONE) {
if (amx->error==AMX_ERR_SLEEP) {
@ -2622,8 +2576,6 @@ static const void * const amx_opcodelist[] = {
amx->frm=frm;
amx->stk=stk;
amx->hea=hea;
amx->pri=pri;
amx->alt=alt;
amx->cip=(cell)((unsigned char*)cip-code);
num=amx->debug(amx);
if (num!=AMX_ERR_NONE) {
@ -3491,8 +3443,6 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
amx->hea=hea;
amx->frm=frm;
amx->stk=stk;
amx->pri=pri;
amx->alt=alt;
num=amx->callback(amx,pri,&pri,(cell *)(data+(int)stk));
if (num!=AMX_ERR_NONE) {
if (num==AMX_ERR_SLEEP) {
@ -3512,8 +3462,6 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
amx->hea=hea;
amx->frm=frm;
amx->stk=stk;
amx->pri=pri;
amx->alt=alt;
num=amx->callback(amx,offs,&pri,(cell *)(data+(int)stk));
if (num!=AMX_ERR_NONE) {
if (num==AMX_ERR_SLEEP) {
@ -3533,8 +3481,6 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
amx->hea=hea;
amx->frm=frm;
amx->stk=stk;
amx->pri=pri;
amx->alt=alt;
pri=((AMX_NATIVE)offs)(amx,(cell *)(data+(int)stk));
if (amx->error!=AMX_ERR_NONE) {
if (amx->error==AMX_ERR_SLEEP) {
@ -3598,8 +3544,6 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
amx->frm=frm;
amx->stk=stk;
amx->hea=hea;
amx->pri=pri;
amx->alt=alt;
amx->cip=(cell)((unsigned char*)cip-code);
num=amx->debug(amx);
if (num!=AMX_ERR_NONE) {

View File

@ -166,7 +166,6 @@ typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct tagAMX *amx, cell *params);
typedef int (AMXAPI *AMX_CALLBACK)(struct tagAMX *amx, cell index,
cell *result, cell *params);
typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
typedef int (AMXAPI *AMX_NATIVE_FILTER)(struct tagAMX *amx, int index);
#if !defined _FAR
#define _FAR
#endif
@ -243,7 +242,6 @@ typedef struct tagAMX {
long usertags[AMX_USERNUM] PACKED;
//okay userdata[3] in AMX Mod X is for the CPlugin * pointer
//we're also gonna set userdata[2] to a special debug structure
//lastly, userdata[1] is for opcode_list from amx_BrowseRelocate
void _FAR *userdata[AMX_USERNUM] PACKED;
/* native functions can raise an error */
int error PACKED;
@ -302,7 +300,6 @@ enum {
AMX_ERR_DIVIDE, /* divide by zero */
AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */
AMX_ERR_INVSTATE, /* invalid state for this access */
AMX_ERR_INVNATIVE, /* invalid native was used */
AMX_ERR_MEMORY = 16, /* out of memory */
AMX_ERR_FORMAT, /* invalid file format */
@ -338,11 +335,23 @@ enum {
#define AMX_COMPACTMARGIN 64
#endif
#define UD_FINDPLUGIN 3
#define UD_DEBUGGER 2
#define UD_OPCODELIST 1
#define UD_HANDLER 0
#define UT_NATIVE 3
struct amx_trace
{
cell frm;
amx_trace *prev;
amx_trace *next;
bool used;
};
struct AMX_DBGINFO
{
void *pDebug; //Pointer to debug data
int error; //non-amx_Exec() error setting
amx_trace *pTrace; //Pointer to stack trace
amx_trace *pTraceFrm;
amx_trace *pTraceEnd;
cell frm;
};
/* for native functions that use floating point parameters, the following
* two macros are convenient for casting a "cell" into a "float" type _without_
@ -376,7 +385,6 @@ uint32_t * AMXAPI amx_Align32(uint32_t *v);
#endif
int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr);
int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params);
int AMXAPI amx_CheckNatives(AMX *amx, AMX_NATIVE_FILTER nf);
int AMXAPI amx_Cleanup(AMX *amx);
int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data);
int AMXAPI amx_Exec(AMX *amx, cell *retval, int index);
@ -406,7 +414,6 @@ int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell
int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar);
int AMXAPI amx_RaiseError(AMX *amx, int error);
int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number);
int AMXAPI amx_RegisterToAny(AMX *amx, AMX_NATIVE f);
int AMXAPI amx_Release(AMX *amx, cell amx_addr);
int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback);
int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug);

View File

@ -129,28 +129,6 @@
jg near err_stack
%endmacro
;Normal abort, saves pri/alt
%macro _ABORT 1
mov ebp,amx
mov [ebp+_pri], dword eax ; store values in AMX structure (PRI, ALT)
mov [ebp+_alt], dword edx ; store values in AMX structure (PRI, ALT)
mov [ebp+_error], dword %1
jmp _return
%endmacro
;Checked abort, saves nothing and uses a conditional
%macro _CHKABORT 1
mov ebp,amx
mov [ebp+_error], %1
cmp %1, AMX_ERR_NONE
jne _return
%endmacro
;Fast abort, only aborts, nothing else
%macro _FASTABORT 0
jmp _return
%endmacro
%macro _CHKHEAP 0
mov ebp,amx
mov ebp,[ebp+_hlw]
@ -1218,7 +1196,8 @@ OP_HALT:
mov eax,esi ; EAX=CIP
sub eax,code
mov [ebp+_cip],eax
_ABORT ebx
mov eax,ebx ; return the parameter of the HALT opcode
jmp _return
OP_BOUNDS:
@ -1242,7 +1221,6 @@ OP_SYSREQ_PRI:
mov alt,edx ; save ALT
mov [ebp+_stk],ecx ; store values in AMX structure (STK, HEA, FRM)
;we don't save regs since they're useless after this
mov ecx,hea
mov ebx,frm
mov [ebp+_hea],ecx
@ -1273,7 +1251,8 @@ OP_SYSREQ_PRI:
pop edi ; restore saved registers
pop esi
pop ebp
_CHKABORT eax ; if result was invalid, leave
cmp eax,AMX_ERR_NONE
jne near _return ; return error code, if any
mov eax,pri ; get retval into eax (PRI)
mov edx,alt ; restore ALT
@ -1314,8 +1293,8 @@ OP_SYSREQ_D: ; (TR)
pop edi ; restore saved registers
pop esi
pop ebp
mov eax,[ebp+_error]
_CHKABORT eax
cmp DWORD [ebp+_error],AMX_ERR_NONE
jne near _return ; return error code, if any
; function result is in eax (PRI)
mov edx,alt ; restore ALT
@ -1437,7 +1416,7 @@ OP_BREAK:
mov [ebp+_error],eax ; save EAX (error code) before restoring all regs
_RESTOREREGS ; abort run, but restore stack first
mov eax,[ebp+_error] ; get error code in EAX back again
_FASTABORT
jmp _return ; return error code
break_noabort:
_RESTOREREGS
mov eax,[ebp+_pri] ; restore PRI and ALT
@ -1446,34 +1425,43 @@ OP_BREAK:
OP_INVALID:
_ABORT AMX_ERR_INVINSTR
mov eax,AMX_ERR_INVINSTR
jmp _return
err_call:
_ABORT AMX_ERR_CALLBACK
mov eax,AMX_ERR_CALLBACK
jmp _return
err_stack:
_ABORT AMX_ERR_STACKERR
mov eax,AMX_ERR_STACKERR
jmp _return
err_stacklow:
_ABORT AMX_ERR_STACKLOW
mov eax,AMX_ERR_STACKLOW
jmp _return
err_memaccess:
_ABORT AMX_ERR_MEMACCESS
mov eax,AMX_ERR_MEMACCESS
jmp _return
err_bounds:
_ABORT AMX_ERR_BOUNDS
mov eax,AMX_ERR_BOUNDS
jmp _return
err_heaplow:
_ABORT AMX_ERR_HEAPLOW
mov eax,AMX_ERR_HEAPLOW
jmp _return
err_divide:
_ABORT AMX_ERR_DIVIDE
mov eax,AMX_ERR_DIVIDE
jmp _return
_return:
; save a few parameters, mostly for the "sleep"function
mov ebp,amx ; get amx into ebp
mov [ebp+_cip],esi ; get corrected cip for amxmodx
mov eax,[ebp+_error]; get error code
mov [ebp+_pri],eax ; store values in AMX structure (PRI, ALT)
mov [ebp+_alt],edx ; store values in AMX structure (PRI, ALT)
pop esi ; remove FRM from stack

View File

@ -21,26 +21,17 @@
; step.
; NOTE 3:
; During execution of the compiled code with amx_exec_jit() the x86 processor's
; stack is switched into the data section of the abstract machine. This means
; that there should always be enough memory left between HEA and STK to provide
; stack space for occurring interrupts! (see the STACKRESERVE variable)
; NOTE 4:
; Although the Pawn compiler doesn't generate the LCTRL, SCTRL and CALL.I
; instructions, I have to tell that they don't work as expected in a JIT
; compiled program, because there is no easy way of transforming AMX code
; addresses and JIT translated ones. This might be fixed in a future version.
; NOTE 4:
; Stack Pointer issues (by David Anderson)
; The JIT was changed recently so it no longer uses ESP as a general purpose
; register (GRP), because it can conflict with threading/signal systems which
; rely on the stack pointer being in-tact to find thread-ids. My fix for this
; was to keep esp safe, but save the stack pointer in 'ecx'. As such, ecx is no
; longer the CIP or scratch register, it is the save point for pieces of the AMX
; structure on the x86 stack.
; This means that the optimization of the JIT has changed, as every amx stack
; push call now takes two operations instead of one (same for pop), and pushing
; addresses is 4 instructions instead of 1.
; As of this moment I don't see a better way around it, but the sacrifice for
; having pthread-safe code was deemed to be necessary.
; NOTE 5:
; NX ("No eXecute") and XD (eXecution Denied) bits
; (by Thiadmer Riemersma)
;
@ -74,8 +65,7 @@
; segment: the JIT-compiler patches P-code parameters into its own code segment
; during compilation. This is handled in the support code for amx_InitJIT.
;
; NOTE 6:
;
; CALLING CONVENTIONS
; (by Thiadmer Riemersma)
;
@ -87,16 +77,9 @@
; a reserved word on the assembler, I had to choose a different name for the
; macro, hence STDECL.)
; Revision History
; ----------------
; 16 august 2005 by David "BAILOPAN" Anderson (DA)
; Changed JIT to not swap stack pointer during execution. This
; is playing with fire, especially with pthreads and signals on linux,
; where the stack pointer is used to find the current thread id. If
; the stack pointer is altered during a thread/signal switch/interrupt
; unexpected behaviour can occur (crashes).
; 26 july 2005 by David "BAILOPAN" Anderson (DA)
; 26 july 2005 by David "BAILOPAN" Anderson
; Fixed a bug where zero casetbl entries would crash the JIT.
; 17 february 2005 by Thiadmer Riemersms
; Addition of the BREAK opcode, removal of the older debugging opcode
@ -182,6 +165,15 @@
;
%define FORCERELOCATABLE
;
; Determines how much memory should be reserved for occurring interrupts.
; (If my memory serves me right, DOS4/G(W) provides a stack of 512 bytes
; for interrupts that occur in real mode and are promoted to protected mode.)
; This value _MUST_ be greater than 64 (for AMX needs) and should be at least
; 128 (to serve interrupts).
;
%define STACKRESERVE 256
;
; This variable controls the generation of memory range checks at run-time.
; You should set this to 0, only when you are sure that there are no range
@ -194,49 +186,32 @@
%define JIT 1
%include "amxdefn.asm"
;Registers used for JIT during execution:
; eax - pri
; ebx - reloc frame
; ecx - info params
; edx - alt
; esi - AMX stack
; edi - DAT
; ebp - scratch
;DA:
; These are still stored in the stack, but the stack pointer
; holding them is now kept in ecx.
%define stk [ecx+32] ; define some aliases to registers that will
%define alt [ecx+28] ; be stored on the stack when the code is
%define pri [ecx+24] ; actually beeing executed
%define code [ecx+20]
%define amx [ecx+16]
%define retval [ecx+12]
%define stp [ecx+8]
%define hea [ecx+4]
%define frm [ecx] ; FRM is NOT stored in ebp, FRM+DAT is being held
; GWMV:
; Nasm can't do the next as equivalence statements, since the value of
; esi is not determined at compile time
%define stk [esi+32] ; define some aliases to registers that will
%define alt [esi+28] ; be stored on the stack when the code is
%define pri [esi+24] ; actually beeing executed
%define code [esi+20]
%define amx [esi+16]
%define retval [esi+12]
%define stp [esi+8]
%define hea [esi+4]
%define frm [esi] ; FRM is NOT stored in ebp, FRM+DAT is being held
; in ebx instead.
;
; #define PUSH(v) ( stk-=sizeof(cell), *(cell *)(data+(int)stk)=v )
;
%macro _PUSH 1
lea esi,[esi-4]
mov dword [esi], %1
%endmacro
%macro _PUSHMEM 1
lea esi,[esi-4]
mov ebp, dword %1
mov dword [esi], ebp
push dword %1
%endmacro
;
; #define POP(v) ( v=*(cell *)(data+(int)stk), stk+=sizeof(cell) )
;
%macro _POP 1
mov %1, dword [esi]
lea esi,[esi+4]
pop dword %1
%endmacro
@ -815,7 +790,7 @@ OP_LCTRL:
jne lctrl_5
GO_ON j_lctrl_4, lctrl_5, 8
j_lctrl_4:
mov eax,esi ; 4=STK
mov eax,esp ; 4=STK
sub eax,edi
CHECKCODESIZE j_lctrl_4
lctrl_5:
@ -849,7 +824,7 @@ OP_SCTRL:
j_sctrl_4:
;mov esp,eax ; 4=STK
;add esp,edi ; relocate stack
lea esi,[eax+edi]
lea esp,[eax+edi]
CHECKCODESIZE j_sctrl_4
sctrl_5:
cmp eax,5
@ -910,16 +885,14 @@ OP_PUSH_ALT:
OP_PUSH_R_PRI:
;nop;
putval j_push_r_pri+2
putval j_push_r_pri+1
GO_ON j_push_r_pri, OP_PUSH_C, 8
j_push_r_pri:
push ecx
mov ecx,12345678h
j_push_loop:
_PUSH eax
loop j_push_loop
pop ecx
;dec ecx
;jnz j_push_loop
CHECKCODESIZE j_push_r_pri
@ -927,33 +900,30 @@ OP_PUSH_R_PRI:
;good
OP_PUSH_C:
;nop;
putval j_push_c_end-4
putval j_push_c+1
GO_ON j_push_c, OP_PUSH, 8
j_push_c:
_PUSH 12345678h
j_push_c_end:
CHECKCODESIZE j_push_c
OP_PUSH:
;nop;
putval j_push_end-6
putval j_push+2
GO_ON j_push, OP_PUSH_S, 8
j_push:
_PUSHMEM [edi+12345678h]
j_push_end:
_PUSH [edi+12345678h]
CHECKCODESIZE j_push
;good
OP_PUSH_S:
;nop;
putval j_push_s_end-6
putval j_push_s+2
GO_ON j_push_s, OP_POP_PRI, 8
j_push_s:
_PUSHMEM [ebx+12345678h]
j_push_s_end:
_PUSH [ebx+12345678h]
CHECKCODESIZE j_push_s
OP_POP_PRI:
@ -980,8 +950,8 @@ OP_STACK:
GO_ON j_stack, OP_HEAP, 8
j_stack:
mov edx,esi
add esi,12345678h
mov edx,esp
add esp,12345678h
sub edx,edi
%ifdef DORUNTIMECHECKS
call [chk_marginstack]
@ -1009,9 +979,9 @@ OP_PROC:
GO_ON j_proc, OP_RET
j_proc: ;[STK] = FRM, STK = STK - cell size, FRM = STK
_PUSHMEM frm ; push old frame (for RET/RETN)
mov frm,esi ; get new frame
mov ebx,esi ; already relocated
_PUSH frm ; push old frame (for RET/RETN)
mov frm,esp ; get new frame
mov ebx,esp ; already relocated
sub frm,edi ; relocate frame
CHECKCODESIZE j_proc
@ -1021,7 +991,6 @@ OP_RET:
j_ret:
_POP ebx ; pop frame
lea esi,[esi+4]
mov frm,ebx
add ebx,edi
ret
@ -1040,13 +1009,11 @@ OP_RETN:
;good
OP_CALL:
;nop;
RELOC j_call_e8-j_call+1
RELOC 1
GO_ON j_call, OP_CALL_I, 8
j_call:
;call 12345678h ; tasm chokes on this out of a sudden
_PUSH 0
j_call_e8
db 0e8h, 0, 0, 0, 0
CHECKCODESIZE j_call
@ -1055,7 +1022,6 @@ OP_CALL_I:
GO_ON j_call_i, OP_JUMP
j_call_i:
_PUSH 0
call eax
CHECKCODESIZE j_call_i
@ -1206,30 +1172,24 @@ OP_SHL:
;nop;
GO_ON j_shl, OP_SHR
j_shl:
push ecx
mov ecx,edx
mov ecx,edx ; TODO: save ECX if used as special register
shl eax,cl
pop ecx
CHECKCODESIZE j_shl
OP_SHR:
;nop;
GO_ON j_shr, OP_SSHR
j_shr:
push ecx
mov ecx,edx
mov ecx,edx ; TODO: save ECX if used as special register
shr eax,cl
pop ecx
CHECKCODESIZE j_shr
OP_SSHR:
;nop;
GO_ON j_sshr, OP_SHL_C_PRI
j_sshr:
push ecx
mov ecx,edx
mov ecx,edx ; TODO: save ECX if used as special register
sar eax,cl
pop ecx
CHECKCODESIZE j_sshr
OP_SHL_C_PRI:
@ -1648,35 +1608,29 @@ OP_DEC_I:
OP_MOVS:
;nop;
putval j_movs+2
putval j_movs+1
GO_ON j_movs, OP_CMPS, 8
j_movs:
push ecx
mov ecx,12345678h
mov ecx,12345678h ;TODO: save ECX if used as special register
call [jit_movs]
pop ecx
CHECKCODESIZE j_movs
OP_CMPS:
;nop;
putval j_cmps+2
putval j_cmps+1
GO_ON j_cmps, OP_FILL, 8
j_cmps:
push ecx
mov ecx,12345678h
mov ecx,12345678h ;TODO: save ECX if used as special register
call [jit_cmps]
pop ecx
CHECKCODESIZE j_cmps
OP_FILL:
;nop;
putval j_fill+2
putval j_fill+1
GO_ON j_fill, OP_HALT, 8
j_fill:
push ecx
mov ecx,12345678h ;TODO: save ECX if used as special register
call [jit_fill]
pop ecx
CHECKCODESIZE j_fill
;good
@ -1925,7 +1879,7 @@ _amx_exec_jit:
push dword [eax+20]; store FRM
mov edx,[eax+4] ; get ALT
mov ebp,[eax+8] ; get CIP
mov ecx,[eax+8] ; get CIP
mov edi,[eax+12] ; get pointer to data segment
mov esi,[eax+16] ; get STK !!changed, now ECX free as counter!!
mov ebx,[eax+20] ; get FRM
@ -1933,14 +1887,13 @@ _amx_exec_jit:
add ebx,edi ; relocate frame
add esi,edi ; ESP will contain DAT+STK
xchg esp,esi ; switch to AMX stack
add [esp+8],edi ; make STP absolute address for run-time checks
add stp,edi ; make STP absolute address for run-time checks
mov dword [esi], 0 ; zero this out, but we need to keep it so
; the stack frame is in tact
mov ecx,esp ; copy stack pointer
_POP ebp ; AMX pseudo-return address, ignored
; Call compiled code via CALL NEAR <address>
call ebp
call ecx
return_to_caller:
cmp dword retval,0
@ -1953,17 +1906,15 @@ return_to_caller:
jmp _return
_return_popstack:
mov esp,ecx ; get our old stack pointer
add esp,4 ; Correct ESP, because we just come from a
; runtime error checking routine.
_return:
; store machine state
push ecx
push ecx
mov ecx,esp ; get STK into ECX
mov ebp,amx ; get amx into EBP
mov ecx,esi ; get STK into ECX
sub ecx,edi ; correct STK
mov [ebp+_stk],ecx ; store values in AMX structure: STK, ...
pop ecx ; get orig value
mov ecx,hea ; ... HEA, ...
mov [ebp+_hea],ecx
mov ecx,ebx ; ... and FRM
@ -1973,8 +1924,8 @@ _return:
mov [ebp+_alt],edx ; ... and ALT
; return
pop ecx
sub stp,edi ; make STP relative to DAT again
xchg esp,esi ; switch back to caller's stack
add esp,4*9 ; remove temporary data
@ -1995,8 +1946,12 @@ err_stacklow:
jmp _return_popstack
_CHKMARGIN_STACK: ; some run-time check routines
cmp esi,stp
cmp esp,stp
lea ebp,[esp-STACKRESERVE]
jg err_stacklow
sub ebp,edi
cmp hea,ebp
jg err_stack
ret
err_heaplow:
@ -2004,7 +1959,7 @@ err_heaplow:
jmp _return_popstack
_CHKMARGIN_HEAP:
cmp esi,stp
cmp esp,stp
jg err_stacklow
cmp dword hea,0
jl err_heaplow
@ -2020,7 +1975,7 @@ _VERIFYADDRESS_eax: ; used in load.i, store.i & lidx
cmp eax,hea
jb veax1
lea ebp,[eax+edi]
cmp ebp,esi
cmp ebp,esp
jb err_memaccess
veax1:
ret
@ -2031,7 +1986,7 @@ _VERIFYADDRESS_edx: ; used in load.i, store.i & lidx
cmp edx,hea
jb vedx1
lea ebp,[edx+edi]
cmp ebp,esi
cmp ebp,esp
jb err_memaccess
vedx1:
ret
@ -2063,15 +2018,15 @@ JIT_OP_SDIV:
JIT_OP_RETN:
_POP ebx ; pop frame
add esi,4 ; get rid of the extra parameter from call
_POP ecx ; get return address
mov frm,ebx
_POP ebp
add ebx,edi
add esi,ebp ; remove data from stack
add esp,ebp ; remove data from stack
ret
jmp ecx
JIT_OP_MOVS: ;length of block to copy is already in ECX
@ -2137,33 +2092,34 @@ err_divide:
jmp _return_popstack
JIT_OP_SYSREQ:
push ecx
push esi
mov ecx,esp ; get STK into ECX
mov ebp,amx ; get amx into EBP
sub esi,edi ; correct STK
sub ecx,edi ; correct STK
mov alt,edx ; save ALT
mov [ebp+_stk],esi ; store values in AMX structure: STK,
mov esi,hea ; HEA,
mov [ebp+_stk],ecx ; store values in AMX structure: STK,
mov ecx,hea ; HEA,
mov ebx,frm ; and FRM
mov [ebp+_hea],esi
mov [ebp+_hea],ecx
mov [ebp+_frm],ebx
lea ebx,pri ; 3rd param: addr. of retval
lea ecx,[esp+4] ; 4th param: parameter array
;Our original esi is still pushed!
xchg esp,esi ; switch to caller stack
push ecx
push ebx
push eax ; 2nd param: function number
push ebp ; 1st param: amx
call [ebp+_callback]
_DROPARGS 12 ; remove args from stack
_DROPARGS 16 ; remove args from stack
pop esi
pop ecx
xchg esp,esi ; switch back to AMX stack
cmp eax,AMX_ERR_NONE
jne _return_popstack
.continue:
jne _return_popstack; return error code, if any
mov eax,pri ; get retval into eax (PRI)
mov edx,alt ; restore ALT
mov ebx,frm ; restore FRM
@ -2172,25 +2128,25 @@ JIT_OP_SYSREQ:
JIT_OP_SYSREQ_D: ; (TR)
push ecx
push esi
mov ecx,esp ; get STK into ECX
mov ebp,amx ; get amx into EBP
sub esi,edi ; correct STK
sub ecx,edi ; correct STK
mov alt,edx ; save ALT
mov [ebp+_stk],esi ; store values in AMX structure: STK,
mov esi,hea ; HEA,
mov [ebp+_stk],ecx ; store values in AMX structure: STK,
mov ecx,hea ; HEA,
mov eax,frm ; and FRM
mov [ebp+_hea],esi
mov [ebp+_hea],ecx
mov [ebp+_frm],eax ; eax & ecx are invalid by now
;esi is still pushed!
lea edx,[esp+4] ; 2nd param: parameter array
xchg esp,esi ; switch to caller stack
push edx
push ebp ; 1st param: amx
call ebx ; direct call
_DROPARGS 8 ; remove args from stack
pop ecx
xchg esp,esi ; switch back to AMX stack
mov ebp,amx ; get amx into EBP
cmp dword [ebp+_error],AMX_ERR_NONE
jne _return_popstack; return error code, if any
@ -2204,27 +2160,25 @@ JIT_OP_SYSREQ_D: ; (TR)
JIT_OP_BREAK:
%ifdef DEBUGSUPPORT
push ecx
push esi
mov ecx,esp ; get STK into ECX
mov ebp,amx ; get amx into EBP
sub esi,edi ; correct STK
sub ecx,edi ; correct STK
mov [ebp+_pri],eax ; store values in AMX structure: PRI,
mov [ebp+_alt],edx ; ALT,
mov [ebp+_stk],esi ; STK,
mov esi,hea ; HEA,
mov [ebp+_stk],ecx ; STK,
mov ecx,hea ; HEA,
mov ebx,frm ; and FRM
mov [ebp+_hea],esi
mov [ebp+_hea],ecx
mov [ebp+_frm],ebx ; EBX & ECX are invalid by now
;??? storing CIP is not very useful, because the code changed (during JIT compile)
xchg esp,esi ; switch to caller stack
push ebp ; 1st param: amx
call [ebp+_debug]
_DROPARGS 4 ; remove args from stack
pop esi
pop ecx
xchg esp,esi ; switch back to AMX stack
cmp eax,AMX_ERR_NONE
jne _return_popstack; return error code, if any
@ -2240,7 +2194,6 @@ JIT_OP_BREAK:
JIT_OP_SWITCH:
pop ebp ; pop return address = table address
push ecx
mov ecx,[ebp] ; ECX = number of records
lea ebp,[ebp+ecx*8+8] ; set pointer _after_ LAST case
;if there are zero cases we should just skip this -- bail
@ -2252,7 +2205,6 @@ JIT_OP_SWITCH:
sub ebp,8 ; position to preceding case
loop op_switch_loop ; check next case, or fall through
op_switch_jump:
pop ecx
%ifndef FORCERELOCATABLE
jmp [ebp-4] ; jump to the case instructions
%else

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,7 @@
#ifndef AMXMODX_H
#define AMXMODX_H
#ifdef __linux__
#include <unistd.h>
#include <stdlib.h>
@ -44,7 +45,7 @@
#include "mm_pextensions.h" // metamod-p extensions
#ifdef MEMORY_TEST
#include "mmgr/mmgr.h"
#include "mmgr/mmgr.h"
#endif
#include "md5.h"
@ -68,31 +69,32 @@
#include "amxxlog.h"
#define AMXXLOG_Log g_log.Log
#define AMX_VERSION "1.60"
#define AMX_VERSION "1.50"
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 amxmod_Natives[];
extern AMX_NATIVE_INFO file_Natives[];
extern AMX_NATIVE_INFO float_Natives[];
extern AMX_NATIVE_INFO string_Natives[];
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
@ -108,33 +110,30 @@ extern AMX_NATIVE_INFO vault_Natives[];
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
{
struct WeaponsVault {
String fullName;
short int iId;
short int ammoSlot;
};
struct fakecmd_t
{
struct fakecmd_t {
char args[256];
const char *argv[3];
//char argv[3][128];
int argc;
bool fake;
};
@ -151,8 +150,7 @@ extern CList<CCVar> g_cvars;
extern CList<ForceObject> g_forcemodels;
extern CList<ForceObject> g_forcesounds;
extern CList<ForceObject> g_forcegeneric;
extern CList<CModule, const char *> g_modules;
extern CList<CScript, AMX*> g_loadedscripts;
extern CList<CModule,const char *> g_modules;
extern CList<CPlayer*> g_auth;
extern EventsMngr g_events;
extern Grenades g_grenades;
@ -178,7 +176,6 @@ extern float g_game_restarting;
extern float g_game_timeleft;
extern float g_task_time;
extern float g_auth_time;
extern bool g_NewDLL_Available;
extern hudtextparms_t g_hudset;
//extern int g_edict_point;
extern int g_players_num;
@ -227,15 +224,14 @@ 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
@ -249,28 +245,26 @@ 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, ...);
@ -285,7 +279,6 @@ enum ModuleCallReason
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();
@ -308,7 +301,7 @@ extern int FF_ClientAuthorized;
extern bool g_coloredmenus;
#ifdef FAKEMETA
extern CFakeMeta g_FakeMeta;
extern CFakeMeta g_FakeMeta;
#endif
struct func_s
@ -318,3 +311,4 @@ struct func_s
};
#endif // AMXMODX_H

View File

@ -35,7 +35,6 @@
/**********************
****** AMXXFILE ******
**********************/
#if defined __GNUC__
#define PACKED __attribute__((packed))
#else
@ -74,7 +73,6 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
{
m_Bh.plugins = NULL;
m_AmxxFile = false;
if (!filename)
{
m_Status = Err_InvalidParam;
@ -83,8 +81,8 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
m_Status = Err_None;
m_CellSize = cellsize;
m_pFile = fopen(filename, "rb");
m_pFile = fopen(filename, "rb");
if (!m_pFile)
{
m_Status = Err_FileOpen;
@ -95,37 +93,28 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
DATAREAD(&magic, sizeof(magic), 1);
m_OldFile = false;
if (magic == 0x524C4542)
{
if ( magic == 0x524C4542 ) {
//we have an invalid, old, RLEB file
m_Status = Err_OldFile;
fclose(m_pFile);
m_pFile = NULL;
return;
}
else if (magic == MAGIC_HEADER2)
{
} else if ( magic == MAGIC_HEADER2 ) {
DATAREAD(&m_Bh.version, sizeof(int16_t), 1);
if (m_Bh.version != MAGIC_VERSION)
{
m_Status = Err_OldFile;
fclose(m_pFile);
m_pFile = NULL;
return;
}
m_AmxxFile = true;
DATAREAD(&m_Bh.numPlugins, sizeof(mint8_t), 1);
m_Bh.plugins = new PluginEntry[m_Bh.numPlugins];
PluginEntry *pe;
m_SectionHdrOffset = 0;
m_Entry = -1;
for (mint8_t i = 0; i < m_Bh.numPlugins; i++)
for (mint8_t i=0; i<m_Bh.numPlugins; i++)
{
pe = &(m_Bh.plugins[i]);
DATAREAD(&pe->cellsize, sizeof(mint8_t), 1);
@ -134,32 +123,26 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
DATAREAD(&pe->memsize, sizeof(int32_t), 1);
DATAREAD(&pe->offs, sizeof(int32_t), 1);
}
for (mint8_t i = 0; i < m_Bh.numPlugins; i++)
for (mint8_t i=0; i<m_Bh.numPlugins; i++)
{
pe = &(m_Bh.plugins[i]);
if (pe->cellsize == m_CellSize)
{
m_Entry = i;
break;
}
}
if (m_Entry == -1)
{
m_Status = Err_SectionNotFound;
fclose(m_pFile);
m_pFile = NULL;
return;
}
pe = &(m_Bh.plugins[m_Entry]);
m_SectionLength = pe->disksize;
}
else if (magic == MAGIC_HEADER)
{
} else if (magic == MAGIC_HEADER) {
// try to find the section
mint8_t numOfPlugins;
DATAREAD(&numOfPlugins, sizeof(numOfPlugins), 1);
@ -168,7 +151,6 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
m_SectionHdrOffset = 0;
int i = 0;
for (i = 0; i < static_cast<int>(numOfPlugins); ++i)
{
DATAREAD(&entry, sizeof(entry), 1);
@ -178,7 +160,6 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
break;
}
}
if (!m_SectionHdrOffset)
{
m_Status = Err_SectionNotFound;
@ -188,13 +169,15 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
}
// compute section length
if ((i + 1) < static_cast<int>(numOfPlugins))
if ((i+1) < static_cast<int>(numOfPlugins))
{
// there is a next section
TableEntry nextEntry;
DATAREAD(&nextEntry, sizeof(nextEntry), 1);
m_SectionLength = nextEntry.offset - entry.offset;
} else {
}
else
{
fseek(m_pFile, 0, SEEK_END);
m_SectionLength = ftell(m_pFile) - (long)entry.offset;
}
@ -204,7 +187,6 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
rewind(m_pFile);
fread(&hdr, sizeof(hdr), 1, m_pFile);
amx_Align16(&hdr.magic);
if (hdr.magic == AMX_MAGIC)
{
if (cellsize != 4)
@ -212,19 +194,18 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
m_Status = Err_SectionNotFound;
fclose(m_pFile);
m_pFile = NULL;
return;
}
m_OldFile = true;
return;
} else {
}
else
{
// no known file format
m_Status = Err_FileInvalid;
fclose(m_pFile);
m_pFile = NULL;
return;
}
}
@ -237,10 +218,9 @@ CAmxxReader::~CAmxxReader()
fclose(m_pFile);
m_pFile = NULL;
}
if (m_Bh.plugins)
{
delete [] m_Bh.plugins;
delete m_Bh.plugins;
m_Bh.plugins = NULL;
}
}
@ -276,16 +256,11 @@ 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)
{
} else if (m_AmxxFile) {
PluginEntry *pe = &(m_Bh.plugins[m_Entry]);
if (pe->imagesize > pe->memsize)
return pe->imagesize + 1;
return pe->memsize + 1;
}
@ -294,7 +269,6 @@ size_t CAmxxReader::GetBufferSize()
TableEntry entry;
DATAREAD(&entry, sizeof(entry), 1);
fseek(m_pFile, save, SEEK_SET);
return entry.origSize + 1; // +1 : safe
}
@ -324,26 +298,22 @@ CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
rewind(m_pFile);
DATAREAD(buffer, 1, filesize);
m_Status = Err_None;
return m_Status;
}
else if (m_AmxxFile)
{
} else if (m_AmxxFile) {
PluginEntry *pe = &(m_Bh.plugins[m_Entry]);
char *tempBuffer = new char[m_SectionLength + 1];
fseek(m_pFile, pe->offs, SEEK_SET);
DATAREAD((void *)tempBuffer, 1, m_SectionLength);
uLongf destLen = GetBufferSize();
int result = uncompress((Bytef *)buffer, &destLen, (Bytef *)tempBuffer, m_SectionLength);
int result = uncompress((Bytef *)buffer, &destLen,
(Bytef *)tempBuffer, m_SectionLength);
delete [] tempBuffer;
if (result != Z_OK)
{
AMXXLOG_Log("[AMXX] Zlib error encountered: %d(%d)", result, m_SectionLength);
m_Status = Err_Decompress;
return Err_Decompress;
}
return Err_None;
} else {
// new file type: go to the section table entry
@ -358,17 +328,15 @@ CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
//fread(tempBuffer, sizeof(char), m_SectionLength, m_pFile);
DATAREAD((void*)tempBuffer, 1, m_SectionLength);
// decompress
int result = uncompress((Bytef *)buffer, &destLen, (Bytef *)tempBuffer, m_SectionLength);
int result = uncompress((Bytef *)buffer, &destLen,
(Bytef *)tempBuffer, m_SectionLength);
delete [] tempBuffer;
if (result != Z_OK)
{
AMXXLOG_Log("[AMXX] Zlib error encountered: %d(%d)", result, m_SectionLength);
m_Status = Err_Decompress;
return Err_Decompress;
}
return Err_None;
}
}

View File

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

View File

@ -36,12 +36,12 @@
#include <time.h>
#ifndef __linux__
#include <io.h>
#include <io.h>
#endif
#include "amxmodx.h"
#ifndef __linux__
#define vsnprintf _vsnprintf
#define vsnprintf _vsnprintf
#endif
CLog::CLog()
@ -61,7 +61,6 @@ void CLog::CloseFile()
if (!m_LogFile.empty())
{
FILE *fp = fopen(m_LogFile.c_str(), "r");
if (fp)
{
fclose(fp);
@ -78,7 +77,6 @@ void CLog::CloseFile()
fprintf(fp, "L %s: %s\n", date, "Log file closed.");
fclose(fp);
}
m_LogFile.clear();
}
}
@ -86,33 +84,29 @@ void CLog::CloseFile()
void CLog::CreateNewFile()
{
CloseFile();
// build filename
time_t td;
time(&td);
tm *curTime = localtime(&td);
int i = 0;
while (true)
{
FILE *pTmpFile = fopen(m_LogFile.c_str(), "r"); // open for reading to check whether the file exists
if (!pTmpFile)
break;
fclose(pTmpFile);
++i;
}
// Log logfile start
FILE *fp = fopen(m_LogFile.c_str(), "w");
if (!fp)
{
ALERT(at_logged, "[AMXX] Unexpected fatal logging error. AMXX Logging disabled.\n");
SET_LOCALINFO("amxx_logging", "0");
} else {
}
else
{
fprintf(fp, "AMX Mod X log file started (file \"%s/L%02d%02d%03d.log\") (version \"%s\")\n", g_log_dir.c_str(), curTime->tm_mon + 1, curTime->tm_mday, i, AMX_VERSION);
fclose(fp);
}
@ -129,13 +123,12 @@ 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"));
if (m_LogType < 0 || m_LogType > 3)
{
SET_LOCALINFO("amxx_logging", "1");
@ -150,7 +143,7 @@ void CLog::MapChange()
}
else if (m_LogType == 1)
{
Log("-------- Mapchange to %s --------", STRING(gpGlobals->mapname));
Log("-------- Mapchange --------");
}
else
return;
@ -159,7 +152,6 @@ void CLog::MapChange()
void CLog::Log(const char *fmt, ...)
{
static char file[256];
if (m_LogType == 1 || m_LogType == 2)
{
// get time
@ -186,7 +178,6 @@ void CLog::Log(const char *fmt, ...)
{
CreateNewFile();
pF = fopen(m_LogFile.c_str(), "a+");
if (!pF)
{
ALERT(at_logged, "[AMXX] Unexpected fatal logging error (couldn't open %s for a+). AMXX Logging disabled for this map.\n", m_LogFile.c_str());
@ -194,16 +185,19 @@ void CLog::Log(const char *fmt, ...)
return;
}
}
} else {
}
else
{
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);
fclose(pF);
} else {
}
else
{
ALERT(at_logged, "[AMXX] Unexpected fatal logging error (couldn't open %s for a+). AMXX Logging disabled for this map.\n", file);
m_LogType = 0;
return;

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,201 +0,0 @@
/* AMX Mod X
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* 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,
* 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,
* 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
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
#ifndef _INCLUDE_DEBUGGER_H_
#define _INCLUDE_DEBUGGER_H_
#include "CVector.h"
#include "amxdbg.h"
/**
* Third revision of the AMX Mod X Plugin Debugger.
* This final, object oriented version is safe for multiple calls and lets you
* fine-tune error handling.
* -BAILOPAN
*/
class Debugger
{
public:
class Tracer
{
public:
struct trace_info
{
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();
public:
void StepI(cell frm, cell cip);
void Reset();
void Clear();
Debugger::Tracer::trace_info *GetStart() const;
Debugger::Tracer::trace_info *GetEnd() const;
public:
int m_Error;
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();
public:
//Begin a trace for a function
void BeginExec();
//Step through one instruction
void StepI();
//Get/set the last traced error
int GetTracedError();
void SetTracedError(int error);
//Get the first trace info of the call stack
Debugger::Tracer::trace_info *GetTraceStart() const;
//Get extra info about the call stack
bool GetTraceInfo(Debugger::Tracer::trace_info *pTraceInfo, long &line, const char *&function, const char *&file);
//Get the next trace in the call stack, NULL if none
Debugger::Tracer::trace_info *GetNextTrace(Debugger::Tracer::trace_info *pTraceInfo);
//Returns true if an error exists
bool ErrorExists();
//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);
//End a trace
void EndExec();
//Reset the internal states as if the debugger was inactive
void Reset();
//Destroy internal states for shutdown
void Clear();
void DisplayTrace(const char *message);
AMX *GetAMX() const { return m_pAmx; }
public:
//generic static opcode breaker
static int AMXAPI DebugHook(AMX *amx);
static void FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLength);
static void GenericMessage(AMX *amx, int error);
private:
void _CacheAmxOpcodeList();
int _GetOpcodeFromCip(cell cip, cell *&addr);
cell _CipAsVa(cell cip);
const char *_GetFilename();
public:
AMX *m_pAmx;
AMX_DBG *m_pAmxDbg;
int m_Top;
cell *m_pOpcodeList;
String m_FileName;
CVector<Tracer *> m_pCalls;
};
typedef Debugger::Tracer::trace_info trace_info_t;
/**
* Error handler for plugins
*/
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() {};
public:
int SetErrorHandler(const char *function);
int SetNativeFilter(const char *function);
int SetModuleFilter(const char *function);
public:
int HandleError(const char *msg);
int HandleNative(const char *native, int index, int trap);
int HandleModule(const char *module);
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;
};
extern AMX_NATIVE_INFO g_DebugNatives[];
#endif //_INCLUDE_DEBUGGER_H_

View File

@ -58,9 +58,7 @@ WeaponsVault g_weaponsData[MAX_WEAPONS];
void Client_VGUIMenu(void* mValue)
{
if (!mPlayer) return;
switch (mState++)
{
switch (mState++){
case 0:
mPlayer->menu = -(*(int*)mValue);
break;
@ -72,14 +70,12 @@ void Client_VGUIMenu(void* mValue)
void Client_ShowMenu(void* mValue)
{
if (!mPlayer) return;
switch (mState++)
{
switch (mState++){
case 0:
mPlayer->keys = *(int*)mValue;
break;
case 3:
mPlayer->menu = g_menucmds.findMenuId((char*)mValue);
mPlayer->menu = g_menucmds.findMenuId( (char*)mValue );
}
}
@ -87,74 +83,59 @@ void Client_TeamInfo(void* mValue)
{
if (mPlayer) return;
static int index;
switch (mState++)
{
switch (mState++) {
case 0:
index = *(int*)mValue;
break;
case 1:
if (index < 1 || index > gpGlobals->maxClients) break;
if ( index < 1 || index > gpGlobals->maxClients ) break;
char* msg = (char*)mValue;
g_players[index].team.assign(msg);
g_teamsIds.registerTeam(msg, -1);
g_players[ index ].team.assign( msg );
g_teamsIds.registerTeam( msg , -1 );
}
}
void Client_TextMsg(void* mValue)
{
if (mPlayer) return;
switch (mState++)
{
case 1:
{
if ( mPlayer ) return;
switch (mState++) {
case 1:{
char * msg = (char*)mValue;
if (!msg) break;
if (!strncmp("#Game_C", msg, 7))
{
if ( !strncmp("#Game_C", msg , 7) ) {
g_game_timeleft = g_game_restarting = gpGlobals->time + 3;
//g_endround_time = gpGlobals->time;
//g_newround_time = gpGlobals->time + CVAR_GET_FLOAT("mp_freezetime") + 3;
// g_endround_time = gpGlobals->time;
// g_newround_time = gpGlobals->time + CVAR_GET_FLOAT("mp_freezetime") + 3;
}
else if (!strncmp("#Game_w", msg, 7))
{
else if (!strncmp("#Game_w", msg , 7) ) {
g_game_timeleft = -2;
}
else if (!strncmp("#game_clan_s", msg, 12))
{
else if ( !strncmp("#game_clan_s", msg , 12) ){
g_game_timeleft = -3;
}
break;
}
case 2:
{
case 2:{
char * msg = (char*)mValue;
if (!msg) break;
if (g_game_timeleft == -2)
{
g_game_timeleft = g_game_restarting = gpGlobals->time + atoi(msg);
//g_newround_time = g_game_timeleft + CVAR_GET_FLOAT("mp_freezetime");
if (g_game_timeleft == -2 ){
g_game_timeleft = g_game_restarting = gpGlobals->time + atoi( msg );
// g_newround_time = g_game_timeleft + CVAR_GET_FLOAT("mp_freezetime");
}
else if (g_game_timeleft == -3)
g_game_restarting = atoi(msg) * 60.0f;
else if ( g_game_timeleft == -3 )
g_game_restarting = atoi( msg ) * 60;
break;
}
case 3:
{
case 3:{
char * msg = (char*)mValue;
if (!msg) break;
if (g_game_timeleft != -3) break;
g_game_restarting += atoi(msg);
if ( g_game_timeleft != -3 ) break;
g_game_restarting += atoi( msg );
g_game_timeleft = g_game_restarting = gpGlobals->time + g_game_restarting;
break;
}
}
}
void Client_WeaponList(void* mValue)
@ -163,9 +144,7 @@ void Client_WeaponList(void* mValue)
//static int wpnList2;
static int iSlot;
static const char* wpnName;
switch (mState++)
{
switch (mState++) {
case 0:
wpnName = (char*)mValue;
break;
@ -174,12 +153,24 @@ void Client_WeaponList(void* mValue)
break;
case 7:
int iId = *(int*)mValue;
if ((iId < 0 || iId >= MAX_WEAPONS) || (wpnList & (1<<iId)))
/*int* blocker;
int iwpn = iId;
if (iId > 31) {
iwpn -= 31;
blocker = &wpnList2;
}
else
blocker = &wpnList;*/
if ( (iId < 0 || iId >= MAX_WEAPONS ) || (wpnList & (1<<iId)) )
break;
wpnList |= (1<<iId);
g_weaponsData[iId].iId = iId;
g_weaponsData[iId].ammoSlot = iSlot;
g_weaponsData[iId].fullName.assign(wpnName);
}
}
@ -187,9 +178,7 @@ void Client_CurWeapon(void* mValue)
{
static int iState;
static int iId;
switch (mState++)
{
switch (mState++){
case 0:
iState = *(int*)mValue;
break;
@ -199,7 +188,7 @@ void Client_CurWeapon(void* mValue)
break;
case 2:
if (!mPlayer) return;
if (!iState || (iId < 1 || iId >= MAX_WEAPONS)) break;
if (!iState || (iId < 1 || iId >= MAX_WEAPONS ) ) break;
mPlayer->weapons[iId].clip = *(int*)mValue;
mPlayer->current = iId;
mPlayer->lastHit = mPlayer->lastTrace;
@ -208,16 +197,15 @@ void Client_CurWeapon(void* mValue)
void Client_AmmoX(void* mValue)
{
static int iAmmo;
switch (mState++)
{
static int iAmmo;
switch (mState++){
case 0:
iAmmo = *(int*)mValue;
break;
case 1:
if (!mPlayer) return;
for (int i = 1; i < MAX_WEAPONS; ++i)
for(int i=1;i<MAX_WEAPONS;++i)
if (iAmmo == g_weaponsData[i].ammoSlot)
mPlayer->weapons[i].ammo = *(int*)mValue;
}
@ -226,15 +214,13 @@ void Client_AmmoX(void* mValue)
void Client_AmmoPickup(void* mValue)
{
static int iSlot;
switch (mState++)
{
switch (mState++){
case 0:
iSlot = *(int*)mValue;
break;
case 1:
if (!mPlayer) return;
for (int i = 1; i < MAX_WEAPONS; ++i)
for(int i=1;i<MAX_WEAPONS;++i)
if (g_weaponsData[i].ammoSlot==iSlot)
mPlayer->weapons[i].ammo += *(int*)mValue;
}
@ -244,9 +230,7 @@ void Client_ScoreInfo(void* mValue)
{
static int index;
static int deaths;
switch (mState++)
{
switch (mState++){
case 0:
index = *(int*)mValue;
break;
@ -254,12 +238,12 @@ void Client_ScoreInfo(void* mValue)
deaths = *(int*)mValue;
break;
case 4:
if (index < 1 || index > gpGlobals->maxClients) break;
CPlayer*pPlayer = GET_PLAYER_POINTER_I(index);
if ( index < 1 || index > gpGlobals->maxClients ) break;
CPlayer*pPlayer = GET_PLAYER_POINTER_I( index );
pPlayer->deaths = deaths;
pPlayer->teamId = *(int*)mValue;
if (g_teamsIds.isNewTeam())
g_teamsIds.registerTeam(pPlayer->team.c_str(), pPlayer->teamId);
if ( g_teamsIds.isNewTeam() )
g_teamsIds.registerTeam( pPlayer->team.c_str() , pPlayer->teamId );
}
}
@ -267,14 +251,14 @@ void Client_DamageEnd(void* mValue)
{
CPlayer* dead = mPlayer;
if (dead && dead->death_killer)
if ( dead && dead->death_killer )
{
g_events.parserInit(CS_DEATHMSG, &gpGlobals->time, mPlayer = 0, mPlayerIndex = 0);
g_events.parseValue(dead->death_killer);
g_events.parseValue(dead->index);
g_events.parseValue(dead->death_headshot);
g_events.parseValue(dead->death_weapon.c_str());
g_events.parseValue(dead->death_tk ? 1 : 0);
g_events.parserInit( CS_DEATHMSG , &gpGlobals->time , mPlayer = 0, mPlayerIndex = 0 );
g_events.parseValue( dead->death_killer );
g_events.parseValue( dead->index );
g_events.parseValue( dead->death_headshot );
g_events.parseValue( dead->death_weapon.c_str() );
g_events.parseValue( dead->death_tk ? 1 : 0 );
g_events.executeEvents();
dead->death_killer = 0;
}
@ -288,21 +272,24 @@ void Client_DeathMsg(void* mValue)
static int victim_id;
static int hs;
switch (mState++)
{
switch (mState++){
case 0:
killer_id = *(int*)mValue;
killer = (killer_id > 0 && killer_id < 33) ? GET_PLAYER_POINTER_I(killer_id) : 0;
killer = (killer_id > 0 && killer_id < 33) ?
GET_PLAYER_POINTER_I(killer_id) : 0;
break;
case 1:
victim_id = *(int*)mValue;
victim = (victim_id > 0 && victim_id < 33) ? GET_PLAYER_POINTER_I(victim_id) : 0;
victim = (victim_id > 0 && victim_id < 33) ?
GET_PLAYER_POINTER_I(victim_id) : 0;
break;
case 2:
hs = *(int*)mValue;
break;
case 3:
if (!killer || !victim) break;
if ( !killer || !victim ) break;
victim->death_killer = killer_id;
victim->death_weapon.assign((char*)mValue);
victim->death_headshot = hs;

View File

@ -32,8 +32,8 @@
#define __FAKEMETA_H__
#ifndef FAKEMETA
int UnloadMetamodPlugin(void *handle);
int LoadMetamodPlugin(const char *path, void **handle, PLUG_LOADTIME now);
int UnloadMetamodPlugin(void *handle);
int LoadMetamodPlugin(const char *path, void **handle, PLUG_LOADTIME now);
#else
// Fake metamod api for modules
@ -42,8 +42,7 @@
// from mplugin.h (metamod)
// Flags to indicate current "load" state of plugin.
// NOTE: order is important, as greater/less comparisons are made.
typedef enum
{
typedef enum {
PL_EMPTY = 0, // empty slot
PL_VALID, // has valid info in it
PL_BADFILE, // nonexistent file (open failed),
@ -56,10 +55,11 @@ typedef enum
// from h_export.h (metamod)
// Our GiveFnptrsToDll, called by engine.
typedef void (WINAPI *GIVE_ENGINE_FUNCTIONS_FN) (enginefuncs_t *pengfuncsFromEngine, globalvars_t *pGlobals);
typedef void (WINAPI *GIVE_ENGINE_FUNCTIONS_FN) (enginefuncs_t
*pengfuncsFromEngine, globalvars_t *pGlobals);
// *** CFakeMeta
class CFakeMeta
{
private:
@ -100,6 +100,7 @@ public:
inline void SetStatus(PLUG_STATUS newStatus)
{ m_Status = newStatus; }
inline plugin_info_t * GetInfo()
{ return m_Info; }
inline const plugin_info_t * GetInfo() const
@ -231,3 +232,4 @@ extern CFakeMeta g_FakeMeta;
#endif //FAKEMETA
#endif // #ifndef __FAKEMETA_H__

View File

@ -5,7 +5,7 @@
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public<EFBFBD> License as published by the
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
@ -62,14 +62,12 @@ class AutoFilePtr
FILE *m_FP;
public:
AutoFilePtr(FILE *fp) : m_FP(fp)
{}
{ }
~AutoFilePtr()
{
if (m_FP)
fclose(m_FP);
}
operator FILE* ()
{
return m_FP;
@ -82,26 +80,20 @@ static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
int a;
struct dirent *ep;
DIR *dp;
char* dirname = build_pathname("%s", get_amxstring(amx, params[1], 0, a));
char* dirname = build_pathname("%s",get_amxstring(amx,params[1],0,a) );
a = params[2];
if ((dp = opendir (dirname)) == NULL)
if ( (dp = opendir (dirname)) == NULL )
return 0;
seekdir(dp, a);
if ((ep = readdir (dp)) != NULL)
{
cell *length = get_amxaddr(amx, params[5]);
*length = set_amxstring(amx, params[3], ep->d_name, params[4]);
a = telldir(dp);
} else
seekdir( dp , a );
if ( (ep = readdir (dp)) != NULL ) {
cell *length = get_amxaddr(amx,params[5]);
*length = set_amxstring(amx,params[3], ep->d_name ,params[4]);
a = telldir( dp );
}
else
a = 0;
closedir (dp);
return a;
#else
int tmp;
char *dirname = build_pathname("%s/*", get_amxstring(amx, params[1], 0, tmp));
@ -109,12 +101,10 @@ static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
_finddata_t fd;
intptr_t handle = _findfirst(dirname, &fd);
if (handle < 0)
return 0;
++tmp;
for (int i = 0; i < tmp; ++i)
{
if (_findnext(handle, &fd) < 0)
@ -123,9 +113,8 @@ static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
break;
}
}
// current data in fd
cell *length = get_amxaddr(amx, params[5]); // pointer to the outLen parameter
cell *length = get_amxaddr(amx,params[5]); // pointer to the outLen parameter
*length = set_amxstring(amx, params[3], fd.name, params[4]); // set output and outLen parameters
_findclose(handle);
@ -136,82 +125,61 @@ static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL read_file(AMX *amx, cell *params) /* 5 param */
{
int iLen;
char* szFile = get_amxstring(amx, params[1], 0, iLen);
FILE *fp;
if ((fp =fopen(build_pathname("%s", szFile), "r")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
char* szFile = get_amxstring(amx,params[1],0,iLen);
FILE*fp;
if ( (fp =fopen(build_pathname("%s",szFile),"r")) == NULL) {
amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0;
}
char buffor[1024];
int i = 0, iLine = params[2];
while ((i <= iLine) && fgets(buffor, 1023, fp))
while((i <= iLine) && fgets(buffor,1023,fp) )
i++;
fclose(fp);
if (i > iLine)
{
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]);
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;
}
return 0;
}
static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
{
int i;
char* sFile = build_pathname("%s", get_amxstring(amx, params[1], 0, i));
char* sText = get_amxstring(amx, params[2], 0, i);
char* sFile = build_pathname("%s", get_amxstring(amx,params[1],0,i) );
char* sText = get_amxstring(amx,params[2],0,i);
FILE* pFile;
int iLine = params[3];
// apending to the end
if (iLine < 0)
{
if ((pFile = fopen(sFile, "a")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
if (iLine < 0) {
if ( (pFile = fopen( sFile ,"a")) == NULL ){
amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0;
}
fputs(sText, pFile);
fputc('\n', pFile);
fclose(pFile);
fputs( sText , pFile );
fputc( '\n', pFile );
fclose( pFile );
return 1;
}
// creating a new file with a line in a middle
if ((pFile = fopen(sFile, "r")) == NULL)
{
if ((pFile = fopen(sFile, "w")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
if ( (pFile = fopen(sFile,"r")) == NULL ) {
if ( (pFile = fopen(sFile,"w")) == NULL ){
amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0;
}
for (i = 0; i < iLine; ++i)
fputc('\n', pFile);
fputs(sText, pFile);
fputc('\n', pFile);
for(i=0;i < iLine;++i)
fputc('\n',pFile);
fputs( sText , pFile );
fputc( '\n', pFile );
fclose(pFile);
return 1;
}
@ -219,84 +187,68 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
FILE* pTemp;
char buffor[2048];
if ((pTemp = tmpfile()) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
if ( (pTemp = tmpfile()) == NULL ){
amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0;
}
for (i = 0; ; ++i)
{
if (i == iLine)
{
fgets(buffor, 2047, pFile);
fputs(sText, pTemp);
fputc('\n', pTemp);
for(i=0;;++i){
if ( i == iLine ){
fgets(buffor,2047,pFile);
fputs( sText , pTemp );
fputc( '\n', pTemp );
}
else if (fgets(buffor, 2047, pFile))
{
fputs(buffor, pTemp);
else if ( fgets(buffor,2047,pFile) ){
fputs(buffor , pTemp );
}
else if (i < iLine)
{
fputc('\n', pTemp);
else if ( i < iLine ) {
fputc( '\n', pTemp );
}
else
break;
else break;
}
fclose(pFile);
rewind(pTemp);
// now rewrite because file can be now smaller...
if ((pFile = fopen(sFile, "w")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
if ( (pFile = fopen(sFile,"w")) == NULL ){
amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0;
}
while (fgets(buffor, 2047, pTemp))
fputs(buffor, pFile);
while(fgets(buffor,2047,pTemp))
fputs(buffor,pFile );
fclose(pTemp);
fclose(pFile);
return 1;
}
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);
char* sFile = get_amxstring(amx,params[1],0,iLen);
return (unlink( build_pathname("%s",sFile) )?0:1);
}
static cell AMX_NATIVE_CALL file_exists(AMX *amx, cell *params) /* 1 param */
{
int iLen;
char *sFile = get_amxstring(amx, params[1], 0, iLen);
char *file = build_pathname("%s", sFile);
char *sFile = get_amxstring(amx,params[1],0,iLen);
char *file = build_pathname("%s",sFile);
#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
}
@ -304,28 +256,21 @@ static cell AMX_NATIVE_CALL file_exists(AMX *amx, cell *params) /* 1 param */
static cell AMX_NATIVE_CALL dir_exists(AMX *amx, cell *params) /* 1 param */
{
int iLen;
char *sFile = get_amxstring(amx, params[1], 0, iLen);
char *file = build_pathname("%s", sFile);
char *sFile = get_amxstring(amx,params[1],0,iLen);
char *file = build_pathname("%s",sFile);
#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
}
@ -333,26 +278,24 @@ static cell AMX_NATIVE_CALL dir_exists(AMX *amx, cell *params) /* 1 param */
static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
{
int iLen;
char* sFile = get_amxstring(amx, params[1], 0, iLen);
AutoFilePtr fp(fopen(build_pathname("%s", sFile), "r"));
if (fp != NULL)
char* sFile = get_amxstring(amx,params[1],0,iLen);
AutoFilePtr fp(fopen(build_pathname("%s",sFile),"r"));
if ( fp != NULL)
{
if (params[0] < 2 || params[2] == 0)
if ( params[0] < 2 || params[2] == 0 )
{
fseek(fp, 0, SEEK_END);
fseek(fp,0,SEEK_END);
int size = ftell(fp);
return size;
}
else if (params[2] == 1)
else if ( params[2] == 1 )
{
int a = 0,lines = 0;
while (a != EOF)
while( a != EOF )
{
++lines;
while ((a = fgetc(fp)) != '\n' && a != EOF);
while ( (a = fgetc(fp)) != '\n' && a != EOF )
;
}
//int a, b = '\n';
//while( (a = fgetc(fp)) != EOF ){
@ -364,17 +307,13 @@ static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
// ++lines;
return lines;
}
else if (params[2] == 2)
{
fseek(fp, -1, SEEK_END);
if (fgetc(fp) == '\n')
else if ( params[2] == 2 ){
fseek(fp,-1,SEEK_END);
if ( fgetc(fp) == '\n' )
return 1;
return 0;
}
}
return -1;
}
@ -383,19 +322,17 @@ 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)
{
if (fp == NULL) {
// Failed
return 0;
}
for (i = 0; i < FileList.size(); i++)
for (i=0; i<FileList.size(); i++)
{
if (FileList.at(i) == NULL)
{
@ -403,8 +340,7 @@ static cell AMX_NATIVE_CALL amx_fopen(AMX *amx, cell *params)
break;
}
}
if (j == -1)
if (j==-1)
{
FileList.push_back(fp);
j = FileList.size() - 1;
@ -412,20 +348,16 @@ static cell AMX_NATIVE_CALL amx_fopen(AMX *amx, cell *params)
FileList.at(j) = fp;
}
return j + 1;
return j+1;
}
static cell AMX_NATIVE_CALL amx_fclose(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
{
if (fp) {
return fclose(fp);
} else {
return -1;
@ -435,24 +367,17 @@ static cell AMX_NATIVE_CALL amx_fclose(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fread(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
char *buffer;
if (fp)
{
if (fp) {
buffer = new char[params[3]]; // SLOW!!! :TODO: Find a better way (auto pointers?)
fread(buffer, sizeof(char), params[3], fp);
set_amxstring(amx, params[2], buffer, params[3]);
delete [] buffer;
return 1;
}
return -1;
}
@ -460,14 +385,10 @@ static cell AMX_NATIVE_CALL amx_fread(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fgetc(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
{
if (fp) {
return fgetc(fp);
} else {
return -1;
@ -477,128 +398,97 @@ static cell AMX_NATIVE_CALL amx_fgetc(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fwrite(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
char *buf;
int len;
if (fp)
{
if (fp) {
buf = format_amxstring(amx, params, 2, len);
return fwrite(buf, sizeof(char), strlen(buf), fp);
}
return -1;
}
static cell AMX_NATIVE_CALL amx_feof(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
{
if (feof(fp))
{
if (fp) {
if (feof(fp)) {
return 1;
}
return 0;
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fseek(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
{
if (fp) {
return fseek(fp, (long)params[2], params[3]);
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fputc(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
{
if (fp) {
return fputc(params[2], fp);
}
return -1;
}
static cell AMX_NATIVE_CALL amx_rewind(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
{
if (fp) {
rewind(fp);
return 1;
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fflush(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
{
if (fp) {
return fflush(fp);
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fscanf(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
char *buf;
int len;
buf = format_amxstring(amx, params, 2, len);
if (fp)
{
if (fp) {
return fscanf(fp, "%s", buf);
}
@ -608,17 +498,13 @@ static cell AMX_NATIVE_CALL amx_fscanf(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_ftell(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
if (fp)
{
if (fp) {
return ftell(fp);
}
return -1;
}
#endif //UNUSED
@ -628,17 +514,12 @@ 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)
{
if (fp) {
fseek(fp, 0, SEEK_END);
size = ftell(fp);
return size;
}
return -1;
}
@ -646,156 +527,116 @@ static cell AMX_NATIVE_CALL amx_filesize(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fgetl(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
long t;
if (fp)
{
if (fp) {
fread(&t, sizeof(long), 1, fp);
return t;
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fgeti(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
int t;
if (fp)
{
if (fp) {
fread(&t, sizeof(int), 1, fp);
return t;
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fgets(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
short t;
if (fp)
{
if (fp) {
fread(&t, sizeof(short), 1, fp);
return t;
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fputs(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
short size = params[2];
if (fp)
{
if (fp) {
return fwrite(&size, sizeof(short), 1, fp);
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fputl(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
long size = params[2];
if (fp)
{
if (fp) {
return fwrite(&size, sizeof(long), 1, fp);
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fputi(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
int size = params[2];
if (fp)
{
if (fp) {
return fwrite(&size, sizeof(int), 1, fp);
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fgetf(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
float t;
if (fp)
{
if (fp) {
fread(&t, sizeof(float), 1, fp);
return *(cell*)&t;
}
return -1;
}
static cell AMX_NATIVE_CALL amx_fputf(AMX *amx, cell *params)
{
unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL)
return 0;
FILE *fp = FileList.at(id);
float size = *(float *)((void *)&params[2]);
if (fp)
{
if (fp) {
return fwrite(&size, sizeof(float), 1, fp);
}
return -1;
}
#endif //UNUSED
@ -804,7 +645,6 @@ 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]);
}
@ -815,32 +655,24 @@ 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;
#else
char *dirname = build_pathname("%s", path);
DIR *dp = opendir(dirname);
if (!dp)
return NULL;
struct dirent *ep = readdir(dp);
if (!ep)
{
closedir(dp);
return NULL;
}
set_amxstring(amx, params[2], ep->d_name, params[3]);
set_amxstring(amx,params[2], ep->d_name,params[3]);
return (cell)dp;
#endif
}
@ -849,19 +681,14 @@ static cell AMX_NATIVE_CALL amx_close_dir(AMX *amx, cell *params)
{
#if defined WIN32 || defined _WIN32
HANDLE hFile = (HANDLE)((DWORD)params[1]);
if (hFile == INVALID_HANDLE_VALUE || hFile == NULL)
return 0;
FindClose(hFile);
return 1;
#else
DIR *dp = (DIR *)params[1];
if (!dp)
return 0;
closedir(dp);
return 1;
#endif
@ -871,71 +698,64 @@ static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params)
{
#if defined WIN32 || defined _WIN32
HANDLE hFile = (HANDLE)((DWORD)params[1]);
if (hFile == INVALID_HANDLE_VALUE || hFile == NULL)
return 0;
WIN32_FIND_DATA fd;
if (!FindNextFile(hFile, &fd))
return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]);
return 1;
#else
DIR *dp = (DIR *)params[1];
if (!dp)
return 0;
struct dirent *ep = readdir(dp);
if (!ep)
return 0;
set_amxstring(amx, params[2], ep->d_name, params[3]);
set_amxstring(amx,params[2], ep->d_name,params[3]);
return 1;
#endif
}
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},
{"write_file", write_file},
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 },
{ "write_file", write_file },
//Sanji's File Natives
{"fopen", amx_fopen},
{"fclose", amx_fclose},
{"fread", amx_fread},
{"filesize", amx_filesize},
{ "fopen", amx_fopen },
{ "fclose", amx_fclose },
{ "fread", amx_fread },
{ "filesize", amx_filesize },
#ifdef UNUSED
{"fgetc", amx_fgetc},
{"fwrite", amx_fwrite},
{"feof", amx_feof},
{"fseek", amx_fseek},
{"fputc", amx_fputc},
{"rewind", amx_rewind},
{"fflush", amx_fflush},
{"fscanf", amx_fscanf},
{"ftell", amx_ftell},
{"fgetl", amx_fgetl},
{"fgeti", amx_fgeti},
{"fgets", amx_fgets},
{"fputs", amx_fputs},
{"fputl", amx_fputl},
{"fputi", amx_fputi},
{"fgetf", amx_fgetf},
{"fputf", amx_fputf},
{ "fgetc", amx_fgetc },
{ "fwrite", amx_fwrite },
{ "feof", amx_feof },
{ "fseek", amx_fseek },
{ "fputc", amx_fputc },
{ "rewind", amx_rewind },
{ "fflush", amx_fflush },
{ "fscanf", amx_fscanf },
{ "ftell", amx_ftell },
{ "fgetl", amx_fgetl },
{ "fgeti", amx_fgeti },
{ "fgets", amx_fgets },
{ "fputs", amx_fputs },
{ "fputl", amx_fputl },
{ "fputi", amx_fputi },
{ "fgetf", amx_fgetf },
{ "fputf", amx_fputf },
#endif
{"unlink", delete_file},
{"build_pathname", amx_build_pathname},
{"dir_exists", dir_exists},
{"open_dir", amx_open_dir},
{"close_dir", amx_close_dir},
{"next_file", amx_get_dir},
{NULL, NULL}
{ "unlink", delete_file },
{ "build_pathname", amx_build_pathname},
{ "dir_exists", dir_exists },
{ "open_dir", amx_open_dir },
{ "close_dir", amx_close_dir },
{ "next_file", amx_get_dir },
{ NULL, NULL }
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -49,6 +49,5 @@
#define STATIC_MODULE 1
int CheckModules(AMX *amx, char error[128]);
const char *StrCaseStr(const char *as, const char *bs);
#endif // __MODULES_H__

View File

@ -42,13 +42,12 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="..\JIT\natives-x86.obj ..\zlib\zlib.lib"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib"
OutputFile="debug/amxmodx_mm.dll"
Version="0.1"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\extra\lib_win32"
IgnoreDefaultLibraryNames="MSVCRT"
ModuleDefinitionFile=""
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\debug/amxx_mm.pdb"
@ -113,12 +112,11 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib ..\JIT\natives-x86.obj"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib"
OutputFile="release/amxmodx_mm.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\extra\lib_win32"
IgnoreDefaultLibraryNames="LIBC"
ModuleDefinitionFile=""
ProgramDatabaseFile=".\release/amxx_mm.pdb"
ImportLibrary=".\release/amxx_mm.lib"/>
@ -181,13 +179,12 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib ..\JIT\natives-x86.obj"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib"
OutputFile="memtestdebug/amxmodx_mm.dll"
Version="0.1"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\extra\lib_win32"
IgnoreDefaultLibraryNames="MSVCRT"
ModuleDefinitionFile=""
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\memtestdebug/amxx_mm.pdb"
@ -252,12 +249,11 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib ..\JIT\natives-x86.obj"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib"
OutputFile="memtestrelease/amxmodx_mm.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\extra\lib_win32"
IgnoreDefaultLibraryNames="LIBC"
ModuleDefinitionFile=""
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\memtestrelease/amxx_mm.pdb"
@ -375,7 +371,6 @@
GlobalOptimizations="TRUE"
InlineFunctionExpansion="1"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
AdditionalIncludeDirectories="..\..\metamod\metamod,..\..\hlsdk\sourcecode\common,..\..\hlsdk\sourcecode\engine,..\..\hlsdk\sourcecode\dlls,..\..\hlsdk\sourcecode\pm_shared,..\extra\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;amxmodx_EXPORTS;JIT;ASM32;PAWN_CELL_SIZE=32"
IgnoreStandardIncludePath="FALSE"
@ -467,12 +462,11 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="..\zlib\zlib.lib ..\JIT\amxjitsn.obj ..\JIT\amxexecn.obj ..\JIT\natives-x86.obj"
AdditionalDependencies="..\zlib\zlib.lib ..\JIT\amxjitsn.obj ..\JIT\amxexecn.obj"
OutputFile="jitmemtestrelease/amxmodx_mm.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\extra\lib_win32"
IgnoreDefaultLibraryNames="MSVCRT"
ModuleDefinitionFile=""
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\jitmemtestrelease/amxx_mm.pdb"
@ -640,9 +634,6 @@
<File
RelativePath="..\CVault.cpp">
</File>
<File
RelativePath="..\debugger.cpp">
</File>
<File
RelativePath="..\emsg.cpp">
</File>
@ -801,9 +792,6 @@
<File
RelativePath="..\CVector.h">
</File>
<File
RelativePath="..\debugger.h">
</File>
<File
RelativePath="..\fakemeta.h">
</File>
@ -849,25 +837,6 @@
RelativePath="..\version.rc">
</File>
</Filter>
<Filter
Name="Assembly"
Filter="">
<File
RelativePath="..\amxdefn.asm">
</File>
<File
RelativePath="..\amxexecn.asm">
</File>
<File
RelativePath="..\amxjitsn.asm">
</File>
<File
RelativePath="..\natives-amd64.asm">
</File>
<File
RelativePath="..\natives-x86.asm">
</File>
</Filter>
</Files>
<Globals>
</Globals>

View File

@ -95,6 +95,4 @@ _amxx_DynaCodesize:
pop ebp
ret
section .data
GLOBAL_GATE DD 0

View File

@ -29,14 +29,13 @@
*/
#include "amxmodx.h"
#include <malloc.h>
#include <stdlib.h>
#include "CStack.h"
#include "natives.h"
#ifdef __linux__
#include <malloc.h>
#include <stdlib.h>
#include <sys/mman.h>
#include "sclinux.h"
#endif
//Written by David "BAILOPAN" Anderson
@ -266,7 +265,8 @@ static cell AMX_NATIVE_CALL get_array(AMX *amx, cell *params)
int size = params[3];
memcpy(dest, source, size * sizeof(cell));
while (size-->0)
*dest = *source;
return 1;
}
@ -292,7 +292,8 @@ static cell AMX_NATIVE_CALL set_array(AMX *amx, cell *params)
int size = params[3];
memcpy(dest, source, size * sizeof(cell));
while (size-->0)
*dest = *source;
return 1;
}
@ -407,7 +408,7 @@ void ClearPluginLibraries()
for (size_t i=0; i<g_RegNatives.size(); i++)
{
delete [] g_RegNatives[i]->pfn;
delete g_RegNatives[i]->pfn;
delete g_RegNatives[i];
}
g_RegNatives.clear();
@ -422,7 +423,7 @@ AMX_NATIVE_INFO g_NativeNatives[] = {
{"get_param", get_param},
{"get_param_byref", get_param_byref},
{"set_param_byref", set_param_byref},
{"get_array", get_array},
{"get_array", set_array},
{"set_array", set_array},
//these are dummy functions for floats ;p
{"get_param_f", get_param},

View File

@ -1,33 +1,3 @@
/* AMX Mod X
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* 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,
* 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,
* 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
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
#include "amxmodx.h"
#include "newmenus.h"
@ -35,9 +5,8 @@ CVector<Menu *> g_NewMenus;
void ClearMenus()
{
for (size_t i = 0; i < g_NewMenus.size(); i++)
for (size_t i=0; i<g_NewMenus.size(); i++)
delete g_NewMenus[i];
g_NewMenus.clear();
}
@ -50,9 +19,8 @@ Menu::Menu(const char *title, int mid, int tid)
Menu::~Menu()
{
for (size_t i = 0; i < m_Items.size(); i++)
for (size_t i=0; i<m_Items.size(); i++)
delete m_Items[i];
m_Items.clear();
}
@ -112,21 +80,16 @@ 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)
return MENU_MORE;
else
return MENU_EXIT;
}
else if (key == rem + 1)
{
} else if (key == rem+1) {
return MENU_EXIT;
}
}
else if (page == pages - 1)
{
} else if (page == pages - 1) {
//find number of remaining items
//for example, 11 items on page 1... means start=7, 11-7=4
item_t rem = numItems - start;
@ -134,18 +97,14 @@ int Menu::PagekeyToItem(page_t page, item_t key)
if (key == rem)
{
return MENU_EXIT;
}
else if (key == rem + 1)
{
} else if (key == rem+1) {
return MENU_BACK;
}
} else {
if (key == 7)
{
return MENU_MORE;
}
else if (key == 8)
{
} else if (key == 8) {
return MENU_BACK;
}
}
@ -188,10 +147,9 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
char buffer[255];
if (g_coloredmenus)
_snprintf(buffer, sizeof(buffer)-1, "\\y%s %d/%d\n\\w\n", m_Title.c_str(), page + 1, pages);
_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);
_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;
@ -204,19 +162,15 @@ 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++)
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);
@ -225,7 +179,6 @@ 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);
@ -234,7 +187,6 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
else if (ret == ITEM_DISABLED)
enabled = false;
}
if (enabled)
{
keys |= (1<<option);
@ -250,7 +202,6 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
}
m_Text.append(buffer);
}
//now for a weird part >:o
//this will either be MORE or BACK..
keys |= (1<<option++);
@ -260,9 +211,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
} else {
_snprintf(buffer, sizeof(buffer)-1, "%d. %s\n", option, "Exit");
}
m_Text.append(buffer);
if (pages > 1)
{
keys |= (1<<option++);
@ -292,7 +241,6 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params)
char *handler = get_amxstring(amx, params[2], 1, len);
int func = registerSPForwardByName(amx, handler, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
if (func == -1)
{
LogError(amx, AMX_ERR_NOTFOUND, "Invalid function \"%s\"", handler);
@ -300,7 +248,7 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params)
}
int id = g_menucmds.registerMenuId(title, amx);
g_menucmds.registerMenuCmd(g_plugins.findPluginFast(amx), id, 1023, func);
g_menucmds.registerMenuCmd( g_plugins.findPluginFast(amx), id, 1023, func );
Menu *pMenu = new Menu(title, id, (int)g_NewMenus.size());
g_NewMenus.push_back(pMenu);
@ -415,58 +363,6 @@ static cell AMX_NATIVE_CALL menu_makecallback(AMX *amx, cell *params)
return id;
}
static cell AMX_NATIVE_CALL menu_item_setname(AMX *amx, cell *params)
{
GETMENU(params[1]);
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
if (!pItem)
return 0;
int len;
char *name;
name = get_amxstring(amx, params[3], 0, len);
pItem->name.assign(name);
return 1;
}
static cell AMX_NATIVE_CALL menu_item_setcmd(AMX *amx, cell *params)
{
GETMENU(params[1]);
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
if (!pItem)
return 0;
int len;
char *cmd;
cmd = get_amxstring(amx, params[3], 0, len);
pItem->cmd.assign(cmd);
return 1;
}
static cell AMX_NATIVE_CALL menu_item_setcall(AMX *amx, cell *params)
{
GETMENU(params[1]);
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
if (!pItem)
return 0;
pItem->handler = params[3];
return 1;
}
AMX_NATIVE_INFO g_NewMenuNatives[] =
{
{"menu_create", menu_create},
@ -477,8 +373,5 @@ AMX_NATIVE_INFO g_NewMenuNatives[] =
{"menu_find_id", menu_find_id},
{"menu_item_getinfo", menu_item_getinfo},
{"menu_makecallback", menu_makecallback},
{"menu_item_setcall", menu_item_setcall},
{"menu_item_setcmd", menu_item_setcmd},
{"menu_item_setname", menu_item_setname},
{NULL, NULL},
};

View File

@ -1,34 +1,3 @@
/* AMX Mod X
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* 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,
* 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,
* 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
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
#ifndef _INCLUDE_NEWMENUS_H
#define _INCLUDE_NEWMENUS_H
@ -47,10 +16,8 @@ struct menuitem
{
String name;
String cmd;
int access;
int handler;
MENUITEM_CALLBACK pfn;
size_t id;
};
@ -64,23 +31,18 @@ class Menu
public:
Menu(const char *title, int menuId, int thisId);
~Menu();
menuitem *GetMenuItem(item_t item);
size_t GetPageCount();
size_t GetItemCount();
menuitem *AddItem(const char *name, const char *cmd, int access);
const char *GetTextString(int player, page_t page, int &keys);
bool Display(int player, page_t page);
int PagekeyToItem(page_t page, item_t key);
int GetMenuMenuid();
private:
CVector<menuitem * > m_Items;
String m_Title;
String m_Text;
int menuId;
int thisId;
};

View File

@ -45,6 +45,8 @@
enginefuncs_t g_engfuncs;
globalvars_t *gpGlobals;
DLL_FUNCTIONS *g_pFunctionTable;
DLL_FUNCTIONS *g_pFunctionTable_Post;
enginefuncs_t *g_pengfuncsTable;
@ -52,6 +54,7 @@ enginefuncs_t *g_pengfuncsTable_Post;
NEW_DLL_FUNCTIONS *g_pNewFunctionsTable;
NEW_DLL_FUNCTIONS *g_pNewFunctionsTable_Post;
// GetEntityAPI2 functions
static DLL_FUNCTIONS g_EntityAPI_Table =
{
@ -2478,11 +2481,9 @@ PFN_IS_PLAYER_CONNECTING g_fn_IsPlayerConnecting;
PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
#ifdef MEMORY_TEST
PFN_ALLOCATOR g_fn_Allocator;
PFN_REALLOCATOR g_fn_Reallocator;
PFN_DEALLOCATOR g_fn_Deallocator;
#endif
PFN_AMX_EXEC g_fn_AmxExec;
PFN_AMX_EXECV g_fn_AmxExecv;
PFN_AMX_ALLOT g_fn_AmxAllot;
@ -2612,12 +2613,10 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
REQFUNC("GetPlayerEdict", g_fn_GetPlayerEdict, PFN_GET_PLAYER_EDICT);
REQFUNC("amx_Push", g_fn_AmxPush, PFN_AMX_PUSH);
#ifdef MEMORY_TEST
// Memory
REQFUNC_OPT("Allocator", g_fn_Allocator, PFN_ALLOCATOR);
REQFUNC_OPT("Reallocator", g_fn_Reallocator, PFN_REALLOCATOR);
REQFUNC_OPT("Deallocator", g_fn_Deallocator, PFN_DEALLOCATOR);
#endif
REQFUNC("CellToReal", g_fn_CellToReal, PFN_CELL_TO_REAL);
REQFUNC("RealToCell", g_fn_RealToCell, PFN_REAL_TO_CELL);
@ -2736,8 +2735,6 @@ void ValidateMacros_DontCallThis_Smiley()
}
#endif
#ifdef MEMORY_TEST
/************* MEMORY *************/
// undef all defined macros
#undef new
@ -2909,30 +2906,6 @@ void operator delete[](void *reportedAddress)
Mem_Deallocator(g_Mem_CurrentFilename, g_Mem_CurrentLine, g_Mem_CurrentFunc, m_alloc_delete_array, reportedAddress);
}
#else
#if !defined NO_ALLOC_OVERRIDES && !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 delete(void * ptr) {
if(ptr)
free(ptr);
}
void ::operator delete[](void * ptr) {
if(ptr)
free(ptr);
}
#endif
#endif //MEMORY_TEST
/************* stuff from dlls/util.cpp *************/
// must come here because cbase.h declares it's own operator new

View File

@ -46,6 +46,8 @@ struct amxx_module_info_s
const char *logtag; // added in version 2
};
// return values from functions called by amxx
#define AMXX_OK 0 /* no error */
#define AMXX_IFVERS 1 /* interface version */
@ -1979,14 +1981,12 @@ typedef edict_t * (*PFN_GET_PLAYER_EDICT) (int /*id*/);
typedef void * (*PFN_GET_PLAYER_EDICT) (int /*id*/);
#endif
#ifdef MEMORY_TEST
typedef void * (*PFN_ALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const size_t /*size*/);
typedef void * (*PFN_REALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const size_t /*size*/, void* /*addr*/ );
typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const void* /*addr*/ );
#endif
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
@ -2048,6 +2048,7 @@ extern PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
extern PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
extern PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
extern PFN_AMX_EXEC g_fn_AmxExec;
extern PFN_AMX_EXECV g_fn_AmxExecv;
extern PFN_AMX_ALLOT g_fn_AmxAllot;
extern PFN_AMX_FINDPUBLIC g_fn_AmxFindPublic;
extern PFN_LOAD_AMXSCRIPT g_fn_LoadAmxScript;
@ -2192,7 +2193,6 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...);
#define MF_RequestFunction g_fn_RequestFunction;
#define MF_AmxPush g_fn_AmxPush
#ifdef MEMORY_TEST
/*** Memory ***/
void *operator new(size_t reportedSize);
void *operator new[](size_t reportedSize);
@ -2236,6 +2236,4 @@ void Mem_Deallocator(const char *sourceFile, const unsigned int sourceLine, cons
#define realloc(ptr,sz) Mem_Reallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_realloc,sz,ptr)
#define free(ptr) Mem_Deallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_free,ptr)
#endif //MEMORY_TEST
#endif // #ifndef __AMXXMODULE_H__

View File

@ -21,23 +21,13 @@
// metamod plugin?
// #define USE_METAMOD
// use memory manager/tester?
// note that if you use this, you cannot construct/allocate
// anything before the module attached (OnAmxxAttach).
// be careful of default constructors using new/malloc!
// #define MEMORY_TEST
// Unless you use STL or exceptions, keep this commented.
// It allows you to compile without libstdc++.so as a dependency
// #define NO_ALLOC_OVERRIDES
// - AMXX Init functions
// Also consider using FN_META_*
// AMXX query
//#define FN_AMXX_QUERY OnAmxxQuery
// AMXX attach
// Do native functions init here (MF_AddNatives)
//#define FN_AMXX_ATTACH OnAmxxAttach
// #define FN_AMXX_ATTACH OnAmxxAttach
// AMXX detach
//#define FN_AMXX_DETACH OnAmxxDetach
// All plugins loaded

View File

@ -31,28 +31,34 @@
#include "amxmodx.h"
void amx_command()
{
void amx_command(){
const char* cmd = CMD_ARGV(1);
if (!strcmp(cmd, "plugins") || !strcmp(cmd, "list"))
if (!strcmp(cmd,"plugins") || !strcmp(cmd,"list"))
{
print_srvconsole("Currently loaded plugins:\n");
print_srvconsole(" %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s\n", "name", "version", "author", "file", "status");
print_srvconsole( "Currently loaded plugins:\n");
print_srvconsole( " %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s\n",
"name","version","author","file","status");
int plugins = 0;
int running = 0;
CPluginMngr::iterator a = g_plugins.begin();
while (a)
{
++plugins;
if ((*a).isValid() && !(*a).isPaused())
if ( (*a).isValid() && !(*a).isPaused() )
++running;
print_srvconsole(" [%3d] %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s\n", plugins, (*a).getTitle(), (*a).getVersion(), (*a).getAuthor(), (*a).getName(), (*a).getStatus());
print_srvconsole( " [%3d] %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s\n",
plugins,(*a).getTitle(),(*a).getVersion(),
(*a).getAuthor(), (*a).getName(), (*a).getStatus() );
++a;
}
@ -60,7 +66,7 @@ void amx_command()
while (a)
{
if ((*a).getStatusCode() == ps_bad_load)
if ( (*a).getStatusCode() == ps_bad_load )
{
//error
print_srvconsole("Load fails: %s\n", (*a).getError());
@ -68,111 +74,118 @@ void amx_command()
++a;
}
print_srvconsole("%d plugins, %d running\n", plugins, running);
print_srvconsole( "%d plugins, %d running\n",plugins,running );
}
else if (!strcmp(cmd, "pause") && CMD_ARGC() > 2)
else if (!strcmp(cmd,"pause") && CMD_ARGC() > 2)
{
const char* sPlugin = CMD_ARGV(2);
CPluginMngr::CPlugin *plugin = g_plugins.findPlugin(sPlugin);
if (plugin && plugin->isValid())
if ( plugin && plugin->isValid() )
{
plugin->pausePlugin();
print_srvconsole("Paused plugin \"%s\"\n", plugin->getName());
print_srvconsole("Paused plugin \"%s\"\n",plugin->getName() );
}
else
print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin);
else print_srvconsole("Couldn't find plugin matching \"%s\"\n",sPlugin);
}
else if (!strcmp(cmd, "unpause") && CMD_ARGC() > 2)
else if (!strcmp(cmd,"unpause") && CMD_ARGC() > 2)
{
const char* sPlugin = CMD_ARGV(2);
CPluginMngr::CPlugin *plugin = g_plugins.findPlugin(sPlugin);
if (plugin && plugin->isValid() && plugin->isPaused())
if ( plugin && plugin->isValid() )
{
plugin->unpausePlugin();
print_srvconsole("Unpaused plugin \"%s\"\n", plugin->getName());
print_srvconsole("Unpaused plugin \"%s\"\n",plugin->getName() );
}
else if (!plugin)
else print_srvconsole("Couldn't find plugin matching \"%s\"\n",sPlugin);
}
else if (!strcmp(cmd,"cvars"))
{
print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin);
} else {
print_srvconsole("Plugin %s can't be unpaused right now.", sPlugin);
}
}
else if (!strcmp(cmd, "cvars"))
{
print_srvconsole("Registered cvars:\n");
print_srvconsole(" %-24.23s %-24.23s %-16.15s\n", "name", "value", "plugin");
print_srvconsole( "Registered cvars:\n");
print_srvconsole( " %-24.23s %-24.23s %-16.15s\n",
"name","value","plugin");
int ammount = 0;
for (CList<CCVar>::iterator a = g_cvars.begin(); a; ++a)
for( CList<CCVar>::iterator a = g_cvars.begin(); a ; ++a )
{
print_srvconsole(" [%3d] %-24.23s %-24.23s %-16.15s\n", ++ammount, (*a).getName(), CVAR_GET_STRING((*a).getName()), (*a).getPluginName());
print_srvconsole( " [%3d] %-24.23s %-24.23s %-16.15s\n",++ammount,
(*a).getName() ,CVAR_GET_STRING( (*a).getName() ),(*a).getPluginName() );
}
print_srvconsole("%d cvars\n", ammount);
print_srvconsole( "%d cvars\n",ammount);
}
else if (!strcmp(cmd, "cmds"))
else if ( !strcmp(cmd,"cmds") )
{
print_srvconsole("Registered commands:\n");
print_srvconsole(" %-24.23s %-16.15s %-8.7s %-16.15s\n", "name", "access", "type", "plugin");
print_srvconsole( "Registered commands:\n");
print_srvconsole( " %-24.23s %-16.15s %-8.7s %-16.15s\n",
"name","access" ,"type" ,"plugin");
int ammount = 0;
char access[32];
CmdMngr::iterator a = g_commands.begin(CMD_ConsoleCommand);
CmdMngr::iterator a = g_commands.begin( CMD_ConsoleCommand );
while (a)
while( a )
{
UTIL_GetFlags(access, (*a).getFlags());
print_srvconsole(" [%3d] %-24.23s %-16.15s %-8.7s %-16.15s\n", ++ammount, (*a).getCmdLine(), access, (*a).getCmdType(), (*a).getPlugin()->getName());
UTIL_GetFlags( access , (*a).getFlags() );
print_srvconsole( " [%3d] %-24.23s %-16.15s %-8.7s %-16.15s\n",
++ammount,(*a).getCmdLine() , access , (*a).getCmdType() , (*a).getPlugin()->getName());
++a;
}
print_srvconsole("%d commands\n",ammount);
print_srvconsole( "%d commands\n",ammount);
}
else if (!strcmp(cmd, "version"))
else if (!strcmp(cmd,"version"))
{
print_srvconsole("%s %s\n", Plugin_info.name, Plugin_info.version);
print_srvconsole("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);
print_srvconsole("Compiled: %s\n", __DATE__ ", " __TIME__);
print_srvconsole( "%s %s\n", Plugin_info.name, Plugin_info.version);
print_srvconsole( "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);
print_srvconsole( "Compiled: %s\n", __DATE__ ", " __TIME__);
#if defined JIT && !defined ASM32
print_srvconsole("Core mode: JIT Only\n");
print_srvconsole( "Core mode: JIT Only\n");
#elif !defined JIT && defined ASM32
print_srvconsole("Core mode: ASM32 Only\n");
print_srvconsole( "Core mode: ASM32 Only\n");
#elif defined JIT && defined ASM32
print_srvconsole("Core mode: JIT+ASM32\n");
print_srvconsole( "Core mode: JIT+ASM32\n");
#else
print_srvconsole("Core mode: Normal\n");
print_srvconsole( "Core mode: Normal\n");
#endif
}
else if (!strcmp(cmd, "modules"))
else if (!strcmp(cmd,"modules"))
{
print_srvconsole("Currently loaded modules:\n");
print_srvconsole(" %-23.22s %-8.7s %-20.19s %-11.10s\n", "name", "version", "author", "status");
print_srvconsole( "Currently loaded modules:\n");
print_srvconsole( " %-23.22s %-8.7s %-20.19s %-11.10s\n",
"name", "version", "author", "status");
int running = 0;
int modules = 0;
CList<CModule,const char *>::iterator a = g_modules.begin();
while (a)
while ( a )
{
if ((*a).getStatusValue() == MODULE_LOADED)
if ( (*a).getStatusValue() == MODULE_LOADED )
++running;
++modules;
print_srvconsole(" [%2d] %-23.22s %-8.7s %-20.19s %-11.10s\n", modules, (*a).getName(), (*a).getVersion(), (*a).getAuthor(), (*a).getStatus());
print_srvconsole( " [%2d] %-23.22s %-8.7s %-20.19s %-11.10s\n", modules,
(*a).getName(), (*a).getVersion(), (*a).getAuthor() , (*a).getStatus() );
++a;
}
print_srvconsole("%d modules, %d correct\n", modules, running);
}
else if (!strcmp(cmd, "gpl"))
print_srvconsole( "%d modules, %d correct\n",modules,running);
} else if (!strcmp(cmd, "gpl"))
{
print_srvconsole("AMX Mod X\n");
print_srvconsole("\n");
@ -229,7 +242,11 @@ void amx_command()
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3A\x78\x78\x24\x40\x4E\x4E\x4D\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5E\x3E\x3E\x3F\x3E\x3E\x3E\x3E\x3B\x3B\x3B\x3A\x3A\x3F\x3E\x3A\x2E\x2E\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2E\x45\x4D\x40\x45\x78\x5E\x33\x68\x33\x2B\n");
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x24\x48\x45\x48\x78\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x4E\x40\x2B\x66\x33\x78\x20\x20\n");
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x2C\x20\x3A\x20\x20\n");
} else {
}
else
{
print_srvconsole("Usage: amxx < command > [ argument ]\n");
print_srvconsole("Commands:\n");
print_srvconsole(" version - display amxx version info\n");
@ -240,9 +257,11 @@ void amx_command()
print_srvconsole(" cmds - list commands registered by plugins\n");
print_srvconsole(" pause < plugin > - pause a running plugin\n");
print_srvconsole(" unpause < plugin > - unpause a previously paused plugin\n");
}
}
void plugin_srvcmd()
{
cell ret = 0;
@ -250,12 +269,13 @@ void plugin_srvcmd()
CmdMngr::iterator a = g_commands.srvcmdbegin();
while (a)
while ( a )
{
if ((*a).matchCommand(cmd) && (*a).getPlugin()->isExecutable((*a).getFunction()))
if ( (*a).matchCommand( cmd ) &&
(*a).getPlugin()->isExecutable( (*a).getFunction() ) )
{
cell ret = executeForwards((*a).getFunction(), g_srvindex, (*a).getFlags(), (*a).getId());
if (ret) break;
if ( ret ) break;
}
++a;
}

File diff suppressed because it is too large Load Diff

View File

@ -30,10 +30,11 @@
*/
#include <time.h>
#include "amxmodx.h"
#ifdef __linux__
#define _vsnprintf vsnprintf
#define _vsnprintf vsnprintf
#endif
char *UTIL_VarArgs(const char *fmt, ...)
@ -51,26 +52,21 @@ char *UTIL_VarArgs(const char *fmt, ...)
int UTIL_ReadFlags(const char* c)
{
int flags = 0;
while (*c)
flags |= (1<<(*c++ - 'a'));
while (*c) flags |= ( 1 << ( *c++ - 'a' ) );
return flags;
}
void UTIL_GetFlags(char* f, int a)
void UTIL_GetFlags(char* f,int a)
{
for (int i = 'a'; i <= 'z'; ++i)
{
if (a & 1) *f++ = i;
for(int i='a';i<='z';++i){
if ( a & 1 ) *f++ = i;
a >>= 1;
}
*f = 0;
}
/* warning - don't pass here const string */
void UTIL_ShowMenu(edict_t* pEdict, int slots, int time, char *menu, int mlen)
void UTIL_ShowMenu( edict_t* pEdict, int slots, int time, char *menu, int mlen )
{
char *n = menu;
char c = 0;
@ -79,19 +75,17 @@ void UTIL_ShowMenu(edict_t* pEdict, int slots, int time, char *menu, int mlen)
if (!gmsgShowMenu)
return; // some games don't support ShowMenu (Firearms)
while (*n)
{
while ( *n ) {
a = mlen;
if (a > 175) a = 175;
if ( a > 175 ) a = 175;
mlen -= a;
c = *(n+=a);
*n = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgShowMenu, NULL, pEdict);
WRITE_SHORT(slots);
WRITE_CHAR(time);
WRITE_BYTE(c ? TRUE : FALSE);
WRITE_STRING(menu);
MESSAGE_BEGIN( MSG_ONE , gmsgShowMenu, NULL, pEdict );
WRITE_SHORT( slots );
WRITE_CHAR( time );
WRITE_BYTE( c ? TRUE : FALSE);
WRITE_STRING( menu );
MESSAGE_END();
*n = c;
menu = n;
@ -99,14 +93,14 @@ void UTIL_ShowMenu(edict_t* pEdict, int slots, int time, char *menu, int mlen)
}
/* warning - don't pass here const string */
void UTIL_ShowMOTD(edict_t *client, char *motd, int mlen, const char *name)
void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name)
{
if (!gmsgMOTD)
return; // :TODO: Maybe output a warning log?
if (gmsgServerName)
{
MESSAGE_BEGIN(MSG_ONE, gmsgServerName, NULL, client);
MESSAGE_BEGIN( MSG_ONE , gmsgServerName, NULL, client );
WRITE_STRING(name);
MESSAGE_END();
}
@ -115,17 +109,15 @@ void UTIL_ShowMOTD(edict_t *client, char *motd, int mlen, const char *name)
char c = 0;
int a;
while (*n)
{
while ( *n ) {
a = mlen;
if (a > 175) a = 175;
if ( a > 175 ) a = 175;
mlen -= a;
c = *(n += a);
c = *(n+=a);
*n = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgMOTD, NULL, client);
WRITE_BYTE(c ? FALSE : TRUE);
WRITE_STRING(motd);
MESSAGE_BEGIN( MSG_ONE , gmsgMOTD, NULL, client );
WRITE_BYTE( c ? FALSE : TRUE );
WRITE_STRING( motd );
MESSAGE_END();
*n = c;
motd = n;
@ -133,52 +125,42 @@ void UTIL_ShowMOTD(edict_t *client, char *motd, int mlen, const char *name)
if (gmsgServerName)
{
MESSAGE_BEGIN(MSG_ONE, gmsgServerName, NULL, client);
WRITE_STRING(hostname->string);
MESSAGE_BEGIN( MSG_ONE , gmsgServerName, NULL, client );
WRITE_STRING( hostname->string );
MESSAGE_END();
}
}
void UTIL_IntToString(int value, char *output)
{
static const char *words[] =
{"zero ","one ","two ","three ","four ",
static const char *words[] = {"zero ","one ","two ","three ","four ",
"five ", "six ","seven ","eight ","nine ","ten ",
"eleven ","twelve ","thirteen ","fourteen ","fifteen ",
"sixteen ","seventeen ","eighteen ","nineteen ",
"twenty ","thirty ","fourty ", "fifty ","sixty ",
"seventy ","eighty ","ninety ",
"hundred ","thousand "};
*output = 0;
if (value < 0) value = -value;
int tho = value / 1000;
int aaa = 0;
if (tho)
{
aaa += sprintf(&output[aaa], words[tho]);
aaa += sprintf(&output[aaa], words[29]);
if (tho){
aaa += sprintf(&output[aaa], words[ tho ] );
aaa += sprintf(&output[aaa], words[29] );
value = value % 1000;
}
int hun = value / 100;
if (hun)
{
aaa += sprintf(&output[aaa], words[hun]);
aaa += sprintf(&output[aaa], words[28]);
if (hun) {
aaa += sprintf(&output[aaa], words[ hun ] );
aaa += sprintf(&output[aaa], words[28] );
value = value % 100;
}
int ten = value / 10;
int unit = value % 10;
if (ten)
aaa += sprintf(&output[aaa], words[(ten > 1) ? (ten + 18) : (unit + 10)]);
if (ten != 1 && (unit || (!value && !hun && !tho)))
sprintf(&output[aaa], words[unit]);
if ( ten )
aaa += sprintf(&output[aaa], words[ ( ten > 1 ) ? ( ten + 18 ) : ( unit + 10 ) ] );
if ( ten != 1 && ( unit || (!value && !hun && !tho) ) )
sprintf(&output[aaa], words[ unit ] );
}
char* UTIL_SplitHudMessage(const char *src)
@ -186,57 +168,50 @@ char* UTIL_SplitHudMessage(const char *src)
static char message[512];
short b = 0, d = 0, e = 0, c = -1;
while (src[d] && e < 480)
{
if (src[d] == ' ')
{
while ( src[ d ] && e < 480 ) {
if ( src[ d ] == ' ' ) {
c = e;
}
else if (src[d] == '\n')
{
else if ( src[ d ] == '\n' ) {
c = -1;
b = 0;
}
message[e++] = src[d++];
if (++b == 69)
{
if (c == -1)
{
message[e++] = '\n';
message[ e++ ] = src[ d++ ];
if ( ++b == 69 ) {
if ( c == -1 ) {
message[ e++ ] = '\n';
b = 0;
} else {
message[c] = '\n';
}
else {
message[ c ] = '\n';
b = e - c - 1;
c = -1;
}
}
}
message[e] = 0;
message[ e ] = 0;
return message;
}
unsigned short FixedUnsigned16(float value, float scale)
unsigned short FixedUnsigned16( float value, float scale )
{
int output = (int)(value * scale);
if (output < 0)
if ( output < 0 )
output = 0;
else if (output > 0xFFFF)
else if ( output > 0xFFFF )
output = 0xFFFF;
return (unsigned short)output;
}
short FixedSigned16(float value, float scale)
short FixedSigned16( float value, float scale )
{
int output = (int)(value * scale);
if (output > 32767)
if ( output > 32767 )
output = 32767;
else if (output < -32768)
else if ( output < -32768 )
output = -32768;
return (short)output;
@ -244,15 +219,15 @@ short FixedSigned16(float value, float scale)
void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pMessage)
{
if (pEntity)
MESSAGE_BEGIN(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, pEntity);
if ( pEntity )
MESSAGE_BEGIN( MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, pEntity );
else
MESSAGE_BEGIN(MSG_BROADCAST, SVC_TEMPENTITY);
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE(29);
WRITE_BYTE(textparms.channel & 0xFF);
WRITE_SHORT(FixedSigned16(textparms.x, (1<<13)));
WRITE_SHORT(FixedSigned16(textparms.y, (1<<13)));
WRITE_SHORT(FixedSigned16(textparms.x, (1<<13) ));
WRITE_SHORT(FixedSigned16(textparms.y, (1<<13) ));
WRITE_BYTE(textparms.effect);
WRITE_BYTE(textparms.r1);
WRITE_BYTE(textparms.g1);
@ -262,34 +237,30 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pM
WRITE_BYTE(255);
WRITE_BYTE(250);
WRITE_BYTE(0);
WRITE_SHORT(FixedUnsigned16(textparms.fadeinTime, (1<<8)));
WRITE_SHORT(FixedUnsigned16(textparms.fadeoutTime, (1<<8)));
WRITE_SHORT(FixedUnsigned16(textparms.holdTime, (1<<8)));
if (textparms.effect == 2)
WRITE_SHORT(FixedUnsigned16(textparms.fxTime, (1<<8)));
WRITE_SHORT(FixedUnsigned16(textparms.fadeinTime, (1<<8) ));
WRITE_SHORT(FixedUnsigned16(textparms.fadeoutTime, (1<<8) ));
WRITE_SHORT(FixedUnsigned16(textparms.holdTime, (1<<8) ));
if (textparms.effect==2)
WRITE_SHORT(FixedUnsigned16(textparms.fxTime, (1<<8) ) );
WRITE_STRING(pMessage);
MESSAGE_END();
}
/* warning - buffer of msg must be longer than 190 chars!
(here in AMX it is always longer) */
void UTIL_ClientPrint(edict_t *pEntity, int msg_dest, char *msg)
void UTIL_ClientPrint( edict_t *pEntity, int msg_dest, char *msg )
{
if (!gmsgTextMsg)
return; // :TODO: Maybe output a warning log?
char c = msg[190];
msg[190] = 0; // truncate without checking with strlen()
if (pEntity)
MESSAGE_BEGIN(MSG_ONE, gmsgTextMsg, NULL, pEntity);
if ( pEntity )
MESSAGE_BEGIN( MSG_ONE, gmsgTextMsg, NULL, pEntity );
else
MESSAGE_BEGIN(MSG_BROADCAST, gmsgTextMsg);
WRITE_BYTE(msg_dest);
WRITE_STRING(msg);
MESSAGE_BEGIN( MSG_BROADCAST , gmsgTextMsg);
WRITE_BYTE( msg_dest );
WRITE_STRING( msg );
MESSAGE_END();
msg[190] = c;
}
@ -333,7 +304,7 @@ void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1,
// store argument
g_fakecmd.argv[1] = arg1;
// build argument line
snprintf(g_fakecmd.args, 255, "%s", arg1);
snprintf( g_fakecmd.args, 255, "%s", arg1);
// if snprintf reached 255 chars limit, this will make sure there will be no access violation
g_fakecmd.args[255] = 0;
}

View File

@ -34,49 +34,52 @@
Vault g_vault;
static cell AMX_NATIVE_CALL set_vaultdata(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL set_vaultdata(AMX *amx,cell *params)
{
int iLen;
g_vault.put(get_amxstring(amx, params[1], 0, iLen), get_amxstring(amx, params[2], 1, iLen));
g_vault.put( get_amxstring(amx,params[1],0,iLen) , get_amxstring(amx,params[2],1,iLen) );
g_vault.saveVault();
return 1;
}
static cell AMX_NATIVE_CALL get_vaultdata(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL get_vaultdata(AMX *amx,cell *params)
{
int iLen;
const char* key = get_amxstring(amx, params[1], 0, iLen);
if (params[3])
return set_amxstring(amx, params[2], g_vault.get(key), params[3]);
const char* key = get_amxstring(amx,params[1],0,iLen);
return g_vault.get_number(key);
if ( params[3] )
return set_amxstring( amx , params[2] , g_vault.get( key ) , params[3] );
return g_vault.get_number( key );
}
static cell AMX_NATIVE_CALL remove_vaultdata(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL remove_vaultdata(AMX *amx,cell *params)
{
int iLen;
g_vault.remove(get_amxstring(amx, params[1], 0, iLen));
g_vault.remove( get_amxstring(amx,params[1],0,iLen) );
g_vault.saveVault();
return 1;
}
static cell AMX_NATIVE_CALL vaultdata_exists(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL vaultdata_exists(AMX *amx,cell *params)
{
int iLen;
return g_vault.exists(get_amxstring(amx, params[1], 0, iLen)) ? 1 : 0;
return g_vault.exists( get_amxstring(amx,params[1],0,iLen) ) ? 1 : 0;
}
AMX_NATIVE_INFO vault_Natives[] =
{
{"set_vaultdata", set_vaultdata},
{"get_vaultdata", get_vaultdata},
{"remove_vaultdata", remove_vaultdata},
{"delete_vaultdata", remove_vaultdata},
{"vaultdata_exists", vaultdata_exists},
{0, 0}
AMX_NATIVE_INFO vault_Natives[] = {
{ "set_vaultdata", set_vaultdata },
{ "get_vaultdata", get_vaultdata },
{ "remove_vaultdata", remove_vaultdata },
{ "delete_vaultdata", remove_vaultdata },
{ "vaultdata_exists", vaultdata_exists },
{ 0, 0 }
};

View File

@ -27,8 +27,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,6,0,0
PRODUCTVERSION 1,6,0,0
FILEVERSION 1,5,0,1
PRODUCTVERSION 1,5,0,1
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -45,12 +45,12 @@ BEGIN
BEGIN
VALUE "Comments", "AMX Mod X"
VALUE "FileDescription", "AMX Mod X"
VALUE "FileVersion", "1.60"
VALUE "FileVersion", "1.50"
VALUE "InternalName", "amxmodx"
VALUE "LegalCopyright", "Copyright (c) 2004-2005, AMX Mod X Dev Team"
VALUE "OriginalFilename", "amxmodx_mm.dll"
VALUE "ProductName", "AMX Mod X"
VALUE "ProductVersion", "1.60"
VALUE "ProductVersion", "1.50-RC1"
END
END
BLOCK "VarFileInfo"

View File

@ -3,14 +3,14 @@
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O3 -funroll-loops -s -pipe
OPT_FLAGS = -O3 -fno-rtti -funroll-loops -s -pipe
DEBUG_FLAGS = -g -ggdb3
CPP = gcc
CPP = g++
BINARY = amxxpc
OBJECTS = amx.cpp amxxpc.cpp Binary.cpp
LINK = -lz /lib/libstdc++.a
LINK = -lz
INCLUDE = -I. -L.
@ -22,7 +22,7 @@ else
CFLAGS = $(OPT_FLAGS)
endif
CFLAGS += -DLINUX -DNDEBUG -Wno-deprecated -fexceptions -DHAVE_STDINT_H -DAMX_ANSIONLY -fno-rtti -static-libgcc
CFLAGS += -DLINUX -DNDEBUG -Wno-deprecated -fexceptions -DHAVE_STDINT_H -DAMX_ANSIONLY
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)

View File

@ -30,11 +30,7 @@ int main(int argc, char **argv)
#endif
#ifdef __linux__
HINSTANCE lib = NULL;
if (FileExists("./amxxpc32.so"))
lib = dlmount("./amxxpc32.so");
else
lib = dlmount("amxxpc32.so");
HINSTANCE lib = dlmount("./amxxpc32.so");
#else
HINSTANCE lib = dlmount("amxxpc32.dll");
#endif
@ -103,18 +99,17 @@ int main(int argc, char **argv)
fclose(fp);
}
dlclose(lib);
unlink(file);
HINSTANCE lib64 = NULL;
HINSTANCE lib64 = 0;
#ifdef __linux__
if (FileExists("./amxxpc64.so"))
lib64 = dlmount("./amxxpc64.so");
else
lib64 = dlmount("amxxpc64.so");
#else
lib64 = dlmount("amxxpc64.dll");
#endif
if (!lib64)
pc_printf = (PRINTF)dlsym(lib64, "pc_printf");
if (!lib64 || !pc_printf)
{
pc_printf("64bit compiler failed to instantiate.\n");
exit(0);
@ -134,8 +129,6 @@ int main(int argc, char **argv)
sc64(argc, argv);
dlclose(lib64);
if (file == NULL)
{
pc_printf("Could not locate the output file on second pass.\n");
@ -214,7 +207,7 @@ int main(int argc, char **argv)
pc_printf("Done.\n");
dlclose(lib);
dlclose(lib64);
exit(0);
}
@ -381,15 +374,3 @@ void show_help()
printf("\t-p<name> set name of \"prefix\" file\n");
printf("\t-r[name] write cross reference report to console or to specified file\n");
}
#ifdef __linux__
bool FileExists(const char *file)
{
FILE *fp = fopen(file, "rb");
if (!fp)
return false;
fclose(fp);
return true;
}
#endif

View File

@ -1,7 +1,7 @@
#ifndef _AMXXSC_INCLUDE_H
#define _AMXXSC_INCLUDE_H
#define VERSION_STRING "1.60-300"
#define VERSION_STRING "1.50-300"
#define VERSION 03000
#define MAGIC_HEADER 0x414D5842
#define MAGIC_HEADER2 0x414D5858
@ -67,8 +67,4 @@ struct BinPlugin
int32_t offs; //file offset
};
#ifdef __linux__
bool FileExists(const char *file);
#endif
#endif //_AMXXSC_INCLUDE_H

View File

@ -3,7 +3,7 @@
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O3 -funroll-loops -s -pipe
OPT_FLAGS = -O3 -fno-rtti -funroll-loops -s -pipe
DEBUG_FLAGS = -g -ggdb3
CPP = gcc
NAME = amxxpc
@ -18,14 +18,14 @@ INCLUDE = -I.
ifeq "$(PAWN64)" "true"
BINARY = $(NAME)64.so
BIN_DIR = Release64
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -Dpc_printf=pc_printf64
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64
else
BINARY = $(NAME)32.so
BIN_DIR = Release32
CFLAGS += -DPAWN_CELL_SIZE=32
endif
CFLAGS += -DLINUX -DNDEBUG -fPIC -DHAVE_STDINT_H -DENABLE_BINRELOC -DNO_MAIN -DPAWNC_DLL -static-libgcc
CFLAGS += -DLINUX -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H -DENABLE_BINRELOC -DNO_MAIN -DPAWNC_DLL
CFLAGS += $(OPT_FLAGS)
OBJ_LINUX := $(OBJECTS:%.c=$(BIN_DIR)/%.o)
@ -42,6 +42,9 @@ all:
pawn_make: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
pawn64:
$(MAKE) pawn_make PAWN64=true
debug:
$(MAKE) all DEBUG=true

View File

@ -65,16 +65,12 @@
* purpose messages; errors go through pc_error(). The function is modelled
* after printf().
*/
#if PAWN_CELL_SIZE==32
#if defined __WIN32__ || defined _WIN32 || defined WIN32
__declspec (dllexport)
int pc_printf(const char *message,...)
#else
extern int pc_printf(const char *message,...)
#endif
#else
int pc_printf(const char *message, ...)
#endif
{
#if PAWN_CELL_SIZE==32
int ret;

View File

@ -6,8 +6,6 @@ EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Debug32 = Debug32
Debug64 = Debug64
Release = Release
Release32 = Release32
Release64 = Release64
@ -15,10 +13,6 @@ Global
GlobalSection(ProjectConfiguration) = postSolution
{19B72687-080B-437A-917A-12AEB0031635}.Debug.ActiveCfg = Release|Win32
{19B72687-080B-437A-917A-12AEB0031635}.Debug.Build.0 = Release|Win32
{19B72687-080B-437A-917A-12AEB0031635}.Debug32.ActiveCfg = Debug32|Win32
{19B72687-080B-437A-917A-12AEB0031635}.Debug32.Build.0 = Debug32|Win32
{19B72687-080B-437A-917A-12AEB0031635}.Debug64.ActiveCfg = Debug64|Win32
{19B72687-080B-437A-917A-12AEB0031635}.Debug64.Build.0 = Debug64|Win32
{19B72687-080B-437A-917A-12AEB0031635}.Release.ActiveCfg = Release|Win32
{19B72687-080B-437A-917A-12AEB0031635}.Release.Build.0 = Release|Win32
{19B72687-080B-437A-917A-12AEB0031635}.Release32.ActiveCfg = Release32|Win32

View File

@ -200,104 +200,6 @@
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug32|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBPC300_EXPORTS;PAWNC_DLL;PAWN_CELL_SIZE=32;NO_MAIN"
MinimalRebuild="TRUE"
BasicRuntimeChecks="1"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="FALSE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/amxxpc32.dll"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/libpc300.pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/libpc300.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug64|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBPC300_EXPORTS;PAWNC_DLL;PAWN_CELL_SIZE=64;NO_MAIN"
MinimalRebuild="TRUE"
BasicRuntimeChecks="1"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="FALSE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/amxxpc64.dll"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/libpc300.pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/libpc300.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>

View File

@ -63,12 +63,6 @@
#define PREPROC_TERM '\x7f'/* termination character for preprocessor expressions (the "DEL" code) */
#define sDEF_PREFIX "default.inc" /* default prefix filename */
#if defined WIN32
#define INVISIBLE
#else
#define INVISIBLE __attribute__((visibility("protected")))
#endif
typedef union {
void *pv; /* e.g. a name */
int i;
@ -441,16 +435,12 @@ int pc_enablewarning(int number,int enable);
*/
/* general console output */
#if PAWN_CELL_SIZE==32
#if defined __WIN32__ || defined _WIN32 || defined WIN32
__declspec (dllexport)
int pc_printf(const char *message,...);
#else
extern int pc_printf(const char *message,...);
#endif
#else
int pc_printf(const char *message, ...) INVISIBLE;
#endif
/* error report function */
int pc_error(int number,char *message,char *filename,int firstline,int lastline,va_list argptr);
@ -639,7 +629,11 @@ SC_FUNC void jmp_eq0(int number);
SC_FUNC void outval(cell val,int newline);
/* function prototypes in SC5.C */
SC_FUNC int error(int number,...) INVISIBLE;
#ifdef __linux__
SC_FUNC int error(int number,...) __attribute__((visibility("internal")));
#else
SC_FUNC int error(int number,...)
#endif
SC_FUNC void errorset(int code);
/* function prototypes in SC6.C */

View File

@ -654,6 +654,7 @@ cleanup:
int flag_exceed=0;
if (sc_amxlimit > 0 && (long)(hdrsize+code_idx+glb_declared*sizeof(cell)+sc_stksize*sizeof(cell)) >= sc_amxlimit)
flag_exceed=1;
#if PAWN_CELL_SIZE==32
if ((sc_debug & sSYMBOLIC)!=0 || verbosity>=2 || stacksize+32>=(long)sc_stksize || flag_exceed) {
pc_printf("Header size: %8ld bytes\n", (long)hdrsize);
pc_printf("Code size: %8ld bytes\n", (long)code_idx);
@ -665,6 +666,7 @@ cleanup:
pc_printf("estimated max. usage=%ld cells (%ld bytes)\n",stacksize,stacksize*sizeof(cell));
pc_printf("Total requirements:%8ld bytes\n", (long)hdrsize+(long)code_idx+(long)glb_declared*sizeof(cell)+(long)sc_stksize*sizeof(cell));
} /* if */
#endif
if (flag_exceed)
error(106,sc_amxlimit); /* this causes a jump back to label "cleanup" */
} /* if */
@ -1918,11 +1920,9 @@ static int declloc(int fstatic)
/* Although valid, a local variable whose name is equal to that
* of a global variable or to that of a local variable at a lower
* level might indicate a bug.
* NOTE - don't bother with the error if there's no valid function!
*/
if ((sym=findloc(name))!=NULL && sym->compound!=nestlevel || findglb(name)!=NULL)
if (curfunc!=NULL && (curfunc->usage & uNATIVE))
error(219,name); /* variable shadows another symbol */
if ((sym=findloc(name))!=NULL && sym->compound!=nestlevel || findglb(name)!=NULL);
//error(219,name); /* variable shadows another symbol */
while (matchtoken('[')){
ident=iARRAY;
if (numdim == sDIMEN_MAX) {
@ -3180,7 +3180,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc
if ((sym->usage & (uPROTOTYPED | uREAD))==uREAD && sym->tag!=0) {
int curstatus=sc_status;
sc_status=statWRITE; /* temporarily set status to WRITE, so the warning isn't blocked */
//error(208); //this is silly, it should be caught the first pass
error(208);
sc_status=curstatus;
sc_reparse=TRUE; /* must add another pass to "initial scan" phase */
} /* if */
@ -3645,8 +3645,8 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags,
if (argsym!=NULL) {
error(21,name); /* symbol already defined */
} else {
if ((argsym=findglb(name))!=NULL && argsym->ident!=iFUNCTN && curfunc!=NULL)
error(219,name); /* variable shadows another symbol */
if ((argsym=findglb(name))!=NULL && argsym->ident!=iFUNCTN) ;
//error(219,name); /* variable shadows another symbol */
/* add details of type and address */
assert(numtags>0);
argsym=addvariable(name,offset,ident,sLOCAL,tags[0],

View File

@ -715,6 +715,18 @@ static int ftoi(cell *val,const unsigned char *curptr)
#endif
#elif PAWN_CELL_SIZE==64
*val=*((cell *)&fnum);
#if !defined NDEBUG
/* I assume that the C/C++ compiler stores "double" values in IEEE 754
* format (as mandated in the ANSI standard).
*/
{ float test1 = 0.0, test2 = 50.0, test3 = -50.0;
uint64_t bit = 1;
/* test 0.0 == all bits 0 */
assert(*(uint64_t*)&test1==0x00000000L);
/* test sign & magnitude format */
assert(((*(uint64_t*)&test2) ^ (*(uint64_t*)&test3)) == (bit << (PAWN_CELL_SIZE-1)));
}
#endif
#else
#error Unsupported cell size
#endif
@ -1407,7 +1419,7 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char
int prefixlen;
const unsigned char *p,*s,*e;
unsigned char *args[10];
int match,arg,len,argsnum=0;
int match,arg,len;
memset(args,0,sizeof args);
@ -1447,8 +1459,6 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char
/* store the parameter (overrule any earlier) */
if (args[arg]!=NULL)
free(args[arg]);
else
argsnum++;
len=(int)(e-s);
args[arg]=(unsigned char*)malloc(len+1);
if (args[arg]==NULL)
@ -1505,17 +1515,14 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char
if (match) {
/* calculate the length of the substituted string */
for (e=(unsigned char*)substitution,len=0; *e!='\0'; e++) {
if (*e=='%' && isdigit(*(e+1)) && argsnum) {
if (*e=='%' && isdigit(*(e+1))) {
arg=*(e+1)-'0';
assert(arg>=0 && arg<=9);
if (args[arg]!=NULL) {
if (args[arg]!=NULL)
len+=strlen((char*)args[arg]);
e++; /* skip %, digit is skipped later */
} else {
len++;
}
} else {
len++;
} /* if */
} /* for */
/* check length of the string after substitution */
@ -1531,21 +1538,8 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char
if (args[arg]!=NULL) {
strins((char*)s,(char*)args[arg],strlen((char*)args[arg]));
s+=strlen((char*)args[arg]);
e++; /* skip %, digit is skipped later */
} else {
strins((char*)s,(char*)e,1);
s++;
} /* if */
} else if (*e=='"') {
p=e;
if (is_startstring(e)) { /* skip strings */
e=skipstring(e);
strins((char*)s,(char*)p,(e-p+1));
s+=(e-p+1);
} else {
strins((char*)s,(char*)e,1);
s++;
}
e++; /* skip %, digit is skipped later */
} else {
strins((char*)s,(char*)e,1);
s++;
@ -1584,7 +1578,7 @@ static void substallpatterns(unsigned char *line,int buffersize)
if (*start=='\0')
break; /* abort loop on error */
/* if matching the operator "defined", skip it plus the symbol behind it */
if (strncmp((char*)start,"defined",7)==0 && !isalpha((char)*(start+7))) {
if (strncmp((char*)start,"defined",7)==0 && *(start+7)<=' ') {
start+=7; /* skip "defined" */
/* skip white space & parantheses */
while (*start<=' ' && *start!='\0' || *start=='(')
@ -2457,7 +2451,7 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int i
while (ptr!=NULL) {
if (hash==ptr->hash && strcmp(name,ptr->name)==0
&& (ptr->parent==NULL || includechildren)
&& (fnumber<0 || (ptr->fnumber<0 || ptr->fnumber==fnumber)))
&& (ptr->fnumber<0 || ptr->fnumber==fnumber))
return ptr;
ptr=ptr->next;
} /* while */

View File

@ -964,12 +964,8 @@ static int hier14(value *lval1)
check_userop(NULL,lval2.tag,lval3.tag,2,&lval3,&lval2.tag);
store(&lval3); /* now, store the expression result */
} /* if */
if (!oper) { /* tagname mismatch (if "oper", warning already given in plunge2()) */
if (lval3.sym && !matchtag(lval3.sym->tag, lval2.tag, TRUE))
error(213);
else if (!lval3.sym && !matchtag(lval3.tag, lval2.tag, TRUE))
error(213);
}
if (!oper && !matchtag(lval3.tag,lval2.tag,TRUE))
error(213); /* tagname mismatch (if "oper", warning already given in plunge2()) */
if (lval3.sym)
markusage(lval3.sym,uWRITTEN);
sideeffect=TRUE;
@ -2206,8 +2202,7 @@ static int nesting=0;
if ((sym->usage & uNATIVE)==0)
totalsize++; /* add "call" opcode */
totalsize+=nest_stkusage;
if (!curfunc) /* if we got here, the function is invalid! */
return;
assert(curfunc!=NULL);
if (curfunc->x.stacksize<totalsize)
curfunc->x.stacksize=totalsize;
nest_stkusage-=nargs+heapalloc+1; /* stack/heap space, +1 for argcount param */

View File

@ -581,8 +581,6 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
constvalue *constptr;
cell mainaddr;
fcurrent = -1;
/* if compression failed, restart the assembly with compaction switched off */
if (setjmp(compact_err)!=0) {
assert(sc_compress); /* cannot arrive here if compact encoding was disabled */

View File

@ -450,14 +450,9 @@ SC_FUNC stringlist *insert_dbgsymbol(symbol *sym)
#endif
if (sym->ident==iARRAY || sym->ident==iREFARRAY) {
symbol *sub;
#if !defined NDEBUG
count = sym->dim.array.level;
#endif
strcat(string," [ ");
for (sub=sym; sub!=NULL; sub=finddepend(sub)) {
#if !defined NDEBUG
assert(sub->dim.array.level==count--);
#endif
assert(sub->dim.array.level==count++);
sprintf(string+strlen(string),"%x:%x ",sub->x.idxtag,sub->dim.array.length);
} /* for */
strcat(string,"]");

View File

@ -35,7 +35,7 @@ statscfg.amxx ; allows to manage stats plugins via menu and commands
; Counter-Strike
;restmenu.amxx ; restrict weapons menu
statsx.amxx ; stats on death or round end (CSX Module required!)
;statsx.amxx ; stats on death or round end (CSX Module required!)
;miscstats.amxx ; bunch of events announcement for Counter-Strike
;stats_logging.amxx ; weapons stats logging (CSX Module required!)

View File

@ -12,16 +12,16 @@ fun_amxx_amd64.so
; ----------------------------------------------------
; Engine - provides engine functions core to Half-Life
; ----------------------------------------------------
engine_amxx_i386.so
engine_amxx.dll
engine_amxx_amd64.so
;engine_amxx_i386.so
;engine_amxx.dll
;engine_amxx_amd64.so
; ----------------------------------------------------------
; Fakemeta - provides a massive interface into the HL engine
; ----------------------------------------------------------
fakemeta_amxx_i386.so
fakemeta_amxx.dll
fakemeta_amxx_amd64.so
;fakemeta_amxx_i386.so
;fakemeta_amxx.dll
;fakemeta_amxx_amd64.so
; -------------------------------------------
; Database Access - only enable one of these
@ -67,3 +67,10 @@ fakemeta_amxx_amd64.so
;nvault_amxx_i386.so
;nvault_amxx.dll
;nvault_amxx_amd64.so
; --------------------------------------------
; Adds ESF miscellanious and hacking functions
; --------------------------------------------
esfmod_amxx_i386.so
esfmod_amxx.dll
esfmod_amxx_amd64.so

View File

@ -1,39 +0,0 @@
; AMX Mod X plugins
; Admin Base - Always one has to be activated
admin.amxx ; admin base (required for any admin-related)
;admin_sql.amxx ; admin base - SQL version (comment admin.amxx)
; Basic
admincmd.amxx ; basic admin console commands
adminhelp.amxx ; help command for admin console commands
adminslots.amxx ; slot reservation
multilingual.amxx ; Multi-Lingual management
; Menus
menufront.amxx ; front-end for admin menus
cmdmenu.amxx ; command menu (speech, settings)
plmenu.amxx ; players menu (kick, ban, client cmds.)
;telemenu.amxx ; teleport menu (Fun Module required!)
mapsmenu.amxx ; maps menu (vote, changelevel)
; Chat / Messages
adminchat.amxx ; console chat commands
antiflood.amxx ; prevent clients from chat-flooding the server
scrollmsg.amxx ; displays a scrolling message
imessage.amxx ; displays information messages
adminvote.amxx ; vote commands
; Map related
nextmap.amxx ; displays next map in mapcycle
mapchooser.amxx ; allows to vote for next map
timeleft.amxx ; displays time left on map
; Configuration
pausecfg.amxx ; allows to pause and unpause some plugins
statscfg.amxx ; allows to manage stats plugins via menu and commands
; Custom - Add 3rd party plugins here
EvolutionX.Core.amxx ; Adds extra plugin functions for Earth's Special Forces
; (made by the Corona Bytes team of EVM)

View File

@ -6,7 +6,7 @@ MM_ROOT = ../metamod/metamod
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O2 -funroll-loops -s -pipe -fomit-frame-pointer
OPT_FLAGS = -O3 -fno-rtti -funroll-loops -s -pipe
DEBUG_FLAGS = -g -ggdb3
CPP = gcc
NAME = cstrike_amxx
@ -26,11 +26,12 @@ else
CFLAGS = $(OPT_FLAGS)
endif
CFLAGS += -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H -fno-rtti -static-libgcc
CFLAGS += -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H
ifeq "$(AMD64)" "true"
BINARY = $(NAME)_amd64.so
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64
LINK += -lstdc++
else
BINARY = $(NAME)_i386.so
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32

View File

@ -45,6 +45,8 @@
enginefuncs_t g_engfuncs;
globalvars_t *gpGlobals;
DLL_FUNCTIONS *g_pFunctionTable;
DLL_FUNCTIONS *g_pFunctionTable_Post;
enginefuncs_t *g_pengfuncsTable;
@ -52,6 +54,7 @@ enginefuncs_t *g_pengfuncsTable_Post;
NEW_DLL_FUNCTIONS *g_pNewFunctionsTable;
NEW_DLL_FUNCTIONS *g_pNewFunctionsTable_Post;
// GetEntityAPI2 functions
static DLL_FUNCTIONS g_EntityAPI_Table =
{
@ -2478,11 +2481,9 @@ PFN_IS_PLAYER_CONNECTING g_fn_IsPlayerConnecting;
PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
#ifdef MEMORY_TEST
PFN_ALLOCATOR g_fn_Allocator;
PFN_REALLOCATOR g_fn_Reallocator;
PFN_DEALLOCATOR g_fn_Deallocator;
#endif
PFN_AMX_EXEC g_fn_AmxExec;
PFN_AMX_EXECV g_fn_AmxExecv;
PFN_AMX_ALLOT g_fn_AmxAllot;
@ -2501,7 +2502,6 @@ PFN_GET_PLAYER_EDICT g_fn_GetPlayerEdict;
PFN_FORMAT g_fn_Format;
PFN_REGISTERFUNCTION g_fn_RegisterFunction;
PFN_REQ_FNPTR g_fn_RequestFunction;
PFN_AMX_PUSH g_fn_AmxPush;
// *** Exports ***
C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo)
@ -2610,14 +2610,11 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
REQFUNC("GetPlayerHealth", g_fn_GetPlayerHealth, PFN_GET_PLAYER_HEALTH);
REQFUNC("GetPlayerFlags", g_fn_GetPlayerFlags, PFN_GETPLAYERFLAGS);
REQFUNC("GetPlayerEdict", g_fn_GetPlayerEdict, PFN_GET_PLAYER_EDICT);
REQFUNC("amx_Push", g_fn_AmxPush, PFN_AMX_PUSH);
#ifdef MEMORY_TEST
// Memory
REQFUNC_OPT("Allocator", g_fn_Allocator, PFN_ALLOCATOR);
REQFUNC_OPT("Reallocator", g_fn_Reallocator, PFN_REALLOCATOR);
REQFUNC_OPT("Deallocator", g_fn_Deallocator, PFN_DEALLOCATOR);
#endif
REQFUNC("CellToReal", g_fn_CellToReal, PFN_CELL_TO_REAL);
REQFUNC("RealToCell", g_fn_RealToCell, PFN_REAL_TO_CELL);
@ -2720,7 +2717,7 @@ void ValidateMacros_DontCallThis_Smiley()
MF_IsPlayerHLTV(0);
MF_GetPlayerArmor(0);
MF_GetPlayerHealth(0);
MF_AmxExec(0, 0, 0);
MF_AmxExec(0, 0, 0, 0);
MF_AmxExecv(0, 0, 0, 0, 0);
MF_AmxFindPublic(0, 0, 0);
MF_AmxAllot(0, 0, 0, 0);
@ -2736,8 +2733,6 @@ void ValidateMacros_DontCallThis_Smiley()
}
#endif
#ifdef MEMORY_TEST
/************* MEMORY *************/
// undef all defined macros
#undef new
@ -2909,30 +2904,6 @@ void operator delete[](void *reportedAddress)
Mem_Deallocator(g_Mem_CurrentFilename, g_Mem_CurrentLine, g_Mem_CurrentFunc, m_alloc_delete_array, reportedAddress);
}
#else
#if !defined NO_ALLOC_OVERRIDES && !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 delete(void * ptr) {
if(ptr)
free(ptr);
}
void ::operator delete[](void * ptr) {
if(ptr)
free(ptr);
}
#endif
#endif //MEMORY_TEST
/************* stuff from dlls/util.cpp *************/
// must come here because cbase.h declares it's own operator new

View File

@ -46,6 +46,8 @@ struct amxx_module_info_s
const char *logtag; // added in version 2
};
// return values from functions called by amxx
#define AMXX_OK 0 /* no error */
#define AMXX_IFVERS 1 /* interface version */
@ -1979,15 +1981,13 @@ typedef edict_t * (*PFN_GET_PLAYER_EDICT) (int /*id*/);
typedef void * (*PFN_GET_PLAYER_EDICT) (int /*id*/);
#endif
#ifdef MEMORY_TEST
typedef void * (*PFN_ALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const size_t /*size*/);
typedef void * (*PFN_REALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const size_t /*size*/, void* /*addr*/ );
typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const void* /*addr*/ );
#endif
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, ... /*params*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/);
@ -2002,7 +2002,6 @@ typedef void (*PFN_UNREGISTER_SPFORWARD) (int /*id*/);
typedef void (*PFN_MERGEDEFINITION_FILE) (const char * /*filename*/);
typedef const char * (*PFN_FORMAT) (const char * /*fmt*/, ... /*params*/);
typedef void (*PFN_REGISTERFUNCTION) (void * /*pfn*/, const char * /*desc*/);
typedef int (*PFN_AMX_PUSH) (AMX * /*amx*/, cell /*value*/);
extern PFN_ADD_NATIVES g_fn_AddNatives;
extern PFN_BUILD_PATHNAME g_fn_BuildPathname;
@ -2048,6 +2047,7 @@ extern PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
extern PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
extern PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
extern PFN_AMX_EXEC g_fn_AmxExec;
extern PFN_AMX_EXECV g_fn_AmxExecv;
extern PFN_AMX_ALLOT g_fn_AmxAllot;
extern PFN_AMX_FINDPUBLIC g_fn_AmxFindPublic;
extern PFN_LOAD_AMXSCRIPT g_fn_LoadAmxScript;
@ -2065,7 +2065,6 @@ extern PFN_FORMAT g_fn_Format;
extern PFN_GET_PLAYER_TEAM g_fn_GetPlayerTeam;
extern PFN_REGISTERFUNCTION g_fn_RegisterFunction;
extern PFN_REQ_FNPTR g_fn_RequestFunction;
extern PFN_AMX_PUSH g_fn_AmxPush;
#ifdef MAY_NEVER_BE_DEFINED
// Function prototypes for intellisense and similar systems
@ -2124,8 +2123,6 @@ edict_t* MF_GetPlayerEdict (int id) { }
const char * MF_Format (const char *fmt, ...) { }
void MF_RegisterFunction (void *pfn, const char *description) { }
void * MF_RequestFunction (const char *description) { }
int MF_AmxPush (AMX *amx, cell *params) { }
int MF_AmxExec (AMX *amx, cell *retval, int idx) { }
#endif // MAY_NEVER_BE_DEFINED
#define MF_AddNatives g_fn_AddNatives
@ -2190,9 +2187,7 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...);
#define MF_Format g_fn_Format
#define MF_RegisterFunction g_fn_RegisterFunction
#define MF_RequestFunction g_fn_RequestFunction;
#define MF_AmxPush g_fn_AmxPush
#ifdef MEMORY_TEST
/*** Memory ***/
void *operator new(size_t reportedSize);
void *operator new[](size_t reportedSize);
@ -2236,6 +2231,4 @@ void Mem_Deallocator(const char *sourceFile, const unsigned int sourceLine, cons
#define realloc(ptr,sz) Mem_Reallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_realloc,sz,ptr)
#define free(ptr) Mem_Deallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_free,ptr)
#endif //MEMORY_TEST
#endif // #ifndef __AMXXMODULE_H__

View File

@ -175,7 +175,7 @@ static cell AMX_NATIVE_CALL cs_get_weapon_silenced(AMX *amx, cell *params) // cs
// Make into edict pointer
edict_t *pWeapon = INDEXENT(params[1]);
int weapontype = *((int *)pWeapon->pvPrivateData + OFFSET_WEAPONTYPE);
int weapontype = (int)*((int *)pWeapon->pvPrivateData + OFFSET_WEAPONTYPE);
int *silencemode = ((int *)pWeapon->pvPrivateData + OFFSET_SILENCER_FIREMODE);
switch (weapontype) {
case CSW_M4A1:
@ -357,12 +357,10 @@ static cell AMX_NATIVE_CALL cs_get_user_armor(AMX *amx, cell *params) // cs_get_
// Make into edict pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]);
#if 0
cell *armorTypeByRef = MF_GetAmxAddr(amx, params[2]);
*armorTypeByRef = *((int *)pPlayer->pvPrivateData + OFFSET_ARMORTYPE);
#endif
return (cell)pPlayer->v.armorvalue;
return pPlayer->v.armorvalue;
}
static cell AMX_NATIVE_CALL cs_set_user_armor(AMX *amx, cell *params) // cs_set_user_armor(index, armorvalue, CsArmorType:armortype); = 3 params
@ -1234,118 +1232,6 @@ static cell AMX_NATIVE_CALL cs_user_spawn(AMX *amx, cell *params)
return 1;
}
static cell AMX_NATIVE_CALL cs_get_armoury_type(AMX *amx, cell *params)
{
// Return CSW_* constants of specified armoury_entity.
// params[1] = entity
// Valid entity should be within range.
CHECK_NONPLAYER(params[1]);
// Make into edict pointer.
edict_t *pArmoury = INDEXENT(params[1]);
// Make sure this is an armoury_entity.
if (strcmp(STRING(pArmoury->v.classname), "armoury_entity")) {
// Error out here.
MF_LogError(amx, AMX_ERR_NATIVE, "Not an armoury_entity! (%d)", params[1]);
return 0;
}
#if PAWN_CELL_SIZE == 32
int weapontype = *((int *)pArmoury->pvPrivateData + OFFSET_ARMOURY_TYPE);
// We do a switch instead of a mapped array because this way we can nicely catch unexpected values, and we don't get array out of bounds thingies.
int weapontype_out;
switch (weapontype) {
case CSA_MP5NAVY: weapontype_out = CSW_MP5NAVY; break;
case CSA_TMP: weapontype_out = CSW_TMP; break;
case CSA_P90: weapontype_out = CSW_P90; break;
case CSA_MAC10: weapontype_out = CSW_MAC10; break;
case CSA_AK47: weapontype_out = CSW_AK47; break;
case CSA_SG552: weapontype_out = CSW_SG552; break;
case CSA_M4A1: weapontype_out = CSW_M4A1; break;
case CSA_AUG: weapontype_out = CSW_AUG; break;
case CSA_SCOUT: weapontype_out = CSW_SCOUT; break;
case CSA_G3SG1: weapontype_out = CSW_G3SG1; break;
case CSA_AWP: weapontype_out = CSW_AWP; break;
case CSA_M3: weapontype_out = CSW_M3; break;
case CSA_XM1014: weapontype_out = CSW_XM1014; break;
case CSA_M249: weapontype_out = CSW_M249; break;
case CSA_FLASHBANG: weapontype_out = CSW_FLASHBANG; break;
case CSA_HEGRENADE: weapontype_out = CSW_HEGRENADE; break;
case CSA_VEST: weapontype_out = CSW_VEST; break;
case CSA_VESTHELM: weapontype_out = CSW_VESTHELM; break;
case CSA_SMOKEGRENADE: weapontype_out = CSW_SMOKEGRENADE; break;
default:
MF_LogError(amx, AMX_ERR_NATIVE, "Unexpected weapon type of %d!", params[1]);
return 0;
}
return weapontype_out;
#else
MF_LogError(amx, AMX_ERR_NATIVE, "This function not implemented on AMD64.");
return 0;
#endif
}
static cell AMX_NATIVE_CALL cs_set_armoury_type(AMX *amx, cell *params)
{
// Set CSW->CSA mapped weapon type to entity.
// params[1] = entity
// params[2] = CSW_* constant
// Valid entity should be within range.
CHECK_NONPLAYER(params[1]);
// Make into edict pointer.
edict_t *pArmoury = INDEXENT(params[1]);
// Make sure this is an armoury_entity.
if (strcmp(STRING(pArmoury->v.classname), "armoury_entity")) {
// Error out here.
MF_LogError(amx, AMX_ERR_NATIVE, "Not an armoury_entity! (%d)", params[1]);
return 0;
}
#if PAWN_CELL_SIZE == 32
// We do a switch instead of a mapped array because this way we can nicely catch unexpected values, and we don't get array out of bounds thingies.
int weapontype;
switch (params[2]) {
case CSW_MP5NAVY: weapontype = CSA_MP5NAVY; break;
case CSW_TMP: weapontype = CSA_TMP; break;
case CSW_P90: weapontype = CSA_P90; break;
case CSW_MAC10: weapontype = CSA_MAC10; break;
case CSW_AK47: weapontype = CSA_AK47; break;
case CSW_SG552: weapontype = CSA_SG552; break;
case CSW_M4A1: weapontype = CSA_M4A1; break;
case CSW_AUG: weapontype = CSA_AUG; break;
case CSW_SCOUT: weapontype = CSA_SCOUT; break;
case CSW_G3SG1: weapontype = CSA_G3SG1; break;
case CSW_AWP: weapontype = CSA_AWP; break;
case CSW_M3: weapontype = CSA_M3; break;
case CSW_XM1014: weapontype = CSA_XM1014; break;
case CSW_M249: weapontype = CSA_M249; break;
case CSW_FLASHBANG: weapontype = CSA_FLASHBANG; break;
case CSW_HEGRENADE: weapontype = CSA_HEGRENADE; break;
case CSW_VEST: weapontype = CSA_VEST; break;
case CSW_VESTHELM: weapontype = CSA_VESTHELM; break;
case CSW_SMOKEGRENADE: weapontype = CSA_SMOKEGRENADE; break;
default:
MF_LogError(amx, AMX_ERR_NATIVE, "Unsupported weapon type! (%d)", params[2]);
return 0;
}
*((int *)pArmoury->pvPrivateData + OFFSET_ARMOURY_TYPE) = weapontype;
return 1;
#else
MF_LogError(amx, AMX_ERR_NATIVE, "This function not implemented on AMD64.");
return 0;
#endif
}
AMX_NATIVE_INFO cstrike_Exports[] = {
{"cs_set_user_money", cs_set_user_money},
{"cs_get_user_money", cs_get_user_money},
@ -1388,8 +1274,6 @@ AMX_NATIVE_INFO cstrike_Exports[] = {
{"cs_set_user_armor", cs_set_user_armor},
{"cs_get_user_shield", cs_get_user_shield},
{"cs_user_spawn", cs_user_spawn},
{"cs_get_armoury_type", cs_get_armoury_type},
{"cs_set_armoury_type", cs_set_armoury_type},
//------------------- <-- max 19 characters!
{NULL, NULL}
};

View File

@ -102,8 +102,6 @@
// "hostage_entity" entities
#define OFFSET_HOSTAGEFOLLOW 86 + EXTRAOFFSET
#define OFFSET_HOSTAGEID 487 + EXTRAOFFSET
// "armoury_entity"
#define OFFSET_ARMOURY_TYPE 34 + EXTRAOFFSET
#else
// Amd64 offsets here
#define OFFSET_ARMORTYPE 137 + EXTRAOFFSET
@ -176,29 +174,6 @@
#define CSW_AK47 28
//#define CSW_KNIFE 29
#define CSW_P90 30
#define CSW_VEST 31 // Brand new invention!
#define CSW_VESTHELM 32 // Brand new invention!
// These are used with armoury_entity:s.
#define CSA_MP5NAVY 0
#define CSA_TMP 1
#define CSA_P90 2
#define CSA_MAC10 3
#define CSA_AK47 4
#define CSA_SG552 5
#define CSA_M4A1 6
#define CSA_AUG 7
#define CSA_SCOUT 8
#define CSA_G3SG1 9
#define CSA_AWP 10
#define CSA_M3 11
#define CSA_XM1014 12
#define CSA_M249 13
#define CSA_FLASHBANG 14
#define CSA_HEGRENADE 15
#define CSA_VEST 16
#define CSA_VESTHELM 17
#define CSA_SMOKEGRENADE 18
#define M4A1_SILENCED (1<<2)
#define M4A1_ATTACHSILENCEANIM 6
@ -301,4 +276,3 @@ bool g_noknives = false;
#define GETEDICT(n) \
((n >= 1 && n <= gpGlobals->maxClients) ? MF_GetPlayerEdict(n) : INDEXENT(n))

View File

@ -5,7 +5,7 @@
// Module info
#define MODULE_NAME "CStrike"
#define MODULE_VERSION "1.60"
#define MODULE_VERSION "1.50"
#define MODULE_AUTHOR "AMX Mod X Dev Team"
#define MODULE_URL "http://www.amxmodx.org"
#define MODULE_LOGTAG "CSTRIKE"
@ -460,4 +460,3 @@
#endif // USE_METAMOD
#endif // __MODULECONFIG_H__

View File

@ -308,4 +308,3 @@ void RankSystem::saveRank( const char* filename )
fclose(bfp);
}

View File

@ -120,4 +120,3 @@ public:
#endif

View File

@ -6,7 +6,7 @@ MM_ROOT = ../../../metamod/metamod
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fomit-frame-pointer
OPT_FLAGS = -O3 -fno-rtti -funroll-loops -s -pipe
DEBUG_FLAGS = -g -ggdb3
CPP = gcc
NAME = csx_amxx
@ -26,11 +26,12 @@ else
CFLAGS = $(OPT_FLAGS)
endif
CFLAGS += -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H -static-libgcc -fno-rtti
CFLAGS += -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H
ifeq "$(AMD64)" "true"
BINARY = $(NAME)_amd64.so
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64
LINK += -lstdc++
else
BINARY = $(NAME)_i386.so
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32

View File

@ -45,6 +45,8 @@
enginefuncs_t g_engfuncs;
globalvars_t *gpGlobals;
DLL_FUNCTIONS *g_pFunctionTable;
DLL_FUNCTIONS *g_pFunctionTable_Post;
enginefuncs_t *g_pengfuncsTable;
@ -52,6 +54,7 @@ enginefuncs_t *g_pengfuncsTable_Post;
NEW_DLL_FUNCTIONS *g_pNewFunctionsTable;
NEW_DLL_FUNCTIONS *g_pNewFunctionsTable_Post;
// GetEntityAPI2 functions
static DLL_FUNCTIONS g_EntityAPI_Table =
{
@ -2478,11 +2481,9 @@ PFN_IS_PLAYER_CONNECTING g_fn_IsPlayerConnecting;
PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
#ifdef MEMORY_TEST
PFN_ALLOCATOR g_fn_Allocator;
PFN_REALLOCATOR g_fn_Reallocator;
PFN_DEALLOCATOR g_fn_Deallocator;
#endif
PFN_AMX_EXEC g_fn_AmxExec;
PFN_AMX_EXECV g_fn_AmxExecv;
PFN_AMX_ALLOT g_fn_AmxAllot;
@ -2612,12 +2613,10 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
REQFUNC("GetPlayerEdict", g_fn_GetPlayerEdict, PFN_GET_PLAYER_EDICT);
REQFUNC("amx_Push", g_fn_AmxPush, PFN_AMX_PUSH);
#ifdef MEMORY_TEST
// Memory
REQFUNC_OPT("Allocator", g_fn_Allocator, PFN_ALLOCATOR);
REQFUNC_OPT("Reallocator", g_fn_Reallocator, PFN_REALLOCATOR);
REQFUNC_OPT("Deallocator", g_fn_Deallocator, PFN_DEALLOCATOR);
#endif
REQFUNC("CellToReal", g_fn_CellToReal, PFN_CELL_TO_REAL);
REQFUNC("RealToCell", g_fn_RealToCell, PFN_REAL_TO_CELL);
@ -2736,8 +2735,6 @@ void ValidateMacros_DontCallThis_Smiley()
}
#endif
#ifdef MEMORY_TEST
/************* MEMORY *************/
// undef all defined macros
#undef new
@ -2909,30 +2906,6 @@ void operator delete[](void *reportedAddress)
Mem_Deallocator(g_Mem_CurrentFilename, g_Mem_CurrentLine, g_Mem_CurrentFunc, m_alloc_delete_array, reportedAddress);
}
#else
#if !defined NO_ALLOC_OVERRIDES && !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 delete(void * ptr) {
if(ptr)
free(ptr);
}
void ::operator delete[](void * ptr) {
if(ptr)
free(ptr);
}
#endif
#endif //MEMORY_TEST
/************* stuff from dlls/util.cpp *************/
// must come here because cbase.h declares it's own operator new

View File

@ -46,6 +46,8 @@ struct amxx_module_info_s
const char *logtag; // added in version 2
};
// return values from functions called by amxx
#define AMXX_OK 0 /* no error */
#define AMXX_IFVERS 1 /* interface version */
@ -1979,14 +1981,12 @@ typedef edict_t * (*PFN_GET_PLAYER_EDICT) (int /*id*/);
typedef void * (*PFN_GET_PLAYER_EDICT) (int /*id*/);
#endif
#ifdef MEMORY_TEST
typedef void * (*PFN_ALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const size_t /*size*/);
typedef void * (*PFN_REALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const size_t /*size*/, void* /*addr*/ );
typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const void* /*addr*/ );
#endif
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
@ -2048,6 +2048,7 @@ extern PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
extern PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
extern PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
extern PFN_AMX_EXEC g_fn_AmxExec;
extern PFN_AMX_EXECV g_fn_AmxExecv;
extern PFN_AMX_ALLOT g_fn_AmxAllot;
extern PFN_AMX_FINDPUBLIC g_fn_AmxFindPublic;
extern PFN_LOAD_AMXSCRIPT g_fn_LoadAmxScript;
@ -2192,7 +2193,6 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...);
#define MF_RequestFunction g_fn_RequestFunction;
#define MF_AmxPush g_fn_AmxPush
#ifdef MEMORY_TEST
/*** Memory ***/
void *operator new(size_t reportedSize);
void *operator new[](size_t reportedSize);
@ -2236,6 +2236,4 @@ void Mem_Deallocator(const char *sourceFile, const unsigned int sourceLine, cons
#define realloc(ptr,sz) Mem_Reallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_realloc,sz,ptr)
#define free(ptr) Mem_Deallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_free,ptr)
#endif //MEMORY_TEST
#endif // #ifndef __AMXXMODULE_H__

View File

@ -5,7 +5,7 @@
// Module info
#define MODULE_NAME "CSX"
#define MODULE_VERSION "1.60"
#define MODULE_VERSION "1.50"
#define MODULE_AUTHOR "AMX Mod X Dev Team"
#define MODULE_URL "http://www.amxmodx.org/"
#define MODULE_LOGTAG "CSX"
@ -460,4 +460,3 @@
#endif // USE_METAMOD
#endif // __MODULECONFIG_H__

View File

@ -26,9 +26,9 @@
AdditionalIncludeDirectories="..\..\metamod,..\..\sdk\common,..\..\sdk\engine,..\..\sdk\dlls"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;csx_EXPORTS;JIT"
StringPooling="TRUE"
RuntimeLibrary="4"
StructMemberAlignment="0"
EnableFunctionLevelLinking="FALSE"
RuntimeLibrary="0"
StructMemberAlignment="3"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\release/csx.pch"
AssemblerListingLocation=".\release/"
@ -91,7 +91,7 @@
AdditionalIncludeDirectories="..\..\metamod,..\..\sdk\common,..\..\sdk\engine,..\..\sdk\dlls,..\..\hlsdk\sourcecode\pm_shared"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;csx_EXPORTS"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\debug/csx.pch"
AssemblerListingLocation=".\debug/"

View File

@ -6,7 +6,7 @@ MM_ROOT = ../../../metamod/metamod
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O3 -funroll-loops -s -pipe
OPT_FLAGS = -O3 -fno-rtti -funroll-loops -s -pipe
DEBUG_FLAGS = -g -ggdb3
CPP = gcc
NAME = dodfun_amxx
@ -26,11 +26,12 @@ else
CFLAGS = $(OPT_FLAGS)
endif
CFLAGS += -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H -static-libgcc -fno-rtti
CFLAGS += -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H
ifeq "$(AMD64)" "true"
BINARY = $(NAME)_amd64.so
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64
LINK += -lstdc++
else
BINARY = $(NAME)_i386.so
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32

View File

@ -45,6 +45,8 @@
enginefuncs_t g_engfuncs;
globalvars_t *gpGlobals;
DLL_FUNCTIONS *g_pFunctionTable;
DLL_FUNCTIONS *g_pFunctionTable_Post;
enginefuncs_t *g_pengfuncsTable;
@ -52,6 +54,7 @@ enginefuncs_t *g_pengfuncsTable_Post;
NEW_DLL_FUNCTIONS *g_pNewFunctionsTable;
NEW_DLL_FUNCTIONS *g_pNewFunctionsTable_Post;
// GetEntityAPI2 functions
static DLL_FUNCTIONS g_EntityAPI_Table =
{
@ -2478,11 +2481,9 @@ PFN_IS_PLAYER_CONNECTING g_fn_IsPlayerConnecting;
PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
#ifdef MEMORY_TEST
PFN_ALLOCATOR g_fn_Allocator;
PFN_REALLOCATOR g_fn_Reallocator;
PFN_DEALLOCATOR g_fn_Deallocator;
#endif
PFN_AMX_EXEC g_fn_AmxExec;
PFN_AMX_EXECV g_fn_AmxExecv;
PFN_AMX_ALLOT g_fn_AmxAllot;
@ -2501,7 +2502,6 @@ PFN_GET_PLAYER_EDICT g_fn_GetPlayerEdict;
PFN_FORMAT g_fn_Format;
PFN_REGISTERFUNCTION g_fn_RegisterFunction;
PFN_REQ_FNPTR g_fn_RequestFunction;
PFN_AMX_PUSH g_fn_AmxPush;
// *** Exports ***
C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo)
@ -2610,14 +2610,11 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
REQFUNC("GetPlayerHealth", g_fn_GetPlayerHealth, PFN_GET_PLAYER_HEALTH);
REQFUNC("GetPlayerFlags", g_fn_GetPlayerFlags, PFN_GETPLAYERFLAGS);
REQFUNC("GetPlayerEdict", g_fn_GetPlayerEdict, PFN_GET_PLAYER_EDICT);
REQFUNC("amx_Push", g_fn_AmxPush, PFN_AMX_PUSH);
#ifdef MEMORY_TEST
// Memory
REQFUNC_OPT("Allocator", g_fn_Allocator, PFN_ALLOCATOR);
REQFUNC_OPT("Reallocator", g_fn_Reallocator, PFN_REALLOCATOR);
REQFUNC_OPT("Deallocator", g_fn_Deallocator, PFN_DEALLOCATOR);
#endif
REQFUNC("CellToReal", g_fn_CellToReal, PFN_CELL_TO_REAL);
REQFUNC("RealToCell", g_fn_RealToCell, PFN_REAL_TO_CELL);
@ -2720,7 +2717,7 @@ void ValidateMacros_DontCallThis_Smiley()
MF_IsPlayerHLTV(0);
MF_GetPlayerArmor(0);
MF_GetPlayerHealth(0);
MF_AmxExec(0, 0, 0);
MF_AmxExec(0, 0, 0, 0);
MF_AmxExecv(0, 0, 0, 0, 0);
MF_AmxFindPublic(0, 0, 0);
MF_AmxAllot(0, 0, 0, 0);
@ -2736,8 +2733,6 @@ void ValidateMacros_DontCallThis_Smiley()
}
#endif
#ifdef MEMORY_TEST
/************* MEMORY *************/
// undef all defined macros
#undef new
@ -2909,30 +2904,6 @@ void operator delete[](void *reportedAddress)
Mem_Deallocator(g_Mem_CurrentFilename, g_Mem_CurrentLine, g_Mem_CurrentFunc, m_alloc_delete_array, reportedAddress);
}
#else
#if !defined NO_ALLOC_OVERRIDES && !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 delete(void * ptr) {
if(ptr)
free(ptr);
}
void ::operator delete[](void * ptr) {
if(ptr)
free(ptr);
}
#endif
#endif //MEMORY_TEST
/************* stuff from dlls/util.cpp *************/
// must come here because cbase.h declares it's own operator new

View File

@ -46,6 +46,8 @@ struct amxx_module_info_s
const char *logtag; // added in version 2
};
// return values from functions called by amxx
#define AMXX_OK 0 /* no error */
#define AMXX_IFVERS 1 /* interface version */
@ -1979,15 +1981,13 @@ typedef edict_t * (*PFN_GET_PLAYER_EDICT) (int /*id*/);
typedef void * (*PFN_GET_PLAYER_EDICT) (int /*id*/);
#endif
#ifdef MEMORY_TEST
typedef void * (*PFN_ALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const size_t /*size*/);
typedef void * (*PFN_REALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const size_t /*size*/, void* /*addr*/ );
typedef void (*PFN_DEALLOCATOR) (const char* /*filename*/, const unsigned int /*line*/, const char* /*func*/,
const unsigned int /*type*/, const void* /*addr*/ );
#endif
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/);
typedef int (*PFN_AMX_EXEC) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, ... /*params*/);
typedef int (*PFN_AMX_EXECV) (AMX* /*amx*/, cell* /*return val*/, int /*index*/, int /*numparams*/, cell[] /*params*/);
typedef int (*PFN_AMX_ALLOT) (AMX* /*amx*/, int /*length*/, cell* /*amx_addr*/, cell** /*phys_addr*/);
typedef int (*PFN_AMX_FINDPUBLIC) (AMX* /*amx*/, char* /*func name*/, int* /*index*/);
@ -2002,7 +2002,6 @@ typedef void (*PFN_UNREGISTER_SPFORWARD) (int /*id*/);
typedef void (*PFN_MERGEDEFINITION_FILE) (const char * /*filename*/);
typedef const char * (*PFN_FORMAT) (const char * /*fmt*/, ... /*params*/);
typedef void (*PFN_REGISTERFUNCTION) (void * /*pfn*/, const char * /*desc*/);
typedef int (*PFN_AMX_PUSH) (AMX * /*amx*/, cell /*value*/);
extern PFN_ADD_NATIVES g_fn_AddNatives;
extern PFN_BUILD_PATHNAME g_fn_BuildPathname;
@ -2048,6 +2047,7 @@ extern PFN_IS_PLAYER_HLTV g_fn_IsPlayerHLTV;
extern PFN_GET_PLAYER_ARMOR g_fn_GetPlayerArmor;
extern PFN_GET_PLAYER_HEALTH g_fn_GetPlayerHealth;
extern PFN_AMX_EXEC g_fn_AmxExec;
extern PFN_AMX_EXECV g_fn_AmxExecv;
extern PFN_AMX_ALLOT g_fn_AmxAllot;
extern PFN_AMX_FINDPUBLIC g_fn_AmxFindPublic;
extern PFN_LOAD_AMXSCRIPT g_fn_LoadAmxScript;
@ -2065,7 +2065,6 @@ extern PFN_FORMAT g_fn_Format;
extern PFN_GET_PLAYER_TEAM g_fn_GetPlayerTeam;
extern PFN_REGISTERFUNCTION g_fn_RegisterFunction;
extern PFN_REQ_FNPTR g_fn_RequestFunction;
extern PFN_AMX_PUSH g_fn_AmxPush;
#ifdef MAY_NEVER_BE_DEFINED
// Function prototypes for intellisense and similar systems
@ -2124,8 +2123,6 @@ edict_t* MF_GetPlayerEdict (int id) { }
const char * MF_Format (const char *fmt, ...) { }
void MF_RegisterFunction (void *pfn, const char *description) { }
void * MF_RequestFunction (const char *description) { }
int MF_AmxPush (AMX *amx, cell *params) { }
int MF_AmxExec (AMX *amx, cell *retval, int idx) { }
#endif // MAY_NEVER_BE_DEFINED
#define MF_AddNatives g_fn_AddNatives
@ -2190,9 +2187,7 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...);
#define MF_Format g_fn_Format
#define MF_RegisterFunction g_fn_RegisterFunction
#define MF_RequestFunction g_fn_RequestFunction;
#define MF_AmxPush g_fn_AmxPush
#ifdef MEMORY_TEST
/*** Memory ***/
void *operator new(size_t reportedSize);
void *operator new[](size_t reportedSize);
@ -2236,6 +2231,4 @@ void Mem_Deallocator(const char *sourceFile, const unsigned int sourceLine, cons
#define realloc(ptr,sz) Mem_Reallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_realloc,sz,ptr)
#define free(ptr) Mem_Deallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_free,ptr)
#endif //MEMORY_TEST
#endif // #ifndef __AMXXMODULE_H__

View File

@ -5,7 +5,7 @@
// Module info
#define MODULE_NAME "DoD Fun"
#define MODULE_VERSION "1.60"
#define MODULE_VERSION "1.50"
#define MODULE_AUTHOR "AMX Mod X Dev Team"
#define MODULE_URL "http://www.amxmodx.org"
#define MODULE_LOGTAG "DODFUN"

View File

@ -6,7 +6,7 @@ MM_ROOT = ../../../metamod/metamod
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O3 -funroll-loops -s -pipe
OPT_FLAGS = -O3 -fno-rtti -funroll-loops -s -pipe
DEBUG_FLAGS = -g -ggdb3
CPP = gcc
NAME = dodx_amxx
@ -26,11 +26,12 @@ else
CFLAGS = $(OPT_FLAGS)
endif
CFLAGS += -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H -static-libgcc -fno-rtti
CFLAGS += -DNDEBUG -fPIC -Wno-deprecated -fno-exceptions -DHAVE_STDINT_H
ifeq "$(AMD64)" "true"
BINARY = $(NAME)_amd64.so
CFLAGS += -DPAWN_CELL_SIZE=64 -DHAVE_I64 -m64
LINK += -lstdc++
else
BINARY = $(NAME)_i386.so
CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32

Some files were not shown because too many files have changed in this diff Show More