roll.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("roll")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("roll")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3B95EEF7-4A97-4393-91A0-3626434F3631")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace tripping
{
	[BepInPlugin("1010101110.roll", "roll", "1.0.0")]
	public class Mod : BaseUnityPlugin
	{
		public static readonly Harmony harmony = new Harmony(typeof(Mod).GetCustomAttributes(typeof(BepInPlugin), inherit: false).Cast<BepInPlugin>().First()
			.GUID);

		private void Awake()
		{
			harmony.PatchAll();
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
}
namespace tripping.Patches
{
	public class TrippingPatches
	{
		[HarmonyPatch(typeof(Chat), "Awake")]
		private class awakepatch
		{
			private static void Postfix(ref Chat __instance)
			{
				((Terminal)__instance).AddString("/roll min(optional) max(optional) rolls dice, default (1-100)");
				((Terminal)__instance).AddString("");
			}
		}

		[HarmonyPatch(typeof(Chat), "InputText")]
		private class sendtextpatch
		{
			private static bool Prefix(ref Chat __instance)
			{
				if (((TMP_InputField)((Terminal)__instance).m_input).text.StartsWith("/roll"))
				{
					try
					{
						int num = 1;
						int num2 = 100;
						string[] array = ((TMP_InputField)((Terminal)__instance).m_input).text.Split(new char[1] { ' ' });
						if (array.Length == 2)
						{
							num2 = int.Parse(array[1]);
						}
						if (array.Length == 3)
						{
							num = int.Parse(array[1]);
							num2 = int.Parse(array[2]);
						}
						if (num > num2)
						{
							throw new Exception("invalid roll");
						}
						Random random = new Random();
						((TMP_InputField)((Terminal)__instance).m_input).text = "rolls " + random.Next(num, num2 + 1) + "  (" + num + "-" + num2 + "){|roll|}";
					}
					catch
					{
						((Terminal)__instance).AddString("failed roll, try /roll or /roll 100 or /roll 1 100");
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Chat), "OnNewChatMessage")]
		private class addstringpatch
		{
			private static bool Prefix(GameObject go, long senderID, Vector3 pos, Type type, UserInfo user, string text, string senderNetworkUserId, ref Chat __instance)
			{
				if (text.Contains("{|roll|}"))
				{
					string text2 = text.Replace("{|roll|}", "");
					((Terminal)__instance).AddString("<color=#607D8B>" + user.GetDisplayName(senderNetworkUserId) + " " + text2 + "</color>");
					return false;
				}
				return true;
			}
		}
	}
}