Decompiled source of ThorinsLogbook v1.0.0

BepInEx\plugins\ThorinsLogbook\ThorinsLogbook.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("ThorinsLogbook")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ThorinsLogbook")]
[assembly: AssemblyTitle("ThorinsLogbook")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 AdventurersLogbookMod
{
	public static class Gfx
	{
		private static readonly Dictionary<string, Sprite> _iconCache = new Dictionary<string, Sprite>();

		private static Texture2D _clear;

		private static Texture2D _background;

		private static Texture2D _leather;

		private static Texture2D _leatherLight;

		private static Texture2D _gold;

		private static Texture2D _parchment;

		private static Texture2D _paper;

		public static Sprite BookIcon => BookIconFor("");

		public static Texture2D Background
		{
			get
			{
				if ((Object)(object)_background == (Object)null)
				{
					_background = LoadBackground();
				}
				if (!((Object)(object)_background != (Object)null))
				{
					return Parchment;
				}
				return _background;
			}
		}

		public static Texture2D Clear
		{
			get
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Expected O, but got Unknown
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_clear == (Object)null)
				{
					_clear = new Texture2D(1, 1, (TextureFormat)4, false);
					_clear.SetPixel(0, 0, Color.clear);
					_clear.Apply();
				}
				return _clear;
			}
		}

		public static Texture2D Leather
		{
			get
			{
				if ((Object)(object)_leather == (Object)null)
				{
					_leather = ToTexture(BuildLeather());
				}
				return _leather;
			}
		}

		public static Texture2D LeatherLight
		{
			get
			{
				if ((Object)(object)_leatherLight == (Object)null)
				{
					_leatherLight = ToTexture(BuildLeatherLight());
				}
				return _leatherLight;
			}
		}

		public static Texture2D Gold
		{
			get
			{
				if ((Object)(object)_gold == (Object)null)
				{
					_gold = ToTexture(BuildGold());
				}
				return _gold;
			}
		}

		public static Texture2D Parchment
		{
			get
			{
				if ((Object)(object)_parchment == (Object)null)
				{
					_parchment = ToTexture(BuildParchment());
				}
				return _parchment;
			}
		}

		public static Texture2D Paper
		{
			get
			{
				if ((Object)(object)_paper == (Object)null)
				{
					_paper = ToTexture(BuildPaper());
				}
				return _paper;
			}
		}

		public static Sprite BookIconFor(string name)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			string text = name ?? "";
			if (_iconCache.TryGetValue(text, out var value))
			{
				return value;
			}
			Texture2D val = ToTexture(BuildBookIcon(text));
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			_iconCache[text] = val2;
			return val2;
		}

		private static Texture2D LoadBackground()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			try
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				string[] array = new string[2]
				{
					Path.Combine(directoryName, "background.png"),
					Path.Combine(directoryName, "background.jpg")
				};
				foreach (string text in array)
				{
					if (!File.Exists(text))
					{
						continue;
					}
					Bitmap val = new Bitmap(text);
					try
					{
						int num = 1024;
						int num2 = Math.Max(1, (int)((float)((Image)val).Height / (float)((Image)val).Width * (float)num));
						Bitmap val2 = new Bitmap(num, num2, (PixelFormat)2498570);
						Graphics val3 = Graphics.FromImage((Image)(object)val2);
						try
						{
							val3.SmoothingMode = (SmoothingMode)2;
							val3.InterpolationMode = (InterpolationMode)7;
							val3.DrawImage((Image)(object)val, 0, 0, num, num2);
						}
						finally
						{
							((IDisposable)val3)?.Dispose();
						}
						return ToTexture(val2);
					}
					finally
					{
						((IDisposable)val)?.Dispose();
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("ThorinsLogbook: could not load background image: " + ex.Message));
			}
			return null;
		}

		private static Bitmap BuildBookIcon(string name)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Expected O, but got Unknown
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Expected O, but got Unknown
			Bitmap val = NewBitmap(96, 96);
			Graphics val2 = Begin(val);
			try
			{
				Color color = Color.FromArgb(255, 89, 63, 32);
				Color color2 = Color.FromArgb(255, 56, 39, 17);
				Color color3 = Color.FromArgb(255, 243, 226, 181);
				Color color4 = Color.FromArgb(255, 172, 128, 70);
				Color color5 = Color.FromArgb(230, 88, 70, 47);
				Color color6 = Color.FromArgb(255, 152, 31, 45);
				Color color7 = Color.FromArgb(255, 118, 22, 36);
				FillRounded(val2, (Brush)new SolidBrush(color), 10, 14, 76, 68, 9);
				DrawRounded(val2, new Pen(color2, 3f), 10, 14, 76, 68, 9);
				val2.FillRectangle((Brush)new SolidBrush(color2), 10, 14, 13, 68);
				val2.DrawLine(new Pen(Color.FromArgb(255, 163, 122, 62), 1.5f), 24, 14, 24, 82);
				FillRounded(val2, (Brush)new SolidBrush(color3), 34, 26, 40, 44, 5);
				DrawRounded(val2, new Pen(color4, 1.5f), 34, 26, 40, 44, 5);
				val2.DrawLine(new Pen(color5, 1.6f), 38, 36, 70, 36);
				val2.DrawLine(new Pen(color5, 1.6f), 38, 43, 63, 43);
				val2.DrawLine(new Pen(color5, 1.6f), 38, 50, 70, 50);
				val2.DrawLine(new Pen(color5, 1.6f), 38, 57, 55, 57);
				val2.FillEllipse((Brush)new SolidBrush(color6), 56, 20, 18, 18);
				val2.FillEllipse((Brush)new SolidBrush(color7), 60, 24, 10, 10);
				if (!string.IsNullOrEmpty(name))
				{
					Rectangle rectangle = new Rectangle(46, 72, 30, 8);
					val2.FillRectangle((Brush)new SolidBrush(Color.FromArgb(235, 30, 20, 10)), rectangle);
					Font val3 = new Font("Georgia", 7.5f, (FontStyle)1);
					string text = FitText(val2, name, val3, rectangle.Width - 4);
					StringFormat val4 = new StringFormat
					{
						Alignment = (StringAlignment)1,
						LineAlignment = (StringAlignment)1
					};
					try
					{
						val2.DrawString(text, val3, (Brush)new SolidBrush(Color.FromArgb(255, 236, 220, 178)), (RectangleF)rectangle, val4);
					}
					finally
					{
						((IDisposable)val4)?.Dispose();
					}
					val3.Dispose();
				}
			}
			finally
			{
				((IDisposable)val2)?.Dispose();
			}
			return val;
		}

		private static string FitText(Graphics g, string text, Font font, int maxWidth)
		{
			if (string.IsNullOrEmpty(text) || g.MeasureString(text, font).Width <= (float)maxWidth)
			{
				return text;
			}
			string text2 = text;
			while (text2.Length > 1 && g.MeasureString(text2 + "…", font).Width > (float)maxWidth)
			{
				text2 = text2.Substring(0, text2.Length - 1);
			}
			return text2 + "…";
		}

		private static Bitmap BuildLeather()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			Bitmap val = NewBitmap(256, 256);
			Graphics val2 = Begin(val);
			try
			{
				val2.Clear(Color.FromArgb(255, 94, 67, 37));
				Random random = new Random(11);
				for (int i = 0; i < 1200; i++)
				{
					int num = random.Next(256);
					int num2 = random.Next(256);
					int alpha = 30 + random.Next(46);
					Color color = ((i % 2 == 0) ? Color.FromArgb(alpha, 46, 32, 15) : Color.FromArgb(alpha, 122, 90, 52));
					val2.FillRectangle((Brush)new SolidBrush(color), num, num2, 2, 2);
				}
				Vignette(val2, 256, 256, Color.FromArgb(200, 30, 19, 9), 52);
				Pen val3 = new Pen(Color.FromArgb(120, 40, 28, 14), 1f);
				try
				{
					for (int j = 8; j < 248; j += 8)
					{
						val2.DrawLine(val3, j, 6, j + 4, 6);
						val2.DrawLine(val3, j, 249, j + 4, 249);
					}
					return val;
				}
				finally
				{
					((IDisposable)val3)?.Dispose();
				}
			}
			finally
			{
				((IDisposable)val2)?.Dispose();
			}
		}

		private static Bitmap BuildLeatherLight()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			Bitmap val = NewBitmap(256, 256);
			Graphics val2 = Begin(val);
			try
			{
				val2.Clear(Color.FromArgb(255, 122, 88, 50));
				Random random = new Random(23);
				for (int i = 0; i < 600; i++)
				{
					int num = random.Next(256);
					int num2 = random.Next(256);
					int alpha = 26 + random.Next(40);
					Color color = ((i % 2 == 0) ? Color.FromArgb(alpha, 62, 44, 22) : Color.FromArgb(alpha, 150, 112, 66));
					val2.FillRectangle((Brush)new SolidBrush(color), num, num2, 2, 2);
				}
				Vignette(val2, 256, 256, Color.FromArgb(180, 40, 28, 14), 40);
				return val;
			}
			finally
			{
				((IDisposable)val2)?.Dispose();
			}
		}

		private static Bitmap BuildGold()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			Bitmap val = NewBitmap(16, 16);
			Graphics val2 = Begin(val);
			try
			{
				val2.Clear(Color.FromArgb(255, 206, 162, 74));
				Pen val3 = new Pen(Color.FromArgb(255, 158, 118, 44), 1f);
				try
				{
					val2.DrawRectangle(val3, 0, 0, 15, 15);
					return val;
				}
				finally
				{
					((IDisposable)val3)?.Dispose();
				}
			}
			finally
			{
				((IDisposable)val2)?.Dispose();
			}
		}

		private static Bitmap BuildParchment()
		{
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Expected O, but got Unknown
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Expected O, but got Unknown
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Expected O, but got Unknown
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Expected O, but got Unknown
			int num = 1024;
			Bitmap val = NewBitmap(num, num);
			Graphics val2 = Begin(val);
			try
			{
				val2.Clear(Color.FromArgb(255, 236, 219, 172));
				Random random = new Random(7);
				for (int i = 0; i < 2600; i++)
				{
					int num2 = random.Next(num);
					int num3 = random.Next(num);
					switch (random.Next(3))
					{
					case 0:
						val2.FillRectangle((Brush)new SolidBrush(Color.FromArgb(6 + random.Next(10), 116, 94, 60)), num2, num3, 2, 2);
						break;
					case 1:
						val2.FillRectangle((Brush)new SolidBrush(Color.FromArgb(6 + random.Next(10), 255, 250, 226)), num2, num3, 2, 2);
						break;
					default:
						val2.FillEllipse((Brush)new SolidBrush(Color.FromArgb(3 + random.Next(8), 132, 106, 62)), num2, num3, 3, 2);
						break;
					}
				}
				Radial(val2, (float)num * 0.22f, (float)num * 0.18f, (float)num * 0.24f, Color.FromArgb(170, 182, 152, 98), Color.FromArgb(0, 182, 152, 98));
				Radial(val2, (float)num * 0.78f, (float)num * 0.3f, (float)num * 0.3f, Color.FromArgb(150, 168, 138, 88), Color.FromArgb(0, 168, 138, 88));
				Radial(val2, (float)num * 0.68f, (float)num * 0.82f, (float)num * 0.26f, Color.FromArgb(160, 192, 162, 108), Color.FromArgb(0, 192, 162, 108));
				Radial(val2, (float)num * 0.28f, (float)num * 0.86f, (float)num * 0.2f, Color.FromArgb(140, 158, 130, 82), Color.FromArgb(0, 158, 130, 82));
				Radial(val2, (float)num * 0.5f, (float)num * 0.5f, (float)num * 0.55f, Color.FromArgb(0, 226, 214, 178), Color.FromArgb(120, 150, 118, 66));
				Radial(val2, (float)num * 0.05f, (float)num * 0.05f, (float)num * 0.16f, Color.FromArgb(190, 70, 50, 24), Color.FromArgb(0, 70, 50, 24));
				Radial(val2, (float)num * 0.95f, (float)num * 0.06f, (float)num * 0.15f, Color.FromArgb(180, 84, 58, 30), Color.FromArgb(0, 84, 58, 30));
				Radial(val2, (float)num * 0.05f, (float)num * 0.95f, (float)num * 0.15f, Color.FromArgb(180, 84, 58, 30), Color.FromArgb(0, 84, 58, 30));
				Radial(val2, (float)num * 0.95f, (float)num * 0.94f, (float)num * 0.16f, Color.FromArgb(190, 70, 50, 24), Color.FromArgb(0, 70, 50, 24));
				Pen val3 = new Pen(Color.FromArgb(14, 190, 172, 128), 1f);
				try
				{
					for (int j = 0; j < 260; j++)
					{
						int num4 = random.Next(num);
						int num5 = random.Next(num);
						int num6 = 12 + random.Next(70);
						float num7 = (float)(random.Next(160) - 80) * 0.7f * 0.0174533f;
						int num8 = (int)(Math.Cos(num7) * (double)num6);
						int num9 = (int)(Math.Sin(num7) * (double)num6);
						if (j % 3 == 0)
						{
							val3.Color = Color.FromArgb(8, 96, 74, 42);
						}
						else
						{
							val3.Color = Color.FromArgb(10, 210, 192, 148);
						}
						val2.DrawLine(val3, num4, num5, num4 + num8, num5 + num9);
					}
				}
				finally
				{
					((IDisposable)val3)?.Dispose();
				}
				val2.DrawLine(new Pen(Color.FromArgb(150, 122, 92, 50), 1f), 78, 92, 78, num - 92);
				val2.DrawLine(new Pen(Color.FromArgb(110, 122, 92, 50), 1f), 84, 92, 84, num - 92);
				Pen val4 = new Pen(Color.FromArgb(80, 150, 128, 86), 1f);
				try
				{
					for (int k = 120; k < num - 60; k += 44)
					{
						val2.DrawLine(val4, 96, k, num - 64, k);
					}
				}
				finally
				{
					((IDisposable)val4)?.Dispose();
				}
				Pen val5 = new Pen(Color.FromArgb(210, 140, 104, 52), 2f);
				try
				{
					val2.DrawRectangle(val5, 28, 28, num - 56, num - 56);
					val2.DrawRectangle(val5, 40, 40, num - 80, num - 80);
				}
				finally
				{
					((IDisposable)val5)?.Dispose();
				}
				Vignette(val2, num, num, Color.FromArgb(220, 74, 52, 26), 70);
				return val;
			}
			finally
			{
				((IDisposable)val2)?.Dispose();
			}
		}

		private static void Radial(Graphics g, float cx, float cy, float r, Color center, Color edge)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			GraphicsPath val = new GraphicsPath();
			try
			{
				val.AddEllipse(cx - r, cy - r, r * 2f, r * 2f);
				PathGradientBrush val2 = new PathGradientBrush(val);
				try
				{
					val2.CenterColor = center;
					val2.SurroundColors = new Color[1] { edge };
					val2.SetSigmaBellShape(0.6f, 1f);
					g.FillPath((Brush)(object)val2, val);
				}
				finally
				{
					((IDisposable)val2)?.Dispose();
				}
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}

		private static Bitmap BuildPaper()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			Bitmap val = NewBitmap(24, 24);
			Graphics val2 = Begin(val);
			try
			{
				val2.Clear(Color.FromArgb(255, 247, 238, 212));
				Pen val3 = new Pen(Color.FromArgb(255, 138, 109, 63), 1.5f);
				try
				{
					val2.DrawRectangle(val3, 0, 0, 23, 23);
					return val;
				}
				finally
				{
					((IDisposable)val3)?.Dispose();
				}
			}
			finally
			{
				((IDisposable)val2)?.Dispose();
			}
		}

		private static void FillRounded(Graphics g, Brush brush, int x, int y, int w, int h, int r)
		{
			GraphicsPath val = RoundedPath(x, y, w, h, r);
			try
			{
				g.FillPath(brush, val);
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}

		private static void DrawRounded(Graphics g, Pen pen, int x, int y, int w, int h, int r)
		{
			GraphicsPath val = RoundedPath(x, y, w, h, r);
			try
			{
				g.DrawPath(pen, val);
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}

		private static GraphicsPath RoundedPath(int x, int y, int w, int h, int r)
		{
			//IL_0000: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			GraphicsPath val = new GraphicsPath();
			int num = r * 2;
			val.AddArc(x, y, num, num, 180f, 90f);
			val.AddArc(x + w - num, y, num, num, 270f, 90f);
			val.AddArc(x + w - num, y + h - num, num, num, 0f, 90f);
			val.AddArc(x, y + h - num, num, num, 90f, 90f);
			val.CloseFigure();
			return val;
		}

		private static void Vignette(Graphics g, int w, int h, Color edge, int steps)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			for (int i = 0; i < steps; i++)
			{
				SolidBrush val = new SolidBrush(Color.FromArgb((int)((float)(int)edge.A * ((float)(steps - i) / (float)steps)), edge.R, edge.G, edge.B));
				try
				{
					g.DrawRectangle(new Pen((Brush)(object)val, 1f), i, i, w - 2 - i * 2, h - 2 - i * 2);
				}
				finally
				{
					((IDisposable)val)?.Dispose();
				}
			}
		}

		private static Bitmap NewBitmap(int w, int h)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			return new Bitmap(w, h, (PixelFormat)2498570);
		}

		private static Graphics Begin(Bitmap bmp)
		{
			Graphics obj = Graphics.FromImage((Image)(object)bmp);
			obj.SmoothingMode = (SmoothingMode)4;
			obj.CompositingQuality = (CompositingQuality)2;
			return obj;
		}

		private static Texture2D ToTexture(Bitmap bmp)
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			int width = ((Image)bmp).Width;
			int height = ((Image)bmp).Height;
			BitmapData val = bmp.LockBits(new Rectangle(0, 0, width, height), (ImageLockMode)1, (PixelFormat)2498570);
			int stride = val.Stride;
			byte[] array = new byte[stride * height];
			Marshal.Copy(val.Scan0, array, 0, array.Length);
			bmp.UnlockBits(val);
			Color32[] array2 = (Color32[])(object)new Color32[width * height];
			for (int i = 0; i < height; i++)
			{
				int num = i * stride;
				int num2 = height - 1 - i;
				for (int j = 0; j < width; j++)
				{
					int num3 = num + j * 4;
					array2[num2 * width + j] = new Color32(array[num3 + 2], array[num3 + 1], array[num3], array[num3 + 3]);
				}
			}
			Texture2D val2 = new Texture2D(width, height, (TextureFormat)4, false);
			val2.SetPixels32(array2);
			val2.Apply();
			return val2;
		}
	}
	public static class JournalGui
	{
		private static readonly string[] PageLabels = new string[3] { "Page I", "Page II", "Page III" };

		private const int MaxBodyChars = 4000;

		private static Vector2 _scroll;

		private static GUIStyle _header;

		private static GUIStyle _headerField;

		private static GUIStyle _tab;

		private static GUIStyle _label;

		private static GUIStyle _field;

		private static GUIStyle _fieldFocus;

		private static GUIStyle _area;

		private static GUIStyle _button;

		private static void EnsureStyles()
		{
			//IL_0026: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Expected O, but got Unknown
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Expected O, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Expected O, but got Unknown
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Expected O, but got Unknown
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Expected O, but got Unknown
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Expected O, but got Unknown
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Expected O, but got Unknown
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Expected O, but got Unknown
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Expected O, but got Unknown
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Expected O, but got Unknown
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Expected O, but got Unknown
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_053e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			//IL_055f: Expected O, but got Unknown
			if (_header == null)
			{
				GUI.skin.settings.cursorColor = new Color(0f, 0f, 0f, 1f);
				GUI.skin.settings.selectionColor = new Color(1f, 0.8f, 0.35f, 0.5f);
				_header = new GUIStyle(GUI.skin.label);
				_header.fontSize = 26;
				_header.fontStyle = (FontStyle)1;
				_header.alignment = (TextAnchor)4;
				_header.normal.textColor = new Color(0.9f, 0.76f, 0.36f);
				_headerField = new GUIStyle(GUI.skin.textField);
				_headerField.fontSize = 24;
				_headerField.fontStyle = (FontStyle)1;
				_headerField.alignment = (TextAnchor)4;
				_headerField.normal.background = Gfx.Clear;
				_headerField.normal.textColor = new Color(0f, 0f, 0f, 1f);
				_headerField.hover.background = Gfx.Clear;
				_headerField.active.background = Gfx.Clear;
				_headerField.focused.background = Gfx.Clear;
				_headerField.focused.textColor = new Color(0f, 0f, 0f, 1f);
				_headerField.border = new RectOffset(4, 4, 4, 4);
				_tab = new GUIStyle(GUI.skin.button);
				_tab.fontSize = 14;
				_tab.fontStyle = (FontStyle)1;
				_tab.alignment = (TextAnchor)4;
				_tab.normal.background = Gfx.Leather;
				_tab.normal.textColor = new Color(0.95f, 0.89f, 0.75f);
				_tab.hover.background = Gfx.LeatherLight;
				_tab.hover.textColor = Color.white;
				_tab.active.background = Gfx.Gold;
				_tab.active.textColor = new Color(0.25f, 0.18f, 0.06f);
				_tab.onNormal.background = Gfx.Gold;
				_tab.onNormal.textColor = new Color(0.25f, 0.18f, 0.06f);
				_tab.border = new RectOffset(12, 12, 12, 12);
				_label = new GUIStyle(GUI.skin.label);
				_label.fontSize = 15;
				_label.normal.textColor = new Color(0.2f, 0.13f, 0.06f);
				_field = new GUIStyle(GUI.skin.textField);
				_field.fontSize = 16;
				_field.normal.background = Gfx.Clear;
				_field.normal.textColor = new Color(0.15f, 0.1f, 0.05f);
				_field.border = new RectOffset(6, 6, 6, 6);
				_fieldFocus = new GUIStyle(_field);
				_fieldFocus.hover.background = Gfx.Clear;
				_fieldFocus.active.background = Gfx.Clear;
				_fieldFocus.focused.background = Gfx.Clear;
				_fieldFocus.focused.textColor = _field.normal.textColor;
				_area = new GUIStyle(GUI.skin.textArea);
				_area.fontSize = 16;
				_area.normal.background = Gfx.Clear;
				_area.normal.textColor = new Color(0.15f, 0.1f, 0.05f);
				_area.active.background = Gfx.Clear;
				_area.focused.background = Gfx.Clear;
				_area.border = new RectOffset(8, 8, 8, 8);
				_area.wordWrap = true;
				_area.padding = new RectOffset(10, 10, 8, 8);
				_button = new GUIStyle(GUI.skin.button);
				_button.fontSize = 15;
				_button.fontStyle = (FontStyle)1;
				_button.alignment = (TextAnchor)4;
				_button.normal.background = Gfx.Leather;
				_button.normal.textColor = new Color(0.95f, 0.89f, 0.75f);
				_button.hover.background = Gfx.LeatherLight;
				_button.hover.textColor = Color.white;
				_button.active.background = Gfx.Gold;
				_button.active.textColor = new Color(0.25f, 0.18f, 0.06f);
				_button.border = new RectOffset(10, 10, 10, 10);
			}
		}

		public static void Draw()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			EnsureStyles();
			float num = 700f;
			float num2 = 560f;
			float num3 = ((float)Screen.width - num) * 0.5f;
			float num4 = ((float)Screen.height - num2) * 0.5f;
			GUI.DrawTexture(new Rect(num3, num4, num, num2), (Texture)(object)Gfx.Leather, (ScaleMode)0, false);
			GUI.DrawTexture(new Rect(num3 + 20f, num4 + 62f, num - 40f, num2 - 82f), (Texture)(object)Gfx.Background, (ScaleMode)0, false);
			GUI.DrawTexture(new Rect(num3, num4, num, 52f), (Texture)(object)Gfx.Gold, (ScaleMode)0, false);
			string text = GUI.TextField(new Rect(num3 + 28f, num4 + 9f, num - 56f, 34f), Logbook.CurrentBookName, 30, _headerField);
			if (text != Logbook.CurrentBookName)
			{
				Logbook.SetBookName(text);
			}
			for (int i = 0; i < 3; i++)
			{
				Rect val = new Rect(num3 + 34f + (float)(i * 136), num4 + 72f, 124f, 26f);
				bool flag = Logbook.Page == i;
				if (GUI.Toggle(val, flag, PageLabels[i], _tab) && !flag)
				{
					Logbook.SetPage(i);
				}
			}
			GUI.Label(new Rect(num3 + 44f, num4 + 110f, 72f, 24f), "Title:", _label);
			string text2 = GUI.TextField(new Rect(num3 + 122f, num4 + 108f, 240f, 26f), Logbook.CurrentTitle, 30, _fieldFocus);
			if (text2 != Logbook.CurrentTitle)
			{
				Logbook.SetTitle(text2);
			}
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(num3 + 44f, num4 + 144f, num - 88f, num2 - 224f);
			float num5 = Mathf.Max(700f, (float)Logbook.CurrentBody.Length * 0.55f + 60f);
			_scroll = GUI.BeginScrollView(val2, _scroll, new Rect(0f, 0f, ((Rect)(ref val2)).width - 24f, num5));
			string text3 = GUI.TextArea(new Rect(2f, 0f, ((Rect)(ref val2)).width - 28f, num5), Logbook.CurrentBody, 4000, _area);
			if (text3 != Logbook.CurrentBody)
			{
				Logbook.SetBody(text3);
			}
			GUI.EndScrollView();
			GUI.Label(new Rect(num3 + 44f, num4 + num2 - 44f, 240f, 22f), "Characters: " + Logbook.CurrentBody.Length + "/" + 4000, _label);
			if (GUI.Button(new Rect(num3 + num - 210f, num4 + num2 - 48f, 88f, 30f), "Save", _button))
			{
				Logbook.Store();
			}
			if (GUI.Button(new Rect(num3 + num - 112f, num4 + num2 - 48f, 88f, 30f), "Close", _button))
			{
				Logbook.Close();
			}
		}
	}
	public static class Logbook
	{
		public static class RightClickPatch
		{
			public static bool Prefix(InventoryGrid grid, ItemData item, Vector2i pos)
			{
				if (!IsLogbook(item))
				{
					return true;
				}
				Plugin.Log.LogInfo((object)("ThorinsLogbook: right-click on logbook, open=" + IsOpen));
				if (IsOpen)
				{
					if (IsCurrent(item))
					{
						Close();
					}
				}
				else
				{
					Open(item);
				}
				return false;
			}
		}

		public static class EquipPatch
		{
			public static bool Prefix(ItemData item)
			{
				if (!IsLogbook(item))
				{
					return true;
				}
				if (IsOpen)
				{
					Close();
				}
				else
				{
					try
					{
						InventoryGui.instance.Show((Container)null, 0);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("ThorinsLogbook: could not open inventory: " + ex.Message));
					}
					Open(item);
				}
				return false;
			}
		}

		public static class InputBlockPatch
		{
			public static bool BlockPlayerInput()
			{
				return !IsOpen;
			}
		}

		public const int PageCount = 3;

		private const string PrefabName = "AdventurersLogbook";

		private const string ItemName = "Thorin's Logbook";

		private const string KeyTitle = "lob_t";

		private const string KeyBody = "lob_b";

		private const string KeyName = "lob_name";

		private static readonly string[] Titles = new string[3];

		private static readonly string[] Bodies = new string[3];

		private static ItemData _item;

		private static bool _setupDone;

		private static string _bookName;

		public static bool IsOpen => _item != null;

		public static int Page { get; private set; }

		public static string CurrentTitle => Titles[Page];

		public static string CurrentBody => Bodies[Page];

		public static string CurrentBookName
		{
			get
			{
				if (!string.IsNullOrEmpty(_bookName))
				{
					return _bookName;
				}
				return "Thorin's Logbook";
			}
		}

		public static void Init()
		{
			PrefabManager.OnVanillaPrefabsAvailable += SetupItem;
		}

		private static void SetupItem()
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			if (_setupDone)
			{
				return;
			}
			_setupDone = true;
			GameObject prefab = Cache.GetPrefab<GameObject>("FishingBait");
			if ((Object)(object)prefab == (Object)null)
			{
				Plugin.Log.LogError((object)"ThorinsLogbook: source prefab 'FishingBait' not found.");
				return;
			}
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("AdventurersLogbook", prefab);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"ThorinsLogbook: could not clone 'FishingBait'.");
				return;
			}
			ItemDrop component = val.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				Plugin.Log.LogError((object)"ThorinsLogbook: cloned prefab has no ItemDrop.");
				return;
			}
			SharedData shared = component.m_itemData.m_shared;
			shared.m_name = "Thorin's Logbook";
			shared.m_description = "A leather-bound field journal. Right-click it (or slot it to a quickbar) to write your notes. The notes are kept on the book itself.";
			shared.m_weight = 0.5f;
			shared.m_maxStackSize = 1;
			shared.m_itemType = (ItemType)16;
			Sprite bookIcon = Gfx.BookIcon;
			if ((Object)(object)bookIcon != (Object)null)
			{
				shared.m_icons = (Sprite[])(object)new Sprite[1] { bookIcon };
			}
			ItemConfig val2 = new ItemConfig();
			val2.Name = "Thorin's Logbook";
			val2.Description = shared.m_description;
			val2.Amount = 1;
			val2.Weight = 0.5f;
			val2.Icon = bookIcon;
			val2.CraftingStation = "piece_workbench";
			val2.MinStationLevel = 1;
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig("Wood", 6, 0, true),
				new RequirementConfig("Resin", 2, 0, true)
			};
			val2.Enabled = true;
			ItemConfig val3 = val2;
			PrefabManager.Instance.RegisterToZNetScene(val);
			ItemManager.Instance.AddItem(new CustomItem(val, true, val3));
			Plugin.Log.LogInfo((object)"ThorinsLogbook: 'Thorin's Logbook' registered, crafts at the workbench.");
		}

		public static void Open(ItemData item)
		{
			if (item != null)
			{
				_bookName = "";
				if (item.m_customData != null && item.m_customData.TryGetValue("lob_name", out var value))
				{
					_bookName = value ?? "";
				}
				_item = item;
				Page = 0;
				LoadFromItem();
			}
		}

		public static void Close()
		{
			ApplyNameAndIcon(_item, CurrentBookName);
			Store();
			_item = null;
		}

		public static void SetBookName(string name)
		{
			_bookName = (name ?? "").Trim();
			Store();
		}

		public static void SetPage(int page)
		{
			if (page >= 0 && page < 3)
			{
				Store();
				Page = page;
			}
		}

		public static void SetTitle(string title)
		{
			Titles[Page] = title ?? "";
			Store();
		}

		public static void SetBody(string body)
		{
			Bodies[Page] = body ?? "";
			Store();
		}

		private static void LoadFromItem()
		{
			for (int i = 0; i < 3; i++)
			{
				Titles[i] = "";
				Bodies[i] = "";
			}
			if (_item.m_customData == null)
			{
				return;
			}
			for (int j = 0; j < 3; j++)
			{
				if (_item.m_customData.TryGetValue("lob_t" + j, out var value))
				{
					Titles[j] = value ?? "";
				}
				if (_item.m_customData.TryGetValue("lob_b" + j, out var value2))
				{
					Bodies[j] = value2 ?? "";
				}
			}
		}

		public static void Store()
		{
			if (_item != null)
			{
				if (_item.m_customData == null)
				{
					_item.m_customData = new Dictionary<string, string>();
				}
				for (int i = 0; i < 3; i++)
				{
					_item.m_customData["lob_t" + i] = Titles[i];
					_item.m_customData["lob_b" + i] = Bodies[i];
				}
				_item.m_customData["lob_name"] = CurrentBookName;
			}
		}

		private static SharedData CloneShared(SharedData source)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			return (SharedData)typeof(SharedData).GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(source, null);
		}

		public static void ApplyNameAndIcon(ItemData item, string name)
		{
			if (item == null || (Object)(object)item.m_dropPrefab == (Object)null)
			{
				return;
			}
			ItemDrop component = item.m_dropPrefab.GetComponent<ItemDrop>();
			if (!((Object)(object)component == (Object)null) && component.m_itemData != null && component.m_itemData.m_shared != null)
			{
				string name2 = (string.IsNullOrEmpty(name) ? "Thorin's Logbook" : name);
				SharedData val = CloneShared(component.m_itemData.m_shared);
				val.m_name = name2;
				Sprite val2 = Gfx.BookIconFor(name2);
				if ((Object)(object)val2 != (Object)null)
				{
					val.m_icons = (Sprite[])(object)new Sprite[1] { val2 };
				}
				item.m_shared = val;
			}
		}

		public static void RestoreBookNames(Inventory inventory)
		{
			if (inventory == null)
			{
				return;
			}
			List<ItemData> allItems = inventory.GetAllItems();
			if (allItems == null || allItems.Count == 0)
			{
				return;
			}
			foreach (ItemData item in allItems)
			{
				if (item != null && !((Object)(object)item.m_dropPrefab == (Object)null) && !(((Object)item.m_dropPrefab).name != "AdventurersLogbook") && item.m_customData != null && item.m_customData.TryGetValue("lob_name", out var value))
				{
					ApplyNameAndIcon(item, value);
				}
			}
		}

		public static void RestoreBookNamesPost(Inventory __instance)
		{
			RestoreBookNames(__instance);
		}

		private static bool IsLogbook(ItemData item)
		{
			if (item != null && (Object)(object)item.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name == "AdventurersLogbook";
			}
			return false;
		}

		public static bool IsCurrent(ItemData item)
		{
			if (item != null)
			{
				return _item == item;
			}
			return false;
		}
	}
	[BepInPlugin("wayfarers.adventurerslogbook", "Thorin's Logbook", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "wayfarers.adventurerslogbook";

		public const string Name = "Thorin's Logbook";

		public const string Version = "1.0.0";

		public static ManualLogSource Log;

		private bool _invWasVisible;

		private void Awake()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Logbook.Init();
			Harmony val = new Harmony("wayfarers.adventurerslogbook");
			MethodInfo methodInfo = AccessTools.Method(typeof(InventoryGui), "OnRightClickItem", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				val.Patch((MethodBase)methodInfo, new HarmonyMethod(AccessTools.Method(typeof(Logbook.RightClickPatch), "Prefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"ThorinsLogbook: patched InventoryGui.OnRightClickItem");
			}
			else
			{
				Log.LogWarning((object)"ThorinsLogbook: InventoryGui.OnRightClickItem not found - journal cannot open.");
			}
			MethodInfo methodInfo2 = AccessTools.Method(typeof(Player), "EquipItem", (Type[])null, (Type[])null);
			if (methodInfo2 != null)
			{
				val.Patch((MethodBase)methodInfo2, new HarmonyMethod(AccessTools.Method(typeof(Logbook.EquipPatch), "Prefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"ThorinsLogbook: patched Player.EquipItem");
			}
			else
			{
				Log.LogInfo((object)"ThorinsLogbook: Player.EquipItem not found - hotbar open disabled.");
			}
			MethodInfo methodInfo3 = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null);
			if (methodInfo3 != null)
			{
				val.Patch((MethodBase)methodInfo3, new HarmonyMethod(AccessTools.Method(typeof(Logbook.InputBlockPatch), "BlockPlayerInput", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"ThorinsLogbook: patched Player.TakeInput");
			}
			else
			{
				Log.LogWarning((object)"ThorinsLogbook: Player.TakeInput not found - movement not blocked while journal open.");
			}
			Type type = AccessTools.TypeByName("Vapok.Common.Tools.KeyPressTool");
			if (type != null)
			{
				int num = 0;
				string[] array = new string[2] { "CheckKeyDown", "CheckKeyHeld" };
				foreach (string text in array)
				{
					MethodInfo methodInfo4 = AccessTools.Method(type, text, (Type[])null, (Type[])null);
					if (methodInfo4 != null)
					{
						val.Patch((MethodBase)methodInfo4, new HarmonyMethod(AccessTools.Method(typeof(Logbook.InputBlockPatch), "BlockPlayerInput", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
				Log.LogInfo((object)("ThorinsLogbook: patched " + num + " KeyPressTool methods"));
			}
			else
			{
				Log.LogInfo((object)"ThorinsLogbook: KeyPressTool type not found.");
			}
			Type type2 = AccessTools.TypeByName("ZInput");
			if (type2 != null)
			{
				int num2 = PatchInputMethods(val, type2, "GetButtonDown", "GetButton", "GetButtonUp", "GetKeyDown", "GetKey", "GetKeyUp", "GetMouseButtonDown", "GetMouseButton", "GetMouseButtonUp");
				Log.LogInfo((object)("ThorinsLogbook: patched " + num2 + " ZInput button methods"));
			}
			else
			{
				Log.LogInfo((object)"ThorinsLogbook: ZInput type not found.");
			}
			int num3 = PatchInputMethods(val, typeof(Input), "GetKeyDown", "GetKey", "GetKeyUp", "GetMouseButtonDown", "GetMouseButton", "GetMouseButtonUp", "GetAxis", "GetAxisRaw");
			Log.LogInfo((object)("ThorinsLogbook: patched " + num3 + " legacy Input methods"));
			HarmonyMethod val2 = new HarmonyMethod(AccessTools.Method(typeof(Logbook), "RestoreBookNamesPost", (Type[])null, (Type[])null));
			MethodInfo methodInfo5 = AccessTools.Method(typeof(Inventory), "Load", new Type[1] { typeof(ZPackage) }, (Type[])null);
			if (methodInfo5 != null)
			{
				val.Patch((MethodBase)methodInfo5, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"ThorinsLogbook: patched Inventory.Load(ZPackage)");
			}
			MethodInfo methodInfo6 = AccessTools.Method(typeof(Inventory), "Load", new Type[2]
			{
				typeof(ZPackage),
				typeof(bool)
			}, (Type[])null);
			if (methodInfo6 != null)
			{
				val.Patch((MethodBase)methodInfo6, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"ThorinsLogbook: patched Inventory.Load(ZPackage, bool)");
			}
			Log.LogInfo((object)"ThorinsLogbook: ready.");
		}

		private static int PatchInputMethods(Harmony harmony, Type target, params string[] names)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			int num = 0;
			MethodInfo methodInfo = AccessTools.Method(typeof(Logbook.InputBlockPatch), "BlockPlayerInput", (Type[])null, (Type[])null);
			MethodInfo[] methods = target.GetMethods(BindingFlags.Static | BindingFlags.Public);
			foreach (MethodInfo methodInfo2 in methods)
			{
				foreach (string text in names)
				{
					if (methodInfo2.Name == text)
					{
						try
						{
							harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							num++;
						}
						catch (Exception ex)
						{
							Log.LogWarning((object)("ThorinsLogbook: could not patch " + target.Name + "." + text + ": " + ex.Message));
						}
					}
				}
			}
			return num;
		}

		private void OnGUI()
		{
			if (Logbook.IsOpen)
			{
				JournalGui.Draw();
			}
		}

		private void Update()
		{
			if (Logbook.IsOpen && Input.GetKeyDown((KeyCode)27))
			{
				Logbook.Close();
			}
			else if (!((Object)(object)InventoryGui.instance == (Object)null))
			{
				bool flag = InventoryGui.IsVisible();
				if (Logbook.IsOpen && !flag && _invWasVisible)
				{
					Logbook.Close();
				}
				_invWasVisible = flag;
			}
		}
	}
}