Decompiled source of RedEchoesLogbookIcon v1.0.1

RedEchoesLogbookIcon.dll

Decompiled a week ago
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using RoR2;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RedEchoesLogbookIcon;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("binma.redechoes.logbookicon", "Red Echoes Logbook Icon", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private static Texture2D icon;

	private static readonly string Target = Rev("nocIydoBecnedivorPxet");

	private static string Rev(string x)
	{
		char[] array = x.ToCharArray();
		Array.Reverse(array);
		return new string(array);
	}

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(Apply));
	}

	private static Texture2D LoadIcon()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RedEchoesLogbookIcon.Icon.rgba");
		byte[] array = new byte[stream.Length];
		stream.Read(array, 0, array.Length);
		Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
		val.LoadRawTextureData(array);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		val.Apply(false, true);
		((Object)val).name = "texRedEchoesIcon";
		return val;
	}

	private static void Apply()
	{
		try
		{
			int num = 0;
			foreach (CharacterBody allBodyPrefabBodyBodyComponent in BodyCatalog.allBodyPrefabBodyBodyComponents)
			{
				if (Object.op_Implicit((Object)(object)allBodyPrefabBodyBodyComponent) && Object.op_Implicit((Object)(object)allBodyPrefabBodyBodyComponent.portraitIcon) && !(((Object)allBodyPrefabBodyBodyComponent.portraitIcon).name != Target))
				{
					if (!Object.op_Implicit((Object)(object)icon))
					{
						icon = LoadIcon();
					}
					allBodyPrefabBodyBodyComponent.portraitIcon = (Texture)(object)icon;
					num++;
				}
			}
			if (num == 0)
			{
				Log.LogWarning((object)"Target icon not found; nothing changed.");
			}
			else
			{
				Log.LogInfo((object)"Logbook icon updated.");
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)ex);
		}
	}
}