From dc783e0c2b3e7a89e0ff05fe9bb61a343a9ccea3 Mon Sep 17 00:00:00 2001 From: Critical Impact Date: Mon, 2 Feb 2026 16:56:31 +1000 Subject: [PATCH] Use plugin internal name for datashare tracking --- .../Windows/Data/Widgets/DataShareWidget.cs | 4 +- Dalamud/Plugin/DalamudPluginInterface.cs | 8 ++-- Dalamud/Plugin/Ipc/Internal/DataShare.cs | 38 ++++++------------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/DataShareWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/DataShareWidget.cs index 73e9d18f8..54bb84ceb 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/DataShareWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/DataShareWidget.cs @@ -87,7 +87,7 @@ internal class DataShareWidget : IDataWindowWidget try { var dataShare = Service.Get(); - var data2 = dataShare.GetData(name); + var data2 = dataShare.GetData(name, "DataShareWidget"); try { data = Encoding.UTF8.GetBytes( @@ -98,7 +98,7 @@ internal class DataShareWidget : IDataWindowWidget } finally { - dataShare.RelinquishData(name); + dataShare.RelinquishData(name, "DataShareWidget"); } } catch (Exception e) diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index df1d0f6e9..28affddb4 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -227,19 +227,19 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa /// public T GetOrCreateData(string tag, Func dataGenerator) where T : class - => Service.Get().GetOrCreateData(tag, dataGenerator); + => Service.Get().GetOrCreateData(tag, this.plugin.InternalName, dataGenerator); /// public void RelinquishData(string tag) - => Service.Get().RelinquishData(tag); + => Service.Get().RelinquishData(tag, this.plugin.InternalName); /// public bool TryGetData(string tag, [NotNullWhen(true)] out T? data) where T : class - => Service.Get().TryGetData(tag, out data); + => Service.Get().TryGetData(tag, this.plugin.InternalName, out data); /// public T? GetData(string tag) where T : class - => Service.Get().GetData(tag); + => Service.Get().GetData(tag, this.plugin.InternalName); /// public ICallGateProvider GetIpcProvider(string name) diff --git a/Dalamud/Plugin/Ipc/Internal/DataShare.cs b/Dalamud/Plugin/Ipc/Internal/DataShare.cs index becbe1211..f71d8d2c2 100644 --- a/Dalamud/Plugin/Ipc/Internal/DataShare.cs +++ b/Dalamud/Plugin/Ipc/Internal/DataShare.cs @@ -33,16 +33,15 @@ internal class DataShare : IServiceType /// /// The type of the stored data - needs to be a reference type that is shared through Dalamud itself, not loaded by the plugin. /// The name for the data cache. + /// The name of the caller. /// The function that generates the data if it does not already exist. /// Either the existing data for or the data generated by . /// Thrown if a cache for exists, but contains data of a type not assignable to . /// Thrown if the stored data for a cache is null. /// Thrown if throws an exception or returns null. - public T GetOrCreateData(string tag, Func dataGenerator) + public T GetOrCreateData(string tag, string callerName, Func dataGenerator) where T : class { - var callerName = GetCallerName(); - Lazy cacheLazy; lock (this.caches) { @@ -58,7 +57,8 @@ internal class DataShare : IServiceType /// If no assembly uses the data anymore, the cache will be removed from the data share and if it is an IDisposable, Dispose will be called on it. /// /// The name for the data cache. - public void RelinquishData(string tag) + /// The name of the caller. + public void RelinquishData(string tag, string callerName) { DataCache cache; lock (this.caches) @@ -66,8 +66,6 @@ internal class DataShare : IServiceType if (!this.caches.TryGetValue(tag, out var cacheLazy)) return; - var callerName = GetCallerName(); - cache = cacheLazy.Value; if (!cache.UserAssemblyNames.Remove(callerName) || cache.UserAssemblyNames.Count > 0) return; @@ -84,7 +82,7 @@ internal class DataShare : IServiceType } catch (Exception e) { - Log.Error(e, "[DataShare] Failed to dispose [{Tag:l}] after it was removed from all shares.", tag); + Log.Error(e, "[DataShare] Failed to dispose [{Tag:l}] after it was removed from all shares.", tag); } } else @@ -99,9 +97,10 @@ internal class DataShare : IServiceType /// /// The type of the stored data - needs to be a reference type that is shared through Dalamud itself, not loaded by the plugin. /// The name for the data cache. + /// The name of the caller. /// The requested data on success, null otherwise. /// True if the requested data exists and is assignable to the requested type. - public bool TryGetData(string tag, [NotNullWhen(true)] out T? data) + public bool TryGetData(string tag, string callerName, [NotNullWhen(true)] out T? data) where T : class { data = null; @@ -112,7 +111,7 @@ internal class DataShare : IServiceType return false; } - return cacheLazy.Value.TryGetData(GetCallerName(), out data, out _); + return cacheLazy.Value.TryGetData(callerName, out data, out _); } /// @@ -121,11 +120,12 @@ internal class DataShare : IServiceType /// /// The type of the stored data - needs to be a reference type that is shared through Dalamud itself, not loaded by the plugin. /// The name for the data cache. + /// The name of the caller. /// The requested data. /// Thrown if is not registered. /// Thrown if a cache for exists, but contains data of a type not assignable to . /// Thrown if the stored data for a cache is null. - public T GetData(string tag) + public T GetData(string tag, string callerName) where T : class { Lazy cacheLazy; @@ -135,7 +135,7 @@ internal class DataShare : IServiceType throw new KeyNotFoundException($"The data cache [{tag}] is not registered."); } - return cacheLazy.Value.TryGetData(GetCallerName(), out var value, out var ex) ? value : throw ex; + return cacheLazy.Value.TryGetData(callerName, out var value, out var ex) ? value : throw ex; } /// @@ -150,20 +150,4 @@ internal class DataShare : IServiceType kvp => (kvp.Key, kvp.Value.Value.CreatorAssemblyName, kvp.Value.Value.UserAssemblyNames.ToArray())); } } - - /// Obtain the last assembly name in the stack trace that is not a system or dalamud assembly. - private static string GetCallerName() - { - var frames = new StackTrace().GetFrames(); - foreach (var frame in frames.Reverse()) - { - var name = frame.GetMethod()?.DeclaringType?.Assembly.GetName().Name ?? "Unknown"; - if (!name.StartsWith("System") && !name.StartsWith("Dalamud")) - { - return name; - } - } - - return "Unknown"; - } }