Decompiled source of RepoPlus v1.0.0

RepoPlus.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using MenuLib;
using MenuLib.MonoBehaviors;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NanoLux")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5516e9a2a8eaad4be573de4c3584ab55e131ee52")]
[assembly: AssemblyProduct("RepoPlus")]
[assembly: AssemblyTitle("RepoPlus")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RepoPlus;

internal sealed class LocalMap
{
	private static readonly FieldInfo Entity = Field(typeof(MapCustom), "mapCustomEntity");

	private static readonly FieldInfo Disabled = Field(typeof(PlayerAvatar), "isDisabled");

	private static readonly FieldInfo Spawned = Field(typeof(EnemyParent), "Spawned");

	private static readonly FieldInfo Enemy = Field(typeof(EnemyParent), "Enemy");

	private static readonly FieldInfo Body = Field(typeof(Enemy), "Rigidbody");

	private static readonly FieldInfo Difficulty = Field(typeof(EnemyParent), "difficulty");

	private static readonly FieldInfo Discovered = Field(typeof(ValuableObject), "discovered");

	private static readonly FieldInfo Generated = Field(typeof(LevelGenerator), "Generated");

	private static readonly FieldInfo LevelInstance = typeof(LevelGenerator).GetField("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

	private readonly Dictionary<Component, MapCustom> markers = new Dictionary<Component, MapCustom>();

	private readonly HashSet<Component> seen = new HashSet<Component>();

	private readonly List<Component> stale = new List<Component>();

	private readonly Dictionary<ValuableObject, MapValuable> valuableMarkers = new Dictionary<ValuableObject, MapValuable>();

	private readonly List<ValuableObject> staleValuables = new List<ValuableObject>();

	private readonly Sprite[] icons = (Sprite[])(object)new Sprite[3];

	private Map current;

	private bool explored;

	private float next;

	private static FieldInfo Field(Type type, string name)
	{
		return type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
	}

	public void Tick(bool enabled, bool players, bool enemies, bool explore, bool valuables, bool difficultyShapes)
	{
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		Map instance = Map.Instance;
		if ((Object)(object)current != (Object)(object)instance || !Object.op_Implicit((Object)(object)instance) || !SemiFunc.RunIsLevel())
		{
			Clear();
			current = instance;
			explored = false;
			next = 0f;
		}
		if (!enabled || !Object.op_Implicit((Object)(object)instance) || !SemiFunc.RunIsLevel())
		{
			Clear();
			return;
		}
		if (!valuables)
		{
			ClearValuables();
		}
		if (Time.unscaledTime < next)
		{
			return;
		}
		next = Time.unscaledTime + 0.25f;
		object? obj = LevelInstance?.GetValue(null);
		Component val = (Component)((obj is Component) ? obj : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		object obj2 = Generated?.GetValue(val);
		bool flag = default(bool);
		int num;
		if (obj2 is bool)
		{
			flag = (bool)obj2;
			num = 1;
		}
		else
		{
			num = 0;
		}
		if (((uint)num & (flag ? 1u : 0u)) == 0)
		{
			return;
		}
		if (explore && !explored)
		{
			RoomVolume[] array = Object.FindObjectsByType<RoomVolume>((FindObjectsSortMode)0);
			RoomVolume[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i].SetExplored();
			}
			explored = array.Length != 0;
		}
		seen.Clear();
		PlayerController instance2 = PlayerController.instance;
		PlayerAvatar val2 = (Object.op_Implicit((Object)(object)instance2) ? instance2.playerAvatarScript : null);
		if (players)
		{
			PlayerAvatar[] array3 = Object.FindObjectsByType<PlayerAvatar>((FindObjectsSortMode)0);
			bool flag2 = default(bool);
			foreach (PlayerAvatar val3 in array3)
			{
				if ((Object)(object)val3 != (Object)(object)val2)
				{
					obj2 = Disabled?.GetValue(val3);
					int num2;
					if (obj2 is bool)
					{
						flag2 = (bool)obj2;
						num2 = 1;
					}
					else
					{
						num2 = 0;
					}
					if (((uint)num2 & (flag2 ? 1u : 0u)) == 0)
					{
						Track((Component)(object)val3, (Component)(object)val3, 0, Color.blue);
					}
				}
			}
		}
		if (enemies)
		{
			Object[] array4 = Object.FindObjectsByType(typeof(EnemyParent), (FindObjectsSortMode)0);
			bool flag3 = default(bool);
			foreach (Object obj3 in array4)
			{
				Component val4 = (Component)(object)((obj3 is Component) ? obj3 : null);
				int num3;
				if (val4 != null)
				{
					obj2 = Spawned?.GetValue(val4);
					if (obj2 is bool)
					{
						flag3 = (bool)obj2;
						num3 = 1;
					}
					else
					{
						num3 = 0;
					}
				}
				else
				{
					num3 = 0;
				}
				if (((uint)num3 & (flag3 ? 1u : 0u)) == 0)
				{
					continue;
				}
				object? obj4 = Enemy?.GetValue(val4);
				Component val5 = (Component)((obj4 is Component) ? obj4 : null);
				if (val5 != null && Object.op_Implicit((Object)(object)val5) && val5.gameObject.activeInHierarchy)
				{
					object? obj5 = Body?.GetValue(val5);
					Component val6 = (Component)((obj5 is Component) ? obj5 : null);
					int num4 = ((!difficultyShapes) ? 1 : Convert.ToInt32(Difficulty?.GetValue(val4)));
					if (num4 < 0 || num4 > 2)
					{
						num4 = 0;
					}
					Track(val4, (Object.op_Implicit((Object)(object)val6) && val6.gameObject.activeInHierarchy) ? val6 : val5, num4, Color.red);
				}
			}
		}
		stale.Clear();
		foreach (KeyValuePair<Component, MapCustom> marker in markers)
		{
			if (!seen.Contains(marker.Key))
			{
				stale.Add(marker.Key);
			}
		}
		foreach (Component item in stale)
		{
			Remove(markers[item]);
			markers.Remove(item);
		}
		if (valuables)
		{
			SyncValuables(instance);
		}
	}

	private void SyncValuables(Map map)
	{
		if (Discovered == null || !Object.op_Implicit((Object)(object)map.OverLayerParent) || !Object.op_Implicit((Object)(object)map.ValuableObject))
		{
			return;
		}
		staleValuables.Clear();
		foreach (KeyValuePair<ValuableObject, MapValuable> valuableMarker in valuableMarkers)
		{
			if (!Object.op_Implicit((Object)(object)valuableMarker.Key) || !Object.op_Implicit((Object)(object)valuableMarker.Value) || !((Component)valuableMarker.Key).gameObject.activeInHierarchy || (bool)Discovered.GetValue(valuableMarker.Key))
			{
				if (Object.op_Implicit((Object)(object)valuableMarker.Value))
				{
					RemoveValuable(valuableMarker.Value);
				}
				staleValuables.Add(valuableMarker.Key);
			}
		}
		foreach (ValuableObject staleValuable in staleValuables)
		{
			valuableMarkers.Remove(staleValuable);
		}
		Transform overLayerParent = map.OverLayerParent;
		ValuableObject[] array = Object.FindObjectsByType<ValuableObject>((FindObjectsSortMode)0);
		MapValuable val2 = default(MapValuable);
		foreach (ValuableObject val in array)
		{
			if (!(bool)Discovered.GetValue(val) && !valuableMarkers.ContainsKey(val))
			{
				int childCount = overLayerParent.childCount;
				map.AddValuable(val);
				if (overLayerParent.childCount > childCount && ((Component)overLayerParent.GetChild(childCount)).TryGetComponent<MapValuable>(ref val2) && (Object)(object)val2.target == (Object)(object)val)
				{
					valuableMarkers.Add(val, val2);
				}
			}
		}
	}

	private static void RemoveValuable(MapValuable marker)
	{
		((Component)marker).gameObject.SetActive(false);
		Object.Destroy((Object)(object)((Component)marker).gameObject);
	}

	private void ClearValuables()
	{
		foreach (MapValuable value in valuableMarkers.Values)
		{
			if (Object.op_Implicit((Object)(object)value))
			{
				RemoveValuable(value);
			}
		}
		valuableMarkers.Clear();
	}

	private void Track(Component key, Component target, int icon, Color color)
	{
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		if (Entity == null)
		{
			return;
		}
		Sprite val = (Object.op_Implicit((Object)(object)icons[icon]) ? icons[icon] : (icons[icon] = BuildIcon(icon)));
		seen.Add(key);
		if (markers.TryGetValue(key, out var value))
		{
			if (Object.op_Implicit((Object)(object)value) && (Object)(object)((Component)value).gameObject == (Object)(object)target.gameObject && (Object)(object)value.sprite == (Object)(object)val)
			{
				object? value2 = Entity.GetValue(value);
				Component val2 = (Component)((value2 is Component) ? value2 : null);
				if (val2 != null && Object.op_Implicit((Object)(object)val2))
				{
					return;
				}
			}
			Remove(value);
		}
		MapCustom val3 = target.gameObject.AddComponent<MapCustom>();
		val3.autoAdd = false;
		val3.sprite = val;
		val3.color = color;
		val3.Add();
		markers[key] = val3;
	}

	private static Sprite BuildIcon(int kind)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		int num = ((kind == 0) ? 5 : 10);
		Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				int num2 = j - 5;
				int num3 = i - 5;
				val.SetPixel(j, i, (kind switch
				{
					1 => num2 * num2 + num3 * num3 <= 16, 
					0 => true, 
					_ => i >= 1 && j * 8 >= 8 + (i - 1) * 4 && j * 8 <= 64 - (i - 1) * 3, 
				}) ? Color.white : Color.clear);
			}
		}
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f));
	}

	private static void Remove(MapCustom marker)
	{
		if (Object.op_Implicit((Object)(object)marker))
		{
			object? obj = Entity?.GetValue(marker);
			Component val = (Component)((obj is Component) ? obj : null);
			if (val != null && Object.op_Implicit((Object)(object)val))
			{
				val.gameObject.SetActive(false);
				Object.Destroy((Object)(object)val.gameObject);
			}
			Object.Destroy((Object)(object)marker);
		}
	}

	public void Clear()
	{
		foreach (MapCustom value in markers.Values)
		{
			Remove(value);
		}
		markers.Clear();
		ClearValuables();
	}

	public void Dispose()
	{
		Clear();
		Sprite[] array = icons;
		foreach (Sprite val in array)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)val.texture);
				Object.Destroy((Object)(object)val);
			}
		}
	}
}
internal sealed class NativeMenu
{
	private readonly ConfigEntry<bool> stamina;

