From 9ad440b88bcbcafc8fa66b1e9403213cbbd2699a Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Sun, 27 Sep 2020 22:06:52 -0400 Subject: [PATCH] fixed BR EOW with IL Editing also some refactoring --- CalamityMod.cs | 89 +------------- ILEditing/ILChanges.cs | 113 ++++++++++++++++++ .../AgedLaboratoryDoorClosed.cs | 6 +- .../AgedLaboratoryDoorOpen.cs | 6 +- .../DraedonStructures/LaboratoryDoorClosed.cs | 6 +- Tiles/DraedonStructures/LaboratoryDoorOpen.cs | 6 +- 6 files changed, 122 insertions(+), 104 deletions(-) diff --git a/CalamityMod.cs b/CalamityMod.cs index 365ae4ce9b..85dbf59fd4 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -37,7 +37,6 @@ using CalamityMod.Projectiles.Summon; using CalamityMod.Schematics; using CalamityMod.Skies; using CalamityMod.TileEntities; -using CalamityMod.Tiles.DraedonStructures; using CalamityMod.UI; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -49,7 +48,6 @@ using System.Reflection; using Terraria; using Terraria.DataStructures; using Terraria.GameContent.Dyes; -using Terraria.GameInput; using Terraria.Graphics.Effects; using Terraria.Graphics.Shaders; using Terraria.ID; @@ -137,7 +135,7 @@ namespace CalamityMod ILChanges.Initialize(); BossRushEvent.Load(); thorium = ModLoader.GetMod("ThoriumMod"); - + BossHealthBarManager.Load(this); CalamityLists.LoadLists(); @@ -147,91 +145,6 @@ namespace CalamityMod SetupThoriumBossDR(thorium); CalamityLocalization.AddLocalizations(); - - On.Terraria.Player.TileInteractionsUse += Player_TileInteractionsUse; - On.Terraria.WorldGen.OpenDoor += LabDoorsOpen; - On.Terraria.WorldGen.CloseDoor += LabDoorsClose; - } - - private static bool LabDoorsOpen(On.Terraria.WorldGen.orig_OpenDoor orig, int i, int j, int direction) - { - Tile tile = Main.tile[i, j]; - if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || - tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) - { - return false; - } - else - { - return orig(i, j, direction); - } - } - - private static bool LabDoorsClose(On.Terraria.WorldGen.orig_CloseDoor orig, int i, int j, bool forced) - { - Tile tile = Main.tile[i, j]; - if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || - tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) - { - return false; - } - else - { - return orig(i, j, forced); - } - } - - private static void Player_TileInteractionsUse(On.Terraria.Player.orig_TileInteractionsUse orig, Player player, int i, int j) - { - Tile tile = Main.tile[i, j]; - if (tile.type == ModContent.TileType()) - { - DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); - } - else if (tile.type == ModContent.TileType()) - { - DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); - } - else if (tile.type == ModContent.TileType()) - { - DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); - } - else if (tile.type == ModContent.TileType()) - { - DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); - } - else - { - orig(player, i, j); - } - } - - public static void DoorSwap(int type1, int type2, int i, int j, bool forced = false) - { - if (PlayerInput.Triggers.JustPressed.MouseRight || forced) - { - ushort type = (ushort)type1; - short frameY = 0; - for (int dy = -4; dy < 4; dy++) - { - if (Main.tile[i, j + dy].frameY > 0 && frameY == 0) - continue; - if (Main.tile[i, j + dy].type == type2) - { - if (Main.tile[i, j + dy] is null) - { - Main.tile[i, j + dy] = new Tile(); - } - Main.tile[i, j + dy].type = type; - Main.tile[i, j + dy].frameY = frameY; - frameY += 16; - if ((int)frameY / 16 >= 4) - break; - } - } - - Main.PlaySound(SoundID.DoorClosed, i * 16, j * 16, 1, 1f, 0f); - } } private void LoadClient() diff --git a/ILEditing/ILChanges.cs b/ILEditing/ILChanges.cs index 5f2556b77c..b55e556a26 100644 --- a/ILEditing/ILChanges.cs +++ b/ILEditing/ILChanges.cs @@ -1,6 +1,10 @@ +using CalamityMod.Tiles.DraedonStructures; using MonoMod.Cil; using System; using Terraria; +using Terraria.GameInput; +using Terraria.ID; +using Terraria.ModLoader; namespace CalamityMod.ILEditing { @@ -10,6 +14,16 @@ namespace CalamityMod.ILEditing /// Loads all IL Editing changes in the mod. /// public static void Initialize() + { + ChangeEoWLifeBytes(); + SlideDungeonOver(); + LabDoorFixes(); + } + + #region IL Editing Routines + private static void ChangeEoWLifeBytes() => On.Terraria.Main.InitLifeBytes += EoWLifeBytes; + + private static void SlideDungeonOver() { IL.Terraria.WorldGen.MakeDungeon += (il) => { @@ -27,5 +41,104 @@ namespace CalamityMod.ILEditing }); }; } + + private static void LabDoorFixes() + { + On.Terraria.Player.TileInteractionsUse += Player_TileInteractionsUse; + On.Terraria.WorldGen.OpenDoor += LabDoorsOpen; + On.Terraria.WorldGen.CloseDoor += LabDoorsClose; + } + #endregion + + #region IL Editing Injection Functions + private static void EoWLifeBytes(On.Terraria.Main.orig_InitLifeBytes orig) + { + orig(); + Main.npcLifeBytes[NPCID.EaterofWorldsHead] = Main.npcLifeBytes[NPCID.EaterofWorldsBody] = Main.npcLifeBytes[NPCID.EaterofWorldsTail] = 4; + } + + private static bool LabDoorsOpen(On.Terraria.WorldGen.orig_OpenDoor orig, int i, int j, int direction) + { + Tile tile = Main.tile[i, j]; + if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || + tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) + { + return false; + } + else + { + return orig(i, j, direction); + } + } + + private static bool LabDoorsClose(On.Terraria.WorldGen.orig_CloseDoor orig, int i, int j, bool forced) + { + Tile tile = Main.tile[i, j]; + if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || + tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) + { + return false; + } + else + { + return orig(i, j, forced); + } + } + + private static void Player_TileInteractionsUse(On.Terraria.Player.orig_TileInteractionsUse orig, Player player, int i, int j) + { + Tile tile = Main.tile[i, j]; + if (tile.type == ModContent.TileType()) + { + DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); + } + else if (tile.type == ModContent.TileType()) + { + DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); + } + else if (tile.type == ModContent.TileType()) + { + DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); + } + else if (tile.type == ModContent.TileType()) + { + DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); + } + else + { + orig(player, i, j); + } + } + #endregion + + #region Helper Functions + public static void DoorSwap(int type1, int type2, int i, int j, bool forced = false) + { + if (PlayerInput.Triggers.JustPressed.MouseRight || forced) + { + ushort type = (ushort)type1; + short frameY = 0; + for (int dy = -4; dy < 4; dy++) + { + if (Main.tile[i, j + dy].frameY > 0 && frameY == 0) + continue; + if (Main.tile[i, j + dy].type == type2) + { + if (Main.tile[i, j + dy] is null) + { + Main.tile[i, j + dy] = new Tile(); + } + Main.tile[i, j + dy].type = type; + Main.tile[i, j + dy].frameY = frameY; + frameY += 16; + if ((int)frameY / 16 >= 4) + break; + } + } + + Main.PlaySound(SoundID.DoorClosed, i * 16, j * 16, 1, 1f, 0f); + } + } + #endregion } } diff --git a/Tiles/DraedonStructures/AgedLaboratoryDoorClosed.cs b/Tiles/DraedonStructures/AgedLaboratoryDoorClosed.cs index d84713a383..7bd4a60726 100644 --- a/Tiles/DraedonStructures/AgedLaboratoryDoorClosed.cs +++ b/Tiles/DraedonStructures/AgedLaboratoryDoorClosed.cs @@ -1,3 +1,4 @@ +using CalamityMod.ILEditing; using CalamityMod.Items.Placeables.DraedonStructures; using Microsoft.Xna.Framework; using Terraria; @@ -55,10 +56,7 @@ namespace CalamityMod.Tiles.DraedonStructures num = fail ? 1 : 3; } - public override void HitWire(int i, int j) - { - CalamityMod.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); - } + public override void HitWire(int i, int j) => ILChanges.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); public override void KillMultiTile(int i, int j, int frameX, int frameY) { diff --git a/Tiles/DraedonStructures/AgedLaboratoryDoorOpen.cs b/Tiles/DraedonStructures/AgedLaboratoryDoorOpen.cs index 1e07787d23..7b42a6cffb 100644 --- a/Tiles/DraedonStructures/AgedLaboratoryDoorOpen.cs +++ b/Tiles/DraedonStructures/AgedLaboratoryDoorOpen.cs @@ -1,3 +1,4 @@ +using CalamityMod.ILEditing; using CalamityMod.Items.Placeables.DraedonStructures; using Microsoft.Xna.Framework; using Terraria; @@ -55,10 +56,7 @@ namespace CalamityMod.Tiles.DraedonStructures num = fail ? 1 : 3; } - public override void HitWire(int i, int j) - { - CalamityMod.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); - } + public override void HitWire(int i, int j) => ILChanges.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); public override void KillMultiTile(int i, int j, int frameX, int frameY) { diff --git a/Tiles/DraedonStructures/LaboratoryDoorClosed.cs b/Tiles/DraedonStructures/LaboratoryDoorClosed.cs index f7e5a431f3..037d439868 100644 --- a/Tiles/DraedonStructures/LaboratoryDoorClosed.cs +++ b/Tiles/DraedonStructures/LaboratoryDoorClosed.cs @@ -1,3 +1,4 @@ +using CalamityMod.ILEditing; using CalamityMod.Items.Placeables.DraedonStructures; using Microsoft.Xna.Framework; using Terraria; @@ -55,10 +56,7 @@ namespace CalamityMod.Tiles.DraedonStructures num = fail ? 1 : 3; } - public override void HitWire(int i, int j) - { - CalamityMod.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); - } + public override void HitWire(int i, int j) => ILChanges.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); public override void KillMultiTile(int i, int j, int frameX, int frameY) { diff --git a/Tiles/DraedonStructures/LaboratoryDoorOpen.cs b/Tiles/DraedonStructures/LaboratoryDoorOpen.cs index 87c11cf966..eb1a3b18a7 100644 --- a/Tiles/DraedonStructures/LaboratoryDoorOpen.cs +++ b/Tiles/DraedonStructures/LaboratoryDoorOpen.cs @@ -1,3 +1,4 @@ +using CalamityMod.ILEditing; using CalamityMod.Items.Placeables.DraedonStructures; using Microsoft.Xna.Framework; using Terraria; @@ -55,10 +56,7 @@ namespace CalamityMod.Tiles.DraedonStructures num = fail ? 1 : 3; } - public override void HitWire(int i, int j) - { - CalamityMod.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); - } + public override void HitWire(int i, int j) => ILChanges.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); public override void KillMultiTile(int i, int j, int frameX, int frameY) {