Decompiled source of CtrlSplit Il2cpp v1.3.0

CtrlSplit.dll

Decompiled 3 days ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using CtrlSplit;
using HarmonyLib;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Persistence.Datas;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.UI.Items;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(global::CtrlSplit.CtrlSplit), "CtrlSplit", "1.3.0", "xVilho", null)]
[assembly: MelonColor(255, 200, 150, 255)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace CtrlSplit;

public class CtrlSplit : MelonMod
{
	private static ItemSlot cachedSlot;

	private static bool rightClickHeld;

	private static Instance Logger;

	private static MelonPreferences_Category cfgCategory;

	private static MelonPreferences_Entry<int> cfgCtrlStep;

	private static MelonPreferences_Entry<int> cfgAltStep;

	public override void OnInitializeMelon()
	{
		Logger = ((MelonBase)this).LoggerInstance;
		Logger.Msg("✅ initialized");
		cfgCategory = MelonPreferences.CreateCategory("CtrlSplit");
		cfgCtrlStep = cfgCategory.CreateEntry<int>("CtrlStep", 5, "Ctrl Scroll Step", (string)null, false, false, (ValueValidator)null, (string)null);
		cfgAltStep = cfgCategory.CreateEntry<int>("AltStep", 10, "Alt Scroll Step", (string)null, false, false, (ValueValidator)null, (string)null);
		((MelonBase)this).HarmonyInstance.PatchAll(typeof(CtrlSplit));
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(ItemUIManager), "Update")]
	private static void PostfixUpdate(ItemUIManager __instance)
	{
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetMouseButtonDown(1))
		{
			ItemSlotUI hoveredSlot = __instance.HoveredSlot;
			cachedSlot = ((hoveredSlot != null) ? hoveredSlot.assignedSlot : null);
			rightClickHeld = true;
		}
		else if (Input.GetMouseButtonUp(1))
		{
			rightClickHeld = false;
			cachedSlot = null;
		}
		if ((rightClickHeld || __instance.draggedAmount > 0) && Input.GetMouseButtonDown(2))
		{
			ItemSlotUI hoveredSlot2 = __instance.HoveredSlot;
			ItemSlot obj = ((hoveredSlot2 != null) ? hoveredSlot2.assignedSlot : null) ?? cachedSlot;
			ItemInstance val = ((obj != null) ? obj.ItemInstance : null);
			if (val != null)
			{
				ItemData itemData = val.GetItemData();
				if (itemData != null && itemData.Quantity > 1)
				{
					int num = Mathf.Max(itemData.Quantity - 1, 1);
					int num2 = Mathf.Clamp(itemData.Quantity / 2, 1, num);
					__instance.SetDraggedAmount(num2);
					Logger.Msg($"MMB half | set to {num2} (stack: {itemData.Quantity})");
				}
			}
		}
		if (!rightClickHeld)
		{
			return;
		}
		bool flag = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
		bool flag2 = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307);
		if (!flag && !flag2)
		{
			return;
		}
		int num3 = (flag ? cfgCtrlStep.Value : cfgAltStep.Value);
		float y = Input.mouseScrollDelta.y;
		if (Mathf.Abs(y) < 0.01f)
		{
			return;
		}
		int draggedAmount = __instance.draggedAmount;
		if (draggedAmount <= 0)
		{
			return;
		}
		int num4 = ((y > 0f) ? 1 : (-1));
		int num5 = 999;
		ItemSlot obj2 = cachedSlot;
		ItemInstance val2 = ((obj2 != null) ? obj2.ItemInstance : null);
		if (val2 != null)
		{
			ItemData itemData2 = val2.GetItemData();
			if (itemData2 != null)
			{
				num5 = Mathf.Max(itemData2.Quantity - 1, 1);
			}
		}
		int num6 = ((num4 <= 0) ? ((draggedAmount <= num3) ? 1 : Mathf.Max((draggedAmount - 1) / num3 * num3, 1)) : ((draggedAmount == 1) ? num3 : Mathf.Min(((draggedAmount - 1) / num3 + 1) * num3, num5)));
		__instance.SetDraggedAmount(num6);
		Logger.Msg($"Ctrl+Mb1+Scroll | {draggedAmount} → {num6} (max: {num5 + 1})");
	}
}