using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using Jotunn; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using ShieldMeBruh.Components; using ShieldMeBruh.Configuration; using ShieldMeBruh.Extensions; using ShieldMeBruh.Features; using ShieldMeBruh.Patches; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using Vapok.Common.Abstractions; using Vapok.Common.Managers; using Vapok.Common.Managers.Configuration; using Vapok.Common.Managers.Creature; using Vapok.Common.Managers.LocalizationManager; using Vapok.Common.Managers.Location; using Vapok.Common.Managers.PieceManager; using Vapok.Common.Managers.Skill; using Vapok.Common.Managers.StatusEffects; using Vapok.Common.Shared; using Vapok.Common.Tools; using YamlDotNet.Serialization; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ShieldMeBruh")] [assembly: AssemblyDescription("A Valheim Quality of Life Mod that will auto equip a selected shield when a one-handed weapon is equipped. I need a shield! Shield me Bruh!")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Vapok Gaming")] [assembly: AssemblyProduct("ShieldMeBruh")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("997CB563-FCC7-44B7-8F71-069747D27CC5")] [assembly: AssemblyFileVersion("1.1.5.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.5.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 ShieldMeBruh { [BepInPlugin("vapok.mods.shieldmebruh", "Shield Me Bruh!", "1.1.5")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class ShieldMeBruh : BaseUnityPlugin, IPluginInfo { public class Waiting { public event EventHandler StatusChanged; public void ValheimIsAwake(bool awakeFlag) { if (awakeFlag) { this.StatusChanged?.Invoke(this, EventArgs.Empty); } } } private const string _pluginId = "vapok.mods.shieldmebruh"; private const string _displayName = "Shield Me Bruh!"; private const string _version = "1.1.5"; public static bool ValheimAwake; public static Waiting Waiter; private static ShieldMeBruh _instance; private static ConfigSyncBase _config; private static ILogIt _log; private Harmony _harmony; public static ShieldMeBruh m_instance; public static ILogIt Log => _log; public static AutoShield AutoShield { get; private set; } public string PluginId => "vapok.mods.shieldmebruh"; public string DisplayName => "Shield Me Bruh!"; public string Version => "1.1.5"; public BaseUnityPlugin Instance => (BaseUnityPlugin)(object)_instance; [UsedImplicitly] private void Awake() { //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown m_instance = (_instance = this); Waiter = new Waiting(); CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); LogManager.Init(PluginId, out _log); Initializer.LoadManagers(localization); _config = new ConfigRegistry(_instance); Localizer.Waiter.StatusChanged += InitializeModule; AutoShield = new AutoShield(); AutoShield.FeatureInitialized = true; AutoShield.ResetEvent.OnResetEvent += delegate { ResetAutoSheild(); }; _harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); _harmony.PatchAll(Assembly.GetExecutingAssembly()); } private void Start() { AutoShield.LoadAssets(); } private void Update() { if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { Object.op_Implicit((Object)(object)ZNetScene.instance); } } private void ResetAutoSheild() { AutoShield.ResetAutoShieldOnPlayerAwake(); } private void OnDestroy() { _instance = null; AutoShield = null; } public void InitializeModule(object send, EventArgs args) { if (!ValheimAwake) { ConfigRegistry.Waiter.ConfigurationComplete(configDone: true); ValheimAwake = true; } } } } namespace ShieldMeBruh.Patches { public static class DeathEvent { [HarmonyPatch(typeof(Player), "OnDeath")] private static class OnDeathEventPatch { [UsedImplicitly] private static void Postfix(bool __runOriginal) { if (__runOriginal) { ShieldMeBruh.AutoShield.SetShieldStatus(statusSetTo: false); DeathInProgress = true; ShieldMeBruh.Log.Debug($"DEATH EVENT: DeathInProgress: {DeathInProgress}"); } } } [HarmonyPatch(typeof(TombStone), "OnTakeAllSuccess")] private static class TombstoneTakeAllEventPatch { [UsedImplicitly] private static void Postfix(TombStone __instance, bool __runOriginal) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Invalid comparison between Unknown and I4 //IL_0189: Unknown result type (might be due to invalid IL or missing references) DeathInProgress = false; if ((Object)(object)Game.instance == (Object)null || (Object)(object)__instance == (Object)null) { return; } Player localPlayer = default(Player); int num; if (__instance.IsOwner()) { localPlayer = Player.m_localPlayer; num = ((localPlayer != null) ? 1 : 0); } else { num = 0; } if (((uint)num & (__runOriginal ? 1u : 0u)) == 0) { return; } PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); string text = ((playerProfile != null) ? playerProfile.GetName() : null); if (text == null || (Object)(object)__instance.m_container == (Object)null || !__instance.m_container.m_name.Equals(text)) { return; } Vector2i savedElement = ShieldMeBruh.AutoShield.GetShieldSaveData().SavedElement; ShieldMeBruh.Log.Debug($"DEATH EVENT: SavedElement: {savedElement}"); if (savedElement.x < 0 || savedElement.y < 0) { return; } ItemData itemAt = ((Humanoid)localPlayer).GetInventory().GetItemAt(savedElement.x, savedElement.y); if (((Humanoid)localPlayer).GetInventory() == null) { return; } Element val = null; if ((Object)(object)ShieldMeBruh.AutoShield.GetActiveInstance() == (Object)null) { if (ShieldMeBruh.AutoShield.CurrentElement != null) { val = ShieldMeBruh.AutoShield.CurrentElement; ShieldMeBruh.Log.Debug($"DEATH EVENT: CurrentElement SavedElement: {val.m_pos}"); } } else { val = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(savedElement.x, savedElement.y, ((Humanoid)localPlayer).GetInventory().m_width); ShieldMeBruh.Log.Debug($"DEATH EVENT: From Inventory SavedElement: {val.m_pos}"); } if (val != null && itemAt != null && (int)itemAt.m_shared.m_itemType == 5) { ShieldMe shieldFromElement = ShieldMe.GetShieldFromElement(val.m_pos); ShieldMeBruh.Log.Debug("DEATH EVENT: Getting Shield: " + ((Object)shieldFromElement).name); shieldFromElement.ApplyShieldToElement(itemAt); } } } public static bool DeathInProgress; } public class FejdStartupPatches { [HarmonyPatch(typeof(FejdStartup), "Awake")] [HarmonyAfter(new string[] { "org.bepinex.helpers.LocalizationManager" })] [HarmonyBefore(new string[] { "org.bepinex.helpers.ItemManager" })] public static class FejdStartupAwakePatch { private static void Prefix() { ShieldMeBruh.Waiter.ValheimIsAwake(awakeFlag: true); } } } public static class Humanoid_Patches { [HarmonyPatch(typeof(Humanoid), "EquipItem")] private static class HumanoidEquipItemPatch { [UsedImplicitly] private static void Postfix(Humanoid __instance, ItemData item, ref bool __result, ItemData ___m_leftItem, bool __runOriginal) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Invalid comparison between Unknown and I4 //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Invalid comparison between Unknown and I4 Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val == null || !ShieldMeBruh.AutoShield.FeatureInitialized || !__runOriginal || !__result || (int)item.m_shared.m_itemType != 3 || ___m_leftItem != null) { return; } if (ShieldMeBruh.AutoShield.SelectedShield != null) { ItemData itemAt = ((Humanoid)val).m_inventory.GetItemAt(ShieldMeBruh.AutoShield.CurrentElement.m_pos.x, ShieldMeBruh.AutoShield.CurrentElement.m_pos.y); if (itemAt != null && (int)itemAt.m_shared.m_itemType == 5) { ((Humanoid)val).EquipItem(itemAt, true); } return; } AutoShieldSaveData shieldSaveData = ShieldMeBruh.AutoShield.GetShieldSaveData(); if (shieldSaveData.SavedElement.x >= 0 && shieldSaveData.SavedElement.y >= 0) { ItemData itemAt2 = ((Humanoid)val).m_inventory.GetItemAt(shieldSaveData.SavedElement.x, shieldSaveData.SavedElement.y); if (itemAt2 != null && (int)itemAt2.m_shared.m_itemType == 5) { ((Humanoid)val).EquipItem(itemAt2, true); } } } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] private static class HumanoidUnequipItemPatch { [UsedImplicitly] private static void Postfix(Humanoid __instance, ItemData item, ItemData ___m_leftItem, bool __runOriginal) { //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Invalid comparison between Unknown and I4 //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Invalid comparison between Unknown and I4 Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val == null || item == null || ___m_leftItem == null || !ShieldMeBruh.AutoShield.FeatureInitialized || !__runOriginal || !ShieldMeBruh.AutoShield.EnableAutoUnequip.Value) { return; } if (ShieldMeBruh.AutoShield.CurrentElement == null && ShieldMeBruh.AutoShield.SelectedShield == null) { AutoShieldSaveData shieldSaveData = ShieldMeBruh.AutoShield.GetShieldSaveData(); if (shieldSaveData.SavedElement.x >= 0 && shieldSaveData.SavedElement.y >= 0) { ItemData itemAt = ((Humanoid)val).m_inventory.GetItemAt(shieldSaveData.SavedElement.x, shieldSaveData.SavedElement.y); if ((int)item.m_shared.m_itemType == 3 && itemAt != null && ___m_leftItem.m_shared.m_name == itemAt.m_shared.m_name && ___m_leftItem == itemAt) { ((Humanoid)val).UnequipItem(itemAt, true); } } } else if (ShieldMeBruh.AutoShield.CurrentElement != null) { ItemData itemAt = ((Humanoid)val).m_inventory.GetItemAt(ShieldMeBruh.AutoShield.CurrentElement.m_pos.x, ShieldMeBruh.AutoShield.CurrentElement.m_pos.y); if ((int)item.m_shared.m_itemType == 3 && ShieldMeBruh.AutoShield.SelectedShield != null && itemAt != null && ___m_leftItem.m_shared.m_name == ShieldMeBruh.AutoShield.SelectedShield.m_shared.m_name && ___m_leftItem == itemAt) { ((Humanoid)val).UnequipItem(itemAt, true); } } } } } public static class InventoryGrid_Patches { [HarmonyPatch(typeof(InventoryGrid), "UpdateGui")] public static class InventoryGridUpdateGuiPatch { [HarmonyPriority(800)] private static void Prefix(InventoryGrid __instance, ref bool __state) { if (ShieldMeBruh.AutoShield.FeatureInitialized && ((Object)__instance).name.Equals("PlayerGrid")) { __state = false; int width = __instance.m_inventory.GetWidth(); int height = __instance.m_inventory.GetHeight(); if (__instance.m_width != width || __instance.m_height != height) { ShieldMeBruh.Log.Debug($"Width {width} doesn't match {__instance.m_width}"); ShieldMeBruh.Log.Debug($"Height {height} doesn't match {__instance.m_height}"); __state = true; } } } [UsedImplicitly] private static void Postfix(InventoryGrid __instance, ref bool __state, bool __runOriginal) { if (!((Object)__instance).name.Equals("PlayerGrid") || !__state || !__runOriginal) { return; } ShieldMeBruh.Log.Debug("Inventory Grid needs to init."); foreach (Element element in __instance.m_elements) { ShieldMe orAddComponent = ExposedGameObjectExtension.GetOrAddComponent(element.m_go); orAddComponent.SetGrid(__instance); orAddComponent.SetElement(element); } } } } public static class InventoryGui_Patches { [HarmonyPatch(typeof(InventoryGui), "Show")] private static class ShowInventoryPatch { [UsedImplicitly] private static void Postfix(InventoryGui __instance, bool __runOriginal) { if (__runOriginal) { ShieldMeBruh.AutoShield.SetActiveInstance(__instance.m_playerGrid); } } } } public static class MoveProtection { [HarmonyPatch(typeof(InventoryGui), "DoCrafting", new Type[] { typeof(Player) })] private static class EnsureCraftingPatches { [UsedImplicitly] private static void Prefix(InventoryGui __instance) { _doingCrafting = true; } [UsedImplicitly] private static void Postfix(InventoryGui __instance) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Invalid comparison between Unknown and I4 _doingCrafting = false; ItemData craftUpgradeItem = __instance.m_craftUpgradeItem; if (craftUpgradeItem != null && (int)craftUpgradeItem.m_shared.m_itemType == 5) { Vector2i gridPos = craftUpgradeItem.m_gridPos; ShieldMe shieldMe = ShieldMe.Elements[gridPos]; ItemData item = shieldMe.GetItem(); if (item == null || (int)item.m_shared.m_itemType != 5 || !shieldMe.ShieldIsActive()) { shieldMe.ResetCurrentSheildElement(); } } } } [HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[] { typeof(Inventory), typeof(ItemData) })] private static class MoveItemPatch { [UsedImplicitly] private static void Prefix(Inventory __instance, Inventory fromInventory, ItemData item) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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) //IL_0092: Unknown result type (might be due to invalid IL or missing references) if (!_movingWithDropItem && (ShieldMeBruh.AutoShield.CurrentElement != null || ShieldMeBruh.AutoShield.SelectedShield != null) && __instance != null && fromInventory != null && item != null && !__instance.m_name.Equals("Inventory")) { Vector2i gridPos = item.m_gridPos; Vector2i? val = ShieldMeBruh.AutoShield.CurrentElement?.m_pos; if (val.HasValue && gridPos == val.GetValueOrDefault()) { ShieldMe.Elements[ShieldMeBruh.AutoShield.CurrentElement.m_pos].ResetCurrentSheildElement(); } } } } [HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[] { typeof(Inventory), typeof(ItemData), typeof(int), typeof(int), typeof(int) })] private static class MoveItemToThisPatch { [UsedImplicitly] private static void Prefix(Inventory __instance, Inventory fromInventory, ItemData item, int x, int y) { if (_movingWithDropItem || (ShieldMeBruh.AutoShield.CurrentElement == null && ShieldMeBruh.AutoShield.SelectedShield == null) || __instance == null || fromInventory == null || item == null || !__instance.m_name.Equals("Inventory")) { return; } if (item != ShieldMeBruh.AutoShield.SelectedShield) { Element element = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(x, y, __instance.m_width); Element element2 = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(item.m_gridPos.x, item.m_gridPos.y, __instance.m_width); ItemData itemAt = __instance.GetItemAt(x, y); if (element == null || element2 == null || itemAt == null || itemAt != ShieldMeBruh.AutoShield.SelectedShield) { return; } _futureElement = element2; _oldElement = element; } else { Element element3 = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(x, y, __instance.m_width); Element element4 = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(item.m_gridPos.x, item.m_gridPos.y, __instance.m_width); if (element3 == null || element4 == null) { return; } _futureElement = element3; _oldElement = element4; } _reEnableShield = true; _movingWithMoveItemToThis = true; } [UsedImplicitly] private static void Postfix(Inventory __instance, Inventory fromInventory, ItemData item, int x, int y, bool __runOriginal) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) if (_movingWithDropItem || !__runOriginal || item == null) { return; } if (_reEnableShield) { ItemData itemAt = __instance.GetItemAt(_futureElement.m_pos.x, _futureElement.m_pos.y); if (itemAt != null && _oldElement != null && _futureElement != null) { ShieldMe.Elements[_oldElement.m_pos].ResetCurrentSheildElement(); ShieldMe.Elements[_futureElement.m_pos].ApplyShieldToElement(itemAt); } _reEnableShield = false; } _oldElement = null; _futureElement = null; _movingWithMoveItemToThis = false; } } [HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[] { typeof(ItemData) })] private static class RemoveItemPatch { [UsedImplicitly] private static void Postfix(Inventory __instance, ItemData item, bool __runOriginal) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Invalid comparison between Unknown and I4 //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) if (item != null && __runOriginal && __instance != null && ShieldMeBruh.AutoShield.CurrentElement != null && ShieldMeBruh.AutoShield.SelectedShield != null && !_movingWithDropItem && !_movingWithMoveItemToThis && !_doingCrafting) { if (DeathEvent.DeathInProgress) { ShieldMeBruh.Log.Debug($"RemoveItemPatch: DeathInProgress: {DeathEvent.DeathInProgress}"); } else if ((int)item.m_shared.m_itemType == 5 && !(item.m_gridPos != ShieldMeBruh.AutoShield.CurrentElement.m_pos)) { ShieldMeBruh.Log.Debug("RemoveItemPatch: Removing an Item Start"); ShieldMe.Elements[ShieldMeBruh.AutoShield.CurrentElement.m_pos].ResetCurrentSheildElement(); ShieldMeBruh.Log.Debug("RemoveItemPatch: Removing an Item Finished"); } } } } [HarmonyPatch(typeof(InventoryGrid), "DropItem", new Type[] { typeof(Inventory), typeof(ItemData), typeof(int), typeof(Vector2i) })] private static class DropItemPatch { [UsedImplicitly] private static void Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, int amount, Vector2i pos) { //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) if (item == null || (Object)(object)__instance == (Object)null || ShieldMeBruh.AutoShield.SelectedShield == null || (Object)(object)ShieldMeBruh.AutoShield.GetActiveInstance() == (Object)null || !((Object)__instance).name.Equals("PlayerGrid")) { return; } ShieldMeBruh.Log.Debug("DropItemPatch: Dropping an Item Start"); if (item != ShieldMeBruh.AutoShield.SelectedShield) { Element element = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(pos.x, pos.y, __instance.m_width); Element element2 = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(item.m_gridPos.x, item.m_gridPos.y, __instance.m_width); ItemData itemAt = __instance.m_inventory.GetItemAt(pos.x, pos.y); if (element == null || element2 == null || itemAt == null || itemAt != ShieldMeBruh.AutoShield.SelectedShield) { return; } _futureElement = element2; _oldElement = element; } else { Element element3 = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(pos.x, pos.y, __instance.m_width); Element element4 = ShieldMeBruh.AutoShield.GetActiveInstance().GetElement(item.m_gridPos.x, item.m_gridPos.y, __instance.m_width); if (element3 == null || element4 == null) { return; } _futureElement = element3; _oldElement = element4; } _reEnableShieldOnDropItem = true; _movingWithDropItem = true; ShieldMeBruh.Log.Debug("DropItemPatch: Dropping an Item Finished"); } [UsedImplicitly] private static void Postfix(InventoryGrid __instance, Inventory fromInventory, ItemData item, int amount, Vector2i pos, ref bool __result, bool __runOriginal) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) if (!__result || !__runOriginal) { _reEnableShieldOnDropItem = false; _oldElement = null; _futureElement = null; _movingWithDropItem = false; return; } if (_reEnableShieldOnDropItem) { ItemData itemAt = __instance.m_inventory.GetItemAt(_futureElement.m_pos.x, _futureElement.m_pos.y); if (itemAt != null && _oldElement != null && _futureElement != null) { ShieldMe.Elements[ShieldMeBruh.AutoShield.CurrentElement.m_pos].ResetCurrentSheildElement(); ShieldMe.Elements[_futureElement.m_pos].ApplyShieldToElement(itemAt); } _reEnableShieldOnDropItem = false; } _oldElement = null; _futureElement = null; _movingWithDropItem = false; } } private static bool _reEnableShield; private static bool _movingWithMoveItemToThis; private static bool _movingWithDropItem; private static bool _reEnableShieldOnDropItem; private static bool _doingCrafting; private static Element _futureElement; private static Element _oldElement; } public static class Player_Patches { [HarmonyPatch(typeof(Player), "SetLocalPlayer")] private static class HumanoidEquipItemPatch { [UsedImplicitly] private static void Postfix(Player __instance) { AutoShield.ResetEvent.PerformReset(__instance); } } } } namespace ShieldMeBruh.Features { public class AutoShieldSaveData { public Vector2i SavedElement { get; set; } public string ItemName { get; set; } } public class AutoShield { public static class ResetEvent { public static event EventHandler OnResetEvent; public static void PerformReset(Player player) { if (!((Object)(object)Player.m_localPlayer == (Object)null)) { ((Humanoid)player).UnequipItem(((Humanoid)player).m_rightItem, false); ((Humanoid)player).UnequipItem(((Humanoid)player).m_leftItem, false); ResetEvent.OnResetEvent?.Invoke(ShieldMeBruh.AutoShield, EventArgs.Empty); } } } private InventoryGrid _activeInstance; public Sprite Shield; public Element CurrentElement; public bool FeatureInitialized; public ItemData SelectedShield; public ConfigEntry EnableAutoShield; public ConfigEntry EnableAutoUnequip; public AutoShield() { ConfigRegistry.Waiter.StatusChanged += delegate { RegisterConfigurationFile(); }; } public void LoadAssets() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) string text = "ShieldMeBruh.Resources"; Shield = LoadSprite(text + ".shield.png", new Rect(0f, 0f, 1024f, 1024f)); } public void SetActiveInstance(InventoryGrid instance) { _activeInstance = instance; } public InventoryGrid GetActiveInstance() { return _activeInstance; } private void RegisterConfigurationFile() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown ConfigSyncBase.UnsyncedConfig("Local Config", "Enable Auto Shield", value: true, new ConfigDescription("When enabled, selected shield will automatically equip when a one handed weapon is equipped.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { Order = 1 } }), ref EnableAutoShield); EnableAutoShield.SettingChanged += delegate { SetEnabledStatus(); }; ConfigSyncBase.UnsyncedConfig("Local Config", "Enable Auto Unequip", value: true, new ConfigDescription("When enabled, when one handed weapon is unequipped, the marked equipped shield, will also unequip.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { Order = 1 } }), ref EnableAutoUnequip); } public static Texture2D LoadImage(byte[] bytes) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown Texture2D val = new Texture2D(2, 2); if (!(bool)AccessTools.Method(typeof(ImageConversion), "LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }, (Type[])null).Invoke(null, new object[2] { val, bytes })) { throw new Exception("Failed to load image data into texture from byte array"); } return val; } public Sprite LoadSprite(string path, Rect size, Vector2? pivot = null, int units = 100) { //IL_0015: 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_0058: Unknown result type (might be due to invalid IL or missing references) if (!pivot.HasValue) { pivot = new Vector2(0.5f, 0.5f); } Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path); Texture2D obj = LoadImage(ReadToEnd(manifestResourceStream)); if ((Object)(object)obj == (Object)null) { ShieldMeBruh.Log.Error("Missing Embedded Resource: " + path); } return Sprite.Create(obj, size, pivot.Value, (float)units, 0u, (SpriteMeshType)1); } private byte[] ReadToEnd(Stream stream) { long position = stream.Position; stream.Position = 0L; try { byte[] array = new byte[4096]; int num = 0; int num2; while ((num2 = stream.Read(array, num, array.Length - num)) > 0) { num += num2; if (num == array.Length) { int num3 = stream.ReadByte(); if (num3 != -1) { byte[] array2 = new byte[array.Length * 2]; Buffer.BlockCopy(array, 0, array2, 0, array.Length); Buffer.SetByte(array2, num, (byte)num3); array = array2; num++; } } } byte[] array3 = array; if (array.Length != num) { array3 = new byte[num]; Buffer.BlockCopy(array, 0, array3, 0, num); } return array3; } finally { stream.Position = position; } } public void SetShieldStatus(bool statusSetTo) { FeatureInitialized = EnableAutoShield.Value; if (!EnableAutoShield.Value) { return; } if (statusSetTo) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null && CurrentElement != null && SelectedShield != null && ((Humanoid)localPlayer).GetInventory().GetItemAt(CurrentElement.m_pos.x, CurrentElement.m_pos.y) != SelectedShield) { statusSetTo = false; } } if (CurrentElement != null) { ((Behaviour)CurrentElement.GetShield()).enabled = statusSetTo; } } public void SetEnabledStatus() { FeatureInitialized = EnableAutoShield.Value; } public void ResetAutoShieldOnPlayerAwake() { if (!DeathEvent.DeathInProgress) { ShieldMeBruh.Log.Debug("Resetting Player Context"); _activeInstance = null; CurrentElement = null; SelectedShield = null; } } public AutoShieldSaveData GetShieldSaveData() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) AutoShieldSaveData result = new AutoShieldSaveData { SavedElement = new Vector2i(-1, -1) }; if (Player.m_localPlayer.m_customData.ContainsKey(ShieldMeBruh.m_instance.PluginId)) { result = new DeserializerBuilder().Build().Deserialize(Player.m_localPlayer.m_customData[ShieldMeBruh.m_instance.PluginId]); } return result; } } } namespace ShieldMeBruh.Extensions { public static class ElementExtensions { public static Image GetShield(this Element _mElement) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return ShieldMe.Elements[_mElement.m_pos]?.GetShield(); } public static Image CreateShield(this Element _mElement) { ShieldMeBruh.Log.Debug("Shield Element: " + ((Object)_mElement.m_go.transform).name); Image obj = _mElement.CreateShieldedImage(); ((Behaviour)obj).enabled = false; return obj; } public static Image CreateShieldedImage(this Element _mElement) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) Image icon = _mElement.m_icon; Image noteleport = _mElement.m_noteleport; Image obj = Object.Instantiate(icon, ((Component)icon).transform.parent); ((Object)((Component)obj).transform).name = "shield"; obj.sprite = ShieldMeBruh.AutoShield.Shield; ((Object)obj).name = "shield"; ((Graphic)obj).color = ((Graphic)noteleport).color; obj.type = noteleport.type; return obj; } } } namespace ShieldMeBruh.Configuration { public class ConfigRegistry : ConfigSyncBase { public static Waiting Waiter; public ConfigRegistry(IPluginInfo mod, bool enableLockedConfigs = false) : base(mod, enableLockedConfigs) { Waiter = new Waiting(); InitializeConfigurationSettings(); } public sealed override void InitializeConfigurationSettings() { _ = ConfigSyncBase._config; } } public class Waiting { public event EventHandler StatusChanged; public void ConfigurationComplete(bool configDone) { if (configDone) { this.StatusChanged?.Invoke(this, EventArgs.Empty); } } } } namespace ShieldMeBruh.Components { public class ShieldMe : MonoBehaviour { public static readonly Dictionary Elements = new Dictionary(); private Element _mElement; private InventoryGrid _mGrid; private UIInputHandler _mInputHandler; private ItemData _mItem; private Image _shieldImage; private bool _active; private GameObject _shieldGo; private void Awake() { ShieldMeBruh.Log.Debug("ShieldMe Element Awake"); } private void Start() { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) ShieldMeBruh.Log.Debug("ShieldMe Element Started"); _shieldImage = _mElement.CreateShield(); _shieldGo = ((Component)_shieldImage).gameObject; ShieldMeBruh.Log.Debug("Loaded GameObject: " + ((Object)_shieldGo).name + " Transform: " + ((Object)_shieldGo.transform).name); Vector2i savedElement = ShieldMeBruh.AutoShield.GetShieldSaveData().SavedElement; if (!(_mElement.m_pos != savedElement)) { _mItem = _mGrid.m_inventory.GetItemAt(_mElement.m_pos.x, _mElement.m_pos.y); ShieldMeBruh.Log.Debug($"_mItem is null: {_mItem == null}"); ApplyShieldToElement(); ((MonoBehaviour)this).InvokeRepeating("UpdateShield", 1f, 1f); } } private void UpdateShield() { if (_active && !((Behaviour)_shieldImage).enabled) { _mItem = _mGrid.m_inventory.GetItemAt(_mElement.m_pos.x, _mElement.m_pos.y); RefreshShield(); } } public static ShieldMe GetShieldFromElement(Vector2i pos) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return Elements[pos]; } public void SetElement(Element element) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) _mElement = element; if (!Elements.ContainsKey(element.m_pos)) { Elements.Add(element.m_pos, this); } _mInputHandler = ((Component)this).gameObject.GetComponentInChildren(); UIInputHandler mInputHandler = _mInputHandler; mInputHandler.m_onMiddleDown = (Action)Delegate.Combine(mInputHandler.m_onMiddleDown, new Action(OnMiddleClick)); ShieldMeBruh.Log.Debug($"Adding to element: X: {_mElement.m_pos.x} Y: {_mElement.m_pos.y}"); } public void SetGrid(InventoryGrid inventoryGrid) { _mGrid = inventoryGrid; } public Image GetShield() { if (!Object.op_Implicit((Object)(object)_shieldImage)) { _shieldImage = _shieldGo.GetComponent(); } return _shieldImage; } public ItemData GetItem() { return _mItem; } public bool ShieldIsActive() { return _active; } public void ApplyShieldToElement(ItemData itemOverride = null, bool allowReset = false) { //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Invalid comparison between Unknown and I4 //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) ShieldMeBruh.Log.Debug($"ApplyShieldToElement called on Grid Element {_mElement.m_pos.x},{_mElement.m_pos.y}"); ShieldMeBruh.Log.Debug($"_mItem is null: {_mItem == null}"); if (_mItem == null) { _mItem = _mGrid.m_inventory.GetItemAt(_mElement.m_pos.x, _mElement.m_pos.y); } ItemData val = ((itemOverride != null) ? itemOverride : _mItem); ShieldMeBruh.Log.Debug($"selectedItem is null: {val == null}"); ShieldMeBruh.Log.Debug($"_shieldImage is null: {!Object.op_Implicit((Object)(object)_shieldImage)}"); ShieldMeBruh.Log.Debug("SelectedItem: " + val?.m_shared.m_name); ShieldMeBruh.Log.Debug($"_mItem is null: {_mItem == null}"); if (val != null && (int)val.m_shared.m_itemType == 5) { ((Behaviour)_shieldImage).enabled = true; if (ShieldMeBruh.AutoShield.CurrentElement == null) { ShieldMeBruh.AutoShield.CurrentElement = _mElement; ShieldMeBruh.AutoShield.SelectedShield = val; } else if ((ShieldMeBruh.AutoShield.CurrentElement.m_pos == _mElement.m_pos && allowReset) || _mElement.m_pos.x < 0 || _mElement.m_pos.y < 0) { ((Behaviour)_shieldImage).enabled = false; ShieldMeBruh.AutoShield.CurrentElement = null; ShieldMeBruh.AutoShield.SelectedShield = null; } else { ShieldMeBruh.AutoShield.CurrentElement = _mElement; ShieldMeBruh.AutoShield.SelectedShield = val; } Vector2i savedElement = default(Vector2i); ((Vector2i)(ref savedElement))..ctor(-1, -1); if (ShieldMeBruh.AutoShield.CurrentElement != null) { ((Vector2i)(ref savedElement))..ctor(_mElement.m_pos.x, _mElement.m_pos.y); } AutoShieldSaveData autoShieldSaveData = new AutoShieldSaveData(); autoShieldSaveData.SavedElement = savedElement; SaveShieldSaveData(autoShieldSaveData); _active = true; RefreshShield(); ShieldMeBruh.Log.Debug($"ApplyShieldToElement fished on Grid Element {_mElement.m_pos.x},{_mElement.m_pos.y}"); ShieldMeBruh.Log.Debug($"CurrentElement: [{ShieldMeBruh.AutoShield.CurrentElement?.m_pos.x},{ShieldMeBruh.AutoShield.CurrentElement?.m_pos.y}]"); ShieldMeBruh.Log.Debug("SelectedItem: [" + ShieldMeBruh.AutoShield.SelectedShield?.m_shared.m_name + "]"); } } private void SaveShieldSaveData(AutoShieldSaveData savedData) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) string value = new SerializerBuilder().Build().Serialize((object)savedData); Player.m_localPlayer.m_customData[ShieldMeBruh.m_instance.PluginId] = value; } private void OnMiddleClick(UIInputHandler middleClick) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Invalid comparison between Unknown and I4 //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) if (!ShieldMeBruh.AutoShield.FeatureInitialized || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)_mGrid == (Object)null || (Object)(object)middleClick == (Object)null || (Object)(object)((Component)middleClick).gameObject == (Object)null) { return; } Player localPlayer = Player.m_localPlayer; Vector2i pos = _mElement.m_pos; ShieldMeBruh.Log.Debug($"Button Pressed on {pos.x},{pos.y}"); _mItem = _mGrid.m_inventory.GetItemAt(pos.x, pos.y); if (_mItem == null) { return; } ShieldMeBruh.Log.Debug($"Item Name {_mItem.m_shared.m_name} of type {_mItem.m_shared.m_itemType}"); if ((int)_mItem.m_shared.m_itemType != 5) { return; } Vector2i val = default(Vector2i); ((Vector2i)(ref val))..ctor(pos.x, pos.y); if (ShieldMeBruh.AutoShield.CurrentElement == null) { ApplyShieldToElement(null, allowReset: true); } else if (ShieldMeBruh.AutoShield.CurrentElement.m_pos == val) { ResetCurrentSheildElement(); } else if (ShieldMeBruh.AutoShield.CurrentElement.m_pos != val) { ItemData itemAt = _mGrid.GetInventory().GetItemAt(ShieldMeBruh.AutoShield.CurrentElement.m_pos.x, ShieldMeBruh.AutoShield.CurrentElement.m_pos.y); ItemData mItem = _mItem; Elements[ShieldMeBruh.AutoShield.CurrentElement.m_pos].ResetCurrentSheildElement(); ApplyShieldToElement(null, allowReset: true); if (itemAt != null && itemAt.m_equipped) { ((Humanoid)localPlayer).EquipItem(mItem, true); } } } public void ResetCurrentSheildElement() { //IL_0157: Unknown result type (might be due to invalid IL or missing references) ShieldMeBruh.Log.Debug($"ResetCurrentShieldElement called on Grid Element {_mElement.m_pos.x},{_mElement.m_pos.y}"); ShieldMeBruh.Log.Debug($"CurrentElement Grid Element {ShieldMeBruh.AutoShield.CurrentElement?.m_pos.x},{ShieldMeBruh.AutoShield.CurrentElement?.m_pos.y}"); ShieldMeBruh.Log.Debug($"Current Shield Status: {((UIBehaviour)GetShield()).IsActive()}"); ShieldMeBruh.Log.Debug("Start SelectedItem: [" + ShieldMeBruh.AutoShield.SelectedShield?.m_shared.m_name + "]"); ShieldMeBruh.Log.Debug($"Active: [{_active}]"); if (_active) { ((Behaviour)_shieldImage).enabled = false; ShieldMeBruh.AutoShield.CurrentElement = null; ShieldMeBruh.AutoShield.SelectedShield = null; AutoShieldSaveData autoShieldSaveData = new AutoShieldSaveData(); autoShieldSaveData.SavedElement = new Vector2i(-1, -1); SaveShieldSaveData(autoShieldSaveData); _active = false; ShieldMeBruh.Log.Debug($"ResetCurrentShieldElement Finished Grid Element {_mElement.m_pos.x},{_mElement.m_pos.y}"); ShieldMeBruh.Log.Debug($"CurrentElement Grid Element {ShieldMeBruh.AutoShield.CurrentElement?.m_pos.x},{ShieldMeBruh.AutoShield.CurrentElement?.m_pos.y}"); ShieldMeBruh.Log.Debug($"Current Shield Status: {((UIBehaviour)GetShield()).IsActive()}"); ShieldMeBruh.Log.Debug("End SelectedItem: [" + ShieldMeBruh.AutoShield.SelectedShield?.m_shared.m_name + "]"); } } public void RefreshShield() { //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) Element currentElement = ShieldMeBruh.AutoShield.CurrentElement; ShieldMeBruh.Log.Debug($"RefreshShield: currentElement is null: {currentElement == null}"); ShieldMeBruh.Log.Debug($"RefreshShield: _mElement is null: {_mElement == null}"); ShieldMeBruh.Log.Debug($"RefreshShield: _shieldImage is null: {(Object)(object)_shieldImage == (Object)null}"); ShieldMeBruh.Log.Debug($"RefreshShield: _active: {_active}"); ShieldMeBruh.Log.Debug($"RefreshShield: _mItem == null: {_mItem == null}"); Image shield = GetShield(); if (!_active || _mElement == null) { ((Behaviour)shield).enabled = false; return; } _mItem = _mGrid.m_inventory.GetItemAt(_mElement.m_pos.x, _mElement.m_pos.y); if (_mItem == null) { ((Behaviour)shield).enabled = false; } else if (ShieldMeBruh.AutoShield.FeatureInitialized) { Vector2i? val = _mElement?.m_pos; Vector2i? val2 = currentElement?.m_pos; if (val.HasValue == val2.HasValue && (!val.HasValue || val.GetValueOrDefault() == val2.GetValueOrDefault())) { ((Behaviour)shield).enabled = true; } else { ((Behaviour)shield).enabled = false; } ShieldMeBruh.Log.Debug($"RefreshShield: Shield Enabled1: {((Behaviour)shield).enabled}"); } else { if (currentElement != null) { ((Behaviour)shield).enabled = false; } ShieldMeBruh.Log.Debug($"RefreshShield: Shield Enabled2: {((Behaviour)shield).enabled}"); } } } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace ItemManager { [PublicAPI] internal enum CraftingTable { Disabled, Inventory, [InternalName("piece_workbench")] Workbench, [InternalName("piece_cauldron")] Cauldron, [InternalName("forge")] Forge, [InternalName("piece_artisanstation")] ArtisanTable, [InternalName("piece_stonecutter")] StoneCutter, [InternalName("piece_magetable")] MageTable, [InternalName("blackforge")] BlackForge, [InternalName("piece_preptable")] FoodPreparationTable, [InternalName("piece_MeadCauldron")] MeadKetill, Custom } [PublicAPI] internal enum ConversionPiece { Disabled, [InternalName("smelter")] Smelter, [InternalName("charcoal_kiln")] CharcoalKiln, [InternalName("blastfurnace")] BlastFurnace, [InternalName("windmill")] Windmill, [InternalName("piece_spinningwheel")] SpinningWheel, [InternalName("eitrrefinery")] EitrRefinery, Custom } internal class InternalName : Attribute { public readonly string internalName; public InternalName(string internalName) { this.internalName = internalName; } } [PublicAPI] internal class RequiredResourceList { public readonly List Requirements = new List(); public bool Free; public void Add(string itemName, int amount, int quality = 0) { Requirements.Add(new Requirement { itemName = itemName, amount = amount, quality = quality }); } public void Add(string itemName, ConfigEntry amountConfig, int quality = 0) { Requirements.Add(new Requirement { itemName = itemName, amountConfig = amountConfig, quality = quality }); } } [PublicAPI] internal class CraftingStationList { public readonly List Stations = new List(); public void Add(CraftingTable table, int level) { Stations.Add(new CraftingStationConfig { Table = table, level = level }); } public void Add(string customTable, int level) { Stations.Add(new CraftingStationConfig { Table = CraftingTable.Custom, level = level, custom = customTable }); } } [PublicAPI] internal class ItemRecipe { public readonly RequiredResourceList RequiredItems = new RequiredResourceList(); public readonly RequiredResourceList RequiredUpgradeItems = new RequiredResourceList(); public readonly CraftingStationList Crafting = new CraftingStationList(); public int CraftAmount = 1; public bool RequireOnlyOneIngredient; public float QualityResultAmountMultiplier = 1f; public ConfigEntryBase? RecipeIsActive; } [PublicAPI] internal class Trade { public Trader Trader; public uint Price; public uint Stack = 1u; public string? RequiredGlobalKey; } [PublicAPI] [Flags] internal enum Trader { None = 0, Haldor = 1, Hildir = 2 } internal struct Requirement { public string itemName; public int amount; public ConfigEntry? amountConfig; [Description("Set to a non-zero value to apply the requirement only for a specific quality")] public int quality; } internal struct CraftingStationConfig { public CraftingTable Table; public int level; public string? custom; } [Flags] internal enum Configurability { Disabled = 0, Recipe = 1, Stats = 2, Drop = 4, Trader = 8, Full = 0xF } [PublicAPI] internal class DropTargets { public readonly List Drops = new List(); public void Add(string creatureName, float chance, int min = 1, int? max = null, bool levelMultiplier = true) { Drops.Add(new DropTarget { creature = creatureName, chance = chance, min = min, max = max.GetValueOrDefault(min), levelMultiplier = levelMultiplier }); } } internal struct DropTarget { public string creature; public int min; public int max; public float chance; public bool levelMultiplier; } internal enum Toggle { On = 1, Off = 0 } [PublicAPI] internal class Item { private class ItemConfig { public ConfigEntry? craft; public ConfigEntry? upgrade; public ConfigEntry table; public ConfigEntry tableLevel; public ConfigEntry customTable; public ConfigEntry? maximumTableLevel; public ConfigEntry requireOneIngredient; public ConfigEntry qualityResultAmountMultiplier; } private class TraderConfig { public ConfigEntry trader; public ConfigEntry price; public ConfigEntry stack; public ConfigEntry requiredGlobalKey; } private class RequirementQuality { public int quality; } private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [UsedImplicitly] public string? Category; [UsedImplicitly] public Action? CustomDrawer; public Func? browsability; } [PublicAPI] public enum DamageModifier { Normal, Resistant, Weak, Immune, Ignore, VeryResistant, VeryWeak, None } private delegate void setDmgFunc(ref DamageTypes dmg, float value); private class SerializedRequirements { public readonly List Reqs; public SerializedRequirements(List reqs) { Reqs = reqs; } public SerializedRequirements(string reqs) : this(reqs.Split(new char[1] { ',' }).Select(delegate(string r) { string[] array = r.Split(new char[1] { ':' }); Requirement result = default(Requirement); result.itemName = array[0]; result.amount = ((array.Length <= 1 || !int.TryParse(array[1], out var result2)) ? 1 : result2); result.quality = ((array.Length > 2 && int.TryParse(array[2], out var result3)) ? result3 : 0); return result; }).ToList()) { } public override string ToString() { return string.Join(",", Reqs.Select((Requirement r) => $"{r.itemName}:{r.amount}")); } public static ItemDrop? fetchByName(ObjectDB objectDB, string name) { GameObject itemPrefab = objectDB.GetItemPrefab(name); ItemDrop obj = ((itemPrefab != null) ? itemPrefab.GetComponent() : null); if ((Object)(object)obj == (Object)null) { LogManager.Log.Warning("The required item '" + name + "' does not exist."); } return obj; } public static Requirement[] toPieceReqs(ObjectDB objectDB, SerializedRequirements craft, SerializedRequirements upgrade) { //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Expected O, but got Unknown //IL_0194: Expected O, but got Unknown //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Expected O, but got Unknown ObjectDB objectDB2 = objectDB; Dictionary dictionary = craft.Reqs.Where((Requirement r) => r.itemName != "").ToDictionary((Func)((Requirement r) => r.itemName), (Func)delegate(Requirement r) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown ItemDrop val6 = ResItem(r); return (val6 != null) ? new Requirement { m_amount = (r.amountConfig?.Value ?? r.amount), m_resItem = val6, m_amountPerLevel = 0 } : ((Requirement)null); }); List list = dictionary.Values.Where((Requirement v) => v != null).ToList(); foreach (Requirement item in upgrade.Reqs.Where((Requirement r) => r.itemName != "")) { if (item.quality > 0) { ItemDrop val = ResItem(item); if (val != null) { Requirement val2 = new Requirement { m_resItem = val, m_amountPerLevel = (item.amountConfig?.Value ?? item.amount), m_amount = 0 }; list.Add(val2); requirementQuality.Add(val2, new RequirementQuality { quality = item.quality }); } continue; } if (!dictionary.TryGetValue(item.itemName, out var value) || value == null) { ItemDrop val3 = ResItem(item); if (val3 != null) { string itemName = item.itemName; Requirement val4 = new Requirement { m_resItem = val3, m_amount = 0 }; Requirement val5 = val4; dictionary[itemName] = val4; value = val5; list.Add(value); } } if (value != null) { value.m_amountPerLevel = item.amountConfig?.Value ?? item.amount; } } return list.ToArray(); ItemDrop? ResItem(Requirement r) { return fetchByName(objectDB2, r.itemName); } } } private class SerializedDrop { public readonly List Drops; public SerializedDrop(List drops) { Drops = drops; } public SerializedDrop(string drops) { Drops = ((drops == "") ? ((IEnumerable)Array.Empty()) : ((IEnumerable)drops.Split(new char[1] { ',' }))).Select(delegate(string r) { string[] array = r.Split(new char[1] { ':' }); if (array.Length <= 2 || !int.TryParse(array[2], out var result)) { result = 1; } if (array.Length <= 3 || !int.TryParse(array[3], out var result2)) { result2 = result; } bool levelMultiplier = array.Length <= 4 || array[4] != "0"; DropTarget result3 = default(DropTarget); result3.creature = array[0]; result3.chance = ((array.Length > 1 && float.TryParse(array[1], out var result4)) ? result4 : 1f); result3.min = result; result3.max = result2; result3.levelMultiplier = levelMultiplier; return result3; }).ToList(); } public override string ToString() { return string.Join(",", Drops.Select((DropTarget r) => $"{r.creature}:{r.chance.ToString(CultureInfo.InvariantCulture)}:{r.min}:" + ((r.min == r.max) ? "" : $"{r.max}") + (r.levelMultiplier ? "" : ":0"))); } private static Character? fetchByName(ZNetScene netScene, string name) { GameObject prefab = netScene.GetPrefab(name); Character obj = ((prefab != null) ? prefab.GetComponent() : null); if ((Object)(object)obj == (Object)null) { LogManager.Log.Debug("The drop target character '" + name + "' does not exist."); } return obj; } public Dictionary toCharacterDrops(ZNetScene netScene, GameObject item) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown Dictionary dictionary = new Dictionary(); foreach (DropTarget drop in Drops) { Character val = fetchByName(netScene, drop.creature); if (val != null) { dictionary[val] = new Drop { m_prefab = item, m_amountMin = drop.min, m_amountMax = drop.max, m_chance = drop.chance, m_levelMultiplier = drop.levelMultiplier }; } } return dictionary; } } [CompilerGenerated] private sealed class <>c__DisplayClass81_0 { public Quaternion? cameraRotation; public float lightIntensity; public ItemDrop item; public Quaternion? itemRotation; } [CompilerGenerated] private sealed class d__83 : IEnumerable, IEnumerable, IEnumerator, IDisposable, IEnumerator { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private IEnumerable instructions; public IEnumerable <>3__instructions; private List 5__2; private FieldInfo 5__3; private int 5__4; CodeInstruction IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__83(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { 5__2 = null; 5__3 = null; <>1__state = -2; } private bool MoveNext() { //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Expected O, but got Unknown //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Expected O, but got Unknown //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown int num; switch (<>1__state) { default: return false; case 0: <>1__state = -1; 5__2 = instructions.ToList(); 5__3 = AccessTools.DeclaredField(typeof(Recipe), "m_amount"); 5__4 = 0; break; case 1: <>1__state = -1; if (5__4 > 1 && 5__2[5__4 - 2].opcode == OpCodes.Ldfld && CodeInstructionExtensions.OperandIs(5__2[5__4 - 2], (MemberInfo)5__3) && 5__2[5__4 - 1].opcode == OpCodes.Ldc_I4_1 && 5__2[5__4].operand is Label) { <>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null); <>1__state = 2; return true; } goto IL_01b2; case 2: <>1__state = -1; <>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(Item), "CheckItemIsUpgrade", (Type[])null, (Type[])null)); <>1__state = 3; return true; case 3: <>1__state = -1; <>2__current = new CodeInstruction(OpCodes.Brtrue, 5__2[5__4].operand); <>1__state = 4; return true; case 4: { <>1__state = -1; goto IL_01b2; } IL_01b2: num = 5__4 + 1; 5__4 = num; break; } if (5__4 < 5__2.Count) { <>2__current = 5__2[5__4]; <>1__state = 1; return true; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { d__83 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__83(0); } d__.instructions = <>3__instructions; return d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } private static bool _initialized = false; private static readonly List registeredItems = new List(); private static readonly Dictionary itemDropMap = new Dictionary(); private static Dictionary>> activeRecipes = new Dictionary>>(); private static Dictionary hiddenCraftRecipes = new Dictionary(); private static Dictionary hiddenUpgradeRecipes = new Dictionary(); private static Dictionary> itemCraftConfigs = new Dictionary>(); private static Dictionary> itemDropConfigs = new Dictionary>(); private static Dictionary> itemDropEnabledConfig = new Dictionary>(); private Dictionary characterDrops = new Dictionary(); private readonly Dictionary statsConfigs = new Dictionary(); private static readonly ConditionalWeakTable requirementQuality = new ConditionalWeakTable(); public string SectionName = string.Empty; public static Configurability DefaultConfigurability = Configurability.Full; public Configurability? Configurable; private Configurability configurationVisible = Configurability.Full; private TraderConfig? traderConfig; public readonly GameObject Prefab; [Description("Specifies the maximum required crafting station level to upgrade and repair the item.\nDefault is calculated from crafting station level and maximum quality.")] public int MaximumRequiredStationLevel = int.MaxValue; [Description("Assigns the item as a drop item to a creature.\nUses a creature name, a drop chance and a minimum and maximum amount.")] public readonly DropTargets DropsFrom = new DropTargets(); [Description("Configures whether the item can be bought at the trader.\nDon't forget to set cost to something above 0 or the item will be sold for free.")] public readonly Trade Trade = new Trade(); internal List Conversions = new List(); internal List conversions = new List(); public Dictionary Recipes = new Dictionary(); private static object? configManager; private static BaseUnityPlugin? _plugin; private Configurability configurability => Configurable ?? DefaultConfigurability; [Description("Specifies the resources needed to craft the item.\nUse .Add to add resources with their internal ID and an amount.\nUse one .Add for each resource type the item should need.")] public RequiredResourceList RequiredItems => this[""].RequiredItems; [Description("Specifies the resources needed to upgrade the item.\nUse .Add to add resources with their internal ID and an amount. This amount will be multipled by the item quality level.\nUse one .Add for each resource type the upgrade should need.")] public RequiredResourceList RequiredUpgradeItems => this[""].RequiredUpgradeItems; [Description("Specifies the crafting station needed to craft the item.\nUse .Add to add a crafting station, using the CraftingTable enum and a minimum level for the crafting station.\nUse one .Add for each crafting station.")] public CraftingStationList Crafting => this[""].Crafting; [Description("Specifies a config entry which toggles whether a recipe is active.")] public ConfigEntryBase? RecipeIsActive { get { return this[""].RecipeIsActive; } set { this[""].RecipeIsActive = value; } } [Description("Specifies the number of items that should be given to the player with a single craft of the item.\nDefaults to 1.")] public int CraftAmount { get { return this[""].CraftAmount; } set { this[""].CraftAmount = value; } } public bool RequireOnlyOneIngredient { get { return this[""].RequireOnlyOneIngredient; } set { this[""].RequireOnlyOneIngredient = value; } } public float QualityResultAmountMultiplier { get { return this[""].QualityResultAmountMultiplier; } set { this[""].QualityResultAmountMultiplier = value; } } public ItemRecipe this[string name] { get { if (Recipes.TryGetValue(name, out ItemRecipe value)) { return value; } return Recipes[name] = new ItemRecipe(); } } private static BaseUnityPlugin plugin { get { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown if (_plugin == null) { IEnumerable source; try { source = Assembly.GetExecutingAssembly().DefinedTypes.ToList(); } catch (ReflectionTypeLoadException ex) { source = from t in ex.Types where t != null select t.GetTypeInfo(); } _plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); } return _plugin; } } public static void Init() { if (!_initialized) { _initialized = true; } } public Item(string assetBundleFileName, string prefabName, string folderName = "assets") : this(PrefabManager.RegisterAssetBundle(assetBundleFileName, folderName), prefabName) { } public Item(AssetBundle bundle, string prefabName) : this(PrefabManager.RegisterPrefab(bundle, prefabName, addToObjectDb: true), skipRegistering: true) { } public Item(GameObject prefab, bool skipRegistering = false) { if (!skipRegistering) { PrefabManager.RegisterPrefab(prefab, addToObjectDb: true); } Prefab = prefab; registeredItems.Add(this); itemDropMap[Prefab.GetComponent()] = this; Prefab.GetComponent().m_itemData.m_dropPrefab = Prefab; } public void ToggleConfigurationVisibility(Configurability visible) { configurationVisible = visible; if (itemDropConfigs.TryGetValue(this, out ConfigEntry value)) { Toggle((ConfigEntryBase)(object)value, Configurability.Drop); } if (itemCraftConfigs.TryGetValue(this, out Dictionary value2)) { foreach (ItemConfig value4 in value2.Values) { ToggleObj(value4, Configurability.Recipe); } } foreach (Conversion conversion in Conversions) { if (conversion.config != null) { ToggleObj(conversion.config, Configurability.Recipe); } } foreach (KeyValuePair statsConfig in statsConfigs) { Toggle(statsConfig.Key, Configurability.Stats); if ((visible & Configurability.Stats) != 0) { statsConfig.Value(); } } reloadConfigDisplay(); void Toggle(ConfigEntryBase cfg, Configurability check) { object[] tags = cfg.Description.Tags; for (int j = 0; j < tags.Length; j++) { if (tags[j] is ConfigurationManagerAttributes configurationManagerAttributes) { configurationManagerAttributes.Browsable = (visible & check) != 0 && (configurationManagerAttributes.browsability == null || configurationManagerAttributes.browsability()); } } } void ToggleObj(object obj, Configurability check) { FieldInfo[] fields = obj.GetType().GetFields(); for (int i = 0; i < fields.Length; i++) { object? value3 = fields[i].GetValue(obj); ConfigEntryBase val = (ConfigEntryBase)((value3 is ConfigEntryBase) ? value3 : null); if (val != null) { Toggle(val, check); } } } } internal static void reloadConfigDisplay() { object obj = configManager?.GetType().GetProperty("DisplayingWindow").GetValue(configManager); if (obj is bool && (bool)obj) { configManager.GetType().GetMethod("BuildSettingList").Invoke(configManager, Array.Empty()); } } private void UpdateItemTableConfig(string recipeKey, CraftingTable table, string customTableValue) { if (activeRecipes.ContainsKey(this) && activeRecipes[this].TryGetValue(recipeKey, out List value)) { value.First().m_enabled = table != CraftingTable.Disabled; if ((uint)table <= 1u) { value.First().m_craftingStation = null; } else if (table == CraftingTable.Custom) { Recipe obj = value.First(); GameObject prefab = ZNetScene.instance.GetPrefab(customTableValue); obj.m_craftingStation = ((prefab != null) ? prefab.GetComponent() : null); } else { value.First().m_craftingStation = ZNetScene.instance.GetPrefab(getInternalName(table)).GetComponent(); } } } private void UpdateCraftConfig(string recipeKey, SerializedRequirements craftRequirements, SerializedRequirements upgradeRequirements) { if (!Object.op_Implicit((Object)(object)ObjectDB.instance) || !activeRecipes.ContainsKey(this) || !activeRecipes[this].TryGetValue(recipeKey, out List value)) { return; } foreach (Recipe item in value) { item.m_resources = SerializedRequirements.toPieceReqs(ObjectDB.instance, craftRequirements, upgradeRequirements); } } internal static void Patch_FejdStartup() { //IL_107a: Unknown result type (might be due to invalid IL or missing references) //IL_107f: Unknown result type (might be due to invalid IL or missing references) //IL_2333: Unknown result type (might be due to invalid IL or missing references) //IL_2340: Expected O, but got Unknown //IL_1143: Unknown result type (might be due to invalid IL or missing references) //IL_1146: Unknown result type (might be due to invalid IL or missing references) //IL_119c: Expected I4, but got Unknown //IL_0c4a: Unknown result type (might be due to invalid IL or missing references) //IL_0c5c: Expected O, but got Unknown //IL_0d1c: Unknown result type (might be due to invalid IL or missing references) //IL_0d29: Expected O, but got Unknown //IL_12d0: Unknown result type (might be due to invalid IL or missing references) //IL_12d3: Unknown result type (might be due to invalid IL or missing references) //IL_12d5: Invalid comparison between Unknown and I4 //IL_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03ba: Expected O, but got Unknown //IL_12d7: Unknown result type (might be due to invalid IL or missing references) //IL_12db: Invalid comparison between Unknown and I4 //IL_0e7d: Unknown result type (might be due to invalid IL or missing references) //IL_0e99: Expected O, but got Unknown //IL_0f29: Unknown result type (might be due to invalid IL or missing references) //IL_0f45: Expected O, but got Unknown //IL_12dd: Unknown result type (might be due to invalid IL or missing references) //IL_12e1: Invalid comparison between Unknown and I4 //IL_0fde: Unknown result type (might be due to invalid IL or missing references) //IL_0ffa: Expected O, but got Unknown //IL_14dc: Unknown result type (might be due to invalid IL or missing references) //IL_14df: Unknown result type (might be due to invalid IL or missing references) //IL_14e1: Invalid comparison between Unknown and I4 //IL_0497: Unknown result type (might be due to invalid IL or missing references) //IL_04ae: Expected O, but got Unknown //IL_14e3: Unknown result type (might be due to invalid IL or missing references) //IL_14e7: Unknown result type (might be due to invalid IL or missing references) //IL_14e9: Invalid comparison between Unknown and I4 //IL_14eb: Unknown result type (might be due to invalid IL or missing references) //IL_14ef: Invalid comparison between Unknown and I4 //IL_05d3: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Expected O, but got Unknown //IL_15c4: Unknown result type (might be due to invalid IL or missing references) //IL_15c9: Unknown result type (might be due to invalid IL or missing references) //IL_15cb: Unknown result type (might be due to invalid IL or missing references) //IL_15ce: Invalid comparison between Unknown and I4 //IL_15d0: Unknown result type (might be due to invalid IL or missing references) //IL_15d4: Invalid comparison between Unknown and I4 //IL_06ec: Unknown result type (might be due to invalid IL or missing references) //IL_0703: Expected O, but got Unknown //IL_1643: Unknown result type (might be due to invalid IL or missing references) //IL_1646: Unknown result type (might be due to invalid IL or missing references) //IL_1648: Invalid comparison between Unknown and I4 //IL_164a: Unknown result type (might be due to invalid IL or missing references) //IL_164e: Unknown result type (might be due to invalid IL or missing references) //IL_1650: Invalid comparison between Unknown and I4 //IL_07cc: Unknown result type (might be due to invalid IL or missing references) //IL_07e3: Expected O, but got Unknown //IL_1652: Unknown result type (might be due to invalid IL or missing references) //IL_1656: Invalid comparison between Unknown and I4 //IL_1793: Unknown result type (might be due to invalid IL or missing references) //IL_1796: Invalid comparison between Unknown and I4 //IL_08d7: Unknown result type (might be due to invalid IL or missing references) //IL_08ee: Expected O, but got Unknown //IL_1993: Unknown result type (might be due to invalid IL or missing references) //IL_199a: Invalid comparison between Unknown and I4 //IL_1a63: Unknown result type (might be due to invalid IL or missing references) //IL_1a68: Unknown result type (might be due to invalid IL or missing references) //IL_1a6a: Unknown result type (might be due to invalid IL or missing references) //IL_1a6e: Unknown result type (might be due to invalid IL or missing references) //IL_1a70: Invalid comparison between Unknown and I4 //IL_1adf: Unknown result type (might be due to invalid IL or missing references) //IL_1ae2: Unknown result type (might be due to invalid IL or missing references) //IL_1ae4: Invalid comparison between Unknown and I4 //IL_1709: Unknown result type (might be due to invalid IL or missing references) //IL_170e: Unknown result type (might be due to invalid IL or missing references) //IL_1ae6: Unknown result type (might be due to invalid IL or missing references) //IL_1aea: Invalid comparison between Unknown and I4 //IL_1aec: Unknown result type (might be due to invalid IL or missing references) //IL_1af0: Invalid comparison between Unknown and I4 //IL_1f5d: Unknown result type (might be due to invalid IL or missing references) //IL_1f60: Invalid comparison between Unknown and I4 Type type = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "ConfigurationManager")?.GetType("ConfigurationManager.ConfigurationManager"); configManager = ((type == null) ? null : Chainloader.ManagerObject.GetComponent(type)); if (DefaultConfigurability != 0) { bool saveOnConfigSet = plugin.Config.SaveOnConfigSet; plugin.Config.SaveOnConfigSet = false; foreach (Item item4 in registeredItems.Where((Item i) => i.configurability != Configurability.Disabled)) { Item item3 = item4; string text = (string.IsNullOrEmpty(item3.SectionName) ? item3.Prefab.GetComponent().m_itemData.m_shared.m_name : item3.SectionName); string englishName = new Regex("['[\"\\]]").Replace(Localizer.GetTranslation("English", text), "").Trim(); string localizedName = Localization.instance.Localize(text).Trim(); int order = 0; if ((item3.configurability & Configurability.Recipe) != 0) { itemCraftConfigs[item3] = new Dictionary(); foreach (string item5 in item3.Recipes.Keys.DefaultIfEmpty("")) { string configKey = item5; string text2 = ((configKey == "") ? "" : (" (" + configKey + ")")); if (configKey == "") { Configurability? configurable = item3.Configurable; if (configurable.HasValue && item3.Crafting.Stations.Count == 0) { item3.Crafting.Add(CraftingTable.Disabled, 1); } } if (!item3.Recipes.ContainsKey(configKey) || item3.Recipes[configKey].Crafting.Stations.Count <= 0) { continue; } ItemConfig itemConfig2 = (itemCraftConfigs[item3][configKey] = new ItemConfig()); ItemConfig cfg = itemConfig2; List hideWhenNoneAttributes = new List(); ConfigSyncBase.SyncedConfig(englishName, "Crafting Station" + text2, item3.Recipes[configKey].Crafting.Stations.First().Table, new ConfigDescription("Crafting station where " + englishName + " is available.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = (order -= 1), Browsable = ((item3.configurationVisible & Configurability.Recipe) != 0), Category = localizedName } }), ref cfg.table); ConfigurationManagerAttributes customTableAttributes = new ConfigurationManagerAttributes { Order = (order -= 1), browsability = CustomTableBrowsability, Browsable = (CustomTableBrowsability() && (item3.configurationVisible & Configurability.Recipe) != 0), Category = localizedName }; ConfigSyncBase.SyncedConfig(englishName, "Custom Crafting Station" + text2, item3.Recipes[configKey].Crafting.Stations.First().custom ?? "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes }), ref cfg.customTable); cfg.table.SettingChanged += TableConfigChanged; cfg.customTable.SettingChanged += TableConfigChanged; ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes { Order = (order -= 1), browsability = TableLevelBrowsability, Browsable = (TableLevelBrowsability() && (item3.configurationVisible & Configurability.Recipe) != 0), Category = localizedName }; hideWhenNoneAttributes.Add(configurationManagerAttributes); ConfigSyncBase.SyncedConfig(englishName, "Crafting Station Level" + text2, item3.Recipes[configKey].Crafting.Stations.First().level, new ConfigDescription("Required crafting station level to craft " + englishName + ".", (AcceptableValueBase)null, new object[1] { configurationManagerAttributes }), ref cfg.tableLevel); cfg.tableLevel.SettingChanged += delegate { if (activeRecipes.ContainsKey(item3) && activeRecipes[item3].TryGetValue(configKey, out List value6)) { value6.First().m_minStationLevel = cfg.tableLevel.Value; } }; if (item3.Prefab.GetComponent().m_itemData.m_shared.m_maxQuality > 1) { ConfigSyncBase.SyncedConfig(englishName, "Maximum Crafting Station Level" + text2, (item3.MaximumRequiredStationLevel == int.MaxValue) ? (item3.Recipes[configKey].Crafting.Stations.First().level + item3.Prefab.GetComponent().m_itemData.m_shared.m_maxQuality - 1) : item3.MaximumRequiredStationLevel, new ConfigDescription("Maximum crafting station level to upgrade and repair " + englishName + ".", (AcceptableValueBase)null, new object[1] { configurationManagerAttributes }), ref cfg.maximumTableLevel); } ConfigSyncBase.SyncedConfig(englishName, "Require only one resource" + text2, item3.Recipes[configKey].RequireOnlyOneIngredient ? Toggle.On : Toggle.Off, new ConfigDescription("Whether only one of the ingredients is needed to craft " + englishName, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = (order -= 1), browsability = TableLevelBrowsability, Browsable = (TableLevelBrowsability() && (item3.configurationVisible & Configurability.Recipe) != 0), Category = localizedName } }), ref cfg.requireOneIngredient); ConfigurationManagerAttributes qualityResultAttributes = new ConfigurationManagerAttributes { Order = (order -= 1), browsability = QualityResultBrowsability, Browsable = (QualityResultBrowsability() && (item3.configurationVisible & Configurability.Recipe) != 0), Category = localizedName }; cfg.requireOneIngredient.SettingChanged += delegate { if (activeRecipes.ContainsKey(item3) && activeRecipes[item3].TryGetValue(configKey, out List value5)) { foreach (Recipe item6 in value5) { item6.m_requireOnlyOneIngredient = cfg.requireOneIngredient.Value == Toggle.On; } } qualityResultAttributes.Browsable = QualityResultBrowsability(); reloadConfigDisplay(); }; ConfigSyncBase.SyncedConfig(englishName, "Quality Multiplier" + text2, item3.Recipes[configKey].QualityResultAmountMultiplier, new ConfigDescription("Multiplies the crafted amount based on the quality of the resources when crafting " + englishName + ". Only works, if Require Only One Resource is true.", (AcceptableValueBase)null, new object[1] { qualityResultAttributes }), ref cfg.qualityResultAmountMultiplier); cfg.qualityResultAmountMultiplier.SettingChanged += delegate { if (activeRecipes.ContainsKey(item3) && activeRecipes[item3].TryGetValue(configKey, out List value4)) { foreach (Recipe item7 in value4) { item7.m_qualityResultAmountMultiplier = cfg.qualityResultAmountMultiplier.Value; } } }; if ((!item3.Recipes[configKey].RequiredItems.Free || item3.Recipes[configKey].RequiredItems.Requirements.Count > 0) && item3.Recipes[configKey].RequiredItems.Requirements.All((Requirement r) => r.amountConfig == null)) { cfg.craft = itemConfig("Crafting Costs" + text2, new SerializedRequirements(item3.Recipes[configKey].RequiredItems.Requirements).ToString(), "Item costs to craft " + englishName, isUpgrade: false); } if (item3.Prefab.GetComponent().m_itemData.m_shared.m_maxQuality > 1 && (!item3.Recipes[configKey].RequiredUpgradeItems.Free || item3.Recipes[configKey].RequiredUpgradeItems.Requirements.Count > 0) && item3.Recipes[configKey].RequiredUpgradeItems.Requirements.All((Requirement r) => r.amountConfig == null)) { cfg.upgrade = itemConfig("Upgrading Costs" + text2, new SerializedRequirements(item3.Recipes[configKey].RequiredUpgradeItems.Requirements).ToString(), "Item costs per level to upgrade " + englishName, isUpgrade: true); } if (cfg.craft != null) { cfg.craft.SettingChanged += ConfigChanged; } if (cfg.upgrade != null) { cfg.upgrade.SettingChanged += ConfigChanged; } void ConfigChanged(object o, EventArgs e) { item3.UpdateCraftConfig(configKey, new SerializedRequirements(cfg.craft?.Value ?? ""), new SerializedRequirements(cfg.upgrade?.Value ?? "")); } bool CustomTableBrowsability() { return cfg.table.Value == CraftingTable.Custom; } bool ItemBrowsability() { return cfg.table.Value != CraftingTable.Disabled; } bool QualityResultBrowsability() { return cfg.requireOneIngredient.Value == Toggle.On; } void TableConfigChanged(object o, EventArgs e) { item3.UpdateItemTableConfig(configKey, cfg.table.Value, cfg.customTable.Value); customTableAttributes.Browsable = cfg.table.Value == CraftingTable.Custom; foreach (ConfigurationManagerAttributes item8 in hideWhenNoneAttributes) { item8.Browsable = cfg.table.Value != CraftingTable.Disabled; } reloadConfigDisplay(); } bool TableLevelBrowsability() { return cfg.table.Value != CraftingTable.Disabled; } ConfigEntry itemConfig(string name, string value, string desc, bool isUpgrade) { //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown ConfigurationManagerAttributes configurationManagerAttributes3 = new ConfigurationManagerAttributes { CustomDrawer = drawRequirementsConfigTable(item3, isUpgrade), Order = (order -= 1), browsability = ItemBrowsability, Browsable = (ItemBrowsability() && (item3.configurationVisible & Configurability.Recipe) != 0), Category = localizedName }; hideWhenNoneAttributes.Add(configurationManagerAttributes3); ConfigEntry configEntry4 = null; ConfigSyncBase.SyncedConfig(englishName, name, value, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes3 }), ref configEntry4); return configEntry4; } } if ((item3.configurability & Configurability.Drop) != 0) { ConfigEntry dropsEnabledConfig = null; ConfigSyncBase.SyncedConfig(englishName, "Drops Enabled", value: false, new ConfigDescription("Enables " + englishName + " drops", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Category = localizedName, Browsable = ((item3.configurationVisible & Configurability.Drop) != 0) } }), ref dropsEnabledConfig); itemDropEnabledConfig[item3] = dropsEnabledConfig; ConfigEntry configEntry = null; ConfigSyncBase.SyncedConfig(englishName, "Drops from", new SerializedDrop(item3.DropsFrom.Drops).ToString(), new ConfigDescription("Creatures " + englishName + " drops from", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { CustomDrawer = drawDropsConfigTable, Category = localizedName, Browsable = ((item3.configurationVisible & Configurability.Drop) != 0) } }), ref configEntry); itemDropConfigs[item3] = configEntry; dropsEnabledConfig.SettingChanged += delegate { item3.UpdateCharacterDrop(dropsEnabledConfig.Value); }; configEntry.SettingChanged += delegate { item3.UpdateCharacterDrop(dropsEnabledConfig.Value); }; item3.UpdateCharacterDrop(dropsEnabledConfig.Value); } for (int j = 0; j < item3.Conversions.Count; j++) { string text3 = ((item3.Conversions.Count > 1) ? $"{j + 1}. " : ""); Conversion conversion = item3.Conversions[j]; conversion.config = new Conversion.ConversionConfig(); int index = j; ConfigSyncBase.SyncedConfig(englishName, text3 + "Conversion Input Item", conversion.Input, new ConfigDescription("Input item to create " + englishName, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Category = localizedName, Browsable = ((item3.configurationVisible & Configurability.Recipe) != 0) } }), ref conversion.config.input); conversion.config.input.SettingChanged += delegate { if (index < item3.conversions.Count) { ObjectDB instance = ObjectDB.instance; if (instance != null) { ItemDrop from = SerializedRequirements.fetchByName(instance, conversion.config.input.Value); item3.conversions[index].m_from = from; UpdatePiece(); } } }; ConfigSyncBase.SyncedConfig(englishName, text3 + "Conversion Piece", conversion.Piece, new ConfigDescription("Conversion piece used to create " + englishName, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Category = localizedName, Browsable = ((item3.configurationVisible & Configurability.Recipe) != 0) } }), ref conversion.config.piece); conversion.config.piece.SettingChanged += delegate { UpdatePiece(); }; ConfigSyncBase.SyncedConfig(englishName, text3 + "Conversion Custom Piece", conversion.customPiece ?? "", new ConfigDescription("Custom conversion piece to create " + englishName, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Category = localizedName, Browsable = ((item3.configurationVisible & Configurability.Recipe) != 0) } }), ref conversion.config.customPiece); conversion.config.customPiece.SettingChanged += delegate { UpdatePiece(); }; void UpdatePiece() { if (index < item3.conversions.Count && Object.op_Implicit((Object)(object)ZNetScene.instance)) { string text4 = ((conversion.config.piece.Value == ConversionPiece.Disabled) ? null : ((conversion.config.piece.Value == ConversionPiece.Custom) ? conversion.config.customPiece.Value : getInternalName(conversion.config.piece.Value))); string activePiece = conversion.config.activePiece; if (conversion.config.activePiece != null) { int num = ZNetScene.instance.GetPrefab(conversion.config.activePiece).GetComponent().m_conversion.IndexOf(item3.conversions[index]); if (num >= 0) { Smelter[] array3 = Resources.FindObjectsOfTypeAll(); foreach (Smelter val2 in array3) { if (Utils.GetPrefabName(((Component)val2).gameObject) == activePiece) { val2.m_conversion.RemoveAt(num); } } } conversion.config.activePiece = null; } if (item3.conversions[index].m_from != null && conversion.config.piece.Value != 0) { GameObject prefab = ZNetScene.instance.GetPrefab(text4); if (((prefab != null) ? prefab.GetComponent() : null) != null) { conversion.config.activePiece = text4; Smelter[] array3 = Resources.FindObjectsOfTypeAll(); foreach (Smelter val3 in array3) { if (Utils.GetPrefabName(((Component)val3).gameObject) == text4) { val3.m_conversion.Add(item3.conversions[index]); } } } } } } } } if ((item3.configurability & Configurability.Stats) != 0) { item3.statsConfigs.Clear(); SharedData shared2 = item3.Prefab.GetComponent().m_itemData.m_shared; ItemType itemType = shared2.m_itemType; statcfg("Weight", "Weight of " + englishName + ".", (SharedData shared) => shared.m_weight, delegate(SharedData shared, float value) { shared.m_weight = value; }); statcfg("Trader Value", "Trader value of " + englishName + ".", (SharedData shared) => shared.m_value, delegate(SharedData shared, int value) { shared.m_value = value; }); bool flag; switch (itemType - 3) { case 0: case 1: case 2: case 3: case 4: case 8: case 9: case 11: case 14: case 16: case 19: flag = true; break; default: flag = false; break; } if (flag) { statcfg("Durability", "Durability of " + englishName + ".", (SharedData shared) => shared.m_maxDurability, delegate(SharedData shared, float value) { shared.m_maxDurability = value; }); statcfg("Durability per Level", "Durability gain per level of " + englishName + ".", (SharedData shared) => shared.m_durabilityPerLevel, delegate(SharedData shared, float value) { shared.m_durabilityPerLevel = value; }); statcfg("Movement Speed Modifier", "Movement speed modifier of " + englishName + ".", (SharedData shared) => shared.m_movementModifier, delegate(SharedData shared, float value) { shared.m_movementModifier = value; }); } if ((itemType - 3 <= 2 || (int)itemType == 14 || (int)itemType == 22) ? true : false) { statcfg("Block Armor", "Block armor of " + englishName + ".", (SharedData shared) => shared.m_blockPower, delegate(SharedData shared, float value) { shared.m_blockPower = value; }); statcfg("Block Armor per Level", "Block armor per level for " + englishName + ".", (SharedData shared) => shared.m_blockPowerPerLevel, delegate(SharedData shared, float value) { shared.m_blockPowerPerLevel = value; }); statcfg("Block Force", "Block force of " + englishName + ".", (SharedData shared) => shared.m_deflectionForce, delegate(SharedData shared, float value) { shared.m_deflectionForce = value; }); statcfg("Block Force per Level", "Block force per level for " + englishName + ".", (SharedData shared) => shared.m_deflectionForcePerLevel, delegate(SharedData shared, float value) { shared.m_deflectionForcePerLevel = value; }); statcfg("Parry Bonus", "Parry bonus of " + englishName + ".", (SharedData shared) => shared.m_timedBlockBonus, delegate(SharedData shared, float value) { shared.m_timedBlockBonus = value; }); } else if ((itemType - 6 <= 1 || itemType - 11 <= 1 || (int)itemType == 17) ? true : false) { statcfg("Armor", "Armor of " + englishName + ".", (SharedData shared) => shared.m_armor, delegate(SharedData shared, float value) { shared.m_armor = value; }); statcfg("Armor per Level", "Armor per level for " + englishName + ".", (SharedData shared) => shared.m_armorPerLevel, delegate(SharedData shared, float value) { shared.m_armorPerLevel = value; }); } SkillType skillType = shared2.m_skillType; if (((int)skillType == 7 || (int)skillType == 12) ? true : false) { statcfg("Tool tier", "Tool tier of " + englishName + ".", (SharedData shared) => shared.m_toolTier, delegate(SharedData shared, int value) { shared.m_toolTier = value; }); } if ((itemType - 5 <= 2 || itemType - 11 <= 1 || (int)itemType == 17) ? true : false) { Dictionary modifiers = shared2.m_damageModifiers.ToDictionary((DamageModPair d) => d.m_type, (DamageModPair d) => (DamageModifier)d.m_modifier); DamageType[] first = (DamageType[])Enum.GetValues(typeof(DamageType)); DamageType[] array = new DamageType[5]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); foreach (DamageType item9 in first.Except((IEnumerable)(object)array)) { DamageType damageType = item9; statcfg(((object)(DamageType)(ref damageType)).ToString() + " Resistance", ((object)(DamageType)(ref damageType)).ToString() + " resistance of " + englishName + ".", (SharedData _) => (!modifiers.TryGetValue(damageType, out var value3)) ? DamageModifier.None : value3, delegate(SharedData shared, DamageModifier value) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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) //IL_0054: Unknown result type (might be due to invalid IL or missing references) DamageModPair val4 = default(DamageModPair); val4.m_type = damageType; val4.m_modifier = (DamageModifier)value; DamageModPair val5 = val4; for (int n = 0; n < shared.m_damageModifiers.Count; n++) { if (shared.m_damageModifiers[n].m_type == damageType) { if (value == DamageModifier.None) { shared.m_damageModifiers.RemoveAt(n); } else { shared.m_damageModifiers[n] = val5; } return; } } if (value != DamageModifier.None) { shared.m_damageModifiers.Add(val5); } }); } } if ((int)itemType == 2 && shared2.m_food > 0f) { statcfg("Health", "Health value of " + englishName + ".", (SharedData shared) => shared.m_food, delegate(SharedData shared, float value) { shared.m_food = value; }); statcfg("Stamina", "Stamina value of " + englishName + ".", (SharedData shared) => shared.m_foodStamina, delegate(SharedData shared, float value) { shared.m_foodStamina = value; }); statcfg("Eitr", "Eitr value of " + englishName + ".", (SharedData shared) => shared.m_foodEitr, delegate(SharedData shared, float value) { shared.m_foodEitr = value; }); statcfg("Duration", "Duration of " + englishName + ".", (SharedData shared) => shared.m_foodBurnTime, delegate(SharedData shared, float value) { shared.m_foodBurnTime = value; }); statcfg("Health Regen", "Health regen value of " + englishName + ".", (SharedData shared) => shared.m_foodRegen, delegate(SharedData shared, float value) { shared.m_foodRegen = value; }); } if ((int)shared2.m_skillType == 10) { statcfg("Health Cost", "Health cost of " + englishName + ".", (SharedData shared) => shared.m_attack.m_attackHealth, delegate(SharedData shared, float value) { shared.m_attack.m_attackHealth = value; }); statcfg("Health Cost Percentage", "Health cost percentage of " + englishName + ".", (SharedData shared) => shared.m_attack.m_attackHealthPercentage, delegate(SharedData shared, float value) { shared.m_attack.m_attackHealthPercentage = value; }); } skillType = shared2.m_skillType; if (skillType - 9 <= 1) { statcfg("Eitr Cost", "Eitr cost of " + englishName + ".", (SharedData shared) => shared.m_attack.m_attackEitr, delegate(SharedData shared, float value) { shared.m_attack.m_attackEitr = value; }); } if ((itemType - 3 <= 1 || (int)itemType == 14 || (int)itemType == 22) ? true : false) { statcfg("Knockback", "Knockback of " + englishName + ".", (SharedData shared) => shared.m_attackForce, delegate(SharedData shared, float value) { shared.m_attackForce = value; }); statcfg("Backstab Bonus", "Backstab bonus of " + englishName + ".", (SharedData shared) => shared.m_backstabBonus, delegate(SharedData shared, float value) { shared.m_backstabBonus = value; }); statcfg("Attack Stamina", "Attack stamina of " + englishName + ".", (SharedData shared) => shared.m_attack.m_attackStamina, delegate(SharedData shared, float value) { shared.m_attack.m_attackStamina = value; }); SetDmg("True", (DamageTypes dmg) => dmg.m_damage, delegate(ref DamageTypes dmg, float val) { dmg.m_damage = val; }); SetDmg("Slash", (DamageTypes dmg) => dmg.m_slash, delegate(ref DamageTypes dmg, float val) { dmg.m_slash = val; }); SetDmg("Pierce", (DamageTypes dmg) => dmg.m_pierce, delegate(ref DamageTypes dmg, float val) { dmg.m_pierce = val; }); SetDmg("Blunt", (DamageTypes dmg) => dmg.m_blunt, delegate(ref DamageTypes dmg, float val) { dmg.m_blunt = val; }); SetDmg("Chop", (DamageTypes dmg) => dmg.m_chop, delegate(ref DamageTypes dmg, float val) { dmg.m_chop = val; }); SetDmg("Pickaxe", (DamageTypes dmg) => dmg.m_pickaxe, delegate(ref DamageTypes dmg, float val) { dmg.m_pickaxe = val; }); SetDmg("Fire", (DamageTypes dmg) => dmg.m_fire, delegate(ref DamageTypes dmg, float val) { dmg.m_fire = val; }); SetDmg("Poison", (DamageTypes dmg) => dmg.m_poison, delegate(ref DamageTypes dmg, float val) { dmg.m_poison = val; }); SetDmg("Frost", (DamageTypes dmg) => dmg.m_frost, delegate(ref DamageTypes dmg, float val) { dmg.m_frost = val; }); SetDmg("Lightning", (DamageTypes dmg) => dmg.m_lightning, delegate(ref DamageTypes dmg, float val) { dmg.m_lightning = val; }); SetDmg("Spirit", (DamageTypes dmg) => dmg.m_spirit, delegate(ref DamageTypes dmg, float val) { dmg.m_spirit = val; }); if ((int)itemType == 4) { statcfg("Projectiles", "Number of projectiles that " + englishName + " shoots at once.", (SharedData shared) => shared.m_attack.m_projectileBursts, delegate(SharedData shared, int value) { shared.m_attack.m_projectileBursts = value; }); statcfg("Burst Interval", "Time between the projectiles " + englishName + " shoots at once.", (SharedData shared) => shared.m_attack.m_burstInterval, delegate(SharedData shared, float value) { shared.m_attack.m_burstInterval = value; }); statcfg("Minimum Accuracy", "Minimum accuracy for " + englishName + ".", (SharedData shared) => shared.m_attack.m_projectileAccuracyMin, delegate(SharedData shared, float value) { shared.m_attack.m_projectileAccuracyMin = value; }); statcfg("Accuracy", "Accuracy for " + englishName + ".", (SharedData shared) => shared.m_attack.m_projectileAccuracy, delegate(SharedData shared, float value) { shared.m_attack.m_projectileAccuracy = value; }); statcfg("Minimum Velocity", "Minimum velocity for " + englishName + ".", (SharedData shared) => shared.m_attack.m_projectileVelMin, delegate(SharedData shared, float value) { shared.m_attack.m_projectileVelMin = value; }); statcfg("Velocity", "Velocity for " + englishName + ".", (SharedData shared) => shared.m_attack.m_projectileVel, delegate(SharedData shared, float value) { shared.m_attack.m_projectileVel = value; }); statcfg("Maximum Draw Time", "Time until " + englishName + " is fully drawn at skill level 0.", (SharedData shared) => shared.m_attack.m_drawDurationMin, delegate(SharedData shared, float value) { shared.m_attack.m_drawDurationMin = value; }); statcfg("Stamina Drain", "Stamina drain per second while drawing " + englishName + ".", (SharedData shared) => shared.m_attack.m_drawStaminaDrain, delegate(SharedData shared, float value) { shared.m_attack.m_drawStaminaDrain = value; }); } } } List traderAttributes; if ((item3.configurability & Configurability.Trader) != 0) { traderAttributes = new List(); ConfigEntry configEntry2 = null; ConfigSyncBase.SyncedConfig(englishName, "Trader Selling", item3.Trade.Trader, new ConfigDescription("Which traders sell " + englishName + ".", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = (order -= 1), Browsable = ((item3.configurationVisible & Configurability.Trader) != 0), Category = localizedName } }), ref configEntry2); item3.traderConfig = new TraderConfig { trader = configEntry2 }; item3.traderConfig.trader.SettingChanged += delegate { item3.ReloadTraderConfiguration(); foreach (ConfigurationManagerAttributes item10 in traderAttributes) { item10.Browsable = TraderBrowsability(); } reloadConfigDisplay(); }; item3.traderConfig.price = traderConfig("Trader Price", item3.Trade.Price, "Price of " + englishName + " at the trader."); item3.traderConfig.stack = traderConfig("Trader Stack", item3.Trade.Stack, "Stack size of " + englishName + " in the trader. Also known as the number of items sold by a trader in one transaction."); item3.traderConfig.requiredGlobalKey = traderConfig("Trader Required Global Key", item3.Trade.RequiredGlobalKey ?? "", "Required global key to unlock " + englishName + " at the trader."); if (item3.traderConfig.trader.Value != 0) { PrefabManager.AddItemToTrader(item3.Prefab, item3.traderConfig.trader.Value, item3.traderConfig.price.Value, item3.traderConfig.stack.Value, item3.traderConfig.requiredGlobalKey.Value); } } else if (item3.Trade.Trader != 0) { PrefabManager.AddItemToTrader(item3.Prefab, item3.Trade.Trader, item3.Trade.Price, item3.Trade.Stack, item3.Trade.RequiredGlobalKey); } void SetDmg(string dmgType, Func readDmg, setDmgFunc setDmg) { Func readDmg2 = readDmg; setDmgFunc setDmg2 = setDmg; statcfg(dmgType + " Damage", dmgType + " damage dealt by " + englishName + ".", (SharedData shared) => readDmg2(shared.m_damages), delegate(SharedData shared, float val) { setDmg2(ref shared.m_damages, val); }); statcfg(dmgType + " Damage Per Level", dmgType + " damage dealt increase per level for " + englishName + ".", (SharedData shared) => readDmg2(shared.m_damagesPerLevel), delegate(SharedData shared, float val) { setDmg2(ref shared.m_damagesPerLevel, val); }); } bool TraderBrowsability() { return item3.traderConfig.trader.Value != Trader.None; } void statcfg(string configName, string description, Func readDefault, Action setValue) where T : notnull { //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown Action setValue2 = setValue; SharedData shared3 = item3.Prefab.GetComponent().m_itemData.m_shared; ConfigEntry cfg2 = null; ConfigSyncBase.SyncedConfig(englishName, configName, readDefault(shared3), new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Category = localizedName, Browsable = ((item3.configurationVisible & Configurability.Stats) != 0) } }), ref cfg2); if ((item3.configurationVisible & Configurability.Stats) != 0) { setValue2(shared3, cfg2.Value); } item3.statsConfigs.Add((ConfigEntryBase)(object)cfg2, ApplyConfig); cfg2.SettingChanged += delegate { if ((item3.configurationVisible & Configurability.Stats) != 0) { ApplyConfig(); } }; void ApplyConfig() { item3.ApplyToAllInstances(delegate(ItemData item) { setValue2(item.m_shared, cfg2.Value); }); } } ConfigEntry traderConfig(string name, T value, string desc) where T : notnull { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown ConfigurationManagerAttributes configurationManagerAttributes2 = new ConfigurationManagerAttributes { Order = (order -= 1), browsability = TraderBrowsability, Browsable = (TraderBrowsability() && (item3.configurationVisible & Configurability.Trader) != 0), Category = localizedName }; traderAttributes.Add(configurationManagerAttributes2); ConfigEntry configEntry3 = null; ConfigSyncBase.SyncedConfig(englishName, name, value, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes2 }), ref configEntry3); configEntry3.SettingChanged += delegate { item3.ReloadTraderConfiguration(); }; return configEntry3; } } if (saveOnConfigSet) { plugin.Config.SaveOnConfigSet = true; plugin.Config.Save(); } } configManager = ((type == null) ? null : Chainloader.ManagerObject.GetComponent(type)); foreach (Item registeredItem in registeredItems) { Item item2 = registeredItem; foreach (KeyValuePair recipe in item2.Recipes) { KeyValuePair kv = recipe; RequiredResourceList[] array2 = new RequiredResourceList[2] { kv.Value.RequiredItems, kv.Value.RequiredUpgradeItems }; foreach (RequiredResourceList requiredResourceList in array2) { for (int l = 0; l < requiredResourceList.Requirements.Count; l++) { ConfigEntry amountCfg; int resourceIndex; if ((item2.configurability & Configurability.Recipe) != 0) { amountCfg = requiredResourceList.Requirements[l].amountConfig; if (amountCfg != null) { resourceIndex = l; amountCfg.SettingChanged += ConfigChanged; } } void ConfigChanged(object o, EventArgs e) { if (Object.op_Implicit((Object)(object)ObjectDB.instance) && activeRecipes.ContainsKey(item2) && activeRecipes[item2].TryGetValue(kv.Key, out List value2)) { foreach (Recipe item11 in value2) { item11.m_resources[resourceIndex].m_amount = amountCfg.Value; } } } } } } item2.InitializeNewRegisteredItem(); } } private void InitializeNewRegisteredItem() { foreach (KeyValuePair recipe in Recipes) { KeyValuePair kv = recipe; ConfigEntryBase enabledCfg = kv.Value.RecipeIsActive; if (enabledCfg != null) { ((object)enabledCfg).GetType().GetEvent("SettingChanged").AddEventHandler(enabledCfg, new EventHandler(ConfigChanged)); } void ConfigChanged(object o, EventArgs e) { if (Object.op_Implicit((Object)(object)ObjectDB.instance) && activeRecipes.ContainsKey(this) && activeRecipes[this].TryGetValue(kv.Key, out List value)) { foreach (Recipe item in value) { item.m_enabled = (int)enabledCfg.BoxedValue != 0; } } } } } public void ReloadCraftingConfiguration() { if (Object.op_Implicit((Object)(object)ObjectDB.instance) && ObjectDB.instance.GetItemPrefab(StringExtensionMethods.GetStableHashCode(((Object)Prefab).name)) == null) { registerRecipesInObjectDB(ObjectDB.instance); ObjectDB.instance.m_items.Add(Prefab); ObjectDB.instance.m_itemByHash.Add(StringExtensionMethods.GetStableHashCode(((Object)Prefab).name), Prefab); ZNetScene.instance.m_prefabs.Add(Prefab); ZNetScene.instance.m_namedPrefabs.Add(StringExtensionMethods.GetStableHashCode(((Object)Prefab).name), Prefab); } foreach (string item in Recipes.Keys.DefaultIfEmpty("")) { if (Recipes.TryGetValue(item, out ItemRecipe value) && value.Crafting.Stations.Count > 0) { UpdateItemTableConfig(item, value.Crafting.Stations.First().Table, value.Crafting.Stations.First().custom ?? ""); UpdateCraftConfig(item, new SerializedRequirements(value.RequiredItems.Requirements), new SerializedRequirements(value.RequiredUpgradeItems.Requirements)); } } } private void ReloadTraderConfiguration() { if (traderConfig.trader.Value == Trader.None) { PrefabManager.RemoveItemFromTrader(Prefab); } else { PrefabManager.AddItemToTrader(Prefab, traderConfig.trader.Value, traderConfig.price.Value, traderConfig.stack.Value, traderConfig.requiredGlobalKey.Value); } } public static void ApplyToAllInstances(GameObject prefab, Action callback) { callback(prefab.GetComponent().m_itemData); string name = prefab.GetComponent().m_itemData.m_shared.m_name; Inventory[] source = (from c in Player.s_players.Select((Player p) => ((Humanoid)p).GetInventory()).Concat(from c in Object.FindObjectsByType((FindObjectsInactive)1, (FindObjectsSortMode)1) select c.GetInventory()) where c != null select c).ToArray(); foreach (ItemData item in (from i in (from p in ObjectDB.instance.m_items select p.GetComponent() into c where Object.op_Implicit((Object)(object)c) && Object.op_Implicit((Object)(object)((Component)c).GetComponent()) select c).Concat(ItemDrop.s_instances) select i.m_itemData).Concat(source.SelectMany((Inventory i) => i.GetAllItems()))) { if (item.m_shared.m_name == name) { callback(item); } } } public void ApplyToAllInstances(Action callback) { ApplyToAllInstances(Prefab, callback); } private static string getInternalName(T value) where T : struct { return ((InternalName)typeof(T).GetMember(value.ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName; } private void registerRecipesInObjectDB(ObjectDB objectDB) { //IL_045a: Unknown result type (might be due to invalid IL or missing references) //IL_045f: Unknown result type (might be due to invalid IL or missing references) //IL_0492: Unknown result type (might be due to invalid IL or missing references) //IL_04a8: Expected O, but got Unknown activeRecipes[this] = new Dictionary>(); itemCraftConfigs.TryGetValue(this, out Dictionary value); foreach (KeyValuePair recipe in Recipes) { List list = new List(); foreach (CraftingStationConfig station in recipe.Value.Crafting.Stations) { ItemConfig itemConfig = value?[recipe.Key]; Recipe val = ScriptableObject.CreateInstance(); string name = ((Object)Prefab).name; CraftingTable table = station.Table; ((Object)val).name = name + "_Recipe_" + table; val.m_amount = recipe.Value.CraftAmount; ConfigEntryBase? recipeIsActive = recipe.Value.RecipeIsActive; val.m_enabled = (int)(((recipeIsActive != null) ? recipeIsActive.BoxedValue : null) ?? ((object)1)) != 0 && (itemConfig == null || itemConfig.table.Value != CraftingTable.Disabled); val.m_item = Prefab.GetComponent(); val.m_resources = SerializedRequirements.toPieceReqs(objectDB, (itemConfig?.craft == null) ? new SerializedRequirements(recipe.Value.RequiredItems.Requirements) : new SerializedRequirements(itemConfig.craft.Value), (itemConfig?.upgrade == null) ? new SerializedRequirements(recipe.Value.RequiredUpgradeItems.Requirements) : new SerializedRequirements(itemConfig.upgrade.Value)); table = ((itemConfig == null || list.Count > 0) ? station.Table : itemConfig.table.Value); if ((uint)table <= 1u) { val.m_craftingStation = null; } else if (((itemConfig == null || list.Count > 0) ? station.Table : itemConfig.table.Value) == CraftingTable.Custom) { GameObject prefab = ZNetScene.instance.GetPrefab((itemConfig == null || list.Count > 0) ? station.custom : itemConfig.customTable.Value); if (prefab != null) { val.m_craftingStation = prefab.GetComponent(); } else { Debug.LogWarning((object)("Custom crafting station '" + ((itemConfig == null || list.Count > 0) ? station.custom : itemConfig.customTable.Value) + "' does not exist")); } } else { val.m_craftingStation = ZNetScene.instance.GetPrefab(getInternalName((itemConfig == null || list.Count > 0) ? station.Table : itemConfig.table.Value)).GetComponent(); } val.m_minStationLevel = ((itemConfig == null || list.Count > 0) ? station.level : itemConfig.tableLevel.Value); val.m_requireOnlyOneIngredient = ((itemConfig == null) ? recipe.Value.RequireOnlyOneIngredient : (itemConfig.requireOneIngredient.Value == Toggle.On)); val.m_qualityResultAmountMultiplier = itemConfig?.qualityResultAmountMultiplier.Value ?? recipe.Value.QualityResultAmountMultiplier; list.Add(val); RequiredResourceList requiredItems; if (station.Table != 0) { requiredItems = recipe.Value.RequiredItems; if (requiredItems != null && !requiredItems.Free) { List requirements = requiredItems.Requirements; if (requirements != null && requirements.Count == 0) { hiddenCraftRecipes.Add(val, recipe.Value.RecipeIsActive); } } } requiredItems = recipe.Value.RequiredUpgradeItems; if (requiredItems != null && !requiredItems.Free) { List requirements = requiredItems.Requirements; if (requirements != null && requirements.Count == 0) { hiddenUpgradeRecipes.Add(val, recipe.Value.RecipeIsActive); } } } activeRecipes[this].Add(recipe.Key, list); objectDB.m_recipes.AddRange(list); } conversions = new List(); for (int i = 0; i < Conversions.Count; i++) { Conversion conversion = Conversions[i]; conversions.Add(new ItemConversion { m_from = SerializedRequirements.fetchByName(ObjectDB.instance, conversion.config?.input.Value ?? conversion.Input), m_to = Prefab.GetComponent() }); ConversionPiece conversionPiece = conversion.config?.piece.Value ?? conversion.Piece; string text = null; if (conversionPiece != 0 && conversions[i].m_from != null) { text = ((conversionPiece != ConversionPiece.Custom) ? getInternalName(conversionPiece) : (conversion.config?.customPiece.Value ?? conversion.customPiece)); GameObject prefab2 = ZNetScene.instance.GetPrefab(text); Smelter val2 = ((prefab2 != null) ? prefab2.GetComponent() : null); if (val2 != null) { val2.m_conversion.Add(conversions[i]); } else { text = null; } } if (conversion.config != null) { conversion.config.activePiece = text; } } } [HarmonyPriority(0)] internal static void Patch_ObjectDBInit(ObjectDB __instance) { if ((Object)(object)__instance.GetItemPrefab("Wood") == (Object)null) { return; } hiddenCraftRecipes.Clear(); hiddenUpgradeRecipes.Clear(); foreach (Item registeredItem in registeredItems) { registeredItem.registerRecipesInObjectDB(__instance); } } internal static void Patch_TraderGetAvailableItems(Trader __instance, ref List __result) { string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject); Trader trader2 = ((prefabName == "Haldor") ? Trader.Haldor : ((prefabName == "Hildir") ? Trader.Hildir : Trader.None)); Trader trader = trader2; __result.AddRange(from tuple in PrefabManager.CustomTradeItems.Values where (tuple.Item1 & trader) != 0 select tuple.Item2 into tradeItem where string.IsNullOrEmpty(tradeItem.m_requiredGlobalKey) || ZoneSystem.instance.GetGlobalKey(tradeItem.m_requiredGlobalKey) select tradeItem); } internal static void Patch_OnAddSmelterInput(ItemData item, bool __result) { if (__result) { ((Humanoid)Player.m_localPlayer).UnequipItem(item, true); } } internal static void Patch_MaximumRequiredStationLevel(Recipe __instance, ref int __result, int quality) { if (!itemDropMap.TryGetValue(__instance.m_item, out Item value)) { return; } IEnumerable source; if (!itemCraftConfigs.TryGetValue(value, out Dictionary value2)) { source = Enumerable.Empty(); } else { CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation(); if (currentCraftingStation != null) { string stationName = Utils.GetPrefabName(((Component)currentCraftingStation).gameObject); source = from c in value2.Where(delegate(KeyValuePair c) { switch (c.Value.table.Value) { case CraftingTable.Disabled: case CraftingTable.Inventory: return false; case CraftingTable.Custom: return c.Value.customTable.Value == stationName; default: return getInternalName(c.Value.table.Value) == stationName; } }) select c.Value; } else { source = value2.Values; } } __result = Mathf.Min(Mathf.Max(1, __instance.m_minStationLevel) + (quality - 1), (from cfg in source where cfg.maximumTableLevel != null select cfg.maximumTableLevel.Value).DefaultIfEmpty(value.MaximumRequiredStationLevel).Max()); } internal static void Patch_GetAvailableRecipesPrefix(ref Dictionary>? __state) { if (__state == null) { __state = new Dictionary>(); } Dictionary source; if (InventoryGui.instance.InCraftTab()) { source = hiddenCraftRecipes; } else { if (!InventoryGui.instance.InUpradeTab()) { return; } source = hiddenUpgradeRecipes; } List list = (from kv in source select kv.Key into r where r.m_enabled select r).ToList(); __state[Assembly.GetExecutingAssembly()] = list; foreach (Recipe item in list) { item.m_enabled = false; } } internal static void Patch_GetAvailableRecipesFinalizer(Dictionary> __state) { if (!__state.TryGetValue(Assembly.GetExecutingAssembly(), out List value)) { return; } foreach (Recipe item in value) { item.m_enabled = true; } } internal static IEnumerable Transpile_SetupRequirementList(IEnumerable instructionsEnumerable, ILGenerator ilg) { //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Expected O, but got Unknown //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Expected O, but got Unknown //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Expected O, but got Unknown //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Expected O, but got Unknown //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Expected O, but got Unknown //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Expected O, but got Unknown //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Expected O, but got Unknown //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Expected O, but got Unknown //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Expected O, but got Unknown List list = instructionsEnumerable.ToList(); MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(InventoryGui), "SetupRequirement", (Type[])null, (Type[])null); CodeInstruction val = null; CodeInstruction val2 = null; LocalBuilder localBuilder = ilg.DeclareLocal(typeof(int)); Dictionary dictionary = new Dictionary(); bool flag = false; int num = 0; int value = 0; Label? label = default(Label?); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], methodInfo)) { val = list[i + 2]; val2 = list[i + 5]; flag = true; } if (flag) { if (CodeInstructionExtensions.Branches(list[i], ref label) && dictionary.TryGetValue(label.Value, out value)) { num = i; break; } continue; } foreach (Label label4 in list[i].labels) { dictionary[label4] = i; } } if (list[value - 3].opcode == OpCodes.Dup) { return list; } Label label2 = ilg.DefineLabel(); Label label3 = ilg.DefineLabel(); list[num + 1].labels.Add(label2); list.InsertRange(num + 1, (IEnumerable)(object)new CodeInstruction[11] { new CodeInstruction(OpCodes.Ldloc, (object)localBuilder), new CodeInstruction(OpCodes.Brfalse, (object)label2), val.Clone(), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.DeclaredField(typeof(InventoryGui), "m_recipeRequirementList")), new CodeInstruction(OpCodes.Ldlen, (object)null), new CodeInstruction(OpCodes.Bgt, (object)label2), new CodeInstruction(OpCodes.Ldc_I4_0, (object)null), val2.Clone(), new CodeInstruction(OpCodes.Ldc_I4_0, (object)null), new CodeInstruction(OpCodes.Br, (object)label3) }); list.InsertRange(value - 2, (IEnumerable)(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Dup, (object)null) { labels = new List