Example #1
0
        public void ReadFromFile(BinaryReader reader)
        {
            if (reader.ReadInt16() != Magic)
            {
                return;
            }

            ushort animalInsCount = reader.ReadUInt16();

            instances = new AnimalTrafficInstance[animalInsCount];

            if (reader.ReadInt32() != Version)
            {
                return;
            }

            for (int i = 0; i < animalInsCount; i++)
            {
                AnimalTrafficInstance instance = new AnimalTrafficInstance();
                instance.Name = new HashName();
                instance.Name.ReadFromFile(reader);
                instances[i] = instance;
            }

            ushort pathCount = reader.ReadUInt16();

            paths = new AnimalTrafficPath[pathCount];

            for (int i = 0; i < pathCount; i++)
            {
                AnimalTrafficPath path = new AnimalTrafficPath();
                byte pathSize          = reader.ReadByte();
                byte count1            = reader.ReadByte();
                byte count2            = reader.ReadByte();
                byte count3            = reader.ReadByte();
                path.Data0       = reader.ReadBytes(count1);
                path.Data1       = reader.ReadBytes(count2);
                path.Data2       = reader.ReadBytes(count3);
                path.BoundingBox = BoundingBoxExtenders.ReadFromFile(reader);
                path.Hash        = new HashName();
                path.Hash.ReadFromFile(reader);     //decompiled exe says this is a hash but its always empty
                path.Unk0    = reader.ReadSingle(); //5
                path.Unk1    = reader.ReadSingle(); //15
                path.Unk2    = reader.ReadByte();   //1 257 or 513.
                path.Unk3    = reader.ReadBytes(path.Unk2);
                path.Vectors = new PathVectors[pathSize];

                for (int x = 0; x < pathSize; x++)
                {
                    PathVectors vector = new PathVectors();
                    vector.Position = Vector3Extenders.ReadFromFile(reader); //Very large differences between these two
                    vector.Rotation = Vector3Extenders.ReadFromFile(reader); //2nd one could be rotation, in radians.
                    vector.Unk0     = reader.ReadByte();                     //7 or 4
                    path.Vectors[x] = vector;
                }


                paths[i] = path;
            }
        }
Example #2
0
        public override void ReadFromFile(MemoryStream stream, bool isBigEndian)
        {
            base.ReadFromFile(stream, isBigEndian);

            NumFrames = stream.ReadInt32(isBigEndian);
            Frames    = new FrameData[NumFrames];

            for (int i = 0; i < NumFrames; i++)
            {
                FrameData frames = new FrameData();
                frames.Unk01     = stream.ReadInt32(isBigEndian);
                frames.Unk02     = stream.ReadInt32(isBigEndian);
                frames.Unk03     = stream.ReadByte8();
                frames.SoundFile = stream.ReadString16(isBigEndian);
                frames.Unk04     = stream.ReadByte8();
                frames.Unk05     = stream.ReadSingle(isBigEndian);
                frames.Unk06     = stream.ReadSingle(isBigEndian);
                frames.Unk07     = stream.ReadSingle(isBigEndian);
                frames.Unk08     = stream.ReadInt32(isBigEndian);
                frames.Unk09     = stream.ReadSingle(isBigEndian);
                frames.Unk10     = stream.ReadInt32(isBigEndian);
                frames.Unk11     = stream.ReadSingle(isBigEndian);
                frames.Unk12     = stream.ReadInt32(isBigEndian);
                frames.Unk13     = stream.ReadSingle(isBigEndian);
                frames.Unk14     = stream.ReadSingle(isBigEndian);
                frames.Unk15     = stream.ReadByte8();
                frames.Position  = Vector3Extenders.ReadFromFile(stream, isBigEndian);
                frames.Rotation  = QuaternionExtensions.ReadFromFile(stream, isBigEndian);
                frames.Unk16     = stream.ReadByte8();
                Frames[i]        = frames;
            }

            Unk05 = stream.ReadUInt16(isBigEndian);
        }
 public void ReadFromFile(BinaryReader reader)
 {
     Position   = Vector3Extenders.ReadFromFile(reader);
     Direction  = Vector3Extenders.ReadFromFile(reader);
     EntityName = XBinCoreUtils.ReadStringPtrWithOffset(reader);
     LoadFlags  = reader.ReadUInt32();
 }
Example #4
0
 public void ReadFromFile(BinaryReader reader)
 {
     Position = Vector3Extenders.ReadFromFile(reader);
     Rotation = Vector3Extenders.ReadFromFile(reader);
     Hash     = reader.ReadUInt64();
     Unk4     = reader.ReadInt32();
     Unk5     = reader.ReadByte();
 }
Example #5
0
 public void ReadFromFile(BinaryReader reader)
 {
     unk0 = reader.ReadByte();
     unk1 = Vector3Extenders.ReadFromFile(reader);
     unk2 = Vector3Extenders.ReadFromFile(reader);
     unk3 = Vector3Extenders.ReadFromFile(reader);
     unk4 = reader.ReadSingle();
 }
Example #6
0
 public void ReadFromFile(BinaryReader reader)
 {
     unk0     = reader.ReadInt16();
     position = Vector3Extenders.ReadFromFile(reader);
     rotation = Vector3Extenders.ReadFromFile(reader);
     unk1     = Vector3Extenders.ReadFromFile(reader);
     unk2     = reader.ReadInt32();
 }
Example #7
0
        public void ReadFromFile(BinaryReader reader)
        {
            unk0        = reader.ReadInt32();
            fileIDHPD   = reader.ReadInt32();
            unk3HPD     = reader.ReadInt32();
            bitFlagsHPD = reader.ReadInt32();

            vertSize = reader.ReadInt32();
            triSize  = reader.ReadInt32();
            //writer.WriteLine(string.Format("{0}, )

            StreamWriter writer = File.CreateText("NAV_AI_OBJ_DATA_" + fileIDHPD + ".txt");

            writer.WriteLine(string.Format("{0} {1} {2} {3}", unk0, fileIDHPD, unk3HPD, bitFlagsHPD));

            //List<string> data = new List<string>();
            List <Vector3> Points = new List <Vector3>();

            vertices = new VertexStruct[vertSize];
            for (int i = 0; i < vertSize; i++)
            {
                VertexStruct vertex = new VertexStruct();
                vertex.Unk7     = reader.ReadUInt32() & 0x7FFFFFFF;
                vertex.Position = Vector3Extenders.ReadFromFile(reader);
                Vector3 pos = vertex.Position;
                float   y   = pos.Y;
                pos.Y           = -pos.Z;
                pos.Z           = y;
                vertex.Position = pos;
                //writer.WriteLine(vertex.Position);
                vertex.Unk0 = reader.ReadSingle();
                vertex.Unk1 = reader.ReadSingle();
                vertex.Unk2 = reader.ReadInt32();
                vertex.Unk3 = reader.ReadInt16();
                vertex.Unk4 = reader.ReadInt16();
                vertex.Unk5 = reader.ReadInt32();
                vertex.Unk6 = reader.ReadInt32();
                vertices[i] = vertex;

                Points.Add(vertex.Position);
            }

            writer.WriteLine("");
            connections = new ConnectionStruct[triSize];
            for (int i = 0; i < triSize; i++)
            {
                ConnectionStruct connection = new ConnectionStruct();
                connection.Flags           = reader.ReadUInt32() & 0x7FFFFFFF;
                connection.NodeID          = reader.ReadUInt32() & 0x7FFFFFFF;
                connection.ConnectedNodeID = reader.ReadUInt32() & 0x7FFFFFFF;
                connections[i]             = connection;
                //writer.WriteLine(string.Format("{0} {1} {2}", connection.Flags, connection.NodeID, connection.ConnectedNodeID));
            }

            //Read KynogonRuntimeMesh
            runtimeMesh = new KynogonRuntimeMesh();
            runtimeMesh.ReadFromFile(reader, writer);
        }
