using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e70e6943c8d50025020cc12e5a1680bf7f695f89")]
[assembly: AssemblyVersion("1.0.0.0")]
public class AedenthornUtils
{
public static bool IgnoreKeyPresses(bool extra = false)
{
int result;
if (!extra)
{
if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
{
Chat instance = Chat.instance;
if (instance == null || !instance.HasFocus())
{
result = (Menu.IsVisible() ? 1 : 0);
goto IL_005f;
}
}
result = 1;
goto IL_005f;
}
int result2;
if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
{
Chat instance2 = Chat.instance;
if ((instance2 == null || !instance2.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible())
{
TextViewer instance3 = TextViewer.instance;
result2 = ((instance3 != null && instance3.IsVisible()) ? 1 : 0);
goto IL_00d9;
}
}
result2 = 1;
goto IL_00d9;
IL_005f:
return (byte)result != 0;
IL_00d9:
return (byte)result2 != 0;
}
public static bool CheckKeyDown(string value)
{
try
{
return Input.GetKeyDown(value.ToLower());
}
catch
{
return false;
}
}
public static bool CheckKeyHeld(string value, bool req = true)
{
try
{
return Input.GetKey(value.ToLower());
}
catch
{
return !req;
}
}
}
namespace CustomToolbarHotkeys;
[BepInPlugin("aedenthorn.CustomToolbarHotkeys", "Custom Toolbar Hotkeys", "0.4.0")]
public class BepInExPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")]
private static class HotkeyBar_UpdateIcons_Patch
{
private static void Postfix(HotkeyBar __instance)
{
if (!modEnabled.Value || ((Object)__instance).name != "HotKeyBar")
{
return;
}
int childCount = ((Component)__instance).transform.childCount;
if (showHotkeys.Value)
{
Dbgl("Switching to Hotkeys");
for (int i = 0; i < childCount; i++)
{
if (Object.op_Implicit((Object)(object)((Component)__instance).transform.GetChild(i).Find("binding")))
{
((TMP_Text)((Component)((Component)__instance).transform.GetChild(i).Find("binding")).GetComponent<TextMeshProUGUI>()).text = hotkeys[i].Value;
}
}
return;
}
if (hideNumbers.Value)
{
Dbgl("Switching to Nothing");
for (int j = 0; j < childCount; j++)
{
if (Object.op_Implicit((Object)(object)((Component)__instance).transform.GetChild(j).Find("binding")))
{
((TMP_Text)((Component)((Component)__instance).transform.GetChild(j).Find("binding")).GetComponent<TextMeshProUGUI>()).text = "";
}
}
return;
}
Dbgl("Switching to Numbers");
for (int k = 0; k < childCount; k++)
{
if (Object.op_Implicit((Object)(object)((Component)__instance).transform.GetChild(k).Find("binding")))
{
((TMP_Text)((Component)((Component)__instance).transform.GetChild(k).Find("binding")).GetComponent<TextMeshProUGUI>()).text = (k + 1).ToString();
}
}
}
}
[HarmonyPatch(typeof(Player), "Update")]
private static class Player_Update_Patch
{
private static bool Prefix(Player __instance)
{
if (!modEnabled.Value || AedenthornUtils.IgnoreKeyPresses(extra: true))
{
return true;
}
int num;
if (AedenthornUtils.CheckKeyDown(hotKey1.Value))
{
num = 1;
}
else if (AedenthornUtils.CheckKeyDown(hotKey2.Value))
{
num = 2;
}
else if (AedenthornUtils.CheckKeyDown(hotKey3.Value))
{
num = 3;
}
else if (AedenthornUtils.CheckKeyDown(hotKey4.Value))
{
num = 4;
}
else if (AedenthornUtils.CheckKeyDown(hotKey5.Value))
{
num = 5;
}
else if (AedenthornUtils.CheckKeyDown(hotKey6.Value))
{
num = 6;
}
else if (AedenthornUtils.CheckKeyDown(hotKey7.Value))
{
num = 7;
}
else
{
if (!AedenthornUtils.CheckKeyDown(hotKey8.Value))
{
return true;
}
num = 8;
}
usingHotkey = true;
__instance.UseHotbarItem(num);
return false;
}
}
[HarmonyPatch(typeof(Player), "UseHotbarItem")]
private static class Player_UseHotbarItem_Patch
{
private static bool Prefix(int index)
{
if (!modEnabled.Value || !usingHotkey)
{
return false;
}
usingHotkey = false;
return true;
}
}
[HarmonyPatch(typeof(InventoryGui), "Update")]
private static class InventoryGui_Update_Patch
{
private static void Postfix(InventoryGrid ___m_playerGrid, Animator ___m_animator)
{
if (!modEnabled.Value || ((Component)___m_playerGrid.m_gridRoot).transform.childCount < 8 || !___m_animator.GetBool("visible"))
{
return;
}
if (showHotkeys.Value)
{
Dbgl("Switching to Hotkeys");
for (int i = 0; i < 8; i++)
{
Transform child = ((Component)___m_playerGrid.m_gridRoot).transform.GetChild(i);
if (Object.op_Implicit((Object)(object)((child != null) ? child.Find("binding") : null)))
{
((Component)((Component)___m_playerGrid.m_gridRoot).transform.GetChild(i).Find("binding")).GetComponent<TMP_Text>().text = hotkeys[i].Value;
}
}
return;
}
if (hideNumbers.Value)
{
Dbgl("Switching to Nothing");
for (int j = 0; j < 8; j++)
{
Transform child2 = ((Component)___m_playerGrid.m_gridRoot).transform.GetChild(j);
if (Object.op_Implicit((Object)(object)((child2 != null) ? child2.Find("binding") : null)))
{
((Component)((Component)___m_playerGrid.m_gridRoot).transform.GetChild(j).Find("binding")).GetComponent<TMP_Text>().text = "";
}
}
return;
}
Dbgl("Switching to Numbers");
for (int k = 0; k < 8; k++)
{
Transform child3 = ((Component)___m_playerGrid.m_gridRoot).transform.GetChild(k);
if (Object.op_Implicit((Object)(object)((child3 != null) ? child3.Find("binding") : null)))
{
((Component)((Component)___m_playerGrid.m_gridRoot).transform.GetChild(k).Find("binding")).GetComponent<TMP_Text>().text = (k + 1).ToString();
}
}
}
}
[HarmonyPatch(typeof(Terminal), "InputText")]
private static class InputText_Patch
{
private static bool Prefix(Terminal __instance)
{
if (!modEnabled.Value)
{
return true;
}
string text = ((TMP_InputField)__instance.m_input).text;
if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
{
((BaseUnityPlugin)context).Config.Reload();
((BaseUnityPlugin)context).Config.Save();
__instance.AddString(text);
__instance.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded");
return false;
}
return true;
}
}
private static readonly bool isDebug;
private static BepInExPlugin context;
private static bool usingHotkey;
public static ConfigEntry<bool> modEnabled;
public static ConfigEntry<int> nexusID;
public static ConfigEntry<bool> hideNumbers;
public static ConfigEntry<bool> showHotkeys;
public static ConfigEntry<string> hotKey1;
public static ConfigEntry<string> hotKey2;
public static ConfigEntry<string> hotKey3;
public static ConfigEntry<string> hotKey4;
public static ConfigEntry<string> hotKey5;
public static ConfigEntry<string> hotKey6;
public static ConfigEntry<string> hotKey7;
public static ConfigEntry<string> hotKey8;
private static ConfigEntry<string>[] hotkeys;
public static void Dbgl(string str = "", bool pref = true)
{
if (isDebug)
{
Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
}
}
private void Awake()
{
context = this;
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 683, "Nexus mod ID for updates");
hideNumbers = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HideNumbers", false, "Hide hotkey numbers on toolbar");
showHotkeys = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowHotkeys", false, "Show new hotkey strings on toolbar (takes priority over numbers or hidden)");
hotKey1 = ((BaseUnityPlugin)this).Config.Bind<string>("Hotkeys", "HotKey1", "1", "Hotkey 1 - Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
hotKey2 = ((BaseUnityPlugin)this).Config.Bind<string>("Hotkeys", "HotKey2", "2", "Hotkey 2 - Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
hotKey3 = ((BaseUnityPlugin)this).Config.Bind<string>("Hotkeys", "HotKey3", "3", "Hotkey 3 - Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
hotKey4 = ((BaseUnityPlugin)this).Config.Bind<string>("Hotkeys", "HotKey4", "4", "Hotkey 4 - Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
hotKey5 = ((BaseUnityPlugin)this).Config.Bind<string>("Hotkeys", "HotKey5", "5", "Hotkey 5 - Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
hotKey6 = ((BaseUnityPlugin)this).Config.Bind<string>("Hotkeys", "HotKey6", "6", "Hotkey 6 - Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
hotKey7 = ((BaseUnityPlugin)this).Config.Bind<string>("Hotkeys", "HotKey7", "7", "Hotkey 7 - Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
hotKey8 = ((BaseUnityPlugin)this).Config.Bind<string>("Hotkeys", "HotKey8", "8", "Hotkey 8 - Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
hotkeys = new ConfigEntry<string>[8] { hotKey1, hotKey2, hotKey3, hotKey4, hotKey5, hotKey6, hotKey7, hotKey8 };
if (modEnabled.Value)
{
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
}
}
}