Exemple #1
0
            public void Read(BINAReader reader)
            {
                uint nodesCount            = reader.ReadUInt32();
                uint dataNodeCount         = reader.ReadUInt32();
                long nodesOffset           = reader.ReadInt64();
                long dataNodeIndicesOffset = reader.ReadInt64();

                // Nodes
                reader.JumpTo(nodesOffset);
                Nodes.Capacity = (int)nodesCount;

                for (int i = 0; i < nodesCount; ++i)
                {
                    Nodes.Add(new Node(reader, false));
                }

                // Data Node Indices
                reader.JumpTo(dataNodeIndicesOffset);
                DataNodeIndices.Capacity = (int)dataNodeCount;

                for (int i = 0; i < dataNodeCount; ++i)
                {
                    DataNodeIndices.Add(reader.ReadInt32());
                }
            }
Exemple #2
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            reader.ReadHeader();

            uint fileCount      = reader.ReadUInt32();
            uint fileEntriesPos = reader.ReadUInt32();

            uint typeCount      = reader.ReadUInt32();
            uint typeEntriesPos = reader.ReadUInt32();

            // Files
            Files.Capacity = (int)fileCount;
            reader.JumpTo(fileEntriesPos, false);

            for (uint i = 0; i < fileCount; ++i)
            {
                Files.Add(new S06FileEntry(reader));
            }

            // Types
            Types.Capacity = (int)typeCount;
            reader.JumpTo(typeEntriesPos, false);

            for (uint i = 0; i < typeCount; ++i)
            {
                Types.Add(new S06TypeEntry(reader, fileEntriesPos));
            }
        }
Exemple #3
0
        // Methods
        public override void Load(Stream fileStream)
        {
            // BINA Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            string sig = reader.ReadSignature(4);

            if (sig != Signature)
            {
                throw new InvalidSignatureException(Signature, sig);
            }
            var unknown1 = reader.ReadUInt32(); //Might be part of the Header according to Skyth's spec?

            if (unknown1 != 1)
            {
                Console.WriteLine($"Unknown1 does not equal 1 in this file! It's actually set to {unknown1}");
            }
            var shapeCount = reader.ReadInt64();
            var unknown2   = reader.ReadUInt64();

            if (unknown2 != 24)
            {
                Console.WriteLine($"Unknown1 does not equal 24 in this file! It's actually set to {unknown1}");
            }
            Console.WriteLine(unknown2);

            for (int i = 0; i < shapeCount; i++)
            {
                SvShape shape           = new SvShape();
                var     shapeNameOffset = reader.ReadInt64();
                long    pos             = reader.BaseStream.Position;
                reader.JumpTo(shapeNameOffset, false);
                shape.Name = reader.ReadNullTerminatedString();
                reader.JumpTo(pos, true);

                shape.Unknown1            = reader.ReadUInt32();
                shape.Size                = reader.ReadVector3();
                shape.Position            = reader.ReadVector3();
                shape.Rotation            = reader.ReadQuaternion();
                shape.BoundingBox.Minimum = reader.ReadVector3();
                shape.BoundingBox.Maximum = reader.ReadVector3();
                shape.Unknown2            = reader.ReadUInt32();

                var sectorCount      = reader.ReadInt64();
                var sectorListOffset = reader.ReadInt64();
                pos = reader.BaseStream.Position;
                reader.JumpTo(sectorListOffset, false);
                for (int s = 0; s < sectorCount; s++)
                {
                    SvSector sector = new SvSector();
                    sector.SectorIndex = reader.Read();
                    sector.Visible     = reader.ReadBoolean();
                    shape.Sectors.Add(sector);
                }
                reader.JumpTo(pos, true);
                SvShapes.Add(shape);
            }
        }
Exemple #4
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            string sig = reader.ReadSignature(4);

            if (sig != Signature)
            {
                throw new InvalidSignatureException(Signature, sig);
            }

            uint unknown1 = reader.ReadUInt32(); //Probably Flags according to Rad's Spec

            if (unknown1 != 537265920)
            {
                Console.WriteLine($"unknown1 does not equal 537265920! Actually equals {unknown1}!");
            }

            uint bankNameOffset    = reader.ReadUInt32(); //Offset to the Scene Bank name
            uint cueNameOffset     = reader.ReadUInt32(); //Offset of the first entry in the Scene Bank
            uint cueIndiciesOffset = reader.ReadUInt32(); //Offset to the number list for non stream indexs
            uint streamOffset      = reader.ReadUInt32(); //Offset to the table for xma names

            Name = reader.ReadChars(64);                  //Scene Bank's name
            uint cueCount       = reader.ReadUInt32();    //Total Number of Cues in this Scene Bank
            uint csbCueCount    = reader.ReadUInt32();    //Amount of Cues in this Scene Bank which pull their data from a corrosponding CSB file
            uint streamCueCount = reader.ReadUInt32();    //Amount of Cues in this Scene Bank which use XMA files

            int streams = 0;

            for (uint i = 0; i < cueCount; i++)
            {
                Cue cue = new Cue()
                {
                    Name = reader.ReadChars(32)
                };
                uint cueType  = reader.ReadUInt32();
                uint cueIndex = reader.ReadUInt32();
                cue.Category = reader.ReadUInt32();
                cue.Unknown1 = reader.ReadSingle();
                cue.Unknown2 = reader.ReadSingle();

                if (cueType == 1)
                {
                    long pos = reader.BaseStream.Position;          //Save position
                    reader.JumpTo(streamOffset, false);
                    reader.JumpAhead(4 * streams);                  //Jump ahead to the right offset for our Cue's XMA
                    reader.JumpTo(reader.ReadUInt32(), false);
                    cue.Stream = reader.ReadNullTerminatedString(); //Read the XMA's name for this Cue
                    reader.JumpTo(pos, true);                       //Jump back to where we were
                    streams++;
                }
                Cues.Add(cue); //Save Cue to list
            }
        }
Exemple #5
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            reader.ReadHeader();

            string sig = reader.ReadSignature(4);

            if (sig != Signature)
            {
                throw new InvalidSignatureException(Signature, sig);
            }

            uint texturePos         = reader.ReadUInt32();
            uint placeholderEntries = reader.ReadUInt32();

            reader.JumpTo(reader.ReadUInt32(), false);
            long pos = reader.BaseStream.Position;

            // Texture
            reader.JumpTo(texturePos, false);
            string texture = reader.ReadNullTerminatedString();

            reader.JumpTo(pos, true);

            // Placeholders
            for (uint i = 0; i < placeholderEntries; ++i)
            {
                S06FontPictureUV fontPicture = new S06FontPictureUV();
                Texture = texture;

                uint placeholderEntry = reader.ReadUInt32();

                fontPicture.X      = reader.ReadUInt16();
                fontPicture.Y      = reader.ReadUInt16();
                fontPicture.Width  = reader.ReadUInt16();
                fontPicture.Height = reader.ReadUInt16();

                pos = reader.BaseStream.Position;

                reader.JumpTo(placeholderEntry, false);
                fontPicture.Placeholder = reader.ReadNullTerminatedString();
                reader.JumpTo(pos, true);

                Entries.Add(fontPicture);
            }
        }
Exemple #6
0
            public void Read(BINAReader reader, bool readChildIndices = true)
            {
                long nameOffset            = reader.ReadInt64();
                long dataOffset            = reader.ReadInt64();
                long childIndexTableOffset = reader.ReadInt64();

                ParentIndex = reader.ReadInt32();
                Index       = reader.ReadInt32();
                DataIndex   = reader.ReadInt32();

                ushort childCount   = reader.ReadUInt16();
                bool   hasData      = reader.ReadBoolean();
                byte   fullPathSize = reader.ReadByte(); // Not counting this node in

                // Read name
                if (nameOffset != 0)
                {
                    Name = reader.GetString((uint)nameOffset);
                }

                // (MINOR HACK) Store data offset in Data
                // to be read later, avoiding some Seeks
                if (hasData && dataOffset != 0)
                {
                    Data = dataOffset;
                }

                // Read Child Indices
                if (!readChildIndices)
                {
                    return;
                }

                long curPos = reader.BaseStream.Position;

                reader.JumpTo(childIndexTableOffset);
                ChildIndices.Capacity = childCount;

                for (int i = 0; i < childCount; ++i)
                {
                    ChildIndices.Add(reader.ReadInt32());
                }

                reader.JumpTo(curPos);
            }
Exemple #7
0
        public S06FileEntry(BINAReader reader)
        {
            // Read entry
            uint friendlyNamePos = reader.ReadUInt32();
            uint filePathPos     = reader.ReadUInt32();

            // Read strings
            long curPos = reader.BaseStream.Position;

            reader.JumpTo(friendlyNamePos, false);
            FriendlyName = reader.ReadNullTerminatedString();

            reader.JumpTo(filePathPos, false);
            FilePath = reader.ReadNullTerminatedString();

            // Jump back
            reader.JumpTo(curPos);
        }
