Exemple #1
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);
                }
            }
Exemple #2
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();
        }
Exemple #3
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();
        }
Exemple #4
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();
        }
        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);
            }
        }
Exemple #6
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]);
                }
            }
        }
Exemple #7
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]);
                }
            }
        }
Exemple #8
0
        public static List <string> Open(string file, string outdir)
        {
            GTFSSlow fs   = new GTFSSlow(file);
            bool     flip = false;

            Directory.CreateDirectory(outdir + "\\Dataa");
            Directory.CreateDirectory(outdir + "\\Datav");
            Directory.CreateDirectory(outdir + "\\Resource");

            uint        numFiles = GT.ReadUInt32(fs, 4, flip);
            List <Pack> obb      = new List <Pack>();

            for (int i = 0; i < numFiles; i++)
            {
                uint inNameLen = GT.ReadUInt32(fs, 4, flip);

                string inName = string.Empty;
                for (int k = 0; k < inNameLen; k++)
                {
                    inName += (char)GT.ReadByte(fs);
                }

                string dest = "Resource\\";
                if (inName[0] == 'V')
                {
                    dest = "Datav\\";
                }
                else if (inName[0] == 'D')
                {
                    dest = "Dataa\\";
                }

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

                obb.Add(new Pack(dest + inName, inStart, inLen));
            }

            List <string> listFiles = new List <string>();

            foreach (Pack pf in obb)
            {
                pf.WriteOut(fs, outdir);
                listFiles.Add(pf.Filename);
            }
            return(listFiles);
        }
Exemple #9
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);
 }
Exemple #10
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]);
                        }
                    }
                }
            }
        }
Exemple #11
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);
            }
        }
        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);
            }
        }
Exemple #13
0
        //https://www.gamefaqs.com/ds/933043-hotel-dusk-room-215/faqs/46878?print=1

        public static GTFS ToGTFS(GTFS fs)
        {
            fs.Position = 0;

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

            byte[] uncompressed = new byte[sizeun];
            byte[] expanded     = new byte[sizeun]; // i.e. doesn't fill in the gaps
            int    pos          = 0;

            byte boff1max = 0x62;

            while (fs.Position < sizeco + 16)
            {
                byte     input = GT.ReadByte(fs);
                BitArray bits  = new BitArray(new byte[] { input });

                for (int i = 0; i < 8; i++)
                {
                    if (fs.Position >= sizeco + 16)
                    {
                        break;
                    }

                    if (bits[i])
                    {
                        byte b = GT.ReadByte(fs);
                        uncompressed[pos] = b;
                        expanded[pos]     = b;
                        pos++;
                    }
                    else
                    {
                        int offsetSIGNED = GT.ReadInt16(fs, 2, false);
                        fs.Position -= 2;
                        int offset = GT.ReadUInt16(fs, 2, false);
                        fs.Position -= 2;
                        byte[] bOff = GT.ReadBytes(fs, 2, false);

                        int len = 4 + GT.ReadByte(fs);

                        /*
                         * //START DEBUG
                         * uncompressed[pos + 0] = bOff[0];
                         * uncompressed[pos + 1] = bOff[1];
                         * uncompressed[pos + 2] = (byte)(len - 4);
                         *
                         * for(int g = 3; g < len; g++) {
                         *  uncompressed[pos + g] = 0xF5;
                         * }
                         * //END DEBUG
                         */

                        /*if (bOff[1] == 0xFE || bOff[1] == 0xFF) {
                         *  Console.WriteLine("0 Problem " + GT.ByteArrayToString(bOff, " ") + " (Signed: " + offsetSIGNED + ") at " + pos + " (for len: " + len + ")");
                         * } else {*/
                        if (pos >= 196608)
                        {
                            // Shouldn't happen
                            throw new Exception();
                        }

                        if (pos >= 131072 && bOff[1] <= boff1max)
                        {
                            offsetSIGNED += 131072 + 259;
                            if (offsetSIGNED >= 0 && offsetSIGNED < pos)
                            {
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = uncompressed[offsetSIGNED + x];
                                }
                            }
                            else
                            {
                                Console.WriteLine("1 Problem " + GT.ByteArrayToString(bOff, " ") + " (Signed: " + offsetSIGNED + ") at " + pos + " (for len: " + len + ")");
                                //throw new Exception();
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = 0x00;
                                }
                            }
                        }
                        else if (pos >= 65536 && bOff[1] <= boff1max)
                        {
                            if (offsetSIGNED < 0)
                            {
                                offsetSIGNED = (bOff[1] << 8) + bOff[0] + 259;
                            }
                            else
                            {
                                offsetSIGNED += 65536;
                            }

                            if (offsetSIGNED >= 0 && offsetSIGNED < pos)
                            {
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = uncompressed[offsetSIGNED + x];
                                }
                            } //else
                              //throw new Exception();
                        }
                        else
                        {
                            offset += 259;

                            if (bOff[1] == 0xFF)
                            {
                                //Can't use offsetSIGNED
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = uncompressed[offset + x];
                                }
                            }
                            else
                            {
                                if (offsetSIGNED + 259 >= 0 && offsetSIGNED + 259 < pos)
                                {
                                    offsetSIGNED += 259;
                                    for (int x = 0; x < len; x++)
                                    {
                                        uncompressed[pos + x] = uncompressed[offsetSIGNED + x];
                                    }
                                }
                                else if (offset > pos)
                                {
                                    Console.WriteLine("3 Problem " + GT.ByteArrayToString(bOff, " ") + " (Signed: " + offsetSIGNED + ") at " + pos + " (for len: " + len + ")");
                                }
                                else if (offset >= sizeun)
                                {
                                    uncompressed[pos + 0] = bOff[0];
                                    uncompressed[pos + 1] = bOff[1];
                                    uncompressed[pos + 2] = (byte)(len - 4);

                                    for (int g = 3; g < len; g++)
                                    {
                                        uncompressed[pos + g] = 0xF5;
                                    }
                                }
                                else
                                {
                                    for (int x = 0; x < len; x++)
                                    {
                                        uncompressed[pos + x] = uncompressed[offset + x];
                                    }
                                }
                            }
                        }

                        #region Expanded
                        expanded[pos + 0] = bOff[0];
                        expanded[pos + 1] = bOff[1];
                        expanded[pos + 2] = (byte)(len - 4);

                        for (int g = 3; g < len; g++)
                        {
                            expanded[pos + g] = 0x00;
                        }
                        #endregion

                        pos += len;
                    }
                }
            }

            new FormHexCompare(expanded, uncompressed).Show();

            return(new GTFS(uncompressed));
        }
