Decompiled source of SimplifiedBuffIcons v1.0.0

plugins/SimplifiedBuffIcons/SimplifedBuffIcons.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using HG.Reflection;
using RoR2;
using RoR2.ContentManagement;
using RoR2BepInExPack.GameAssetPathsBetter;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace SimplifiedBuffIcons;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.bobot.simplifiedbufficons", "Simplified Buff Icons", "1.0.0")]
public class SimplifiedBuffIconsMain : BaseUnityPlugin
{
	public const string GUID = "com.bobot.simplifiedbufficons";

	public const string MODNAME = "Simplified Buff Icons";

	public const string VERSION = "1.0.0";

	private static AssetBundle mainBundle;

	private Dictionary<string, Sprite> iconCache = new Dictionary<string, Sprite>();

	private static List<BuffDef> buffsToGive = new List<BuffDef>();

	internal static DirectoryInfo exportDirectory = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Icons"));

	public static PluginInfo pluginInfo { get; private set; }

	public static SimplifiedBuffIconsMain instance { get; private set; }

	private static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(pluginInfo.Location), "SimplifiedBuffIconsAssets");

	private void Awake()
	{
		instance = this;
		pluginInfo = ((BaseUnityPlugin)this).Info;
		mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		((ResourceAvailability)(ref BuffCatalog.availability)).CallWhenAvailable((Action)SetNewIcons);
	}

	[ConCommand(/*Could not decode attribute arguments.*/)]
	private static void CCBuffIconTest(ConCommandArgs args)
	{
		CharacterBody body = PlayerCharacterMasterController.instances[0].body;
		foreach (BuffDef item in buffsToGive)
		{
			body.AddUnmanagedBuff(item, 1);
		}
	}

	private void SetNewIcons()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		Color val = default(Color);
		ColorUtility.TryParseHtmlString("#666666", ref val);
		Color accelerantColour = default(Color);
		ColorUtility.TryParseHtmlString("#394142", ref accelerantColour);
		Color chefColour = default(Color);
		ColorUtility.TryParseHtmlString("#d0d8dc", ref chefColour);
		Color colour = default(Color);
		ColorUtility.TryParseHtmlString("#adc152", ref colour);
		Color soulCostColour = default(Color);
		ColorUtility.TryParseHtmlString("#81E3A5", ref soulCostColour);
		Color val2 = default(Color);
		ColorUtility.TryParseHtmlString("#24CFFF", ref val2);
		AsyncOperationHandle<Sprite> val3 = AssetAsyncReferenceManager<Sprite>.LoadAsset(new AssetReferenceT<Sprite>(RoR2_DLC2_Chef.texChefOiledDebuffIcon_png), (AsyncReferenceHandleUnloadType)2);
		val3.Completed += delegate(AsyncOperationHandle<Sprite> x)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Sprite result = x.Result;
			ReplaceIcon(Buffs.Accelerant, result, accelerantColour, changeColour: true);
			ReplaceIcon(Buffs.AccelerantIgnited, result, accelerantColour, changeColour: true);
		};
		val3 = AssetAsyncReferenceManager<Sprite>.LoadAsset(new AssetReferenceT<Sprite>(RoR2_Base_EclipseRun.texBuffPermanentCurse_tif), (AsyncReferenceHandleUnloadType)2);
		val3.Completed += delegate(AsyncOperationHandle<Sprite> x)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Sprite result = x.Result;
			ReplaceIcon(Buffs.SoulCost, result, soulCostColour, changeColour: true);
			ReplaceIcon(Buffs.SmallSoulCost, result, soulCostColour, changeColour: true);
		};
		val3 = AssetAsyncReferenceManager<Sprite>.LoadAsset(new AssetReferenceT<Sprite>(RoR2_Base_Common.texBuffOnFireIcon_tif), (AsyncReferenceHandleUnloadType)2);
		val3.Completed += delegate(AsyncOperationHandle<Sprite> x)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			Sprite result = x.Result;
			ReplaceIcon(Buffs.CookingRoasted, result, chefColour, changeColour: true);
		};
		val3 = AssetAsyncReferenceManager<Sprite>.LoadAsset(new AssetReferenceT<Sprite>(RoR2_Base_Common.texBuffSlow50Icon_tif), (AsyncReferenceHandleUnloadType)2);
		val3.Completed += delegate(AsyncOperationHandle<Sprite> x)
		{
			Sprite result = x.Result;
			ReplaceIcon(Buffs.BogSlow, result);
		};
		val3 = AssetAsyncReferenceManager<Sprite>.LoadAsset(new AssetReferenceT<Sprite>(RoR2_DLC2_Elites_EliteAurelionite.texBuffAffixAureleonite_png), (AsyncReferenceHandleUnloadType)2);
		val3.Completed += delegate(AsyncOperationHandle<Sprite> x)
		{
			ReplaceIcon(Buffs.EliteAurelionite, x.Result);
		};
		ReplaceIcon(Buffs.CookingChilled, chefColour);
		ReplaceIcon(Buffs.CookingChopped, chefColour);
		ReplaceIcon(Buffs.CookingOiled, chefColour);
		ReplaceIcon(Buffs.CookingRolled, chefColour);
		ReplaceIcon(Buffs.ExtraStatsOnLevelUpBuff, "f4e86e");
		ReplaceIcon(Buffs.ElusiveAntlersBuff, "60d7e4");
		ReplaceIcon(Buffs.AttackSpeedPerNearbyAllyOrEnemyBuff, "5ab999");
		ReplaceIcon(Buffs.HealAndReviveRegenBuff, "36EB3F");
		ReplaceIcon(Buffs.FreeUnlocks, "fcff86");
		ReplaceIcon(Buffs.CritChanceAndDamage, "216F87");
		ReplaceIcon(Buffs.SharedSufferingStockEmpty, val, "texSharedSufferingStockIcon");
		ReplaceIcon(Buffs.StimShot, "c8f34d");
		ReplaceIcon(Buffs.SureProc, Color.white);
		ReplaceIcon(Buffs.Parrying);
		BuffDef jumpDamageStrikeCharge = Buffs.JumpDamageStrikeCharge;
		BuffDefStockThresholdIcon val4 = (BuffDefStockThresholdIcon)(object)((jumpDamageStrikeCharge is BuffDefStockThresholdIcon) ? jumpDamageStrikeCharge : null);
		ReplaceIcon((BuffDef)(object)val4, "9E9E9E", "texJumpDamageStrikeChargedIcon");
		StackIconOverride val5 = val4.iconOverrides[0];
		ExportTexture(val5.iconOverride, ((BuffDef)val4).buffColor, ((Object)val4).name + "Override", baseIcon: true);
		val5.iconOverride = mainBundle.LoadAsset<Sprite>("texJumpDamageStrikeChargedIcon");
		val5.colorOverride = val2;
		ExportTexture(val5.iconOverride, val2, ((Object)val4).name + "Override", baseIcon: false);
		ReplaceIcon(Buffs.RechargeableExtraJump, colour);
		ReplaceIcon(Buffs.RechargeableExtraJumpCounter, colour);
		ReplaceIcon(Buffs.SprintDamageSpeed, "8AE386");
		ReplaceIcon(Buffs.SprintDamageReady, "b0c2ff", "texSprintDamageCooldownBuffIcon");
		ReplaceIcon(Buffs.SprintDamageCooldown, val, "texSprintDamageCooldownBuffIcon");
		ReplaceIcon(Buffs.MidasTouchReady, Color.white);
		ReplaceIcon(Buffs.MidasTouchCooldown, Color.white);
		ReplaceIcon(Buffs.Clarity, "2ebb9f");
		ReplaceIcon(Buffs.SacrificeRitualMarked, "08D372");
		ReplaceIcon(Buffs.Haunted, "89e434");
		Buffs.PheromoneExhaustion.buffColor = val;
		ReplaceIcon(Buffs.VengefulRage, "00FFF5");
		ReplaceIcon(Buffs.LowHealthOrbSpawnerReady);
		ReplaceIcon(Buffs.LowHealthOrbSpawnerCooldown);
		ReplaceIcon(Buffs.WeakAssHamstringJumpReduction, "b3df3a");
		ReplaceIcon(Buffs.CrowdControlBuff, "4161DE");
		ReplaceIcon(Buffs.EliteBead);
		iconCache = null;
	}

	private void ReplaceIcon(BuffDef buff, string colour, string nameOverride)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		if (!colour.StartsWith("#"))
		{
			colour = "#" + colour;
		}
		Color colour2 = default(Color);
		ColorUtility.TryParseHtmlString(colour, ref colour2);
		ReplaceIcon(buff, colour2, changeColour: true, nameOverride);
	}

	private void ReplaceIcon(BuffDef buff, Color colour, string nameOverride)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		ReplaceIcon(buff, colour, changeColour: true, nameOverride);
	}

	private void ReplaceIcon(BuffDef buff, string colour)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		if (!colour.StartsWith("#"))
		{
			colour = "#" + colour;
		}
		Color colour2 = default(Color);
		ColorUtility.TryParseHtmlString(colour, ref colour2);
		ReplaceIcon(buff, colour2, changeColour: true);
	}

	private void ReplaceIcon(BuffDef buff, Color colour)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		ReplaceIcon(buff, colour, changeColour: true);
	}

	private void ReplaceIcon(BuffDef buff)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		ReplaceIcon(buff, Color.black, changeColour: false);
	}

	private void ReplaceIcon(BuffDef buff, Color colour, bool changeColour, string nameOverride = null)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		ExportTexture(buff.iconSprite, buff.buffColor, ((Object)buff).name, baseIcon: true);
		buffsToGive.Add(buff);
		string text = nameOverride ?? ((Object)buff.iconSprite).name;
		if (!iconCache.TryGetValue(text, out var value))
		{
			value = mainBundle.LoadAsset<Sprite>(text);
			iconCache.Add(text, value);
		}
		if (changeColour)
		{
			buff.buffColor = colour;
		}
		if (Object.op_Implicit((Object)(object)value))
		{
			buff.iconSprite = value;
			ExportTexture(value, buff.buffColor, ((Object)buff).name, baseIcon: false);
			return;
		}
		LogWarning("Failed to load \"" + text + "\" for buff \"" + ((Object)buff).name + "\"");
	}

	private void ReplaceIcon(BuffDef buff, Sprite newIcon)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		ReplaceIcon(buff, newIcon, Color.black, changeColour: false);
	}

	private void ReplaceIcon(BuffDef buff, Sprite newIcon, Color colour, bool changeColour)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: 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)
		ExportTexture(buff.iconSprite, buff.buffColor, ((Object)buff).name, baseIcon: true);
		buffsToGive.Add(buff);
		if (changeColour)
		{
			buff.buffColor = colour;
		}
		buff.iconSprite = newIcon;
		ExportTexture(newIcon, buff.buffColor, ((Object)buff).name, baseIcon: false);
	}

	private void ExportTexture(Sprite sprite, Color color, string buffName, bool baseIcon)
	{
	}

	internal static void LogFatal(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogFatal(data);
	}

	internal static void LogError(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogError(data);
	}

	internal static void LogWarning(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogWarning(data);
	}

	internal static void LogMessage(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogMessage(data);
	}

	internal static void LogInfo(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogInfo(data);
	}

	internal static void LogDebug(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogDebug(data);
	}
}