Exemple #8
0
        public S06TypeEntry(BINAReader reader, uint fileEntriesPos)
        {
            // Read entry
            uint namePos = reader.ReadUInt32();

            FileCount = reader.ReadUInt32();
            uint filesPos = reader.ReadUInt32();

            // Read name
            long curPos = reader.BaseStream.Position;

            reader.JumpTo(namePos, false);
            TypeName = reader.ReadNullTerminatedString();

            // Get file start index
            FileStartIndex = ((filesPos - fileEntriesPos) / 8);

            // Jump back
            reader.JumpTo(curPos);
        }
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            var rfzoneCount   = reader.ReadUInt32();
            var rfzoneOffset  = reader.ReadUInt32(); //Seemingly always 16? (0x10)
            var entriesCount  = reader.ReadUInt32(); //Seemingly always the same as rfzoneCount?
            var entriesOffset = reader.ReadUInt32();

            for (int i = 0; i < rfzoneCount; i++)
            {
                S06RFZone rfZone = new S06RFZone();
                rfZone.Unknown1 = reader.ReadSingle();
                rfZone.Unknown2 = reader.ReadSingle();
                rfZone.Unknown3 = reader.ReadSingle();
                rfZone.Unknown4 = reader.ReadSingle();
                Zones.Add(rfZone);
            }

            for (int i = 0; i < entriesCount; i++)
            {
                S06RFEntry entry = new S06RFEntry();
                entry.VertexCount = reader.ReadUInt32();
                var vertexTableOffset = reader.ReadUInt32();
                var zoneIndex         = reader.ReadUInt32();

                long pos = reader.BaseStream.Position;
                reader.JumpTo(vertexTableOffset, false);

                for (int v = 0; v < entry.VertexCount; v++)
                {
                    entry.Verticies.Add(reader.ReadVector3());
                }

                reader.JumpTo(pos, true);
                Entries.Add(entry);
            }
        }
Exemple #10
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            reader.ReadHeader();

            //File related header stuff
            uint fileCount      = reader.ReadUInt32();
            uint fileEntriesPos = reader.ReadUInt32();

            //Type related header stuff
            uint typeCount      = reader.ReadUInt32();
            uint typeEntriesPos = reader.ReadUInt32();

            //Read Types
            reader.JumpTo(typeEntriesPos, false);
            for (uint i = 0; i < typeCount; ++i)
            {
                S06TypeEntry type          = new S06TypeEntry();
                uint         namePos       = reader.ReadUInt32();
                uint         typeFileCount = reader.ReadUInt32();
                uint         filesPos      = reader.ReadUInt32();

                long pos = reader.BaseStream.Position;

                reader.JumpTo(namePos, false);
                type.TypeName = reader.ReadNullTerminatedString();

                reader.JumpTo(filesPos, false);

                //Read Objects
                for (uint f = 0; f < typeFileCount; ++f)
                {
                    S06FileEntry file            = new S06FileEntry();
                    uint         friendlyNamePos = reader.ReadUInt32();
                    uint         filePathPos     = reader.ReadUInt32();

                    long curPos = reader.BaseStream.Position;

                    reader.JumpTo(friendlyNamePos, false);
                    file.FriendlyName = reader.ReadNullTerminatedString();

                    reader.JumpTo(filePathPos, false);
                    file.FilePath = reader.ReadNullTerminatedString();

                    reader.JumpTo(curPos);
                    type.Files.Add(file);
                }
                Types.Add(type);

                reader.JumpTo(pos, true);
            }
        }
Exemple #11
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            int           entriesInObj = 0;
            long          nullPos      = 0;
            List <string> objects      = new List <string> {
            };

            //while (reader.ReadUInt32() != 0)
            while (reader.BaseStream.Position != 624)
            {
                //reader.JumpBehind(0x4);
                var valueOffset = reader.ReadUInt32();
                if (valueOffset != 0)
                {
                    long position = reader.BaseStream.Position;
                    reader.JumpTo(valueOffset, false);
                    objects.Add(reader.ReadNullTerminatedString());
                    reader.JumpTo(position, true);
                }
                else
                {
                    PathObjEntryStrings entry = new PathObjEntryStrings();
                    foreach (var value in objects)
                    {
                        entry.ObjectValues.Add(value);
                    }
                    objects.Clear();
                    extractedData.Objects.Add(entry);
                    nullPos = reader.BaseStream.Position;
                }
                entriesInObj++;
            }
        }
        // Methods
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            string sig = reader.ReadSignature(4);

            if (sig != Signature)
            {
                throw new InvalidSignatureException(Signature, sig);
            }

            uint unknown1           = reader.ReadUInt32();
            uint soundEntryCount    = reader.ReadUInt32();
            uint soundEntriesOffset = reader.ReadUInt32();

            // Data
            SoundEntries = new string[soundEntryCount];
            var soundNameOffsets = new uint[soundEntryCount];

            reader.JumpTo(soundEntriesOffset, false);

            // We read the offsets first and then the names to avoid unnecessary seeking.
            for (uint i = 0; i < soundEntryCount; ++i)
            {
                uint soundEntryIndex = reader.ReadUInt32();
                soundNameOffsets[soundEntryIndex] = reader.ReadUInt32();
            }

            for (uint i = 0; i < soundEntryCount; ++i)
            {
                reader.JumpTo(soundNameOffsets[i], false);
                SoundEntries[i] = reader.ReadNullTerminatedString();
            }
        }
        protected NodeTree ReadNodeTree(BINAReader reader)
        {
            var  nodeTree   = new NodeTree();
            uint nodesCount = reader.ReadUInt32();

            nodeTree.DataNodeCount = reader.ReadUInt32();
            long nodesOffset           = reader.ReadInt64();
            long dataNodeIndicesOffset = reader.ReadInt64();

            // Nodes
            reader.JumpTo(nodesOffset);
            for (uint i = 0; i < nodesCount; ++i)
            {
                nodeTree.Nodes.Add(new Node(reader));
            }

            return(nodeTree);
        }
Exemple #14
0
        // Methods
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            string sig = reader.ReadSignature(4);

            if (sig != Signature)
            {
                throw new InvalidSignatureException(Signature, sig);
            }

            uint messageTableOffset = reader.ReadUInt32();
            uint messageCount       = reader.ReadUInt32();

            long namePos = reader.BaseStream.Position;

            reader.JumpTo(messageTableOffset, false);
            Name = reader.ReadNullTerminatedString();
            reader.JumpTo(namePos, true);

            for (uint i = 0; i < messageCount; i++)
            {
                string name        = string.Empty;
                string text        = string.Empty;
                string placeholder = string.Empty;

                uint nameOffset        = reader.ReadUInt32();
                uint textOffset        = reader.ReadUInt32();
                uint placeholderOffset = reader.ReadUInt32();

                long pos = reader.BaseStream.Position;

                reader.JumpTo(nameOffset, false);
                name = reader.ReadNullTerminatedString();
                reader.JumpTo(textOffset, false);
                text = reader.ReadNullTerminatedStringUTF16();
                if (placeholderOffset != 0)
                {
                    reader.JumpTo(placeholderOffset, false);
                    placeholder = reader.ReadNullTerminatedString();
                }

                MSTEntries entry = new MSTEntries(name, text, placeholder);
                entries.Add(entry);

                reader.JumpTo(pos, true);
            }
        }
Exemple #15
0
        // Methods
        public override void Read(BINAReader reader, BINAHeader header = null)
        {
            // Stage Entries
            uint stopOffset = ((header as BINAv2Header).StringTableOffset + reader.Offset);

            StageEntries.Clear();

            while (reader.BaseStream.Position < stopOffset)
            {
                StageEntries.Add(new StageEntry(reader));
            }

            // String Table
            foreach (var entry in StageEntries)
            {
                reader.JumpTo((long)entry.StageIDOffset, false);
                entry.StageID = reader.ReadNullTerminatedString();
            }
        }
