Decompiled source of ChaoticCompany v0.0.1

Chaotic Company.dll

Decompiled 11 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 Chaotic_Company.Helpers;
using Chaotic_Company.Managers;
using Chaotic_Company.Misc;
using GameNetcodeStuff;
using Microsoft.CodeAnalysis;
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 = "")]
[assembly: AssemblyCompany("Chaotic Company")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Chaotic Company")]
[assembly: AssemblyTitle("Chaotic Company")]
[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 Chaotic_Company
{
	[BepInPlugin("com.deja.lethalcompany.chaoticcompany", "Chaotic Company", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin Instance;

		public static ManualLogSource LogSource;

		private void Awake()
		{
			LogSource = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			InitializePlayerSwapManager();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Chaotic Company Player Swap has been initialized.");
		}

		private void InitializePlayerSwapManager()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			GameObject val = new GameObject("PlayerSwapManager");
			val.AddComponent<PlayerSwapManager>();
			Object.DontDestroyOnLoad((Object)(object)val);
		}
	}
}
namespace Chaotic_Company.Misc
{
	public class MultiObjectPool<T> where T : Object
	{
		public T[]? Objects { get; private set; }

		public MultiObjectPool(MonoBehaviour self, float renewInterval = 1f)
		{
			self.StartCoroutine(RenewObjects(renewInterval));
		}

		public void Renew()
		{
			Objects = Object.FindObjectsOfType<T>();
		}

		private IEnumerator RenewObjects(float renewInterval)
		{
			while (true)
			{
				Renew();
				yield return (object)new WaitForSeconds(renewInterval);
			}
		}
	}
	public readonly struct ObjectPlacement<T, M> where T : Transform where M : MonoBehaviour
	{
		public readonly T TargetObject;

		public readonly M GameObject;

		public readonly Vector3 PositionOffset;

		public readonly Vector3 RotationOffset;

		public ObjectPlacement(T targetObject, M gameObject, Vector3 positionOffset, Vector3 rotationOffset)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			TargetObject = targetObject;
			GameObject = gameObject;
			PositionOffset = positionOffset;
			RotationOffset = rotationOffset;
		}
	}
	public readonly struct ObjectPlacements<T, M> where T : Transform where M : MonoBehaviour
	{
		public readonly ObjectPlacement<T, M> Placement;

		public readonly ObjectPlacement<T, M> PreviousPlacement;

		public ObjectPlacements(ObjectPlacement<T, M> placement, ObjectPlacement<T, M> previousPlacement)
		{
			Placement = placement;
			PreviousPlacement = previousPlacement;
		}
	}
	internal static class Metadata
	{
		public const string GUID = "com.deja.lethalcompany.chaoticcompany";

		public const string NAME = "Chaotic Company";

		public const string VERSION = "0.0.1";
	}
	public class Reflector
	{
		private const BindingFlags privateOrInternal = BindingFlags.Instance | BindingFlags.NonPublic;

		private const BindingFlags internalStatic = BindingFlags.Static | BindingFlags.NonPublic;

		private const BindingFlags internalField = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField;

		private const BindingFlags internalProperty = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty;

		private const BindingFlags internalMethod = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod;

		private const BindingFlags internalStaticField = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField;

		private const BindingFlags internalStaticProperty = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetProperty;

		private const BindingFlags internalStaticMethod = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod;

		private object Obj { get; }

		private Type ObjType { get; }

		private Reflector(object obj)
		{
			Obj = obj;
			ObjType = obj.GetType();
		}

		private T? GetField<T>(string variableName, BindingFlags flags)
		{
			try
			{
				return (T)ObjType.GetField(variableName, flags).GetValue(Obj);
			}
			catch (InvalidCastException)
			{
				return default(T);
			}
		}

		private Reflector? GetProperty(string propertyName, BindingFlags flags)
		{
			try
			{
				return new Reflector(ObjType.GetProperty(propertyName, flags).GetValue(Obj, null));
			}
			catch (Exception)
			{
				return null;
			}
		}

		private Reflector? SetField(string variableName, object value, BindingFlags flags)
		{
			try
			{
				ObjType.GetField(variableName, flags).SetValue(Obj, value);
				return this;
			}
			catch (Exception)
			{
				return null;
			}
		}

		private Reflector? SetProperty(string propertyName, object value, BindingFlags flags)
		{
			try
			{
				ObjType.GetProperty(propertyName, flags).SetValue(Obj, value, null);
				return this;
			}
			catch (Exception)
			{
				return null;
			}
		}

		private T? InvokeMethod<T>(string methodName, BindingFlags flags, params object[] args)
		{
			try
			{
				return (T)ObjType.GetMethod(methodName, flags).Invoke(Obj, args);
			}
			catch (InvalidCastException)
			{
				return default(T);
			}
		}

		public T? GetInternalField<T>(string variableName)
		{
			return GetField<T>(variableName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
		}

		public T? GetInternalStaticField<T>(string variableName)
		{
			return GetField<T>(variableName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField);
		}

		public Reflector? GetInternalField(string variableName)
		{
			object obj = GetInternalField(variableName);
			return (obj == null) ? null : new Reflector(obj);
		}

		public Reflector? GetInternalStaticField(string variableName)
		{
			object obj = GetInternalStaticField(variableName);
			return (obj == null) ? null : new Reflector(obj);
		}

		public Reflector? SetInternalField(string variableName, object value)
		{
			return SetField(variableName, value, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
		}

		public Reflector? SetInternalStaticField(string variableName, object value)
		{
			return SetField(variableName, value, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField);
		}

		public Reflector? GetInternalProperty(string propertyName)
		{
			return GetProperty(propertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty);
		}

		public Reflector? SetInternalProperty(string propertyName, object value)
		{
			return SetProperty(propertyName, value, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty);
		}

		public T? InvokeInternalMethod<T>(string methodName, params object[] args)
		{
			return InvokeMethod<T>(methodName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, args);
		}

		public Reflector? InvokeInternalMethod(string methodName, params object[] args)
		{
			object obj = InvokeInternalMethod<object>(methodName, args);
			return (obj == null) ? null : new Reflector(obj);
		}

		public static Reflector Target(object obj)
		{
			return new Reflector(obj);
		}
	}
	public class TPObject : MonoBehaviour
	{
		public static TPObject? Instance { get; private set; }

		public MultiObjectPool<ShipTeleporter> ShipTeleporters { get; private set; }

		private void Awake()
		{
			ShipTeleporters = new MultiObjectPool<ShipTeleporter>((MonoBehaviour)(object)this);
			Instance = this;
		}
	}
	public enum Unlockable
	{
		ORANGE_SUIT,
		GREEN_SUIT,
		HAZARD_SUIT,
		PAJAMA_SUIT,
		COZY_LIGHTS,
		TELEPORTER,
		TELEVISION,
		CUPBOARD,
		FILE_CABINET,
		TOILET,
		SHOWER,
		LIGHT_SWITCH,
		RECORD_PLAYER,
		TABLE,
		ROMANTIC_TABLE,
		BUNKBEDS,
		TERMINAL,
		SIGNAL_TRANSMITTER,
		LOUD_HORN,
		INVERSE_TELEPORTER,
		JACK_O_LANTERN
	}
	public static class UnlockableExtension
	{
		public static bool Is(this Unlockable unlockable, int unlockableId)
		{
			return unlockableId == (int)unlockable;
		}
	}
}
namespace Chaotic_Company.Managers
{
	public class PlayerSwapManager : NetworkBehaviour
	{
		public float minSwapInterval = 5f;

		public float maxSwapInterval = 15f;

		private void Start()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				((MonoBehaviour)this).StartCoroutine(SwapPlayersCoroutine());
			}
		}

		private IEnumerator SwapPlayersCoroutine()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(Random.Range(minSwapInterval, maxSwapInterval));
				RequestSwapPlayersServerRpc();
			}
		}

		[ServerRpc]
		private void RequestSwapPlayersServerRpc()
		{
			SwapPlayerPositions();
		}

		private void SwapPlayerPositions()
		{
			//IL_0062: 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)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB[] players = Helper.Players;
			if (players != null && players.Length > 1)
			{
				Random random = new Random();
				int num = players.Length;
				while (num > 1)
				{
					num--;
					int num2 = random.Next(num + 1);
					PlayerControllerB val = players[num2];
					players[num2] = players[num];
					players[num] = val;
				}
				Vector3 position = ((Component)players[0]).transform.position;
				Vector3 position2 = position;
				for (int i = 1; i < players.Length; i++)
				{
					Vector3 position3 = ((Component)players[i]).transform.position;
					((Component)players[i]).transform.position = position2;
					position2 = position3;
				}
				((Component)players[0]).transform.position = position2;
			}
		}
	}
}
namespace Chaotic_Company.Helpers
{
	public static class Helper
	{
		public static Camera? CurrentCamera => ((Object)(object)LocalPlayer?.gameplayCamera != (Object)null && ((Behaviour)LocalPlayer.gameplayCamera).enabled) ? LocalPlayer.gameplayCamera : StartOfRound?.spectateCamera;

