Decompiled source of ChallengerPEAK v0.0.2

plugins/com.github.raspberry1111.challengerpeak.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using ChallengerPEAK.Challenges;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[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("Raspberry1111")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds support for additional challenges to be added to your runs")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2+591f820fcf03efa0f1c28ff5551a8e0622dcd1d8")]
[assembly: AssemblyProduct("com.github.raspberry1111.challengerpeak")]
[assembly: AssemblyTitle("ChallengerPEAK")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace ChallengerPEAK
{
	internal class ChallengeManager : MonoBehaviourPunCallbacks
	{
		private static string[] _enabledChallenges = Array.Empty<string>();

		internal static readonly List<Challenge> LoadedChallenges = new List<Challenge>();

		internal static bool HasReceivedChallenges;

		internal static bool CanInitializeChallenges;

		internal static ChallengeManager? Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
		}

		public void SendChallenges(string[] challenges)
		{
			Plugin.Log.LogInfo((object)("Sending challenges: " + string.Join(", ", challenges)));
			((MonoBehaviourPun)this).photonView.RPC("SyncChallengesRPC", (RpcTarget)0, new object[1] { challenges });
		}

		public void SendChallenges(string[] challenges, Player player)
		{
			Plugin.Log.LogInfo((object)("Sending challenges to " + player.NickName + ": " + string.Join(", ", challenges)));
			((MonoBehaviourPun)this).photonView.RPC("SyncChallengesRPC", player, new object[1] { challenges });
		}

		[PunRPC]
		public void SyncChallengesRPC(string[] challenges)
		{
			if (challenges.Length == 0)
			{
				return;
			}
			if (HasReceivedChallenges)
			{
				Plugin.Log.LogInfo((object)"Received challenges after first receive. Ignoring...");
				return;
			}
			Plugin.Log.LogInfo((object)("Received challenges: " + string.Join(", ", challenges)));
			_enabledChallenges = challenges;
			HasReceivedChallenges = true;
			if (CanInitializeChallenges)
			{
				InitializeChallenges();
			}
		}

		internal static void InitializeChallenges()
		{
			Plugin.Log.LogDebug((object)"Initializing challenges");
			string[] enabledChallenges = _enabledChallenges;
			foreach (string text in enabledChallenges)
			{
				Plugin.Log.LogDebug((object)("Initializing challenge " + text));
				Challenge challenge = ChallengeRegister.RegisteredChallenges[text];
				challenge.Initialize();
				LoadedChallenges.Add(challenge);
			}
			Plugin.Log.LogDebug((object)"Initialized challenges");
		}

		internal static void CleanupChallenges()
		{
			Plugin.Log.LogDebug((object)"Cleaning up challenges");
			foreach (Challenge loadedChallenge in LoadedChallenges)
			{
				Plugin.Log.LogDebug((object)("Cleaning up challenge " + loadedChallenge.ID));
				loadedChallenge.Cleanup();
			}
			LoadedChallenges.Clear();
			_enabledChallenges = Array.Empty<string>();
			HasReceivedChallenges = false;
			CanInitializeChallenges = false;
			Plugin.Log.LogDebug((object)"Cleaned up challenges");
		}

		public override void OnPlayerEnteredRoom(Player newPlayer)
		{
			((MonoBehaviourPunCallbacks)this).OnPlayerEnteredRoom(newPlayer);
			if (PhotonNetwork.IsMasterClient)
			{
				SendChallenges(_enabledChallenges, newPlayer);
			}
		}
	}
	internal class Patches
	{
		[HarmonyPatch(typeof(GameUtils), "Awake")]
		[HarmonyPostfix]
		private static void AddChallengeManager(GameUtils __instance)
		{
			((Component)__instance).gameObject.AddComponent<ChallengeManager>();
		}

		[HarmonyPatch(typeof(MapHandler), "Start")]
		[HarmonyPostfix]
		private static void InitializeChallengesOnMapStart()
		{
			ChallengeManager.CanInitializeChallenges = true;
			Plugin.Log.LogDebug((object)$"MapHandler_StartPatch: CanInitializeChallenges={ChallengeManager.CanInitializeChallenges} | HasReceivedChallenges={ChallengeManager.HasReceivedChallenges}");
			if (ChallengeManager.HasReceivedChallenges)
			{
				ChallengeManager.InitializeChallenges();
			}
		}

		[HarmonyPatch(typeof(MapHandler), "OnDestroy")]
		[HarmonyPostfix]
		private static void CleanupChallengesOnMapDestroy()
		{
			ChallengeManager.CleanupChallenges();
		}

		[HarmonyPatch(typeof(BoardingPass), "Initialize")]
		[HarmonyPrefix]
		private static void AddChallengePassToBoardingPass(BoardingPass __instance)
		{
			ChallengePass challengePass = ((Component)__instance).gameObject.AddComponent<ChallengePass>();
			challengePass.boardingPass = __instance;
			Plugin.Log.LogDebug((object)"ChallengePass initialized!");
		}

		[HarmonyPatch(typeof(BoardingPass), "IncrementAscent")]
		[HarmonyPrefix]
		private static bool InterceptIncrementAscentButton(BoardingPass __instance)
		{
			ChallengePass component = ((Component)__instance).gameObject.GetComponent<ChallengePass>();
			if (!component.ShowChallenges)
			{
				return true;
			}
			component.SelectedChallengeIdx++;
			component.UpdateChallenge();
			return false;
		}

		[HarmonyPatch(typeof(BoardingPass), "DecrementAscent")]
		[HarmonyPrefix]
		private static bool InterceptDecrementAscentButton(BoardingPass __instance)
		{
			ChallengePass component = ((Component)__instance).gameObject.GetComponent<ChallengePass>();
			if (!component.ShowChallenges)
			{
				return true;
			}
			component.SelectedChallengeIdx--;
			component.UpdateChallenge();
			return false;
		}

		[HarmonyPatch(typeof(AirportCheckInKiosk), "StartGame")]
		[HarmonyPrefix]
		private static void SyncChallengesWhenStartingGame()
		{
			ChallengePass.Instance.SyncChallenges();
		}

		[HarmonyPatch(typeof(AscentUI), "Update")]
		[HarmonyPostfix]
		private static void UpdateAscentUI(AscentUI __instance)
		{
			//IL_0066: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			foreach (Challenge loadedChallenge in ChallengeManager.LoadedChallenges)
			{
				TextMeshProUGUI text = __instance.text;
				((TMP_Text)text).text = ((TMP_Text)text).text + "\n" + loadedChallenge.Title;
			}
			RectTransform component = ((Component)__instance.text).GetComponent<RectTransform>();
			component.anchorMin = new Vector2(1f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.anchoredPosition = new Vector2(-2f, 0f);
		}
	}
	internal class ChallengePass : MonoBehaviour
	{
		internal static ChallengePass? Instance;

		public GameObject? switchButton;

		public TextMeshProUGUI? switchButtonText;

		public GameObject? enableButton;

		public TextMeshProUGUI? enableButtonText;

		public BoardingPass? boardingPass;

		private readonly HashSet<string> _enabledChallenges = new HashSet<string>();

		internal int SelectedChallengeIdx;

		internal bool ShowChallenges;

		private Challenge SelectedChallenge => ChallengeRegister.RegisteredChallenges.Values.ElementAt(SelectedChallengeIdx);

		private void Awake()
		{
			Instance = this;
		}

		private void Start()
		{
			//IL_0023: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_0113: 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_0126: 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_01b7: Expected O, but got Unknown
			//IL_01ce: 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_01f4: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)this).gameObject.transform.Find("BoardingPass").Find("Panel");
			switchButton = TMP_DefaultControls.CreateButton(default(Resources));
			switchButtonText = switchButton.GetComponentInChildren<TextMeshProUGUI>();
			switchButton.transform.SetParent(val.Find("Ascent"), false);
			((Object)switchButton).name = "SwitchButton";
			((TMP_Text)switchButtonText).text = "SHOW CHALLENGES";
			switchButton.AddComponent<AnimateButton>();
			((UnityEvent)switchButton.GetComponent<Button>().onClick).AddListener(new UnityAction(SwitchButtonClicked));
			RectTransform component = switchButton.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(0f, 0f);
			component.anchoredPosition = new Vector2(25f + component.sizeDelta.x / 2f, 25f + component.sizeDelta.y / 2f);
			enableButton = TMP_DefaultControls.CreateButton(default(Resources));
			enableButton.SetActive(false);
			enableButtonText = enableButton.GetComponentInChildren<TextMeshProUGUI>();
			enableButton.transform.SetParent(val.Find("Ascent"), false);
			((Object)enableButton).name = "EnableChallengeButton";
			((TMP_Text)enableButtonText).text = "ENABLE";
			enableButton.AddComponent<AnimateButton>();
			((UnityEvent)enableButton.GetComponent<Button>().onClick).AddListener(new UnityAction(EnableButtonClicked));
			RectTransform component2 = enableButton.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(1f, 0f);
			component2.anchorMax = new Vector2(1f, 0f);
			component2.anchoredPosition = new Vector2(-25f - component2.sizeDelta.x / 2f, 25f + component2.sizeDelta.y / 2f);
		}

		private void OnEnable()
		{
			if (ShowChallenges)
			{
				UpdateChallenge();
			}
		}

		private void UpdateAscent()
		{
			ReversePatches.BoardingPass_UpdateAscent(boardingPass);
		}

		internal void UpdateChallenge()
		{
			((Selectable)boardingPass.incrementAscentButton).interactable = SelectedChallengeIdx < ChallengeRegister.RegisteredChallenges.Count - 1;
			((Selectable)boardingPass.decrementAscentButton).interactable = SelectedChallengeIdx > 0;
			boardingPass.ascentTitle.text = SelectedChallenge.Title;
			boardingPass.ascentDesc.text = SelectedChallenge.Description;
			((TMP_Text)enableButtonText).text = (_enabledChallenges.Contains(SelectedChallenge.ID) ? "DISABLE" : "ENABLE");
		}

		private void SwitchButtonClicked()
		{
			ShowChallenges = !ShowChallenges;
			if (ShowChallenges)
			{
				enableButton.SetActive(true);
				boardingPass.reward.SetActive(false);
				UpdateChallenge();
				((TMP_Text)switchButtonText).text = "SHOW ASCENTS";
			}
			else
			{
				enableButton.SetActive(false);
				UpdateAscent();
				((TMP_Text)switchButtonText).text = "SHOW CHALLENGES";
			}
		}

		private void EnableButtonClicked()
		{
			if (!_enabledChallenges.Add(SelectedChallenge.ID))
			{
				_enabledChallenges.Remove(SelectedChallenge.ID);
			}
			UpdateChallenge();
		}

		internal void SyncChallenges()
		{
			ChallengeManager.Instance.SendChallenges(_enabledChallenges.ToArray());
		}
	}
	internal class AnimateButton : MonoBehaviour
	{
		private float _scale = 1f;

		private float _vel;

		private void Start()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Button component = ((Component)this).GetComponent<Button>();
			if (component != null)
			{
				((UnityEvent)component.onClick).AddListener(new UnityAction(OnClick));
			}
		}

		private void Update()
		{
			//IL_0048: 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)
			_vel = FRILerp.Lerp(_vel, (1f - _scale) * 25f, 20f, true);
			_scale += _vel * Time.deltaTime;
			((Component)this).transform.localScale = Vector3.one * _scale;
		}

		private void OnEnable()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.localScale = Vector3.one;
			_scale = 1f;
			_vel = 0f;
		}

		private void OnClick()
		{
			_vel += 4.5f;
		}
	}
	internal class ReversePatches
	{
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(BoardingPass), "UpdateAscent")]
		internal static void BoardingPass_UpdateAscent(object instance)
		{
		}
	}
	public static class ChallengeRegister
	{
		private static readonly SortedDictionary<string, Challenge> _registeredChallenges = new SortedDictionary<string, Challenge>();

		public static IReadOnlyDictionary<string, Challenge> RegisteredChallenges => _registeredChallenges;

		public static bool RegisterChallenge(Challenge challenge)
		{
			return _registeredChallenges.TryAdd(challenge.ID, challenge);
		}
	}
	public abstract class Challenge
	{
		public abstract string ID { get; }

		public abstract string Title { get; }

		public abstract string Description { get; }

		public abstract void Initialize();

		public abstract void Cleanup();
	}
	[BepInPlugin("com.github.raspberry1111.challengerpeak", "ChallengerPEAK", "0.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.raspberry1111.challengerpeak");

		public const string Id = "com.github.raspberry1111.challengerpeak";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "ChallengerPEAK";

		public static string Version => "0.0.2";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll(typeof(Patches));
			_harmony.PatchAll(typeof(ReversePatches));
			ChallengeRegister.RegisterChallenge(new FatalDamage());
			ChallengeRegister.RegisterChallenge(new NoCooking());
			ChallengeRegister.RegisterChallenge(new NoTrace());
			ChallengeRegister.RegisterChallenge(new OneFlare());
			ChallengeRegister.RegisterChallenge(new NoBackpacks());
			ChallengeRegister.RegisterChallenge(new RuleZero());
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void OnDestroy()
		{
			ChallengeManager.CleanupChallenges();
			_harmony.UnpatchSelf();
		}
	}
}
namespace ChallengerPEAK.Challenges
{
	public class FatalDamage : Challenge
	{
		private const string _id = "com.github.raspberry1111.challengerpeak.FatalDamage";

