internal static BntxFile CreateBNTX(List <TextureShared> textureList) { BntxFile bntx = new BntxFile(); bntx.Target = new char[] { 'N', 'X', ' ', ' ' }; bntx.Name = "textures"; bntx.Alignment = 0xC; bntx.TargetAddressSize = 0x40; bntx.VersionMajor = 0; bntx.VersionMajor2 = 4; bntx.VersionMinor = 0; bntx.VersionMinor2 = 0; bntx.Textures = new List <Texture>(); bntx.TextureDict = new Syroot.NintenTools.NSW.Bntx.ResDict(); bntx.RelocationTable = new RelocationTable(); bntx.Flag = 0; foreach (var tex in textureList) { //Create a new switch texture instance var textureNX = new Switch.SwitchTexture(bntx, null); textureNX.FromWiiU((WiiU.Texture)tex); //Now set the new texture bntx.Textures.Add(textureNX.Texture); bntx.TextureDict.Add(textureNX.Name); } return(bntx); }
public void LoadFile(byte[] data, string Name = "") { Textures = new Dictionary <string, TextureData>(); Data = data; BinaryTexFile = new BntxFile(new MemoryStream(Data)); Text = BinaryTexFile.Name; prop = new PropertieGridData(); prop.Target = new string(BinaryTexFile.Target); prop.VersionMajor = BinaryTexFile.VersionMajor; prop.VersionMajor2 = BinaryTexFile.VersionMajor2; prop.VersionMinor = BinaryTexFile.VersionMinor; prop.VersionMinor2 = BinaryTexFile.VersionMinor2; prop.VersionFull = $"{BinaryTexFile.VersionMajor}.{BinaryTexFile.VersionMajor2}.{BinaryTexFile.VersionMinor}.{BinaryTexFile.VersionMinor2}"; foreach (Texture tex in BinaryTexFile.Textures) { TextureData texData = new TextureData(tex, BinaryTexFile); // texData.LoadOpenGLTexture(); Nodes.Add(texData); Textures.Add(tex.Name, texData); } BinaryTexFile.Textures.Clear(); //We don't need these in memeory anymore BinaryTexFile.TextureDict.Clear(); }
public void LoadDDS(string FileName, BntxFile bntxFile, byte[] FileData = null, TextureData tree = null) { TexName = Path.GetFileNameWithoutExtension(FileName); DDS dds = new DDS(); if (FileData != null) { dds.Load(new FileReader(new MemoryStream(FileData))); } else { dds.Load(new FileReader(FileName)); } MipCount = dds.header.mipmapCount; TexWidth = dds.header.width; TexHeight = dds.header.height; DataBlockOutput = dds.bdata; Format = LoadDDSFormat(dds.header.ddspf.fourCC, dds, IsSRGB); Texture tex = FromBitMap(DataBlockOutput, this); if (tree != null) { tree.LoadTexture(tex, 1); } else { textureData = new TextureData(tex, bntxFile); } }
public void LoadTGA(string FileName, BntxFile bntxFile) { DecompressedData.Clear(); TexName = Path.GetFileNameWithoutExtension(FileName); bntx = bntxFile; Format = TEX_FORMAT.BC1; FormatType = TEX_FORMAT_TYPE.SRGB; GenerateMipmaps = true; Bitmap Image = Paloma.TargaImage.LoadTargaImage(FileName); Image = STGenericTexture.SwapBlueRedChannels(Image); TexWidth = (uint)Image.Width; TexHeight = (uint)Image.Height; MipCount = (uint)GetTotalMipCount(); DecompressedData.Add(BitmapExtension.ImageToByte(Image)); Image.Dispose(); if (DecompressedData.Count == 0) { throw new Exception("Failed to load " + Format); } }
public void LoadBitMap(string FileName, BntxFile bntxFile) { DecompressedData.Clear(); TexName = Path.GetFileNameWithoutExtension(FileName); bntx = bntxFile; Format = SurfaceFormat.BC1_SRGB; GenerateMipmaps = true; Bitmap Image = new Bitmap(FileName); Image = TextureData.SwapBlueRedChannels(Image); TexWidth = (uint)Image.Width; TexHeight = (uint)Image.Height; MipCount = (uint)GetTotalMipCount(); DecompressedData.Add(BitmapExtension.ImageToByte(Image)); Image.Dispose(); if (DecompressedData.Count == 0) { throw new Exception("Failed to load " + Format); } }
public void Load(Stream stream) { BntxFile = new BntxFile(stream); //Load the textures into generic textures foreach (var tex in BntxFile.Textures) { Textures.Add(new BntxTexture(BntxFile, tex)); } }
public void LoadFile(byte[] data, string Name = "") { Textures = new Dictionary <string, TextureData>(); Data = data; BinaryTexFile = new BntxFile(new MemoryStream(Data)); Text = BinaryTexFile.Name; prop = new PropertieGridData(); prop.Target = new string(BinaryTexFile.Target); prop.VersionMajor = BinaryTexFile.VersionMajor; prop.VersionMajor2 = BinaryTexFile.VersionMajor2; prop.VersionMinor = BinaryTexFile.VersionMinor; prop.VersionMinor2 = BinaryTexFile.VersionMinor2; prop.VersionFull = $"{BinaryTexFile.VersionMajor}.{BinaryTexFile.VersionMajor2}.{BinaryTexFile.VersionMinor}.{BinaryTexFile.VersionMinor2}"; foreach (Texture tex in BinaryTexFile.Textures) { TextureData texData = new TextureData(tex, BinaryTexFile); // texData.LoadOpenGLTexture(); Nodes.Add(texData); Textures.Add(tex.Name, texData); } ContextMenu = new ContextMenu(); MenuItem export = new MenuItem("Export BNTX"); ContextMenu.MenuItems.Add(export); export.Click += Export; MenuItem replace = new MenuItem("Replace BNTX"); ContextMenu.MenuItems.Add(replace); replace.Click += Import; MenuItem importTex = new MenuItem("Import Texture"); ContextMenu.MenuItems.Add(importTex); importTex.Click += ImportTexture; MenuItem exportAll = new MenuItem("Export All Textures"); ContextMenu.MenuItems.Add(exportAll); exportAll.Click += ExportAll; MenuItem clear = new MenuItem("Clear"); ContextMenu.MenuItems.Add(clear); clear.Click += Clear; }
public TextureData(Texture tex, BntxFile bntx) { ImageKey = "Texture"; SelectedImageKey = "Texture"; Texture = tex; bntxFile = bntx; Text = tex.Name; Width = tex.Width; Height = tex.Height; MipmapCount = tex.MipCount; var formats = ConvertFormat(tex.Format, tex.FormatType); Format = formats.Item1; FormatType = formats.Item2; ContextMenu = new ContextMenu(); MenuItem export = new MenuItem("Export"); MenuItem replace = new MenuItem("Replace"); MenuItem remove = new MenuItem("Remove"); MenuItem rename = new MenuItem("Rename"); ContextMenu.MenuItems.Add(export); ContextMenu.MenuItems.Add(replace); ContextMenu.MenuItems.Add(remove); ContextMenu.MenuItems.Add(rename); export.Click += Export; replace.Click += Replace; remove.Click += Remove; rename.Click += Rename; string TargetString = new string(bntx.Target); int target = 0; if (TargetString == "NX ") { target = 1; } LoadTexture(Texture); }
public BntxTexture(BntxFile bntx, Texture tex) { Texture = tex; BntxFile = bntx; Name = tex.Name; Width = tex.Width; Height = tex.Height; MipCount = tex.MipCount; ArrayCount = tex.ArrayLength; DisplayProperties = tex; Platform = new SwitchSwizzle(FormatList[tex.Format]) { BlockHeightLog2 = (uint)tex.BlockHeightLog2, Target = BntxFile.PlatformTarget != "NX " ? 0 : 1, }; RedChannel = SetChannel(tex.ChannelRed); GreenChannel = SetChannel(tex.ChannelGreen); BlueChannel = SetChannel(tex.ChannelBlue); AlphaChannel = SetChannel(tex.ChannelAlpha); if (Texture.Format.ToString().Contains("SRGB")) { IsSRGB = true; } if (tex.SurfaceDim == SurfaceDim.Dim2DArray) { SurfaceType = STSurfaceType.Texture2D_Array; } if (tex.SurfaceDim == SurfaceDim.DimCube) { SurfaceType = STSurfaceType.TextureCube; } if (tex.SurfaceDim == SurfaceDim.DimCubeArray) { SurfaceType = STSurfaceType.TextureCube_Array; } DisplayPropertiesChanged = (o, e) => { OnPropertyChanged(); }; }
public void LoadDDS(string FileName, BntxFile bntxFile, byte[] FileData = null, TextureData tree = null) { TexName = Path.GetFileNameWithoutExtension(FileName); DDS dds = new DDS(); if (FileData != null) { dds.Load(new FileReader(new MemoryStream(FileData))); } else { dds.Load(new FileReader(FileName)); } MipCount = dds.header.mipmapCount; TexWidth = dds.header.width; TexHeight = dds.header.height; arrayLength = 1; if (dds.header.caps2 == (uint)DDS.DDSCAPS2.CUBEMAP_ALLFACES) { arrayLength = 6; } DataBlockOutput.Add(dds.bdata); var formats = dds.GetFormat(); Format = formats.Item1; FormatType = formats.Item2; Texture tex = FromBitMap(DataBlockOutput[0], this); if (tree != null) { tree.LoadTexture(tex, 1); } else { textureData = new TextureData(tex, bntxFile); } }
static Texture GetTexture(string path, ResFile file) { var basename = Path.GetFileName(path); if (file.ExternalFiles.Count() > 1) { Console.WriteLine($"[SKIP] {basename} - contains multiple external files"); return(null); } try { using (var bntxStream = file.ExternalFiles.First().GetStream()) { var bntxFile = new BntxFile(bntxStream); if (bntxFile.Textures.Count != 1) { Console.WriteLine($"[SKIP] {basename} - contains {bntxFile.Textures.Count} textures"); return(null); } var texture = bntxFile.Textures.First(); if (IsTextureDecodable(texture)) { return(texture); } if (TextureFormatInfo.FormatTable.ContainsKey(texture.Format)) { Console.WriteLine($"[SKIP] {basename} - unhandled texture format {texture.Format}"); return(null); } Console.WriteLine($"[SKIP] {basename} - unknown texture format {texture.Format}"); return(null); } } catch (Exception) { return(null); } }
public void LoadBitMap(string FileName, BntxFile bntxFile, TextureData tree = null) { TexName = Path.GetFileNameWithoutExtension(FileName); bntx = bntxFile; textureData = tree; Format = SurfaceFormat.R8_G8_B8_A8_SRGB; Bitmap Image = new Bitmap(FileName); TexWidth = (uint)Image.Width; TexHeight = (uint)Image.Height; MipCount = 1; DataBlockOutput = BitmapExtension.ImageToByte(Image); Image.Dispose(); if (DataBlockOutput.Length == 0) { throw new Exception("Failed to load " + Format); } }
private byte[] CreateNewBNTX(string Name) { MemoryStream mem = new MemoryStream(); BntxFile bntx = new BntxFile(); bntx.Target = new char[] { 'N', 'X', ' ', ' ' }; bntx.Name = Name; bntx.Alignment = 0xC; bntx.TargetAddressSize = 0x40; bntx.VersionMajor = 0; bntx.VersionMajor2 = 4; bntx.VersionMinor = 0; bntx.VersionMinor2 = 0; bntx.Textures = new List <Texture>(); bntx.TextureDict = new ResDict(); bntx.RelocationTable = new RelocationTable(); bntx.Flag = 0; bntx.Save(mem); return(mem.ToArray()); }
public TextureData(Texture tex, BntxFile bntx) { ImageKey = "Texture"; SelectedImageKey = "Texture"; Texture = tex; bntxFile = bntx; Text = tex.Name; ContextMenu = new ContextMenu(); MenuItem export = new MenuItem("Export"); ContextMenu.MenuItems.Add(export); export.Click += Export; MenuItem replace = new MenuItem("Replace"); ContextMenu.MenuItems.Add(replace); replace.Click += Replace; MenuItem remove = new MenuItem("Remove"); ContextMenu.MenuItems.Add(remove); remove.Click += Remove; MenuItem rename = new MenuItem("Rename"); ContextMenu.MenuItems.Add(rename); rename.Click += Rename; string TargetString = new string(bntx.Target); int target = 0; if (TargetString == "NX ") { target = 1; } }
private void CreateBNTX(string path, List <Texture> textures) { BntxFile bntx = new BntxFile(); bntx.Target = new char[] { 'N', 'X', ' ', ' ' }; bntx.Name = "textures"; bntx.Alignment = 0xC; bntx.TargetAddressSize = 0x40; bntx.VersionMajor = 0; bntx.VersionMajor2 = 4; bntx.VersionMinor = 0; bntx.VersionMinor2 = 0; bntx.Textures = new List <Texture>(); bntx.TextureDict = new ResDict(); bntx.RelocationTable = new RelocationTable(); bntx.Flag = 0; foreach (var file in textures) { bntx.Textures.Add(file); } bntx.Save(path); }
public BntxWrapper(BntxFile bntxFile) { BntxFile = bntxFile; }
public static void Load(ResFileSwitchLoader loader, ResFile resFile) { loader.CheckSignature("FRES"); uint padding = loader.ReadUInt32(); resFile.Version = loader.ReadUInt32(); resFile.SetVersionInfo(resFile.Version); resFile.ByteOrder = loader.ReadByteOrder(); resFile.Alignment = loader.ReadByte(); resFile.TargetAddressSize = loader.ReadByte(); //Thanks MasterF0X for pointing out the layout of the these uint OffsetToFileName = loader.ReadUInt32(); resFile.Flag = loader.ReadUInt16(); resFile.BlockOffset = loader.ReadUInt16(); uint RelocationTableOffset = loader.ReadUInt32(); uint sizFile = loader.ReadUInt32(); resFile.Name = loader.LoadString(); long modelOffset = loader.ReadOffset(); long modelDictOffset = loader.ReadOffset(); if (loader.ResFile.VersionMajor2 == 9) { loader.ReadBytes(32); //reserved } resFile.SkeletalAnims = loader.LoadDictValues <SkeletalAnim>(); resFile.MaterialAnims = loader.LoadDictValues <MaterialAnim>(); resFile.BoneVisibilityAnims = loader.LoadDictValues <VisibilityAnim>(); resFile.ShapeAnims = loader.LoadDictValues <ShapeAnim>(); resFile.SceneAnims = loader.LoadDictValues <SceneAnim>(); resFile.MemoryPool = loader.Load <MemoryPool>(); resFile.BufferInfo = loader.Load <BufferInfo>(); resFile.ExternalFiles = loader.LoadDictValues <ExternalFile>(); long padding1 = loader.ReadInt64(); resFile.StringTable = loader.Load <StringTable>(); uint StringPoolSize = loader.ReadUInt32(); ushort numModel = loader.ReadUInt16(); //Read models after buffer data resFile.Models = loader.LoadDictValues <Model>(modelDictOffset, modelOffset); if (loader.ResFile.VersionMajor2 == 9) { //Count for 2 new sections ushort unkCount = loader.ReadUInt16(); ushort unk2Count = loader.ReadUInt16(); if (unkCount != 0) { throw new System.Exception("unk1 has section!"); } if (unk2Count != 0) { throw new System.Exception("unk2 has section!"); } } ushort numSkeletalAnim = loader.ReadUInt16(); ushort numMaterialAnim = loader.ReadUInt16(); ushort numBoneVisibilityAnim = loader.ReadUInt16(); ushort numShapeAnim = loader.ReadUInt16(); ushort numSceneAnim = loader.ReadUInt16(); ushort numExternalFile = loader.ReadUInt16(); uint padding2 = loader.ReadUInt16(); uint padding3 = loader.ReadUInt32(); resFile.Textures = new ResDict <TextureShared>(); foreach (var ext in resFile.ExternalFiles) { if (ext.Key.Contains(".bntx")) { BntxFile bntx = new BntxFile(new MemoryStream(ext.Value.Data)); ext.Value.LoadedFileData = bntx; foreach (var tex in bntx.Textures) { resFile.Textures.Add(tex.Name, new SwitchTexture(bntx, tex)); } } } resFile.TexPatternAnims = new ResDict <MaterialAnim>(); resFile.MatVisibilityAnims = new ResDict <MaterialAnim>(); resFile.ShaderParamAnims = new ResDict <MaterialAnim>(); resFile.ColorAnims = new ResDict <MaterialAnim>(); resFile.TexSrtAnims = new ResDict <MaterialAnim>(); //Split material animations into shader, texture, and visual animation lists foreach (var anim in resFile.MaterialAnims.Values) { if (anim.Name.Contains("_ftp")) { resFile.TexPatternAnims.Add(anim.Name, anim); } else if (anim.Name.Contains("_fts")) { resFile.ShaderParamAnims.Add(anim.Name, anim); } else if (anim.Name.Contains("_fcl")) { resFile.ColorAnims.Add(anim.Name, anim); } else if (anim.Name.Contains("_fst")) { resFile.TexSrtAnims.Add(anim.Name, anim); } else if (anim.Name.Contains("_fvt")) { resFile.MatVisibilityAnims.Add(anim.Name, anim); } else if (anim.MaterialAnimDataList != null && anim.MaterialAnimDataList.Any(x => x.VisibilyCount > 0)) { resFile.MatVisibilityAnims.Add(anim.Name, anim); } else if (anim.MaterialAnimDataList != null && anim.MaterialAnimDataList.Any(x => x.TexturePatternCount > 0)) { resFile.TexPatternAnims.Add(anim.Name, anim); } else { resFile.ShaderParamAnims.Add(anim.Name, anim); } } }