Decompiled source of Public screen chat v1.0.1

Public_screen_chat.dll

Decompiled a month 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 ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
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("XiaoLei")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Public_screen_chat")]
[assembly: AssemblyTitle("Public_screen_chat")]
[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;
		}
	}
}
public static class ChatListGUI
{
	public class ChatLine
	{
		public string PlayerName;

		public string Message;

		public Color PlayerColor;

		public ChatLine(string playerName, string message, Color color)
		{
			//IL_0017: 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)
			PlayerName = playerName;
			Message = message;
			PlayerColor = color;
		}
	}

	private static readonly List<ChatLine> chatLines = new List<ChatLine>();

	public static int MaxLines = 15;

	private static float lastMessageTime = -100f;

	private static float visibleDuration = 10f;

	private static float fadeDuration = 0.5f;

	private static float alpha = 0f;

	public static void Add(string playerName, string message, Color color)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		chatLines.Add(new ChatLine(playerName, message, color));
		if (chatLines.Count > MaxLines)
		{
			chatLines.RemoveAt(0);
		}
		lastMessageTime = Time.time;
	}

	public static void Clear()
	{
		chatLines.Clear();
		lastMessageTime = -100f;
		alpha = 0f;
	}

	public static void OnGUI()
	{
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Expected O, but got Unknown
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		if (chatLines.Count == 0 && alpha <= 0f)
		{
			return;
		}
		float num = ((chatLines.Count > 0 && Time.time - lastMessageTime <= visibleDuration) ? 1f : 0f);
		float num2 = Time.deltaTime / fadeDuration;
		alpha = Mathf.MoveTowards(alpha, num, num2);
		if (alpha <= 0f)
		{
			return;
		}
		int num3 = 400;
		int num4 = 20;
		int num5 = (Screen.height - 360) / 2;
		int num6 = 12;
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)0,
			fontSize = 20,
			wordWrap = true
		};
		float num7 = 0f;
		List<float> list = new List<float>();
		foreach (ChatLine chatLine2 in chatLines)
		{
			string text = chatLine2.PlayerName + ":" + chatLine2.Message;
			float num8 = val.CalcHeight(new GUIContent(text), (float)num3);
			list.Add(num8);
			num7 += num8;
		}
		GUI.color = new Color(0f, 0f, 0f, 0.6f * alpha);
		GUI.Box(new Rect((float)(num4 - num6), (float)(num5 - num6), (float)(num3 + num6 * 2), num7 + (float)(num6 * 2)), GUIContent.none);
		float num9 = num5;
		for (int i = 0; i < chatLines.Count; i++)
		{
			ChatLine chatLine = chatLines[i];
			string text2 = chatLine.PlayerName + ":" + chatLine.Message;
			GUI.color = new Color(chatLine.PlayerColor.r, chatLine.PlayerColor.g, chatLine.PlayerColor.b, alpha);
			GUI.Label(new Rect((float)num4, num9, (float)num3, list[i]), text2, val);
			num9 += list[i];
		}
		GUI.color = Color.white;
	}
}
namespace Public_screen_chat
{
	internal static class ChineseInputGUI
	{
		private static bool _showInput = false;

		private static string _inputText = "";

		public static bool IsInputActive => _showInput;

		public static void Open()
		{
			_showInput = true;
			_inputText = "";
		}

		public static void Close()
		{
			_showInput = false;
			_inputText = "";
		}

		public static void Update()
		{
		}

