Decompiled source of Build Your Own Bench v1.2.1

plugins/BuildYourOwnBench/BuildYourOwnBench.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GlobalEnums;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BeplnexMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BeplnexMod")]
[assembly: AssemblyTitle("BeplnexMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
[Serializable]
public class BenchData
{
	public string SceneName;

	public float PositionX;

	public float PositionY;

	public float PinPositionX;

	public float PinPositionY;

	public bool FacingRight;

	public string ID;

	public string CustomName;

	public static string CreateId(string sceneName, float x, float y)
	{
		return "MOD_BENCH_" + sceneName + "_" + x.ToString("F2") + "_" + y.ToString("F2");
	}
}
public static class BenchPrefabHolder
{
	public static GameObject BenchPrefab;

	public static bool IsReady;
}
[BepInPlugin("buildyourownbench", "Build Your Own Bench", "1.2.1")]
public class BuildYourOwnBench : BaseUnityPlugin
{
	[HarmonyPatch(typeof(GameManager), "PlayerDead")]
	public static class GameManager_PlayerDead_Patch
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			OnPlayerDeath();
		}
	}

	[HarmonyPatch(typeof(GameManager), "ReturnToMainMenu")]
	public static class GameManager_ReturnToMainMenu_Patch
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			if ((Object)(object)pinManagerObject != (Object)null)
			{
				Object.Destroy((Object)(object)pinManagerObject);
				pinManagerObject = null;
			}
			if ((Object)(object)_modSkin != (Object)null)
			{
				_modSkin = null;
			}
		}
	}

	[HarmonyPatch(typeof(UIManager), "ContinueGame")]
	public static class UIManager_ContinueGame_Patch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if ((Object)(object)pinManagerObject == (Object)null)
			{
				pinManagerObject = new GameObject("ModBenchPinManager");
				pinManagerObject.AddComponent<ModBenchPinManager>();
			}
			if ((Object)(object)Instance != (Object)null)
			{
				Instance.LoadBenchesFromFile();
				Instance.RegisterAllBenchesInTeleportMap();
			}
		}
	}

	[HarmonyPatch(typeof(UIManager), "StartNewGame")]
	public static class UIManager_StartNewGame_Patch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if ((Object)(object)pinManagerObject == (Object)null)
			{
				pinManagerObject = new GameObject("ModBenchPinManager");
				pinManagerObject.AddComponent<ModBenchPinManager>();
			}
			if ((Object)(object)Instance != (Object)null)
			{
				Instance.LoadBenchesFromFile();
				Instance.RegisterAllBenchesInTeleportMap();
			}
		}
	}

	[HarmonyPatch(typeof(InputHandler), "Update")]
	public static class InputHandler_Update_Patch
	{
		private static MethodInfo _setCursorVisibleMethod;

		[HarmonyPrefix]
		public static bool Prefix(InputHandler __instance)
		{
			if (BenchManagerUI.IsVisible || BenchManagerUI.IsPromptVisible)
			{
				if (_setCursorVisibleMethod == null)
				{
					_setCursorVisibleMethod = typeof(InputHandler).GetMethod("SetCursorVisible", BindingFlags.Instance | BindingFlags.NonPublic);
				}
				_setCursorVisibleMethod?.Invoke(__instance, new object[1] { true });
				return false;
			}
			return true;
		}
	}

	internal static ManualLogSource Log;

	private static string _saveFilePath;

	public static GameObject pinManagerObject;

	private static List<BenchData> _customBenches;

	private float pixelUnit = 100f;

	private Sprite normalBenchSprite = null;

	private Sprite destroyedBenchSprite = null;

	private static bool hasStartedAcquisition;

	public static string lastRecreatedScene;

	private bool _isBuilding = false;

	private float _buildTimer = 0f;

	private const float BUILD_TIME = 2f;

	private bool _isDestroying = false;

	private float _destroyTimer = 0f;

	private const float DESTROY_TIME = 1f;

	private GameObject _benchToDestroy = null;

	private bool _isPanicking = false;

	private float _panicTimer = 0f;

	private const float PANIC_TIME = 3f;

	private ParticleSystem _activeParticles;

	private static readonly object _inputBlocker;

	private static Material _buildParticleMaterial;

	private static Material _destroyParticleMaterial;

	private const string DESTROYED_MARKER_PREFIX = "TEMP_DESTROYED_";

	private static string _lastKnownRespawnMarker;

	private ConfigEntry<KeyCode> BuildKey;

	private ConfigEntry<KeyCode> PanicKey;

	private static ConfigEntry<int> ShardCost;

	private static ConfigEntry<int> BenchLimitPerScene;

	private static ConfigEntry<float> BenchYAxisOffset;

	private ConfigEntry<bool> PromptOnBuild;

	private ConfigEntry<KeyCode> ToggleUIKey;

	private ConfigEntry<bool> EnableTeleport;

	private BenchManagerUI _uiInstance;

	private static GUISkin _modSkin;

	private static readonly Dictionary<string, string> ExactSceneMap;

	private static readonly List<KeyValuePair<string, string>> StartsWithSceneMap;

	public static BuildYourOwnBench Instance { get; private set; }

	private string bundlePath => Path.Combine(Application.streamingAssetsPath, "aa", "StandaloneWindows64", "scenes_scenes_scenes", "weave_07.bundle");

	private string bundlePath_backup => Path.Combine(Application.streamingAssetsPath, "aa", "StandaloneWindows64", "scenes_scenes_scenes", "bone_04.bundle");

	private string modDir => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	private void Awake()
	{
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		ToggleUIKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "ToggleUIKey", (KeyCode)283, "Key to open and close the Modded Bench Manager UI.");
		EnableTeleport = ((BaseUnityPlugin)this).Config.Bind<bool>("Cheat", "EnableTeleport", false, "When enabled, it will add an option in UI to allow player to teleport to a modded bench");
		PanicKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "PanicButton", (KeyCode)8, "Hold this key for 3 seconds to trigger panic button if you get a black screen to force a scene reload.");
		BuildKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "BuildKey", (KeyCode)122, "The key to hold on your keyboard or controller to build and destroy modded benches.");
		ShardCost = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "ShardCost", 150, "How many shards are required to build a bench.");
		BenchLimitPerScene = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "BenchLimitPerScene", 2, "How many modded bench you can build in one scene");
		BenchYAxisOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Customization", "BenchYAxisOffset", 0.9f, "Offset used to adjust modded bench's Y Axis to fit the custom sprite. The bigger the value, the lower the modded bench will be when placed");
		PromptOnBuild = ((BaseUnityPlugin)this).Config.Bind<bool>("Customization", "PromptOnBuild", true, "Whether to display a prompt box to edit the name upon a bench is built. You can always edit the name in UI");
		Log = ((BaseUnityPlugin)this).Logger;
		_saveFilePath = Path.Combine(Paths.ConfigPath, "BenchesBuilt.json");
		SceneManager.sceneLoaded += OnSceneLoaded;
		try
		{
			new Harmony("buildyourownbench").PatchAll(typeof(BuildYourOwnBench).Assembly);
			Log.LogInfo((object)"Build Your Own Bench Plugin Loaded");
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"Failed to load plugin: {arg}");
		}
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
	}

	private void Update()
	{
		//IL_002e: 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_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)HeroController.instance == (Object)null || !BenchPrefabHolder.IsReady)
		{
			return;
		}
		HeroController instance = HeroController.instance;
		if (Input.GetKeyDown(ToggleUIKey.Value))
		{
			if ((Object)(object)_uiInstance == (Object)null)
			{
				GameObject val = new GameObject("BenchManagerUI");
				Object.DontDestroyOnLoad((Object)(object)val);
				_uiInstance = val.AddComponent<BenchManagerUI>();
				_uiInstance.Initialize(this);
			}
			_uiInstance.Toggle();
		}
		if (Input.GetKeyDown(BuildKey.Value))
		{
			if (_isBuilding || _isDestroying || _isPanicking)
			{
				return;
			}
			if (instance.cState.nearBench)
			{
				StartBenchDestruction();
			}
			else if (instance.cState.onGround)
			{
				StartBenchCreation();
			}
		}
		if (Input.GetKeyUp(BuildKey.Value))
		{
			if (_isBuilding)
			{
				CancelBenchCreation();
			}
			if (_isDestroying)
			{
				CancelBenchDestruction();
			}
		}
		if (Input.GetKeyDown(PanicKey.Value))
		{
			if (_isBuilding || _isDestroying || _isPanicking)
			{
				return;
			}
			_isPanicking = true;
			_panicTimer = 0f;
			Log.LogWarning((object)"Panic button active... Waiting for confirmation timer");
		}
		if (Input.GetKeyUp(PanicKey.Value) && _isPanicking)
		{
			_isPanicking = false;
			_panicTimer = 0f;
		}
		if (_isBuilding)
		{
			if (!instance.cState.onGround)
			{
				CancelBenchCreation();
				return;
			}
			_buildTimer += Time.deltaTime;
			if (_buildTimer >= 2f)
			{
				FinalizeBenchCreation();
			}
		}
		else if (_isDestroying)
		{
			if (!instance.cState.nearBench)
			{
				CancelBenchDestruction();
				return;
			}
			_destroyTimer += Time.deltaTime;
			if (_destroyTimer >= 1f)
			{
				FinalizeBenchDestruction();
			}
		}
		else if (_isPanicking)
		{
			_panicTimer += Time.deltaTime;
			if (_panicTimer >= 3f)
			{
				TriggerPanicReload();
			}
		}
		CheckAndCleanupDestroyedMarkers();
	}

	private void RegisterAllBenchesInTeleportMap()
	{
		if (_customBenches == null || _customBenches.Count == 0)
		{
			return;
		}
		Log.LogInfo((object)$"Pre-registering all {_customBenches.Count} custom benches created in SceneTeleportMap");
		foreach (BenchData customBench in _customBenches)
		{
			try
			{
				SceneTeleportMap.AddRespawnPoint(customBench.SceneName, customBench.ID);
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to pre-register respawn point '{customBench.ID}' in scene '{customBench.SceneName}': {arg}");
			}
		}
		Log.LogInfo((object)"Finished pre-registering custom benches.");
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if (!BenchPrefabHolder.IsReady && !hasStartedAcquisition && (Object)(object)HeroController.instance != (Object)null)
		{
			hasStartedAcquisition = true;
			((MonoBehaviour)this).StartCoroutine(AcquireBenchPrefabFromSceneBundle());
		}
		if (BenchPrefabHolder.IsReady && lastRecreatedScene != ((Scene)(ref scene)).name)
		{
			lastRecreatedScene = ((Scene)(ref scene)).name;
			((MonoBehaviour)this).StartCoroutine(RecreateBenchesCoroutine(((Scene)(ref scene)).name));
		}
	}

	private IEnumerator AcquireBenchPrefabFromSceneBundle()
	{
		if (BenchPrefabHolder.IsReady)
		{
			yield break;
		}
		AssetBundleCreateRequest bundleLoadRequest = AssetBundle.LoadFromFileAsync(bundlePath);
		yield return bundleLoadRequest;
		AssetBundle sceneBundle = bundleLoadRequest.assetBundle;
		if ((Object)(object)sceneBundle == (Object)null)
		{
			Log.LogWarning((object)"Failed to load the scene asset bundle, using backup asset");
			bundleLoadRequest = AssetBundle.LoadFromFileAsync(bundlePath_backup);
			sceneBundle = bundleLoadRequest.assetBundle;
			if ((Object)(object)sceneBundle == (Object)null)
			{
				Log.LogError((object)"No asset can be used, mod failed to load");
				yield break;
			}
		}
		string[] scenePaths = sceneBundle.GetAllScenePaths();
		if (scenePaths == null || scenePaths.Length == 0)
		{
			Log.LogError((object)"No scenes found in asset bundle.");
			sceneBundle.Unload(false);
			yield break;
		}
		string sceneToLoad = Path.GetFileNameWithoutExtension(scenePaths[0]);
		yield return SceneManager.LoadSceneAsync(sceneToLoad, (LoadSceneMode)1);
		yield return null;
		RestBench[] allBenches = Object.FindObjectsOfType<RestBench>();
		GameObject sourceBenchObject = null;
		RestBench[] array = allBenches;
		Scene val;
		foreach (RestBench bench in array)
		{
			try
			{
				val = ((Component)bench).gameObject.scene;
				if (((Scene)(ref val)).name == sceneToLoad && (Object)(object)((Component)bench).GetComponent<HeroController>() == (Object)null)
				{
					sourceBenchObject = ((Component)bench).gameObject;
					break;
				}
			}
			catch
			{
			}
		}
		if ((Object)(object)sourceBenchObject != (Object)null)
		{
			try
			{
				pixelUnit = sourceBenchObject.GetComponent<SpriteRenderer>().sprite.pixelsPerUnit;
				normalBenchSprite = LoadSpriteFromFile(Path.Combine(modDir, "SpriteAsset", "modded_bench_normal_sprite_bench.png"), pixelUnit);
				destroyedBenchSprite = LoadSpriteFromFile(Path.Combine(modDir, "SpriteAsset", "modded_bench_destroyed_sprite_bench.png"), pixelUnit);
			}
			catch
			{
				Log.LogError((object)"Failed to load custom bench sprite");
			}
			BenchPrefabHolder.BenchPrefab = Object.Instantiate<GameObject>(sourceBenchObject);
			((Object)BenchPrefabHolder.BenchPrefab).name = "MODDED_BENCH_PREFAB (DoNotRemove)";
			BenchPrefabHolder.BenchPrefab.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)BenchPrefabHolder.BenchPrefab);
			BenchPrefabHolder.IsReady = true;
			val = SceneManager.GetActiveScene();
			RecreateBenchesForScene(lastRecreatedScene = ((Scene)(ref val)).name);
		}
		else
		{
			Log.LogError((object)"Failed to find a suitable RestBench in loaded scene.");
		}
		yield return SceneManager.UnloadSceneAsync(sceneToLoad);
		sceneBundle.Unload(false);
	}

	private IEnumerator RecreateBenchesCoroutine(string sceneName)
	{
		yield return (object)new WaitForEndOfFrame();
		RecreateBenchesForScene(sceneName);
	}

	private void RecreateBenchesForScene(string sceneName)
	{
		foreach (BenchData customBench in _customBenches)
		{
			if (customBench.SceneName == sceneName && !((Object)(object)GameObject.Find(customBench.ID) != (Object)null))
			{
				InstantiateBench(customBench);
			}
		}
	}

	private static void SaveBenchesToFile()
	{
		try
		{
			Directory.CreateDirectory(Path.GetDirectoryName(_saveFilePath));
			File.WriteAllText(_saveFilePath, JsonConvert.SerializeObject((object)_customBenches, (Formatting)1));
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"Failed to save benches to file: {arg}");
		}
	}

	private void LoadBenchesFromFile()
	{
		try
		{
			if (!File.Exists(_saveFilePath))
			{
				_customBenches = new List<BenchData>();
				return;
			}
			string text = File.ReadAllText(_saveFilePath);
			_customBenches = JsonConvert.DeserializeObject<List<BenchData>>(text) ?? new List<BenchData>();
			if ((Object)(object)ModBenchPinManager.Instance != (Object)null)
			{
				ModBenchPinManager.Instance.ScheduleRecreation(_customBenches);
			}
			else
			{
				Log.LogError((object)"Modded Bench Pin Failed to Setup because ModBenchPinManager.Instance Is Not Created");
			}
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"Failed to load benches from file: {arg}");
			_customBenches = new List<BenchData>();
		}
	}

	private Sprite LoadSpriteFromFile(string filePath, float pixelsPerUnit)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		if (!File.Exists(filePath))
		{
			return null;
		}
		byte[] array = File.ReadAllBytes(filePath);
		Texture2D val = new Texture2D(2, 2);
		if (ImageConversion.LoadImage(val, array))
		{
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), pixelsPerUnit);
			((Object)val2).name = Path.GetFileNameWithoutExtension(filePath);
			return val2;
		}
		return null;
	}

	private void InstantiateBench(BenchData benchData)
	{
		//IL_0061: 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)
		if (!BenchPrefabHolder.IsReady)
		{
			return;
		}
		string sceneName = benchData.SceneName;
		string text = benchData.ID ?? BenchData.CreateId(sceneName, benchData.PositionX, benchData.PositionY);
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(benchData.PositionX, benchData.PositionY - BenchYAxisOffset.Value, 0.01f);
		GameObject val2;
		try
		{
			val2 = Object.Instantiate<GameObject>(BenchPrefabHolder.BenchPrefab, val, Quaternion.identity);
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"Failed to instantiate bench prefab: {arg}");
			return;
		}
		((Object)val2).name = text;
		RespawnMarker component = val2.GetComponent<RespawnMarker>();
		if ((Object)(object)component != (Object)null)
		{
			component.respawnFacingRight = benchData.FacingRight;
		}
		RespawnTrigger component2 = val2.GetComponent<RespawnTrigger>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.respawnType = 1;
		}
		SpriteRenderer component3 = val2.GetComponent<SpriteRenderer>();
		if ((Object)(object)component3 != (Object)null)
		{
			component3.sprite = normalBenchSprite;
		}
		Transform val3 = val2.transform.Find("Lit");
		if ((Object)(object)val3 != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)val3).gameObject);
		}
		val2.SetActive(true);
		try
		{
			Dictionary<string, SceneInfo> teleportMap = SceneTeleportMap.GetTeleportMap();
			if (teleportMap != null && teleportMap.ContainsKey(sceneName))
			{
				SceneInfo val4 = teleportMap[sceneName];
				if (!val4.RespawnPoints.Contains(text))
				{
					SceneTeleportMap.AddRespawnPoint(sceneName, text);
				}
			}
			else
			{
				SceneTeleportMap.AddRespawnPoint(sceneName, text);
			}
		}
		catch (Exception arg2)
		{
			Log.LogError((object)$"Failed to call SceneTeleportMap.AddRespawnPoint: {arg2}");
		}
		if (text.StartsWith("TEMP_DESTROYED_"))
		{
			ConvertBenchToDestroyedState(val2);
		}
	}

	private void StartBenchCreation()
	{
		if (CurrencyManager.GetCurrencyAmount((CurrencyType)1) >= ShardCost.Value)
		{
			int num = _customBenches.Count(delegate(BenchData b)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				string sceneName = b.SceneName;
				Scene activeScene = SceneManager.GetActiveScene();
				return sceneName == ((Scene)(ref activeScene)).name;
			});
			if (num < BenchLimitPerScene.Value)
			{
				_isBuilding = true;
				_buildTimer = 0f;
				HeroController.instance.AddInputBlocker(_inputBlocker);
				CreateBuildParticles();
				_activeParticles.Play();
			}
		}
	}

	private void CancelBenchCreation()
	{
		if (_isBuilding)
		{
			_isBuilding = false;
			_buildTimer = 0f;
			HeroController.instance.RemoveInputBlocker(_inputBlocker);
			if ((Object)(object)_activeParticles != (Object)null)
			{
				_activeParticles.Stop();
				Object.Destroy((Object)(object)((Component)_activeParticles).gameObject, 2f);
				_activeParticles = null;
			}
		}
	}

	private BenchData CreateAndSaveBenchAtPlayer()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		string name = ((Scene)(ref activeScene)).name;
		float x = ((Component)HeroController.instance).transform.position.x;
		float y = ((Component)HeroController.instance).transform.position.y;
		bool facingRight = HeroController.instance.cState.facingRight;
		string id = BenchData.CreateId(name, x, y);
		if (_customBenches.Exists((BenchData b) => b.ID == id))
		{
			return null;
		}
		BenchData benchData = new BenchData
		{
			SceneName = name,
			PositionX = x,
			PositionY = y,
			FacingRight = facingRight,
			ID = id
		};
		_customBenches.Add(benchData);
		SaveBenchesToFile();
		InstantiateBench(benchData);
		return benchData;
	}

	private void FinalizeBenchCreation()
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		if (CurrencyManager.GetCurrencyAmount((CurrencyType)1) >= ShardCost.Value)
		{
			CurrencyManager.TakeCurrency(ShardCost.Value, (CurrencyType)1, true);
			BenchData benchData = CreateAndSaveBenchAtPlayer();
			if (benchData != null)
			{
				ModBenchPinManager.Instance.CreatePinForBench(benchData);
				benchData.CustomName = "Bench_at_" + GetAreaNameForScene(benchData.SceneName);
				SaveBenchesToFile();
				if (PromptOnBuild.Value)
				{
					if ((Object)(object)_uiInstance == (Object)null)
					{
						GameObject val = new GameObject("BenchManagerUI");
						Object.DontDestroyOnLoad((Object)(object)val);
						_uiInstance = val.AddComponent<BenchManagerUI>();
						_uiInstance.Initialize(this);
					}
					_uiInstance.ShowCreationPrompt(benchData);
				}
			}
		}
		CancelBenchCreation();
	}

	private GameObject FindClosestModdedBench()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		Vector3 playerPos = ((Component)HeroController.instance).transform.position;
		return (from bench in Object.FindObjectsOfType<RestBench>()
			select ((Component)bench).gameObject into go
			where ((Object)go).name.StartsWith("MOD_BENCH_")
			orderby Vector3.Distance(go.transform.position, playerPos)
			select go).FirstOrDefault();
	}

	private void StartBenchDestruction()
	{
		_benchToDestroy = FindClosestModdedBench();
		if (!((Object)(object)_benchToDestroy == (Object)null))
		{
			_isDestroying = true;
			_destroyTimer = 0f;
			HeroController.instance.AddInputBlocker(_inputBlocker);
			CreateDestroyParticles();
			_activeParticles.Play();
		}
	}

	private void CancelBenchDestruction()
	{
		if (_isDestroying)
		{
			_isDestroying = false;
			_destroyTimer = 0f;
			_benchToDestroy = null;
			HeroController.instance.RemoveInputBlocker(_inputBlocker);
			if ((Object)(object)_activeParticles != (Object)null)
			{
				_activeParticles.Stop();
				Object.Destroy((Object)(object)((Component)_activeParticles).gameObject, 2f);
				_activeParticles = null;
			}
		}
	}

	private void FinalizeBenchDestruction()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_benchToDestroy != (Object)null)
		{
			string benchId = ((Object)_benchToDestroy).name;
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (PlayerData.instance.respawnMarkerName == benchId)
			{
				ConvertBenchToDestroyedState(_benchToDestroy);
				string text = "TEMP_DESTROYED_" + benchId;
				((Object)_benchToDestroy).name = text;
				Dictionary<string, SceneInfo> teleportMap = SceneTeleportMap.GetTeleportMap();
				if (teleportMap != null && teleportMap.ContainsKey(name))
				{
					teleportMap[name].RespawnPoints.Remove(benchId);
					teleportMap[name].RespawnPoints.Add(text);
				}
				PlayerData.instance.respawnScene = name;
				PlayerData.instance.respawnMarkerName = text;
				PlayerData.instance.respawnType = 0;
				BenchData benchData = _customBenches.Find((BenchData b) => b.ID == benchId);
				benchData.ID = text;
				ModBenchPinManager.Instance.ConvertPinToTemporary(benchId, text, benchData);
			}
			else
			{
				Object.Destroy((Object)(object)_benchToDestroy);
				_customBenches.RemoveAll((BenchData b) => b.ID == benchId);
				ModBenchPinManager.Instance.RemovePin(benchId);
			}
			SaveBenchesToFile();
		}
		CancelBenchDestruction();
	}

	private void ConvertBenchToDestroyedState(GameObject benchObject)
	{
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Expected O, but got Unknown
		Collider2D[] components = benchObject.GetComponents<Collider2D>();
		foreach (Collider2D val in components)
		{
			((Behaviour)val).enabled = false;
		}
		RestBench component = benchObject.GetComponent<RestBench>();
		if ((Object)(object)component != (Object)null)
		{
			((Behaviour)component).enabled = false;
		}
		SpriteRenderer component2 = benchObject.GetComponent<SpriteRenderer>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.sprite = destroyedBenchSprite;
		}
		RespawnTrigger component3 = benchObject.GetComponent<RespawnTrigger>();
		if ((Object)(object)component3 != (Object)null)
		{
			component3.respawnType = 0;
		}
		List<GameObject> list = new List<GameObject>();
		foreach (Transform item in benchObject.transform)
		{
			Transform val2 = item;
			if (((Object)val2).name == "Particle B" || ((Object)val2).name == "Particle F")
			{
				list.Add(((Component)val2).gameObject);
			}
		}
		foreach (GameObject item2 in list)
		{
			Object.Destroy((Object)(object)item2);
		}
	}

	private static void CheckAndCleanupDestroyedMarkers()
	{
		string respawnMarkerName = PlayerData.instance.respawnMarkerName;
		if (!(respawnMarkerName != _lastKnownRespawnMarker))
		{
			return;
		}
		if (_lastKnownRespawnMarker != null && _lastKnownRespawnMarker.StartsWith("TEMP_DESTROYED_"))
		{
			List<BenchData> list = _customBenches.Where((BenchData b) => b.ID.StartsWith("TEMP_DESTROYED_")).ToList();
			_customBenches.RemoveAll((BenchData b) => b.ID.StartsWith("TEMP_DESTROYED_"));
			SaveBenchesToFile();
			foreach (BenchData item in list)
			{
				GameObject val = GameObject.Find(item.ID);
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				ModBenchPinManager.Instance.RemovePin(item.ID);
			}
		}
		_lastKnownRespawnMarker = respawnMarkerName;
	}

	private void GetOrCreateParticleMaterial(ref Material material, Color color)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_00c9: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)material != (Object)null)
		{
			return;
		}
		material = new Material(Shader.Find("Sprites/Default"));
		int num = 64;
		Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
		float num2 = (float)num / 2f;
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num3 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(num2, num2));
				float num4 = Mathf.Clamp01(1f - num3 / num2);
				val.SetPixel(j, i, new Color(1f, 1f, 1f, num4 * num4));
			}
		}
		val.Apply();
		material.mainTexture = (Texture)(object)val;
		material.color = color;
	}

	private void CreateBuildParticles()
	{
		//IL_002a: 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)
		//IL_0040: Expected O, but got Unknown
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: 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_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: 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_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Expected O, but got Unknown
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Expected O, but got Unknown
		//IL_0229: 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_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_activeParticles != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_activeParticles).gameObject);
		}
		GetOrCreateParticleMaterial(ref _buildParticleMaterial, Color.white);
		GameObject val = new GameObject("BuildBenchParticles");
		val.transform.SetParent(((Component)HeroController.instance).transform, false);
		val.transform.localPosition = Vector3.zero;
		_activeParticles = val.AddComponent<ParticleSystem>();
		ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
		((Renderer)component).material = _buildParticleMaterial;
		MainModule main = _activeParticles.main;
		((MainModule)(ref main)).duration = 2f;
		((MainModule)(ref main)).loop = true;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(1.5f, 2.5f);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.5f, 1.5f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.25f, 0.35f);
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.1f);
		EmissionModule emission = _activeParticles.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(50f);
		ShapeModule shape = _activeParticles.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)2;
		((ShapeModule)(ref shape)).radius = 0.8f;
		((ShapeModule)(ref shape)).rotation = new Vector3(-90f, 0f, 0f);
		ColorOverLifetimeModule colorOverLifetime = _activeParticles.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val2 = new Gradient();
		val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[1]
		{
			new GradientColorKey(Color.white, 0f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val2);
		SizeOverLifetimeModule sizeOverLifetime = _activeParticles.sizeOverLifetime;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
		AnimationCurve val3 = new AnimationCurve();
		val3.AddKey(0f, 1f);
		val3.AddKey(1f, 0f);
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, val3);
		NoiseModule noise = _activeParticles.noise;
		((NoiseModule)(ref noise)).enabled = true;
		((NoiseModule)(ref noise)).strength = MinMaxCurve.op_Implicit(0.2f);
		((NoiseModule)(ref noise)).frequency = 0.5f;
	}

	private void CreateDestroyParticles()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_010a: 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_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//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_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Expected O, but got Unknown
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_activeParticles != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_activeParticles).gameObject);
		}
		GetOrCreateParticleMaterial(ref _destroyParticleMaterial, new Color(1f, 0.2f, 0.2f));
		GameObject val = new GameObject("DestroyBenchParticles");
		val.transform.SetParent(_benchToDestroy.transform, false);
		val.transform.localPosition = new Vector3(0f, 1f, 0f);
		_activeParticles = val.AddComponent<ParticleSystem>();
		ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
		((Renderer)component).material = _destroyParticleMaterial;
		MainModule main = _activeParticles.main;
		((MainModule)(ref main)).duration = 1f;
		((MainModule)(ref main)).loop = true;
		((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(1f);
		((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(2f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.25f, 0.35f);
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.2f);
		EmissionModule emission = _activeParticles.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(80f);
		ShapeModule shape = _activeParticles.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
		((ShapeModule)(ref shape)).radius = 1.5f;
		ColorOverLifetimeModule colorOverLifetime = _activeParticles.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val2 = new Gradient();
		val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[1]
		{
			new GradientColorKey(Color.white, 0f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val2);
	}

	public static void OnPlayerDeath()
	{
		lastRecreatedScene = null;
	}

	private void TriggerPanicReload()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		string name = ((Scene)(ref activeScene)).name;
		Log.LogWarning((object)("PANIC TRIGGERED! Reloading current scene '" + name + "' to fix potential softlock."));
		_isPanicking = false;
		_panicTimer = 0f;
		GameManager instance = GameManager.instance;
		if ((Object)(object)instance != (Object)null)
		{
			instance.LoadScene(name);
		}
		else
		{
			Log.LogError((object)"Could not find GameManager instance to trigger panic reload!");
		}
	}

	public List<BenchData> GetBenchList()
	{
		return _customBenches;
	}

	public bool IsTeleportEnabled()
	{
		return EnableTeleport.Value;
	}

	public void RenameBench(string benchId, string newName)
	{
		BenchData benchData = _customBenches.Find((BenchData b) => b.ID == benchId);
		if (benchData != null)
		{
			benchData.CustomName = newName;
			SaveBenchesToFile();
		}
	}

	public void RequestDeleteBench(string benchId)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find(benchId);
		Scene activeScene = SceneManager.GetActiveScene();
		string name = ((Scene)(ref activeScene)).name;
		Dictionary<string, SceneInfo> teleportMap = SceneTeleportMap.GetTeleportMap();
		if ((Object)(object)val != (Object)null)
		{
			if (PlayerData.instance.respawnMarkerName == benchId)
			{
				ConvertBenchToDestroyedState(val);
				string text = (((Object)val).name = "TEMP_DESTROYED_" + benchId);
				if (teleportMap != null)
				{
					teleportMap[name].RespawnPoints.Remove(benchId);
					teleportMap[name].RespawnPoints.Add(text);
				}
				PlayerData.instance.respawnMarkerName = text;
				PlayerData.instance.respawnType = 0;
				BenchData benchData = _customBenches.Find((BenchData b) => b.ID == benchId);
				benchData.ID = text;
				ModBenchPinManager.Instance.ConvertPinToTemporary(benchId, text, benchData);
			}
			else
			{
				Object.Destroy((Object)(object)val);
				_customBenches.RemoveAll((BenchData b) => b.ID == benchId);
				ModBenchPinManager.Instance.RemovePin(benchId);
			}
		}
		else if (PlayerData.instance.respawnMarkerName == benchId)
		{
			string text3 = "TEMP_DESTROYED_" + benchId;
			BenchData benchData2 = _customBenches.Find((BenchData b) => b.ID == benchId);
			name = benchData2.SceneName;
			if (teleportMap != null)
			{
				teleportMap[name].RespawnPoints.Remove(benchId);
				teleportMap[name].RespawnPoints.Add(text3);
			}
			PlayerData.instance.respawnMarkerName = text3;
			PlayerData.instance.respawnType = 0;
			benchData2.ID = text3;
			ModBenchPinManager.Instance.ConvertPinToTemporary(benchId, text3, benchData2);
		}
		else
		{
			_customBenches.RemoveAll((BenchData b) => b.ID == benchId);
			ModBenchPinManager.Instance.RemovePin(benchId);
		}
		SaveBenchesToFile();
	}

	public void RequestTeleportToBench(BenchData bench)
	{
		if (!((Object)(object)HeroController.instance == (Object)null))
		{
			if ((Object)(object)_uiInstance != (Object)null)
			{
				_uiInstance.Hide();
			}
			((MonoBehaviour)this).StartCoroutine(TeleportPlayer(bench));
		}
	}

	private IEnumerator TeleportPlayer(BenchData bench)
	{
		if (GameManager.instance.sceneName != bench.SceneName)
		{
			GameManager.instance.LoadScene(bench.SceneName);
			yield return (object)new WaitUntil((Func<bool>)(() => GameManager.instance.sceneName == bench.SceneName));
			yield return (object)new WaitForSeconds(0.5f);
		}
		((Component)HeroController.instance).transform.position = new Vector3(bench.PositionX, bench.PositionY + 1f);
		HeroController.instance.cState.onGround = true;
	}

	public static GUISkin GetModSkin()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_00f3: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Expected O, but got Unknown
		//IL_02ee: Expected O, but got Unknown
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Expected O, but got Unknown
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Expected O, but got Unknown
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Expected O, but got Unknown
		if ((Object)(object)_modSkin == (Object)null)
		{
			try
			{
				Color col = default(Color);
				((Color)(ref col))..ctor(0.1f, 0.1f, 0.1f, 0.95f);
				Color col2 = default(Color);
				((Color)(ref col2))..ctor(0.05f, 0.05f, 0.05f, 0.95f);
				Color col3 = default(Color);
				((Color)(ref col3))..ctor(0.15f, 0.15f, 0.15f, 0.95f);
				Color col4 = default(Color);
				((Color)(ref col4))..ctor(0.2f, 0.2f, 0.2f, 0.95f);
				Color col5 = default(Color);
				((Color)(ref col5))..ctor(0.3f, 0.3f, 0.3f, 1f);
				Color col6 = default(Color);
				((Color)(ref col6))..ctor(0.4f, 0.4f, 0.4f, 1f);
				Color col7 = default(Color);
				((Color)(ref col7))..ctor(0.1f, 0.1f, 0.1f, 1f);
				Texture2D background = MakeTex(1, 1, col);
				Texture2D background2 = MakeTex(1, 1, col3);
				Texture2D background3 = MakeTex(1, 1, col4);
				Texture2D background4 = MakeTex(1, 1, col5);
				Texture2D background5 = MakeTex(1, 1, col6);
				Texture2D background6 = MakeTex(1, 1, col7);
				_modSkin = Object.Instantiate<GUISkin>(GUI.skin);
				((Object)_modSkin).hideFlags = (HideFlags)61;
				_modSkin.window.normal.background = MakeTex(1, 1, col2);
				_modSkin.window.onNormal.background = MakeTex(1, 1, col2);
				_modSkin.window.fontStyle = (FontStyle)1;
				_modSkin.window.normal.textColor = Color.white;
				_modSkin.box.normal.background = background3;
				_modSkin.label.normal.textColor = Color.white;
				_modSkin.button.normal.background = background4;
				_modSkin.button.hover.background = background5;
				_modSkin.button.active.background = background5;
				_modSkin.button.normal.textColor = Color.white;
				_modSkin.button.hover.textColor = Color.white;
				_modSkin.button.active.textColor = Color.white;
				_modSkin.scrollView.normal.background = background;
				_modSkin.verticalScrollbar.normal.background = background6;
				_modSkin.verticalScrollbarThumb.normal.background = background4;
				_modSkin.verticalScrollbarThumb.hover.background = background5;
				GUIStyle val = new GUIStyle(_modSkin.box)
				{
					name = "HeaderBox"
				};
				val.normal.background = background2;
				val.padding = new RectOffset(5, 5, 5, 5);
				GUIStyle val2 = val;
				GUIStyle val3 = new GUIStyle(_modSkin.label)
				{
					name = "HeaderLabel",
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3
				};
				_modSkin.customStyles = (GUIStyle[])(object)new GUIStyle[2] { val2, val3 };
				_modSkin.window.padding = new RectOffset(8, 8, 30, 8);
				_modSkin.button.margin = new RectOffset(2, 2, 2, 2);
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Error creating modded bench manager UI skin: {arg}");
				_modSkin = GUI.skin;
			}
		}
		return _modSkin;
	}

	private static Texture2D MakeTex(int width, int height, Color col)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		Color[] array = (Color[])(object)new Color[width * height];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = col;
		}
		Texture2D val = new Texture2D(width, height);
		((Object)val).hideFlags = (HideFlags)61;
		val.SetPixels(array);
		val.Apply();
		return val;
	}

	static BuildYourOwnBench()
	{
		_customBenches = new List<BenchData>();
		hasStartedAcquisition = false;
		lastRecreatedScene = null;
		_inputBlocker = new object();
		ExactSceneMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
		StartsWithSceneMap = new List<KeyValuePair<string, string>>();
		ExactSceneMap["Abandoned_town"] = "Nameless Town";
		ExactSceneMap["Abyss_Cocoon"] = "Lost Lace Fight";
		ExactSceneMap["Aspid_01"] = "Bone Bottom";
		ExactSceneMap["Bellshrine"] = "The Marrow";
		ExactSceneMap["Bellshrine_02"] = "Greymoor";
		ExactSceneMap["Bellshrine_03"] = "Shellwood";
		ExactSceneMap["Bellshrine_05"] = "Deep Docks";
		ExactSceneMap["Bellshrine_Coral"] = "Sands of Karak";
		ExactSceneMap["Bellshrine_Enclave"] = "Choral Chambers";
		ExactSceneMap["Bellway_01"] = "Bone Bottom";
		ExactSceneMap["Bellway_02"] = "Deep Docks";
		ExactSceneMap["Bellway_03"] = "Far Fields";
		ExactSceneMap["Bellway_04"] = "Greymoor";
		ExactSceneMap["Bellway_08"] = "Blasted Steps";
		ExactSceneMap["Bellway_Aqueduct"] = "Putrified Ducts";
		ExactSceneMap["Bellway_City"] = "Choral Chambers";
		ExactSceneMap["Bellway_Shadow"] = "Bilewater";
		ExactSceneMap["Bellway_Centipede_Arena"] = "Centipede Arena";
		ExactSceneMap["Bone_East_01"] = "Deep Docks";
		ExactSceneMap["Bone_East_02"] = "Far Fields";
		ExactSceneMap["Bone_East_03"] = "Deep Docks";
		ExactSceneMap["Bone_East_05"] = "Deep Docks";
		ExactSceneMap["Bone_East_07"] = "Far Fields";
		ExactSceneMap["Bone_East_08"] = "Far Fields";
		ExactSceneMap["Bone_East_11"] = "Far Fields";
		ExactSceneMap["Bone_East_12"] = "Deep Docks";
		ExactSceneMap["Bone_East_13"] = "Deep Docks";
		ExactSceneMap["Bone_East_15"] = "Far Fields";
		ExactSceneMap["Bone_East_16"] = "Far Fields";
		ExactSceneMap["Bone_East_20"] = "Far Fields";
		ExactSceneMap["Bone_East_21"] = "Far Fields";
		ExactSceneMap["Bone_East_22"] = "Far Fields";
		ExactSceneMap["Bone_East_24"] = "Far Fields";
		ExactSceneMap["Bone_East_25"] = "Far Fields";
		ExactSceneMap["Bone_East_26"] = "Far Fields";
		ExactSceneMap["Bone_East_27"] = "Far Fields";
		ExactSceneMap["Bone_East_Umbrella"] = "Far Fields";
		ExactSceneMap["Bone_East_LavaChallenge"] = "Far Fields";
		ExactSceneMap["Bone_East_Weavehome"] = "Far Fields";
		ExactSceneMap["Bone_Steel_Servant"] = "Bone Bottom";
		ExactSceneMap["Bonegrave"] = "Bone Bottom";
		ExactSceneMap["Bonetown"] = "Bone Bottom";
		ExactSceneMap["Chapel_Wanderer"] = "Bone Bottom";
		ExactSceneMap["Coral_02"] = "Blasted Steps";
		ExactSceneMap["Coral_03"] = "Blasted Steps";
		ExactSceneMap["Coral_10"] = "Grand Gate";
		ExactSceneMap["Coral_12"] = "Blasted Steps";
		ExactSceneMap["Coral_32"] = "Blasted Steps";
		ExactSceneMap["Coral_33"] = "Blasted Steps";
		ExactSceneMap["Coral_34"] = "Blasted Steps";
		ExactSceneMap["Coral_35"] = "Blasted Steps";
		ExactSceneMap["Coral_36"] = "Blasted Steps";
		ExactSceneMap["Coral_37"] = "Blasted Steps";
		ExactSceneMap["Coral_38"] = "Sands of Karak";
		ExactSceneMap["Coral_39"] = "Sands of Karak";
		ExactSceneMap["Coral_40"] = "Sands of Karak";
		ExactSceneMap["Coral_41"] = "Sands of Karak";
		ExactSceneMap["Coral_42"] = "Blasted Steps";
		ExactSceneMap["Coral_43"] = "Blasted Steps";
		ExactSceneMap["Coral_44"] = "Sands of Karak";
		ExactSceneMap["Coral_Judge_Arena"] = "Blasted Steps";
		ExactSceneMap["Coral_Tower_01"] = "Sands of Karak";
		ExactSceneMap["Halfway_01"] = "Greymoor";
		ExactSceneMap["Hang_01"] = "Choral Chambers";
		ExactSceneMap["Hang_02"] = "High Halls";
		ExactSceneMap["Hang_03"] = "High Halls";
		ExactSceneMap["Hang_04"] = "High Halls";
		ExactSceneMap["Hang_06"] = "High Halls";
		ExactSceneMap["Hang_07"] = "Choral Chambers";
		ExactSceneMap["Hang_08"] = "High Halls";
		ExactSceneMap["Hang_09"] = "High Halls";
		ExactSceneMap["Hang_10"] = "High Halls";
		ExactSceneMap["Hang_12"] = "High Halls";
		ExactSceneMap["Hang_13"] = "High Halls";
		ExactSceneMap["Hang_14"] = "High Halls";
		ExactSceneMap["Hang_15"] = "High Halls";
		ExactSceneMap["Hang_16"] = "High Halls";
		ExactSceneMap["Hang_17b"] = "High Halls";
		ExactSceneMap["Peak_01"] = "The Slab";
		ExactSceneMap["Peak_02"] = "Mount Fay";
		ExactSceneMap["Peak_07"] = "Mount Fay";
		ExactSceneMap["Peak_08"] = "Mount Fay";
		ExactSceneMap["Peak_10"] = "Mount Fay";
		ExactSceneMap["Peak_12"] = "Mount Fay";
		ExactSceneMap["Peak_Mask_Maker"] = "Mount Fay";
		ExactSceneMap["Room_CrowCourt"] = "Greymoor";
		ExactSceneMap["Room_CrowCourt_02"] = "Greymoor";
		ExactSceneMap["Room_Diving_Bell"] = "Deep Docks";
		ExactSceneMap["Room_Forge"] = "Deep Docks";
		ExactSceneMap["Room_Huntress"] = "Putrified Ducts";
		ExactSceneMap["Room_Pinstress"] = "Blasted Step";
		ExactSceneMap["Room_Witch"] = "Shellwood";
		ExactSceneMap["Shellgrave"] = "Shellwood";
		ExactSceneMap["Sprintmaster_Cave"] = "Far Fields";
		ExactSceneMap["Tube_Hub"] = "The Cradle";
		ExactSceneMap["Under_01"] = "Grand Gate";
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Abyss_", "The Abyss"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Ant_", "Hunter's March"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Aqueduct_", "Putrified Ducts"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Arborium_", "Memorium"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Belltown", "Bellhart"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Bellway_Peak", "Mount Fay"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Bone_", "The Marrow"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Bone_East_04", "Deep Docks"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Bone_East_09", "Far Fields"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Bone_East_10", "Far Fields"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Bone_East_14", "Far Fields"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Bone_East_17", "Far Fields"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Bone_East_18", "Far Fields"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Clover_", "Verdania"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Cog_", "Cogwork Core"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Coral_11", "Blasted Steps"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Coral_19", "Blasted Steps"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Coral_2", "Sands of Karak"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Cradle_", "The Cradle"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Crawl_", "Wormways"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Dock_", "Deep Docks"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Dust_", "Sinner's Road"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Dust_Maze_", "The Mist"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Greymoor_", "Greymoor"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Library_", "Whispering Vaults"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Mosstown_", "Bone Bottom"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Peak_04", "Mount Fay"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Peak_05", "Mount Fay"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Room_Caravan_", "Flea Caravan"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Room_Diving_Bell_Abyss", "The Abyss"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Shadow_", "Bilewater"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Shellwood_", "Shellwood"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Slab_", "The Slab"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Song_", "Choral Chambers"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Song_Enclave", "Songclave"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Song_Tower", "The Cradle"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Tut_", "Moss Grotto"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Under_", "Underworks"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Ward_", "Whiteward"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Weave_", "Weavenest Atla"));
		StartsWithSceneMap.Add(new KeyValuePair<string, string>("Wisp_", "Wisp Thicket"));
	}

	public static string GetAreaNameForScene(string sceneName)
	{
		if (string.IsNullOrEmpty(sceneName))
		{
			return "N/A";
		}
		if (ExactSceneMap.TryGetValue(sceneName, out string value))
		{
			return value;
		}
		for (int num = StartsWithSceneMap.Count - 1; num >= 0; num--)
		{
			if (sceneName.StartsWith(StartsWithSceneMap[num].Key, StringComparison.OrdinalIgnoreCase))
			{
				return StartsWithSceneMap[num].Value;
			}
		}
		return "Unknown Area";
	}

	public string GetCurrentRespawnId()
	{
		return PlayerData.instance?.respawnMarkerName ?? "";
	}

	public string GetCurrentSceneName()
	{
		if ((Object)(object)GameManager.instance == (Object)null)
		{
			return "N/A";
		}
		return GameManager.instance.sceneName;
	}
}
public class ModBenchPinManager : MonoBehaviour
{
	private enum BenchType
	{
		Normal,
		Temporary
	}

