Skip to content

Instantly share code, notes, and snippets.

@Scobalula
Created October 8, 2018 09:29
Show Gist options
  • Save Scobalula/37229307de57de685d16ec621d5aceb5 to your computer and use it in GitHub Desktop.
Save Scobalula/37229307de57de685d16ec621d5aceb5 to your computer and use it in GitHub Desktop.
Oodle Decompression in C# - Requires Oodle DLL
// ------------------------------------------------------------------------
// PhilLibX - My Utility Library
// Copyright(c) 2018 Philip/Scobalula
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ------------------------------------------------------------------------
// File: Compression/Oodle.cs
// Author: Philip/Scobalula
// Description: Basic Oodle64 Compression Wrapper, currently supports decompression.
// Credits:
// - DTZxPorter - SirenLib (for OodleLZ_Decompress parameters)
// Other notes:
// - Tested on Oodle V5 and V6
using System.Runtime.InteropServices;
namespace PhilLibX.Compression
{
/// <summary>
/// Oodle Compression Utils
/// </summary>
public class Oodle
{
/// <summary>
/// Oodle Library Path
/// </summary>
private const string OodleLibraryPath = "oo2core_6_win64";
/// <summary>
/// Oodle64 Decompression Method
/// </summary>
[DllImport(OodleLibraryPath, CallingConvention = CallingConvention.Cdecl)]
private static extern long OodleLZ_Decompress(byte[] buffer, long bufferSize, byte[] result, long outputBufferSize, int a, int b, int c, long d, long e, long f, long g, long h, long i, int ThreadModule);
/// <summary>
/// Decompresses a byte array of Oodle Compressed Data (Requires Oodle DLL)
/// </summary>
/// <param name="input">Input Compressed Data</param>
/// <param name="decompressedLength">Decompressed Size</param>
/// <returns>Resulting Array if success, otherwise null.</returns>
public static byte[] Decompress(byte[] input, long decompressedLength)
{
// Resulting decompressed Data
byte[] result = new byte[decompressedLength];
// Decode the data (other parameters such as callbacks not required)
long decodedSize = OodleLZ_Decompress(input, input.Length, result, decompressedLength, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3);
// Check did we fail
if (decodedSize == 0) return null;
// Return Result
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment