Decompiled source of ChatChaos v0.44.0

ChatChaos.dll

Decompiled 24 seconds ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Security;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ChatChaos.Config;
using ChatChaos.Core;
using ChatChaos.Events;
using ChatChaos.Localization;
using ChatChaos.Logging;
using ChatChaos.NetcodePatcher;
using ChatChaos.Networking;
using ChatChaos.Twitch;
using ChatChaos.UI;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[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("ChatChaos")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.44.0.0")]
[assembly: AssemblyInformationalVersion("0.44.0+d436ee288b9eea4d12398bc54579cd27f0606b27")]
[assembly: AssemblyProduct("ChatChaos")]
[assembly: AssemblyTitle("ChatChaos")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.44.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 ChatChaos
{
	[BepInPlugin("Remilulz_91.ChatChaos", "ChatChaos", "0.44.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Author = "Remilulz_91";

		public const string Guid = "Remilulz_91.ChatChaos";

		public const string Name = "ChatChaos";

		public const string Version = "0.44.0";

		private readonly Harmony _harmony = new Harmony("Remilulz_91.ChatChaos");

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			Loc.Init();
			EventRegistry.RegisterDefaults();
			try
			{
				_harmony.PatchAll();
				PollTicker.EnsureExists();
				Log.LogInfo((object)("ChatChaos v0.44.0 by Remilulz_91 loaded. " + $"{EventRegistry.Count} event(s) registered. Language: {Loc.Current}."));
				Log.LogInfo((object)"Inspired by Sehelitar's Twitch-integration mod (moderator for MrTiboute).");
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to apply Harmony patches: {arg}");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ChatChaos";

		public const string PLUGIN_NAME = "ChatChaos";

		public const string PLUGIN_VERSION = "0.44.0";
	}
}
namespace ChatChaos.UI
{
	public class BerserkHud : MonoBehaviour
	{
		private static readonly Color SignalColor = Color32.op_Implicit(new Color32((byte)80, (byte)240, (byte)90, byte.MaxValue));

		private static readonly Color BerserkColor = Color32.op_Implicit(new Color32((byte)230, (byte)40, (byte)40, byte.MaxValue));

		private const string SignalLine = "RECEIVING SIGNAL";

		private const string BerserkLine = "GO BERSERK";

		private const float SignalTypeDur = 1.3f;

		private const float BerserkStart = 1.7f;

		private const float BerserkTypeDur = 1.1f;

		private const float TotalDur = 3.4f;

		private RectTransform _panel;

		private Text _signal;

		private Text _berserk;

		private Sprite _white;

		private bool _active;

		private float _start;

		public static BerserkHud? Instance { get; private set; }

		public static void EnsureExists()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				GameObject val = new GameObject("ChatChaos_BerserkHud");
				Object.DontDestroyOnLoad((Object)(object)val);
				((Object)val).hideFlags = (HideFlags)61;
				Instance = val.AddComponent<BerserkHud>();
			}
		}

		private void Awake()
		{
			Build();
			SetVisible(v: false);
		}

		public void ShowSignal()
		{
			_active = true;
			_start = Time.time;
			_signal.text = "";
			_berserk.text = "";
			SetVisible(v: true);
		}

		private void Update()
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if (_active)
			{
				float num = Time.time - _start;
				int length = Mathf.Clamp(Mathf.FloorToInt((float)"RECEIVING SIGNAL".Length * (num / 1.3f)), 0, "RECEIVING SIGNAL".Length);
				_signal.text = "RECEIVING SIGNAL".Substring(0, length);
				if (num >= 1.7f)
				{
					float num2 = (num - 1.7f) / 1.1f;
					int length2 = Mathf.Clamp(Mathf.FloorToInt((float)"GO BERSERK".Length * num2), 0, "GO BERSERK".Length);
					_berserk.text = "GO BERSERK".Substring(0, length2);
					float num3 = 0.7f + 0.3f * Mathf.Abs(Mathf.Sin(num * 12f));
					((Graphic)_berserk).color = new Color(BerserkColor.r, BerserkColor.g, BerserkColor.b, num3);
				}
				if (num >= 3.4f)
				{
					_active = false;
					SetVisible(v: false);
				}
			}
		}

		private void Build()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			_white = MakeWhiteSprite();
			Canvas val = ((Component)this).gameObject.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 1100;
			CanvasScaler val2 = ((Component)this).gameObject.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.matchWidthOrHeight = 0.5f;
			((Component)this).gameObject.AddComponent<GraphicRaycaster>();
			GameObject val3 = new GameObject("Panel", new Type[1] { typeof(RectTransform) });
			val3.transform.SetParent(((Component)this).transform, false);
			_panel = (RectTransform)val3.transform;
			Stretch(_panel);
			Image val4 = NewImage((Transform)(object)_panel, "BG", new Color(0f, 0f, 0f, 0.45f));
			Stretch((RectTransform)((Component)val4).transform);
			_signal = NewText((Transform)(object)_panel, "Signal", 54, SignalColor, (FontStyle)1);
			RectTransform rectTransform = ((Graphic)_signal).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 0.6f);
			rectTransform.anchorMax = new Vector2(1f, 0.72f);
			rectTransform.offsetMin = Vector2.zero;
			rectTransform.offsetMax = Vector2.zero;
			_berserk = NewText((Transform)(object)_panel, "Berserk", 96, BerserkColor, (FontStyle)1);
			RectTransform rectTransform2 = ((Graphic)_berserk).rectTransform;
			rectTransform2.anchorMin = new Vector2(0f, 0.38f);
			rectTransform2.anchorMax = new Vector2(1f, 0.58f);
			rectTransform2.offsetMin = Vector2.zero;
			rectTransform2.offsetMax = Vector2.zero;
		}

		private void SetVisible(bool v)
		{
			if ((Object)(object)_panel != (Object)null)
			{
				((Component)_panel).gameObject.SetActive(v);
			}
		}

		private static void Stretch(RectTransform rt)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.offsetMin = Vector2.zero;
			rt.offsetMax = Vector2.zero;
		}

		private Image NewImage(Transform parent, string name, Color color)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			Image component = val.GetComponent<Image>();
			component.sprite = _white;
			((Graphic)component).color = color;
			return component;
		}

		private Text NewText(Transform parent, string name, int size, Color color, FontStyle style)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Text)
			});
			val.transform.SetParent(parent, false);
			Text component = val.GetComponent<Text>();
			component.font = GetFont();
			component.fontSize = size;
			component.fontStyle = style;
			component.alignment = (TextAnchor)4;
			((Graphic)component).color = color;
			component.horizontalOverflow = (HorizontalWrapMode)1;
			component.verticalOverflow = (VerticalWrapMode)1;
			return component;
		}

		private static Font GetFont()
		{
			Font val = null;
			try
			{
				val = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null)
			{
				try
				{
					val = Resources.GetBuiltinResource<Font>("Arial.ttf");
				}
				catch
				{
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Font.CreateDynamicFontFromOSFont("Consolas", 16);
			}
			return val;
		}

		private static Sprite MakeWhiteSprite()
		{
			//IL_001f: 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)
			Texture2D whiteTexture = Texture2D.whiteTexture;
			return Sprite.Create(whiteTexture, new Rect(0f, 0f, (float)((Texture)whiteTexture).width, (float)((Texture)whiteTexture).height), new Vector2(0.5f, 0.5f), 100f);
		}
	}
	public class EffectTimerHud : MonoBehaviour
	{
		private static readonly Color TextColor = Color32.op_Implicit(new Color32((byte)238, (byte)238, (byte)238, byte.MaxValue));

		private Text _text;

		public static EffectTimerHud? Instance { get; private set; }

		public static void EnsureExists()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				GameObject val = new GameObject("ChatChaos_EffectTimers");
				Object.DontDestroyOnLoad((Object)(object)val);
				((Object)val).hideFlags = (HideFlags)61;
				Instance = val.AddComponent<EffectTimerHud>();
			}
		}

		private void Awake()
		{
			Build();
		}

		private void Update()
		{
			List<(string, int)> active = EffectTimers.GetActive();
			if (active.Count == 0)
			{
				if (_text.text.Length != 0)
				{
					_text.text = "";
				}
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			foreach (var item in active)
			{
				stringBuilder.Append(item.Item1).Append("  ").Append(item.Item2)
					.Append("s\n");
			}
			_text.text = stringBuilder.ToString().TrimEnd();
		}

		private void Build()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			Canvas val = ((Component)this).gameObject.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 1050;
			CanvasScaler val2 = ((Component)this).gameObject.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.matchWidthOrHeight = 0.5f;
			((Component)this).gameObject.AddComponent<GraphicRaycaster>();
			float num = Mathf.Clamp01(ModConfig.TimerAnchorX.Value);
			float num2 = Mathf.Clamp01(ModConfig.TimerAnchorY.Value);
			bool flag = num > 0.5f;
			GameObject val3 = new GameObject("Text", new Type[4]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Text),
				typeof(Outline)
			});
			val3.transform.SetParent(((Component)this).transform, false);
			RectTransform val4 = (RectTransform)val3.transform;
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor(num, num2);
			val4.anchorMax = val5;
			val4.anchorMin = val5;
			val4.pivot = new Vector2(num, 1f);
			val4.sizeDelta = new Vector2(520f, 400f);
			val4.anchoredPosition = new Vector2(flag ? (-20f) : 20f, 0f);
			_text = val3.GetComponent<Text>();
			_text.font = GetFont();
			_text.fontSize = 24;
			_text.fontStyle = (FontStyle)1;
			_text.alignment = (TextAnchor)(flag ? 2 : 0);
			((Graphic)_text).color = TextColor;
			_text.horizontalOverflow = (HorizontalWrapMode)1;
			_text.verticalOverflow = (VerticalWrapMode)1;
			_text.text = "";
			Outline component = val3.GetComponent<Outline>();
			((Shadow)component).effectColor = new Color(0f, 0f, 0f, 0.85f);
			((Shadow)component).effectDistance = new Vector2(2f, -2f);
		}

		private static Font GetFont()
		{
			Font val = null;
			try
			{
				val = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null)
			{
				try
				{
					val = Resources.GetBuiltinResource<Font>("Arial.ttf");
				}
				catch
				{
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Font.CreateDynamicFontFromOSFont("Consolas", 16);
			}
			return val;
		}
	}
	public static class GameChat
	{
		public static void Show(string message)
		{
			if (string.IsNullOrEmpty(message))
			{
				return;
			}
			try
			{
				HUDManager instance = HUDManager.Instance;
				if (!((Object)(object)instance == (Object)null))
				{
					instance.AddTextToChatOnServer(message, -1);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("ChatChaos: could not post in-game chat: " + ex.Message));
			}
		}
	}
	public static class GameTips
	{
		public static void Show(string header, string body)
		{
			try
			{
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip(header, body, false, false, "LC_Tip1");
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("ChatChaos: could not show on-screen tip: " + ex.Message));
			}
		}
	}
	public class PollHud : MonoBehaviour
	{
		private static readonly Color PanelColor = Color32.op_Implicit(new Color32((byte)214, (byte)182, (byte)122, byte.MaxValue));

		private static readonly Color HeaderText = Color32.op_Implicit(new Color32((byte)38, (byte)28, (byte)16, byte.MaxValue));

		private static readonly Color RowEmpty = Color32.op_Implicit(new Color32((byte)43, (byte)43, (byte)46, byte.MaxValue));

		private static readonly Color BarOrange = Color32.op_Implicit(new Color32((byte)240, (byte)168, (byte)30, byte.MaxValue));

		private static readonly Color BarWinner = Color32.op_Implicit(new Color32((byte)95, (byte)190, (byte)70, byte.MaxValue));

		private static readonly Color RowText = Color32.op_Implicit(new Color32((byte)238, (byte)238, (byte)238, byte.MaxValue));

		private static readonly Color AlarmRed = Color32.op_Implicit(new Color32((byte)214, (byte)48, (byte)40, byte.MaxValue));

		private const int PanelWidth = 470;

		private const int PanelHeight = 232;

		private const int Pad = 16;

		private const int RowHeight = 34;

		private const int RowGap = 9;

		private const int MaxRows = 3;

		private bool _active;

		private bool _finished;

		private bool _paused;

		private bool _pausedPulse;

		private readonly string[] _labels = new string[3];

		private readonly int[] _counts = new int[3];

		private int _rowsUsed;

		private float _endTime;

		private float _autoHideTime = float.MaxValue;

		private float _votingHardDeadline = float.MaxValue;

		private int _winnerIndex = -1;

		private int _winnerCount;

		private Canvas _canvas;

		private RectTransform _panel;

		private Text _title;

		private Text _timer;

		private Image _clockIcon;

		private Text _instruction;

		private Sprite _white;

		private readonly Image[] _rowBg = (Image[])(object)new Image[3];

		private readonly Image[] _rowFill = (Image[])(object)new Image[3];

		private readonly Text[] _rowLabel = (Text[])(object)new Text[3];

		private readonly Text[] _rowCount = (Text[])(object)new Text[3];

		public static PollHud? Instance { get; private set; }

		public static void EnsureExists()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				GameObject val = new GameObject("ChatChaos_Hud");
				Object.DontDestroyOnLoad((Object)(object)val);
				((Object)val).hideFlags = (HideFlags)61;
				Instance = val.AddComponent<PollHud>();
			}
		}

		private void Awake()
		{
			Build();
			SetVisible(v: false);
		}

		public void ShowPoll(string l0, string l1, string l2, float duration)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			_labels[0] = l0 ?? "";
			_labels[1] = l1 ?? "";
			_labels[2] = l2 ?? "";
			_rowsUsed = 0;
			for (int i = 0; i < 3; i++)
			{
				_counts[i] = 0;
				if (_labels[i].Length > 0)
				{
					_rowsUsed = i + 1;
				}
			}
			_finished = false;
			_paused = false;
			_pausedPulse = false;
			_winnerIndex = -1;
			_endTime = Time.time + duration;
			_autoHideTime = float.MaxValue;
			_votingHardDeadline = Time.time + duration + 12f;
			_active = true;
			_title.text = Loc.Get("panel.title");
			_instruction.text = Loc.Get("panel.instruction");
			((Graphic)_instruction).color = HeaderText;
			if ((Object)(object)_clockIcon != (Object)null)
			{
				((Component)_clockIcon).gameObject.SetActive(true);
			}
			ApplyTimerVisual(1f, HeaderText);
			SetVisible(v: true);
			Refresh();
		}

		public void UpdateCounts(int c0, int c1, int c2)
		{
			if (!_paused)
			{
				_counts[0] = c0;
				_counts[1] = c1;
				_counts[2] = c2;
				if (_active && !_finished)
				{
					Refresh();
				}
			}
		}

		public void Pause()
		{
			if (_active && !_finished)
			{
				float num = _endTime - Time.time;
				_pausedPulse = num <= 10f && num > 0f;
				_paused = true;
				_autoHideTime = Time.time + Mathf.Max(1f, ModConfig.ResultDisplayDuration.Value);
				SetVisible(v: true);
			}
		}

		public void ShowResult(int winnerIndex, int winnerCount)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			_finished = true;
			_paused = false;
			_pausedPulse = false;
			_winnerIndex = winnerIndex;
			_winnerCount = winnerCount;
			_instruction.text = Loc.Get("panel.finished");
			_autoHideTime = Time.time + Mathf.Max(1f, ModConfig.ResultDisplayDuration.Value);
			_votingHardDeadline = float.MaxValue;
			_active = true;
			if ((Object)(object)_clockIcon != (Object)null)
			{
				((Component)_clockIcon).gameObject.SetActive(false);
			}
			ApplyTimerVisual(1f, HeaderText);
			SetVisible(v: true);
			Refresh();
		}

		public void Hide()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			_active = false;
			_finished = false;
			_paused = false;
			_pausedPulse = false;
			_autoHideTime = float.MaxValue;
			_votingHardDeadline = float.MaxValue;
			if ((Object)(object)_clockIcon != (Object)null)
			{
				((Component)_clockIcon).gameObject.SetActive(false);
			}
			ApplyTimerVisual(1f, HeaderText);
			SetVisible(v: false);
		}

		private void Update()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!_active)
			{
				return;
			}
			if (_paused)
			{
				if (_pausedPulse)
				{
					float num = Mathf.Sin(Time.time % 1f * MathF.PI);
					ApplyTimerVisual(Mathf.Lerp(1f, 1.6f, num), Color.Lerp(HeaderText, AlarmRed, num));
				}
				if (Time.time >= _autoHideTime)
				{
					Hide();
				}
			}
			else if (!_finished)
			{
				float num2 = _endTime - Time.time;
				int num3 = Mathf.Max(0, Mathf.CeilToInt(num2));
				_timer.text = num3 + "s";
				UpdateTimerPulse(num2);
				if (Time.time >= _votingHardDeadline)
				{
					Hide();
				}
			}
			else
			{
				_timer.text = "";
				if (Time.time >= _autoHideTime)
				{
					Hide();
				}
			}
		}

		private void UpdateTimerPulse(float remaining)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (remaining <= 10f && remaining > 0f)
			{
				float num = Mathf.Ceil(remaining) - remaining;
				float num2 = Mathf.Sin(num * MathF.PI);
				ApplyTimerVisual(Mathf.Lerp(1f, 1.6f, num2), Color.Lerp(HeaderText, AlarmRed, num2));
			}
			else
			{
				ApplyTimerVisual(1f, HeaderText);
			}
		}

		private void ApplyTimerVisual(float scale, Color color)
		{
			//IL_0019: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			Vector3 localScale = default(Vector3);
			((Vector3)(ref localScale))..ctor(scale, scale, 1f);
			((Transform)((Graphic)_timer).rectTransform).localScale = localScale;
			((Graphic)_timer).color = color;
			if ((Object)(object)_clockIcon != (Object)null)
			{
				((Transform)((Graphic)_clockIcon).rectTransform).localScale = localScale;
				((Graphic)_clockIcon).color = color;
			}
		}

		private void Refresh()
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			int num = 1;
			for (int i = 0; i < _rowsUsed; i++)
			{
				num = Mathf.Max(num, _counts[i]);
			}
			for (int j = 0; j < 3; j++)
			{
				bool flag = j < _rowsUsed;
				((Component)_rowBg[j]).gameObject.SetActive(flag);
				if (flag)
				{
					bool flag2 = _finished && j == _winnerIndex;
					bool flag3 = _finished && j != _winnerIndex;
					float num2 = (flag2 ? 1f : Mathf.Clamp01((float)_counts[j] / (float)num));
					float num3 = 438f;
					RectTransform val = (RectTransform)((Component)_rowFill[j]).transform;
					val.sizeDelta = new Vector2(num3 * num2, 34f);
					Color color = (flag2 ? BarWinner : BarOrange);
					((Graphic)_rowFill[j]).color = color;
					((Component)_rowFill[j]).gameObject.SetActive(flag2 || _counts[j] > 0);
					_rowLabel[j].text = $"{j + 1}|{_labels[j]}";
					((Graphic)_rowLabel[j]).color = (Color)(flag3 ? new Color(1f, 1f, 1f, 0.45f) : RowText);
					string text = (flag2 ? "  \ud83c\udfc6" : "");
					_rowCount[j].text = _counts[j] + text;
					((Graphic)_rowCount[j]).color = (Color)(flag3 ? new Color(1f, 1f, 1f, 0.45f) : RowText);
				}
			}
		}

		private void Build()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00f1: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Expected O, but got Unknown
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Expected O, but got Unknown
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0530: Unknown result type (might be due to invalid IL or missing references)
			_white = MakeWhiteSprite();
			_canvas = ((Component)this).gameObject.AddComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = 1000;
			CanvasScaler val = ((Component)this).gameObject.AddComponent<CanvasScaler>();
			val.uiScaleMode = (ScaleMode)1;
			val.referenceResolution = new Vector2(1920f, 1080f);
			val.matchWidthOrHeight = 0.5f;
			((Component)this).gameObject.AddComponent<GraphicRaycaster>();
			float num = Mathf.Clamp01(ModConfig.HudAnchorX.Value);
			float num2 = Mathf.Clamp01(ModConfig.HudAnchorY.Value);
			float num3 = Mathf.Max(0.3f, ModConfig.HudScale.Value);
			Image val2 = NewImage(((Component)this).transform, "Panel", PanelColor);
			_panel = (RectTransform)((Component)val2).transform;
			RectTransform panel = _panel;
			RectTransform panel2 = _panel;
			RectTransform panel3 = _panel;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(num, num2);
			panel3.pivot = val3;
			Vector2 val4 = (panel.anchorMin = (panel2.anchorMax = val3));
			_panel.sizeDelta = new Vector2(470f, 232f);
			_panel.anchoredPosition = Vector2.zero;
			((Transform)_panel).localScale = new Vector3(num3, num3, 1f);
			_title = NewText((Transform)(object)_panel, "Title", ">SONDAGE", 30, (TextAnchor)0, HeaderText, (FontStyle)1);
			Place(((Graphic)_title).rectTransform, 16f, 16f, 438f, 36f);
			_clockIcon = NewImage((Transform)(object)_panel, "ClockIcon", HeaderText);
			_clockIcon.sprite = MakeClockSprite();
			RectTransform val7 = (RectTransform)((Component)_clockIcon).transform;
			((Vector2)(ref val4))..ctor(1f, 1f);
			val7.anchorMax = val4;
			val7.anchorMin = val4;
			val7.pivot = new Vector2(1f, 0.5f);
			val7.sizeDelta = new Vector2(26f, 26f);
			val7.anchoredPosition = new Vector2(-76f, -34f);
			_timer = NewText((Transform)(object)_panel, "Timer", "", 26, (TextAnchor)5, HeaderText, (FontStyle)1);
			RectTransform rectTransform = ((Graphic)_timer).rectTransform;
			((Vector2)(ref val4))..ctor(1f, 1f);
			rectTransform.anchorMax = val4;
			rectTransform.anchorMin = val4;
			rectTransform.pivot = new Vector2(1f, 0.5f);
			rectTransform.sizeDelta = new Vector2(58f, 34f);
			rectTransform.anchoredPosition = new Vector2(-16f, -34f);
			_instruction = NewText((Transform)(object)_panel, "Instruction", "", 18, (TextAnchor)0, HeaderText, (FontStyle)0);
			Place(((Graphic)_instruction).rectTransform, 16f, 58f, 438f, 26f);
			int num4 = 92;
			for (int i = 0; i < 3; i++)
			{
				int num5 = num4 + i * 43;
				Image val8 = NewImage((Transform)(object)_panel, "RowBg" + i, RowEmpty);
				_rowBg[i] = val8;
				Place((RectTransform)((Component)val8).transform, 16f, num5, 438f, 34f);
				Image val9 = NewImage(((Component)val8).transform, "RowFill" + i, BarOrange);
				_rowFill[i] = val9;
				RectTransform val10 = (RectTransform)((Component)val9).transform;
				val10.anchorMin = new Vector2(0f, 1f);
				val10.anchorMax = new Vector2(0f, 1f);
				val10.pivot = new Vector2(0f, 1f);
				val10.anchoredPosition = Vector2.zero;
				val10.sizeDelta = new Vector2(0f, 34f);
				Text val11 = NewText(((Component)val8).transform, "RowLabel" + i, "", 18, (TextAnchor)3, RowText, (FontStyle)1);
				Place(((Graphic)val11).rectTransform, 10f, 0f, 368f, 34f);
				((Graphic)val11).rectTransform.anchoredPosition = new Vector2(10f, 0f);
				StretchVert(((Graphic)val11).rectTransform);
				Text val12 = NewText(((Component)val8).transform, "RowCount" + i, "", 18, (TextAnchor)5, RowText, (FontStyle)1);
				RectTransform rectTransform2 = ((Graphic)val12).rectTransform;
				rectTransform2.anchorMin = new Vector2(1f, 0f);
				rectTransform2.anchorMax = new Vector2(1f, 1f);
				rectTransform2.pivot = new Vector2(1f, 0.5f);
				rectTransform2.sizeDelta = new Vector2(90f, 0f);
				rectTransform2.anchoredPosition = new Vector2(-10f, 0f);
				_rowLabel[i] = val11;
				_rowCount[i] = val12;
			}
		}

		private void SetVisible(bool v)
		{
			if ((Object)(object)_panel != (Object)null)
			{
				((Component)_panel).gameObject.SetActive(v);
			}
		}

		private Image NewImage(Transform parent, string name, Color color)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			Image component = val.GetComponent<Image>();
			component.sprite = _white;
			component.type = (Type)0;
			((Graphic)component).color = color;
			return component;
		}

		private Text NewText(Transform parent, string name, string text, int size, TextAnchor anchor, Color color, FontStyle style)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Text)
			});
			val.transform.SetParent(parent, false);
			Text component = val.GetComponent<Text>();
			component.text = text;
			component.font = GetFont();
			component.fontSize = size;
			component.fontStyle = style;
			component.alignment = anchor;
			((Graphic)component).color = color;
			component.horizontalOverflow = (HorizontalWrapMode)1;
			component.verticalOverflow = (VerticalWrapMode)1;
			return component;
		}

		private static void Place(RectTransform rt, float x, float y, float w, float h)
		{
			//IL_000b: 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_0035: 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)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = new Vector2(0f, 1f);
			rt.anchorMax = new Vector2(0f, 1f);
			rt.pivot = new Vector2(0f, 1f);
			rt.sizeDelta = new Vector2(w, h);
			rt.anchoredPosition = new Vector2(x, 0f - y);
		}

		private static void StretchVert(RectTransform rt)
		{
			//IL_000b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = new Vector2(0f, 0f);
			rt.anchorMax = new Vector2(0f, 1f);
			rt.pivot = new Vector2(0f, 0.5f);
		}

		private static Font GetFont()
		{
			Font val = null;
			try
			{
				val = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null)
			{
				try
				{
					val = Resources.GetBuiltinResource<Font>("Arial.ttf");
				}
				catch
				{
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Font.CreateDynamicFontFromOSFont("Consolas", 16);
			}
			return val;
		}

		private static Sprite MakeWhiteSprite()
		{
			//IL_001f: 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)
			Texture2D whiteTexture = Texture2D.whiteTexture;
			return Sprite.Create(whiteTexture, new Rect(0f, 0f, (float)((Texture)whiteTexture).width, (float)((Texture)whiteTexture).height), new Vector2(0.5f, 0.5f), 100f);
		}

		private static Sprite MakeClockSprite()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			Color32[] px = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < px.Length; i++)
			{
				px[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)0);
			}
			float num = 31.5f;
			float num2 = 28f;
			float num3 = 21f;
			float num4 = 4.5f;
			Color32 on = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			for (int j = 0; j < 64; j++)
			{
				for (int k = 0; k < 64; k++)
				{
					float num5 = (float)k - num;
					float num6 = (float)j - num2;
					float num7 = Mathf.Sqrt(num5 * num5 + num6 * num6);
					if (num7 <= num3 && num7 >= num3 - num4)
					{
						Set(k, j);
					}
				}
			}
			FillRect((int)num - 2, (int)num + 1, (int)(num2 + num3), (int)(num2 + num3) + 4);
			FillRect((int)num - 4, (int)num + 3, (int)(num2 + num3) + 4, (int)(num2 + num3) + 6);
			Line(num, num2, num, num2 + num3 * 0.55f, 2.2f);
			Line(num, num2, num + num3 * 0.62f, num2 + num3 * 0.2f, 2.2f);
			Line(num, num2, num, num2, 3f);
			val.SetPixels32(px);
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
			void FillRect(int x0, int x1, int y0, int y1)
			{
				for (int l = y0; l <= y1; l++)
				{
					for (int m = x0; m <= x1; m++)
					{
						Set(m, l);
					}
				}
			}
			void Line(float x0, float y0, float x1, float y1, float w)
			{
				float num8 = Mathf.Max(Mathf.Abs(x1 - x0), Mathf.Abs(y1 - y0)) * 2f + 1f;
				int num9 = Mathf.CeilToInt(w / 2f);
				for (int l = 0; (float)l <= num8; l++)
				{
					float num10 = (float)l / num8;
					int num11 = Mathf.RoundToInt(Mathf.Lerp(x0, x1, num10));
					int num12 = Mathf.RoundToInt(Mathf.Lerp(y0, y1, num10));
					for (int m = -num9; m <= num9; m++)
					{
						for (int n = -num9; n <= num9; n++)
						{
							Set(num11 + n, num12 + m);
						}
					}
				}
			}
			void Set(int x, int y)
			{
				//IL_001f: 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)
				if (x >= 0 && x < 64 && y >= 0 && y < 64)
				{
					px[y * 64 + x] = on;
				}
			}
		}
	}
}
namespace ChatChaos.Twitch
{
	public class TwitchClient
	{
		public readonly struct ChatLine
		{
			public readonly string User;

			public readonly string Message;

			public ChatLine(string user, string message)
			{
				User = user;
				Message = message;
			}
		}

