Esempio n. 1
0
            internal CollisionMask(Reader reader)
            {
                byte flags = reader.ReadByte();

                isCeiling    = (flags >> 4) != 0;
                Behaviour    = (byte)(flags & 0xF);
                FloorAngle   = reader.ReadByte();
                RWallAngle   = reader.ReadByte();
                LWallAngle   = reader.ReadByte();
                CeilingAngle = reader.ReadByte();

                byte[] collision = reader.ReadBytes(8);

                int ActiveCollision = reader.ReadByte() << 8;

                ActiveCollision |= reader.ReadByte();

                int i  = 0;
                int i2 = 1;

                for (int c = 0; c < 8; c++)
                {
                    Collision[i]  = (byte)((collision[c] & 0xF0) >> 4);
                    Collision[i2] = (byte)(collision[c] & 0x0F);
                    i            += 2;
                    i2           += 2;
                }

                int b = 0;

                for (int ii = 0; ii < 16; ii++)
                {
                    HasCollision[ii] = IsBitSet(ActiveCollision, b);
                    b++;
                }
            }
Esempio n. 2
0
            public void ReadGIFData(Reader reader)
            {
                int eighthHeight  = Height >> 3;
                int quarterHeight = Height >> 2;
                int halfHeight    = Height >> 1;
                int bitsWidth     = 0;
                int width         = 0;

                Entry[] codeTable = new Entry[0x10000];
                ImageData = new byte[Width * Height + 1];

                for (int i = 0; i < 0x10000; i++)
                {
                    codeTable[i] = new Entry();
                }

                // Get frame
                byte type, subtype, temp;

                type = reader.ReadByte();

                while (type != 0)
                {
                    bool tableFull, interlaced;
                    int  codeSize, initCodeSize;
                    int  clearCode, eoiCode, emptyCode;
                    int  blockLength, bitCache, bitCacheLength;
                    int  codeToAddFrom, mark, str_len = 0, frm_off = 0;
                    uint currentCode;

                    switch (type)
                    {
                    // Extension
                    case 0x21:
                        subtype = reader.ReadByte();
                        switch (subtype)
                        {
                        // Graphics Control Extension
                        case 0xF9:
                            reader.ReadBytes(0x06);
                            // temp = reader.ReadByte();  // Block Size [byte] (always 0x04)
                            // temp = reader.ReadByte();  // Packed Field [byte] //
                            // temp16 = reader.ReadUInt16(); // Delay Time [short] //
                            // temp = reader.ReadByte();  // Transparent Color Index? [byte] //
                            // temp = reader.ReadByte();  // Block Terminator [byte] //
                            break;

                        // Plain Text Extension
                        case 0x01:
                        // Comment Extension
                        case 0xFE:
                        // Application Extension
                        case 0xFF:
                            temp = reader.ReadByte();         // Block Size
                                                              // Continue until we run out of blocks
                            while (temp != 0)
                            {
                                // Read block
                                reader.ReadBytes(temp);
                                temp = reader.ReadByte();         // next block Size
                            }
                            break;

                        default:
                            Console.WriteLine("GIF LOAD FAILED");
                            return;
                        }
                        break;

                    // Image descriptor
                    case 0x2C:
                        // temp16 = reader.ReadUInt16(); // Destination X
                        // temp16 = reader.ReadUInt16(); // Destination Y
                        // temp16 = reader.ReadUInt16(); // Destination Width
                        // temp16 = reader.ReadUInt16(); // Destination Height
                        reader.ReadBytes(8);
                        temp = reader.ReadByte();        // Packed Field [byte]

                        // If a local color table exists,
                        if ((temp & 0x80) != 0)
                        {
                            int size = 2 << (temp & 0x07);
                            // Load all colors
                            reader.ReadBytes(3 * size);     // reader.ReadBytesTo(buffer, 3 * size);
                        }

                        interlaced = (temp & 0x40) == 0x40;
                        if (interlaced)
                        {
                            bitsWidth = 0;
                            while (width != 0)
                            {
                                width >>= 1;
                                bitsWidth++;
                            }
                            width = Width - 1;
                        }

                        codeSize = reader.ReadByte();

                        clearCode = 1 << codeSize;
                        eoiCode   = clearCode + 1;
                        emptyCode = eoiCode + 1;

                        codeSize++;
                        initCodeSize = codeSize;

                        // Init table
                        for (int i = 0; i <= eoiCode; i++)
                        {
                            codeTable[i].Length = 1;
                            codeTable[i].Prefix = 0xFFF;
                            codeTable[i].Suffix = (byte)i;
                        }

                        blockLength    = 0;
                        bitCache       = 0b00000000;
                        bitCacheLength = 0;
                        tableFull      = false;

                        currentCode = ReadCode(reader, codeSize);

                        codeSize  = initCodeSize;
                        emptyCode = eoiCode + 1;
                        tableFull = false;

                        Entry entry = new Entry();
                        entry.Suffix = 0;

                        while (blockLength != 0)
                        {
                            codeToAddFrom = -1;
                            mark          = 0;

                            if (currentCode == clearCode)
                            {
                                codeSize  = initCodeSize;
                                emptyCode = eoiCode + 1;
                                tableFull = false;
                            }
                            else if (!tableFull)
                            {
                                codeTable[emptyCode].Length = (ushort)(str_len + 1);
                                codeTable[emptyCode].Prefix = (ushort)currentCode;
                                codeTable[emptyCode].Suffix = entry.Suffix;
                                emptyCode++;

                                // Once we reach highest code, increase code size
                                if ((emptyCode & (emptyCode - 1)) == 0)
                                {
                                    mark = 1;
                                }
                                else
                                {
                                    mark = 0;
                                }

                                if (emptyCode >= 0x1000)
                                {
                                    mark      = 0;
                                    tableFull = true;
                                }
                            }

                            currentCode = ReadCode(reader, codeSize);

                            if (currentCode == clearCode)
                            {
                                continue;
                            }
                            if (currentCode == eoiCode)
                            {
                                return;
                            }
                            if (mark == 1)
                            {
                                codeSize++;
                            }

                            entry   = codeTable[currentCode];
                            str_len = entry.Length;

                            while (true)
                            {
                                int p = frm_off + entry.Length - 1;
                                if (interlaced)
                                {
                                    int row = p >> bitsWidth;
                                    if (row < eighthHeight)
                                    {
                                        p = (p & width) + ((((row) << 3) + 0) << bitsWidth);
                                    }
                                    else if (row < quarterHeight)
                                    {
                                        p = (p & width) + ((((row - eighthHeight) << 3) + 4) << bitsWidth);
                                    }
                                    else if (row < halfHeight)
                                    {
                                        p = (p & width) + ((((row - quarterHeight) << 2) + 2) << bitsWidth);
                                    }
                                    else
                                    {
                                        p = (p & width) + ((((row - halfHeight) << 1) + 1) << bitsWidth);
                                    }
                                }

                                ImageData[p] = entry.Suffix;
                                if (entry.Prefix != 0xFFF)
                                {
                                    entry = codeTable[entry.Prefix];
                                }
                                else
                                {
                                    break;
                                }
                            }
                            frm_off += str_len;
                            if (currentCode < emptyCode - 1 && !tableFull)
                            {
                                codeTable[emptyCode - 1].Suffix = entry.Suffix;
                            }
                        }
                        break;
                    }

                    type = reader.ReadByte();

                    if (type == 0x3B)
                    {
                        break;
                    }
                }
            }
