Decompiled source of All Undodgeable Bullets v1.0.1

AllUndodgeableBulletsBIE.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AllUndodgeableBulletsBIE")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AllUndodgeableBulletsBIE")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f301fcac-e641-4f73-9242-5de36aff571e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace AllUndodgeableBulletsBIE;

[BepInPlugin("spapi.etg.allundodgeablebullets", "All Undodgeable Bullets", "1.0.0")]
[HarmonyPatch]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "spapi.etg.allundodgeablebullets";

	public const string NAME = "All Undodgeable Bullets";

	public const string VERSION = "1.0.0";

	public static bool undodgeablemode;

	public void Awake()
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		ETGModConsole.CommandDescriptions["undodgeablemode"] = "Toggles All Undodgeable Bullets mode.";
		ETGModConsole.Commands.AddUnit("undodgeablemode", (Action<string[]>)delegate
		{
			undodgeablemode = !undodgeablemode;
			if (undodgeablemode)
			{
				ETGModConsole.Log((object)"All Undodgeable Bullets mode enabled.", false);
				List<string> list = new List<string> { "Good luck beating dragun with that on.", "You can go unbind your dodgeroll key now.", "You're lucky that this doesn't work on beams.", "Why?", "Can you beat this mode? I don't think you can." };
				ETGModConsole.Log((object)BraveUtility.RandomElement<string>(list), false);
			}
			else
			{
				ETGModConsole.Log((object)"All Undodgeable Bullets mode disabled.", false);
			}
		});
		new Harmony("spapi.etg.allundodgeablebullets").PatchAll();
	}

	[HarmonyPatch(typeof(Projectile), "OnPreCollision")]
	[HarmonyPrefix]
	public static bool PreCollision(Projectile __instance, SpeculativeRigidbody otherRigidbody)
	{
		if (undodgeablemode && ((Object)(object)__instance.Owner == (Object)null || !(__instance.Owner is PlayerController)))
		{
			if ((Object)(object)otherRigidbody == (Object)(object)__instance.Shooter && !__instance.allowSelfShooting)
			{
				PhysicsEngine.SkipCollision = true;
				return false;
			}
			if ((Object)(object)((BraveBehaviour)otherRigidbody).gameActor != (Object)null && ((BraveBehaviour)otherRigidbody).gameActor is PlayerController && (!__instance.collidesWithPlayer || ((PlayerController)/*isinst with value type is only supported in some contexts*/).IsGhost || ((PlayerController)/*isinst with value type is only supported in some contexts*/).IsEthereal))
			{
				PhysicsEngine.SkipCollision = true;
				return false;
			}
			if (Object.op_Implicit((Object)(object)((BraveBehaviour)otherRigidbody).aiActor))
			{
				if (__instance.Owner is PlayerController && !((BraveBehaviour)otherRigidbody).aiActor.IsNormalEnemy)
				{
					PhysicsEngine.SkipCollision = true;
					return false;
				}
				if (__instance.Owner is AIActor && !__instance.collidesWithEnemies && ((BraveBehaviour)otherRigidbody).aiActor.IsNormalEnemy && !((BraveBehaviour)otherRigidbody).aiActor.HitByEnemyBullets)
				{
					PhysicsEngine.SkipCollision = true;
					return false;
				}
			}
			if (!GameManager.PVP_ENABLED && __instance.Owner is PlayerController && (Object)(object)((Component)otherRigidbody).GetComponent<PlayerController>() != (Object)null && !__instance.allowSelfShooting)
			{
				PhysicsEngine.SkipCollision = true;
				return false;
			}
			if (GameManager.Instance.InTutorial)
			{
				PlayerController component = ((Component)otherRigidbody).GetComponent<PlayerController>();
				if (Object.op_Implicit((Object)(object)component))
				{
					if (((BraveBehaviour)component).spriteAnimator.QueryInvulnerabilityFrame())
					{
						GameManager.BroadcastRoomTalkDoerFsmEvent("playerDodgedBullet");
					}
					else if (component.IsDodgeRolling)
					{
						GameManager.BroadcastRoomTalkDoerFsmEvent("playerAlmostDodgedBullet");
					}
					else
					{
						GameManager.BroadcastRoomTalkDoerFsmEvent("playerDidNotDodgeBullet");
					}
				}
			}
			if (__instance.collidesWithProjectiles && __instance.collidesOnlyWithPlayerProjectiles && Object.op_Implicit((Object)(object)((BraveBehaviour)otherRigidbody).projectile) && !(((BraveBehaviour)otherRigidbody).projectile.Owner is PlayerController))
			{
				PhysicsEngine.SkipCollision = true;
				return false;
			}
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Projectile), "HandleDamage")]
	[HarmonyPrefix]
	public static bool HandleDamage(Projectile __instance, ref HandleDamageResult __result, SpeculativeRigidbody rigidbody, PixelCollider hitPixelCollider, ref bool killedTarget, PlayerController player, bool alreadyPlayerDelayed)
	{
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		if (undodgeablemode && ((Object)(object)__instance.Owner == (Object)null || !(__instance.Owner is PlayerController)))
		{
			killedTarget = false;
			if (rigidbody.ReflectProjectiles)
			{
				__result = (HandleDamageResult)0;
				return false;
			}
			if (!Object.op_Implicit((Object)(object)((BraveBehaviour)rigidbody).healthHaver))
			{
				__result = (HandleDamageResult)0;
				return false;
			}
			if (!alreadyPlayerDelayed && Projectile.s_delayPlayerDamage && Object.op_Implicit((Object)(object)player))
			{
				__result = (HandleDamageResult)1;
				return false;
			}
			bool flag = !((BraveBehaviour)rigidbody).healthHaver.IsDead;
			float num = __instance.ModifiedDamage;
			if (__instance.Owner is AIActor && Object.op_Implicit((Object)(object)rigidbody) && Object.op_Implicit((Object)(object)((BraveBehaviour)rigidbody).aiActor) && ((AIActor)/*isinst with value type is only supported in some contexts*/).IsNormalEnemy)
			{
				num = ProjectileData.FixedFallbackDamageToEnemies;
				if (((BraveBehaviour)rigidbody).aiActor.HitByEnemyBullets)
				{
					num /= 4f;
				}
			}
			int healthHaverHitCount = __instance.m_healthHaverHitCount;
			if (__instance.Owner is PlayerController && __instance.m_hasPierced && healthHaverHitCount >= 1)
			{
				int num2 = Mathf.Clamp(healthHaverHitCount - 1, 0, GameManager.Instance.PierceDamageScaling.Length - 1);
				num *= GameManager.Instance.PierceDamageScaling[num2];
			}
			if (__instance.OnWillKillEnemy != null && num >= ((BraveBehaviour)rigidbody).healthHaver.GetCurrentHealth())
			{
				__instance.OnWillKillEnemy(__instance, rigidbody);
			}
			if (((BraveBehaviour)rigidbody).healthHaver.IsBoss)
			{
				num *= __instance.BossDamageMultiplier;
			}
			if (__instance.BlackPhantomDamageMultiplier != 1f && Object.op_Implicit((Object)(object)((BraveBehaviour)rigidbody).aiActor) && ((BraveBehaviour)rigidbody).aiActor.IsBlackPhantom)
			{
				num *= __instance.BlackPhantomDamageMultiplier;
			}
			bool flag2 = false;
			if (__instance.DelayedDamageToExploders)
			{
				flag2 = Object.op_Implicit((Object)(object)((Component)rigidbody).GetComponent<ExplodeOnDeath>()) && ((BraveBehaviour)rigidbody).healthHaver.GetCurrentHealth() <= num;
			}
			if (!flag2)
			{
				HealthHaver healthHaver = ((BraveBehaviour)rigidbody).healthHaver;
				float num3 = num;
				Vector2 velocity = ((BraveBehaviour)__instance).specRigidbody.Velocity;
				string ownerName = __instance.OwnerName;
				CoreDamageTypes damageTypes = __instance.damageTypes;
				DamageCategory val = (DamageCategory)(__instance.IsBlackBullet ? 4 : 0);
				healthHaver.ApplyDamage(num3, velocity, ownerName, damageTypes, val, true, hitPixelCollider, __instance.ignoreDamageCaps);
				if (Object.op_Implicit((Object)(object)player) && player.OnHitByProjectile != null)
				{
					player.OnHitByProjectile(__instance, player);
				}
			}
			else
			{
				((MonoBehaviour)rigidbody).StartCoroutine(__instance.HandleDelayedDamage(rigidbody, num, ((BraveBehaviour)__instance).specRigidbody.Velocity, hitPixelCollider));
			}
			if (Object.op_Implicit((Object)(object)__instance.Owner) && __instance.Owner is AIActor && Object.op_Implicit((Object)(object)player))
			{
				GameActor owner = __instance.Owner;
				((AIActor)((owner is AIActor) ? owner : null)).HasDamagedPlayer = true;
			}
			killedTarget = flag && ((BraveBehaviour)rigidbody).healthHaver.IsDead;
			if (!killedTarget && (Object)(object)((BraveBehaviour)rigidbody).gameActor != (Object)null)
			{
				if (__instance.AppliesPoison && Random.value < __instance.PoisonApplyChance)
				{
					((BraveBehaviour)rigidbody).gameActor.ApplyEffect((GameActorEffect)(object)__instance.healthEffect, 1f, (Projectile)null);
				}
				if (__instance.AppliesSpeedModifier && Random.value < __instance.SpeedApplyChance)
				{
					((BraveBehaviour)rigidbody).gameActor.ApplyEffect((GameActorEffect)(object)__instance.speedEffect, 1f, (Projectile)null);
				}
				if (__instance.AppliesCharm && Random.value < __instance.CharmApplyChance)
				{
					((BraveBehaviour)rigidbody).gameActor.ApplyEffect((GameActorEffect)(object)__instance.charmEffect, 1f, (Projectile)null);
				}
				if (__instance.AppliesFreeze && Random.value < __instance.FreezeApplyChance)
				{
					((BraveBehaviour)rigidbody).gameActor.ApplyEffect((GameActorEffect)(object)__instance.freezeEffect, 1f, (Projectile)null);
				}
				if (__instance.AppliesCheese && Random.value < __instance.CheeseApplyChance)
				{
					((BraveBehaviour)rigidbody).gameActor.ApplyEffect((GameActorEffect)(object)__instance.cheeseEffect, 1f, (Projectile)null);
				}
				if (__instance.AppliesBleed && Random.value < __instance.BleedApplyChance)
				{
					((BraveBehaviour)rigidbody).gameActor.ApplyEffect((GameActorEffect)(object)__instance.bleedEffect, -1f, __instance);
				}
				if (__instance.AppliesFire && Random.value < __instance.FireApplyChance)
				{
					((BraveBehaviour)rigidbody).gameActor.ApplyEffect((GameActorEffect)(object)__instance.fireEffect, 1f, (Projectile)null);
				}
				if (Object.op_Implicit((Object)(object)__instance) && Random.value < __instance.StunApplyChance && Object.op_Implicit((Object)(object)((BraveBehaviour)((BraveBehaviour)rigidbody).gameActor).behaviorSpeculator))
				{
					((BraveBehaviour)((BraveBehaviour)rigidbody).gameActor).behaviorSpeculator.Stun(__instance.AppliedStunDuration, true);
				}
				for (int i = 0; i < __instance.statusEffectsToApply.Count; i++)
				{
					((BraveBehaviour)rigidbody).gameActor.ApplyEffect(__instance.statusEffectsToApply[i], 1f, (Projectile)null);
				}
			}
			__instance.m_healthHaverHitCount++;
			__result = (HandleDamageResult)((!killedTarget) ? 1 : 2);
			return false;
		}
		return true;
	}
}