Example #8
0
        public override void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            base.ReadFromFile(reader, isBigEndian);
            flags = reader.ReadInt32(isBigEndian);

            for (int i = 0; i < 7; i++)
            {
                unkFloat1[i] = reader.ReadSingle(isBigEndian);
            }

            unk_int = reader.ReadInt32(isBigEndian);

            for (int i = 0; i < 5; i++)
            {
                unkFloat2[i] = reader.ReadSingle(isBigEndian);
            }

            unk_byte1 = reader.ReadByte8();

            for (int i = 0; i < 17; i++)
            {
                unkFloat3[i] = reader.ReadSingle(isBigEndian);
            }

            unk_byte2 = reader.ReadByte8();

            for (int i = 0; i < 5; i++)
            {
                unkFloat4[i] = reader.ReadSingle(isBigEndian);
            }

            nameLight = new HashName(reader, isBigEndian);

            unk_int2 = reader.ReadInt32(isBigEndian);

            for (int i = 0; i < 20; i++)
            {
                unkFloat5[i] = reader.ReadSingle(isBigEndian);
            }

            for (int i = 0; i < 4; i++)
            {
                names[i] = new HashName(reader, isBigEndian);
            }

            unkVector1 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            unkVector2 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            unk_byte3  = reader.ReadByte8();
            unkVector3 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            unkVector4 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            unkVector5 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            unkVector6 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
        }
Example #9
0
        public override void ReadFromFile(MemoryStream stream, bool isBigEndian)
        {
            base.ReadFromFile(stream, isBigEndian);

            NumSounds = stream.ReadInt32(isBigEndian);
            Sounds    = new SoundData_Type19[NumSounds];

            for (int i = 0; i < NumSounds; i++)
            {
                SoundData_Type19 SoundInfo = new SoundData_Type19();
                SoundInfo.Unk01     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk02     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk03     = stream.ReadByte8();
                SoundInfo.SoundFile = stream.ReadString16(isBigEndian);
                SoundInfo.Unk04     = stream.ReadByte8();
                SoundInfo.Unk05     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk06     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk07     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk08     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk10     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk11     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk12     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk13     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk14     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk15     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk16     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk17     = stream.ReadSingle(isBigEndian);

                SoundInfo.Unk18    = stream.ReadByte8();
                SoundInfo.Position = Vector3Extenders.ReadFromFile(stream, isBigEndian);
                SoundInfo.Unk19    = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk20    = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk21    = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk22    = stream.ReadSingle(isBigEndian);

                SoundInfo.IsMeshAvailableFlags = stream.ReadByte8();
                if (SoundInfo.IsMeshAvailableFlags == 3)
                {
                    SoundInfo.FrameName     = stream.ReadString16(isBigEndian);
                    SoundInfo.MainJointHash = stream.ReadUInt64(isBigEndian);
                    SoundInfo.FrameHash     = stream.ReadUInt64(isBigEndian);
                }
                else if (SoundInfo.IsMeshAvailableFlags == 1)
                {
                    SoundInfo.FrameName     = stream.ReadString16(isBigEndian);
                    SoundInfo.MainJointHash = stream.ReadUInt64(isBigEndian);
                }

                Sounds[i] = SoundInfo;
            }

            Unk05 = stream.ReadUInt16(isBigEndian);
        }
Example #10
0
        public void ReadFromFile(BinaryReader reader)
        {
            Vector3 m1 = Vector3Extenders.ReadFromFile(reader);
            float   x  = reader.ReadSingle();
            Vector3 m2 = Vector3Extenders.ReadFromFile(reader);
            float   y  = reader.ReadSingle();
            Vector3 m3 = Vector3Extenders.ReadFromFile(reader);
            float   z  = reader.ReadSingle();

            transformedMatrix = new Matrix33(m1, m2, m3);
            Decompose();
            Position = new Vector3(x, y, z);
        }
Example #11
0
        public void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            Vector3 m1 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            float   x  = reader.ReadSingle(isBigEndian);
            Vector3 m2 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            float   y  = reader.ReadSingle(isBigEndian);
            Vector3 m3 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            float   z  = reader.ReadSingle(isBigEndian);

            transformedMatrix = new Matrix33(m1, m2, m3);
            Decompose();
            Position = new Vector3(x, y, z);
        }
Example #12
0
        public void ReadFromFile(BinaryReader reader)
        {
            unk0     = reader.ReadInt32();
            unk2     = reader.ReadInt32();
            unk3     = reader.ReadInt32();
            unk4     = reader.ReadInt32();
            vertSize = reader.ReadInt32();
            triSize  = reader.ReadInt32();

            vertices = new VertexStruct[vertSize];
            for (int i = 0; i < vertSize; i++)
            {
                VertexStruct vertex = new VertexStruct();
                vertex.unk7     = reader.ReadInt32();
                vertex.position = Vector3Extenders.ReadFromFile(reader);
                float pos = vertex.position.Y; //f**k the third var thing
                vertex.position.Y = vertex.position.Z;
                vertex.position.Z = pos;
                vertex.unk0       = reader.ReadSingle();
                vertex.unk1       = reader.ReadSingle();
                vertex.unk2       = reader.ReadInt32();
                vertex.unk3       = reader.ReadInt16();
                vertex.unk4       = reader.ReadInt16();
                vertex.unk5       = reader.ReadInt32();
                vertex.unk6       = reader.ReadInt32();
                vertices[i]       = vertex;
            }
            //unk6 = reader.ReadInt32();
            //unk7 = reader.ReadInt32();
            //unk8 = reader.ReadInt16();
            //unk9 = reader.ReadInt16();

            //int x = 2;
            //indices = new uint[(triSize - 1) * 3];
            //for (int i = 0; i < (triSize - 1) * 3; i++)
            //{
            //    if (x == 0)
            //    {
            //        indices[i] = reader.ReadUInt32();
            //        x = 2;
            //    }
            //    else
            //    {
            //        indices[i] = (uint)reader.ReadInt24();
            //        reader.ReadByte();
            //        x--;
            //    }
            //}
            //TODO::
        }
