void EnableResidentMenuCheckbox(SarcData sarc) { if (cb11Compat.Tag != null) { return; } if (sarc == null) { return; } cb11Compat.Visible = (DefaultTemplates.GetFor(sarc)?.NXThemeName ?? "home") == "home"; cb11Compat.Checked = true; cb11Compat.Tag = "checked"; }
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); }