diff --git a/Balancing/BalancingConstants.cs b/Balancing/BalancingConstants.cs index 2ea46bc24f..398fda9324 100644 --- a/Balancing/BalancingConstants.cs +++ b/Balancing/BalancingConstants.cs @@ -12,6 +12,12 @@ // Sharpening Station grants this much armor penetration to melee weapons. internal const float SharpeningStationArmorPenetration = 5f; + // Dash cooldowns (in frames) + internal const int UniversalDashCooldown = 30; + internal const int UniversalShieldSlamCooldown = 30; + internal const int UniversalShieldBonkCooldown = 30; + internal const int OnShieldBonkCooldown = 30; + // Vanilla shield slam stats // These are consts because they replace hardcoded values in vanilla internal const int ShieldOfCthulhuBonkNoCollideFrames = 6; diff --git a/CalPlayer/CalamityPlayerDashEffects.cs b/CalPlayer/CalamityPlayerDashEffects.cs index 730aa26cd3..7d58e4ba8d 100644 --- a/CalPlayer/CalamityPlayerDashEffects.cs +++ b/CalPlayer/CalamityPlayerDashEffects.cs @@ -1,7 +1,9 @@ -using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Balancing; +using CalamityMod.Buffs.DamageOverTime; using CalamityMod.CalPlayer.Dashes; using CalamityMod.Cooldowns; using CalamityMod.Dusts; +using CalamityMod.Enums; using CalamityMod.Items.Accessories; using CalamityMod.Items.Armor; using CalamityMod.Items.Mounts; @@ -88,7 +90,6 @@ namespace CalamityMod.CalPlayer if (Player.dashDelay < 0) { - int delay = 30; float dashSpeed = 12f; float dashSpeedDecelerationFactor = 0.985f; float runSpeed = Math.Max(Player.accRunSpeed, Player.maxRunSpeed); @@ -133,7 +134,13 @@ namespace CalamityMod.CalPlayer } } - Player.dashDelay = delay; + // Dash delay depends on the type of dash used. + int dashDelayToApply = BalancingConstants.UniversalDashCooldown; + if (UsedDash.CollisionType == DashCollisionType.ShieldSlam) + dashDelayToApply = BalancingConstants.UniversalShieldSlamCooldown; + else if (UsedDash.CollisionType == DashCollisionType.ShieldBonk) + dashDelayToApply = BalancingConstants.UniversalShieldBonkCooldown; + Player.dashDelay = dashDelayToApply; if (UsedDash.IsOmnidirectional) { diff --git a/CalPlayer/Dashes/AsgardianAegisDash.cs b/CalPlayer/Dashes/AsgardianAegisDash.cs index 3bd54c606d..752de9ed02 100644 --- a/CalPlayer/Dashes/AsgardianAegisDash.cs +++ b/CalPlayer/Dashes/AsgardianAegisDash.cs @@ -1,6 +1,7 @@ using System; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; +using CalamityMod.Enums; using CalamityMod.Items.Accessories; using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; @@ -15,6 +16,7 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Asgardian Aegis"; + public override DashCollisionType CollisionType => DashCollisionType.ShieldSlam; public override bool IsOmnidirectional => false; public override float CalculateDashSpeed(Player player) => 23.3f; diff --git a/CalPlayer/Dashes/AsgardsValorDash.cs b/CalPlayer/Dashes/AsgardsValorDash.cs index 602e973030..e31e67a466 100644 --- a/CalPlayer/Dashes/AsgardsValorDash.cs +++ b/CalPlayer/Dashes/AsgardsValorDash.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Enums; using CalamityMod.Items.Accessories; using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; @@ -13,6 +14,8 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Asgard's Valor"; + public override DashCollisionType CollisionType => DashCollisionType.ShieldSlam; + public override bool IsOmnidirectional => false; public override float CalculateDashSpeed(Player player) => 16.9f; diff --git a/CalPlayer/Dashes/CounterScarfDash.cs b/CalPlayer/Dashes/CounterScarfDash.cs index 9b81b859be..a131bd97ce 100644 --- a/CalPlayer/Dashes/CounterScarfDash.cs +++ b/CalPlayer/Dashes/CounterScarfDash.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Enums; +using Microsoft.Xna.Framework; using Terraria; using Terraria.Graphics.Shaders; @@ -8,6 +9,8 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Counter Scarf"; + public override DashCollisionType CollisionType => DashCollisionType.NoCollision; + public override bool IsOmnidirectional => false; public override float CalculateDashSpeed(Player player) => player.Calamity().evasionScarf ? 16.3f : 15f; diff --git a/CalPlayer/Dashes/DeepDiverDash.cs b/CalPlayer/Dashes/DeepDiverDash.cs index 3e8afc9f4d..4a8f33f43a 100644 --- a/CalPlayer/Dashes/DeepDiverDash.cs +++ b/CalPlayer/Dashes/DeepDiverDash.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Enums; +using Microsoft.Xna.Framework; using Terraria; using Terraria.Graphics.Shaders; @@ -8,6 +9,8 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Deep Diver"; + public override DashCollisionType CollisionType => DashCollisionType.NoCollision; + public override bool IsOmnidirectional => false; public override float CalculateDashSpeed(Player player) => 25.9f; diff --git a/CalPlayer/Dashes/ElysianAegisDash.cs b/CalPlayer/Dashes/ElysianAegisDash.cs index 4f1f1b929a..3db1af4956 100644 --- a/CalPlayer/Dashes/ElysianAegisDash.cs +++ b/CalPlayer/Dashes/ElysianAegisDash.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Enums; using CalamityMod.Items.Accessories; using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; @@ -13,6 +14,8 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Elysian Aegis"; + public override DashCollisionType CollisionType => DashCollisionType.ShieldSlam; + public override bool IsOmnidirectional => false; public override float CalculateDashSpeed(Player player) => 21.5f; diff --git a/CalPlayer/Dashes/GodslayerArmorDash.cs b/CalPlayer/Dashes/GodslayerArmorDash.cs index 04b957d5c2..9bfe4fbb66 100644 --- a/CalPlayer/Dashes/GodslayerArmorDash.cs +++ b/CalPlayer/Dashes/GodslayerArmorDash.cs @@ -1,7 +1,9 @@ using System; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; +using CalamityMod.Enums; using CalamityMod.Items.Armor; +using CalamityMod.NPCs.DevourerofGods; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -9,7 +11,6 @@ using Terraria.DataStructures; using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; -using CalamityMod.NPCs.DevourerofGods; namespace CalamityMod.CalPlayer.Dashes { @@ -17,6 +18,8 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Godslayer Armor"; + public override DashCollisionType CollisionType => DashCollisionType.ShieldSlam; + public override bool IsOmnidirectional => true; public override float CalculateDashSpeed(Player player) => 80f; diff --git a/CalPlayer/Dashes/OrnateShieldDash.cs b/CalPlayer/Dashes/OrnateShieldDash.cs index 4828c1f1f0..51b41e7110 100644 --- a/CalPlayer/Dashes/OrnateShieldDash.cs +++ b/CalPlayer/Dashes/OrnateShieldDash.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Enums; using CalamityMod.Items.Accessories; using Microsoft.Xna.Framework; using Terraria; @@ -13,6 +14,8 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Ornate Shield"; + public override DashCollisionType CollisionType => DashCollisionType.ShieldSlam; + public override bool IsOmnidirectional => false; public override float CalculateDashSpeed(Player player) => 16.9f; diff --git a/CalPlayer/Dashes/PlaguebringerArmorDash.cs b/CalPlayer/Dashes/PlaguebringerArmorDash.cs index 0952cad40f..50ba65437a 100644 --- a/CalPlayer/Dashes/PlaguebringerArmorDash.cs +++ b/CalPlayer/Dashes/PlaguebringerArmorDash.cs @@ -1,11 +1,10 @@ using System; +using CalamityMod.Enums; using CalamityMod.Items.Accessories; -using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; using Terraria.Graphics.Shaders; -using Terraria.ModLoader; namespace CalamityMod.CalPlayer.Dashes { @@ -13,6 +12,8 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Plaguebringer Armor"; + public override DashCollisionType CollisionType => DashCollisionType.NoCollision; + public override bool IsOmnidirectional => false; public override float CalculateDashSpeed(Player player) => 19f; diff --git a/CalPlayer/Dashes/PlayerDashEffect.cs b/CalPlayer/Dashes/PlayerDashEffect.cs index ac57a2365b..4ea5d0a336 100644 --- a/CalPlayer/Dashes/PlayerDashEffect.cs +++ b/CalPlayer/Dashes/PlayerDashEffect.cs @@ -1,4 +1,5 @@ -using Terraria; +using CalamityMod.Enums; +using Terraria; using Terraria.DataStructures; namespace CalamityMod.CalPlayer.Dashes @@ -9,6 +10,8 @@ namespace CalamityMod.CalPlayer.Dashes // Derived classes should use the new keyword on this member to define their own version of it. public static string ID { get; } + public abstract DashCollisionType CollisionType { get; } + public abstract bool IsOmnidirectional { get; } public abstract float CalculateDashSpeed(Player player); diff --git a/CalPlayer/Dashes/StatisBeltOfCursesDash.cs b/CalPlayer/Dashes/StatisBeltOfCursesDash.cs index ac31d545c2..8bc2bcb4c0 100644 --- a/CalPlayer/Dashes/StatisBeltOfCursesDash.cs +++ b/CalPlayer/Dashes/StatisBeltOfCursesDash.cs @@ -1,4 +1,5 @@ -using CalamityMod.Projectiles.Rogue; +using CalamityMod.Enums; +using CalamityMod.Projectiles.Rogue; using Microsoft.Xna.Framework; using Terraria; using Terraria.Graphics.Shaders; @@ -10,6 +11,8 @@ namespace CalamityMod.CalPlayer.Dashes { public static new string ID => "Statis' Belt of Curses"; + public override DashCollisionType CollisionType => DashCollisionType.NoCollision; + public override bool IsOmnidirectional => false; public override float CalculateDashSpeed(Player player) => 25.4f; diff --git a/Enums/DashCollisionType.cs b/Enums/DashCollisionType.cs new file mode 100644 index 0000000000..5c8afda7c7 --- /dev/null +++ b/Enums/DashCollisionType.cs @@ -0,0 +1,9 @@ +namespace CalamityMod.Enums +{ + public enum DashCollisionType + { + NoCollision = 0, + ShieldSlam = 1, + ShieldBonk = 2 + } +} diff --git a/Enums/DashDirection.cs b/Enums/DashDirection.cs index 158cd25ca7..a3f21d89c6 100644 --- a/Enums/DashDirection.cs +++ b/Enums/DashDirection.cs @@ -1,4 +1,4 @@ -namespace CalamityMod +namespace CalamityMod.Enums { public enum DashDirection { diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 736e51ce7d..2b573bcc84 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -35,8 +35,7 @@ namespace CalamityMod.ILEditing IL.Terraria.Main.UpdateTime += PermitNighttimeTownNPCSpawning; On.Terraria.Main.UpdateTime_SpawnTownNPCs += AlterTownNPCSpawnRate; IL.Terraria.Player.Hurt += RemoveRNGFromDodges; - IL.Terraria.Player.DashMovement += BuffSolarFlareShieldSlam; - IL.Terraria.Player.DashMovement += FixModdedDashesResettingDashCountdown; + IL.Terraria.Player.DashMovement += FixAllDashMechanics; IL.Terraria.Player.GiveImmuneTimeForCollisionAttack += MakeShieldSlamIFramesConsistent; IL.Terraria.Player.Update_NPCCollision += NerfShieldOfCthulhuBonkSafety; On.Terraria.WorldGen.OpenDoor += OpenDoor_LabDoorOverride; @@ -127,8 +126,7 @@ namespace CalamityMod.ILEditing IL.Terraria.Main.UpdateTime -= PermitNighttimeTownNPCSpawning; On.Terraria.Main.UpdateTime_SpawnTownNPCs -= AlterTownNPCSpawnRate; IL.Terraria.Player.Hurt -= RemoveRNGFromDodges; - IL.Terraria.Player.DashMovement -= BuffSolarFlareShieldSlam; - IL.Terraria.Player.DashMovement -= FixModdedDashesResettingDashCountdown; + IL.Terraria.Player.DashMovement -= FixAllDashMechanics; IL.Terraria.Player.GiveImmuneTimeForCollisionAttack -= MakeShieldSlamIFramesConsistent; IL.Terraria.Player.Update_NPCCollision -= NerfShieldOfCthulhuBonkSafety; On.Terraria.WorldGen.OpenDoor -= OpenDoor_LabDoorOverride; diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 1a94876180..c3487d60e1 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -47,6 +47,186 @@ namespace CalamityMod.ILEditing // This function is (optionally) invoked manually in an IL edit to enable NPCs to spawn at night. private static Action VanillaSpawnTownNPCs; + #region Dash Fixes and Improvements + private static void MakeShieldSlamIFramesConsistent(ILContext il) + { + var cursor = new ILCursor(il); + + // Find the direct assignment of the player's iframes. + if (!cursor.TryGotoNext(MoveType.AfterLabel, i => i.MatchStfld("immuneTime"))) + { + LogFailure("Shield Slam Consistent Immunity Frames", "Could not locate the assignment of the player's immune time."); + return; + } + + // Delete this instruction. The stack still contains the player and amount of iframes to give. + cursor.Remove(); + + // Emit a delegate which calls the Calamity utility to consistently provide iframes. + cursor.EmitDelegate>((p, frames) => CalamityUtils.GiveIFrames(p, frames, false)); + } + + private static readonly Func CalamityDashEquipped = (Player p) => p.Calamity().HasCustomDash ? 1 : 0; + + private static void FixAllDashMechanics(ILContext il) + { + var cursor = new ILCursor(il); + + // + // FIX DASH COOLDOWN RESET FOR CALAMITY DASHES + // + + // Vanilla resets dash cooldown if no vanilla dash is equipped. Calamity dashes must also be considered. + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdfld("dash"))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate the check for vanilla dash ID."); + return; + } + + // Load the player itself onto the stack so that it becomes an argument for the following delegate. + cursor.Emit(OpCodes.Ldarg_0); + + // Emit a delegate which places whether the player has a Calamity dash equipped onto the stack. + cursor.EmitDelegate>(CalamityDashEquipped); + + // Bitwise OR the two values together. This will only return zero if both values were zero. + // This will occur precisely when the player has no vanilla OR Calamity dash items equipped. + cursor.Emit(OpCodes.Or); + + // + // SHIELD OF CTHULHU + // + + // Move to Shield of Cthulhu's code by finding its function call for iframes. + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchCall("GiveImmuneTimeForCollisionAttack"))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate function call for Shield of Cthulhu iframes."); + return; + } + + if (!cursor.TryGotoPrev(MoveType.AfterLabel, i => i.MatchLdcI4(30))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate amount of frames of dash cooldown applied on impact with Shield of Cthulhu."); + return; + } + + // Remove the instruction and replace it with one which gives Calamity's (customizable) amount of dash cooldown. + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, BalancingConstants.OnShieldBonkCooldown); + + // + // SOLAR FLARE ARMOR + // + + // Move onto the next dash (Solar Flare set bonus) by looking for the base damage of the direct contact strike. + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(150f))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate Solar Flare Armor shield slam base damage."); + return; + } + + // Replace vanilla's base damage of 150 with Calamity's custom base damage. + cursor.Next.Operand = BalancingConstants.SolarFlareBaseDamage; + + // Now that the new base damage has been applied to the direct contact strike, also apply it to the Solar Counter projectile. + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(150))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate Solar Flare Armor \"Solar Counter\" base damage."); + return; + } + + // Replace vanilla's flat 150 damage (doesn't even scale with melee stats!) with the already-calculated base damage, then cast it to int. + cursor.Remove(); + cursor.Emit(OpCodes.Ldloc, 13); + cursor.Emit(OpCodes.Conv_I4); + + // Move to the immunity frame setting code for the Solar Flare set bonus. Find the constant 4 given as iframes. + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(4))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate Solar Flare shield slam iframes."); + return; + } + + // Replace it with Calamity's number of iframes. + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, BalancingConstants.SolarFlareIFrames); + + // + // DASH COOLDOWNS + // + + // Move to the dash cooldown code by finding the location where the dash cooldown local variable is initialized. + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchStloc(22))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate default dash cooldown initialization."); + return; + } + + // The instruction right before this is Ldc.I4 20, so replace its operand directly. + // This is the default, so set it to the default universal dash cooldown. + cursor.Previous.Operand = BalancingConstants.UniversalDashCooldown; + + // dash == 1 (aka Tabi) uses the default cooldown and thus does not need edits. + + // Same thing as last time, but this time it's the cooldown for dash == 2 (aka Shield of Cthulhu). + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchStloc(22))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate dash cooldown assignment for Shield of Cthulhu."); + return; + } + + // The instruction right before this is Ldc.I4 30, so replace its operand directly. + // This is for Shield of Cthulhu, so set it to the shield bonk cooldown. + cursor.Previous.Operand = BalancingConstants.UniversalShieldBonkCooldown; + + // Same thing as last time, but this time it's the cooldown for dash == 3 (aka Solar Flare Armor). + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchStloc(22))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate dash cooldown assignment for Solar Flare Armor."); + return; + } + + // The instruction right before this is Ldc.I4 30, so replace its operand directly. + // This is for Solar Flare Armor, so set it to the shield slam cooldown. + cursor.Previous.Operand = BalancingConstants.UniversalShieldSlamCooldown; + + // Same thing as last time, but this time it's the cooldown for dash == 4 (?????). + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchStloc(22))) + { + LogFailure("Vanilla Dash Fixes", "Could not locate dash cooldown assignment for UNKNOWN DASH ID 4."); + return; + } + + // The instruction right before this is Ldc.I4 20, so replace its operand directly. + cursor.Previous.Operand = BalancingConstants.UniversalDashCooldown; + + // dash == 5 (aka Crystal Assassin Armor) uses the default cooldown and thus does not need edits. + } + + private static void NerfShieldOfCthulhuBonkSafety(ILContext il) + { + // Reduce the number of "no-collide frames" (they are NOT iframes) granted by the Shield of Cthulhu bonk. + var cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdfld("eocDash"))) // Loading the remaining frames of the SoC dash + { + LogFailure("Shield of Cthulhu Bonk Nerf", "Could not locate Shield of Cthulhu dash remaining frame counter."); + return; + } + + // Find the 0 this is normally compared to. We will be replacing this value. + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(0))) + { + LogFailure("Shield of Cthulhu Bonk Nerf", "Could not locate the zero comparison."); + return; + } + + // Remove the zero and replace it with a calculated value. + // This is the total length of the EoC bonk (10) minus the number of safe frames allowed by Calamity. + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4, 10 - BalancingConstants.ShieldOfCthulhuBonkNoCollideFrames); + } + #endregion Dash Fixes and Improvements + #region Enabling of Triggered NPC Platform Fallthrough // Why this isn't a mechanism provided by TML itself or vanilla itself is beyond me. private static void AllowTriggeredFallthrough(On.Terraria.NPC.orig_ApplyTileCollision orig, NPC self, bool fall, Vector2 cPosition, int cWidth, int cHeight) @@ -202,117 +382,6 @@ namespace CalamityMod.ILEditing } #endregion Removal of Dodge RNG - #region Vanilla Dash / Shield Slam Improvements - private static void MakeShieldSlamIFramesConsistent(ILContext il) - { - var cursor = new ILCursor(il); - - // Find the direct assignment of the player's iframes. - if (!cursor.TryGotoNext(MoveType.AfterLabel, i => i.MatchStfld("immuneTime"))) - { - LogFailure("Shield Slam Consistent Immunity Frames", "Could not locate the assignment of the player's immune time."); - return; - } - - // Delete this instruction. The stack still contains the player and amount of iframes to give. - cursor.Remove(); - - // Emit a delegate which calls the Calamity utility to consistently provide iframes. - cursor.EmitDelegate>((p, frames) => CalamityUtils.GiveIFrames(p, frames, false)); - } - - private static void BuffSolarFlareShieldSlam(ILContext il) - { - var cursor = new ILCursor(il); - - // Move onto the next dash (Solar Flare set bonus) by looking for the base damage of the direct contact strike. - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcR4(150f))) - { - LogFailure("Vanilla Shield Slam Fix", "Could not locate Solar Flare Armor shield slam base damage."); - return; - } - - // Replace vanilla's base damage of 150 with Calamity's custom base damage. - cursor.Next.Operand = BalancingConstants.SolarFlareBaseDamage; - - // Now that the new base damage has been applied to the direct contact strike, also apply it to the Solar Counter projectile. - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(150))) - { - LogFailure("Vanilla Shield Slam Fix", "Could not locate Solar Flare Armor \"Solar Counter\" base damage."); - return; - } - - // Replace vanilla's flat 150 damage (doesn't even scale with melee stats!) with the already-calculated base damage, then cast it to int. - cursor.Remove(); - cursor.Emit(OpCodes.Ldloc, 13); - cursor.Emit(OpCodes.Conv_I4); - - // Move to the immunity frame setting code for the Solar Flare set bonus. Find the constant 4 given as iframes. - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(4))) - { - LogFailure("Vanilla Shield Slam Fix", "Could not locate Solar Flare shield slam iframes."); - return; - } - - // Replace it with Calamity's number of iframes. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4, BalancingConstants.SolarFlareIFrames); - } - - private static void NerfShieldOfCthulhuBonkSafety(ILContext il) - { - // Reduce the number of "no-collide frames" (they are NOT iframes) granted by the Shield of Cthulhu bonk. - var cursor = new ILCursor(il); - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdfld("eocDash"))) // Loading the remaining frames of the SoC dash - { - LogFailure("Shield of Cthulhu Bonk Nerf", "Could not locate Shield of Cthulhu dash remaining frame counter."); - return; - } - - // Find the 0 this is normally compared to. We will be replacing this value. - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(0))) - { - LogFailure("Shield of Cthulhu Bonk Nerf", "Could not locate the zero comparison."); - return; - } - - // Remove the zero and replace it with a calculated value. - // This is the total length of the EoC bonk (10) minus the number of safe frames allowed by Calamity. - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4, 10 - BalancingConstants.ShieldOfCthulhuBonkNoCollideFrames); - } - - private static void FixModdedDashesResettingDashCountdown(ILContext il) - { - var cursor = new ILCursor(il); - if (!cursor.TryGotoNext(MoveType.After, i => i.MatchStfld("dashDelay"))) - { - LogFailure("Modded Dashes Resetting Dash Countdown Fix", "Could not locate the dash delay storage."); - return; - } - - int afterDashResetsIndex = cursor.Index; - - // Go back to the start and remove the original check, replacing it with one that accepts modded dashes. - cursor.Goto(0); - cursor.RemoveRange(afterDashResetsIndex); - - cursor.Emit(OpCodes.Ldarg_0); - cursor.EmitDelegate>(p => - { - if (p.dashDelay == 0) - p.dash = p.dashType; - - if (p.dash == 0 && !p.Calamity().HasCustomDash) - { - p.dashTime = 0; - p.dashDelay = 0; - } - }); - } - - #endregion Vanilla Dash Shield Improvements - #region Custom Gate Door Logic private static bool OpenDoor_LabDoorOverride(On.Terraria.WorldGen.orig_OpenDoor orig, int i, int j, int direction) {