Decompiled source of ExtraDaysToDeadline v2.2.2

BepInEx/plugins/ExtraDaysToDeadline.dll

Decompiled 9 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Anubis.LC.ExtraDays.Commands;
using Anubis.LC.ExtraDays.Extensions;
using Anubis.LC.ExtraDays.Helpers;
using Anubis.LC.ExtraDays.ModNetwork;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalAPI.LibTerminal;
using LethalAPI.LibTerminal.Attributes;
using LethalAPI.LibTerminal.Interactions;
using LethalAPI.LibTerminal.Interfaces;
using LethalAPI.LibTerminal.Models;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using RuntimeNetcodeRPCValidator;
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: AssemblyCompany("Anubis")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows the player to purchase an extra day via the terminal. This mod's uniqueness is that It tries to add functionality that will give you the option to extend the deadline but with some price on it.")]
[assembly: AssemblyFileVersion("2.2.2.0")]
[assembly: AssemblyInformationalVersion("2.2.2+6bda7a25166c2f9fd67964c7f4cf74e9cd8791f5")]
[assembly: AssemblyProduct("ExtraDaysToDeadline")]
[assembly: AssemblyTitle("ExtraDaysToDeadline")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.2.2.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;
		}
	}
}
[HarmonyPatch(typeof(Terminal))]
internal static class TerminalPatch
{
	[HarmonyPatch("BeginUsingTerminal")]
	[HarmonyPostfix]
	public static void BeginUsingTerminal(Terminal __instance)
	{
		if (StartOfRound.Instance.companyBuyingRate <= 0f)
		{
			ModStaticHelper.Logger.LogInfo((object)"Company buying rate is lower than zero, recalculating...");
			TimeOfDay.Instance.ReCalculateBuyingRateForCompany();
		}
		else
		{
			TimeOfDay.Instance.ReCalculateBuyingRateForCompany(tryGetFromDisk: true);
		}
	}

