Decompiled source of CtrlSplit Il2cpp v1.1.0

CtrlSplit.dll

Decompiled 2 weeks ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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.1", "xVilho", null)]
[assembly: MelonColor(255, 200, 150, 255)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CtrlSplit")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2b32cbe78cc3e1c266669096e604810206e3d6c0")]
[assembly: AssemblyProduct("CtrlSplit")]
[assembly: AssemblyTitle("CtrlSplit")]
[assembly: AssemblyVersion("1.0.0.0")]
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_0098: 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)
		{
			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 num = (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 num2 = ((y > 0f) ? 1 : (-1));
		int num3 = 999;
		ItemSlot obj = cachedSlot;
		ItemInstance val = ((obj != null) ? obj.ItemInstance : null);
		if (val != null)
		{
			ItemData itemData = val.GetItemData();
			if (itemData != null)
			{
				num3 = Mathf.Max(itemData.Quantity - 1, 1);
			}
		}
		int num4 = ((num2 <= 0) ? ((draggedAmount <= num) ? 1 : Mathf.Max((draggedAmount - 1) / num * num, 1)) : ((draggedAmount == 1) ? num : Mathf.Min(((draggedAmount - 1) / num + 1) * num, num3)));
		__instance.SetDraggedAmount(num4);
		Logger.Msg($"Ctrl+Mb1+Scroll | {draggedAmount} → {num4} (max: {num3 + 1})");
	}
}