	private GameMap gameMap;

	private GameObject benchPinTemplate;

	private Sprite normalBenchSprite;

	private Sprite tempBenchSprite;

	private readonly Dictionary<string, GameObject> _activePins = new Dictionary<string, GameObject>();

	private bool _isInitialized = false;

	private bool _pinsRecreatedThisSession = false;

	private List<BenchData> _benchesToRecreate;

	public static ModBenchPinManager Instance { get; private set; }

	private void Awake()
	{
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		Instance = this;
	}

	private void OnDestroy()
	{
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
	}

	private void Update()
	{
		if (!_isInitialized)
		{
			Initialize();
		}
		else if (!_pinsRecreatedThisSession && _benchesToRecreate != null)
		{
			BuildYourOwnBench.Log.LogInfo((object)"Modded Bench Pin Manager is initialized For This Gameplay Session");
			RecreateAllPinsInternal();
		}
	}

	private void Initialize()
	{
		gameMap = Object.FindObjectOfType<GameMap>();
		if ((Object)(object)gameMap == (Object)null)
		{
			return;
		}
		Transform val = ((Component)gameMap).transform.Find("Ant/Ant_17/Bench Pin");
		if ((Object)(object)val != (Object)null)
		{
			benchPinTemplate = ((Component)val).gameObject;
		}
		else
		{
			benchPinTemplate = FindInactiveGameObjectByName("Bench Pin");
		}
		if (!((Object)(object)benchPinTemplate == (Object)null))
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			normalBenchSprite = LoadSpriteFromFile(Path.Combine(directoryName, "SpriteAsset", "modded_bench_normal_sprite_benchpin.png"));
			tempBenchSprite = LoadSpriteFromFile(Path.Combine(directoryName, "SpriteAsset", "modded_bench_destroyed_sprite_benchpin.png"));
			if (!((Object)(object)normalBenchSprite == (Object)null) && !((Object)(object)tempBenchSprite == (Object)null))
			{
				_isInitialized = true;
			}
		}
	}

	public void ScheduleRecreation(List<BenchData> benches)
	{
		_benchesToRecreate = benches;
		_pinsRecreatedThisSession = false;
	}

	private void RecreateAllPinsInternal()
	{
		if (_benchesToRecreate == null)
		{
			return;
		}
		foreach (BenchData item in _benchesToRecreate)
		{
			BenchType type = (item.ID.StartsWith("TEMP_DESTROYED_") ? BenchType.Temporary : BenchType.Normal);
			CreatePinInternal(item, type);
		}
		_pinsRecreatedThisSession = true;
		_benchesToRecreate = null;
	}

	public void CreatePinForBench(BenchData benchData)
	{
		if (_isInitialized)
		{
			CreatePinInternal(benchData, BenchType.Normal);
		}
	}

	public void RemovePin(string benchId)
	{
		if (_isInitialized && _activePins.TryGetValue(benchId, out GameObject value))
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)value);
			}
			_activePins.Remove(benchId);
		}
	}

	public void ConvertPinToTemporary(string originalId, string temporaryId, BenchData tempBenchData)
	{
		if (_isInitialized)
		{
			RemovePin(originalId);
			CreatePinInternal(tempBenchData, BenchType.Temporary);
		}
	}

	public void OnReturnToMenu()
	{
		_isInitialized = false;
		_pinsRecreatedThisSession = false;
		_benchesToRecreate = null;
		gameMap = null;
		benchPinTemplate = null;
		foreach (GameObject value in _activePins.Values)
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)value);
			}
		}
		_activePins.Clear();
	}

	private void CreatePinInternal(BenchData benchData, BenchType type)
	{
		//IL_013c: 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_0101: 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_0108: 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_0165: Unknown result type (might be due to invalid IL or missing references)
		if (!_isInitialized || _activePins.ContainsKey(benchData.ID) || (Object)(object)gameMap == (Object)null)
		{
			return;
		}
		gameMap.UpdateCurrentScene();
		GameObject sceneObjectFromGameMap = GetSceneObjectFromGameMap(benchData.SceneName);
		if (!((Object)(object)sceneObjectFromGameMap == (Object)null))
		{
			GameObject val = Object.Instantiate<GameObject>(benchPinTemplate);
			((Object)val).name = "ModdedPin_" + benchData.ID;
			SpriteRenderer component = val.GetComponent<SpriteRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.sprite = ((type == BenchType.Normal) ? normalBenchSprite : tempBenchSprite);
			}
			Vector3 val2 = default(Vector3);
			if (benchData.PinPositionX == 0f && benchData.PinPositionY == 0f)
			{
				Vector2 benchWorldPosition = default(Vector2);
				((Vector2)(ref benchWorldPosition))..ctor(benchData.PositionX, benchData.PositionY);
				val2 = CalculateInitialPinPosition(benchWorldPosition, sceneObjectFromGameMap);
				benchData.PinPositionX = val2.x;
				benchData.PinPositionY = val2.y;
			}
			else
			{
				((Vector3)(ref val2))..ctor(benchData.PinPositionX, benchData.PinPositionY, benchPinTemplate.transform.localPosition.z);
			}
			val.transform.SetParent(sceneObjectFromGameMap.transform, false);
			val.transform.localPosition = val2;
			val.SetActive(true);
			_activePins[benchData.ID] = val;
		}
	}

	private Vector3 CalculateInitialPinPosition(Vector2 benchWorldPosition, GameObject sceneObj)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		GameMapScene scene = (GameMapScene)GetInstanceField(gameMap, "currentScene");
		Vector2 scenePos = (Vector2)GetInstanceField(gameMap, "currentScenePos");
		Vector2 sceneSize = (Vector2)GetInstanceField(gameMap, "currentSceneSize");
		Vector2 mapPositionFromData = GetMapPositionFromData(benchWorldPosition, scene, scenePos, sceneSize);
		Vector3 val = ((Component)gameMap).transform.TransformPoint(Vector2.op_Implicit(mapPositionFromData));
		Vector3 result = sceneObj.transform.InverseTransformPoint(val);
		result.z = benchPinTemplate.transform.localPosition.z;
		return result;
	}

	private Vector2 GetMapPositionFromData(Vector2 positionInScene, GameMapScene scene, Vector2 scenePos, Vector2 sceneSize)
	{
		//IL_00a8: 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_0025: 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)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: 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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)scene) && Object.op_Implicit((Object)(object)scene.BoundsSprite))
		{
			Bounds bounds = scene.BoundsSprite.bounds;
			Vector2 val = Vector2.op_Implicit(Vector3.Scale(((Bounds)(ref bounds)).size, ((Component)scene).transform.localScale));
			float num = scenePos.x - val.x / 2f + positionInScene.x / sceneSize.x * val.x;
			float num2 = scenePos.y - val.y / 2f + positionInScene.y / sceneSize.y * val.y;
			return new Vector2(num, num2);
		}
		return scenePos;
	}

	private GameObject GetSceneObjectFromGameMap(string sceneName)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		MapZone val = (MapZone)InvokePrivateMethod(gameMap, "GetMapZoneFromSceneName", new object[1] { sceneName });
		object[] array = new object[5] { sceneName, val, null, null, null };
		InvokePrivateMethod(gameMap, "GetSceneInfo", array);
		return (GameObject)array[3];
	}

	private object InvokePrivateMethod(object instance, string methodName, object[] parameters)
	{
		MethodInfo method = instance.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
		if (method == null)
		{
			return null;
		}
		return method.Invoke(instance, parameters);
	}

	private Sprite LoadSpriteFromFile(string filePath)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		if (!File.Exists(filePath))
		{
			return null;
		}
		byte[] array = File.ReadAllBytes(filePath);
		Texture2D val = new Texture2D(2, 2);
		if (ImageConversion.LoadImage(val, array))
		{
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			((Object)val2).name = Path.GetFileNameWithoutExtension(filePath);
			return val2;
		}
		return null;
	}

	private object GetInstanceField(object i, string f)
	{
		return i.GetType().GetField(f, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(i);
	}

	private GameObject FindInactiveGameObjectByName(string name)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Invalid comparison between Unknown and I4
		GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
		foreach (GameObject val in array)
		{
			if (((Object)val).name == name && (int)((Object)val).hideFlags == 0)
			{
				return val;
			}
		}
		return null;
	}
}
public class BenchManagerUI : MonoBehaviour
{
	private BuildYourOwnBench _mainMod;

