using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HeadElfGlitnir")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HeadElfGlitnir")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6c70859c-a9c3-4d51-b6d8-896b306390d0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HeadElfGlitnir;
[BepInPlugin("jotav.grit", "HelmetElf", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class HeadElfGlitnir : BaseUnityPlugin
{
public const string PluginGUID = "jotav.grit";
public const string PluginName = "HelmetElf";
public const string PluginVersion = "1.0.2";
private Harmony _harmony;
public static AssetBundle ArmorBundle;
public static List<string> headList = new List<string> { "HeadElf" };
private void Awake()
{
PrefabManager.OnVanillaPrefabsAvailable += LoadHelmetElf;
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "jotav.grit");
}
private void LoadHelmetElf()
{
ArmorBundle = GetAssetBundleFromResources("helmetElf");
if ((Object)(object)ArmorBundle == (Object)null)
{
Debug.LogError((object)"Failed to load AssetBundle!");
return;
}
headList.ForEach(delegate(string x)
{
AddItemsWithRenderedIcons(x, recipe.HelmetElfRequirements);
});
Debug.Log((object)"<color=green>HelmetElf loaded</color>");
}
public void AddItemsWithRenderedIcons(string itemName, RequirementConfig[] requirements, bool setSkill = false)
{
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Expected O, but got Unknown
try
{
GameObject val = ArmorBundle.LoadAsset<GameObject>("HeadElf");
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)"Failed to load GameObject from AssetBundle.");
return;
}
Debug.Log((object)("Successfully loaded GameObject '" + ((Object)val).name + "' from AssetBundle."));
ItemDrop component = val.GetComponent<ItemDrop>();
if ((Object)(object)component != (Object)null)
{
Object.DestroyImmediate((Object)(object)component);
}
GameObject prefab = PrefabManager.Instance.GetPrefab("HelmetLeather");
if ((Object)(object)prefab == (Object)null)
{
Debug.LogError((object)"Failed to find HelmetLeather prefab for reference.");
return;
}
ItemDrop val2 = val.AddComponent<ItemDrop>();
ItemDrop component2 = prefab.GetComponent<ItemDrop>();
val2.m_itemData = component2.m_itemData.Clone();
val2.m_itemData.m_shared.m_itemType = (ItemType)6;
val2.m_itemData.m_shared.m_helmetHideHair = (HelmetHairType)0;
ItemConfig val3 = new ItemConfig();
val3.Name = "Elven Ears";
val3.Description = "A stylish elven ear headpiece";
val3.Amount = 1;
val3.CraftingStation = "forge";
val3.MinStationLevel = 1;
val3.Icons = (Sprite[])(object)new Sprite[1] { component2.m_itemData.GetIcon() };
val3.Requirements = requirements;
ItemConfig val4 = val3;
CustomItem val5 = new CustomItem(val, true, val4);
ItemManager.Instance.AddItem(val5);
Debug.Log((object)("Item " + itemName + " adicionado ao jogo."));
}
catch (Exception arg)
{
Logger.LogError((object)$"Error while adding item: {arg}");
}
}
public static AssetBundle GetAssetBundleFromResources(string fileName)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
string[] array = manifestResourceNames;
foreach (string text in array)
{
Debug.Log((object)("Resource found: " + text));
}
string text2 = manifestResourceNames.FirstOrDefault((string str) => str == "HeadElfGlitnir.Resources.helmetElf");
if (string.IsNullOrEmpty(text2))
{
Debug.LogError((object)"Could not find resource with name: HeadElfGlitnir.Resources.helmetElf ");
return null;
}
using Stream stream = executingAssembly.GetManifestResourceStream(text2);
return AssetBundle.LoadFromStream(stream);
}
[HarmonyPatch]
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
internal class recipe
{
public static RequirementConfig[] HelmetElfRequirements = (RequirementConfig[])(object)new RequirementConfig[3]
{
new RequirementConfig
{
Item = "SwordCheat",
Amount = 10
},
new RequirementConfig
{
Item = "SwordCheat",
Amount = 5
},
new RequirementConfig
{
Item = "SwordCheat",
Amount = 5
}
};
}