	[HarmonyPatch("QuitTerminal")]
	[HarmonyPostfix]
	public static void QuitTerminal(Terminal __instance)
	{
		CommandHandler.HandleCommandInput("help", __instance);
	}
}
namespace Anubis.LC.ExtraDays
{
	[BepInPlugin("ExtraDaysToDeadline", "ExtraDaysToDeadline", "2.2.2")]
	[BepInDependency("NicholaScott.BepInEx.RuntimeNetcodeRPCValidator", "0.2.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ExtraDaysToDeadlinePlugin : BaseUnityPlugin
	{
		private const string modGUID = "ExtraDaysToDeadline";

		private const string modName = "ExtraDaysToDeadline";

		private const string modVersion = "2.2.2";

		private Harmony m_Harmony = new Harmony("ExtraDaysToDeadline");

		private TerminalModRegistry m_Registry;

		public static ExtraDaysToDeadlinePlugin Instance;

		private NetcodeValidator netcodeValidator;

		private void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			netcodeValidator = new NetcodeValidator("ExtraDaysToDeadline");
			netcodeValidator.PatchAll();
			netcodeValidator.BindToPreExistingObjectByBehaviour<Networking, Terminal>();
			ModStaticHelper.Logger.LogInfo((object)"ExtraDaysToDeadline is loading...");
			ModStaticHelper.Logger.LogInfo((object)"Installing patches");
			m_Harmony.PatchAll(typeof(ExtraDaysToDeadlinePlugin).Assembly);
			ModStaticHelper.Logger.LogInfo((object)"Registering built-in Commands");
			m_Registry = TerminalRegistry.CreateTerminalRegistry();
			m_Registry.RegisterFrom<BuyExtraDaysCommands>();
			LethalConfigHelper.SetLehalConfig(((BaseUnityPlugin)this).Config);
			Object.DontDestroyOnLoad((Object)(object)this);
			ModStaticHelper.Logger.LogInfo((object)"Plugin ExtraDaysToDeadline is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ExtraDaysToDeadline";

		public const string PLUGIN_NAME = "ExtraDaysToDeadline";

		public const string PLUGIN_VERSION = "2.2.2";
	}
}
namespace Anubis.LC.ExtraDays.Patches
{
	[HarmonyPatch(typeof(DeleteFileButton))]
	public class DeleteFileButtonPatch
	{
		[HarmonyPatch("DeleteFile")]
		[HarmonyPrefix]
		public static void DeleteFile()
		{
			if (LethalConfigHelper.GetConfigForSaveFile().TryGetValue("correlatedPrice", out var value))
			{
				((ConfigEntry<bool>)(object)value).Value = (bool)value.DefaultValue;
			}
			if (LethalConfigHelper.GetConfigForSaveFile().TryGetValue("buyingRate", out var value2))
			{
				((ConfigEntry<bool>)(object)value2).Value = (bool)value2.DefaultValue;
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	public class ResetSavedValuesPatch
	{
		[HarmonyPatch("ResetSavedGameValues")]
		[HarmonyPostfix]
		public static void ResetSavedValues()
		{
			string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
			if (!ModStaticHelper.IsThisModInstalled("LethalExpansion"))
			{
				ModStaticHelper.Logger.LogInfo((object)("Reset deadline days amount for save file " + currentSaveFileName));
				ES3.Save<int>(ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS_SAVE_KEY, ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS, currentSaveFileName);
			}
			else
			{
				ModStaticHelper.Logger.LogInfo((object)("Reset deadline days amount for save file " + currentSaveFileName + ", using LethalExpansion"));
				ES3.Save<int>(ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS_SAVE_KEY, TimeOfDay.Instance.quotaVariables.deadlineDaysAmount, currentSaveFileName);
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	public class RoundManagerPatch
	{
		public static int PreviousDaysUntilDeadline = TimeOfDay.Instance.daysUntilDeadline;

		public static bool DaysUntilDeadlineModuluRan = false;

		[HarmonyPatch("AdvanceHourAndSpawnNewBatchOfEnemies")]
		[HarmonyPatch("BeginEnemySpawning")]
		[HarmonyPrefix]
		public static void Prefix_PlotOutEnemiesForNextHour()
		{
			if (TimeOfDay.Instance.daysUntilDeadline > ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS)
			{
				ModStaticHelper.Logger.LogInfo((object)"Adjusting enemies in higer deadline - Start");
				PreviousDaysUntilDeadline = TimeOfDay.Instance.daysUntilDeadline;
				TimeOfDay.Instance.daysUntilDeadline = TimeOfDay.Instance.daysUntilDeadline % ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS;
				DaysUntilDeadlineModuluRan = true;
			}
		}

		[HarmonyPatch("AdvanceHourAndSpawnNewBatchOfEnemies")]
		[HarmonyPatch("BeginEnemySpawning")]
		[HarmonyPostfix]
		public static void Postfix_PlotOutEnemiesForNextHour()
		{
			if (DaysUntilDeadlineModuluRan)
			{
				TimeOfDay.Instance.daysUntilDeadline = PreviousDaysUntilDeadline;
				DaysUntilDeadlineModuluRan = false;
				ModStaticHelper.Logger.LogInfo((object)"Adjusting enemies in higer deadline - End");
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public static class StartOfRoundPatch
	{
		[HarmonyPatch("ResetShip")]
		[HarmonyPostfix]
		public static void Postfix_ResetShip(StartOfRound __instance)
		{
			TimeOfDay.Instance.ResetDeadline(isShipReset: true);
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	internal static class TimeOfDayPatch
	{
		[HarmonyPatch("SetNewProfitQuota")]
		[HarmonyPostfix]
		public static void SetNewProfitQuota(TimeOfDay __instance)
		{
			__instance.ResetDeadline();
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start(TimeOfDay __instance)
		{
			__instance.ReCalculateBuyingRateForCompany(tryGetFromDisk: true);
		}
	}
}
namespace Anubis.LC.ExtraDays.ModNetwork
{
	internal class Networking : NetworkBehaviour
	{
		public static Networking Instance;

		public int extraDaysPrice;

		public bool isCorrelatedPrice;

		public bool isReduceBuyingRate;

		[ServerRpc(RequireOwnership = false)]
		public void SetReduceBuyingRateServerRpc(bool _isReduce)
		{
			if (((NetworkBehaviour)this).IsHost)
			{
				ModStaticHelper.Logger.LogInfo((object)$"Setup correlated price for everyone {_isReduce}");
				SetReduceBuyingRateClientRpc(_isReduce);
			}
		}

		[ClientRpc]
		public void SetReduceBuyingRateClientRpc(bool _isReduce)
		{
			ModStaticHelper.Logger.LogInfo((object)$"Setup extra day price for player, {_isReduce}");
			isReduceBuyingRate = _isReduce;
		}

		[ServerRpc(RequireOwnership = false)]
		public void SetCorrelatedPriceServerRpc(bool _isCorrelated)
		{
			if (((NetworkBehaviour)this).IsHost)
			{
				ModStaticHelper.Logger.LogInfo((object)$"Setup correlated price for everyone {_isCorrelated}");
				SetCorrelatedPriceClientRpc(_isCorrelated);
				if (_isCorrelated)
				{
					SetExtraDaysPriceServerRpc(null);
				}
			}
		}

		[ClientRpc]
		public void SetCorrelatedPriceClientRpc(bool _isCorrelated)
		{
			ModStaticHelper.Logger.LogInfo((object)$"Setup extra day price for player, {_isCorrelated}");
			isCorrelatedPrice = _isCorrelated;
		}

		[ServerRpc(RequireOwnership = false)]
		public void SetExtraDaysPriceServerRpc(int? _extraDaysPrice)
		{
			if (((NetworkBehaviour)this).IsHost)
			{
				TimeOfDay.Instance.SetExtraDaysPrice();
				int num = (_extraDaysPrice.HasValue ? _extraDaysPrice.Value : TimeOfDay.Instance.GetExtraDaysPrice());
				ModStaticHelper.Logger.LogInfo((object)$"Setup extra day price for everyone {num}");
				SetExtraDaysPriceClientRpc(num);
			}
		}

		[ClientRpc]
		public void SetExtraDaysPriceClientRpc(int _extraDaysPrice)
		{
			ModStaticHelper.Logger.LogInfo((object)$"Setup extra day price for player, {_extraDaysPrice}");
			extraDaysPrice = _extraDaysPrice;
			TimeOfDay.Instance.SyncTimeAndDeadline();
		}

		[ServerRpc(RequireOwnership = false)]
		public void BuyExtraDayServerRpc()
		{
			BuyExtraDayClientRpc();
		}

		[ClientRpc]
		public void BuyExtraDayClientRpc()
		{
			if (((NetworkBehaviour)this).IsHost)
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				if ((Object)(object)val == (Object)null)
				{
					ModStaticHelper.Logger.LogWarning((object)"Could not find Terminal object. Might be sync issues");
				}
				else
				{
					val.SetDaysToDeadline();
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SyncTimeServerRpc()
		{
			SyncTimeClientRpc();
		}

		[ClientRpc]
		public void SyncTimeClientRpc()
		{
			TimeOfDay.Instance.SyncTimeAndDeadline();
		}

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				((MonoBehaviour)this).StartCoroutine(WaitForSomeTime());
			}
		}

		private IEnumerator WaitForSomeTime()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => ((NetworkBehaviour)this).NetworkObject.IsSpawned));
			if (LethalConfigHelper.GetConfigForSaveFile().TryGetValue("correlatedPrice", out var value))
			{
				SetCorrelatedPriceServerRpc(((ConfigEntry<bool>)(object)value).Value);
			}
			if (LethalConfigHelper.GetConfigForSaveFile().TryGetValue("buyingRate", out var value2))
			{
				SetReduceBuyingRateServerRpc(((ConfigEntry<bool>)(object)value2).Value);
			}
			if (LethalConfigHelper.GetConfigForSaveFile().TryGetValue("extraDayPrice", out var value3))
			{
				SetExtraDaysPriceServerRpc(((ConfigEntry<int>)(object)value3).Value);
				SyncTimeServerRpc();
			}
		}
	}
}
namespace Anubis.LC.ExtraDays.Helpers
{
	public static class LethalConfigHelper
	{
		public static Dictionary<string, Dictionary<string, ConfigEntryBase>> SaveFilesConfigurations;

		public static void SetLehalConfig(ConfigFile config)
		{
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Expected O, but got Unknown
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Expected O, but got Unknown
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Expected O, but got Unknown
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Expected O, but got Unknown
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Expected O, but got Unknown
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Expected O, but got Unknown
			SaveFilesConfigurations = new Dictionary<string, Dictionary<string, ConfigEntryBase>>();
			int num = 0;
			string[] files = ES3.GetFiles();
			foreach (string text in files)
			{
				if (ES3.FileExists(text) && text.StartsWith("LCSaveFile"))
				{
					num++;
				}
			}
			ModStaticHelper.Logger.LogInfo((object)$"There are {num} save files");
			if (num > 3)
			{
				int num2 = 1;
				files = ES3.GetFiles();
				foreach (string text2 in files)
				{
					if (!ES3.FileExists(text2) || !text2.StartsWith("LCSaveFile"))
					{
						continue;
					}
					int num3 = num2++;
					Dictionary<string, ConfigEntryBase> dictionary = new Dictionary<string, ConfigEntryBase>();
					ConfigEntry<bool> correlatedPrice = config.Bind<bool>($"Save File {num3}", "Use price correlated calculation?", true, "This determines if the price to buy an extra day will be constant value (350 credits) or correlated to the quota (dynamic)");
					correlatedPrice.SettingChanged += delegate
					{
						if (Object.op_Implicit((Object)(object)Networking.Instance) && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
						{
							Networking.Instance.SetCorrelatedPriceServerRpc(correlatedPrice.Value);
						}
					};
					ConfigEntry<bool> val = config.Bind<bool>($"Save File {num3}", "Use reduce buying rate?", false, "This determines if the buying rate will reduce a bit after buying an extra day");
					ConfigEntry<int> extraDayPrice2 = config.Bind<int>($"Save File {num3}", "Setup extra day price", ModStaticHelper.CONSTANT_PRICE, "This configure the price of an extra day only if `correlated calculation` field is OFF");
					extraDayPrice2.SettingChanged += delegate
					{
						if (Object.op_Implicit((Object)(object)Networking.Instance) && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
						{
							Networking.Instance.SetExtraDaysPriceServerRpc(extraDayPrice2.Value);
						}
					};
					LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(correlatedPrice, false));
					ConfigEntry<int> obj2 = extraDayPrice2;
					IntSliderOptions val2 = new IntSliderOptions();
					((BaseRangeOptions<int>)val2).Min = 250;
					((BaseRangeOptions<int>)val2).Max = 1700;
					((BaseOptions)val2).RequiresRestart = false;
					LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(obj2, val2));
					LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val, false));
					dictionary.Add("correlatedPrice", (ConfigEntryBase)(object)correlatedPrice);
					dictionary.Add("buyingRate", (ConfigEntryBase)(object)val);
					dictionary.Add("extraDayPrice", (ConfigEntryBase)(object)extraDayPrice2);
					SaveFilesConfigurations.Add(text2, dictionary);
				}
			}
			else
			{
				for (int j = 0; j < 3; j++)
				{
					int num4 = j + 1;
					Dictionary<string, ConfigEntryBase> dictionary2 = new Dictionary<string, ConfigEntryBase>();
					ConfigEntry<bool> correlatedPrice2 = config.Bind<bool>($"Save File {num4}", "Use price correlated calculation?", true, "This determines if the price to buy an extra day will be constant value (350 credits) or correlated to the quota (dynamic)");
					correlatedPrice2.SettingChanged += delegate
					{
						if (Object.op_Implicit((Object)(object)Networking.Instance) && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
						{
							Networking.Instance.SetCorrelatedPriceServerRpc(correlatedPrice2.Value);
						}
					};
					ConfigEntry<bool> val3 = config.Bind<bool>($"Save File {num4}", "Use reduce buying rate?", false, "This determines if the buying rate will reduce a bit after buying an extra day");
					ConfigEntry<int> extraDayPrice = config.Bind<int>($"Save File {num4}", "Setup extra day price", ModStaticHelper.CONSTANT_PRICE, "This configure the price of an extra day only if `correlated calculation` field is OFF");
					extraDayPrice.SettingChanged += delegate
					{
						if (Object.op_Implicit((Object)(object)Networking.Instance) && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
						{
							Networking.Instance.SetExtraDaysPriceServerRpc(extraDayPrice.Value);
						}
					};
					LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(correlatedPrice2, false));
					ConfigEntry<int> obj3 = extraDayPrice;
					IntSliderOptions val4 = new IntSliderOptions();
					((BaseRangeOptions<int>)val4).Min = 250;
					((BaseRangeOptions<int>)val4).Max = 1700;
					((BaseOptions)val4).RequiresRestart = false;
					LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(obj3, val4));
					LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val3, false));
					dictionary2.Add("correlatedPrice", (ConfigEntryBase)(object)correlatedPrice2);
					dictionary2.Add("buyingRate", (ConfigEntryBase)(object)val3);
					dictionary2.Add("extraDayPrice", (ConfigEntryBase)(object)extraDayPrice);
					SaveFilesConfigurations.Add($"LCSaveFile{j}", dictionary2);
				}
			}
			LethalConfigManager.SetModIcon(LoadNewSprite(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icon.png")));
			LethalConfigManager.SetModDescription("Allows the player to purchase an extra day via the terminal. This mod's uniqueness is that it tries to be more realistic with the game, as it is not trying to modify the main logic of the deadline. It tries to add functionality that will give you extends for the deadline but with some price on it.");
		}

		public static Dictionary<string, ConfigEntryBase> GetConfigForSaveFile()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			SaveFilesConfigurations.TryGetValue(GameNetworkManager.Instance.currentSaveFileName, out var value);
			if (value == null)
			{
				ModStaticHelper.Logger.LogError((object)"Could not find save file. Using defaults configuration for save files");
				Dictionary<string, ConfigEntryBase> dictionary = new Dictionary<string, ConfigEntryBase>();
				ConfigEntry<bool> correlatedPrice = ((BaseUnityPlugin)ExtraDaysToDeadlinePlugin.Instance).Config.Bind<bool>("Save File 1", "Use price correlated calculation?", true, "This determines if the price to buy an extra day will be constant value (350 credits) or correlated to the quota (dynamic)");
				correlatedPrice.SettingChanged += delegate
				{
					if (Object.op_Implicit((Object)(object)Networking.Instance) && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
					{
						Networking.Instance.SetCorrelatedPriceServerRpc(correlatedPrice.Value);
					}
				};
				ConfigEntry<bool> val = ((BaseUnityPlugin)ExtraDaysToDeadlinePlugin.Instance).Config.Bind<bool>("Save File 1", "Use reduce buying rate?", false, "This determines if the buying rate will reduce a bit after buying an extra day");
				ConfigEntry<int> val2 = ((BaseUnityPlugin)ExtraDaysToDeadlinePlugin.Instance).Config.Bind<int>("Save File 1", "Setup extra day price", ModStaticHelper.CONSTANT_PRICE, "This configure the price of an extra day only if `correlated calculation` field is OFF");
				LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(correlatedPrice, false));
				IntSliderOptions val3 = new IntSliderOptions();
				((BaseRangeOptions<int>)val3).Min = 250;
				((BaseRangeOptions<int>)val3).Max = 1700;
				((BaseOptions)val3).RequiresRestart = false;
				LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(val2, val3));
				LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val, false));
				dictionary.Add("correlatedPrice", (ConfigEntryBase)(object)correlatedPrice);
				dictionary.Add("buyingRate", (ConfigEntryBase)(object)val);
				dictionary.Add("extraDayPrice", (ConfigEntryBase)(object)val2);
				return dictionary;
			}
			return value;
		}

		private static Sprite LoadNewSprite(string filePath, float pixelsPerUnit = 100f)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Texture2D val = LoadTexture(filePath);
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0f, 0f), pixelsPerUnit);
			}
			catch
			{
				return null;
			}
		}

		private static Texture2D LoadTexture(string filePath)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (File.Exists(filePath))
			{
				byte[] array = File.ReadAllBytes(filePath);
				Texture2D val = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val, array))
				{
					return val;
				}
			}
			return null;
		}
	}
	public class ModStaticHelper
	{
		public const string modGUID = "ExtraDaysToDeadline";

		public const string modName = "ExtraDaysToDeadline";

		public const string modVersion = "2.2.2";

		public static ManualLogSource Logger = Logger.CreateLogSource("ExtraDaysToDeadline");

		public static readonly int DAYS_TO_INCREASE = 1;

		public static readonly int DEFAULT_AMOUNT_OF_DEADLINE_DAYS = 3;

		public static readonly string DEFAULT_AMOUNT_OF_DEADLINE_DAYS_SAVE_KEY = "ExtraDaysToDeadline_deadlineDaysAmount";

		public static readonly int CONSTANT_PRICE = 350;

		public static bool IsThisModInstalled(string mod)
		{
			if (Chainloader.PluginInfos.TryGetValue(mod, out var _))
			{
				Logger.LogInfo((object)("Mod $" + mod + " is loaded alongside ExtraDaysToDeadline"));
				return true;
			}
			return false;
		}
	}
}
namespace Anubis.LC.ExtraDays.Extensions
{
	public static class TerminalExtensions
	{
		public static bool IsExtraDaysPurchasable(this Terminal terminal)
		{
			return terminal.groupCredits >= TimeOfDay.Instance.GetExtraDaysPrice();
		}

