Decompiled source of ANSI Mod v2.0.1

BepInEx\patchers\ANSI Mod.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using AnsiConsolePlugin.Util;
using Cecil_Libraries.ANSI_Utils.Objects;
using Cecil_Libraries.ANSI_Utils.Util;
using Microsoft.CodeAnalysis;
using Mono.Cecil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Chaosyr")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("This mod simply enables ANSI and UTF-8 for Windows Terminals e.g. the BepInEx Console, this relies on the Cecil.ANSI_Utils functionality.")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+174da8580ee6ca0f4c1d8742e2205e616eeae7cc")]
[assembly: AssemblyProduct("ANSI Mod")]
[assembly: AssemblyTitle("ANSI Mod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AnsiConsolePlugin
{
	public class AnsiConsolePlugin
	{
		public static IEnumerable<string> TargetDLLs
		{
			get
			{
				yield break;
			}
		}

		public static void Initialize()
		{
			Console.OutputEncoding = Encoding.UTF8;
			Console.InputEncoding = Encoding.UTF8;
			Console.WriteLine();
			Console.WriteLine("Enabled UTF8 Encoding on Output and Input, now attempting to enable ANSI!");
			try
			{
				EnableNativeAnsiUtil.EnableNativeAnsi();
				Console.WriteLine("We have enabled ANSI in the Terminal! This will last the entirety of the Console Session.");
			}
			catch
			{
				Console.WriteLine("Unable to enable ANSI Code Handling.");
			}
			Console.WriteLine("We are attempting a Test to see if this is working!");
			Test.TestMain();
		}

		public static void Patch(AssemblyDefinition assembly)
		{
		}
	}
	public class Test
	{
		public static ColorRGB NeonGreen = new ColorRGB("Regular", ConvertFromXToRGB.ConverToRGBFromHex("#217727"), false, false);

		public static ColorRGB NeonGreenBG = new ColorRGB("Regular", ConvertFromXToRGB.ConverToRGBFromHex("#1b1f1b"), true, false);

		public static void TestMain()
		{
			string value = "\u001b[0;38" + ((ColorBase)NeonGreen).Extra + ";48" + ((ColorBase)NeonGreenBG).Extra + "m";
			string[] array = "┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐\r\n│                                                                                                                                                  │\r\n│          ┌─────┬─────┐   ┌         ┐   ┌─────────┐          ┌────────────┐   ┌         ┐   ┌───────────┐   ┌──────────┐   ┌─────┬─────┐          │\r\n│                │         │         │   │                    │                │         │   │           │   │                    │                │\r\n│                │         │         │   │                    │                │         │   │           │   │                    │                │\r\n│                │         │         │   │                    │                │         │   │           │   │                    │                │\r\n│                │         ├─────────┤   ├──────────          │       ┌────┐   ├─────────┤   │           │   └──────────┐         │                │\r\n│                │         │         │   │                    │            │   │         │   │           │              │         │                │\r\n│                │         │         │   │                    │            │   │         │   │           │              │         │                │\r\n│                │         │         │   │                    │            │   │         │   │           │              │         │                │\r\n│                └         └         ┘   └─────────┘          └────────────┘   └         ┘   └───────────┘   └──────────┘         └                │\r\n│                                                                                                                                                  │\r\n│                                ┌─────┬─────┐   ┌┐        ┐          ┌─────┬─────┐   ┌         ┐   ┌─────────┐                                    │\r\n│                                      │         │ ╎       │                │         │         │   │                                              │\r\n│                                      │         │  ╎      │                │         │         │   │                                              │\r\n│                                      │         │   ╎     │                │         │         │   │                                              │\r\n│                                      │         │    ╎    │                │         ├─────────┤   ├──────────                                    │\r\n│                                      │         │     ╎   │                │         │         │   │                                              │\r\n│                                      │         │      ╎  │                │         │         │   │                                              │\r\n│                                      │         │       ╎ │                │         │         │   │                                              │\r\n│                                └─────┴─────┘   └        └┘                └         └         ┘   └─────────┘                                    │\r\n│                                                                                                                                                  │\r\n│                                           ┌───────────┐   ┌───────────┐   ┌─────────┐     ┌─────────┐                                            │\r\n│                                           │               │           │   │          ╎    │                                                      │\r\n│                                           │               │           │   │           ╎   │                                                      │\r\n│                                           │               │     │     │   │     │      │  │                                                      │\r\n│                                           │               │    ─│─    │   │    ─│─     │  ├──────────                                            │\r\n│                                           │               │     │     │   │     │      │  │                                                      │\r\n│                                           │               │           │   │           ╎   │                                                      │\r\n│                                           │               │           │   │          ╎    │                                                      │\r\n│                                           └───────────┘   └───────────┘   └─────────┘     └─────────┘                                            │\r\n│                                                                                                                                                  │\r\n└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘".Split(new string[3] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
			Console.WriteLine(value);
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				Console.WriteLine(array2[i]);
			}
			Console.Write("\u001b[0m\n");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ANSI Mod";

		public const string PLUGIN_NAME = "ANSI Mod";

		public const string PLUGIN_VERSION = "2.0.0";
	}
}
namespace AnsiConsolePlugin.Util
{
	public class EnableNativeAnsiUtil
	{
		public static void EnableNativeAnsi()
		{
			if (Environment.OSVersion.Platform == PlatformID.Win32NT)
			{
				IntPtr passedHandle = FetchSTDHandle(-11);
				FetchSTDHandleValue(passedHandle, out var fetchedMode);
				fetchedMode |= 4;
				SetSTDHandleValue(passedHandle, fetchedMode);
			}
		}

		[DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true)]
		public static extern IntPtr FetchSTDHandle(int location);

		[DllImport("kernel32.dll", EntryPoint = "GetConsoleMode", SetLastError = true)]
		public static extern bool FetchSTDHandleValue(IntPtr passedHandle, out uint fetchedMode);

		[DllImport("kernel32.dll", EntryPoint = "SetConsoleMode", SetLastError = true)]
		public static extern bool SetSTDHandleValue(IntPtr passedHandle, uint setMode);
	}
}