From 4821a44195b1e44b798760af778d839252b7d05d Mon Sep 17 00:00:00 2001 From: ZeromusXYZ Date: Sun, 16 Oct 2022 16:05:56 +0200 Subject: [PATCH] -add: PakType converter Added option to convert between PakType of a opened Pak file. --- AAPacker/AAPakFileHeader.cs | 2 +- AAPakEditor/AAPakEditor.csproj | 10 +- AAPakEditor/Forms/MainForm.Designer.cs | 32 +++++- AAPakEditor/Forms/MainForm.cs | 142 +++++++++++++------------ AAPakEditor/Resources/AAMod.exe | Bin 62976 -> 62976 bytes Common/AAPak.cs | 2 + 6 files changed, 111 insertions(+), 77 deletions(-) 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 a3a5762610633dfdf91a000d5f8456c3b15dd1c5..de2df1f566ea9d32f895c789d320ac644d4d8241 100644 GIT binary patch delta 724 zcmYk)T}YEr7zgnG**hm5ry0y`jo5pmfYhcsG0ryRjP`1>G2Up~K4&T?~o}iWSxSRdnDv@Z*1;=jJ@&Dif|UGf8!O zE%+myGLdL{=`3M6Lb~g6-vB3dh~XioAL zmFpnMa-%K_ndV}yqm2efRtTWdIl}xK*ML2wJ}-_)V2??I01A@g_}#Wa0(f~r%rXet z8)yLP5m^=UE_xeoMTeS+<_>J5Viw0Rvq6IRFfJ;AsI3)26feqp*QKX-k(`kAtErPt z!4$eA(_?qgdnhV0T1zAhqfgG(3@nYH@1LABinyXr#6@HHsi;N{(>UCh<-T?6ahkxU zqMO!4FwXF5ghp1eY^~B(#9Q@a0<+VYY#k!;n_Uj__ zDYSku%iy^oNuPn0lt9To&dkBBsH01Rd7M!6-tvgf!{^6{(3m!^ntPB(Tnag?>KZk9 zypo?9SIinL;I*U}au}lvsQs4}zzAOs#E=rQ0`!s+Qr{vv_%9Rf`ue1>DPhd=hUtdh zmdB+7Z`X>w$MTWNB6n)@7SFDDt*x^jOI4hs5^7MWEn(rdxTWpAEd#3MBj=`Q|9$u8 sxtWN2nA_RzYZ_E`Pi(ot^_1I)m-m!k5Wab*W>CeQ{O+$GNt&(y10jX9)&Kwi delta 716 zcmYk)Z%7ky7zgn0Z z2qqQROvd?M&O`?JFxMe`yre1kEmhQulA=$B zTIz$XN6wDc5cVdty^+Px|nz@ZY{7Q$r zHDp;a4R7WRf+KsuTz6>gcV23$#OV@eNj$P8{>|zh&0O%zj*;ce@zlip%fTD1Lws?y nrMgYIH>u*}n+px3Q|K