Example #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();
    }
Example #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);
    }
Example #3
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();
    }
Example #4
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());
    }