diff --git a/src/TerraSharp/Core/Hotkeys.cs b/src/TerraSharp/Core/Hotkeys.cs index d308544..42d6022 100644 --- a/src/TerraSharp/Core/Hotkeys.cs +++ b/src/TerraSharp/Core/Hotkeys.cs @@ -70,6 +70,7 @@ public static class Hotkeys Toggle("Visuals", "BiomeSight", "Biome Sight", () => Settings.BiomeSight, v => Settings.BiomeSight = v), Toggle("Visuals", "NightOwl", "Night Owl", () => Settings.NightOwl, v => Settings.NightOwl = v), Toggle("Visuals", "Shine", "Shine", () => Settings.Shine, v => Settings.Shine = v), + Toggle("Visuals", "FullBright", "Full Bright", () => Settings.FullBright, v => Settings.FullBright = v), Toggle("World", "FreezeTime", "Freeze Time", () => Settings.FreezeTime, v => Settings.FreezeTime = v), Toggle("World", "SpawnRate", "Spawn Rate", () => Settings.SpawnRateBoost, v => Settings.SpawnRateBoost = v), diff --git a/src/TerraSharp/Core/Settings.Json.cs b/src/TerraSharp/Core/Settings.Json.cs index 9c7d37b..9b0e06d 100644 --- a/src/TerraSharp/Core/Settings.Json.cs +++ b/src/TerraSharp/Core/Settings.Json.cs @@ -116,6 +116,7 @@ public static partial class Settings [nameof(NightOwl)] = "Vision.NightOwl", [nameof(DangerSense)] = "Vision.DangerSense", [nameof(BiomeSight)] = "Vision.BiomeSight", + [nameof(FullBright)] = "Vision.FullBright", [nameof(FreezeTime)] = "World.FreezeTime", [nameof(SpawnRateBoost)] = "World.SpawnRate.Enabled", diff --git a/src/TerraSharp/Core/Settings.cs b/src/TerraSharp/Core/Settings.cs index 0dbfb20..375b656 100644 --- a/src/TerraSharp/Core/Settings.cs +++ b/src/TerraSharp/Core/Settings.cs @@ -48,7 +48,7 @@ public static partial class Settings public static Color ColLocal = Color.White, ColPlayers = new(70, 200, 255), ColHostile = new(235, 60, 60), ColCritters = new(200, 170, 120), ColTown = new(80, 220, 110), ColBoss = new(255, 120, 40), ColItems = new(255, 210, 70), ColProjHostile = new(255, 80, 200), ColProjFriendly = new(120, 160, 255), ColWaypoint = new(220, 90, 255); public static bool DamageMelee, DamageRanged, DamageMagic, DamageSummon; public static Color ColDamageMelee = new(255, 110, 60), ColDamageRanged = new(120, 230, 90), ColDamageMagic = new(90, 150, 255), ColDamageSummon = new(200, 110, 255); - public static bool Spelunker, Hunter, Shine, NightOwl, DangerSense, BiomeSight; + public static bool Spelunker, Hunter, Shine, NightOwl, DangerSense, BiomeSight, FullBright; public static bool FreezeTime, SpawnRateBoost; public static float SpawnRateMult = 5f; diff --git a/src/TerraSharp/Patches/HookRegistry.cs b/src/TerraSharp/Patches/HookRegistry.cs index 0e3c3dc..6be9a55 100644 --- a/src/TerraSharp/Patches/HookRegistry.cs +++ b/src/TerraSharp/Patches/HookRegistry.cs @@ -22,6 +22,7 @@ internal sealed class HookRegistry : IDisposable PlayerPatches.Install(hooks); NpcPatches.Install(hooks); DamageNumberPatches.Install(hooks); + VisionPatches.Install(hooks); SpawnRatePatch.Install(hooks); ItemCheckShootPatch.Install(hooks); SandboxGuards.Install(hooks); diff --git a/src/TerraSharp/Patches/VisionPatches.cs b/src/TerraSharp/Patches/VisionPatches.cs new file mode 100644 index 0000000..c32fb4a --- /dev/null +++ b/src/TerraSharp/Patches/VisionPatches.cs @@ -0,0 +1,38 @@ +using Microsoft.Xna.Framework; +using Mono.Cecil.Cil; +using MonoMod.Cil; +using Terraria; +using Terraria.Graphics.Light; +using TerraSharp.Core; + +namespace TerraSharp.Patches; + +internal static class VisionPatches +{ + internal static void Install(HookRegistry hooks) + { + FullBrightPatch.Install(hooks); + } +} + +// Every Lighting query reaches the active engine's GetColor, millions of times per frame, so the check is a bare field load. +internal static class FullBrightPatch +{ + internal static void Install(HookRegistry hooks) + { + hooks.Modify(HookRegistry.Method(typeof(LightingEngine), nameof(LightingEngine.GetColor)), ReturnWhite); + hooks.Modify(HookRegistry.Method(typeof(LegacyLighting), nameof(LegacyLighting.GetColor)), ReturnWhite); + } + + static void ReturnWhite(ILContext context) + { + var cursor = new ILCursor(context); + ILLabel body = cursor.DefineLabel(); + cursor.Emit(OpCodes.Ldsfld, typeof(Settings).GetField(nameof(Settings.FullBright))!); + cursor.Emit(OpCodes.Brfalse, body); + cursor.Emit(OpCodes.Call, typeof(Vector3).GetProperty(nameof(Vector3.One))!.GetGetMethod()!); + cursor.Emit(OpCodes.Ret); + cursor.Emit(OpCodes.Nop); + body.Target = cursor.Prev; + } +} diff --git a/src/TerraSharp/UI/MainWindow.Pages.cs b/src/TerraSharp/UI/MainWindow.Pages.cs index 2ce8af7..db4921f 100644 --- a/src/TerraSharp/UI/MainWindow.Pages.cs +++ b/src/TerraSharp/UI/MainWindow.Pages.cs @@ -185,6 +185,9 @@ public sealed partial class MainWindow ToggleColor("Melee", ref Settings.DamageMelee, ref Settings.ColDamageMelee, nameof(Settings.ColDamageMelee)); ToggleColor("Ranged", ref Settings.DamageRanged, ref Settings.ColDamageRanged, nameof(Settings.ColDamageRanged)); ToggleColor("Summon", ref Settings.DamageSummon, ref Settings.ColDamageSummon, nameof(Settings.ColDamageSummon)); + + Group("View"); + Toggle("Full Bright", ref Settings.FullBright); } void WorldPage() diff --git a/src/TerraSharp/UI/MainWindow.Tooltips.cs b/src/TerraSharp/UI/MainWindow.Tooltips.cs index 33ba9c2..008d163 100644 --- a/src/TerraSharp/UI/MainWindow.Tooltips.cs +++ b/src/TerraSharp/UI/MainWindow.Tooltips.cs @@ -55,6 +55,7 @@ public sealed partial class MainWindow ["Night Owl"] = "Brightens dark areas.", ["Danger Sense"] = "Makes traps and hazards glow.", ["Biome Sight"] = "Makes Corruption, Crimson and Hallow blocks glow.", + ["Full Bright"] = "Lights everything at full brightness.", ["Full Heal"] = "Refills health and mana.", ["TP to Spawn"] = "Recalls like a Magic Mirror: to your bed if set, otherwise the world's spawn point.", ["Reset Learned Ballistics"] = "Clears learned projectile data. Learns it again as you shoot.", diff --git a/src/TerraSharp/UI/MainWindow.cs b/src/TerraSharp/UI/MainWindow.cs index f586ce5..3642df8 100644 --- a/src/TerraSharp/UI/MainWindow.cs +++ b/src/TerraSharp/UI/MainWindow.cs @@ -34,7 +34,7 @@ public sealed partial class MainWindow : Window new Page("Movement", MovementPage, () => Count(Settings.Fly, Settings.SuperSpeed, Settings.HighJump, Settings.GravityFlip, Settings.NoFallDamage, Settings.LavaImmune, Settings.WaterWalk, Settings.NoKnockback, Settings.ExtendedReach)), new Page("Combat", CombatPage, () => Count(Settings.RapidAttack, Settings.AutoSwing, Settings.DamageBoost, Settings.NoManaCost, Settings.NoSpread, Settings.Aimbot, Settings.AutoAttack, Settings.KillAura, Settings.HitMagnet, Settings.FreezeEnemies, Settings.WeakenEnemies)), new Page("Items", ItemsPage, () => Count(Settings.InstantBreak, Settings.InfItems, Settings.ItemVacuum, Settings.AutoFish, Settings.Sonar)), - new Page("Visuals", VisualsPage, () => Count(Settings.Esp, Settings.Spelunker, Settings.Hunter, Settings.Shine, Settings.NightOwl, Settings.DangerSense, Settings.BiomeSight)), + new Page("Visuals", VisualsPage, () => Count(Settings.Esp, Settings.Spelunker, Settings.Hunter, Settings.Shine, Settings.NightOwl, Settings.DangerSense, Settings.BiomeSight, Settings.FullBright)), new Page("World", WorldPage, () => Count(Settings.FreezeTime, Settings.SpawnRateBoost)), new Page("Keys", KeysPage, () => 0), ];