private static void WriteConsoleOutputPlain(SafeFileHandle consoleHandle, Coordinates origin, BufferCell[,] contents) { int length = contents.GetLength(0); int num = contents.GetLength(1); if (length <= 0 || num <= 0) { ConsoleControl.tracer.WriteLine("contents passed in has 0 rows and columns", new object[0]); return; } else { int num1 = 0x800; ConsoleControl.COORD cOORD; cOORD.X = 0; cOORD.Y = 0; ConsoleControl.SMALL_RECT y; y.Top = (short)origin.Y; int y1 = length; while (y1 > 0) { y.Left = (short)origin.X; ConsoleControl.COORD cOORD1; cOORD1.X = (short)Math.Min(num, num1); cOORD1.Y = (short)Math.Min(y1, num1 / cOORD1.X); y.Bottom = (short)(y.Top + cOORD1.Y - 1); int lowerBound = length - y1 + contents.GetLowerBound(0); int x = num; while (x > 0) { y.Right = (short)(y.Left + cOORD1.X - 1); int lowerBound1 = num - x + contents.GetLowerBound(1); ConsoleControl.CHAR_INFO[] character = new ConsoleControl.CHAR_INFO[cOORD1.Y * cOORD1.X]; int num2 = lowerBound; int num3 = 0; while (num2 < cOORD1.Y + lowerBound) { int num4 = lowerBound1; while (num4 < cOORD1.X + lowerBound1) { character[num3].UnicodeChar = contents[num2, num4].Character; character[num3].Attributes = ConsoleControl.ColorToWORD(contents[num2, num4].ForegroundColor, contents[num2, num4].BackgroundColor); num4++; num3++; } num2++; } bool flag = ConsoleControl.NativeMethods.WriteConsoleOutput(consoleHandle.DangerousGetHandle(), character, cOORD1, cOORD, ref y); if (flag) { x = x - cOORD1.X; y.Left = (short)(y.Left + cOORD1.X); cOORD1.X = (short)Math.Min(x, num1); } else { if (num1 >= 2) { num1 = num1 / 2; if (num != x) { cOORD1.X = (short)Math.Min(x, num1); } else { cOORD1.Y = 0; break; } } else { int lastWin32Error = Marshal.GetLastWin32Error(); HostException hostException = ConsoleControl.CreateHostException(lastWin32Error, "WriteConsoleOutput", ErrorCategory.WriteError, ConsoleControlStrings.WriteConsoleOutputExceptionTemplate); throw hostException; } } } y1 = y1 - cOORD1.Y; y.Top = (short)(y.Top + cOORD1.Y); } return; } }
private static void ReadConsoleOutputPlain(SafeFileHandle consoleHandle, Coordinates origin, Rectangle contentsRegion, ref BufferCell[,] contents) { ConsoleColor consoleColor = ConsoleColor.Black; ConsoleColor consoleColor1 = ConsoleColor.Black; int bottom = contentsRegion.Bottom - contentsRegion.Top + 1; int right = contentsRegion.Right - contentsRegion.Left + 1; if (bottom <= 0 || right <= 0) { ConsoleControl.tracer.WriteLine("invalid contents region", new object[0]); return; } else { int num = 0x800; ConsoleControl.COORD cOORD; cOORD.X = 0; cOORD.Y = 0; ConsoleControl.SMALL_RECT y; y.Top = (short)origin.Y; int y1 = bottom; while (y1 > 0) { y.Left = (short)origin.X; ConsoleControl.COORD cOORD1; cOORD1.X = (short)Math.Min(right, num); cOORD1.Y = (short)Math.Min(y1, num / cOORD1.X); y.Bottom = (short)(y.Top + cOORD1.Y - 1); int top = bottom - y1 + contentsRegion.Top; int x = right; while (x > 0) { y.Right = (short)(y.Left + cOORD1.X - 1); ConsoleControl.CHAR_INFO[] cHARINFOArray = new ConsoleControl.CHAR_INFO[cOORD1.Y * cOORD1.X]; bool flag = ConsoleControl.NativeMethods.ReadConsoleOutput(consoleHandle.DangerousGetHandle(), cHARINFOArray, cOORD1, cOORD, ref y); if (flag) { int left = right - x + contentsRegion.Left; int num1 = 0; for (int i = top; i < cOORD1.Y + top; i++) { int num2 = left; while (num2 < cOORD1.X + left) { contents[i, num2].Character = Convert.ToChar(cHARINFOArray[num1].UnicodeChar); ConsoleControl.WORDToColor(cHARINFOArray[num1].Attributes, out consoleColor, out consoleColor1); contents[i, num2].ForegroundColor = consoleColor; contents[i, num2].BackgroundColor = consoleColor1; num2++; num1++; } } x = x - cOORD1.X; y.Left = (short)(y.Left + cOORD1.X); cOORD1.X = (short)Math.Min(x, num); } else { if (num >= 2) { num = num / 2; if (right != x) { cOORD1.X = (short)Math.Min(x, num); } else { cOORD1.Y = 0; break; } } else { int lastWin32Error = Marshal.GetLastWin32Error(); HostException hostException = ConsoleControl.CreateHostException(lastWin32Error, "ReadConsoleOutput", ErrorCategory.ReadError, ConsoleControlStrings.ReadConsoleOutputExceptionTemplate); throw hostException; } } } y1 = y1 - cOORD1.Y; y.Top = (short)(y.Top + cOORD1.Y); } int lowerBound = contents.GetLowerBound(0); int upperBound = contents.GetUpperBound(0); int lowerBound1 = contents.GetLowerBound(1); int upperBound1 = contents.GetUpperBound(1); ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO consoleScreenBufferInfo = ConsoleControl.GetConsoleScreenBufferInfo(consoleHandle); ConsoleColor consoleColor2 = ConsoleColor.Black; ConsoleColor consoleColor3 = ConsoleColor.Black; ConsoleControl.WORDToColor(consoleScreenBufferInfo.Attributes, out consoleColor2, out consoleColor3); while (lowerBound <= upperBound) { int right1 = lowerBound1; while (true) { if (contentsRegion.Top <= lowerBound && lowerBound <= contentsRegion.Bottom && contentsRegion.Left <= right1 && right1 <= contentsRegion.Right) { right1 = contentsRegion.Right + 1; } if (right1 > upperBound1) { break; } contents[lowerBound, right1].Character = ' '; contents[lowerBound, right1].ForegroundColor = consoleColor2; contents[lowerBound, right1].BackgroundColor = consoleColor3; right1++; } lowerBound++; } return; } }
private static void WriteConsoleOutputCJK(SafeFileHandle consoleHandle, Coordinates origin, Rectangle contentsRegion, BufferCell[,] contents, ConsoleControl.BufferCellArrayRowType rowType) { bool flag; int bottom = contentsRegion.Bottom - contentsRegion.Top + 1; int right = contentsRegion.Right - contentsRegion.Left + 1; ConsoleControl.CONSOLE_FONT_INFO_EX consoleFontInfo = ConsoleControl.GetConsoleFontInfo(consoleHandle); int fontFamily = consoleFontInfo.FontFamily & 6; bool flag1 = (fontFamily & 4) == 4; int num = 0x800; ConsoleControl.COORD cOORD; cOORD.X = 0; cOORD.Y = 0; ConsoleControl.SMALL_RECT y; y.Top = (short)origin.Y; int y1 = bottom; while (y1 > 0) { y.Left = (short)origin.X; ConsoleControl.COORD x; x.X = (short)Math.Min(right, num); x.Y = (short)Math.Min(y1, num / x.X); y.Bottom = (short)(y.Top + x.Y - 1); int top = bottom - y1 + contentsRegion.Top; int x1 = right; while (x1 > 0) { y.Right = (short)(y.Left + x.X - 1); int left = right - x1 + contentsRegion.Left; if (x1 > x.X && contents[top, left + x.X - 1].BufferCellType == BufferCellType.Leading) { x.X = (short)(x.X - 1); y.Right = (short)(y.Right - 1); } ConsoleControl.CHAR_INFO[] character = new ConsoleControl.CHAR_INFO[x.Y * x.X]; int num1 = 0; bool flag2 = false; BufferCell bufferCell = new BufferCell(); for (int i = top; i < x.Y + top; i++) { int num2 = left; while (num2 < x.X + left) { if (contents[i, num2].BufferCellType != BufferCellType.Complete) { if (contents[i, num2].BufferCellType != BufferCellType.Leading) { if (contents[i, num2].BufferCellType == BufferCellType.Trailing) { if (!flag2 || !flag1) { num1--; } else { character[num1].UnicodeChar = bufferCell.Character; character[num1].Attributes = (ushort)(ConsoleControl.ColorToWORD(contents[i, num2].ForegroundColor, contents[i, num2].BackgroundColor) | 0x200); } flag2 = false; } } else { character[num1].UnicodeChar = contents[i, num2].Character; character[num1].Attributes = (ushort)(ConsoleControl.ColorToWORD(contents[i, num2].ForegroundColor, contents[i, num2].BackgroundColor) | 0x100); flag2 = true; bufferCell = contents[i, num2]; } } else { character[num1].UnicodeChar = contents[i, num2].Character; character[num1].Attributes = ConsoleControl.ColorToWORD(contents[i, num2].ForegroundColor, contents[i, num2].BackgroundColor); flag2 = false; } num2++; num1++; } } if ((rowType & ConsoleControl.BufferCellArrayRowType.RightLeading) == 0 || x1 != x.X) { flag = ConsoleControl.NativeMethods.WriteConsoleOutput(consoleHandle.DangerousGetHandle(), character, x, cOORD, ref y); } else { ConsoleControl.COORD cOORD1 = x; cOORD1.X = (short)(cOORD1.X + 1); ConsoleControl.SMALL_RECT sMALLRECT = y; sMALLRECT.Right = (short)(sMALLRECT.Right + 1); flag = ConsoleControl.NativeMethods.WriteConsoleOutput(consoleHandle.DangerousGetHandle(), character, cOORD1, cOORD, ref sMALLRECT); } if (flag) { x1 = x1 - x.X; y.Left = (short)(y.Left + x.X); x.X = (short)Math.Min(x1, num); } else { if (num >= 2) { num = num / 2; if (right != x1) { x.X = (short)Math.Min(x1, num); } else { x.Y = 0; break; } } else { int lastWin32Error = Marshal.GetLastWin32Error(); HostException hostException = ConsoleControl.CreateHostException(lastWin32Error, "WriteConsoleOutput", ErrorCategory.WriteError, ConsoleControlStrings.WriteConsoleOutputExceptionTemplate); throw hostException; } } } y1 = y1 - x.Y; y.Top = (short)(y.Top + x.Y); } }
private static bool ReadConsoleOutputCJKSmall(SafeFileHandle consoleHandle, uint codePage, Coordinates origin, Rectangle contentsRegion, ref BufferCell[,] contents) { ConsoleColor consoleColor = ConsoleColor.Black; ConsoleColor consoleColor1 = ConsoleColor.Black; ConsoleControl.COORD right; right.X = (short)(contentsRegion.Right - contentsRegion.Left + 1); right.Y = (short)(contentsRegion.Bottom - contentsRegion.Top + 1); ConsoleControl.COORD cOORD; cOORD.X = 0; cOORD.Y = 0; ConsoleControl.CHAR_INFO[] cHARINFOArray = new ConsoleControl.CHAR_INFO[right.X * right.Y]; ConsoleControl.SMALL_RECT x; x.Left = (short)origin.X; x.Top = (short)origin.Y; x.Right = (short)(origin.X + right.X - 1); x.Bottom = (short)(origin.Y + right.Y - 1); bool flag = ConsoleControl.NativeMethods.ReadConsoleOutput(consoleHandle.DangerousGetHandle(), cHARINFOArray, right, cOORD, ref x); if (flag) { int num = 0; for (int i = contentsRegion.Top; i <= contentsRegion.Bottom; i++) { int left = contentsRegion.Left; while (left <= contentsRegion.Right) { contents[i, left].Character = Convert.ToChar(cHARINFOArray[num].UnicodeChar); ConsoleControl.WORDToColor(cHARINFOArray[num].Attributes, out consoleColor, out consoleColor1); contents[i, left].ForegroundColor = consoleColor; contents[i, left].BackgroundColor = consoleColor1; if ((cHARINFOArray[num].Attributes & 0x100) != 0x100) { if ((cHARINFOArray[num].Attributes & 0x200) != 0x200) { int num1 = ConsoleControl.LengthInBufferCells(contents[i, left].Character); if (num1 != 2) { contents[i, left].BufferCellType = BufferCellType.Complete; } else { contents[i, left].BufferCellType = BufferCellType.Leading; left++; contents[i, left].Character = '\0'; contents[i, left].ForegroundColor = consoleColor; contents[i, left].BackgroundColor = consoleColor1; contents[i, left].BufferCellType = BufferCellType.Trailing; } } else { contents[i, left].Character = '\0'; contents[i, left].BufferCellType = BufferCellType.Trailing; } } else { contents[i, left].BufferCellType = BufferCellType.Leading; } left++; num++; } } return true; } else { return false; } }