From 8e39846caaf06bab1b601bd331afffe547ab18f8 Mon Sep 17 00:00:00 2001 From: Razmoth <12517189-Razmoth@users.noreply.gitlab.com> Date: Thu, 16 Feb 2023 21:42:02 +0400 Subject: [PATCH] CNUnity update, bug fixes. --- AssetStudio/Crypto/BlkUtils.cs | 5 +- AssetStudio/Crypto/CNUnity.cs | 20 +++----- AssetStudio/Keys.json | 48 +++++++++++++++---- AssetStudio/{CryptoStream.cs => XORStream.cs} | 6 +-- AssetStudioGUI/AssetStudioGUIForm.cs | 2 +- AssetStudioGUI/CNUnityForm.Designer.cs | 39 ++------------- AssetStudioGUI/CNUnityForm.cs | 43 +++++++++++++++++ 7 files changed, 99 insertions(+), 64 deletions(-) rename AssetStudio/{CryptoStream.cs => XORStream.cs} (73%) diff --git a/AssetStudio/Crypto/BlkUtils.cs b/AssetStudio/Crypto/BlkUtils.cs index 3e2f655..adab1c8 100644 --- a/AssetStudio/Crypto/BlkUtils.cs +++ b/AssetStudio/Crypto/BlkUtils.cs @@ -5,10 +5,11 @@ namespace AssetStudio { public static class BlkUtils { + private const int DataPos = 0x2A; private const int KeySize = 0x1000; private const int SeedBlockSize = 0x800; - public static CryptoStream Decrypt(FileReader reader, Blk blk) + public static XORStream Decrypt(FileReader reader, Blk blk) { reader.Endian = EndianType.LittleEndian; @@ -53,7 +54,7 @@ namespace AssetStudio BinaryPrimitives.WriteUInt64LittleEndian(xorpad.AsSpan(i, 8), mt64.Int64()); } - return new CryptoStream(reader.BaseStream, xorpad); + return new XORStream(reader.BaseStream, DataPos, xorpad); } } } \ No newline at end of file diff --git a/AssetStudio/Crypto/CNUnity.cs b/AssetStudio/Crypto/CNUnity.cs index ea91e94..f8e2a6c 100644 --- a/AssetStudio/Crypto/CNUnity.cs +++ b/AssetStudio/Crypto/CNUnity.cs @@ -49,7 +49,7 @@ namespace AssetStudio { using var aes = Aes.Create(); aes.Mode = CipherMode.ECB; - aes.Key = Encoding.UTF8.GetBytes(entry.Key); + aes.Key = entry.GenerateKey(); Encryptor = aes.CreateEncryptor(); } @@ -140,24 +140,18 @@ namespace AssetStudio public bool Validate() { - try + var bytes = GenerateKey(); + if (bytes.Length != 0x10) { - var bytes = Encoding.UTF8.GetBytes(Key); - if (bytes.Length != 0x10) - { - Logger.Warning($"[CNUnity] {this} has invalid key, size should be 16 bytes, skipping..."); - return false; - } - } - catch(Exception e) - { - Logger.Error($"[CNUnity] Error while adding {this}: {e.Message}"); + Logger.Warning($"[CNUnity] {this} has invalid key, size should be 16 bytes, skipping..."); return false; } - + return true; } + public byte[] GenerateKey() => Convert.FromHexString(Key); + public override string ToString() => $"{Name} ({Key})"; } } diff --git a/AssetStudio/Keys.json b/AssetStudio/Keys.json index 148a104..0962ae1 100644 --- a/AssetStudio/Keys.json +++ b/AssetStudio/Keys.json @@ -1,42 +1,70 @@ [ { "Name": "PGR GLB/KR", - "Key": "kurokurokurokuro" + "Key": "6B75726F6B75726F6B75726F6B75726F" }, { "Name": "PGR CN/JP/TW", - "Key": "y5XPvqLOrCokWRIa" + "Key": "7935585076714C4F72436F6B57524961" }, { "Name": "Archeland/Kalpa of Universe", - "Key": "BlackJackProject" + "Key": "426C61636B4A61636B50726F6A656374" }, { "Name": "Archeland 1.1.14", - "Key": "ProjectArcheLand" + "Key": "50726F6A65637441726368654C616E64" }, { "Name": "Neural Cloud", - "Key": "1cab846f52901c9e" + "Key": "31636162383436663532393031633965" }, { "Name": "Higan: Eruthyll", - "Key": "E1x2c3a4l5i6b7ur" + "Key": "45317832633361346C35693662377572" }, { "Name": "White Chord", - "Key": "yulong1868gnoluy" + "Key": "79756C6F6E6731383638676E6F6C7579" }, { "Name": "Mecharashi", - "Key": "38C83F132E7F7A0A" + "Key": "33384338334631333245374637413041" }, { "Name": "Castlevania: Moon Night Fantasy", - "Key": "1234567812345678" + "Key": "31323334353637383132333435363738" }, { "Name": "Huā Yì Shān Xīn Zhī Yuè", - "Key": "INHJnhdypqk547xd" + "Key": "494E484A6E68647970716B3534377864" + }, + { + "Name": "Doula Continent", + "Key": "52346366773339474644326661785756" + }, + { + "Name": "Bless Global", + "Key": "6C6F6E67747567616D652E796A66623F" + }, + { + "Name": "Starside", + "Key": "41394A3542384D4A50554D3539464B57" + }, + { + "Name": "Resonance Soltice", + "Key": "5265736F6E616E63655265626F726E52" + }, + { + "Name": "Oblivion Override", + "Key": "7179666D6F6F6E323331323433343532" + }, + { + "Name": "Dawnlands", + "Key": "636F6465737339353237636F64657373" + }, + { + "Name": "BB", + "Key": "5F6C4E3F3A3F233F3F3F3F663F1A3F3F" } ] \ No newline at end of file diff --git a/AssetStudio/CryptoStream.cs b/AssetStudio/XORStream.cs similarity index 73% rename from AssetStudio/CryptoStream.cs rename to AssetStudio/XORStream.cs index 88ee4df..599ad39 100644 --- a/AssetStudio/CryptoStream.cs +++ b/AssetStudio/XORStream.cs @@ -2,13 +2,11 @@ namespace AssetStudio { - public class CryptoStream : BlockStream + public class XORStream : BlockStream { - private const long _dataPosition = 0x2A; - private readonly byte[] _xorpad; - public CryptoStream(Stream stream, byte[] xorpad) : base(stream, _dataPosition) + public XORStream(Stream stream, long pos, byte[] xorpad) : base(stream, pos) { _xorpad = xorpad; } diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index b54555d..bb08dfc 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -508,7 +508,7 @@ namespace AssetStudioGUI Properties.Settings.Default.skipContainer = skipContainer.Checked; Properties.Settings.Default.Save(); - SkipContainer = enableResolveDependencies.Checked; + SkipContainer = skipContainer.Checked; } private void displayAssetInfo_Check(object sender, EventArgs e) { diff --git a/AssetStudioGUI/CNUnityForm.Designer.cs b/AssetStudioGUI/CNUnityForm.Designer.cs index c851456..cc0046b 100644 --- a/AssetStudioGUI/CNUnityForm.Designer.cs +++ b/AssetStudioGUI/CNUnityForm.Designer.cs @@ -31,8 +31,6 @@ this.specifyCNUnityList = new System.Windows.Forms.DataGridView(); this.NameField = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.KeyField = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Cancel = new System.Windows.Forms.Button(); - this.OKbutton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.specifyCNUnityList)).BeginInit(); this.SuspendLayout(); // @@ -45,13 +43,15 @@ this.specifyCNUnityList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.NameField, this.KeyField}); - this.specifyCNUnityList.Location = new System.Drawing.Point(12, 12); + this.specifyCNUnityList.Dock = System.Windows.Forms.DockStyle.Fill; + this.specifyCNUnityList.Location = new System.Drawing.Point(0, 0); this.specifyCNUnityList.MultiSelect = false; this.specifyCNUnityList.Name = "specifyCNUnityList"; this.specifyCNUnityList.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; this.specifyCNUnityList.RowTemplate.Height = 25; - this.specifyCNUnityList.Size = new System.Drawing.Size(332, 171); + this.specifyCNUnityList.Size = new System.Drawing.Size(432, 229); this.specifyCNUnityList.TabIndex = 0; + this.specifyCNUnityList.RowHeaderMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.specifyCNUnityList_RowHeaderMouseDoubleClick); // // NameField // @@ -65,38 +65,11 @@ this.KeyField.HeaderText = "Key"; this.KeyField.Name = "KeyField"; // - // Cancel - // - this.Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.Cancel.Location = new System.Drawing.Point(255, 190); - this.Cancel.Margin = new System.Windows.Forms.Padding(4); - this.Cancel.Name = "Cancel"; - this.Cancel.Size = new System.Drawing.Size(88, 26); - this.Cancel.TabIndex = 9; - this.Cancel.Text = "Cancel"; - this.Cancel.UseVisualStyleBackColor = true; - this.Cancel.Click += new System.EventHandler(this.Cancel_Click); - // - // OKbutton - // - this.OKbutton.Location = new System.Drawing.Point(159, 190); - this.OKbutton.Margin = new System.Windows.Forms.Padding(4); - this.OKbutton.Name = "OKbutton"; - this.OKbutton.Size = new System.Drawing.Size(88, 26); - this.OKbutton.TabIndex = 8; - this.OKbutton.Text = "OK"; - this.OKbutton.UseVisualStyleBackColor = true; - this.OKbutton.Click += new System.EventHandler(this.OKbutton_Click); - // // CNUnityForm // - this.AcceptButton = this.OKbutton; this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this.Cancel; - this.ClientSize = new System.Drawing.Size(356, 229); - this.Controls.Add(this.Cancel); - this.Controls.Add(this.OKbutton); + this.ClientSize = new System.Drawing.Size(432, 229); this.Controls.Add(this.specifyCNUnityList); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; this.MaximizeBox = false; @@ -115,8 +88,6 @@ #endregion private System.Windows.Forms.DataGridView specifyCNUnityList; - private System.Windows.Forms.Button Cancel; - private System.Windows.Forms.Button OKbutton; private System.Windows.Forms.DataGridViewTextBoxColumn NameField; private System.Windows.Forms.DataGridViewTextBoxColumn KeyField; } diff --git a/AssetStudioGUI/CNUnityForm.cs b/AssetStudioGUI/CNUnityForm.cs index 5d00edc..7de79cf 100644 --- a/AssetStudioGUI/CNUnityForm.cs +++ b/AssetStudioGUI/CNUnityForm.cs @@ -79,5 +79,48 @@ namespace AssetStudioGUI DialogResult = DialogResult.Cancel; Close(); } + + private void specifyCNUnityList_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) + { + var keys = new List(); + for (int i = specifyCNUnityList.Rows.Count - 1; i >= 0; i--) + { + var row = specifyCNUnityList.Rows[i]; + var name = row.Cells["NameField"].Value as string; + var key = row.Cells["KeyField"].Value as string; + + if (!(string.IsNullOrEmpty(name) || string.IsNullOrEmpty(key))) + { + var cnunity = new CNUnity.Entry(name, key); + + if (cnunity.Validate()) + { + keys.Add(cnunity); + continue; + } + } + + if (specifyCNUnityList.CurrentCell.RowIndex == row.Index) + { + var previousRow = specifyCNUnityList.Rows.Cast().ElementAtOrDefault(i - 1); + if (previousRow != null) + { + specifyCNUnityList.CurrentCell = previousRow.Cells[0]; + } + } + if (i != specifyCNUnityList.RowCount - 1) + { + specifyCNUnityList.Rows.RemoveAt(i); + } + } + CNUnityKeyManager.SaveEntries(keys.Reverse().ToList()); + CNUnityKeyManager.SetKey(specifyCNUnityList.CurrentRow.Index); + + Properties.Settings.Default.selectedCNUnityKey = specifyCNUnityList.CurrentRow.Index; + Properties.Settings.Default.Save(); + + DialogResult = DialogResult.OK; + Close(); + } } }