Decompiled source of 31Arcadia v1.1.3

ArcadiaMoonPlugin.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
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.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;

[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("ArcadiaMoonPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A helper tool for ArcadiaMoon mod")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fe795d19ff63a21b0b5b415981e553c41b564603")]
[assembly: AssemblyProduct("ArcadiaMoonPlugin")]
[assembly: AssemblyTitle("ArcadiaMoonPlugin")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ArcadiaMoonPlugin
{
	[BepInPlugin("ArcadiaMoonPlugin", "ArcadiaMoonPlugin", "1.0.0")]
	public class ArcadiaMoon : BaseUnityPlugin
	{
		private Harmony harmony;

		public static ArcadiaMoon instance;

		public static ConfigEntry<bool> ForceSpawnFlowerman { get; private set; }

		public static ConfigEntry<bool> ForceSpawnBaboon { get; private set; }

		public static ConfigEntry<bool> ForceSpawnRadMech { get; private set; }

		private void Awake()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ArcadiaMoonPlugin is loaded!");
			ForceSpawnFlowerman = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "ForceSpawnFlowerman", true, "Enable forced spawning for Flowerman");
			ForceSpawnBaboon = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "ForceSpawnBaboon", true, "Enable forced spawning for Baboon hawk");
			ForceSpawnRadMech = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "ForceSpawnRadMech", true, "Enable forced spawning for Old Bird");
			harmony = new Harmony("ArcadiaMoonPlugin");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ArcadiaMoonPlugin patched PlayerControllerB!");
		}
	}
	public class TimeAnimSyncronizer : MonoBehaviour
	{
		private Animator timeSyncAnimator;

		private void Start()
		{
			timeSyncAnimator = ((Component)this).GetComponent<Animator>();
			if ((Object)(object)timeSyncAnimator == (Object)null)
			{
				Debug.LogError((object)"There is no Animator component attached to this object!");
			}
		}

		private void Update()
		{
			if ((Object)(object)timeSyncAnimator != (Object)null && TimeOfDay.Instance.timeHasStarted)
			{
				timeSyncAnimator.SetFloat("timeOfDay", Mathf.Clamp(TimeOfDay.Instance.normalizedTimeOfDay, 0f, 0.99f));
			}
		}
	}
	internal class HeatwaveZoneInteract : MonoBehaviour
	{
		public float timeInZoneMax = 10f;

		public float resetDuration = 5f;

		public Volume exhaustionFilter;

		private void OnTriggerEnter(Collider other)
		{
			if (((Component)other).CompareTag("Player"))
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					PlayerHeatEffects.OnPlayerEnterZone(timeInZoneMax);
				}
			}
		}

		private void OnTriggerStay(Collider other)
		{
			if (!((Component)other).CompareTag("Player"))
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				if (component.isPlayerDead || component.beamUpParticle.isPlaying)
				{
					PlayerHeatEffects.OnPlayerNearDeathOrTeleporting(exhaustionFilter, resetDuration);
				}
				else
				{
					PlayerHeatEffects.IncreaseEffects(timeInZoneMax, exhaustionFilter);
				}
			}
		}

		private void OnTriggerExit(Collider other)
		{
			if (((Component)other).CompareTag("Player"))
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					PlayerHeatEffects.OnPlayerExitZone(exhaustionFilter, resetDuration);
				}
			}
		}

		private void OnDestroy()
		{
			PlayerHeatEffects.OnZoneDestroy(exhaustionFilter);
		}
	}
	internal class PlayerHeatEffects : MonoBehaviour
	{
		private static float heatSeverity;

		private static float exhaustionTimer;

		private static int colliderCount;

		private static Coroutine resetCoroutine;

		private static PlayerHeatEffects instance;

		public static PlayerHeatEffects Instance
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)instance == (Object)null)
				{
					instance = new GameObject("PlayerHeatEffects").AddComponent<PlayerHeatEffects>();
				}
				return instance;
			}
		}

		internal static void OnPlayerEnterZone(float timeInZoneMax)
		{
			colliderCount++;
			if (colliderCount == 1 && resetCoroutine != null)
			{
				StopResetCoroutine();
				exhaustionTimer = timeInZoneMax * heatSeverity;
				Debug.Log((object)"Player has entered a heatwave zone!");
			}
		}

		internal static void OnPlayerNearDeathOrTeleporting(Volume exhaustionFilter, float resetDuration)
		{
			if (resetCoroutine == null)
			{
				resetCoroutine = ((MonoBehaviour)Instance).StartCoroutine(GraduallyResetEffects(exhaustionFilter, resetDuration));
				colliderCount = 0;
				Debug.Log((object)"Player is dead or teleporting, removing heatstroke!");
			}
		}

		internal static void IncreaseEffects(float timeInZoneMax, Volume exhaustionFilter)
		{
			exhaustionTimer += Time.deltaTime;
			float severity = Mathf.Clamp01(exhaustionTimer / timeInZoneMax);
			if (resetCoroutine != null)
			{
				StopResetCoroutine();
			}
			SetHeatSeverity(severity, exhaustionFilter);
		}

		internal static void OnPlayerExitZone(Volume exhaustionFilter, float resetDuration)
		{
			colliderCount = Mathf.Max(colliderCount - 1, 0);
			if (colliderCount == 0 && resetCoroutine == null)
			{
				resetCoroutine = ((MonoBehaviour)Instance).StartCoroutine(GraduallyResetEffects(exhaustionFilter, resetDuration));
				Debug.Log((object)"Player has left the heatwave zone!");
			}
		}

		internal static void OnZoneDestroy(Volume exhaustionFilter)
		{
			if (heatSeverity > 0f && resetCoroutine == null)
			{
				SetHeatSeverity(0f, exhaustionFilter);
				colliderCount = 0;
				exhaustionTimer = 0f;
				Debug.Log((object)"Heatwave zone object destroyed, removing heatstroke!");
			}
		}

		private static void StopResetCoroutine()
		{
			if (resetCoroutine != null)
			{
				((MonoBehaviour)Instance).StopCoroutine(resetCoroutine);
				resetCoroutine = null;
			}
		}

		private static IEnumerator GraduallyResetEffects(Volume exhaustionFilter, float resetDuration)
		{
			float startSeverity = heatSeverity;
			float elapsedTime = 0f;
			while (elapsedTime < resetDuration && startSeverity > 0f)
			{
				elapsedTime += Time.deltaTime;
				float newSeverity = Mathf.Lerp(startSeverity, 0f, elapsedTime / resetDuration);
				SetHeatSeverity(newSeverity, exhaustionFilter);
				yield return null;
			}
			exhaustionTimer = 0f;
			SetHeatSeverity(0f, exhaustionFilter);
		}

		internal static void SetExhaustionTimer(float timeInZone)
		{
			exhaustionTimer = timeInZone;
		}

		public static float GetExhaustionTimer()
		{
			return exhaustionTimer;
		}

		internal static void SetHeatSeverity(float severity, Volume volume)
		{
			heatSeverity = severity;
			if ((Object)(object)volume != (Object)null)
			{
				volume.weight = Mathf.Clamp01(severity);
			}
		}

		public static float GetHeatSeverity()
		{
			return heatSeverity;
		}

		public static int GetColliderCount()
		{
			return colliderCount;
		}
	}
	public class EnemySpawner : MonoBehaviour
	{
		public string enemyName = "RadMech";

		private EnemyType enemyType;

		private GameObject nestPrefab;

		public float timer = 0.5f;

		private List<GameObject> spawnedNests = new List<GameObject>();

		private Random random = new Random(StartOfRound.Instance.randomMapSeed + 42);

		private void LoadResources(string enemyName)
		{
			IEnumerable<EnemyType> source = Resources.FindObjectsOfTypeAll<EnemyType>().Distinct();
			enemyType = source.FirstOrDefault((Func<EnemyType, bool>)((EnemyType e) => e.enemyName == enemyName));
			if ((Object)(object)enemyType != (Object)null)
			{
				nestPrefab = enemyType.nestSpawnPrefab;
				Debug.Log((object)(enemyType.enemyName + " and its prefab loaded successfully!"));
			}
			else
			{
				Debug.LogError((object)"Failed to load EnemyType!");
			}
		}

		private void Start()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00a1: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			if (!GameNetworkManager.Instance.isHostingGame)
			{
				return;
			}
			LoadResources(enemyName);
			if (!IsSpawningEnabled())
			{
				Debug.Log((object)("Forced spawning for " + enemyName + " is disabled in the config."));
				((Behaviour)this).enabled = false;
				return;
			}
			foreach (Transform item in ((Component)this).transform)
			{
				Transform val = item;
				if ((Object)(object)nestPrefab != (Object)null)
				{
					Debug.Log((object)"Started nest prefab spawning routine!");
					Vector3 randomNavMeshPositionInBoxPredictable = RoundManager.Instance.GetRandomNavMeshPositionInBoxPredictable(val.position, 10f, default(NavMeshHit), random, RoundManager.Instance.GetLayermaskForEnemySizeLimit(enemyType));
					randomNavMeshPositionInBoxPredictable = RoundManager.Instance.PositionEdgeCheck(randomNavMeshPositionInBoxPredictable, enemyType.nestSpawnPrefabWidth);
					GameObject val2 = Object.Instantiate<GameObject>(nestPrefab, randomNavMeshPositionInBoxPredictable, Quaternion.identity);
					val2.transform.Rotate(Vector3.up, (float)random.Next(-180, 180), (Space)0);
					spawnedNests.Add(val2);
					if (Object.op_Implicit((Object)(object)val2.GetComponentInChildren<NetworkObject>()))
					{
						val2.GetComponentInChildren<NetworkObject>().Spawn(true);
						Debug.Log((object)("Spawned an " + enemyName + " nest prefab!"));
					}
					else
					{
						Debug.LogError((object)("Nest prefab of " + enemyName + " does not have a NetworkObject component. Desync possible!"));
					}
				}
			}
		}

		private void Update()
		{
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_0122: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			if (!(TimeOfDay.Instance.normalizedTimeOfDay > timer) || !TimeOfDay.Instance.timeHasStarted || !GameNetworkManager.Instance.isHostingGame)
			{
				return;
			}
			if ((Object)(object)nestPrefab != (Object)null)
			{
				foreach (GameObject spawnedNest in spawnedNests)
				{
					Vector3 position = spawnedNest.transform.position;
					Quaternion rotation = spawnedNest.transform.rotation;
					float y = ((Quaternion)(ref rotation)).eulerAngles.y;
					Object.Destroy((Object)(object)spawnedNest);
					SpawnEnemyAtPosition(position, y);
					Debug.Log((object)("Spawned enemy " + enemyName + " in place of a nest prefab!"));
				}
				spawnedNests.Clear();
				Debug.Log((object)("Destroyed all spawned enemy nest prefabs of " + enemyType.enemyName + "!"));
			}
			else
			{
				foreach (Transform item in ((Component)this).transform)
				{
					Transform val = item;
					SpawnEnemyAtPosition(val.position);
					Debug.Log((object)"Force spawned an enemy!");
				}
			}
			((Behaviour)this).enabled = false;
		}

		private void SpawnEnemyAtPosition(Vector3 position, float yRot = 0f)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)("Current enemy type for force spawn is " + enemyType.enemyName));
			if ((Object)(object)enemyType.enemyPrefab == (Object)null)
			{
				Debug.LogError((object)(enemyType.enemyName + " does not have a valid enemy prefab to spawn."));
			}
			else
			{
				RoundManager.Instance.SpawnEnemyGameObject(position, yRot, -1, enemyType);
			}
		}

		private bool IsSpawningEnabled()
		{
			return enemyName.ToLower() switch
			{
				"flowerman" => ArcadiaMoon.ForceSpawnFlowerman.Value, 
				"baboon hawk" => ArcadiaMoon.ForceSpawnBaboon.Value, 
				"radmech" => ArcadiaMoon.ForceSpawnRadMech.Value, 
				_ => true, 
			};
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ArcadiaMoonPlugin";

		public const string PLUGIN_NAME = "ArcadiaMoonPlugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ArcadiaMoonPlugin.Patches
{
	[HarmonyPatch]
	internal class PlayerControllerBHeatStrokePatch
	{
		private static float prevSprintMeter;

		private static float severityMultiplier = 1f;

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPrefix]
		[HarmonyPriority(600)]
		private static void HeatStrokePatchPrefix(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled)
			{
				prevSprintMeter = __instance.sprintMeter;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		[HarmonyPriority(200)]
		private static void HeatStrokePatchPostfix(PlayerControllerB __instance)
		{
			if (!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled)
			{
				return;
			}
			float heatSeverity = PlayerHeatEffects.GetHeatSeverity();
			if (heatSeverity > 0f)
			{
				float num = __instance.sprintMeter - prevSprintMeter;
				if ((double)num < 0.0)
				{
					__instance.sprintMeter = Mathf.Max(prevSprintMeter + num * (1f + heatSeverity * severityMultiplier), 0f);
				}
				else if ((double)num > 0.0)
				{
					__instance.sprintMeter = Mathf.Min(prevSprintMeter + num / (1f + heatSeverity * severityMultiplier), 1f);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")]
		[HarmonyPrefix]
		[HarmonyPriority(600)]
		private static void HeatStrokePatchLatePrefix(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled)
			{
				prevSprintMeter = __instance.sprintMeter;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")]
		[HarmonyPostfix]
		[HarmonyPriority(200)]
		private static void HeatStrokePatchLatePostfix(PlayerControllerB __instance)
		{
			if (!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled)
			{
				return;
			}
			float heatSeverity = PlayerHeatEffects.GetHeatSeverity();
			if (heatSeverity > 0f)
			{
				float num = __instance.sprintMeter - prevSprintMeter;
				if ((double)num < 0.0)
				{
					__instance.sprintMeter = Mathf.Max(prevSprintMeter + num * (1f + heatSeverity * severityMultiplier), 0f);
				}
				else if ((double)num > 0.0)
				{
					__instance.sprintMeter = Mathf.Min(prevSprintMeter + num / (1f + heatSeverity * severityMultiplier), 1f);
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}