Exemplo n.º 1
0
 public ArkStructColor(IOMemoryStream ms, ArkClassName structType)
 {
     b = ms.ReadByte();
     g = ms.ReadByte();
     r = ms.ReadByte();
     a = ms.ReadByte();
 }
Exemplo n.º 2
0
 public override void ReadStruct(IOMemoryStream ms, UAssetFile f, StructProperty s)
 {
     b = ms.ReadByte();
     g = ms.ReadByte();
     r = ms.ReadByte();
     a = ms.ReadByte();
 }
Exemplo n.º 3
0
        public byte byteValue;   //Use ONLY if the above boolean is true

        public override void Read(IOMemoryStream ms, UAssetFile f)
        {
            if (length == 1)
            {
                //Read in the enum name
                enumName = ms.ReadNameTableEntry(f);

                //That can be None, but cannot be null.
                if (enumName == null)
                {
                    throw new Exception("Tried to read enum type, but got null!");
                }

                isNormalByte = enumName == "None";

                //If that type is a None, this is not an enum. If it is, this is an enum. Read the name.
                if (isNormalByte)
                {
                    byteValue = ms.ReadByte();
                    ms.ReadInt();
                }
                else
                {
                    enumValue = ms.ReadNameTableEntry(f);
                }
            }
            else if (length == 8)
            {
                //If the length is 8, this is an enum. It seems to follow like this...
                //Enum name
                //Int, usually 0
                //Enum value
                //Int, usually 0
                enumType     = ms.ReadNameTableEntry(f);
                ms.position += 4;
                enumValue    = ms.ReadNameTableEntry(f);
                ms.position += 4;
            }
            else if (length == 0)
            {
                //Just skip.
                throw new NotImplementedException();
                ms.position += 4;
            }
            else
            {
                throw new Exception($"Warning: Unknown ByteProperty length '{length}'.");
            }
        }
Exemplo n.º 4
0
        public override void Read(IOMemoryStream ms)
        {
            //Read first enum
            enumName = ms.ReadUEString();

            //If this is None, this is a normal byte
            isNormalByte = enumName == "None";

            //Read accordingly
            if (isNormalByte)
            {
                byteValue = ms.ReadByte();
            }
            else
            {
                enumValue = ms.ReadUEString(); //Untested! Todo
            }
        }
Exemplo n.º 5
0
        public byte byteValue;         //Use ONLY if the above boolean is true

        public InlineByteProperty(IOMemoryStream ms) : base(ms)
        {
            //Read in the enum name
            enumName = ms.ReadInlineArkClassname();

            //That can be None, but cannot be null.
            if (enumName == null)
            {
                throw new Exception("Tried to read enum type, but got null!");
            }

            isNormalByte = enumName.IsNone();

            //If that type is a None, this is not an enum. If it is, this is an enum. Read the name.
            if (isNormalByte)
            {
                byteValue = ms.ReadByte();
            }
            else
            {
                enumValue = ms.ReadInlineArkClassname();
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
 public override void Read(IOMemoryStream ms)
 {
     value = ms.ReadByte();
 }
Exemplo n.º 8
0
 public override void Read(IOMemoryStream ms, UAssetFile f)
 {
     data = ms.ReadByte();
 }
 public InlineBoolProperty(IOMemoryStream ms) : base(ms)
 {
     value = ms.ReadByte() != 0;
 }
Exemplo n.º 10
0
 public override void Read(IOMemoryStream ms, UAssetFile f)
 {
     flag = ms.ReadByte() != 0;
 }