Exemple #1
0
        public static ArkDinoEntry Convert(UAssetFileBlueprint f, UAssetCacheBlock cache, Dictionary <string, PropertyReader> dinoEntries)
        {
            //Open reader
            PropertyReader reader = new PropertyReader(f.GetFullProperties(cache));

            //Get the dino settings
            UAssetFileBlueprint settingsFileAdult = ArkDinoFood.GetAdultFile(f, cache);
            UAssetFileBlueprint settingsFileBaby  = ArkDinoFood.GetBabyFile(f, cache);

            //Get time
            int time = (int)Math.Round((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds);

            //Get status component
            UAssetFileBlueprint statusComponent = ArkDinoEntryStatus.GetFile(f, cache);
            PropertyReader      statusReader    = new PropertyReader(statusComponent.GetFullProperties(cache));

            //Use name tag to find entry
            string tag = reader.GetPropertyStringOrName("DinoNameTag");

            if (!dinoEntries.ContainsKey(tag))
            {
                throw new Exception($"Could not find dino entry for '{f.classname}' (tag '{tag}')");
            }
            PropertyReader entry = dinoEntries[tag];

            //Now, load the material used for the dino image
            UAssetFileMaterial entryMaterial = entry.GetProperty <ObjectProperty>("DinoMaterial").GetReferencedFileMaterial();

            UAssetFileMaterial.TextureParameterValue entryMaterialTexture = entryMaterial.textureParameters[0];
            ClassnamePathnamePair entryTexture = entryMaterialTexture.prop.GetReferencedFile();

            //Read
            ArkDinoEntry e = new ArkDinoEntry
            {
                screen_name                       = reader.GetPropertyString("DescriptiveName", null),
                colorizationIntensity             = reader.GetPropertyFloat("ColorizationIntensity", 1),
                babyGestationSpeed                = reader.GetPropertyFloat("BabyGestationSpeed", -1),
                extraBabyGestationSpeedMultiplier = reader.GetPropertyFloat("ExtraBabyGestationSpeedMultiplier", -1),
                babyAgeSpeed                      = reader.GetPropertyFloat("BabyAgeSpeed", null),
                extraBabyAgeMultiplier            = reader.GetPropertyFloat("ExtraBabyAgeSpeedMultiplier", -1),
                useBabyGestation                  = reader.GetPropertyBool("bUseBabyGestation", false),
                statusComponent                   = ArkDinoEntryStatus.Convert(statusComponent, statusReader),
                adultFoods    = ArkDinoFood.Convert(settingsFileAdult, cache),
                childFoods    = ArkDinoFood.Convert(settingsFileBaby, cache),
                classname     = f.classname,
                blueprintPath = "N/A",
                captureTime   = time,
                icon          = ImageTool.QueueImage(entryTexture, ImageTool.ImageModifications.None),
                icon_white    = ImageTool.QueueImage(entryTexture, ImageTool.ImageModifications.White)
            };

            //Finally, read stats
            ArkStatsRipper.DoRipStats(statusReader, e);

            return(e);
        }
        /// <summary>
        /// Extracts data and returns the package
        /// </summary>
        public Stream Run(UAssetCacheBlock cache, out string hash)
        {
            //Get pathnames that match this
            List <ArkAsset>[] files = DiscoveryService.DiscoverFiles(installation, this);

            //Load mod info if this is a mod. TODO

            //Load Primal Data for mod
            string              primalDataPathname = "/Game/PrimalEarth/CoreBlueprints/PrimalGameData_BP";
            ArkAsset            primalDataNs       = ArkAsset.GetAssetFromGame(primalDataPathname, installation);
            UAssetFileBlueprint primalData         = UAssetFileBlueprint.OpenFile(primalDataNs.filename, false, primalDataNs.name, this.installation.contentFolder);
            PropertyReader      primalDataReader   = new PropertyReader(primalData.GetFullProperties(cache));

            //Load all dino entries
            var dinoEntriesArray = primalDataReader.GetProperty <ArrayProperty>("DinoEntries");
            Dictionary <string, PropertyReader> dinoEntries = new Dictionary <string, PropertyReader>(); //Dino entries mapped by tag name

            foreach (var i in dinoEntriesArray.props)
            {
                var    ii  = ((ObjectProperty)i).GetReferencedFileBlueprint();
                var    iir = new PropertyReader(ii.GetFullProperties(cache));
                string tag = iir.GetPropertyStringOrName("DinoNameTag");
                if (!dinoEntries.ContainsKey(tag))
                {
                    dinoEntries.Add(tag, iir);
                }
                else
                {
                    dinoEntries[tag] = iir;
                }
            }

            //Import dinos
            var dinos = DinoExtractorService.ExtractDinos(cache, files[(int)ArkAssetType.Dino], patch, primalDataReader, dinoEntries);

            //Import items
            var items = ItemExtractorService.ExtractItems(cache, files[(int)ArkAssetType.InventoryItem], patch);

            Log.WriteSuccess("Export-Package-Run", $"Package {name}: Processed {dinos.Count} dinos, {items.Count} items");

            //Return the package
            return(CompilePackage(new Dictionary <string, object>
            {
                { "items.bson", items },
                { "dinos.bson", dinos }
            }, out hash));
        }
Exemple #3
0
        public static DinosaurEntry Convert(UAssetFileBlueprint f, UAssetCacheBlock cache, DeltaExportPatch patch, PropertyReader primalDataReader, Dictionary <string, PropertyReader> dinoEntries)
        {
            //Open reader
            PropertyReader reader = new PropertyReader(f.GetFullProperties(cache));

            //Get the dino settings
            UAssetFileBlueprint settingsFileAdult = ArkDinoFoodConverter.GetAdultFile(f, cache);
            UAssetFileBlueprint settingsFileBaby  = ArkDinoFoodConverter.GetBabyFile(f, cache);

            //Get status component
            UAssetFileBlueprint statusComponent = ArkDinoEntryStatusConverter.GetFile(f, cache);
            PropertyReader      statusReader    = new PropertyReader(statusComponent.GetFullProperties(cache));

            //Use name tag to find entry
            string         tag   = reader.GetPropertyStringOrName("DinoNameTag");
            PropertyReader entry = dinoEntries[tag];

            //Now, load the material used for the dino image
            UAssetFileMaterial entryMaterial = entry.GetProperty <ObjectProperty>("DinoMaterial").GetReferencedFileMaterial();

            UAssetFileMaterial.TextureParameterValue entryMaterialTexture = entryMaterial.textureParameters[0];
            ClassnamePathnamePair entryTexture = entryMaterialTexture.prop.GetReferencedFile();

            //Read
            DinosaurEntry e = new DinosaurEntry
            {
                screen_name                       = reader.GetPropertyString("DescriptiveName", null),
                colorizationIntensity             = reader.GetPropertyFloat("ColorizationIntensity", 1),
                babyGestationSpeed                = reader.GetPropertyFloat("BabyGestationSpeed", -1),
                extraBabyGestationSpeedMultiplier = reader.GetPropertyFloat("ExtraBabyGestationSpeedMultiplier", -1),
                babyAgeSpeed                      = reader.GetPropertyFloat("BabyAgeSpeed", null),
                extraBabyAgeMultiplier            = reader.GetPropertyFloat("ExtraBabyAgeSpeedMultiplier", -1),
                useBabyGestation                  = reader.GetPropertyBool("bUseBabyGestation", false),
                statusComponent                   = ArkDinoEntryStatusConverter.Convert(statusComponent, statusReader),
                adultFoods = ArkDinoFoodConverter.Convert(settingsFileAdult, cache),
                childFoods = ArkDinoFoodConverter.Convert(settingsFileBaby, cache),
                classname  = DeltaDataExtractor.Program.TrimArkClassname(f.classname),
                icon       = ImageTool.QueueImage(entryTexture, ImageTool.ImageModifications.None, patch),
            };

            //Finally, read stats
            ArkStatsRipper.DoRipStats(statusReader, e);

            return(e);
        }
Exemple #4
0
        public static void ImportDinos(UAssetCacheBlock cache, Dictionary <string, string> map, List <string> readErrors)
        {
            //Open PrimalGameData
            Console.WriteLine("Opening PrimalGameData...");
            UAssetFileBlueprint primalGameData       = UAssetFileBlueprint.OpenFile(Program.GAME_ROOT_PATH + @"PrimalEarth\CoreBlueprints\PrimalGameData_BP.uasset", false, "PrimalGameData_BP", Program.GAME_ROOT_PATH);
            PropertyReader      primalGameDataReader = new PropertyReader(primalGameData.GetFullProperties(cache));

            Console.WriteLine("PrimalGameData opened.");

            //Now, open all dino entries
            Console.WriteLine("Opening dino entries...");
            Dictionary <string, PropertyReader> dinoEntries = new Dictionary <string, PropertyReader>();
            ArrayProperty entriesArray = primalGameDataReader.GetProperty <ArrayProperty>("DinoEntries");
            int           entriesCount = 0;

            foreach (var en in entriesArray.props)
            {
                //Open
                UAssetFileBlueprint bp       = ((ObjectProperty)en).GetReferencedFileBlueprint();
                PropertyReader      bpReader = new PropertyReader(bp.GetFullProperties(cache));
                string name = bpReader.GetPropertyStringOrName("DinoNameTag");
                if (dinoEntries.ContainsKey(name))
                {
                    dinoEntries.Remove(name);
                }
                dinoEntries.Add(name, bpReader);
                entriesCount++;
            }
            Console.WriteLine($"Finished opening dino entries. Found {entriesCount} entries.");

            //Now, open binder
            ClassListBinder binder = ClassListBinder.OpenBinder("classes.json");

            //Find base dino
            ClassListEntry dinoBase = binder.ClassData.SearchForClass("Dino_Character_BP");

            if (dinoBase == null)
            {
                throw new Exception("Failed to find dino base class.");
            }

            //Get children
            List <ClassListEntry> dinoClasses = dinoBase.GetAllChildren();

            Console.WriteLine($"Found {dinoClasses.Count} dino classes to import.");

            //Loop classes and start reading
            List <ArkDinoEntry> dinos = new List <ArkDinoEntry>();

            foreach (ClassListEntry e in dinoClasses)
            {
                try
                {
                    //Find this dino file in the map
                    if (!map.ContainsKey(e.Name))
                    {
                        throw new Exception($"Failed to find dino {e.Name} in uasset map.");
                    }
                    string pathname = map[e.Name];

                    //Now, open the UASSET file
                    UAssetFileBlueprint f = UAssetFileBlueprint.OpenFile(pathname, false, e.Name, Program.GAME_ROOT_PATH);

                    //Create a dino entry
                    ArkDinoEntry entry = ArkDinoEntry.Convert(f, cache, dinoEntries);
                    dinos.Add(entry);
                } catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"Failed to import dino {e.Name} with error {ex.Message}!");
                    readErrors.Add($"Failed to import dino {e.Name} with error {ex.Message}{ex.StackTrace}!");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }

            //Now, save
            Console.WriteLine($"Finished reading {dinos.Count}/{dinoClasses.Count} dinos. Saving now...");
            File.WriteAllText(Program.GetOutputDir() + "dinos.json", JsonConvert.SerializeObject(dinos, Formatting.Indented));

            Console.WriteLine("Done importing dinos.");
        }