Decompiled source of Sandevistan v0.2.1

plugins/Sandevistan.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;
using cn_xc.TimeControl;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Sandevistan;

[BepInPlugin("cn_xc.Sandevistan", "Sandevistan", "0.2.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	internal static Plugin Instance;

	private static ConfigEntry<bool> _enabled;

	private static ConfigEntry<string> _toggleKey;

	private const float SlowScale = 0.25f;

	private const float Duration = 60f;

	private const float Volume = 0.8f;

	private const bool HostOnly = true;

	private static bool _active;

	private static float _endAt;

	private static float _remaining;

	private static int _healthSnapshot = -1;

	private static int _useCount;

	private const byte EvRequest = 97;

	private const byte EvReply = 98;

	private static float _cooldownUntil;

	private static bool _localFx;

	internal static float _fxUntil;

	internal static bool ApplyingCost;

	internal static bool AllowDeathFromOveruse;

	private static bool _immunityUsed;

	private static string _lastScene = "";

	private static float _rescueGraceUntil;

	private static float _rescueInvincibleUntil;

	private static MethodInfo _muiRegister;

	private static bool _muiReady;

	internal static float _lastBlockLog;

	private static QuotePopup _popup;

	private static ScreenEdgeOverlay _edge;

	private static SandevistanAura _aura;

	private static object _audio;

	private static object _clip;

	internal static bool ActiveNow => _active;

	internal static bool RescueInvincible => Time.unscaledTime < _rescueInvincibleUntil;

	private void Awake()
	{
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Instance = this;
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("常规", "启用", true, "总开关。");
		_toggleKey = ((BaseUnityPlugin)this).Config.Bind<string>("常规", "快捷键", "F", "按这个键切换(Unity KeyCode,例如 F / Q / LeftAlt)。");
		TryInitMoreUIPanel();
		try
		{
			PhotonNetwork.NetworkingClient.EventReceived += OnPhotonEvent;
		}
		catch
		{
		}
		_popup = ((Component)this).gameObject.AddComponent<QuotePopup>();
		_edge = ((Component)this).gameObject.AddComponent<ScreenEdgeOverlay>();
		_aura = ((Component)this).gameObject.AddComponent<SandevistanAura>();
		LoadSound();
		try
		{
			new Harmony("cn_xc.Sandevistan").PatchAll(typeof(Plugin).Assembly);
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("补丁挂载失败: " + ex.Message));
		}
		Log.LogInfo((object)"Sandevistan 0.2.1 已加载(依赖 TimeControlLib,全房间减速 + 自动关闭)");
	}

	private void Update()
	{
		//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_023c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!_enabled.Value)
			{
				return;
			}
			try
			{
				Scene activeScene = SceneManager.GetActiveScene();
				string name = ((Scene)(ref activeScene)).name;
				if (name != _lastScene)
				{
					_lastScene = name;
					_immunityUsed = false;
				}
			}
			catch
			{
			}
			if (!PhotonNetwork.IsMasterClient && _localFx && (TimeControl.CurrentScale > 0.95f || Time.unscaledTime > _fxUntil))
			{
				_localFx = false;
				ApplyLocalEffects(on: false);
				try
				{
					Instance?.PlaySoundPublic(on: false);
				}
				catch
				{
				}
			}
			if (!_immunityUsed && GetLocalHealth() == 0)
			{
				try
				{
					PlayerAvatar instance = PlayerAvatar.instance;
					if ((Object)(object)instance != (Object)null)
					{
						FieldInfo field = ((object)instance).GetType().GetField("deadSet", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						bool flag = default(bool);
						int num;
						if (field != null)
						{
							object value = field.GetValue(instance);
							if (value is bool)
							{
								flag = (bool)value;
								num = 1;
							}
							else
							{
								num = 0;
							}
						}
						else
						{
							num = 0;
						}
						if (((uint)num & (flag ? 1u : 0u)) == 0)
						{
							TryRescueFromLethal(instance);
						}
					}
				}
				catch
				{
				}
			}
			if (_active && IsPlayerDead())
			{
				Log.LogInfo((object)"玩家已死亡,斯安威斯坦自动关闭");
				SetActive(on: false);
			}
			if (_active && !IsInNormalLevel())
			{
				Log.LogInfo((object)"已离开关卡,斯安威斯坦自动关闭");
				SetActive(on: false);
			}
			try
			{
				PlayerAvatar instance2 = PlayerAvatar.instance;
				if ((Object)(object)instance2 == (Object)null)
				{
					_useCount = 0;
				}
				else
				{
					FieldInfo field2 = ((object)instance2).GetType().GetField("playerHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field2 != null)
					{
						field2.GetValue(instance2);
					}
					FieldInfo field3 = ((object)instance2).GetType().GetField("deadSet", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					bool flag2 = default(bool);
					int num2;
					if (field3 != null)
					{
						object value = field3.GetValue(instance2);
						if (value is bool)
						{
							flag2 = (bool)value;
							num2 = 1;
						}
						else
						{
							num2 = 0;
						}
					}
					else
					{
						num2 = 0;
					}
					if (((uint)num2 & (flag2 ? 1u : 0u)) != 0)
					{
						_useCount = 0;
					}
				}
			}
			catch
			{
			}
			if (_active)
			{
				_remaining -= Time.unscaledDeltaTime;
				if (_remaining <= 0.01f)
				{
					Log.LogInfo((object)("时间到,自动关闭(剩余 " + _remaining.ToString("F2") + "s)"));
					SetActive(on: false);
				}
			}
			if (Enum.TryParse<KeyCode>(_toggleKey.Value, ignoreCase: true, out KeyCode result) && Input.GetKeyDown(result))
			{
				if (!_active && IsPlayerDead())
				{
					Log.LogInfo((object)"玩家已死亡,无法开启斯安威斯坦");
				}
				else if (!_active && !IsInNormalLevel())
				{
					Log.LogInfo((object)"当前不在关卡内(卡车/商店/菜单),斯安威斯坦不可用");
				}
				else if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
				{
					SendRequest();
				}
				else
				{
					SetActive(!_active);
				}
			}
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("Update 异常: " + ex.Message));
		}
	}

	private static void TryInitMoreUIPanel()
	{
		try
		{
			Type type = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				type = assemblies[i].GetType("MoreUIPanel.Plugin", throwOnError: false);
				if (type != null)
				{
					break;
				}
			}
			if (!(type == null))
			{
				_muiRegister = type.GetMethod("RegisterLine", new Type[2]
				{
					typeof(string),
					typeof(Func<string>)
				});
				if (!(_muiRegister == null))
				{
					_muiRegister.Invoke(null, new object[2]
					{
						"sandevistan.status",
						new Func<string>(BuildPanelLine)
					});
					_muiReady = true;
					Log.LogInfo((object)"已把状态注册到 MoreUIPanel");
				}
			}
		}
		catch (Exception ex)
		{
			Verbose("接入 MoreUIPanel 失败: " + ex.Message);
		}
	}

	private static string BuildPanelLine()
	{
		try
		{
			if (!IsInNormalLevel())
			{
				return string.Empty;
			}
			string text = (_active ? ("<color=#05D9E8>开启中 " + Mathf.Max(0f, _remaining).ToString("F0") + "s</color>") : ((!(Time.unscaledTime < _cooldownUntil)) ? "<color=#9AA0A6>待命</color>" : ("<color=#FCEE0A>冷却 " + ((Time.unscaledTime < _cooldownUntil) ? Mathf.Max(0f, _cooldownUntil - Time.unscaledTime).ToString("F0") : "0") + "s</color>")));
			string text2 = "<color=#FF59BF>下次第 " + (_useCount + 1) + " 次</color>";
			string text3 = (_immunityUsed ? "<color=#9AA0A6>免疫已用</color>" : "<color=#00F099>免疫可用</color>");
			return "斯安威斯坦:" + text + "  " + text2 + "  " + text3;
		}
		catch
		{
			return string.Empty;
		}
	}

	internal static void Verbose(string msg)
	{
		try
		{
			ManualLogSource log = Log;
			if (log != null)
			{
				log.LogInfo((object)msg);
			}
		}
		catch
		{
		}
	}

	private void SendRequest()
	{
		//IL_0000: 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)
		//IL_001f: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_0035: Expected O, but got Unknown
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0042: Expected O, but got Unknown
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Hashtable val = new Hashtable();
			((Dictionary<object, object>)val).Add((object)"actor", (object)PhotonNetwork.LocalPlayer.ActorNumber);
			((Dictionary<object, object>)val).Add((object)"name", (object)PhotonNetwork.LocalPlayer.NickName);
			Hashtable val2 = val;
			RaiseEventOptions val3 = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)2
			};
			SendOptions val4 = default(SendOptions);
			((SendOptions)(ref val4)).Reliability = true;
			PhotonNetwork.RaiseEvent((byte)97, (object)val2, val3, val4);
			Log.LogInfo((object)"已向房主发送开启请求…");
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("发送请求失败: " + ex.Message));
		}
	}

	private static void SendReply(int targetActor, bool ok, string reason)
	{
		//IL_0000: 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)
		//IL_0016: Expected O, but got Unknown
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0023: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		//IL_0041: 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)
		try
		{
			Hashtable val = new Hashtable();
			((Dictionary<object, object>)val).Add((object)"ok", (object)ok);
			((Dictionary<object, object>)val).Add((object)"reason", (object)reason);
			Hashtable val2 = val;
			RaiseEventOptions val3 = new RaiseEventOptions();
			val3.TargetActors = new int[1] { targetActor };
			RaiseEventOptions val4 = val3;
			SendOptions val5 = default(SendOptions);
			((SendOptions)(ref val5)).Reliability = true;
			PhotonNetwork.RaiseEvent((byte)98, (object)val2, val4, val5);
		}
		catch
		{
		}
	}

	private void OnPhotonEvent(EventData data)
	{
		try
		{
			if (data == null)
			{
				return;
			}
			int actor;
			object obj2;
			if (data.Code == 97 && PhotonNetwork.IsMasterClient)
			{
				actor = Convert.ToInt32(data[byte.MaxValue]);
				if (data.Parameters.ContainsKey((byte)1))
				{
					object obj = data[(byte)1];
					Hashtable val = (Hashtable)((obj is Hashtable) ? obj : null);
					if (val != null)
					{
						obj2 = (val[(object)"name"] as string) ?? "?";
						goto IL_0068;
					}
				}
				obj2 = "?";
				goto IL_0068;
			}
			if (data.Code != 98 || PhotonNetwork.IsMasterClient)
			{
				return;
			}
			bool flag = default(bool);
			int num;
			if (data.Parameters.ContainsKey((byte)1))
			{
				object obj3 = data[(byte)1];
				Hashtable val2 = (Hashtable)((obj3 is Hashtable) ? obj3 : null);
				if (val2 != null)
				{
					object obj4 = val2[(object)"ok"];
					if (obj4 is bool)
					{
						flag = (bool)obj4;
						num = 1;
					}
					else
					{
						num = 0;
					}
					goto IL_00d1;
				}
			}
			num = 0;
			goto IL_00d1;
			IL_0115:
			object obj5;
			string text = (string)obj5;
			int num2;
			if (num2 != 0)
			{
				Log.LogInfo((object)"房主已批准开启");
				_localFx = true;
				_fxUntil = Time.unscaledTime + 62f;
				ApplyLocalEffects(on: true);
				PlaySound(on: true);
			}
			else
			{
				Log.LogInfo((object)("房主拒绝开启:" + text));
			}
			return;
			IL_00d1:
			num2 = num & (flag ? 1 : 0);
			if (data.Parameters.ContainsKey((byte)1))
			{
				object obj6 = data[(byte)1];
				Hashtable val3 = (Hashtable)((obj6 is Hashtable) ? obj6 : null);
				if (val3 != null)
				{
					obj5 = (val3[(object)"reason"] as string) ?? "";
					goto IL_0115;
				}
			}
			obj5 = "";
			goto IL_0115;
			IL_0068:
			string name = (string)obj2;
			DecideRequest(actor, name);
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("事件处理失败: " + ex.Message));
		}
	}

	private void DecideRequest(int actor, string name)
	{
		try
		{
			if (_active)
			{
				SendReply(actor, ok: false, "已有玩家开启中");
				Log.LogInfo((object)("拒绝 " + name + ":已有玩家开启中"));
			}
			else if (!IsInNormalLevel())
			{
				SendReply(actor, ok: false, "不在关卡内");
			}
			else if (Time.unscaledTime < _cooldownUntil)
			{
				SendReply(actor, ok: false, "冷却中");
			}
			else
			{
				Log.LogInfo((object)("批准 " + name + " 的开启请求(房主广播减速)"));
				SendReply(actor, ok: true, "");
				SetActive(on: true, free: true);
			}
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("裁决失败: " + ex.Message));
		}
	}

	private static void ApplyLocalEffects(bool on)
	{
		try
		{
			_edge?.SetActive(on);
		}
		catch
		{
		}
		try
		{
			_aura?.SetActive(on);
		}
		catch
		{
		}
		try
		{
			if (on)
			{
				_popup?.Show("「以我残躯化烈火」", "With this broken body of mine, I burn.", 2f);
			}
		}
		catch
		{
		}
	}

	private void SetActive(bool on, bool free = false)
	{
		if (on && !free)
		{
			_useCount++;
			if (!ApplyUsePenalty(_useCount))
			{
				return;
			}
		}
		if (on && _active)
		{
			_remaining = 60f;
			if (_healthSnapshot <= 0)
			{
				_healthSnapshot = GetLocalHealth();
			}
			return;
		}
		_active = on;
		if (!on)
		{
			_remaining = 0f;
			_healthSnapshot = -1;
		}
		if (on)
		{
			_endAt = Time.unscaledTime + 60f;
			_remaining = 60f;
			_healthSnapshot = GetLocalHealth();
			TimeControl.Slow(0.25f, 60f, true);
			try
			{
				_edge?.SetActive(on: true);
			}
			catch
			{
			}
			try
			{
				_aura?.SetActive(on: true);
			}
			catch
			{
			}
			PlaySound(on: true);
			Log.LogInfo((object)("斯安威斯坦:开启(" + 60f + " 秒)"));
		}
		else
		{
			TimeControl.Restore(true);
			try
			{
				_edge?.SetActive(on: false);
			}
			catch
			{
			}
			try
			{
				_aura?.SetActive(on: false);
			}
			catch
			{
			}
			PlaySound(on: false);
			_cooldownUntil = (PhotonNetwork.InRoom ? (Time.unscaledTime + 10f) : 0f);
			Log.LogInfo((object)"斯安威斯坦:关闭");
		}
	}

	private bool ApplyUsePenalty(int count)
	{
		try
		{
			PlayerAvatar instance = PlayerAvatar.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return true;
			}
			FieldInfo field = ((object)instance).GetType().GetField("playerHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object obj = ((field != null) ? field.GetValue(instance) : null);
			if (obj == null)
			{
				return true;
			}
			Type type = obj.GetType();
			MethodInfo method = type.GetMethod("Hurt", new Type[4]
			{
				typeof(int),
				typeof(bool),
				typeof(int),
				typeof(bool)
			});
			ApplyingCost = true;
			MethodInfo method2 = type.GetMethod("Death", Type.EmptyTypes);
			int num = GetInt(obj, "health", 100);
			GetInt(obj, "maxHealth", 100);
			switch (count)
			{
			case 1:
				Log.LogInfo((object)"第 1 次开启:无代价");
				return true;
			case 2:
			{
				int num2 = Mathf.Max(1, Mathf.RoundToInt((float)num * 0.25f));
				method?.Invoke(obj, new object[4] { num2, false, -1, false });
				int num3 = GetInt(obj, "health", num);
				Log.LogInfo((object)((num3 >= num) ? "第 2 次开启:扣血被游戏忽略(不在关卡内 / 无敌帧)" : ("第 2 次开启:扣除当前血量 25%(" + num2 + "),剩 " + num3)));
				return true;
			}
			case 3:
			{
				int num6 = Mathf.Max(1, Mathf.RoundToInt((float)num * 0.5f));
				method?.Invoke(obj, new object[4] { num6, false, -1, false });
				int num7 = GetInt(obj, "health", num);
				Log.LogInfo((object)((num7 >= num) ? "第 3 次开启:扣血被游戏忽略(不在关卡内 / 无敌帧)" : ("第 3 次开启:扣除当前血量 50%(" + num6 + "),剩 " + num7)));
				return true;
			}
			case 4:
			{
				int num4 = Mathf.Max(0, num - 1);
				if (num4 <= 0)
				{
					Log.LogInfo((object)"第 4 次开启:血量已 ≤1,无需扣血");
					return true;
				}
				method?.Invoke(obj, new object[4] { num4, false, -1, false });
				int num5 = GetInt(obj, "health", num);
				Log.LogInfo((object)((num5 >= num) ? "第 4 次开启:扣血被游戏忽略(不在关卡内 / 无敌帧)" : ("第 4 次开启:只保留 1 点血(扣 " + num4 + ",剩 " + num5 + ")")));
				try
				{
					_popup?.Show("「以我残躯化烈火」", "With this broken body of mine, I burn.", 2f);
				}
				catch
				{
				}
				_rescueGraceUntil = Time.unscaledTime + 2.5f;
				return true;
			}
			default:
			{
				MethodInfo method3 = ((object)instance).GetType().GetMethod("PlayerDeath", new Type[1] { typeof(int) });
				AllowDeathFromOveruse = true;
				try
				{
					if (method3 != null)
					{
						method3.Invoke(instance, new object[1] { -1 });
					}
					else
					{
						method2?.Invoke(obj, null);
					}
				}
				finally
				{
					AllowDeathFromOveruse = false;
				}
				_useCount = 0;
				Log.LogWarning((object)("第 " + count + " 次开启:直接死亡"));
				return false;
			}
			}
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("惩罚失败: " + ex.Message));
			return true;
		}
	}

	internal static bool TryRescueFromLethal(PlayerAvatar avatar)
	{
		try
		{
			if (_immunityUsed)
			{
				Log.LogInfo((object)"免疫未触发:本关已经用过一次");
				return false;
			}
			if (!IsInNormalLevel())
			{
				Log.LogInfo((object)"免疫未触发:当前不在关卡内");
				return false;
			}
			_immunityUsed = true;
			FieldInfo field = ((object)avatar).GetType().GetField("playerHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object obj = ((field != null) ? field.GetValue(avatar) : null);
			if (obj == null)
			{
				return false;
			}
			Type type = obj.GetType();
			int num = GetInt(obj, "maxHealth", 100);
			type.GetMethod("Hurt", new Type[4]
			{
				typeof(int),
				typeof(bool),
				typeof(int),
				typeof(bool)
			});
			FieldInfo field2 = type.GetField("health", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field2 != null)
			{
				field2.SetValue(obj, 1);
			}
			Log.LogInfo((object)("致命免疫:救援后血量 = " + GetInt(obj, "health", -1)));
			_rescueGraceUntil = Time.unscaledTime + 2.5f;
			try
			{
				FieldInfo field3 = obj.GetType().GetField("photonView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				PhotonView val = (PhotonView)((field3 != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val != (Object)null && PhotonNetwork.InRoom)
				{
					val.RPC("UpdateHealthRPC", (RpcTarget)0, new object[4] { 1, num, true, false });
				}
			}
			catch
			{
			}
			Log.LogWarning((object)"致命一击免疫:保留 1 点血,自动开启斯安威斯坦(本关仅一次)");
			try
			{
				_popup?.Show("「以我残躯化烈火」", "With this broken body of mine, I burn.", 2f);
			}
			catch
			{
			}
			_rescueGraceUntil = Time.unscaledTime + 2.5f;
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				ApplyLocalEffects(on: true);
			}
			else if (!ActiveNow)
			{
				try
				{
					Instance?.SetActive(on: true, free: true);
				}
				catch
				{
				}
			}
			_rescueInvincibleUntil = Time.unscaledTime + 2.5f;
			return true;
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("免疫救援失败: " + ex.Message));
			return false;
		}
	}

	private static bool IsPlayerDead()
	{
		try
		{
			if (Time.unscaledTime < _rescueGraceUntil)
			{
				return false;
			}
			PlayerAvatar instance = PlayerAvatar.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			FieldInfo field = ((object)instance).GetType().GetField("deadSet", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			bool flag = default(bool);
			int num;
			if (field != null)
			{
				object value = field.GetValue(instance);
				if (value is bool)
				{
					flag = (bool)value;
					num = 1;
				}
				else
				{
					num = 0;
				}
			}
			else
			{
				num = 0;
			}
			if (((uint)num & (flag ? 1u : 0u)) != 0)
			{
				return true;
			}
			FieldInfo field2 = ((object)instance).GetType().GetField("playerHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object obj = ((field2 != null) ? field2.GetValue(instance) : null);
			return obj != null && GetInt(obj, "health", 100) <= 0;
		}
		catch
		{
			return false;
		}
	}

	private static bool IsInNormalLevel()
	{
		try
		{
			return SemiFunc.RunIsLevel();
		}
		catch
		{
			return false;
		}
	}

	internal static int GetLocalHealth()
	{
		try
		{
			PlayerAvatar instance = PlayerAvatar.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return -1;
			}
			FieldInfo field = ((object)instance).GetType().GetField("playerHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object obj = ((field != null) ? field.GetValue(instance) : null);
			return (obj == null) ? (-1) : GetInt(obj, "health", -1);
		}
		catch
		{
			return -1;
		}
	}

	internal static int GetInt(object obj, string field, int fallback)
	{
		try
		{
			FieldInfo field2 = obj.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			return (field2 != null) ? Convert.ToInt32(field2.GetValue(obj)) : fallback;
		}
		catch
		{
			return fallback;
		}
	}

	private void LoadSound()
	{
		try
		{
			string? path = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? ".";
			string text = "Sandevistan.wav";
			string path2 = Path.Combine(path, text);
			Log.LogInfo((object)("音乐文件: " + text));
			if (!File.Exists(path2))
			{
				Log.LogWarning((object)("没找到 " + text));
				return;
			}
			_clip = LoadWav(path2);
			if (_clip != null)
			{
				Type type = Type.GetType("UnityEngine.AudioSource, UnityEngine.AudioModule");
				if (!(type == null))
				{
					_audio = ((Component)this).gameObject.AddComponent(type);
					type.GetProperty("clip")?.SetValue(_audio, _clip);
					type.GetProperty("loop")?.SetValue(_audio, true);
					type.GetProperty("spatialBlend")?.SetValue(_audio, 0f);
					type.GetProperty("playOnAwake")?.SetValue(_audio, false);
					Log.LogInfo((object)("音效已加载: " + GetClipLength(_clip).ToString("F1") + "s"));
				}
			}
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("音效加载失败: " + ex.Message));
		}
	}

	internal void PlaySoundPublic(bool on)
	{
		PlaySound(on);
	}

	private void PlaySound(bool on)
	{
		try
		{
			if (_audio != null)
			{
				Type type = _audio.GetType();
				if (on)
				{
					type.GetProperty("volume")?.SetValue(_audio, 0.8f);
					type.GetMethod("Play", Type.EmptyTypes)?.Invoke(_audio, null);
				}
				else
				{
					type.GetMethod("Stop", Type.EmptyTypes)?.Invoke(_audio, null);
				}
			}
		}
		catch
		{
		}
	}

	private static float GetClipLength(object clip)
	{
		try
		{
			return (clip != null) ? ((float)(clip.GetType().GetProperty("length")?.GetValue(clip) ?? ((object)0f))) : 0f;
		}
		catch
		{
			return 0f;
		}
	}

	private static object LoadWav(string path)
	{
		byte[] array = File.ReadAllBytes(path);
		if (array.Length < 44)
		{
			return null;
		}
		int num = 1;
		int num2 = 44100;
		int num3 = 16;
		int num4 = -1;
		int num5 = 0;
		int num6;
		for (int i = 12; i + 8 <= array.Length; i += 8 + num6 + num6 % 2)
		{
			string text = Encoding.ASCII.GetString(array, i, 4);
			num6 = BitConverter.ToInt32(array, i + 4);
			if (text == "fmt ")
			{
				num = BitConverter.ToInt16(array, i + 10);
				num2 = BitConverter.ToInt32(array, i + 12);
				num3 = BitConverter.ToInt16(array, i + 22);
			}
			else if (text == "data")
			{
				num4 = i + 8;
				num5 = num6;
				break;
			}
		}
		if (num4 < 0 || num5 <= 0)
		{
			return null;
		}
		int num7 = num3 / 8;
		int num8 = num5 / num7;
		float[] array2 = new float[num8];
		switch (num3)
		{
		case 16:
		{
			for (int k = 0; k < num8; k++)
			{
				array2[k] = (float)BitConverter.ToInt16(array, num4 + k * 2) / 32768f;
			}
			break;
		}
		case 8:
		{
			for (int j = 0; j < num8; j++)
			{
				array2[j] = (float)(array[num4 + j] - 128) / 128f;
			}
			break;
		}
		default:
			return null;
		}
		Type type = Type.GetType("UnityEngine.AudioClip, UnityEngine.AudioModule");
		if (type == null)
		{
			return null;
		}
		MethodInfo method = type.GetMethod("Create", new Type[5]
		{
			typeof(string),
			typeof(int),
			typeof(int),
			typeof(int),
			typeof(bool)
		});
		if (method == null)
		{
			return null;
		}
		object obj = method.Invoke(null, new object[5]
		{
			"Sandevistan",
			num8 / num,
			num,
			num2,
			false
		});
		type.GetMethod("SetData", new Type[2]
		{
			typeof(float[]),
			typeof(int)
		})?.Invoke(obj, new object[2] { array2, 0 });
		return obj;
	}
}
internal sealed class QuotePopup : MonoBehaviour
{
	private string _title;

