protected override void setBMPInternal(int index, ref Bitmap bmp) { if (this.file == null || !this.file.CanWrite) { throw new NotSupportedException("Stream is readonly"); } if (this.compatFixes) { throw new NotSupportedException("Input data had various compatibility fixes applied to be able to load! Cannot save with these."); } parsedImgData imgInfo = this.imgDatas[index]; if (bmp.Width != imgInfo.width || bmp.Height != imgInfo.height) { throw new NotSupportedException("New image has different dimensions"); } { PixelFormat pf; switch (imgInfo.type) { case 19: pf = PixelFormat.Format8bppIndexed; break; case 20: pf = PixelFormat.Format4bppIndexed; break; default: throw new NotSupportedException("Unsupported type"); } if (bmp.PixelFormat != pf) { requestQuantize(ref bmp, pf); } } /*Get the BAR subfile*/ byte[] barFile = this.BAR.fileList[imgInfo.barFile].data; using (BinaryReader br = new BinaryReader(new MemoryStream(barFile, true))) { br.BaseStream.Position = imgInfo.palBOffs; byte[] palData = getData(br, imgInfo.baseP), imgData; { byte[] palette = new byte[1024]; Array.Copy(palData, imgInfo.palOffs, palette, 0, palette.Length); imgData = TexUt2.Encode(bmp, ref palette, imgInfo.palCs); Array.Copy(palette, 0, palData, imgInfo.palOffs, palette.Length); } br.BaseStream.Position = imgInfo.palBOffs; setData(br, imgInfo.baseP, palData); br.BaseStream.Position = imgInfo.imgBOffs; setData(br, imgInfo.baseP, imgData); } this.BAR.fileList[imgInfo.barFile].data = barFile; this.file.Position = 0; this.BAR.save(new Crazycatz00.Utility.Substream(this.file)); }