Updated to 1.3 - Added the ability to copy parts of one WAD to a different

WAD (either the banner, the icon, the sound, or the dol)
                 - Added the ability to download just a single content from NUS
                 - Code cleanup and bug fixes
This commit is contained in:
mzolob@gmail.com 2011-10-11 02:48:10 +00:00
parent 5e0a75f8f5
commit 2db50709b3
4 changed files with 317 additions and 188 deletions

View File

@ -39,6 +39,7 @@ namespace Sharpii
//Set up variables
string id = "";
string content = "";
int version = -1;
string output = "";
bool local = false;
@ -127,6 +128,22 @@ namespace Sharpii
}
id = args[i + 1];
break;
case "-SINGLE":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No ID specified");
return;
}
content = args[i + 1];
break;
case "-S":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No ID specified");
return;
}
content = args[i + 1];
break;
}
}
@ -169,6 +186,19 @@ namespace Sharpii
nus.UseLocalFiles = true;
}
if (content != "")
{
if (Quiet.quiet > 1)
System.Console.Write("Downloading content...");
nus.DownloadSingleContent(id, version.ToString(), content, output);
if (Quiet.quiet > 1)
System.Console.Write("Done!\n");
}
else
{
if (Quiet.quiet > 1)
System.Console.Write("Downloading title...");
@ -176,6 +206,7 @@ namespace Sharpii
if (Quiet.quiet > 1)
System.Console.Write("Done!\n");
}
if (Quiet.quiet > 1)
System.Console.WriteLine("Operation completed succesfully!");
@ -201,7 +232,7 @@ namespace Sharpii
System.Console.WriteLine(" Usage:");
System.Console.WriteLine("");
System.Console.WriteLine(" Sharpii.exe NUSD [-id titleID] [-v version] [-o otput] [-all] [-wad]");
System.Console.WriteLine(" [-decrypt] [-encrypt] [-local]");
System.Console.WriteLine(" [-decrypt] [-encrypt] [-local] [-s content]");
System.Console.WriteLine("");
System.Console.WriteLine("");
System.Console.WriteLine(" Arguments:");
@ -210,6 +241,9 @@ namespace Sharpii
System.Console.WriteLine(" -v version [required] The version of the file you wish to download");
System.Console.WriteLine(" -o output Folder to output the files to");
System.Console.WriteLine(" -local Use local files if present");
System.Console.WriteLine(" -s content Download a single content from the file");
System.Console.WriteLine(" NOTE: When using this, output MUST have a path and a");
System.Console.WriteLine(" filename. For current directory use '.\\[filename]'");
System.Console.WriteLine(" -all Create and keep encrypted, decrypted, and WAD versions");
System.Console.WriteLine(" of the file you wish to download");
System.Console.WriteLine(" -wad Keep only the WAD version of the file you wish to");

View File

@ -147,6 +147,31 @@ namespace Sharpii
}
}
public class DeleteDir
{
public static bool DeleteDirectory(string target_dir)
{
bool result = false;
string[] files = Directory.GetFiles(target_dir);
string[] dirs = Directory.GetDirectories(target_dir);
foreach (string file in files)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
Directory.Delete(target_dir, false);
return result;
}
}
public class Quiet {
//1 = little
//2 = normal
@ -155,5 +180,5 @@ namespace Sharpii
}
public class Version
{
public static string version = "1.2";
public static string version = "1.3";
}

View File

@ -1,5 +1,5 @@
/------------------------------------------------------------------------------>
Sharpii 1.2
Sharpii 1.3
<---------------------------------------------------------------->
An app by person66
libWiiSharp.dll by leathl (mod by scooby74029)
@ -15,6 +15,7 @@ libWiiSharp.dll to perform tasks such as:
- Pack, unpack, or edit .wad files
- Pack, and unpack U8 archives
- Patch IOS .wad files with various patches
- Download files from NUS
- Convert a .wav file to .bns, and vice versa
- Convert an image file to a .tpl, and vice versa
- Send a .dol to the Homebrew Channel over Wi-Fi
@ -36,6 +37,35 @@ Where [function] would obviously be replaced with the function you want
help with.
/----NOTES
/------------------------------>
NUS Downloading:
/------------------>
When downloading single contents from NUS (using the -s argument) make
sure you have both the path, and the file name when specifying the output.
For example, if the output is set to '.\hello.app' then the file will be
saved as 'hello.app' in the current directory. However, if the output is
set to 'hello.app' you will get an error.
Also note that When Downloading single contents, it will only save the
decrypted file.
WAD Editing:
/------------------>
When changing the type of WAD (using the -type argument) some of the types
may not work, as they have not all been tested. Here is a list of what the
different types are:
- Channel: Regular channel WAD, nothing special
- DLC: WAD for game DLC (downloaded game content)
- GameChannel: Channels such as the Wii Fit or Mario Kart channels
- HiddenChannels: A hidden channel, it wont show up on the Wii Menu
- SystemChannels: Channels such as the Mii or Shopping channels
- SystemTitles: Stuff like the System Menu and boot2 (but not IOSs)
For more details see http://wiibrew.org/wiki/Title_database
/----SOURCE
/------------------------------>
@ -51,7 +81,7 @@ it borrows some code from some of the examples included with libWiiSharp.
libWiiSharp can be found at: libwiisharp.googlecode.com
I would also like to thank Xflak and JoostinOnline for doing a bit of beta
I would also like to thank XFlak and JoostinOnline for doing a bit of beta
testing for me. Thanks!
@ -65,6 +95,12 @@ See "LICENSE.txt" for more information.
/----CHANGELOG
/------------------------------>
1.3
- Added the ability to copy parts of one WAD to a different
WAD (either the banner, the icon, the sound, or the dol)
- Added the ability to download just a single content from NUS
- Code cleanup and bug fixes
- Sharpii can now find JoostinOnline a girlfriend! :P
1.2
- Added version patch support for IOS patching
- Switched to scooby74029's mod of libWiiSharp

