Пример #1
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;
            }
        }
Пример #2
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();
        }