Beispiel #1
0
        public static byte[] Make(SarcData input, DDSLoadResult dds, PatchTemplate targetPatch, LayoutPatch layout)
        {
            if (layout != null)
            {
                var layoutres = SwitchThemesCommon.PatchLayouts(input, layout.Files);
                if (layoutres == BflytFile.PatchResult.Fail)
                {
                    Window.Alert("One of the target files for the selected layout patch is missing in the SZS, you are probably using an already patched SZS or the wrong layout");
                    return(null);
                }
                else if (layoutres == BflytFile.PatchResult.CorruptedFile)
                {
                    Window.Alert("A layout in this SZS is missing a pane required for the selected layout patch, you are probably using an already patched SZS or the wrong layout");
                    return(null);
                }
            }

            if (SwitchThemesCommon.PatchBntx(input, dds, targetPatch) == BflytFile.PatchResult.Fail)
            {
                Window.Alert(
                    "Can't build this theme: the szs you opened doesn't contain some information needed to patch the bntx," +
                    "without this information it is not possible to rebuild the bntx." +
                    "You should use an original or at least working szs");
                return(null);
            }
            var res = SwitchThemesCommon.PatchBgLayouts(input, targetPatch);

            if (res == BflytFile.PatchResult.Fail)
            {
                Window.Alert("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                return(null);
            }
            else if (res == BflytFile.PatchResult.CorruptedFile)
            {
                Window.Alert("This file has been already patched with another tool and is not compatible, you should get an unmodified layout.");
                return(null);
            }
            var sarc = SARC.PackN(input);

            return(ManagedYaz0.Compress(sarc.Item2, 1, (int)sarc.Item1));
        }
Beispiel #2
0
        private void PatchButtonClick(object sender, EventArgs e)
        {
            if (CommonSzs == null || targetPatch == null)
            {
                MessageBox.Show("Open a valid theme first !");
                return;
            }
            if (tbBntxFile.Text.Trim() == "")
            {
                if (LayoutPatchList.SelectedIndex <= 0)
                {
                    MessageBox.Show("There is nothing to patch");
                    return;
                }
                if (MessageBox.Show("Are you sure you want to continue without selecting a bntx ?", "", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }
            else if (!File.Exists(tbBntxFile.Text))
            {
                MessageBox.Show($"{tbBntxFile.Text} not found !");
                return;
            }

            SaveFileDialog sav = new SaveFileDialog()
            {
                Filter   = "szs file|*.szs",
                FileName = targetPatch.szsName
            };

            if (sav.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var res = BflytFile.PatchResult.OK;

            if (tbBntxFile.Text.Trim() != "")
            {
                if (!BgImageCheck(true))
                {
                    return;
                }

                if (SwitchThemesCommon.PatchBntx(CommonSzs, File.ReadAllBytes(tbBntxFile.Text), targetPatch) == BflytFile.PatchResult.Fail)
                {
                    MessageBox.Show(
                        "Can't build this theme: the szs you opened doesn't contain some information needed to patch the bntx," +
                        "without this information it is not possible to rebuild the bntx." +
                        "You should use an original or at least working szs", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (targetPatch.NXThemeName == "home" && AlbumIcon != null)
                {
                    if (!AlbumIcon.EndsWith(".dds") && !AlbumIcontoDDS())
                    {
                        return;
                    }
                    SwitchThemesCommon.PatchBntxTexture(CommonSzs, File.ReadAllBytes(AlbumIcon), "RdtIcoPvr_00^s", 0x02000000);
                }

                res = SwitchThemesCommon.PatchBgLayouts(CommonSzs, targetPatch);

                if (res == BflytFile.PatchResult.Fail)
                {
                    MessageBox.Show("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                    return;
                }
                else if (res == BflytFile.PatchResult.CorruptedFile)
                {
                    MessageBox.Show("This file has been already patched with another tool and is not compatible, you should get an unmodified layout.");
                    return;
                }
            }

            if (LayoutPatchList.SelectedIndex != 0)
            {
                var layoutres = SwitchThemesCommon.PatchLayouts(CommonSzs, LayoutPatchList.SelectedItem as LayoutPatch, targetPatch.NXThemeName == "home", !UseAnim.Checked);
                if (layoutres == BflytFile.PatchResult.Fail)
                {
                    MessageBox.Show("One of the target files for the selected layout patch is missing in the SZS, you are probably using an already patched SZS");
                    return;
                }
                else if (layoutres == BflytFile.PatchResult.CorruptedFile)
                {
                    MessageBox.Show("A layout in this SZS is missing a pane required for the selected layout patch, you are probably using an already patched SZS");
                    return;
                }
                layoutres = SwitchThemesCommon.PatchAnimations(CommonSzs, (LayoutPatchList.SelectedItem as LayoutPatch).Anims);
                if (layoutres != BflytFile.PatchResult.OK)
                {
                    MessageBox.Show("Error while patching the animations !");
                    return;
                }
            }

            var sarc = SARC.PackN(CommonSzs);

            File.WriteAllBytes(sav.FileName, ManagedYaz0.Compress(sarc.Item2, 3, (int)sarc.Item1));
            GC.Collect();

            if (res == BflytFile.PatchResult.AlreadyPatched)
            {
                MessageBox.Show("Done, This file has already been patched before.\r\nIf you have issues try with an unmodified file");
            }
            else
            {
                MessageBox.Show("Done");
            }
        }
Beispiel #3
0
        static bool SZSFromArgs(string[] args)
        {
            string GetArg(string start)
            {
                var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(a.Split('=')[1]);
                }
            }

            if (args.Length < 2)
            {
                return(false);
            }

            string Target      = args[1];
            var    CommonSzs   = SARCExt.SARC.UnpackRamN(ManagedYaz0.Decompress(File.ReadAllBytes(Target)));
            var    targetPatch = SwitchThemesCommon.DetectSarc(CommonSzs, DefaultTemplates.templates);

            if (targetPatch == null)
            {
                Console.WriteLine("Unknown szs file");
                return(false);
            }

            string Image = args.Where(x => x.EndsWith(".dds") || x.EndsWith(".jpg") || x.EndsWith(".png") || x.EndsWith("jpeg")).FirstOrDefault();

            if (Image == null || !File.Exists(Image))
            {
                Console.WriteLine("No image file !");
                return(false);
            }
            string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();

            string Output = GetArg("out");

            if (Output == null || Output == "")
            {
                return(false);
            }

            if (!Image.EndsWith(".dds"))
            {
                if (Form1.ImageToDDS(Image, Path.GetTempPath()))
                {
                    Image = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Image) + ".dds");
                }
                else
                {
                    return(false);
                }
            }

            string album = GetArg("ablum");

            if (album != null && !album.EndsWith(".dds"))
            {
                if (Form1.ImageToDDS(album, Path.GetTempPath(), "DXT5", true))
                {
                    album = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(album) + ".dds");
                }
                else
                {
                    return(false);
                }
            }

            try
            {
                var res = BflytFile.PatchResult.OK;

                if (Image != null)
                {
                    if (SwitchThemesCommon.PatchBntx(CommonSzs, File.ReadAllBytes(Image), targetPatch) == BflytFile.PatchResult.Fail)
                    {
                        Console.WriteLine(
                            "Can't build this theme: the szs you opened doesn't contain some information needed to patch the bntx," +
                            "without this information it is not possible to rebuild the bntx." +
                            "You should use an original or at least working szs", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }

                if (album != null && targetPatch.szsName == "ResidentMenu.szs")
                {
                    SwitchThemesCommon.PatchBntxTexture(CommonSzs, File.ReadAllBytes(album), "RdtIcoPvr_00^s", 0x02000000);
                }

                res = SwitchThemesCommon.PatchBgLayouts(CommonSzs, targetPatch);

                if (res == BflytFile.PatchResult.Fail)
                {
                    Console.WriteLine("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                    return(false);
                }
                else if (res == BflytFile.PatchResult.CorruptedFile)
                {
                    Console.WriteLine("This file has been already patched with another tool and is not compatible, you should get an unmodified layout.");
                    return(false);
                }

                if (Layout != null)
                {
                    var layoutres = SwitchThemesCommon.PatchLayouts(CommonSzs, LayoutPatch.LoadTemplate(File.ReadAllText(Layout)), targetPatch.NXThemeName == "home", true);
                    if (layoutres == BflytFile.PatchResult.Fail)
                    {
                        Console.WriteLine("One of the target files for the selected layout patch is missing in the SZS, you are probably using an already patched SZS");
                        return(false);
                    }
                    else if (layoutres == BflytFile.PatchResult.CorruptedFile)
                    {
                        Console.WriteLine("A layout in this SZS is missing a pane required for the selected layout patch, you are probably using an already patched SZS");
                        return(false);
                    }
                }

                var sarc = SARC.PackN(CommonSzs);

                File.WriteAllBytes(Output, ManagedYaz0.Compress(sarc.Item2, 3, (int)sarc.Item1));
                GC.Collect();

                if (res == BflytFile.PatchResult.AlreadyPatched)
                {
                    Console.WriteLine("Done, This file has already been patched before.\r\nIf you have issues try with an unmodified file");
                }
                else
                {
                    Console.WriteLine("Done");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }

            return(true);
        }