Support loading mods from arbitrary locations.
This commit is contained in:
@@ -244,6 +244,16 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);
|
Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
var modArgument = args.GetValue("Game.Mod", null);
|
||||||
|
string customModPath = null;
|
||||||
|
if (modArgument != null && (File.Exists(modArgument) || Directory.Exists(modArgument)))
|
||||||
|
{
|
||||||
|
customModPath = modArgument;
|
||||||
|
args.ReplaceValue("Game.Mod", Path.GetFileNameWithoutExtension(modArgument));
|
||||||
|
}
|
||||||
|
|
||||||
InitializeSettings(args);
|
InitializeSettings(args);
|
||||||
|
|
||||||
Log.AddChannel("perf", "perf.log");
|
Log.AddChannel("perf", "perf.log");
|
||||||
@@ -303,7 +313,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
GlobalChat = new GlobalChat();
|
GlobalChat = new GlobalChat();
|
||||||
|
|
||||||
Mods = new InstalledMods();
|
Mods = new InstalledMods(customModPath);
|
||||||
Console.WriteLine("Available mods:");
|
Console.WriteLine("Available mods:");
|
||||||
foreach (var mod in Mods)
|
foreach (var mod in Mods)
|
||||||
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);
|
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
readonly Dictionary<string, Manifest> mods;
|
readonly Dictionary<string, Manifest> mods;
|
||||||
|
|
||||||
public InstalledMods()
|
public InstalledMods(string customModPath)
|
||||||
{
|
{
|
||||||
mods = GetInstalledMods();
|
mods = GetInstalledMods(customModPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<Pair<string, string>> GetCandidateMods()
|
static IEnumerable<Pair<string, string>> GetCandidateMods()
|
||||||
@@ -89,10 +89,14 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dictionary<string, Manifest> GetInstalledMods()
|
static Dictionary<string, Manifest> GetInstalledMods(string customModPath)
|
||||||
{
|
{
|
||||||
var ret = new Dictionary<string, Manifest>();
|
var ret = new Dictionary<string, Manifest>();
|
||||||
foreach (var pair in GetCandidateMods())
|
var candidates = GetCandidateMods();
|
||||||
|
if (customModPath != null)
|
||||||
|
candidates = candidates.Append(Pair.New(Path.GetFileNameWithoutExtension(customModPath), customModPath));
|
||||||
|
|
||||||
|
foreach (var pair in candidates)
|
||||||
{
|
{
|
||||||
var mod = LoadMod(pair.First, pair.Second);
|
var mod = LoadMod(pair.First, pair.Second);
|
||||||
|
|
||||||
|
|||||||
@@ -35,5 +35,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
public bool Contains(string key) { return args.ContainsKey(key); }
|
public bool Contains(string key) { return args.ContainsKey(key); }
|
||||||
public string GetValue(string key, string defaultValue) { return Contains(key) ? args[key] : defaultValue; }
|
public string GetValue(string key, string defaultValue) { return Contains(key) ? args[key] : defaultValue; }
|
||||||
|
public void ReplaceValue(string key, string value) { args[key] = value; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
@@ -20,18 +21,29 @@ namespace OpenRA.Server
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var arguments = new Arguments(args);
|
||||||
Log.AddChannel("debug", "dedicated-debug.log");
|
Log.AddChannel("debug", "dedicated-debug.log");
|
||||||
Log.AddChannel("perf", "dedicated-perf.log");
|
Log.AddChannel("perf", "dedicated-perf.log");
|
||||||
Log.AddChannel("server", "dedicated-server.log");
|
Log.AddChannel("server", "dedicated-server.log");
|
||||||
Log.AddChannel("nat", "dedicated-nat.log");
|
Log.AddChannel("nat", "dedicated-nat.log");
|
||||||
|
|
||||||
|
// 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
|
||||||
|
var modArgument = arguments.GetValue("Game.Mod", null);
|
||||||
|
string customModPath = null;
|
||||||
|
if (modArgument != null && (File.Exists(modArgument) || Directory.Exists(modArgument)))
|
||||||
|
{
|
||||||
|
customModPath = modArgument;
|
||||||
|
arguments.ReplaceValue("Game.Mod", Path.GetFileNameWithoutExtension(modArgument));
|
||||||
|
}
|
||||||
|
|
||||||
// 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(new Arguments(args));
|
Game.InitializeSettings(arguments);
|
||||||
var settings = Game.Settings.Server;
|
var settings = Game.Settings.Server;
|
||||||
|
|
||||||
var mod = Game.Settings.Game.Mod;
|
var mod = Game.Settings.Game.Mod;
|
||||||
var mods = new InstalledMods();
|
var mods = new InstalledMods(customModPath);
|
||||||
|
|
||||||
// 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[mod], mods);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
@@ -43,22 +44,29 @@ namespace OpenRA
|
|||||||
Log.AddChannel("debug", null);
|
Log.AddChannel("debug", null);
|
||||||
|
|
||||||
Game.InitializeSettings(Arguments.Empty);
|
Game.InitializeSettings(Arguments.Empty);
|
||||||
var mods = new InstalledMods();
|
|
||||||
|
|
||||||
if (args.Length == 0)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
PrintUsage(mods, null);
|
PrintUsage(new InstalledMods(null), null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var modName = args[0];
|
var modId = args[0];
|
||||||
if (!mods.Keys.Contains(modName))
|
string customModPath = null;
|
||||||
|
if (File.Exists(modId) || Directory.Exists(modId))
|
||||||
|
{
|
||||||
|
customModPath = modId;
|
||||||
|
modId = Path.GetFileNameWithoutExtension(modId);
|
||||||
|
}
|
||||||
|
|
||||||
|
var mods = new InstalledMods(customModPath);
|
||||||
|
if (!mods.Keys.Contains(modId))
|
||||||
{
|
{
|
||||||
PrintUsage(mods, null);
|
PrintUsage(mods, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var modData = new ModData(mods[modName], mods);
|
var modData = new ModData(mods[modId], mods);
|
||||||
var utility = new Utility(modData, mods);
|
var utility = new Utility(modData, mods);
|
||||||
args = args.Skip(1).ToArray();
|
args = args.Skip(1).ToArray();
|
||||||
var actions = new UtilityActions();
|
var actions = new UtilityActions();
|
||||||
|
|||||||
Reference in New Issue
Block a user