ConsoleWriter.cs 585 B

12345678910111213141516171819
  1. using System.IO;
  2. using System.Reflection;
  3. using System.Text;
  4. using HarmonyLib;
  5. namespace BepInEx.Unix
  6. {
  7. public static class ConsoleWriter
  8. {
  9. private static ConstructorInfo cStreamWriterConstructor = AccessTools.Constructor(AccessTools.TypeByName("System.IO.CStreamWriter"));
  10. public static TextWriter CreateConsoleStreamWriter(Stream stream, Encoding encoding, bool leaveOpen)
  11. {
  12. var writer = (StreamWriter)cStreamWriterConstructor.Invoke(null, new object[] { stream, encoding, leaveOpen, });
  13. writer.AutoFlush = true;
  14. return TextWriter.Synchronized(writer);
  15. }
  16. }
  17. }