From 7ad4d2342cd76989471eef1e0834e2c34cb40d80 Mon Sep 17 00:00:00 2001 From: Bluzume <39113159+KuromeSan@users.noreply.github.com> Date: Wed, 11 Aug 2021 01:56:18 +1200 Subject: [PATCH] fix MZ --- .vs/RMDEC/v16/.suo | Bin 81920 -> 82944 bytes RMDEC/MVProject.cs | 70 +++++++++++++++++++++++--------------- RMDEC/MVProjectToolset.cs | 27 ++++++++++----- RMDEC/projectSelector.cs | 17 ++++----- 4 files changed, 67 insertions(+), 47 deletions(-) diff --git a/.vs/RMDEC/v16/.suo b/.vs/RMDEC/v16/.suo index f43cfe8b85efa44e7fe87736b5af5718190f6007..5beb6660c498b6631b8bc32a25a4c4bcafa49b2f 100644 GIT binary patch delta 3486 zcmd5by`PRA8EQ8KMxA$4Uu_m&eq= z)}$>jsSsix#zzVr)JV_*?G}GqqOFtWi7IVVs?rtF!e6KlX`8x*K{AQ1adxgBA!%S} z6Pk9TpTBd@J@=g7Irs5>>FrhY?pO4eY0Zo=86h+^HARoGJb%!o7ZR)|RQY2EKLra{ zKZ!eqolt`l!b|WKcFT4t48YiFye-SiG0=D%fjmrcHUB*oAk+&RDq!S7Wn+RN2=5^)63jDiV((NGCc0vn*PiduR z8v%c(Fv0U)SBkQSdM^-sLQ6vbT7~WYxy_5@#v{e@Y{q!4gzyn&!ZPkf!am=tzG2_Lu|zxJWkB&;FuOhR7wCq8x6e>pRd zFb;~x$<+YfPTU20>`Ll^1vo*!8B&+#Wx<~;s03oiu~gia4d#q;kH^x`*4n)7hoob1 zWvyK;Ei1W*)!H8=y_k2w@vE;3=I_~cGUqWV@D93+9awK{B>cdaCWrlAmmagz%HUPn zRuBE0rkx<1BrF(o^}vG*7Fc*EHFJ%!m?D%B@b|Y&*lDSi=S4fxxJ3=Vq6;eE8-nj+ zZX%5rsUhTxY^yGhnW~fvsjne$s&EavOg-?KG-3J# zr1!EN;47$7E~nA*s0DTw^g^mMQLql~Q-}YQNu?^B@?EIRmj#w22~v{v2Kek%N`8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0x4D, 0x34, 0x41, 0x20, 0x00, 0x00, 0x00, 0x00 }; - byte[] oggHeader = new byte[0x10] { 0x4F, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; - - Random rng = new Random(); int index = rng.Next(0, files.Count); string file = files[index]; @@ -183,7 +182,7 @@ namespace RMDEC string filetype = Path.GetExtension(file).ToLower(); - if (filetype == "._png" || filetype == ".rpgmvp") { + if (filetype == ".png_" || filetype == ".rpgmvp") { byte[] key = RMProject.Xor(encryptedHeader, pngHeader); if(!tryKey(path, key)) { @@ -194,7 +193,7 @@ namespace RMDEC return key; } } - else if (filetype == "._m4a" || filetype == ".rpgmvm") + else if (filetype == ".m4a_" || filetype == ".rpgmvm") { byte[] key = RMProject.Xor(encryptedHeader, m4aHeader); if (!tryKey(path, key)) @@ -206,7 +205,7 @@ namespace RMDEC return key; } } - else if (filetype == "._ogg" || filetype == ".rpgmvo") + else if (filetype == ".ogg_" || filetype == ".rpgmvo") { byte[] key = RMProject.Xor(encryptedHeader, oggHeader); if (!tryKey(path, key)) @@ -223,11 +222,11 @@ namespace RMDEC } private static bool tryKey(string path, byte[] key) // Checks if the key really works { - string[] mzPngs = Directory.GetFiles(path, "*._png", SearchOption.AllDirectories); + string[] mzPngs = Directory.GetFiles(path, "*.png_", SearchOption.AllDirectories); string[] mvPngs = Directory.GetFiles(path, "*.rpgmvp", SearchOption.AllDirectories); - string[] mzM4as = Directory.GetFiles(path, "*._m4a", SearchOption.AllDirectories); + string[] mzM4as = Directory.GetFiles(path, "*.m4a_", SearchOption.AllDirectories); string[] mvM4as = Directory.GetFiles(path, "*.rpgmvm", SearchOption.AllDirectories); - string[] mzOggs = Directory.GetFiles(path, "*._ogg", SearchOption.AllDirectories); + string[] mzOggs = Directory.GetFiles(path, "*.ogg_", SearchOption.AllDirectories); string[] mvOggs = Directory.GetFiles(path, "*.rpgmvo", SearchOption.AllDirectories); List files = new List(); @@ -246,28 +245,34 @@ namespace RMDEC Random rng = new Random(); int index = rng.Next(0, files.Count); string file = files[index]; + string filetype = Path.GetExtension(file).ToLower(); byte[] encryptedHeader = new byte[0x10]; FileStream fs = File.OpenRead(file); fs.Seek(0x10, SeekOrigin.Begin); fs.Read(encryptedHeader, 0x00, 0x10); + if (filetype == ".ogg_" || filetype == ".rpgmvo") + { + fs.Seek(0x58, SeekOrigin.Begin); + oggHeader[0x0E] = (byte)fs.ReadByte(); + oggHeader[0x0F] = (byte)fs.ReadByte(); + } fs.Close(); byte[] plaintextHeader = RMProject.Xor(encryptedHeader, key); - string filetype = Path.GetExtension(file).ToLower(); - if (filetype == "._png" || filetype == ".rpgmvp") - if (Encoding.ASCII.GetString(plaintextHeader).Contains("PNG")) + if (filetype == ".png_" || filetype == ".rpgmvp") + if (plaintextHeader.SequenceEqual(pngHeader)) return true; else return false; - else if (filetype == "._ogg" || filetype == ".rpgmvo") - if (Encoding.ASCII.GetString(plaintextHeader).StartsWith("OggS")) + else if (filetype == ".ogg_" || filetype == ".rpgmvo") + if (plaintextHeader.SequenceEqual(oggHeader)) return true; else return false; - else if (filetype == "._m4a" || filetype == ".rpgmvm") - if (Encoding.ASCII.GetString(plaintextHeader).Contains("ftypM4A")) + else if (filetype == ".m4a_" || filetype == ".rpgmvm") + if (plaintextHeader.SequenceEqual(m4aHeader)) return true; else return false; @@ -275,7 +280,7 @@ namespace RMDEC return false; } - private static MVProject GuessProject(string folder) + private static MVProject GuessProject(string folder, bool triedThat=false) { MVProject mvp = new MVProject(); @@ -283,11 +288,16 @@ namespace RMDEC mvp.encryptedImages = false; mvp.encryptedAudio = false; folder = Path.GetDirectoryName(Path.GetDirectoryName(folder)); - string[] mzPngs = Directory.GetFiles(folder, "*._png", SearchOption.AllDirectories); + if(File.Exists(Path.Combine(folder, "data", "System.json")) && !triedThat) + { + throw new Exception("Quit"); + } + + string[] mzPngs = Directory.GetFiles(folder, "*.png_", SearchOption.AllDirectories); string[] mvPngs = Directory.GetFiles(folder, "*.rpgmvp", SearchOption.AllDirectories); - string[] mzM4as = Directory.GetFiles(folder, "*._m4a", SearchOption.AllDirectories); + string[] mzM4as = Directory.GetFiles(folder, "*.m4a_", SearchOption.AllDirectories); string[] mvM4as = Directory.GetFiles(folder, "*.rpgmvm", SearchOption.AllDirectories); - string[] mzOggs = Directory.GetFiles(folder, "*._ogg", SearchOption.AllDirectories); + string[] mzOggs = Directory.GetFiles(folder, "*.ogg_", SearchOption.AllDirectories); string[] mvOggs = Directory.GetFiles(folder, "*.rpgmvo", SearchOption.AllDirectories); string[] mzArtifacts = Directory.GetFiles(folder, "rmmz_*", SearchOption.AllDirectories); @@ -350,6 +360,7 @@ namespace RMDEC mvp.systemJsonFile = null; mvp.jsonData = null; + mvp.gameTitle = "Unknown Title"; return mvp; } @@ -360,8 +371,11 @@ namespace RMDEC Random rng = new Random((int)DateTime.Now.Ticks); rng.NextBytes(keyData); encryptionKey = keyData; - jsonData.encryptionKey = BitConverter.ToString(keyData, 0x00, keyData.Length).Replace("-", ""); - File.WriteAllText(systemJsonFile, jsonData.ToString(Formatting.None)); + if(jsonData != null) + { + jsonData.encryptionKey = BitConverter.ToString(keyData, 0x00, keyData.Length).Replace("-", ""); + File.WriteAllText(systemJsonFile, jsonData.ToString(Formatting.None)); + } isKeySet = true; } @@ -386,7 +400,7 @@ namespace RMDEC } else { - return GuessProject(path); + return GuessProject(path, true); } if (systemJson.hasEncryptedAudio != null) diff --git a/RMDEC/MVProjectToolset.cs b/RMDEC/MVProjectToolset.cs index 3cd5ab1..72bfa68 100644 --- a/RMDEC/MVProjectToolset.cs +++ b/RMDEC/MVProjectToolset.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; -using System.Linq; using System.Threading; using System.Windows.Forms; using static System.Windows.Forms.ListBox; @@ -28,7 +27,7 @@ namespace RMDEC private List encFileList = new List(); private List decFileList = new List(); - private string[] blacklistedFiles = { Path.Combine("icon", "icon.png"), Path.Combine("img", "system", "Window.png"), Path.Combine("img", "system", "Loading.png") }; + private string[] blacklistedFiles = { Path.Combine("effects", "Texture"), Path.Combine("icon", "icon.png"), Path.Combine("img", "system", "Window.png"), Path.Combine("img", "system", "Loading.png") }; private bool encryptedIndexingComplete = false; private bool unencryptedIndexingComplete = false; @@ -130,8 +129,6 @@ namespace RMDEC foreach (string file in Directory.EnumerateFiles(mvProject.FilePath, "*", SearchOption.AllDirectories)) { - - string fileExtension = Path.GetExtension(file).ToLower(); switch (fileExtension) @@ -218,7 +215,17 @@ namespace RMDEC string relativeName = file.Remove(0, mvProject.FilePath.Length + 1); string fileExtension = Path.GetExtension(file).ToLower(); - if(blacklistedFiles.Contains(relativeName)) + bool skip = false; + foreach (string blacklistedFile in blacklistedFiles) + { + if (relativeName.StartsWith(blacklistedFile)) + { + skip = true; + break; + } + } + + if (skip) { continue; } @@ -773,18 +780,20 @@ namespace RMDEC { if(mvProject.EncryptedAudio == true && unencryptedMusicCount > 0) { - DialogResult res = MessageBox.Show("Warning: You have mixed unencrypted/encrypted Audio files!\n\nMV Requires ALL Decrypted or ALL Encrypted\nThe game WILL CRASH when attemping to load these files\nPlease Encrypt ALL Audio Files or Decrypt ALL Audio Files.", "Mixed Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); - if(res == DialogResult.OK) + DialogResult res = MessageBox.Show("Warning: You have mixed unencrypted/encrypted Audio files!\n\nMV Requires ALL Decrypted or ALL Encrypted\nThe game WILL CRASH when attemping to load these files\nPlease Encrypt ALL Audio Files or Decrypt ALL Audio Files.\n\nDo you want to exit anyway?", "Mixed Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); + if(res == DialogResult.No) { e.Cancel = true; + return; } } if (mvProject.EncryptedImages == true && unencryptedImageCount > 0) { - DialogResult res = MessageBox.Show("Warning: You have mixed unencrypted/encrypted Image files!\n\nMV Requires ALL Decrypted or ALL Encrypted\nThe game WILL CRASH when attemping to load these files\nPlease Encrypt ALL Images or Decrypt ALL Images.", "Mixed Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); - if (res == DialogResult.OK) + DialogResult res = MessageBox.Show("Warning: You have mixed unencrypted/encrypted Image files!\n\nMV Requires ALL Decrypted or ALL Encrypted\nThe game WILL CRASH when attemping to load these files\nPlease Encrypt ALL Images or Decrypt ALL Images.\n\nDo you want to exit anyway?", "Mixed Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); + if (res == DialogResult.No) { e.Cancel = true; + return; } } } diff --git a/RMDEC/projectSelector.cs b/RMDEC/projectSelector.cs index d00a8ed..5551085 100644 --- a/RMDEC/projectSelector.cs +++ b/RMDEC/projectSelector.cs @@ -28,7 +28,7 @@ namespace RMDEC string relativeName = projectFile.Remove(0,projectDir.Text.Length + 1); string extension = Path.GetExtension(projectFile).ToLower(); - if (extension == ".json" || extension == ".js" || extension == ".png") + if (extension == ".json" || extension == ".js") { try { @@ -72,16 +72,13 @@ namespace RMDEC { foreach (string fileEntry in fileList) { - bool shouldBreak = false; - if (Path.GetFileName(fileEntry).ToLower() == "system.json" || Path.GetFileName(fileEntry).ToLower().StartsWith("rmmz_core") || Path.GetFileName(fileEntry).ToLower().StartsWith("rpg_core") || Path.GetFileName(fileEntry).ToLower().StartsWith("icon.png") || Path.GetExtension(fileEntry).ToLower() == ".rgss3a") + if (Path.GetFileName(fileEntry).ToLower() == "system.json" || Path.GetFileName(fileEntry).ToLower().StartsWith("rmmz_core") || Path.GetFileName(fileEntry).ToLower().StartsWith("rpg_core") || Path.GetExtension(fileEntry).ToLower() == ".rgss3a") { Invoke((Action)delegate { - shouldBreak = tryAddProject(fileEntry); + tryAddProject(fileEntry); }); } - if (shouldBreak) - break; } } catch (Exception) { }; @@ -133,14 +130,14 @@ namespace RMDEC mvProjectToolset mvToolset = new mvProjectToolset((MVProject)globalProjectList[index]); this.Hide(); mvToolset.Show(); - mvToolset.FormClosing += MvToolset_FormClosing; + mvToolset.FormClosed += MvToolset_FormClosed; } if(proj is VXAProject) { vxaProjectToolset vxToolset = new vxaProjectToolset((VXAProject)globalProjectList[index]); this.Hide(); vxToolset.Show(); - vxToolset.FormClosing += VxToolset_FormClosing; + vxToolset.FormClosed += VxToolset_FormClosed; } } } @@ -161,12 +158,12 @@ namespace RMDEC this.Show(); } - private void MvToolset_FormClosing(object sender, FormClosingEventArgs e) + private void MvToolset_FormClosed(object sender, FormClosedEventArgs e) { onChildFormClosed(); } - private void VxToolset_FormClosing(object sender, FormClosingEventArgs e) + private void VxToolset_FormClosed(object sender, FormClosedEventArgs e) { onChildFormClosed(); }