using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Windows.Forms;
using BepInEx;
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: AssemblyTitle("AutoOrderV2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoOrderV2")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cbd83831-7714-4393-95d5-1f32fce57cd3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AutoOrderV2
{
public class Form1 : Form
{
private IContainer components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
((Form)this).Dispose(disposing);
}
private void InitializeComponent()
{
components = new Container();
((ContainerControl)this).AutoScaleMode = (AutoScaleMode)1;
((Form)this).ClientSize = new Size(800, 450);
((Control)this).Text = "Form1";
}
}
internal static class Program
{
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run((Form)(object)new Form1());
}
}
}
namespace AutoOrderV2.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
ResourceManager resourceManager = new ResourceManager("AutoOrderV2.Properties.Resources", typeof(Resources).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal Resources()
{
}
}
[CompilerGenerated]
[GeneratedCode("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed class Settings : ApplicationSettingsBase
{
private static Settings defaultInstance = (Settings)(object)SettingsBase.Synchronized((SettingsBase)(object)new Settings());
public static Settings Default => defaultInstance;
}
}
namespace STSmartListMod
{
[HarmonyPatch(typeof(ManagerBlackboard))]
internal static class BlackboardSmartButtonPatch
{
private static readonly BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
private static bool _buttonsCreated;
[HarmonyPostfix]
[HarmonyPatch("CreateUIShopItem", new Type[]
{
typeof(int),
typeof(ProductListing),
typeof(float),
typeof(string)
})]
private static void CreateUIShopItem_Postfix(ManagerBlackboard __instance, int productIndex)
{
if ((Object)(object)__instance == (Object)null || _buttonsCreated)
{
return;
}
try
{
GameObject val = GameObject.Find("Buttons_Bar");
if ((Object)(object)val == (Object)null)
{
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogWarning((object)"[STSmartList] Buttons_Bar not found – cannot create Smart buttons.");
}
}
else if ((Object)(object)val.transform.Find("SmartAddButton") == (Object)null && (Object)(object)val.transform.Find("FullReorderButton") == (Object)null)
{
CreateTopButton(val, "SmartAddButton", "Smart Add", -450f, 160f, RunSmartAddForAllVisible);
CreateTopButton(val, "FullReorderButton", "Full reorder", -275f, 175f, RunFullReorderForAllProducts);
_buttonsCreated = true;
ManualLogSource log2 = Plugin.Log;
if (log2 != null)
{
log2.LogInfo((object)"[STSmartList] Smart Add & Full reorder buttons created.");
}
}
}
catch (Exception arg)
{
ManualLogSource log3 = Plugin.Log;
if (log3 != null)
{
log3.LogError((object)$"[STSmartList] Error creating top buttons: {arg}");
}
}
}
private static void CreateTopButton(GameObject parent, string name, string label, float xOffset, float width, Action onClick)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: 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_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Expected O, but got Unknown
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Expected O, but got Unknown
GameObject val = new GameObject(name);
val.transform.SetParent(parent.transform, false);
RectTransform val2 = val.AddComponent<RectTransform>();
val2.sizeDelta = new Vector2(width, 35f);
val2.anchorMin = new Vector2(0.5f, 0.5f);
val2.anchorMax = new Vector2(0.5f, 0.5f);
val2.pivot = new Vector2(0.5f, 0.5f);
val2.anchoredPosition = new Vector2(xOffset, 612f);
Image val3 = val.AddComponent<Image>();
((Graphic)val3).color = Color.white;
Button val4 = val.AddComponent<Button>();
((Selectable)val4).transition = (Transition)1;
ColorBlock colors = ((Selectable)val4).colors;
((ColorBlock)(ref colors)).normalColor = Color.white;
((ColorBlock)(ref colors)).highlightedColor = new Color(1f / 51f, 0.52156866f, 0.8156863f);
((ColorBlock)(ref colors)).pressedColor = new Color(0.8f, 0.8f, 0.8f);
((ColorBlock)(ref colors)).selectedColor = ((ColorBlock)(ref colors)).normalColor;
((ColorBlock)(ref colors)).disabledColor = new Color(0.7f, 0.7f, 0.7f);
((Selectable)val4).colors = colors;
GameObject val5 = new GameObject("Label");
val5.transform.SetParent(val.transform, false);
RectTransform val6 = val5.AddComponent<RectTransform>();
val6.anchorMin = Vector2.zero;
val6.anchorMax = Vector2.one;
val6.offsetMin = Vector2.zero;
val6.offsetMax = Vector2.zero;
TextMeshProUGUI val7 = val5.AddComponent<TextMeshProUGUI>();
((TMP_Text)val7).text = label;
((TMP_Text)val7).alignment = (TextAlignmentOptions)514;
((TMP_Text)val7).enableAutoSizing = true;
((Graphic)val7).color = Color.black;
((UnityEventBase)val4.onClick).RemoveAllListeners();
((UnityEvent)val4.onClick).AddListener((UnityAction)delegate
{
try
{
onClick?.Invoke();
}
catch (Exception arg)
{
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogError((object)$"[STSmartList] Exception in {name} click: {arg}");
}
}
});
}
private static void RunSmartAddForAllVisible()
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
GameData instance = GameData.Instance;
ManagerBlackboard val = ((instance != null) ? ((Component)instance).GetComponent<ManagerBlackboard>() : null);
if ((Object)(object)val == (Object)null)
{
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogWarning((object)"[STSmartList] ManagerBlackboard not found for Smart Add.");
}
return;
}
object? obj = typeof(ManagerBlackboard).GetField("shopItemsParent", Flags)?.GetValue(val);
GameObject val2 = (GameObject)((obj is GameObject) ? obj : null);
if ((Object)(object)val2 == (Object)null)
{
return;
}
foreach (Transform item in val2.transform)
{
Transform val3 = item;
Data_Product component = ((Component)val3).GetComponent<Data_Product>();
if ((Object)(object)component == (Object)null)
{
continue;
}
int productID = component.productID;
try
{
RunSmartAddLogic(val, val3, productID);
}
catch (Exception arg)
{
ManualLogSource log2 = Plugin.Log;
if (log2 != null)
{
log2.LogError((object)$"[STSmartList] Smart Add error for product {productID}: {arg}");
}
}
}
}
private static void RunFullReorderForAllProducts()
{
GameData instance = GameData.Instance;
ManagerBlackboard val = ((instance != null) ? ((Component)instance).GetComponent<ManagerBlackboard>() : null);
if ((Object)(object)val == (Object)null)
{
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogWarning((object)"[STSmartList] ManagerBlackboard not found for Full reorder.");
}
return;
}
ProductListing component = ((Component)val).GetComponent<ProductListing>();
if ((Object)(object)component == (Object)null || component.availableProducts == null)
{
ManualLogSource log2 = Plugin.Log;
if (log2 != null)
{
log2.LogWarning((object)"[STSmartList] ProductListing / availableProducts missing for Full reorder.");
}
return;
}
foreach (int availableProduct in component.availableProducts)
{
try
{
RunSmartAddLogic(val, null, availableProduct);
}
catch (Exception arg)
{
ManualLogSource log3 = Plugin.Log;
if (log3 != null)
{
log3.LogError((object)$"[STSmartList] Full reorder error for product {availableProduct}: {arg}");
}
}
}
}
private static void RunSmartAddLogic(ManagerBlackboard manager, Transform row, int productId)
{
//IL_0266: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Expected O, but got Unknown
if ((Object)(object)manager == (Object)null)
{
return;
}
if (productId == 322)
{
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogInfo((object)"[STSmartList] Skipping product 322 (Candy Bucket: Pumpkin) in smart logic.");
}
return;
}
int num = 0;
float num2 = 0f;
int num3 = 0;
if (typeof(ManagerBlackboard).GetMethod("GetProductsExistences", Flags)?.Invoke(manager, new object[1] { productId }) is int[] array && array.Length >= 3)
{
int num4 = array[1];
int num5 = array[2];
num = num4 + num5;
}
int num6 = 1;
ProductListing component = ((Component)manager).GetComponent<ProductListing>();
if ((Object)(object)component != (Object)null && component.productPrefabs != null && productId >= 0 && productId < component.productPrefabs.Length && (Object)(object)component.productPrefabs[productId] != (Object)null)
{
Data_Product component2 = component.productPrefabs[productId].GetComponent<Data_Product>();
if ((Object)(object)component2 != (Object)null && component2.maxItemsPerBox > 0)
{
num6 = component2.maxItemsPerBox;
}
}
if (num6 <= 0)
{
num6 = 1;
}
if (num > 0)
{
num2 = (float)num / (float)num6;
num2 = Mathf.Round(num2 * 100f) / 100f;
num3 = Mathf.RoundToInt(num2);
}
else
{
num2 = 0f;
num3 = 0;
}
int num7 = 0;
num7 = ((num2 <= 0.0001f) ? 2 : ((num2 <= 1.0001f) ? 1 : 0));
ManualLogSource log2 = Plugin.Log;
if (log2 != null)
{
log2.LogInfo((object)$"[STSmartList] Product {productId}: units={num}, boxesFloat={num2}, approxBoxes={num3}, desiredBoxes={num7}");
}
if (num7 <= 0)
{
return;
}
object? obj = typeof(ManagerBlackboard).GetField("shoppingListParent", Flags)?.GetValue(manager);
GameObject val = (GameObject)((obj is GameObject) ? obj : null);
int num8 = 0;
if ((Object)(object)val != (Object)null)
{
foreach (Transform item in val.transform)
{
Transform val2 = item;
InteractableData component3 = ((Component)val2).GetComponent<InteractableData>();
if ((Object)(object)component3 != (Object)null && component3.thisSkillIndex == productId)
{
num8++;
}
}
}
ManualLogSource log3 = Plugin.Log;
if (log3 != null)
{
log3.LogInfo((object)$"[STSmartList] Product {productId}: currentOnList={num8}, desired={num7}");
}
if (num8 >= num7)
{
return;
}
int num9 = num7 - num8;
float result = 0f;
MethodInfo method = typeof(ManagerBlackboard).GetMethod("PricePerBoxRetrieve", Flags);
if (method != null)
{
result = (float)method.Invoke(manager, new object[1] { productId });
}
else if ((Object)(object)row != (Object)null)
{
Transform obj2 = row.Find("BoxPrice");
object obj3;
if (obj2 == null)
{
obj3 = null;
}
else
{
TextMeshProUGUI component4 = ((Component)obj2).GetComponent<TextMeshProUGUI>();
obj3 = ((component4 != null) ? ((TMP_Text)component4).text : null);
}
string text = (string)obj3;
if (!string.IsNullOrEmpty(text) && text.Length > 2)
{
float.TryParse(text.Substring(2), out result);
}
}
MethodInfo method2 = typeof(ManagerBlackboard).GetMethod("AddShoppingListProduct", Flags);
if (method2 == null)
{
ManualLogSource log4 = Plugin.Log;
if (log4 != null)
{
log4.LogWarning((object)"[STSmartList] AddShoppingListProduct method not found.");
}
return;
}
for (int i = 0; i < num9; i++)
{
method2.Invoke(manager, new object[2] { productId, result });
}
}
}
[BepInPlugin("com.samle.STSmartList", "ST Smart Shopping List", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
internal static ConfigEntry<int> Threshold;
private Harmony _harmony;
private void Awake()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Threshold = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BoxesThreshold", 2, "If approx. boxes in storage for a product (using the same logic as the ordering device) are < this value, the Smart+ button adds one box to the shopping list.");
_harmony = new Harmony("com.samle.STSmartList");
_harmony.PatchAll();
Log.LogInfo((object)"[STSmartList] Plugin loaded successfully.");
}
}
}