Decompiled source of ReviveZones v0.1.0

plugins/ReviveZones.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ReviveZones")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Host-only instant revive when a death head is in an extraction point, the spawn truck or a cart.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("ReviveZones")]
[assembly: AssemblyTitle("ReviveZones")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 ReviveZones
{
	[BepInPlugin("com.yanyan.repo.revivezones", "Revive Zones 复活区域", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.yanyan.repo.revivezones";

		public const string Version = "0.1.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<string> Language;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> InExtraction;

		internal static ConfigEntry<bool> InTruck;

		internal static ConfigEntry<bool> InCart;

		internal static ConfigEntry<int> ReviveHealth;

		private readonly Dictionary<PlayerAvatar, float> _cooldown = new Dictionary<PlayerAvatar, float>();

		private PhysGrabCart[] _carts = (PhysGrabCart[])(object)new PhysGrabCart[0];

		private float _cartScanAt;

		internal static readonly string[] LangCodes = new string[2] { "zh", "en" };

		internal static readonly string[] LangNames = new string[2] { "中文", "English" };

		private static int _lang;

		private static readonly Dictionary<PlayerAvatar, float> Pending = new Dictionary<PlayerAvatar, float>();

		private static readonly List<PlayerAvatar> Done = new List<PlayerAvatar>();

		private void Awake()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Language = ((BaseUnityPlugin)this).Config.Bind<string>("1. General / 常规", "Language / 语言", "zh", new ConfigDescription("界面语言 zh / en(仅影响本配置文件的显示,复活逻辑与此无关)", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "zh", "en" }), Array.Empty<object>()));
			_lang = Array.IndexOf(LangCodes, Language.Value);
			if (_lang < 0)
			{
				_lang = 0;
			}
			Language.SettingChanged += delegate
			{
				_lang = Array.IndexOf(LangCodes, Language.Value);
				if (_lang < 0)
				{
					_lang = 0;
				}
			};
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. General / 常规", "Enabled / 启用", true, new ConfigDescription("总开关,只有房主设置有效。 / Master switch; only the host's setting applies.", (AcceptableValueBase)null, Array.Empty<object>()));
			ReviveHealth = ((BaseUnityPlugin)this).Config.Bind<int>("1. General / 常规", "Revive HP / 复活血量", 50, new ConfigDescription("复活后的血量,超过上限按上限算。 / HP after revive, capped by max HP.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000), Array.Empty<object>()));
			InExtraction = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Zones / 区域", "Extraction / 提交点内复活", true, new ConfigDescription("死亡头颅进入提交点范围就立刻复活。 / Revive instantly when the death head enters an extraction point.", (AcceptableValueBase)null, Array.Empty<object>()));
			InTruck = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Zones / 区域", "Spawn Truck / 出生点卡车内复活", true, new ConfigDescription("死亡头颅进入出生点卡车就立刻复活,不用等所有提交点完成。 / Revive instantly in the spawn truck, no need to clear all extraction points.", (AcceptableValueBase)null, Array.Empty<object>()));
			InCart = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Zones / 区域", "Cart / 推车内复活", true, new ConfigDescription("死亡头颅放进推车里就立刻复活。 / Revive instantly when the death head is placed in any push cart.", (AcceptableValueBase)null, Array.Empty<object>()));
			Log.LogInfo((object)"Revive Zones 复活区域 0.1.0 loaded");
		}

		private void Update()
		{
			if (!Enabled.Value || !Object.op_Implicit((Object)(object)GameDirector.instance) || !SemiFunc.IsMasterClientOrSingleplayer() || !SemiFunc.RunIsLevel())
			{
				return;
			}
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (Object.op_Implicit((Object)(object)player) && player.deadSet && Object.op_Implicit((Object)(object)player.playerDeathHead) && player.playerDeathHead.triggered && (!_cooldown.TryGetValue(player, out var value) || !(Time.time < value)) && InZone(player.playerDeathHead))
				{
					_cooldown[player] = Time.time + 1f;
					ReviveNow(player);
				}
			}
		}

		private static bool InZone(PlayerDeathHead head)
		{
			RoomVolumeCheck roomVolumeCheck = head.roomVolumeCheck;
			if (Object.op_Implicit((Object)(object)roomVolumeCheck))
			{
				if (InExtraction.Value && (roomVolumeCheck.inExtractionPoint || head.inExtractionPoint))
				{
					return true;
				}
				if (InTruck.Value && roomVolumeCheck.inTruck)
				{
					return true;
				}
			}
			return false;
		}

		private void LateUpdate()
		{
			if (!Enabled.Value || !InCart.Value || !Object.op_Implicit((Object)(object)GameDirector.instance) || !SemiFunc.IsMasterClientOrSingleplayer() || !SemiFunc.RunIsLevel())
			{
				return;
			}
			if (Time.time >= _cartScanAt)
			{
				_cartScanAt = Time.time + 1f;
				_carts = Object.FindObjectsByType<PhysGrabCart>((FindObjectsSortMode)0);
			}
			if (_carts.Length == 0)
			{
				return;
			}
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (Object.op_Implicit((Object)(object)player) && player.deadSet && Object.op_Implicit((Object)(object)player.playerDeathHead) && player.playerDeathHead.triggered && (!_cooldown.TryGetValue(player, out var value) || !(Time.time < value)) && InAnyCart(player.playerDeathHead))
				{
					_cooldown[player] = Time.time + 1f;
					ReviveNow(player);
				}
			}
		}

		private bool InAnyCart(PlayerDeathHead head)
		{
			//IL_0020: 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_0025: 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_0085: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00d5: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (Object.op_Implicit((Object)(object)head.physGrabObject) ? head.physGrabObject.centerPoint : ((Component)head).transform.position);
			PhysGrabCart[] carts = _carts;
			foreach (PhysGrabCart val2 in carts)
			{
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.inCart))
				{
					if (Object.op_Implicit((Object)(object)head.physGrabObject) && val2.itemsInCart.Contains(head.physGrabObject))
					{
						return true;
					}
					Vector3 val3 = Quaternion.Inverse(val2.inCart.rotation) * (val - val2.inCart.position);
					Vector3 val4 = val2.inCart.localScale / 2f;
					if (Mathf.Abs(val3.x) <= val4.x && Mathf.Abs(val3.y) <= val4.y && Mathf.Abs(val3.z) <= val4.z)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static void ReviveNow(PlayerAvatar p)
		{
			p.Revive(false);
			Pending[p] = Time.time + 5f;
		}

		private void FixedUpdate()
		{
			if (Pending.Count == 0)
			{
				return;
			}
			Done.Clear();
			foreach (KeyValuePair<PlayerAvatar, float> item in Pending)
			{
				PlayerAvatar key = item.Key;
				if (!Object.op_Implicit((Object)(object)key) || Time.time > item.Value)
				{
					Done.Add(key);
				}
				else if (!key.deadSet && !key.isDisabled && Object.op_Implicit((Object)(object)key.playerHealth))
				{
					int num = ReviveHealth.Value - 1;
					if (num > 0)
					{
						key.playerHealth.HealOther(num, false);
					}
					Done.Add(key);
				}
			}
			foreach (PlayerAvatar item2 in Done)
			{
				Pending.Remove(item2);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}