		private const string Host = "irc.chat.twitch.tv";

		private TcpClient? _tcp;

		private Stream? _stream;

		private StreamReader? _reader;

		private StreamWriter? _writer;

		private Thread? _thread;

		private volatile bool _running;

		private volatile bool _connected;

		private volatile bool _canPost;

		private string _channel = "";

		private string _nick = "";

		private string _token = "";

		private bool _ssl;

		private readonly object _writeLock = new object();

		private readonly ConcurrentQueue<ChatLine> _incoming = new ConcurrentQueue<ChatLine>();

		public static TwitchClient? Instance { get; private set; }

		public bool IsConnected => _connected;

		public bool CanPost
		{
			get
			{
				if (_connected)
				{
					return _canPost;
				}
				return false;
			}
		}

		public static void StartFromConfig()
		{
			Stop();
			if (!ModConfig.TwitchEnabled.Value)
			{
				Plugin.Log.LogInfo((object)"Twitch: integration disabled in config. Polls will pick random options.");
				return;
			}
			string text = (ModConfig.TwitchChannel.Value ?? "").Trim().TrimStart('#').ToLowerInvariant();
			if (text.Length == 0)
			{
				Plugin.Log.LogWarning((object)"Twitch: no Channel set in config — cannot connect. Set Twitch/Channel (and OAuthToken to post messages).");
				return;
			}
			string text2 = NormalizeToken(ModConfig.TwitchOAuthToken.Value);
			string text3 = ((text2.Length > 0) ? ModConfig.EffectiveUsername().Trim().ToLowerInvariant() : ("justinfan" + new Random().Next(10000, 99999)));
			if (text3.Length == 0)
			{
				text3 = text;
			}
			Instance = new TwitchClient
			{
				_channel = text,
				_nick = text3,
				_token = text2,
				_ssl = ModConfig.TwitchUseSsl.Value
			};
			Instance.Start();
		}

