Decompiled source of Hotbar Scroll v2.1.0

plugins/ScrollHotbar.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ScrollHotbar")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.1.0")]
[assembly: AssemblyProduct("ScrollHotbar")]
[assembly: AssemblyTitle("ScrollHotbar")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.0.0")]
[module: UnverifiableCode]
[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 ScrollHotbar
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("ScrollHotbar", "Hotbar Scroll by BenjSammy", "2.1.0")]
	public class Main : BaseUnityPlugin
	{
		internal static class HotbarSwitchCompat
		{
			private static bool resolved;

			private static MethodInfo hotbarYMethod;

			internal static int GetHotbarRow()
			{
				try
				{
					if (!resolved)
					{
						resolved = true;
						Resolve();
					}
					if (hotbarYMethod == null)
					{
						return 0;
					}
					if (hotbarYMethod.Invoke(null, null) is int num && num >= 0)
					{
						return num;
					}
				}
				catch
				{
				}
				return 0;
			}

			private static void Resolve()
			{
				try
				{
					Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
					foreach (Assembly assembly in assemblies)
					{
						Type type;
						try
						{
							type = assembly.GetType("HotbarSwitch.BepInExPlugin");
						}
						catch
						{
							continue;
						}
						if (!(type == null))
						{
							hotbarYMethod = type.GetMethod("HotbarY", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
							if (hotbarYMethod != null)
							{
								break;
							}
						}
					}
				}
				catch
				{
					hotbarYMethod = null;
				}
			}
		}

		[HarmonyPatch(typeof(ZInput), "GetMouseScrollWheel")]
		internal static class ZInputMouseScrollPatch
		{
			private static bool Prefix(ref float __result)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				Main instance = Instance;
				if ((Object)(object)instance == (Object)null)
				{
					return true;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					return true;
				}
				if (CameraZoomKey != null && Input.GetKey(CameraZoomKey.Value))
				{
					return true;
				}
				if (instance.UiIsBlocking())
				{
					return true;
				}
				__result = 0f;
				return false;
			}
		}

		private const int HotbarSlots = 8;

		internal static ConfigEntry<KeyCode> CameraZoomKey;

		internal static ConfigEntry<bool> InvertScroll;

		internal static ConfigEntry<string> IgnoredItems;

		private readonly Harmony harmony = new Harmony("ScrollHotbar");

		private ManualLogSource logger;

		private int currentIndex = -1;

		private int pendingIndex = -1;

		private float pendingTimer;

		private const float SelectionDelay = 0.05f;

		internal static Main Instance { get; private set; }

		internal static void LogWarning(string message)
		{
			Main instance = Instance;
			if (instance != null)
			{
				instance.logger.LogWarning((object)message);
			}
		}

		internal static void LogInfo(string message)
		{
			Main instance = Instance;
			if (instance != null)
			{
				instance.logger.LogInfo((object)message);
			}
		}

		private void Awake()
		{
			Instance = this;
			logger = ((BaseUnityPlugin)this).Logger;
			CameraZoomKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotbar Scroll Settings", "Camera Zoom Key", (KeyCode)306, "Hold this key to allow the mouse wheel to control camera zoom.");
			InvertScroll = ((BaseUnityPlugin)this).Config.Bind<bool>("Hotbar Scroll Settings", "Invert Scroll Direction", false, "If true, scrolling up selects lower hotbar slots and vice versa.");
			IgnoredItems = ((BaseUnityPlugin)this).Config.Bind<string>("Hotbar Scroll Settings", "Ignored Items", "$item_hammer, $item_cultivator, $item_hoe", "Comma-separated list of item names that will not scroll the hotbar when held. Example: $item_hammer, $item_cultivator, $item_hoe");
			harmony.PatchAll();
			logger.LogInfo((object)"Hotbar Scroll by BenjSammy 2.1.0 loaded");
		}

		private void Update()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			for (int i = 0; i < 8; i++)
			{
				if (Input.GetKeyDown((KeyCode)(49 + i)) || Input.GetKeyDown((KeyCode)(257 + i)))
				{
					currentIndex = i;
					pendingIndex = -1;
					pendingTimer = 0f;
					break;
				}
			}
			if (CameraZoomKey != null && Input.GetKey(CameraZoomKey.Value))
			{
				pendingIndex = -1;
				pendingTimer = 0f;
				return;
			}
			if (UiIsBlocking())
			{
				pendingIndex = -1;
				pendingTimer = 0f;
				return;
			}
			float axis = Input.GetAxis("Mouse ScrollWheel");
			if (!Mathf.Approximately(axis, 0f))
			{
				if (currentIndex < 0)
				{
					currentIndex = GetCurrentHotbarIndex(localPlayer);
				}
				int num = ((axis > 0f) ? 1 : (-1));
				if (InvertScroll.Value)
				{
					num = -num;
				}
				int num2 = ((pendingIndex >= 0) ? pendingIndex : currentIndex);
				pendingIndex = WrapIndex(num2 + num);
				pendingTimer = 0.05f;
			}
			if (pendingIndex >= 0)
			{
				pendingTimer -= Time.deltaTime;
				if (pendingTimer <= 0f)
				{
					int index = pendingIndex;
					pendingIndex = -1;
					currentIndex = index;
					SelectHotbarSlot(localPlayer, index);
				}
			}
		}

		private static int WrapIndex(int index)
		{
			int num = ((Instance.pendingIndex < 0) ? Instance.currentIndex : Instance.pendingIndex);
			int num2 = ((index > num) ? 1 : (-1));
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null && ((Humanoid)localPlayer).m_inventory != null)
			{
				int num3 = (index + 8) % 8;
				for (int i = 0; i < 8; i++)
				{
					ItemData itemAt = ((Humanoid)localPlayer).m_inventory.GetItemAt(num3, HotbarSwitchCompat.GetHotbarRow());
					if (itemAt == null || IsIgnoredItem(itemAt))
					{
						num3 = (num3 + num2 + 8) % 8;
						continue;
					}
					return num3;
				}
			}
			return -1;
		}

		private int GetCurrentHotbarIndex(Player player)
		{
			if (((Humanoid)player).m_inventory == null)
			{
				return 0;
			}
			ItemData rightItem = ((Humanoid)player).GetRightItem();
			if (rightItem == null)
			{
				return 0;
			}
			int hotbarRow = HotbarSwitchCompat.GetHotbarRow();
			for (int i = 0; i < 8; i++)
			{
				ItemData itemAt = ((Humanoid)player).m_inventory.GetItemAt(i, hotbarRow);
				if (itemAt == rightItem)
				{
					return i;
				}
			}
			return 0;
		}

		private void SelectHotbarSlot(Player player, int index)
		{
			if (((Humanoid)player).m_inventory != null && index >= 0 && index < 8)
			{
				ItemData itemAt = ((Humanoid)player).m_inventory.GetItemAt(index, HotbarSwitchCompat.GetHotbarRow());
				if (itemAt == null)
				{
					logger.LogInfo((object)$"Slot {index + 1} is empty");
					return;
				}
				((Humanoid)player).EquipItem(itemAt, true);
				logger.LogInfo((object)$"Equipped slot {index + 1} ({itemAt.m_shared.m_name})");
			}
		}

		internal bool UiIsBlocking()
		{
			try
			{
				if (Menu.IsVisible())
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)InventoryGui.instance != (Object)null && InventoryGui.IsVisible())
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				if (Minimap.IsOpen())
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer != (Object)null && IsIgnoredItem(((Humanoid)localPlayer).GetRightItem()))
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool IsIgnoredItem(ItemData item)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			if (item == null)
			{
				return false;
			}
			if ((int)item.m_shared.m_itemType == 19 || item.m_shared.m_buildPieces != null)
			{
				return true;
			}
			string name = item.m_shared.m_name;
			string text = IgnoredItems?.Value ?? "";
			string[] array = text.Split(new char[1] { ',' });
			foreach (string text2 in array)
			{
				if (text2.Trim() == name)
				{
					return true;
				}
			}
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}

