public static byte[] GetDataFromHTML(byte[] file) { for (int u = 0; u < file.Length - 15; u++) { if (System.Text.Encoding.GetEncoding(932).GetString(file, u, 15) == "NAME=\"chaodata\"") { // Load Base64 StringBuilder b64str = new StringBuilder(); for (int k = u + 23; k < file.Length - 2; k++) { if (file[k] == 0x22 && file[k + 1] == 0x3E) { break; } else { b64str.Append((Convert.ToChar(file[k])).ToString()); } } // Decode Base64, decrypt byte[] data = Convert.FromBase64String(b64str.ToString()); VMSFile.DecryptData(ref data); return(data); } } return(null); }
public static void ProcessVMS(ref byte[] input) { int aniFrames = input[0x40] + (input[0x41] << 8); int dataStart = 0x80 + (aniFrames * 0x200); byte[] encrypted = new byte[input.Length - dataStart]; Array.Copy(input, dataStart, encrypted, 0, encrypted.Length); VMSFile.DecryptData(ref encrypted); Array.Copy(encrypted, 0, input, dataStart, encrypted.Length); }
private void wholeFileToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog od = new OpenFileDialog() { DefaultExt = "bin", Filter = "All Files|*.*" }) if (od.ShowDialog(this) == DialogResult.OK) { byte[] data = File.ReadAllBytes(od.FileName); VMSFile.DecryptData(ref data); string outpath = Path.Combine(Path.GetDirectoryName(od.FileName), Path.GetFileNameWithoutExtension(od.FileName)) + "_dec.bin"; File.WriteAllBytes(outpath, data); MessageBox.Show(this, "Binary file saved as:\n" + outpath, "VMS Editor", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void vMSFileToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog od = new OpenFileDialog() { DefaultExt = "vms", Filter = "VMS Files|*.vms|All Files|*.*" }) if (od.ShowDialog(this) == DialogResult.OK) { byte[] data = File.ReadAllBytes(od.FileName); int aniFrames = data[0x40] + (data[0x41] << 8); int dataStart = 0x80 + (aniFrames * 0x200); byte[] encrypted = new byte[data.Length - dataStart]; Array.Copy(data, dataStart, encrypted, 0, encrypted.Length); VMSFile.DecryptData(ref encrypted); Array.Copy(encrypted, 0, data, dataStart, encrypted.Length); string outpath = Path.Combine(Path.GetDirectoryName(od.FileName), Path.GetFileNameWithoutExtension(od.FileName)) + "_dec.vms"; File.WriteAllBytes(outpath, data); MessageBox.Show(this, "VMS file saved as:\n" + outpath, "VMS Editor", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Load from a byte array (VMS file) /// </summary> public VMS_DLC(byte[] file) { // Decrypt if encrypted if (BitConverter.ToUInt32(file, 0x280) != 0x2C0) { int aniFrames = file[0x40] + (file[0x41] << 8); int dataStart = 0x80 + (aniFrames * 0x200); byte[] encrypted = new byte[file.Length - dataStart]; Array.Copy(file, dataStart, encrypted, 0, encrypted.Length); VMSFile.DecryptData(ref encrypted); Array.Copy(encrypted, 0, file, dataStart, encrypted.Length); } // Get title and other stuff byte[] title_b = GetTextItem(ref file, 0, 16); byte[] description_b = GetTextItem(ref file, 0x10, 32); byte[] appname_b = GetTextItem(ref file, 0x30, 16); Description = System.Text.Encoding.GetEncoding(932).GetString(description_b); Title = System.Text.Encoding.GetEncoding(932).GetString(title_b); AppName = System.Text.Encoding.GetEncoding(932).GetString(appname_b); Icon = GetIconFromFile(file); // Get items int item_pointer = BitConverter.ToInt32(file, 0x280); if (item_pointer != 0x2C0) { System.Windows.Forms.MessageBox.Show("Unable to find SA1 DLC data.", "DLC Tool Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); Items = new List <DLCObjectData>(); JapaneseStrings = new string[16]; EnglishStrings = new string[16]; FrenchStrings = new string[16]; GermanStrings = new string[16]; SpanishStrings = new string[16]; TextureData = new byte[0]; SoundData = new byte[0]; ModelData = new byte[0]; return; } Identifier = BitConverter.ToUInt32(file, item_pointer); if ((file[item_pointer + 4] & 0xF) > 0) { EnableSonic = true; } if ((file[item_pointer + 4] >> 4) > 0) { EnableTails = true; } if ((file[item_pointer + 5] & 0xF) > 0) { EnableKnuckles = true; } if ((file[item_pointer + 5] >> 4) > 0) { EnableGamma = true; } if ((file[item_pointer + 6] & 0xF) > 0) { EnableAmy = true; } if ((file[item_pointer + 6] >> 4) > 0) { EnableBig = true; } if ((file[item_pointer + 7] & 0xF) > 0) { EnableWhatever1 = true; } if ((file[item_pointer + 7] >> 4) > 0) { EnableWhatever2 = true; } Region = (DLCRegionLocks)BitConverter.ToInt32(file, item_pointer + 8); // Item table int item_count = BitConverter.ToInt32(file, 0x284); Items = new List <DLCObjectData>(item_count); item_pointer += 12; // Skip 12-byte item section header for (int u = 0; u < item_count; u++) { DLCObjectData dlcitem = new DLCObjectData(); dlcitem.Level = file[item_pointer + u * 30]; dlcitem.Act = file[item_pointer + u * 30 + 1]; dlcitem.ScaleX = file[item_pointer + u * 30 + 2]; dlcitem.ScaleY = file[item_pointer + u * 30 + 3]; dlcitem.ScaleZ = file[item_pointer + u * 30 + 4]; dlcitem.RotSpeedX = (sbyte)file[item_pointer + u * 30 + 5]; dlcitem.RotSpeedY = (sbyte)file[item_pointer + u * 30 + 6]; dlcitem.RotSpeedX = (sbyte)file[item_pointer + u * 30 + 7]; dlcitem.ObjectType = (DLCObjectTypes)file[item_pointer + u * 30 + 8]; dlcitem.Texture = file[item_pointer + u * 30 + 9]; dlcitem.Flags = (DLCObjectFlags)(BitConverter.ToUInt16(file, item_pointer + u * 30 + 10)); dlcitem.InternalID = file[item_pointer + u * 30 + 12]; dlcitem.Unknown3 = file[item_pointer + u * 30 + 13]; dlcitem.Message = file[item_pointer + u * 30 + 14]; dlcitem.TriggerDistance = file[item_pointer + u * 30 + 15]; dlcitem.WarpLevelOrSoundbank = file[item_pointer + u * 30 + 16]; dlcitem.WarpActOrSoundID = file[item_pointer + u * 30 + 17]; dlcitem.RotationX = BitConverter.ToUInt16(file, item_pointer + u * 30 + 18); dlcitem.RotationY = BitConverter.ToUInt16(file, item_pointer + u * 30 + 20); dlcitem.RotationZ = BitConverter.ToUInt16(file, item_pointer + u * 30 + 22); dlcitem.X = BitConverter.ToInt16(file, item_pointer + u * 30 + 24); dlcitem.Y = BitConverter.ToInt16(file, item_pointer + u * 30 + 26); dlcitem.Z = BitConverter.ToInt16(file, item_pointer + u * 30 + 28); Items.Add(dlcitem); } // Get strings JapaneseStrings = new string[16]; EnglishStrings = new string[16]; FrenchStrings = new string[16]; SpanishStrings = new string[16]; GermanStrings = new string[16]; int text_pointer = BitConverter.ToInt32(file, 0x288); int text_count = BitConverter.ToInt32(file, 0x28C); List <string> strings = new List <string>(); for (int u = 0; u < text_count; u++) { byte[] arr = new byte[64]; Array.Copy(file, text_pointer + 64 * u, arr, 0, 64); int charcount = 0; for (int a = 0; a < arr.Length; a++) { if (arr[a] == 0) { break; } charcount++; } System.Text.Encoding enc = System.Text.Encoding.GetEncoding(932); if (u >= 32) { enc = System.Text.Encoding.GetEncoding(1252); } string str = enc.GetString(arr, 0, charcount); strings.Add(str); } // Process special characters List <string> strings_new = new List <string>(); foreach (string str in strings) { string newstr = System.String.Empty; for (int s = 0; s < str.Length; s++) { if (s == 0 && (str[s] == '~' || str[s] == 't')) { newstr += ("\t"); } else if (str[s] == 't' && str[0] == 't') { newstr += ("\t"); } else if (str[s] == '~' && str[0] == '~') { newstr += ("\t"); } else if ((str[s] == 'n' && str[0] == 't') || (str[s] == '@' && str[0] == '~')) { newstr += ("\n"); } else { newstr += str[s]; } } strings_new.Add(newstr); } string[] stringarr = strings_new.ToArray(); for (int u = 0; u < 16; u++) { if (u >= text_count) { break; } JapaneseStrings[u] = stringarr[u]; if (text_count <= 16) { continue; } EnglishStrings[u] = stringarr[u + 16]; if (text_count <= 32) { continue; } FrenchStrings[u] = stringarr[u + 32]; if (text_count <= 48) { continue; } SpanishStrings[u] = stringarr[u + 48]; if (text_count <= 64) { continue; } GermanStrings[u] = stringarr[u + 64]; } TextureData = new byte[0]; SoundData = new byte[0]; ModelData = new byte[0]; // Get PVM pointer uint pvm_pointer = BitConverter.ToUInt32(file, 0x290); // Number of PVMs at 0x294, number of textures at 0x298 // Get MLT pointer uint mlt_pointer = BitConverter.ToUInt32(file, 0x29C); int nummlt = BitConverter.ToInt32(file, 0x2A0); if (nummlt != 0) { ContainsSound = true; } // Get PRS pointer uint prs_pointer = BitConverter.ToUInt32(file, 0x2A4); // Number of PRSes at 0x2A8 // Get PVM data int pvm_size = (int)mlt_pointer - (int)pvm_pointer; if (pvm_size > 0) { TextureData = new byte[pvm_size]; Array.Copy(file, pvm_pointer, TextureData, 0, pvm_size); } // Get MLT data int mlt_size = (int)prs_pointer - (int)mlt_pointer; if (mlt_size > 0) { SoundData = new byte[mlt_size]; Array.Copy(file, mlt_pointer, SoundData, 0, mlt_size); } int item_size = (item_count * 30 + 12); // 12-byte header, headerless section size at 0x48 do { item_size++; }while (item_size % 16 != 0); // The size of the PRS cannot be determined reliably because the file might be padded to have a size divisible by 512 // To get the correct size, the PRS chunk is read until the end of file or a sequence of 16 empty bytes int prs_size = 0; for (int indx = (int)prs_pointer; indx < file.Length; indx += 16) { bool valid = false; for (int u = 0; u < 16; u++) { if (file[indx + u] != 0) { valid = true; break; } } if (valid) { prs_size += 16; } else { break; } } // Get PRS data if (prs_size > 0) { ModelData = new byte[prs_size]; Array.Copy(file, prs_pointer, ModelData, 0, prs_size); } }