Decompiled source of ReplayViewer v1.0.0

repviewer.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("repviewer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("repviewer")]
[assembly: AssemblyTitle("repviewer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace repviewer
{
	[HarmonyDebug]
	[BepInPlugin("com.erwer.repviewer", "repviewer", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__OpenReplayViewer;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<string, bool> <>9__27_0;

			public static Func<string, string> <>9__27_1;

			public static UnityAction <>9__29_0;

			internal bool <scan_replays>b__27_0(string x)
			{
				return favorited.Contains(x);
			}

			internal string <scan_replays>b__27_1(string x)
			{
				return x;
			}

			internal void <guistuff>b__29_0()
			{
				Debug.Log((object)$"Favorited : {Host.replaysSaved}, next one is {Host.replaysSaved + 1}");
				favorited.Add($"{Host.replaysSaved + 1}");
			}
		}

		public const string PLUGIN_GUID = "com.erwer.repviewer";

		public const string PLUGIN_NAME = "repviewer";

		public const string PLUGIN_VERSION = "1.0.0";

		private static bool created_warning = false;

		private static bool show_replays = false;

		private static long click_count = 0L;

		private static GameObject warningBox;

		private static GameObject replay_btn;

		private static string[] replays;

		private static GameObject[] buttons_file_replays;

		private static string game_path = Paths.GameRootPath;

		private static readonly string replays_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Replace("Roaming", "LocalLow"), "Johan Gronvall", "BoplBattle", "replays");

		public static string debug_path = Path.Combine(Paths.BepInExRootPath, "plugins", "erwer-repviewer");

		private static string current_replay = "None";

		private static GameObject replaymenu_text;

		private static GameObject replaymenu_screen;

		private static GameObject favorite_replay_btn_gameplay;

		private static TextMeshProUGUI textComp;

		private static RectTransform location;

		public static bool replaymenu_toggled_fast = false;

		public static bool replaymenu_toggled_pause = false;

		private Harmony harmony = new Harmony("com.erwer.repviewer");

		public static List<string> favorited = new List<string>();

		public static string gdpath()
		{
			return debug_path;
		}

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.erwer.repviewer is loaded!");
			((BaseUnityPlugin)this).Logger.LogInfo((object)debug_path);
			harmony.PatchAll(typeof(Patches));
			try
			{
				using StreamReader streamReader = new StreamReader(Path.Combine(gdpath(), "favorited.repview"));
				string text = streamReader.ReadToEnd();
				favorited = text.Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList();
				foreach (string item in favorited)
				{
					Debug.Log((object)item);
				}
			}
			catch (Exception ex)
			{
				Debug.Log((object)(ex?.ToString() + "\n ErrrNoFind"));
			}
			replays = scan_replays();
		}

		private void OnApplicationQuit()
		{
			harmony.UnpatchSelf();
			using StreamWriter streamWriter = new StreamWriter(Path.Combine(gdpath(), "favorited.repview"));
			foreach (string item in favorited)
			{
				streamWriter.WriteLine(item);
			}
		}

		private void Update()
		{
			if (!created_warning)
			{
				guistuff();
			}
		}

		private static string[] scan_replays()
		{
			Debug.Log((object)replays_path);
			string[] files = Directory.GetFiles(replays_path);
			string[] array = files;
			foreach (string path in array)
			{
				Debug.Log((object)Path.GetFileName(path));
			}
			List<string> list = (from x in files
				orderby favorited.Contains(x) descending, x
				select x).ToList();
			return list.ToArray();
		}

		private static GameObject newtx(string name)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			return new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(TextMeshProUGUI)
			});
		}

		private static void guistuff()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Expected O, but got Unknown
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_051e: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0556: Expected O, but got Unknown
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_05da: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0608: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0636: Unknown result type (might be due to invalid IL or missing references)
			//IL_064d: Unknown result type (might be due to invalid IL or missing references)
			//IL_066f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0674: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Expected O, but got Unknown
			//IL_06e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e8: Expected O, but got Unknown
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0714: Unknown result type (might be due to invalid IL or missing references)
			//IL_072b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_0759: Unknown result type (might be due to invalid IL or missing references)
			//IL_0772: Unknown result type (might be due to invalid IL or missing references)
			//IL_0779: Expected O, but got Unknown
			//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0805: Unknown result type (might be due to invalid IL or missing references)
			//IL_081c: Unknown result type (might be due to invalid IL or missing references)
			//IL_088a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0891: Expected O, but got Unknown
			//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0904: Unknown result type (might be due to invalid IL or missing references)
			//IL_0925: Unknown result type (might be due to invalid IL or missing references)
			//IL_0932: Unknown result type (might be due to invalid IL or missing references)
			//IL_0946: Unknown result type (might be due to invalid IL or missing references)
			//IL_095d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0974: Unknown result type (might be due to invalid IL or missing references)
			//IL_098b: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a09: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a2e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a60: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a67: Expected O, but got Unknown
			//IL_0a8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ab5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b2c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b36: Expected O, but got Unknown
			GameObject val = null;
			Canvas val2 = null;
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name.Contains("Level"))
			{
				if ((Object)(object)replaymenu_screen == (Object)null)
				{
					val = GameObject.Find("AbilitySelectCanvas");
					val2 = val.GetComponent<Canvas>();
				}
			}
			else
			{
				Object.Destroy((Object)(object)replaymenu_text);
			}
			Rect val3;
			if ((Object)(object)val != (Object)null && GameLobby.isPlayingAReplay)
			{
				if ((Object)(object)replaymenu_text == (Object)null)
				{
					replaymenu_text = new GameObject("ReplayMenuText", new Type[2]
					{
						typeof(RectTransform),
						typeof(TextMeshProUGUI)
					});
					replaymenu_text.transform.SetParent(((Component)val2).transform);
					textComp = replaymenu_text.GetComponent<TextMeshProUGUI>();
					((Graphic)textComp).raycastTarget = false;
					((TMP_Text)textComp).fontSize = 20f;
					((TMP_Text)textComp).alignment = (TextAlignmentOptions)260;
					((TMP_Text)textComp).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
					location = replaymenu_text.GetComponent<RectTransform>();
					location.pivot = new Vector2(0f, 1f);
					replaymenu_text.SetActive(true);
				}
				else
				{
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.AppendLine("<#FF0000>Viewing Replay " + current_replay + " <#FFFFFF>");
					stringBuilder.AppendLine("<#FFF000>Tilda(~) to leave replay.<#FFFFFF>");
					stringBuilder.AppendLine(replaymenu_toggled_fast ? "<#00FF00>2xSpeed(F1)<#FFFFFF>" : "<#FF0000>2x Speed(F1)<#FFFFFF>");
					stringBuilder.AppendLine(replaymenu_toggled_pause ? "<#00FF00>Pause(F3)<#FFFFFF>" : "<#FF0000>Pause(F3)<#FFFFFF>");
					((TMP_Text)textComp).text = stringBuilder.ToString();
					Rect rect = ((Component)val2).GetComponent<RectTransform>().rect;
					val3 = rect;
					float height = ((Rect)(ref val3)).height;
					rect = ((Component)val2).GetComponent<RectTransform>().rect;
					val3 = rect;
					float width = ((Rect)(ref val3)).width;
					int num = 20;
					location.anchoredPosition = new Vector2(width / 2f - 325f, height / 2f - 100f - (float)num);
				}
				return;
			}
			if (!GameLobby.isPlayingAReplay)
			{
				Object.Destroy((Object)(object)replaymenu_text);
				replaymenu_toggled_pause = false;
				replaymenu_toggled_fast = false;
			}
			if (!GameLobby.isPlayingAReplay && (Object)(object)val != (Object)null)
			{
				activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name.Contains("Level") && (Object)(object)favorite_replay_btn_gameplay == (Object)null)
				{
					GameObject val4 = newtx("Favorite");
					Button val5 = val4.AddComponent<Button>();
					val4.transform.SetParent(((Component)val2).transform);
					textComp = val4.GetComponent<TextMeshProUGUI>();
					((Graphic)textComp).raycastTarget = true;
					((TMP_Text)textComp).fontSize = 20f;
					((TMP_Text)textComp).alignment = (TextAlignmentOptions)260;
					((TMP_Text)textComp).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
					((TMP_Text)textComp).text = "Favorite";
					ColorBlock colors = ((Selectable)val5).colors;
					((ColorBlock)(ref colors)).normalColor = new Color(1f, 1f, 1f, 1f);
					((ColorBlock)(ref colors)).highlightedColor = new Color(0.3f, 0.7f, 1f, 1f);
					((ColorBlock)(ref colors)).pressedColor = new Color(0.1f, 0.5f, 0.8f, 1f);
					((ColorBlock)(ref colors)).disabledColor = new Color(0.5f, 0.5f, 0.5f, 1f);
					((Selectable)val5).colors = colors;
					((Selectable)val5).targetGraphic = (Graphic)(object)textComp;
					location = val4.GetComponent<RectTransform>();
					location.pivot = new Vector2(0f, 1f);
					val4.SetActive(true);
					Rect rect2 = ((Component)val2).GetComponent<RectTransform>().rect;
					val3 = rect2;
					float height2 = ((Rect)(ref val3)).height;
					rect2 = ((Component)val2).GetComponent<RectTransform>().rect;
					val3 = rect2;
					float width2 = ((Rect)(ref val3)).width;
					int num2 = 20;
					location.anchoredPosition = new Vector2(width2 / 2f - 325f, height2 / 2f - 100f - (float)num2);
					ButtonClickedEvent onClick = val5.onClick;
					object obj = <>c.<>9__29_0;
					if (obj == null)
					{
						UnityAction val6 = delegate
						{
							Debug.Log((object)$"Favorited : {Host.replaysSaved}, next one is {Host.replaysSaved + 1}");
							favorited.Add($"{Host.replaysSaved + 1}");
						};
						<>c.<>9__29_0 = val6;
						obj = (object)val6;
					}
					((UnityEvent)onClick).AddListener((UnityAction)obj);
					favorite_replay_btn_gameplay = val4;
					goto IL_04eb;
				}
			}
			activeScene = SceneManager.GetActiveScene();
			if (!((Scene)(ref activeScene)).name.Contains("Level") && (Object)(object)favorite_replay_btn_gameplay != (Object)null)
			{
				Object.Destroy((Object)(object)favorite_replay_btn_gameplay);
			}
			goto IL_04eb;
			IL_04eb:
			val = GameObject.Find("Canvas (1)");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Canvas component = val.GetComponent<Canvas>();
			Rect rect3 = ((Component)component).GetComponent<RectTransform>().rect;
			float height3 = ((Rect)(ref rect3)).height;
			float width3 = ((Rect)(ref rect3)).width;
			if ((Object)(object)replay_btn == (Object)null)
			{
				replay_btn = new GameObject("ReplayButton");
				RectTransform val7 = replay_btn.AddComponent<RectTransform>();
				Button val8 = replay_btn.AddComponent<Button>();
				TextMeshProUGUI val9 = replay_btn.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val9).text = "Open Replay Viewer";
				((Graphic)val9).color = Color.red;
				((TMP_Text)val9).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val9).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
				((TMP_Text)val9).fontSize = width3 / 80f;
				val7.sizeDelta = new Vector2(400f, 75f);
				val7.anchorMin = new Vector2(1f, 1f);
				val7.anchorMax = new Vector2(1f, 1f);
				val7.pivot = new Vector2(1f, 1f);
				val7.anchoredPosition = new Vector2(-20f, -20f);
				((Selectable)val8).targetGraphic = (Graphic)(object)val9;
				((Selectable)val8).colors = ColorBlock.defaultColorBlock;
				ButtonClickedEvent onClick2 = val8.onClick;
				object obj2 = <>O.<0>__OpenReplayViewer;
				if (obj2 == null)
				{
					UnityAction val10 = OpenReplayViewer;
					<>O.<0>__OpenReplayViewer = val10;
					obj2 = (object)val10;
				}
				((UnityEvent)onClick2).AddListener((UnityAction)obj2);
				((Transform)val7).SetParent(((Component)component).transform, false);
				replay_btn.SetActive(true);
			}
			if (!show_replays)
			{
				return;
			}
			buttons_file_replays = (GameObject[])(object)new GameObject[replays.Length];
			if ((Object)(object)GameObject.Find("scroller_replays") == (Object)null)
			{
				GameObject val11 = new GameObject("scroller_content");
				RectTransform val12 = val11.AddComponent<RectTransform>();
				val12.sizeDelta = new Vector2(400f, 75f);
				val12.anchorMin = new Vector2(1f, 1f);
				val12.anchorMax = new Vector2(1f, 1f);
				val12.pivot = new Vector2(1f, 1f);
				val12.anchoredPosition = new Vector2(-20f, -20f);
				val11.SetActive(true);
				GameObject val13 = new GameObject("scroller_replays");
				RectTransform val14 = val13.AddComponent<RectTransform>();
				ScrollRect val15 = val13.AddComponent<ScrollRect>();
				val15.horizontal = false;
				val15.vertical = true;
				val15.scrollSensitivity = 20f;
				val15.content = val12;
				val14.sizeDelta = new Vector2(400f, 75f);
				val14.anchorMin = new Vector2(1f, 1f);
				val14.anchorMax = new Vector2(1f, 1f);
				val14.pivot = new Vector2(1f, 1f);
				val14.anchoredPosition = new Vector2(-20f, -20f);
				((Transform)val14).SetParent(((Component)component).transform, false);
				val13.SetActive(true);
				((Transform)val12).SetParent(val13.transform, false);
			}
			for (int i = 0; i < replays.Length; i++)
			{
				string path = replays[i];
				string rep = Path.GetFileNameWithoutExtension(path);
				GameObject val16 = new GameObject(rep + "_btn_load");
				RectTransform val17 = val16.AddComponent<RectTransform>();
				Button val18 = val16.AddComponent<Button>();
				ColorBlock colors2 = ((Selectable)val18).colors;
				((ColorBlock)(ref colors2)).normalColor = new Color(1f, 1f, 1f, 1f);
				((ColorBlock)(ref colors2)).highlightedColor = new Color(0.3f, 0.7f, 1f, 1f);
				((ColorBlock)(ref colors2)).pressedColor = new Color(0.1f, 0.5f, 0.8f, 1f);
				((ColorBlock)(ref colors2)).disabledColor = new Color(0.5f, 0.5f, 0.5f, 1f);
				((Selectable)val18).colors = colors2;
				val17.sizeDelta = new Vector2(550f, 75f);
				val17.anchorMin = new Vector2(1f, 0.9f);
				val17.anchorMax = new Vector2(1f, 0.9f);
				val17.pivot = new Vector2(1f, 1f);
				val17.anchoredPosition = new Vector2(-20f, -85f * (float)i - 75f);
				TextMeshProUGUI val19 = val16.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val19).text = rep;
				if (favorited.Contains(rep))
				{
					((Graphic)val19).color = new Color(1f, 0.5f, 0f);
				}
				else
				{
					((Graphic)val19).color = Color.black;
				}
				((TMP_Text)val19).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val19).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
				((TMP_Text)val19).fontSize = width3 / 80f;
				GameObject val20 = new GameObject(rep + "_bg");
				RectTransform val21 = val20.AddComponent<RectTransform>();
				Image val22 = val20.AddComponent<Image>();
				((Graphic)val22).color = new Color(0.8f, 0.8f, 0.8f, 0.5f);
				val21.sizeDelta = new Vector2(550f, 90f);
				val21.anchorMin = val17.anchorMin;
				val21.anchorMax = val17.anchorMax;
				val21.pivot = val17.pivot;
				val21.anchoredPosition = new Vector2(0f, 0f);
				((Transform)val21).SetParent(((Component)val17).transform, false);
				((Transform)val17).SetParent(GameObject.Find("scroller_content").transform, false);
				((UnityEvent)val18.onClick).AddListener((UnityAction)delegate
				{
					run_replay(rep);
				});
				buttons_file_replays[i] = val16;
			}
			show_replays = false;
		}

		private static void OpenReplayViewer()
		{
			if (buttons_file_replays != null && buttons_file_replays.Length != 0)
			{
				GameObject[] array = buttons_file_replays;
				foreach (GameObject val in array)
				{
					Object.Destroy((Object)(object)val);
				}
			}
			click_count++;
			if (click_count % 2 == 0)
			{
				Debug.Log((object)"Replay Viewer Closed");
				replays = scan_replays();
			}
			else
			{
				Debug.Log((object)"Replay Viewer Opened");
				show_replays = true;
			}
		}

		private void Dispose()
		{
			Object.Destroy((Object)(object)replay_btn);
			created_warning = false;
		}

		private static void run_replay(string replayName)
		{
			//IL_0083: 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_00c1: 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)
			//IL_00b2: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			Host.recordReplay = false;
			Host.replayPath = Path.Combine(replays_path, replayName + ".rep");
			Debug.Log((object)("Loading replay from: " + Host.replayPath));
			Host component = GameObject.Find("networkClient").GetComponent<Host>();
			current_replay = replayName;
			if (File.Exists(Host.replayPath))
			{
				string replayPath = Host.replayPath;
				if (replayPath != null)
				{
					StartRequestPacket val = default(StartRequestPacket);
					component.replay = NetworkTools.ReadCompressedReplay(File.ReadAllBytes(replayPath), ref val);
					SteamManager.startParameters = val;
					GameLobby.isPlayingAReplay = true;
					component.clients = new List<Client>();
					for (int i = 0; i < val.nrOfPlayers - 1; i++)
					{
						component.clients.Add(new Client(1, new SteamConnection()));
					}
					float num = duration_of_replay(File.ReadAllBytes(replayPath));
					Debug.Log((object)("Raw Duration : " + num));
					Debug.Log((object)("Second Guess Duration : " + Math.Round(num / 79f)));
				}
				SceneManager.LoadScene("Replay");
				GameLobby.isPlayingAReplay = true;
			}
			else
			{
				Debug.LogError((object)("Replay file does not exist: " + Host.replayPath));
			}
		}

		public static float duration_of_replay(byte[] compressedReplay)
		{
			StartRequestPacket val = default(StartRequestPacket);
			List<InputPacketQuad> list = new List<InputPacketQuad>(NetworkTools.ReadCompressedReplay(compressedReplay, ref val));
			return list.Count;
		}
	}
	public class Patches
	{
		[HarmonyPatch(typeof(CharacterSelectHandler_online), "Awake")]
		private static void Prefix(CharacterSelectBox __instance)
		{
			CharacterSelectHandler_online.clientSideMods_you_can_increment_this_to_enable_matchmaking_for_your_mods__please_dont_use_it_to_cheat_thats_really_cringe_especially_if_its_desyncing_others___you_didnt_even_win_on_your_opponents_screen___I_cannot_imagine_a_sadder_existence += 2;
		}

		[HarmonyPatch(typeof(Host), "PlayReplayUpdate")]
		[HarmonyPrefix]
		public static bool PlayReplayUpdate(Host __instance)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			if (((ButtonControl)Keyboard.current.backquoteKey).wasPressedThisFrame)
			{
				__instance.clients.Clear();
				GameLobby.isPlayingAReplay = false;
				Host.replayPath = "";
				Debug.Log((object)"A client was disconnected, abandoning lobby");
				GameSessionHandler.LeaveGame(true, false);
				Host.recordReplay = true;
				Host.replayLevelsLoaded++;
			}
			__instance.timePassed += Time.deltaTime;
			double num = (double)Updater.SimulationTicks * (double)GameTime.FixedTimeStep;
			double num2 = Mathf.Max((float)((double)__instance.timePassed - num) / (float)GameTime.FixedTimeStep, 0f);
			num2 = ((num2 > 4.0) ? 4.0 : num2);
			if (((ButtonControl)Keyboard.current.f1Key).wasPressedThisFrame)
			{
				Plugin.replaymenu_toggled_fast = !Plugin.replaymenu_toggled_fast;
			}
			else if (((ButtonControl)Keyboard.current.f3Key).wasPressedThisFrame)
			{
				Plugin.replaymenu_toggled_pause = !Plugin.replaymenu_toggled_pause;
			}
			if (Plugin.replaymenu_toggled_pause)
			{
				num2 = 0.0;
				__instance.timePassed = (float)(num + (double)GameTime.FixedTimeStep * num2);
			}
			else if (Plugin.replaymenu_toggled_fast)
			{
				num2 = 2.0;
				__instance.timePassed = (float)(num + (double)GameTime.FixedTimeStep * num2);
			}
			for (int i = 0; (double)i < num2; i++)
			{
				InputPacketQuad val = (InputPacketQuad)((__instance.replay.Count <= 0) ? default(InputPacketQuad) : __instance.replay.Dequeue());
				Player player = PlayerHandler.Get().GetPlayer(1);
				Player player2 = PlayerHandler.Get().GetPlayer(2);
				Player player3 = PlayerHandler.Get().GetPlayer(3);
				Player player4 = PlayerHandler.Get().GetPlayer(4);
				if (GameTime.IsTimeStopped())
				{
					if (player != null && player.isProtectedFromTimeStop)
					{
						player.OverrideInputWithNetworkInput(val.p1);
					}
					if (player2 != null && player2.isProtectedFromTimeStop)
					{
						player2.OverrideInputWithNetworkInput(val.p2);
					}
					if (player3 != null && player3.isProtectedFromTimeStop)
					{
						player3.OverrideInputWithNetworkInput(val.p3);
					}
					if (player4 != null && player4.isProtectedFromTimeStop)
					{
						player4.OverrideInputWithNetworkInput(val.p4);
					}
				}
				else
				{
					if (player != null)
					{
						player.OverrideInputWithNetworkInput(val.p1);
					}
					if (player2 != null)
					{
						player2.OverrideInputWithNetworkInput(val.p2);
					}
					if (player3 != null)
					{
						player3.OverrideInputWithNetworkInput(val.p3);
					}
					if (player4 != null)
					{
						player4.OverrideInputWithNetworkInput(val.p4);
					}
				}
				Updater.TickSimulation(GameTime.FixedTimeStep);
				if (Updater.LoadedALevelThisUpdate)
				{
					Updater.LoadedALevelThisUpdate = false;
					break;
				}
			}
			return false;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "repviewer";

		public const string PLUGIN_NAME = "repviewer";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}