Ejemplo n.º 1
0
        private MCNK getChunkHeader(Stormlib.MPQFile file, int chunkX, int chunkY, bool noThrow)
        {
            int cindex = chunkX + chunkY * 16;

            if (cindex < 0 || cindex >= 256)
            {
                if (noThrow)
                {
                    return(new MCNK());
                }

                throw new ArgumentException();
            }

            if (noThrow)
            {
                if (!TrySeekChunk(file, "NICM"))
                {
                    return(new MCNK());
                }
            }
            else
            {
                SeekChunk(file, "NICM");
            }

            file.Position += 8 + cindex * Marshal.SizeOf(typeof(MCIN));
            var mcin = file.Read <MCIN>();

            file.Position = mcin.ofsMcnk + 8;
            return(file.Read <MCNK>());
        }
Ejemplo n.º 2
0
        private void AsyncLoadProc()
        {
            try
            {
                mpqFile = new Stormlib.MPQFile(FileName);
            }
            catch (System.IO.FileNotFoundException)
            {
                mLoadEvent.Set();
                return;
            }

            if (ReadSignature() != "REVM")
            {
                return;
            }

            uint size = mpqFile.Read <uint>();

            if (size != 4)
            {
                return;
            }

            uint version = mpqFile.Read <uint>();

            if (version != 18)
            {
                return;
            }

            LoadAsyncData();
            mLoadEvent.Set();
        }
Ejemplo n.º 3
0
        private void AsyncLoadProc()
        {
            mpqFile = new Stormlib.MPQFile(FileName);
            if (ReadSignature() != "REVM")
            {
                return;
            }

            uint size = mpqFile.Read <uint>();

            if (size != 4)
            {
                return;
            }

            uint version = mpqFile.Read <uint>();

            if (version != 18)
            {
                return;
            }

            LoadAsyncData();
            mLoadEvent.Set();
            loadFinished = true;
        }
