示例#1
0
    public const uint KARK = 1263681867; // 0x4b, 0x41, 0x52, 0x4b

    public static bool Load()
    {
        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            // try get oodle dll from game
            if (TryCopyOodleLib())
            {
                var result = OodleLib.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oo2ext_7_win64.dll"));
                if (result)
                {
                    CompressionSettings.Get().CompressionLevel = CompressionLevel.Optimal2;
                    CompressionSettings.Get().UseOodle         = true;
                    return(true);
                }
            }

            return(true);
        }

        if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        {
            return(true);
        }

        if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
        {
            return(true);
        }
        throw new NotImplementedException();
    }
示例#2
0
    public static long Decompress(byte[] inputBuffer, byte[] outputBuffer)
    {
        var result = 0;

        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            result = CompressionSettings.Get().UseOodle
                ? OodleLib.OodleLZ_Decompress(inputBuffer, outputBuffer)
                : KrakenNative.Decompress(inputBuffer, outputBuffer);
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        {
            result = KrakenNative.Decompress(inputBuffer, outputBuffer);
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
        {
            result = OozNative.Kraken_Decompress(inputBuffer, outputBuffer);
        }
        else
        {
            throw new NotImplementedException();
        }

        return(result);
    }
示例#3
0
    public static Status CompressBuffer(byte[] rawBuf, out byte[] compBuf)
    {
        if (rawBuf.Length > 256)
        {
            //var compressedBufferSizeNeeded = GetCompressedBufferSizeNeeded(rawBuf.Length);
            //var compressedBuffer = new byte[compressedBufferSizeNeeded];
            IEnumerable <byte> compressedBuffer = new List <byte>();

            var compressedSize = Oodle.Compress(rawBuf, ref compressedBuffer, false, CompressionSettings.Get().CompressionLevel);

            var outArray = new byte[compressedSize + 8];

            Array.Copy(BitConverter.GetBytes(KARK), 0, outArray, 0, 4);
            Array.Copy(BitConverter.GetBytes(rawBuf.Length), 0, outArray, 4, 4);
            Array.Copy(compressedBuffer.ToArray(), 0, outArray, 8, compressedSize);

            if (rawBuf.Length > outArray.Length)
            {
                compBuf = outArray;
                return(Status.Compressed);
            }
        }

        compBuf = rawBuf;
        return(Status.Uncompressed);
    }
示例#4
0
    public const uint KARK = 1263681867; // 0x4b, 0x41, 0x52, 0x4b

    public static bool Load()
    {
        // try get oodle dll from game
        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            var result = false;
            if (TryCopyOodleLib())
            {
                result = OodleLib.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oo2ext_7_win64.dll"));
                if (result)
                {
                    CompressionSettings.Get().CompressionLevel = CompressionLevel.Optimal2;
                    CompressionSettings.Get().UseOodle         = true;
                    return(true);
                }
            }

            // try load Kraken
            result = KrakenLib.Load();
            if (result)
            {
                return(true);
            }

            Log.Error("Could not automatically find oo2ext_7_win64.dll. " +
                      "Please manually copy and paste the DLL found in <gamedir>\\Cyberpunk 2077\\bin\\x64\\oo2ext_7_win64.dll into this folder: " +
                      $"{AppDomain.CurrentDomain.BaseDirectory}.");
            return(false);
        }

        if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        {
            return(KrakenLib.Load());
        }

        if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
        {
        }
        throw new NotImplementedException();
    }
示例#5
0
    public static int Compress(byte[] inputBuffer, ref IEnumerable <byte> outputBuffer, bool useRedHeader,
                               CompressionLevel level = CompressionLevel.Normal, Compressor compressor = Compressor.Kraken)
    {
        if (inputBuffer == null)
        {
            throw new ArgumentNullException(nameof(inputBuffer));
        }
        var inputCount = inputBuffer.Length;

        if (inputCount <= 0 || inputCount > inputBuffer.Length)
        {
            throw new ArgumentOutOfRangeException(nameof(inputCount));
        }
        if (outputBuffer == null)
        {
            throw new ArgumentNullException(nameof(outputBuffer));
        }

        var result = 0;
        var compressedBufferSizeNeeded = Oodle.GetCompressedBufferSizeNeeded(inputCount);
        var compressedBuffer           = new byte[compressedBufferSizeNeeded];

        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            result = CompressionSettings.Get().UseOodle
                ? OodleLib.OodleLZ_Compress(inputBuffer, compressedBuffer, compressor, level)
                : KrakenNative.Compress(inputBuffer, compressedBuffer, (int)level);
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        {
            result = KrakenNative.Compress(inputBuffer, compressedBuffer, (int)level);
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
        {
            result = OozNative.Kraken_Compress(inputBuffer, compressedBuffer, (int)level);
        }
        else
        {
            throw new NotImplementedException();
        }


        if (result == 0 || inputCount <= (result + 8))
        {
            outputBuffer = inputBuffer;
            return(outputBuffer.Count());
        }

        if (useRedHeader)
        {
            // write KARK header
            var writelist = new List <byte>()
            {
                0x4B, 0x41, 0x52, 0x4B          //KARK, TODO: make this dependent on the compression algo
            };
            // write size
            writelist.AddRange(BitConverter.GetBytes(inputCount));
            // write compressed data
            writelist.AddRange(compressedBuffer.Take(result));

            outputBuffer = writelist;
        }
        else
        {
            outputBuffer = compressedBuffer.Take(result);
        }

        return(outputBuffer.Count());
    }