SRL Archive - MSI Tutorials

HOW-TO: Making Extras!


Gu3st...

2011-05-13 17:47:18

So you want to help MSI but don't want to mess around with the core of MSI too much? That's fine too! With the Extras system you can hook MSI's functions and use them to your advantage :)

In this tutorial I will give you a short introduction to the extra system and explain the extra "Example.simba" found in the /Extras/ folder by default.

The system was made so that people can develop things like Auto-responders and world walkers. The users of MSI can choose what extras to use and test before (maybe) getting added to the MSI core itself.

In each and every extra, we have at least 2 procedures:
- procedure ExampleName_Attach;
- function ExampleName_Init;

ExampleName_Attach; is for loading information about the extra to MSI_Extras and should always look quite similar to this:
procedure ExampleName_Attach;
begin
with MSI_Extras[CurrentExtra] do
begin
Name := 'ExampleName Extra'; // Name of the extra. I.E "Zyt3x_WorldWalker"
Author := 'The MSI Team'; // Name of the Author of the extra. I.E "Zyt3x"
Version := EXTRA_BETA; // What version the extra is at. This is stored as a string, so you can change it to whatever you'd want. I.E 'v127.0.0.1:25565 Beta Build'
Setup := @Example_Init; // A pointer to your extra's initialize procedure.

PointerCount := 1; // We'll get back to pointers later on.
SetArrayLength(Pointers, PointerCount);
with Pointers[0] do
begin
Constant := MSI_onProcedureCall; // The procedure to hook.
FunctionCall := 'Example_Procedure'; // The procedure to call.
end;
end;
end;

ExampleName_Init; could look like anything, but the result should always be a Boolean. (function ExampleName_Init: Boolean;).
If the extra doesn't require any loading, simply make it like this:
function ExampleName_Init: Boolean;
begin
Result := True;
end;

These are the only two procedures that's required for each and every extra.

Now for the actual hooking.

The system is based on pointers and hooking of MSI's procedures and functions.
You could literary hook any* procedure or function inside MSI. *=Any procedure/function we allow you to hook. We wont like it if you hook login functions and such.

The pointer system works like this:
1. The original function is called.
2. The system checks if any extra has requested this function to be hooked.
3. If 2 returns true then the system will call the function you'd like to replace with MSI's original function. I.E you want to hook MSI_Debug and replace it with ExmapleName_Debug.

If you'd like to hook MSI_Debug then you'd have to add this to your ExampleName_Attach:
    PointerCount := 1;
SetArrayLength(Pointers, PointerCount);
with Pointers[0] do
begin
Constant := MSI_OnDebugCall; // The procedure to hook.
FunctionCall := 'ExampleName_Debug'; // The procedure to call.
end;
If you'd like to hook more than one procedure/function then increase PointerCount and add one more "with Pointers[] do…end;" block.
Remember: MSI will port all the parameters of the function you hook to your version of the function, so remember that if you hook MSI_Debug(S: String); then you have to make sure your ExampleName_Debug has S : String as one of the parameters.


I think that's about it for now.
If several extras tries to hook one common function/procedure, then one of the extra's will get disabled, so make sure you aren't hooking a function some other extra is hooking or else someone will get mad at you for not doing your job properly :P

footballjds

2011-05-13 17:53:17

you sir should have 2 MSI cups

Gu3st...

2011-05-13 18:06:00

From: footballjds
you sir should have 2 MSI cups
Hahah thanks :) If any, Coh3n and NCDS is the ones who deserve that ;)

footballjds

2011-05-13 18:07:07

From: Zyt3x
Hahah thanks :) If any, Coh3n and NCDS is the ones who deserve that ;)


Coh3n should have 4 :p

this looks cool Zyt3x, i'll stop posting spam and actually try this out :D