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 = Vector3Utils.ReadFromFile(reader); //Very large differences between these two
                    vector.Rotation = Vector3Utils.ReadFromFile(reader); //2nd one could be rotation, in radians.
                    vector.Unk0     = reader.ReadByte();                 //7 or 4
                    path.Vectors[x] = vector;
                }


                paths[i] = path;
            }
        }
 public override void ReadFromFile(MemoryStream reader, bool isBigEndian)
 {
     base.ReadFromFile(reader, isBigEndian);
     flags         = (SingleMeshFlags)reader.ReadInt32(isBigEndian);
     bounds        = BoundingBoxExtenders.ReadFromFile(reader, isBigEndian);
     unk14         = reader.ReadByte8();
     meshIndex     = reader.ReadInt32(isBigEndian);
     materialIndex = reader.ReadInt32(isBigEndian);
     omTextureHash = new HashName(reader, isBigEndian);
     unk18_1       = reader.ReadByte8();
     unk18_2       = reader.ReadByte8();
     unk18_3       = reader.ReadByte8();
 }
Example #3
0
        public override void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            base.ReadFromFile(reader, isBigEndian);
            unk01      = 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);
        }
Example #4
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 = Vector3Utils.ReadFromFile(reader, isBigEndian);
            unk_14_vector3 = Vector3Utils.ReadFromFile(reader, isBigEndian);
            sectorName     = new HashName(reader, isBigEndian);
        }
        public void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            int  numBones = reader.ReadInt32(isBigEndian);
            byte numLods  = reader.ReadByte8();

            //index infos
            boneIndexInfos = new BoneIndexInfo[numLods];
            for (int i = 0; i != boneIndexInfos.Length; i++)
            {
                boneIndexInfos[i].NumIDs       = reader.ReadInt32(isBigEndian);
                boneIndexInfos[i].NumMaterials = reader.ReadInt32(isBigEndian);
            }

            //bounds for all bones together?
            bounds = BoundingBoxExtenders.ReadFromFile(reader, isBigEndian);

            //Bone Transforms
            boneTransforms = new BoneTransform[numBones];
            for (int i = 0; i != boneTransforms.Length; i++)
            {
                boneTransforms[i] = new BoneTransform();
                boneTransforms[i].ReadFromFile(reader, isBigEndian);
            }

            for (int i = 0; i != boneIndexInfos.Length; i++)
            {
                boneIndexInfos[i].BonesPerPool = reader.ReadBytes(8);

                //IDs..
                boneIndexInfos[i].IDs = reader.ReadBytes(boneIndexInfos[i].NumIDs);

                //Material blendings..
                boneIndexInfos[i].MatBlends           = new ushort[boneIndexInfos[i].NumMaterials];
                boneIndexInfos[i].BonesSlot           = new byte[boneIndexInfos[i].NumMaterials];
                boneIndexInfos[i].NumWeightsPerVertex = new int[boneIndexInfos[i].NumMaterials];
                for (int x = 0; x != boneIndexInfos[i].NumMaterials; x++)
                {
                    boneIndexInfos[i].MatBlends[x] = reader.ReadUInt16(isBigEndian);
                    ushort value = boneIndexInfos[i].MatBlends[x];
                    boneIndexInfos[i].BonesSlot[x]           = (byte)(value & 0xFF);
                    boneIndexInfos[i].NumWeightsPerVertex[x] = (value >> 8);
                }
            }
        }
Example #6
0
        public void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            numLods     = reader.ReadByte8();
            lodMatCount = new int[numLods];
            for (int i = 0; i != numLods; i++)
            {
                lodMatCount[i] = reader.ReadInt32(isBigEndian);
            }

            materials = new List <MaterialStruct[]>();

            bounds = BoundingBoxExtenders.ReadFromFile(reader, isBigEndian);

            for (int i = 0; i != numLods; i++)
            {
                MaterialStruct[] array = new MaterialStruct[lodMatCount[i]];
                for (int d = 0; d != array.Length; d++)
                {
                    array[d] = new MaterialStruct(reader, isBigEndian);
                }
                materials.Add(array);
            }
        }
