Decompiled source of QuotaRolloverTweaks v1.0.2

plugins/QuotaRolloverTweaks/QuotaRolloverTweaks.dll

Decompiled 2 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 HarmonyLib;
using IL;
using LethalModDataLib.Attributes;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using QuotaRolloverTweaks.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("QuotaRolloverTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("QuotaRolloverTweaks")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ea55591a-2a00-4d63-9d8a-f37f0abf8888")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace QuotaRolloverTweaks
{
	internal class Config
	{
		public static ConfigEntry<bool> currentQuotaScrapOnly;

		public static ConfigEntry<bool> noOvertime;

		public static ConfigEntry<bool> removeFulfilledQuotaOnDeath;

		public static void Load()
		{
			currentQuotaScrapOnly = Plugin.config.Bind<bool>("Overtime Bonus", "OnlyConsiderCurrentQuotasScrap", true, "Only consider newly added scrap this quota towards the overtime bonus. Basically removes rollovered quota from the overtime bonus calculation.");
			noOvertime = Plugin.config.Bind<bool>("Overtime Bonus", "RemoveOvertimeBonus", false, "Disables Overtime bonus by reducing it to 0.");
			removeFulfilledQuotaOnDeath = Plugin.config.Bind<bool>("Death Penalty", "RemoveFulfilledQuotaOnDeath", true, "Sets your fulfilled quota to 0 when all players are dead. Much like when you die and lose all scrap in the ship.");
		}
	}
	[BepInPlugin("33mamaster.QuotaRolloverTweaks", "Quota Rollover Tweaks", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "33mamaster.QuotaRolloverTweaks";

		private const string modName = "Quota Rollover Tweaks";

		private const string modVersion = "1.0.2";

		public static ConfigFile config;

		internal static ManualLogSource Logger;

		private readonly Harmony harmony = new Harmony("33mamaster.QuotaRolloverTweaks");

		private static Plugin Instance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Mod Quota Rollover Tweaks is loaded!");
			config = ((BaseUnityPlugin)this).Config;
			Config.Load();
			TimeOfDayPatch.Init();
			harmony.PatchAll();
		}
	}
	internal static class QuotaRolloverTweaksData
	{
		[ModData(/*Could not decode attribute arguments.*/)]
		internal static int overflowQuota;
	}
}
namespace QuotaRolloverTweaks.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		[HarmonyPostfix]
		private static void DespawnPropsAtEndOfRoundPatch()
		{
			if (StartOfRound.Instance.allPlayersDead && Config.removeFulfilledQuotaOnDeath.Value)
			{
				Plugin.Logger.LogInfo((object)$"Are all players dead?: {StartOfRound.Instance.allPlayersDead}");
				QuotaRolloverTweaksData.overflowQuota = 0;
				TimeOfDay.Instance.quotaFulfilled = 0;
			}
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class TimeOfDayPatch
	{
		internal static void Init()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			if (Config.currentQuotaScrapOnly.Value)
			{
				TimeOfDay.SetNewProfitQuota += new Manipulator(currentQuotaScrapOnly);
			}
			if (Config.noOvertime.Value)
			{
				TimeOfDay.SetNewProfitQuota += new Manipulator(noOvertimeBonus);
			}
		}

		[HarmonyPatch("SetNewProfitQuota")]
		[HarmonyPostfix]
		private static void SaveQuotaFulfillment(ref int ___quotaFulfilled)
		{
			if (TimeOfDay.Instance.daysUntilDeadline < 0)
			{
				Plugin.Logger.LogDebug((object)$"Setting New Overflow Quota: {___quotaFulfilled}");
				QuotaRolloverTweaksData.overflowQuota = ___quotaFulfilled;
			}
		}

		private static void currentQuotaScrapOnly(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			val.GotoNext((MoveType)2, new Func<Instruction, bool>[5]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdarg(i, 0),
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, typeof(TimeOfDay).GetField("quotaFulfilled")),
				(Instruction i) => ILPatternMatchingExt.MatchLdarg(i, 0),
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, typeof(TimeOfDay).GetField("profitQuota")),
				(Instruction i) => i.OpCode == OpCodes.Sub
			});
			val.EmitDelegate<Func<int, int>>((Func<int, int>)delegate(int num)
			{
				int num2 = Mathf.Max(num - QuotaRolloverTweaksData.overflowQuota, 0);
				Plugin.Logger.LogInfo((object)$"Calculated Overtime at: {num2}");
				return num2;
			});
		}

		private static void noOvertimeBonus(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[7]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdarg(i, 0),
				(Instruction i) => ILPatternMatchingExt.MatchLdarg(i, 0),
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, typeof(TimeOfDay).GetField("profitQuota")),
				(Instruction i) => ILPatternMatchingExt.MatchLdloc(i, 1),
				(Instruction i) => ILPatternMatchingExt.MatchLdarg(i, 0),
				(Instruction i) => ILPatternMatchingExt.MatchLdfld(i, typeof(TimeOfDay).GetField("timesFulfilledQuota")),
				(Instruction i) => ILPatternMatchingExt.MatchCall(i, (MethodBase)typeof(TimeOfDay).GetMethod("SyncNewProfitQuotaClientRpc", new Type[3]
				{
					typeof(int),
					typeof(int),
					typeof(int)
				}))
			});
			val.Index += 3;
			val.Remove();
			val.Emit(OpCodes.Ldc_I4_0);
		}
	}
}