Exemplo n.º 1
0
 private static unsafe void LZSlide(
     MKDS_Course_Modifier.Converters.Compression.MI_Compress.LZCompressInfo *info,
     byte *srcp,
     uint n)
 {
     for (uint index = 0; index < n; ++index)
     {
         MKDS_Course_Modifier.Converters.Compression.MI_Compress.SlideByte(info, srcp++);
     }
 }
Exemplo n.º 2
0
 private static unsafe void LZInitTable(
     MKDS_Course_Modifier.Converters.Compression.MI_Compress.LZCompressInfo *info,
     byte *work)
 {
     info->LZOffsetTable = (short *)work;
     info->LZByteTable   = (short *)(work + 8192);
     info->LZEndTable    = (short *)(work + 8192 + 512);
     for (ushort index = 0; index < (ushort)256; ++index)
     {
         info->LZByteTable[index] = (short)-1;
         info->LZEndTable[index]  = (short)-1;
     }
     info->windowPos = (ushort)0;
     info->windowLen = (ushort)0;
 }
Exemplo n.º 3
0
            private static unsafe void SlideByte(MKDS_Course_Modifier.Converters.Compression.MI_Compress.LZCompressInfo *info, byte *srcp)
            {
                byte   index1        = *srcp;
                short *lzByteTable   = info->LZByteTable;
                short *lzOffsetTable = info->LZOffsetTable;
                short *lzEndTable    = info->LZEndTable;
                ushort windowPos     = info->windowPos;
                ushort windowLen     = info->windowLen;
                ushort index2;

                if (windowLen == (ushort)4096)
                {
                    byte index3 = *(srcp - 4096);
                    if ((lzByteTable[index3] = lzOffsetTable[lzByteTable[index3]]) == (short)-1)
                    {
                        lzEndTable[index3] = (short)-1;
                    }
                    index2 = windowPos;
                }
                else
                {
                    index2 = windowLen;
                }
                short index4 = lzEndTable[index1];

                if (index4 == (short)-1)
                {
                    lzByteTable[index1] = (short)index2;
                }
                else
                {
                    lzOffsetTable[index4] = (short)index2;
                }
                lzEndTable[index1]    = (short)index2;
                lzOffsetTable[index2] = (short)-1;
                if (windowLen == (ushort)4096)
                {
                    info->windowPos = (ushort)(((int)windowPos + 1) % 4096);
                }
                else
                {
                    ++info->windowLen;
                }
            }
Exemplo n.º 4
0
            private static unsafe uint SearchLZFast(
                MKDS_Course_Modifier.Converters.Compression.MI_Compress.LZCompressInfo *info,
                byte *nextp,
                uint remainSize,
                ushort *offset,
                uint maxLength)
            {
                ushort num1          = 0;
                uint   num2          = 2;
                short *lzOffsetTable = info->LZOffsetTable;
                ushort windowPos     = info->windowPos;
                ushort windowLen     = info->windowLen;

                if (remainSize < 3U)
                {
                    return(0);
                }
                int index = (int)info->LZByteTable[*nextp];

                while (index != -1)
                {
                    byte *numPtr1 = index >= (int)windowPos ? nextp - (int)windowLen - (int)windowPos + index : nextp - (int)windowPos + index;
                    if ((int)numPtr1[1] != (int)nextp[1] || (int)numPtr1[2] != (int)nextp[2])
                    {
                        index = (int)lzOffsetTable[index];
                    }
                    else if (nextp - numPtr1 >= 2L)
                    {
                        uint  num3    = 3;
                        byte *numPtr2 = numPtr1 + 3;
                        byte *numPtr3 = nextp + 3;
                        while ((uint)(numPtr3 - nextp) < remainSize && (int)*numPtr3 == (int)*numPtr2)
                        {
                            ++numPtr3;
                            ++numPtr2;
                            ++num3;
                            if ((int)num3 == (int)maxLength)
                            {
                                break;
                            }
                        }
                        if (num3 > num2)
                        {
                            num2 = num3;
                            num1 = (ushort)(nextp - numPtr1);
                            if ((int)num2 == (int)maxLength || (int)num2 == (int)remainSize)
                            {
                                break;
                            }
                        }
                        index = (int)lzOffsetTable[index];
                    }
                    else
                    {
                        break;
                    }
                }
                if (num2 < 3U)
                {
                    return(0);
                }
                *offset = num1;
                return(num2);
            }