Пример #1
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "";
            openFileDialog1.Filter   = "All Files (*.*)|*.*";
            DialogResult res = openFileDialog1.ShowDialog();

            if (res == DialogResult.OK)
            {
                numBlocks = 0;
                listBytes = new List <byte[]>();

                string file = openFileDialog1.FileName;
                GTFS   fs   = new GTFS(file);

                for (int i = 0; i < fs.Length; i += 4)
                {
                    byte[] bytes = GT.ReadBytes(fs, 4, false);

                    listBytes.Add(bytes);
                    numBlocks++;
                }

                RefreshTable();
            }
        }
Пример #2
0
            public MTCFrame(GTFS fs, int mtcWidth, int mtcHeight)
            {
                //pixels = new Color[mtcWidth * mtcHeight];
                bitmap = new Bitmap(mtcWidth, mtcHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                int i = 0;

                for (int y = 0; y < mtcHeight; y++)
                {
                    for (int x = 0; x < mtcWidth; x++)
                    {
                        byte left  = (byte)fs.ReadByte();
                        byte right = (byte)fs.ReadByte();

                        ushort palette = (ushort)(right | left << 8);
                        Color  c       = FRM.Palette2Color(palette);

                        if (c.R != c.G && c.G != c.B)
                        {
                            c = Color.FromArgb(150, c);
                        }
                        else
                        {
                            c = Color.FromArgb(0, c);
                        }

                        //pixels[i++] = c;
                        bitmap.SetPixel(x, y, c);
                    }
                }
            }
Пример #3
0
        public static void Open(OpenFileDialog openFileDialog)
        {
            bool flip = false;
            GTFS fs   = new GTFS(openFileDialog.FileName);

            int numFrames = GT.ReadInt32(fs, 4, flip);

            int[] remaining = new int[22];
            for (int i = 0; i < 22; i++)
            {
                remaining[i] = GT.ReadInt32(fs, 4, flip);
            }
            //fs.Position = 0x5C;

            int[] offsetCoTable = new int[numFrames];
            int[] lenCoTable    = new int[numFrames];
            int[] lenBuffer     = new int[numFrames]; //This doesn't seem to be at all related to the length of the CoTable...

            for (int i = 0; i < numFrames; i++)
            {
                offsetCoTable[i] = GT.ReadInt32(fs, 4, flip);
                lenCoTable[i]    = GT.ReadInt32(fs, 4, flip);
                lenBuffer[i]     = GT.ReadInt32(fs, 4, flip);
            }

            //--

            for (int i = 0; i < numFrames; i++)
            {
                bool[,] coord = new bool[16, 16];

                fs.Position = offsetCoTable[i];
                //Console.WriteLine("Pos: " + fs.Position);
                for (int k = 0; k < lenCoTable[i]; k += 2)
                {
                    int x = GT.ReadByte(fs);
                    int y = GT.ReadByte(fs);

                    coord[x, y] = true;
                }

                GT.WriteSubFile(fs, "test-" + i + ".brf", lenBuffer[i]);

                /*
                 * for(int x = 0; x < 16; x++) {
                 *  for(int y = 0; y < 16; y++) {
                 *      if(coord[x,y])
                 *          Console.Write("X");
                 *      else
                 *          Console.Write(".");
                 *  }
                 *  Console.WriteLine();
                 * }
                 * Console.WriteLine("\n");
                 */
            }

            Console.WriteLine();
        }
Пример #4
0
            public URBLinux(GTFS fs, int remlen = 0)
            {
                bool flip = false;

                //URB
                id              = GT.ReadBytes(fs, 8, flip); //ulong
                event_type      = GT.ReadByte(fs);
                transfer_type   = (TransferType)GT.ReadByte(fs);
                endpoint_number = GT.ReadByte(fs);
                device_address  = GT.ReadByte(fs);
                bus_id          = GT.ReadUInt16(fs, 2, flip);
                setup_flag      = GT.ReadByte(fs);           //char
                data_flag       = GT.ReadByte(fs);           //char
                ts_sec          = GT.ReadBytes(fs, 8, flip); //long
                ts_usec         = GT.ReadInt32(fs, 4, flip);
                status          = GT.ReadInt32(fs, 4, flip);
                urb_len         = GT.ReadUInt32(fs, 4, flip);
                data_len        = GT.ReadUInt32(fs, 4, flip);
                remlen         -= 40;

                //URB Setup
                bmRequestType = GT.ReadByte(fs);
                bRequest      = GT.ReadByte(fs);
                wValue        = GT.ReadUInt16(fs, 2, flip);
                wIndex        = GT.ReadUInt16(fs, 2, flip);
                wLength       = GT.ReadUInt16(fs, 2, flip);
                remlen       -= 8;

                interval          = GT.ReadInt32(fs, 4, flip);
                startFrame        = GT.ReadInt32(fs, 4, flip);
                copyTransferFlags = GT.ReadBytes(fs, 4, flip);
                numISOdesc        = GT.ReadInt32(fs, 4, flip);
                remlen           -= 16;

                if (numISOdesc > 0)
                {
                    listIsodesc = new List <isodesc>();
                    for (int i = 0; i < numISOdesc; i++)
                    {
                        isodesc desc = new isodesc(fs, true);
                        listIsodesc.Add(desc);
                    }

                    remlen   -= numISOdesc * 16;
                    remaining = GT.ReadBytes(fs, remlen, flip);

                    if (remlen > 0)
                    {
                        for (int i = 0; i < numISOdesc; i++)
                        {
                            listIsodesc[i].ReadData(remaining);
                        }
                    }
                }
                else
                {
                    remaining = GT.ReadBytes(fs, remlen, flip);
                }
            }
Пример #5
0
        static void Main(string[] args)
        {
            bool flip      = false;
            GTFS fs        = new GTFS("Bracelet-F0.frm");
            int  zero      = GT.ReadInt32(fs, 4, flip);
            int  len       = GT.ReadInt32(fs, 4, flip);
            int  sixtyfour = GT.ReadInt32(fs, 4, flip);
            int  next      = GT.ReadInt32(fs, 4, flip);

            List <byte> listBytes = new List <byte>();

            while (fs.Position - 16 < len)
            {
                byte first = GT.ReadByte(fs);

                if (first < 0x40 || first == 0x7F)   //0x7F for Br_bracelet_.anm
                {
                    for (int i = 0; i < first; i++)
                    {
                        byte b = GT.ReadByte(fs);
                        listBytes.Add(b);
                    }
                }
                else if (first == 0x40)
                {
                    throw new Exception();
                }
                else if (first < 0x80)
                {
                    int  repeatlen = first - 0x40;
                    byte second    = GT.ReadByte(fs);
                    for (int i = 0; i < repeatlen; i++)
                    {
                        listBytes.Add(second);
                    }
                }
                else if (first == 0x80)
                {
                    throw new Exception();
                }
                else
                {
                    int gap = first - 0x80;
                    for (int i = 0; i < gap; i++)
                    {
                        listBytes.Add(0xFF);
                    }
                }
            }

            FileStream nf = new FileStream("Test-HTD-ANMFRM.bin", FileMode.Create);

            foreach (byte b in listBytes)
            {
                nf.WriteByte(b);
            }
            nf.Close();
        }
Пример #6
0
        public static void Open(string file, string outdir)
        {
            bool flip  = false;
            GTFS fs    = new GTFS(file);
            uint count = GT.ReadUInt32(fs, 4, flip) / 4;

            if (count < 300)
            {
                uint[] ExOffset = new uint[count];
                uint[] ExSize   = new uint[count];

                //Outdir is wrong, but other than that this is fine.

                if (count > 0)
                {
                    Directory.CreateDirectory(outdir);
                }

                for (int i = 0; i < count; i++)
                {
                    ExOffset[i] = GT.ReadUInt32(fs, 4, flip);
                }
                for (int i = 0; i < count; i++)
                {
                    ExSize[i] = GT.ReadUInt32(fs, 4, flip);
                }

                for (int i = 0; i < count; i++)
                {
                    if (ExSize[i] > 0)
                    {
                        string ext  = "bin";
                        uint   head = GT.ReadUInt32(fs, 4, flip);
                        if (head == 0x474E5089)
                        {
                            ext = "png";
                        }
                        else if (head == 0xE0FFD8FF || head == 0xE1FFD8FF)
                        {
                            ext = "jpg";
                        }

                        if (!File.Exists(outdir + "\\" + i + "." + ext))
                        {
                            string newfile = outdir + "\\" + i + "." + ext;
                            GT.WriteSubFile(fs, newfile, ExSize[i], ExOffset[i]);

                            /*
                             * if (ext == "bin") { //Might be a Resource pack
                             *  string newDirIn = outdir + "\\" + i + "-" + ext;
                             *  ResourceImage.Open(outdir + "\\" + i + "." + ext, newDirIn);
                             * }
                             */
                        }
                    }
                }
            } //End Count limit
        }
Пример #7
0
        public static void Decompress(string file)   //"EP1_BOOK.txt"
        {
            GTFS fs = new GTFS(file);

            byte[] header = GT.ReadBytes(fs, 4, false);
            int    sizeun = GT.ReadInt32(fs, 4, false);
            int    sizeco = GT.ReadInt32(fs, 4, false);
            int    zero   = GT.ReadInt32(fs, 4, false);

            string uncompressed = "";

            while (fs.Position < sizeco)   // Wrong but it'll do?
            {
                byte     input = GT.ReadByte(fs);
                BitArray bits  = new BitArray(new byte[] { input });

                for (int i = 0; i < 8; i++)
                {
                    if (bits[i])
                    {
                        byte b = GT.ReadByte(fs);
                        uncompressed += (char)b;
                    }
                    else
                    {
                        byte[] lookup = GT.ReadBytes(fs, 3, false);
                        int    len    = 4 + lookup[2];

                        int offset = lookup[0] + 3;

                        if (lookup[1] < 255 && lookup[1] > 10)
                        {
                            offset -= 256 * (255 - lookup[1]);
                            string add = uncompressed.Substring(offset, len);
                            uncompressed += add;
                        }
                        else
                        {
                            if (lookup[1] < 127)
                            {
                                offset += 256 * (lookup[1] + 1);
                            }
                            else
                            {
                                throw new Exception();
                            }

                            string add = uncompressed.Substring(offset, len);

                            uncompressed += add;
                        }
                    }
                }
            }

            Console.WriteLine(uncompressed);
            Console.WriteLine();
        }
Пример #8
0
        public ANM(GTFS fs)
        {
            flip           = false;
            this.fs        = fs;
            FileName       = fs.FilePath;
            SafeFileName   = Path.GetFileName(FileName);
            listPackFrames = new List <Pack>();
            listFrames     = new List <FRM>();

            //--

            uint unk1               = GT.ReadUInt32(fs, 4, flip);
            uint numFrames          = GT.ReadUInt32(fs, 4, flip);
            uint numFramesHeaderLen = GT.ReadUInt32(fs, 4, flip);
            uint unk2               = GT.ReadUInt32(fs, 4, flip);

            Height = GT.ReadUInt16(fs, 2, flip);
            Width  = GT.ReadUInt16(fs, 2, flip);
            uint unk3 = GT.ReadUInt32(fs, 4, flip);
            uint unk4 = GT.ReadUInt32(fs, 4, flip);
            uint unk5 = GT.ReadUInt32(fs, 4, flip);

            for (int i = 0; i < numFrames; i++)
            {
                uint frameOffset = GT.ReadUInt32(fs, 4, flip);
                uint frameLen    = GT.ReadUInt32(fs, 4, flip);
                uint frameUnk    = GT.ReadUInt32(fs, 4, flip);
                uint framePad    = GT.ReadUInt32(fs, 4, flip);

                string name = "Frame " + i + ".frm";
                listPackFrames.Add(new Pack(name, frameOffset, frameLen));
            }

            Bitmap lastBitmap = null;

            foreach (Pack pack in listPackFrames)
            {
                FRM frm = new FRM(fs, pack, Height, Width, lastBitmap);
                listFrames.Add(frm);

                lastBitmap = frm.bitmap;
            }

            //--

            string filemtc = FileName.Replace(".anm", "m_.mtc");

            if (File.Exists(filemtc))
            {
                mtc = new MTC(new GTFS(filemtc));
                Console.WriteLine();
            }
        }
Пример #9
0
        public static void Open(string file, string outdir)
        {
            throw new NotImplementedException();

            bool flip  = false;
            GTFS fs    = new GTFS(file);
            int  count = GT.ReadInt32(fs, 4, flip) / 4;

            for (int i = 0; i < count; i++)
            {
            }
        }
Пример #10
0
        public override void Open(OpenFileDialog openFileDialog, bool export = false, bool useGTFSView = false)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "All Last Window|*.pack;*.bra;*.bin;*.bpg;*.ebp|"
                                      + "All Files (*.*)|*.*";

            DialogResult res = openFileDialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                string[] filenameParts = openFileDialog.SafeFileName.Split('.');
                Array.Reverse(filenameParts);

                if (filenameParts[0].ToUpper() == "BPG")
                {
                    BPG bpg = new BPG(Decompress(openFileDialog.FileName));
                    new FormImage(bpg.bitmap).Show();
                }
                else if (filenameParts[0].ToUpper() == "EBP")
                {
                    GTFS fs = Decompress(openFileDialog.FileName);
                    fs.WriteBytesToFile(openFileDialog.SafeFileName + ".gtbin");

                    EBP ebp = new EBP(fs);

                    if (ebp.bitmap != null)
                    {
                        new FormImage(ebp.bitmap).Show();
                    }
                }
                else if (filenameParts[0].ToUpper() == "BIN")
                {
                    GTFS fs = Decompress(openFileDialog.FileName);
                    fs.WriteBytesToFile("GT-KH-ZL.out");
                }
                else if (filenameParts[0].ToUpper() == "BRA")
                {
                    LWBRA.Open(openFileDialog);
                }
                else if (filenameParts[0].ToUpper() == "PACK")
                {
                    LWPack.OpenPack(openFileDialog.FileName, openFileDialog.SafeFileName);
                }
                else
                {
                    MessageBox.Show("Unexpected file extension: " + filenameParts[0]);
                }
            }
        }
