Decompiled source of MagicBeanPiP v0.5.5

plugins/MagicBeanPiP.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 MagicBeanPiP
{
	internal static class BeanPrediction
	{
		public struct LandingResult
		{
			public bool valid;

			public Vector3 point;

			public Vector3 normal;
		}

		private const int MaxSteps = 120;

		private const float StepMargin = 0.03f;

		private const float AbortingDepth = 150f;

		private const float SampleRadius = 0.25f;

		private const float SampleDepth = 1.5f;

		private const float VerticalSnapDegrees = 15f;

		private const float MinValidDistance = 0.7f;

		private static readonly LayerMask SolidMask;

		private static MethodInfo _aimResolver;

		static BeanPrediction()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			SolidMask = LayerMask.op_Implicit(LayerMask.GetMask(new string[4] { "Terrain", "Map", "Default", "Character" }));
			try
			{
				_aimResolver = typeof(HelperFunctions).GetMethod("LookToDirection", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
			catch
			{
				_aimResolver = null;
			}
		}

		public static float ResolveThrowForce(CharacterItems items)
		{
			if ((Object)(object)items == (Object)null)
			{
				return 0f;
			}
			return items.minThrowForce + (items.maxThrowForce - items.minThrowForce) * items.throwChargeLevel;
		}

		public static Vector3 ResolveAimDirection(Character owner)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)owner == (Object)null || (Object)(object)owner.data == (Object)null)
			{
				return Vector3.forward;
			}
			Vector3 val = InvokeAimResolver(Vector2.op_Implicit(owner.data.lookValues), Vector3.forward);
			if (!(((Vector3)(ref val)).sqrMagnitude > 1E-06f))
			{
				return Vector3.forward;
			}
			return ((Vector3)(ref val)).normalized;
		}

		public static Vector3 HorizontalAimOf(Character owner)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.ProjectOnPlane(ResolveAimDirection(owner), Vector3.up);
			if (!(((Vector3)(ref val)).sqrMagnitude > 1E-06f))
			{
				return Vector3.forward;
			}
			return ((Vector3)(ref val)).normalized;
		}

		public static LandingResult PredictLanding(Item item, Character owner, float throwForce)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0097: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00b5: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00cd: 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)
			//IL_0139: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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)
			LandingResult result = default(LandingResult);
			if ((Object)(object)item == (Object)null || (Object)(object)owner == (Object)null || (Object)(object)owner.data == (Object)null)
			{
				return result;
			}
			Rigidbody component = ((Component)item).GetComponent<Rigidbody>();
			Vector3 position = item.transform.position;
			Vector3 val = ResolveAimDirection(owner) * throwForce * 0.5f * item.throwForceMultiplier;
			if ((Object)(object)component != (Object)null)
			{
				val += component.linearVelocity;
			}
			if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
			{
				return result;
			}
			Vector3 val2 = position;
			Vector3 val3 = val;
			float fixedDeltaTime = Time.fixedDeltaTime;
			Vector3 gravity = Physics.gravity;
			RaycastHit val7 = default(RaycastHit);
			for (int i = 0; i < 120; i++)
			{
				Vector3 val4 = val2;
				val3 += gravity * fixedDeltaTime;
				val4 += val3 * fixedDeltaTime;
				Vector3 val5 = val4 - val2;
				if (((Vector3)(ref val5)).sqrMagnitude > 1E-08f)
				{
					Vector3 val6 = val4 + ((Vector3)(ref val5)).normalized * 0.03f;
					if (Physics.Linecast(val2, val6, ref val7, LayerMask.op_Implicit(SolidMask)))
					{
						result.valid = true;
						result.point = ((RaycastHit)(ref val7)).point;
						result.normal = ((RaycastHit)(ref val7)).normal;
						return result;
					}
				}
				val2 = val4;
				if (val2.y < position.y - 150f)
				{
					break;
				}
			}
			return result;
		}

		public static Vector3 ResolveGrowthDirection(Vector3 basePoint, Vector3 centerNormal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0036: 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)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0052: 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)
			//IL_005a: 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_0069: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_008d: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00ac: 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)
			//IL_00b2: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = centerNormal;
			Vector3 val2 = Vector3.ProjectOnPlane(Vector3.right, centerNormal);
			if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
			{
				val2 = Vector3.ProjectOnPlane(Vector3.forward, centerNormal);
			}
			((Vector3)(ref val2)).Normalize();
			Vector3 val3 = Vector3.Cross(centerNormal, val2);
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			Vector3[] array = (Vector3[])(object)new Vector3[4]
			{
				val2 * 0.25f,
				-val2 * 0.25f,
				normalized * 0.25f,
				-normalized * 0.25f
			};
			RaycastHit val5 = default(RaycastHit);
			foreach (Vector3 val4 in array)
			{
				if (Physics.Raycast(basePoint + val4 + centerNormal, -centerNormal, ref val5, 1.5f, LayerMask.op_Implicit(SolidMask)) && (Object)(object)((RaycastHit)(ref val5)).collider != (Object)null)
				{
					val += ((RaycastHit)(ref val5)).normal;
				}
			}
			((Vector3)(ref val)).Normalize();
			if (Vector3.Angle(val, Vector3.up) < 15f)
			{
				val = Vector3.up;
			}
			return val;
		}

		public static float MeasureVineLength(Vector3 start, Vector3 growthDir, float cap)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(start, growthDir, ref val, cap, LayerMask.op_Implicit(SolidMask)) && ((RaycastHit)(ref val)).distance > 0.7f)
			{
				return ((RaycastHit)(ref val)).distance;
			}
			return cap;
		}

		private static Vector3 InvokeAimResolver(Vector3 look, Vector3 fallback)
		{
			//IL_000d: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (_aimResolver == null)
			{
				return fallback;
			}
			try
			{
				object obj = _aimResolver.Invoke(null, new object[2] { look, fallback });
				if (obj is Vector3)
				{
					return (Vector3)obj;
				}
			}
			catch
			{
			}
			return fallback;
		}
	}
	[HarmonyPatch(typeof(CharacterItems), "DoDropping")]
	internal static class BeanPredictionController
	{
		private const float UpdateInterval = 0.1f;

		public const int PreviewLayer = 31;

		public const string ExternalPredictionVineName = "MagicBeanVinePrediction";

		public const string ExternalActualVineName = "ActualVinePrediction";

		private static GameObject _ownVine;

		private static bool _ownVineAssigned;

		private static float _nextUpdateAt;

		private static float _lastThrowForce = -1f;

		private static bool _vineHiddenFromMain;

		private static int _createCount;

		private static bool _wasCharging;

		private static BeanPredictionData? _frozen;

		private static float _frozenSince;

		public static bool HasFrozenPrediction => _frozen.HasValue;

		public static BeanPredictionData? FrozenPrediction => _frozen;

		public static bool UsingOurHiddenVine
		{
			get
			{
				if ((Object)(object)_ownVine != (Object)null)
				{
					return _vineHiddenFromMain;
				}
				return false;
			}
		}

		public static void Postfix(CharacterItems __instance, Character ___character, bool ___pressedDrop)
		{
			try
			{
				Tick(__instance, ___character, ___pressedDrop);
			}
			catch (Exception arg)
			{
				ManualLogSource loggerRef = Plugin.LoggerRef;
				if (loggerRef != null)
				{
					loggerRef.LogError((object)$"[魔豆画中画预览] 预测补丁异常:{arg}");
				}
			}
		}

		private static void Tick(CharacterItems items, Character character, bool pressedDrop)
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: 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_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: 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_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.Enable == null || !ModConfig.Enable.Value)
			{
				ClearAll();
			}
			else
			{
				if ((Object)(object)items == (Object)null || (Object)(object)character == (Object)null || !character.IsLocal || (Object)(object)character.data == (Object)null)
				{
					return;
				}
				if (_ownVineAssigned && (Object)(object)_ownVine == (Object)null)
				{
					LogDebug("[Tick] 检测到 _ownVine 被外部销毁(fake null),将重建");
					_ownVine = null;
					_ownVineAssigned = false;
					_vineHiddenFromMain = false;
				}
				Item currentItem = character.data.currentItem;
				MagicBean val = (((Object)(object)currentItem != (Object)null) ? ((Component)currentItem).GetComponent<MagicBean>() : null);
				bool flag = pressedDrop && (Object)(object)character.input != (Object)null && character.input.dropIsPressed && items.throwChargeLevel > 0.1f;
				if (flag != _wasCharging)
				{
					LogDebug($"[Tick] 蓄力状态变化: {_wasCharging} → {flag}(throwChargeLevel={items.throwChargeLevel})");
					_wasCharging = flag;
				}
				if ((Object)(object)val == (Object)null || !flag)
				{
					if (_frozen.HasValue && Time.time - _frozenSince > ModConfig.KeepAfterThrow.Value)
					{
						ClearAll();
					}
				}
				else
				{
					if (Time.time < _nextUpdateAt)
					{
						return;
					}
					_nextUpdateAt = Time.time + 0.1f;
					float num = BeanPrediction.ResolveThrowForce(items);
					if (num <= 0f)
					{
						LogDebug("[Tick] throwForce<=0,跳过");
						return;
					}
					BeanPrediction.LandingResult landingResult = BeanPrediction.PredictLanding(currentItem, character, num);
					if (!landingResult.valid)
					{
						LogDebug("[Tick] 落点预测无效,跳过");
						return;
					}
					Vector3 val2 = BeanPrediction.ResolveGrowthDirection(landingResult.point, landingResult.normal);
					float num2 = BeanPrediction.MeasureVineLength(landingResult.point, val2, val.plantPrefab.maxLength);
					LogDebug(string.Format("[Tick] 预测完成 落点={0} 方向={1} 长度={2} _ownVine={3}", landingResult.point, val2, num2, ((Object)(object)_ownVine == (Object)null) ? "null" : "alive"));
					_frozen = new BeanPredictionData
					{
						basePos = landingResult.point,
						direction = val2,
						length = num2,
						referenceHorizontal = BeanPrediction.HorizontalAimOf(character),
						timestamp = Time.time
					};
					_frozenSince = Time.time;
					_lastThrowForce = num;
					if ((Object)(object)GameObject.Find("MagicBeanVinePrediction") != (Object)null)
					{
						LogDebug("[Tick] 发现外部预测藤蔓,不自建");
						DestroyOwnVine();
					}
					else
					{
						EnsureOwnVine(val, landingResult.point, val2, num2);
					}
				}
			}
		}

		private static void EnsureOwnVine(MagicBean bean, Vector3 pos, Vector3 dir, float length)
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_003f: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_ownVine == (Object)null)
			{
				_createCount++;
				LogDebug($"[Ensure #{_createCount}] 创建预测藤蔓 pos={pos} dir={dir} length={length}");
				_ownVine = VinePreviewFactory.CreatePredictionVine(bean, pos, dir, length);
				if ((Object)(object)_ownVine == (Object)null)
				{
					LogDebug($"[Ensure #{_createCount}] 创建返回 null");
					return;
				}
				LogDebug($"[Ensure #{_createCount}] 创建成功 active={_ownVine.activeSelf}");
				_ownVineAssigned = true;
				_vineHiddenFromMain = !ModConfig.MainViewPredictionVine.Value;
				if (_vineHiddenFromMain)
				{
					SetLayerRecursive(_ownVine.transform, 31);
				}
			}
			else
			{
				LogDebug($"[Ensure] 原位更新 active={_ownVine.activeSelf}");
				VinePreviewFactory.UpdatePredictionVine(_ownVine, pos, dir, length);
			}
		}

		public static void ClearAll()
		{
			LogDebug("[ClearAll] 清理 _frozen=" + (_frozen.HasValue ? "yes" : "no") + " _ownVine=" + (((Object)(object)_ownVine != (Object)null) ? "alive" : "null"));
			_frozen = null;
			_frozenSince = 0f;
			_nextUpdateAt = 0f;
			_lastThrowForce = -1f;
			DestroyOwnVine();
		}

		private static void DestroyOwnVine()
		{
			if ((Object)(object)_ownVine != (Object)null)
			{
				LogDebug($"[DestroyOwnVine] 销毁 active={_ownVine.activeSelf}");
				VinePreviewFactory.DestroyPredictionVine(_ownVine);
				_ownVine = null;
			}
			_ownVineAssigned = false;
			_vineHiddenFromMain = false;
		}

		private static void SetLayerRecursive(Transform t, int layer)
		{
			if (!((Object)(object)t == (Object)null))
			{
				((Component)t).gameObject.layer = layer;
				for (int i = 0; i < t.childCount; i++)
				{
					SetLayerRecursive(t.GetChild(i), layer);
				}
			}
		}

		private static void LogDebug(string msg)
		{
			if (ModConfig.DebugLog != null && ModConfig.DebugLog.Value)
			{
				ManualLogSource loggerRef = Plugin.LoggerRef;
				if (loggerRef != null)
				{
					loggerRef.LogInfo((object)("[魔豆画中画预览] " + msg));
				}
			}
		}
	}
	internal static class ModConfig
	{
		public const int MaxViewSlots = 4;

		public static ConfigEntry<bool> Enable;

		public static ConfigEntry<float> KeepAfterThrow;

		public static ConfigEntry<bool> MainViewPredictionVine;

		public static ConfigEntry<bool> DebugLog;

		public static ConfigEntry<bool>[] ViewEnabled;

		public static ConfigEntry<float>[] ViewAzimuth;

		public static ConfigEntry<float>[] ViewElevation;

		public static ConfigEntry<float>[] ViewFov;

		public static ConfigEntry<float>[] ViewDistance;

		public static ConfigEntry<int>[] ViewFocus;

		public static ConfigEntry<int>[] ViewCorner;

		public static ConfigEntry<float>[] ViewWidth;

		public static ConfigEntry<bool>[] ViewShowLabel;

		public static ConfigEntry<string>[] ViewLabel;

		public static void Init(ConfigFile config)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Expected O, but got Unknown
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Expected O, but got Unknown
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Expected O, but got Unknown
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Expected O, but got Unknown
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Expected O, but got Unknown
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Expected O, but got Unknown
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Expected O, but got Unknown
			Enable = config.Bind<bool>("通用", "启用", true, "魔豆画中画预览总开关。关闭后不显示任何画中画窗口,也不计算预测。");
			KeepAfterThrow = config.Bind<float>("通用", "抛出后预测保留秒数", 0f, new ConfigDescription("松手抛出魔豆后,预测藤蔓与画中画继续保留的秒数。0 表示抛出后立即关闭(默认)。设为正值可观察魔豆飞向落点的过程。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), Array.Empty<object>()));
			MainViewPredictionVine = config.Bind<bool>("通用", "主视角显示预测藤蔓", false, "当场景中检测不到其它魔豆藤蔓预测 mod(如 MagicBeanVinePrediction)的预测藤蔓时,本 mod 会自建一条预测藤蔓供画中画取景使用。开启后该自建预测藤蔓也显示在主视角;关闭则只在画中画窗口内可见(不影响主视角画面)。");
			DebugLog = config.Bind<bool>("调试", "调试日志", false, "输出详细调试日志。");
			ViewEnabled = new ConfigEntry<bool>[4];
			ViewAzimuth = new ConfigEntry<float>[4];
			ViewElevation = new ConfigEntry<float>[4];
			ViewFov = new ConfigEntry<float>[4];
			ViewDistance = new ConfigEntry<float>[4];
			ViewFocus = new ConfigEntry<int>[4];
			ViewCorner = new ConfigEntry<int>[4];
			ViewWidth = new ConfigEntry<float>[4];
			ViewShowLabel = new ConfigEntry<bool>[4];
			ViewLabel = new ConfigEntry<string>[4];
			float[] array = new float[4] { 0f, 90f, 180f, 0f };
			float[] array2 = new float[4] { 15f, 10f, 0f, -25f };
			int[] array3 = new int[4] { 2, 0, 1, 1 };
			int[] array4 = new int[4] { 0, 1, 2, 3 };
			float[] array5 = new float[4] { 360f, 360f, 320f, 320f };
			float[] array6 = new float[4] { 2f, 0f, 0f, 0f };
			string[] array7 = new string[4] { "顶端侧面", "底端侧面", "中部平视", "底部仰视" };
			for (int i = 0; i < 4; i++)
			{
				string text = $"视角{i + 1}";
				ViewEnabled[i] = config.Bind<bool>(text, "启用", true, "本视角的画中画窗口是否启用。默认 4 个视角全部开启。");
				ViewAzimuth[i] = config.Bind<float>(text, "水平环绕角", array[i], new ConfigDescription("围绕藤蔓的水平环绕角(度,-180 ~ 180)。0 表示相机位于「投掷方向的延长线上、落点的后方」,正值相机向右(顺时针)环绕。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-180f, 180f), Array.Empty<object>()));
				ViewElevation[i] = config.Bind<float>(text, "俯仰角", array2[i], new ConfigDescription("相机俯仰角(度,-30 ~ 90)。0 为贴地平视,30 ~ 45 为常见的侧面俯视,90 为正上方俯视;负值为仰视(相机在藤蔓下方往上看)。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-30f, 90f), Array.Empty<object>()));
				ViewFov[i] = config.Bind<float>(text, "视野角度", 60f, new ConfigDescription("画中画相机视野(度)。数值越小越“拉近放大”。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(20f, 110f), Array.Empty<object>()));
				ViewDistance[i] = config.Bind<float>(text, "相机距离", array6[i], new ConfigDescription("相机与藤蔓(注视点)的距离(米)。0 = 自动:按藤蔓长度与视野自动取景,保证整棵藤蔓完整入画。设置具体数值后使用固定距离(如 2 = 从距藤蔓 2 米处近看)。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
				ViewFocus[i] = config.Bind<int>(text, "视野朝向", array3[i], new ConfigDescription("相机注视点落在魔豆藤蔓的哪个部位:0=底端(落点处) 1=中部 2=顶端。切换后相机自动调整距离,保证整棵藤蔓仍在画面内。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 2), Array.Empty<object>()));
				ViewCorner[i] = config.Bind<int>(text, "窗口位置", array4[i], new ConfigDescription("窗口在屏幕上的位置:0=右下 1=左下 2=右上 3=左上。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 3), Array.Empty<object>()));
				ViewWidth[i] = config.Bind<float>(text, "窗口宽度", array5[i], new ConfigDescription("画中画窗口宽度(像素),高度按 16:9 自动计算。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(96f, 1280f), Array.Empty<object>()));
				ViewShowLabel[i] = config.Bind<bool>(text, "显示视角标签", true, "是否在窗口左上角显示视角名称标签。");
				ViewLabel[i] = config.Bind<string>(text, "视角标签文字", array7[i], "窗口左上角显示的标签文字。");
			}
		}
	}
	internal sealed class PiPManager : MonoBehaviour
	{
		private PiPWindow[] _windows;

		private void Update()
		{
			try
			{
				Tick();
			}
			catch (Exception arg)
			{
				ManualLogSource loggerRef = Plugin.LoggerRef;
				if (loggerRef != null)
				{
					loggerRef.LogError((object)$"[魔豆画中画预览] 画中画更新异常:{arg}");
				}
			}
		}

		private void Tick()
		{
			if (ModConfig.Enable == null || !ModConfig.Enable.Value)
			{
				SetAllVisible(visible: false);
				return;
			}
			if (!VineFrameTarget.TryGetFrameTarget(out var target))
			{
				SetAllVisible(visible: false);
				return;
			}
			EnsureWindows();
			for (int i = 0; i < 4; i++)
			{
				PiPWindow piPWindow = _windows[i];
				if (piPWindow != null)
				{
					if (!ModConfig.ViewEnabled[i].Value)
					{
						piPWindow.SetVisible(visible: false);
						continue;
					}
					piPWindow.UpdateTransform(in target);
					piPWindow.SetVisible(visible: true);
				}
			}
			MaintainMainCameraMask();
		}

		private void EnsureWindows()
		{
			if (_windows == null)
			{
				_windows = new PiPWindow[4];
				for (int i = 0; i < _windows.Length; i++)
				{
					_windows[i] = new PiPWindow(i, ((Component)this).transform);
				}
			}
		}

		private void SetAllVisible(bool visible)
		{
			if (_windows != null)
			{
				for (int i = 0; i < _windows.Length; i++)
				{
					_windows[i]?.SetVisible(visible);
				}
			}
		}

		private static void MaintainMainCameraMask()
		{
			if (BeanPredictionController.UsingOurHiddenVine)
			{
				Camera main = Camera.main;
				if (!((Object)(object)main == (Object)null))
				{
					main.cullingMask &= 0x7FFFFFFF;
				}
			}
		}

		private void OnGUI()
		{
			if (_windows != null)
			{
				for (int i = 0; i < _windows.Length; i++)
				{
					_windows[i]?.Draw();
				}
			}
		}

		private void OnDestroy()
		{
			if (_windows != null)
			{
				for (int i = 0; i < _windows.Length; i++)
				{
					_windows[i]?.Release();
					_windows[i] = null;
				}
				_windows = null;
			}
		}
	}
	internal sealed class PiPWindow
	{
		private const float DrawMargin = 12f;

		private readonly int _slot;

		private readonly Transform _parent;

		private GameObject _camObj;

		private Camera _cam;

		private RenderTexture _rt;

		private int _rtWidth;

		private int _rtHeight;

		private bool _visible;

		private static Type _urpCameraDataType;

		private static bool _urpTypeResolved;

		private static GUIStyle _labelStyle;

		public bool Visible => _visible;

		private float Azimuth => ModConfig.ViewAzimuth[_slot].Value;

		private float Elevation => ModConfig.ViewElevation[_slot].Value;

		private float Fov => ModConfig.ViewFov[_slot].Value;

		private float CameraDistance => ModConfig.ViewDistance[_slot].Value;

		private int Focus => ModConfig.ViewFocus[_slot].Value;

		private int Corner => ModConfig.ViewCorner[_slot].Value;

		private float Width => ModConfig.ViewWidth[_slot].Value;

		private bool ShowLabel => ModConfig.ViewShowLabel[_slot].Value;

		private string LabelText => ModConfig.ViewLabel[_slot].Value;

		public PiPWindow(int slotIndex, Transform parent)
		{
			_slot = slotIndex;
			_parent = parent;
		}

		public void UpdateTransform(in FrameTarget frame)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: 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_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: 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)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: 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_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: 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_02dd: Unknown result type (might be due to invalid IL or missing references)
			EnsureRig();
			Vector3 normalized = ((Vector3)(ref frame.direction)).normalized;
			Vector3 val = frame.referenceHorizontal;
			if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
			{
				val = Vector3.forward;
			}
			val = Vector3.ProjectOnPlane(val, normalized);
			if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
			{
				Vector3 val2 = Vector3.Cross(normalized, Vector3.right);
				val = ((((Vector3)(ref val2)).sqrMagnitude > 1E-06f) ? val2 : Vector3.Cross(normalized, Vector3.forward));
			}
			val = ((Vector3)(ref val)).normalized;
			Vector3 val3 = Vector3.Cross(normalized, val);
			Vector3 normalized2 = ((Vector3)(ref val3)).normalized;
			float num = Focus switch
			{
				0 => 0f, 
				2 => 1f, 
				_ => 0.5f, 
			};
			Vector3 val4 = frame.anchor + normalized * (frame.length * num);
			float num2 = Azimuth * ((float)Math.PI / 180f);
			float num3 = Elevation * ((float)Math.PI / 180f);
			Vector3 val5 = (normalized2 * Mathf.Sin(num2) + val * Mathf.Cos(num2)) * Mathf.Cos(num3) + normalized * Mathf.Sin(num3);
			if (((Vector3)(ref val5)).sqrMagnitude < 1E-06f)
			{
				val5 = normalized;
			}
			val5 = ((Vector3)(ref val5)).normalized;
			float num4 = Mathf.Clamp(Fov, 20f, 110f);
			float num5 = num4 * 0.5f * 0.85f * ((float)Math.PI / 180f);
			float cameraDistance = CameraDistance;
			float num6;
			if (cameraDistance > 0f)
			{
				num6 = Mathf.Clamp(cameraDistance, 1f, 600f);
			}
			else
			{
				float num7 = Mathf.Abs(num - 0.5f) + 0.5f;
				num6 = Mathf.Clamp(frame.length * 1.5f * num7, 4f, 600f);
				for (int i = 0; i < 2; i++)
				{
					Vector3 val6 = val4 + val5 * num6;
					val3 = val4 - val6;
					Vector3 normalized3 = ((Vector3)(ref val3)).normalized;
					val3 = Vector3.Cross(normalized3, normalized);
					float num8 = Mathf.Max(0.25f, ((Vector3)(ref val3)).magnitude);
					num6 = Mathf.Clamp(Mathf.Max(frame.length * num8, Mathf.Clamp(frame.length * 0.45f, 5f, 25f)) * 0.5f * num7 / Mathf.Tan(num5), 2f, 600f);
				}
			}
			Vector3 val7 = val4 + val5 * num6;
			val3 = val4 - val7;
			Vector3 normalized4 = ((Vector3)(ref val3)).normalized;
			Vector3 val8 = ((Mathf.Abs(Vector3.Dot(normalized4, Vector3.up)) > 0.999f) ? val : Vector3.up);
			_camObj.transform.position = val7;
			_camObj.transform.rotation = Quaternion.LookRotation(normalized4, val8);
			_cam.fieldOfView = num4;
		}

		public void SetVisible(bool visible)
		{
			_visible = visible;
			if ((Object)(object)_cam != (Object)null)
			{
				((Behaviour)_cam).enabled = visible;
			}
		}

		private void EnsureRig()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if ((Object)(object)_camObj == (Object)null)
			{
				_camObj = new GameObject($"MagicBeanPiP_Camera_Slot{_slot + 1}");
				_camObj.transform.SetParent(_parent, false);
				((Object)_camObj).hideFlags = (HideFlags)61;
				_cam = _camObj.AddComponent<Camera>();
				((Behaviour)_cam).enabled = false;
				_cam.depth = -50f;
				_cam.clearFlags = (CameraClearFlags)1;
				_cam.nearClipPlane = 0.03f;
				_cam.farClipPlane = 1500f;
				_cam.allowHDR = false;
				_cam.allowMSAA = false;
				_cam.stereoTargetEye = (StereoTargetEyeMask)0;
				int num = LayerMask.NameToLayer("UI");
				_cam.cullingMask = ((num >= 0) ? (~(1 << num)) : (-1));
				EnsureUrpCameraData();
			}
			EnsureRenderTexture();
			_cam.fieldOfView = Mathf.Clamp(Fov, 20f, 110f);
		}

		private void EnsureRenderTexture()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			int num = Mathf.Clamp(Mathf.RoundToInt(Width), 96, 1280);
			int num2 = Mathf.Clamp(Mathf.RoundToInt((float)num * 9f / 16f), 54, 720);
			if ((Object)(object)_rt != (Object)null && _rtWidth == num && _rtHeight == num2)
			{
				return;
			}
			if ((Object)(object)_rt != (Object)null)
			{
				if ((Object)(object)_cam != (Object)null)
				{
					_cam.targetTexture = null;
				}
				_rt.Release();
				Object.Destroy((Object)(object)_rt);
			}
			_rt = new RenderTexture(num, num2, 24, (RenderTextureFormat)7)
			{
				hideFlags = (HideFlags)61
			};
			_rt.Create();
			_rtWidth = num;
			_rtHeight = num2;
			if ((Object)(object)_cam != (Object)null)
			{
				_cam.targetTexture = _rt;
			}
		}

		private void EnsureUrpCameraData()
		{
			Type urpCameraDataType = GetUrpCameraDataType();
			if (urpCameraDataType == null)
			{
				return;
			}
			try
			{
				if ((Object)(object)_camObj.GetComponent(urpCameraDataType) == (Object)null)
				{
					_camObj.AddComponent(urpCameraDataType);
				}
			}
			catch
			{
			}
		}

		private static Type GetUrpCameraDataType()
		{
			if (_urpTypeResolved)
			{
				return _urpCameraDataType;
			}
			_urpTypeResolved = true;
			try
			{
				_urpCameraDataType = Type.GetType("UnityEngine.Rendering.Universal.UniversalAdditionalCameraData, Unity.RenderPipelines.Universal.Runtime");
				if (_urpCameraDataType == null)
				{
					Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
					for (int i = 0; i < assemblies.Length; i++)
					{
						Type type = assemblies[i].GetType("UnityEngine.Rendering.Universal.UniversalAdditionalCameraData", throwOnError: false);
						if (type != null)
						{
							_urpCameraDataType = type;
							break;
						}
					}
				}
			}
			catch
			{
				_urpCameraDataType = null;
			}
			return _urpCameraDataType;
		}

		public void Draw()
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if (!_visible || (Object)(object)_rt == (Object)null)
			{
				return;
			}
			try
			{
				float num = Mathf.Clamp(Width, 96f, Mathf.Max(96f, (float)Screen.width - 16f));
				float num2 = num * 9f / 16f;
				bool num3 = Corner == 2 || Corner == 3;
				bool flag = Corner == 1 || Corner == 3;
				float num4 = (num3 ? 12f : ((float)Screen.width - 12f - num));
				float num5 = (flag ? 12f : ((float)Screen.height - 12f - num2));
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(num4, num5, num, num2);
				Color color = GUI.color;
				GUI.color = new Color(0f, 0f, 0f, 0.85f);
				GUI.DrawTexture(new Rect(((Rect)(ref val)).x - 2f, ((Rect)(ref val)).y - 2f, ((Rect)(ref val)).width + 4f, ((Rect)(ref val)).height + 4f), (Texture)(object)Texture2D.whiteTexture);
				GUI.color = Color.white;
				GUI.DrawTexture(val, (Texture)(object)_rt, (ScaleMode)0, false);
				if (ShowLabel)
				{
					DrawLabel(val);
				}
				GUI.color = color;
			}
			catch
			{
			}
		}

		private void DrawLabel(Rect windowRect)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_003d: 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_005f: 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)
			//IL_0090: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			EnsureLabelStyle();
			GUIContent val = new GUIContent(string.IsNullOrEmpty(LabelText) ? $"视角{_slot + 1}" : LabelText);
			Vector2 val2 = _labelStyle.CalcSize(val);
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(((Rect)(ref windowRect)).x + 4f, ((Rect)(ref windowRect)).y + 4f, val2.x + 10f, val2.y + 4f);
			GUI.color = new Color(0f, 0f, 0f, 0.7f);
			GUI.DrawTexture(val3, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = Color.white;
			GUI.Label(new Rect(((Rect)(ref val3)).x + 5f, ((Rect)(ref val3)).y + 2f, val2.x, val2.y), val, _labelStyle);
		}

		private static void EnsureLabelStyle()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (_labelStyle == null)
			{
				_labelStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 13
				};
				_labelStyle.normal.textColor = Color.white;
				_labelStyle.font = CreateChineseFont();
			}
		}

		private static Font CreateChineseFont()
		{
			try
			{
				Font val = Font.CreateDynamicFontFromOSFont(new string[6] { "Microsoft YaHei", "微软雅黑", "SimHei", "黑体", "Noto Sans CJK SC", "Arial" }, 13);
				if ((Object)(object)val != (Object)null)
				{
					((Object)val).hideFlags = (HideFlags)61;
				}
				return val;
			}
			catch
			{
				return null;
			}
		}

		public void Release()
		{
			if ((Object)(object)_cam != (Object)null)
			{
				_cam.targetTexture = null;
			}
			if ((Object)(object)_rt != (Object)null)
			{
				_rt.Release();
				Object.Destroy((Object)(object)_rt);
				_rt = null;
			}
			if ((Object)(object)_camObj != (Object)null)
			{
				Object.Destroy((Object)(object)_camObj);
				_camObj = null;
				_cam = null;
			}
		}
	}
	[BepInPlugin("com.fufu.magicbeanpip", "魔豆画中画预览", "0.5.5")]
	internal sealed class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		private GameObject _host;

		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource LoggerRef { get; private set; }

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			Instance = this;
			LoggerRef = ((BaseUnityPlugin)this).Logger;
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("com.fufu.magicbeanpip");
			try
			{
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[魔豆画中画预览] v0.5.5 已加载,Harmony 补丁应用成功。");
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"[魔豆画中画预览] Harmony 补丁应用失败:{arg}");
			}
			_host = new GameObject("MagicBeanPiP_Host");
			Object.DontDestroyOnLoad((Object)(object)_host);
			((Object)_host).hideFlags = (HideFlags)61;
			_host.AddComponent<PiPManager>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[魔豆画中画预览] 画中画管理器已挂载。");
		}

		private void OnDestroy()
		{
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
			}
		}
	}
	internal static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.fufu.magicbeanpip";

		public const string PLUGIN_NAME = "魔豆画中画预览";

		public const string PLUGIN_VERSION = "0.5.5";
	}
	public struct BeanPredictionData
	{
		public Vector3 basePos;

		public Vector3 direction;

		public float length;

		public Vector3 referenceHorizontal;

		public float timestamp;
	}
	public struct FrameTarget
	{
		public Vector3 anchor;

		public Vector3 direction;

		public float length;

		public Vector3 center;

		public Vector3 referenceHorizontal;
	}
	internal static class VineFrameTarget
	{
		public static bool TryGetFrameTarget(out FrameTarget target)
		{
			//IL_004c: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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)
			//IL_005f: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//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_00af: Unknown result type (might be due to invalid IL or missing references)
			target = default(FrameTarget);
			if (TryGetActualVine(out target))
			{
				return true;
			}
			BeanPredictionData? frozenPrediction = BeanPredictionController.FrozenPrediction;
			if (frozenPrediction.HasValue)
			{
				BeanPredictionData value = frozenPrediction.Value;
				Vector3 val = ((((Vector3)(ref value.direction)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref value.direction)).normalized : Vector3.up);
				target.anchor = value.basePos;
				target.direction = val;
				target.length = Mathf.Max(0.5f, value.length);
				target.referenceHorizontal = MakeReference(value.referenceHorizontal, val);
				target.center = target.anchor + val * target.length * 0.5f;
				return true;
			}
			if (TryGetPrethrowVine(out target))
			{
				return true;
			}
			return false;
		}

		private static bool TryGetPrethrowVine(out FrameTarget target)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			target = default(FrameTarget);
			GameObject val = GameObject.Find("MagicBeanVinePrediction");
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Vector3 val2 = val.transform.up;
			if (((Vector3)(ref val2)).sqrMagnitude < 1E-06f)
			{
				val2 = Vector3.up;
			}
			val2 = ((Vector3)(ref val2)).normalized;
			MagicBeanVine component = val.GetComponent<MagicBeanVine>();
			float num = (((Object)(object)component != (Object)null) ? component.maxLength : 8f);
			target.anchor = val.transform.position;
			target.direction = val2;
			target.length = Mathf.Max(0.5f, num);
			target.referenceHorizontal = MakeReference(PlayerLookHorizontal(), val2);
			target.center = target.anchor + val2 * target.length * 0.5f;
			return true;
		}

		private static bool TryGetActualVine(out FrameTarget target)
		{
			//IL_005f: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			target = default(FrameTarget);
			GameObject val = GameObject.Find("ActualVinePrediction");
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Transform val2 = null;
			MagicBeanVine componentInChildren = val.GetComponentInChildren<MagicBeanVine>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				val2 = ((Component)componentInChildren).transform;
			}
			else if (val.transform.childCount > 0)
			{
				val2 = val.transform.GetChild(0);
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			Vector3 val3 = val2.up;
			if (((Vector3)(ref val3)).sqrMagnitude < 1E-06f)
			{
				val3 = Vector3.up;
			}
			val3 = ((Vector3)(ref val3)).normalized;
			float num = (((Object)(object)componentInChildren != (Object)null) ? componentInChildren.maxLength : 8f);
			target.anchor = val2.position;
			target.direction = val3;
			target.length = Mathf.Max(0.5f, num);
			target.referenceHorizontal = MakeReference(PlayerLookHorizontal(), val3);
			target.center = target.anchor + val3 * target.length * 0.5f;
			return true;
		}

		private static Vector3 PlayerLookHorizontal()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter != (Object)null)
			{
				Vector3 val = Vector3.ProjectOnPlane(BeanPrediction.ResolveAimDirection(localCharacter), Vector3.up);
				if (((Vector3)(ref val)).sqrMagnitude > 1E-06f)
				{
					return ((Vector3)(ref val)).normalized;
				}
			}
			return Vector3.forward;
		}

		private static Vector3 MakeReference(Vector3 reference, Vector3 up)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.ProjectOnPlane(reference, up);
			if (((Vector3)(ref val)).sqrMagnitude > 1E-06f)
			{
				return ((Vector3)(ref val)).normalized;
			}
			Vector3 val2 = Vector3.Cross(up, Vector3.right);
			if (((Vector3)(ref val2)).sqrMagnitude < 1E-06f)
			{
				val2 = Vector3.Cross(up, Vector3.forward);
			}
			return ((Vector3)(ref val2)).normalized;
		}
	}
	internal static class VinePreviewFactory
	{
		private const string StalkPath = "VineOrigin/Stalk";

		private const float StandableDeviation = 45f;

		private static readonly Color WalkableTint = new Color(1f, 0.4f, 0.55f, 1f);

		private static readonly Color NonWalkableTint = new Color(0.4f, 0.4f, 0.4f, 1f);

		private static GameObject _root;

		private static int _createCount;

		public static GameObject Root
		{
			get
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)_root == (Object)null)
				{
					_root = new GameObject("MagicBeanPiP_VinePreviewRoot");
					Object.DontDestroyOnLoad((Object)(object)_root);
					((Object)_root).hideFlags = (HideFlags)61;
				}
				return _root;
			}
		}

		public static GameObject CreatePredictionVine(MagicBean bean, Vector3 pos, Vector3 dir, float length)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: 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_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)bean == (Object)null || (Object)(object)bean.plantPrefab == (Object)null)
			{
				Log("[Create] bean 或 plantPrefab 为空,放弃创建");
				return null;
			}
			_createCount++;
			Log($"[Create #{_createCount}] 开始创建预测藤蔓 pos={pos} dir={dir} length={length}");
			GameObject val;
			try
			{
				val = Object.Instantiate<GameObject>(((Component)bean.plantPrefab).gameObject, Root.transform);
				Log($"[Create #{_createCount}] 实例化成功,active={val.activeSelf} activeInHierarchy={val.activeInHierarchy}");
			}
			catch (Exception arg)
			{
				ManualLogSource loggerRef = Plugin.LoggerRef;
				if (loggerRef != null)
				{
					loggerRef.LogError((object)$"[魔豆画中画预览] 实例化预测藤蔓失败:{arg}");
				}
				return null;
			}
			Component[] componentsInChildren = val.GetComponentsInChildren<Component>();
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] == (Object)null)
				{
					stringBuilder.Append("[null]");
				}
				else
				{
					stringBuilder.Append(((object)componentsInChildren[i]).GetType().Name);
				}
				if (i < componentsInChildren.Length - 1)
				{
					stringBuilder.Append(", ");
				}
			}
			Log($"[Create #{_createCount}] 组件列表: {stringBuilder}");
			((Object)val).name = "MagicBeanPiPVinePrediction";
			val.transform.SetPositionAndRotation(pos, Quaternion.identity);
			val.transform.up = dir;
			ShapeVine(val, length);
			StripExtras(val);
			ApplyPreviewColor(val, dir);
			PurgePhysics(val);
			if ((Object)(object)val == (Object)null)
			{
				LogError($"[Create #{_createCount}] 创建流程结束后 preview 已被销毁!");
				return null;
			}
			MagicBeanVine component = val.GetComponent<MagicBeanVine>();
			Log(string.Format("[Create #{0}] 创建完成,active={1},MagicBeanVine={2},", _createCount, val.activeSelf, ((Object)(object)component == (Object)null) ? "null" : ((Behaviour)component).enabled.ToString()) + $"childCount={val.transform.childCount},pos={val.transform.position}");
			if ((Object)(object)component != (Object)null && (Object)(object)component.vineOriginTransform != (Object)null)
			{
				Log($"[Create #{_createCount}] vineOriginTransform.localScale={component.vineOriginTransform.localScale},active={((Component)component.vineOriginTransform).gameObject.activeSelf}");
			}
			else
			{
				LogError($"[Create #{_createCount}] vineOriginTransform 为空!");
			}
			return val;
		}

		public static void UpdatePredictionVine(GameObject preview, Vector3 pos, Vector3 dir, float length)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)preview == (Object)null)
			{
				LogError("[Update] preview 为空,跳过更新");
				return;
			}
			Log($"[Update] 开始更新 preview(active={preview.activeSelf}) pos={pos} length={length}");
			if ((Object)(object)preview == (Object)null)
			{
				LogError("[Update] preview 已被销毁(fake null),应重建");
				return;
			}
			preview.transform.SetPositionAndRotation(pos, Quaternion.identity);
			if (((Vector3)(ref dir)).sqrMagnitude > 1E-06f)
			{
				preview.transform.up = ((Vector3)(ref dir)).normalized;
			}
			ShapeVine(preview, length);
			ApplyPreviewColor(preview, dir);
		}

		public static void DestroyPredictionVine(GameObject preview)
		{
			if ((Object)(object)preview != (Object)null)
			{
				Log($"[Destroy] 销毁预测藤蔓 active={preview.activeSelf}");
				Object.Destroy((Object)(object)preview);
			}
		}

		private static void ShapeVine(GameObject preview, float length)
		{
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			MagicBeanVine component = preview.GetComponent<MagicBeanVine>();
			if ((Object)(object)component == (Object)null)
			{
				LogError("[Shape] MagicBeanVine 组件为空");
				return;
			}
			float num = Mathf.Max(0.01f, length);
			Log(string.Format("[Shape] 开始成型 length={0}→{1},vine.enabled={2},vineOriginTransform={3}", length, num, ((Behaviour)component).enabled, ((Object)(object)component.vineOriginTransform == (Object)null) ? "null" : ((Object)component.vineOriginTransform).name));
			component.growingSpeed = 1f;
			bool flag = false;
			try
			{
				component.RPC_GrowVine(num, float.MinValue, default(PhotonMessageInfo));
				flag = true;
				Log("[Shape] RPC_GrowVine 调用成功");
			}
			catch (Exception arg)
			{
				LogError($"[Shape] RPC_GrowVine 调用异常:{arg}");
			}
			if (!flag && (Object)(object)component.vineOriginTransform != (Object)null)
			{
				float num2 = Mathf.Max(0.01f, component.maxWidth);
				component.vineOriginTransform.localScale = new Vector3(num2, num, num2);
				Log($"[Shape] 退回直接设缩放 localScale=({num2}, {num}, {num2})");
			}
			if ((Object)(object)component.vineOriginTransform != (Object)null)
			{
				Log($"[Shape] 成型后 localScale={component.vineOriginTransform.localScale},active={((Component)component.vineOriginTransform).gameObject.activeSelf}");
			}
			component.growingSpeed = 0f;
			((Behaviour)component).enabled = false;
			Animator[] componentsInChildren = preview.GetComponentsInChildren<Animator>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Behaviour)componentsInChildren[i]).enabled = false;
			}
			Log($"[Shape] 最终 vine.enabled={((Behaviour)component).enabled},preview.active={preview.activeSelf},preview==null={(Object)(object)preview == (Object)null}");
		}

		private static void StripExtras(GameObject preview)
		{
			PhotonCleanupHelper component = preview.GetComponent<PhotonCleanupHelper>();
			if ((Object)(object)component != (Object)null)
			{
				Log("[Strip] 销毁 PhotonCleanupHelper");
				Object.Destroy((Object)(object)component);
			}
			for (int num = preview.transform.childCount - 1; num >= 0; num--)
			{
				Transform child = preview.transform.GetChild(num);
				string name = ((Object)child).name;
				if (name.StartsWith("VFX") || name.StartsWith("SFX"))
				{
					Log("[Strip] 销毁子物体 " + name);
					Object.Destroy((Object)(object)((Component)child).gameObject);
				}
			}
			Log($"[Strip] 完成,剩余 childCount={preview.transform.childCount}");
		}

		private static void ApplyPreviewColor(GameObject preview, Vector3 growthDir)
		{
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_0108: 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)
			//IL_0111: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			Transform val = preview.transform.Find("VineOrigin/Stalk");
			if ((Object)(object)val == (Object)null)
			{
				StringBuilder stringBuilder = new StringBuilder();
				for (int i = 0; i < preview.transform.childCount; i++)
				{
					Transform child = preview.transform.GetChild(i);
					stringBuilder.Append(((Object)child).name).Append("/").Append((child.childCount > 0) ? ((Object)child.GetChild(0)).name : "[no child]");
					if (i < preview.transform.childCount - 1)
					{
						stringBuilder.Append(", ");
					}
				}
				LogError(string.Format("[Color] 找不到 {0},子物体结构: {1}", "VineOrigin/Stalk", stringBuilder));
				return;
			}
			Renderer component = ((Component)val).GetComponent<Renderer>();
			if ((Object)(object)component == (Object)null)
			{
				LogError("[Color] VineOrigin/Stalk 上无 Renderer");
				return;
			}
			float num = Mathf.Abs(90f - Vector3.Angle(growthDir, Vector3.up));
			bool flag = num < 45f;
			Color val2 = (flag ? WalkableTint : NonWalkableTint);
			MaterialPropertyBlock val3 = new MaterialPropertyBlock();
			component.GetPropertyBlock(val3);
			val3.SetColor("_Color", val2);
			val3.SetColor("_BaseColor", val2);
			component.SetPropertyBlock(val3);
			Log($"[Color] 完成 deviation={num} standable={flag} tint={val2},shader={((Object)component.material.shader).name}");
		}

		private static void PurgePhysics(GameObject preview)
		{
			Collider[] componentsInChildren = preview.GetComponentsInChildren<Collider>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
			Rigidbody[] componentsInChildren2 = preview.GetComponentsInChildren<Rigidbody>();
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren2[i]);
			}
		}

		private static void Log(string msg)
		{
			if (ModConfig.DebugLog != null && ModConfig.DebugLog.Value)
			{
				ManualLogSource loggerRef = Plugin.LoggerRef;
				if (loggerRef != null)
				{
					loggerRef.LogInfo((object)("[魔豆画中画预览] " + msg));
				}
			}
		}

		private static void LogError(string msg)
		{
			ManualLogSource loggerRef = Plugin.LoggerRef;
			if (loggerRef != null)
			{
				loggerRef.LogError((object)("[魔豆画中画预览] " + msg));
			}
		}
	}
}