From 6304019f18948271694bf3131eff8504bb45d826 Mon Sep 17 00:00:00 2001 From: CissiBot Date: Wed, 21 Oct 2026 10:19:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BC=82=E7=94=BB?= =?UTF-8?q?=E5=8D=A1=E6=8B=BC=E8=A3=85=E7=95=8C=E9=9D=A2=E7=9A=84=E7=A9=BA?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HsMod/Patcher.cs | 1 + HsMod/Patches/PatchAssemble.cs | 81 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 HsMod/Patches/PatchAssemble.cs diff --git a/HsMod/Patcher.cs b/HsMod/Patcher.cs index c986182..c684f23 100644 --- a/HsMod/Patcher.cs +++ b/HsMod/Patcher.cs @@ -209,6 +209,7 @@ public static void PatchAll() LoadPatch(typeof(Patcher.PatchIGMMessage)); LoadPatch(typeof(Patcher.PatchMercenaries)); LoadPatch(typeof(Patcher.PatchHearthstone)); + LoadPatch(typeof(Patcher.PatchAssemble)); LoadPatch(typeof(Patcher.PatchLogArchive)); LoadPatch(typeof(Patcher.PatchBattlegrounds)); LoadPatch(typeof(Patcher.PatchBgsUnlockCollection)); diff --git a/HsMod/Patches/PatchAssemble.cs b/HsMod/Patches/PatchAssemble.cs new file mode 100644 index 0000000..798eeb1 --- /dev/null +++ b/HsMod/Patches/PatchAssemble.cs @@ -0,0 +1,81 @@ +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; +using UnityEngine; + +namespace HsMod +{ + public partial class Patcher + { + public class PatchAssemble + { + private static readonly FieldInfo rarityGemMesh = AccessTools.Field(typeof(Actor), nameof(Actor.m_rarityGemMesh)); + private static readonly FieldInfo rarityFrameMesh = AccessTools.Field(typeof(Actor), nameof(Actor.m_rarityFrameMesh)); + private static readonly MethodInfo setRendererEnabled = AccessTools.PropertySetter(typeof(Renderer), nameof(Renderer.enabled)); + private static readonly MethodInfo setRarityMeshEnabled = AccessTools.Method(typeof(PatchAssemble), nameof(SetRarityMeshEnabled)); + + [HarmonyPrepare] + public static bool Prepare() + { + // 旧版游戏没有拼装界面;没有可用目标时不能交给 Harmony 处理空列表。 + return TargetMethods().Any(); + } + + [HarmonyTargetMethods] + public static IEnumerable TargetMethods() + { + Type assembleUIManager = typeof(Actor).Assembly.GetType("AssembleUIManager"); + if (assembleUIManager == null) + yield break; + + foreach (string methodName in new[] { "OnShowChoices", "ToggleAssembleUIDisplay" }) + { + MethodInfo method = AccessTools.DeclaredMethod(assembleUIManager, methodName); + if (method != null) + yield return method; + } + } + + [HarmonyTranspiler] + public static IEnumerable Transpiler(IEnumerable instructions) + { + List result = new List(instructions); + for (int i = 0; i + 3 < result.Count; i++) + { + if (result[i].opcode != OpCodes.Ldfld || + (!Equals(result[i].operand, rarityGemMesh) && !Equals(result[i].operand, rarityFrameMesh))) + continue; + + MethodInfo getComponent = result[i + 1].operand as MethodInfo; + if (result[i + 1].opcode != OpCodes.Callvirt || getComponent == null || + getComponent.DeclaringType != typeof(GameObject) || getComponent.Name != nameof(GameObject.GetComponent) || + !getComponent.IsGenericMethod || getComponent.GetGenericArguments()[0] != typeof(Renderer) || + result[i + 2].opcode != OpCodes.Ldc_I4_0 || + result[i + 3].opcode != OpCodes.Callvirt || !Equals(result[i + 3].operand, setRendererEnabled)) + continue; + + // 原地替换以保留跳转标签与异常块,仅保护拼装界面的稀有度装饰。 + result[i + 1].opcode = OpCodes.Nop; + result[i + 1].operand = null; + result[i + 3].opcode = OpCodes.Call; + result[i + 3].operand = setRarityMeshEnabled; + } + return result; + } + + private static void SetRarityMeshEnabled(GameObject mesh, bool enabled) + { + // 异画卡的宝石与边框可以独立缺省,不能由宝石存在推断边框存在(#334)。 + if (mesh == null) + return; + + Renderer renderer = mesh.GetComponent(); + if (renderer != null) + renderer.enabled = enabled; + } + } + } +}