Exemple #1
0
        /// <summary>
        /// Loads all the offsets of the MCNK-chunks in the main file and in the tex stream and stores them in mChunkOffsets
        /// </summary>
        private void InitChunkOffsets()
        {
            SeekChunk(mpqFile, "KNCM");
            for (int i = 0; i < 256; ++i)
            {
                var ofs = new ChunkOffset()
                {
                    Offset = (uint)mpqFile.Position,
                };

                mpqFile.Position += 4;
                ofs.Size          = mpqFile.Read <uint>();

                mChunkOffsets.Add(ofs);
                mpqFile.Position += ofs.Size;
            }

            SeekChunk(TexStream, "KNCM");
            for (int i = 0; i < 256; ++i)
            {
                var offset = (uint)TexStream.Position;
                TexStream.Position += 4;
                uint size = TexStream.Read <uint>();

                mChunkOffsets[i].OffsetTexStream = offset;
                TexStream.Position = offset + 8 + size;
            }
        }
Exemple #2
0
        /// <summary>
        /// Reads the MTEX chunk and splits the block of texture names into the separate textures.
        /// Loads all the textures in the main thread using Invoke
        /// </summary>
        private void LoadTextureNames()
        {
            SeekChunk(TexStream, "XETM");
            TexStream.Position += 4;
            uint numBytes = TexStream.Read <uint>();

            byte[] textureData = new byte[numBytes];
            TexStream.Read(textureData, 0, (int)numBytes);
            string texString = Encoding.UTF8.GetString(textureData);

            string[] texNames = texString.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
            mTextureNames = texNames.ToList();

            Game.GameManager.GraphicsThread.CallOnThread(() =>
            {
                foreach (var tex in mTextureNames)
                {
                    mTextures.Add(Video.TextureManager.GetTexture(tex));
                }
            }
                                                         );
        }