Exemple #16
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            var pathTableOffset = reader.ReadUInt32();
            var pathCount       = reader.ReadUInt32();
            var nodeTableOffset = reader.ReadUInt32();
            var nodeCount       = reader.ReadUInt32();

            for (int i = 0; i < pathCount; i++)
            {
                S06PathEntry pathEntry = new S06PathEntry();
                pathEntry.SplineInfoOffset = reader.ReadUInt32();
                pathEntry.SplineCount      = reader.ReadUInt32();
                pathEntry.Unknown1         = reader.ReadUInt32();
                pathEntry.VertexDataOffset = reader.ReadUInt32();
                pathEntry.VertexCount      = reader.ReadUInt32();
                pathEntry.Unknown2         = reader.ReadUInt32();
                Paths.Add(pathEntry);
            }

            for (int i = 0; i < Paths.Count; i++)
            {
                reader.JumpTo(Paths[i].VertexDataOffset, false);
                for (int v = 0; v < Paths[i].VertexCount; v++)
                {
                    Console.WriteLine($"Flag: {reader.ReadSingle()}");
                    Console.WriteLine($"xPos: {reader.ReadSingle()}");
                    Console.WriteLine($"yPos: {reader.ReadSingle()}");
                    Console.WriteLine($"zPos: {reader.ReadSingle()}");
                    Console.WriteLine($"invec_xPos: {reader.ReadSingle()}");
                    Console.WriteLine($"invec_yPos: {reader.ReadSingle()}");
                    Console.WriteLine($"invec_zPos: {reader.ReadSingle()}");
                    Console.WriteLine($"outvec_xPos: {reader.ReadSingle()}");
                    Console.WriteLine($"outvec_yPos: {reader.ReadSingle()}");
                    Console.WriteLine($"outvec_zPos: {reader.ReadSingle()}");
                }
            }
        }
Exemple #17
0
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();
            long namePositionHack = reader.BaseStream.Position;

            reader.JumpAhead(0xC);
            prop.Name = reader.ReadNullTerminatedString();
            reader.JumpTo(namePositionHack, true);
            reader.JumpTo(0x4c, true);
            prop.ObjectCount = reader.ReadUInt32();
            reader.JumpAhead(0x4);
            for (uint i = 0; i < prop.ObjectCount; i++)
            {
                S06PropObject obj = new S06PropObject();

                var objectNameOffset = reader.ReadUInt32();
                obj.ObjectParameterCount = reader.ReadUInt32();
                var paramOffset = reader.ReadUInt32();
                obj.ObjectUnknown1 = reader.ReadUInt32();
                obj.ObjectUnknown2 = reader.ReadUInt32();

                long position = reader.BaseStream.Position;

                reader.JumpTo(objectNameOffset, false);
                obj.ObjectName = reader.ReadNullTerminatedString();

                for (uint c = 0; c < obj.ObjectParameterCount; c++)
                {
                    reader.JumpTo(paramOffset + (c * 0x18), false);

                    S06PropParameter parameter = new S06PropParameter();
                    parameter.ParameterName = reader.ReadNullTerminatedString();
                    reader.JumpTo(paramOffset + (c * 0x18) + 0x10, false);

                    parameter.ParameterType = reader.ReadUInt32();
                    parameter.ParameterID   = reader.ReadUInt32();

                    obj.Parameters.Add(parameter);
                }

                prop.Objects.Add(obj);

                reader.JumpTo(position, true);
            }
        }
Exemple #18
0
        // Methods
        public override void Read(BINAReader reader, BINAHeader header = null)
        {
            // Slots
            Unknown1         = new Slot(reader); // gadget_database?
            CustomizeBody    = new Slot(reader);
            CustomizeHead    = new Slot(reader);
            CustomizeGlass   = new Slot(reader);
            Unknown2         = new Slot(reader); // customize_face?
            CustomizeGlove   = new Slot(reader);
            CustomizeShoes   = new Slot(reader);
            CustomizePattern = new Slot(reader);
            EventMovie       = new Slot(reader);
            GameScore        = new Slot(reader);
            StageScore       = new Slot(reader);
            Unknown3         = new Slot(reader); // idk (padding?)

            // Paths
            ulong miscPACOffset       = reader.ReadUInt64();
            ulong unknownPath1Offset  = reader.ReadUInt64();
            ulong stgMissionLUAOffset = reader.ReadUInt64();
            ulong unknownPath2Offset  = reader.ReadUInt64();

            MiscPAC       = ReadPath(miscPACOffset);
            UnknownPath1  = ReadPath(unknownPath1Offset);
            StgMissionLUA = ReadPath(stgMissionLUAOffset);
            UnknownPath2  = ReadPath(unknownPath2Offset);

            // Sub-Methods
            string ReadPath(ulong offset)
            {
                if (offset == 0)
                {
                    return(null);
                }

                reader.JumpTo((long)offset, false);
                return(reader.ReadNullTerminatedString());
            }
        }
        public override void Load(Stream fileStream)
        {
            // PACx Header
            var reader = new BINAReader(fileStream);

            Header.Read(reader);

            // Type Names
            var typeTree = ReadNodeTree(reader);
            var names    = new string[typeTree.Nodes.Count];

            for (int i = 0; i < typeTree.Nodes.Count; ++i)
            {
                var typeNode = typeTree.Nodes[i];
                if (typeNode.ChildCount < 1)
                {
                    continue;
                }

                int nameIndex = -1;
                if (typeNode.ChildIDTableOffset > 0)
                {
                    reader.JumpTo(typeNode.ChildIDTableOffset);
                    nameIndex = reader.ReadInt32();
                }

                if (typeNode.NameOffset > 0)
                {
                    reader.JumpTo(typeNode.NameOffset);
                    names[i] = reader.ReadNullTerminatedString();
                }
            }

            // Types
            foreach (var type in typeTree.Nodes)
            {
                if (!type.HasData)
                {
                    continue;
                }

                string name = string.Empty;
                var    n    = type;

                while (n.ParentIndex >= 0)
                {
                    name = $"{names[n.ParentIndex]}{name}";
                    n    = typeTree.Nodes[n.ParentIndex];
                }

                reader.JumpTo(type.DataOffset);
                var fileTree = ReadNodeTree(reader);

                // File Names
                var fileNames = new string[fileTree.Nodes.Count];
                for (int i = 0; i < fileTree.Nodes.Count; ++i)
                {
                    var fileNode = fileTree.Nodes[i];
                    if (fileNode.ChildCount < 1)
                    {
                        continue;
                    }

                    int nameIndex = -1;
                    if (fileNode.ChildIDTableOffset > 0)
                    {
                        reader.JumpTo(fileNode.ChildIDTableOffset);
                        nameIndex = reader.ReadInt32();
                    }

                    if (fileNode.NameOffset > 0)
                    {
                        reader.JumpTo(fileNode.NameOffset);
                        fileNames[i] = reader.ReadNullTerminatedString();
                    }
                }

                // File Nodes
                foreach (var file in fileTree.Nodes)
                {
                    if (!file.HasData)
                    {
                        continue;
                    }

                    name = string.Empty;
                    n    = file;

                    while (n.ParentIndex >= 0)
                    {
                        name = $"{fileNames[n.ParentIndex]}{name}";
                        n    = fileTree.Nodes[n.ParentIndex];
                    }

                    // File Entries
                    reader.JumpTo(file.DataOffset);
                    uint pacID = reader.ReadUInt32();
                    if (pacID != Header.ID)
                    {
                        Console.WriteLine(
                            $"WARNING: Skipped file {name} as its pac ID was missing");
                        continue;
                    }

                    ulong fileSize        = reader.ReadUInt64();
                    uint  padding1        = reader.ReadUInt32();
                    long  fileDataOffset  = reader.ReadInt64();
                    ulong padding2        = reader.ReadUInt64();
                    long  extensionOffset = reader.ReadInt64();
                    uint  pacType         = reader.ReadUInt32();
                    uint  padding3        = reader.ReadUInt32();

                    if (fileDataOffset <= 0 || pacType == 1)
                    {
                        continue;
                    }

                    // File Extension
                    reader.JumpTo(extensionOffset);
                    name += $".{reader.ReadNullTerminatedString()}";

                    // File Data
                    reader.JumpTo(fileDataOffset);
                    var data = reader.ReadBytes((int)fileSize);

                    // BINA Check
                    // TODO: Remove this check
                    if (data[0] == 0x42 && data[1] == 0x49 && data[2] == 0x4E && data[3] == 0x41)
                    {
                        if (pacType != 2)
                        {
                            Console.WriteLine(
                                $"WARNING: FileType ({pacType}) != 2 when file carries BINA Header!");
                        }
                    }
                    else
                    {
                        if (pacType == 2)
                        {
                            Console.WriteLine(
                                $"WARNING: FileType ({pacType}) == 2 when file has no BINA Header!");
                        }
                    }

                    Data.Add(new ArchiveFile(name, data));
                }
            }
        }
        // Methods
        public override void Load(Stream fileStream,
                                  Dictionary <string, SetObjectType> objectTemplates)
        {
            if (objectTemplates == null)
            {
                throw new ArgumentNullException("objectTemplates",
                                                "Cannot load Forces set data without object templates.");
            }

            // BINA Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            // Set Data Header
            ulong padding1 = reader.ReadUInt64();
            ulong padding2 = reader.ReadUInt64();

            long  objectTableOffset = reader.ReadInt64();
            ulong objectCount       = reader.ReadUInt64();
            ulong objectCount2      = reader.ReadUInt64();
            ulong padding3          = reader.ReadUInt64();

            // Padding/Unknown Value Checks
            if (padding1 != 0)
            {
                Console.WriteLine($"WARNING: Padding1 != 0 ({padding1})");
            }

            if (padding2 != 0)
            {
                Console.WriteLine($"WARNING: Padding2 != 0 ({padding2})");
            }

            if (padding3 != 0)
            {
                Console.WriteLine($"WARNING: Padding3 != 0 ({padding3})");
            }

            if (objectCount != objectCount2)
            {
                Console.WriteLine(
                    "WARNING: ObjectCount ({0}) != ObjectCount2 ({1})",
                    objectCount, objectCount2);
            }

            // Object Offsets
            var objectOffsets = new long[objectCount];

            reader.JumpTo(objectTableOffset, false);

            for (uint i = 0; i < objectCount; ++i)
            {
                objectOffsets[i] = reader.ReadInt64();
            }

            // Objects
            for (uint i = 0; i < objectCount; ++i)
            {
                reader.JumpTo(objectOffsets[i], false);

                var obj = ReadObject(reader, objectTemplates);
                if (obj == null)
                {
                    continue;
                }
                Objects.Add(obj);
            }
        }