		public static void SetDaysToDeadline(this Terminal terminal)
		{
			ModStaticHelper.Logger.LogInfo((object)$"Player input CONFIRM and {ModStaticHelper.DAYS_TO_INCREASE} day to deadline has been added");
			float num = TimeOfDay.Instance.GetExtraDaysPrice();
			terminal.groupCredits -= (int)num;
			terminal.SyncGroupCreditsServerRpc(terminal.groupCredits, terminal.numberOfItemsInDropship);
			TimeOfDay.Instance.AddXDaysToDeadline(ModStaticHelper.DAYS_TO_INCREASE);
		}
	}
	public static class TimeOfDayExtensions
	{
		private static int extraDayPrice;

		public static void AddXDaysToDeadline(this TimeOfDay timeOfDay, float days = 1f)
		{
			timeOfDay.timeUntilDeadline += timeOfDay.totalTime * days;
			timeOfDay.ReCalculateBuyingRateForCompany();
			Networking.Instance.SyncTimeServerRpc();
			ModStaticHelper.Logger.LogInfo((object)$"Added {ModStaticHelper.DAYS_TO_INCREASE} day to deadline.");
		}

		public static int CalculateDeadlineDaysAmount(this TimeOfDay timeOfDay)
		{
			int num = (int)Mathf.Floor(timeOfDay.timeUntilDeadline / timeOfDay.totalTime);
			if (num <= ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS)
			{
				return ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS;
			}
			return num;
		}

