public static void RVExtension(StringBuilder output, int outputSize, [MarshalAs(UnmanagedType.LPStr)] string input) { outputSize--; switch (input) { case "": return; case "debugger": Debugger.Toggle(); return; case "version": output.Append(DllEntry.GetVersion()); break; default: switch (input[0]) { case ControlCharacter.ACK: output.Append(DllEntry._outputBuffer); break; case ControlCharacter.ENQ: if (Tasks.Count == 0) { break; } try { var completedTasksIndices = new List <int>(); foreach (var taskEntry in Tasks) { if (!taskEntry.Value.IsCompleted) { continue; } try { output.Append(ControlCharacter.SOH + taskEntry.Key.ToString() + ControlCharacter.STX + taskEntry.Value.Result); } catch (Exception e) { output.Append(ControlCharacter.SOH + taskEntry.Key.ToString() + ControlCharacter.STX); if (e is AggregateException) { ((AggregateException)e).Handle(x => { output.Append(x.Message + "\n"); return(true); }); } else { output.Append(e.Message); } } Debugger.Log("Task result: " + taskEntry.Key); completedTasksIndices.Add(taskEntry.Key); } foreach (int index in completedTasksIndices) { Tasks.Remove(index); } output.Append(ControlCharacter.EOT); } catch (Exception e) { Debugger.Log(e); output.Append(e.Message); } break; default: try { _inputBuffer += input; if (_inputBuffer[_inputBuffer.Length - 1] == ControlCharacter.ETX) { output.Append(ExecuteRequest(ArmaRequest.Parse(_inputBuffer))); } else { output.Append(ControlCharacter.ACK); } } catch (Exception e) { output.Append(e.Message); } break; } break; } List <byte> outputBytes = Encoding.Default.GetBytes(output.ToString()).ToList(); if (outputBytes.Count <= outputSize) { return; } int outputSplitPosition = outputSize; while ((outputBytes[outputSplitPosition - 1] & 0xC0) == 0x80) { outputSplitPosition--; } DllEntry._outputBuffer = Encoding.Default.GetString(outputBytes.GetRange(outputSplitPosition, outputBytes.Count - outputSplitPosition).ToArray()); output = output.Remove(output.Length - DllEntry._outputBuffer.Length, DllEntry._outputBuffer.Length); }
public static void RVExtensionVersion(StringBuilder output, int outputSize) { output.Append(DllEntry.GetVersion()); }