public BFRESBuffer(FileData f) { f.skip(4); // padding 0 size = f.readInt(); f.skip(4); // padding 0 stride = f.readShort(); f.skip(2); // always 1 f.skip(4); // padding 0 dataOffset = f.readOffset(); data = f.getSection(dataOffset, size); }
public void Read(FileData f) { f.skip(4); // magic check f.skip(2); // headerlength if (f.readShort() == 0xFEFF) { f.Endian = Endianness.Big; } else { f.Endian = Endianness.Little; } f.skip(4); // filesize int dataOffset = f.readInt(); f.skip(4); // always 0x01000000 // SFAT Header f.skip(4); // SFAT f.skip(2); // header size int nodeCount = f.readShort(); f.skip(4); // hash multiplyer always 0x65 // before nodes get strings int stringoff = f.pos() + 16 * nodeCount + 8; // nodes for (int i = 0; i < nodeCount; i++) { uint hash = (uint)f.readInt(); byte flag = (byte)f.readByte(); string name = f.readString(stringoff + f.readThree() * 4, -1); int nodeStart = f.readInt(); int size = f.readInt() - nodeStart; Nodes.Add(FileBase.ReadFileBase(new FileData(f.getSection(nodeStart + dataOffset, size), name))); } }
public BRTI(FileData f) //Docs thanks to gdkchan!! { ImageKey = "texture"; SelectedImageKey = "texture"; if (!f.readString(4).Equals("BRTI")) { throw new Exception("Error reading Texture"); } int BRTISize1 = f.readInt(); long BRTISize2 = (f.readInt() | f.readInt() << 32); surf = new Swizzle.Surface(); surf.tileMode = (sbyte)f.readByte(); surf.dim = (sbyte)f.readByte(); ushort Flags = (ushort)f.readShort(); surf.swizzle = (ushort)f.readShort(); surf.numMips = (ushort)f.readShort(); uint unk18 = (uint)f.readInt(); surf.format = (uint)f.readInt(); byte DataType = (byte)(surf.format & 0xFF); uint unk20 = (uint)f.readInt(); surf.width = f.readInt(); surf.height = f.readInt(); surf.depth = f.readInt(); int FaceCount = f.readInt(); surf.sizeRange = f.readInt(); uint unk38 = (uint)f.readInt(); uint unk3C = (uint)f.readInt(); uint unk40 = (uint)f.readInt(); uint unk44 = (uint)f.readInt(); uint unk48 = (uint)f.readInt(); uint unk4C = (uint)f.readInt(); surf.imageSize = f.readInt(); surf.alignment = f.readInt(); int ChannelType = f.readInt(); int TextureType = f.readInt(); Text = f.readString((f.readOffset() | f.readOffset() << 32) + ExternalFiles.DataOffset + 2, -1); long ParentOffset = f.readOffset() | f.readOffset() << 32; long PtrsOffset = f.readOffset() | f.readOffset() << 32; Console.WriteLine($"ParentOffset {ParentOffset} PtrsOffset {PtrsOffset}"); f.seek((int)PtrsOffset + ExternalFiles.DataOffset); long dataOff = f.readOffset() | f.readOffset() << 32; surf.data = f.getSection((int)dataOff + ExternalFiles.DataOffset, surf.imageSize); //Console.WriteLine(surf.data.Length + " " + dataOff.ToString("x") + " " + surf.imageSize); uint blk_dim = Formats.blk_dims(surf.format >> 8); uint blkWidth = blk_dim >> 4; uint blkHeight = blk_dim & 0xF; uint bpp = Formats.bpps(surf.format >> 8); Console.WriteLine($"{Text} Height {surf.height}wdith = {surf.width}allignment = {surf.alignment}blkwidth = {blkWidth}blkheight = {blkHeight}blkdims = {blk_dim} format = {surf.format} datatype = {DataType} dataoffset = {dataOff}"); // byte[] result = surf.data; byte[] result = Swizzle.deswizzle((uint)surf.width, (uint)surf.height, blkWidth, blkHeight, bpp, (uint)surf.tileMode, (uint)surf.alignment, surf.sizeRange, surf.data, 0); uint width = Swizzle.DIV_ROUND_UP((uint)surf.width, blkWidth); uint height = Swizzle.DIV_ROUND_UP((uint)surf.height, blkHeight); byte[] result_ = new byte[width * height * bpp]; Array.Copy(result, 0, result_, 0, width * height * bpp); tex.mipmaps.Add(result_); tex.width = surf.width; tex.height = surf.height; //File.WriteAllBytes(dataOff.ToString("x") + ".bin" ,data); PropertyGridSimpleDemoClass propgrid = new PropertyGridSimpleDemoClass(); switch (surf.format >> 8) { case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC1): if (DataType == (byte)Formats.BNTXImageTypes.UNORM) { tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; propgrid.Format = "FORMAT_T_BC1_UNORM"; } else if (DataType == (byte)Formats.BNTXImageTypes.SRGB) { tex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt1Ext; propgrid.Format = "FORMAT_T_BC1_SRGB"; } else { throw new Exception("Unsupported data type"); } break; case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC2): if (DataType == (byte)Formats.BNTXImageTypes.UNORM) { tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; } else if (DataType == (byte)Formats.BNTXImageTypes.SRGB) { tex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext; } else { throw new Exception("Unsupported data type"); } break; case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC3): if (DataType == (byte)Formats.BNTXImageTypes.UNORM) { tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; propgrid.Format = "FORMAT_T_BC3_UNORM"; } else if (DataType == (byte)Formats.BNTXImageTypes.SRGB) { tex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext; propgrid.Format = "FORMAT_T_BC3_SRGB"; } else { throw new Exception("Unsupported data type"); } break; case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC4): if (DataType == (byte)Formats.BNTXImageTypes.UNORM) { tex.type = PixelInternalFormat.CompressedRedRgtc1; propgrid.Format = "FORMAT_T_BC4_UNORM"; } else if (DataType == (byte)Formats.BNTXImageTypes.SNORM) { tex.type = PixelInternalFormat.CompressedSignedRedRgtc1; propgrid.Format = "FORMAT_T_BC4_SNORM"; } else { throw new Exception("Unsupported data type"); } break; case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC5): if (DataType == (byte)Formats.BNTXImageTypes.UNORM) { tex.type = PixelInternalFormat.CompressedRedRgtc1; propgrid.Format = "FORMAT_T_BC5_UNORM"; } else if (DataType == (byte)Formats.BNTXImageTypes.SNORM) { tex.type = PixelInternalFormat.CompressedSignedRedRgtc1; propgrid.Format = "FORMAT_T_BC5_SNORM"; } else { Console.WriteLine("Unsupported data type"); } break; case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_R8_G8_B8_A8): if (DataType == (byte)Formats.BNTXImageTypes.UNORM || DataType == (byte)Formats.BNTXImageTypes.SRGB) { tex.type = PixelInternalFormat.Rgba; tex.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; } else { throw new Exception("Unsupported data type"); } break; default: MessageBox.Show($"Error! Unsupported texture type for {Text}", "Error"); break; } tex.load(); //Property grid stuff }
public FTEX(FileData f) { ImageKey = "texture"; SelectedImageKey = "texture"; if (!f.readString(4).Equals("FTEX")) { throw new Exception("Error reading Texture"); } sur = new GTX.GX2Surface() { dim = f.readInt(), width = f.readInt(), height = f.readInt(), depth = f.readInt(), numMips = f.readInt(), format = f.readInt(), aa = f.readInt(), use = f.readInt() }; int datalength = f.readInt(); f.skip(4); // unknown sur.mipSize = f.readInt(); f.skip(4); // unknown sur.tileMode = f.readInt(); sur.swizzle = f.readInt(); sur.alignment = f.readInt(); sur.pitch = f.readInt(); f.skip(0x6C); // unknown int dataOff = f.readOffset(); int mipOff = f.readOffset(); f.skip(8); //unkown sur.data = f.getSection(dataOff, datalength); //Console.WriteLine(sur.data.Length + " " + dataOff.ToString("x") + " " + datalength); byte[] data = GTX.swizzleBC(sur.data, sur.width, sur.height, sur.format, sur.tileMode, sur.pitch, sur.swizzle); tex.mipmaps.Add(data); tex.width = sur.width; tex.height = sur.height; //File.WriteAllBytes(dataOff.ToString("x") + ".bin" ,data); switch (sur.format) { case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC1_UNORM): tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC1_SRGB): tex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt1Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC2_UNORM): tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC2_SRGB): tex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC3_UNORM): tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC3_SRGB): tex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC4_UNORM): tex.type = PixelInternalFormat.CompressedRedRgtc1; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC4_SNORM): tex.type = PixelInternalFormat.CompressedSignedRedRgtc1; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_UNORM): tex.type = PixelInternalFormat.CompressedRgRgtc2; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_SNORM): tex.type = PixelInternalFormat.CompressedSignedRgRgtc2; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM): tex.type = PixelInternalFormat.Rgba; tex.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; //default: //throw new Exception("Unknown format"); } tex.load(); }
public FVTX(FileData f) { Text = "VertexAttributeBuffer"; if (!f.readString(4).Equals("FVTX")) { throw new Exception("Error reading Skeleton"); } f.skip(12); //padding int vertexAttribArrayOffset = f.readOffset(); f.skip(4); //padding int vertexAttribDictOffset = f.readOffset(); f.skip(4); //padding int unk = f.readOffset(); f.skip(4); //padding int unk2 = f.readOffset(); f.skip(4); //padding int unk3 = f.readOffset(); f.skip(4); //padding int vertexBufferSizeOffset = f.readOffset(); f.skip(4); //padding int vertexStrideSizeOffset = f.readOffset(); f.skip(4); //padding int vertexBufferArrayOffset = f.readOffset(); f.skip(4); //padding int BufferOffset = f.readOffset(); int attrCount = f.readByte(); int bufferCount = f.readByte(); int index = f.readShort(); vertCount = f.readInt(); int SkinWeightInfluence = f.readInt(); int temp = f.pos(); for (int i = 0; i < attrCount; i++) { f.seek(vertexAttribArrayOffset + (i * 0x10)); attributes.Add(new BFRESAttribute(f, buffers)); } //Find buffer size & stride RelocationTable RLT = new RelocationTable(f); for (int i = 0; i < bufferCount; i++) { f.seek(vertexBufferSizeOffset + ((i) * 0x10)); VertexBufferSize = f.readInt(); f.seek(vertexStrideSizeOffset + ((i) * 0x10)); vertexStrideSize = f.readInt(); //So these work by grabbing the RLT offset first and then adding the buffer offset. Then they keep adding each other by their buffer sizes if (i == 0) { DataOffset = (RLT.DataStart + BufferOffset); } if (i > 0) { DataOffset = BufferOffsets[i - 1].DataOffsetData + BufferOffsets[i - 1].VertexBufferSizeData; } if (DataOffset % 8 != 0) { DataOffset = DataOffset + (8 - (DataOffset % 8)); } BufferOffsets.Add(new BufferData { VertexBufferSizeData = VertexBufferSize, DataOffsetData = DataOffset, VertexStrideSizeData = vertexStrideSize }); dataBuff = f.getSection(BufferOffsets[i].DataOffsetData, BufferOffsets[i].VertexBufferSizeData); Console.WriteLine("Data Offset = " + DataOffset + " Vertex Buffer Size =" + BufferOffsets[i].VertexBufferSizeData + " Index = " + i + " vertexStrideSize size =" + vertexStrideSize); //WriteByteArray(dataBuff, "dataBuff"); BuffSizes.Add(new BufferSizes { BuffSizes = dataBuff }); } Nodes.AddRange(attributes.ToArray()); f.seek(BufferOffsets[0].DataOffsetData); myRender(); f.seek(temp); }