示例#1
0
        } // 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);
        }
示例#2
0
        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);
        }
示例#3
0
 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(0x10 + 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.WriteHex("3C00000000001000090002080000000100000000000000000000000000000000");
                     f.Save(sfd.FileName);
                 }
             }
         }
     }
 }
示例#4
0
            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);
            }
示例#5
0
        public override void Save()
        {
            FileOutput o = new FileOutput();

            byte[] n = lumen.Rebuild();
            o.WriteBytes(n);
            o.Save(lumen.Filename);
            Edited = false;
        }
示例#6
0
        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))));
        }
示例#7
0
        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);
                    }
                }
            }
        }
示例#8
0
        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());
        }
示例#9
0
        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(animType);
            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());
        }
示例#10
0
        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());
        }
示例#11
0
        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;
        }
示例#12
0
        public override void Save()
        {
            if (FilePath.Equals(""))
            {
                SaveAs();
                return;
            }
            FileOutput o = new FileOutput();

            byte[] n = mta.Rebuild();
            o.WriteBytes(n);
            o.Save(FilePath);
            Edited = false;
        }
示例#13
0
        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;
        }
示例#14
0
        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") && currentNut != null)
                    {
                        FileOutput o = new FileOutput();
                        o.WriteBytes(FileData.DeflateZlib(currentNut.Rebuild()));
                        o.Save(sfd.FileName);
                    }
                }
            }
        }
示例#15
0
        public override void Save()
        {
            ShowGtxMipmapWarning(currentNut);

            if (FilePath.Equals(""))
            {
                SaveAs();
                return;
            }

            FileOutput fileOutput = new FileOutput();

            byte[] n = currentNut.Rebuild();

            fileOutput.WriteBytes(n);
            fileOutput.Save(FilePath);
            Edited = false;
        }
示例#16
0
        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);
        }
示例#17
0
        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());
        }
示例#18
0
        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());
        }
示例#19
0
        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());
        }
示例#20
0
        public override byte[] Rebuild()
        {
            FileOutput o    = new FileOutput();
            FileOutput data = new FileOutput();

            //We always want BE for the first six bytes
            o.endian    = Endianness.Big;
            data.endian = Endianness.Big;

            if (Endian == Endianness.Big)
            {
                o.WriteUInt(0x4E545033); //NTP3
            }
            else if (Endian == Endianness.Little)
            {
                o.WriteUInt(0x4E545744); //NTWD
            }

            //Most NTWU NUTs are 0x020E, which isn't valid for NTP3/NTWD
            if (Version > 0x0200)
            {
                Version = 0x0200;
            }
            o.WriteUShort(Version);

            //After that, endian is used appropriately
            o.endian    = Endian;
            data.endian = Endian;

            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);

                if (Version < 0x0200)
                {
                    o.WriteUInt(0);
                }
                else if (Version >= 0x0200)
                {
                    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.WriteBytes(new byte[] { 0x65, 0x58, 0x74, 0x00 }); // "eXt\0"
                o.WriteInt(0x20);
                o.WriteInt(0x10);
                o.WriteInt(0x00);

                o.WriteBytes(new byte[] { 0x47, 0x49, 0x44, 0x58 }); // "GIDX"
                o.WriteInt(0x10);
                o.WriteInt(texture.HashId);
                o.WriteInt(0);

                if (Version < 0x0200)
                {
                    o.WriteOutput(data);
                    data = new FileOutput();
                }
            }

            if (Version >= 0x0200)
            {
                o.WriteOutput(data);
            }

            return(o.GetBytes());
        }
示例#21
0
        public override byte[] Rebuild()
        {
            FileOutput f = new FileOutput();

            f.endian = Endianness.Big;

            f.WriteString("MTA4");
            f.WriteUInt(unknown);
            f.WriteUInt(frameCount);
            f.WriteUInt(startFrame);
            f.WriteUInt(endFrame);
            f.WriteUInt(frameRate);

            f.WriteInt(matEntries.Count);
            if (matEntries.Count > 0)
            {
                f.WriteInt(0x38);
            }
            else
            {
                f.WriteInt(0);
            }
            f.WriteInt(visEntries.Count);
            if (visEntries.Count > 0)
            {
                f.WriteInt(0x38 + 4 * matEntries.Count);
            }
            else
            {
                f.WriteInt(0);
            }
            for (int i = 0; i < 0x10; i++)
            {
                f.WriteByte(0);
            }

            List <byte[]> matEntriesBuilt = new List <byte[]>();
            List <byte[]> visEntriesBuilt = new List <byte[]>();

            int position = 0x38 + matEntries.Count + visEntries.Count;

            while (position % 0x10 != 0)
            {
                position++;
            }

            foreach (MatEntry m in matEntries)
            {
                byte[] b = m.Rebuild(position);
                matEntriesBuilt.Add(b);
                f.WriteInt(position);
                position += b.Length;
                while (position % 0x10 != 0)
                {
                    position++;
                }
            }

            foreach (VisEntry v in visEntries)
            {
                byte[] b = v.Rebuild(position);
                matEntriesBuilt.Add(b);
                f.WriteInt(position);
                position += b.Length;
                while (position % 0x10 != 0)
                {
                    position++;
                }
            }

            while (f.Pos() % 0x10 != 0)
            {
                f.WriteByte(0);
            }

            foreach (byte[] b in matEntriesBuilt)
            {
                f.WriteBytes(b);
                while (f.Pos() % 0x10 != 0)
                {
                    f.WriteByte(0);
                }
            }

            foreach (byte[] b in visEntriesBuilt)
            {
                f.WriteBytes(b);
                while (f.Pos() % 0x10 != 0)
                {
                    f.WriteByte(0);
                }
            }

            return(f.GetBytes());
        }