		public static HUDManager? HUDManager => HUDManager.Instance;

		public static RoundManager? RoundManager => RoundManager.Instance;

		private static ShipBuildModeManager? ShipBuildModeManager => ShipBuildModeManager.Instance;

		public static PlayerControllerB? LocalPlayer => GameNetworkManager.Instance.localPlayerController;

		public static PlayerControllerB[]? Players => StartOfRound?.allPlayerScripts;

		public static StartOfRound? StartOfRound => StartOfRound.Instance;

		private static ShipTeleporter[]? ShipTeleporters => TPObject.Instance?.ShipTeleporters.Objects;

		public static ShipTeleporter? InverseTeleporter => ShipTeleporters?.FirstOrDefault((Func<ShipTeleporter, bool>)((ShipTeleporter teleporter) => teleporter.isInverseTeleporter));

		public static ShipTeleporter? Teleporter => ShipTeleporters?.FirstOrDefault((Func<ShipTeleporter, bool>)((ShipTeleporter teleporter) => !teleporter.isInverseTeleporter));

		public static Terminal? Terminal => (HUDManager == null) ? null : Reflector.Target(HUDManager).GetInternalField<Terminal>("terminalScript");

		public static void PrintSystem(string? message)
		{
			if (message == null)
			{
				Console.WriteLine("SYSTEM: [null message]");
			}
			else
			{
				Console.WriteLine("SYSTEM: " + message);
			}
		}

