Decompiled source of NoLateNotification v1.0.1

NoLateNotification.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using NoLateNotification.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("NoLateNotification")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NoLateNotification")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ea8f041b-d11f-422a-b9ae-5ff7cea46c0a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 NoLateNotification
{
	[BepInPlugin("Jacky.NoLateNotification", "NolateNotification", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class NoLateNotification : BaseUnityPlugin
	{
		private const string modGUID = "Jacky.NoLateNotification";

		private const string modName = "NolateNotification";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("Jacky.NoLateNotification");

		public static NoLateNotification Instance;

		public static ManualLogSource logger;

		public ConfigEntry<bool> isNoLateNotificationEnabledEntry;

		public ConfigEntry<bool> isRandomNotificationEnabledEntry;

		private void Awake()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = ((BaseUnityPlugin)this).Logger;
			logger.LogInfo((object)"NoLateNotification mod has awaken");
			isNoLateNotificationEnabledEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("NoLateNotification Config", "Disable Time Late Notification", true, "This disables the ship is leaving soon notification!");
			isRandomNotificationEnabledEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("NoLateNotification Config", "Randomize Late Notification", false, "This randomizes the time that the ship is leaving soon notification is displayed!");
			BaseConfigItem val = (BaseConfigItem)new BoolCheckBoxConfigItem(isNoLateNotificationEnabledEntry, false);
			BaseConfigItem val2 = (BaseConfigItem)new BoolCheckBoxConfigItem(isRandomNotificationEnabledEntry, true);
			LethalConfigManager.AddConfigItem(val);
			LethalConfigManager.AddConfigItem(val2);
			harmony.PatchAll(typeof(NotificationPatch));
		}
	}
}
namespace NoLateNotification.Patches
{
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class NotificationPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void disableNotificationPatch(ref bool ___shipLeavingAlertCalled)
		{
			if (NoLateNotification.Instance.isNoLateNotificationEnabledEntry.Value)
			{
				___shipLeavingAlertCalled = true;
			}
		}

		[HarmonyPatch("TimeOfDayEvents")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> randomNotificationPatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			if (NoLateNotification.Instance.isRandomNotificationEnabledEntry.Value)
			{
				for (int i = 0; i < list.Count; i++)
				{
					CodeInstruction val = list[i];
					if (val.opcode == OpCodes.Ldc_R4 && (float)val.operand == 0.9f)
					{
						Random random = new Random();
						val.operand = (float)random.NextDouble();
						CodeInstruction item = new CodeInstruction(OpCodes.Ldc_R4, (object)0.35f);
						CodeInstruction item2 = new CodeInstruction(OpCodes.Mul, (object)null);
						CodeInstruction item3 = new CodeInstruction(OpCodes.Ldc_R4, (object)0.5f);
						CodeInstruction item4 = new CodeInstruction(OpCodes.Add, (object)null);
						list.Insert(i + 1, item);
						list.Insert(i + 2, item2);
						list.Insert(i + 3, item3);
						list.Insert(i + 4, item4);
						break;
					}
				}
			}
			return list;
		}
	}
}
namespace SigurdLib.Util.Extensions
{
	public static class ManualLogSourceExtensions
	{
		private class CodeInstructionFormatter
		{
			private int _instructionIndexPadLength = instructionCount.ToString().Length;

			public CodeInstructionFormatter(int instructionCount)
			{
			}

			public string Format(CodeInstruction instruction, int index)
			{
				return $"    IL_{index.ToString().PadLeft(_instructionIndexPadLength, '0')}: {instruction}";
			}
		}

		public static void LogDebugInstructionsFrom(this ManualLogSource source, CodeMatcher matcher)
		{
			string name = new StackTrace().GetFrame(1).GetMethod().Name;
			CodeInstructionFormatter @object = new CodeInstructionFormatter(matcher.Length);
			StringBuilder stringBuilder = new StringBuilder("'" + name + "' Matcher Instructions:\n").AppendLine(string.Join("\n", matcher.InstructionEnumeration().Select(@object.Format))).AppendLine("End of matcher instructions.");
			source.LogInfo((object)stringBuilder.ToString());
		}

		public static void LogDebugInstructionsFrom(this ManualLogSource source, IEnumerable<CodeInstruction> instructions)
		{
			string name = new StackTrace().GetFrame(1).GetMethod().Name;
			CodeInstruction[] array = instructions.ToArray();
			CodeInstructionFormatter @object = new CodeInstructionFormatter(array.Length);
			StringBuilder stringBuilder = new StringBuilder("'" + name + "' Enumerable Instructions:\n").AppendLine(string.Join("\n", array.Select(@object.Format))).AppendLine("End of matcher instructions.");
			source.LogInfo((object)stringBuilder.ToString());
		}
	}
}