	private string _subtitle;

	private float _until;

	private Font _font;

	private GUIStyle _titleStyle;

	private GUIStyle _subStyle;

	private static readonly Color NeonYellow = new Color(1f, 0.93f, 0.04f);

	private static readonly Color NeonPink = new Color(1f, 0.16f, 0.43f);

	private static readonly Color NeonCyan = new Color(0.02f, 0.85f, 0.91f);

	private static readonly Color PanelBlack = new Color(0.02f, 0.01f, 0.06f);

	internal void Show(string title, string subtitle, float seconds)
	{
		_title = title;
		_subtitle = subtitle;
		_until = Time.unscaledTime + Mathf.Max(0.5f, seconds);
	}

	private void EnsureStyles()
	{
		//IL_0055: 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_0062: 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_007c: Expected O, but got Unknown
		//IL_0087: 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_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_00a7: Expected O, but got Unknown
		if (_titleStyle == null)
		{
			try
			{
				_font = Font.CreateDynamicFontFromOSFont(new string[5] { "Microsoft YaHei", "Microsoft YaHei UI", "SimHei", "Segoe UI", "Arial Unicode MS" }, 32);
			}
			catch
			{
			}
			_titleStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 34,
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)1,
				wordWrap = true
			};
			_subStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 20,
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)2
			};
			if ((Object)(object)_font != (Object)null)
			{
				_titleStyle.font = _font;
				_subStyle.font = _font;
			}
		}
	}

	private static void Fill(Rect r, Color c)
	{
		//IL_0000: 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)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		Color color = GUI.color;
		GUI.color = c;
		GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture);
		GUI.color = color;
	}

	private void OnGUI()
	{
		//IL_00ab: 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)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		if (_title == null || Time.unscaledTime > _until)
		{
			return;
		}
		try
		{
			EnsureStyles();
			float num = Mathf.Clamp01((_until - Time.unscaledTime) / 0.35f);
			float num2 = Mathf.Min((float)Screen.width * 0.72f, 820f);
			float num3 = 132f;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((float)Screen.width - num2) * 0.5f, ((float)Screen.height - num3) * 0.5f, num2, num3);
			Fill(new Rect(((Rect)(ref r)).x - 2f, ((Rect)(ref r)).y - 2f, ((Rect)(ref r)).width + 4f, ((Rect)(ref r)).height + 4f), new Color(NeonCyan.r, NeonCyan.g, NeonCyan.b, 0.22f * num));
			Fill(r, new Color(PanelBlack.r, PanelBlack.g, PanelBlack.b, 0.78f * num));
			float num4 = 2f;
			Color c = default(Color);
			((Color)(ref c))..ctor(NeonCyan.r, NeonCyan.g, NeonCyan.b, 0.95f * num);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, num4), c);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - num4, ((Rect)(ref r)).width, num4), c);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, num4, ((Rect)(ref r)).height), c);
			Fill(new Rect(((Rect)(ref r)).xMax - num4, ((Rect)(ref r)).y, num4, ((Rect)(ref r)).height), c);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref r)).x + 18f, ((Rect)(ref r)).y + 16f, ((Rect)(ref r)).width - 36f, 46f);
			GUI.color = new Color(NeonPink.r, NeonPink.g, NeonPink.b, 0.85f * num);
			GUI.Label(new Rect(((Rect)(ref val)).x - 2f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), _title, _titleStyle);
			GUI.color = new Color(NeonCyan.r, NeonCyan.g, NeonCyan.b, 0.85f * num);
			GUI.Label(new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y - 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), _title, _titleStyle);
			GUI.color = new Color(NeonYellow.r, NeonYellow.g, NeonYellow.b, num);
			GUI.Label(val, _title, _titleStyle);
			if (!string.IsNullOrEmpty(_subtitle))
			{
				GUI.color = new Color(NeonPink.r, NeonPink.g, NeonPink.b, num);
				GUI.Label(new Rect(((Rect)(ref r)).x + 18f, ((Rect)(ref r)).y + 78f, ((Rect)(ref r)).width - 36f, 34f), _subtitle, _subStyle);
			}
			GUI.color = Color.white;
		}
		catch
		{
		}
	}
}
internal sealed class ScreenEdgeOverlay : MonoBehaviour
{
	private bool _on;