Exemple #14
0
        public static object Get(GTFS fs)
        {
            bool flip   = true;
            int  first  = GT.ReadUInt16(fs, 2, flip);
            int  second = GT.ReadUInt16(fs, 2, flip);

            if (second == 32773)
            {
                OP_REQ_DEVLIST op     = new OP_REQ_DEVLIST();
                int            status = GT.ReadInt32(fs, 4, flip);

                return(op);
            }
            else if (second == 5)
            {
                OP_REP_DEVLIST op        = new OP_REP_DEVLIST();
                int            status    = GT.ReadInt32(fs, 4, flip);
                int            NumExport = GT.ReadInt32(fs, 4, flip);

                Device dev = new Device(fs);
                for (int i = 0; i < 1; i++)   //dev.bNumInterfaces
                {
                    byte bInterfaceClass    = GT.ReadByte(fs);
                    byte bInterfaceSubClass = GT.ReadByte(fs);
                    byte bInterfaceProtocol = GT.ReadByte(fs);
                    byte padding            = GT.ReadByte(fs);
                }

                return(op);
            }
            else if (second == 32771)
            {
                OP_REQ_IMPORT op     = new OP_REQ_IMPORT();
                int           status = GT.ReadInt32(fs, 4, flip);
                string        busid  = GT.ReadASCII(fs, 32, flip);
                return(op);
            }
            else if (second == 3)
            {
                OP_REP_IMPORT op     = new OP_REP_IMPORT();
                int           status = GT.ReadInt32(fs, 4, flip);
                Device        dev    = new Device(fs);
                return(op);
            }
            else if (second == 1)
            {
                USBIP_CMD_SUBMIT op           = new USBIP_CMD_SUBMIT();
                int    seqnum                 = GT.ReadInt32(fs, 4, flip);
                int    devid                  = GT.ReadInt32(fs, 4, flip);
                int    direction              = GT.ReadInt32(fs, 4, flip);
                int    ep                     = GT.ReadInt32(fs, 4, flip);
                byte[] transfer_flags         = GT.ReadBytes(fs, 4, flip);
                byte[] transfer_buffer_length = GT.ReadBytes(fs, 4, flip);
                byte[] start_frame            = GT.ReadBytes(fs, 4, flip);
                int    number_of_packets      = GT.ReadInt32(fs, 4, flip);
                int    interval               = GT.ReadInt32(fs, 4, flip);

                //URB Setup
                byte bmRequestType = GT.ReadByte(fs);
                byte bRequest      = GT.ReadByte(fs);
                int  wValue        = GT.ReadUInt16(fs, 2, false);
                int  wIndex        = GT.ReadUInt16(fs, 2, false);
                int  wLength       = GT.ReadUInt16(fs, 2, false);

                byte[] _remainingURB;
                if (fs.Position < fs.Length)
                {
                    _remainingURB = GT.ReadBytes(fs, (int)(fs.Length - fs.Position), flip);
                }

                return(op);
            }
            else if (second == 3)
            {
                USBIP_RET_SUBMIT op      = new USBIP_RET_SUBMIT();
                int    seqnum            = GT.ReadInt32(fs, 4, flip);
                int    devid             = GT.ReadInt32(fs, 4, flip);
                int    direction         = GT.ReadInt32(fs, 4, flip);
                int    ep                = GT.ReadInt32(fs, 4, flip);
                int    status            = GT.ReadInt32(fs, 4, flip);
                int    actual_length     = GT.ReadInt32(fs, 4, flip);
                byte[] start_frame       = GT.ReadBytes(fs, 4, flip);
                int    number_of_packets = GT.ReadInt32(fs, 4, flip);
                int    error_count       = GT.ReadInt32(fs, 4, flip);
                byte[] setup             = GT.ReadBytes(fs, 8, flip);
                byte[] _data             = GT.ReadBytes(fs, actual_length, flip);

                return(op);
            }

            return(null);
        }
Exemple #15
0
        public EBP(GTFS fs)
        {
            bool flip = false;

            Width  = GT.ReadInt32(fs, 4, flip);
            Height = GT.ReadInt32(fs, 4, flip);
            int flag = GT.ReadInt32(fs, 4, flip);

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

            if (flag == 4)
            {
                //Unsure
                int numPal = 16;
                palette = new Color[numPal];
                for (int i = 0; i < numPal; i++)
                {
                    byte left  = GT.ReadByte(fs);
                    byte right = GT.ReadByte(fs);
                    palette[i++] = HotelDusk.FRM.Palette2Color(left, left);
                    palette[i]   = HotelDusk.FRM.Palette2Color(right, right);
                }

                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        byte two   = GT.ReadByte(fs);
                        byte left  = (byte)(two >> 4);
                        byte right = (byte)(two & 0xF);

                        bitmap.SetPixel(x++, y, palette[left]);
                        bitmap.SetPixel(x, y, palette[right]);
                    }
                }
            }
            else if (flag == 8)
            {
                //BGRA8888
                int numPal = 256;
                palette = new Color[numPal];
                for (int i = 0; i < numPal; i++)
                {
                    byte red   = GT.ReadByte(fs);
                    byte green = GT.ReadByte(fs);
                    byte blue  = GT.ReadByte(fs);
                    byte alpha = GT.ReadByte(fs);
                    palette[i] = Color.FromArgb(255 - alpha, red, green, blue);
                }

                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        byte lookup = GT.ReadByte(fs);
                        bitmap.SetPixel(x, y, palette[lookup]);
                    }
                }
            }
            else if (flag == 53)
            {
                //RBGA1555
                int numPal = 32;
                palette = new Color[numPal];
                for (int i = 0; i < numPal; i++)
                {
                    byte left  = GT.ReadByte(fs);
                    byte right = GT.ReadByte(fs);
                    palette[i] = HotelDusk.FRM.Palette2Color(left, right);
                }

                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        byte lookup = GT.ReadByte(fs);
                        if (lookup >= numPal)
                        {
                            lookup = (byte)(numPal - 1);
                        }
                        bitmap.SetPixel(x, y, palette[lookup]);
                    }
                }
            }
            else if (flag == 17476)
            {
                //RGBA1555
                int palLen   = GT.ReadInt32(fs, 4, flip);
                int imgSmall = GT.ReadInt32(fs, 4, flip);
                int imgLarge = GT.ReadInt32(fs, 4, flip);

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

                //This doesn't seem to be working at all, compression or the width/height are wrong?

                //First image should be the largest
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        byte lookup = GT.ReadByte(fs);
                        bitmap.SetPixel(x, y, palette[lookup]);
                    }
                }

                //Ignore the last image?
            }
            else
            {
                throw new Exception();
            }
        }
Exemple #16
0
        public ModelPS2Old(string filename) : base()
        {
            FileName = filename;
            fsMem1   = new List <byte>();  //Type5 - Joins
            fsMem2   = new List <float>(); //X,Y,Z - Vertexes
            fsMem3   = new List <long>();  //Faces
            fsMem4   = new List <float>();

            //--

            bool flip = false;
            GTFS fs0  = new GTFS(FileName);

            int iHeader = GT.ReadInt32(fs0, 4, flip);
            int _base   = GT.ReadInt32(fs0, 4, flip);

            fs0.Position = _base;
            int meshnumber = GT.ReadInt16(fs0, 2, flip);

            //Meshes = new Mesh3D[meshnumber];

            StringBuilder csv = new StringBuilder();

            for (int mesh = 1; mesh <= meshnumber; mesh++)
            {
                //Meshes[mesh] = new Mesh3D(mesh);
                //textBox1.AppendText("Mesh " + mesh + "\r\n");
                long wolf = _base + (-144 * mesh);

                fs0.Position = wolf + 96; //98
                int numvertex = GT.ReadInt16(fs0, 2, flip);
                //The value at +98 might happen to be numfaces/2 ?

                fs0.Position = wolf + 40;
                int tovertexes = GT.ReadInt32(fs0, 4, flip);

                fs0.Position = tovertexes;
                for (int v = 0; v < numvertex; v++)
                {
                    float Type1 = GT.ReadFloat(fs0, 4, flip); //fVX
                    float Type2 = GT.ReadFloat(fs0, 4, flip); //fVY
                    float Type3 = GT.ReadFloat(fs0, 4, flip); //fVZ
                    byte  Type4 = GT.ReadByte(fs0);           //fVC
                    byte  Type5 = GT.ReadByte(fs0);
                    byte  Type6 = GT.ReadByte(fs0);
                    byte  Type7 = GT.ReadByte(fs0);

                    fsMem2.Add(Type1);
                    fsMem2.Add(Type2);
                    fsMem2.Add(Type3);

                    fsMem1.Add(Type5);

                    //csv.AppendLine(Type1 + "," + Type2 + "," + Type3);

                    //Meshes[mesh].Points.Add(new Point3D(fVX, fVY, fVZ, fVC));
                    //textBox1.AppendText(fVX + "," + fVY + "," + fVZ + "," + fVC + "\r\n");
                }
                // The stuff after the verticies
                for (int v = 0; v < numvertex; v++)
                {
                    float Type1 = GT.ReadFloat(fs0, 4, flip);
                    float Type2 = GT.ReadFloat(fs0, 4, flip);
                    float Type3 = GT.ReadFloat(fs0, 4, flip);

                    fsMem4.Add(Type1);
                    fsMem4.Add(Type2);
                    fsMem4.Add(Type3);

                    csv.AppendLine(Type1 + "," + Type2 + "," + Type3);
                }

                //textBox1.AppendText("\r\n");
            }

            //foreach(Mesh3D mesh in Meshes) { checklistMeshes.Items.Add("Mesh " + mesh.ID, true); }

            for (int FFF = 2; FFF < fsMem1.Count; FFF++)
            {
                byte cool1 = fsMem1[FFF - 2];
                byte cool2 = fsMem1[FFF - 1];
                byte cool3 = fsMem1[FFF];

                if (cool3 != 128)
                {
                    fsMem3.Add((short)(FFF - 2));
                    fsMem3.Add((short)(FFF - 1));
                    fsMem3.Add((short)(FFF));
                    fsMem3.Add((short)(0));
                    fsMem3.Add((short)(FFF - 1));
                    fsMem3.Add((short)(FFF - 2));
                    fsMem3.Add((short)(FFF));
                    fsMem3.Add((short)(0));
                }
            }

            if (File.Exists("test.csv"))
            {
                File.Delete("test.csv");
            }
            File.WriteAllText("test.csv", csv.ToString());
        }
        static void Main(string[] args)
        {
            bool flip      = false;
            GTFS fs        = new GTFS("Kaban3-F0.frm"); //Kaban3-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);

            byte previousQ     = 0;
            int  previousAbove = 0;

            List <int[]> idea = new List <int[]>();

            idea.Add(Enumerable.Repeat(0xFF, 127).ToArray());

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

                if (b < 0x80)
                {
                    if (previousAbove > 0)
                    {
                        //Console.WriteLine();
                        Console.Write("= " + previousAbove.ToString().PadLeft(3, ' '));
                        if (previousQ == previousAbove)
                        {
                            Console.Write(" *");
                        }

                        previousAbove = 0;
                        idea.Add(Enumerable.Repeat(0xFF, 127).ToArray());
                    }

                    previousQ = b;

                    //Console.WriteLine();
                    Console.Write("\r\n" + b.ToString().PadLeft(5, ' ') + " ( " + Convert.ToString(b, 2).PadLeft(8, '0') + " ) ");
                    //Console.WriteLine();
                }
                else
                {
                    idea.Last()[previousAbove] = b;

                    previousAbove++;
                    Console.Write(b.ToString("X2") + ", ");
                }
            }
            Console.Write("= " + previousAbove.ToString().PadLeft(3, ' ') + " (last)");

            Console.WriteLine("\r\n");

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

            foreach (int[] line in idea)
            {
                for (int i = 0; i < line.Length; i++)
                {
                    nf.WriteByte((byte)line[i]);
                }
            }
            nf.Close();
        }