Example #7
0
            public void ReadFromFile(BinaryReader reader)
            {
                nxs   = new string(reader.ReadChars(4));
                mesh  = new string(reader.ReadChars(4));
                ver   = reader.ReadInt32();
                flags = (MeshSerialFlags)reader.ReadInt32();
                convexEdgeThreshold = reader.ReadSingle();
                maxVertices         = reader.ReadInt32();
                num4 = reader.ReadInt32();

                nPoints    = reader.ReadInt32();
                nTriangles = reader.ReadInt32();

                points    = new Vector3[nPoints];
                indices   = new uint[nTriangles * 3];
                materials = new CollisionMaterials[nTriangles];

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

                if (flags.HasFlag(MeshSerialFlags.MSF_8BIT_INDICES))
                {
                    for (int i = 0; i != indices.Length; i++)
                    {
                        indices[i] = reader.ReadByte();
                    }
                }
                else if (flags.HasFlag(MeshSerialFlags.MSF_16BIT_INDICES))
                {
                    for (int i = 0; i != indices.Length; i++)
                    {
                        indices[i] = reader.ReadUInt16();
                    }
                }
                else
                {
                    for (int i = 0; i != indices.Length; i++)
                    {
                        indices[i] = reader.ReadUInt32();
                    }
                }

                if (flags.HasFlag(MeshSerialFlags.MSF_MATERIALS))
                {
                    for (int i = 0; i != materials.Length; i++)
                    {
                        materials[i] = (CollisionMaterials)reader.ReadInt16();
                    }
                }

                if (flags.HasFlag(MeshSerialFlags.MSF_FACE_REMAP))
                {
                    max       = reader.ReadInt32();
                    remapData = new int[nTriangles];

                    for (int i = 0; i < nTriangles; i++)
                    {
                        if (max > 0xFFFF)
                        {
                            remapData[i] = reader.ReadInt32();
                        }
                        else if (max > 0xFF)
                        {
                            remapData[i] = reader.ReadInt16();
                        }
                        else
                        {
                            remapData[i] = reader.ReadByte();
                        }
                    }
                }

                numConvexParts = reader.ReadInt32();
                numFlatParts   = reader.ReadInt32();

                if (numConvexParts > 0)
                {
                    convexParts = new short[nTriangles];
                    for (int i = 0; i != nTriangles; i++)
                    {
                        convexParts[i] = reader.ReadInt16();
                    }
                }
                if (numFlatParts > 0)
                {
                    if (numFlatParts < 256)
                    {
                        flatParts = new short[nTriangles];
                        for (int i = 0; i != nTriangles; i++)
                        {
                            flatParts[i] = reader.ReadByte();
                        }
                    }
                    else
                    {
                        flatParts = new short[nTriangles];
                        for (int i = 0; i != nTriangles; i++)
                        {
                            flatParts[i] = reader.ReadInt16();
                        }
                    }
                }

                opcHbmData = new HBMOPCDataClass(reader);

                unkFloats    = new float[14];
                unkFloats[0] = reader.ReadSingle();

                boundingSphere = BoundingSphereExtenders.ReadFromFile(reader);
                boundingBox    = BoundingBoxExtenders.ReadFromFile(reader);

                for (int i = 1; i != unkFloats.Length; i++)
                {
                    unkFloats[i] = reader.ReadSingle();
                }

                unkSize     = reader.ReadInt32();
                unkSizeData = reader.ReadBytes(unkSize);

                if (unkSize != nTriangles)
                {
                    throw new FormatException("UnkSize does not equal nTriangles:");
                }
            }
Example #8
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.Hash         = reader.ReadUInt64();
                    obj.Name         = StringHelpers.ReadString(reader);
                    obj.UnkBytes1    = reader.ReadBytes(31 - obj.Name.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);

                        if (!IDs.Contains(instance.ID))
                        {
                            IDs.Add(instance.ID);
                        }
                        else
                        {
                            Console.WriteLine("Duplication!! {0} {1}", obj.Name, instance.ID);
                        }

                        DecompressScale(instance);
                        DecompressRotation(instance);
                        instance.Position = DecompressPosition(packed, instance, bounds.Minimum, bounds.Maximum);
                        obj.Instances[y]  = instance;
                    }
                    objectGroup.Objects[x] = obj;
                }
                ObjectGroups[i] = objectGroup;
            }
            IDs.Sort();
        }
