public bool PatchBntxTexture(byte[] DDS, string texName, uint TexFlag = 0xFFFFFFFF)
		{
			QuickBntx q = GetBntx();
			if (q.Rlt.Length != 0x80)
				return false;
			q.ReplaceTex(texName, DDS);
			if (TexFlag != 0xFFFFFFFF)
				q.FindTex(texName).ChannelTypes = (int)TexFlag;
			return true;
		}
Beispiel #2
0
        public static BflytFile.PatchResult PatchBntx(SARCExt.SarcData sarc, DDSEncoder.DDSLoadResult DDS, PatchTemplate targetPatch)
        {
            QuickBntx q = new QuickBntx(new BinaryDataReader(new MemoryStream(sarc.Files[@"timg/__Combined.bntx"])));

            if (q.Rlt.Length != 0x80)
            {
                return(BflytFile.PatchResult.Fail);
            }
            q.ReplaceTex(targetPatch.MaintextureName, DDS);
            DDS = null;
            sarc.Files[@"timg/__Combined.bntx"] = null;
            sarc.Files[@"timg/__Combined.bntx"] = q.Write();
            return(BflytFile.PatchResult.OK);
        }
        public BflytFile.PatchResult PatchBntxTexture(byte[] DDS, string texName, uint TexFlag = 0xFFFFFFFF)
        {
            QuickBntx q = GetBntx();

            if (q.Rlt.Length != 0x80)
            {
                return(BflytFile.PatchResult.CorruptedFile);
            }
            q.ReplaceTex(texName, DDS);
            if (TexFlag != 0xFFFFFFFF)
            {
                q.FindTex(texName).ChannelTypes = (int)TexFlag;
            }
            return(BflytFile.PatchResult.OK);
        }
Beispiel #4
0
        public static BflytFile.PatchResult PatchBntxTexture(SARCExt.SarcData sarc, byte[] DDS, string texName, uint TexFlag = 0xFFFFFFFF)
        {
            QuickBntx q = new QuickBntx(new BinaryDataReader(new MemoryStream(sarc.Files[@"timg/__Combined.bntx"])));

            if (q.Rlt.Length != 0x80)
            {
                return(BflytFile.PatchResult.Fail);
            }
            q.ReplaceTex(texName, DDS);
            if (TexFlag != 0xFFFFFFFF)
            {
                q.Textures.Where(x => x.Name == texName).First().ChannelTypes = (int)TexFlag;
            }
            sarc.Files[@"timg/__Combined.bntx"] = null;
            sarc.Files[@"timg/__Combined.bntx"] = q.Write();
            return(BflytFile.PatchResult.OK);
        }
        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;
		}