using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BlindCartographer.Loader;
using BlindCartographer.Modifier;
using BlindCartographer.Ui;
using HarmonyLib;
using Splatform;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BlindCartographer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BlindCartographer")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2DA6F5A0-E14F-4334-A8B7-A2D9040E3BFC")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace BlindCartographer
{
[BepInPlugin("nightkosh.BlindCartographer", "BlindCartographer", "1.0.1")]
public class BlindCartographer : BaseUnityPlugin
{
private const string PluginGuid = "nightkosh.BlindCartographer";
private const string PluginName = "BlindCartographer";
private const string PluginVersion = "1.0.1";
public static ConfigEntry<KeyCode> ConfigPinKey;
private static ConfigEntry<bool> _modEnabled;
public static ConfigEntry<bool> _enableCartographyTableInNoMapMode;
public static ConfigEntry<bool> _enableHotKey;
public static ConfigEntry<bool> _showHotKeyText;
public static Harmony Harmony;
private GameObject _lastHoveredObject;
private string _lastObjectName;
private bool _showPopup;
private string _textInput = "";
public void Awake()
{
_modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ModEnabled", true, "Enable or disable the mod.");
_enableCartographyTableInNoMapMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Map", "EnableCartographyTableInNoMapMode", true, "Enable cartography table in no map mode.");
_enableHotKey = ((BaseUnityPlugin)this).Config.Bind<bool>("Hotkeys", "EnableHotKey", true, "Enable hot key.");
_showHotKeyText = ((BaseUnityPlugin)this).Config.Bind<bool>("Hotkeys", "ShowHotKeyText", true, "Show hot key text.");
ConfigPinKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkeys", "HotKey", (KeyCode)116, "Key to press with LEFT ALT to pin hovered object to the map");
if (_modEnabled.Value)
{
Harmony = Harmony.CreateAndPatchAll(typeof(BlindCartographer).Assembly, "nightkosh.BlindCartographer");
HoverTextPatchLoader.ApplyPatches();
}
}
private void Update()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
if (_modEnabled.Value && !IsAnyGameUIOpen() && _enableHotKey.Value && Input.GetKeyDown(ConfigPinKey.Value) && Input.GetKey((KeyCode)308))
{
Player localPlayer = Player.m_localPlayer;
if (!((Object)(object)localPlayer == (Object)null))
{
GetHoverObject(localPlayer);
TextInput.instance.RequestText((TextReceiver)(object)new PinTextReceiver(_lastObjectName, AddToMap), "Enter pin name", 255);
}
}
}
private bool IsAnyGameUIOpen()
{
int result;
if (!InventoryGui.IsVisible() && !Minimap.IsOpen() && !TextInput.IsVisible() && !StoreGui.IsVisible())
{
Chat instance = Chat.instance;
if ((instance == null || !instance.HasFocus()) && !Console.IsVisible())
{
result = (Menu.IsVisible() ? 1 : 0);
goto IL_003f;
}
}
result = 1;
goto IL_003f;
IL_003f:
return (byte)result != 0;
}
private void GetHoverObject(Player player)
{
_lastHoveredObject = null;
_lastObjectName = "";
GameObject hoverObject = ((Humanoid)player).GetHoverObject();
if (!((Object)(object)hoverObject != (Object)null))
{
return;
}
Hoverable componentInParent = hoverObject.GetComponentInParent<Hoverable>();
if (componentInParent == null)
{
return;
}
_lastHoveredObject = hoverObject;
string hoverText = componentInParent.GetHoverText();
if (!string.IsNullOrEmpty(hoverText))
{
string[] array = hoverText.Split(new char[1] { '\n' });
if (array.Length > 1)
{
_lastObjectName = array[0];
}
}
}
private void AddToMap(string pinName)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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_0045: 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_0054: Unknown result type (might be due to invalid IL or missing references)
Minimap instance = Minimap.instance;
if (!((Object)(object)instance == (Object)null))
{
Vector3 val = (((Object)(object)_lastHoveredObject == (Object)null) ? ((Component)Player.m_localPlayer).transform.position : _lastHoveredObject.transform.position);
instance.AddPin(val, (PinType)3, pinName, true, false, 0L, default(PlatformUserID));
Player localPlayer = Player.m_localPlayer;
if (localPlayer != null)
{
((Character)localPlayer).Message((MessageType)1, "Pin `" + pinName + "` added!", 0, (Sprite)null);
}
}
}
}
}
namespace BlindCartographer.Ui
{
public class PinTextReceiver : TextReceiver
{
private readonly string _initial;
private readonly Action<string> _onSubmit;
public PinTextReceiver(string initial, Action<string> onSubmit)
{
_initial = initial;
_onSubmit = onSubmit;
}
public string GetText()
{
return _initial;
}
public void SetText(string text)
{
_onSubmit?.Invoke(text);
}
}
}
namespace BlindCartographer.Patches
{
[HarmonyPatch(typeof(MapTable), "OnRead", new Type[]
{
typeof(Switch),
typeof(Humanoid),
typeof(ItemData),
typeof(bool)
})]
public static class MapTableOnReadPatch
{
public static void Postfix()
{
if (BlindCartographer._enableCartographyTableInNoMapMode.Value && Game.m_noMap)
{
Game.m_noMap = false;
Minimap.instance.SetMapMode((MapMode)2);
Game.m_noMap = true;
}
}
}
}
namespace BlindCartographer.Modifier
{
public static class HoverTextModifier
{
public static void AddHoverText<T>(T __instance, ref string __result)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if (BlindCartographer._enableHotKey.Value && BlindCartographer._showHotKeyText.Value && __instance != null)
{
__result += $"\n[<color=yellow>LEFT ALT + {BlindCartographer.ConfigPinKey.Value}</color>] Pin to the map";
}
}
}
}
namespace BlindCartographer.Loader
{
public static class HoverTextPatchLoader
{
public static void ApplyPatches()
{
IEnumerable<Type> enumerable = (from t in typeof(Hoverable).Assembly.GetTypes()
where typeof(Hoverable).IsAssignableFrom(t)
select t).Where(delegate(Type t)
{
MethodInfo method = t.GetMethod("GetHoverText", BindingFlags.Instance | BindingFlags.Public);
return method != null && method.GetMethodBody() != null && !typeof(Character).IsAssignableFrom(t);
});
foreach (Type item in enumerable)
{
PatchHoverText(item);
}
}
private static void PatchHoverText(Type type)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.Method(type, "GetHoverText", (Type[])null, (Type[])null);
if (methodInfo == null)
{
Debug.LogWarning((object)("[HoverTextPatch] Can't find GetHoverText of " + type.Name));
return;
}
HarmonyMethod val = new HarmonyMethod(typeof(HoverTextModifier).GetMethod("AddHoverText")?.MakeGenericMethod(type));
BlindCartographer.Harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
}