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 ToxozQoL v1.15.0
ToxozQoL.dll
Decompiled 3 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("ToxozQoL")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Valheim-mod: samlade quality-of-life-funktioner (crafta/bygga/smälta från kistor, behåll inventory vid död, ökade stackar)")] [assembly: AssemblyFileVersion("1.15.0.0")] [assembly: AssemblyInformationalVersion("1.15.0")] [assembly: AssemblyProduct("ToxozQoL")] [assembly: AssemblyTitle("ToxozQoL")] [assembly: AssemblyVersion("1.15.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 ToxozQoL { [HarmonyPatch(typeof(InventoryGui), "UpdateRepair")] public static class InventoryGui_UpdateRepair_AutoRepairPatch { private static readonly MethodInfo GetCurrentCraftingStationMethod = AccessTools.Method(typeof(Player), "GetCurrentCraftingStation", (Type[])null, (Type[])null); private static readonly MethodInfo HaveRepairableItemsMethod = AccessTools.Method(typeof(InventoryGui), "HaveRepairableItems", (Type[])null, (Type[])null); private static readonly MethodInfo RepairOneItemMethod = AccessTools.Method(typeof(InventoryGui), "RepairOneItem", (Type[])null, (Type[])null); private static CraftingStation lastAutoRepairedStation; private static void Postfix(InventoryGui __instance) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } object? obj = GetCurrentCraftingStationMethod.Invoke(localPlayer, null); CraftingStation val = (CraftingStation)((obj is CraftingStation) ? obj : null); if ((Object)(object)val == (Object)null || !val.m_canRepair) { lastAutoRepairedStation = null; } else { if ((Object)(object)val == (Object)(object)lastAutoRepairedStation) { return; } lastAutoRepairedStation = val; for (int i = 0; i < 50; i++) { if (!(bool)HaveRepairableItemsMethod.Invoke(__instance, null)) { break; } RepairOneItemMethod.Invoke(__instance, null); } } } } internal static class BigChest { public const string PrefabName = "ToxozQoL_BigChest"; public const int Width = 5; public const int Height = 20; private static readonly FieldInfo NamedPrefabsField = AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs"); private static readonly FieldInfo InstancesField = AccessTools.Field(typeof(ZNetScene), "m_instances"); private const float PhantomPositionThreshold = 0.5f; public static void RegisterPrefab(ZNetScene znetScene) { if ((Object)(object)znetScene.GetPrefab("ToxozQoL_BigChest") != (Object)null) { return; } GameObject val = null; foreach (GameObject prefab in znetScene.m_prefabs) { if ((Object)(object)prefab != (Object)null && ((Object)prefab).name == "piece_chest_wood") { val = prefab; break; } } if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)"[ToxozQoL] Kunde inte hitta piece_chest_wood att klona för BigChest."); return; } GameObject val2 = Object.Instantiate<GameObject>(val); ((Object)val2).name = "ToxozQoL_BigChest"; Container component = val2.GetComponent<Container>(); if ((Object)(object)component != (Object)null) { component.m_width = 5; component.m_height = 20; } znetScene.m_prefabs.Add(val2); ((Dictionary<int, GameObject>)NamedPrefabsField.GetValue(znetScene))[StringExtensionMethods.GetStableHashCode(((Object)val2).name)] = val2; CleanupPhantomZdo(znetScene, val2); } private static void CleanupPhantomZdo(ZNetScene znetScene, GameObject clone) { ZNetView component = clone.GetComponent<ZNetView>(); ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null); if (val != null) { component.ResetZDO(); ((Dictionary<ZDO, ZNetView>)InstancesField.GetValue(znetScene)).Remove(val); if (val.IsOwner()) { ZDOMan.instance.DestroyZDO(val); } } } public static void CleanupPhantomInstances() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) ZDOMan instance = ZDOMan.instance; if (instance == null) { return; } List<ZDO> list = new List<ZDO>(); int num = 0; while (!instance.GetAllZDOsWithPrefabIterative("ToxozQoL_BigChest", list, ref num)) { } if (list.Count == 0) { return; } int num2 = 0; int num3 = 0; int num4 = 0; foreach (ZDO item in list) { Vector3 position = item.GetPosition(); if (((Vector3)(ref position)).sqrMagnitude > 0.25f) { num4++; continue; } if (!item.IsOwner()) { num3++; continue; } instance.DestroyZDO(item); num2++; } Debug.Log((object)$"[ToxozQoL] BigChest-städning: hittade {list.Count} st totalt, städade {num2} spökobjekt (position ~0,0,0), {num3} ägs av en annan spelare (städas när de uppdaterar), {num4} såg ut att vara riktiga (position långt från origo - rörde INTE dessa)."); } } [HarmonyPatch(typeof(ZNetScene), "Awake")] public static class ZNetScene_Awake_BigChestPatch { private static void Postfix(ZNetScene __instance) { BigChest.RegisterPrefab(__instance); } } [HarmonyPatch(typeof(Player), "OnSpawned")] public static class Player_OnSpawned_BigChestCleanupPatch { private static bool cleanedUp; private static void Postfix(Player __instance) { if (!cleanedUp && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { cleanedUp = true; BigChest.CleanupPhantomInstances(); } } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] public static class HaveRequirements_Piece_Patch { private static readonly FieldInfo KnownStationsField = AccessTools.Field(typeof(Player), "m_knownStations"); private static bool Prefix(Player __instance, Piece piece, RequirementMode mode, ref bool __result) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Invalid comparison between Unknown and I4 //IL_009e: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Invalid comparison between Unknown and I4 if ((int)mode == 1) { return true; } if (Object.op_Implicit((Object)(object)piece.m_craftingStation)) { if ((int)mode == 2) { if (!((Dictionary<string, int>)KnownStationsField.GetValue(__instance)).ContainsKey(piece.m_craftingStation.m_name)) { __result = false; return false; } } else if (!Object.op_Implicit((Object)(object)CraftingStation.HaveBuildStationInRange(piece.m_craftingStation.m_name, ((Component)__instance).transform.position)) && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)27)) { __result = false; return false; } } if (piece.m_dlc.Length > 0 && !DLCMan.instance.IsDLCInstalled(piece.m_dlc)) { __result = false; return false; } if (ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey())) { __result = true; return false; } List<Container> nearbyContainers = ContainerUtils.GetNearbyContainers(((Component)__instance).transform.position, ContainerUtils.SearchRadius); Requirement[] resources = piece.m_resources; foreach (Requirement val in resources) { if (!Object.op_Implicit((Object)(object)val.m_resItem) || val.m_amount <= 0) { continue; } string name = val.m_resItem.m_itemData.m_shared.m_name; int num = ((Humanoid)__instance).GetInventory().CountItems(name, -1, true); foreach (Container item in nearbyContainers) { num += item.GetInventory().CountItems(name, -1, true); } if ((int)mode == 2) { if (num <= 0) { __result = false; return false; } } else if (num < val.m_amount) { __result = false; return false; } } __result = true; return false; } } [HarmonyPatch(typeof(Hud), "SetupPieceInfo")] public static class Hud_SetupPieceInfo_ComfortPatch { private static void Postfix(Hud __instance, Piece piece) { if (!((Object)(object)piece == (Object)null) && piece.m_comfort > 0 && !((Object)(object)__instance.m_pieceDescription == (Object)null)) { string arg = Localization.instance.Localize("$se_rested_comfort"); TMP_Text pieceDescription = __instance.m_pieceDescription; pieceDescription.text += $"\n{arg}: {piece.m_comfort}"; } } } [HarmonyPatch(typeof(Piece), "GetAllComfortPiecesInRadius")] public static class Piece_GetAllComfortPiecesInRadius_DoubleRangePatch { private static void Prefix(ref float radius) { radius *= 2f; } } [HarmonyPatch(typeof(Player), "HaveRequirementItems")] public static class HaveRequirementItems_Patch { private static readonly MethodInfo GetCurrentCraftingStationMethod = AccessTools.Method(typeof(Player), "GetCurrentCraftingStation", (Type[])null, (Type[])null); private static bool Prefix(Player __instance, Recipe piece, bool discover, int qualityLevel, int amount, ref bool __result) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (discover) { return true; } CraftingStation val = (CraftingStation)GetCurrentCraftingStationMethod.Invoke(__instance, null); List<Container> nearbyContainers = ContainerUtils.GetNearbyContainers(((Component)__instance).transform.position, ContainerUtils.SearchRadius); Requirement[] resources = piece.m_resources; foreach (Requirement val2 in resources) { if (((Object)(object)val != (Object)null && val.m_upgrader != val2.m_upgraderResource) || ((Object)(object)val == (Object)null && val2.m_upgraderResource) || (Object)(object)val2.m_resItem == (Object)null) { continue; } int num = val2.GetAmount(qualityLevel) * amount; int num2 = 0; string name = val2.m_resItem.m_itemData.m_shared.m_name; int maxQuality = val2.m_resItem.m_itemData.m_shared.m_maxQuality; for (int j = 1; j < maxQuality + 1; j++) { int num3 = ((Humanoid)__instance).GetInventory().CountItems(name, j, true); foreach (Container item in nearbyContainers) { num3 += item.GetInventory().CountItems(name, j, true); } if (num3 > num2) { num2 = num3; } } if (piece.m_requireOnlyOneIngredient) { if (num2 >= num) { __result = true; return false; } } else if (num2 < num) { __result = false; return false; } } __result = !piece.m_requireOnlyOneIngredient; return false; } } [HarmonyPatch(typeof(Player), "ConsumeResources")] public static class ConsumeResources_Patch { private static readonly MethodInfo GetCurrentCraftingStationMethod = AccessTools.Method(typeof(Player), "GetCurrentCraftingStation", (Type[])null, (Type[])null); private static bool Prefix(Player __instance, Requirement[] requirements, int qualityLevel, int itemQuality, int multiplier) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) CraftingStation val = (CraftingStation)GetCurrentCraftingStationMethod.Invoke(__instance, null); List<Container> nearbyContainers = ContainerUtils.GetNearbyContainers(((Component)__instance).transform.position, ContainerUtils.SearchRadius); foreach (Requirement val2 in requirements) { if ((!((Object)(object)val == (Object)null) && val.m_upgrader != val2.m_upgraderResource) || (!((Object)(object)val != (Object)null) && val2.m_upgraderResource) || (Object)(object)val2.m_resItem == (Object)null) { continue; } int num = val2.GetAmount(qualityLevel) * multiplier; if (num <= 0) { continue; } string name = val2.m_resItem.m_itemData.m_shared.m_name; int num2 = Math.Min(num, ((Humanoid)__instance).GetInventory().CountItems(name, -1, true)); if (num2 > 0) { ((Humanoid)__instance).GetInventory().RemoveItem(name, num2, itemQuality, true); num -= num2; } foreach (Container item in nearbyContainers) { if (num <= 0) { break; } Inventory inventory = item.GetInventory(); int val3 = inventory.CountItems(name, -1, true); int num3 = Math.Min(num, val3); if (num3 > 0) { inventory.RemoveItem(name, num3, itemQuality, true); num -= num3; } } } return false; } } [HarmonyPatch(typeof(Player), "CreateTombStone")] public static class CreateTombStone_Patch { private static bool Prefix() { return false; } } [HarmonyPatch(typeof(Fireplace), "Awake")] public static class Fireplace_Awake_Patch { private static void Postfix(Fireplace __instance) { __instance.m_infiniteFuel = true; } } [HarmonyPatch(typeof(Minimap), "Awake")] public static class Minimap_Awake_ExploreRadiusPatch { private static readonly float RadiusMultiplier = Mathf.Sqrt(2f); private static void Postfix(Minimap __instance) { __instance.m_exploreRadius *= RadiusMultiplier; } } [HarmonyPatch(typeof(Player), "UpdateFood")] public static class Player_UpdateFood_NoDecayPatch { private const float Step = 1f; private static readonly FieldInfo FoodUpdateTimerField = AccessTools.Field(typeof(Player), "m_foodUpdateTimer"); private static readonly FieldInfo FoodRegenTimerField = AccessTools.Field(typeof(Player), "m_foodRegenTimer"); private static readonly MethodInfo GetTotalFoodValueMethod = AccessTools.Method(typeof(Player), "GetTotalFoodValue", (Type[])null, (Type[])null); private static readonly MethodInfo SetMaxEitrMethod = AccessTools.Method(typeof(Player), "SetMaxEitr", new Type[2] { typeof(float), typeof(bool) }, (Type[])null); private static bool Prefix(Player __instance, float dt, bool forceUpdate) { float num = (float)FoodUpdateTimerField.GetValue(__instance) + dt * Game.m_foodRate; if (num >= 1f || forceUpdate) { num -= 1f; foreach (Food food in __instance.GetFoods()) { food.m_time -= 1f; food.m_health = food.m_item.m_shared.m_food; food.m_stamina = food.m_item.m_shared.m_foodStamina; food.m_eitr = food.m_item.m_shared.m_foodEitr; if (food.m_time <= 0f) { ((Character)__instance).Message((MessageType)2, "$msg_food_done", 0, (Sprite)null, false); __instance.GetFoods().Remove(food); break; } } object[] array = new object[3] { 0f, 0f, 0f }; GetTotalFoodValueMethod.Invoke(__instance, array); float num2 = (float)array[0]; float num3 = (float)array[1]; float num4 = (float)array[2]; __instance.SetMaxHealth(num2, true); __instance.SetMaxStamina(num3, true); SetMaxEitrMethod.Invoke(__instance, new object[2] { num4, true }); if (num4 > 0f) { __instance.ShowTutorial("eitr", false); } } FoodUpdateTimerField.SetValue(__instance, num); if (forceUpdate) { return false; } float num5 = (float)FoodRegenTimerField.GetValue(__instance) + dt; if (num5 >= 10f) { num5 = 0f; float num6 = 0f; foreach (Food food2 in __instance.GetFoods()) { num6 += food2.m_item.m_shared.m_foodRegen; } if (num6 > 0f) { float num7 = 1f; ((Character)__instance).GetSEMan().ModifyHealthRegen(ref num7); num6 *= num7; ((Character)__instance).Heal(num6, true); } } FoodRegenTimerField.SetValue(__instance, num5); return false; } } [HarmonyPatch(typeof(InventoryGui), "SetupRequirement")] public static class SetupRequirement_Patch { private static void Postfix(Transform elementRoot, Requirement req, Player player, bool craft, int quality, int craftMultiplier, bool __result) { //IL_007f: 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_0141: 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) if (!__result || (Object)(object)req.m_resItem == (Object)null || (Object)(object)player == (Object)null) { return; } int num = req.GetAmount(quality) * craftMultiplier; if (num <= 0) { return; } Transform obj = ((Component)elementRoot).transform.Find("res_amount"); TMP_Text val = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null); if ((Object)(object)val == (Object)null) { return; } string name = req.m_resItem.m_itemData.m_shared.m_name; int num2 = ((Humanoid)player).GetInventory().CountItems(name, -1, true); foreach (Container nearbyContainer in ContainerUtils.GetNearbyContainers(((Component)player).transform.position, ContainerUtils.SearchRadius)) { num2 += nearbyContainer.GetInventory().CountItems(name, -1, true); } bool flag = (!craft && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)24)) || (craft && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)25)); val.text = $"{num}/{num2}"; ((Graphic)val).color = ((!(num2 < num && flag)) ? Color.white : ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white)); } } [HarmonyPatch(typeof(Smelter), "Spawn")] public static class Smelter_Spawn_ToNearbyChestPatch { private const float Range = 6f; private static readonly MethodInfo GetItemConversionMethod = AccessTools.Method(typeof(Smelter), "GetItemConversion", new Type[1] { typeof(string) }, (Type[])null); private static bool Prefix(Smelter __instance, string ore, int stack) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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) //IL_0055: 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_0094: 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_00a8: Unknown result type (might be due to invalid IL or missing references) object? obj = GetItemConversionMethod.Invoke(__instance, new object[1] { ore }); ItemConversion val = (ItemConversion)((obj is ItemConversion) ? obj : null); if (val == null || (Object)(object)val.m_to == (Object)null) { return true; } Vector3 val2 = (((Object)(object)__instance.m_outputPoint != (Object)null) ? __instance.m_outputPoint.position : ((Component)__instance).transform.position); foreach (Container nearbyContainer in ContainerUtils.GetNearbyContainers(val2, 6f)) { if (nearbyContainer.GetInventory().AddItem(((Component)val.m_to).gameObject, stack)) { __instance.m_produceEffects.Create(val2, ((Component)__instance).transform.rotation, (Transform)null, 1f, -1, default(ZDOID)); return false; } } return true; } } internal static class BatchAddModifier { public const int DefaultBatchSize = 5; public static int GetBatchSize() { if (!ZInput.GetKey((KeyCode)304, false) && !ZInput.GetKey((KeyCode)303, false)) { return 5; } return 1; } } [HarmonyPatch(typeof(Smelter), "OnAddOre")] public static class Smelter_OnAddOre_Patch { private static readonly MethodInfo FindCookableItemMethod = AccessTools.Method(typeof(Smelter), "FindCookableItem", new Type[1] { typeof(Inventory) }, (Type[])null); private static readonly MethodInfo GetQueueSizeMethod = AccessTools.Method(typeof(Smelter), "GetQueueSize", (Type[])null, (Type[])null); private static readonly FieldInfo NviewField = AccessTools.Field(typeof(Smelter), "m_nview"); private static readonly FieldInfo AddedOreTimeField = AccessTools.Field(typeof(Smelter), "m_addedOreTime"); private static readonly FieldInfo AddOreAnimDurationField = AccessTools.Field(typeof(Smelter), "m_addOreAnimationDuration"); private static readonly MethodInfo SetAnimationMethod = AccessTools.Method(typeof(Smelter), "SetAnimation", (Type[])null, (Type[])null); private static bool Prefix(Smelter __instance, Humanoid user, ItemData item, ref bool __result) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_0157: Unknown result type (might be due to invalid IL or missing references) if (item != null) { return true; } int num = __instance.m_maxOre - (int)GetQueueSizeMethod.Invoke(__instance, null); if (num <= 0) { return true; } int num2 = Math.Min(BatchAddModifier.GetBatchSize(), num); ZNetView val = (ZNetView)NviewField.GetValue(__instance); int num3 = 0; string text = null; string text2 = null; try { List<Inventory> list = new List<Inventory> { user.GetInventory() }; bool flag = false; for (int i = 0; i < list.Count; i++) { if (num2 <= 0) { break; } Inventory val2 = list[i]; while (num2 > 0) { object? obj = FindCookableItemMethod.Invoke(__instance, new object[1] { val2 }); ItemData val3 = (ItemData)((obj is ItemData) ? obj : null); if (val3 == null) { break; } if (text == null) { text = ((Object)val3.m_dropPrefab).name; text2 = val3.m_shared.m_name; } else if (((Object)val3.m_dropPrefab).name != text) { break; } int num4 = Math.Min(num2, val3.m_stack); bool cheated = val3.m_cheated; if (!val2.RemoveItem(val3, num4)) { break; } for (int j = 0; j < num4; j++) { val.InvokeRPC("RPC_AddOre", new object[2] { text, cheated }); } num2 -= num4; num3 += num4; } if (i != list.Count - 1 || flag || num2 <= 0) { continue; } flag = true; foreach (Container nearbyContainer in ContainerUtils.GetNearbyContainers(((Component)user).transform.position, ContainerUtils.SearchRadius)) { Inventory inventory = nearbyContainer.GetInventory(); if (inventory != null) { list.Add(inventory); } } } } catch (Exception arg) { Debug.LogWarning((object)$"[ToxozQoL] Avbröt malm-påfyllning efter {num3} st: {arg}"); } if (num3 == 0) { return true; } ((Character)user).Message((MessageType)2, "$msg_added " + text2 + ((num3 > 1) ? (" x" + num3) : ""), 0, (Sprite)null, false); AddedOreTimeField.SetValue(__instance, Time.time); if ((float)AddOreAnimDurationField.GetValue(__instance) > 0f) { SetAnimationMethod.Invoke(__instance, new object[1] { true }); } __result = true; return false; } } [HarmonyPatch(typeof(Smelter), "OnAddFuel")] public static class Smelter_OnAddFuel_Patch { private static readonly FieldInfo FuelItemField = AccessTools.Field(typeof(Smelter), "m_fuelItem"); private static readonly MethodInfo GetFuelMethod = AccessTools.Method(typeof(Smelter), "GetFuel", (Type[])null, (Type[])null); private static readonly FieldInfo NviewField = AccessTools.Field(typeof(Smelter), "m_nview"); private static bool Prefix(Smelter __instance, Humanoid user, ItemData item, ref bool __result) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) if (item != null) { return true; } object? value = FuelItemField.GetValue(__instance); ItemDrop val = (ItemDrop)((value is ItemDrop) ? value : null); if ((Object)(object)val == (Object)null) { return true; } float num = (float)GetFuelMethod.Invoke(__instance, null); int batchSize = BatchAddModifier.GetBatchSize(); int i; for (i = 0; i < batchSize && num + (float)i <= (float)__instance.m_maxFuel - 1f; i++) { } if (i <= 0) { return true; } string name = val.m_itemData.m_shared.m_name; ZNetView nview = (ZNetView)NviewField.GetValue(__instance); int remaining = i; int num2 = 0; try { Inventory inventory = user.GetInventory(); num2 += TakeFuel(inventory, name, ref remaining, nview); if (remaining > 0) { foreach (Container nearbyContainer in ContainerUtils.GetNearbyContainers(((Component)user).transform.position, ContainerUtils.SearchRadius)) { if (remaining > 0) { Inventory inventory2 = nearbyContainer.GetInventory(); if (inventory2 != null) { num2 += TakeFuel(inventory2, name, ref remaining, nview); } continue; } break; } } } catch (Exception arg) { Debug.LogWarning((object)$"[ToxozQoL] Avbröt bränsle-påfyllning efter {num2} st: {arg}"); } if (num2 == 0) { return true; } ((Character)user).Message((MessageType)2, "$msg_added " + name + ((num2 > 1) ? (" x" + num2) : ""), 0, (Sprite)null, false); __result = true; return false; } private static int TakeFuel(Inventory inventory, string fuelName, ref int remaining, ZNetView nview) { int num = Math.Min(remaining, inventory.CountItems(fuelName, -1, true)); if (num <= 0) { return 0; } inventory.RemoveItem(fuelName, num, -1, true); for (int i = 0; i < num; i++) { nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>()); } remaining -= num; return num; } } [HarmonyPatch(typeof(InventoryGui), "Show", new Type[] { typeof(Container), typeof(int) })] public static class InventoryGui_Show_StackAllTrackPatch { private static void Postfix(Container container) { StackAllAcrossNearby.CurrentContainer = container; } } [HarmonyPatch(typeof(InventoryGui), "Hide")] public static class InventoryGui_Hide_StackAllTrackPatch { private static void Postfix() { StackAllAcrossNearby.CurrentContainer = null; } } [HarmonyPatch(typeof(InventoryGui), "CloseContainer")] public static class InventoryGui_CloseContainer_StackAllTrackPatch { private static void Postfix() { StackAllAcrossNearby.CurrentContainer = null; } } public static class StackAllAcrossNearby { public static Container CurrentContainer; } [HarmonyPatch(typeof(Inventory), "StackAll")] public static class Inventory_StackAll_NearbyPatch { private static bool Prefix(Inventory __instance, Inventory fromInventory, bool message, ref int __result) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: 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) Container currentContainer = StackAllAcrossNearby.CurrentContainer; if ((Object)(object)currentContainer == (Object)null || __instance != currentContainer.GetInventory()) { return true; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return true; } List<Container> nearbyContainers = ContainerUtils.GetNearbyContainers(((Component)currentContainer).transform.position, ContainerUtils.SearchRadius); List<ItemData> list = new List<ItemData>(fromInventory.GetAllItems()); int num = 0; foreach (ItemData item in list) { if (((Humanoid)localPlayer).IsItemEquiped(item) || item.m_stack <= 0) { continue; } Inventory val = null; Container val2 = null; if (__instance.ContainsItemByName(item.m_shared.m_name)) { val = __instance; val2 = currentContainer; } else { foreach (Container item2 in nearbyContainers) { if (!((Object)(object)item2 == (Object)(object)currentContainer)) { Inventory inventory = item2.GetInventory(); if (inventory != null && inventory.ContainsItemByName(item.m_shared.m_name)) { val = inventory; val2 = item2; break; } } } } if (val == null) { continue; } int stack = item.m_stack; if (val.AddItem(item)) { fromInventory.RemoveItem(item); num++; if ((Object)(object)val2 != (Object)(object)currentContainer) { Debug.Log((object)$"[ToxozQoL] Place stacks: flyttade {stack}x {item.m_shared.m_name} till en annan närliggande kista ({((Component)val2).transform.position}), inte den öppnade."); } } else { Debug.LogWarning((object)$"[ToxozQoL] Place stacks: kunde inte lägga {item.m_shared.m_name} (hade {stack}, {item.m_stack} kvar olagd) i kistan på {((Component)val2).transform.position} - fullt, lämnar resten i din inventory."); } } if (message) { if (num > 0) { ((Character)localPlayer).Message((MessageType)2, "$msg_stackall " + num, 0, (Sprite)null, false); } else { ((Character)localPlayer).Message((MessageType)2, "$msg_stackall_none", 0, (Sprite)null, false); } } Game.instance.IncrementPlayerStat((PlayerStatType)82, 1f, false); __result = num; return false; } } [HarmonyPatch(typeof(ObjectDB), "UpdateRegisters")] public static class ObjectDB_UpdateRegisters_Patch { private static readonly HashSet<SharedData> AlreadyScaled = new HashSet<SharedData>(); private static void Postfix(ObjectDB __instance) { int value = Plugin.StackMultiplier.Value; float value2 = Plugin.WeightMultiplier.Value; foreach (GameObject item in __instance.m_items) { ItemDrop component = item.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null) { continue; } SharedData shared = component.m_itemData.m_shared; if (shared != null && !AlreadyScaled.Contains(shared)) { AlreadyScaled.Add(shared); if (shared.m_maxStackSize > 1) { shared.m_maxStackSize *= value; shared.m_weight *= value2; } } } } } [HarmonyPatch(typeof(StationExtension), "Awake")] public static class StationExtension_Awake_RangePatch { private static void Postfix(StationExtension __instance) { float value = Plugin.StationExtensionRange.Value; if (__instance.m_maxStationDistance < value) { __instance.m_maxStationDistance = value; } } } internal static class WeaponLoadedPersist { public const string LoadedKey = "ToxozQoL_Loaded"; } [HarmonyPatch(typeof(Player), "SetWeaponLoaded")] public static class Player_SetWeaponLoaded_MarkPatch { private static void Postfix(ItemData weapon) { if (weapon != null) { weapon.m_customData["ToxozQoL_Loaded"] = "1"; } } } [HarmonyPatch(typeof(Attack), "OnAttackTrigger")] public static class Attack_OnAttackTrigger_ClearLoadedMarkPatch { private static void Postfix(Attack __instance, ItemData ___m_weapon) { if (__instance.m_requiresReload) { ___m_weapon?.m_customData.Remove("ToxozQoL_Loaded"); } } } [HarmonyPatch(typeof(Humanoid), "EquipItem")] public static class Humanoid_EquipItem_RestoreLoadedPatch { private static readonly MethodInfo SetWeaponLoadedMethod = AccessTools.Method(typeof(Player), "SetWeaponLoaded", (Type[])null, (Type[])null); private static void Postfix(Humanoid __instance, ItemData item, bool __result) { if (__result && item != null) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val != null && item.IsWeapon() && item.m_shared.m_attack.m_requiresReload && item.m_customData.ContainsKey("ToxozQoL_Loaded")) { SetWeaponLoadedMethod.Invoke(val, new object[1] { item }); } } } } [BepInPlugin("toxo.toxozqol", "ToxozQoL", "1.15.0")] public class Plugin : BaseUnityPlugin { public const string PluginGUID = "toxo.toxozqol"; public const string PluginName = "ToxozQoL"; public const string PluginVersion = "1.15.0"; public static ConfigEntry<float> SearchRadius; public static ConfigEntry<int> StackMultiplier; public static ConfigEntry<float> WeightMultiplier; public static ConfigEntry<float> StationExtensionRange; private Harmony harmony; private void Awake() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Expected O, but got Unknown SearchRadius = ((BaseUnityPlugin)this).Config.Bind<float>("CraftFromChests", "SearchRadius", 40f, new ConfigDescription("Hur långt (i meter) modden letar efter närliggande kistor att crafta, bygga eller mata smältverk/kolmilor från.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), Array.Empty<object>())); StackMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("StackIncrease", "StackMultiplier", 10, new ConfigDescription("Hur mycket max-stackstorleken för stapelbara föremål multipliceras med. Föremål som redan bara kan bära 1 (vapen, rustning m.m.) påverkas inte. Kräver omstart av spelet för att en ändring ska slå igenom.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000), Array.Empty<object>())); WeightMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("StackIncrease", "WeightMultiplier", 0.2f, new ConfigDescription("Vikten för samma stapelbara material multipliceras med detta (0.2 = 20% av originalvikten, dvs 80% lättare). Föremål med maxstack 1 (vapen, rustning m.m.) påverkas inte. Kräver omstart av spelet för att en ändring ska slå igenom.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 2f), Array.Empty<object>())); StationExtensionRange = ((BaseUnityPlugin)this).Config.Bind<float>("CraftingStations", "StationExtensionRange", 20f, new ConfigDescription("Hur långt (i meter) uppgraderingspjäser (huggkubb, garverihylla, städ, bälgar m.m.) får vara från en craftingstation (workbench, forge m.fl.) för att fortfarande räknas. Höjer bara avståndet om pjäsens eget standardvärde är lägre - sänker aldrig. Kräver omstart/omladdning av världen för att slå igenom på redan placerade pjäser.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 50f), Array.Empty<object>())); harmony = new Harmony("toxo.toxozqol"); harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"ToxozQoL v1.15.0 laddad!"); } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } } public static class ContainerUtils { private static readonly MethodInfo CheckAccessMethod = AccessTools.Method(typeof(Container), "CheckAccess", new Type[1] { typeof(long) }, (Type[])null); public static float SearchRadius => Plugin.SearchRadius.Value; public static List<Container> GetNearbyContainers(Vector3 position, float radius) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) List<Container> list = new List<Container>(); Collider[] array = Physics.OverlapSphere(position, radius); for (int i = 0; i < array.Length; i++) { Container componentInParent = ((Component)array[i]).GetComponentInParent<Container>(); if (!((Object)(object)componentInParent == (Object)null) && !list.Contains(componentInParent) && componentInParent.GetInventory() != null && (!((Object)(object)Player.m_localPlayer != (Object)null) || (bool)CheckAccessMethod.Invoke(componentInParent, new object[1] { Player.m_localPlayer.GetPlayerID() }))) { list.Add(componentInParent); } } return list; } public static int CountItemInContainers(List<Container> containers, string itemName) { int num = 0; foreach (Container container in containers) { num += container.GetInventory().CountItems(itemName, -1, true); } return num; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "ToxozQoL"; public const string PLUGIN_NAME = "ToxozQoL"; public const string PLUGIN_VERSION = "1.15.0"; } }