feat: Add extended zoom

This commit is contained in:
VAC committed 2026-10-16 00:38:51 -03:00
1 parent a9081d28d9
commit 2692887684
7 files changed
+55 -2

No files matched your search

+1
View File
@@ -71,6 +71,7 @@ public static class Hotkeys
Toggle("Visuals", "NightOwl", "Night Owl", () => Settings.NightOwl, v => Settings.NightOwl = v), Toggle("Visuals", "NightOwl", "Night Owl", () => Settings.NightOwl, v => Settings.NightOwl = v),
Toggle("Visuals", "Shine", "Shine", () => Settings.Shine, v => Settings.Shine = v), Toggle("Visuals", "Shine", "Shine", () => Settings.Shine, v => Settings.Shine = v),
Toggle("Visuals", "FullBright", "Full Bright", () => Settings.FullBright, v => Settings.FullBright = v), Toggle("Visuals", "FullBright", "Full Bright", () => Settings.FullBright, v => Settings.FullBright = v),
Toggle("Visuals", "ExtendedZoom", "Extended Zoom", () => Settings.ExtendedZoom, v => Settings.ExtendedZoom = v),
Toggle("World", "FreezeTime", "Freeze Time", () => Settings.FreezeTime, v => Settings.FreezeTime = v), Toggle("World", "FreezeTime", "Freeze Time", () => Settings.FreezeTime, v => Settings.FreezeTime = v),
Toggle("World", "SpawnRate", "Spawn Rate", () => Settings.SpawnRateBoost, v => Settings.SpawnRateBoost = v), Toggle("World", "SpawnRate", "Spawn Rate", () => Settings.SpawnRateBoost, v => Settings.SpawnRateBoost = v),
+1
View File
@@ -117,6 +117,7 @@ public static partial class Settings
[nameof(DangerSense)] = "Vision.DangerSense", [nameof(DangerSense)] = "Vision.DangerSense",
[nameof(BiomeSight)] = "Vision.BiomeSight", [nameof(BiomeSight)] = "Vision.BiomeSight",
[nameof(FullBright)] = "Vision.FullBright", [nameof(FullBright)] = "Vision.FullBright",
[nameof(ExtendedZoom)] = "Vision.ExtendedZoom",
[nameof(FreezeTime)] = "World.FreezeTime", [nameof(FreezeTime)] = "World.FreezeTime",
[nameof(SpawnRateBoost)] = "World.SpawnRate.Enabled", [nameof(SpawnRateBoost)] = "World.SpawnRate.Enabled",
+1 -1
View File
@@ -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 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 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 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, FullBright; public static bool Spelunker, Hunter, Shine, NightOwl, DangerSense, BiomeSight, FullBright, ExtendedZoom;
public static bool FreezeTime, SpawnRateBoost; public static bool FreezeTime, SpawnRateBoost;
public static float SpawnRateMult = 5f; public static float SpawnRateMult = 5f;
+42
View File
@@ -1,3 +1,4 @@
using System;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Mono.Cecil.Cil; using Mono.Cecil.Cil;
using MonoMod.Cil; using MonoMod.Cil;
@@ -12,6 +13,7 @@ internal static class VisionPatches
internal static void Install(HookRegistry hooks) internal static void Install(HookRegistry hooks)
{ {
FullBrightPatch.Install(hooks); FullBrightPatch.Install(hooks);
ZoomPatch.Install(hooks);
} }
} }
@@ -36,3 +38,43 @@ internal static class FullBrightPatch
body.Target = cursor.Prev; body.Target = cursor.Prev;
} }
} }
// Main.DoDraw and Main.UpdateViewZoomKeys clamp Main.GameZoomTarget to [1, 2].
internal static class ZoomPatch
{
public const float MaxZoom = 8f;
const int SearchWindow = 8;
// Tile and wall targets cover the screen plus Main.offScreenRange on each side.
public static float MinZoom => Math.Max(Main.screenWidth / (float)(Main.screenWidth + 2 * Main.offScreenRange), Main.screenHeight / (float)(Main.screenHeight + 2 * Main.offScreenRange));
internal static void Install(HookRegistry hooks)
{
hooks.Modify(HookRegistry.Method(typeof(Main), "DoDraw"), ReplaceClamps);
hooks.Modify(HookRegistry.Method(typeof(Main), nameof(Main.UpdateViewZoomKeys)), ReplaceClamps);
}
public static float Clamp(float value, float minimum, float maximum) => Settings.ExtendedZoom && Plugin.Active ? MathHelper.Clamp(value, MinZoom, MaxZoom) : MathHelper.Clamp(value, minimum, maximum);
static void ReplaceClamps(ILContext context)
{
var cursor = new ILCursor(context);
int replaced = 0;
while (cursor.TryGotoNext(MoveType.After, i => i.MatchLdsfld(typeof(Main), nameof(Main.GameZoomTarget))))
{
Instruction? instruction = cursor.Next;
for (int i = 0; i < SearchWindow && instruction is not null; i++, instruction = instruction.Next)
{
if (instruction.OpCode != OpCodes.Call || instruction.Operand is not Mono.Cecil.MethodReference { Name: "Clamp" })
continue;
instruction.Operand = context.Import(typeof(ZoomPatch).GetMethod(nameof(Clamp))!);
replaced++;
break;
}
}
if (replaced == 0)
throw new MissingMethodException(context.Method.FullName, "Clamp");
}
}
+8
View File
@@ -7,6 +7,7 @@ using Terraria.GameContent.Events;
using TerraSharp.Core; using TerraSharp.Core;
using TerraSharp.Features; using TerraSharp.Features;
using TerraSharp.Features.Combat; using TerraSharp.Features.Combat;
using TerraSharp.Patches;
using TerraSharp.Simulation; using TerraSharp.Simulation;
namespace TerraSharp.UI; namespace TerraSharp.UI;
@@ -188,6 +189,13 @@ public sealed partial class MainWindow
Group("View"); Group("View");
Toggle("Full Bright", ref Settings.FullBright); Toggle("Full Bright", ref Settings.FullBright);
if (Toggle("Extended Zoom", ref Settings.ExtendedZoom))
Sub(() =>
{
float zoom = Main.GameZoomTarget;
Slider("Zoom", ref zoom, ZoomPatch.MinZoom, ZoomPatch.MaxZoom, 1f, "{0:0.00}x");
Main.GameZoomTarget = zoom;
});
} }
void WorldPage() void WorldPage()
+1
View File
@@ -56,6 +56,7 @@ public sealed partial class MainWindow
["Danger Sense"] = "Makes traps and hazards glow.", ["Danger Sense"] = "Makes traps and hazards glow.",
["Biome Sight"] = "Makes Corruption, Crimson and Hallow blocks glow.", ["Biome Sight"] = "Makes Corruption, Crimson and Hallow blocks glow.",
["Full Bright"] = "Lights everything at full brightness.", ["Full Bright"] = "Lights everything at full brightness.",
["Extended Zoom"] = "Zoom in up to 8x and out until the edge of what the game draws.",
["Full Heal"] = "Refills health and mana.", ["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.", ["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.", ["Reset Learned Ballistics"] = "Clears learned projectile data. Learns it again as you shoot.",
+1 -1
View File
@@ -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("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("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("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, Settings.FullBright)), new Page("Visuals", VisualsPage, () => Count(Settings.Esp, Settings.Spelunker, Settings.Hunter, Settings.Shine, Settings.NightOwl, Settings.DangerSense, Settings.BiomeSight, Settings.FullBright, Settings.ExtendedZoom)),
new Page("World", WorldPage, () => Count(Settings.FreezeTime, Settings.SpawnRateBoost)), new Page("World", WorldPage, () => Count(Settings.FreezeTime, Settings.SpawnRateBoost)),
new Page("Keys", KeysPage, () => 0), new Page("Keys", KeysPage, () => 0),
]; ];