Decompiled source of ShopTweaks v1.1.3

BepInEx/plugins/ViViKo.ShopTweaks.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.PropertyVariants;
using UnityEngine.UI;
using UnityEngine.UI.ProceduralImage;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ViViKo.ShopTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("ShopTweaks")]
[assembly: AssemblyFileVersion("1.1.3.0")]
[assembly: AssemblyInformationalVersion("1.1.3")]
[assembly: AssemblyProduct("ShopTweaks")]
[assembly: AssemblyTitle("ViViKo.ShopTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.3.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 ShopTweaks
{
	public class ShopCategories
	{
		internal static List<ShopItemCategory> registerCategories = new List<ShopItemCategory>();

		internal static Dictionary<Keys, string> registerLocales = new Dictionary<Keys, string>();

		internal static void Initialize()
		{
			ShopTweaks.Logger.LogInfo((object)$"Registered {registerCategories.Count} Shop Categories");
		}

		public static ShopItemCategory RegisterCategory(string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			ShopItemCategory val = EnumUtils.Create<ShopItemCategory>(name);
			registerCategories.Add(val);
			Keys key = EnumUtils.Create<Keys>(name);
			registerLocales.Add(key, name);
			return val;
		}
	}
	[ContentWarningPlugin("ViViKo.ShopTweaks", "ShopTweaks", true)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("ViViKo.ShopTweaks", "ShopTweaks", "1.1.3")]
	public class ShopTweaks : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("ViViKo.ShopTweaks");

		public static ShopTweaks Instance;

		public bool DetectedEmoteWheel;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			DetectedEmoteWheel = Chainloader.PluginInfos.Values.ToList().Exists((PluginInfo x) => x.Metadata.GUID.Contains("com.Playboy.EmoteWheel"));
			ShopCategories.Initialize();
			harmony.PatchAll();
			Logger.LogInfo((object)"Plugin ShopTweaks v1.1.3 is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ViViKo.ShopTweaks";

		public const string PLUGIN_NAME = "ShopTweaks";

		public const string PLUGIN_VERSION = "1.1.3";
	}
}
namespace ShopTweaks.Patches
{
	[HarmonyPatch(typeof(LocalizationKeys))]
	public class LocalizationKeysPatch
	{
		[HarmonyPatch("GetLocalizedInternal")]
		[HarmonyPrefix]
		private static bool GetLocalizedInternalPatch(ref string __result, ref Locale locale, ref Keys key)
		{
			if (!ShopCategories.registerLocales.ContainsKey(key))
			{
				return true;
			}
			__result = ShopCategories.registerLocales[key];
			return false;
		}
	}
	[HarmonyPatch(typeof(ShopViewScreen))]
	public class ShopViewScreenPatch
	{
		public static int pageIndex = 0;

		public static int itemsPerPage = 8;

		public static int maxPageIndex = 0;

		public static GameObject leftArrowBtn;

		public static GameObject rightArrowBtn;

		public static GameObject pageNumber;

		public static bool shopClosed = false;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch(ShopViewScreen __instance)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Expected O, but got Unknown
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (!ShopTweaks.Instance.DetectedEmoteWheel)
			{
				Item[] objects = ((DatabaseAsset<ItemDatabase, Item>)(object)SingletonAsset<ItemDatabase>.Instance).Objects;
				foreach (Item val in objects)
				{
					if ((int)val.Category == 5)
					{
						val.Category = (ShopItemCategory)4;
					}
				}
			}
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(0f, 30f, 0f);
			Transform transform = ((TMP_Text)__instance.m_CurrentCategoryNameText).transform;
			transform.localPosition += val2;
			Transform transform2 = ((Component)__instance.m_ItemsGrid).transform;
			transform2.localPosition += val2;
			Transform transform3 = ((Component)__instance.m_CategoriesGrid).transform;
			transform3.localPosition += val2;
			GameObject obj = GameObject.Find("Tools/ShopV2/McScreen/Order/UI_OrderClear");
			TextMeshProUGUI component = GameObject.Find("Tools/ShopV2/McScreen/Order/Items").GetComponent<TextMeshProUGUI>();
			leftArrowBtn = Object.Instantiate<GameObject>(obj);
			Object.Destroy((Object)(object)leftArrowBtn.GetComponentInChildren<ShopInteractibleClear>());
			Object.Destroy((Object)(object)leftArrowBtn.GetComponentInChildren<ProceduralImage>());
			Object.Destroy((Object)(object)leftArrowBtn.GetComponentInChildren<GameObjectLocalizer>());
			TextMeshProUGUI component2 = ((Component)leftArrowBtn.transform.GetChild(1)).gameObject.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component2).font = ((TMP_Text)component).font;
			((TMP_Text)component2).text = "<-";
			((Graphic)component2).color = Color.black;
			leftArrowBtn.transform.SetParent(__instance.m_ItemsGrid.parent.parent);
			leftArrowBtn.transform.localPosition = new Vector3(-8f, -206f, 0f);
			leftArrowBtn.transform.localScale = new Vector3(1f, 1f, 1f);
			leftArrowBtn.AddComponent<ShopInteractiblePageBack>();
			rightArrowBtn = Object.Instantiate<GameObject>(obj);
			Object.Destroy((Object)(object)rightArrowBtn.GetComponentInChildren<ShopInteractibleClear>());
			Object.Destroy((Object)(object)rightArrowBtn.GetComponentInChildren<ProceduralImage>());
			Object.Destroy((Object)(object)rightArrowBtn.GetComponentInChildren<GameObjectLocalizer>());
			TextMeshProUGUI component3 = ((Component)rightArrowBtn.transform.GetChild(1)).gameObject.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component3).font = ((TMP_Text)component).font;
			((TMP_Text)component3).text = "->";
			((Graphic)component3).color = Color.black;
			rightArrowBtn.transform.SetParent(__instance.m_ItemsGrid.parent.parent);
			rightArrowBtn.transform.localPosition = new Vector3(152f, -206f, 0f);
			rightArrowBtn.transform.localScale = new Vector3(1f, 1f, 1f);
			rightArrowBtn.AddComponent<ShopInteractiblePageForward>();
			pageNumber = new GameObject("PageNumber");
			pageNumber.transform.SetParent(__instance.m_ItemsGrid.parent.parent);
			pageNumber.transform.localPosition = new Vector3(72f, -206f, 0f);
			pageNumber.transform.localScale = new Vector3(1f, 1f, 1f);
			TextMeshProUGUI obj2 = pageNumber.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj2).font = ((TMP_Text)component).font;
			((TMP_Text)obj2).fontSize = ((TMP_Text)component).fontSize;
			((Behaviour)obj2).enabled = true;
			((Graphic)obj2).color = ((Graphic)component).color;
			((TMP_Text)obj2).alignment = (TextAlignmentOptions)514;
			ShopTweaks.Logger.LogWarning((object)"Applied ShopTweaks");
		}

		[HarmonyPatch("Init")]
		[HarmonyPrefix]
		private static void InitPatch(ShopViewScreen __instance)
		{
			if (!ShopTweaks.Instance.DetectedEmoteWheel)
			{
				__instance.excludeCategories.Add((ShopItemCategory)5);
			}
		}

		[HarmonyPatch("DrawItems")]
		[HarmonyPrefix]
		private static void DrawItemsPatch(ShopViewScreen __instance)
		{
			maxPageIndex = (int)Math.Ceiling((double)((__instance.CurrentShopItems.Length - 1) / itemsPerPage));
			int count = pageIndex * itemsPerPage;
			__instance.CurrentShopItems = __instance.CurrentShopItems.Skip(count).Take(itemsPerPage).ToArray();
			((TMP_Text)pageNumber.GetComponent<TextMeshProUGUI>()).text = $"{pageIndex + 1}/{maxPageIndex + 1}";
			bool active = maxPageIndex != 0 && !shopClosed;
			leftArrowBtn.SetActive(active);
			rightArrowBtn.SetActive(active);
			pageNumber.SetActive(active);
		}

		[HarmonyPatch("CloseShop")]
		[HarmonyPrefix]
		private static void CloseShopPatch(ShopViewScreen __instance)
		{
			try
			{
				leftArrowBtn.SetActive(false);
				rightArrowBtn.SetActive(false);
				pageNumber.SetActive(false);
			}
			catch (Exception)
			{
			}
			pageIndex = 0;
			maxPageIndex = 0;
			shopClosed = true;
		}

		[HarmonyPatch("OpenShop")]
		[HarmonyPrefix]
		private static void OpenShopPatch()
		{
			try
			{
				leftArrowBtn.SetActive(true);
				rightArrowBtn.SetActive(true);
				pageNumber.SetActive(true);
			}
			catch (Exception)
			{
			}
			pageIndex = 0;
			maxPageIndex = 0;
			shopClosed = false;
		}

		[HarmonyPatch("ChangeCategory")]
		[HarmonyPrefix]
		private static void ChangeCategoryPatch()
		{
			pageIndex = 0;
		}

		[HarmonyPatch("SetIndex")]
		[HarmonyPrefix]
		private static void SetIndexPatch()
		{
			pageIndex = 0;
		}
	}
	public class ShopInteractiblePageBack : Interactable
	{
		private void Start()
		{
			base.hoverText = LocalizationKeys.GetLocalizedString((Keys)33);
		}

		public override void Interact(Player player)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			ShopViewScreenPatch.pageIndex--;
			if (ShopViewScreenPatch.pageIndex < 0)
			{
				ShopViewScreenPatch.pageIndex = ShopViewScreenPatch.maxPageIndex;
			}
			ShopHandler.Instance.clickSFX.Play(((Component)ShopHandler.Instance).transform.position, false, 1f, (Transform)null);
			ShopHandler.Instance.m_ShopView.UpdateViewScreen();
		}
	}
	public class ShopInteractiblePageForward : Interactable
	{
		private void Start()
		{
			base.hoverText = LocalizationKeys.GetLocalizedString((Keys)34);
		}

		public override void Interact(Player player)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			ShopViewScreenPatch.pageIndex++;
			if (ShopViewScreenPatch.pageIndex > ShopViewScreenPatch.maxPageIndex)
			{
				ShopViewScreenPatch.pageIndex = 0;
			}
			ShopHandler.Instance.clickSFX.Play(((Component)ShopHandler.Instance).transform.position, false, 1f, (Transform)null);
			ShopHandler.Instance.m_ShopView.UpdateViewScreen();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}