Decompiled source of Readable Notes v1.0.3

plugins/Wren23.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("Wren23")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+13bf810f8f0db3629e1e463013015778230459cd")]
[assembly: AssemblyProduct("Wren23")]
[assembly: AssemblyTitle("Wren23")]
[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 Wren23
{
	[BepInPlugin("sm3gm.wren23", "Readable Notes", "1.0.3")]
	public class Plugin : BasePlugin
	{
		internal const string VER = "1.0.3";

		internal static ManualLogSource LogSource;

		internal static ConfigEntry<bool> StartClear;

		public override void Load()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			LogSource = ((BasePlugin)this).Log;
			StartClear = ((BasePlugin)this).Config.Bind<bool>("Text", "StartInClearText", true, "Open notes and documents in the clear text font. The window's own button still switches back to handwriting.");
			((BasePlugin)this).AddComponent<ClearTextPresser>();
			Harmony.CreateAndPatchAll(typeof(ClearTextByDefault), (string)null);
			Harmony.CreateAndPatchAll(typeof(PlayerPressedAa), (string)null);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Readable Notes ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.3");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
			}
			log.LogInfo(val);
		}
	}
	[HarmonyPatch(typeof(InfoWindow), "Setup")]
	internal static class ClearTextByDefault
	{
		private static void Postfix(InfoWindow __instance)
		{
			if (Plugin.StartClear.Value)
			{
				ClearTextPresser.Queue(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(InfoWindow), "OnClearTextButton")]
	internal static class PlayerPressedAa
	{
		private static void Postfix(InfoWindow __instance)
		{
			if (ClearTextPresser.Pressing || (Object)(object)__instance == (Object)null)
			{
				return;
			}
			try
			{
				string item = ClearTextPresser.Key(__instance);
				if ((Object)(object)__instance.activeContent != (Object)null && __instance.activeContent.clearTextMode)
				{
					ClearTextPresser.Handwriting.Remove(item);
				}
				else
				{
					ClearTextPresser.Handwriting.Add(item);
				}
			}
			catch
			{
			}
		}
	}
	public class ClearTextPresser : MonoBehaviour
	{
		internal static bool Pressing;

		internal static readonly HashSet<string> Handwriting = new HashSet<string>();

		private const int WaitFrames = 2;

		private static readonly List<(InfoWindow window, int frame)> pending = new List<(InfoWindow, int)>();

		internal static string Key(InfoWindow w)
		{
			try
			{
				Evidence passedEvidence = w.passedEvidence;
				string text = ((passedEvidence != null) ? passedEvidence.evID : null);
				if (!string.IsNullOrEmpty(text))
				{
					return text;
				}
			}
			catch
			{
			}
			return "w" + ((Il2CppObjectBase)w).Pointer.ToInt64();
		}

		public ClearTextPresser(IntPtr ptr)
			: base(ptr)
		{
		}

		internal static void Queue(InfoWindow w)
		{
			pending.Add((w, Time.frameCount + 2));
		}

		private void Update()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			bool flag = default(bool);
			for (int num = pending.Count - 1; num >= 0; num--)
			{
				var (val, num2) = pending[num];
				if (Time.frameCount >= num2)
				{
					pending.RemoveAt(num);
					try
					{
						if (!((Object)(object)val == (Object)null) && !Handwriting.Contains(Key(val)) && !((Object)(object)val.clearTextButton == (Object)null) && ((Component)val.clearTextButton).gameObject.activeInHierarchy)
						{
							WindowContentController activeContent = val.activeContent;
							if (!((Object)(object)activeContent == (Object)null) && !activeContent.clearTextMode)
							{
								Pressing = true;
								try
								{
									val.OnClearTextButton();
								}
								finally
								{
									Pressing = false;
								}
							}
						}
					}
					catch (Exception ex)
					{
						ManualLogSource logSource = Plugin.LogSource;
						BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(6, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[W23] ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
						}
						logSource.LogError(val2);
					}
				}
			}
		}
	}
}