Exemplo n.º 1
0
        public static WTSkinnedModel ReadBinary(Stream stream)
        {
            var reader = new BinaryReader(stream);

            //Header is 5 bytes long. V2.0 + a null byte
            int  headerMagic = reader.ReadInt32();
            byte nullByte    = reader.ReadByte();

            if (headerMagic != HEADER_MAGIC || nullByte != 0)
            {
                reader.Dispose();
                throw new Exception("Bad SMS header!");
            }
            reader.BaseStream.Seek(4, SeekOrigin.Current);

            //cosntruct model
            var returnModel = new WTSkinnedModel();

            int objectCount = reader.ReadInt32();
            int unkCount    = reader.ReadInt32();

            int tagCount      = reader.ReadInt32();
            int materialCount = reader.ReadInt32();
            int textureCount  = reader.ReadInt32();

            //textures
            for (int i = 0; i < textureCount; i++)
            {
                string tex = reader.ReadNullTerminatedString();
                int    id  = reader.ReadInt32();
                returnModel.Textures.Add(id, tex);
            }

            //materials
            for (int i = 0; i < materialCount; i++)
            {
                var material = WTMaterial.ReadBinary(reader);
                returnModel.Materials.Add(material.ID, material);
            }

            //weird tag list
            for (int i = 0; i < tagCount; i++)
            {
                string item1 = reader.ReadNullTerminatedString();

                bool   hasPair2 = reader.ReadUInt16() != 0;
                string item2    = (hasPair2) ? reader.ReadNullTerminatedString() : null;

                returnModel.UnkStringList.Add(new Tuple <string, string>(item1, item2));
            }

            for (int i = 0; i < objectCount; i++)
            {
                var obj = WTSkinnedObject.ReadBinary(reader);
                returnModel.Objects.Add(obj);
            }

            //read bone count
            int boneCount = reader.ReadInt32();

            for (int i = 0; i < boneCount; i++)
            {
                returnModel.Bones.Add(SkinnedModelBone.ReadBinary(reader));
            }

            reader.Dispose();
            return(returnModel);
        }
Exemplo n.º 2
0
        public static WTModel ReadBinary(Stream stream)
        {
            var reader      = new BinaryReader(stream);
            var returnModel = new WTModel();

            //determine filetype
            bool isSceneFile = false;

            reader.BaseStream.Seek(24, SeekOrigin.Begin);

            float version = reader.ReadSingle();

            if (version == 1f)
            {
                isSceneFile = true;
            }
            else
            {
                reader.BaseStream.Seek(0, SeekOrigin.Begin);
                version = reader.ReadSingle();
                if (version != 1f)
                {
                    throw new System.Exception($"Expected version 1.0, got version {version}. Either not a MDL/SCN file, or wrong version.");
                }
            }

            //read data
            int meshCount   = reader.ReadInt32();
            int lightCount  = reader.ReadInt32();
            int helperCount = reader.ReadInt32();
            int splineCount = reader.ReadInt32();

            int materialCount = reader.ReadInt32();
            int textureCount  = reader.ReadInt32();

            //textures
            for (int i = 0; i < textureCount; i++)
            {
                string tex = reader.ReadNullTerminatedString();
                int    id  = reader.ReadInt32();
                returnModel.Textures.Add(id, tex);
            }

            //materials
            for (int i = 0; i < materialCount; i++)
            {
                var material = WTMaterial.ReadBinary(reader);
                returnModel.Materials.Add(material.ID, material);
            }

            //meshes
            for (int i = 0; i < meshCount; i++)
            {
                returnModel.Meshes.Add(WTMesh.ReadBinary(reader, isSceneFile));
            }

            //lights
            for (int i = 0; i < lightCount; i++)
            {
                returnModel.Lights.Add(WTLight.ReadBinary(reader));
            }

            //helpers
            for (int i = 0; i < helperCount; i++)
            {
                returnModel.Helpers.Add(WTHelper.ReadBinary(reader));
            }

            //splines
            for (int i = 0; i < splineCount; i++)
            {
                returnModel.Splines.Add(WTSpline.ReadBinary(reader));
            }

            reader.Dispose();
            return(returnModel);
        }
Exemplo n.º 3
0
        public static WTMaterial ReadBinary(BinaryReader reader)
        {
            var material = new WTMaterial()
            {
                Name        = reader.ReadNullTerminatedString(),
                ID          = reader.ReadInt32(),
                DoubleSided = reader.ReadInt32() == 1,
                Collideable = reader.ReadInt32() == 1,
                Visible     = reader.ReadInt32() == 1,
                DataID      = reader.ReadInt32()
            };

            material.ColorKey = reader.ReadInt32() == 1;
            if (material.ColorKey)
            {
                material.ColorKeyColor = reader.ReadColor48();
            }

            bool hasUvSpin = reader.ReadInt32() == 1;

            if (hasUvSpin)
            {
                material.USpinner = reader.ReadSingle();
                material.VSpinner = reader.ReadSingle();
            }

            bool hasHfVfSpin = reader.ReadInt32() == 1;

            if (hasHfVfSpin)
            {
                material.HFSpinner   = reader.ReadInt16();
                material.VFSpinner   = reader.ReadInt16();
                material.TimeSpinner = reader.ReadSingle();
            }

            bool hasUvSpin2 = reader.ReadInt32() == 1;

            if (hasUvSpin2)
            {
                material.USpinner2 = reader.ReadSingle();
                material.VSpinner2 = reader.ReadSingle();
            }

            bool hasHfVfSpin2 = reader.ReadInt32() == 1;

            if (hasHfVfSpin2)
            {
                material.HFSpinner2   = reader.ReadInt16();
                material.VFSpinner2   = reader.ReadInt16();
                material.TimeSpinner2 = reader.ReadSingle();
            }

            material.RenderLast  = reader.ReadInt32();
            material.RenderFirst = reader.ReadInt32();

            material.Color1 = reader.ReadColor48();
            material.Color2 = reader.ReadColor48();
            material.Color3 = reader.ReadColor48();
            material.Color4 = reader.ReadColor48();

            material.unkFloat1 = reader.ReadSingle();
            material.unkFloat2 = reader.ReadSingle();

            for (int mtc = 0; mtc < 7; mtc++)
            {
                int texId = reader.ReadInt32();
                material.TextureSlots[mtc] = texId;
            }

            return(material);
        }