using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KikisFallDamageCancel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("KikisFallDamageCancel")]
[assembly: AssemblyTitle("KikisFallDamageCancel")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 KFDC
{
[BepInPlugin("kikisfalldamagecancel.peak.kfdc", "KikisFallDamageCancel", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
try
{
new Harmony("kikisfalldamagecancel.peak.kfdc").PatchAll(typeof(Plugin).Assembly);
MethodInfo methodInfo = AccessTools.Method(typeof(CharacterItems), "DoSwitching", (Type[])null, (Type[])null);
Patches val = ((methodInfo != null) ? Harmony.GetPatchInfo((MethodBase)methodInfo) : null);
if (val != null && val.Prefixes.Count > 0 && val.Finalizers.Count > 0)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"[KFDC] KikisFallDamageCancel 1.0.1 loaded - CharacterItems.DoSwitching hook ok");
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"[KFDC] KikisFallDamageCancel 1.0.1: CharacterItems.DoSwitching hook MISSING - the play dead lock stays");
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("[KFDC] KikisFallDamageCancel 1.0.1 failed to patch: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(CharacterItems), "DoSwitching")]
internal static class SwitchPatch
{
private static float _realLast = -1f;
private static float _lockUntil;
private static float _swapped;
private static bool _open;
private static bool IsMine(CharacterItems items)
{
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter != (Object)null && localCharacter.refs != null)
{
return (Object)(object)localCharacter.refs.items == (Object)(object)items;
}
return false;
}
private static void Prefix(CharacterItems __instance)
{
_open = false;
try
{
if (IsMine(__instance))
{
float lastEquippedSlotTime = __instance.lastEquippedSlotTime;
if (lastEquippedSlotTime <= Time.time)
{
_realLast = lastEquippedSlotTime;
return;
}
_lockUntil = lastEquippedSlotTime;
_swapped = _realLast;
__instance.lastEquippedSlotTime = _swapped;
_open = true;
}
}
catch
{
_open = false;
}
}
private static void Finalizer(CharacterItems __instance)
{
if (!_open)
{
return;
}
_open = false;
try
{
float lastEquippedSlotTime = __instance.lastEquippedSlotTime;
if (lastEquippedSlotTime != _swapped)
{
_realLast = lastEquippedSlotTime;
}
__instance.lastEquippedSlotTime = Mathf.Max(lastEquippedSlotTime, _lockUntil);
}
catch
{
}
}
}
}