Ejemplo n.º 4
0
 public WDTFile(string continent)
 {
     mFile = new Stormlib.MPQFile(@"World\Maps\" + continent + "\\" + continent + ".wdt");
     SeekChunk(mFile, "DHPM");
     mFile.Position = 8;
     Flags          = mFile.Read <uint>();
 }
Ejemplo n.º 5
0
        public bool LoadGroup()
        {
            mFile = new Stormlib.MPQFile(FileName);
            SeekChunk("PGOM", false);
            mFile.Position += 4;
            mHeader         = mFile.Read <MOGP>();

            Vector3[] vertices  = ReadChunkAs <Vector3>("TVOM");
            ushort[]  indices   = ReadChunkAs <ushort>("IVOM");
            Vector2[] texCoords = ReadChunkAs <Vector2>("VTOM");
            Vector3[] normals   = ReadChunkAs <Vector3>("RNOM");

            MOBA[] batches = ReadChunkAs <MOBA>("ABOM");
            Game.GameManager.GraphicsThread.CallOnThread(
                () =>
            {
                foreach (var batch in batches)
                {
                    WMOVertex[] vert = new WMOVertex[batch.numIndices];
                    for (uint t = 0, j = batch.startIndex; t < batch.numIndices; ++t, ++j)
                    {
                        vert[t] = new WMOVertex()
                        {
                            x  = vertices[indices[j]].X,
                            y  = vertices[indices[j]].Y,
                            z  = vertices[indices[j]].Z,
                            nx = normals[indices[j]].X,
                            ny = normals[indices[j]].Y,
                            nz = normals[indices[j]].Z,
                            u  = texCoords[indices[j]].X,
                            v  = texCoords[indices[j]].Y
                        };
                    }

                    Mesh mesh = new Mesh(mParent.TextureManager.AssociatedDevice,
                                         batch.numIndices / 3, batch.numIndices, MeshFlags.Managed, WMOVertex.FVF);

                    var strm = mesh.LockVertexBuffer(LockFlags.None);
                    strm.WriteRange(vert);
                    mesh.UnlockVertexBuffer();

                    strm = mesh.LockIndexBuffer(LockFlags.None);
                    ushort[] meshIndices = new ushort[vert.Length];
                    for (int i = 0; i < vert.Length; ++i)
                    {
                        meshIndices[i] = (ushort)i;
                    }

                    strm.WriteRange(meshIndices);
                    mesh.UnlockIndexBuffer();

                    mMeshes.Add(mesh);
                    mTextureIndices.Add(batch.textureID);
                    mMaterials.Add(mParent.GetMaterial(batch.textureID));
                }
            }
                );

            return(true);
        }
Ejemplo n.º 6
0
 public WDTFile(string continent)
 {
     mFile = new Stormlib.MPQFile(@"World\Maps\" + continent + "\\" + continent + ".wdt");
     SeekChunk(mFile, "DHPM");
     mFile.Position = 8;
     Flags = mFile.Read<uint>();
 }
Ejemplo n.º 7
0
        private void loadMinimaps()
        {
            Stormlib.MPQFile file = new Stormlib.MPQFile(@"textures\Minimap\md5translate.trs");
            var fullContent       = file.Read((uint)file.Length);
            var fullString        = Encoding.UTF8.GetString(fullContent);
            var lines             = fullString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var rawline in lines)
            {
                var line = rawline.Trim();

                if (line.StartsWith("dir: "))
                {
                    beginNewDirectoryEntry(line);
                    continue;
                }

                if (mIsCurrentEntryValid == false)
                {
                    continue;
                }

                addNewMapEntry(line);
            }
        }
Ejemplo n.º 8
0
        public M2Info(string modelName)
        {
            ModelPath = modelName;
            mFile = new Stormlib.MPQFile(modelName);
            Header = mFile.Read<M2Header>();

            BoundingBox = new SlimDX.BoundingBox(Header.VertexMin, Header.VertexMax);

            mFile.Position = Header.ofsName;
            byte[] data = mFile.Read(Header.lenName - 1);
            ModelName = Encoding.UTF8.GetString(data);

            FileDirectory = System.IO.Path.GetDirectoryName(modelName) + "\\";
            var vertices = new M2Vertex[Header.nVertices];
            mFile.Position = Header.ofsVertices;
            mFile.Read(vertices);

            LoadTextures();
            ParseVertices(vertices);
            LoadSkins();
        }
Ejemplo n.º 9
0
        public M2Info(string modelName)
        {
            ModelPath = modelName;
            mFile     = new Stormlib.MPQFile(modelName);
            Header    = mFile.Read <M2Header>();

            BoundingBox = new SlimDX.BoundingBox(Header.VertexMin, Header.VertexMax);

            mFile.Position = Header.ofsName;
            byte[] data = mFile.Read(Header.lenName - 1);
            ModelName = Encoding.UTF8.GetString(data);

            FileDirectory = System.IO.Path.GetDirectoryName(modelName) + "\\";
            var vertices = new M2Vertex[Header.nVertices];

            mFile.Position = Header.ofsVertices;
            mFile.Read(vertices);

            LoadTextures();
            ParseVertices(vertices);
            LoadSkins();
        }
Ejemplo n.º 10
0
        public M2BoneAnimator(Stormlib.MPQFile file, M2Info parent)
        {
            string AnimPath = parent.FileDirectory + parent.ModelName;

            M2Animation[] anims = new M2Animation[parent.Header.nAnimations];
            file.Position = parent.Header.ofsAnimations;
            file.Read(anims);

            Stormlib.MPQFile[] AnimFiles = new Stormlib.MPQFile[parent.Header.nAnimations];
            for (int i = 0; i < parent.Header.nAnimations; ++i)
            {
                string full = AnimPath + anims[i].AnimationID.ToString("D4") + "-" + anims[i].SubAnimationID.ToString("D2") + ".anim";
                if (Stormlib.MPQFile.Exists(full))
                {
                    Console.WriteLine(full);
                    AnimFiles[i] = new Stormlib.MPQFile(full);
                }
            }

            Animations.AddRange(anims);

            this.file = file;
            var bones = new M2Bone[parent.Header.nBones];

            file.Position = parent.Header.ofsBones;
            file.Read(bones);

            foreach (var bone in bones)
            {
                M2AnimationBone ab = new M2AnimationBone(bone, this, file, parent.GlobalSequences, AnimFiles);
                Bones.Add(ab);
                ab.BoneIndex = Bones.Count - 1;
            }
            foreach (var bone in Bones)
            {
                bone.Init();
            }
        }
Ejemplo n.º 11
0
        private void LoadSkins()
        {
            string skinFile = FileDirectory + ModelName + "00.skin";
            Stormlib.MPQFile skin = new Stormlib.MPQFile(skinFile);
            skin.Dispose();
            SKINView mView = skin.Read<SKINView>();
            ushort[] indexLookup = new ushort[mView.nIndices];
            skin.Position = mView.ofsIndices;
            skin.Read(indexLookup);
            ushort[] triangles = new ushort[mView.nTriangles];
            skin.Position = mView.ofsTriangles;
            skin.Read(triangles);

            SKINSubMesh[] SubMeshes = new SKINSubMesh[mView.nSubMeshes];
            skin.Position = mView.ofsSubMeshes;
            skin.Read(SubMeshes);

            SKINTexUnit[] TexUnits = new SKINTexUnit[mView.nTexUnits];
            skin.Position = mView.ofsTexUnits;
            skin.Read(TexUnits);

            ushort[] texLookUp = new ushort[Header.nTexLookups];
            mFile.Position = Header.ofsTexLookups;
            mFile.Read(texLookUp);

            ushort[] texUnitLookUp = new ushort[Header.nTexUnits];
            mFile.Position = Header.ofsTexUnits;
            mFile.Read(texUnitLookUp);

            M2RenderFlags[] renderFlags = new M2RenderFlags[Header.nRenderFlags];
            mFile.Position = Header.ofsRenderFlags;
            mFile.Read(renderFlags);

            ushort[] indices = new ushort[mView.nTriangles];
            for (int i = 0; i < mView.nTriangles; ++i)
                indices[i] = indexLookup[triangles[i]];

            var bones = new M2Bone[Header.nBones];
            mFile.Position = Header.ofsBones;
            mFile.Read(bones);

            M2BoneAnimator mba = new M2BoneAnimator(mFile, this);
            BoneLookupTable = new ushort[Header.nBoneLookupTables];
            mFile.Position = Header.ofsBoneLookupTables;
            mFile.Read(BoneLookupTable);

            GlobalSequences = new uint[Header.nGlobalSequences];
            mFile.Position = Header.ofsGlobalSequences;
            mFile.Read(GlobalSequences);

            for (int i = 0; i < mView.nTexUnits; ++i)
            {
                M2RenderPass pass = new M2RenderPass();
                SKINSubMesh mesh = SubMeshes[TexUnits[i].SubMesh1];
                pass.Vertices = new MdxVertex[mesh.nTriangles];
                pass.Texture = Textures[(int)texLookUp[TexUnits[i].Texture]];
                pass.BlendMode = renderFlags[TexUnits[i].RenderFlags];
                pass.BoneMatrices = new SlimDX.Matrix[mesh.nBones];
                pass.BoneBaseIndex = mesh.startBone;
                pass.ParentModel = this;
                pass.Index = TexUnits[i].TexUnitNumber;

                for (uint q = 0; q < mesh.nBones; ++q)
                {
                    pass.BoneMatrices[q] = mba.GetBone((short)(BoneLookupTable[mesh.startBone + q])).Matrix;
                }

                for (ushort t = mesh.startTriangle, k = 0; k < mesh.nTriangles; ++t, ++k)
                {
                    ushort index = indices[t];
                    pass.Vertices[k] = Vertices[index];
                    pass.Vertices[k].bi1 = (byte)(Vertices[i].bi1);
                    pass.Vertices[k].bi2 = (byte)(Vertices[i].bi2);
                    pass.Vertices[k].bi3 = (byte)(Vertices[i].bi3);
                    pass.Vertices[k].bi4 = (byte)(Vertices[i].bi4);
                }

                pass.SetVertexIndices();
                Passes.Add(pass);
            }

            Passes.Sort((g1, g2) =>
            {
                if (g1.BlendMode.blend == 2 && g2.BlendMode.blend != 2)
                    return 1;
                if (g2.BlendMode.blend == 2 && g1.BlendMode.blend != 2)
                    return -1;

                if (g1.BlendMode.blend < g2.BlendMode.blend)
                    return -1;
                if (g2.BlendMode.blend < g1.BlendMode.blend)
                    return 1;

                if (g1.Index == g2.Index)
                    return 0;
                if (g1.Index < g2.Index)
                    return -1;
                if (g1.Index > g2.Index)
                    return 1;
                return 0;
            }
            );

            BoneAnimator = mba;
        }
Ejemplo n.º 12
0
        public Bitmap CreateImage()
        {
            if (CreatedImages.ContainsKey(mMapId))
            {
                return(CreatedImages[mMapId]);
            }

            Stormlib.MPQFile file      = new Stormlib.MPQFile(@"World\Maps\" + mContinent + "\\" + mContinent + ".wdl");
            uint[]           offsets   = new uint[64 * 64];
            string           signature = "";

            while ((signature = ReadSignature(file)) != "MAOF")
            {
                SkipChunk(file);
            }

            file.Position += 4;
            file.Read(offsets);
            uint[]  texData = new uint[64 * 17 * 64 * 17];
            short[] tile    = new short[17 * 17];
            for (uint i = 0; i < 64; ++i)
            {
                for (uint j = 0; j < 64; ++j)
                {
                    if (offsets[i * 64 + j] != 0)
                    {
                        file.Position = offsets[i * 64 + j] + 0x08;
                        file.Read(tile);
                        for (uint k = 0; k < 17; ++k)
                        {
                            for (uint l = 0; l < 17; ++l)
                            {
                                short height = tile[k * 17 + l];
                                uint  r = 0, g = 0, b = 0;
                                if (height > 1000)
                                {
                                    r = g = b = 255;
                                }
                                else if (height > 600)
                                {
                                    float am = (height - 600.0f) / 400.0f;
                                    r = (uint)(0.75f + am * 0.25f * 255);
                                    g = (uint)(0.5f * am * 255);
                                    b = (uint)(am * 255);
                                }
                                else if (height > 300)
                                {
                                    float am = (height - 300.0f) / 300.0f;
                                    r = (uint)(255 - am * 255);
                                    g = (uint)(1.0f);
                                    b = (uint)(0.0f);
                                }
                                else if (height > 0)
                                {
                                    float am = height / 300.0f;
                                    r = (uint)(0.75f * am * 255);
                                    g = (uint)(255 - (0.5f * am * 255));
                                    b = (uint)(0);
                                }
                                else if (height > -100)
                                {
                                    float am = (height + 100.0f) / 100.0f;
                                    r = (uint)(0.0f);
                                    g = (uint)(am * 255);
                                    b = (uint)(255);
                                }
                                else if (height > -550)
                                {
                                    float am = (height + 550) / (450.0f);
                                    r = (uint)(0.0f);
                                    g = (uint)(0.0f);
                                    b = (uint)(0x7F);
                                }
                                else if (height > -1000)
                                {
                                    r = (uint)(0);
                                    g = (uint)(0);
                                    b = (uint)(0x7F);
                                }
                                if (k == 0 || l == 0)
                                {
                                    r = g = b = 0x3F;
                                }

                                texData[(i * 17 + k) * (64 * 17) + j * 17 + l] = (uint)((b) | (g << 8) | (r << 16) | (255 << 24));
                            }
                        }
                    }
                }
            }

            Bitmap bmp  = new Bitmap(64 * 17, 64 * 17);
            var    data = bmp.LockBits(new Rectangle(0, 0, 64 * 17, 64 * 17), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            Utils.Memory.CopyMemory(texData, data.Scan0);
            bmp.UnlockBits(data);
            CreatedImages.Add(mMapId, bmp);
            return(bmp);
        }
Ejemplo n.º 13
0
        private void SkipChunk(Stormlib.MPQFile file)
        {
            uint size = file.Read <uint>();

            file.Position += size;
        }
Ejemplo n.º 14
0
 private string ReadSignature()
 {
     byte[] bytes = mFile.Read(4);
     bytes = bytes.Reverse().ToArray();
     return(Encoding.UTF8.GetString(bytes));
 }
Ejemplo n.º 15
0
        private void AsyncLoadProc()
        {
            mpqFile = new Stormlib.MPQFile(FileName);
            if (ReadSignature() != "REVM")
                return;

            uint size = mpqFile.Read<uint>();
            if (size != 4)
                return;

            uint version = mpqFile.Read<uint>();
            if (version != 18)
                return;

            LoadAsyncData();
            mLoadEvent.Set();
            loadFinished = true;
        }
Ejemplo n.º 16
0
        private void AsyncLoadProc()
        {
            mFile = new Stormlib.MPQFile(FileName);
            SeekChunk("DHOM");
            mFile.Position += 4;
            mHeader = mFile.Read<MOHD>();

            BoundingBox = new SlimDX.BoundingBox(new SlimDX.Vector3(mHeader.MinPosition.X, mHeader.MinPosition.Y, mHeader.MinPosition.Z),
                new SlimDX.Vector3(mHeader.MaxPosition.X, mHeader.MaxPosition.Y, mHeader.MaxPosition.Z));

            SeekChunk("XTOM");
            uint numBytes = mFile.Read<uint>();
            byte[] texData = mFile.Read(numBytes);
            var fullStr = Encoding.UTF8.GetString(texData);
            var textures = fullStr.Split('\0');

            uint curPos = 0;
            foreach (var tex in textures)
            {
                if (tex != "")
                    mTextureNames.Add(curPos, tex);

                curPos += (uint)tex.Length + 1;
            }

            SeekChunk("TMOM");
            mFile.Position += 4;

            for (uint i = 0; i < mHeader.nMaterials; ++i)
            {
                MOMT mat = mFile.Read<MOMT>();
                mMaterials.Add(mat);
            }

            Game.GameManager.GraphicsThread.CallOnThread(
                () =>
                {
                    foreach (var mat in mMaterials)
                    {
                        if (mCustomTextureMgr == null)
                            mTextures.Add(Video.TextureManager.GetTexture(mTextureNames[mat.ofsTexture1]));
                        else
                            mTextures.Add(mCustomTextureMgr.LoadTexture(mTextureNames[mat.ofsTexture1]));

                    }
                }
            );

            SeekChunk("IGOM");
            mFile.Position += 4;

            for (uint i = 0; i < mHeader.nGroups; ++i)
            {
                MOGI mogi = mFile.Read<MOGI>();
                mGroupInfos.Add(mogi);

                WMOGroup group = new WMOGroup(FileName, i, this);
                if (group.LoadGroup())
                {
                    lock (mGroups) mGroups.Add(group);
                }
            }

            isLoadFinished = true;
        }
Ejemplo n.º 17
0
        private void LoadSkins()
        {
            string skinFile = FileDirectory + ModelName + "00.skin";

            Stormlib.MPQFile skin = new Stormlib.MPQFile(skinFile);
            skin.Dispose();
            SKINView mView = skin.Read <SKINView>();

            ushort[] indexLookup = new ushort[mView.nIndices];
            skin.Position = mView.ofsIndices;
            skin.Read(indexLookup);
            ushort[] triangles = new ushort[mView.nTriangles];
            skin.Position = mView.ofsTriangles;
            skin.Read(triangles);

            SKINSubMesh[] SubMeshes = new SKINSubMesh[mView.nSubMeshes];
            skin.Position = mView.ofsSubMeshes;
            skin.Read(SubMeshes);

            SKINTexUnit[] TexUnits = new SKINTexUnit[mView.nTexUnits];
            skin.Position = mView.ofsTexUnits;
            skin.Read(TexUnits);

            ushort[] texLookUp = new ushort[Header.nTexLookups];
            mFile.Position = Header.ofsTexLookups;
            mFile.Read(texLookUp);

            ushort[] texUnitLookUp = new ushort[Header.nTexUnits];
            mFile.Position = Header.ofsTexUnits;
            mFile.Read(texUnitLookUp);

            M2RenderFlags[] renderFlags = new M2RenderFlags[Header.nRenderFlags];
            mFile.Position = Header.ofsRenderFlags;
            mFile.Read(renderFlags);

            ushort[] indices = new ushort[mView.nTriangles];
            for (int i = 0; i < mView.nTriangles; ++i)
            {
                indices[i] = indexLookup[triangles[i]];
            }

            var bones = new M2Bone[Header.nBones];

            mFile.Position = Header.ofsBones;
            mFile.Read(bones);

            M2BoneAnimator mba = new M2BoneAnimator(mFile, this);

            BoneLookupTable = new ushort[Header.nBoneLookupTables];
            mFile.Position  = Header.ofsBoneLookupTables;
            mFile.Read(BoneLookupTable);

            GlobalSequences = new uint[Header.nGlobalSequences];
            mFile.Position  = Header.ofsGlobalSequences;
            mFile.Read(GlobalSequences);

            for (int i = 0; i < mView.nTexUnits; ++i)
            {
                M2RenderPass pass = new M2RenderPass();
                SKINSubMesh  mesh = SubMeshes[TexUnits[i].SubMesh1];
                pass.Vertices      = new MdxVertex[mesh.nTriangles];
                pass.Texture       = Textures[(int)texLookUp[TexUnits[i].Texture]];
                pass.BlendMode     = renderFlags[TexUnits[i].RenderFlags];
                pass.BoneMatrices  = new SlimDX.Matrix[mesh.nBones];
                pass.BoneBaseIndex = mesh.startBone;
                pass.ParentModel   = this;
                pass.Index         = TexUnits[i].TexUnitNumber;

                for (uint q = 0; q < mesh.nBones; ++q)
                {
                    pass.BoneMatrices[q] = mba.GetBone((short)(BoneLookupTable[mesh.startBone + q])).Matrix;
                }

                for (ushort t = mesh.startTriangle, k = 0; k < mesh.nTriangles; ++t, ++k)
                {
                    ushort index = indices[t];
                    pass.Vertices[k]     = Vertices[index];
                    pass.Vertices[k].bi1 = (byte)(Vertices[i].bi1);
                    pass.Vertices[k].bi2 = (byte)(Vertices[i].bi2);
                    pass.Vertices[k].bi3 = (byte)(Vertices[i].bi3);
                    pass.Vertices[k].bi4 = (byte)(Vertices[i].bi4);
                }

                pass.SetVertexIndices();
                Passes.Add(pass);
            }

            Passes.Sort((g1, g2) =>
            {
                if (g1.BlendMode.blend == 2 && g2.BlendMode.blend != 2)
                {
                    return(1);
                }
                if (g2.BlendMode.blend == 2 && g1.BlendMode.blend != 2)
                {
                    return(-1);
                }

                if (g1.BlendMode.blend < g2.BlendMode.blend)
                {
                    return(-1);
                }
                if (g2.BlendMode.blend < g1.BlendMode.blend)
                {
                    return(1);
                }

                if (g1.Index == g2.Index)
                {
                    return(0);
                }
                if (g1.Index < g2.Index)
                {
                    return(-1);
                }
                if (g1.Index > g2.Index)
                {
                    return(1);
                }
                return(0);
            }
                        );

            BoneAnimator = mba;
        }
Ejemplo n.º 18
0
        public M2BoneAnimator(Stormlib.MPQFile file, M2Info parent)
        {
            string AnimPath = parent.FileDirectory + parent.ModelName;

            M2Animation[] anims = new M2Animation[parent.Header.nAnimations];
            file.Position = parent.Header.ofsAnimations;
            file.Read(anims);

            Stormlib.MPQFile[] AnimFiles = new Stormlib.MPQFile[parent.Header.nAnimations];
            for (int i = 0; i < parent.Header.nAnimations; ++i)
            {
                string full = AnimPath + anims[i].AnimationID.ToString("D4") + "-" + anims[i].SubAnimationID.ToString("D2") + ".anim";
                if (Stormlib.MPQFile.Exists(full))
                {
                    Console.WriteLine(full);
                    AnimFiles[i] = new Stormlib.MPQFile(full);
                }
            }

            Animations.AddRange(anims);

            this.file = file;
            var bones = new M2Bone[parent.Header.nBones];
            file.Position = parent.Header.ofsBones;
            file.Read(bones);

            foreach (var bone in bones)
            {
                M2AnimationBone ab = new M2AnimationBone(bone, this, file, parent.GlobalSequences, AnimFiles);
                Bones.Add(ab);
                ab.BoneIndex = Bones.Count - 1;
            }
            foreach (var bone in Bones)
            {
                bone.Init();
            }
        }
Ejemplo n.º 19
0
        public Bitmap CreateImage()
        {
            if (CreatedImages.ContainsKey(mMapId))
                return CreatedImages[mMapId];

            Stormlib.MPQFile file = new Stormlib.MPQFile(@"World\Maps\" + mContinent + "\\" + mContinent + ".wdl");
            uint[] offsets = new uint[64 * 64];
            string signature = "";
            while ((signature = ReadSignature(file)) != "MAOF")
                SkipChunk(file);

            file.Position += 4;
            file.Read(offsets);
            uint[] texData = new uint[64 * 17 * 64 * 17];
            short[] tile = new short[17 * 17];
            for (uint i = 0; i < 64; ++i)
            {
                for (uint j = 0; j < 64; ++j)
                {
                    if (offsets[i * 64 + j] != 0)
                    {
                        file.Position = offsets[i * 64 + j] + 0x08;
                        file.Read(tile);
                        for (uint k = 0; k < 17; ++k)
                        {
                            for (uint l = 0; l < 17; ++l)
                            {
                                short height = tile[k * 17 + l];
                                uint r = 0, g = 0, b = 0;
                                if (height > 1000)
                                {
                                    r = g = b = 255;
                                }
                                else if (height > 600)
                                {
                                    float am = (height - 600.0f) / 400.0f;
                                    r = (uint)(0.75f + am * 0.25f * 255);
                                    g = (uint)(0.5f * am * 255);
                                    b = (uint)(am * 255);
                                }
                                else if (height > 300)
                                {
                                    float am = (height - 300.0f) / 300.0f;
                                    r = (uint)(255 - am * 255);
                                    g = (uint)(1.0f);
                                    b = (uint)(0.0f);
                                }
                                else if (height > 0)
                                {
                                    float am = height / 300.0f;
                                    r = (uint)(0.75f * am * 255);
                                    g = (uint)(255 - (0.5f * am * 255));
                                    b = (uint)(0);
                                }
                                else if (height > -100)
                                {
                                    float am = (height + 100.0f) / 100.0f;
                                    r = (uint)(0.0f);
                                    g = (uint)(am * 255);
                                    b = (uint)(255);
                                }
                                else if (height > -550)
                                {
                                    float am = (height + 550) / (450.0f);
                                    r = (uint)(0.0f);
                                    g = (uint)(0.0f);
                                    b = (uint)(0x7F);
                                }
                                else if (height > -1000)
                                {
                                    r = (uint)(0);
                                    g = (uint)(0);
                                    b = (uint)(0x7F);
                                }
                                if (k == 0 || l == 0)
                                    r = g = b = 0x3F;

                                texData[(i * 17 + k) * (64 * 17) + j * 17 + l] = (uint)((b) | (g << 8) | (r << 16) | (255 << 24));
                            }
                        }
                    }
                }
            }

            Bitmap bmp = new Bitmap(64 * 17, 64 * 17);
            var data = bmp.LockBits(new Rectangle(0, 0, 64 * 17, 64 * 17), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            Utils.Memory.CopyMemory(texData, data.Scan0);
            bmp.UnlockBits(data);
            CreatedImages.Add(mMapId, bmp);
            return bmp;
        }
Ejemplo n.º 20
0
        private void loadMinimaps()
        {
            Stormlib.MPQFile file = new Stormlib.MPQFile(@"textures\Minimap\md5translate.trs");
            var fullContent = file.Read((uint)file.Length);
            var fullString = Encoding.UTF8.GetString(fullContent);
            var lines = fullString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var rawline in lines)
            {
                var line = rawline.Trim();

                if (line.StartsWith("dir: "))
                {
                    beginNewDirectoryEntry(line);
                    continue;
                }

                if (mIsCurrentEntryValid == false)
                    continue;

                addNewMapEntry(line);
            }
        }
Ejemplo n.º 21
0
 private string ReadSignature()
 {
     byte[] bytes = mpqFile.Read(4);
     return(Encoding.UTF8.GetString(bytes));
 }
Ejemplo n.º 22
0
 private string ReadSignature(Stormlib.MPQFile file)
 {
     byte[] bytes = file.Read(4);
     bytes = bytes.Reverse().ToArray();
     return(Encoding.UTF8.GetString(bytes));
 }
Ejemplo n.º 23
0
        private void AsyncLoadProc()
        {
            mFile = new Stormlib.MPQFile(FileName);
            SeekChunk("DHOM");
            mFile.Position += 4;
            mHeader         = mFile.Read <MOHD>();

            BoundingBox = new SlimDX.BoundingBox(new SlimDX.Vector3(mHeader.MinPosition.X, mHeader.MinPosition.Y, mHeader.MinPosition.Z),
                                                 new SlimDX.Vector3(mHeader.MaxPosition.X, mHeader.MaxPosition.Y, mHeader.MaxPosition.Z));

            SeekChunk("XTOM");
            uint numBytes = mFile.Read <uint>();

            byte[] texData  = mFile.Read(numBytes);
            var    fullStr  = Encoding.UTF8.GetString(texData);
            var    textures = fullStr.Split('\0');

            uint curPos = 0;

            foreach (var tex in textures)
            {
                if (tex != "")
                {
                    mTextureNames.Add(curPos, tex);
                }

                curPos += (uint)tex.Length + 1;
            }

            SeekChunk("TMOM");
            mFile.Position += 4;

            for (uint i = 0; i < mHeader.nMaterials; ++i)
            {
                MOMT mat = mFile.Read <MOMT>();
                mMaterials.Add(mat);
            }

            Game.GameManager.GraphicsThread.CallOnThread(
                () =>
            {
                foreach (var mat in mMaterials)
                {
                    if (mCustomTextureMgr == null)
                    {
                        mTextures.Add(Video.TextureManager.GetTexture(mTextureNames[mat.ofsTexture1]));
                    }
                    else
                    {
                        mTextures.Add(mCustomTextureMgr.LoadTexture(mTextureNames[mat.ofsTexture1]));
                    }
                }
            }
                );

            SeekChunk("IGOM");
            mFile.Position += 4;

            for (uint i = 0; i < mHeader.nGroups; ++i)
            {
                MOGI mogi = mFile.Read <MOGI>();
                mGroupInfos.Add(mogi);

                WMOGroup group = new WMOGroup(FileName, i, this);
                if (group.LoadGroup())
                {
                    lock (mGroups) mGroups.Add(group);
                }
            }

            isLoadFinished = true;
        }
Ejemplo n.º 24
0
        private void AsyncLoadProc()
        {
            try
            {
                mpqFile = new Stormlib.MPQFile(FileName);
            }
            catch (System.IO.FileNotFoundException)
            {
                mLoadEvent.Set();
                return;
            }

            if (ReadSignature() != "REVM")
                return;

            uint size = mpqFile.Read<uint>();
            if (size != 4)
                return;

            uint version = mpqFile.Read<uint>();
            if (version != 18)
                return;

            LoadAsyncData();
            mLoadEvent.Set();
        }