using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Utils;
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("ShieldAlwaysVisible")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShieldAlwaysVisible")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace ShieldAlwaysVisible;
public static class Configs
{
public static ConfigEntry<KeyboardShortcut> EnableAndDisableHotkey;
public static ConfigEntry<bool> RememberLastEquippedShield;
public static void SetupConfigs(ConfigFile config)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
EnableAndDisableHotkey = config.Bind<KeyboardShortcut>("General", GenerateConfigKey("EnableAndDisableHotkey"), new KeyboardShortcut((KeyCode)108, Array.Empty<KeyCode>()), "Hotkey for enabling and disabling the functionality for the shield to always be visible. Examples: Mouse 0, Mouse 1, Q, C, Shift + Q, Shift + C");
RememberLastEquippedShield = config.Bind<bool>("General", GenerateConfigKey("RememberLastEquippedShield"), true, "Remembers the last equipped shield even after it vanishes. For example, if you unequip a bow, it will replace the shield on your back, but once equipping again a weapon the shield will once again appear on your back.");
}
public static string GenerateConfigKey(string key)
{
return GenerateConfigKey(key, null);
}
public static string GenerateConfigKey(string key, string unit)
{
key = string.Concat(key.Select((char x) => char.IsUpper(x) ? (" " + x) : x.ToString())).TrimStart(new char[1] { ' ' });
if (!string.IsNullOrEmpty(unit))
{
key += $" ({unit})";
}
return key;
}
}
[BepInPlugin("ShieldAlwaysVisible", "ShieldAlwaysVisible", "1.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class ShieldAlwaysVisible : BaseUnityPlugin
{
[HarmonyPatch(typeof(Player), "Update")]
public class Player_Update_Patch
{
public static void Postfix(Player __instance)
{
//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)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
{
return;
}
KeyboardShortcut value = Configs.EnableAndDisableHotkey.Value;
if (((KeyboardShortcut)(ref value)).Modifiers.Count() == 0)
{
value = Configs.EnableAndDisableHotkey.Value;
if (Input.GetKeyUp(((KeyboardShortcut)(ref value)).MainKey))
{
goto IL_006b;
}
}
value = Configs.EnableAndDisableHotkey.Value;
if (!((KeyboardShortcut)(ref value)).IsUp() || !((Character)__instance).TakeInput())
{
return;
}
goto IL_006b;
IL_006b:
modEnabled = !modEnabled;
((Character)__instance).Message((MessageType)1, string.Format("Shield always visible = {0}.", modEnabled ? "on" : "off"), 0, (Sprite)null);
}
}
[HarmonyPatch(typeof(Humanoid), "EquipItem")]
public static class Humanoid_EquipItem_Patch
{
public static ItemData Shield;
public static void Prefix(Humanoid __instance, ItemData item, bool __result)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Invalid comparison between Unknown and I4
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Invalid comparison between Unknown and I4
if (__instance is Player && modEnabled)
{
if (__instance.m_leftItem != null && (int)__instance.m_leftItem.m_shared.m_itemType == 5)
{
Shield = __instance.m_leftItem;
}
else if (__instance.m_hiddenLeftItem != null && (int)__instance.m_hiddenLeftItem.m_shared.m_itemType == 5)
{
Shield = __instance.m_hiddenLeftItem;
}
}
}
public static void Postfix(Humanoid __instance)
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Invalid comparison between Unknown and I4
if (__instance is Player && modEnabled)
{
if (Shield != null && __instance.m_hiddenLeftItem == null && (__instance.m_leftItem == null || (int)__instance.m_leftItem.m_shared.m_itemType != 5))
{
__instance.m_hiddenLeftItem = Shield;
__instance.SetupEquipment();
}
if (!Configs.RememberLastEquippedShield.Value)
{
Shield = null;
}
}
}
}
[HarmonyPatch(typeof(Humanoid), "HideHandItems")]
public static class Humanoid_HideHandItems_Patch
{
public static ItemData Shield;
public static void Prefix(Humanoid __instance)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Invalid comparison between Unknown and I4
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Invalid comparison between Unknown and I4
if (__instance is Player && modEnabled && __instance.m_hiddenLeftItem != null && (int)__instance.m_hiddenLeftItem.m_shared.m_itemType == 5 && (__instance.m_leftItem == null || (int)__instance.m_leftItem.m_shared.m_itemType != 5))
{
Shield = __instance.m_hiddenLeftItem;
}
}
public static void Postfix(Humanoid __instance)
{
if (__instance is Player && modEnabled)
{
if (Shield != null && __instance.m_hiddenLeftItem == null)
{
__instance.m_hiddenLeftItem = Shield;
__instance.SetupEquipment();
}
Shield = null;
}
}
}
[HarmonyPatch(typeof(Menu), "OnLogoutYes")]
public class Menu_OnLogoutYes_Patch
{
public static void Postfix()
{
Humanoid_EquipItem_Patch.Shield = null;
Humanoid_HideHandItems_Patch.Shield = null;
}
}
public const string PluginGUID = "ShieldAlwaysVisible";
public const string PluginName = "ShieldAlwaysVisible";
public const string PluginVersion = "1.2.0";
private static bool modEnabled = true;
private static Harmony harmony;
private void Awake()
{
Configs.SetupConfigs(((BaseUnityPlugin)this).Config);
harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "ShieldAlwaysVisible");
}
private void OnDestroy()
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
}