Decompiled source of BrewingInformation v2.0.0

com.rus9384.brewinginformation.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using DarkScreenSystem;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PotionCraft.Assemblies.DataBaseSystem.PreparedObjects;
using PotionCraft.DebugObjects.DebugWindows;
using PotionCraft.LocalizationSystem;
using PotionCraft.ManagersSystem;
using PotionCraft.ManagersSystem.Menu;
using PotionCraft.ManagersSystem.RecipeMap;
using PotionCraft.ObjectBased;
using PotionCraft.ObjectBased.Mortar;
using PotionCraft.ObjectBased.RecipeMap.Path;
using PotionCraft.ObjectBased.RecipeMap.RecipeMapItem.IndicatorMapItem;
using PotionCraft.ObjectBased.UIElements;
using UnityEngine;
using UnityEngine.Events;

[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("com.rus9384.brewinginformation")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+2f79eb5ef9855760383b7404dfb17c367dfae610")]
[assembly: AssemblyProduct("Brewing Information")]
[assembly: AssemblyTitle("com.rus9384.brewinginformation")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
[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 BrewingInformation
{
	[BepInPlugin("com.rus9384.brewinginformation", "Brewing Information", "2.0.0")]
	public class BrewingInformation : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__SetModLocalization;
		}

		internal static bool enableGrindStatus;

		internal static bool enableHealth;

		internal static bool enablePotionCoordinates;

		internal static bool enablePotionRotation;

		internal static bool enablePathAngle;

		internal static float scale;

		internal static bool enableScratches;

		internal static Room laboratory;

		private static DebugWindow window;

		private static FieldInfo healthFI;

		internal static bool needsUpdating;

		private static float _health;

		private static float? _grind;

		private static Vector2 _position;

		private static float _rotation;

		private static float? _pathAngle;

		internal static float Health
		{
			get
			{
				return _health;
			}
			set
			{
				if (value != _health)
				{
					_health = value;
					needsUpdating = true;
				}
			}
		}

		internal static float? Grind
		{
			get
			{
				return _grind;
			}
			set
			{
				if (value != _grind)
				{
					_grind = value;
					needsUpdating = true;
				}
			}
		}

		internal static Vector2 Position
		{
			get
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				return _position;
			}
			set
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				if (_position != value)
				{
					_position = value;
					needsUpdating = true;
				}
			}
		}

		internal static float Rotation
		{
			get
			{
				return _rotation;
			}
			set
			{
				if (_rotation != value)
				{
					_rotation = value;
					needsUpdating = true;
				}
			}
		}

		internal static float? PathAngle
		{
			get
			{
				return _pathAngle;
			}
			set
			{
				if (_pathAngle != value)
				{
					_pathAngle = value;
					needsUpdating = true;
				}
			}
		}

		private void Awake()
		{
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			Harmony.CreateAndPatchAll(typeof(BrewingInformation), (string)null);
			enableGrindStatus = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableGrindStatus", true, (ConfigDescription)null).Value;
			enableHealth = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableHealth", true, (ConfigDescription)null).Value;
			enablePotionCoordinates = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnablePotionCoordinates", true, (ConfigDescription)null).Value;
			enablePotionRotation = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnablePotionRotation", true, (ConfigDescription)null).Value;
			enablePathAngle = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnablePathAngle", true, (ConfigDescription)null).Value;
			scale = ((BaseUnityPlugin)this).Config.Bind<float>("Graphics", "Scale", 100f, "Window scale in %").Value;
			enableScratches = ((BaseUnityPlugin)this).Config.Bind<bool>("Graphics", "EnableScratches", true, "Set this to 'false' if you want a cleaner but less authentic view").Value;
			UnityEvent onInitialize = LocalizationManager.OnInitialize;
			object obj = <>O.<0>__SetModLocalization;
			if (obj == null)
			{
				UnityAction val = SetModLocalization;
				<>O.<0>__SetModLocalization = val;
				obj = (object)val;
			}
			onInitialize.AddListener((UnityAction)obj);
			healthFI = AccessTools.Field(typeof(IndicatorMapItem), "health");
		}

		private void Update()
		{
			if ((Object)(object)window == (Object)null)
			{
				window = UIElements.CreateWindow();
			}
			if (needsUpdating)
			{
				window.ShowText(GetInfo());
				needsUpdating = false;
			}
		}

		private static void SetModLocalization()
		{
			RegisterLoc("#BrewingInformationTitle", "Information");
		}

		private static void RegisterLoc(string key, string en)
		{
			for (int i = 0; i <= 13; i++)
			{
				AccessTools.StaticFieldRefAccess<LocalizationData>(typeof(LocalizationManager), "localizationData").Add(i, key, en);
			}
		}

		internal static string GetInfo()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			if (enableGrindStatus)
			{
				list.Add($"Grind: {Grind:P2}");
			}
			if (enableHealth)
			{
				list.Add($"Health: {Health:P2}");
			}
			if (enablePotionCoordinates)
			{
				list.Add($"x: {Position.x:#0.####}, y: {Position.y:#0.####}");
			}
			if (enablePotionRotation)
			{
				list.Add($"Angle: {Rotation:##0.###}");
			}
			if (enablePathAngle)
			{
				list.Add($"Path Angle: {PathAngle:##0.###}");
			}
			return string.Join("\n", list);
		}

		[HarmonyPatch(typeof(Room), "Awake")]
		[HarmonyPostfix]
		public static void Room_Awake_Patch(Room __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)__instance.roomIndex == 1)
			{
				laboratory = __instance;
			}
		}

		[HarmonyPatch(typeof(DebugWindow), "Update")]
		[HarmonyPostfix]
		private static void DebugWindowUpdatePatch(DebugWindow __instance)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)(object)window && ((Component)__instance).transform.localPosition != UIElements.position)
			{
				((Component)__instance).transform.localPosition = UIElements.position;
			}
		}

		[HarmonyPatch(typeof(Mortar), "Update")]
		[HarmonyPostfix]
		private static void MortarUpdateInfo(Mortar __instance)
		{
			if (enableGrindStatus)
			{
				if ((Object)(object)__instance.ContainedStack != (Object)null)
				{
					Grind = Mathf.Clamp01(__instance.ContainedStack.overallGrindStatus);
				}
				else
				{
					Grind = null;
				}
			}
		}

		[HarmonyPatch(typeof(RecipeMapManager), "Update")]
		[HarmonyPostfix]
		private static void RecipeMapUpdateInfo(RecipeMapManager __instance)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if ((!enableHealth && !enablePotionCoordinates && !enablePotionRotation && !enablePathAngle) || (Object)(object)__instance.indicator == (Object)null || __instance.indicatorRotation == null || (Object)(object)__instance.path == (Object)null)
			{
				return;
			}
			if (enableHealth)
			{
				Health = (float)healthFI.GetValue(__instance.indicator);
			}
			if (enablePotionCoordinates)
			{
				Position = __instance.indicator.TargetPosition;
			}
			if (enablePotionRotation)
			{
				Rotation = __instance.indicatorRotation.Value;
			}
			if (enablePathAngle)
			{
				float? pathAngle = null;
				FixedHint val = __instance.path.fixedPathHints.Find((FixedHint hint) => hint.evenlySpacedPointsFixedPhysics.points.Length > 1);
				if ((Object)(object)val != (Object)null)
				{
					Vector3 val2 = val.evenlySpacedPointsFixedPhysics.points[1] - val.evenlySpacedPointsFixedPhysics.points[0];
					pathAngle = (Mathf.Atan2(0f - val2.x, val2.y) * 180f / MathF.PI + 360f) % 360f;
				}
				PathAngle = pathAngle;
			}
		}

		[HarmonyPatch(typeof(DebugWindow), "RecalculateWindowSize")]
		[HarmonyPrefix]
		private static bool DebugWindowRecalculateWindowSizePatch(DebugWindow __instance)
		{
			return (Object)(object)__instance != (Object)(object)window;
		}

		[HarmonyPatch(typeof(DarkScreen), "ShowObject")]
		[HarmonyPatch(typeof(MenuManager), "OpenMainMenu")]
		[HarmonyPatch(typeof(MenuManager), "OpenPauseMenu")]
		[HarmonyPostfix]
		private static void HideWindow()
		{
			if ((Object)(object)window != (Object)null)
			{
				((Window)window).Visible = false;
			}
		}

		[HarmonyPatch(typeof(DarkScreen), "HideObject")]
		[HarmonyPatch(typeof(MenuManager), "CloseMenu")]
		[HarmonyPostfix]
		private static void ShowWindow()
		{
			if ((Object)(object)window != (Object)null)
			{
				((Window)window).Visible = true;
			}
		}
	}
	public static class UIElements
	{
		internal static Vector3 position;

		public static DebugWindow CreateWindow()
		{
			//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_005e: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Invalid comparison between Unknown and I4
			if ((Object)(object)BrewingInformation.laboratory == (Object)null)
			{
				return null;
			}
			DebugWindow obj = DebugWindow.Init(LocalizationManager.GetText("#BrewingInformationTitle"), true);
			((Component)obj).transform.SetParent(((Component)BrewingInformation.laboratory).transform, false);
			obj.ShowText(BrewingInformation.GetInfo());
			Vector2 size = obj.spriteBackground.size;
			size.x = 3.29f;
			obj.spriteBackground.size = size;
			obj.spriteScratches.size = size;
			obj.colliderBackground.size = Vector2.zero;
			((Collider2D)obj.colliderBackground).offset = Vector2.zero;
			float num = BrewingInformation.scale / 100f;
			Transform transform = ((Component)obj).transform;
			transform.localScale *= num;
			position = new Vector3(6.14f - 3.29f * num, 6.95f, 0f);
			((Component)obj).transform.position = position;
			((MovableUIItem)obj).movable = false;
			((Window)obj).Visible = (int)Managers.Menu.CurrentMenu == 0;
			((Component)((Component)obj).transform.Find("Maximized/Background/Scratches")).gameObject.SetActive(BrewingInformation.enableScratches);
			((Component)((Component)obj).transform.Find("Maximized/Head")).gameObject.SetActive(false);
			return obj;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.rus9384.brewinginformation";

		public const string PLUGIN_NAME = "Brewing Information";

		public const string PLUGIN_VERSION = "2.0.0";
	}
}