Skip to content

Commit a51db60

Browse files
committed
removed console and changed some bad code. the seed used is now written to a text file in the same directory as the randomized file
1 parent 01a5cfa commit a51db60

File tree

5 files changed

+63
-59
lines changed

5 files changed

+63
-59
lines changed

Form1.Designer.cs renamed to EditorForm.Designer.cs

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Form1.cs renamed to EditorForm.cs

+49-45
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,45 @@ namespace NSMB_Randomiser
1919
{
2020
public partial class EditorForm : Form
2121
{
22+
public EditorForm()
23+
{
24+
InitializeComponent();
25+
}
2226

2327
//Variables, lists and whatever
2428
private decimal currentSetSeed;
2529
private string overlayFilePath;
26-
private long overlayFileLength = 0;
30+
private long overlayFileSize = 0;
2731
private int[] dataNodesWorldOffsets = new int[8] { 111092, 111320, 110204, 110636, 112068, 111560, 110420, 110864 };
2832
private int[] nodesPerWorld = new int[8] { 19, 20, 18, 19, 24, 20, 18, 17 };
2933
private int[][] worldNodesAreas = new int[8][];
3034

3135
private int[] secretExitNodesAreas = { 3, 14, 26, 28, 34, 46, 58, 66, 80, 89, 99, 96, 144, 134, 135, 138 };
32-
private int[] secretExitAreasHexPos = { 111120, 111144 , 111360, 111372 , 111468 , 110256 , 110304 , 110652, 110736, 112108, 112168, 112264, 110448, 110496 , 110508, 110616 };
36+
private int[] secretExitAreasHexPos = { 111120, 111144, 111360, 111372, 111468, 110256, 110304, 110652, 110736, 112108, 112168, 112264, 110448, 110496, 110508, 110616 };
3337

34-
private int[] normalExitNodesAreas = { 0, 6, 7, 10, 17, 12, 21, 24, 37, 30, 32, 40, 44, 61, 48, 63, 51, 54, 56, 67, 69, 83, 71, 73, 76, 85, 78, 88, 102, 91, 93, 104, 94, 97, 107, 109, 122, 111, 113 , 124, 114, 116, 126, 119, 121, 129, 130, 132, 147, 141, 142, 149, 151, 153, 167, 156, 158, 171, 160, 162, 164, 165, 169, 173};
35-
private int[] normalExitAreasHexPos = { 111108, 111132, 111156, 111168, 111180, 111240, 111336, 111348, 111384, 111408 , 111432 , 111444 , 110232, 110268 , 110292 , 110328 , 110340 , 110364 , 110388 , 110664 , 110676 , 110688 , 110712 , 110748 , 110760 , 110772 , 110808 , 112084 , 112132 , 112156 , 112192 , 112204 , 112228 , 112288 , 111588 , 111612 , 111624 , 111636, 111648, 111660 , 111684 , 111696 , 111708 , 111720 , 111792 , 110436 , 110460 , 110472 , 110484 , 110628 , 110520 , 110544 , 110880 , 110892 , 110904 , 110916 , 110928 , 110940 , 110952, 110964 , 110976 , 110988 , 111000 , 111012 };
36-
38+
private int[] normalExitNodesAreas = { 0, 6, 7, 10, 17, 12, 21, 24, 37, 30, 32, 40, 44, 61, 48, 63, 51, 54, 56, 67, 69, 83, 71, 73, 76, 85, 78, 88, 102, 91, 93, 104, 94, 97, 107, 109, 122, 111, 113, 124, 114, 116, 126, 119, 121, 129, 130, 132, 147, 141, 142, 149, 151, 153, 167, 156, 158, 171, 160, 162, 164, 165, 169, 173 };
39+
private int[] normalExitAreasHexPos = { 111108, 111132, 111156, 111168, 111180, 111240, 111336, 111348, 111384, 111408, 111432, 111444, 110232, 110268, 110292, 110328, 110340, 110364, 110388, 110664, 110676, 110688, 110712, 110748, 110760, 110772, 110808, 112084, 112132, 112156, 112192, 112204, 112228, 112288, 111588, 111612, 111624, 111636, 111648, 111660, 111684, 111696, 111708, 111720, 111792, 110436, 110460, 110472, 110484, 110628, 110520, 110544, 110880, 110892, 110904, 110916, 110928, 110940, 110952, 110964, 110976, 110988, 111000, 111012 };
3740
//-----------------------------
38-
public EditorForm()
39-
{
40-
InitializeComponent();
41-
}
42-
private void ofdButton_Click(object sender, EventArgs e)
41+
private void OpenButtonClicked(object sender, EventArgs e)
4342
{;
44-
#region ofd settings
43+
#region OpenFileDialog settings
4544
OpenFileDialog ofd = new OpenFileDialog();
4645
ofd.FileName = "overlay9_8.bin";
4746
ofd.Filter = "Binary Files|*.bin|All Files|*.*";
4847
ofd.Title = "Open overlay9_8";
4948
#endregion
5049

51-
//Runs Windows File Dialog to select your overlay9_8 file
52-
Console.WriteLine("Opening Windows File Dialog...");
53-
DialogResult ofdResult = ofd.ShowDialog();
50+
//Console.WriteLine("Opening Windows File Dialog...");
51+
DialogResult ofdResult = ofd.ShowDialog(); //Runs Windows File Dialog to select your overlay9_8 file
5452
overlayFilePath = ofd.FileName;
5553
try
5654
{
57-
overlayFileLength = new FileInfo(overlayFilePath).Length;
55+
overlayFileSize = new FileInfo(overlayFilePath).Length;
5856
}
5957
catch { }
60-
if (ofdResult == DialogResult.OK && overlayFileLength == 139360)
58+
if (ofdResult == DialogResult.OK && overlayFileSize == 139360)
6159
{
62-
Console.WriteLine("Overlay filepath saved successfully!");
60+
//Console.WriteLine("Overlay filepath saved successfully!");
6361
ofdButton.Enabled = false;
6462
try
6563
{
@@ -82,21 +80,25 @@ private void ofdButton_Click(object sender, EventArgs e)
8280
}
8381

8482
}
85-
else if (ofdResult == DialogResult.Cancel) { Console.WriteLine("Please select a file!"); }
86-
else
83+
else if (ofdResult == DialogResult.Cancel)
8784
{
88-
Console.WriteLine("This Overlay file has been modified, is corrupted or is not an Overlay file at all. Please make sure you grab a freshly extracted one from your ROM!");
85+
//Console.WriteLine("Please select a file!");
86+
}
87+
else
88+
{
89+
//Console.WriteLine("This Overlay file has been modified, is corrupted or is not an Overlay file at all. Please make sure you grab a freshly extracted one from your ROM!");
90+
MessageBox.Show("This Overlay file has been modified, is corrupted or is not an Overlay file at all. Please make sure you grab a freshly extracted one from your NTSC-U ROM.","Error");
8991
}
9092
}
9193

92-
//Most of this code was used to find all the hex positions and area ID locations
93-
#region readOverlay code, unneeded
94-
/*
94+
/// <summary>
95+
/// Most of this code was used to find all the hex positions and area ID locations. Left it for reference, obsolete now
96+
/// </summary>
97+
[Obsolete]
9598
private void readOverlay()
9699
{
97100

98101
#region long ass manual (working) way to do it
99-
100102
worldNodesAreas[0] = new int[19];
101103
worldNodesAreas[1] = new int[20];
102104
worldNodesAreas[2] = new int[18];
@@ -105,16 +107,13 @@ private void readOverlay()
105107
worldNodesAreas[5] = new int[20];
106108
worldNodesAreas[6] = new int[18];
107109
worldNodesAreas[7] = new int[17];
108-
109110
#endregion
110111

111112
#region cool (broken) way to do it
112-
113113
//for (int i = 0; i < 8; i++)
114114
//{
115115
// worldNodesAreas[i] = new nodesPerWorld[i];
116116
//}
117-
118117
#endregion
119118

120119
BinaryReader br = new BinaryReader(File.Open("Temp/overlay9_8.tmp", FileMode.Open));
@@ -148,27 +147,24 @@ private void readOverlay()
148147
catch
149148
{
150149
ofdButton.Enabled = true;
151-
Console.WriteLine("Failed to read the overlay file's data.");
150+
MessageBox.Show("Failed to read the overlay file's data.","Error");
152151
}
153152
br.Close();
154153
}
155-
*/
156-
#endregion
157-
//
158154

159-
private void goButton_Click(object sender, EventArgs e)
155+
private void GoButtonClicked(object sender, EventArgs e)
160156
{
161157
//Check whether the seed check box is ticked or not, and if it is use the seed entered in that checkbox
162158
if (seedCheckBox.Checked)
163159
{
164160
currentSetSeed = seedNumericBox.Value;
165-
Console.WriteLine("Proceeding with seed: {0}", currentSetSeed);
161+
//Console.WriteLine("Proceeding with seed: {0}", currentSetSeed);
166162
}
167163
else if (!seedCheckBox.Checked)
168164
{
169165
Random tempRand = new Random();
170166
currentSetSeed = tempRand.Next();
171-
Console.WriteLine("Proceeding with random seed: {0}", currentSetSeed);
167+
//Console.WriteLine("Proceeding with random seed: {0}", currentSetSeed);
172168
}
173169
else { }
174170
goButton.Enabled = false;
@@ -180,15 +176,14 @@ private void goButton_Click(object sender, EventArgs e)
180176
int[] randomisedNormalExAreas = normalExitNodesAreas.OrderBy(x => rand.Next()).ToArray();
181177
//Write everything to the file
182178
BinaryWriter bw = new BinaryWriter(File.Open("Temp/overlay9_8.tmp", FileMode.Open, FileAccess.Write));
183-
184-
Console.WriteLine("Writing randomized normal exits to the file...");
179+
//Console.WriteLine("Writing randomized normal exits to the file...");
185180
for (int i = 0; i < 64; i++)
186181
{
187182
bw.Seek(normalExitAreasHexPos[i], 0);
188183

189184
bw.Write((byte)randomisedNormalExAreas[i]);
190185
}
191-
Console.WriteLine("Writing randomized secret exits to the file...");
186+
//Console.WriteLine("Writing randomized secret exits to the file...");
192187
for (int i = 0; i < 16; i++)
193188
{
194189
bw.Seek(secretExitAreasHexPos[i], 0);
@@ -206,17 +201,27 @@ private void goButton_Click(object sender, EventArgs e)
206201
File.Copy("Temp/overlay9_8.tmp", "Out/overlay9_8.bin", true);
207202
File.Delete("Temp/overlay9_8.tmp");
208203
Directory.Delete("Temp");
209-
Console.WriteLine("All done! Find your randomized file in the Out folder!");
210-
MessageBox.Show("All done! Find your randomized file in the Out folder!");
204+
//Console.WriteLine("All done! Find your randomized file in the Out folder!");
205+
string[] seed = new string[] { currentSetSeed.ToString() };
206+
File.WriteAllLines("Out/seed.txt",seed);
207+
MessageBox.Show("All done! Find your randomized file in the \"Out\" folder, and the seed that was used in the seed.txt!","Success!");
211208
Application.Exit();
212209

213210
}
214-
catch { Console.WriteLine("FAILED TO COPY RANDOMISED FILE, ABORT"); Application.Exit(); }
211+
catch
212+
{
213+
MessageBox.Show("Failed to copy randomized file, aborted","Critical Error!");
214+
Application.Exit();
215+
}
215216
}
216-
catch { Console.WriteLine("FAILED TO CREATE OUT DIRECTORY, ABORT"); Application.Exit(); };
217+
catch
218+
{
219+
MessageBox.Show("Failed to create out directory, aborted", "Critical Error!");
220+
Application.Exit();
221+
};
217222
}
218223

219-
private void seedCheckBox_CheckedChanged(object sender, EventArgs e)
224+
private void SeedBoxCheckChanged(object sender, EventArgs e)
220225
{
221226

222227
if (seedCheckBox.Checked)
@@ -234,10 +239,9 @@ private void seedCheckBox_CheckedChanged(object sender, EventArgs e)
234239

235240
}
236241

237-
private void EditorForm_Load(object sender, EventArgs e)
242+
private void EditorFormLoaded(object sender, EventArgs e)
238243
{
239-
Console.WriteLine("Randomizer window has loaded successfully!");
240-
244+
//Console.WriteLine("Randomizer window has loaded successfully!");
241245
}
242246
}
243247
}
File renamed without changes.

