Decompiled source of HoverTooltipDelay v1.1.0

HoverTooltipDelay.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HoverTooltipDelay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HoverTooltipDelay")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8b627b35-bfc6-434f-a9a6-07746a7ba9ff")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace HoverTooltipDelay;

[BepInPlugin("com.starfi5h.plugin.HoverTooltipDelay", "HoverTooltipDelay", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "com.starfi5h.plugin.HoverTooltipDelay";

	public const string NAME = "HoverTooltipDelay";

	public const string VERSION = "1.1.0";

	public static Plugin instance;

	public static ManualLogSource log;

	private Harmony harmony;

	public void LoadConfig()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		ConfigEntry<int> obj = ((BaseUnityPlugin)this).Config.Bind<int>("General", "DelayFrame", 15, "Time delay for tooltip to show up when mouse hovering on a building.\n弹出式简报介面延迟");
		Patch.SetConfig(fastFillin: ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkey", "FastFillin", (KeyCode)9, "Hotkey to transfer group of items to the selecting buildings.\n背包快捷物品转移的热键").Value, delay: obj.Value);
	}

	public void Awake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		instance = this;
		LoadConfig();
		harmony = new Harmony("com.starfi5h.plugin.HoverTooltipDelay");
		harmony.PatchAll(typeof(Patch));
		log = ((BaseUnityPlugin)this).Logger;
	}

	public void OnDestroy()
	{
		harmony.UnpatchSelf();
	}
}
internal class Patch
{
	private static int UIEntityBriefInfo_DelayFrame = 15;

	private static KeyCode KeyFastFillin = (KeyCode)9;

	public static void SetConfig(int delay, KeyCode fastFillin)
	{
		//IL_0006: 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)
		UIEntityBriefInfo_DelayFrame = delay;
		KeyFastFillin = fastFillin;
	}

	public static int GetDelay()
	{
		return UIEntityBriefInfo_DelayFrame;
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(UIEntityBriefInfo), "_OnUpdate")]
	public static IEnumerable<CodeInstruction> UIEntityBriefInfo_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Expected O, but got Unknown
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Expected O, but got Unknown
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Expected O, but got Unknown
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Expected O, but got Unknown
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Expected O, but got Unknown
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Expected O, but got Unknown
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Expected O, but got Unknown
		try
		{
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "frame"), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ble, (object)null, (string)null)
			}).Advance(2).SetAndAdvance(OpCodes.Call, (object)AccessTools.Method(typeof(Patch), "GetDelay", (Type[])null, (Type[])null))
				.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "frame"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Cgt, (object)null, (string)null)
				})
				.Advance(2)
				.SetAndAdvance(OpCodes.Call, (object)AccessTools.Method(typeof(Patch), "GetDelay", (Type[])null, (Type[])null))
				.MatchForward(false, (CodeMatch[])(object)new CodeMatch[6]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "frame"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Cgt, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ceq, (object)null, (string)null)
				})
				.Advance(2)
				.SetAndAdvance(OpCodes.Call, (object)AccessTools.Method(typeof(Patch), "GetDelay", (Type[])null, (Type[])null))
				.SetAndAdvance(OpCodes.Ldc_I4_1, (object)null)
				.SetAndAdvance(OpCodes.Add, (object)null)
				.InstructionEnumeration();
		}
		catch
		{
			Plugin.log.LogError((object)"Transpiler UIEntityBriefInfo._OnUpdate failed. Mod version not compatible with game version.");
			return instructions;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIEntityBriefInfo), "_OnUpdate")]
	public static void OnUpdate_Postfix(UIEntityBriefInfo __instance)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(KeyFastFillin) && __instance.factory != null && __instance.entityId > 0 && __instance.entityId < __instance.factory.entityCursor)
		{
			TryFastFillStationStoarge(__instance.factory, __instance.entityId);
			ItemBundle val = default(ItemBundle);
			__instance.factory.EntityFastFillIn(__instance.entityId, true, ref val);
			if (val.items.Count > 0)
			{
				VFAudio.Create("transfer-item", (Transform)null, Vector3.zero, true, 3, -1, -1L);
			}
			UIItemup.ForceResetAllGets();
		}
	}

	private static void TryFastFillStationStoarge(PlanetFactory factory, int entityId)
	{
		int stationId = factory.entityPool[entityId].stationId;
		if (stationId <= 0)
		{
			return;
		}
		StationComponent val = factory.transport.stationPool[stationId];
		if (val?.storage == null)
		{
			return;
		}
		int stationMaxItemCount = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)factory.entityPool[entityId].modelIndex).prefabDesc.stationMaxItemCount;
		stationMaxItemCount = (val.isCollector ? (stationMaxItemCount + GameMain.history.localStationExtraStorage) : (val.isVeinCollector ? (stationMaxItemCount + GameMain.history.localStationExtraStorage) : ((!val.isStellar) ? (stationMaxItemCount + GameMain.history.localStationExtraStorage) : (stationMaxItemCount + GameMain.history.remoteStationExtraStorage))));
		StationStore[] storage = val.storage;
		for (int i = 0; i < val.storage.Length; i++)
		{
			int itemId = storage[i].itemId;
			if (itemId > 0)
			{
				int num = stationMaxItemCount - storage[i].count;
				int num2 = 0;
				if (num > 0)
				{
					GameMain.mainPlayer.packageUtility.TryTakeItemFromAllPackages(ref itemId, ref num, ref num2, false);
				}
				if (num > 0)
				{
					storage[i].count = storage[i].count + num;
					storage[i].inc = storage[i].inc + num2;
					break;
				}
			}
		}
	}
}