Example #1
0
        public void LoadM2(int fileDataID)
        {
            Stream m2 = CASC.OpenFile(fileDataID);

            var bin = new BinaryReader(m2);

            BlizzHeader chunk;

            long position = 0;

            while (position < m2.Length)
            {
                m2.Position = position;
                chunk       = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32());
                position    = m2.Position + chunk.Size;

                switch (chunk.ToString())
                {
                case "MD21":
                    using (Stream m2stream = new MemoryStream(bin.ReadBytes((int)chunk.Size)))
                    {
                        ParseYeOldeM2Struct(m2stream);
                    }
                    break;

                case "AFID":
                    var afids = new AFID[chunk.Size / 16];
                    for (int a = 0; a < chunk.Size / 16; a++)
                    {
                        afids[a].animID     = (short)bin.ReadUInt16();
                        afids[a].subAnimID  = (short)bin.ReadUInt16();
                        afids[a].fileDataID = bin.ReadUInt32();
                    }
                    model.animFileData = afids;
                    break;

                case "BFID":
                    var bfids = new int[chunk.Size / 4];
                    for (int b = 0; b < chunk.Size / 4; b++)
                    {
                        bfids[b] = (int)bin.ReadUInt32();
                    }
                    break;

                case "SFID":
                    var sfids = new int[model.nViews];
                    for (int s = 0; s < model.nViews; s++)
                    {
                        sfids[s] = (int)bin.ReadUInt32();
                    }
                    model.skinFileDataIDs = sfids;
                    break;

                case "PFID":
                    model.physFileID = (int)bin.ReadUInt32();
                    break;

                default:
                    throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\"", chunk.ToString(), position.ToString(), "id: " + fileDataID));
                }
            }

            model.skins = readSkins(model.skinFileDataIDs);

            return;
        }
Example #2
0
        public void LoadM2(Stream m2, bool loadSkins = true)
        {
            var  bin      = new BinaryReader(m2);
            long position = 0;

            while (position < m2.Length)
            {
                m2.Position = position;

                var chunkName = (M2Chunks)bin.ReadUInt32();
                var chunkSize = bin.ReadUInt32();

                position = m2.Position + chunkSize;

                switch (chunkName)
                {
                case M2Chunks.MD21:
                    using (Stream m2stream = new MemoryStream(bin.ReadBytes((int)chunkSize)))
                    {
                        ParseYeOldeM2Struct(m2stream);
                    }
                    break;

                case M2Chunks.AFID:     // Animation file IDs
                    var afids = new AFID[chunkSize / 8];
                    for (var a = 0; a < chunkSize / 8; a++)
                    {
                        afids[a].animID     = bin.ReadInt16();
                        afids[a].subAnimID  = bin.ReadInt16();
                        afids[a].fileDataID = bin.ReadUInt32();
                    }
                    model.animFileDataIDs = afids;
                    break;

                case M2Chunks.BFID:     // Bone file IDs
                    var bfids = new uint[chunkSize / 4];
                    for (var b = 0; b < chunkSize / 4; b++)
                    {
                        bfids[b] = bin.ReadUInt32();
                    }
                    break;

                case M2Chunks.SFID:     // Skin file IDs
                    var sfids = new uint[model.nViews];
                    for (var s = 0; s < model.nViews; s++)
                    {
                        sfids[s] = bin.ReadUInt32();
                    }
                    model.skinFileDataIDs = sfids;
                    break;

                case M2Chunks.PFID:     // Phys file ID
                    model.physFileID = bin.ReadUInt32();
                    break;

                case M2Chunks.SKID:     // Skel file ID
                    model.skelFileID = bin.ReadUInt32();
                    break;

                case M2Chunks.TXID:     // Texture file IDs
                    var txids = new uint[chunkSize / 4];
                    for (var t = 0; t < chunkSize / 4; t++)
                    {
                        txids[t] = bin.ReadUInt32();
                    }
                    model.textureFileDataIDs = txids;
                    break;

                case M2Chunks.RPID:     // Recursive particle file IDs
                    var rpids = new uint[chunkSize / 4];
                    for (var t = 0; t < chunkSize / 4; t++)
                    {
                        rpids[t] = bin.ReadUInt32();
                    }
                    model.recursiveParticleModelFileIDs = rpids;
                    break;

                case M2Chunks.GPID:     // Geometry particle file IDs
                    var gpids = new uint[chunkSize / 4];
                    for (var t = 0; t < chunkSize / 4; t++)
                    {
                        gpids[t] = bin.ReadUInt32();
                    }
                    model.geometryParticleModelFileIDs = gpids;
                    break;

                case M2Chunks.TXAC:     // Texture transforms (?)
                case M2Chunks.EXPT:     // Extended Particles
                case M2Chunks.EXP2:     // Extended Particles 2
                case M2Chunks.PABC:
                case M2Chunks.PADC:
                case M2Chunks.PEDC:
                case M2Chunks.PSBC:
                case M2Chunks.LDV1:
                    break;

                default:
#if DEBUG
                    throw new Exception(string.Format("M2: Found unknown header at offset {1} \"{0}\"", chunkName.ToString("X"), position.ToString()));
#else
                    CASCLib.Logger.WriteLine(String.Format("M2: Found unknown header at offset {1} \"{0}\"", chunkName, position.ToString()));
                    break;
#endif
                }
            }

            if (loadSkins && CASC.IsCASCInit)
            {
                model.skins = ReadSkins(model.skinFileDataIDs);
            }

            return;
        }
