Decompiled source of ItemsLeft v1.0.2

plugins/ItemsLeft.dll

Decompiled 30 minutes ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ItemsLeft")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+3fbe067a4e6d737947118b770fef3a1f19fb4aaf")]
[assembly: AssemblyProduct("ItemsLeft")]
[assembly: AssemblyTitle("ItemsLeft")]
[assembly: AssemblyVersion("1.0.2.0")]
namespace ItemsLeft;

[BepInPlugin("fr.romaindurand.itemsleft", "ItemsLeft", "1.0.2")]
public sealed class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Hud), "SetupPieceInfo")]
	private static class PieceInfoPatch
	{
		private static void Postfix(Hud __instance, Piece __0)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)__0 == (Object)null || (Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			int num = Math.Min(__0.m_resources.Length, __instance.m_requirementItems.Length);
			for (int i = 0; i < num; i++)
			{
				Requirement val = __0.m_resources[i];
				ItemDrop resItem = val.m_resItem;
				if (!((Object)(object)resItem == (Object)null))
				{
					int amount = val.GetAmount(0);
					if (amount > 0)
					{
						TMP_Text component = ((Component)__instance.m_requirementItems[i].transform.Find("res_amount")).GetComponent<TMP_Text>();
						int num2 = inventory.CountItems(resItem.m_itemData.m_shared.m_name, -1, true);
						component.text = $"{num2}/{amount}";
					}
				}
			}
		}
	}

	private const string Guid = "fr.romaindurand.itemsleft";

	private const string Version = "1.0.2";

	private Harmony harmony;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		harmony = new Harmony("fr.romaindurand.itemsleft");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"ItemsLeft 1.0.2 chargé (fr.romaindurand.itemsleft).");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}
}