From dfbb5e31dc6a1a787ada15397fc410615f5e89a7 Mon Sep 17 00:00:00 2001 From: DominicKarma <51094361+DominicKarma@users.noreply.github.com> Date: Wed, 18 May 2022 21:10:11 -0500 Subject: [PATCH] Tag damage isn't flat, unfucked Firecracker --- Balancing/BalancingConstants.cs | 9 ++ ILEditing/ILChangesLoading.cs | 2 + ILEditing/VanillaStupidityFixingILChanges.cs | 95 +++++++++++++++++++- 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/Balancing/BalancingConstants.cs b/Balancing/BalancingConstants.cs index cea0943cdd..8eed5ff6f4 100644 --- a/Balancing/BalancingConstants.cs +++ b/Balancing/BalancingConstants.cs @@ -22,6 +22,15 @@ internal static readonly int DaedalusReflectCooldown = 5400; internal static readonly int EvolutionReflectCooldown = 7200; + // Internal vanilla item damage variables + internal static readonly float LeatherWhipTagDamageMultiplier = 1.08f; + internal static readonly float SnapthornTagDamageMultiplier = 1.04f; + internal static readonly float SpinalTapTagDamageMultiplier = 1.08f; + internal static readonly float FirecrackerExplosionDamageMultiplier = 2.25f; // Relative to the whip, not the summon. + internal static readonly float DurendalTagDamageMultiplier = 1.09f; + internal static readonly float MorningStarTagDamageMultiplier = 1.11f; + internal static readonly float KaleidoscopeTagDamageMultiplier = 1.12f; + // TODO -- Add all balance related constants here that don't belong in other files. // These constants were just the ones sitting in CalamityPlayer. // Review all constants and static readonlys in the entire mod to find things to add. diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index d7f7c27ef2..a10ad0827b 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -102,6 +102,7 @@ namespace CalamityMod.ILEditing IL.Terraria.Projectile.CanExplodeTile += MakeMeteoriteExplodable; IL.Terraria.Main.UpdateTime_StartNight += BloodMoonsRequire200MaxLife; IL.Terraria.WorldGen.AttemptFossilShattering += PreventFossilShattering; + IL.Terraria.Projectile.Damage += MakeTagDamageMultiplicative; // Fix vanilla bugs exposed by Calamity mechanics IL.Terraria.NPC.NPCLoot += FixSplittingWormBannerDrops; @@ -184,6 +185,7 @@ namespace CalamityMod.ILEditing IL.Terraria.Projectile.CanExplodeTile -= MakeMeteoriteExplodable; IL.Terraria.Main.UpdateTime_StartNight -= BloodMoonsRequire200MaxLife; IL.Terraria.WorldGen.AttemptFossilShattering -= PreventFossilShattering; + IL.Terraria.Projectile.Damage -= MakeTagDamageMultiplicative; // Fix vanilla bugs exposed by Calamity mechanics // On.Terraria.Main.InitLifeBytes -= BossRushLifeBytes; diff --git a/ILEditing/VanillaStupidityFixingILChanges.cs b/ILEditing/VanillaStupidityFixingILChanges.cs index 293254ee2c..b4cc23baa8 100644 --- a/ILEditing/VanillaStupidityFixingILChanges.cs +++ b/ILEditing/VanillaStupidityFixingILChanges.cs @@ -1,8 +1,11 @@ -using Mono.Cecil.Cil; +using CalamityMod.Balancing; +using Microsoft.Xna.Framework; +using Mono.Cecil.Cil; using MonoMod.Cil; using System; using Terraria; using Terraria.ID; +using Terraria.ModLoader; namespace CalamityMod.ILEditing { @@ -220,6 +223,96 @@ namespace CalamityMod.ILEditing } #endregion + #region Make Tag Damage Multiplicative + private static void MakeTagDamageMultiplicative(ILContext il) + { + var cursor = new ILCursor(il); + int damageLocalIndex = 37; + + bool replaceWithMultipler(int flagLocalIndex, float damageFactor, bool usesExtraVariableToStoreDamage = false) + { + // Move after the bool load and branch-if-false instruction. + cursor.Goto(0); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdloc(flagLocalIndex))) + { + LogFailure("Making Tag Damage Multiplicative", $"Could not locate the flag local index of '{flagLocalIndex}'."); + return false; + } + cursor.Index += 2; + + // OPTIONAL case for if an extra variable to store damage is used: + // Load damage to add. + // Store damage to add as a variable. + + // Load damage -> + // Load damage addition -> + // Add the two -> + // Store damage. + cursor.RemoveRange(usesExtraVariableToStoreDamage ? 6 : 4); + + // Load damage -> + // Cast damage to float -> + // Load the damage factor -> + // Multiply the two -> + // Cast the result to int, removing the fractional part -> + // Store damage. + cursor.Emit(OpCodes.Ldloc, damageLocalIndex); + cursor.Emit(OpCodes.Conv_R4); + cursor.Emit(OpCodes.Ldc_R4, damageFactor); + cursor.Emit(OpCodes.Mul); + cursor.Emit(OpCodes.Conv_I4); + cursor.Emit(OpCodes.Stloc, damageLocalIndex); + return true; + } + + // Leather whip. + replaceWithMultipler(50, BalancingConstants.LeatherWhipTagDamageMultiplier); + + // Durendal. + replaceWithMultipler(51, BalancingConstants.DurendalTagDamageMultiplier); + + // Snapthorn. + replaceWithMultipler(54, BalancingConstants.SnapthornTagDamageMultiplier); + + // Spinal Tap. + replaceWithMultipler(55, BalancingConstants.SpinalTapTagDamageMultiplier); + + // Morning Star. + replaceWithMultipler(56, BalancingConstants.MorningStarTagDamageMultiplier); + + // Kaleidoscope. + replaceWithMultipler(57, BalancingConstants.KaleidoscopeTagDamageMultiplier, true); + + // SPECIAL CASE: Firecracker's damage is fucking absurd and everything needs to go. + cursor.Goto(0); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchStloc(64))) + { + LogFailure("Making Tag Damage Multiplicative", $"Could not locate the flag local index of 52."); + return; + } + + // Change the damage of the explosions. + cursor.Emit(OpCodes.Ldarg_0); + cursor.EmitDelegate>(projectile => + { + int damage = (int)(Main.player[projectile.owner].ActiveItem().damage * BalancingConstants.FirecrackerExplosionDamageMultiplier); + damage = (int)Main.player[projectile.owner].GetDamage(DamageClass.Summon).ApplyTo(damage); + return damage; + }); + cursor.Emit(OpCodes.Stloc, 64); + + // Change the x in damage += x; to zero. + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchAdd())) + { + LogFailure("Making Tag Damage Multiplicative", $"Could not locate the damage additive value."); + return; + } + cursor.Index--; + cursor.Remove(); + cursor.Emit(OpCodes.Ldc_I4_0); + } + #endregion Make Tag Damage Multiplicative + #region Fix Chlorophyte Crystal Attacking Where it Shouldn't #endregion Fix Chlorophyte Crystal Attacking Where it Shouldn't