diff --git a/Dalamud/Configuration/PluginConfigurations.cs b/Dalamud/Configuration/PluginConfigurations.cs
index de5e071c1..8e32fa992 100644
--- a/Dalamud/Configuration/PluginConfigurations.cs
+++ b/Dalamud/Configuration/PluginConfigurations.cs
@@ -1,4 +1,5 @@
using System.IO;
+using System.Reflection;
using Dalamud.Storage;
using Newtonsoft.Json;
@@ -116,9 +117,18 @@ public sealed class PluginConfigurations
/// Plugin Configuration.
public T LoadForType(string pluginName) where T : IPluginConfiguration
{
- var path = this.GetConfigFile(pluginName);
+ if (this.GetConfigFile(pluginName) is not { Exists: true } path)
+ return default;
- return !path.Exists ? default : JsonConvert.DeserializeObject(File.ReadAllText(path.FullName));
+ return JsonConvert.DeserializeObject(
+ File.ReadAllText(path.FullName),
+ new JsonSerializerSettings
+ {
+ Converters =
+ [
+ DalamudAssemblyTypeNameForcingJsonConverter.Instance,
+ ],
+ });
// intentionally no type handling - it will break when updating a plugin at runtime
// and turns out to be unnecessary when we fully qualify the object type
@@ -162,4 +172,33 @@ public sealed class PluginConfigurations
}
private DirectoryInfo GetDirectoryPath(string pluginName) => new(Path.Combine(this.configDirectory.FullName, pluginName));
+
+ private class DalamudAssemblyTypeNameForcingJsonConverter : JsonConverter
+ {
+ public static readonly DalamudAssemblyTypeNameForcingJsonConverter Instance = new();
+
+ private static readonly Assembly DalamudAssembly = typeof(DalamudAssemblyTypeNameForcingJsonConverter).Assembly;
+
+ private static readonly JsonSerializer TypeNameForcingJsonConverterDefaultSerializer = new()
+ {
+ TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
+ TypeNameHandling = TypeNameHandling.Objects,
+ };
+
+ private DalamudAssemblyTypeNameForcingJsonConverter()
+ {
+ }
+
+ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) =>
+ TypeNameForcingJsonConverterDefaultSerializer.Serialize(writer, value);
+
+ public override object? ReadJson(
+ JsonReader reader,
+ Type objectType,
+ object? existingValue,
+ JsonSerializer serializer) =>
+ TypeNameForcingJsonConverterDefaultSerializer.Deserialize(reader, objectType);
+
+ public override bool CanConvert(Type objectType) => objectType.Assembly == DalamudAssembly;
+ }
}