using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
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("AtraHats")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AtraHats")]
[assembly: AssemblyTitle("AtraHats")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AtraHats.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
ResourceManager resourceManager = new ResourceManager("AtraHats.Properties.Resources", typeof(Resources).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal Resources()
{
}
}
}
namespace MoreCustomHats
{
[BepInPlugin("joberg.atrahats", "Atramentous And Friends Hat Pack", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private class Patcher
{
private static readonly int SkinColor = Shader.PropertyToID("_SkinColor");
private static PlayerCustomizationDummy lastModifiedDummy;
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)("[Joberg] 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)$"[Joberg] 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)"[Joberg] Adding PassportManager CustomizationOptions.");
Texture2D icon = assetBundle.LoadAsset<Texture2D>("Assets/Passport_Dummy.png");
for (int i = 0; i < component.fits.Length; i++)
{
if (component.fits[i].overrideHat)
{
while (component.hats.Length - 1 < component.fits[i].overrideHatIndex)
{
CreateHatOption(component, $"Dummy#{component.hats.Length}", icon);
}
}
}
for (int j = 0; j < hats.Count; j++)
{
HatEntry hatEntry = hats[j];
CreateHatOption(component, hatEntry.Name, hatEntry.Icon);
}
Debug.Log((object)"[Joberg] 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)$"[Joberg] 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)$"[Joberg] 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(PlayerCustomizationDummy), "UpdateDummy")]
[HarmonyPrefix]
public static void PlayerCustomizationDummyUpdateDummyPrefix(PlayerCustomizationDummy __instance)
{
//IL_0072: 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 ((Object)(object)__instance == (Object)(object)lastModifiedDummy)
{
return;
}
lastModifiedDummy = __instance;
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)$"[Joberg] Instanciating PlayerCustomizationDummy 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)$"[Joberg] PlayerCustomizationDummy Hats[{__instance.refs.playerHats.Length}] = {hatEntry.Name}");
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;
}
}
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("joberg.atrahats").PatchAll(typeof(Patcher));
((MonoBehaviour)this).StartCoroutine(LoadHatsFromDisk());
}
private static IEnumerator LoadHatsFromDisk()
{
Debug.Log((object)"[Joberg] Loading hats from disk.");
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(directoryName, "atrahats");
Debug.Log((object)("[Joberg] Path to AssetBundle: " + path));
AssetBundleCreateRequest createRequest = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path));
yield return createRequest;
assetBundle = createRequest.assetBundle;
Debug.Log((object)"[Joberg] AssetBundle loaded.");
hats = new List<HatEntry>();
hats.Add(LoadHat("atra"));
hats.Add(LoadHat("stari"));
hats.Add(LoadHat("ramen"));
hats.Add(LoadHat("seina"));
hats.Add(LoadHat("yozora"));
hats.Add(LoadHat("gwen"));
Debug.Log((object)"[Joberg] Done!");
}
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);
}
}
private static HatEntry LoadHat(string hatName)
{
Debug.Log((object)("[Joberg] Loading hat '" + hatName + "'."));
GameObject val = assetBundle.LoadAsset<GameObject>("Assets/" + hatName + ".prefab");
Texture2D val2 = assetBundle.LoadAsset<Texture2D>("Assets/" + hatName + ".png");
Debug.Log((object)$"[Joberg] Loaded prefab {val} and texture {val2}");
return new HatEntry(hatName, val, val2);
}
}
}