View File

@ -34,13 +34,25 @@ namespace Sharpii
//********************* PACK *********************
if (args[1] == "-p")
{
Pack(args);
if (args.Length < 4)
{
WAD_help();
return;
}
Editor(args, false);
return;
}
//********************* UNPACK *********************
if (args[1] == "-u")
{
if (args.Length < 4)
{
WAD_help();
return;
}
Unpack(args);
return;
}
@ -48,7 +60,13 @@ namespace Sharpii
//********************* EDIT *********************
if (args[1] == "-e")
{
Edit(args);
if (args.Length < 4)
{
WAD_help();
return;
}
Editor(args, true);
return;
}
@ -188,23 +206,34 @@ namespace Sharpii
}
}
private static void Edit(string[] args)
private static void Editor(string[] args, bool edit)
{
//setting up variables
//Setting up variables
string input = args[2];
string output = args[3];
string id = "";
int ios = -1;
string title = "";
string lwrid = "Channel";
string lwrid = "";
bool fake = false;
string sound = "";
string banner = "";
string icon = "";
string app = "";
//Check if file exists
//Check if file/folder exists
if (edit == true)
if (File.Exists(input) == false)
{
System.Console.WriteLine("ERROR: Unable to open file: {0}", input);
return;
}
if (edit == false)
if (Directory.Exists(input) == false)
{
System.Console.WriteLine("ERROR: Unable to open folder: {0}", input);
return;
}
for (int i = 1; i < args.Length; i++)
{
@ -234,9 +263,9 @@ namespace Sharpii
return;
}
lwrid = args[i + 1];
if (lwrid != "Channel" & lwrid != "DLC" & lwrid != "GameChannel" & lwrid != "HiddenChannels" & lwrid != "SystemChannels" & lwrid != "SystemTitles")
if (args[i + 1].ToUpper() != "CHANNEL" && args[i + 1].ToUpper() != "DLC" && args[i + 1].ToUpper() != "GAMECHANNEL" && args[i + 1].ToUpper() != "HIDDENCHANNELS" && args[i + 1].ToUpper() != "SYSTEMCHANNELS" && args[i + 1].ToUpper() != "SYSTEMTITLES")
{
System.Console.WriteLine("ERROR: Unknown WAD type: {0}", lwrid);
System.Console.WriteLine("ERROR: Unknown WAD type: {0}", args[i + 1]);
return;
}
break;
@ -260,11 +289,63 @@ namespace Sharpii
case "-TITLE":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No type set");
Console.WriteLine("ERROR: No title set");
return;
}
title = args[i + 1];
break;
case "-SOUND":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No sound set");
return;
}
sound = args[i + 1];
if (File.Exists(sound) == false)
{
Console.WriteLine("ERROR: Unable to find sound wad");
return;
}
break;
case "-BANNER":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No banner set");
return;
}
banner = args[i + 1];
if (File.Exists(banner) == false)
{
Console.WriteLine("ERROR: Unable to find banner wad");
return;
}
break;
case "-ICON":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No sound set");
return;
}
icon = args[i + 1];
if (File.Exists(icon) == false)
{
Console.WriteLine("ERROR: Unable to find icon wad");
return;
}
break;
case "-DOL":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No dol set");
return;
}
app = args[i + 1];
if (File.Exists(app) == false)
{
Console.WriteLine("ERROR: Unable to find dol wad");
return;
}
break;
}
}
@ -273,14 +354,106 @@ namespace Sharpii
{
WAD wad = new WAD();
if (edit == true)
{
if (Quiet.quiet > 2)
System.Console.Write("Loading file...");
wad.LoadFile(input);
}
else
{
if (Quiet.quiet > 2)
System.Console.Write("Loading folder...");
wad.CreateNew(input);
}
if (Quiet.quiet > 2)
System.Console.Write("Done!\n");
if (sound != "" || banner != "" || icon != "" || app != "")
{
string temp = Path.GetTempPath() + "Sharpii.tmp";
if (Directory.Exists(temp) == true)
DeleteDir.DeleteDirectory(temp);
Directory.CreateDirectory(temp);
wad.Unpack(temp + "\\main");
U8 u = new U8();
u.LoadFile(temp + "\\main\\00000000.app");
u.Extract(temp + "\\main\\00000000");
WAD twad = new WAD();
if (sound != "")
{
if (Quiet.quiet > 2)
System.Console.Write("Grabbing sound...");
twad.LoadFile(sound);
twad.Unpack(temp + "\\sound");
U8 tu = new U8();
tu.LoadFile(temp + "\\sound\\00000000.app");
tu.Extract(temp + "\\sound\\00000000");
File.Copy(temp + "\\sound\\00000000\\meta\\sound.bin", temp + "\\main\\00000000\\meta\\sound.bin", true);
if (Quiet.quiet > 2)
System.Console.Write("Done!\n");
}
if (banner != "")
{
if (Quiet.quiet > 2)
System.Console.Write("Grabbing banner...");
twad.LoadFile(banner);
twad.Unpack(temp + "\\banner");
U8 tu = new U8();
tu.LoadFile(temp + "\\banner\\00000000.app");
tu.Extract(temp + "\\banner\\00000000");
File.Copy(temp + "\\banner\\00000000\\meta\\banner.bin", temp + "\\main\\00000000\\meta\\banner.bin", true);
if (Quiet.quiet > 2)
System.Console.Write("Done!\n");
}
if (icon != "")
{
if (Quiet.quiet > 2)
System.Console.Write("Grabbing icon...");
twad.LoadFile(icon);
twad.Unpack(temp + "\\icon");
U8 tu = new U8();
tu.LoadFile(temp + "\\icon\\00000000.app");
tu.Extract(temp + "\\icon\\00000000");
File.Copy(temp + "\\icon\\00000000\\meta\\icon.bin", temp + "\\main\\00000000\\meta\\icon.bin", true);
if (Quiet.quiet > 2)
System.Console.Write("Done!\n");
}
if (app != "")
{
if (Quiet.quiet > 2)
System.Console.Write("Grabbing dol...");
twad.LoadFile(app);
twad.Unpack(temp + "\\dol");
File.Copy(temp + "\\dol\\00000001.app", temp + "\\main\\00000001.app", true);
if (Quiet.quiet > 2)
System.Console.Write("Done!\n");
}
u.ReplaceFile(1, temp + "\\main\\00000000\\meta\\banner.bin");
u.ReplaceFile(2, temp + "\\main\\00000000\\meta\\icon.bin");
u.ReplaceFile(3, temp + "\\main\\00000000\\meta\\sound.bin");
u.Save(temp + "\\main\\00000000.app");
DeleteDir.DeleteDirectory(temp + "\\main\\00000000\\");
wad.CreateNew(temp + "\\main");
DeleteDir.DeleteDirectory(temp);
}
if (Quiet.quiet > 2 && fake == true)
System.Console.WriteLine("FakeSigning WAD");
@ -289,19 +462,29 @@ namespace Sharpii
if (id != "")
{
if (Quiet.quiet > 2)
System.Console.WriteLine("Changing channel type to: {0}", lwrid);
System.Console.WriteLine("Changing channel ID to: {0}", id);
if (lwrid == "Channel")
if (lwrid != "")
{
if (Quiet.quiet > 2)
System.Console.WriteLine("Changing channel type to: {0}", lwrid);
}
else
{
lwrid = "CHANNEL";
}
if (lwrid == "CHANNEL")
wad.ChangeTitleID(LowerTitleID.Channel, id);
if (lwrid == "DLC")
wad.ChangeTitleID(LowerTitleID.DLC, id);
if (lwrid == "GameChannel")
if (lwrid == "GAMECHANNEL")
wad.ChangeTitleID(LowerTitleID.GameChannel, id);
if (lwrid == "HiddenChannels")
if (lwrid == "HIDDENCHANNELS")
wad.ChangeTitleID(LowerTitleID.HiddenChannels, id);
if (lwrid == "SystemChannels")
if (lwrid == "SYSTEMCHANNELS")
wad.ChangeTitleID(LowerTitleID.SystemChannels, id);
if (lwrid == "SystemTitles")
if (lwrid == "SYSTEMTITLES")
wad.ChangeTitleID(LowerTitleID.SystemTitles, id);
}
if (ios > -1)
@ -398,159 +581,6 @@ namespace Sharpii
}
}
private static void Pack(string[] args)
{
//Setting up variables
string input = args[2];
string output = args[3];
string id = "";
int ios = -1;
string lwrid = "Channel";
string title = "";
bool fake = false;
//Check if folder exists
if (Directory.Exists(input) == false)
{
System.Console.WriteLine("ERROR: Unable to open Folder: {0}", input);
return;
}
for (int i = 1; i < args.Length; i++)
{
switch (args[i].ToUpper())
{
case "-F":
fake = true;
break;
case "-ID":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No ID set");
return;
}
id = args[i + 1];
if (id.Length < 4)
{
System.Console.WriteLine("ERROR: ID too short");
return;
}
id = id.Substring(0, 4);
break;
case "-TYPE":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No type set");
return;
}
lwrid = args[i + 1];
if (lwrid != "Channel" & lwrid != "DLC" & lwrid != "GameChannel" & lwrid != "HiddenChannels" & lwrid != "SystemChannels" & lwrid != "SystemTitles")
{
System.Console.WriteLine("ERROR: Unknown WAD type: {0}", lwrid);
return;
}
break;
case "-IOS":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No type set");
return;
}
if (!int.TryParse(args[i + 1], out ios))
{
Console.WriteLine("Invalid slot {0}...", args[i + 1]);
return;
}
if (ios < 0 || ios > 255)
{
Console.WriteLine("Invalid slot {0}...", ios);
return;
}
break;
case "-TITLE":
if (i + 1 >= args.Length)
{
Console.WriteLine("ERROR: No type set");
return;
}
title = args[i + 1];
break;
}
}
//Run main part, and check for exceptions
try
{
WAD wad = new WAD();
if (Quiet.quiet > 2)
System.Console.Write("Loading folder...");
wad.CreateNew(input);
if (Quiet.quiet > 2)
System.Console.Write("Done!\n");
if (Quiet.quiet > 2 && fake == true)
System.Console.WriteLine("FakeSigning WAD");
wad.FakeSign = fake;
if (id != "")
{
if (Quiet.quiet > 2)
System.Console.WriteLine("Changing channel type to: {0}", lwrid);
if (lwrid == "Channel")
wad.ChangeTitleID(LowerTitleID.Channel, id);
if (lwrid == "DLC")
wad.ChangeTitleID(LowerTitleID.DLC, id);
if (lwrid == "GameChannel")
wad.ChangeTitleID(LowerTitleID.GameChannel, id);
if (lwrid == "HiddenChannels")
wad.ChangeTitleID(LowerTitleID.HiddenChannels, id);
if (lwrid == "SystemChannels")
wad.ChangeTitleID(LowerTitleID.SystemChannels, id);
if (lwrid == "SystemTitles")
wad.ChangeTitleID(LowerTitleID.SystemTitles, id);
}
if (ios > -1)
{
if (Quiet.quiet > 2)
System.Console.WriteLine("Changing startup IOS to: {0}", ios);
wad.ChangeStartupIOS(ios);
}
if (title != "")
{
if (Quiet.quiet > 2)
System.Console.WriteLine("Changing channel title to: {0}", title);
wad.ChangeChannelTitles(title);
}
if (Quiet.quiet > 2)
System.Console.Write("Saving file...");
if (output.Substring(output.Length - 4, 4).ToUpper() != ".WAD")
output = output + ".wad";
wad.Save(output);
if (Quiet.quiet > 2)
System.Console.Write("Done!\n");
if (Quiet.quiet > 1)
System.Console.WriteLine("Operation completed succesfully!");
}
catch (Exception ex)
{
System.Console.WriteLine("An unknown error occured, please try again");
System.Console.WriteLine("");
System.Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
return;
}
}
public static void WAD_help()
{
System.Console.WriteLine("");
@ -590,6 +620,10 @@ namespace Sharpii
System.Console.WriteLine(" -type [type] Change the Channel type. Possible values are:");
System.Console.WriteLine(" Channel, DLC, GameChannel, HiddenChannels,");
System.Console.WriteLine(" SystemChannels, or SystemTitles");
System.Console.WriteLine(" -sound [wad] Use the sound from 'wad'");
System.Console.WriteLine(" -banner [wad] Use the banner from 'wad'");
System.Console.WriteLine(" -icon [wad] Use the icon from 'wad'");
System.Console.WriteLine(" -dol [wad] Use the dol from 'wad'");
}
}
}