Decompiled source of OnlineGameTweak v1.0.1

OnlineGameTweak.dll

Decompiled 3 weeks ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("OnlineGameTweak")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fa9a23e22eb0f6f7dd0c2981c5c1765c0a69d27f")]
[assembly: AssemblyProduct("OnlineGameTweak")]
[assembly: AssemblyTitle("OnlineGameTweak")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace OnlineGameTweak
{
	public class Configuration
	{
		public static ConfigEntry<bool> Enabled { get; private set; }

		public static ConfigEntry<bool> ShowPing { get; private set; }

		public static void Init(ConfigFile config)
		{
			Enabled = config.Bind<bool>("General", "Enabled", true, "Enable this mod.");
			ShowPing = config.Bind<bool>("General", "ShowPing", true, "Show real-time ping in game.");
		}
	}
	[BepInPlugin("Kaguya.Repo.OnlineGameTweak", "OnlineGameTweak", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		public static Plugin Instance;

		private const string Name = "OnlineGameTweak";

		private const string Guid = "Kaguya.Repo.OnlineGameTweak";

		private const string Version = "1.0.1";

		public static GameObject TextInstance;

		public static TextMeshProUGUI ValueText;

		public static bool IsPublic;

		private void Awake()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = Logger.CreateLogSource("OnlineGameTweak");
			Configuration.Init(((BaseUnityPlugin)this).Config);
			new Harmony("Kaguya.Repo.OnlineGameTweak").PatchAll();
			Logger.LogInfo((object)"PublicGameContinueSave has loaded. Version 1.0.1");
		}
	}
}
namespace OnlineGameTweak.Patches
{
	[HarmonyPatch(typeof(MenuPageServerListCreateNew), "ButtonConfirm")]
	internal class MenuPageServerListCreateNewPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(ref MenuPageServerListCreateNew __instance)
		{
			if (Configuration.Enabled.Value)
			{
				Plugin.IsPublic = true;
				DataDirector.instance.networkServerName = __instance.menuTextInput.textCurrent;
				SemiFunc.MainMenuSetMultiplayer();
				MenuManager.instance.PageCloseAll();
				MenuManager.instance.PageOpen((MenuPageIndex)11, false);
				Plugin.Logger.LogInfo((object)"ButtonConfirm intercepted.");
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar), "Update")]
	internal class PlayerAvatarPatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (Configuration.ShowPing.Value && SemiFunc.RunIsLevel())
			{
				if ((Object)(object)Plugin.TextInstance == (Object)null)
				{
					GameObject val = GameObject.Find("Game Hud");
					TMP_FontAsset font = GameObject.Find("Tax Haul").GetComponent<TMP_Text>().font;
					Plugin.TextInstance = new GameObject();
					Plugin.TextInstance.SetActive(false);
					((Object)Plugin.TextInstance).name = "Ping HUD";
					Plugin.TextInstance.AddComponent<TextMeshProUGUI>();
					Plugin.ValueText = Plugin.TextInstance.GetComponent<TextMeshProUGUI>();
					((TMP_Text)Plugin.ValueText).font = font;
					((Graphic)Plugin.ValueText).color = Color.cyan;
					((TMP_Text)Plugin.ValueText).fontSize = 24f;
					((TMP_Text)Plugin.ValueText).enableWordWrapping = false;
					((TMP_Text)Plugin.ValueText).alignment = (TextAlignmentOptions)2052;
					((TMP_Text)Plugin.ValueText).horizontalAlignment = (HorizontalAlignmentOptions)4;
					((TMP_Text)Plugin.ValueText).verticalAlignment = (VerticalAlignmentOptions)2048;
					Plugin.TextInstance.transform.SetParent(val.transform, false);
					SetCoordinates(Plugin.TextInstance.GetComponent<RectTransform>());
				}
				else if ((Object)(object)Plugin.ValueText != (Object)null)
				{
					int ping = PhotonNetwork.GetPing();
					SetCoordinates(Plugin.TextInstance.GetComponent<RectTransform>());
					((TMP_Text)Plugin.ValueText).SetText($"Ping {ping}", true);
					Plugin.TextInstance.SetActive(true);
				}
			}
		}

		private static void SetCoordinates(RectTransform component)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			component.pivot = new Vector2(1f, 1f);
			component.anchoredPosition = new Vector2(1f, -1f);
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 0f);
			component.sizeDelta = new Vector2(0f, 0f);
			component.offsetMax = new Vector2(0f, 225f);
			component.offsetMin = new Vector2(0f, 225f);
		}
	}
	[HarmonyPatch(typeof(SemiFunc), "MenuActionHostGame")]
	internal class SemiFuncPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(ref string saveFileName, ref List<string> saveFileBackups)
		{
			if (Configuration.Enabled.Value)
			{
				if (!Plugin.IsPublic)
				{
					Plugin.Logger.LogInfo((object)"Ignore for private game.");
					return true;
				}
				RunManager.instance.ResetProgress();
				if (saveFileName != null)
				{
					Plugin.Logger.LogInfo((object)("Loading " + saveFileName));
					SemiFunc.SaveFileLoad(saveFileName, saveFileBackups);
				}
				else
				{
					Plugin.Logger.LogInfo((object)"New match");
					SemiFunc.SaveFileCreate();
				}
				GameManager.instance.localTest = false;
				RunManager.instance.waitToChangeScene = true;
				RunManager.instance.ChangeLevel(true, false, (ChangeLevelType)3);
				GameManager.instance.SetConnectRandom(true);
				RunManager.instance.lobbyJoin = true;
				return false;
			}
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}