Decompiled source of InstantRepairPlus v2.0.1

InstantRepairPlus.dll

Decompiled 4 hours ago
using System.Collections.Generic;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RepairItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("RepairItems")]
[assembly: AssemblyCopyright("Copyright © HP 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("83ac90bd-822e-4bc6-89cd-f3420370d3e0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.yourname.instantrepairplus", "Instant Repair Plus", "2.0.1")]
public class InstantRepairPlus : BaseUnityPlugin
{
	[HarmonyPatch(typeof(InventoryGui), "Show")]
	public static class InventoryGui_Show_Patch
	{
		private static void Postfix()
		{
			if (Instance.autoRepairOnOpen.Value)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null))
				{
					Instance.RepairItems(localPlayer);
				}
			}
		}
	}

	public static InstantRepairPlus Instance;

	private ConfigEntry<KeyCode> repairKey;

	private ConfigEntry<bool> ignoreStation;

	private ConfigEntry<bool> repairEquippedOnly;

	private ConfigEntry<bool> repairHotbarOnly;

	private ConfigEntry<bool> autoRepairOnOpen;

	private ConfigEntry<float> staminaCost;

	private ConfigEntry<bool> playEffect;

	private ConfigEntry<bool> showMessage;

	private void Awake()
	{
		Instance = this;
		repairKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "RepairKey", (KeyCode)57, "Key to repair items");
		ignoreStation = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "IgnoreStationRequirements", true, "Repair without needing a workbench/forge");
		repairEquippedOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("Filters", "RepairEquippedOnly", false, "Only repair equipped items");
		repairHotbarOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("Filters", "RepairHotbarOnly", false, "Only repair hotbar items (row 0)");
		autoRepairOnOpen = ((BaseUnityPlugin)this).Config.Bind<bool>("Automation", "AutoRepairOnInventoryOpen", false, "Automatically repair when inventory opens");
		staminaCost = ((BaseUnityPlugin)this).Config.Bind<float>("Cost", "StaminaCost", 0f, "Stamina cost per repair action");
		playEffect = ((BaseUnityPlugin)this).Config.Bind<bool>("Feedback", "PlayRepairEffect", true, "Play repair animation");
		showMessage = ((BaseUnityPlugin)this).Config.Bind<bool>("Feedback", "ShowMessage", true, "Show on-screen message");
		Harmony.CreateAndPatchAll(typeof(InstantRepairPlus), (string)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Instant Repair Plus Loaded!");
	}

	private void Update()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(repairKey.Value))
		{
			TryRepair();
		}
	}

	private void TryRepair()
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return;
		}
		if (staminaCost.Value > 0f && localPlayer.GetStamina() < staminaCost.Value)
		{
			((Character)localPlayer).Message((MessageType)2, "Not enough stamina!", 0, (Sprite)null);
			return;
		}
		int num = RepairItems(localPlayer);
		if (num > 0)
		{
			if (staminaCost.Value > 0f)
			{
				((Character)localPlayer).UseStamina(staminaCost.Value);
			}
			if (playEffect.Value)
			{
				localPlayer.StartEmote("craft", true);
			}
			if (showMessage.Value)
			{
				((Character)localPlayer).Message((MessageType)2, $"Repaired {num} items", 0, (Sprite)null);
			}
		}
	}

	public int RepairItems(Player player)
	{
		List<ItemData> allItems = ((Humanoid)player).GetInventory().GetAllItems();
		int num = 0;
		foreach (ItemData item in allItems)
		{
			if (item != null && (!repairEquippedOnly.Value || item.m_equipped) && (!repairHotbarOnly.Value || item.m_gridPos.y == 0) && (ignoreStation.Value || CanRepairVanilla(player, item)) && item.m_durability < item.GetMaxDurability())
			{
				item.m_durability = item.GetMaxDurability();
				num++;
			}
		}
		return num;
	}

	private bool CanRepairVanilla(Player player, ItemData item)
	{
		CraftingStation currentCraftingStation = player.GetCurrentCraftingStation();
		if ((Object)(object)currentCraftingStation == (Object)null)
		{
			return false;
		}
		Recipe recipe = ObjectDB.instance.GetRecipe(item);
		if ((Object)(object)recipe == (Object)null || (Object)(object)recipe.m_craftingStation == (Object)null)
		{
			return false;
		}
		if (currentCraftingStation.m_name != recipe.m_craftingStation.m_name)
		{
			return false;
		}
		return currentCraftingStation.GetLevel(true) >= recipe.m_minStationLevel;
	}
}
namespace RepairItems;

public class Class1
{
}