Decompiled source of EnhancedIcons v1.0.4

plugins/EnhancedIcons.dll

Decompiled 2 months ago
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EnhancedIcons")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EnhancedIcons")]
[assembly: AssemblyTitle("EnhancedIcons")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace EnhancedIcons
{
	public static class IconLoader
	{
		private const string ResourcePathPrefix = "EnhancedIcons.image.";

		public static Sprite? LoadCustomIcon(string imagePath)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string name = "EnhancedIcons.image." + imagePath;
			try
			{
				using Stream stream = executingAssembly.GetManifestResourceStream(name);
				if (stream == null)
				{
					return null;
				}
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				Texture2D val = new Texture2D(2, 2);
				ImageConversion.LoadImage(val, memoryStream.ToArray());
				Sprite result = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
				Debug.Log((object)("Custom icon loaded successfully: " + imagePath));
				return result;
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"Error loading custom icon: {imagePath}. Exception: {arg}");
				return null;
			}
		}
	}
	public static class InventoryIconPatch
	{
		private static readonly ConcurrentDictionary<string, Sprite> iconCache = new ConcurrentDictionary<string, Sprite>();

		[HarmonyPatch(typeof(HUDManager), "Update")]
		[HarmonyPostfix]
		public static void Update_Postfix(HUDManager __instance)
		{
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			string text = val.currentlyHeldObjectServer?.itemProperties?.itemName;
			if (text == null)
			{
				return;
			}
			string text2 = text + ".png";
			if (iconCache.TryGetValue(text2, out Sprite value))
			{
				__instance.itemSlotIcons[val.currentItemSlot].sprite = value;
				return;
			}
			Sprite val2 = IconLoader.LoadCustomIcon(text2);
			if ((Object)(object)val2 != (Object)null)
			{
				iconCache[text2] = val2;
				__instance.itemSlotIcons[val.currentItemSlot].sprite = val2;
			}
			else
			{
				__instance.itemSlotIcons[val.currentItemSlot].sprite = __instance.itemSlotIcons[val.currentItemSlot].sprite;
			}
		}
	}
	[BepInPlugin("Nilaier.EnhancedIcons", "EnhancedIcons", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony? _harmony;

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			_harmony = new Harmony("Nilaier.EnhancedIcons");
			_harmony.PatchAll(typeof(InventoryIconPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin EnhancedIcons is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PluginGuid = "Nilaier.EnhancedIcons";

		public const string PluginName = "EnhancedIcons";

		public const string PluginVersion = "1.0.4";
	}
}