Decompiled source of Awakened Hearthstone v1.0.0

Hearthstone/HearthstoneMod.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
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 Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HearthstoneMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HearthstoneMod")]
[assembly: AssemblyTitle("HearthstoneMod")]
[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 HearthstoneMod
{
	public static class CooldownManager
	{
		private const string KeyNormalRem = "HS_CD_Normal_Rem";

		private const string KeyAwakenedRem = "HS_CD_Awakened_Rem";

		public static bool IsReady(Player player, bool awakened)
		{
			return GetRemainingSeconds(player, awakened) <= 0f;
		}

		public static float GetRemainingSeconds(Player player, bool awakened)
		{
			if ((Object)(object)player == (Object)null)
			{
				return 0f;
			}
			string key = (awakened ? "HS_CD_Awakened_Rem" : "HS_CD_Normal_Rem");
			if (!player.m_customData.TryGetValue(key, out var value))
			{
				return 0f;
			}
			if (!float.TryParse(value, out var result) || result <= 0f)
			{
				return 0f;
			}
			return result;
		}

		public static void ApplyCooldown(Player player, bool awakened)
		{
			if (!((Object)(object)player == (Object)null))
			{
				float seconds = (awakened ? 900f : 1800f);
				SetRemaining(player, awakened, seconds);
				StartTicking(player, awakened);
			}
		}

		public static void ResumeOnLogin(Player player)
		{
			if (!((Object)(object)player == (Object)null))
			{
				if (GetRemainingSeconds(player, awakened: false) > 0f)
				{
					StartTicking(player, awakened: false);
				}
				if (GetRemainingSeconds(player, awakened: true) > 0f)
				{
					StartTicking(player, awakened: true);
				}
			}
		}

		public static string FormatRemaining(Player player, bool awakened)
		{
			float remainingSeconds = GetRemainingSeconds(player, awakened);
			if (remainingSeconds <= 0f)
			{
				return "$tt_hs_ready";
			}
			int num = Mathf.FloorToInt(remainingSeconds / 60f);
			int num2 = Mathf.FloorToInt(remainingSeconds % 60f);
			return (num > 0) ? (num + "m " + num2 + "s") : (num2 + "s");
		}

		private static void SetRemaining(Player player, bool awakened, float seconds)
		{
			string key = (awakened ? "HS_CD_Awakened_Rem" : "HS_CD_Normal_Rem");
			if (seconds <= 0f)
			{
				player.m_customData.Remove(key);
			}
			else
			{
				player.m_customData[key] = seconds.ToString("F2");
			}
		}

		private static void StartTicking(Player player, bool awakened)
		{
			((MonoBehaviour)player).StartCoroutine(TickCoroutine(player, awakened));
		}

		private static IEnumerator TickCoroutine(Player player, bool awakened)
		{
			while ((Object)(object)player != (Object)null)
			{
				yield return (object)new WaitForSeconds(1f);
				if ((Object)(object)player == (Object)null)
				{
					break;
				}
				float current = GetRemainingSeconds(player, awakened);
				if (current <= 0f)
				{
					SetRemaining(player, awakened, 0f);
					break;
				}
				SetRemaining(player, awakened, current - 1f);
			}
		}
	}
	public class HearthstoneCastBar : MonoBehaviour
	{
		private const float MoveThreshold = 0.7f;

		private const float DamageThreshold = 1f;

		private const float BarHeightFrac = 0.034f;

		private const float ApertureAspect = 11.607f;

		private const float ApertureWFrac = 0.8086f;

		private const float ApertureHFrac = 0.1045f;

		private const float ApertureTopFrac = 0.4463f;

		private const float VerticalPos = 0.72f;

		private Player _player;

		private bool _awakened;

		private float _castDuration;

		private float _elapsed;

		private Vector3 _startPos;

		private float _startHealth;

		private bool _finished;

		private static Texture2D _frameTex;

		private static Texture2D _whiteTex;

		private static GUIStyle _labelStyle;

		private static bool _texturesReady;

		public event Action OnCastComplete;

		public event Action OnCastInterrupted;

		private void Awake()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!_texturesReady)
			{
				_texturesReady = true;
				_whiteTex = new Texture2D(1, 1);
				_whiteTex.SetPixel(0, 0, Color.white);
				_whiteTex.Apply();
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				_frameTex = LoadTexture(Path.Combine(directoryName, "CastbarFrame1.png"));
			}
		}

		public void Begin(Player player, bool awakened, float castDuration)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			_player = player;
			_awakened = awakened;
			_castDuration = castDuration;
			_elapsed = 0f;
			_finished = false;
			_startPos = ((Component)player).transform.position;
			_startHealth = ((Character)player).GetHealth();
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)1, "$msg_hs_casting", 0, (Sprite)null, false, true);
			}
		}

		private void Update()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (_finished || (Object)(object)_player == (Object)null)
			{
				Object.Destroy((Object)(object)this);
				return;
			}
			if (Vector3.Distance(((Component)_player).transform.position, _startPos) > 0.7f)
			{
				Interrupt("moved");
				return;
			}
			float num = _startHealth - ((Character)_player).GetHealth();
			if (num > 1f)
			{
				Interrupt("took damage");
				return;
			}
			if (((Character)_player).GetHealth() > _startHealth)
			{
				_startHealth = ((Character)_player).GetHealth();
			}
			if (((Character)_player).IsDead())
			{
				Interrupt("died");
				return;
			}
			_elapsed += Time.deltaTime;
			if (_elapsed >= _castDuration)
			{
				_finished = true;
				this.OnCastComplete?.Invoke();
				Object.Destroy((Object)(object)this);
			}
		}

		private void OnGUI()
		{
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			if (!_finished && !((Object)(object)_player == (Object)null))
			{
				float num = (float)Screen.height * 0.034f;
				float num2 = num * 11.607f;
				float num3 = num2 / 0.8086f;
				float num4 = num / 0.1045f;
				int num5 = Mathf.Clamp(Mathf.RoundToInt(num2 / 24.5f), 10, 22);
				if (_labelStyle == null || _labelStyle.fontSize != num5)
				{
					GUIStyle val = new GUIStyle(GUI.skin.label)
					{
						alignment = (TextAnchor)4,
						fontStyle = (FontStyle)1,
						fontSize = num5
					};
					val.normal.textColor = Color.white;
					_labelStyle = val;
				}
				float num6 = Mathf.Clamp01(_elapsed / _castDuration);
				float num7 = ((float)Screen.width - num2) * 0.5f;
				float num8 = (float)Screen.height * 0.72f;
				float num9 = ((float)Screen.width - num3) * 0.5f;
				float num10 = num8 - num4 * 0.4463f;
				float num11 = num4 * 0.01f;
				float num12 = num + num11 * 2f;
				float num13 = num2 + num11 * 2f;
				Color color = Color.Lerp(new Color(0.08f, 0.72f, 0.18f), new Color(1f, 0.62f, 0.04f), num6);
				GUI.color = color;
				GUI.DrawTexture(new Rect(num7 - num11, num8 - num11, Mathf.Max(0f, num13 * num6), num12), (Texture)(object)_whiteTex);
				GUI.color = Color.white;
				if ((Object)(object)_frameTex != (Object)null)
				{
					GUI.DrawTexture(new Rect(num9, num10, num3, num4), (Texture)(object)_frameTex, (ScaleMode)0, true);
				}
				float num14 = Mathf.Max(0f, _castDuration - _elapsed);
				string text = (_awakened ? "Casting Awakened Hearthstone" : "Casting Hearthstone") + "   " + num14.ToString("F1");
				GUI.color = new Color(0f, 0f, 0f, 0.9f);
				GUI.Label(new Rect(num7 + 1f, num8 + 1f, num2, num), text, _labelStyle);
				GUI.color = Color.white;
				GUI.Label(new Rect(num7, num8, num2, num), text, _labelStyle);
			}
		}

		private void Interrupt(string reason)
		{
			_finished = true;
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)2, "$msg_hs_interrupted", 0, (Sprite)null, false, true);
			}
			this.OnCastInterrupted?.Invoke();
			Object.Destroy((Object)(object)this);
		}

		private void OnDestroy()
		{
			if (!_finished)
			{
				this.OnCastInterrupted?.Invoke();
			}
		}

		private static Texture2D LoadTexture(string path)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				return null;
			}
			try
			{
				Bitmap val = new Bitmap(path);
				try
				{
					int width = ((Image)val).Width;
					int height = ((Image)val).Height;
					BitmapData val2 = val.LockBits(new Rectangle(0, 0, width, height), (ImageLockMode)1, (PixelFormat)2498570);
					int num = Math.Abs(val2.Stride);
					byte[] array = new byte[num * height];
					Marshal.Copy(val2.Scan0, array, 0, array.Length);
					val.UnlockBits(val2);
					byte[] array2 = new byte[width * height * 4];
					for (int i = 0; i < height; i++)
					{
						int num2 = (height - 1 - i) * num;
						int num3 = i * width * 4;
						for (int j = 0; j < width; j++)
						{
							int num4 = num2 + j * 4;
							int num5 = num3 + j * 4;
							array2[num5] = array[num4 + 2];
							array2[num5 + 1] = array[num4 + 1];
							array2[num5 + 2] = array[num4];
							array2[num5 + 3] = array[num4 + 3];
						}
					}
					Texture2D val3 = new Texture2D(width, height, (TextureFormat)4, false);
					val3.LoadRawTextureData(array2);
					val3.Apply();
					((Texture)val3).filterMode = (FilterMode)1;
					return val3;
				}
				finally
				{
					((IDisposable)val)?.Dispose();
				}
			}
			catch
			{
				return null;
			}
		}
	}
	[BepInPlugin("com.cdirk.hearthstone", "Hearthstone", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class HearthstonePlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.cdirk.hearthstone";

		public const string PluginName = "Hearthstone";

		public const string PluginVersion = "1.0.0";

		public const string ItemName_Normal = "Hearthstone";

		public const string ItemName_Awakened = "Awakened_Hearthstone";

		public const float Cooldown_Normal = 1800f;

		public const float Cooldown_Awakened = 900f;

		public const float CastTime = 3f;

		public static Sprite Sprite_Normal;

		public static Sprite Sprite_Awakened;

		internal static ManualLogSource Log;

		internal static HearthstonePlugin Instance;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			LoadSprites();
			AddLocalizations();
			_harmony = new Harmony("com.cdirk.hearthstone");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			ApplyUseItemPatch();
			PrefabManager.OnVanillaPrefabsAvailable += OnVanillaPrefabsAvailable;
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void LoadSprites()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			Sprite_Normal = LoadSprite(Path.Combine(directoryName, "Hearthstone_OG.png"));
			Sprite_Awakened = LoadSprite(Path.Combine(directoryName, "Hearthstone_Awakened.png"));
		}

		private static Sprite LoadSprite(string path)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			if (!File.Exists(path))
			{
				return null;
			}
			try
			{
				Bitmap val = new Bitmap(path);
				try
				{
					int width = ((Image)val).Width;
					int height = ((Image)val).Height;
					BitmapData val2 = val.LockBits(new Rectangle(0, 0, width, height), (ImageLockMode)1, (PixelFormat)2498570);
					int num = Math.Abs(val2.Stride) * height;
					byte[] array = new byte[num];
					Marshal.Copy(val2.Scan0, array, 0, num);
					val.UnlockBits(val2);
					byte[] array2 = new byte[width * height * 4];
					int num2 = Math.Abs(val2.Stride);
					for (int i = 0; i < height; i++)
					{
						int num3 = (height - 1 - i) * num2;
						int num4 = i * width * 4;
						for (int j = 0; j < width; j++)
						{
							int num5 = num3 + j * 4;
							int num6 = num4 + j * 4;
							array2[num6] = array[num5 + 2];
							array2[num6 + 1] = array[num5 + 1];
							array2[num6 + 2] = array[num5];
							array2[num6 + 3] = array[num5 + 3];
						}
					}
					Texture2D val3 = new Texture2D(width, height, (TextureFormat)4, false);
					val3.LoadRawTextureData(array2);
					val3.Apply();
					((Texture)val3).filterMode = (FilterMode)1;
					return Sprite.Create(val3, new Rect(0f, 0f, (float)width, (float)height), Vector2.one * 0.5f, 100f);
				}
				finally
				{
					((IDisposable)val)?.Dispose();
				}
			}
			catch
			{
				return null;
			}
		}

		private static void AddLocalizations()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			string text2 = "item_hsmod_hearthstone";
			localization.AddTranslation(ref text, ref text2, "Hearthstone");
			text = "English";
			text2 = "item_hsmod_hearthstone_desc";
			localization.AddTranslation(ref text, ref text2, "A heart of ancient stone bound by the spirit of the forest. Its verdant energy remembers the place you call home. Right-click from your inventory to channel its power. Cannot carry items that cannot pass through a portal.");
			text = "English";
			text2 = "item_hsmod_hearthstone_awakened";
			localization.AddTranslation(ref text, ref text2, "Awakened Hearthstone");
			text = "English";
			text2 = "item_hsmod_hearthstone_awakened_desc";
			localization.AddTranslation(ref text, ref text2, "The forest spirit within has been tempered by Ashlands flame, its ancient bond scorched into something fiercer and far-reaching. Right-click from your inventory to channel its power. No burden is too great for it to carry home.");
			text = "English";
			text2 = "msg_hs_cooldown";
			localization.AddTranslation(ref text, ref text2, "Hearthstone is cooling down.");
			text = "English";
			text2 = "msg_hs_blocked";
			localization.AddTranslation(ref text, ref text2, "You are carrying items that cannot pass through a portal. Stash them, or use the Awakened Hearthstone.");
			text = "English";
			text2 = "msg_hs_nobed";
			localization.AddTranslation(ref text, ref text2, "You have no bed to return to. Sleep in a bed first.");
			text = "English";
			text2 = "msg_hs_used";
			localization.AddTranslation(ref text, ref text2, "The Hearthstone carries you home.");
			text = "English";
			text2 = "msg_hs_casting";
			localization.AddTranslation(ref text, ref text2, "Channeling Hearthstone...");
			text = "English";
			text2 = "msg_hs_interrupted";
			localization.AddTranslation(ref text, ref text2, "Hearthstone interrupted!");
			text = "English";
			text2 = "tt_hs_ready";
			localization.AddTranslation(ref text, ref text2, "Ready");
			text = "English";
			text2 = "tt_hs_cooldown";
			localization.AddTranslation(ref text, ref text2, "Cooldown:");
			text = "English";
			text2 = "tt_hs_restrict";
			localization.AddTranslation(ref text, ref text2, "Cannot carry non-teleportable items.");
			text = "English";
			text2 = "tt_hs_cast";
			localization.AddTranslation(ref text, ref text2, "Cast time: 3 seconds. Moving or taking damage cancels.");
		}

		private void OnVanillaPrefabsAvailable()
		{
			try
			{
				RegisterNormalHearthstone();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[Hearthstone] " + ex));
			}
			try
			{
				RegisterAwakenedHearthstone();
			}
			catch (Exception ex2)
			{
				Log.LogError((object)("[Hearthstone] " + ex2));
			}
			PrefabManager.OnVanillaPrefabsAvailable -= OnVanillaPrefabsAvailable;
		}

		private void RegisterNormalHearthstone()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			ItemConfig val = new ItemConfig();
			val.Name = "$item_hsmod_hearthstone";
			val.Description = "$item_hsmod_hearthstone_desc";
			val.Icons = (Sprite[])(object)((!((Object)(object)Sprite_Normal != (Object)null)) ? null : new Sprite[1] { Sprite_Normal });
			val.CraftingStation = CraftingStations.Workbench;
			val.MinStationLevel = 1;
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				new RequirementConfig("AncientSeed", 1, 0, true),
				new RequirementConfig("Blueberries", 5, 0, true),
				new RequirementConfig("Stone", 10, 0, true),
				new RequirementConfig("SurtlingCore", 1, 0, true)
			};
			CustomItem val2 = new CustomItem("Hearthstone", "Stone", val);
			ApplySharedData(val2.ItemDrop, awakened: false);
			ItemManager.Instance.AddItem(val2);
		}

		private void RegisterAwakenedHearthstone()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			ItemConfig val = new ItemConfig();
			val.Name = "$item_hsmod_hearthstone_awakened";
			val.Description = "$item_hsmod_hearthstone_awakened_desc";
			val.Icons = (Sprite[])(object)((!((Object)(object)Sprite_Awakened != (Object)null)) ? null : new Sprite[1] { Sprite_Awakened });
			CustomItem val2 = new CustomItem("Awakened_Hearthstone", "Stone", val);
			ApplySharedData(val2.ItemDrop, awakened: true);
			ItemManager.Instance.AddItem(val2);
			RequirementConfig[] requirements = (RequirementConfig[])(object)new RequirementConfig[5]
			{
				new RequirementConfig("Hearthstone", 1, 0, true),
				new RequirementConfig("Grausten", 10, 0, true),
				new RequirementConfig("CelestialFeather", 1, 0, true),
				new RequirementConfig("MushroomSmokePuff", 10, 0, true),
				new RequirementConfig("MoltenCore", 1, 0, true)
			};
			string[] array = new string[2] { "blackforge", "BlackForge" };
			foreach (string text in array)
			{
				try
				{
					ItemManager.Instance.AddRecipe(new CustomRecipe(new RecipeConfig
					{
						Name = "Recipe_Awakened_Hearthstone_" + text,
						Item = "Awakened_Hearthstone",
						CraftingStation = text,
						MinStationLevel = 1,
						Requirements = requirements
					}));
				}
				catch
				{
				}
			}
		}

		private static void ApplySharedData(ItemDrop drop, bool awakened)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)drop == (Object)null))
			{
				SharedData shared = drop.m_itemData.m_shared;
				shared.m_name = (awakened ? "$item_hsmod_hearthstone_awakened" : "$item_hsmod_hearthstone");
				shared.m_description = (awakened ? "$item_hsmod_hearthstone_awakened_desc" : "$item_hsmod_hearthstone_desc");
				shared.m_itemType = (ItemType)16;
				shared.m_maxStackSize = 1;
				shared.m_weight = 2f;
				shared.m_maxQuality = 1;
				shared.m_useDurability = false;
				shared.m_destroyBroken = false;
				shared.m_food = 0f;
				shared.m_foodStamina = 0f;
				shared.m_foodBurnTime = 0f;
				shared.m_foodRegen = 0f;
				shared.m_teleportable = true;
			}
		}

		private void ApplyUseItemPatch()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			try
			{
				MethodInfo[] methods = typeof(Humanoid).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo[] array = methods;
				foreach (MethodInfo methodInfo in array)
				{
					if (!(methodInfo.Name != "UseItem"))
					{
						_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(UseItemPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
				}
				MethodInfo[] methods2 = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods2;
				foreach (MethodInfo methodInfo2 in array2)
				{
					if (!(methodInfo2.Name != "ConsumeItem"))
					{
						_harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(UseItemPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
				}
			}
			catch
			{
			}
		}

		public void ApplyDroppedItemEffects()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ApplyGlow("Hearthstone", new Color(0f, 1f, 0.2f, 1f));
				ApplyGlow("Awakened_Hearthstone", new Color(1f, 0.4f, 0f, 1f));
			}
			catch
			{
			}
		}

		private void ApplyGlow(string prefabName, Color color)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00a0: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: 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)
			GameObject val = PrefabManager.Instance.GetPrefab(prefabName);
			if ((Object)(object)val == (Object)null && (Object)(object)ObjectDB.instance != (Object)null)
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName);
				if ((Object)(object)itemPrefab != (Object)null)
				{
					val = itemPrefab.gameObject;
				}
			}
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.transform.Find("HearthstoneGlow") != (Object)null))
			{
				GameObject val2 = new GameObject("HearthstoneGlow");
				val2.transform.SetParent(val.transform, false);
				val2.transform.localPosition = Vector3.zero;
				ParticleSystem val3 = val2.AddComponent<ParticleSystem>();
				val3.Stop(true, (ParticleSystemStopBehavior)0);
				MainModule main = val3.main;
				((MainModule)(ref main)).loop = true;
				((MainModule)(ref main)).playOnAwake = true;
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(1.2f, 2f);
				((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.2f, 0.6f);
				((MainModule)(ref main)).startSize = new MinMaxCurve(0.04f, 0.12f);
				((MainModule)(ref main)).startColor = new MinMaxGradient(color);
				((MainModule)(ref main)).maxParticles = 40;
				((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
				EmissionModule emission = val3.emission;
				((EmissionModule)(ref emission)).enabled = true;
				((EmissionModule)(ref emission)).rateOverTime = new MinMaxCurve(18f);
				ShapeModule shape = val3.shape;
				((ShapeModule)(ref shape)).enabled = true;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
				((ShapeModule)(ref shape)).radius = 0.22f;
				ParticleSystemRenderer val4 = val2.GetComponent<ParticleSystemRenderer>();
				if ((Object)(object)val4 == (Object)null)
				{
					val4 = val2.AddComponent<ParticleSystemRenderer>();
				}
				Shader val5 = Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Sprites/Default");
				if ((Object)(object)val5 != (Object)null)
				{
					Material val6 = new Material(val5);
					val6.SetColor("_TintColor", color);
					val6.SetColor("_Color", color);
					val6.SetColor("_EmissionColor", color * 3f);
					((Renderer)val4).material = val6;
				}
				val3.Play(true);
			}
		}
	}
	public static class UseItemPatch
	{
		public static bool Prefix(object[] __args)
		{
			ItemData val = null;
			if (__args != null)
			{
				foreach (object obj in __args)
				{
					ItemData val2 = (ItemData)((obj is ItemData) ? obj : null);
					if (val2 != null)
					{
						val = val2;
						break;
					}
				}
			}
			if ((Object)(object)val?.m_dropPrefab == (Object)null)
			{
				return true;
			}
			string name = ((Object)val.m_dropPrefab).name;
			bool flag = name == "Hearthstone";
			bool flag2 = name == "Awakened_Hearthstone";
			if (!flag && !flag2)
			{
				return true;
			}
			HearthstoneUseHandler.TryUse(Player.m_localPlayer, flag2);
			return false;
		}
	}
	public static class HearthstoneUseHandler
	{
		private static readonly HashSet<string> BlockedPrefabs = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
		{
			"CopperOre", "TinOre", "IronScrap", "SilverOre", "BlackMetalScrap", "FlametalOreNew", "FlametalOre", "Copper", "Tin", "Bronze",
			"Iron", "Silver", "BlackMetal", "Flametal", "DragonEgg", "DvergrExtractor", "MechanicalSpring", "CharredCogwheel", "HildirChest_forestcrypt", "HildirChest_Crypt",
			"HildirChest_Sunkencrypt"
		};

		private static HearthstoneCastBar _activeCast;

		public static bool TryUse(Player player, bool awakened)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || (Object)(object)_activeCast != (Object)null)
			{
				return false;
			}
			if (!CooldownManager.IsReady(player, awakened))
			{
				MessageHud instance = MessageHud.instance;
				if (instance != null)
				{
					instance.ShowMessage((MessageType)2, "$msg_hs_cooldown  (" + CooldownManager.FormatRemaining(player, awakened) + ")", 0, (Sprite)null, false, true);
				}
				return false;
			}
			if (!awakened && PlayerCarriesBlockedItem(player))
			{
				MessageHud instance2 = MessageHud.instance;
				if (instance2 != null)
				{
					instance2.ShowMessage((MessageType)2, "$msg_hs_blocked", 0, (Sprite)null, false, true);
				}
				return false;
			}
			if (!TryGetSpawnPoint(player, out var point))
			{
				MessageHud instance3 = MessageHud.instance;
				if (instance3 != null)
				{
					instance3.ShowMessage((MessageType)2, "$msg_hs_nobed", 0, (Sprite)null, false, true);
				}
				return false;
			}
			StartCast(player, awakened, point);
			return true;
		}

		public static void CancelActiveCast()
		{
			if ((Object)(object)_activeCast != (Object)null)
			{
				Object.Destroy((Object)(object)_activeCast);
				_activeCast = null;
			}
		}

		private static void StartCast(Player player, bool awakened, Vector3 spawnPoint)
		{
			HearthstoneCastBar hearthstoneCastBar = (_activeCast = ((Component)player).gameObject.AddComponent<HearthstoneCastBar>());
			hearthstoneCastBar.Begin(player, awakened, 3f);
			hearthstoneCastBar.OnCastComplete += delegate
			{
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				_activeCast = null;
				if (!TryGetSpawnPoint(player, out var point))
				{
					MessageHud instance = MessageHud.instance;
					if (instance != null)
					{
						instance.ShowMessage((MessageType)2, "$msg_hs_nobed", 0, (Sprite)null, false, true);
					}
				}
				else
				{
					CooldownManager.ApplyCooldown(player, awakened);
					InventoryGui instance2 = InventoryGui.instance;
					if (instance2 != null)
					{
						instance2.Hide();
					}
					((MonoBehaviour)player).StartCoroutine(TeleportSequence(player, point));
				}
			};
			hearthstoneCastBar.OnCastInterrupted += delegate
			{
				_activeCast = null;
			};
		}

		private static IEnumerator TeleportSequence(Player player, Vector3 destination)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForEndOfFrame();
			((Character)player).TeleportTo(destination, ((Component)player).transform.rotation, true);
			yield return (object)new WaitForSeconds(2f);
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)2, "$msg_hs_used", 0, (Sprite)null, false, true);
			}
		}

		private static bool PlayerCarriesBlockedItem(Player player)
		{
			foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null)
				{
					if (!allItem.m_shared.m_teleportable)
					{
						return true;
					}
					if ((Object)(object)allItem.m_dropPrefab != (Object)null && BlockedPrefabs.Contains(((Object)allItem.m_dropPrefab).name))
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool TryGetSpawnPoint(Player player, out Vector3 point)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			point = Vector3.zero;
			try
			{
				Game instance = Game.instance;
				PlayerProfile val = ((instance != null) ? instance.GetPlayerProfile() : null);
				if (val != null)
				{
					MethodInfo method = ((object)val).GetType().GetMethod("GetCustomSpawnPoint", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						ParameterInfo[] parameters = method.GetParameters();
						object[] array = new object[parameters.Length];
						for (int i = 0; i < parameters.Length; i++)
						{
							array[i] = Vector3.zero;
						}
						object obj = method.Invoke(val, array);
						for (int j = 0; j < parameters.Length; j++)
						{
							if (array[j] is Vector3 val2 && val2 != Vector3.zero)
							{
								point = val2;
								return true;
							}
						}
						if (obj is Vector3 val3 && val3 != Vector3.zero)
						{
							point = val3;
							return true;
						}
					}
					FieldInfo[] fields = ((object)val).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						if (!(fieldInfo.FieldType != typeof(Vector3)))
						{
							Vector3 val4 = (Vector3)fieldInfo.GetValue(val);
							if (val4 != Vector3.zero && point == Vector3.zero)
							{
								point = val4;
							}
						}
					}
					if (point != Vector3.zero)
					{
						return true;
					}
				}
			}
			catch
			{
			}
			return false;
		}
	}
}
namespace HearthstoneMod.Patches
{
	[HarmonyPatch(typeof(Humanoid), "EquipItem")]
	public static class Patch_Humanoid_EquipItem
	{
		private static bool Prepare()
		{
			return AccessTools.Method(typeof(Humanoid), "EquipItem", (Type[])null, (Type[])null) != null;
		}

