public void save(FileOutput f) { f.writeHex("030401017735BB750000000201"); f.writeString(name.PadRight(0x38, (char)0)); f.writeByte(1); f.writeString(subname.PadRight(0x40, (char)0)); f.writeByte(1); foreach (float i in startPos) { f.writeFloat(i); } f.writeFlag(useStartPos); f.writeByte(1); f.writeInt(unk2); f.writeByte(1); f.writeBytes(unk3); f.writeHex("FFFFFFFF01"); f.writeChars(unk4); f.writeFlag(flag1); f.writeFlag(flag2); f.writeFlag(flag3); f.writeFlag(flag4); f.writeByte(1); f.writeInt(verts.Count); foreach (Vector2D v in verts) { f.writeByte(1); f.writeFloat(v.x); f.writeFloat(v.y); } f.writeByte(1); f.writeInt(normals.Count); foreach (Vector2D n in normals) { f.writeByte(1); f.writeFloat(n.x); f.writeFloat(n.y); } f.writeByte(1); f.writeInt(0); f.writeByte(1); f.writeInt(materials.Count); foreach (CollisionMat m in materials) { f.writeByte(1); f.writeBytes(m.material); } }
private void injectRom(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Title = "Select NES ROM"; if (ofd.ShowDialog() == DialogResult.OK) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Title = "Select Save Location"; if (sfd.ShowDialog() == DialogResult.OK) { byte[] rom = File.ReadAllBytes(ofd.FileName); FileOutput f = new FileOutput(); f.Endian = Endianness.Little; f.writeInt(0); f.writeInt(0x30 + rom.Length); f.writeInt(0x30); f.writeInt(0x20 + rom.Length); f.writeInt(0x30 + rom.Length); f.writeInt(0); f.writeInt(0x1B + rom.Length); f.writeInt(0x1B + rom.Length); f.writeString("JAM WAS HERE"); f.writeInt(0); f.writeBytes(rom); f.save(sfd.FileName); } } } } }
public void ExportTEX(string filename) { FileOutput o = new FileOutput(); o.Endian = Endianness.Little; o.writeInt(pictureBox1.Image.Width); o.writeInt(pictureBox1.Image.Height); o.writeByte(formatSelector.SelectedIndex); o.writeByte(1); o.writeShort(0); o.writeString(nameBox.Text); for (int i = 0; i < 0x74 - nameBox.Text.Length; i++) { o.writeByte(0); } pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY); o.writeBytes(_3DS.EncodeImage(new Bitmap(pictureBox1.Image), (_3DS.Tex_Formats)formatSelector.SelectedIndex)); pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY); o.save(filename); }
} // Read() #region serialization void writeSymbols(FileOutput o) { FileOutput tag = new FileOutput(); tag.writeInt(Strings.Count); Console.WriteLine($"Strings = [ // offset=0x{o.size():X2}"); for (int i = 0; i < Strings.Count; i++) { var str = Strings[i]; Console.WriteLine($"\t0x{i:X3}: \"{str}\""); var strBytes = Encoding.UTF8.GetBytes(str); tag.writeInt(strBytes.Length); tag.writeBytes(strBytes); int padSize = 4 - (tag.size() % 4); for (int j = 0; j < padSize; j++) { tag.writeByte(0); } } Console.WriteLine("]\n"); o.writeInt((int)TagType.Symbols); o.writeInt(tag.size() / 4); o.writeOutput(tag); }
public override void Save() { FileOutput o = new FileOutput(); byte[] n = Lumen.Rebuild(); o.writeBytes(n); o.save(Lumen.Filename); }
public void Write(FileOutput o) { Console.WriteLine($"unk_{(int)Type:X4} (size=0x{Size * 4:X4}) // offset=0x{o.size():X2}\n"); o.writeInt((int)Type); o.writeInt(Size); o.writeBytes(Data); }
public DRP(string fname) { Text = Path.GetFileNameWithoutExtension(fname); var o = new FileOutput(); o.writeBytes(Decrypt(new FileData(fname))); o.save(fname + "_dec"); Read(new FileData(Decrypt(new FileData(fname)))); }
public void SaveAs(object sender, EventArgs args) { if (Runtime.TargetVBN == null) { MessageBox.Show("You must have a bone-set (VBN) selected to save animations."); return; } using (var sfd = new SaveFileDialog()) { sfd.Filter = "Supported Files (.omo, .anim, .smd)|*.omo;*.anim;*.smd|" + "Maya Anim (.anim)|*.anim|" + "Object Motion (.omo)|*.omo|" + "Source Animation (.smd)|*.smd|" + "All Files (*.*)|*.*"; sfd.DefaultExt = "smd"; //Set a default extension to prevent crashing if not specified by user if (sfd.ShowDialog() == DialogResult.OK) { sfd.FileName = sfd.FileName; if (sfd.FileName.EndsWith(".anim")) { if (Tag is AnimTrack) { ((AnimTrack)Tag).createANIM(sfd.FileName, Runtime.TargetVBN); } else { ANIM.CreateANIM(sfd.FileName, this, Runtime.TargetVBN); } } if (sfd.FileName.EndsWith(".omo")) { if (Tag is FileData) { FileOutput o = new FileOutput(); o.writeBytes(((FileData)Tag).getSection(0, ((FileData)Tag).size())); o.save(sfd.FileName); } else { File.WriteAllBytes(sfd.FileName, OMOOld.CreateOMOFromAnimation(this, Runtime.TargetVBN)); } } if (sfd.FileName.EndsWith(".smd")) { SMD.Save(this, Runtime.TargetVBN, sfd.FileName); } } } }
public void SaveAs(object sender, EventArgs args) { if (Runtime.TargetVBN == null) { MessageBox.Show("You must have a bone set (VBN) open before saving animations"); return; } using (var sfd = new SaveFileDialog()) { sfd.Filter = "Supported Files (.omo, .anim, .smd)|*.omo;*.anim;*.smd|" + "Maya Anim (.anim)|*.anim|" + "Object Motion (.omo)|*.omo|" + "Source Animation (.smd)|*.smd|" + "All Files (*.*)|*.*"; if (sfd.ShowDialog() == DialogResult.OK) { sfd.FileName = sfd.FileName; if (sfd.FileName.EndsWith(".anim")) { if (Tag is AnimTrack) { ((AnimTrack)Tag).createANIM(sfd.FileName, Runtime.TargetVBN); } else { ANIM.CreateANIM(sfd.FileName, this, Runtime.TargetVBN); } } if (sfd.FileName.EndsWith(".omo")) { if (Tag is FileData) { FileOutput o = new FileOutput(); o.writeBytes(((FileData)Tag).getSection(0, ((FileData)Tag).size())); o.save(sfd.FileName); } else { OMOOld.CreateOMOFromAnimation(this, Runtime.TargetVBN); } } if (sfd.FileName.EndsWith(".smd")) { SMD.Save(this, Runtime.TargetVBN, sfd.FileName); } } } }
public override byte[] Rebuild() { FileOutput f = new FileOutput(); f.Endian = endianess; f.writeInt(entries.Count); f.writeInt(otherEntries.Count); f.writeInt(0x30); f.writeInt(0x20); f.writeInt(0x8); f.writeInt(0x30); byte[] entryData = RebuildEntries(new FileOutput()); f.writeInt(entryData.Length + 0x30); f.writeBytes(new byte[0x14]); f.writeBytes(entryData); f.writeBytes(RebuildOtherEntries(new FileOutput(), f.pos())); return(f.getBytes()); }
public byte[] Rebuild(int pos) { FileOutput f = new FileOutput(); f.Endian = Endianness.Big; f.writeInt(pos + f.pos() + 0x20); f.writeInt(Convert.ToInt32(unk1)); int offset = pos + f.pos() + 0x18; offset += name.Length + 1; while (offset % 16 != 0) { offset++; } offset += 0x10; f.writeInt(offset); f.writeBytes(new byte[0x14]); f.writeString(name); f.writeByte(0); while ((pos + f.pos()) % 16 != 0) { f.writeByte(0); } f.writeBytes(new byte[0x10]); f.writeInt(frameCount); f.writeShort(Convert.ToInt32(unk2)); f.writeShort(frames.Count); f.writeInt(pos + f.pos() + 0x18); f.writeBytes(new byte[0x14]); foreach (frame keyframe in frames) { f.writeShort(keyframe.frameNum); f.writeByte(keyframe.state); f.writeByte(keyframe.unknown); } return(f.getBytes()); }
public byte[] Rebuild(int pos) { FileOutput f = new FileOutput(); f.Endian = Endianness.Big; f.writeInt(pos + f.pos() + 0x20); f.writeInt(unknown); f.writeInt(valueCount); f.writeInt(frames.Count); f.writeShort(unknown2); f.writeShort(unknown3); int position = pos + f.pos() + 0xC + name.Length + 1; while (position % 0x10 != 0) { position++; } f.writeInt(position); f.writeBytes(new byte[8]); f.writeString(name); f.writeByte(0); while ((pos + f.pos()) % 0x10 != 0) { f.writeByte(0); } foreach (frame fr in frames) { for (int i = 0; i < valueCount; i++) { f.writeFloat(fr.values[i]); } } f.writeBytes(new byte[0x10]); return(f.getBytes()); }
public override void Save() { if (String.IsNullOrEmpty(FilePath)) { SaveAs(); return; } FileOutput o = new FileOutput(); byte[] n = swag.Rebuild(); o.writeBytes(n); o.save(FilePath); Edited = false; }
public override void Save() { if (FilePath.Equals("")) { SaveAs(); return; } FileOutput o = new FileOutput(); byte[] n = VBN.Rebuild(); o.writeBytes(n); o.save(FilePath); Edited = false; }
public override void Save() { if (FilePath.Equals("")) { SaveAs(); return; } FileOutput fileOutput = new FileOutput(); byte[] n = currentNut.Rebuild(); fileOutput.writeBytes(n); fileOutput.save(FilePath); Edited = false; }
public override void Save() { if (FilePath.Equals("")) { SaveAs(); return; } FileOutput o = new FileOutput(); mta.Compile(new List <string>(richTextBox1.Text.Split('\n'))); byte[] n = mta.Rebuild(); o.writeBytes(n); o.save(FilePath); Edited = false; }
public void ExportTEX(string filename) { FileOutput o = new FileOutput(); o.Endian = Endianness.Little; o.writeInt(pictureBox1.Image.Width); o.writeInt(pictureBox1.Image.Height); o.writeByte(formatSelector.SelectedIndex); o.writeByte(1); o.writeShort(0); o.writeString(nameBox.Text); for (int i = 0; i < 0x74 - nameBox.Text.Length; i++) { o.writeByte(0); } pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY); if (formatSelector.SelectedIndex == 0x0C) { o.writeBytes(Pixel.encodeETC(new Bitmap(pictureBox1.Image))); } if (formatSelector.SelectedIndex == 0x0D) { o.writeBytes(Pixel.encodeETCa4(new Bitmap(pictureBox1.Image))); } else { throw new Exception("Unsuppored format"); } pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY); o.save(filename); }
public override void Save() { if (FilePath.Equals("")) { SaveAs(); return; } PromptUserToConfirmMipRegenIfGtx(currentNut); FileOutput fileOutput = new FileOutput(); byte[] n = currentNut.Rebuild(); fileOutput.writeBytes(n); fileOutput.save(FilePath); Edited = false; }
private void saveNUTZLIBToolStripMenuItem_Click(object sender, EventArgs e) { using (var sfd = new SaveFileDialog()) { sfd.Filter = "Namco Universal Texture (.nut)|*.nut|" + "All Files (*.*)|*.*"; if (sfd.ShowDialog() == DialogResult.OK) { if (sfd.FileName.EndsWith(".nut") && NUT != null) { FileOutput o = new FileOutput(); o.writeBytes(FileData.DeflateZLIB(NUT.Rebuild())); o.save(sfd.FileName); } } } }
public override void Save() { if (FilePath.Equals("")) { SaveAs(); return; } FileOutput fileOutput = new FileOutput(); byte[] n = NUT.Rebuild(); //Temporarily disabling this prompt until zlib works properly /*DialogResult dialogResult = MessageBox.Show("Would you like to compress this NUT file with zlib?\nIf you are unsure, select \"No\".", "zlib Compression", MessageBoxButtons.YesNo); * if (dialogResult == DialogResult.Yes) * n = FileData.DeflateZLIB(n);*/ fileOutput.writeBytes(n); fileOutput.save(FilePath); Edited = false; }
public void save(FileOutput f) { base.save(f); f.writeFlag(flag1); f.writeFlag(flag2); f.writeFlag(flag3); f.writeFlag(flag4); f.writeByte(1); f.writeInt(verts.Count); foreach (Vector2D v in verts) { f.writeByte(1); f.writeFloat(v.x); f.writeFloat(v.y); } f.writeByte(1); f.writeInt(normals.Count); foreach (Vector2D n in normals) { f.writeByte(1); f.writeFloat(n.x); f.writeFloat(n.y); } f.writeByte(1); f.writeInt(cliffs.Count); foreach (CollisionCliff c in cliffs) { c.save(f); } f.writeByte(1); f.writeInt(materials.Count); foreach (CollisionMat m in materials) { f.writeByte(1); f.writeBytes(m.material); } }
public override void Save() { if (FilePath.Equals("")) { SaveAs(); return; } FileOutput o = new FileOutput(); byte[] n = NUT.Rebuild(); DialogResult dialogResult = MessageBox.Show("Would you like to compress this NUT file with zlib?\nIf you are unsure, select \"No\".", "zlib Compression", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { n = FileData.DeflateZLIB(n); } o.writeBytes(n); o.save(FilePath); Edited = false; }
public byte[] Rebuild(int pos) { FileOutput f = new FileOutput(); f.Endian = Endianness.Big; f.writeInt(pos + f.pos() + 0x8); f.writeInt(0); f.writeInt(defaultTexId); f.writeInt(keyframes.Count); f.writeInt(pos + f.pos() + 0x1C); f.writeInt(frameCount - 1); f.writeInt(unknown); f.writeBytes(new byte[0x10]); foreach (keyframe k in keyframes) { f.writeInt(k.texId); f.writeInt(k.frameNum); } return(f.getBytes()); }
public void Save(string fname) { FileOutput f = new FileOutput(); f.Endian = System.IO.Endianness.Little; f.writeUInt(magic); f.writeUInt(header.size); f.writeUInt(header.flags); f.writeUInt(header.height); f.writeUInt(header.width); f.writeUInt(header.pitchOrLinearSize); f.writeUInt(header.depth); f.writeUInt(header.mipmapCount); for (int i = 0; i < 11; ++i) { f.writeUInt(header.reserved1[i]); } f.writeUInt(header.ddspf.size); f.writeUInt(header.ddspf.flags); f.writeUInt(header.ddspf.fourCC); f.writeUInt(header.ddspf.RGBBitCount); f.writeUInt(header.ddspf.RBitMask); f.writeUInt(header.ddspf.GBitMask); f.writeUInt(header.ddspf.BBitMask); f.writeUInt(header.ddspf.ABitMask); f.writeUInt(header.caps); f.writeUInt(header.caps2); f.writeUInt(header.caps3); f.writeUInt(header.caps4); f.writeUInt(header.reserved2); f.writeBytes(bdata); f.save(fname); }
public byte[] RebuildEntries(FileOutput f) { List <int> nameOffsets = new List <int>(); int nameTableOffset = 0x30 + (0x20 * entries.Count); FileOutput nameTable = new FileOutput() { Endian = Endianness.Big }; foreach (Entry entry in entries) { nameOffsets.Add(nameTableOffset + nameTable.pos()); nameTable.writeString(entry.name); nameTable.writeBytes(new byte[4 - (entry.name.Length % 4)]); //Pad to next word } while (nameTable.pos() % 0x10 != 0) { nameTable.writeByte(0); } for (int i = 0; i < entries.Count; i++) { entries[i].values[0] = nameOffsets[i]; } foreach (Entry entry in entries) { foreach (int value in entry.values) { f.writeInt(value); } } f.writeBytes(nameTable.getBytes()); return(f.getBytes()); }
public void Save(string fname) { FileOutput f = new FileOutput(); f.Endian = System.IO.Endianness.Little; f.writeString("DDS "); f.writeInt(header.size); f.writeInt(header.flags); f.writeInt(header.height); f.writeInt(header.width); f.writeInt(header.pitchOrLinear); f.writeInt(header.depth); f.writeInt(header.mipmapCount); for (int i = 0; i < 11; i++) { f.writeInt(0); } f.writeInt(header.dwSize); f.writeInt(header.dwFlags); f.writeInt(header.dwFourCC); f.writeInt(header.dwBitmask); f.writeInt((int)header.dwCaps); f.writeInt((int)header.dwCaps2); f.writeInt((int)header.dwCaps3); f.writeInt((int)header.dwCaps4); f.writeInt((int)header.reserve); for (int i = 0; i < 4; i++) { f.writeInt(0); } f.writeBytes(data); f.save(fname); }
public override byte[] Rebuild() { FileOutput o = new FileOutput(); o.writeInt(0x4E545033); // "NTP3" o.writeShort(0x0200); o.writeShort(textures.Count); o.writeInt(0); o.writeInt(0); int offset = textures.Count * 0x60; foreach (var texture in textures) { int size = 0; int headerSize = 0x60; foreach (var mip in texture.mipmaps) { size += mip.Length; } // // headerSize 0x50 seems to crash with models //if (texture.mipmaps.Count == 1) //{ // headerSize = 0x50; //} o.writeInt(size + headerSize); o.writeInt(0x00); o.writeInt(size); o.writeShort(headerSize); o.writeShort(0); o.writeShort(texture.mipmaps.Count); o.writeShort(texture.getNutFormat()); o.writeShort(texture.width); o.writeShort(texture.height); o.writeInt(0); o.writeInt(0); o.writeInt(offset); o.writeInt(0); o.writeInt(0); o.writeInt(0); if (headerSize > 0x50) { foreach (var mip in texture.mipmaps) { o.writeInt(mip.Length); } // Sizes for missing mips. for (int j = 0; j < 4 - texture.mipmaps.Count; j++) { o.writeInt(0); } } o.writeInt(0x65587400); // "eXt\0" o.writeInt(0x20); o.writeInt(0x10); o.writeInt(0x00); o.writeInt(0x47494458); // "GIDX" o.writeInt(0x10); o.writeInt(texture.id); o.writeInt(0); offset += (size - headerSize); } foreach (var texture in textures) { int m = 0; foreach (var mip in texture.mipmaps) { int off = 0; if (texture.getNutFormat() == 14) { for (int h = 0; h < (texture.height / (Math.Pow(2, m))) * (texture.width / (Math.Pow(2, m))); h++) { for (int p = 0; p < 4; p++) { if (p == 0) { o.writeByte(mip[off + 3]); } else { o.writeByte(mip[off + (p - 1)]); } } off += 4; } } else { o.writeBytes(mip); } m++; } } return(o.getBytes()); }
public override byte[] Rebuild() { FileOutput o = new FileOutput(); FileOutput data = new FileOutput(); o.writeInt(0x4E545033); // "NTP3" o.writeShort(0x0200); o.writeShort(textures.Count); o.writeInt(0); o.writeInt(0); //calculate total header size int headerLength = 0; foreach (var texture in textures) { int headerSize = 0x50; if (texture.mipmaps.Count > 1) { headerSize += texture.mipmaps.Count * 4; while (headerSize % 16 != 0) { headerSize += 4; } } headerLength += headerSize; } // write headers+data foreach (var texture in textures) { int size = 0; foreach (var mip in texture.mipmaps) { size += mip.Length; while (size % 16 != 0) { size += 1; } } int headerSize = 0x50; // calculate header size if (texture.mipmaps.Count > 1) { headerSize += texture.mipmaps.Count * 4; //align to 16 while (headerSize % 16 != 0) { headerSize += 1; } } o.writeInt(size + headerSize); o.writeInt(0x00); //padding o.writeInt(size); o.writeShort(headerSize); //+ (texture.mipmaps.Count - 4 > 0 ? texture.mipmaps.Count - 4 : 0) * 4 o.writeShort(0); o.writeShort(texture.mipmaps.Count); o.writeShort(texture.getNutFormat()); o.writeShort(texture.width); o.writeShort(texture.height); o.writeInt(0); o.writeInt(0); o.writeInt(headerLength + data.size()); headerLength -= headerSize; o.writeInt(0); o.writeInt(0); o.writeInt(0); if (texture.getNutFormat() == 14 || texture.getNutFormat() == 17) { foreach (byte[] mip in texture.mipmaps) { for (int t = 0; t < mip.Length; t += 4) { byte t1 = mip[t + 3]; mip[t + 3] = mip[t + 2]; mip[t + 2] = mip[t + 1]; mip[t + 1] = mip[t]; mip[t] = t1; } } } foreach (var mip in texture.mipmaps) { int ds = data.size(); data.writeBytes(mip); data.align(0x10); if (texture.mipmaps.Count > 1) { o.writeInt(data.size() - ds); } } o.align(16); if (texture.getNutFormat() == 14 || texture.getNutFormat() == 17) { foreach (byte[] mip in texture.mipmaps) { for (int t = 0; t < mip.Length; t += 4) { byte t1 = mip[t]; mip[t] = mip[t + 1]; mip[t + 1] = mip[t + 2]; mip[t + 2] = mip[t + 3]; mip[t + 3] = t1; } } } o.writeInt(0x65587400); // "eXt\0" o.writeInt(0x20); o.writeInt(0x10); o.writeInt(0x00); o.writeInt(0x47494458); // "GIDX" o.writeInt(0x10); o.writeInt(texture.id); o.writeInt(0); } o.writeOutput(data); return(o.getBytes()); }
public override byte[] Rebuild() { FileOutput o = new FileOutput(); FileOutput data = new FileOutput(); o.writeUInt(0x4E545033); // "NTP3" o.writeUShort(Version); o.writeUShort((ushort)Nodes.Count); o.writeInt(0); o.writeInt(0); //calculate total header size uint headerLength = 0; foreach (NutTexture texture in Nodes) { byte surfaceCount = (byte)texture.surfaces.Count; bool isCubemap = surfaceCount == 6; if (surfaceCount < 1 || surfaceCount > 6) { throw new NotImplementedException($"Unsupported surface amount {surfaceCount} for texture with hash 0x{texture.HashId:X}. 1 to 6 faces are required."); } else if (surfaceCount > 1 && surfaceCount < 6) { throw new NotImplementedException($"Unsupported cubemap face amount for texture with hash 0x{texture.HashId:X}. Six faces are required."); } byte mipmapCount = (byte)texture.surfaces[0].mipmaps.Count; ushort headerSize = 0x50; if (isCubemap) { headerSize += 0x10; } if (mipmapCount > 1) { headerSize += (ushort)(mipmapCount * 4); while (headerSize % 0x10 != 0) { headerSize += 1; } } headerLength += headerSize; } // write headers+data foreach (NutTexture texture in Nodes) { byte surfaceCount = (byte)texture.surfaces.Count; bool isCubemap = surfaceCount == 6; byte mipmapCount = (byte)texture.surfaces[0].mipmaps.Count; uint dataSize = 0; foreach (var mip in texture.GetAllMipmaps()) { dataSize += (uint)mip.Length; while (dataSize % 0x10 != 0) { dataSize += 1; } } ushort headerSize = 0x50; if (isCubemap) { headerSize += 0x10; } if (mipmapCount > 1) { headerSize += (ushort)(mipmapCount * 4); while (headerSize % 0x10 != 0) { headerSize += 1; } } o.writeUInt(dataSize + headerSize); o.writeUInt(0); o.writeUInt(dataSize); o.writeUShort(headerSize); o.writeUShort(0); o.writeByte(0); o.writeByte(mipmapCount); o.writeByte(0); o.writeByte(texture.getNutFormat()); o.writeShort(texture.Width); o.writeShort(texture.Height); o.writeInt(0); o.writeUInt(texture.DdsCaps2); o.writeUInt((uint)(headerLength + data.size())); headerLength -= headerSize; o.writeInt(0); o.writeInt(0); o.writeInt(0); if (isCubemap) { o.writeInt(texture.surfaces[0].mipmaps[0].Length); o.writeInt(texture.surfaces[0].mipmaps[0].Length); o.writeInt(0); o.writeInt(0); } if (texture.getNutFormat() == 14 || texture.getNutFormat() == 17) { texture.SwapChannelOrderDown(); } for (byte surfaceLevel = 0; surfaceLevel < surfaceCount; ++surfaceLevel) { for (byte mipLevel = 0; mipLevel < mipmapCount; ++mipLevel) { int ds = data.size(); data.writeBytes(texture.surfaces[surfaceLevel].mipmaps[mipLevel]); data.align(0x10); if (mipmapCount > 1 && surfaceLevel == 0) { o.writeInt(data.size() - ds); } } } o.align(0x10); if (texture.getNutFormat() == 14 || texture.getNutFormat() == 17) { texture.SwapChannelOrderUp(); } o.writeUInt(0x65587400); // "eXt\0" o.writeInt(0x20); o.writeInt(0x10); o.writeInt(0x00); o.writeUInt(0x47494458); // "GIDX" o.writeInt(0x10); o.writeInt(texture.HashId); o.writeInt(0); } o.writeOutput(data); return(o.getBytes()); }
public static byte[] EncodeImage(Bitmap img, Tex_Formats type) { if (type == Tex_Formats.ETC1) { return(RG_ETC1.encodeETC(img)); } if (type == Tex_Formats.ETC1a4) { return(RG_ETC1.encodeETCa4(img)); } FileOutput o = new FileOutput(); BitmapData bmpData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.WriteOnly, img.PixelFormat); int[] pixels = new int[img.Width * img.Height]; Marshal.Copy(bmpData.Scan0, pixels, 0, pixels.Length); img.UnlockBits(bmpData); for (int h = 0; h < img.Height; h += 8) { for (int w = 0; w < img.Width; w += 8) { // 8x8 block List <byte[]> colors = new List <byte[]>(); for (int bh = 0; bh < 8; bh++) { for (int bw = 0; bw < 8; bw++) { switch (type) { case Tex_Formats.RGBA8: colors.Add(encode8888(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.RGB8: colors.Add(encode8(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.RGBA4444: colors.Add(encode4444(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.RGBA5551: colors.Add(encode5551(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.RGB565: colors.Add(encode565(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.LA8: colors.Add(encodeLA8(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.HILO8: colors.Add(encodeHILO8(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.L8: colors.Add(encodeL8(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.A8: colors.Add(encodeA8(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.LA4: colors.Add(encodeLA4(pixels[(w + bw) + (h + bh) * img.Width])); break; case Tex_Formats.L4: { colors.Add(new byte[] { (byte)((encodeL8(pixels[(w + bw) + (h + bh) * img.Width])[0] / 0x11) & 0xF | ((encodeL8(pixels[(w + bw) + (h + bh) * img.Width + 1])[0] / 0x11) << 4)) }); bw++; break; } case Tex_Formats.A4: { colors.Add(new byte[] { (byte)((encodeA8(pixels[(w + bw) + (h + bh) * img.Width])[0] / 0x11) & 0xF | ((encodeA8(pixels[(w + bw) + (h + bh) * img.Width + 1])[0] / 0x11) << 4)) }); bw++; break; } } } } for (int bh = 0; bh < 8; bh++) { for (int bw = 0; bw < 8; bw++) { int pos = bw + bh * 8; for (int i = 0; i < zorder.Length; i++) { if (zorder[i] == pos) { if (type == Tex_Formats.L4 || type == Tex_Formats.A4) { i /= 2; bw++; } o.writeBytes(colors[i]); break; } } } } } } return(o.getBytes()); }