Example #9
0
        public override void ReadFromFile(MemoryStream reader, bool bIsBigEndian)
        {
            base.ReadFromFile(reader, bIsBigEndian);

            Flags             = reader.ReadInt32(bIsBigEndian);
            LUnk0             = reader.ReadSingle(bIsBigEndian);
            LUnk1             = reader.ReadSingle(bIsBigEndian);
            LUnk2             = reader.ReadSingle(bIsBigEndian);
            LUnk3             = reader.ReadSingle(bIsBigEndian);
            LUnk4             = reader.ReadSingle(bIsBigEndian);
            LUnk5             = reader.ReadSingle(bIsBigEndian);
            LUnk6             = reader.ReadSingle(bIsBigEndian);
            UnkInt1           = reader.ReadInt32(bIsBigEndian);
            UnkVector_0       = Vector3Utils.ReadFromFile(reader, bIsBigEndian);
            LUnk7             = reader.ReadSingle(bIsBigEndian);
            LUnk8             = reader.ReadSingle(bIsBigEndian);
            UnkByte1          = reader.ReadByte8();
            LUnk9             = reader.ReadSingle(bIsBigEndian);
            LUnk10            = reader.ReadSingle(bIsBigEndian);
            LUnk11            = reader.ReadSingle(bIsBigEndian);
            LUnk12            = reader.ReadSingle(bIsBigEndian);
            UnkVector_1       = Vector3Utils.ReadFromFile(reader, bIsBigEndian);
            UnkVector_2       = Vector3Utils.ReadFromFile(reader, bIsBigEndian);
            LUnk13            = reader.ReadSingle(bIsBigEndian);
            UnkVector_3       = Vector3Utils.ReadFromFile(reader, bIsBigEndian);
            LUnk14            = reader.ReadSingle(bIsBigEndian);
            LUnk15            = reader.ReadSingle(bIsBigEndian);
            LUnk16            = reader.ReadSingle(bIsBigEndian);
            UnkByte2          = reader.ReadByte8();
            LUnk17            = reader.ReadSingle(bIsBigEndian);
            LUnk18            = reader.ReadSingle(bIsBigEndian);
            LUnk19            = reader.ReadSingle(bIsBigEndian);
            LUnk20            = reader.ReadSingle(bIsBigEndian);
            LUnk21            = reader.ReadSingle(bIsBigEndian);
            ProjectionTexture = new HashName(reader, bIsBigEndian);
            UnkInt2           = reader.ReadInt32(bIsBigEndian);
            LUnk22            = reader.ReadSingle(bIsBigEndian);
            LUnk23            = reader.ReadSingle(bIsBigEndian);
            UnkVector_4       = Vector3Utils.ReadFromFile(reader, bIsBigEndian);
            LUnk24            = reader.ReadSingle(bIsBigEndian);
            LUnk25            = reader.ReadSingle(bIsBigEndian);
            LUnk26            = reader.ReadSingle(bIsBigEndian);
            LUnk27            = reader.ReadSingle(bIsBigEndian);
            LUnk28            = reader.ReadSingle(bIsBigEndian);
            UnkVector_5       = Vector3Utils.ReadFromFile(reader, bIsBigEndian);
            LUnk29            = reader.ReadSingle(bIsBigEndian);
            LUnk30            = reader.ReadSingle(bIsBigEndian);
            LUnk31            = reader.ReadSingle(bIsBigEndian);
            LUnk32            = reader.ReadSingle(bIsBigEndian);
            LUnk33            = reader.ReadSingle(bIsBigEndian);
            LUnk34            = reader.ReadSingle(bIsBigEndian);
            LUnk35            = reader.ReadSingle(bIsBigEndian);

            // Read Textures
            for (int i = 0; i < 4; i++)
            {
                TextureHashes[i] = new HashName(reader, bIsBigEndian);
            }

            UnkBox        = BoundingBoxExtenders.ReadFromFile(reader, bIsBigEndian);
            UnkByte3      = reader.ReadByte8();
            UnknownMatrix = MatrixUtils.ReadFromFile(reader, bIsBigEndian);
        }
Example #10
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 #11
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;
            }
        }
Example #12
0
 public override void ReadFromFile(MemoryStream reader, bool isBigEndian)
 {
     base.ReadFromFile(reader, isBigEndian);
     bounds = BoundingBoxExtenders.ReadFromFile(reader, isBigEndian);
 }
