LethalCompanyRandomizer.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using Randomizer.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LethalCompanyRandomizer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A Randomizer for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7+4091abc2e5ef2875e33212b894a9f33601625b22")]
[assembly: AssemblyProduct("LethalCompanyRandomizer")]
[assembly: AssemblyTitle("LethalCompanyRandomizer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.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 LethalCompanyRandomizer
{
	[BepInPlugin("Randomizer", "Lethal Company Randomizer", "1.0.7")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "Randomizer";

		private const string PLUGIN_NAME = "Lethal Company Randomizer";

		private const string PLUGIN_VERSION = "1.0.7";

		private readonly Harmony harmony = new Harmony("Randomizer");

		private void Awake()
		{
			Debug.Log((object)"I'm a cowboy");
			harmony.PatchAll(typeof(ChooseRandom));
			harmony.PatchAll(typeof(ChangeScrap));
			harmony.PatchAll(typeof(ChangeMapObjects));
			harmony.PatchAll(typeof(ChangeOutsideEnemies));
			harmony.PatchAll(typeof(ChangeInsideEnemies));
			harmony.PatchAll(typeof(ChangeText));
			harmony.PatchAll(typeof(CheckStartOfRound));
		}
	}
}
namespace Randomizer
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalCompanyRandomizer";

		public const string PLUGIN_NAME = "LethalCompanyRandomizer";

		public const string PLUGIN_VERSION = "1.0.7";
	}
}
namespace Randomizer.Patches
{
	public class ChooseRandom
	{
		public static SelectableLevel RealLevel;

		public static SelectableLevel ScrapLevel;

		public static SelectableLevel IndoorEnemiesLevel;

		public static SelectableLevel OutdoorEnemiesLevel;

		[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
		[HarmonyPrefix]
		public static void Randomize(RoundManager __instance)
		{
			RealLevel = __instance.currentLevel;
			ScrapLevel = RoundManager.Instance.playersManager.levels[new Random().Next(0, RoundManager.Instance.playersManager.levels.Length)];
			IndoorEnemiesLevel = RoundManager.Instance.playersManager.levels[new Random().Next(0, RoundManager.Instance.playersManager.levels.Length)];
			OutdoorEnemiesLevel = RoundManager.Instance.playersManager.levels[new Random().Next(0, RoundManager.Instance.playersManager.levels.Length)];
			while (OutdoorEnemiesLevel.PlanetName == "44 Liquidation")
			{
				OutdoorEnemiesLevel = RoundManager.Instance.playersManager.levels[new Random().Next(0, RoundManager.Instance.playersManager.levels.Length)];
				Debug.Log((object)(OutdoorEnemiesLevel.PlanetName + " was liquidation before"));
			}
		}
	}
	public class CheckStartOfRound
	{
		[HarmonyPatch(typeof(StartOfRound), "StartGame")]
		[HarmonyPrefix]
		public static void StartGame(StartOfRound __instance)
		{
			Debug.Log((object)(__instance.currentLevel.PlanetName + " Start of Game Instance Level"));
		}

