Decompiled source of PearlToCore v1.0.0

plugins\PearlToCore\PearlToCore.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
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("PearlToCore")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PearlToCore")]
[assembly: AssemblyTitle("PearlToCore")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 PearlToCore
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.KoWoogi.PearlToCore", "PearlToCore", "1.0.0")]
	public class PearlToCorePlugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_SetItemDefs <>9__6_0;

			internal void <Awake>b__6_0(orig_SetItemDefs orig, ItemDef[] defs)
			{
				RetierItemDefs();
				orig.Invoke(defs);
			}
		}

		public const string Guid = "com.KoWoogi.PearlToCore";

		public const string Name = "PearlToCore";

		public const string Version = "1.0.0";

		private static ManualLogSource _log;

		private static readonly Dictionary<string, Sprite> SpriteCache = new Dictionary<string, Sprite>();

		private static (ItemDef itemDef, string iconResourceName)[] Targets()
		{
			return new(ItemDef, string)[2]
			{
				(Items.Pearl, "texPearlIcon.png"),
				(Items.ShinyPearl, "texShinyPearlIcon.png")
			};
		}

		private void Awake()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			_log = ((BaseUnityPlugin)this).Logger;
			PickupCatalog.modifyPickups = (Action<List<PickupDef>>)Delegate.Combine(PickupCatalog.modifyPickups, new Action<List<PickupDef>>(ModifyPickups));
			object obj = <>c.<>9__6_0;
			if (obj == null)
			{
				hook_SetItemDefs val = delegate(orig_SetItemDefs orig, ItemDef[] defs)
				{
					RetierItemDefs();
					orig.Invoke(defs);
				};
				<>c.<>9__6_0 = val;
				obj = (object)val;
			}
			ItemCatalog.SetItemDefs += (hook_SetItemDefs)obj;
		}

		private static void RetierItemDefs()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ItemTierDef val = FindCoreTierDef();
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				(ItemDef, string)[] array = Targets();
				for (int i = 0; i < array.Length; i++)
				{
					var (val2, fileName) = array[i];
					if (!((Object)(object)val2 == (Object)null))
					{
						val2.tier = val.tier;
						Sprite val3 = LoadEmbeddedSprite(fileName);
						if ((Object)(object)val3 != (Object)null)
						{
							val2.pickupIconSprite = val3;
						}
						_log.LogInfo((object)("Retiered " + ((Object)val2).name + " to " + ((Object)val).name + " tier " + $"and swapped its icon art (sprite loaded: {(Object)(object)val3 != (Object)null})."));
					}
				}
			}
			catch (Exception ex)
			{
				_log.LogError((object)("RetierItemDefs failed: " + ex));
			}
		}

		private static void ModifyPickups(List<PickupDef> pickups)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ItemTierDef val = FindCoreTierDef();
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Color32 color = ColorCatalog.GetColor(val.colorIndex);
				Color32 color2 = ColorCatalog.GetColor(val.darkColorIndex);
				(ItemDef, string)[] array = Targets();
				for (int i = 0; i < array.Length; i++)
				{
					ItemDef item = array[i].Item1;
					ItemIndex itemIndex = item.itemIndex;
					PickupDef val2 = null;
					foreach (PickupDef pickup in pickups)
					{
						if (pickup != null && pickup.itemIndex == itemIndex)
						{
							val2 = pickup;
							break;
						}
					}
					if (val2 != null)
					{
						val2.itemTier = val.tier;
						val2.baseColor = Color32.op_Implicit(color);
						val2.darkColor = Color32.op_Implicit(color2);
						val2.dropletDisplayPrefab = val.dropletDisplayPrefab;
						_log.LogInfo((object)$"Recolored pickup for {itemIndex} to {((Object)val).name} tier.");
					}
				}
			}
			catch (Exception ex)
			{
				_log.LogError((object)("ModifyPickups failed: " + ex));
			}
		}

		private static ItemTierDef FindCoreTierDef()
		{
			ItemTierDef val = ItemTierCatalog.FindTierDef("Core");
			if ((Object)(object)val == (Object)null)
			{
				_log.LogError((object)"Could not find Augmentum's \"Core\" item tier. Is Augmentum installed and up to date?");
			}
			return val;
		}

		private static Sprite LoadEmbeddedSprite(string fileName)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if (SpriteCache.TryGetValue(fileName, out var value))
			{
				return value;
			}
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = "PearlToCore.Resources." + fileName;
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				_log.LogError((object)("Embedded resource not found: " + text));
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			byte[] array = memoryStream.ToArray();
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, array))
			{
				_log.LogError((object)("Failed to decode embedded PNG: " + text));
				return null;
			}
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			SpriteCache[fileName] = val2;
			return val2;
		}
	}
}