using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Jotunn.Managers;
using TMPro;
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("BetterSplitDialog")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterSplitDialog")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8a1df304-05f0-44a3-9919-55aa56f614c1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BetterSplitDialog
{
[BepInPlugin("Turbero.BetterSplitDialog", "Better SplitDialog", "1.0.4")]
public class BetterSplitDialog : BaseUnityPlugin
{
public const string GUID = "Turbero.BetterSplitDialog";
public const string NAME = "Better SplitDialog";
public const string VERSION = "1.0.4";
private Harmony harmony;
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
harmony = new Harmony("Turbero.BetterSplitDialog");
harmony.PatchAll();
}
private void OnDestroy()
{
harmony.UnpatchSelf();
}
}
}
namespace BetterSplitDialog.Dialog
{
[HarmonyPatch(typeof(InventoryGui), "Awake")]
[HarmonyPatch]
public class SplitDialogExtraButtonsPatch
{
private static void Postfix(InventoryGui __instance)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: 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_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
Button splitOkButton = InventoryGui.instance.m_splitOkButton;
Transform parent = ((Component)splitOkButton).transform.parent;
Button val = createButton(splitOkButton, "PickerButton1", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-120f, 160f), 0);
Button val2 = createButton(splitOkButton, "PickerButtonPct20", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-120f, 160f), 0);
Button val3 = createButton(splitOkButton, "PickerButtonPct40", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-120f, 124f), 0);
Button val4 = createButton(splitOkButton, "PickerButtonPct60", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-65f, 160f), 0);
Button val5 = createButton(splitOkButton, "PickerButtonPct80", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-65f, 124f), 0);
Button val6 = createButton(splitOkButton, "PickerButtonPctMin", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-100f, 58f), 0);
Button val7 = createButton(splitOkButton, "PickerButtonPctMinus1", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-50f, 58f), 0);
Button val8 = createButton(splitOkButton, "PickerButtonPct50", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(0f, 58f), 0);
Button val9 = createButton(splitOkButton, "PickerButtonPctPlus1", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(50f, 58f), 0);
Button val10 = createButton(splitOkButton, "PickerButtonPctMax", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(100f, 58f), 0);
Transform transform = ((Component)InventoryGui.instance.m_splitCancelButton).transform;
((RectTransform)((transform is RectTransform) ? transform : null)).anchoredPosition = new Vector2(-90f, 16f);
Transform transform2 = ((Component)InventoryGui.instance.m_splitOkButton).transform;
((RectTransform)((transform2 is RectTransform) ? transform2 : null)).anchoredPosition = new Vector2(90f, 16f);
}
private static Button createButton(Button copy, string name, Transform parent, Vector2 sizeDetlta, Vector2 anchoredPosition, int quantity)
{
//IL_001e: 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)
GameObject val = Object.Instantiate<GameObject>(((Component)copy).gameObject, parent);
((Object)val).name = name;
RectTransform component = val.GetComponent<RectTransform>();
component.sizeDelta = sizeDetlta;
component.anchoredPosition = anchoredPosition;
TMP_Text componentInChildren = val.GetComponentInChildren<TMP_Text>();
componentInChildren.text = quantity.ToString();
return val.GetComponent<Button>();
}
}
[HarmonyPatch]
public class SplitDialogExtraButtonsUpdatePatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(InventoryGui), "ShowSplitDialog", (Type[])null, (Type[])null);
}
private static void Postfix(ref InventoryGui __instance, ref ItemData ___m_splitItem, ref Inventory ___m_splitInventory, ItemData item, Inventory __1)
{
if (!((Object)(object)GameObject.Find("PickerButton1") == (Object)null))
{
___m_splitItem = item;
___m_splitInventory = __1;
int stack = item.m_stack;
InputField component = SplitDialogLoadPatch.quantityInputField.GetComponent<InputField>();
component.text = "";
component.characterLimit = stack.ToString().Length;
updateTextAndEvent("PickerButtonPct20", ___m_splitInventory, ___m_splitItem, Mathf.CeilToInt((float)item.m_stack * 0.2f));
updateTextAndEvent("PickerButtonPct40", ___m_splitInventory, ___m_splitItem, Mathf.CeilToInt((float)item.m_stack * 0.4f));
updateTextAndEvent("PickerButtonPct60", ___m_splitInventory, ___m_splitItem, Mathf.CeilToInt((float)item.m_stack * 0.6f));
updateTextAndEvent("PickerButtonPct80", ___m_splitInventory, ___m_splitItem, Mathf.CeilToInt((float)item.m_stack * 0.8f));
updateTextAndEvent("PickerButtonPctMin", ___m_splitInventory, ___m_splitItem, 1, "Min");
updateTextAndEvent("PickerButtonPctMinus1", ___m_splitInventory, ___m_splitItem, stack / 2 - 1, "-1");
updateTextAndEvent("PickerButtonPct50", ___m_splitInventory, ___m_splitItem, stack / 2, "50%");
updateTextAndEvent("PickerButtonPctPlus1", ___m_splitInventory, ___m_splitItem, stack / 2 + 1, "+1");
updateTextAndEvent("PickerButtonPctMax", ___m_splitInventory, ___m_splitItem, stack, "Max");
}
}
private static void updateTextAndEvent(string objectName, Inventory m_splitInventory, ItemData m_splitItem, int newQuantity, string btnText = null)
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
GameObject val = GameObject.Find(objectName);
TMP_Text componentInChildren = val.GetComponentInChildren<TMP_Text>();
componentInChildren.text = ((btnText != null) ? btnText : newQuantity.ToString());
Button component = val.GetComponent<Button>();
component.onClick = new ButtonClickedEvent();
((UnityEvent)component.onClick).AddListener((UnityAction)delegate
{
if (btnText == null)
{
Type type = ((object)InventoryGui.instance).GetType();
MethodInfo method = type.GetMethod("SetupDragItem", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(InventoryGui.instance, new object[3] { m_splitItem, m_splitInventory, newQuantity });
FieldInfo field = type.GetField("m_splitItem", BindingFlags.Instance | BindingFlags.NonPublic);
field.SetValue(InventoryGui.instance, null);
FieldInfo field2 = type.GetField("m_splitInventory", BindingFlags.Instance | BindingFlags.NonPublic);
field2.SetValue(InventoryGui.instance, null);
((Component)InventoryGui.instance.m_splitPanel).gameObject.SetActive(false);
}
else
{
Slider splitSlider = InventoryGui.instance.m_splitSlider;
if (btnText == "Min")
{
splitSlider.value = 1f;
}
else if (btnText == "-1")
{
splitSlider.value = Math.Max(splitSlider.value - 1f, 1f);
}
else if (btnText == "50%")
{
splitSlider.value = (int)Math.Floor(splitSlider.maxValue / 2f + 0.5f);
}
else if (btnText == "+1")
{
splitSlider.value = Math.Min(splitSlider.value + 1f, splitSlider.maxValue);
}
else if (btnText == "Max")
{
splitSlider.value = splitSlider.maxValue;
}
}
});
}
}
[HarmonyPatch(typeof(InventoryGui), "Awake")]
[HarmonyPatch]
public class SplitDialogLoadPatch
{
public static GameObject quantityInputField;
public static bool InputFieldFocused;
private static void Postfix(InventoryGui __instance)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: 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_00d4: Expected O, but got Unknown
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Expected O, but got Unknown
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Expected O, but got Unknown
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)quantityInputField != (Object)null)
{
return;
}
Transform transform = ((Component)((Component)InventoryGui.instance.m_splitPanel).transform.Find("win_bkg")).transform;
quantityInputField = GUIManager.Instance.CreateInputField(transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(110f, 18f), (ContentType)2, "...", 16, 100f, 30f);
InputField component = quantityInputField.GetComponent<InputField>();
((UnityEvent<string>)(object)component.onEndEdit).AddListener((UnityAction<string>)delegate(string quantityText)
{
if (int.TryParse(quantityText, out var result))
{
InventoryGui.instance.m_splitSlider.value = Mathf.Clamp(result, 1, (int)InventoryGui.instance.m_splitSlider.maxValue);
}
InputFieldFocused = false;
});
EventTrigger val = quantityInputField.AddComponent<EventTrigger>();
Entry val2 = new Entry
{
eventID = (EventTriggerType)9
};
((UnityEvent<BaseEventData>)(object)val2.callback).AddListener((UnityAction<BaseEventData>)delegate
{
InputFieldFocused = true;
});
val.triggers.Add(val2);
Entry val3 = new Entry
{
eventID = (EventTriggerType)10
};
((UnityEvent<BaseEventData>)(object)val3.callback).AddListener((UnityAction<BaseEventData>)delegate
{
InputFieldFocused = false;
});
val.triggers.Add(val3);
GameObject val4 = new GameObject("SplitQuantityTitle", new Type[1] { typeof(TextMeshProUGUI) });
val4.transform.SetParent(transform, false);
TextMeshProUGUI component2 = val4.GetComponent<TextMeshProUGUI>();
((TMP_Text)component2).text = "$inventory_pickup...";
((TMP_Text)component2).fontSize = 22f;
((TMP_Text)component2).fontStyle = (FontStyles)0;
((Graphic)component2).color = new Color(1f, 0.7176f, 0.3603f, 1f);
((TMP_Text)component2).alignment = (TextAlignmentOptions)514;
RectTransform component3 = val4.GetComponent<RectTransform>();
component3.anchoredPosition = new Vector2(110f, 50f);
}
}
[HarmonyPatch(typeof(InventoryGui), "Update")]
public class InventoryGuiUpdateSplitDialogLoadPatch
{
[HarmonyPrefix]
public static bool Prefix()
{
return !SplitDialogLoadPatch.InputFieldFocused;
}
}
}