using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("KnifeFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5ff5497fad3a9fd2f6023bf89f192528bc115db8")]
[assembly: AssemblyProduct("KnifeFix")]
[assembly: AssemblyTitle("KnifeFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace KnifeFix
{
internal static class KnifePatch
{
private static readonly Dictionary<uint, float> ModifiedSpheres = new Dictionary<uint, float>();
private const float KNIFE_SPHERE_MIN = 0.15f;
private const float KNIFE_SPHERE_MOD = -0.1f;
private const float KNIFE_LENGTH_MOD = 0.25f;
[HarmonyPatch(typeof(MeleeWeaponFirstPerson), "SetupMeleeAnimations")]
[HarmonyAfter(new string[] { "Dinorush.MeleeSwingCustomization" })]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void EditKnifeDatablock(MeleeWeaponFirstPerson __instance, MeleeAnimationSetDataBlock data)
{
if (IsKnife(__instance))
{
OverwriteKnifeArchBlock(((ItemEquippable)__instance).MeleeArchetypeData);
Loader.Logger.LogMessage((object)("Modifying animations for " + ((Item)__instance).PublicName));
OverwriteKnifeAnim(__instance);
}
}
private static bool IsKnife(MeleeWeaponFirstPerson melee)
{
if (!((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[4].m_data.m_name.Equals("Knife_Hit"))
{
return false;
}
if (((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[4].m_data.m_attackHitTime < 0.16f)
{
return false;
}
if (!((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[3].m_data.m_name.Equals("Knife_Hit2"))
{
return false;
}
if (((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[3].m_data.m_attackHitTime < 0.16f)
{
return false;
}
if (!((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[10].m_data.m_name.Equals("Knife_ChargeupRelease"))
{
return false;
}
if (((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[10].m_data.m_attackHitTime < 0.16f)
{
return false;
}
if (((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[10].m_data.m_damageStartTime > 0f)
{
return false;
}
if (!((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[8].m_data.m_name.Equals("Knife_ChargeupRelease2"))
{
return false;
}
if (((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[8].m_data.m_attackHitTime < 0.16f)
{
return false;
}
if (((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[8].m_data.m_damageStartTime > 0f)
{
return false;
}
return true;
}
private static void OverwriteKnifeArchBlock(MeleeArchetypeDataBlock archBlock)
{
uint persistentID = ((GameDataBlockBase<MeleeArchetypeDataBlock>)(object)archBlock).persistentID;
if (!ModifiedSpheres.TryGetValue(persistentID, out var value) || value != archBlock.AttackSphereRadius)
{
Loader.Logger.LogMessage((object)("Modifying archetype block. Name: " + ((GameDataBlockBase<MeleeArchetypeDataBlock>)(object)archBlock).name + ", ID: " + persistentID));
float num = Math.Min(1f, Math.Max(0f, (archBlock.AttackSphereRadius + -0.1f) / 0.15f));
archBlock.CameraDamageRayLength += num * 0.25f;
archBlock.AttackSphereRadius += num * -0.1f;
ModifiedSpheres[persistentID] = archBlock.AttackSphereRadius;
}
}
private static void OverwriteKnifeAnim(MeleeWeaponFirstPerson melee)
{
MeleeAttackData data = ((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[4].m_data;
data.m_attackHitTime = 0.1167f;
data.m_attackCamFwdHitTime = 0.1167f;
data.m_comboEarlyTime = 0.4667f;
MeleeAttackData data2 = ((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[3].m_data;
data2.m_attackHitTime = 0.1167f;
data2.m_attackCamFwdHitTime = 0.1167f;
data2.m_comboEarlyTime = 0.4667f;
MeleeAttackData data3 = ((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[6].m_data;
data3.m_attackHitTime = 0.1167f;
data3.m_comboEarlyTime = 0.3333f;
MeleeAttackData data4 = ((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[5].m_data;
data4.m_attackHitTime = 0.1167f;
data4.m_comboEarlyTime = 0.3333f;
MeleeAttackData data5 = ((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[10].m_data;
data5.m_attackHitTime = 0.1f;
data5.m_damageStartTime = 0.08f;
data5.m_attackCamFwdHitTime = 0.1f;
MeleeAttackData data6 = ((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[8].m_data;
data6.m_attackHitTime = 0.1f;
data6.m_damageStartTime = 0.0667f;
data6.m_attackCamFwdHitTime = 0.1f;
((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[12].m_data.m_comboEarlyTime = 0.3333f;
((Il2CppArrayBase<MWS_Base>)(object)melee.m_states)[11].m_data.m_comboEarlyTime = 0.3333f;
}
}
[BepInPlugin("Dinorush.KnifeFix", "KnifeFix", "1.3.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal sealed class Loader : BasePlugin
{
public const string MODNAME = "KnifeFix";
public static ManualLogSource Logger;
public override void Load()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BasePlugin)this).Log;
((BasePlugin)this).Log.LogMessage((object)"Loading KnifeFix");
new Harmony("KnifeFix").PatchAll(typeof(KnifePatch));
((BasePlugin)this).Log.LogMessage((object)"Loaded KnifeFix");
}
}
internal static class MWCWrapper
{
public const string GUID = "Dinorush.MeleeSwingCustomization";
public static bool HasMWC { get; }
static MWCWrapper()
{
HasMWC = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("Dinorush.MeleeSwingCustomization");
}
}
}