public IndexTable(CacheFile cache) { var indexHeader = cache.IndexHeader; var cacheHeader = cache.Header; var reader = cache.Reader; ClassList = new List <TagClass>(); #region Read Class List reader.SeekTo(indexHeader.TagGroupsOffset); for (int i = 0; i < indexHeader.TagGroupCount; i++) { var tc = new TagClass() { ClassCode = reader.ReadString(4), Parent = reader.ReadString(4), Parent2 = reader.ReadString(4), StringID = reader.ReadInt32() }; ClassList.Add(tc); } #endregion #region Read Tags Info reader.SeekTo(indexHeader.TagsOffset); for (int i = 0; i < indexHeader.TagCount; i++) { IndexItem item = new IndexItem() { Cache = cache }; item.ClassIndex = reader.ReadInt16(); item.ID = (reader.ReadInt16() << 16) | i; item.Offset = reader.ReadInt32() - cache.Magic; item.Index = i; Add(item); } #endregion #region Read Indices reader.SeekTo(cacheHeader.TagNamesIndicesOffset); int[] indices = new int[indexHeader.TagCount]; for (int i = 0; i < indexHeader.TagCount; i++) { indices[i] = reader.ReadInt32(); } #endregion #region Read Names reader.SeekTo(cacheHeader.TagNamesBufferOffset); EndianReader newReader = null; if (cache.TagsKey == "" || cache.TagsKey == null) { newReader = new EndianReader(new MemoryStream(reader.ReadBytes(cacheHeader.TagNamesBufferSize)), EndianFormat.BigEndian); } else { reader.BaseStream.Position = cacheHeader.TagNamesBufferOffset; newReader = new EndianReader(reader.DecryptAesSegment(cacheHeader.TagNamesBufferSize, cache.TagsKey), EndianFormat.BigEndian); } for (int i = 0; i < indices.Length; i++) { if (indices[i] == -1) { this[i].Name = "<null>"; continue; } newReader.SeekTo(indices[i]); int length; if (i == indices.Length - 1) { length = cacheHeader.TagNamesBufferSize - indices[i]; } else { if (indices[i + 1] == -1) { int index = -1; for (int j = i + 1; j < indices.Length; j++) { if (indices[j] != -1) { index = j; break; } } length = (index == -1) ? cacheHeader.TagNamesBufferSize - indices[i] : indices[index] - indices[i]; } else { length = indices[i + 1] - indices[i]; } } if (length == 1) { this[i].Name = "<blank>"; continue; } if (length < 0) { int i0 = indices[i]; int i1 = indices[i + 1]; int i2 = indices[i + 2]; int i3 = indices[i + 3]; } this[i].Name = newReader.ReadString(length); } newReader.Close(); newReader.Dispose(); #endregion }
private CacheIndexTable CreateCacheIndexTable(EndianReader reader) { CacheIndexTable indexTable = new CacheIndexTable(); indexTable.ClassList = new List <TagClass>(); #region Read Class List reader.SeekTo(IndexHeader.TagGroupsOffset); for (int i = 0; i < IndexHeader.TagGroupCount; i++) { var tc = new TagClass() { ClassCode = reader.ReadString(4), Parent = reader.ReadString(4), Parent2 = reader.ReadString(4), StringID = reader.ReadInt32() }; indexTable.ClassList.Add(tc); } #endregion #region Read Tags Info reader.SeekTo(IndexHeader.TagsOffset); for (int i = 0; i < IndexHeader.TagCount; i++) { var classIndex = reader.ReadInt16(); var tagClass = classIndex == -1 ? null : indexTable.ClassList[classIndex]; string groupName = classIndex == -1 ? "" : Strings.GetItemByID(tagClass.StringID); CacheIndexItem item = new CacheIndexItem(classIndex, (reader.ReadInt16() << 16) | i, reader.ReadInt32() - Magic, i, tagClass, groupName); indexTable.Add(item); } #endregion #region Read Indices reader.SeekTo(BaseMapFile.Header.GetTagNamesIndicesOffset()); int[] indices = new int[IndexHeader.TagCount]; for (int i = 0; i < IndexHeader.TagCount; i++) { indices[i] = reader.ReadInt32(); } #endregion #region Read Names reader.SeekTo(BaseMapFile.Header.GetTagNamesBufferOffset()); EndianReader newReader = null; if (TagsKey == "" || TagsKey == null) { newReader = new EndianReader(new MemoryStream(reader.ReadBytes(BaseMapFile.Header.GetTagNamesBufferSize())), EndianFormat.BigEndian); } else { reader.BaseStream.Position = BaseMapFile.Header.GetTagNamesBufferOffset(); newReader = new EndianReader(reader.DecryptAesSegment(BaseMapFile.Header.GetTagNamesBufferSize(), TagsKey), EndianFormat.BigEndian); } for (int i = 0; i < indices.Length; i++) { if (indices[i] == -1) { indexTable[i].Name = "<null>"; continue; } newReader.SeekTo(indices[i]); int length; if (i == indices.Length - 1) { length = BaseMapFile.Header.GetTagNamesBufferSize() - indices[i]; } else { if (indices[i + 1] == -1) { int index = -1; for (int j = i + 1; j < indices.Length; j++) { if (indices[j] != -1) { index = j; break; } } length = (index == -1) ? BaseMapFile.Header.GetTagNamesBufferSize() - indices[i] : indices[index] - indices[i]; } else { length = indices[i + 1] - indices[i]; } } if (length == 1) { indexTable[i].Name = "<blank>"; continue; } if (length < 0) { int i0 = indices[i]; int i1 = indices[i + 1]; int i2 = indices[i + 2]; int i3 = indices[i + 3]; } indexTable[i].Name = newReader.ReadString(length); } newReader.Close(); newReader.Dispose(); #endregion return(indexTable); }