void ReadHeader() { saveVersion = ms.ReadShort(); //Game version. Important for later. //Depending on the version, read this in switch (saveVersion) { case 5: ark.gameTime = ms.ReadFloat(); break; case 6: nameTableOffset = ms.ReadInt(); propertiesBlockOffset = ms.ReadInt(); ark.gameTime = ms.ReadFloat(); break; case 7: case 8: binaryDataTableOffset = ms.ReadInt(); unknownData1 = ms.ReadInt(); nameTableOffset = ms.ReadInt(); propertiesBlockOffset = ms.ReadInt(); ark.gameTime = ms.ReadFloat(); break; case 9: binaryDataTableOffset = ms.ReadInt(); unknownData1 = ms.ReadInt(); nameTableOffset = ms.ReadInt(); propertiesBlockOffset = ms.ReadInt(); ark.gameTime = ms.ReadFloat(); saveCount = ms.ReadInt(); break; default: throw new Exception($"Unknown game version {saveVersion.ToString()}, expected 5-9."); } }
public static void ProcessImages(List <string> readErrors, DeltaExportPatch patch) { //Clean up any old and bad paths Console.WriteLine("Cleaning up old image conversions..."); if (Directory.Exists("./Lib/UModel/in_temp/")) { Directory.Delete("./Lib/UModel/in_temp/", true); } if (Directory.Exists("./Lib/UModel/out_temp/")) { Directory.Delete("./Lib/UModel/out_temp/", true); } //Make structre Directory.CreateDirectory("./Lib/UModel/in_temp/"); Directory.CreateDirectory("./Lib/UModel/out_temp/"); //Get the queue var queue = patch.queued_images; //First, we copy all packages to a temporary path with their index Console.WriteLine($"Now copying {queue.Count} images..."); for (int i = 0; i < queue.Count; i++) { string source = queue[i].pathname; File.Copy(source, $"./Lib/UModel/in_temp/{i}.uasset"); } //Now, run the conversion Console.WriteLine("Now converting images using UModel..."); Process p = Process.Start(new ProcessStartInfo { Arguments = "", FileName = "go.bat", WorkingDirectory = "Lib\\UModel\\", UseShellExecute = true }); p.WaitForExit(); //Now, load and process these images int ok = 0; Console.WriteLine($"Now processing {queue.Count} images..."); for (int i = 0; i < queue.Count; i += 1) { QueuedImage q = queue[i]; bool status = false; try { //Get the directory. It's a little janky, as files are stored in subdirs string[] results = Directory.GetFiles($"./Lib/UModel/out_temp/{i}/"); if (results.Length != 1) { throw new Exception("None or too many results found for image."); } //Open FileStream on this using (FileStream imgStream = new FileStream(results[0], FileMode.Open, FileAccess.Read)) { //Now, begin reading the TGA data https://en.wikipedia.org/wiki/Truevision_TGA IOMemoryStream imgReader = new IOMemoryStream(imgStream, true); imgReader.position += 3 + 5; //Skip intro, it will always be known imgReader.ReadShort(); //Will always be 0 imgReader.ReadShort(); //Will aways be 0 short width = imgReader.ReadShort(); short height = imgReader.ReadShort(); byte colorDepth = imgReader.ReadByte(); imgReader.ReadByte(); //Now, we can begin reading image data //This appears to be bugged for non-square images right now. using (Image <Rgba32> img = new Image <Rgba32>(width, height)) { //Read file byte[] channels; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (colorDepth == 32) { //Read four channels channels = imgReader.ReadBytes(4); //Set pixel img[x, width - y - 1] = new Rgba32(channels[2], channels[1], channels[0], channels[3]); } else if (colorDepth == 24) { //Read three channels channels = imgReader.ReadBytes(3); //Set pixel img[x, width - y - 1] = new Rgba32(channels[2], channels[1], channels[0]); } } } //Apply mods if (q.mods == ImageModifications.White) { ApplyWhiteMod(img); } //Save original image using (MemoryStream ms = new MemoryStream()) { img.SaveAsPng(ms); ms.Position = 0; patch.asset_manager.Upload(Program.config.GetProfile().upload_images + q.hiId + FORMAT_TYPE, ms); } //Now, downscale img.Mutate(x => x.Resize(64, 64)); //Save thumbnail using (MemoryStream ms = new MemoryStream()) { img.SaveAsPng(ms, new PngEncoder { CompressionLevel = 9 }); ms.Position = 0; patch.asset_manager.Upload(Program.config.GetProfile().upload_images + q.loId + FORMAT_TYPE, ms); } status = true; ok++; } } } catch (Exception ex) { Console.WriteLine($"Failed to process image {q.classname} with error {ex.Message}"); readErrors.Add($"Failed to process image {q.classname} with error {ex.Message} {ex.StackTrace}"); } //Now, add to persistent storage patch.persist.external_assets.Add(new DeltaExportBranchExternalAsset { name = q.name, patch = patch.tag, sha1 = q.sha1, time = DateTime.UtcNow, id_hires = q.hiId, id_lores = q.loId, ok = status }); } Log.WriteSuccess("ImageTool", $"Processed and uploading {ok}/{queue.Count} images."); queue.Clear(); //Clean up any old and bad paths Console.WriteLine("Cleaning up..."); if (Directory.Exists("./Lib/UModel/in_temp/")) { Directory.Delete("./Lib/UModel/in_temp/", true); } if (Directory.Exists("./Lib/UModel/out_temp/")) { Directory.Delete("./Lib/UModel/out_temp/", true); } }
public override void Read(IOMemoryStream ms, UAssetFile f) { data = ms.ReadShort(); }