Decompiled source of RepairOnHold v0.1.0

RepairOnHold.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using RussLeeIV.Valheim.RepairOnHold.Patch;
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: AssemblyTitle("RepairOnHold")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("RussLeeIV")]
[assembly: AssemblyProduct("RussLeeIV.Valheim.RepairOnHold")]
[assembly: AssemblyCopyright("Copyright © RussLeeIV 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7ebaa706-3112-4e44-b167-799a30e41f89")]
[assembly: AssemblyFileVersion("1.26.1003.1728")]
[assembly: AssemblyInformationalVersion("0.26.1003.1728")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.26.1003.1728")]
namespace RussLeeIV.Valheim.RepairOnHold
{
	[BepInPlugin("RepairOnHold.RussLeeIV", "Repair On Hold", "0.1.0")]
	[BepInProcess("valheim.exe")]
	public class RepairOnHoldPlugin : BaseUnityPlugin
	{
		private static Harmony _harmony;

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<int> RepairDelay;

		public static void UnityDebugLog(string message, Object context = null)
		{
			if (context == (Object)null)
			{
				Debug.Log((object)(_harmony.Id + " " + message));
				return;
			}
			Debug.LogFormat(_harmony.Id + " " + message, new object[1] { context });
		}

		public RepairOnHoldPlugin()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			_harmony = new Harmony("RepairOnHold.RussLeeIV");
		}

		public void Awake()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			UnityDebugLog(_harmony.Id + ", Awake!");
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Enabled", true, new ConfigDescription("Is the mod enabled.", (AcceptableValueBase)null, Array.Empty<object>()));
			RepairDelay = ((BaseUnityPlugin)this).Config.Bind<int>("", "Repair Delay", 8, new ConfigDescription("The number of frames to delay between Repairs.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 60), Array.Empty<object>()));
			_harmony.PatchAll(typeof(InventoryGui_Patch));
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			_harmony = null;
		}
	}
}
namespace RussLeeIV.Valheim.RepairOnHold.Patch
{
	public static class InventoryGui_Patch
	{
		private const float HoldDelay = 0.5f;

		private static int _updateDelay = 0;

		private static float _holdTime = 0f;

		private static readonly MethodInfo UseButtonHeld_MethodInfo = typeof(InventoryGui).GetMethod("UseButtonHeld", BindingFlags.Static | BindingFlags.NonPublic);

		private static readonly MethodInfo OnRepairPressed_MethodInfo = typeof(InventoryGui).GetMethod("OnRepairPressed", BindingFlags.Instance | BindingFlags.NonPublic);

		[HarmonyPatch(typeof(InventoryGui), "Update")]
		[HarmonyPostfix]
		public static void Update_Postfix(InventoryGui __instance)
		{
			if (!RepairOnHoldPlugin.Enabled.Value)
			{
				return;
			}
			Button repairButton = __instance.m_repairButton;
			if (((Selectable)repairButton).interactable && ((Behaviour)repairButton).isActiveAndEnabled && (bool)UseButtonHeld_MethodInfo.Invoke(__instance, null) && (bool)UseButtonHeld_MethodInfo.Invoke(__instance, null))
			{
				_holdTime += Time.deltaTime;
				if (!(_holdTime < 0.5f) && 0 >= --_updateDelay)
				{
					OnRepairPressed_MethodInfo.Invoke(__instance, null);
					_updateDelay = RepairOnHoldPlugin.RepairDelay.Value;
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Hide")]
		[HarmonyPostfix]
		public static void Hide_Postfix(InventoryGui __instance)
		{
			_holdTime = 0f;
		}
	}
}