Exemple #18
0
            public URBWindows(GTFS fs, int remlen = 0)
            {
                bool flip = false;

                //URB
                int USBPcap_pseudoheader_length = GT.ReadUInt16(fs, 2, flip);

                id = GT.ReadBytes(fs, 8, flip); //ulong
                int  IRPstatus   = GT.ReadInt32(fs, 4, flip);
                int  URBfunction = GT.ReadInt16(fs, 2, flip);
                byte IRPinfo     = GT.ReadByte(fs);

                bus_id          = GT.ReadUInt16(fs, 2, flip);
                device_address  = GT.ReadInt16(fs, 2, flip);
                endpoint_number = GT.ReadByte(fs);
                transfer_type   = (TransferType)GT.ReadByte(fs);
                data_len        = urb_len = GT.ReadUInt32(fs, 4, flip);
                remlen         -= 27;

                if (transfer_type == TransferType.Control)
                {
                    byte stage = GT.ReadByte(fs);
                    remlen -= 1;
                    if (urb_len == 8)
                    {
                        //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;
                    }
                    else
                    {
                        remaining = GT.ReadBytes(fs, remlen, flip);
                    }
                }
                else if (transfer_type == TransferType.Isochronous)
                {
                    int iso_start = GT.ReadInt32(fs, 4, flip);
                    numISOdesc = GT.ReadInt32(fs, 4, flip);
                    int iso_error = GT.ReadInt32(fs, 4, flip);
                    remlen -= 12;

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

                        remlen   -= numISOdesc * 12;
                        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);
                }
            }
Exemple #19
0
        static void Main(string[] args)
        {
            GTFS fs = new GTFS("AC_01L.bin");

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

            byte[] uncompressed = new byte[sizeun];
            int    pos          = 0;

            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[pos++] = 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]);

                            if (offset >= 0)
                            {
                                Array.Copy(uncompressed, offset, uncompressed, pos, len);
                            }
                            else
                            {
                                for (int x = 0; x < len; x++)
                                {
                                    uncompressed[pos + x] = 0x00; // This is wrong
                                }
                            }

                            pos += len;
                        }
                        else
                        {
                            if (lookup[1] < 127)
                            {
                                offset += 256 * (lookup[1] + 1);
                            }
                            else if (lookup[1] != 255)
                            {
                                throw new Exception();
                            }

                            Array.Copy(uncompressed, offset, uncompressed, pos, len);
                            pos += len;
                        }
                    }
                }
            }

            File.WriteAllBytes("HotelDuskDecompress.Test.bin", uncompressed);
        }
