Skip to content

Commit

Permalink
Added YAY0 Support for the Luigis Mansion modders
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperHackio committed Nov 23, 2020
1 parent 824d29e commit 4b97311
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 96 deletions.
6 changes: 6 additions & 0 deletions WiiExplorer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hack.io.YAZ0", "..\Hack.io\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hack.io", "..\Hack.io\Hack.io\Hack.io.csproj", "{389F751D-DB2A-4746-B3BC-88E106C361CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hack.io.YAY0", "..\Hack.io\Hack.io.YAY0\Hack.io.YAY0.csproj", "{2576022C-4A09-4A25-AFB8-9F7DF919E02C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{389F751D-DB2A-4746-B3BC-88E106C361CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{389F751D-DB2A-4746-B3BC-88E106C361CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{389F751D-DB2A-4746-B3BC-88E106C361CE}.Release|Any CPU.Build.0 = Release|Any CPU
{2576022C-4A09-4A25-AFB8-9F7DF919E02C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2576022C-4A09-4A25-AFB8-9F7DF919E02C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2576022C-4A09-4A25-AFB8-9F7DF919E02C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2576022C-4A09-4A25-AFB8-9F7DF919E02C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions WiiExplorer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<setting name="ElapsedTimeFast" serializeAs="String">
<value>0.0058136878654970756</value>
</setting>
<setting name="ElapsedTimeYAY0" serializeAs="String">
<value>0</value>
</setting>
<setting name="IsNeedUpgrade" serializeAs="String">
<value>True</value>
</setting>
Expand Down
37 changes: 19 additions & 18 deletions WiiExplorer/MainForm.Designer.cs

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

58 changes: 43 additions & 15 deletions WiiExplorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
using System.Diagnostics;
using WiiExplorer.Properties;
using System.Reflection;
using Hack.io.YAY0;

namespace WiiExplorer
{
public partial class MainForm : Form
{
OpenFileDialog ofd = new OpenFileDialog() { Filter = "All Supported Files|*.arc;*.szs|Revolution Archives|*.arc|YAZ0 Identified Revolution Archives|*.szs|All Files|*.*" };
SaveFileDialog sfd = new SaveFileDialog() { Filter = "All Supported Files|*.arc;*.szs|Revolution Archives|*.arc|YAZ0 Identified Revolution Archives|*.szs|All Files|*.*" };
OpenFileDialog ofd = new OpenFileDialog() { Filter = "All Supported Files|*.arc;*.szs;*.szp|Revolution Archives|*.arc|YAZ0 Identified Revolution Archives|*.szs|YAY0 Identified Revolution Archives|*.szp|All Files|*.*" };
SaveFileDialog sfd = new SaveFileDialog() { Filter = "All Supported Files|*.arc;*.szs;*.szp|Revolution Archives|*.arc|YAZ0 Identified Revolution Archives|*.szs|YAY0 Identified Revolution Archives|*.szp|All Files|*.*" };
OpenFileDialog Fileofd = new OpenFileDialog() { Multiselect = true };
SaveFileDialog Exportsfd = new SaveFileDialog();
RARC Archive;
Expand All @@ -30,7 +31,7 @@ public MainForm(string Openwith)
{
InitializeComponent();
CenterToScreen();
Yaz0ToolStripComboBox.SelectedIndex = Program.Yaz0Mode;
Yaz0ToolStripComboBox.SelectedIndex = Program.EncodingMode;
Text = $"WiiExplorer {Application.ProductVersion}";
OpenWith = Openwith;

Expand Down Expand Up @@ -67,9 +68,15 @@ private void MainForm_KeyDown(object sender, KeyEventArgs e)
}
}

private void MainForm_FormClosing(object sender, FormClosingEventArgs e) => e.Cancel = Yaz0BackgroundWorker.IsBusy || (e.CloseReason == CloseReason.UserClosing & Edited) && MessageBox.Show("You have unsaved changes.\nAre you sure you want to quit?", "Unsaved Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No;
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) => e.Cancel = EncodingBackgroundWorker.IsBusy || (e.CloseReason == CloseReason.UserClosing & Edited) && MessageBox.Show("You have unsaved changes.\nAre you sure you want to quit?", "Unsaved Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No;

private void Yaz0BackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) => YAZ0.Compress((string)e.Argument, Program.Yaz0Mode == 2);
private void EncodingBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
if (Program.EncodingMode == 3)
YAY0.Compress((string)e.Argument);
else
YAZ0.Compress((string)e.Argument, Program.EncodingMode == 2);
}

private void SetControlsEnabled(bool toggle = true, bool affectall = false)
{
Expand Down Expand Up @@ -460,7 +467,7 @@ private void ItemPropertiesToolStripMenuItem_Click(object sender, EventArgs e)
}
}

private void Yaz0ToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e) => Program.Yaz0Mode = (byte)Yaz0ToolStripComboBox.SelectedIndex;
private void Yaz0ToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e) => Program.EncodingMode = (byte)Yaz0ToolStripComboBox.SelectedIndex;

#region MenuStrip Managers
private class MyRenderer : ToolStripProfessionalRenderer
Expand Down Expand Up @@ -1062,7 +1069,9 @@ private void OpenArchive(string Filename)
{
ofd.FileName = Filename;
MainToolStripProgressBar.Value = 0;
Archive = YAZ0.Check(Filename) ? new RARC(YAZ0.DecompressToMemoryStream(Filename), Filename) : new RARC(Filename);
bool IsYaz0 = YAZ0.Check(Filename);
bool IsYay0 = YAY0.Check(Filename);
Archive = IsYaz0 ? new RARC(YAZ0.DecompressToMemoryStream(Filename), Filename) : (IsYay0 ? new RARC(YAY0.DecompressToMemoryStream(Filename), Filename) : new RARC(Filename));
MainToolStripProgressBar.Value = 20;
ArchiveTreeView.Nodes.Clear();
ArchiveTreeView.Nodes.AddRange(Archive.ToTreeNode(0, ArchiveImageList));
Expand All @@ -1076,41 +1085,60 @@ private void OpenArchive(string Filename)
Text = $"WiiExplorer {Application.ProductVersion} - {new FileInfo(Filename).Name}";
Settings.Default.PreviousOpenArchivePath = new FileInfo(Filename).DirectoryName;
Settings.Default.Save();
if (IsYay0 && Program.EncodingMode != 0x03)
Program.EncodingMode = 0x03;
else if (!IsYaz0 && !IsYay0 && Program.EncodingMode != 0x00)
Program.EncodingMode = 0x00;
else if (IsYaz0 && Program.EncodingMode != 0x02)
Program.EncodingMode = 0x01;
Yaz0ToolStripComboBox.SelectedIndex = Program.EncodingMode;
}

private void SaveArchive(string Filename)
{
FileInfo fi = new FileInfo(Filename);
byte prevencoding = Program.EncodingMode;
if (fi.Extension.Equals(".szp") && Program.EncodingMode != 0x03 && MessageBox.Show("The chosen encoding type doesn't match the file extension.\nSZP files are supposed to be YAY0 Encoded, would you like to switch to YAY0 Strong?", "Encoding Mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
Program.EncodingMode = 0x03;
else if (fi.Extension.Equals(".szs") && Program.EncodingMode != 0x01 && Program.EncodingMode != 0x02 && MessageBox.Show("The chosen encoding type doesn't match the file extension.\nSZS files are supposed to be YAZ0 Encoded, would you like to switch to YAZ0 Strong?", "Encoding Mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
Program.EncodingMode = 0x01;

Yaz0ToolStripComboBox.SelectedIndex = Program.EncodingMode;
MainToolStripProgressBar.Value = 0;
Archive.FromTreeNode(ArchiveTreeView);
MainToolStripProgressBar.Value = 70;
Archive.Save(Filename);
long UncompressedFilesize = File.ReadAllBytes(Filename).Length;
double ETA = UncompressedFilesize * (Program.Yaz0Mode == 0x02 ? Settings.Default.ElapsedTimeFast : Settings.Default.ElapsedTimeStrong);
double ETA = UncompressedFilesize * (Program.EncodingMode == 0x02 ? Settings.Default.ElapsedTimeFast : (Program.EncodingMode == 0x03 ? Settings.Default.ElapsedTimeYAY0 : Settings.Default.ElapsedTimeStrong));
Stopwatch timer = new Stopwatch();
timer.Start();
if (Program.Yaz0Mode != 0)
Yaz0BackgroundWorker.RunWorkerAsync(Filename);
if (Program.EncodingMode != 0x00)
EncodingBackgroundWorker.RunWorkerAsync(Filename);
SetControlsEnabled(false, true);
ItemPropertiesToolStripMenuItem.Enabled = false;
while (Yaz0BackgroundWorker.IsBusy)
while (EncodingBackgroundWorker.IsBusy)
{
MainToolStripStatusLabel.Text = $"{(Program.Yaz0Mode == 2 ? "Fast ":"")}Yaz0 Encoding, Please Wait. ({timer.Elapsed.ToString("mm\\:ss")} Elapsed, {TimeSpan.FromMilliseconds(ETA).ToString("mm\\:ss")} Estimated)";
MainToolStripStatusLabel.Text = $"{(Program.EncodingMode == 2 ? "Fast ":"")}{(Program.EncodingMode == 3 ? "Yay0":"Yaz0")} Encoding, Please Wait. ({timer.Elapsed.ToString("mm\\:ss")} Elapsed, {TimeSpan.FromMilliseconds(ETA).ToString("mm\\:ss")} Estimated)";
Application.DoEvents();
}
timer.Stop();

if (Program.Yaz0Mode == 0x01)
if (Program.EncodingMode == 0x01)
Settings.Default.ElapsedTimeStrong = (double)timer.ElapsedMilliseconds / (double)UncompressedFilesize;
else if (Program.Yaz0Mode == 0x02)
else if (Program.EncodingMode == 0x02)
Settings.Default.ElapsedTimeFast = (double)timer.ElapsedMilliseconds / (double)UncompressedFilesize;
else if (Program.EncodingMode == 0x03)
Settings.Default.ElapsedTimeYAY0 = (double)timer.ElapsedMilliseconds / (double)UncompressedFilesize;

Edited = false;
MainToolStripProgressBar.Value = 100;
MainToolStripStatusLabel.Text = $"Archive saved successfully!{(Program.Yaz0Mode != 0 ? $" ({timer.Elapsed.ToString("mm\\:ss")} Elapsed, {(TimeSpan.FromMilliseconds(ETA).ToString("mm\\:ss").Equals(timer.Elapsed.ToString("mm\\:ss")) ? "Right on time!" : $"{TimeSpan.FromMilliseconds(ETA - timer.ElapsedMilliseconds).ToString("mm\\:ss")} {(timer.ElapsedMilliseconds < ETA ? $"Ahead." : "Behind.")}")})" : "")}";
MainToolStripStatusLabel.Text = $"Archive saved successfully!{(Program.EncodingMode != 0 ? $" ({timer.Elapsed.ToString("mm\\:ss")} Elapsed, {(TimeSpan.FromMilliseconds(ETA).ToString("mm\\:ss").Equals(timer.Elapsed.ToString("mm\\:ss")) ? "Right on time!" : $"{TimeSpan.FromMilliseconds(ETA - timer.ElapsedMilliseconds).ToString("mm\\:ss")} {(timer.ElapsedMilliseconds < ETA ? $"Ahead." : "Behind.")}")})" : "")}";
SetControlsEnabled(affectall:true);
Text = $"WiiExplorer {Application.ProductVersion} - {new FileInfo(Filename).Name}";
Settings.Default.PreviousSaveArchivePath = new FileInfo(Filename).DirectoryName;
Settings.Default.Save();
Program.EncodingMode = prevencoding;
Yaz0ToolStripComboBox.SelectedIndex = Program.EncodingMode;
}

private void AddItemToRARC(string[] FileNames)
Expand Down
Loading

0 comments on commit 4b97311

Please sign in to comment.