Decompiled source of Parry v1.0.0

BepInEx/plugins/Parry/Parry.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using FX_EffectSystem;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Parry")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+52e590b816d9f37b6d0e23f6e00a5e651b5f4eac")]
[assembly: AssemblyProduct("Parry")]
[assembly: AssemblyTitle("Parry")]
[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 Parry
{
	internal static class Logger
	{
		private static ManualLogSource m_LogSource;

		public static void SetupFromInit(ManualLogSource logSource)
		{
			m_LogSource = logSource;
		}

		private static string Format(object data)
		{
			return data.ToString();
		}

		public static void Debug(object msg)
		{
			m_LogSource.LogDebug((object)Format(msg));
		}

		public static void Info(object msg)
		{
			m_LogSource.LogInfo((object)Format(msg));
		}

		public static void Warn(object msg)
		{
			m_LogSource.LogWarning((object)Format(msg));
		}

		public static void Error(object msg)
		{
			m_LogSource.LogError((object)Format(msg));
		}

		public static void Fatal(object msg)
		{
			m_LogSource.LogFatal((object)Format(msg));
		}

		[Conditional("DEBUG")]
		public static void DebugOnly(object msg)
		{
			m_LogSource.LogInfo((object)("DEBUG: " + Format(msg)));
		}
	}
	[HarmonyPatch]
	internal static class Patch
	{
		private const float PARRYDURATION = 0.3f;

		public static bool parryEnabled = true;

		public static float parryExplosionDamage;

		public static float parryExplosionRadius;

		public static float parryBulletDamage;

		public static float parryBulletPrecisionMultiplier;

		public static float parryBulletStaggerMultiplier;

		public static float parryBulletFalloffStart;

		public static float parryBulletFalloffEnd;

		public static float parryHealMulti;

		public static float parryMainAmmoMulti;

		public static float parrySpecAmmoMulti;

		public static float parryToolMulti;

		private static float shoveTime;

		private static bool SuccessfullyParry(pMediumDamageData damageData, bool isTentacle)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			if (!parryEnabled)
			{
				return true;
			}
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			localPlayerAgent.Sound.Post(1256202815u, true);
			float num = ((UFloat16)(ref damageData.damage)).Get(1f);
			localPlayerAgent.GiveHealth(localPlayerAgent, num * parryHealMulti);
			localPlayerAgent.GiveAmmoRel(localPlayerAgent, num * parryMainAmmoMulti / 5f, num * parrySpecAmmoMulti / 5f, num * parryToolMulti / 5f);
			Agent val = default(Agent);
			((pAgent)(ref damageData.source)).TryGet(ref val);
			if ((Object)(object)val != (Object)null && isTentacle)
			{
				DoExplosionDamage(val.Position, parryExplosionRadius, parryExplosionDamage, 1500f);
			}
			else
			{
				WeaponHitData val2 = new WeaponHitData
				{
					randomSpread = 0f,
					maxRayDist = 100f
				};
				Vector3 position = localPlayerAgent.FPSCamera.Position;
				WeaponHitData obj = val2;
				Vector3 val3 = localPlayerAgent.FPSCamera.CameraRayPos - position;
				obj.fireDir = ((Vector3)(ref val3)).normalized;
				val2.owner = localPlayerAgent;
				val2.damage = parryBulletDamage;
				val2.staggerMulti = parryBulletPrecisionMultiplier;
				val2.precisionMulti = parryBulletStaggerMultiplier;
				val2.damageFalloff = new Vector2(parryBulletFalloffStart, parryBulletFalloffEnd);
				if (Weapon.CastWeaponRay(((Component)localPlayerAgent.FPSCamera).transform, ref val2, position, -1))
				{
					BulletWeapon.BulletHit(val2, true, 0f, 0u, true);
					RaycastHit rayHit = val2.rayHit;
					FX_Manager.EffectTargetPosition = ((RaycastHit)(ref rayHit)).point;
				}
				else
				{
					FX_Manager.EffectTargetPosition = localPlayerAgent.FPSCamera.CameraRayPos;
				}
				FX_Manager.PlayLocalVersion = false;
				((FX_EffectBase)BulletWeapon.s_tracerPool.AquireEffect()).Play((FX_Trigger)null, ((Agent)localPlayerAgent).EyePosition, Quaternion.LookRotation(val2.fireDir));
			}
			return false;
		}

		public static void DoExplosionDamage(Vector3 sourcePos, float radius, float damage, float explosionForce)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.OverlapSphereNonAlloc(sourcePos, radius, DamageUtil.s_tempColliders, LayerManager.MASK_EXPLOSION_TARGETS);
			if (num < 1)
			{
				return;
			}
			DamageUtil.IncrementSearchID();
			RaycastHit val3 = default(RaycastHit);
			for (int i = 0; i < num; i++)
			{
				Collider val = ((Il2CppArrayBase<Collider>)(object)DamageUtil.s_tempColliders)[i];
				if (Object.op_Implicit((Object)(object)((Component)val).GetComponent<Dam_PlayerDamageLocal>()))
				{
					continue;
				}
				Rigidbody component = ((Component)val).GetComponent<Rigidbody>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.AddExplosionForce(explosionForce, sourcePos, radius, 3f);
				}
				IDamageable component2 = ((Component)val).GetComponent<IDamageable>();
				if (component2 == null)
				{
					continue;
				}
				IDamageable baseDamagable = component2.GetBaseDamagable();
				if (baseDamagable != null && baseDamagable.TempSearchID != DamageUtil.SearchID)
				{
					Vector3 val2 = component2.DamageTargetPos - sourcePos;
					if (!Physics.Raycast(sourcePos, ((Vector3)(ref val2)).normalized, ref val3, ((Vector3)(ref val2)).magnitude, LayerManager.MASK_EXPLOSION_BLOCKERS) || (Object)(object)((RaycastHit)(ref val3)).collider == (Object)(object)val)
					{
						baseDamagable.TempSearchID = DamageUtil.SearchID;
						component2.ExplosionDamage(damage, sourcePos, Vector3.up * explosionForce, 0u);
					}
				}
			}
		}

		[HarmonyPatch(typeof(MWS_Push), "Enter")]
		[HarmonyPostfix]
		public static void ParryEnter()
		{
			shoveTime = Clock.Time;
		}

		[HarmonyPatch(typeof(Dam_PlayerDamageLocal), "ReceiveShooterProjectileDamage")]
		[HarmonyPrefix]
		public static bool ParryShooterProjectileDamage(pMediumDamageData data)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float time = Clock.Time;
			if (time > shoveTime && time - shoveTime < 0.3f)
			{
				return SuccessfullyParry(data, isTentacle: false);
			}
			return true;
		}

		[HarmonyPatch(typeof(Dam_PlayerDamageLocal), "ReceiveTentacleAttackDamage")]
		[HarmonyPrefix]
		public static bool ParryTentacleAttackDamage(pMediumDamageData data)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float time = Clock.Time;
			if (time > shoveTime && time - shoveTime < 0.3f)
			{
				return SuccessfullyParry(data, isTentacle: true);
			}
			return true;
		}
	}
	[BepInPlugin("CellSkippers.Parry", "Parry", "1.0.0")]
	public class Plugin : BasePlugin
	{
		internal const string AUTHOR = "CellSkippers";

		internal const string MODNAME = "Parry";

		internal const string GUID = "CellSkippers.Parry";

		internal const string VERSION = "1.0.0";

		public override void Load()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Logger.SetupFromInit(((BasePlugin)this).Log);
			Logger.Info("Parry is loading...");
			ReadConfigFile();
			new Harmony("CellSkippers.Parry").PatchAll();
			Logger.Info("Parry loaded!");
		}

		public static void ReadConfigFile()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "CellSkippers.Parry.cfg"), true);
			Patch.parryExplosionDamage = val.Bind<float>("Explosion", "parryExplosionDamage", 100.01f, "The damage of the explosion for parrying tentacles.").Value;
			Patch.parryExplosionRadius = val.Bind<float>("Explosion", "parryExplosionRadius", 2f, "The radius of the explosion for parrying tentacles.").Value;
			Patch.parryBulletDamage = val.Bind<float>("Bullet", "parryBulletDamage", 150.01f, "The damage of the bullet for parrying projectiles.").Value;
			Patch.parryBulletPrecisionMultiplier = val.Bind<float>("Bullet", "parryBulletPrecisionMultiplier", 1f, "The precision multiplier of the bullet for parrying projectiles.").Value;
			Patch.parryBulletStaggerMultiplier = val.Bind<float>("Bullet", "parryBulletStaggerMultiplier", 1f, "The stagger multiplier of the bullet for parrying projectiles.").Value;
			Patch.parryBulletFalloffStart = val.Bind<float>("Bullet", "parryBulletFalloffStart", 40f, "The falloff start distance of the bullet for parrying projectiles.").Value;
			Patch.parryBulletFalloffEnd = val.Bind<float>("Bullet", "parryBulletFalloffEnd", 100f, "The falloff end distance of the bullet for parrying projectiles.").Value;
			Patch.parryHealMulti = val.Bind<float>("OnParry", "parryHealMulti", 1f, "The multiplier for receiving health on a successful parry.\n(Default value gives damage-of-hit percent health.)").Value;
			Patch.parryMainAmmoMulti = val.Bind<float>("OnParry", "parryMainAmmoMulti", 1f, "The multiplier for receiving main ammo on a successful parry.\n(Default value gives damage-of-hit percent of a regular ammo pack.)").Value;
			Patch.parrySpecAmmoMulti = val.Bind<float>("OnParry", "parrySpecAmmoMulti", 1f, "The multiplier for receiving special ammo on a successful parry.\n(Default value gives damage-of-hit percent of a regular ammo pack.)").Value;
			Patch.parryToolMulti = val.Bind<float>("OnParry", "parryToolMulti", 1f, "The multiplier for receiving tool on a successful parry.\n(Default value gives damage-of-hit percent of a regular tool pack.)").Value;
		}
	}
}