Decompiled source of SummonStatue v1.0.0

SummonStatue.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SummonStatue")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+86207bbc108145a9068ee74c2c4a3426bfb235fe")]
[assembly: AssemblyProduct("SummonStatue")]
[assembly: AssemblyTitle("SummonStatue")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SummonStatue;

[BepInPlugin("t0y9n.peak.summonstatue", "SummonStatue", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	internal const string Guid = "t0y9n.peak.summonstatue";

	private const float LiftAbovePlayer = 1.5f;

	private const float SpreadRadius = 0.75f;

	private const float GroundSearch = 4f;

	private ConfigEntry<bool> summonEnabled;

	private ConfigEntry<KeyCode> summonKey;

	private void Awake()
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Invalid comparison between Unknown and I4
		//IL_005d: 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_0068: Expected O, but got Unknown
		//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)
		summonEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Revive dead friends next to you with the summon key while you carry an Ancient Idol.");
		summonKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "SummonKey", (KeyCode)290, "Key that calls on the ancient statue and revives every dead friend next to you. Works only while you carry an Ancient Idol.");
		if ((((Object)((Component)this).gameObject).hideFlags & 0x3D) == 61)
		{
			GameObject val = new GameObject("SummonStatue key");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<KeyReader>().Owner = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SummonStatue: the key is read on a persistent GameObject.");
		}
		else
		{
			((Component)this).gameObject.AddComponent<KeyReader>().Owner = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SummonStatue: the key is read on the plugin GameObject.");
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("SummonStatue 1.0.0 loaded. Key: " + ((object)summonKey.Value/*cast due to .constrained prefix*/).ToString()));
	}

	internal void OnFrame()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (!summonEnabled.Value || !Input.GetKeyDown(summonKey.Value))
		{
			return;
		}
		try
		{
			Summon();
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)$"SummonStatue: {arg}");
		}
	}

	private static bool CarriesIdol(Character self)
	{
		if (IsIdol(self.data.currentItem))
		{
			return true;
		}
		Player player = self.player;
		if ((Object)(object)player == (Object)null)
		{
			return false;
		}
		if (player.itemSlots != null)
		{
			ItemSlot[] itemSlots = player.itemSlots;
			foreach (ItemSlot val in itemSlots)
			{
				if (val != null && IsIdol(val.prefab))
				{
					return true;
				}
			}
		}
		if (player.tempFullSlot != null)
		{
			return IsIdol(player.tempFullSlot.prefab);
		}
		return false;
	}

	private static bool IsIdol(Item item)
	{
		//IL_000a: 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: Invalid comparison between Unknown and I4
		if ((Object)(object)item != (Object)null)
		{
			return (item.itemTags & 0x40) > 0;
		}
		return false;
	}

	private void Summon()
	{
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: 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_0163: 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_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_00e8: 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_00f7: 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_0101: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: 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)
		if (!GameHandler.IsOnIsland)
		{
			return;
		}
		Character localCharacter = Character.localCharacter;
		if ((Object)(object)localCharacter == (Object)null || localCharacter.data.dead || localCharacter.data.fullyPassedOut)
		{
			return;
		}
		if (!CarriesIdol(localCharacter))
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SummonStatue: carry an Ancient Idol to call on the statue.");
			return;
		}
		List<Character> list = new List<Character>();
		foreach (Character allCharacter in Character.AllCharacters)
		{
			if (!((Object)(object)allCharacter == (Object)null) && !((Object)(object)allCharacter == (Object)(object)localCharacter) && !((Object)(object)((MonoBehaviourPun)allCharacter).photonView == (Object)null) && (allCharacter.data.dead || allCharacter.data.fullyPassedOut))
			{
				list.Add(allCharacter);
			}
		}
		if (list.Count == 0)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SummonStatue: nobody to revive.");
			return;
		}
		LayerMask allPhysicalExceptCharacter = HelperFunctions.AllPhysicalExceptCharacter;
		Vector3 val = localCharacter.Center + Vector3.up * 1.5f;
		if (Physics.Linecast(localCharacter.Center, val, LayerMask.op_Implicit(allPhysicalExceptCharacter)))
		{
			val = localCharacter.Center;
		}
		int num = 0;
		for (int i = 0; i < list.Count; i++)
		{
			float num2 = MathF.PI * 2f * (float)i / (float)list.Count;
			Vector3 val2 = val + new Vector3(Mathf.Cos(num2), 0f, Mathf.Sin(num2)) * 0.75f;
			if (Physics.Linecast(val, val2, LayerMask.op_Implicit(allPhysicalExceptCharacter)) || !Physics.Raycast(val2, Vector3.down, 4f, LayerMask.op_Implicit(allPhysicalExceptCharacter)))
			{
				val2 = val;
			}
			try
			{
				((MonoBehaviourPun)list[i]).photonView.RPC("RPCA_ReviveAtPosition", (RpcTarget)0, new object[3] { val2, true, -1 });
				num++;
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"SummonStatue: could not revive {((Object)list[i]).name}: {arg}");
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"SummonStatue: sent the revive to {num} of {list.Count} dead friends.");
	}
}
internal class KeyReader : MonoBehaviour
{
	internal Plugin Owner;

	private void Update()
	{
		if ((Object)(object)Owner != (Object)null)
		{
			Owner.OnFrame();
		}
	}
}