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 ValheimHUD v1.0.2
plugins/ValheimHUD.dll
Decompiled 6 hours 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.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ValheimHUD { internal class CharacterStage : MonoBehaviour, IDragHandler, IEventSystemHandler, IScrollHandler, IPointerClickHandler { private const float Fov = 26f; private const float DefaultYaw = 18f; private RawImage _view; private RenderTexture _rt; private Camera _cam; private Light _key; private Light _rim; private int _layer = -1; private Player _player; private readonly List<Renderer> _rends = new List<Renderer>(); private readonly List<int> _saved = new List<int>(); private static readonly List<Renderer> Found = new List<Renderer>(); private float _rescan; private bool _swapped; private float _yaw = 18f; private float _yawShown = 18f; private float _zoom; private float _zoomShown; private float _height = 1.85f; private static readonly FieldRef<InventoryGui, ItemData> _dragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem"); private static readonly FieldRef<InventoryGui, Inventory> _dragInv = AccessTools.FieldRefAccess<InventoryGui, Inventory>("m_dragInventory"); private static readonly Color Backdrop = new Color(0.1f, 0.075f, 0.05f, 1f); public static CharacterStage Create(RectTransform stage, float w, float h) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Expected O, but got Unknown RectTransform val = UI.Rect("Personagem3D_Borda", (Transform)(object)stage, 0f, 0f, w, h); ((Component)val).gameObject.AddComponent<RectMask2D>().softness = new Vector2Int(46, 46); RectTransform val2 = UI.Rect("Personagem3D", (Transform)(object)val, 0f, 0f, w, h); CharacterStage characterStage = ((Component)val2).gameObject.AddComponent<CharacterStage>(); characterStage._view = ((Component)val2).gameObject.AddComponent<RawImage>(); ((Graphic)characterStage._view).color = new Color(1f, 1f, 1f, 0f); ((Graphic)characterStage._view).raycastTarget = true; int num = 768; int num2 = Mathf.Clamp(Mathf.RoundToInt(768f * h / Mathf.Max(1f, w)), 128, 1536); characterStage._rt = new RenderTexture(num, num2, 24, (RenderTextureFormat)0) { name = "ValheimHUD_PersonagemInventario" }; characterStage._rt.Create(); characterStage._view.texture = (Texture)(object)characterStage._rt; return characterStage; } private static int FreeLayer() { int value = Plugin.MapLayer.Value; for (int num = 30; num >= 20; num--) { if (num != value && string.IsNullOrEmpty(LayerMask.LayerToName(num))) { return num; } } return -1; } private void Setup() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0170: 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_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Expected O, but got Unknown //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Expected O, but got Unknown //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Expected O, but got Unknown //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Expected O, but got Unknown if (!((Object)(object)_cam != (Object)null)) { _layer = FreeLayer(); if (_layer < 0) { Plugin.Log.LogWarning((object)"[Personagem] nenhuma layer livre pra filmar o personagem."); ((Behaviour)this).enabled = false; return; } GameObject val = new GameObject("ValheimHUD_PersonagemCam"); _cam = val.AddComponent<Camera>(); _cam.fieldOfView = 26f; _cam.nearClipPlane = 0.2f; _cam.farClipPlane = 12f; _cam.clearFlags = (CameraClearFlags)2; _cam.backgroundColor = Backdrop; _cam.cullingMask = 1 << _layer; _cam.targetTexture = _rt; _cam.renderingPath = (RenderingPath)(-1); _cam.depth = -98f; _cam.allowHDR = false; _cam.allowMSAA = false; _cam.useOcclusionCulling = false; ((Behaviour)_cam).enabled = false; _key = MakeLight(val.transform, "Chave", new Vector3(0.9f, 1.1f, 0.3f), 1.35f, new Color(1f, 0.93f, 0.82f)); _rim = MakeLight(val.transform, "Contorno", new Vector3(-1.2f, 0.6f, 4.6f), 1.6f, new Color(1f, 0.62f, 0.32f)); Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(BeforeCull)); Camera.onPostRender = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(AfterRender)); } } private Light MakeLight(Transform parent, string name, Vector3 local, float intensity, Color color) { //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_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.transform.localPosition = local; Light obj = val.AddComponent<Light>(); obj.type = (LightType)2; obj.range = 9f; obj.intensity = intensity; obj.color = color; obj.shadows = (LightShadows)0; obj.cullingMask = 1 << _layer; ((Behaviour)obj).enabled = false; return obj; } private void Rescan() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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) _rends.Clear(); if ((Object)(object)_player == (Object)null) { return; } float num = ((Component)_player).transform.position.y + 1f; ((Component)_player).GetComponentsInChildren<Renderer>(Found); foreach (Renderer item in Found) { if (!(item is ParticleSystemRenderer) && !(item is TrailRenderer) && !(item is LineRenderer) && item.enabled && ((Component)item).gameObject.activeInHierarchy) { _rends.Add(item); if (item is SkinnedMeshRenderer) { float num2 = num; Bounds bounds = item.bounds; num = Mathf.Max(num2, ((Bounds)(ref bounds)).max.y); } } } _height = Mathf.Clamp(num - ((Component)_player).transform.position.y, 1.2f, 2.6f); } private void BeforeCull(Camera c) { if ((Object)(object)c != (Object)(object)_cam || _swapped) { return; } _saved.Clear(); for (int i = 0; i < _rends.Count; i++) { Renderer val = _rends[i]; if ((Object)(object)val == (Object)null) { _saved.Add(-1); continue; } _saved.Add(((Component)val).gameObject.layer); ((Component)val).gameObject.layer = _layer; } _swapped = true; Light key = _key; bool enabled = (((Behaviour)_rim).enabled = true); ((Behaviour)key).enabled = enabled; } private void AfterRender(Camera c) { if ((Object)(object)c != (Object)(object)_cam || !_swapped) { return; } for (int i = 0; i < _rends.Count && i < _saved.Count; i++) { if ((Object)(object)_rends[i] != (Object)null && _saved[i] >= 0) { ((Component)_rends[i]).gameObject.layer = _saved[i]; } } _swapped = false; Light key = _key; bool enabled = (((Behaviour)_rim).enabled = false); ((Behaviour)key).enabled = enabled; } private void LateUpdate() { //IL_0113: 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_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer != (Object)null) || !InventoryGui.IsVisible() || !((Component)this).gameObject.activeInHierarchy) { if ((Object)(object)_cam != (Object)null && ((Behaviour)_cam).enabled) { ((Behaviour)_cam).enabled = false; } return; } Setup(); if (!((Object)(object)_cam == (Object)null)) { if ((Object)(object)localPlayer != (Object)(object)_player) { _player = localPlayer; _rescan = 0f; } _rescan -= Time.unscaledDeltaTime; if (_rescan <= 0f) { _rescan = 0.4f; Rescan(); } float unscaledDeltaTime = Time.unscaledDeltaTime; _yawShown = Mathf.LerpAngle(_yawShown, _yaw, 1f - Mathf.Exp((0f - unscaledDeltaTime) * 14f)); _zoomShown = Mathf.Lerp(_zoomShown, _zoom, 1f - Mathf.Exp((0f - unscaledDeltaTime) * 10f)); Vector3 forward = ((Component)localPlayer).transform.forward; forward.y = 0f; if (((Vector3)(ref forward)).sqrMagnitude < 0.001f) { forward = Vector3.forward; } ((Vector3)(ref forward)).Normalize(); Vector3 val = Quaternion.Euler(0f, _yawShown, 0f) * forward; float num = _height * 0.56f / Mathf.Tan(0.2268928f); float num2 = Mathf.Lerp(num, num * 0.38f, _zoomShown); Vector3 val2 = ((Component)localPlayer).transform.position + Vector3.up * Mathf.Lerp(_height * 0.5f, _height * 0.86f, _zoomShown); ((Component)_cam).transform.position = val2 + val * num2 + Vector3.up * num2 * 0.06f; ((Component)_cam).transform.LookAt(val2); if (!((Behaviour)_cam).enabled) { ((Behaviour)_cam).enabled = true; } if (((Graphic)_view).color.a < 1f) { ((Graphic)_view).color = Color.white; } } } public void OnDrag(PointerEventData e) { //IL_0001: 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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 if ((int)e.button == 0 || (int)e.button == 1) { _yaw -= e.delta.x * 0.45f; } } public void OnScroll(PointerEventData e) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) _zoom = Mathf.Clamp01(_zoom + e.scrollDelta.y * 0.12f); } public void OnPointerClick(PointerEventData e) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) if (e.dragging) { return; } InventoryGui instance = InventoryGui.instance; Player localPlayer = Player.m_localPlayer; if ((Object)(object)instance != (Object)null && (Object)(object)localPlayer != (Object)null && (int)e.button == 0) { ItemData val = _dragItem.Invoke(instance); Inventory val2 = _dragInv.Invoke(instance); if (val != null && val2 != null) { if (val.IsEquipable() && val2 == ((Humanoid)localPlayer).GetInventory()) { ((Humanoid)localPlayer).UseItem(val2, val, true); Traverse.Create((object)instance).Method("SetupDragItem", new Type[3] { typeof(ItemData), typeof(Inventory), typeof(int) }, (object[])null).GetValue(new object[3] { null, null, 1 }); } return; } } if (e.clickCount >= 2) { _yaw = 18f; _zoom = 0f; } } private void OnDestroy() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(BeforeCull)); Camera.onPostRender = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(AfterRender)); if (_swapped) { AfterRender(_cam); } if ((Object)(object)_cam != (Object)null) { Object.Destroy((Object)(object)((Component)_cam).gameObject); } if ((Object)(object)_rt != (Object)null) { _rt.Release(); Object.Destroy((Object)(object)_rt); } } } internal static class Compat { public const string AepiGuid = "Azumatt.AzuExtendedPlayerInventory"; public const string GlitnirInventoryGuid = "glitnir.inventory"; public const string ProgressionLockGuid = "ValheimProgressionLock"; private static bool? _aepi; private static bool? _glitnirInv; private const string NpcsGuid = "morgnar.valheimnpcs"; private const string NpcClockName = "ValheimNPCs_Clock"; private static bool? _npcs; private static CanvasGroup _npcClock; private static float _npcLookup; private static readonly string[] PartyHudGuids = new string[2] { "com.dhack.partyhud", "com.quad.partyhud" }; private static bool _partyTried; private static ConfigEntry<bool> _partyOn; private static ConfigEntry<bool> _partyLeft; private static ConfigEntry<bool> _partyBottom; private static bool _lockTried; private static FieldInfo _stateF; private static FieldInfo _blockUseF; private static MethodInfo _isLocked; private static readonly object[] Args = new object[2]; public static bool Aepi { get { bool? aepi = _aepi; if (!aepi.HasValue) { bool? flag = (_aepi = Chainloader.PluginInfos.ContainsKey("Azumatt.AzuExtendedPlayerInventory")); return flag.Value; } return aepi == true; } } public static bool GlitnirInventory { get { bool? glitnirInv = _glitnirInv; if (!glitnirInv.HasValue) { bool? flag = (_glitnirInv = Chainloader.PluginInfos.ContainsKey("glitnir.inventory")); return flag.Value; } return glitnirInv == true; } } public static bool OtherInventory { get { if (!Aepi && !GlitnirInventory) { return PovCompat.EquipmentOn; } return true; } } public static bool OtherInventoryScreen { get { if (!GlitnirInventory) { if (PovCompat.Installed) { return !PovCompat.CanHost; } return false; } return true; } } public static string OtherInventoryName { get { if (!Aepi) { if (!GlitnirInventory) { return "Path of Valheiman (equipamento)"; } return "GlitnirInventory"; } return "AzuExtendedPlayerInventory"; } } public static bool PartyHudOnRight { get { if (!_partyTried) { _partyTried = true; string[] partyHudGuids = PartyHudGuids; foreach (string key in partyHudGuids) { if (Chainloader.PluginInfos.TryGetValue(key, out var value) && !((Object)(object)value.Instance == (Object)null)) { ConfigFile config = value.Instance.Config; config.TryGetEntry<bool>("General", "Enabled", ref _partyOn); config.TryGetEntry<bool>("Layout", "OnLeft", ref _partyLeft); config.TryGetEntry<bool>("Layout", "AnchorBottom", ref _partyBottom); Plugin.Log.LogInfo((object)"PartyHud encontrado: buffs do lado do minimapa."); break; } } } if (_partyOn == null) { return false; } if (_partyOn.Value && (_partyLeft == null || !_partyLeft.Value)) { if (_partyBottom != null) { return !_partyBottom.Value; } return true; } return false; } } public static void HideNpcClock(bool hide) { bool? npcs = _npcs; bool num; if (!npcs.HasValue) { bool? flag = (_npcs = Chainloader.PluginInfos.ContainsKey("morgnar.valheimnpcs")); num = flag.Value; } else { num = npcs == true; } if (!num) { return; } if ((Object)(object)_npcClock == (Object)null) { if (!hide || Time.unscaledTime < _npcLookup) { return; } _npcLookup = Time.unscaledTime + 2f; GameObject val = GameObject.Find("ValheimNPCs_Clock"); if ((Object)(object)val == (Object)null) { return; } _npcClock = val.GetComponent<CanvasGroup>() ?? val.AddComponent<CanvasGroup>(); _npcClock.blocksRaycasts = false; } float num2 = (hide ? 0f : 1f); if (_npcClock.alpha != num2) { _npcClock.alpha = num2; } } public static bool LockedByProgression(ItemData item) { if ((Object)(object)item?.m_dropPrefab == (Object)null || !BindLock()) { return false; } try { object value = _stateF.GetValue(null); if (value != null) { object value2 = _blockUseF.GetValue(value); if (value2 is bool && (bool)value2) { Args[0] = ((Object)item.m_dropPrefab).name; Args[1] = null; value2 = _isLocked.Invoke(null, Args); bool flag = default(bool); int num; if (value2 is bool) { flag = (bool)value2; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } } return false; } catch { return false; } } private static bool BindLock() { if (_lockTried) { return _isLocked != null; } _lockTried = true; if (!Chainloader.PluginInfos.ContainsKey("ValheimProgressionLock")) { return false; } try { Type type = AccessTools.TypeByName("ValheimProgressionLock.ValheimProgressionLockPlugin"); _stateF = ((type != null) ? AccessTools.Field(type, "State") : null); _blockUseF = ((_stateF != null) ? AccessTools.Field(_stateF.FieldType, "BlockUse") : null); _isLocked = ((type != null) ? AccessTools.Method(type, "IsLocked", new Type[2] { typeof(string), typeof(string).MakeByRefType() }, (Type[])null) : null); if (_stateF == null || _blockUseF == null) { _isLocked = null; } if (_isLocked == null) { Plugin.Log.LogWarning((object)"ValheimProgressionLock: não deu pra ler as travas (versão diferente?)."); } } catch (Exception ex) { _isLocked = null; Plugin.Log.LogWarning((object)("ValheimProgressionLock: " + ex.Message)); } return _isLocked != null; } } internal static class EpicMmoCompat { public const string Guid = "WackyMole.EpicMMOSystem"; private static bool _tried; private static bool _ok; private static MethodInfo _instM; private static MethodInfo _levelM; private static MethodInfo _curM; private static MethodInfo _needM; private static MethodInfo _pointsM; private static MethodInfo _levelPanelM; private static MethodInfo _friendsM; private static MethodInfo _inviteM; private static FieldInfo _navF; private static FieldInfo _friendsBtnF; private static CanvasGroup _nav; private static readonly List<FieldInfo> HudFields = new List<FieldInfo>(); private static readonly List<CanvasGroup> Hidden = new List<CanvasGroup>(); private static float _nextLookup; private const float CacheTime = 0.2f; private static float _readAt = -1f; private static bool _hasLevel; private static int _level; private static int _points; private static float _progress; public static bool Active { get { if (Plugin.EpicMmoOn.Value) { return Init(); } return false; } } public static bool HasFriends { get { if (Active) { return _friendsM != null; } return false; } } private static bool Init() { if (_tried) { return _ok; } _tried = true; if (!Chainloader.PluginInfos.ContainsKey("WackyMole.EpicMMOSystem")) { return false; } try { Type type = AccessTools.TypeByName("EpicMMOSystem.LevelSystem"); Type type2 = AccessTools.TypeByName("EpicMMOSystem.MyUI"); _instM = ((type != null) ? AccessTools.PropertyGetter(type, "Instance") : null); _levelM = ((type != null) ? AccessTools.Method(type, "getLevel", (Type[])null, (Type[])null) : null); _curM = ((type != null) ? AccessTools.Method(type, "getCurrentExp", (Type[])null, (Type[])null) : null); _needM = ((type != null) ? AccessTools.Method(type, "getNeedExp", new Type[1] { typeof(int) }, (Type[])null) : null); _pointsM = ((type != null) ? AccessTools.Method(type, "getFreePoints", (Type[])null, (Type[])null) : null); _levelPanelM = ((type2 != null) ? AccessTools.Method(type2, "ClickButtonLevelSystem", (Type[])null, (Type[])null) : null); _friendsM = ((type2 != null) ? AccessTools.Method(type2, "ClickButtonFriendsList", (Type[])null, (Type[])null) : null); _inviteM = ((type2 != null) ? AccessTools.Method(type2, "hasInvite", (Type[])null, (Type[])null) : null); _navF = ((type2 != null) ? AccessTools.Field(type2, "navigationPanel") : null); _friendsBtnF = ((type2 != null) ? AccessTools.Field(type2, "buttonFriendsList") : null); if (type2 != null) { string[] array = new string[5] { "Exp", "hp", "stamina", "EitrTran", "expPanelBackground" }; foreach (string text in array) { FieldInfo fieldInfo = AccessTools.Field(type2, text); if (fieldInfo != null && fieldInfo.IsStatic) { HudFields.Add(fieldInfo); } } } _ok = _instM != null && _levelM != null && _curM != null && _needM != null; if (_ok) { Plugin.Log.LogInfo((object)"EpicMMOSystem encontrado: nível e XP no HUD."); } else { Plugin.Log.LogWarning((object)"EpicMMOSystem instalado, mas numa versão que o HUD não reconhece: compatibilidade desligada."); } } catch (Exception ex) { _ok = false; Plugin.Log.LogWarning((object)("EpicMMOSystem: compatibilidade desligada (" + ex.Message + ").")); } return _ok; } private static void Read() { float unscaledTime = Time.unscaledTime; if (_readAt >= 0f && unscaledTime - _readAt < 0.2f) { return; } _readAt = unscaledTime; _hasLevel = false; _points = 0; try { object obj = _instM.Invoke(null, null); if (obj != null) { _level = Convert.ToInt32(_levelM.Invoke(obj, null)); long num = Convert.ToInt64(_curM.Invoke(obj, null)); long num2 = Convert.ToInt64(_needM.Invoke(obj, new object[1] { 0 })); _progress = ((num2 > 0) ? Mathf.Clamp01((float)num / (float)num2) : 1f); if (_pointsM != null) { _points = Convert.ToInt32(_pointsM.Invoke(obj, null)); } _hasLevel = _level > 0; } } catch { _hasLevel = false; } } public static bool TryGet(out int level, out float progress) { level = 0; progress = 0f; if (!Active || (Object)(object)Player.m_localPlayer == (Object)null) { return false; } Read(); level = _level; progress = _progress; return _hasLevel; } public static int AvailablePoints() { if (!Active || (Object)(object)Player.m_localPlayer == (Object)null) { return 0; } Read(); return _points; } public static void OpenAttributes() { Click(_levelPanelM, "atributos"); } public static void OpenFriends() { Click(_friendsM, "amigos"); } public static bool HasInvite() { if (!HasFriends || _inviteM == null) { return false; } try { object obj = _inviteM.Invoke(null, null); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } catch { return false; } } public static Sprite FriendsIcon() { if (!HasFriends || _friendsBtnF == null) { return null; } try { object? value = _friendsBtnF.GetValue(null); Transform val = (Transform)((value is Transform) ? value : null); if (val == null || (Object)(object)val == (Object)null) { return null; } Transform val2 = ((val.childCount > 0) ? val.GetChild(0) : null); Sprite result = null; Image[] componentsInChildren = ((Component)val).GetComponentsInChildren<Image>(true); foreach (Image val3 in componentsInChildren) { if (!((Object)(object)val3.sprite == (Object)null) && (!((Object)(object)val2 != (Object)null) || !((Component)val3).transform.IsChildOf(val2))) { result = val3.sprite; if ((Object)(object)((Component)val3).transform != (Object)(object)val) { break; } } } return result; } catch { return null; } } private static void Click(MethodInfo m, string what) { if (!Active || m == null) { return; } try { m.Invoke(null, null); } catch (Exception ex) { Plugin.Log.LogWarning((object)("EpicMMOSystem: não deu pra abrir " + what + " (" + ex.Message + ").")); } } private static void HideNav(bool hide) { if ((Object)(object)_nav == (Object)null) { if (!hide || _navF == null) { return; } try { object? value = _navF.GetValue(null); GameObject val = (GameObject)((value is GameObject) ? value : null); if (val == null || (Object)(object)val == (Object)null) { return; } _nav = val.GetComponent<CanvasGroup>() ?? val.AddComponent<CanvasGroup>(); } catch { return; } } float num = (hide ? 0f : 1f); if (_nav.alpha != num) { _nav.alpha = num; _nav.blocksRaycasts = !hide; _nav.interactable = !hide; } } public static void Tick() { if (_tried && _ok) { HideNav(Active && InventoryScreen.Active); } if (!Active || !Plugin.EpicMmoHideHud.Value || !Plugin.Enabled.Value || !Plugin.BarsEnabled.Value) { foreach (CanvasGroup item in Hidden) { if ((Object)(object)item != (Object)null && item.alpha < 1f) { item.alpha = 1f; item.blocksRaycasts = true; } } return; } if (Time.unscaledTime >= _nextLookup) { _nextLookup = Time.unscaledTime + 1f; Hidden.RemoveAll((CanvasGroup g) => (Object)(object)g == (Object)null); foreach (FieldInfo hudField in HudFields) { object value; try { value = hudField.GetValue(null); } catch { continue; } Component val = (Component)((value is Component) ? value : null); object obj3; if (val == null || !((Object)(object)val != (Object)null)) { object obj2 = ((value is GameObject) ? value : null); obj3 = ((obj2 != null) ? ((GameObject)obj2).transform : null); } else { obj3 = val.transform; } Transform val2 = (Transform)obj3; if (!((Object)(object)val2 == (Object)null)) { CanvasGroup val3 = ((Component)val2).GetComponent<CanvasGroup>(); if ((Object)(object)val3 == (Object)null) { val3 = ((Component)val2).gameObject.AddComponent<CanvasGroup>(); } if (!Hidden.Contains(val3)) { Hidden.Add(val3); } } } } foreach (CanvasGroup item2 in Hidden) { if ((Object)(object)item2 != (Object)null && item2.alpha > 0f) { item2.alpha = 0f; item2.blocksRaycasts = false; } } } } internal static class Levels { public static bool Active { get { if (!LevelingCompat.Active && !EpicMmoCompat.Active) { return PovCompat.Active; } return true; } } public static bool TryGet(Player p, out int level, out float progress) { if (LevelingCompat.Active) { return LevelingCompat.TryGet(p, out level, out progress); } if (EpicMmoCompat.Active) { return EpicMmoCompat.TryGet(out level, out progress); } return PovCompat.TryGet(out level, out progress); } public static int AvailablePoints(Player p) { if (!LevelingCompat.Active) { if (!EpicMmoCompat.Active) { return PovCompat.AvailablePoints(); } return EpicMmoCompat.AvailablePoints(); } return LevelingCompat.AvailablePoints(p); } public static void OpenAttributes() { if (LevelingCompat.Active) { LevelingCompat.OpenAttributes(); } else if (EpicMmoCompat.Active) { EpicMmoCompat.OpenAttributes(); } else { PovCompat.OpenTree(); } } } internal static class ExtraSlots { public static int NormalRows; public const int ExtraRows = 2; public const int ExtraUtilX = 6; public const int UtilitySlots = 2; public static bool Active; private static readonly ItemType[] EquipTypes; private static readonly FieldRef<Inventory, List<ItemData>> InvList; private static readonly FieldInfo InvHeight; private static readonly MethodInfo InvChanged; private static readonly MethodInfo TakeInputM; private static readonly string[] EquipFields; private static readonly FieldInfo[] EquipFieldInfos; private static readonly HashSet<ItemData> StuckUnequipped; internal static bool Suppress; internal static bool InEquip; private static float _timer; private static Player _migratedFor; private static readonly FieldRef<Humanoid, HashSet<StatusEffect>> WornEffects; private static readonly Dictionary<int, KeyValuePair<StatusEffect, int>> WantEffects; private static readonly HashSet<int> OurEffects; private static readonly List<int> Drop; private static Player _effectsFor; private static readonly List<ItemData> Snapshot; public const string WearKey = "ValheimHUD_vestir"; private static RectTransform _panel; private static Image _panelBg; private static bool _panelVanilla; private static InventoryGrid _panelGrid; private static readonly FieldInfo ElementsF; private static readonly FieldInfo ElementSpaceF; private static readonly FieldInfo PlayerPanelF; private static readonly FieldInfo GridRootF; private static readonly FieldInfo InvRootF; private static RectTransform _playerPanel; private static readonly Vector3[] Corners; private static readonly string[] SilNames; private static readonly Dictionary<GameObject, Image> Silhouettes; private const float Pad = 14f; private const float GroupGap = 10f; private const float FlikWidth = 74f; private static readonly HashSet<string> _logged; public static int EquipRow => NormalRows; public static int QuickRow => NormalRows + 1; public static Inventory PlayerInv { get { if (!((Object)(object)Player.m_localPlayer != (Object)null)) { return null; } return ((Humanoid)Player.m_localPlayer).GetInventory(); } } public static RectTransform Panel => _panel; static ExtraSlots() { NormalRows = 4; ItemType[] array = new ItemType[6]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); EquipTypes = (ItemType[])(object)array; InvList = AccessTools.FieldRefAccess<Inventory, List<ItemData>>("m_inventory"); InvHeight = AccessTools.Field(typeof(Inventory), "m_height"); InvChanged = AccessTools.Method(typeof(Inventory), "Changed", new Type[2] { typeof(bool), typeof(bool) }, (Type[])null); TakeInputM = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null); EquipFields = new string[6] { "m_helmetItem", "m_chestItem", "m_legItem", "m_shoulderItem", "m_utilityItem", "m_trinketItem" }; EquipFieldInfos = new FieldInfo[6]; StuckUnequipped = new HashSet<ItemData>(); WornEffects = AccessTools.FieldRefAccess<Humanoid, HashSet<StatusEffect>>("m_equipmentStatusEffects"); WantEffects = new Dictionary<int, KeyValuePair<StatusEffect, int>>(); OurEffects = new HashSet<int>(); Drop = new List<int>(); Snapshot = new List<ItemData>(); ElementsF = AccessTools.Field(typeof(InventoryGrid), "m_elements"); ElementSpaceF = AccessTools.Field(typeof(InventoryGrid), "m_elementSpace"); PlayerPanelF = AccessTools.Field(typeof(InventoryGui), "m_player"); GridRootF = AccessTools.Field(typeof(InventoryGrid), "m_gridRoot"); InvRootF = AccessTools.Field(typeof(InventoryGui), "m_inventoryRoot"); Corners = (Vector3[])(object)new Vector3[4]; SilNames = new string[8] { "helmet", "chest", "legs", "cape", "utility", "trinket", "wishbone", "wisp" }; Silhouettes = new Dictionary<GameObject, Image>(); _logged = new HashSet<string>(); for (int i = 0; i < EquipFields.Length; i++) { EquipFieldInfos[i] = AccessTools.Field(typeof(Humanoid), EquipFields[i]); } } public static bool IsPlayerInv(Inventory inv) { if (Active && inv != null) { return inv == PlayerInv; } return false; } public static bool IsSpecial(Vector2i p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return p.y >= NormalRows; } public static int EquipIndex(ItemData item) { //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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between I4 and Unknown if (item == null) { return -1; } ItemType itemType = item.m_shared.m_itemType; for (int i = 0; i < EquipTypes.Length; i++) { if ((int)EquipTypes[i] == (int)itemType) { return i; } } return -1; } public static bool IsAmmo(ItemData item) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 if (item != null) { return (int)item.m_shared.m_itemType == 9; } return false; } public static bool IsUtility(ItemData item) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 if (item != null) { return (int)item.m_shared.m_itemType == 18; } return false; } public static bool IsFood(ItemData item) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 if (item != null) { return (int)item.m_shared.m_itemType == 2; } return false; } public static bool Allowed(ItemData item, Vector2i p) { //IL_0000: 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_004b: 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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) if (p.y < NormalRows) { return true; } if (item == null) { return true; } if (p.y == EquipRow) { if (p.x < 6) { return EquipIndex(item) == p.x; } if (p.x < 8) { return IsUtility(item); } return false; } if (p.y == QuickRow) { if (p.x < 3) { return IsAmmo(item); } if (p.x < 6) { return IsFood(item); } } return false; } public static void SetHeight(Inventory inv, int h) { if (InvHeight != null) { InvHeight.SetValue(inv, h); } } public static void Changed(Inventory inv) { try { InvChanged?.Invoke(inv, new object[2] { false, false }); } catch { } } public static bool TakeInput(Player p) { try { return TakeInputM == null || (bool)TakeInputM.Invoke(p, null); } catch { return true; } } public static Vector2i FindNormalEmpty(Inventory inv, bool topFirst) { //IL_0072: 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_001e: Unknown result type (might be due to invalid IL or missing references) int width = inv.GetWidth(); if (topFirst) { for (int i = 0; i < NormalRows; i++) { for (int j = 0; j < width; j++) { if (inv.GetItemAt(j, i) == null) { return new Vector2i(j, i); } } } } else { for (int num = NormalRows - 1; num >= 0; num--) { for (int k = 0; k < width; k++) { if (inv.GetItemAt(k, num) == null) { return new Vector2i(k, num); } } } } return new Vector2i(-1, -1); } public static int NormalEmptyCount(Inventory inv) { int num = 0; foreach (ItemData item in InvList.Invoke(inv)) { if (item.m_gridPos.y < NormalRows && item.m_gridPos.y >= 0 && item.m_gridPos.x >= 0 && item.m_gridPos.x < inv.GetWidth()) { num++; } } return Mathf.Max(0, inv.GetWidth() * NormalRows - num); } private static void Move(Inventory inv, ItemData item, Vector2i to) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) item.m_gridPos = to; Changed(inv); } private static bool MoveToNormal(Inventory inv, ItemData item) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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) Vector2i val = FindNormalEmpty(inv, topFirst: true); if (val.x < 0) { return false; } Move(inv, item, val); return true; } private static void MoveIntoEquipSlot(Inventory inv, ItemData item) { //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_0029: 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_0077: 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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) int num = EquipIndex(item); if (num < 0) { return; } Vector2i val = default(Vector2i); ((Vector2i)(ref val))..ctor(num, EquipRow); if (item.m_gridPos == val) { return; } ItemData itemAt = inv.GetItemAt(val.x, val.y); if (itemAt != null && itemAt != item) { if (!IsSpecial(item.m_gridPos) || Allowed(itemAt, item.m_gridPos)) { itemAt.m_gridPos = item.m_gridPos; } else if (!MoveToNormal(inv, itemAt)) { return; } } Move(inv, item, val); } public static void OnEquipped(Humanoid h, ItemData item) { if (Suppress) { return; } Player val = (Player)(object)((h is Player) ? h : null); if (val != null && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && Active && item != null && EquipIndex(item) >= 0 && ((Humanoid)val).IsItemEquiped(item)) { Inventory inventory = ((Humanoid)val).GetInventory(); if (inventory.ContainsItem(item)) { StuckUnequipped.Remove(item); MoveIntoEquipSlot(inventory, item); } } } public static void OnUnequipped(Humanoid h, ItemData item) { if (Suppress || InEquip) { return; } Player val = (Player)(object)((h is Player) ? h : null); if (val != null && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && Active && item != null && EquipIndex(item) >= 0 && !((Humanoid)val).IsItemEquiped(item)) { Inventory inventory = ((Humanoid)val).GetInventory(); if (inventory.ContainsItem(item) && item.m_gridPos.y == EquipRow && !MoveToNormal(inventory, item)) { StuckUnequipped.Add(item); ((Character)val).Message((MessageType)2, "$inventory_full", 0, (Sprite)null, false); } } } public static void Tick(float dt) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead()) { return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory == null) { return; } if (!Active) { if (Compat.OtherInventory) { return; } _timer -= dt; if (!(_timer > 0f)) { _timer = 2f; int height = inventory.GetHeight(); inventory.GetWidth(); if (RescueBeforeShrink(localPlayer, height) > 0) { Changed(inventory); } UpdateExtraUtilities(localPlayer); } } else { _timer -= dt; if (!(_timer > 0f)) { _timer = 0.4f; bool announce = (Object)(object)_migratedFor != (Object)(object)localPlayer; _migratedFor = localPlayer; Migrate(localPlayer, inventory, announce); Validate(localPlayer, inventory); UpdateExtraUtilities(localPlayer); } } } public static bool TryExtraUtility(Humanoid h, ItemData item) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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) if (!Suppress && Active) { Player val = (Player)(object)((h is Player) ? h : null); if (val != null && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && IsUtility(item)) { Inventory inventory = ((Humanoid)val).GetInventory(); if (!inventory.ContainsItem(item)) { return false; } Vector2i gridPos = item.m_gridPos; if (gridPos.y == EquipRow && gridPos.x >= 6) { if (!MoveToNormal(inventory, item)) { ((Character)val).Message((MessageType)2, "$inventory_full", 0, (Sprite)null, false); } UpdateExtraUtilities(val); return true; } if (gridPos.y == EquipRow && gridPos.x == EquipIndex(item)) { return false; } object? obj = EquipFieldInfos[4]?.GetValue(val); ItemData val2 = (ItemData)((obj is ItemData) ? obj : null); if (val2 == null || val2 == item) { return false; } Vector2i val3 = FreeIn(inventory, EquipRow, 6, 8); if (val3.x < 0) { return false; } Move(inventory, item, val3); UpdateExtraUtilities(val); return true; } } return false; } public static void UpdateExtraUtilities(Player p) { if ((Object)(object)p == (Object)null || (Object)(object)p != (Object)(object)Player.m_localPlayer) { return; } if ((Object)(object)_effectsFor != (Object)(object)p) { OurEffects.Clear(); _effectsFor = p; } if (!Active && OurEffects.Count == 0) { return; } SEMan sEMan = ((Character)p).GetSEMan(); if (sEMan == null) { return; } WantEffects.Clear(); if (Active && !((Character)p).IsDead()) { Inventory inventory = ((Humanoid)p).GetInventory(); for (int i = 6; i < 8; i++) { ItemData itemAt = inventory.GetItemAt(i, EquipRow); StatusEffect val = ((IsUtility(itemAt) && !Compat.LockedByProgression(itemAt)) ? itemAt.m_shared.m_equipStatusEffect : null); if ((Object)(object)val != (Object)null) { WantEffects[val.NameHash()] = new KeyValuePair<StatusEffect, int>(val, itemAt.m_quality); } } } Drop.Clear(); foreach (int ourEffect in OurEffects) { if (!WantEffects.ContainsKey(ourEffect)) { Drop.Add(ourEffect); } } foreach (int item in Drop) { OurEffects.Remove(item); if (!Worn(p, item)) { sEMan.RemoveStatusEffect(item, true); } } foreach (KeyValuePair<int, KeyValuePair<StatusEffect, int>> wantEffect in WantEffects) { OurEffects.Add(wantEffect.Key); if (!sEMan.HaveStatusEffect(wantEffect.Key)) { sEMan.AddStatusEffect(wantEffect.Value.Key, false, wantEffect.Value.Value, 0f, (short)0); } } } private static bool Worn(Player p, int hash) { HashSet<StatusEffect> hashSet = WornEffects.Invoke((Humanoid)(object)p); if (hashSet != null) { foreach (StatusEffect item in hashSet) { if ((Object)(object)item != (Object)null && item.NameHash() == hash) { return true; } } } return false; } private static List<ItemData> Copy(Inventory inv) { Snapshot.Clear(); Snapshot.AddRange(InvList.Invoke(inv)); return Snapshot; } private static void Migrate(Player p, Inventory inv, bool announce) { //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_0025: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) int num = 0; int num2 = 0; Vector2i val = default(Vector2i); foreach (ItemData item in Copy(inv)) { Vector2i gridPos = item.m_gridPos; if (gridPos.x < 0 || gridPos.x >= inv.GetWidth() || gridPos.y < 0 || gridPos.y >= NormalRows + 2 || !Allowed(item, gridPos) || (IsSpecial(gridPos) && SlotTakenByOther(inv, item))) { ((Vector2i)(ref val))..ctor(-1, -1); int num3 = EquipIndex(item); if (num3 >= 0 && item.m_equipped && inv.GetItemAt(num3, EquipRow) == null) { ((Vector2i)(ref val))..ctor(num3, EquipRow); } else if (IsAmmo(item)) { val = FreeIn(inv, QuickRow, 0, 3); } else if (IsFood(item)) { val = FreeIn(inv, QuickRow, 3, 6); } if (val.x < 0) { val = FindNormalEmpty(inv, topFirst: true); } if (val.x >= 0) { item.m_gridPos = val; num++; } else { num2++; } } } if (num > 0) { Changed(inv); } if (num > 0 || (num2 > 0 && announce)) { Plugin.Log.LogInfo((object)$"Slots extras: {num} item(ns) reorganizado(s), {num2} sem espaço (continuam guardados)."); } if (num2 > 0 && announce) { ((Character)p).Message((MessageType)2, Lang.T("msg.slots_stored", "Inventory full: some items from old slots are stored. Free up space."), 0, (Sprite)null, false); } } private static bool SlotTakenByOther(Inventory inv, ItemData it) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) foreach (ItemData item in InvList.Invoke(inv)) { if (item != it && item.m_gridPos == it.m_gridPos) { return true; } } return false; } private static Vector2i FreeIn(Inventory inv, int row, int x0, int x1) { //IL_0020: 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) for (int i = x0; i < x1; i++) { if (inv.GetItemAt(i, row) == null) { return new Vector2i(i, row); } } return new Vector2i(-1, -1); } public static void ApplyInventorySize(Player p, int rows) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_00cb: 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_00d7: 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) rows = Mathf.Clamp(rows, 0, 9); Inventory inventory = ((Humanoid)p).GetInventory(); if ((Object)(object)p == (Object)(object)Player.m_localPlayer || (Object)(object)Player.m_localPlayer == (Object)null) { NormalRows = rows; } SetHeight(inventory, rows + 2); p.AddUniqueKeyValue("invrows", rows.ToString()); if ((Object)(object)InventoryGui.instance != (Object)null) { InventoryGui.instance.SetInventorySize(rows); } int num = 0; ItemData[] array = InvList.Invoke(inventory).ToArray(); foreach (ItemData val in array) { Vector2i gridPos = val.m_gridPos; if (gridPos.x < 0 || gridPos.y < 0 || gridPos.x >= inventory.GetWidth() || gridPos.y >= inventory.GetHeight()) { Vector2i val2 = FindNormalEmpty(inventory, topFirst: true); if (val2.x >= 0) { val.m_gridPos = val2; num++; } } } if (num > 0) { Changed(inventory); } Plugin.Log.LogInfo((object)$"[Slots] inventário: {rows} linhas normais + {2} extras ({num} item(ns) reposicionado(s), nada foi largado no chão)."); } public static int RescueBeforeShrink(Player p, int rows) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) int num = 0; try { Inventory inventory = ((Humanoid)p).GetInventory(); int num2 = Mathf.Clamp(rows, 0, 9); int width = inventory.GetWidth(); ItemData[] array = InvList.Invoke(inventory).ToArray(); foreach (ItemData val in array) { if (val.m_gridPos.y < num2 && val.m_gridPos.y >= 0 && val.m_gridPos.x >= 0 && val.m_gridPos.x < width) { continue; } bool flag = false; for (int j = 0; j < num2; j++) { if (flag) { break; } for (int k = 0; k < width; k++) { if (flag) { break; } if (inventory.GetItemAt(k, j) == null) { val.m_gridPos = new Vector2i(k, j); flag = true; num++; } } } } if (num > 0) { Plugin.Log.LogInfo((object)$"[Slots] {num} item(ns) das linhas extras voltaram pro inventário normal."); } } catch (Exception ex) { Plugin.Log.LogError((object)("[Slots] RescueBeforeShrink: " + ex)); } return num; } public static void MarkWornForDeath(Player p) { if (!Active || (Object)(object)p == (Object)null || (Object)(object)p != (Object)(object)Player.m_localPlayer) { return; } for (int i = 0; i < EquipFieldInfos.Length; i++) { object? obj = EquipFieldInfos[i]?.GetValue(p); ItemData val = (ItemData)((obj is ItemData) ? obj : null); if (val != null) { if (val.m_customData == null) { val.m_customData = new Dictionary<string, string>(); } val.m_customData["ValheimHUD_vestir"] = "1"; } } } private static void Validate(Player p, Inventory inv) { //IL_0062: 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) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) foreach (ItemData item in Copy(inv)) { if (item.m_customData != null && item.m_customData.ContainsKey("ValheimHUD_vestir")) { item.m_customData.Remove("ValheimHUD_vestir"); int num = EquipIndex(item); if (num >= 0 && item.m_gridPos != new Vector2i(num, EquipRow) && inv.GetItemAt(num, EquipRow) == null) { Move(inv, item, new Vector2i(num, EquipRow)); } } } for (int i = 0; i < EquipFieldInfos.Length; i++) { if (!(EquipFieldInfos[i] == null)) { object? value = EquipFieldInfos[i].GetValue(p); ItemData val = (ItemData)((value is ItemData) ? value : null); if (val != null && !inv.ContainsItem(val)) { ((Humanoid)p).UnequipItem(val, false); } } } for (int j = 0; j < 6; j++) { ItemData itemAt = inv.GetItemAt(j, EquipRow); ItemData val2 = (ItemData)((EquipFieldInfos[j] != null) ? /*isinst with value type is only supported in some contexts*/: null); if (itemAt != null && EquipIndex(itemAt) != j) { MoveToNormal(inv, itemAt); } else if (val2 != null && inv.ContainsItem(val2) && val2.m_gridPos != new Vector2i(j, EquipRow)) { MoveIntoEquipSlot(inv, val2); } else if (itemAt != null && !((Humanoid)p).IsItemEquiped(itemAt) && !StuckUnequipped.Contains(itemAt)) { ((Humanoid)p).EquipItem(itemAt, false); } } StuckUnequipped.RemoveWhere((ItemData it) => it == null || !inv.ContainsItem(it) || it.m_gridPos.y != EquipRow); for (int num2 = 0; num2 < inv.GetWidth(); num2++) { ItemData itemAt2 = inv.GetItemAt(num2, QuickRow); if (itemAt2 != null && !Allowed(itemAt2, itemAt2.m_gridPos)) { MoveToNormal(inv, itemAt2); } ItemData itemAt3 = inv.GetItemAt(num2, EquipRow); if (num2 >= 6 && itemAt3 != null && !Allowed(itemAt3, itemAt3.m_gridPos)) { MoveToNormal(inv, itemAt3); } } } public static void UpdateInput() { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) if (!Active) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || !TakeInput(localPlayer) || ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || TextInput.IsVisible() || Menu.IsVisible() || Minimap.IsOpen()) { return; } for (int i = 0; i < 3; i++) { KeyboardShortcut value = ((ConfigEntry<KeyboardShortcut>)(i switch { 1 => Plugin.QuickFood2, 0 => Plugin.QuickFood1, _ => Plugin.QuickFood3, })).Value; if (((KeyboardShortcut)(ref value)).IsDown()) { Inventory inventory = ((Humanoid)localPlayer).GetInventory(); ItemData itemAt = inventory.GetItemAt(3 + i, QuickRow); if (itemAt != null) { ((Humanoid)localPlayer).UseItem(inventory, itemAt, false); } } } } public static void Reevaluate() { bool flag = ServerRules.SlotsAllowed && !Compat.OtherInventory; Player localPlayer = Player.m_localPlayer; if (flag == Active) { return; } if ((Object)(object)localPlayer == (Object)null) { Active = flag; return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (flag) { NormalRows = inventory.GetHeight(); Active = true; SetHeight(inventory, NormalRows + 2); } else { int num = RescueBeforeShrink(localPlayer, NormalRows); Active = false; SetHeight(inventory, NormalRows); if (num > 0) { ((Character)localPlayer).Message((MessageType)2, Lang.T("msg.slots_off", "The server disabled the extra slots: items went back to your bag."), 0, (Sprite)null, false); } } Changed(inventory); } public static string KeyLabel(int i) { //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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = ((ConfigEntry<KeyboardShortcut>)(i switch { 1 => Plugin.QuickFood2, 0 => Plugin.QuickFood1, _ => Plugin.QuickFood3, })).Value; string text = ((object)((KeyboardShortcut)(ref value)).MainKey/*cast due to .constrained prefix*/).ToString(); if (!text.StartsWith("Alpha")) { return text; } return text.Substring(5); } private static void LogOnce(string key, string msg) { if (_logged.Add(key)) { Plugin.Log.LogInfo((object)("[Slots] " + msg)); } } public static void LayoutGrid(InventoryGrid grid) { //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Expected O, but got Unknown //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_039e: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_0486: Unknown result type (might be due to invalid IL or missing references) //IL_048b: Unknown result type (might be due to invalid IL or missing references) //IL_048f: Unknown result type (might be due to invalid IL or missing references) //IL_0494: Unknown result type (might be due to invalid IL or missing references) //IL_049a: Unknown result type (might be due to invalid IL or missing references) //IL_04a3: Unknown result type (might be due to invalid IL or missing references) //IL_04b1: Unknown result type (might be due to invalid IL or missing references) //IL_04bf: Unknown result type (might be due to invalid IL or missing references) //IL_04cd: Unknown result type (might be due to invalid IL or missing references) if (!Active || (Object)(object)grid == (Object)null) { return; } Inventory inventory = grid.GetInventory(); if (!IsPlayerInv(inventory) || (Object)(object)InventoryGui.instance == (Object)null) { return; } if (!(ElementsF?.GetValue(grid) is IList list)) { LogOnce("noel", "InventoryGrid.m_elements não encontrado."); return; } if (list.Count < inventory.GetWidth() * (NormalRows + 2)) { LogOnce("count" + list.Count, $"grade com {list.Count} slots (esperado {inventory.GetWidth() * (NormalRows + 2)}), altura do inventário = {inventory.GetHeight()}."); return; } float num = ((ElementSpaceF != null) ? ((float)ElementSpaceF.GetValue(grid)) : 70f); EnsurePanel(grid, num); object? obj = GridRootF?.GetValue(grid); RectTransform val = (RectTransform)((obj is RectTransform) ? obj : null); if ((Object)(object)val != (Object)null) { val.SetSizeWithCurrentAnchors((Axis)1, (float)NormalRows * num); } if (_panelVanilla != Look.Vanilla) { _panelVanilla = Look.Vanilla; Look.Set(_panelBg, "ui_panel", InventorySkin.PanelBorder); } bool active = InventoryScreen.Active; if (((Component)_panel).gameObject.activeSelf == active) { ((Component)_panel).gameObject.SetActive(!active); } RectTransform val2 = (((Object)(object)_playerPanel != (Object)null) ? _playerPanel : val); if ((Object)(object)val2 != (Object)null && !active) { val2.GetWorldCorners(Corners); float x = ((Transform)_panel).lossyScale.x; ((Transform)_panel).position = new Vector3(Corners[2].x + 74f * x, Corners[2].y + 8f * x, ((Transform)_panel).position.z); } int width = inventory.GetWidth(); Vector2 val6 = default(Vector2); for (int i = 0; i < list.Count; i++) { int num2 = i % width; int num3 = i / width; if (num3 < NormalRows) { continue; } object? obj2 = list[i]; Component val3 = (Component)((obj2 is Component) ? obj2 : null); if ((Object)(object)val3 == (Object)null) { continue; } RectTransform val4 = (RectTransform)val3.transform; bool flag = ((num3 == EquipRow) ? (num2 < 8) : (num2 < 6)); if (val3.gameObject.activeSelf != flag) { val3.gameObject.SetActive(flag); } if (!flag) { continue; } RectTransform val5 = InventoryScreen.SlotAnchor(num2, num3 == EquipRow); Rect rect; if ((Object)(object)val5 != (Object)null) { if ((Object)(object)((Transform)val4).parent != (Object)(object)val5) { ((Transform)val4).SetParent((Transform)(object)val5, false); ((Vector2)(ref val6))..ctor(0.5f, 0.5f); val4.anchorMax = val6; val4.anchorMin = val6; if (!Silhouettes.ContainsKey(val3.gameObject)) { AddDecor(val3.gameObject, num2, num3); } } rect = val4.rect; Vector2 size = ((Rect)(ref rect)).size; float num4; if (!(size.x > 0f)) { num4 = 1f; } else { rect = val5.rect; num4 = ((Rect)(ref rect)).width / size.x; } float num5 = num4; ((Transform)val4).localScale = new Vector3(num5, num5, 1f); val4.anchoredPosition = new Vector2((val4.pivot.x - 0.5f) * size.x * num5, (val4.pivot.y - 0.5f) * size.y * num5); UpdateSilhouette(val3.gameObject, inventory, num2, num3); continue; } if ((Object)(object)((Transform)val4).parent != (Object)(object)_panel) { ((Transform)val4).SetParent((Transform)(object)_panel, false); ((Vector2)(ref val6))..ctor(0f, 1f); val4.anchorMax = val6; val4.anchorMin = val6; ((Transform)val4).localScale = Vector3.one; if (!Silhouettes.ContainsKey(val3.gameObject)) { AddDecor(val3.gameObject, num2, num3); } } int num6 = num2 % 3; int num7 = ((num3 == EquipRow) ? (num2 / 3) : (3 + num2 / 3)); float num8 = 14f + (float)num6 * num; float num9 = 14f + (float)num7 * num + ((num7 >= 3) ? 10f : 0f); rect = val4.rect; Vector2 size2 = ((Rect)(ref rect)).size; val4.anchoredPosition = new Vector2(num8 + size2.x * val4.pivot.x, 0f - (num9 + size2.y * (1f - val4.pivot.y))); UpdateSilhouette(val3.gameObject, inventory, num2, num3); } } private static void UpdateSilhouette(GameObject el, Inventory inv, int x, int y) { bool flag = inv.GetItemAt(x, y) == null; if (Silhouettes.TryGetValue(el, out var value) && (Object)(object)value != (Object)null && ((Behaviour)value).enabled != flag) { ((Behaviour)value).enabled = flag; } InventoryElement val = default(InventoryElement); if (!flag && y == EquipRow && x >= 6 && el.TryGetComponent<InventoryElement>(ref val) && (Object)(object)val.m_equiped != (Object)null && !((Behaviour)val.m_equiped).enabled) { ((Behaviour)val.m_equiped).enabled = true; } } private static void EnsurePanel(InventoryGrid grid, float space) { //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00fc: 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) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_panel != (Object)null) || !((Object)(object)_panelGrid == (Object)(object)grid)) { object? obj = PlayerPanelF?.GetValue(InventoryGui.instance); _playerPanel = (RectTransform)((obj is RectTransform) ? obj : null); object? obj2 = InvRootF?.GetValue(InventoryGui.instance); Transform val = (Transform)((obj2 is Transform) ? obj2 : null); if ((Object)(object)val == (Object)null) { val = (((Object)(object)_playerPanel != (Object)null && (Object)(object)((Transform)_playerPanel).parent != (Object)null) ? ((Transform)_playerPanel).parent : ((Component)grid).transform.parent); } GameObject val2 = new GameObject("ValheimHUD_SlotsExtras", new Type[1] { typeof(RectTransform) }) { layer = ((Component)val).gameObject.layer }; _panel = (RectTransform)val2.transform; ((Transform)_panel).SetParent(val, false); RectTransform panel = _panel; RectTransform panel2 = _panel; Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(0.5f, 0.5f); panel2.anchorMax = val3; panel.anchorMin = val3; _panel.pivot = new Vector2(0f, 1f); ((Transform)_panel).SetAsLastSibling(); _panel.sizeDelta = new Vector2(28f + 3f * space, 28f + 5f * space + 10f); _panelGrid = grid; Silhouettes.Clear(); _panelBg = val2.AddComponent<Image>(); ((Graphic)_panelBg).raycastTarget = false; _panelVanilla = !Look.Vanilla; Image obj3 = ((Component)UI.Rect("Separador", (Transform)(object)_panel, 14f, 14f + 3f * space + 5f - 1f, 3f * space, 2f)).gameObject.AddComponent<Image>(); ((Graphic)obj3).color = new Color(0.45f, 0.36f, 0.24f, 0.8f); ((Graphic)obj3).raycastTarget = false; } } private static void AddDecor(GameObject el, int x, int y) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) string kind = ((y == EquipRow) ? SilNames[x] : ((x < 3) ? "ammo" : "food")); RectTransform obj = UI.Rect("Silhueta", el.transform, 0f, 0f, 0f, 0f); obj.anchorMin = new Vector2(0.18f, 0.18f); obj.anchorMax = new Vector2(0.82f, 0.82f); Vector2 offsetMin = (obj.offsetMax = Vector2.zero); obj.offsetMin = offsetMin; ((Transform)obj).SetAsFirstSibling(); Image val = ((Component)obj).gameObject.AddComponent<Image>(); val.sprite = Tex.Silhouette(kind, out var _); ((Graphic)val).color = new Color(1f, 1f, 1f, 0.22f); ((Graphic)val).raycastTarget = false; val.preserveAspect = true; Silhouettes[el] = val; if (y == QuickRow && x >= 3) { UI.Text(el.transform, "Tecla", 4f, 2f, 30f, 20f, 16f, (TextAlignmentOptions)257, UI.GoldText).Set(KeyLabel(x - 3)); } } } [HarmonyPatch(typeof(Player), "Awake")] internal static class Slots_PlayerAwake { private static void Postfix(Player __instance) { ExtraSlots.Active = ServerRules.SlotsAllowed && !Compat.OtherInventory; if (ServerRules.SlotsAllowed && Compat.OtherInventory) { Plugin.Log.LogWarning((object)(Compat.OtherInventoryName + " detectado: os slots extras do ValheimHUD ficam desligados pra não conflitar.")); } if (ExtraSlots.Active) { ExtraSlots.SetHeight(((Humanoid)__instance).GetInventory(), ExtraSlots.NormalRows + 2); } } } [HarmonyPatch(typeof(Player), "SetInventorySize")] internal static class Slots_SetInventorySize { private static bool Prefix(Player __instance, int rows) { if (!ExtraSlots.Active) { if (!Compat.OtherInventory) { ExtraSlots.RescueBeforeShrink(__instance, rows); } return true; } try { ExtraSlots.ApplyInventorySize(__instance, rows); return false; } catch (Exception ex) { Plugin.Log.LogError((object)("[Slots] SetInventorySize: " + ex)); return true; } } } [HarmonyPatch(typeof(Inventory), "FindEmptySlot")] internal static class Slots_FindEmptySlot { private static bool Prefix(Inventory __instance, bool topFirst, ref Vector2i __result) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (!ExtraSlots.IsPlayerInv(__instance)) { return true; } __result = ExtraSlots.FindNormalEmpty(__instance, topFirst); return false; } } [HarmonyPatch(typeof(Inventory), "GetEmptySlots")] internal static class Slots_GetEmptySlots { private static bool Prefix(Inventory __instance, ref int __result) { if (!ExtraSlots.IsPlayerInv(__instance)) { return true; } __result = ExtraSlots.NormalEmptyCount(__instance); return false; } } [HarmonyPatch(typeof(Inventory), "HaveEmptySlot")] internal static class Slots_HaveEmptySlot { private static bool Prefix(Inventory __instance, ref bool __result) { if (!ExtraSlots.IsPlayerInv(__instance)) { return true; } __result = ExtraSlots.NormalEmptyCount(__instance) > 0; return false; } } [HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[] { typeof(ItemData), typeof(int) })] internal static class Slots_CanAddItem { private static void Postfix(Inventory __instance, ItemData item, int stack, ref bool __result) { if (!__result || !ExtraSlots.IsPlayerInv(__instance) || item == null) { return; } if (stack <= 0) { stack = item.m_stack; } int num = 0; foreach (ItemData allItem in __instance.GetAllItems()) { if (allItem.m_shared.m_name == item.m_shared.m_name && allItem.m_worldLevel == item.m_worldLevel && allItem.m_quality == item.m_quality) { num += Mathf.Max(0, allItem.m_shared.m_maxStackSize - allItem.m_stack); } } num += ExtraSlots.NormalEmptyCount(__instance) * item.m_shared.m_maxStackSize; __result = num >= stack; } } [HarmonyPatch(typeof(Inventory), "StackAll")] internal static class Slots_StackAll { private static readonly FieldRef<Inventory, List<ItemData>> List = AccessTools.FieldRefAccess<Inventory, List<ItemData>>("m_inventory"); private static void Prefix(Inventory fromInventory, out List<ItemData> __state) { __state = null; if (!ExtraSlots.IsPlayerInv(fromInventory)) { return; } List<ItemData> list = List.Invoke(fromInventory); __state = list.FindAll((ItemData it) => it.m_gridPos.y >= ExtraSlots.NormalRows); if (__state.Count > 0) { list.RemoveAll((ItemData it) => it.m_gridPos.y >= ExtraSlots.NormalRows); } } private static void Finalizer(Inventory fromInventory, List<ItemData> __state) { if (__state == null || __state.Count == 0 || fromInventory == null) { return; } List<ItemData> list = List.Invoke(fromInventory); foreach (ItemData item in __state) { if (!list.Contains(item)) { list.Add(item); } } ExtraSlots.Changed(fromInventory); } } [HarmonyPatch(typeof(Humanoid), "EquipItem")] [HarmonyPriority(200)] internal static class Slots_Equip { private static bool Prefix(Humanoid __instance, ItemData item, ref bool __result, bool __runOriginal) { if (!__runOriginal) { return false; } if (ExtraSlots.TryExtraUtility(__instance, item)) { __result = true; return false; } ExtraSlots.InEquip = true; return true; } private static void Finalizer() { ExtraSlots.InEquip = false; } private static void Postfix(Humanoid __instance, ItemData item, bool __result) { if (__result) { ExtraSlots.OnEquipped(__instance, item); } } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] internal static class Slots_Unequip { private static void Postfix(Humanoid __instance, ItemData item) { ExtraSlots.OnUnequipped(__instance, item); } } [HarmonyPatch(typeof(Humanoid), "UpdateEquipmentStatusEffects")] internal static class Slots_EquipEffects { private static void Postfix(Humanoid __instance) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val != null && (Object)(object)val == (Object)(object)Player.m_localPlayer) { ExtraSlots.UpdateExtraUtilities(val); } } } [HarmonyPatch(typeof(Humanoid), "UnequipAllItems")] internal static class Slots_UnequipAll { private static void Prefix() { ExtraSlots.Suppress = true; } private static void Finalizer() { ExtraSlots.Suppress = false; } } [HarmonyPatch(typeof(Player), "UnequipDeathDropItems")] internal static class Slots_DeathDrop { private static void Prefix(Player __instance) { ExtraSlots.MarkWornForDeath(__instance); ExtraSlots.Suppress = true; } private static void Finalizer() { ExtraSlots.Suppress = false; } } [HarmonyPatch(typeof(Player), "CreateTombStone")] internal static class Slots_TombStone { private static void Prefix(Player __instance) { ExtraSlots.MarkWornForDeath(__instance); } } [HarmonyPatch(typeof(InventoryGrid), "DropItem")] internal static class Slots_DropItem { private static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos, ref bool __result) { //IL_002e: 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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = __instance.GetInventory(); Inventory val = (ExtraSlots.IsPlayerInv(inventory) ? inventory : (ExtraSlots.IsPlayerInv(fromInventory) ? fromInventory : null)); if (val == null || item == null) { return true; } bool flag = false; if (inventory == val) { ItemData itemAt = inventory.GetItemAt(pos.x, pos.y); if (ExtraSlots.IsSpecial(pos)) { if (!ExtraSlots.Allowed(item, pos)) { flag = true; } else if (itemAt != null && itemAt != item && fromInventory != inventory) { flag = true; } } if (!flag && fromInventory == inventory && itemAt != null && itemAt != item && !ExtraSlots.Allowed(itemAt, item.m_gridPos)) { flag = true; } } else if (fromInventory == val && ExtraSlots.IsSpecial(item.m_gridPos)) { ItemData val2 = ((inventory != null) ? inventory.GetItemAt(pos.x, pos.y) : null); if (val2 != null && val2 != item && !ExtraSlots.Allowed(val2, item.m_gridPos)) { flag = true; } } if (flag) { __result = false; return false; } return true; } private static void Postfix(InventoryGrid __instance, Inventory fromInventory, ItemData item) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || item == null || !ExtraSlots.Active) { return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); int num = ExtraSlots.EquipIndex(item); if (num >= 0) { bool flag = inventory.ContainsItem(item) && item.m_gridPos.x == num && item.m_gridPos.y == ExtraSlots.EquipRow; if (flag && !((Humanoid)localPlayer).IsItemEquiped(item)) { ((Humanoid)localPlayer).EquipItem(item, true); } else if (!flag && ((Humanoid)localPlayer).IsItemEquiped(item)) { ((Humanoid)localPlayer).UnequipItem(item, true); } } } } [HarmonyPatch(typeof(InventoryGrid), "UpdateGui")] internal static class Slots_GridLayout { private static bool _logged; private static void Postfix(InventoryGrid __instance) { try { ExtraSlots.LayoutGrid(__instance); } catch (Exception ex) { if (!_logged) { _logged = true; Plugin.Log.LogError((object)("Slots extras (layout): " + ex)); } } } } internal static class InventoryScreen { private struct Moved { public Transform Parent; public int Sibling; public Vector2 AnchorMin; public Vector2 AnchorMax; public Vector2 Pivot; public Vector2 Pos; public Vector2 Size; public Vector3 Scale; } [HarmonyPatch(typeof(InventoryGrid), "UpdateGui")] private static class PovGrid_Patch { private static void Postfix(InventoryGrid __instance) { try { LayoutPovGrid(__instance); } catch (Exception ex) { if (!_povLogged) { Plugin.Log.LogError((object)("[Tela nova] Path of Valheiman: " + ex)); } _povLogged = true; } } } private const float CenterW = 540f; private const float MinH = 860f; private const float ColGap = 64f; private const float StackGap = 40f; private const float GridTop = 78f; private const float HotGap = 22f; private const float TopMargin = 28f; private const float EmblemSize = 88f; private const float EmblemOut = 30f; private static float _sw; private static float _sh; private const float OpenCloseSpeed = 3f; private const float EquipSize = 70f; private const float QuickSize = 64f; private static readonly Color Dim = new Color(0.66f, 0.61f, 0.54f, 1f); private static readonly FieldRef<InventoryGui, Animator> AnimatorF = AccessTools.FieldRefAccess<InventoryGui, Animator>("m_animator"); private static readonly FieldInfo ContainerGridF = AccessTools.Field(typeof(InventoryGui), "m_containerGrid"); private static readonly MethodInfo BlockerM = AccessTools.Method(typeof(Humanoid), "GetCurrentBlocker", (Type[])null, (Type[])null); private static readonly Dictionary<RectTransform, Moved> MovedOrig = new Dictionary<RectTransform, Moved>(); private static readonly Dictionary<RectTransform, Moved> Targets = new Dictionary<RectTransform, Moved>(); private static readonly Dictionary<Transform, Vector3> HiddenOrig = new Dictionary<Transform, Vector3>(); private static readonly Dictionary<InventoryGrid, RectTransform> TooltipOrig = new Dictionary<InventoryGrid, RectTransform>(); private static readonly Dictionary<RectTransform, RectTransform> Pinned = new Dictionary<RectTransform, RectTransform>(); private static InventoryGui _gui; private static bool _failed; private static bool _builtVanilla; private static bool _builtSlots; private static int _builtLang; private static float _statsTimer; private static RectTransform _screen; private static RectTransform _left; private static RectTransform _bag; private static RectTransform _chest; private static RectTransform _center; private static RectTransform _right; private static readonly RectTransform[] EquipAnchors = (RectTransform[])(object)new RectTransform[8]; private static readonly RectTransform[] QuickAnchors = (RectTransform[])(object)new RectTransform[6]; private static TextMeshProUGUI _name; private static TextMeshProUGUI _chestTitle; private static TextMeshProUGUI _chestWeight; private static TextMeshProUGUI _armor; private static TextMeshProUGUI _weight; private static Image _weightBar; private static float _weightBarW; private static TMP_FontAsset _font; private static readonly TextMeshProUGUI[] _statL = (TextMeshProUGUI[])(object)new TextMeshProUGUI[4]; private static readonly TextMeshProUGUI[] _statR = (TextMeshProUGUI[])(object)new TextMeshProUGUI[3]; private static RectTransform _hotRow; private static RectTransform _bagTray; private static readonly Dictionary<RectTransform, Vector2> Shifted = new Dictionary<RectTransform, Vector2>(); private static int _builtRows; private static Image _pvpIcon; private static Image _pvpFrame; private static TextMeshProUGUI _levelNum; private static Image _levelPts; private static Image _friendsDot; private static TextMeshProUGUI _levelPtsNum; private const float BadgeSize = 22f; private static readonly Vector3[] _wc = (Vector3[])(object)new Vector3[4]; private static readonly Vector3[] _corners = (Vector3[])(object)new Vector3[4]; private static GameObject _takeAllStandIn; private const float BtnSize = 58f; private const float PovQuick = 48f; private static bool _pov; private static readonly Dictionary<string, RectTransform> PovAnchors = new Dictionary<string, RectTransform>(); private static readonly Dictionary<string, Image> PovClosed = new Dictionary<string, Image>(); private static readonly Dictionary<string, string> PovSil = new Dictionary<string, string>(); private static readonly Dictionary<int, string> PovAt = new Dictionary<int, string>(); private static readonly HashSet<string> PovOpen = new HashSet<string>(); private static readonly Dictionary<RectTransform, Transform> PovMoved = new Dictionary<RectTransform, Transform>(); private static readonly Dictionary<GameObject, Image> PovDecor = new Dictionary<GameObject, Image>(); private static readonly List<string> PovExtras = new List<string>(); private static string _povExtrasSig = ""; private static float _povMapTimer; private static bool _povLogged; private static readonly FieldRef<InventoryGrid, int> GridWidthF = AccessTools.FieldRefAccess<InventoryGrid, int>("m_width"); private static readonly FieldRef<InventoryGrid, List<InventoryElement>> GridElementsF = AccessTools.FieldRefAccess<InventoryGrid, List<InventoryElement>>("m_elements"); public static bool Active { get; private set; } public static bool Failed => _failed; public static void Tick() { InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance != (Object)(object)_gui) { Forget(); _failed = false; } _gui = instance; if ((Object)(object)instance == (Object)null) { return; } bool num = Plugin.SkinInventory.Value && Plugin.NewScreen.Value && !Compat.OtherInventoryScreen; Animator val = AnimatorF.Invoke(instance); float num2 = (num ? 3f : 1f); if ((Object)(object)val != (Object)null && val.speed != num2) { val.speed = num2; } if (!num) { if (Active) { Restore(); } } else { if (!InventoryGui.IsVisible() || (Object)(object)Player.m_localPlayer == (Object)null || _failed) { return; } if (Active && (_builtVanilla != Look.Vanilla || _builtLang != Lang.Revision || _builtSlots != ExtraSlots.Active || _pov != PovCompat.Hosting)) { Restore(); } if (!Active) { if (PovCompat.CanHost && !PovCompat.Hosting) { return; } try { Build(instance); Active = true; _statsTimer = 0f; _builtVanilla = Look.Vanilla; _builtLang = Lang.Revision; _builtSlots = ExtraSlots.Active; } catch (Exception ex) { Plugin.Log.LogError((object)("[Tela nova] Falha montando a tela do inventário, voltando pro vanilla: " + ex)); Restore(); _failed = true; return; } } Refresh(instance); } } public static void LateTick() { //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) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: 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_0108: Unknown result type (might be due to invalid IL or missing references) if (!Active) { return; } foreach (KeyValuePair<Transform, Vector3> item in HiddenOrig) { if ((Object)(object)item.Key != (Object)null && item.Key.localScale != Vector3.zero) { item.Key.localScale = Vector3.zero; } } foreach (KeyValuePair<RectTransform, Moved> target in Targets) { RectTransform key = target.Key; if (!((Object)(object)key == (Object)null)) { if (key.anchoredPosition != target.Value.Pos) { key.anchoredPosition = target.Value.Pos; } if (key.sizeDelta != target.Value.Size) { key.sizeDelta = target.Value.Size; } if (((Transform)key).localScale != Vector3.one) { ((Transform)key).localScale = Vector3.one; } } } FollowPins(); } public static RectTransform SlotAnchor(int x, bool equipRow) { if (!Active || x < 0) { return null; } if (equipRow) { if (x >= EquipAnchors.Length) { return null; } return EquipAnchors[x]; } if (x >= QuickAnchors.Length) { return null; } return QuickAnchors[x]; } private static void Build(InventoryGui gui) { //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0142: 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_0164: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_0463: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Expected O, but got Unknown //IL_04cc: Unknown result type (might be due to invalid IL or missing references) //IL_04e6: Expected O, but got Unknown //IL_0571: Unknown result type (might be due to invalid IL or missing references) //IL_058e: Expected O, but got Unknown //IL_0517: Unknown result type (might be due to invalid IL or missing references) //IL_053d: Expected O, but got Unknown //IL_0604: Unknown result type (might be due to invalid IL or missing references) //IL_0676: Unknown result type (might be due to invalid IL or missing references) //IL_06a9: Unknown result type (might be due to invalid IL or missing references) //IL_05a7: Unknown result type (might be due to invalid IL or missing references) //IL_05cd: Expected O, but got Unknown //IL_074a: Unknown result type (might be due to invalid IL or missing references) //IL_077d: Unknown result type (might be due to invalid IL or missing references) //IL_07c6: Unknown result type (might be due to invalid IL or missing references) //IL_08bf: Unknown result type (might be due to invalid IL or missing references) //IL_090e: Unknown result type (might be due to invalid IL or missing references) //IL_0a47: Unknown result type (might be due to invalid IL or missing references) //IL_0961: Unknown result type (might be due to invalid IL or missing references) //IL_09b9: Unknown result type (might be due to invalid IL or missing references) //IL_0bdd: Unknown result type (might be due to invalid IL or missing references) //IL_0c15: Unknown result type (might be due to invalid IL or missing references) //IL_0c65: Unknown result type (might be due to invalid IL or missing references) //IL_0cf3: Unknown result type (might be due to invalid IL or missing references) //IL_0d43: Unknown result type (might be due to invalid IL or missing references) //IL_0f17: Unknown result type (might be due to invalid IL or missing references) //IL_0f1e: Unknown result type (might be due to invalid IL or missing references) //IL_0f75: Unknown result type (might be due to invalid IL or missing references) //IL_0f7c: Expected O, but got Unknown //IL_0fac: Unknown result type (might be due to invalid IL or missing references) //IL_0fb1: Unknown result type (might be due to invalid IL or missing references) //IL_0fb6: Unknown result type (might be due to invalid IL or missing references) //IL_0fc0: Unknown result type (might be due to invalid IL or missing references) //IL_0fc5: Unknown result type (might be due to invalid IL or missing references) //IL_0fca: Unknown result type (might be due to invalid IL or missing references) //IL_0fce: Unknown result type (might be due to invalid IL or missing references) //IL_0fd3: Unknown result type (might be due to invalid IL or missing references) //IL_0fd5: Unknown result type (might be due to invalid IL or missing references) //IL_0fed: Unknown result type (might be due to invalid IL or missing references) //IL_0ff7: Unknown result type (might be due to invalid IL or missing references) //IL_0ffe: Unknown result type (might be due to invalid IL or missing references) //IL_1008: Unknown result type (might be due to invalid IL or missing references) //IL_100f: Unknown result type (might be due to invalid IL or missing references) //IL_101b: Unknown result type (might be due to invalid IL or missing references) //IL_1020: Unknown result type (might be due to invalid IL or missing references) //IL_1024: Unknown result type (might be due to invalid IL or missing references) //IL_1029: Unknown result type (might be due to invalid IL or missing references) //IL_1033: Unknown result type (might be due to invalid IL or missing references) //IL_1046: Unknown result type (might be due to invalid IL or missing references) //IL_1055: Unknown result type (might be due to invalid IL or missing references) //IL_105c: Unknown result type (might be due to invalid IL or missing references) Transform inventoryRoot = gui.m_inventoryRoot; RectTransform val = (RectTransform)(object)((inventoryRoot is RectTransform) ? inventoryRoot : null); if ((Object)(object)val == (Object)null) { throw new Exception("m_inventoryRoot não é RectTransform"); } _font = (UI.Usable(UI.Font) ? UI.Font : (((Object)(object)gui.m_recipeDecription != (Object)null) ? gui.m_recipeDecription.font : null)); InventoryGrid playerGrid = gui.m_playerGrid; object? obj = ContainerGridF?.GetValue(gui); InventoryGrid val2 = (InventoryGrid)((obj is InventoryGrid) ? obj : null); float num = (((Object)(object)playerGrid != (Object)null) ? playerGrid.m_elementSpace : 64f); _pov = PovCompat.Hosting; _povExtrasSig = (_pov ? PovExtrasSignature(Player.m_localPlayer, PovExtras) : ""); if (!_pov) { PovExtras.Clear(); } int num2 = (_builtRows = BagRows(playerGrid)); float num3 = 8f * num; float num4 = 4f * num; float num5 = (float)num2 * num; float num6 = Mathf.Max(600f, num3 + 88f); float num7 = (num6 - num3) / 2f; float num8 = num6 + 64f; float num9 = num8 + 540f + 64f; ? val3; Rect rect; if (!((Object)(object)gui.m_crafting != (Object)null)) { val3 = new Vector2(517f, 589f); } else { rect = gui.m_crafting.rect; val3 = ((Rect)(ref rect)).size; } Vector2 val4 = (Vector2)val3; float num10 = 72f + val4.x + 9f + 4f; float num11 = PovExtrasHeight(num); float num12 = 78f + num5 + 22f + 58f + num11; float num13 = 78f + num4 + 78f; _sw = num9 + num10; _sh = Mathf.Max(new float[3] { 860f, num12 + 40f + num13, val4.y + 18f }); _screen = UI.Rect("ValheimHUD_TelaInventario", (Transform)(object)val, 0f, 0f, _sw, _sh); RectTransform screen = _screen; RectTransform screen2 = _screen; RectTransform screen3 = _screen; Vector2 val5 = default(Vector2); ((Vector2)(ref val5))..ctor(0.5f, 1f); screen3.pivot = val5; Vector2 anchorMin = (screen2.anchorMax = val5); screen.anchorMin = anchorMin; _screen.anchoredPosition = new Vector2(0f, -28f); int siblingIndex = (((Object)(object)gui.m_dropButton != (Object)null) ? (((Component)gui.m_dropButton).transform.GetSiblingIndex() + 1) : 0); ((Transform)_screen).SetSiblingIndex(siblingIndex); Fit(val); _left = UI.Rect("Esquerda", (Transform)(object)_screen, 0f, 0f, num6, _sh); _bag = Panel(_left, "Mochila", 0f, 0f, num6, num12, emblems: true); Title(_bag, Lang.T("screen.backpack", "BACKPACK"), num6); Image obj2 = Sliced(UI.Img("BarraRapida", (Transform)(object)_bag, null, num7, 78f, num3, num), "ui_inset", new Vector4(16f, 16f, 16f, 16f)); ((Graphic)obj2).color = new Color(1f, 0.86f, 0.62f, 1f); _hotRow = ((Graphic)obj2).rectTransform; _bagTray = null; if (num2 > 1) { _bagTray = ((Graphic)Sliced(UI.Img("BandejaMochila", (Transform)(object)_bag, null, num7, 78f + num + 22f, num3, num5 - num), "ui_inset", new Vector4(16f, 16f, 16f, 16f))).rectTransform; } if ((Object)(object)playerGrid != (Object)null) { Move((RectTransform)((Component)playerGrid).transform, _bag, num7, 78f, num3, num5 + 22f); Tooltip(playerGrid, _bag, num6 + 6f, 0f); } BuildPovExtras(_bag, num7, 78f + num5 + 22f + 10f, num); ((TMP_Text)Txt((Transform)(object)_bag, "Dica", 60f, 78f + num5 + 22f + 12f + num11, num6 - 120f, 24f, 15f, (TextAlignmentOptions)514, Dim)).text = Lang.T("screen.hint", "1–8: hotbar • drag the character to rotate"); _chest = Panel(_left, "Bau", 0f, num12 + 40f, num6, num13, emblems: true); _chestTitle = Tit