Exemple #21
0
        public const uint Signature   = 0x4658434F; // FXCO in ASCII

        // Methods
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            uint sig = reader.ReadUInt32();

            if (sig != Signature)
            {
                throw new InvalidSignatureException("FXCO",
                                                    Encoding.ASCII.GetString(BitConverter.GetBytes(sig)));
            }

            uint  unknown1        = reader.ReadUInt32(); // Version number?
            ulong instanceCount   = reader.ReadUInt64();
            ulong instancesOffset = reader.ReadUInt64();

            ulong shapesCount  = reader.ReadUInt64();
            ulong shapesOffset = reader.ReadUInt64();

            ulong unknownCount  = reader.ReadUInt64();
            ulong unknownOffset = reader.ReadUInt64();

            // Instances
            reader.JumpTo((long)instancesOffset, false);
            for (uint i = 0; i < instanceCount; ++i)
            {
                reader.FixPadding(8);
                ulong nameOffset   = reader.ReadUInt64();
                byte  unknownFlag1 = reader.ReadByte();
                byte  unknownFlag2 = reader.ReadByte();
                byte  unknownFlag3 = reader.ReadByte();
                byte  unknownFlag4 = reader.ReadByte();

                var   vect1        = reader.ReadVector3(); // Position or size?
                ulong instPadding1 = reader.ReadUInt64();
                uint  instPadding2 = reader.ReadUInt32();
                uint  instUnknown1 = reader.ReadUInt32();

                ulong instPadding3 = reader.ReadUInt64();
                ulong instPadding4 = reader.ReadUInt64();
                ulong instPadding5 = reader.ReadUInt64();
                ulong instPadding6 = reader.ReadUInt64();

                ulong unknownString1 = reader.ReadUInt64();  // Always "none"?
                var   vect2          = reader.ReadVector3(); // Position or size?
                uint  instUnknown2   = reader.ReadUInt32();  // Always 0x00000080?
                uint  instPadding7   = reader.ReadUInt32();
                uint  instUnknown3   = reader.ReadUInt32();  // Always 0x00000080?

                float instUnknown4 = reader.ReadSingle();    // Always 1?
            }

            // Unknown
            reader.JumpTo((long)unknownOffset, false);
            for (uint i = 0; i < unknownCount; ++i)
            {
                ulong uk1 = reader.ReadUInt64(); // Maybe 8 indices?
            }

            // Shapes
            reader.JumpTo((long)shapesOffset, false);
            for (uint i = 0; i < shapesCount; ++i)
            {
                uint shapeUnknown1 = reader.ReadUInt32();
                uint shapeUnknown2 = reader.ReadUInt32();
                var  shapeUnknown3 = reader.ReadVector3();
                var  shapeUnknown4 = reader.ReadVector3();
            }
        }
Exemple #22
0
        // Methods
        public override void Load(Stream fileStream,
                                  Dictionary <string, SetObjectType> objectTemplates)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            reader.JumpAhead(0x2C); // Skip "test" string
            uint objectLength = reader.ReadUInt32();
            uint objectOffset = reader.ReadUInt32();
            uint groupLength  = reader.ReadUInt32();
            uint groupOffset  = reader.ReadUInt32();

            Console.WriteLine($"Object Count: {objectLength}");
            Console.WriteLine($"Object Table Offset Location: {objectOffset}");
            Console.WriteLine($"Group Count: {groupLength}");
            Console.WriteLine($"Group Table Offset Location: {groupOffset}");

            //Groups
            reader.JumpTo(groupOffset, false);
            for (uint i = 0; i < groupLength; ++i)
            {
                //What we know so far:
                //First 4 bytes is a name for the group (usually GroupHelperXX?)
                //Second 4 bytes are the type? (according to LibS06), might be a second name (stuff like next_set/GroupHelperXX)?
                //Third 4 bytes is the amount of objects in this group.
                //Last 4 bytes is a list of the object IDs in this group.

                uint nameOffset        = reader.ReadUInt32(); //Name
                uint typeOffset        = reader.ReadUInt32(); //Type?
                uint groupObjectCount  = reader.ReadUInt32(); //Count
                uint groupObjectOffset = reader.ReadUInt32(); //Address of Objects

                string groupName = string.Empty;
                string groupType = string.Empty;

                long pos = reader.BaseStream.Position;

                reader.JumpTo(nameOffset, false);
                groupName = reader.ReadNullTerminatedString();
                groupNames.Add(groupName);

                reader.JumpTo(typeOffset, false);
                groupType = reader.ReadNullTerminatedString();
                groupTypes.Add(groupType);

                reader.JumpTo(groupObjectOffset, false);
                for (int c = 0; c < groupObjectCount; c++)
                {
                    reader.JumpAhead(4);
                    uint objID = reader.ReadUInt32();
                    objGroupData.Add($"{groupName}|{groupType}|{objID}");
                    groupIDs.Add(objID);
                }

                reader.JumpTo(pos, true);
            }

            // Data
            reader.JumpTo(objectOffset, false);
            for (uint i = 0; i < objectLength; ++i)
            {
                Objects.Add(ReadObject(i));
            }

            // TODO: Read Footer

            // Sub-Methods
            SetObject ReadObject(uint id)
            {
                // Object Entry
                var  obj        = new SetObject();
                uint nameOffset = reader.ReadUInt32();
                uint typeOffset = reader.ReadUInt32();

                reader.JumpAhead(16);

                obj.Transform.Position = reader.ReadVector3();
                reader.JumpAhead(4);
                obj.Transform.Rotation = new Quaternion(reader.ReadVector4());

                uint paramCount  = reader.ReadUInt32();
                uint paramOffset = reader.ReadUInt32();

                // Object Parameters
                long pos = reader.BaseStream.Position;

                for (uint i = 0; i < paramCount; ++i)
                {
                    reader.JumpTo(paramOffset + i * 0x14, false);
                    obj.Parameters.Add(ReadParam());
                }

                // Object Name
                reader.JumpTo(nameOffset, false);
                obj.CustomData.Add("Name", new SetObjectParam(
                                       typeof(string), reader.ReadNullTerminatedString()));

                // Object Type
                reader.JumpTo(typeOffset, false);
                obj.ObjectType = reader.ReadNullTerminatedString();
                obj.ObjectID   = id;

                //Object Group
                if (!groupIDs.Contains(id))
                {
                    obj.CustomData.Add("GroupName", new SetObjectParam(
                                           typeof(string), ""));
                    obj.CustomData.Add("GroupType", new SetObjectParam(
                                           typeof(string), ""));
                }
                else
                {
                    string[] groupData = objGroupData[groupIDs.IndexOf(id)].Split('|');
                    obj.CustomData.Add("GroupName", new SetObjectParam(
                                           typeof(string), groupData[0]));
                    obj.CustomData.Add("GroupType", new SetObjectParam(
                                           typeof(string), groupData[1]));
                }

                reader.JumpTo(pos, true);
                return(obj);
            }

            SetObjectParam ReadParam()
            {
                var  param = new SetObjectParam();
                uint type  = reader.ReadUInt32();

                switch (type)
                {
                case 0:
                    param.DataType = typeof(bool);
                    param.Data     = (reader.ReadUInt32() == 1);
                    break;

                case 1:
                    param.DataType = typeof(int);
                    param.Data     = reader.ReadInt32();
                    break;

                case 2:
                    param.DataType = typeof(float);
                    param.Data     = reader.ReadSingle();
                    break;

                case 3:
                    uint offset = reader.ReadUInt32();
                    uint amount = reader.ReadUInt32();

                    if (amount != 1)
                    {
                        Console.WriteLine($"WARNING: Amount != 1. ({amount})");
                    }

                    long pos = reader.BaseStream.Position;
                    reader.JumpTo(offset, false);

                    param.DataType = typeof(string);
                    param.Data     = reader.ReadNullTerminatedString();
                    reader.JumpTo(pos, true);
                    break;

                case 4:
                    param.DataType = typeof(Vector3);
                    param.Data     = reader.ReadVector3();
                    break;

                case 6:
                    param.DataType = typeof(uint);
                    param.Data     = reader.ReadUInt32();
                    break;

                default:
                    Console.WriteLine($"WARNING: Unknown object param type {type}!");
                    return(null);
                }

                return(param);
            }
        }
        protected SetObjectParam ReadParameter(BINAReader reader, SetObjectTypeParam param)
        {
            FixPadding(reader, param.DataType);

            // Special Param Types
            if (param is SetObjectTypeParamGroup group)
            {
                var g           = new SetObjectParamGroup(group.Padding);
                var groupParams = g.Parameters;

                foreach (var p in group.Parameters)
                {
                    groupParams.Add(ReadParameter(reader, p));
                }

                reader.FixPadding(group.Padding ?? 16);
                return(g);
            }
            else if (param.DataType == typeof(ObjectReference[]))
            {
                long  arrOffset  = reader.ReadInt64();
                ulong arrLength  = reader.ReadUInt64();
                ulong arrLength2 = reader.ReadUInt64();
                long  curPos     = reader.BaseStream.Position;

                if (arrLength != arrLength2)
                {
                    Console.WriteLine(
                        "WARNING: ArrLength ({0}) != ArrLength2 ({1})",
                        arrLength, arrLength2);
                }

                var arr = new ObjectReference[arrLength];
                if (arrLength > 0 && arrOffset > 0)
                {
                    reader.JumpTo(arrOffset, false);
                    for (uint i = 0; i < arrLength; ++i)
                    {
                        arr[i] = new ObjectReference(reader);
                    }

                    reader.JumpTo(curPos);
                }

                return(new SetObjectParam(param.DataType, arr));
            }
            else if (param.DataType == typeof(ObjectReference))
            {
                return(new SetObjectParam(typeof(ObjectReference),
                                          new ObjectReference(reader)));
            }
            else if (param.DataType == typeof(string))
            {
                var  stringParam   = new SetObjectParam(typeof(string), string.Empty);
                long offset        = reader.ReadInt64();
                long stringPadding = reader.ReadInt64();

                if (offset > 0)
                {
                    long curPos = reader.BaseStream.Position;
                    reader.JumpTo(offset, false);
                    stringParam.Data = reader.ReadNullTerminatedString();
                    reader.JumpTo(curPos);
                }

                if (stringPadding != 0)
                {
                    Console.WriteLine("WARNING: String Padding != 0 ({0:X})!!", stringPadding);
                }

                //reader.FixPadding(16);
                return(stringParam);
            }

            // Data
            var objParam = new SetObjectParam(param.DataType,
                                              reader.ReadByType(param.DataType));

            // Post-Param Padding
            if (param.DataType == typeof(Vector3))
            {
                uint vecPadding = reader.ReadUInt32();
                if (vecPadding != 0)
                {
                    Console.WriteLine("WARNING: Vector Padding != 0 ({0:X})!!", vecPadding);
                }
            }

            return(objParam);
        }