	private float _alpha;

	private float _enterAt = -99f;

	private float _nextGlitch;

	private float _glitchEnd;

	private float _flicker = 1f;

	private float _nextFlicker;

	private const float EnterDuration = 0.45f;

	private static readonly Color[] Palette = (Color[])(object)new Color[7]
	{
		new Color(0.02f, 0.85f, 0.91f),
		new Color(1f, 0.16f, 0.43f),
		new Color(1f, 0.93f, 0.04f),
		new Color(0.42f, 0.05f, 0.68f),
		new Color(1f, 0.42f, 0f),
		new Color(0f, 0.94f, 0.6f),
		new Color(0.55f, 0.2f, 1f)
	};

	internal void SetActive(bool on)
	{
		_on = on;
		if (on)
		{
			_enterAt = Time.unscaledTime;
		}
	}

	private static void Fill(Rect r, Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		if (!(c.a <= 0.004f) && !(((Rect)(ref r)).width <= 0f) && !(((Rect)(ref r)).height <= 0f))
		{
			Color color = GUI.color;
			GUI.color = c;
			GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color;
		}
	}

	private static float Hash(int x, int y, int t)
	{
		int num = (x * 73856093) ^ (y * 19349663) ^ (t * 83492791);
		return (float)Mathf.Abs((num ^ (num >> 13)) * 1274126177 % 1000) / 1000f;
	}

