public void Write(Stream oStream, BXML_TYPE oType) { if (oType == BXML_TYPE.BXML_PLAIN) { Nodes.Save(oStream); } if (oType == BXML_TYPE.BXML_BINARY) { BinaryWriter bw = new BinaryWriter(oStream); bw.Write(Signature); bw.Write(Version); bw.Write(FileSize); bw.Write(Padding); bw.Write(Unknown); bw.Write(OriginalPathLength); bw.Write(OriginalPath); AutoID = 1; WriteNode(oStream); FileSize = (int)oStream.Position; oStream.Position = 12; bw.Write(FileSize); } }
public BXML_TYPE DetectType(Stream iStream) { int offset = (int)iStream.Position; iStream.Position = 0; byte[] Signature = new byte[13]; iStream.Read(Signature, 0, 13); iStream.Position = offset; BXML_TYPE result = BXML_TYPE.BXML_UNKNOWN; if ( BitConverter.ToString(Signature).Replace("-", "").Replace("00", "").Contains(BitConverter.ToString(new byte[] { (byte)'<', (byte)'?', (byte)'x', (byte)'m', (byte)'l' }).Replace("-", "")) ) { result = BXML_TYPE.BXML_PLAIN; } if ( Signature[7] == 'B' && Signature[6] == 'L' && Signature[5] == 'S' && Signature[4] == 'O' && Signature[3] == 'B' && Signature[2] == 'X' && Signature[1] == 'M' && Signature[0] == 'L' ) { result = BXML_TYPE.BXML_BINARY; } return(result); }
public BXML_TYPE DetectType(Stream iStream) { int num = (int)iStream.Position; iStream.Position = 0L; byte[] array = new byte[13]; iStream.Read(array, 0, 13); iStream.Position = num; BXML_TYPE result = BXML_TYPE.BXML_UNKNOWN; if (BitConverter.ToString(array).Replace("-", "").Replace("00", "") .Contains(BitConverter.ToString(new byte[5] { 60, 63, 120, 109, 108 }).Replace("-", ""))) { result = BXML_TYPE.BXML_PLAIN; } if (array[7] == 66 && array[6] == 76 && array[5] == 83 && array[4] == 79 && array[3] == 66 && array[2] == 88 && array[1] == 77 && array[0] == 76) { result = BXML_TYPE.BXML_BINARY; } return(result); }
public void Write64(BinaryWriter bw, BXML_TYPE iType) { bw.Write((long)Size_1); bw.Write((long)Size_2); bw.Write((long)Size_3); bw.Write(Padding); if (!Complement) { bw.Write(Data); } }
public void Read64(BinaryReader br, BXML_TYPE iType) { Size_1 = (int)br.ReadInt64(); Size_2 = (int)br.ReadInt64(); Size_3 = (int)br.ReadInt64(); Padding = br.ReadBytes(62); Data = new byte[Size_1]; if (!Complement) { Data = br.ReadBytes(Size_1); } }
public void Save(BinaryWriter bw, BXML_TYPE iType, bool is64) { if (is64) { _content.Write64(bw, iType); } else { _content.Write(bw, iType); } bw.Flush(); }
public void Write64(BinaryWriter bw, BXML_TYPE iType) { bw.Write(Signature); bw.Write(Version); bw.Write(Unknown); bw.Write((long)ListCount); HeadList.Write64(bw, iType); for (int l = 0; l < ListCount; l++) { Lists[l].Write(bw); } }
private void Converts(Stream iStream, BXML_TYPE iType, Stream oStream, BXML_TYPE oType) { if ((iType == BXML_TYPE.BXML_PLAIN && oType == BXML_TYPE.BXML_BINARY) || (iType == BXML_TYPE.BXML_BINARY && oType == BXML_TYPE.BXML_PLAIN)) { BXML bns_xml = new BXML(XOR_KEY); bns_xml.Load(iStream, iType); bns_xml.Save(oStream, oType); } else { iStream.CopyTo(oStream); } }
public void Load(BinaryReader br, BXML_TYPE iType, bool is64 = false) { if (iType == BXML_TYPE.BXML_PLAIN || iType == BXML_TYPE.BXML_BINARY) { if (is64) { _content.Read64(br, BXML_TYPE.BXML_BINARY); } else { _content.Read(br, BXML_TYPE.BXML_BINARY); } DetectIndices(); } }
public void Dump(string FileName, string saveFolder, BXML_TYPE format, bool is64) { FileStream fs = new FileStream(FileName, FileMode.Open); BinaryReader br = new BinaryReader(fs); Load(br, format, is64); Directory.CreateDirectory(saveFolder); DumpFAQ(saveFolder + @"\lookup_faq.txt"); DumpGeneral(saveFolder + @"\lookup_general.txt"); DumpCommand(saveFolder + @"\lookup_command.txt"); DumpXML(saveFolder); fs.Close(); br.Close(); }
public void Read64(BinaryReader br, BXML_TYPE iType) { Signature = br.ReadBytes(8); Version = br.ReadInt32(); Unknown = br.ReadBytes(13); ListCount = (int)br.ReadInt64(); HeadList = new BDAT_HEAD(); HeadList.Complement = false; if (ListCount < 20) { HeadList.Complement = true; } HeadList.Read64(br, iType); Lists = new BDAT_LIST[ListCount]; //Console.WriteLine("64bit Signature: {0}, Version: {1}, Unknown: {2}, ListCount: {3}", Signature, Version, Unknown, ListCount); for (int l = 0; l < ListCount; l++) { Lists[l] = new BDAT_LIST(); Lists[l].Read(br); } }
public void Save(Stream oStream, BXML_TYPE oType) { _content.Write(oStream, oType); }
public void Load(Stream iStream, BXML_TYPE iType) { _content.Read(iStream, iType); }
public void ExportTranslate(string FileName, string saveFolder, BXML_TYPE format, bool is64) { FileStream fs = new FileStream(FileName, FileMode.Open); BinaryReader br = new BinaryReader(fs); Load(br, format, is64); using (StreamWriter outfile = new StreamWriter(saveFolder)) { outfile.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); int empty = 0; string alias = string.Empty; string text = string.Empty; for (int l = 0; l < _content.ListCount; l++) { BDAT_LIST blist = _content.Lists[l]; BDAT_COLLECTION bcollection = blist.Collection; if (bcollection.Compressed > 0) { outfile.WriteLine("<table>"); int autoId = 1; BDAT_ARCHIVE barchive = bcollection.Archive; for (int a = 0; a < barchive.SubArchiveCount; a++) { BDAT_SUBARCHIVE bsubarchive = barchive.SubArchives[a]; for (int f = 0; f < bsubarchive.FieldLookupCount; f++) { BDAT_FIELDTABLE bfield = bsubarchive.Fields[f]; BDAT_LOOKUPTABLE blookup = bsubarchive.Lookups[f]; string[] words = LookupSplitToWords(blookup.Data, blookup.Size); empty = 0; alias = string.Empty; text = string.Empty; for (int w = 0; w < words.Length; w++) { if (words[w] != null && words[w].Length > 0) { switch (w) { case 0: alias = string.Format("\t<text autoId=\"{0}\" alias=\"{1}\" priority=\"0\">", autoId, words[w]); autoId++; break; default: text = "<![CDATA[" + words[w] + "]]>"; //System.Web.HttpUtility.HtmlEncode(words[w]); break; } } else { empty++; } } if (!string.IsNullOrEmpty(alias) && !string.IsNullOrEmpty(text)) { outfile.WriteLine(alias); outfile.WriteLine("\t\t<original>" + text + "</original>"); outfile.WriteLine("\t\t<replacement>" + text + "</replacement>"); outfile.WriteLine("\t</text>"); } } } outfile.WriteLine("</table>"); } } } fs.Close(); br.Close(); }
public void Read(Stream iStream, BXML_TYPE iType) { if (iType == BXML_TYPE.BXML_PLAIN) { Signature = new byte[8] { (byte)'L', (byte)'M', (byte)'X', (byte)'B', (byte)'O', (byte)'S', (byte)'L', (byte)'B' }; Version = 3; FileSize = 85; Padding = new byte[64]; Unknown = true; OriginalPathLength = 0; // NOTE: keep whitespace text nodes (to be compliant with the whitespace TEXT_NODES in bns xml) // no we don't keep them, we remove them because it is cleaner Nodes.PreserveWhitespace = Keep_XML_WhiteSpace; Nodes.Load(iStream); // get original path from first comment node XmlNode node = null; try { node = Nodes.DocumentElement.ChildNodes.OfType <XmlComment>().First(); } catch { } finally { if (node != null && node.NodeType == XmlNodeType.Comment) { string Text = node.InnerText; OriginalPathLength = Text.Length; OriginalPath = Encoding.Unicode.GetBytes(Text); Xor(OriginalPath, 2 * OriginalPathLength); if (Nodes.PreserveWhitespace && node.NextSibling.NodeType == XmlNodeType.Whitespace) { Nodes.DocumentElement.RemoveChild(node.NextSibling); } } else { OriginalPath = new byte[2 * OriginalPathLength]; } } } if (iType == BXML_TYPE.BXML_BINARY) { Signature = new byte[8]; BinaryReader br = new BinaryReader(iStream); br.BaseStream.Position = 0; Signature = br.ReadBytes(8); Version = br.ReadInt32(); FileSize = br.ReadInt32(); Padding = br.ReadBytes(64); Unknown = br.ReadByte() == 1; OriginalPathLength = br.ReadInt32(); OriginalPath = br.ReadBytes(2 * OriginalPathLength); AutoID = 1; ReadNode(iStream); // add original path as first comment node byte[] Path = OriginalPath; Xor(Path, 2 * OriginalPathLength); XmlComment node = Nodes.CreateComment(Encoding.Unicode.GetString(Path)); Nodes.DocumentElement.PrependChild(node); XmlNode docNode = Nodes.CreateXmlDeclaration("1.0", "utf-8", null); Nodes.PrependChild(docNode); if (FileSize != iStream.Position) { throw new Exception(String.Format("Filesize Mismatch, expected size was {0} while actual size was {1}.", FileSize, iStream.Position)); } } }
public void Read(Stream iStream, BXML_TYPE iType) { if (iType == BXML_TYPE.BXML_PLAIN) { Signature = new byte[8] { 76, 77, 88, 66, 79, 83, 76, 66 }; Version = 3; FileSize = 85; Padding = new byte[64]; Unknown = true; OriginalPathLength = 0; Nodes.PreserveWhitespace = Keep_XML_WhiteSpace; Nodes.Load(iStream); XmlNode xmlNode = Nodes.DocumentElement.ChildNodes.OfType <XmlComment>().First(); origName = xmlNode; if (xmlNode != null && xmlNode.NodeType == XmlNodeType.Comment) { string innerText = xmlNode.InnerText; OriginalPathLength = innerText.Length; OriginalPath = Encoding.Unicode.GetBytes(innerText); Xor(OriginalPath, 2 * OriginalPathLength); if (Nodes.PreserveWhitespace && xmlNode.NextSibling.NodeType == XmlNodeType.Whitespace) { Nodes.DocumentElement.RemoveChild(xmlNode.NextSibling); } } else { OriginalPath = new byte[2 * OriginalPathLength]; } } if (iType == BXML_TYPE.BXML_BINARY) { Signature = new byte[8]; BinaryReader binaryReader = new BinaryReader(iStream); binaryReader.BaseStream.Position = 0L; Signature = binaryReader.ReadBytes(8); Version = binaryReader.ReadInt32(); FileSize = binaryReader.ReadInt32(); Padding = binaryReader.ReadBytes(64); Unknown = (binaryReader.ReadByte() == 1); OriginalPathLength = binaryReader.ReadInt32(); OriginalPath = binaryReader.ReadBytes(2 * OriginalPathLength); AutoID = 1; ReadNode(iStream); byte[] originalPath = OriginalPath; Xor(originalPath, 2 * OriginalPathLength); XmlComment newChild = Nodes.CreateComment(Encoding.Unicode.GetString(originalPath)); Nodes.DocumentElement.PrependChild(newChild); XmlNode newChild2 = Nodes.CreateXmlDeclaration("1.0", "utf-8", null); Nodes.PrependChild(newChild2); if (FileSize != iStream.Position) { throw new Exception($"Filesize Mismatch, expected size was {FileSize} while actual size was {iStream.Position}."); } } }