That code use the pawn emit which originally not exist in sm compiler
More info about #emit here
Regards to
komashchenko for restoring some removed features to a compiler and for the code below,
which show a simple example of what scripters can do with
#emit, myself found it very useful for menu info , when you need to store some data like "4 5.0 -1" and now I don't use FormatEx and ExploadString and just simply send data via parameters and after extracting them back. Remember that any formatting on that stream char will break it, so only use the two function below, I hope the original sm once will return some of that kind of features because they might be useful in some situation, for example when you need to get the number of arguments which use sent to (any ...)
Use can send data like int, float by the AnyToStream(sBuf, 5, 5.0, 3, 5, 7) and get back using StreamToAny(sBuf, iData)
where iData is the
any[]
Minimum size of char buffer array should be not less then args * 4 + 1
PHP Code:
/**
* @brief Converts any parameter into a stream.
*
* @param sStream Input string buffer.
*/
void AnyToStream(char[] sStream, any ...)
{
// Initialize some variables
int iArgs; int nArg;
#emit load.s.pri 8
#emit stor.s.pri iArgs
sStream[iArgs * 5 - 4] = 0;
iArgs = 12 + iArgs * 4;
// i = byte index
for(int i = 16; i < iArgs; i += 4, nArg++)
{
#emit addr.alt 0
#emit load.s.pri i
#emit add
#emit load.i
#emit load.i
#emit push.pri
#emit load.s.pri nArg
#emit smul.c 5
#emit load.s.alt sStream
#emit add
#emit move.alt
#emit pop.pri
#emit stor.i
#emit move.pri
#emit add.c 4
#emit move.alt
#emit const.pri 16
#emit strb.i 0x1
for(int x = 0, y = nArg * 5; x != 4; x++)
{
if(sStream[y + x] == 0)
{
sStream[y + 4] |= (1<<x);
sStream[y + x] = 0xFF;
}
}
}
}
/**
* @brief Converts the stream in an any array.
*
* @param sStream Input stream buffer.
* @param iBuffer Output data array.
*/
int StreamToAny(char[] sStream, any[] iBuffer)
{
// Initialize some variables
int iCount = strlen(sStream) / 5, nTemp, iMagic;
// i = byte index
for(int i = 0; i < iCount; i++)
{
#emit load.s.alt sStream
#emit load.s.pri i
#emit smul.c 5
#emit add
#emit lodb.i 4
#emit addr.alt nTemp
#emit stor.i
if((iMagic = sStream[i * 5 + 4]) != 16)
{
if(iMagic & (1 << 0)) nTemp &= 0xFFFFFF00;
if(iMagic & (1 << 1)) nTemp &= 0xFFFF00FF;
if(iMagic & (1 << 2)) nTemp &= 0xFF00FFFF;
if(iMagic & (1 << 3)) nTemp &= 0x00FFFFFF;
}
iBuffer[i] = nTemp;
}
// Return amount
return iCount;
}
Some other lower performed examples:
Spoiler
PHP Code:
public void OnPluginStart()
{
PrintToServer("START");
char sBuf[6];
for(int i = cellmin; i < cellmax; i++)
{
strcopy(sBuf, sizeof sBuf, AnyToString(i));
if(StringToAny(sBuf) != i)
{
PrintToServer("ERROR");
}
}
PrintToServer("END");
}
char[] AnyToString(any Data)
{
char Buf[6];
#emit break
#emit load.s.pri Data
#emit stor.s.pri Buf
for(int i = 0; i != 4; i++)
{
if(Buf[i] == 0)
{
Buf[4] |= (1<<i);
Buf[i] = 0xFF;
}
}
return Buf;
}
any StringToAny(char[] Data)
{
char Buf[5];
#emit break
#emit addr.alt Buf
#emit load.s.pri Data
#emit movs 0x5
for(int i = 0; i != 4; i++)
{
if(Buf[4] & (1<<i))
{
Buf[i] = 0;
}
}
#emit break
#emit load.s.pri Buf
#emit stack 0x8
#emit retn
return 0;
}
public void OnPluginStart()
{
char fff[80];
AnyToString(fff, 240, 888, 111111, 0, 77777);
PrintToServer("strlen %d", strlen(fff));
int bbb[10];
int ff = StringToAny(fff, bbb);
for(int i = 0; i < ff; i++)
{
PrintToServer("%d", bbb[i]);
}
}
void AnyToString(char[] Buf, ...)
{
int num_args = 0, arg = 0;
#emit load.s.pri 8
#emit stor.s.pri num_args
Buf[num_args * 5 - 4] = 0;
num_args = 12 + num_args * 4;
for(int i = 16; i < num_args; i += 4, arg++)
{
#emit addr.alt 0
#emit load.s.pri i
#emit add
#emit load.i
#emit load.i
#emit push.pri //Запихаем полученное значение аргумента в стек
#emit load.s.pri arg
#emit smul.c 5
#emit load.s.alt Buf
#emit add
#emit move.alt
#emit pop.pri //Получили значение аргумента из стека
#emit stor.i
#emit move.pri
#emit add.c 4
#emit move.alt
#emit const.pri 16
#emit strb.i 0x1
for(int u = 0, pos = arg * 5; u != 4; u++)
{
if(Buf[pos + u] == 0)
{
Buf[pos + 4] |= (1<<u);
Buf[pos + u] = 0xFF;
}
}
}
}
int StringToAny(char[] Buf, any[] Data)
{
int count = strlen(Buf) / 5, magic;
for(int i = 0; i < count; i++)
{
#emit load.s.alt Data
#emit load.s.pri i
#emit idxaddr
#emit push.pri
#emit load.s.alt Buf
#emit load.s.pri i
#emit smul.c 5
#emit add
#emit lodb.i 4
#emit pop.alt
#emit stor.i
if ((magic = Buf[i * 5 + 4]) != 16)
{
for (int u = 0; u != 4; u++)
{
if (magic & (1 << u))
{
Data[i] &= ~(0xFF << (u * 8));
}
}
}
}
return count;
}
GitHub
__________________