Example #13
0
        public void ReadFromFile(BinaryReader reader)
        {
            //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");
            }

            Unk0 = reader.ReadInt32();
            Unk1 = reader.ReadInt32();
            Unk2 = reader.ReadSingle();
            Unk3 = reader.ReadSingle();

            float boundMinX = reader.ReadSingle();
            float boundMaxX = reader.ReadSingle();
            float boundMaxY = -reader.ReadSingle();
            float boundMinY = -reader.ReadSingle();

            BoundMin = new Vector2(boundMinX, boundMinY);
            BoundMax = new Vector2(boundMaxX, boundMaxY);

            //BoundingBox = BoundingBoxExtenders.ReadFromFile(reader);
            CellSizeX = reader.ReadInt32();
            CellSizeY = reader.ReadInt32();
            Radius    = reader.ReadSingle();
            Unk4      = reader.ReadInt32();
            Height    = reader.ReadInt32();
            Offset    = reader.ReadInt32(); //this is a potential offset;
            Grid      = new int[(CellSizeX * CellSizeY)];
            Cells     = new Cell[Grid.Length];

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

            int end   = reader.ReadInt32();
            int Count = 0;

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

                Cell cell    = new Cell();
                int  numSet0 = reader.ReadInt32();
                cell.Sets = new UnkSet0[numSet0];
                Cells[i]  = cell;

                if (numSet0 == 0)
                {
                    continue;
                }

                //NOTE: EVERY OFFSET IN UNKSET0 BEGINS FROM MESH_POS HIGHER IN THE CODE FILE.
                cell.Offset = reader.ReadInt32(); /// start offset (excluding sets)

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

                //NOTE: EVERY BLOCK OF DATA SEEMS TO START WITH 96, THIS IS HOWEVER UNCONFIRMED.
                for (int z = 0; z < numSet0; z++)
                {
                    long set_offset = reader.BaseStream.Position - mesh_pos;

                    UnkSet0 set = cell.Sets[z];
                    //NOTE: MOST OF THE OFFSETS BEGIN HERE, JUST AFTER THE SETS HAVE BEEN DEFINED ABOVE.
                    set.cellUnk0 = reader.ReadInt32();

                    if (set.cellUnk0 != Unk1)
                    {
                        throw new FormatException();
                    }

                    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.NumUnk10Boxes = reader.ReadInt32(); //1;
                    set.cellUnk11     = reader.ReadInt32(); // offset is start - setpos
                    set.NumUnk12Boxes = reader.ReadInt32(); //0
                    set.cellUnk13     = reader.ReadInt32(); // offset is start - setpos
                    set.NumUn14Boxes  = reader.ReadInt32(); //0
                    set.cellUnk15     = reader.ReadInt32(); // offset is start - setpos
                    set.NumEdges      = reader.ReadInt32(); //8;
                    set.cellUnk17     = reader.ReadInt32(); // offset is start - setpos
                    set.NumUnk18Boxes = reader.ReadInt32(); //0;
                    set.cellUnk19     = reader.ReadInt32(); // offset is start - setpos

                    Count += set.NumUnk12Boxes;

                    // First set of boxes
                    set.unk10Boxes = new Unk10DataSet[set.NumUnk10Boxes];
                    for (int x = 0; x < set.NumUnk10Boxes; x++)
                    {
                        Unk10DataSet unk10Set = new Unk10DataSet();
                        unk10Set.B1        = BoundingBoxExtenders.ReadFromFile(reader);
                        unk10Set.UnkOffset = reader.ReadInt32(); // offset is next set in next cell?

                        //  Linked cell?
                        unk10Set.Unk20    = reader.ReadInt32(); // really unsure on what this is
                        set.unk10Boxes[x] = unk10Set;
                    }

                    // 2nd set of boxes
                    set.unk12Boxes = new Unk12DataSet[set.NumUnk12Boxes];
                    for (int x = 0; x < set.NumUnk12Boxes; 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;
                    }

                    // 3rd set of boxes, but these are offsets
                    set.unk14Boxes = new Unk14DataSet[set.NumUn14Boxes];
                    for (int x = 0; x < set.NumUn14Boxes; x++)
                    {
                        var dataSet = new Unk14DataSet();
                        dataSet.Offset = reader.ReadInt32();

                        set.unk14Boxes[x] = dataSet;
                    }

                    // 4th set of boxes, based on the offsets above.
                    if (set.NumUn14Boxes > 0)
                    {
                        set.unk14End = reader.ReadInt32();
                        var currentOffset = set.unk14Boxes[0].Offset;
                        for (int x = 0; x < set.NumUn14Boxes; x++)
                        {
                            var dataSet = set.unk14Boxes[x];
                            var offset  = (x + 1 < set.NumUn14Boxes ? set.unk14Boxes[x + 1].Offset : set.unk14End);
                            var size    = offset - currentOffset;
                            currentOffset = offset;
                            var count = size / 12;
                            dataSet.Points = new Vector3[count];

                            for (int f = 0; f < dataSet.Points.Length; f++)
                            {
                                dataSet.Points[f] = Vector3Utils.ReadFromFile(reader);
                            }

                            set.unk14Boxes[x] = dataSet;
                        }
                    }

                    // 5th set of boxes
                    set.unk16Offsets = new int[set.NumEdges];
                    for (int x = 0; x < set.NumEdges; x++)
                    {
                        set.unk16Offsets[x] = reader.ReadInt32(); // bounding box position - set_pos
                    }

                    //ALWAYS A 4-BYTE INTEGER WHICH DENOTES THE END OF THE BATCH
                    if (set.NumEdges > 0)
                    {
                        set.EdgesDataEndOffset = reader.ReadInt32(); // very end of set_pos
                    }

                    // 6th set of boxes
                    set.EdgeBoxes = new BoundingBox[set.NumEdges];
                    for (int x = 0; x < set.NumEdges; x++)
                    {
                        set.EdgeBoxes[x] = BoundingBoxExtenders.ReadFromFile(reader);
                    }

                    // 7th set of boxes
                    set.unk18Set = new Unk18DataSet[set.NumUnk18Boxes];
                    if (set.NumUnk18Boxes > 0)
                    {
                        set.unk18End = reader.ReadInt32();
                        for (int x = 0; x < set.NumUnk18Boxes; x++)
                        {
                            Unk18DataSet dataSet = new Unk18DataSet();
                            dataSet.Unk0   = reader.ReadSingle();
                            dataSet.Unk1   = reader.ReadSingle();
                            dataSet.Unk2   = reader.ReadSingle();
                            dataSet.Offset = reader.ReadInt32();

                            set.unk18Set[x] = dataSet;
                        }

                        byte[] unknown_data = reader.ReadBytes(12); //usually padding

                        var currentOffset = set.unk18End;
                        for (int x = 0; x < set.NumUnk18Boxes; x++)
                        {
                            var dataSet = set.unk18Set[x];
                            var size    = dataSet.Offset - currentOffset;
                            var count   = size / 12;
                            dataSet.Points = new Vector3[count];

                            for (int f = 0; f < dataSet.Points.Length; f++)
                            {
                                dataSet.Points[f] = Vector3Utils.ReadFromFile(reader);
                            }

                            currentOffset   = dataSet.Offset;
                            set.unk18Set[x] = dataSet;
                        }
                    }

                    cell.Sets[z] = set;
                }
            }

            /*uint UnkFooter0 = reader.ReadUInt32();
             * if(UnkFooter0 == 0)
             * {
             *  throw new NotImplementedException();
             * }
             *
             * uint OffsetToFooter = reader.ReadUInt32(); // should be same as reader.position - kynogon mesh start
             * uint FooterPadding = reader.ReadUInt32(); // Usually zero for me.
             * string FooterName = StringHelpers.ReadString(reader); // A null terminated string.
             * uint FooterUnk0 = reader.ReadUInt32(); // Size of string. Goes _after_ the string has been stored.
             * uint FooterMagic = reader.ReadUInt32(); // should be 0x1213F001
             * Debug.Assert(FooterMagic == 0x1213F001, "Didn't reach end of file.");
             */

            //File.WriteAllLines("model.obj", data.ToArray());
        }
        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());
        }
