Exemplo n.º 1
0
        private bool PatchSingleLayout(LayoutFilePatch p)
        {
            if (p == null || p.FileName == null)
            {
                return(true);
            }
            if (!sarc.Files.ContainsKey(p.FileName))
            {
                return(false);
            }

            var target = new BflytFile(sarc.Files[p.FileName]);

            target.ApplyMaterialsPatch(p.Materials);             //Do not check result as it fails only if the file doesn't have any material

            var res = target.ApplyLayoutPatch(p.Patches);

            if (!res)
            {
                return(res);
            }

            res = target.AddGroupNames(p.AddGroups);
            if (!res)
            {
                return(res);
            }

            if (p.PullFrontPanes != null)
            {
                foreach (var n in p.PullFrontPanes)
                {
                    target.PanePullToFront(n);
                }
            }
            if (p.PushBackPanes != null)
            {
                foreach (var n in p.PushBackPanes)
                {
                    target.PanePushBack(n);
                }
            }

            sarc.Files[p.FileName] = target.SaveFile();
            return(true);
        }
Exemplo n.º 2
0
 public static BflytFile.PatchResult PatchLayouts(SARCExt.SarcData sarc, LayoutFilePatch[] Files)
 {
     foreach (var p in Files)
     {
         if (!sarc.Files.ContainsKey(p.FileName))
         {
             return(BflytFile.PatchResult.Fail);
         }
         var target = new BflytFile(sarc.Files[p.FileName]);
         var res    = target.ApplyLayoutPatch(p.Patches);
         if (res != BflytFile.PatchResult.OK)
         {
             return(res);
         }
         sarc.Files[p.FileName] = target.SaveFile();
     }
     return(BflytFile.PatchResult.OK);
 }
Exemplo n.º 3
0
        public static BflytFile.PatchResult PatchBgLayouts(SARCExt.SarcData sarc, PatchTemplate template)
        {
            BflytFile BflytFromSzs(string name) => new BflytFile(sarc.Files[name]);

            BflytFile MainFile = BflytFromSzs(template.MainLayoutName);
            var       res      = MainFile.PatchBgLayout(template);

            if (res == BflytFile.PatchResult.OK)
            {
                sarc.Files[template.MainLayoutName] = MainFile.SaveFile();
                foreach (var f in template.SecondaryLayouts)
                {
                    BflytFile curTarget = BflytFromSzs(f);
                    curTarget.PatchTextureName(template.MaintextureName, template.SecondaryTexReplace);
                    sarc.Files[f] = curTarget.SaveFile();
                }
            }
            return(res);
        }
		public bool PatchAppletIcon(byte[] DDS, string name)
		{
			var patch = PatchTemplate;
			if (!TextureReplacement.NxNameToList.ContainsKey(patch.NXThemeName))
				return false;

			var target = TextureReplacement.NxNameToList[patch.NXThemeName].Where(x => x.NxThemeName == name).First();

			var res = PatchSingleLayout(target.patch);
			if (!res) return res;

			PatchBntxTexture(DDS, target.BntxName, target.NewColorFlags);

			BflytFile curTarget = new BflytFile(sarc.Files[target.FileName]);
			curTarget.ClearUVData(target.PaneName);
			sarc.Files[target.FileName] = curTarget.SaveFile();

			return true;
		}
