Decompiled source of LethalTwitchChat Client v0.1.0

LethalTwitchChat.Client.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LethalTwitchChat.Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("linkoid.lethaltwitchchat.client")]
[assembly: AssemblyCopyright("Copyright © linkoid 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: InternalsVisibleTo("LethalTwitchChat")]
[assembly: InternalsVisibleTo("LethalTwitchChat.Tests")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.36272")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
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 LethalTwitchChat.Client
{
	[HarmonyPatch]
	internal class EventFeed : MonoBehaviour
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static RpcReceiveHandler <0>____rpc_handler_1594719134;

			public static RpcReceiveHandler <1>____rpc_handler_1594719135;
		}

		private Canvas canvas;

		private RectTransform messageContainer;

		private Dictionary<int, RectTransform> messages = new Dictionary<int, RectTransform>();

		private bool useInGameChat = true;

		private bool useCustomPanel = false;

		private const uint RPC_ID_AddEventMessageClientRPC = 1594719134u;

		private const uint RPC_ID_RemoveEventMessageClientRPC = 1594719135u;

		public static EventFeed Instance { get; private set; }

		[HarmonyPrepare]
		private static void InitializeRPCS()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			Dictionary<uint, RpcReceiveHandler> _rpc_func_table = NetworkManager.__rpc_func_table;
			object obj = <>O.<0>____rpc_handler_1594719134;
			if (obj == null)
			{
				RpcReceiveHandler val = __rpc_handler_1594719134;
				<>O.<0>____rpc_handler_1594719134 = val;
				obj = (object)val;
			}
			_rpc_func_table.Add(1594719134u, (RpcReceiveHandler)obj);
			Dictionary<uint, RpcReceiveHandler> _rpc_func_table2 = NetworkManager.__rpc_func_table;
			object obj2 = <>O.<1>____rpc_handler_1594719135;
			if (obj2 == null)
			{
				RpcReceiveHandler val2 = __rpc_handler_1594719135;
				<>O.<1>____rpc_handler_1594719135 = val2;
				obj2 = (object)val2;
			}
			_rpc_func_table2.Add(1594719135u, (RpcReceiveHandler)obj2);
		}

		private void Awake()
		{
			Instance = this;
		}

		private void Start()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			canvas = ((Component)this).gameObject.AddComponent<Canvas>();
			messageContainer = new GameObject("MessageContainer").AddComponent<RectTransform>();
			((Component)messageContainer).transform.SetParent(((Component)canvas).transform, false);
			((Component)messageContainer).gameObject.AddComponent<VerticalLayoutGroup>();
		}

		public void AddEventMessage(ICommandObject key, string text)
		{
			if (key == null)
			{
				throw new ArgumentNullException("key");
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if (!((Object)(object)localPlayerController == (Object)null))
			{
				AddEventMessageClientRPC(localPlayerController, key.GetInstanceID(), text);
			}
		}

		private void AddEventMessageInternal(int key, string text)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if (useInGameChat && (Object)(object)HUDManager.Instance != (Object)null && !string.IsNullOrWhiteSpace(text))
			{
				string lastChatMessage = HUDManager.Instance.lastChatMessage;
				HUDManager.Instance.AddChatMessage("<color=#8040FF>" + text + "</color>", "");
				HUDManager.Instance.lastChatMessage = lastChatMessage;
			}
			if (useCustomPanel)
			{
				RectTransform val = new GameObject("message").AddComponent<RectTransform>();
				((Transform)val).SetParent((Transform)(object)messageContainer, false);
				TextMeshProUGUI val2 = ((Component)val).gameObject.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val2).text = text;
				((Behaviour)val2).enabled = !string.IsNullOrWhiteSpace(text);
				messages.Add(key, val);
			}
		}

		public void RemoveEventMessage(ICommandObject key)
		{
			if (key == null)
			{
				throw new ArgumentNullException("key");
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if (!((Object)(object)localPlayerController == (Object)null))
			{
				RemoveEventMessageClientRPC(localPlayerController, key.GetInstanceID());
			}
		}

		private void RemoveEventMessageInternal(int key)
		{
			if (messages.ContainsKey(key))
			{
				Object.Destroy((Object)(object)((Component)messages[key]).gameObject);
				messages.Remove(key);
			}
		}

		private static void AddEventMessageClientRPC(PlayerControllerB player, int key, string text)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Invalid comparison between Unknown and I4
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			LethalTwitchChatClientPlugin.Logger.LogDebug((object)"AddEventMessageClientRPC");
			NetworkManager networkManager = ((NetworkBehaviour)player).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)player).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					LethalTwitchChatClientPlugin.Logger.LogDebug((object)"AddEventMessageClientRPC: SendClientRpc(AddEventMessageClientRPC)");
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)player).__beginSendClientRpc(1594719134u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, key);
					((FastBufferWriter)(ref val2)).WriteValueSafe(text, false);
					((NetworkBehaviour)player).__endSendClientRpc(ref val2, 1594719134u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)player).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					LethalTwitchChatClientPlugin.Logger.LogDebug((object)"AddEventMessageClientRPC: AddEventMessageInternal");
					Instance.AddEventMessageInternal(key, text);
				}
			}
		}

		private static void RemoveEventMessageClientRPC(PlayerControllerB player, int key)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			LethalTwitchChatClientPlugin.Logger.LogDebug((object)"RemoveEventMessageClientRPC");
			NetworkManager networkManager = ((NetworkBehaviour)player).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)player).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					LethalTwitchChatClientPlugin.Logger.LogDebug((object)"RemoveEventMessageClientRPC: SendClientRpc(AddEventMessageClientRPC)");
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)player).__beginSendClientRpc(1594719135u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, key);
					((NetworkBehaviour)player).__endSendClientRpc(ref val2, 1594719135u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)player).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					LethalTwitchChatClientPlugin.Logger.LogDebug((object)"RemoveEventMessageClientRPC: AddEventMessageInternal");
					Instance.RemoveEventMessageInternal(key);
				}
			}
		}

		private static void __rpc_handler_1594719134(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0019: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int key = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref key);
				string text = default(string);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				AddEventMessageClientRPC((PlayerControllerB)(object)((target is PlayerControllerB) ? target : null), key, text);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1594719135(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0019: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int key = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref key);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				RemoveEventMessageClientRPC((PlayerControllerB)(object)((target is PlayerControllerB) ? target : null), key);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}
	}
	internal interface ICommandObject
	{
		int GetInstanceID();
	}
	[BepInPlugin("linkoid.lethaltwitchchat.client", "Lethal Twitch Chat Client", "0.1.0")]
	public class LethalTwitchChatClientPlugin : BaseUnityPlugin
	{
		internal static LethalTwitchChatClientPlugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Initialize();
		}

		internal void Initialize()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			Harmony val = new Harmony("linkoid.lethaltwitchchat.client");
			val.PatchAll();
			GameObject val2 = new GameObject("LethalTwitchChatEventFeed");
			Object.DontDestroyOnLoad((Object)(object)val2);
			((Object)val2).hideFlags = (HideFlags)61;
			val2.AddComponent<EventFeed>();
			((BaseUnityPlugin)this).Config.Save();
			Logger.LogDebug((object)"LethalTwitchChatClientPlugin initialized");
		}
	}
	public static class PluginInfo
	{
		internal const string GUID = "linkoid.lethaltwitchchat.client";

		internal const string NAME = "Lethal Twitch Chat Client";

		internal const string VERSION = "0.1.0";

		public static readonly string Guid = "linkoid.lethaltwitchchat.client";

		public static readonly string Name = "Lethal Twitch Chat Client";

		public static readonly string Version = "0.1.0";
	}
	[HarmonyPatch]
	internal class TeleporterPatches
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static RpcReceiveHandler <0>____rpc_handler_3896195649;
		}

		private const uint RPC_ID_TeleportRemotePlayerOutClientRpc = 3896195649u;

		[HarmonyPrepare]
		private static void InitializeRPCS()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Dictionary<uint, RpcReceiveHandler> _rpc_func_table = NetworkManager.__rpc_func_table;
			object obj = <>O.<0>____rpc_handler_3896195649;
			if (obj == null)
			{
				RpcReceiveHandler val = __rpc_handler_3896195649;
				<>O.<0>____rpc_handler_3896195649 = val;
				obj = (object)val;
			}
			_rpc_func_table.Add(3896195649u, (RpcReceiveHandler)obj);
		}

		public static void TeleportRemotePlayerOutClientRpc(ShipTeleporter shipTeleporter, int playerObj, Vector3 teleportPos)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Invalid comparison between Unknown and I4
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			LethalTwitchChatClientPlugin.Logger.LogDebug((object)"TeleportRemotePlayerOutClientRpc");
			NetworkManager networkManager = ((NetworkBehaviour)shipTeleporter).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)shipTeleporter).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					LethalTwitchChatClientPlugin.Logger.LogDebug((object)"TeleportRemotePlayerOutClientRpc: SendClientRpc(TeleportRemotePlayerOutClientRpc)");
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)shipTeleporter).__beginSendClientRpc(3896195649u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, playerObj);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref teleportPos);
					((NetworkBehaviour)shipTeleporter).__endSendClientRpc(ref val2, 3896195649u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)shipTeleporter).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !StartOfRound.Instance.inShipPhase)
				{
					LethalTwitchChatClientPlugin.Logger.LogDebug((object)"TeleportRemotePlayerOutClientRpc: TeleportPlayerOutWithInverseTeleporter");
					shipTeleporter.TeleportPlayerOutWithInverseTeleporter(playerObj, teleportPos);
				}
			}
		}

		private static void __rpc_handler_3896195649(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0019: 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_003a: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerObj = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerObj);
				Vector3 teleportPos = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref teleportPos);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				TeleportRemotePlayerOutClientRpc((ShipTeleporter)(object)((target is ShipTeleporter) ? target : null), playerObj, teleportPos);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}
	}
}