-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
135 lines (104 loc) · 3.62 KB
/
Program.cs
File metadata and controls
135 lines (104 loc) · 3.62 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
namespace Pluton.Patcher
{
using System;
using System.IO;
using System.Linq;
using Reflection;
class MainClass
{
public static AssemblyPatcher rustAssembly;
public static string Version { get; } = typeof(MainClass).Assembly.GetName().Version.ToString();
internal static bool gendiffs = false;
internal static bool newAssCS = false;
internal static bool LogToFile = false;
internal static string LogFile = "Pluton.Patcher.log";
public static string GetHtmlDiff(string a, string b)
{
var dmp = new DiffMatchPatch.diff_match_patch();
var diffmain = dmp.diff_main(a, b);
dmp.diff_cleanupSemantic(diffmain);
return "<div id='hook_diff'><pre>" + dmp.diff_prettyHtml(diffmain) + "</pre></div>";
}
public static int Main(string[] args)
{
bool interactive = args.Length > 0;
gendiffs = args.Any(arg => arg == "--generatediffs" || arg == "-gd");
string logfile = (from arg in args
where arg.StartsWith("--logFile:", StringComparison.Ordinal) || arg.StartsWith("-l:", StringComparison.Ordinal)
select arg.Split(':').Last()).FirstOrDefault();
LogFile = !String.IsNullOrEmpty(logfile) ? logfile : LogFile;
LogToFile = !String.IsNullOrEmpty(logfile);
if (gendiffs)
MethodDB.GetInstance();
newAssCS = true;
Log($"[( Pluton Patcher v{Version} )]");
rustAssembly = AssemblyPatcher.GetPatcher("Assembly-CSharp.dll");
if (rustAssembly.GetType("PlutonPatched") != null) {
LogError("Assembly-CSharp.dll is already patched!");
if (interactive)
System.Threading.Thread.Sleep(250);
return (int)ExitCode.ACDLL_ALREADY_PATCHED;
}
foreach (var json in Directory.GetFiles("./", "*.json")) {
JSON.Array jsonArr = JSON.Array.Parse(File.ReadAllText(json));
foreach (JSON.Value jsonElmnt in jsonArr) {
JSON.Object jsonObj = jsonElmnt.Obj;
var assemblyPatch = AssemblyPatch.ParseFromJSON(jsonObj);
if (!assemblyPatch.Patch()) {
LogError("Failed to patch!");
if (interactive)
System.Threading.Thread.Sleep(250);
return (int)ExitCode.ACDLL_GENERIC_PATCH_ERR;
}
}
}
if (gendiffs) {
MethodDB.GetInstance().Save();
string diffs = MethodDB.GetDifferences();
if (!String.IsNullOrEmpty(diffs))
File.WriteAllText($"diffs-{DateTime.Now.ToShortDateString()}{DateTime.Now.ToShortTimeString()}.html".Replace('\\', '_').Replace('/', '_'), "<html><head><style>del,ins{text-decoration:none}ins{background-color:#0F0}del{color:#999;background-color:#F00}</style></head><body>" + diffs + "</body></html>");
}
Log("Completed!");
if (interactive)
System.Threading.Thread.Sleep(250);
return (int)ExitCode.SUCCESS;
}
public static void Log(string log)
{
if (LogToFile) File.AppendAllText(LogFile, log);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(log);
}
public static void LogLine(string log)
{
if (LogToFile) File.AppendAllText(LogFile, log + Environment.NewLine);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(log);
}
public static void LogError(string log)
{
if (LogToFile) File.AppendAllText(LogFile, log);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(log);
}
public static void LogErrorLine(string log)
{
if (LogToFile) File.AppendAllText(LogFile, log + Environment.NewLine);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(log);
}
public static void LogException(Exception ex)
{
LogErrorLine(ex.ToString());
}
}
public enum ExitCode
{
SUCCESS = 0,
DLL_MISSING = 10,
DLL_READ_ERROR = 20,
DLL_WRITE_ERROR = 21,
ACDLL_ALREADY_PATCHED = 30,
ACDLL_GENERIC_PATCH_ERR = 40
}
}