	private readonly ConfigEntry<bool> regen;

	private readonly ConfigEntry<bool> map;

	private readonly ConfigEntry<bool> players;

	private readonly ConfigEntry<bool> enemies;

	private readonly ConfigEntry<bool> explore;

	private readonly ConfigEntry<bool> valuables;

	private readonly ConfigEntry<bool> difficultyShapes;

	private readonly ConfigEntry<int> hp;

	private readonly ConfigEntry<int> interval;

	private readonly ConfigEntry<KeyboardShortcut> shortcut;

	private static readonly KeyCode[] Keys = (KeyCode[])Enum.GetValues(typeof(KeyCode));

	private REPOPopupPage page;

	private bool rebinding;

	private int rebindFrame;

	private REPOButton shortcutButton;

	public NativeMenu(ConfigEntry<bool> stamina, ConfigEntry<bool> regen, ConfigEntry<int> hp, ConfigEntry<int> interval, ConfigEntry<KeyboardShortcut> shortcut, ConfigEntry<bool> map, ConfigEntry<bool> players, ConfigEntry<bool> enemies, ConfigEntry<bool> explore, ConfigEntry<bool> valuables, ConfigEntry<bool> difficultyShapes)
	{
		this.stamina = stamina;
		this.regen = regen;
		this.hp = hp;
		this.interval = interval;
		this.shortcut = shortcut;
		this.map = map;
		this.players = players;
		this.enemies = enemies;
		this.explore = explore;
		this.valuables = valuables;
		this.difficultyShapes = difficultyShapes;
	}

