Decompiled source of Sailwind Receipt Alert v1.1.1

BepInEx/plugins/SailwindReceiptAlert/SailwindReceiptAlert.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 SailwindReceiptAlert
{
	[HarmonyPatch(typeof(NotificationUi), "ShowNotification", new Type[]
	{
		typeof(string),
		typeof(float)
	})]
	internal static class NotificationWidth
	{
		private const float ReceiptWidth = 1.2f;

		private static Vector3? normalScale;

		private static bool missingLogged;

		private static void Postfix(string notification, GameObject ___UI)
		{
			//IL_003b: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ___UI.transform.Find("notification UI");
			if (!Object.op_Implicit((Object)(object)val))
			{
				if (!missingLogged)
				{
					Plugin.Log.LogWarning((object)"Could not find the notification parchment; receipt messages use the normal width.");
				}
				missingLogged = true;
				return;
			}
			Vector3 valueOrDefault = normalScale.GetValueOrDefault();
			Vector3 val2;
			if (!normalScale.HasValue)
			{
				valueOrDefault = val.localScale;
				normalScale = valueOrDefault;
				val2 = valueOrDefault;
			}
			else
			{
				val2 = valueOrDefault;
			}
			Vector3 val3 = val2;
			bool flag = notification == "Don't forget your trade receipt!" || notification == "Trade receipt collected!";
			val.localScale = (Vector3)(flag ? new Vector3(val3.x * 1.2f, val3.y, val3.z) : val3);
		}
	}
	[BepInPlugin("skeptic043.sailwind.receiptalert", "Sailwind Receipt Alert", "1.1.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Id = "skeptic043.sailwind.receiptalert";

		public const string Name = "Sailwind Receipt Alert";

		public const string Version = "1.1.1";

		internal const string ReminderText = "Don't forget your trade receipt!";

		internal const string CollectedText = "Trade receipt collected!";

		internal static ManualLogSource Log;

		private static ConfigEntry<bool> enabledSetting;

		private static ConfigEntry<bool> autoCollectSetting;

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			enabledSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Handle uncollected trade receipts when leaving a port desk area.");
			autoCollectSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AutoCollectReceipt", false, "Automatically collect an available trade receipt on exit instead of showing a reminder.");
			new Harmony("skeptic043.sailwind.receiptalert").PatchAll(typeof(Plugin).Assembly);
		}

		internal static void OnLeftDesk()
		{
			NotificationUi instance = NotificationUi.instance;
			EconomyUIReceiptScribe instance2 = EconomyUIReceiptScribe.instance;
			if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance2))
			{
				ExitAction exitAction = ReceiptExit.Decide(enabledSetting.Value, instance2.ReceiptAvailable(), autoCollectSetting.Value, Object.op_Implicit((Object)(object)TradeReceiptsUI.instance));
				if (exitAction == ExitAction.Collect && instance2.RequestCurrentReceipt())
				{
					instance.ShowNotification("Trade receipt collected!");
				}
				else if (exitAction == ExitAction.Remind)
				{
					instance.ShowNotification("Don't forget your trade receipt!");
				}
			}
		}
	}
	internal enum ExitAction
	{
		None,
		Remind,
		Collect
	}
	internal static class ReceiptExit
	{
		internal static ExitAction Decide(bool enabled, bool receiptWaiting, bool autoCollect, bool receiptBookReady)
		{
			if (!enabled || !receiptWaiting)
			{
				return ExitAction.None;
			}
			if (!(autoCollect && receiptBookReady))
			{
				return ExitAction.Remind;
			}
			return ExitAction.Collect;
		}
	}
	public sealed class ReceiptZone : MonoBehaviour
	{
		private static readonly Vector3 Size = new Vector3(12f, 4f, 12f);

		private static readonly Vector3 Offset = new Vector3(0f, 0.5f, 0f);

		internal static void Attach(Transform desk)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Receipt Alert Zone");
			val.SetActive(false);
			val.transform.SetParent(desk, false);
			Vector3 lossyScale = desk.lossyScale;
			val.transform.localPosition = new Vector3(Offset.x / lossyScale.x, Offset.y / lossyScale.y, Offset.z / lossyScale.z);
			val.transform.localScale = new Vector3(1f / lossyScale.x, 1f / lossyScale.y, 1f / lossyScale.z);
			Rigidbody obj = val.AddComponent<Rigidbody>();
			obj.isKinematic = true;
			obj.useGravity = false;
			BoxCollider obj2 = val.AddComponent<BoxCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.size = Size;
			val.AddComponent<ReceiptZone>();
			val.SetActive(true);
		}

		private void OnTriggerExit(Collider other)
		{
			if (((Component)other).CompareTag("Player"))
			{
				Plugin.OnLeftDesk();
			}
		}
	}
	[HarmonyPatch(typeof(PortDude), "Awake")]
	internal static class PortDudeAwakePatch
	{
		private static void Postfix(PortDude __instance)
		{
			try
			{
				ReceiptZone.Attach(((Component)__instance).transform);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogWarning((object)$"Could not add the receipt zone at {((Object)__instance).name}: {arg}");
			}
		}
	}
}