		public static void Stop()
		{
			Instance?.Dispose();
			Instance = null;
		}

		private void Start()
		{
			_running = true;
			_thread = new Thread(RunLoop)
			{
				IsBackground = true,
				Name = "ChatChaos-Twitch"
			};
			_thread.Start();
		}

		private void RunLoop()
		{
			int num = 0;
			while (_running)
			{
				try
				{
					Connect();
					num = 0;
					ReadUntilClosed();
				}
				catch (Exception ex)
				{
					if (_running)
					{
						Plugin.Log.LogWarning((object)("Twitch: connection error: " + ex.Message));
					}
				}
				_connected = false;
				CloseSocket();
				if (!_running)
				{
					break;
				}
				num++;
				int num2 = Math.Min(30, 3 * (int)Math.Pow(2.0, Math.Min(num - 1, 3)));
				for (int i = 0; i < num2 * 10; i++)
				{
					if (!_running)
					{
						break;
					}
					Thread.Sleep(100);
				}
			}
		}

		private void Connect()
		{
			int port = (_ssl ? 6697 : 6667);
			_tcp = new TcpClient();
			_tcp.Connect("irc.chat.twitch.tv", port);
			Stream stream = _tcp.GetStream();
			if (_ssl)
			{
				SslStream sslStream = new SslStream(stream, leaveInnerStreamOpen: false, (object s, X509Certificate c, X509Chain ch, SslPolicyErrors e) => true);
				sslStream.AuthenticateAsClient("irc.chat.twitch.tv");
				stream = sslStream;
			}
			_stream = stream;
			_reader = new StreamReader(_stream, Encoding.UTF8);
			_writer = new StreamWriter(_stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false))
			{
				AutoFlush = true,
				NewLine = "\r\n"
			};
			if (_token.Length > 0)
			{
				SendRaw("PASS " + _token);
			}
			SendRaw("NICK " + _nick);
			SendRaw("JOIN #" + _channel);
			_canPost = _token.Length > 0;
			_connected = true;
			Plugin.Log.LogInfo((object)("Twitch: connected to #" + _channel + " as " + _nick + " (" + (_canPost ? "read + post" : "read-only") + ")."));
		}

