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;
using Zorro.Core;
[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("ManyManyHats")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("ManyManyHats")]
[assembly: AssemblyTitle("MoreCustomHats_SamVersion")]
[assembly: AssemblyVersion("0.0.1.0")]
namespace ManyManyHats;
[BepInPlugin("manymanyhats", "Many Many Hats", "1.4.0")]
[BepInDependency("MoreCustomizations", "1.1.9")]
public class Plugin : BaseUnityPlugin
{
private class Patcher
{
private static readonly int SkinColor = Shader.PropertyToID("_SkinColor");
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] PassportManager[{customization.hats.Length - 1}] = {name}");
return true;
}
[HarmonyPatch(typeof(PassportManager), "Awake")]
[HarmonyPostfix]
public static void PassportManagerAwakePostfix(PassportManager __instance)
{
Customization component = ((Component)__instance).GetComponent<Customization>();
Debug.Log((object)"[MonAmiral] Adding PassportManager 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_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
Transform val = ((Component)__instance.refs).transform.Find("Armature/Hip/Mid/AimJoint/Torso/Head/Hat");
List<Renderer> list = new List<Renderer>(__instance.refs.playerHats);
Debug.Log((object)$"[MonAmiral] Instanciating CharacterCustomization hats as children of {__instance} / {val}.");
for (int i = 0; i < hats.Count; i++)
{
HatEntry hatEntry = hats[i];
GameObject val2 = Object.Instantiate<GameObject>(hatEntry.Prefab, val.position, val.rotation, val);
SetLayerRecursively(val2.transform, ((Component)val).gameObject.layer);
Renderer componentInChildren = val2.GetComponentInChildren<Renderer>();
((Component)componentInChildren).gameObject.SetActive(false);
for (int j = 0; j < componentInChildren.materials.Length; j++)
{
componentInChildren.materials[j].shader = Shader.Find("W/Character");
}
Debug.Log((object)$"[MonAmiral] CharacterCustomization Hats[{list.Count}] = {hatEntry.Name}");
__instance.refs.AllRenderers = CollectionExtensions.AddToArray<Renderer>(__instance.refs.AllRenderers, componentInChildren);
list.Add(componentInChildren);
}
__instance.refs.playerHats = list.ToArray();
}
[HarmonyPatch(typeof(CharacterCustomization), "OnPlayerDataChange")]
[HarmonyPostfix]
public static void CharacterCustomizationOnPlayerDataChangePostFix(CharacterCustomization __instance, ref PersistentPlayerData playerData)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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)
if ((Object)(object)__instance.refs.PlayerRenderers[0] == (Object)null)
{
return;
}
int num = playerData.customizationData.currentSkin;
if (__instance.useDebugColor)
{
num = __instance.debugColorIndex;
}
Color color = Singleton<Customization>.Instance.skins[num].color;
for (int i = 0; i < __instance.refs.playerHats.Length; i++)
{
for (int j = 0; j < __instance.refs.playerHats[i].materials.Length; j++)
{
__instance.refs.playerHats[i].materials[j].SetColor(SkinColor, color);
}
}
}
[HarmonyPatch(typeof(PlayerCustomizationDummy), "SetPlayerColor")]
[HarmonyPostfix]
public static void PlayerCustomizationDummySetPlayerColorPostFix(PlayerCustomizationDummy __instance, ref int index)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
if (index > Singleton<Customization>.Instance.skins.Length)
{
return;
}
Color color = Singleton<Customization>.Instance.skins[index].color;
for (int i = 0; i < __instance.refs.playerHats.Length; i++)
{
for (int j = 0; j < __instance.refs.playerHats[i].materials.Length; j++)
{
__instance.refs.playerHats[i].materials[j].SetColor(SkinColor, color);
}
}
}
}
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;
}
}
[CompilerGenerated]
private sealed class <LoadHatsFromDisk>d__4 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
private string <directoryName>5__1;
private string <path>5__2;
private AssetBundleCreateRequest <createRequest>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadHatsFromDisk>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<directoryName>5__1 = null;
<path>5__2 = null;
<createRequest>5__3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
Debug.Log((object)"[MonAmiral] Loading hats from disk.");
<directoryName>5__1 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
<path>5__2 = Path.Combine(<directoryName>5__1, "manymanyhats");
Debug.Log((object)("[MonAmiral] Path to AssetBundle: " + <path>5__2));
<createRequest>5__3 = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(<path>5__2));
<>2__current = <createRequest>5__3;
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
assetBundle = <createRequest>5__3.assetBundle;
Debug.Log((object)"[MonAmiral] AssetBundle loaded.");
hats = new List<HatEntry>();
hats.Add(LoadHat("Acorn"));
hats.Add(LoadHat("Antenna"));
hats.Add(LoadHat("Astronaut"));
hats.Add(LoadHat("Aviators"));
hats.Add(LoadHat("Baseball"));
hats.Add(LoadHat("Bat"));
hats.Add(LoadHat("Bbackward"));
hats.Add(LoadHat("Beanie"));
hats.Add(LoadHat("Bee"));
hats.Add(LoadHat("Beetle"));
hats.Add(LoadHat("Bellhop"));
hats.Add(LoadHat("Beret"));
hats.Add(LoadHat("Bird"));
hats.Add(LoadHat("Blindfold"));
hats.Add(LoadHat("Bow"));
hats.Add(LoadHat("Bucket"));
hats.Add(LoadHat("Bunny"));
hats.Add(LoadHat("Butterfly"));
hats.Add(LoadHat("Capy"));
hats.Add(LoadHat("Crown"));
hats.Add(LoadHat("CuteHat"));
hats.Add(LoadHat("Devil"));
hats.Add(LoadHat("DivinghelmetClosed"));
hats.Add(LoadHat("DivinghelmetOpen"));
hats.Add(LoadHat("dwi"));
hats.Add(LoadHat("Egg"));
hats.Add(LoadHat("Fish"));
hats.Add(LoadHat("Flower"));
hats.Add(LoadHat("Fork"));
hats.Add(LoadHat("Fox"));
hats.Add(LoadHat("Foxhood"));
hats.Add(LoadHat("Frog"));
hats.Add(LoadHat("Furhat"));
hats.Add(LoadHat("Gbutterfly"));
hats.Add(LoadHat("Ghost"));
hats.Add(LoadHat("Gnome"));
hats.Add(LoadHat("Goggles"));
hats.Add(LoadHat("Goromi"));
hats.Add(LoadHat("Goth"));
hats.Add(LoadHat("Hairbun"));
hats.Add(LoadHat("Halo"));
hats.Add(LoadHat("Headphones"));
hats.Add(LoadHat("Headwrap"));
hats.Add(LoadHat("Hennin"));
hats.Add(LoadHat("Horns"));
hats.Add(LoadHat("Hotdog"));
hats.Add(LoadHat("Kalotti"));
hats.Add(LoadHat("Kitty"));
hats.Add(LoadHat("Knife"));
hats.Add(LoadHat("Knife2"));
hats.Add(LoadHat("Knight"));
hats.Add(LoadHat("Llama"));
hats.Add(LoadHat("Leaf"));
hats.Add(LoadHat("Mask"));
hats.Add(LoadHat("Mohawk"));
hats.Add(LoadHat("Moth"));
hats.Add(LoadHat("Nightcap"));
hats.Add(LoadHat("Octojelly"));
hats.Add(LoadHat("Party"));
hats.Add(LoadHat("Piranha"));
hats.Add(LoadHat("Pirate"));
hats.Add(LoadHat("Plant1"));
hats.Add(LoadHat("Plant2"));
hats.Add(LoadHat("PompomHat"));
hats.Add(LoadHat("Safety"));
hats.Add(LoadHat("Saunahattu"));
hats.Add(LoadHat("Showercap"));
hats.Add(LoadHat("Skelly"));
hats.Add(LoadHat("Skull"));
hats.Add(LoadHat("Souwester"));
hats.Add(LoadHat("Straw"));
hats.Add(LoadHat("Sunhat"));
hats.Add(LoadHat("Takoyaki"));
hats.Add(LoadHat("Tiara"));
hats.Add(LoadHat("Tophat"));
hats.Add(LoadHat("Tricera"));
hats.Add(LoadHat("Twig"));
hats.Add(LoadHat("Umbrella"));
hats.Add(LoadHat("Witch"));
Debug.Log((object)"[MonAmiral] Done!");
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
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("manymanyhats").PatchAll(typeof(Patcher));
((MonoBehaviour)this).StartCoroutine(LoadHatsFromDisk());
}
[IteratorStateMachine(typeof(<LoadHatsFromDisk>d__4))]
private static IEnumerator LoadHatsFromDisk()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadHatsFromDisk>d__4(0);
}
private static HatEntry LoadHat(string hatName)
{
Debug.Log((object)("[MonAmiral] Loading hat '" + hatName + "'."));
GameObject val = assetBundle.LoadAsset<GameObject>("Assets/" + hatName + ".prefab");
Texture2D val2 = assetBundle.LoadAsset<Texture2D>("Assets/" + hatName + "_icon.png");
Debug.Log((object)$"[MonAmiral] Loaded prefab {val} and texture {val2}");
return new HatEntry(hatName, val, val2);
}
private static void SetLayerRecursively(Transform transform, int layer)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
((Component)transform).gameObject.layer = layer;
foreach (Transform item in transform)
{
Transform transform2 = item;
SetLayerRecursively(transform2, layer);
}
}
}