From 52e7023bd73b6527fea9dad49d026f084a1546a4 Mon Sep 17 00:00:00 2001 From: REDCODE Date: Sun, 14 Jun 2026 00:28:31 +0200 Subject: [PATCH] Fixed Ele/EleD and EleI remapping using additional mappings --- 2DGAMELIB/_2DGAMELIB/RemappedTypeBinder.cs | 24 +++++++++++++++---- .../SlaveMatrix/GameClasses/Program.cs | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/2DGAMELIB/_2DGAMELIB/RemappedTypeBinder.cs b/2DGAMELIB/_2DGAMELIB/RemappedTypeBinder.cs index 6e9addb..2a9e5a9 100644 --- a/2DGAMELIB/_2DGAMELIB/RemappedTypeBinder.cs +++ b/2DGAMELIB/_2DGAMELIB/RemappedTypeBinder.cs @@ -1,7 +1,7 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; namespace _2DGAMELIB { @@ -9,6 +9,12 @@ namespace _2DGAMELIB { private readonly Dictionary _typeOnlyMap = new(); private readonly Dictionary _fullMap = new(); + private static readonly ConcurrentDictionary _additionalMappings = new(); + + public static void RegisterMapping(string oldTypeName, Type newType) + { + _additionalMappings[oldTypeName] = newType; + } public RemappedTypeBinder Add(string oldTypeName, Type newType) { @@ -33,6 +39,9 @@ namespace _2DGAMELIB if (_typeOnlyMap.TryGetValue(typeName, out var type)) return type; + if (_additionalMappings.TryGetValue(typeName, out var extra)) + return extra; + var fullName = typeName; if (!string.IsNullOrEmpty(assemblyName)) fullName += ", " + assemblyName; @@ -90,11 +99,16 @@ namespace _2DGAMELIB var inner = typeName.Substring(bracketStart, bracketEnd - bracketStart + 1); // Replace mapped old type names (longest first to avoid partial prefix matches) - var sortedKeys = new List(_typeOnlyMap.Keys); - sortedKeys.Sort((a, b) => b.Length.CompareTo(a.Length)); - foreach (var old in sortedKeys) + var allKeys = new List(_typeOnlyMap.Keys); + allKeys.AddRange(_additionalMappings.Keys); + allKeys.Sort((a, b) => b.Length.CompareTo(a.Length)); + foreach (var old in allKeys) { - var rep = _typeOnlyMap[old].FullName; + Type repType; + if (!_typeOnlyMap.TryGetValue(old, out repType)) + _additionalMappings.TryGetValue(old, out repType); + if (repType == null) continue; + var rep = repType.FullName; inner = inner.Replace(old + ",", rep + ","); inner = inner.Replace(old + "]", rep + "]"); } diff --git a/SlaveMatrix/SlaveMatrix/GameClasses/Program.cs b/SlaveMatrix/SlaveMatrix/GameClasses/Program.cs index 263f3c7..37ba686 100644 --- a/SlaveMatrix/SlaveMatrix/GameClasses/Program.cs +++ b/SlaveMatrix/SlaveMatrix/GameClasses/Program.cs @@ -9,6 +9,9 @@ namespace SlaveMatrix static Program() { AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true); + RemappedTypeBinder.RegisterMapping("SlaveMatrix.Ele", typeof(Element)); + RemappedTypeBinder.RegisterMapping("SlaveMatrix.EleD", typeof(ElementData)); + RemappedTypeBinder.RegisterMapping("SlaveMatrix.EleI", typeof(ElementInstance)); } [STAThread]