Decompiled source of NightmareClan v0.4.1

plugins/NightmareClan.Plugin.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using NightmareClan.Plugin.Common;
using ShinyShoe;
using TrainworksReloaded.Base.Prefab;
using TrainworksReloaded.Core;
using TrainworksReloaded.Core.Extensions;
using TrainworksReloaded.Core.Interfaces;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NightmareClan.Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.1.0")]
[assembly: AssemblyInformationalVersion("0.4.1")]
[assembly: AssemblyProduct("NightmareClan.Plugin")]
[assembly: AssemblyTitle("NightmareClan.Plugin")]
[assembly: AssemblyVersion("0.4.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NightmareClan.Plugin
{
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NightmareMods.NightmareClan";

		public const string PLUGIN_NAME = "NightmareClan";

		public const string PLUGIN_VERSION = "0.4.1";
	}
	[BepInPlugin("NightmareMods.NightmareClan", "NightmareClan", "0.4.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal const string TrainworksGuid = "TrainworksReloaded.Plugin";

		internal static ManualLogSource Logger = new ManualLogSource("NightmareMods.NightmareClan");

		public void Awake()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			try
			{
				Railhead.GetBuilder().Configure("NightmareMods.NightmareClan", (Action<IConfigurationBuilder>)delegate(IConfigurationBuilder c)
				{
					ConfigurationExtensions.AddMergedJsonFile(c, new List<string>(18)
					{
						"json/global.json", "json/clan/clan.json", "json/clan/clan_banner.json", "json/clan/clan_card_frame.json", "json/clan/clan_subtypes.json", "json/champions/dreamlord.json", "json/champions/dreamweaver.json", "json/spells/starter.json", "json/spells/common.json", "json/spells/uncommon.json",
						"json/spells/rare.json", "json/units/banner_units.json", "json/units/draft_units.json", "json/equipment/models.json", "json/rooms/rooms.json", "json/curse/bells.json", "json/enhancers/phantom_stone.json", "json/relics/artifacts.json"
					});
				});
				Logger.LogInfo((object)"NightmareClan v0.4.1 数据已注册");
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"数据注册失败,梦魇氏族不会出现在游戏里:{arg}");
			}
			try
			{
				Harmony val = new Harmony("NightmareMods.NightmareClan");
				val.PatchAll(Assembly.GetExecutingAssembly());
				int num = 0;
				foreach (MethodBase patchedMethod in val.GetPatchedMethods())
				{
					num++;
					string name = patchedMethod.Name;
					switch (name)
					{
					case "FocusCardInternal":
					case "UnFocusCardInternal":
					case "PlayAnyCard":
						Logger.LogInfo((object)("[PatchCheck] 已装 " + patchedMethod.DeclaringType?.Name + "." + name));
						break;
					}
				}
				Logger.LogInfo((object)$"[PatchCheck] 共 {num} 个方法被 patch");
			}
			catch (Exception arg2)
			{
				Logger.LogError((object)$"Harmony 补丁应用失败,部分功能会缺失:{arg2}");
			}
		}
	}
}
namespace NightmareClan.Plugin.Patches
{
	[HarmonyPatch(typeof(GameObjectCardArtDecorator), "Setup")]
	internal static class CardArtFillSlotPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(GameObjectCardArtDecorator), "Setup", "[CardArt]", "卡面槽位垫底关闭(卡面上缘可能露白)");
		}

		[HarmonyPostfix]
		private static void Postfix(IDefinition<GameObject> definition)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)definition?.Data == (Object)null)
				{
					return;
				}
				Transform val = definition.Data.transform.Find("CardSprite");
				Image val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Image>() : null);
				if (!((Object)(object)val2 == (Object)null) && val2.preserveAspect)
				{
					Transform transform = definition.Data.transform;
					if (!((Object)(object)transform.Find("CardArtBacking") != (Object)null))
					{
						GameObject val3 = new GameObject("CardArtBacking");
						val3.transform.SetParent(transform, false);
						val3.layer = 5;
						RectTransform obj = val3.AddComponent<RectTransform>();
						obj.anchorMin = Vector2.zero;
						obj.anchorMax = Vector2.one;
						obj.offsetMin = Vector2.zero;
						obj.offsetMax = Vector2.zero;
						Image obj2 = val3.AddComponent<Image>();
						((Graphic)obj2).color = Color.black;
						((Graphic)obj2).raycastTarget = false;
						val3.transform.SetAsFirstSibling();
					}
				}
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[CardArt] 槽位垫底失败:{arg}");
			}
		}
	}
	public class CardFxAnimator : MonoBehaviour
	{
		private sealed class LiveLayer
		{
			public RawImage? Img;

			public FxLayerSpec Spec = new FxLayerSpec();

			public float BaseAlpha;

			public Vector2 BasePos;
		}

		private readonly List<LiveLayer> _layers = new List<LiveLayer>();

		private static bool _startupLogged;

		private float _nextRebindAt;

		private void Awake()
		{
			Rebind();
		}

		private void OnEnable()
		{
			if (_layers.Count == 0)
			{
				Rebind();
			}
		}

		public void Rebind()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			_layers.Clear();
			CardFxKind? cardFxKind = null;
			foreach (Transform item in ((Component)this).transform)
			{
				Transform val = item;
				if (!((Object)val).name.StartsWith("NFx_", StringComparison.Ordinal))
				{
					continue;
				}
				RawImage component = ((Component)val).GetComponent<RawImage>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				string[] array = ((Object)val).name.Split('_');
				if (array.Length >= 3 && int.TryParse(array[2], out var result))
				{
					if (!cardFxKind.HasValue)
					{
						cardFxKind = (Enum.TryParse<CardFxKind>(array[1], out var result2) ? result2 : CardFxKind.Mist);
					}
					if (CardFxPatch.Variants.TryGetValue(cardFxKind.Value, out FxLayerSpec[] value) && result >= 0 && result < value.Length)
					{
						_layers.Add(new LiveLayer
						{
							Img = component,
							Spec = value[result],
							BaseAlpha = ((Graphic)component).color.a,
							BasePos = ((Graphic)component).rectTransform.anchoredPosition
						});
					}
				}
			}
		}

		private static float Wave(FxLayerSpec s, float now)
		{
			float num = now * s.PulseSpeed + s.PulsePhase;
			return s.PulseShape switch
			{
				1 => Mathf.Pow(0.5f + 0.5f * Mathf.Sin(num), 4f) * 2f - 1f, 
				2 => Mathf.PerlinNoise(num, 0.37f) * 2f - 1f, 
				_ => Mathf.Sin(num), 
			};
		}

		private void Update()
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			if (_layers.Count == 0)
			{
				if (Time.unscaledTime < _nextRebindAt)
				{
					return;
				}
				_nextRebindAt = Time.unscaledTime + 1f;
				Rebind();
				if (_layers.Count == 0)
				{
					return;
				}
			}
			float unscaledDeltaTime = Time.unscaledDeltaTime;
			float unscaledTime = Time.unscaledTime;
			for (int i = 0; i < _layers.Count; i++)
			{
				LiveLayer liveLayer = _layers[i];
				RawImage img = liveLayer.Img;
				if (!((Object)(object)img == (Object)null))
				{
					FxLayerSpec spec = liveLayer.Spec;
					if (spec.Speed.x != 0f || spec.Speed.y != 0f)
					{
						Rect uvRect = img.uvRect;
						((Rect)(ref uvRect)).x = Mathf.Repeat(((Rect)(ref uvRect)).x + spec.Speed.x * unscaledDeltaTime, 1f);
						((Rect)(ref uvRect)).y = Mathf.Repeat(((Rect)(ref uvRect)).y + spec.Speed.y * unscaledDeltaTime, 1f);
						img.uvRect = uvRect;
					}
					if (spec.PulseAmp > 0f)
					{
						Color color = ((Graphic)img).color;
						color.a = liveLayer.BaseAlpha * (1f + spec.PulseAmp * Wave(spec, unscaledTime));
						((Graphic)img).color = color;
					}
					if (spec.JitterAmp > 0f)
					{
						float num = 0.62f * Mathf.Sin(unscaledTime * spec.JitterSpeed) + 0.38f * Mathf.Sin(unscaledTime * spec.JitterSpeed * 2.31f + 1.7f);
						float num2 = 0.58f * Mathf.Cos(unscaledTime * spec.JitterSpeed * 1.43f) + 0.42f * Mathf.Sin(unscaledTime * spec.JitterSpeed * 0.77f + 3.1f);
						((Graphic)img).rectTransform.anchoredPosition = liveLayer.BasePos + new Vector2(num, num2) * spec.JitterAmp;
					}
				}
			}
			if (!_startupLogged)
			{
				_startupLogged = true;
				ManualLogSource logger = Plugin.Logger;
				string text = _layers.Count.ToString();
				Transform parent = ((Component)this).transform.parent;
				object obj;
				if (parent == null)
				{
					obj = null;
				}
				else
				{
					Transform parent2 = parent.parent;
					obj = ((parent2 != null) ? ((Object)parent2).name : null);
				}
				logger.LogInfo((object)("[CardFx] 动效已启动 layers=" + text + " on " + (string?)obj));
			}
		}
	}
	[HarmonyPatch(typeof(GameObjectCardArtDecorator), "Setup")]
	internal static class CardFxPatch
	{
		private const string CardArtPrefix = "CardArt_NightmareMods.NightmareClan_";

		internal const string LayerPrefix = "NFx_";

		private static readonly Dictionary<string, Texture2D?> Textures = new Dictionary<string, Texture2D>();

		private static Material? _additiveMaterial;

		private static bool _additiveLookupDone;

		private static readonly CardFxKind[] FallbackPool = new CardFxKind[11]
		{
			CardFxKind.Mist,
			CardFxKind.Spark,
			CardFxKind.Bloom,
			CardFxKind.Tremor,
			CardFxKind.Surge,
			CardFxKind.Ember,
			CardFxKind.SoulRise,
			CardFxKind.AshFall,
			CardFxKind.Swirl,
			CardFxKind.Heartbeat,
			CardFxKind.Glitter
		};

		internal static Dictionary<CardFxKind, FxLayerSpec[]> Variants => CardFxVariants.Table;

		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(GameObjectCardArtDecorator), "Setup", "[CardFx]", "卡面动效关闭");
		}

		[HarmonyPostfix]
		private static void Postfix(IDefinition<GameObject> definition)
		{
			try
			{
				GameObject val = definition?.Data;
				if ((Object)(object)val == (Object)null || !((Object)val).name.StartsWith("CardArt_NightmareMods.NightmareClan_", StringComparison.Ordinal))
				{
					return;
				}
				Transform val2 = val.transform.Find("CardSprite");
				Image val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<Image>() : null);
				if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || HasFxChild(val2))
				{
					return;
				}
				string text = ((Object)val).name.Substring("CardArt_NightmareMods.NightmareClan_".Length);
				CardFxKind value;
				CardFxKind cardFxKind = (CardFxTable.Map.TryGetValue(text, out value) ? value : FallbackKind(text));
				LoadTextures();
				FxLayerSpec[] array = Variants[cardFxKind];
				int num = 0;
				for (int i = 0; i < array.Length; i++)
				{
					FxLayerSpec fxLayerSpec = array[i];
					Texture2D value2;
					Texture2D val4 = (Textures.TryGetValue(fxLayerSpec.Tex, out value2) ? value2 : null);
					if (!((Object)(object)val4 == (Object)null) && (Object)(object)AddLayer(val2, cardFxKind, i, val4, fxLayerSpec) != (Object)null)
					{
						num++;
					}
				}
				if (num != 0)
				{
					((Component)val2).gameObject.AddComponent<CardFxAnimator>().Rebind();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[CardFx] 挂载失败: " + ex.Message));
			}
		}

		private static CardFxKind FallbackKind(string id)
		{
			int num = 0;
			foreach (char c in id)
			{
				num = num * 31 + c;
			}
			CardFxKind[] fallbackPool = FallbackPool;
			return fallbackPool[(num & 0x7FFFFFFF) % fallbackPool.Length];
		}

		private static bool HasFxChild(Transform parent)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in parent)
			{
				if (((Object)item).name.StartsWith("NFx_", StringComparison.Ordinal))
				{
					return true;
				}
			}
			return false;
		}

		private static RawImage? AddLayer(Transform parent, CardFxKind kind, int index, Texture2D tex, FxLayerSpec spec)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("NFx_" + kind.ToString() + "_" + index, new Type[2]
			{
				typeof(RectTransform),
				typeof(RawImage)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = Vector2.zero;
			RawImage component2 = val.GetComponent<RawImage>();
			component2.texture = (Texture)(object)tex;
			((Graphic)component2).raycastTarget = false;
			((Graphic)component2).color = new Color(spec.Tint.r, spec.Tint.g, spec.Tint.b, spec.Alpha);
			component2.uvRect = new Rect(0f, 0f, spec.Zoom, spec.Zoom);
			if (spec.Additive)
			{
				Material val2 = AdditiveMaterial();
				if ((Object)(object)val2 != (Object)null)
				{
					((Graphic)component2).material = val2;
				}
			}
			val.transform.SetAsLastSibling();
			return component2;
		}

		private static Material? AdditiveMaterial()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (_additiveLookupDone)
			{
				return _additiveMaterial;
			}
			_additiveLookupDone = true;
			Shader val = Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Particles/Additive");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"[CardFx] 找不到加色 shader,退回普通混合");
				return null;
			}
			_additiveMaterial = new Material(val)
			{
				name = "NFxAdditive"
			};
			if (_additiveMaterial.HasProperty("_TintColor"))
			{
				_additiveMaterial.SetColor("_TintColor", Color.white);
			}
			return _additiveMaterial;
		}

		private static void LoadTextures()
		{
			if (Textures.Count > 0)
			{
				return;
			}
			Textures["fog"] = FxTexture.Load("FX_NightmareFog.png", "NFxFog", "[CardFx]", repeat: true);
			Textures["glow"] = FxTexture.Load("FX_NightmareGlow.png", "NFxGlow", "[CardFx]", repeat: true);
			Textures["spark"] = FxTexture.Load("FX_NightmareSpark.png", "NFxSpark", "[CardFx]", repeat: true);
			int num = 0;
			foreach (KeyValuePair<string, Texture2D> texture in Textures)
			{
				if ((Object)(object)texture.Value != (Object)null)
				{
					num++;
				}
			}
			Plugin.Logger.LogInfo((object)("[CardFx] 贴图加载 " + num + "/3"));
		}
	}
	internal static class CardFxTable
	{
		internal static readonly Dictionary<string, CardFxKind> Map = new Dictionary<string, CardFxKind>
		{
			{
				"ArtAbilityCard",
				CardFxKind.Bloom
			},
			{
				"ArtCardChain",
				CardFxKind.Tremor
			},
			{
				"ArtCardDeathDream",
				CardFxKind.Bloom
			},
			{
				"ArtCardDeathModel",
				CardFxKind.Glitter
			},
			{
				"ArtCardDespairBell",
				CardFxKind.AshFall
			},
			{
				"ArtCardDevilPower",
				CardFxKind.Ember
			},
			{
				"ArtCardDevilRealm",
				CardFxKind.Bloom
			},
			{
				"ArtCardDevilVoice",
				CardFxKind.Bloom
			},
			{
				"ArtCardDreamBook",
				CardFxKind.Glitter
			},
			{
				"ArtCardDreamFigure",
				CardFxKind.Swirl
			},
			{
				"ArtCardDreamMachine",
				CardFxKind.Heartbeat
			},
			{
				"ArtCardDreamMonster",
				CardFxKind.SoulRise
			},
			{
				"ArtCardDreamShatterer",
				CardFxKind.Heartbeat
			},
			{
				"ArtCardDreamSpike",
				CardFxKind.Glitter
			},
			{
				"ArtCardDreamSpirit",
				CardFxKind.Ember
			},
			{
				"ArtCardDreamSpreader",
				CardFxKind.Swirl
			},
			{
				"ArtCardDreamWisp",
				CardFxKind.Mist
			},
			{
				"ArtCardDreamWraith",
				CardFxKind.SoulRise
			},
			{
				"ArtCardDreamZealot",
				CardFxKind.Ember
			},
			{
				"ArtCardEchoModel",
				CardFxKind.Glitter
			},
			{
				"ArtCardEnterDream",
				CardFxKind.Bloom
			},
			{
				"ArtCardEscape",
				CardFxKind.Mist
			},
			{
				"ArtCardExplore",
				CardFxKind.Mist
			},
			{
				"ArtCardFervorModel",
				CardFxKind.Swirl
			},
			{
				"ArtCardGhostHaunt",
				CardFxKind.SoulRise
			},
			{
				"ArtCardGhostKill",
				CardFxKind.AshFall
			},
			{
				"ArtCardGhostSummon",
				CardFxKind.SoulRise
			},
			{
				"ArtCardGrudge",
				CardFxKind.SoulRise
			},
			{
				"ArtCardGuardianDream",
				CardFxKind.Bloom
			},
			{
				"ArtCardIronWall",
				CardFxKind.Tremor
			},
			{
				"ArtCardLastStrike",
				CardFxKind.Tremor
			},
			{
				"ArtCardReviveModel",
				CardFxKind.AshFall
			},
			{
				"ArtCardRuinEngine",
				CardFxKind.Heartbeat
			},
			{
				"ArtCardSelfEnd",
				CardFxKind.AshFall
			},
			{
				"ArtCardShatteredDream",
				CardFxKind.Tremor
			},
			{
				"ArtCardSleepPotion",
				CardFxKind.AshFall
			},
			{
				"ArtCardSoulCall",
				CardFxKind.SoulRise
			},
			{
				"ArtCardSpeedDream",
				CardFxKind.Swirl
			},
			{
				"ArtCardStartledSoul",
				CardFxKind.SoulRise
			},
			{
				"ArtCardUndying",
				CardFxKind.Swirl
			},
			{
				"ArtCardWander",
				CardFxKind.Bloom
			},
			{
				"ArtCardWillToLive",
				CardFxKind.Mist
			},
			{
				"DreamlordCardArt",
				CardFxKind.Surge
			},
			{
				"DreamweaverCardArt",
				CardFxKind.Surge
			},
			{
				"NightmareAbilityCardArt",
				CardFxKind.Surge
			}
		};
	}
	public enum CardFxKind
	{
		Mist = 0,
		Spark = 1,
		Bloom = 2,
		Tremor = 3,
		Surge = 4,
		Ember = 5,
		SoulRise = 6,
		AshFall = 7,
		Swirl = 9,
		Heartbeat = 10,
		Glitter = 11
	}
	internal sealed class FxLayerSpec
	{
		public string Tex = "fog";

		public float Alpha = 0.3f;

		public Vector2 Speed = Vector2.zero;

		public float Zoom = 1f;

		public Color Tint = Color.white;

		public float PulseAmp;

		public float PulseSpeed = 1f;

		public float PulsePhase;

		public int PulseShape;

		public bool Additive = true;

		public float JitterAmp;

		public float JitterSpeed = 9f;
	}
	internal static class CardFxVariants
	{
		internal static readonly Dictionary<CardFxKind, FxLayerSpec[]> Table = new Dictionary<CardFxKind, FxLayerSpec[]>
		{
			[CardFxKind.Mist] = new FxLayerSpec[3]
			{
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.019125f,
					Speed = new Vector2(0.045f, 0.014f)
				},
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.01125f,
					Speed = new Vector2(-0.022f, -0.009f),
					Tint = new Color(0.8f, 1f, 1f)
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.03825f,
					PulseAmp = 0.55f,
					PulseSpeed = 1f
				}
			},
			[CardFxKind.Spark] = new FxLayerSpec[3]
			{
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 0.06975f,
					Speed = new Vector2(0.012f, -0.085f),
					Zoom = 0.62f,
					PulseAmp = 0.18f,
					PulseSpeed = 0.9f,
					Tint = new Color(0.66f, 1f, 0.94f)
				},
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 0.045f,
					Speed = new Vector2(-0.016f, -0.048f),
					Zoom = 0.95f,
					PulseAmp = 0.22f,
					PulseSpeed = 0.63f,
					PulsePhase = 1.9f,
					Tint = new Color(0.78f, 1f, 0.96f)
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.02925f,
					PulseAmp = 0.45f,
					PulseSpeed = 0.8f
				}
			},
			[CardFxKind.Bloom] = new FxLayerSpec[3]
			{
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 9f / 160f,
					PulseAmp = 0.72f,
					PulseSpeed = 1.15f,
					Zoom = 0.72f
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.0375f,
					PulseAmp = 0.55f,
					PulseSpeed = 0.82f,
					PulsePhase = 2.4f,
					Tint = new Color(0.8f, 1f, 1f)
				},
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 3f / 160f,
					Speed = new Vector2(0.03f, 0.01f)
				}
			},
			[CardFxKind.Tremor] = new FxLayerSpec[2]
			{
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.031875f,
					Speed = new Vector2(0.01f, 0.003f),
					JitterAmp = 2.6f,
					JitterSpeed = 13f
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.04875f,
					PulseAmp = 0.45f,
					PulseSpeed = 2.4f,
					JitterAmp = 2f,
					JitterSpeed = 11.5f,
					Tint = new Color(0.94f, 0.82f, 1f)
				}
			},
			[CardFxKind.Surge] = new FxLayerSpec[3]
			{
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 9f / 160f,
					Speed = new Vector2(0.01f, -0.072f),
					Zoom = 0.6f,
					PulseAmp = 0.2f,
					PulseSpeed = 1.05f,
					Tint = new Color(0.72f, 1f, 0.95f)
				},
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.0135f,
					Speed = new Vector2(0.038f, 0.011f)
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.03825f,
					PulseAmp = 0.62f,
					PulseSpeed = 1f
				}
			},
			[CardFxKind.Ember] = new FxLayerSpec[3]
			{
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 0.0675f,
					Speed = new Vector2(0.008f, -0.115f),
					Zoom = 0.55f,
					PulseAmp = 0.3f,
					PulseSpeed = 1.7f,
					Tint = new Color(1f, 0.62f, 0.28f)
				},
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 0.03825f,
					Speed = new Vector2(-0.013f, -0.058f),
					Zoom = 0.88f,
					PulseAmp = 0.28f,
					PulseSpeed = 1.1f,
					PulsePhase = 2.1f,
					Tint = new Color(1f, 0.44f, 0.18f)
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.03375f,
					PulseAmp = 0.5f,
					PulseSpeed = 1.4f,
					Tint = new Color(1f, 0.68f, 0.42f)
				}
			},
			[CardFxKind.SoulRise] = new FxLayerSpec[3]
			{
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 0.06075f,
					Speed = new Vector2(0.01f, -0.066f),
					Zoom = 0.58f,
					PulseAmp = 0.26f,
					PulseSpeed = 0.75f,
					Tint = new Color(0.6f, 0.98f, 1f)
				},
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.014625f,
					Speed = new Vector2(0.03f, 0.01f)
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.027f,
					PulseAmp = 0.4f,
					PulseSpeed = 0.85f,
					Tint = new Color(0.72f, 1f, 1f)
				}
			},
			[CardFxKind.AshFall] = new FxLayerSpec[3]
			{
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 0.05175f,
					Speed = new Vector2(0.012f, 0.058f),
					Zoom = 0.78f,
					PulseAmp = 0.24f,
					PulseSpeed = 0.5f,
					Tint = new Color(0.7f, 0.76f, 0.86f)
				},
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.018f,
					Speed = new Vector2(0.014f, -0.008f),
					Tint = new Color(0.72f, 0.82f, 1f)
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.018f,
					PulseAmp = 0.3f,
					PulseSpeed = 0.5f,
					Tint = new Color(0.6f, 0.7f, 0.92f)
				}
			},
			[CardFxKind.Swirl] = new FxLayerSpec[4]
			{
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.0225f,
					Speed = new Vector2(0.055f, -0.03f),
					Zoom = 0.78f
				},
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.01575f,
					Speed = new Vector2(-0.048f, -0.034f),
					Zoom = 0.92f,
					Tint = new Color(0.8f, 0.92f, 1f)
				},
				new FxLayerSpec
				{
					Tex = "fog",
					Alpha = 0.01125f,
					Speed = new Vector2(0.02f, 0.048f),
					Tint = new Color(0.88f, 0.86f, 1f)
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.02475f,
					PulseAmp = 0.35f,
					PulseSpeed = 0.7f
				}
			},
			[CardFxKind.Heartbeat] = new FxLayerSpec[2]
			{
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.04275f,
					PulseAmp = 0.85f,
					PulseSpeed = 5.2f,
					PulseShape = 1
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.027f,
					PulseAmp = 0.7f,
					PulseSpeed = 5.2f,
					PulsePhase = 0.42f,
					PulseShape = 1,
					Tint = new Color(0.86f, 0.92f, 1f)
				}
			},
			[CardFxKind.Glitter] = new FxLayerSpec[3]
			{
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 0.06525f,
					Speed = new Vector2(0.006f, -0.036f),
					Zoom = 0.66f,
					PulseAmp = 0.85f,
					PulseSpeed = 2.3f,
					PulseShape = 2,
					Tint = new Color(1f, 0.94f, 0.74f)
				},
				new FxLayerSpec
				{
					Tex = "spark",
					Alpha = 0.03825f,
					Speed = new Vector2(-0.009f, -0.024f),
					Zoom = 1f,
					PulseAmp = 0.8f,
					PulseSpeed = 1.4f,
					PulseShape = 2,
					PulsePhase = 3.7f,
					Tint = new Color(0.86f, 1f, 1f)
				},
				new FxLayerSpec
				{
					Tex = "glow",
					Alpha = 0.02475f,
					PulseAmp = 0.4f,
					PulseSpeed = 0.6f,
					Tint = new Color(1f, 0.92f, 0.72f)
				}
			}
		};
	}
	internal static class CardIdMatcher
	{
		internal static bool IsTarget(CardState? card, string[] ids)
		{
			if (card == null || ids == null || ids.Length == 0)
			{
				return false;
			}
			if (!Matches(Probe((Func<string>)card.GetAssetName), ids) && !Matches(Probe((Func<string>)card.GetCardDataID), ids))
			{
				return Matches(Probe((Func<string>)card.GetTitleKey), ids);
			}
			return true;
		}

		private static bool Matches(string value, string[] ids)
		{
			if (string.IsNullOrEmpty(value))
			{
				return false;
			}
			for (int i = 0; i < ids.Length; i++)
			{
				if (value.IndexOf(ids[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		private static string Probe(Func<string> getter)
		{
			try
			{
				return getter() ?? string.Empty;
			}
			catch (Exception)
			{
				return string.Empty;
			}
		}
	}
	[HarmonyPatch(typeof(CardTextReplacements), "GetCardTextReplacementIntegerValue")]
	internal static class CardTextTriggerDoublingPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(CardTextReplacements), "GetCardTextReplacementIntegerValue", "[CardText]", "触发次数翻倍不再体现在卡面数值上");
		}

		[HarmonyPostfix]
		private static void Postfix(ILocalizationEffectPower localizationEffectPower, RelicManager relicManager, TranslationToken token, ref int? __result, ref bool powerModified)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!__result.HasValue || (Object)(object)relicManager == (Object)null)
				{
					return;
				}
				CharacterTriggerData val = (CharacterTriggerData)(object)((localizationEffectPower is CharacterTriggerData) ? localizationEffectPower : null);
				if (val == null)
				{
					return;
				}
				TranslationTokenCardText val2 = (TranslationTokenCardText)(object)((token is TranslationTokenCardText) ? token : null);
				if (val2 != null && val2.elements != null && val2.elements.Count != 0 && (int)val2.elements[0].ElementType == 0)
				{
					int triggerFireCountModifier = relicManager.GetTriggerFireCountModifier(val.GetTrigger());
					if (triggerFireCountModifier > 0)
					{
						__result = __result.Value * (1 + triggerFireCountModifier);
						powerModified = true;
					}
				}
			}
			catch
			{
			}
		}
	}
	internal static class CompendiumChampClanColumnHelper
	{
		private static readonly FieldInfo? ClassesRootField = AccessTools.Field(typeof(CompendiumSectionChampUpgrades), "classesOptionRoot");

		private static readonly FieldInfo? CrewRootField = AccessTools.Field(typeof(CompendiumSectionChampUpgrades), "crewClassesOptionRoot");

		internal static LayoutGroup? GetClassesRoot(CompendiumSectionChampUpgrades section)
		{
			try
			{
				object? obj = ClassesRootField?.GetValue(section);
				return (LayoutGroup?)((obj is LayoutGroup) ? obj : null);
			}
			catch
			{
				return null;
			}
		}

		internal static LayoutGroup? GetCrewRoot(CompendiumSectionChampUpgrades section)
		{
			try
			{
				object? obj = CrewRootField?.GetValue(section);
				return (LayoutGroup?)((obj is LayoutGroup) ? obj : null);
			}
			catch
			{
				return null;
			}
		}

		private static ClanOptionUI? FindNightmareItem(Component? root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return null;
			}
			try
			{
				ClanOptionButton[] componentsInChildren = root.GetComponentsInChildren<ClanOptionButton>(true);
				foreach (ClanOptionButton val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && CompendiumClanChecklistHelper.IsNightmare(val.ClassData))
					{
						ClanOptionUI componentInParent = ((Component)val).GetComponentInParent<ClanOptionUI>(true);
						if ((Object)(object)componentInParent != (Object)null)
						{
							return componentInParent;
						}
						return ((Component)val).GetComponent<ClanOptionUI>();
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[ChampClanColumn] 查找梦魇氏族按钮失败:" + ex.Message));
			}
			return null;
		}

		private static bool MoveTo(ClanOptionUI item, LayoutGroup target, string reason)
		{
			try
			{
				if ((Object)(object)item == (Object)null || (Object)(object)target == (Object)null)
				{
					return false;
				}
				if ((Object)(object)((Component)item).transform.parent == (Object)(object)((Component)target).transform)
				{
					return false;
				}
				((Component)item).transform.SetParent(((Component)target).transform, false);
				((Component)item).transform.SetAsLastSibling();
				((Component)item).gameObject.SetActive(true);
				Plugin.Logger.LogInfo((object)("[ChampClanColumn] 梦魇氏族按钮 → " + ((Object)target).name + "(" + reason + ")。"));
				return true;
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[ChampClanColumn] 移动梦魇氏族按钮失败:{arg}");
				return false;
			}
		}

		private static void Rebuild(LayoutGroup? layout)
		{
			try
			{
				if (!((Object)(object)layout == (Object)null))
				{
					Transform transform = ((Component)layout).transform;
					RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
					if ((Object)(object)val != (Object)null)
					{
						LayoutRebuilder.ForceRebuildLayoutImmediate(val);
					}
					Transform parent = ((Component)layout).transform.parent;
					RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
					if ((Object)(object)val2 != (Object)null)
					{
						LayoutRebuilder.ForceRebuildLayoutImmediate(val2);
					}
				}
			}
			catch
			{
			}
		}

		internal static void RestoreToClassesColumn(CompendiumSectionChampUpgrades section)
		{
			LayoutGroup classesRoot = GetClassesRoot(section);
			if (!((Object)(object)classesRoot == (Object)null))
			{
				ClanOptionUI val = FindNightmareItem((Component?)(object)classesRoot);
				if ((Object)(object)val == (Object)null)
				{
					val = FindNightmareItem((Component?)(object)((Component)section).transform);
				}
				if (!((Object)(object)val == (Object)null) && MoveTo(val, classesRoot, "进入前复原"))
				{
					Rebuild(classesRoot);
				}
			}
		}

		internal static void MoveToSecondColumn(CompendiumSectionChampUpgrades section)
		{
			LayoutGroup classesRoot = GetClassesRoot(section);
			LayoutGroup crewRoot = GetCrewRoot(section);
			if ((Object)(object)classesRoot == (Object)null || (Object)(object)crewRoot == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"[ChampClanColumn] 取不到氏族列布局,跳过。");
				return;
			}
			if (!((Component)crewRoot).gameObject.activeSelf)
			{
				Plugin.Logger.LogInfo((object)"[ChampClanColumn] Crew 列未启用,梦魇留在左列。");
				return;
			}
			ClanOptionUI val = FindNightmareItem((Component?)(object)classesRoot);
			if ((Object)(object)val == (Object)null)
			{
				val = FindNightmareItem((Component?)(object)crewRoot);
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"[ChampClanColumn] 找不到梦魇氏族按钮,跳过。");
				return;
			}
			MoveTo(val, crewRoot, "改到第二列");
			Rebuild(classesRoot);
			Rebuild(crewRoot);
			ManualLogSource logger = Plugin.Logger;
			string[] obj = new string[5]
			{
				$"[ChampClanColumn] 左列 {((Component)classesRoot).transform.childCount} 项 / ",
				$"右列 {((Component)crewRoot).transform.childCount} 项,",
				$"梦魇 active={((Component)val).gameObject.activeSelf} ",
				"父节点=",
				null
			};
			Transform parent = ((Component)val).transform.parent;
			obj[4] = ((parent != null) ? ((Object)parent).name : null);
			logger.LogInfo((object)string.Concat(obj));
		}
	}
	[HarmonyPatch(typeof(CompendiumSectionChampUpgrades), "InitializeImpl")]
	internal static class ChampUpgradesClanColumnPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(CompendiumSectionChampUpgrades), "InitializeImpl", "[ChampClanColumn]", "图鉴升级页氏族列排版修正关闭");
		}

		[HarmonyPrefix]
		private static void Prefix(CompendiumSectionChampUpgrades __instance)
		{
			try
			{
				CompendiumChampClanColumnHelper.RestoreToClassesColumn(__instance);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[ChampClanColumn] 进入前处理失败:{arg}");
			}
		}

		[HarmonyPostfix]
		private static void Postfix(CompendiumSectionChampUpgrades __instance)
		{
			try
			{
				CompendiumChampClanColumnHelper.MoveToSecondColumn(__instance);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[ChampClanColumn] 填充后处理失败:{arg}");
			}
		}
	}
	internal static class CompendiumClanChecklistHelper
	{
		private const string NightmareToken = "Nightmare";

		private const string CloneName = "ClanChecklistSection_Nightmare";

		private static readonly FieldInfo? ClassDataField = AccessTools.Field(typeof(ClanChecklistSection), "classData");

		private static readonly FieldInfo? PageSectionsField = AccessTools.Field(typeof(DlcChecklistPage), "clanChecklistSections");

		internal static bool IsNightmare(ClassData? cd)
		{
			if ((Object)(object)cd == (Object)null)
			{
				return false;
			}
			try
			{
				if (((Object)cd).name != null && ((Object)cd).name.IndexOf("Nightmare", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
				string titleKey = cd.GetTitleKey();
				return !string.IsNullOrEmpty(titleKey) && titleKey.IndexOf("Nightmare", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			catch
			{
				return false;
			}
		}

		private static ClassData? GetBoundClass(ClanChecklistSection section)
		{
			if ((Object)(object)section == (Object)null || ClassDataField == null)
			{
				return null;
			}
			try
			{
				object? value = ClassDataField.GetValue(section);
				return (ClassData?)((value is ClassData) ? value : null);
			}
			catch
			{
				return null;
			}
		}

		internal static ClassData? FindNightmareClass(SaveManager saveManager)
		{
			if ((Object)(object)saveManager == (Object)null)
			{
				return null;
			}
			try
			{
				foreach (ClassData classData in saveManager.GetBalanceData().GetClassDatas())
				{
					if (IsNightmare(classData))
					{
						return classData;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("图鉴清单:取氏族数据失败:" + ex.Message));
			}
			return null;
		}

		internal static void HideNightmareAndLog(Component? layout)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)layout == (Object)null)
			{
				return;
			}
			try
			{
				List<ClanChecklistSection> list = new List<ClanChecklistSection>();
				ClanChecklistSection[] componentsInChildren = layout.GetComponentsInChildren<ClanChecklistSection>(true);
				foreach (ClanChecklistSection val in componentsInChildren)
				{
					if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).transform.parent == (Object)(object)layout.transform)
					{
						list.Add(val);
					}
				}
				Transform transform = layout.transform;
				RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				GridLayoutGroup component = layout.GetComponent<GridLayoutGroup>();
				string text = (((Object)(object)component == (Object)null) ? ("布局类型 " + ((object)layout).GetType().Name) : ($"Grid cell={component.cellSize} spacing={component.spacing} " + $"constraint={component.constraint} count={component.constraintCount}"));
				ManualLogSource logger = Plugin.Logger;
				string[] obj = new string[6]
				{
					$"[CompendiumClan] 布局 {((Object)layout).name}:直属块 {list.Count}",
					$"/子项 {layout.transform.childCount},",
					"rect=",
					null,
					null,
					null
				};
				Rect rect;
				object obj2;
				if (!((Object)(object)val2 == (Object)null))
				{
					rect = val2.rect;
					obj2 = ((object)((Rect)(ref rect)).size/*cast due to .constrained prefix*/).ToString();
				}
				else
				{
					obj2 = "?";
				}
				obj[3] = (string)obj2;
				obj[4] = ",";
				obj[5] = text;
				logger.LogInfo((object)string.Concat(obj));
				int num = 0;
				foreach (ClanChecklistSection item in list)
				{
					ClassData boundClass = GetBoundClass(item);
					RectTransform val3 = (RectTransform)((Component)item).transform;
					ManualLogSource logger2 = Plugin.Logger;
					string[] obj3 = new string[7]
					{
						"[CompendiumClan]   · name=",
						((boundClass != null) ? ((Object)boundClass).name : null) ?? "(空)",
						" title=",
						((boundClass != null) ? boundClass.GetTitleKey() : null) ?? "-",
						$" activeSelf={((Component)item).gameObject.activeSelf}",
						$" visible={((Component)item).gameObject.activeInHierarchy}",
						null
					};
					object arg = val3.anchoredPosition;
					rect = val3.rect;
					obj3[6] = $" pos={arg} size={((Rect)(ref rect)).size}";
					logger2.LogInfo((object)string.Concat(obj3));
					if (IsNightmare(boundClass))
					{
						((Component)item).gameObject.SetActive(false);
						num++;
						Plugin.Logger.LogInfo((object)"[CompendiumClan]     已从本页隐藏梦魇氏族块。");
					}
				}
				if (num == 0)
				{
					Plugin.Logger.LogWarning((object)"[CompendiumClan] 本页没找到梦魇块,未做隐藏。");
				}
				else if ((Object)(object)val2 != (Object)null)
				{
					LayoutRebuilder.ForceRebuildLayoutImmediate(val2);
					ManualLogSource logger3 = Plugin.Logger;
					rect = val2.rect;
					logger3.LogInfo((object)$"[CompendiumClan] 隐藏后重排,布局 rect={((Rect)(ref rect)).size}。");
				}
			}
			catch (Exception arg2)
			{
				Plugin.Logger.LogWarning((object)$"[CompendiumClan] 隐藏氏族块失败:{arg2}");
			}
		}

		internal static void AddToDlcPage(DlcChecklistPage page, SaveManager saveManager)
		{
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)page == (Object)null)
			{
				return;
			}
			ClassData val = FindNightmareClass(saveManager);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"[CompendiumClan] 找不到 ClassNightmare,第 2 页不补块。");
				return;
			}
			try
			{
				LayoutGroup val2 = PickLayout(page);
				if ((Object)(object)val2 == (Object)null)
				{
					Plugin.Logger.LogWarning((object)"[CompendiumClan] 第 2 页找不到可用的布局。");
					return;
				}
				List<ClanChecklistSection> list = PageSectionsField?.GetValue(page) as List<ClanChecklistSection>;
				if (list == null)
				{
					list = new List<ClanChecklistSection>();
					PageSectionsField?.SetValue(page, list);
				}
				int num = PurgeStaleClones(val2, list);
				if (num > 0)
				{
					Plugin.Logger.LogInfo((object)$"[CompendiumClan] 第 2 页清掉上次残留的梦魇块 {num} 个。");
				}
				if (HasVisibleNightmare(val2))
				{
					Plugin.Logger.LogInfo((object)"[CompendiumClan] 第 2 页已有可见的梦魇块,跳过补块。");
					return;
				}
				ClanChecklistSection val3 = (ClanChecklistSection)((list.Count > 0) ? ((object)list[0]) : ((object)FindTemplate(val2)));
				if ((Object)(object)val3 == (Object)null)
				{
					Plugin.Logger.LogWarning((object)"[CompendiumClan] 第 2 页找不到模板块。");
					return;
				}
				GameObject val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject, ((Component)val2).transform);
				((Object)val4).name = "ClanChecklistSection_Nightmare";
				val4.SetActive(true);
				ClanChecklistSection component = val4.GetComponent<ClanChecklistSection>();
				if ((Object)(object)component == (Object)null)
				{
					Plugin.Logger.LogWarning((object)"[CompendiumClan] 克隆体缺少 ClanChecklistSection,放弃。");
					Object.DestroyImmediate((Object)(object)val4);
					return;
				}
				TrimStaleVictoryItems(component);
				component.Set(val, saveManager, ((Component)val2).transform.childCount - 1);
				try
				{
					component.ReparentCrewVictoryItems();
				}
				catch
				{
				}
				LogVictoryCounts("梦魇块重建完成", component);
				if (!list.Contains(component))
				{
					list.Add(component);
				}
				Transform transform = ((Component)val2).transform;
				RectTransform val5 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if ((Object)(object)val5 != (Object)null)
				{
					LayoutRebuilder.ForceRebuildLayoutImmediate(val5);
					ManualLogSource logger = Plugin.Logger;
					string name = ((Object)val2).name;
					Rect rect = val5.rect;
					logger.LogInfo((object)($"[CompendiumClan] 已在第 2 页补梦魇块,布局 {name} 尺寸 {((Rect)(ref rect)).size}," + $"块数 {((Component)val2).transform.childCount}"));
				}
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[CompendiumClan] 第 2 页补块失败:{arg}");
			}
		}

		private static int PurgeStaleClones(LayoutGroup layout, List<ClanChecklistSection> sections)
		{
			int num = 0;
			try
			{
				List<ClanChecklistSection> list = new List<ClanChecklistSection>();
				ClanChecklistSection[] componentsInChildren = ((Component)layout).GetComponentsInChildren<ClanChecklistSection>(true);
				foreach (ClanChecklistSection val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).transform.parent != (Object)(object)((Component)layout).transform) && !(((Object)((Component)val).gameObject).name != "ClanChecklistSection_Nightmare") && IsNightmare(GetBoundClass(val)))
					{
						list.Add(val);
					}
				}
				foreach (ClanChecklistSection item in list)
				{
					sections.Remove(item);
					Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
					num++;
				}
				for (int num2 = sections.Count - 1; num2 >= 0; num2--)
				{
					if ((Object)(object)sections[num2] == (Object)null)
					{
						sections.RemoveAt(num2);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[CompendiumClan] 清理残留块失败:" + ex.Message));
			}
			return num;
		}

		private static bool HasVisibleNightmare(LayoutGroup layout)
		{
			ClanChecklistSection[] componentsInChildren = ((Component)layout).GetComponentsInChildren<ClanChecklistSection>(true);
			foreach (ClanChecklistSection val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).transform.parent != (Object)(object)((Component)layout).transform) && ((Component)val).gameObject.activeSelf && IsNightmare(GetBoundClass(val)))
				{
					return true;
				}
			}
			return false;
		}

		internal static void PurgeClonesUnder(Component? root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			try
			{
				List<GameObject> list = new List<GameObject>();
				ClanChecklistSection[] componentsInChildren = root.GetComponentsInChildren<ClanChecklistSection>(true);
				foreach (ClanChecklistSection val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && !(((Object)((Component)val).gameObject).name != "ClanChecklistSection_Nightmare") && IsNightmare(GetBoundClass(val)))
					{
						list.Add(((Component)val).gameObject);
					}
				}
				foreach (GameObject item in list)
				{
					Object.DestroyImmediate((Object)(object)item);
				}
				if (list.Count > 0)
				{
					Plugin.Logger.LogInfo((object)$"[CompendiumClan] 进入前清掉上次补的梦魇块 {list.Count} 个(复原复用池)。");
				}
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[CompendiumClan] 进入前清理失败:{arg}");
			}
		}

		private static LayoutGroup? PickLayout(DlcChecklistPage page)
		{
			object? obj = AccessTools.Field(typeof(DlcChecklistPage), "clanSectionsLayoutAllDlcClans")?.GetValue(page);
			LayoutGroup val = (LayoutGroup)((obj is LayoutGroup) ? obj : null);
			object? obj2 = AccessTools.Field(typeof(DlcChecklistPage), "clanSectionsLayoutStartingDlcClans")?.GetValue(page);
			LayoutGroup val2 = (LayoutGroup)((obj2 is LayoutGroup) ? obj2 : null);
			if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf)
			{
				return val;
			}
			if ((Object)(object)val2 != (Object)null && ((Component)val2).gameObject.activeSelf)
			{
				return val2;
			}
			LayoutGroup val3 = val2 ?? val;
			if ((Object)(object)val3 != (Object)null)
			{
				((Component)val3).gameObject.SetActive(true);
				Plugin.Logger.LogInfo((object)("[CompendiumClan] 第 2 页原本没有氏族,重新启用布局 " + ((Object)val3).name + "。"));
			}
			return val3;
		}

		private static void TrimStaleVictoryItems(ClanChecklistSection clone)
		{
			try
			{
				object? obj = AccessTools.Field(typeof(ClanChecklistSection), "subclanVictoryLayout")?.GetValue(clone);
				LayoutGroup val = (LayoutGroup)((obj is LayoutGroup) ? obj : null);
				object? obj2 = AccessTools.Field(typeof(ClanChecklistSection), "subclanVictoryLayoutCrew")?.GetValue(clone);
				LayoutGroup val2 = (LayoutGroup)((obj2 is LayoutGroup) ? obj2 : null);
				int num = ((!((Object)(object)val == (Object)null)) ? ((Component)val).transform.childCount : 0);
				int num2 = ((!((Object)(object)val2 == (Object)null)) ? ((Component)val2).transform.childCount : 0);
				SubclanVictoryItem val3 = null;
				if ((Object)(object)val != (Object)null)
				{
					val3 = ((Component)val).GetComponentInChildren<SubclanVictoryItem>(true);
				}
				if ((Object)(object)val3 == (Object)null && (Object)(object)val2 != (Object)null)
				{
					val3 = ((Component)val2).GetComponentInChildren<SubclanVictoryItem>(true);
					if ((Object)(object)val3 != (Object)null && (Object)(object)val != (Object)null)
					{
						((Component)val3).transform.SetParent(((Component)val).transform, true);
					}
				}
				if ((Object)(object)val3 == (Object)null)
				{
					Plugin.Logger.LogWarning((object)"[CompendiumClan] 模板块里找不到任何胜利项,无法给 PopulateViewList 留模板。");
					return;
				}
				int num3 = 0;
				SubclanVictoryItem[] componentsInChildren = ((Component)clone).GetComponentsInChildren<SubclanVictoryItem>(true);
				foreach (SubclanVictoryItem val4 in componentsInChildren)
				{
					if (!((Object)(object)val4 == (Object)null) && !((Object)(object)val4 == (Object)(object)val3))
					{
						Object.DestroyImmediate((Object)(object)((Component)val4).gameObject);
						num3++;
					}
				}
				Plugin.Logger.LogInfo((object)($"[CompendiumClan] 克隆体清理:主布局 {num} 项 / Crew 栏 {num2} 项" + $" → 销毁 {num3} 项,保留 1 项当模板。"));
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[CompendiumClan] 清理克隆体胜利项失败:{arg}");
			}
		}

		private static void LogVictoryCounts(string tag, ClanChecklistSection section)
		{
			try
			{
				object? obj = AccessTools.Field(typeof(ClanChecklistSection), "subclanVictoryLayout")?.GetValue(section);
				LayoutGroup val = (LayoutGroup)((obj is LayoutGroup) ? obj : null);
				object? obj2 = AccessTools.Field(typeof(ClanChecklistSection), "subclanVictoryLayoutCrew")?.GetValue(section);
				LayoutGroup val2 = (LayoutGroup)((obj2 is LayoutGroup) ? obj2 : null);
				Plugin.Logger.LogInfo((object)($"[CompendiumClan] {tag}:主布局 {((val != null) ? ((Component)val).transform.childCount : 0)} 项," + $"Crew 栏 {((val2 != null) ? ((Component)val2).transform.childCount : 0)} 项。"));
				SubclanVictoryItem[] componentsInChildren = ((Component)section).GetComponentsInChildren<SubclanVictoryItem>(true);
				foreach (SubclanVictoryItem val3 in componentsInChildren)
				{
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					string text = "-";
					try
					{
						Data data = val3.data;
						object obj3;
						if (data == null)
						{
							obj3 = null;
						}
						else
						{
							ClassData subClassData = data.subClassData;
							obj3 = ((subClassData != null) ? ((Object)subClassData).name : null);
						}
						if (obj3 == null)
						{
							obj3 = "(空)";
						}
						text = (string)obj3;
					}
					catch
					{
						text = "(读取失败)";
					}
					ManualLogSource logger = Plugin.Logger;
					string text2 = $"[CompendiumClan]     · {text} active={((Component)val3).gameObject.activeSelf}";
					Transform parent = ((Component)val3).transform.parent;
					logger.LogInfo((object)(text2 + " parent=" + ((parent != null) ? ((Object)parent).name : null)));
				}
			}
			catch
			{
			}
		}

		private static ClanChecklistSection? FindTemplate(LayoutGroup layout)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			ClanChecklistSection[] componentsInChildren = ((Component)layout).GetComponentsInChildren<ClanChecklistSection>(true);
			if (componentsInChildren.Length != 0)
			{
				return componentsInChildren[0];
			}
			ClanChecklistSection[] array = Resources.FindObjectsOfTypeAll<ClanChecklistSection>();
			foreach (ClanChecklistSection val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Scene scene = ((Component)val).gameObject.scene;
					if (((Scene)(ref scene)).IsValid())
					{
						return val;
					}
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(StandardChecklistPage), "Initialize")]
	internal static class StandardChecklistPageClanPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(StandardChecklistPage), "Initialize", "[CompendiumClan]", "图鉴第 1 页排版修正关闭");
		}

		[HarmonyPostfix]
		private static void Postfix(StandardChecklistPage __instance, SaveManager saveManager)
		{
			try
			{
				object? obj = AccessTools.Field(typeof(StandardChecklistPage), "clanSectionsLayoutStartingClans")?.GetValue(__instance);
				Component val = (Component)((obj is Component) ? obj : null);
				object? obj2 = AccessTools.Field(typeof(StandardChecklistPage), "clanSectionsLayoutAllClans")?.GetValue(__instance);
				Component val2 = (Component)((obj2 is Component) ? obj2 : null);
				if ((Object)(object)val != (Object)null && val.gameObject.activeSelf)
				{
					CompendiumClanChecklistHelper.HideNightmareAndLog(val);
				}
				if ((Object)(object)val2 != (Object)null && val2.gameObject.activeSelf)
				{
					CompendiumClanChecklistHelper.HideNightmareAndLog(val2);
				}
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[CompendiumClan] 第 1 页处理失败:{arg}");
			}
		}
	}
	[HarmonyPatch(typeof(DlcChecklistPage), "Initialize")]
	internal static class DlcChecklistPageClanPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(DlcChecklistPage), "Initialize", "[CompendiumClan]", "图鉴第 2 页补块关闭");
		}

		[HarmonyPrefix]
		private static void Prefix(DlcChecklistPage __instance)
		{
			try
			{
				CompendiumClanChecklistHelper.PurgeClonesUnder((Component?)(object)__instance);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[CompendiumClan] 第 2 页进入前处理失败:{arg}");
			}
		}

		[HarmonyPostfix]
		private static void Postfix(DlcChecklistPage __instance, SaveManager saveManager)
		{
			try
			{
				CompendiumClanChecklistHelper.AddToDlcPage(__instance, saveManager);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogWarning((object)$"[CompendiumClan] 第 2 页处理失败:{arg}");
			}
		}
	}
	public sealed class DreamMachineOverlay : MonoBehaviour
	{
		private sealed class Spin
		{
			internal RawImage Img;

			internal RectTransform Rt;

			internal float Speed;

			internal float Base;

			internal float Phase;
		}

		private const string GearAFile = "FX_DreamMachineGearA.png";

		private const string GearBFile = "FX_DreamMachineGearB.png";

		private const string DialFile = "FX_DreamMachineDial.png";

		private const string PlateFile = "FX_DreamMachinePlate.png";

		private const string HourFile = "FX_DreamMachineHandHour.png";

		private const string MinFile = "FX_DreamMachineHandMin.png";

		private const int CanvasOrder = 32000;

		private static DreamMachineOverlay? _inst;

		private static readonly float[,] RingLayout = new float[12, 5]
		{
			{ -0.455f, 0.43f, 0.2f, 14f, 0f },
			{ -0.18f, 0.47f, 0.13f, -22f, 1f },
			{ 0.15f, 0.48f, 0.11f, 30f, 0f },
			{ 0.44f, 0.43f, 0.18f, -11f, 1f },
			{ -0.48f, 0.19f, 0.15f, 18f, 1f },
			{ -0.47f, -0.09f, 0.11f, -26f, 0f },
			{ 0.48f, 0.18f, 0.13f, 21f, 0f },
			{ 0.47f, -0.12f, 0.16f, -15f, 1f },
			{ -0.42f, -0.43f, 0.17f, 25f, 0f },
			{ -0.23f, -0.47f, 0.1f, -32f, 1f },
			{ 0.23f, -0.475f, 0.1f, 12f, 1f },
			{ 0.42f, -0.44f, 0.15f, -19f, 0f }
		};

		private static readonly float[,] DialGears = new float[4, 5]
		{
			{ -0.185f, 0.095f, 0.26f, 1f, 1f },
			{ 0.18f, 0.185f, 0.21f, -1f, 0f },
			{ 0.13f, -0.15f, 0.29f, 1f, 1f },
			{ -0.15f, -0.18f, 0.18f, -1f, 0f }
		};

		private RectTransform? _ringRoot;

		private RectTransform? _clockRoot;

		private readonly List<Spin> _ring = new List<Spin>();

		private readonly List<Spin> _dialGears = new List<Spin>();

		private readonly List<Spin> _clockItems = new List<Spin>();

		private RawImage? _plate;

		private RawImage? _dial;

		private RectTransform? _handHour;

		private RectTransform? _handMin;

		private float _ringAlpha;

		private float _ringTarget;

		private float _holdUntil;

		private bool _pendingHide;

		private float _lastClockAt = -10f;

		private Coroutine? _clockRoutine;

		private int _lastW;

		private int _lastH;

		private bool _asleep;

		private static Texture2D? _gearA;

		private static Texture2D? _gearB;

		private static Texture2D? _plateTex;

		private static Texture2D? _dialTex;

		private static Texture2D? _hourTex;

		private static Texture2D? _minTex;

		private static bool _texLoaded;

		internal static void ShowRing()
		{
			try
			{
				DreamMachineOverlay dreamMachineOverlay = Ensure();
				if (!((Object)(object)dreamMachineOverlay == (Object)null))
				{
					dreamMachineOverlay._pendingHide = false;
					dreamMachineOverlay._ringTarget = 1f;
					dreamMachineOverlay._asleep = false;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[DreamMachine] ShowRing 失败: " + ex.Message));
			}
		}

		internal static void HideRing()
		{
			try
			{
				DreamMachineOverlay inst = _inst;
				if (!((Object)(object)inst == (Object)null))
				{
					if (Time.unscaledTime < inst._holdUntil)
					{
						inst._pendingHide = true;
					}
					else
					{
						inst._ringTarget = 0f;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[DreamMachine] HideRing 失败: " + ex.Message));
			}
		}

		internal static void PlayClock()
		{
			try
			{
				DreamMachineOverlay dreamMachineOverlay = Ensure();
				if (!((Object)(object)dreamMachineOverlay == (Object)null) && !(Time.unscaledTime - dreamMachineOverlay._lastClockAt < 0.9f))
				{
					dreamMachineOverlay._lastClockAt = Time.unscaledTime;
					dreamMachineOverlay._ringTarget = 1f;
					dreamMachineOverlay._pendingHide = false;
					dreamMachineOverlay._asleep = false;
					dreamMachineOverlay._holdUntil = Time.unscaledTime + 2.1f;
					if (dreamMachineOverlay._clockRoutine != null)
					{
						((MonoBehaviour)dreamMachineOverlay).StopCoroutine(dreamMachineOverlay._clockRoutine);
					}
					dreamMachineOverlay._clockRoutine = ((MonoBehaviour)dreamMachineOverlay).StartCoroutine(dreamMachineOverlay.ClockRoutine());
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[DreamMachine] PlayClock 失败: " + ex.Message));
			}
		}

		private static DreamMachineOverlay? Ensure()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)(object)_inst != (Object)null)
			{
				return _inst;
			}
			GameObject val = new GameObject("NDreamMachineVfx");
			Object.DontDestroyOnLoad((Object)val);
			_inst = val.AddComponent<DreamMachineOverlay>();
			return _inst;
		}

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			_inst = this;
			GameObject val = new GameObject("Canvas", new Type[2]
			{
				typeof(RectTransform),
				typeof(Canvas)
			});
			val.transform.SetParent(((Component)this).transform, false);
			Canvas component = val.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.sortingOrder = 32000;
			LoadTextures();
			_ringRoot = NewFullScreen(val.transform, "Gears");
			_clockRoot = NewCenter(val.transform, "Clock");
			((Component)_clockRoot).gameObject.SetActive(false);
			BuildClock();
			Layout();
			_lastW = Screen.width;
			_lastH = Screen.height;
		}

		private static RectTransform NewFullScreen(Transform parent, string name)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			component.pivot = new Vector2(0.5f, 0.5f);
			return component;
		}

		private static RectTransform NewCenter(Transform parent, string name)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = Vector2.zero;
			return component;
		}

		private static RawImage? NewImage(Transform parent, string name, Texture2D? tex, Vector2 size)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)tex == (Object)null)
			{
				return null;
			}
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(RawImage)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.sizeDelta = size;
			RawImage component2 = val.GetComponent<RawImage>();
			component2.texture = (Texture)(object)tex;
			((Graphic)component2).raycastTarget = false;
			((Graphic)component2).color = new Color(1f, 1f, 1f, 0f);
			return component2;
		}

		private void BuildClock()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_clockRoot == (Object)null)
			{
				return;
			}
			_dialGears.Clear();
			_clockItems.Clear();
			_plate = NewImage((Transform)(object)_clockRoot, "Plate", _plateTex, Vector2.one);
			if ((Object)(object)_plate != (Object)null)
			{
				_clockItems.Add(new Spin
				{
					Img = _plate,
					Rt = ((Graphic)_plate).rectTransform,
					Speed = 0f,
					Base = 0.95f
				});
			}
			for (int i = 0; i < DialGears.GetLength(0); i++)
			{
				float num = DialGears[i, 0];
				float num2 = DialGears[i, 1];
				_ = DialGears[i, 2];
				bool flag = DialGears[i, 4] > 0.5f;
				RawImage val = NewImage((Transform)(object)_clockRoot, "DialGear" + i, flag ? _gearB : _gearA, Vector2.one);
				if (!((Object)(object)val == (Object)null))
				{
					Spin spin = new Spin
					{
						Img = val,
						Rt = ((Graphic)val).rectTransform,
						Speed = DialGears[i, 3] * 260f,
						Base = 0.92f,
						Phase = (float)i * 1.7f
					};
					_dialGears.Add(spin);
					_clockItems.Add(spin);
					spin.Rt.anchoredPosition = new Vector2(num, 0f - num2) * 100f;
				}
			}
			_dial = NewImage((Transform)(object)_clockRoot, "Dial", _dialTex, Vector2.one);
			if ((Object)(object)_dial != (Object)null)
			{
				_clockItems.Add(new Spin
				{
					Img = _dial,
					Rt = ((Graphic)_dial).rectTransform,
					Speed = 0f,
					Base = 0.95f
				});
			}
			RawImage val2 = NewImage((Transform)(object)_clockRoot, "HandHour", _hourTex, Vector2.one);
			if ((Object)(object)val2 != (Object)null)
			{
				_handHour = ((Graphic)val2).rectTransform;
				_clockItems.Add(new Spin
				{
					Img = val2,
					Rt = _handHour,
					Speed = 0f,
					Base = 0.98f
				});
			}
			RawImage val3 = NewImage((Transform)(object)_clockRoot, "HandMin", _minTex, Vector2.one);
			if ((Object)(object)val3 != (Object)null)
			{
				_handMin = ((Graphic)val3).rectTransform;
				_clockItems.Add(new Spin
				{
					Img = val3,
					Rt = _handMin,
					Speed = 0f,
					Base = 0.98f
				});
			}
		}

		private void Layout()
		{
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			float num = Screen.width;
			float num2 = Screen.height;
			if ((Object)(object)_ringRoot != (Object)null)
			{
				for (int num3 = ((Transform)_ringRoot).childCount - 1; num3 >= 0; num3--)
				{
					Object.Destroy((Object)(object)((Component)((Transform)_ringRoot).GetChild(num3)).gameObject);
				}
				_ring.Clear();
				for (int i = 0; i < RingLayout.GetLength(0); i++)
				{
					float num4 = RingLayout[i, 0];
					float num5 = RingLayout[i, 1];
					float num6 = RingLayout[i, 2];
					bool flag = RingLayout[i, 4] > 0.5f;
					float num7 = num2 * num6;
					RawImage val = NewImage((Transform)(object)_ringRoot, "Gear" + i, flag ? _gearB : _gearA, new Vector2(num7, num7));
					if (!((Object)(object)val == (Object)null))
					{
						((Graphic)val).rectTransform.anchoredPosition = new Vector2(num4 * num, num5 * num2);
						_ring.Add(new Spin
						{
							Img = val,
							Rt = ((Graphic)val).rectTransform,
							Speed = RingLayout[i, 3],
							Base = 0.88f + 0.1f * Mathf.Sin((float)i * 2.3f),
							Phase = (float)i * 1.31f
						});
					}
				}
			}
			float num8 = num2 * 0.54f;
			if ((Object)(object)_clockRoot != (Object)null)
			{
				_clockRoot.sizeDelta = new Vector2(num8, num8);
			}
			if ((Object)(object)_plate != (Object)null)
			{
				((Graphic)_plate).rectTransform.sizeDelta = new Vector2(num8, num8);
			}
			if ((Object)(object)_dial != (Object)null)
			{
				((Graphic)_dial).rectTransform.sizeDelta = new Vector2(num8, num8);
			}
			for (int j = 0; j < _dialGears.Count; j++)
			{
				float num9 = DialGears[j, 2] * num8;
				_dialGears[j].Rt.sizeDelta = new Vector2(num9, num9);
				_dialGears[j].Rt.anchoredPosition = new Vector2(DialGears[j, 0], 0f - DialGears[j, 1]) * num8;
			}
			if ((Object)(object)_handHour != (Object)null)
			{
				_handHour.sizeDelta = new Vector2(num8, num8);
			}
			if ((Object)(object)_handMin != (Object)null)
			{
				_handMin.sizeDelta = new Vector2(num8, num8);
			}
		}

		private void Update()
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (_asleep)
				{
					return;
				}
				float unscaledTime = Time.unscaledTime;
				float unscaledDeltaTime = Time.unscaledDeltaTime;
				if (Screen.width != _lastW || Screen.height != _lastH)
				{
					_lastW = Screen.width;
					_lastH = Screen.height;
					Layout();
				}
				if (_pendingHide && unscaledTime >= _holdUntil)
				{
					_pendingHide = false;
					_ringTarget = 0f;
				}
				_ringAlpha = Mathf.MoveTowards(_ringAlpha, _ringTarget, unscaledDeltaTime * 1.9f);
				for (int i = 0; i < _ring.Count; i++)
				{
					Spin spin = _ring[i];
					float num = _ringAlpha * spin.Base * (0.86f + 0.14f * Mathf.Sin(unscaledTime * 0.85f + spin.Phase));
					SetAlpha(spin.Img, num);
					((Behaviour)spin.Img).enabled = num > 0.004f;
					if (((Behaviour)spin.Img).enabled)
					{
						((Transform)spin.Rt).localRotation = Quaternion.Euler(0f, 0f, spin.Phase * 41f + spin.Speed * unscaledTime);
					}
				}
				_asleep = _ringAlpha <= 0f && _ringTarget <= 0f && !_pendingHide && _clockRoutine == null;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[DreamMachine] Update 出错: " + ex.Message));
			}
		}

		private IEnumerator ClockRoutine()
		{
			if ((Object)(object)_clockRoot == (Object)null)
			{
				yield break;
			}
			((Component)_clockRoot).gameObject.SetActive(true);
			((Transform)_clockRoot).localScale = Vector3.one;
			if ((Object)(object)_handHour != (Object)null)
			{
				((Transform)_handHour).localRotation = Quaternion.identity;
			}
			if ((Object)(object)_handMin != (Object)null)
			{
				((Transform)_handMin).localRotation = Quaternion.identity;
			}
			for (int i = 0; i < _dialGears.Count; i++)
			{
				((Transform)_dialGears[i].Rt).localRotation = Quaternion.Euler(0f, 0f, _dialGears[i].Phase * 41f);
			}
			for (float t = 0f; t < 0.2f; t += Time.unscaledDeltaTime)
			{
				float num = Mathf.Clamp01(t / 0.2f);
				float num2 = 1f - Mathf.Pow(1f - num, 3f);
				SetClockAlpha(0.96f * num2);
				float num3 = Mathf.Lerp(0.88f, 1f, num2);
				((Transform)_clockRoot).localScale = new Vector3(num3, num3, 1f);
				yield return null;
			}
			for (float t = 0f; t < 1.35f; t += Time.unscaledDeltaTime)
			{
				float num4 = Mathf.Clamp01(t / 1.35f);
				float num5 = num4 * num4 * (3f - 2f * num4);
				float num6 = 360f * num5;
				if ((Object)(object)_handHour != (Object)null)
				{
					((Transform)_handHour).localRotation = Quaternion.Euler(0f, 0f, 0f - num6);
				}
				if ((Object)(object)_handMin != (Object)null)
				{
					((Transform)_handMin).localRotation = Quaternion.Euler(0f, 0f, 0f - num6);
				}
				for (int j = 0; j < _dialGears.Count; j++)
				{
					Spin spin = _dialGears[j];
					((Transform)spin.Rt).localRotation = Quaternion.Euler(0f, 0f, spin.Phase * 41f + spin.Speed / 260f * num6);
				}
				SetClockAlpha(0.96f + 0.04f * Mathf.Sin(t * 34f));
				float num7 = Mathf.Lerp(1f, 1.03f, num5);
				((Transform)_clockRoot).localScale = new Vector3(num7, num7, 1f);
				yield return null;
			}
			for (float t = 0f; t < 0.18f; t += Time.unscaledDeltaTime)
			{
				yield return null;
			}
			for (float t = 0f; t < 0.55f; t += Time.unscaledDeltaTime)
			{
				float num8 = Mathf.Clamp01(t / 0.55f);
				float num9 = num8 * num8;
				SetClockAlpha(0.96f * (1f - num9));
				float num10 = Mathf.Lerp(1.03f, 1.12f, num9);
				((Transform)_clockRoot).localScale = new Vector3(num10, num10, 1f);
				yield return null;
			}
			SetClockAlpha(0f);
			((Transform)_clockRoot).localScale = Vector3.one;
			((Component)_clockRoot).gameObject.SetActive(false);
			_holdUntil = 0f;
			if (!_pendingHide)
			{
				_ringTarget = 0f;
			}
			_clockRoutine = null;
		}

		private void SetClockAlpha(float mul)
		{
			for (int i = 0; i < _clockItems.Count; i++)
			{
				Spin spin = _clockItems[i];
				SetAlpha(spin.Img, Mathf.Clamp01(mul * spin.Base));
				((Behaviour)spin.Img).enabled = mul > 0.004f;
			}
		}

		private static void SetAlpha(RawImage img, float a)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Color color = ((Graphic)img).color;
			color.r = 1f;
			color.g = 1f;
			color.b = 1f;
			color.a = Mathf.Clamp01(a);
			((Graphic)img).color = color;
		}

		private static void LoadTextures()
		{
			if (!_texLoaded)
			{
				_texLoaded = true;
				_gearA = FxTexture.Load("FX_DreamMachineGearA.png", "NDreamGearA", "[DreamMachine]");
				_gearB = FxTexture.Load("FX_DreamMachineGearB.png", "NDreamGearB", "[DreamMachine]");
				_plateTex = FxTexture.Load("FX_DreamMachinePlate.png", "NDreamPlate", "[DreamMachine]");
				_dialTex = FxTexture.Load("FX_DreamMachineDial.png", "NDreamDial", "[DreamMachine]");
				_hourTex = FxTexture.Load("FX_DreamMachineHandHour.png", "NDreamHandHour", "[DreamMachine]");
				_minTex = FxTexture.Load("FX_DreamMachineHandMin.png", "NDreamHandMin", "[DreamMachine]");
				int num = (((Object)(object)_gearA != (Object)null) ? 1 : 0) + (((Object)(object)_gearB != (Object)null) ? 1 : 0) + (((Object)(object)_plateTex != (Object)null) ? 1 : 0) + (((Object)(object)_dialTex != (Object)null) ? 1 : 0) + (((Object)(object)_hourTex != (Object)null) ? 1 : 0) + (((Object)(object)_minTex != (Object)null) ? 1 : 0);
				Plugin.Logger.LogInfo((object)("[DreamMachine] 贴图加载 " + num + "/6"));
			}
		}
	}
	internal static class DreamMachineVfx
	{
		private static readonly string[] TargetCardIds = new string[3] { "UnitDreamMachine", "UnitDreamShatterer", "UnitRuinEngine" };

		internal static bool IsTargetCard(CardState? card)
		{
			return CardIdMatcher.IsTarget(card, TargetCardIds);
		}
	}
	[HarmonyPatch(typeof(CommonSelectionBehavior), "FocusCardInternal")]
	internal static class DreamMachineFocusPatch
	{
		private static readonly FieldRef<CommonSelectionBehavior, CardState> FocusedCard = AccessTools.FieldRefAccess<CommonSelectionBehavior, CardState>("focusedCardState");

		private static bool Prepare()
		{
			return Guard("FocusCardInternal");
		}

		internal static bool GuardPublic(string method)
		{
			return Guard(method);
		}

		internal static CardState? ReadFocused(CommonSelectionBehavior behavior)
		{
			try
			{
				return FocusedCard.Invoke(behavior);
			}
			catch (Exception)
			{
				return null;
			}
		}

		private static bool Guard(string method)
		{
			return PatchGuard.Method(typeof(CommonSelectionBehavior), method, "[DreamMachine]", "齿轮环绕开关失效");
		}

		[HarmonyPostfix]
		private static void Postfix(CommonSelectionBehavior __instance)
		{
			try
			{
				if (DreamMachineVfx.IsTargetCard(ReadFocused(__instance)))
				{
					DreamMachineOverlay.ShowRing();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[DreamMachine] Focus 补丁失败: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(CommonSelectionBehavior), "UnFocusCardInternal")]
	internal static class DreamMachineUnfocusPatch
	{
		private static bool Prepare()
		{
			return DreamMachineFocusPatch.GuardPublic("UnFocusCardInternal");
		}

		private static void Prefix(CommonSelectionBehavior __instance, out bool __state)
		{
			__state = SafeIsSelected(__instance);
		}

		[HarmonyPostfix]
		private static void Postfix(bool __state)
		{
			try
			{
				if (!__state)
				{
					DreamMachineOverlay.HideRing();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[DreamMachine] UnFocus 补丁失败: " + ex.Message));
			}
		}

		private static bool SafeIsSelected(CommonSelectionBehavior behavior)
		{
			try
			{
				return behavior.IsCardSelected();
			}
			catch (Exception)
			{
				return false;
			}
		}
	}
	[HarmonyPatch(typeof(CommonSelectionBehavior), "SelectCardInternal")]
	internal static class DreamMachineSelectPatch
	{
		private static bool Prepare()
		{
			return DreamMachineFocusPatch.GuardPublic("SelectCardInternal");
		}

		[HarmonyPostfix]
		private static void Postfix(CommonSelectionBehavior __instance)
		{
			try
			{
				if (DreamMachineVfx.IsTargetCard(DreamMachineFocusPatch.ReadFocused(__instance)))
				{
					DreamMachineOverlay.ShowRing();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[DreamMachine] Select 补丁失败: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(CardManager), "PlayAnyCard")]
	internal static class DreamMachinePlayPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(CardManager), "PlayAnyCard", "[DreamMachine]", "齿轮时钟关闭");
		}

		[HarmonyPostfix]
		private static void Postfix(CardState cardState, bool __result)
		{
			try
			{
				if (__result && DreamMachineVfx.IsTargetCard(cardState))
				{
					DreamMachineOverlay.PlayClock();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[DreamMachine] Play 补丁失败: " + ex.Message));
			}
		}
	}
	public sealed class EnterDreamClawsOverlay : MonoBehaviour
	{
		private enum Edge
		{
			Left,
			Right,
			Top,
			Bottom
		}

		private sealed class Claw
		{
			internal Edge Side;

			internal float Along;

			internal float Size;

			internal float Depth;

			internal float Delay;

			internal float Tilt;

			internal bool Mirror;

			internal RawImage? Img;

			internal RectTransform? Rect;
		}

		private const string ClawAFile = "FX_DreamClawA.png";

		private const string ClawBFile = "FX_DreamClawB.png";

		private const int CanvasOrder = 32000;

		private static EnterDreamClawsOverlay? _inst;

		private Canvas? _canvas;

		private readonly Claw[] _claws = new Claw[8];

		private float _reach;

		private float _target;

		private float _lunge = 1f;

		private const float LungeSpan = 0.3f;

		private float _lungeTimer;

		private bool _asleep;

		private static Texture2D? _texA;

		private static Texture2D? _texB;

		private static bool _texLoaded;

		private float _aspect = 41f / 54f;

		internal static void Show()
		{
			try
			{
				EnterDreamClawsOverlay enterDreamClawsOverlay = Ensure();
				if (!((Object)(object)enterDreamClawsOverlay == (Object)null))
				{
					enterDreamClawsOverlay._target = 1f;
					enterDreamClawsOverlay._asleep = false;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[Claws] Show 失败: " + ex.Message));
			}
		}

		internal static void Hide()
		{
			try
			{
				if ((Object)(object)_inst != (Object)null)
				{
					_inst._target = 0f;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[Claws] Hide 失败: " + ex.Message));
			}
		}

		internal static void Play()
		{
			try
			{
				EnterDreamClawsOverlay enterDreamClawsOverlay = Ensure();
				if (!((Object)(object)enterDreamClawsOverlay == (Object)null))
				{
					enterDreamClawsOverlay._target = 1f;
					enterDreamClawsOverlay._lungeTimer = 0.3f;
					enterDreamClawsOverlay._lunge = 1f;
					enterDreamClawsOverlay._asleep = false;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[Claws] Play 失败: " + ex.Message));
			}
		}

		private static EnterDreamClawsOverlay? Ensure()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)(object)_inst != (Object)null)
			{
				return _inst;
			}
			GameObject val = new GameObject("NDreamClawsVfx");
			Object.DontDestroyOnLoad((Object)val);
			_inst = val.AddComponent<EnterDreamClawsOverlay>();
			return _inst;
		}

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			_inst = this;
			GameObject val = new GameObject("Canvas", new Type[2]
			{
				typeof(RectTransform),
				typeof(Canvas)
			});
			val.transform.SetParent(((Component)this).transform, false);
			_canvas = val.GetComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = 32000;
			LoadTextures();
			if ((Object)(object)_texA != (Object)null && ((Texture)_texA).height > 0)
			{
				_aspect = (float)((Texture)_texA).width / (float)((Texture)_texA).height;
			}
			Init(0, Edge.Left, 0.315f, 0.62f, 0.255f, 0f, -5f, mirror: false);
			Init(1, Edge.Left, 0.76f, 0.46f, 0.215f, 0.26f, 4f, mirror: true);
			Init(2, Edge.Right, 0.295f, 0.58f, 0.25f, 0.12f, 5f, mirror: true);
			Init(3, Edge.Right, 0.72f, 0.45f, 0.21f, 0.34f, -4f, mirror: false);
			Init(4, Edge.Top, 0.28f, 0.52f, 0.235f, 0.06f, -3f, mirror: false);
			Init(5, Edge.Top, 0.715f, 0.43f, 0.2f, 0.3f, 3f, mirror: true);
			Init(6, Edge.Bottom, 0.125f, 0.4f, 0.185f, 0.18f, 6f, mirror: true);
			Init(7, Edge.Bottom, 0.875f, 0.4f, 0.185f, 0.22f, -6f, mirror: false);
		}

		private void Init(int index, Edge side, float along, float size, float depth, float delay, float tilt, bool mirror)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			Texture2D texture = ((mirror && (Object)(object)_texB != (Object)null) ? _texB : (_texA ?? _texB));
			Claw claw = new Claw
			{
				Side = side,
				Along = along,
				Size = size,
				Depth = depth,
				Delay = delay,
				Tilt = tilt,
				Mirror = mirror
			};
			GameObject val = new GameObject("Claw" + index, new Type[2]
			{
				typeof(RectTransform),
				typeof(RawImage)
			});
			val.transform.SetParent(((Component)_canvas).transform, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.sizeDelta = new Vector2(100f, 130f);
			RawImage component2 = val.GetComponent<RawImage>();
			component2.texture = (Texture)(object)texture;
			((Graphic)component2).raycastTarget = false;
			((Graphic)component2).color = new Color(1f, 1f, 1f, 0f);
			if (mirror)
			{
				component2.uvRect = new Rect(1f, 0f, -1f, 1f);
			}
			claw.Img = component2;
			claw.Rect = component;
			_claws[index] = claw;
		}

		private void Update()
		{
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (_asleep)
				{
					return;
				}
				float unscaledDeltaTime = Time.unscaledDeltaTime;
				float unscaledTime = Time.unscaledTime;
				_reach = Mathf.MoveTowards(_reach, _target, unscaledDeltaTime * 2.4f);
				if (_lungeTimer > 0f)
				{
					_lungeTimer -= unscaledDeltaTime;
					_lunge = Mathf.Clamp01(_lungeTimer / 0.3f);
				}
				else
				{
					_lunge = 0f;
				}
				float num = Screen.width;
				float num2 = Screen.height;
				Vector2 anchoredPosition = default(Vector2);
				for (int i = 0; i < _claws.Length; i++)
				{
					Claw claw = _claws[i];
					if (!((Object)(object)claw.Img == (Object)null) && !((Object)(object)claw.Rect == (Object)null))
					{
						float num3 = Mathf.Max(1f - claw.Delay, 0.001f);
						float num4 = Mathf.Clamp01((_reach - claw.Delay) / num3);
						float num5 = num4 - 1f;
						float num6 = 1f + 2.70158f * num5 * num5 * num5 + 1.70158f * num5 * num5;
						float num7 = num2 * claw.Size;
						float num8 = claw.Depth + 0.115f * _lunge;
						float num9 = Mathf.Lerp(-0.62f, num8, num6) * num7;
						float num10 = (Mathf.Sin(unscaledTime * 0.75f + (float)i * 2.1f) * 1.6f + Mathf.Sin(unscaledTime * 1.31f + (float)i * 1.3f) * 0.9f) * num4;
						float num11;
						switch (claw.Side)
						{
						case Edge.Left:
							((Vector2)(ref anchoredPosition))..ctor((0f - num) * 0.5f + num9 + num10, (claw.Along - 0.5f) * num2);
							num11 = -90f;
							break;
						case Edge.Right:
							((Vector2)(ref anchoredPosition))..ctor(num * 0.5f - num9 - num10, (claw.Along - 0.5f) * num2);
							num11 = 90f;
							break;
						case Edge.Top:
							((Vector2)(ref anchoredPosition))..ctor((claw.Along - 0.5f) * num + num10, num2 * 0.5f - num9);
							num11 = 180f;
							break;
						default:
							((Vector2)(ref anchoredPosition))..ctor((claw.Along - 0.5f) * num + num10, (0f - num2) * 0.5f + num9);
							num11 = 0f;
							break;
						}
						claw.Rect.anchoredPosition = anchoredPosition;
						claw.Rect.sizeDelta = new Vector2(num7 * _aspect, num7);
						((Transform)claw.Rect).localRotation = Quaternion.Euler(0f, 0f, num11 + claw.Tilt + 8f * (1f - num4));
						float num12 = Mathf.Clamp01(num4 * 1.7f);
						((Graphic)claw.Img).color = new Color(1f, 1f, 1f, num12 * 0.97f);
						((Behaviour)claw.Img).enabled = num12 > 0.004f;
					}
				}
				_asleep = _reach <= 0f && _target <= 0f && _lungeTimer <= 0f;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[Claws] Update 出错: " + ex.Message));
			}
		}

		private static void LoadTextures()
		{
			if (!_texLoaded)
			{
				_texLoaded = true;
				_texA = FxTexture.Load("FX_DreamClawA.png", "NDreamClawA", "[Claws]");
				_texB = FxTexture.Load("FX_DreamClawB.png", "NDreamClawB", "[Claws]");
				int num = (((Object)(object)_texA != (Object)null) ? 1 : 0) + (((Object)(object)_texB != (Object)null) ? 1 : 0);
				Plugin.Logger.LogInfo((object)("[Claws] 贴图加载 " + num + "/2"));
			}
		}
	}
	internal static class EnterDreamClawsVfx
	{
		private static readonly string[] TargetCardIds = new string[2] { "SpellGhostHaunt", "SpellUndying" };

		internal static bool IsTargetCard(CardState? card)
		{
			return CardIdMatcher.IsTarget(card, TargetCardIds);
		}
	}
	[HarmonyPatch(typeof(CommonSelectionBehavior), "FocusCardInternal")]
	internal static class EnterDreamClawsFocusPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(CommonSelectionBehavior), "FocusCardInternal", "[Claws]", "悬停爪效关闭");
		}

		[HarmonyPostfix]
		private static void Postfix(CommonSelectionBehavior __instance)
		{
			try
			{
				if (EnterDreamClawsVfx.IsTargetCard(EnterDreamFocusPatch.ReadFocused(__instance)))
				{
					EnterDreamClawsOverlay.Show();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[Claws] Focus 补丁失败: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(CommonSelectionBehavior), "UnFocusCardInternal")]
	internal static class EnterDreamClawsUnfocusPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(CommonSelectionBehavior), "UnFocusCardInternal", "[Claws]", "爪效收不回去");
		}

		private static void Prefix(CommonSelectionBehavior __instance, out bool __state)
		{
			__state = EnterDreamUnfocusPatch.SafeIsSelected(__instance);
		}

		[HarmonyPostfix]
		private static void Postfix(bool __state)
		{
			try
			{
				if (!__state)
				{
					EnterDreamClawsOverlay.Hide();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[Claws] UnFocus 补丁失败: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(CommonSelectionBehavior), "SelectCardInternal")]
	internal static class EnterDreamClawsSelectPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(CommonSelectionBehavior), "SelectCardInternal", "[Claws]", "点选兜底关闭");
		}

		[HarmonyPostfix]
		private static void Postfix(CommonSelectionBehavior __instance)
		{
			try
			{
				if (EnterDreamClawsVfx.IsTargetCard(EnterDreamFocusPatch.ReadFocused(__instance)))
				{
					EnterDreamClawsOverlay.Show();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[Claws] Select 补丁失败: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(CardManager), "PlayAnyCard")]
	internal static class EnterDreamClawsPlayPatch
	{
		private static bool Prepare()
		{
			return PatchGuard.Method(typeof(CardManager), "PlayAnyCard", "[Claws]", "打出收爪关闭");
		}

		[HarmonyPostfix]
		private static void Postfix(CardState cardState, bool __result)
		{
			try
			{
				if (__result && EnterDreamClawsVfx.IsTargetCard(cardState))
				{
					EnterDreamClawsOverlay.Play();
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[Claws] Play 补丁失败: " + ex.Message));
			}
		}
	}
	public sealed class EnterDreamOverlay : MonoBehaviour
	{
		private const string VeilFile = "FX_EnterDreamVeil.png";

		private const string MistFile = "FX_EnterDreamMist.png";

		private const string FaceFile = "FX_EnterDreamFace.png";

		private const int CanvasOrder = 32000;

		private static EnterDreamOverlay? _inst;

		private Canvas? _canvas;

		private RawImage? _veil;

		private RawImage? _mist;

		private RawImage? _face;

		private RectTransform? _faceRect;

		private float _veilAlpha;

		private float _veilTarget;

		private float _holdUntil;

		private bool _pendingHide;

		private float _lastSmileAt = -10f;

		private int _lastW;

		private int _lastH;

		private bool _asleep;

		private static Texture2D? _veilTex;

		private static Texture2D? _mistTex;

		private static Texture2D? _faceTex;

		private static bool _texLoaded;

		private Coroutine? _smileRoutine;

		internal static void ShowVeil()
		{
			try
			{
				EnterDreamOverlay enterDreamOverlay = Ensure();
				if (!((Object)(object)enterDreamOverlay == (Object)null))
				{
					enterDreamOverlay._pendingHide = false;
					enterDreamOverlay._veilTarget = 1f;
					enterDreamOverlay._asleep = false;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[EnterDream] ShowVeil 失败: " + ex.Message));
			}
		}

		internal static void HideVeil()
		{
			try
			{
				EnterDreamOverlay inst = _inst;
				if (!((Object)(object)inst == (Object)null))
				{
					if (Time.unscaledTime < inst._holdUntil)
					{
						inst._pendingHide = true;
					}
					else
					{
						inst._veilTarget = 0f;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[EnterDream] HideVeil 失败: " + ex.Message));
			}
		}

		internal static void PlaySmile()
		{
			try
			{
				EnterDreamOverlay enterDreamOverlay = Ensure();
				if (!((Object)(object)enterDreamOverlay == (Object)null) && !(Time.unscaledTime - enterDreamOverlay._lastSmileAt < 0.6f))
				{
					enterDreamOverlay._lastSmileAt = Time.unscaledTime;
					enterDreamOverlay._veilTarget = 1f;
					enterDreamOverlay._pendingHide = false;
					enterDreamOverlay._asleep = false;
					enterDreamOverlay._holdUntil = Time.unscaledTime + 1.3f;
					if (enterDreamOverlay._smileRoutine != null)
					{
						((MonoBehaviour)enterDreamOverlay).StopCoroutine(enterDreamOverlay._smileRoutine);
					}
					enterDreamOverlay._smileRoutine = ((MonoBehaviour)enterDreamOverlay).StartCoroutine(enterDreamOverlay.SmileRoutine());
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[EnterDream] PlaySmile 失败: " + ex.Message));
			}
		}

		private static EnterDreamOverlay? Ensure()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)(object)_inst != (Object)null)
			{
				return _inst;
			}
			GameObject val = new GameObject("NDreamEnterVfx");
			Object.DontDestroyOnLoad((Object)val);
			_inst = val.AddComponent<EnterDreamOverlay>();
			return _inst;
		}

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			_inst = this;
			GameObject val = new GameObject("Canvas", new Type[2]
			{
				typeof(RectTransform),
				typeof(Canvas)
			});
			val.transform.SetParent(((Component)this).transform, false);
			_canvas = val.GetComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = 32000;
			LoadTextures();
			_veil = AddLayer(val.transform, "Veil", _veilTex, repeat: true);
			_mist = AddLayer(val.transform, "Mist", _mistTex, repeat: true);
			_face = AddLayer(val.transform, "Face", _faceTex, repeat: false);
			if ((Object)(object)_veil != (Object)null)
			{
				SetAlpha(_veil, 0f);
			}
			if ((Object)(object)_mist != (Object)null)
			{
				_mist.uvRect = new Rect(0f, 0f, 2.2f, 2.2f);
				SetAlpha(_mist, 0f);
			}
			if ((Object)(object)_face != (Object)null)
			{
				_faceRect = ((Graphic)_face).rectTransform;
				_faceRect.anchorMin = new Vector2(0.5f, 0.5f);
				_faceRect.anchorMax = new Vector2(0.5f, 0.5f);
				_faceRect.pivot = new Vector2(0.5f, 0.5f);
				SetAlpha(_face, 0f);
				((Behaviour)_face).enabled = false;
			}
			ResizeFace();
		}

		private static RawImage? AddLayer(Transform parent, string name, Texture2D? tex, bool repeat)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)tex == (Object)null)
			{
				return null;
			}
			if (repeat)
			{
				((Texture)tex).wrapMode = (TextureWrapMode)0;
			}
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(RawImage)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			component.pivot = new Vector2(0.5f, 0.5f);
			RawImage component2 = val.GetComponent<RawImage>();
			component2.texture = (Texture)(object)tex;
			((Graphic)component2).raycastTarget = false;
			((Graphic)component2).color = new Color(1f, 1f, 1f, 0f);
			return component2;
		}

		private void ResizeFace()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_faceRect == (Object)null))
			{
				float num = (float)Screen.height * 0.58f;
				float num2 = (((Object)(object)_faceTex != (Object)null && ((Texture)_faceTex).height > 0) ? ((float)((Texture)_faceTex).width / (float)((Texture)_faceTex).height) : 1.0526316f);
				_faceRect.sizeDelta = new Vector2(num * num2, num);
				_faceRect.anchoredPosition = Vector2.zero;
			}
		}

		private void Update()
		{
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!_asleep)
				{
					float unscaledTime = Time.unscaledTime;
					float unscaledDeltaTime = Time.unscaledDeltaTime;
					if (_pendingHide && unscaledTime >= _holdUntil)
					{
						_pendingHide = false;
						_veilTarget = 0f;
					}
					if (Screen.width != _lastW || Screen.height != _lastH)
					{
						_lastW = Screen.width;
						_lastH = Screen.height;
						ResizeFace();
					}
					_veilAlpha = Mathf.MoveTowards(_veilAlpha, _veilTarget, unscaledDeltaTime * 1.6f);
					if ((Object)(object)_veil != (Object)null)
					{
						float num = 0.9f + 0.1f * Mathf.Sin(unscaledTime * 1.45f);
						SetAlpha(_veil, _veilAlpha * 0.95f * num);
						float num2 = 0.006f * Mathf.Sin(unscaledTime * 0.65f);
						_veil.uvRect = new Rect(0f - num2, num2, 1f + 2f * num2, 1f + 2f * num2);
						((Behaviour)_veil).enabled = _veilAlpha > 0.002f;
					}
					if ((Object)(object)_mist != (Object)null)
					{
						SetAlpha(_mist, _veilAlpha * 0.4f * (0.82f + 0.18f * Mathf.Sin(unscaledTime * 0.9f)));
						_mist.uvRect = new Rect(Mathf.Repeat(unscaledTime * 0.012f, 1f), Mathf.Repeat((0f - unscaledTime) * 0.008f, 1f), 2.2f, 2.2f);
						((Behaviour)_mist).enabled = _veilAlpha > 0.002f;
					}
					_asleep = _veilAlpha <= 0f && _veilTarget <= 0f && !_pendingHide && _smileRoutine == null;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogWarning((object)("[EnterDream] Update 出错: " + ex.Message));
			}
		}

		private IEnumerator Sm