Esempio n. 1
0
        public static string GetAssetJsonData(PakReader.PakReader reader, IEnumerable <FPakEntry> entriesList, bool loadImageInBox = false)
        {
            Stream[] AssetStreamArray = new Stream[3];

            foreach (FPakEntry entry in entriesList)
            {
                switch (Path.GetExtension(entry.Name.ToLowerInvariant()))
                {
                case ".ini":
                    FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        FWindow.FMain.AssetPropertiesBox_Main.SyntaxHighlighting = ResourceLoader.LoadHighlightingDefinition("Ini.xshd");
                    });
                    using (var s = reader.GetPackageStream(entry))
                        using (var r = new StreamReader(s))
                            return(r.ReadToEnd());

                case ".uproject":
                case ".uplugin":
                case ".upluginmanifest":
                    using (var s = reader.GetPackageStream(entry))
                        using (var r = new StreamReader(s))
                            return(r.ReadToEnd());

                case ".locmeta":
                    using (var s = reader.GetPackageStream(entry))
                        return(JsonConvert.SerializeObject(new LocMetaFile(s), Formatting.Indented));

                case ".locres":
                    using (var s = reader.GetPackageStream(entry))
                        return(JsonConvert.SerializeObject(new LocResFile(s).Entries, Formatting.Indented));

                case ".udic":
                    using (var s = reader.GetPackageStream(entry))
                        using (var r = new BinaryReader(s))
                            return(JsonConvert.SerializeObject(new UDicFile(r).Header, Formatting.Indented));

                case ".bin":
                    if (string.Equals(entry.Name, "/FortniteGame/AssetRegistry.bin") || !entry.Name.Contains("AssetRegistry"))     //MEMORY ISSUE
                    {
                        break;
                    }

                    using (var s = reader.GetPackageStream(entry))
                        return(JsonConvert.SerializeObject(new AssetRegistryFile(s), Formatting.Indented));

                default:
                    if (entry.Name.EndsWith(".uasset"))
                    {
                        AssetStreamArray[0] = reader.GetPackageStream(entry);
                    }

                    if (entry.Name.EndsWith(".uexp"))
                    {
                        AssetStreamArray[1] = reader.GetPackageStream(entry);
                    }

                    if (entry.Name.EndsWith(".ubulk"))
                    {
                        AssetStreamArray[2] = reader.GetPackageStream(entry);
                    }
                    break;
                }
            }

            AssetReader ar = GetAssetReader(AssetStreamArray);

            if (ar != null)
            {
                if (loadImageInBox)
                {
                    foreach (ExportObject eo in ar.Exports)
                    {
                        switch (eo)
                        {
                        case Texture2D texture:
                            SKImage image = texture.GetImage();
                            if (image != null)
                            {
                                using (var data = image.Encode())
                                    using (var stream = data.AsStream())
                                    {
                                        ImageSource img = ImagesUtility.GetImageSource(stream);
                                        FWindow.FMain.Dispatcher.InvokeAsync(() =>
                                        {
                                            FWindow.FMain.ImageBox_Main.Source = BitmapFrame.Create((BitmapSource)img); //thread safe and fast af

                                            if (FWindow.FMain.MI_Auto_Save_Images.IsChecked)                            //auto save images
                                            {
                                                ImagesUtility.SaveImage(FProp.Default.FOutput_Path + "\\Icons\\" + FWindow.FCurrentAsset + ".png");
                                            }
                                        });
                                    }
                            }
                            return(JsonConvert.SerializeObject(texture.textures, Formatting.Indented));

                        case USoundWave sound:
                            using (sound)
                            {
                                byte[] s = readSound(sound);
                                if (s != null)
                                {
                                    string path = FProp.Default.FOutput_Path + "\\Sounds\\" + FWindow.FCurrentAsset + ".ogg";
                                    File.WriteAllBytes(path, s);

                                    //open sound
                                    if (FProp.Default.FOpenSounds)
                                    {
                                        FoldersUtility.OpenWithDefaultProgram(path);
                                    }
                                }

                                GC.Collect();
                                GC.WaitForPendingFinalizers();
                                return(JsonConvert.SerializeObject(sound.base_object, Formatting.Indented));
                            }
                        }
                    }
                }

                return(JsonConvert.SerializeObject(ar.Exports, Formatting.Indented));
            }

            return(string.Empty);
        }
