public BflytFile.PatchResult PatchBntxTextureAttribs(params Tuple <string, UInt32>[] patches)
        {
            QuickBntx q = GetBntx();

            if (q.Rlt.Length != 0x80)
            {
                return(BflytFile.PatchResult.CorruptedFile);
            }
            try
            {
                foreach (var patch in patches)
                {
                    var target = q.FindTex(patch.Item1);
                    if (target != null)
                    {
                        target.ChannelTypes = (int)patch.Item2;
                    }
                }
            }
            catch
            {
                return(BflytFile.PatchResult.Fail);
            }
            return(BflytFile.PatchResult.OK);
        }
        public bool PatchBntxTextureAttribs(params Tuple <string, UInt32>[] patches)
        {
            QuickBntx q = GetBntx();

            if (q.Rlt.Length != 0x80)
            {
                return(false);
            }
            try
            {
                foreach (var patch in patches)
                {
                    var target = q.FindTex(patch.Item1);
                    if (target != null)
                    {
                        target.ChannelTypes = (int)patch.Item2;
                    }
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
 QuickBntx GetBntx()
 {
     if (bntx != null)
     {
         return(bntx);
     }
     bntx = new QuickBntx(new BinaryDataReader(new MemoryStream(sarc.Files[@"timg/__Combined.bntx"])));
     return(bntx);
 }
 void SaveBntx()
 {
     if (bntx == null)
     {
         return;
     }
     sarc.Files[@"timg/__Combined.bntx"] = bntx.Write();
     bntx = null;
 }
Beispiel #5
0
 QuickBntx GetBntx()
 {
     if (bntx != null)
     {
         return(bntx);
     }
     bntx = new QuickBntx(sarc.Files[@"timg/__Combined.bntx"]);
     return(bntx);
 }
		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 #7
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 #9
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);
        }
Beispiel #10
0
        private void materialRaisedButton5_Click(object sender, EventArgs e)
        {
            if (CommonSzs == null)
            {
                return;
            }
            if (!CommonSzs.Files.ContainsKey(@"timg/__Combined.bntx"))
            {
                MessageBox.Show("This szs doesn't contain the btnx file");
                return;
            }
            QuickBntx b = new QuickBntx(new BinaryDataReader(new MemoryStream(CommonSzs.Files["timg/__Combined.bntx"])));

            string[] TexList = b.Textures.Select(x => x.Name).ToArray();
            Dictionary <string, List <string> > UsageCount = new Dictionary <string, List <string> >();

            foreach (string s in TexList)
            {
                UsageCount.Add(s, new List <string>());
            }

            foreach (string k in CommonSzs.Files.Keys)
            {
                string fileText = UTF8Encoding.Default.GetString(CommonSzs.Files[k]);
                foreach (string s in TexList)
                {
                    if (fileText.Contains(s))
                    {
                        UsageCount[s].Add(k);
                    }
                }
            }

            string res = "Result:\r\n";

            foreach (string s in TexList)
            {
                res += s + " has " + UsageCount[s].Count + " references :" + string.Join(",", UsageCount[s]) + "\r\n";
            }

            MessageBox.Show(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;
		}