Skip to content

Commit

Permalink
Added FireFlower support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGameratorT committed Apr 26, 2021
1 parent ec96580 commit 1ab4f57
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 33 deletions.
43 changes: 25 additions & 18 deletions NSMBe5/LevelChooser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,11 @@
using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using NSMBe5.DSFileSystem;
using NSMBe5.NSBMD;
using NSMBe5.Patcher;
using System.Net;
using System.Diagnostics;
using System.Threading.Tasks;

namespace NSMBe5 {
public partial class LevelChooser : Form
Expand Down Expand Up @@ -104,8 +96,8 @@ private void LevelChooser_Load(object sender, EventArgs e)
}


this.Text = "NSMB Editor 5.3.2 - " + ROM.filename;
label3.Text = "NSMB Editor 5.3.2 " + Properties.Resources.version.Trim();
this.Text = "NSMB Editor 5.3.3 - " + ROM.filename;
label3.Text = "NSMB Editor 5.3.3 " + Properties.Resources.version.Trim();
this.Icon = Properties.Resources.nsmbe;

if (!ROM.isNSMBRom)
Expand All @@ -117,7 +109,13 @@ private void LevelChooser_Load(object sender, EventArgs e)
musicSlotsGrp.Enabled = false;
}

// new LevelEditor("A01_1", "LOL").Show();
// new LevelEditor("A01_1", "LOL").Show();

if (Properties.Settings.Default.UseFireflower)
{
makeinsert.Text = "Run 'fireflower' and insert";
makeclean.Text = "Clean build";
}
}


Expand Down Expand Up @@ -658,13 +656,22 @@ private void decompArm9Bin_Click(object sender, EventArgs e)

private void makeinsert_Click(object sender, EventArgs e)
{
PatchMaker pm = new PatchMaker(ROM.romfile.Directory);
string hookmap;
string replaces;
pm.insertCode(ROM.romfile.Directory, out hookmap, out replaces);
pm.restore();
pm.compilePatch();
pm.generatePatch(hookmap, replaces);
if (Properties.Settings.Default.UseFireflower)
{
PatchMakerFF pmff = new PatchMakerFF(ROM.romfile.Directory);
pmff.compilePatch();
pmff.importPatch();
}
else
{
PatchMaker pm = new PatchMaker(ROM.romfile.Directory);
string hookmap;
string replaces;
pm.insertCode(ROM.romfile.Directory, out hookmap, out replaces);
pm.restore();
pm.compilePatch();
pm.generatePatch(hookmap, replaces);
}
}

private void makeclean_Click(object sender, EventArgs e)
Expand Down
1 change: 1 addition & 0 deletions NSMBe5/NSMBe5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
<DependentUpon>ObjectPickerControlNew.cs</DependentUpon>
</Compile>
<Compile Include="Patcher\PatchCompiler.cs" />
<Compile Include="Patcher\PatchMakerFF.cs" />
<Compile Include="Patcher\PatchMaker.cs" />
<Compile Include="PickerTest.cs">
<SubType>Form</SubType>
Expand Down
30 changes: 27 additions & 3 deletions NSMBe5/Patcher/PatchCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

namespace NSMBe5.Patcher
{
Expand All @@ -31,9 +30,34 @@ public static int compilePatch(uint destAddr, DirectoryInfo romDir)
return runProcess("make CODEADDR=0x" + destAddr.ToString("X8"), romDir.FullName);
}

public static int compilePatchFF(DirectoryInfo romDir)
{
return runProcess("fireflower", romDir.FullName);
}