Example #13
0
            /// <summary>
            /// Read data from file.
            /// </summary>
            /// <param name="reader">stream</param>
            public void ReadFromFile(BinaryReader reader)
            {
                position = Vector3Extenders.ReadFromFile(reader);
                rotation = Vector3Extenders.ReadFromFile(reader);
                Vector3 rot = new Vector3();

                rot.X    = MathUtil.RadiansToDegrees(rotation.X);
                rot.Y    = MathUtil.RadiansToDegrees(rotation.Y);
                rot.Z    = -MathUtil.RadiansToDegrees(rotation.Z);
                rotation = rot;
                hash     = reader.ReadUInt64();
                unk4     = reader.ReadInt32();
                unk5     = reader.ReadByte();
            }
Example #14
0
                public void ReadFromFile(BinaryReader reader)
                {
                    unk0 = reader.ReadByte();
                    unk1 = reader.ReadInt32();
                    unk2 = Vector3Extenders.ReadFromFile(reader);
                    unk3 = reader.ReadSingle();
                    unk4 = reader.ReadSingle();
                    short count = reader.ReadInt16();

                    unk5 = new int[count];
                    for (int i = 0; i != count; i++)
                    {
                        unk5[i] = reader.ReadInt32();
                    }
                }
Example #15
0
        /// <summary>
        /// Read data from stream.
        /// </summary>
        /// <param name="reader"></param>
        public void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            numLods = reader.ReadByte8();
            unk01   = reader.ReadInt16(isBigEndian);

            decompressionOffset = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            decompressionFactor = reader.ReadSingle(isBigEndian);

            LOD = new FrameLOD[numLods];

            for (int i = 0; i < numLods; i++)
            {
                LOD[i] = new FrameLOD();
                LOD[i].ReadFromFile(reader, isBigEndian);
            }
        }
Example #16
0
        public override void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            base.ReadFromFile(reader, isBigEndian);
            unk_08_int = reader.ReadInt32(isBigEndian);
            planesSize = reader.ReadInt32(isBigEndian);

            planes = new Vector4[planesSize];
            for (int i = 0; i != planes.Length; i++)
            {
                planes[i] = Vector4Extenders.ReadFromFile(reader, isBigEndian);
            }

            bounds         = BoundingBoxExtenders.ReadFromFile(reader, isBigEndian);
            unk_13_vector3 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            unk_14_vector3 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            sectorName     = new Hash(reader, isBigEndian);
        }
Example #17
0
 public void ReadFromFile(BinaryReader reader)
 {
     size           = reader.ReadInt32();
     actorTypeName  = readString(reader);
     entityType     = readString(reader);
     unkString      = readString(reader);
     unk2String     = readString(reader);
     definitionName = readString(reader);
     frameName      = readString(reader);
     actortypeID    = reader.ReadInt32();
     defintionHash  = reader.ReadUInt64();
     frameNameHash  = reader.ReadUInt64();
     position       = Vector3Extenders.ReadFromFile(reader);
     quat           = Vector4Extenders.ReadFromFile(reader);
     scale          = Vector3Extenders.ReadFromFile(reader);
     unk3           = reader.ReadUInt16();
     dataID         = reader.ReadUInt16();
 }
Example #18
0
        public override void ReadFromFile(MemoryStream stream, bool isBigEndian)
        {
            base.ReadFromFile(stream, isBigEndian);
            Debug.Assert(stream.Position != stream.Length, "I've read the parent class data, although i've hit the eof!");

            if (stream.Position != stream.Length)
            {
                Unk02 = stream.ReadInt32(isBigEndian);
                Unk03 = Vector3Extenders.ReadFromFile(stream, isBigEndian);
                Unk04 = stream.ReadSingle(isBigEndian);
                Unk05 = stream.ReadBytes(24);
                Unk06 = stream.ReadSingle(isBigEndian);
                Unk07 = stream.ReadInt32(isBigEndian);
                Unk08 = stream.ReadByte8();

                bDoesHaveExtraData = true;
            }
        }
Example #19
0
        public override void ReadFromFile(MemoryStream stream, bool isBigEndian)
        {
            base.ReadFromFile(stream, isBigEndian);

            NumPositions = stream.ReadInt32(isBigEndian);
            Positions    = new PositionData[NumPositions];

            for (int i = 0; i < NumPositions; i++)
            {
                PositionData position = new PositionData();
                position.Unk01    = stream.ReadInt32(isBigEndian);
                position.Unk02    = stream.ReadInt32(isBigEndian);
                position.Unk03    = stream.ReadByte8();
                position.Position = Vector3Extenders.ReadFromFile(stream, isBigEndian);
                Positions[i]      = position;
            }

            Unk05 = stream.ReadUInt16(isBigEndian);
        }
Example #20
0
        public void ReadFromFile(BinaryReader reader)
        {
            int size = reader.ReadInt32();

            position = new Vector3[size];

            for (int i = 0; i != size; i++)
            {
                position[i] = Vector3Extenders.ReadFromFile(reader);
            }

            size   = reader.ReadInt32();
            sphere = new Vector3[size];

            for (int i = 0; i != size; i++)
            {
                sphere[i] = Vector3Extenders.ReadFromFile(reader);
            }
        }
Example #21
0
                public void ReadFromFile(BinaryReader reader)
                {
                    unk0     = reader.ReadByte();
                    position = Vector3Extenders.ReadFromFile(reader);
                    rotation = Vector3Extenders.ReadFromFile(reader);
                    unk1     = reader.ReadInt32();
                    unk2     = reader.ReadInt32();
                    unk3     = reader.ReadInt32();
                    unk4     = Vector3Extenders.ReadFromFile(reader);
                    unk5     = reader.ReadInt32();
                    unk6     = reader.ReadByte();
                    unk7     = reader.ReadByte();
                    short count = reader.ReadInt16();

                    unk8 = new int[count];
                    for (int i = 0; i != count; i++)
                    {
                        unk8[i] = reader.ReadInt32();
                    }
                    unk9 = reader.ReadInt32();
                }
Example #22
0
        public HPDData(BinaryReader reader)
        {
            unk0            = reader.ReadInt32();
            unk1            = reader.ReadInt32();
            remainingHeader = reader.ReadBytes(132);

            unkData = new unkStruct[unk1];

            for (int i = 0; i != unkData.Length; i++)
            {
                unkStruct data = new unkStruct();
                data.id      = reader.ReadInt32();
                data.unk0    = Vector3Extenders.ReadFromFile(reader);
                data.unk1    = Vector3Extenders.ReadFromFile(reader);
                data.unkData = reader.ReadBytes(20);
                unkData[i]   = data;
            }

            unk2 = StringHelpers.ReadString(reader);
            unk3 = reader.ReadInt32();
            unk4 = reader.ReadInt32();
        }
