using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
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
{
public class ControllerUtils
{
public static void BindGamePad(Transform buttonGo, KeyCode gamepadKeyCode, Vector2 hintAnchoredPosition, InventoryGui inventoryGui = null)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
UIGamePad val = null;
if (((Component)buttonGo).TryGetComponent<UIGamePad>(ref val))
{
string text = KeyCodeToString(gamepadKeyCode);
if (ZInput.instance != null)
{
((TMP_Text)val.m_hint.GetComponentInChildren<TextMeshProUGUI>(true)).text = ZInput.instance.GetBoundKeyString(text, true);
}
else
{
ZInput.Initialize();
TextMeshProUGUI componentInChildren = val.m_hint.GetComponentInChildren<TextMeshProUGUI>(true);
ZInput instance = ZInput.instance;
((TMP_Text)componentInChildren).text = ((instance != null) ? instance.GetBoundKeyString(text, true) : null);
}
RectTransform component = val.m_hint.GetComponent<RectTransform>();
if (hintAnchoredPosition != Vector2.zero || component.anchoredPosition != Vector2.zero)
{
val.m_hint.GetComponent<RectTransform>().anchoredPosition = hintAnchoredPosition;
}
val.m_zinputKey = text;
val.m_keyCode = gamepadKeyCode;
UIGroupHandler value = default(UIGroupHandler);
if ((Object)(object)inventoryGui != (Object)null && ((Component)inventoryGui.m_crafting).TryGetComponent<UIGroupHandler>(ref value))
{
SetPrivateValue(val, "m_group", value);
}
}
}
private static void SetPrivateValue(object obj, string name, object value, BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic)
{
obj.GetType().GetField(name, bindingAttr)?.SetValue(obj, value);
}
public static string KeyCodeToString(KeyCode keyCode)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Expected I4, but got Unknown
int num = keyCode - 330;
if (1 == 0)
{
}
string result = num switch
{
1 => "JoyButtonB",
2 => "JoyButtonX",
3 => "JoyButtonY",
4 => "JoyLBumper",
5 => "JoyRBumper",
6 => "JoyBack",
7 => "JoyStart",
8 => "JoyLStick",
9 => "JoyRStick",
10 => "JoyDPadLeft",
11 => "JoyDPadRight",
12 => "JoyDPadUp",
13 => "JoyDPadDown",
14 => "JoyLTrigger",
15 => "JoyRTrigger",
16 => "JoyButtonA",
17 => "JoyButtonB",
18 => "JoyButtonX",
19 => "JoyButtonY",
_ => "JoyButtonA",
};
if (1 == 0)
{
}
return result;
}
}
[BepInPlugin("Turbero.BetterSplitDialog", "Better SplitDialog", "1.1.0")]
public class BetterSplitDialog : BaseUnityPlugin
{
private const string GUID = "Turbero.BetterSplitDialog";
private const string NAME = "Better SplitDialog";
private const string VERSION = "1.1.0";
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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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)
//IL_00b3: 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_00d6: 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)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: 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_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: 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)
//IL_0260: Unknown result type (might be due to invalid IL or missing references)
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_033a: Unknown result type (might be due to invalid IL or missing references)
//IL_0363: 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, 170f), (KeyCode)48, new Vector2(-22f, 22f));
Button val2 = createButton(splitOkButton, "PickerButtonPct20", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-120f, 170f), (KeyCode)344, new Vector2(-22f, 22f));
Button val3 = createButton(splitOkButton, "PickerButtonPct40", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-120f, 134f), (KeyCode)338, new Vector2(-22f, -22f));
Button val4 = createButton(splitOkButton, "PickerButtonPct60", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-65f, 170f), (KeyCode)343, new Vector2(-22f, 22f));
Button val5 = createButton(splitOkButton, "PickerButtonPct80", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-65f, 134f), (KeyCode)339, new Vector2(-22f, -22f));
Button val6 = createButton(splitOkButton, "PickerButtonPctMax", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(100f, 58f), (KeyCode)341, new Vector2(30f, 0f));
Button val7 = createButton(splitOkButton, "PickerButtonPctPlus1", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(50f, 58f), (KeyCode)337, new Vector2(0f, -22f));
Button val8 = createButton(splitOkButton, "PickerButtonPct50", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(0f, 58f), (KeyCode)332, new Vector2(0f, -22f));
Button val9 = createButton(splitOkButton, "PickerButtonPctMin", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-100f, 58f), (KeyCode)340, new Vector2(-30f, 0f));
Button val10 = createButton(splitOkButton, "PickerButtonPctMinus1", ((Component)parent).transform, new Vector2(50f, 35f), new Vector2(-50f, 58f), (KeyCode)336, new Vector2(0f, -22f));
Transform transform = ((Component)InventoryGui.instance.m_splitCancelButton).transform;
((RectTransform)((transform is RectTransform) ? transform : null)).anchoredPosition = new Vector2(-90f, 16f);
ControllerUtils.BindGamePad(((Component)InventoryGui.instance.m_splitCancelButton).transform, (KeyCode)331, new Vector2(-75f, 20f), InventoryGui.instance);
Transform transform2 = ((Component)InventoryGui.instance.m_splitOkButton).transform;
((RectTransform)((transform2 is RectTransform) ? transform2 : null)).anchoredPosition = new Vector2(90f, 16f);
ControllerUtils.BindGamePad(((Component)InventoryGui.instance.m_splitOkButton).transform, (KeyCode)330, new Vector2(75f, 20f), InventoryGui.instance);
}
private static Button createButton(Button copy, string name, Transform parent, Vector2 sizeDelta, Vector2 anchoredPosition, KeyCode hintGamepad, Vector2 hintGamepadAnchoredPosition)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
GameObject val = Object.Instantiate<GameObject>(((Component)copy).gameObject, parent);
((Object)val).name = name;
ControllerUtils.BindGamePad(val.transform, hintGamepad, hintGamepadAnchoredPosition, InventoryGui.instance);
RectTransform component = val.GetComponent<RectTransform>();
component.sizeDelta = sizeDelta;
component.anchoredPosition = anchoredPosition;
TMP_Text componentInChildren = val.GetComponentInChildren<TMP_Text>();
componentInChildren.text = "0";
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;
Transform val = ((Component)InventoryGui.instance).transform.Find("root/SplitDialog/win_bkg");
bool flag = Chainloader.PluginInfos.ContainsKey("Azumatt.CurrencyPocket");
((Component)val.Find("PickerButtonPct20")).gameObject.SetActive(!flag);
((Component)val.Find("PickerButtonPct40")).gameObject.SetActive(item.m_stack != 2 && !flag);
((Component)val.Find("PickerButtonPct60")).gameObject.SetActive(item.m_stack != 3 && !flag);
((Component)val.Find("PickerButtonPct80")).gameObject.SetActive(item.m_stack != 2 && !flag);
updateTextAndEvent("PickerButtonPct20", ___m_splitInventory, ___m_splitItem, Mathf.CeilToInt((float)item.m_stack * 0.2f));
if (((Component)val.Find("PickerButtonPct40")).gameObject.activeSelf)
{
updateTextAndEvent("PickerButtonPct40", ___m_splitInventory, ___m_splitItem, Mathf.CeilToInt((float)item.m_stack * 0.4f));
}
if (((Component)val.Find("PickerButtonPct60")).gameObject.activeSelf)
{
updateTextAndEvent("PickerButtonPct60", ___m_splitInventory, ___m_splitItem, Mathf.CeilToInt((float)item.m_stack * 0.6f));
}
if (((Component)val.Find("PickerButtonPct80")).gameObject.activeSelf)
{
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 amountToPick, string btnText = null)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
GameObject val = GameObject.Find(objectName);
if ((Object)(object)val == (Object)null)
{
return;
}
TMP_Text componentInChildren = val.GetComponentInChildren<TMP_Text>();
componentInChildren.text = btnText ?? amountToPick.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();
type.GetMethod("SetupDragItem", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(InventoryGui.instance, new object[3] { m_splitItem, m_splitInventory, amountToPick });
type.GetField("m_splitItem", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(InventoryGui.instance, null);
type.GetField("m_splitInventory", BindingFlags.Instance | BindingFlags.NonPublic)?.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
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);
}
}
[HarmonyPatch(typeof(InventoryGui), "Update")]
public class InventoryGuiUpdateSplitDialogLoadPatch
{
[HarmonyPrefix]
public static bool Prefix()
{
return !SplitDialogLoadPatch.InputFieldFocused;
}
}
}