public static int cleanPatch(DirectoryInfo romDir)
{
return runProcess("make clean", romDir.FullName);
if (Properties.Settings.Default.UseFireflower)
{
string path = Path.Combine(romDir.FullName, "build");
if (Directory.Exists(path))
{
try
{
Directory.Delete(path, true);
MessageBox.Show("Done!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
return 0;
}
else
{
return runProcess("make clean", romDir.FullName);
}
}

public static int runProcess(string proc, string cwd)
Expand Down
111 changes: 111 additions & 0 deletions NSMBe5/Patcher/PatchMakerFF.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* This file is part of NSMB Editor 5.
*
* NSMB Editor 5 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NSMB Editor 5 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NSMB Editor 5. If not, see <http://www.gnu.org/licenses/>.
*/

using System.IO;

namespace NSMBe5.Patcher
{
public class PatchMakerFF
{
DirectoryInfo romdir;
private string codedir;
private static readonly byte[] dummyFnt = { 0x08, 0x00, 0x00, 0x00, 0x83, 0x0, 0x1, 0x00, 0x00 };

public PatchMakerFF(DirectoryInfo romdir)
{
this.romdir = romdir;
this.codedir = Path.Combine(romdir.FullName, "__tmp");
}

public void compilePatch()
{
byte[] contents1 = ROM.arm9binFile.getContents();
byte[] contents2 = ROM.arm9ovFile.getContents();
byte[] contents3 = ROM.arm7binFile.getContents();
byte[] contents4 = ROM.arm7ovFile.getContents();
byte[] contents5 = ROM.headerFile.getContents();

Directory.CreateDirectory(codedir);
Directory.CreateDirectory(codedir + "/root");
Directory.CreateDirectory(codedir + "/overlay9");
Directory.CreateDirectory(codedir + "/overlay7");

File.WriteAllBytes(codedir + "/arm9.bin", contents1);
File.WriteAllBytes(codedir + "/arm9ovt.bin", contents2);
File.WriteAllBytes(codedir + "/arm7.bin", contents3);
File.WriteAllBytes(codedir + "/arm7ovt.bin", contents4);
File.WriteAllBytes(codedir + "/header.bin", contents5);
File.WriteAllBytes(codedir + "/fnt.bin", dummyFnt);

DSFileSystem.Directory dirByPath1 = ROM.FS.getDirByPath("overlay9");
DSFileSystem.Directory dirByPath2 = ROM.FS.getDirByPath("overlay7");

foreach (DSFileSystem.File childrenFile in dirByPath1.childrenFiles)
File.WriteAllBytes(codedir + "/overlay9/" + childrenFile.name, childrenFile.getContents());

foreach (DSFileSystem.File childrenFile in dirByPath2.childrenFiles)
File.WriteAllBytes(codedir + "/overlay7/" + childrenFile.name, childrenFile.getContents());

PatchCompiler.compilePatchFF(romdir);
}

public void importPatch()
{
byte[] newFile1 = File.ReadAllBytes(codedir + "/arm9.bin");
byte[] newFile2 = File.ReadAllBytes(codedir + "/arm9ovt.bin");
byte[] newFile3 = File.ReadAllBytes(codedir + "/arm7.bin");
byte[] newFile4 = File.ReadAllBytes(codedir + "/arm7ovt.bin");

ROM.arm9binFile.beginEdit(this);
ROM.arm9ovFile.beginEdit(this);
ROM.arm7binFile.beginEdit(this);
ROM.arm7ovFile.beginEdit(this);

ROM.arm9binFile.replace(newFile1, this);
ROM.arm9ovFile.replace(newFile2, this);
ROM.arm7binFile.replace(newFile3, this);
ROM.arm7ovFile.replace(newFile4, this);

ROM.arm9binFile.endEdit(this);
ROM.arm9ovFile.endEdit(this);
ROM.arm7binFile.endEdit(this);
ROM.arm7ovFile.endEdit(this);

DirectoryInfo directoryInfo1 = new DirectoryInfo(codedir + "/overlay9");
DirectoryInfo directoryInfo2 = new DirectoryInfo(codedir + "/overlay7");

foreach (FileInfo file in directoryInfo1.GetFiles())
{
byte[] newFile5 = File.ReadAllBytes(file.FullName);
DSFileSystem.File fileByName = ROM.FS.getFileByName(file.Name);
fileByName.beginEdit(this);
fileByName.replace(newFile5, this);
fileByName.endEdit(this);
}
foreach (FileInfo file in directoryInfo2.GetFiles())
{
byte[] newFile5 = File.ReadAllBytes(file.FullName);
DSFileSystem.File fileByName = ROM.FS.getFileByName(file.Name);
fileByName.beginEdit(this);
fileByName.replace(newFile5, this);
fileByName.endEdit(this);
}

Directory.Delete(codedir, true);
}
}
}
6 changes: 3 additions & 3 deletions NSMBe5/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright © Treeki and Dirbaio 2019, further maintained by TheGameratorT, Szymbar 2020")]
[assembly: AssemblyCopyright("Copyright © Treeki and Dirbaio 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.3.2.0")]
[assembly: AssemblyFileVersion("5.3.2.0")]
[assembly: AssemblyVersion("5.3.3.0")]
[assembly: AssemblyFileVersion("5.3.3.0")]
22 changes: 17 additions & 5 deletions NSMBe5/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions NSMBe5/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@
<Setting Name="using_signboard_asm" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="UseFireflower" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
9 changes: 6 additions & 3 deletions NSMBe5/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
<value>5</value>
</setting>
<setting name="BackupFiles" serializeAs="String">
<value/>
<value />
</setting>
<setting name="ROMFolder" serializeAs="String">
<value/>
<value />
</setting>
<setting name="LevelMaximized" serializeAs="String">
<value>False</value>
Expand All @@ -50,11 +50,14 @@
<value>False</value>
</setting>
<setting name="ROMPath" serializeAs="String">
<value/>
<value />
</setting>
<setting name="using_signboard_asm" serializeAs="String">
<value>False</value>
</setting>
<setting name="UseFireflower" serializeAs="String">
<value>False</value>
</setting>
</NSMBe5.Properties.Settings>
</userSettings>
<System.Windows.Forms.ApplicationConfigurationSection>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NSMB-Editor
Forked from https://github.com/Mero-Mero/NSMB-Editor originally by https://github.com/Dirbaio/NSMB-Editor

NSMBe 5.3.2 Git
NSMBe 5.3.3 Git
-----------------
Download NSMBe on the GitHub Release page, older versions available at NSMBHD: https://nsmbhd.net/download/

Expand Down

0 comments on commit 1ab4f57

Please sign in to comment.