From 5d83706eaebce27897544b47f746f44f3c510e5d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 25 Sep 2021 11:23:51 +0100 Subject: [PATCH] Require an explicit launch path for mod registrations. This also removes a workaround that allowed the current mod to be registered even if it defined a bogus path. Uses of Game.ExternalMods should therefore always use TryGetValue and correctly handle it returning false. --- OpenRA.Game/ExternalMods.cs | 12 ++++-------- OpenRA.Game/Game.cs | 16 ++++------------ .../ClearInvalidModRegistrationsCommand.cs | 6 +----- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/OpenRA.Game/ExternalMods.cs b/OpenRA.Game/ExternalMods.cs index c5855f76f2..d45fe1c189 100644 --- a/OpenRA.Game/ExternalMods.cs +++ b/OpenRA.Game/ExternalMods.cs @@ -191,7 +191,7 @@ namespace OpenRA /// * Filename doesn't match internal key /// * Fails to parse as a mod registration /// - internal void ClearInvalidRegistrations(ExternalMod activeMod, ModRegistration registration) + internal void ClearInvalidRegistrations(ModRegistration registration) { var sources = new List(); if (registration.HasFlag(ModRegistration.System)) @@ -206,7 +206,6 @@ namespace OpenRA sources.Add(Platform.GetSupportDir(SupportDirType.LegacyUser)); } - var activeModKey = ExternalMod.MakeKey(activeMod); foreach (var source in sources.Distinct()) { var metadataPath = Path.Combine(source, "ModMetadata"); @@ -222,13 +221,10 @@ namespace OpenRA var m = FieldLoader.Load(yaml); modKey = ExternalMod.MakeKey(m); - // Continue to the next entry if it is the active mod (even if the LaunchPath is bogus) - if (modKey == activeModKey) - continue; - // Continue to the next entry if this one is valid - if (File.Exists(m.LaunchPath) && Path.GetFileNameWithoutExtension(path) == modKey && - !(activeMod != null && m.LaunchPath == activeMod.LaunchPath && m.Id == activeMod.Id && m.Version != activeMod.Version)) + // HACK: Explicitly invalidate paths to OpenRA.dll to clean up bogus metadata files + // that were created after the initial migration from .NET Framework to Core/5. + if (File.Exists(m.LaunchPath) && Path.GetFileNameWithoutExtension(path) == modKey && Path.GetExtension(m.LaunchPath) != ".dll") continue; } catch (Exception e) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 3df307a941..6b448e7636 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -407,19 +407,11 @@ namespace OpenRA if (launchPath != null && launchPath.First() == '"' && launchPath.Last() == '"') launchPath = launchPath.Substring(1, launchPath.Length - 2); - if (launchPath == null) - { - // When launching the assembly directly we must propagate the Engine.EngineDir argument if defined - // Platform-specific launchers are expected to manage this internally. - launchPath = Assembly.GetEntryAssembly().Location; - if (!string.IsNullOrEmpty(engineDirArg)) - launchArgs.Add("Engine.EngineDir=\"" + engineDirArg + "\""); - } + // Metadata registration requires an explicit launch path + if (launchPath != null) + ExternalMods.Register(Mods[modID], launchPath, launchArgs, ModRegistration.User); - ExternalMods.Register(Mods[modID], launchPath, launchArgs, ModRegistration.User); - - if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out var activeMod)) - ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User); + ExternalMods.ClearInvalidRegistrations(ModRegistration.User); } Console.WriteLine("External mods:"); diff --git a/OpenRA.Game/UtilityCommands/ClearInvalidModRegistrationsCommand.cs b/OpenRA.Game/UtilityCommands/ClearInvalidModRegistrationsCommand.cs index dd9b464ac3..7cb133c95d 100644 --- a/OpenRA.Game/UtilityCommands/ClearInvalidModRegistrationsCommand.cs +++ b/OpenRA.Game/UtilityCommands/ClearInvalidModRegistrationsCommand.cs @@ -32,11 +32,7 @@ namespace OpenRA.UtilityCommands if (args[1] == "user" || args[1] == "both") type |= ModRegistration.User; - var mods = new ExternalMods(); - - ExternalMod activeMod = null; - mods.TryGetValue(ExternalMod.MakeKey(utility.ModData.Manifest), out activeMod); - mods.ClearInvalidRegistrations(activeMod, type); + new ExternalMods().ClearInvalidRegistrations(type); } } }