Пример #11
0
        public RunawayPackedImage(GTFS fs)
        {
            first     = GT.ReadInt16(fs, 2, false);
            second    = GT.ReadInt16(fs, 2, false);
            numValues = GT.ReadInt16(fs, 2, false);
            values    = new byte[numValues];

            derivedfirstadd      = first + numValues;
            derivedfirstsubtract = first - numValues;

            for (int i = 0; i < numValues; i++)
            {
                values[i] = GT.ReadByte(fs);
            }
        }
Пример #12
0
        public static void Open(string file, string outdir)
        {
            bool flip = false;
            GTFS fs   = new GTFS(file);

            string newDir = file.Replace('.', '-');//.Replace("\\uk", "");
            //if (newDir.Contains("uk"))
            //throw new Exception();

            uint count = GT.ReadUInt32(fs, 4, flip) / 4;

            uint[] ExOffset  = new uint[count];
            uint[] ExSize    = new uint[count];
            uint[] ExUnknown = new uint[count];
            byte[] ExType    = new byte[count];

            if (count > 0)
            {
                Directory.CreateDirectory(newDir);
            }

            for (int i = 0; i < count; i++)
            {
                ExOffset[i]  = GT.ReadUInt32(fs, 4, flip);
                ExSize[i]    = GT.ReadUInt32(fs, 4, flip);
                ExUnknown[i] = GT.ReadUInt32(fs, 4, flip);
                ExType[i]    = GT.ReadByte(fs);
            }

            for (int i = 0; i < count; i++)
            {
                string ext = "bin";
                if (ExType[i] == 0x00)
                {
                    ext = "wav";
                }
                else if (ExType[i] == 0x02)
                {
                    ext = "ogg";
                }

                if (!File.Exists(newDir + "\\" + i + "." + ext))
                {
                    string newfile = newDir + "\\" + i + "." + ext;
                    GT.WriteSubFile(fs, newfile, ExSize[i], ExOffset[i]);
                }
            }
        }
