diff --git a/AAPacker/AAPakFileHeader.cs b/AAPacker/AAPakFileHeader.cs index f0e23f3..1e71adc 100644 --- a/AAPacker/AAPakFileHeader.cs +++ b/AAPacker/AAPakFileHeader.cs @@ -112,7 +112,7 @@ protected internal void SetCustomKey(byte[] newKey) } /// - /// Reverts back to the original encryption key, this function is also automatically called when closing a file + /// Reverts back to the original XL encryption key, this function is also automatically called after closing a file /// protected internal void SetDefaultKey() { diff --git a/AAPakEditor/AAPakEditor.csproj b/AAPakEditor/AAPakEditor.csproj index 6a042bb..386d89b 100644 --- a/AAPakEditor/AAPakEditor.csproj +++ b/AAPakEditor/AAPakEditor.csproj @@ -15,6 +15,9 @@ true false + + + default publish\ true Disk @@ -25,14 +28,11 @@ false false true - 2 - 0.3.1.%2a + 0 + 0.8.0.%2a false true true - - - default AnyCPU diff --git a/AAPakEditor/Forms/MainForm.Designer.cs b/AAPakEditor/Forms/MainForm.Designer.cs index f2d9885..4e3329e 100644 --- a/AAPakEditor/Forms/MainForm.Designer.cs +++ b/AAPakEditor/Forms/MainForm.Designer.cs @@ -99,6 +99,9 @@ private void InitializeComponent() this.lPakExtraInfo = new System.Windows.Forms.ToolStripStatusLabel(); this.lTypePak = new System.Windows.Forms.ToolStripStatusLabel(); this.MainFormSplitter = new System.Windows.Forms.SplitContainer(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); + this.MMToolsConvertMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.MMToolsConvertPak = new System.Windows.Forms.ToolStripMenuItem(); this.MM.SuspendLayout(); this.pFileInfo.SuspendLayout(); this.tcDirectoryViews.SuspendLayout(); @@ -335,7 +338,9 @@ private void InitializeComponent() this.MMToolsApplyPatch, this.MMToolsS2, this.MMToolsMD5, - this.MMToolsMD5All}); + this.MMToolsMD5All, + this.toolStripMenuItem1, + this.MMToolsConvertMenu}); this.MMTools.Name = "MMTools"; this.MMTools.Size = new System.Drawing.Size(46, 20); this.MMTools.Text = "&Tools"; @@ -728,6 +733,28 @@ private void InitializeComponent() this.MainFormSplitter.SplitterDistance = 250; this.MainFormSplitter.TabIndex = 10; // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(231, 6); + // + // MMToolsConvertMenu + // + this.MMToolsConvertMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.MMToolsConvertPak}); + this.MMToolsConvertMenu.Name = "MMToolsConvertMenu"; + this.MMToolsConvertMenu.Size = new System.Drawing.Size(234, 22); + this.MMToolsConvertMenu.Text = "Convert Pak Type"; + this.MMToolsConvertMenu.DropDownOpening += new System.EventHandler(this.MMToolsConvertMenu_DropDownOpening); + // + // MMToolsConvertPak + // + this.MMToolsConvertPak.Name = "MMToolsConvertPak"; + this.MMToolsConvertPak.Size = new System.Drawing.Size(180, 22); + this.MMToolsConvertPak.Tag = "1"; + this.MMToolsConvertPak.Text = "Classic"; + this.MMToolsConvertPak.Click += new System.EventHandler(this.MMToolsConvertPak_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -836,6 +863,9 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem MMToolsCreatePatch; private System.Windows.Forms.ToolStripMenuItem MMToolsApplyPatch; private System.Windows.Forms.ToolStripSeparator MMToolsS2; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem MMToolsConvertMenu; + private System.Windows.Forms.ToolStripMenuItem MMToolsConvertPak; } } diff --git a/AAPakEditor/Forms/MainForm.cs b/AAPakEditor/Forms/MainForm.cs index 9ae03f0..0009344 100644 --- a/AAPakEditor/Forms/MainForm.cs +++ b/AAPakEditor/Forms/MainForm.cs @@ -66,6 +66,7 @@ private void UpdateMm() MMToolsApplyPatch.Enabled = Pak?.IsOpen == true && !Pak.IsVirtual && Pak.ReadOnly == false; MMToolsMD5.Enabled = Pak?.IsOpen == true && !Pak.IsVirtual && Pak.ReadOnly == false && lbFiles.SelectedIndex >= 0; MMToolsMD5All.Enabled = Pak?.IsOpen == true && !Pak.IsVirtual && Pak.ReadOnly == false; + MMToolsConvertMenu.Enabled = Pak?.IsOpen == true && !Pak.IsVirtual && !Pak.ReadOnly; MMTools.Visible = Pak?.IsOpen == true; if (Pak?.IsOpen == true) @@ -75,12 +76,19 @@ private void UpdateMm() else Text = _baseTitle + @" - " + Pak.GpFilePath; lPakExtraInfo.Text = Pak.NewestFileDate.ToString("yyyy-MM-dd HH:mm:ss"); + + if (Pak.PakType == PakFileType.Reader) + lTypePak.Text = Pak.Reader?.ReaderName ?? "Invalid Reader"; + else + lTypePak.Text = Pak.PakType.ToString(); } else { Text = _baseTitle; lPakExtraInfo.Text = @"..."; + lTypePak.Text = ""; } + } @@ -183,73 +191,8 @@ private void MainForm_Load(object sender, EventArgs e) // Initialize Pak Readers AAPak.ReaderPool.Clear(); - /* - AAPak.ReaderPool.Add(new AAPakFileFormatReader() { }); // default - - // AAFree - var aaFree = new AAPakFileFormatReader(); - aaFree.ReaderName = "AAFree"; - aaFree.HeaderBytes = new byte[] { 0x5A, 0x45, 0x52, 0x4F }; // Z E R O - aaFree.HeaderEncryptionKey = new byte[] { 0x67, 0xDF, 0x7A, 0xAE, 0xFA, 0x28, 0x1A, 0x34, 0x6A, 0x64, 0x91, 0xB9, 0xA5, 0X33, 0x3C, 0x8F }; - aaFree.ReadOrder = new List() - { - AAPakFileHeaderElement.Header, - AAPakFileHeaderElement.NullByte, - AAPakFileHeaderElement.NullByte, - AAPakFileHeaderElement.NullByte, - AAPakFileHeaderElement.NullByte, - AAPakFileHeaderElement.FilesCount, - AAPakFileHeaderElement.ExtraFilesCount, - }; - aaFree.FileInfoReadOrder = new List() - { - AAPakFileInfoElement.Dummy2, - AAPakFileInfoElement.FileName, - AAPakFileInfoElement.Offset, - AAPakFileInfoElement.Size, - AAPakFileInfoElement.SizeDuplicate, - AAPakFileInfoElement.PaddingSize, - AAPakFileInfoElement.Md5, - AAPakFileInfoElement.Dummy1, - AAPakFileInfoElement.CreateTime, - AAPakFileInfoElement.ModifyTime, - }; - AAPak.ReaderPool.Add(aaFree); - - - var rage = new AAPakFileFormatReader(); - rage.ReaderName = "ArcheRage"; - rage.HeaderBytes = new byte[] { 0x49, 0x44, 0x45, 0x4A }; // I D E J - rage.HeaderEncryptionKey = new byte[] { 0x6F, 0xF6, 0x6A, 0xB5, 0x11, 0xC0, 0x42, 0x69, 0xEA, 0x96, 0x97, 0x9D, 0x51, 0X82, 0x98, 0x14 }; - rage.ReadOrder = new List() - { - AAPakFileHeaderElement.ExtraFilesCount, - AAPakFileHeaderElement.NullByte, - AAPakFileHeaderElement.NullByte, - AAPakFileHeaderElement.NullByte, - AAPakFileHeaderElement.NullByte, - AAPakFileHeaderElement.Header, - AAPakFileHeaderElement.FilesCount, - }; - rage.InvertFileCounter = true; - rage.FileInfoReadOrder = new List() - { - AAPakFileInfoElement.PaddingSize, - AAPakFileInfoElement.Md5, - AAPakFileInfoElement.Dummy1, - AAPakFileInfoElement.Size, - AAPakFileInfoElement.FileName, - AAPakFileInfoElement.SizeDuplicate, - AAPakFileInfoElement.Offset, - AAPakFileInfoElement.ModifyTime, - AAPakFileInfoElement.CreateTime, - AAPakFileInfoElement.Dummy2, - }; - AAPak.ReaderPool.Add(rage); - */ - - LoadCustomReaders(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "AAPakEditor")); + LoadCustomReaders(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ZeromusXYZ", "AAPakEditor")); UpdateMm(); ShowFileInfo(null); @@ -428,10 +371,7 @@ private void LoadPakFile(string filename, bool openAsReadOnly, bool showWriteWar } } - if (Pak.PakType == PakFileType.Reader) - lTypePak.Text = Pak.Reader?.ReaderName ?? "Invalid Reader"; - else - lTypePak.Text = Pak.PakType.ToString(); + UpdateMm(); } private void lbFolders_SelectedIndexChanged(object sender, EventArgs e) @@ -1782,4 +1722,66 @@ private void MMVersionGetLatest_Click(object sender, EventArgs e) { Process.Start(_urlGitHubLatestRelease); } + + private void MMToolsConvertPak_Click(object sender, EventArgs e) + { + // Warning way too many if's coming + if ((Pak?.IsOpen == true) && (Pak.ReadOnly == false)) + { + var newType = Pak.PakType; + var newReader = Pak.Reader; + + // Convert it + if (sender is ToolStripMenuItem toolStripMenuItem) + { + if (toolStripMenuItem.Tag is AAPakFileFormatReader ffr) + { + newType = PakFileType.Reader; + newReader = ffr; + } + else + if (toolStripMenuItem.Tag is string val) + { + if (val == "1") + { + newType = PakFileType.Classic; + newReader = null; + } + } + } + + if ((newType != Pak.PakType) || (newReader != Pak.Reader)) + { + Pak.PakType = newType; + Pak.Reader = newReader; + if (newType == PakFileType.Reader) + Pak.SetCustomKey(newReader.HeaderEncryptionKey); + else + Pak.SetDefaultKey(); + Pak.IsDirty = true; + UpdateMm(); + } + } + } + + private void MMToolsConvertMenu_DropDownOpening(object sender, EventArgs e) + { + MMToolsConvertMenu.DropDownItems.Clear(); + var classicItem = new ToolStripMenuItem(); + classicItem.Text = "Classic"; + classicItem.Tag = "1"; + classicItem.Checked = (Pak?.PakType == PakFileType.Classic); + classicItem.Click += MMToolsConvertPak_Click; + MMToolsConvertMenu.DropDownItems.Add(classicItem); + + foreach (var aaPakFileFormatReader in AAPak.ReaderPool) + { + var newItem = new ToolStripMenuItem(); + newItem.Text = aaPakFileFormatReader.ReaderName; + newItem.Tag = aaPakFileFormatReader; + newItem.Checked = ((Pak?.PakType == PakFileType.Reader) && (Pak?.Reader == aaPakFileFormatReader)); + newItem.Click += MMToolsConvertPak_Click; + MMToolsConvertMenu.DropDownItems.Add(newItem); + } + } } \ No newline at end of file diff --git a/AAPakEditor/Resources/AAMod.exe b/AAPakEditor/Resources/AAMod.exe index a3a5762..de2df1f 100644 Binary files a/AAPakEditor/Resources/AAMod.exe and b/AAPakEditor/Resources/AAMod.exe differ diff --git a/Common/AAPak.cs b/Common/AAPak.cs index e9e3ed4..d4b633e 100644 --- a/Common/AAPak.cs +++ b/Common/AAPak.cs @@ -293,6 +293,8 @@ public void ClosePak() GpFileStream = null; GpFilePath = null; IsOpen = false; + PakType = PakFileType.Classic; + Reader = null; Header.SetDefaultKey(); LastError = string.Empty;