Example #23
0
        public void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            Vector3 m1 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            float   x  = reader.ReadSingle(isBigEndian);
            Vector3 m2 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            float   y  = reader.ReadSingle(isBigEndian);
            Vector3 m3 = Vector3Extenders.ReadFromFile(reader, isBigEndian);
            float   z  = reader.ReadSingle(isBigEndian);

            transformedMatrix     = new Matrix33(m1, m2, m3);
            scale                 = new Matrix33(new Vector3(m1.Length(), 0.0f, 0.0f), new Vector3(0.0f, m2.Length(), 0.0f), new Vector3(0.0f, 0.0f, m3.Length()));
            rotation              = new Matrix33();
            transformedMatrix.M00 = transformedMatrix.M00 / scale.M00;
            transformedMatrix.M01 = transformedMatrix.M01 / scale.M00;
            transformedMatrix.M02 = transformedMatrix.M02 / scale.M00;
            transformedMatrix.M10 = transformedMatrix.M10 / scale.M11;
            transformedMatrix.M11 = transformedMatrix.M11 / scale.M11;
            transformedMatrix.M12 = transformedMatrix.M12 / scale.M11;
            transformedMatrix.M20 = transformedMatrix.M20 / scale.M22;
            transformedMatrix.M21 = transformedMatrix.M21 / scale.M22;
            transformedMatrix.M22 = transformedMatrix.M22 / scale.M22;
            Position              = new Vector3(x, y, z);
        }
        public void ReadFromFile(BinaryReader reader)
        {
            if (reader.ReadInt32() != type)
            {
                return;
            }

            if (StringHelpers.ReadString32(reader) != name)
            {
                return;
            }

            unk0      = reader.ReadInt32();
            unk1      = reader.ReadInt32();
            numVerts1 = reader.ReadInt32();
            unk2      = reader.ReadInt64();
            unkFlags  = reader.ReadBytes(5);
            unk3      = reader.ReadInt32();
            unk4      = reader.ReadInt64();
            padding   = reader.ReadByte();
            numVerts2 = reader.ReadInt32();

            vertices = new Vector3[numVerts2];
            for (int i = 0; i != numVerts2; i++)
            {
                vertices[i] = Vector3Extenders.ReadFromFile(reader);
            }

            numVerts3   = reader.ReadInt32();
            unkVectors1 = new Vector3[numVerts3];
            for (int i = 0; i != numVerts3; i++)
            {
                unkVectors1[i] = Vector3Extenders.ReadFromFile(reader);
            }

            numVerts4   = reader.ReadInt32();
            unkVectors2 = new Vector3[numVerts4];
            for (int i = 0; i != numVerts4; i++)
            {
                unkVectors2[i] = Vector3Extenders.ReadFromFile(reader);
            }

            numVerts5   = reader.ReadInt32();
            unkVectors3 = new Vector3[numVerts5];
            for (int i = 0; i != numVerts5; i++)
            {
                unkVectors3[i] = Vector3Extenders.ReadFromFile(reader);
            }

            numVerts6 = reader.ReadInt32();
            boneIdx   = new int[numVerts6];
            for (int i = 0; i != numVerts6; i++)
            {
                boneIdx[i] = reader.ReadInt32();
            }

            unkShorts = new short[numVerts6 * 4];
            for (int i = 0; i != numVerts6 * 4; i++)
            {
                unkShorts[i] = reader.ReadInt16();
            }

            unk6            = reader.ReadInt16();
            unk7            = reader.ReadInt16();
            unk8            = reader.ReadInt32();
            unk8Collection  = new float[unk8];
            unk8Collection2 = new int[unk8];
            for (int i = 0; i != unk8; i++)
            {
                unk8Collection[i] = reader.ReadSingle();
            }

            for (int i = 0; i != unk8; i++)
            {
                unk8Collection2[i] = reader.ReadInt32();
            }

            numTriangles = reader.ReadInt32();
            triangles    = new Int3[numTriangles];

            for (int i = 0; i != numTriangles; i++)
            {
                Int3 int3 = new Int3();
                int3.X       = reader.ReadInt32();
                int3.Y       = reader.ReadInt32();
                int3.Z       = reader.ReadInt32();
                triangles[i] = int3;
            }

            unk20         = reader.ReadInt64();
            unk20_1       = reader.ReadInt32();
            unk21         = reader.ReadInt64();
            unk21_1       = reader.ReadInt32();
            numMaterials  = reader.ReadInt32();
            materialNames = new string[numMaterials];
            for (int i = 0; i != numMaterials; i++)
            {
                materialNames[i] = StringHelpers.ReadString32(reader);
            }

            unk22 = reader.ReadInt32();
            bbox  = BoundingBoxExtenders.ReadFromFile(reader);
            unk23 = reader.ReadInt32();

            List <string> data = new List <string>();

            for (int z = 0; z != unkVectors1.Length; z++)
            {
                data.Add(string.Format("v {0} {1} {2}", unkVectors1[z].X, unkVectors1[z].Y, unkVectors1[z].Z));
            }

            data.Add("");
            data.Add("g " + "Object");
            for (int z = 0; z != numTriangles; z++)
            {
                data.Add(string.Format("f {0} {1} {2}", triangles[z].X + 1, triangles[z].Y + 1, triangles[z].Z + 1));
            }

            File.WriteAllLines("Object.obj", data.ToArray());
        }
        public void ReadFromM2T(BinaryReader reader)
        {
            if (new string(reader.ReadChars(3)) != fileHeader)
            {
                return;
            }

            if (reader.ReadByte() != fileVersion)
            {
                return;
            }

            //mesh name
            name = reader.ReadString();

            //Number of Lods
            Lods = new Lod[reader.ReadByte()];

            for (int i = 0; i != Lods.Length; i++)
            {
                Lods[i] = new Lod
                {
                    VertexDeclaration = 0
                };

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.Position;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.Normals;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.Tangent;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.Skin;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.Color;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.TexCoords0;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.TexCoords1;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.TexCoords2;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.ShadowTexture;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.Color1;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.BBCoeffs;
                }

                if (reader.ReadBoolean())
                {
                    Lods[i].VertexDeclaration += (int)VertexFlags.DamageGroup;
                }

                //write length and then all vertices.
                lods[i].Vertices      = new Vertex[reader.ReadInt32()];
                lods[i].NumUVChannels = 4;
                for (int x = 0; x != lods[i].Vertices.Length; x++)
                {
                    Vertex vert = new Vertex();
                    vert.UVs = new Half2[lods[i].NumUVChannels];

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Position))
                    {
                        vert.Position = Vector3Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Normals))
                    {
                        vert.Normal = Vector3Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Tangent))
                    {
                        vert.Tangent = Vector3Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords0))
                    {
                        vert.UVs[0] = Half2Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords1))
                    {
                        vert.UVs[1] = Half2Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords2))
                    {
                        vert.UVs[2] = Half2Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.ShadowTexture))
                    {
                        vert.UVs[3] = Half2Extenders.ReadFromFile(reader);
                    }

                    lods[i].Vertices[x] = vert;
                }

                //write mesh count and texture names.
                Lods[i].Parts = new ModelPart[reader.ReadInt32()];
                for (int x = 0; x != Lods[i].Parts.Length; x++)
                {
                    Lods[i].Parts[x]          = new ModelPart();
                    Lods[i].Parts[x].Material = reader.ReadString();
                    ulong hash = 0;
                    ulong.TryParse(Lods[i].Parts[x].Material, out hash);
                    Lods[i].Parts[x].Hash       = hash;
                    Lods[i].Parts[x].StartIndex = reader.ReadUInt32();
                    Lods[i].Parts[x].NumFaces   = reader.ReadUInt32();
                }

                int numIndices = reader.ReadInt32();
                Lods[i].Indices = new ushort[numIndices];
                for (int x = 0; x != Lods[i].Indices.Length; x++)
                {
                    Lods[i].Indices[x] = reader.ReadUInt16();
                }

                Lods[i].CalculatePartBounds();
            }
        }
