Beispiel #1
0
        public void DumpGeneral(string file)
        {
            if (_indexCommons > -1)
            {
                using (StreamWriter outfile = new StreamWriter(file))
                {
                    BDAT_LIST blist = _content.Lists[_indexCommons];

                    if (blist.Collection.Compressed > 0)
                    {
                        BDAT_ARCHIVE barchive = blist.Collection.Archive;
                        for (int s = 0; s < barchive.SubArchiveCount; s++)
                        {
                            BDAT_SUBARCHIVE bsubarchive = barchive.SubArchives[s];
                            for (int f = 0; f < bsubarchive.FieldLookupCount; f++)
                            {
                                BDAT_LOOKUPTABLE blookup = bsubarchive.Lookups[f];
                                string[]         words   = LookupSplitToWords(blookup.Data, blookup.Size);
                                for (int w = 0; w < words.Length; w++)
                                {
                                    if (w % 2 == 0)
                                    {
                                        outfile.WriteLine("<alias>");
                                        outfile.WriteLine(words[w]);
                                        outfile.WriteLine("</alias>");
                                    }
                                    else
                                    {
                                        outfile.WriteLine("<text>");
                                        outfile.WriteLine(words[w]);
                                        outfile.WriteLine("</text>");
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        BDAT_LOOSE bloose = blist.Collection.Loose;
                        string[]   words  = LookupSplitToWords(bloose.Lookup.Data, bloose.SizeLookup);
                        for (int w = 0; w < words.Length; w++)
                        {
                            if (w % 2 == 0)
                            {
                                outfile.WriteLine("<alias>");
                                outfile.WriteLine(words[w]);
                                outfile.WriteLine("</alias>");
                            }
                            else
                            {
                                outfile.WriteLine("<text>");
                                outfile.WriteLine(words[w]);
                                outfile.WriteLine("</text>");
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
        public void DumpCommand(string file)
        {
            if (_indexCommands > -1)
            {
                using (StreamWriter outfile = new StreamWriter(file))
                {
                    BDAT_LIST blist = _content.Lists[_indexCommands];

                    BDAT_LOOSE bloose = blist.Collection.Loose;
                    string[]   words  = LookupSplitToWords(bloose.Lookup.Data, bloose.SizeLookup);
                    for (int w = 0; w < words.Length; w++)
                    {
                        outfile.WriteLine("<alias>");
                        outfile.WriteLine("</alias>");
                        outfile.WriteLine("<text>");
                        outfile.WriteLine(words[w]);
                        outfile.WriteLine("</text>");
                    }
                }
            }
            //Console.WriteLine("_indexCommands: " + _indexCommands);
        }
Beispiel #4
0
        public void DumpFAQ(string file)
        {
            if (_indexFaqs > -1)
            {
                BDAT_LIST blist = _content.Lists[_indexFaqs];

                BDAT_LOOSE bloose = blist.Collection.Loose;

                string[] words = LookupSplitToWords(bloose.Lookup.Data, bloose.SizeLookup);

                using (StreamWriter outfile = new StreamWriter(file))
                {
                    foreach (string text in words)
                    {
                        outfile.WriteLine("<alias>");
                        outfile.WriteLine("</alias>");
                        outfile.WriteLine("<text>");
                        outfile.WriteLine(text);
                        outfile.WriteLine("</text>");
                    }
                }
            }
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
        public void DetectIndices()
        {
            int fieldsize = 0;

            for (int l = 0; l < _content.ListCount; l++)
            {
                BDAT_LIST blist = _content.Lists[l];
                if (blist.Unknown1 == 2 && blist.Unknown2 == 0)
                {
                    fieldsize = 0;
                    if (blist.Collection.Archive != null && blist.Collection.Archive.SubArchiveCount > 0 && blist.Collection.Archive.SubArchives[0].FieldLookupCount > 0)
                    {
                        fieldsize = blist.Collection.Archive.SubArchives[0].Fields[0].Size;
                    }
                    else if (blist.Collection.Loose != null && blist.Collection.Loose.FieldCount > 0)
                    {
                        fieldsize = blist.Collection.Loose.Fields[0].Size;
                    }
                    if (fieldsize == 32 || fieldsize == 40)
                    {
                        _indexFaqs = l;
                    }
                }

                if (blist.Size > 5000000 && blist.Unknown1 == 1 && blist.Unknown2 == 0)
                {
                    fieldsize = 0;
                    if (blist.Collection.Archive != null && blist.Collection.Archive.SubArchiveCount > 0 && blist.Collection.Archive.SubArchives[0].FieldLookupCount > 0)
                    {
                        fieldsize = blist.Collection.Archive.SubArchives[0].Fields[0].Size;
                    }
                    else if (blist.Collection.Loose != null && blist.Collection.Loose.FieldCount > 0)
                    {
                        fieldsize = blist.Collection.Loose.Fields[0].Size;
                    }
                    if (fieldsize == 28 || fieldsize == 36)
                    {
                        _indexCommons = l;
                    }
                }

                if (_indexCommons > -1 && (int)_indexCommons < l && blist.Unknown1 == 1 && blist.Unknown2 == 0)
                {
                    fieldsize = 0;
                    if (blist.Collection.Archive != null && blist.Collection.Archive.SubArchiveCount > 0 && blist.Collection.Archive.SubArchives[0].FieldLookupCount > 0)
                    {
                        fieldsize = blist.Collection.Archive.SubArchives[0].Fields[0].Size;
                        //Console.WriteLine("1=> _indexCommands fieldsize = " + fieldsize);
                    }
                    else if (blist.Collection.Loose != null && blist.Collection.Loose.FieldCount > 0)
                    {
                        fieldsize = blist.Collection.Loose.Fields[0].Size;
                        //Console.WriteLine("2 =>_indexCommands fieldsize = " + fieldsize);
                    }

                    if (fieldsize == 28)
                    {
                        _indexCommands = l;
                    }
                }
            }
        }
Beispiel #7
0
        public void DumpXML(string dir)
        {
            for (int l = 0; l < _content.ListCount; l++)
            {
                BDAT_LIST blist = _content.Lists[l];

                using (StreamWriter outfile = new StreamWriter(dir + "\\datafile_" + blist.ID + ".xml"))
                {
                    outfile.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                    outfile.WriteLine(string.Format("<list id=\"{0}\" size=\"{1}\" unk1=\"{2}\" unk2=\"{3}\" unk3=\"{4}\">", blist.ID, blist.Size, blist.Unknown1, blist.Unknown2, blist.Unknown3));
                    BDAT_COLLECTION bcollection = blist.Collection;
                    outfile.WriteLine(string.Format("\t<collection compressed=\"{0}\">", bcollection.Compressed));
                    if (bcollection.Compressed > 0)
                    {
                        BDAT_ARCHIVE barchive = bcollection.Archive;
                        outfile.WriteLine(string.Format("\t\t<archive count=\"{0}\">", barchive.SubArchiveCount));
                        for (int a = 0; a < barchive.SubArchiveCount; a++)
                        {
                            BDAT_SUBARCHIVE bsubarchive = barchive.SubArchives[a];
                            outfile.WriteLine(string.Format("\t\t\t<subarchive count=\"{0}\" StartAndEndFieldId=\"{1}\">", bsubarchive.FieldLookupCount, m_bnsDat.BytesToHex(bsubarchive.StartAndEndFieldId)));
                            for (int f = 0; f < bsubarchive.FieldLookupCount; f++)
                            {
                                BDAT_FIELDTABLE bfield = bsubarchive.Fields[f];
                                outfile.Write(string.Format("\t\t\t\t<field ID=\"{3}\" size=\"{0}\" unk1=\"{1}\" unk2=\"{2}\">", bfield.Size, bfield.Unknown1, bfield.Unknown2, bfield.ID));
                                outfile.Write(m_bnsDat.BytesToHex(bfield.Data));//00 00 00 00 00 00 00 00 0c 00 00 00 50 00 00 00
                                outfile.WriteLine("</field>");

                                BDAT_LOOKUPTABLE blookup = bsubarchive.Lookups[f];
                                string[]         words   = LookupSplitToWords(blookup.Data, blookup.Size);
                                outfile.WriteLine(string.Format("\t\t\t\t<lookup count=\"{0}\">", words.Length));
                                int empty = 0;
                                for (int w = 0; w < words.Length; w++)
                                {
                                    if (words[w] != null && words[w].Length > 0)
                                    {
                                        outfile.Write("\t\t\t\t\t<word>");
                                        outfile.Write(words[w]);
                                        outfile.WriteLine("</word>");
                                    }
                                    else
                                    {
                                        empty++;
                                    }
                                }
                                outfile.WriteLine(string.Format("\t\t\t\t\t<empty count=\"{0}\"/>", empty));
                                outfile.WriteLine("\t\t\t\t</lookup>");
                            }
                            outfile.WriteLine("\t\t\t</subarchive>");
                        }
                        outfile.WriteLine("\t\t</archive>");
                    }
                    else
                    {
                        BDAT_LOOSE bloose = bcollection.Loose;
                        outfile.WriteLine(string.Format("\t\t<loose countFields=\"{0}\" sizeFields=\"{1}\" sizePadding=\"{2}\" sizeLookup=\"{3}\" unk=\"{4}\">", bloose.FieldCount, bloose.SizeFields, bloose.SizePadding, bloose.SizeLookup, bloose.Unknown));
                        for (int f = 0; f < bloose.FieldCount; f++)
                        {
                            BDAT_FIELDTABLE bfield = bloose.Fields[f];
                            outfile.Write(string.Format("\t\t\t<field size=\"{0}\" unk1=\"{1}\" unk2=\"{2}\">", bfield.Size, bfield.Unknown1, bfield.Unknown2));
                            outfile.Write(m_bnsDat.BytesToHex(bfield.Data));
                            outfile.WriteLine("</field>");
                        }
                        outfile.Write("\t\t\t<padding>");
                        if (bloose.Padding != null)
                        {
                            outfile.Write(m_bnsDat.BytesToHex(bloose.Padding));
                        }
                        outfile.WriteLine("</padding>");

                        string[] words = LookupSplitToWords(bloose.Lookup.Data, bloose.Lookup.Size);
                        outfile.WriteLine(string.Format("\t\t\t<lookup count=\"{0}\">", words.Length));

                        int empty = 0;
                        for (int w = 0; w < words.Length; w++)
                        {
                            // only add non-empty words
                            if (words[w] != null && words[w].Length > 0)
                            {
                                outfile.Write("\t\t\t\t<word>");
                                outfile.Write(words[w]);//WebUtility.HtmlEncode(
                                outfile.WriteLine("</word>");
                            }
                            else
                            {
                                empty++;
                            }
                        }
                        outfile.WriteLine(string.Format("\t\t\t\t<empty count=\"{0}\"/>", empty));
                        outfile.WriteLine("\t\t\t</lookup>");
                        outfile.WriteLine("\t\t</loose>");
                    }
                    outfile.WriteLine("\t</collection>");
                    outfile.WriteLine("</list>");
                }
            }
        }
Beispiel #8
0
        public void TranslateGeneral(TranslateReader translator)
        {
            if (_indexCommons > -1)
            {
                int index  = 0;
                int index2 = index;

                BDAT_LIST blist = _content.Lists[_indexCommons];

                if (blist.Collection.Compressed > 0)
                {
                    BDAT_ARCHIVE           barchive = blist.Collection.Archive;
                    BDAT_SUBARCHIVE        bsubarchive;
                    List <BDAT_SUBARCHIVE> subNews = new List <BDAT_SUBARCHIVE>();

                    for (int s = 0; s < barchive.SubArchiveCount; s++)
                    {
                        bsubarchive = barchive.SubArchives[s];

                        for (int f = 0; f < bsubarchive.FieldLookupCount; f++)
                        {
                            BDAT_FIELDTABLE  field   = bsubarchive.Fields[f];
                            BDAT_LOOKUPTABLE blookup = bsubarchive.Lookups[f];

                            string[] words      = LookupSplitToWords(blookup.Data, blookup.Size);
                            string   translated = translator.Translate(words[1], words[0]);

                            // alias
                            //Buffer.BlockCopy(BitConverter.GetBytes(words[0].Length), 0, field.Data, 12, 4);

                            //translate
                            if (translated != null)
                            {
                                words[1]     = translated;
                                blookup.Data = LookupWorldsToBytes(words);
                                blookup.Size = blookup.Data.Length;
                                // set new test size
                                //Buffer.BlockCopy(BitConverter.GetBytes(words[1].Length), 0, field.Data, 8, 4);
                            }
                        }

                        if (bsubarchive.NeedSplit(ref index))
                        {
                            BDAT_SUBARCHIVE bClone1 = new BDAT_SUBARCHIVE()
                            {
                                StartAndEndFieldId = new byte[16],
                                Fields             = new BDAT_FIELDTABLE[index],
                                Lookups            = new BDAT_LOOKUPTABLE[index],
                                FieldLookupCount   = index
                            };

                            Array.Copy(bsubarchive.Fields, 0, bClone1.Fields, 0, index);
                            Array.Copy(bsubarchive.Lookups, 0, bClone1.Lookups, 0, index);

                            // set new start field id
                            Buffer.BlockCopy(BitConverter.GetBytes(bClone1.Fields[0].ID), 0, bClone1.StartAndEndFieldId, 0, 4);
                            // set new end field id
                            Buffer.BlockCopy(BitConverter.GetBytes(bClone1.Fields[index - 1].ID), 0, bClone1.StartAndEndFieldId, 8, 4);
                            subNews.Add(bClone1);

                            //part 2
                            index2 = bsubarchive.FieldLookupCount - index;
                            BDAT_SUBARCHIVE bClone2 = new BDAT_SUBARCHIVE()
                            {
                                StartAndEndFieldId = new byte[16],
                                Fields             = new BDAT_FIELDTABLE[index2],
                                Lookups            = new BDAT_LOOKUPTABLE[index2],
                                FieldLookupCount   = index2
                            };
                            Array.Copy(bsubarchive.Fields, index, bClone2.Fields, 0, index2);
                            Array.Copy(bsubarchive.Lookups, index, bClone2.Lookups, 0, index2);

                            // set new start field id
                            Buffer.BlockCopy(BitConverter.GetBytes(bClone2.Fields[0].ID), 0, bClone2.StartAndEndFieldId, 0, 4);
                            // set new end field id
                            Buffer.BlockCopy(BitConverter.GetBytes(bClone2.Fields[index2 - 1].ID), 0, bClone2.StartAndEndFieldId, 8, 4);
                            subNews.Add(bClone2);

                            Console.WriteLine("A:{0}<>B:{1}.OK!", m_bnsDat.BytesToHex(bClone1.StartAndEndFieldId), m_bnsDat.BytesToHex(bClone2.StartAndEndFieldId));
                        }
                        else
                        {
                            subNews.Add(bsubarchive);
                        }
                    }
                    barchive.SubArchiveCount = subNews.Count;
                    barchive.SubArchives     = subNews.ToArray();
                    Console.WriteLine("IF A==B that mean have something wrong! Check source code and fix it.");
                }
                else
                {
                    BDAT_LOOSE bloose = blist.Collection.Loose;

                    BDAT_LOOKUPTABLE blookup = bloose.Lookup;

                    string[] words = LookupSplitToWords(bloose.Lookup.Data, bloose.SizeLookup);

                    for (int w = 0; w < words.Length; w += 2)
                    {
                        string translated = translator.Translate(words[w + 1], words[w]);
                        if (translated != null)
                        {
                            words[w + 1] = translated;
                        }
                        //Console.WriteLine("words[w + 1]: " + words[w + 1]);
                    }

                    blookup.Data = LookupWorldsToBytes(words);
                    blookup.Size = blookup.Data.Length;
                }
            }
        }