Decompiled source of Pro Controller Prompts v1.0.0

YapYapControllerPrompts.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("com.yourname.yapyap.uiprompts", "YapYap Controller Prompts", "1.0.0")]
public class YapYapPromptMod : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private static Dictionary<string, Texture2D> customTextures = new Dictionary<string, Texture2D>();

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

	private void Awake()
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
		string[] files = Directory.GetFiles(directoryName, "*.png");
		string[] array = files;
		foreach (string path in array)
		{
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
			byte[] array2 = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array2);
			((Object)val).name = fileNameWithoutExtension;
			customTextures[fileNameWithoutExtension] = val;
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			((Object)val2).name = fileNameWithoutExtension;
			customSprites[fileNameWithoutExtension] = val2;
			Log.LogInfo((object)("Loaded custom prompt replacement for: " + fileNameWithoutExtension));
		}
		Harmony.CreateAndPatchAll(typeof(YapYapPromptMod), (string)null);
		Log.LogInfo((object)"YapYap Controller Prompts loaded and patching!");
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(RawImage), "set_texture")]
	private static void SwapRawImageTexture(ref Texture value)
	{
		if ((Object)(object)value != (Object)null && customTextures.ContainsKey(((Object)value).name))
		{
			value = (Texture)(object)customTextures[((Object)value).name];
		}
	}

	[HarmonyPatch(typeof(Image), "set_sprite")]
	[HarmonyPrefix]
	private static void SwapImageSprite(ref Sprite value)
	{
		if ((Object)(object)value != (Object)null && customSprites.ContainsKey(((Object)value).name))
		{
			value = customSprites[((Object)value).name];
		}
	}
}