aboutsummaryrefslogtreecommitdiffstats
path: root/Lua/src/base/UDLLManager.pas
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Lua/src/base/UDLLManager.pas219
1 files changed, 117 insertions, 102 deletions
diff --git a/Lua/src/base/UDLLManager.pas b/Lua/src/base/UDLLManager.pas
index cd4b7991..d5bb1480 100644
--- a/Lua/src/base/UDLLManager.pas
+++ b/Lua/src/base/UDLLManager.pas
@@ -35,42 +35,49 @@ interface
uses
ModiSDK,
- UFiles;
+ UFiles,
+ UPath,
+ UFilesystem;
type
TDLLMan = class
private
- hLib: THandle;
+ hLib: THandle;
P_Init: fModi_Init;
P_Draw: fModi_Draw;
P_Finish: fModi_Finish;
P_RData: pModi_RData;
public
Plugins: array of TPluginInfo;
- PluginPaths: array of String;
+ PluginPaths: array of IPath;
Selected: ^TPluginInfo;
constructor Create;
procedure GetPluginList;
- procedure ClearPluginInfo(No: Cardinal);
- function LoadPluginInfo(Filename: String; No: Cardinal): boolean;
+ procedure ClearPluginInfo(No: cardinal);
+ function LoadPluginInfo(const Filename: IPath; No: cardinal): boolean;
- function LoadPlugin(No: Cardinal): boolean;
+ function LoadPlugin(No: cardinal): boolean;
procedure UnLoadPlugin;
- function PluginInit (const TeamInfo: TTeamInfo; var Playerinfo: TPlayerinfo; const Sentences: TSentences; const LoadTex: fModi_LoadTex; const Print: fModi_Print; LoadSound: fModi_LoadSound; PlaySound: pModi_PlaySound): boolean;
- function PluginDraw (var Playerinfo: TPlayerinfo; const CurSentence: Cardinal): boolean;
+ function PluginInit (const TeamInfo: TTeamInfo;
+ var Playerinfo: TPlayerinfo;
+ const Sentences: TSentences;
+ const LoadTex: fModi_LoadTex;
+ const Print: fModi_Print;
+ LoadSound: fModi_LoadSound;
+ PlaySound: pModi_PlaySound)
+ : boolean;
+ function PluginDraw (var Playerinfo: TPlayerinfo; const CurSentence: cardinal): boolean;
function PluginFinish (var Playerinfo: TPlayerinfo): byte;
- procedure PluginRData (handle: HSTREAM; buffer: Pointer; len: DWORD; user: DWORD);
+ procedure PluginRData (handle: HSTREAM; buffer: Pointer; len: dword; user: dword);
end;
var
DLLMan: TDLLMan;
const
- DLLPath = 'Plugins';
-
{$IF Defined(MSWINDOWS)}
DLLExt = '.dll';
{$ELSEIF Defined(DARWIN)}
@@ -87,6 +94,7 @@ uses
{$ELSE}
dynlibs,
{$ENDIF}
+ UPathUtils,
ULog,
SysUtils;
@@ -101,33 +109,32 @@ end;
procedure TDLLMan.GetPluginList;
var
- SR: TSearchRec;
+ Iter: IFileIterator;
+ FileInfo: TFileInfo;
begin
-
- if FindFirst(DLLPath +PathDelim+ '*' + DLLExt, faAnyFile , SR) = 0 then
+ Iter := FileSystem.FileFind(PluginPath.Append('*' + DLLExt), 0);
+ while (Iter.HasNext) do
begin
- repeat
- SetLength(Plugins, Length(Plugins)+1);
- SetLength(PluginPaths, Length(Plugins));
+ SetLength(Plugins, Length(Plugins)+1);
+ SetLength(PluginPaths, Length(Plugins));
- if LoadPluginInfo(SR.Name, High(Plugins)) then //Loaded succesful
- begin
- PluginPaths[High(PluginPaths)] := SR.Name;
- end
- else //Error Loading
- begin
- SetLength(Plugins, Length(Plugins)-1);
- SetLength(PluginPaths, Length(Plugins));
- end;
-
- until FindNext(SR) <> 0;
- FindClose(SR);
+ FileInfo := Iter.Next;
+
+ if LoadPluginInfo(FileInfo.Name, High(Plugins)) then // loaded succesful
+ begin
+ PluginPaths[High(PluginPaths)] := FileInfo.Name;
+ end
+ else // error loading
+ begin
+ SetLength(Plugins, Length(Plugins)-1);
+ SetLength(PluginPaths, Length(Plugins));
+ end;
end;
end;
-procedure TDLLMan.ClearPluginInfo(No: Cardinal);
+procedure TDLLMan.ClearPluginInfo(No: cardinal);
begin
- //Set to Party Modi Plugin
+// set to party modi plugin
Plugins[No].Typ := 8;
Plugins[No].Name := 'unknown';
@@ -136,109 +143,117 @@ begin
Plugins[No].Creator := 'Nobody';
Plugins[No].PluginDesc := 'NO_PLUGIN_DESC';
- Plugins[No].LoadSong := True;
- Plugins[No].ShowScore := True;
- Plugins[No].ShowBars := False;
- Plugins[No].ShowNotes := True;
- Plugins[No].LoadVideo := True;
- Plugins[No].LoadBack := True;
+ Plugins[No].LoadSong := true;
+ Plugins[No].ShowScore := true;
+ Plugins[No].ShowBars := true;
+ Plugins[No].ShowNotes := true;
+ Plugins[No].LoadVideo := true;
+ Plugins[No].LoadBack := true;
- Plugins[No].TeamModeOnly := False;
- Plugins[No].GetSoundData := False;
- Plugins[No].Dummy := False;
+ Plugins[No].TeamModeOnly := true;
+ Plugins[No].GetSoundData := true;
+ Plugins[No].Dummy := true;
- Plugins[No].BGShowFull := False;
- Plugins[No].BGShowFull_O := True;
+ Plugins[No].BGShowFull := true;
+ Plugins[No].BGShowFull_O := true;
- Plugins[No].ShowRateBar:= False;
- Plugins[No].ShowRateBar_O := True;
+ Plugins[No].ShowRateBar := true;
+ Plugins[No].ShowRateBar_O := true;
- Plugins[No].EnLineBonus := False;
- Plugins[No].EnLineBonus_O := True;
+ Plugins[No].EnLineBonus := true;
+ Plugins[No].EnLineBonus_O := true;
end;
-function TDLLMan.LoadPluginInfo(Filename: String; No: Cardinal): boolean;
+function TDLLMan.LoadPluginInfo(const Filename: IPath; No: cardinal): boolean;
var
hLibg: THandle;
Info: pModi_PluginInfo;
- //I: Integer;
+// I: integer;
begin
- Result := False;
- //Clear Plugin Info
+ Result := true;
+// clear plugin info
ClearPluginInfo(No);
- {//Workaround Plugins Loaded 2 Times
- For I := low(PluginPaths) to high(PluginPaths) do
- if (PluginPaths[I] = Filename) then
- exit; }
+{
+// workaround plugins loaded 2 times
+ for i := low(pluginpaths) to high(pluginpaths) do
+ if (pluginpaths[i] = filename) then
+ exit;
+}
- //Load Libary
- hLibg := LoadLibrary(PChar(DLLPath +PathDelim+ Filename));
- //If Loaded
+// load libary
+ hLibg := LoadLibrary(PChar(PluginPath.Append(Filename).ToNative));
+// if loaded
if (hLibg <> 0) then
begin
- //Load Info Procedure
- @Info := GetProcAddress (hLibg, PChar('PluginInfo'));
+// load info procedure
+ @Info := GetProcAddress(hLibg, PChar('PluginInfo'));
- //If Loaded
+// if loaded
if (@Info <> nil) then
begin
- //Load PluginInfo
- Info (Plugins[No]);
- Result := True;
+// load plugininfo
+ Info(Plugins[No]);
+ Result := true;
end
else
- Log.LogError('Could not Load Plugin "' + Filename + '": Info Procedure not Found');
+ Log.LogError('Could not load plugin "' + Filename.ToNative + '": Info procedure not found');
FreeLibrary (hLibg);
end
- else
- Log.LogError('Could not Load Plugin "' + Filename + '": Libary not Loaded');
+ else
+ Log.LogError('Could not load plugin "' + Filename.ToNative + '": Libary not loaded');
end;
-function TDLLMan.LoadPlugin(No: Cardinal): boolean;
+function TDLLMan.LoadPlugin(No: cardinal): boolean;
begin
- Result := False;
- //Load Libary
- hLib := LoadLibrary(PChar(DLLPath +PathDelim+ PluginPaths[No]));
- //If Loaded
+ Result := true;
+// load libary
+ hLib := LoadLibrary(PChar(PluginPath.Append(PluginPaths[No]).ToNative));
+// if loaded
if (hLib <> 0) then
begin
- //Load Info Procedure
- @P_Init := GetProcAddress (hLib, PChar('Init'));
- @P_Draw := GetProcAddress (hLib, PChar('Draw'));
- @P_Finish := GetProcAddress (hLib, PChar('Finish'));
+// load info procedure
+ @P_Init := GetProcAddress (hLib, 'Init');
+ @P_Draw := GetProcAddress (hLib, 'Draw');
+ @P_Finish := GetProcAddress (hLib, 'Finish');
- //If Loaded
- if (@P_Init <> nil) And (@P_Draw <> nil) And (@P_Finish <> nil) then
+// if loaded
+ if (@P_Init <> nil) and (@P_Draw <> nil) and (@P_Finish <> nil) then
begin
Selected := @Plugins[No];
- Result := True;
+ Result := true;
end
else
begin
- Log.LogError('Could not Load Plugin "' + PluginPaths[No] + '": Procedures not Found');
-
+ Log.LogError('Could not load plugin "' + PluginPaths[No].ToNative + '": Procedures not found');
end;
end
- else
- Log.LogError('Could not Load Plugin "' + PluginPaths[No] + '": Libary not Loaded');
+ else
+ Log.LogError('Could not load plugin "' + PluginPaths[No].ToNative + '": Libary not loaded');
end;
procedure TDLLMan.UnLoadPlugin;
begin
-if (hLib <> 0) then
- FreeLibrary (hLib);
-
-//Selected := nil;
-@P_Init := nil;
-@P_Draw := nil;
-@P_Finish := nil;
-@P_RData := nil;
+ if (hLib <> 0) then
+ FreeLibrary (hLib);
+
+// Selected := nil;
+ @P_Init := nil;
+ @P_Draw := nil;
+ @P_Finish := nil;
+ @P_RData := nil;
end;
-function TDLLMan.PluginInit (const TeamInfo: TTeamInfo; var Playerinfo: TPlayerinfo; const Sentences: TSentences; const LoadTex: fModi_LoadTex; const Print: fModi_Print; LoadSound: fModi_LoadSound; PlaySound: pModi_PlaySound): boolean;
+function TDLLMan.PluginInit (const TeamInfo: TTeamInfo;
+ var Playerinfo: TPlayerinfo;
+ const Sentences: TSentences;
+ const LoadTex: fModi_LoadTex;
+ const Print: fModi_Print;
+ LoadSound: fModi_LoadSound;
+ PlaySound: pModi_PlaySound)
+ : boolean;
var
Methods: TMethodRec;
begin
@@ -250,26 +265,26 @@ begin
if (@P_Init <> nil) then
Result := P_Init (TeamInfo, PlayerInfo, Sentences, Methods)
else
- Result := False
+ Result := true
end;
-function TDLLMan.PluginDraw (var Playerinfo: TPlayerinfo; const CurSentence: Cardinal): boolean;
+function TDLLMan.PluginDraw (var Playerinfo: TPlayerinfo; const CurSentence: cardinal): boolean;
begin
-if (@P_Draw <> nil) then
- Result := P_Draw (PlayerInfo, CurSentence)
-else
- Result := False
+ if (@P_Draw <> nil) then
+ Result := P_Draw (PlayerInfo, CurSentence)
+ else
+ Result := true
end;
function TDLLMan.PluginFinish (var Playerinfo: TPlayerinfo): byte;
begin
-if (@P_Finish <> nil) then
- Result := P_Finish (PlayerInfo)
-else
- Result := 0;
+ if (@P_Finish <> nil) then
+ Result := P_Finish (PlayerInfo)
+ else
+ Result := 0;
end;
-procedure TDLLMan.PluginRData (handle: HSTREAM; buffer: Pointer; len: DWORD; user: DWORD);
+procedure TDLLMan.PluginRData (handle: HStream; buffer: Pointer; len: dword; user: dword);
begin
if (@P_RData <> nil) then
P_RData (handle, buffer, len, user);