Exemple #24
0
        // Methods
        public override void Load(Stream fileStream)
        {
            // BINA Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            // Header
            byte unknown1     = reader.ReadByte(); // Always 3?
            byte sheetCount   = reader.ReadByte(); // ?
            byte unknown2     = reader.ReadByte(); // Always 0?
            byte unknown3     = reader.ReadByte(); // Always 0?
            uint unknown4     = reader.ReadUInt32();
            long sheetsOffset = reader.ReadInt64();

            // Sheets
            reader.JumpTo(sheetsOffset, false);
            for (uint i = 0; i < sheetCount; ++i)
            {
                Sheets.Add(new Sheet()
                {
                    NameOffset  = reader.ReadInt64(),
                    CellCount   = reader.ReadUInt64(),
                    CellsOffset = reader.ReadInt64()
                });
            }

            // Cells
            for (int i = 0; i < sheetCount; ++i)
            {
                var sheet = Sheets[i];
                reader.JumpTo(sheet.CellsOffset, false);

                for (uint i2 = 0; i2 < sheet.CellCount; ++i2)
                {
                    sheet.Cells.Add(new Cell()
                    {
                        UUID              = reader.ReadUInt64(),
                        NameOffset        = reader.ReadInt64(),
                        SecondEntryOffset = reader.ReadInt64(),
                        DataOffset        = reader.ReadInt64()
                    });
                }
            }

            // Data
            foreach (var sheet in Sheets)
            {
                for (int i = 0; i < sheet.Cells.Count; ++i)
                {
                    var cell = sheet.Cells[i];
                    reader.JumpTo(cell.DataOffset.Value, false);

                    var  chars           = new List <byte>();
                    bool isReadingButton = false;

                    // Read Unicode strings
                    do
                    {
                        byte b1 = reader.ReadByte();
                        byte b2 = reader.ReadByte();

                        if (b1 != 0 && ((b2 & 0xE0) == 0xE0))
                        {
                            isReadingButton = true;
                        }

                        if (b1 == 0 && b2 == 0)
                        {
                            if (isReadingButton)
                            {
                                isReadingButton = false;
                                chars.Add(0x57); // NullReplaceChar byte1
                                chars.Add(0x2B); // NullReplaceChar byte2
                                continue;
                            }
                            else
                            {
                                break;
                            }
                        }

                        chars.Add(b1);
                        chars.Add(b2);
                    }while (fileStream.Position < fileStream.Length);
                    cell.Data = Encoding.Unicode.GetString(chars.ToArray());
                }
            }

            // Second Entries
            var typeOffsets = new Dictionary <long, string>();

            foreach (var sheet in Sheets)
            {
                for (int i = 0; i < sheet.Cells.Count; ++i)
                {
                    var cell = sheet.Cells[i];
                    reader.JumpTo(cell.SecondEntryOffset.Value, false);

                    long nameOffset = reader.ReadInt64();
                    long typeOffset = reader.ReadInt64();
                    cell.LayoutOffset = reader.ReadInt64();

                    if (nameOffset != cell.NameOffset)
                    {
                        Console.WriteLine(
                            "WARNING: Second name offset ({0:X}) != first ({1:X})!",
                            nameOffset, cell.NameOffset);
                    }

                    // Caption Type
                    if (typeOffsets.ContainsKey(typeOffset))
                    {
                        cell.TypeName = typeOffsets[typeOffset];
                        continue;
                    }

                    var type = new CellType();
                    reader.JumpTo(typeOffset, false);

                    long typeNameOffset      = reader.ReadInt64();
                    long typeNamespaceOffset = reader.ReadInt64();
                    long unknownFloat1Offset = reader.ReadInt64();
                    long unknownFloat2Offset = reader.ReadInt64();
                    long unknownFloat3Offset = reader.ReadInt64();
                    long unknownInt1Offset   = reader.ReadInt64();
                    long unknownInt2Offset   = reader.ReadInt64();
                    long unknownOffset1      = reader.ReadInt64();
                    long unknownULong2Offset = reader.ReadInt64();
                    long unknownOffset2      = reader.ReadInt64();
                    long unknownOffset3      = reader.ReadInt64();
                    long unknownOffset4      = reader.ReadInt64();
                    long unknownULong1Offset = reader.ReadInt64();
                    long unknownOffset5      = reader.ReadInt64();

                    // UnknownFloat1
                    if (unknownFloat1Offset > 0)
                    {
                        reader.JumpTo(unknownFloat1Offset, false);
                        type.UnknownFloat1 = reader.ReadSingle();
                        uint padding1 = reader.ReadUInt32();

                        if (padding1 != 0)
                        {
                            Console.WriteLine("WARNING: Type Padding1 != 0 (0x{0:X})", padding1);
                        }
                    }

                    // UnknownFloat2
                    if (unknownFloat2Offset > 0)
                    {
                        reader.JumpTo(unknownFloat2Offset, false);
                        type.UnknownFloat2 = reader.ReadSingle();
                        uint padding2 = reader.ReadUInt32();

                        if (padding2 != 0)
                        {
                            Console.WriteLine("WARNING: Type Padding2 != 0 (0x{0:X})", padding2);
                        }
                    }

                    // UnknownFloat3
                    if (unknownFloat3Offset > 0)
                    {
                        reader.JumpTo(unknownFloat3Offset, false);
                        type.UnknownFloat3 = reader.ReadSingle();
                        uint padding3 = reader.ReadUInt32();

                        if (padding3 != 0)
                        {
                            Console.WriteLine("WARNING: Type Padding3 != 0 (0x{0:X})", padding3);
                        }
                    }

                    // UnknownInt1
                    if (unknownInt1Offset > 0)
                    {
                        reader.JumpTo(unknownInt1Offset, false);
                        type.UnknownInt1 = reader.ReadInt32();
                        uint padding4 = reader.ReadUInt32();

                        if (padding4 != 0)
                        {
                            Console.WriteLine("WARNING: Type Padding4 != 0 (0x{0:X})", padding4);
                        }
                    }

                    // UnknownInt2
                    if (unknownInt2Offset > 0)
                    {
                        reader.JumpTo(unknownInt2Offset, false);
                        type.UnknownInt2 = reader.ReadInt32();
                        uint padding5 = reader.ReadUInt32();

                        if (padding5 != 0)
                        {
                            Console.WriteLine("WARNING: Type Padding5 != 0 (0x{0:X})", padding5);
                        }
                    }

                    if (unknownOffset1 != 0)
                    {
                        Console.WriteLine("WARNING: Type ukOff1 != 0 (0x{0:X})", unknownOffset1);
                    }

                    // UnknownULong2Offset
                    if (unknownULong2Offset > 0)
                    {
                        reader.JumpTo(unknownULong2Offset, false);
                        type.UnknownULong2 = reader.ReadUInt64();
                    }

                    if (unknownOffset2 != 0)
                    {
                        Console.WriteLine("WARNING: Type ukOff2 != 0 (0x{0:X})", unknownOffset2);
                    }

                    if (unknownOffset3 != 0)
                    {
                        Console.WriteLine("WARNING: Type ukOff3 != 0 (0x{0:X})", unknownOffset3);
                    }

                    if (unknownOffset4 != 0)
                    {
                        Console.WriteLine("WARNING: Type ukOff4 != 0 (0x{0:X})", unknownOffset4);
                    }

                    // UnknownULong1Offset
                    if (unknownULong1Offset > 0)
                    {
                        reader.JumpTo(unknownULong1Offset, false);
                        type.UnknownULong1 = reader.ReadUInt64();
                    }

                    if (unknownOffset5 != 0)
                    {
                        Console.WriteLine("WARNING: Type ukOff5 != 0 (0x{0:X})", unknownOffset5);
                    }

                    // Strings
                    reader.JumpTo(typeNameOffset, false);
                    string typeName = reader.ReadNullTerminatedString();

                    reader.JumpTo(typeNamespaceOffset, false);
                    type.Namespace = reader.ReadNullTerminatedString();

                    cell.TypeName = typeName;
                    typeOffsets.Add(typeOffset, typeName);
                    Types.Add(typeName, type);
                }
            }

            // Layouts
            var layoutOffsets = new List <long>();

            foreach (var sheet in Sheets)
            {
                foreach (var cell in sheet.Cells)
                {
                    if (!layoutOffsets.Contains(cell.LayoutOffset.Value))
                    {
                        var layout = new Layout();
                        reader.JumpTo(cell.LayoutOffset.Value, false);

                        long layoutNameOffset   = reader.ReadInt64();
                        long unknownData1Offset = reader.ReadInt64();
                        long unknownData2Offset = reader.ReadInt64();
                        long unknownData3Offset = reader.ReadInt64();
                        long unknownData4Offset = reader.ReadInt64();
                        long unknownData5Offset = reader.ReadInt64();
                        long unknownData6Offset = reader.ReadInt64();
                        long unknownData7Offset = reader.ReadInt64();
                        layout.UnknownData8 = reader.ReadInt64(); // Always 0?

                        if (layout.UnknownData8 != 0)
                        {
                            Console.WriteLine(
                                "WARNING: Layout UnknownData8 != 0! ({0:X})",
                                layout.UnknownData8);
                        }

                        // Unknown Data 1
                        if (unknownData1Offset > 0)
                        {
                            reader.JumpTo(unknownData1Offset, false);
                            layout.UnknownData1 = reader.ReadInt32(); // Always 1?
                        }

                        // Unknown Data 2
                        if (unknownData2Offset > 0)
                        {
                            reader.JumpTo(unknownData2Offset, false);
                            layout.UnknownData2 = reader.ReadSingle();
                            uint padding = reader.ReadUInt32();

                            if (padding != 0)
                            {
                                Console.WriteLine(
                                    "WARNING: Layout UnknownData2 Padding != 0! ({0:X})",
                                    padding);
                            }
                        }

                        // Unknown Data 3
                        if (unknownData3Offset > 0)
                        {
                            reader.JumpTo(unknownData3Offset, false);
                            layout.UnknownData3 = reader.ReadSingle();
                            uint padding = reader.ReadUInt32();

                            if (padding != 0)
                            {
                                Console.WriteLine(
                                    "WARNING: Layout UnknownData3 Padding != 0! ({0:X})",
                                    padding);
                            }
                        }

                        // Unknown Data 4
                        if (unknownData4Offset > 0)
                        {
                            reader.JumpTo(unknownData4Offset, false);
                            layout.UnknownData4 = reader.ReadInt32(); // Always 0?
                        }

                        // Unknown Data 5
                        if (unknownData5Offset > 0)
                        {
                            reader.JumpTo(unknownData5Offset, false);
                            layout.UnknownData5 = reader.ReadInt32();
                        }

                        // Unknown Data 6
                        if (unknownData6Offset > 0)
                        {
                            reader.JumpTo(unknownData6Offset, false);
                            layout.UnknownData6 = reader.ReadInt32(); // Always 1?
                        }

                        // Unknown Data 7
                        if (unknownData7Offset > 0)
                        {
                            reader.JumpTo(unknownData7Offset, false);
                            layout.UnknownData7 = reader.ReadInt32(); // Always 2?
                        }

                        // Layout Name
                        reader.JumpTo(layoutNameOffset, false);
                        layout.Name = reader.ReadNullTerminatedString();

                        layout.Offset    = cell.LayoutOffset;
                        cell.LayoutIndex = layoutOffsets.Count;
                        layoutOffsets.Add(cell.LayoutOffset.Value);
                        Layouts.Add(layout);
                    }
                    else
                    {
                        cell.LayoutIndex = layoutOffsets.IndexOf(
                            cell.LayoutOffset.Value);
                    }
                }
            }

            // Names
            foreach (var sheet in Sheets)
            {
                reader.JumpTo(sheet.NameOffset, false);
                sheet.Name = reader.ReadNullTerminatedString();

                for (int i = 0; i < sheet.Cells.Count; ++i)
                {
                    var cell = sheet.Cells[i];
                    reader.JumpTo(cell.NameOffset.Value, false);
                    cell.Name = reader.ReadNullTerminatedString();
                }
            }
        }
        protected SetObject ReadObject(BINAReader reader,
                                       Dictionary <string, SetObjectType> objectTemplates)
        {
            var   obj           = new SetObject();
            ulong padding1      = reader.ReadUInt64();
            long  objTypeOffset = reader.ReadInt64();
            long  objNameOffset = reader.ReadInt64();

            ushort id            = reader.ReadUInt16();
            ushort groupID       = reader.ReadUInt16();
            ushort parentID      = reader.ReadUInt16();
            ushort parentGroupID = reader.ReadUInt16();

            obj.CustomData.Add("ParentID", new SetObjectParam(
                                   typeof(ushort), parentID));
            obj.CustomData.Add("ParentGroupID", new SetObjectParam(
                                   typeof(ushort), parentGroupID));

            obj.ObjectID = id;
            obj.CustomData.Add("GroupID", new SetObjectParam(
                                   typeof(ushort), groupID));

            var pos            = reader.ReadVector3();
            var rot            = reader.ReadVector3();
            var childPosOffset = reader.ReadVector3();
            var childRotOffset = reader.ReadVector3();

            obj.CustomData.Add("ChildPosOffset", new SetObjectParam(
                                   typeof(Vector3), childPosOffset));

            obj.CustomData.Add("ChildRotOffset", new SetObjectParam(
                                   typeof(Vector3), childRotOffset));

            obj.Transform.Position = pos;
            obj.Transform.Rotation = new Quaternion(rot, true);

            long  extraParamsOffset = reader.ReadInt64();
            ulong unknownCount1     = reader.ReadUInt64();
            ulong unknownCount2     = reader.ReadUInt64();
            ulong padding3          = reader.ReadUInt64();

            long objParamsOffset = reader.ReadInt64();

            // Unknown Count Checks
            if (unknownCount1 != unknownCount2)
            {
                Console.WriteLine(
                    "WARNING: UnknownCount1 ({0}) != UnknownCount2 ({1})",
                    unknownCount1, unknownCount2);
            }

            if (unknownCount1 > 1)
            {
                Console.WriteLine(
                    "WARNING: UnknownCount1 > 1 ({0})",
                    unknownCount1);
            }

            // Extra Parameter Offsets
            var extraParamOffsets = new long[unknownCount1];

            reader.JumpTo(extraParamsOffset, false);

            for (uint i = 0; i < unknownCount1; ++i)
            {
                extraParamOffsets[i] = reader.ReadInt64();
                ulong padding5 = reader.ReadUInt64(); // TODO: Make sure this is correct
            }

            // Extra Parameters
            for (uint i = 0; i < unknownCount1; ++i)
            {
                reader.JumpTo(extraParamOffsets[i], false);
                ulong padding6 = reader.ReadUInt64();

                long  extraParamNameOffset = reader.ReadInt64();
                ulong extraParamLength     = reader.ReadUInt64();
                long  extraParamDataOffset = reader.ReadInt64();

                // Extra Parameter Data
                reader.JumpTo(extraParamDataOffset, false);
                var data = reader.ReadBytes((int)extraParamLength);

                // Extra Parameter Name
                reader.JumpTo(extraParamNameOffset, false);
                string name = reader.ReadNullTerminatedString();

                // Parse Data
                switch (name)
                {
                case "RangeSpawning":
                {
                    obj.CustomData.Add("RangeIn", new SetObjectParam(
                                           typeof(float), BitConverter.ToSingle(data, 0)));

                    obj.CustomData.Add("RangeOut", new SetObjectParam(
                                           typeof(float), BitConverter.ToSingle(data, 4)));
                    continue;
                }
                }

                Console.WriteLine($"WARNING: Unknown extra parameter type {name}");
                obj.CustomData.Add(name, new SetObjectParam(
                                       data.GetType(), data));
            }

            // Object Name
            reader.JumpTo(objNameOffset, false);
            string objName = reader.ReadNullTerminatedString();

            obj.CustomData.Add("Name", new SetObjectParam(typeof(string), objName));

            // Object Type
            reader.JumpTo(objTypeOffset, false);
            string objType = reader.ReadNullTerminatedString();

            obj.ObjectType = objType;

            if (!objectTemplates.ContainsKey(objType))
            {
                Console.WriteLine(
                    "WARNING: Skipped {0} because there is no template for type {1}!",
                    objName, objType);
                Console.WriteLine("Params at: {0:X}",
                                  objParamsOffset + reader.Offset);
                return(null);
            }

            //Console.WriteLine("\"{1}\" Params at: {0:X}",
            //    objParamsOffset + reader.Offset, objName);
            var template = objectTemplates[objType];

            // Object Parameters
            reader.JumpTo(objParamsOffset, false);
            foreach (var param in template.Parameters)
            {
                obj.Parameters.Add(ReadParameter(reader, param));
            }

            // Additional Padding
            var rawDataLenExtra = template.GetExtra("RawByteLength");

            if (uint.TryParse(rawDataLenExtra?.Value, out var rawLength))
            {
                uint paramLen = (uint)(reader.BaseStream.Position -
                                       objParamsOffset - reader.Offset);

                if (paramLen != rawLength)
                {
                    obj.CustomData.Add("RawByteLength", new SetObjectParam(
                                           typeof(uint), rawLength));
                }
            }

            // Padding Checks
            if (padding1 != 0)
            {
                Console.WriteLine($"WARNING: Obj Padding1 != 0 ({padding1})");
            }

            if (padding3 != 0)
            {
                Console.WriteLine($"WARNING: Obj Padding3 != 0 ({padding3})");
            }

            return(obj);
        }
