Decompiled source of LethalChungus v1.0.2

jantepyan.lethalchungus.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using LethalChungus.Patches;
using LethalLib.Extras;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using TerminalApi;
using TerminalApi.Classes;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("jantepyan.lethalchungus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalChungus")]
[assembly: AssemblyTitle("jantepyan.lethalchungus")]
[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 LethalChungus
{
	[BepInPlugin("jantepyan.lethalchungus", "LethalChungus", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LethalChungus : BaseUnityPlugin
	{
		public static LethalChungus Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogDebug((object)"Patching...");
			TerminalTeleport.Init(((BaseUnityPlugin)this).Logger);
			TerminalKill.Init(((BaseUnityPlugin)this).Logger);
			CustomOutsideObjects.Init(((BaseUnityPlugin)this).Logger, ((BaseUnityPlugin)this).Info);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"jantepyan.lethalchungus v1.0.0 has loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "jantepyan.lethalchungus";

		public const string PLUGIN_NAME = "LethalChungus";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LethalChungus.Patches
{
	internal static class CustomOutsideObjects
	{
		private const string AssetName = "chungus";

		public static void Init(ManualLogSource logger, PluginInfo info)
		{
			try
			{
				string text = Path.Combine(Path.GetDirectoryName(info.Location), "chungus");
				logger.LogInfo((object)("Loading Asset: " + text));
				AssetBundle assetBundle = AssetBundle.LoadFromFile(text);
				foreach (SpawnableOutsideObjectDef item in CreateOutsideObjectDefinitions(assetBundle))
				{
					logger.LogInfo((object)("Loading object: " + ((Object)item.spawnableMapObject.spawnableObject.prefabToSpawn).name));
					MapObjects.RegisterOutsideObject(item, (LevelTypes)(-1), (Func<SelectableLevel, AnimationCurve>)((SelectableLevel level) => AnimationCurve.Linear(0f, 8f, 1f, 30f)));
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
			}
		}

		private static List<SpawnableOutsideObjectDef> CreateOutsideObjectDefinitions(AssetBundle assetBundle)
		{
			return new List<SpawnableOutsideObjectDef> { CreateOutsideObjectWithRarityDef(assetBundle.LoadAsset<GameObject>("chungusOutside")) };
		}

		private static SpawnableOutsideObjectDef CreateOutsideObjectWithRarityDef(GameObject prefab)
		{
			SpawnableOutsideObjectDef val = ScriptableObject.CreateInstance<SpawnableOutsideObjectDef>();
			val.spawnableMapObject = CreateOutsideObjectWithRarity(prefab);
			((Object)val).name = ((Object)val.spawnableMapObject.spawnableObject).name;
			return val;
		}

		private static SpawnableOutsideObjectWithRarity CreateOutsideObjectWithRarity(GameObject prefab)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			return new SpawnableOutsideObjectWithRarity
			{
				spawnableObject = CreateOutsideObject(prefab)
			};
		}

		private static SpawnableOutsideObject CreateOutsideObject(GameObject prefab)
		{
			SpawnableOutsideObject val = ScriptableObject.CreateInstance<SpawnableOutsideObject>();
			((Object)val).name = ((Object)prefab).name + "_so";
			val.objectWidth = 3;
			val.spawnFacingAwayFromWall = true;
			val.prefabToSpawn = prefab;
			val.spawnableFloorTags = new string[3] { "Grass", "Gravel", "Snow" };
			return val;
		}
	}
	internal class TerminalKill
	{
		public static void Init(ManualLogSource logger)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			try
			{
				CommandInfo val = new CommandInfo();
				val.DisplayTextSupplier = EndGame;
				TerminalApi.AddCommand("fuckit", val, (string)null, true);
				val = new CommandInfo();
				val.DisplayTextSupplier = KillPlayer;
				TerminalApi.AddCommand("kill", val, (string)null, true);
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex.Message);
			}
		}

		private static string EndGame()
		{
			int[] endgameStatsInOrder = StartOfRound.Instance.GetEndgameStatsInOrder();
			StartOfRound.Instance.FirePlayersAfterDeadlineClientRpc(endgameStatsInOrder, true);
			return "lol ok\n\n";
		}

		private static string KillPlayer()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)StartOfRound.Instance.mapScreen == (Object)null || (Object)(object)StartOfRound.Instance.mapScreen.targetedPlayer == (Object)null)
			{
				return "Couldn't find targeted player...";
			}
			PlayerControllerB targetedPlayer = StartOfRound.Instance.mapScreen.targetedPlayer;
			if (targetedPlayer.isPlayerDead)
			{
				return "already dead :p";
			}
			targetedPlayer.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0, default(Vector3));
			return "lol rip\n\n";
		}
	}
	internal static class TerminalTeleport
	{
		private static readonly Random Random = new Random();

		public static void Init(ManualLogSource logger)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			try
			{
				CommandInfo val = new CommandInfo();
				val.DisplayTextSupplier = WrapLineEnding(HandleTeleportCommand);
				TerminalApi.AddCommand("teleport", val, (string)null, false);
				val = new CommandInfo();
				val.DisplayTextSupplier = WrapLineEnding(HandleInverseTeleportKeyword);
				TerminalApi.AddCommand("invteleport", val, (string)null, false);
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex.Message);
			}
		}

		private static Func<string> WrapLineEnding(Func<string> action)
		{
			Func<string> action2 = action;
			return delegate
			{
				try
				{
					return action2() + "\n\n";
				}
				catch (Exception ex)
				{
					return ex.Message;
				}
			};
		}

		private static string HandleInverseTeleportKeyword()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (!ShipTeleporter.hasBeenSpawnedThisSessionInverse)
			{
				return "uh oh need to buy an inverse teleporter";
			}
			ShipTeleporter teleporter = GetTeleporter(isInverseTeleport: true);
			if ((Object)(object)teleporter == (Object)null)
			{
				return "couldn't find inverse teleporter :(";
			}
			PlayerControllerB targetedPlayer = StartOfRound.Instance.mapScreen.targetedPlayer;
			if ((Object)(object)targetedPlayer.deadBody != (Object)null)
			{
				return "nah they dead";
			}
			int num = (int)targetedPlayer.playerClientId;
			Vector3 randomPosition = GetRandomPosition();
			MethodInfo method = ((object)teleporter).GetType().GetMethod("TeleportPlayerOutWithInverseTeleporter", BindingFlags.Instance | BindingFlags.NonPublic);
			method.Invoke(teleporter, new object[2] { num, randomPosition });
			teleporter.TeleportPlayerOutServerRpc(num, randomPosition);
			return "good luck :)";
		}

		private static Vector3 GetRandomPosition()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = RoundManager.Instance.insideAINodes[Random.Next(0, RoundManager.Instance.insideAINodes.Length)].transform.position;
			return RoundManager.Instance.GetRandomNavMeshPositionInBoxPredictable(position, 10f, default(NavMeshHit), Random, -1);
		}

		private static string HandleTeleportCommand()
		{
			if (!ShipTeleporter.hasBeenSpawnedThisSession)
			{
				return "uh oh need to buy a teleporter";
			}
			ShipTeleporter teleporter = GetTeleporter(isInverseTeleport: false);
			if ((Object)(object)teleporter == (Object)null)
			{
				return "couldn't find teleporter :(";
			}
			if (teleporter.cooldownTime > 0f)
			{
				return $"Gotta wait: {(int)teleporter.cooldownTime + 1} secs";
			}
			teleporter.PressTeleportButtonOnLocalClient();
			return "ok fine";
		}

		private static ShipTeleporter GetTeleporter(bool isInverseTeleport)
		{
			ShipTeleporter[] array = Object.FindObjectsOfType<ShipTeleporter>();
			foreach (ShipTeleporter val in array)
			{
				if (val.isInverseTeleporter == isInverseTeleport)
				{
					return val;
				}
			}
			return null;
		}
	}
}