Exemplo n.º 5
0
        public static BflytFile.PatchResult PatchBgLayouts(SARCExt.SarcData sarc, PatchTemplate template)
        {
            BflytFile BflytFromSzs(string name) => new BflytFile(sarc.Files[name]);

            var layouts = sarc.Files.Keys.Where(x => x.StartsWith("blyt/") && x.EndsWith(".bflyt") && x != template.MainLayoutName).ToArray();

            foreach (var f in layouts)
            {
                BflytFile curTarget = BflytFromSzs(f);
                if (curTarget.PatchTextureName(template.MaintextureName, template.SecondaryTexReplace))
                {
                    sarc.Files[f] = curTarget.SaveFile();
                }
            }
            BflytFile MainFile = BflytFromSzs(template.MainLayoutName);
            var       res      = MainFile.PatchBgLayout(template);

            sarc.Files[template.MainLayoutName] = MainFile.SaveFile();
            return(res);
        }
        public bool PatchMainBG(DDSEncoder.DDSLoadResult DDS)
        {
            var template = PatchTemplate;

            BflytFile BflytFromSzs(string name) => new BflytFile(sarc.Files[name]);

            //PatchBGLayouts
            BflytFile MainFile = BflytFromSzs(template.MainLayoutName);
            var       res      = MainFile.PatchBgLayout(template);

            if (!res)
            {
                return(res);
            }

            sarc.Files[template.MainLayoutName] = MainFile.SaveFile();
            var layouts = sarc.Files.Keys.Where(x => x.StartsWith("blyt/") && x.EndsWith(".bflyt") && x != template.MainLayoutName).ToArray();

            foreach (var f in layouts)
            {
                BflytFile curTarget = BflytFromSzs(f);
                if (curTarget.PatchTextureName(template.MaintextureName, template.SecondaryTexReplace))
                {
                    sarc.Files[f] = curTarget.SaveFile();
                }
            }

            //PatchBGBntx
            QuickBntx q = GetBntx();

            if (q.Rlt.Length != 0x80)
            {
                return(false);
            }
            q.ReplaceTex(template.MaintextureName, DDS);
            DDS = null;
            return(true);
        }
		public bool PatchMainBG(Images.DDS DDS)
		{
			var template = PatchTemplate;
			BflytFile BflytFromSzs(string name) => new BflytFile(sarc.Files[name]);

			//PatchBGLayouts
			BflytFile MainFile = BflytFromSzs(template.MainLayoutName);
			var res = MainFile.PatchBgLayout(template);
			if (!res) return res;

			sarc.Files[template.MainLayoutName] = MainFile.SaveFile();

			//PatchBGBntx
			QuickBntx q = GetBntx();
			if (q.Rlt.Length != 0x80)
				return false;
			q.ReplaceTex(template.MaintextureName, DDS);

            // Remove references to the texture we replaced from other layouts

			// If the hardcoded texture is not present fallback to the first one called White*
            var replaceWith = 
				q.Textures.Any(x => x.Name == template.SecondaryTexReplace) ? template.SecondaryTexReplace :
				q.Textures.FirstOrDefault(x => x.Name.StartsWith("White"))?.Name;

			if (replaceWith == null)
				return false;
            
            var layouts = sarc.Files.Keys.Where(x => x.StartsWith("blyt/") && x.EndsWith(".bflyt") && x != template.MainLayoutName).ToArray();
			foreach (var f in layouts)
			{
				BflytFile curTarget = BflytFromSzs(f);
				if (curTarget.PatchTextureName(template.MaintextureName, replaceWith))
					sarc.Files[f] = curTarget.SaveFile();
			}

			return true;
		}
Exemplo n.º 8
0
        public static BflytFile.PatchResult PatchLayouts(SARCExt.SarcData sarc, LayoutPatch Patch, bool FixFor8, bool AddAnimations = false)
        {
            List <LayoutFilePatch> Files = new List <LayoutFilePatch>();

            Files.AddRange(Patch.Files);
            if (FixFor8 && !Patch.Ready8X)
            {
                var extra = NewFirmFixes.GetFix(Patch.PatchName);
                if (extra != null)
                {
                    Files.AddRange(extra);
                }
            }

            foreach (var p in Files)
            {
                if (!sarc.Files.ContainsKey(p.FileName))
                {
                    return(BflytFile.PatchResult.Fail);
                }
                var target = new BflytFile(sarc.Files[p.FileName]);
                var res    = target.ApplyLayoutPatch(p.Patches);
                if (res != BflytFile.PatchResult.OK)
                {
                    return(res);
                }
                if (AddAnimations)
                {
                    res = target.AddGroupNames(p.AddGroups);
                    if (res != BflytFile.PatchResult.OK)
                    {
                        return(res);
                    }
                }
                sarc.Files[p.FileName] = target.SaveFile();
            }
            return(BflytFile.PatchResult.OK);
        }