Decompiled source of Parry v1.1.0

BepInEx/plugins/Parry/Parry.dll

Decompiled 2 months ago
#define DEBUG
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Parry")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6efa9d9c35c664ad60fa9993eaea01f34f514a38")]
[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)));
		}
	}
	internal enum ParryType
	{
		Tentacle,
		Projectile,
		Bullet
	}
	[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;

		public static float parryFriendlyBulletMulti;

		private static float shoveTime;

		private static bool SuccessfullyParry(Agent damagingAgent, float damageTaken, ParryType parried)
		{
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Expected O, but got Unknown
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: 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);
			Vector3 val2;
			RaycastHit rayHit;
			switch (parried)
			{
			case ParryType.Tentacle:
				if (SNet.IsMaster)
				{
					localPlayerAgent.GiveHealth(localPlayerAgent, damageTaken * parryHealMulti);
				}
				else
				{
					localPlayerAgent.GiveHealth(localPlayerAgent, damageTaken * parryHealMulti + damageTaken);
				}
				localPlayerAgent.GiveAmmoRel(localPlayerAgent, damageTaken * parryMainAmmoMulti / 5f, damageTaken * parrySpecAmmoMulti / 5f, damageTaken * parryToolMulti / 5f);
				if ((Object)(object)damagingAgent != (Object)null)
				{
					DoExplosionDamage(damagingAgent.Position, parryExplosionRadius, parryExplosionDamage, 1500f);
				}
				break;
			case ParryType.Projectile:
			{
				if (SNet.IsMaster)
				{
					localPlayerAgent.GiveHealth(localPlayerAgent, damageTaken * parryHealMulti);
				}
				else
				{
					localPlayerAgent.GiveHealth(localPlayerAgent, damageTaken * parryHealMulti + damageTaken);
				}
				localPlayerAgent.GiveAmmoRel(localPlayerAgent, damageTaken * parryMainAmmoMulti / 5f, damageTaken * parrySpecAmmoMulti / 5f, damageTaken * parryToolMulti / 5f);
				WeaponHitData val3 = new WeaponHitData
				{
					randomSpread = 0f,
					maxRayDist = 100f
				};
				Vector3 position2 = localPlayerAgent.FPSCamera.Position;
				WeaponHitData obj2 = val3;
				val2 = localPlayerAgent.FPSCamera.CameraRayPos - position2;
				obj2.fireDir = ((Vector3)(ref val2)).normalized;
				val3.owner = localPlayerAgent;
				val3.damage = parryBulletDamage;
				val3.staggerMulti = parryBulletStaggerMultiplier;
				val3.precisionMulti = parryBulletPrecisionMultiplier;
				val3.damageFalloff = new Vector2(parryBulletFalloffStart, parryBulletFalloffEnd);
				if (Weapon.CastWeaponRay(((Component)localPlayerAgent.FPSCamera).transform, ref val3, position2, -1))
				{
					BulletWeapon.BulletHit(val3, true, 0f, 0u, true);
					rayHit = val3.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(val3.fireDir));
				break;
			}
			case ParryType.Bullet:
			{
				if (!SNet.IsMaster)
				{
					localPlayerAgent.GiveHealth(localPlayerAgent, damageTaken);
				}
				WeaponHitData val = new WeaponHitData
				{
					randomSpread = 0f,
					maxRayDist = 100f
				};
				Vector3 position = localPlayerAgent.FPSCamera.Position;
				WeaponHitData obj = val;
				val2 = localPlayerAgent.FPSCamera.CameraRayPos - position;
				obj.fireDir = ((Vector3)(ref val2)).normalized;
				val.owner = localPlayerAgent;
				val.damage = damageTaken * 50f * parryFriendlyBulletMulti;
				Logger.DebugOnly(val.damage);
				val.staggerMulti = 1f;
				val.precisionMulti = 2f;
				val.damageFalloff = new Vector2(80f, 100f);
				if (Weapon.CastWeaponRay(((Component)localPlayerAgent.FPSCamera).transform, ref val, position, -1))
				{
					BulletWeapon.BulletHit(val, true, 0f, 0u, true);
					rayHit = val.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(val.fireDir));
				break;
			}
			}
			return false;
		}

		public static void DoExplosionDamage(Vector3 sourcePos, float radius, float damage, float explosionForce)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			Logger.DebugOnly("Doing custom explosion damage.");
			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_PlayerDamageBase>()) || Object.op_Implicit((Object)(object)((Component)val).GetComponent<Dam_PlayerDamageLimb>()))
				{
					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();
				Logger.DebugOnly("baseDam: " + ((object)baseDamagable)?.ToString() + " baseDam.TempSearchID: " + ((baseDamagable != null) ? new uint?(baseDamagable.TempSearchID) : null) + " searchID: " + DamageUtil.SearchID);
				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)
		{
			Logger.DebugOnly("Received shooter projectile damage.");
			float time = Clock.Time;
			if (time > shoveTime && time - shoveTime < 0.3f)
			{
				return SuccessfullyParry(null, ((UFloat16)(ref data.damage)).Get(1f), ParryType.Projectile);
			}
			return true;
		}

		[HarmonyPatch(typeof(Dam_PlayerDamageLocal), "ReceiveTentacleAttackDamage")]
		[HarmonyPrefix]
		public static bool ParryTentacleAttackDamage(pMediumDamageData data)
		{
			Logger.DebugOnly("Received tentacle attack damage.");
			float time = Clock.Time;
			if (time > shoveTime && time - shoveTime < 0.3f)
			{
				Agent damagingAgent = default(Agent);
				((pAgent)(ref data.source)).TryGet(ref damagingAgent);
				return SuccessfullyParry(damagingAgent, ((UFloat16)(ref data.damage)).Get(1f), ParryType.Tentacle);
			}
			return true;
		}

		[HarmonyPatch(typeof(Dam_PlayerDamageLocal), "ReceiveBulletDamage")]
		[HarmonyPrefix]
		public static bool ParryBulletAttackDamage(pBulletDamageData data)
		{
			Logger.DebugOnly("Received bullet attack damage.");
			float time = Clock.Time;
			if (time > shoveTime && time - shoveTime < 0.3f)
			{
				return SuccessfullyParry(null, ((UFloat16)(ref data.damage)).Get(1f), ParryType.Bullet);
			}
			return true;
		}

		[HarmonyPatch(typeof(Dam_PlayerDamageLocal), "ReceiveSetDead")]
		[HarmonyPrefix]
		public static bool ParrySetDead()
		{
			Logger.DebugOnly("Received set dead.");
			float time = Clock.Time;
			if (time > shoveTime && time - shoveTime < 0.3f)
			{
				return false;
			}
			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_0023: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			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;
			Patch.parryFriendlyBulletMulti = val.Bind<float>("OnParry", "parryFriendlyBulletMulti", 4f, "The damage multiplier for the bullet produced by parrying someone else's bullet.\n(Default value multiplies damage by 4.)").Value;
		}
	}
}