Example #15
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());
        }
        public void ReadFromFile(BinaryReader reader, StreamWriter writer)
        {
            //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");
            }

            writer.WriteLine("");
            Unk0 = reader.ReadInt32();
            Unk1 = reader.ReadInt32();
            Unk2 = reader.ReadSingle();
            Unk3 = reader.ReadSingle();
            writer.WriteLine(Unk0);
            writer.WriteLine(Unk1);
            writer.WriteLine(Unk2);
            writer.WriteLine(Unk3);

            float boundMinX = reader.ReadSingle();
            float boundMaxX = reader.ReadSingle();
            float boundMaxY = -reader.ReadSingle();
            float boundMinY = -reader.ReadSingle();

            BoundMin = new Vector2(boundMinX, boundMinY);
            BoundMax = new Vector2(boundMaxX, boundMaxY);



            writer.WriteLine(BoundMin);
            writer.WriteLine(BoundMax);
            //BoundingBox = BoundingBoxExtenders.ReadFromFile(reader);
            CellSizeX = reader.ReadInt32();
            CellSizeY = reader.ReadInt32();
            writer.WriteLine(CellSizeX);
            writer.WriteLine(CellSizeY);
            Radius = reader.ReadSingle();
            Unk4   = reader.ReadInt32();
            Height = reader.ReadInt32();
            Offset = reader.ReadInt32(); //this is a potential offset;
            writer.WriteLine(Radius);
            writer.WriteLine(Unk4);
            writer.WriteLine(Height);
            writer.WriteLine(Offset);
            Grid  = new int[(CellSizeX * CellSizeY)];
            Cells = new Cell[Grid.Length];
            writer.WriteLine("");

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

            int end = reader.ReadInt32();

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

                Cell cell    = new Cell();
                int  numSet0 = reader.ReadInt32();
                cell.Sets = new UnkSet0[numSet0];
                Cells[i]  = cell;

                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.
                cell.Offset = 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();
                    cell.Sets[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 = cell.Sets[z];
                    //NOTE: MOST OF THE OFFSETS BEGIN HERE, JUST AFTER THE SETS HAVE BEEN DEFINED ABOVE.
                    set.cellUnk0 = reader.ReadInt32();

                    if (set.cellUnk0 != Unk1)
                    {
                        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.NumEdges  = 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.NumEdges));
                    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.unk14Boxes = new Unk14DataSet[set.cellUnk14];
                    for (int x = 0; x < set.cellUnk14; x++)
                    {
                        var dataSet = new Unk14DataSet();
                        dataSet.Offset    = reader.ReadInt32();
                        set.unk14Boxes[x] = dataSet;
                        writer.WriteLine(string.Format("{0} ", dataSet.Offset));
                    }

                    //ALWAYS A 4-BYTE INTEGER WHICH DENOTES THE END OF THE BATCH
                    if (set.cellUnk14 > 0)
                    {
                        set.unk14End = reader.ReadInt32();
                        var currentOffset = set.unk14Boxes[0].Offset;
                        for (int x = 0; x < set.cellUnk14; x++)
                        {
                            var dataSet = set.unk14Boxes[x];
                            var offset  = (x + 1 < set.cellUnk14 ? set.unk14Boxes[x + 1].Offset : set.unk14End);
                            var size    = offset - currentOffset;
                            currentOffset = offset;
                            var count = size / 12;
                            dataSet.Points = new Vector3[count];
                            writer.WriteLine(string.Format("Unk14: {0} {1}", x, count));
                            for (int f = 0; f < dataSet.Points.Length; f++)
                            {
                                dataSet.Points[f] = Vector3Extenders.ReadFromFile(reader);
                                writer.WriteLine("{0}: {1}", f, dataSet.Points[f]);
                            }
                            set.unk14Boxes[x] = dataSet;
                        }
                    }
                    writer.WriteLine("");

                    //CONTINUE ONTO THE NEXT BATCH
                    set.unk16Offsets = new int[set.NumEdges];
                    writer.WriteLine("Unk16 Offsets");
                    for (int x = 0; x < set.NumEdges; 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.NumEdges > 0)
                    {
                        set.EdgesDataEndOffset = reader.ReadInt32();
                    }

                    set.EdgeBoxes = new BoundingBox[set.NumEdges];
                    writer.WriteLine("Unk16 Boxes");
                    for (int x = 0; x < set.NumEdges; x++)
                    {
                        set.EdgeBoxes[x] = BoundingBoxExtenders.ReadFromFile(reader);
                        writer.WriteLine(string.Format("{0} ", set.EdgeBoxes[x]));
                    }

                    set.unk18Set = new Unk18DataSet[set.cellUnk18];
                    writer.WriteLine("");
                    if (set.cellUnk18 > 0)
                    {
                        set.unk18End = reader.ReadInt32();
                        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.ReadSingle();
                            dataSet.Unk1   = reader.ReadSingle();
                            dataSet.Unk2   = reader.ReadSingle();
                            dataSet.Offset = reader.ReadInt32();
                            writer.WriteLine(string.Format("{0} {1} {2} {3}", dataSet.Unk0, dataSet.Unk1, dataSet.Unk2, dataSet.Offset));
                            set.unk18Set[x] = dataSet;
                        }

                        byte[] unknown_data = reader.ReadBytes(12); //usually padding

                        var currentOffset = set.unk18End;
                        for (int x = 0; x < set.cellUnk18; x++)
                        {
                            var dataSet = set.unk18Set[x];
                            var size    = dataSet.Offset - currentOffset;
                            var count   = size / 12;
                            dataSet.Points = new Vector3[count];

                            for (int f = 0; f < dataSet.Points.Length; f++)
                            {
                                dataSet.Points[f] = Vector3Extenders.ReadFromFile(reader);
                                writer.WriteLine("{0}: {1}", f, dataSet.Points[f]);
                            }
                            currentOffset   = dataSet.Offset;
                            set.unk18Set[x] = dataSet;
                        }
                    }
                    writer.WriteLine("");
                    cell.Sets[z] = set;
                }
                Console.WriteLine("Completed: " + i);
                //byte[] data = reader.ReadBytes(size);
                //File.WriteAllBytes("grid_" + i + ".bin", data);
            }
            writer.Close();

            //File.WriteAllLines("model.obj", data.ToArray());
        }
 public void ReadFromFile(MemoryStream stream, bool isBigEndian)
 {
     transform = MatrixExtensions.ReadFromFile(stream, isBigEndian);
     bounds    = BoundingBoxExtenders.ReadFromFile(stream, isBigEndian);
     isValid   = stream.ReadByte8();
 }