	private Rect _windowRect = new Rect(20f, 20f, 700f, 450f);

	private Vector2 _scrollPosition = Vector2.zero;

	private static readonly object _uiInputBlocker = new object();

	private bool _isResizing = false;

	private Rect _resizeHandleRect;

	private const float MinWindowWidth = 700f;

	private const float BaseWindowWidth = 700f;

	private const float BaseWindowHeight = 450f;

	private const float WindowAspectRatio = 1.5555556f;

	private float _currentScale = 1f;

	private string _editingBenchId = null;

	private string _editingNameTemp = "";

	private Rect _activeEditRect = Rect.zero;

	private BenchData _promptBenchData = null;

	private Rect _promptRect = new Rect(0f, 0f, 350f, 120f);

	internal static bool IsVisible { get; private set; }

	internal static bool IsPromptVisible { get; private set; }

	public void Initialize(BuildYourOwnBench mainModInstance)
	{
		_mainMod = mainModInstance;
	}

	private void OnGUI()
	{
		//IL_0064: 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_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Expected O, but got Unknown
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: 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)
		if ((IsVisible || IsPromptVisible) && !((Object)(object)_mainMod == (Object)null))
		{
			GUI.skin = BuildYourOwnBench.GetModSkin();
			if (IsPromptVisible)
			{
				((Rect)(ref _promptRect)).center = new Vector2((float)Screen.width / 2f, (float)Screen.height / 2f);
				_promptRect = GUILayout.Window(5678, _promptRect, new WindowFunction(DrawPromptWindow), "Name Your New Bench", Array.Empty<GUILayoutOption>());
			}
			else if (IsVisible)
			{
				Matrix4x4 matrix = GUI.matrix;
				_currentScale = ((Rect)(ref _windowRect)).width / 700f;
				GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(_currentScale, _currentScale, 1f));
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((Rect)(ref _windowRect)).x / _currentScale, ((Rect)(ref _windowRect)).y / _currentScale, 700f, 450f);
				val = GUILayout.Window(1234, val, new WindowFunction(DrawWindowContents), "Modded Bench Manager", Array.Empty<GUILayoutOption>());
				((Rect)(ref _windowRect)).x = ((Rect)(ref val)).x * _currentScale;
				((Rect)(ref _windowRect)).y = ((Rect)(ref val)).y * _currentScale;
				GUI.matrix = matrix;
			}
		}
	}

	private void DrawWindowContents(int windowID)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Invalid comparison between Unknown and I4
		//IL_0581: Unknown result type (might be due to invalid IL or missing references)
		//IL_0586: Unknown result type (might be due to invalid IL or missing references)
		//IL_058c: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Invalid comparison between Unknown and I4
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_040d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Invalid comparison between Unknown and I4
		//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		if (GUI.Button(new Rect(675f, 5f, 20f, 20f), "X"))
		{
			Hide();
		}
		GUILayout.Space(5f);
		GUILayout.BeginVertical(GUIStyle.op_Implicit("HeaderBox"), Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label($"Total Modded Benches: {_mainMod.GetBenchList().Count}", GUIStyle.op_Implicit("HeaderLabel"), Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		string currentSceneName = _mainMod.GetCurrentSceneName();
		string areaNameForScene = BuildYourOwnBench.GetAreaNameForScene(currentSceneName);
		GUILayout.Label("Current Scene (Area): " + currentSceneName + " (" + areaNameForScene + ")", GUIStyle.op_Implicit("HeaderLabel"), Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUILayout.Space(5f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("<b>Bench Name</b>", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(250f) });
		GUILayout.Label("<b>Scene (Area)</b>", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
		GUILayout.Label("<b>State</b>", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
		GUILayout.Label("<b>Operations</b>", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
		GUILayout.EndHorizontal();
		_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, Array.Empty<GUILayoutOption>());
		if (_editingBenchId != null)
		{
			if (Event.current.isKey && ((int)Event.current.keyCode == 13 || (int)Event.current.keyCode == 271))
			{
				CommitInlineEdit();
				Event.current.Use();
			}
			else if ((int)Event.current.type == 0 && ((Rect)(ref _activeEditRect)).width > 0f && !((Rect)(ref _activeEditRect)).Contains(Event.current.mousePosition))
			{
				CommitInlineEdit();
			}
		}
		string currentRespawnId = _mainMod.GetCurrentRespawnId();
		List<BenchData> benchList = _mainMod.GetBenchList();
		if (benchList.Any())
		{
			foreach (BenchData item in benchList)
			{
				GUILayout.BeginHorizontal(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
				bool flag = !string.IsNullOrEmpty(currentRespawnId) && item.ID == currentRespawnId;
				Color contentColor = GUI.contentColor;
				if (flag)
				{
					GUI.contentColor = Color.cyan;
				}
				string text = (string.IsNullOrEmpty(item.CustomName) ? item.ID : item.CustomName);
				if (_editingBenchId == item.ID)
				{
					GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(250f) });
					_editingNameTemp = GUILayout.TextField(_editingNameTemp, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					GUI.contentColor = contentColor;
					if (GUILayout.Button("Save", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
					{
						_mainMod.RenameBench(item.ID, _editingNameTemp);
						_editingBenchId = null;
					}
					GUILayout.EndHorizontal();
					if ((int)Event.current.type == 7)
					{
						_activeEditRect = GUILayoutUtility.GetLastRect();
					}
				}
				else
				{
					if (GUILayout.Button(text, GUI.skin.label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(250f) }))
					{
						CommitInlineEdit();
						_editingBenchId = item.ID;
						_editingNameTemp = text;
					}
					GUI.contentColor = contentColor;
				}
				string areaNameForScene2 = BuildYourOwnBench.GetAreaNameForScene(item.SceneName);
				GUILayout.Label(item.SceneName + " (" + areaNameForScene2 + ")", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
				bool flag2 = item.ID.StartsWith("TEMP_DESTROYED_");
				string text2 = ((!flag2) ? "Normal" : "<color=red>Destroyed</color>");
				GUILayout.Label(text2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
				GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
				GUI.enabled = !flag2;
				if (GUILayout.Button("Delete", Array.Empty<GUILayoutOption>()))
				{
					_mainMod.RequestDeleteBench(item.ID);
				}
				GUI.enabled = true;
				if (_mainMod.IsTeleportEnabled() && GUILayout.Button("Teleport", Array.Empty<GUILayoutOption>()))
				{
					_mainMod.RequestTeleportToBench(item);
				}
				GUI.enabled = true;
				GUILayout.EndHorizontal();
				GUILayout.EndHorizontal();
			}
		}
		else
		{
			GUILayout.Label("No modded benches have been created yet.", Array.Empty<GUILayoutOption>());
		}
		GUILayout.EndScrollView();
		_resizeHandleRect = new Rect(684f, 434f, 16f, 16f);
		GUI.Box(_resizeHandleRect, "///");
		HandleResizeEvents();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 30f));
	}

	private void HandleResizeEvents()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Invalid comparison between Unknown and I4
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Invalid comparison between Unknown and I4
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		Event current = Event.current;
		if ((int)current.type == 0 && ((Rect)(ref _resizeHandleRect)).Contains(current.mousePosition))
		{
			_isResizing = true;
			current.Use();
		}
		else if ((int)current.type == 1)
		{
			_isResizing = false;
		}
		else if ((int)current.type == 3 && _isResizing)
		{
			float num = (current.delta.x + current.delta.y) / _currentScale;
			ref Rect windowRect = ref _windowRect;
			((Rect)(ref windowRect)).width = ((Rect)(ref windowRect)).width + num;
			float num2 = (float)Screen.height * 1.5555556f;
			((Rect)(ref _windowRect)).width = Mathf.Clamp(((Rect)(ref _windowRect)).width, 700f, num2);
			((Rect)(ref _windowRect)).height = ((Rect)(ref _windowRect)).width / 1.5555556f;
			current.Use();
		}
	}

	public void Toggle()
	{
		if (IsVisible)
		{
			Hide();
		}
		else
		{
			Show();
		}
	}

	public void Show()
	{
		IsVisible = true;
		HeroController.instance.AddInputBlocker(_uiInputBlocker);
	}

	public void Hide()
	{
		CommitInlineEdit();
		IsVisible = false;
		HeroController.instance.RemoveInputBlocker(_uiInputBlocker);
	}

	public void ShowCreationPrompt(BenchData benchData)
	{
		IsPromptVisible = true;
		_promptBenchData = benchData;
		_editingNameTemp = (string.IsNullOrEmpty(benchData.CustomName) ? "New Bench" : benchData.CustomName);
		HeroController.instance.AddInputBlocker(_uiInputBlocker);
	}

	public void HidePrompt()
	{
		IsPromptVisible = false;
		_promptBenchData = null;
		HeroController.instance.RemoveInputBlocker(_uiInputBlocker);
	}

	private void DrawPromptWindow(int windowID)
	{
		GUILayout.Space(10f);
		GUILayout.Label("Enter a custom name for this bench:", GUIStyle.op_Implicit("HeaderLabel"), Array.Empty<GUILayoutOption>());
		GUI.SetNextControlName("BenchNameField");
		_editingNameTemp = GUILayout.TextField(_editingNameTemp, 25, Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		if (GUILayout.Button("Save", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
		{
			_mainMod.RenameBench(_promptBenchData.ID, _editingNameTemp);
			HidePrompt();
		}
		GUILayout.EndHorizontal();
		GUI.FocusControl("BenchNameField");
	}

	private void CommitInlineEdit()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		if (_editingBenchId != null)
		{
			if (!string.IsNullOrWhiteSpace(_editingNameTemp))
			{
				_mainMod.RenameBench(_editingBenchId, _editingNameTemp.Trim());
			}
			_editingBenchId = null;
			_activeEditRect = Rect.zero;
			GUIUtility.keyboardControl = 0;
		}
	}
}