Is this correct? (Assembly) - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is this correct? (Assembly) (
/showthread.php?tid=314881)
Is this correct? (Assembly) -
The King's Bastard - 31.01.2012
Hi.
I'm trying to make some dynamic language functions by using assembly language.
I've made a prototype and the tests were successful.
Prototype:
pawn Code:
#include <a_samp>
main()
{
SendClientMessage(7, 0xFF, "HAHA");
print("lol");
TestMsg(7, 0xFFAA, "Hi", "ROFLOLMAO", "It's workin'");
}
new MsgIdx = 2;
TestMsg(playerid, color, const message[], ...)
{
new arg = 0x14 + 4 * MsgIdx;
#emit LCTRL 5
#emit LOAD.S.alt arg
#emit ADD
#emit LOAD.I
#emit PUSH.pri //
//#emit PUSH.S 0x10 // color, for SCM
//#emit PUSH.S 0xc // playerid, for SCM
#emit PUSH.C 0xc
#emit SYSREQ.c print
#emit STACK 0xc
//#emit STACK 0x14, for SCM
#emit ZERO.pri
#emit RETN
#pragma unused playerid
#pragma unused color
#pragma unused message
return 0;
}
Now I wanted to extend this to my desired functions:
pawn Code:
stock SendMessage(playerid, stdmsg[], ...)
{
new
var = 0x10 + 4 * max(0, min(numargs() - 2, Player.Language[playerid]));
// Get frame pointer
#emit LCTRL 5
// Add offset (var)
#emit LOAD.S.alt var
#emit ADD
// Access desired string argument.
#emit LOAD.I
// Push argument.
#emit PUSH.pri // 0x10 + 4 * min(numargs() - 2, Player.Language[playerid]);
var = Player.Color[playerid];
#emit LCTRL 5
#emit LOAD.S.alt var
#emit ADD
#emit LOAD.I
#emit PUSH.pri // Player.Color[playerid]
#emit PUSH.S 0xC // playerid
#emit PUSH.C 0xC
#emit SYSREQ.C SendClientMessage
#emit STACK 0x14
#emit ZERO.pri
#emit RETN
#pragma unused stdmsg
return 0;
}
stock SendMessageToAll(stdmsg[], ...)
{
new
var,
i;
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i) && !IsPlayerNPC(i))
{
var = 0xC + 4 * max(0, min(numargs() - 2, Player.Language[i]));
#emit LCTRL 5
#emit LOAD.S.alt var
#emit ADD
#emit LOAD.I
#emit PUSH.pri
// Now push Player.Color[playerid]
var = Player.Color[playerid];
#emit LCTRL 5
#emit LOAD.S.alt var
#emit ADD
#emit LOAD.I
#emit PUSH.pri // Player.Color[playerid]
// Push i
#emit LCTRL 5
#emit LOAD.S.alt i
#emit ADD
#emit LOAD.I
#emit PUSH.pri // i
// Done.
#emit PUSH.C 0xC // Size of arguments (12 bytes)
#emit SYSREQ.C SendClientMessage
#emit STACK 0xC
}
}
return 0;
}
Please ignore the weird
Player. syntax.
I can't really test this function since I do not have all my scripts with me and I also haven't got GTA SA where I am right now...
So tell me guys, is this correct?