		private void ReadUntilClosed()
		{
			string line;
			while (_running && _reader != null && (line = _reader.ReadLine()) != null)
			{
				HandleLine(line);
			}
		}

		private void HandleLine(string line)
		{
			if (line.StartsWith("PING"))
			{
				string text = ((line.Length > 5) ? line.Substring(5) : ":tmi.twitch.tv");
				SendRaw("PONG " + text);
				return;
			}
			int num = line.IndexOf(" PRIVMSG ", StringComparison.Ordinal);
			if (num < 0 || !line.StartsWith(":"))
			{
				return;
			}
			int num2 = line.IndexOf('!');
			if (num2 <= 1)
			{
				return;
			}
			string text2 = line.Substring(1, num2 - 1);
			int num3 = line.IndexOf(" :", num, StringComparison.Ordinal);
			if (num3 >= 0)
			{
				string text3 = line.Substring(num3 + 2).Trim();
				if (text2.Length > 0 && text3.Length > 0)
				{
					_incoming.Enqueue(new ChatLine(text2, text3));
				}
			}
		}

		public bool TryDequeue(out ChatLine line)
		{
			return _incoming.TryDequeue(out line);
		}

		public void SendMessage(string text)
		{
			if (!_canPost || !_connected || string.IsNullOrEmpty(text))
			{
				return;
			}
			try
			{
				lock (_writeLock)
				{
					_writer?.WriteLine("PRIVMSG #" + _channel + " :" + text);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Twitch: failed to send message: " + ex.Message));
			}
		}

		private void SendRaw(string raw)
		{
			lock (_writeLock)
			{
				_writer?.WriteLine(raw);
			}
		}

		private void CloseSocket()
		{
			try
			{
				_reader?.Dispose();
			}
			catch
			{
			}
			try
			{
				_writer?.Dispose();
			}
			catch
			{
			}
			try
			{
				_stream?.Dispose();
			}
			catch
			{
			}
			try
			{
				_tcp?.Close();
			}
			catch
			{
			}
			_reader = null;
			_writer = null;
			_stream = null;
			_tcp = null;
		}

		public void Dispose()
		{
			_running = false;
			_connected = false;
			CloseSocket();
			try
			{
				_thread?.Join(500);
			}
			catch
			{
			}
			_thread = null;
		}

		private static string NormalizeToken(string? raw)
		{
			string text = (raw ?? "").Trim();
			if (text.Length == 0)
			{
				return "";
			}
			if (text.StartsWith("oauth:", StringComparison.OrdinalIgnoreCase))
			{
				return text;
			}
			return "oauth:" + text;
		}
	}
}
namespace ChatChaos.Patches
{
	[HarmonyPatch]
	public static class BerserkPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
		public static bool DamagePrefix(PlayerControllerB __instance)
		{
			return !Berserk.IsInvincible(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		public static bool KillPrefix(PlayerControllerB __instance)
		{
			return !Berserk.IsInvincible(__instance);
		}
	}
}
namespace ChatChaos.Networking
{
	public class ChatChaosNetworker : NetworkBehaviour
	{
		private static bool _warnedRpc;