		public static Vector3 Copy(this Vector3 vector)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(vector.x, vector.y, vector.z);
		}

		public static Quaternion Copy(this Quaternion quaternion)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return new Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
		}

		public static GameObject Copy(this Transform transform)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			GameObject val = new GameObject();
			val.transform.position = transform.position.Copy();
			val.transform.eulerAngles = transform.eulerAngles.Copy();
			return val;
		}

		public static T CreateComponent<T>() where T : Component
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return new GameObject().AddComponent<T>();
		}

		public static bool IsNotNull<T>(this T? obj, out T notNullObj) where T : class
		{
			if (obj == null)
			{
				notNullObj = null;
				return false;
			}
			notNullObj = obj;
			return true;
		}

		private static NetworkObject GetNetworkObject<M>(M gameObject) where M : MonoBehaviour
		{
			return ((Component)((Component)(object)gameObject).GetComponentInChildren<PlaceableShipObject>().parentObject).GetComponent<NetworkObject>();
		}

		public static Action<float> PlaceObjectAtTransform<T, M>(T targetObject, M gameObject, Vector3 positionOffset = default(Vector3), Vector3 rotationOffset = default(Vector3)) where T : Transform where M : MonoBehaviour
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			return delegate
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				NetworkObject networkObject = GetNetworkObject(gameObject);
				ShipBuildModeManager? shipBuildModeManager = ShipBuildModeManager;
				if (shipBuildModeManager != null)
				{
					shipBuildModeManager.PlaceShipObjectServerRpc(((Transform)targetObject).position + positionOffset, ((Transform)targetObject).eulerAngles + rotationOffset, NetworkObjectReference.op_Implicit(networkObject), -1);
				}
			};
		}

		public static Action<float> PlaceObjectAtTransform<T, M>(ObjectPlacement<T, M> placement) where T : Transform where M : MonoBehaviour
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return PlaceObjectAtTransform(placement.TargetObject, placement.GameObject, placement.PositionOffset, placement.RotationOffset);
		}

		public static Action<float> PlaceObjectAtPosition<T, M>(T targetObject, M gameObject, Vector3 positionOffset = default(Vector3), Vector3 rotationOffset = default(Vector3)) where T : Transform where M : MonoBehaviour
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			return delegate
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: 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)
				NetworkObject networkObject = GetNetworkObject(gameObject);
				ShipBuildModeManager? shipBuildModeManager = ShipBuildModeManager;
				if (shipBuildModeManager != null)
				{
					shipBuildModeManager.PlaceShipObjectServerRpc(((Transform)targetObject).position + positionOffset, rotationOffset, NetworkObjectReference.op_Implicit(networkObject), -1);
				}
			};
		}

		public static Action<float> PlaceObjectAtPosition<M>(M gameObject, Vector3 position, Vector3 rotation) where M : MonoBehaviour
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			return delegate
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				NetworkObject networkObject = GetNetworkObject(gameObject);
				ShipBuildModeManager? shipBuildModeManager = ShipBuildModeManager;
				if (shipBuildModeManager != null)
				{
					shipBuildModeManager.PlaceShipObjectServerRpc(position, rotation, NetworkObjectReference.op_Implicit(networkObject), -1);
				}
			};
		}

		public static Action<float> PlaceObjectAtPosition<T, M>(ObjectPlacement<T, M> placement) where T : Transform where M : MonoBehaviour
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return PlaceObjectAtPosition(placement.TargetObject, placement.GameObject, placement.PositionOffset, placement.RotationOffset);
		}

		public static PlayerControllerB? GetPlayer(string playerNameOrId)
		{
			PlayerControllerB[] players = Players;
			return players?.FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB player) => player.playerUsername == playerNameOrId)) ?? players?.FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB player) => player.playerClientId.ToString() == playerNameOrId));
		}

		public static PlayerControllerB? GetPlayer(int playerId)
		{
			return GetPlayer(playerId.ToString());
		}

		public static void SwitchRadarTarget(ulong playerClientId)
		{
			StartOfRound? startOfRound = StartOfRound;
			if (startOfRound != null)
			{
				startOfRound.mapScreen.SwitchRadarTargetServerRpc((int)playerClientId);
			}
		}

		public static void SwitchRadarTarget(PlayerControllerB player)
		{
			SwitchRadarTarget(player.playerClientId);
		}

		public static bool Is(this Unlockable unlockable, int unlockableId)
		{
			return unlockableId == (int)unlockable;
		}

		public static void BuyUnlockable(Unlockable unlockable)
		{
			if (!Terminal.IsNotNull<Terminal>(out var notNullObj))
			{
				PrintSystem("Terminal not found!");
				return;
			}
			StartOfRound? startOfRound = StartOfRound;
			if (startOfRound != null)
			{
				startOfRound.BuyShipUnlockableServerRpc((int)unlockable, notNullObj.groupCredits);
			}
		}

		public static PlaceableShipObject? GetUnlockable(Unlockable unlockable)
		{
			return ((IEnumerable<PlaceableShipObject>)Object.FindObjectsOfType<PlaceableShipObject>()).FirstOrDefault((Func<PlaceableShipObject, bool>)((PlaceableShipObject placeableObject) => unlockable.Is(placeableObject.unlockableID)));
		}
	}
}