Decompiled source of ReplayViewer v0.3.1

repviewer.dll

Decompiled 2 months 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 UnityAction <>9__28_0;

			internal void <guistuff>b__28_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", "Unknown-repviewer");

		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));
			}
			return files;
		}

		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_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Expected O, but got Unknown
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Expected O, but got Unknown
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_059e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_0627: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Expected O, but got Unknown
			//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Expected O, but got Unknown
			//IL_0707: Unknown result type (might be due to invalid IL or missing references)
			//IL_070c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0724: Unknown result type (might be due to invalid IL or missing references)
			//IL_0745: Unknown result type (might be due to invalid IL or missing references)
			//IL_0766: Unknown result type (might be due to invalid IL or missing references)
			//IL_0787: Unknown result type (might be due to invalid IL or missing references)
			//IL_0794: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_080e: Unknown result type (might be due to invalid IL or missing references)
			//IL_086b: Unknown result type (might be due to invalid IL or missing references)
			//IL_085a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0890: 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_08c9: Expected O, but got Unknown
			//IL_08f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0908: Unknown result type (might be due to invalid IL or missing references)
			//IL_0917: Unknown result type (might be due to invalid IL or missing references)
			//IL_0926: Unknown result type (might be due to invalid IL or missing references)
			//IL_0935: Unknown result type (might be due to invalid IL or missing references)
			//IL_094c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0986: Unknown result type (might be due to invalid IL or missing references)
			//IL_0990: 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...<#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__28_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__28_0 = val6;
						obj = (object)val6;
					}
					((UnityEvent)onClick).AddListener((UnityAction)obj);
					favorite_replay_btn_gameplay = val4;
					goto IL_04dc;
				}
			}
			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_04dc;
			IL_04dc:
			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];
			for (int i = 0; i < replays.Length; i++)
			{
				string path = replays[i];
				string rep = Path.GetFileNameWithoutExtension(path);
				GameObject val11 = new GameObject(rep + "_btn_load");
				RectTransform val12 = val11.AddComponent<RectTransform>();
				Button val13 = val11.AddComponent<Button>();
				ColorBlock colors2 = ((Selectable)val13).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)val13).colors = colors2;
				val12.sizeDelta = new Vector2(550f, 75f);
				val12.anchorMin = new Vector2(1f, 0.9f);
				val12.anchorMax = new Vector2(1f, 0.9f);
				val12.pivot = new Vector2(1f, 1f);
				val12.anchoredPosition = new Vector2(-20f, -85f * (float)i - 75f);
				TextMeshProUGUI val14 = val11.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val14).text = rep;
				if (favorited.Contains(rep))
				{
					((Graphic)val14).color = new Color(1f, 0.5f, 0f);
				}
				else
				{
					((Graphic)val14).color = Color.black;
				}
				((TMP_Text)val14).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val14).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
				((TMP_Text)val14).fontSize = width3 / 80f;
				GameObject val15 = new GameObject(rep + "_bg");
				RectTransform val16 = val15.AddComponent<RectTransform>();
				Image val17 = val15.AddComponent<Image>();
				((Graphic)val17).color = new Color(0.8f, 0.8f, 0.8f, 0.5f);
				val16.sizeDelta = new Vector2(550f, 90f);
				val16.anchorMin = val12.anchorMin;
				val16.anchorMax = val12.anchorMax;
				val16.pivot = val12.pivot;
				val16.anchoredPosition = new Vector2(0f, 0f);
				((Transform)val16).SetParent(((Component)val12).transform, false);
				((Transform)val12).SetParent(((Component)component).transform, false);
				((UnityEvent)val13.onClick).AddListener((UnityAction)delegate
				{
					run_replay(rep);
				});
				buttons_file_replays[i] = val11;
			}
			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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00a2: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			Host.recordReplay = false;
			Host.replayPath = Path.Combine(replays_path, replayName);
			Debug.Log((object)("Loading replay from: " + Host.replayPath));
			Host component = GameObject.Find("networkClient").GetComponent<Host>();
			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;
				}
			}
			__instance.renderDebugText(true);
			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";
	}
}