using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("MoreHatsMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreHatsMod")]
[assembly: AssemblyTitle("MoreHatsMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace MoreHatsMod
{
[HarmonyPatch(typeof(CharacterCustomizerManager))]
internal class AddHats
{
public static bool included_the_hats = false;
public static string[] registered_hats = new string[5] { "Hat_Cube", "Hat_Cylinder", "Hat_Troll", "Hat_Sphere", "Hat_Thug" };
public static List<GameObject> hat_list;
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void Postfix()
{
if (included_the_hats)
{
return;
}
included_the_hats = true;
hat_list = new List<GameObject>();
LoadHats();
foreach (GameObject item in hat_list)
{
MenuToGameBridger.Singleton.hat_Prefabs.Add(item);
}
}
private static void LoadHats()
{
string[] array = registered_hats;
foreach (string text in array)
{
GameObject val = Plugin.Load<GameObject>(text + ".prefab");
if ((Object)(object)val == (Object)null)
{
continue;
}
val.AddComponent<HumanCustomizerAccessory>();
HumanCustomizerAccessory component = val.GetComponent<HumanCustomizerAccessory>();
component.displayName = text;
component.allowInFriendsPass = true;
component.alwaysUnlocked = true;
Sprite val2 = Plugin.Load<Sprite>(text + ".png");
if ((Object)(object)val2 != (Object)null)
{
component.thumbnailImage = val2;
}
else
{
component.thumbnailImage = Plugin.Load<Sprite>("Hat_Empty.png");
}
Material hatMat = GetHatMat();
MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>();
for (int j = 0; j < componentsInChildren.Length; j++)
{
Renderer val3 = (Renderer)(object)componentsInChildren[j];
int num = val3.materials.Length;
Material[] array2 = (Material[])(object)new Material[num];
for (int k = 0; k < num; k++)
{
array2[k] = hatMat;
}
val3.SetMaterialArray(array2);
}
hat_list.Add(val);
}
}
private static Material GetHatMat()
{
Material result = null;
Material[] array = Resources.FindObjectsOfTypeAll<Material>();
foreach (Material val in array)
{
if (((Object)val).name == "Clay_Accessories")
{
result = val;
break;
}
}
return result;
}
}
[BepInPlugin("MoreHatsMod", "MoreHatsMod", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static AssetBundle bundle;
private readonly Harmony harmony = new Harmony("MoreHatsMod");
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MoreHatsMod is loaded!");
bundle = AssetBundle.LoadFromFile(Assembly.GetExecutingAssembly().Location.Replace("MoreHatsMod.dll", "morehats"));
harmony.PatchAll(typeof(AddHats));
}
public static T Load<T>(string key) where T : Object
{
return bundle.LoadAsset<T>(key);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "MoreHatsMod";
public const string PLUGIN_NAME = "MoreHatsMod";
public const string PLUGIN_VERSION = "1.0.0";
}
}