Decompiled source of ShowMaxStackforItem v1.0.0

BepInEx/plugins/ShowMaxStackforItem.DysonSphereProgram.Desperationfighter/ShowMaxStackforItem.dll

Decompiled 4 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ShowMaxStackforItem")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Desperationfighter")]
[assembly: AssemblyProduct("ShowMaxStackforItem")]
[assembly: AssemblyCopyright("Copyright ©  2024 Desperationfighter")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3c144831-255a-4024-b300-1ce2ce7f98e1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ShowMaxStackforItem
{
	[BepInPlugin("Desperationfighter.DysonSphereProgram.ShowMaxStackforItem", "Show Max Stack for Item", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "Desperationfighter.DysonSphereProgram.ShowMaxStackforItem";

		public const string Name = "Show Max Stack for Item";

		public const string Version = "1.0.0";

		public static ConfigEntry<int> Modus;

		public static ConfigEntry<int> Modus_1_Setting;

		public static ConfigEntry<int> Modus_2_Setting;

		public static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Modus = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Modus", 2, "(Game restart recommend to apply changes) Change Modus: 1. Show Max Stack Size in Item Name, 2. Show Max Stack Size as Item Description, 3. Show Both");
			Modus_1_Setting = ((BaseUnityPlugin)this).Config.Bind<int>("Modus 1 Settings", "Modus1Setting", 2, "Change Config: 1. Show as (Stack Size: 100), 2. Show as (Stack: 100), 3. Show as (100)");
			Modus_2_Setting = ((BaseUnityPlugin)this).Config.Bind<int>("Modus 2 Settings", "Modus1Setting", 1, "Change Config: 1. Show Stack Size on Start of list, 2. Show Stack Size on End of list");
			if ((Modus.Value <= 0) | (Modus.Value >= 4))
			{
				Modus.Value = 2;
			}
			if ((Modus_1_Setting.Value <= 0) | (Modus_1_Setting.Value >= 4))
			{
				Modus_1_Setting.Value = 2;
			}
			if ((Modus_2_Setting.Value <= 0) | (Modus_2_Setting.Value >= 3))
			{
				Modus_2_Setting.Value = 1;
			}
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Desperationfighter.DysonSphereProgram.ShowMaxStackforItem");
			Logger.LogInfo((object)"Plugin Desperationfighter.DysonSphereProgram.ShowMaxStackforItem is loaded!");
		}
	}
}
namespace ShowMaxStackforItem.Patches
{
	[HarmonyPatch(typeof(UIItemTip))]
	[HarmonyPatch("SetTip")]
	public static class UIItemTip_SetTip_Patch
	{
		private static bool debuglogging;

		private static bool deeplogging;

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Expected O, but got Unknown
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Expected O, but got Unknown
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Expected O, but got Unknown
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Expected O, but got Unknown
			string text = "UIItemTip_SetTip_Patch";
			if (debuglogging && !deeplogging)
			{
				Plugin.Logger.LogDebug((object)"Deeploging deactivated");
			}
			if (debuglogging)
			{
				Plugin.Logger.LogDebug((object)("Start Transpiler - " + text));
			}
			bool flag = false;
			int num = -1;
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			if (debuglogging && deeplogging)
			{
				Plugin.Logger.LogDebug((object)"Deep Logging pre-transpiler:");
				for (int i = 0; i < list.Count; i++)
				{
					Plugin.Logger.LogDebug((object)($"0x{i:X4}" + " : " + list[i].opcode.ToString() + "\t" + ((list[i].operand != null) ? list[i].operand.ToString() : "")));
				}
			}
			if (debuglogging)
			{
				Plugin.Logger.LogDebug((object)"Start code analyses");
			}
			for (int j = 0; j < list.Count; j++)
			{
				if (list[j].opcode == OpCodes.Cgt && list[j + 2].opcode == OpCodes.Ceq && list[j + 3].opcode == OpCodes.Dup && list[j - 2].opcode == OpCodes.Add)
				{
					if (debuglogging)
					{
						Plugin.Logger.LogDebug((object)"Found IL Code Line for Index");
						Plugin.Logger.LogDebug((object)("Index = " + num));
					}
					flag = true;
					num = j;
					break;
				}
			}
			if (debuglogging)
			{
				if (flag)
				{
					Plugin.Logger.LogDebug((object)"found true");
				}
				else
				{
					Plugin.Logger.LogDebug((object)"found false");
				}
			}
			if (num > -1)
			{
				if (debuglogging)
				{
					Plugin.Logger.LogDebug((object)"Index1 > -1");
				}
				Plugin.Logger.LogInfo((object)("Transpiler injectection position found for - " + text));
				if (Plugin.Modus.Value != 1)
				{
					Plugin.Logger.LogDebug((object)"Adding New Line to UI of ToolTip");
					int num2 = 4;
					LocalBuilder localBuilder = list[num - 4].operand as LocalBuilder;
					list.Insert(num - num2, new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder));
					list.Insert(num - num2, new CodeInstruction(OpCodes.Add, (object)null));
					list.Insert(num - num2, new CodeInstruction(OpCodes.Ldc_I4_1, (object)null));
					list.Insert(num - num2, new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder));
				}
			}
			else
			{
				Plugin.Logger.LogError((object)"Index was not found");
			}
			if (debuglogging && deeplogging)
			{
				Plugin.Logger.LogDebug((object)"Deep Logging after-transpiler:");
				for (int k = 0; k < list.Count; k++)
				{
					Plugin.Logger.LogDebug((object)($"0x{k:X4}" + " : " + list[k].opcode.ToString() + "\t" + ((list[k].operand != null) ? list[k].operand.ToString() : "")));
				}
			}
			if (debuglogging)
			{
				Plugin.Logger.LogDebug((object)"Transpiler end going to return");
			}
			return list.AsEnumerable();
		}

		[HarmonyPostfix]
		private static void Postfix(UIItemTip __instance)
		{
			ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(__instance.showingItemId);
			if (val == null)
			{
				return;
			}
			Plugin.Logger.LogDebug((object)"Item Proto found");
			if (Plugin.Modus.Value != 2)
			{
				Plugin.Logger.LogDebug((object)"Modus 1 runs");
				switch (Plugin.Modus_1_Setting.Value)
				{
				case 1:
					__instance.nameText.text = __instance.nameText.text + " (Stack Size:" + val.StackSize + ")";
					break;
				case 2:
					__instance.nameText.text = __instance.nameText.text + " (Stack:" + val.StackSize + ")";
					break;
				case 3:
					__instance.nameText.text = __instance.nameText.text + " (" + val.StackSize + ")";
					break;
				}
			}
			if (Plugin.Modus.Value != 1)
			{
				Plugin.Logger.LogDebug((object)"Modus 2 runs");
				switch (Plugin.Modus_2_Setting.Value)
				{
				case 1:
					__instance.propsText.text = "Stack Size\r\n" + __instance.propsText.text;
					__instance.valuesText.text = val.StackSize + "\r\n" + __instance.valuesText.text;
					break;
				case 2:
					__instance.propsText.text = __instance.propsText.text + "Stack Size";
					__instance.valuesText.text = __instance.valuesText.text + val.StackSize;
					break;
				}
			}
		}
	}
}