		public static void SetExtraDaysPrice(this TimeOfDay timeOfDay)
		{
			ConfigEntryBase value;
			if (Networking.Instance.isCorrelatedPrice)
			{
				int profitQuota = timeOfDay.profitQuota;
				float num = 0.15f * (float)profitQuota;
				float num2 = 0.5f * (float)profitQuota;
				float num3 = timeOfDay.quotaVariables.randomizerCurve.Evaluate(Random.Range(0f, 1f)) * timeOfDay.quotaVariables.randomizerMultiplier + 1f;
				extraDayPrice = (int)Mathf.Clamp(num * num3, num2, 1E+09f);
			}
			else if (LethalConfigHelper.GetConfigForSaveFile().TryGetValue("extraDayPrice", out value))
			{
				extraDayPrice = ((ConfigEntry<int>)(object)value).Value;
			}
			else
			{
				extraDayPrice = ModStaticHelper.CONSTANT_PRICE;
			}
		}

		public static int GetExtraDaysPrice(this TimeOfDay timeOfDay)
		{
			if (!Networking.Instance.isCorrelatedPrice)
			{
				return Networking.Instance.extraDaysPrice;
			}
			return extraDayPrice;
		}

		public static void ResetDeadline(this TimeOfDay timeOfDay, bool isShipReset = false)
		{
			if (isShipReset && ModStaticHelper.IsThisModInstalled("LethalExpansion"))
			{
				timeOfDay.timeUntilDeadline = timeOfDay.totalTime * (float)TimeOfDay.Instance.quotaVariables.deadlineDaysAmount;
				ModStaticHelper.Logger.LogInfo((object)"Deadline reset to defaults (Compatibility for Lethal Expansion)");
			}
			else if (isShipReset || !ModStaticHelper.IsThisModInstalled("Haha.DynamicDeadline") || !ModStaticHelper.IsThisModInstalled("BrutalCompany") || !ModStaticHelper.IsThisModInstalled("BrutalCompanyPlus") || !ModStaticHelper.IsThisModInstalled("LethalOrg.ProgressiveDeadline") || !ModStaticHelper.IsThisModInstalled("LethalExpansion"))
			{
				timeOfDay.timeUntilDeadline = timeOfDay.totalTime * (float)ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS;
				ModStaticHelper.Logger.LogInfo((object)"Deadline reset to defaults");
			}
			timeOfDay.ReCalculateBuyingRateForCompany();
			timeOfDay.SyncTimeAndDeadline();
		}