		[HarmonyPrefix]
		public static bool Prefix(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null)
			{
				return true;
			}
			string name = ((Object)item.m_dropPrefab).name;
			if (name != "Hearthstone" && name != "Awakened_Hearthstone")
			{
				return true;
			}
			HearthstoneUseHandler.TryUse(Player.m_localPlayer, name == "Awakened_Hearthstone");
			return false;
		}
	}
	[HarmonyPatch(typeof(Character), "Damage")]
	public static class Patch_Character_Damage
	{
		private static bool Prepare()
		{
			return AccessTools.Method(typeof(Character), "Damage", (Type[])null, (Type[])null) != null;
		}

		[HarmonyPostfix]
		public static void Postfix(Character __instance)
		{
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				HearthstoneUseHandler.CancelActiveCast();
			}
		}
	}
	[HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[]
	{
		typeof(ItemData),
		typeof(int)
	})]
	public static class Patch_Inventory_RemoveItem_Guard
	{
		private static bool Prepare()
		{
			return AccessTools.Method(typeof(Inventory), "RemoveItem", new Type[2]
			{
				typeof(ItemData),
				typeof(int)
			}, (Type[])null) != null;
		}

		[HarmonyPrefix]
		public static bool Prefix(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null)
			{
				return true;
			}
			string name = ((Object)item.m_dropPrefab).name;
			return name != "Hearthstone" && name != "Awakened_Hearthstone";
		}
	}
	[HarmonyPatch(typeof(Player), "EatFood")]
	public static class Patch_Player_EatFood
	{
		private static bool Prepare()
		{
			return AccessTools.Method(typeof(Player), "EatFood", (Type[])null, (Type[])null) != null;
		}

		[HarmonyPrefix]
		public static bool Prefix(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null)
			{
				return true;
			}
			string name = ((Object)item.m_dropPrefab).name;
			return name != "Hearthstone" && name != "Awakened_Hearthstone";
		}
	}
	[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
	{
		typeof(ItemData),
		typeof(int),
		typeof(bool),
		typeof(float)
	})]
	public static class Patch_ItemData_GetTooltip
	{
		private static bool Prepare()
		{
			return AccessTools.Method(typeof(ItemData), "GetTooltip", new Type[4]
			{
				typeof(ItemData),
				typeof(int),
				typeof(bool),
				typeof(float)
			}, (Type[])null) != null;
		}

		[HarmonyPostfix]
		public static void Postfix(ItemData item, ref string __result)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null)
			{
				return;
			}
			string name = ((Object)item.m_dropPrefab).name;
			bool flag = name == "Hearthstone";
			bool flag2 = name == "Awakened_Hearthstone";
			if (!flag && !flag2)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				__result += "\n<color=#CCCCCC><i>$tt_hs_cast</i></color>";
				if (flag)
				{
					__result += "\n<color=#AAAAAA><i>$tt_hs_restrict</i></color>";
				}
				float remainingSeconds = CooldownManager.GetRemainingSeconds(localPlayer, flag2);
				__result += ((remainingSeconds <= 0f) ? "\n<color=#55FF55>$tt_hs_ready</color>" : ("\n<color=#FF9900>$tt_hs_cooldown " + CooldownManager.FormatRemaining(localPlayer, flag2) + "</color>"));
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnSpawned")]
	public static class Patch_Player_OnSpawned
	{
		private static bool _glowApplied;

		private static bool Prepare()
		{
			return AccessTools.Method(typeof(Player), "OnSpawned", (Type[])null, (Type[])null) != null;
		}

		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				CooldownManager.ResumeOnLogin(__instance);
				if (!_glowApplied)
				{
					_glowApplied = true;
					((MonoBehaviour)__instance).StartCoroutine(ApplyGlowDelayed());
				}
			}
		}

		private static IEnumerator ApplyGlowDelayed()
		{
			yield return (object)new WaitForSeconds(2f);
			HearthstonePlugin.Instance?.ApplyDroppedItemEffects();
		}
	}
	[HarmonyPatch(typeof(Player), "Awake")]
	public static class Patch_Player_Awake
	{
		private static bool Prepare()
		{
			return AccessTools.Method(typeof(Player), "Awake", (Type[])null, (Type[])null) != null;
		}

		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null) && component.IsValid())
			{
				component.Register<bool>("RPC_HearthstoneUsed", (Action<long, bool>)delegate
				{
				});
			}
		}
	}
}