using System;
using System.Diagnostics;
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 BulkPurchasePlus;
using HarmonyLib;
using UnityEngine;
using UnityEngine.EventSystems;
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("BulkPurchasePlus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BulkPurchasePlus")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a15a3d6a-6ae9-46e1-99bc-007f149c9fc0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BulkPurchasePlus
{
[BepInPlugin("com.Kalkune.BulkPurchasePlus", "BulkPurchasePlus", "1.0.1")]
public class BulkPurchasePlus : BaseUnityPlugin
{
internal static Harmony Harmony;
public static int threshold;
public static int currentMode = 1;
public static bool notificationSent = false;
public static string notificationMessage;
public static ConfigEntry<int> HardThreshold { get; set; }
public static ConfigEntry<int> StorageThreshold { get; set; }
public static ConfigEntry<int> StorageBoxThreshold { get; set; }
public static ConfigEntry<KeyboardShortcut> KeyboardShortcutDoublePrice { get; set; }
public void Awake()
{
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Expected O, but got Unknown
HardThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Threshold", "Hard Threshold Cap", 50, "Products with quantity above this number won't be ordered with Needs Only if on alternate modes.");
StorageThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Threshold", "Storage Threshold Cap", 30, "Products with quantity above this number won't be ordered with Product Storage Mode.");
StorageBoxThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Threshold", "Storage Box Threshold Cap", 4, "Products with box quantity above this number won't be ordered with Box Storage Mode.");
KeyboardShortcutDoublePrice = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Threshold", "Toggle Threshold Keybind", new KeyboardShortcut((KeyCode)114, Array.Empty<KeyCode>()), "");
threshold = HardThreshold.Value;
Harmony = new Harmony("com.Kalkune.BulkPurchasePlus");
Harmony.PatchAll();
}
public void Update()
{
//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)
KeyboardShortcut value = KeyboardShortcutDoublePrice.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
if (currentMode >= 6)
{
currentMode = 1;
}
else
{
currentMode++;
}
notificationMessage = "ThresholdToggle";
notificationSent = true;
}
}
public static int somethingsomething(NPC_Manager __instance, int productId)
{
//IL_00a6: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
if (__instance.shelvesOBJ.transform.childCount == 0)
{
return 0;
}
int num = 0;
int num2 = 0;
for (int i = 0; i < __instance.shelvesOBJ.transform.childCount; i++)
{
int[] productInfoArray = ((Component)__instance.shelvesOBJ.transform.GetChild(i)).GetComponent<Data_Container>().productInfoArray;
int num3 = productInfoArray.Length / 2;
for (int j = 0; j < num3; j++)
{
int num4 = productInfoArray[j * 2];
if (num4 == productId)
{
num++;
}
Data_Container component = ((Component)__instance.shelvesOBJ.transform.GetChild(i)).GetComponent<Data_Container>();
GameObject val = component.productlistComponent.productPrefabs[productId];
Vector3 size = val.GetComponent<BoxCollider>().size;
bool isStackable = val.GetComponent<Data_Product>().isStackable;
int num5 = Mathf.FloorToInt(component.shelfLength / (size.x * 1.1f));
num5 = Mathf.Clamp(num5, 1, 100);
int num6 = Mathf.FloorToInt(component.shelfWidth / (size.z * 1.1f));
num6 = Mathf.Clamp(num6, 1, 100);
int num7 = num5 * num6;
if (isStackable)
{
int num8 = Mathf.FloorToInt(component.shelfHeight / (size.y * 1.1f));
num8 = Mathf.Clamp(num8, 1, 100);
num7 = num5 * num6 * num8;
}
num2 += num7 * num;
num = 0;
}
}
return num2;
}
}
}
namespace BuyAllButton.Patches
{
[HarmonyPatch(typeof(GameCanvas))]
internal class NotificationHandler
{
[HarmonyPatch(typeof(LocalizationManager))]
internal class LocalizationHandler
{
[HarmonyPatch("GetLocalizationString")]
[HarmonyPrefix]
public static bool noLocalization_Prefix(ref string key, ref string __result)
{
if (key[0] == '`')
{
__result = key.Substring(1);
return false;
}
return true;
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void NotificationHandler_Postfix(GameCanvas __instance, ref bool ___inCooldown)
{
if (global::BulkPurchasePlus.BulkPurchasePlus.notificationSent)
{
___inCooldown = false;
global::BulkPurchasePlus.BulkPurchasePlus.notificationSent = false;
string text = "`";
switch (global::BulkPurchasePlus.BulkPurchasePlus.currentMode)
{
case 1:
text += "Threshold: Shelves Filled";
break;
case 2:
text = text + "Threshold: " + global::BulkPurchasePlus.BulkPurchasePlus.HardThreshold.Value + " On Shelf";
break;
case 3:
text += "Threshold: Shelf Mixed";
break;
case 4:
text = text + "Threshold: " + global::BulkPurchasePlus.BulkPurchasePlus.StorageThreshold.Value + " Product In Storage";
break;
case 5:
text = text + "Threshold: " + global::BulkPurchasePlus.BulkPurchasePlus.StorageBoxThreshold.Value + " Boxes In Storage";
break;
case 6:
text += "Threshold: Storage Mixed";
break;
}
__instance.CreateCanvasNotification(text);
}
}
}
[HarmonyPatch(typeof(PlayerNetwork), "OnStartClient")]
public class AddButton
{
public static bool Prefix()
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Expected O, but got Unknown
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Expected O, but got Unknown
GameObject val = GameObject.Find("Buttons_Bar");
if ((Object)(object)val == (Object)null)
{
return true;
}
if ((Object)(object)val.transform.Find("AddAllToCartButton") == (Object)null)
{
GameObject val2 = CreateButton(val, "AddAllToCartButton", -450f, 110f);
AddButtonEvents(val2.GetComponent<Button>(), val2.GetComponent<Image>(), new UnityAction(OnAddAllToCartButtonClick));
}
if ((Object)(object)val.transform.Find("RemoveAllFromCartButton") == (Object)null)
{
GameObject val3 = CreateButton(val, "RemoveAllFromCartButton", 425f, 110f);
AddButtonEvents(val3.GetComponent<Button>(), val3.GetComponent<Image>(), new UnityAction(OnRemoveAllFromCartButtonClick));
}
if ((Object)(object)val.transform.Find("NeedsOnlyButton") == (Object)null)
{
GameObject val4 = CreateButton(val, "NeedsOnlyButton", -325f, 55f);
AddButtonEvents(val4.GetComponent<Button>(), val4.GetComponent<Image>(), new UnityAction(OnNeedsOnlyButtonClick));
}
return true;
}
private static GameObject CreateButton(GameObject parent, string name, float xOffset, float width)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: 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)
GameObject val = new GameObject(name);
RectTransform val2 = val.AddComponent<RectTransform>();
Button val3 = val.AddComponent<Button>();
Image val4 = val.AddComponent<Image>();
val.transform.SetParent(parent.transform, false);
val2.sizeDelta = new Vector2(width, 35f);
val2.anchoredPosition = new Vector2(xOffset, 612f);
val2.anchorMin = new Vector2(0.5f, 0.5f);
val2.anchorMax = new Vector2(0.5f, 0.5f);
val2.pivot = new Vector2(0.5f, 0.5f);
GameObject val5 = new GameObject("ButtonText");
val5.transform.SetParent(val.transform, false);
RectTransform val6 = val5.AddComponent<RectTransform>();
Text val7 = val5.AddComponent<Text>();
val6.sizeDelta = val2.sizeDelta;
val6.anchoredPosition = Vector2.zero;
val7.text = ((name == "AddAllToCartButton") ? "Add All to Cart" : ((name == "RemoveAllFromCartButton") ? "Remove All from Cart" : "Needs Only Button"));
val7.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
val7.alignment = (TextAnchor)4;
((Graphic)val7).color = Color.black;
val7.fontStyle = (FontStyle)1;
return val;
}
private static void AddButtonEvents(Button button, Image buttonImage, UnityAction onClickAction)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: 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_0060: Expected O, but got Unknown
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
EventTrigger val = ((Component)button).gameObject.AddComponent<EventTrigger>();
Entry val2 = new Entry
{
eventID = (EventTriggerType)0
};
((UnityEvent<BaseEventData>)(object)val2.callback).AddListener((UnityAction<BaseEventData>)delegate
{
OnHoverEnter(buttonImage);
});
val.triggers.Add(val2);
Entry val3 = new Entry
{
eventID = (EventTriggerType)1
};
((UnityEvent<BaseEventData>)(object)val3.callback).AddListener((UnityAction<BaseEventData>)delegate
{
OnHoverExit(buttonImage);
});
val.triggers.Add(val3);
((UnityEvent)button.onClick).AddListener((UnityAction)delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if (((Graphic)buttonImage).color != Color.white)
{
onClickAction.Invoke();
}
});
}
private static void OnHoverEnter(Image buttonImage)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
((Graphic)buttonImage).color = new Color(1f / 51f, 0.52156866f, 0.8156863f);
}
private static void OnHoverExit(Image buttonImage)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
((Graphic)buttonImage).color = Color.white;
}
private static void OnAddAllToCartButtonClick()
{
ProductListing val = Object.FindFirstObjectByType<ProductListing>();
ManagerBlackboard val2 = Object.FindFirstObjectByType<ManagerBlackboard>();
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
{
return;
}
GameObject[] productPrefabs = val.productPrefabs;
foreach (GameObject val3 in productPrefabs)
{
Data_Product component = val3.GetComponent<Data_Product>();
if ((Object)(object)component != (Object)null && val.unlockedProductTiers[component.productTier])
{
float num = component.basePricePerUnit * (float)component.maxItemsPerBox;
num *= val.tierInflation[component.productTier];
float num2 = Mathf.Round(num * 100f) / 100f;
val2.AddShoppingListProduct(component.productID, num2);
}
}
}
private static void OnRemoveAllFromCartButtonClick()
{
ManagerBlackboard val = Object.FindFirstObjectByType<ManagerBlackboard>();
if (!((Object)(object)val == (Object)null))
{
int childCount = val.shoppingListParent.transform.childCount;
for (int num = childCount - 1; num >= 0; num--)
{
val.RemoveShoppingListProduct(num);
}
}
}
private static void OnNeedsOnlyButtonClick()
{
ProductListing val = Object.FindFirstObjectByType<ProductListing>();
ManagerBlackboard val2 = Object.FindFirstObjectByType<ManagerBlackboard>();
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
{
return;
}
GameObject[] productPrefabs = val.productPrefabs;
foreach (GameObject val3 in productPrefabs)
{
Data_Product component = val3.GetComponent<Data_Product>();
if ((Object)(object)component != (Object)null && val.unlockedProductTiers[component.productTier])
{
int productID = component.productID;
bool flag = false;
int[] productsExistences = val2.GetProductsExistences(productID);
int num = 0;
int[] array = productsExistences;
foreach (int num2 in array)
{
num += num2;
}
if (CheckOrderAviablility(num, productID, global::BulkPurchasePlus.BulkPurchasePlus.currentMode, component))
{
float num3 = component.basePricePerUnit * (float)component.maxItemsPerBox;
num3 *= val.tierInflation[component.productTier];
float num4 = Mathf.Round(num3 * 100f) / 100f;
val2.AddShoppingListProduct(productID, num4);
}
}
}
}
public static bool CheckOrderAviablility(int totalExistence, int productID, int orderNumber, Data_Product productComponent)
{
bool result = false;
switch (orderNumber)
{
case 1:
if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID))
{
result = true;
}
break;
case 2:
if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.threshold)
{
result = true;
}
break;
case 3:
if (CheckOrderAviablility(totalExistence, productID, 1, productComponent) && CheckOrderAviablility(totalExistence, productID, 2, productComponent))
{
result = true;
}
break;
case 4:
if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID) + global::BulkPurchasePlus.BulkPurchasePlus.StorageThreshold.Value)
{
result = true;
}
break;
case 5:
if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID) + global::BulkPurchasePlus.BulkPurchasePlus.StorageBoxThreshold.Value * productComponent.maxItemsPerBox)
{
result = true;
}
break;
case 6:
if (CheckOrderAviablility(totalExistence, productID, 4, productComponent) && CheckOrderAviablility(totalExistence, productID, 5, productComponent))
{
result = true;
}
break;
}
return result;
}
}
}