Decompiled source of Custom Quota Mod v1.0.2

BepInEx/plugins/QuotaMod.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
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("QuotaMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("QuotaMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("63d0aa0e-f9e9-42c6-9ce4-1ffabcd1a1fe")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.plusblankplus.quotamod", "REPO Random Quota Mod", "1.3.6")]
public class QuotaMod : BaseUnityPlugin
{
	[HarmonyPatch]
	private static class RoundDirector_Patches
	{
		private static bool s_modEnabled = true;

		private static int s_minQuota = 2000;

		private static int s_maxQuota = 5000;

		private static bool s_loggingEnabled = true;

		private static bool s_cachePopulated = false;

		private static bool s_quotaAlreadySetForThisRound = false;

		public static void CacheConfigSettings(bool modEnabled, int min, int max, bool loggingEnabled)
		{
			s_modEnabled = modEnabled;
			s_minQuota = min;
			s_maxQuota = max;
			s_loggingEnabled = loggingEnabled;
			s_cachePopulated = true;
			if (s_loggingEnabled)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogDebug((object)$"Static Cache updated: ModEnabled={s_modEnabled}, LoggingEnabled={s_loggingEnabled}, Min={s_minQuota}, Max={s_maxQuota}");
				}
			}
		}

		[HarmonyPatch(typeof(RoundDirector), "Start")]
		[HarmonyPrefix]
		private static void ResetQuotaGuardPrefix()
		{
			if (s_loggingEnabled)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogDebug((object)"RoundDirector.Start Prefix: Resetting quota modification guard.");
				}
			}
			s_quotaAlreadySetForThisRound = false;
		}

		[HarmonyPatch(typeof(RoundDirector), "StartRoundLogic")]
		[HarmonyPrefix]
		private static bool ModifyQuotaPrefix(RoundDirector __instance, ref int value)
		{
			if (s_loggingEnabled)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogDebug((object)$"StartRoundLogic Prefix executing. Initial value = {value}");
				}
			}
			if (!s_cachePopulated)
			{
				if (s_loggingEnabled)
				{
					ManualLogSource log2 = Log;
					if (log2 != null)
					{
						log2.LogWarning((object)"Prefix: Static cache not populated yet! Skipping.");
					}
				}
				return true;
			}
			if (!s_modEnabled)
			{
				if (s_loggingEnabled)
				{
					ManualLogSource log3 = Log;
					if (log3 != null)
					{
						log3.LogDebug((object)"Prefix: Mod disabled. Skipping.");
					}
				}
				return true;
			}
			bool flag = false;
			try
			{
				if ((Object)(object)GameManager.instance == (Object)null)
				{
					ManualLogSource log4 = Log;
					if (log4 != null)
					{
						log4.LogError((object)"Prefix: GameManager.instance is null!");
					}
					return true;
				}
				if (GameManager.instance.gameMode == 0)
				{
					flag = true;
					if (s_loggingEnabled)
					{
						ManualLogSource log5 = Log;
						if (log5 != null)
						{
							log5.LogDebug((object)"Prefix: Single Player detected.");
						}
					}
				}
				else if (PhotonNetwork.IsMasterClient)
				{
					flag = true;
					if (s_loggingEnabled)
					{
						ManualLogSource log6 = Log;
						if (log6 != null)
						{
							log6.LogDebug((object)"Prefix: MasterClient detected.");
						}
					}
				}
				else if (s_loggingEnabled)
				{
					ManualLogSource log7 = Log;
					if (log7 != null)
					{
						log7.LogDebug((object)"Prefix: Not Authority.");
					}
				}
			}
			catch (Exception arg)
			{
				ManualLogSource log8 = Log;
				if (log8 != null)
				{
					log8.LogError((object)$"Prefix: Error checking authority: {arg}");
				}
				return true;
			}
			if (flag)
			{
				if (s_quotaAlreadySetForThisRound)
				{
					if (s_loggingEnabled)
					{
						ManualLogSource log9 = Log;
						if (log9 != null)
						{
							log9.LogDebug((object)"Prefix: Quota already set for this round sequence. Skipping modification.");
						}
					}
					return true;
				}
				if (s_loggingEnabled)
				{
					ManualLogSource log10 = Log;
					if (log10 != null)
					{
						log10.LogInfo((object)$"Prefix (Authority, First Call): Modifying quota. Original calculated value = {value}");
					}
				}
				int num = s_minQuota;
				int num2 = s_maxQuota;
				if (num > num2)
				{
					if (s_loggingEnabled)
					{
						ManualLogSource log11 = Log;
						if (log11 != null)
						{
							log11.LogWarning((object)"Prefix: MinQuota>MaxQuota from static cache. Clamping.");
						}
					}
					num = num2;
				}
				int num3 = Random.Range(num, num2 + 1);
				value = num3;
				if (s_loggingEnabled)
				{
					ManualLogSource log12 = Log;
					if (log12 != null)
					{
						log12.LogInfo((object)$"Prefix (Authority, First Call): Set quota to {value} (Range: {num}-{num2}).");
					}
				}
				s_quotaAlreadySetForThisRound = true;
				if (s_loggingEnabled)
				{
					ManualLogSource log13 = Log;
					if (log13 != null)
					{
						log13.LogDebug((object)"Prefix: Quota modification guard SET.");
					}
				}
			}
			else if (s_loggingEnabled)
			{
				ManualLogSource log14 = Log;
				if (log14 != null)
				{
					log14.LogDebug((object)$"Prefix (Client): Not Authority. Using received value = {value}. No modification.");
				}
			}
			return true;
		}
	}

	private ConfigEntry<bool> modEnabledConfig;

	private ConfigEntry<int> minQuotaConfig;

	private ConfigEntry<int> maxQuotaConfig;

	private ConfigEntry<bool> loggingEnabledConfig;

	private Harmony harmony;

	internal static QuotaMod Instance { get; private set; }

	internal static ManualLogSource Log { get; private set; }

	private void Awake()
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Expected O, but got Unknown
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogDebug((object)"QuotaMod Instance and Logger assigned.");
		modEnabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the random quota mod.");
		loggingEnabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LoggingEnabled", true, "Enable detailed logging for this mod.");
		minQuotaConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Quota Range", "MinimumQuota", 2000, new ConfigDescription("The minimum possible haul goal quota (inclusive).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000000), Array.Empty<object>()));
		maxQuotaConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Quota Range", "MaximumQuota", 5000, new ConfigDescription("The maximum possible haul goal quota (inclusive).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000000), Array.Empty<object>()));
		Log.LogInfo((object)"Random Quota Mod config bound.");
		RoundDirector_Patches.CacheConfigSettings(modEnabledConfig.Value, minQuotaConfig.Value, maxQuotaConfig.Value, loggingEnabledConfig.Value);
		Log.LogInfo((object)"Static config cache populated.");
		harmony = new Harmony("com.plusblankplus.quotamod.harmony");
		try
		{
			harmony.PatchAll(Assembly.GetExecutingAssembly());
			Log.LogInfo((object)"Harmony patches applied successfully.");
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"Harmony patching failed: {arg}");
		}
		Log.LogInfo((object)"Random Quota Mod Loaded and Awake Finished!");
	}
}