Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            LoadFileText   = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text = "(To dump the following files check the guide at https://git.io/fxdyF )\r\n" + LoadFileText;
        }
Exemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();
            PatchLabelText = materialLabel3.Text;

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            LoadFileText   = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text = "(To dump the following files check the guide at https://git.io/fxdyF )\r\n" + LoadFileText;

            if (!File.Exists("hactool\\hactool.exe") || !File.Exists("hactool\\keys.dat"))
            {
                materialTabControl1.TabPages.Remove(NCADumpPage);
            }
        }
Exemplo n.º 3
0
        public Form1()
        {
            MaterialSkin.MaterialSkinManager.Instance.Theme = MaterialSkin.MaterialSkinManager.Themes.DARK;
            InitializeComponent();

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            LoadFileText    = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text += LoadFileText;
        }
Exemplo n.º 4
0
 public void LoadAndOptimizeAll()
 {
     // This generates layouts to load for SwitchThemesNXTests::Layouts::LayoutLoading
     foreach (var f in Directory.EnumerateFiles("../../../../../SwitchThemes/layouts").Where(x => x.EndsWith(".json")))
     {
         File.WriteAllText(
             Path.Combine(Util.GetPath("ParsedLayouts"), Path.GetFileName(f)),
             LayoutPatch.LoadTemplate(File.ReadAllText(f)).AsJson()
             );
     }
 }
Exemplo n.º 5
0
        private void LayoutPatchList_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox comboBox = (ComboBox)sender;

            if (comboBox.SelectedIndex == comboBox.Items.Count - 1)
            {
                OpenFileDialog opn = new OpenFileDialog()
                {
                    Title = "Select a layout", Filter = "Json files|*.json"
                };
                if (opn.ShowDialog() != DialogResult.OK)
                {
                    comboBox.SelectedIndex = 0;
                    return;
                }
                comboBox.Items.Insert(1, LayoutPatch.LoadTemplate(File.ReadAllText(opn.FileName)));
                comboBox.SelectedIndex = 1;
            }
        }
Exemplo n.º 6
0
        private void ProcessSzs(string name)
        {
            SarcData src = SARC.Unpack(ManagedYaz0.Decompress(Util.ReadData($"Source/{name}.szs")));
            SarcData exp = SARC.Unpack(ManagedYaz0.Decompress(Util.ReadData($"Expected/{name}.szs")));

            string lyt = Util.Exists($"Source/{name}.json") ? Util.ReadString($"Source/{name}.json") : null;

            SzsPatcher patcher = new SzsPatcher(src);

            Assert.IsTrue(patcher.PatchMainBG(DDS));

            if (lyt != null)
            {
                var l = LayoutPatch.LoadTemplate(lyt);
                patcher.PatchLayouts(l);
            }

            var final = patcher.GetFinalSarc();

            CompareSarc(final, exp);
        }