Exemple #20
0
        private void Form1_Load(object sender, EventArgs e)
        {
            bool flip = false;
            GTFS fs   = new GTFS("bed.3ds");

            while (fs.Position < fs.Length)
            {
                uint id   = GT.ReadUInt16(fs, 2, flip);
                uint next = GT.ReadUInt32(fs, 4, flip);

                if (id == 0x4D4D)
                {
                    Console.WriteLine("Main Chunk");
                    uint fileSize = next;
                }
                else if (id == 0x0002)
                {
                    Console.WriteLine("M3D Version / 3DS-Version");
                    int version = GT.ReadInt32(fs, 4, flip);
                }
                else if (id == 0x3D33)
                {
                    Console.WriteLine("Unknown");
                    fs.Position += next;
                }
                else if (id == 0x3D3D)
                {
                    Console.WriteLine("3D Editor Chunk");
                }
                else if (id == 0x3D3E)
                {
                    int version = GT.ReadInt32(fs, 4, flip);
                    Console.WriteLine("Mesh version");
                }
                else if (id == 0x4000)
                {
                    Console.WriteLine("Object Block");
                    string name = GT.ReadASCIItoNull(fs, fs.Position, flip);
                    fs.Position += name.Length + 1;
                }
                else if (id == 0x4100)
                {
                    Console.WriteLine("Triangular mesh");
                }
                else if (id == 0x4110)
                {
                    Console.WriteLine("Vertices List");
                    int vertexnumber = GT.ReadInt16(fs, 2, flip);
                    for (int i = 0; i < vertexnumber; i++)
                    {
                        float v1 = GT.ReadFloat(fs, 4, flip);
                        float v2 = GT.ReadFloat(fs, 4, flip);
                        float v3 = GT.ReadFloat(fs, 4, flip);
                    }
                }
                else if (id == 0x4120)
                {
                    Console.WriteLine("Faces description");
                    int facenumber = GT.ReadInt16(fs, 2, flip);
                    for (int i = 0; i < facenumber; i++)
                    {
                        int vA       = GT.ReadInt16(fs, 2, flip);
                        int vB       = GT.ReadInt16(fs, 2, flip);
                        int vC       = GT.ReadInt16(fs, 2, flip);
                        int faceFlag = GT.ReadInt16(fs, 2, flip);
                    }
                }
                else if (id == 0x4130)
                {
                    Console.WriteLine("Faces material list");
                    string name = GT.ReadASCIItoNull(fs, fs.Position, flip);
                    fs.Position += name.Length + 1;
                    int entries = GT.ReadInt16(fs, 2, flip);
                    for (int i = 0; i < entries; i++)
                    {
                        int face = GT.ReadInt16(fs, 2, flip);
                    }
                }
                else if (id == 0x4140)
                {
                    Console.WriteLine("Mapping coordinates list for each vertex");
                    int vertnum = GT.ReadInt16(fs, 2, flip);
                    for (int i = 0; i < vertnum; i++)
                    {
                        float uC = GT.ReadFloat(fs, 4, flip);
                        float vC = GT.ReadFloat(fs, 4, flip);
                    }
                }
                else if (id == 0x4150)
                {
                    Console.WriteLine("Smoothing groups list");
                    //List of Int, one per face
                    uint _numOfFaces = (next - 4) / 4;
                    for (uint i = 0; i < _numOfFaces; i++)
                    {
                        int s = GT.ReadInt32(fs, 4, flip);
                    }
                }
                else if (id == 0x4160)
                {
                    Console.WriteLine("Local coordinate system");
                    float x1x = GT.ReadFloat(fs, 4, flip);
                    float x1y = GT.ReadFloat(fs, 4, flip);
                    float x1z = GT.ReadFloat(fs, 4, flip);

                    float x2x = GT.ReadFloat(fs, 4, flip);
                    float x2y = GT.ReadFloat(fs, 4, flip);
                    float x2z = GT.ReadFloat(fs, 4, flip);

                    float x3x = GT.ReadFloat(fs, 4, flip);
                    float x3y = GT.ReadFloat(fs, 4, flip);
                    float x3z = GT.ReadFloat(fs, 4, flip);

                    float ox = GT.ReadFloat(fs, 4, flip);
                    float oy = GT.ReadFloat(fs, 4, flip);
                    float oz = GT.ReadFloat(fs, 4, flip);
                }
                else if (id == 0xAFFF)
                {
                    Console.WriteLine("Material editor chunk");
                }
                else if (id == 0xA000)
                {
                    Console.WriteLine("Material name");
                    string name = GT.ReadASCIItoNull(fs, fs.Position, flip);
                    Console.WriteLine("> " + name);
                    fs.Position += name.Length + 1;
                }
                else if (id == 0xA010)
                {
                    Console.WriteLine("Material ambient color");
                }
                else if (id == 0xA020)
                {
                    Console.WriteLine("Diffuse color");
                }
                else if (id == 0xA030)
                {
                    Console.WriteLine("Material specular color");
                }
                else if (id == 0xA040)
                {
                    Console.WriteLine("Material shininess percent");
                }
                else if (id == 0xA041)
                {
                    Console.WriteLine("Material shininess strength percent");
                }
                else if (id == 0xA050)
                {
                    Console.WriteLine("Transparency percent");
                }
                else if (id == 0xA052)
                {
                    Console.WriteLine("Transparency falloff percent");
                }
                else if (id == 0xA053)
                {
                    Console.WriteLine("Reflection blur percent");
                }
                else if (id == 0xA084)
                {
                    Console.WriteLine("Self Illumination");
                    uint u1 = GT.ReadUInt32(fs, 4, flip);
                    uint u2 = GT.ReadUInt32(fs, 4, flip);
                }
                else if (id == 0xA087)
                {
                    Console.WriteLine("Wire thickness");
                    float wire = GT.ReadFloat(fs, 4, flip);
                }
                else if (id == 0xA08A)
                {
                    Console.WriteLine("In tranc / Transparency fall off IN");
                }
                else if (id == 0xA100)
                {
                    Console.WriteLine("Render type");
                    uint type = GT.ReadUInt16(fs, 2, flip);
                    //Unsigned Short [1=flat 2=gour. 3=phong 4=metal]
                }
                else if (id == 0xA200)
                {
                    Console.WriteLine("Texture map 1");
                    uint u1 = GT.ReadUInt32(fs, 4, flip);
                    uint u2 = GT.ReadUInt32(fs, 4, flip);
                }
                else if (id == 0xA300)
                {
                    Console.WriteLine("Mapping filename");
                    string name = GT.ReadASCIItoNull(fs, fs.Position, flip);
                    Console.WriteLine("> " + name);
                    fs.Position += name.Length + 1;
                }
                else if (id == 0xA351)
                {
                    Console.WriteLine("Mapping parameters");
                    uint u1 = GT.ReadUInt16(fs, 2, flip);
                }
                else if (id == 0xA353)
                {
                    Console.WriteLine("Mapping parameters");
                    uint u1 = GT.ReadUInt32(fs, 4, flip);
                }
                else if (id == 0xA354)
                {
                    Console.WriteLine("V scale");
                    float vS = GT.ReadFloat(fs, 4, flip);
                }
                else if (id == 0xA356)
                {
                    Console.WriteLine("U scale");
                    float uS = GT.ReadFloat(fs, 4, flip);
                }
                else if (id == 0xB000)
                {
                    Console.WriteLine("Keyframer chunk");
                    fs.Position += next - 4;
                }
                else if (id == 0x0011)
                {
                    Console.WriteLine("byte RGB");
                    byte r = GT.ReadByte(fs);
                    byte g = GT.ReadByte(fs);
                    byte b = GT.ReadByte(fs);
                }
                else if (id == 0x0030)
                {
                    Console.WriteLine("percent (int format)");
                    uint percent = GT.ReadUInt16(fs, 2, flip);
                }
                else if (id == 0x0100)
                {
                    Console.WriteLine("One unit");
                    float f = GT.ReadFloat(fs, 4, flip);
                }
                else
                {
                    long pos = fs.Position;
                    uint idd = id;
                    Console.WriteLine();
                }
            }
        }
Exemple #21
0
        public FRM(GTFS fs)
        {
            Width  = 192;
            Height = 256;

            //--

            bool flip       = false;
            int  zero       = GT.ReadInt32(fs, 4, flip);
            int  len        = GT.ReadInt32(fs, 4, flip);
            int  paletteLen = GT.ReadInt32(fs, 4, flip);
            int  next       = GT.ReadInt32(fs, 4, flip);

            long offsetPalette = 16 + len;

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

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

                if (first < 0x40)   //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);
                    }
                }
            }

            rawbytes = listBytes.ToArray();

            if (rawbytes.Length != 49152)
            {
                Console.WriteLine();
            }

            File.WriteAllBytes("GT-KY-FRM.bin", rawbytes);

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

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int b = 255 - rawbytes[k++];

                    if (b > 32)
                    {
                        Color c = Color.FromArgb(b, b, b);
                        bitmap.SetPixel(x, Height - 1 - y, c);
                    }
                    else
                    {
                        fs.Position = offsetPalette + (62 - b * 2);

                        byte left  = (byte)fs.ReadByte();
                        byte right = (byte)fs.ReadByte();

                        ushort palette = (ushort)(right | left << 8);

                        Color c = Palette2Color(palette);
                        //c = Color.FromArgb(255 - (left3 * 36), c);
                        bitmap.SetPixel(x, Height - 1 - y, c);
                    }
                }
            }
        }
Exemple #22
0
        public static GTFS ToGTFS(GTFS fs, int diff)
        {
            fs.Position = 0;

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

            byte[] uncompressed = new byte[sizeun];
            int    pos          = 0;

            while (fs.Position < sizeco + 16)   // 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 (fs.Position >= sizeco + 16)
                    {
                        break;
                    }

                    if (bits[i])
                    {
                        byte b = GT.ReadByte(fs);
                        uncompressed[pos++] = b;
                    }
                    else
                    {
                        int offset = GT.ReadInt16(fs, 2, false);
                        fs.Position -= 2;
                        byte[] bOff = GT.ReadBytes(fs, 2, false);

                        /*
                         * Console.WriteLine(bOff[0] + ", " + bOff[1]);
                         *
                         * //int offsetOrg = offset;
                         *
                         * offset += 259;
                         * int len = 4 + GT.ReadByte(fs);
                         *
                         * if (offset < 0) {
                         *  for (int x = 0; x < len; x++)
                         *      uncompressed[pos + x] = uncompressed[0];
                         * } else {
                         *  for (int x = 0; x < len; x++)
                         *      uncompressed[pos + x] = uncompressed[offset + x];
                         * }
                         */

                        int len = 4 + GT.ReadByte(fs);

                        /*
                         * if((bOff[1] & 0x80) == 0x80) {
                         *  uncompressed[pos + 0] = 0xFF;
                         *  uncompressed[pos + 1] = bOff[0];
                         *  uncompressed[pos + 2] = bOff[1];
                         *  uncompressed[pos + 3] = (byte)len;
                         *
                         *  for (int x = 4; x < len; x++)
                         *      uncompressed[pos + x] = 0;
                         * } else {
                         */
                        offset += 259;
                        if (offset == -1)
                        {
                            for (int x = 0; x < len; x++)
                            {
                                uncompressed[pos + x] = uncompressed[0];
                            }
                        }
                        else if (offset < 0)
                        {
                            //offset -= diff;
                        }
                        else
                        {
                            for (int x = 0; x < len; x++)
                            {
                                uncompressed[pos + x] = uncompressed[offset + x];
                            }
                        }
                        //}

                        pos += len;
                    }
                }
            }

            return(new GTFS(uncompressed));
        }
