public void Add(int count, byte[] name)
 {
     Section header = new Section
     {
         XStringCount = count,
         Name = name,
     };
     this.listSection.Add(header);
 }
 public void Add(Section section)
 {
     Add(section.XStringCount, section.Name);
 }
Exemplo n.º 3
0
        public override void load(string filename)
        {
            if (!File.Exists(filename))
                throw new FileNotFoundException("File '" + filename + "' does not exist.");

            isEncrypted = false;
            Filename = filename;

            using (BinaryReader br = new BinaryReader(File.Open(filename, FileMode.Open)))
            {
                header = br.ReadInt32();
                if (!ValidHeaders.Contains(header))
                    throw new Exception(string.Format("File '{0}' is not valid. [{1}]", filename, header.ToString("X4")));

                version = br.ReadInt32();

                this.setupLanguages();

                int stringLength;
                byte[] stringText;
                totalSectionCount = br.ReadInt32();

                Debug.WriteLine(string.Format("Version: {0} (Languages={1} Sections={2})",
                    version.ToString("X4"),
                    MaxLanguages,
                    totalSectionCount));

                for (int i = 0, numSections = totalSectionCount; i < numSections; i++)
                {
                    Section section = new Section();
                    section.XStringCount = br.ReadInt32();
                    section.Name = br.ReadBytes(sizeof(char) * Section.NAME_MAXLEN);

                    // String is XOR'd
                    if (section.Name.Length > 1 && section.Name[1] == Keys[1])
                    {
                        isEncrypted = true;
                        section.Name = TextEncrypt.BikeyXor(section.Name, Keys);
                    }

                    sectionCollection.Add(section);

                    for (int j = 0; j < section.XStringCount; j++)
                    {
                        XString textStringItem = new XString();
                        textStringItem.ResourceIndex = br.ReadInt32();

                        if (version == (int)Version.Separated)
                        {
                            textStringItem.ParameterOrder.Add(br.ReadInt32());

                            stringLength = br.ReadInt32();
                            stringText = br.ReadBytes(sizeof(char) * stringLength);

                            if (isEncrypted)
                                stringText = TextEncrypt.BikeyXor(stringText, Keys);

                            textStringItem.TextString.Add(stringText);
                            textStringItem.TextStringLength.Add(stringLength);

                            sectionCollection.Sections[i].XStrings.Add(
                                textStringItem.ResourceIndex,
                                textStringItem.ParameterOrder[0],
                                textStringItem.TextStringLength[0],
                                textStringItem.TextString[0]);

                            continue;
                        }

                        for (int lancnt = 0; lancnt < MaxLanguages; lancnt++)
                        {
                            textStringItem.ParameterOrder.Add(br.ReadInt32());
                        }

                        for (int lancnt = 0; lancnt < MaxLanguages; lancnt++)
                        {
                            stringLength = br.ReadInt32();
                            stringText = br.ReadBytes(sizeof(char) * stringLength);

                            if (isEncrypted)
                                stringText = TextEncrypt.BikeyXor(stringText, Keys);

                            textStringItem.TextString.Add(stringText);
                            textStringItem.TextStringLength.Add(stringLength);
                        }

                        sectionCollection.Sections[i].XStrings.Add(
                                textStringItem.ResourceIndex,
                                textStringItem.ParameterOrder,
                                textStringItem.TextStringLength,
                                textStringItem.TextString);
                    }
                }
            }

            OnLoaded(EventArgs.Empty);
        }