Example #26
0
        public void ReadFromFile(BinaryReader reader)
        {
            if (reader.ReadInt16() != 21569)
            {
                return;
            }

            ushort animalInsCount = reader.ReadUInt16();

            instances = new AnimalTrafficInstance[animalInsCount];

            if (reader.ReadInt32() != 1595612873)
            {
                return;
            }

            for (int i = 0; i < animalInsCount; i++)
            {
                AnimalTrafficInstance instance = new AnimalTrafficInstance();
                instance.Name = new Hash();
                instance.Name.ReadFromFile(reader);
                instances[i] = instance;
            }

            ushort pathCount = reader.ReadUInt16();

            paths = new AnimalTrafficPath[pathCount];

            for (int i = 0; i < pathCount; i++)
            {
                AnimalTrafficPath path = new AnimalTrafficPath();
                path.numPaths = reader.ReadByte();
                byte count1 = reader.ReadByte();
                byte count2 = reader.ReadByte();
                byte count3 = reader.ReadByte();
                path.unkSet0 = reader.ReadBytes(count1);
                path.unkSet1 = reader.ReadBytes(count2);
                path.unkSet2 = reader.ReadBytes(count3);
                path.bbox    = BoundingBoxExtenders.ReadFromFile(reader);
                path.unkHash = new Hash();
                path.unkHash.ReadFromFile(reader);  //decompiled exe says this is a hash but its always empty
                path.Unk0    = reader.ReadSingle(); //5
                path.Unk1    = reader.ReadSingle(); //15
                path.Unk2    = reader.ReadInt16();  //1 257 or 513.
                path.vectors = new PathVectors[path.numPaths];

                for (int x = 0; x < path.numPaths; x++)
                {
                    PathVectors vector = new PathVectors();
                    vector.vectors    = new Vector3[2];
                    vector.vectors[0] = Vector3Extenders.ReadFromFile(reader); //Very large differences between these two
                    vector.vectors[1] = Vector3Extenders.ReadFromFile(reader); //2nd one could be rotation, in radians.
                    vector.unk0       = reader.ReadByte();                     //7 or 4
                    path.vectors[x]   = vector;
                }
                if (path.Unk2 == 2)
                {
                    path.unk3 = reader.ReadByte();
                }

                paths[i] = path;
            }
        }
