Decompiled source of KnifeFix v1.2.0

KnifeFix.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
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+d4fd95f157a8a8bd66e1e270fb5923d3783bc695")]
[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 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")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void EditKnifeDatablock(MeleeWeaponFirstPerson __instance, MeleeAnimationSetDataBlock data)
		{
			if (IsKnife(__instance))
			{
				Loader.Logger.LogMessage((object)("Modifying " + ((Item)__instance).PublicName + " archetype block."));
				OverwriteKnifeArchBlock(((ItemEquippable)__instance).MeleeArchetypeData);
				Loader.Logger.LogMessage((object)("Modifying " + ((GameDataBlockBase<MeleeAnimationSetDataBlock>)(object)data).name + " animations."));
				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)
		{
			float num = Math.Min(1f, Math.Max(0f, (archBlock.AttackSphereRadius + -0.1f) / 0.15f));
			archBlock.CameraDamageRayLength += num * 0.25f;
			archBlock.AttackSphereRadius += num * -0.1f;
		}

		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.1.0")]
	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");
		}
	}
}