/// <summary> /// Creates a new object that is not owned by any other object. The specified /// |data| will be copied. /// </summary> public static CfxBinaryValue Create(byte[] data) { if(data == null || data.Length == 0) { throw new ArgumentException("Data is null or zero length", "data"); } var po = new PinnedObject(data); var retval = CfxBinaryValue.Create(po.PinnedPtr, data.Length); po.Free(); return retval; }
protected override void RemoteProcedure() { if (data == null || data.Length == 0) { throw new ArgumentException("Data is null or zero length", "data"); } var po = new PinnedObject(data); __retval = CfxApi.BinaryValue.cfx_binary_value_create(po.PinnedPtr, (UIntPtr)data.Length); po.Free(); }
/// <summary> /// Read uncompressed file contents into the specified buffer. Returns /// 0 if at the end of file, or the number of bytes read. /// Throws an exception if an error occurred. /// </summary> public int ReadFile(byte[] buffer) { if(buffer == null || buffer.Length == 0) throw new ArgumentException("Buffer can't be null or zero length.", "buffer"); var pb = new PinnedObject(buffer); var retval = CfxApi.cfx_zip_reader_read_file(NativePtr, pb.PinnedPtr, buffer.Length); pb.Free(); if(retval < 0) throw new CfxException("Failed to read from zip file"); return retval; }
protected override void ExecuteInTargetProcess(RemoteConnection connection) { var identifiersCount = CfxApi.Browser.cfx_browser_get_frame_count(@this); __retval = new long[(ulong)identifiersCount]; if (identifiersCount == UIntPtr.Zero) { return; } var retval_p = new PinnedObject(__retval); CfxApi.Browser.cfx_browser_get_frame_identifiers(@this, identifiersCount, retval_p.PinnedPtr); retval_p.Free(); }
protected override void RemoteProcedure() { var count = CfxApi.PostData.cfx_post_data_get_element_count(@this); __retval = new IntPtr[(ulong)count]; if (__retval.Length == 0) { return; } var ptrs_p = new PinnedObject(__retval); CfxApi.PostData.cfx_post_data_get_elements(@this, count, ptrs_p.PinnedPtr); ptrs_p.Free(); }
/// <summary> /// Read up to (buffer.Length - bufferOffset) bytes into |buffer|. Reading begins at /// the specified byte dataOffset. Writing begins at the /// specified byte bufferOffset. /// Returns the number of bytes read. /// </summary> public int GetData(byte[] buffer, int bufferOffset, int dataOffset) { if(buffer == null || buffer.Length == 0) { throw new ArgumentException("Buffer is null or zero length.", "buffer"); } var maxBytes = buffer.Length - bufferOffset; if(maxBytes <= 0) throw new ArgumentException("bufferOffset >= buffer.Length.", "bufferOffset"); var po = new PinnedObject(buffer); var retval = CfxApi.cfx_binary_value_get_data(NativePtr, po.PinnedPtr + bufferOffset, maxBytes, dataOffset); po.Free(); return retval; }
private static List<DemoInfo> ParseDemosImpl(ref udtParseArg parseArg, List<string> filePaths, int maxThreadCount, int inputIndexBase) { var errorCodeArray = new Int32[filePaths.Count]; var filePathArray = new IntPtr[filePaths.Count]; for(var i = 0; i < filePaths.Count; ++i) { filePathArray[i] = Marshal.StringToHGlobalAnsi(Path.GetFullPath(filePaths[i])); } var pinnedPlugIns = new PinnedObject(PlugInArray); parseArg.PlugInCount = (UInt32)PlugInArray.Length; parseArg.PlugIns = pinnedPlugIns.Address; var pinnedFilePaths = new PinnedObject(filePathArray); var pinnedErrorCodes = new PinnedObject(errorCodeArray); var multiParseArg = new udtMultiParseArg(); multiParseArg.FileCount = (UInt32)filePathArray.Length; multiParseArg.FilePaths = pinnedFilePaths.Address; multiParseArg.OutputErrorCodes = pinnedErrorCodes.Address; multiParseArg.MaxThreadCount = (UInt32)maxThreadCount; udtParserContextGroupRef contextGroup = IntPtr.Zero; var result = udtParseDemoFiles(ref contextGroup, ref parseArg, ref multiParseArg); pinnedPlugIns.Free(); pinnedFilePaths.Free(); pinnedErrorCodes.Free(); for(var i = 0; i < filePathArray.Length; ++i) { Marshal.FreeHGlobal(filePathArray[i]); } if(result != udtErrorCode.None && result != udtErrorCode.OperationCanceled) { udtDestroyContextGroup(contextGroup); App.GlobalLogError("Failed to parse demos: " + GetErrorCodeString(result)); return null; } uint contextCount = 0; if(udtGetContextCountFromGroup(contextGroup, ref contextCount) != udtErrorCode.None) { udtDestroyContextGroup(contextGroup); return null; } var infoList = new List<DemoInfo>(); for(uint i = 0; i < contextCount; ++i) { udtParserContextRef context = IntPtr.Zero; if(udtGetContextFromGroup(contextGroup, i, ref context) != udtErrorCode.None) { udtDestroyContextGroup(contextGroup); return null; } uint demoCount = 0; if(udtGetDemoCountFromContext(context, ref demoCount) != udtErrorCode.None) { udtDestroyContextGroup(contextGroup); return null; } for(uint j = 0; j < demoCount; ++j) { uint inputIdx = 0; if(udtGetDemoInputIndex(context, j, ref inputIdx) != udtErrorCode.None) { continue; } var errorCode = errorCodeArray[(int)inputIdx]; if(errorCode != (Int32)udtErrorCode.None) { if(errorCode != (Int32)udtErrorCode.Unprocessed && errorCode != (Int32)udtErrorCode.OperationCanceled) { var fileName = Path.GetFileName(filePaths[(int)inputIdx]); var errorCodeString = GetErrorCodeString((udtErrorCode)errorCode); App.GlobalLogError("Failed to parse demo file {0}: {1}", fileName, errorCodeString); } continue; } var filePath = filePaths[(int)inputIdx]; var protocol = udtGetProtocolByFilePath(filePath); var info = new DemoInfo(); info.Analyzed = true; info.InputIndex = inputIndexBase + (int)inputIdx; info.FilePath = Path.GetFullPath(filePath); info.Protocol = UDT_DLL.GetProtocolAsString(protocol); ExtractDemoInfo(context, j, ref info); infoList.Add(info); } } udtDestroyContextGroup(contextGroup); // Keep the original input order. infoList.Sort((a, b) => a.InputIndex - b.InputIndex); return infoList; }
public static bool CutDemoByTime(udtParserContextRef context, ref udtParseArg parseArg, string filePath, int startTimeSec, int endTimeSec) { if(context == IntPtr.Zero) { return false; } parseArg.PlugInCount = 0; parseArg.PlugIns = IntPtr.Zero; var cut = new udtCut(); cut.GameStateIndex = parseArg.GameStateIndex; cut.StartTimeMs = startTimeSec * 1000; cut.EndTimeMs = endTimeSec * 1000; var pinnedCut = new PinnedObject(cut); var cutInfo = new udtCutByTimeArg(); cutInfo.Cuts = pinnedCut.Address; cutInfo.CutCount = 1; var success = udtCutDemoFileByTime(context, ref parseArg, ref cutInfo, filePath) == udtErrorCode.None; pinnedCut.Free(); return success; }