Decompiled source of MrFallTwitchChatChallenge v1.0.6

MrFallTwitchChatChallenge.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using WebSocketSharp;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ChatChaos;

public class ConfigMenu : MonoBehaviour
{
	private const int WindowId = 731205;

	private static readonly string[] Tabs = new string[3] { "Geral", "Eventos", "Testar" };

	private bool _open;

	private Rect _window = new Rect(0f, 0f, 520f, 560f);

	private bool _placed;

	private int _tab;

	private Vector2 _eventScroll;

	private Vector2 _testScroll;

	private Vector2 _itemScroll;

	private int _dropdownFor = -1;

	private string _itemFilter = "";

	private string _channelDraft = "";

	private CursorLockMode _previousLock;

	private bool _previousVisible;

	private EventVoting _voting;

	private GUIStyle _header;

	private GUIStyle _sub;

	private int _resizing;

	private string _keyDraft;

	private Vector2 _voiceScroll;

	private string _voiceStatus = "";

	private static readonly string[] ModelIds = new string[2] { "eleven_multilingual_v2", "eleven_turbo_v2_5" };

	private Vector2 _paidScroll;

	private Vector2 _pickerScroll;

	private string _pixDraft = "";

	private int _pickerFor = -1;

	private string _pickerFilter = "";

	private string _copiedWhat = "";

	private float _copiedUntil;

	private Vector2 _skinScroll;

	public bool IsOpen => _open;

	private void Start()
	{
		_voting = ((Component)this).GetComponent<EventVoting>();
	}

