using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LastUsedWeapons")]
[assembly: AssemblyDescription("Adds new shortcut to equip items you last held in your hands. Think 'Q' in CS.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("bakaspaceman")]
[assembly: AssemblyProduct("LastUsedWeapons")]
[assembly: AssemblyCopyright("Copyright © bakaspaceman 2021-2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("840eefbf-ed22-45a8-9db3-b7e50d11d3fa")]
[assembly: AssemblyFileVersion("2.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.1.0")]
[module: UnverifiableCode]
public class BepInPluginTemplate : BaseUnityPlugin
{
public enum LogMessageType
{
LogInfo,
LogMessage,
LogDebug,
LogWarning,
LogError,
LogFatal
}
public static ConfigEntry<bool> enableLogging;
public static ConfigEntry<bool> enableTranspilerLogging;
protected BepInPlugin BepInAttr { get; set; }
protected static Harmony harmonyInst { get; set; }
protected static BepInPluginTemplate modInst { get; set; }
protected static ManualLogSource Logger { get; set; }
public static void DebugTranspilerLog(object message, LogMessageType msgType = LogMessageType.LogInfo)
{
DebugLog(message, msgType, transpilerlogs: true);
}
public static void DebugLog(object message, LogMessageType msgType = LogMessageType.LogInfo, bool transpilerlogs = false)
{
if (enableLogging != null && enableLogging.Value && (!transpilerlogs || enableTranspilerLogging == null || enableTranspilerLogging.Value))
{
switch (msgType)
{
case LogMessageType.LogMessage:
Logger.LogMessage(message);
break;
case LogMessageType.LogDebug:
Logger.LogDebug(message);
break;
case LogMessageType.LogWarning:
Logger.LogWarning(message);
break;
case LogMessageType.LogError:
Logger.LogError(message);
break;
case LogMessageType.LogFatal:
Logger.LogFatal(message);
break;
default:
Logger.LogInfo(message);
break;
}
}
}
public static void PrintOutInstructions(List<CodeInstruction> instructions)
{
DebugTranspilerLog("");
DebugTranspilerLog("#############################################################");
DebugTranspilerLog($"######## MODIFIED INSTRUCTIONS - {instructions.Count} ########");
DebugTranspilerLog("#############################################################");
DebugTranspilerLog("");
for (int i = 0; i < instructions.Count; i++)
{
CodeInstruction arg = instructions[i];
DebugTranspilerLog($"{i} {arg}");
}
}
protected virtual void Awake()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
modInst = this;
BepInAttr = (BepInPlugin)Attribute.GetCustomAttribute(((object)this).GetType(), typeof(BepInPlugin));
Logger = Logger.CreateLogSource(BepInAttr.Name);
harmonyInst = new Harmony(BepInAttr.GUID);
DebugLog("Loading..");
}
protected virtual void OnDestroy()
{
if (harmonyInst != null)
{
harmonyInst.UnpatchSelf();
}
DebugLog("Unloading..");
Logger.Sources.Remove((ILogSource)(object)Logger);
}
}
internal static class BepInExHelpers
{
public static ObjectDB FindObjectDB()
{
GameObject val = GameObject.Find("_GameMain");
if ((Object)(object)val != (Object)null)
{
ObjectDB component = val.GetComponent<ObjectDB>();
if ((Object)(object)component != (Object)null)
{
return component;
}
}
return null;
}
}
public static class MathUtils
{
public static string ColorRGBToHexString(int r, int g, int b)
{
return $"#{r:X2}{g:X2}{b:X2}";
}
public static float ConvertRange(float originalStart, float originalEnd, float newStart, float newEnd, float value)
{
double num = (double)(newEnd - newStart) / (double)(originalEnd - originalStart);
return (float)((double)newStart + (double)(value - originalStart) * num);
}
public static float Clamp(float value, float min, float max)
{
if (!(value < min))
{
if (!(value > max))
{
return value;
}
return max;
}
return min;
}
}
public static class EasingFunctions
{
public enum Ease
{
EaseInQuad,
EaseOutQuad,
EaseInOutQuad,
EaseInCubic,
EaseOutCubic,
EaseInOutCubic,
EaseInQuart,
EaseOutQuart,
EaseInOutQuart,
EaseInQuint,
EaseOutQuint,
EaseInOutQuint,
EaseInSine,
EaseOutSine,
EaseInOutSine,
EaseInExpo,
EaseOutExpo,
EaseInOutExpo,
EaseInCirc,
EaseOutCirc,
EaseInOutCirc,
Linear,
Spring,
EaseInBounce,
EaseOutBounce,
EaseInOutBounce,
EaseInBack,
EaseOutBack,
EaseInOutBack,
EaseInElastic,
EaseOutElastic,
EaseInOutElastic
}
public delegate float Function(float s, float e, float v);
private const float NATURAL_LOG_OF_2 = 0.6931472f;
public static float Linear(float start, float end, float value)
{
return Mathf.Lerp(start, end, value);
}
public static float Spring(float start, float end, float value)
{
value = Mathf.Clamp01(value);
value = (Mathf.Sin(value * (float)Math.PI * (0.2f + 2.5f * value * value * value)) * Mathf.Pow(1f - value, 2.2f) + value) * (1f + 1.2f * (1f - value));
return start + (end - start) * value;
}
public static float EaseInQuad(float start, float end, float value)
{
end -= start;
return end * value * value + start;
}
public static float EaseOutQuad(float start, float end, float value)
{
end -= start;
return (0f - end) * value * (value - 2f) + start;
}
public static float EaseInOutQuad(float start, float end, float value)
{
value /= 0.5f;
end -= start;
if (value < 1f)
{
return end * 0.5f * value * value + start;
}
value -= 1f;
return (0f - end) * 0.5f * (value * (value - 2f) - 1f) + start;
}
public static float EaseInCubic(float start, float end, float value)
{
end -= start;
return end * value * value * value + start;
}
public static float EaseOutCubic(float start, float end, float value)
{
value -= 1f;
end -= start;
return end * (value * value * value + 1f) + start;
}
public static float EaseInOutCubic(float start, float end, float value)
{
value /= 0.5f;
end -= start;
if (value < 1f)
{
return end * 0.5f * value * value * value + start;
}
value -= 2f;
return end * 0.5f * (value * value * value + 2f) + start;
}
public static float EaseInQuart(float start, float end, float value)
{
end -= start;
return end * value * value * value * value + start;
}
public static float EaseOutQuart(float start, float end, float value)
{
value -= 1f;
end -= start;
return (0f - end) * (value * value * value * value - 1f) + start;
}
public static float EaseInOutQuart(float start, float end, float value)
{
value /= 0.5f;
end -= start;
if (value < 1f)
{
return end * 0.5f * value * value * value * value + start;
}
value -= 2f;
return (0f - end) * 0.5f * (value * value * value * value - 2f) + start;
}
public static float EaseInQuint(float start, float end, float value)
{
end -= start;
return end * value * value * value * value * value + start;
}
public static float EaseOutQuint(float start, float end, float value)
{
value -= 1f;
end -= start;
return end * (value * value * value * value * value + 1f) + start;
}
public static float EaseInOutQuint(float start, float end, float value)
{
value /= 0.5f;
end -= start;
if (value < 1f)
{
return end * 0.5f * value * value * value * value * value + start;
}
value -= 2f;
return end * 0.5f * (value * value * value * value * value + 2f) + start;
}
public static float EaseInSine(float start, float end, float value)
{
end -= start;
return (0f - end) * Mathf.Cos(value * ((float)Math.PI / 2f)) + end + start;
}
public static float EaseOutSine(float start, float end, float value)
{
end -= start;
return end * Mathf.Sin(value * ((float)Math.PI / 2f)) + start;
}
public static float EaseInOutSine(float start, float end, float value)
{
end -= start;
return (0f - end) * 0.5f * (Mathf.Cos((float)Math.PI * value) - 1f) + start;
}
public static float EaseInExpo(float start, float end, float value)
{
end -= start;
return end * Mathf.Pow(2f, 10f * (value - 1f)) + start;
}
public static float EaseOutExpo(float start, float end, float value)
{
end -= start;
return end * (0f - Mathf.Pow(2f, -10f * value) + 1f) + start;
}
public static float EaseInOutExpo(float start, float end, float value)
{
value /= 0.5f;
end -= start;
if (value < 1f)
{
return end * 0.5f * Mathf.Pow(2f, 10f * (value - 1f)) + start;
}
value -= 1f;
return end * 0.5f * (0f - Mathf.Pow(2f, -10f * value) + 2f) + start;
}
public static float EaseInCirc(float start, float end, float value)
{
end -= start;
return (0f - end) * (Mathf.Sqrt(1f - value * value) - 1f) + start;
}
public static float EaseOutCirc(float start, float end, float value)
{
value -= 1f;
end -= start;
return end * Mathf.Sqrt(1f - value * value) + start;
}
public static float EaseInOutCirc(float start, float end, float value)
{
value /= 0.5f;
end -= start;
if (value < 1f)
{
return (0f - end) * 0.5f * (Mathf.Sqrt(1f - value * value) - 1f) + start;
}
value -= 2f;
return end * 0.5f * (Mathf.Sqrt(1f - value * value) + 1f) + start;
}
public static float EaseInBounce(float start, float end, float value)
{
end -= start;
float num = 1f;
return end - EaseOutBounce(0f, end, num - value) + start;
}
public static float EaseOutBounce(float start, float end, float value)
{
value /= 1f;
end -= start;
if (value < 0.36363637f)
{
return end * (7.5625f * value * value) + start;
}
if (value < 0.72727275f)
{
value -= 0.54545456f;
return end * (7.5625f * value * value + 0.75f) + start;
}
if ((double)value < 0.9090909090909091)
{
value -= 0.8181818f;
return end * (7.5625f * value * value + 0.9375f) + start;
}
value -= 21f / 22f;
return end * (7.5625f * value * value + 63f / 64f) + start;
}
public static float EaseInOutBounce(float start, float end, float value)
{
end -= start;
float num = 1f;
if (value < num * 0.5f)
{
return EaseInBounce(0f, end, value * 2f) * 0.5f + start;
}
return EaseOutBounce(0f, end, value * 2f - num) * 0.5f + end * 0.5f + start;
}
public static float EaseInBack(float start, float end, float value)
{
end -= start;
value /= 1f;
float num = 1.70158f;
return end * value * value * ((num + 1f) * value - num) + start;
}
public static float EaseOutBack(float start, float end, float value)
{
float num = 1.70158f;
end -= start;
value -= 1f;
return end * (value * value * ((num + 1f) * value + num) + 1f) + start;
}
public static float EaseInOutBack(float start, float end, float value)
{
float num = 1.70158f;
end -= start;
value /= 0.5f;
if (value < 1f)
{
num *= 1.525f;
return end * 0.5f * (value * value * ((num + 1f) * value - num)) + start;
}
value -= 2f;
num *= 1.525f;
return end * 0.5f * (value * value * ((num + 1f) * value + num) + 2f) + start;
}
public static float EaseInElastic(float start, float end, float value)
{
end -= start;
float num = 1f;
float num2 = num * 0.3f;
float num3 = 0f;
if (value == 0f)
{
return start;
}
if ((value /= num) == 1f)
{
return start + end;
}
float num4;
if (num3 == 0f || num3 < Mathf.Abs(end))
{
num3 = end;
num4 = num2 / 4f;
}
else
{
num4 = num2 / ((float)Math.PI * 2f) * Mathf.Asin(end / num3);
}
return 0f - num3 * Mathf.Pow(2f, 10f * (value -= 1f)) * Mathf.Sin((value * num - num4) * ((float)Math.PI * 2f) / num2) + start;
}
public static float EaseOutElastic(float start, float end, float value)
{
end -= start;
float num = 1f;
float num2 = num * 0.3f;
float num3 = 0f;
if (value == 0f)
{
return start;
}
if ((value /= num) == 1f)
{
return start + end;
}
float num4;
if (num3 == 0f || num3 < Mathf.Abs(end))
{
num3 = end;
num4 = num2 * 0.25f;
}
else
{
num4 = num2 / ((float)Math.PI * 2f) * Mathf.Asin(end / num3);
}
return num3 * Mathf.Pow(2f, -10f * value) * Mathf.Sin((value * num - num4) * ((float)Math.PI * 2f) / num2) + end + start;
}
public static float EaseInOutElastic(float start, float end, float value)
{
end -= start;
float num = 1f;
float num2 = num * 0.3f;
float num3 = 0f;
if (value == 0f)
{
return start;
}
if ((value /= num * 0.5f) == 2f)
{
return start + end;
}
float num4;
if (num3 == 0f || num3 < Mathf.Abs(end))
{
num3 = end;
num4 = num2 / 4f;
}
else
{
num4 = num2 / ((float)Math.PI * 2f) * Mathf.Asin(end / num3);
}
if (value < 1f)
{
return -0.5f * (num3 * Mathf.Pow(2f, 10f * (value -= 1f)) * Mathf.Sin((value * num - num4) * ((float)Math.PI * 2f) / num2)) + start;
}
return num3 * Mathf.Pow(2f, -10f * (value -= 1f)) * Mathf.Sin((value * num - num4) * ((float)Math.PI * 2f) / num2) * 0.5f + end + start;
}
public static Function GetEasingFunction(Ease easingFunction)
{
return easingFunction switch
{
Ease.EaseInQuad => EaseInQuad,
Ease.EaseOutQuad => EaseOutQuad,
Ease.EaseInOutQuad => EaseInOutQuad,
Ease.EaseInCubic => EaseInCubic,
Ease.EaseOutCubic => EaseOutCubic,
Ease.EaseInOutCubic => EaseInOutCubic,
Ease.EaseInQuart => EaseInQuart,
Ease.EaseOutQuart => EaseOutQuart,
Ease.EaseInOutQuart => EaseInOutQuart,
Ease.EaseInQuint => EaseInQuint,
Ease.EaseOutQuint => EaseOutQuint,
Ease.EaseInOutQuint => EaseInOutQuint,
Ease.EaseInSine => EaseInSine,
Ease.EaseOutSine => EaseOutSine,
Ease.EaseInOutSine => EaseInOutSine,
Ease.EaseInExpo => EaseInExpo,
Ease.EaseOutExpo => EaseOutExpo,
Ease.EaseInOutExpo => EaseInOutExpo,
Ease.EaseInCirc => EaseInCirc,
Ease.EaseOutCirc => EaseOutCirc,
Ease.EaseInOutCirc => EaseInOutCirc,
Ease.Linear => Linear,
Ease.Spring => Spring,
Ease.EaseInBounce => EaseInBounce,
Ease.EaseOutBounce => EaseOutBounce,
Ease.EaseInOutBounce => EaseInOutBounce,
Ease.EaseInBack => EaseInBack,
Ease.EaseOutBack => EaseOutBack,
Ease.EaseInOutBack => EaseInOutBack,
Ease.EaseInElastic => EaseInElastic,
Ease.EaseOutElastic => EaseOutElastic,
Ease.EaseInOutElastic => EaseInOutElastic,
_ => null,
};
}
}
namespace LastUsedWeapons;
[BepInPlugin("bakaSpaceman.LastUsedWeapons", "Last Used Weapons", "2.0.1")]
public class LastUsedWeapons : BepInPluginTemplate
{
public static ConfigEntry<int> nexusID;
private ConfigEntry<KeyboardShortcut> toggleLastEquippedShortcut;
public static ConfigEntry<bool> autoEquipAfterSwimming;
private static MethodInfo _toggleEquipedMethod = typeof(Humanoid).GetMethod("ToggleEquipped", BindingFlags.Instance | BindingFlags.NonPublic);
private static MethodInfo _takeInputMethod = typeof(Player).GetMethod("TakeInput", BindingFlags.Instance | BindingFlags.NonPublic);
private static FieldInfo _hiddenRightItemField = typeof(Humanoid).GetField("m_hiddenRightItem", BindingFlags.Instance | BindingFlags.NonPublic);
private static FieldInfo _hiddenLeftItemField = typeof(Humanoid).GetField("m_hiddenLeftItem", BindingFlags.Instance | BindingFlags.NonPublic);
private static FieldInfo _rightItemField = typeof(Humanoid).GetField("m_rightItem", BindingFlags.Instance | BindingFlags.NonPublic);
private static FieldInfo _leftItemField = typeof(Humanoid).GetField("m_leftItem", BindingFlags.Instance | BindingFlags.NonPublic);
private static ItemData _lastRightItem = null;
private static ItemData _lastLeftItem = null;
private static ItemData _equippedRightItem = null;
private static ItemData _equippedLeftItem = null;
private static bool _cacheLastitems = true;
private static bool _hiddenItemsForSwimming = false;
private void SetupConfig()
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 259, "Nexus mod ID for updates");
toggleLastEquippedShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Key Bindings", "ToggleLastUsedWeapons", new KeyboardShortcut((KeyCode)116, Array.Empty<KeyCode>()), "Equips previous set of weapons");
autoEquipAfterSwimming = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AutoEquipOnLeavingWater", true, "Will automatically restore weapons that were unequipped on entering water");
}
protected override void Awake()
{
base.Awake();
SetupConfig();
BepInPluginTemplate.harmonyInst.PatchAll(typeof(LastUsedWeapons));
}
private void Update()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)Player.m_localPlayer != (Object)null))
{
return;
}
if ((bool)_takeInputMethod.Invoke(Player.m_localPlayer, new object[0]))
{
KeyboardShortcut value = toggleLastEquippedShortcut.Value;
if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
{
ToggleLastEquippedItems();
}
}
if (autoEquipAfterSwimming.Value && (!((Character)Player.m_localPlayer).IsSwimming() || ((Character)Player.m_localPlayer).IsOnGround()))
{
if (_hiddenItemsForSwimming)
{
((Humanoid)Player.m_localPlayer).ShowHandItems();
}
_hiddenItemsForSwimming = false;
}
}
private static void SetLastRightItem(ItemData newRightItem)
{
//IL_003d: 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)
//IL_0084: Invalid comparison between Unknown and I4
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Invalid comparison between Unknown and I4
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Invalid comparison between Unknown and I4
string name = new StackFrame(1).GetMethod().Name;
_lastRightItem = newRightItem;
if (_lastRightItem != null)
{
BepInPluginTemplate.DebugLog($"SetLastRightItem: ({name}) set - {_lastRightItem.m_shared.m_name}, type - {_lastRightItem.m_shared.m_itemType}");
}
else
{
BepInPluginTemplate.DebugLog("SetLastRightItem: (" + name + ") set to empty.");
}
if ((_lastRightItem != null && (int)_lastRightItem.m_shared.m_itemType == 14) || (_lastRightItem != null && (int)_lastRightItem.m_shared.m_itemType == 19) || (_lastLeftItem != null && (int)_lastLeftItem.m_shared.m_itemType == 4))
{
_lastLeftItem = null;
BepInPluginTemplate.DebugLog("SetLastRightItem: (" + name + ") last LEFT set to empty.");
}
}
private static void SetLastLeftItem(ItemData newLeftItem)
{
//IL_003d: 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)
//IL_0083: Invalid comparison between Unknown and I4
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Invalid comparison between Unknown and I4
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Invalid comparison between Unknown and I4
string name = new StackFrame(1).GetMethod().Name;
_lastLeftItem = newLeftItem;
if (_lastLeftItem != null)
{
BepInPluginTemplate.DebugLog($"SetLastLeftItem: ({name}) set - {_lastLeftItem.m_shared.m_name}, type - {_lastLeftItem.m_shared.m_itemType}");
}
else
{
BepInPluginTemplate.DebugLog("SetLastLeftItem: (" + name + ") set to empty.");
}
if ((_lastLeftItem != null && (int)_lastLeftItem.m_shared.m_itemType == 4) || (_lastRightItem != null && ((int)_lastRightItem.m_shared.m_itemType == 14 || (int)_lastRightItem.m_shared.m_itemType == 19)))
{
_lastRightItem = null;
BepInPluginTemplate.DebugLog("SetLastLeftItem: (" + name + ") last RIGHT set to empty.");
}
}
[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
[HarmonyPrefix]
private static bool UnequipItem_Prefix(Humanoid __instance, ItemData item, bool triggerEquipEffects = true)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
{
return true;
}
if (!_cacheLastitems)
{
return true;
}
if (item != null && item.m_shared != null)
{
BepInPluginTemplate.DebugLog($"UnequipItem_Prefix: item - {item.m_shared.m_name}, type - {item.m_shared.m_itemType}");
return CacheCurrentlyEquippedItems(__instance, ref _equippedRightItem, ref _equippedLeftItem);
}
return true;
}
[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
[HarmonyPostfix]
private static void UnequipItem_Postfix(Humanoid __instance, ItemData item, bool triggerEquipEffects = true)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Invalid comparison between O and Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Invalid comparison between O and Unknown
if (!_cacheLastitems || item == null || item.m_shared == null)
{
return;
}
BepInPluginTemplate.DebugLog($"UnequipItem_Postfix: item - {item.m_shared.m_name}, type - {item.m_shared.m_itemType}");
if (!((Object)(object)Player.m_localPlayer != (Object)(object)__instance))
{
if ((object)_equippedRightItem != (object)(ItemData)_rightItemField.GetValue(__instance))
{
SetLastRightItem(_equippedRightItem);
}
if ((object)_equippedLeftItem != (object)(ItemData)_leftItemField.GetValue(__instance))
{
SetLastLeftItem(_equippedLeftItem);
}
_equippedRightItem = null;
_equippedLeftItem = null;
}
}
[HarmonyPatch(typeof(Humanoid), "EquipItem")]
[HarmonyPrefix]
private static bool EquipItem_Prefix(Humanoid __instance, ItemData item, bool triggerEquipEffects = true)
{
//IL_003c: 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_006f: Invalid comparison between Unknown and I4
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Expected O, but got Unknown
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Expected O, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Invalid comparison between Unknown and I4
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Invalid comparison between Unknown and I4
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Invalid comparison between Unknown and I4
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Invalid comparison between Unknown and I4
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Invalid comparison between Unknown and I4
if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
{
return true;
}
BepInPluginTemplate.DebugLog("");
if (item != null && item.m_shared != null)
{
BepInPluginTemplate.DebugLog($"EquipItem_Prefix: item - {item.m_shared.m_name}, type - {item.m_shared.m_itemType}");
if ((int)item.m_shared.m_itemType == 19 || (int)item.m_shared.m_itemType == 15 || (int)item.m_shared.m_itemType == 3 || (int)item.m_shared.m_itemType == 5 || (int)item.m_shared.m_itemType == 4 || (int)item.m_shared.m_itemType == 14)
{
ItemData val = (ItemData)_hiddenLeftItemField.GetValue(__instance);
ItemData val2 = (ItemData)_hiddenRightItemField.GetValue(__instance);
if (val2 != null)
{
SetLastRightItem(val2);
}
if (val != null)
{
SetLastLeftItem(val);
}
}
return true;
}
BepInPluginTemplate.DebugLog("EquipItem_Prefix: item - NULL");
return true;
}
[HarmonyPatch(typeof(Humanoid), "HideHandItems")]
[HarmonyPrefix]
private static bool HideHandItems_Prefix(Humanoid __instance)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
{
return true;
}
if (((Character)__instance).IsSwimming() && !((Character)__instance).IsOnGround() && ((int)(ItemData)_rightItemField.GetValue(__instance) != 0 || (int)(ItemData)_leftItemField.GetValue(__instance) != 0))
{
_hiddenItemsForSwimming = true;
}
_cacheLastitems = false;
return true;
}
[HarmonyPatch(typeof(Humanoid), "HideHandItems")]
[HarmonyPostfix]
private static void HideHandItems_Postfix(Humanoid __instance)
{
if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
{
_cacheLastitems = true;
}
}
private void ToggleLastEquippedItems()
{
//IL_002a: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Invalid comparison between Unknown and I4
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Invalid comparison between Unknown and I4
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_0323: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Player.m_localPlayer == (Object)null || ((Character)Player.m_localPlayer).IsRunning())
{
return;
}
if ((int)(ItemData)_hiddenLeftItemField.GetValue(Player.m_localPlayer) != 0 || (int)(ItemData)_hiddenRightItemField.GetValue(Player.m_localPlayer) != 0)
{
if (!((Character)Player.m_localPlayer).IsSwimming() || ((Character)Player.m_localPlayer).IsOnGround())
{
BepInPluginTemplate.DebugLog("");
BepInPluginTemplate.DebugLog("--- [Toggle Last Equipped] START ---");
((Humanoid)Player.m_localPlayer).ShowHandItems();
BepInPluginTemplate.DebugLog("ShowHandItems() instead");
BepInPluginTemplate.DebugLog("");
}
return;
}
BepInPluginTemplate.DebugLog("");
BepInPluginTemplate.DebugLog("--- [Toggle Last Equipped] START ---");
_cacheLastitems = false;
ItemData rightItem = null;
ItemData leftItem = null;
CacheCurrentlyEquippedItems((Humanoid)(object)Player.m_localPlayer, ref rightItem, ref leftItem);
bool flag = false;
bool flag2 = false;
bool flag3 = leftItem != null && _lastRightItem != null && (int)_lastRightItem.m_shared.m_itemType == 19;
if (_lastRightItem != null)
{
if (rightItem != null && _lastRightItem.m_shared.m_name == rightItem.m_shared.m_name)
{
_lastRightItem = null;
BepInPluginTemplate.DebugLog("ToggleLastEquippedItems: last RIGHT item is same as current equipped one. Setting to empty.");
}
else
{
if (_lastLeftItem != null && (int)_lastLeftItem.m_shared.m_itemType == 15)
{
_lastLeftItem = null;
BepInPluginTemplate.DebugLog("ToggleLastEquippedItems: last LEFT set to empty because its a torch.");
}
BepInPluginTemplate.DebugLog($"Trying to equip {_lastRightItem.m_shared.m_name}({_lastRightItem.m_shared.m_itemType}) to right arm");
_ = _lastRightItem.m_shared.m_itemType;
flag = (bool)_toggleEquipedMethod.Invoke(Player.m_localPlayer, new object[1] { _lastRightItem });
if (flag)
{
BepInPluginTemplate.DebugLog("Successful");
_lastRightItem = rightItem;
if (_lastRightItem != null)
{
BepInPluginTemplate.DebugLog($"ToggleLastEquippedItems: last RIGHT set - {_lastRightItem.m_shared.m_name}, type - {_lastRightItem.m_shared.m_itemType}");
}
else
{
BepInPluginTemplate.DebugLog("ToggleLastEquippedItems: last RIGHT set to empty.");
}
}
}
}
if (_lastLeftItem != null)
{
if (leftItem != null && _lastLeftItem.m_shared.m_name == leftItem.m_shared.m_name)
{
_lastLeftItem = null;
BepInPluginTemplate.DebugLog("ToggleLastEquippedItems: last LEFT item is same as current equipped one. Setting to empty.");
}
else
{
BepInPluginTemplate.DebugLog($"Trying to equip {_lastLeftItem.m_shared.m_name}({_lastLeftItem.m_shared.m_itemType}) to left arm");
_ = _lastLeftItem.m_shared.m_itemType;
if ((!flag) ? ((bool)_toggleEquipedMethod.Invoke(Player.m_localPlayer, new object[1] { _lastLeftItem })) : ((Humanoid)Player.m_localPlayer).EquipItem(_lastLeftItem, true))
{
BepInPluginTemplate.DebugLog("Successful");
_lastLeftItem = leftItem;
if (_lastLeftItem != null)
{
BepInPluginTemplate.DebugLog($"ToggleLastEquippedItems: last LEFT set - {_lastLeftItem.m_shared.m_name}, type - {_lastLeftItem.m_shared.m_itemType}");
}
else
{
BepInPluginTemplate.DebugLog("ToggleLastEquippedItems: last LEFT set to empty.");
}
}
}
}
else if (flag3)
{
_lastLeftItem = leftItem;
}
_cacheLastitems = true;
BepInPluginTemplate.DebugLog("--- [Toggle Last Equipped] END ---");
BepInPluginTemplate.DebugLog("");
}
private static bool CacheCurrentlyEquippedItems(Humanoid __instance, ref ItemData rightItem, ref ItemData leftItem)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Player.m_localPlayer != (Object)(object)__instance || (Object)(object)__instance == (Object)null)
{
return true;
}
if (_rightItemField != null)
{
rightItem = (ItemData)_rightItemField.GetValue(__instance);
if (rightItem != null && rightItem.m_shared != null)
{
BepInPluginTemplate.DebugLog($"Currently equipped RIGHT item - {rightItem.m_shared.m_name}, type - {rightItem.m_shared.m_itemType}");
}
}
if (_leftItemField != null)
{
leftItem = (ItemData)_leftItemField.GetValue(__instance);
if (leftItem != null && leftItem.m_shared != null)
{
BepInPluginTemplate.DebugLog($"Currently equipped LEFT item - {leftItem.m_shared.m_name}, type - {leftItem.m_shared.m_itemType}");
}
}
return true;
}
}