public static ArkContainer GetCryopodCreature(this GameObject gameObject)
        {
            StructPropertyList customData      = gameObject.GetPropertyValue <IArkArray, ArkArrayStruct>("CustomItemDatas").FirstOrDefault() as StructPropertyList;
            PropertyStruct     customDataBytes = customData?.Properties.FirstOrDefault(p => p.NameString == "CustomDataBytes") as PropertyStruct;
            PropertyArray      byteArrays      = (customDataBytes?.Value as StructPropertyList)?.Properties.FirstOrDefault(property => property.NameString == "ByteArrays") as PropertyArray;
            ArkArrayStruct     byteArraysValue = byteArrays?.Value as ArkArrayStruct;

            if (!(((byteArraysValue?[0] as StructPropertyList)?.Properties.FirstOrDefault(p => p.NameString == "Bytes") as PropertyArray)?.Value is ArkArrayUInt8 creatureBytes))
            {
                return(null);
            }
            ArkContainer creature = new ArkContainer(creatureBytes);

            /*
             * ArkArrayUInt8 saddleBytes = ((byteArraysValue?[1] as StructPropertyList)?.Properties.FirstOrDefault(p => p.NameString == "Bytes") as PropertyArray)?.Value as ArkArrayUInt8;
             *
             * using (MemoryStream stream = new MemoryStream(saddleBytes?.ToArray())) {
             *  using (ArkArchive archive = new ArkArchive(stream)) {
             *      int objectCount = archive.ReadInt();
             *
             *      //List<GameObject> objects = new List<GameObject>();
             *      //for (int i = 0; i < objectCount; i++) {
             *      //    //objects.Add(new GameObject(archive));
             *      //}
             *  }
             * }
             */
            return(creature);
        }
Exemplo n.º 2
0
        protected override void RunCommand(IEnumerable <string> args)
        {
            List <string> argsList = args.ToList();

            if (showCommandHelp(argsList))
            {
                return;
            }

            string clusterDirectory = argsList[0];
            string outputDirectory  = argsList[1];

            ArkDataManager.LoadData(GlobalOptions.Language);

            List <Action> tasks = GlobalOptions.Parallel ? new List <Action>() : null;

            Stopwatch stopwatch = new Stopwatch(GlobalOptions.UseStopWatch);

            foreach (string path in Directory.EnumerateFiles(clusterDirectory))
            {
                Action task = () => {
                    try {
                        ArkCloudInventory cloudInventory = new ArkCloudInventory().ReadBinary <ArkCloudInventory>(path, ReadingOptions.Create());

                        CustomDataContext context = new CustomDataContext {
                            ObjectContainer = cloudInventory
                        };

                        IPropertyContainer arkData = cloudInventory.InventoryData.GetPropertyValue <IPropertyContainer>("MyArkData");

                        CommonFunctions.WriteJson(Path.Combine(outputDirectory, path + ".json"), (generator, writingOptions) => {
                            generator.WriteStartObject();

                            ArkArrayStruct tamedDinosData = arkData.GetPropertyValue <ArkArrayStruct>("ArkTamedDinosData");
                            if (tamedDinosData != null && tamedDinosData.Any())
                            {
                                generator.WriteArrayFieldStart("creatures");
                                foreach (IStruct dinoStruct in tamedDinosData)
                                {
                                    IPropertyContainer dino = (IPropertyContainer)dinoStruct;
                                    ArkContainer container  = null;
                                    if (cloudInventory.InventoryVersion == 1)
                                    {
                                        ArkArrayUInt8 byteData = dino.GetPropertyValue <ArkArrayUInt8>("DinoData");

                                        container = new ArkContainer(byteData);
                                    }
                                    else if (cloudInventory.InventoryVersion == 3)
                                    {
                                        ArkArrayInt8 byteData = dino.GetPropertyValue <ArkArrayInt8>("DinoData");

                                        container = new ArkContainer(byteData);
                                    }

                                    ObjectReference dinoClass = dino.GetPropertyValue <ObjectReference>("DinoClass");
                                    // Skip "BlueprintGeneratedClass " = 24 chars
                                    string dinoClassName = dinoClass.ObjectString.ToString().Substring(24);
                                    generator.WriteStartObject();

                                    generator.WriteField("type",
                                                         ArkDataManager.HasCreatureByPath(dinoClassName) ? ArkDataManager.GetCreatureByPath(dinoClassName).Name : dinoClassName);

                                    // NPE for unknown versions
                                    Creature creature = new Creature(container.Objects[0], container);
                                    generator.WriteObjectFieldStart("data");
                                    creature.writeAllProperties(generator, context, writeAllFields);
                                    generator.WriteEndObject();

                                    generator.WriteEndObject();
                                }

                                generator.WriteEndArray();
                            }

                            ArkArrayStruct arkItems = arkData.GetPropertyValue <ArkArrayStruct>("ArkItems");
                            if (arkItems != null)
                            {
                                List <Item> items = new List <Item>();
                                foreach (IStruct itemStruct in arkItems)
                                {
                                    IPropertyContainer item    = (IPropertyContainer)itemStruct;
                                    IPropertyContainer netItem = item.GetPropertyValue <IPropertyContainer>("ArkTributeItem");

                                    items.Add(new Item(netItem));
                                }

                                if (items.Any())
                                {
                                    generator.WritePropertyName("items");
                                    Inventory.writeInventoryLong(generator, context, items, writeAllFields);
                                }
                            }

                            generator.WriteEndObject();
                        }, writingOptions);
                    } catch (Exception ex) {
                        Console.Error.WriteLine("Found potentially corrupt cluster data: " + path);
                        if (GlobalOptions.Verbose)
                        {
                            Console.Error.WriteLine(ex.Message);
                            Console.Error.WriteLine(ex.StackTrace);
                        }
                    }
                };

                if (tasks != null)
                {
                    tasks.Add(task);
                }
                else
                {
                    task();
                }
            }

            if (tasks != null)
            {
                Parallel.ForEach(tasks, task => task());
            }

            stopwatch.Stop("Loading cluster data and writing info");
            stopwatch.Print();
        }