aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code
diff options
context:
space:
mode:
Diffstat (limited to 'Game/Code')
-rw-r--r--Game/Code/Classes/UCore.pas68
-rw-r--r--Game/Code/Classes/UHooks.pas10
-rw-r--r--Game/Code/Classes/UParty.pas1230
-rw-r--r--Game/Code/Classes/UPluginInterface.pas8
-rw-r--r--Game/Code/Classes/UServices.pas4
-rw-r--r--Game/Code/Classes/uPluginLoader.pas92
6 files changed, 707 insertions, 705 deletions
diff --git a/Game/Code/Classes/UCore.pas b/Game/Code/Classes/UCore.pas
index 5b144b45..c150ff34 100644
--- a/Game/Code/Classes/UCore.pas
+++ b/Game/Code/Classes/UCore.pas
@@ -104,13 +104,13 @@ type
//--------------
// Hook and Service Procs:
//--------------
- Function ShowMessage(wParam, lParam: DWord): integer; //Shows a Message (lParam: PChar Text, wParam: Symbol)
- Function ReportError(wParam, lParam: DWord): integer; //Shows a Message (wParam: Pchar(Message), lParam: PChar(Reportername))
- Function ReportDebug(wParam, lParam: DWord): integer; //Shows a Message (wParam: Pchar(Message), lParam: PChar(Reportername))
- Function Retranslate(wParam, lParam: DWord): integer; //Calls Translate hook
- Function ReloadTextures(wParam, lParam: DWord): integer; //Calls LoadTextures hook
- Function GetModuleInfo(wParam, lParam: DWord): 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, lParam: DWord): 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
@@ -196,50 +196,50 @@ begin
else
begin
If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error calling LoadingFinished Hook: ' + LastErrorString)))
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error calling LoadingFinished Hook: ' + LastErrorString))
else
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error calling LoadingFinished Hook')));
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error calling LoadingFinished Hook'));
end;
end
else
begin
If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error loading textures: ' + LastErrorString)))
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error loading textures: ' + LastErrorString))
else
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error loading textures')));
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error loading textures'));
end;
end
else
begin
If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error translating: ' + LastErrorString)))
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error translating: ' + LastErrorString))
else
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error translating')));
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error translating'));
end;
end
else
begin
If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error initing Modules: ' + LastErrorString)))
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error initing Modules: ' + LastErrorString))
else
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error initing Modules')));
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error initing Modules'));
end;
end
else
begin
If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error loading Modules: ' + LastErrorString)))
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error loading Modules: ' + LastErrorString))
else
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error loading Modules')));
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error loading Modules'));
end;
end
else
begin
If (LastErrorString <> '') then
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error Getting Modules: ' + LastErrorString)))
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error Getting Modules: ' + LastErrorString))
else
- Self.ShowMessage(CORE_SM_ERROR, Integer(PChar('Error Getting Modules')));
+ Self.ShowMessage(CORE_SM_ERROR, PChar('Error Getting Modules'));
end;
//DeInit
@@ -272,7 +272,7 @@ begin
end;
Result := True;
except
- ReportError(Integer(PChar('Can''t get module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), Integer(PChar('Core')));
+ ReportError(Integer(PChar('Can''t get module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), PChar('Core'));
end;
end;
@@ -292,7 +292,7 @@ begin
Result := Modules[I].Module.Load;
except
Result := False;
- ReportError(Integer(PChar('Error loading module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), Integer(PChar('Core')));
+ ReportError(Integer(PChar('Error loading module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), PChar('Core'));
end;
Inc(I);
@@ -315,7 +315,7 @@ begin
Result := Modules[I].Module.Init;
except
Result := False;
- ReportError(Integer(PChar('Error initing module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), Integer(PChar('Core')));
+ ReportError(Integer(PChar('Error initing module #' + InttoStr(I) + ' "' + Modules[I].Info.Name + '"')), PChar('Core'));
end;
Modules[I].NeedsDeInit := Result;
@@ -414,13 +414,13 @@ end;
//-------------
// Shows a MessageDialog (lParam: PChar Text, wParam: Symbol)
//-------------
-Function TCore.ShowMessage(wParam, lParam: DWord): integer;
+Function TCore.ShowMessage(wParam: TwParam; lParam: TlParam): integer;
var Params: Cardinal;
begin
Result := -1;
{$IFDEF Delphi}
- If (ptr(lParam)<>nil) then
+ If (lParam<>nil) then
begin
Params := MB_OK;
Case wParam of
@@ -430,7 +430,7 @@ begin
end;
//Anzeigen:
- Result := Messagebox(0, ptr(lParam), PChar(Name), Params);
+ Result := Messagebox(0, lParam, PChar(Name), Params);
end;
{$ENDIF}
@@ -440,10 +440,10 @@ end;
//-------------
// Calls NewError HookChain (wParam: Pchar(Message), lParam: PChar(Reportername))
//-------------
-Function TCore.ReportError(wParam, lParam: DWord): integer;
+Function TCore.ReportError(wParam: TwParam; lParam: TlParam): integer;
begin
//Update LastErrorReporter and LastErrorString
- LastErrorReporter := String(PChar(Pointer(lParam)));
+ LastErrorReporter := String(PChar(lParam));
LastErrorString := String(PChar(Pointer(wParam)));
Hooks.CallEventChain(hError, wParam, lParam);
@@ -452,7 +452,7 @@ end;
//-------------
// Calls NewDebugInfo HookChain (wParam: Pchar(Message), lParam: PChar(Reportername))
//-------------
-Function TCore.ReportDebug(wParam, lParam: DWord): integer;
+Function TCore.ReportDebug(wParam: TwParam; lParam: TlParam): integer;
begin
Hooks.CallEventChain(hDebug, wParam, lParam);
end;
@@ -460,23 +460,23 @@ end;
//-------------
// Calls Translate hook
//-------------
-Function TCore.Retranslate(wParam, lParam: DWord): integer;
+Function TCore.Retranslate(wParam: TwParam; lParam: TlParam): integer;
begin
- Hooks.CallEventChain(hTranslate, 0, 1);
+ Hooks.CallEventChain(hTranslate, 1, nil);
end;
//-------------
// Calls LoadTextures hook
//-------------
-Function TCore.ReloadTextures(wParam, lParam: DWord): integer;
+Function TCore.ReloadTextures(wParam: TwParam; lParam: TlParam): integer;
begin
- Hooks.CallEventChain(hLoadTextures, 0, 1);
+ Hooks.CallEventChain(hLoadTextures, 1, nil);
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, lParam: DWord): integer;
+Function TCore.GetModuleInfo(wParam: TwParam; lParam: TlParam): integer;
begin
if (Pointer(lParam) = nil) then
begin
@@ -500,7 +500,7 @@ end;
//-------------
// Returns Application Handle
//-------------
-Function TCore.GetApplicationHandle(wParam, lParam: DWord): integer;
+Function TCore.GetApplicationHandle(wParam: TwParam; lParam: TlParam): integer;
begin
Result := hInstance;
end;
diff --git a/Game/Code/Classes/UHooks.pas b/Game/Code/Classes/UHooks.pas
index c30803f7..3e22bc75 100644
--- a/Game/Code/Classes/UHooks.pas
+++ b/Game/Code/Classes/UHooks.pas
@@ -54,13 +54,13 @@ type
Function AddSubscriber (const EventName: PChar; const Proc: TUS_Hook = nil; const ProcOfClass: TUS_Hook_of_Object = nil): THandle;
Function DelSubscriber (const hSubscriber: THandle): Integer;
- Function CallEventChain (const hEvent: THandle; const wParam, lParam: LongWord): Integer;
+ Function CallEventChain (const hEvent: THandle; const wParam: TwParam; lParam: TlParam): Integer;
Function EventExists (const EventName: PChar): Integer;
Procedure DelbyOwner(const Owner: Integer);
end;
-function HookTest(wParam, lParam: DWord): integer; stdcall;
+function HookTest(wParam: TwParam; lParam: TlParam): integer; stdcall;
var
HookManager: THookManager;
@@ -318,7 +318,7 @@ end;
// CallEventChain - Calls the Chain of a specified EventHandle
// Returns: -1: Handle doesn't Exist, 0 Chain is called until the End
//------------
-Function THookManager.CallEventChain (const hEvent: THandle; const wParam, lParam: LongWord): Integer;
+Function THookManager.CallEventChain (const hEvent: THandle; const wParam: TwParam; lParam: TlParam): Integer;
var
EventIndex: Cardinal;
Cur: PSubscriberInfo;
@@ -421,10 +421,10 @@ begin
end;
-function HookTest(wParam, lParam: DWord): integer; stdcall;
+function HookTest(wParam: TwParam; lParam: TlParam): integer; stdcall;
begin
Result := 0; //Don't break the chain
- Core.ShowMessage(CORE_SM_INFO, Integer(PChar(String(PChar(Pointer(lParam))) + ': ' + String(PChar(Pointer(wParam))))));
+ Core.ShowMessage(CORE_SM_INFO, PChar(String(PChar(Pointer(lParam))) + ': ' + String(PChar(Pointer(wParam)))));
end;
end.
diff --git a/Game/Code/Classes/UParty.pas b/Game/Code/Classes/UParty.pas
index 3fc52b8e..b0b400db 100644
--- a/Game/Code/Classes/UParty.pas
+++ b/Game/Code/Classes/UParty.pas
@@ -1,614 +1,616 @@
-unit UParty;
-
-interface
-
-{$IFDEF FPC}
- {$MODE DELPHI}
-{$ENDIF}
-
-{$I switches.inc}
-
-uses UPartyDefs, UCoreModule, UPluginDefs;
-
-type
- ARounds = Array [0..252] of Integer; //0..252 needed for
- PARounds = ^ARounds;
-
- TRoundInfo = record
- Modi: Cardinal;
- Winner: Byte;
- end;
-
- TeamOrderEntry = record
- Teamnum: Byte;
- Score: Byte;
- end;
-
- TeamOrderArray = Array[0..5] of Byte;
-
- TUS_ModiInfoEx = record
- Info: TUS_ModiInfo;
- Owner: Integer;
- TimesPlayed: Byte; //Helper for setting Round Plugins
- end;
-
- TPartySession = class (TCoreModule)
- private
- bPartyMode: Boolean; //Is this Party or Singleplayer
- CurRound: Byte;
-
- Modis: Array of TUS_ModiInfoEx;
- Teams: TTeamInfo;
-
- function IsWinner(Player, Winner: Byte): boolean;
- procedure GenScores;
- function GetRandomPlugin(TeamMode: Boolean): Cardinal;
- function GetRandomPlayer(Team: Byte): Byte;
- public
- //Teams: TTeamInfo;
- Rounds: array of TRoundInfo;
-
- //TCoreModule methods to inherit
- Constructor Create; override;
- Procedure Info(const pInfo: PModuleInfo); override;
- Function Load: Boolean; override;
- Function Init: Boolean; override;
- Procedure DeInit; override;
- Procedure Free; override;
-
- //Register Modi Service
- Function RegisterModi(pModiInfo, nothin: DWord): integer; //Registers a new Modi. wParam: Pointer to TUS_ModiInfo
-
- //Start new Party
- Function StartParty(NumRounds, PAofIRounds: DWord): integer; //Starts new Party Mode. Returns Non Zero on Success
- Function GetCurModi(wParam, lParam: DWord): integer; //Returns Pointer to Cur. Modis TUS_ModiInfo (to Use with Singscreen)
- Function StopParty(wParam, lParam: DWord): integer; //Stops Party Mode. Returns 1 If Partymode was enabled before.
- Function NextRound(wParam, lParam: DWord): integer; //Increases CurRound by 1; Returns num of Round or -1 if last Round is already played
-
- Function CallModiInit(wParam, lParam: DWord): integer; //Calls CurModis Init Proc. If an Error occurs, Returns Nonzero. In this Case a New Plugin was Selected. Please renew Loading
- Function CallModiDeInit(wParam, lParam: DWord): integer; //Calls DeInitProc and does the RoundEnding
-
- Function GetTeamInfo(wParam, pTeamInfo: DWord): integer; //Writes TTeamInfo Record to Pointer at lParam. Returns Zero on Success
- Function SetTeamInfo(wParam, pTeamInfo: DWord): integer; //Read TTeamInfo Record from Pointer at lParam. Returns Zero on Success
-
- Function GetTeamOrder(wParam, lParam: DWord): integer; //Returns Team Order. Structure: Bits 1..3: Team at Place1; Bits 4..6: Team at Place2 ...
- Function GetWinnerString(wParam, lParam: DWord): integer; //wParam is Roundnum. If (Pointer = nil) then Return Length of the String. Otherwise Write the String to Address at lParam
- end;
-
-const
- StandardModi = 0; //Modi ID that will be played in non party Mode
-
-implementation
-
-uses UCore, UGraphic, UMain, ULanguage, ULog, SysUtils;
-
-{*********************
- TPluginLoader
- Implentation
-*********************}
-
-//-------------
-// Function that gives some Infos about the Module to the Core
-//-------------
-Procedure TPartySession.Info(const pInfo: PModuleInfo);
-begin
- pInfo^.Name := 'TPartySession';
- pInfo^.Version := MakeVersion(1,0,0,chr(0));
- pInfo^.Description := 'Manages Party Modi and Party Game';
-end;
-
-//-------------
-// Just the Constructor
-//-------------
-Constructor TPartySession.Create;
-begin
- //UnSet PartyMode
- bPartyMode := False;
-end;
-
-//-------------
-//Is Called on Loading.
-//In this Method only Events and Services should be created
-//to offer them to other Modules or Plugins during the Init process
-//If False is Returned this will cause a Forced Exit
-//-------------
-Function TPartySession.Load: Boolean;
-begin
- //Add Register Party Modi Service
- Result := True;
- Core.Services.AddService('Party/RegisterModi', nil, Self.RegisterModi);
- Core.Services.AddService('Party/StartParty', nil, Self.StartParty);
- Core.Services.AddService('Party/GetCurModi', nil, Self.GetCurModi);
-end;
-
-//-------------
-//Is Called on Init Process
-//In this Method you can Hook some Events and Create + Init
-//your Classes, Variables etc.
-//If False is Returned this will cause a Forced Exit
-//-------------
-Function TPartySession.Init: Boolean;
-begin
- //Just set Prvate Var to true.
- Result := true;
-end;
-
-//-------------
-//Is Called if this Module has been Inited and there is a Exit.
-//Deinit is in backwards Initing Order
-//-------------
-Procedure TPartySession.DeInit;
-begin
- //Force DeInit
-
-end;
-
-//-------------
-//Is Called if this Module will be unloaded and has been created
-//Should be used to Free Memory
-//-------------
-Procedure TPartySession.Free;
-begin
- //Just save some Memory if it wasn't done now..
- SetLength(Modis, 0);
-end;
-
-//-------------
-// Registers a new Modi. wParam: Pointer to TUS_ModiInfo
-// Service for Plugins
-//-------------
-Function TPartySession.RegisterModi(pModiInfo, nothin: DWord): integer;
-var
- Len: Integer;
- Info: PUS_ModiInfo;
-begin
- Info := Pointer(PModiInfo);
- //Copy Info if cbSize is correct
- If (Info.cbSize = SizeOf(TUS_ModiInfo)) then
- begin
- Len := Length(Modis);
- SetLength(Modis, Len + 1);
-
- Modis[Len].Info := Info^;
- end
- else
- Core.ReportError(Integer(PChar('Plugins try to Register Modi with wrong Pointer, or wrong TUS_ModiInfo Record.')), Integer(PChar('TPartySession')));
-end;
-
-//----------
-// Returns a Number of a Random Plugin
-//----------
-Function TPartySession.GetRandomPlugin(TeamMode: Boolean): Cardinal;
-var
- LowestTP: Byte;
- NumPwithLTP: Word;
- I: Integer;
- R: Word;
-begin
- Result := StandardModi; //If there are no matching Modis, Play StandardModi
- LowestTP := high(Byte);
- NumPwithLTP := 0;
-
- //Search for Plugins not often played yet
- For I := 0 to high(Modis) do
- begin
- if (Modis[I].TimesPlayed < lowestTP) And (((Modis[I].Info.LoadingSettings AND MLS_TeamOnly) <> 0) = TeamMode) then
- begin
- lowestTP := Modis[I].TimesPlayed;
- NumPwithLTP := 1;
- end
- else if (Modis[I].TimesPlayed = lowestTP) And (((Modis[I].Info.LoadingSettings AND MLS_TeamOnly) <> 0) = TeamMode) then
- begin
- Inc(NumPwithLTP);
- end;
- end;
-
- //Create Random No
- R := Random(NumPwithLTP);
-
- //Search for Random Plugin
- For I := 0 to high(Modis) do
- begin
- if (Modis[I].TimesPlayed = lowestTP) And (((Modis[I].Info.LoadingSettings AND MLS_TeamOnly) <> 0) = TeamMode) then
- begin
- //Plugin Found
- if (R = 0) then
- begin
- Result := I;
- Inc(Modis[I].TimesPlayed);
- Break;
- end;
-
- Dec(R);
- end;
- end;
-end;
-
-//----------
-// Starts new Party Mode. Returns Non Zero on Success
-//----------
-Function TPartySession.StartParty(NumRounds, PAofIRounds: DWord): integer;
-var
- I: Integer;
- aiRounds: PARounds;
- TeamMode: Boolean;
-begin
- Result := 0;
- If (Teams.NumTeams >= 1) AND (NumRounds < High(Byte)-1) then
- begin
- bPartyMode := false;
- aiRounds := Pointer(PAofIRounds);
-
- Try
- //Is this Teammode(More then one Player per Team) ?
- TeamMode := True;
- For I := 0 to Teams.NumTeams-1 do
- TeamMode := TeamMode AND (Teams.Teaminfo[I].NumPlayers > 1);
-
- // For I := 0 to High(NumRounds) do // eddie: changed NumRounds to Rounds - is this correct ??? I get compile errors on the mac otherwise...
- For I := 0 to High(Rounds) do
- begin //Set Plugins
- If (aiRounds[I] = -1) then
- Rounds[I].Modi := GetRandomPlugin(TeamMode)
- Else If (aiRounds[I] >= 0) AND (aiRounds[I] <= High(Modis)) AND (TeamMode OR ((Modis[aiRounds[I]].Info.LoadingSettings AND MLS_TeamOnly) = 0)) then
- Rounds[I].Modi := aiRounds[I]
- Else
- Rounds[I].Modi := StandardModi;
-
- Rounds[I].Winner := High(Byte); //Set Winner to Not Played
- end;
-
- CurRound := High(Byte); //Set CurRound to not defined
-
- //Return teh true and Set PartyMode
- bPartyMode := True;
- Result := 1;
-
- Except
- Core.ReportError(Integer(PChar('Can''t start PartyMode.')), Integer(PChar('TPartySession')));
- end;
- end;
-end;
-
-//----------
-// Returns Pointer to Cur. ModiInfoEx (to Use with Singscreen)
-//----------
-Function TPartySession.GetCurModi(wParam, lParam: DWord): integer;
-begin
- If (bPartyMode) AND (CurRound <= High(Rounds)) then
- begin //If PartyMode is enabled:
- //Return the Plugin of the Cur Round
- Result := Integer(@Modis[Rounds[CurRound].Modi]);
- end
- else
- begin //Return StandardModi
- Result := Integer(@Modis[StandardModi]);
- end;
-end;
-
-//----------
-// Stops Party Mode. Returns 1 If Partymode was enabled before. And -1 if Change was not possible
-//----------
-Function TPartySession.StopParty(wParam, lParam: DWord): integer;
-begin
- Result := -1;
- If (bPartyMode) then
- begin
- // to-do : Whitü: Check here if SingScreen is not Shown atm.
- bPartyMode := False;
- Result := 1;
- end
- else
- Result := 0;
-end;
-
-//----------
-//GetRandomPlayer - Gives back a Random Player to Play next Round
-//----------
-function TPartySession.GetRandomPlayer(Team: Byte): Byte;
-var
- I, R: Integer;
- lowestTP: Byte;
- NumPwithLTP: Byte;
-begin
- LowestTP := high(Byte);
- NumPwithLTP := 0;
- Result := 0;
-
- //Search for Players that have not often played yet
- For I := 0 to Teams.Teaminfo[Team].NumPlayers-1 do
- begin
- if (Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed < lowestTP) then
- begin
- lowestTP := Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed;
- NumPwithLTP := 1;
- end
- else if (Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed = lowestTP) then
- begin
- Inc(NumPwithLTP);
- end;
- end;
-
- //Create Random No
- R := Random(NumPwithLTP);
-
- //Search for Random Player
- For I := 0 to Teams.Teaminfo[Team].NumPlayers-1 do
- begin
- if Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed = lowestTP then
- begin
- //Player Found
- if (R = 0) then
- begin
- Result := I;
- Break;
- end;
-
- Dec(R);
- end;
- end;
-end;
-
-//----------
-// NextRound - Increases CurRound by 1; Returns num of Round or -1 if last Round is already played
-//----------
-Function TPartySession.NextRound(wParam, lParam: DWord): integer;
-var I: Integer;
-begin
- If ((CurRound < high(Rounds)) OR (CurRound = high(CurRound))) then
- begin //everythings OK! -> Start the Round, maaaaan
- Inc(CurRound);
-
- //Set Players to play this Round
- for I := 0 to Teams.NumTeams-1 do
- Teams.Teaminfo[I].CurPlayer := GetRandomPlayer(I);
- end
- else
- Result := -1;
-end;
-
-//----------
-//IsWinner - Returns True if the Players Bit is set in the Winner Byte
-//----------
-function TPartySession.IsWinner(Player, Winner: Byte): boolean;
-var
- Bit: Byte;
-begin
- Bit := 1 shl Player;
-
- Result := ((Winner AND Bit) = Bit);
-end;
-
-//----------
-//GenScores - Inc Scores for Cur. Round
-//----------
-procedure TPartySession.GenScores;
-var
- I: Byte;
-begin
- for I := 0 to Teams.NumTeams-1 do
- begin
- if isWinner(I, Rounds[CurRound].Winner) then
- Inc(Teams.Teaminfo[I].Score);
- end;
-end;
-
-//----------
-// CallModiInit - Calls CurModis Init Proc. If an Error occurs, Returns Nonzero. In this Case a New Plugin was Selected. Please renew Loading
-//----------
-Function TPartySession.CallModiInit(wParam, lParam: DWord): integer;
-begin
- If (not bPartyMode) then
- begin //Set Rounds if not in PartyMode
- SetLength(Rounds, 1);
- Rounds[0].Modi := StandardModi;
- Rounds[0].Winner := High(Byte);
- CurRound := 0;
- end;
-
- Try
- //Core.
- Except
- on E : Exception do
- begin
- Core.ReportError(Integer(PChar('Error starting Modi: ' + Modis[Rounds[CurRound].Modi].Info.Name + ' ErrorStr: ' + E.Message)), Integer(PChar('TPartySession')));
- If (Rounds[CurRound].Modi = StandardModi) then
- begin
- Core.ReportError(Integer(PChar('Can''t start StandardModi, will exit now!')), Integer(PChar('TPartySession')));
- Halt;
- end
- Else //Select StandardModi
- begin
- Rounds[CurRound].Modi := StandardModi
- end;
- end;
- End;
-end;
-
-//----------
-// CallModiDeInit - Calls DeInitProc and does the RoundEnding
-//----------
-Function TPartySession.CallModiDeInit(wParam, lParam: DWord): integer;
-var
- I: Integer;
- MaxScore: Word;
-begin
- If (bPartyMode) then
- begin
- //Get Winner Byte!
- if (@Modis[Rounds[CurRound].Modi].Info.ModiDeInit <> nil) then //get Winners from Plugin
- Rounds[CurRound].Winner := Modis[Rounds[CurRound].Modi].Info.ModiDeInit(Modis[Rounds[CurRound].Modi].Info.ID)
- else
- begin //Create winners by Score :/
- Rounds[CurRound].Winner := 0;
- MaxScore := 0;
- for I := 0 to Teams.NumTeams-1 do
- begin
- // to-do : recode Percentage stuff
- //PlayerInfo.Playerinfo[I].Percentage := PlayerInfo.Playerinfo[I].Score div 9999;
- if (Player[I].ScoreTotalI > MaxScore) then
- begin
- MaxScore := Player[I].ScoreTotalI;
- Rounds[CurRound].Winner := 1 shl I;
- end
- else if (Player[I].ScoreTotalI = MaxScore) AND (Player[I].ScoreTotalI <> 0) then
- begin
- Rounds[CurRound].Winner := Rounds[CurRound].Winner or (1 shl I);
- end;
- end;
-
-
- //When nobody has Points -> Everybody loose
- if (MaxScore = 0) then
- Rounds[CurRound].Winner := 0;
-
- end;
-
- //Generate teh Scores
- GenScores;
-
- //Inc Players TimesPlayed
- If ((Modis[Rounds[CurRound-1].Modi].Info.LoadingSettings AND MLS_IncTP) = MLS_IncTP) then
- begin
- For I := 0 to Teams.NumTeams-1 do
- Inc(Teams.TeamInfo[I].Playerinfo[Teams.TeamInfo[I].CurPlayer].TimesPlayed);
- end;
- end
- else if (@Modis[Rounds[CurRound].Modi].Info.ModiDeInit <> nil) then
- Modis[Rounds[CurRound].Modi].Info.ModiDeInit(Modis[Rounds[CurRound].Modi].Info.ID);
-end;
-
-//----------
-// GetTeamInfo - Writes TTeamInfo Record to Pointer at lParam. Returns Zero on Success
-//----------
-Function TPartySession.GetTeamInfo(wParam, pTeamInfo: DWord): integer;
-var Info: ^TTeamInfo;
-begin
- Result := -1;
- Info := Pointer(pTeamInfo);
- If (Info <> nil) then
- begin
- Try
- // to - do : Check Delphi memory management in this case
- //Not sure if i had to copy PChars to a new address or if delphi manages this o0
- Info^ := Teams;
- Result := 0;
- Except
- Result := -2;
- End;
- end;
-end;
-
-//----------
-// SetTeamInfo - Read TTeamInfo Record from Pointer at lParam. Returns Zero on Success
-//----------
-Function TPartySession.SetTeamInfo(wParam, pTeamInfo: DWord): integer;
-var
- TeamInfobackup: TTeamInfo;
- Info: ^TTeamInfo;
-begin
- Result := -1;
- Info := Pointer(pTeamInfo);
- If (Info <> nil) then
- begin
- Try
- TeamInfoBackup := Teams;
- // to - do : Check Delphi memory management in this case
- //Not sure if i had to copy PChars to a new address or if delphi manages this o0
- Teams := Info^;
- Result := 0;
- Except
- Teams := TeamInfoBackup;
- Result := -2;
- End;
- end;
-end;
-
-//----------
-// GetTeamOrder - Returns Team Order. Structure: Bits 1..3: Team at Place1; Bits 4..6: Team at Place2 ...
-//----------
-Function TPartySession.GetTeamOrder(wParam, lParam: DWord): integer;
-var
- I, J: Integer;
- ATeams: array [0..5] of TeamOrderEntry;
- TempTeam: TeamOrderEntry;
-begin
- // to-do : PartyMode: Write this in another way, so that teams with the same scire get the same Placing
- //Fill Team Array
- For I := 0 to Teams.NumTeams-1 do
- begin
- ATeams[I].Teamnum := I;
- ATeams[I].Score := Teams.Teaminfo[I].Score;
- end;
-
- //Sort Teams
- for J := 0 to Teams.NumTeams-1 do
- for I := 1 to Teams.NumTeams-1 do
- if ATeams[I].Score > ATeams[I-1].Score then
- begin
- TempTeam := ATeams[I-1];
- ATeams[I-1] := ATeams[I];
- ATeams[I] := TempTeam;
- end;
-
- //Copy to Result
- Result := 0;
- For I := 0 to Teams.NumTeams-1 do
- Result := Result or (ATeams[I].TeamNum Shl I*3);
-end;
-
-//----------
-// GetWinnerString - wParam is Roundnum. If (Pointer = nil) then Return Length of the String. Otherwise Write the String to Address at lParam
-//----------
-Function TPartySession.GetWinnerString(wParam, lParam: DWord): integer;
-var
- Winners: Array of String;
- I: Integer;
- ResultStr: String;
- S: ^String;
-begin
- ResultStr := Language.Translate('PARTY_NOBODY');
-
- if (wParam <= High(Rounds)) then
- begin
- if (Rounds[wParam].Winner <> 0) then
- begin
- if (Rounds[wParam].Winner = 255) then
- begin
- ResultStr := Language.Translate('PARTY_NOTPLAYEDYET');
- end
- else
- begin
- SetLength(Winners, 0);
- for I := 0 to Teams.NumTeams-1 do
- begin
- if isWinner(I, Rounds[wParam].Winner) then
- begin
- SetLength(Winners, Length(Winners) + 1);
- Winners[high(Winners)] := Teams.TeamInfo[I].Name;
- end;
- end;
- ResultStr := Language.Implode(Winners);
- end;
- end;
- end;
-
- //Now Return what we have got
- If (Pointer(lParam) = nil) then
- begin //ReturnString Length
- Result := Length(ResultStr);
- end
- Else
- begin //Return String
- Try
- S := Pointer(lParam);
- S^ := ResultStr;
- Result := 0;
- Except
- Result := -1;
-
- End;
- end;
-end;
-
-end.
+unit UParty;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE DELPHI}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses UPartyDefs, UCoreModule, UPluginDefs;
+
+type
+ ARounds = Array [0..252] of Integer; //0..252 needed for
+ PARounds = ^ARounds;
+
+ TRoundInfo = record
+ Modi: Cardinal;
+ Winner: Byte;
+ end;
+
+ TeamOrderEntry = record
+ Teamnum: Byte;
+ Score: Byte;
+ end;
+
+ TeamOrderArray = Array[0..5] of Byte;
+
+ TUS_ModiInfoEx = record
+ Info: TUS_ModiInfo;
+ Owner: Integer;
+ TimesPlayed: Byte; //Helper for setting Round Plugins
+ end;
+
+ TPartySession = class (TCoreModule)
+ private
+ bPartyMode: Boolean; //Is this Party or Singleplayer
+ CurRound: Byte;
+
+ Modis: Array of TUS_ModiInfoEx;
+ Teams: TTeamInfo;
+
+ function IsWinner(Player, Winner: Byte): boolean;
+ procedure GenScores;
+ function GetRandomPlugin(TeamMode: Boolean): Cardinal;
+ function GetRandomPlayer(Team: Byte): Byte;
+ public
+ //Teams: TTeamInfo;
+ Rounds: array of TRoundInfo;
+
+ //TCoreModule methods to inherit
+ Constructor Create; override;
+ Procedure Info(const pInfo: PModuleInfo); override;
+ Function Load: Boolean; override;
+ Function Init: Boolean; override;
+ Procedure DeInit; override;
+ Procedure Free; override;
+
+ //Register Modi Service
+ Function RegisterModi(nothin: TwParam; pModiInfo: TlParam): integer; //Registers a new Modi. wParam: Pointer to TUS_ModiInfo
+
+ //Start new Party
+ Function StartParty(NumRounds: TwParam; PAofIRounds: TlParam): integer; //Starts new Party Mode. Returns Non Zero on Success
+ Function GetCurModi(wParam: TwParam; lParam: TlParam): integer; //Returns Pointer to Cur. Modis TUS_ModiInfo (to Use with Singscreen)
+ Function StopParty(wParam: TwParam; lParam: TlParam): integer; //Stops Party Mode. Returns 1 If Partymode was enabled before.
+ Function NextRound(wParam: TwParam; lParam: TlParam): integer; //Increases CurRound by 1; Returns num of Round or -1 if last Round is already played
+
+ Function CallModiInit(wParam: TwParam; lParam: TlParam): integer; //Calls CurModis Init Proc. If an Error occurs, Returns Nonzero. In this Case a New Plugin was Selected. Please renew Loading
+ Function CallModiDeInit(wParam: TwParam; lParam: TlParam): integer; //Calls DeInitProc and does the RoundEnding
+
+ Function GetTeamInfo(wParam: TwParam; pTeamInfo: TlParam): integer; //Writes TTeamInfo Record to Pointer at lParam. Returns Zero on Success
+ Function SetTeamInfo(wParam: TwParam; pTeamInfo: TlParam): integer; //Read TTeamInfo Record from Pointer at lParam. Returns Zero on Success
+
+ Function GetTeamOrder(wParam: TwParam; lParam: TlParam): integer; //Returns Team Order. Structure: Bits 1..3: Team at Place1; Bits 4..6: Team at Place2 ...
+ Function GetWinnerString(wParam: TwParam; lParam: TlParam): integer; //wParam is Roundnum. If (Pointer = nil) then Return Length of the String. Otherwise Write the String to Address at lParam
+ end;
+
+const
+ StandardModi = 0; //Modi ID that will be played in non party Mode
+
+implementation
+
+uses UCore, UGraphic, UMain, ULanguage, ULog, SysUtils;
+
+{*********************
+ TPluginLoader
+ Implentation
+*********************}
+
+//-------------
+// Function that gives some Infos about the Module to the Core
+//-------------
+Procedure TPartySession.Info(const pInfo: PModuleInfo);
+begin
+ pInfo^.Name := 'TPartySession';
+ pInfo^.Version := MakeVersion(1,0,0,chr(0));
+ pInfo^.Description := 'Manages Party Modi and Party Game';
+end;
+
+//-------------
+// Just the Constructor
+//-------------
+Constructor TPartySession.Create;
+begin
+ //UnSet PartyMode
+ bPartyMode := False;
+end;
+
+//-------------
+//Is Called on Loading.
+//In this Method only Events and Services should be created
+//to offer them to other Modules or Plugins during the Init process
+//If False is Returned this will cause a Forced Exit
+//-------------
+Function TPartySession.Load: Boolean;
+begin
+ //Add Register Party Modi Service
+ Result := True;
+ Core.Services.AddService('Party/RegisterModi', nil, Self.RegisterModi);
+ Core.Services.AddService('Party/StartParty', nil, Self.StartParty);
+ Core.Services.AddService('Party/GetCurModi', nil, Self.GetCurModi);
+end;
+
+//-------------
+//Is Called on Init Process
+//In this Method you can Hook some Events and Create + Init
+//your Classes, Variables etc.
+//If False is Returned this will cause a Forced Exit
+//-------------
+Function TPartySession.Init: Boolean;
+begin
+ //Just set Prvate Var to true.
+ Result := true;
+end;
+
+//-------------
+//Is Called if this Module has been Inited and there is a Exit.
+//Deinit is in backwards Initing Order
+//-------------
+Procedure TPartySession.DeInit;
+begin
+ //Force DeInit
+
+end;
+
+//-------------
+//Is Called if this Module will be unloaded and has been created
+//Should be used to Free Memory
+//-------------
+Procedure TPartySession.Free;
+begin
+ //Just save some Memory if it wasn't done now..
+ SetLength(Modis, 0);
+end;
+
+//-------------
+// Registers a new Modi. wParam: Pointer to TUS_ModiInfo
+// Service for Plugins
+//-------------
+Function TPartySession.RegisterModi(nothin: TwParam; pModiInfo: TlParam): integer;
+var
+ Len: Integer;
+ Info: PUS_ModiInfo;
+begin
+ Info := PModiInfo;
+ //Copy Info if cbSize is correct
+ If (Info.cbSize = SizeOf(TUS_ModiInfo)) then
+ begin
+ Len := Length(Modis);
+ SetLength(Modis, Len + 1);
+
+ Modis[Len].Info := Info^;
+ end
+ else
+ Core.ReportError(Integer(PChar('Plugins try to Register Modi with wrong Pointer, or wrong TUS_ModiInfo Record.')), PChar('TPartySession'));
+end;
+
+//----------
+// Returns a Number of a Random Plugin
+//----------
+Function TPartySession.GetRandomPlugin(TeamMode: Boolean): Cardinal;
+var
+ LowestTP: Byte;
+ NumPwithLTP: Word;
+ I: Integer;
+ R: Word;
+begin
+ Result := StandardModi; //If there are no matching Modis, Play StandardModi
+ LowestTP := high(Byte);
+ NumPwithLTP := 0;
+
+ //Search for Plugins not often played yet
+ For I := 0 to high(Modis) do
+ begin
+ if (Modis[I].TimesPlayed < lowestTP) And (((Modis[I].Info.LoadingSettings AND MLS_TeamOnly) <> 0) = TeamMode) then
+ begin
+ lowestTP := Modis[I].TimesPlayed;
+ NumPwithLTP := 1;
+ end
+ else if (Modis[I].TimesPlayed = lowestTP) And (((Modis[I].Info.LoadingSettings AND MLS_TeamOnly) <> 0) = TeamMode) then
+ begin
+ Inc(NumPwithLTP);
+ end;
+ end;
+
+ //Create Random No
+ R := Random(NumPwithLTP);
+
+ //Search for Random Plugin
+ For I := 0 to high(Modis) do
+ begin
+ if (Modis[I].TimesPlayed = lowestTP) And (((Modis[I].Info.LoadingSettings AND MLS_TeamOnly) <> 0) = TeamMode) then
+ begin
+ //Plugin Found
+ if (R = 0) then
+ begin
+ Result := I;
+ Inc(Modis[I].TimesPlayed);
+ Break;
+ end;
+
+ Dec(R);
+ end;
+ end;
+end;
+
+//----------
+// Starts new Party Mode. Returns Non Zero on Success
+//----------
+Function TPartySession.StartParty(NumRounds: TwParam; PAofIRounds: TlParam): integer;
+var
+ I: Integer;
+ aiRounds: PARounds;
+ TeamMode: Boolean;
+begin
+ Result := 0;
+ If (Teams.NumTeams >= 1) AND (NumRounds < High(Byte)-1) then
+ begin
+ bPartyMode := false;
+ aiRounds := PAofIRounds;
+
+ Try
+ //Is this Teammode(More then one Player per Team) ?
+ TeamMode := True;
+ For I := 0 to Teams.NumTeams-1 do
+ TeamMode := TeamMode AND (Teams.Teaminfo[I].NumPlayers > 1);
+
+ //Set Rounds
+ SetLength(Rounds, NumRounds);
+
+ For I := 0 to High(Rounds) do
+ begin //Set Plugins
+ If (aiRounds[I] = -1) then
+ Rounds[I].Modi := GetRandomPlugin(TeamMode)
+ Else If (aiRounds[I] >= 0) AND (aiRounds[I] <= High(Modis)) AND (TeamMode OR ((Modis[aiRounds[I]].Info.LoadingSettings AND MLS_TeamOnly) = 0)) then
+ Rounds[I].Modi := aiRounds[I]
+ Else
+ Rounds[I].Modi := StandardModi;
+
+ Rounds[I].Winner := High(Byte); //Set Winner to Not Played
+ end;
+
+ CurRound := High(Byte); //Set CurRound to not defined
+
+ //Return teh true and Set PartyMode
+ bPartyMode := True;
+ Result := 1;
+
+ Except
+ Core.ReportError(Integer(PChar('Can''t start PartyMode.')), PChar('TPartySession'));
+ end;
+ end;
+end;
+
+//----------
+// Returns Pointer to Cur. ModiInfoEx (to Use with Singscreen)
+//----------
+Function TPartySession.GetCurModi(wParam: TwParam; lParam: TlParam): integer;
+begin
+ If (bPartyMode) AND (CurRound <= High(Rounds)) then
+ begin //If PartyMode is enabled:
+ //Return the Plugin of the Cur Round
+ Result := Integer(@Modis[Rounds[CurRound].Modi]);
+ end
+ else
+ begin //Return StandardModi
+ Result := Integer(@Modis[StandardModi]);
+ end;
+end;
+
+//----------
+// Stops Party Mode. Returns 1 If Partymode was enabled before. And -1 if Change was not possible
+//----------
+Function TPartySession.StopParty(wParam: TwParam; lParam: TlParam): integer;
+begin
+ Result := -1;
+ If (bPartyMode) then
+ begin
+ // to-do : Whitü: Check here if SingScreen is not Shown atm.
+ bPartyMode := False;
+ Result := 1;
+ end
+ else
+ Result := 0;
+end;
+
+//----------
+//GetRandomPlayer - Gives back a Random Player to Play next Round
+//----------
+function TPartySession.GetRandomPlayer(Team: Byte): Byte;
+var
+ I, R: Integer;
+ lowestTP: Byte;
+ NumPwithLTP: Byte;
+begin
+ LowestTP := high(Byte);
+ NumPwithLTP := 0;
+ Result := 0;
+
+ //Search for Players that have not often played yet
+ For I := 0 to Teams.Teaminfo[Team].NumPlayers-1 do
+ begin
+ if (Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed < lowestTP) then
+ begin
+ lowestTP := Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed;
+ NumPwithLTP := 1;
+ end
+ else if (Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed = lowestTP) then
+ begin
+ Inc(NumPwithLTP);
+ end;
+ end;
+
+ //Create Random No
+ R := Random(NumPwithLTP);
+
+ //Search for Random Player
+ For I := 0 to Teams.Teaminfo[Team].NumPlayers-1 do
+ begin
+ if Teams.Teaminfo[Team].Playerinfo[I].TimesPlayed = lowestTP then
+ begin
+ //Player Found
+ if (R = 0) then
+ begin
+ Result := I;
+ Break;
+ end;
+
+ Dec(R);
+ end;
+ end;
+end;
+
+//----------
+// NextRound - Increases CurRound by 1; Returns num of Round or -1 if last Round is already played
+//----------
+Function TPartySession.NextRound(wParam: TwParam; lParam: TlParam): integer;
+var I: Integer;
+begin
+ If ((CurRound < high(Rounds)) OR (CurRound = high(CurRound))) then
+ begin //everythings OK! -> Start the Round, maaaaan
+ Inc(CurRound);
+
+ //Set Players to play this Round
+ for I := 0 to Teams.NumTeams-1 do
+ Teams.Teaminfo[I].CurPlayer := GetRandomPlayer(I);
+ end
+ else
+ Result := -1;
+end;
+
+//----------
+//IsWinner - Returns True if the Players Bit is set in the Winner Byte
+//----------
+function TPartySession.IsWinner(Player, Winner: Byte): boolean;
+var
+ Bit: Byte;
+begin
+ Bit := 1 shl Player;
+
+ Result := ((Winner AND Bit) = Bit);
+end;
+
+//----------
+//GenScores - Inc Scores for Cur. Round
+//----------
+procedure TPartySession.GenScores;
+var
+ I: Byte;
+begin
+ for I := 0 to Teams.NumTeams-1 do
+ begin
+ if isWinner(I, Rounds[CurRound].Winner) then
+ Inc(Teams.Teaminfo[I].Score);
+ end;
+end;
+
+//----------
+// CallModiInit - Calls CurModis Init Proc. If an Error occurs, Returns Nonzero. In this Case a New Plugin was Selected. Please renew Loading
+//----------
+Function TPartySession.CallModiInit(wParam: TwParam; lParam: TlParam): integer;
+begin
+ If (not bPartyMode) then
+ begin //Set Rounds if not in PartyMode
+ SetLength(Rounds, 1);
+ Rounds[0].Modi := StandardModi;
+ Rounds[0].Winner := High(Byte);
+ CurRound := 0;
+ end;
+
+ Try
+ //Core.
+ Except
+ on E : Exception do
+ begin
+ Core.ReportError(Integer(PChar('Error starting Modi: ' + Modis[Rounds[CurRound].Modi].Info.Name + ' ErrorStr: ' + E.Message)), PChar('TPartySession'));
+ If (Rounds[CurRound].Modi = StandardModi) then
+ begin
+ Core.ReportError(Integer(PChar('Can''t start StandardModi, will exit now!')), PChar('TPartySession'));
+ Halt;
+ end
+ Else //Select StandardModi
+ begin
+ Rounds[CurRound].Modi := StandardModi
+ end;
+ end;
+ End;
+end;
+
+//----------
+// CallModiDeInit - Calls DeInitProc and does the RoundEnding
+//----------
+Function TPartySession.CallModiDeInit(wParam: TwParam; lParam: TlParam): integer;
+var
+ I: Integer;
+ MaxScore: Word;
+begin
+ If (bPartyMode) then
+ begin
+ //Get Winner Byte!
+ if (@Modis[Rounds[CurRound].Modi].Info.ModiDeInit <> nil) then //get Winners from Plugin
+ Rounds[CurRound].Winner := Modis[Rounds[CurRound].Modi].Info.ModiDeInit(Modis[Rounds[CurRound].Modi].Info.ID)
+ else
+ begin //Create winners by Score :/
+ Rounds[CurRound].Winner := 0;
+ MaxScore := 0;
+ for I := 0 to Teams.NumTeams-1 do
+ begin
+ // to-do : recode Percentage stuff
+ //PlayerInfo.Playerinfo[I].Percentage := PlayerInfo.Playerinfo[I].Score div 9999;
+ if (Player[I].ScoreTotalI > MaxScore) then
+ begin
+ MaxScore := Player[I].ScoreTotalI;
+ Rounds[CurRound].Winner := 1 shl I;
+ end
+ else if (Player[I].ScoreTotalI = MaxScore) AND (Player[I].ScoreTotalI <> 0) then
+ begin
+ Rounds[CurRound].Winner := Rounds[CurRound].Winner or (1 shl I);
+ end;
+ end;
+
+
+ //When nobody has Points -> Everybody loose
+ if (MaxScore = 0) then
+ Rounds[CurRound].Winner := 0;
+
+ end;
+
+ //Generate teh Scores
+ GenScores;
+
+ //Inc Players TimesPlayed
+ If ((Modis[Rounds[CurRound-1].Modi].Info.LoadingSettings AND MLS_IncTP) = MLS_IncTP) then
+ begin
+ For I := 0 to Teams.NumTeams-1 do
+ Inc(Teams.TeamInfo[I].Playerinfo[Teams.TeamInfo[I].CurPlayer].TimesPlayed);
+ end;
+ end
+ else if (@Modis[Rounds[CurRound].Modi].Info.ModiDeInit <> nil) then
+ Modis[Rounds[CurRound].Modi].Info.ModiDeInit(Modis[Rounds[CurRound].Modi].Info.ID);
+end;
+
+//----------
+// GetTeamInfo - Writes TTeamInfo Record to Pointer at lParam. Returns Zero on Success
+//----------
+Function TPartySession.GetTeamInfo(wParam: TwParam; pTeamInfo: TlParam): integer;
+var Info: ^TTeamInfo;
+begin
+ Result := -1;
+ Info := pTeamInfo;
+ If (Info <> nil) then
+ begin
+ Try
+ // to - do : Check Delphi memory management in this case
+ //Not sure if i had to copy PChars to a new address or if delphi manages this o0
+ Info^ := Teams;
+ Result := 0;
+ Except
+ Result := -2;
+ End;
+ end;
+end;
+
+//----------
+// SetTeamInfo - Read TTeamInfo Record from Pointer at lParam. Returns Zero on Success
+//----------
+Function TPartySession.SetTeamInfo(wParam: TwParam; pTeamInfo: TlParam): integer;
+var
+ TeamInfobackup: TTeamInfo;
+ Info: ^TTeamInfo;
+begin
+ Result := -1;
+ Info := pTeamInfo;
+ If (Info <> nil) then
+ begin
+ Try
+ TeamInfoBackup := Teams;
+ // to - do : Check Delphi memory management in this case
+ //Not sure if i had to copy PChars to a new address or if delphi manages this o0
+ Teams := Info^;
+ Result := 0;
+ Except
+ Teams := TeamInfoBackup;
+ Result := -2;
+ End;
+ end;
+end;
+
+//----------
+// GetTeamOrder - Returns Team Order. Structure: Bits 1..3: Team at Place1; Bits 4..6: Team at Place2 ...
+//----------
+Function TPartySession.GetTeamOrder(wParam: TwParam; lParam: TlParam): integer;
+var
+ I, J: Integer;
+ ATeams: array [0..5] of TeamOrderEntry;
+ TempTeam: TeamOrderEntry;
+begin
+ // to-do : PartyMode: Write this in another way, so that teams with the same scire get the same Placing
+ //Fill Team Array
+ For I := 0 to Teams.NumTeams-1 do
+ begin
+ ATeams[I].Teamnum := I;
+ ATeams[I].Score := Teams.Teaminfo[I].Score;
+ end;
+
+ //Sort Teams
+ for J := 0 to Teams.NumTeams-1 do
+ for I := 1 to Teams.NumTeams-1 do
+ if ATeams[I].Score > ATeams[I-1].Score then
+ begin
+ TempTeam := ATeams[I-1];
+ ATeams[I-1] := ATeams[I];
+ ATeams[I] := TempTeam;
+ end;
+
+ //Copy to Result
+ Result := 0;
+ For I := 0 to Teams.NumTeams-1 do
+ Result := Result or (ATeams[I].TeamNum Shl I*3);
+end;
+
+//----------
+// GetWinnerString - wParam is Roundnum. If (Pointer = nil) then Return Length of the String. Otherwise Write the String to Address at lParam
+//----------
+Function TPartySession.GetWinnerString(wParam: TwParam; lParam: TlParam): integer;
+var
+ Winners: Array of String;
+ I: Integer;
+ ResultStr: String;
+ S: ^String;
+begin
+ ResultStr := Language.Translate('PARTY_NOBODY');
+
+ if (wParam <= High(Rounds)) then
+ begin
+ if (Rounds[wParam].Winner <> 0) then
+ begin
+ if (Rounds[wParam].Winner = 255) then
+ begin
+ ResultStr := Language.Translate('PARTY_NOTPLAYEDYET');
+ end
+ else
+ begin
+ SetLength(Winners, 0);
+ for I := 0 to Teams.NumTeams-1 do
+ begin
+ if isWinner(I, Rounds[wParam].Winner) then
+ begin
+ SetLength(Winners, Length(Winners) + 1);
+ Winners[high(Winners)] := Teams.TeamInfo[I].Name;
+ end;
+ end;
+ ResultStr := Language.Implode(Winners);
+ end;
+ end;
+ end;
+
+ //Now Return what we have got
+ If (lParam = nil) then
+ begin //ReturnString Length
+ Result := Length(ResultStr);
+ end
+ Else
+ begin //Return String
+ Try
+ S := lParam;
+ S^ := ResultStr;
+ Result := 0;
+ Except
+ Result := -1;
+
+ End;
+ end;
+end;
+
+end.
diff --git a/Game/Code/Classes/UPluginInterface.pas b/Game/Code/Classes/UPluginInterface.pas
index 56293848..6a83d7c3 100644
--- a/Game/Code/Classes/UPluginInterface.pas
+++ b/Game/Code/Classes/UPluginInterface.pas
@@ -26,7 +26,7 @@ uses uPluginDefs;
{Function start calling the Hook Chain
0 if Chain is called until the End, -1 if Event Handle is not valid
otherwise Return Value of the Hook that breaks the Chain}
- Function NotivyEventHooks (hEvent: THandle; wParam, lParam: dWord): integer; stdcall;
+ Function NotivyEventHooks (hEvent: THandle; wParam: TwParam; lParam: TlParam): integer; stdcall;
{Function Hooks an Event by Name.
Returns Hook Handle on Success, otherwise 0}
@@ -51,7 +51,7 @@ uses uPluginDefs;
{Function Calls a Services Proc
Returns Services Return Value or SERVICE_NOT_FOUND on Failure}
- Function CallService (ServiceName: PChar; wParam, lParam: dWord): integer; stdcall;
+ Function CallService (ServiceName: PChar; wParam: TwParam; lParam: TlParam): integer; stdcall;
{Function Returns Non Zero if a Service with the given Name Exists,
otherwise 0}
@@ -84,7 +84,7 @@ end;
// 0 if Chain is called until the End, -1 if Event Handle is not valid
// otherwise Return Value of the Hook that breaks the Chain
//---------------
-Function NotivyEventHooks (hEvent: THandle; wParam, lParam: dWord): integer; stdcall;
+Function NotivyEventHooks (hEvent: THandle; wParam: TwParam; lParam: TlParam): integer; stdcall;
begin
Result := Core.Hooks.CallEventChain(hEvent, wParam, lParam);
end;
@@ -139,7 +139,7 @@ end;
// Function Calls a Services Proc
// Returns Services Return Value or SERVICE_NOT_FOUND on Failure
//---------------
-Function CallService (ServiceName: PChar; wParam, lParam: dWord): integer; stdcall;
+Function CallService (ServiceName: PChar; wParam: TwParam; lParam: TlParam): integer; stdcall;
begin
Result := Core.Services.CallService(ServiceName, wParam, lParam);
end;
diff --git a/Game/Code/Classes/UServices.pas b/Game/Code/Classes/UServices.pas
index 094c3fed..be1fcf2c 100644
--- a/Game/Code/Classes/UServices.pas
+++ b/Game/Code/Classes/UServices.pas
@@ -55,7 +55,7 @@ type
Function AddService(const ServiceName: PChar; const Proc: TUS_Service = nil; const ProcofClass: TUS_Service_of_Object = nil): THandle;
Function DelService(const hService: THandle): integer;
- Function CallService(const ServiceName: PChar; const wParam, lParam: dWord): integer;
+ Function CallService(const ServiceName: PChar; const wParam: TwParam; lParam: TlParam): integer;
Function NametoHash(const ServiceName: TServiceName): Integer;
Function ServiceExists(const ServiceName: PChar): Integer;
@@ -210,7 +210,7 @@ end;
// Function Calls a Services Proc
// Returns Services Return Value or SERVICE_NOT_FOUND on Failure
//------------
-Function TServiceManager.CallService(const ServiceName: PChar; const wParam, lParam: dWord): integer;
+Function TServiceManager.CallService(const ServiceName: PChar; const wParam: TwParam; lParam: TlParam): integer;
var
SExists: Integer;
Service: PServiceInfo;
diff --git a/Game/Code/Classes/uPluginLoader.pas b/Game/Code/Classes/uPluginLoader.pas
index 87951fed..b018ccc2 100644
--- a/Game/Code/Classes/uPluginLoader.pas
+++ b/Game/Code/Classes/uPluginLoader.pas
@@ -65,10 +65,10 @@ type
Procedure CallDeInit(Index: Cardinal);
//Services offered
- Function LoadPlugin(wParam, lParam: DWord): integer; //wParam PChar(PluginName/PluginPath) | lParam (if wParam = nil) ID of the Plugin
- Function UnloadPlugin(wParam, lParam: DWord): integer; //wParam PChar(PluginName/PluginPath) | lParam (if wParam = nil) ID of the Plugin
- Function GetPluginInfo(wParam, lParam: DWord): 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, lParam: DWord): 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;
@@ -163,7 +163,7 @@ begin
BrowseDir(PluginPath);
Except
Result := False;
- Core.ReportError(Integer(PChar('Error Browsing and Loading.')), Integer(PChar('TPluginLoader')));
+ Core.ReportError(Integer(PChar('Error Browsing and Loading.')), PChar('TPluginLoader'));
end;
end;
@@ -279,7 +279,7 @@ begin
PInfo(@Info);
Except
Info.Name := '';
- Core.ReportError(Integer(PChar('Error getting Plugin Info: ' + Filename)), Integer(PChar('TPluginLoader')));
+ Core.ReportError(Integer(PChar('Error getting Plugin Info: ' + Filename)), PChar('TPluginLoader'));
end;
//Is Name set ?
@@ -312,7 +312,7 @@ begin
begin
Plugins[PluginID].State := 255;
FreeLibrary(hLib);
- Core.ReportError(Integer(PChar('Can''t get Plugin Procs from Libary: "' + Info.Name + '" ' + Filename)), Integer(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
@@ -326,10 +326,10 @@ begin
begin
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))), Integer(PChar('TPluginLoader')));
+ Core.ReportDebug(Integer(PChar('Found a newer Version of Plugin: ' + String(Info.Name))), PChar('TPluginLoader'));
//Unload Old Plugin
- UnloadPlugin(Integer(nil), PluginID);
+ UnloadPlugin(PluginID, nil);
//Fill with new Info
Plugins[PluginID].Info := Info;
@@ -347,7 +347,7 @@ begin
begin
FreeLibrary(hLib);
Plugins[PluginID].State := 255;
- Core.ReportError(Integer(PChar('Can''t get Plugin Procs from Libary: "' + Info.Name + '" ' + Filename)), Integer(PChar('TPluginLoader')));
+ Core.ReportError(Integer(PChar('Can''t get Plugin Procs from Libary: "' + Info.Name + '" ' + Filename)), PChar('TPluginLoader'));
end;
end
else
@@ -358,23 +358,23 @@ begin
else
begin
FreeLibrary(hLib);
- Core.ReportError(Integer(PChar('Plugin with this Name already exists: ' + String(Info.Name))), Integer(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)), Integer(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)), Integer(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)), Integer(PChar('TPluginLoader')));
+ Core.ReportError(Integer(PChar('Can''t load Plugin Libary: ' + Filename)), PChar('TPluginLoader'));
end;
end;
@@ -400,7 +400,7 @@ begin
begin
FreePlugin(Index);
Plugins[Index].State := 255;
- Core.ReportError(Integer(PChar('Error calling Load Function from Plugin: ' + String(Plugins[Index].Info.Name))), Integer(PChar('TPluginLoader')));
+ Core.ReportError(Integer(PChar('Error calling Load Function from Plugin: ' + String(Plugins[Index].Info.Name))), PChar('TPluginLoader'));
end;
end;
end;
@@ -431,7 +431,7 @@ begin
begin
FreePlugin(Index);
Plugins[Index].State := 255;
- Core.ReportError(Integer(PChar('Error calling Init Function from Plugin: ' + String(Plugins[Index].Info.Name))), Integer(PChar('TPluginLoader')));
+ Core.ReportError(Integer(PChar('Error calling Init Function from Plugin: ' + String(Plugins[Index].Info.Name))), PChar('TPluginLoader'));
end;
end;
end;
@@ -478,9 +478,9 @@ end;
//--------------
-// wParam PChar(PluginName/PluginPath) | lParam (if wParam = nil) ID of the Plugin
+// wParam PChar(PluginName/PluginPath) | wParam (if lParam = nil) ID of the Plugin
//--------------
-Function TPluginLoader.LoadPlugin(wParam, lParam: DWord): integer;
+Function TPluginLoader.LoadPlugin(wParam: TwParam; lParam: TlParam): integer;
var
Index: Integer;
sFile: String;
@@ -488,14 +488,14 @@ begin
Result := -1;
sFile := '';
//lParam is ID
- If (Pointer(wParam) = nil) then
+ If (lParam = nil) then
begin
- Index := lParam;
+ Index := wParam;
end
else
- begin //wParam is PChar
+ begin //lParam is PChar
try
- sFile := String(PChar(Pointer(wParam)));
+ sFile := String(PChar(lParam));
Index := PluginExists(sFile);
If (Index < 0) And FileExists(sFile) then
begin //Is Filename
@@ -516,23 +516,23 @@ begin
end;
//--------------
-// wParam PChar(PluginName/PluginPath) | lParam (if wParam = nil) ID of the Plugin
+// wParam PChar(PluginName/PluginPath) | wParam (if lParam = nil) ID of the Plugin
//--------------
-Function TPluginLoader.UnloadPlugin(wParam, lParam: DWord): integer;
+Function TPluginLoader.UnloadPlugin(wParam: TwParam; lParam: TlParam): integer;
var
Index: Integer;
sName: String;
begin
Result := -1;
//lParam is ID
- If (Pointer(wParam) = nil) then
+ If (lParam = nil) then
begin
- Index := lParam;
+ Index := wParam;
end
else
begin //wParam is PChar
try
- sName := String(PChar(Pointer(wParam)));
+ sName := String(PChar(lParam));
Index := PluginExists(sName);
except
Index := -2;
@@ -547,23 +547,23 @@ 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)
//--------------
-Function TPluginLoader.GetPluginInfo(wParam, lParam: DWord): 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 (Pointer(lParam) <> nil) AND (wParam < Length(Plugins)) then
+ If (lParam <> nil) AND (wParam < Length(Plugins)) then
begin
Try
Result := 1;
- PUS_PluginInfo(Pointer(lParam))^ := Plugins[wParam].Info;
+ PUS_PluginInfo(lParam)^ := Plugins[wParam].Info;
Except
End;
end;
end
- Else If (Pointer(lParam) = nil) then
+ Else If (lParam = nil) then
begin //Get Length of Plugin (Info) Array
Result := Length(Plugins);
end
@@ -571,10 +571,10 @@ begin
begin
Try
For I := 0 to high(Plugins) do
- PAUS_PluginInfo(Pointer(lParam))^[I] := Plugins[I].Info;
+ PAUS_PluginInfo(lParam)^[I] := Plugins[I].Info;
Result := Length(Plugins);
Except
- Core.ReportError(Integer(PChar('Could not write PluginInfo Array')), Integer(PChar('TPluginLoader')));
+ Core.ReportError(Integer(PChar('Could not write PluginInfo Array')), PChar('TPluginLoader'));
End;
end;
@@ -583,18 +583,18 @@ 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))
//--------------
-Function TPluginLoader.GetPluginState(wParam, lParam: DWord): 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
begin
Result := Plugins[wParam].State;
end;
end
- Else If (Pointer(lParam) = nil) then
+ Else If (lParam = nil) then
begin //Get Length of Plugin (Info) Array
Result := Length(Plugins);
end
@@ -602,10 +602,10 @@ begin
begin
Try
For I := 0 to high(Plugins) do
- Byte(Pointer(lParam + I)^) := Plugins[I].State;
+ Byte(Pointer(Integer(lParam) + I)^) := Plugins[I].State;
Result := Length(Plugins);
Except
- Core.ReportError(Integer(PChar('Could not write PluginState Array')), Integer(PChar('TPluginLoader')));
+ Core.ReportError(Integer(PChar('Could not write PluginState Array')), PChar('TPluginLoader'));
End;
end;
end;
@@ -654,7 +654,7 @@ begin
If (PluginLoader = nil) then
begin
Result := False;
- Core.ReportError(Integer(PChar('Could not get Pointer to PluginLoader')), Integer(PChar('TtehPlugins')));
+ Core.ReportError(Integer(PChar('Could not get Pointer to PluginLoader')), PChar('TtehPlugins'));
end
else
begin
@@ -676,10 +676,10 @@ begin
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))), Integer(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))), Integer(PChar('TtehPlugins')));
+ Core.ReportDebug(Integer(PChar('Plugin loaded succesful: ' + String(PluginLoader.Plugins[I].Info.Name))), PChar('TtehPlugins'));
Inc(I);
end;
@@ -690,7 +690,7 @@ begin
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 + '"')), Integer(PChar('TtehPlugins')));
+ Core.ReportError(Integer(PChar('Plugin causes Error during loading process: ' + PluginLoader.Plugins[I].Info.Name + ', ErrorMsg: "' + E.Message + '"')), PChar('TtehPlugins'));
//don't forget to increase I
@@ -736,10 +736,10 @@ 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))), Integer(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))), Integer(PChar('TtehPlugins')));
+ Core.ReportDebug(Integer(PChar('Plugin inited succesful: ' + String(PluginLoader.Plugins[I].Info.Name))), PChar('TtehPlugins'));
//don't forget to increase I
Inc(I);
@@ -749,7 +749,7 @@ begin
// => 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))), Integer(PChar('TtehPlugins')));
+ Core.ReportError(Integer(PChar('Plugin causes Error during init process: ' + String(PluginLoader.Plugins[I].Info.Name))), PChar('TtehPlugins'));
//don't forget to increase I
Inc(I);