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 TMPro;
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("MultipleUtilityUpdate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("MultipleUtilityUpdate")]
[assembly: AssemblyCopyright("Copyright © HP 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("26d8dd0d-8012-4523-a5b5-28225fc7b02f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace EquipMultipleUtilityItems;
[BepInPlugin("toombe.EquipMultipleUtilityItemsUpdate", "Equip Multiple Utility Items Unofficial Ashlands Update", "0.6.7")]
public class BepInExPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Player), "UpdateModifiers")]
private static class UpdateModifiers_Patch
{
private static void Postfix(Player __instance, ref float ___m_equipmentModifierValues, ItemData ___m_utilityItem)
{
if (!modEnabled.Value)
{
return;
}
try
{
List<ItemData> list = ((Humanoid)__instance).GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18 && i != ___m_utilityItem);
foreach (ItemData item in list)
{
___m_equipmentModifierValues += item.m_shared.m_movementModifier;
}
}
catch
{
}
}
}
private static class ApplyArmorDamageMods_Patch
{
private static void Postfix(Player __instance, ref DamageModifiers mods, ItemData ___m_utilityItem)
{
if (!modEnabled.Value)
{
return;
}
try
{
List<ItemData> list = ((Humanoid)__instance).GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18 && i != ___m_utilityItem);
foreach (ItemData item in list)
{
((DamageModifiers)(ref mods)).Apply(item.m_shared.m_damageModifiers);
}
}
catch
{
}
}
}
private static class GetBodyArmor_Patch
{
private static void Postfix(Player __instance, ref float __result)
{
if (!modEnabled.Value)
{
return;
}
try
{
List<ItemData> list = ((Humanoid)__instance).GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18);
foreach (ItemData item in list)
{
__result += item.GetArmor();
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(Humanoid), "IsItemEquiped")]
private static class Humanoid_IsItemEquiped_Patch
{
private static void Postfix(Humanoid __instance, ItemData item, ItemData ___m_utilityItem, ref bool __result)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Invalid comparison between Unknown and I4
if (!modEnabled.Value | __result)
{
return;
}
try
{
__result = item.m_equipped && (int)item.m_shared.m_itemType == 18 && item != ___m_utilityItem;
}
catch
{
}
}
}
[HarmonyPatch(typeof(Player), "GetEquipmentEitrRegenModifier")]
private static class GetEquipmentEitrRegenModifier_Patch
{
private static void Postfix(Player __instance, ItemData ___m_utilityItem, ref float __result)
{
if (!modEnabled.Value)
{
return;
}
try
{
List<ItemData> list = ((Humanoid)__instance).GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18 && i != ___m_utilityItem);
foreach (ItemData item in list)
{
__result += item.m_shared.m_eitrRegenModifier;
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(Player), "QueueEquipAction")]
private static class QueueEquipItem_Patch
{
private static bool Prefix(Player __instance, ItemData item)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Invalid comparison between Unknown and I4
if (!modEnabled.Value || item == null || __instance.IsEquipActionQueued(item) || (int)item.m_shared.m_itemType != 18)
{
return true;
}
try
{
List<ItemData> list = ((Humanoid)__instance).GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18);
if (list.Exists((ItemData i) => i.m_shared.m_name == item.m_shared.m_name))
{
return false;
}
if (list.Count >= maxEquippedItems.Value)
{
return false;
}
}
catch
{
Dbgl("Error: " + Environment.StackTrace);
}
return true;
}
}
[HarmonyPatch(typeof(Humanoid), "EquipItem")]
private static class EquipItem_Patch
{
private static bool Prefix(Humanoid __instance, ItemData item, bool triggerEquipEffects, Inventory ___m_inventory, ref bool __result, ref ItemData ___m_utilityItem)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Invalid comparison between Unknown and I4
try
{
if (!modEnabled.Value || item == null || (int)item.m_shared.m_itemType != 18 || !((Character)__instance).IsPlayer() || !___m_inventory.ContainsItem(item) || ((Character)__instance).InAttack() || ((Character)__instance).InDodge() || (((Character)__instance).IsPlayer() && !((Character)__instance).IsDead() && ((Character)__instance).IsSwimming() && !((Character)__instance).IsOnGround()) || (item.m_shared.m_useDurability && item.m_durability <= 0f) || (item.m_shared.m_dlc.Length > 0 && !DLCMan.instance.IsDLCInstalled(item.m_shared.m_dlc)))
{
return true;
}
int count = __instance.GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18)
.Count;
if (count >= maxEquippedItems.Value)
{
__result = false;
return false;
}
if (___m_utilityItem == null)
{
___m_utilityItem = item;
}
item.m_equipped = true;
typeof(Humanoid).GetMethod("SetupEquipment", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[0]);
if (triggerEquipEffects)
{
typeof(Humanoid).GetMethod("TriggerEquipEffect", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[1] { item });
}
__result = true;
return false;
}
catch
{
Dbgl("Error: " + Environment.StackTrace);
}
return true;
}
}
[HarmonyPatch(typeof(Humanoid), "UpdateEquipmentStatusEffects")]
private static class UpdateEquipmentStatusEffects_Patch
{
private static void Prefix(Humanoid __instance, ItemData ___m_utilityItem, SEMan ___m_seman)
{
try
{
if (!modEnabled.Value || !((Character)__instance).IsPlayer())
{
return;
}
List<ItemData> list = __instance.GetInventory().GetAllItems().FindAll((ItemData i) => !i.m_equipped && (int)i.m_shared.m_itemType == 18 && i != ___m_utilityItem && Object.op_Implicit((Object)(object)i.m_shared.m_equipStatusEffect));
List<ItemData> list2 = __instance.GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18 && i != ___m_utilityItem && Object.op_Implicit((Object)(object)i.m_shared.m_equipStatusEffect));
List<StatusEffect> list3 = new List<StatusEffect>();
foreach (ItemData item in list)
{
foreach (StatusEffect statusEffect in AccessTools.FieldRefAccess<SEMan, List<StatusEffect>>(___m_seman, "m_statusEffects"))
{
if (((Object)statusEffect).name == ((Object)item.m_shared.m_equipStatusEffect).name && (___m_utilityItem == null || ((Object)___m_utilityItem.m_shared.m_equipStatusEffect).name != ((Object)statusEffect).name) && !list2.Exists((ItemData i) => ((Object)i.m_shared.m_equipStatusEffect).name == ((Object)statusEffect).name))
{
list3.Add(statusEffect);
}
}
}
foreach (StatusEffect item2 in list3)
{
___m_seman.RemoveStatusEffect(item2.NameHash(), false);
}
}
catch
{
}
}
private static void Postfix(Humanoid __instance, ItemData ___m_utilityItem, SEMan ___m_seman)
{
try
{
if (!modEnabled.Value || !((Character)__instance).IsPlayer())
{
return;
}
List<ItemData> list = __instance.GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18 && i != ___m_utilityItem && Object.op_Implicit((Object)(object)i.m_shared.m_equipStatusEffect));
List<StatusEffect> list2 = new List<StatusEffect>();
foreach (ItemData item in list)
{
list2.Add(item.m_shared.m_equipStatusEffect);
}
foreach (StatusEffect item2 in list2)
{
___m_seman.AddStatusEffect(item2, false, 0, 0f);
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(Humanoid), "UnequipAllItems")]
private static class UnequipAllItems_Patch
{
private static void Postfix(Humanoid __instance, ItemData ___m_utilityItem)
{
try
{
if (!modEnabled.Value || !((Character)__instance).IsPlayer())
{
return;
}
List<ItemData> list = __instance.GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18 && i != ___m_utilityItem);
foreach (ItemData item in list)
{
__instance.UnequipItem(item, false);
}
}
catch
{
Dbgl("Error: " + Environment.StackTrace);
}
}
}
[HarmonyPatch(typeof(Player), "UnequipDeathDropItems")]
private static class UnequipDeathDropItems_Patch
{
private static void Postfix(Player __instance, ItemData ___m_utilityItem)
{
try
{
if (!modEnabled.Value)
{
return;
}
List<ItemData> list = ((Humanoid)__instance).GetInventory().GetAllItems().FindAll((ItemData i) => i.m_equipped && (int)i.m_shared.m_itemType == 18 && i != ___m_utilityItem);
foreach (ItemData item in list)
{
((Humanoid)__instance).UnequipItem(item, false);
}
}
catch
{
Dbgl("Error: " + Environment.StackTrace);
}
}
}
private static class GetTooltip_Patch
{
private static void Postfix(ref ItemData item, int qualityLevel, float worldLevel, ref string __result)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Invalid comparison between Unknown and I4
try
{
if (modEnabled.Value && (int)item.m_shared.m_itemType == 18)
{
__result += $"\n\n$item_armor: <color=orange>{item.GetArmor(qualityLevel, worldLevel)}</color>";
if (item.m_shared.m_damageModifiers.Count > 0)
{
__result += SE_Stats.GetDamageModifiersTooltipString(item.m_shared.m_damageModifiers);
}
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(Terminal), "InputText")]
private static class InputText_Patch
{
private static bool Prefix(Terminal __instance)
{
if (!modEnabled.Value)
{
return true;
}
try
{
string text = ((TMP_InputField)__instance.m_input).text;
if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
{
((BaseUnityPlugin)context).Config.Reload();
((BaseUnityPlugin)context).Config.Save();
__instance.AddString(text);
__instance.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded");
return false;
}
}
catch
{
Dbgl("Error: " + Environment.StackTrace);
}
return true;
}
}
private static BepInExPlugin context;
private Harmony harmony;
public static ConfigEntry<bool> modEnabled;
public static ConfigEntry<bool> isDebug;
public static ConfigEntry<int> nexusID;
public static ConfigEntry<int> maxEquippedItems;
public static void Dbgl(string str = "", bool pref = true)
{
if (isDebug.Value)
{
Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
}
}
private void Awake()
{
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Expected O, but got Unknown
context = this;
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
isDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "IsDebug", true, "Enable debug logs");
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 2789, "Nexus mod ID for updates");
nexusID.Value = 2789;
maxEquippedItems = ((BaseUnityPlugin)this).Config.Bind<int>("Variables", "MaxEquippedItems", 5, "Maximum number of utility items equipped at once.");
if (modEnabled.Value)
{
harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
harmony.PatchAll();
}
}
}