ChivalryServerLauncher/source/model/Game.Chivalry.MedievalWarfa...

133 lines
3.1 KiB
ObjectPascal

unit Game.Chivalry.MedievalWarfare;
interface
uses
System.Generics.Collections,
Game.Base,
Game.Chivalry,
Game.Intf;
type
{ I haven't actually done any research into the dedicated server
for the other Chivalry game, so for now most stuff is implemented
in the base Chivalry class. }
TChivalryMedievalWarfareGame = class(TChivalryGame)
protected
procedure LoadPredefinedMapList(AList: TList<TGameMap>); override;
public
class function GameName: string; override;
class function AutoDetect: TCustomGame; override;
end;
implementation
uses
System.Classes,
System.IOUtils,
System.SysUtils,
System.Win.Registry,
Winapi.Windows,
superobject,
Resources,
Game.Registry;
const
SteamKey = '\Software\Valve\Steam';
SteamValuePath = 'SteamPath';
ChivalryServerSteamPath = 'steamapps\common\chivalry_ded_server\';
{ TChivalryMedievalWarfareGame }
class function TChivalryMedievalWarfareGame.GameName: string;
begin
Result := 'Chivalry: Medieval Warfare';
end;
class function TChivalryMedievalWarfareGame.AutoDetect: TCustomGame;
var
registry: TRegistry;
steamPath: string;
serverPath: string;
begin
Result := nil;
steamPath := '';
registry := TRegistry.Create(KEY_READ);
try
registry.RootKey := HKEY_CURRENT_USER;
if registry.OpenKeyReadOnly(SteamKey) then
try
if registry.ValueExists(SteamValuePath) then
steamPath := StringReplace(registry.ReadString(SteamValuePath), '/', '\', [rfReplaceAll]);
finally
registry.CloseKey;
end;
finally
FreeAndNil(registry);
end;
if (Length(steamPath) > 0) then
begin
serverPath := IncludeTrailingPathDelimiter(steamPath) + ChivalryServerSteamPath;
if DirectoryExists(serverPath) then
Result := TChivalryMedievalWarfareGame.Create(serverPath);
end;
end;
procedure TChivalryMedievalWarfareGame.LoadPredefinedMapList(AList: TList<TGameMap>);
var
mapListFileName: string;
mapList: ISuperObject;
category: ISuperObject;
categoryName: string;
maps: ISuperObject;
map: ISuperObject;
mapName: string;
displayName: string;
previewName: string;
begin
mapListFileName := Resources.GetAssetPath(Resources.AssetChivalryMedievalWarfareMapListFileName);
if not FileExists(mapListFileName) then
exit;
mapList := SO(TFile.ReadAllText(mapListFileName));
if not Assigned(mapList) then
exit;
for category in mapList do
begin
categoryName := Trim(category.S['category']);
if Length(categoryName) > 0 then
begin
maps := category.O['maps'];
if Assigned(maps) then
begin
for map in maps do
begin
mapName := Trim(map.S['name']);
displayName := Trim(map.S['displayName']);
previewName := Trim(map.S['preview']);
AList.Add(TGameMap.Create(mapName, displayname, categoryName, previewName));
end;
end;
end;
end;
end;
initialization
TGameRegistry.Register(TChivalryMedievalWarfareGame);
end.