Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of QOL KPX v2.16.0
QOL_KPX.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("QOL_KPX")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("2.16.0.0")] [assembly: AssemblyInformationalVersion("2.16.0+b7f5e8396792dd212c73a0c4ce8f758bfce82d7d")] [assembly: AssemblyProduct("QOL_KPX")] [assembly: AssemblyTitle("QOL_KPX")] [assembly: AssemblyVersion("2.16.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 QolKpx { internal static class Archery { internal static float StaminaReduction = 0.5f; internal static float AccuracyBonus = 1f; internal static bool Enabled = true; private static Player Local => Player.m_localPlayer; private static float Factor => ((Character)Local).GetSkillFactor((SkillType)8); private static bool IsLocalBow(Character c, ItemData weapon) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Invalid comparison between Unknown and I4 if (Enabled && (Object)(object)Local != (Object)null && (Object)(object)c == (Object)(object)Local && weapon != null) { return (int)weapon.m_shared.m_skillType == 8; } return false; } [HarmonyPatch(typeof(ItemData), "GetDrawStaminaDrain")] [HarmonyPostfix] private static void DrawDrain(ItemData __instance, ref float __result) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 try { if (Enabled && !(__result <= 0f) && !((Object)(object)Local == (Object)null) && (int)__instance.m_shared.m_skillType == 8) { __result *= 1f - Factor * StaminaReduction; } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha na stamina do arco: " + ex.Message)); } } [HarmonyPatch(typeof(Attack), "GetAttackStamina")] [HarmonyPostfix] private static void ShotStamina(ref float __result, Character ___m_character, ItemData ___m_weapon) { try { if (!(__result <= 0f) && IsLocalBow(___m_character, ___m_weapon)) { __result *= 1f - Factor * StaminaReduction; } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha na stamina do disparo: " + ex.Message)); } } [HarmonyPatch(typeof(Attack), "FireProjectileBurst")] [HarmonyPrefix] private static void AimBefore(Character ___m_character, ItemData ___m_weapon, out float __state) { __state = float.NaN; try { if (IsLocalBow(___m_character, ___m_weapon)) { Attack attack = ___m_weapon.m_shared.m_attack; __state = attack.m_projectileAccuracy; attack.m_projectileAccuracy = Mathf.Lerp(attack.m_projectileAccuracy, attack.m_projectileAccuracyMin, Mathf.Clamp01(Factor * AccuracyBonus)); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha na precisão do arco: " + ex.Message)); } } [HarmonyPatch(typeof(Attack), "FireProjectileBurst")] [HarmonyPostfix] private static void AimAfter(ItemData ___m_weapon, float __state) { if (!float.IsNaN(__state) && ___m_weapon != null) { ___m_weapon.m_shared.m_attack.m_projectileAccuracy = __state; } } } internal static class BlastFurnace { internal struct Saved { internal bool active; internal float seconds; internal int fuel; } internal static bool Enabled = true; internal static float Efficiency = 0.5f; private const string Furnace = "blastfurnace"; private const string Smelter = "smelter"; private static readonly HashSet<string> borrowed = new HashSet<string>(); private static readonly Func<Smelter, string> QueuedOre = AccessTools.MethodDelegate<Func<Smelter, string>>(AccessTools.Method(typeof(Smelter), "GetQueuedOre", (Type[])null, (Type[])null), (object)null, true); [HarmonyPatch(typeof(ZNetScene), "Awake")] [HarmonyPostfix] private static void Teach(ZNetScene __instance) { try { if (!Enabled || (Object)(object)__instance == (Object)null) { return; } Smelter val = Component(__instance, "blastfurnace"); Smelter val2 = Component(__instance, "smelter"); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return; } borrowed.Clear(); foreach (ItemConversion item in val2.m_conversion) { if ((Object)(object)item?.m_from != (Object)null && (Object)(object)item.m_to != (Object)null) { borrowed.Add(((Object)((Component)item.m_from).gameObject).name); } } HashSet<string> hashSet = new HashSet<string>(); foreach (ItemConversion item2 in val.m_conversion) { if ((Object)(object)item2?.m_from != (Object)null) { hashSet.Add(((Object)((Component)item2.m_from).gameObject).name); } } int num = 0; foreach (ItemConversion item3 in val2.m_conversion) { if (!((Object)(object)item3?.m_from == (Object)null) && !((Object)(object)item3.m_to == (Object)null) && hashSet.Add(((Object)((Component)item3.m_from).gameObject).name)) { val.m_conversion.Add(item3); num++; } } Debug.Log((object)("[QOL KPX] [BlastFurnace] minérios com desconto: " + borrowed.Count + ", receitas novas: " + num)); } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao ensinar o alto-forno: " + ex.Message)); } } private static Smelter Component(ZNetScene scene, string prefabName) { GameObject prefab = scene.GetPrefab(prefabName); if (!((Object)(object)prefab != (Object)null)) { return null; } return prefab.GetComponent<Smelter>(); } [HarmonyPatch(typeof(Smelter), "UpdateSmelter")] [HarmonyPrefix] private static void Cheaper(Smelter __instance, out Saved __state) { __state = default(Saved); try { if (Enabled && !(Efficiency <= 0f) && !(Efficiency >= 1f) && !((Object)(object)__instance == (Object)null) && borrowed.Count != 0 && !(Utils.GetPrefabName(((Component)__instance).gameObject) != "blastfurnace") && borrowed.Contains(QueuedOre(__instance))) { __state.active = true; __state.seconds = __instance.m_secPerProduct; __state.fuel = __instance.m_fuelPerProduct; __instance.m_secPerProduct *= Efficiency; __instance.m_fuelPerProduct = Mathf.Max(1, Mathf.RoundToInt((float)__state.fuel * Efficiency)); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no desconto do alto-forno: " + ex.Message)); } } [HarmonyPatch(typeof(Smelter), "UpdateSmelter")] [HarmonyFinalizer] private static void Restore(Smelter __instance, Saved __state) { if (__state.active && !((Object)(object)__instance == (Object)null)) { __instance.m_secPerProduct = __state.seconds; __instance.m_fuelPerProduct = __state.fuel; } } } internal static class Bronze { internal static bool Enabled = true; internal static float Ratio = 1f; private const string Item = "Bronze"; [HarmonyPatch(typeof(ObjectDB), "Awake")] [HarmonyPostfix] private static void OnDbAwake(ObjectDB __instance) { Rebalance(__instance); } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] [HarmonyPostfix] private static void OnDbCopied(ObjectDB __instance) { Rebalance(__instance); } private static void Rebalance(ObjectDB db) { try { if (!Enabled || db?.m_recipes == null) { return; } foreach (Recipe recipe in db.m_recipes) { if ((Object)(object)recipe?.m_item == (Object)null || ((Object)((Component)recipe.m_item).gameObject).name != "Bronze" || recipe.m_resources == null || recipe.m_resources.Length == 0) { continue; } int num = 0; Requirement[] resources = recipe.m_resources; foreach (Requirement val in resources) { if ((Object)(object)val?.m_resItem != (Object)null) { num += val.m_amount; } } if (num > 0) { int num2 = Mathf.Max(1, Mathf.RoundToInt((float)num * Ratio)); if (recipe.m_amount != num2) { Debug.Log((object)$"[QOL KPX] bronze: {num} de entrada passa a render {num2} (era {recipe.m_amount})"); recipe.m_amount = num2; } } } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao ajustar o bronze: " + ex.Message)); } } } internal static class BuildAnywhere { internal static bool Enabled = true; [HarmonyPatch(typeof(Location), "IsInsideNoBuildLocation")] [HarmonyPrefix] private static bool Open(ref bool __result) { if (!Enabled) { return true; } __result = false; return false; } } internal static class Building { internal static bool Enabled = true; internal static float Multiplier = 3f; [HarmonyPatch(typeof(WearNTear), "GetMaterialProperties")] [HarmonyPostfix] private static void Reinforce(ref float maxSupport, ref float horizontalLoss, ref float verticalLoss) { try { if (Enabled && !(Multiplier <= 0f)) { maxSupport *= Multiplier; horizontalLoss /= Multiplier; verticalLoss /= Multiplier; } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no limite de construção: " + ex.Message)); } } } internal static class BuildTools { internal static bool NoStamina = true; internal static bool NoDurability = true; internal static bool NoMoveStamina = true; private static bool IsLocal(Player p) { if ((Object)(object)p != (Object)null) { return (Object)(object)p == (Object)(object)Player.m_localPlayer; } return false; } [HarmonyPatch(typeof(Player), "UseStamina")] [HarmonyPrefix] private static bool FreeWhileBuilding(Player __instance) { if (!NoMoveStamina || !IsLocal(__instance) || !((Character)__instance).InPlaceMode()) { return true; } return false; } [HarmonyPatch(typeof(Player), "GetBuildStamina")] [HarmonyPostfix] private static void NoBuildStamina(Player __instance, ref float __result) { if (NoStamina && IsLocal(__instance)) { __result = 0f; } } [HarmonyPatch(typeof(Player), "GetPlaceDurability")] [HarmonyPostfix] private static void NoPlaceWear(Player __instance, ref float __result) { if (NoDurability && IsLocal(__instance)) { __result = 0f; } } [HarmonyPatch(typeof(Player), "Repair")] [HarmonyPrefix] private static void KeepWear(ItemData __0, out float __state) { __state = __0?.m_durability ?? (-1f); } [HarmonyPatch(typeof(Player), "Repair")] [HarmonyPostfix] private static void RestoreWear(Player __instance, ItemData __0, float __state) { if (NoDurability && __state >= 0f && __0 != null && IsLocal(__instance)) { __0.m_durability = __state; } } } internal static class Charcoal { internal static bool Enabled = true; internal static int KilnCapacity = 100; internal static string WeightList = "Wood:1,RoundLog:5,FineWood:8,ElderBark:10,YggdrasilWood:15,Blackwood:20,Frostwood:25"; private const string CoalName = "Coal"; private static readonly FieldRef<Smelter, ZNetView> NView = AccessTools.FieldRefAccess<Smelter, ZNetView>("m_nview"); private static readonly Func<Smelter, int> QueueSize = AccessTools.MethodDelegate<Func<Smelter, int>>(AccessTools.Method(typeof(Smelter), "GetQueueSize", (Type[])null, (Type[])null), (object)null, true); private static readonly Func<Smelter, Inventory, ItemData> FindCookable = AccessTools.MethodDelegate<Func<Smelter, Inventory, ItemData>>(AccessTools.Method(typeof(Smelter), "FindCookableItem", (Type[])null, (Type[])null), (object)null, true); private static readonly Dictionary<string, int> weights = new Dictionary<string, int>(); private static readonly HashSet<string> warned = new HashSet<string>(); private static string parsedFrom; private static void Parse() { if (parsedFrom == WeightList) { return; } parsedFrom = WeightList; weights.Clear(); warned.Clear(); string[] array = WeightList.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { ':' }); if (array2.Length == 2 && int.TryParse(array2[1].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && result > 0) { weights[array2[0].Trim()] = result; } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] [HarmonyPostfix] private static void Prepare(ZNetScene __instance) { //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Expected O, but got Unknown try { if (!Enabled || (Object)(object)__instance == (Object)null) { return; } Parse(); int num = 1; foreach (int value in weights.Values) { if (value > num) { num = value; } } foreach (GameObject prefab2 in __instance.m_prefabs) { Smelter val = (((Object)(object)prefab2 != (Object)null) ? prefab2.GetComponent<Smelter>() : null); if ((Object)(object)val == (Object)null || val.m_conversion == null) { continue; } ItemDrop val2 = CoalFrom(val); if ((Object)(object)val2 == (Object)null) { continue; } int num2 = 0; foreach (KeyValuePair<string, int> weight in weights) { if (!IsInput(val, weight.Key)) { GameObject prefab = __instance.GetPrefab(weight.Key); ItemDrop val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null); if (!((Object)(object)val3 == (Object)null)) { val.m_conversion.Add(new ItemConversion { m_from = val3, m_to = val2 }); num2++; } } } int maxOre = val.m_maxOre; val.m_maxOre = Mathf.Max(maxOre, Mathf.Max(KilnCapacity, num)); Debug.Log((object)("[QOL KPX] [Charcoal] " + ((Object)prefab2).name + ": carga " + maxOre + " -> " + val.m_maxOre + ", madeiras novas: " + num2)); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao preparar o forno de carvão: " + ex.Message)); } } private static ItemDrop CoalFrom(Smelter kiln) { foreach (ItemConversion item in kiln.m_conversion) { if ((Object)(object)item?.m_from != (Object)null && (Object)(object)item.m_to != (Object)null && Utils.GetPrefabName(((Component)item.m_to).gameObject) == "Coal") { return item.m_to; } } return null; } private static bool MakesCoal(Smelter smelter, string prefab) { foreach (ItemConversion item in smelter.m_conversion) { if (!((Object)(object)item?.m_from == (Object)null) && !((Object)(object)item.m_to == (Object)null) && !(Utils.GetPrefabName(((Component)item.m_from).gameObject) != prefab)) { return Utils.GetPrefabName(((Component)item.m_to).gameObject) == "Coal"; } } return false; } internal static int Weight(Smelter smelter, string prefab) { if (!Enabled || (Object)(object)smelter == (Object)null || string.IsNullOrEmpty(prefab)) { return 1; } Parse(); if (!weights.TryGetValue(prefab, out var value) || value <= 1) { return 1; } if (!MakesCoal(smelter, prefab)) { return 1; } if (value > smelter.m_maxOre && warned.Add(prefab)) { Debug.LogWarning((object)("[QOL KPX] [Charcoal] " + prefab + " pesa " + value + ", mas o forno só cabe " + smelter.m_maxOre + ": nunca vai entrar")); } return value; } internal static bool Fits(Smelter smelter, string prefab) { if ((Object)(object)smelter == (Object)null) { return false; } return QueueSize(smelter) + Weight(smelter, prefab) <= smelter.m_maxOre; } [HarmonyPatch(typeof(Smelter), "OnAddOre")] [HarmonyPrefix] private static bool OnlyWhatFits(Smelter __instance, Humanoid user, ref ItemData item, ref bool __result) { try { if (!Enabled || (Object)(object)__instance == (Object)null || (Object)(object)user == (Object)null) { return true; } Inventory inventory = user.GetInventory(); bool flag = item != null; ItemData val = item ?? FindCookable(__instance, inventory); string text = (((Object)(object)val?.m_dropPrefab != (Object)null) ? ((Object)val.m_dropPrefab).name : null); if (text == null) { return true; } if (Fits(__instance, text)) { return true; } if (!flag) { ItemData val2 = BestFit(__instance, inventory); if (val2 != null) { item = val2; return true; } } ((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null, false); __result = false; return false; } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao conferir a carga do forno: " + ex.Message)); } return true; } internal static ItemData BestFit(Smelter smelter, Inventory inv) { if ((Object)(object)smelter == (Object)null || inv == null) { return null; } ItemData result = null; int num = 0; foreach (ItemData allItem in inv.GetAllItems()) { string text = (((Object)(object)allItem?.m_dropPrefab != (Object)null) ? ((Object)allItem.m_dropPrefab).name : null); if (text != null && IsInput(smelter, text) && Fits(smelter, text)) { int num2 = Weight(smelter, text); if (num2 > num) { result = allItem; num = num2; } } } return result; } internal static bool IsInput(Smelter smelter, string prefab) { foreach (ItemConversion item in smelter.m_conversion) { if ((Object)(object)item?.m_from != (Object)null && Utils.GetPrefabName(((Component)item.m_from).gameObject) == prefab) { return true; } } return false; } [HarmonyPatch(typeof(Smelter), "QueueOre")] [HarmonyPostfix] private static void Weigh(Smelter __instance, string name, bool cheated) { try { if (!Enabled || (Object)(object)__instance == (Object)null || string.IsNullOrEmpty(name)) { return; } int num = Weight(__instance, name); if (num <= 1) { return; } ZNetView obj = NView.Invoke(__instance); ZDO val = ((obj != null) ? obj.GetZDO() : null); if (val == null) { return; } for (int i = 1; i < num; i++) { int num2 = val.GetInt(ZDOVars.s_queued, 0); if (num2 < __instance.m_maxOre) { val.Set("item" + num2, name); val.Set(ZDOVars.s_queued, num2 + 1, false); val.Set(ZDOVars.s_cheatedQueued, cheated); continue; } break; } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no peso da madeira: " + ex.Message)); } } } internal static class ChestCrafting { private class Request { internal Container Chest; internal string Name; internal int Amount; internal int Quality; internal int Tries; internal bool ForCredit; internal bool Replied; internal uint Revision; internal float Time; } internal static bool Enabled = true; internal static float Range = 50f; private const string RpcTake = "QolKpx_ChestTake"; private const string RpcTook = "QolKpx_ChestTook"; private const float ReplyTimeout = 5f; private const int MaxTries = 3; private static readonly FieldRef<Container, ZNetView> View = AccessTools.FieldRefAccess<Container, ZNetView>("m_nview"); private static readonly FieldRef<Container, uint> LoadedRevision = AccessTools.FieldRefAccess<Container, uint>("m_lastRevision"); private static readonly FieldRef<InventoryGui, float> CraftTimer = AccessTools.FieldRefAccess<InventoryGui, float>("m_craftTimer"); private static readonly FieldRef<InventoryGui, Recipe> CraftRecipe = AccessTools.FieldRefAccess<InventoryGui, Recipe>("m_craftRecipe"); private static readonly FieldRef<InventoryGui, ItemData> CraftUpgradeItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_craftUpgradeItem"); private static readonly FieldRef<InventoryGui, bool> MultiCrafting = AccessTools.FieldRefAccess<InventoryGui, bool>("m_multiCrafting"); private static readonly FieldRef<InventoryGui, ItemData> DragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem"); private static readonly FieldRef<InventoryGui, ItemData> SplitItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_splitItem"); private static readonly FieldInfo Stations = AccessTools.Field(typeof(CraftingStation), "m_allStations"); private static readonly HashSet<Container> all = new HashSet<Container>(); private static readonly List<Container> nearby = new List<Container>(); private static readonly List<CraftingStation> covering = new List<CraftingStation>(); private static float nearbyAt = -10f; private const float Refresh = 0.5f; private static readonly Dictionary<string, int> counts = new Dictionary<string, int>(); private static int countsFrame = -1; private static int depth; private static readonly Dictionary<string, int> credit = new Dictionary<string, int>(); private static readonly Dictionary<string, ItemDrop> prefabs = new Dictionary<string, ItemDrop>(); private static readonly Dictionary<int, Request> requests = new Dictionary<int, Request>(); private static readonly List<int> finished = new List<int>(); private static int nextId; private static Player Local => Player.m_localPlayer; [HarmonyPatch(typeof(Container), "Awake")] [HarmonyPostfix] private static void Track(Container __instance) { try { if ((Object)(object)__instance == (Object)null || __instance.GetInventory() == null) { return; } all.Add(__instance); ZNetView val = View.Invoke(__instance); if (!((Object)(object)val == (Object)null)) { Container chest = __instance; val.Register<string, int, int, int>("QolKpx_ChestTake", (Method<string, int, int, int>)delegate(long sender, string name, int amount, int quality, int id) { OnTake(chest, sender, name, amount, quality, id); }); val.Register<int, int, bool>("QolKpx_ChestTook", (Action<long, int, int, bool>)OnTook); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao registrar baú: " + ex.Message)); } } [HarmonyPatch(typeof(Player), "HaveRequirementItems")] [HarmonyPrefix] private static void EnterRecipe(Player __instance, Recipe piece, bool discover, out bool __state) { __state = Enabled && (Object)(object)__instance == (Object)(object)Local && !discover && (Object)(object)piece != (Object)null && !piece.m_requireOnlyOneIngredient; if (__state) { depth++; } } [HarmonyPatch(typeof(Player), "HaveRequirementItems")] [HarmonyFinalizer] private static void LeaveRecipe(bool __state) { if (__state) { depth--; } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] [HarmonyPrefix] private static void EnterBuild(Player __instance, RequirementMode mode, out bool __state) { //IL_0015: 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_001a: Invalid comparison between Unknown and I4 __state = Enabled && (Object)(object)__instance == (Object)(object)Local && ((int)mode == 0 || (int)mode == 2); if (__state) { depth++; } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] [HarmonyFinalizer] private static void LeaveBuild(bool __state) { if (__state) { depth--; } } [HarmonyPatch(typeof(InventoryGui), "SetupRequirement")] [HarmonyPrefix] private static void EnterPanel(Player player, out bool __state) { __state = Enabled && (Object)(object)player != (Object)null && (Object)(object)player == (Object)(object)Local; if (__state) { depth++; } } [HarmonyPatch(typeof(InventoryGui), "SetupRequirement")] [HarmonyFinalizer] private static void LeavePanel(bool __state) { if (__state) { depth--; } } [HarmonyPatch(typeof(Inventory), "CountItems")] [HarmonyPostfix] private static void AddStock(Inventory __instance, string name, int quality, bool matchWorldLevel, ref int __result) { try { if (depth > 0 && name != null && !((Object)(object)Local == (Object)null) && __instance == ((Humanoid)Local).GetInventory()) { __result += Stock(name, quality, matchWorldLevel); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao contar os baús: " + ex.Message)); } } [HarmonyPatch(typeof(Inventory), "HaveItem", new Type[] { typeof(string), typeof(bool) })] [HarmonyPostfix] private static void HaveStock(Inventory __instance, string name, bool matchWorldLevel, ref bool __result) { try { if (!__result && depth > 0 && name != null && !((Object)(object)Local == (Object)null) && __instance == ((Humanoid)Local).GetInventory()) { __result = Stock(name, -1, matchWorldLevel) > 0; } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao contar os baús: " + ex.Message)); } } internal static int Reachable(string name) { try { return (Enabled && name != null && (Object)(object)Local != (Object)null) ? Stock(name, -1, matchWorldLevel: true) : 0; } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao ler o estoque dos baús: " + ex.Message)); return 0; } } private static int Stock(string name, int quality, bool matchWorldLevel) { if (countsFrame != Time.frameCount) { counts.Clear(); countsFrame = Time.frameCount; } string key = name + "|" + quality + (matchWorldLevel ? "|1" : "|0"); if (counts.TryGetValue(key, out var value)) { return value; } value = ((quality <= 1 && credit.TryGetValue(name, out var value2)) ? value2 : 0); foreach (Container item in Nearby(force: false)) { if (Valid(item)) { value += Available(item, name, quality, matchWorldLevel); } } counts[key] = value; return value; } private static int Available(Container c, string name, int quality, bool matchWorldLevel) { int num = c.GetInventory().CountItems(name, quality, matchWorldLevel); foreach (Request value in requests.Values) { if ((Object)(object)value.Chest == (Object)(object)c && value.Name == name) { num -= value.Amount; } } return Mathf.Max(0, num); } [HarmonyPatch(typeof(InventoryGui), "OnCraftPressed")] [HarmonyPostfix] private static void PayOnClick(InventoryGui __instance) { try { Player local = Local; if (Enabled && !((Object)(object)local == (Object)null) && CraftTimer.Invoke(__instance) == 0f) { Recipe val = CraftRecipe.Invoke(__instance); if (!((Object)(object)val == (Object)null) && !val.m_requireOnlyOneIngredient && !local.NoCostCheat() && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)25)) { ItemData val2 = CraftUpgradeItem.Invoke(__instance); int qualityLevel = ((val2 == null) ? 1 : (val2.m_quality + 1)); int multiplier = ((!MultiCrafting.Invoke(__instance)) ? 1 : __instance.m_multiCraftAmount); Pay(local, val.m_resources, qualityLevel, -1, multiplier, toCredit: true); } } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao pagar a fabricação: " + ex.Message)); } } [HarmonyPatch(typeof(InventoryGui), "Update")] [HarmonyPostfix] private static void Settle(InventoryGui __instance) { try { Expire(); if (credit.Count == 0 || CraftTimer.Invoke(__instance) >= 0f) { return; } foreach (Request value in requests.Values) { if (value.ForCredit && !value.Replied) { return; } } Refund(); } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao devolver material: " + ex.Message)); } } private static void Refund() { Player local = Local; if ((Object)(object)local != (Object)null) { foreach (KeyValuePair<string, int> item in credit) { if (item.Value > 0 && prefabs.TryGetValue(item.Key, out var value) && !((Object)(object)value == (Object)null)) { ((Humanoid)local).GetInventory().AddItem(((Object)((Component)value).gameObject).name, item.Value, 1, 0, 0L, "", false, false); } } } credit.Clear(); countsFrame = -1; } [HarmonyPatch(typeof(Player), "ConsumeResources")] [HarmonyPrefix] private static bool Consume(Player __instance, Requirement[] requirements, int qualityLevel, int itemQuality, int multiplier) { try { if (!Enabled || (Object)(object)__instance != (Object)(object)Local || requirements == null) { return true; } Pay(__instance, requirements, qualityLevel, itemQuality, multiplier, toCredit: false); return false; } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao tirar recursos dos baús: " + ex.Message)); return true; } } private static void Pay(Player player, Requirement[] requirements, int qualityLevel, int itemQuality, int multiplier, bool toCredit) { CraftingStation currentCraftingStation = player.GetCurrentCraftingStation(); Inventory inventory = ((Humanoid)player).GetInventory(); List<Container> list = null; foreach (Requirement val in requirements) { if (val == null || !Object.op_Implicit((Object)(object)val.m_resItem) || (((Object)(object)currentCraftingStation != (Object)null) ? (currentCraftingStation.m_upgrader != val.m_upgraderResource) : val.m_upgraderResource)) { continue; } int num = val.GetAmount(qualityLevel) * multiplier; if (num <= 0) { continue; } string name = val.m_resItem.m_itemData.m_shared.m_name; prefabs[name] = val.m_resItem; if (!toCredit && credit.TryGetValue(name, out var value)) { int num2 = Mathf.Min(value, num); credit[name] = value - num2; num -= num2; } int num3 = Mathf.Min(num, inventory.CountItems(name, itemQuality, true)); if (num3 > 0) { inventory.RemoveItem(name, num3, itemQuality, true); num -= num3; if (toCredit) { AddCredit(name, num3); } } if (num <= 0) { continue; } if (list == null) { list = Nearby(force: true); } foreach (Container item in list) { if (num <= 0) { break; } num -= Withdraw(item, name, num, itemQuality, toCredit); } } countsFrame = -1; } private static void AddCredit(string name, int amount) { credit.TryGetValue(name, out var value); credit[name] = value + amount; } private static int Withdraw(Container c, string name, int amount, int quality, bool toCredit) { if (!Valid(c)) { return 0; } int num = Mathf.Min(amount, Available(c, name, quality, matchWorldLevel: true)); if (num <= 0) { return 0; } ZNetView val = View.Invoke(c); if (!val.GetZDO().HasOwner()) { val.ClaimOwnership(); } if (val.IsOwner()) { num = TakeFrom(c, name, num, quality); if (toCredit) { AddCredit(name, num); } return num; } Send(new Request { Chest = c, Name = name, Amount = num, Quality = quality, ForCredit = toCredit, Revision = LoadedRevision.Invoke(c), Time = Time.time }); if (toCredit) { AddCredit(name, num); } return num; } private static void Send(Request r) { int num = ++nextId; r.Tries++; r.Time = Time.time; requests[num] = r; View.Invoke(r.Chest).InvokeRPC("QolKpx_ChestTake", new object[4] { r.Name, r.Amount, r.Quality, num }); } private static void OnTake(Container c, long sender, string name, int amount, int quality, int id) { int num = 0; bool flag = false; try { ZNetView val = View.Invoke(c); if ((Object)(object)val == (Object)null || !val.IsValid() || !val.IsOwner()) { flag = true; } else { num = TakeFrom(c, name, amount, quality); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao atender pedido de baú: " + ex.Message)); } try { ZNetView obj = View.Invoke(c); if (obj != null) { obj.InvokeRPC(sender, "QolKpx_ChestTook", new object[3] { id, num, flag }); } } catch (Exception ex2) { Debug.LogWarning((object)("[QOL KPX] falha ao responder pedido de baú: " + ex2.Message)); } } private static int TakeFrom(Container c, string name, int amount, int quality) { Inventory inventory = c.GetInventory(); InventoryGui instance = InventoryGui.instance; ItemData val = (((Object)(object)instance != (Object)null) ? DragItem.Invoke(instance) : null); ItemData val2 = (((Object)(object)instance != (Object)null) ? SplitItem.Invoke(instance) : null); int num = 0; ItemData[] array = inventory.GetAllItems().ToArray(); foreach (ItemData val3 in array) { if (num >= amount) { break; } if (val3 != val && val3 != val2 && !(val3.m_shared.m_name != name) && (quality < 0 || val3.m_quality == quality) && val3.m_worldLevel >= Game.m_worldLevel) { int num2 = Mathf.Min(val3.m_stack, amount - num); if (inventory.RemoveItem(val3, num2)) { num += num2; } } } return num; } private static void OnTook(long sender, int id, int removed, bool notOwner) { try { if (!requests.TryGetValue(id, out var value)) { return; } if (notOwner && value.Tries < 3 && Valid(value.Chest)) { requests.Remove(id); Send(value); return; } if (removed < value.Amount) { if (value.ForCredit) { AddCredit(value.Name, removed - value.Amount); } else { Debug.LogWarning((object)$"[QOL KPX] baú entregou {removed} de {value.Amount} {value.Name}"); } } value.Amount = removed; value.Replied = true; countsFrame = -1; } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao ler resposta de baú: " + ex.Message)); } } private static void Expire() { if (requests.Count == 0) { return; } finished.Clear(); foreach (KeyValuePair<int, Request> request in requests) { Request value = request.Value; if ((Object)(object)value.Chest == (Object)null) { finished.Add(request.Key); } else if (value.Replied) { if (value.Amount <= 0 || LoadedRevision.Invoke(value.Chest) != value.Revision || Time.time - value.Time > 5f) { finished.Add(request.Key); } } else if (Time.time - value.Time > 5f) { if (value.ForCredit) { AddCredit(value.Name, -value.Amount); } Debug.LogWarning((object)$"[QOL KPX] baú não respondeu ao pedido de {value.Amount} {value.Name}"); finished.Add(request.Key); } } foreach (int item in finished) { requests.Remove(item); } if (finished.Count > 0) { countsFrame = -1; } } private static List<Container> Nearby(bool force) { //IL_0065: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_0139: Unknown result type (might be due to invalid IL or missing references) if (!force && Time.time - nearbyAt < 0.5f) { return nearby; } nearbyAt = Time.time; nearby.Clear(); Player local = Local; List<CraftingStation> list = Stations?.GetValue(null) as List<CraftingStation>; if ((Object)(object)local == (Object)null || list == null) { return nearby; } Vector3 position = ((Component)local).transform.position; covering.Clear(); foreach (CraftingStation item in list) { if ((Object)(object)item != (Object)null && Flat(((Component)item).transform.position, position) < item.GetStationBuildRange()) { covering.Add(item); } } if (covering.Count == 0) { return nearby; } all.RemoveWhere((Container c) => (Object)(object)c == (Object)null); foreach (Container item2 in all) { if (Allowed(item2) && Flat(((Component)item2).transform.position, position) <= Range) { nearby.Add(item2); } } return nearby; } internal static IEnumerable<Container> All() { all.RemoveWhere((Container c) => (Object)(object)c == (Object)null); return all; } internal static float Flat(Vector3 a, Vector3 b) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) a.y = b.y; return Vector3.Distance(a, b); } internal static bool Allowed(Container c) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Invalid comparison between Unknown and I4 if (c.GetInventory() == null) { return false; } if (Object.op_Implicit((Object)(object)((Component)c).GetComponent<TombStone>()) || Object.op_Implicit((Object)(object)((Component)c).GetComponent<Smelter>())) { return false; } if (c.m_checkGuardStone && !PrivateArea.CheckAccess(((Component)c).transform.position, 0f, false, false)) { return false; } PrivacySetting privacy = c.m_privacy; if ((int)privacy != 0) { if ((int)privacy == 2) { return true; } return false; } Piece component = ((Component)c).GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { return component.GetCreator() == Game.instance.GetPlayerProfile().GetPlayerID(); } return false; } private static bool Valid(Container c) { if ((Object)(object)c == (Object)null) { return false; } ZNetView val = View.Invoke(c); if ((Object)(object)val != (Object)null) { return val.IsValid(); } return false; } } internal static class CookTime { internal static bool Enabled = true; private const int NotDone = 0; private const int Done = 1; private const int Burnt = 2; private static readonly FieldRef<CookingStation, ZNetView> CookView = AccessTools.FieldRefAccess<CookingStation, ZNetView>("m_nview"); private static readonly FieldRef<Fermenter, ZNetView> BarrelView = AccessTools.FieldRefAccess<Fermenter, ZNetView>("m_nview"); [HarmonyPatch(typeof(CookingStation), "GetHoverText")] [HarmonyPostfix] private static void CookingLeft(CookingStation __instance, ref string __result) { try { if (!Enabled || string.IsNullOrEmpty(__result) || (Object)(object)__instance == (Object)null) { return; } ZNetView val = CookView.Invoke(__instance); if ((Object)(object)val == (Object)null || !val.IsValid()) { return; } ZDO zDO = val.GetZDO(); string text = ""; for (int i = 0; i < __instance.m_slots.Length; i++) { string text2 = zDO.GetString("slot" + i, ""); if (string.IsNullOrEmpty(text2)) { continue; } int num = zDO.GetInt("slotstatus" + i, 0); string text3 = Name(text2); switch (num) { case 2: text = text + "\n" + text3 + ": burnt"; continue; case 1: text = text + "\n" + text3 + ": ready"; continue; } ItemConversion val2 = Conversion(__instance, text2); if (val2 != null) { float seconds = val2.m_cookTime - zDO.GetFloat("slot" + i, 0f); text = text + "\n" + text3 + ": ready in " + Spell(seconds); } } if (text.Length > 0) { __result = Insert(__result, text); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no tempo da fogueira: " + ex.Message)); } } [HarmonyPatch(typeof(Fermenter), "GetHoverText")] [HarmonyPostfix] private static void FermentingLeft(Fermenter __instance, ref string __result) { try { if (!Enabled || string.IsNullOrEmpty(__result) || (Object)(object)__instance == (Object)null || (Object)(object)ZNet.instance == (Object)null) { return; } ZNetView val = BarrelView.Invoke(__instance); if ((Object)(object)val == (Object)null || !val.IsValid()) { return; } long num = val.GetZDO().GetLong(ZDOVars.s_startTime, 0L); if (num != 0L) { double totalSeconds = (ZNet.instance.GetTime() - new DateTime(num)).TotalSeconds; float num2 = __instance.m_fermentationDuration - (float)totalSeconds; if (!(num2 <= 0f)) { __result = Insert(__result, "\nReady in " + Spell(num2)); } } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no tempo do fermentador: " + ex.Message)); } } private static string Insert(string hover, string lines) { int num = hover.IndexOf("\n["); if (num >= 0) { return hover.Substring(0, num) + lines + hover.Substring(num); } return hover + lines; } private static ItemConversion Conversion(CookingStation station, string itemName) { foreach (ItemConversion item in station.m_conversion) { if ((Object)(object)item?.m_from != (Object)null && ((Object)item.m_from).name == itemName) { return item; } } return null; } private static string Name(string prefab) { GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(prefab) : null); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if (!((Object)(object)val2 != (Object)null)) { return prefab; } return Localization.instance.Localize(val2.m_itemData.m_shared.m_name); } private static string Spell(float seconds) { int num = Mathf.Max(0, Mathf.CeilToInt(seconds)); int num2 = num / 3600; int num3 = num % 3600 / 60; int num4 = num % 60; if (num2 > 0) { if (num3 <= 0) { return num2 + "h"; } return num2 + "h " + num3 + "m"; } if (num3 > 0) { if (num4 <= 0) { return num3 + "m"; } return num3 + "m " + num4 + "s"; } return num4 + "s"; } } internal static class CraftAmount { internal static bool Enabled = true; internal static int Cap = 999; private const float Gap = 8f; private const float KeyShare = 0.2f; private static readonly FieldRef<InventoryGui, bool> TouchMulti = AccessTools.FieldRefAccess<InventoryGui, bool>("m_touchMultiCrafting"); private static readonly FieldRef<InventoryGui, float> CraftTimer = AccessTools.FieldRefAccess<InventoryGui, float>("m_craftTimer"); private static readonly FieldInfo Selected = AccessTools.Field(typeof(InventoryGui), "m_selectedRecipe"); private static readonly PropertyInfo PairRecipe = ((Selected != null) ? Selected.FieldType.GetProperty("Recipe") : null); private static readonly PropertyInfo PairItem = ((Selected != null) ? Selected.FieldType.GetProperty("ItemData") : null); private static InventoryGui built; private static Button less; private static Button more; private static Recipe current; private static int amount = 1; private static int max = 1; private static int vanillaAmount = 1; [HarmonyPatch(typeof(InventoryGui), "Show")] [HarmonyPostfix] private static void Build(InventoryGui __instance) { //IL_0087: 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) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //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_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013d: 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_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) try { if (!Enabled || (Object)(object)__instance == (Object)null) { return; } if ((Object)(object)built == (Object)(object)__instance && (Object)(object)less != (Object)null) { amount = 1; current = null; } else { if ((Object)(object)__instance.m_craftButton == (Object)null) { return; } RectTransform component = ((Component)__instance.m_craftButton).GetComponent<RectTransform>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)((Transform)component).parent == (Object)null)) { vanillaAmount = __instance.m_multiCraftAmount; Rect rect = component.rect; float width = ((Rect)(ref rect)).width; float num = Mathf.Max(28f, (width - 16f) * 0.2f); Vector2 offsetMin = component.offsetMin; Vector2 offsetMax = component.offsetMax; less = Key(__instance, "-", offsetMin, new Vector2(offsetMax.x - (width - num), offsetMax.y), -1); more = Key(__instance, "+", new Vector2(offsetMin.x + (width - num), offsetMin.y), offsetMax, 1); component.offsetMin = new Vector2(offsetMin.x + num + 8f, offsetMin.y); component.offsetMax = new Vector2(offsetMax.x - num - 8f, offsetMax.y); TMP_Text componentInChildren = ((Component)__instance.m_craftButton).GetComponentInChildren<TMP_Text>(); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.enableAutoSizing = true; componentInChildren.fontSizeMin = 12f; } Show(on: false); built = __instance; amount = 1; current = null; string[] obj = new string[6] { "[QOL KPX] [CraftAmount] teclas de ", num.ToString(), " e botão de ", null, null, null }; rect = component.rect; obj[3] = ((Rect)(ref rect)).width.ToString(); obj[4] = " na linha de "; obj[5] = width.ToString(); Debug.Log((object)string.Concat(obj)); } } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao montar o seletor de quantidade: " + ex.Message)); } } private static Button Key(InventoryGui gui, string caption, Vector2 min, Vector2 max, int by) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: 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_006d: Expected O, but got Unknown //IL_007c: 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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Expected O, but got Unknown //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0177: 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_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0183: 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) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) RectTransform component = ((Component)gui.m_craftButton).GetComponent<RectTransform>(); GameObject val = new GameObject((by < 0) ? "QolKpxLess" : "QolKpxMore", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent(((Transform)component).parent, false); val2.anchorMin = component.anchorMin; val2.anchorMax = component.anchorMax; val2.pivot = component.pivot; val2.offsetMin = min; val2.offsetMax = max; Image component2 = ((Component)gui.m_craftButton).GetComponent<Image>(); Image component3 = val.GetComponent<Image>(); if ((Object)(object)component2 != (Object)null) { component3.sprite = component2.sprite; component3.type = component2.type; ((Graphic)component3).color = ((Graphic)component2).color; } Button component4 = val.GetComponent<Button>(); ((Selectable)component4).targetGraphic = (Graphic)(object)component3; ((Selectable)component4).transition = ((Selectable)gui.m_craftButton).transition; ((Selectable)component4).colors = ((Selectable)gui.m_craftButton).colors; ((UnityEvent)component4.onClick).AddListener((UnityAction)delegate { Step(by); }); GameObject val3 = new GameObject("Text", new Type[1] { typeof(RectTransform) }); RectTransform val4 = (RectTransform)val3.transform; ((Transform)val4).SetParent((Transform)(object)val2, false); val4.anchorMin = Vector2.zero; val4.anchorMax = Vector2.one; Vector2 offsetMin = (val4.offsetMax = Vector2.zero); val4.offsetMin = offsetMin; TextMeshProUGUI obj = val3.AddComponent<TextMeshProUGUI>(); ((TMP_Text)obj).font = Font(gui); ((TMP_Text)obj).fontSize = 26f; ((Graphic)obj).color = Color.white; ((TMP_Text)obj).alignment = (TextAlignmentOptions)514; ((Graphic)obj).raycastTarget = false; ((TMP_Text)obj).text = caption; return component4; } private static TMP_FontAsset Font(InventoryGui gui) { TMP_Text componentInChildren = ((Component)gui.m_craftButton).GetComponentInChildren<TMP_Text>(); if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.font != (Object)null) { return componentInChildren.font; } if (!((Object)(object)gui.m_recipeName != (Object)null)) { return null; } return gui.m_recipeName.font; } private static void Show(bool on) { if ((Object)(object)less != (Object)null) { ((Component)less).gameObject.SetActive(on); } if ((Object)(object)more != (Object)null) { ((Component)more).gameObject.SetActive(on); } } private static void Step(int by) { int num = amount; amount = Mathf.Clamp(amount + by, 1, Mathf.Max(1, max)); if (amount != num) { Debug.Log((object)("[QOL KPX] [CraftAmount] quantidade " + amount + " de no máximo " + max)); } } [HarmonyPatch(typeof(InventoryGui), "UpdateRecipe")] [HarmonyPrefix] private static void Dial(InventoryGui __instance, Player player) { try { if (!Enabled || (Object)(object)__instance == (Object)null || (Object)(object)less == (Object)null || (Object)(object)built != (Object)(object)__instance) { return; } if (CraftTimer.Invoke(__instance) >= 0f) { Show(on: false); return; } Recipe val = SelectedRecipe(__instance); bool flag = SelectedItem(__instance) != null; bool flag2 = (Object)(object)val != (Object)null && !flag && __instance.InCraftTab(); if ((Object)(object)val != (Object)(object)current) { current = val; amount = 1; max = ((!flag2) ? 1 : Limit(player, val)); if (flag2) { Debug.Log((object)("[QOL KPX] [CraftAmount] " + val.m_item.m_itemData.m_shared.m_name + ": dá para fazer " + max)); } } Show(flag2); amount = ((!flag2) ? 1 : Mathf.Clamp(amount, 1, Mathf.Max(1, max))); bool flag3 = flag2 && amount > 1; __instance.m_multiCraftAmount = (flag3 ? amount : vanillaAmount); TouchMulti.Invoke(__instance) = flag3; } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no seletor de quantidade: " + ex.Message)); } } [HarmonyPatch(typeof(InventoryGui), "DoCrafting")] [HarmonyPostfix] private static void Crafted(InventoryGui __instance, Player player) { try { if (Enabled && !((Object)(object)less == (Object)null) && !((Object)(object)built != (Object)(object)__instance)) { if (amount > 1) { Debug.Log((object)("[QOL KPX] [CraftAmount] fabricou " + amount + " de uma vez")); } max = Limit(player, SelectedRecipe(__instance)); amount = Mathf.Clamp(amount, 1, Mathf.Max(1, max)); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao recalcular a quantidade: " + ex.Message)); } } private static Recipe SelectedRecipe(InventoryGui gui) { if (Selected == null || PairRecipe == null) { return null; } object? value = PairRecipe.GetValue(Selected.GetValue(gui)); return (Recipe)((value is Recipe) ? value : null); } private static ItemData SelectedItem(InventoryGui gui) { if (Selected == null || PairItem == null) { return null; } object? value = PairItem.GetValue(Selected.GetValue(gui)); return (ItemData)((value is ItemData) ? value : null); } private static int Limit(Player player, Recipe recipe) { if ((Object)(object)player == (Object)null || (Object)(object)recipe == (Object)null || (Object)(object)recipe.m_item == (Object)null) { return 1; } if (!Fits(player, recipe, 1)) { return 1; } int num = 1; int num2 = 2; while (num2 <= Cap && Fits(player, recipe, num2)) { num = num2; num2 *= 2; } num2 = Mathf.Min(num2, Cap); while (num + 1 < num2) { int num3 = (num + num2) / 2; if (Fits(player, recipe, num3)) { num = num3; } else { num2 = num3; } } return num; } private static bool Fits(Player player, Recipe recipe, int times) { if (player.HaveRequirements(recipe, false, 1, times)) { return ((Humanoid)player).GetInventory().CanAddItem(recipe.m_item.m_itemData, times * recipe.m_amount); } return false; } } internal static class Crafting { internal static SkillType Skill; internal static float MaxDiscount = 0.25f; internal static float MaxTimeCut = 0.5f; internal static float XpPerCraft = 0.2f; internal static bool Enabled = true; private static Requirement[] lowered; private static int[] originalAmounts; private static Player Local => Player.m_localPlayer; [HarmonyPatch(typeof(Requirement), "GetAmount")] [HarmonyPostfix] private static void Discount(ref int __result) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) try { if (Enabled && __result > 1 && !((Object)(object)Local == (Object)null)) { float num = 1f - ((Character)Local).GetSkillFactor(Skill) * MaxDiscount; __result = Round((float)__result * num); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no desconto de criação: " + ex.Message)); } } private static int Discounted(int amount) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (amount <= 1 || (Object)(object)Local == (Object)null) { return amount; } float num = 1f - ((Character)Local).GetSkillFactor(Skill) * MaxDiscount; return Round((float)amount * num); } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] [HarmonyPrefix] private static void DiscountBuildCheck(Player __instance, Piece piece, RequirementMode mode) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) lowered = null; try { if (!Enabled || (Object)(object)__instance != (Object)(object)Local || (int)mode != 0) { return; } Requirement[] array = piece?.m_resources; if (array != null && array.Length != 0) { lowered = array; originalAmounts = new int[array.Length]; for (int i = 0; i < array.Length; i++) { originalAmounts[i] = array[i].m_amount; array[i].m_amount = Discounted(array[i].m_amount); } } } catch (Exception ex) { lowered = null; Debug.LogWarning((object)("[QOL KPX] falha no desconto da checagem de construção: " + ex.Message)); } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] [HarmonyFinalizer] private static void RestoreBuildCheck() { Requirement[] array = lowered; lowered = null; if (array != null) { for (int i = 0; i < array.Length && i < originalAmounts.Length; i++) { array[i].m_amount = originalAmounts[i]; } } } private static int Round(float value) { return Mathf.Max(1, Mathf.FloorToInt(value + 0.5f)); } private static void Gain() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (Enabled && !((Object)(object)Local == (Object)null)) { ((Character)Local).RaiseSkill(Skill, XpPerCraft); } } [HarmonyPatch(typeof(InventoryGui), "UpdateRecipe")] [HarmonyPrefix] private static void Faster(ref float dt) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) try { if (Enabled && !(MaxTimeCut <= 0f) && !((Object)(object)Local == (Object)null)) { float num = 1f - ((Character)Local).GetSkillFactor(Skill) * Mathf.Clamp01(MaxTimeCut); if (num > 0.05f) { dt /= num; } } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha na pressa da bancada: " + ex.Message)); } } [HarmonyPatch(typeof(InventoryGui), "DoCrafting")] [HarmonyPostfix] private static void CraftXp(Player player) { try { if ((Object)(object)player == (Object)(object)Local) { Gain(); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no XP de criação: " + ex.Message)); } } [HarmonyPatch(typeof(Player), "GetBuildStamina")] [HarmonyPostfix] private static void HammerXp(Player __instance) { try { if ((Object)(object)__instance == (Object)(object)Local) { Gain(); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no XP de martelo: " + ex.Message)); } } } internal static class Deposit { [CompilerGenerated] private static class <>O { public static UnityAction <0>__Run; } internal static bool Enabled = true; internal static float Range = 50f; internal static float OffsetX; internal static float OffsetY; private const float Lead = 10f; private const float Gap = 12f; private static readonly Vector2 Area = new Vector2(68f, 72f); private const float Window = 1.5f; private const float Guard = 15f; private static readonly HashSet<Inventory> targets = new HashSet<Inventory>(); private static readonly List<Container> chests = new List<Container>(); private static float window; private static float guard; private static int moved; private static GameObject field; private static InventoryGui built; private static bool complained; private static bool logged; private static bool fumbled; private static ItemData chosen; private static readonly FieldRef<InventoryGui, ItemData> DragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem"); private static readonly FieldRef<InventoryGui, Inventory> DragFrom = AccessTools.FieldRefAccess<InventoryGui, Inventory>("m_dragInventory"); private static readonly MethodInfo DragSetup = AccessTools.Method(typeof(InventoryGui), "SetupDragItem", (Type[])null, (Type[])null); private static readonly object[] NoDrag = new object[3] { null, null, 1 }; private static readonly FieldRef<InventoryGrid, List<InventoryElement>> Elements = AccessTools.FieldRefAccess<InventoryGrid, List<InventoryElement>>("m_elements"); private const string Caption = "Stash"; private static readonly Vector3[] corners = (Vector3[])(object)new Vector3[4]; internal static ItemData Chosen => chosen; private static Sprite Icon() { ZNetScene instance = ZNetScene.instance; GameObject val = (((Object)(object)instance != (Object)null) ? instance.GetPrefab("piece_chest_wood") : null); Piece val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Piece>() : null); if (!((Object)(object)val2 != (Object)null)) { return null; } return val2.m_icon; } private static void Dress(Transform stash) { Transform val = stash.Find("armor_icon"); Image val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Image>() : null); Sprite val3 = Icon(); if ((Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null) { val2.sprite = val3; val2.preserveAspect = true; } else { Debug.Log((object)"[QOL KPX-UI] [Deposit] sem ícone do baú; o campo fica com o escudo"); } Transform val4 = stash.Find("ac_text"); TMP_Text val5 = (((Object)(object)val4 != (Object)null) ? ((Component)val4).GetComponent<TMP_Text>() : null); if ((Object)(object)val5 != (Object)null) { val5.text = "Stash"; } else { Debug.Log((object)"[QOL KPX-UI] [Deposit] o campo não tem ac_text; fica sem texto"); } } private static void Hit(RectTransform stash) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Expected O, but got Unknown GameObject val = new GameObject("QolKpxStashHit", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); Transform transform = val.transform; Transform obj = ((transform is RectTransform) ? transform : null); obj.SetParent((Transform)(object)stash, false); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); ((RectTransform)obj).pivot = val2; Vector2 anchorMin = (((RectTransform)obj).anchorMax = val2); ((RectTransform)obj).anchorMin = anchorMin; ((RectTransform)obj).anchoredPosition = Vector2.zero; Rect rect = stash.rect; Vector2 size = ((Rect)(ref rect)).size; ((RectTransform)obj).sizeDelta = new Vector2((size.x > 1f) ? size.x : Area.x, (size.y > 1f) ? size.y : Area.y); Image component = val.GetComponent<Image>(); ((Graphic)component).color = new Color(0f, 0f, 0f, 0f); Button component2 = val.GetComponent<Button>(); ((Selectable)component2).targetGraphic = (Graphic)(object)component; ButtonClickedEvent onClick = component2.onClick; object obj2 = <>O.<0>__Run; if (obj2 == null) { UnityAction val4 = Run; <>O.<0>__Run = val4; obj2 = (object)val4; } ((UnityEvent)onClick).AddListener((UnityAction)obj2); } private static void Edges(RectTransform t, RectTransform panel, out float high, out float low) { //IL_0013: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) t.GetWorldCorners(corners); high = ((Transform)panel).InverseTransformPoint(corners[1]).y; low = ((Transform)panel).InverseTransformPoint(corners[0]).y; } private static void Drop(RectTransform t, RectTransform panel, float y) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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) Edges(t, panel, out var high, out var _); ((Transform)t).position = ((Transform)t).position + ((Transform)panel).TransformVector(new Vector3(0f, y - high, 0f)); } private static RectTransform Holder(TMP_Text text, RectTransform panel) { Transform val = (((Object)(object)text != (Object)null) ? text.transform : null); Transform val2 = val; while ((Object)(object)val2 != (Object)null && (Object)(object)val2.parent != (Object)null && (Object)(object)val2.parent != (Object)(object)panel) { val2 = val2.parent; } if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)val || (Object)(object)val2.parent != (Object)(object)panel) { return null; } return (RectTransform)(object)((val2 is RectTransform) ? val2 : null); } private static void Layout(InventoryGui gui, RectTransform panel, RectTransform stash) { //IL_011f: 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_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) InventoryGrid playerGrid = gui.m_playerGrid; List<InventoryElement> list = (((Object)(object)playerGrid != (Object)null) ? Elements.Invoke(playerGrid) : null); RectTransform val = (RectTransform)((list != null && list.Count > 0) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val == (Object)null) { return; } Edges(val, panel, out var high, out var low); float num = low - 10f; Transform obj = ((Transform)panel).Find("Armor"); RectTransform val2 = (RectTransform)(((object)((obj is RectTransform) ? obj : null)) ?? ((object)Holder(gui.m_armor, panel))); if (!((Object)(object)val2 == (Object)null)) { Edges(val2, panel, out high, out low); float num2 = high - low + 12f; Transform obj2 = ((Transform)panel).Find("Trash"); RectTransform val3 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null); RectTransform val4 = Holder(gui.m_weight, panel); Drop(val2, panel, num); int num3 = 1; if ((Object)(object)val3 != (Object)null) { Drop(val3, panel, num - num2 * (float)num3++); } if ((Object)(object)stash != (Object)null && ((Component)stash).gameObject.activeSelf) { Drop(stash, panel, num - num2 * (float)num3++); ((Transform)stash).position = ((Transform)stash).position + ((Transform)panel).TransformVector(new Vector3(OffsetX, OffsetY, 0f)); } if ((Object)(object)val4 != (Object)null) { Drop(val4, panel, num - num2 * (float)num3); } } } private static void Arrange() { if (fumbled || (Object)(object)field == (Object)null || (Object)(object)built == (Object)null) { return; } try { if (InventoryGui.IsVisible()) { RectTransform player = built.m_player; if ((Object)(object)player != (Object)null) { InventoryGui gui = built; Transform transform = field.transform; Layout(gui, player, (RectTransform)(object)((transform is RectTransform) ? transform : null)); } } } catch (Exception ex) { fumbled = true; Debug.LogWarning((object)("[QOL KPX] falha ao arrumar a coluna da mochila: " + ex.Message)); } } internal static void Tick(float dt) { Arrange(); try { if (window > 0f) { window -= dt; if (window <= 0f) { Report(); } } if (!(guard <= 0f)) { guard -= dt; if (guard <= 0f) { Lower(); } } } catch (Exception ex) { Lower(); Debug.LogWarning((object)("[QOL KPX] falha ao guardar nos baús: " + ex.Message)); } } [HarmonyPatch(typeof(InventoryGui), "Show")] [HarmonyPostfix] private static void Build(InventoryGui __instance) { //IL_012c: 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_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)__instance == (Object)null) { return; } if ((Object)(object)built == (Object)(object)__instance && (Object)(object)field != (Object)null) { field.SetActive(Enabled); return; } RectTransform player = __instance.m_player; RectTransform val = (RectTransform)(((Object)(object)player != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val == (Object)null) { if (!complained) { complained = true; Debug.LogWarning((object)("[QOL KPX] [Deposit] campo não montado: painel=" + ((Object)(object)player != (Object)null) + " armadura=" + ((Object)(object)val != (Object)null))); } return; } RectTransform val2 = Object.Instantiate<RectTransform>(val, (Transform)(object)player); ((Object)val2).name = "QolKpxStash"; ((Transform)val2).SetSiblingIndex(((Transform)val).GetSiblingIndex()); field = ((Component)val2).gameObject; field.SetActive(Enabled); Dress((Transform)(object)val2); Hit(val2); Layout(__instance, player, val2); built = __instance; if (!logged) { logged = true; RectTransform val3 = Holder(__instance.m_weight, player); string[] obj = new string[6] { $"[QOL KPX-UI] [Deposit] campo em {((Transform)val2).position} ", null, null, null, null, null }; Rect rect = val2.rect; obj[1] = $"tam={((Rect)(ref rect)).size} armadura={((Transform)val).position} "; obj[2] = "peso="; obj[3] = (((Object)(object)val3 != (Object)null) ? ((Object)val3).name : "nenhum"); obj[4] = " "; obj[5] = string.Format("lixeira={0}", (Object)(object)((Transform)player).Find("Trash") != (Object)null); Debug.Log((object)string.Concat(obj)); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao montar o campo de guardar: " + ex.Message)); } } private static ItemData Picked(InventoryGui gui) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)gui == (Object)null || (Object)(object)localPlayer == (Object)null) { return null; } ItemData val = DragItem.Invoke(gui); if (val == null || DragFrom.Invoke(gui) != ((Humanoid)localPlayer).GetInventory()) { return null; } return val; } private static bool Holds(Container chest, ItemData item) { Inventory inventory = chest.GetInventory(); if (inventory != null) { return inventory.ContainsItemByName(item.m_shared.m_name); } return false; } private static void Run() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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) try { Player localPlayer = Player.m_localPlayer; if (!Enabled || (Object)(object)localPlayer == (Object)null) { return; } InventoryGui instance = InventoryGui.instance; chosen = Picked(instance); if (chosen != null && DragSetup != null) { DragSetup.Invoke(instance, NoDrag); } Vector3 me = ((Component)localPlayer).transform.position; chests.Clear(); foreach (Container item in ChestCrafting.All()) { if (!((Object)(object)item == (Object)null) && ChestCrafting.Allowed(item) && !(ChestCrafting.Flat(((Component)item).transform.position, me) > Range) && (chosen == null || Holds(item, chosen))) { chests.Add(item); } } chests.Sort((Container a, Container b) => ChestCrafting.Flat(((Component)a).transform.position, me).CompareTo(ChestCrafting.Flat(((Component)b).transform.position, me))); targets.Clear(); moved = 0; window = 1.5f; guard = 15f; foreach (Container chest in chests) { Inventory inventory = chest.GetInventory(); if (inventory != null) { targets.Add(inventory); chest.StackAll(); } } chests.Clear(); if (targets.Count == 0) { Report(); Lower(); } } catch (Exception ex) { Lower(); Debug.LogWarning((object)("[QOL KPX] falha ao guardar nos baús: " + ex.Message)); } } [HarmonyPatch(typeof(Inventory), "StackAll")] [HarmonyPrefix] private static void Quiet(Inventory __instance, ref bool message) { if (window > 0f && targets.Contains(__instance)) { message = false; } } [HarmonyPatch(typeof(Inventory), "StackAll")] [HarmonyPostfix] private static void Count(Inventory __instance, int __result) { if (window > 0f && targets.Contains(__instance)) { moved += __result; } } private static void Report() { window = 0f; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { ((Character)localPlayer).Message((MessageType)2, (moved > 0) ? ("$msg_stackall " + moved) : "$msg_stackall_none", 0, (Sprite)null, false); } moved = 0; } internal static bool Owns(Inventory inventory) { if (guard > 0f && inventory != null) { return targets.Contains(inventory); } return false; } private static void Lower() { window = 0f; guard = 0f; moved = 0; chosen = null; targets.Clear(); chests.Clear(); } } internal static class Dust { internal static bool Enabled = true; private static readonly FieldRef<Humanoid, ItemData> RightRef = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_rightItem"); private static bool InHand() { if (!Enabled) { return false; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return false; } ItemData val = RightRef.Invoke((Humanoid)(object)localPlayer); if (val == null || val.m_shared == null) { return false; } string name = val.m_shared.m_name; if (!(name == "$item_hammer") && !(name == "$item_hoe")) { return name == "$item_cultivator"; } return true; } private static void Mute(EffectList list) { if (list == null || list.m_effectPrefabs == null) { return; } EffectData[] effectPrefabs = list.m_effectPrefabs; foreach (EffectData val in effectPrefabs) { if (val != null && val.m_enabled && (Object)(object)val.m_prefab != (Object)null && ((Object)val.m_prefab).name.StartsWith("vfx_")) { val.m_enabled = false; Debug.Log((object)("[QOL KPX] [Dust] efeito desligado: " + ((Object)val.m_prefab).name)); } } } [HarmonyPatch(typeof(Player), "PlacePiece")] [HarmonyPrefix] private static void OnPiece(Piece piece) { try { if ((Object)(object)piece != (Object)null && InHand()) { Mute(piece.m_placeEffect); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] [Dust] falha na peça: " + ex.Message)); } } [HarmonyPatch(typeof(TerrainOp), "OnPlaced")] [HarmonyPrefix] private static void OnGround(TerrainOp __instance) { try { if ((Object)(object)__instance != (Object)null && InHand()) { Mute(__instance.m_onPlacedEffect); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] [Dust] falha no terreno: " + ex.Message)); } } } internal static class Equipment { internal static readonly ItemType[] Types; internal const int Width = 10; internal const int FoodCount = 3; private const string RowsKey = "invrows"; private const int MaxRows = 9; private static int rows; private static readonly FieldRef<Inventory, int> HeightRef; private static readonly FieldRef<Inventory, int> WidthRef; private static readonly FieldRef<InventoryGrid, List<InventoryElement>> ElementsRef; private static readonly MethodInfo Changed; private static readonly object[] ChangedArgs; private static bool enabled; private static float basePanelWidth; private static Vector2 basePanelPos; private static bool logged; private static readonly Vector3[] PanelCorners; private static readonly Vector3[] CellCorners; internal static int Row => rows; internal static bool Active => enabled; internal static int FoodColumn(int i) { return Types.Length + i; } private static string IconKey(int k) { if (k >= Types.Length) { return "Food"; } return ((object)Unsafe.As<ItemType, ItemType>(ref Types[k])/*cast due to .constrained prefix*/).ToString(); } private static bool IsPlayerInv(Inventory inv) { if ((Object)(object)Player.m_localPlayer != (Object)null && inv != null) { return ((Humanoid)Player.m_localPlayer).GetInventory() == inv; } return false; } private static int SlotFor(ItemData item) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) return Array.IndexOf(Types, item.m_shared.m_itemType); } internal static bool IsFood(ItemData item) { SharedData val = item?.m_shared; if (val != null) { if (!(val.m_food > 0f) && !(val.m_foodStamina > 0f)) { return val.m_foodEitr > 0f; } return true; } return false; } internal static void EnsureSize(Inventory inv, bool on) { enabled = on; if (inv != null) { int num = (on ? 10 : 8); int num2 = (on ? (Row + 1) : Row); if (num < WidthRef.Invoke(inv)) { VacateColumns(inv, num); } if (WidthRef.Invoke(inv) != num) { WidthRef.Invoke(inv) = num; } if (HeightRef.Invoke(inv) != num2) { HeightRef.Invoke(inv) = num2; } } } private static void SetRows(Inventory inv, int want) { want = Mathf.Clamp(want, 4, 9); if (want != rows) { int num = rows; rows = want; if (inv != null) { EnsureSize(inv, enabled); Migrate(inv, num, want); Debug.Log((object)$"[QOL KPX] linhas de estoque: {num} -> {want}; linha reservada agora é a {want}"); } } } internal static void RefreshRows(Player p) { try { if (!((Object)(object)p == (Object)null)) { int want = 4; string s = default(string); if (p.TryGetUniqueKeyValue("invrows", ref s) && int.TryParse(s, out var result)) { want = result; } SetRows(((Humanoid)p).GetInventory(), want); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao ler as linhas da mochila: " + ex.Message)); } } [HarmonyPatch(typeof(Player), "SetInventorySize")] [HarmonyPrefix] private static void RowsChanged(Player __instance, int __0) { try { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { SetRows(((Humanoid)__instance).GetInventory(), __0); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao mudar o tamanho da mochila: " + ex.Message)); } } private static void Migrate(Inventory inv, int from, int to) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) try { int num = 0; foreach (ItemData item in new List<ItemData>(inv.GetAllItems())) { if (item.m_gridPos.y == from) { int x = item.m_gridPos.x; if (inv.GetItemAt(x, to) == null) { item.m_gridPos = new Vector2i(x, to); } else if (!MoveToFreeSlot(inv, item)) { continue; } num++; } } if (num > 0) { Changed?.Invoke(inv, ChangedArgs); Debug.Log((object)$"[QOL KPX] {num} item(ns) movido(s) da linha {from} para a {to}"); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao mover a linha reservada: " + ex.Message)); } } private static void VacateColumns(Inventory inv, int keep) { try { int num = 0; foreach (ItemData item in new List<ItemData>(inv.GetAllItems())) { if (item.m_gridPos.x >= keep && MoveToFreeSlot(inv, item, keep)) { num++; } } if (num > 0) { Changed?.Invoke(inv, ChangedArgs); Debug.Log((object)$"[QOL KPX] {num} item(ns) tirado(s) das colunas que seriam removidas"); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao esvaziar colunas: " + ex.Message)); } } [HarmonyPatch(typeof(Player), "Load", new Type[] { typeof(ZPackage) })] [HarmonyPrefix] private static void GrowBeforeLoad(Player __instance) { try { if ((Object)(object)__instance != (Object)null) { EnsureSize(((Humanoid)__instance).GetInventory(), enabled); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao preparar a mochila antes do load: " + ex.Message)); } } internal static void EnsurePanel(bool on, float gap) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_040f: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_playerGrid == (Object)null) { return; } RectTransform player = instance.m_player; InventoryGrid playerGrid = instance.m_playerGrid; if ((Object)(object)player == (Object)null) { return; } if (basePanelWidth <= 0f) { basePanelWidth = player.sizeDelta.x; basePanelPos = player.anchoredPosition; } List<InventoryElement> list = ElementsRef.Invoke(playerGrid); Inventory inventory = playerGrid.GetInventory(); int num = ((inventory != null) ? inventory.GetWidth() : 0); if (!on || list == null || num == 0 || list.Count < (Row + 1) * num) { instance.SetInventorySize(Row); player.sizeDelta = new Vector2(basePanelWidth, player.sizeDelta.y); player.anchoredPosition = basePanelPos; return; } float elementSpace = playerGrid.m_elementSpace; float num2 = (float)(num - 8) * elementSpace; instance.SetInventorySize(Row + 1); player.sizeDelta = new Vector2(basePanelWidth + num2, player.sizeDelta.y + gap); for (int i = 0; i < num; i++) { InventoryElement val = list[Row * num + i]; InventoryElement val2 = list[(Row - 1) * num + i]; if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { continue; } Transform transform = ((Component)val).transform; RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null); Transform transform2 = ((Component)val2).transform; RectTransform val4 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null); if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val4 == (Object)null)) { val3.anchoredPosition = new Vector2(val4.anchoredPosition.x, val4.anchoredPosition.y - elementSpace - gap); if (i < Types.Length + 3) { SlotIcons.Apply((Transform)(object)val3, IconKey(i)); } } } if (num >= 10) { InventoryElement obj = list[9]; object obj2; if (obj == null) { obj2 = null; } else { Transform obj3 = ((Component)obj).transform.Find("binding"); obj2 = ((obj3 != null) ? ((Component)obj3).GetComponent<TMP_Text>() : null); } TMP_Text val5 = (TMP_Text)obj2; if ((Object)(object)val5 != (Object)null && val5.text != "0") { val5.text = "0"; } } InventoryElement obj4 = list[0]; Transform obj5 = ((obj4 != null) ? ((Component)obj4).transform : null); RectTransform val6 = (RectTransform)(object)((obj5 is RectTransform) ? obj5 : null); InventoryElement obj6 = list[num - 1]; Transform obj7 = ((obj6 != null) ? ((Component)obj6).transform : null); RectTransform val7 = (RectTransform)(object)((obj7 is RectTransform) ? obj7 : null); Transform obj8 = ((val6 != null) ? ((Transform)val6).parent : null); RectTransform val8 = (RectTransform)(object)((obj8 is RectTransform) ? obj8 : null); if ((Object)(object)val6 == (Object)null || (Object)(object)val7 == (Object)null || (Object)(object)val8 == (Object)null) { return; } player.GetWorldCorners(PanelCorners); float x = PanelCorners[0].x; float x2 = PanelCorners[2].x; val6.GetWorldCorners(CellCorners); float x3 = CellCorners[0].x; val7.GetWorldCorners(CellCorners); float x4 = CellCorners[2].x; float num3 = (x + x2) * 0.5f - (x3 + x4) * 0.5f; float x5 = ((Transform)val8).InverseTransformVector(new Vector3(num3, 0f, 0f)).x; if (Mathf.Abs(x5) > 0.5f) { foreach (InventoryElement item in list) { Transform obj9 = ((item != null) ? ((Component)item).transform : null); RectTransform val9 = (RectTransform)(object)((obj9 is RectTransform) ? obj9 : null); if ((Object)(object)val9 != (Object)null) { val9.anchoredPosition += new Vector2(x5, 0f); } } } if (!logged) { logged = true; Debug.Log((object)($"[QOL KPX-UI] painel=[{x:F1}..{x2:F1}] " + $"grid=[{x3:F1}..{x4:F1}] dx={x5:F1} " + $"tam={player.sizeDelta} space={elementSpace} pivoCelula={val6.pivot}")); } } [HarmonyPatch(typeof(Humanoid), "DropInvalidItems")] [HarmonyPrefix] private static void GrowBeforeValidation(Humanoid __instance) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { Inventory inventory = __instance.GetInventory(); EnsureSize(inventory, enabled); Rescue(inventory); } } private static void Rescue(Inventory inv) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_005b: Unknown result type (might be due to invalid IL or missing references) try { if (inv == null) { return; } int width = inv.GetWidth(); int height = inv.GetHeight(); int num = 0; foreach (ItemData item in new List<ItemData>(inv.GetAllItems())) { Vector2i gridPos = item.m_gridPos; if ((gridPos.x < 0 || gridPos.y < 0 || gridPos.x >= width || gridPos.y >= height) && MoveToFreeSlot(inv, item)) { num++; } } if (num > 0) { Changed?.Invoke(inv, ChangedArgs); Debug.Log((object)$"[QOL KPX] {num} item(ns) fora da grade devolvido(s) à mochila"); } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao resgatar itens fora da grade: " + ex.Message)); } } private static bool MoveToFreeSlot(Inventory inv, ItemData item, int maxWidth = int.MaxValue) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Min(inv.GetWidth(), maxWidth); for (int i = 0; i < Row; i++) { for (int j = 0; j < num; j++) { if (inv.GetItemAt(j, i) == null) { item.m_gridPos = new Vector2i(j, i); return true; } } } return false; } [HarmonyPatch(typeof(Inventory), "FindEmptySlot")] [HarmonyPostfix] private static void KeepRowFree(Inventory __instance, bool __0, ref Vector2i __result) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if (!IsPlayerInv(__instance) || (__result.x >= 0 && __result.y < Row)) { return; } __result = new Vector2i(-1, -1); int width = __instance.GetWidth(); for (int i = 0; i < Row; i++) { int num = (__0 ? i : (Row - 1 - i)); for (int j = 0; j < width; j++) { if (__instance.GetItemAt(j, num) == null) { __result = new Vector2i(j, num); return; } } } } [HarmonyPatch(typeof(Inventory), "GetEmptySlots")] [HarmonyPostfix] private static void FreeSlots(Inventory __instance, ref int __result) { if (!IsPlayerInv(__instance)) { return; } for (int i = 0; i < __instance.GetWidth(); i++) { if (__instance.GetItemAt(i, Row) == null) { __result--; } } } [HarmonyPatch(typeof(Inventory), "HaveEmptySlot")] [HarmonyPostfix] private static void HaveSlot(Inventory __instance, ref bool __result) { if (!__result || !IsPlayerInv(__instance)) { return; } __result = false; for (int i = 0; i < Row; i++) { if (__result) { break; } for (int j = 0; j < __instance.GetWidth(); j++) { if (__result) { break; } if (__instance.GetItemAt(j, i) == null) { __result = true; } } } } [HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[] { typeof(ItemData), typeof(int) })] [HarmonyPostfix] private static void CanAdd(Inventory __instance, ItemData __0, int __1, ref bool __result) { if (!__result || __0 == null || !IsPlayerInv(__instance)) { return; } int num = ((__1 > 0) ? __1 : __0.m_stack); int num2 = 0; int width = __instance.GetWidth(); for (int i = 0; i < Row; i++) { for (int j = 0; j < width; j++) { if (__instance.GetItemAt(j, i) == null) { num2++; } } } __result = __instance.FindFreeStackSpace(__0.m_shared.m_name, (float)__0.m_worldLevel) + num2 * __0.m_shared.m_maxStackSize >= num; } [HarmonyPatch(typeof(InventoryGrid), "DropItem")] [HarmonyPrefix] private static bool GuardDrop(InventoryGrid __instance, ItemData __1, Vector2i __3, ref bool __result) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (!IsPlayerInv(__instance.GetInventory()) || __3.y != Row) { return true; } if ((__3.x < Types.Length) ? (SlotFor(__1) == __3.x) : IsFood(__1)) { return true; } __result = false; return false; } [HarmonyPatch(typeof(Humanoid), "EquipItem")] [HarmonyPostfix] private static void MoveToSlot(Humanoid __instance, ItemData __0, bool __result) { //IL_004f: 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) try { if (!__result || !enabled || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } int num = SlotFor(__0); if (num >= 0) { Inventory inventory = __instance.GetInventory(); EnsureSize(inventory, enabled); if (inventory.GetItemAt(num, Row) == null) { __0.m_gridPos = new Vector2i(num, Row); Changed?.Invoke(inventory, ChangedArgs); } } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao mover para o slot: " + ex.Message)); } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] [HarmonyPostfix] private static void BackToBag(Humanoid __instance, ItemData __0) { //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) try { if (!enabled || __0 == null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || __0.m_gridPos.y != Row) { return; } Inventory inventory = __instance.GetInventory(); for (int i = 0; i < Row; i++) { for (int j = 0; j < inventory.GetWidth(); j++) { if (inventory.GetItemAt(j, i) == null) { __0.m_gridPos = new Vector2i(j, i); Changed?.Invoke(inventory, ChangedArgs); return; } } } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha ao devolver a peça: " + ex.Message)); } } static Equipment() { ItemType[] array = new ItemType[7]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); Types = (ItemType[])(object)array; rows = 4; HeightRef = AccessTools.FieldRefAccess<Inventory, int>("m_height"); WidthRef = AccessTools.FieldRefAccess<Inventory, int>("m_width"); ElementsRef = AccessTools.FieldRefAccess<InventoryGrid, List<InventoryElement>>("m_elements"); Changed = AccessTools.Method(typeof(Inventory), "Changed", (Type[])null, (Type[])null); ChangedArgs = new object[2] { false, false }; enabled = true; PanelCorners = (Vector3[])(object)new Vector3[4]; CellCorners = (Vector3[])(object)new Vector3[4]; } } internal static class Exploration { internal static int NewPixels; [HarmonyPatch(typeof(Minimap), "Explore", new Type[] { typeof(int), typeof(int) })] [HarmonyPostfix] private static void Count(bool __result) { if (__result) { NewPixels++; } } } internal static class ExtraSlots { internal static bool Enabled = true; private static Player Local => Player.m_localPlayer; internal static bool CanTakeInput() { if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return false; } if (Console.IsVisible() || TextInput.IsVisible()) { return false; } if (InventoryGui.IsVisible() || Menu.IsVisible()) { return false; } return true; } internal static void Tick() { try { if (Enabled && !((Object)(object)Local == (Object)null) && CanTakeInput()) { if (Input.GetKeyDown((KeyCode)57)) { Local.UseHotbarItem(9); } else if (Input.GetKeyDown((KeyCode)48)) { Local.UseHotbarItem(10); } } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no atalho de poção: " + ex.Message)); } } } internal static class Fires { internal static bool Enabled = true; [HarmonyPatch(typeof(Fireplace), "UpdateFireplace")] [HarmonyPrefix] private static void NeverRunOut(Fireplace __instance) { try { if (Enabled && (Object)(object)__instance != (Object)null) { __instance.m_infiniteFuel = true; } } catch (Exception ex) { Debug.LogWarning((object)("[QOL KPX] falha no combustível infinito: " + ex.Message)); } } } internal static class