Decompiled source of ExtendDays v1.1.0

ExtendDaysMod.dll

Decompiled 4 days 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 LobbyCompatibility.Attributes;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KROOOL.ExtendDaysMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExtendDaysMod")]
[assembly: AssemblyTitle("KROOOL.ExtendDaysMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ExtendDaysMod
{
	[BepInPlugin("KROOOL.ExtendDaysMod", "ExtendDaysMod", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[LobbyCompatibility(/*Could not decode attribute arguments.*/)]
	public class ExtendDaysMod : BaseUnityPlugin
	{
		private static ConfigEntry<int> _cfgQuotaPerDay;

		private static ConfigEntry<int> _cfgDayExtension;

		private static ConfigEntry<int> _cfgMaxExtraDays;

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static int QuotaPerDay => _cfgQuotaPerDay.Value;

		internal static int DayExtension => _cfgDayExtension.Value;

		internal static int MaxExtraDays => _cfgMaxExtraDays.Value;

		private void Awake()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			_cfgQuotaPerDay = ((BaseUnityPlugin)this).Config.Bind<int>("ExtendDays", "QuotaPerDay", 200, "Profit required for +1 extra day");
			_cfgDayExtension = ((BaseUnityPlugin)this).Config.Bind<int>("ExtendDays", "DayExtension", 1, "Number of days added per block");
			_cfgMaxExtraDays = ((BaseUnityPlugin)this).Config.Bind<int>("ExtendDays", "MaxExtraDays", 5, "Maximum extra days allowed");
			RegisterWithLethalConfig();
			PluginHelper.RegisterPlugin("KROOOL.ExtendDaysMod", new Version("1.0.0"), (CompatibilityLevel)2, (VersionStrictness)2);
			Harmony = new Harmony("KROOOL.ExtendDaysMod");
			Harmony.PatchAll();
			Logger.LogInfo((object)"KROOOL.ExtendDaysMod v1.0.0 loaded!");
		}

		private void RegisterWithLethalConfig()
		{
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name.Equals("LethalConfig", StringComparison.OrdinalIgnoreCase));
			if (assembly == null)
			{
				return;
			}
			Type type = assembly.GetType("LethalConfig.LethalConfigManager");
			Type sliderType;
			Type sliderOpt;
			MethodInfo addItem;
			if (!(type == null))
			{
				type.GetMethod("RegisterSection", new Type[2]
				{
					typeof(string),
					typeof(string)
				})?.Invoke(null, new object[2] { "ExtendDays", "ExtendDaysMod Settings" });
				sliderType = assembly.GetType("LethalConfig.ConfigItems.IntSliderConfigItem") ?? assembly.GetType("LethalConfig.ConfigItems.FloatSliderConfigItem");
				sliderOpt = assembly.GetType("LethalConfig.ConfigItems.Options.IntSliderOptions") ?? assembly.GetType("LethalConfig.ConfigItems.Options.FloatSliderOptions");
				addItem = type.GetMethod("AddConfigItem", new Type[1] { typeof(object) });
				if (sliderType != null && sliderOpt != null && addItem != null)
				{
					MakeSlider(_cfgQuotaPerDay, 1, 10000, "Profit required for +1 extra day");
					MakeSlider(_cfgDayExtension, 1, 10, "Days added per block of profit");
					MakeSlider(_cfgMaxExtraDays, 0, 20, "Maximum extra days allowed");
				}
			}
			void MakeSlider(ConfigEntry<int> cfg, int min, int max, string desc)
			{
				ConstructorInfo constructor = sliderType.GetConstructor(new Type[2]
				{
					typeof(ConfigEntry<int>),
					sliderOpt
				});
				object obj = Activator.CreateInstance(sliderOpt);
				sliderOpt.GetProperty("Min").SetValue(obj, min);
				sliderOpt.GetProperty("Max").SetValue(obj, max);
				sliderOpt.GetProperty("Description")?.SetValue(obj, desc);
				object obj2 = constructor.Invoke(new object[2] { cfg, obj });
				addItem.Invoke(null, new object[1] { obj2 });
			}
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("KROOOL.ExtendDaysMod");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "KROOOL.ExtendDaysMod";

		public const string PLUGIN_NAME = "ExtendDaysMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ExtendDaysMod.Patches
{
	[HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")]
	public static class Patch_SetNewProfitQuota_Extend
	{
		private static void Postfix(TimeOfDay __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer)
			{
				int num = __instance.profitQuota / ExtendDaysMod.QuotaPerDay;
				int num2 = num * ExtendDaysMod.DayExtension;
				num2 = Mathf.Min(num2, ExtendDaysMod.MaxExtraDays);
				float num3 = __instance.quotaVariables.deadlineDaysAmount;
				float num4 = __instance.totalTime / num3;
				float num5 = num4 * (float)num2;
				__instance.timeUntilDeadline += num5;
				__instance.daysUntilDeadline += num2;
				ExtendDaysMod.Logger.LogInfo((object)$"[ExtendDaysMod] (Server) +{num2} days → +{num5:F1}s");
			}
		}
	}
	[HarmonyPatch(typeof(TimeOfDay), "SyncNewProfitQuotaClientRpc")]
	public static class Patch_SyncNewProfit_Extend
	{
		private static void Postfix(TimeOfDay __instance, int newProfitQuota, int overtimeBonus, int fulfilledQuota)
		{
			if (((NetworkBehaviour)__instance).IsClient)
			{
				int num = __instance.profitQuota / ExtendDaysMod.QuotaPerDay;
				int num2 = num * ExtendDaysMod.DayExtension;
				num2 = Mathf.Min(num2, ExtendDaysMod.MaxExtraDays);
				float num3 = __instance.quotaVariables.deadlineDaysAmount;
				float num4 = __instance.totalTime / num3;
				float num5 = num4 * (float)num2;
				__instance.timeUntilDeadline += num5;
				__instance.daysUntilDeadline += num2;
				ExtendDaysMod.Logger.LogInfo((object)$"[ExtendDaysMod] (Client) +{num2} days → +{num5:F1}s");
			}
		}
	}
	[HarmonyPatch(typeof(TimeOfDay), "UpdateProfitQuotaCurrentTime")]
	public static class Patch_UpdateQuotaHUD
	{
		private static void Postfix(TimeOfDay __instance)
		{
			if (((NetworkBehaviour)__instance).IsClient)
			{
				int num = __instance.profitQuota / ExtendDaysMod.QuotaPerDay;
				int num2 = num * ExtendDaysMod.DayExtension;
				num2 = Mathf.Min(num2, ExtendDaysMod.MaxExtraDays);
				__instance.daysUntilDeadline += num2;
			}
		}
	}
}