	private void Update()
	{
		float num = (_on ? 1f : 0f);
		_alpha = Mathf.MoveTowards(_alpha, num, Time.unscaledDeltaTime * 3f);
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime >= _nextFlicker)
		{
			_nextFlicker = unscaledTime + Random.Range(0.03f, 0.18f);
			_flicker = ((Random.value < 0.18f) ? Random.Range(0.35f, 0.65f) : Random.Range(0.88f, 1f));
		}
		if (unscaledTime >= _nextGlitch)
		{
			_nextGlitch = unscaledTime + Random.Range(0.6f, 1.4f);
			_glitchEnd = unscaledTime + Random.Range(0.25f, 0.55f);
		}
	}

	private void OnGUI()
	{
		//IL_0092: 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_00e2: 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_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: 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_01df: 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_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: 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_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_0489: Unknown result type (might be due to invalid IL or missing references)
		//IL_048e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0495: Unknown result type (might be due to invalid IL or missing references)
		//IL_049c: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04df: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0352: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		if (_alpha <= 0.002f)
		{
			return;
		}
		try
		{
			float unscaledTime = Time.unscaledTime;
			float num = _alpha * _flicker;
			int width = Screen.width;
			int height = Screen.height;
			float num2 = Mathf.Clamp01((unscaledTime - _enterAt) / 0.45f);
			float num3 = 1f - Mathf.Pow(1f - num2, 3f);
			float num4 = (float)Mathf.Min(width, height) * Mathf.Lerp(0.26f, 0.15f, num3);
			int tb = (int)(unscaledTime * 8f);
			DrawEdge(new Rect(0f, 0f, (float)width, num4), num * 0.85f, horizontal: true, fromStart: true, unscaledTime + 0f);
			DrawEdge(new Rect(0f, (float)height - num4, (float)width, num4), num * 0.85f, horizontal: true, fromStart: false, unscaledTime + 0.25f);
			DrawEdge(new Rect(0f, 0f, num4, (float)height), num * 0.75f, horizontal: false, fromStart: true, unscaledTime + 0.5f);
			DrawEdge(new Rect((float)width - num4, 0f, num4, (float)height), num * 0.75f, horizontal: false, fromStart: false, unscaledTime + 0.75f);
			float num5 = Mathf.Repeat(unscaledTime * 24f, 4f);
			Color c = default(Color);
			((Color)(ref c))..ctor(0f, 0f, 0f, 0.14f * num);
			for (float num6 = 0f - num5; num6 < (float)height; num6 += 4f)
			{
				Fill(new Rect(0f, num6, (float)width, 1f), c);
			}
			float num7 = Mathf.Repeat(unscaledTime, 2.5f);
			if (num7 < 0.8f)
			{
				float num8 = Mathf.Lerp(-20f, (float)height + 20f, num7 / 0.8f);
				Color val = Cycle(unscaledTime);
				Fill(new Rect(0f, num8, (float)width, 6f), new Color(val.r, val.g, val.b, 0.28f * num));
				Fill(new Rect(0f, num8 + 6f, (float)width, 10f), new Color(val.r, val.g, val.b, 0.12f * num));
			}
			if (unscaledTime < _glitchEnd)
			{
				for (int i = 0; i < 5; i++)
				{
					float num9 = Random.Range(2f, 14f);
					float num10 = Random.Range(0f, Mathf.Max(1f, (float)height - num9));
					float num11 = Random.Range((float)width * 0.15f, (float)width * 0.85f);
					float num12 = Random.Range(0f, Mathf.Max(1f, (float)width - num11));
					Color val2 = Cycle(unscaledTime + Random.Range(0f, 1.5f));
					Fill(new Rect(num12, num10, num11, num9), new Color(val2.r, val2.g, val2.b, Random.Range(0.06f, 0.2f) * num));
				}
				for (int j = 0; j < 3; j++)
				{
					float num13 = Random.Range(0f, (float)height);
					float num14 = Random.Range(-24f, 24f);
					Color val3 = Palette[2];
					Fill(new Rect(num14, num13, (float)width, 2f), new Color(val3.r, val3.g, val3.b, 0.12f * num));
				}
			}
			if (num2 < 1f)
			{
				float num15 = Mathf.Pow(1f - num2, 2f);
				Fill(new Rect(0f, 0f, (float)width, (float)height), new Color(1f, 1f, 1f, 0.45f * num15));
				for (int k = 0; k < 3; k++)
				{
					float num16 = Random.Range(0f, (float)height);
					float num17 = Random.Range(4f, 26f);
					Color val4 = Palette[Random.Range(0, Palette.Length)];
					Fill(new Rect(Random.Range(-30f, 30f), num16, (float)width, num17), new Color(val4.r, val4.g, val4.b, 0.25f * num15));
				}
				float num18 = (float)Mathf.Min(width, height) * (0.5f - num2 * 0.5f);
				Color val5 = Palette[0];
				Fill(new Rect(0f, num18, (float)width, 3f), new Color(val5.r, val5.g, val5.b, 0.5f * num15));
				Fill(new Rect(0f, (float)height - num18 - 3f, (float)width, 3f), new Color(val5.r, val5.g, val5.b, 0.5f * num15));
			}
			float num19 = (float)Mathf.Min(width, height) * 0.08f;
			float bs = Mathf.Max(6f, num19 / 6f);
			DrawCorner(0f, 0f, 1f, 1f, bs, num19, num, tb);
			DrawCorner(width, 0f, -1f, 1f, bs, num19, num, tb);
			DrawCorner(0f, height, 1f, -1f, bs, num19, num, tb);
			DrawCorner(width, height, -1f, -1f, bs, num19, num, tb);
		}
		catch
		{
		}
	}

	private static Color Cycle(float t)
	{
		//IL_0017: 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_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_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_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)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: 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)
		Color[] array = (Color[])(object)new Color[4]
		{
			new Color(0.02f, 0.85f, 0.91f),
			new Color(1f, 0.93f, 0.04f),
			new Color(0.55f, 0.2f, 1f),
			new Color(1f, 0.35f, 0.75f)
		};
		float num = Mathf.Repeat(t * 0.35f, (float)array.Length);
		int num2 = (int)num;
		float num3 = num - (float)num2;
		return Color.Lerp(array[num2 % array.Length], array[(num2 + 1) % array.Length], num3);
	}

	private static void DrawEdge(Rect area, float maxAlpha, bool horizontal, bool fromStart, float phase)
	{
		//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_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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_0103: 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_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: 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_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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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)
		Color val = Cycle(phase);
		Color val2 = Cycle(phase + 0.9f);
		float num = (horizontal ? ((Rect)(ref area)).height : ((Rect)(ref area)).width);
		int num2 = 28;
		float num3 = num / (float)num2;
		for (int i = 0; i <= num2; i++)
		{
			float num4 = (float)i / (float)num2;
			float num5 = maxAlpha * Mathf.Pow(1f - num4, 2.4f);
			if (!(num5 <= 0.005f))
			{
				Color val3 = Color.Lerp(val, val2, num4);
				float num6 = (float)i * num3;
				if (horizontal)
				{
					float num7 = (fromStart ? (((Rect)(ref area)).y + num6) : (((Rect)(ref area)).yMax - num6 - num3));
					Fill(new Rect(((Rect)(ref area)).x, num7, ((Rect)(ref area)).width, num3 + 1f), new Color(val3.r, val3.g, val3.b, num5));
				}
				else
				{
					Fill(new Rect(fromStart ? (((Rect)(ref area)).x + num6) : (((Rect)(ref area)).xMax - num6 - num3), ((Rect)(ref area)).y, num3 + 1f, ((Rect)(ref area)).height), new Color(val3.r, val3.g, val3.b, num5));
				}
			}
		}
	}

	private static void DrawCorner(float cx, float cy, float dx, float dy, float bs, float len, float a, int tb)
	{
		//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_007c: 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_0087: 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_0094: 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_00cc: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < 3; i++)
		{
			float num = a * (1f - (float)i / 3f) * 0.95f;
			Color val = Cycle(Time.unscaledTime + (float)i * 0.2f);
			float num2 = cx + dx * (float)i * bs;
			float num3 = cy + dy * (float)i * bs;
			float num4 = ((dx > 0f) ? num2 : (num2 - bs));
			float num5 = ((dy > 0f) ? num3 : (num3 - bs));
			Fill(new Rect(num4, num5, bs + 1f, bs + 1f), new Color(val.r, val.g, val.b, num));
			if (i == 0)
			{
				float num6 = ((dx > 0f) ? cx : (cx - len));
				float num7 = ((dy > 0f) ? cy : (cy - bs));
				Fill(new Rect(num6, num7, len, bs), new Color(val.r, val.g, val.b, num * 0.85f));
			}
		}
	}
}
internal sealed class SandevistanAura : MonoBehaviour
{
	private bool _on;

