This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added oodle for asset registry compression
- Loading branch information
1 parent
6a6e195
commit 2addfb3
Showing
20 changed files
with
344 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bin/ | ||
obj/ | ||
Binaries/ | ||
Binaries/ | ||
.vs |
Binary file not shown.
Binary file removed
BIN
-1.4 MB
.vs/ProSwapperLobby/FileContentIndex/153bc937-b4bf-43ef-8dca-1a3a1579d11e.vsidx
Binary file not shown.
Binary file removed
BIN
-102 KB
.vs/ProSwapperLobby/FileContentIndex/8caea3d1-0b75-41e0-9b73-cf559ee16848.vsidx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
using Ionic.Zlib; | ||
using CUE4Parse.Compression; | ||
using Ionic.Zlib; | ||
|
||
namespace ProSwapperLobby.SwapperLogic | ||
{ | ||
public class AssetRegistryCompression | ||
{ | ||
public static byte[] Decompress(byte[] input)=> ZlibStream.UncompressBuffer(input); | ||
public static byte[] Compress(byte[] input, CompressionMethod compressionMethod) | ||
{ | ||
switch (compressionMethod) | ||
{ | ||
case CompressionMethod.Zlib: | ||
return ZlibStream.CompressBuffer(input); | ||
case CompressionMethod.Oodle: | ||
if (!File.Exists(OodleImports.OodleDll)) | ||
{ | ||
using (HttpClient client = new HttpClient()) | ||
{ | ||
byte[] dll = client.GetByteArrayAsync($"https://cdn.proswapper.xyz/{OodleImports.OodleDll}").Result; | ||
File.WriteAllBytes(OodleImports.OodleDll, dll); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Compresses a byte array with CompressionLevel.BestCompression | ||
/// </summary> | ||
/// <param name="input"></param> | ||
/// <returns></returns> | ||
public static byte[] Compress(byte[] input) => ZlibStream.CompressBuffer(input); | ||
|
||
return Oodle.Compress(input); | ||
default: | ||
return null; | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
//Credit to Tamely | ||
//https://github.com/Tamely/Oodle-Tools/blob/main/OodleTools/Oodle.cs | ||
|
||
|
||
using static ProSwapperLobby.SwapperLogic.OodleImports; | ||
|
||
namespace ProSwapperLobby.SwapperLogic | ||
{ | ||
public class Oodle : Imports | ||
{ | ||
/// <summary> | ||
/// Attempts to compress a byte[] using Oodle. | ||
/// </summary> | ||
/// <param name="data">byte[]: The decompressed data you want to compress</param> | ||
/// <param name="compressedData">out byte[]: The compressed data Oodle returns</param> | ||
/// <returns>bool: True if the compression was a success, false if it was a failure</returns> | ||
public static bool TryCompress(byte[] data, out byte[] compressedData) | ||
{ | ||
try | ||
{ | ||
compressedData = Compress(data); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
compressedData = new byte[] { }; | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Compresses a byte[] using Oodle. | ||
/// </summary> | ||
/// <param name="data">byte[]: The decompressed data you want to compress</param> | ||
/// <returns>byte[]: The compressed data</returns> | ||
public static byte[] Compress(byte[] data) | ||
{ | ||
var maxSize = GetCompressedBounds((uint)data.Length); | ||
var compressedData = new byte[maxSize]; | ||
|
||
var compressedSize = Compress(data, (uint)data.Length, ref compressedData, | ||
maxSize, OodleFormat.Kraken, OodleCompressionLevel.Optimal5); | ||
|
||
byte[] result = new byte[compressedSize]; | ||
Buffer.BlockCopy(compressedData, 0, result, 0, (int)compressedSize); | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to decompress a byte[] using Oodle. | ||
/// </summary> | ||
/// <param name="data">byte[]: The compressed data you want to decompress</param> | ||
/// <param name="decompressedSize">int: The expected size of the decompressed data.</param> | ||
/// <param name="decompressedData">out byte[]: The decompressed data</param> | ||
/// <returns>bool: True if the decompression was a success, false if it was a failure</returns> | ||
public static bool TryDecompress(byte[] data, int decompressedSize, out byte[] decompressedData) | ||
{ | ||
try | ||
{ | ||
decompressedData = Decompress(data, decompressedSize); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
decompressedData = new byte[] { }; | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Decompresses a byte[] using Oodle. | ||
/// </summary> | ||
/// <param name="data">byte[]: The compressed data</param> | ||
/// <param name="decompressedSize">int: The expected size of the decompressed data</param> | ||
/// <returns>byte[]: The decompressed data</returns> | ||
/// <exception cref="Exception">Gets thrown when "decompressedSize" doesn't match with what Oodle returns</exception> | ||
public static byte[] Decompress(byte[] data, int decompressedSize) | ||
{ | ||
byte[] decompressedData = new byte[decompressedSize]; | ||
var verificationSize = Decompress(data, (uint)data.Length, | ||
ref decompressedData, (uint)decompressedSize); | ||
|
||
if (verificationSize != decompressedSize) | ||
throw new Exception("Decompression failed. Verification size does not match given size."); | ||
|
||
return decompressedData; | ||
} | ||
|
||
private static uint Compress(byte[] buffer, uint bufferSize, ref byte[] OutputBuffer, uint OutputBufferSize, | ||
OodleFormat format, OodleCompressionLevel level) | ||
{ | ||
if (buffer.Length > 0 && bufferSize > 0 && OutputBuffer.Length > 0 && OutputBufferSize > 0) | ||
return (uint)OodleLZ_Compress(format, buffer, bufferSize, OutputBuffer, level, 0, 0, 0); | ||
|
||
return 0; | ||
} | ||
|
||
private static uint Decompress(byte[] buffer, uint bufferSize, ref byte[] outputBuffer, uint outputBufferSize) | ||
{ | ||
if (buffer.Length > 0 && bufferSize > 0 && outputBuffer.Length > 0 && outputBufferSize > 0) | ||
return (uint)OodleLZ_Decompress(buffer, bufferSize, outputBuffer, outputBufferSize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | ||
|
||
return 0; | ||
} | ||
} | ||
} |
Oops, something went wrong.