From edfb81c9591fb69f852ca709e0d1b5546800a4ce Mon Sep 17 00:00:00 2001 From: Altixal <73398287+Altixal@users.noreply.github.com> Date: Thu, 22 Jun 2023 05:20:16 +0700 Subject: [PATCH] Dodges IL Edit + Worldgen task localization fix --- ILEditing/ILChangesLoading.cs | 5 +- ILEditing/MechanicILChanges.cs | 123 ++++++---------------------- Systems/WorldgenManagementSystem.cs | 68 +++++++-------- 3 files changed, 60 insertions(+), 136 deletions(-) diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 1e73ad5d55..8d6e15ab50 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -59,10 +59,7 @@ namespace CalamityMod.ILEditing // Mechanics / features Terraria.On_NPC.ApplyTileCollision += AllowTriggeredFallthrough; Terraria.IL_Player.ApplyEquipFunctional += ScopesRequireVisibilityToZoom; - - // ERROR - //Terraria.IL_Player.Hurt += RemoveRNGFromDodges; - + Terraria.On_Player.Hurt_PlayerDeathReason_int_int_bool_bool_int_bool_float_float_float += RemoveRNGFromDodges; Terraria.IL_Player.DashMovement += FixAllDashMechanics; Terraria.On_Player.DoCommonDashHandle += ApplyDashKeybind; Terraria.IL_Player.GiveImmuneTimeForCollisionAttack += MakeShieldSlamIFramesConsistent; diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 129824011e..b55bff0509 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -344,109 +344,36 @@ namespace CalamityMod.ILEditing #endregion Town NPC Spawning Improvements #region Removal of Dodge RNG - private static readonly Func CalamityDodgeAvailable = (Player p) => + private static double RemoveRNGFromDodges(Terraria.On_Player.orig_Hurt_PlayerDeathReason_int_int_bool_bool_int_bool_float_float_float orig, Player self, PlayerDeathReason damageSource, int Damage, int hitDirection, bool pvp, bool quiet, int cooldownCounter, bool dodgeable, float armorPenetration, float scalingArmorPenetration, float knockback) { - CalamityPlayer mp = p.Calamity(); - // If your dodges are universally disabled, then they simply "never come off cooldown" and always have 1 frame left. - if (mp.disableAllDodges) - return 1; - - bool dodgeCooldownActive = p.HasCooldown(GlobalDodge.ID); - return dodgeCooldownActive ? 1 : 0; - }; - - private static void RemoveRNGFromDodges(ILContext il) - { - // - // BLACK BELT - // - - // Change the random chance of the Black Belt to 100%, but don't let it work if Calamity's cooldown is active. - var cursor = new ILCursor(il); - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(10))) // 1 in 10 Main.rand call for Black Belt activation. + if (self.whoAmI == Main.myPlayer) { - LogFailure("No RNG Black Belt", "Could not locate the dodge chance."); - return; - } - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4_1); // Replace with Main.rand.Next(1), aka 100% chance. + // Disable dodges + if (self.Calamity().disableAllDodges) + dodgeable = false; + + // Provided you have no other dodges, disable dodging while under the cooldown + bool hasOtherDodges = self.shadowDodge; + if (self.HasCooldown(GlobalDodge.ID)) + dodgeable = hasOtherDodges; - // Move forwards past the Main.rand.Next call now that it has been edited. - if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCallvirt("Next"))) - { - LogFailure("No RNG Black Belt", "Could not locate the Random.Next call."); - return; + // Remove Black Belt RNG and add the cooldown + else if (self.blackBelt) + { + self.NinjaDodge(); + self.AddCooldown(GlobalDodge.ID, BalancingConstants.BeltDodgeCooldown); + return 0.0; + } + // Remove Brain of Confusion RNG and add the cooldown + else if (self.brainOfConfusionItem != null && !self.brainOfConfusionItem.IsAir) + { + self.BrainOfConfusionDodge(); + self.AddCooldown(GlobalDodge.ID, self.Calamity().amalgam ? BalancingConstants.AmalgamDodgeCooldown : BalancingConstants.BrainDodgeCooldown); + return 0.0; + } } - // 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 the player's dodge availability onto the stack. - // This is typically the Calamity dodge cooldown -- zero lets you dodge, anything else doesn't. - cursor.EmitDelegate>(CalamityDodgeAvailable); - - // Bitwise OR the "RNG result" (always zero) with the dodge cooldown. This will only return zero if both values were zero. - // The code path which calls NinjaDodge can ONLY occur if the result of this operation is zero, - // because it is now the value checked by the immediately following branch-if-true. - cursor.Emit(OpCodes.Or); - - // Move forwards past the NinjaDodge call. We need to set the dodge cooldown here. - if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCall("NinjaDodge"))) - { - LogFailure("No RNG Black Belt", "Could not locate the Player.NinjaDodge call."); - 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 sets the player's Calamity dodge cooldown and sends a sync packet appropriately. - cursor.EmitDelegate>((Player p) => p.AddCooldown(GlobalDodge.ID, BalancingConstants.BeltDodgeCooldown)); - - // - // BRAIN OF CONFUSION - // - - // Change the random chance of the Brain of Confusion to 100%, but don't let it work if Calamity's cooldown is active. - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(6))) // 1 in 6 Main.rand call for Brain of Confusion activation. - { - LogFailure("No RNG Brain of Confusion", "Could not locate the dodge chance."); - return; - } - cursor.Remove(); - cursor.Emit(OpCodes.Ldc_I4_1); // Replace with Main.rand.Next(1), aka 100% chance. - - // Move forwards past the Main.rand.Next call now that it has been edited. - if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCallvirt("Next"))) - { - LogFailure("No RNG Brain of Confusion", "Could not locate the Random.Next call."); - 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 the player's dodge availability onto the stack. - // This is typically the Calamity dodge cooldown -- zero lets you dodge, anything else doesn't. - cursor.EmitDelegate>(CalamityDodgeAvailable); - - // Bitwise OR the "RNG result" (always zero) with the dodge cooldown. This will only return zero if both values were zero. - // The code path which calls BrainOfConfusionDodge can ONLY occur if the result of this operation is zero, - // because it is now the value checked by the immediately following branch-if-true. - cursor.Emit(OpCodes.Or); - - // Move forwards past the BrainOfConfusionDodge call. We need to set the dodge cooldown here. - if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCall("BrainOfConfusionDodge"))) - { - LogFailure("No RNG Brain of Confusion", "Could not locate the Player.BrainOfConfusionDodge call."); - 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 sets the player's Calamity dodge cooldown and sends a sync packet appropriately. - cursor.EmitDelegate>((Player p) => p.AddCooldown(GlobalDodge.ID, p.Calamity().amalgam ? BalancingConstants.AmalgamDodgeCooldown : BalancingConstants.BrainDodgeCooldown)); + return orig(self, damageSource, Damage, hitDirection, pvp, quiet, cooldownCounter, dodgeable, armorPenetration, scalingArmorPenetration, knockback); } #endregion Removal of Dodge RNG diff --git a/Systems/WorldgenManagementSystem.cs b/Systems/WorldgenManagementSystem.cs index 2e35db5d32..9b98c29c70 100644 --- a/Systems/WorldgenManagementSystem.cs +++ b/Systems/WorldgenManagementSystem.cs @@ -36,7 +36,7 @@ namespace CalamityMod.Systems { tasks.Insert(islandIndex + 2, new PassLegacy("Evil Island", (progress, config) => { - progress.Message = Language.GetOrRegister(WorldGen.crimson ? "Mods.Calamity.UI.EvilIslandCrimson" : "Mods.Calamity.UI.EvilIslandCorrupt").Value; + progress.Message = Language.GetOrRegister(WorldGen.crimson ? "Mods.CalamityMod.UI.EvilIslandCrimson" : "Mods.CalamityMod.UI.EvilIslandCorrupt").Value; WorldEvilIsland.PlaceEvilIsland(); })); } @@ -45,7 +45,7 @@ namespace CalamityMod.Systems int DungeonIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Dungeon")); tasks[DungeonIndex] = new PassLegacy("Dungeon", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.BetterDungeon").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.BetterDungeon").Value; CustomDungeon.NewDungeon(); }); @@ -53,7 +53,7 @@ namespace CalamityMod.Systems int JungleTempleIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Jungle Temple")); tasks[JungleTempleIndex] = new PassLegacy("Jungle Temple", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.BetterJungleTemple").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.BetterJungleTemple").Value; CustomTemple.NewJungleTemple(); }); @@ -61,7 +61,7 @@ namespace CalamityMod.Systems int JungleTempleIndex2 = tasks.FindIndex(genpass => genpass.Name.Equals("Temple")); tasks[JungleTempleIndex2] = new PassLegacy("Temple", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.BetterJungleTemple").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.BetterJungleTemple").Value; Main.tileSolid[162] = false; Main.tileSolid[226] = true; CustomTemple.NewJungleTemplePart2(); @@ -72,7 +72,7 @@ namespace CalamityMod.Systems int LihzahrdAltarIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Lihzahrd Altars")); tasks[LihzahrdAltarIndex] = new PassLegacy("Lihzahrd Altars", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.JungleTempleAltar").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.JungleTempleAltar").Value; CustomTemple.NewJungleTempleLihzahrdAltar(); }); @@ -82,7 +82,7 @@ namespace CalamityMod.Systems { tasks.Insert(giantHiveIndex + 1, new PassLegacy("Giant Hive", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.GiantBeehive").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.GiantBeehive").Value; int attempts = 0; while (attempts < 1000) { @@ -100,7 +100,7 @@ namespace CalamityMod.Systems { tasks.Insert(mechanicIndex + 1, new PassLegacy("Mechanic Shed", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.MechanicShed").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.MechanicShed").Value; MechanicShed.PlaceMechanicShed(GenVars.structures); })); } @@ -111,7 +111,7 @@ namespace CalamityMod.Systems { tasks.Insert(vernalIndex + 1, new PassLegacy("Vernal Pass", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.VernalPass").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.VernalPass").Value; VernalPass.PlaceVernalPass(GenVars.structures); })); } @@ -122,7 +122,7 @@ namespace CalamityMod.Systems { tasks.Insert(SunkenSeaIndex + 1, new PassLegacy("Sunken Sea", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.SunkenSea").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.SunkenSea").Value; int sunkenSeaX = GenVars.UndergroundDesertLocation.Left; int sunkenSeaY = Main.maxTilesY - 400; @@ -139,7 +139,7 @@ namespace CalamityMod.Systems int currentFinalIndex = FinalIndex; tasks.Insert(++currentFinalIndex, new PassLegacy("Gem Depth Adjustment", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.GemAdjustment").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.GemAdjustment").Value; MiscWorldgenRoutines.SmartGemGen(); })); @@ -147,7 +147,7 @@ namespace CalamityMod.Systems // Forsaken Archive structure in the Dungeon tasks.Insert(++currentFinalIndex, new PassLegacy("Forsaken Archive", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.DungeonArchive").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.DungeonArchive").Value; DungeonArchive.PlaceArchive(); })); @@ -161,7 +161,7 @@ namespace CalamityMod.Systems { tasks.Insert(SulphurIndex + 1, new PassLegacy("Sulphur Sea", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.SulphurSea").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.SulphurSea").Value; SulphurousSea.PlaceSulphurSea(); })); @@ -170,44 +170,44 @@ namespace CalamityMod.Systems // Brimstone Crags tasks.Insert(++currentFinalIndex, new PassLegacy("Brimstone Crag", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.BrimstoneCrags").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.BrimstoneCrags").Value; BrimstoneCrag.GenAllCragsStuff(); })); // Biome shrines tasks.Insert(++currentFinalIndex, new PassLegacy("Special Shrines", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.HiddenShrines").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.HiddenShrines").Value; // Cuts down on worldgen time to process the right one. // TODO -- Possible Both Evils compat whenever if (WorldGen.crimson) { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.CrimsonShrine").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.CrimsonShrine").Value; UndergroundShrines.PlaceCrimsonShrine(GenVars.structures); } else { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.CorruptShrine").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.CorruptShrine").Value; UndergroundShrines.PlaceCorruptionShrine(GenVars.structures); } - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.DesertShrine").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.DesertShrine").Value; UndergroundShrines.PlaceDesertShrine(GenVars.structures); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.GraniteShrine").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.GraniteShrine").Value; UndergroundShrines.PlaceGraniteShrine(GenVars.structures); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.IceShrine").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.IceShrine").Value; UndergroundShrines.PlaceIceShrine(GenVars.structures); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.MarbleShrine").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.MarbleShrine").Value; UndergroundShrines.PlaceMarbleShrine(GenVars.structures); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.MushroomShrine").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.MushroomShrine").Value; UndergroundShrines.PlaceMushroomShrine(GenVars.structures); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.SurfaceShrine").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.SurfaceShrine").Value; UndergroundShrines.PlaceSurfaceShrine(GenVars.structures); })); @@ -215,14 +215,14 @@ namespace CalamityMod.Systems // This MUST generate after the evil island, otherwise the ores keep getting painted from the evil island gen tasks.Insert(++currentFinalIndex, new PassLegacy("Aerialite", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.Aerialite").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.Aerialite").Value; AerialiteOreGen.Generate(false); })); // Draedon Labs tasks.Insert(++currentFinalIndex, new PassLegacy("Draedon Structures", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.DraedonLabs").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.DraedonLabs").Value; List workshopPositions = new List(); // Small: 4, Normal: 7, Large: 9 @@ -233,33 +233,33 @@ namespace CalamityMod.Systems // Tries to scale up reasonably for XL worlds int labCount = Main.maxTilesX / 1500; - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.HellLab").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.HellLab").Value; DraedonStructures.PlaceHellLab(out Point hellPlacementPosition, workshopPositions, GenVars.structures); workshopPositions.Add(hellPlacementPosition); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.SunkenLab").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.SunkenLab").Value; DraedonStructures.PlaceSunkenSeaLab(out Point sunkenSeaPlacementPosition, workshopPositions, GenVars.structures); workshopPositions.Add(sunkenSeaPlacementPosition); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.IceLab").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.IceLab").Value; DraedonStructures.PlaceIceLab(out Point icePlacementPosition, workshopPositions, GenVars.structures); workshopPositions.Add(icePlacementPosition); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.PlagueLab").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.PlagueLab").Value; DraedonStructures.PlacePlagueLab(out Point plaguePlacementPosition, workshopPositions, GenVars.structures); workshopPositions.Add(plaguePlacementPosition); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.CavernLab").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.CavernLab").Value; DraedonStructures.PlaceCavernLab(out Point cavernPlacementPosition, workshopPositions, GenVars.structures); workshopPositions.Add(cavernPlacementPosition); - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.DraedonWorkshop").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.DraedonWorkshop").Value; for (int i = 0; i < workshopCount; i++) { DraedonStructures.PlaceWorkshop(out Point placementPosition, workshopPositions, GenVars.structures); workshopPositions.Add(placementPosition); } - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.DraedonFacility").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.DraedonFacility").Value; for (int i = 0; i < labCount; i++) { DraedonStructures.PlaceResearchFacility(out Point placementPosition, workshopPositions, GenVars.structures); @@ -270,21 +270,21 @@ namespace CalamityMod.Systems // Abyss tasks.Insert(++currentFinalIndex, new PassLegacy("Abyss", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.Abyss").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.Abyss").Value; Abyss.PlaceAbyss(); })); // Sulphurous Sea (Part 2, after Abyss) tasks.Insert(++currentFinalIndex, new PassLegacy("Sulphur Sea 2", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.SulphurSea2").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.SulphurSea2").Value; SulphurousSea.SulphurSeaGenerationAfterAbyss(); })); // Roxcalibur tasks.Insert(++currentFinalIndex, new PassLegacy("Roxcalibur", (progress, config) => { - progress.Message = Language.GetOrRegister("Mods.Calamity.UI.Roxcalibur").Value; + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.Roxcalibur").Value; MiscWorldgenRoutines.PlaceRoxShrine(); })); }