Gu3st...
2011-01-20 18:27:36
I present to you; The new Extra system!
This system makes it possible for users to activate/deactivate extras on-fly if they want to, and it will allow Extra writers to take advantage of the include.
It's also possible to add activate/deactivate form to the MSI Form.
It's still possible to use the old "system" even though we have this system, but with this system, the user is allowed to do much more advanced things, and will make the job of making extras work with the include much easier!
With this system, extras can be loaded into memory using the variable MSI_Extras, which is an array of TExtra:
All those things that I listed there except PointerCount and Pointers are self-explanatory. Pointers is an array of TPointer:
This means scripters can make their Extra do stuff when MSI calls functions. This can be very helpful in some cases (One example is MSI_Walk. It would benefit a WorldWalker to hook that function).
Now we'll get to the new Extras.simba. In this function MSI will call the function LoadAllExtras:
What this procedure does is to check all the files in the Extra folder for a function named *Extra_Name*_Attach, and if found it'll try calling that function. If the function cannot be called, that means that either 1. The file is not included in Setup.simba, or 2. It's included but it has {$DEFINE} tags around it.
All we (Devs) have to do is to add functionality to the procedures and function we want the user to be able to hook with (Obviously we don't want scripters to be able to hook SetupMSI and stuff like that). We'll do this by adding this:
The difference between this system and the old one, is that we don't have to edit a lot of code in order for it to work. With the old one, if a user wanted to use cstrike's WorldWalker, (s)he'd have to locate MSI_Walk and add it in, now we can make the Extra do that itself, meaning less work for us, and less work for scripters. :) Win win!
On a side-note; I'd like to have a name-change. Extra -> Plugin
And someone please make a new sub-forum in MSI for Extras (/Plugins)? :)
I will be adding an example later. It wont take me long to write on up for you though :)
This system makes it possible for users to activate/deactivate extras on-fly if they want to, and it will allow Extra writers to take advantage of the include.
It's also possible to add activate/deactivate form to the MSI Form.
It's still possible to use the old "system" even though we have this system, but with this system, the user is allowed to do much more advanced things, and will make the job of making extras work with the include much easier!
With this system, extras can be loaded into memory using the variable MSI_Extras, which is an array of TExtra:
type
TExtra = record
Name, Author, Version : String;
Setup : function: Boolean;
Enabled : Boolean;
PointerCount, Constant : Integer;
Pointers : TPointerArray;
end;As you can see, TExtra has information about the name of the extra, the author, the version, what function it uses to initialize the extra, if it's enabled or not (user setting) and Constant and some other stuff (PointerCount, Pointers).All those things that I listed there except PointerCount and Pointers are self-explanatory. Pointers is an array of TPointer:
type
TPointer = record
Constant : Integer;
FunctionCall : function: Integer;
end;TPointer has two variables. Constant can be MSI_onMSIWalkCall, MSI_onMSIDebugCall and so on and FunctionCall is the function to call when the function associated with the proper Constant (MSI_onFunctionXCall) is called.This means scripters can make their Extra do stuff when MSI calls functions. This can be very helpful in some cases (One example is MSI_Walk. It would benefit a WorldWalker to hook that function).
Now we'll get to the new Extras.simba. In this function MSI will call the function LoadAllExtras:
procedure MSI_LoadAllExtras;
var
Extras : TStringArray;
H, I : Integer;
V : TVariantArray;
NotUsing : Boolean;
begin
Extras := GetFiles(PATH_EXTRAS, 'simba');
SetArrayLength(MSI_Extras, Length(Extras));
if Length(Extras) = 0 then Exit;
H := High(Extras);
for I := 0 to H do
Delete(Extras[I], Pos('.', Extras[I]), Length(Extras[I]));
H := High(MSI_Extras);
for I := 0 to H do
begin
CurrentExtra := I;
NotUsing := False;
try
CallProc(Extras[CurrentExtra] + '_Attach', V);
WriteLn('Using Extra ''' + MSI_Extras[CurrentExtra].Name + ''' by ' + MSI_Extras[CurrentExtra].Author + ', v ' + MSI_Extras[CurrentExtra].Version + '.');
except
NotUsing := True;
end;
if NotUsing then
begin
WriteLn('Not using Extra ''' + Extras[CurrentExtra] + '''. Attach function not found.');
Continue;
end;
if MSI_Extras[CurrentExtra].Setup <> nil then
begin
if MSI_Extras[CurrentExtra].Setup() then
begin
MSI_Extras[CurrentExtra].Constant := CurrentExtra;
MSI_Extras[CurrentExtra].Enabled := True;
end;
end else
begin
WriteLn('Not using Extra ''' + Extras[CurrentExtra] + '''. Setup function not found.');
Continue;
end;
if MSI_Extras[CurrentExtra].PointerCount > 0 then
begin
H := High(MSI_Extras[CurrentExtra].Pointers);
if H <> 0 then
for I := 0 to H do
begin
WriteLn([CurrentExtra, I, H]);
if MSI_Pointers[MSI_Extras[CurrentExtra].Pointers[I].Constant].FunctionCall <> nil then
begin
WriteLn('Pointer already used! Turning off ' + MSI_Extras[CurrentExtra].Name + '...');
MSI_Extras[CurrentExtra].Enabled := False; // There's a bug here. Will fix later!
Break;
end else
begin
MSI_Pointers[MSI_Extras[CurrentExtra].Pointers[I].Constant].FunctionCall := MSI_Extras[CurrentExtra].Pointers[I].FunctionCall;
WriteLn('Pointer used: ' + IntToStr(MSI_Extras[CurrentExtra].Pointers[I].Constant) + '.');
end;
end;
end;
end;
end;What this procedure does is to check all the files in the Extra folder for a function named *Extra_Name*_Attach, and if found it'll try calling that function. If the function cannot be called, that means that either 1. The file is not included in Setup.simba, or 2. It's included but it has {$DEFINE} tags around it.
All we (Devs) have to do is to add functionality to the procedures and function we want the user to be able to hook with (Obviously we don't want scripters to be able to hook SetupMSI and stuff like that). We'll do this by adding this:
if MSI_Pointers[MSI_on_FunctionHere_Cal].FunctionCall <> nil then
case MSI_Pointers[MSI_on_FunctionHere_Call].FunctionCall() of
EXTRA_CONTINUE: ;
EXTRA_EXIT: Exit;
end;To the function and procedures that we want the scripters to be able to hook, and replace "FunctionHere" with the name of the function (I.E MSI_Walk).The difference between this system and the old one, is that we don't have to edit a lot of code in order for it to work. With the old one, if a user wanted to use cstrike's WorldWalker, (s)he'd have to locate MSI_Walk and add it in, now we can make the Extra do that itself, meaning less work for us, and less work for scripters. :) Win win!
On a side-note; I'd like to have a name-change. Extra -> Plugin
And someone please make a new sub-forum in MSI for Extras (/Plugins)? :)
I will be adding an example later. It wont take me long to write on up for you though :)