Decompiled source of Speedrun Tweaks v1.0.2

SpeedRunTweaks.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: AssemblyFileVersion("1.0.2")]
[assembly: Guid("E0E2F92E-557C-4A05-9D89-AA92A0BD75C4")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyProduct("SpeedrunTweaks")]
[assembly: AssemblyCompany("warpalicious")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("SpeedrunTweaks")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace SpeedRunTweaks
{
	public class GUI_Patch
	{
		[HarmonyPatch(typeof(FejdStartup), "OnWorldNew")]
		public static class FejdStartup_OnWorldNew_Patch
		{
			public static void Postfix(FejdStartup __instance)
			{
				GameObject gameObject = ((Component)__instance.m_createWorldPanel.transform.GetChild(0)).gameObject;
				GameObject gameObject2 = ((Component)gameObject.transform.GetChild(3)).gameObject;
				GameObject gameObject3 = ((Component)gameObject2.transform.GetChild(0)).gameObject;
				GameObject gameObject4 = ((Component)gameObject3.transform.GetChild(2)).gameObject;
				TextMeshProUGUI component = gameObject4.GetComponent<TextMeshProUGUI>();
				((TMP_Text)component).fontSize = 0f;
			}
		}

		[HarmonyPatch(typeof(FejdStartup), "UpdateWorldList")]
		public static class FejdStartup_UpdateWorldList_Patch
		{
			public static void Postfix(FejdStartup __instance)
			{
				RectTransform worldListRoot = __instance.m_worldListRoot;
				for (int i = 0; i < ((Transform)worldListRoot).childCount; i++)
				{
					GameObject gameObject = ((Component)((Transform)worldListRoot).GetChild(i)).gameObject;
					GameObject gameObject2 = ((Component)gameObject.transform.GetChild(4)).gameObject;
					gameObject2.SetActive(false);
				}
			}
		}
	}
	[BepInPlugin("warpalicious.SpeedrunTweaks", "SpeedrunTweaks", "1.0.2")]
	public class SpeedRunTweaksPlugin : BaseUnityPlugin
	{
		internal const string ModName = "SpeedrunTweaks";

		internal const string ModVersion = "1.0.2";

		internal const string Author = "warpalicious";

		private const string ModGUID = "warpalicious.SpeedrunTweaks";

		private static string ConfigFileName = "warpalicious.SpeedrunTweaks.cfg";

		private static string ConfigFileFullPath;

		internal static string ConnectionError;

		private readonly Harmony _harmony = new Harmony("warpalicious.SpeedrunTweaks");

		public static readonly ManualLogSource SpeedRunTweaksLogger;

		public void Awake()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		static SpeedRunTweaksPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			ConnectionError = "";
			SpeedRunTweaksLogger = Logger.CreateLogSource("SpeedrunTweaks");
		}
	}
	public class Terminal_Patch
	{
		[HarmonyPatch(typeof(Terminal), "InitTerminal")]
		public static class Terminal_InitTerminal_Patch
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static ConsoleEventFailable <>9__0_0;

				internal object <Postfix>b__0_0(ConsoleEventArgs args)
				{
					//IL_0055: Unknown result type (might be due to invalid IL or missing references)
					//IL_005c: Expected O, but got Unknown
					//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
					if ((Object)(object)Player.m_localPlayer == (Object)null)
					{
						return false;
					}
					double num = Math.Min(20f, args.TryParameterFloat(1, 5f));
					Object[] array = Object.FindObjectsOfType(typeof(DungeonGenerator));
					Object[] array2 = array;
					for (int i = 0; i < array2.Length; i++)
					{
						DungeonGenerator val = (DungeonGenerator)array2[i];
						args.Context.AddString(string.Format("  {0}: Seed: {1}/{2}, Distance: {3}", ((Object)val).name, val.m_generatedSeed, val.GetSeed(), Utils.DistanceXZ(((Component)Player.m_localPlayer).transform.position, ((Component)val).transform.position).ToString("0.0")));
					}
					return true;
				}
			}

			public static void Postfix(Terminal __instance)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				Dictionary<string, ConsoleCommand> commands = Terminal.commands;
				object obj = <>c.<>9__0_0;
				if (obj == null)
				{
					ConsoleEventFailable val = delegate(ConsoleEventArgs args)
					{
						//IL_0055: Unknown result type (might be due to invalid IL or missing references)
						//IL_005c: Expected O, but got Unknown
						//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
						//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
						if ((Object)(object)Player.m_localPlayer == (Object)null)
						{
							return false;
						}
						double num = Math.Min(20f, args.TryParameterFloat(1, 5f));
						Object[] array = Object.FindObjectsOfType(typeof(DungeonGenerator));
						Object[] array2 = array;
						for (int i = 0; i < array2.Length; i++)
						{
							DungeonGenerator val2 = (DungeonGenerator)array2[i];
							args.Context.AddString(string.Format("  {0}: Seed: {1}/{2}, Distance: {3}", ((Object)val2).name, val2.m_generatedSeed, val2.GetSeed(), Utils.DistanceXZ(((Component)Player.m_localPlayer).transform.position, ((Component)val2).transform.position).ToString("0.0")));
						}
						return true;
					};
					<>c.<>9__0_0 = val;
					obj = (object)val;
				}
				commands["printseeds"] = new ConsoleCommand("printseeds", "print seeds of loaded dungeons without seed values", (ConsoleEventFailable)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
	public static class RegisterAndCheckVersion
	{
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			SpeedRunTweaksPlugin.SpeedRunTweaksLogger.LogDebug((object)"Registering version RPC handler");
			peer.m_rpc.Register<ZPackage>("SpeedrunTweaks_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_SpeedRunTweaks_Version);
			SpeedRunTweaksPlugin.SpeedRunTweaksLogger.LogDebug((object)"Invoking version check");
			ZPackage val = new ZPackage();
			val.Write("1.0.2");
			peer.m_rpc.Invoke("SpeedrunTweaks_VersionCheck", new object[1] { val });
		}
	}
	[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
	public static class VerifyClient
	{
		private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance)
		{
			if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc))
			{
				return true;
			}
			SpeedRunTweaksPlugin.SpeedRunTweaksLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting"));
			rpc.Invoke("Error", new object[1] { 3 });
			return false;
		}

		private static void Postfix(ZNet __instance)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "SpeedrunTweaksRequestAdminSync", new object[1] { (object)new ZPackage() });
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "ShowConnectError")]
	public class ShowConnectionError
	{
		private static void Postfix(FejdStartup __instance)
		{
			if (__instance.m_connectionFailedPanel.activeSelf)
			{
				__instance.m_connectionFailedError.fontSizeMax = 25f;
				__instance.m_connectionFailedError.fontSizeMin = 15f;
				TMP_Text connectionFailedError = __instance.m_connectionFailedError;
				connectionFailedError.text = connectionFailedError.text + "\n" + SpeedRunTweaksPlugin.ConnectionError;
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "Disconnect")]
	public static class RemoveDisconnectedPeerFromVerified
	{
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			if (__instance.IsServer())
			{
				SpeedRunTweaksPlugin.SpeedRunTweaksLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list"));
				RpcHandlers.ValidatedPeers.Remove(peer.m_rpc);
			}
		}
	}
	public static class RpcHandlers
	{
		public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>();

		public static void RPC_SpeedRunTweaks_Version(ZRpc rpc, ZPackage pkg)
		{
			string text = pkg.ReadString();
			SpeedRunTweaksPlugin.SpeedRunTweaksLogger.LogInfo((object)("Version check, local: 1.0.2,  remote: " + text));
			if (text != "1.0.2")
			{
				SpeedRunTweaksPlugin.ConnectionError = "SpeedrunTweaks Installed: 1.0.2\n Needed: " + text;
				if (ZNet.instance.IsServer())
				{
					SpeedRunTweaksPlugin.SpeedRunTweaksLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting..."));
					rpc.Invoke("Error", new object[1] { 3 });
				}
			}
			else if (!ZNet.instance.IsServer())
			{
				SpeedRunTweaksPlugin.SpeedRunTweaksLogger.LogInfo((object)"Received same version from server!");
			}
			else
			{
				SpeedRunTweaksPlugin.SpeedRunTweaksLogger.LogInfo((object)("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list"));
				ValidatedPeers.Add(rpc);
			}
		}
	}
}