		public static void OnGUI(Action<string>? onSubmit = null)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0072: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Invalid comparison between Unknown and I4
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Invalid comparison between Unknown and I4
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Invalid comparison between Unknown and I4
			if (_showInput)
			{
				Event current = Event.current;
				int num = 100;
				int num2 = 700;
				int num3 = 60;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor((float)((Screen.width - num2) / 2), (float)(Screen.height - num3 - num), (float)num2, (float)num3);
				GUI.SetNextControlName("ChatInputField");
				GUIStyle val2 = new GUIStyle(GUI.skin.textField)
				{
					fontSize = 28,
					alignment = (TextAnchor)3
				};
				_inputText = GUI.TextField(val, _inputText, 200, val2);
				GUI.FocusControl("ChatInputField");
				if (current.isKey && ((int)current.keyCode == 13 || (int)current.keyCode == 271))
				{
					_showInput = false;
					string inputText = _inputText;
					_inputText = "";
					onSubmit?.Invoke(inputText);
					current.Use();
				}
				else if (current.isKey && (int)current.keyCode == 27)
				{
					_showInput = false;
					_inputText = "";
					current.Use();
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController))]
	internal static class ExamplePlayerControllerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		private static void Start_Prefix(PlayerController __instance)
		{
			Public_screen_chat.Logger.LogDebug((object)$"{__instance} Start Prefix");
		}

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Start_Postfix(PlayerController __instance)
		{
			Public_screen_chat.Logger.LogDebug((object)$"{__instance} Start Postfix");
		}
	}
	[HarmonyPatch(typeof(SemiFunc), "InputDown", new Type[] { typeof(InputKey) })]
	internal class Patch_SemiFunc_InputDown
	{
		private static readonly InputKey[] DisableKeysInInput;

		private static bool Prefix(InputKey key, ref bool __result)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (ChineseInputGUI.IsInputActive && DisableKeysInInput.Contains(key))
			{
				__result = false;
				return false;
			}
			return true;
		}

		static Patch_SemiFunc_InputDown()
		{
			InputKey[] array = new InputKey[7];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			DisableKeysInInput = (InputKey[])(object)array;
		}
	}
	[HarmonyPatch(typeof(InputManager), "FixedUpdate")]
	internal class Patch_InputManager_FixedUpdate
	{
		private static void Postfix(InputManager __instance)
		{
			if (ChineseInputGUI.IsInputActive)
			{
				__instance.DisableMovement();
			}
		}
	}
	[BepInPlugin("XiaoLei.Public_screen_chat", "Public_screen_chat", "1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Public_screen_chat : BaseUnityPlugin
	{
		internal static Public_screen_chat Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		public static NetworkedEvent ChatEvent { get; private set; }

		private void Awake()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			ChatEvent = new NetworkedEvent("PublicChatEvent", (Action<EventData>)OnChatEventReceived);
			Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			val.PatchAll();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private void Update()
		{
			if (!PhotonNetwork.InRoom)
			{
				ChineseInputGUI.Close();
				ChatListGUI.Clear();
				return;
			}
			ChineseInputGUI.Update();
			if (Input.GetKeyDown((KeyCode)121) && !ChineseInputGUI.IsInputActive)
			{
				ChineseInputGUI.Open();
			}
		}

		private void OnGUI()
		{
			if (!PhotonNetwork.InRoom)
			{
				return;
			}
			ChineseInputGUI.OnGUI(delegate(string inputText)
			{
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)PlayerAvatar.instance == (Object)null || (Object)(object)StatsManager.instance == (Object)null)
				{
					Logger.LogWarning((object)"玩家信息未初始化,无法发送聊天信息。");
				}
				else
				{
					string nickName = PhotonNetwork.NickName;
					string steamID = PlayerAvatar.instance.steamID;
					Dictionary<string, int> playerColor = StatsManager.instance.playerColor;
					if (!playerColor.ContainsKey(steamID))
					{
						StatsManager.instance.SetPlayerColor(steamID, 0);
						Logger.LogWarning((object)("[完善] 本地playerColor表无自己(" + steamID + "),已分配默认色0。"));
					}
					int num = 0;
					try
					{
						num = StatsManager.instance.GetPlayerColor(steamID);
					}
					catch
					{
						Logger.LogWarning((object)"GetPlayerColor异常,使用默认色0");
					}
					ChatEvent.RaiseEvent((object)new object[4] { nickName, steamID, inputText, num }, NetworkingEvents.RaiseAll, SendOptions.SendReliable);
				}
			});
			ChatListGUI.OnGUI();
		}

		private static void OnChatEventReceived(EventData eventData)
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			if (eventData.CustomData is object[] array && array.Length >= 4)
			{
				string text = (array[0] as string) ?? string.Empty;
				string text2 = (array[1] as string) ?? string.Empty;
				string message = (array[2] as string) ?? string.Empty;
				int result = 0;
				object obj = array[3];
				if (obj is int num)
				{
					result = num;
				}
				else if (obj is long num2)
				{
					result = (int)num2;
				}
				else if (obj is float num3)
				{
					result = (int)num3;
				}
				else if (obj != null)
				{
					int.TryParse(obj.ToString(), out result);
				}
				Color color = Color.white;
				List<Color> list = AssetManager.instance?.playerColors;
				if (list != null && result >= 0 && result < list.Count)
				{
					color = list[result];
				}
				else
				{
					Logger.LogWarning((object)$"【显示消息】sender={text}, 下标={result}, colors.Count={list?.Count ?? 0},取色失败,用白色");
				}
				ChatListGUI.Add(text, message, color);
			}
		}
	}
}