Example #27
0
        public void ReadFromFile(BinaryReader reader)
        {
            StreamWriter writer = File.CreateText("NAV_AI_OBJ_DATA.txt");

            unk0     = reader.ReadInt32();
            unk2     = reader.ReadInt32();
            unk3     = reader.ReadInt32();
            unk4     = reader.ReadInt32();
            vertSize = reader.ReadInt32();
            triSize  = reader.ReadInt32();
            //writer.WriteLine(string.Format("{0}, )

            //List<string> data = new List<string>();
            vertices = new VertexStruct[vertSize];
            for (int i = 0; i < vertSize; i++)
            {
                VertexStruct vertex = new VertexStruct();
                vertex.unk7     = reader.ReadUInt32() & 0x7FFFFFFF;
                vertex.position = Vector3Extenders.ReadFromFile(reader);
                //float pos = vertex.position.Y;
                //vertex.position.Y = vertex.position.Z;
                //vertex.position.Z = pos;
                vertex.unk0 = reader.ReadSingle();
                vertex.unk1 = reader.ReadSingle();
                vertex.unk2 = reader.ReadInt32();
                vertex.unk3 = reader.ReadInt16();
                vertex.unk4 = reader.ReadInt16();
                vertex.unk5 = reader.ReadInt32();
                vertex.unk6 = reader.ReadInt32();
                //data.Add(string.Format("v {0} {1} {2}", vertex.position.X, vertex.position.Z, vertex.position.Y));
                vertices[i] = vertex;
            }
            //data.Add("");
            //data.Add("g mesh");
            indices = new uint[triSize * 3];
            int index = 0;

            for (int i = 0; i < triSize; i++)
            {
                indices[index]     = reader.ReadUInt32() & 0x7FFFFFFF;
                indices[index + 1] = reader.ReadUInt32() & 0x7FFFFFFF;
                indices[index + 2] = reader.ReadUInt32() & 0x7FFFFFFF;
                //data.Add(string.Format("f {0} {1} {2}", indices[index] + 1, indices[index + 1] + 1, indices[index + 2] + 1));
                index += 3;
            }

            //KynogonRuntimeMesh
            long   mesh_pos  = reader.BaseStream.Position;
            string magicName = new string(reader.ReadChars(18));

            if (magicName != "KynogonRuntimeMesh")
            {
                throw new FormatException("Did not find KynogonRuntimeMesh");
            }

            short mesh_unk0    = reader.ReadInt16();
            int   magicVersion = reader.ReadInt32();

            if (magicVersion != 2)
            {
                throw new FormatException("Version did not equal 2");
            }

            int         mesh_unk1 = reader.ReadInt32();
            int         mesh_unk2 = reader.ReadInt32();
            BoundingBox bbox      = BoundingBoxExtenders.ReadFromFile(reader);
            int         cellSizeX = reader.ReadInt32();
            int         cellSizeY = reader.ReadInt32();
            float       radius    = reader.ReadSingle();
            int         map_unk3  = reader.ReadInt32();
            int         height    = reader.ReadInt32();
            int         offset    = reader.ReadInt32(); //this is a potential offset;

            int[]            grid     = new int[(cellSizeX * cellSizeY) + 1];
            List <UnkSet0[]> gridSets = new List <UnkSet0[]>();

            for (int i = 0; i < grid.Length; i++)
            {
                grid[i] = reader.ReadInt32();
            }

            for (int i = 0; i < grid.Length; i++)
            {
                if (i + 1 >= grid.Length)
                {
                    break;
                }

                if (i == 189)
                {
                    Console.WriteLine("st");
                }

                int       numSet0 = reader.ReadInt32();
                UnkSet0[] set0s   = new UnkSet0[numSet0];
                gridSets.Add(set0s);

                writer.WriteLine("-----------------------");
                writer.WriteLine(string.Format("{0} {1}", i, numSet0));
                writer.WriteLine("");

                if (numSet0 == 0)
                {
                    continue;
                }

                //NOTE: EVERY OFFSET IN UNKSET0 BEGINS FROM MESH_POS HIGHER IN THE CODE FILE.
                int offset0 = reader.ReadInt32();

                for (int x = 0; x < numSet0; x++)
                {
                    UnkSet0 set = new UnkSet0();
                    set.X      = reader.ReadSingle();
                    set.Y      = reader.ReadSingle();
                    set.Offset = reader.ReadInt32();
                    set0s[x]   = set;
                }

                //NOTE: EVERY BLOCK OF DATA SEEMS TO START WITH 96, THIS IS HOWEVER UNCONFIRMED.
                for (int z = 0; z < numSet0; z++)
                {
                    UnkSet0 set = set0s[z];
                    //NOTE: MOST OF THE OFFSETS BEGIN HERE, JUST AFTER THE SETS HAVE BEEN DEFINED ABOVE.
                    set.cellUnk0 = reader.ReadInt32();

                    if (set.cellUnk0 != mesh_unk2)
                    {
                        throw new FormatException();
                    }
                    writer.WriteLine("");
                    set.cellUnk1  = reader.ReadInt32();
                    set.cellUnk2  = reader.ReadInt32();
                    set.cellUnk3  = reader.ReadInt32();
                    set.cellUnk4  = reader.ReadSingle();
                    set.cellUnk5  = reader.ReadSingle();
                    set.cellUnk6  = reader.ReadSingle();
                    set.cellUnk7  = reader.ReadSingle();
                    set.cellUnk8  = reader.ReadInt32();
                    set.cellUnk9  = reader.ReadInt32(); //-1?
                    set.cellUnk10 = reader.ReadInt32(); //1;
                    set.cellUnk11 = reader.ReadInt32();
                    set.cellUnk12 = reader.ReadInt32(); //0
                    set.cellUnk13 = reader.ReadInt32(); //-1;
                    set.cellUnk14 = reader.ReadInt32(); //0
                    set.cellUnk15 = reader.ReadInt32(); //-1;
                    set.cellUnk16 = reader.ReadInt32(); //8;
                    set.cellUnk17 = reader.ReadInt32(); //112;
                    set.cellUnk18 = reader.ReadInt32(); //0;
                    set.cellUnk19 = reader.ReadInt32(); //-1;
                    writer.WriteLine(string.Format("Unk1: {0}", set.cellUnk1));
                    writer.WriteLine(string.Format("Unk2: {0}", set.cellUnk2));
                    writer.WriteLine(string.Format("Unk3: {0}", set.cellUnk3));
                    writer.WriteLine(string.Format("Unk4: {0}", set.cellUnk4));
                    writer.WriteLine(string.Format("Unk5: {0}", set.cellUnk5));
                    writer.WriteLine(string.Format("Unk6: {0}", set.cellUnk6));
                    writer.WriteLine(string.Format("Unk7: {0}", set.cellUnk7));
                    writer.WriteLine(string.Format("Unk8: {0}", set.cellUnk8));
                    writer.WriteLine(string.Format("Unk9: {0}", set.cellUnk9));
                    writer.WriteLine(string.Format("Unk10: {0}", set.cellUnk10));
                    writer.WriteLine(string.Format("Unk11: {0}", set.cellUnk11));
                    writer.WriteLine(string.Format("Unk12: {0}", set.cellUnk12));
                    writer.WriteLine(string.Format("Unk13: {0}", set.cellUnk13));
                    writer.WriteLine(string.Format("Unk14: {0}", set.cellUnk14));
                    writer.WriteLine(string.Format("Unk15: {0}", set.cellUnk15));
                    writer.WriteLine(string.Format("Unk16: {0}", set.cellUnk16));
                    writer.WriteLine(string.Format("Unk17: {0}", set.cellUnk17));
                    writer.WriteLine(string.Format("Unk18: {0}", set.cellUnk18));
                    writer.WriteLine(string.Format("Unk19: {0}", set.cellUnk19));
                    writer.WriteLine("");
                    //THIS BIT IS UNKNOWN, UPTO CELLUNK20
                    set.unk10Boxes = new Unk10DataSet[set.cellUnk10];
                    writer.WriteLine("Unk10 Boxes");
                    for (int x = 0; x < set.cellUnk10; x++)
                    {
                        Unk10DataSet unk10Set = new Unk10DataSet();
                        unk10Set.B1        = BoundingBoxExtenders.ReadFromFile(reader);
                        unk10Set.UnkOffset = reader.ReadInt32();
                        unk10Set.Unk20     = reader.ReadInt32();
                        set.unk10Boxes[x]  = unk10Set;
                        writer.WriteLine(string.Format("Minimum: {0} ", unk10Set.B1.Minimum.ToString()));
                        writer.WriteLine(string.Format("Maximum: {0} ", unk10Set.B1.Maximum.ToString()));
                        writer.WriteLine(string.Format("UnkOffset: {0} ", unk10Set.UnkOffset));
                        writer.WriteLine(string.Format("Unk20: {0} ", unk10Set.Unk20));
                        writer.WriteLine("");
                    }
                    //END OF CONFUSING BIT.


                    //THIS BIT IS UNKNOWN, BUT IS CELLUNK12
                    set.unk12Boxes = new Unk12DataSet[set.cellUnk12];
                    writer.WriteLine("Unk12 Boxes");
                    for (int x = 0; x < set.cellUnk12; x++)
                    {
                        Unk12DataSet unk12Set = new Unk12DataSet();
                        unk12Set.B1       = BoundingBoxExtenders.ReadFromFile(reader);
                        unk12Set.Unk01    = reader.ReadInt32();
                        unk12Set.Unk02    = reader.ReadInt32();
                        unk12Set.Unk03    = reader.ReadSingle();
                        unk12Set.Unk04    = reader.ReadSingle();
                        unk12Set.Unk05    = reader.ReadSingle();
                        set.unk12Boxes[x] = unk12Set;
                        writer.WriteLine(string.Format("Minimum: {0} ", unk12Set.B1.Minimum.ToString()));
                        writer.WriteLine(string.Format("Maximum: {0} ", unk12Set.B1.Maximum.ToString()));
                        writer.WriteLine(string.Format("Unk01: {0} ", unk12Set.Unk01));
                        writer.WriteLine(string.Format("Unk02: {0} ", unk12Set.Unk02));
                        writer.WriteLine(string.Format("Unk03: {0} ", unk12Set.Unk03));
                        writer.WriteLine(string.Format("Unk04: {0} ", unk12Set.Unk04));
                        writer.WriteLine(string.Format("Unk05: {0} ", unk12Set.Unk05));
                        writer.WriteLine("");
                    }

                    //END OF CONFUSING BIT.

                    //THIS LOOPS THROUGH OFFSETS TO BBOX'S
                    writer.WriteLine("Unk14 Offsets");
                    set.unk14Offsets = new int[set.cellUnk14];
                    for (int x = 0; x < set.cellUnk14; x++)
                    {
                        set.unk14Offsets[x] = reader.ReadInt32();
                        writer.WriteLine(string.Format("{0} ", set.unk14Offsets[x]));
                    }

                    //ALWAYS A 4-BYTE INTEGER WHICH DENOTES THE END OF THE BATCH
                    if (set.cellUnk14 > 0)
                    {
                        set.unk14End = reader.ReadInt32();
                    }

                    if (set.cellUnk14 > 0)
                    {
                        set.unk14Data = reader.ReadBytes(set.unk14End - set.unk14Offsets[0]);
                    }
                    writer.WriteLine("");

                    //set.unk14Boxes = new BoundingBox[set.cellUnk14];
                    //writer.WriteLine("Unk14 Boxes");
                    //for (int x = 0; x < set.cellUnk14; x++)
                    //{
                    //    set.unk14Boxes[x] = BoundingBoxExtenders.ReadFromFile(reader);
                    //    writer.WriteLine(string.Format("{0} ", set.unk14Boxes[x].ToString()));
                    //}
                    //writer.WriteLine("");



                    //CONTINUE ONTO THE NEXT BATCH
                    set.unk16Offsets = new int[set.cellUnk16];
                    writer.WriteLine("Unk16 Offsets");
                    for (int x = 0; x < set.cellUnk16; x++)
                    {
                        set.unk16Offsets[x] = reader.ReadInt32();
                        writer.WriteLine(string.Format("{0} ", set.unk16Offsets[x]));
                    }
                    writer.WriteLine("");
                    //ALWAYS A 4-BYTE INTEGER WHICH DENOTES THE END OF THE BATCH
                    if (set.cellUnk16 > 0)
                    {
                        set.unk16End = reader.ReadInt32();
                    }

                    set.unk16Boxes = new BoundingBox[set.cellUnk16];
                    writer.WriteLine("Unk16 Boxes");
                    for (int x = 0; x < set.cellUnk16; x++)
                    {
                        set.unk16Boxes[x] = BoundingBoxExtenders.ReadFromFile(reader);
                        writer.WriteLine(string.Format("{0} ", set.unk16Boxes[x]));
                    }
                    writer.WriteLine("");
                    if (set.cellUnk18 > 1)
                    {
                        throw new FormatException();
                    }

                    set.unk18Set = new Unk18DataSet[set.cellUnk18];
                    writer.WriteLine("Unk18 Boxes");
                    for (int x = 0; x < set.cellUnk18; x++)
                    {
                        //THIS COULD BE AN OFFSET LIST WITH SOMEKIND OF FLOAT/ROTATION DATA
                        Unk18DataSet dataSet = new Unk18DataSet();
                        dataSet.Unk0 = reader.ReadInt32();
                        dataSet.Unk1 = reader.ReadSingle();
                        dataSet.Unk2 = reader.ReadSingle();
                        dataSet.Unk3 = reader.ReadSingle();

                        //THIS COULD BE THE FINAL AREA WITH THE 12 BYTES SIMPLY PADDING OUT
                        dataSet.Unk4 = reader.ReadInt32();
                        dataSet.Unk5 = reader.ReadBytes(12);

                        //BOUNDING BOX FOR THIS KIND OF DATA.
                        dataSet.B1      = BoundingBoxExtenders.ReadFromFile(reader);
                        dataSet.B2      = BoundingBoxExtenders.ReadFromFile(reader);
                        dataSet.B3      = BoundingBoxExtenders.ReadFromFile(reader);
                        set.unk18Set[x] = dataSet;


                        writer.WriteLine(string.Format("Unk01: {0} ", dataSet.Unk1));
                        writer.WriteLine(string.Format("Unk02: {0} ", dataSet.Unk2));
                        writer.WriteLine(string.Format("Unk03: {0} ", dataSet.Unk3));
                        writer.WriteLine(string.Format("Unk04: {0} ", dataSet.Unk4));
                        writer.WriteLine(string.Format("Unk05: {0} ", dataSet.Unk5));
                        writer.WriteLine(string.Format("Minimum: {0} ", dataSet.B1.Minimum.ToString()));
                        writer.WriteLine(string.Format("Maximum: {0} ", dataSet.B1.Maximum.ToString()));
                        writer.WriteLine(string.Format("Minimum: {0} ", dataSet.B2.Minimum.ToString()));
                        writer.WriteLine(string.Format("Maximum: {0} ", dataSet.B2.Maximum.ToString()));
                        writer.WriteLine(string.Format("Minimum: {0} ", dataSet.B3.Minimum.ToString()));
                        writer.WriteLine(string.Format("Maximum: {0} ", dataSet.B3.Maximum.ToString()));
                    }
                    writer.WriteLine("");
                    set0s[z] = set;
                }
                Console.WriteLine("Completed: " + i);
                //byte[] data = reader.ReadBytes(size);
                //File.WriteAllBytes("grid_" + i + ".bin", data);
            }


            //File.WriteAllLines("model.obj", data.ToArray());
        }
