Decompiled source of FLAREBITS SUNCAPS PACK MoreCustomHats v1.0.0

MoreCustomHats.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
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("MoreCustomHats")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+50991cf4e6a7b4d70b9a04ba60966584af1867dc")]
[assembly: AssemblyProduct("MoreCustomHats")]
[assembly: AssemblyTitle("MoreCustomHats")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreCustomHats;

[BepInPlugin("unknown.flarebits-who_up_pea-ing_their_king-moremustommats", "More custom hats", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private class Patcher
	{
		public static bool CreateHatOption(Customization customization, string name, Texture2D icon)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			if (Array.Exists(customization.hats, (CustomizationOption hat) => ((Object)hat).name == name))
			{
				Debug.LogError((object)("[MonAmiral] Trying to add " + name + " a second time."));
				return false;
			}
			CustomizationOption val = ScriptableObject.CreateInstance<CustomizationOption>();
			val.color = Color.white;
			((Object)val).name = name;
			val.texture = (Texture)(object)icon;
			val.type = (Type)50;
			val.requiredAchievement = (ACHIEVEMENTTYPE)0;
			customization.hats = CollectionExtensions.AddToArray<CustomizationOption>(customization.hats, val);
			Debug.Log((object)("[MonAmiral] " + name + " added."));
			return true;
		}

		[HarmonyPatch(typeof(PassportManager), "Awake")]
		[HarmonyPostfix]
		public static void PassportManagerAwakePostfix(PassportManager __instance)
		{
			Customization component = ((Component)__instance).GetComponent<Customization>();
			Debug.Log((object)"[MonAmiral] Adding hat CustomizationOptions.");
			for (int i = 0; i < hats.Count; i++)
			{
				HatEntry hatEntry = hats[i];
				CreateHatOption(component, hatEntry.Name, hatEntry.Icon);
			}
			Debug.Log((object)"[MonAmiral] Done.");
		}

		[HarmonyPatch(typeof(CharacterCustomization), "Awake")]
		[HarmonyPostfix]
		public static void CharacterCustomizationAwakePostfix(CharacterCustomization __instance)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			Transform child = ((Component)__instance).transform.GetChild(0).GetChild(0).GetChild(0)
				.GetChild(2)
				.GetChild(0)
				.GetChild(0)
				.GetChild(1)
				.GetChild(1);
			Debug.Log((object)$"[MonAmiral] Instanciating hats as children of {child}.");
			for (int i = 0; i < hats.Count; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(hats[i].Prefab, child.position, child.rotation, child);
				Renderer componentInChildren = val.GetComponentInChildren<Renderer>();
				((Component)componentInChildren).gameObject.SetActive(false);
				componentInChildren.material.shader = Shader.Find("W/Character");
				__instance.refs.playerHats = CollectionExtensions.AddToArray<Renderer>(__instance.refs.playerHats, componentInChildren);
			}
		}
	}

	public struct HatEntry
	{
		public string Name;

		public GameObject Prefab;

		public Texture2D Icon;

		public HatEntry(string name, GameObject prefab, Texture2D icon)
		{
			Name = name;
			Prefab = prefab;
			Icon = icon;
		}
	}

	public static AssetBundle assetBundle;

	public static List<HatEntry> hats;

	public void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("unknown.flarebits-who_up_pea-ing_their_king-moremustommats").PatchAll(typeof(Patcher));
		((MonoBehaviour)this).StartCoroutine(LoadHatsFromDisk());
	}

	private static IEnumerator LoadHatsFromDisk()
	{
		Debug.Log((object)"[MonAmiral] Loading hats from disk.");
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string path = Path.Combine(directoryName, "morecustomhats");
		Debug.Log((object)("[MonAmiral] Path to AssetBundle: " + path));
		AssetBundleCreateRequest createRequest = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path));
		yield return createRequest;
		assetBundle = createRequest.assetBundle;
		Debug.Log((object)"[MonAmiral] AssetBundle loaded.");
		hats = new List<HatEntry>();
		hats.Add(LoadHat("SUNNYEGG"));
		hats.Add(LoadHat("NOTCAPSCOMBO"));
		Debug.Log((object)"[MonAmiral] Done!");
	}

	private static HatEntry LoadHat(string hatName)
	{
		Debug.Log((object)("[MonAmiral] Loading hat '" + hatName + "'."));
		GameObject val = assetBundle.LoadAsset<GameObject>(hatName + "prefab");
		if (val == null)
		{
			Debug.Log((object)"prefab null");
		}
		else
		{
			Debug.Log((object)"prefab not null");
		}
		Texture2D val2 = assetBundle.LoadAsset<Texture2D>(hatName + "icon");
		if (val2 == null)
		{
			Debug.Log((object)"icon null");
		}
		else
		{
			Debug.Log((object)"icon not null");
		}
		Debug.Log((object)$"[MonAmiral] Loaded prefab {val} and texture {val2}");
		return new HatEntry(hatName, val, val2);
	}
}