		private readonly Harmony _harmony = new Harmony("com.github.raspberry1111.challengerpeak.FatalDamage");

		public override string ID => "com.github.raspberry1111.challengerpeak.FatalDamage";

		public override string Title => "Fatal Damage";

		public override string Description => "All injury damage (from the Scout Master or Falling) is permanent";

		public override void Initialize()
		{
			_harmony.PatchAll(typeof(FatalDamagePatches));
		}

		public override void Cleanup()
		{
			_harmony.UnpatchSelf();
		}
	}
	internal class FatalDamagePatches
	{
		[HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")]
		[HarmonyPrefix]
		private static void ChangeAfflictionTypes(ref STATUSTYPE statusType)
		{
			if ((int)statusType == 0)
			{
				statusType = (STATUSTYPE)5;
			}
		}
	}
	public class NoBackpacks : Challenge
	{
		private const string _id = "com.github.raspberry1111.challengerpeak.NoBackpacks";

		private readonly Harmony _harmony = new Harmony("com.github.raspberry1111.challengerpeak.NoBackpacks");

		public override string ID => "com.github.raspberry1111.challengerpeak.NoBackpacks";

		public override string Title => "No Backpacks";

		public override string Description => "No backpacks will spawn";

		public override void Initialize()
		{
			_harmony.PatchAll(typeof(NoBackpacksPatches));
		}