Example #18
0
        public void ReadFromFile(MemoryStream stream, bool isBigEndian)
        {
            //all the same values?
            for (int i = 0; i != numBones.Length; i++)
            {
                numBones[i] = stream.ReadInt32(isBigEndian);
            }

            numBlendIDs = stream.ReadInt32(isBigEndian);
            numLods     = stream.ReadInt32(isBigEndian);

            //unknown lod data;
            unkLodData = new int[numLods];
            for (int i = 0; i != unkLodData.Length; i++)
            {
                unkLodData[i] = stream.ReadInt32(isBigEndian);
            }

            idType = stream.ReadByte8();

            //Bone Names and LOD data.
            boneNames = new Hash[numBones[0]];
            for (int i = 0; i != boneNames.Length; i++)
            {
                boneNames[i] = new Hash(stream, isBigEndian);
            }

            //Matrices;
            matrices1 = new Matrix[numBones[1]];
            matrices2 = new Matrix[numBones[3]];

            for (int i = 0; i != matrices1.Length; i++)
            {
                matrices1[i] = MatrixExtensions.ReadFromFile(stream, isBigEndian);
            }

            numUnkCount2 = stream.ReadInt32(isBigEndian);
            boneLODUsage = stream.ReadBytes(numUnkCount2);

            for (int i = 0; i != matrices2.Length; i++)
            {
                matrices2[i] = MatrixExtensions.ReadFromFile(stream, isBigEndian);
            }

            //BoneMappings.
            mappingForBlendingInfos = new MappingForBlendingInfo[numLods];
            for (int i = 0; i != mappingForBlendingInfos.Length; i++)
            {
                mappingForBlendingInfos[i].Bounds = new BoundingBox[numBones[2]];

                for (int x = 0; x != mappingForBlendingInfos[i].Bounds.Length; x++)
                {
                    mappingForBlendingInfos[i].Bounds[x] = BoundingBoxExtenders.ReadFromFile(stream, isBigEndian);
                }
                if (stream.ReadByte() != 0)
                {
                    throw new System.Exception("oops");
                }

                mappingForBlendingInfos[i].RefToUsageArray = stream.ReadBytes(numBones[2]);
                mappingForBlendingInfos[i].UsageArray      = stream.ReadBytes(unkLodData[i]);
            }
        }
Example #19
0
 public void ReadFromFile(MemoryStream reader, bool isBigEndian)
 {
     transform = new TransformMatrix(reader, isBigEndian);
     bounds = BoundingBoxExtenders.ReadFromFile(reader, isBigEndian);
     isValid = reader.ReadByte8();
 }