Decompiled source of cNote v1.0.0

cNote1.0.0.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("cNote")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("cNote")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5d38fdfb-73de-4eba-9b92-ef307f8a8d52")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace cNote;

[BepInPlugin("cUtils.cNote", "cNote", "1.0.0")]
[BepInProcess("atlyss.exe")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ChatBehaviour), "Cmd_SendChatMessage")]
	public class Cmd_SendChatMessage_Patch
	{
		public static bool Prefix(ChatBehaviour __instance, ref string _message)
		{
			if (_message == null || !_message.StartsWith("/"))
			{
				return true;
			}
			string[] array = _message.Split(new char[1] { ' ' });
			switch (array[0].ToLower())
			{
			case "/cnote":
				WriteNote(__instance, array);
				return false;
			case "/cnoteremoveall":
			case "/cnotedeleteall":
				RemoveAllNotes(__instance);
				return false;
			case "/cnoteread":
			case "/cnotedisplay":
				ReadNotes(__instance, array);
				return false;
			case "/cnotehelp":
				CNoteHelp(__instance);
				return false;
			case "/cnotecount":
				CountNotes(__instance);
				return false;
			case "/cnoteremove":
			case "/cnotedelete":
				RemoveNote(__instance, array);
				return false;
			case "/cnotegetnote":
			case "/cgetnote":
				GetNote(__instance, array);
				return false;
			case "/cnotegetmessage":
			case "/cgetmessage":
				GetChatMessage(__instance, array);
				return false;
			default:
				return true;
			}
		}

		private static void WriteNote(ChatBehaviour chat, string[] inputArray)
		{
			if (inputArray.Length == 1)
			{
				chat.New_ChatMessage("no note taken\ntype <color=green>/cnotehelp</color> for more info");
				return;
			}
			string path = Path.Combine(Paths.ConfigPath, "cNote.txt");
			DateTime now = DateTime.Now;
			string arg = string.Join(" ", inputArray.Skip(1));
			arg = $"{now}: {arg}\n";
			File.AppendAllText(path, arg);
			chat.New_ChatMessage("took a note");
		}

		private static void RemoveAllNotes(ChatBehaviour chat)
		{
			string[] lines = GetLines(chat);
			if (lines != null)
			{
				string path = Path.Combine(Paths.ConfigPath, "cNote.txt");
				File.WriteAllText(path, "");
				chat.New_ChatMessage("removed all notes");
			}
		}

		private static void ReadNotes(ChatBehaviour chat, string[] inputArray)
		{
			string[] lines = GetLines(chat);
			if (lines == null)
			{
				return;
			}
			int maxPage = GetMaxPage(lines);
			if (lines.Length <= 10)
			{
				for (int i = 0; i < lines.Length; i++)
				{
					chat.New_ChatMessage(i + 1 + ". " + lines[i]);
				}
				return;
			}
			if (inputArray.Length < 2)
			{
				chat.New_ChatMessage($"you have <color=yellow>{maxPage}</color> pages\ntype <color=green>/cnoteread [page]</color> to read older notes");
				for (int j = lines.Length - 10; j < lines.Length; j++)
				{
					chat.New_ChatMessage(j + 1 + ". " + lines[j]);
				}
				return;
			}
			int.TryParse(inputArray[1], out var result);
			if (result < 1)
			{
				chat.New_ChatMessage($"<color=red>invalid page</color>\nyou have <color=yellow>{maxPage}</color> pages\ntype <color=green>/cnoteread [page]</color> to read a specific page");
				return;
			}
			result = ((result > maxPage) ? maxPage : result);
			int num = lines.Length - 10 * result;
			int num2 = lines.Length - 10 * (result - 1);
			num = ((num >= 0) ? num : 0);
			for (int k = num; k < num2; k++)
			{
				chat.New_ChatMessage(k + 1 + ". " + lines[k]);
			}
		}

		private static void CNoteHelp(ChatBehaviour chat)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("<color=yellow>cUtils.cNote 1.0.0</color> /cnotehelp:\n");
			stringBuilder.Append("type <color=green>/cnote [note]</color> to take a note.\n");
			stringBuilder.Append("type <color=green>/cnoteread</color> to read your latest page.\n");
			stringBuilder.Append("type <color=green>/cnoteread [page]</color> to read a specific page.\n");
			stringBuilder.Append("type <color=green>/cnotegetnote</color> to copy your latest note to your textbox.\n");
			stringBuilder.Append("type <color=green>/cnotegetnote [nr]</color> to copy a specific note to your textbox.\n");
			stringBuilder.Append("type <color=green>/cnotegetmessage [start]</color> to copy the latest chatmessage with matching start to your textbox.\n");
			stringBuilder.Append("type <color=green>/cnotecount</color> to read your note and page count.\n");
			stringBuilder.Append("type <color=green>/cnoteremove</color> to remove your latest note.\n");
			stringBuilder.Append("type <color=green>/cnoteremove [nr]</color> to remove a specific note.\n");
			stringBuilder.Append("type <color=green>/cnoteremoveall</color> to remove all your notes.\n");
			stringBuilder.Append("your notes also are accessible from the <color=yellow>BepInEx config</color> directory.");
			chat.New_ChatMessage(stringBuilder.ToString());
		}

		private static void CountNotes(ChatBehaviour chat)
		{
			string[] lines = GetLines(chat);
			if (lines != null)
			{
				int maxPage = GetMaxPage(lines);
				chat.New_ChatMessage($"you took <color=yellow>{lines.Length}</color> notes\nthat are <color=yellow>{maxPage}</color> pages");
			}
		}

		private static int GetMaxPage(string[] lines)
		{
			int num = lines.Length / 10;
			if (num * 10 < lines.Length)
			{
				num++;
			}
			return num;
		}

		private static void RemoveNote(ChatBehaviour chat, string[] inputArray)
		{
			string[] lines = GetLines(chat);
			if (lines != null)
			{
				int noteNumber = GetNoteNumber(chat, inputArray, lines);
				if (noteNumber != 0)
				{
					List<string> list = new List<string>(lines);
					list.RemoveAt(noteNumber - 1);
					string path = Path.Combine(Paths.ConfigPath, "cNote.txt");
					File.WriteAllLines(path, list.ToArray());
					chat.New_ChatMessage("removed note");
				}
			}
		}

		private static void GetNote(ChatBehaviour chat, string[] inputArray)
		{
			string[] lines = GetLines(chat);
			if (lines != null)
			{
				int noteNumber = GetNoteNumber(chat, inputArray, lines);
				if (noteNumber != 0)
				{
					string input = lines[noteNumber - 1];
					input = Regex.Replace(input, ".*?: ", "");
					chat._chatAssets._chatInput.text = input;
					chat.New_ChatMessage("copied note to textbox:\n<color=yellow>" + input + "</color>");
				}
			}
		}

		private static int GetNoteNumber(ChatBehaviour chat, string[] inputArray, string[] lines)
		{
			int result;
			if (inputArray.Length < 2)
			{
				result = lines.Length;
			}
			else
			{
				int.TryParse(inputArray[1], out result);
				if (result < 1)
				{
					chat.New_ChatMessage("invalid notenumber");
					return 0;
				}
				result = ((result > lines.Length) ? lines.Length : result);
			}
			return result;
		}

		private static void GetChatMessage(ChatBehaviour chat, string[] inputArray)
		{
			int count = chat._chatMessages.Count;
			if (count < 1)
			{
				chat.New_ChatMessage("no chatmessage found");
				return;
			}
			if (inputArray.Length < 2)
			{
				chat.New_ChatMessage("no start provided");
				return;
			}
			string value = string.Join(" ", inputArray.Skip(1)).ToLower();
			for (int num = count; num > 0; num--)
			{
				string input = chat._chatMessages[num - 1];
				input = Regex.Replace(input, ".*?:\\s*<color=[^>]+>(.*?)</color>", "$1");
				if (input.StartsWith("<color"))
				{
					input = Regex.Replace(input, "\\s*<color=[^>]+>(.*?)<\\/color>", "$1");
				}
				if (input.ToLower().StartsWith(value))
				{
					chat._chatAssets._chatInput.text = input;
					chat.New_ChatMessage("copied message to textbox:\n<color=yellow>" + input + "</color>");
					return;
				}
			}
			chat.New_ChatMessage("no match found");
		}

		private static string[] GetLines(ChatBehaviour chat)
		{
			string path = Path.Combine(Paths.ConfigPath, "cNote.txt");
			if (!File.Exists(path))
			{
				chat.New_ChatMessage("no notes found");
				return null;
			}
			string[] array = File.ReadAllLines(path);
			if (array.Length < 1)
			{
				chat.New_ChatMessage("no notes found");
				return null;
			}
			return array;
		}
	}

	private const string PLUGIN_GUID = "cUtils.cNote";

	private const string PLUGIN_NAME = "cNote";

	private const string PLUGIN_VERSION = "1.0.0";

	private const string FILE_NAME = "cNote.txt";

	private readonly Harmony harmony = new Harmony("cUtils.cNote");

	private void Awake()
	{
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin cUtils.cNote 1.0.0 is loaded!");
	}
}