Fixed a crash bug in FormatAmxString()
Added amx_FindNative to module API Changed LZO->GZ in .amxx format
This commit is contained in:
parent
94219ae71a
commit
9d3ea5513b
|
@ -47,6 +47,15 @@
|
||||||
#define FFHL_VERSION 4
|
#define FFHL_VERSION 4
|
||||||
#define FFHL_MIN_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:
|
/*version history:
|
||||||
* 1 (BAILOPAN) - Simplest form possible, no reverse
|
* 1 (BAILOPAN) - Simplest form possible, no reverse
|
||||||
* 2 (BAILOPAN) - One language per file with full 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)
|
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];
|
static char outbuf[4096];
|
||||||
|
cell *src = get_amxaddr(amx, params[parm++]);
|
||||||
char *outptr = outbuf;
|
char *outptr = outbuf;
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
|
@ -646,6 +656,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||||
if (*src=='L')
|
if (*src=='L')
|
||||||
{
|
{
|
||||||
cell langName = params[parm]; // "en" case (langName contains the address to the string)
|
cell langName = params[parm]; // "en" case (langName contains the address to the string)
|
||||||
|
NEXT_PARAM();
|
||||||
cell *pAmxLangName = get_amxaddr(amx, params[parm++]); // other cases
|
cell *pAmxLangName = get_amxaddr(amx, params[parm++]); // other cases
|
||||||
const char *cpLangName=NULL;
|
const char *cpLangName=NULL;
|
||||||
// Handle player ids (1-32) and server language
|
// 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)
|
if (!cpLangName || strlen(cpLangName) < 1)
|
||||||
cpLangName = "en";
|
cpLangName = "en";
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
NEXT_PARAM();
|
||||||
char *key = get_amxstring(amx, params[parm++], 1, len);
|
char *key = get_amxstring(amx, params[parm++], 1, len);
|
||||||
const char *def = GetDef(cpLangName, key);
|
const char *def = GetDef(cpLangName, key);
|
||||||
if (def == NULL)
|
if (def == NULL)
|
||||||
|
@ -709,6 +721,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||||
{
|
{
|
||||||
char tmpString[256];
|
char tmpString[256];
|
||||||
char *tmpPtr = tmpString;
|
char *tmpPtr = tmpString;
|
||||||
|
NEXT_PARAM();
|
||||||
cell *tmpCell = get_amxaddr(amx, params[parm++]);
|
cell *tmpCell = get_amxaddr(amx, params[parm++]);
|
||||||
while (*tmpCell)
|
while (*tmpCell)
|
||||||
*tmpPtr++ = *tmpCell++;
|
*tmpPtr++ = *tmpCell++;
|
||||||
|
@ -719,15 +732,23 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'f':
|
case 'f':
|
||||||
{
|
{
|
||||||
|
NEXT_PARAM();
|
||||||
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
|
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'd':
|
case 'd':
|
||||||
{
|
{
|
||||||
|
NEXT_PARAM();
|
||||||
sprintf(outptr, format, (int)*get_amxaddr(amx, params[parm++]));
|
sprintf(outptr, format, (int)*get_amxaddr(amx, params[parm++]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
*outptr++ = '%';
|
||||||
|
*outptr++ = *(ptr-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
outptr += strlen(outptr);
|
outptr += strlen(outptr);
|
||||||
}
|
}
|
||||||
|
@ -764,33 +785,49 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
|
||||||
char format[16];
|
char format[16];
|
||||||
format[0] = '%';
|
format[0] = '%';
|
||||||
char *ptr = format+1;
|
char *ptr = format+1;
|
||||||
while (!isalpha(*ptr++ = *src++))
|
if (*src != '%')
|
||||||
/*nothing*/;
|
|
||||||
--src;
|
|
||||||
*ptr = 0;
|
|
||||||
switch ( *(ptr-1) )
|
|
||||||
{
|
{
|
||||||
case 's':
|
while (!isalpha(*ptr++ = *src++))
|
||||||
|
/*nothing*/;
|
||||||
|
--src;
|
||||||
|
*ptr = 0;
|
||||||
|
switch ( *(ptr-1) )
|
||||||
{
|
{
|
||||||
cell *tmpCell = get_amxaddr(amx, params[parm++]);
|
case 's':
|
||||||
while (*tmpCell)
|
{
|
||||||
*tmpPtr++ = *tmpCell++;
|
NEXT_PARAM();
|
||||||
*tmpPtr = 0;
|
cell *tmpCell = get_amxaddr(amx, params[parm++]);
|
||||||
sprintf(outptr, format, tmpString);
|
while (*tmpCell)
|
||||||
break;
|
*tmpPtr++ = *tmpCell++;
|
||||||
}
|
*tmpPtr = 0;
|
||||||
case 'g':
|
sprintf(outptr, format, tmpString);
|
||||||
case 'f':
|
break;
|
||||||
{
|
}
|
||||||
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
|
case 'g':
|
||||||
break;
|
case 'f':
|
||||||
}
|
{
|
||||||
case 'i':
|
NEXT_PARAM();
|
||||||
case 'd':
|
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
|
||||||
{
|
break;
|
||||||
sprintf(outptr, format, (int)*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);
|
outptr += strlen(outptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,45 +124,52 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
|
||||||
m_pFile = NULL;
|
m_pFile = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else if ( magic == 0x524C4542 ) {
|
||||||
|
//we have an invalid, old, RLEB file
|
||||||
// try to find the section
|
m_Status = Err_OldFile;
|
||||||
mint8_t numOfPlugins;
|
|
||||||
DATAREAD(&numOfPlugins, sizeof(numOfPlugins), 1);
|
|
||||||
|
|
||||||
TableEntry entry;
|
|
||||||
|
|
||||||
m_SectionHdrOffset = 0;
|
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < static_cast<int>(numOfPlugins); ++i)
|
|
||||||
{
|
|
||||||
DATAREAD(&entry, sizeof(entry), 1);
|
|
||||||
if (entry.cellSize == m_CellSize)
|
|
||||||
{
|
|
||||||
m_SectionHdrOffset = ftell(m_pFile) - sizeof(entry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!m_SectionHdrOffset)
|
|
||||||
{
|
|
||||||
m_Status = Err_SectionNotFound;
|
|
||||||
fclose(m_pFile);
|
fclose(m_pFile);
|
||||||
m_pFile = NULL;
|
m_pFile = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// compute section length
|
// try to find the section
|
||||||
if ((i+1) < static_cast<int>(numOfPlugins))
|
mint8_t numOfPlugins;
|
||||||
{
|
DATAREAD(&numOfPlugins, sizeof(numOfPlugins), 1);
|
||||||
// there is a next section
|
|
||||||
TableEntry nextEntry;
|
TableEntry entry;
|
||||||
DATAREAD(&nextEntry, sizeof(nextEntry), 1);
|
|
||||||
m_SectionLength = nextEntry.offset - entry.offset;
|
m_SectionHdrOffset = 0;
|
||||||
}
|
int i = 0;
|
||||||
else
|
for (i = 0; i < static_cast<int>(numOfPlugins); ++i)
|
||||||
{
|
{
|
||||||
fseek(m_pFile, 0, SEEK_END);
|
DATAREAD(&entry, sizeof(entry), 1);
|
||||||
m_SectionLength = ftell(m_pFile) - (long)entry.offset;
|
if (entry.cellSize == m_CellSize)
|
||||||
|
{
|
||||||
|
m_SectionHdrOffset = ftell(m_pFile) - sizeof(entry);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!m_SectionHdrOffset)
|
||||||
|
{
|
||||||
|
m_Status = Err_SectionNotFound;
|
||||||
|
fclose(m_pFile);
|
||||||
|
m_pFile = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute section length
|
||||||
|
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
|
||||||
|
{
|
||||||
|
fseek(m_pFile, 0, SEEK_END);
|
||||||
|
m_SectionLength = ftell(m_pFile) - (long)entry.offset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@ public:
|
||||||
Err_FileInvalid,
|
Err_FileInvalid,
|
||||||
Err_SectionNotFound,
|
Err_SectionNotFound,
|
||||||
Err_DecompressorInit,
|
Err_DecompressorInit,
|
||||||
Err_Decompress
|
Err_Decompress,
|
||||||
|
Err_OldFile,
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -132,6 +132,8 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
|
||||||
case CAmxxReader::Err_Decompress:
|
case CAmxxReader::Err_Decompress:
|
||||||
strcpy(error, "Internal error: Decompress");
|
strcpy(error, "Internal error: Decompress");
|
||||||
return (amx->error = AMX_ERR_NOTFOUND);
|
return (amx->error = AMX_ERR_NOTFOUND);
|
||||||
|
case CAmxxReader::Err_OldFile:
|
||||||
|
strcpy(error, "Plugin uses deprecated format. Update compiler");
|
||||||
default:
|
default:
|
||||||
strcpy(error, "Unknown error");
|
strcpy(error, "Unknown error");
|
||||||
return (amx->error = AMX_ERR_NOTFOUND);
|
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_Execv", amx_Execv)
|
||||||
REGISTER_FUNC("amx_Allot", amx_Allot)
|
REGISTER_FUNC("amx_Allot", amx_Allot)
|
||||||
REGISTER_FUNC("amx_FindPublic", amx_FindPublic)
|
REGISTER_FUNC("amx_FindPublic", amx_FindPublic)
|
||||||
|
REGISTER_FUNC("amx_FindNative", amx_FindNative)
|
||||||
|
|
||||||
// Natives / Forwards
|
// Natives / Forwards
|
||||||
REGISTER_FUNC("AddNatives", MNF_AddNatives)
|
REGISTER_FUNC("AddNatives", MNF_AddNatives)
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalOptions="/MACHINE:I386"
|
AdditionalOptions="/MACHINE:I386"
|
||||||
AdditionalDependencies="odbc32.lib odbccp32.lib"
|
AdditionalDependencies="odbc32.lib odbccp32.lib ..\zlib\zlib.lib"
|
||||||
OutputFile="debug/amxx_mm.dll"
|
OutputFile="debug/amxx_mm.dll"
|
||||||
Version="0.1"
|
Version="0.1"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user