Require Game.Mod to be give an a launch arg to OpenRA.Game.exe.

This commit is contained in:
Paul Chote
2017-04-21 16:55:16 +00:00
parent 215aa6fa60
commit 688feea33b
5 changed files with 16 additions and 23 deletions

View File

@@ -248,12 +248,12 @@ namespace OpenRA
// Special case handling of Game.Mod argument: if it matches a real filesystem path // Special case handling of Game.Mod argument: if it matches a real filesystem path
// then we use this to override the mod search path, and replace it with the mod id // then we use this to override the mod search path, and replace it with the mod id
var modArgument = args.GetValue("Game.Mod", null); var modID = args.GetValue("Game.Mod", null);
var explicitModPaths = new string[0]; var explicitModPaths = new string[0];
if (modArgument != null && (File.Exists(modArgument) || Directory.Exists(modArgument))) if (modID != null && (File.Exists(modID) || Directory.Exists(modID)))
{ {
explicitModPaths = new[] { modArgument }; explicitModPaths = new[] { modID };
args.ReplaceValue("Game.Mod", Path.GetFileNameWithoutExtension(modArgument)); modID = Path.GetFileNameWithoutExtension(modID);
} }
InitializeSettings(args); InitializeSettings(args);
@@ -330,7 +330,7 @@ namespace OpenRA
foreach (var mod in ExternalMods) foreach (var mod in ExternalMods)
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
InitializeMod(Settings.Game.Mod, args); InitializeMod(modID, args);
} }
public static void InitializeMod(string mod, Arguments args) public static void InitializeMod(string mod, Arguments args)
@@ -360,12 +360,10 @@ namespace OpenRA
ModData = null; ModData = null;
// Fall back to default if the mod doesn't exist
if (mod == null) if (mod == null)
mod = args.GetValue("Engine.DefaultMod", "modchooser"); throw new InvalidOperationException("Game.Mod argument missing or mod could not be found.");
Console.WriteLine("Loading mod: {0}", mod); Console.WriteLine("Loading mod: {0}", mod);
Settings.Game.Mod = mod;
Sound.StopVideo(); Sound.StopVideo();

View File

@@ -154,10 +154,6 @@ namespace OpenRA
public class GameSettings public class GameSettings
{ {
[Desc("Load a specific mod on startup.")]
public string Mod = null;
public string PreviousMod = "ra";
public string Platform = "Default"; public string Platform = "Default";
public bool ViewportEdgeScroll = true; public bool ViewportEdgeScroll = true;

View File

@@ -93,7 +93,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// so we can't do this inside the input handler. // so we can't do this inside the input handler.
Game.RunAfterTick(() => Game.RunAfterTick(() =>
{ {
Game.Settings.Game.PreviousMod = modData.Manifest.Id;
Game.InitializeMod("modchooser", null); Game.InitializeMod("modchooser", null);
}); });
}; };

View File

@@ -115,9 +115,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
catch (Exception) { } catch (Exception) { }
} }
Manifest initialMod; SelectMod(Game.Mods["ra"]);
Game.Mods.TryGetValue(Game.Settings.Game.PreviousMod, out initialMod);
SelectMod(initialMod != null && initialMod.Id != "modchooser" ? initialMod : Game.Mods["ra"]);
RebuildModList(); RebuildModList();
} }

View File

@@ -30,14 +30,17 @@ namespace OpenRA.Server
// Special case handling of Game.Mod argument: if it matches a real filesystem path // Special case handling of Game.Mod argument: if it matches a real filesystem path
// then we use this to override the mod search path, and replace it with the mod id // then we use this to override the mod search path, and replace it with the mod id
var modArgument = arguments.GetValue("Game.Mod", null); var modID = arguments.GetValue("Game.Mod", null);
var explicitModPaths = new string[0]; var explicitModPaths = new string[0];
if (modArgument != null && (File.Exists(modArgument) || Directory.Exists(modArgument))) if (modID != null && (File.Exists(modID) || Directory.Exists(modID)))
{ {
explicitModPaths = new[] { modArgument }; explicitModPaths = new[] { modID };
arguments.ReplaceValue("Game.Mod", Path.GetFileNameWithoutExtension(modArgument)); modID = Path.GetFileNameWithoutExtension(modID);
} }
if (modID == null)
throw new InvalidOperationException("Game.Mod argument missing or mod could not be found.");
// HACK: The engine code assumes that Game.Settings is set. // HACK: The engine code assumes that Game.Settings is set.
// This isn't nearly as bad as ModData, but is still not very nice. // This isn't nearly as bad as ModData, but is still not very nice.
Game.InitializeSettings(arguments); Game.InitializeSettings(arguments);
@@ -48,16 +51,15 @@ namespace OpenRA.Server
FieldLoader.GetValue<string[]>("MOD_SEARCH_PATHS", envModSearchPaths) : FieldLoader.GetValue<string[]>("MOD_SEARCH_PATHS", envModSearchPaths) :
new[] { Path.Combine(".", "mods") }; new[] { Path.Combine(".", "mods") };
var mod = Game.Settings.Game.Mod;
var mods = new InstalledMods(modSearchPaths, explicitModPaths); var mods = new InstalledMods(modSearchPaths, explicitModPaths);
// HACK: The engine code *still* assumes that Game.ModData is set // HACK: The engine code *still* assumes that Game.ModData is set
var modData = Game.ModData = new ModData(mods[mod], mods); var modData = Game.ModData = new ModData(mods[modID], mods);
modData.MapCache.LoadMaps(); modData.MapCache.LoadMaps();
settings.Map = modData.MapCache.ChooseInitialMap(settings.Map, new MersenneTwister()); settings.Map = modData.MapCache.ChooseInitialMap(settings.Map, new MersenneTwister());
Console.WriteLine("[{0}] Starting dedicated server for mod: {1}", DateTime.Now.ToString(settings.TimestampFormat), mod); Console.WriteLine("[{0}] Starting dedicated server for mod: {1}", DateTime.Now.ToString(settings.TimestampFormat), modID);
while (true) while (true)
{ {
var server = new Server(new IPEndPoint(IPAddress.Any, settings.ListenPort), settings, modData, true); var server = new Server(new IPEndPoint(IPAddress.Any, settings.ListenPort), settings, modData, true);