Decompiled source of HoldToPause v1.0.1

HoldToPause.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LLBML.Players;
using LLBML.States;
using LLBML.Utils;
using LLGUI;
using LLHandlers;
using LLScreen;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
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: AssemblyCompany("HoldToPause")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+cbc2a5fe607b1e0f8e42ef3ad5adc77e75221f34")]
[assembly: AssemblyProduct("HoldToPause")]
[assembly: AssemblyTitle("HoldToPause")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 HoldToPause
{
	[BepInPlugin("avgduck.plugins.llb.holdtopause", "HoldToPause", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "avgduck.plugins.llb.holdtopause";

		private static Vector2[] pauseIndicatorPositions = (Vector2[])(object)new Vector2[3]
		{
			Vector2.zero,
			new Vector2(-616f, -334f),
			new Vector2(616f, -334f)
		};

		private float[] pauseTimers;

		private bool pauseAllowed;

		private int pausePlayer;

		private Sprite spritePauseProgress;

		private Image imgPauseProgress;

		private Sprite spritePauseIcon;

		private Image imgPauseIcon;

		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource LogGlobal { get; private set; }

		internal static ConfigEntry<int> PauseHoldTime { get; private set; }

		internal static ConfigEntry<int> PauseDisplayMode { get; private set; }

		private void Awake()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_018d: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			LogGlobal = ((BaseUnityPlugin)this).Logger;
			PauseHoldTime = ((BaseUnityPlugin)Instance).Config.Bind<int>("Settings", "PauseHoldTime", 1000, "The amount of time a player needs to hold the pause button to pause the game, in milliseconds (1000ms = 1s). Must be greater than 0");
			PauseDisplayMode = ((BaseUnityPlugin)Instance).Config.Bind<int>("Settings", "PauseDisplayMode", 1, new ConfigDescription("Display mode for the pause progress indicator. 1 = off, 2 = bottom left, 3 = bottom right", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, pauseIndicatorPositions.Length - 1), new object[0]));
			ModDependenciesUtils.RegisterToModMenu(((BaseUnityPlugin)Instance).Info, new List<string>(3) { "Forces the pause button to be held down to prevent accidental pausing in tournament settings.", "Pause hold time is specified in milliseconds (1000ms = 1s) and must be greater than 0.", "Pause display mode: 0 = off, 1 = bottom left, 2 = bottom right" });
			pausePlayer = -1;
			pauseTimers = new float[4];
			Harmony val = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			spritePauseProgress = Sprite.Create(CreateCircleTexture(Color.white, new Color(0.08f, 0.08f, 0.08f), 256, 256, 128, 128, 96, 128, 4), new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f));
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "assets"));
			FileInfo fileInfo = directoryInfo.GetFiles().First();
			byte[] array = File.ReadAllBytes(fileInfo.FullName);
			Texture2D val2 = new Texture2D(122, 132);
			ImageConversion.LoadImage(val2, array);
			spritePauseIcon = Sprite.Create(val2, new Rect(0f, 0f, 122f, 132f), new Vector2(0.5f, 0.5f));
		}

		private static Texture2D CreateCircleTexture(Color mainColor, Color borderColor, int width, int height, int centerX, int centerY, int innerRadius, int outerRadius, int borderWidth)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_008d: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(width, height);
			float num = innerRadius * innerRadius;
			float num2 = (innerRadius + borderWidth) * (innerRadius + borderWidth);
			float num3 = outerRadius * outerRadius;
			float num4 = (outerRadius - borderWidth) * (outerRadius - borderWidth);
			for (int i = centerX - outerRadius; i <= centerX + outerRadius; i++)
			{
				for (int j = centerY - outerRadius; j <= centerY + outerRadius; j++)
				{
					float num5 = (centerX - i) * (centerX - i) + (centerY - j) * (centerY - j);
					if ((num5 > num && num5 < num2) || (num5 > num4 && num5 < num3))
					{
						val.SetPixel(i, j, borderColor);
					}
					else if (num5 > num2 && num5 < num4)
					{
						val.SetPixel(i, j, mainColor);
					}
					else
					{
						val.SetPixel(i, j, Color.clear);
					}
				}
			}
			val.Apply();
			return val;
		}

		private void ResetPauseTimers()
		{
			for (int i = 0; i < 4; i++)
			{
				pauseTimers[i] = 0f;
			}
		}

		private static string PrintArray<T>(T[] arr)
		{
			string text = "[";
			for (int i = 0; i < arr.Length; i++)
			{
				if (i != 0)
				{
					text += ", ";
				}
				text += arr[i].ToString();
			}
			return text + "]";
		}

		[HarmonyPatch(typeof(ScreenGameHud), "OnOpen")]
		[HarmonyPostfix]
		private static void ScreenGameHud_OnOpen_Postfix(ScreenGameHud __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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)
			Instance.ResetPauseTimers();
			Instance.imgPauseProgress = new GameObject("imgPauseProgress").AddComponent<Image>();
			Instance.imgPauseProgress.sprite = Instance.spritePauseProgress;
			((Graphic)Instance.imgPauseProgress).color = new Color(1f, 1f, 1f, 1f);
			Instance.imgPauseProgress.type = (Type)3;
			Instance.imgPauseProgress.fillMethod = (FillMethod)4;
			Instance.imgPauseProgress.fillClockwise = true;
			Instance.imgPauseProgress.fillOrigin = 2;
			((Transform)((Graphic)Instance.imgPauseProgress).rectTransform).SetParent(((Component)__instance).transform, false);
			((Transform)((Graphic)Instance.imgPauseProgress).rectTransform).localPosition = Vector2.op_Implicit(pauseIndicatorPositions[PauseDisplayMode.Value]);
			((Transform)((Graphic)Instance.imgPauseProgress).rectTransform).localScale = Vector2.op_Implicit(new Vector2(0.3f, 0.3f));
			Instance.imgPauseIcon = new GameObject("imgPauseIcon").AddComponent<Image>();
			Instance.imgPauseIcon.sprite = Instance.spritePauseIcon;
			((Graphic)Instance.imgPauseIcon).color = new Color(1f, 1f, 1f, 1f);
			((Transform)((Graphic)Instance.imgPauseIcon).rectTransform).SetParent((Transform)(object)((Graphic)Instance.imgPauseProgress).rectTransform, false);
			((Transform)((Graphic)Instance.imgPauseIcon).rectTransform).localPosition = Vector2.op_Implicit(new Vector2(0f, 0f));
			((Transform)((Graphic)Instance.imgPauseIcon).rectTransform).localScale = Vector2.op_Implicit(new Vector2(0.5f, 0.5f));
			Instance.imgPauseProgress.fillAmount = 0f;
			((Behaviour)Instance.imgPauseIcon).enabled = false;
		}

		[HarmonyPatch(typeof(OGONAGCFDPK), "UpdateState")]
		[HarmonyPrefix]
		private static void GameStatesGame_UpdateState_Prefix(OGONAGCFDPK __instance)
		{
			Instance.pauseAllowed = __instance.pauseAllowed;
		}

		[HarmonyPatch(typeof(ScreenGameHud), "DoUpdate")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> ScreenGameHud_DoUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, il);
			val.End();
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[10]
			{
				new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldflda, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldsfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_M1, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Br, (object)null, (string)null)
			});
			val.Advance(1);
			val.RemoveInstructions(9);
			val.Insert((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Action<ALDOKEMAOMB>>((Action<ALDOKEMAOMB>)delegate(ALDOKEMAOMB p)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				Player val2 = Player.op_Implicit(p);
				if (Instance.pauseAllowed)
				{
					Controller controller = val2.controller;
					if (((Controller)(ref controller)).GetButton(InputAction.PAUSE))
					{
						Instance.pauseTimers[val2.nr] += Time.deltaTime;
						return;
					}
				}
				Instance.pauseTimers[val2.nr] = 0f;
			}) });
			return val.InstructionEnumeration();
		}

		[HarmonyPatch(typeof(ScreenGameHud), "DoUpdate")]
		[HarmonyPostfix]
		private static void ScreenGameHud_DoUpdate_Postfix()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if (!Instance.pauseAllowed)
			{
				return;
			}
			bool flag = false;
			int num = -1;
			float num2 = 0f;
			for (int i = 0; i < 4; i++)
			{
				if (Instance.pauseTimers[i] >= (float)PauseHoldTime.Value / 1000f)
				{
					Instance.pausePlayer = i;
					flag = true;
				}
				if (Instance.pauseTimers[i] > num2)
				{
					num = i;
					num2 = Instance.pauseTimers[i];
				}
			}
			((Transform)((Graphic)Instance.imgPauseProgress).rectTransform).localPosition = Vector2.op_Implicit(pauseIndicatorPositions[PauseDisplayMode.Value]);
			if (Instance.pausePlayer == -1 && num2 > 0f && PauseDisplayMode.Value != 0)
			{
				Instance.imgPauseProgress.fillAmount = num2 / ((float)PauseHoldTime.Value / 1000f);
				((Behaviour)Instance.imgPauseIcon).enabled = true;
			}
			else
			{
				Instance.imgPauseProgress.fillAmount = 0f;
				((Behaviour)Instance.imgPauseIcon).enabled = false;
			}
			if (flag)
			{
				Instance.ResetPauseTimers();
				GameStates.Send((Msg)102, Instance.pausePlayer, -1);
			}
		}

		[HarmonyPatch(typeof(ScreenGamePause), "OnOpen")]
		[HarmonyPostfix]
		private static void ScreenGamePause_OnOpen_Postfix(ScreenGamePause __instance)
		{
			//IL_0045: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text component = ((Component)Object.Instantiate<LLButton>(__instance.btResume, ((Component)__instance).transform)).GetComponent<TMP_Text>();
			((Object)((Component)component).gameObject).name = "lbPausePlayer";
			Object.Destroy((Object)(object)((Component)component).GetComponent<LLButton>());
			component.transform.localPosition = Vector2.op_Implicit(new Vector2(0f, 310f));
			component.transform.localScale = Vector2.op_Implicit(new Vector2(1f, 1f));
			((Graphic)component).color = Color.white;
			component.fontSize = 28f;
			TextHandler.SetText(component, (Instance.pausePlayer != -1) ? $"P{Instance.pausePlayer + 1} pause" : "");
			Instance.pausePlayer = -1;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "HoldToPause";

		public const string PLUGIN_NAME = "HoldToPause";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}