		public static void ReCalculateBuyingRateForCompany(this TimeOfDay timeOfDay, bool tryGetFromDisk = false)
		{
			timeOfDay.SetDeadlineDaysAmount(tryGetFromDisk);
			timeOfDay.SetBuyingRateForDay();
			timeOfDay.SetReduceBuyingRate();
			StartOfRound.Instance.SyncCompanyBuyingRateServerRpc();
			ModStaticHelper.Logger.LogInfo((object)"Buying rate recalculated");
		}

		public static void SetReduceBuyingRate(this TimeOfDay timeOfDay)
		{
			if (Networking.Instance.isReduceBuyingRate)
			{
				ModStaticHelper.Logger.LogInfo((object)"Reduced buying rate is ON");
				float num = 0.01f * (float)timeOfDay.quotaVariables.deadlineDaysAmount;
				float companyBuyingRate = StartOfRound.Instance.companyBuyingRate;
				float num2 = StartOfRound.Instance.companyBuyingRate - num;
				ModStaticHelper.Logger.LogInfo((object)$"Current rate: {companyBuyingRate}, Next rate: {num2}");
				if (companyBuyingRate >= 0.9f && num2 > 0.7f)
				{
					ModStaticHelper.Logger.LogInfo((object)$"Buying rate set to: {num2}");
					StartOfRound.Instance.companyBuyingRate = num2;
				}
				else
				{
					ModStaticHelper.Logger.LogInfo((object)"Buying rate did not change due to chance of very low rate");
				}
			}
		}

