forked from az64/mm-rando
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfMain.cs
426 lines (391 loc) · 15.2 KB
/
fMain.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MMRando
{
public partial class mmrMain : Form
{
bool Updating = false;
bool Output_VC = false;
string SettingOld = "";
int SeedOld = 0;
fAbout About = new fAbout();
fManual Manual = new fManual();
fLogicEdit LogicEditor = new fLogicEdit();
fItemEdit ItemEditor = new fItemEdit();
public static string MainDir = Application.StartupPath;
public static string MusicDir = Application.StartupPath + "\\music\\";
public static string ModsDir = Application.StartupPath + "\\mods\\";
public static string AddrsDir = Application.StartupPath + "\\addresses\\";
public static string ObjsDir = Application.StartupPath + "\\obj\\";
public static string VCDir = Application.StartupPath + "\\vc\\";
//read/write settings
private void SeedRNG()
{
RNG = new Random(Convert.ToInt32(tSeed.Text));
}
private int[] GetOptions()
{
int[] O = new int[3];
if (cUserItems.Checked) { O[0] += 8192; };
if (cAdditional.Checked) { O[0] += 4096; };
if (cGossip.Checked) { O[0] += 2048; };
if (cSoS.Checked) { O[0] += 1024; };
if (cSpoiler.Checked) { O[0] += 512; };
if (cMixSongs.Checked) { O[0] += 256; };
if (cBottled.Checked) { O[0] += 128; };
if (cDChests.Checked) { O[0] += 64; };
if (cShop.Checked) { O[0] += 32; };
if (cDEnt.Checked) { O[0] += 16; };
if (cBGM.Checked) { O[0] += 8; };
if (cEnemy.Checked) { O[0] += 4; };
if (cCutsc.Checked) { O[0] += 2; };
if (cQText.Checked) { O[0] += 1; };
O[1] = ((byte)cMode.SelectedIndex << 16) | ((byte)cLink.SelectedIndex << 8) | ((byte)cTatl.SelectedIndex) |
((byte)cDType.SelectedIndex << 24) | ((byte)cDMult.SelectedIndex << 28);
O[2] = (bTunic.BackColor.R << 16) | (bTunic.BackColor.G << 8) | (bTunic.BackColor.B) |
((byte)cFloors.SelectedIndex << 24) | ((byte)cGravity.SelectedIndex << 28);
return O;
}
private string UpdateSettingsString()
{
string Settings;
Settings = Base36.Encode(Convert.ToInt32(tSeed.Text));
Settings += "-";
int[] Options = GetOptions();
Settings += Base36.Encode(Options[0]);
Settings += "-";
Settings += Base36.Encode(Options[1]);
Settings += "-";
Settings += Base36.Encode(Options[2]);
tSString.Text = Settings;
saveROM.FileName = "MMR-" + Settings + ".z64";
saveWad.FileName = "MMR-" + Settings + ".wad";
return Settings;
}
private void SetOptions(string[] O)
{
tSeed.Text = Base36.Decode(O[0]).ToString();
int Checks = (int)Base36.Decode(O[1]);
int Combos = (int)Base36.Decode(O[2]);
int Colour = (int)Base36.Decode(O[3]);
if ((Checks & 8192) > 0) { cUserItems.Checked = true; } else { cUserItems.Checked = false; };
if ((Checks & 4096) > 0) { cAdditional.Checked = true; } else { cAdditional.Checked = false; };
if ((Checks & 2048) > 0) { cGossip.Checked = true; } else { cGossip.Checked = false; };
if ((Checks & 1024) > 0) { cSoS.Checked = true; } else { cSoS.Checked = false; };
if ((Checks & 512) > 0) { cSpoiler.Checked = true; } else { cSpoiler.Checked = false; };
if ((Checks & 256) > 0) { cMixSongs.Checked = true; } else { cMixSongs.Checked = false; };
if ((Checks & 128) > 0) { cBottled.Checked = true; } else { cBottled.Checked = false; };
if ((Checks & 64) > 0) { cDChests.Checked = true; } else { cDChests.Checked = false; };
if ((Checks & 32) > 0) { cShop.Checked = true; } else { cShop.Checked = false; };
if ((Checks & 16) > 0) { cDEnt.Checked = true; } else { cDEnt.Checked = false; };
if ((Checks & 8) > 0) { cBGM.Checked = true; } else { cBGM.Checked = false; };
if ((Checks & 4) > 0) { cEnemy.Checked = true; } else { cEnemy.Checked = false; };
if ((Checks & 2) > 0) { cCutsc.Checked = true; } else { cCutsc.Checked = false; };
if ((Checks & 1) > 0) { cQText.Checked = true; } else { cQText.Checked = false; };
cDMult.SelectedIndex = (int)((Combos & 0xF0000000) >> 28);
cDType.SelectedIndex = (Combos & 0xF000000) >> 24;
cMode.SelectedIndex = (Combos & 0xFF0000) >> 16;
cLink.SelectedIndex = (Combos & 0xFF00) >> 8;
cTatl.SelectedIndex = Combos & 0xFF;
cGravity.SelectedIndex = (int)((Colour & 0xF0000000) >> 28);
cFloors.SelectedIndex = (Colour & 0xF000000) >> 24;
bTunic.BackColor = Color.FromArgb((Colour & 0xFF0000) >> 16, (Colour & 0xFF00) >> 8, Colour & 0xFF);
}
private void DecodeSettings(string Settings)
{
SetOptions(Settings.Split('-'));
saveROM.FileName = "MMR-" + Settings + ".z64";
saveWad.FileName = "MMR-" + Settings + ".wad";
}
//form functions
public mmrMain()
{
InitializeComponent();
}
private void EnableBoxes()
{
if (cMode.SelectedIndex == 2)
{
cMixSongs.Enabled = false;
cSoS.Enabled = false;
cDChests.Enabled = false;
cDEnt.Enabled = false;
cBottled.Enabled = false;
cShop.Enabled = false;
cSpoiler.Enabled = false;
cGossip.Enabled = false;
cAdditional.Enabled = false;
cUserItems.Enabled = false;
}
else
{
cMixSongs.Enabled = true;
cSoS.Enabled = true;
cDChests.Enabled = true;
cDEnt.Enabled = true;
cBottled.Enabled = true;
cShop.Enabled = true;
cSpoiler.Enabled = true;
cGossip.Enabled = true;
cAdditional.Enabled = true;
cUserItems.Enabled = true;
};
if (cUserItems.Checked)
{
cSoS.Enabled = false;
cDChests.Enabled = false;
cBottled.Enabled = false;
cShop.Enabled = false;
cAdditional.Enabled = false;
}
else
{
if (cMode.SelectedIndex != 2)
{
cSoS.Enabled = true;
cDChests.Enabled = true;
cBottled.Enabled = true;
cShop.Enabled = true;
cAdditional.Enabled = true;
};
};
}
private void mmrMain_Load(object sender, EventArgs e)
{
// initialise some stuff
Updating = true;
cDMult.SelectedIndex = 0;
cDType.SelectedIndex = 0;
cGravity.SelectedIndex = 0;
cFloors.SelectedIndex = 0;
cMode.SelectedIndex = 0;
cLink.SelectedIndex = 0;
cTatl.SelectedIndex = 0;
cSpoiler.Checked = true;
cSoS.Checked = true;
cGossip.Checked = true;
//cQText.Checked = true;
//cCutsc.Checked = true;
bTunic.BackColor = Color.FromArgb(0x1E, 0x69, 0x1B);
tSeed.Text = Math.Abs(Environment.TickCount).ToString();
SettingOld = UpdateSettingsString();
Updating = false;
}
private void bTunic_Click(object sender, EventArgs e)
{
Updating = true;
cTunic.ShowDialog();
bTunic.BackColor = cTunic.Color;
UpdateSettingsString();
Updating = false;
}
private void bopen_Click(object sender, EventArgs e)
{
openROM.ShowDialog();
tROMName.Text = openROM.FileName;
}
private void bRandomise_Click(object sender, EventArgs e)
{
SeedRNG();
if (cMode.SelectedIndex != 2)
{
ReadRulesetItemData();
//check if entrance shuffle is on
if (cDEnt.Checked) { EntranceShuffle(); };
int[] OathReq = new int[] { 100, 103, 108, 113 };
ItemList[97].Dependence = new List<int>();
ItemList[97].Dependence.Add(OathReq[RNG.Next(4)]);
ItemShuffle();
//gossip
SeedRNG();
MakeGossipQuotes();
};
//tatl colour
SeedRNG();
SetTatlColour();
//bgm sort
SeedRNG();
SortBGM();
if ((tROMName.Text != "") && (File.Exists(tROMName.Text)))
{
if (saveROM.ShowDialog() == DialogResult.OK)
{
if (saveROM.FileName != "")
{
if (ValidateROM(tROMName.Text))
{
if (Output_VC)
{
if (saveWad.ShowDialog() != DialogResult.OK)
{
MessageBox.Show("Output file not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
};
};
MakeROM(tROMName.Text, saveROM.FileName);
MessageBox.Show("Successfully built output ROM!", "Success", MessageBoxButtons.OK, MessageBoxIcon.None);
}
else
{
MessageBox.Show("Cannot verify input ROM is Majora's Mask (U).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
}
else
{
MessageBox.Show("Output file not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
}
else
{
MessageBox.Show("No output selected; ROM will not be saved.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
};
}
else
{
MessageBox.Show("Input ROM not selected or doesn't exist, cannot generate output.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
};
}
private void tSString_Enter(object sender, EventArgs e)
{
SettingOld = tSString.Text;
Updating = true;
}
private void tSString_Leave(object sender, EventArgs e)
{
try
{
DecodeSettings(tSString.Text);
}
catch
{
tSString.Text = SettingOld;
DecodeSettings(tSString.Text);
MessageBox.Show("Settings string is invalid; reverted to previous settings.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
Updating = false;
}
private void tSString_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
cDummy.Select();
};
}
private void tSeed_Enter(object sender, EventArgs e)
{
SeedOld = Convert.ToInt32(tSeed.Text);
Updating = true;
}
private void tSeed_Leave(object sender, EventArgs e)
{
try
{
int s = Convert.ToInt32(tSeed.Text);
if (s < 0)
{
s = Math.Abs(s);
tSeed.Text = s.ToString();
MessageBox.Show("Seed must be positive", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
};
}
catch
{
tSeed.Text = SeedOld.ToString();
MessageBox.Show("Invalid seed: must be a positive integer.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
UpdateSettingsString();
Updating = false;
}
private void tSeed_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
cDummy.Select();
};
}
private void cSpoiler_CheckedChanged(object sender, EventArgs e)
{
EnableBoxes();
if (!Updating)
{
Updating = true;
UpdateSettingsString();
Updating = false;
};
}
private void cMode_SelectedIndexChanged(object sender, EventArgs e)
{
EnableBoxes();
if (!Updating)
{
if (cMode.SelectedIndex == 3)
{
if (openLogic.ShowDialog() == DialogResult.OK)
{
//do nothing?
}
else
{
cMode.SelectedIndex = 0;
};
};
Updating = true;
UpdateSettingsString();
Updating = false;
};
}
private void cVC_CheckedChanged(object sender, EventArgs e)
{
Output_VC = cVC.Checked;
}
private void mExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void mAbout_Click(object sender, EventArgs e)
{
About.ShowDialog();
}
private void mManual_Click(object sender, EventArgs e)
{
Manual.Show();
}
private void mByteswap_Click(object sender, EventArgs e)
{
if (openBROM.ShowDialog() == DialogResult.OK)
{
int r = ROMFuncs.ByteswapROM(openBROM.FileName);
switch (r)
{
case 0:
MessageBox.Show("Successfully byteswapped ROM.", "Success", MessageBoxButtons.OK, MessageBoxIcon.None);
break;
case 1:
MessageBox.Show("ROM appears to be big endian.", "Success", MessageBoxButtons.OK, MessageBoxIcon.None);
break;
default:
MessageBox.Show("Could not byteswap ROM.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
};
};
}
private void mLogicEdit_Click(object sender, EventArgs e)
{
LogicEditor.Show();
}
private void mItemIncl_Click(object sender, EventArgs e)
{
ItemEditor.Show();
}
}
}