Decompiled source of MaxCashPerSlot v1.0.0

Mods/MaxCashPerSlot.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MaxCashMod;
using MelonLoader;
using ScheduleOne.ObjectScripts.Cash;
using ScheduleOne.UI.Items;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MaxCashMod")]
[assembly: AssemblyDescription("setting set max_cash_per_slot to million")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MaxCashMod for Schedule I")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: MelonInfo(typeof(MaxCashModMain), "MaxCashMod", "1.0.0", "cathair", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: ComVisible(false)]
[assembly: Guid("b4c6e7f8-9d5a-46e3-88c2-1a9c4d5e2f3a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MaxCashMod;

public class MaxCashModMain : MelonMod
{
	public const float NEW_MAX_CASH = 1000000f;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("MaxCashMod: Initializing...");
		try
		{
			((MelonBase)this).HarmonyInstance.PatchAll();
			PatchCashStackVisuals();
			PatchItemUIManagerMethods();
			MelonLogger.Msg($"MaxCashMod: MAX_CASH patched to {1000000f}");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("MaxCashMod: Initialization failed: " + ex.Message);
			MelonLogger.Error(ex.StackTrace);
		}
	}

	private void PatchCashStackVisuals()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		MethodInfo method = typeof(CashStackVisuals).GetMethod("ShowAmount", BindingFlags.Instance | BindingFlags.Public);
		if (method != null)
		{
			((MelonBase)this).HarmonyInstance.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(MaxCashModMain).GetMethod("ShowAmountPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MelonLogger.Msg("MaxCashMod: Patched CashStackVisuals.ShowAmount() with visual logic fix");
		}
	}

	private void PatchItemUIManagerMethods()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Expected O, but got Unknown
		string[] array = new string[3] { "StartDragCash", "EndCashDrag", "UpdateCashDragAmount" };
		string[] array2 = array;
		foreach (string text in array2)
		{
			MethodInfo method = typeof(ItemUIManager).GetMethod(text, BindingFlags.Instance | BindingFlags.NonPublic);
			if (method != null)
			{
				((MelonBase)this).HarmonyInstance.Patch((MethodBase)method, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(MaxCashModMain).GetMethod("TranspileReplaceCashLimits", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null);
				MelonLogger.Msg("MaxCashMod: Patched ItemUIManager." + text + "()");
			}
			else
			{
				MelonLogger.Warning("MaxCashMod: Failed to find ItemUIManager." + text + "()");
			}
		}
	}

	public static IEnumerable<CodeInstruction> TranspileReplaceCashLimits(IEnumerable<CodeInstruction> instructions)
	{
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		bool flag = false;
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].opcode == OpCodes.Ldc_R4)
			{
				float num = (float)list[i].operand;
				if (num == 1000f)
				{
					list[i].operand = 1000000f;
					flag = true;
				}
			}
		}
		if (flag)
		{
			MelonLogger.Msg("MaxCashMod: Replaced 1000f with NEW_MAX_CASH");
		}
		return list;
	}

	public static void ShowAmountPostfix(CashStackVisuals __instance, float amount)
	{
		bool flag = amount >= 100f;
		GameObject visuals_Over = __instance.Visuals_Over100;
		if (visuals_Over != null)
		{
			visuals_Over.SetActive(flag);
		}
		GameObject visuals_Under = __instance.Visuals_Under100;
		if (visuals_Under != null)
		{
			visuals_Under.SetActive(!flag);
		}
		if (flag)
		{
			int num = Mathf.Clamp(Mathf.FloorToInt(amount / 100f), 0, __instance.Bills.Length);
			for (int i = 0; i < __instance.Bills.Length; i++)
			{
				GameObject obj = __instance.Bills[i];
				if (obj != null)
				{
					obj.SetActive(i < num);
				}
			}
			if (__instance.Notes == null)
			{
				return;
			}
			GameObject[] notes = __instance.Notes;
			foreach (GameObject val in notes)
			{
				if (val != null)
				{
					val.SetActive(false);
				}
			}
			return;
		}
		int num2 = Mathf.Clamp(Mathf.FloorToInt(amount / 10f), 0, __instance.Notes.Length);
		for (int k = 0; k < __instance.Notes.Length; k++)
		{
			GameObject obj2 = __instance.Notes[k];
			if (obj2 != null)
			{
				obj2.SetActive(k < num2);
			}
		}
		if (__instance.Bills == null)
		{
			return;
		}
		GameObject[] bills = __instance.Bills;
		foreach (GameObject val2 in bills)
		{
			if (val2 != null)
			{
				val2.SetActive(false);
			}
		}
	}
}
[HarmonyPatch(typeof(Equippable_Cash), "UpdateCashVisuals")]
public static class EquippableCashPatch
{
	public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 1000f)
			{
				list[i].operand = 1000000f;
			}
		}
		return list;
	}
}