diff --git a/.vs/RMDEC/v16/.suo b/.vs/RMDEC/v16/.suo index f43cfe8..5beb666 100644 Binary files a/.vs/RMDEC/v16/.suo and b/.vs/RMDEC/v16/.suo differ diff --git a/RMDEC/MVProject.cs b/RMDEC/MVProject.cs index c70291b..c1e9321 100644 --- a/RMDEC/MVProject.cs +++ b/RMDEC/MVProject.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Text; namespace RMDEC @@ -15,6 +16,9 @@ namespace RMDEC //Private internal variables private byte[] encryptionKey = new byte[0x10]; + private static byte[] pngHeader = new byte[0x10] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52 }; + private static byte[] m4aHeader = new byte[0x10] { 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41, 0x20, 0x00, 0x00, 0x00, 0x00 }; + private static byte[] oggHeader = new byte[0x10] { 0x4F, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; private bool isKeySet = false; private bool encryptedImages = false; @@ -132,11 +136,11 @@ namespace RMDEC private static byte[] guessKey(string path) // Incase you think your smart { bool useOgg = false; - 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(); @@ -160,11 +164,6 @@ namespace RMDEC } } - byte[] pngHeader = new byte[0x10] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52 }; - byte[] m4aHeader = new byte[0x10] { 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 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(); }