Пример #1
0
            public LocaleTable(CacheBase Cache, GameLanguage Lang)
            {
                cache = Cache;
                EndianReader Reader = cache.Reader;
                CacheHeader  CH     = cache.Header;

                #region Get Info
                int matgOffset = -1;
                foreach (IndexItem item in cache.IndexItems)
                {
                    if (item.ClassCode == "matg")
                    {
                        matgOffset = item.Offset;
                        break;
                    }
                }

                if (matgOffset == -1)
                {
                    return;
                }

                int localeStart = int.Parse(cache.buildNode.Attributes["localesStart"].Value);
                Reader.SeekTo(matgOffset + localeStart + (int)Lang * int.Parse(cache.buildNode.Attributes["languageSize"].Value));

                int localeCount = Reader.ReadInt32();
                int tableSize   = Reader.ReadInt32();
                int indexOffset = Reader.ReadInt32() + CH.localeModifier;
                int tableOffset = Reader.ReadInt32() + CH.localeModifier;
                #endregion

                #region Read Indices
                Reader.SeekTo(indexOffset);
                int[] indices = new int[localeCount];
                for (int i = 0; i < localeCount; i++)
                {
                    this.Add("");
                    Reader.ReadInt32();
                    indices[i] = Reader.ReadInt32();
                }
                #endregion

                #region Read Names
                Reader.SeekTo(tableOffset);
                EndianReader newReader = (cache.localesKey == "" || cache.localesKey == null)
                    ? new EndianReader(new MemoryStream(Reader.ReadBytes(tableSize)), EndianFormat.Big)
                    : AES.DecryptSegment(Reader, tableOffset, tableSize, cache.localesKey);

                for (int i = 0; i < indices.Length; i++)
                {
                    if (indices[i] == -1)
                    {
                        this[i] = "<null>";
                        continue;
                    }

                    newReader.SeekTo(indices[i]);

                    int length;
                    if (i == indices.Length - 1)
                    {
                        length = tableSize - indices[i];
                    }
                    else
                    {
                        length = (indices[i + 1] != -1)
                            ? indices[i + 1] - indices[i]
                            : indices[i + 2] - indices[i];
                    }

                    if (length == 1)
                    {
                        this[i] = "<blank>";
                        continue;
                    }

                    this[i] = newReader.ReadString(length);
                }
                newReader.Close();
                newReader.Dispose();
                #endregion
            }
Пример #2
0
            public StringTable(CacheBase Cache)
            {
                if (Cache.Version <= DefinitionSet.Halo1AE)
                {
                    return;
                }

                cache = Cache;
                var Reader = cache.Reader;
                var CH     = cache.Header;

                #region Read Indices
                Reader.SeekTo(CH.stringTableIndexOffset);
                int[] indices = new int[CH.stringCount];
                for (int i = 0; i < CH.stringCount; i++)
                {
                    indices[i] = Reader.ReadInt32();
                    this.Add("");
                }
                #endregion

                #region Read Names
                Reader.SeekTo(CH.stringTableOffset);
                EndianReader newReader = (cache.stringsKey == "" || cache.stringsKey == null)
                    ? new EndianReader(new MemoryStream(Reader.ReadBytes(CH.stringTableSize)), EndianFormat.Big)
                    : AES.DecryptSegment(Reader, CH.stringTableOffset, CH.stringTableSize, cache.stringsKey);

                for (int i = 0; i < indices.Length; i++)
                {
                    if (indices[i] == -1)
                    {
                        this[i] = "<null>";
                        continue;
                    }

                    newReader.SeekTo(indices[i]);

                    int length;
                    if (i == indices.Length - 1)
                    {
                        length = CH.stringTableSize - indices[i];
                    }
                    else
                    {
                        length = (indices[i + 1] != -1)
                            ? indices[i + 1] - indices[i]
                            : indices[i + 2] - indices[i];
                    }

                    if (length == 1)
                    {
                        this[i] = "<blank>";
                        continue;
                    }

                    this[i] = newReader.ReadString(length);
                }
                newReader.Close();
                newReader.Dispose();
                #endregion
            }