Decompiled source of ReplaceSkillIcons v1.0.0

ReplaceSkillIcons.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ReplaceSkillIcons")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReplaceSkillIcons")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("B8DEEF05-EC39-4886-88F9-1B405FA1A525")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ReplaceSkillIcons
{
	[BepInPlugin("kg.ReplaceSkillIcons", "ReplaceSkillIcons", "1.0.0")]
	public class ReplaceSkillIcons : BaseUnityPlugin
	{
		[HarmonyPatch]
		private static class SkillsDialog_Setup_Patch
		{
			[UsedImplicitly]
			private static IEnumerable<MethodInfo> TargetMethods()
			{
				yield return AccessTools.Method(typeof(SkillsDialog), "Setup", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(Skills), "CheatRaiseSkill", new Type[3]
				{
					typeof(string),
					typeof(float),
					typeof(bool)
				}, (Type[])null);
				yield return AccessTools.Method(typeof(Skills), "RaiseSkill", new Type[2]
				{
					typeof(SkillType),
					typeof(float)
				}, (Type[])null);
			}

			[UsedImplicitly]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> code)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(code, (ILGenerator)null);
				FieldInfo fieldInfo = AccessTools.Field(typeof(SkillDef), "m_icon");
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo, (string)null)
				});
				if (val.IsInvalid)
				{
					return val.Instructions();
				}
				val.Set(OpCodes.Call, (object)AccessTools.Method(typeof(ReplaceSkillIcons), "TryOverrideSkillIcon", (Type[])null, (Type[])null));
				return val.Instructions();
			}
		}

		private const string GUID = "kg.ReplaceSkillIcons";

		private const string NAME = "ReplaceSkillIcons";

		private const string VERSION = "1.0.0";

		private static readonly Dictionary<int, Sprite> _skillIcons = new Dictionary<int, Sprite>();

		private void Awake()
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Paths.ConfigPath, "ReplaceSkillIcons");
			if (!Directory.Exists(path))
			{
				Directory.CreateDirectory(path);
			}
			string[] files = Directory.GetFiles(path);
			foreach (string text in files)
			{
				if (text.EndsWith(".png"))
				{
					string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
					Texture2D val = new Texture2D(2, 2);
					ImageConversion.LoadImage(val, File.ReadAllBytes(text));
					Sprite value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero);
					SkillType result;
					int key = ((!Enum.TryParse<SkillType>(fileNameWithoutExtension, ignoreCase: true, out result)) ? Math.Abs(StringExtensionMethods.GetStableHashCode(fileNameWithoutExtension)) : ((int)result));
					_skillIcons[key] = value;
				}
			}
			new Harmony("kg.ReplaceSkillIcons").PatchAll();
		}

		public static Sprite TryOverrideSkillIcon(SkillDef skill)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected I4, but got Unknown
			if (!_skillIcons.TryGetValue((int)skill.m_skill, out var value))
			{
				return skill.m_icon;
			}
			return value;
		}
	}
}