Decompiled source of ReplayViewer v0.2.0

repviewer.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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;
		}

		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");

		private static GameObject replaymenu_text;

		private static GameObject replaymenu_screen;

		private static TextMeshProUGUI textComp;

		private static RectTransform location;

		public static bool replaymenu_toggled_fast = false;

		public static bool replaymenu_toggled_pause = false;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.erwer.repviewer is loaded!");
			Harmony val = new Harmony("com.erwer.repviewer");
			val.PatchAll(typeof(Patches));
			replays = scan_replays();
		}

		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 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_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: 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_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Expected O, but got Unknown
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Expected O, but got Unknown
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Expected O, but got Unknown
			//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_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: 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_0517: Unknown result type (might be due to invalid IL or missing references)
			//IL_052b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_0559: Unknown result type (might be due to invalid IL or missing references)
			//IL_0570: Unknown result type (might be due to invalid IL or missing references)
			//IL_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b6: 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_060c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0613: Expected O, but got Unknown
			//IL_063b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0652: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: Unknown result type (might be due to invalid IL or missing references)
			//IL_067f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0696: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06da: Expected O, but got Unknown
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: 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_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: 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_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			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);
			}
			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 = 25f;
					((TMP_Text)textComp).alignment = (TextAlignmentOptions)514;
					((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.Append("<#FF0000>Viewing Replay...<#FFFFFF>");
					stringBuilder.Append(" ");
					stringBuilder.Append("<#FFF000>Tilda(~) to leave replay.<#FFFFFF>");
					stringBuilder.Append(" ");
					stringBuilder.Append(replaymenu_toggled_fast ? "<#00FF00>2xSpeed(F1)<#FFFFFF>" : "<#FF0000>2x Speed(F1)<#FFFFFF>");
					stringBuilder.Append(" ");
					stringBuilder.Append(replaymenu_toggled_pause ? "<#00FF00>Pause(F3)<#FFFFFF>" : "<#FF0000>Pause(F3)<#FFFFFF>");
					((TMP_Text)textComp).text = stringBuilder.ToString();
					Rect rect = ((Component)val2).GetComponent<RectTransform>().rect;
					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 = 3;
					location.anchoredPosition = new Vector2(width / 2f - 325f, height / 2f - 100f - (float)num);
				}
				return;
			}
			val = GameObject.Find("Canvas (1)");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Canvas component = val.GetComponent<Canvas>();
			Rect rect2 = ((Component)component).GetComponent<RectTransform>().rect;
			float height2 = ((Rect)(ref rect2)).height;
			float width2 = ((Rect)(ref rect2)).width;
			if ((Object)(object)replay_btn == (Object)null)
			{
				replay_btn = new GameObject("ReplayButton");
				RectTransform val4 = replay_btn.AddComponent<RectTransform>();
				Button val5 = replay_btn.AddComponent<Button>();
				TextMeshProUGUI val6 = replay_btn.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val6).text = "Open Replay Viewer";
				((Graphic)val6).color = Color.red;
				((TMP_Text)val6).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val6).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
				((TMP_Text)val6).fontSize = width2 / 80f;
				val4.sizeDelta = new Vector2(400f, 75f);
				val4.anchorMin = new Vector2(1f, 1f);
				val4.anchorMax = new Vector2(1f, 1f);
				val4.pivot = new Vector2(1f, 1f);
				val4.anchoredPosition = new Vector2(-20f, -20f);
				((Selectable)val5).targetGraphic = (Graphic)(object)val6;
				((Selectable)val5).colors = ColorBlock.defaultColorBlock;
				ButtonClickedEvent onClick = val5.onClick;
				object obj = <>O.<0>__OpenReplayViewer;
				if (obj == null)
				{
					UnityAction val7 = OpenReplayViewer;
					<>O.<0>__OpenReplayViewer = val7;
					obj = (object)val7;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj);
				((Transform)val4).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.GetFileName(path);
				GameObject val8 = new GameObject(rep + "_btn_load");
				RectTransform val9 = val8.AddComponent<RectTransform>();
				Button val10 = val8.AddComponent<Button>();
				ColorBlock colors = ((Selectable)val10).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)val10).colors = colors;
				val9.sizeDelta = new Vector2(550f, 75f);
				val9.anchorMin = new Vector2(1f, 0.9f);
				val9.anchorMax = new Vector2(1f, 0.9f);
				val9.pivot = new Vector2(1f, 1f);
				val9.anchoredPosition = new Vector2(-20f, -75f * (float)i - 75f);
				TextMeshProUGUI val11 = val8.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val11).text = rep;
				((Graphic)val11).color = Color.black;
				((TMP_Text)val11).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val11).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
				((TMP_Text)val11).fontSize = width2 / 80f;
				GameObject val12 = new GameObject(rep + "_bg");
				RectTransform val13 = val12.AddComponent<RectTransform>();
				Image val14 = val12.AddComponent<Image>();
				((Graphic)val14).color = new Color(0.8f, 0.8f, 0.8f, 0.5f);
				val13.sizeDelta = new Vector2(550f, 90f);
				val13.anchorMin = val9.anchorMin;
				val13.anchorMax = val9.anchorMax;
				val13.pivot = val9.pivot;
				val13.anchoredPosition = new Vector2(0f, 0f);
				((Transform)val13).SetParent(((Component)val9).transform, false);
				((Transform)val9).SetParent(((Component)component).transform, false);
				((UnityEvent)val10.onClick).AddListener((UnityAction)delegate
				{
					run_replay(rep);
				});
				buttons_file_replays[i] = val8;
			}
			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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_0099: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			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()));
					}
				}
				SceneManager.LoadScene("Replay");
				GameLobby.isPlayingAReplay = true;
			}
			else
			{
				Debug.LogError((object)("Replay file does not exist: " + Host.replayPath));
			}
		}
	}
	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++;
		}

		[HarmonyPatch(typeof(Host), "PlayReplayUpdate")]
		[HarmonyPrefix]
		public static bool PlayReplayUpdate(Host __instance)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: 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_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: 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_0217: 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_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			if (((ButtonControl)Keyboard.current.backquoteKey).wasPressedThisFrame)
			{
				__instance.clients.Clear();
				Debug.Log((object)"A client was disconnected, abandoning lobby");
				GameSessionHandler.LeaveGame(true, false);
			}
			__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;
				}
			}
			if (__instance.clients.Count > 0)
			{
				__instance.renderDebugText(false);
			}
			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";
	}
}