示例#1
0
        public PartitionReader LoadEbx(string name, params Type[] enumTypes)
        {
            var dataManager = this._DataManager;

            if (dataManager == null)
            {
                return(null);
            }

            var info = dataManager.GetEbxInfo(name);

            if (info == null)
            {
                return(null);
            }

            using (var data = new MemoryStream())
            {
                dataManager.LoadData(info, data);
                data.Position = 0;

                var partition = new PartitionFile();
                partition.Deserialize(data);
                return(new PartitionReader(partition, enumTypes));
            }
        }
        public void DumpPartition(EbxInfo ebxInfo, PartitionFile partition)
        {
            string[] unknownTypeNames;
            if (HasPlotFlagId(partition, out unknownTypeNames) == false)
            {
                return;
            }

            if (unknownTypeNames.Length > 0)
            {
                return;

                throw new NotSupportedException();
            }

            using (var reader = new PartitionReader(
                       partition,
                       typeof(PlotConditionType),
                       typeof(PlotActionType),
                       typeof(PlotLogicOperator)))
            {
                var allObjects = reader.GetObjects().ToArray();
                foreach (var kv in this._Handlers)
                {
                    var typeName = kv.Key;
                    var handler  = kv.Value;
                    foreach (var data in reader.GetObjectsOfType(typeName))
                    {
                        handler(ebxInfo, this, typeName, data);
                    }
                }
            }
        }
        private static bool HasPlotFlagId(PartitionFile partition, out string[] unknownTypeNames)
        {
            var idTypeIndex = partition.TypeDefinitionEntries.FindIndex(tde => tde.Name == "PlotFlagId");

            if (idTypeIndex < 0)
            {
                unknownTypeNames = null;
                return(false);
            }

            var referencingFieldIndices =
                partition
                .FieldDefinitionEntries
                .FindAllIndices(fde => fde.TypeIndex == idTypeIndex)
                .ToArray();
            var referencingTypeIndices =
                partition
                .TypeDefinitionEntries
                .FindAllIndices(tde => referencingFieldIndices.Any(
                                    i => tde.FieldCount > 0 &&
                                    i >= tde.FieldStartIndex &&
                                    i < tde.FieldStartIndex + tde.FieldCount) == true)
                .ToArray();

            var queue = new Queue <int>();

            foreach (var referencingTypeIndex in referencingTypeIndices)
            {
                queue.Enqueue(referencingTypeIndex);
            }

            var interestingTypeIndices = new List <int>();

            while (queue.Count > 0)
            {
                var referencingTypeIndex = queue.Dequeue();
                var referencingType      = partition.TypeDefinitionEntries[referencingTypeIndex];
                if (referencingType.Flags.DataType == Frostbite3.ResourceFormats.Partition.DataType.List ||
                    TypeHelpers.IsNested(referencingType.Name) == true)
                {
                    var parentFieldIndices =
                        partition
                        .FieldDefinitionEntries
                        .FindAllIndices(
                            fde => fde.TypeIndex == referencingTypeIndex)
                        .ToArray();
                    var parentTypeIndices =
                        partition
                        .TypeDefinitionEntries.FindAllIndices(
                            tde => tde.FieldCount > 0 &&
                            parentFieldIndices.Any(
                                i => i >= tde.FieldStartIndex &&
                                i < tde.FieldStartIndex + tde.FieldCount) == true)
                        .ToArray();
                    foreach (var parentTypeIndex in parentTypeIndices)
                    {
                        queue.Enqueue(parentTypeIndex);
                    }
                    continue;
                }
                interestingTypeIndices.Add(referencingTypeIndex);
            }

            var interestingTypes =
                interestingTypeIndices
                .Distinct()
                .Select(i => partition.TypeDefinitionEntries[i])
                .ToArray();
            var interestingTypeNames = interestingTypes.Select(tde => tde.Name).ToArray();

            unknownTypeNames = interestingTypeNames.Where(v => TypeHelpers.IsKnown(v) == false).ToArray();
            return(true);
        }