Esempio n. 3
0
            public FileInfo(Reader reader)
            {
                byte ss = reader.ReadByte();

                char   buf             = ',';
                string DecryptedString = "";

                for (int i = 0; i < ss; i++)
                {
                    byte b      = reader.ReadByte();
                    int  bufInt = b;

                    bufInt ^= 0xFF;

                    buf             = (char)bufInt;
                    DecryptedString = DecryptedString + buf;
                }

                FileName = DecryptedString;

                //Console.WriteLine(FileName);

                fileSize = reader.ReadUInt32();

                byte[] tmp    = reader.ReadBytes(fileSize);
                int[]  outbuf = new int[fileSize];

                for (int i = 0; i < (int)fileSize; i++)
                {
                    outbuf[i] = tmp[i];
                }

                decryptKeyZ      = ((int)fileSize & 0x1fc) >> 2;
                decryptKeyIndex2 = (decryptKeyZ % 9) + 1;
                decryptKeyIndex1 = (decryptKeyZ % decryptKeyIndex2) + 1;

                decryptKeyIndexZ = 0;

                for (int i = 0; i < (int)fileSize; i++)
                {
                    outbuf[i] ^= decryptKey2[decryptKeyIndex2++] ^ decryptKeyZ;

                    if (decryptKeyIndexZ == 1) // swap nibbles
                    {
                        outbuf[i] = (outbuf[i] >> 4) | ((outbuf[i] & 0xf) << 4);
                    }

                    outbuf[i] ^= decryptKey1[decryptKeyIndex1++];

                    if ((decryptKeyIndex1 <= 19) || (decryptKeyIndex2 <= 11))
                    {
                        if (decryptKeyIndex1 > 19)
                        {
                            decryptKeyIndex1  = 1;
                            decryptKeyIndexZ ^= 1;
                        }
                        if (decryptKeyIndex2 > 11)
                        {
                            decryptKeyIndex2  = 1;
                            decryptKeyIndexZ ^= 1;
                        }
                    }
                    else
                    {
                        decryptKeyZ++;
                        decryptKeyZ &= 0x7F;

                        if (decryptKeyIndexZ != 0)
                        {
                            decryptKeyIndex1 = (decryptKeyZ % 12) + 6;
                            decryptKeyIndex2 = (decryptKeyZ % 5) + 4;
                            decryptKeyIndexZ = 0;
                        }
                        else
                        {
                            decryptKeyIndexZ = 1;
                            decryptKeyIndex1 = (decryptKeyZ % 15) + 3;
                            decryptKeyIndex2 = (decryptKeyZ % 7) + 1;
                        }
                    }
                }
                Filedata = new byte[outbuf.Length];
                for (int i = 0; i < outbuf.Length; i++)
                {
                    Filedata[i] = (byte)outbuf[i];
                }
            }
