Decompiled source of StageSelect v1.0.0

BepInEx/plugins/StageSelect/com.github.daioutzu.stageselect.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("com.github.daioutzu.stageselect")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StageSelect")]
[assembly: AssemblyTitle("com.github.daioutzu.stageselect")]
[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 StageSelect
{
	[BepInPlugin("com.github.daioutzu.stageselect", "StageSelect", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private Harmony harmony = new Harmony("com.github.daioutzu.stageselect");

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin com.github.daioutzu.stageselect is loaded!");
			harmony.PatchAll();
		}
	}
	[HarmonyPatch]
	internal class ScreenPlayersStage_Patch
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ControlDelegate <>9__16_1;

			public static ControlDelegate <>9__16_3;

			public static ControlDelegate <>9__16_6;

			public static ControlDelegate <>9__16_8;

			internal void <ReorganiseStageButtons>b__16_1(int playerNr)
			{
				foreach (LLButton item in stageButtons3D)
				{
					((Component)item).gameObject.SetActive(true);
				}
				foreach (LLButton item2 in stageButtons2D)
				{
					((Component)item2).gameObject.SetActive(false);
				}
			}

			internal void <ReorganiseStageButtons>b__16_3(int playerNr)
			{
				foreach (LLButton item in stageButtons3D)
				{
					((Component)item).gameObject.SetActive(false);
				}
				foreach (LLButton item2 in stageButtons2D)
				{
					((Component)item2).gameObject.SetActive(true);
				}
			}

			internal void <ReorganiseStageButtons>b__16_6(int playerNr)
			{
				TextHandler.SetText(lbStageName, "");
				TextHandler.SetText(lbStageSize, "");
			}

			internal void <ReorganiseStageButtons>b__16_8(int playerNr)
			{
				TextHandler.SetText(lbStageName, "");
			}
		}

		private static List<LLButton> stageButtons3D = new List<LLButton>(10);

		private static List<LLButton> stageButtons2D = new List<LLButton>(7);

		private static LLButton[] stageButtonsRND = (LLButton[])(object)new LLButton[2];

		private static TMP_Text lbStageName;

		private static TMP_Text lbStageSize;

		private const float SCALE_FACTOR = 0.415f;

		private const float SPACING = 5f;

		private const float SIZE_X = 207.5f;

		private const float SIZE_Y = 103.75f;

		private const float RND_START_POS_X = -531f;

		private const float START_POS_X = -318.5f;

		private const float START_POS_Y = 89f;

		private static string GetStageSize(Stage stage)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected I4, but got Unknown
			switch (stage - 3)
			{
			case 0:
			case 1:
				return "1240, 510";
			case 2:
				return "1130, 510";
			case 3:
				return "1492, 522";
			case 4:
				return "1400, 542";
			case 5:
				return "1050, 510";
			case 6:
				return "1230, 540";
			case 7:
				return "1320, 515";
			case 8:
				return "1210, 575";
			case 9:
				return "1100, 550";
			default:
				return "";
			}
		}

		private static string UnlockStageText(Stage stage)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected I4, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int num2 = 0;
			switch (stage - 20)
			{
			case 4:
				num = 500;
				num2 = 70;
				break;
			case 6:
				num = 670;
				num2 = 90;
				break;
			case 2:
				num = 840;
				num2 = 110;
				break;
			case 3:
				num = 1010;
				num2 = 130;
				break;
			case 5:
				num = 1180;
				num2 = 150;
				break;
			case 1:
				num = 1350;
				num2 = 170;
				break;
			case 0:
				num = 1520;
				num2 = 190;
				break;
			default:
				return TextHandler.Get($"STAGE_{stage}", new string[0]);
			}
			return TextHandler.Get("MAIN_TXT_MATCHES", new string[1] { num.ToString() }) + " || " + TextHandler.Get("MAIN_TXT_LEVEL", new string[1] { num2.ToString() });
		}

		[HarmonyPatch(typeof(ScreenPlayersStage), "OnOpen")]
		[HarmonyPostfix]
		private static void OnOpen_Postfix(ScreenPlayersStage __instance)
		{
			for (int i = 0; i < __instance.stageButtonsContainer.childCount; i++)
			{
				Object.Destroy((Object)(object)((Component)__instance.stageButtonsContainer.GetChild(i)).gameObject);
			}
			ReorganiseStageButtons(__instance);
			((LLControl)__instance.btRight).visible = false;
			((LLControl)__instance.btLeft).visible = false;
		}

		private static TMP_Text MakeNewTextFromlbTitle(TMP_Text copyThis, Transform parentTf, Vector3 position)
		{
			//IL_0013: 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)
			TMP_Text obj = Object.Instantiate<TMP_Text>(copyThis, parentTf);
			obj.SetText("");
			((Graphic)obj).color = Color.white;
			obj.fontSize = 32f;
			obj.transform.localPosition = position;
			return obj;
		}

		private static void ReorganiseStageButtons(ScreenPlayersStage instance)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_01c3: Expected O, but got Unknown
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: 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_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Expected O, but got Unknown
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Expected O, but got Unknown
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Expected O, but got Unknown
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Expected O, but got Unknown
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Expected I4, but got Unknown
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Invalid comparison between Unknown and I4
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Expected O, but got Unknown
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Invalid comparison between Unknown and I4
			//IL_0522: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			//IL_0536: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Expected O, but got Unknown
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Expected O, but got Unknown
			//IL_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Invalid comparison between Unknown and I4
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Expected O, but got Unknown
			stageButtons3D.Clear();
			stageButtons2D.Clear();
			float num = -531f;
			float num2 = 89f;
			lbStageName = MakeNewTextFromlbTitle(instance.lbTitle, instance.lbTitle.transform.parent, new Vector3(0f, -360f));
			((Object)lbStageName).name = "lbStageName";
			lbStageSize = MakeNewTextFromlbTitle(instance.lbTitle, instance.lbTitle.transform.parent, new Vector3(0f, -355f));
			((Object)lbStageSize).name = "lbStageSize";
			lbStageSize.alignment = (TextAlignmentOptions)516;
			lbStageSize.fontSize = 24f;
			RectTransform component = ((Component)lbStageSize).gameObject.GetComponent<RectTransform>();
			component.sizeDelta = Vector2.one;
			component.anchorMax = new Vector2(0.99f, 1f);
			List<Stage> list = new List<Stage>();
			list.AddRange(StageHandler.stagesAll);
			instance.nButtons = list.Count + 2;
			instance.btStages = (LLButton[])(object)new LLButton[instance.nButtons];
			Sprite val = JPLELOFJOOH.BNFIDCAPPDK("_spritePreviewRandom");
			LLButton val2 = LLButton.CreateImageButton(instance.stageButtonsContainer, val, new Color(0.6f, 0.6f, 0.6f, 1f), Color.white);
			((LLClickable)val2).SetActive(true);
			((Object)val2).name = ((Object)val2).name + "_" + -1;
			((LLClickable)val2).onClick = (ControlDelegate)delegate(int playerNr)
			{
				instance.SelectStage(playerNr, -1);
			};
			LLButton obj = val2;
			object obj2 = <>c.<>9__16_1;
			if (obj2 == null)
			{
				ControlDelegate val3 = delegate
				{
					foreach (LLButton item in stageButtons3D)
					{
						((Component)item).gameObject.SetActive(true);
					}
					foreach (LLButton item2 in stageButtons2D)
					{
						((Component)item2).gameObject.SetActive(false);
					}
				};
				<>c.<>9__16_1 = val3;
				obj2 = (object)val3;
			}
			((LLClickable)obj).onHover = (ControlDelegate)obj2;
			RectTransform component2 = ((Component)val2).GetComponent<RectTransform>();
			component2.anchoredPosition = new Vector2(num, num2);
			((Transform)component2).localScale = 0.415f * Vector3.one;
			num2 -= 108.75f;
			instance.btStages[0] = val2;
			stageButtonsRND[0] = val2;
			val = Resources.Load<Sprite>("Textures/_spritePreviewRandom_2d");
			val2 = LLButton.CreateImageButton(instance.stageButtonsContainer, val, new Color(0.6f, 0.6f, 0.6f, 1f), Color.white);
			((LLClickable)val2).SetActive(true);
			((Object)val2).name = ((Object)val2).name + "_" + -2;
			((LLClickable)val2).onClick = (ControlDelegate)delegate(int playerNr)
			{
				instance.SelectStage(playerNr, -2);
			};
			LLButton obj3 = val2;
			object obj4 = <>c.<>9__16_3;
			if (obj4 == null)
			{
				ControlDelegate val4 = delegate
				{
					foreach (LLButton item3 in stageButtons3D)
					{
						((Component)item3).gameObject.SetActive(false);
					}
					foreach (LLButton item4 in stageButtons2D)
					{
						((Component)item4).gameObject.SetActive(true);
					}
				};
				<>c.<>9__16_3 = val4;
				obj4 = (object)val4;
			}
			((LLClickable)obj3).onHover = (ControlDelegate)obj4;
			RectTransform component3 = ((Component)val2).GetComponent<RectTransform>();
			component3.anchoredPosition = new Vector2(num, num2);
			((Transform)component3).localScale = 0.415f * Vector3.one;
			instance.btStages[1] = val2;
			stageButtonsRND[1] = val2;
			num = -318.5f;
			num2 = 89f;
			int num3 = 0;
			for (int i = 0; i < list.Count; i++)
			{
				num3++;
				Stage val5 = list[i];
				val = JPLELOFJOOH.BNFIDCAPPDK("_spritePreview" + ((object)(Stage)(ref val5)).ToString());
				LLButton val6 = LLButton.CreateImageButton(instance.stageButtonsContainer, val, new Color(0.6f, 0.6f, 0.6f, 1f), Color.white);
				((LLClickable)val6).SetActive(true);
				if (EPCDKLCABNC.KFFJOEAJLEH(list[i]))
				{
					Stage stage = list[i];
					int stage_selection2 = (int)stage;
					object obj5;
					if ((int)list[i] == 23)
					{
						obj5 = "MENTAL_2D";
					}
					else if ((int)list[i] == 25)
					{
						obj5 = "TRAIN_2D";
					}
					else
					{
						val5 = list[i];
						obj5 = ((object)(Stage)(ref val5)).ToString();
					}
					string stageName = (string)obj5;
					((Object)val6).name = ((Object)val6).name + "_" + stage_selection2;
					((LLClickable)val6).onClick = (ControlDelegate)delegate(int playerNr)
					{
						instance.SelectStage(playerNr, stage_selection2);
					};
					((LLClickable)val6).onHover = (ControlDelegate)delegate
					{
						//IL_0020: Unknown result type (might be due to invalid IL or missing references)
						TextHandler.SetTextCode(lbStageName, "STAGE_" + stageName);
						TextHandler.SetText(lbStageSize, GetStageSize(stage));
					};
					object obj6 = <>c.<>9__16_6;
					if (obj6 == null)
					{
						ControlDelegate val7 = delegate
						{
							TextHandler.SetText(lbStageName, "");
							TextHandler.SetText(lbStageSize, "");
						};
						<>c.<>9__16_6 = val7;
						obj6 = (object)val7;
					}
					((LLClickable)val6).onHoverOut = (ControlDelegate)obj6;
				}
				else
				{
					Stage stage_selection = list[i];
					val = JPLELOFJOOH.BNFIDCAPPDK("_spritePreviewLOCKED");
					((LLClickable)LLButton.CreateImageButton(((Component)val6).transform, val, new Color(0.6f, 0.6f, 0.6f, 1f), Color.white)).SetActive(false);
					((LLClickable)val6).onHover = (ControlDelegate)delegate
					{
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						TextHandler.SetText(lbStageName, UnlockStageText(stage_selection));
					};
					object obj7 = <>c.<>9__16_8;
					if (obj7 == null)
					{
						ControlDelegate val8 = delegate
						{
							TextHandler.SetText(lbStageName, "");
						};
						<>c.<>9__16_8 = val8;
						obj7 = (object)val8;
					}
					((LLClickable)val6).onHoverOut = (ControlDelegate)obj7;
				}
				RectTransform component4 = ((Component)val6).GetComponent<RectTransform>();
				component4.anchoredPosition = new Vector2(num, num2);
				((Transform)component4).localScale = 0.415f * Vector3.one;
				if (num3 >= 5)
				{
					num2 = (((int)list[i] != 12) ? (num2 - 108.75f) : 89f);
					num = -318.5f;
					num3 = 0;
				}
				else
				{
					num += 212.5f;
				}
				int num4 = i + 2;
				if (i <= 9)
				{
					stageButtons3D.Add(val6);
				}
				else
				{
					stageButtons2D.Add(val6);
					((Component)val6).gameObject.SetActive(false);
				}
				instance.btStages[num4] = val6;
			}
			instance.curIndex = 0;
		}

		private static void Move(int d, ScreenPlayersStage inst, bool vert = false)
		{
			bool flag = inst.curIndex >= 14 && inst.curIndex <= 16;
			bool num = inst.curIndex >= 2 && inst.curIndex <= 11;
			int curIndex = inst.curIndex;
			curIndex += d;
			int num2 = (num ? Mathf.Clamp(curIndex, 2, 11) : Mathf.Clamp(curIndex, 12, 18));
			if (num)
			{
				if (vert)
				{
					if (curIndex > num2)
					{
						curIndex -= 10;
					}
					else if (curIndex < num2)
					{
						curIndex += 10;
					}
				}
			}
			else if (vert)
			{
				if (flag)
				{
					curIndex = 18;
				}
				else if (curIndex > num2)
				{
					curIndex -= 10;
				}
				else if (curIndex < num2)
				{
					curIndex += 10;
					if (curIndex > 18)
					{
						curIndex = inst.nButtons - 1;
					}
				}
			}
			inst.curIndex = curIndex;
			UIScreen.SetFocus((LLClickable)(object)inst.GetButton(inst.curIndex));
		}

		[HarmonyPatch(typeof(ScreenPlayersStage), "GetControls")]
		[HarmonyPrefix]
		private static bool GetControls(ref List<LLClickable> list, bool vert, LLClickable curFocus, LLCursor cursor, ScreenPlayersStage __instance)
		{
			if ((Object)(object)curFocus == (Object)null)
			{
				int num = ((__instance.curIndex >= 12) ? 1 : 0);
				list.Add((LLClickable)(object)stageButtonsRND[num]);
				__instance.curIndex = num;
			}
			if (vert)
			{
				if ((Object)(object)curFocus != (Object)(object)stageButtonsRND[0])
				{
					list.Add((LLClickable)(object)stageButtonsRND[0]);
					__instance.curIndex = 0;
				}
				else
				{
					list.Add((LLClickable)(object)stageButtonsRND[1]);
					__instance.curIndex = 1;
				}
			}
			else if (((Object)(object)curFocus != (Object)(object)stageButtonsRND[0] && (__instance.curIndex == 2 || __instance.curIndex == 6)) || __instance.curIndex == 12 || __instance.curIndex == 16)
			{
				list.Add((LLClickable)(object)stageButtonsRND[0]);
				__instance.curIndex = 0;
			}
			else
			{
				list.Add((LLClickable)(object)stageButtonsRND[1]);
				__instance.curIndex = 1;
			}
			return false;
		}

		[HarmonyPatch(typeof(ScreenPlayersStage), "DirectMove")]
		[HarmonyPrefix]
		private static bool DirectMove(ref Vector2 move, LLClickable curFocus, bool shouldMove, ScreenPlayersStage __instance, ref bool __result)
		{
			bool flag = (Object)(object)curFocus == (Object)null;
			bool flag2 = (Object)(object)curFocus == (Object)(object)stageButtonsRND[0] || (Object)(object)curFocus == (Object)(object)stageButtonsRND[1];
			bool flag3 = (__instance.curIndex == 2 && move.x < 0f) || (__instance.curIndex == 6 && move.x > 0f) || (__instance.curIndex == 12 && move.x < 0f) || (__instance.curIndex == 16 && move.x > 0f);
			bool flag4 = (__instance.curIndex == 7 && move.x < 0f) || (__instance.curIndex == 11 && move.x > 0f) || (__instance.curIndex == 17 && move.x < 0f) || (__instance.curIndex == 18 && move.x > 0f);
			if (!shouldMove || flag3 || flag4 || (flag2 && move.y != 0f) || flag)
			{
				__result = false;
				return false;
			}
			if ((Object)(object)curFocus == (Object)(object)stageButtonsRND[0] && move.y == 0f)
			{
				__instance.curIndex = ((move.x > 0f) ? 2 : 6);
				Move(0, __instance);
				__result = true;
				return false;
			}
			if ((Object)(object)curFocus == (Object)(object)stageButtonsRND[1] && move.y == 0f)
			{
				__instance.curIndex = ((move.x > 0f) ? 17 : 18);
				Move(0, __instance);
				__result = true;
				return false;
			}
			if (move.x < 0f)
			{
				Move(-1, __instance);
			}
			else if (move.x > 0f)
			{
				Move(1, __instance);
			}
			else if (move.y < 0f)
			{
				Move(5, __instance, vert: true);
			}
			else
			{
				Move(-5, __instance, vert: true);
			}
			__result = true;
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.daioutzu.stageselect";

		public const string PLUGIN_NAME = "StageSelect";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}