Пример #13
0
        public TexturePS2(string f, string sf, GTFS fs, bool useGTFSView = false)
        {
            file         = f;
            safefilename = sf;

            //--

            bool flip = false;

            fs.Position = 0;
            int magic   = GT.ReadInt32(fs, 4, flip);
            int unknown = GT.ReadInt32(fs, 4, flip);

            width  = GT.ReadInt32(fs, 4, flip);
            height = GT.ReadInt32(fs, 4, flip);
            long apal  = fs.Position;
            long atex  = 0x410;
            int  HALFX = width / 2;
            int  HALFY = height / 2;
            int  TLONG = width * height + 1372;
            int  XY    = width * height;

            // Color Palette = RGBA8888
            fs.Position = apal;
            Color[] palette = new Color[256];
            for (int p = 0; p < 256; p++)
            {
                byte r = GT.ReadByte(fs);
                byte g = GT.ReadByte(fs);
                byte b = GT.ReadByte(fs);
                byte a = GT.ReadByte(fs); // Max is 127, is it alpha?
                //a = 255;

                //Console.WriteLine(r + " " + g + " " + b + " " + a);
                palette[p] = Color.FromArgb(a * 2, r, g, b);
            }

            fs.Position = atex;
            bitmap      = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    byte pix = GT.ReadByte(fs);
                    bitmap.SetPixel(x, y, palette[pix]);
                }
            }
        }