	private void Update()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (ToggleKeyPressed())
		{
			if (Plugin.IsGuest)
			{
				MessageOverlay.ShowBanner(Lang.GuestLocked, 6f, Skin.Warn);
				Plugin.Log.LogInfo((object)"F6 bloqueado: modo convidado. F7 reabre a pergunta de host.");
			}
			else if (_open)
			{
				Close();
			}
			else
			{
				Open();
			}
		}
	}

	private void Open()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		_open = true;
		_previousLock = Cursor.lockState;
		_previousVisible = Cursor.visible;
		ForceCursor();
		ItemCatalog.Refresh();
		_channelDraft = Plugin.CfgChannel.Value;
	}

	private void Close()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		_open = false;
		_dropdownFor = -1;
		Cursor.lockState = _previousLock;
		Cursor.visible = _previousVisible;
	}

	private void ForceCursor()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		if ((int)Cursor.lockState != 0)
		{
			Cursor.lockState = (CursorLockMode)0;
		}
		if (!Cursor.visible)
		{
			Cursor.visible = true;
		}
	}

	private void LateUpdate()
	{
		if (_open)
		{
			ForceCursor();
		}
	}

	private static bool ToggleKeyPressed()
	{
		try
		{
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				return ((ButtonControl)current[(Key)99]).wasPressedThisFrame;
			}
		}
		catch
		{
		}
		try
		{
			return Input.GetKeyDown((KeyCode)287);
		}
		catch
		{
		}
		return false;
	}

	private void EnsureStyles()
	{
		_header = Skin.Title;
		_sub = Skin.Small;
	}

	private void OnGUI()
	{
		//IL_0068: 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_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Expected O, but got Unknown
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		if (_open)
		{
			ForceCursor();
			Skin.InMenu = true;
			EnsureStyles();
			if (!_placed)
			{
				((Rect)(ref _window)).x = 40f;
				((Rect)(ref _window)).y = Mathf.Max(30f, ((float)Screen.height - ((Rect)(ref _window)).height) / 2f);
				_placed = true;
			}
			GUI.Box(_window, GUIContent.none, Skin.Panel);
			_window = GUILayout.Window(731205, _window, new WindowFunction(DrawWindow), GUIContent.none, GUIStyle.none, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(((Rect)(ref _window)).width),
				GUILayout.Height(((Rect)(ref _window)).height)
			});
			Skin.InMenu = false;
		}
	}

	private void DrawGrips()
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Invalid comparison between Unknown and I4
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Invalid comparison between Unknown and I4
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		Event current = Event.current;
		if (current == null)
		{
			return;
		}
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref _window)).width - 8f, 40f, 8f, ((Rect)(ref _window)).height - 40f - 22f);
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(((Rect)(ref _window)).width - 22f, ((Rect)(ref _window)).height - 22f, 22f, 22f);
		Color color = GUI.color;
		GUI.color = ((_resizing == 0) ? Skin.Muted : Skin.Accent);
		GUI.DrawTexture(val, (Texture)(object)Skin.White);
		GUI.Label(new Rect(((Rect)(ref val2)).x + 2f, ((Rect)(ref val2)).y - 2f, 22f, 22f), "◢", Skin.Small);
		GUI.color = color;
		if ((int)current.type == 0)
		{
			if (((Rect)(ref val2)).Contains(current.mousePosition))
			{
				_resizing = 2;
				current.Use();
			}
			else if (((Rect)(ref val)).Contains(current.mousePosition))
			{
				_resizing = 1;
				current.Use();
			}
		}
		else if ((int)current.type == 3 && _resizing != 0)
		{
			((Rect)(ref _window)).width = Mathf.Clamp(((Rect)(ref _window)).width + current.delta.x, 420f, (float)Screen.width - ((Rect)(ref _window)).x - 10f);
			if (_resizing == 2)
			{
				((Rect)(ref _window)).height = Mathf.Clamp(((Rect)(ref _window)).height + current.delta.y, 320f, (float)Screen.height - ((Rect)(ref _window)).y - 10f);
			}
			current.Use();
		}
		else if ((int)current.type == 1 && _resizing != 0)
		{
			_resizing = 0;
			current.Use();
		}
	}

	private void DrawWindow(int id)
	{
		//IL_0039: 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_003f: 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)
		//IL_00c7: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Space(6f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label("  CHATCHAOS", Skin.Header, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) });
		Color color = GUI.color;
		GUI.color = Skin.Accent;
		if (GUILayout.Button("−", (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(34f),
			GUILayout.Height(36f)
		}))
		{
			Zoom(-0.1f);
		}
		if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(34f),
			GUILayout.Height(36f)
		}))
		{
			Zoom(0.1f);
		}
		GUI.color = color;
		Color color2 = GUI.color;
		GUI.color = (Lang.English ? Skin.Muted : Skin.Accent);
		if (GUILayout.Button("PT", (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(44f),
			GUILayout.Height(36f)
		}))
		{
			Lang.SetEnglish(english: false);
		}
		GUI.color = (Lang.English ? Skin.Accent : Skin.Muted);
		if (GUILayout.Button("EN", (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(44f),
			GUILayout.Height(36f)
		}))
		{
			Lang.SetEnglish(english: true);
		}
		GUI.color = color2;
		GUILayout.EndHorizontal();
		GUILayout.Space(8f);
		DrawStatusLine();
		GUILayout.Space(6f);
		DrawCountdownLine();
		GUILayout.Space(8f);
		string[] array = new string[7]
		{
			Lang.TabGeneral,
			Lang.TabEvents,
			Lang.TabZombies,
			Lang.TabVoice,
			Lang.TabSkins,
			Lang.TabPaid,
			Lang.TabTest
		};
		_tab = GUILayout.Toolbar(_tab, array, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f * Skin.Scale) });
		GUILayout.Space(10f);
		if (_tab == 0)
		{
			DrawGeneral();
		}
		else if (_tab == 1)
		{
			DrawEvents();
		}
		else if (_tab == 2)
		{
			DrawZombies();
		}
		else if (_tab == 3)
		{
			DrawVoiceTab();
		}
		else if (_tab == 4)
		{
			DrawSkins();
		}
		else if (_tab == 5)
		{
			DrawPaid();
		}
		else
		{
			DrawTesting();
		}
		GUILayout.Space(6f);
		if (GUILayout.Button(Lang.Close, (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			Close();
		}
		DrawGrips();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}

	private void DrawStatusLine()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: 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)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		bool inRoom = PhotonNetwork.InRoom;
		bool isMasterClient = PhotonNetwork.IsMasterClient;
		Color color = GUI.color;
		if (Plugin.IsGuest)
		{
			GUI.color = Skin.Accent;
			GUILayout.Label(Lang.GuestActive, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color;
		}
		else
		{
			GUI.color = ((inRoom && isMasterClient) ? Skin.Good : Skin.Warn);
			GUILayout.Label((!inRoom) ? Lang.NoRoom : (isMasterClient ? Lang.HostOk : Lang.HostNo), Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color;
		}
	}

	private void DrawCountdownLine()
	{
		//IL_0042: 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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: 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_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.IsGuest)
		{
			return;
		}
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		if ((Object)(object)_voting == (Object)null)
		{
			GUILayout.Label(Lang.TimerUnavailable, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		else if (!PhotonNetwork.InRoom)
		{
			Color color = GUI.color;
			GUI.color = Skin.Muted;
			GUILayout.Label(Lang.TimerWaitingRoom, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color;
		}
		else if (_voting.Paused)
		{
			Color color2 = GUI.color;
			GUI.color = Skin.Warn;
			GUILayout.Label(Lang.PausedLine, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color2;
		}
		else
		{
			float secondsUntilNext = _voting.SecondsUntilNext;
			if (secondsUntilNext < 0f)
			{
				GUILayout.Label(Lang.TimerRunningNow, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			}
			else
			{
				int num = Mathf.FloorToInt(secondsUntilNext / 60f);
				int num2 = Mathf.FloorToInt(secondsUntilNext % 60f);
				GUILayout.Label(Lang.NextVoteIn + " " + num.ToString("00") + ":" + num2.ToString("00"), Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			}
		}
		GUILayout.FlexibleSpace();
		Color color3 = GUI.color;
		if ((Object)(object)_voting != (Object)null && _voting.Paused)
		{
			float num3 = Mathf.PingPong(Time.unscaledTime * 1.7f, 1f);
			GUI.color = Color.Lerp(Skin.Good, Color.white, num3 * 0.75f);
		}
		else
		{
			GUI.color = Skin.Good;
		}
		if (GUILayout.Button(Lang.StartNow, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(150f * Skin.Scale),
			GUILayout.Height(28f * Skin.Scale)
		}) && (Object)(object)_voting != (Object)null)
		{
			_voting.StartVote();
			Close();
		}
		GUI.color = color3;
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		bool flag = (Object)(object)_voting != (Object)null && _voting.Paused;
		GUI.color = (flag ? Skin.Good : Skin.Bad);
		if (GUILayout.Button(flag ? Lang.ModPausedStart : Lang.ModRunningPause, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f * Skin.Scale) }) && (Object)(object)_voting != (Object)null)
		{
			_voting.SetPaused(!flag);
		}
		GUI.color = color3;
		if (flag)
		{
			GUILayout.Label(Lang.PausedHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
	}

	private void DrawGeneral()
	{
		//IL_0198: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label(Lang.GuestSection, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		bool value = Plugin.CfgGuest.Value;
		Plugin.CfgGuest.Value = GUILayout.Toggle(value, Lang.GuestToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (Plugin.CfgGuest.Value != value)
		{
			if (Plugin.CfgGuest.Value)
			{
				Plugin.Disconnect();
			}
			else
			{
				Plugin.Reconnect();
			}
		}
		GUILayout.Label(Lang.GuestHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Plugin.CfgAskOnJoin.Value = GUILayout.Toggle(Plugin.CfgAskOnJoin.Value, Lang.AskOnJoin, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(12f);
		GUILayout.Label(Lang.ModeTitle, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.ModeHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		DrawModeButton("padrao", Lang.ModeSquad, Lang.ModeSquadHint);
		DrawModeButton("solo", Lang.ModeSolo, Lang.ModeSoloHint);
		GUILayout.EndHorizontal();
		GUILayout.Space(10f);
		GUILayout.Label(Lang.Channel, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		_channelDraft = GUILayout.TextField(_channelDraft, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
		bool flag = _channelDraft.Trim() != Plugin.CfgChannel.Value.Trim();
		GUI.enabled = flag && _channelDraft.Trim().Length > 0;
		Color color = GUI.color;
		if (flag)
		{
			GUI.color = Skin.Good;
		}
		if (GUILayout.Button(Lang.Apply, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(60f),
			GUILayout.Height(26f)
		}))
		{
			Plugin.CfgChannel.Value = _channelDraft.Trim();
			Plugin.Reconnect();
		}
		GUI.color = color;
		GUI.enabled = true;
		GUILayout.EndHorizontal();
		GUILayout.Label(Lang.ChannelHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		color = GUI.color;
		if (Plugin.ChatConnected)
		{
			GUI.color = Skin.Good;
			GUILayout.Label(Lang.Connected + " #" + Plugin.CurrentChannel, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		else if (Plugin.CfgChannel.Value.Length > 0)
		{
			GUI.color = Skin.Warn;
			GUILayout.Label(Lang.Connecting, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		else
		{
			GUI.color = Skin.Bad;
			GUILayout.Label(Lang.NotConnected, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		GUI.color = color;
		GUILayout.Space(12f);
		GUILayout.Label(Lang.Pacing, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Plugin.CfgSecondsBetween.Value = Slider(Lang.SecondsBetween, Plugin.CfgSecondsBetween.Value, 10f, 600f, "0");
		Plugin.CfgVoteSeconds.Value = Slider(Lang.VoteDuration, Plugin.CfgVoteSeconds.Value, 10f, 300f, "0");
		Plugin.CfgResultSeconds.Value = Slider(Lang.ResultDuration, Plugin.CfgResultSeconds.Value, 2f, 60f, "0");
		Plugin.CfgTornadoSeconds.Value = Slider(Lang.English ? "Tornado lasts (s)" : "Tornado dura (s)", Plugin.CfgTornadoSeconds.Value, 3f, 120f, "0");
		GUILayout.Space(12f);
		GUILayout.Label(Lang.PanelSection, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Plugin.CfgPanelOnLeft.Value = GUILayout.Toggle(Plugin.CfgPanelOnLeft.Value, Lang.PanelLeft, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Plugin.CfgPanelWidth.Value = Slider(Lang.PanelWidth, Plugin.CfgPanelWidth.Value, 300f, 900f, "0");
		Plugin.CfgPanelTop.Value = Slider(Lang.PanelTop, Plugin.CfgPanelTop.Value, 0f, Mathf.Max(100f, (float)Screen.height - 300f), "0");
		Plugin.CfgFontScale.Value = Slider(Lang.FontSize, Plugin.CfgFontScale.Value, 0.7f, 2.5f, "0.00");
		GUILayout.Space(12f);
		GUILayout.Label(Lang.ReceiverSection, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Plugin.CfgRandomReceiver.Value = GUILayout.Toggle(Plugin.CfgRandomReceiver.Value, Lang.ReceiverRandom, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.ReceiverHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(8f);
		GUILayout.Label(Lang.CursorNote, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		DrawDefaultsButton(new List<ConfigEntryBase>
		{
			(ConfigEntryBase)(object)Plugin.CfgGuest,
			(ConfigEntryBase)(object)Plugin.CfgAskOnJoin,
			(ConfigEntryBase)(object)Plugin.CfgSecondsBetween,
			(ConfigEntryBase)(object)Plugin.CfgVoteSeconds,
			(ConfigEntryBase)(object)Plugin.CfgResultSeconds,
			(ConfigEntryBase)(object)Plugin.CfgTornadoSeconds,
			(ConfigEntryBase)(object)Plugin.CfgPanelOnLeft,
			(ConfigEntryBase)(object)Plugin.CfgPanelWidth,
			(ConfigEntryBase)(object)Plugin.CfgPanelTop,
			(ConfigEntryBase)(object)Plugin.CfgFontScale,
			(ConfigEntryBase)(object)Plugin.CfgRandomReceiver,
			(ConfigEntryBase)(object)Plugin.CfgQuickKeys
		});
	}

	private void DrawVoiceTab()
	{
		//IL_0083: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0467: Unknown result type (might be due to invalid IL or missing references)
		//IL_048a: Unknown result type (might be due to invalid IL or missing references)
		//IL_048f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04be: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_04de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0527: Unknown result type (might be due to invalid IL or missing references)
		if (_keyDraft == null)
		{
			_keyDraft = Plugin.ElevenKey;
		}
		GUILayout.Label(Lang.ApiKeyLabel, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		_keyDraft = GUILayout.PasswordField(_keyDraft, '*', (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f * Skin.Scale) });
		bool flag = (GUI.enabled = _keyDraft.Trim() != Plugin.ElevenKey);
		Color color = GUI.color;
		if (flag)
		{
			GUI.color = Skin.Good;
		}
		if (GUILayout.Button(Lang.Ok, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(60f * Skin.Scale),
			GUILayout.Height(26f * Skin.Scale)
		}))
		{
			Plugin.ElevenKey = _keyDraft;
			Tts.Reset();
			_voiceStatus = "";
		}
		GUI.color = color;
		GUI.enabled = true;
		GUILayout.EndHorizontal();
		GUILayout.Label(Lang.ApiKeyHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(12f);
		GUILayout.Label(Lang.ModelLabel, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		int num = 0;
		for (int i = 0; i < ModelIds.Length; i++)
		{
			if (ModelIds[i] == Plugin.CfgElevenModel.Value)
			{
				num = i;
			}
		}
		string[] array = new string[2]
		{
			Lang.ModelMultilingual,
			Lang.ModelTurbo
		};
		int num2 = GUILayout.Toolbar(num, array, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f * Skin.Scale) });
		if (num2 != num)
		{
			Plugin.CfgElevenModel.Value = ModelIds[num2];
			Tts.Reset();
		}
		GUILayout.Label(Lang.ModelHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(10f);
		Plugin.CfgSpeakEvents.Value = GUILayout.Toggle(Plugin.CfgSpeakEvents.Value, Lang.SpeakEventsToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.SpeakEventsHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(10f);
		Plugin.CfgVoicePitch.Value = Slider(Lang.VoicePitch, Plugin.CfgVoicePitch.Value, 0.5f, 2f, "0.00");
		Plugin.CfgVoiceVolume.Value = Slider(Lang.VoiceVolume, Plugin.CfgVoiceVolume.Value, 0f, 1f, "0.00");
		GUILayout.Space(10f);
		Plugin.CfgMemeSounds.Value = GUILayout.Toggle(Plugin.CfgMemeSounds.Value, Lang.MemeSoundsToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Plugin.CfgMemeVolume.Value = Slider(Lang.VoiceVolume + " (meme)", Plugin.CfgMemeVolume.Value, 0f, 1f, "0.00");
		Plugin.CfgSacrificeEndSeconds.Value = Slider(Lang.SacrificeEndSeconds, Plugin.CfgSacrificeEndSeconds.Value, 0f, 30f, "0.0");
		GUILayout.Label(Lang.SacrificeEndHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Plugin.CfgSuspenseInterval.Value = Slider(Lang.SuspenseInterval, Plugin.CfgSuspenseInterval.Value, 2f, 120f, "0");
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUI.enabled = Tts.Configured;
		if (GUILayout.Button(Lang.LoadVoices, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f * Skin.Scale) }))
		{
			_voiceStatus = "...";
			((MonoBehaviour)this).StartCoroutine(Tts.FetchVoices(delegate(string error)
			{
				_voiceStatus = ((error == null) ? (Tts.Voices.Length + " vozes") : error);
			}));
		}
		if (GUILayout.Button(Lang.TestVoice, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(110f * Skin.Scale),
			GUILayout.Height(30f * Skin.Scale)
		}))
		{
			Tts.Speak(Lang.English ? "ChatChaos is ready" : "ChatChaos esta pronto", Plugin.CfgVoicePitch.Value);
		}
		GUI.enabled = true;
		GUILayout.EndHorizontal();
		if (!string.IsNullOrEmpty(_voiceStatus))
		{
			GUILayout.Label(_voiceStatus, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		GUILayout.Space(8f);
		_voiceScroll = GUILayout.BeginScrollView(_voiceScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(170f * Skin.Scale) });
		for (int num3 = 0; num3 < Tts.Voices.Length; num3++)
		{
			Tts.VoiceInfo voiceInfo = Tts.Voices[num3];
			bool flag3 = voiceInfo.Id == Plugin.CfgElevenVoiceId.Value;
			Color color2 = GUI.color;
			if (!voiceInfo.FreePlanFriendly)
			{
				GUI.color = Skin.Muted;
			}
			else if (flag3)
			{
				GUI.color = Skin.Good;
			}
			if (GUILayout.Button((flag3 ? "> " : "   ") + voiceInfo.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[0]))
			{
				Plugin.CfgElevenVoiceId.Value = voiceInfo.Id;
				Tts.Reset();
			}
			GUI.color = color2;
		}
		GUILayout.EndScrollView();
		DrawDefaultsButton(new List<ConfigEntryBase>
		{
			(ConfigEntryBase)(object)Plugin.CfgSpeakEvents,
			(ConfigEntryBase)(object)Plugin.CfgVoicePitch,
			(ConfigEntryBase)(object)Plugin.CfgVoiceVolume,
			(ConfigEntryBase)(object)Plugin.CfgMemeSounds,
			(ConfigEntryBase)(object)Plugin.CfgMemeVolume,
			(ConfigEntryBase)(object)Plugin.CfgElevenModel,
			(ConfigEntryBase)(object)Plugin.CfgElevenVoiceId,
			(ConfigEntryBase)(object)Plugin.CfgElevenTimeout,
			(ConfigEntryBase)(object)Plugin.CfgElevenMinGap,
			(ConfigEntryBase)(object)Plugin.CfgSacrificeEndSeconds,
			(ConfigEntryBase)(object)Plugin.CfgSuspenseInterval
		});
	}

	private static void RestoreDefaults(List<ConfigEntryBase> entries)
	{
		for (int i = 0; i < entries.Count; i++)
		{
			if (entries[i] != null)
			{
				try
				{
					entries[i].BoxedValue = entries[i].DefaultValue;
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Nao consegui restaurar um ajuste: " + ex.Message));
				}
			}
		}
		Skin.Invalidate();
		Plugin.Log.LogInfo((object)"Ajustes desta aba voltaram ao padrao.");
	}

	private void DrawDefaultsButton(List<ConfigEntryBase> entries)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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)
		GUILayout.Space(12f);
		Color color = GUI.color;
		GUI.color = Skin.Warn;
		if (GUILayout.Button(Lang.RestoreDefaults, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f * Skin.Scale) }))
		{
			RestoreDefaults(entries);
		}
		GUI.color = color;
		GUILayout.Label(Lang.RestoreDefaultsHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
	}

	private void DrawPaid()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label(Lang.PaidTitle, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.PaidHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(8f);
		_paidScroll = GUILayout.BeginScrollView(_paidScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(300f * Skin.Scale) });
		for (int i = 0; i < Rewards.All.Count; i++)
		{
			DrawRule(i, Rewards.All[i]);
		}
		GUILayout.EndScrollView();
		GUILayout.Space(10f);
		DrawAuth();
		GUILayout.Space(10f);
		DrawLivePix();
		GUILayout.Space(10f);
		DrawWebhook();
		GUILayout.Space(10f);
		DrawLinks();
	}

	private void DrawRule(int index, Rewards.Rule rule)
	{
		//IL_0158: 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_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		rule.Enabled.Value = GUILayout.Toggle(rule.Enabled.Value, " " + (index + 1).ToString("00"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f * Skin.Scale) });
		if (GUILayout.Button(Lang.PaidTrigger + ": " + rule.Trigger.Value, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f * Skin.Scale) }))
		{
			rule.Trigger.Value = NextTrigger(rule.Trigger.Value);
		}
		GUILayout.Label(Lang.PaidMinimum, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(85f * Skin.Scale) });
		rule.Minimum.Value = Typed(rule.Minimum.Value, 60f);
		GUILayout.Label(Lang.PaidUnit(Rewards.KindOf(rule.Trigger.Value)), Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f * Skin.Scale) });
		GUILayout.FlexibleSpace();
		Color color = GUI.color;
		GUI.color = Skin.Warn;
		if (GUILayout.Button(Lang.PaidSimulate, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(105f * Skin.Scale) }))
		{
			Rewards.Simulate(index);
			Close();
		}
		GUI.color = color;
		GUILayout.EndHorizontal();
		bool flag = Rewards.IsItemAction(rule.Action.Value);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.PaidAction, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f * Skin.Scale) });
		if (GUILayout.Button(flag ? Lang.PaidKindItem : Lang.PaidKindEvent, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(85f * Skin.Scale) }))
		{
			rule.Action.Value = (flag ? FirstEventId() : Rewards.ComposeItem(ItemCatalog.RandomSpawnable(), 1));
			flag = !flag;
			_pickerFor = -1;
		}
		string text = (flag ? Rewards.ItemOf(rule.Action.Value) : EventTitle(rule.Action.Value));
		if (string.IsNullOrEmpty(text))
		{
			text = Lang.PaidNothing;
		}
		if (GUILayout.Button(text, (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			TogglePicker(index);
		}
		if (flag)
		{
			GUILayout.Label(Lang.PaidAmount, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(65f * Skin.Scale) });
			int count = Typed(Rewards.CountOf(rule.Action.Value), 50f);
			rule.Action.Value = Rewards.ComposeItem(Rewards.ItemOf(rule.Action.Value), count);
		}
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.PaidLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f * Skin.Scale) });
		rule.Label.Value = GUILayout.TextField(rule.Label.Value, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndHorizontal();
		if (_pickerFor == index)
		{
			DrawPicker(rule, flag);
		}
		GUILayout.EndVertical();
		GUILayout.Space(4f);
	}

	private void DrawPicker(Rewards.Rule rule, bool isItem)
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Space(4f);
		GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		_pickerFilter = GUILayout.TextField(_pickerFilter, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (GUILayout.Button(Lang.PaidClose, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f * Skin.Scale) }))
		{
			_pickerFor = -1;
		}
		GUILayout.EndHorizontal();
		if (_pickerFilter.Length == 0)
		{
			GUILayout.Label(Lang.PaidFilter, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		_pickerScroll = GUILayout.BeginScrollView(_pickerScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(150f * Skin.Scale) });
		if (isItem)
		{
			string[] names = ItemCatalog.Names;
			int count = Rewards.CountOf(rule.Action.Value);
			for (int i = 0; i < names.Length; i++)
			{
				if (Matches(names[i]) && GUILayout.Button(names[i], Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]))
				{
					rule.Action.Value = Rewards.ComposeItem(names[i], count);
					_pickerFor = -1;
				}
			}
		}
		else
		{
			for (int j = 0; j < GameEvents.All.Count; j++)
			{
				GameEvent gameEvent = GameEvents.All[j];
				if ((Matches(gameEvent.Title) || Matches(gameEvent.Id)) && GUILayout.Button(gameEvent.Title, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]))
				{
					rule.Action.Value = gameEvent.Id;
					rule.Label.Value = gameEvent.Title;
					_pickerFor = -1;
				}
			}
		}
		GUILayout.EndScrollView();
		GUILayout.EndVertical();
	}

	private bool Matches(string text)
	{
		if (_pickerFilter.Length == 0)
		{
			return true;
		}
		if (string.IsNullOrEmpty(text))
		{
			return false;
		}
		return text.IndexOf(_pickerFilter, StringComparison.OrdinalIgnoreCase) >= 0;
	}

	private void TogglePicker(int index)
	{
		_pickerFor = ((_pickerFor == index) ? (-1) : index);
		_pickerFilter = "";
	}

	private static int Typed(int value, float width)
	{
		string s = GUILayout.TextField(value.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(width * Skin.Scale) });
		if (!int.TryParse(s, out var result) || result <= 0)
		{
			return value;
		}
		return result;
	}

	private static string FirstEventId()
	{
		if (GameEvents.All.Count <= 0)
		{
			return "";
		}
		return GameEvents.All[0].Id;
	}

	private static string EventTitle(string id)
	{
		for (int i = 0; i < GameEvents.All.Count; i++)
		{
			if (string.Equals(GameEvents.All[i].Id, id, StringComparison.OrdinalIgnoreCase))
			{
				return GameEvents.All[i].Title;
			}
		}
		return id;
	}

	private static string NextTrigger(string current)
	{
		for (int i = 0; i < Rewards.Triggers.Length; i++)
		{
			if (string.Equals(Rewards.Triggers[i], current, StringComparison.OrdinalIgnoreCase))
			{
				return Rewards.Triggers[(i + 1) % Rewards.Triggers.Length];
			}
		}
		return Rewards.Triggers[0];
	}

	private void DrawWebhook()
	{
		GUILayout.Label(Lang.WebhookTitle, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.WebhookHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		bool flag = GUILayout.Toggle(Plugin.CfgWebhookEnabled.Value, "  http://127.0.0.1:" + Plugin.CfgWebhookPort.Value + "/", (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (flag != Plugin.CfgWebhookEnabled.Value)
		{
			Plugin.CfgWebhookEnabled.Value = flag;
			LocalWebhook component = ((Component)this).GetComponent<LocalWebhook>();
			if ((Object)(object)component != (Object)null)
			{
				if (flag)
				{
					component.Begin();
				}
				else
				{
					component.Stop();
				}
			}
		}
		GUILayout.EndHorizontal();
		GUILayout.Label(LocalWebhook.Status, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
	}

	private void DrawAuth()
	{
		//IL_01e8: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label(Lang.AuthTitle, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.AuthHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		bool flag = GUILayout.Toggle(Plugin.CfgEventSubEnabled.Value, "  " + Lang.AuthTitle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (flag != Plugin.CfgEventSubEnabled.Value)
		{
			Plugin.CfgEventSubEnabled.Value = flag;
			EventSub component = ((Component)this).GetComponent<EventSub>();
			if ((Object)(object)component != (Object)null)
			{
				if (flag)
				{
					component.Begin();
				}
				else
				{
					component.Stop();
				}
			}
		}
		GUILayout.FlexibleSpace();
		GUILayout.Label(EventSub.Status, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndHorizontal();
		if (!Plugin.CfgEventSubEnabled.Value)
		{
			GUILayout.Label(Lang.EventSubFallback, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			return;
		}
		if (!TwitchAuth.HasBuiltIn)
		{
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Label(Lang.AuthClientId, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f * Skin.Scale) });
			Plugin.CfgTwitchClientId.Value = GUILayout.TextField(Plugin.CfgTwitchClientId.Value, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.EndHorizontal();
			GUILayout.Label(Lang.AuthClientIdHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Space(4f);
		}
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (TwitchAuth.Waiting)
		{
			if (GUILayout.Button(Lang.AuthCancel, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f * Skin.Scale) }))
			{
				TwitchAuth.Cancel();
			}
		}
		else if (TwitchAuth.Ready)
		{
			if (GUILayout.Button(Lang.AuthLogout, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f * Skin.Scale) }))
			{
				EventSub component2 = ((Component)this).GetComponent<EventSub>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.Stop();
				}
				TwitchAuth.Forget();
			}
		}
		else
		{
			Color color = GUI.color;
			GUI.color = Skin.Warn;
			if (GUILayout.Button(Lang.AuthConnect, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f * Skin.Scale) }))
			{
				((MonoBehaviour)this).StartCoroutine(TwitchAuth.Begin());
			}
			GUI.color = color;
		}
		GUILayout.FlexibleSpace();
		GUILayout.Label(TwitchAuth.Status, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndHorizontal();
		if (TwitchAuth.Ready)
		{
			string text = ((TwitchAuth.Login == null) ? "" : TwitchAuth.Login).Trim().ToLowerInvariant();
			string text2 = ((Plugin.CfgChannel.Value == null) ? "" : Plugin.CfgChannel.Value).Trim().TrimStart('#').ToLowerInvariant();
			if (text.Length > 0 && text2.Length > 0 && text != text2)
			{
				GUILayout.Space(6f);
				GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]);
				Color color2 = GUI.color;
				GUI.color = Skin.Warn;
				GUILayout.Label(Lang.ChannelMismatch(text, text2), Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
				GUI.color = color2;
				if (GUILayout.Button(Lang.ChannelAlign(text), (GUILayoutOption[])(object)new GUILayoutOption[0]))
				{
					Plugin.CfgChannel.Value = text;
					_channelDraft = text;
					Plugin.Reconnect();
				}
				GUILayout.EndVertical();
			}
		}
		if (!string.IsNullOrEmpty(TwitchAuth.UserCode))
		{
			GUILayout.Space(6f);
			GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Label(Lang.AuthTypeCode, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			Color color3 = GUI.color;
			GUI.color = Skin.Warn;
			GUILayout.Label(TwitchAuth.UserCode, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color3;
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			if (GUILayout.Button(Lang.LinksCopy, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f * Skin.Scale) }))
			{
				Copy(Lang.AuthTypeCode, TwitchAuth.UserCode);
			}
			if (GUILayout.Button(Lang.AuthOpenPage, (GUILayoutOption[])(object)new GUILayoutOption[0]))
			{
				Open(TwitchAuth.VerifyUrl);
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}
	}

	private void DrawLivePix()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label(Lang.LivePixTitle, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.LivePixHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		bool flag = GUILayout.Toggle(Plugin.CfgLivePixEnabled.Value, "  " + Lang.LivePixTitle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (flag != Plugin.CfgLivePixEnabled.Value)
		{
			Plugin.CfgLivePixEnabled.Value = flag;
			LivePix component = ((Component)this).GetComponent<LivePix>();
			if ((Object)(object)component != (Object)null)
			{
				if (flag)
				{
					component.Begin();
				}
				else
				{
					component.Stop();
				}
			}
		}
		GUILayout.FlexibleSpace();
		GUILayout.Label(LivePix.Status, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndHorizontal();
		if (!Plugin.CfgLivePixEnabled.Value)
		{
			return;
		}
		GUILayout.Label(Lang.LivePixKeysHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Color color = GUI.color;
		GUI.color = (Secrets.Available ? Skin.Good : Skin.Warn);
		GUILayout.Label(Secrets.Available ? Lang.SecretsSafe : Lang.SecretsPlain, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUI.color = color;
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label("Client ID", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f * Skin.Scale) });
		Plugin.CfgLivePixClientId.Value = GUILayout.TextField(Plugin.CfgLivePixClientId.Value, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label("Secret", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f * Skin.Scale) });
		if (Plugin.LivePixSecret.Length > 0)
		{
			GUILayout.Label(Secrets.Masked(Plugin.LivePixSecret), (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.FlexibleSpace();
			if (GUILayout.Button(Lang.SecretForget, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f * Skin.Scale) }))
			{
				Plugin.LivePixSecret = "";
				_pixDraft = "";
			}
		}
		else
		{
			_pixDraft = GUILayout.PasswordField(_pixDraft, '*', (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.enabled = _pixDraft.Trim().Length > 0;
			if (GUILayout.Button(Lang.Ok, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f * Skin.Scale) }))
			{
				Plugin.LivePixSecret = _pixDraft;
				_pixDraft = "";
			}
			GUI.enabled = true;
		}
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.LivePixEvery, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f * Skin.Scale) });
		Plugin.CfgLivePixSeconds.Value = Mathf.Round(GUILayout.HorizontalSlider(Plugin.CfgLivePixSeconds.Value, 5f, 120f, (GUILayoutOption[])(object)new GUILayoutOption[0]));
		GUILayout.Label(Plugin.CfgLivePixSeconds.Value + Lang.LivePixSeconds, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f * Skin.Scale) });
		GUILayout.EndHorizontal();
	}

	private void DrawLinks()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label(Lang.LinksTitle, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.LinksNative, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(4f);
		GUILayout.Label(Lang.LinksExternal, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (!Plugin.CfgWebhookEnabled.Value)
		{
			Color color = GUI.color;
			GUI.color = Skin.Warn;
			GUILayout.Label(Lang.LinksOffHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color;
		}
		GUILayout.Space(6f);
		string text = "http://127.0.0.1:" + Plugin.CfgWebhookPort.Value + "/";
		LinkRow("LivePix / Streamlabs / StreamElements", text + "?tipo=pix&valor=VALOR&nome=NOME&mensagem=MENSAGEM");
		LinkRow("Pontos de canal", text + "?tipo=pontos&valor=1&nome=NOME");
		LinkRow("Bits por fora (bot, Stream Deck)", text + "?tipo=bits&valor=VALOR&nome=NOME");
		GUILayout.Space(4f);
		GUILayout.Label(Lang.LinksPlaceholders, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(6f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.LinksTest, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f * Skin.Scale) });
		string text2 = text + "?tipo=pix&valor=50&nome=Teste";
		if (GUILayout.Button(text2, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			Open(text2);
		}
		GUILayout.EndHorizontal();
		if (Time.unscaledTime < _copiedUntil)
		{
			Color color2 = GUI.color;
			GUI.color = Skin.Warn;
			GUILayout.Label(Lang.LinksCopied + "  " + _copiedWhat, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color2;
		}
	}

	private void LinkRow(string what, string url)
	{
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(what, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(230f * Skin.Scale) });
		GUILayout.Label(url, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (GUILayout.Button(Lang.LinksCopy, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f * Skin.Scale) }))
		{
			Copy(what, url);
		}
		GUILayout.EndHorizontal();
	}

	private void Copy(string what, string url)
	{
		try
		{
			GUIUtility.systemCopyBuffer = url;
			_copiedWhat = what;
			_copiedUntil = Time.unscaledTime + 3f;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Nao consegui copiar: " + ex.Message));
		}
	}

	private static void Open(string url)
	{
		try
		{
			Application.OpenURL(url);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Nao consegui abrir o navegador: " + ex.Message));
		}
	}

	private void DrawSkins()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label(Lang.SkinsTitle, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.SkinsHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(10f);
		Color color = GUI.color;
		GUI.color = Skin.Good;
		if (GUILayout.Button(Lang.ReloadSkins, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(38f * Skin.Scale) }))
		{
			ItemSkins.Apply();
		}
		GUI.color = color;
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (GUILayout.Button(Lang.OpenSkinsFolder, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f * Skin.Scale) }))
		{
			OpenSkinsFolder();
		}
		GUILayout.Space(8f);
		GUI.color = Skin.Warn;
		if (GUILayout.Button(Lang.RestoreSkins, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f * Skin.Scale) }))
		{
			ItemSkins.RestoreAll();
		}
		GUI.color = color;
		GUILayout.EndHorizontal();
		if (!string.IsNullOrEmpty(ItemSkins.Status))
		{
			GUILayout.Space(6f);
			GUILayout.Label(ItemSkins.Status, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		GUILayout.Space(12f);
		GUILayout.Label(Lang.SkinsItemList, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.SkinsExportHint, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		_itemFilter = GUILayout.TextField(_itemFilter, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(24f * Skin.Scale) });
		_skinScroll = GUILayout.BeginScrollView(_skinScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(220f * Skin.Scale) });
		string[] names = ItemCatalog.Names;
		for (int i = 0; i < names.Length; i++)
		{
			if ((_itemFilter.Length <= 0 || names[i].IndexOf(_itemFilter, StringComparison.OrdinalIgnoreCase) >= 0) && GUILayout.Button(names[i], Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]))
			{
				ItemSkins.Export(names[i]);
			}
		}
		GUILayout.EndScrollView();
	}

	private static void OpenSkinsFolder()
	{
		ItemSkins.EnsureFolder();
		try
		{
			Application.OpenURL("file:///" + ItemSkins.Folder.Replace("\\", "/"));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Nao consegui abrir a pasta: " + ex.Message));
		}
	}

	private void DrawModeButton(string valor, string nome, string dica)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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_0030: 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)
		bool flag = string.Equals(Plugin.CfgMode.Value, valor, StringComparison.OrdinalIgnoreCase);
		GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Color color = GUI.color;
		GUI.color = (flag ? Skin.Accent : Skin.Muted);
		if (GUILayout.Button((flag ? "● " : "○ ") + nome, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f * Skin.Scale) }))
		{
			Plugin.CfgMode.Value = valor;
		}
		GUI.color = color;
		GUILayout.Label(dica, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndVertical();
	}

	private static void Zoom(float passo)
	{
		if (Plugin.CfgFontScale != null)
		{
			Plugin.CfgFontScale.Value = Mathf.Clamp(Plugin.CfgFontScale.Value + passo, 0.7f, 2.5f);
		}
	}

	private float Slider(string label, float value, float min, float max, string format)
	{
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(180f) });
		float result = GUILayout.HorizontalSlider(value, min, max, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(result.ToString(format), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) });
		GUILayout.EndHorizontal();
		return result;
	}

	private void DrawEvents()
	{
		//IL_0022: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label(Lang.EventsHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(6f);
		_eventScroll = GUILayout.BeginScrollView(_eventScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(340f) });
		for (int i = 0; i < GameEvents.All.Count; i++)
		{
			DrawEventRow(GameEvents.All[i], i);
			GUILayout.Space(6f);
		}
		GUILayout.EndScrollView();
		DrawDefaultsButton(EventEntries());
	}

	private static List<ConfigEntryBase> EventEntries()
	{
		List<ConfigEntryBase> list = new List<ConfigEntryBase>();
		for (int i = 0; i < GameEvents.All.Count; i++)
		{
			GameEvent gameEvent = GameEvents.All[i];
			list.Add((ConfigEntryBase)(object)gameEvent.Enabled);
			list.Add((ConfigEntryBase)(object)gameEvent.ItemName);
			list.Add((ConfigEntryBase)(object)gameEvent.Amount);
			list.Add((ConfigEntryBase)(object)gameEvent.Intensity);
		}
		return list;
	}

	private void DrawEventRow(GameEvent option, int index)
	{
		//IL_0020: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		Color color = GUI.color;
		GUI.color = (option.IsGood ? new Color(0.6f, 1f, 0.6f) : new Color(1f, 0.7f, 0.7f));
		GUILayout.Label(option.IsGood ? "[+]" : "[-]", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) });
		GUI.color = color;
		option.Enabled.Value = GUILayout.Toggle(option.Enabled.Value, " " + option.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndHorizontal();
		GUILayout.Label(option.Description, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (option.UsesItem)
		{
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Label(Lang.Item, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) });
			if (GUILayout.Button(option.ItemName.Value + "   ▼", (GUILayoutOption[])(object)new GUILayoutOption[0]))
			{
				_dropdownFor = ((_dropdownFor == index) ? (-1) : index);
				_itemFilter = "";
			}
			GUILayout.EndHorizontal();
			if (_dropdownFor == index)
			{
				DrawItemDropdown(option);
			}
		}
		if (option.UsesItem || option.Kind == EventKind.Tornado || option.Kind == EventKind.Zombies)
		{
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Label(Lang.Amount, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			if (GUILayout.Button("-", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(26f) }) && option.Amount.Value > 1)
			{
				ConfigEntry<int> amount = option.Amount;
				amount.Value -= 1;
			}
			GUILayout.Label(option.Amount.Value.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
			if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(26f) }))
			{
				ConfigEntry<int> amount2 = option.Amount;
				amount2.Value += 1;
			}
			GUILayout.EndHorizontal();
		}
		if (option.UsesIntensity)
		{
			option.Intensity.Value = Slider(Lang.Intensity, option.Intensity.Value, 0.05f, 1f, "0.00");
		}
		GUILayout.EndVertical();
	}

	private void DrawItemDropdown(GameEvent option)
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.Search, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) });
		_itemFilter = GUILayout.TextField(_itemFilter, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndHorizontal();
		string[] names = ItemCatalog.Names;
		if (names.Length == 0)
		{
			GUILayout.Label(Lang.NoItems, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		else
		{
			_itemScroll = GUILayout.BeginScrollView(_itemScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(150f) });
			int num = 0;
			for (int i = 0; i < names.Length; i++)
			{
				if (_itemFilter.Length <= 0 || names[i].IndexOf(_itemFilter, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					num++;
					string text = ((names[i] == option.ItemName.Value) ? "• " : "   ");
					if (GUILayout.Button(text + names[i], (GUILayoutOption[])(object)new GUILayoutOption[0]))
					{
						option.ItemName.Value = names[i];
						_dropdownFor = -1;
					}
				}
			}
			if (num == 0)
			{
				GUILayout.Label(Lang.NothingNamed, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			}
			GUILayout.EndScrollView();
		}
		GUILayout.EndVertical();
	}

	private void DrawZombies()
	{
		GUILayout.Label(Lang.ZombieTuning, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.ZombieTuningHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(10f);
		Plugin.CfgZombieStrength.Value = Slider(Lang.ZombieStrength, Plugin.CfgZombieStrength.Value, 0.25f, 4f, "0.00");
		GUILayout.Label(Lang.ZombieStrengthHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(8f);
		Plugin.CfgZombieSpeed.Value = Slider(Lang.ZombieSpeed, Plugin.CfgZombieSpeed.Value, 0.25f, 4f, "0.00");
		GUILayout.Label(Lang.ZombieSpeedHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(8f);
		Plugin.CfgZombieAggression.Value = Slider(Lang.ZombieAggression, Plugin.CfgZombieAggression.Value, 0.25f, 4f, "0.00");
		GUILayout.Label(Lang.ZombieAggressionHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(12f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (GUILayout.Button(Lang.PresetWeak, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
		{
			SetTuning(0.5f, 0.6f, 0.6f);
		}
		if (GUILayout.Button(Lang.PresetNormal, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
		{
			SetTuning(1f, 1f, 1f);
		}
		if (GUILayout.Button(Lang.PresetBrutal, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
		{
			SetTuning(2.5f, 2f, 2f);
		}
		GUILayout.EndHorizontal();
		GUILayout.Space(12f);
		if (GUILayout.Button(Lang.ApplyToExisting, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
		{
			ZombieTuning.Reset();
			ZombieTuning.ApplyToAll();
		}
		GUILayout.Label(Lang.ApplyToExistingHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(12f);
		GUILayout.Label(Lang.ZombieDefence, Skin.Title, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.AmountEach, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f * Skin.Scale) });
		if (GUILayout.Button("-", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(26f) }) && Plugin.CfgZombieDefenseCount.Value > 1)
		{
			ConfigEntry<int> cfgZombieDefenseCount = Plugin.CfgZombieDefenseCount;
			cfgZombieDefenseCount.Value -= 1;
		}
		GUILayout.Label(Plugin.CfgZombieDefenseCount.Value.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
		if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(26f) }) && Plugin.CfgZombieDefenseCount.Value < 10)
		{
			ConfigEntry<int> cfgZombieDefenseCount2 = Plugin.CfgZombieDefenseCount;
			cfgZombieDefenseCount2.Value += 1;
		}
		GUILayout.EndHorizontal();
		GUILayout.Label(Lang.ZombieDefenceHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		DrawDefaultsButton(new List<ConfigEntryBase>
		{
			(ConfigEntryBase)(object)Plugin.CfgZombieStrength,
			(ConfigEntryBase)(object)Plugin.CfgZombieSpeed,
			(ConfigEntryBase)(object)Plugin.CfgZombieAggression,
			(ConfigEntryBase)(object)Plugin.CfgZombieLifetime,
			(ConfigEntryBase)(object)Plugin.CfgZombieDefenseItem,
			(ConfigEntryBase)(object)Plugin.CfgZombieDefenseCount
		});
	}

	private static void SetTuning(float strength, float speed, float aggression)
	{
		Plugin.CfgZombieStrength.Value = strength;
		Plugin.CfgZombieSpeed.Value = speed;
		Plugin.CfgZombieAggression.Value = aggression;
	}

	private void DrawTesting()
	{
		//IL_0007: 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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: 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_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: 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_0192: 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_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.IsGuest)
		{
			Color color = GUI.color;
			GUI.color = Skin.Accent;
			GUILayout.Label(Lang.GuestActive, Skin.Label, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color;
			GUILayout.Space(6f);
		}
		if (GUILayout.Button(Lang.OpenVoteNow, (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			if ((Object)(object)_voting != (Object)null)
			{
				_voting.StartVote();
			}
			Close();
			GUI.enabled = true;
			return;
		}
		GUILayout.Label(Lang.OpenVoteHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUI.enabled = true;
		GUILayout.Space(10f);
		Color color2 = GUI.color;
		GUI.color = Skin.Warn;
		if (GUILayout.Button(Lang.StopAll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }))
		{
			GameEvents.StopEverything();
		}
		GUI.color = color2;
		GUILayout.Label(Lang.StopAllHint, _sub, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(10f);
		for (int i = 0; i < GameEvents.All.Count; i++)
		{
			GameEvent gameEvent = GameEvents.All[i];
			if (gameEvent.ManualOnly)
			{
				gameEvent.Intensity.Value = Slider(gameEvent.Title + (Lang.English ? " lasts (s)" : " dura (s)"), gameEvent.Intensity.Value, 0f, 900f, "0");
			}
		}
		GUILayout.Space(10f);
		GUILayout.Label(Lang.FireEvent, _header, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (!Plugin.CanAffectGame)
		{
			Color color3 = GUI.color;
			GUI.color = Skin.Warn;
			GUILayout.Label(Lang.OnlyHostCan, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color3;
		}
		GUI.enabled = Plugin.CanAffectGame;
		_testScroll = GUILayout.BeginScrollView(_testScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(300f) });
		for (int j = 0; j < GameEvents.All.Count; j++)
		{
			GameEvent gameEvent2 = GameEvents.All[j];
			Color color4 = GUI.color;
			if (gameEvent2.ManualOnly)
			{
				GUI.color = Skin.Accent;
			}
			else
			{
				GUI.color = (gameEvent2.IsGood ? new Color(0.7f, 1f, 0.7f) : new Color(1f, 0.8f, 0.8f));
			}
			string text = (gameEvent2.ManualOnly ? ("★ " + gameEvent2.Title) : ((gameEvent2.IsGood ? "[+] " : "[-] ") + gameEvent2.Title));
			if (GUILayout.Button(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height((float)(gameEvent2.ManualOnly ? 34 : 24)) }))
			{
				Plugin.Log.LogInfo((object)("Teste manual: " + gameEvent2.Title));
				try
				{
					gameEvent2.Run();
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Falhou: " + ex));
				}
			}
			GUI.color = color4;
		}
		GUILayout.EndScrollView();
		GUI.enabled = true;
		List<ConfigEntryBase> list = new List<ConfigEntryBase>();
		for (int k = 0; k < GameEvents.All.Count; k++)
		{
			if (GameEvents.All[k].ManualOnly)
			{
				list.Add((ConfigEntryBase)(object)GameEvents.All[k].Intensity);
			}
		}
		list.Add((ConfigEntryBase)(object)Plugin.CfgSuspenseSound);
		list.Add((ConfigEntryBase)(object)Plugin.CfgSuspenseInterval);
		list.Add((ConfigEntryBase)(object)Plugin.CfgHoverSeconds);
		DrawDefaultsButton(list);
	}
}
public class EventSub : MonoBehaviour
{
	private const string SocketUrl = "wss://eventsub.wss.twitch.tv/ws";

	private const string HelixSubs = "https://api.twitch.tv/helix/eventsub/subscriptions";

	private static readonly string[][] Wanted = new string[5][]
	{
		new string[2] { "channel.cheer", "1" },
		new string[2] { "channel.subscribe", "1" },
		new string[2] { "channel.subscription.message", "1" },
		new string[2] { "channel.subscription.gift", "1" },
		new string[2] { "channel.channel_points_custom_reward_redemption.add", "1" }
	};

	private WebSocket _socket;

	private string _sessionId;

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

	private float _silentSince;

	private float _keepaliveWindow = 30f;

	private bool _closing;

	public static string Status = "desligado";

	public static int Subscribed;

	public bool Live
	{
		get
		{
			if (_socket != null)
			{
				return _socket.IsAlive;
			}
			return false;
		}
	}

	private void OnEnable()
	{
		TwitchAuth.Connected = (Action)Delegate.Combine(TwitchAuth.Connected, new Action(OnAuthorised));
	}

	private void OnDisable()
	{
		TwitchAuth.Connected = (Action)Delegate.Remove(TwitchAuth.Connected, new Action(OnAuthorised));
	}

	private void OnAuthorised()
	{
		if (Plugin.CfgEventSubEnabled.Value)
		{
			Begin();
		}
	}

	public void Begin()
	{
		if (_socket == null)
		{
			if (!TwitchAuth.Ready)
			{
				Status = Lang.EventSubNoAuth;
			}
			else
			{
				Open("wss://eventsub.wss.twitch.tv/ws");
			}
		}
	}

	private void Open(string url)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		try
		{
			_closing = false;
			WebSocket val = new WebSocket(url, new string[0]);
			val.OnMessage += delegate(object sender, MessageEventArgs e)
			{
				if (e.IsText)
				{
					_incoming.Enqueue(e.Data);
				}
			};
			val.OnError += delegate(object sender, ErrorEventArgs e)
			{
				Plugin.Log.LogWarning((object)("EventSub: " + e.Message));
			};
			val.OnClose += delegate(object sender, CloseEventArgs e)
			{
				if (!_closing)
				{
					Plugin.Log.LogWarning((object)("EventSub caiu (" + e.Code + " " + e.Reason + ")."));
					Status = Lang.EventSubDropped;
				}
			};
			val.ConnectAsync();
			_socket = val;
			_silentSince = Time.unscaledTime;
			Status = Lang.EventSubConnecting;
			Plugin.Log.LogInfo((object)"EventSub: conectando.");
		}
		catch (Exception ex)
		{
			Status = "falhou: " + ex.Message;
			Plugin.Log.LogWarning((object)("EventSub nao abriu: " + ex.Message));
			_socket = null;
		}
	}

	public void Stop()
	{
		_closing = true;
		_sessionId = null;
		Subscribed = 0;
		WebSocket socket = _socket;
		_socket = null;
		if (socket != null)
		{
			try
			{
				socket.Close();
			}
			catch
			{
			}
		}
		Status = "desligado";
	}

	private void OnDestroy()
	{
		Stop();
	}

	private void Update()
	{
		string result;
		while (_incoming.TryDequeue(out result))
		{
			_silentSince = Time.unscaledTime;
			Handle(result);
		}
		if (_socket != null && !_closing && Time.unscaledTime - _silentSince > _keepaliveWindow + 10f)
		{
			Plugin.Log.LogWarning((object)"EventSub calado demais; reconectando.");
			Restart();
		}
	}

	private void Restart()
	{
		Stop();
		Begin();
	}

	private void Handle(string text)
	{
		JObject val;
		try
		{
			val = JObject.Parse(text);
		}
		catch (Exception)
		{
			Plugin.Log.LogWarning((object)"EventSub mandou algo que nao e json.");
			return;
		}
		JToken val2 = val["metadata"];
		if (val2 != null)
		{
			string text2 = (string)val2[(object)"message_type"];
			JToken payload = val["payload"];
			switch (text2)
			{
			case "session_welcome":
				Welcome(payload);
				break;
			case "notification":
				Notify((string)val2[(object)"subscription_type"], payload);
				break;
			case "session_reconnect":
				Reconnect(payload);
				break;
			case "revocation":
				Revoked(payload);
				break;
			case "session_keepalive":
				break;
			}
		}
	}

	private void Welcome(JToken payload)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Invalid comparison between Unknown and I4
		JToken val = ((payload == null) ? null : payload[(object)"session"]);
		if (val != null)
		{
			_sessionId = (string)val[(object)"id"];
			if (val[(object)"keepalive_timeout_seconds"] != null && (int)val[(object)"keepalive_timeout_seconds"].Type != 10)
			{
				_keepaliveWindow = (float)val[(object)"keepalive_timeout_seconds"];
			}
			Plugin.Log.LogInfo((object)("EventSub conectado (sessao " + _sessionId + ")."));
			((MonoBehaviour)this).StartCoroutine(SubscribeAll());
		}
	}

	private IEnumerator SubscribeAll()
	{
		Subscribed = 0;
		for (int i = 0; i < Wanted.Length; i++)
		{
			yield return Subscribe(Wanted[i][0], Wanted[i][1]);
		}
		Status = Lang.EventSubLive(Subscribed, Wanted.Length);
		Plugin.Log.LogInfo((object)("EventSub: " + Subscribed + " de " + Wanted.Length + " assinaturas ativas."));
		if (Subscribed == 0)
		{
			Plugin.Log.LogWarning((object)"Nenhuma assinatura passou. Provavelmente o token nao tem as permissoes, ou quem autorizou nao e o dono do canal.");
		}
	}

	private IEnumerator Subscribe(string type, string version)
	{
		JObject condition = new JObject();
		condition["broadcaster_user_id"] = JToken.op_Implicit(TwitchAuth.UserId);
		if (type.StartsWith("channel.channel_points", StringComparison.Ordinal))
		{
			condition["user_id"] = JToken.op_Implicit(TwitchAuth.UserId);
		}
		JObject transport = new JObject();
		transport["method"] = JToken.op_Implicit("websocket");
		transport["session_id"] = JToken.op_Implicit(_sessionId);
		JObject body = new JObject();
		body["type"] = JToken.op_Implicit(type);
		body["version"] = JToken.op_Implicit(version);
		body["condition"] = (JToken)(object)condition;
		body["transport"] = (JToken)(object)transport;
		byte[] payload = Encoding.UTF8.GetBytes(((object)body).ToString());
		UnityWebRequest request = new UnityWebRequest("https://api.twitch.tv/helix/eventsub/subscriptions", "POST");
		try
		{
			request.uploadHandler = (UploadHandler)new UploadHandlerRaw(payload);
			request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
			request.SetRequestHeader("Content-Type", "application/json");
			request.SetRequestHeader("Client-Id", TwitchAuth.ClientId);
			request.SetRequestHeader("Authorization", "Bearer " + Plugin.TwitchToken);
			yield return request.SendWebRequest();
			if ((int)request.result == 1)
			{
				Subscribed++;
				Plugin.Log.LogInfo((object)("EventSub assinou " + type + "."));
			}
			else
			{
				string why = ((request.downloadHandler == null) ? request.error : request.downloadHandler.text);
				Plugin.Log.LogWarning((object)("EventSub nao assinou " + type + ": " + why));
			}
		}
		finally
		{
			((IDisposable)request)?.Dispose();
		}
	}

	private void Reconnect(JToken payload)
	{
		JToken val = ((payload == null) ? null : payload[(object)"session"]);
		string text = ((val == null) ? null : ((string)val[(object)"reconnect_url"]));
		if (string.IsNullOrEmpty(text))
		{
			Restart();
			return;
		}
		Plugin.Log.LogInfo((object)"EventSub pediu pra trocar de servidor.");
		WebSocket socket = _socket;
		_socket = null;
		Open(text);
		if (socket == null)
		{
			return;
		}
		try
		{
			socket.Close();
		}
		catch
		{
		}
	}

	private void Revoked(JToken payload)
	{
		JToken val = ((payload == null) ? null : payload[(object)"subscription"]);
		if (val != null)
		{
			string text = (string)val[(object)"type"];
			string text2 = (string)val[(object)"status"];
			Plugin.Log.LogWarning((object)("A Twitch cancelou " + text + " (" + text2 + ")."));
			if (Subscribed > 0)
			{
				Subscribed--;
			}
			Status = Lang.EventSubLive(Subscribed, Wanted.Length);
			if (text2 == "authorization_revoked")
			{
				TwitchAuth.Forget();
			}
		}
	}

	private void Notify(string type, JToken payload)
	{
		JToken val = ((payload == null) ? null : payload[(object)"event"]);
		if (val != null && type != null)
		{
			string text = Text(val[(object)"user_name"]);
			if (string.IsNullOrEmpty(text))
			{
				text = Text(val[(object)"user_login"]);
			}
			if (Flag(val[(object)"is_anonymous"]))
			{
				text = Lang.Anonymous;
			}
			if (string.IsNullOrEmpty(text))
			{
				text = Lang.Anonymous;
			}
			switch (type)
			{
			case "channel.cheer":
				Fire(text, ChatKind.Cheer, Number(val[(object)"bits"], 1), Text(val[(object)"message"]));
				break;
			case "channel.subscribe":
				Fire(text, ChatKind.Sub, 1, "");
				break;
			case "channel.subscription.message":
			{
				JToken val3 = val[(object)"message"];
				Fire(text, ChatKind.Sub, Number(val[(object)"cumulative_months"], 1), (val3 == null) ? "" : Text(val3[(object)"text"]));
				break;
			}
			case "channel.subscription.gift":
				Fire(text, ChatKind.SubGift, Number(val[(object)"total"], 1), "");
				break;
			case "channel.channel_points_custom_reward_redemption.add":
			{
				JToken val2 = val[(object)"reward"];
				Fire(text, ChatKind.ChannelPoints, (val2 == null) ? 1 : Number(val2[(object)"cost"], 1), (val2 == null) ? "" : Text(val2[(object)"title"]));
				break;
			}
			}
		}
	}

	private static void Fire(string who, ChatKind kind, int amount, string message)
	{
		Plugin.Log.LogInfo((object)string.Concat("EventSub: ", kind, " ", amount, " de ", who));
		Rewards.Handle(who, kind, amount, message);
	}

	private static string Text(JToken token)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		if (token != null && (int)token.Type != 10)
		{
			return (string)token;
		}
		return "";
	}

	private static int Number(JToken token, int fallback)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		if (token == null || (int)token.Type == 10)
		{
			return fallback;
		}
		try
		{
			return (int)token;
		}
		catch (Exception)
		{
			return fallback;
		}
	}

	private static bool Flag(JToken token)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		if (token == null || (int)token.Type == 10)
		{
			return false;
		}
		try
		{
			return (bool)token;
		}
		catch (Exception)
		{
			return false;
		}
	}
}
public class EventVoting : MonoBehaviour
{
	private enum Phase
	{
		Waiting,
		Voting,
		Announcing
	}

	private Phase _phase;

	private float _nextEventAt;

	private float _phaseEndsAt;

	private List<GameEvent> _ballot = new List<GameEvent>();

	private readonly int[] _votes = new int[5];

	private readonly HashSet<string> _voters = new HashSet<string>();

	private GameEvent _winner;

	private string _winnerLine = "";

	private int _winnerIndex = -1;

	private bool _wasInRoom;

	private float _nextBroadcast;

	public float SecondsUntilNext
	{
		get
		{
			if (_phase != Phase.Waiting)
			{
				return -1f;
			}
			return Mathf.Max(0f, _nextEventAt - Now);
		}
	}

	public bool IsIdle => _phase == Phase.Waiting;

	public bool Paused { get; private set; }

	private static float Now => Time.unscaledTime;

	public void SetPaused(bool paused)
	{
		if (Paused == paused)
		{
			return;
		}
		Paused = paused;
		if (!paused)
		{
			GameEvents.ResetSacrificeUse();
			if (_phase == Phase.Waiting)
			{
				ScheduleNext();
			}
		}
		Plugin.Log.LogInfo((object)(paused ? "Mod pausado: a contagem parou." : ("Mod iniciado: proxima votacao em " + Plugin.CfgSecondsBetween.Value + "s.")));
	}

	private void Start()
	{
		Paused = true;
		ScheduleNext();
	}

	private void ScheduleNext()
	{
		_phase = Phase.Waiting;
		_nextEventAt = Now + Mathf.Max(5f, Plugin.CfgSecondsBetween.Value);
	}

	private void Update()
	{
		if (!Plugin.CfgEnabled.Value || Plugin.IsGuest)
		{
			return;
		}
		bool inRoom = PhotonNetwork.InRoom;
		if (inRoom != _wasInRoom)
		{
			_wasInRoom = inRoom;
			GameEvents.ForgetWorldState();
			if (inRoom)
			{
				ItemSkins.Apply();
			}
			if (inRoom)
			{
				Paused = true;
				ScheduleNext();
				Plugin.Log.LogInfo((object)"Partida comecou. O mod entra PAUSADO: aperte F6 e clique em Iniciar quando quiser comecar.");
			}
		}
		if (!inRoom)
		{
			if (_phase == Phase.Waiting)
			{
				_nextEventAt = Now + Mathf.Max(5f, Plugin.CfgSecondsBetween.Value);
			}
			return;
		}
		Broadcast();
		if (Paused && _phase == Phase.Waiting)
		{
			_nextEventAt = Now + Mathf.Max(5f, Plugin.CfgSecondsBetween.Value);
			return;
		}
		switch (_phase)
		{
		case Phase.Waiting:
			if (Now >= _nextEventAt)
			{
				StartVote();
			}
			break;
		case Phase.Voting:
			if (Now >= _phaseEndsAt)
			{
				FinishVote();
			}
			break;
		case Phase.Announcing:
			if (Now >= _phaseEndsAt)
			{
				ScheduleNext();
			}
			break;
		}
	}

	private void Broadcast()
	{
		if (PhotonNetwork.IsMasterClient && !(Now < _nextBroadcast))
		{
			_nextBroadcast = Now + 0.4f;
			string[] array = new string[_ballot.Count];
			bool[] array2 = new bool[_ballot.Count];
			int[] array3 = new int[_ballot.Count];
			for (int i = 0; i < _ballot.Count; i++)
			{
				array[i] = _ballot[i].Title;
				array2[i] = _ballot[i].IsGood;
				array3[i] = _votes[i];
			}
			byte phase = (byte)((_phase == Phase.Voting) ? 1 : ((_phase == Phase.Announcing) ? 2 : 0));
			Net.SendVoteState(array, array2, array3, Mathf.Max(0f, _phaseEndsAt - Now), phase, _winnerLine, _winnerIndex);
		}
	}

	public void StartVote()
	{
		if (Plugin.IsGuest)
		{
			Plugin.Log.LogInfo((object)"Modo convidado: a votacao e do host.");
			return;
		}
		_ballot = GameEvents.BuildBallot();
		if (_ballot.Count == 0)
		{
			ScheduleNext();
			return;
		}
		for (int i = 0; i < _votes.Length; i++)
		{
			_votes[i] = 0;
		}
		_voters.Clear();
		GameEvents.RememberBallot(_ballot);
		_winnerIndex = -1;
		_phase = Phase.Voting;
		_phaseEndsAt = Now + Mathf.Max(10f, Plugin.CfgVoteSeconds.Value);
		Plugin.Log.LogInfo((object)"Votacao aberta:");
		for (int j = 0; j < _ballot.Count; j++)
		{
			Plugin.Log.LogInfo((object)("  " + (j + 1) + ") " + _ballot[j].Title));
		}
	}

	public void RegisterVote(string author, string text)
	{
		if (_phase != Phase.Voting || string.IsNullOrEmpty(text))
		{
			return;
		}
		string text2 = text.Trim();
		if (text2.Length != 0 && int.TryParse(text2, out var result) && result >= 1 && result <= _ballot.Count)
		{
			string item = ((author == null) ? "" : author).ToLowerInvariant();
			if (!_voters.Contains(item))
			{
				_voters.Add(item);
				_votes[result - 1]++;
			}
		}
	}

	private void FinishVote()
	{
		int num = 0;
		for (int i = 1; i < _ballot.Count; i++)
		{
			if (_votes[i] > _votes[num])
			{
				num = i;
			}
		}
		if (_votes[num] == 0)
		{
			num = Random.Range(0, _ballot.Count);
		}
		_winner = _ballot[num];
		_winnerIndex = num;
		_winnerLine = _winner.Title + " (" + _votes[num] + " " + Lang.Votes + ")";
		Plugin.Log.LogInfo((object)("Votacao encerrada -> " + _winnerLine));
		Net.SendAnnounce(_winner.Id, _winner.Title, _winner.Description, _winner.IsGood);
		Tts.SpeakEventTitle(_winner.Title);
		try
		{
			_winner.Run();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Falha no evento: " + ex));
		}
		_phase = Phase.Announcing;
		_phaseEndsAt = Now + Plugin.CfgResultSeconds.Value;
	}

	private void OnGUI()
	{
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.CfgEnabled.Value)
		{
			return;
		}
		string[] array;
		bool[] array2;
		int[] array3;
		float secondsLeft;
		byte b;
		string winnerLine;
		int winnerIndex;
		if (PhotonNetwork.IsMasterClient)
		{
			if (_phase == Phase.Waiting)
			{
				return;
			}
			array = new string[_ballot.Count];
			array2 = new bool[_ballot.Count];
			array3 = new int[_ballot.Count];
			for (int i = 0; i < _ballot.Count; i++)
			{
				array[i] = _ballot[i].Title;
				array2[i] = _ballot[i].IsGood;
				array3[i] = _votes[i];
			}
			secondsLeft = Mathf.Max(0f, _phaseEndsAt - Now);
			b = (byte)((_phase == Phase.Voting) ? 1 : 2);
			winnerLine = _winnerLine;
			winnerIndex = _winnerIndex;
		}
		else
		{
			Net.MirroredVote mirror = Net.Mirror;
			if (mirror == null || mirror.Phase == 0 || Time.unscaledTime - mirror.ReceivedAt > 3f)
			{
				return;
			}
			array = mirror.Titles;
			array2 = mirror.Good;
			array3 = mirror.Votes;
			b = mirror.Phase;
			winnerLine = mirror.WinnerLine;
			winnerIndex = mirror.WinnerIndex;
			secondsLeft = Mathf.Max(0f, mirror.SecondsLeft - (Time.unscaledTime - mirror.ReceivedAt));
		}
		if (array != null && array.Length != 0)
		{
			float num = Mathf.Clamp(Plugin.CfgPanelWidth.Value, 300f, (float)Screen.width * 0.6f);
			float num2 = 66f * Skin.Scale;
			float num3 = ((b == 1) ? (90f * Skin.Scale + (float)array.Length * num2) : (170f * Skin.Scale));
			float num4 = (Plugin.CfgPanelOnLeft.Value ? 24f : ((float)Screen.width - num - 24f));
			float num5 = Mathf.Clamp(Plugin.CfgPanelTop.Value, 0f, (float)Screen.height - num3 - 20f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(num4, num5, num, num3);
			GUI.Box(val, GUIContent.none, Skin.Panel);
			GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 12f, ((Rect)(ref val)).y + 10f, ((Rect)(ref val)).width - 24f, ((Rect)(ref val)).height - 20f));
			if (b == 1)
			{
				DrawBallot(((Rect)(ref val)).width - 24f, array, array2, array3, secondsLeft);
			}
			else
			{
				DrawResult(array, array2, winnerIndex, winnerLine);
			}
			GUILayout.EndArea();
		}
	}

	private void DrawBallot(float innerWidth, string[] titles, bool[] good, int[] votes, float secondsLeft)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Max(0, Mathf.CeilToInt(secondsLeft));
		float num2 = Mathf.Max(1f, Plugin.CfgVoteSeconds.Value);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(Lang.VoteTitle, Skin.Header, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f * Skin.Scale) });
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		Rect rect = GUILayoutUtility.GetRect(innerWidth, 8f);
		Skin.Fill(rect, Skin.BarBack);
		float num3 = Mathf.Clamp01(secondsLeft / num2);
		if (num3 > 0f)
		{
			Color color = GUI.color;
			GUI.color = ((num <= 10) ? Skin.Bad : Skin.Accent);
			Skin.Fill(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width * num3, ((Rect)(ref rect)).height), Skin.White);
			GUI.color = color;
		}
		GUILayout.Space(4f);
		GUILayout.Label(Lang.TypeNumber + "  " + num + "s", Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(8f);
		int num4 = 0;
		for (int i = 0; i < votes.Length; i++)
		{
			num4 += votes[i];
		}
		for (int j = 0; j < titles.Length; j++)
		{
			int num5 = ((j < votes.Length) ? votes[j] : 0);
			bool flag = j < good.Length && good[j];
			float num6 = ((num4 > 0) ? ((float)num5 / (float)num4) : 0f);
			float num7 = 40f * Skin.Scale;
			Rect rect2 = GUILayoutUtility.GetRect(innerWidth, num7);
			GUI.DrawTexture(rect2, (Texture)(object)(flag ? Skin.RowGood : Skin.RowBad));
			float num8 = 10f * Skin.Scale;
			float num9 = 54f * Skin.Scale;
			float num10 = 34f * Skin.Scale;
			Skin.OutlinedLabel(new Rect(((Rect)(ref rect2)).x + num8, ((Rect)(ref rect2)).y, num10, ((Rect)(ref rect2)).height), j + 1 + ".", Skin.HeaderFlat, Color.white, Mathf.Max(1f, Skin.Scale));
			Skin.OutlinedLabel(new Rect(((Rect)(ref rect2)).x + num8 + num10, ((Rect)(ref rect2)).y, ((Rect)(ref rect2)).width - num8 * 2f - num10 - num9, ((Rect)(ref rect2)).height), titles[j], Skin.HeaderFlat, Color.white, Mathf.Max(1f, Skin.Scale));
			Skin.OutlinedLabel(new Rect(((Rect)(ref rect2)).x + ((Rect)(ref rect2)).width - num8 - num9, ((Rect)(ref rect2)).y, num9, ((Rect)(ref rect2)).height), num5.ToString(), Skin.HeaderRight, Color.white, Mathf.Max(1f, Skin.Scale));
			Rect rect3 = GUILayoutUtility.GetRect(innerWidth, 10f);
			Skin.Fill(rect3, Skin.BarBack);
			if (num6 > 0f)
			{
				Skin.Fill(new Rect(((Rect)(ref rect3)).x, ((Rect)(ref rect3)).y, ((Rect)(ref rect3)).width * num6, ((Rect)(ref rect3)).height), flag ? Skin.BarGood : Skin.BarBad);
			}
			GUILayout.Space(8f);
		}
	}

	private void DrawResult(string[] titles, bool[] good, int winnerIndex, string winnerLine)
	{
		//IL_003e: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label(Lang.ResultTitle, Skin.Header, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f * Skin.Scale) });
		GUILayout.Space(10f);
		if (winnerIndex >= 0 && winnerIndex < titles.Length)
		{
			Color color = GUI.color;
			GUI.color = ((winnerIndex < good.Length && good[winnerIndex]) ? Skin.Good : Skin.Bad);
			GUILayout.Label(titles[winnerIndex], Skin.Option, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUI.color = color;
			GUILayout.Space(6f);
		}
		GUILayout.Label(winnerLine, Skin.Small, (GUILayoutOption[])(object)new GUILayoutOption[0]);
	}
}
public class FloatingItem : MonoBehaviour
{
	private Character _target;

	private Rigidbody _body;

	private Item _item;

	private float _endsAt;

	private float _angle;

	private bool _restored;

	private bool _hadGravity;

	private bool _wasKinematic;

	public static void Attach(GameObject target, Character follow, float seconds)
	{
		if (!((Object)(object)target == (Object)null) && !((Object)(object)follow == (Object)null) && !((Object)(object)target.GetComponent<FloatingItem>() != (Object)null))
		{
			FloatingItem floatingItem = target.AddComponent<FloatingItem>();
			floatingItem._target = follow;
			floatingItem._endsAt = Time.time + seconds;
		}
	}

	private void Start()
	{
		_body = ((Component)this).GetComponent<Rigidbody>();
		_item = ((Component)this).GetComponent<Item>();
		if ((Object)(object)_body != (Object)null)
		{
			_hadGravity = _body.useGravity;
			_wasKinematic = _body.isKinematic;
			_body.useGravity = false;
			_body.isKinematic = true;
		}
		_angle = Random.Range(0f, 360f);
	}

	private void Update()
	{
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		if (!_restored)
		{
			bool flag = Time.time >= _endsAt;
			bool flag2 = (Object)(object)_target == (Object)null || (Object)(object)_target.data == (Object)null || _target.data.dead;
			bool flag3 = (Object)(object)_item != (Object)null && (Object)(object)_item.holderCharacter != (Object)null;
			if (flag || flag2 || flag3)
			{
				Release();
				return;
			}
			_angle += 55f * Time.deltaTime;
			float num = _angle * ((float)Math.PI / 180f);
			Vector3 val = new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * 1.3f;
			float num2 = Mathf.Sin(Time.time * 2f) * 0.15f;
			Vector3 val2 = _target.Center + val + Vector3.up * (0.6f + num2);
			((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, val2, Time.deltaTime * 6f);
			((Component)this).transform.Rotate(Vector3.up, 60f * Time.deltaTime, (Space)0);
		}
	}

	private void Release()
	{
		_restored = true;
		if ((Object)(object)_body != (Object)null)
		{
			_body.isKinematic = _wasKinematic;
			_body.useGravity = _hadGravity;
		}
		Object.Destroy((Object)(object)this);
	}

	private void OnDestroy()
	{
		if (!_restored && (Object)(object)_body != (Object)null)
		{
			_body.isKinematic = _wasKinematic;
			_body.useGravity = _hadGravity;
		}
	}
}
public enum EventKind
{
	SpawnItem,
	SpawnRandom,
	Status,
	Tornado,
	Zombies,
	Cleanse,
	Blizzard,
	RandomItem,
	Horde,
	Sacrifice,
	Nap,
	Scoutmaster,
	TornadoPlayer,
	Humiliate,
	VoiceChaos
}
public class GameEvent
{
	public string Id;

	public string TitlePt;

	public string DescriptionPt;

	public EventKind Kind;

	public bool IsGood;

	public ConfigEntry<bool> Enabled;

	public ConfigEntry<string> ItemName;

	public ConfigEntry<int> Amount;

	public ConfigEntry<float> Intensity;

	public STATUSTYPE Status;

	public string[] Candidates;

	public float LifetimeSeconds;

	public bool ManualOnly;

	public ConfigEntry<bool> Hover;

	public bool NeedsGroup;

	public string Title => Lang.EventTitle(Id, TitlePt);

	public string Description => Lang.EventDescription(Id, DescriptionPt);

	public bool UsesItem => Kind == EventKind.SpawnItem;

	public bool UsesIntensity => Kind == EventKind.Status;

	public bool CanRunNow()
	{
		if (Targeting.Living().Count == 0)
		{
			return false;
		}
		if (Kind == EventKind.Sacrifice)
		{
			if (Targeting.HostIsDead)
			{
				return false;
			}
			if (GameEvents.SacrificeUsed)
			{
				return false;
			}
		}
		if (Kind == EventKind.Humiliate && Lang.English)
		{
			return false;
		}
		if (NeedsGroup && (Plugin.IsSolo || Targeting.Living().Count < 2))
		{
			return false;
		}
		return true;
	}

	public void Run()
	{
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		switch (Kind)
		{
		case EventKind.SpawnItem:
			GameEvents.SpawnItems(ItemName.Value, Amount.Value, Hover != null && Hover.Value, LifetimeSeconds);
			break;
		case EventKind.SpawnRandom:
			GameEvents.SpawnRandomFrom(Title, Candidates, Amount.Value);
			break;
		case EventKind.Status:
			GameEvents.AddStatusToEveryone(Status, Intensity.Value);
			break;
		case EventKind.Tornado:
			GameEvents.SpawnTornado(Amount.Value);
			break;
		case EventKind.Zombies:
			GameEvents.WakeZombiesForEveryone();
			break;
		case EventKind.Cleanse:
			GameEvents.CleanseEveryone();
			break;
		case EventKind.Sacrifice:
			GameEvents.SacrificeOrDie(Intensity.Value);
			break;
		case EventKind.Scoutmaster:
			GameEvents.ReleaseScoutmaster(Intensity.Value);
			break;
		case EventKind.TornadoPlayer:
			GameEvents.TurnSomeoneIntoTornado(Intensity.Value);
			break;
		case EventKind.Humiliate:
			GameEvents.Humiliate(Intensity.Value);
			break;
		case EventKind.Nap:
			GameEvents.NapTime(Intensity.Value);
			break;
		case EventKind.VoiceChaos:
			GameEvents.StartVoiceChaos(Intensity.Value);
			break;
		case EventKind.RandomItem:
			GameEvents.SpawnRandomAnything(Amount.Value);
			break;
		case EventKind.Horde:
			GameEvents.SpawnHorde(Amount.Value);
			break;
		case EventKind.Blizzard:
			GameEvents.StartBlizzard(Intensity.Value);
			GameEvents.AddStatusToEveryone((STATUSTYPE)2, 0.15f);
			break;
		}
	}
}
public static class GameEvents
{
	private const string ZombiePrefab = "MushroomZombie";

	private const float SuspenseVolume = 0.28f;

	public static readonly List<GameEvent> All = new List<GameEvent>();

	private static readonly string[] Healing = new string[11]
	{
		"Bandages", "FirstAidKit", "MedicinalRoot", "Antidote", "Cure-All", "Cure-Some", "HealingPuffShroom", "AloeVera", "Lantern_Faerie", "Heat Pack",
		"Sunscreen"
	};

	private static readonly string[] Food = new string[43]
	{
		"Airplane Food", "Apple Berry Green", "Apple Berry Red", "Apple Berry Yellow", "Berrynana Blue", "Berrynana Brown", "Berrynana Pink", "Berrynana Yellow", "Clusterberry Black", "Clusterberry Red",
		"Clusterberry Yellow", "Kingberry Green", "Kingberry Purple", "Kingberry Yellow", "Winterberry Orange", "Winterberry Yellow", "Shroomberry_Blue", "Shroomberry_Green", "Shroomberry_Purple", "Shroomberry_Red",
		"Shroomberry_Yellow", "Mushroom Chubby", "Mushroom Cluster", "Mushroom Normie", "Mushroom Lace", "Energy Drink", "Sports Drink", "Granola Bar", "Marshmallow", "ScoutCookies",
		"TrailMix", "FortifiedMilk", "Egg", "Item_Honeycomb", "Item_Coconut", "Napberry", "Pepper Berry", "Prickleberry_Gold", "Prickleberry_Red", "Wonderberry",
		"Yuzu Berry", "Glizzy", "FrogLegs"
	};

	private static readonly string[] Climbing = new string[9] { "RopeSpool", "RopeShooter", "ChainShooter", "ClimbingSpike", "RescueHook", "Glider", "Parachute", "Rocketpack", "Jetpack" };

	private static Character _receiverOverride;

	private static readonly List<GameObject> _temporary = new List<GameObject>();

	private static Bounds _originalWindBounds;

	private static bool _windBoundsSaved;

	private static int _sacrificeRun;

	private static Character _sacrificeVictim;

	private static AudioSource _suspenseSource;

	private static int _scoutmasterRun;

	private static readonly Dictionary<string, int> _lastSeen = new Dictionary<string, int>();

	private static int _ballotNumber;

	public static bool SacrificeUsed { get; private set; }

	public static void Build(ConfigFile config)
	{
		All.Clear();
		AddSpawn(config, "dinamite", "Dinamite", "Dinamites caem perto de vocês", "Dynamite", 3);
		AddTornado(config);
		AddZombies(config);
		AddBlizzard(config);
		AddHorde(config);
		AddRandomItem(config);
		AddTornadoPlayer(config);
		AddHumiliate(config);
		AddNap(config);
		AddVoiceChaos(config);
		AddSpawn(config, "reviver", "Reviver um amigo", "Cai uma Scout Effigy, o item que traz alguém de volta", "ScoutEffigy", 1, isGood: true);
		All[All.Count - 1].NeedsGroup = true;
		AddSpawn(config, "bingbong", "Bing Bong!", "Uma chuva de Bing Bongs cai do céu", "BingBong", 20);
		AddSpawn(config, "sapo", "Sapos", "Três sapos aparecem do nada", "Frog", 3, isGood: false, 120f);
		AddSacrifice(config);
		AddScoutmaster(config);
		AddStatus(config, "fome", "Fome", "A fome bate de uma vez só", (STATUSTYPE)1, 0.4f);
		AddCleanse(config);
		AddRandom(config, "cura", "Item de cura", "Um item de cura aleatório cai do céu", Healing, 2);
		AddRandom(config, "comida", "Comida", "Uma comida aleatória para recuperar as forças", Food, 3);
		AddRandom(config, "escalada", "Item de escalada", "Um item de escalada aleatório para ajudar na subida", Climbing, 1);
	}

	private static void AddSpawn(ConfigFile config, string id, string title, string description, string defaultItem, int defaultAmount, bool isGood = false, float lifetimeSeconds = 0f)
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		GameEvent gameEvent = new GameEvent()