using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Agents;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Gear;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Player;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ShoveSwitchBack")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShoveSwitchBack")]
[assembly: AssemblyTitle("ShoveSwitchBack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ShoveSwitchBack
{
[BepInPlugin("Localia.ShoveSwitchBack", "ShoveSwitchBack", "1.0.0")]
public class EntryPoint : BasePlugin
{
private Harmony m_Harmony;
public override void Load()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
m_Harmony = new Harmony("Localia.ShoveSwitchBack");
m_Harmony.PatchAll();
Logs.Info("OK");
}
}
internal static class Logs
{
private static readonly ManualLogSource _logger;
static Logs()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
_logger = new ManualLogSource("Localia.ShoveSwitchBack");
Logger.Sources.Add((ILogSource)(object)_logger);
}
private static string Format(object msg)
{
return msg.ToString();
}
public static void Info(object data)
{
_logger.LogMessage((object)Format(data));
}
public static void Verbose(object data)
{
_logger.LogDebug((object)Format(data));
}
public static void Debug(object data)
{
_logger.LogDebug((object)Format(data));
}
public static void Error(object data)
{
_logger.LogError((object)Format(data));
}
}
internal static class UFuncs
{
internal static bool is_shortcut_check = false;
internal static bool can_switch_back = false;
internal static InventorySlot checking_slot = (InventorySlot)1;
internal static InventorySlot last_slot = (InventorySlot)1;
internal static void SwitchBack(PlayerAgent agent)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Invalid comparison between Unknown and I4
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Invalid comparison between Unknown and I4
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: 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
//IL_004c: 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)
if (!((Object)(object)agent == (Object)null) && ((Agent)agent).IsLocallyOwned && (int)last_slot != 10)
{
if ((int)last_slot != 1 && (int)last_slot != 2)
{
last_slot = (InventorySlot)1;
}
PlayerInventoryLocal inventoryLocal = agent.FPItemHolder.m_inventoryLocal;
if ((int)FocusStateManager.CurrentState != 6 && !inventoryLocal.CheckWieldingKeys() && (Object)(object)((PlayerInventoryBase)inventoryLocal).m_wieldedItem != (Object)null)
{
can_switch_back = false;
((PlayerInventoryBase)inventoryLocal).Owner.Sync.WantsToWieldSlot(last_slot, false);
}
}
}
}
[HarmonyPatch(typeof(MWS_Push))]
internal static class Patch_MWS_Push
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
[HarmonyWrapSafe]
private static void MWS_Push_Update(MWS_Push __instance)
{
if (UFuncs.can_switch_back)
{
if (__instance.m_damageDone)
{
UFuncs.SwitchBack(((Item)((MWS_Base)__instance).m_weapon).Owner);
}
else if (__instance.m_elapsed >= ((MWS_Base)__instance).m_data.m_damageEndTime)
{
UFuncs.SwitchBack(((Item)((MWS_Base)__instance).m_weapon).Owner);
}
}
}
}
[HarmonyPatch(typeof(FirstPersonItemHolder))]
internal static class Patch_FirstPersonItemHolder
{
[HarmonyPatch("MeleeAttackShortcut")]
[HarmonyPrefix]
[HarmonyWrapSafe]
private static void FirstPersonItemHolder_MeleeAttackShortcut(FirstPersonItemHolder __instance)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
UFuncs.is_shortcut_check = true;
UFuncs.can_switch_back = false;
UFuncs.checking_slot = ((PlayerInventoryBase)__instance.m_inventoryLocal).WieldedSlot;
}
[HarmonyPatch("MeleeAttackShortcut")]
[HarmonyPostfix]
[HarmonyWrapSafe]
private static void FirstPersonItemHolder_MeleeAttackShortcutPost(FirstPersonItemHolder __instance)
{
UFuncs.is_shortcut_check = false;
}
}
[HarmonyPatch(typeof(MeleeWeaponFirstPerson))]
internal static class Patch_MeleeWeaponFirstPerson
{
[HarmonyPatch("OnWield")]
[HarmonyPostfix]
[HarmonyWrapSafe]
private static void MeleeWeaponFirstPerson_OnWield(MeleeWeaponFirstPerson __instance)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
if (((Agent)((Item)__instance).Owner).IsLocallyOwned)
{
if (UFuncs.is_shortcut_check)
{
UFuncs.last_slot = UFuncs.checking_slot;
UFuncs.can_switch_back = true;
}
else
{
UFuncs.can_switch_back = false;
UFuncs.is_shortcut_check = false;
}
}
}
[HarmonyPatch("DoAttackDamage")]
[HarmonyPostfix]
[HarmonyWrapSafe]
private static void MeleeWeaponFirstPerson_DoAttackDamage(MeleeWeaponFirstPerson __instance, MeleeWeaponDamageData __0, bool __1)
{
if (__1 && ((Agent)((Item)__instance).Owner).IsLocallyOwned && UFuncs.can_switch_back)
{
((Item)__instance).Owner.Sound.Post(((ItemEquippable)__instance).MeleeSFXData.ShoveHit, true);
}
}
}
}