Decompiled source of InscryptionWarning v0.1.0

plugins/InscryptionWarning.dll

Decompiled 20 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 InscryptionWarning.Patches;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[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("InscryptionWarning")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+960ddc910412d52b01632943df5e93b742dfa8cb")]
[assembly: AssemblyProduct("InscryptionWarning")]
[assembly: AssemblyTitle("InscryptionWarning")]
[assembly: AssemblyVersion("0.1.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 InscryptionWarning
{
	[BepInPlugin("InscryptionWarning", "InscryptionWarning", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger = new ManualLogSource("InscryptionWarning");

		public void Awake()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin InscryptionWarning is loaded!");
			MapHintPatch.Init(((BaseUnityPlugin)this).Config);
			new Harmony("InscryptionWarning").PatchAll();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "InscryptionWarning";

		public const string PLUGIN_NAME = "InscryptionWarning";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace InscryptionWarning.Patches
{
	internal static class MapHintPatch
	{
		internal enum CueStyle
		{
			Off,
			Diegetic,
			Icon,
			Debug
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static class TrackEventStart
		{
			private static void Postfix(FollowupConditionData data, int currentDistance)
			{
				if (data != null && data.ConditionName == "FollowupConditionInscryptionEvent")
				{
					startDistance = currentDistance;
				}
			}
		}

		[HarmonyPatch(typeof(MapNodeUI), "RefreshState")]
		private static class HintNode
		{
			private static void Postfix(MapNodeUI __instance, SaveManager saveManager)
			{
				GameObject orCreateOverlay = GetOrCreateOverlay(__instance);
				if (!ShouldShowHint(__instance, saveManager))
				{
					orCreateOverlay.SetActive(false);
					return;
				}
				ApplyStyle(orCreateOverlay);
				orCreateOverlay.SetActive(true);
			}
		}

		private const string OverlayName = "InscryptionWarning_Hint";

		private static ConfigEntry<CueStyle> style;

		private static int? startDistance;

		public static void Init(ConfigFile config)
		{
			style = config.Bind<CueStyle>("Hint", "CueStyle", CueStyle.Diegetic, "How obvious the Inscryption path hint should be on the map: Off (disabled), Diegetic (a barely-there tint on the correct node), Icon (a small visible badge), Debug (an unmissable marker).");
			SelfCheck();
		}

		internal static BranchSelection? GetHintedBranch(int startDistance, int nodeDistance, int code)
		{
			int num = nodeDistance - (startDistance + 1);
			if (num < 0 || num > 2)
			{
				return null;
			}
			return (BranchSelection)((((code >> 2 - num) & 1) != 0) ? 1 : 0);
		}

		private static void SelfCheck()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0021: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			if ((int)GetHintedBranch(10, 11, 5).GetValueOrDefault() != 1 || GetHintedBranch(10, 12, 5) != (BranchSelection?)0 || (int)GetHintedBranch(10, 13, 5).GetValueOrDefault() != 1 || GetHintedBranch(10, 10, 5).HasValue || GetHintedBranch(10, 14, 5).HasValue)
			{
				throw new InvalidOperationException("MapHintPatch.GetHintedBranch self-check failed");
			}
		}

		private static bool ShouldShowHint(MapNodeUI node, SaveManager saveManager)
		{
			//IL_005f: 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)
			if (style.Value == CueStyle.Off || !startDistance.HasValue || (Object)(object)saveManager == (Object)null)
			{
				return false;
			}
			if (saveManager.GetInscryptionEventSuccessfullyCompleted())
			{
				return false;
			}
			Location location = node.GetLocation();
			if (location == null)
			{
				return false;
			}
			BranchSelection? hintedBranch = GetHintedBranch(startDistance.Value, location.Distance, saveManager.GetInscryptionEventPath());
			if (hintedBranch.HasValue)
			{
				return (BranchSelection?)node.GetBranch() == hintedBranch;
			}
			return false;
		}

		private static GameObject GetOrCreateOverlay(MapNodeUI node)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			Transform val = ((Component)node).transform.Find("InscryptionWarning_Hint");
			if ((Object)(object)val != (Object)null)
			{
				return ((Component)val).gameObject;
			}
			GameObject val2 = new GameObject("InscryptionWarning_Hint", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val2.transform.SetParent(((Component)node).transform, false);
			((Graphic)val2.GetComponent<Image>()).raycastTarget = false;
			return val2;
		}

		private static void ApplyStyle(GameObject overlay)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0039: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)overlay.transform;
			Image component = overlay.GetComponent<Image>();
			switch (style.Value)
			{
			case CueStyle.Icon:
				val.anchorMin = new Vector2(0.5f, 1f);
				val.anchorMax = new Vector2(0.5f, 1f);
				val.pivot = new Vector2(0.5f, 0.5f);
				val.sizeDelta = new Vector2(20f, 20f);
				val.anchoredPosition = Vector2.zero;
				((Graphic)component).color = new Color(1f, 0.85f, 0.3f, 0.95f);
				break;
			case CueStyle.Debug:
				val.anchorMin = Vector2.zero;
				val.anchorMax = Vector2.one;
				val.offsetMin = Vector2.zero;
				val.offsetMax = Vector2.zero;
				((Graphic)component).color = new Color(1f, 0.1f, 0.9f, 0.8f);
				break;
			default:
				val.anchorMin = Vector2.zero;
				val.anchorMax = Vector2.one;
				val.offsetMin = Vector2.zero;
				val.offsetMax = Vector2.zero;
				((Graphic)component).color = new Color(1f, 0.85f, 0.3f, 0.14f);
				break;
			}
		}
	}
}