Decompiled source of IconTuner v0.1.0

IconTuner.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using RoR2;
using RoR2.UI;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
namespace Prototype;

[BepInPlugin("icon.tuner", "IconTuner", "0.1.0")]
public class IconTuner : BaseUnityPlugin
{
	public const string identifier = "icon.tuner";

	public const string version = "0.1.0";

	private static ConfigFile file;

	public void Awake()
	{
		file = ((BaseUnityPlugin)this).Config;
		Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
	}

	[HarmonyPatch(typeof(DifficultyDef), "GetIconSprite")]
	[HarmonyPostfix]
	private static Sprite GetIconSprite(Sprite __result)
	{
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Expected O, but got Unknown
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = ((__result != null) ? __result.texture : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return __result;
		}
		Graphics.Blit((Texture)(object)val, RenderTexture.GetTemporary(((Texture)val).width, ((Texture)val).height));
		val = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, 2, false);
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height);
		val.ReadPixels(val2, 0, 0);
		try
		{
			file.Reload();
		}
		catch (FileNotFoundException)
		{
			file.Clear();
		}
		float num = file.Bind<float>("Color", "Hue", 50f, new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 360f), Array.Empty<object>())).Value / 360f;
		float num2 = file.Bind<float>("Color", "Saturation", 80f, new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())).Value / 50f;
		float num3 = file.Bind<float>("Color", "Value", 50f, new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())).Value / 100f - 0.5f;
		float num4 = default(float);
		float num5 = default(float);
		float num6 = default(float);
		for (int i = 0; i < ((Texture)val).width; i++)
		{
			for (int j = 0; j < ((Texture)val).height; j++)
			{
				Color pixel = val.GetPixel(i, j);
				float a = pixel.a;
				Color.RGBToHSV(pixel, ref num4, ref num5, ref num6);
				pixel = Color.HSVToRGB(num, num2 * num5, num6 + num3);
				pixel.a = a;
				val.SetPixel(i, j, pixel);
			}
		}
		val.Apply();
		return Sprite.Create(val, val2, __result.pivot);
	}

	[HarmonyPatch(typeof(RuleChoiceController), "UpdateChoiceDisplay")]
	[HarmonyPostfix]
	private static void UpdateChoiceDisplay(RuleChoiceController __instance)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Invalid comparison between Unknown and I4
		Image image = __instance.image;
		if (Object.op_Implicit((Object)(object)image))
		{
			RuleChoiceDef choiceDef = __instance.choiceDef;
			if (choiceDef == null || (int)choiceDef.difficultyIndex != -1)
			{
				image.sprite = GetIconSprite(image.sprite);
			}
		}
	}
}