From 1d45158d2e850b439b6879d58aa8b243d49c6fc1 Mon Sep 17 00:00:00 2001 From: kmyuhkyuk <72241714+kmyuhkyuk@users.noreply.github.com> Date: Fri, 13 Mar 2026 20:18:39 +0800 Subject: [PATCH] Fixed error from Treasure Room on chose Relic with more than 4 players --- .../NTreasureRoomRelicCollectionPatch.cs | 67 +++++++++++++++++++ .../SlayTheSpire2.LAN.Multiplayer.csproj | 8 +-- 2 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 SlayTheSpire2.LAN.Multiplayer/Patchs/NTreasureRoomRelicCollectionPatch.cs diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/NTreasureRoomRelicCollectionPatch.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/NTreasureRoomRelicCollectionPatch.cs new file mode 100644 index 0000000..f8c97d8 --- /dev/null +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/NTreasureRoomRelicCollectionPatch.cs @@ -0,0 +1,67 @@ +using Godot; +using HarmonyLib; +using MegaCrit.Sts2.Core.Nodes.Screens.TreasureRoomRelic; +using MegaCrit.Sts2.Core.Runs; + +// ReSharper disable UnusedMember.Global +// ReSharper disable UnusedType.Global + +namespace SlayTheSpire2.LAN.Multiplayer.Patchs +{ + [HarmonyPatch(typeof(NTreasureRoomRelicCollection), "_Ready")] + internal class NTreasureRoomRelicCollectionPatch + { + private static void Prefix(NTreasureRoomRelicCollection __instance) + { + var runState = Traverse.Create(RunManager.Instance).Property("State").GetValue(); + + if (runState is { Players.Count: > 4 }) + { + var container = __instance.GetNode("Container"); + var lastMultiplayerRelicHolder = container.GetNode("MultiplayerRelicHolder4"); + + for (var i = 4; i < runState.Players.Count; i++) + { + lastMultiplayerRelicHolder = lastMultiplayerRelicHolder.Duplicate(); + container.AddChild(lastMultiplayerRelicHolder); + + if (lastMultiplayerRelicHolder is NTreasureRoomRelicHolder nTreasureRoomRelicHolder) + { + nTreasureRoomRelicHolder.Name = $"MultiplayerRelicHolder{i + 1}"; + } + } + } + } + + private static void Postfix(List ____multiplayerHolders) + { + if (____multiplayerHolders.Count > 4) + { + var more16People = ____multiplayerHolders.Count > 16; + + var position = new Vector2(more16People ? 30 : 62, 110); + + for (var i = 0; i < ____multiplayerHolders.Count; i++) + { + if (i > 0) + { + if (more16People) + { + position = i % 6 == 0 + ? new Vector2(30, position.Y + 140) + : new Vector2(position.X + 140, position.Y); + } + else + { + position = i % 4 == 0 + ? new Vector2(62, position.Y + 140) + : new Vector2(position.X + 240, position.Y); + } + } + + ____multiplayerHolders[i].Position = position; + } + } + } + } +} \ No newline at end of file diff --git a/SlayTheSpire2.LAN.Multiplayer/SlayTheSpire2.LAN.Multiplayer.csproj b/SlayTheSpire2.LAN.Multiplayer/SlayTheSpire2.LAN.Multiplayer.csproj index e1be5ae..f796386 100644 --- a/SlayTheSpire2.LAN.Multiplayer/SlayTheSpire2.LAN.Multiplayer.csproj +++ b/SlayTheSpire2.LAN.Multiplayer/SlayTheSpire2.LAN.Multiplayer.csproj @@ -10,16 +10,16 @@ - V:\Slay.the.Spire.2\game\data_sts2_windows_x86_64\0Harmony.dll + V:\Slay.the.Spire.2\data_sts2_windows_x86_64\0Harmony.dll - V:\Slay.the.Spire.2\game\data_sts2_windows_x86_64\GodotSharp.dll + V:\Slay.the.Spire.2\data_sts2_windows_x86_64\GodotSharp.dll - V:\Slay.the.Spire.2\game\data_sts2_windows_x86_64\Steamworks.NET.dll + V:\Slay.the.Spire.2\data_sts2_windows_x86_64\Steamworks.NET.dll - V:\Slay.the.Spire.2\game\data_sts2_windows_x86_64\sts2.dll + V:\Slay.the.Spire.2\data_sts2_windows_x86_64\sts2.dll