示例#1
0
        public NodeClass GetNodeClass()
        {
            var root = new NodeClass("EntityLibraries");

            foreach (var library in Libraries)
            {
                var node = library.GetNodeClass();
                root.Children.Add(node);
            }

            return(root);
        }
示例#2
0
        public void Deserialize(XmlElement xml)
        {
            var attrs    = xml.Attributes;
            var children = xml.ChildNodes;

            if (children.Count > 1)
            {
                throw new InvalidOperationException("Malformed EntityReference node -- too many children!");
            }

            var entNode = xml.FirstChild as XmlElement;

            if (entNode == null)
            {
                throw new InvalidOperationException("Malformed EntityReference node -- could not get the Entity node!");
            }

            if (attrs.Count != 0)
            {
                var uidAttr = attrs.GetNamedItem("UID");

                if (uidAttr != null)
                {
                    var uidHex = AttributeData.Parse(uidAttr.Value);

                    if (Use32Bit)
                    {
                        UID = BitConverter.ToInt32(uidHex, 0);
                    }
                    else
                    {
                        UID = BitConverter.ToInt64(uidHex, 0);
                    }
                }
            }

            if (UID == 0)
            {
                throw new InvalidOperationException("Attempted to deserialize a reference with no UID attribute!");
            }

            // yuck!!!
            GroupNode  = new NodeClass(0x256A1FF9);
            EntityNode = new NodeClass(entNode);

            GroupNode.Children.Add(EntityNode);
        }
示例#3
0
        public bool Equals(NodeClass obj)
        {
            var equal = true;

            equal = (obj.Hash == Hash) &&
                    (obj.Children.Count == Children.Count) &&
                    (obj.Attributes.Count == Attributes.Count);

            if (equal)
            {
                for (int i = 0; i < Attributes.Count; i++)
                {
                    var myAttr  = Attributes[i];
                    var datAttr = obj.Attributes[i];

                    equal = (myAttr.Hash == datAttr.Hash) &&
                            (myAttr.Data.GetHashCode() == datAttr.Data.GetHashCode());

                    if (!equal)
                    {
                        break;
                    }
                }
            }

            if (equal)
            {
                for (int i = 0; i < Children.Count; i++)
                {
                    var myChild  = Children[i];
                    var datChild = obj.Children[i];

                    equal = myChild.Equals(datChild);

                    if (!equal)
                    {
                        break;
                    }
                }
            }

            // will either be true or false
            return(equal);
        }
示例#4
0
        public void LoadBinary(string filename)
        {
            using (var stream = new BinaryStream(filename))
            {
                Debug.WriteLine(">> Reading infos header...");
                var infosOffset = stream.ReadInt32();
                var infosCount  = stream.ReadInt32();

                Use32Bit = ((stream.Length - (infosCount * 0xC)) == infosOffset);

                Debug.WriteLine(">> Reading FCB header...");
                var magic = stream.ReadInt32();

                if (magic != Magic)
                {
                    throw new InvalidOperationException("Bad magic, no FCB data to parse!");
                }

                var type = stream.ReadInt16();

                if (type != Type)
                {
                    throw new InvalidOperationException("FCB library reported the incorrect type?!");
                }

                stream.Position += 2;                // ;)

                var totalCount = stream.ReadInt32(); // * 3
                var nodesCount = stream.ReadInt32(); // * 4

                var dataOffset = (int)stream.Position;

                var memSize      = ((totalCount * 3) + nodesCount) * 4;
                var memSizeAlign = Memory.Align(memSize, 16);

#if DEBUG
                Console.WriteLine("[Library.Header]");
                Console.WriteLine($"  Total: {totalCount}");
                Console.WriteLine($"  Nodes: {nodesCount}");
                Console.WriteLine($"  MemSize: {memSize:X8}");
#endif

                // read the infos first!
                Debug.WriteLine(">> Reading infos...");
                stream.Position = infosOffset;

                var nInfosTotal = 0;
                var nInfosNodes = 0;

                var refDatas = new Dictionary <int, EntityReferenceData>(infosCount);

                for (int i = 0; i < infosCount; i++)
                {
                    var refData = new EntityReferenceData(stream, Use32Bit);

                    nInfosTotal += refData.TotalCount;
                    nInfosNodes += refData.NodesCount;

                    refDatas.Add(refData.Offset, refData);
                }

                var count1Diff = (totalCount - nInfosTotal);
                var count2Diff = (nodesCount - nInfosNodes);

#if DEBUG
                Console.WriteLine("[Library.Infos]");
                Console.WriteLine($"  Total: {nInfosTotal}");
                Console.WriteLine($"  Nodes: {nInfosNodes}");
                Console.WriteLine("[Library.Logging]");
                Console.WriteLine($"  TotalDiff: {count1Diff}");
                Console.WriteLine($"  NodesDiff: {count2Diff}");
#endif

                // read fcb data
                Debug.WriteLine(">> Reading libraries...");
                stream.Position = dataOffset;

                var root = new NodeClass(stream);

                Libraries = new List <EntityLibrary>(root.Children.Count);

                foreach (var library in root.Children)
                {
                    // deserialize from the class
                    var lib = new EntityLibrary()
                    {
                        Use32Bit = Use32Bit,
                    };

                    lib.Deserialize(library);

                    // update UIDs
                    foreach (var entry in lib.Entries)
                    {
                        var node   = entry.GroupNode;
                        var offset = node.Offset;

                        if (refDatas.ContainsKey(offset))
                        {
                            var entRef = refDatas[offset];
                            entry.UID = entRef.UID;
                        }
                    }

                    Libraries.Add(lib);
                }

                Console.WriteLine($"Finished reading {Libraries.Count} libraries. Collected {Utils.GetTotalNumberOfNodes(root)} nodes in total.");
            }
        }