Пример #14
0
        public override void Open(OpenFileDialog openFileDialog, bool export = false, bool useGTFSView = false)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "All PS2|*.pak;*.raw|"
                                      + "PS2 Raw|*.raw|"
                                      + "Pak|*.pak|"
                                      + "All Files (*.*)|*.*";

            DialogResult res = openFileDialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                string[] filenameParts = openFileDialog.SafeFileName.Split('.');
                Array.Reverse(filenameParts);

                if (filenameParts[0].ToUpper() == "PAK")
                {
                    List <string> files = Pak.Open(openFileDialog.FileName, openFileDialog.SafeFileName);
                    FormGameTools2.ListFiles(files);
                }
                else if (filenameParts[0].ToUpper() == "RAW")
                {
                    GTFS   fs      = new GTFS(openFileDialog.FileName);
                    byte[] bHeader = GT.ReadBytes(fs, 4, false);

                    if ((bHeader[0] == 0x10 && bHeader[1] == 0x00 && bHeader[2] == 0x00 && bHeader[3] == 0x00) || //PS2 object
                        (bHeader[0] == 0x20 && bHeader[1] == 0x00 && bHeader[2] == 0x00 && bHeader[3] == 0x00))   //PS2 level
                    {
                        ModelPS2 model = new ModelPS2(openFileDialog.FileName, openFileDialog.SafeFileName, useGTFSView);
                        FormGameTools2.UseViewer(model);
                    }
                    else if ((bHeader[0] == 0x01 && bHeader[1] == 0x00 && bHeader[2] == 0x00 && bHeader[3] == 0x00) ||
                             (bHeader[0] == 0x03 && bHeader[1] == 0x00 && bHeader[2] == 0x00 && bHeader[3] == 0x00))
                    {
                        TexturePS2 texture = new TexturePS2(openFileDialog.FileName, openFileDialog.SafeFileName, useGTFSView);
                        new GameTools3D.FormTextureView(texture).Show();
                    }
                    else
                    {
                        MessageBox.Show("Unknown header (hex): " + GT.ByteArrayToString(bHeader, " "));
                    }
                }
                else
                {
                    MessageBox.Show("Unexpected file extension: " + filenameParts[0]);
                }
            }
        }
