Skip to content

Commit

Permalink
Added version display, added .Net Core cross-platform app.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Zeotni committed May 7, 2018
1 parent a60dfb4 commit ed88329
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 30 deletions.
12 changes: 12 additions & 0 deletions BotWSaveManager.Command/BotWSaveManager.Command.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BotWSaveManager.Conversion\BotWSaveManager.Conversion.csproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions BotWSaveManager.Command/Globals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.IO;
using System.Reflection;

namespace BotWSaveManager.Command
{
public static class Globals
{
public static readonly string AppPath = Directory.GetParent(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath).FullName;
}
}
82 changes: 82 additions & 0 deletions BotWSaveManager.Command/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.IO;
using System.Linq;
using BotWSaveManager.Conversion;

namespace BotWSaveManager.Command
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Breath of the Wild Save Manager by Jordan Zeotni, fork of https://github.com/WemI0/BOTW_SaveConv");
Console.Write("Enter the path of the save file or press enter if the file is in the same folder as this application (option.sav): ");
string fileLocation = Console.ReadLine();

if (string.IsNullOrWhiteSpace(fileLocation))
{
if (Directory.GetFiles(Globals.AppPath, "*.sav").First() == null)
{
Console.WriteLine("There are no files with the extension *.sav in this folder. Either place one in the root directory or enter the save file's path.");
Main(args);
return;
}

fileLocation = Path.Combine(Globals.AppPath, Directory.GetFiles(Globals.AppPath, "*.sav").First());
}
else if (!File.Exists(fileLocation))
{
Console.WriteLine("This file does not exist at this path. Either place one in the root directory or enter the save file's path.");
Main(args);
return;
}

Save selectedSave;

try
{
selectedSave = new Save(fileLocation);
}
catch (UnsupportedSaveException e)
{
Console.WriteLine("This save is not supported. If you think this is an error report the following stacktrace:");
Console.WriteLine(e);
Console.WriteLine();
Console.WriteLine();
Main(args);
return;
}

Console.WriteLine(selectedSave.SaveConsoleType == Save.SaveType.Switch ? $"BotW {selectedSave.GameVersion} - Switch" : $"BotW {selectedSave.GameVersion} - Wii U");
Console.WriteLine("Press any key to begin conversion, or ESC to cancel...");
ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(true);

if (consoleKeyInfo.Key == ConsoleKey.Escape)
{
return;
}

byte[] convertSaveBytes = selectedSave.ConvertSave();

Console.Write("Enter a path to save the file as, or press enter to save as \"option.sav\" in the application folder: ");
string saveLocation = Console.ReadLine();

try
{
File.WriteAllBytes(string.IsNullOrWhiteSpace(saveLocation) ? Path.Combine(Globals.AppPath, "option.sav") : saveLocation, convertSaveBytes);
}
catch (Exception e)
{
Console.WriteLine("The file cannot be saved at this path. If you think this is an error report the following stacktrace:");
Console.WriteLine(e);
Console.WriteLine();
Console.WriteLine();
Main(args);
return;
}

Console.WriteLine($"File saved successfully! Please note that you are required to use {selectedSave.GameVersion} of BotW on the target system with (probably) the same DLC for this save file to work. This application only supports conversion at the moment, stay tuned for more features.\nPress any key to close...");
Console.ReadKey(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,44 @@ public enum SaveType

public SaveType SaveConsoleType;
public string FileLocation;
public string GameVersion;

private bool skip;

private static List<string> Items = new List<string>
private static List<int> filesizes = new List<int>
{
896976,
897160,
897112,
907824,
1020648,
1027208,
1027208
};

private static List<int> headers = new List<int>
{
0x24e2,
0x24EE,
0x2588,
0x29c0,
0x3ef8,
0x471a,
0x471b
};

private static List<string> versionList = new List<string>
{
"v1.0",
"v1.1",
"v1.2",
"v1.3",
"v1.3.3",
"v1.4",
"v1.5"
};

private static List<string> items = new List<string>
{
"Item", "Weap", "Armo", "Fire", "Norm", "IceA", "Elec", "Bomb", "Anci", "Anim",
"Obj_", "Game", "Dm_N", "Dm_A", "Dm_E", "Dm_P", "FldO", "Gano", "Gian", "Grea",
Expand All @@ -28,7 +62,7 @@ public enum SaveType
"Lana", "Hate", "Akka", "Yash", "Dung", "BeeH", "Boar", "Boko", "Brig", "DgnO"
};

private static List<string> Hash = new List<string>
private static List<string> hash = new List<string>
{
"7B74E117", "17E1747B", "D913B769", "69B713D9", "B666D246", "46D266B6", "021A6FF2",
"F26F1A02", "FF74960F", "0F9674FF", "8932285F", "5F283289", "3B0A289B", "9B280A3B",
Expand All @@ -46,8 +80,29 @@ public Save(string file)
{
FileInfo f = new FileInfo(file);

byte[] check = br.ReadBytes(Convert.ToInt32(1));
// Not a reliable way to determine game version
//this.GameVersion = versionList[filesizes.IndexOf((int)f.Length)];

byte[] check = br.ReadBytes(1);
this.SaveConsoleType = ByteArrayToString(check) == "00" ? SaveType.WiiU : SaveType.Switch;

while (ByteArrayToString(br.ReadBytes(1)) == "00")
{
}

br.BaseStream.Position -= 1;

byte[] backwardsHeader = br.ReadBytes(2);

try
{
this.GameVersion = versionList[headers.IndexOf(BitConverter.ToInt16(backwardsHeader.Reverse().ToArray(), 0))];
}
catch (Exception e)
{
Console.WriteLine(e);
throw new UnsupportedSaveException("The save file you selected is not currently supported.");
}
}

this.FileLocation = file;
Expand All @@ -65,7 +120,7 @@ public byte[] ConvertSave(string outputLocation = null)
br.BaseStream.Position = h * 4;
byte[] endianConv = br.ReadBytes(Convert.ToInt32(4));

if (Hash.Contains(ByteArrayToString(endianConv))) // skip strings
if (hash.Contains(ByteArrayToString(endianConv))) // skip strings
{
Array.Reverse(endianConv);

Expand Down Expand Up @@ -127,7 +182,7 @@ public static string ByteArrayToString(byte[] byteA)
public static bool CheckString(byte[] toCheck)
{
string Object = System.Text.Encoding.UTF8.GetString(toCheck);
return Items.Any(Object.Contains);
return items.Any(Object.Contains);
}
}
}
13 changes: 13 additions & 0 deletions BotWSaveManager.Conversion/UnsupportedSaveException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BotWSaveManager.Conversion
{
public class UnsupportedSaveException : Exception
{
public UnsupportedSaveException(string message) : base(message)
{
}
}
}
36 changes: 18 additions & 18 deletions BotWSaveManager.UI/MainForm.Designer.cs

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

26 changes: 20 additions & 6 deletions BotWSaveManager.UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,28 @@ private void OpenSaveToolStripMenuItem_Click(object sender, EventArgs e)
MessageBox.Show("Please select a valid file before continuing.");
}