Exemple #23
0
        private void Form1_Load(object sender, EventArgs e)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "Wireshark pcapng|*.pcapng|All Files (*.*)|*.*";

            DialogResult res = openFileDialog.ShowDialog();

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

                bool flip = false;
                GTFS fs   = new GTFS(openFileDialog.FileName);
                //bool linux = false;
                int wiresharkNo = 0;

                while (fs.Position < fs.Length)
                {
                    bool setflip = flip;

                    int blockType   = GT.ReadInt32(fs, 4, false);
                    int blockLength = GT.ReadInt32(fs, 4, false);

                    if (blockType == 0xA0D0D0A)
                    {
                        //Section Header Block
                        int    BOM          = GT.ReadInt32(fs, 4, false);
                        byte[] blockBodyRem = GT.ReadBytes(fs, blockLength - 16, flip);

                        if (BOM == 0x1a2b3c4d)
                        {
                            setflip = true;
                        }
                        else if (BOM == 0x4D3C2B1A)
                        {
                            setflip = false;
                        }
                        else
                        {
                            Console.WriteLine();
                        }
                    }
                    else if (blockType == 0x01)
                    {
                        //Interface Description Block
                        flip = false;
                        int LinkType = GT.ReadInt16(fs, 2, flip); //1 is ethernet
                        int Reserved = GT.ReadInt16(fs, 2, flip);
                        int SnapLen  = GT.ReadInt32(fs, 4, flip);
                        //Options
                        byte[] remaining = GT.ReadBytes(fs, blockLength - 12 - 8, flip);

                        //I don't suspect there's any data in here I need
                    }
                    else if (blockType == 0x05)
                    {
                        //Interface Statistics Block
                        //Nothing special
                        byte[] blockBody = GT.ReadBytes(fs, blockLength - 12, flip);
                    }
                    else if (blockType == 0x06)
                    {
                        wiresharkNo++;
                        flip = false;
                        //Enhanced Packet Block
                        int InterfaceID    = GT.ReadInt32(fs, 4, flip);
                        int TimestampHigh  = GT.ReadInt32(fs, 4, flip);
                        int TimestampLow   = GT.ReadInt32(fs, 4, flip);
                        int CapturedLength = GT.ReadInt32(fs, 4, flip);
                        int PacketLength   = GT.ReadInt32(fs, 4, flip);

                        int CapturedLenRem = CapturedLength;

                        //-----
                        byte[] MACdestination = GT.ReadBytes(fs, 6, flip);
                        byte[] MACsource      = GT.ReadBytes(fs, 6, flip);
                        int    type           = GT.ReadInt16(fs, 2, flip);
                        CapturedLenRem -= 14;

                        if (type == 8)   //IPv4
                        {
                            flip = true;
                            byte   version        = GT.ReadByte(fs);
                            byte   dsf            = GT.ReadByte(fs);
                            int    totallen       = GT.ReadInt16(fs, 2, flip);
                            int    id             = GT.ReadInt16(fs, 2, flip);
                            byte   flags          = GT.ReadByte(fs);
                            int    fragmentOffset = GT.ReadByte(fs);
                            byte   ttl            = GT.ReadByte(fs);
                            byte   protocol       = GT.ReadByte(fs);
                            int    headerChecksum = GT.ReadInt16(fs, 2, flip);
                            byte[] IPsource       = GT.ReadBytes(fs, 4, flip);
                            byte[] IPdestination  = GT.ReadBytes(fs, 4, flip);
                            CapturedLenRem -= 20;

                            if (protocol == 0x01)   //ICMP
                            {
                                byte   ICMP_type  = GT.ReadByte(fs);
                                byte   ICMP_code  = GT.ReadByte(fs);
                                int    checksum   = GT.ReadInt16(fs, 2, flip);
                                int    identifier = GT.ReadInt16(fs, 2, flip);
                                int    seqnum     = GT.ReadInt16(fs, 2, flip);
                                byte[] remaining  = GT.ReadBytes(fs, 32, flip);
                                CapturedLenRem -= 40;
                            }
                            else if (protocol == 0x06)     //TCP
                            {
                                int  srcPort    = GT.ReadUInt16(fs, 2, flip);
                                int  destPort   = GT.ReadUInt16(fs, 2, flip);
                                int  seqnum     = GT.ReadInt16(fs, 4, false);
                                int  acknum     = GT.ReadInt16(fs, 4, false);
                                int  headerLen  = GT.ReadByte(fs) / 4;
                                byte flag       = GT.ReadByte(fs);
                                int  windowSize = GT.ReadUInt16(fs, 2, flip);
                                int  checksum   = GT.ReadInt16(fs, 2, flip);
                                int  urgent     = GT.ReadInt16(fs, 2, flip);
                                CapturedLenRem -= 20;

                                Console.WriteLine(seqnum.ToString() + " / " + acknum.ToString());

                                if (headerLen > 20)
                                {
                                    byte[] options = GT.ReadBytes(fs, headerLen - 20, flip);
                                    CapturedLenRem -= options.Length;
                                }

                                if ((flag & 0x08) == 0x08)  //PSH flag
                                {
                                    byte[] remainingData = GT.ReadBytes(fs, CapturedLenRem, false);
                                    CapturedLenRem -= CapturedLenRem;

                                    listTCPdata.Add(remainingData);
                                }
                            }
                            else if (protocol == 0x11)     //UDP
                            {
                                int srcPort  = GT.ReadUInt16(fs, 2, flip);
                                int destPort = GT.ReadUInt16(fs, 2, flip);
                                int length   = GT.ReadInt16(fs, 2, flip);
                                int checksum = GT.ReadInt16(fs, 2, flip);
                                CapturedLenRem -= 8;
                                byte[] remaining = GT.ReadBytes(fs, CapturedLenRem, flip);
                                CapturedLenRem -= CapturedLenRem;
                            }
                            else
                            {
                                Console.WriteLine("???");
                            }
                        }
                        else
                        {
                            Console.WriteLine("UNKNOWN");
                        }

                        int padding = blockLength - 32 - CapturedLength;
                        if (padding > 0)
                        {
                            GT.ReadBytes(fs, padding, flip);
                        }
                        else if (CapturedLenRem > 0)
                        {
                            GT.ReadBytes(fs, CapturedLenRem, flip);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Block type: " + blockType.ToString("X2"));
                        byte[] blockBody = GT.ReadBytes(fs, blockLength - 12, flip);
                    }

                    int blockLength2 = GT.ReadInt32(fs, 4, false);
                    if (blockLength != blockLength2)
                    {
                        Console.WriteLine("Lengths not equal. Block definition wrong.");
                    }

                    flip = setflip;
                }

                MemoryStream stream = new MemoryStream();
                foreach (byte[] b in listTCPdata)
                {
                    stream.Write(b, 0, b.Length);
                }
                GTFS usbIPdata = new GTFS(stream.ToArray());
                usbIPdata.WriteBytesToFile("usbip.bin");

                while (usbIPdata.Position < usbIPdata.Length)
                {
                    var proto = Protocol.Get(usbIPdata);
                    Console.WriteLine(proto.ToString());
                }
            }
        }
