Decompiled source of QuotaTweaks v0.0.3

QuotaTweaks.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("QuotaTweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+be5ef7cb36ebfee2b049cf4601c2957046560ec8")]
[assembly: AssemblyProduct("QuotaTweaks")]
[assembly: AssemblyTitle("QuotaTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 QuotaTweaks
{
	public class ConfigManager
	{
		public static ConfigManager Instance { get; private set; }

		public static ConfigEntry<int> startingQuota { get; private set; }

		public static ConfigEntry<int> quotaMinIncrease { get; private set; }

		public static ConfigEntry<float> quotaIncreaseSteepness { get; private set; }

		public static ConfigEntry<float> quotaRandomizerMultiplier { get; private set; }

		public static void Init(ConfigFile config)
		{
			Instance = new ConfigManager(config);
		}

		private ConfigManager(ConfigFile config)
		{
			startingQuota = config.Bind<int>("Settings", "Starting Quota", 250, "The starting quota for the game.");
			quotaMinIncrease = config.Bind<int>("Settings", "Quota Min Increase", 300, "The minimum amount of quota increase.");
			quotaIncreaseSteepness = config.Bind<float>("Settings", "Quota Increase Steepness", 4f, "The steepness of the quota increase curve - higher value means a less steep exponential increase.");
			quotaRandomizerMultiplier = config.Bind<float>("Settings", "Quota Randomizer Multiplier", 1f, "The multiplier for the quota randomizer - this determines the severity of the randomizer curve.");
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	public class TimeOfDayPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		public static void UpdateQuota(ref TimeOfDay __instance)
		{
			QuotaSettings quotaVariables = __instance.quotaVariables;
			quotaVariables.startingQuota = ConfigManager.startingQuota.Value;
			quotaVariables.baseIncrease = ConfigManager.quotaMinIncrease.Value;
			quotaVariables.increaseSteepness = ConfigManager.quotaIncreaseSteepness.Value;
			quotaVariables.randomizerMultiplier = ConfigManager.quotaRandomizerMultiplier.Value;
		}

		public static void VanillaQuota(TimeOfDay __instance)
		{
			int profitQuota = __instance.profitQuota;
			float baseIncrease = __instance.quotaVariables.baseIncrease;
			int timesFulfilledQuota = __instance.timesFulfilledQuota;
			float increaseSteepness = __instance.quotaVariables.increaseSteepness;
			float randomizerMultiplier = __instance.quotaVariables.randomizerMultiplier;
			float num = (float)(1.0 + (double)timesFulfilledQuota * ((double)timesFulfilledQuota / (double)increaseSteepness));
			double num2 = (double)__instance.quotaVariables.randomizerCurve.Evaluate(Random.Range(0f, 1f)) * (double)randomizerMultiplier + 1.0;
			float num3 = baseIncrease * Mathf.Clamp(num, 0f, 10000f) * (float)num2;
			int num4 = (int)Mathf.Clamp((float)profitQuota + num3, 0f, 1E+09f);
			Plugin.logger.LogDebug((object)"Vanilla Quota Calculation");
			Plugin.logger.LogDebug((object)$"Previous Quota: {profitQuota}");
			Plugin.logger.LogDebug((object)$"Base Increase: {baseIncrease}");
			Plugin.logger.LogDebug((object)$"Times Fulfilled Quota: {timesFulfilledQuota}");
			Plugin.logger.LogDebug((object)$"Increase Steepness: {increaseSteepness}");
			Plugin.logger.LogDebug((object)$"Randomizer Multiplier: {randomizerMultiplier}");
			Plugin.logger.LogDebug((object)$"Variable 1: {num}");
			Plugin.logger.LogDebug((object)$"Variable 2: {num2}");
			Plugin.logger.LogDebug((object)$"Combined: {num3}");
			Plugin.logger.LogDebug((object)$"New Quota: {num4}");
			Plugin.logger.LogDebug((object)"==============");
		}

		[HarmonyPatch("SetNewProfitQuota")]
		[HarmonyPrefix]
		public static bool SetNewProfitQuota(ref TimeOfDay __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return true;
			}
			int profitQuota = __instance.profitQuota;
			int num = __instance.quotaFulfilled - __instance.profitQuota;
			int timesFulfilledQuota = __instance.timesFulfilledQuota;
			float baseIncrease = __instance.quotaVariables.baseIncrease;
			float increaseSteepness = __instance.quotaVariables.increaseSteepness;
			float randomizerMultiplier = __instance.quotaVariables.randomizerMultiplier;
			int num2 = (from obj in GameObject.Find("/Environment/HangarShip").GetComponentsInChildren<GrabbableObject>().ToList()
				where ((Object)obj).name != "ClipboardManual" && ((Object)obj).name != "StickyNoteItem" && ((Object)obj).name != "Key(Clone)" && ((Object)obj).name != "Key"
				where obj.scrapValue > 0
				select obj).ToList().Sum((GrabbableObject scrap) => scrap.scrapValue);
			int scrapValueCollected = StartOfRound.Instance.gameStats.scrapValueCollected;
			int daysSpent = StartOfRound.Instance.gameStats.daysSpent;
			int livingPlayers = StartOfRound.Instance.livingPlayers;
			int num3 = scrapValueCollected / daysSpent;
			int num4 = num3 / livingPlayers;
			float num5 = (float)num2 / (float)profitQuota;
			Plugin.logger.LogDebug((object)"==============");
			Plugin.logger.LogDebug((object)"Quota Calculation");
			Plugin.logger.LogDebug((object)$"Previous Quota: {profitQuota}");
			Plugin.logger.LogDebug((object)$"Base Increase: {baseIncrease}");
			Plugin.logger.LogDebug((object)$"Times Fulfilled Quota: {timesFulfilledQuota}");
			Plugin.logger.LogDebug((object)$"Increase Steepness: {increaseSteepness}");
			Plugin.logger.LogDebug((object)$"Randomizer Multiplier: {randomizerMultiplier}");
			Plugin.logger.LogDebug((object)$"Loot On Ship: {num2}");
			Plugin.logger.LogDebug((object)$"Total Loot Collected: {scrapValueCollected}");
			Plugin.logger.LogDebug((object)$"Days Played: {daysSpent}");
			Plugin.logger.LogDebug((object)$"Players On Ship: {livingPlayers}");
			Plugin.logger.LogDebug((object)$"Money Per Day: {num3}");
			Plugin.logger.LogDebug((object)$"Money Per Player: {num4}");
			Plugin.logger.LogDebug((object)$"Loot As Percent Of Quota: {num5}");
			Plugin.logger.LogDebug((object)"==============");
			VanillaQuota(__instance);
			return true;
		}
	}
	[BepInPlugin("QuotaTweaks", "QuotaTweaks", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource logger;

		private readonly Harmony harmony = new Harmony("QuotaTweaks");

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			ConfigManager.Init(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin QuotaTweaks is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "QuotaTweaks";

		public const string PLUGIN_NAME = "QuotaTweaks";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}