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 ValheimCore v1.0.11
BepInEx/plugins/Goblinheim - ValheimCore/ValheimCore.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.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using GoblinHeim.CoreBuild; using GoblinHeim.CoreBuilding; using GoblinHeim.CoreCrafting; using GoblinHeim.CoreEquipment; using GoblinHeim.CoreInventory; using GoblinHeim.CoreStorage; using GoblinHeim.ValheimCore; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ValheimCore")] [assembly: AssemblyDescription("GoblinHeim — native F4 menu and server-admin settings")] [assembly: AssemblyFileVersion("1.0.11.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.11.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 GoblinHeim.CoreBuilding { public static class BuildingModule { private static bool dirty = true; private static readonly HashSet<ShieldGenerator> shields = new HashSet<ShieldGenerator>(); private static readonly FieldRef<CraftingStation, float> Timer = AccessTools.FieldRefAccess<CraftingStation, float>("m_updateExtensionTimer"); public static void DrawSettings(bool admin, Action<string, float> set) { bool enabled = GUI.enabled; GUI.enabled = enabled && admin; bool flag = GUILayout.Toggle(CorePlugin.Settings.HoeRaiseWithoutWorkbench, "Réhausser à la houe sans atelier", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }); if (flag != CorePlugin.Settings.HoeRaiseWithoutWorkbench) { set("hoeraisewithoutworkbench", flag ? 1f : 0f); } bool flag2 = GUILayout.Toggle(CorePlugin.Settings.StonePathWithoutStonecutter, "Stone path sans stone cutter", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }); if (flag2 != CorePlugin.Settings.StonePathWithoutStonecutter) { set("stonepathwithoutstonecutter", flag2 ? 1f : 0f); } bool flag3 = GUILayout.Toggle(CorePlugin.Settings.BasicTorchesWithoutWorkbench, "Torches de base (bois/résine) sans atelier", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }); if (flag3 != CorePlugin.Settings.BasicTorchesWithoutWorkbench) { set("basictorcheswithoutworkbench", flag3 ? 1f : 0f); } GUILayout.Space(14f); GUILayout.Label("Workshop Range " + CorePlugin.Settings.WorkshopRange.ToString("0") + " m", Array.Empty<GUILayoutOption>()); float num = Mathf.Round(GUILayout.HorizontalSlider(CorePlugin.Settings.WorkshopRange, 20f, 200f, Array.Empty<GUILayoutOption>())); if (num != CorePlugin.Settings.WorkshopRange) { set("workshoprange", num); } GUILayout.Space(14f); GUILayout.Label("Comfort Range " + CorePlugin.Settings.ComfortRange.ToString("0") + " m", Array.Empty<GUILayoutOption>()); float num2 = Mathf.Round(GUILayout.HorizontalSlider(CorePlugin.Settings.ComfortRange, 0f, 100f, Array.Empty<GUILayoutOption>())); if (num2 != CorePlugin.Settings.ComfortRange) { set("comfortrange", num2); } if (CorePlugin.CopperGolemInstalled) { GUILayout.Space(14f); GUILayout.Label("CopperGolem Range " + CorePlugin.Settings.CopperGolemRange.ToString("0") + " m", Array.Empty<GUILayoutOption>()); float num3 = Mathf.Round(GUILayout.HorizontalSlider(CorePlugin.Settings.CopperGolemRange, 1f, 200f, Array.Empty<GUILayoutOption>())); if (num3 != CorePlugin.Settings.CopperGolemRange) { set("coppergolemrange", num3); } } GUILayout.Space(14f); GUILayout.Label("Shield Generator Range " + CorePlugin.Settings.ShieldRange.ToString("0") + " m", Array.Empty<GUILayoutOption>()); float num4 = Mathf.Round(GUILayout.HorizontalSlider(CorePlugin.Settings.ShieldRange, 1f, 200f, Array.Empty<GUILayoutOption>())); if (num4 != CorePlugin.Settings.ShieldRange) { set("shieldrange", num4); } GUILayout.Label("Shield Field Opacity " + CorePlugin.Settings.ShieldOpacity.ToString("0") + " %", Array.Empty<GUILayoutOption>()); float num5 = Mathf.Round(GUILayout.HorizontalSlider(CorePlugin.Settings.ShieldOpacity, 0f, 100f, Array.Empty<GUILayoutOption>())); if (num5 != CorePlugin.Settings.ShieldOpacity) { set("shieldopacity", num5); } GUI.enabled = enabled; } public static void Update() { if (dirty) { dirty = false; ApplyAll(); } } public static void ApplyRangeSoon() { dirty = true; } internal static void Apply(CraftingStation station) { if (Object.op_Implicit((Object)(object)station)) { station.m_rangeBuild = CorePlugin.Settings.WorkshopRange; Timer.Invoke(station) = 2f; float range = StationRange(station); ResizeArea(station, range); } } internal static float StationRange(CraftingStation station) { if (!Object.op_Implicit((Object)(object)station)) { return 0f; } try { return station.GetStationBuildRange(); } catch (NullReferenceException ex) { ZLog.LogWarning((object)("ValheimCore: station range fallback for " + ((Object)((Component)station).gameObject).name + ": " + ex.Message)); return station.m_rangeBuild; } } internal static bool IsStonecutter(CraftingStation station) { if (!Object.op_Implicit((Object)(object)station)) { return false; } string name = ((Object)((Component)station).gameObject).name; if (!(station.m_name == "$piece_stonecutter") && !(name == "piece_stonecutter")) { return name.StartsWith("piece_stonecutter(", StringComparison.Ordinal); } return true; } private static void ResizeArea(CraftingStation station, float range) { Collider val = station.m_effectAreaCollider; if (!Object.op_Implicit((Object)(object)val)) { EffectArea componentInChildren = ((Component)station).GetComponentInChildren<EffectArea>(true); if (Object.op_Implicit((Object)(object)componentInChildren)) { val = ((Component)componentInChildren).GetComponent<Collider>() ?? ((Component)componentInChildren).GetComponentInChildren<Collider>(); } } SphereCollider val2 = (SphereCollider)(object)((val is SphereCollider) ? val : null); if (val2 != null) { val2.radius = range; return; } CapsuleCollider val3 = (CapsuleCollider)(object)((val is CapsuleCollider) ? val : null); if (val3 != null) { val3.radius = range; } } private static void ApplyAll() { foreach (IMonoUpdater instance in CraftingStation.Instances) { CraftingStation val = (CraftingStation)(object)((instance is CraftingStation) ? instance : null); if (Object.op_Implicit((Object)(object)val)) { Apply(val); } } shields.RemoveWhere((ShieldGenerator shield) => !Object.op_Implicit((Object)(object)shield)); foreach (ShieldGenerator shield in shields) { Apply(shield); } } internal static void Apply(ShieldGenerator shield) { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)shield)) { return; } shields.Add(shield); shield.m_minShieldRadius = CorePlugin.Settings.ShieldRange; shield.m_maxShieldRadius = CorePlugin.Settings.ShieldRange; if (!Object.op_Implicit((Object)(object)shield.m_shieldDome)) { return; } float num = CorePlugin.Settings.ShieldOpacity / 100f; shield.m_shieldDome.SetActive(num > 0f); if (num <= 0f) { return; } Renderer[] componentsInChildren = shield.m_shieldDome.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { Material sharedMaterial = val.sharedMaterial; if (Object.op_Implicit((Object)(object)sharedMaterial) && sharedMaterial.HasProperty("_Color")) { MaterialPropertyBlock val2 = new MaterialPropertyBlock(); val.GetPropertyBlock(val2); Color color = sharedMaterial.GetColor("_Color"); color.a *= num; val2.SetColor("_Color", color); val.SetPropertyBlock(val2); } } } public static void WorldChanged() { shields.Clear(); dirty = true; } } [HarmonyPatch(typeof(SE_Rested), "GetNearbyComfortPieces")] internal static class ComfortRangePatch { public static float Range { get { if (CorePlugin.Settings == null) { return 10f; } return CorePlugin.Settings.ComfortRange; } } [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { if (instruction.opcode == OpCodes.Ldc_R4 && instruction.operand is float num && Mathf.Approximately(num, 10f)) { yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(ComfortRangePatch), "Range")); } else { yield return instruction; } } } } [HarmonyPatch(typeof(ShieldGenerator), "Start")] internal static class ShieldGeneratorRangeVisual { [HarmonyPostfix] private static void Postfix(ShieldGenerator __instance) { BuildingModule.Apply(__instance); } } [HarmonyPatch(typeof(ShieldGenerator), "UpdateShield")] internal static class ShieldGeneratorHiddenVisual { [HarmonyPostfix] private static void Postfix(ShieldGenerator __instance) { if (CorePlugin.Settings.ShieldOpacity <= 0f && Object.op_Implicit((Object)(object)__instance.m_shieldDome)) { __instance.m_shieldDome.SetActive(false); } } } [HarmonyPatch(typeof(CraftingStation), "Start")] internal static class BuildingStationStart { [HarmonyPostfix] private static void Postfix(CraftingStation __instance) { BuildingModule.Apply(__instance); } } [HarmonyPatch(typeof(Piece), "Awake")] internal static class StonecutterPlacement { [HarmonyPrefix] private static void Prefix(Piece __instance) { string name = ((Object)((Component)__instance).gameObject).name; if (name == "piece_stonecutter" || name.StartsWith("piece_stonecutter(", StringComparison.Ordinal)) { __instance.m_craftingStation = null; } } } [HarmonyPatch(typeof(CraftingStation), "HaveBuildStationInRange")] internal static class StonecutterAsWorkbench { [HarmonyPostfix] private static void Postfix(string name, Vector3 point, ref CraftingStation __result) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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 (Object.op_Implicit((Object)(object)__result) || name != "$piece_workbench") { return; } foreach (IMonoUpdater instance in CraftingStation.Instances) { CraftingStation val = (CraftingStation)(object)((instance is CraftingStation) ? instance : null); if (BuildingModule.IsStonecutter(val)) { Vector3 val2 = point; val2.y = ((Component)val).transform.position.y; if (Vector3.Distance(((Component)val).transform.position, val2) < BuildingModule.StationRange(val)) { __result = val; break; } } } } } internal static class HammerDismantle { [ThreadStatic] internal static Player Player; private static Piece confirmedWorldPiece; internal static void ConfirmWorldPiece(Piece piece) { confirmedWorldPiece = piece; } internal static void ClearWorldConfirmation() { confirmedWorldPiece = null; } internal static bool ConsumeWorldConfirmation(Piece piece) { if (!Object.op_Implicit((Object)(object)piece) || (Object)(object)confirmedWorldPiece != (Object)(object)piece) { return false; } confirmedWorldPiece = null; return true; } internal static void Refund(Piece piece) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) Player player = Player; if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)piece) || !Object.op_Implicit((Object)(object)ObjectDB.instance) || !Object.op_Implicit((Object)(object)Game.instance) || ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey())) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); Feast component = ((Component)piece).gameObject.GetComponent<Feast>(); ZNetView component2 = ((Component)piece).GetComponent<ZNetView>(); bool cheated = Object.op_Implicit((Object)(object)component2) && component2.IsValid() && component2.GetZDO().GetInt(ZDOVars.s_cheated, 0) == 2 && !PlayerProfile.s_bypassCheatChecks; int num = 0; int num2 = 0; Requirement[] resources = piece.m_resources; foreach (Requirement val in resources) { if (!Object.op_Implicit((Object)(object)val.m_resItem) || !val.m_recover) { continue; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(Utils.GetPrefabName(((Object)val.m_resItem).name)); if (!Object.op_Implicit((Object)(object)itemPrefab)) { continue; } int num3 = val.m_amount; if (Object.op_Implicit((Object)(object)component)) { num3 = (int)Math.Floor((float)num3 * component.GetStackPercentige()); } if (num3 <= 0) { continue; } itemPrefab = Game.instance.CheckDropConversion((HitData)null, val.m_resItem, itemPrefab, ref num3); if (!piece.IsPlacedByPlayer()) { num3 = Mathf.Max(1, num3 / 3); } ItemDrop val2 = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null); if (!Object.op_Implicit((Object)(object)val2)) { continue; } while (num3 > 0) { int num4 = Mathf.Min(num3, val2.m_itemData.m_shared.m_maxStackSize); ItemData val3 = val2.m_itemData.Clone(); val3.m_dropPrefab = itemPrefab; val3.m_stack = num4; val3.m_cheated = cheated; if (inventory.AddItem(val3)) { num += num4; } else { int num5 = Mathf.Clamp(val3.m_stack, 0, num4); num += num4 - num5; if (num5 > 0) { DropAtFeet(player, itemPrefab, num5, cheated); num2 += num5; } } num3 -= num4; } } if (num > 0 || num2 > 0) { ((Character)player).Message((MessageType)1, "Matériaux récupérés : " + num + ((num2 > 0) ? (" — au sol : " + num2) : ""), 0, (Sprite)null, false); } } private static void DropAtFeet(Player player, GameObject prefab, int stack, bool cheated) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)player).transform.position + Vector3.up * 0.25f; ItemDrop component = Object.Instantiate<GameObject>(prefab, val, Quaternion.identity).GetComponent<ItemDrop>(); if (Object.op_Implicit((Object)(object)component)) { component.SetStack(stack); component.m_itemData.m_cheated = cheated; ItemDrop.OnCreateNew(component, cheated); } } } [HarmonyPatch(typeof(Player), "RemovePiece")] internal static class HammerRemoveAnyPiece { internal struct State { internal Player Previous; internal Piece Piece; internal bool CanRemove; } [HarmonyPrefix] private static bool Prefix(Player __instance, out State __state) { Piece hoveringPiece = __instance.GetHoveringPiece(); __state = new State { Previous = HammerDismantle.Player, Piece = hoveringPiece, CanRemove = (Object.op_Implicit((Object)(object)hoveringPiece) && hoveringPiece.m_canBeRemoved) }; if (Object.op_Implicit((Object)(object)hoveringPiece) && !hoveringPiece.IsPlacedByPlayer() && !HammerDismantle.ConsumeWorldConfirmation(hoveringPiece)) { WorldPieceRemovalConfirmation.Open(__instance, hoveringPiece); return false; } HammerDismantle.Player = __instance; if (Object.op_Implicit((Object)(object)hoveringPiece)) { hoveringPiece.m_canBeRemoved = true; } return true; } [HarmonyFinalizer] private static Exception Finalizer(Exception __exception, State __state) { if (Object.op_Implicit((Object)(object)__state.Piece)) { __state.Piece.m_canBeRemoved = __state.CanRemove; } HammerDismantle.Player = __state.Previous; return __exception; } } [HarmonyPatch(typeof(Player), "CheckCanRemovePiece")] internal static class HammerRemoveWithoutStation { [HarmonyPrefix] private static bool Prefix(Player __instance, ref bool __result) { if ((Object)(object)HammerDismantle.Player != (Object)(object)__instance) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(WearNTear), "Remove")] internal static class HammerWearNTearRefund { [HarmonyPrefix] private static void Prefix(WearNTear __instance, ref bool blockDrop) { if (!(!Object.op_Implicit((Object)(object)HammerDismantle.Player) | blockDrop)) { Piece component = ((Component)__instance).GetComponent<Piece>(); ZNetView component2 = ((Component)__instance).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2) && component2.IsValid()) { HammerDismantle.Refund(component); blockDrop = true; } } } } [HarmonyPatch(typeof(Piece), "DropResources")] internal static class HammerDirectPieceRefund { [HarmonyPrefix] private static bool Prefix(Piece __instance) { if (!Object.op_Implicit((Object)(object)HammerDismantle.Player)) { return true; } HammerDismantle.Refund(__instance); return false; } } internal sealed class RepairBeacon : MonoBehaviour, Hoverable, Interactable { internal const string PrefabName = "piece_repair_beacon"; private Piece piece; private void Awake() { piece = ((Component)this).GetComponent<Piece>(); } private bool Allowed(Player player) { if (Object.op_Implicit((Object)(object)player) && Object.op_Implicit((Object)(object)piece)) { return piece.GetCreator() == player.GetPlayerID(); } return false; } public string GetHoverName() { return "Balise de réparation"; } public float GetHoverOffset() { return 0f; } public string GetHoverText() { if (!Allowed(Player.m_localPlayer)) { return "Balise de réparation\n<color=grey>Personnelle</color>"; } return "Balise de réparation\n[<color=yellow><b>$KEY_Use</b></color>] Réparer dans un rayon de 200 m"; } public bool Interact(Humanoid user, bool hold, bool alt) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) Player val = (Player)(object)((user is Player) ? user : null); if (hold || !Allowed(val)) { return false; } int num = 0; foreach (WearNTear allInstance in WearNTear.GetAllInstances()) { if (Object.op_Implicit((Object)(object)allInstance) && !(Vector3.Distance(((Component)this).transform.position, ((Component)allInstance).transform.position) > 200f) && allInstance.Repair()) { num++; } } ((Character)val).Message((MessageType)2, "Balise : " + num + " structure(s) réparée(s).", 0, (Sprite)null, false); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } } internal static class RepairBeaconPrefab { private const string SourceName = "guard_stone"; private static GameObject root; private static GameObject prefab; internal static void Register(ZNetScene scene) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)scene)) { return; } if (Object.op_Implicit((Object)(object)prefab)) { if (!scene.m_prefabs.Contains(prefab)) { scene.m_prefabs.Add(prefab); } return; } GameObject val = ((IEnumerable<GameObject>)scene.m_prefabs).FirstOrDefault((Func<GameObject, bool>)((GameObject go) => Object.op_Implicit((Object)(object)go) && ((Object)go).name == "guard_stone")); if (!Object.op_Implicit((Object)(object)val)) { return; } root = new GameObject("RepairBeacon_PrefabRoot"); Object.DontDestroyOnLoad((Object)(object)root); root.SetActive(false); prefab = Object.Instantiate<GameObject>(val, root.transform, false); ((Object)prefab).name = "piece_repair_beacon"; PrivateArea[] componentsInChildren = prefab.GetComponentsInChildren<PrivateArea>(true); for (int num = 0; num < componentsInChildren.Length; num++) { Object.DestroyImmediate((Object)(object)componentsInChildren[num]); } Piece component = prefab.GetComponent<Piece>(); if (!Object.op_Implicit((Object)(object)component)) { Object.Destroy((Object)(object)prefab); prefab = null; return; } component.m_name = "Balise de réparation"; component.m_description = "Répare les structures chargées dans un rayon de 200 mètres."; GameObject val2 = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab("Stone") : null); GameObject val3 = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab("SurtlingCore") : null); if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3)) { component.m_resources = (Requirement[])(object)new Requirement[2] { new Requirement { m_resItem = val2.GetComponent<ItemDrop>(), m_amount = 10, m_recover = true }, new Requirement { m_resItem = val3.GetComponent<ItemDrop>(), m_amount = 1, m_recover = true } }; } prefab.AddComponent<RepairBeacon>(); scene.m_prefabs.Add(prefab); } internal static void AddToHammer() { if (!Object.op_Implicit((Object)(object)prefab) || !Object.op_Implicit((Object)(object)ObjectDB.instance)) { return; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Hammer"); ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); PieceTable val2 = (Object.op_Implicit((Object)(object)val) ? val.m_itemData.m_shared.m_buildPieces : null); if (Object.op_Implicit((Object)(object)val2) && !val2.m_pieces.Contains(prefab)) { int num = val2.m_pieces.FindIndex((GameObject go) => Object.op_Implicit((Object)(object)go) && ((Object)go).name == "guard_stone"); if (num < 0) { val2.m_pieces.Add(prefab); } else { val2.m_pieces.Insert(num + 1, prefab); } } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class RepairBeaconScenePatch { [HarmonyPrefix] private static void Prefix(ZNetScene __instance) { RepairBeaconPrefab.Register(__instance); } [HarmonyPostfix] private static void Postfix() { RepairBeaconPrefab.AddToHammer(); } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class RepairBeaconObjectDbPatch { [HarmonyPostfix] private static void Postfix() { RepairBeaconPrefab.AddToHammer(); } } internal static class TerrainStationPolicy { internal static bool SkipStation(string prefab, bool synchronized, bool raise, bool stonePath, bool basicTorches = false) { if (!synchronized || string.IsNullOrEmpty(prefab)) { return false; } if ((!raise || !Family(prefab, "raise")) && (!stonePath || !Family(prefab, "paved_road"))) { if (basicTorches) { return prefab == "piece_groundtorch_wood"; } return false; } return true; } private static bool Family(string name, string root) { if (!name.Equals(root, StringComparison.Ordinal)) { return name.StartsWith(root + "_", StringComparison.Ordinal); } return true; } } internal static class TerrainStationRequirements { internal static CraftingStation RequiredStation(Piece piece) { if (!Object.op_Implicit((Object)(object)piece)) { return null; } CoreSettings settings = CorePlugin.Settings; string prefabName = Utils.GetPrefabName(((Component)piece).gameObject); if (CorePlugin.Ready && StarterWoodOrPortal(piece, prefabName)) { return null; } if (!TerrainStationPolicy.SkipStation(prefabName, CorePlugin.Ready, settings.HoeRaiseWithoutWorkbench, settings.StonePathWithoutStonecutter, settings.BasicTorchesWithoutWorkbench)) { return piece.m_craftingStation; } return null; } private static bool StarterWoodOrPortal(Piece piece, string prefab) { if (prefab == "portal_wood") { return true; } if (piece.m_resources == null || piece.m_resources.Length == 0) { return false; } Requirement[] resources = piece.m_resources; foreach (Requirement val in resources) { if (Object.op_Implicit((Object)(object)val.m_resItem) && Utils.GetPrefabName(((Component)val.m_resItem).gameObject) != "Wood") { return false; } } return true; } internal static IEnumerable<CodeInstruction> ReplaceStationReads(IEnumerable<CodeInstruction> instructions) { FieldInfo field = AccessTools.Field(typeof(Piece), "m_craftingStation"); MethodInfo getter = AccessTools.Method(typeof(TerrainStationRequirements), "RequiredStation", (Type[])null, (Type[])null); foreach (CodeInstruction instruction in instructions) { if (instruction.opcode == OpCodes.Ldfld && object.Equals(instruction.operand, field)) { instruction.opcode = OpCodes.Call; instruction.operand = getter; } yield return instruction; } } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] internal static class TerrainBuildStationRequirement { [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { return TerrainStationRequirements.ReplaceStationReads(instructions); } } [HarmonyPatch(typeof(Hud), "SetupPieceInfo", new Type[] { typeof(Piece) })] internal static class TerrainBuildStationHud { [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { return TerrainStationRequirements.ReplaceStationReads(instructions); } } internal static class WorldPieceRemovalConfirmation { private static readonly object Owner = new object(); private static readonly MethodInfo RemovePiece = AccessTools.Method(typeof(Player), "RemovePiece", (Type[])null, (Type[])null); private static GameObject root; private static Player player; private static Piece piece; internal static void Open(Player candidate, Piece target) { //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_012d: 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_0135: 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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)candidate) || !Object.op_Implicit((Object)(object)target) || target.IsPlacedByPlayer() || (Object.op_Implicit((Object)(object)root) && (Object)(object)piece == (Object)(object)target)) { return; } Close(); InventoryGui instance = InventoryGui.instance; Hud instance2 = Hud.instance; RectTransform val = (RectTransform)((Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.m_player)) ? /*isinst with value type is only supported in some contexts*/: null); if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance2) || !Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)instance.m_craftButton) || !Object.op_Implicit((Object)(object)instance.m_playerName)) { ((Character)candidate).Message((MessageType)2, "Confirmation impossible : interface Vanilla indisponible.", 0, (Sprite)null, false); return; } player = candidate; piece = target; RectTransform val2 = Object.Instantiate<RectTransform>(val, ((Component)instance2).transform, false); root = ((Component)val2).gameObject; ((Object)root).name = "ValheimCore World Piece Confirmation"; for (int i = 0; i < ((Transform)val2).childCount; i++) { ((Component)((Transform)val2).GetChild(i)).gameObject.SetActive(false); } Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(0.5f, 0.5f); val2.pivot = val3; Vector2 anchorMin = (val2.anchorMax = val3); val2.anchorMin = anchorMin; val2.anchoredPosition = Vector2.zero; val2.sizeDelta = new Vector2(560f, 220f); ((Transform)val2).localScale = Vector3.one; root.SetActive(true); ((Transform)val2).SetAsLastSibling(); string text = (string.IsNullOrWhiteSpace(target.m_name) ? Utils.GetPrefabName(((Component)target).gameObject) : target.m_name); string text2 = ((Localization.instance != null) ? Localization.instance.Localize(text) : text); TMP_Text obj = NativeUi.Text((Transform)(object)val2, instance.m_playerName, "DÉMOLITION DU MONDE", new Vector2(500f, 34f)); obj.fontSize = 24f; NativeUi.Position((Component)(object)obj, 0f, 68f); TMP_Text obj2 = NativeUi.Text((Transform)(object)val2, instance.m_playerName, "Êtes-vous sûr de vouloir détruire « " + text2 + " » ?", new Vector2(500f, 70f)); obj2.fontSize = 18f; NativeUi.Position((Component)(object)obj2, 0f, 18f); Button obj3 = NativeUi.CloneButton(instance.m_craftButton, (Transform)(object)val2, "Confirm World Removal", new Vector2(190f, 46f), Confirm); NativeUi.SetButtonText(obj3, "Oui"); NativeUi.Position((Component)(object)obj3, -112f, -70f); Button obj4 = NativeUi.CloneButton(instance.m_craftButton, (Transform)(object)val2, "Cancel World Removal", new Vector2(190f, 46f), Close); NativeUi.SetButtonText(obj4, "Non"); NativeUi.Position((Component)(object)obj4, 112f, -70f); CoreUiWindows.Open(Owner, Close); } private static void Confirm() { Player val = player; Piece val2 = piece; Close(); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || val2.IsPlacedByPlayer()) { return; } HammerDismantle.ConfirmWorldPiece(val2); try { RemovePiece.Invoke(val, null); } catch (Exception ex) { ZLog.LogError((object)("ValheimCore world-piece removal confirmation failed: " + ex)); } finally { HammerDismantle.ClearWorldConfirmation(); } } internal static void Close() { CoreUiWindows.CloseRegistration(Owner); if (Object.op_Implicit((Object)(object)root)) { Object.Destroy((Object)(object)root); } root = null; player = null; piece = null; } } } namespace GoblinHeim.CoreEquipment { public static class EquipmentModule { internal struct EquipState { internal ItemData Item; internal Vector2i From; internal int Target; internal bool Tracked; internal bool CustomUtility; } private const string BaseKey = "ValheimCore.Equipment.BaseRows.v2"; private const string BackupKey = "ValheimCore.Equipment.Backup.v2"; private const string LegacyKey = "ValheimCore.SpecialSlot.v1"; private const string DeathEquipKey = "ValheimCore.Equipment.DeathEquipped.v1"; private static readonly string[] Names = new string[16] { "Head", "Trinket", "Arrow 1", "Consumable 1", "Shoulders", "Utility 1", "Arrow 2", "Consumable 2", "Chest", "Utility 2", "Arrow 3", "Consumable 3", "Legs", "Utility 3", "Arrow 4", "Consumable 4" }; private static ConfigEntry<KeyboardShortcut>[] arrows; private static ConfigEntry<KeyboardShortcut>[] quicks; private static ConfigEntry<KeyboardShortcut> listening; private static ConfigEntry<bool> minimized; private static ConfigEntry<bool> compact; private static ConfigEntry<Vector2> panelPosition; private static int consumed = -1; private static int baseRows = 4; private static int lastUtility = -1; private static int lastArrows = -1; private static int lastConsumables = -1; private static bool restoring; private static bool layoutLogged; private static bool slotsDirty = true; private static bool inventorySubscribed; private static Player owner; private static readonly Dictionary<ItemData, int> pendingEquipTargets = new Dictionary<ItemData, int>(); private static readonly Dictionary<ItemData, Vector2i> pendingUnequipTargets = new Dictionary<ItemData, Vector2i>(); private static readonly HashSet<ItemData> pendingDisplaced = new HashSet<ItemData>(); [ThreadStatic] private static bool nativeTransfer; [ThreadStatic] private static bool reconciling; [ThreadStatic] private static bool graveTransfer; [ThreadStatic] private static int equipDepth; [ThreadStatic] private static int directPickup; private static readonly FieldRef<InventoryGui, ItemData> DragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem"); private static readonly FieldRef<InventoryGui, Inventory> DragInventory = AccessTools.FieldRefAccess<InventoryGui, Inventory>("m_dragInventory"); private static readonly Action<InventoryGui, ItemData, Inventory, int> ClearDrag = AccessTools.MethodDelegate<Action<InventoryGui, ItemData, Inventory, int>>(AccessTools.Method(typeof(InventoryGui), "SetupDragItem", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Player, ItemData> QueueEquip = AccessTools.MethodDelegate<Action<Player, ItemData>>(AccessTools.Method(typeof(Player), "QueueEquipAction", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Player, ItemData> QueueUnequip = AccessTools.MethodDelegate<Action<Player, ItemData>>(AccessTools.Method(typeof(Player), "QueueUnequipAction", (Type[])null, (Type[])null), (object)null, true); private static readonly FieldRef<Player, List<MinorActionData>> ActionQueue = AccessTools.FieldRefAccess<Player, List<MinorActionData>>("m_actionQueue"); private static readonly Action<Inventory, bool, bool> Notify = AccessTools.MethodDelegate<Action<Inventory, bool, bool>>(AccessTools.Method(typeof(Inventory), "Changed", (Type[])null, (Type[])null), (object)null, true); private static readonly FieldRef<Humanoid, ItemData> NativeUtility = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_utilityItem"); private static readonly FieldRef<Humanoid, ItemData> NativeAmmo = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_ammoItem"); private static readonly Action<Humanoid> SetupEquipment = AccessTools.MethodDelegate<Action<Humanoid>>(AccessTools.Method(typeof(Humanoid), "SetupEquipment", (Type[])null, (Type[])null), (object)null, true); private static readonly Vector3[] HudCorners = (Vector3[])(object)new Vector3[4]; private static readonly int[] HudSlots = new int[8] { 2, 6, 10, 14, 3, 7, 11, 15 }; private static HotkeyBar hudBar; private static RectTransform hudFirst; private static RectTransform hudSecond; private static Image hudSelection; private static Canvas hudCanvas; private static GUIStyle hudStackStyle; public static bool InputConsumedThisFrame => consumed == Time.frameCount; public static bool BoundShortcutDown { get { if (CoreUiWindows.Active || arrows == null) { return false; } bool flag = false; for (int i = 0; i < 4; i++) { if (flag) { break; } flag = Down(arrows[i]) || Down(quicks[i]); } if (flag) { return !InventoryAccess.Typing; } return false; } } internal static bool Restoring => restoring; internal static int BaseRows => baseRows; internal static bool Minimized { get { if (minimized != null) { return minimized.Value; } return false; } } internal static bool Compact { get { if (compact != null) { return compact.Value; } return false; } } internal static Vector2 PanelPosition { get { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (panelPosition != null) { return panelPosition.Value; } return new Vector2(615f, 28f); } set { //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (panelPosition != null) { panelPosition.Value = value; } } } private static bool Down(ConfigEntry<KeyboardShortcut> e) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = e.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey != 0) { return CoreInput.IsDown(e.Value); } return false; } public static void Initialize(ConfigFile c) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) arrows = new ConfigEntry<KeyboardShortcut>[4]; quicks = new ConfigEntry<KeyboardShortcut>[4]; for (int i = 0; i < 4; i++) { arrows[i] = c.Bind<KeyboardShortcut>("Client.Input", "ArrowSlot" + (i + 1), new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), "Select ammunition slot."); quicks[i] = c.Bind<KeyboardShortcut>("Client.Input", "QuickSlot" + (i + 1), new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), "Use consumable slot."); } minimized = c.Bind<bool>("Client.UI", "EquipmentMinimized", false, "Show only the title bar."); compact = c.Bind<bool>("Client.UI", "EquipmentCompact", false, "Show only arrows and consumables."); panelPosition = c.Bind<Vector2>("Client.UI", "EquipmentPanelPosition", new Vector2(615f, 28f), "Equipment panel position relative to the Vanilla inventory."); if (!inventorySubscribed) { InventoryAccess.InventoryChanged += MarkSlotsDirty; inventorySubscribed = true; } } public static void Shutdown() { if (inventorySubscribed) { InventoryAccess.InventoryChanged -= MarkSlotsDirty; inventorySubscribed = false; } listening = null; owner = null; pendingEquipTargets.Clear(); pendingUnequipTargets.Clear(); pendingDisplaced.Clear(); ClearHudCache(); NativeEquipmentPanel.Clear(); } private static void MarkSlotsDirty() { slotsDirty = true; } public static void DrawSettings(bool admin, Action<string, float> set) { GUILayout.Label("Equipment Inventory — grille 4 × 4", Array.Empty<GUILayoutOption>()); bool enabled = GUI.enabled; GUI.enabled = enabled && admin; Count("Utility Slots", "utilityslots", CorePlugin.Settings.UtilitySlots, 1, 3, set); Count("Arrow Slots Active", "arrowslots", CorePlugin.Settings.ArrowSlotsActive, 1, 4, set); Count("Consumable Slots Active", "consumableslots", CorePlugin.Settings.ConsumableSlotsActive, 1, 4, set); GUI.enabled = enabled; for (int i = 0; i < 4; i++) { Bind("Arrow Slot " + (i + 1), arrows[i]); } GUILayout.Space(8f); for (int j = 0; j < 4; j++) { Bind("Consumable Slot " + (j + 1), quicks[j]); } } private static void Count(string l, string k, int v, int min, int max, Action<string, float> set) { GUILayout.Label(l + " " + v, Array.Empty<GUILayoutOption>()); int num = (int)Mathf.Round(GUILayout.HorizontalSlider((float)v, (float)min, (float)max, Array.Empty<GUILayoutOption>())); if (num != v) { set(k, num); } GUILayout.Space(6f); } private unsafe static void Bind(string n, ConfigEntry<KeyboardShortcut> e) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) object obj; if (listening != e) { KeyboardShortcut value = e.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey != 0) { value = e.Value; obj = ((object)(*(KeyboardShortcut*)(&value))/*cast due to .constrained prefix*/).ToString(); } else { obj = "Non assigné"; } } else { obj = "Appuyez sur la combinaison…"; } if (GUILayout.Button(n + " " + (string?)obj, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) })) { listening = e; } } public static void Update() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_0060: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: 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_0099: Unknown result type (might be due to invalid IL or missing references) Ensure(Player.m_localPlayer); if (!InventoryGui.IsVisible() && !CorePlugin.visible) { listening = null; } if (listening != null && Input.anyKeyDown) { foreach (KeyCode value in Enum.GetValues(typeof(KeyCode))) { if (Modifier(value) || !Input.GetKeyDown(value)) { continue; } List<KeyCode> list = new List<KeyCode>(); KeyCode[] array = new KeyCode[6]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); KeyCode[] array2 = (KeyCode[])(object)array; foreach (KeyCode val2 in array2) { if (Input.GetKey(val2)) { list.Add(val2); } } listening.Value = new KeyboardShortcut(value, list.ToArray()); listening = null; consumed = Time.frameCount; return; } } if (!Object.op_Implicit((Object)(object)owner)) { return; } if (lastUtility != CorePlugin.Settings.UtilitySlots || lastArrows != CorePlugin.Settings.ArrowSlotsActive || lastConsumables != CorePlugin.Settings.ConsumableSlotsActive) { lastUtility = CorePlugin.Settings.UtilitySlots; lastArrows = CorePlugin.Settings.ArrowSlotsActive; lastConsumables = CorePlugin.Settings.ConsumableSlotsActive; slotsDirty = true; } if (slotsDirty && CorePlugin.Ready) { slotsDirty = false; EnforceSlots(); ReconcileEquipment(); } if (CoreUiWindows.Active) { return; } int num = -1; bool use = false; for (int j = 0; j < 4; j++) { if (num >= 0) { break; } if (Down(arrows[j])) { num = 2 + j * 4; } } for (int k = 0; k < 4; k++) { if (num >= 0) { break; } if (Down(quicks[k])) { num = 3 + k * 4; use = true; } } if (num >= 0 && !InventoryAccess.Typing) { Activate(num, use); consumed = Time.frameCount; } } private static bool Modifier(KeyCode k) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Invalid comparison between Unknown and I4 //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Invalid comparison between Unknown and I4 //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 if ((int)k != 306 && (int)k != 305 && (int)k != 304 && (int)k != 303 && (int)k != 308) { return (int)k == 307; } return true; } private static void Ensure(Player p) { if (Object.op_Implicit((Object)(object)p) && !((Object)(object)owner == (Object)(object)p)) { owner = p; slotsDirty = true; pendingDisplaced.Clear(); ClearHudCache(); ReadBaseRows(p); Extend(); MigrateLegacy(); Validate(CorePlugin.Ready); if (CorePlugin.Ready) { ReconcileEquipment(); } } } private static void ReadBaseRows(Player p) { if (!p.m_customData.TryGetValue("ValheimCore.Equipment.BaseRows.v2", out var value) || !int.TryParse(value, out baseRows) || baseRows < 1) { baseRows = Math.Max(1, Math.Min(4, ((Humanoid)p).GetInventory().GetHeight())); } p.m_customData["ValheimCore.Equipment.BaseRows.v2"] = baseRows.ToString(); } private static void Extend() { if (Object.op_Implicit((Object)(object)owner)) { Inventory inventory = ((Humanoid)owner).GetInventory(); inventory.SetHeight(baseRows + (16 + inventory.GetWidth() - 1) / inventory.GetWidth()); } } public static bool IsInSpecialRegion(ItemData i) { if (Object.op_Implicit((Object)(object)owner) && i != null) { return i.m_gridPos.y >= baseRows; } return false; } private static Vector2i Pos(int n) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) int width = ((Humanoid)owner).GetInventory().GetWidth(); return new Vector2i(n % width, baseRows + n / width); } private static ItemData Item(int n) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)owner)) { return null; } Vector2i val = Pos(n); return ((Humanoid)owner).GetInventory().GetItemAt(val.x, val.y); } private static void MigrateLegacy() { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) foreach (ItemData allItem in ((Humanoid)owner).GetInventory().GetAllItems()) { if (allItem.m_customData.TryGetValue("ValheimCore.SpecialSlot.v1", out var value)) { allItem.m_customData.Remove("ValheimCore.SpecialSlot.v1"); value = value.Replace("Quick ", "Consumable "); int num = Array.IndexOf(Names, value); if (num >= 0 && Item(num) == null) { allItem.m_gridPos = Pos(num); } } } Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); } private static Vector2i EmptyBase() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = ((Humanoid)owner).GetInventory(); for (int i = 0; i < baseRows; i++) { for (int j = 0; j < inventory.GetWidth(); j++) { if (inventory.GetItemAt(j, i) == null) { return new Vector2i(j, i); } } } return new Vector2i(-1, -1); } private static void Full() { ((Character)owner).Message((MessageType)2, "Inventaire plein", 0, (Sprite)null, false); } private static bool MoveBase(ItemData i) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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) Vector2i val = EmptyBase(); if (val.x < 0) { Full(); return false; } i.m_gridPos = val; return true; } internal static bool Unlocked(int n) { return n switch { 2 => CorePlugin.Settings.ArrowSlotsActive >= 4, 6 => CorePlugin.Settings.ArrowSlotsActive >= 3, 10 => CorePlugin.Settings.ArrowSlotsActive >= 2, 14 => CorePlugin.Settings.ArrowSlotsActive >= 1, 3 => CorePlugin.Settings.ConsumableSlotsActive >= 4, 7 => CorePlugin.Settings.ConsumableSlotsActive >= 3, 11 => CorePlugin.Settings.ConsumableSlotsActive >= 2, 15 => CorePlugin.Settings.ConsumableSlotsActive >= 1, 9 => CorePlugin.Settings.UtilitySlots >= 2, 13 => CorePlugin.Settings.UtilitySlots >= 3, _ => true, }; } internal static bool Fits(int n, ItemData i) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Invalid comparison between Unknown and I4 //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Invalid comparison between Unknown and I4 //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Invalid comparison between Unknown and I4 //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Invalid comparison between Unknown and I4 //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Invalid comparison between Unknown and I4 //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Invalid comparison between Unknown and I4 if (i == null) { return false; } ItemType itemType = i.m_shared.m_itemType; switch (n) { case 0: return (int)itemType == 6; case 1: return (int)itemType == 24; case 4: return (int)itemType == 17; case 8: return (int)itemType == 7; case 12: return (int)itemType == 11; case 5: case 9: case 13: return (int)itemType == 18; case 2: case 6: case 10: case 14: if ((int)itemType != 9) { return (int)itemType == 23; } return true; case 3: case 7: case 11: case 15: return (int)itemType == 2; default: return false; } } private static void Activate(int n, bool use) { if (Unlocked(n)) { ItemData val = Item(n); if (val != null && Fits(n, val)) { ((Humanoid)owner).UseItem(((Humanoid)owner).GetInventory(), val, true); } } } private static bool Playable() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)owner) && (Object)(object)owner == (Object)(object)Player.m_localPlayer && ((Component)owner).gameObject.activeInHierarchy) { ZDOID zDOID = ((Character)owner).GetZDOID(); if (!((ZDOID)(ref zDOID)).IsNone() && Object.op_Implicit((Object)(object)Hud.instance) && Object.op_Implicit((Object)(object)Game.instance) && Object.op_Implicit((Object)(object)ZNet.instance) && Object.op_Implicit((Object)(object)ZNetScene.instance)) { return !Object.op_Implicit((Object)(object)FejdStartup.instance); } } return false; } public static void OnGUI() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 if ((int)Event.current.type == 7 && Playable() && !CorePlugin.visible && !InventoryGui.IsVisible()) { DrawHud(); } } private static bool ResolveHud() { if (!Object.op_Implicit((Object)(object)hudBar)) { hudBar = ((Component)Hud.instance).GetComponentInChildren<HotkeyBar>(true); } if (!Object.op_Implicit((Object)(object)hudBar) || ((Component)hudBar).transform.childCount < 1) { return false; } if (!Object.op_Implicit((Object)(object)hudFirst)) { Transform child = ((Component)hudBar).transform.GetChild(0); hudFirst = (RectTransform)(object)((child is RectTransform) ? child : null); if (!Object.op_Implicit((Object)(object)hudFirst)) { return false; } Transform val = ((Transform)hudFirst).Find("equiped") ?? ((Transform)hudFirst).Find("selected"); hudSelection = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<Image>() : null); hudCanvas = ((Component)hudFirst).GetComponentInParent<Canvas>(); } hudSecond = (RectTransform)((((Component)hudBar).transform.childCount > 1) ? /*isinst with value type is only supported in some contexts*/: null); return true; } private static void ClearHudCache() { hudBar = null; hudFirst = null; hudSecond = null; hudSelection = null; hudCanvas = null; hudStackStyle = null; } private static void DrawHud() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //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) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00be: 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_0157: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) if (!ResolveHud()) { return; } Camera val = ((Object.op_Implicit((Object)(object)hudCanvas) && (int)hudCanvas.renderMode != 0) ? hudCanvas.worldCamera : null); hudFirst.GetWorldCorners(HudCorners); Vector2 val2 = RectTransformUtility.WorldToScreenPoint(val, HudCorners[0]); Vector2 val3 = RectTransformUtility.WorldToScreenPoint(val, HudCorners[2]); float num = Mathf.Min(Mathf.Abs(val3.x - val2.x), Mathf.Abs(val3.y - val2.y)); if (num < 1f) { return; } float num2 = num; if (Object.op_Implicit((Object)(object)hudSecond)) { num2 = Mathf.Abs(RectTransformUtility.WorldToScreenPoint(val, ((Transform)hudSecond).position).x - RectTransformUtility.WorldToScreenPoint(val, ((Transform)hudFirst).position).x); } float x = val2.x; float num3 = (float)Screen.height - val2.y + 2f; ItemData val4 = NativeAmmo.Invoke((Humanoid)(object)owner); Rect r = default(Rect); for (int i = 0; i < 8; i++) { ((Rect)(ref r))..ctor(x + (float)(i % 4) * num2, num3 + (float)(i / 4) * (num + 2f), num, num); ItemData val5 = Item(HudSlots[i]); if (i < 4 && val5 != null && val5 == val4) { DrawSelection(r, hudSelection); } DrawHudSlot(r, HudSlots[i]); } } private static void DrawSelection(Rect r, Image source) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)source) && Object.op_Implicit((Object)(object)source.sprite)) { Sprite sprite = source.sprite; Rect textureRect = sprite.textureRect; Color color = GUI.color; GUI.color = ((Graphic)source).color; GUI.DrawTextureWithTexCoords(r, (Texture)(object)sprite.texture, new Rect(((Rect)(ref textureRect)).x / (float)((Texture)sprite.texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)sprite.texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)sprite.texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)sprite.texture).height), true); GUI.color = color; } } private static void DrawHudSlot(Rect r, int n) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Expected O, but got Unknown ItemData val = Item(n); if (val != null) { Sprite icon = val.GetIcon(); if (Object.op_Implicit((Object)(object)icon)) { Rect textureRect = icon.textureRect; float num = Mathf.Max(3f, ((Rect)(ref r)).width * 0.08f); Color color = GUI.color; GUI.color = Color.white; GUI.DrawTextureWithTexCoords(new Rect(((Rect)(ref r)).x + num, ((Rect)(ref r)).y + num, ((Rect)(ref r)).width - num * 2f, ((Rect)(ref r)).height - num * 2f), (Texture)(object)icon.texture, new Rect(((Rect)(ref textureRect)).x / (float)((Texture)icon.texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)icon.texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)icon.texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)icon.texture).height), true); GUI.color = color; } if (hudStackStyle == null) { hudStackStyle = new GUIStyle(GUI.skin.label) { alignment = (TextAnchor)8, fontSize = 14, fontStyle = (FontStyle)1 }; } GUI.Label(new Rect(((Rect)(ref r)).x + 3f, ((Rect)(ref r)).y + ((Rect)(ref r)).height - 24f, ((Rect)(ref r)).width - 7f, 20f), val.m_stack.ToString(), hudStackStyle); } } private static int EquipmentIndex(ItemData i) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Invalid comparison between Unknown and I4 //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected I4, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Invalid comparison between Unknown and I4 //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 ItemType itemType = i.m_shared.m_itemType; if ((int)itemType <= 17) { switch (itemType - 6) { default: if ((int)itemType != 17) { goto IL_00d0; } return 4; case 0: return 0; case 1: return 8; case 5: return 12; case 3: break; case 2: case 4: goto IL_00d0; } } else { if ((int)itemType == 18) { int result = 5; for (int j = 5; j <= 13; j += 4) { if (Unlocked(j)) { result = j; if (Item(j) == null) { return j; } } } return result; } if ((int)itemType != 23) { if ((int)itemType != 24) { goto IL_00d0; } return 1; } } int result2 = -1; for (int k = 2; k <= 14; k += 4) { if (Unlocked(k)) { result2 = k; if (Item(k) == null) { return k; } } } int num = ExistingIndex(NativeAmmo.Invoke((Humanoid)(object)owner)); if (num < 0) { return result2; } return num; IL_00d0: return -1; } private static int ExistingIndex(ItemData i) { if (i == null) { return -1; } for (int j = 0; j < 16; j++) { if (Item(j) == i) { return j; } } return -1; } internal static bool BeforeEquip(Humanoid h, ItemData i, ref bool result, ref EquipState state) { //IL_0015: 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_001a: 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_00e0: Invalid comparison between Unknown and I4 state.Item = i; state.From = (Vector2i)(((??)i?.m_gridPos) ?? new Vector2i(-1, -1)); state.Target = -1; state.Tracked = false; state.CustomUtility = false; Player val = (Player)(object)((h is Player) ? h : null); if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer || nativeTransfer || reconciling) { return true; } Ensure(val); state.Tracked = true; equipDepth++; if (i != null && pendingEquipTargets.TryGetValue(i, out var value) && Unlocked(value) && Fits(value, i)) { state.Target = value; } else { int num = ExistingIndex(i); state.Target = ((num >= 0) ? num : ((i == null) ? (-1) : EquipmentIndex(i))); } int target = state.Target; if (target < 0) { return true; } if ((int)i.m_shared.m_itemType == 18 && target != 5 && NativeUtility.Invoke(h) != null) { foreach (ItemData item in ExtraUtilities()) { if (item != i && item.m_shared.m_name == i.m_shared.m_name) { result = false; return false; } } ItemData val2 = Item(target); if (val2 != null && val2 != i && h.IsItemEquiped(val2)) { h.UnequipItem(val2, false); } i.m_equipped = true; state.CustomUtility = true; result = true; return false; } return true; } internal static void AfterEquip(Humanoid h, ItemData i, bool result, EquipState state) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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) //IL_0035: Unknown result type (might be due to invalid IL or missing references) if (!result || (Object)(object)h != (Object)(object)owner || i == null) { return; } int target = state.Target; if (target >= 0) { ItemData val = Item(target); if (val != null && val != i) { val.m_gridPos = state.From; } i.m_gridPos = Pos(target); if (state.CustomUtility) { SetupEquipment(h); } Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); } } internal static Exception FinishEquip(Humanoid h, EquipState state, Exception error) { if (state.Tracked && equipDepth > 0) { equipDepth--; } if (state.Tracked && state.Item != null) { pendingEquipTargets.Remove(state.Item); } if (state.Tracked && equipDepth == 0) { FlushDisplaced(h); } return error; } internal static void AfterUnequip(Humanoid h, ItemData i) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)h != (Object)(object)owner || i == null || nativeTransfer || reconciling || restoring || graveTransfer) { return; } int n = SpecialIndex(i.m_gridPos); if (!IsEquipmentStateSlot(n) || h.IsItemEquiped(i)) { return; } bool flag = pendingUnequipTargets.ContainsKey(i); if (equipDepth > 0) { if (!IsArrowSlot(n) || flag) { pendingDisplaced.Add(i); } } else { MoveUnequippedOut(h, i, n, flag); } } private static void FlushDisplaced(Humanoid h) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) while (pendingDisplaced.Count > 0) { ItemData val = null; using (HashSet<ItemData>.Enumerator enumerator = pendingDisplaced.GetEnumerator()) { if (enumerator.MoveNext()) { val = enumerator.Current; } } pendingDisplaced.Remove(val); if (val != null) { int n = SpecialIndex(val.m_gridPos); if (IsEquipmentStateSlot(n) && !h.IsItemEquiped(val)) { MoveUnequippedOut(h, val, n, pendingUnequipTargets.ContainsKey(val)); } else { pendingUnequipTargets.Remove(val); } } } } private static void MoveUnequippedOut(Humanoid h, ItemData i, int n, bool requested) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) if (!pendingUnequipTargets.TryGetValue(i, out var value)) { ((Vector2i)(ref value))..ctor(-1, -1); } pendingUnequipTargets.Remove(i); if (IsArrowSlot(n) && !requested) { return; } if (!requested || value.y < 0 || value.y >= baseRows || ((Humanoid)owner).GetInventory().GetItemAt(value.x, value.y) != null) { value = EmptyBase(); } if (value.x >= 0) { i.m_gridPos = value; Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); return; } Full(); reconciling = true; try { ((Humanoid)owner).DropItem(((Humanoid)owner).GetInventory(), i, i.m_stack); } finally { reconciling = false; } Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); } private static bool ActionQueued(ItemData i, ActionType type) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)owner) || i == null) { return false; } foreach (MinorActionData item in ActionQueue.Invoke(owner)) { if (item.m_item == i && item.m_type == type) { return true; } } return false; } internal static bool QueueNativeEquip(ItemData i, int n) { if (!Object.op_Implicit((Object)(object)owner) || i == null || !((Humanoid)owner).GetInventory().ContainsItem(i) || !IsEquipmentStateSlot(n) || !Unlocked(n) || !Fits(n, i)) { return false; } if (((Humanoid)owner).IsItemEquiped(i)) { return true; } if (ActionQueued(i, (ActionType)0)) { pendingEquipTargets[i] = n; return true; } if (ActionQueued(i, (ActionType)1)) { ((Humanoid)owner).RemoveEquipAction(i); } pendingUnequipTargets.Remove(i); pendingEquipTargets[i] = n; QueueEquip(owner, i); Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); CorePlugin.LogEquipment("Queued native equip " + i.m_shared.m_name + " -> " + SlotName(n)); return ActionQueued(i, (ActionType)0); } internal static bool QueueNativeUnequip(ItemData i, Vector2i destination) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)owner) || i == null || !((Humanoid)owner).GetInventory().ContainsItem(i) || !((Humanoid)owner).IsItemEquiped(i)) { return false; } if (ActionQueued(i, (ActionType)1)) { pendingUnequipTargets[i] = destination; return true; } if (ActionQueued(i, (ActionType)0)) { ((Humanoid)owner).RemoveEquipAction(i); } pendingEquipTargets.Remove(i); pendingUnequipTargets[i] = destination; QueueUnequip(owner, i); Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); CorePlugin.LogEquipment("Queued native unequip " + i.m_shared.m_name + " -> Inventory"); return ActionQueued(i, (ActionType)1); } internal static void CancelPendingAction(ItemData i) { if (i != null) { pendingEquipTargets.Remove(i); pendingUnequipTargets.Remove(i); } } internal static IEnumerable<ItemData> ExtraUtilities() { for (int n = 9; n <= 13; n += 4) { ItemData val = Item(n); if (val != null && val.m_equipped) { yield return val; } } } private static void EnforceSlots() { for (int i = 0; i < 16; i++) { if (!Unlocked(i) && Item(i) != null) { Evict(i); } } } private static void Evict(int n) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) ItemData val = Item(n); if (val == null) { return; } Vector2i val2 = EmptyBase(); if (val2.x >= 0) { if (val.m_equipped) { ((Humanoid)owner).UnequipItem(val, true); } val.m_gridPos = val2; Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); } else { if (val.m_equipped) { ((Humanoid)owner).UnequipItem(val, true); } ((Humanoid)owner).DropItem(((Humanoid)owner).GetInventory(), val, val.m_stack); } } internal static int FreeEquipmentSlot(ItemData i) { int num = EquipmentIndex(i); if (num < 0 || !Unlocked(num) || Item(num) != null) { return -1; } return num; } internal static void BeginDirectPickup(Humanoid h, GameObject go) { directPickup = -1; Ensure((Player)(object)((h is Player) ? h : null)); if (!((Object)(object)h != (Object)(object)owner) && !((Object)(object)go == (Object)null) && ((Humanoid)owner).GetInventory().GetEmptySlots() <= 0) { ItemDrop component = go.GetComponent<ItemDrop>(); if ((Object)(object)component != (Object)null) { directPickup = FreeEquipmentSlot(component.m_itemData); } } } internal static void EndDirectPickup(Humanoid h, GameObject go, bool result) { if (result && directPickup >= 0 && (Object)(object)h == (Object)(object)owner) { ItemData val = Item(directPickup); if (val != null) { QueueNativeEquip(val, directPickup); } } directPickup = -1; } internal static void ClearDirectPickup() { directPickup = -1; } internal static int BaseEmptySlots(Inventory inv) { if (!Object.op_Implicit((Object)(object)owner) || inv != ((Humanoid)owner).GetInventory()) { return inv.GetEmptySlots(); } int num = 0; for (int i = 0; i < baseRows; i++) { for (int j = 0; j < inv.GetWidth(); j++) { if (inv.GetItemAt(j, i) == null) { num++; } } } return num; } internal static bool CanAddVisible(Inventory inv, ItemData i, int stack) { if (!Object.op_Implicit((Object)(object)owner) || inv != ((Humanoid)owner).GetInventory() || i == null) { return false; } if (stack <= 0) { stack = i.m_stack; } long num = inv.FindFreeStackSpace(i.m_shared.m_name, (float)i.m_worldLevel) + (long)BaseEmptySlots(inv) * (long)i.m_shared.m_maxStackSize; if (directPickup >= 0 && FreeEquipmentSlot(i) >= 0) { num += i.m_shared.m_maxStackSize; } return num >= stack; } internal static void DirectPosition(Inventory inv, ref Vector2i p) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)owner) && inv == ((Humanoid)owner).GetInventory() && directPickup >= 0) { p = Pos(directPickup); } } private static void Validate(bool enforceLocks) { for (int i = 0; i < 16; i++) { ItemData val = Item(i); if (val != null && (!Fits(i, val) || (enforceLocks && !Unlocked(i)))) { MoveBase(val); } } Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); } private static int RestoreIndex(ItemData i) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Invalid comparison between Unknown and I4 //IL_0016: 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_0036: Expected I4, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Invalid comparison between Unknown and I4 //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Invalid comparison between Unknown and I4 //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Invalid comparison between Unknown and I4 if (i == null) { return -1; } ItemType itemType = i.m_shared.m_itemType; if ((int)itemType <= 17) { switch (itemType - 6) { default: if ((int)itemType != 17) { goto IL_008c; } return 4; case 0: return 0; case 1: return 8; case 5: return 12; case 3: break; case 2: case 4: goto IL_008c; } } else { if ((int)itemType == 18) { for (int j = 5; j <= 13; j += 4) { if (Item(j) == null) { return j; } } return 5; } if ((int)itemType != 23) { if ((int)itemType != 24) { goto IL_008c; } return 1; } } for (int k = 2; k <= 14; k += 4) { if (Item(k) == null) { return k; } } return 14; IL_008c: return -1; } private static void MoveOutNow(ItemData i) { if (i == null) { return; } if (((Humanoid)owner).IsItemEquiped(i)) { ((Humanoid)owner).UnequipItem(i, false); } if (!IsInSpecialRegion(i) || MoveBase(i)) { return; } reconciling = true; try { ((Humanoid)owner).DropItem(((Humanoid)owner).GetInventory(), i, i.m_stack); } finally { reconciling = false; } } private static void ReconcileEquipment() { //IL_0047: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_0118: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)owner) || restoring) { return; } Inventory inventory = ((Humanoid)owner).GetInventory(); List<ItemData> list = new List<ItemData>(inventory.GetAllItems()); int num = 0; int num2 = 0; int num3 = 0; foreach (ItemData item in list) { int num4 = SpecialIndex(item.m_gridPos); if (!item.m_equipped && !((Humanoid)owner).IsItemEquiped(item)) { continue; } int num5 = ((num4 >= 0 && IsEquipmentStateSlot(num4) && Fits(num4, item)) ? num4 : RestoreIndex(item)); if (num5 < 0 || num4 == num5) { continue; } Vector2i gridPos = item.m_gridPos; ItemData val = Item(num5); item.m_gridPos = new Vector2i(-100, -100); if (val != null && val != item) { if (gridPos.y >= 0 && gridPos.y < baseRows && inventory.GetItemAt(gridPos.x, gridPos.y) == null) { val.m_gridPos = gridPos; } else { MoveOutNow(val); num3++; } } item.m_gridPos = Pos(num5); num++; } int[] array = new int[8] { 0, 1, 4, 5, 8, 9, 12, 13 }; for (int i = 0; i < array.Length; i++) { ItemData val2 = Item(array[i]); if (val2 != null && !((Humanoid)owner).IsItemEquiped(val2)) { val2.m_equipped = false; if (((Humanoid)owner).EquipItem(val2, false)) { num2++; continue; } MoveOutNow(val2); num3++; } } if (num + num2 + num3 != 0) { SetupEquipment((Humanoid)(object)owner); Notify(inventory, arg2: true, arg3: false); CorePlugin.LogEquipment("Équipement réconcilié : déplacés=" + num + ", équipés=" + num2 + ", sortis=" + num3); } } internal static void BeginGraveTransfer(Player p) { //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Invalid comparison between Unknown and I4 if (!Object.op_Implicit((Object)(object)p) || (Object)(object)p != (Object)(object)Player.m_localPlayer) { return; } Ensure(p); graveTransfer = true; pendingDisplaced.Clear(); if ((Object.op_Implicit((Object)(object)ZoneSystem.instance) && ZoneSystem.instance.GetGlobalKey((GlobalKeys)23)) || (Object.op_Implicit((Object)(object)ZoneSystem.instance) && ZoneSystem.instance.GetGlobalKey((GlobalKeys)19))) { return; } string value = (Object.op_Implicit((Object)(object)Game.instance) ? Game.instance.GetPlayerProfile().GetPlayerID().ToString() : ""); for (int i = 0; i < 16; i++) { ItemData val = Item(i); if (val != null && IsEquipmentStateSlot(i) && ((Humanoid)owner).IsItemEquiped(val)) { val.m_customData["ValheimCore.Equipment.DeathEquipped.v1"] = value; if ((i == 9 || i == 13) && (int)val.m_shared.m_itemType == 18) { val.m_equipped = false; } } } } internal static void EndGraveTransfer(Player p) { if ((Object)(object)p == (Object)(object)Player.m_localPlayer) { graveTransfer = false; pendingDisplaced.Clear(); slotsDirty = true; } } internal static void RestoreFromTombstone() { //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Invalid comparison between Unknown and I4 //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || ((Character)Player.m_localPlayer).IsDead()) { return; } Ensure(Player.m_localPlayer); string text = (Object.op_Implicit((Object)(object)Game.instance) ? Game.instance.GetPlayerProfile().GetPlayerID().ToString() : ""); List<ItemData> list = new List<ItemData>(); foreach (ItemData allItem in ((Humanoid)owner).GetInventory().GetAllItems()) { if (allItem != null && allItem.m_customData.TryGetValue("ValheimCore.Equipment.DeathEquipped.v1", out var value) && value == text) { allItem.m_customData.Remove("ValheimCore.Equipment.DeathEquipped.v1"); list.Add(allItem); } } ReconcileEquipment(); int num = 0; foreach (ItemData item in list) { if (!((Humanoid)owner).GetInventory().ContainsItem(item) || ((Humanoid)owner).IsItemEquiped(item) || (int)item.m_shared.m_itemType == 2) { continue; } int num2 = SpecialIndex(item.m_gridPos); if (num2 < 0) { num2 = RestoreIndex(item); if (num2 >= 0 && Unlocked(num2) && Fits(num2, item) && Item(num2) == null) { item.m_gridPos = Pos(num2); } } if (num2 >= 0 && IsEquipmentStateSlot(num2) && ((Humanoid)owner).EquipItem(item, false)) { num++; } } if (list.Count > 0) { SetupEquipment((Humanoid)(object)owner); Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); CorePlugin.LogEquipment("Tombe restaurée : " + list.Count + " objets, " + num + " rééquipés."); } } internal static bool TombstoneFits(Player p, Inventory grave) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)p) || (Object)(object)p != (Object)(object)Player.m_localPlayer || grave == null) { return false; } Ensure(p); HashSet<int> hashSet = new HashSet<int>(); int num = 0; List<ItemData> list = new List<ItemData>(); foreach (ItemData allItem in grave.GetAllItems()) { int num2 = SpecialIndex(allItem.m_gridPos); if (num2 < 0 || !IsEquipmentStateSlot(num2) || !Unlocked(num2) || !Fits(num2, allItem) || Item(num2) != null || !hashSet.Add(num2)) { num++; list.Add(allItem); } } int emptySlots = ((Humanoid)p).GetInventory().GetEmptySlots(); if (num > emptySlots) { foreach (ItemData item in list) { if (((Humanoid)p).GetInventory().FindFreeStackSpace(item.m_shared.m_name, (float)item.m_worldLevel) >= item.m_stack) { num--; } } } if (num <= emptySlots) { return ((Humanoid)p).GetInventory().GetTotalWeight() + grave.GetTotalWeight() <= p.GetMaxCarryWeight(); } return false; } internal static void SaveBackup(Player p) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) Ensure(p); Inventory val = new Inventory("Core Equipment backup", (Sprite)null, 4, 4); for (int i = 0; i < 16; i++) { ItemData val2 = Item(i); if (val2 != null) { val.AddItem(val2.Clone(), new Vector2i(i % 4, i / 4)); } } ZPackage val3 = new ZPackage(); val.Save(val3); p.m_customData["ValheimCore.Equipment.Backup.v2"] = val3.GetBase64(); p.m_customData["ValheimCore.Equipment.BaseRows.v2"] = baseRows.ToString(); } internal static void PrepareResize(Player p, ref int rows, out int original) { original = -1; if (Object.op_Implicit((Object)(object)p) && !((Object)(object)p != (Object)(object)Player.m_localPlayer)) { owner = p; original = Math.Max(1, rows); baseRows = original; p.m_customData["ValheimCore.Equipment.BaseRows.v2"] = baseRows.ToString(); rows = baseRows + (16 + ((Humanoid)p).GetInventory().GetWidth() - 1) / ((Humanoid)p).GetInventory().GetWidth(); } } internal static void FinishResize(Player p, int original) { if (original >= 0 && Object.op_Implicit((Object)(object)p)) { p.m_customData["ValheimCore.Equipment.BaseRows.v2"] = original.ToString(); p.AddUniqueKeyValue("invrows", original.ToString()); baseRows = original; owner = p; Extend(); if (Object.op_Implicit((Object)(object)InventoryGui.instance)) { InventoryGui.instance.SetInventorySize(baseRows); } Validate(CorePlugin.Ready); slotsDirty = true; } } internal static void BeginLoad(Player p) { if ((Object)(object)p == (Object)(object)Player.m_localPlayer) { owner = p; restoring = true; } } internal static void EndLoad(Player p) { if ((Object)(object)p == (Object)(object)Player.m_localPlayer && restoring) { owner = p; ReadBaseRows(p); Extend(); MigrateLegacy(); restoring = false; Validate(CorePlugin.Ready); ReconcileEquipment(); slotsDirty = true; if (Object.op_Implicit((Object)(object)InventoryGui.instance) && DraggedItem(InventoryGui.instance) != null) { ClearDrag(InventoryGui.instance, null, null, 1); } Notify(((Humanoid)p).GetInventory(), arg2: true, arg3: false); } } internal static void ApplyPreviewVisuals(Player p) { //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Invalid comparison between Unknown and I4 //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Invalid comparison between Unknown and I4 //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Invalid comparison between Unknown and I4 //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Invalid comparison between Unknown and I4 //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Invalid comparison between Unknown and I4 //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Invalid comparison between Unknown and I4 //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Invalid comparison between Unknown and I4 if (!Object.op_Implicit((Object)(object)p) || (Object)(object)p == (Object)(object)Player.m_localPlayer) { return; } VisEquipment component = ((Component)p).GetComponent<VisEquipment>(); if (!Object.op_Implicit((Object)(object)component)) { return; } int num = 4; if (p.m_customData.TryGetValue("ValheimCore.Equipment.BaseRows.v2", out var value) && int.TryParse(value, out var result) && result > 0) { num = result; } ItemData i = null; ItemData val = null; ItemData i2 = null; ItemData i3 = null; ItemData val2 = null; ItemData val3 = null; foreach (ItemData allItem in ((Humanoid)p).GetInventory().GetAllItems()) { int num2 = (allItem.m_gridPos.y - num) * ((Humanoid)p).GetInventory().GetWidth() + allItem.m_gridPos.x; if (num2 < 0 || num2 >= 16 || !IsWearableSlot(num2)) { continue; } ItemType itemType = allItem.m_shared.m_itemType; if ((int)itemType <= 11) { if ((int)itemType != 6) { if ((int)itemType != 7) { if ((int)itemType == 11) { i3 = allItem; } } else { i2 = allItem; } } else { i = allItem; } } else if ((int)itemType != 17) { if ((int)itemType != 18) { if ((int)itemType == 24) { val2 = allItem; } } else if (val3 == null) { val3 = allItem; } } else { val = allItem; } } component.SetHelmetItem(Hash(i)); component.SetShoulderItem(Hash(val), val?.m_variant ?? 0, val?.m_quality ?? 0); component.SetChestItem(Hash(i2)); component.SetLegItem(Hash(i3)); component.SetTrinketItem((val2 != null && Object.op_Implicit((Object)(object)val2.m_dropPrefab)) ? ((Object)val2.m_dropPrefab).name : ""); component.SetUtilityItem(Hash(val3)); } private static int Hash(ItemData i) { if (i == null || !Object.op_Implicit((Object)(object)i.m_dropPrefab)) { return 0; } return StringExtensionMethods.GetStableHashCode(((Object)i.m_dropPrefab).name); } internal static int VisibleRows(Inventory i) { if (!Object.op_Implicit((Object)(object)owner) || i != ((Humanoid)owner).GetInventory()) { return -1; } return baseRows; } internal static int SpecialIndex(Vector2i p) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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) if (!Object.op_Implicit((Object)(object)owner) || p.y < baseRows) { return -1; } int num = (p.y - baseRows) * ((Humanoid)owner).GetInventory().GetWidth() + p.x; if (num < 0 || num >= 16) { return -1; } return num; } internal static string SlotName(int n) { if (n < 0 || n >= Names.Length) { return ""; } return Names[n]; } internal static string LocationName(int n) { if (n < 0) { return "Vanilla Inventory"; } return SlotName(n); } internal static bool IsWearableSlot(int n) { if (n != 0 && n != 1 && n != 4 && n != 5 && n != 8 && n != 9 && n != 12) { return n == 13; } return true; } internal static bool IsArrowSlot(int n) { if (n != 2 && n != 6 && n != 10) { return n == 14; } return true; } internal static bool IsEquipmentStateSlot(int n) { if (!IsWearableSlot(n)) { return IsArrowSlot(n); } return true; } internal static void ToggleMinimized() { if (minimized != null) { if (minimized.Value) { minimized.Value = false; compact.Value = false; } else { minimized.Value = true; } } } internal static void ToggleCompact() { if (compact != null) { if (minimized.Value) { minimized.Value = false; compact.Value = true; } else { compact.Value = !compact.Value; } } } internal static void SetNativeTransfer(bool value) { nativeTransfer = value; } internal static ItemData DraggedItem(InventoryGui gui) { if (!Object.op_Implicit((Object)(object)gui)) { return null; } return DragItem.Invoke(gui); } internal static Inventory DraggedInventory(InventoryGui gui) { if (!Object.op_Implicit((Object)(object)gui)) { return null; } return DragInventory.Invoke(gui); } internal static void ClearNativeDrag(InventoryGui gui) { if (Object.op_Implicit((Object)(object)gui)) { ClearDrag(gui, null, null, 1); } } internal static void NotifyInventory() { if (Object.op_Implicit((Object)(object)owner)) { Notify(((Humanoid)owner).GetInventory(), arg2: true, arg3: false); } } internal static void LogDrag(string message) { CorePlugin.LogEquipment("Drag " + message); } internal static void LogLayoutOnce(float width, float height, float horizontalInset, float verticalInset, float step) { if (!layoutLogged) { layoutLogged = true; CorePlugin.LogEquipment("Layout full panel=" + width.ToString("0.#") + "x" + height.ToString("0.#") + " inset=" + horizontalInset.ToString("0.#") + "," + verticalInset.ToString("0.#") + " step=" + step.ToString("0.#")); } } } [HarmonyPatch(typeof(Player), "Save")] internal static class EqSave { [HarmonyPrefix] private static void Prefix(Player __instance) { EquipmentModule.SaveBackup(__instance); } } [HarmonyPatch(typeof(Player), "SetInventorySize")] internal static class EqResize { [HarmonyPrefix] private static void Prefix(Player __instance, ref int rows, out int __state) { EquipmentModule.PrepareResize(__instance, ref rows, out __state); } [HarmonyPostfix] private static void Postfix(Player __instance, int __state) { EquipmentModule.FinishResize(__instance, __state); } } [HarmonyPatch(typeof(Inventory), "FindEmptySlot")] internal static class EqEmpty { [HarmonyPostfix] private static void Postfix(Inventory __instance, ref Vector2i __result) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) int num = EquipmentModule.VisibleRows(__instance); if (num < 0) { return; } if (__result.y >= num) { __result = new Vector2i(-1, -1); for (int i = 0; i < num; i++) { if (__result.x >= 0) { break; } for (int j = 0; j < __instance.GetWidth(); j++) { if (__instance.GetItemAt(j, i) == null) { __result = new Vector2i(j, i); break; } } } } if (__result.x < 0) { EquipmentModule.DirectPosition(__instance, ref __result); } } } [HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[] { typeof(ItemData), typeof(int) })] internal static class EqCanDirect { [HarmonyPostfix] private static void Postfix(Inventory __instance, ItemData item, int stack, ref bool __result) { if (EquipmentModule.VisibleRows(__instance) >= 0) { __result = EquipmentModule.CanAddVisible(__instance, item, stack); } } } [HarmonyPatch(typeof(Humanoid), "Pickup")] internal static class EqDirectPickup { [HarmonyPrefix] private static void Prefix(Humanoid __instance, GameObject go) { EquipmentModule.BeginDirectPickup(__instance, go); } [HarmonyPostfix] private static void Postfix(Humanoid __instance, GameObject go, bool __result) { EquipmentModule.EndDirectPickup(__instance, go, __result); } [HarmonyFinalizer] private static Exception Finalizer(Exception __exception) { EquipmentModule.ClearDirectPickup(); return __exception; } } [HarmonyPatch(typeof(Inventory), "GetEmptySlots")] internal static class EqEmptyCount { [HarmonyPostfix] private static void Postfix(Inventory __instance, ref int __result) { if (EquipmentModule.VisibleRows(__instance) >= 0) { __result = EquipmentModule.BaseEmptySlots(__instance); } } } [HarmonyPatch(typeof(Player), "Load")] internal static class EqLoad { [HarmonyPrefix] private static void Prefix(Player __instance) { EquipmentModule.BeginLoad(__instance); } [HarmonyPostfix] private static void Postfix(Player __instance) { EquipmentModule.EndLoad(__instance); } [HarmonyFinalizer] private static Exception Finalizer(Player __instance, Exception __exception) { EquipmentModule.EndLoad(__instance); return __exception; } } [HarmonyPatch(typeof(Player), "CreateTombStone")] internal static class EqGraveTransfer { [HarmonyPrefix] private static void Prefix(Player __instance) { EquipmentModule.BeginGraveTransfer(__instance); } [HarmonyFinalizer] private static Exception Finalizer(Player __instance, Exception __exception) { EquipmentModule.EndGraveTransfer(__instance); return __exception; } } [HarmonyPatch(typeof(TombStone), "EasyFitInInventory")] internal static class EqGraveFit { [HarmonyPostfix] private static void Postfix(Player player, Container ___m_container, ref bool __result) { if (!__result && Object.op_Implicit((Object)(object)___m_container)) { __result = EquipmentModule.TombstoneFits(player, ___m_container.GetInventory()); } } } [HarmonyPatch(typeof(TombStone), "OnTakeAllSuccess")] internal static class EqGraveTakeAll { [HarmonyPostfix] private static void Postfix() { EquipmentModule.RestoreFromTombstone(); } } [HarmonyPatch(typeof(InventoryGui), "OnTakeAll")] internal static class EqGraveGuiTakeAll { [HarmonyPostfix] private static void Postfix(Container ___m_currentContainer) { if (Object.op_Implicit((Object)(object)___m_currentContainer) && Object.op_Implicit((Object)(object)((Component)___m_currentContainer).GetComponent<TombStone>())) { EquipmentModule.RestoreFromTombstone(); } } } [Harmo