		public override void Cleanup()
		{
			_harmony.UnpatchSelf();
		}
	}
	internal class NoBackpacksPatches
	{
		[HarmonyPatch(typeof(Backpack), "Update")]
		[HarmonyPrefix]
		private static bool BackpackUpdatePatch(Backpack __instance)
		{
			Object.Destroy((Object)(object)((Component)__instance).gameObject);
			return true;
		}
	}
	public class NoCooking : Challenge
	{
		private const string _id = "com.github.raspberry1111.challengerpeak.NoCooking";

		private readonly Harmony _harmony = new Harmony("com.github.raspberry1111.challengerpeak.NoCooking");

		public override string ID => "com.github.raspberry1111.challengerpeak.NoCooking";

		public override string Title => "No Cooking";

		public override string Description => "Everything gets destroyed when cooked";

		public override void Initialize()
		{
			_harmony.PatchAll(typeof(NoCookingPatches));
		}

		public override void Cleanup()
		{
			_harmony.UnpatchSelf();
		}
	}
	internal class NoCookingPatches
	{
		[HarmonyPatch(typeof(Item), "Start")]
		[HarmonyPostfix]
		private static void ItemStart(Item __instance)
		{
			__instance.cooking.wreckWhenCooked = true;
		}
	}
	public class NoTrace : Challenge
	{
		private const string _id = "com.github.raspberry1111.challengerpeak.NoTrace";

