forked from Gota7/SM64DSe-Ultimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeCompilerForm.cs
251 lines (233 loc) · 9.86 KB
/
CodeCompilerForm.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SM64DSe
{
public partial class CodeCompilerForm : Form
{
public CodeCompilerForm()
{
InitializeComponent();
}
private void btnCompile_Click(object sender, EventArgs e)
{
if (!Patcher.PatchMaker.PatchToSupportBigASMHacks())
return;
//code and patcher borrowed from NSMBe and edited.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(txtFolder.Text);
uint addr = 0x02400000;
if (btnOverlay.Checked) {
addr = new NitroOverlay(Program.m_ROM, uint.Parse(txtOverlayId.Text)).GetRAMAddr();
} else if (btnInjection.Checked) {
} else if (!btnDynamicLibrary.Checked) {
addr = uint.Parse(txtOffset.Text, System.Globalization.NumberStyles.HexNumber);
}
Patcher.PatchMaker pm = new Patcher.PatchMaker(dir, addr);
byte[] ret = null;
if (btnDynamicLibrary.Checked)
ret = pm.makeDynamicLibrary();
else if (btnOverlay.Checked) {
pm.compilePatch();
pm.makeOverlay(uint.Parse(txtOverlayId.Text));
return;
} else if (btnInjection.Checked) {
//TODO.
} else {
pm.compilePatch();
ret = pm.generatePatch();
}
if (ret == null) { return; }
bool isOut = btnExternal.Checked;
if (isOut) {
string file = txtOutput.Text;
if (txtOutput.Text == "") {
return;
}
System.IO.File.WriteAllBytes(file, ret);
} else {
if (txtInput.Text != "") {
var file = Program.m_ROM.GetFileFromName(txtInput.Text);
file.m_Data = ret;
file.SaveChanges();
}
}
}
private void btnClean_Click(object sender, EventArgs e)
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(txtFolder.Text);
Patcher.PatchCompiler.cleanPatch(dir);
}
private void btnSelectFolder_Click(object sender, EventArgs e) {
folderBrowserDialog.SelectedPath = System.IO.Path.GetDirectoryName(Program.m_ROMPath);
folderBrowserDialog.ShowDialog();
txtFolder.Text = folderBrowserDialog.SelectedPath;
}
private void btnSelectExternal_Click(object sender, EventArgs e) {
SaveFileDialog f = new SaveFileDialog();
f.RestoreDirectory = true;
if (f.ShowDialog() == DialogResult.OK) {
txtOutput.Text = f.FileName;
}
}
private void btnSelectInternal_Click(object sender, EventArgs e) {
ROMFileSelect r = new ROMFileSelect();
r.ShowDialog();
txtInput.Text = r.m_SelectedFile;
}
private void btnGeneric_CheckedChanged(object sender, EventArgs e) {
if (btnInjection.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
} else if (btnDynamicLibrary.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
} else if (btnOverlay.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = true;
txtInput.Enabled = false;
txtOutput.Enabled = false;
btnExternal.Enabled = false;
btnInternal.Enabled = false;
} else {
txtOffset.Enabled = true;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
}
}
private void btnDynamicLibrary_CheckedChanged(object sender, EventArgs e) {
if (btnInjection.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
} else if (btnDynamicLibrary.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
} else if (btnOverlay.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = true;
txtInput.Enabled = false;
txtOutput.Enabled = false;
btnExternal.Enabled = false;
btnInternal.Enabled = false;
} else {
txtOffset.Enabled = true;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
}
}
private void btnInjection_CheckedChanged(object sender, EventArgs e) {
if (btnInjection.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
} else if (btnDynamicLibrary.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
} else if (btnOverlay.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = true;
txtInput.Enabled = false;
txtOutput.Enabled = false;
btnExternal.Enabled = false;
btnInternal.Enabled = false;
} else {
txtOffset.Enabled = true;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
}
}
private void btnOverlay_CheckedChanged(object sender, EventArgs e) {
if (btnInjection.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
} else if (btnDynamicLibrary.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
} else if (btnOverlay.Checked) {
txtOffset.Enabled = false;
txtOverlayId.Enabled = true;
txtInput.Enabled = false;
txtOutput.Enabled = false;
btnExternal.Enabled = false;
btnInternal.Enabled = false;
} else {
txtOffset.Enabled = true;
txtOverlayId.Enabled = false;
txtInput.Enabled = btnInternal.Checked;
txtOutput.Enabled = btnExternal.Checked;
btnExternal.Enabled = true;
btnInternal.Enabled = true;
}
}
private void btnInternal_CheckedChanged(object sender, EventArgs e) {
if (btnExternal.Checked) {
txtInput.Enabled = false;
btnSelectInternal.Enabled = false;
txtOutput.Enabled = true;
btnSelectExternal.Enabled = true;
} else {
txtInput.Enabled = true;
btnSelectInternal.Enabled = true;
txtOutput.Enabled = false;
btnSelectExternal.Enabled = false;
}
}
private void btnExternal_CheckedChanged(object sender, EventArgs e) {
if (btnExternal.Checked) {
txtInput.Enabled = false;
btnSelectInternal.Enabled = false;
txtOutput.Enabled = true;
btnSelectExternal.Enabled = true;
} else {
txtInput.Enabled = true;
btnSelectInternal.Enabled = true;
txtOutput.Enabled = false;
btnSelectExternal.Enabled = false;
}
}
}
}