Decompiled source of LethalChaos v1.0.3

BepinEx/plugins/LethalChaos.dll

Decompiled 10 months 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 BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("LethalChaos")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalChaos")]
[assembly: AssemblyTitle("LethalChaos")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace LethalChaos
{
	public class CompanyBuyRate : EventBase
	{
		public override string Text { get; } = "Buy Rate Randomizer";


		public override Phase Phase { get; } = Phase.Company;


		public override void Activate()
		{
			StartOfRound instance = StartOfRound.Instance;
			instance.companyBuyingRate *= Random.Range(0.9f, 1.5f);
		}
	}
	public class EclipsedWeather : EventBase
	{
		public override string Text { get; } = "Eclipsed Moon";


		public override Phase Phase { get; } = Phase.Exploration;


		public override bool IsUseable => base.IsUseable && (int)TimeOfDay.Instance.currentLevelWeather != 5;

		public override void Activate()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			if ((int)TimeOfDay.Instance.currentLevelWeather != -1)
			{
				TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectEnabled = false;
				if ((Object)(object)TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectObject != (Object)null)
				{
					TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectObject.SetActive(false);
				}
				if ((Object)(object)TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectPermanentObject != (Object)null)
				{
					TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectPermanentObject.SetActive(false);
				}
			}
			RoundManager.Instance.currentLevel.currentWeather = (LevelWeatherType)5;
			TimeOfDay.Instance.currentLevelWeather = (LevelWeatherType)5;
			TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectEnabled = true;
			if ((Object)(object)TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectObject != (Object)null)
			{
				TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectObject.SetActive(true);
			}
			if ((Object)(object)TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectPermanentObject != (Object)null)
			{
				TimeOfDay.Instance.effects[TimeOfDay.Instance.currentLevelWeather].effectPermanentObject.SetActive(true);
			}
			for (int i = 0; i < RoundManager.Instance.currentLevel.randomWeathers.Length; i++)
			{
				if (RoundManager.Instance.currentLevel.randomWeathers[i].weatherType == RoundManager.Instance.currentLevel.currentWeather)
				{
					TimeOfDay.Instance.currentWeatherVariable = RoundManager.Instance.currentLevel.randomWeathers[i].weatherVariable;
					TimeOfDay.Instance.currentWeatherVariable2 = RoundManager.Instance.currentLevel.randomWeathers[i].weatherVariable2;
				}
			}
			GameObject.Find("EclipseObject").SetActive(true);
			RoundManager.Instance.minOutsideEnemiesToSpawn = TimeOfDay.Instance.currentWeatherVariable;
			RoundManager.Instance.minEnemiesToSpawn = TimeOfDay.Instance.currentWeatherVariable;
			Utility.SpawnEnemyOutside(typeof(MouthDogAI), ForceOutside: false);
			Utility.SpawnEnemyOutside(typeof(MouthDogAI), ForceOutside: false);
			Utility.SpawnEnemyOutside(typeof(MouthDogAI), ForceOutside: false);
		}
	}
	public abstract class EventBase
	{
		public static Phase CurrentPhase = Phase.Orbiting;

		public bool isUsed;

		public abstract string Text { get; }

		public abstract Phase Phase { get; }

		public virtual bool IsUseable => !isUsed;

		public static HashSet<EventBase> Events { get; } = new HashSet<EventBase>();


		public abstract void Activate();

		public static List<EventBase> GetFromPhase(Phase phase)
		{
			return Events.Where((EventBase e) => e.IsUseable && e.Phase == phase).ToList();
		}

		public static EventBase GetRandomForPhase()
		{
			return Events.Where((EventBase e) => e.IsUseable && e.Phase == CurrentPhase).ToList().GetRandom();
		}

		public static void ResetUses()
		{
			foreach (EventBase @event in Events)
			{
				@event.isUsed = false;
			}
			SpeedBoost.IsActivated = false;
		}

		public static void Register()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			Type[] types = executingAssembly.GetTypes();
			foreach (Type type in types)
			{
				if (!(type.BaseType != typeof(EventBase)))
				{
					EventBase item = (EventBase)Activator.CreateInstance(type);
					Events.Add(item);
				}
			}
		}
	}
	public class FacilityError : EventBase
	{
		public override string Text { get; } = "Facility Error";


		public override Phase Phase { get; } = Phase.Exploration;


		public override void Activate()
		{
			((MonoBehaviour)RoundManager.Instance).StartCoroutine(DoActivation());
		}

		private IEnumerator DoActivation()
		{
			Landmine[] landmines = Object.FindObjectsOfType<Landmine>();
			Turret[] turrets = Object.FindObjectsOfType<Turret>();
			Landmine[] array = landmines;
			foreach (Landmine landmine in array)
			{
				landmine.ToggleMine(false);
			}
			Turret[] array2 = turrets;
			foreach (Turret turret in array2)
			{
				turret.ToggleTurretEnabled(false);
			}
			RoundManager.Instance.TurnOnAllLights(false);
			yield return (object)new WaitForSeconds(15f);
			Landmine[] array3 = landmines;
			foreach (Landmine landmine2 in array3)
			{
				landmine2.ToggleMine(true);
			}
			Turret[] array4 = turrets;
			foreach (Turret turret2 in array4)
			{
				turret2.ToggleTurretEnabled(true);
			}
			RoundManager.Instance.TurnOnAllLights(true);
			isUsed = false;
		}
	}
	public class Kaboom : EventBase
	{
		public override string Text { get; } = "Kaboom!";


		public override Phase Phase { get; } = Phase.Exploration;


		public override void Activate()
		{
			Landmine[] array = Object.FindObjectsOfType<Landmine>();
			foreach (Landmine val in array)
			{
				val.Detonate();
			}
		}
	}
	public class MineHell : EventBase
	{
		public override string Text { get; } = "Mine Hell";


		public override Phase Phase { get; } = Phase.MoonLanding;


		public override void Activate()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < RoundManager.Instance.shipSpawnPathPoints.Length; i++)
			{
				SpawnMines(RoundManager.Instance.shipSpawnPathPoints[i].position);
			}
		}

		private void SpawnMines(Vector3 original, int amount = 10, bool spawnMore = true)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			for (int i = 0; i < amount; i++)
			{
				RoundManager instance = RoundManager.Instance;
				Random random = new Random(Random.Range(1, 1000));
				Vector3 randomNavMeshPositionInBoxPredictable = instance.GetRandomNavMeshPositionInBoxPredictable(original, 30f, default(NavMeshHit), random, -5);
				GameObject val = Object.Instantiate<GameObject>(Variables.LandminePrefab, randomNavMeshPositionInBoxPredictable, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(true);
				if (spawnMore)
				{
					SpawnMines(randomNavMeshPositionInBoxPredictable, 5, spawnMore: false);
				}
			}
		}
	}
	public class OpenEnemyVents : EventBase
	{
		public override string Text { get; } = "Open Vents";


		public override Phase Phase { get; } = Phase.Exploration;


		public override void Activate()
		{
			foreach (EnemyVent enemyVent in RoundManager.Instance.allEnemyVents.Where((EnemyVent v) => !v.occupied))
			{
				enemyVent.enemyType = RoundManager.Instance.currentLevel.Enemies.GetRandom().enemyType;
				enemyVent.enemyTypeIndex = RoundManager.Instance.currentLevel.Enemies.FindIndex((SpawnableEnemyWithRarity e) => (Object)(object)e.enemyType == (Object)(object)enemyVent.enemyType);
				enemyVent.occupied = true;
				RoundManager.Instance.SpawnEnemyFromVent(enemyVent);
			}
		}
	}
	public class RandomTeleport : EventBase
	{
		public override string Text { get; } = "Random Teleport";


		public override Phase Phase { get; } = Phase.Exploration;


		public override bool IsUseable => GameNetworkManager.Instance.localPlayerController.isInsideFactory;

		public override void Activate()
		{
			GameObject[] allPlayerObjects = StartOfRound.Instance.allPlayerObjects;
			foreach (GameObject val in allPlayerObjects)
			{
				PlayerControllerB component = val.GetComponent<PlayerControllerB>();
				if (!((Object)(object)component == (Object)null) && !component.isPlayerDead)
				{
					((MonoBehaviour)RoundManager.Instance).StartCoroutine(DoTeleport(component));
				}
			}
		}

		private IEnumerator DoTeleport(PlayerControllerB controller)
		{
			controller.beamUpParticle.Play();
			yield return (object)new WaitForSeconds(2.5f);
			PlayerControllerB playerController = GameNetworkManager.Instance.localPlayerController;
			playerController.averageVelocity = 0f;
			playerController.velocityLastFrame = Vector3.zero;
			playerController.TeleportPlayer(((Component)RoundManager.Instance.allEnemyVents.ToList().GetRandom()).transform.position, false, 0f, false, true);
			playerController.isInElevator = false;
			playerController.isInHangarShipRoom = false;
			playerController.isInsideFactory = true;
			for (int i = 0; i < playerController.ItemSlots.Length; i++)
			{
				if ((Object)(object)playerController.ItemSlots[i] != (Object)null)
				{
					playerController.ItemSlots[i].isInFactory = true;
				}
			}
			yield return (object)new WaitForSeconds(1f);
			controller.beamOutBuildupParticle.Stop();
		}
	}
	public class SpeedBoost : EventBase
	{
		public static bool IsActivated;

		public override string Text { get; } = "Speed Boost";


		public override Phase Phase { get; } = Phase.MoonLanding;


		public override void Activate()
		{
			IsActivated = true;
		}
	}
	public enum Phase
	{
		Company,
		MoonLanding,
		Exploration,
		Orbiting
	}
	[BepInPlugin("Misfiy.LethalChaos", "Lethal Chaos", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Misfiy.LethalChaos";

		private const string modName = "Lethal Chaos";

		private const string modVersion = "1.0.3";

		private readonly Harmony harmony = new Harmony("Misfiy.LethalChaos");

		public static ManualLogSource Logging { get; private set; }

		private void Awake()
		{
			Logging = ((BaseUnityPlugin)this).Logger;
			EventBase.Register();
			harmony.PatchAll();
		}
	}
	public static class Utility
	{
		public static float CurrentScrapAmountMultiplier => RoundManager.Instance.currentLevel.PlanetName.Contains("Titan") ? 3f : 1.5f;

		public static float CurrentScrapValueMultiplier => RoundManager.Instance.currentLevel.PlanetName.Contains("Titan") ? 1.5f : 1.25f;

		public static T GetRandom<T>(this List<T> list)
		{
			return list[Random.Range(0, list.Count)];
		}

		public static List<T> ToList<T>(this Array array)
		{
			List<T> list = new List<T>();
			foreach (T item in array)
			{
				list.Add(item);
			}
			return list;
		}

		public static GameObject FindEnemyPrefabByType(Type enemyType, List<SpawnableEnemyWithRarity> enemyList, SelectableLevel newLevel)
		{
			foreach (SpawnableEnemyWithRarity enemy in enemyList)
			{
				if ((Object)(object)enemy.enemyType.enemyPrefab.GetComponent(enemyType) != (Object)null)
				{
					return enemy.enemyType.enemyPrefab;
				}
			}
			foreach (SpawnableEnemyWithRarity enemy2 in newLevel.Enemies)
			{
				if ((Object)(object)enemy2.enemyType.enemyPrefab.GetComponent(enemyType) != (Object)null)
				{
					return enemy2.enemyType.enemyPrefab;
				}
			}
			throw new Exception("Enemy type " + enemyType.Name + " not found and could not be added.");
		}

		public static EnemyAI SpawnEnemyOutside(Type enemyType, bool ForceOutside)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = ((!ForceOutside) ? FindEnemyPrefabByType(enemyType, RoundManager.Instance.currentLevel.OutsideEnemies, RoundManager.Instance.currentLevel) : FindEnemyPrefabByType(enemyType, RoundManager.Instance.currentLevel.Enemies, RoundManager.Instance.currentLevel));
			GameObject[] array = GameObject.FindGameObjectsWithTag("OutsideAINode");
			Vector3 position = array[Random.Range(0, array.Length)].transform.position;
			GameObject val2 = Object.Instantiate<GameObject>(val, position, Quaternion.identity);
			val2.GetComponentInChildren<NetworkObject>().Spawn(true);
			EnemyAI component = val2.GetComponent<EnemyAI>();
			if (ForceOutside)
			{
				component.enemyType.isOutsideEnemy = true;
				component.allAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode");
				component.SyncPositionToClients();
			}
			RoundManager.Instance.SpawnedEnemies.Add(component);
			return component;
		}
	}
	public class Variables
	{
		public static GameObject LandminePrefab { get; set; }
	}
}
namespace LethalChaos.Patches
{
	[HarmonyPatch(typeof(LungProp))]
	public class LungPropPatch
	{
		[HarmonyPatch("DisconnectFromMachinery")]
		[HarmonyPrefix]
		private static void DisconnectPrefix(LungProp __instance)
		{
			((GrabbableObject)__instance).scrapValue = (int)((float)((GrabbableObject)__instance).scrapValue * Utility.CurrentScrapValueMultiplier);
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void OnUpdated(PlayerControllerB __instance)
		{
			__instance.movementSpeed = (SpeedBoost.IsActivated ? 7.5f : 4.5f);
			__instance.climbSpeed = (SpeedBoost.IsActivated ? 9 : 3);
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		private static Coroutine? _coroutine;

		[HarmonyPatch("LoadNewLevel")]
		[HarmonyPrefix]
		private static void OnLevelLoad(RoundManager __instance, ref SelectableLevel newLevel)
		{
			Plugin.Logging.LogInfo((object)("Level Load: " + newLevel.PlanetName));
			SpawnableMapObject[] spawnableMapObjects = RoundManager.Instance.currentLevel.spawnableMapObjects;
			foreach (SpawnableMapObject val in spawnableMapObjects)
			{
				if ((Object)(object)val.prefabToSpawn.GetComponentInChildren<Landmine>() != (Object)null)
				{
					Variables.LandminePrefab = val.prefabToSpawn;
				}
			}
			EventBase.ResetUses();
			EventBase.CurrentPhase = ((!newLevel.PlanetName.Contains("Gordi")) ? Phase.Exploration : Phase.Company);
			if (_coroutine != null)
			{
				((MonoBehaviour)__instance).StopCoroutine(_coroutine);
			}
			Plugin.Logging.LogInfo((object)EventBase.CurrentPhase);
			if (EventBase.CurrentPhase == Phase.Exploration && EventBase.CurrentPhase != 0)
			{
				_coroutine = ((MonoBehaviour)__instance).StartCoroutine(EventCoroutine(newLevel, EventBase.CurrentPhase));
			}
		}

		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPrefix]
		private static void StartScrapSpawn(RoundManager __instance)
		{
			__instance.scrapAmountMultiplier *= Utility.CurrentScrapAmountMultiplier;
			__instance.scrapValueMultiplier *= Utility.CurrentScrapValueMultiplier;
		}

		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPostfix]
		private static void FinishedScrapSpawn(RoundManager __instance)
		{
			__instance.scrapAmountMultiplier /= Utility.CurrentScrapAmountMultiplier;
			__instance.scrapValueMultiplier /= Utility.CurrentScrapValueMultiplier;
			foreach (EventBase item in EventBase.GetFromPhase((EventBase.CurrentPhase != 0) ? Phase.MoonLanding : Phase.Company))
			{
				if (Random.Range(1, 100) <= 25)
				{
					item.Activate();
					item.isUsed = true;
					HUDManager.Instance.AddTextToChatOnServer(item.Text + " has been triggered!", -1);
					Plugin.Logging.LogInfo((object)(item.Text + " has been triggered!"));
				}
			}
		}

		private static IEnumerator EventCoroutine(SelectableLevel level, Phase phase)
		{
			Plugin.Logging.LogInfo((object)"Starting EventCoroutine");
			while ((Object)(object)RoundManager.Instance.currentLevel == (Object)(object)level && EventBase.CurrentPhase == phase)
			{
				yield return (object)new WaitForSeconds(60f);
				Plugin.Logging.LogInfo((object)"Running random event..");
				EventBase ev = EventBase.GetRandomForPhase();
				if (ev != null)
				{
					ev.Activate();
					ev.isUsed = true;
					Plugin.Logging.LogInfo((object)(ev.Text + " has been triggered!"));
					HUDManager.Instance.DisplayTip("Random Event!", ev.Text + " has been triggered!", true, false, "LC_Tip1");
				}
			}
			Plugin.Logging.LogInfo((object)"Finished EventCoroutine");
		}
	}
}