		private readonly Harmony _harmony = new Harmony("com.github.raspberry1111.challengerpeak.NoTrace");

		public override string ID => "com.github.raspberry1111.challengerpeak.NoTrace";

		public override string Title => "Leave No Trace";

		public override string Description => "Anything that can be placed will spawn incinerated";

		public override void Initialize()
		{
			_harmony.PatchAll(typeof(NoTracePatches));
		}

		public override void Cleanup()
		{
			_harmony.UnpatchSelf();
		}
	}
	internal class NoTracePatches
	{
		[HarmonyPatch(typeof(Item), "Start")]
		[HarmonyPostfix]
		private static void ItemStart(Item __instance)
		{
			string text = ((Object)((Component)__instance).gameObject).name.ToLower();
			if (text.Contains("rope") || text.Contains("climbingspike") || text.Contains("chain") || text.Contains("stove"))
			{
				__instance.cooking.wreckWhenCooked = true;
				__instance.SetCookedAmountRPC(5);
				__instance.cooking.UpdateCookedBehavior();
			}
		}
	}
	public class OneFlare : Challenge
	{
		private const string _id = "com.github.raspberry1111.challengerpeak.OneFlare";

		private readonly Harmony _harmony = new Harmony("com.github.raspberry1111.challengerpeak.OneFlare");

