Skip to content

Commit

Permalink
removed console and changed some bad code. the seed used is now writt…
Browse files Browse the repository at this point in the history
…en to a text file in the same directory as the randomized file
  • Loading branch information
islender committed Jun 11, 2021
1 parent 01a5cfa commit a51db60
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 59 deletions.
12 changes: 6 additions & 6 deletions Form1.Designer.cs → EditorForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 49 additions & 45 deletions Form1.cs → EditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,45 @@ namespace NSMB_Randomiser
{
public partial class EditorForm : Form
{
public EditorForm()
{
InitializeComponent();
}

//Variables, lists and whatever
private decimal currentSetSeed;
private string overlayFilePath;
private long overlayFileLength = 0;
private long overlayFileSize = 0;
private int[] dataNodesWorldOffsets = new int[8] { 111092, 111320, 110204, 110636, 112068, 111560, 110420, 110864 };
private int[] nodesPerWorld = new int[8] { 19, 20, 18, 19, 24, 20, 18, 17 };
private int[][] worldNodesAreas = new int[8][];

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

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};
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 };

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 };
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 };
//-----------------------------
public EditorForm()
{
InitializeComponent();
}
private void ofdButton_Click(object sender, EventArgs e)
private void OpenButtonClicked(object sender, EventArgs e)
{;
#region ofd settings
#region OpenFileDialog settings
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = "overlay9_8.bin";
ofd.Filter = "Binary Files|*.bin|All Files|*.*";
ofd.Title = "Open overlay9_8";
#endregion

//Runs Windows File Dialog to select your overlay9_8 file
Console.WriteLine("Opening Windows File Dialog...");
DialogResult ofdResult = ofd.ShowDialog();
//Console.WriteLine("Opening Windows File Dialog...");
DialogResult ofdResult = ofd.ShowDialog(); //Runs Windows File Dialog to select your overlay9_8 file
overlayFilePath = ofd.FileName;
try
{
overlayFileLength = new FileInfo(overlayFilePath).Length;
overlayFileSize = new FileInfo(overlayFilePath).Length;
}
catch { }
if (ofdResult == DialogResult.OK && overlayFileLength == 139360)
if (ofdResult == DialogResult.OK && overlayFileSize == 139360)
{
Console.WriteLine("Overlay filepath saved successfully!");
//Console.WriteLine("Overlay filepath saved successfully!");
ofdButton.Enabled = false;
try
{
Expand All @@ -82,21 +80,25 @@ private void ofdButton_Click(object sender, EventArgs e)
}

}
else if (ofdResult == DialogResult.Cancel) { Console.WriteLine("Please select a file!"); }
else
else if (ofdResult == DialogResult.Cancel)
{
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!");
//Console.WriteLine("Please select a file!");
}
else
{
//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!");
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");
}
}

//Most of this code was used to find all the hex positions and area ID locations
#region readOverlay code, unneeded
/*
/// <summary>
/// Most of this code was used to find all the hex positions and area ID locations. Left it for reference, obsolete now
/// </summary>
[Obsolete]
private void readOverlay()
{

#region long ass manual (working) way to do it
worldNodesAreas[0] = new int[19];
worldNodesAreas[1] = new int[20];
worldNodesAreas[2] = new int[18];
Expand All @@ -105,16 +107,13 @@ private void readOverlay()
worldNodesAreas[5] = new int[20];
worldNodesAreas[6] = new int[18];
worldNodesAreas[7] = new int[17];
#endregion

#region cool (broken) way to do it
//for (int i = 0; i < 8; i++)
//{
// worldNodesAreas[i] = new nodesPerWorld[i];
//}
#endregion

BinaryReader br = new BinaryReader(File.Open("Temp/overlay9_8.tmp", FileMode.Open));
Expand Down Expand Up @@ -148,27 +147,24 @@ private void readOverlay()
catch
{
ofdButton.Enabled = true;
Console.WriteLine("Failed to read the overlay file's data.");
MessageBox.Show("Failed to read the overlay file's data.","Error");
}
br.Close();
}
*/
#endregion
//

private void goButton_Click(object sender, EventArgs e)
private void GoButtonClicked(object sender, EventArgs e)
{
//Check whether the seed check box is ticked or not, and if it is use the seed entered in that checkbox
if (seedCheckBox.Checked)
{
currentSetSeed = seedNumericBox.Value;
Console.WriteLine("Proceeding with seed: {0}", currentSetSeed);
//Console.WriteLine("Proceeding with seed: {0}", currentSetSeed);
}
else if (!seedCheckBox.Checked)
{
Random tempRand = new Random();
currentSetSeed = tempRand.Next();
Console.WriteLine("Proceeding with random seed: {0}", currentSetSeed);
//Console.WriteLine("Proceeding with random seed: {0}", currentSetSeed);
}
else { }
goButton.Enabled = false;
Expand All @@ -180,15 +176,14 @@ private void goButton_Click(object sender, EventArgs e)
int[] randomisedNormalExAreas = normalExitNodesAreas.OrderBy(x => rand.Next()).ToArray();
//Write everything to the file
BinaryWriter bw = new BinaryWriter(File.Open("Temp/overlay9_8.tmp", FileMode.Open, FileAccess.Write));

Console.WriteLine("Writing randomized normal exits to the file...");
//Console.WriteLine("Writing randomized normal exits to the file...");
for (int i = 0; i < 64; i++)
{
bw.Seek(normalExitAreasHexPos[i], 0);

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

}
catch { Console.WriteLine("FAILED TO COPY RANDOMISED FILE, ABORT"); Application.Exit(); }
catch
{
MessageBox.Show("Failed to copy randomized file, aborted","Critical Error!");
Application.Exit();
}
}
catch { Console.WriteLine("FAILED TO CREATE OUT DIRECTORY, ABORT"); Application.Exit(); };
catch
{
MessageBox.Show("Failed to create out directory, aborted", "Critical Error!");
Application.Exit();
};
}

private void seedCheckBox_CheckedChanged(object sender, EventArgs e)
private void SeedBoxCheckChanged(object sender, EventArgs e)
{

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

}

private void EditorForm_Load(object sender, EventArgs e)
private void EditorFormLoaded(object sender, EventArgs e)
{
Console.WriteLine("Randomizer window has loaded successfully!");

//Console.WriteLine("Randomizer window has loaded successfully!");
}
}
}
File renamed without changes.
12 changes: 6 additions & 6 deletions NSMB Randomiser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B8ECCB53-735B-45F8-9E78-DCD7BB932ECF}</ProjectGuid>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<RootNamespace>NSMB_Randomiser</RootNamespace>
<AssemblyName>NSMB Randomizer</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
Expand Down Expand Up @@ -67,16 +67,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="EditorForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="EditorForm.Designer.cs">
<DependentUpon>EditorForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="EditorForm.resx">
<DependentUpon>EditorForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
4 changes: 2 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Console.WriteLine("Loading...");
//Console.WriteLine("Loading...");
Application.Run(new EditorForm());
Console.WriteLine("Randomizer window closed. You can view debug output here if necessary.");
//Console.WriteLine("Randomizer window closed. You can view debug output here if necessary.");
}
}
}

0 comments on commit a51db60

Please sign in to comment.