Пример #15
0
        private List <long> ReadOffsetsToPos(GTFS fs, int maxpos, bool flip)
        {
            List <long> listOffsets = new List <long>();

            while (fs.Position < maxpos)
            {
                int off = GT.ReadInt32(fs, 4, flip);

                if (off > 0 && !listOffsets.Contains(off))
                {
                    listOffsets.Add(off);
                }
            }

            return(listOffsets);
        }
Пример #16
0
        public static void OpenANM(OpenFileDialog openFileDialog)
        {
            bool flip = false;
            GTFS fs   = new GTFS(openFileDialog.FileName);

            uint unk1               = GT.ReadUInt32(fs, 4, flip);
            uint numFrames          = GT.ReadUInt32(fs, 4, flip);
            uint numFramesHeaderLen = GT.ReadUInt32(fs, 4, flip);
            uint unk2               = GT.ReadUInt32(fs, 4, flip);

            ushort height = GT.ReadUInt16(fs, 2, flip); //<<<--------- WRONG FROM HERE
            ushort width  = GT.ReadUInt16(fs, 2, flip);
            uint   unk3   = GT.ReadUInt32(fs, 4, flip);
            uint   unk4   = GT.ReadUInt32(fs, 4, flip);
            uint   unk5   = GT.ReadUInt32(fs, 4, flip);

            List <Pack> listFrames = new List <Pack>();

            for (int i = 0; i < numFrames; i++)
            {
                uint frameOffset = GT.ReadUInt32(fs, 4, flip);
                uint frameLen    = GT.ReadUInt32(fs, 4, flip);
                uint frameUnk    = GT.ReadUInt32(fs, 4, flip);
                uint framePad    = GT.ReadUInt32(fs, 4, flip);

                string name = "Frame " + i + ".frm";
                listFrames.Add(new Pack(name, frameOffset, frameLen));
            }

            string toFolder = openFileDialog.SafeFileName.Replace('.', '_');

            if (!Directory.Exists(extract_path))
            {
                Directory.CreateDirectory(extract_path);
            }

            if (!Directory.Exists(extract_path + "\\" + toFolder))
            {
                Directory.CreateDirectory(extract_path + "\\" + toFolder);
            }

            foreach (Pack frame in listFrames)
            {
                string newfile = extract_path + "\\" + toFolder + "\\" + frame.Filename;
                GT.WriteSubFile(fs, newfile, frame.Size, frame.Offset);
            }
        }
