From 3842b9eed4ecfcc47c37665f255a263187446428 Mon Sep 17 00:00:00 2001 From: Norman Rasmussen Date: Sun, 1 Mar 2026 22:32:25 -0800 Subject: [PATCH] XPNC 10.0.1 --- .../TemplateCollectionServicePatches.cs | 39 +++++++++++++++++++ XtraPlzNoCrashes/manifest.json | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 XtraPlzNoCrashes/Patches/TemplateCollectionServicePatches.cs diff --git a/XtraPlzNoCrashes/Patches/TemplateCollectionServicePatches.cs b/XtraPlzNoCrashes/Patches/TemplateCollectionServicePatches.cs new file mode 100644 index 00000000..74d619ce --- /dev/null +++ b/XtraPlzNoCrashes/Patches/TemplateCollectionServicePatches.cs @@ -0,0 +1,39 @@ +using System.Reflection.Emit; + +namespace XtraPlzNoCrashes.Patches; + +[HarmonyPatch] +public static class TemplateCollectionServicePatches +{ + [HarmonyTranspiler, HarmonyPatch(typeof(TemplateCollectionService), nameof(TemplateCollectionService.Load))] + public static IEnumerable DistinctLoad(IEnumerable instructions) + { + foreach (var ins in instructions) + { + yield return ins; + if (ins.opcode == OpCodes.Call && ins.operand is MethodInfo mi && mi.Name == nameof(Enumerable.SelectMany)) + { + yield return new CodeInstruction( + OpCodes.Call, + typeof(TemplateCollectionServicePatches) + .Method(nameof(DistinctAssets)) + ); + } + } + } + + static IEnumerable> DistinctAssets(IEnumerable> assetRefs) => + assetRefs.Distinct(BlueprintAssetRefEqualizer.Instance); + + class BlueprintAssetRefEqualizer : IEqualityComparer> + { + + public static readonly BlueprintAssetRefEqualizer Instance = new(); + + public bool Equals(AssetRef x, AssetRef y) => x.Path.ToLowerInvariant().Equals(y.Path.ToLowerInvariant()); + + public int GetHashCode(AssetRef obj) => obj.Path.ToLowerInvariant().GetHashCode(); + + } + +} \ No newline at end of file diff --git a/XtraPlzNoCrashes/manifest.json b/XtraPlzNoCrashes/manifest.json index 67665c9f..f6efc6fd 100644 --- a/XtraPlzNoCrashes/manifest.json +++ b/XtraPlzNoCrashes/manifest.json @@ -1,6 +1,6 @@ { "Name": "XtraPlzNoCrashes", - "Version": "10.0.0", + "Version": "10.0.1", "Id": "XtraPlzNoCrashes", "MinimumGameVersion": "1.0.0", "Description": "Support for mods so game constraints don't crash them.",