		public static void SetDeadlineDaysAmount(this TimeOfDay timeOfDay, bool tryGetFromDisk = false)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				int num = ((!tryGetFromDisk) ? timeOfDay.CalculateDeadlineDaysAmount() : timeOfDay.GetDeadlineDaysAmountFromDisk());
				if (!ModStaticHelper.IsThisModInstalled("LethalExpansion"))
				{
					timeOfDay.quotaVariables.deadlineDaysAmount = num;
				}
				else
				{
					num = timeOfDay.quotaVariables.deadlineDaysAmount;
				}
				string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
				ES3.Save<int>(ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS_SAVE_KEY, num, currentSaveFileName);
				ModStaticHelper.Logger.LogInfo((object)$"Deadline days amount: {num} (To calculate buying rate)");
			}
		}

		public static int GetDeadlineDaysAmountFromDisk(this TimeOfDay timeOfDay)
		{
			string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
			int num;
			if (!ES3.KeyExists(ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS_SAVE_KEY, currentSaveFileName))
			{
				ES3.Save<int>(ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS_SAVE_KEY, timeOfDay.CalculateDeadlineDaysAmount(), currentSaveFileName);
				num = ES3.Load<int>(ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS_SAVE_KEY, currentSaveFileName);
				ModStaticHelper.Logger.LogInfo((object)$"Saved deadlineDaysAmount to disk and then loaded, deadlineDaysAmount: {num}");
			}
			else
			{
				num = ES3.Load<int>(ModStaticHelper.DEFAULT_AMOUNT_OF_DEADLINE_DAYS_SAVE_KEY, currentSaveFileName);
				ModStaticHelper.Logger.LogInfo((object)$"Loaded deadlineDaysAmount from disk, deadlineDaysAmount: {num}");
			}
			return num;
		}

		public static void SyncTimeAndDeadline(this TimeOfDay timeOfDay)
		{
			timeOfDay.SyncTimeClientRpc(timeOfDay.globalTime, (int)timeOfDay.timeUntilDeadline);
			timeOfDay.UpdateProfitQuotaCurrentTime();
			ModStaticHelper.Logger.LogInfo((object)"Deadline sync");
		}
	}
}
namespace Anubis.LC.ExtraDays.Commands
{
	public class BuyExtraDaysCommands
	{
		[RequireInterface(typeof(ConfirmInteraction))]
		[TerminalCommand("deny", false)]
		public string DenyBuyExtraDays(Terminal terminal)
		{
			terminal.terminalAudio.PlayOneShot(terminal.syncedAudios[1]);
			ModStaticHelper.Logger.LogInfo((object)"Player denied so the deadline didn't change!");
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("Cancelled order.");
			stringBuilder.AppendLine();
			return stringBuilder.ToString();
		}

