Decompiled source of ChocoQuota v1.0.9

ChocoQuota.dll

Decompiled 3 months 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 ChocoQuota.Patches;
using HarmonyLib;
using TMPro;
using Unity.Netcode;
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("ChocoQuota")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChocoQuota")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d38d2064-347b-417a-a052-2ecb101156a1")]
[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 ChocoQuota
{
	[BepInPlugin("Jade.ChocoQuota", "ChocoQuota", "1.0.9")]
	public class ChocoQuotaBase : BaseUnityPlugin
	{
		private const string modGUID = "Jade.ChocoQuota";

		private const string modName = "ChocoQuota";

		private const string modVersion = "1.0.9";

		private readonly Harmony harmony = new Harmony("Jade.ChocoQuota");

		public static ChocoQuotaBase Instance;

		internal ManualLogSource als;

		private ConfigEntry<int> config_startingCredits;

		private ConfigEntry<int> config_startingQuota;

		private ConfigEntry<int> config_baseIncrease;

		private ConfigEntry<float> config_sharpness;

		private ConfigEntry<int> config_levelOut;

		private ConfigEntry<int> config_flatIncrease;

		private ConfigEntry<int> config_deadline;

		private ConfigEntry<bool> config_quotaEnabled;

		private ConfigEntry<float> config_rollover;

		private ConfigEntry<int> config_cap;

		public static int startingCredits;

		public static int startingQuota;

		public static int baseIncrease;

		public static float sharpness;

		public static int levelOut;

		public static int flatIncrease;

		public static int deadline;

		public static bool quotaEnabled;

		public static float rollover;

		public static int cap;

		public int savedRollover;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			als = Logger.CreateLogSource("Jade.ChocoQuota");
			als.LogInfo((object)":");
			als.LogInfo((object)"ChocoQuota has loaded!");
			als.LogInfo((object)":");
			config_startingCredits = ((BaseUnityPlugin)this).Config.Bind<int>("0. Basic", "StartingCredits", 120, "The amount of credits you start with.");
			config_deadline = ((BaseUnityPlugin)this).Config.Bind<int>("0. Basic", "DaysToDeadline", 3, "How many days to fulfill quota.");
			config_startingQuota = ((BaseUnityPlugin)this).Config.Bind<int>("0. Basic", "StartingQuota", 130, "The value of the first quota.");
			config_baseIncrease = ((BaseUnityPlugin)this).Config.Bind<int>("0. Basic", "BaseIncrease", 120, "The flat rate at which the quota increases upon success.");
			config_sharpness = ((BaseUnityPlugin)this).Config.Bind<float>("0. Basic", "CurveSharpness", 3f, "The sharpness of the curve for quota increase.\n(set to 0.0 to disable exponential growth)");
			config_levelOut = ((BaseUnityPlugin)this).Config.Bind<int>("1. Added", "FinalLevel", 1400, "After the quota reaches this value, the base increase and curve sharpness are ignored in favor of the final increase.\n(set to -1 to disable this feature)");
			config_flatIncrease = ((BaseUnityPlugin)this).Config.Bind<int>("1. Added", "FinalIncrease", 202, "After final level is passed, the quota will begin increasing at this flat rate.");
			config_quotaEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Optional Features", "DisableQuota", false, "Whether to disable the quota system.\n(allows for limitless exploration)");
			config_rollover = ((BaseUnityPlugin)this).Config.Bind<float>("2. Optional Features", "RolloverAmount", 0f, "When you overshoot the quota, what portion of the extra money should roll over to the next one?\n(Number between 0.0-1.0)\n(Set to 1.0 to enable a normal rollover)");
			config_cap = ((BaseUnityPlugin)this).Config.Bind<int>("2. Optional Features", "Quota Cap", -1, "The quota will not rise past this value. (set to -1 to disable this feature)");
			startingCredits = config_startingCredits.Value;
			startingQuota = config_startingQuota.Value;
			baseIncrease = config_baseIncrease.Value;
			sharpness = config_sharpness.Value;
			levelOut = config_levelOut.Value;
			flatIncrease = config_flatIncrease.Value;
			deadline = config_deadline.Value;
			quotaEnabled = !config_quotaEnabled.Value;
			rollover = config_rollover.Value;
			cap = config_cap.Value;
			harmony.PatchAll(typeof(ChocoQuotaBase));
			harmony.PatchAll(typeof(TimeOfDayPatch));
		}
	}
}
namespace ChocoQuota.Patches
{
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class TimeOfDayPatch : NetworkBehaviour
	{
		[HarmonyPatch("SetNewProfitQuota")]
		[HarmonyPrefix]
		private static bool NewQuotaPrepatch(ref int ___timesFulfilledQuota, ref int ___profitQuota, ref float ___timeUntilDeadline, ref int ___quotaFulfilled, ref int ___daysUntilDeadline, ref float ___totalTime)
		{
			if (((NetworkBehaviour)TimeOfDay.Instance).IsServer)
			{
				___timesFulfilledQuota++;
				int num = ___quotaFulfilled - ___profitQuota;
				if (___profitQuota < ChocoQuotaBase.levelOut || ChocoQuotaBase.levelOut == -1)
				{
					___profitQuota = (int)((double)(ChocoQuotaBase.startingQuota + ChocoQuotaBase.baseIncrease * ___timesFulfilledQuota) + (double)ChocoQuotaBase.sharpness * Math.Pow(___timesFulfilledQuota, 3.0));
				}
				else
				{
					___profitQuota += ChocoQuotaBase.flatIncrease;
				}
				if (ChocoQuotaBase.cap != -1 && ___profitQuota > ChocoQuotaBase.cap)
				{
					___profitQuota = ChocoQuotaBase.cap;
				}
				ChocoQuotaBase.Instance.savedRollover = num;
				if (ChocoQuotaBase.quotaEnabled)
				{
					___quotaFulfilled = (int)Math.Max(0f, (float)num * ChocoQuotaBase.rollover);
				}
				___timeUntilDeadline = ___totalTime * 4f;
				int num2 = num / 5 + 15 * ___daysUntilDeadline;
				TimeOfDay.Instance.SyncNewProfitQuotaClientRpc(___profitQuota, num2, ___timesFulfilledQuota);
			}
			return false;
		}

		[HarmonyPatch("SyncNewProfitQuotaClientRpc")]
		[HarmonyPostfix]
		private static void SyncQuotaPatch(ref int ___quotaFulfilled, ref int ___profitQuota)
		{
			if (!ChocoQuotaBase.quotaEnabled)
			{
				StartOfRound.Instance.companyBuyingRate = 1f;
			}
			if (ChocoQuotaBase.quotaEnabled)
			{
				___quotaFulfilled = (int)Math.Max(0f, (float)ChocoQuotaBase.Instance.savedRollover * ChocoQuotaBase.rollover);
			}
		}

		[HarmonyPatch("SetBuyingRateForDay")]
		[HarmonyPostfix]
		private static void BuyingRatePatch(ref float ___timeUntilDeadline, ref float ___totalTime, ref QuotaSettings ___quotaVariables, ref int ___quotaFulfilled)
		{
			if (!ChocoQuotaBase.quotaEnabled)
			{
				___timeUntilDeadline = ___totalTime * (float)___quotaVariables.deadlineDaysAmount;
				StartOfRound.Instance.companyBuyingRate = 1f;
				((TMP_Text)StartOfRound.Instance.deadlineMonitorText).text = "DEADLINE:\nNEVER";
				((TMP_Text)StartOfRound.Instance.profitQuotaMonitorText).text = $"SCRAP SOLD:\n${___quotaFulfilled}";
			}
		}

		[HarmonyPatch("UpdateProfitQuotaCurrentTime")]
		[HarmonyPostfix]
		private static void UpdateQuotaRatePatch(ref float ___timeUntilDeadline, ref float ___totalTime, ref QuotaSettings ___quotaVariables, ref int ___quotaFulfilled)
		{
			if (!ChocoQuotaBase.quotaEnabled)
			{
				___timeUntilDeadline = ___totalTime * (float)___quotaVariables.deadlineDaysAmount;
				StartOfRound.Instance.companyBuyingRate = 1f;
				((TMP_Text)StartOfRound.Instance.deadlineMonitorText).text = "DEADLINE:\nNEVER";
				((TMP_Text)StartOfRound.Instance.profitQuotaMonitorText).text = $"SCRAP SOLD:\n${___quotaFulfilled}";
			}
		}

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch(ref float ___timeUntilDeadline, ref float ___totalTime, ref QuotaSettings ___quotaVariables, ref int ___quotaFulfilled)
		{
			TimeOfDay.Instance.quotaVariables.startingQuota = ChocoQuotaBase.startingQuota;
			TimeOfDay.Instance.quotaVariables.startingCredits = ChocoQuotaBase.startingCredits;
			TimeOfDay.Instance.quotaVariables.deadlineDaysAmount = ChocoQuotaBase.deadline;
			if (!ChocoQuotaBase.quotaEnabled)
			{
				TimeOfDay.Instance.quotaVariables.startingQuota = 999999999;
				TimeOfDay.Instance.quotaVariables.deadlineDaysAmount = 3;
				___timeUntilDeadline = ___totalTime * (float)___quotaVariables.deadlineDaysAmount;
				StartOfRound.Instance.companyBuyingRate = 1f;
				((TMP_Text)StartOfRound.Instance.deadlineMonitorText).text = "DEADLINE:\nNEVER";
				((TMP_Text)StartOfRound.Instance.profitQuotaMonitorText).text = $"SCRAP SOLD:\n${___quotaFulfilled}";
			}
		}
	}
}