Ejemplo n.º 1
0
        /// <summary>
        /// Gets the max buffer size needed for oodle compression
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public static int GetCompressedBufferSizeNeeded(int count)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var n = ((long)(count + 0x3ffff + (long)((uint)(count + 0x3ffff >> 0x3f) & 0x3ffff))
                         >> 0x12) * 0x112 + count;
                //var n  = OodleNative.GetCompressedBufferSizeNeeded((long)count);
                return((int)n);
            }

            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                try
                {
                    return(OozNative.GetCompressedBufferSizeNeeded(count));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Wrapper around Oodle Kraken Decompress. Decompresses an inputBuffer to an outputBuffer of correct size
        /// </summary>
        /// <param name="inputBuffer"></param>
        /// <param name="outputBuffer"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public static unsafe int Decompress(byte[] inputBuffer, byte[] outputBuffer)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
#pragma warning disable 162

                if (true)
                {
                    var inputHandle   = GCHandle.Alloc(inputBuffer, GCHandleType.Pinned);
                    var inputAddress  = inputHandle.AddrOfPinnedObject();
                    var outputHandle  = GCHandle.Alloc(outputBuffer, GCHandleType.Pinned);
                    var outputAddress = outputHandle.AddrOfPinnedObject();



                    var r = OodleLoadLib.OodleLZ_Decompress(inputAddress,
                                                            outputAddress,
                                                            inputBuffer.Length,
                                                            outputBuffer.Length
                                                            );

                    inputHandle.Free();
                    outputHandle.Free();

                    return(r);
                }

                return(OodleNative.OodleLZ_Decompress(
                           inputBuffer,
                           inputBuffer.Length,
                           outputBuffer,
                           outputBuffer.Length,
                           OodleNative.OodleLZ_FuzzSafe.No, OodleNative.OodleLZ_CheckCRC.No,
                           OodleNative.OodleLZ_Verbosity.None,
                           0,
                           0,
                           0,
                           0,
                           0,
                           0,
                           OodleNative.OodleLZ_Decode.Unthreaded));

#pragma warning restore 162
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(OozNative.Kraken_Decompress(inputBuffer, inputBuffer.Length, outputBuffer,
                                                   outputBuffer.Length));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="inputBuffer"></param>
 /// <param name="outputBuffer"></param>
 /// <returns></returns>
 /// <exception cref="NotImplementedException"></exception>
 public static int Decompress(byte[] inputBuffer, byte[] outputBuffer)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(OodleNative.OodleLZ_Decompress(inputBuffer, inputBuffer.Length, outputBuffer,
                                               outputBuffer.Length, OodleNative.OodleLZ_FuzzSafe.No, OodleNative.OodleLZ_CheckCRC.No,
                                               OodleNative.OodleLZ_Verbosity.None, 0, 0, 0, 0, 0, 0, OodleNative.OodleLZ_Decode.Unthreaded));
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         return(OozNative.Kraken_Decompress(inputBuffer, inputBuffer.Length, outputBuffer,
                                            outputBuffer.Length));
     }
     else
     {
         throw new NotImplementedException();
     }
 }