2014-06-30 14:37:42 +00:00
|
|
|
unit Game.Chivalry.MedievalWarfare;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
System.Generics.Collections,
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
Game.Base,
|
2014-06-30 14:37:42 +00:00
|
|
|
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 LoadSupportedMapList(AList: TList<IGameMap>); override;
|
|
|
|
public
|
2014-06-30 16:07:40 +00:00
|
|
|
class function GameName: string; override;
|
|
|
|
class function AutoDetect: TCustomGame; override;
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
System.Classes,
|
|
|
|
System.IniFiles,
|
|
|
|
System.SysUtils,
|
2014-06-30 16:07:40 +00:00
|
|
|
System.Win.Registry,
|
|
|
|
Winapi.Windows,
|
2014-06-30 14:37:42 +00:00
|
|
|
|
|
|
|
Resources,
|
|
|
|
Game.Map,
|
|
|
|
Game.Registry;
|
|
|
|
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
const
|
|
|
|
SteamKey = '\Software\Valve\Steam';
|
|
|
|
SteamValuePath = 'SteamPath';
|
|
|
|
|
|
|
|
ChivalryServerSteamPath = 'steamapps\common\chivalry_ded_server\';
|
|
|
|
|
|
|
|
|
2014-06-30 14:37:42 +00:00
|
|
|
{ TChivalryMedievalWarfareGame }
|
2014-06-30 16:07:40 +00:00
|
|
|
class function TChivalryMedievalWarfareGame.GameName: string;
|
2014-06-30 14:37:42 +00:00
|
|
|
begin
|
|
|
|
Result := 'Chivalry: Medieval Warfare';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
class function TChivalryMedievalWarfareGame.AutoDetect: TCustomGame;
|
|
|
|
var
|
|
|
|
registry: TRegistry;
|
|
|
|
steamPath: string;
|
|
|
|
serverPath: string;
|
|
|
|
|
|
|
|
begin
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2014-06-30 14:37:42 +00:00
|
|
|
procedure TChivalryMedievalWarfareGame.LoadSupportedMapList(AList: TList<IGameMap>);
|
|
|
|
var
|
|
|
|
mapListFileName: string;
|
|
|
|
mapList: TMemIniFile;
|
|
|
|
categories: TStringList;
|
|
|
|
categoryName: string;
|
|
|
|
maps: TStringList;
|
|
|
|
mapIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
2014-06-30 16:07:40 +00:00
|
|
|
mapListFileName := Resources.GetAssetPath(Resources.AssetChivalryMedievalWarfareMapListFileName);
|
2014-06-30 14:37:42 +00:00
|
|
|
if not FileExists(mapListFileName) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
mapList := TMemIniFile.Create(mapListFileName);
|
|
|
|
try
|
|
|
|
categories := nil;
|
|
|
|
maps := nil;
|
|
|
|
try
|
|
|
|
categories := TStringList.Create;
|
|
|
|
maps := TStringList.Create;
|
|
|
|
|
|
|
|
mapList.ReadSections(categories);
|
|
|
|
|
|
|
|
for categoryName in categories do
|
|
|
|
begin
|
|
|
|
maps.Clear;
|
|
|
|
mapList.ReadSectionValues(categoryName, maps);
|
|
|
|
|
|
|
|
for mapIndex := 0 to Pred(maps.Count) do
|
|
|
|
AList.Add(TGameMap.Create(Trim(maps.Names[mapIndex]),
|
|
|
|
Trim(maps.ValueFromIndex[mapIndex]),
|
|
|
|
Trim(categoryName)));
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(maps);
|
|
|
|
FreeAndNil(categories);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(mapList);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
initialization
|
|
|
|
TGameRegistry.Register(TChivalryMedievalWarfareGame);
|
|
|
|
|
|
|
|
end.
|