Decompiled source of CtrlSplit Mono v1.1.0

CtrlSplitMono.dll

Decompiled a day ago
using System;
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 MelonLoader;
using MelonLoader.Preferences;
using ScheduleOne.ItemFramework;
using ScheduleOne.Persistence.Datas;
using ScheduleOne.UI;
using ScheduleOne.UI.Items;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CtrlSplitMono")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f404bea03a913292fc5a26be72095ba9c96c36ee")]
[assembly: AssemblyProduct("CtrlSplitMono")]
[assembly: AssemblyTitle("CtrlSplitMono")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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_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 num2 = (int)AccessTools.Field(typeof(ItemUIManager), "draggedAmount").GetValue(__instance);
		if (num2 <= 0)
		{
			return;
		}
		int num3 = ((y > 0f) ? 1 : (-1));
		int num4 = 999;
		ItemSlot obj = cachedSlot;
		ItemInstance val = ((obj != null) ? obj.ItemInstance : null);
		if (val != null)
		{
			ItemData itemData = val.GetItemData();
			if (itemData != null)
			{
				num4 = Mathf.Max(itemData.Quantity - 1, 1);
			}
		}
		int num5 = ((num3 <= 0) ? ((num2 <= num) ? 1 : Mathf.Max((num2 - 1) / num * num, 1)) : ((num2 == 1) ? num : Mathf.Min(((num2 - 1) / num + 1) * num, num4)));
		AccessTools.Method(typeof(ItemUIManager), "SetDraggedAmount", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { num5 });
		Logger.Msg($"Ctrl+Mb1+Scroll | {num2} → {num5} (max: {num4 + 1})");
	}
}