	private float _alpha;

	private readonly Dictionary<int, TrailRenderer> _trails = new Dictionary<int, TrailRenderer>();

	private readonly Dictionary<int, Vector3> _lastPos = new Dictionary<int, Vector3>();

	internal void SetActive(bool on)
	{
		_on = on;
	}

	private void Update()
	{
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		try
		{
			flag = TimeControl.CurrentScale < 0.95f;
		}
		catch
		{
		}
		float num = ((_on || flag) ? 1f : 0f);
		_alpha = Mathf.MoveTowards(_alpha, num, Time.unscaledDeltaTime * 3f);
		if (_alpha <= 0.01f)
		{
			foreach (TrailRenderer value3 in _trails.Values)
			{
				if ((Object)(object)value3 != (Object)null)
				{
					((Component)value3).gameObject.SetActive(false);
				}
			}
			return;
		}
		try
		{
			PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
			foreach (PlayerAvatar val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					int instanceID = ((Object)val).GetInstanceID();
					if (!_trails.TryGetValue(instanceID, out var value) || (Object)(object)value == (Object)null)
					{
						value = CreateTrail(((Component)val).transform);
						_trails[instanceID] = value;
					}
					((Component)value).gameObject.SetActive(true);
					Vector3 position = ((Component)val).transform.position;
					float num2 = 0f;
					if (_lastPos.TryGetValue(instanceID, out var value2) && Time.unscaledDeltaTime > 0.0001f)
					{
						Vector3 val2 = position - value2;
						num2 = ((Vector3)(ref val2)).magnitude / Time.unscaledDeltaTime;
					}
					_lastPos[instanceID] = position;
					float num3 = Mathf.Clamp01(num2 / 6f);
					value.widthMultiplier = Mathf.Lerp(0.02f, 0.55f, num3) * _alpha;
					value.time = Mathf.Lerp(0.28f, 1f, num3);
				}
			}
		}
		catch
		{
		}
	}

	private static TrailRenderer CreateTrail(Transform player)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_008a: 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_0099: 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)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: 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_0108: 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_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_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		GameObject val = new GameObject("Sandevistan_Trail");
		val.transform.SetParent(player, false);
		TrailRenderer val2 = val.AddComponent<TrailRenderer>();
		val2.time = 0.8f;
		val2.minVertexDistance = 0.08f;
		val2.widthMultiplier = 0.35f;
		val2.numCapVertices = 4;
		val2.alignment = (LineAlignment)0;
		Shader val3 = Shader.Find("Sprites/Default");
		if ((Object)(object)val3 != (Object)null)
		{
			((Renderer)val2).material = new Material(val3);
		}
		Gradient val4 = new Gradient();
		val4.colorKeys = (GradientColorKey[])(object)new GradientColorKey[4]
		{
			new GradientColorKey(new Color(0.02f, 0.85f, 0.91f), 0f),
			new GradientColorKey(new Color(1f, 0.93f, 0.04f), 0.35f),
			new GradientColorKey(new Color(0.55f, 0.2f, 1f), 0.7f),
			new GradientColorKey(new Color(1f, 0.35f, 0.75f), 1f)
		};
		val4.alphaKeys = (GradientAlphaKey[])(object)new GradientAlphaKey[4]
		{
			new GradientAlphaKey(0.55f, 0f),
			new GradientAlphaKey(0.35f, 0.4f),
			new GradientAlphaKey(0.12f, 0.75f),
			new GradientAlphaKey(0f, 1f)
		};
		val2.colorGradient = val4;
		return val2;
	}
}
[HarmonyPatch(typeof(PlayerHealth), "Hurt", new Type[]
{
	typeof(int),
	typeof(bool),
	typeof(int),
	typeof(bool)
})]
internal static class PatchHurtInvincible
{
	private static bool Prefix(PlayerHealth __instance, int damage)
	{
		try
		{
			if (Plugin.ApplyingCost)
			{
				return true;
			}
			if (Plugin.RescueInvincible)
			{
				if (Time.unscaledTime - Plugin._lastBlockLog > 1f)
				{
					Plugin._lastBlockLog = Time.unscaledTime;
					Plugin.Log.LogInfo((object)("救援无敌:已跳过 " + damage + " 点伤害"));
				}
				return false;
			}
			if ((Object)(object)__instance == (Object)null || damage <= 0)
			{
				return true;
			}
			FieldInfo field = ((object)__instance).GetType().GetField("playerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			PlayerAvatar val = (PlayerAvatar)((field != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null || (Object)(object)PlayerAvatar.instance != (Object)(object)val)
			{
				return true;
			}
			if (Plugin.GetInt(__instance, "health", 100) - damage > 0)
			{
				return true;
			}
			if (Plugin.TryRescueFromLethal(val))
			{
				return false;
			}
		}
		catch
		{
		}
		return true;
	}
}
[HarmonyPatch(typeof(PlayerAvatar), "PlayerDeath", new Type[] { typeof(int) })]
internal static class PatchPlayerDeathImmunityGuardInvincible
{
	private static bool Prefix(PlayerAvatar __instance)
	{
		try
		{
			if (Plugin.AllowDeathFromOveruse)
			{
				return true;
			}
			if (Plugin.RescueInvincible)
			{
				return false;
			}
		}
		catch
		{
		}
		return true;
	}
}
[HarmonyPatch(typeof(PlayerHealth), "Death", new Type[] { })]
internal static class PatchHealthDeathImmunity
{
	private static bool Prefix(PlayerHealth __instance)
	{
		try
		{
			if (Plugin.AllowDeathFromOveruse)
			{
				return true;
			}
			FieldInfo field = ((object)__instance).GetType().GetField("playerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			PlayerAvatar val = (PlayerAvatar)((field != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null || (Object)(object)PlayerAvatar.instance != (Object)(object)val)
			{
				return true;
			}
			if (Plugin.TryRescueFromLethal(val))
			{
				return false;
			}
		}
		catch
		{
		}
		return true;
	}
}
[HarmonyPatch(typeof(PlayerAvatar), "PlayerDeath", new Type[] { typeof(int) })]
internal static class PatchPlayerDeathImmunity
{
	private static bool Prefix(PlayerAvatar __instance)
	{
		try
		{
			if (Plugin.AllowDeathFromOveruse)
			{
				return true;
			}
			if ((Object)(object)__instance == (Object)null)
			{
				return true;
			}
			if ((Object)(object)PlayerAvatar.instance != (Object)(object)__instance)
			{
				return true;
			}
			if (Plugin.TryRescueFromLethal(__instance))
			{
				return false;
			}
		}
		catch
		{
		}
		return true;
	}
}