Decompiled source of ChainedTogether v1.0.0

ChainedTogether.dll

Decompiled 2 weeks ago
using System;
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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ChainedTogether")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Chained Together mechanics for Lethal Company.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChainedTogether")]
[assembly: AssemblyTitle("ChainedTogether")]
[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 ChainedTogetherMod
{
	[BepInPlugin("com.thefuckingkevin.chainedtogether", "Chained Together", "1.0.0")]
	public class ChainedTogetherPlugin : BaseUnityPlugin
	{
		public const string GUID = "com.thefuckingkevin.chainedtogether";

		public const string NAME = "Chained Together";

		public const string VERSION = "1.0.0";

		internal static ManualLogSource Log;

		private readonly Harmony _harmony = new Harmony("com.thefuckingkevin.chainedtogether");

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll(typeof(ChainedTogetherPatches));
			Log.LogInfo((object)"Chained Together 1.0.0 initialized.");
		}
	}
	public class ChainedTogetherManager : MonoBehaviour
	{
		public PlayerControllerB player1;

		public PlayerControllerB player2;

		private LineRenderer _lineRenderer;

		private const float MaxLength = 4f;

		private const float SpringStrength = 15f;

		private float _teleportCooldown = 0f;

		private bool? _sharedInsideState = null;

		private void Start()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			_lineRenderer = ((Component)this).gameObject.AddComponent<LineRenderer>();
			_lineRenderer.positionCount = 2;
			_lineRenderer.startWidth = 0.12f;
			_lineRenderer.endWidth = 0.12f;
			_lineRenderer.textureMode = (LineTextureMode)1;
			((Renderer)_lineRenderer).material = new Material(Shader.Find("Sprites/Default"))
			{
				mainTexture = (Texture)(object)CreateTetherTexture()
			};
		}

		private Texture2D CreateTetherTexture()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			int num = 128;
			Texture2D val = new Texture2D(num, num, (TextureFormat)4, true);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)0;
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.18f, 0.1f, 0.05f);
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.55f, 0.38f, 0.2f);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					float num2 = Mathf.Sin((float)j * 0.1f) * 4f;
					if ((float)i >= 32f + num2 && (float)i <= 96f + num2)
					{
						float num3 = Mathf.Clamp01((Mathf.Sin((float)j * 0.2f + (float)i * 0.2f) + 1f) / 2f + Random.Range(-0.15f, 0.15f));
						val.SetPixel(j, i, Color.Lerp(val3, val4, num3));
					}
					else
					{
						val.SetPixel(j, i, val2);
					}
				}
			}
			val.Apply();
			return val;
		}

		private void Update()
		{
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			if (StartOfRound.Instance.shipIsLeaving)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			if ((Object)(object)player1 == (Object)null || (Object)(object)player2 == (Object)null || player1.isPlayerDead || player2.isPlayerDead)
			{
				((Renderer)_lineRenderer).enabled = false;
				return;
			}
			if (!_sharedInsideState.HasValue)
			{
				_sharedInsideState = player1.isInsideFactory;
			}
			if (_teleportCooldown > 0f)
			{
				_teleportCooldown -= Time.deltaTime;
			}
			if (player1.isInsideFactory != player2.isInsideFactory)
			{
				((Renderer)_lineRenderer).enabled = false;
				HandleDesyncTeleport();
				return;
			}
			_sharedInsideState = player1.isInsideFactory;
			((Renderer)_lineRenderer).enabled = true;
			Vector3 val = ((Component)player1).transform.position + Vector3.up * 1.2f;
			Vector3 val2 = ((Component)player2).transform.position + Vector3.up * 1.2f;
			_lineRenderer.SetPosition(0, val);
			_lineRenderer.SetPosition(1, val2);
			float num = Vector3.Distance(val, val2);
			((Renderer)_lineRenderer).material.mainTextureScale = new Vector2(num * 3f, 1f);
			if (num > 4f)
			{
				Vector3 val3 = val - val2;
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				Vector3 val4 = Vector3.ClampMagnitude(normalized * (num - 4f) * 15f, 25f);
				if (((NetworkBehaviour)player1).IsOwner)
				{
					ApplyForce(player1, -val4);
				}
				if (((NetworkBehaviour)player2).IsOwner)
				{
					ApplyForce(player2, val4);
				}
			}
		}

		private void ApplyForce(PlayerControllerB p, Vector3 f)
		{
			//IL_0001: 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_0029: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			if (f.y < 0f)
			{
				f.y *= 0.1f;
			}
			p.externalForceAutoFade += f * Time.deltaTime;
		}

		private void HandleDesyncTeleport()
		{
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null || _teleportCooldown > 0f)
			{
				return;
			}
			PlayerControllerB target = (((Object)(object)localPlayerController == (Object)(object)player1) ? player2 : (((Object)(object)localPlayerController == (Object)(object)player2) ? player1 : null));
			if ((Object)(object)target != (Object)null && localPlayerController.isInsideFactory == _sharedInsideState)
			{
				EntranceTeleport val = ((IEnumerable<EntranceTeleport>)Object.FindObjectsOfType<EntranceTeleport>()).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport d) => d.isEntranceToBuilding == target.isInsideFactory));
				if ((Object)(object)val != (Object)null)
				{
					val.TeleportPlayer();
					_teleportCooldown = 4f;
				}
			}
		}
	}
	public class ChainedTogetherPatches
	{
		private static bool _spawned;

		[HarmonyPatch(typeof(StartOfRound), "Update")]
		[HarmonyPostfix]
		public static void CheckRoundState(StartOfRound __instance)
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			if (__instance.inShipPhase)
			{
				_spawned = false;
			}
			else
			{
				if (__instance.inShipPhase || _spawned)
				{
					return;
				}
				_spawned = true;
				Random random = new Random(__instance.randomMapSeed);
				if (random.Next(0, 10) != 0)
				{
					return;
				}
				List<PlayerControllerB> list = __instance.allPlayerScripts.Where((PlayerControllerB p) => p.isPlayerControlled && !p.isPlayerDead).ToList();
				if (list.Count >= 2)
				{
					for (int num = list.Count - 1; num > 0; num--)
					{
						int index = random.Next(num + 1);
						PlayerControllerB value = list[index];
						list[index] = list[num];
						list[num] = value;
					}
					GameObject val = new GameObject("ChainedTogetherManager");
					ChainedTogetherManager chainedTogetherManager = val.AddComponent<ChainedTogetherManager>();
					chainedTogetherManager.player1 = list[0];
					chainedTogetherManager.player2 = list[1];
				}
			}
		}
	}
}