コード例 #1
0
        private static void ImportInstanceInfo(XPathNavigator instanceNode, AdfFile adf)
        {
            InstanceInfo instance = new InstanceInfo()
            {
                Name     = instanceNode.GetAttribute("name", ""),
                NameHash = uint.Parse(instanceNode.GetAttribute("name-hash", "")),
            };

            TypeDefinitionType type;

            Enum.TryParse(instanceNode.GetAttribute("type", ""), out type);
            uint   typeHash   = uint.Parse(instanceNode.GetAttribute("type-hash", ""), CultureInfo.InvariantCulture);
            string typeString = instanceNode.GetAttribute("type-name", "");

            instance.Type     = adf.Runtime.GetTypeDefinition(typeHash);
            instance.TypeHash = instance.Type.NameHash;

            if (!int.TryParse(instanceNode.GetAttribute("inline-array-copy-index", ""), out instance.InlineArrayIndex))
            {
                instance.InlineArrayIndex = -1;
            }
            if (!uint.TryParse(instanceNode.GetAttribute("inline-array-copy-minsz", ""), out instance.MinInlineArraySize))
            {
                instance.MinInlineArraySize = 0;
            }

            if (type != instance.Type.Type)
            {
                throw new InvalidOperationException("do not touch things like type and type-name in the xml file, yo");
            }

            instance.Members = new List <AdfFile.InstanceMemberInfo>();
            // parse members
            var membersList = instanceNode.Select("member");

            // normal array or structure
            foreach (XPathNavigator memberNode in membersList)
            {
                instance.Members.Add(ImportInstanceMemberInfo(memberNode, adf));
            }

            // add it
            adf.AddInstanceInfo(instance);
        }
コード例 #2
0
        private static void ImportInstanceInfo(XPathNavigator instanceNode, AdfFile adf)
        {
            InstanceInfo instance = new InstanceInfo()
            {
                Name     = instanceNode.GetAttribute("name", ""),
                NameHash = uint.Parse(instanceNode.GetAttribute("name-hash", "")),
            };

            TypeDefinitionType type;

            Enum.TryParse(instanceNode.GetAttribute("type", ""), out type);
            uint   typeHash   = uint.Parse(instanceNode.GetAttribute("type-hash", ""), CultureInfo.InvariantCulture);
            string typeString = instanceNode.GetAttribute("type-name", "");

            instance.Type     = adf.Runtime.GetTypeDefinition(typeHash);
            instance.TypeHash = instance.Type.NameHash;

            if (!int.TryParse(instanceNode.GetAttribute("inline-array-copy-index", ""), out instance.InlineArrayIndex))
            {
                instance.InlineArrayIndex = -1;
            }
            if (!uint.TryParse(instanceNode.GetAttribute("inline-array-copy-minsz", ""), out instance.MinInlineArraySize))
            {
                instance.MinInlineArraySize = 0;
            }

            if (type != instance.Type.Type)
            {
                throw new InvalidOperationException("do not touch things like type and type-name in the xml file, yo");
            }

            instance.Members = new List <AdfFile.InstanceMemberInfo>();

            // Hold the contents of the last Array (A[int8])
            List <byte> stringArray = new List <byte>();

            // parse members
            instance.Members.Add(null); // prepare the future
            var memberNode = instanceNode.SelectSingleNode("member");

            instance.Members[0] = (ImportInstanceMemberInfo(memberNode, instance, adf, stringArray));

            var stringArrayMemberIndex = 0;

            foreach (var member in instance.Members)
            {
                if (member.Id == 2)
                {
                    break;
                }
                ++stringArrayMemberIndex;
            }
            var stringArrayMember = instance.Members[stringArrayMemberIndex];

            // Generate the string array (type is array of int8)
            foreach (byte b in stringArray) // the foreach is sooo overkill...
            {
                var subMember = new AdfFile.InstanceMemberInfo()
                {
                    Type     = TypeDefinitionType.Primitive,
                    TypeHash = AdfTypeHashes.Primitive.Int8,
                    Name     = null,
                };
                subMember.Data.WriteByte(b);
                stringArrayMember.Members.Add(subMember);
            }

            // add instance to ADF structure
            adf.AddInstanceInfo(instance);
        }