Example #1
0
        internal void Read(EndianBinaryReader reader)
        {
            int osageNameCount = reader.ReadInt32();
            int osageBoneCount = reader.ReadInt32();

            reader.SeekCurrent(4);
            long osageBonesOffset = reader.ReadOffset();
            long osageNamesOffset = reader.ReadOffset();
            long nodesOffset      = reader.ReadOffset();
            int  boneNameCount    = reader.ReadInt32();
            long boneNamesOffset  = reader.ReadOffset();
            long entriesOffset    = reader.ReadOffset();

            reader.ReadAtOffset(osageBonesOffset, () =>
            {
                OsageBones.Capacity = osageBoneCount;
                for (int i = 0; i < osageBoneCount; i++)
                {
                    var osageBone = new ExOsageBone();
                    osageBone.Read(reader);
                    OsageBones.Add(osageBone);
                }
            });

            reader.ReadAtOffset(osageNamesOffset, () =>
            {
                OsageNames.Capacity = osageNameCount;
                for (int i = 0; i < osageNameCount; i++)
                {
                    OsageNames.Add(reader.ReadStringOffset(StringBinaryFormat.NullTerminated));
                }
            });

            reader.ReadAtOffset(nodesOffset, () =>
            {
                while (true)
                {
                    string nodeSignature = reader.ReadStringOffset(StringBinaryFormat.NullTerminated);
                    long nodeOffset      = reader.ReadOffset();

                    if (nodeOffset == 0)
                    {
                        break;
                    }

                    reader.ReadAtOffset(nodeOffset, () =>
                    {
                        if (!ExNode.NodeFactory.TryGetValue(nodeSignature, out var nodeConstructor))
                        {
                            return;
                        }

                        var node = nodeConstructor();
                        node.Read(reader);
                        Nodes.Add(node);
                    });
                }
            });

            reader.ReadAtOffset(boneNamesOffset, () =>
            {
                BoneNames.Capacity = boneNameCount;
                for (int i = 0; i < boneNameCount; i++)
                {
                    BoneNames.Add(reader.ReadStringOffset(StringBinaryFormat.NullTerminated));
                }
            });

            reader.ReadAtOffset(entriesOffset, () =>
            {
                while (true)
                {
                    var entry = new ExEntry();
                    entry.Read(reader);

                    if (entry.Field00 == 0)
                    {
                        break;
                    }

                    Entries.Add(entry);
                }
            });
        }
Example #2
0
        internal void Read(EndianBinaryReader reader)
        {
            int osageNameCount = reader.ReadInt32();
            int osageBoneCount = reader.ReadInt32();

            reader.SeekCurrent(4);
            long osageBonesOffset = reader.ReadOffset();
            long osageNamesOffset = reader.ReadOffset();
            long exBlocksOffset   = reader.ReadOffset();
            int  boneNameCount    = reader.ReadInt32();
            long boneNamesOffset  = reader.ReadOffset();
            long exEntriesOffset  = reader.ReadOffset();

            reader.ReadAtOffset(osageBonesOffset, () =>
            {
                OsageBones.Capacity = osageBoneCount;
                for (int i = 0; i < osageBoneCount; i++)
                {
                    var osageBone = new ExOsageBoneEntry();
                    osageBone.Read(reader);
                    OsageBones.Add(osageBone);
                }
            });

            reader.ReadAtOffset(osageNamesOffset, () =>
            {
                OsageNames.Capacity = osageNameCount;
                for (int i = 0; i < osageNameCount; i++)
                {
                    OsageNames.Add(reader.ReadStringOffset(StringBinaryFormat.NullTerminated));
                }
            });

            reader.ReadAtOffset(exBlocksOffset, () =>
            {
                while (true)
                {
                    string exBlockSignature = reader.ReadStringOffset(StringBinaryFormat.NullTerminated);
                    long exBlockDataOffset  = reader.ReadOffset();

                    if (exBlockDataOffset == 0)
                    {
                        break;
                    }

                    ExBlock exBlock = null;

                    reader.ReadAtOffset(exBlockDataOffset, () =>
                    {
                        switch (exBlockSignature)
                        {
                        case "OSG":
                            exBlock = new ExBlockOsage();
                            break;

                        case "EXP":
                            exBlock = new ExBlockExpression();
                            break;

                        case "MOT":
                            exBlock = new ExBlockMotion();
                            break;

                        case "CNS":
                            exBlock = new ExBlockConstraint();
                            break;

                        default:
                            Debug.WriteLine($"WARNING: Unknown ex-block type {exBlockSignature}");
                            break;
                        }

                        if (exBlock != null)
                        {
                            exBlock.Read(reader);
                            ExBlocks.Add(exBlock);
                        }
                    });
                }
            });

            reader.ReadAtOffset(boneNamesOffset, () =>
            {
                BoneNames.Capacity = boneNameCount;
                for (int i = 0; i < boneNameCount; i++)
                {
                    BoneNames.Add(reader.ReadStringOffset(StringBinaryFormat.NullTerminated));
                }
            });

            reader.ReadAtOffset(exEntriesOffset, () =>
            {
                while (true)
                {
                    var exEntry = new ExEntry();
                    exEntry.Read(reader);

                    if (exEntry.Field00 == 0)
                    {
                        break;
                    }

                    Entries.Add(exEntry);
                }
            });
        }