/// <summary> /// Reads data asynchronously from the game's allocated save file into a buffer, starting at a given offset and up to a /// given length. /// </summary> /// <param name="name"></param> /// <param name="offset"></param> /// <param name="length"></param> /// <param name="callback"></param> public void ReadAsyncPartial(string name, ulong offset, ulong length, ReadAsyncPartialHandler callback) { GCHandle wrapped = GCHandle.Alloc(callback); Methods.ReadAsyncPartial(methodsPtr, name, offset, length, GCHandle.ToIntPtr(wrapped), ReadAsyncPartialCallbackImpl); }
private static void ReadAsyncPartialCallbackImpl(IntPtr ptr, Result result, IntPtr dataPtr, int dataLen) { GCHandle h = GCHandle.FromIntPtr(ptr); ReadAsyncPartialHandler callback = (ReadAsyncPartialHandler)h.Target; h.Free(); byte[] data = new byte[dataLen]; Marshal.Copy(dataPtr, data, 0, dataLen); callback(result, data); }