Decompiled source of Oh Good Lord the Scoutmasters are Plentiful v1.0.5

BepInEx/plugins/Oh_Good_Lord_the_Scoutmasters_are_Plentiful.dll

Decompiled a month ago
using System;
using System.Collections;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Oh_Good_Lord_the_Scoutmasters_are_Plentiful")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Oh_Good_Lord_the_Scoutmasters_are_Plentiful")]
[assembly: AssemblyTitle("OhGoodLordtheScoutmastersarePlentiful")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 ogltsap
{
	[HarmonyPatch(typeof(Character), "Awake")]
	internal static class PlentifulMe
	{
		internal static void Postfix(Character __instance)
		{
			((Component)__instance).gameObject.AddComponent<ThePlentifulnessIsEverywhere>().character = __instance;
		}
	}
	internal class PutTeleporterHere : MonoBehaviour
	{
		public Scoutmaster meYippee;

		public Character charToChase;

		public void Awake()
		{
			((MonoBehaviour)this).StartCoroutine((IEnumerator)checkDistanceFromTarget());
		}

		public IEnumerator<WaitForSeconds> checkDistanceFromTarget()
		{
			WaitForSeconds _cache = new WaitForSeconds(15f);
			while (true)
			{
				yield return _cache;
				if ((Object)(object)meYippee.currentTarget != (Object)(object)charToChase)
				{
					PhotonNetwork.Destroy(((Component)meYippee).gameObject);
				}
				if (Vector3.Distance(meYippee.character.Center, meYippee.currentTarget.Center) > Plugin.maxDistanceBeforeTp.Value)
				{
					Vector3 pointToRaycastFrom = meYippee.currentTarget.Center + new Vector3(Random.Range((0f - Plugin.maxDistanceBeforeTp.Value) * 0.5f, Plugin.maxDistanceBeforeTp.Value * 0.5f), 50f, Random.Range((0f - Plugin.maxDistanceBeforeTp.Value) * 0.5f, Plugin.maxDistanceBeforeTp.Value * 0.5f));
					Vector3 pointToSpawn = HelperFunctions.GetGroundPos(pointToRaycastFrom, (LayerType)1, 0f);
					meYippee.character.WarpPlayer(pointToSpawn, false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Scoutmaster), "EvasiveBehaviour")]
	internal static class discoveredPatch
	{
		internal static bool Prefix(Scoutmaster __instance)
		{
			if (!Plugin.plentifulMode.Value || Plugin.gracePeriod.Value <= 0f)
			{
				if (!Object.op_Implicit((Object)(object)__instance.discovered))
				{
					__instance.discovered = __instance.GetPlayerWhoSeesMe();
				}
				if (Object.op_Implicit((Object)(object)__instance.discovered))
				{
					__instance.Flee();
					if (__instance.sinceAnyoneCanSeeMe > 0.5f)
					{
						__instance.TeleportFarAway();
					}
				}
			}
			return false;
		}
	}
	internal class ThePlentifulnessIsEverywhere : MonoBehaviour
	{
		public Character character;

		public Character scoutmasterChasingThisFella;

		public Scoutmaster scoutyComponent;

		public bool beingChasedRN = false;

		public float graceTimer = Plugin.gracePeriod.Value;

		public void Awake()
		{
			((MonoBehaviour)this).StartCoroutine((IEnumerator)doit());
		}

		public IEnumerator<WaitForSeconds> doit()
		{
			yield return new WaitForSeconds(20f);
			WaitForSeconds _cache = new WaitForSeconds(5f);
			while (!character.inAirport && PhotonNetwork.IsMasterClient && !character.isBot && Plugin.plentifulMode.Value && !Plugin.useVanilla.Value)
			{
				graceTimer -= 1f;
				try
				{
					if (Object.op_Implicit((Object)(object)scoutyComponent.discovered) || (Object)(object)scoutyComponent == (Object)null || (Object)(object)scoutyComponent.currentTarget != (Object)(object)character)
					{
						beingChasedRN = false;
					}
					else
					{
						graceTimer = Plugin.gracePeriod.Value;
					}
				}
				catch
				{
					beingChasedRN = false;
				}
				foreach (Character c2 in Character.AllCharacters)
				{
					if (beingChasedRN || !(graceTimer < 0f) || !(character.Center.y - c2.Center.y > Plugin.minDistanceForChase.Value) || (c2.data.dead && character.data.dead && c2.data.passedOut && character.data.passedOut) || (Plugin.ignorePlayersInFog.Value && (c2.data.isInFog || character.data.isInFog)))
					{
						continue;
					}
					yield return new WaitForSeconds(Plugin.beforeChaseGracePeriod.Value);
					if (!(character.Center.y - c2.Center.y > Plugin.minDistanceForChase.Value))
					{
						break;
					}
					if ((Object)(object)scoutmasterChasingThisFella == (Object)null)
					{
						scoutmasterChasingThisFella = PhotonNetwork.InstantiateRoomObject("Character_Scoutmaster", ((Component)this).transform.position, ((Component)this).transform.rotation, (byte)0, (object[])null).GetComponent<Character>();
						scoutyComponent = ((Component)scoutmasterChasingThisFella).gameObject.GetComponent<Scoutmaster>();
						scoutmasterChasingThisFella.data.spawnPoint = ((Component)this).transform;
						PutTeleporterHere teleportHandler = ((Component)scoutmasterChasingThisFella).gameObject.AddComponent<PutTeleporterHere>();
						teleportHandler.charToChase = character;
						teleportHandler.meYippee = scoutyComponent;
					}
					if (Plugin.maxScoutmasters.Value < 30)
					{
						Scoutmaster[] allScoutMs = Object.FindObjectsByType<Scoutmaster>((FindObjectsInactive)1, (FindObjectsSortMode)0);
						if (allScoutMs.Length > Plugin.maxScoutmasters.Value)
						{
							PhotonNetwork.Destroy(((Component)scoutmasterChasingThisFella).gameObject);
							graceTimer = Plugin.gracePeriod.Value;
							yield return _cache;
						}
					}
					else
					{
						yield return new WaitForSeconds(0.01f);
						scoutyComponent.SetCurrentTarget(character, Plugin.forcedChaseTime.Value);
						beingChasedRN = true;
					}
					break;
				}
				yield return _cache;
			}
			Scoutmaster scoutmaster = default(Scoutmaster);
			while (!character.inAirport && PhotonNetwork.IsMasterClient && !character.isBot && !Plugin.useVanilla.Value)
			{
				graceTimer -= 1f;
				Scoutmaster.GetPrimaryScoutmaster(ref scoutmaster);
				if ((Object)(object)scoutmaster.currentTarget != (Object)null)
				{
					graceTimer = Plugin.gracePeriod.Value;
				}
				foreach (Character c in Character.AllCharacters)
				{
					if (graceTimer < 0f && character.Center.y - c.Center.y > Plugin.minDistanceForChase.Value)
					{
						yield return new WaitForSeconds(Plugin.beforeChaseGracePeriod.Value);
						if (character.Center.y - c.Center.y > Plugin.minDistanceForChase.Value && Object.op_Implicit((Object)(object)scoutmaster))
						{
							scoutmaster.SetCurrentTarget(character, Plugin.forcedChaseTime.Value);
						}
					}
				}
				yield return _cache;
				scoutmaster = null;
			}
		}
	}
	[BepInPlugin("ohgoodlordthescoutmastersareplentiful", "ohgoodlordthescoutmastersareplentiful", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ConfigEntry<bool> plentifulMode;

		internal static ConfigEntry<int> maxScoutmasters;

		internal static int currentScoutmasterCount;

		internal static ConfigEntry<float> minDistanceForChase;

		internal static ConfigEntry<float> forcedChaseTime;

		internal static ConfigEntry<float> gracePeriod;

		internal static ConfigEntry<float> beforeChaseGracePeriod;

		internal static ConfigEntry<float> maxDistanceBeforeTp;

		internal static ConfigEntry<bool> ignorePlayersInFog;

		internal static ConfigEntry<bool> useVanilla;

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			plentifulMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Plentiful Mode", "Enabled", false, "Allows many scoutmasters to spawn");
			maxScoutmasters = ((BaseUnityPlugin)this).Config.Bind<int>("Plentiful Mode", "Max Scoutmasters (30 or more means no max)", 30, "Max amount of scoutmasters");
			minDistanceForChase = ((BaseUnityPlugin)this).Config.Bind<float>("Rule 0 Stuff", "Minimum Height Difference for a Scoutmaster Chase", 150f, (ConfigDescription)null);
			forcedChaseTime = ((BaseUnityPlugin)this).Config.Bind<float>("Rule 0 Stuff", "Forced Chase Time", 30f, (ConfigDescription)null);
			gracePeriod = ((BaseUnityPlugin)this).Config.Bind<float>("Rule 0 Stuff", "Grace Period After Chase", 45f, (ConfigDescription)null);
			beforeChaseGracePeriod = ((BaseUnityPlugin)this).Config.Bind<float>("Rule 0 Stuff", "Grace Period Before Chase", 30f, (ConfigDescription)null);
			maxDistanceBeforeTp = ((BaseUnityPlugin)this).Config.Bind<float>("Rule 0 Stuff", "Max Distance Before TP", 30f, (ConfigDescription)null);
			ignorePlayersInFog = ((BaseUnityPlugin)this).Config.Bind<bool>("Plentiful Mode", "Ignore Players in Fog", true, (ConfigDescription)null);
			useVanilla = ((BaseUnityPlugin)this).Config.Bind<bool>("Rule 0 Stuff", "Use Vanilla Scoutmaster (turns off the mod)", false, (ConfigDescription)null);
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Plugin oh good lord the scoutmasters are plentiful is loaded!");
			Harmony val = new Harmony("ogltsap");
			val.PatchAll();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}