diff --git a/Backgrounds/AstralDesertSurfaceBGStyle.cs b/Backgrounds/AstralDesertSurfaceBGStyle.cs index d5ef0d60c7..d7585a1371 100644 --- a/Backgrounds/AstralDesertSurfaceBGStyle.cs +++ b/Backgrounds/AstralDesertSurfaceBGStyle.cs @@ -1,19 +1,15 @@ -using Microsoft.Xna.Framework.Graphics; -using System.Reflection; -using System; -using Terraria.Graphics.Effects; -using Terraria; -using Terraria.ModLoader; -using Microsoft.Xna.Framework; +using System; using CalamityMod.Skies; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Effects; +using Terraria.ModLoader; namespace CalamityMod.Backgrounds { public class AstralDesertSurfaceBGStyle : ModSurfaceBackgroundStyle { - internal static readonly FieldInfo screenOffField = typeof(Main).GetField("screenOff", BindingFlags.Instance | BindingFlags.NonPublic); - internal static readonly FieldInfo scAdjField = typeof(Main).GetField("scAdj", BindingFlags.Instance | BindingFlags.NonPublic); - internal static readonly FieldInfo COSBMAplhaField = typeof(Main).GetField("ColorOfSurfaceBackgroundsModified", BindingFlags.Static | BindingFlags.NonPublic); readonly int CloseBGYOffset = 475; readonly int MiddleBGYOffset = 475; @@ -45,9 +41,9 @@ namespace CalamityMod.Backgrounds public override bool PreDrawCloseBackground(SpriteBatch spriteBatch) { //Please see AstralSurfaceBGStyle for comments, code is pretty much identical here - float screenOff = (float)screenOffField.GetValue(Main.instance); - float scAdj = (float)scAdjField.GetValue(Main.instance); - Color COSBMAplha = (Color)COSBMAplhaField.GetValue(null); + float screenOff = Main.instance.screenOff; + float scAdj = Main.instance.scAdj; + Color COSBMAplha = Main.ColorOfSurfaceBackgroundsModified; Color ColorOfSurfaceBackgroundsModified = new Color(63, 51, 90, COSBMAplha.A); bool canBGDraw = false; if ((!Main.remixWorld || (Main.gameMenu && !WorldGen.remixWorldGen)) && (!WorldGen.remixWorldGen || !WorldGen.drunkWorldGen)) diff --git a/Backgrounds/AstralSnowSurfaceBGStyle.cs b/Backgrounds/AstralSnowSurfaceBGStyle.cs index 5d16ae8916..fbbebf7119 100644 --- a/Backgrounds/AstralSnowSurfaceBGStyle.cs +++ b/Backgrounds/AstralSnowSurfaceBGStyle.cs @@ -1,19 +1,15 @@ -using Microsoft.Xna.Framework.Graphics; -using System.Reflection; -using System; -using Terraria.Graphics.Effects; -using Terraria; -using Terraria.ModLoader; -using Microsoft.Xna.Framework; +using System; using CalamityMod.Skies; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Effects; +using Terraria.ModLoader; namespace CalamityMod.Backgrounds { public class AstralSnowSurfaceBGStyle : ModSurfaceBackgroundStyle { - internal static readonly FieldInfo screenOffField = typeof(Main).GetField("screenOff", BindingFlags.Instance | BindingFlags.NonPublic); - internal static readonly FieldInfo scAdjField = typeof(Main).GetField("scAdj", BindingFlags.Instance | BindingFlags.NonPublic); - internal static readonly FieldInfo COSBMAplhaField = typeof(Main).GetField("ColorOfSurfaceBackgroundsModified", BindingFlags.Static | BindingFlags.NonPublic); readonly int FrontBGYOffset = 275; readonly int CloseBGYOffset = 175; readonly int MiddleBGYOffset = 475; @@ -46,9 +42,9 @@ namespace CalamityMod.Backgrounds public override bool PreDrawCloseBackground(SpriteBatch spriteBatch) { //Please see AstralSurfaceBGStyle for comments, code is pretty much identical here - float screenOff = (float)screenOffField.GetValue(Main.instance); - float scAdj = (float)scAdjField.GetValue(Main.instance); - Color COSBMAplha = (Color)COSBMAplhaField.GetValue(null); + float screenOff = Main.instance.screenOff; + float scAdj = Main.instance.scAdj; + Color COSBMAplha = Main.ColorOfSurfaceBackgroundsModified; Color ColorOfSurfaceBackgroundsModified = new Color(63, 51, 90, COSBMAplha.A); bool canBGDraw = false; if ((!Main.remixWorld || (Main.gameMenu && !WorldGen.remixWorldGen)) && (!WorldGen.remixWorldGen || !WorldGen.drunkWorldGen)) diff --git a/Backgrounds/AstralSurfaceBGStyle.cs b/Backgrounds/AstralSurfaceBGStyle.cs index c32d475687..57838097ab 100644 --- a/Backgrounds/AstralSurfaceBGStyle.cs +++ b/Backgrounds/AstralSurfaceBGStyle.cs @@ -1,20 +1,16 @@ -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework; -using System.Reflection; -using System; -using Terraria.Graphics.Effects; -using Terraria; -using Terraria.ModLoader; +using System; using CalamityMod.Skies; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Effects; +using Terraria.ModLoader; namespace CalamityMod.Backgrounds { //this is just a blank background, so each custom background will draw over it public class AstralSurfaceBGStyle : ModSurfaceBackgroundStyle { - internal static readonly FieldInfo screenOffField = typeof(Main).GetField("screenOff", BindingFlags.Instance | BindingFlags.NonPublic); - internal static readonly FieldInfo scAdjField = typeof(Main).GetField("scAdj", BindingFlags.Instance | BindingFlags.NonPublic); - internal static readonly FieldInfo COSBMAplhaField = typeof(Main).GetField("ColorOfSurfaceBackgroundsModified", BindingFlags.Static | BindingFlags.NonPublic); readonly int FrontBGYOffset = 275; //Offsets for the height positioning. Make these 0 for backgrounds that want to be the same as treeline backgrounds (backgrounds that have the front 3 layers as trees) readonly int CloseBGYOffset = 175; readonly int MiddleBGYOffset = 475; @@ -50,9 +46,9 @@ namespace CalamityMod.Backgrounds public override bool PreDrawCloseBackground(SpriteBatch spriteBatch) //Taken from vanilla to draw the front 3 layers, edited to fit tmod and astral background needs { - float screenOff = (float)screenOffField.GetValue(Main.instance); - float scAdj = (float)scAdjField.GetValue(Main.instance); - Color COSBMAplha = (Color)COSBMAplhaField.GetValue(null); + float screenOff = Main.instance.screenOff; + float scAdj = Main.instance.scAdj; + Color COSBMAplha = Main.ColorOfSurfaceBackgroundsModified; Color ColorOfSurfaceBackgroundsModified = new Color(63, 51, 90, COSBMAplha.A); //Astral Biome Coloration with the alpha as the background fade bool canBGDraw = false; if ((!Main.remixWorld || (Main.gameMenu && !WorldGen.remixWorldGen)) && (!WorldGen.remixWorldGen || !WorldGen.drunkWorldGen)) diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 9f19ff0a6d..31726b8ae8 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -1,6 +1,4 @@ -using System; -using System.Reflection; -using CalamityMod.Tiles.DraedonStructures; +using CalamityMod.Tiles.DraedonStructures; using CalamityMod.Tiles.FurnitureExo; using Terraria; using Terraria.DataStructures; @@ -36,10 +34,6 @@ namespace CalamityMod.ILEditing /// private static void ApplyEdits(ManipulatorContext ctx) { - // Wrap the vanilla town NPC spawning function in a delegate so that it can be tossed around and called at will. - var updateTime = typeof(Main).GetMethod("UpdateTime_SpawnTownNPCs", BindingFlags.Static | BindingFlags.NonPublic); - VanillaSpawnTownNPCs = Delegate.CreateDelegate(typeof(Action), updateTime) as Action; - // Cache the six lab door tile types for efficiency. labDoorOpen = ModContent.TileType(); labDoorClosed = ModContent.TileType(); diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index b5170c214c..3491e35798 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -350,13 +350,11 @@ namespace CalamityMod.ILEditing var cursor = new ILCursor(il); cursor.EmitDelegate(() => { - // A cached delegate is used here instead of direct reflection for performance reasons - // since UpdateTime is called every frame. if (Main.dayTime || CalamityServerConfig.Instance.TownNPCsSpawnAtNight) - VanillaSpawnTownNPCs(); + Main.UpdateTime_SpawnTownNPCs(); }); - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchCallOrCallvirt
("UpdateTime_SpawnTownNPCs"))) + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchCallOrCallvirt
(nameof(Main.UpdateTime_SpawnTownNPCs)))) { CalamityMod.Log.Warn("Town NPC spawn editing code failed."); return; diff --git a/MainMenu/CalamityMainMenu_Sunken.cs b/MainMenu/CalamityMainMenu_Sunken.cs index 1883b6b6c7..244c34fba2 100644 --- a/MainMenu/CalamityMainMenu_Sunken.cs +++ b/MainMenu/CalamityMainMenu_Sunken.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using CalamityMod.Effects; using CalamityMod.Systems; using Microsoft.Xna.Framework; @@ -75,11 +74,11 @@ namespace CalamityMod.MainMenu public static List Fishes { get; private set; } = []; public static Asset LogoWater => ModContent.Request("CalamityMod/MainMenu/LogoSunken_Water"); - + public static Asset LogoWaterFill => ModContent.Request("CalamityMod/MainMenu/LogoSunken_Water_Fill"); - + public static Asset Perlin => ModContent.Request("CalamityMod/MainMenu/Perlin"); - + public static Asset WorleyInverted => ModContent.Request("CalamityMod/MainMenu/WorleyInverted"); private static RenderTarget2D logoWaterFillTarget; @@ -88,7 +87,7 @@ namespace CalamityMod.MainMenu public int MaxBoids = 120; public float remixLogoRotation = 0f; - + /// /// The global save data key which dictates whether or not the player is opening the Sunken Sea Overhaul update for the first time. /// @@ -129,15 +128,13 @@ namespace CalamityMod.MainMenu if (GlobalSaveDataSystem.IsKeyAlreadySaved(FirstTimeOpeningSunkenSeaOverhaulKey)) return; - FieldInfo menusInfo = typeof(MenuLoader).GetField("menus", BindingFlags.Static | BindingFlags.NonPublic); - List modMenus = (List)menusInfo.GetValue(null); + List modMenus = MenuLoader.menus; var sunkenMenu = ModContent.GetInstance(); if (modMenus.Contains(sunkenMenu)) { - FieldInfo lastSelectedMenuInfo = typeof(MenuLoader).GetField("LastSelectedModMenu", BindingFlags.Static | BindingFlags.NonPublic); int sunkenSeaMenuIndex = modMenus.IndexOf(sunkenMenu); - lastSelectedMenuInfo.SetValue(null, modMenus[sunkenSeaMenuIndex].FullName); + MenuLoader.LastSelectedModMenu = modMenus[sunkenSeaMenuIndex].FullName; } } @@ -150,7 +147,7 @@ namespace CalamityMod.MainMenu public override bool PreDrawLogo(SpriteBatch spriteBatch, ref Vector2 logoDrawCenter, ref float logoRotation, ref float logoScale, ref Color drawColor) { DrawLogoWaterShader(spriteBatch); - + // Draw the main background for the menu. DrawMenuBackground(spriteBatch); @@ -165,17 +162,17 @@ namespace CalamityMod.MainMenu // Draw the logo. DrawLogo(spriteBatch, ref logoDrawCenter, ref logoRotation, ref logoScale, ref drawColor); - + return false; } private static void DrawLogoWaterShader(SpriteBatch sb) { sb.End(); - + Main.instance.GraphicsDevice.SetRenderTarget(logoWaterFillTarget); Main.instance.GraphicsDevice.Clear(Color.Transparent); - + sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity); var fillShader = CalamityShaders.SunkenSeaMenuLogoWater.Value; @@ -192,19 +189,19 @@ namespace CalamityMod.MainMenu fillShader.Parameters["uEdgeColor"]?.SetValue(new Color(16, 99, 112, 255 / 2).ToVector4() * 0.7f); fillShader.Parameters["uLineColor"]?.SetValue(new Color(179, 255, 255, 255 / 2).ToVector4() * 0.7f); fillShader.CurrentTechnique.Passes[0].Apply(); - + sb.Draw(LogoWaterFill.Value, Vector2.Zero, Color.White); - + sb.End(); - + Main.pixelShader.CurrentTechnique.Passes[0].Apply(); - + Main.instance.GraphicsDevice.SetRenderTarget(logoTarget); Main.instance.GraphicsDevice.Clear(Color.Transparent); sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity); - + sb.Draw(logoWaterFillTarget, new Vector2(406, 48), Color.White); - + sb.End(); Main.instance.GraphicsDevice.SetRenderTarget(null); sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.UIScaleMatrix); diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index eea2c5efbe..0afadd2e4d 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using CalamityMod.Balancing; using CalamityMod.BiomeManagers; using CalamityMod.Buffs; @@ -1020,8 +1019,8 @@ namespace CalamityMod.NPCs blazingStarShredTimer--; } npc.lifeRegenCount -= dmg; - if (damage < dmg/12) // 1/6th of the DPS dealt by Glaive Shred shows up as the indicator, unless another debuff does more per tick - damage = dmg/12; + if (damage < dmg / 12) // 1/6th of the DPS dealt by Glaive Shred shows up as the indicator, unless another debuff does more per tick + damage = dmg / 12; if (-120 * damage >= npc.lifeRegenCount) { @@ -2421,7 +2420,7 @@ namespace CalamityMod.NPCs VulnerableToSickness = true; VulnerableToWater = true; break; - #endregion + #endregion } } #endregion @@ -4730,15 +4729,13 @@ namespace CalamityMod.NPCs #endregion #region Edit Spawn Pool - internal static readonly FieldInfo MaxSpawnsField = typeof(NPC).GetField("maxSpawns", BindingFlags.NonPublic | BindingFlags.Static); - public static void AttemptToSpawnLabCritters(Player player) { if (Main.netMode == NetmodeID.MultiplayerClient) return; int spawnRate = 400; - int maxSpawnCount = (int)MaxSpawnsField.GetValue(null); + int maxSpawnCount = NPC.maxSpawns; NPCLoader.EditSpawnRate(player, ref spawnRate, ref maxSpawnCount); // Enforce a limit on the amount of enemies that can appear. @@ -4812,7 +4809,7 @@ namespace CalamityMod.NPCs return; int spawnRate = 400; - int maxSpawnCount = (int)MaxSpawnsField.GetValue(null); + int maxSpawnCount = NPC.maxSpawns; NPCLoader.EditSpawnRate(player, ref spawnRate, ref maxSpawnCount); // Enforce a limit on the amount of enemies that can appear. diff --git a/Scenes/MiscScenes/BossRushScene.cs b/Scenes/MiscScenes/BossRushScene.cs index e9f9a021b3..7ff89c21f0 100644 --- a/Scenes/MiscScenes/BossRushScene.cs +++ b/Scenes/MiscScenes/BossRushScene.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Reflection; using CalamityMod.Events; using CalamityMod.Skies; using Microsoft.Xna.Framework; @@ -11,8 +10,6 @@ namespace CalamityMod.Systems { public class BossRushScene : ModSceneEffect { - internal static readonly FieldInfo EffectsField = typeof(SkyManager).GetField("_effects", BindingFlags.NonPublic | BindingFlags.Instance); - public override int Music => BossRushEvent.MusicToPlay; public override SceneEffectPriority Priority => SceneEffectPriority.BossHigh; @@ -23,7 +20,7 @@ namespace CalamityMod.Systems // Clear all other skies, including the vanilla ones. if (isActive) { - Dictionary skies = EffectsField.GetValue(SkyManager.Instance) as Dictionary; + Dictionary skies = SkyManager.Instance._effects; bool updateRequired = false; foreach (string skyName in skies.Keys) { diff --git a/Systems/Graphic/LiquidSystem/ModLavaStyleSystem_ILEdit.cs b/Systems/Graphic/LiquidSystem/ModLavaStyleSystem_ILEdit.cs index 3d799d1fc7..9c821ee107 100644 --- a/Systems/Graphic/LiquidSystem/ModLavaStyleSystem_ILEdit.cs +++ b/Systems/Graphic/LiquidSystem/ModLavaStyleSystem_ILEdit.cs @@ -20,7 +20,7 @@ namespace CalamityMod.Systems.Graphic.LiquidSystem [Autoload(Side = ModSide.Client)] public sealed partial class ModLavaStyleSystem : ModSystem { - private static readonly MethodInfo Tex2DAssetGetter = typeof(Asset).GetProperty(nameof(Asset.Value)).GetMethod; + private static readonly MethodInfo Tex2DAssetGetter = typeof(Asset).GetProperty(nameof(Asset<>.Value)).GetMethod; private static void ApplyEdits(ManipulatorContext ctx) { diff --git a/Systems/Mechanic/DifficultyModeSystem.cs b/Systems/Mechanic/DifficultyModeSystem.cs index f0c76419f6..ff1eba5820 100644 --- a/Systems/Mechanic/DifficultyModeSystem.cs +++ b/Systems/Mechanic/DifficultyModeSystem.cs @@ -28,7 +28,6 @@ namespace CalamityMod.Systems public static List DifficultyTiers; //Difficulty modes grouped together by difficulty public static int MostAlternateDifficulties; //The most alternate difficulties at any tier that exists. Used to know the widest space to take in the ui - public static FieldInfo journeySliderCacheField; // The current value of the journey mode difficulty slider public static MethodInfo journeyDifficultyUpdateMethod; // The method which updates difficulty modes in journey mode public override void OnModLoad() @@ -40,8 +39,6 @@ namespace CalamityMod.Systems ModContent.GetInstance(), ModContent.GetInstance(), ModContent.GetInstance() }; - // Reflect private journey difficulty slider info - journeySliderCacheField = typeof(CreativePowers.DifficultySliderPower).GetField("_sliderCurrentValueCache", BindingFlags.Instance | BindingFlags.NonPublic); journeyDifficultyUpdateMethod = typeof(CreativePowers.DifficultySliderPower).GetMethod("UpdateInfoFromSliderValueCache", BindingFlags.Instance | BindingFlags.NonPublic); CalculateDifficultyData(); @@ -95,7 +92,7 @@ namespace CalamityMod.Systems if (power.GetIsUnlocked()) { int effectiveVanillaDifficulty; - var sliderValue = (float)journeySliderCacheField.GetValue(power); + var sliderValue = power._sliderCurrentValueCache; if (sliderValue == 1) { effectiveVanillaDifficulty = GameModeID.Master; @@ -181,10 +178,10 @@ namespace CalamityMod.Systems throw new ArgumentException("DifficultyModeSystemAlignJourneyDifficultySlider(): must be invoked in journey mode"); } CreativePowers.DifficultySliderPower power = CreativePowerManager.Instance.GetPower(); - var oldValue = (float)journeySliderCacheField.GetValue(power); - if (compatitableValueRanges.ContainsKey(_newGameModeID)) + var oldValue = power._sliderCurrentValueCache; + if (compatitableValueRanges.TryGetValue(_newGameModeID, out var value)) { - var (low, high) = compatitableValueRanges[_newGameModeID]; + var (low, high) = value; float valueToSet; if (oldValue >= low && oldValue < high) { @@ -194,7 +191,7 @@ namespace CalamityMod.Systems { valueToSet = low; } - journeySliderCacheField.SetValue(power, valueToSet); + power._sliderCurrentValueCache = valueToSet; journeyDifficultyUpdateMethod.Invoke(power, null); } else diff --git a/Systems/Mechanic/WorldSelectionDifficultySystem.cs b/Systems/Mechanic/WorldSelectionDifficultySystem.cs index 1fbdcf1496..e4e5b0b442 100644 --- a/Systems/Mechanic/WorldSelectionDifficultySystem.cs +++ b/Systems/Mechanic/WorldSelectionDifficultySystem.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria.GameContent.UI.Elements; @@ -51,8 +50,7 @@ namespace CalamityMod.Systems public static bool GetDeath(AWorldListItem item) { // Grab data from the listed world - FieldInfo worldDataField = typeof(UIWorldListItem).GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance); - WorldFileData worldData = (WorldFileData)worldDataField.GetValue(item); + WorldFileData worldData = item._data; if (item.Data.TryGetHeaderData(out TagCompound tag)) { @@ -71,8 +69,7 @@ namespace CalamityMod.Systems public static bool GetMalice(AWorldListItem item) { // Grab data from the listed world - FieldInfo worldDataField = typeof(UIWorldListItem).GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance); - WorldFileData worldData = (WorldFileData)worldDataField.GetValue(item); + WorldFileData worldData = item._data; int trueGameMode = worldData.GameMode; if (worldData.ForTheWorthy) diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index bd8d41c7a3..c49f5eab9c 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using Microsoft.Xna.Framework; @@ -643,11 +642,6 @@ namespace CalamityMod return false; } - // Cached for efficiency purposes. - internal static readonly FieldInfo UImageFieldMisc0 = typeof(MiscShaderData).GetField("_uImage0", BindingFlags.NonPublic | BindingFlags.Instance); - internal static readonly FieldInfo UImageFieldMisc1 = typeof(MiscShaderData).GetField("_uImage1", BindingFlags.NonPublic | BindingFlags.Instance); - internal static readonly FieldInfo UImageFieldArmor = typeof(ArmorShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); - /// /// Manually sets the texture of a instance, since vanilla's implementation only supports strings that access vanilla textures. /// @@ -658,10 +652,9 @@ namespace CalamityMod switch (index) { case 0: - UImageFieldMisc0.SetValue(shader, texture); + shader._uImage0 = texture; break; case 1: - UImageFieldMisc1.SetValue(shader, texture); break; } return shader; @@ -674,7 +667,7 @@ namespace CalamityMod /// The texture to bind. public static ArmorShaderData SetShaderTextureArmor(this ArmorShaderData shader, Asset texture) { - UImageFieldArmor.SetValue(shader, texture); + shader._uImage = texture; return shader; } diff --git a/Utilities/PlayerUtils.cs b/Utilities/PlayerUtils.cs index cfecbbb6dc..d597f965bc 100644 --- a/Utilities/PlayerUtils.cs +++ b/Utilities/PlayerUtils.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using CalamityMod.Balancing; using CalamityMod.CalPlayer; using CalamityMod.Cooldowns; @@ -613,17 +612,13 @@ namespace CalamityMod player.hurtCooldowns[i] = 0; } - private static readonly FieldInfo hurtInfoDamageField = typeof(HurtInfo).GetField("_damage", BindingFlags.Instance | BindingFlags.NonPublic); - /// /// Lifted from Fargo's. Sets the damage and knockback of an incoming hit to zero, making it not affect the player. /// /// The HurtInfo instance to nullify. public static void NullifyHit(ref this HurtInfo hurtInfo) { - object unboxedHurtInfo = hurtInfo; - hurtInfoDamageField.SetValue(unboxedHurtInfo, 0); - hurtInfo = (Player.HurtInfo)unboxedHurtInfo; + hurtInfo._damage = 0; hurtInfo.Knockback = 0; } #endregion @@ -645,7 +640,7 @@ namespace CalamityMod // Limit the amount of heal to the player's max health amount = Math.Min(amount, player.statLifeMax2 - player.statLife); - + // As well as the physical cap to how much HP can be healed amount = Math.Min(amount, BalancingConstants.LifeStealCap); @@ -697,7 +692,7 @@ namespace CalamityMod // Limit the amount of heal to the target player's max health amount = Math.Min(amount, lowestHealthCheck); - + // As well as the physical cap to how much HP can be healed amount = Math.Min(amount, BalancingConstants.LifeStealCap); @@ -997,7 +992,7 @@ namespace CalamityMod public static Vector2 ClampedMouseWorld(this Player player) { Vector2 mouseWorld = player.Calamity().mouseWorld; - + // Clamp each axis mouseWorld.X = mouseWorld.X >= player.MountedCenter.X ? MathF.Min(mouseWorld.X, player.MountedCenter.X + 960f) : MathF.Max(mouseWorld.X, player.MountedCenter.X - 960f); mouseWorld.Y = mouseWorld.Y >= player.MountedCenter.Y ? MathF.Min(mouseWorld.Y, player.MountedCenter.Y + 540f) : MathF.Max(mouseWorld.Y, player.MountedCenter.Y - 540f); diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index cb5c868395..8a789c3fd0 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -1,14 +1,11 @@ -using System.Reflection; -using CalamityMod.Items.Tools.ClimateChange; +using CalamityMod.Items.Tools.ClimateChange; using CalamityMod.NPCs.ExoMechs; using CalamityMod.NPCs.ExoMechs.Apollo; using CalamityMod.NPCs.ExoMechs.Ares; using CalamityMod.NPCs.ExoMechs.Artemis; using CalamityMod.NPCs.ExoMechs.Thanatos; -using CalamityMod.Systems; using Microsoft.Xna.Framework; using Terraria; -using Terraria.DataStructures; using Terraria.GameContent.Creative; using Terraria.GameContent.Events; using Terraria.ID; @@ -61,13 +58,11 @@ namespace CalamityMod.World if (Main.GameModeInfo.IsJourneyMode) { CreativePowers.DifficultySliderPower power = CreativePowerManager.Instance.GetPower(); - float level = (float)DifficultyModeSystem.journeySliderCacheField.GetValue(power); + float level = power._sliderCurrentValueCache; return level == 1f; } - FieldInfo findInfo = typeof(Main).GetField("_currentGameModeInfo", BindingFlags.Static | BindingFlags.NonPublic); - GameModeData data = (GameModeData)findInfo.GetValue(null); - return data.IsMasterMode; + return Main._currentGameModeInfo.IsMasterMode; } // Sunken Sea