Exemple #24
0
        public ModelPS2(string filename, string sf, bool useGTFSView = false) : base()
        {
            FileName = filename;
            string fileDir = filename.Replace(sf, "");

            bool flip = false;
            GTFS fs   = new GTFS(FileName);

            meshInfo = new List <MeshInfo>();
            textures = new List <Texture>();

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

            fs.Position = texStart;

            long texID = 0;

            while (texID != -1)
            {
                texID        = GT.ReadInt32(fs, 4, flip);
                fs.Position += 12;
                if (texID != -1)
                {
                    string fileTexture = "textures_";
                    if (texID < 10)
                    {
                        fileTexture += "0";
                    }
                    if (texID < 100)
                    {
                        fileTexture += "0";
                    }
                    if (texID < 1000)
                    {
                        fileTexture += "0";
                    }
                    fileTexture += texID + ".raw";
                    textures.Add(new TexturePS2(fileDir + fileTexture, fileTexture));
                }
            }

            long meshTableOffset = -1;

            if (texStart == 16)
            {
                fs.Position = meshCountOffset;
                int modelCount = GT.ReadInt32(fs, 4, flip);
                int unk000     = GT.ReadInt32(fs, 4, flip);
                int unk001     = GT.ReadInt32(fs, 4, flip);
                meshTableOffset = (meshCountOffset - (0x90 * modelCount));
                fs.Position     = meshTableOffset;
                for (int i = 0; i < modelCount; i++)
                {
                    byte[] bHead = GT.ReadBytes(fs, 6, flip);
                    fs.Position += 0xE; //14
                    int[] vertOffsets = new int[19];
                    for (int k = 0; k < 19; k++)
                    {
                        vertOffsets[k] = GT.ReadInt32(fs, 4, flip);
                    }
                    int count000 = GT.ReadInt16(fs, 2, flip); //Numvertex
                    int count001 = GT.ReadInt16(fs, 2, flip);
                    fs.Position += 0x28;
                    float float000    = GT.ReadFloat(fs, 4, flip);
                    int[] faceOffsets = new int[3];
                    for (int k = 0; k < 3; k++)
                    {
                        faceOffsets[k] = GT.ReadInt32(fs, 4, flip);
                    }
                    int sections = 1;
                    if (faceOffsets[2] != 0)
                    {
                        sections = 3;
                    }
                    else if (faceOffsets[1] != 0)
                    {
                        sections = 2;
                    }

                    if (vertOffsets[0] != 0)
                    {
                        meshInfo.Add(new MeshInfo(sections, vertOffsets, faceOffsets, count000, count001));
                    }
                }
            }
            else if (texStart == 0x20)
            {
                //Level
                long modelCount = fs.Length - meshCountOffset / 0xB0;
                for (long i = 0; i < modelCount; i++)
                {
                    fs.Position = meshCountOffset + (i * 0xB0);
                    long x = GT.ReadInt32(fs, 4, flip);
                    meshTableOffset = x - 0x90;
                    if (meshTableOffset > 0)
                    {
                        fs.Position = meshTableOffset;
                        //<<--
                        byte[] bHead = GT.ReadBytes(fs, 6, flip);
                        fs.Position += 0xE; //14
                        int[] vertOffsets = new int[19];
                        for (int k = 0; k < 19; k++)
                        {
                            vertOffsets[k] = GT.ReadInt32(fs, 4, flip);
                        }
                        int count000 = GT.ReadInt16(fs, 2, flip);
                        int count001 = GT.ReadInt16(fs, 2, flip);
                        fs.Position += 0x28;
                        float float000    = GT.ReadFloat(fs, 4, flip);
                        int[] faceOffsets = new int[3];
                        for (int k = 0; k < 3; k++)
                        {
                            faceOffsets[k] = GT.ReadInt32(fs, 4, flip);
                        }
                        int sections = 1;
                        if (faceOffsets[2] != 0)
                        {
                            sections = 3;
                        }
                        else if (faceOffsets[1] != 0)
                        {
                            sections = 2;
                        }

                        if (vertOffsets[0] != 0)
                        {
                            meshInfo.Add(new MeshInfo(sections, vertOffsets, faceOffsets, count000, count001));
                        }
                        //<<--
                    }
                }
            }

            foreach (MeshInfo meshinfo in meshInfo)
            {
                int objCount = 0;
                if (texStart == 16)
                {
                    objCount    = (int)(((meshTableOffset - meshinfo.vertOffsets[0]) - 14) / 10);
                    fs.Position = meshinfo.vertOffsets[0];
                }
                else
                {
                    objCount    = (((meshinfo.vertOffsets[7] - meshinfo.vertOffsets[4])) / 0x10);
                    fs.Position = meshinfo.vertOffsets[0];
                }

                //The problem is PS2 has the mesh data in a different spot to Xbox, can't work out how many objects.

                for (int a = 0; a < objCount; a++)
                {
                    uint texid     = GT.ReadUInt16(fs, 2, flip);
                    uint meshId    = GT.ReadUInt16(fs, 2, flip);
                    uint vertStart = GT.ReadUInt16(fs, 2, flip);
                    uint vertCount = GT.ReadUInt16(fs, 2, flip);
                    uint unk003    = GT.ReadUInt16(fs, 2, flip);
                    if (meshId >= meshinfo.meshTable.Count)
                    {
                        meshinfo.meshTable.Add(new Mesh(meshId, vertStart, vertCount, texid, meshinfo.vertOffsets[5], meshinfo.vertOffsets[6], meshinfo.vertOffsets[7], meshinfo.vertOffsets[8]));
                    }
                }

                //Previously the below had to be disabled. Unsure what needs to be changed.
                if (meshinfo.count000 >= 2)
                {
                    if (texStart == 16)
                    {
                        objCount    = (((meshinfo.vertOffsets[9] - meshinfo.vertOffsets[5]) - 2) / 10);
                        fs.Position = meshinfo.vertOffsets[0];
                    }
                    else
                    {
                        objCount    = (((meshinfo.vertOffsets[12] - meshinfo.vertOffsets[9])) / 0x10);
                        fs.Position = meshinfo.vertOffsets[1];
                        for (int a = 0; a < objCount; a++)
                        {
                            uint texid     = GT.ReadUInt16(fs, 2, flip);
                            uint meshId    = GT.ReadUInt16(fs, 2, flip);
                            uint vertStart = GT.ReadUInt16(fs, 2, flip);
                            uint vertCount = GT.ReadUInt16(fs, 2, flip);
                            uint unk003    = GT.ReadUInt16(fs, 2, flip);
                            if (vertCount != 0xFFFF)
                            {
                                meshinfo.meshTable.Add(new Mesh(meshId, vertStart, vertCount, texid, meshinfo.vertOffsets[10], meshinfo.vertOffsets[11], meshinfo.vertOffsets[12], meshinfo.vertOffsets[13]));
                            }
                        }
                    }
                }
                else if (meshinfo.count000 >= 3)
                {
                    if (texStart == 16)
                    {
                        objCount    = (((meshinfo.vertOffsets[14] - meshinfo.vertOffsets[10]) - 2) / 10);
                        fs.Position = meshinfo.vertOffsets[2];
                    }
                    else
                    {
                        objCount    = (((meshinfo.vertOffsets[17] - meshinfo.vertOffsets[14])) / 0x10);
                        fs.Position = meshinfo.vertOffsets[2];
                        for (int a = 0; a < objCount; a++)
                        {
                            uint texid     = GT.ReadUInt16(fs, 2, flip);
                            uint meshId    = GT.ReadUInt16(fs, 2, flip);
                            uint vertStart = GT.ReadUInt16(fs, 2, flip);
                            uint vertCount = GT.ReadUInt16(fs, 2, flip);
                            uint unk003    = GT.ReadUInt16(fs, 2, flip);
                            if (vertCount != 0xFFFF)
                            {
                                meshinfo.meshTable.Add(new Mesh(meshId, vertStart, vertCount, texid, meshinfo.vertOffsets[15], meshinfo.vertOffsets[16], meshinfo.vertOffsets[17], meshinfo.vertOffsets[18]));
                            }
                        }
                    }
                }

                foreach (Mesh mesh in meshinfo.meshTable)
                {
                    int facedir = 0;
                    fs.Position = mesh.off5 + (0x10 * mesh.vertStart);
                    //setName
                    //setMaterial
                    for (int b = 0; b < mesh.vertCount; b++)
                    {
                        float vx = GT.ReadFloat(fs, 4, flip);
                        float vy = GT.ReadFloat(fs, 4, flip);
                        float vz = GT.ReadFloat(fs, 4, flip);
                        mesh.vertData.Add(new float[] { vx, vy, vz });

                        byte   wind  = GT.ReadByte(fs);
                        byte   flag  = GT.ReadByte(fs);
                        ushort scale = GT.ReadUInt16(fs, 2, flip);
                        if (flag == 0x00)
                        {
                            if ((facedir ^ wind) == 0)
                            {
                                mesh.faceData.Add(new int[] { b - 2, b - 1, b });
                            }
                            else
                            {
                                mesh.faceData.Add(new int[] { b - 1, b - 2, b });
                            }
                        }
                        else
                        {
                            facedir = 1;
                        }
                        facedir = 1 - facedir;
                    }
                    fs.Position = mesh.off6 + (16 * mesh.vertStart);
                    for (int b = 0; b < mesh.vertCount; b++)
                    {
                        float tu = GT.ReadFloat(fs, 4, flip);
                        float tv = GT.ReadFloat(fs, 4, flip);
                        float tw = GT.ReadFloat(fs, 4, flip);
                        mesh.uvData.Add(new float[] { tu *tw, tv *tw });
                    }
                    if (texStart == 16)
                    {
                        fs.Position = mesh.off8 + (0x10 * mesh.vertStart);
                        for (int b = 0; b < mesh.vertCount; b++)
                        {
                            float nx = GT.ReadFloat(fs, 4, flip);
                            float ny = GT.ReadFloat(fs, 4, flip);
                            float nz = GT.ReadFloat(fs, 4, flip);
                            float nw = GT.ReadFloat(fs, 4, flip);
                            mesh.normalData.Add(new float[] { nx, ny, nz });
                            HasNormals = true;
                        }
                    }
                    else
                    {
                        fs.Position = mesh.off7 + (0x10 * mesh.vertStart);
                    }
                }
            }

            if (useGTFSView)
            {
                new GTFSView(fs).Show();
            }
        }
