mcmd Command Engine - Plugin based command processing -
Mellnik - 28.06.2014
mcmd - beta 0.0.1
This is the latest project I have been working on. mcmd, the first command processor which a) completely overwrites the default SA-MP command system and b) processes commands without PAWN interaction to pass OnPlayerCommandText parameters to the plugin. Even tho of it's memory hacking, it was designed to work with any version of the 0.3 branch.
Defining commands
To create commands, simply go to any location in your code and using following syntax. Commands are processed in lower case meaning /HellO is the same as /HELLo or /hello.
pawn Код:
mcmd:examplecommand(playerid, params[])
{
return 1;
}
Handling user input
To control any player input before the actual command gets executed, this callback is being called in the gamemode.
playerid | The id of the player who requested the command. |
cmdtext[] | The full command string including slash and parameters. |
|
exists | 1 = command was found in the script, 0 = command not found |
pawn Код:
forward OnPlayerRequestCommand(playerid, cmdtext[], exists);
Returning 0 stops any further processing of this command request, returning 1 calls the command as long as it exists. So giving the player an error if the command doesn't exist would be:
pawn Код:
public OnPlayerRequestCommand(playerid, cmdtext[], exists)
{
if(!exists)
{
SendClientMessage(playerid, 0xFFFFFFFF, "This command does not exist!");
return 0;
}
return 1;
}
Anti spam
mcmd provides an inbuild function to control command spam.
pawn Код:
native GetPlayerLastRequestTime(playerid);
This function returns the passed time since the last command request of a specific player. In other words, the time since the player sent a command to the server in
seconds (Will be milliseconds in future releases). To prevent command spam, you can restrict the player under OnPlayerRequestCommand. Exmaple:
pawn Код:
public OnPlayerRequestCommand(playerid, cmdtext[], exists)
{
if(GetPlayerLastRequestTime(playerid) < 1)
{
SendClientMessage(playerid, 0xFFFFFFFF, "You may only use 1 command per second!");
return 0; // Do not call the command
}
if(!exists)
{
SendClientMessage(playerid, 0xFFFFFFFF, "This command does not exist!");
return 0;
}
return 1;
}
How it works
Here are the assembly instructions from the SA-MP 0.3z R2-2 server where it calls OnPlayerCommandText.
http://i.imgur.com/veUXSa2.png
mcmd erases everything from 0x46AA17 to 0x46AA85 and places a JMP to the internal function
engine_opct_hook. cmdtext is located in register ebx and playerid in ebp, these are being pushed onto the stack and
engine_command_detour is being called.
Linux:
http://urlremoved/SAMP/mcmd/opct.txt
The return locations differ (See engine.c for more information). cmdtext is located at EBP-0x14, playerid at EBP+0xC.
Speed
I did not create this plugin to make a faster version of y_commands or any other cmd processor. It was more like out of fun since I do find reverse engineering really interesting. I had this idea in mind for a long time but wasn't able to accomplish it until recently. Anyways, here is the speedtest I did in the early phase of the plugin. To test mcmd I've created an additional native function to call the internal
engine_command_detour.
Quote:
Defaults:
100000 iterations
+2700 commands in the gamemode
custom callbacks enabled
3 cmd calls per iteration:
(0, "/first testparams yes")
(0, "/last testparams yes")
(0, "/none testparams yes")
Results:
mcmd: 199 ms
zcmd: 626 ms + internal OnPlayerCommandText execution from the samp-server (not measured)
|
Download
v0.0.1-beta for Windows:
https://github.com/Mellnik/mcmd/rele...-beta/mcmd.rar
Source hosted at GitHub
https://github.com/Mellnik/mcmd
Credits:
MyU for helping me with IDA
maddinat0r for general coding help
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Kathleen - 28.06.2014
First time i see a Command Processor inside a plugin :P
Anyway Good Job, Keep it up
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Snipa - 28.06.2014
Great job, fantastic times.
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Jessyy - 28.06.2014
try the second not first -
https://sampforum.blast.hk/showthread.php?tid=423815
AW: Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Mellnik - 28.06.2014
Quote:
Originally Posted by Jessyy
|
Read the thread.
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Pottus - 28.06.2014
It will be interesting to see what ****** says about this but your not after speed so I predict leniency.
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
PT - 28.06.2014
its interesting, but i dont know if is more secure than zcmd, i like to see what ****** says about this, i will whait to see.
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Whitetiger - 28.06.2014
love the implementation, but i find all that assembly shit fascinating. don't know how useful it REALLY is though considering commands speed has NEVER really been a problem since dcmd imo. and the memory hacking always means it may not be compatible in the future...
Re : mcmd Command Engine - Plugin based command processing - first of it's kind -
S4t3K - 28.06.2014
I'm curious about ****** and Kalcor's opinions (if either reads the thread obviously), but I'm really interested in this, so as soon as I can get an "expert" opinion (don't take it the wrong way), I'll be able to chose.
Anyway, really good job !
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
CyNiC - 28.06.2014
People ever try to speed up commands run as it were the priority to gain CPU use or something. I liked your find but not your objective, it's almost deprecated at least for me.
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Raefal - 28.06.2014
Wow nice job
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
[D]ry[D]esert - 29.06.2014
Fantastic
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
StreetGT - 29.06.2014
Nice work!
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
iFarbod - 29.06.2014
Nice job. i tested it's speed and i want to share the results :
Windows 7 Ultimate x64 :
Код:
[13:18:28] mcmd : 79 ms
[13:18:30] zcmd : 14 ms
[13:18:31] dcmd : 131 ms
[13:18:30] Normal command system (strcmp) : 127 ms
[13:18:33] Y_CMD : 11 ms
Re: mcmd Command Engine - Plugin based command processing - first of it's kind - Guest4390857394857 - 29.06.2014
Quote:
Originally Posted by iFarbod
Nice job. i tested it's speed and i want to share the results :
Windows 7 Ultimate x64 :
Код:
[13:18:28] mcmd : 79 ms
[13:18:30] zcmd : 14 ms
[13:18:31] dcmd : 131 ms
[13:18:30] Normal command system (strcmp) : 127 ms
[13:18:33] Y_CMD : 11 ms
|
WOW, HOw did you test it?
AW: Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Mellnik - 29.06.2014
Quote:
Originally Posted by Whitetiger
love the implementation, but i find all that assembly shit fascinating. don't know how useful it REALLY is though considering commands speed has NEVER really been a problem since dcmd imo. and the memory hacking always means it may not be compatible in the future...
|
As long as nothing changes regarding the command system mcmd should work with almost any version.
Quote:
Originally Posted by iFarbod
Nice job. i tested it's speed and i want to share the results :
Windows 7 Ultimate x64 :
Код:
[13:18:28] mcmd : 79 ms
[13:18:30] zcmd : 14 ms
[13:18:31] dcmd : 131 ms
[13:18:30] Normal command system (strcmp) : 127 ms
[13:18:33] Y_CMD : 11 ms
|
You did it the wrong way. Counting speed is only possible by creating a pipe to it's internal functions, even then it's not 100% accurate.
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
iZN - 29.06.2014
Ah, I always wanted to see some plugin based command processor. Really great work Mellnik.
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Schocc - 29.06.2014
liked the idea, + rep
Re: AW: Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
SlashPT - 30.06.2014
Quote:
Originally Posted by Mellnik
As long as nothing changes regarding the command system mcmd should work with almost any version.
You did it the wrong way. Counting speed is only possible by creating a pipe to it's internal functions, even then it's not 100% accurate.
|
No.. The speed must be measured by the run time it takes until pawn can call the next function.. and it seems it is slower than other command processors..
Re: mcmd Command Engine - Plugin based command processing - first of it's kind -
Inn0cent - 30.06.2014
Nice