Decompiled source of MultiCraft for SeneaL UI v1.0.1

MultiCraftForSeneaLUI.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MultiCraft;
using SeneaLUI;
using SeneaLUI.Components;
using SeneaLUI.Core;
using SeneaLUI.Inv;
using SeneaLUI.Patches;
using SeneaLUI.Theme;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: IgnoresAccessChecksTo("MultiCraft")]
[assembly: IgnoresAccessChecksTo("SeneaL-UI")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MultiCraftForSeneaLUI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+1cdaa29e6767d3be2ba2e4c424c8d27ad80d9cd5")]
[assembly: AssemblyProduct("MultiCraftForSeneaLUI")]
[assembly: AssemblyTitle("MultiCraftForSeneaLUI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 MultiCraftForSeneaLUI
{
	[HarmonyPatch(typeof(CraftView))]
	internal static class AmountControl
	{
		private const float ButtonWidth = 38f;

		private const float LabelWidth = 44f;

		private const float Width = 120f;

		private const float RowHeight = 50f;

		private const float Gap = 14f;

		private const float DimmedAlpha = 0.35f;

		internal static CraftView View;

		private static RectTransform _root;

		private static TextMeshProUGUI _label;

		private static CanvasGroup _minus;

		private static CanvasGroup _plus;

		private static int _shownAmount = -1;

		internal static bool Visible;

		internal static bool InPadTick;

		private static void Build(CraftView view)
		{
			//IL_0079: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			View = view;
			_root = Ui.TL((Transform)(object)view._panel, "multicraft_amount", 0f, 0f, 120f, 50f);
			Tb val = new Tb((Transform)(object)_root, "minus", "minus", (Action)OnMinus, (Func<Tip>)(() => new Tip
			{
				Body = "Lower the craft amount: Shift+click by the bulk step, Ctrl+click back to 1."
			}), (Action)null);
			val.SetLabel((string)null);
			Ui.Place(val.Root, 0f, 0.5f, 0f, 0f, 38f, 36f);
			_minus = Ui.Group(val.Root);
			TextStyle segBtn = TextStyles.SegBtn;
			_label = Ui.Label((Transform)(object)_root, "amount", segBtn, 0f, 38f, (50f - segBtn.Size * 1.3f) * 0.5f + segBtn.Baseline(1.3f), 44f, (TextAlignmentOptions)258);
			((Graphic)_label).color = Palette.Parchment;
			Tb val2 = new Tb((Transform)(object)_root, "plus", "plus", (Action)OnPlus, (Func<Tip>)(() => new Tip
			{
				Body = "Raise the craft amount: Shift+click by the bulk step, Ctrl+click to the most you can craft."
			}), (Action)null);
			val2.SetLabel((string)null);
			Ui.Place(val2.Root, 0f, 0.5f, 82f, 0f, 38f, 36f);
			_plus = Ui.Group(val2.Root);
			((Component)_root).gameObject.SetActive(false);
			_shownAmount = -1;
			Visible = false;
		}

		private static bool ShouldShow(CraftView view, bool open)
		{
			if (open && view._shown && BatchCraft.SeneaLCraftingActive() && ((Component)view._button.Root).gameObject.activeSelf && view._tab && Object.op_Implicit((Object)(object)view._dRecipe) && view._dItem == null)
			{
				return !view._dGhost;
			}
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Tick")]
		private static void Refresh(CraftView __instance, bool open)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			if (View != __instance || !Object.op_Implicit((Object)(object)_root))
			{
				Build(__instance);
			}
			bool flag = ShouldShow(__instance, open);
			if (flag != Visible)
			{
				Visible = flag;
				((Component)_root).gameObject.SetActive(flag);
				if (!flag)
				{
					__instance._button.SetWidth(__instance._detailW);
				}
			}
			if (flag)
			{
				((Component)__instance._multiHost).gameObject.SetActive(false);
				float y = __instance._button.Root.anchoredPosition.y;
				__instance._button.SetWidth(__instance._detailW - 120f - 14f);
				_root.anchoredPosition = new Vector2(__instance._detailX + __instance._detailW - 120f, y);
				int amount = BatchCraft.Amount;
				if (amount != _shownAmount)
				{
					_shownAmount = amount;
					((TMP_Text)_label).text = amount.ToString();
				}
				bool flag2 = !BatchCraft.IsCrafting(__instance._gui);
				SetEnabled(_minus, flag2 && amount > 1);
				SetEnabled(_plus, flag2 && !MultiCraft_UI.instance.IsAtMaximumCraftable());
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("BuildDetail")]
		private static void HideShiftHint(CraftView __instance)
		{
			if (Visible)
			{
				((Component)__instance._multiHost).gameObject.SetActive(false);
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch("TickDetail")]
		private static IEnumerable<CodeInstruction> DetailShowsAmount(IEnumerable<CodeInstruction> instructions)
		{
			return BatchCraft.ReplaceGetButton(instructions, "MultiCraftRequested");
		}

		[HarmonyPrefix]
		[HarmonyPatch("PadTick")]
		private static void EnterPadTick()
		{
			InPadTick = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("PadTick")]
		private static void LeavePadTick()
		{
			InPadTick = false;
		}

		private static void OnMinus()
		{
			if (Input.GetKey((KeyCode)306))
			{
				MultiCraft_Logic.instance.SetCraftAmount(1);
			}
			else
			{
				MultiCraft_Logic.instance.AddToCraftAmount(Input.GetKey((KeyCode)304) ? (-MultiCraft_UI.BulkStep()) : (-1));
			}
		}

		private static void OnPlus()
		{
			CurrentRecipeInformation instance = CurrentRecipeInformation.instance;
			if (Input.GetKey((KeyCode)306))
			{
				MultiCraft_Logic.instance.SetCraftAmount(instance.HasRequirements ? instance.GetCurrentMaxCraftable() : 99);
			}
			else
			{
				MultiCraft_Logic.instance.AddToCraftAmount((!Input.GetKey((KeyCode)304)) ? 1 : MultiCraft_UI.BulkStep());
			}
		}

		private static void SetEnabled(CanvasGroup group, bool on)
		{
			group.alpha = (on ? 1f : 0.35f);
			group.interactable = on;
			group.blocksRaycasts = on;
		}
	}
	[HarmonyPatch(typeof(Pad), "Dir")]
	internal static class PadAmount
	{
		[HarmonyPrefix]
		private static bool DPadStepsAmount(ref Vector2Int __result)
		{
			//IL_0062: 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)
			if (!AmountControl.InPadTick || !AmountControl.Visible || !MultiCraftPlugin.EnableGamepadInput.Value || AmountControl.View == null || BatchCraft.IsCrafting(AmountControl.View._gui))
			{
				return true;
			}
			int num;
			if (Pad.DownRaw("JoyDPadLeft"))
			{
				num = -1;
			}
			else
			{
				if (!Pad.DownRaw("JoyDPadRight"))
				{
					return true;
				}
				num = 1;
			}
			MultiCraft_Logic.instance.AddToCraftAmount(num);
			__result = Vector2Int.zero;
			return false;
		}
	}
	[HarmonyPatch(typeof(InventoryGui))]
	internal static class BatchCraft
	{
		private static readonly MethodInfo GetButton = AccessTools.Method(typeof(ZInput), "GetButton", new Type[1] { typeof(string) }, (Type[])null);

		private static int _batchAmount = 1;

		internal static int Amount => MultiCraft_Logic.instance.CurrentCraftAmount;

		internal static bool IsCrafting(InventoryGui gui)
		{
			return gui.m_craftTimer >= 0f;
		}

		internal static bool SeneaLCraftingActive()
		{
			CraftView craft = InventoryGuiPatches.Craft;
			if (Plugin.Active && craft != null)
			{
				return craft._applied;
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("UpdateRecipe")]
		[HarmonyAfter(new string[] { "maximods.valheim.multicraft" })]
		private static void SetAmountBeforeUpdateRecipe(InventoryGui __instance)
		{
			if (SeneaLCraftingActive())
			{
				__instance.m_multiCraftAmount = (IsCrafting(__instance) ? _batchAmount : Amount);
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch("UpdateRecipe")]
		private static IEnumerable<CodeInstruction> UpdateRecipeIgnoresShift(IEnumerable<CodeInstruction> instructions)
		{
			return ReplaceGetButton(instructions, "ShiftHeldWhileIdle");
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateRecipe")]
		private static void RequireMaterialsForWholeBatch(InventoryGui __instance, Player player)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (SeneaLCraftingActive() && !IsCrafting(__instance) && Amount > 1 && ((Selectable)__instance.m_craftButton).interactable)
			{
				RecipeDataPair selectedRecipe = __instance.m_selectedRecipe;
				if (Object.op_Implicit((Object)(object)((RecipeDataPair)(ref selectedRecipe)).Recipe) && ((RecipeDataPair)(ref selectedRecipe)).ItemData == null && !player.NoCostCheat() && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)25) && !player.HaveRequirements(((RecipeDataPair)(ref selectedRecipe)).Recipe, false, 1, Amount))
				{
					((Selectable)__instance.m_craftButton).interactable = false;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnCraftPressed")]
		private static void LockBatchAmount(InventoryGui __instance)
		{
			if (SeneaLCraftingActive())
			{
				_batchAmount = Amount;
				__instance.m_multiCraftAmount = _batchAmount;
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch("OnCraftPressed")]
		private static IEnumerable<CodeInstruction> OnCraftPressedUsesAmount(IEnumerable<CodeInstruction> instructions)
		{
			return ReplaceGetButton(instructions, "MultiCraftRequested");
		}

		internal static IEnumerable<CodeInstruction> ReplaceGetButton(IEnumerable<CodeInstruction> instructions, string hook)
		{
			MethodInfo replacement = AccessTools.Method(typeof(BatchCraft), hook, (Type[])null, (Type[])null);
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, GetButton))
				{
					instruction.operand = replacement;
				}
				yield return instruction;
			}
		}

		private static bool IsMultiCraftButton(string name)
		{
			if (!(name == "AltPlace"))
			{
				return name == "JoyLStick";
			}
			return true;
		}

		internal static bool ShiftHeldWhileIdle(string name)
		{
			if (SeneaLCraftingActive() && IsMultiCraftButton(name))
			{
				return false;
			}
			return ZInput.GetButton(name);
		}

		internal static bool MultiCraftRequested(string name)
		{
			if (SeneaLCraftingActive() && IsMultiCraftButton(name))
			{
				if (name == "AltPlace")
				{
					return Amount > 1;
				}
				return false;
			}
			return ZInput.GetButton(name);
		}
	}
	[HarmonyPatch(typeof(HintBar))]
	internal static class HintBarCraftHint
	{
		private const float GapHint = 22f;

		[HarmonyPostfix]
		[HarmonyPatch("Build")]
		private static void HideKeyboardCraftHint(HintBar __instance)
		{
			HideCraftHint(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("BuildPadCraft")]
		private static void HidePadCraftHint(HintBar __instance)
		{
			HideCraftHint(__instance);
		}

		private static void HideCraftHint(HintBar bar)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_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)
			if (!BatchCraft.SeneaLCraftingActive())
			{
				return;
			}
			InventoryGui instance = InventoryGui.instance;
			string text = string.Format(Loc.HintCraft, Object.op_Implicit((Object)(object)instance) ? instance.m_multiCraftAmount : 5);
			float num = 0f;
			foreach (Item item in bar._items)
			{
				if (((Component)item.Root).gameObject.activeSelf)
				{
					if (num > 0f)
					{
						RectTransform root = item.Root;
						root.anchoredPosition -= new Vector2(num, 0f);
					}
					else if (((TMP_Text)item.Text).text == text)
					{
						num = item.Width + 22f;
						((Component)item.Root).gameObject.SetActive(false);
					}
				}
			}
			if (num > 0f)
			{
				RectTransform root2 = bar._root;
				root2.sizeDelta -= new Vector2(num, 0f);
			}
		}
	}
	[BepInPlugin("alkeari.valheim.multicraftforsenealui", "MultiCraft for SeneaL UI", "1.0.1")]
	[BepInProcess("valheim.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "alkeari.valheim.multicraftforsenealui";

		public const string Name = "MultiCraft for SeneaL UI";

		private const string MultiCraftGuid = "maximods.valheim.multicraft";

		private const string SeneaLUiGuid = "seneaL.valheim.ui";

		private Harmony _harmony;

		private void Awake()
		{
			_harmony = Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, "alkeari.valheim.multicraftforsenealui");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"MultiCraft for SeneaL UI 1.0.1 loaded");
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}
	}
	internal static class PluginVersion
	{
		public const string Value = "1.0.1";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}