Example #1
0
        protected override void Parse(ref BitStreamReader bsr)
        {
            Info = new List <MapCompletedInfo>();
            Span <byte> bytes = stackalloc byte[2 * MaxPortal2CoopBranches * MaxPortal2CoopLevelsPerBranch / 8];

            bsr.ReadToSpan(bytes);
            int current = 0;
            int mask    = 0x01;

            for (int player = 0; player < 2; player++)
            {
                for (int branch = 0; branch < MaxPortal2CoopBranches; branch++)
                {
                    for (int level = 0; level < MaxPortal2CoopLevelsPerBranch; level++)
                    {
                        if ((bytes[current] & mask) != 0)
                        {
                            Info.Add(new MapCompletedInfo {
                                Player = player, Branch = branch, Level = level
                            });
                        }
                        mask <<= 1;
                        if (mask >= 0x0100)
                        {
                            current++;
                            mask = 0x01;
                        }
                    }
                }
            }
        }
        public static unsafe byte[] Decompress(ref BitStreamReader bsr, int compSize)
        {
            uint type       = bsr.ReadUInt();
            int  decompSize = bsr.ReadSInt();

            switch (type)
            {
            case LZSS_ID:
                Span <byte> dataIn = compSize < 100000 ? stackalloc byte[compSize] : new byte[compSize];
                bsr.ReadToSpan(dataIn);
                byte[] arrOut = new byte[decompSize];

                fixed(byte *pDataIn = dataIn)
                fixed(byte *pDataOut = arrOut)
                DecompressLZSS(pDataIn, pDataOut);

                return(arrOut);

            case SNAPPY_ID:
                Debug.Assert(false);
                throw new NotImplementedException("snappy decompression not implemented");

            default:
                throw new InvalidOperationException("unknown compression method");
            }
        }