Decompiled source of BulletFalloffQoL v1.0.0

BulletQoL.dll

Decompiled 6 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BulletQoL")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BulletQoL")]
[assembly: AssemblyTitle("BulletQoL")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BulletFalloffQoL;

[BepInPlugin("com.rob.BulletFalloffQoL", "BulletFalloffQoL", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string MODUID = "com.rob.BulletFalloffQoL";

	public static GameObject doubleTapImpactEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Commando/HitsparkCommando.prefab").WaitForCompletion();

	public static GameObject suppressiveFireImpactEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Junk/Commando/HitsparkCommandoBarrage.prefab").WaitForCompletion();

	public static GameObject commandoFMJImpactEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Junk/Commando/HitsparkCommandoFMJ.prefab").WaitForCompletion();

	public GameObject phaseBlastImpactEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Commando/HitsparkCommandoShotgun.prefab").WaitForCompletion();

	public static GameObject nailgunImpactEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Toolbot/ImpactNailgun.prefab").WaitForCompletion();

	public static GameObject banditImpactEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Bandit2/HitsparkBandit.prefab").WaitForCompletion();

	public static GameObject captainShotgunImpactEffect = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Captain/HitsparkCaptainShotgun.prefab").WaitForCompletion();

	private const float sweetspotScale = 2.5f;

	private void Awake()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		BulletAttack.DefaultHitCallbackImplementation += new hook_DefaultHitCallbackImplementation(BulletAttack_DefaultHitCallbackImplementation);
		doubleTapImpactEffect.GetComponent<EffectComponent>().applyScale = true;
		suppressiveFireImpactEffect.GetComponent<EffectComponent>().applyScale = true;
		commandoFMJImpactEffect.GetComponent<EffectComponent>().applyScale = true;
		phaseBlastImpactEffect.GetComponent<EffectComponent>().applyScale = true;
		nailgunImpactEffect.GetComponent<EffectComponent>().applyScale = true;
		banditImpactEffect.GetComponent<EffectComponent>().applyScale = true;
		captainShotgunImpactEffect.GetComponent<EffectComponent>().applyScale = true;
	}

	private bool BulletAttack_DefaultHitCallbackImplementation(orig_DefaultHitCallbackImplementation orig, BulletAttack bulletAttack, ref BulletHit hitInfo)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Invalid comparison between Unknown and I4
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Invalid comparison between Unknown and I4
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: 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_0178: 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)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: 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_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_0391: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03be: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0436: Unknown result type (might be due to invalid IL or missing references)
		//IL_0456: Unknown result type (might be due to invalid IL or missing references)
		//IL_045d: Unknown result type (might be due to invalid IL or missing references)
		//IL_047d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_0495: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0548: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0563: Unknown result type (might be due to invalid IL or missing references)
		//IL_0556: Unknown result type (might be due to invalid IL or missing references)
		//IL_055b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0505: Unknown result type (might be due to invalid IL or missing references)
		//IL_051c: Unknown result type (might be due to invalid IL or missing references)
		//IL_050f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0514: Unknown result type (might be due to invalid IL or missing references)
		//IL_0521: Unknown result type (might be due to invalid IL or missing references)
		//IL_0526: Unknown result type (might be due to invalid IL or missing references)
		//IL_052b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0538: Expected O, but got Unknown
		GameObject val = null;
		if (Object.op_Implicit((Object)(object)bulletAttack.hitEffectPrefab))
		{
			val = bulletAttack.hitEffectPrefab;
			bulletAttack.hitEffectPrefab = null;
		}
		float num = CalcFalloffFactor(bulletAttack.falloffModel, hitInfo.distance);
		if ((num <= 0.5f && (int)bulletAttack.falloffModel == 1) || (num <= 0.25f && (int)bulletAttack.falloffModel == 2))
		{
			bulletAttack.damageColorIndex = (DamageColorIndex)3;
		}
		bool result = orig.Invoke(bulletAttack, ref hitInfo);
		if (Object.op_Implicit((Object)(object)val))
		{
			float num2 = 1f;
			if (num >= 1f)
			{
				num2 = 2.5f;
			}
			if ((Object)(object)val == (Object)(object)doubleTapImpactEffect)
			{
				((Component)doubleTapImpactEffect.transform.GetChild(0).GetChild(1)).transform.localScale = Vector3.one * num2;
				((Component)doubleTapImpactEffect.transform.GetChild(0).GetChild(2)).transform.localScale = Vector3.one * num2;
				EffectManager.SimpleImpactEffect(doubleTapImpactEffect, hitInfo.point, bulletAttack.HitEffectNormal ? hitInfo.surfaceNormal : (-hitInfo.direction), true);
				return result;
			}
			if ((Object)(object)val == (Object)(object)suppressiveFireImpactEffect)
			{
				((Component)suppressiveFireImpactEffect.transform.GetChild(0)).transform.localScale = Vector3.one * num2;
				((Component)suppressiveFireImpactEffect.transform.GetChild(1)).transform.localScale = Vector3.one * num2;
				((Component)suppressiveFireImpactEffect.transform.GetChild(2)).transform.localScale = Vector3.one * num2;
				((Component)suppressiveFireImpactEffect.transform.GetChild(3)).transform.localScale = Vector3.one * num2;
				EffectManager.SimpleImpactEffect(suppressiveFireImpactEffect, hitInfo.point, bulletAttack.HitEffectNormal ? hitInfo.surfaceNormal : (-hitInfo.direction), true);
				return result;
			}
			if ((Object)(object)val == (Object)(object)phaseBlastImpactEffect)
			{
				((Component)phaseBlastImpactEffect.transform.GetChild(0)).transform.localScale = Vector3.one * num2;
				((Component)phaseBlastImpactEffect.transform.GetChild(2)).transform.localScale = Vector3.one * num2;
				EffectManager.SimpleImpactEffect(phaseBlastImpactEffect, hitInfo.point, bulletAttack.HitEffectNormal ? hitInfo.surfaceNormal : (-hitInfo.direction), true);
				return result;
			}
			if ((Object)(object)val == (Object)(object)nailgunImpactEffect)
			{
				((Component)nailgunImpactEffect.transform.GetChild(0)).transform.localScale = Vector3.one * num2;
				((Component)nailgunImpactEffect.transform.GetChild(1)).transform.localScale = Vector3.one * num2;
				EffectManager.SimpleImpactEffect(nailgunImpactEffect, hitInfo.point, bulletAttack.HitEffectNormal ? hitInfo.surfaceNormal : (-hitInfo.direction), true);
				return result;
			}
			if ((Object)(object)val == (Object)(object)banditImpactEffect)
			{
				((Component)banditImpactEffect.transform.GetChild(0).GetChild(1)).transform.localScale = Vector3.one * num2;
				((Component)banditImpactEffect.transform.GetChild(0).GetChild(2)).transform.localScale = Vector3.one * num2;
				EffectManager.SimpleImpactEffect(banditImpactEffect, hitInfo.point, bulletAttack.HitEffectNormal ? hitInfo.surfaceNormal : (-hitInfo.direction), true);
				return result;
			}
			if ((Object)(object)val == (Object)(object)captainShotgunImpactEffect)
			{
				((Component)captainShotgunImpactEffect.transform.GetChild(0)).transform.localScale = Vector3.one * num2;
				((Component)captainShotgunImpactEffect.transform.GetChild(2)).transform.localScale = Vector3.one * num2;
				((Component)captainShotgunImpactEffect.transform.GetChild(3)).transform.localScale = Vector3.one * num2;
				EffectManager.SimpleImpactEffect(captainShotgunImpactEffect, hitInfo.point, bulletAttack.HitEffectNormal ? hitInfo.surfaceNormal : (-hitInfo.direction), true);
				return result;
			}
			if (num >= 1f)
			{
				EffectComponent component = val.GetComponent<EffectComponent>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.applyScale = true;
				}
				EffectData val2 = new EffectData
				{
					origin = hitInfo.point,
					rotation = Util.QuaternionSafeLookRotation(bulletAttack.HitEffectNormal ? hitInfo.surfaceNormal : (-hitInfo.direction)),
					scale = 2f
				};
				EffectManager.SpawnEffect(val, val2, true);
			}
			else
			{
				EffectManager.SimpleImpactEffect(val, hitInfo.point, bulletAttack.HitEffectNormal ? hitInfo.surfaceNormal : (-hitInfo.direction), true);
			}
		}
		return result;
	}

	private static float CalcFalloffFactor(FalloffModel falloffModel, float distance)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		if ((int)falloffModel != 1)
		{
			if ((int)falloffModel == 2)
			{
				return 0.25f + Mathf.Clamp01(Mathf.InverseLerp(25f, 7f, distance)) * 0.75f;
			}
			return 1f;
		}
		return 0.5f + Mathf.Clamp01(Mathf.InverseLerp(60f, 25f, distance)) * 0.5f;
	}
}