Пример #17
0
        public static void Open(OpenFileDialog openFileDialog)
        {
            bool flip = false;
            GTFS fs   = new GTFS(openFileDialog.FileName);

            List <Pack> listPack = new List <Pack>();

            while (fs.Position < fs.Length - 40)
            {
                byte[] nameArray = new byte[24];
                for (int k = 0; k < 24; k++)
                {
                    nameArray[k] = (byte)fs.ReadByte();
                }

                long fileLen        = GT.ReadUInt32(fs, 4, flip);
                long nextFileOffset = GT.ReadUInt32(fs, 4, flip);
                long currentOffset  = fs.Position;

                string name = Encoding.Default.GetString(nameArray);
                name = name.Substring(1).Replace("\0", "").Replace(".bin", ".wpfbin");

                listPack.Add(new Pack(name, currentOffset, fileLen));

                fs.Seek(nextFileOffset, SeekOrigin.Begin);
            }

            string toFolder = openFileDialog.SafeFileName.Replace('.', '_');

            if (!Directory.Exists(extract_path))
            {
                Directory.CreateDirectory(extract_path);
            }

            if (!Directory.Exists(extract_path + "\\" + toFolder))
            {
                Directory.CreateDirectory(extract_path + "\\" + toFolder);
            }

            foreach (Pack pack in listPack)
            {
                string newfile = extract_path + "\\" + toFolder + "\\" + pack.Filename;
                GT.WriteSubFile(fs, newfile, pack.Size, pack.Offset);
            }
        }
Пример #18
0
        public override void Open(OpenFileDialog openFileDialog, bool export = false, bool useGTFSView = false)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "All Files (*.*)|*.*";

            DialogResult res = openFileDialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                string filePal = openFileDialog.FileName.Replace(openFileDialog.SafeFileName, "") + "..\\sprite.pal";
                GTFS   fsPal   = new GTFS(filePal);

                List <Color> listPal = new List <Color>();
                while (fsPal.Position < fsPal.Length - 1)
                {
                    int input = GT.ReadInt16(fsPal, 2, false);
                    listPal.Add(Colour.ABGR1555(input));
                }


                //-------

                GTFS fs = new GTFS(openFileDialog.FileName);

                List <RunawayPackedImage> listImage = new List <RunawayPackedImage>();
                while (fs.Position < fs.Length - 1)
                {
                    listImage.Add(new RunawayPackedImage(fs));
                }

                int maxFirst  = listImage.Max(x => x.derivedfirstadd);
                int maxSecond = listImage.Max(x => x.second);

                Bitmap bmp = new Bitmap(maxFirst, maxSecond + 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                foreach (RunawayPackedImage rpi in listImage)
                {
                    for (int i = 0; i < rpi.numValues; i++)
                    {
                        bmp.SetPixel(rpi.first + i, rpi.second, listPal[rpi.values[i]]);
                    }
                }

                new FormImage(bmp).Show();
            }
        }
Пример #19
0
        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            GTFS fs = new GTFS(@"D:\ExtractedGames\NDS_UNPACK_HDR215\data\data\system\note\notememoedit_wpf\eraser.bin");

            byte[] header       = GT.ReadBytes(fs, 4, false);
            int    uncompressed = GT.ReadInt32(fs, 4, false);
            int    compressed   = GT.ReadInt32(fs, 4, false);
            int    zero         = GT.ReadInt32(fs, 4, false);

            byte[] data = GT.ReadBytes(fs, compressed, false);

            byte[] undata = GBA.LZ77.Decompress(data, uncompressed);

            FileStream nf = new FileStream("TestPCXOut.bin", FileMode.Create);

            nf.Write(undata, 0, uncompressed);
            nf.Close();
        }
Пример #20
0
            public isodesc(GTFS fs, bool linux)
            {
                bool flip = false;

                if (linux)
                {
                    status = GT.ReadInt32(fs, 4, flip);
                    offset = GT.ReadInt32(fs, 4, flip);
                    length = GT.ReadInt32(fs, 4, flip);
                    int padding = GT.ReadInt32(fs, 4, flip);
                }
                else
                {
                    offset = GT.ReadInt32(fs, 4, flip);
                    length = GT.ReadInt32(fs, 4, flip);
                    status = GT.ReadInt32(fs, 4, flip);
                }
            }
Пример #21
0
 public Device(GTFS fs)
 {
     bool   flip                = false;
     string DevicePath          = GT.ReadASCII(fs, 256, flip);
     string DeviceBusID         = GT.ReadASCII(fs, 32, flip);
     int    busnum              = GT.ReadInt32(fs, 4, flip);
     int    devnum              = GT.ReadInt32(fs, 4, flip);
     int    speed               = GT.ReadInt32(fs, 4, flip);
     int    idVendor            = GT.ReadInt16(fs, 2, flip);
     int    idProduct           = GT.ReadInt16(fs, 2, flip);
     int    bcdDevice           = GT.ReadInt16(fs, 2, flip);
     int    bDeviceClass        = GT.ReadByte(fs);
     int    bDeviceSubClass     = GT.ReadByte(fs);
     int    bDeviceProtocol     = GT.ReadByte(fs);
     int    bConfigurationValue = GT.ReadByte(fs);
     int    bNumConfigurations  = GT.ReadByte(fs);
     int    bNumInterfaces      = GT.ReadByte(fs);
 }
