From 776a838dbeb15a8002d33b637a136ffbeeb330b7 Mon Sep 17 00:00:00 2001 From: goat Date: Wed, 25 Dec 2024 23:47:18 +0100 Subject: [PATCH] remove legacy MonoMod patches for codebase and assembly location --- Dalamud/Plugin/Internal/PluginManager.cs | 125 ------------------- Dalamud/Plugin/Internal/Types/LocalPlugin.cs | 4 - 2 files changed, 129 deletions(-) diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 45a923aed..b70b74b03 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -134,9 +134,6 @@ internal class PluginManager : IInternalDisposableService this.configuration.PluginTestingOptIns ??= new(); this.MainRepo = PluginRepository.CreateMainRepo(this.happyHttpClient); - // NET8 CHORE - // this.ApplyPatches(); - registerStartupBlocker( Task.Run(this.LoadAndStartLoadSyncPlugins), "Waiting for plugins that asked to be loaded before the game."); @@ -433,10 +430,6 @@ internal class PluginManager : IInternalDisposableService await Task.WhenAll(disposablePlugins.Select(plugin => plugin.DisposeAsync().AsTask())) .SuppressException(); } - - // NET8 CHORE - // this.assemblyLocationMonoHook?.Dispose(); - // this.assemblyCodeBaseMonoHook?.Dispose(); } /// @@ -876,9 +869,6 @@ internal class PluginManager : IInternalDisposableService this.installedPluginsList.Remove(plugin); } - // NET8 CHORE - // PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _); - this.NotifyinstalledPluginsListChanged(); this.NotifyAvailablePluginsChanged(); } @@ -1677,8 +1667,6 @@ internal class PluginManager : IInternalDisposableService } catch (InvalidPluginException) { - // NET8 CHORE - // PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _); throw; } catch (BannedPluginException) @@ -1724,8 +1712,6 @@ internal class PluginManager : IInternalDisposableService } else { - // NET8 CHORE - // PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _); throw; } } @@ -1934,114 +1920,3 @@ internal class PluginManager : IInternalDisposableService public static string DalamudPluginUpdateFailed(string name, Version version, string why) => Loc.Localize("DalamudPluginUpdateFailed", " 》 {0} update to v{1} failed ({2}).").Format(name, version, why); } } - -// NET8 CHORE -/* -/// -/// Class responsible for loading and unloading plugins. -/// This contains the assembly patching functionality to resolve assembly locations. -/// -internal partial class PluginManager -{ - /// - /// A mapping of plugin assembly name to patch data. Used to fill in missing data due to loading - /// plugins via byte[]. - /// - internal static readonly ConcurrentDictionary PluginLocations = new(); - - private MonoMod.RuntimeDetour.Hook? assemblyLocationMonoHook; - private MonoMod.RuntimeDetour.Hook? assemblyCodeBaseMonoHook; - - /// - /// Patch method for internal class RuntimeAssembly.Location, also known as Assembly.Location. - /// This patch facilitates resolving the assembly location for plugins that are loaded via byte[]. - /// It should never be called manually. - /// - /// A delegate that acts as the original method. - /// The equivalent of `this`. - /// The plugin location, or the result from the original method. - private static string AssemblyLocationPatch(Func orig, Assembly self) - { - var result = orig(self); - - if (string.IsNullOrEmpty(result)) - { - foreach (var assemblyName in GetStackFrameAssemblyNames()) - { - if (PluginLocations.TryGetValue(assemblyName, out var data)) - { - result = data.Location; - break; - } - } - } - - result ??= string.Empty; - - Log.Verbose($"Assembly.Location // {self.FullName} // {result}"); - return result; - } - - /// - /// Patch method for internal class RuntimeAssembly.CodeBase, also known as Assembly.CodeBase. - /// This patch facilitates resolving the assembly location for plugins that are loaded via byte[]. - /// It should never be called manually. - /// - /// A delegate that acts as the original method. - /// The equivalent of `this`. - /// The plugin code base, or the result from the original method. - private static string AssemblyCodeBasePatch(Func orig, Assembly self) - { - var result = orig(self); - - if (string.IsNullOrEmpty(result)) - { - foreach (var assemblyName in GetStackFrameAssemblyNames()) - { - if (PluginLocations.TryGetValue(assemblyName, out var data)) - { - result = data.CodeBase; - break; - } - } - } - - result ??= string.Empty; - - Log.Verbose($"Assembly.CodeBase // {self.FullName} // {result}"); - return result; - } - - private static IEnumerable GetStackFrameAssemblyNames() - { - var stackTrace = new StackTrace(); - var stackFrames = stackTrace.GetFrames(); - - foreach (var stackFrame in stackFrames) - { - var methodBase = stackFrame.GetMethod(); - if (methodBase == null) - continue; - - yield return methodBase.Module.Assembly.FullName!; - } - } - - private void ApplyPatches() - { - var targetType = typeof(PluginManager).Assembly.GetType(); - - var locationTarget = targetType.GetProperty(nameof(Assembly.Location))!.GetGetMethod(); - var locationPatch = typeof(PluginManager).GetMethod(nameof(AssemblyLocationPatch), BindingFlags.NonPublic | BindingFlags.Static); - this.assemblyLocationMonoHook = new MonoMod.RuntimeDetour.Hook(locationTarget, locationPatch); - -#pragma warning disable CS0618 -#pragma warning disable SYSLIB0012 - var codebaseTarget = targetType.GetProperty(nameof(Assembly.CodeBase))?.GetGetMethod(); -#pragma warning restore SYSLIB0012 -#pragma warning restore CS0618 - var codebasePatch = typeof(PluginManager).GetMethod(nameof(AssemblyCodeBasePatch), BindingFlags.NonPublic | BindingFlags.Static); - this.assemblyCodeBaseMonoHook = new MonoMod.RuntimeDetour.Hook(codebaseTarget, codebasePatch); - } -} -*/ diff --git a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs index ed3a94994..43bba0a5b 100644 --- a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs @@ -382,10 +382,6 @@ internal class LocalPlugin : IAsyncDisposable } } - // Update the location for the Location and CodeBase patches - // NET8 CHORE - // PluginManager.PluginLocations[this.pluginType.Assembly.FullName] = new PluginPatchData(this.DllFile); - this.dalamudInterface = new(this, reason); this.serviceScope = ioc.GetScope();