Exemple #26
0
        // Methods
        public override void Load(Stream fileStream,
                                  Dictionary <string, SetObjectType> objectTemplates)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            //Set Name (hardcoded to ASSUME it's four characters long)
            long namePosition = reader.BaseStream.Position; //Save position so we can jump back after reading name, type and parameters

            reader.JumpAhead(0xC);
            Name = reader.ReadNullTerminatedString();
            reader.JumpTo(namePosition, true);
            reader.JumpAhead(0x2C);

            uint objectCount       = reader.ReadUInt32();
            uint objectTableOffset = reader.ReadUInt32();
            uint groupCount        = reader.ReadUInt32();
            uint groupTableOffset  = reader.ReadUInt32();

            //Objects
            reader.JumpTo(objectTableOffset, false);
            for (uint i = 0; i < objectCount; i++)
            {
                var obj = new SetObject();
                obj.ObjectID = i;
                uint objectNameOffset = reader.ReadUInt32();
                uint objectTypeOffset = reader.ReadUInt32();
                obj.UnknownBytes       = reader.ReadBytes(16); //parameter.Unknown 16 bytes (pattern tends to be 40 00 00 00/01 (depending on whether object is activated by a group) 00 00 00 00 00 00 00 00 00 00 00 00)
                obj.Transform.Position = reader.ReadVector3();
                obj.DrawDistance       = reader.ReadSingle();
                obj.Transform.Rotation = reader.ReadQuaternion();
                uint parameterCount  = reader.ReadUInt32();
                uint parameterOffset = reader.ReadUInt32();

                long position = reader.BaseStream.Position; //Save position so we can jump back after reading name, type and parameters

                //Object Name and Type
                reader.JumpTo(objectNameOffset, false);
                obj.ObjectName = reader.ReadNullTerminatedString();
                reader.JumpTo(objectTypeOffset, false);
                obj.ObjectType = reader.ReadNullTerminatedString();

                reader.JumpTo(parameterOffset, false);
                //Object Parameters
                for (uint c = 0; c < parameterCount; c++)
                {
                    var  parameter     = new SetObjectParam();
                    uint parameterType = reader.ReadUInt32();
                    switch (parameterType)
                    {
                    case 0:     //boolean
                        parameter.DataType = typeof(bool);
                        parameter.Data     = reader.ReadUInt32() == 1;
                        parameter.Unknown1 = reader.ReadUInt32();
                        parameter.Unknown2 = reader.ReadUInt32();
                        parameter.Unknown3 = reader.ReadUInt32();
                        break;

                    case 1:     //int
                        parameter.DataType = typeof(int);
                        parameter.Data     = reader.ReadInt32();
                        parameter.Unknown1 = reader.ReadUInt32();
                        parameter.Unknown2 = reader.ReadUInt32();
                        parameter.Unknown3 = reader.ReadUInt32();
                        break;

                    case 2:     //single
                        parameter.DataType = typeof(float);
                        parameter.Data     = reader.ReadSingle();
                        parameter.Unknown1 = reader.ReadUInt32();
                        parameter.Unknown2 = reader.ReadUInt32();
                        parameter.Unknown3 = reader.ReadUInt32();
                        break;

                    case 3:     //string
                        uint offset = reader.ReadUInt32();
                        parameter.Unknown1 = reader.ReadUInt32();
                        parameter.Unknown2 = reader.ReadUInt32();
                        parameter.Unknown3 = reader.ReadUInt32();

                        long stringParameterPosition = reader.BaseStream.Position;     //Save position so we can jump back after reading name, type and parameters
                        reader.JumpTo(offset, false);

                        parameter.DataType = typeof(string);
                        parameter.Data     = reader.ReadNullTerminatedString();

                        reader.JumpTo(stringParameterPosition, true);
                        break;

                    case 4:     //Vector3
                        parameter.DataType = typeof(Vector3);
                        parameter.Data     = reader.ReadVector3();
                        parameter.Unknown3 = reader.ReadUInt32();
                        break;

                    case 6:     //uint
                        parameter.DataType = typeof(uint);
                        parameter.Data     = reader.ReadUInt32();
                        parameter.Unknown1 = reader.ReadUInt32();
                        parameter.Unknown2 = reader.ReadUInt32();
                        parameter.Unknown3 = reader.ReadUInt32();
                        break;

                    default:
                        Console.WriteLine("Unhandled Data Type!");
                        break;
                    }
                    obj.Parameters.Add(parameter);
                }

                //Save Object and jump back for the next one
                Objects.Add(obj);
                reader.JumpTo(position, true);
            }

            //Groups
            reader.JumpTo(groupTableOffset, false);
            for (uint i = 0; i < groupCount; i++)
            {
                var  group           = new SetGroup();
                uint groupNameOffset = reader.ReadUInt32();
                uint groupTypeOffset = reader.ReadUInt32();
                group.GroupObjectCount = reader.ReadUInt32();
                uint groupObjectListOffset = reader.ReadUInt32();

                long position = reader.BaseStream.Position; //Save position so we can jump back after reading name, type and object list

                //Group Name and Type
                reader.JumpTo(groupNameOffset, false);
                group.GroupName = reader.ReadNullTerminatedString();
                reader.JumpTo(groupTypeOffset, false);
                group.GroupType = reader.ReadNullTerminatedString();

                //Group Object List
                reader.JumpTo(groupObjectListOffset, false);
                for (uint c = 0; c < group.GroupObjectCount; c++)
                {
                    reader.JumpAhead(4);
                    group.ObjectIDs.Add(reader.ReadUInt32());
                }

                //Save Group and jump back for the next one
                Groups.Add(group);
                reader.JumpTo(position, true);
            }
        }
