using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("GsiX.MultiCraft")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GsiX.MultiCraft")]
[assembly: AssemblyTitle("GsiX.MultiCraft")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MultiCraft;
internal class Multicraft
{
public enum Boxtype
{
none,
ship,
wood,
ironmeatl,
blackmetal,
personal,
yuleklapp,
drawer
}
public static string[] Boxname = new string[8] { "None", "Storage", "$piece_chestwood", "$piece_chest", "$piece_chestblackmetal", "$piece_chestprivate", "$piece_yuleklapp", "piece_chest_drawer" };
public static ManualLogSource DeLogger;
public static InventoryGui GUI;
public static InventoryGui GuiBuffer;
public static Inventory myInventory;
public static RectTransform BUTTON_CRAFT;
public static RectTransform BUTTON_PROGS;
public static RectTransform BUTTON_PLUS;
public static RectTransform BUTTON_MINUS;
public static RectTransform BUTTON_STOP;
public static RectTransform AMOUNT_TEXTMIN;
public static RectTransform AMOUNT_TEXTMAX;
public static RectTransform NOTE_JOYPAD;
public static RectTransform NOTE_NOCOST;
public static RectTransform NOTE_NOTE;
public static RectTransform BACKGROUND;
public static TMP_Text AMOUNT_TMPMin;
public static TMP_Text AMOUNT_TMPMax;
public static TMP_Text NOTE_TMPNoCost;
public static TMP_Text NOTE_TMPNote;
public static bool GamepadStats;
public static bool InProgress;
public static bool UIShown;
public static bool DeductAmount;
public static int CURRENTMAXIMUM = -1;
public static int CURRENTAMOUNT = 0;
public static float CraftingStart = Time.time;
public static float NoCostStart = Time.time;
public static float RangeToCount = -1f;
public static string RecipeNameCurrent = "";
public static string RecipeNameBuffers = "";
public const string NAME_PLUS = "multicraft_plus";
public const string NAME_MINUS = "multicraft_minus";
public const string NAME_STOP = "multicraft_stop";
public const string NAME_AMOUNTMIN = "multicraft_amt_min";
public const string NAME_AMOUNTMAX = "multicraft_amt_max";
public const string NAME_AMOUNTJOY = "multicraft_amt_joy";
public const string NAME_NOCOST = "multicraft_nocost";
public const string NAME_NOTE = "multicraft_note";
public const string NAME_BACKGROUND = "multicraft_bkg";
public const string colorOFF = "#404040";
public const string colorONS = "#00ff00";
public const float bkgNormY = -590f;
public const float bkgAugaY = -440f;
public const float width = 50f;
public const float height = 40f;
public const float posY = 0f;
public static MethodInfo InfoContainer_CheckAccess;
public static long BuffPlayerID;
public static bool IsRunning_General = false;
public static bool IsRunning_Aedenthorn = false;
public static bool IsRunning_Valheimplus = false;
public static bool Valheimplus_AllowCouldron = false;
public static bool Valheimplus_CheckWorkbench = false;
public static string CraftButtonPanel = "craft_button_panel";
public static string CraftButtonProgs = "Progress";
public static string CraftButtonTextName = "Text";
public static string ProjectAugaGUID = "randyknapp.mods.auga";
public static string AugaButtonPanel = "RightColumn";
public static string AugaButtonProgs = "CraftProgress";
public static string AugaButtonTextName = "Label";
public static bool IsRunning_ProjectAuga = false;
public static bool AllowContainersBuff_Ship;
public static bool AllowContainersBuff_Wagon;
public static bool AllowContainersBuff_Wood;
public static bool AllowContainersBuff_Reinforced;
public static bool AllowContainersBuff_BlackMetal;
public static bool AllowContainersBuff_Personal;
public static bool AllowContainersBuff_Yuleklapp;
public static bool AllowContainersBuff_Warded;
public static bool AllowContainersBuff_InUse;
public static bool AllowContainersBuff_ItemDrawer;
public static bool IsMultiCraftButtonReady()
{
return (Object)(object)GUI != (Object)null && (Object)(object)BACKGROUND != (Object)null && (Object)(object)BUTTON_CRAFT != (Object)null && (Object)(object)BUTTON_PROGS != (Object)null && (Object)(object)BUTTON_PLUS != (Object)null && (Object)(object)BUTTON_MINUS != (Object)null && (Object)(object)BUTTON_STOP != (Object)null && (Object)(object)AMOUNT_TEXTMIN != (Object)null && (Object)(object)AMOUNT_TEXTMAX != (Object)null && (Object)(object)NOTE_JOYPAD != (Object)null && (Object)(object)NOTE_NOCOST != (Object)null;
}
public static void SetVisible(GameObject button, bool setactive = true)
{
if (button != null)
{
button.SetActive(setactive);
}
}
public static void OnStopButtonPressed()
{
if (MultiCraftPlugin.PluginEnable.Value && (Object)(object)GUI != (Object)null)
{
((MonoBehaviour)GUI).Invoke("OnCraftCancelPressed", 0f);
}
}
public static void OnPlusButtonPressed()
{
AmountChanges(isPlus: true);
}
public static void OnMinusButtonPressed()
{
AmountChanges(isPlus: false);
}
public static void AmountChanges(bool isPlus)
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
if (!MultiCraftPlugin.PluginEnable.Value)
{
return;
}
int num = (isPlus ? 1 : (-1));
if (ZInput.IsGamepadActive())
{
if (ZInput.GetButton(MultiCraftPlugin.JYDeltaSmall.Value))
{
num *= 10;
}
else if (ZInput.GetButton(MultiCraftPlugin.JYDeltaMedium.Value))
{
num *= 100;
}
}
else
{
KeyboardShortcut value = MultiCraftPlugin.KBDeltaSmall.Value;
if (((KeyboardShortcut)(ref value)).IsPressed())
{
num *= 10;
}
else
{
value = MultiCraftPlugin.KBDeltaMedium.Value;
if (((KeyboardShortcut)(ref value)).IsPressed())
{
num *= 100;
}
}
}
CURRENTAMOUNT += num;
if (CURRENTAMOUNT <= 0)
{
if (CURRENTMAXIMUM > 0)
{
CURRENTAMOUNT = 1;
}
else
{
CURRENTAMOUNT = 0;
}
}
else if (CURRENTAMOUNT > CURRENTMAXIMUM)
{
if (!IsNoCraftCost() && MultiCraftPlugin.CapMaximumCraftable.Value)
{
CURRENTAMOUNT = CURRENTMAXIMUM;
}
if (CURRENTMAXIMUM > 0)
{
ShowCraftableText("#00ff00");
}
else
{
ShowCraftableText("#404040");
}
}
UpdateCraftingAmount();
SetCraftingCompleted("");
}
public static void ResetCurrentAmount()
{
CURRENTAMOUNT = 0;
UpdateCraftingAmount();
}
public static void UpdateCraftingAmount()
{
//IL_006b: 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_010c: 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)
if ((Object)(object)AMOUNT_TMPMin != (Object)null)
{
AMOUNT_TMPMin.text = $"{CURRENTAMOUNT}";
if (CURRENTAMOUNT <= 0 || !((Selectable)GUI.m_craftButton).IsInteractable())
{
((Graphic)AMOUNT_TMPMin).color = Color.grey;
}
else
{
((Graphic)AMOUNT_TMPMin).color = Color.green;
}
}
if ((Object)(object)AMOUNT_TMPMax != (Object)null)
{
if (CURRENTMAXIMUM <= 0)
{
AMOUNT_TMPMax.text = "0";
}
else
{
AMOUNT_TMPMax.text = $"{CURRENTMAXIMUM}";
}
if (CURRENTMAXIMUM <= 0 || !((Selectable)GUI.m_craftButton).IsInteractable())
{
((Graphic)AMOUNT_TMPMax).color = Color.grey;
}
else
{
((Graphic)AMOUNT_TMPMax).color = Color.magenta;
}
}
}
public static void ShowCraftableText(string coloritem)
{
if (GUI.InCraftTab() && MultiCraftPlugin.ShowMaxCraftable.Value)
{
string text = coloritem;
if (!((Selectable)GUI.m_craftButton).IsInteractable() && text != "#404040")
{
text = "#404040";
}
if (MultiCraftPlugin.CapMaximumCraftable.Value)
{
CenterMsg("<color=" + text + ">" + GUI.m_recipeName.text + "</color>\nMaximum Craftable" + $"\n<color={text}>{CURRENTMAXIMUM}</color>");
}
else
{
CenterMsg("<color=" + text + ">" + GUI.m_recipeName.text + "</color>\nUncapped Maximum Craftable" + $"\n<color={text}>{CURRENTMAXIMUM}</color>");
}
}
}
public static bool ConstructButton(InventoryGui inventoriGui)
{
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Expected O, but got Unknown
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Expected O, but got Unknown
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Expected O, but got Unknown
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Expected O, but got Unknown
//IL_029c: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Expected O, but got Unknown
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0351: Unknown result type (might be due to invalid IL or missing references)
//IL_0357: Expected O, but got Unknown
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Expected O, but got Unknown
//IL_038d: Unknown result type (might be due to invalid IL or missing references)
//IL_0393: Expected O, but got Unknown
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Expected O, but got Unknown
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
//IL_03fb: Expected O, but got Unknown
//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
//IL_03bb: Expected O, but got Unknown
//IL_0439: Unknown result type (might be due to invalid IL or missing references)
//IL_0443: Expected O, but got Unknown
//IL_0546: Unknown result type (might be due to invalid IL or missing references)
//IL_0550: Expected O, but got Unknown
//IL_0627: Unknown result type (might be due to invalid IL or missing references)
//IL_0631: Expected O, but got Unknown
//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
//IL_04e0: Expected O, but got Unknown
//IL_0708: Unknown result type (might be due to invalid IL or missing references)
//IL_0712: Expected O, but got Unknown
//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
//IL_05ea: Expected O, but got Unknown
//IL_0849: Unknown result type (might be due to invalid IL or missing references)
//IL_0853: Expected O, but got Unknown
//IL_069b: Unknown result type (might be due to invalid IL or missing references)
//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
//IL_06cb: Expected O, but got Unknown
//IL_098a: Unknown result type (might be due to invalid IL or missing references)
//IL_0994: Expected O, but got Unknown
//IL_075d: Unknown result type (might be due to invalid IL or missing references)
//IL_0767: Expected O, but got Unknown
//IL_0ac2: Unknown result type (might be due to invalid IL or missing references)
//IL_0acc: Expected O, but got Unknown
//IL_089e: Unknown result type (might be due to invalid IL or missing references)
//IL_08a8: Expected O, but got Unknown
//IL_07d2: Unknown result type (might be due to invalid IL or missing references)
//IL_0801: Unknown result type (might be due to invalid IL or missing references)
//IL_0c03: Unknown result type (might be due to invalid IL or missing references)
//IL_0c0d: Expected O, but got Unknown
//IL_09df: Unknown result type (might be due to invalid IL or missing references)
//IL_09e9: Expected O, but got Unknown
//IL_0913: Unknown result type (might be due to invalid IL or missing references)
//IL_0942: Unknown result type (might be due to invalid IL or missing references)
//IL_0b17: Unknown result type (might be due to invalid IL or missing references)
//IL_0b21: Expected O, but got Unknown
//IL_0a54: Unknown result type (might be due to invalid IL or missing references)
//IL_0a7a: Unknown result type (might be due to invalid IL or missing references)
//IL_0c58: Unknown result type (might be due to invalid IL or missing references)
//IL_0c62: Expected O, but got Unknown
//IL_0b8c: Unknown result type (might be due to invalid IL or missing references)
//IL_0bbb: Unknown result type (might be due to invalid IL or missing references)
//IL_0d8b: Unknown result type (might be due to invalid IL or missing references)
//IL_0daa: Unknown result type (might be due to invalid IL or missing references)
//IL_0dc9: Unknown result type (might be due to invalid IL or missing references)
//IL_0ccd: Unknown result type (might be due to invalid IL or missing references)
//IL_0cfc: Unknown result type (might be due to invalid IL or missing references)
GUI = inventoriGui;
if (IsRunning_ProjectAuga)
{
RectTransform val = (RectTransform)((Component)inventoriGui.m_craftButton).transform.parent.parent;
BACKGROUND = (RectTransform)((Component)val).transform.Find("multicraft_bkg");
if ((Object)(object)BACKGROUND == (Object)null)
{
RectTransform val2 = (RectTransform)((Component)inventoriGui.m_craftButton).transform.parent.parent.parent.parent;
if ((Object)(object)val2 == (Object)null)
{
DeLogger.LogMessage((object)"Auga dummyparent failed stage 1");
return false;
}
val2 = (RectTransform)((Component)val2).transform.Find("WorkbenchContent");
if ((Object)(object)val2 == (Object)null)
{
DeLogger.LogMessage((object)"Auga dummyparent failed stage 2");
return false;
}
RectTransform val3 = (RectTransform)((Component)val2).transform.Find("Background");
if ((Object)(object)val3 != (Object)null)
{
Transform val4 = (Transform)(object)Object.Instantiate<RectTransform>(val3, ((Component)val3).transform.parent);
((Object)val4).name = "multicraft_bkg";
((Component)val4).transform.SetAsFirstSibling();
BACKGROUND = (RectTransform)((Component)val4).transform;
((Transform)BACKGROUND).SetParent((Transform)(object)val);
BACKGROUND.SetSizeWithCurrentAnchors((Axis)0, 360f);
BACKGROUND.SetSizeWithCurrentAnchors((Axis)1, 60f);
((Transform)BACKGROUND).localPosition = new Vector3(90f, -440f, 0f);
((Component)BACKGROUND).gameObject.SetActive(false);
DeLogger.LogMessage((object)"Valheim Auga Success.");
}
}
}
else
{
RectTransform val2 = (RectTransform)((Component)inventoriGui.m_craftButton).transform.parent.parent;
if ((Object)(object)val2 == (Object)null)
{
DeLog("panel parent failed at Awake");
return false;
}
BACKGROUND = (RectTransform)((Component)val2).transform.Find("multicraft_bkg");
if ((Object)(object)BACKGROUND == (Object)null)
{
RectTransform val5 = (RectTransform)((Component)((Transform)val2).parent).transform.Find("Bkg");
if ((Object)(object)val5 != (Object)null)
{
Transform val6 = (Transform)(object)Object.Instantiate<RectTransform>(val5, ((Component)val5).transform.parent);
((Object)val6).name = "multicraft_bkg";
((Component)val6).transform.SetAsFirstSibling();
BACKGROUND = (RectTransform)((Component)val6).transform;
((Transform)BACKGROUND).SetParent((Transform)(object)val2);
BACKGROUND.SetSizeWithCurrentAnchors((Axis)0, 360f);
BACKGROUND.SetSizeWithCurrentAnchors((Axis)1, 60f);
((Transform)BACKGROUND).localPosition = new Vector3(-175f, -590f, 0f);
((Component)BACKGROUND).gameObject.SetActive(false);
DeLogger.LogMessage((object)"Valheim Vanilla Success.");
}
}
}
if ((Object)(object)BACKGROUND == (Object)null)
{
DeLogger.LogMessage((object)"Background was Failed.");
return false;
}
RectTransform val7 = (RectTransform)((Component)inventoriGui.m_craftButton).transform.parent;
if ((Object)(object)val7 == (Object)null)
{
DeLog("panel parent failed at Awake");
return false;
}
RectTransform val8 = (RectTransform)((Transform)val7).parent.Find(CraftButtonPanel);
if ((Object)(object)val8 != (Object)null)
{
BUTTON_PROGS = (RectTransform)((Component)val8).transform.Find(CraftButtonProgs);
if ((Object)(object)BUTTON_PROGS == (Object)null)
{
DeLogger.LogMessage((object)"button progress failed at Awake");
return false;
}
}
BUTTON_CRAFT = (RectTransform)((Component)inventoriGui.m_craftButton).transform;
if ((Object)(object)BUTTON_CRAFT == (Object)null)
{
DeLog("button craft failed at Awake");
return false;
}
BUTTON_STOP = (RectTransform)((Component)BACKGROUND).transform.Find("multicraft_stop");
if ((Object)(object)BUTTON_STOP == (Object)null)
{
BUTTON_STOP = CreateMultiCraftButton(inventoriGui, "multicraft_stop", "STOP", 100f, 40f);
if (!((Object)(object)BUTTON_STOP != (Object)null))
{
DeLogger.LogMessage((object)"Button Stop Failed.");
return false;
}
((Transform)BUTTON_STOP).SetParent((Transform)(object)BACKGROUND);
((Transform)BUTTON_STOP).localPosition = new Vector3(110f, 0f, 0f);
((UnityEvent)((Component)BUTTON_STOP).gameObject.GetComponent<Button>().onClick).AddListener(new UnityAction(OnStopButtonPressed));
TMP_Text component = ((Component)BUTTON_STOP).GetComponent<TMP_Text>();
if ((Object)(object)component != (Object)null)
{
component.fontSize = 5f;
}
ButtonDebug("Button Stop Created.");
}
BUTTON_PLUS = (RectTransform)((Component)BACKGROUND).transform.Find("multicraft_plus");
if ((Object)(object)BUTTON_PLUS == (Object)null)
{
BUTTON_PLUS = CreateMultiCraftButton(inventoriGui, "multicraft_plus", "+", 50f, 40f);
if (!((Object)(object)BUTTON_PLUS != (Object)null))
{
DeLogger.LogMessage((object)"Button Plus Failed.");
return false;
}
((Transform)BUTTON_PLUS).SetParent((Transform)(object)BACKGROUND);
((Transform)BUTTON_PLUS).localPosition = new Vector3(135f, 0f, 0f);
((UnityEvent)((Component)BUTTON_PLUS).gameObject.GetComponent<Button>().onClick).AddListener(new UnityAction(OnPlusButtonPressed));
ButtonDebug("Button Plus Created.");
}
BUTTON_MINUS = (RectTransform)((Component)BACKGROUND).transform.Find("multicraft_minus");
if ((Object)(object)BUTTON_MINUS == (Object)null)
{
BUTTON_MINUS = CreateMultiCraftButton(inventoriGui, "multicraft_minus", "-", 50f, 40f);
if (!((Object)(object)BUTTON_MINUS != (Object)null))
{
DeLogger.LogMessage((object)"Button Minus Failed.");
return false;
}
((Transform)BUTTON_MINUS).SetParent((Transform)(object)BACKGROUND);
((Transform)BUTTON_MINUS).localPosition = new Vector3(85f, 0f, 0f);
((UnityEvent)((Component)BUTTON_MINUS).gameObject.GetComponent<Button>().onClick).AddListener(new UnityAction(OnMinusButtonPressed));
ButtonDebug("Button Minus Created.");
}
AMOUNT_TEXTMIN = (RectTransform)((Component)BACKGROUND).transform.Find("multicraft_amt_min");
if ((Object)(object)AMOUNT_TEXTMIN == (Object)null)
{
Transform val9 = ((Component)inventoriGui.m_craftButton).transform.Find(CraftButtonTextName);
if ((Object)(object)val9 != (Object)null)
{
AMOUNT_TEXTMIN = (RectTransform)Object.Instantiate<Transform>(val9, ((Component)val7).transform);
if (!((Object)(object)AMOUNT_TEXTMIN != (Object)null))
{
DeLogger.LogMessage((object)"Amount Text Min Failed.");
return false;
}
((Object)AMOUNT_TEXTMIN).name = "multicraft_amt_min";
AMOUNT_TEXTMIN.SetSizeWithCurrentAnchors((Axis)0, 100f);
AMOUNT_TEXTMIN.SetSizeWithCurrentAnchors((Axis)1, 40f);
((Transform)AMOUNT_TEXTMIN).SetParent((Transform)(object)BACKGROUND);
((Transform)AMOUNT_TEXTMIN).localPosition = new Vector3(-100f, 0f, 0f);
AMOUNT_TMPMin = ((Component)AMOUNT_TEXTMIN).GetComponent<TMP_Text>();
AMOUNT_TMPMin.text = "1";
((Graphic)AMOUNT_TMPMin).color = Color.green;
ButtonDebug("Text Amount Min Created.");
}
}
AMOUNT_TEXTMAX = (RectTransform)((Component)BACKGROUND).transform.Find("multicraft_amt_max");
if ((Object)(object)AMOUNT_TEXTMAX == (Object)null)
{
Transform val10 = ((Component)inventoriGui.m_craftButton).transform.Find(CraftButtonTextName);
if ((Object)(object)val10 != (Object)null)
{
AMOUNT_TEXTMAX = (RectTransform)Object.Instantiate<Transform>(val10, ((Component)val7).transform);
if (!((Object)(object)AMOUNT_TEXTMAX != (Object)null))
{
DeLogger.LogMessage((object)"Amount Text Max Failed.");
return false;
}
((Object)AMOUNT_TEXTMAX).name = "multicraft_amt_max";
AMOUNT_TEXTMAX.SetSizeWithCurrentAnchors((Axis)0, 100f);
AMOUNT_TEXTMAX.SetSizeWithCurrentAnchors((Axis)1, 40f);
((Transform)AMOUNT_TEXTMAX).SetParent((Transform)(object)BACKGROUND);
((Transform)AMOUNT_TEXTMAX).localPosition = new Vector3(0f, 0f, 0f);
AMOUNT_TMPMax = ((Component)AMOUNT_TEXTMAX).GetComponent<TMP_Text>();
AMOUNT_TMPMax.text = "1";
((Graphic)AMOUNT_TMPMax).color = Color.magenta;
ButtonDebug("Text Amount Max Created.");
}
}
NOTE_JOYPAD = (RectTransform)((Component)BACKGROUND).transform.Find("multicraft_amt_joy");
if ((Object)(object)NOTE_JOYPAD == (Object)null)
{
Transform val11 = ((Component)inventoriGui.m_craftButton).transform.Find(CraftButtonTextName);
if ((Object)(object)val11 != (Object)null)
{
NOTE_JOYPAD = (RectTransform)Object.Instantiate<Transform>(val11, ((Component)val7).transform);
if (!((Object)(object)NOTE_JOYPAD != (Object)null))
{
DeLogger.LogMessage((object)"Text Joypad Failed.");
return false;
}
((Object)NOTE_JOYPAD).name = "multicraft_amt_joy";
NOTE_JOYPAD.SetSizeWithCurrentAnchors((Axis)0, 100f);
NOTE_JOYPAD.SetSizeWithCurrentAnchors((Axis)1, 40f);
((Transform)NOTE_JOYPAD).SetParent((Transform)(object)BACKGROUND);
((Transform)NOTE_JOYPAD).localPosition = new Vector3(105f, 0f, 0f);
TMP_Text component2 = ((Component)NOTE_JOYPAD).GetComponent<TMP_Text>();
component2.text = "JOYPAD";
((Graphic)component2).color = Color.black;
ButtonDebug("Text Joypad Created.");
}
}
NOTE_NOCOST = (RectTransform)((Component)BACKGROUND).transform.Find("multicraft_nocost");
if ((Object)(object)NOTE_NOCOST == (Object)null)
{
Transform val12 = ((Component)inventoriGui.m_craftButton).transform.Find(CraftButtonTextName);
if ((Object)(object)val12 != (Object)null)
{
NOTE_NOCOST = (RectTransform)Object.Instantiate<Transform>(val12, ((Component)val7).transform);
if (!((Object)(object)NOTE_NOCOST != (Object)null))
{
DeLogger.LogMessage((object)"Text No Cost Failed.");
return false;
}
((Object)NOTE_NOCOST).name = "multicraft_nocost";
NOTE_NOCOST.SetSizeWithCurrentAnchors((Axis)0, 200f);
NOTE_NOCOST.SetSizeWithCurrentAnchors((Axis)1, 40f);
((Transform)NOTE_NOCOST).SetParent((Transform)(object)BACKGROUND);
((Transform)NOTE_NOCOST).localPosition = new Vector3(0f, -50f, 0f);
NOTE_TMPNoCost = ((Component)NOTE_NOCOST).GetComponent<TMP_Text>();
NOTE_TMPNoCost.text = "NO CRAFTING COST";
((Graphic)NOTE_TMPNoCost).color = Color.yellow;
ButtonDebug("Text No Cost Created.");
}
}
NOTE_NOTE = (RectTransform)((Component)BACKGROUND).transform.Find("multicraft_note");
if ((Object)(object)NOTE_NOTE == (Object)null)
{
Transform val13 = ((Component)inventoriGui.m_craftButton).transform.Find(CraftButtonTextName);
if ((Object)(object)val13 != (Object)null)
{
NOTE_NOTE = (RectTransform)Object.Instantiate<Transform>(val13, ((Component)val7).transform);
if (!((Object)(object)NOTE_NOTE != (Object)null))
{
DeLogger.LogMessage((object)"Text No Cost Failed.");
return false;
}
((Object)NOTE_NOTE).name = "multicraft_note";
NOTE_NOTE.SetSizeWithCurrentAnchors((Axis)0, 300f);
NOTE_NOTE.SetSizeWithCurrentAnchors((Axis)1, 60f);
((Transform)NOTE_NOTE).SetParent((Transform)(object)BACKGROUND);
((Transform)NOTE_NOTE).localPosition = new Vector3(0f, -90f, 0f);
NOTE_TMPNote = ((Component)NOTE_NOTE).GetComponent<TMP_Text>();
NOTE_TMPNote.text = "NO CRAFTING COST";
((Graphic)NOTE_TMPNote).color = Color.green;
ButtonDebug("Text No Cost Created.");
}
}
ResetCurrentAmount();
if (GUI.m_craftDuration != MultiCraftPlugin.CraftingDuration.Value)
{
GUI.m_craftDuration = MultiCraftPlugin.CraftingDuration.Value;
}
if (IsRunning_ProjectAuga)
{
((Transform)BUTTON_PLUS).localPosition = new Vector3(140f, 0f, 0f);
((Transform)BUTTON_MINUS).localPosition = new Vector3(93f, 0f, 0f);
((Transform)BUTTON_STOP).localPosition = new Vector3(116f, 0f, 0f);
}
return true;
static RectTransform CreateMultiCraftButton(InventoryGui invgui, string name, string sometext, float axisZero, float axisOne)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
Transform transform = ((Component)invgui.m_craftButton).transform;
Transform val14 = Object.Instantiate<Transform>(transform, ((Component)transform).transform.parent);
((Object)val14).name = name;
RectTransform val15 = (RectTransform)((Component)val14).transform;
val15.SetSizeWithCurrentAnchors((Axis)0, axisZero);
val15.SetSizeWithCurrentAnchors((Axis)1, axisOne);
RectTransform val16 = (RectTransform)((Component)val15).transform.Find(CraftButtonTextName);
if ((Object)(object)val16 == (Object)null)
{
DeLogger.LogMessage((object)"rectransform null");
return null;
}
val16.SetSizeWithCurrentAnchors((Axis)0, axisZero);
val16.SetSizeWithCurrentAnchors((Axis)1, axisOne);
TMP_Text component3 = ((Component)val16).GetComponent<TMP_Text>();
component3.text = sometext;
((Component)val15).gameObject.SetActive(false);
return val15;
}
}
public static void ShowMultiCraftUI(MultiCraftPlugin.ButtonShowType type)
{
if (!MultiCraftPlugin.PluginEnable.Value)
{
if (IsMultiCraftButtonReady())
{
SetVisible(((Component)BACKGROUND).gameObject, setactive: false);
}
DeLog("MultiCraft Disabled");
return;
}
if (!IsMultiCraftButtonReady())
{
DeLog("ShowMultiCraftUI Button Not Ready");
return;
}
switch (type)
{
case MultiCraftPlugin.ButtonShowType.BUTTON_TYP_MULT:
if (!GamepadStats)
{
SetVisible(((Component)BACKGROUND).gameObject);
SetVisible(((Component)BUTTON_STOP).gameObject, setactive: false);
SetVisible(((Component)BUTTON_PLUS).gameObject);
SetVisible(((Component)BUTTON_MINUS).gameObject);
SetVisible(((Component)NOTE_JOYPAD).gameObject, setactive: false);
DeLog("BUTTON_TYP_MULT");
}
break;
case MultiCraftPlugin.ButtonShowType.BUTTON_TYP_STOP:
if (!GamepadStats)
{
SetVisible(((Component)BACKGROUND).gameObject);
SetVisible(((Component)BUTTON_PLUS).gameObject, setactive: false);
SetVisible(((Component)BUTTON_MINUS).gameObject, setactive: false);
SetVisible(((Component)BUTTON_STOP).gameObject);
SetVisible(((Component)NOTE_JOYPAD).gameObject, setactive: false);
DeLog("BUTTON_TYP_STOP");
}
break;
case MultiCraftPlugin.ButtonShowType.BUTTON_TYP_JOY:
SetVisible(((Component)BACKGROUND).gameObject);
SetVisible(((Component)BUTTON_STOP).gameObject, setactive: false);
SetVisible(((Component)BUTTON_PLUS).gameObject, setactive: false);
SetVisible(((Component)BUTTON_MINUS).gameObject, setactive: false);
SetVisible(((Component)NOTE_JOYPAD).gameObject);
DeLog("BUTTON_TYP_JOY");
break;
case MultiCraftPlugin.ButtonShowType.BUTTON_TYP_HIDE:
SetVisible(((Component)BACKGROUND).gameObject, setactive: false);
DeLog("BUTTON_TYP_HIDE");
break;
default:
DeLog("Unknown Button type");
break;
}
}
public static void UpdateGamepad()
{
if (IsRunning_ProjectAuga && (Object)(object)GUI != (Object)null && ZInput.IsGamepadActive() && GUI.InCraftTab())
{
((MonoBehaviour)GUI).Invoke("UpdateRecipeGamepadInput", 0f);
if (ZInput.GetButtonDown("JoyButtonX"))
{
if (InProgress)
{
((MonoBehaviour)GUI).Invoke("OnCraftCancelPressed", 0f);
}
else
{
((MonoBehaviour)GUI).Invoke("OnCraftPressed", 0f);
}
}
}
if (GamepadStats != ZInput.IsGamepadActive())
{
GamepadStats = ZInput.IsGamepadActive();
if (GamepadStats)
{
ShowMultiCraftUI(MultiCraftPlugin.ButtonShowType.BUTTON_TYP_JOY);
}
else if (InProgress)
{
ShowMultiCraftUI(MultiCraftPlugin.ButtonShowType.BUTTON_TYP_STOP);
}
else
{
ShowMultiCraftUI(MultiCraftPlugin.ButtonShowType.BUTTON_TYP_MULT);
}
}
if (!InProgress)
{
if (ZInput.GetButtonDown(MultiCraftPlugin.JYAmountPlus.Value))
{
OnPlusButtonPressed();
}
else if (ZInput.GetButtonDown(MultiCraftPlugin.JYAmountMinus.Value))
{
OnMinusButtonPressed();
}
}
}
public static float DeLog(string text, float intervaL = 0f)
{
return 0f;
}
public static void CenterMsg(string text)
{
if ((Object)(object)Player.m_localPlayer != (Object)null)
{
Humanoid component = ((Component)Player.m_localPlayer).GetComponent<Humanoid>();
if (component != null)
{
((Character)component).Message((MessageType)2, Localization.instance.Localize(text), 0, (Sprite)null);
}
}
}
private static bool IsNoCraftCost()
{
return (Object)(object)Player.m_localPlayer != (Object)null && Player.m_localPlayer.NoCostCheat();
}
public static void ShowNoCostText()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if (IsNoCraftCost())
{
SetVisible(((Component)NOTE_NOCOST).gameObject);
((Graphic)NOTE_TMPNoCost).color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.yellow);
}
else
{
SetVisible(((Component)NOTE_NOCOST).gameObject, setactive: false);
}
}
public static void SetCraftingCompleted(string text)
{
NOTE_TMPNote.text = text;
SetVisible(((Component)NOTE_NOTE).gameObject, text != "");
}
private static void ButtonDebug(string text)
{
}
}
[BepInPlugin("GsiX.MultiCraft", "GsiX MultiCraft", "1.6.0")]
[BepInProcess("valheim.exe")]
public class MultiCraftPlugin : BaseUnityPlugin
{
public enum ButtonShowType
{
BUTTON_TYP_MULT,
BUTTON_TYP_STOP,
BUTTON_TYP_JOY,
BUTTON_TYP_HIDE
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
public static class ZNetScene_Awake_Patch
{
[HarmonyPostfix]
public static void Postfix(ZNetScene __instance)
{
if (!((Object)(object)__instance != (Object)null))
{
return;
}
if (Chainloader.PluginInfos.TryGetValue(Multicraft.ProjectAugaGUID, out var value))
{
Multicraft.IsRunning_ProjectAuga = true;
Multicraft.CraftButtonProgs = Multicraft.AugaButtonProgs;
Multicraft.CraftButtonTextName = Multicraft.AugaButtonTextName;
Multicraft.CraftButtonPanel = Multicraft.AugaButtonPanel;
Multicraft.DeLogger.LogMessage((object)$"{value.Instance.Info.Metadata.Name} | Version: {value.Instance.Info.Metadata.Version} | SUCCESS");
}
if (ClientSync_VPlus())
{
Multicraft.DeLogger.LogMessage((object)"Valheim+ Config Success");
}
else if (ClientSync_Adent())
{
Multicraft.DeLogger.LogMessage((object)"Aeden's Config Success");
}
else if (ClientSync_General())
{
Multicraft.DeLogger.LogMessage((object)"General Config Success");
}
if (Multicraft.RangeToCount == -1f)
{
Multicraft.RangeToCount = AlternateRange.Value;
if (Multicraft.RangeToCount > 0f)
{
Multicraft.DeLogger.LogMessage((object)"No Craft From Container Detected or Sync option disabled | Switching to AlternateRange Config");
}
else
{
Multicraft.DeLogger.LogMessage((object)"Craft From Container Failed | AUTO DETECTION TURNED OFF.");
}
}
UpdateBufferClient();
UpdateCustomSupportStatus();
ProjectAuga.SettingChanged += delegate
{
UpdateCustomSupportStatus();
};
ValheimPlus.SettingChanged += delegate
{
UpdateCustomSupportStatus();
};
Aedenthorn.SettingChanged += delegate
{
UpdateCustomSupportStatus();
};
GeneralSet.SettingChanged += delegate
{
UpdateCustomSupportStatus();
};
AlternateRange.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_Ship.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_Wagon.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_Wood.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_Reinforced.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_BlackMetal.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_Personal.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_Yuleklapp.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_Warded.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_InUse.SettingChanged += delegate
{
UpdateConfingEmulation();
};
AllowContainers_ItemDrawer.SettingChanged += delegate
{
UpdateConfingEmulation();
};
}
}
[HarmonyPatch(typeof(Player), "Start")]
private static class Player_Start_Patch
{
private static void Postfix(Player __instance)
{
if (!PluginEnable.Value || (Object)(object)__instance == (Object)null || !((Character)__instance).IsPlayer() || !((Object)(object)__instance == (Object)(object)Player.m_localPlayer))
{
return;
}
Multicraft.BuffPlayerID = __instance.GetPlayerID();
Multicraft.InfoContainer_CheckAccess = AccessTools.Method(typeof(Container), "CheckAccess", (Type[])null, (Type[])null);
if ((Object)(object)Multicraft.GuiBuffer != (Object)null && !Multicraft.IsMultiCraftButtonReady())
{
if (Multicraft.ConstructButton(Multicraft.GuiBuffer))
{
Multicraft.DeLogger.LogMessage((object)"MultiCraft Button Success");
}
else
{
Multicraft.DeLogger.LogMessage((object)"MultiCraft Button Failed");
}
Multicraft.GuiBuffer = null;
}
}
}
[HarmonyPatch(typeof(InventoryGui), "Awake")]
private static class InventoryGui_Awake_Patch
{
private static void Postfix(InventoryGui __instance)
{
if (PluginEnable.Value && !((Object)(object)__instance == (Object)null))
{
Multicraft.GuiBuffer = __instance;
}
}
}
[HarmonyPatch(typeof(InventoryGui), "Show")]
private static class InventoryGui_Show_Patch
{
private static void Postfix(InventoryGui __instance, Container container, int activeGroup)
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
if (!PluginEnable.Value && Multicraft.IsMultiCraftButtonReady())
{
Multicraft.SetVisible(((Component)Multicraft.BACKGROUND).gameObject, setactive: false);
return;
}
if (Multicraft.myInventory == null)
{
Multicraft.myInventory = ((Humanoid)Player.m_localPlayer).GetInventory();
}
Multicraft.ConstructButton(__instance);
Multicraft.CURRENTMAXIMUM = -1;
Multicraft.RecipeNameBuffers = " ";
if (ZInput.IsGamepadActive())
{
Multicraft.GamepadStats = !ZInput.IsGamepadActive();
}
}
}
[HarmonyPatch(typeof(InventoryGui), "Hide")]
private static class InventoryGui_Hide_Patch
{
private static void Postfix()
{
if (PluginEnable.Value && Multicraft.IsMultiCraftButtonReady())
{
Multicraft.ResetCurrentAmount();
}
}
}
[HarmonyPatch(typeof(InventoryGui), "SetupRequirementList")]
private static class InventoryGui_SetupRequirementList_Patch
{
private static void Postfix(InventoryGui __instance, int quality, Player player, bool allowedQuality, ref KeyValuePair<Recipe, ItemData> ___m_selectedRecipe)
{
if (!PluginEnable.Value || !((Object)(object)__instance != (Object)null) || !((Object)(object)player != (Object)null))
{
return;
}
Multicraft.ShowNoCostText();
if (allowedQuality && !Multicraft.InProgress)
{
int num = 0;
bool requireOnlyOneIngredient = ___m_selectedRecipe.Key.m_requireOnlyOneIngredient;
Requirement[] array = ___m_selectedRecipe.Key.m_resources;
if (requireOnlyOneIngredient)
{
List<Requirement> list = new List<Requirement>();
Requirement[] array2 = array;
Requirement[] array3 = array2;
foreach (Requirement val in array3)
{
if (player.IsKnownMaterial(val.m_resItem.m_itemData.m_shared.m_name))
{
list.Add(val);
}
}
array = list.ToArray();
}
for (int j = 0; j < array.Length; j++)
{
int amount = array[j].GetAmount(quality);
if (amount <= 0)
{
continue;
}
string name = array[j].m_resItem.m_itemData.m_shared.m_name;
float num2 = array[j].GetAmount(quality);
float availableItems = GetAvailableItems(player, name);
int num3 = Mathf.FloorToInt(availableItems / num2);
if (num3 < 0)
{
continue;
}
if (requireOnlyOneIngredient)
{
num += num3;
continue;
}
if (Multicraft.CURRENTMAXIMUM < 0)
{
Multicraft.CURRENTMAXIMUM = num3;
}
if (num3 < Multicraft.CURRENTMAXIMUM)
{
Multicraft.CURRENTMAXIMUM = num3;
}
}
if (requireOnlyOneIngredient)
{
Multicraft.CURRENTMAXIMUM = num;
}
}
if (Multicraft.RecipeNameCurrent != __instance.m_recipeName.text)
{
Multicraft.RecipeNameCurrent = __instance.m_recipeName.text;
}
}
}
[HarmonyPatch(typeof(InventoryGui), "SetupRequirement", new Type[]
{
typeof(Transform),
typeof(Requirement),
typeof(Player),
typeof(bool),
typeof(int)
})]
private static class InventoryGui_SetupRequirement_Patch
{
private static void Postfix(Transform elementRoot, Requirement req, Player player, bool craft, int quality)
{
if (!PluginEnable.Value || !ShowIconRequirement.Value)
{
return;
}
if ((Object)(object)elementRoot == (Object)null || req == null || (Object)(object)player == (Object)null)
{
INTERVAL_ERROR = Multicraft.DeLog("InventoryGui_SetupRequirement_Patch Failed", INTERVAL_ERROR);
return;
}
string name = req.m_resItem.m_itemData.m_shared.m_name;
float num = req.GetAmount(quality);
float availableItems = GetAvailableItems(player, name);
if (Multicraft.CURRENTAMOUNT > 0)
{
num *= (float)Multicraft.CURRENTAMOUNT;
}
TMP_Text component = ((Component)((Component)elementRoot).transform.Find("res_amount")).GetComponent<TMP_Text>();
component.text = $"{num}/{availableItems}";
}
}
[HarmonyPatch(typeof(InventoryGui), "SetRecipe")]
private static class InventoryGui_SetRecipe_Patch
{
private static void Postfix(InventoryGui __instance, int index, bool center)
{
if (PluginEnable.Value && !((Object)(object)__instance == (Object)null) && !Multicraft.InProgress && Multicraft.IsMultiCraftButtonReady())
{
Multicraft.CURRENTMAXIMUM = -1;
Multicraft.ResetCurrentAmount();
}
}
}
[HarmonyPatch(typeof(InventoryGui), "OnCraftPressed")]
private static class InventoryGui_OnCraftPressed_Patch
{
private static bool Prefix(InventoryGui __instance, ref Recipe ___m_craftRecipe, ref KeyValuePair<Recipe, ItemData> ___m_selectedRecipe, ref bool __runOriginal)
{
if (!PluginEnable.Value)
{
return true;
}
if (__instance.InCraftTab())
{
if (Multicraft.CURRENTAMOUNT <= 0)
{
Multicraft.CenterMsg("Set Current Crafting Amount");
__runOriginal = false;
return false;
}
Multicraft.InProgress = true;
Multicraft.ShowMultiCraftUI(ButtonShowType.BUTTON_TYP_STOP);
Multicraft.SetCraftingCompleted("");
}
__runOriginal = true;
return true;
}
}
[HarmonyPatch(typeof(InventoryGui), "OnCraftCancelPressed")]
private static class InventoryGui_OnCraftCancelPressed_Patch
{
private static void Postfix(InventoryGui __instance)
{
if (PluginEnable.Value)
{
if (__instance.InCraftTab())
{
Multicraft.ShowMultiCraftUI(ButtonTypeBuffer);
ButtonTypeBuffer = ButtonShowType.BUTTON_TYP_MULT;
}
else
{
Multicraft.ShowMultiCraftUI(ButtonShowType.BUTTON_TYP_HIDE);
ButtonTypeBuffer = ButtonShowType.BUTTON_TYP_MULT;
}
Multicraft.DeductAmount = false;
Multicraft.InProgress = false;
}
}
}
[HarmonyPatch(typeof(InventoryGui), "OnSelectedRecipe")]
private static class InventoryGui_OnSelectedRecipe_Patch
{
private static void Postfix(ref InventoryGui __instance, GameObject button)
{
if (PluginEnable.Value && (Object)(object)__instance != (Object)null)
{
if (Multicraft.InProgress)
{
Multicraft.OnStopButtonPressed();
}
Multicraft.RecipeNameBuffers = " ";
}
}
}
[HarmonyPatch(typeof(InventoryGui), "UpdateRecipeGamepadInput")]
private static class InventoryGui_UpdateRecipeGamepadInput_Patch
{
private static void Postfix(InventoryGui __instance, ref List<KeyValuePair<Recipe, ItemData>> ___m_availableRecipes)
{
if (!PluginEnable.Value || !((Object)(object)__instance != (Object)null) || !Multicraft.InProgress || ___m_availableRecipes.Count <= 0)
{
return;
}
if (Multicraft.IsRunning_ProjectAuga)
{
if (ZInput.GetButton("JoyLStickDown") || ZInput.GetButton("JoyDPadDown"))
{
StopOrReset();
}
if (ZInput.GetButton("JoyLStickUp") || ZInput.GetButton("JoyDPadUp"))
{
StopOrReset();
}
}
else if (ZInput.GetButtonDown("JoyLStickDown") || ZInput.GetButtonDown("JoyDPadDown") || ZInput.GetButtonDown("JoyLStickUp") || ZInput.GetButtonDown("JoyDPadUp"))
{
StopOrReset();
}
static void StopOrReset()
{
if (Multicraft.InProgress)
{
Multicraft.OnStopButtonPressed();
}
Multicraft.RecipeNameBuffers = " ";
}
}
}
[HarmonyPatch(typeof(Container), "Awake")]
private static class Container_Awake_Patch
{
private static void Postfix(Container __instance, ZNetView ___m_nview)
{
if ((Object)(object)__instance != (Object)null && __instance.GetInventory() != null && ((___m_nview != null) ? ___m_nview.GetZDO() : null) != null && (((Object)__instance).name.StartsWith("piece_") || ((Object)__instance).name.StartsWith("Container") || ___m_nview.GetZDO().GetLong(StringExtensionMethods.GetStableHashCode("creator"), 0L) != 0))
{
ContainerBufferList.Add(__instance);
}
}
}
[HarmonyPatch(typeof(Container), "OnDestroyed")]
private static class Container_OnDestroyed_Patch
{
private static void Prefix(Container __instance)
{
ContainerBufferList.Remove(__instance);
DeveloperMessage("Container OnDestroyed name", ((Object)__instance).name);
DeveloperMessage("Container OnDestroyed m_name", __instance.m_name);
}
}
public const string PluginGUID = "GsiX.MultiCraft";
public const string PluginName = "GsiX MultiCraft";
public const string PluginVersion = "1.6.0";
private readonly Harmony harmony = new Harmony("GsiX.MultiCraft");
private static float INTERVAL_ERROR = Time.time;
private static List<Container> ContainerBufferList = new List<Container>();
public static ButtonShowType ButtonTypeBuffer = ButtonShowType.BUTTON_TYP_MULT;
public static ConfigEntry<bool> DeveloperConsole;
public static ConfigEntry<bool> PluginEnable;
public static ConfigEntry<bool> ShowMaxCraftable;
public static ConfigEntry<float> CraftingDuration;
public static ConfigEntry<bool> CapMaximumCraftable;
public static ConfigEntry<bool> ShowIconRequirement;
public static ConfigEntry<string> ExtendedContainerGUID;
public static ConfigEntry<string> ExtendedConfigSection;
public static ConfigEntry<string> ExtendedConfigKeys;
public static ConfigEntry<float> AlternateRange;
public static ConfigEntry<bool> ProjectAuga;
public static ConfigEntry<bool> ValheimPlus;
public static ConfigEntry<bool> Aedenthorn;
public static ConfigEntry<bool> GeneralSet;
public static ConfigEntry<bool> ContainerEmulationSync;
public static ConfigEntry<bool> AllowContainers_Ship;
public static ConfigEntry<bool> AllowContainers_Wagon;
public static ConfigEntry<bool> AllowContainers_Wood;
public static ConfigEntry<bool> AllowContainers_Reinforced;
public static ConfigEntry<bool> AllowContainers_BlackMetal;
public static ConfigEntry<bool> AllowContainers_Personal;
public static ConfigEntry<bool> AllowContainers_Yuleklapp;
public static ConfigEntry<bool> AllowContainers_ItemDrawer;
public static ConfigEntry<bool> AllowContainers_Warded;
public static ConfigEntry<bool> AllowContainers_InUse;
public static ConfigEntry<KeyboardShortcut> KBDeltaSmall;
public static ConfigEntry<KeyboardShortcut> KBDeltaMedium;
public static ConfigEntry<string> JYAmountPlus;
public static ConfigEntry<string> JYAmountMinus;
public static ConfigEntry<string> JYDeltaSmall;
public static ConfigEntry<string> JYDeltaMedium;
public void Awake()
{
//IL_034f: Unknown result type (might be due to invalid IL or missing references)
//IL_035f: Unknown result type (might be due to invalid IL or missing references)
//IL_0369: Expected O, but got Unknown
//IL_0388: Unknown result type (might be due to invalid IL or missing references)
//IL_0398: Unknown result type (might be due to invalid IL or missing references)
//IL_03a2: Expected O, but got Unknown
DeveloperConsole = ((BaseUnityPlugin)this).Config.Bind<bool>("DEVELOPER", "DebugOutput", false, "Allow Developer console output. You dont need this.");
PluginEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Plugin Enable", "PluginEnable", true, "Plugin Enabled/Disabled");
ShowMaxCraftable = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowMaxCraftable", false, "Show maximum craftable amount at center text");
CraftingDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CraftingDuration", 0.5f, "Crafting time. 2f is ingame default value");
CapMaximumCraftable = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CapMaximumCraftable", true, "If true, maximum craftable capped at maximum amount of resources.");
ShowIconRequirement = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowRequiredBelowIcon", false, "If true, maximum required amount will be shown in individual requirement icon, this may cause issue for other plugin that read the value in real-time. Try turn it to false");
ExtendedContainerGUID = ((BaseUnityPlugin)this).Config.Bind<string>("CRAFT FROM CONTAINER", "ExtendedContainerGUID", "", "Name of the Craft from container plugin GUID");
ExtendedConfigSection = ((BaseUnityPlugin)this).Config.Bind<string>("CRAFT FROM CONTAINER", "ExtendedContainerSection", "", "Name of the config section where we retrive the value");
ExtendedConfigKeys = ((BaseUnityPlugin)this).Config.Bind<string>("CRAFT FROM CONTAINER", "ExtendedContainerKey", "", "Name of the config key we try to retrive the value");
ProjectAuga = ((BaseUnityPlugin)this).Config.Bind<bool>("CUSTOM SUPPORT STATUS", "ProjectAuga", false, "Show Project Auga is running");
ValheimPlus = ((BaseUnityPlugin)this).Config.Bind<bool>("CUSTOM SUPPORT STATUS", "ValheimPlus", false, "Show Valheim+ is running");
Aedenthorn = ((BaseUnityPlugin)this).Config.Bind<bool>("CUSTOM SUPPORT STATUS", "Aedenthorn", false, "Show Adent's is running");
GeneralSet = ((BaseUnityPlugin)this).Config.Bind<bool>("CUSTOM SUPPORT STATUS", "GeneralSet", false, "Show non custom support is running");
ContainerEmulationSync = ((BaseUnityPlugin)this).Config.Bind<bool>("SYNCHRONIZE", "ContainerEmulationSync", true, "Sync config with craft from container config. Only for supported Craft From Container.");
AlternateRange = ((BaseUnityPlugin)this).Config.Bind<float>("EMULATE CRAFT FROM CONTAINER", "AlternateRange", 0f, "Alternate manual Container range config.");
AllowContainers_Ship = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_Ship", true, "Emulate allow Ship container to pull resources");
AllowContainers_Wagon = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_Wagon", true, "Emulate allow Wagon container to pull resources");
AllowContainers_Wood = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_Wood", true, "Emulate allow Wooden Container to pull resources");
AllowContainers_Reinforced = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_Reinforced", true, "Emulate allow Reinforced Container to pull resources");
AllowContainers_BlackMetal = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_BlackMetal", true, "Emulate allow Black Metal Container to pull resources");
AllowContainers_Personal = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_Personal", false, "Emulate allow Personal Chest to pull resources");
AllowContainers_Yuleklapp = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_Yuleklapp", false, "Emulate allow Yuleklapp Chest to pull resources");
AllowContainers_ItemDrawer = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_ItemDrawer", false, "Emulate allow ItemDrawers Chest to pull resources");
AllowContainers_Warded = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_Warded", false, "Emulate allow Warded Container to pull resources");
AllowContainers_InUse = ((BaseUnityPlugin)this).Config.Bind<bool>("EMULATE CRAFT FROM CONTAINER", "AllowContainers_InUse", false, "Emulate allow container being use by player to pull resources");
KBDeltaSmall = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("KEYBOARD SHORTCUT", "KeyboardDelta_10", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), new ConfigDescription("Keyboard shortcut amount +/- 10. List at https://docs.unity3d.com/ScriptReference/KeyCode.html", (AcceptableValueBase)null, Array.Empty<object>()));
KBDeltaMedium = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("KEYBOARD SHORTCUT", "KeyboardDelta_100", new KeyboardShortcut((KeyCode)306, Array.Empty<KeyCode>()), new ConfigDescription("Keyboard shortcut amount +/- 100. List at https://docs.unity3d.com/ScriptReference/KeyCode.html", (AcceptableValueBase)null, Array.Empty<object>()));
JYAmountPlus = ((BaseUnityPlugin)this).Config.Bind<string>("GAMEPAD SHORTCUT", "GamePadAmount_Plus", "JoyDPadRight", "GamePad amount plus. List at https://valheim-modding.github.io/Jotunn/data/input/input-list.html");
JYAmountMinus = ((BaseUnityPlugin)this).Config.Bind<string>("GAMEPAD SHORTCUT", "GamePadAmount_Minus", "JoyDPadLeft", "GamePad amount minus. List at https://valheim-modding.github.io/Jotunn/data/input/input-list.html");
JYDeltaSmall = ((BaseUnityPlugin)this).Config.Bind<string>("GAMEPAD SHORTCUT", "GamePadDelta_10", "JoyButtonA", "GamePad shortcut amount +/- 10. List at https://valheim-modding.github.io/Jotunn/data/input/input-list.html");
JYDeltaMedium = ((BaseUnityPlugin)this).Config.Bind<string>("GAMEPAD SHORTCUT", "GamePadDelta_100", "JoyRStick", "GamePad shortcut amount +/- 100. List at https://valheim-modding.github.io/Jotunn/data/input/input-list.html");
Multicraft.DeLogger = ((BaseUnityPlugin)this).Logger;
harmony.PatchAll();
}
private static void UpdateConfingEmulation()
{
if (Multicraft.IsRunning_Valheimplus)
{
if (ContainerEmulationSync.Value)
{
ClientSync_VPlus();
Multicraft.DeLogger.LogMessage((object)"Vplus+ config updated with emulation sync enabled");
}
else
{
Multicraft.DeLogger.LogMessage((object)"Vplus+ config updated with emulation sync disabled");
}
}
else if (Multicraft.IsRunning_Aedenthorn)
{
if (ContainerEmulationSync.Value)
{
ClientSync_Adent();
Multicraft.DeLogger.LogMessage((object)"Adent's config updated with emulation sync enabled");
}
else
{
Multicraft.DeLogger.LogMessage((object)"Vplus+ config updated with emulation sync disabled");
}
}
else if (Multicraft.IsRunning_General)
{
ConfigEntry<float> val = default(ConfigEntry<float>);
if (Chainloader.PluginInfos.TryGetValue(ExtendedContainerGUID.Value, out var value) && value.Instance.Config.TryGetEntry<float>(ExtendedConfigSection.Value, ExtendedConfigKeys.Value, ref val))
{
Multicraft.RangeToCount = val.Value;
Multicraft.DeLogger.LogMessage((object)"Preset Config has been updated.");
}
}
else
{
Multicraft.RangeToCount = AlternateRange.Value;
Multicraft.DeLogger.LogMessage((object)"Alternate Config has been updated.");
}
UpdateBufferClient();
UpdateCustomSupportStatus();
}
private static void UpdateCustomSupportStatus()
{
ProjectAuga.Value = Multicraft.IsRunning_ProjectAuga;
ValheimPlus.Value = Multicraft.IsRunning_Valheimplus;
Aedenthorn.Value = Multicraft.IsRunning_Aedenthorn;
GeneralSet.Value = Multicraft.IsRunning_General;
}
private static void UpdateBufferClient()
{
Multicraft.AllowContainersBuff_Ship = AllowContainers_Ship.Value;
Multicraft.AllowContainersBuff_Wagon = AllowContainers_Wagon.Value;
Multicraft.AllowContainersBuff_Warded = AllowContainers_Warded.Value;
Multicraft.AllowContainersBuff_Wood = AllowContainers_Wood.Value;
Multicraft.AllowContainersBuff_Reinforced = AllowContainers_Reinforced.Value;
Multicraft.AllowContainersBuff_BlackMetal = AllowContainers_BlackMetal.Value;
Multicraft.AllowContainersBuff_Personal = AllowContainers_Personal.Value;
Multicraft.AllowContainersBuff_Yuleklapp = AllowContainers_Yuleklapp.Value;
Multicraft.AllowContainersBuff_InUse = AllowContainers_InUse.Value;
Multicraft.AllowContainersBuff_ItemDrawer = AllowContainers_ItemDrawer.Value;
}
public void OnDestroy()
{
harmony.UnpatchSelf();
}
public void Update()
{
if (!PluginEnable.Value || (Object)(object)Player.m_localPlayer == (Object)null || Multicraft.myInventory == null || !Multicraft.IsMultiCraftButtonReady())
{
return;
}
if (Multicraft.GUI.InCraftTab())
{
if (!Multicraft.UIShown)
{
Multicraft.UIShown = true;
ButtonTypeBuffer = ButtonShowType.BUTTON_TYP_MULT;
Multicraft.OnStopButtonPressed();
Multicraft.RecipeNameBuffers = " ";
}
Multicraft.UpdateGamepad();
}
else if (Multicraft.UIShown)
{
Multicraft.UIShown = false;
ButtonTypeBuffer = ButtonShowType.BUTTON_TYP_HIDE;
Multicraft.OnStopButtonPressed();
Multicraft.RecipeNameBuffers = " ";
Multicraft.CURRENTMAXIMUM = -1;
Multicraft.ResetCurrentAmount();
Multicraft.GamepadStats = false;
Multicraft.SetCraftingCompleted("");
}
if (Multicraft.InProgress)
{
if (!(Time.time - Multicraft.CraftingStart >= Multicraft.GUI.m_craftDuration) || ((Component)Multicraft.GUI.m_craftProgressBar).gameObject.activeInHierarchy)
{
return;
}
if (Multicraft.DeductAmount)
{
Multicraft.DeductAmount = false;
Multicraft.CURRENTAMOUNT--;
Multicraft.CURRENTMAXIMUM--;
Multicraft.UpdateCraftingAmount();
if (Multicraft.CURRENTAMOUNT <= 0)
{
Multicraft.SetCraftingCompleted("Crafting\n <color=yellow>" + Multicraft.RecipeNameCurrent + "</color> \nCompleted");
}
}
if (Multicraft.CURRENTAMOUNT > 0)
{
if (Multicraft.myInventory.HaveEmptySlot())
{
Multicraft.DeductAmount = true;
Multicraft.CraftingStart = Time.time;
((UnityEvent)((Component)Multicraft.GUI.m_craftButton).GetComponent<Button>().onClick).Invoke();
return;
}
Multicraft.CenterMsg("MultiCraft Minimum One <color=#00ff00>Extra</color> Empty Slot");
}
Multicraft.OnStopButtonPressed();
if (Multicraft.CURRENTMAXIMUM > 0)
{
Multicraft.CURRENTAMOUNT = 1;
Multicraft.UpdateCraftingAmount();
}
}
else if (Multicraft.CURRENTMAXIMUM >= 0 && Multicraft.RecipeNameBuffers != Multicraft.RecipeNameCurrent)
{
Multicraft.RecipeNameBuffers = Multicraft.RecipeNameCurrent;
if (Multicraft.CURRENTMAXIMUM > 0)
{
Multicraft.CURRENTAMOUNT = 1;
Multicraft.ShowCraftableText("#00ff00");
}
else
{
Multicraft.CURRENTAMOUNT = 0;
Multicraft.ShowCraftableText("#404040");
}
Multicraft.UpdateCraftingAmount();
Multicraft.SetCraftingCompleted("");
}
}
private static bool ClientSync_VPlus()
{
bool flag = false;
if (Chainloader.PluginInfos.TryGetValue("org.bepinex.plugins.valheim_plus", out var value))
{
if (!Multicraft.IsRunning_Valheimplus)
{
Multicraft.DeLogger.LogMessage((object)$"{value.Instance.Info.Metadata.GUID} | {value.Instance.Info.Metadata.Name} | Version: {value.Instance.Info.Metadata.Version} | CLIENT DETECTED");
}
if (!ContainerEmulationSync.Value)
{
Multicraft.DeLogger.LogMessage((object)"Auto config sync not enabled. Config sync bypassed.");
}
else
{
string? directoryName = Path.GetDirectoryName(Paths.BepInExConfigPath);
char directorySeparatorChar = Path.DirectorySeparatorChar;
string path = directoryName + directorySeparatorChar + "valheim_plus.cfg";
if (!File.Exists(path))
{
Multicraft.DeLogger.LogMessage((object)"Valheim+ unable to loacte valheim_plus.cfg file.");
}
else
{
List<string> list = File.ReadAllLines(path).ToList();
bool flag2 = false;
bool flag3 = false;
int num = 0;
foreach (string item in list)
{
if (item.StartsWith(";"))
{
continue;
}
string text = item.Replace(" ", "");
text = text.ToLower();
if (!flag2 && text == "[craftfromchest]")
{
flag2 = true;
}
else
{
if (!flag2)
{
continue;
}
if (text.StartsWith("["))
{
flag3 = true;
break;
}
if (text.Contains("enabled="))
{
flag = text.Contains("true");
if (!flag)
{
break;
}
num++;
}
else if (text.Contains("disablecookingstation="))
{
bool flag4 = text.Contains("true");
Multicraft.Valheimplus_AllowCouldron = !flag4;
num++;
}
else if (text.Contains("checkfromworkbench="))
{
bool flag4 = text.Contains("true");
Multicraft.Valheimplus_CheckWorkbench = flag4;
num++;
}
else if (text.Contains("ignoreprivateareacheck="))
{
bool flag4 = text.Contains("true");
AllowContainers_Warded.Value = flag4;
num++;
}
else if (text.Contains("range="))
{
text = text.Replace("range=", "");
if (int.TryParse(text, out var result))
{
Multicraft.RangeToCount = result;
AllowContainers_Wood.Value = true;
AllowContainers_Reinforced.Value = true;
AllowContainers_BlackMetal.Value = true;
AllowContainers_Personal.Value = false;
AllowContainers_Yuleklapp.Value = false;
AllowContainers_InUse.Value = false;
AllowContainers_ItemDrawer.Value = true;
}
num++;
}
else if (text.Contains("allowcraftingfromcarts="))
{
bool flag4 = text.Contains("true");
AllowContainers_Wagon.Value = flag4;
Multicraft.AllowContainersBuff_Wagon = flag4;
num++;
}
else if (text.Contains("allowcraftingfromships="))
{
bool flag4 = text.Contains("true");
AllowContainers_Ship.Value = flag4;
Multicraft.AllowContainersBuff_Ship = flag4;
num++;
}
else if (num >= 7)
{
break;
}
}
}
if (flag3)
{
Multicraft.DeLogger.LogMessage((object)"Valheim+ unexpected config read breakout.");
}
else
{
if (flag)
{
if (!Multicraft.IsRunning_Valheimplus)
{
Multicraft.DeLogger.LogMessage((object)$"Valheim+ {value.Instance.Info.Metadata.GUID} | Version: {value.Instance.Info.Metadata.Version} | Range: {Multicraft.RangeToCount} | SUCCESS");
}
Multicraft.IsRunning_Valheimplus = true;
return true;
}
Multicraft.RangeToCount = -1f;
Multicraft.DeLogger.LogMessage((object)"Valheim+ Craft From Chest Config Disabled");
}
}
}
}
return false;
}
private static bool ClientSync_Adent()
{
if (Chainloader.PluginInfos.TryGetValue("aedenthorn.CraftFromContainers", out var value))
{
if (!Multicraft.IsRunning_Aedenthorn)
{
Multicraft.DeLogger.LogMessage((object)$"{value.Instance.Info.Metadata.GUID} | {value.Instance.Info.Metadata.Name} | Version: {value.Instance.Info.Metadata.Version} | CLIENT DETECTED");
}
if (!ContainerEmulationSync.Value)
{
Multicraft.DeLogger.LogMessage((object)"Auto Config Sync Not Enabled. Config Sync Bypassed.");
}
else
{
bool flag = false;
ConfigEntry<bool> val = default(ConfigEntry<bool>);
if (value.Instance.Config.TryGetEntry<bool>("General", "Enabled", ref val))
{
flag = val.Value;
}
if (flag)
{
ConfigEntry<bool> val2 = default(ConfigEntry<bool>);
if (value.Instance.Config.TryGetEntry<bool>("Container Types", "IgnoreShipContainers", ref val2))
{
AllowContainers_Ship.Value = !val2.Value;
}
ConfigEntry<bool> val3 = default(ConfigEntry<bool>);
if (value.Instance.Config.TryGetEntry<bool>("Container Types", "IgnoreWagonContainers", ref val3))
{
AllowContainers_Wagon.Value = !val3.Value;
}
ConfigEntry<bool> val4 = default(ConfigEntry<bool>);
if (value.Instance.Config.TryGetEntry<bool>("Container Types", "IgnoreWoodChests", ref val4))
{
AllowContainers_Wood.Value = !val4.Value;
}
ConfigEntry<bool> val5 = default(ConfigEntry<bool>);
if (value.Instance.Config.TryGetEntry<bool>("Container Types", "IgnoreReinforcedChests", ref val5))
{
AllowContainers_Reinforced.Value = !val5.Value;
}
ConfigEntry<bool> val6 = default(ConfigEntry<bool>);
if (value.Instance.Config.TryGetEntry<bool>("Container Types", "IgnoreBlackMetalChests", ref val6))
{
AllowContainers_BlackMetal.Value = !val6.Value;
}
ConfigEntry<bool> val7 = default(ConfigEntry<bool>);
if (value.Instance.Config.TryGetEntry<bool>("Container Types", "IgnorePrivateChests", ref val7))
{
AllowContainers_Personal.Value = !val7.Value;
}
ConfigEntry<float> val8 = default(ConfigEntry<float>);
if (value.Instance.Config.TryGetEntry<float>("General", "ContainerRange", ref val8))
{
if (!Multicraft.IsRunning_Aedenthorn)
{
Multicraft.DeLogger.LogMessage((object)$"{value.Instance.Info.Metadata.GUID} | Version: {value.Instance.Info.Metadata.Version} | Range: {val8.Value} | SUCCESS");
}
AllowContainers_Yuleklapp.Value = false;
AllowContainers_Warded.Value = false;
AllowContainers_InUse.Value = false;
AllowContainers_ItemDrawer.Value = true;
Multicraft.IsRunning_Aedenthorn = true;
Multicraft.RangeToCount = val8.Value;
return true;
}
}
else
{
Multicraft.RangeToCount = -1f;
Multicraft.DeLogger.LogMessage((object)(value.Instance.Info.Metadata.Name + " Config Has Been Disabled"));
}
}
}
return false;
}
private static bool ClientSync_General()
{
if (Chainloader.PluginInfos.TryGetValue(ExtendedContainerGUID.Value, out var value))
{
Multicraft.DeLogger.LogMessage((object)$"{value.Instance.Info.Metadata.GUID} | {value.Instance.Info.Metadata.Name} | Version: {value.Instance.Info.Metadata.Version} | CLIENT DETECTED");
ConfigEntry<float> val = default(ConfigEntry<float>);
if (value.Instance.Config.TryGetEntry<float>(ExtendedConfigSection.Value, ExtendedConfigKeys.Value, ref val))
{
Multicraft.IsRunning_General = true;
Multicraft.RangeToCount = val.Value;
Multicraft.DeLogger.LogMessage((object)$"{value.Instance.Info.Metadata.GUID} | Version: {value.Instance.Info.Metadata.Version} | Range: {val.Value} | SUCCESS");
Multicraft.DeLogger.LogMessage((object)("Please setup the MultiCraft emulation to match " + value.Instance.Info.Metadata.Name + " plugin."));
return true;
}
}
return false;
}
private static float GetAvailableItems(Player localplayer, string itemname)
{
//IL_009b: 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_0065: Unknown result type (might be due to invalid IL or missing references)
int num = 0;
if (Multicraft.RangeToCount > 0f)
{
List<Container> list = new List<Container>();
CraftingStation currentCraftingStation = localplayer.GetCurrentCraftingStation();
if ((Object)(object)currentCraftingStation != (Object)null)
{
if (Multicraft.IsRunning_Valheimplus && ((Object)currentCraftingStation).name == "piece_cauldron(Clone)")
{
if (Multicraft.Valheimplus_AllowCouldron)
{
list = AccessNearbyContainer(((Component)currentCraftingStation).transform.position, Multicraft.RangeToCount);
}
}
else
{
list = AccessNearbyContainer(((Component)currentCraftingStation).transform.position, Multicraft.RangeToCount);
}
}
else
{
list = AccessNearbyContainer(((Component)localplayer).transform.position, Multicraft.RangeToCount);
}
if (list.Count > 0)
{
foreach (Container item in list)
{
num += item.GetInventory().CountItems(itemname, -1, true);
}
}
}
return ((Humanoid)localplayer).GetInventory().CountItems(itemname, -1, true) + num;
static List<Container> AccessNearbyContainer(Vector3 center, float distance)
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
DeveloperMessage("", "");
DeveloperMessage("", "");
List<Container> list2 = new List<Container>();
bool flag = true;
bool flag2 = true;
foreach (Container containerBuffer in ContainerBufferList)
{
if (!((Object)(object)containerBuffer == (Object)null))
{
Piece componentInParent3 = ((Component)containerBuffer).GetComponentInParent<Piece>();
float num2 = Vector3.Distance(center, ((Component)containerBuffer).transform.position);
if (Multicraft.IsRunning_Valheimplus)
{
bool flag3 = (Object)(object)((Component)containerBuffer).GetComponentInParent<Vagon>() != (Object)null;
bool flag4 = (Object)(object)((Component)containerBuffer).GetComponentInParent<Ship>() != (Object)null;
if ((Object)(object)componentInParent3 != (Object)null && !list2.Contains(containerBuffer))
{
flag2 = CheckPersonalAccess(containerBuffer);
if (!Multicraft.AllowContainersBuff_Warded)
{
flag2 = flag2 && PrivateArea.CheckAccess(((Component)containerBuffer).gameObject.transform.position, 0f, false, true);
}
if (num2 <= distance && flag && flag2 && (!flag3 || Multicraft.AllowContainersBuff_Wagon) && (!flag4 || Multicraft.AllowContainersBuff_Ship) && (componentInParent3.IsPlacedByPlayer() || (flag4 && Multicraft.AllowContainersBuff_Ship)))
{
list2.Add(containerBuffer);
DeveloperMessage("Allowed Container Buffer name", ((Object)containerBuffer).name);
DeveloperMessage("Allowed Container Buffer m_name", ((Object)containerBuffer).name);
}
}
}
else if (num2 <= distance && (Object)(object)componentInParent3 != (Object)null && CheckPersonalAccess(containerBuffer) && AllowContainerType_General(containerBuffer))
{
list2.Add(containerBuffer);
DeveloperMessage("Allowed Container Buffer name", ((Object)containerBuffer).name);
DeveloperMessage("Allowed Container Buffer m_name", ((Object)containerBuffer).name);
}
}
}
DeveloperMessage("==================== Got", $"{list2.Count} containers.");
DeveloperMessage("", "");
DeveloperMessage("", "");
return list2;
}
static bool AllowContainerType_General(Container container)
{
if (!CheckWardedAccess(container) && !Multicraft.AllowContainersBuff_Warded)
{
return false;
}
if (container.IsInUse() && !AllowContainers_InUse.Value)
{
ZNetView componentInParent = ((Component)container).GetComponentInParent<ZNetView>();
if ((Object)(object)componentInParent != (Object)null && !componentInParent.IsOwner())
{
return false;
}
}
Ship componentInParent2 = ((Component)container).GetComponentInParent<Ship>();
if ((Object)(object)componentInParent2 != (Object)null)
{
return Multicraft.AllowContainersBuff_Ship;
}
if ((Object)(object)container.m_wagon != (Object)null)
{
return Multicraft.AllowContainersBuff_Wagon;
}
if (container.m_name == Multicraft.Boxname[2])
{
return Multicraft.AllowContainersBuff_Wood;
}
if (container.m_name == Multicraft.Boxname[3])
{
return Multicraft.AllowContainersBuff_Reinforced;
}
if (container.m_name == Multicraft.Boxname[4])
{
return Multicraft.AllowContainersBuff_BlackMetal;
}
if (container.m_name == Multicraft.Boxname[5])
{
return Multicraft.AllowContainersBuff_Personal;
}
if (container.m_name == Multicraft.Boxname[6])
{
return Multicraft.AllowContainersBuff_Yuleklapp;
}
if (container.m_name == Multicraft.Boxname[7])
{
return Multicraft.AllowContainersBuff_ItemDrawer;
}
return false;
}
static bool CheckPersonalAccess(Container container)
{
return (bool)Multicraft.InfoContainer_CheckAccess.Invoke(container, new object[1] { Multicraft.BuffPlayerID });
}
static bool CheckWardedAccess(Container container)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
return PrivateArea.CheckAccess(((Component)container).transform.position, 0f, false, false);
}
}
private static void DeveloperMessage(string message, string value)
{
if (DeveloperConsole.Value)
{
Multicraft.DeLogger.LogMessage((object)("==================== " + message + ": " + value));
}
}
public static float ReadChainloaderConfig(string pluginGUID, string pluginSection, string pluginKey)
{
if (Chainloader.PluginInfos.TryGetValue(pluginGUID, out var value))
{
ConfigEntry<float> val = default(ConfigEntry<float>);
if (value.Instance.Config.TryGetEntry<float>(pluginSection, pluginKey, ref val))
{
Multicraft.DeLogger.LogMessage((object)$"{pluginGUID} | {pluginSection} | {pluginKey} | {val.Value} | SUCCESS");
return val.Value;
}
Multicraft.DeLogger.LogMessage((object)(pluginGUID + " | " + pluginSection + " | " + pluginKey + " | FAILED"));
}
return -1f;
}
}