plugins/HotbarScrollSettings.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HotbarScrollSettings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.1.0")]
[assembly: AssemblyProduct("HotbarScrollSettings")]
[assembly: AssemblyTitle("HotbarScrollSettings")]
[assembly: AssemblyVersion("2.1.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 BenjSammy.HotbarScroll
{
	[BepInPlugin("benjsammy.hotbarscroll.settings", "Hotbar Scroll Settings", "2.1.0")]
	[BepInDependency("ScrollHotbar", "2.1.0")]
	public sealed class Settings : BaseUnityPlugin
	{
		public enum Offhand
		{
			Aucun,
			Torche,
			Bouclier,
			TorcheNuitBouclierJour,
			OrdreHotbar
		}

		private const string Id = "benjsammy.hotbarscroll.settings";

		private static Settings instance;

		private readonly ConfigEntry<bool>[] excluded = new ConfigEntry<bool>[8];

		private ConfigEntry<Offhand> mode;

		private Func<ItemData, bool> ignored;

		private Func<int> row;

		private Harmony harmony;

		private BaseUnityPlugin original;

		private FieldInfo pendingIndex;

		private FieldInfo currentIndex;

		private bool equipping;

		private bool? previousDay;

		private Player observedPlayer;

		private float equipAfter;

		private bool offhandFailed;

		private static readonly MethodInfo RightHand = AccessTools.Method(typeof(Humanoid), "GetRightItem", Type.EmptyTypes, (Type[])null);

		private static readonly MethodInfo LeftHand = AccessTools.Method(typeof(Humanoid), "GetLeftItem", Type.EmptyTypes, (Type[])null);

		private static readonly MethodInfo InventoryFor = AccessTools.Method(typeof(Humanoid), "GetInventory", Type.EmptyTypes, (Type[])null);

		private static readonly MethodInfo Equip = AccessTools.Method(typeof(Humanoid), "EquipItem", new Type[2]
		{
			typeof(ItemData),
			typeof(bool)
		}, (Type[])null);

		private static readonly MethodInfo Unequip = AccessTools.Method(typeof(Humanoid), "UnequipItem", new Type[2]
		{
			typeof(ItemData),
			typeof(bool)
		}, (Type[])null);

		private void Awake()
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Expected O, but got Unknown
			original = Chainloader.PluginInfos["ScrollHotbar"].Instance;
			Type type = ((object)original).GetType();
			pendingIndex = AccessTools.Field(type, "pendingIndex");
			currentIndex = AccessTools.Field(type, "currentIndex");
			Type nestedType = type.GetNestedType("HotbarSwitchCompat", BindingFlags.Public | BindingFlags.NonPublic);
			ignored = (Func<ItemData, bool>)AccessTools.Method(type, "IsIgnoredItem", (Type[])null, (Type[])null).CreateDelegate(typeof(Func<ItemData, bool>));
			row = (Func<int>)AccessTools.Method(nestedType, "GetHotbarRow", (Type[])null, (Type[])null).CreateDelegate(typeof(Func<int>));
			for (int i = 0; i < excluded.Length; i++)
			{
				excluded[i] = original.Config.Bind<bool>("Cases ignorées", $"Case {i + 1}", false, "Coche pour sauter cette case à la molette. Le clavier et la main secondaire restent disponibles.");
			}
			mode = original.Config.Bind<Offhand>("Main secondaire", "Équipement automatique", Offhand.Aucun, "Cherche une torche ou un bouclier dans tout ton inventaire lorsque tu équipes une arme compatible à une main.");
			instance = this;
			harmony = new Harmony("benjsammy.hotbarscroll.settings");
			PatchPrefix(type, "WrapIndex", "FilterWheel");
			PatchPrefix(type, "SelectHotbarSlot", "ValidateSlot");
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Humanoid), "EquipItem", new Type[2]
			{
				typeof(ItemData),
				typeof(bool)
			}, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Settings), "AfterEquip", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private void PatchPrefix(Type target, string name, string prefix)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(target, name, (Type[])null, (Type[])null), new HarmonyMethod(typeof(Settings), prefix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			instance = null;
		}

		private bool CanScrollTo(int slot, ItemData item)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			//IL_0055: 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_0059: Invalid comparison between Unknown and I4
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Invalid comparison between Unknown and I4
			//IL_005b: 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_0060: Invalid comparison between Unknown and I4
			if (slot < 0 || slot >= excluded.Length || excluded[slot].Value || item?.m_shared == null || !item.IsEquipable() || ignored(item))
			{
				return false;
			}
			ItemType itemType = item.m_shared.m_itemType;
			if ((int)itemType <= 15)
			{
				if (itemType - 3 <= 2 || itemType - 14 <= 1)
				{
					goto IL_006e;
				}
			}
			else if ((int)itemType == 19 || (int)itemType == 22)
			{
				goto IL_006e;
			}
			return false;
			IL_006e:
			return true;
		}

		private static bool FilterWheel(int index, ref int __result)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			__result = -1;
			Settings settings = instance;
			Player localPlayer = Player.m_localPlayer;
			Inventory val = (((Object)(object)localPlayer == (Object)null) ? ((Inventory)null) : ((Inventory)InventoryFor.Invoke(localPlayer, null)));
			if ((Object)(object)settings == (Object)null || val == null)
			{
				return false;
			}
			int num = (int)settings.pendingIndex.GetValue(settings.original);
			int num2 = ((num >= 0) ? num : ((int)settings.currentIndex.GetValue(settings.original)));
			int num3 = ((index > num2) ? 1 : (-1));
			int num4 = settings.row();
			int num5 = (index + 8) % 8;
			for (int i = 0; i < 8; i++)
			{
				if (settings.CanScrollTo(num5, val.GetItemAt(num5, num4)))
				{
					__result = num5;
					break;
				}
				num5 = (num5 + num3 + 8) % 8;
			}
			return false;
		}

		private static bool ValidateSlot(Player player, int index)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			Settings settings = instance;
			if ((Object)(object)settings != (Object)null && index >= 0 && index < 8)
			{
				Inventory val = (Inventory)InventoryFor.Invoke(player, null);
				return settings.CanScrollTo(index, ((int)val != 0) ? val.GetItemAt(index, settings.row()) : null);
			}
			return false;
		}

		private static void AfterEquip(Humanoid __instance, ItemData item, bool __result)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Invalid comparison between Unknown and I4
			Settings settings = instance;
			if (__result && !((Object)(object)settings == (Object)null) && !settings.equipping && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Object)(object)__instance != (Object)(object)settings.observedPlayer) && !(Time.unscaledTime < settings.equipAfter) && item != null && (int)(item.m_shared?.m_itemType).GetValueOrDefault() == 3)
			{
				settings.TryOffhand(__instance, item);
			}
		}

		private void Update()
		{
			Player localPlayer = Player.m_localPlayer;
			if (observedPlayer != localPlayer)
			{
				observedPlayer = localPlayer;
				equipAfter = Time.unscaledTime + 1f;
				previousDay = null;
				return;
			}
			if ((Object)(object)localPlayer == (Object)null || offhandFailed || mode.Value != Offhand.TorcheNuitBouclierJour || (Object)(object)EnvMan.instance == (Object)null)
			{
				previousDay = null;
				return;
			}
			bool flag = EnvMan.IsDay();
			bool num = previousDay.HasValue && previousDay.Value != flag;
			previousDay = flag;
			if (num && Time.unscaledTime >= equipAfter)
			{
				TryOffhand((Humanoid)(object)localPlayer, null);
			}
		}

		private void TryOffhand(Humanoid player, ItemData equipped)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			if (offhandFailed || mode.Value == Offhand.Aucun)
			{
				return;
			}
			try
			{
				ItemData val = (ItemData)RightHand.Invoke(player, null);
				if (val != null && (int)(val.m_shared?.m_itemType).GetValueOrDefault() == 3 && (equipped == null || val == equipped))
				{
					EquipOffhand(player, val);
				}
			}
			catch (Exception ex)
			{
				offhandFailed = true;
				((BaseUnityPlugin)this).Logger.LogError((object)("Équipement automatique désactivé pour cette session : " + ex.GetBaseException()));
			}
		}

		private void EquipOffhand(Humanoid player, ItemData weapon)
		{
			//IL_003c: 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_0078: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_0065: 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)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Invalid comparison between Unknown and O
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Invalid comparison between Unknown and O
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Invalid comparison between Unknown and O
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Invalid comparison between Unknown and O
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Invalid comparison between Unknown and O
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			if (mode.Value == Offhand.Aucun || (Object)(object)weapon.m_shared.m_buildPieces != (Object)null || weapon.IsTwoHanded())
			{
				return;
			}
			ItemType preferred = (ItemType)((mode.Value == Offhand.Torche) ? 15 : 5);
			if (mode.Value == Offhand.TorcheNuitBouclierJour)
			{
				if ((Object)(object)EnvMan.instance == (Object)null)
				{
					return;
				}
				preferred = (ItemType)(EnvMan.IsDay() ? 5 : 15);
			}
			Inventory val = (Inventory)InventoryFor.Invoke(player, null);
			if (val == null)
			{
				return;
			}
			int num = row();
			ItemData val2 = FindOffhandInRow(val, num, Math.Min(8, val.GetWidth()), preferred);
			for (int i = 0; i < val.GetHeight(); i++)
			{
				if (val2 != null)
				{
					break;
				}
				int start = ((i == num) ? 8 : 0);
				val2 = FindOffhandInRow(val, i, val.GetWidth(), preferred, start);
			}
			ItemData val3 = (ItemData)LeftHand.Invoke(player, null);
			if (val2 == null || val3 == val2)
			{
				return;
			}
			equipping = true;
			try
			{
				if (val3 != null)
				{
					Unequip.Invoke(player, new object[2] { val3, false });
				}
				if (!(bool)Equip.Invoke(player, new object[2] { val2, false }) || (object)(ItemData)RightHand.Invoke(player, null) != weapon || (object)(ItemData)LeftHand.Invoke(player, null) != val2)
				{
					if ((object)(ItemData)RightHand.Invoke(player, null) == val2 || (object)(ItemData)LeftHand.Invoke(player, null) == val2)
					{
						Unequip.Invoke(player, new object[2] { val2, false });
					}
					if ((object)(ItemData)RightHand.Invoke(player, null) != weapon)
					{
						Equip.Invoke(player, new object[2] { weapon, false });
					}
					if (val3 != null && (int)(ItemData)LeftHand.Invoke(player, null) == 0)
					{
						Equip.Invoke(player, new object[2] { val3, false });
					}
				}
			}
			finally
			{
				equipping = false;
			}
		}

		private ItemData FindOffhandInRow(Inventory inventory, int y, int end, ItemType preferred, int start = 0)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Invalid comparison between Unknown and I4
			for (int i = start; i < end; i++)
			{
				ItemData itemAt = inventory.GetItemAt(i, y);
				if (itemAt?.m_shared == null || !itemAt.IsEquipable() || (itemAt.m_shared.m_useDurability && itemAt.m_durability <= 0f))
				{
					continue;
				}
				ItemType itemType = itemAt.m_shared.m_itemType;
				bool num;
				if (mode.Value != Offhand.OrdreHotbar)
				{
					num = itemType == preferred;
				}
				else
				{
					if ((int)itemType == 5)
					{
						goto IL_006d;
					}
					num = (int)itemType == 15;
				}
				if (!num)
				{
					continue;
				}
				goto IL_006d;
				IL_006d:
				return itemAt;
			}
			return null;
		}
	}
}