	public void Update()
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: 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_0058: Invalid comparison between Unknown and I4
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)page))
		{
			rebinding = false;
		}
		if (rebinding)
		{
			if (Time.frameCount <= rebindFrame || !Input.anyKeyDown)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)27))
			{
				FinishRebind();
				return;
			}
			KeyCode[] keys = Keys;
			foreach (KeyCode val in keys)
			{
				if ((int)val != 0 && (int)val < 323 && Input.GetKeyDown(val))
				{
					shortcut.Value = new KeyboardShortcut(val, Array.Empty<KeyCode>());
					FinishRebind();
					break;
				}
			}
			return;
		}
		KeyboardShortcut value = shortcut.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			if (Object.op_Implicit((Object)(object)page))
			{
				Close();
			}
			else if (Object.op_Implicit((Object)(object)MenuManager.instance) && Object.op_Implicit((Object)(object)MenuHolder.instance))
			{
				Open();
			}
		}
	}

	private void Open()
	{
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Expected O, but got Unknown
		page = MenuAPI.CreateREPOPopupPage("REPO PLUS", (PresetSide)0, false, true, 5f);
		Label("GAMEPLAY");
		Toggle("Infinite Stamina", stamina);
		Label("HEALTH REGEN");
		Toggle("Health Regen", regen);
		Number("HP per ciclo", "Punti vita recuperati", hp, 100);
		Number("Intervallo", "Secondi senza subire danni", interval, 300);
		Label("BETTER MAP");
		Toggle("Better Map", map);
		Toggle("Player Markers", players);
		Toggle("Enemy Markers", enemies);
		Toggle("Enemy Difficulty Shapes", difficultyShapes);
		Toggle("Show All Valuables", valuables);
		Toggle("Explore All Rooms", explore);
		Label("COSMETICS");
		Button("Unlock All Cosmetics", ConfirmCosmetics);
		page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent)
		{
			//IL_000c: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			shortcutButton = MenuAPI.CreateREPOButton($"Cambia tasto: {shortcut.Value}", (Action)delegate
			{
				if (rebinding)
				{
					FinishRebind();
				}
				else
				{
					rebinding = true;
					rebindFrame = Time.frameCount;
					SetShortcutLabel("Premi un tasto · Esc annulla");
				}
			}, parent, default(Vector2));
			return ((REPOElement)shortcutButton).rectTransform;
		}, 0f, 0f);
		Button("Chiudi", Close);
		Label("<size=75%>By NanoLux</size>");
		page.OpenPage(false);
	}

	private void FinishRebind()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		rebinding = false;
		SetShortcutLabel($"Cambia tasto: {shortcut.Value}");
	}

	private void SetShortcutLabel(string text)
	{
		if (Object.op_Implicit((Object)(object)shortcutButton))
		{
			object obj = typeof(REPOButton).GetField("labelTMP")?.GetValue(shortcutButton);
			obj?.GetType().GetProperty("text")?.SetValue(obj, text);
		}
	}

	private void ConfirmCosmetics()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)MetaManager.instance))
		{
			return;
		}
		Close();
		MenuAPI.OpenPopup("Unlock All Cosmetics", Color.white, "Sbloccare tutti i cosmetici nel salvataggio locale?", (Action)delegate
		{
			if (Object.op_Implicit((Object)(object)MetaManager.instance))
			{
				MetaManager.instance.CosmeticUnlockAll();
			}
		}, (Action)null);
	}

	private void Close()
	{
		rebinding = false;
		if (Object.op_Implicit((Object)(object)page))
		{
			page.ClosePage(false);
		}
	}

	private void Label(string text)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		page.AddElementToScrollView((ScrollViewBuilderDelegate)((Transform parent) => ((REPOElement)MenuAPI.CreateREPOLabel(text, parent, default(Vector2))).rectTransform), 0f, 0f);
	}

	private void Button(string text, Action onClick)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		page.AddElementToScrollView((ScrollViewBuilderDelegate)((Transform parent) => ((REPOElement)MenuAPI.CreateREPOButton(text, onClick, parent, default(Vector2))).rectTransform), 0f, 0f);
	}

	private void Toggle(string text, ConfigEntry<bool> entry)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent)
		{
			//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)
			string text2 = text;
			Action<bool> obj = delegate(bool value2)
			{
				entry.Value = value2;
			};
			bool value = entry.Value;
			return ((REPOElement)MenuAPI.CreateREPOToggle(text2, obj, parent, default(Vector2), "ON", "OFF", value)).rectTransform;
		}, 0f, 0f);
	}

	private void Number(string text, string description, ConfigEntry<int> entry, int max)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent)
		{
			//IL_0041: 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)
			string text2 = text;
			string text3 = description;
			Action<int> obj = delegate(int value2)
			{
				entry.Value = value2;
			};
			int num = max;
			int value = entry.Value;
			return ((REPOElement)MenuAPI.CreateREPOSlider(text2, text3, obj, parent, default(Vector2), 1, num, value, "", "", (BarBehavior)0)).rectTransform;
		}, 0f, 0f);
	}
}
[BepInPlugin("nanolux.repoplus", "RepoPlus", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class RepoPlusPlugin : BaseUnityPlugin
{
	private ConfigEntry<KeyboardShortcut> menuKey;

	private ConfigEntry<bool> stamina;

	private ConfigEntry<bool> map;

	private ConfigEntry<bool> players;

	private ConfigEntry<bool> enemies;

	private ConfigEntry<bool> explore;

	private ConfigEntry<bool> regen;

	private ConfigEntry<bool> valuables;

	private ConfigEntry<bool> difficultyShapes;

	private ConfigEntry<int> hp;

	private ConfigEntry<int> interval;

	private bool open;

	private bool rebinding;

	private bool previousCursorVisible;

	private CursorLockMode previousCursorLock;

	private Vector2 scroll;

	private Coroutine regenLoop;

	private bool confirmCosmetics;

	private string cosmeticsStatus;

	private GUIStyle heading;

	private GUIStyle section;

	private NativeMenu nativeMenu;

	private readonly LocalMap localMap = new LocalMap();

	private static readonly FieldInfo Health = typeof(PlayerHealth).GetField("health", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo MaxHealth = typeof(PlayerHealth).GetField("maxHealth", BindingFlags.Instance | BindingFlags.NonPublic);

	private void Awake()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Expected O, but got Unknown
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Expected O, but got Unknown
		menuKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Menu", "Shortcut", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Tasto del menu.");
		stamina = Toggle("Gameplay", "InfiniteStamina");
		map = Toggle("BetterMap", "Enabled");
		players = Toggle("BetterMap", "PlayerMarkers");
		enemies = Toggle("BetterMap", "EnemyMarkers");
		explore = Toggle("BetterMap", "ExploreAllRooms");
		valuables = Toggle("BetterMap", "ShowValuables");
		difficultyShapes = Toggle("BetterMap", "EnemyDifficultyShapes");
		regen = Toggle("HealthRegen", "Enabled");
		hp = ((BaseUnityPlugin)this).Config.Bind<int>("HealthRegen", "HpPerCycle", 1, new ConfigDescription("HP per ciclo.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
		interval = ((BaseUnityPlugin)this).Config.Bind<int>("HealthRegen", "IntervalSeconds", 5, new ConfigDescription("Intervallo in secondi.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 300), Array.Empty<object>()));
		regen.SettingChanged += delegate
		{
			UpdateRegen();
		};
		interval.SettingChanged += delegate
		{
			UpdateRegen();
		};
		if (Chainloader.PluginInfos.ContainsKey("nickklmao.menulib"))
		{
			CreateNativeMenu();
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	private void CreateNativeMenu()
	{
		nativeMenu = new NativeMenu(stamina, regen, hp, interval, menuKey, map, players, enemies, explore, valuables, difficultyShapes);
	}

	private ConfigEntry<bool> Toggle(string section, string key)
	{
		return ((BaseUnityPlugin)this).Config.Bind<bool>(section, key, false, (ConfigDescription)null);
	}

	private void OnEnable()
	{
		UpdateRegen();
	}

	private void UpdateRegen()
	{
		if (regenLoop != null)
		{
			((MonoBehaviour)this).StopCoroutine(regenLoop);
			regenLoop = null;
		}
		if (((Behaviour)this).isActiveAndEnabled)
		{
			ConfigEntry<bool> obj = regen;
			if (obj != null && obj.Value && Health != null && MaxHealth != null)
			{
				regenLoop = ((MonoBehaviour)this).StartCoroutine(Regenerate());
			}
		}
	}

	private IEnumerator Regenerate()
	{
		PlayerHealth previous = null;
		int previousHp = 0;
		float next = 0f;
		WaitForSeconds poll = new WaitForSeconds(0.2f);
		while (true)
		{
			PlayerController instance = PlayerController.instance;
			PlayerAvatar val = (Object.op_Implicit((Object)(object)instance) ? instance.playerAvatarScript : null);
			PlayerHealth val2 = ((Object.op_Implicit((Object)(object)val) && !SemiFunc.RunIsLobbyMenu()) ? val.playerHealth : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				int num = (int)Health.GetValue(val2);
				int num2 = (int)MaxHealth.GetValue(val2);
				if ((Object)(object)val2 != (Object)(object)previous || num < previousHp || num >= num2)
				{
					next = Time.time + (float)interval.Value;
				}
				if (num > 0 && num < num2 && Time.time >= next)
				{
					val2.Heal(Mathf.Min(hp.Value, num2 - num), false);
					num = (int)Health.GetValue(val2);
					next = Time.time + (float)interval.Value;
				}
				previousHp = num;
			}
			previous = val2;
			yield return poll;
		}
	}

	private void FixedUpdate()
	{
		if (stamina.Value)
		{
			PlayerController instance = PlayerController.instance;
			if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.playerAvatar))
			{
				instance.EnergyCurrent = instance.EnergyStart;
			}
		}
	}

	private void Update()
	{
		//IL_0081: 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)
		localMap.Tick(map.Value, players.Value, enemies.Value, explore.Value, valuables.Value, difficultyShapes.Value);
		if (nativeMenu != null)
		{
			nativeMenu.Update();
		}
		else
		{
			if (rebinding)
			{
				return;
			}
			if (!open || !Input.GetKeyDown((KeyCode)27))
			{
				KeyboardShortcut value = menuKey.Value;
				if (!((KeyboardShortcut)(ref value)).IsDown())
				{
					return;
				}
			}
			SetOpen(!open);
		}
	}

	private void OnDisable()
	{
		localMap.Clear();
		UpdateRegen();
		SetOpen(value: false);
	}

	private void OnDestroy()
	{
		localMap.Dispose();
	}

	private void SetOpen(bool value)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		if (value != open)
		{
			open = value;
			rebinding = false;
			confirmCosmetics = false;
			if (open)
			{
				previousCursorVisible = Cursor.visible;
				previousCursorLock = Cursor.lockState;
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			else
			{
				Cursor.lockState = previousCursorLock;
				Cursor.visible = previousCursorVisible;
			}
		}
	}

	private void OnGUI()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: 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: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: 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_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Invalid comparison between Unknown and I4
		//IL_021e: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		if (!open)
		{
			return;
		}
		Event current = Event.current;
		if (rebinding && (int)current.type == 4 && (int)current.keyCode != 0)
		{
			if ((int)current.keyCode != 27)
			{
				menuKey.Value = new KeyboardShortcut(current.keyCode, Array.Empty<KeyCode>());
			}
			rebinding = false;
			current.Use();
		}
		if (heading == null)
		{
			heading = new GUIStyle(GUI.skin.label)
			{
				fontSize = 28
			};
		}
		if (section == null)
		{
			section = new GUIStyle(GUI.skin.label)
			{
				fontSize = 15
			};
		}
		heading.normal.textColor = new Color(1f, 0.82f, 0.46f);
		section.normal.textColor = new Color(1f, 0.82f, 0.46f);
		float num = Mathf.Min(520, Screen.width - 24);
		float num2 = Mathf.Min(640, Screen.height - 24);
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2);
		Color color = GUI.color;
		GUI.color = new Color(0.1f, 0.085f, 0.075f);
		GUI.DrawTexture(val, (Texture)(object)Texture2D.whiteTexture);
		GUI.color = new Color(1f, 0.65f, 0.22f);
		GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, 3f), (Texture)(object)Texture2D.whiteTexture);
		GUI.color = color;
		GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 16f, ((Rect)(ref val)).y + 12f, ((Rect)(ref val)).width - 32f, ((Rect)(ref val)).height - 24f));
		GUILayout.Label("REPO PLUS", heading, Array.Empty<GUILayoutOption>());
		GUILayout.Label("NANOLUX  /  BUILD DI PROVA", Array.Empty<GUILayoutOption>());
		if (GUILayout.Button(rebinding ? "Premi un tasto (Esc annulla)" : $"Cambia tasto: {menuKey.Value}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }))
		{
			rebinding = !rebinding;
		}
		scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
		GUILayout.Label("GAMEPLAY", section, Array.Empty<GUILayoutOption>());
		DrawToggle("Infinite Stamina", stamina);
		GUILayout.Label("BETTER MAP", section, Array.Empty<GUILayoutOption>());
		bool enabled = GUI.enabled;
		DrawToggle("BetterMap", map);
		GUI.enabled = enabled && map.Value;
		DrawToggle("Player Markers", players);
		DrawToggle("Enemy Markers", enemies);
		DrawToggle("Enemy Difficulty Shapes", difficultyShapes);
		DrawToggle("Show All Valuables", valuables);
		DrawToggle("Explore All Rooms", explore);
		GUI.enabled = enabled;
		GUILayout.Label("HEALTH REGEN", section, Array.Empty<GUILayoutOption>());
		DrawToggle("Health Regen", regen);
		DrawNumber("HP per ciclo", hp, 100);
		DrawNumber("Intervallo (secondi)", interval, 300);
		GUILayout.Label("COSMETICS", section, Array.Empty<GUILayoutOption>());
		GUI.enabled = enabled && (Object)(object)MetaManager.instance != (Object)null;
		if (GUILayout.Button(confirmCosmetics ? "Conferma sblocco permanente" : "Unlock All Cosmetics", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }))
		{
			if (confirmCosmetics)
			{
				cosmeticsStatus = (MetaManager.instance.CosmeticUnlockAll() ? "Sblocco eseguito. Verifica dopo il riavvio." : "Nessun nuovo cosmetico da sbloccare.");
			}
			confirmCosmetics = !confirmCosmetics;
		}
		GUI.enabled = enabled;
		if (confirmCosmetics && GUILayout.Button("Annulla", Array.Empty<GUILayoutOption>()))
		{
			confirmCosmetics = false;
		}
		if (!string.IsNullOrEmpty(cosmeticsStatus))
		{
			GUILayout.Label(cosmeticsStatus, Array.Empty<GUILayoutOption>());
		}
		GUILayout.EndScrollView();
		if (GUILayout.Button("Chiudi", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }))
		{
			SetOpen(value: false);
		}
		GUILayout.Label("By NanoLux", Array.Empty<GUILayoutOption>());
		GUILayout.EndArea();
	}

	private static void DrawToggle(string label, ConfigEntry<bool> entry)
	{
		bool flag = GUILayout.Toggle(entry.Value, label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) });
		if (flag != entry.Value)
		{
			entry.Value = flag;
		}
	}

	private static void DrawNumber(string label, ConfigEntry<int> entry, int max)
	{
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label($"{label}: {entry.Value}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
		if (GUILayout.Button("−", (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(42f),
			GUILayout.Height(32f)
		}))
		{
			entry.Value = Mathf.Max(1, entry.Value - 1);
		}
		if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(42f),
			GUILayout.Height(32f)
		}))
		{
			entry.Value = Mathf.Min(max, entry.Value + 1);
		}
		GUILayout.EndHorizontal();
	}
}