Decompiled source of ProgressiveDeadline v2.0.0

BepInEx/plugins/ProgressiveDeadline.dll

Decompiled 11 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ProgressiveDeadline
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ProgressiveDeadline";

		public const string PLUGIN_NAME = "ProgressiveDeadline";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ProgressiveDeadlineMod
{
	public class Utils
	{
		public static float dailyIncrease(float runCount, AnimationCurve randomizerCurve)
		{
			float value = ProgressiveDeadlineMod.minScrapIncrease.Value;
			float value2 = ProgressiveDeadlineMod.minScrapIncreaseSteepness.Value;
			if (ProgressiveDeadlineMod.useLinearAlgorithm.Value)
			{
				return value;
			}
			float num = randomizerCurve.Evaluate(Random.Range(0f, 1f)) + 1f;
			float num2 = 1f + runCount * (runCount / value2);
			return value * num2 * num;
		}

		public static float buyingRate(TimeOfDay timeOfDay)
		{
			int deadlineDaysAmount = timeOfDay.quotaVariables.deadlineDaysAmount;
			int deadlineDays = getDeadlineDays(timeOfDay);
			ProgressiveDeadlineMod.Instance.mls.LogInfo((object)$"AQ {deadlineDaysAmount} {deadlineDays}");
			if (deadlineDays == 0)
			{
				return 1f;
			}
			float num = 1f / (float)deadlineDaysAmount;
			return (1f - num) / (float)deadlineDaysAmount * (float)(deadlineDaysAmount - deadlineDays) + num;
		}

		public static float getTotalTime(TimeOfDay timeOfDay)
		{
			float num = timeOfDay.totalTime;
			if (num == 0f)
			{
				num = timeOfDay.lengthOfHours * (float)timeOfDay.numberOfHours;
			}
			return num;
		}

		public static float getTimeUntilDeadline(TimeOfDay timeOfDay, float days)
		{
			return days * getTotalTime(timeOfDay);
		}

		public static int getDeadlineDays(TimeOfDay timeOfDay)
		{
			return (int)(timeOfDay.timeUntilDeadline / getTotalTime(timeOfDay));
		}
	}
	[BepInPlugin("LethalOrg.ProgressiveDeadline", "Progressive Deadline", "2.0.0")]
	public class ProgressiveDeadlineMod : BaseUnityPlugin
	{
		private const string modGUID = "LethalOrg.ProgressiveDeadline";

		private const string modName = "Progressive Deadline";

		private const string modVersion = "2.0.0";

		private readonly Harmony harmony = new Harmony("LethalOrg.ProgressiveDeadline");

		public static ProgressiveDeadlineMod Instance;

		internal static ConfigEntry<float> minimumDays;

		internal static ConfigEntry<float> maximumDays;

		internal static ConfigEntry<float> minDailyScrap;

		internal static ConfigEntry<bool> useLinearAlgorithm;

		internal static ConfigEntry<float> minScrapIncrease;

		internal static ConfigEntry<float> minScrapIncreaseSteepness;

		internal ManualLogSource mls;

		internal void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Progressive Deadline");
			mls.LogInfo((object)"Progressive deadline started");
			minimumDays = ((BaseUnityPlugin)this).Config.Bind<float>("Customizable Values", "Minimum Deadline", 2f, "This is the minimum deadline you will have.");
			maximumDays = ((BaseUnityPlugin)this).Config.Bind<float>("Customizable Values", "Maximum Deadline", float.MaxValue, "This is the maximum deadline you will have.");
			minDailyScrap = ((BaseUnityPlugin)this).Config.Bind<float>("Customizable Values", "Minimum Daily ScrapValue", 100f, "Minimum scrap value you can achieve per day. This will ignore the calculation for daily scrap if it's below this number. (Default: 100f)");
			minScrapIncrease = ((BaseUnityPlugin)this).Config.Bind<float>("Customizable Values", "Base Minimum Scrap Value Increase", 30f, "This is the minimum amount the minimum scrap value will increase every time a quota is complete. (Default: 30f)");
			minScrapIncreaseSteepness = ((BaseUnityPlugin)this).Config.Bind<float>("Customizable Values", "Incremental Daily Value Steepness", 200f, "Defines the Steepness of the minimum incremental daily value scalling with each completed quota. (Default: 200f)");
			useLinearAlgorithm = ((BaseUnityPlugin)this).Config.Bind<bool>("Use linear calculations for minimum daily scrap", "Static Base Minimum Scrap", false, "If set to true, the 'Base Minimum Scrap Value Increase' will remain fixed and will not scale based on 'Incremental Daily Value Steepness' and quota completion. (Default: false)");
			harmony.PatchAll();
		}
	}
}
namespace ProgressiveDeadlineMod.Patches
{
	[HarmonyPatch(typeof(TimeOfDay))]
	[HarmonyPatch("Awake")]
	public static class QuotaSettingsPatch
	{
		[HarmonyPostfix]
		public static void SetStartingDeadline(TimeOfDay __instance)
		{
			if (__instance.quotaVariables != null && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
				float value = ProgressiveDeadlineMod.minimumDays.Value;
				float days = ES3.Load<float>("deadlineAmount", currentSaveFileName, value);
				__instance.timeUntilDeadline = Utils.getTimeUntilDeadline(__instance, days);
				__instance.SyncTimeClientRpc(__instance.globalTime, (int)__instance.timeUntilDeadline);
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "ResetSavedGameValues")]
	public class ResetSavedValuesPatch
	{
		[HarmonyPrefix]
		public static void ResetSaves(GameNetworkManager __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				TimeOfDay val = Object.FindObjectOfType<TimeOfDay>();
				string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
				float value = ProgressiveDeadlineMod.minimumDays.Value;
				float value2 = ProgressiveDeadlineMod.minDailyScrap.Value;
				val.timeUntilDeadline = Utils.getTimeUntilDeadline(val, value);
				val.SyncTimeClientRpc(val.globalTime, (int)val.timeUntilDeadline);
				ES3.Save<float>("deadlineAmount", value, currentSaveFileName);
				ES3.Save<float>("previousDaily", value2, currentSaveFileName);
			}
		}
	}
	[HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")]
	public class ProfitQuotaPatch
	{
		[HarmonyPostfix]
		private static void ProgressiveDeadline(TimeOfDay __instance)
		{
			if (!((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				ProgressiveDeadlineMod.Instance.mls.LogInfo((object)"You're not the host.");
				return;
			}
			float value = ProgressiveDeadlineMod.minimumDays.Value;
			float value2 = ProgressiveDeadlineMod.maximumDays.Value;
			float value3 = ProgressiveDeadlineMod.minDailyScrap.Value;
			string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
			float num = __instance.totalTime;
			float runCount = __instance.timesFulfilledQuota;
			AnimationCurve randomizerCurve = __instance.quotaVariables.randomizerCurve;
			float num2 = ES3.Load<float>("previousDaily", currentSaveFileName, value3);
			num2 += Utils.dailyIncrease(runCount, randomizerCurve);
			float num3 = Mathf.Clamp(Mathf.Ceil((float)__instance.profitQuota / num2), value, value2);
			ES3.Save<float>("previousDaily", num2, currentSaveFileName);
			ES3.Save<float>("deadlineAmount", num3, currentSaveFileName);
			__instance.timeUntilDeadline = num * num3;
			TimeOfDay.Instance.SyncTimeClientRpc(__instance.globalTime, (int)__instance.timeUntilDeadline);
			ProgressiveDeadlineMod.Instance.mls.LogInfo((object)$"You're host, new deadline: {num3}");
		}
	}
	[HarmonyPatch(typeof(TimeOfDay), "SyncTimeClientRpc")]
	public class DeadlineDaysAmountSyncPatch
	{
		[HarmonyPostfix]
		private static void deadlineSync(TimeOfDay __instance)
		{
			int deadlineDays = Utils.getDeadlineDays(__instance);
			if (__instance.totalTime == 0f)
			{
				__instance.quotaVariables.deadlineDaysAmount = deadlineDays;
			}
			else if (deadlineDays > __instance.quotaVariables.deadlineDaysAmount)
			{
				__instance.quotaVariables.deadlineDaysAmount = deadlineDays;
				StartOfRound.Instance.companyBuyingRate = Utils.buyingRate(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(TimeOfDay), "SetBuyingRateForDay")]
	public class BuyingRatePatch
	{
		[HarmonyPostfix]
		public static void SetBuyingRate(TimeOfDay __instance)
		{
			StartOfRound.Instance.companyBuyingRate = Utils.buyingRate(__instance);
		}
	}
}