NSMB Randomiser.csproj

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{B8ECCB53-735B-45F8-9E78-DCD7BB932ECF}</ProjectGuid>
8-
<OutputType>Exe</OutputType>
8+
<OutputType>WinExe</OutputType>
99
<RootNamespace>NSMB_Randomiser</RootNamespace>
1010
<AssemblyName>NSMB Randomizer</AssemblyName>
1111
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
@@ -67,16 +67,16 @@
6767
<Reference Include="System.Xml" />
6868
</ItemGroup>
6969
<ItemGroup>
70-
<Compile Include="Form1.cs">
70+
<Compile Include="EditorForm.cs">
7171
<SubType>Form</SubType>
7272
</Compile>
73-
<Compile Include="Form1.Designer.cs">
74-
<DependentUpon>Form1.cs</DependentUpon>
73+
<Compile Include="EditorForm.Designer.cs">
74+
<DependentUpon>EditorForm.cs</DependentUpon>
7575
</Compile>
7676
<Compile Include="Program.cs" />
7777
<Compile Include="Properties\AssemblyInfo.cs" />
78-
<EmbeddedResource Include="Form1.resx">
79-
<DependentUpon>Form1.cs</DependentUpon>
78+
<EmbeddedResource Include="EditorForm.resx">
79+
<DependentUpon>EditorForm.cs</DependentUpon>
8080
</EmbeddedResource>
8181
<EmbeddedResource Include="Properties\Resources.resx">
8282
<Generator>ResXFileCodeGenerator</Generator>

Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ static void Main()
1616
{
1717
Application.EnableVisualStyles();
1818
Application.SetCompatibleTextRenderingDefault(false);
19-
Console.WriteLine("Loading...");
19+
//Console.WriteLine("Loading...");
2020
Application.Run(new EditorForm());
21-
Console.WriteLine("Randomizer window closed. You can view debug output here if necessary.");
21+
//Console.WriteLine("Randomizer window closed. You can view debug output here if necessary.");
2222
}
2323
}
2424
}

0 commit comments

Comments
 (0)