Decompiled source of HighDeadlineSpawningFix v1.1.0

lunasa2307.HighDeadlineSpawningFix.dll

Decompiled a day ago
using System;
using System.Diagnostics;
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 HighDeadlineSpawningFix.Hooks;
using IL;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
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("lunasa2307.HighDeadlineSpawningFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HighDeadlineSpawningFix")]
[assembly: AssemblyTitle("lunasa2307.HighDeadlineSpawningFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 HighDeadlineSpawningFix
{
	public enum DeadlineClampType
	{
		None,
		Clamp,
		Modulo
	}
	[BepInPlugin("lunasa2307.HighDeadlineSpawningFix", "HighDeadlineSpawningFix", "1.0.0")]
	public class HighDeadlineSpawningFix : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__PatchDaysUntilDeadlineAccess;
		}

		public static HighDeadlineSpawningFix Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		public static ConfigFile Config { get; private set; }

		public static ConfigEntry<DeadlineClampType> ClampType { get; private set; }

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

		private static void InitConfig()
		{
			ClampType = Config.Bind<DeadlineClampType>("High Deadline Spawning Fix Settings", "Clamp Type", DeadlineClampType.Modulo, "Sets the clamp type.\nNone = Disables clamping (vanilla behavior)\nClamp = clamps daysUntilDeadline used in calculations to a maximum value\nModulo = gets the mod 4 of the daysUntilDeadline used in calculations (e.g. 4 Days Before Deadline will be treated as 0 Days Before Deadline by the spawning script).");
			ClampValue = Config.Bind<int>("High Deadline Spawning Fix Settings", "Clamp Value (Clamp)", 3, "When Clamp Type is set to Clamp, sets the maximum amount of days left before deadline. Has no effect if None or Modulo is selected.");
		}

		private void Awake()
		{
			Config = ((BaseUnityPlugin)this).Config;
			InitConfig();
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Hook();
			Logger.LogInfo((object)"lunasa2307.HighDeadlineSpawningFix v1.0.0 has loaded!");
		}

		internal static void Hook()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			Logger.LogDebug((object)"Hooking...");
			object obj = <>O.<0>__PatchDaysUntilDeadlineAccess;
			if (obj == null)
			{
				Manipulator val = RoundManagerHook.PatchDaysUntilDeadlineAccess;
				<>O.<0>__PatchDaysUntilDeadlineAccess = val;
				obj = (object)val;
			}
			RoundManager.PredictAllOutsideEnemies += (Manipulator)obj;
			object obj2 = <>O.<0>__PatchDaysUntilDeadlineAccess;
			if (obj2 == null)
			{
				Manipulator val2 = RoundManagerHook.PatchDaysUntilDeadlineAccess;
				<>O.<0>__PatchDaysUntilDeadlineAccess = val2;
				obj2 = (object)val2;
			}
			RoundManager.SpawnEnemiesOutside += (Manipulator)obj2;
			object obj3 = <>O.<0>__PatchDaysUntilDeadlineAccess;
			if (obj3 == null)
			{
				Manipulator val3 = RoundManagerHook.PatchDaysUntilDeadlineAccess;
				<>O.<0>__PatchDaysUntilDeadlineAccess = val3;
				obj3 = (object)val3;
			}
			RoundManager.PlotOutEnemiesForNextHour += (Manipulator)obj3;
			object obj4 = <>O.<0>__PatchDaysUntilDeadlineAccess;
			if (obj4 == null)
			{
				Manipulator val4 = RoundManagerHook.PatchDaysUntilDeadlineAccess;
				<>O.<0>__PatchDaysUntilDeadlineAccess = val4;
				obj4 = (object)val4;
			}
			RoundManager.AdvanceHourAndSpawnNewBatchOfEnemies += (Manipulator)obj4;
			Logger.LogDebug((object)"Finished Hooking!");
		}

		internal static void Unhook()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			Logger.LogDebug((object)"Unhooking...");
			object obj = <>O.<0>__PatchDaysUntilDeadlineAccess;
			if (obj == null)
			{
				Manipulator val = RoundManagerHook.PatchDaysUntilDeadlineAccess;
				<>O.<0>__PatchDaysUntilDeadlineAccess = val;
				obj = (object)val;
			}
			RoundManager.PredictAllOutsideEnemies -= (Manipulator)obj;
			object obj2 = <>O.<0>__PatchDaysUntilDeadlineAccess;
			if (obj2 == null)
			{
				Manipulator val2 = RoundManagerHook.PatchDaysUntilDeadlineAccess;
				<>O.<0>__PatchDaysUntilDeadlineAccess = val2;
				obj2 = (object)val2;
			}
			RoundManager.SpawnEnemiesOutside -= (Manipulator)obj2;
			object obj3 = <>O.<0>__PatchDaysUntilDeadlineAccess;
			if (obj3 == null)
			{
				Manipulator val3 = RoundManagerHook.PatchDaysUntilDeadlineAccess;
				<>O.<0>__PatchDaysUntilDeadlineAccess = val3;
				obj3 = (object)val3;
			}
			RoundManager.PlotOutEnemiesForNextHour -= (Manipulator)obj3;
			object obj4 = <>O.<0>__PatchDaysUntilDeadlineAccess;
			if (obj4 == null)
			{
				Manipulator val4 = RoundManagerHook.PatchDaysUntilDeadlineAccess;
				<>O.<0>__PatchDaysUntilDeadlineAccess = val4;
				obj4 = (object)val4;
			}
			RoundManager.AdvanceHourAndSpawnNewBatchOfEnemies -= (Manipulator)obj4;
			Logger.LogDebug((object)"Finished Unhooking!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "lunasa2307.HighDeadlineSpawningFix";

		public const string PLUGIN_NAME = "HighDeadlineSpawningFix";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace HighDeadlineSpawningFix.Hooks
{
	public static class RoundManagerHook
	{
		public static void PatchDaysUntilDeadlineAccess(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);
			int num = 0;
			while (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction i) => ILPatternMatchingExt.MatchLdfld<TimeOfDay>(i, "daysUntilDeadline")
			}))
			{
				val.Remove();
				val.EmitDelegate<Func<TimeOfDay, int>>((Func<TimeOfDay, int>)ClampedDaysUntilDeadline);
				num++;
			}
			HighDeadlineSpawningFix.Logger.LogInfo((object)$"Patched {num} occurence(s).");
		}

		private static int ClampedDaysUntilDeadline(TimeOfDay tod)
		{
			DeadlineClampType value = HighDeadlineSpawningFix.ClampType.Value;
			if (1 == 0)
			{
			}
			int result = value switch
			{
				DeadlineClampType.Clamp => Mathf.Min(HighDeadlineSpawningFix.ClampValue.Value, tod.daysUntilDeadline), 
				DeadlineClampType.Modulo => tod.daysUntilDeadline % 4, 
				_ => tod.daysUntilDeadline, 
			};
			if (1 == 0)
			{
			}
			return result;
		}
	}
}