Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.9 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
  1. using System;
  2. using System.IO;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using UnityEngine;
  6. namespace Photon.Bolt
  7. {
  8. public static class ConsoleWriter
  9. {
  10. #if UNITY_STANDALONE_WIN
  11. static class PInvoke
  12. {
  13. public const int STD_OUTPUT_HANDLE = -11;
  14. [DllImport("kernel32.dll", SetLastError = true)]
  15. public static extern bool AttachConsole(uint dwProcessId);
  16. [DllImport("kernel32.dll", SetLastError = true)]
  17. public static extern bool AllocConsole();
  18. [DllImport("kernel32.dll", SetLastError = true)]
  19. public static extern bool FreeConsole();
  20. [DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  21. public static extern IntPtr GetStdHandle(int nStdHandle);
  22. [DllImport("kernel32.dll")]
  23. public static extern bool SetConsoleTitle(string lpConsoleTitle);
  24. }
  25. static TextWriter realOut;
  26. #endif
  27. public static void Open()
  28. {
  29. #if UNITY_STANDALONE_WIN
  30. if (realOut == null)
  31. {
  32. realOut = Console.Out;
  33. }
  34. var hasConsole = PInvoke.AttachConsole(0x0ffffffff);
  35. if (hasConsole == false)
  36. {
  37. PInvoke.AllocConsole();
  38. }
  39. try
  40. {
  41. // grab handle ptr
  42. var outHandlePtr = PInvoke.GetStdHandle(PInvoke.STD_OUTPUT_HANDLE);
  43. // we can then create a filestream from this handle
  44. #pragma warning disable 0618
  45. var fileStream = new FileStream(outHandlePtr, FileAccess.Write);
  46. #pragma warning restore 0618
  47. // and then create a new stream writer (using ASCII)
  48. var stdOut = new StreamWriter(fileStream, Encoding.ASCII)
  49. {
  50. AutoFlush = true
  51. };
  52. // and force unity to use this
  53. Console.SetOut(stdOut);
  54. }
  55. catch (Exception e)
  56. {
  57. Debug.Log(e);
  58. }
  59. #endif
  60. }
  61. public static void Close()
  62. {
  63. #if UNITY_STANDALONE_WIN
  64. PInvoke.FreeConsole();
  65. Console.SetOut(realOut);
  66. realOut = null;
  67. #endif
  68. }
  69. }
  70. }