-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
80 lines (72 loc) · 3.61 KB
/
Program.cs
File metadata and controls
80 lines (72 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Mono.Cecil;
using System.IO;
namespace TerrariaZoomPatcher
{
class Program
{
static void Main(string[] args)
{
var terrariaPath = args.Length == 0 ? Path.Combine(Directory.GetCurrentDirectory(), "Terraria.exe") : args[0];
if (!File.Exists(terrariaPath)) return;
var newTerrariaPath = Path.Combine(Path.GetDirectoryName(terrariaPath), "Terraria.exe.bak");
if (File.Exists(newTerrariaPath)) File.Delete(newTerrariaPath);
File.Move(terrariaPath, newTerrariaPath);
ModuleDefinition terrariaAsModule = ModuleDefinition.ReadModule(newTerrariaPath);
foreach (var type in terrariaAsModule.Types)
{
if (type.Name == "Main")
{
foreach (var method in type.Methods)
{
// Allow for drawing wider than 1920 + 192 * 2
if (method.Name == ".cctor")
{
foreach (var instruction in method.Body.Instructions)
{
if (instruction.ToString().Contains("Terraria.Main::MaxWorldViewSize"))
{
// keeping it safe so that x + 192 * 2 < 4096
// above 4096 might be possible on Windows
instruction.Previous.Previous.Operand = 3711; // default 1200
instruction.Previous.Previous.Previous.Operand = 3711; // default 1920
}
}
}
// Changing MaxWorldViewSize throws off the high res detection so just always force it
if (method.Name == "LoadContent_TryEnteringHiDef")
{
foreach (var instruction in method.Body.Instructions)
{
if (instruction.ToString().Contains("Support4K") && instruction.Previous.Previous.ToString().Contains("IsXna"))
{
instruction.Next.Operand = ((Mono.Cecil.Cil.Instruction)instruction.Next.Operand).Next.Next; // Jump two ins further
}
}
}
// Remove the force zoom instructions
if (method.Name == "DoDraw")
{
foreach (var instruction in method.Body.Instructions)
{
if (instruction.ToString().Contains("ForcedMinimumZoom") &&
instruction.Previous.ToString().Contains("Max"))
{
var insLoop = instruction;
// remove 20 instructions before the selected one
for (var i = 0; i < 20; i++)
{
var toBeRemoved = insLoop;
insLoop = insLoop.Previous;
method.Body.Instructions.Remove(toBeRemoved);
}
break;
}
}
}
}
}
}
terrariaAsModule.Write("Terraria.exe");
}
}
}