		private const int MaxHp = 100;

		private static float _savedTimeMultiplier = 1f;

		private static GrabbableObject? _hostBerserkShotgun;

		public static ChatChaosNetworker? Instance { get; private set; }

		public static ChatChaosNetworker? Active
		{
			get
			{
				if ((Object)(object)Instance != (Object)null)
				{
					return Instance;
				}
				Instance = Object.FindObjectOfType<ChatChaosNetworker>();
				return Instance;
			}
		}

		public override void OnNetworkSpawn()
		{
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
			Plugin.Log.LogInfo((object)"ChatChaosNetworker ready (network active).");
		}

		public override void OnNetworkDespawn()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
			((NetworkBehaviour)this).OnNetworkDespawn();
		}

		private static void Safe(Action rpc)
		{
			try
			{
				rpc();
			}
			catch (Exception ex)
			{
				if (!_warnedRpc)
				{
					_warnedRpc = true;
					Plugin.Log.LogWarning((object)("Networking note: an RPC could not be sent. This is harmless in solo and if the build isn't fully netcode-patched; multiplayer sync may be limited. (" + ex.Message + ")"));
				}
			}
		}

		public void BroadcastStart(string l0, string l1, string l2, float duration)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				PollHud.Instance?.ShowPoll(l0, l1, l2, duration);
				Safe(delegate
				{
					StartPollClientRpc(l0, l1, l2, duration);
				});
			}
		}

		public void BroadcastCounts(int c0, int c1, int c2)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				PollHud.Instance?.UpdateCounts(c0, c1, c2);
				Safe(delegate
				{
					CountsClientRpc(c0, c1, c2);
				});
			}
		}

		public void BroadcastEnd(int winnerIndex, int winnerCount)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				PollHud.Instance?.ShowResult(winnerIndex, winnerCount);
				Safe(delegate
				{
					EndPollClientRpc(winnerIndex, winnerCount);
				});
			}
		}

		public void BroadcastHide()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				PollHud.Instance?.Hide();
				Safe(delegate
				{
					HideClientRpc();
				});
			}
		}

		public void BroadcastTip(string header, string body)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				GameTips.Show(header, body);
				Safe(delegate
				{
					TipClientRpc(header, body);
				});
			}
		}

		public void BroadcastPause()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				PollHud.Instance?.Pause();
				Safe(delegate
				{
					PauseClientRpc();
				});
			}
		}

		public void KillPlayer(int index)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				KillIfLocalTarget(index);
				Safe(delegate
				{
					KillPlayerClientRpc(index);
				});
			}
		}

		[ClientRpc]
		private void KillPlayerClientRpc(int index)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1905460702u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, index);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1905460702u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					KillIfLocalTarget(index);
				}
			}
		}

		private static void KillIfLocalTarget(int index)
		{
			//IL_0054: 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)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if (!((Object)(object)instance == (Object)null) && instance.allPlayerScripts != null && index >= 0 && index < instance.allPlayerScripts.Length)
			{
				PlayerControllerB val = instance.allPlayerScripts[index];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val != (Object)(object)instance.localPlayerController) && !val.isPlayerDead)
				{
					val.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0, default(Vector3), false);
				}
			}
		}

		public void DropAllItems()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				DropLocalPlayerItems();
				Safe(delegate
				{
					DropAllItemsClientRpc();
				});
			}
		}

		[ClientRpc]
		private void DropAllItemsClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3823407637u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3823407637u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					DropLocalPlayerItems();
				}
			}
		}

		private static void DropLocalPlayerItems()
		{
			//IL_0038: 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_0041: 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)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				PlayerControllerB localPlayerController = instance.localPlayerController;
				if (!((Object)(object)localPlayerController == (Object)null) && localPlayerController.isPlayerControlled && !localPlayerController.isPlayerDead)
				{
					localPlayerController.DropAllHeldItems(true, false, false, false, default(Vector3), default(Vector3), default(Vector3), default(Vector3), default(Vector3));
				}
			}
		}

		public void SetOneHp()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				SetLocalPlayerOneHp();
				Safe(delegate
				{
					SetOneHpClientRpc();
				});
			}
		}

		[ClientRpc]
		private void SetOneHpClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(8917357u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 8917357u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					SetLocalPlayerOneHp();
				}
			}
		}

		private static void SetLocalPlayerOneHp()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			PlayerControllerB localPlayerController = instance.localPlayerController;
			if (!((Object)(object)localPlayerController == (Object)null) && localPlayerController.isPlayerControlled && !localPlayerController.isPlayerDead)
			{
				int num = localPlayerController.health - 1;
				if (num > 0)
				{
					localPlayerController.DamagePlayer(num, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
			}
		}

		public void HealAll()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				HealAllPlayersLocal();
				Safe(delegate
				{
					HealAllClientRpc();
				});
			}
		}

		[ClientRpc]
		private void HealAllClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(640034695u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 640034695u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					HealAllPlayersLocal();
				}
			}
		}

		public void SetGroupCredits(int credits)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyGroupCreditsLocal(credits);
				Safe(delegate
				{
					SetGroupCreditsClientRpc(credits);
				});
			}
		}

		[ClientRpc]
		private void SetGroupCreditsClientRpc(int credits)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1004467159u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, credits);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1004467159u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyGroupCreditsLocal(credits);
				}
			}
		}

		private static void ApplyGroupCreditsLocal(int credits)
		{
			Terminal val = Object.FindObjectOfType<Terminal>();
			if (!((Object)(object)val == (Object)null))
			{
				val.groupCredits = credits;
			}
		}

		public void ChangeScrapValues(int percent)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyScrapValueChangeLocal(percent);
				Safe(delegate
				{
					ChangeScrapValuesClientRpc(percent);
				});
			}
		}

		[ClientRpc]
		private void ChangeScrapValuesClientRpc(int percent)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1274065427u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, percent);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1274065427u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyScrapValueChangeLocal(percent);
				}
			}
		}

		private static void ApplyScrapValueChangeLocal(int percent)
		{
			float num = 1f + (float)percent / 100f;
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			int num2 = 0;
			GrabbableObject[] array2 = array;
			foreach (GrabbableObject val in array2)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.itemProperties == (Object)null) && val.itemProperties.isScrap)
				{
					int num3 = (val.scrapValue = Mathf.Max(0, Mathf.RoundToInt((float)val.scrapValue * num)));
					ScanNodeProperties componentInChildren = ((Component)val).GetComponentInChildren<ScanNodeProperties>();
					if ((Object)(object)componentInChildren != (Object)null)
					{
						componentInChildren.subText = $"Value: ${num3}";
					}
					num2++;
				}
			}
			Plugin.Log.LogInfo((object)string.Format("ChatChaos: scrap value {0}{1}% applied to {2} item(s).", (percent >= 0) ? "+" : "", percent, num2));
		}

		public void SetBatteries(float charge)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyBatteryChargeLocal(charge);
				Safe(delegate
				{
					SetBatteriesClientRpc(charge);
				});
			}
		}

		[ClientRpc]
		private void SetBatteriesClientRpc(float charge)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1981296301u, val2, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref charge, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1981296301u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyBatteryChargeLocal(charge);
				}
			}
		}

		private static void ApplyBatteryChargeLocal(float charge)
		{
			charge = Mathf.Clamp01(charge);
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			int num = 0;
			GrabbableObject[] array2 = array;
			foreach (GrabbableObject val in array2)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.itemProperties == (Object)null) && val.itemProperties.requiresBattery && val.insertedBattery != null)
				{
					val.insertedBattery.charge = charge;
					val.insertedBattery.empty = charge <= 0f;
					num++;
				}
			}
			Plugin.Log.LogInfo((object)$"ChatChaos: set battery to {Mathf.RoundToInt(charge * 100f)}% on {num} item(s).");
		}

		public void SetDoors(bool unlock)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyBigDoorsHost(unlock);
				ApplyClassicDoorsLocal(unlock);
				Safe(delegate
				{
					ClassicDoorsClientRpc(unlock);
				});
			}
		}

		[ClientRpc]
		private void ClassicDoorsClientRpc(bool unlock)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1394449627u, val2, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref unlock, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1394449627u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyClassicDoorsLocal(unlock);
				}
			}
		}

		private static void ApplyBigDoorsHost(bool unlock)
		{
			int num = 0;
			TerminalAccessibleObject[] array = Object.FindObjectsOfType<TerminalAccessibleObject>();
			foreach (TerminalAccessibleObject val in array)
			{
				if (!((Object)(object)val == (Object)null) && val.isBigDoor)
				{
					val.SetDoorOpenServerRpc(unlock);
					num++;
				}
			}
			if (num > 0)
			{
				Plugin.Log.LogInfo((object)string.Format("ChatChaos: {0} {1} big door(s).", unlock ? "opened" : "closed", num));
			}
		}

		private static void ApplyClassicDoorsLocal(bool unlock)
		{
			int num = 0;
			DoorLock[] array = Object.FindObjectsOfType<DoorLock>();
			foreach (DoorLock val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				if (unlock)
				{
					if (val.isLocked)
					{
						val.UnlockDoor();
						num++;
					}
				}
				else if (!val.isDoorOpened && !val.isLocked)
				{
					val.LockDoor(30f);
					num++;
				}
			}
			if (num > 0)
			{
				Plugin.Log.LogInfo((object)string.Format("ChatChaos: {0} {1} classic door(s).", unlock ? "unlocked" : "locked", num));
			}
		}

		public void SetTimeFrozen(bool frozen)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyTimeFrozenLocal(frozen);
				Safe(delegate
				{
					SetTimeFrozenClientRpc(frozen);
				});
			}
		}

		[ClientRpc]
		private void SetTimeFrozenClientRpc(bool frozen)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1447575031u, val2, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref frozen, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1447575031u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyTimeFrozenLocal(frozen);
				}
			}
		}

		private static void ApplyTimeFrozenLocal(bool frozen)
		{
			TimeOfDay instance = TimeOfDay.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if (frozen)
			{
				if (instance.globalTimeSpeedMultiplier > 0f)
				{
					_savedTimeMultiplier = instance.globalTimeSpeedMultiplier;
				}
				instance.globalTimeSpeedMultiplier = 0f;
				Plugin.Log.LogInfo((object)"ChatChaos: in-game time frozen.");
			}
			else
			{
				instance.globalTimeSpeedMultiplier = ((_savedTimeMultiplier > 0f) ? _savedTimeMultiplier : 1f);
				Plugin.Log.LogInfo((object)"ChatChaos: in-game time resumed.");
			}
		}

		public void TeleportToShip()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				TeleportLocalToShip();
				Safe(delegate
				{
					TeleportToShipClientRpc();
				});
			}
		}

		[ClientRpc]
		private void TeleportToShipClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(4145462141u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 4145462141u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					TeleportLocalToShip();
				}
			}
		}

		private static void TeleportLocalToShip()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			PlayerControllerB localPlayerController = instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null || !localPlayerController.isPlayerControlled || localPlayerController.isPlayerDead)
			{
				return;
			}
			Transform[] playerSpawnPositions = instance.playerSpawnPositions;
			if (playerSpawnPositions != null && playerSpawnPositions.Length != 0)
			{
				int num = Array.IndexOf(instance.allPlayerScripts, localPlayerController);
				int num2 = Mathf.Clamp((num >= 0) ? num : 0, 0, playerSpawnPositions.Length - 1);
				if (!((Object)(object)playerSpawnPositions[num2] == (Object)null))
				{
					localPlayerController.TeleportPlayer(playerSpawnPositions[num2].position, false, 0f, false, true);
					localPlayerController.isInElevator = true;
					localPlayerController.isInHangarShipRoom = true;
					localPlayerController.isInsideFactory = false;
				}
			}
		}

		public void StartStaminaBoost(float seconds)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				StaminaBoost.Activate(seconds);
				ShowEffectTimer("stamina", "fx.stamina", seconds);
				Safe(delegate
				{
					StaminaBoostClientRpc(seconds);
				});
			}
		}

		[ClientRpc]
		private void StaminaBoostClientRpc(float seconds)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3885039656u, val2, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref seconds, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3885039656u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					StaminaBoost.Activate(seconds);
				}
			}
		}

		public void StartSpeedBoost(float seconds)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				SpeedBoost.Activate(seconds);
				ShowEffectTimer("speed", "fx.speed", seconds);
				Safe(delegate
				{
					SpeedBoostClientRpc(seconds);
				});
			}
		}

		[ClientRpc]
		private void SpeedBoostClientRpc(float seconds)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2683613781u, val2, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref seconds, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 2683613781u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					SpeedBoost.Activate(seconds);
				}
			}
		}

		public void SetShipLocked(bool locked)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyShipLockedLocal(locked);
				Safe(delegate
				{
					SetShipLockedClientRpc(locked);
				});
			}
		}

		[ClientRpc]
		private void SetShipLockedClientRpc(bool locked)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3127508880u, val2, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref locked, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3127508880u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyShipLockedLocal(locked);
				}
			}
		}

		private static void ApplyShipLockedLocal(bool locked)
		{
			StartMatchLever val = Object.FindObjectOfType<StartMatchLever>();
			if ((Object)(object)val != (Object)null && (Object)(object)val.triggerScript != (Object)null)
			{
				val.triggerScript.interactable = !locked;
			}
			HangarShipDoor val2 = Object.FindObjectOfType<HangarShipDoor>();
			if ((Object)(object)val2 != (Object)null)
			{
				if ((Object)(object)val2.shipDoorsAnimator != (Object)null)
				{
					val2.shipDoorsAnimator.SetBool("Closed", locked);
				}
				string[] array = new string[4] { "doorButtons", "buttons", "interactTriggers", "triggers" };
				foreach (string text in array)
				{
					try
					{
						if (!(Traverse.Create((object)val2).Field(text).GetValue() is InteractTrigger[] array2))
						{
							continue;
						}
						InteractTrigger[] array3 = array2;
						foreach (InteractTrigger val3 in array3)
						{
							if ((Object)(object)val3 != (Object)null)
							{
								val3.interactable = !locked;
							}
						}
					}
					catch
					{
					}
				}
			}
			Plugin.Log.LogInfo((object)("ChatChaos: ship " + (locked ? "locked (door closed, lever blocked)" : "unlocked") + "."));
		}

		public void ReviveTeam()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyReviveLocal();
				Safe(delegate
				{
					ReviveTeamClientRpc();
				});
			}
		}

		[ClientRpc]
		private void ReviveTeamClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3255136564u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3255136564u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyReviveLocal();
				}
			}
		}

		private static void ApplyReviveLocal()
		{
			StartOfRound instance = StartOfRound.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				instance.ReviveDeadPlayers();
				Plugin.Log.LogInfo((object)"ChatChaos: revived dead players (teleported to the ship).");
			}
		}

		public void SetFacilityPower(bool on)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyPowerLocal(on);
				Safe(delegate
				{
					SetFacilityPowerClientRpc(on);
				});
			}
		}

		[ClientRpc]
		private void SetFacilityPowerClientRpc(bool on)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3774307684u, val2, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref on, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3774307684u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyPowerLocal(on);
				}
			}
		}

		private static void ApplyPowerLocal(bool on)
		{
			BreakerBox target = Object.FindObjectOfType<BreakerBox>();
			RoundManager instance = RoundManager.Instance;
			bool flag = TryInvoke(target, "SwitchBreaker", on) || TryInvoke(instance, "SwitchPower", on) || TryInvoke(instance, on ? "PowerSwitchOn" : "PowerSwitchOff") || TryInvoke(instance, on ? "TurnOnAllLights" : "TurnOffAllLights");
			Plugin.Log.LogInfo((object)("ChatChaos: facility power " + (on ? "on" : "off") + " -> " + (flag ? "applied" : "NO matching method found (tell the dev).")));
		}

		private static bool TryInvoke(object target, string method, params object[] args)
		{
			if (target == null)
			{
				return false;
			}
			try
			{
				Traverse val = Traverse.Create(target).Method(method, args);
				if (val.MethodExists())
				{
					val.GetValue();
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		public void SetWeather(int weather)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyWeatherLocal(weather);
				Safe(delegate
				{
					SetWeatherClientRpc(weather);
				});
			}
		}

		[ClientRpc]
		private void SetWeatherClientRpc(int weather)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2895239465u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, weather);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 2895239465u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyWeatherLocal(weather);
				}
			}
		}

		private static void ApplyWeatherLocal(int weather)
		{
			//IL_0001: 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_004a: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			LevelWeatherType val = (LevelWeatherType)weather;
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance.currentLevel != (Object)null)
			{
				instance.currentLevel.currentWeather = val;
			}
			TimeOfDay instance2 = TimeOfDay.Instance;
			if ((Object)(object)instance2 != (Object)null)
			{
				try
				{
					Traverse.Create((object)instance2).Field("currentLevelWeather").SetValue((object)val);
				}
				catch
				{
				}
				ToggleWeatherEffects(instance2, weather);
			}
			Plugin.Log.LogInfo((object)$"[ChatChaos][Weather] applied '{val}'.");
		}

		public void ShowBerserkSignal()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				BerserkHud.Instance?.ShowSignal();
				Safe(delegate
				{
					ShowBerserkSignalClientRpc();
				});
			}
		}

		[ClientRpc]
		private void ShowBerserkSignalClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2932696264u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 2932696264u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					BerserkHud.Instance?.ShowSignal();
				}
			}
		}

		public void SetBerserkPlayer(int index)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				Berserk.SetActivePlayer(index);
				Safe(delegate
				{
					SetBerserkPlayerClientRpc(index);
				});
			}
		}

		[ClientRpc]
		private void SetBerserkPlayerClientRpc(int index)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2917893799u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, index);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 2917893799u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					Berserk.SetActivePlayer(index);
				}
			}
		}

		public void ShowEffectTimer(string id, string labelKey, float seconds)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				EffectTimers.Start(id, labelKey, seconds);
				Safe(delegate
				{
					ShowEffectTimerClientRpc(id, labelKey, seconds);
				});
			}
		}

		[ClientRpc]
		private void ShowEffectTimerClientRpc(string id, string labelKey, float seconds)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1941508532u, val2, (RpcDelivery)0);
				bool flag = id != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(id, false);
				}
				bool flag2 = labelKey != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives));
				if (flag2)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(labelKey, false);
				}
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref seconds, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1941508532u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					EffectTimers.Start(id, labelKey, seconds);
				}
			}
		}

		public void ResetDayTime()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				ApplyResetDayTimeLocal();
				Safe(delegate
				{
					ResetDayTimeClientRpc();
				});
			}
		}

		[ClientRpc]
		private void ResetDayTimeClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3614851500u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 3614851500u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					ApplyResetDayTimeLocal();
				}
			}
		}

		private static void ApplyResetDayTimeLocal()
		{
			TimeOfDay instance = TimeOfDay.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				instance.currentDayTime = 0f;
				Plugin.Log.LogInfo((object)"[ChatChaos][Time] day clock reset to the morning start.");
			}
		}

		public void GiveBerserkShotgun(int index)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null || index < 0 || index >= instance.allPlayerScripts.Length)
			{
				return;
			}
			Item val = FindShotgunItem();
			if ((Object)(object)val == (Object)null || (Object)(object)val.spawnPrefab == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[ChatChaos][Berserk] shotgun item not found in the item list.");
				return;
			}