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) : KrakenLib.Decompress(inputBuffer, outputBuffer); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { result = KrakenLib.Decompress(inputBuffer, outputBuffer); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { result = OozNative.Kraken_Decompress(inputBuffer, outputBuffer); } else { throw new NotImplementedException(); } return(result); }
public void Kraken_Compress(int level) { var path = Path.GetFullPath(Path.Combine("Resources", s_uncompressedFile)); var inbuffer = File.ReadAllBytes(path); var compressedBufferSizeNeeded = Oodle.GetCompressedBufferSizeNeeded(inbuffer.Length); var outdir = Path.Combine(Environment.CurrentDirectory, "ooz"); Directory.CreateDirectory(outdir); // oodle //IEnumerable<byte> outBuffer = new List<byte>(); //var r = Oodle.Compress(inbuffer, ref outBuffer, true, (Oodle.CompressionLevel)level); //var outpath = Path.Combine(outdir, $"{level}_oodle.kark"); //var final = outBuffer.ToArray(); //File.WriteAllBytes(outpath, final); #if _WINDOWS // kraken var outBuffer2 = new byte[compressedBufferSizeNeeded]; //var outBuffer2 = new byte[inbuffer.Length + 65536]; KrakenLib.Load(); var r2 = KrakenLib.Compress(inbuffer, outBuffer2, (int)level); var outpath2 = Path.Combine(outdir, $"{(int)level}_kraken.kark"); var final2 = outBuffer2.Take(r2).ToArray(); File.WriteAllBytes(outpath2, final2); #endif var compareFile = Path.GetFullPath(Path.Combine("Resources", $"{level}_oodle.kark")); var compareBytes = File.ReadAllBytes(compareFile); Assert.IsTrue(Enumerable.SequenceEqual(final2, compareBytes.Skip(8))); }
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(); }
public void Kraken_Decompress(int level) { var testFile = Path.GetFullPath(Path.Combine("Resources", $"{level}_oodle.kark")); var outdir = Path.Combine(Environment.CurrentDirectory, "ooz"); Directory.CreateDirectory(outdir); using var fs = new FileStream(testFile, FileMode.Open, FileAccess.Read); using var br = new BinaryReader(fs); var oodleCompression = br.ReadBytes(4); if (!oodleCompression.SequenceEqual(new byte[] { 0x4b, 0x41, 0x52, 0x4b })) { throw new NotImplementedException(); } var size = br.ReadUInt32(); var buffer = br.ReadBytes((int)fs.Length - 8); // oodle var outBuffer1 = new byte[size]; { var unpackedSize = Oodle.Decompress(buffer, outBuffer1); var outpath = Path.Combine(outdir, "oodle.txt"); File.WriteAllBytes(outpath, outBuffer1); } #if _WINDOWS // kraken var outBuffer2 = new byte[size]; { KrakenLib.Load(); long unpackedSize2 = KrakenLib.Decompress(buffer, outBuffer2); var outpath2 = Path.Combine(outdir, "kraken.txt"); File.WriteAllBytes(outpath2, outBuffer2); } Assert.IsTrue(Enumerable.SequenceEqual(outBuffer1, outBuffer2)); #endif }
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) : KrakenLib.Compress(inputBuffer, compressedBuffer, (int)level); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { result = KrakenLib.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()); }