示例#1
0
        private static void RegisterPrefabInternal(GameObject prefab, string callPath, string callMember, int callLine)
        {
            HashStruct h = new HashStruct
            {
                prefab     = prefab,
                goName     = prefab.name,
                callPath   = callPath,
                callMember = callMember,
                callLine   = callLine
            };

            thingsToHash.Add(h);
            SetupRegistrationEvent();
        }
示例#2
0
        //[DllImport("API/LZFuncs", CallingConvention = CallingConvention.Cdecl)]
        //internal static extern int LZDecomp([Out] byte[] outputBuffer, [In] byte[] compressedBuffer, uint compBufferLength);

        //[DllImport("API/LZFuncs", CharSet = CharSet.None, ExactSpelling = false)]
        //internal static extern int LZCompress([Out] byte[] compDataBuff, [In] byte[] uncompDataBuff, uint uncompDataSize);


        public static int LZDecomp(out byte[] outputBuffer, byte[] compressedBuffer, uint outputLength, uint compBufferLength)
        {
            BASE_BITS     = 9;
            MAX_BIT_INDEX = (1 << BASE_BITS);

            //INIT
            //LZSrcBufEnd = compressedBuffer[compBufferLength - 3];

            LZCodeMask  = (uint)MAX_BIT_INDEX - 1;
            LZMaxIndex  = (uint)MAX_BIT_INDEX; //max index for 9 bits == 512
            LZFreeIndex = (uint)HASH_FREE;     //set index to 258

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

            uint       code, c, t, next_code = (uint)HASH_FREE;
            int        bits = 8;
            HashStruct aux;

            clearDictionary();

            int shift    = 0;
            int shiftInc = 1;

            for (int i = 0; i < compBufferLength; i++)
            {
                if (shift > 7)
                {
                    shift -= 8;
                    continue;
                }


                code = ReadCode(compressedBuffer, i, bits, shift);

                shift += shiftInc;



                if (code == HASH_EOF)
                {
                    break;
                }
                if (code == HASH_CLEAR)
                {
                    bits     = 8;
                    shiftInc = 1;
                    clearDictionary();
                    continue;
                }

                if (code >= LZFreeIndex)
                {
                    throw new Exception("Bad sequence.");
                }

                HashStruct next = new HashStruct();
                next.prev = c = code;

                if (!dictionary.ContainsKey(LZFreeIndex))
                {
                    dictionary.Add(LZFreeIndex, next);
                    while (c > 255)
                    {
                        t             = dictionary[c].prev;
                        aux           = dictionary[t];
                        aux.back      = c;
                        dictionary[t] = aux;
                        c             = t;
                    }
                    dictionary[LZFreeIndex] = next;
                }
                if (dictionary.ContainsKey(LZFreeIndex - 1))
                {
                    aux   = dictionary[LZFreeIndex - 1];
                    aux.c = (byte)c;
                    dictionary[LZFreeIndex - 1] = aux;

                    LZFreeIndex++;
                }


                while (dictionary[c].back > 0)
                {
                    // write_out(d[c].c);
                    uncompressed.Add((byte)dictionary[c].c);
                    t             = dictionary[c].back;
                    aux           = dictionary[c];
                    aux.back      = 0;
                    dictionary[c] = aux;
                    c             = t;
                }
                uncompressed.Add((byte)dictionary[c].c);

                if (LZFreeIndex > LZMaxIndex)
                {
                    if (bits == 11)
                    {
                        continue;
                    }
                    else
                    {
                        MAX_BIT_INDEX *= 2;
                        bits++;
                        LZCodeMask = (uint)MAX_BIT_INDEX - 1;
                        LZMaxIndex = (uint)MAX_BIT_INDEX;
                        shiftInc++;
                    }
                }
            }

            outputBuffer = new byte[outputLength];

            Array.Copy(uncompressed.ToArray(), outputBuffer, uncompressed.Count);
            //      outputBuffer = uncompressed.ToArray();
            return(uncompressed.Count);
        }