Exemple #25
0
        public ModelXbox(string filename, string sf, bool useGTFSView = false) : base()
        {
            FileName = filename;
            string fileDir = filename.Replace(sf, "");

            bool flip = false;
            GTFS fs   = new GTFS(FileName);

            meshInfo = new List <MeshInfo>();
            textures = new List <Texture>();

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

            //int unknownOffset1 = GT.ReadInt32(fs, 4, flip);
            //int unknownOffset2 = GT.ReadInt32(fs, 4, flip);

            fs.Position = texStart;

            long texID = 0;

            while (texID != -1)
            {
                texID = GT.ReadInt32(fs, 4, flip);

                int texUnk1 = GT.ReadInt32(fs, 4, flip); //Guessing X repeat?
                int texUnk2 = GT.ReadInt32(fs, 4, flip); //Guessing Y repeat?
                int texUnk3 = GT.ReadInt32(fs, 4, flip); //Guessing sound related?

                if (texID != -1)
                {
                    string fileTexture = "textures_";
                    if (texID < 10)
                    {
                        fileTexture += "0";
                    }
                    if (texID < 100)
                    {
                        fileTexture += "0";
                    }
                    if (texID < 1000)
                    {
                        fileTexture += "0";
                    }
                    fileTexture += texID + ".xbt";
                    textures.Add(new TextureXbox(fileDir + fileTexture, fileTexture));
                }
            }

            long meshTableOffset = -1;

            if (texStart == 0xC)
            {
                fs.Position = meshCountOffset;
                int modelCount = GT.ReadInt32(fs, 4, flip);
                int unk000     = GT.ReadInt32(fs, 4, flip);
                int unk001     = GT.ReadInt32(fs, 4, flip);
                meshTableOffset = (meshCountOffset - (0x9C * modelCount));
                fs.Position     = meshTableOffset;
                for (int i = 0; i < modelCount; i++)
                {
                    byte[] bHead = GT.ReadBytes(fs, 6, flip);
                    fs.Position += 0xE; //14
                    int[] vertOffsets = new int[19];
                    for (int k = 0; k < 19; k++)
                    {
                        vertOffsets[k] = GT.ReadInt32(fs, 4, flip);
                    }
                    int count000 = GT.ReadInt16(fs, 2, flip);
                    int count001 = GT.ReadInt16(fs, 2, flip);
                    fs.Position += 0x28;
                    float float000    = GT.ReadFloat(fs, 4, flip);
                    int[] faceOffsets = new int[3];
                    for (int k = 0; k < 3; k++)
                    {
                        faceOffsets[k] = GT.ReadInt32(fs, 4, flip);
                    }
                    int sections = 1;
                    if (faceOffsets[2] != 0)
                    {
                        sections = 3;
                    }
                    else if (faceOffsets[1] != 0)
                    {
                        sections = 2;
                    }

                    if (vertOffsets[0] != 0)
                    {
                        meshInfo.Add(new MeshInfo(sections, vertOffsets, faceOffsets, count000, count001));
                    }
                }
            }
            else if (texStart == 0x20)
            {
                //Level
                long modelCount = (fs.Length - meshCountOffset) / 0xB0;
                for (long i = 0; i < modelCount; i++)
                {
                    fs.Position = meshCountOffset + (i * 0xB0);
                    long x = GT.ReadInt32(fs, 4, flip);
                    meshTableOffset = x - 0x9C; //Not sure why I had 0x90
                    if (meshTableOffset > 0)
                    {
                        fs.Position = meshTableOffset;
                        //<<--
                        byte[] bHead = GT.ReadBytes(fs, 6, flip);
                        fs.Position += 0xE; //14
                        int[] vertOffsets = new int[19];
                        for (int k = 0; k < 19; k++)
                        {
                            vertOffsets[k] = GT.ReadInt32(fs, 4, flip);
                        }
                        int count000 = GT.ReadInt16(fs, 2, flip);
                        int count001 = GT.ReadInt16(fs, 2, flip);
                        fs.Position += 0x28;
                        float float000    = GT.ReadFloat(fs, 4, flip);
                        int[] faceOffsets = new int[3];
                        for (int k = 0; k < 3; k++)
                        {
                            faceOffsets[k] = GT.ReadInt32(fs, 4, flip);
                        }
                        int sections = 1;
                        if (faceOffsets[2] != 0)
                        {
                            sections = 3;
                        }
                        else if (faceOffsets[1] != 0)
                        {
                            sections = 2;
                        }

                        if (vertOffsets[0] != 0)
                        {
                            meshInfo.Add(new MeshInfo(sections, vertOffsets, faceOffsets, count000, count001));
                        }
                        //<<--
                    }
                }
            }

            foreach (MeshInfo meshinfo in meshInfo)
            {
                int objCount = 0;
                if (texStart == 0xC)
                {
                    objCount    = (((meshinfo.vertOffsets[4] - meshinfo.vertOffsets[0]) - 2) / 10);
                    fs.Position = meshinfo.vertOffsets[0];
                }
                else
                {
                    objCount    = (((meshinfo.vertOffsets[7] - meshinfo.vertOffsets[4])) / 0x10);
                    fs.Position = meshinfo.vertOffsets[0];
                }

                for (int a = 0; a < objCount; a++)
                {
                    uint texid     = GT.ReadUInt16(fs, 2, flip);
                    uint meshId    = GT.ReadUInt16(fs, 2, flip);
                    uint vertStart = GT.ReadUInt16(fs, 2, flip);
                    uint vertCount = GT.ReadUInt16(fs, 2, flip);
                    uint unk003    = GT.ReadUInt16(fs, 2, flip);

                    //if(unk003 != 0) // Have yet to see anything else (okay mapboy ph had some)
                    //Console.WriteLine("Mesh " + meshId + " Tex " + texid + " Unk003: " + unk003);

                    if (meshId >= meshinfo.meshTable.Count)
                    {
                        meshinfo.meshTable.Add(new Mesh(meshId, vertStart, vertCount, texid, meshinfo.vertOffsets[5], meshinfo.vertOffsets[6], meshinfo.vertOffsets[7], meshinfo.vertOffsets[8]));
                    }
                }

                if (meshinfo.count000 >= 2)
                {
                    if (texStart == 0xC)
                    {
                        objCount    = (((meshinfo.vertOffsets[9] - meshinfo.vertOffsets[5]) - 2) / 10);
                        fs.Position = meshinfo.vertOffsets[0];
                    }
                    else
                    {
                        objCount    = (((meshinfo.vertOffsets[12] - meshinfo.vertOffsets[9])) / 0x10);
                        fs.Position = meshinfo.vertOffsets[1];
                        for (int a = 0; a < objCount; a++)
                        {
                            uint texid     = GT.ReadUInt16(fs, 2, flip);
                            uint meshId    = GT.ReadUInt16(fs, 2, flip);
                            uint vertStart = GT.ReadUInt16(fs, 2, flip);
                            uint vertCount = GT.ReadUInt16(fs, 2, flip);
                            uint unk003    = GT.ReadUInt16(fs, 2, flip);

                            //if (unk003 != 0) // Have yet to see anything else
                            //Console.WriteLine("Mesh " + meshId + " Tex " + texid + " Unk003: " + unk003);

                            if (vertCount != 0xFFFF)
                            {
                                meshinfo.meshTable.Add(new Mesh(meshId, vertStart, vertCount, texid, meshinfo.vertOffsets[10], meshinfo.vertOffsets[11], meshinfo.vertOffsets[12], meshinfo.vertOffsets[13]));
                            }
                        }
                    }
                }
                else if (meshinfo.count000 >= 3)
                {
                    if (texStart == 0xC)
                    {
                        objCount    = (((meshinfo.vertOffsets[14] - meshinfo.vertOffsets[10]) - 2) / 10);
                        fs.Position = meshinfo.vertOffsets[2];
                    }
                    else
                    {
                        objCount    = (((meshinfo.vertOffsets[17] - meshinfo.vertOffsets[14])) / 0x10);
                        fs.Position = meshinfo.vertOffsets[2];
                        for (int a = 0; a < objCount; a++)
                        {
                            uint texid     = GT.ReadUInt16(fs, 2, flip);
                            uint meshId    = GT.ReadUInt16(fs, 2, flip);
                            uint vertStart = GT.ReadUInt16(fs, 2, flip);
                            uint vertCount = GT.ReadUInt16(fs, 2, flip);
                            uint unk003    = GT.ReadUInt16(fs, 2, flip);

                            //if (unk003 != 0) // Have yet to see anything else
                            //Console.WriteLine("Mesh " + meshId + " Tex " + texid + " Unk003: " + unk003);

                            if (vertCount != 0xFFFF)
                            {
                                meshinfo.meshTable.Add(new Mesh(meshId, vertStart, vertCount, texid, meshinfo.vertOffsets[15], meshinfo.vertOffsets[16], meshinfo.vertOffsets[17], meshinfo.vertOffsets[18]));
                            }
                        }
                    }
                }

                foreach (Mesh mesh in meshinfo.meshTable)
                {
                    int facedir = 0;
                    fs.Position = mesh.off5 + (0x10 * mesh.vertStart);
                    //setName
                    //setMaterial
                    for (int b = 0; b < mesh.vertCount; b++)
                    {
                        float vx = GT.ReadFloat(fs, 4, flip);
                        float vy = GT.ReadFloat(fs, 4, flip);
                        float vz = GT.ReadFloat(fs, 4, flip);
                        mesh.vertData.Add(new float[] { vx, vy, vz });

                        byte   wind  = GT.ReadByte(fs);
                        byte   flag  = GT.ReadByte(fs);
                        ushort scale = GT.ReadUInt16(fs, 2, flip);

                        //if (scale != 16256 || (flag != 0 && flag != 128))
                        //Console.WriteLine("Mesh " + mesh.meshId + " wind: " + wind + " flag: " + flag + " scale: " + scale);

                        if (flag == 0x00)
                        {
                            if ((facedir ^ wind) == 0)
                            {
                                mesh.faceData.Add(new int[] { b - 2, b - 1, b });
                            }
                            else
                            {
                                mesh.faceData.Add(new int[] { b - 1, b - 2, b });
                            }
                        }
                        else
                        {
                            facedir = 1;
                        }
                        facedir = 1 - facedir;
                    }
                    fs.Position = mesh.off6 + (0xC * mesh.vertStart);
                    for (int b = 0; b < mesh.vertCount; b++)
                    {
                        float tu = GT.ReadFloat(fs, 4, flip);
                        float tv = GT.ReadFloat(fs, 4, flip);
                        float tw = GT.ReadFloat(fs, 4, flip);
                        mesh.uvData.Add(new float[] { tu *tw, tv *tw });
                        //Console.WriteLine(fs.Position);
                    }
                    if (texStart == 0xC)
                    {
                        fs.Position = mesh.off8 + (0x10 * mesh.vertStart);
                        for (int b = 0; b < mesh.vertCount; b++)
                        {
                            float nx = GT.ReadFloat(fs, 4, flip);
                            float ny = GT.ReadFloat(fs, 4, flip);
                            float nz = GT.ReadFloat(fs, 4, flip);
                            float nw = GT.ReadFloat(fs, 4, flip);
                            mesh.normalData.Add(new float[] { nx, ny, nz });
                            HasNormals = true;
                        }
                    }
                    else
                    {
                        fs.Position = mesh.off7 + (0x10 * mesh.vertStart);
                    }
                }
            }

            if (useGTFSView)
            {
                new GTFSView(fs).Show();
            }
        }
