aboutsummaryrefslogtreecommitdiffstats
path: root/Game
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-06-08 10:05:48 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-06-08 10:05:48 +0000
commitbe27cafddf3134820fbef437a4dfa47e467f097f (patch)
tree0be9c0a0f82c7886d15a9b5e99be89d35e5c37e8 /Game
parent920a63a63cb123957adeffbbb51da04b16e92559 (diff)
downloadusdx-be27cafddf3134820fbef437a4dfa47e467f097f.tar.gz
usdx-be27cafddf3134820fbef437a4dfa47e467f097f.tar.xz
usdx-be27cafddf3134820fbef437a4dfa47e467f097f.zip
clean up
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1140 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game')
-rw-r--r--Game/Code/Classes/UCore.pas333
-rw-r--r--Game/Code/Classes/uPluginLoader.pas322
2 files changed, 324 insertions, 331 deletions
diff --git a/Game/Code/Classes/UCore.pas b/Game/Code/Classes/UCore.pas
index c19147ea..2e1304de 100644
--- a/Game/Code/Classes/UCore.pas
+++ b/Game/Code/Classes/UCore.pas
@@ -8,11 +8,13 @@ interface
{$I switches.inc}
-uses uPluginDefs,
- uCoreModule,
- UHooks,
- UServices,
- UModules;
+uses
+ uPluginDefs,
+ uCoreModule,
+ UHooks,
+ UServices,
+ UModules;
+
{*********************
TCore
Class manages all CoreModules, teh StartUp, teh MainLoop and the shutdown process
@@ -51,31 +53,31 @@ type
iCurExecuted: Integer;
iLastExecuted: Integer;
- Procedure SetCurExecuted(Value: Integer);
+ procedure SetCurExecuted(Value: Integer);
//Function Get all Modules and Creates them
- Function GetModules: Boolean;
+ function GetModules: Boolean;
//Loads Core and all Modules
- Function Load: Boolean;
+ function Load: Boolean;
//Inits Core and all Modules
- Function Init: Boolean;
+ function Init: Boolean;
//DeInits Core and all Modules
- Function DeInit: Boolean;
+ function DeInit: Boolean;
//Load the Core
- Function LoadCore: Boolean;
+ function LoadCore: Boolean;
//Init the Core
- Function InitCore: Boolean;
+ function InitCore: Boolean;
//DeInit the Core
- Function DeInitCore: Boolean;
+ function DeInitCore: Boolean;
//Called one Time per Frame
- Function MainLoop: Boolean;
+ function MainLoop: Boolean;
public
Hooks: THookManager; //Teh Hook Manager ;)
@@ -93,24 +95,24 @@ type
//---------------
//Main Methods to control the Core:
//---------------
- Constructor Create(const cName: String; const cVersion: LongWord);
+ constructor Create(const cName: String; const cVersion: LongWord);
//Starts Loading and Init Process. Then Runs MainLoop. DeInits on Shutdown
- Procedure Run;
+ procedure Run;
//Method for other Classes to get Pointer to a specific Module
- Function GetModulebyName(const Name: String): PCoreModule;
+ function GetModulebyName(const Name: String): PCoreModule;
//--------------
// Hook and Service Procs:
//--------------
- Function ShowMessage(wParam: TwParam; lParam: TlParam): integer; //Shows a Message (lParam: PChar Text, wParam: Symbol)
- Function ReportError(wParam: TwParam; lParam: TlParam): integer; //Shows a Message (wParam: Pchar(Message), lParam: PChar(Reportername))
- Function ReportDebug(wParam: TwParam; lParam: TlParam): integer; //Shows a Message (wParam: Pchar(Message), lParam: PChar(Reportername))
- Function Retranslate(wParam: TwParam; lParam: TlParam): integer; //Calls Translate hook
- Function ReloadTextures(wParam: TwParam; lParam: TlParam): integer; //Calls LoadTextures hook
- Function GetModuleInfo(wParam: TwParam; lParam: TlParam): integer; //If lParam = nil then get length of Moduleinfo Array. If lparam <> nil then write array of TModuleInfo to address at lparam
- Function GetApplicationHandle(wParam: TwParam; lParam: TlParam): integer; //Returns Application Handle
+ function ShowMessage(wParam: TwParam; lParam: TlParam): integer; //Shows a Message (lParam: PChar Text, wParam: Symbol)
+ function ReportError(wParam: TwParam; lParam: TlParam): integer; //Shows a Message (wParam: Pchar(Message), lParam: PChar(Reportername))
+ function ReportDebug(wParam: TwParam; lParam: TlParam): integer; //Shows a Message (wParam: Pchar(Message), lParam: PChar(Reportername))
+ function Retranslate(wParam: TwParam; lParam: TlParam): integer; //Calls Translate hook
+ function ReloadTextures(wParam: TwParam; lParam: TlParam): integer; //Calls LoadTextures hook
+ function GetModuleInfo(wParam: TwParam; lParam: TlParam): integer; //If lParam = nil then get length of Moduleinfo Array. If lparam <> nil then write array of TModuleInfo to address at lparam
+ function GetApplicationHandle(wParam: TwParam; lParam: TlParam): integer; //Returns Application Handle
end;
var
@@ -118,15 +120,16 @@ var
implementation
-uses {$IFDEF win32}
- Windows,
- {$ENDIF}
- SysUtils;
+uses
+ {$IFDEF win32}
+ Windows,
+ {$ENDIF}
+ SysUtils;
//-------------
// Create - Creates Class + Hook and Service Manager
//-------------
-Constructor TCore.Create(const cName: String; const cVersion: LongWord);
+constructor TCore.Create(const cName: String; const cVersion: LongWord);
begin
inherited Create;
@@ -145,134 +148,114 @@ end;
//-------------
//Starts Loading and Init Process. Then Runs MainLoop. DeInits on Shutdown
//-------------
-Procedure TCore.Run;
+procedure TCore.Run;
var
- noError: Boolean;
+ Success: Boolean;
+
+ procedure HandleError(const ErrorMsg: string);
+ begin
+ if (LastErrorString <> '') then
+ Self.ShowMessage(CORE_SM_ERROR, PChar(ErrorMsg + ': ' + LastErrorString))
+ else
+ Self.ShowMessage(CORE_SM_ERROR, PChar(ErrorMsg));
+
+ //DeInit
+ DeInit;
+ end;
+
begin
//Get Modules
- Try
- noError := GetModules;
- Except
- noError := False;
+ try
+ Success := GetModules();
+ except
+ Success := False;
+ end;
+
+ if (not Success) then
+ begin
+ HandleError('Error Getting Modules');
+ Exit;
end;
//Loading
- if (noError) then
+ try
+ Success := Load();
+ except
+ Success := False;
+ end;
+
+ if (not Success) then
begin
- Try
- noError := Load;
- Except
- noError := False;
- end;
+ HandleError('Error loading Modules');
+ Exit;
+ end;
- if (noError) then
- begin //Init
- Try
- noError := Init;
- Except
- noError := False;
- end;
+ //Init
+ try
+ Success := Init();
+ except
+ Success := False;
+ end;
- If noError then
- begin
- //Call Translate Hook
- noError := (Hooks.CallEventChain(hTranslate, 0, nil) = 0);
-
- If noError then
- begin //Calls LoadTextures Hook
- noError := (Hooks.CallEventChain(hLoadTextures, 0, nil) = 0);
-
- if noError then
- begin //Calls Loading Finished Hook
- noError := (Hooks.CallEventChain(hLoadingFinished, 0, nil) = 0);
-
- If noError then
- begin
- //Start MainLoop
- While noError do
- begin
- noError := MainLoop;
- // to-do : Call Display Draw here
- end;
- end
- else
- begin
- If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error calling LoadingFinished Hook: ' + LastErrorString))
- else
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error calling LoadingFinished Hook'));
- end;
- end
- else
- begin
- If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error loading textures: ' + LastErrorString))
- else
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error loading textures'));
- end;
- end
- else
- begin
- If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error translating: ' + LastErrorString))
- else
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error translating'));
- end;
-
- end
- else
- begin
- If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error initing Modules: ' + LastErrorString))
- else
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error initing Modules'));
- end;
- end
- else
- begin
- If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error loading Modules: ' + LastErrorString))
- else
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error loading Modules'));
- end;
- end
- else
+ if (not Success) then
begin
- If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error Getting Modules: ' + LastErrorString))
- else
- Self.ShowMessage(CORE_SM_ERROR, PChar('Error Getting Modules'));
+ HandleError('Error initing Modules');
+ Exit;
end;
- //DeInit
- DeInit;
+ //Call Translate Hook
+ if (Hooks.CallEventChain(hTranslate, 0, nil) <> 0) then
+ begin
+ HandleError('Error translating');
+ Exit;
+ end;
+
+ //Calls LoadTextures Hook
+ if (Hooks.CallEventChain(hLoadTextures, 0, nil) <> 0) then
+ begin
+ HandleError('Error loading textures');
+ Exit;
+ end;
+
+ //Calls Loading Finished Hook
+ if (Hooks.CallEventChain(hLoadingFinished, 0, nil) <> 0) then
+ begin
+ HandleError('Error calling LoadingFinished Hook');
+ Exit;
+ end;
+
+ //Start MainLoop
+ while Success do
+ begin
+ Success := MainLoop();
+ // to-do : Call Display Draw here
+ end;
end;
//-------------
//Called one Time per Frame
//-------------
-Function TCore.MainLoop: Boolean;
+function TCore.MainLoop: Boolean;
begin
Result := False;
-
end;
//-------------
//Function Get all Modules and Creates them
//-------------
-Function TCore.GetModules: Boolean;
+function TCore.GetModules: Boolean;
var
- I: Integer;
+ i: Integer;
begin
Result := False;
- for I := 0 to high(Modules) do
+ for i := 0 to high(Modules) do
begin
try
- Modules[I].NeedsDeInit := False;
- Modules[I].Module := CORE_MODULES_TO_LOAD[I].Create;
- Modules[I].Module.Info(@Modules[I].Info);
+ Modules[i].NeedsDeInit := False;
+ Modules[i].Module := CORE_MODULES_TO_LOAD[i].Create;
+ Modules[i].Module.Info(@Modules[i].Info);
except
- ReportError(Integer(PChar('Can''t get module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), PChar('Core'));
+ ReportError(Integer(PChar('Can''t get module #' + InttoStr(i) + ' "' + Modules[i].Info.Name + '"')), PChar('Core'));
Exit;
end;
end;
@@ -282,61 +265,65 @@ end;
//-------------
//Loads Core and all Modules
//-------------
-Function TCore.Load: Boolean;
+function TCore.Load: Boolean;
var
- I: Integer;
+ i: Integer;
begin
Result := LoadCore;
- I := 0;
- While ((Result = True) AND (I <= High(CORE_MODULES_TO_LOAD))) do
+ for i := 0 to High(CORE_MODULES_TO_LOAD) do
begin
try
- Result := Modules[I].Module.Load;
+ Result := Modules[i].Module.Load;
except
Result := False;
- ReportError(Integer(PChar('Error loading module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), PChar('Core'));
end;
- Inc(I);
+ if (not Result) then
+ begin
+ ReportError(Integer(PChar('Error loading module #' + InttoStr(i) + ' "' + Modules[i].Info.Name + '"')), PChar('Core'));
+ break;
+ end;
end;
end;
//-------------
//Inits Core and all Modules
//-------------
-Function TCore.Init: Boolean;
+function TCore.Init: Boolean;
var
- I: Integer;
+ i: Integer;
begin
Result := InitCore;
- I := 0;
- While ((Result = True) AND (I <= High(CORE_MODULES_TO_LOAD))) do
+ for i := 0 to High(CORE_MODULES_TO_LOAD) do
begin
try
- Result := Modules[I].Module.Init;
+ Result := Modules[i].Module.Init;
except
Result := False;
- ReportError(Integer(PChar('Error initing module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), PChar('Core'));
end;
- Modules[I].NeedsDeInit := Result;
- Inc(I);
+ if (not Result) then
+ begin
+ ReportError(Integer(PChar('Error initing module #' + InttoStr(i) + ' "' + Modules[i].Info.Name + '"')), PChar('Core'));
+ break;
+ end;
+
+ Modules[i].NeedsDeInit := Result;
end;
end;
//-------------
//DeInits Core and all Modules
//-------------
-Function TCore.DeInit: boolean;
-
+function TCore.DeInit: boolean;
var
i: integer;
-
begin
for i := High(CORE_MODULES_TO_LOAD) downto 0 do
+ begin
try
if (Modules[i].NeedsDeInit) then
Modules[i].Module.DeInit;
@@ -352,7 +339,7 @@ end;
//-------------
//Load the Core
//-------------
-Function TCore.LoadCore: Boolean;
+function TCore.LoadCore: Boolean;
begin
hLoadingFinished := Hooks.AddEvent('Core/LoadingFinished');
hMainLoop := Hooks.AddEvent('Core/MainLoop');
@@ -380,53 +367,53 @@ end;
//-------------
//Init the Core
//-------------
-Function TCore.InitCore: Boolean;
+function TCore.InitCore: Boolean;
begin
- //Dont Init s.th. atm.
+ //Don not init something atm.
result := true;
end;
//-------------
//DeInit the Core
//-------------
-Function TCore.DeInitCore: Boolean;
+function TCore.DeInitCore: Boolean;
begin
-
-
- // to-do : write TService-/HookManager.Free and call it here
+ // TODO: write TService-/HookManager.Free and call it here
Result := true;
end;
//-------------
-//Method for other Classes to get Pointer to a specific Module
+//Method for other classes to get pointer to a specific module
//-------------
-Function TCore.GetModulebyName(const Name: String): PCoreModule;
-var I: Integer;
+function TCore.GetModuleByName(const Name: String): PCoreModule;
+var i: Integer;
begin
Result := nil;
- For I := 0 to high(Modules) do
- If (Modules[I].Info.Name = Name) then
+ for i := 0 to High(Modules) do
+ begin
+ if (Modules[i].Info.Name = Name) then
begin
- Result := @Modules[I].Module;
+ Result := @Modules[i].Module;
Break;
end;
+ end;
end;
//-------------
// Shows a MessageDialog (lParam: PChar Text, wParam: Symbol)
//-------------
-Function TCore.ShowMessage(wParam: TwParam; lParam: TlParam): integer;
+function TCore.ShowMessage(wParam: TwParam; lParam: TlParam): integer;
{$IFDEF MSWINDOWS}
-var Params: Cardinal; // Auto Removed, Unused Variable
+var Params: Cardinal;
{$ENDIF}
begin
Result := -1;
{$IFDEF MSWINDOWS}
- If (lParam<>nil) then
+ if (lParam <> nil) then
begin
Params := MB_OK;
- Case wParam of
+ case wParam of
CORE_SM_ERROR: Params := Params or MB_ICONERROR;
CORE_SM_WARNING: Params := Params or MB_ICONWARNING;
CORE_SM_INFO: Params := Params or MB_ICONINFORMATION;
@@ -437,13 +424,13 @@ begin
end;
{$ENDIF}
- // to-do : write ShowMessage for other OSes
+ // TODO: write ShowMessage for other OSes
end;
//-------------
// Calls NewError HookChain (wParam: Pchar(Message), lParam: PChar(Reportername))
//-------------
-Function TCore.ReportError(wParam: TwParam; lParam: TlParam): integer;
+function TCore.ReportError(wParam: TwParam; lParam: TlParam): integer;
begin
//Update LastErrorReporter and LastErrorString
LastErrorReporter := String(PChar(lParam));
@@ -455,7 +442,7 @@ end;
//-------------
// Calls NewDebugInfo HookChain (wParam: Pchar(Message), lParam: PChar(Reportername))
//-------------
-Function TCore.ReportDebug(wParam: TwParam; lParam: TlParam): integer;
+function TCore.ReportDebug(wParam: TwParam; lParam: TlParam): integer;
begin
Hooks.CallEventChain(hDebug, wParam, lParam);
end;
@@ -463,7 +450,7 @@ end;
//-------------
// Calls Translate hook
//-------------
-Function TCore.Retranslate(wParam: TwParam; lParam: TlParam): integer;
+function TCore.Retranslate(wParam: TwParam; lParam: TlParam): integer;
begin
Hooks.CallEventChain(hTranslate, 1, nil);
end;
@@ -471,7 +458,7 @@ end;
//-------------
// Calls LoadTextures hook
//-------------
-Function TCore.ReloadTextures(wParam: TwParam; lParam: TlParam): integer;
+function TCore.ReloadTextures(wParam: TwParam; lParam: TlParam): integer;
begin
Hooks.CallEventChain(hLoadTextures, 1, nil);
end;
@@ -479,7 +466,7 @@ end;
//-------------
// If lParam = nil then get length of Moduleinfo Array. If lparam <> nil then write array of TModuleInfo to address at lparam
//-------------
-Function TCore.GetModuleInfo(wParam: TwParam; lParam: TlParam): integer;
+function TCore.GetModuleInfo(wParam: TwParam; lParam: TlParam): integer;
begin
if (Pointer(lParam) = nil) then
begin
@@ -487,14 +474,14 @@ begin
end
else
begin
- Try
- For Result := 0 to High(Modules) do
+ try
+ for Result := 0 to High(Modules) do
begin
AModuleInfo(Pointer(lParam))[Result].Name := Modules[Result].Info.Name;
AModuleInfo(Pointer(lParam))[Result].Version := Modules[Result].Info.Version;
AModuleInfo(Pointer(lParam))[Result].Description := Modules[Result].Info.Description;
end;
- Except
+ except
Result := -1;
end;
end;
@@ -503,7 +490,7 @@ end;
//-------------
// Returns Application Handle
//-------------
-Function TCore.GetApplicationHandle(wParam: TwParam; lParam: TlParam): integer;
+function TCore.GetApplicationHandle(wParam: TwParam; lParam: TlParam): integer;
begin
Result := hInstance;
end;
@@ -511,7 +498,7 @@ end;
//-------------
// Called when setting CurExecuted
//-------------
-Procedure TCore.SetCurExecuted(Value: Integer);
+procedure TCore.SetCurExecuted(Value: Integer);
begin
//Set Last Executed
iLastExecuted := iCurExecuted;
diff --git a/Game/Code/Classes/uPluginLoader.pas b/Game/Code/Classes/uPluginLoader.pas
index 00a6714c..f4b6a87a 100644
--- a/Game/Code/Classes/uPluginLoader.pas
+++ b/Game/Code/Classes/uPluginLoader.pas
@@ -14,7 +14,9 @@ interface
{$I switches.inc}
-uses UPluginDefs, UCoreModule;
+uses
+ UPluginDefs,
+ UCoreModule;
type
TPluginListItem = record
@@ -42,33 +44,33 @@ type
sGetPluginInfo: THandle;
sGetPluginState: THandle;
- Procedure FreePlugin(Index: Cardinal);
+ procedure FreePlugin(Index: Cardinal);
public
PluginInterface: TUS_PluginInterface;
- Plugins: Array of TPluginListItem;
+ Plugins: array of TPluginListItem;
//TCoreModule methods to inherit
- Constructor Create; override;
- Procedure Info(const pInfo: PModuleInfo); override;
- Function Load: Boolean; override;
- Function Init: Boolean; override;
- Procedure DeInit; override;
+ constructor Create; override;
+ procedure Info(const pInfo: PModuleInfo); override;
+ function Load: Boolean; override;
+ function Init: Boolean; override;
+ procedure DeInit; override;
Destructor Destroy; override;
//New Methods
- Procedure BrowseDir(Path: String); //Browses the Path at _Path_ for Plugins
- Function PluginExists(Name: String): Integer; //If Plugin Exists: Index of Plugin, else -1
- Procedure AddPlugin(Filename: String);//Adds Plugin to the Array
+ procedure BrowseDir(Path: String); //Browses the Path at _Path_ for Plugins
+ function PluginExists(Name: String): integer; //If Plugin Exists: Index of Plugin, else -1
+ procedure AddPlugin(Filename: String);//Adds Plugin to the Array
- Function CallLoad(Index: Cardinal): Integer;
- Function CallInit(Index: Cardinal): Integer;
- Procedure CallDeInit(Index: Cardinal);
+ function CallLoad(Index: Cardinal): integer;
+ function CallInit(Index: Cardinal): integer;
+ procedure CallDeInit(Index: Cardinal);
//Services offered
- Function LoadPlugin(wParam: TwParam; lParam: TlParam): Integer; //wParam PChar(PluginName/PluginPath) | lParam (if wParam = nil) ID of the Plugin
- Function UnloadPlugin(wParam: TwParam; lParam: TlParam): Integer; //wParam PChar(PluginName/PluginPath) | lParam (if wParam = nil) ID of the Plugin
- Function GetPluginInfo(wParam: TwParam; lParam: TlParam): Integer; //If wParam = -1 then (If lParam = nil then get length of Moduleinfo Array. If lparam <> nil then write array of TUS_PluginInfo to address at lparam) Else (Get PluginInfo of Plugin with Index(wParam) to Address at lParam)
- Function GetPluginState(wParam: TwParam; lParam: TlParam): Integer; //If wParam = -1 then (If lParam = nil then get length of Moduleinfo Array. If lparam <> nil then write array of TUS_PluginInfo to address at lparam) Else (Return PluginInfo of Plugin with Index(wParam))
+ function LoadPlugin(wParam: TwParam; lParam: TlParam): integer; //wParam PChar(PluginName/PluginPath) | lParam (if wParam = nil) ID of the Plugin
+ function UnloadPlugin(wParam: TwParam; lParam: TlParam): integer; //wParam PChar(PluginName/PluginPath) | lParam (if wParam = nil) ID of the Plugin
+ function GetPluginInfo(wParam: TwParam; lParam: TlParam): integer; //If wParam = -1 then (If lParam = nil then get length of Moduleinfo Array. If lparam <> nil then write array of TUS_PluginInfo to address at lparam) else (Get PluginInfo of Plugin with Index(wParam) to Address at lParam)
+ function GetPluginState(wParam: TwParam; lParam: TlParam): integer; //If wParam = -1 then (If lParam = nil then get length of Moduleinfo Array. If lparam <> nil then write array of TUS_PluginInfo to address at lparam) else (Return PluginInfo of Plugin with Index(wParam))
end;
@@ -82,12 +84,12 @@ type
PluginLoader: PPluginLoader;
public
//TCoreModule methods to inherit
- Constructor Create; override;
+ constructor Create; override;
- Procedure Info(const pInfo: PModuleInfo); override;
- Function Load: Boolean; override;
- Function Init: Boolean; override;
- Procedure DeInit; override;
+ procedure Info(const pInfo: PModuleInfo); override;
+ function Load: Boolean; override;
+ function Init: Boolean; override;
+ procedure DeInit; override;
end;
const
@@ -102,13 +104,17 @@ const
{$ENDIF}
implementation
-uses UCore, UPluginInterface,
+
+uses
+ UCore,
+ UPluginInterface,
{$IFDEF MSWINDOWS}
windows,
{$ELSE}
dynlibs,
{$ENDIF}
-UMain, SysUtils;
+ UMain,
+ SysUtils;
{*********************
TPluginLoader
@@ -116,9 +122,9 @@ UMain, SysUtils;
*********************}
//-------------
-// Function that gives some Infos about the Module to the Core
+// function that gives some Infos about the Module to the Core
//-------------
-Procedure TPluginLoader.Info(const pInfo: PModuleInfo);
+procedure TPluginLoader.Info(const pInfo: PModuleInfo);
begin
pInfo^.Name := 'TPluginLoader';
pInfo^.Version := MakeVersion(1,0,0,chr(0));
@@ -128,7 +134,7 @@ end;
//-------------
// Just the Constructor
//-------------
-Constructor TPluginLoader.Create;
+constructor TPluginLoader.Create;
begin
inherited;
@@ -156,16 +162,16 @@ end;
//to offer them to other Modules or Plugins during the Init process
//If False is Returned this will cause a Forced Exit
//-------------
-Function TPluginLoader.Load: Boolean;
+function TPluginLoader.Load: Boolean;
begin
Result := True;
- Try
+ try
//Start Searching for Plugins
BrowseDir(PluginPath);
- Except
+ except
Result := False;
- Core.ReportError(Integer(PChar('Error Browsing and Loading.')), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Error Browsing and Loading.')), PChar('TPluginLoader'));
end;
end;
@@ -175,7 +181,7 @@ end;
//your Classes, Variables etc.
//If False is Returned this will cause a Forced Exit
//-------------
-Function TPluginLoader.Init: Boolean;
+function TPluginLoader.Init: Boolean;
begin
//Just set Prvate Var to true.
LoadingProcessFinished := True;
@@ -186,15 +192,15 @@ end;
//Is Called if this Module has been Inited and there is a Exit.
//Deinit is in backwards Initing Order
//-------------
-Procedure TPluginLoader.DeInit;
+procedure TPluginLoader.DeInit;
var
- I: Integer;
+ I: integer;
begin
//Force DeInit
//If some Plugins aren't DeInited for some Reason o0
- For I := 0 to High(Plugins) do
+ for I := 0 to High(Plugins) do
begin
- If (Plugins[I].State < 4) then
+ if (Plugins[I].State < 4) then
FreePlugin(I);
end;
@@ -215,7 +221,7 @@ end;
//--------------
// Browses the Path at _Path_ for Plugins
//--------------
-Procedure TPluginLoader.BrowseDir(Path: String);
+procedure TPluginLoader.BrowseDir(Path: String);
var
SR: TSearchRec;
begin
@@ -241,15 +247,15 @@ end;
//--------------
// If Plugin Exists: Index of Plugin, else -1
//--------------
-Function TPluginLoader.PluginExists(Name: String): Integer;
+function TPluginLoader.PluginExists(Name: String): integer;
var
- I: Integer;
+ I: integer;
begin
Result := -1;
- If (Length(Name) <= 32 { =>Length(TUS_PluginInfo.Name)}) then
+ if (Length(Name) <= 32 { =>Length(TUS_PluginInfo.Name)}) then
begin
- For I := 0 to High(Plugins) do
+ for I := 0 to High(Plugins) do
if (Plugins[I].Info.Name = Name) then
begin //Found the Plugin
Result := I;
@@ -261,39 +267,39 @@ end;
//--------------
// Adds Plugin to the Array
//--------------
-Procedure TPluginLoader.AddPlugin(Filename: String);
+procedure TPluginLoader.AddPlugin(Filename: String);
var
hLib: THandle;
PInfo: Proc_PluginInfo;
Info: TUS_PluginInfo;
- PluginID: Integer;
+ PluginID: integer;
begin
- If (FileExists(Filename)) then
+ if (FileExists(Filename)) then
begin //Load Libary
hLib := LoadLibrary(PChar(Filename));
- If (hLib <> 0) then
+ if (hLib <> 0) then
begin //Try to get Address of the Info Proc
PInfo := GetProcAddress (hLib, PChar('USPlugin_Info'));
- If (@PInfo <> nil) then
+ if (@PInfo <> nil) then
begin
Info.cbSize := SizeOf(TUS_PluginInfo);
- Try //Call Info Proc
+ try //Call Info Proc
PInfo(@Info);
- Except
+ except
Info.Name := '';
- Core.ReportError(Integer(PChar('Error getting Plugin Info: ' + Filename)), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Error getting Plugin Info: ' + Filename)), PChar('TPluginLoader'));
end;
//Is Name set ?
- If (Trim(Info.Name) <> '') then
+ if (Trim(Info.Name) <> '') then
begin
PluginID := PluginExists(Info.Name);
- If (PluginID > 0) AND (Plugins[PluginID].State >=4) then
+ if (PluginID > 0) and (Plugins[PluginID].State >=4) then
PluginID := -1;
- If (PluginID = -1) then
+ if (PluginID = -1) then
begin
//Add new item to array
PluginID := Length(Plugins);
@@ -311,25 +317,25 @@ begin
Plugins[PluginID].Procs.Init := GetProcAddress (hLib, PChar('USPlugin_Init'));
Plugins[PluginID].Procs.DeInit := GetProcAddress (hLib, PChar('USPlugin_DeInit'));
- If (@Plugins[PluginID].Procs.Load = nil) OR (@Plugins[PluginID].Procs.Init = nil) OR (@Plugins[PluginID].Procs.DeInit = nil) then
+ if (@Plugins[PluginID].Procs.Load = nil) OR (@Plugins[PluginID].Procs.Init = nil) OR (@Plugins[PluginID].Procs.DeInit = nil) then
begin
Plugins[PluginID].State := 255;
FreeLibrary(hLib);
- Core.ReportError(Integer(PChar('Can''t get Plugin Procs from Libary: "' + Info.Name + '" ' + Filename)), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Can''t get Plugin Procs from Libary: "' + Info.Name + '" ' + Filename)), PChar('TPluginLoader'));
end;
//Emulate loading process if this Plugin is loaded to late
- If (LoadingProcessFinished) then
+ if (LoadingProcessFinished) then
begin
CallLoad(PluginID);
CallInit(PluginID);
end;
end
- Else If (LoadingProcessFinished = False) then
+ else if (LoadingProcessFinished = False) then
begin
- If (Plugins[PluginID].Info.Version < Info.Version) then
+ if (Plugins[PluginID].Info.Version < Info.Version) then
begin //Found newer Version of this Plugin
- Core.ReportDebug(Integer(PChar('Found a newer Version of Plugin: ' + String(Info.Name))), PChar('TPluginLoader'));
+ Core.ReportDebug(integer(PChar('Found a newer Version of Plugin: ' + String(Info.Name))), PChar('TPluginLoader'));
//Unload Old Plugin
UnloadPlugin(PluginID, nil);
@@ -346,11 +352,11 @@ begin
Plugins[PluginID].Procs.Init := GetProcAddress (hLib, PChar('USPlugin_Init'));
Plugins[PluginID].Procs.DeInit := GetProcAddress (hLib, PChar('USPlugin_DeInit'));
- If (@Plugins[PluginID].Procs.Load = nil) OR (@Plugins[PluginID].Procs.Init = nil) OR (@Plugins[PluginID].Procs.DeInit = nil) then
+ if (@Plugins[PluginID].Procs.Load = nil) OR (@Plugins[PluginID].Procs.Init = nil) OR (@Plugins[PluginID].Procs.DeInit = nil) then
begin
FreeLibrary(hLib);
Plugins[PluginID].State := 255;
- Core.ReportError(Integer(PChar('Can''t get Plugin Procs from Libary: "' + Info.Name + '" ' + Filename)), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Can''t get Plugin Procs from Libary: "' + Info.Name + '" ' + Filename)), PChar('TPluginLoader'));
end;
end
else
@@ -361,49 +367,49 @@ begin
else
begin
FreeLibrary(hLib);
- Core.ReportError(Integer(PChar('Plugin with this Name already exists: ' + String(Info.Name))), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Plugin with this Name already exists: ' + String(Info.Name))), PChar('TPluginLoader'));
end;
end
else
begin
FreeLibrary(hLib);
- Core.ReportError(Integer(PChar('No name reported: ' + Filename)), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('No name reported: ' + Filename)), PChar('TPluginLoader'));
end;
end
else
begin
FreeLibrary(hLib);
- Core.ReportError(Integer(PChar('Can''t find Info Procedure: ' + Filename)), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Can''t find Info procedure: ' + Filename)), PChar('TPluginLoader'));
end;
end
else
- Core.ReportError(Integer(PChar('Can''t load Plugin Libary: ' + Filename)), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Can''t load Plugin Libary: ' + Filename)), PChar('TPluginLoader'));
end;
end;
//--------------
// Calls Load Func of Plugin with the given Index
//--------------
-Function TPluginLoader.CallLoad(Index: Cardinal): Integer;
+function TPluginLoader.CallLoad(Index: Cardinal): integer;
begin
Result := -2;
- If(Index < Length(Plugins)) then
+ if(Index < Length(Plugins)) then
begin
- If (@Plugins[Index].Procs.Load <> nil) AND (Plugins[Index].State = 0) then
+ if (@Plugins[Index].Procs.Load <> nil) and (Plugins[Index].State = 0) then
begin
- Try
+ try
Result := Plugins[Index].Procs.Load(@PluginInterface);
- Except
+ except
Result := -3;
End;
- If (Result = 0) then
+ if (Result = 0) then
Plugins[Index].State := 1
- Else
+ else
begin
FreePlugin(Index);
Plugins[Index].State := 255;
- Core.ReportError(Integer(PChar('Error calling Load Function from Plugin: ' + String(Plugins[Index].Info.Name))), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Error calling Load function from Plugin: ' + String(Plugins[Index].Info.Name))), PChar('TPluginLoader'));
end;
end;
end;
@@ -412,29 +418,29 @@ end;
//--------------
// Calls Init Func of Plugin with the given Index
//--------------
-Function TPluginLoader.CallInit(Index: Cardinal): Integer;
+function TPluginLoader.CallInit(Index: Cardinal): integer;
begin
Result := -2;
- If(Index < Length(Plugins)) then
+ if(Index < Length(Plugins)) then
begin
- If (@Plugins[Index].Procs.Init <> nil) AND (Plugins[Index].State = 1) then
+ if (@Plugins[Index].Procs.Init <> nil) and (Plugins[Index].State = 1) then
begin
- Try
+ try
Result := Plugins[Index].Procs.Init(@PluginInterface);
- Except
+ except
Result := -3;
End;
- If (Result = 0) then
+ if (Result = 0) then
begin
Plugins[Index].State := 2;
Plugins[Index].NeedsDeInit := True;
end
- Else
+ else
begin
FreePlugin(Index);
Plugins[Index].State := 255;
- Core.ReportError(Integer(PChar('Error calling Init Function from Plugin: ' + String(Plugins[Index].Info.Name))), PChar('TPluginLoader'));
+ Core.ReportError(integer(PChar('Error calling Init function from Plugin: ' + String(Plugins[Index].Info.Name))), PChar('TPluginLoader'));
end;
end;
end;
@@ -443,16 +449,16 @@ end;
//--------------
// Calls DeInit Proc of Plugin with the given Index
//--------------
-Procedure TPluginLoader.CallDeInit(Index: Cardinal);
+procedure TPluginLoader.CallDeInit(Index: Cardinal);
begin
- If(Index < Length(Plugins)) then
+ if(Index < Length(Plugins)) then
begin
- If (Plugins[Index].State < 4) then
+ if (Plugins[Index].State < 4) then
begin
- If (@Plugins[Index].Procs.DeInit <> nil) and (Plugins[Index].NeedsDeInit) then
- Try
+ if (@Plugins[Index].Procs.DeInit <> nil) and (Plugins[Index].NeedsDeInit) then
+ try
Plugins[Index].Procs.DeInit(@PluginInterface);
- Except
+ except
End;
@@ -467,14 +473,14 @@ end;
//--------------
// Frees all Plugin Sources (Procs and Handles) - Helper for Deiniting Functions
//--------------
-Procedure TPluginLoader.FreePlugin(Index: Cardinal);
+procedure TPluginLoader.FreePlugin(Index: Cardinal);
begin
Plugins[Index].State := 4;
Plugins[Index].Procs.Load := nil;
Plugins[Index].Procs.Init := nil;
Plugins[Index].Procs.DeInit := nil;
- If (Plugins[Index].hLib <> 0) then
+ if (Plugins[Index].hLib <> 0) then
FreeLibrary(Plugins[Index].hLib);
end;
@@ -483,15 +489,15 @@ end;
//--------------
// wParam PChar(PluginName/PluginPath) | wParam (if lParam = nil) ID of the Plugin
//--------------
-Function TPluginLoader.LoadPlugin(wParam: TwParam; lParam: TlParam): Integer;
+function TPluginLoader.LoadPlugin(wParam: TwParam; lParam: TlParam): integer;
var
- Index: Integer;
+ Index: integer;
sFile: String;
begin
Result := -1;
sFile := '';
//lParam is ID
- If (lParam = nil) then
+ if (lParam = nil) then
begin
Index := wParam;
end
@@ -500,7 +506,7 @@ begin
try
sFile := String(PChar(lParam));
Index := PluginExists(sFile);
- If (Index < 0) And FileExists(sFile) then
+ if (Index < 0) And FileExists(sFile) then
begin //Is Filename
AddPlugin(sFile);
Result := Plugins[High(Plugins)].State;
@@ -511,7 +517,7 @@ begin
end;
- If (Index >= 0) and (Index < Length(Plugins)) then
+ if (Index >= 0) and (Index < Length(Plugins)) then
begin
AddPlugin(Plugins[Index].Path);
Result := Plugins[Index].State;
@@ -521,14 +527,14 @@ end;
//--------------
// wParam PChar(PluginName/PluginPath) | wParam (if lParam = nil) ID of the Plugin
//--------------
-Function TPluginLoader.UnloadPlugin(wParam: TwParam; lParam: TlParam): Integer;
+function TPluginLoader.UnloadPlugin(wParam: TwParam; lParam: TlParam): integer;
var
- Index: Integer;
+ Index: integer;
sName: String;
begin
Result := -1;
//lParam is ID
- If (lParam = nil) then
+ if (lParam = nil) then
begin
Index := wParam;
end
@@ -543,72 +549,72 @@ begin
end;
- If (Index >= 0) and (Index < Length(Plugins)) then
+ if (Index >= 0) and (Index < Length(Plugins)) then
CallDeInit(Index)
end;
//--------------
-// If wParam = -1 then (If lParam = nil then get length of Moduleinfo Array. If lparam <> nil then write array of TUS_PluginInfo to address at lparam) Else (Get PluginInfo of Plugin with Index(wParam) to Address at lParam)
+// if wParam = -1 then (if lParam = nil then get length of Moduleinfo Array. if lparam <> nil then write array of TUS_PluginInfo to address at lparam) else (Get PluginInfo of Plugin with Index(wParam) to Address at lParam)
//--------------
-Function TPluginLoader.GetPluginInfo(wParam: TwParam; lParam: TlParam): Integer;
-var I: Integer;
+function TPluginLoader.GetPluginInfo(wParam: TwParam; lParam: TlParam): integer;
+var I: integer;
begin
Result := 0;
- If (wParam > 0) then
+ if (wParam > 0) then
begin //Get Info of 1 Plugin
- If (lParam <> nil) AND (wParam < Length(Plugins)) then
+ if (lParam <> nil) and (wParam < Length(Plugins)) then
begin
- Try
+ try
Result := 1;
PUS_PluginInfo(lParam)^ := Plugins[wParam].Info;
- Except
+ except
End;
end;
end
- Else If (lParam = nil) then
+ else if (lParam = nil) then
begin //Get Length of Plugin (Info) Array
Result := Length(Plugins);
end
- Else //Write PluginInfo Array to Address in lParam
+ else //Write PluginInfo Array to Address in lParam
begin
- Try
- For I := 0 to high(Plugins) do
+ try
+ for I := 0 to high(Plugins) do
PAUS_PluginInfo(lParam)^[I] := Plugins[I].Info;
Result := Length(Plugins);
- Except
- Core.ReportError(Integer(PChar('Could not write PluginInfo Array')), PChar('TPluginLoader'));
+ except
+ Core.ReportError(integer(PChar('Could not write PluginInfo Array')), PChar('TPluginLoader'));
End;
end;
end;
//--------------
-// If wParam = -1 then (If lParam = nil then get length of Plugin State Array. If lparam <> nil then write array of Byte to address at lparam) Else (Return State of Plugin with Index(wParam))
+// if wParam = -1 then (if lParam = nil then get length of Plugin State Array. if lparam <> nil then write array of Byte to address at lparam) else (Return State of Plugin with Index(wParam))
//--------------
-Function TPluginLoader.GetPluginState(wParam: TwParam; lParam: TlParam): Integer;
-var I: Integer;
+function TPluginLoader.GetPluginState(wParam: TwParam; lParam: TlParam): integer;
+var I: integer;
begin
Result := -1;
- If (wParam > 0) then
+ if (wParam > 0) then
begin //Get State of 1 Plugin
- If (wParam < Length(Plugins)) then
+ if (wParam < Length(Plugins)) then
begin
Result := Plugins[wParam].State;
end;
end
- Else If (lParam = nil) then
+ else if (lParam = nil) then
begin //Get Length of Plugin (Info) Array
Result := Length(Plugins);
end
- Else //Write PluginInfo Array to Address in lParam
+ else //Write PluginInfo Array to Address in lParam
begin
- Try
- For I := 0 to high(Plugins) do
- Byte(Pointer(Integer(lParam) + I)^) := Plugins[I].State;
+ try
+ for I := 0 to high(Plugins) do
+ Byte(Pointer(integer(lParam) + I)^) := Plugins[I].State;
Result := Length(Plugins);
- Except
- Core.ReportError(Integer(PChar('Could not write PluginState Array')), PChar('TPluginLoader'));
+ except
+ Core.ReportError(integer(PChar('Could not write PluginState Array')), PChar('TPluginLoader'));
End;
end;
end;
@@ -620,9 +626,9 @@ end;
*********************}
//-------------
-// Function that gives some Infos about the Module to the Core
+// function that gives some Infos about the Module to the Core
//-------------
-Procedure TtehPlugins.Info(const pInfo: PModuleInfo);
+procedure TtehPlugins.Info(const pInfo: PModuleInfo);
begin
pInfo^.Name := 'TtehPlugins';
pInfo^.Version := MakeVersion(1,0,0,chr(0));
@@ -632,7 +638,7 @@ end;
//-------------
// Just the Constructor
//-------------
-Constructor TtehPlugins.Create;
+constructor TtehPlugins.Create;
begin
inherited;
PluginLoader := nil;
@@ -644,19 +650,17 @@ end;
//to offer them to other Modules or Plugins during the Init process
//If False is Returned this will cause a Forced Exit
//-------------
-Function TtehPlugins.Load: Boolean;
-
+function TtehPlugins.Load: Boolean;
var
- i: Integer; //Counter
- CurExecutedBackup: Integer; //backup of Core.CurExecuted Attribute
-
+ i: integer; //Counter
+ CurExecutedBackup: integer; //backup of Core.CurExecuted Attribute
begin
//Get Pointer to PluginLoader
PluginLoader := PPluginLoader(Core.GetModulebyName('TPluginLoader'));
if (PluginLoader = nil) then
begin
Result := false;
- Core.ReportError(Integer(PChar('Could not get Pointer to PluginLoader')), PChar('TtehPlugins'));
+ Core.ReportError(integer(PChar('Could not get Pointer to PluginLoader')), PChar('TtehPlugins'));
end
else
begin
@@ -667,28 +671,32 @@ begin
//Start Loading the Plugins
for i := 0 to High(PluginLoader.Plugins) do
- try
- Core.CurExecuted := -1 - i;
+ begin
+ Core.CurExecuted := -1 - i;
+ try
//Unload Plugin if not correctly Executed
if (PluginLoader.CallLoad(i) <> 0) then
begin
PluginLoader.CallDeInit(i);
PluginLoader.Plugins[i].State := 254; //Plugin asks for unload
- Core.ReportDebug(Integer(PChar('Plugin Selfabort during loading process: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
+ Core.ReportDebug(integer(PChar('Plugin Selfabort during loading process: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
end
else
- Core.ReportDebug(Integer(PChar('Plugin loaded succesful: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
+ begin
+ Core.ReportDebug(integer(PChar('Plugin loaded succesful: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
+ end;
except
- //Plugin could not be loaded.
- // => Show Error Message, then ShutDown Plugin
- on E: Exception do
- begin
- PluginLoader.CallDeInit(i);
- PluginLoader.Plugins[i].State := 255; //Plugin causes Error
- Core.ReportError(Integer(PChar('Plugin causes Error during loading process: ' + PluginLoader.Plugins[i].Info.Name + ', ErrorMsg: "' + E.Message + '"')), PChar('TtehPlugins'));
- end;
+ //Plugin could not be loaded.
+ // => Show Error Message, then ShutDown Plugin
+ on E: Exception do
+ begin
+ PluginLoader.CallDeInit(i);
+ PluginLoader.Plugins[i].State := 255; //Plugin causes Error
+ Core.ReportError(integer(PChar('Plugin causes Error during loading process: ' + PluginLoader.Plugins[i].Info.Name + ', ErrorMsg: "' + E.Message + '"')), PChar('TtehPlugins'));
+ end;
end;
+ end;
//Reset CurExecuted
Core.CurExecuted := CurExecutedBackup;
@@ -701,12 +709,10 @@ end;
//your Classes, Variables etc.
//If False is Returned this will cause a Forced Exit
//-------------
-Function TtehPlugins.Init: Boolean;
-
+function TtehPlugins.Init: Boolean;
var
- i: Integer; //Counter
- CurExecutedBackup: Integer; //backup of Core.CurExecuted Attribute
-
+ i: integer; //Counter
+ CurExecutedBackup: integer; //backup of Core.CurExecuted Attribute
begin
Result := true;
@@ -723,16 +729,16 @@ begin
begin
PluginLoader.CallDeInit(i);
PluginLoader.Plugins[i].State := 254; //Plugin asks for unload
- Core.ReportDebug(Integer(PChar('Plugin Selfabort during init process: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
+ Core.ReportDebug(integer(PChar('Plugin Selfabort during init process: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
end
else
- Core.ReportDebug(Integer(PChar('Plugin inited succesful: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
+ Core.ReportDebug(integer(PChar('Plugin inited succesful: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
except
//Plugin could not be loaded.
// => Show Error Message, then ShutDown Plugin
PluginLoader.CallDeInit(i);
PluginLoader.Plugins[i].State := 255; //Plugin causes Error
- Core.ReportError(Integer(PChar('Plugin causes Error during init process: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
+ Core.ReportError(integer(PChar('Plugin causes Error during init process: ' + String(PluginLoader.Plugins[i].Info.Name))), PChar('TtehPlugins'));
end;
//Reset CurExecuted
@@ -743,24 +749,24 @@ end;
//Is Called if this Module has been Inited and there is a Exit.
//Deinit is in backwards Initing Order
//-------------
-Procedure TtehPlugins.DeInit;
-
+procedure TtehPlugins.DeInit;
var
- i: Integer; //Counter
- CurExecutedBackup: Integer; //backup of Core.CurExecuted Attribute
-
+ i: integer; //Counter
+ CurExecutedBackup: integer; //backup of Core.CurExecuted Attribute
begin
//Backup CurExecuted
CurExecutedBackup := Core.CurExecuted;
//Start Loop
- for i := 0 to High(PluginLoader.Plugins)) do
+ for i := 0 to High(PluginLoader.Plugins) do
+ begin
try
//DeInit Plugin
PluginLoader.CallDeInit(i);
except
end;
+ end;
//Reset CurExecuted
Core.CurExecuted := CurExecutedBackup;