Exemplo n.º 1
0
        private void InternalWriteToFile(BinaryWriter writer)
        {
            writer.Write(version);
            writer.Write(unk1);
            writer.Write(unk2);
            BoundingBoxExtenders.WriteToFile(bounds, writer);
            writer.Write(Grids.Length);

            for (int i = 0; i < Grids.Length; i++)
            {
                Grid grid = Grids[i];
                writer.Write(grid.Key);
                Vector3Extenders.WriteToFile(grid.Origin, writer);
                Vector2Extenders.WriteToFile(grid.CellSize, writer);
                writer.Write(grid.Width);
                writer.Write(grid.Height);

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

            writer.Write(unk3.Length / 2);
            for (int i = 0; i < unk3.Length; i++)
            {
                writer.Write(unk3[i]);
            }

            writer.Write(ObjectGroups.Length);
            for (int i = 0; i != ObjectGroups.Length; i++)
            {
                ObjectGroup objectGroup = ObjectGroups[i];
                writer.Write(objectGroup.Unk01);
                writer.Write(objectGroup.Objects.Length);

                for (int x = 0; x != objectGroup.NumObjects; x++)
                {
                    Object obj = objectGroup.Objects[x];
                    writer.Write(obj.NumInstance2);
                    writer.Write(obj.Unk02);
                    writer.Write(obj.Name.Hash);
                    StringHelpers.WriteString(writer, obj.Name.String);
                    writer.Write(obj.UnkBytes1);
                    writer.Write(obj.GridMax);
                    writer.Write(obj.GridMin);
                    writer.Write(obj.NumInstances);

                    for (int y = 0; y != obj.NumInstances; y++)
                    {
                        Instance instance = obj.Instances[y];
                        writer.Write(instance.W0);
                        writer.Write(instance.W1);
                        writer.Write(instance.W2);
                        writer.Write(instance.D5);
                        writer.Write(instance.ID);
                        writer.Write(instance.D4);
                    }
                    objectGroup.Objects[x] = obj;
                }
                ObjectGroups[i] = objectGroup;
            }
        }
        public void WriteToFile(BinaryWriter writer)
        {
            StringHelpers.WriteString(writer, "KynogonRuntimeMesh", false);
            writer.Write((ushort)0); //magic is name with two extra 00
            writer.Write(2);         //version

            writer.Write(Unk0);
            writer.Write(Unk1);
            writer.Write(Unk2);
            writer.Write(Unk3);
            Vector2Extenders.WriteToFile(BoundMin, writer);
            Vector2Extenders.WriteToFile(BoundMax, writer);
            writer.Write(CellSizeX);
            writer.Write(CellSizeY);
            writer.Write(Radius);
            writer.Write(Unk4);
            writer.Write(Height);
            writer.Write(Offset);

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

            for (int i = 0; i < Grid.Length; i++)
            {
                Cell cell = Cells[i];
                writer.Write(cell.Sets.Length);

                if (cell.Sets.Length == 0)
                {
                    continue;
                }

                writer.Write(cell.Offset);

                for (int x = 0; x < cell.Sets.Length; x++)
                {
                    var set = cell.Sets[x];
                    writer.Write(set.X);
                    writer.Write(set.Y);
                    writer.Write(set.Offset);
                }

                for (int x = 0; x < cell.Sets.Length; x++)
                {
                    var set = cell.Sets[x];
                    writer.Write(set.cellUnk0);
                    writer.Write(set.cellUnk1);
                    writer.Write(set.cellUnk2);
                    writer.Write(set.cellUnk3);
                    writer.Write(set.cellUnk4);
                    writer.Write(set.cellUnk5);
                    writer.Write(set.cellUnk6);
                    writer.Write(set.cellUnk7);
                    writer.Write(set.cellUnk8);
                    writer.Write(set.cellUnk9);
                    writer.Write(set.cellUnk10);
                    writer.Write(set.cellUnk11);
                    writer.Write(set.cellUnk12);
                    writer.Write(set.cellUnk13);
                    writer.Write(set.cellUnk14);
                    writer.Write(set.cellUnk15);
                    writer.Write(set.NumEdges);
                    writer.Write(set.cellUnk17);
                    writer.Write(set.cellUnk18);
                    writer.Write(set.cellUnk19);

                    foreach (var dataSet in set.unk10Boxes)
                    {
                        BoundingBoxExtenders.WriteToFile(dataSet.B1, writer);
                        writer.Write(dataSet.UnkOffset);
                        writer.Write(dataSet.Unk20);
                    }

                    foreach (var dataSet in set.unk12Boxes)
                    {
                        BoundingBoxExtenders.WriteToFile(dataSet.B1, writer);
                        writer.Write(dataSet.Unk01);
                        writer.Write(dataSet.Unk02);
                        writer.Write(dataSet.Unk03);
                        writer.Write(dataSet.Unk04);
                        writer.Write(dataSet.Unk05);
                    }

                    if (set.cellUnk14 > 0)
                    {
                        foreach (var offset in set.unk14Offsets)
                        {
                            writer.Write(offset);
                        }

                        writer.Write(set.unk14End);
                        foreach (var dataSet in set.unk14Boxes)
                        {
                            foreach (var point in dataSet.Points)
                            {
                                Vector3Extenders.WriteToFile(point, writer);
                            }
                        }
                    }

                    foreach (var offset in set.unk16Offsets)
                    {
                        writer.Write(offset);
                    }

                    if (set.NumEdges > 0)
                    {
                        writer.Write(set.EdgesDataEndOffset);

                        foreach (var dataSet in set.EdgeBoxes)
                        {
                            dataSet.WriteToFile(writer);
                        }
                    }

                    if (set.cellUnk18 > 0)
                    {
                        writer.Write(set.unk18End);

                        foreach (var dataSet in set.unk18Set)
                        {
                            writer.Write(dataSet.Unk0);
                            writer.Write(dataSet.Unk1);
                            writer.Write(dataSet.Unk2);
                            writer.Write(dataSet.Offset);
                        }

                        writer.Write(new byte[12]);

                        foreach (var dataSet in set.unk18Set)
                        {
                            foreach (var point in dataSet.Points)
                            {
                                Vector3Extenders.WriteToFile(point, writer);
                            }
                        }
                    }
                }
            }
        }