Decompiled source of FixedCashDrops v1.0.0

Mods/ATMFixedDrop.dll

Decompiled 38 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using ATMFixedDrop;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.ObjectScripts;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Fixed Cash Drops", "1.0.0", "purplehaxttv", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ATMFixedDrop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9557bc05f42337ad2775be43ce66100dd5d10791")]
[assembly: AssemblyProduct("ATMFixedDrop")]
[assembly: AssemblyTitle("ATMFixedDrop")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ATMFixedDrop
{
	public class Core : MelonMod
	{
		private static MelonPreferences_Category cfg;

		private static MelonPreferences_Entry<int> payoutEntry;

		private static MelonPreferences_Entry<bool> atmEntry;

		private static MelonPreferences_Entry<bool> cukeEntry;

		private static MelonPreferences_Entry<bool> recyclerEntry;

		internal static Instance Log;

		private static MelonPreferences_Entry<float> recyclerMultiplierEntry;

		private static MelonPreferences_Entry<float> machineMultiplierEntry;

		private static MelonPreferences_Entry<bool> verboseEntry;

		internal static bool FixATM
		{
			get
			{
				if (atmEntry != null)
				{
					return atmEntry.Value;
				}
				return true;
			}
		}

		internal static bool FixCukeMachine
		{
			get
			{
				if (cukeEntry != null)
				{
					return cukeEntry.Value;
				}
				return true;
			}
		}

		internal static bool FixRecycler
		{
			get
			{
				if (recyclerEntry != null)
				{
					return recyclerEntry.Value;
				}
				return true;
			}
		}

		internal static int PayoutDollars
		{
			get
			{
				if (payoutEntry == null)
				{
					return 200;
				}
				return payoutEntry.Value;
			}
		}

		internal static int BillCount
		{
			get
			{
				int num = PayoutDollars / 10;
				if (num >= 1)
				{
					return num;
				}
				return 1;
			}
		}

		internal static float RecyclerMultiplier
		{
			get
			{
				if (recyclerMultiplierEntry == null)
				{
					return 0f;
				}
				return recyclerMultiplierEntry.Value;
			}
		}

		internal static float MachineMultiplier
		{
			get
			{
				if (machineMultiplierEntry == null)
				{
					return 0f;
				}
				return machineMultiplierEntry.Value;
			}
		}

		internal static bool Verbose
		{
			get
			{
				if (verboseEntry != null)
				{
					return verboseEntry.Value;
				}
				return false;
			}
		}

		internal static int MachineBills(int rolled)
		{
			float machineMultiplier = MachineMultiplier;
			if (machineMultiplier > 0f)
			{
				return Math.Max(1, (int)Math.Round((float)rolled * machineMultiplier));
			}
			return BillCount;
		}

		internal static float RecyclerPayout(float vanilla)
		{
			float recyclerMultiplier = RecyclerMultiplier;
			if (recyclerMultiplier > 0f)
			{
				return (float)Math.Round(vanilla * recyclerMultiplier);
			}
			return PayoutDollars;
		}

		public override void OnInitializeMelon()
		{
			Log = ((MelonBase)this).LoggerInstance;
			cfg = MelonPreferences.CreateCategory("ATMFixedDrop");
			payoutEntry = cfg.CreateEntry<int>("PayoutDollars", 200, (string)null, "Flat payout, only used where a multiplier below is set to 0. Rounds down to the nearest $10 for ATMs and Cuke machines.", false, false, (ValueValidator)null, (string)null);
			atmEntry = cfg.CreateEntry<bool>("FixATM", true, (string)null, "Change what broken ATMs drop. false = vanilla payout.", false, false, (ValueValidator)null, (string)null);
			cukeEntry = cfg.CreateEntry<bool>("FixCukeMachine", true, (string)null, "Change what broken Cuke machines drop. false = vanilla payout.", false, false, (ValueValidator)null, (string)null);
			machineMultiplierEntry = cfg.CreateEntry<float>("MachineMultiplier", 7f, (string)null, "Broken ATMs and Cuke machines drop the game's own random amount, times this. Vanilla ATMs roll $20 to $80 and Cuke machines $10 to $40, so 7 gives $140 to $560 and $70 to $280. 0 = always drop a flat PayoutDollars.", false, false, (ValueValidator)null, (string)null);
			recyclerEntry = cfg.CreateEntry<bool>("FixRecycler", true, (string)null, "Change what trash recyclers pay. false = vanilla payout.", false, false, (ValueValidator)null, (string)null);
			recyclerMultiplierEntry = cfg.CreateEntry<float>("RecyclerMultiplier", 7f, (string)null, "Recyclers pay the real value of the trash put in, times this. The game values each piece at $1 to $3 (bags count by their contents). 0 = ignore the trash and pay a flat PayoutDollars per press.", false, false, (ValueValidator)null, (string)null);
			verboseEntry = cfg.CreateEntry<bool>("VerboseLog", false, (string)null, "Log every recycler value change (for troubleshooting).", false, false, (ValueValidator)null, (string)null);
			string value = ((!FixRecycler) ? "vanilla" : ((RecyclerMultiplier > 0f) ? $"trash value x{RecyclerMultiplier}" : $"flat ${PayoutDollars}"));
			string text = ((MachineMultiplier > 0f) ? $"random roll x{MachineMultiplier}" : $"flat ${PayoutDollars}");
			Log.Msg($"Fixed Cash Drops v1.0 loaded. ATMs: {(FixATM ? text : "vanilla")}, Cuke machines: {(FixCukeMachine ? text : "vanilla")}, recyclers: {value}.");
		}
	}
	[HarmonyPatch(typeof(ObjectCompilerGeneratedNPrivateSealedIEnumerator1ObjectIEnumeratorIDisposableInObATInObInObUnique), "MoveNext")]
	public static class ATM_BreakRoutine_Patch
	{
		private static readonly HashSet<IntPtr> handled = new HashSet<IntPtr>();

		[HarmonyPostfix]
		public static void Postfix(ObjectCompilerGeneratedNPrivateSealedIEnumerator1ObjectIEnumeratorIDisposableInObATInObInObUnique __instance)
		{
			if (!Core.FixATM)
			{
				return;
			}
			try
			{
				int cashDrop_5__ = __instance._cashDrop_5__2;
				if (cashDrop_5__ > 0 && handled.Add(((Il2CppObjectBase)__instance).Pointer))
				{
					int num = Core.MachineBills(cashDrop_5__);
					Core.Log.Msg($"[ATM] rolled ${cashDrop_5__ * 10}, drops ${num * 10}");
					__instance._cashDrop_5__2 = num;
					if (handled.Count > 500)
					{
						handled.Clear();
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log.Warning("ATM patch error: " + ex.Message);
			}
		}
	}
	[HarmonyPatch(typeof(ObjectCompilerGeneratedNPrivateSealedIEnumerator1ObjectIEnumeratorIDisposableInObVeInObInObUnique), "MoveNext")]
	public static class Vending_BreakRoutine_Patch
	{
		private static readonly HashSet<IntPtr> handled = new HashSet<IntPtr>();

		[HarmonyPostfix]
		public static void Postfix(ObjectCompilerGeneratedNPrivateSealedIEnumerator1ObjectIEnumeratorIDisposableInObVeInObInObUnique __instance)
		{
			if (!Core.FixCukeMachine)
			{
				return;
			}
			try
			{
				int cashDrop_5__ = __instance._cashDrop_5__2;
				if (cashDrop_5__ > 0 && handled.Add(((Il2CppObjectBase)__instance).Pointer))
				{
					int num = Core.MachineBills(cashDrop_5__);
					Core.Log.Msg($"[Cuke machine] rolled ${cashDrop_5__ * 10}, drops ${num * 10}");
					__instance._cashDrop_5__2 = num;
					if (handled.Count > 500)
					{
						handled.Clear();
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Vending patch error: " + ex.Message);
			}
		}
	}
	[HarmonyPatch(typeof(Recycler), "SetCashValue")]
	public static class Recycler_SetCashValue_Patch
	{
		[HarmonyPrefix]
		public static void Prefix(Recycler __instance, ref float amount)
		{
			if (!Core.FixRecycler || amount <= 0f)
			{
				return;
			}
			try
			{
				float value = amount;
				amount = Recycler_Process_Patch.PayoutFor(__instance, amount);
				if (Core.Verbose)
				{
					Core.Log.Msg($"[Recycler] SetCashValue {value} -> {amount}");
				}
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Recycler cash patch error: " + ex.Message);
			}
		}
	}
	[HarmonyPatch(typeof(_Process_d__45), "MoveNext")]
	public static class Recycler_Process_Patch
	{
		private static readonly HashSet<IntPtr> handled = new HashSet<IntPtr>();

		private static readonly Dictionary<IntPtr, float> rawByRecycler = new Dictionary<IntPtr, float>();

		private static readonly Dictionary<IntPtr, float> paidByRecycler = new Dictionary<IntPtr, float>();

		internal static float PayoutFor(Recycler recycler, float value)
		{
			IntPtr key = (((Object)(object)recycler != (Object)null) ? ((Il2CppObjectBase)recycler).Pointer : IntPtr.Zero);
			if (paidByRecycler.TryGetValue(key, out var value2) && Math.Abs(value2 - value) < 0.01f && rawByRecycler.TryGetValue(key, out var value3) && Math.Abs(value3 - value) > 0.01f)
			{
				return value;
			}
			float num = Core.RecyclerPayout(value);
			rawByRecycler[key] = value;
			paidByRecycler[key] = num;
			return num;
		}

		[HarmonyPostfix]
		public static void Postfix(_Process_d__45 __instance)
		{
			if (!Core.FixRecycler)
			{
				return;
			}
			try
			{
				float value_5__ = __instance._value_5__2;
				if (value_5__ > 0f && handled.Add(((Il2CppObjectBase)__instance).Pointer))
				{
					float num = PayoutFor(__instance.__4__this, value_5__);
					Core.Log.Msg($"[Recycler] trash worth ${value_5__} pays ${num}");
					__instance._value_5__2 = num;
					if (handled.Count > 500)
					{
						handled.Clear();
					}
				}
				else if (value_5__ <= 0f)
				{
					Recycler _4__this = __instance.__4__this;
					if ((Object)(object)_4__this != (Object)null)
					{
						rawByRecycler.Remove(((Il2CppObjectBase)_4__this).Pointer);
						paidByRecycler.Remove(((Il2CppObjectBase)_4__this).Pointer);
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Recycler process patch error: " + ex.Message);
			}
		}
	}
}