-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
51 lines (48 loc) · 2.05 KB
/
Program.cs
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
using System;
using System.IO;
using Mono.Cecil;
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)
{
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 15 instructions before the selected one
for (var i = 0; i < 16; i++)
{
var toBeRemoved = insLoop;
insLoop = insLoop.Previous;
method.Body.Instructions.Remove(toBeRemoved);
}
break;
}
}
Console.WriteLine(method);
}
}
}
}
terrariaAsModule.Write("Terraria.exe");
}
}
}