using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
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 TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AssemblyLine")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AssemblyLine")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("36a1739a-1b97-41dd-a553-cb6423df9a2a")]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace AssemblyLine
{
[BepInPlugin("bruce.valheim.comfy.assemblyline", "AssemblyLine", "1.1.1")]
public class AssemblyLine : BaseUnityPlugin
{
public const string PluginGuid = "bruce.valheim.comfy.assemblyline";
public const string PluginName = "AssemblyLine";
public const string PluginVersion = "1.1.1";
private static ManualLogSource _logger;
private Harmony _harmony;
public void Awake()
{
_logger = ((BaseUnityPlugin)this).Logger;
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "bruce.valheim.comfy.assemblyline");
}
public void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
public static void LogInfo(string message)
{
((Terminal)Chat.m_instance).AddString(message);
_logger.LogInfo((object)("[" + DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo) + "] " + message));
}
}
public class PluginConfig
{
public static ConfigEntry<bool> IsModEnabled;
public static ConfigEntry<bool> RoundToStackSize;
public static ConfigEntry<KeyboardShortcut> AmountChangeModifier { get; private set; }
public static ConfigEntry<KeyboardShortcut> MaxAmountChangeModifier { get; private set; }
public static void BindConfig(ConfigFile config)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
IsModEnabled = config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod.");
AmountChangeModifier = config.Bind<KeyboardShortcut>("Modifiers", "amountChangeModifier", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Keyboard shortcut to increment or decrement craft amount by 10.");
MaxAmountChangeModifier = config.Bind<KeyboardShortcut>("Modifiers", "maxAmountChangeModifier", new KeyboardShortcut((KeyCode)306, Array.Empty<KeyCode>()), "Keyboard shortcut to increment or decrement craft amount to maximum or minimum.");
RoundToStackSize = config.Bind<bool>("Toggles", "roundToStackSize", false, "Changes first increment with account change modifier from 1 to 11 to 1 to 10 so that even stacks may be made.");
}
}
}
namespace AssemblyLine.Patches
{
[HarmonyPatch(typeof(InventoryGui))]
public class InventoryGuiPatch
{
private static RectTransform _incrementButtonTransform;
private static RectTransform _decrementButtonTransform;
private static RectTransform _countText;
private static Button _craftButton;
private static Button _incrementButton;
private static Button _decrementButton;
private static int _maxCraftAmount = 1;
private static Dictionary<string, int> _requirementAmountByName = new Dictionary<string, int>();
private static Dictionary<string, int> _maxAmountByName = new Dictionary<string, int>();
private static Dictionary<string, Transform> _requirementTransformByName = new Dictionary<string, Transform>();
private static int _craftsRemaining = 0;
[HarmonyPostfix]
[HarmonyPatch("Show")]
public static void ShowPostfix(InventoryGui __instance, Container container)
{
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Expected O, but got Unknown
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Expected O, but got Unknown
if (!((Object)(object)_incrementButtonTransform != (Object)null) && !((Object)(object)_decrementButtonTransform != (Object)null) && !((Object)(object)_craftButton != (Object)null))
{
_craftButton = __instance.m_craftButton;
CreateCountText();
SetCraftAmountToMin();
ScaleCraftButton();
_incrementButtonTransform = CreateButton(__instance, "incrementButton", "+");
_decrementButtonTransform = CreateButton(__instance, "decrementButton", "-");
_incrementButton = ((Component)_incrementButtonTransform).GetComponent<Button>();
_decrementButton = ((Component)_decrementButtonTransform).GetComponent<Button>();
_incrementButtonTransform.pivot = new Vector2(1f, 0.75f);
_decrementButtonTransform.pivot = new Vector2(1f, 0f);
((UnityEvent)((Component)_incrementButtonTransform).GetComponent<Button>().onClick).AddListener(new UnityAction(OnIncrementPressed));
((UnityEvent)((Component)_decrementButtonTransform).GetComponent<Button>().onClick).AddListener(new UnityAction(OnDecrementPressed));
}
}
[HarmonyPostfix]
[HarmonyPatch("OnTabCraftPressed")]
public static void OnTabCraftPressed(InventoryGui __instance)
{
SetButtonInteractable(interactable: true);
}
[HarmonyPostfix]
[HarmonyPatch("OnTabUpgradePressed")]
public static void OnTabUpgradePressed(InventoryGui __instance)
{
SetButtonInteractable(interactable: false);
SetCraftAmountToMin();
}
[HarmonyPostfix]
[HarmonyPatch("OnCraftPressed")]
public static void OnCraftPressedPrefix(InventoryGui __instance)
{
_craftsRemaining = int.Parse(((Component)_countText).GetComponent<TMP_Text>().text) - 1;
}
[HarmonyPostfix]
[HarmonyPatch("OnCraftCancelPressed")]
public static void OnCraftCancelPressedPostfix(InventoryGui __instance)
{
_craftsRemaining = 0;
}
[HarmonyPostfix]
[HarmonyPatch("Hide")]
public static void HidePostfix(InventoryGui __instance)
{
_craftsRemaining = 0;
}
[HarmonyPostfix]
[HarmonyPatch("UpdateRecipe")]
public static void OnUpdateRecipePostfix(InventoryGui __instance, Player player, float dt)
{
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)Player.m_localPlayer != (Object)(object)player || ((Humanoid)Player.m_localPlayer).GetInventory() == null || (Object)(object)__instance.m_selectedRecipe.Key == (Object)null)
{
return;
}
if (__instance.InCraftTab() && (Object)(object)_incrementButton != (Object)null && (Object)(object)_decrementButton != (Object)null)
{
((Selectable)_incrementButton).interactable = true;
((Selectable)_decrementButton).interactable = true;
}
if (!((Humanoid)player).GetInventory().CanAddItem(__instance.m_selectedRecipe.Key.m_item.m_itemData, __instance.m_selectedRecipe.Key.m_amount))
{
DecrementCraftAmount(1);
_craftsRemaining = 0;
}
else if (__instance.m_craftTimer < 0f && _craftsRemaining > 0)
{
_craftsRemaining--;
__instance.m_craftTimer = 0f;
DecrementCraftAmount(1);
UpdateMaxAmount();
SetRequirementText();
if ((Object)(object)Player.m_localPlayer.GetCurrentCraftingStation() != (Object)null)
{
player.GetCurrentCraftingStation().m_craftItemEffects.Create(((Component)player).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
}
__instance.m_craftItemEffects.Create(((Component)player).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
__instance.m_craftRecipe = __instance.m_selectedRecipe.Key;
}
}
[HarmonyPostfix]
[HarmonyPatch("SetRecipe")]
public static void OnSetRecipePostfix(InventoryGui __instance, int index, bool center)
{
if (!IsCraftingMultiple())
{
_requirementAmountByName.Clear();
_maxAmountByName.Clear();
_requirementTransformByName.Clear();
SetMaxCraftAmount(__instance);
if (Object.op_Implicit((Object)(object)_countText))
{
SetCraftAmountToMin();
}
}
}
[HarmonyPostfix]
[HarmonyPatch("SetupRequirement")]
public static void SetupRequirementPostfix(InventoryGui __instance, Transform elementRoot, Requirement req, Player player, bool craft, int quality)
{
if (InventoryGui.IsVisible())
{
if (!_requirementAmountByName.Keys.Contains(req.m_resItem.m_itemData.m_shared.m_name))
{
_requirementAmountByName.Add(req.m_resItem.m_itemData.m_shared.m_name, req.GetAmount(quality));
_maxAmountByName.Add(req.m_resItem.m_itemData.m_shared.m_name, ((Humanoid)Player.m_localPlayer).GetInventory().CountItems(req.m_resItem.m_itemData.m_shared.m_name, -1, true));
_requirementTransformByName.Add(req.m_resItem.m_itemData.m_shared.m_name, elementRoot);
}
SetRequirementText();
}
}
public static RectTransform CreateButton(InventoryGui inventoryGui, string name, string text)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
Transform val = Object.Instantiate<Transform>(((Component)_craftButton).transform, ((Component)((Component)_craftButton).transform).transform.parent);
((Object)val).name = name;
Transform transform = ((Component)val).transform;
RectTransform val2 = (RectTransform)((Component)transform).transform;
val2.SetSizeWithCurrentAnchors((Axis)0, 40f);
val2.SetSizeWithCurrentAnchors((Axis)1, 30f);
RectTransform val3 = (RectTransform)((Component)val2).transform.Find("Text");
val3.SetSizeWithCurrentAnchors((Axis)0, 40f);
val3.SetSizeWithCurrentAnchors((Axis)1, 30f);
TMP_Text component = ((Component)val3).GetComponent<TMP_Text>();
component.text = text;
component.enableAutoSizing = true;
return val2;
}
public static void CreateCountText()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
RectTransform val = (RectTransform)((Component)((Component)_craftButton).transform).transform.Find("Text");
_countText = Object.Instantiate<RectTransform>(val, ((Component)((Transform)val).parent).transform.parent);
_countText.SetSizeWithCurrentAnchors((Axis)0, 50f);
_countText.SetSizeWithCurrentAnchors((Axis)0, 100f);
_countText.pivot = new Vector2(0.975f, 0f);
((Component)_countText).GetComponent<TMP_Text>().text = "1";
}
private static void ScaleCraftButton()
{
//IL_001a: 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)
((Component)_craftButton).transform.localScale = new Vector3(0.75f, 1f, 1f);
((RectTransform)((Component)_craftButton).transform).pivot = new Vector2(0f, 0f);
}
public static void SetRequirementText()
{
foreach (KeyValuePair<string, Transform> item in _requirementTransformByName)
{
_maxAmountByName[item.Key] = ((Humanoid)Player.m_localPlayer).GetInventory().CountItems(item.Key, -1, true);
((Component)((Component)item.Value).transform.Find("res_amount")).GetComponent<TMP_Text>().text = _requirementAmountByName[item.Key] * int.Parse(((Component)_countText).GetComponent<TMP_Text>().text) + "/" + _maxAmountByName[item.Key];
}
}
private static void OnIncrementPressed()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
SetMaxCraftAmount(InventoryGui.instance);
KeyboardShortcut value = PluginConfig.MaxAmountChangeModifier.Value;
if (((KeyboardShortcut)(ref value)).IsPressed())
{
SetCraftAmountToMax();
SetRequirementText();
return;
}
value = PluginConfig.AmountChangeModifier.Value;
if (((KeyboardShortcut)(ref value)).IsPressed())
{
if (!HaveCraftRequirements(10))
{
SetCraftAmountToMax();
}
IncrementCraftAmount(10);
SetRequirementText();
}
else
{
IncrementCraftAmount(1);
SetRequirementText();
}
}
private static void OnDecrementPressed()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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)
KeyboardShortcut value = PluginConfig.MaxAmountChangeModifier.Value;
if (((KeyboardShortcut)(ref value)).IsPressed())
{
SetCraftAmountToMin();
SetRequirementText();
return;
}
value = PluginConfig.AmountChangeModifier.Value;
if (((KeyboardShortcut)(ref value)).IsPressed())
{
DecrementCraftAmount(10);
SetRequirementText();
}
else
{
DecrementCraftAmount(1);
SetRequirementText();
}
}
private static void IncrementCraftAmount(int amount)
{
int num = int.Parse(((Component)_countText).GetComponent<TMP_Text>().text);
int newCount = num + amount;
if (PluginConfig.RoundToStackSize.Value && HaveCraftRequirements(10) && num == 1 && amount == 10)
{
((Component)_countText).GetComponent<TMP_Text>().text = 10.ToString();
}
else if (HaveCraftRequirements(newCount) && amount != -1)
{
((Component)_countText).GetComponent<TMP_Text>().text = newCount.ToString();
}
}
private static void DecrementCraftAmount(int amount)
{
int num = int.Parse(((Component)_countText).GetComponent<TMP_Text>().text);
int num2 = num - amount;
if (num2 < 1)
{
SetCraftAmountToMin();
}
else
{
((Component)_countText).GetComponent<TMP_Text>().text = num2.ToString();
}
}
private static void SetButtonInteractable(bool interactable)
{
if ((Object)(object)_incrementButton != (Object)null)
{
((Selectable)_incrementButton).interactable = interactable;
}
if ((Object)(object)_decrementButton != (Object)null)
{
((Selectable)_decrementButton).interactable = interactable;
}
}
private static void SetCraftAmountToMax()
{
((Component)_countText).GetComponent<TMP_Text>().text = _maxCraftAmount.ToString();
}
private static void SetCraftAmountToMin()
{
((Component)_countText).GetComponent<TMP_Text>().text = 1.ToString();
}
private static void SetMaxCraftAmount(InventoryGui inventoryGui)
{
_maxCraftAmount = GetMaxCraftAmount(inventoryGui);
}
private static bool IsCraftingMultiple()
{
if (_craftsRemaining > 0)
{
return true;
}
return false;
}
private static void UpdateMaxAmount()
{
foreach (KeyValuePair<string, int> item in _requirementAmountByName)
{
_maxAmountByName[item.Key] = _maxAmountByName[item.Key] - _requirementAmountByName[item.Key];
}
}
private static int GetMaxCraftAmount(InventoryGui inventoryGui)
{
if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)inventoryGui.m_selectedRecipe.Key == (Object)null)
{
return 1;
}
if (Player.m_localPlayer.NoCostCheat())
{
ZLog.Log((object)"No cost enabled. Setting max to 500.");
return 500;
}
List<int> list = new List<int>();
Requirement[] resources = inventoryGui.m_selectedRecipe.Key.m_resources;
foreach (Requirement val in resources)
{
if (Object.op_Implicit((Object)(object)val.m_resItem) && val.m_amount > 0)
{
int num = ((Humanoid)Player.m_localPlayer).GetInventory().CountItems(val.m_resItem.m_itemData.m_shared.m_name, -1, true);
int item = num / val.m_amount;
list.Add(item);
}
}
return (list.Min() == 0) ? 1 : list.Min();
}
private static bool HaveCraftRequirements(int newCount)
{
if (_maxCraftAmount >= newCount)
{
return true;
}
return false;
}
}
[HarmonyPatch(typeof(Inventory))]
internal class InventoryPatch
{
[HarmonyPostfix]
[HarmonyPatch("Changed")]
public static void OnInventoryChangedPostfix(Inventory __instance)
{
if (!((Object)(object)Player.m_localPlayer == (Object)null) && ((Humanoid)Player.m_localPlayer).GetInventory() == __instance && InventoryGui.IsVisible())
{
InventoryGuiPatch.SetRequirementText();
}
}
}
}