Skip to content

Commit

Permalink
[HaRepacker] Dump WZ .img as json or bson
Browse files Browse the repository at this point in the history
  • Loading branch information
LastBattle committed Dec 4, 2020
1 parent 65b07f0 commit 1f93b2d
Show file tree
Hide file tree
Showing 10 changed files with 849 additions and 293 deletions.
53 changes: 31 additions & 22 deletions HaRepacker/GUI/MainForm.Designer.cs

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

139 changes: 106 additions & 33 deletions HaRepacker/GUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ private async void openToolStripMenuItem_Click(object sender, EventArgs e)
using (OpenFileDialog dialog = new OpenFileDialog()
{
Title = HaRepacker.Properties.Resources.SelectWz,
Filter = string.Format("{0}|*.wz",
Filter = string.Format("{0}|*.wz;ZLZ.dll",
HaRepacker.Properties.Resources.WzFilter),
Multiselect = true,
})
Expand All @@ -746,7 +746,29 @@ private async void openToolStripMenuItem_Click(object sender, EventArgs e)
{
string filePathLowerCase = filePath.ToLower();

if (filePathLowerCase.EndsWith("data.wz") && WzTool.IsDataWzHotfixFile(filePath))
if (filePathLowerCase.EndsWith("zlz.dll")) // ZLZ.dll encryption keys
{
AssemblyName executingAssemblyName = Assembly.GetExecutingAssembly().GetName();
//similarly to find process architecture
var assemblyArchitecture = executingAssemblyName.ProcessorArchitecture;

if (assemblyArchitecture == ProcessorArchitecture.X86)
{
ZLZPacketEncryptionKeyForm form = new ZLZPacketEncryptionKeyForm();
bool opened = form.OpenZLZDllFile();

if (opened)
form.Show();
}
else
{
MessageBox.Show(HaRepacker.Properties.Resources.ExecutingAssemblyError, HaRepacker.Properties.Resources.Warning, MessageBoxButtons.OK);
}
return;
}

// Other WZs
else if (filePathLowerCase.EndsWith("data.wz") && WzTool.IsDataWzHotfixFile(filePath))
{
WzImage img = Program.WzFileManager.LoadDataWzHotfixFile(filePath, MapleVersionEncryptionSelected, MainPanel);
if (img == null)
Expand Down Expand Up @@ -1221,6 +1243,11 @@ private void imgToolStripMenuItem_Click(object sender, EventArgs e)
new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
}

/// <summary>
/// Export IMG
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void imgToolStripMenuItem1_Click(object sender, EventArgs e)
{
string outPath = GetOutputDirectory();
Expand Down Expand Up @@ -1250,6 +1277,11 @@ private void imgToolStripMenuItem1_Click(object sender, EventArgs e)
new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
}

/// <summary>
/// Export PNG / MP3
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pNGsToolStripMenuItem_Click(object sender, EventArgs e)
{
string outPath = GetOutputDirectory();
Expand All @@ -1275,6 +1307,62 @@ private void pNGsToolStripMenuItem_Click(object sender, EventArgs e)
new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
}


/// <summary>
/// Export as Json
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void jSONToolStripMenuItem_Click(object sender, EventArgs e)
{
ExportBsonJsonInternal(true);
}

/// <summary>
/// Export as BSON
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bSONToolStripMenuItem_Click(object sender, EventArgs e)
{
ExportBsonJsonInternal(false);
}

/// <summary>
/// Export as Json or Bson
/// </summary>
/// <param name="isJson"></param>
private void ExportBsonJsonInternal(bool isJson)
{
string outPath = GetOutputDirectory();
if (outPath == string.Empty)
{
MessageBox.Show(Properties.Resources.MainWzExportError, Properties.Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
bool bIncludeBase64BinData = MessageBox.Show(Properties.Resources.MainWzExportJson_IncludeBase64, Properties.Resources.MainWzExportJson_IncludeBase64_Title, MessageBoxButtons.YesNo) == DialogResult.Yes;

List<WzDirectory> dirs = new List<WzDirectory>();
List<WzImage> imgs = new List<WzImage>();
foreach (WzNode node in MainPanel.DataTree.SelectedNodes)
{
if (node.Tag is WzDirectory directory)
dirs.Add(directory);
else if (node.Tag is WzImage image)
imgs.Add(image);
else if (node.Tag is WzFile file)
{
dirs.Add(file.WzDirectory);
}
}
WzJsonBsonSerializer serializer = new WzJsonBsonSerializer(Program.ConfigurationManager.UserSettings.Indentation, Program.ConfigurationManager.UserSettings.LineBreakType, bIncludeBase64BinData, isJson);
threadDone = false;
runningThread = new Thread(new ParameterizedThreadStart(RunWzImgDirsExtraction));
runningThread.Start((object)new object[] { dirs, imgs, outPath, serializer });

new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
}

/// <summary>
/// Export to private server toolstrip
/// </summary>
Expand All @@ -1293,13 +1381,13 @@ private void privateServerToolStripMenuItem_Click(object sender, EventArgs e)
List<WzImage> imgs = new List<WzImage>();
foreach (WzNode node in MainPanel.DataTree.SelectedNodes)
{
if (node.Tag is WzDirectory)
dirs.Add((WzDirectory)node.Tag);
else if (node.Tag is WzImage)
imgs.Add((WzImage)node.Tag);
else if (node.Tag is WzFile)
if (node.Tag is WzDirectory directory)
dirs.Add(directory);
else if (node.Tag is WzImage image)
imgs.Add(image);
else if (node.Tag is WzFile file)
{
dirs.Add(((WzFile)node.Tag).WzDirectory);
dirs.Add(file.WzDirectory);
}
}
WzClassicXmlSerializer serializer = new WzClassicXmlSerializer(
Expand All @@ -1312,6 +1400,11 @@ private void privateServerToolStripMenuItem_Click(object sender, EventArgs e)
new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
}

/// <summary>
/// Export as XML, classic
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void classicToolStripMenuItem_Click(object sender, EventArgs e)
{
string outPath = GetOutputDirectory();
Expand Down Expand Up @@ -1343,6 +1436,11 @@ private void classicToolStripMenuItem_Click(object sender, EventArgs e)
new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
}

/// <summary>
/// Export as XML, new
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void newToolStripMenuItem1_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog()
Expand Down Expand Up @@ -1489,31 +1587,6 @@ private void ToolStripMenuItem_searchWzStrings_Click(object sender, EventArgs e)
form.Show();
}
}

/// <summary>
/// Get packet encryption keys from ZLZ.dll
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripMenuItem_WzEncryption_Click(object sender, EventArgs e)
{
AssemblyName executingAssemblyName = Assembly.GetExecutingAssembly().GetName();
//similarly to find process architecture
var assemblyArchitecture = executingAssemblyName.ProcessorArchitecture;

if (assemblyArchitecture == ProcessorArchitecture.X86)
{
ZLZPacketEncryptionKeyForm form = new ZLZPacketEncryptionKeyForm();
bool opened = form.OpenZLZDllFile();

if (opened)
form.Show();
}
else
{
MessageBox.Show(HaRepacker.Properties.Resources.ExecutingAssemblyError, HaRepacker.Properties.Resources.Warning, MessageBoxButtons.OK);
}
}
#endregion

private void AbortButton_Click(object sender, EventArgs e)
Expand Down
Loading

1 comment on commit 1f93b2d

@lastbattle
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

Please sign in to comment.