Exemple #27
0
        public override void Load(Stream fileStream)
        {
            // Read PACx Header
            var reader = new BINAReader(fileStream);

            Header.Read(reader);

            // Read Node Trees and compute Data Entry count
            var typeTree  = new NodeTree(reader);
            var fileTrees = new NodeTree[typeTree.DataNodeIndices.Count];

            int  dataEntryCount = 0;
            Node dataNode;

            for (int i = 0; i < fileTrees.Length; ++i)
            {
                dataNode = typeTree.Nodes[typeTree.DataNodeIndices[i]];
                reader.JumpTo((long)dataNode.Data);
                fileTrees[i]    = new NodeTree(reader);
                dataEntryCount += fileTrees[i].DataNodeIndices.Count;
            }

            // Read Data Entries
            var dataEntries    = new DataEntry[dataEntryCount];
            int dataEntryIndex = -1;

            foreach (var fileTree in fileTrees)
            {
                for (int i = 0; i < fileTree.DataNodeIndices.Count; ++i)
                {
                    dataNode = fileTree.Nodes[fileTree.DataNodeIndices[i]];
                    reader.JumpTo((long)dataNode.Data);
                    dataEntries[++dataEntryIndex] = new DataEntry(reader);
                }
            }

            // Read Data
            int dataSize, bytesRead;

            foreach (var dataEntry in dataEntries)
            {
                if (dataEntry.DataType == DataEntryTypes.NotHere)
                {
                    continue;
                }

                reader.JumpTo(dataEntry.DataOffset);
                dataSize = dataEntry.Data.Length;

                do
                {
                    bytesRead = reader.Read(dataEntry.Data, 0, dataSize);
                    if (bytesRead == 0)
                    {
                        throw new EndOfStreamException(
                                  "Could not read file data from PAC.");
                    }

                    dataSize -= bytesRead;
                }while (dataSize > 0);
            }

            // Get file names and add files to archive
            var builder = new StringBuilder(byte.MaxValue);

            dataEntryIndex = -1;

            foreach (var fileTree in fileTrees)
            {
                for (int i = 0; i < fileTree.DataNodeIndices.Count; ++i)
                {
                    var dataEntry = dataEntries[++dataEntryIndex];
                    if (dataEntry.DataType == DataEntryTypes.NotHere)
                    {
                        continue;
                    }

                    dataNode = fileTree.Nodes[fileTree.DataNodeIndices[i]];

                    // Read extension
                    reader.JumpTo(dataEntry.ExtensionOffset);
                    builder.Append('.');
                    builder.Append(reader.ReadNullTerminatedString());

                    // Get full file name
                    string pth;
                    for (int i2 = dataNode.ParentIndex; i2 > 0;)
                    {
                        pth = fileTree.Nodes[i2].Name;
                        i2  = fileTree.Nodes[i2].ParentIndex;

                        if (string.IsNullOrEmpty(pth))
                        {
                            continue;
                        }

                        builder.Insert(0, pth);
                    }

                    // Add to archive
                    Data.Add(new ArchiveFile(
                                 builder.ToString(),
                                 dataEntry.Data));

                    builder.Clear();
                }
            }
        }