		[RequireInterface(typeof(ConfirmInteraction))]
		[TerminalCommand("confirm", false)]
		public string ConfirmBuyExtraDays(Terminal terminal)
		{
			StringBuilder stringBuilder = new StringBuilder();
			if (!terminal.IsExtraDaysPurchasable())
			{
				terminal.terminalAudio.PlayOneShot(terminal.syncedAudios[1]);
				ModStaticHelper.Logger.LogInfo((object)"Player has insufficient credits to purchase an extra day");
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("You don't have enough credits to buy an extra day.");
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("Cancelled order.");
				stringBuilder.AppendLine();
				return stringBuilder.ToString();
			}
			terminal.terminalAudio.PlayOneShot(terminal.syncedAudios[0]);
			Networking.Instance.BuyExtraDayServerRpc();
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("An extra day has been added to your deadline. Don't waste it!");
			stringBuilder.AppendLine();
			stringBuilder.AppendLine($"({TimeOfDay.Instance.daysUntilDeadline} day(s) remaining)");
			stringBuilder.AppendLine();
			return stringBuilder.ToString();
		}

		[TerminalCommand("buyday", true)]
		[CommandInfo("Ask the Company for an extra day to reach the quota", "")]
		public ITerminalInteraction BuyDaysCommand()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			new StringBuilder();
			return (ITerminalInteraction)new ConfirmInteraction(new TerminalNode
			{
				displayText = $"You're about to ask the Company for ONE extra day to reach the profit quota. It will cost you {TimeOfDay.Instance.GetExtraDaysPrice()} credits ({TimeOfDay.Instance.daysUntilDeadline} day(s) remaining).",
				clearPreviousText = true,
				name = "buyday"
			}, (Delegate)new Func<Terminal, string>(ConfirmBuyExtraDays), (Delegate)new Func<Terminal, string>(DenyBuyExtraDays));
		}
	}
}