Example #28
0
 public void ReadFromFile(BinaryReader reader)
 {
     Position = Vector3Extenders.ReadFromFile(reader);
     Rotation = QuaternionExtensions.ReadFromFile(reader);
     Scale    = Vector3Extenders.ReadFromFile(reader);
 }
Example #29
0
        private void ReadM2TVersionTwo(BinaryReader reader)
        {
            //mesh name
            name = reader.ReadString();

            isSkinned = reader.ReadBoolean();
            if (isSkinned)
            {
                byte size = reader.ReadByte();
                skeleton        = new Skeleton();
                skeleton.Joints = new Joint[size];
                for (int i = 0; i < size; i++)
                {
                    Joint joint = new Joint();
                    joint.Name        = reader.ReadString8();
                    joint.ParentIndex = reader.ReadByte();
                    joint.Parent      = (joint.ParentIndex != 0xFF) ? skeleton.Joints[joint.ParentIndex] : null; //may crash because root will not be in range
                    Vector3    position = Vector3Extenders.ReadFromFile(reader);
                    Quaternion rotation = QuaternionExtensions.ReadFromFile(reader);
                    Vector3    scale    = Vector3Extenders.ReadFromFile(reader);
                    joint.WorldTransform = MatrixExtensions.SetMatrix(rotation, scale, position);
                    skeleton.Joints[i]   = joint;
                }
            }

            //Number of Lods
            Lods = new Lod[reader.ReadByte()];

            for (int i = 0; i != Lods.Length; i++)
            {
                Lods[i] = new Lod
                {
                    VertexDeclaration = 0
                };

                lods[i].VertexDeclaration = (VertexFlags)reader.ReadInt32();

                //write length and then all vertices.
                lods[i].Vertices = new Vertex[reader.ReadInt32()];
                for (int x = 0; x != lods[i].Vertices.Length; x++)
                {
                    Vertex vert = new Vertex();
                    vert.UVs = new Half2[4];

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Position))
                    {
                        vert.Position = Vector3Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Normals))
                    {
                        vert.Normal = Vector3Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Tangent))
                    {
                        vert.Tangent = Vector3Extenders.ReadFromFile(reader);
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Skin))
                    {
                        vert.BoneIDs     = reader.ReadBytes(4);
                        vert.BoneWeights = new float[4];
                        for (int z = 0; z < 4; z++)
                        {
                            vert.BoneWeights[z] = reader.ReadSingle();
                        }
                    }

                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Color))
                    {
                        vert.Color0 = reader.ReadBytes(4);
                    }
                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.Color1))
                    {
                        vert.Color1 = reader.ReadBytes(4);
                    }
                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords0))
                    {
                        vert.UVs[0] = Half2Extenders.ReadFromFile(reader);
                    }
                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords1))
                    {
                        vert.UVs[1] = Half2Extenders.ReadFromFile(reader);
                    }
                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords2))
                    {
                        vert.UVs[2] = Half2Extenders.ReadFromFile(reader);
                    }
                    if (Lods[i].VertexDeclaration.HasFlag(VertexFlags.ShadowTexture))
                    {
                        vert.UVs[3] = Half2Extenders.ReadFromFile(reader);
                    }
                    lods[i].Vertices[x] = vert;
                }

                //read mesh count and texture names.
                Lods[i].Parts = new ModelPart[reader.ReadInt32()];
                for (int x = 0; x != Lods[i].Parts.Length; x++)
                {
                    Lods[i].Parts[x]            = new ModelPart();
                    Lods[i].Parts[x].Material   = reader.ReadString();
                    Lods[i].Parts[x].StartIndex = reader.ReadUInt32();
                    Lods[i].Parts[x].NumFaces   = reader.ReadUInt32();

                    var material = MaterialsManager.LookupMaterialByName(Lods[i].Parts[x].Material);

                    if (material != null)
                    {
                        Lods[i].Parts[x].Hash = material.GetMaterialHash();
                    }
                }

                int numIndices = reader.ReadInt32();
                Lods[i].Indices = new uint[numIndices];
                for (int x = 0; x != Lods[i].Indices.Length; x++)
                {
                    Lods[i].Indices[x] = reader.ReadUInt32();
                }
                Lods[i].CalculatePartBounds();
            }
        }
