diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index b92382d5d2..054197916e 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -428,7 +428,10 @@ namespace OpenRA ExternalMods = new ExternalMods(); - if (modID != null && Mods.TryGetValue(modID, out _)) + if (modID == null) + throw new InvalidOperationException("Game.Mod argument missing."); + + if (Mods.TryGetValue(modID, out var manifest)) { var launchPath = args.GetValue("Engine.LaunchPath", null); var launchArgs = new List(); @@ -444,12 +447,14 @@ namespace OpenRA ExternalMods.ClearInvalidRegistrations(ModRegistration.User); } + else + throw new InvalidOperationException($"Unknown or invalid mod '{modID}'."); Console.WriteLine("External mods:"); foreach (var mod in ExternalMods) Console.WriteLine($"\t{mod.Key} ({mod.Value.Version})"); - InitializeMod(modID, args); + InitializeMod(manifest, args); } public static IPlatform CreatePlatform(string platformName) @@ -465,7 +470,7 @@ namespace OpenRA return (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null); } - public static void InitializeMod(string mod, Arguments args) + public static void InitializeMod(Manifest manifest, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; @@ -489,17 +494,11 @@ namespace OpenRA ModData = null; - if (mod == null) - throw new InvalidOperationException("Game.Mod argument missing."); - - if (!Mods.ContainsKey(mod)) - throw new InvalidOperationException($"Unknown or invalid mod '{mod}'."); - - Console.WriteLine($"Loading mod: {mod}"); + Console.WriteLine($"Loading mod: {manifest.Id}"); Sound.StopVideo(); - ModData = new ModData(Mods[mod], Mods, true); + ModData = new ModData(manifest, Mods, true); LocalPlayerProfile = new LocalPlayerProfile(Path.Combine(Platform.SupportDir, Settings.Game.AuthProfile), ModData.Manifest.Get()); diff --git a/OpenRA.Mods.Common/FileSystem/ContentInstallerFileSystemLoader.cs b/OpenRA.Mods.Common/FileSystem/ContentInstallerFileSystemLoader.cs index cef00f44b8..3df6c8c950 100644 --- a/OpenRA.Mods.Common/FileSystem/ContentInstallerFileSystemLoader.cs +++ b/OpenRA.Mods.Common/FileSystem/ContentInstallerFileSystemLoader.cs @@ -95,8 +95,8 @@ namespace OpenRA.Mods.Common.FileSystem bool IFileSystemExternalContent.InstallContentIfRequired(ModData modData) { - if (!isContentAvailable) - Game.InitializeMod(ContentInstallerMod, new Arguments()); + if (!isContentAvailable && Game.Mods.TryGetValue(ContentInstallerMod, out var mod)) + Game.InitializeMod(mod, new Arguments()); return !isContentAvailable; } @@ -105,7 +105,8 @@ namespace OpenRA.Mods.Common.FileSystem { // Switching mods changes the world state (by disposing it), // so we can't do this inside the input handler. - Game.RunAfterTick(() => Game.InitializeMod(ContentInstallerMod, new Arguments())); + if (Game.Mods.TryGetValue(ContentInstallerMod, out var mod)) + Game.RunAfterTick(() => Game.InitializeMod(mod, new Arguments())); } } } diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index b76a7dc842..a2fbbafbde 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -88,8 +88,8 @@ namespace OpenRA.Mods.Common.LoadScreens if (replayMeta != null) { - var mod = replayMeta.GameInfo.Mod; - if (mod != null && mod != Game.ModData.Manifest.Id && Game.Mods.ContainsKey(mod)) + var modID = replayMeta.GameInfo.Mod; + if (modID != null && modID != Game.ModData.Manifest.Id && Game.Mods.TryGetValue(modID, out var mod)) Game.InitializeMod(mod, args); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs index 37ec4290f4..0f94e2dab8 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs @@ -23,11 +23,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic public ModContentLogic(ModData modData) { var content = modData.Manifest.Get(); + var mod = Game.Mods[content.Mod]; if (!IsModInstalled(content)) { var widgetArgs = new WidgetArgs { - { "continueLoading", () => Game.RunAfterTick(() => Game.InitializeMod(content.Mod, new Arguments())) }, + { "continueLoading", () => Game.RunAfterTick(() => Game.InitializeMod(mod, new Arguments())) }, { "content", content }, }; @@ -37,7 +38,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var widgetArgs = new WidgetArgs { - { "onCancel", () => Game.RunAfterTick(() => Game.InitializeMod(content.Mod, new Arguments())) }, + { "onCancel", () => Game.RunAfterTick(() => Game.InitializeMod(mod, new Arguments())) }, { "content", content }, };