Пример #22
0
        public static void Open(string file, string outdir) {
            bool flip = false;
            GTFS fs = new GTFS(file);

            string newDir = file.Replace('.', '-');//.Replace("\\uk", "");
            //if (newDir.Contains("uk"))
                //throw new Exception();

            uint head = GT.ReadUInt32(fs, 4, flip);

            string ext = "txt";
            if (head == 0x46464952) ext = "mp4"; //Android: RIFF
            else if (head == 0x694B4942) ext = "bik"; //Steam: BIKi

            if (!System.IO.File.Exists(newDir + "." + ext)) {
                //Copy the file under a new name
                System.IO.File.Copy(file, newDir + "." + ext);
            }
        }
Пример #23
0
        public MTC(GTFS fs)
        {
            mtcHeight = 33;
            mtcWidth  = 17;

            //--

            bool flip = false;

            numFrames    = GT.ReadInt32(fs, 4, flip);
            anmWidth     = GT.ReadInt16(fs, 2, flip);
            anmHeight    = GT.ReadInt16(fs, 2, flip);
            fs.Position += 24;

            listFrames = new List <MTCFrame>();
            for (int i = 0; i < numFrames; i++)
            {
                listFrames.Add(new MTCFrame(fs, mtcWidth, mtcHeight));
            }
        }
Пример #24
0
        private static GTFS Decompress(string file)
        {
            //First 4 bytes is uncompressed size
            //Next 2 bytes should be 78 9C

            GTFS fs = null;

            FileStream fsComp   = new FileStream(file, FileMode.Open);
            int        uncomLen = GT.ReadInt32(fsComp, 4, false);

            fsComp.Position += 2;
            using (DeflateStream decompressionStream = new DeflateStream(fsComp, CompressionMode.Decompress)) {
                byte[] raw = new byte[uncomLen];
                decompressionStream.Read(raw, 0, uncomLen);
                fs = new GTFS(raw);
            }
            fsComp.Close();

            return(fs);
        }
Пример #25
0
        public BPG(GTFS fs)
        {
            bool flip = false;

            byte[] magic      = GT.ReadBytes(fs, 4, flip); //BPG1
            int    paletteNum = GT.ReadInt16(fs, 2, flip);
            int    unknown2   = GT.ReadInt16(fs, 2, flip); //Should be 8 ?

            Width  = GT.ReadInt16(fs, 2, flip);
            Height = GT.ReadInt16(fs, 2, flip);
            int tileWidth  = GT.ReadInt16(fs, 2, flip);
            int tileHeight = GT.ReadInt16(fs, 2, flip);

            int numTilesX = Width / tileWidth;
            int numTilesY = Height / tileHeight;

            Color[] palette = new Color[paletteNum];
            for (int i = 0; i < paletteNum; i++)
            {
                byte left  = GT.ReadByte(fs);
                byte right = GT.ReadByte(fs);
                palette[i] = HotelDusk.FRM.Palette2Color(left, right);
            }

            bitmap = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            for (int y = 0; y < numTilesY; y++)
            {
                for (int x = 0; x < numTilesX; x++)
                {
                    for (int ty = 0; ty < tileHeight; ty++)
                    {
                        for (int tx = 0; tx < tileWidth; tx++)
                        {
                            byte lookup = GT.ReadByte(fs);
                            bitmap.SetPixel(x * tileWidth + tx, y * tileHeight + ty, palette[lookup]);
                        }
                    }
                }
            }
        }
Пример #26
0
        public TextureGCN(string f, string sf, GTFS fs, bool useGTFSView = false)
        {
            file         = f;
            safefilename = sf;

            //--

            bool flip = true;

            fs.Position = 0;
            int magic = GT.ReadInt32(fs, 4, flip);
            int stuff = GT.ReadInt32(fs, 4, flip);

            width  = GT.ReadInt32(fs, 4, flip);
            height = GT.ReadInt32(fs, 4, flip);
            int unknown = GT.ReadInt32(fs, 4, flip);
            int format  = GT.ReadInt32(fs, 4, flip);

            fs.Position = 0x20; //Only for Gamecube

            Color[][] blocks = DXT.ReadCMPR(fs, flip, width, height);

            bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            int bi = 0;

            for (int y = 0; y < height / 4; y++)
            {
                for (int x = 0; x < width / 4; x++)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        int row = i / 4;
                        int col = i - (row * 4);
                        bitmap.SetPixel(x * 4 + col, y * 4 + row, blocks[bi][i]);
                    }
                    bi++;
                }
            }
        }