this.SelectedSave = new Save(dia.FileName);
try
{
this.SelectedSave = new Save(dia.FileName);
}
catch (UnsupportedSaveException exception)
{
MessageBox.Show(exception.Message);
this.btnConvert.Hide();
this.tbSaveLocation.Hide();
this.btnBrowse.Hide();
this.btnSaveToFile.Hide();
this.pbConsole.Image = null;
this.lblConsoleName.Text = "";
return;
}

this.ConvertedSaveBytes = File.ReadAllBytes(this.SelectedSave.FileLocation);

this.lblFileWarning.Hide();

this.pbConsole.Image = this.SelectedSave.SaveConsoleType == Save.SaveType.Switch ? Resources.nintendo_switch_logo : Resources.wii_u_logo;
this.lblConsoleName.Text = this.SelectedSave.SaveConsoleType == Save.SaveType.Switch ? "BotW - Switch" : "BotW - Wii U";
this.lblConsoleName.Text = (this.SelectedSave.SaveConsoleType == Save.SaveType.Switch ? $"BotW {this.SelectedSave.GameVersion} - Switch" : $"BotW {this.SelectedSave.GameVersion} - Wii U");

this.btnConvert.Show();
this.tbSaveLocation.Show();
Expand All @@ -60,7 +74,7 @@ private void OpenSaveToolStripMenuItem_Click(object sender, EventArgs e)

private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
{

new About().Show();
}

private void BtnConvert_Click(object sender, EventArgs e)
Expand All @@ -80,12 +94,12 @@ private void BtnConvert_Click(object sender, EventArgs e)
return;
}

MessageBox.Show("Save converted successfully! Either continue with the save editor or just save the file and copy it to your console.");
MessageBox.Show("Save converted successfully! Either continue with the save editor (not supported currently) or just save the file and copy it to your Nintendo console.");

this.Enabled = true;

this.pbConsole.Image = this.SelectedSave.SaveConsoleType == Save.SaveType.Switch ? Resources.nintendo_switch_logo : Resources.wii_u_logo;
this.lblConsoleName.Text = this.SelectedSave.SaveConsoleType == Save.SaveType.Switch ? "BotW - Switch" : "BotW - Wii U";
this.lblConsoleName.Text = this.SelectedSave.SaveConsoleType == Save.SaveType.Switch ? $"BotW {this.SelectedSave.GameVersion} - Switch" : $"BotW {this.SelectedSave.GameVersion} - Wii U";
}

private void BtnBrowse_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -114,7 +128,7 @@ private void BtnSaveToFile_Click(object sender, EventArgs e)
MessageBox.Show("Error writing save file to disk! Create an issue at https://github.com/JordanZeotni/BotW-Save-Manager with the error log **IF** you think its **NOT** a permission error.", exception.Message);
}

MessageBox.Show("File saved successfully!");
MessageBox.Show($"File saved successfully! Please note that you are required to use {this.SelectedSave.GameVersion} of BotW on the target system with (probably) the same DLC for this save file to work.");
}
}
}
Loading

0 comments on commit ed88329

Please sign in to comment.