using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Wardrobe")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Wardrobe")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("466cf3d5-484d-48d0-8b99-e69bec9c3827")]
[assembly: AssemblyFileVersion("1.3.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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 Wardrobe
{
public static class PluginConfig
{
public static ConfigEntry<KeyboardShortcut> QuickSwapKey;
public static ConfigEntry<bool> IsModEnabled { get; private set; }
public static ConfigEntry<bool> SwapUtilityItem { get; private set; }
public static void BindConfig(ConfigFile config)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
IsModEnabled = config.Bind<bool>("Global", "IsModEnabled", true, "Enable or Disable this mod");
QuickSwapKey = config.Bind<KeyboardShortcut>("Quick Swap Keybind", "QuickSwapKey", new KeyboardShortcut((KeyCode)101, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Keyboard Shortcut to swap equipment. You must `E` with a modifier key (LeftAlt, RightCtrl, etc.");
SwapUtilityItem = config.Bind<bool>("Swap Options", "SwapUtilityItem", true, "Enable or disable swapping your Utility Item");
}
}
[BepInPlugin("EardwulfDoesMods.valheim.Wardrobe", "Wardrobe", "1.3.0")]
public class Wardrobe : BaseUnityPlugin
{
[HarmonyPatch(typeof(ArmorStand))]
private static class ArmorStandSwapPatch
{
public static readonly int ArmorStandHashCode = StringExtensionMethods.GetStableHashCode("ArmorStand");
[HarmonyPrefix]
[HarmonyPatch("UseItem")]
private static bool ArmorStandSwapGear(ArmorStand __instance, Humanoid user)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
KeyboardShortcut value = PluginConfig.QuickSwapKey.Value;
if (!((KeyboardShortcut)(ref value)).IsDown() || !PluginConfig.IsModEnabled.Value)
{
return true;
}
if (!PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, true, false))
{
ZLog.Log((object)"You do you have access to this armor stand.");
return false;
}
if (Object.op_Implicit((Object)(object)__instance.m_nview) && __instance.m_nview.m_zdo.m_prefab == ArmorStandHashCode)
{
List<ItemDrop> itemlist = ArmorStandEquip(__instance);
PlayerEquipmentToArmorStand(__instance, user);
ArmorStandEquipmentToPlayer(itemlist, user);
ZLog.Log((object)"Swapping Gear with Armor Stand!");
((Terminal)Chat.m_instance).AddString("Swapping gear with ArmorStand");
return false;
}
((Terminal)Chat.m_instance).AddString("<color=red>Failed to swap armor because this is not an armor stand.</color>");
ZLog.Log((object)"ArmorStandSwapGear() failed beacuse the target is not an ArmorStand.");
return false;
}
}
public const string PluginGuid = "EardwulfDoesMods.valheim.Wardrobe";
public const string PluginName = "Wardrobe";
public const string PluginVersion = "1.3.0";
private void Awake()
{
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "EardwulfDoesMods.valheim.Wardrobe");
}
public static List<ItemDrop> ArmorStandEquip(ArmorStand stand)
{
List<ItemDrop> list = new List<ItemDrop>();
for (int i = 0; i < stand.m_slots.Count; i++)
{
if (stand.HaveAttachment(i))
{
string @string = stand.m_nview.GetZDO().GetString(i + "_item", "");
ItemDrop component = ObjectDB.instance.GetItemPrefab(@string).GetComponent<ItemDrop>();
ItemDrop.LoadFromZDO(i, component.m_itemData, stand.m_nview.GetZDO());
list.Add(component);
ZLog.Log((object)$"Wardrobe says I removed item {((Object)component).name} From the ArmorStand. Level: {component.m_itemData.m_quality}");
stand.DestroyAttachment(i);
stand.m_nview.GetZDO().Set(i + "_item", "");
stand.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_SetVisualItem", new object[3] { i, "", 0 });
stand.UpdateSupports();
stand.m_cloths = ((Component)stand).GetComponentsInChildren<Cloth>();
}
}
return list;
}
public static void PlayerEquipmentToArmorStand(ArmorStand stand, Humanoid player)
{
List<ItemData> list = new List<ItemData>();
list.Add(player.m_rightItem);
list.Add(player.m_leftItem);
list.Add(player.m_chestItem);
list.Add(player.m_legItem);
list.Add(player.m_helmetItem);
list.Add(player.m_shoulderItem);
if (PluginConfig.SwapUtilityItem.Value)
{
list.Add(player.m_utilityItem);
}
((MonoBehaviour)stand).CancelInvoke("UpdateAttach");
foreach (ItemData item in list)
{
if (item != null)
{
int num = FindFreeSlot(stand, item);
if (num < 0)
{
throw new IndexOutOfRangeException("This should never happen! Call a grownup!");
}
stand.m_queuedItem = item;
ZLog.Log((object)$"Sending {item.m_shared.m_name} to the Armor Stand. Level: {item.m_quality}");
stand.m_queuedSlot = num;
stand.UpdateAttach();
}
}
((MonoBehaviour)stand).InvokeRepeating("UpdateAttach", 0f, 0.1f);
}
public static void ArmorStandEquipmentToPlayer(List<ItemDrop> itemlist, Humanoid human)
{
//IL_0044: 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)
Player localPlayer = Player.m_localPlayer;
if (!((Object)(object)human == (Object)(object)localPlayer))
{
return;
}
foreach (ItemDrop item in itemlist)
{
if (!((Humanoid)localPlayer).m_inventory.AddItem(item.m_itemData))
{
Object.Instantiate<GameObject>(item.m_itemData.m_dropPrefab, ((Component)localPlayer).transform.position, ((Component)localPlayer).transform.rotation);
}
else
{
localPlayer.QueueEquipAction(item.m_itemData);
}
}
}
private static int FindFreeSlot(ArmorStand stand, ItemData item)
{
for (int i = 0; i < stand.m_slots.Count; i++)
{
if (stand.CanAttach(stand.m_slots[i], item))
{
return i;
}
}
return -1;
}
}
}