		[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
		[HarmonyPrefix]
		public static void EndOfGame(StartOfRound __instance)
		{
			Debug.Log((object)(__instance.currentLevel.PlanetName + " End Of Game Instance Level"));
		}
	}
	public class ChangeScrap
	{
		public static SelectableLevel PickedLevel;

		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		[HarmonyPrefix]
		public static void RandomizeScrap(RoundManager __instance)
		{
			Debug.Log((object)__instance.currentLevel.PlanetName);
			Debug.Log((object)ChooseRandom.ScrapLevel.PlanetName);
			while (ChooseRandom.ScrapLevel.PlanetName == "71 Gordion")
			{
				ChooseRandom.ScrapLevel = RoundManager.Instance.playersManager.levels[new Random().Next(0, RoundManager.Instance.playersManager.levels.Length)];
			}
			Debug.Log((object)ChooseRandom.ScrapLevel.PlanetName);
			__instance.currentLevel = ChooseRandom.ScrapLevel;
			PickedLevel = __instance.currentLevel;
		}
	}
	public class ChangeMapObjects
	{
		[HarmonyPatch(typeof(RoundManager), "SpawnMapObjects")]
		[HarmonyPrefix]
		public static void ChangeLevel(RoundManager __instance)
		{
			SelectableLevel pickedLevel = ChangeScrap.PickedLevel;
			__instance.currentLevel = pickedLevel;
			Debug.Log((object)__instance.currentLevel.PlanetName);
		}
	}
	public class ChangeOutsideEnemies
	{
		[HarmonyPatch(typeof(RoundManager), "PredictAllOutsideEnemies")]
		[HarmonyPrefix]
		public static void ChooseOutsideEnemies(RoundManager __instance)
		{
			__instance.currentLevel = ChooseRandom.OutdoorEnemiesLevel;
			Debug.Log((object)("Outside Enemies: " + __instance.currentLevel.PlanetName));
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnEnemiesOutside")]
		[HarmonyPrefix]
		public static void SpawnOutsideEnemies(RoundManager __instance)
		{
			__instance.currentLevel = ChooseRandom.OutdoorEnemiesLevel;
			Debug.Log((object)("Outside Enemies: " + __instance.currentLevel.PlanetName));
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnRandomOutsideEnemy")]
		[HarmonyPrefix]
		public static void SpawnOutsideEnemy(RoundManager __instance)
		{
			__instance.currentLevel = ChooseRandom.OutdoorEnemiesLevel;
		}

		[HarmonyPatch(typeof(RoundManager), "RefreshEnemiesList")]
		[HarmonyPrefix]
		public static void RefreshEnemyList(RoundManager __instance)
		{
			__instance.currentLevel.maxOutsideEnemyPowerCount = ChooseRandom.OutdoorEnemiesLevel.maxOutsideEnemyPowerCount;
		}
	}
	public class ChangeInsideEnemies
	{
		[HarmonyPatch(typeof(RoundManager), "PlotOutEnemiesForNextHour")]
		[HarmonyPrefix]
		public static void PlotOutEnemiesForNextHour(RoundManager __instance)
		{
			__instance.currentLevel = ChooseRandom.IndoorEnemiesLevel;
		}

		[HarmonyPatch(typeof(RoundManager), "AssignRandomEnemyToVent")]
		[HarmonyPrefix]
		public static void AssignRandomEnemyToVent(RoundManager __instance)
		{
			__instance.currentLevel = ChooseRandom.IndoorEnemiesLevel;
		}

		[HarmonyPatch(typeof(RoundManager), "EnemyCannotBeSpawned")]
		[HarmonyPrefix]
		public static void EnemyCannotBeSpawned(RoundManager __instance)
		{
			__instance.currentLevel = ChooseRandom.IndoorEnemiesLevel;
		}

		[HarmonyPatch(typeof(RoundManager), "BeginEnemySpawning")]
		[HarmonyPrefix]
		public static void BeginEnemySpawning(RoundManager __instance)
		{
			__instance.currentLevel = ChooseRandom.IndoorEnemiesLevel;
		}

		[HarmonyPatch(typeof(RoundManager), "RefreshEnemiesList")]
		[HarmonyPrefix]
		public static void RefreshEnemyList(RoundManager __instance)
		{
			__instance.currentLevel.maxEnemyPowerCount = ChooseRandom.IndoorEnemiesLevel.maxEnemyPowerCount;
		}
	}
	public class ChangeText
	{
		private static LNetworkMessage<string> EventMessage = LNetworkMessage<string>.Connect("ServerSendAnnouncment", (Action<string, ulong>)null, (Action<string>)null, (Action<string, ulong>)null);

		private static string _planetScrap;

		private static string _planetEnemies;

		private static string _planetOutside;

		[HarmonyPatch(typeof(StartOfRound), "ShipHasLeft")]
		[HarmonyPrefix]
		public static void SendPlanets(StartOfRound __instance)
		{
			try
			{
				EventMessage.OnClientReceived += EventMessageOnOnClientReceived;
				if (((NetworkBehaviour)__instance).IsServer)
				{
					string text = ChooseRandom.ScrapLevel.PlanetName ?? "Unknown";
					string text2 = ChooseRandom.IndoorEnemiesLevel.PlanetName ?? "Unknown";
					string text3 = ChooseRandom.OutdoorEnemiesLevel.PlanetName ?? "Unknown";
					EventMessage.SendClients(text + "/" + text2 + "/" + text3);
				}
				EventMessage.OnClientReceived -= EventMessageOnOnClientReceived;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error in SendPlanets: " + ex.Message + "\n" + ex.StackTrace));
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "WritePlayerNotes")]
		[HarmonyPostfix]
		public static void Update(StartOfRound __instance)
		{
			try
			{
				__instance.gameStats.allPlayerStats[0].playerNotes.Clear();
				__instance.gameStats.allPlayerStats[0].playerNotes.Add("S:" + _planetScrap);
				__instance.gameStats.allPlayerStats[0].playerNotes.Add("IE:" + _planetEnemies);
				__instance.gameStats.allPlayerStats[0].playerNotes.Add("OE:" + _planetOutside);
			}
			catch (Exception ex)
			{
				Debug.Log((object)ex);
			}
		}

		private static void EventMessageOnOnClientReceived(string obj)
		{
			string[] array = obj.Split('/');
			Debug.Log((object)("EventMessageOnOnClientReceived: " + array[0] + "/" + array[1] + "/" + array[2]));
			_planetScrap = array[0];
			_planetEnemies = array[1];
			_planetOutside = array[2];
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}