Exemple #26
0
        // V1

        //https://www.gamefaqs.com/ds/933043-hotel-dusk-room-215/faqs/46878?print=1

        public static GTFS ToGTFS(GTFS fs)
        {
            fs.Position = 0;

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

            byte[] uncompressed = new byte[sizeun];
            byte[] expanded     = new byte[sizeun]; // i.e. doesn't fill in the gaps
            int    pos          = 0;

            while (fs.Position < sizeco + 16)
            {
                byte     input = GT.ReadByte(fs);
                BitArray bits  = new BitArray(new byte[] { input });

                for (int i = 0; i < 8; i++)
                {
                    if (fs.Position >= sizeco + 16)
                    {
                        break;
                    }

                    if (bits[i])
                    {
                        byte b = GT.ReadByte(fs);
                        uncompressed[pos] = b;
                        expanded[pos]     = b;
                        pos++;
                    }
                    else
                    {
                        byte[] bOff   = GT.ReadBytes(fs, 2, false);
                        int    len    = 4 + GT.ReadByte(fs);
                        int    offset = (bOff[1] << 8) + bOff[0];

                        int posHi = hibit(pos - 259);
                        int offHi = hibit(offset);
                        if (pos < 0x10000)
                        {
                            int signed = (short)offset;
                            if (signed < 0 && signed + 259 >= 0)
                            {
                                offset = signed;
                            }
                        }
                        else if (posHi >= 0x20000 && offHi < posHi)
                        {
                            if (offset + posHi < pos)
                            {
                                offset += posHi;
                            }
                            else if (offset + 0x10000 < pos)
                            {
                                offset += 0x10000;
                            }
                        }
                        else if (posHi >= 0x10000 && offHi < posHi && offset + posHi < pos)
                        {
                            offset += posHi;
                        }
                        offset += 259;

                        if (offset < 0 || offset + len >= uncompressed.Length)
                        {
                            //Console.WriteLine("Shouldn't happen: " + GT.ByteArrayToString(bOff, " ") + " (" + offset + ") at pos: " + pos);
                            for (int x = 0; x < len; x++)
                            {
                                uncompressed[pos + x] = 0;
                            }
                        }
                        else
                        {
                            for (int x = 0; x < len; x++)
                            {
                                uncompressed[pos + x] = uncompressed[offset + x];
                            }
                        }
                        #region Expanded
                        expanded[pos + 0] = bOff[0];
                        expanded[pos + 1] = bOff[1];
                        expanded[pos + 2] = (byte)(len - 4);

                        for (int g = 3; g < len; g++)
                        {
                            expanded[pos + g] = 0x00;
                        }
                        #endregion

                        pos += len;
                    }
                }
            }

            //new FormHexCompare(expanded, uncompressed).Show();

            return(new GTFS(uncompressed));
        }