Пример #27
0
        public LRIM(GTFS fs)
        {
            flip           = false;
            this.fs        = fs;
            FileName       = fs.FilePath;
            SafeFileName   = Path.GetFileName(FileName);
            listPackFrames = new List <Pack>();

            //--

            int magicheader = GT.ReadInt32(fs, 4, flip);
            int num         = GT.ReadInt32(fs, 4, flip);
            int sixteen     = GT.ReadInt32(fs, 4, flip);
            int unk1        = GT.ReadInt32(fs, 4, flip);

            int[] offset = new int[num];
            for (int i = 0; i < num; i++)
            {
                offset[i] = GT.ReadInt32(fs, 4, flip);
            }

            int[] size = new int[num];
            for (int i = 0; i < num; i++)
            {
                size[i] = GT.ReadInt32(fs, 4, flip);

                string name = "LRIM " + i + ".lrim";
                listPackFrames.Add(new Pack(name, offset[i], size[i]));
            }

            foreach (Pack pack in listPackFrames)
            {
                pack.WriteOut(fs, "GT-HD-LRIM-" + SafeFileName.Replace(".bin", ""));
            }

            Console.WriteLine("Offsets: " + string.Join(", ", offset));
            Console.WriteLine("Sizes: " + string.Join(", ", size));

            Console.WriteLine();
        }
Пример #28
0
        public YesterdayPackedImage(GTFS fs)
        {
            first         = GT.ReadInt16(fs, 2, false);
            second        = GT.ReadInt16(fs, 2, false);
            type          = GT.ReadByte(fs);
            numValuesBase = GT.ReadInt16(fs, 2, false);

            if (type == 4)
            {
                numValuesLen = numValuesBase;
                values       = new byte[numValuesLen];
            }
            else if (type == 6)
            {
                numValuesLen = numValuesBase * 3;
                values       = new byte[numValuesLen];
            }
            else if (type == 7)
            {
                numValuesLen = numValuesBase * 4;
                values       = new byte[numValuesLen];
            }
            else if (type == 8)
            {
                numValuesLen = 0;
                values       = new byte[numValuesLen];
            }
            else
            {
                throw new System.Exception();
            }

            derivedfirstadd      = first + numValuesBase;
            derivedfirstsubtract = first - numValuesBase;

            for (int i = 0; i < numValuesLen; i++)
            {
                values[i] = GT.ReadByte(fs);
            }
        }
Пример #29
0
        public static void OpenPack(OpenFileDialog openFileDialog)
        {
            bool flip = true;
            GTFS fs   = new GTFS(openFileDialog.FileName);

            uint nothing  = GT.ReadUInt32(fs, 4, flip);
            uint numFiles = GT.ReadUInt32(fs, 4, flip);
            uint offset   = GT.ReadUInt32(fs, 4, flip); // + 4 I guess?

            uint unknown = GT.ReadUInt32(fs, 4, flip);

            List <Pack> listPack = new List <Pack>();

            for (int i = 0; i < numFiles; i++)
            {
                byte   nameLen = GT.ReadByte(fs);
                string name    = GT.ReadASCII(fs, nameLen, false);
                int    fileLen = GT.ReadInt32(fs, 4, flip);

                listPack.Add(new Pack(name, -1, fileLen));
            }

            string toFolder = openFileDialog.SafeFileName.Replace('.', '_');

            if (!Directory.Exists(extract_path))
            {
                Directory.CreateDirectory(extract_path);
            }

            if (!Directory.Exists(extract_path + "\\" + toFolder))
            {
                Directory.CreateDirectory(extract_path + "\\" + toFolder);
            }

            foreach (Pack pack in listPack)
            {
                string newfile = extract_path + "\\" + toFolder + "\\" + pack.Filename;
                GT.WriteSubFile(fs, newfile, (int)pack.Size);
            }
        }
Пример #30
0
        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "";
            openFileDialog1.Filter   = "All Files (*.*)|*.*";
            DialogResult res = openFileDialog1.ShowDialog();

            if (res == DialogResult.OK)
            {
                listBox1.Items.Clear();

                string file = openFileDialog1.FileName;
                GTFS   fs   = new GTFS(file);
                fs.Position = Int32.Parse(txtSkipBytes.Text);

                int num = Int32.Parse(txtFor.Text);

                for (int i = 0; i < num; i++)
                {
                    int read = GT.ReadInt32(fs, 4, false);
                    listBox1.Items.Add(read);
                }
            }
        }