Example #30
0
        public void ReadFromFile(BinaryReader reader)
        {
            version  = reader.ReadInt32();
            unk1     = reader.ReadInt32();
            unk2     = reader.ReadInt16();
            bounds   = BoundingBoxExtenders.ReadFromFile(reader);
            numGrids = reader.ReadInt32();

            Grids = new Grid[numGrids];

            for (int i = 0; i < numGrids; i++)
            {
                Grid grid = new Grid();
                grid.Key      = reader.ReadInt16();
                grid.Origin   = Vector3Extenders.ReadFromFile(reader);
                grid.CellSize = Vector2Extenders.ReadFromFile(reader);
                grid.Width    = reader.ReadInt32();
                grid.Height   = reader.ReadInt32();
                grid.Data     = new ushort[grid.Width * grid.Height];

                for (int y = 0; y != grid.Data.Length; y++)
                {
                    grid.Data[y] = reader.ReadUInt16();
                }

                Grids[i] = grid;
            }

            numUnk3 = reader.ReadInt32();
            unk3    = new short[numUnk3 * 2];

            for (int i = 0; i < numUnk3 * 2; i++)
            {
                unk3[i] = reader.ReadInt16();
            }

            numObjectGroups = reader.ReadInt32();
            ObjectGroups    = new ObjectGroup[numObjectGroups];

            for (int i = 0; i != numObjectGroups; i++)
            {
                ObjectGroup objectGroup = new ObjectGroup();
                objectGroup.Unk01      = reader.ReadInt16();
                objectGroup.NumObjects = reader.ReadInt32();
                objectGroup.Objects    = new Object[objectGroup.NumObjects];

                for (int x = 0; x != objectGroup.NumObjects; x++)
                {
                    Object obj = new Object();
                    obj.NumInstance2 = reader.ReadInt16();
                    obj.Unk02        = reader.ReadInt16();

                    obj.Name = new HashName();
                    ulong hashvalue = reader.ReadUInt64();
                    obj.Name.Hash   = hashvalue;
                    obj.Name.String = StringHelpers.ReadString(reader);
                    Debug.Assert(obj.Name.Hash == hashvalue, "Object Hash and Name should be identical");

                    obj.UnkBytes1    = reader.ReadBytes(31 - obj.Name.ToString().Length);
                    obj.GridMax      = reader.ReadSingle();
                    obj.GridMin      = reader.ReadSingle();
                    obj.NumInstances = reader.ReadInt32();
                    obj.Instances    = new Instance[obj.NumInstances];

                    for (int y = 0; y != obj.NumInstances; y++)
                    {
                        byte[]   packed   = reader.ReadBytes(14);
                        Instance instance = new Instance();
                        instance.W0 = BitConverter.ToUInt16(packed, 0);
                        instance.W1 = BitConverter.ToUInt16(packed, 2);
                        instance.W2 = BitConverter.ToUInt16(packed, 4);
                        instance.D5 = BitConverter.ToInt32(packed, 6);
                        instance.ID = BitConverter.ToUInt16(packed, 10);
                        instance.D4 = BitConverter.ToUInt16(packed, 12);
                        DecompressScale(instance);
                        DecompressRotation(instance);
                        instance.Position = DecompressPosition(packed, instance, bounds.Minimum, bounds.Maximum);
                        obj.Instances[y]  = instance;
                    }
                    objectGroup.Objects[x] = obj;
                }
                ObjectGroups[i] = objectGroup;
            }
        }