using JDC; using System; using System.Runtime.InteropServices; public class JDCZlibWrapper : Singleton { private object _lock = new object(); private JDCZlibWrapper() { JDCZlibWrapper.JDCZlibInitialize(); } [DllImport("JDCZlibForUnity")] private static extern void JDCZlibInitialize(); [DllImport("JDCZlibForUnity")] private static extern bool JDCZlibCompress(string source, ref long resultAddress, ref long resultSize); [DllImport("JDCZlibForUnity")] private static extern IntPtr JDCZlibDeCompress([MarshalAs(UnmanagedType.LPArray)] byte[] source, int length); public int doCompressOnBytes(string source, ref byte[] buffer, int bufferIdx = 0) { object @lock = this._lock; int result; lock (@lock) { if (buffer == null) { buffer = BufferPool.GetBuffer((long)source.Length); } long value = 0L; long num = 0L; bool flag = JDCZlibWrapper.JDCZlibCompress(source, ref value, ref num); if (flag) { int num2 = bufferIdx + (int)num; BufferPool.EnsureNewSize(ref buffer, (long)num2, (long)bufferIdx, false); IntPtr source2 = new IntPtr(value); Marshal.Copy(source2, buffer, bufferIdx, (int)num); result = (int)num; } else { result = 0; } } return result; } public byte[] doCompress(string source) { object @lock = this._lock; byte[] result; lock (@lock) { long value = 0L; long num = 0L; bool flag = JDCZlibWrapper.JDCZlibCompress(source, ref value, ref num); if (flag) { IntPtr source2 = new IntPtr(value); byte[] array = new byte[num]; Marshal.Copy(source2, array, 0, (int)num); result = array; } else { result = null; } } return result; } public string doDeCompress(byte[] source) { object @lock = this._lock; string result; lock (@lock) { IntPtr ptr = JDCZlibWrapper.JDCZlibDeCompress(source, source.Length); result = Marshal.PtrToStringAnsi(ptr); } return result; } public string doDeCompress(byte[] source, int length) { object @lock = this._lock; string result; lock (@lock) { IntPtr ptr = JDCZlibWrapper.JDCZlibDeCompress(source, length); result = Marshal.PtrToStringAnsi(ptr); } return result; } public string UnzipFile(string zipFilePath, string targetFolder) { object @lock = this._lock; string empty; lock (@lock) { empty = string.Empty; } return empty; } }