Beispiel #1
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            string typeValue = reader.ReadString();
            TableType = GetTableType(typeValue);

            int rowCount = reader.ReadInt32();

            for (int i = 0; i < rowCount; i++) {
                StringTableKey key = new StringTableKey();
                key.Key = reader.ReadString();
                key.ID = reader.ReadInt32();

                keys.Add(key);
            }

            int languageCount = reader.ReadInt32();

            for (int j = 0; j < rowCount; j++) {
                StringTableRow row = new StringTableRow(languageCount);
                rows.Add(row);
            }

            for (int i = 0; i < languageCount; i++) {
                StringTableLanguage language = (StringTableLanguage)i;

                int languageOffset = reader.ReadInt32();
                long nextLanguageOffset = stream.Position;

                stream.Seek(languageOffset, SeekOrigin.Begin);

                for (int j = 0; j < rowCount; j++) {
                    int rowOffset = reader.ReadInt32();
                    long nextRowOffset = stream.Position;

                    stream.Seek(rowOffset, SeekOrigin.Begin);

                    StringTableRow row = rows[j];
                    row.SetText(reader.ReadString(), language);

                    if (TableType == StringTableType.Item || TableType == StringTableType.Quest) {
                        row.SetDescription(reader.ReadString(), language);

                        if (TableType == StringTableType.Quest) {
                            row.SetStartMessage(reader.ReadString(), language);
                            row.SetEndMessage(reader.ReadString(), language);
                        }
                    }

                    if (j < rowCount - 1) {
                        stream.Seek(nextRowOffset, SeekOrigin.Begin);
                    }
                }

                if (i < languageCount - 1) {
                    stream.Seek(nextLanguageOffset, SeekOrigin.Begin);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Removes the specified row.
        /// </summary>
        /// <param name="row">The row to remove.</param>
        /// <exception cref="System.ArgumentException">Thrown when the file does not contain the specified row.</exception>
        public void RemoveRow(StringTableRow row)
        {
            if (!rows.Contains(row)) {
                throw new ArgumentException("row", "File does not contain the specified row");
            }

            int rowIndex = rows.IndexOf(row);
            RemoveRow(rowIndex);
        }
Beispiel #3
0
        /// <summary>
        /// Adds a new row using the specified key and id.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="id">The id.</param>
        /// <returns>The row created.</returns>
        public StringTableRow AddRow(string key, int id)
        {
            StringTableKey tableKey = new StringTableKey();
            tableKey.Key = key;
            tableKey.ID = id;

            StringTableRow tableRow = new StringTableRow(LanguageCount);

            keys.Add(tableKey);
            rows.Add(tableRow);

            return tableRow;
        }