Exemple #28
0
        // Methods
        public override void Load(Stream fileStream,
                                  Dictionary <string, SetObjectType> objectTemplates)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header = reader.ReadHeader();

            reader.JumpAhead(0x2C); // Skip "test" string
            uint objectLength = reader.ReadUInt32();
            uint objectOffset = reader.ReadUInt32();
            uint groupLength  = reader.ReadUInt32();
            uint groupOffset  = reader.ReadUInt32();

            // Data
            reader.JumpTo(objectOffset, false);
            for (uint i = 0; i < objectLength; ++i)
            {
                Objects.Add(ReadObject());
            }

            // TODO: Read Groups
            // TODO: Read Footer

            // Sub-Methods
            SetObject ReadObject()
            {
                // Object Entry
                var  obj        = new SetObject();
                uint nameOffset = reader.ReadUInt32();
                uint typeOffset = reader.ReadUInt32();

                reader.JumpAhead(16);

                obj.Transform.Position = reader.ReadVector3();
                reader.JumpAhead(4);
                obj.Transform.Rotation = new Quaternion(reader.ReadVector4());

                uint paramCount  = reader.ReadUInt32();
                uint paramOffset = reader.ReadUInt32();

                // Object Parameters
                long pos = reader.BaseStream.Position;

                for (uint i = 0; i < paramCount; ++i)
                {
                    reader.JumpTo(paramOffset + i * 0x14, false);
                    obj.Parameters.Add(ReadParam());
                }

                // TODO: Read Object Name

                // Object Type
                reader.JumpTo(typeOffset, false);
                obj.ObjectType = reader.ReadNullTerminatedString();

                reader.JumpTo(pos, true);
                return(obj);
            }

            SetObjectParam ReadParam()
            {
                var  param = new SetObjectParam();
                uint type  = reader.ReadUInt32();

                switch (type)
                {
                case 0:
                    param.DataType = typeof(bool);
                    param.Data     = (reader.ReadUInt32() == 1);
                    break;

                case 1:
                    param.DataType = typeof(int);
                    param.Data     = reader.ReadInt32();
                    break;

                case 2:
                    param.DataType = typeof(float);
                    param.Data     = reader.ReadSingle();
                    break;

                case 3:
                    uint offset = reader.ReadUInt32();
                    uint amount = reader.ReadUInt32();

                    if (amount != 1)
                    {
                        Console.WriteLine($"WARNING: Amount != 1. ({amount})");
                    }

                    long pos = reader.BaseStream.Position;
                    reader.JumpTo(offset, false);

                    param.DataType = typeof(string);
                    param.Data     = reader.ReadNullTerminatedString();
                    reader.JumpTo(pos, true);
                    break;

                case 4:
                    param.DataType = typeof(Vector3);
                    param.Data     = reader.ReadVector3();
                    break;

                case 6:
                    param.DataType = typeof(uint);
                    param.Data     = reader.ReadUInt32();
                    break;

                default:
                    Console.WriteLine($"WARNING: Unknown object param type {type}!");
                    return(null);
                }

                return(param);
            }
        }
Exemple #29
0
        // Methods
        public override void Load(Stream fileStream)
        {
            // Header
            var reader = new BINAReader(fileStream);

            Header      = reader.ReadHeader();
            IsBigEndian = reader.IsBigEndian;

            uint gismOffset = reader.ReadUInt32();

            UnknownBoolean1 = reader.ReadUInt32(); // TODO: Find out what this is.
            uint gismoCount = reader.ReadUInt32();

            Gismos = new LWGismo[gismoCount];

            // Containers
            uint containerOffset = reader.ReadUInt32();

            reader.JumpTo(containerOffset, false);

            for (uint i = 0; i < gismoCount; ++i)
            {
                var gismo = new LWGismo();

                // Container 1
                uint fileNameOffset    = reader.ReadUInt32();
                uint fileNameOffset2   = reader.ReadUInt32(); // TODO: Find out what this is for.
                uint unknownNameOffset = reader.ReadUInt32();
                gismo.Unknown1 = reader.ReadUInt32();

                gismo.Unknown2    = reader.ReadSingle();
                gismo.Unknown3    = reader.ReadSingle();
                gismo.DoesAnimate = (reader.ReadUInt32() == 1);
                uint havokOffset = reader.ReadUInt32();

                gismo.UnknownBoolean1 = (reader.ReadUInt32() == 1);
                uint containerTwoOffset = reader.ReadUInt32();

                if (fileNameOffset != fileNameOffset2)
                {
                    Console.WriteLine(
                        "WARNING: fileNameOffset != fileNameOffset2 ({0} vs. {1})",
                        fileNameOffset, fileNameOffset2);
                }

                long curPos = reader.BaseStream.Position;
                gismo.FileName = reader.GetString(fileNameOffset, true);

                // Havok Array
                reader.JumpTo(havokOffset, false);
                uint unknown10 = reader.ReadUInt32();

                if (unknown10 != 0)
                {
                    Console.WriteLine("WARNING: Unknown10 != 0 ({0})!", unknown10);
                }

                gismo.HavokName = reader.GetString();

                // Container 2
                reader.JumpTo(containerTwoOffset, false);

                gismo.UnknownBoolean2 = (reader.ReadUInt32() == 1);
                gismo.UnknownBoolean3 = (reader.ReadUInt32() == 1);

                gismo.Unknown5 = reader.ReadSingle();
                gismo.Unknown6 = reader.ReadSingle();
                gismo.Unknown7 = reader.ReadSingle();

                gismo.Unknown8       = reader.ReadSingle();
                gismo.RotationAmount = reader.ReadSingle();
                gismo.Unknown9       = reader.ReadSingle();

                reader.BaseStream.Position = curPos;
                Gismos[i] = gismo;
            }
        }