Decompiled source of QuotaRolloverAddition v0.0.0

LC_QuotaRolloverAddition.dll

Decompiled 5 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.Logging;
using HarmonyLib;
using QuotaRollover.Patches;
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("LC_Template")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LC_Template")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f0665a4a-fa55-44a9-bc91-21caf15c74ff")]
[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")]
[BepInPlugin("Mellowdy.QuotaRolloverAddition", "QuotaRolloverAddition", "0.0.0")]
public class QuotaRolloverBase : BaseUnityPlugin
{
	private const string modGUID = "Mellowdy.QuotaRolloverAddition";

	private const string modName = "QuotaRolloverAddition";

	private const string modVersion = "0.0.0";

	private readonly Harmony harmony = new Harmony("Mellowdy.QuotaRolloverAddition");

	public static ManualLogSource mls;

	private static QuotaRolloverBase instance;

	public static float rolloverPercentage = 0.5f;

	private void Awake()
	{
		if ((Object)(object)instance == (Object)null)
		{
			instance = this;
		}
		mls = Logger.CreateLogSource("Mellowdy.QuotaRolloverAddition");
		rolloverPercentage = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Rollover Percentage", 0.7f, "How many percent of the previous quota will be rolled over (1 = 100%, 0.5 = 50%, etc)").Value;
		rolloverPercentage = Mathf.Clamp01(rolloverPercentage);
		harmony.PatchAll(typeof(QuotaRolloverBase));
		harmony.PatchAll(typeof(TimeOfDayPatch));
		mls.LogInfo((object)"QuotaRolloverAddition has been loaded. Credit to boxofbiscuits97's orignal mod QuotaRollover");
	}
}
namespace QuotaRollover.Patches;

[HarmonyPatch(typeof(TimeOfDay))]
internal class TimeOfDayPatch
{
	[HarmonyPatch("SetNewProfitQuota")]
	[HarmonyPrefix]
	[HarmonyAfter(new string[] { })]
	private static bool GetQuotaFulfilledHost(ref int ___quotaFulfilled, ref int ___profitQuota, out int __state)
	{
		QuotaRolloverBase.mls.LogInfo((object)$"days: {TimeOfDay.Instance.daysUntilDeadline} time: {TimeOfDay.Instance.timeUntilDeadline} ID: {StartOfRound.Instance.currentLevelID}");
		if (TimeOfDay.Instance.timeUntilDeadline <= 0f)
		{
			__state = CalculateState(___quotaFulfilled, ___profitQuota);
			QuotaRolloverBase.mls.LogInfo((object)$"Host Got New Quota at: {__state} ful: {___quotaFulfilled}");
			return true;
		}
		QuotaRolloverBase.mls.LogInfo((object)"returned FALSE");
		__state = ___quotaFulfilled;
		return false;
	}

	[HarmonyPatch("SetNewProfitQuota")]
	[HarmonyPostfix]
	[HarmonyBefore(new string[] { })]
	private static void SetQuotaFulfilledHost(ref int ___quotaFulfilled, int __state)
	{
		___quotaFulfilled = __state;
		QuotaRolloverBase.mls.LogInfo((object)$"Host Set New Quota at: {__state}");
	}

	[HarmonyPatch("SyncNewProfitQuotaClientRpc")]
	[HarmonyPrefix]
	private static void GetNewQuotaFulfilledClient(ref int ___quotaFulfilled, ref int ___profitQuota, out int __state)
	{
		__state = CalculateState(___quotaFulfilled, ___profitQuota);
		QuotaRolloverBase.mls.LogInfo((object)$"Client Got New Quota at: {__state}");
	}

	[HarmonyPatch("SyncNewProfitQuotaClientRpc")]
	[HarmonyPostfix]
	private static void SetNewQuotaFulfiledClient(ref int ___quotaFulfilled, int __state)
	{
		if (___quotaFulfilled == 0)
		{
			___quotaFulfilled = __state;
			QuotaRolloverBase.mls.LogInfo((object)$"Client Set New Quota at: {__state}");
		}
	}

	public static int CalculateState(int quotaFulfilled, int profitQuota)
	{
		return (int)Math.Floor((float)(quotaFulfilled - profitQuota) * QuotaRolloverBase.rolloverPercentage);
	}
}