Exemplo n.º 7
0
        private void btnOpenCustomLayout_Click(object sender, EventArgs e)
        {
            if (ExtraCommonLyt != null)
            {
                btnOpenCustomLayout.Text = "...";
                lblCustomCommonLyt.Text  = "Custom common layout: Not set";
                ExtraCommonLyt           = null;
                return;
            }
            OpenFileDialog opn = new OpenFileDialog()
            {
                Filter = "json layout|*.json"
            };

            if (opn.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            ExtraCommonLyt           = LayoutPatch.LoadTemplate(File.ReadAllText(opn.FileName));
            lblCustomCommonLyt.Text  = $"Custom common layout: {ExtraCommonLyt.ToString()}";
            btnOpenCustomLayout.Text = "X";
        }
Exemplo n.º 8
0
        static void GetLayoutPart(int i)
        {
            XMLHttpRequest req = new XMLHttpRequest();

            req.ResponseType       = XMLHttpRequestResponseType.String;
            req.OnReadyStateChange = () =>
            {
                if (req.ReadyState != AjaxReadyState.Done)
                {
                    return;
                }
                string DownloadRes = req.Response as string;
                if (DownloadRes == null || DownloadRes.Length == 0)
                {
                    PrintError("Error downloading one of the embedded layouts : " + embedLyouts[i] + ", it won't be available to make themes");
                    return;
                }
                layoutPatches[i] = LayoutPatch.LoadTemplate(DownloadRes);
                DownloadRes      = null;
            };
            req.Open("GET", "layouts/" + embedLyouts[i] + ".json", true);
            req.Send();
        }
Exemplo n.º 9
0
        public Form1()
        {
            MaterialSkin.MaterialSkinManager.Instance.Theme = MaterialSkin.MaterialSkinManager.Themes.DARK;
            InitializeComponent();

            Advanced = Properties.Settings.Default.Adv;
            if (Advanced)
            {
                EnableAdvanced();
            }
            else
            {
                DisableAdvanced();
            }

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            HomeAppletIcoButtonsInit();
        }
Exemplo n.º 10
0
        static void DoAutoTheme(string type, string url, string layout)
        {
            cardLoad = Document.GetElementById <HTMLDivElement>("CardLoad");
            Document.GetElementById <HTMLDivElement>("CardTutorial").Hidden = true;
            string themeTarget = "<br/><br/>This theme is an nxtheme, download NXThemes Installer to install it on your switch.";

            cardLoad.InnerHTML = "Wait while your theme is being generated.... " + themeTarget;
            cardLoad.Hidden    = false;
            StartLoading();

            byte[]      DDS;
            LayoutPatch targetLayout = null;

            void BuildTheme()
            {
                var urlSplit = url.Split("/");
                var meta     = new ThemeFileManifest()
                {
                    Version    = 1,
                    Author     = "Auto-Theme",
                    LayoutInfo = targetLayout != null?targetLayout.ToString() : "",
                                     ThemeName = urlSplit[urlSplit.Length - 1],
                                     Target    = type
                };

                var res = SwitchThemesCommon.GenerateNXTheme(meta, DDS, targetLayout == null ? null : targetLayout.AsJson());

                if (res == null)
                {
                    endWithError("GenerateNXTheme() failed :(");
                    return;
                }
                Uint8Array dwn           = new Uint8Array(res);
                string     DownloadFname = urlSplit[urlSplit.Length - 1] + ".nxtheme";

                Script.Write("downloadBlob(dwn,DownloadFname,'application/octet-stream');");
                Document.GetElementById <HTMLDivElement>("CardLoad").InnerHTML = "Your theme has been generated !" + themeTarget;
                EndLoading();
            }

            void DDSDownloaded(Uint8Array arr)
            {
                DDS = arr.ToArray();

                if (layout == null)
                {
                    BuildTheme();
                }
                else
                {
                    HttpRequest(layout, LayoutDownloaded, "Layout");
                }
            }

            void LayoutDownloaded(string req)
            {
                targetLayout = LayoutPatch.LoadTemplate(req);
                BuildTheme();
            }

            HttpRequest(url, DDSDownloaded, "DDS");
        }
Exemplo n.º 11
0
        static bool NXThemeFromArgs(string[] args)
        {
            if (args.Length < 4)
            {
                return(false);
            }
            string Target = args[1];

            if (!Form1.HomeMenuParts.Values.Contains(Target))
            {
                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();

            if (Image == null && Layout == null)
            {
                Console.WriteLine("You need at least an image or a layout to make a theme");
                return(false);
            }

            string GetArg(string start)
            {
                var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();

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

            bool?GetArgBool(string start)
            {
                var a = GetArg(start);

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(bool.Parse(a));
                }
            }

            string Name        = GetArg("name");
            string Author      = GetArg("author");
            string Output      = GetArg("out");
            string ExtraCommon = GetArg("commonlyt");
            string album       = GetArg("album");

            if (Output == null || Output == "")
            {
                Console.WriteLine("Missing out= arg");
                return(false);
            }

            bool preview = GetArgBool("preview") ?? true;

            if (Name == null || Name.Trim() == "")
            {
                var info = ThemeInputInfo.Ask();
                Name    = info.Item1;
                Author  = info.Item2;
                preview = info.Item3;
            }

            LayoutPatch layout = null;

            if (Layout != null && File.Exists(Layout))
            {
                layout = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
            }

            Dictionary <string, string> AppletIcons = new Dictionary <string, string>();

            void PopulateAppletIcons(List <TextureReplacement> l)
            {
                foreach (var a in l)
                {
                    string path = GetArg(a.NxThemeName);
                    AppletIcons.Add(a.NxThemeName, path);
                }
            }

            if (TextureReplacement.NxNameToList.ContainsKey(Target))
            {
                PopulateAppletIcons(TextureReplacement.NxNameToList[Target]);
            }

            try
            {
                var builder = new NXThemeBuilder(Target, Name, Author);

                if (layout != null)
                {
                    builder.AddMainLayout(layout);
                }
                if (Image != null)
                {
                    builder.AddMainBg(File.ReadAllBytes(Image));
                }
                if (ExtraCommon != null)
                {
                    builder.AddFile("common.json", File.ReadAllBytes(ExtraCommon));
                }

                foreach (var i in AppletIcons)
                {
                    if (i.Value != null)
                    {
                        builder.AddAppletIcon(i.Key, File.ReadAllBytes(i.Value));
                    }
                }

                File.WriteAllBytes(Output, builder.GetNxtheme());
                Console.WriteLine("Done !");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                return(false);
            }

            return(true);
        }
Exemplo n.º 12
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 = SzsPatcher.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);
                }
            }

            try
            {
                var res     = true;
                var Patcher = new SzsPatcher(CommonSzs, DefaultTemplates.templates);

                if (Image != null)
                {
                    res = Patcher.PatchMainBG(File.ReadAllBytes(Image));
                    if (!res)
                    {
                        Console.WriteLine("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                        return(false);
                    }
                }

                void ProcessAppletIcons(List <TextureReplacement> l)
                {
                    foreach (var a in l)
                    {
                        string path = GetArg(a.NxThemeName);
                        if (!path.EndsWith(".dds") && !Form1.IcontoDDS(ref path))
                        {
                            path = null;
                        }
                        if (path != null)
                        {
                            if (!Patcher.PatchAppletIcon(File.ReadAllBytes(path), a.NxThemeName))
                            {
                                Console.WriteLine($"Applet icon patch for {a.NxThemeName} failed");
                            }
                        }
                    }
                }

                if (TextureReplacement.NxNameToList.ContainsKey(targetPatch.NXThemeName))
                {
                    ProcessAppletIcons(TextureReplacement.NxNameToList[targetPatch.NXThemeName]);
                }

                if (Layout != null)
                {
                    Patcher.EnableAnimations = true;
                    var l         = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
                    var layoutres = Patcher.PatchLayouts(l, targetPatch.NXThemeName, targetPatch);
                    if (!layoutres)
                    {
                        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);
                    }
                    layoutres = Patcher.PatchAnimations(l.Anims);
                }

                CommonSzs = Patcher.GetFinalSarc();
                var sarc = SARC.PackN(CommonSzs);

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

                if (Patcher.PatchTemplate.RequiresCodePatch)
                {
                    Console.WriteLine("The file has been patched successfully but due to memory limitations this szs requires an extra code patch to be applied to the home menu, if you use NXThemesInstaller to install this it will be done automatically, otherwise you need to manually copy the patches from https://github.com/exelix11/SwitchThemeInjector/tree/master/SwitchThemesNX/romfs to the exefs patches directory of your cfw");
                }
                else
                {
                    Console.WriteLine("Done");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            return(true);
        }
Exemplo n.º 13
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.Unpack(ManagedYaz0.Decompress(File.ReadAllBytes(Target)));
            var    targetPatch = DefaultTemplates.GetFor(CommonSzs);

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

            string Image = args.Where(x => x.ToLower().EndsWith(".dds")).FirstOrDefault();

            if (Image == null || !File.Exists(Image))
            {
                Console.WriteLine("No image file !\r\nNote that only dds files are supported for szs themes.");
                return(false);
            }
            string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();

            string Output = GetArg("out");

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

            {
                var dds = Common.Images.Util.ParseDds(File.ReadAllBytes(Image));
                if (dds.Encoding != "DXT1")
                {
                    Console.WriteLine("WARNING: the encoding of the selected DDS is not DXT1, it may crash on the switch");
                }
                if (dds.Size.Width != 1280 || dds.Size.Height != 720)
                {
                    Console.WriteLine("WARNING: the selected image is not 720p (1280x720), it may crash on the swtich");
                }
            }

            try
            {
                var res     = true;
                var Patcher = new SzsPatcher(CommonSzs);

                if (Image != null)
                {
                    res = Patcher.PatchMainBG(File.ReadAllBytes(Image));
                    if (!res)
                    {
                        Console.WriteLine("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                        return(false);
                    }
                }

                void ProcessAppletIcons(List <TextureReplacement> l)
                {
                    foreach (var a in l)
                    {
                        string path = GetArg(a.NxThemeName);
                        if (!path.EndsWith(".dds"))
                        {
                            Console.WriteLine($"{path} is not supported, only dds files can be used for szs themes");
                            path = null;
                        }
                        if (path != null)
                        {
                            if (!Patcher.PatchAppletIcon(File.ReadAllBytes(path), a.NxThemeName))
                            {
                                Console.WriteLine($"Applet icon patch for {a.NxThemeName} failed");
                            }
                        }
                    }
                }

                if (TextureReplacement.NxNameToList.ContainsKey(targetPatch.NXThemeName))
                {
                    ProcessAppletIcons(TextureReplacement.NxNameToList[targetPatch.NXThemeName]);
                }

                if (Layout != null)
                {
                    var l         = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
                    var layoutres = Patcher.PatchLayouts(l);
                    if (!layoutres)
                    {
                        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);
                    }
                }

                CommonSzs = Patcher.GetFinalSarc();
                var sarc = SARC.Pack(CommonSzs);

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

                if (Patcher.PatchTemplate.RequiresCodePatch)
                {
                    Console.WriteLine("The file has been patched successfully but due to memory limitations this szs requires an extra code patch to be applied to the home menu, if you use NXThemesInstaller to install this it will be done automatically, otherwise you need to manually copy the patches from https://github.com/exelix11/SwitchThemeInjector/tree/master/SwitchThemesNX/romfs to the exefs patches directory of your cfw");
                }
                else
                {
                    Console.WriteLine("Done");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            return(true);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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 = SzsPatcher.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;
			}		

			try
			{				
				var res = BflytFile.PatchResult.OK;
				var Patcher = new SzsPatcher(CommonSzs, DefaultTemplates.templates);

				if (Image != null)
				{
					res = Patcher.PatchMainBG(File.ReadAllBytes(Image));
					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)
				{
					Patcher.EnableAnimations = true;
					var l = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
					var layoutres = Patcher.PatchLayouts(l, targetPatch.NXThemeName, targetPatch.NXThemeName == "home");
					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;
					}
					layoutres = Patcher.PatchAnimations(l.Anims);
				}

				void ProcessAppletIcons(List<TextureReplacement> l)
				{
					foreach (var a in l)
					{
						string path = GetArg(a.NxThemeName);
						if (!path.EndsWith(".dds") && !Form1.IcontoDDS(ref path))
							path = null;
						if (path != null)
							Patcher.PatchAppletIcon(File.ReadAllBytes(path), a.NxThemeName);
					}
				}

				if (TextureReplacement.NxNameToList.ContainsKey(targetPatch.NXThemeName))
					ProcessAppletIcons(TextureReplacement.NxNameToList[targetPatch.NXThemeName]);

				CommonSzs = Patcher.GetFinalSarc();
				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;
		}
Exemplo n.º 16
0
        static bool NXThemeFromArgs(string[] args)
        {
            if (args.Length < 4)
            {
                return(false);
            }
            string Target = args[1];

            if (!Form1.HomeMenuParts.Values.Contains(Target))
            {
                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 GetArg(string start)
            {
                var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();

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

            bool?GetArgBool(string start)
            {
                var a = GetArg(start);

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(bool.Parse(a));
                }
            }

            string Name        = GetArg("name");
            string Author      = GetArg("author");
            string Output      = GetArg("out");
            string ExtraCommon = GetArg("commonlyt");

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

            bool preview = GetArgBool("preview") ?? true;

            if (Name == null || Name.Trim() == "")
            {
                var info = ThemeInputInfo.Ask();
                Name    = info.Item1;
                Author  = info.Item2;
                preview = info.Item3;
            }

            LayoutPatch layout = null;

            if (Layout != null && File.Exists(Layout))
            {
                layout = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
            }

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

            var res = SwitchThemesCommon.GenerateNXTheme(
                new ThemeFileManifest()
            {
                Version    = 3,
                ThemeName  = Name,
                Author     = Author,
                Target     = Target,
                LayoutInfo = layout == null ? "" : layout.PatchName + " by " + layout.AuthorName,
            },
                File.ReadAllBytes(Image),
                layout?.AsByteArray(),
                new Tuple <string, byte[]>("preview.png", preview ? Form1.GenerateDDSPreview(Image) : null));

            File.WriteAllBytes(Output, res);

            return(true);
        }
Exemplo n.º 17
0
        static void DoAutoTheme(string type, string url, string layout)
        {
            cardLoad = Document.GetElementById <HTMLDivElement>("CardLoad");
            Document.GetElementById <HTMLDivElement>("CardTutorial").Hidden = true;
            string themeTarget = "<br/><br/>This theme is for " + Window.LocalStorage.GetItem(type + "Name") as string + "<br/>To change the target version upload another szs for Auto-Theme on the <a href=\"index.html\">Home page</a>";

            cardLoad.InnerHTML = "Wait while your theme is being generated.... " + themeTarget;
            cardLoad.Hidden    = false;
            StartLoading();

            DDSEncoder.DDSLoadResult LoadedDDS;
            SarcData      CommonSzs;
            PatchTemplate targetPatch;
            LayoutPatch   targetLayout = null;

            void BuildTheme()
            {
                var yaz0 = Theme.Make(CommonSzs, LoadedDDS, targetPatch, targetLayout);

                if (yaz0 == null)
                {
                    endWithError("Theme.Make() failed :(");
                    return;
                }
                Uint8Array dwn           = new Uint8Array(yaz0);
                string     DownloadFname = targetPatch.szsName;

                Script.Write("downloadBlob(dwn,DownloadFname,'application/octet-stream');");
                Document.GetElementById <HTMLDivElement>("CardLoad").InnerHTML = "Your theme has been generated !" + themeTarget;
                EndLoading();
            }

            void DDSDownloaded(Uint8Array arr)
            {
                LoadedDDS = DDSEncoder.LoadDDS(arr.ToArray());
                arr       = null;
                CommonSzs = SARC.UnpackRamN(
                    ManagedYaz0.Decompress(
                        Convert.FromBase64String(
                            Window.LocalStorage.GetItem(type) as string)));

                targetPatch = SwitchThemesCommon.DetectSarc(CommonSzs, DefaultTemplates.templates);

                if (layout == null)
                {
                    BuildTheme();
                }
                else
                {
                    HttpRequest(layout, LayoutDownloaded, "Layout");
                }
            }

            void LayoutDownloaded(string req)
            {
                targetLayout = LayoutPatch.LoadTemplate(req);
                BuildTheme();
            }

            HttpRequest(url, DDSDownloaded, "DDS");
        }