		public override string ID => "com.github.raspberry1111.challengerpeak.OneFlare";

		public override string Title => "One Flare";

		public override string Description => "No flares spawn in luggage\n<alpha=#CC><size=70%>Good luck on Ascent 4+";

		public override void Initialize()
		{
			_harmony.PatchAll(typeof(OneFlarePatches));
		}

		public override void Cleanup()
		{
			_harmony.UnpatchSelf();
		}
	}
	internal class OneFlarePatches
	{
		[HarmonyPatch(typeof(Spawner), "GetObjectsToSpawn")]
		[HarmonyPostfix]
		private static void ChangeSpawnedObjects(Spawner __instance, ref List<GameObject> __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if ((int)__instance.spawnMode != 0)
			{
				__result.RemoveAll((GameObject gameObject) => ((Object)gameObject).name.ToLower().Contains("flare"));
			}
		}
	}
	public class RuleZero : Challenge
	{
		private const string _id = "com.github.raspberry1111.challengerpeak.RuleZero";

		private readonly Harmony _harmony = new Harmony("com.github.raspberry1111.challengerpeak.RuleZero");

		internal static Vector3? PlayerJustDiedPosition;

		public override string ID => "com.github.raspberry1111.challengerpeak.RuleZero";

		public override string Title => "Rule 0";

		public override string Description => "Never abandon a friend in need!\n<alpha=#CC><size=70%>Myers spawns when someone dies";

		public override void Initialize()
		{
			_harmony.PatchAll(typeof(RuleZeroPatches));
		}

		public override void Cleanup()
		{
			PlayerJustDiedPosition = null;
			_harmony.UnpatchSelf();
		}

		internal static Character? ClosestAlivePlayerTo(Vector3 position)
		{
			//IL_0048: 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_005b: 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)
			Character val = null;
			foreach (Character allCharacter in Character.AllCharacters)
			{
				if (allCharacter.isBot || allCharacter.data.dead || allCharacter.data.fullyPassedOut)
				{
					continue;
				}
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 position2 = ((Component)allCharacter).transform.position;
					float sqrMagnitude = ((Vector3)(ref position2)).sqrMagnitude;
					position2 = ((Component)val).transform.position;
					if (!(sqrMagnitude < ((Vector3)(ref position2)).sqrMagnitude))
					{
						continue;
					}
				}
				val = allCharacter;
			}
			return val;
		}
	}
	internal class RuleZeroPatches
	{
		[HarmonyPatch(typeof(Character), "RPCA_Die")]
		[HarmonyPrefix]
		private static void GetPlayerDeathPosition(Character __instance)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			RuleZero.PlayerJustDiedPosition = ((Component)__instance).gameObject.transform.position;
		}

		[HarmonyPatch(typeof(Scoutmaster), "Start")]
		[HarmonyPostfix]
		private static void ChangeScoutmasterAggroRange(Scoutmaster __instance)
		{
			__instance.maxAggroHeight = 600f;
		}

		[HarmonyPatch(typeof(Scoutmaster), "LookForTarget")]
		[HarmonyPostfix]
		private static void AddClosestPlayerAsTarget(Scoutmaster __instance)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (Character.AllCharacters.Count > 1 && RuleZero.PlayerJustDiedPosition.HasValue)
			{
				Character val = RuleZero.ClosestAlivePlayerTo(RuleZero.PlayerJustDiedPosition.Value);
				if (Object.op_Implicit((Object)(object)val))
				{
					__instance.SetCurrentTarget(val, 40f);
					RuleZero.PlayerJustDiedPosition = null;
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}