Fixed a crash bug in FormatAmxString()

Added amx_FindNative to module API
Changed LZO->GZ in .amxx format
This commit is contained in:
David Anderson 2004-08-24 04:30:13 +00:00
parent 94219ae71a
commit 9d3ea5513b
5 changed files with 110 additions and 62 deletions

View File

@ -47,6 +47,15 @@
#define FFHL_VERSION 4
#define FFHL_MIN_VERSION 4
#define NEXT_PARAM() \
if (parm > paramCount) \
{ \
strcpy(outbuf, ""); \
len = 0; \
AMXXLOG_Log("[AMXX] Plugin did not format a string correctly (parameter %d (total %d), line %d, \"%s\")", parm, paramCount, amx->curline, g_plugins.findPluginFast(amx)); \
return outbuf; \
}
/*version history:
* 1 (BAILOPAN) - Simplest form possible, no reverse
* 2 (BAILOPAN) - One language per file with full reverse
@ -627,8 +636,9 @@ const char *CLangMngr::Format(const char *src, ...)
char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
{
cell *src = get_amxaddr(amx, params[parm++]);
int paramCount = *params / sizeof(cell);
static char outbuf[4096];
cell *src = get_amxaddr(amx, params[parm++]);
char *outptr = outbuf;
enum State
{
@ -646,6 +656,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
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
@ -673,6 +684,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
if (!cpLangName || strlen(cpLangName) < 1)
cpLangName = "en";
int len = 0;
NEXT_PARAM();
char *key = get_amxstring(amx, params[parm++], 1, len);
const char *def = GetDef(cpLangName, key);
if (def == NULL)
@ -709,6 +721,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
{
char tmpString[256];
char *tmpPtr = tmpString;
NEXT_PARAM();
cell *tmpCell = get_amxaddr(amx, params[parm++]);
while (*tmpCell)
*tmpPtr++ = *tmpCell++;
@ -719,15 +732,23 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
case 'g':
case 'f':
{
NEXT_PARAM();
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
break;
}
case 'i':
case 'd':
{
NEXT_PARAM();
sprintf(outptr, format, (int)*get_amxaddr(amx, params[parm++]));
break;
}
default:
{
*outptr++ = '%';
*outptr++ = *(ptr-1);
break;
}
}
outptr += strlen(outptr);
}
@ -764,6 +785,8 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
char format[16];
format[0] = '%';
char *ptr = format+1;
if (*src != '%')
{
while (!isalpha(*ptr++ = *src++))
/*nothing*/;
--src;
@ -772,6 +795,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
{
case 's':
{
NEXT_PARAM();
cell *tmpCell = get_amxaddr(amx, params[parm++]);
while (*tmpCell)
*tmpPtr++ = *tmpCell++;
@ -782,15 +806,28 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
case 'g':
case 'f':
{
NEXT_PARAM();
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
break;
}
case 'i':
case 'd':
{
NEXT_PARAM();
sprintf(outptr, format, (int)*get_amxaddr(amx, params[parm++]));
break;
}
default:
{
*outptr++ = '%';
*outptr++ = *(ptr-1);
break;
}
}
} else {
*outptr++ = '%';
*outptr++ = '%';
src++;
}
outptr += strlen(outptr);
}

View File

@ -124,7 +124,13 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
m_pFile = NULL;
return;
}
}
} else if ( magic == 0x524C4542 ) {
//we have an invalid, old, RLEB file
m_Status = Err_OldFile;
fclose(m_pFile);
m_pFile = NULL;
return;
} else {
// try to find the section
mint8_t numOfPlugins;
@ -164,6 +170,7 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
fseek(m_pFile, 0, SEEK_END);
m_SectionLength = ftell(m_pFile) - (long)entry.offset;
}
}
}
CAmxxReader::~CAmxxReader()

View File

@ -44,7 +44,8 @@ public:
Err_FileInvalid,
Err_SectionNotFound,
Err_DecompressorInit,
Err_Decompress
Err_Decompress,
Err_OldFile,
};
private:

View File

@ -132,6 +132,8 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
case CAmxxReader::Err_Decompress:
strcpy(error, "Internal error: Decompress");
return (amx->error = AMX_ERR_NOTFOUND);
case CAmxxReader::Err_OldFile:
strcpy(error, "Plugin uses deprecated format. Update compiler");
default:
strcpy(error, "Unknown error");
return (amx->error = AMX_ERR_NOTFOUND);
@ -894,6 +896,7 @@ void *Module_ReqFnptr(const char *funcName)
REGISTER_FUNC("amx_Execv", amx_Execv)
REGISTER_FUNC("amx_Allot", amx_Allot)
REGISTER_FUNC("amx_FindPublic", amx_FindPublic)
REGISTER_FUNC("amx_FindNative", amx_FindNative)
// Natives / Forwards
REGISTER_FUNC("AddNatives", MNF_AddNatives)

View File

@ -42,7 +42,7 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="odbc32.lib odbccp32.lib"
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib"
OutputFile="debug/amxx_mm.dll"
Version="0.1"
LinkIncremental="1"