Skip to content

Commit

Permalink
Add patch menu (Idea from Impeeza)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdude2478 committed Oct 31, 2024
1 parent ebc44ba commit bc2e111
Show file tree
Hide file tree
Showing 8 changed files with 3,128 additions and 15 deletions.

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

35 changes: 34 additions & 1 deletion NRO Forwarder/Form1.cs → NRO Forwarder/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ private void button_Generate_Click(object sender, EventArgs e)
{
fileStream.WriteByte(newcontrol[q]);
}
fileStream.Close();
fileStream.Dispose();
}

//patch main.npdm with correct ID
Expand Down Expand Up @@ -588,6 +590,7 @@ private void button_Generate_Click(object sender, EventArgs e)
//byte[] versionblank = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
//ReplaceData(file, pos, versionblank); //Reset Version
ReplaceData(file, pos, data);//Write New Version String
Array.Clear(data, 0, data.Length);

//cleanup old backup files and remove old nro's
if (Directory.Exists("Tools/NSP"))
Expand All @@ -599,10 +602,12 @@ private void button_Generate_Click(object sender, EventArgs e)
//Try to Build NSP
try
{
string myargs = " --titleid " + titleid + " --titlename " + '"' + apptitle + '"' + " --titlepublisher " + '"' + publisher + '"' + " --nspdir NSP -k ./prod.keys";

Process process = new Process();
process.StartInfo.WorkingDirectory = "Tools";
process.StartInfo.FileName = "Tools\\hacbrewpack.exe";
process.StartInfo.Arguments = " --titleid " + titleid + " --titlename " + '"' + apptitle + '"' + " --titlepublisher " + '"' + publisher + '"' + " --nspdir NSP -k ./prod.keys";
process.StartInfo.Arguments = myargs;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = false;
Expand Down Expand Up @@ -673,6 +678,8 @@ public static void ReplaceData(string filename, int position, byte[] data)
{
stream.Position = position;
stream.Write(data, 0, data.Length);
stream.Close();
stream.Dispose();
}
}

Expand Down Expand Up @@ -744,6 +751,7 @@ Debug Flags - Valid Flags are
"force_debug_prod": false
*/

/*
String file = "Tools/exefs/main.npdm";
int pos1 = 818; //(0x332)
int pos2 = 1010; //(0x3F2)
Expand Down Expand Up @@ -784,6 +792,7 @@ Debug Flags - Valid Flags are
{
MessageBox.Show("Cant'find " + file, "Oops"); //Atmosphere pre-1.8.0
}
*/
}

private void checkBox_licence_CheckedChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -836,5 +845,29 @@ public override string ToString()
return string.Format("{0}->{1}->{2}", emulator, nropath, rompath);
}
}

private void button_Generate_MouseDown(object sender, MouseEventArgs e)
{
try
{
switch (e.Button)
{
case MouseButtons.Right:
Form search = new Form_Patch();
this.Hide();
search.ShowDialog();
this.Show();
break;

case MouseButtons.Left:
//
break;
}
}
catch (Exception error)
{
MessageBox.Show("Error is: " + error.Message);
}
}
}
}
File renamed without changes.
19 changes: 14 additions & 5 deletions NRO Forwarder/NRO Forwarder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,25 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="Main.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="Main.Designer.cs">
<DependentUpon>Main.cs</DependentUpon>
</Compile>
<Compile Include="Patch.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Patch.Designer.cs">
<DependentUpon>Patch.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="Main.resx">
<DependentUpon>Main.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Patch.resx">
<DependentUpon>Patch.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
135 changes: 135 additions & 0 deletions NRO Forwarder/Patch.Designer.cs

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

113 changes: 113 additions & 0 deletions NRO Forwarder/Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.IO;
using System.Windows.Forms;

namespace NRO_Forwarder
{
public partial class Form_Patch : Form
{
public Form_Patch()
{
InitializeComponent();
String filex = "Tools/exefs/main.npdm";
if (File.Exists(filex))
{
try
{
BinaryReader reader = new BinaryReader(new FileStream(filex, FileMode.Open));
reader.BaseStream.Position = 1010; //
byte[] bytes = reader.ReadBytes(1);
reader.Close();
reader.Dispose();
string currentval = BitConverter.ToString(bytes);
//MessageBox.Show(BitConverter.ToString(bytes)); //show bytes pattern

if (currentval == "00")
{
radioButton_nodebug.Checked = true;
}
else if (currentval == "02")
{
radioButton_allowdebug.Checked = true;
}
else if (currentval == "04")
{
radioButton_forceprod.Checked = true;
}
else if (currentval == "08")
{
radioButton_forcedebug.Checked = true;
}
}
catch (Exception error)
{
MessageBox.Show("Error is: " + error.Message);
}
}
else
{
MessageBox.Show("Unable to find " + filex, "Missing file", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

private void button_exit_Click(object sender, EventArgs e)
{
this.Close();
}

public static void ReplaceData(string filename, int position, byte[] data)
{
using (Stream stream = File.Open(filename, FileMode.Open))
{
stream.Position = position;
stream.Write(data, 0, data.Length);
stream.Close();
stream.Dispose();
}
}

private void button_patch_Click(object sender, EventArgs e)
{
String file = "Tools/exefs/main.npdm";
int pos1 = 818; //(0x332)
int pos2 = 1010; //(0x3F2)
byte[] patch = { 0x00 };
byte[] patch2 = { 0x02 };
byte[] patch3 = { 0x04 };
byte[] patch4 = { 0x08 };
string info = "main.npdm Patched at 0x332 + 0x3F2 with: ";

if (File.Exists("Tools/exefs/main.npdm"))
{
if (radioButton_nodebug.Checked)
{
ReplaceData(file, pos1, patch);
ReplaceData(file, pos2, patch);
MessageBox.Show(info + "0x00", "No debugs enabled", MessageBoxButtons.OK, MessageBoxIcon.Information); //no debugs enabled
}
else if (radioButton_allowdebug.Checked)
{
ReplaceData(file, pos1, patch2);
ReplaceData(file, pos2, patch2);
MessageBox.Show(info + "0x02", "Flag 'allow_debug' enabled", MessageBoxButtons.OK, MessageBoxIcon.Information); //Allow debug
}
else if (radioButton_forceprod.Checked)
{
ReplaceData(file, pos1, patch3);
ReplaceData(file, pos2, patch3);
MessageBox.Show(info + "0x04", "Flag 'force_debug_prod' enabled", MessageBoxButtons.OK, MessageBoxIcon.Information); //force_debug_prod
}
else if (radioButton_forcedebug.Checked)
{
ReplaceData(file, pos1, patch4);
ReplaceData(file, pos2, patch4);
MessageBox.Show(info + "0x08", "Flag 'force_debug' enabled", MessageBoxButtons.OK, MessageBoxIcon.Information); //force_debug
}
}
else
{
MessageBox.Show("Cant'find " + file, "Oops"); //Atmosphere pre-1.8.0
}
}
}
}
Loading

0 comments on commit bc2e111

Please sign in to comment.