示例#22
0
        public byte[] Rebuild(int pos)
        {
            FileOutput f = new FileOutput();

            f.endian = Endianness.Big;

            f.WriteInt(pos + f.Pos() + 0x20);
            f.WriteInt(matHash);
            f.WriteInt(properties.Count);
            int nameOffset = pos + f.Pos() + 0x15 + name.Length;

            while (nameOffset % 4 != 0)
            {
                nameOffset++;
            }
            f.WriteInt(nameOffset);
            f.WriteFlag(hasPat);
            f.WriteBytes(new byte[3]);
            //Write all the mat data into a buffer (g) then write pat offset
            int        pos2 = pos + f.Pos() + 4;
            FileOutput g    = new FileOutput();

            g.endian = Endianness.Big;

            if (matHash2 != 0)
            {
                g.WriteInt(pos2 + g.Pos() + 0x8);
                g.WriteInt(matHash);
            }
            else
            {
                g.WriteBytes(new byte[8]);
            }

            g.WriteString(name);
            g.WriteByte(0);
            while ((pos2 + g.Pos()) % 0x10 != 0)
            {
                g.WriteByte(0);
            }

            int position = pos2 + g.Pos() + properties.Count * 4;

            while (position % 16 != 0)
            {
                position++;
            }

            List <byte[]> builtProperties = new List <byte[]>();

            foreach (MatData prop in properties)
            {
                g.WriteInt(position);
                byte[] b = prop.Rebuild(position);
                builtProperties.Add(b);
                position += b.Length;
                while (position % 16 != 0)
                {
                    position++;
                }
            }

            while ((pos2 + g.Pos()) % 16 != 0)
            {
                g.WriteByte(0);
            }

            foreach (byte[] b in builtProperties)
            {
                g.WriteBytes(b);
                while ((pos2 + g.Pos()) % 16 != 0)
                {
                    g.WriteByte(0);
                }
            }

            f.WriteInt(pos2 + g.Pos());
            f.WriteBytes(g.GetBytes());
            if (hasPat)
            {
                f.WriteBytes(pat0.Rebuild(f.Pos()));
            }

            return(f.GetBytes());
        }
示例#23
0
        public static byte[] encodeETC(Bitmap b)
        {
            int width  = b.Width;
            int height = b.Height;

            int[] pixels = new int[width * height];
            init();

            int i, j;

            FileOutput o = new FileOutput();

            o.endian = System.IO.Endianness.Little;

            for (i = 0; i < height; i += 8)
            {
                for (j = 0; j < width; j += 8)
                {
                    int x, y;

                    Color[] temp = new Color[16];
                    int     pi   = 0;
                    for (x = i; x < i + 4; x++)
                    {
                        for (y = j; y < j + 4; y++)
                        {
                            temp[pi++] = b.GetPixel(y, x);
                        }
                    }

                    o.WriteBytes(GenETC1(temp));


                    temp = new Color[16];
                    pi   = 0;
                    for (x = i; x < i + 4; x++)
                    {
                        for (y = j + 4; y < j + 8; y++)
                        {
                            temp[pi++] = b.GetPixel(y, x);
                        }
                    }

                    o.WriteBytes(GenETC1(temp));


                    temp = new Color[16];
                    pi   = 0;
                    for (x = i + 4; x < i + 8; x++)
                    {
                        for (y = j; y < j + 4; y++)
                        {
                            temp[pi++] = b.GetPixel(y, x);
                        }
                    }

                    o.WriteBytes(GenETC1(temp));


                    temp = new Color[16];
                    pi   = 0;
                    for (x = i + 4; x < i + 8; x++)
                    {
                        for (y = j + 4; y < j + 8; y++)
                        {
                            temp[pi++] = b.GetPixel(y, x);
                        }
                    }

                    o.WriteBytes(GenETC1(temp));
                }
            }

            return(o.GetBytes());
        }