Esempio n. 2
0
        public static string GetAssetJsonData(PakReader.PakReader reader, IEnumerable <FPakEntry> entriesList, bool loadImageInBox = false)
        {
            DebugHelper.WriteLine("Assets: Gathering info about {0}", entriesList.ElementAt(0).Name);

            Stream[] AssetStreamArray = new Stream[3];

            foreach (FPakEntry entry in entriesList)
            {
                #region AUTO EXTRACT RAW
                if (FProp.Default.FAutoExtractRaw)
                {
                    string path       = FProp.Default.FOutput_Path + "\\Exports\\" + entry.Name;
                    string pWExt      = FoldersUtility.GetFullPathWithoutExtension(entry.Name);
                    string subfolders = pWExt.Substring(0, pWExt.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase));

                    Directory.CreateDirectory(FProp.Default.FOutput_Path + "\\Exports\\" + subfolders);
                    Stream stream = reader.GetPackageStream(entry);
                    using (var fStream = File.OpenWrite(path))
                        using (stream)
                        {
                            stream.CopyTo(fStream);
                        }

                    if (File.Exists(path))
                    {
                        DebugHelper.WriteLine("Assets: Successfully extracted data of {0}", entry.Name);

                        new UpdateMyConsole(Path.GetFileName(path), CColors.Blue).Append();
                        new UpdateMyConsole(" successfully exported", CColors.White, true).Append();
                    }
                    else //just in case
                    {
                        DebugHelper.WriteLine("Assets: Couldn't extract data of {0}", entry.Name);

                        new UpdateMyConsole("Bruh moment\nCouldn't export ", CColors.White).Append();
                        new UpdateMyConsole(Path.GetFileName(path), CColors.Blue, true).Append();
                    }
                }
                #endregion

                switch (Path.GetExtension(entry.Name.ToLowerInvariant()))
                {
                case ".ini":
                    FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        FWindow.FMain.AssetPropertiesBox_Main.SyntaxHighlighting = ResourceLoader.LoadHighlightingDefinition("Ini.xshd");
                    });
                    using (var s = reader.GetPackageStream(entry))
                        using (var r = new StreamReader(s))
                            return(r.ReadToEnd());

                case ".uproject":
                case ".uplugin":
                case ".upluginmanifest":
                    using (var s = reader.GetPackageStream(entry))
                        using (var r = new StreamReader(s))
                            return(r.ReadToEnd());

                case ".locmeta":
                    using (var s = reader.GetPackageStream(entry))
                        return(JsonConvert.SerializeObject(new LocMetaFile(s), Formatting.Indented));

                case ".locres":
                    using (var s = reader.GetPackageStream(entry))
                        return(JsonConvert.SerializeObject(new LocResFile(s).Entries, Formatting.Indented));

                case ".udic":
                    using (var s = reader.GetPackageStream(entry))
                        using (var r = new BinaryReader(s))
                            return(JsonConvert.SerializeObject(new UDicFile(r).Header, Formatting.Indented));

                case ".bin":
                    if (string.Equals(entry.Name, "/FortniteGame/AssetRegistry.bin") || !entry.Name.Contains("AssetRegistry"))     //MEMORY ISSUE
                    {
                        break;
                    }

                    using (var s = reader.GetPackageStream(entry))
                        return(JsonConvert.SerializeObject(new AssetRegistryFile(s), Formatting.Indented));

                default:
                    if (entry.Name.EndsWith(".uasset"))
                    {
                        AssetStreamArray[0] = reader.GetPackageStream(entry);
                    }

                    if (entry.Name.EndsWith(".uexp"))
                    {
                        AssetStreamArray[1] = reader.GetPackageStream(entry);
                    }

                    if (entry.Name.EndsWith(".ubulk"))
                    {
                        AssetStreamArray[2] = reader.GetPackageStream(entry);
                    }
                    break;
                }
            }

            AssetReader ar = GetAssetReader(AssetStreamArray);
            if (ar != null)
            {
                if (loadImageInBox)
                {
                    foreach (ExportObject eo in ar.Exports)
                    {
                        switch (eo)
                        {
                        case Texture2D texture:
                            SKImage image = texture.GetImage();
                            if (image != null)
                            {
                                using (var data = image.Encode())
                                    using (var stream = data.AsStream())
                                    {
                                        ImageSource img = ImagesUtility.GetImageSource(stream);
                                        FWindow.FMain.Dispatcher.InvokeAsync(() =>
                                        {
                                            FWindow.FMain.ImageBox_Main.Source = BitmapFrame.Create((BitmapSource)img); //thread safe and fast af

                                            if (FWindow.FMain.MI_Auto_Save_Images.IsChecked)                            //auto save images
                                            {
                                                ImagesUtility.SaveImage(FProp.Default.FOutput_Path + "\\Icons\\" + FWindow.FCurrentAsset + ".png");
                                            }
                                        });
                                    }
                            }
                            return(JsonConvert.SerializeObject(texture.textures, Formatting.Indented));

                        case USoundWave sound:
                            using (sound)
                            {
                                byte[] s = readSound(sound);
                                if (s != null)
                                {
                                    string path = FProp.Default.FOutput_Path + "\\Sounds\\" + FWindow.FCurrentAsset + ".ogg";
                                    File.WriteAllBytes(path, s);

                                    //open sound
                                    if (FProp.Default.FOpenSounds)
                                    {
                                        FoldersUtility.OpenWithDefaultProgram(path);
                                    }
                                }

                                GC.Collect();
                                GC.WaitForPendingFinalizers();
                                return(JsonConvert.SerializeObject(sound.base_object, Formatting.Indented));
                            }
                        }
                    }
                }

                string stringData = JsonConvert.SerializeObject(ar.Exports, Formatting.Indented);

                #region AUTO SAVE JSON
                if (FProp.Default.FAutoSaveJson)
                {
                    string name = Path.GetFileNameWithoutExtension(entriesList.ElementAt(0).Name);
                    string path = FProp.Default.FOutput_Path + "\\JSONs\\" + name + ".json";
                    if (!string.IsNullOrEmpty(stringData))
                    {
                        File.WriteAllText(path, stringData);
                        if (File.Exists(path))
                        {
                            DebugHelper.WriteLine("Assets: Successfully saved serialized data of {0}", entriesList.ElementAt(0).Name);

                            new UpdateMyConsole(name, CColors.Blue).Append();
                            new UpdateMyConsole("'s Json data successfully saved", CColors.White, true).Append();
                        }
                        else //just in case
                        {
                            DebugHelper.WriteLine("Assets: Couldn't save serialized data of {0}", entriesList.ElementAt(0).Name);

                            new UpdateMyConsole("Bruh moment\nCouldn't export ", CColors.White).Append();
                            new UpdateMyConsole(name, CColors.Blue, true).Append();
                        }
                    }
                }
                #endregion

                return(stringData);
            }

            return(string.Empty);
        }