Esempio n. 4
0
        public StringSet(Reader reader)
        {
            int FileSize = (int)reader.BaseStream.Length;

            byte[] FileData = reader.ReadBytes(reader.BaseStream.Length);
            reader.Close();

            byte  LanguageCount = FileData[0];
            short StringCount   = (short)(FileData[2] + (FileData[1] << 8));

            int StartOffset = (2 * FileData[4]) * StringCount + 3;

            int ID = 0;

            while (true)
            {
                int Count = ((FileSize - StartOffset) / 2);
                if (ID >= Count)
                {
                    break;
                }
                byte v2 = FileData[2 * ID + StartOffset];
                FileData[2 * ID + StartOffset]     = FileData[2 * ID + 1 + StartOffset];
                FileData[2 * ID + 1 + StartOffset] = v2;
                ID++;
            }

            for (int l = 0; l < LanguageCount; l++)
            {
                for (int s = 0; s < StringCount; s++)
                {
                    int Offset = 2 * FileData[4];
                    int v9     = (FileData[Offset * s + 3] << 24) | (FileData[Offset * s + 4] << 16) | (FileData[Offset * s + 5] << 8) | FileData[Offset * s + 6];
                    int v8     = Offset * s + 9;
                    int v10    = 2 * ((FileData[Offset * s + 7] << 8) | FileData[Offset * s + 8]);

                    for (int i = 0; i < l; i++)
                    {
                        v9 += v10;
                        int v4 = FileData[v8] << 8;
                        int v5 = v8 + 1;
                        int v6 = v4 | FileData[v5];
                        v8  = v5 + 1;
                        v10 = 2 * v6;
                    }

                    byte[] array = new byte[0xFF * 2];
                    ID = 0;
                    while (true)
                    {
                        byte A = FileData[v9];
                        byte B = FileData[v9 + 1];
                        if (A == 0 && B == 0)
                        {
                            break;
                        }
                        array[ID + 0] = A;
                        array[ID + 1] = B;
                        ID           += 2;
                    }
                    strings.Add(System.Text.Encoding.Unicode.GetString(array));
                }
            }
        }