Example #3
0
        public void LoadM2(int fileDataID)
        {
            Stream m2       = CASC.cascHandler.OpenFile(fileDataID);
            var    bin      = new BinaryReader(m2);
            long   position = 0;

            while (position < m2.Length)
            {
                m2.Position = position;

                var chunkName = new string(bin.ReadChars(4));
                var chunkSize = bin.ReadUInt32();

                position = m2.Position + chunkSize;

                switch (chunkName)
                {
                case "MD21":
                    using (Stream m2stream = new MemoryStream(bin.ReadBytes((int)chunkSize)))
                    {
                        ParseYeOldeM2Struct(m2stream);
                    }
                    break;

                case "AFID":     // Animation file IDs
                    var afids = new AFID[chunkSize / 16];
                    for (int a = 0; a < chunkSize / 16; a++)
                    {
                        afids[a].animID     = (short)bin.ReadUInt16();
                        afids[a].subAnimID  = (short)bin.ReadUInt16();
                        afids[a].fileDataID = bin.ReadUInt32();
                    }
                    model.animFileData = afids;
                    break;

                case "BFID":     // Bone file IDs
                    var bfids = new int[chunkSize / 4];
                    for (int b = 0; b < chunkSize / 4; b++)
                    {
                        bfids[b] = (int)bin.ReadUInt32();
                    }
                    break;

                case "SFID":     // Skin file IDs
                    var sfids = new int[model.nViews];
                    for (int s = 0; s < model.nViews; s++)
                    {
                        sfids[s] = (int)bin.ReadUInt32();
                    }
                    model.skinFileDataIDs = sfids;
                    break;

                case "PFID":     // Phys file IDs
                    model.physFileID = (int)bin.ReadUInt32();
                    break;

                case "SKID":
                    model.skelFileID = (int)bin.ReadUInt32();
                    break;

                case "TXAC":
                case "EXPT":
                case "EXP2":
                case "PADC":
                case "PABC":
                case "PSBC":
                case "PEDC":
                    break;

                default:
#if DEBUG
                    throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\"", chunkName, position.ToString(), "id: " + fileDataID));
#else
                    CASCLib.Logger.WriteLine(String.Format("{2} Found unknown header at offset {1} \"{0}\"", chunkName, position.ToString(), "id: " + fileDataID));
                    break;
#endif
                }
            }

            model.skins = ReadSkins(model.skinFileDataIDs);

            return;
        }