roll.dll

Decompiled 2 weeks 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 Splatform;
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), "AddInworldText")]
		private class noinworldtext
		{
			private static bool Prefix(GameObject go, long senderID, Vector3 position, Type type, UserInfo user, string text)
			{
				bool result = true;
				if (text.Contains("{|roll|}"))
				{
					result = false;
				}
				return result;
			}
		}

		[HarmonyPatch(typeof(Terminal), "AddString", new Type[]
		{
			typeof(PlatformUserID),
			typeof(string),
			typeof(Type),
			typeof(bool)
		})]
		private class rollstring
		{
			private static bool Prefix(PlatformUserID user, string text, Type type, bool timestamp, ref Terminal __instance)
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				bool result = true;
				if (text.Contains("{|roll|}"))
				{
					ZLog.LogError((object)user);
					ZLog.LogError((object)text);
					PlayerInfo val = default(PlayerInfo);
					if (ZNet.TryGetPlayerByPlatformUserID(user, ref val))
					{
						string text2 = text.Replace("{|roll|}", "");
						__instance.AddString("<color=#607D8B>" + val.m_name + " " + text2 + "</color>");
						result = false;
					}
				}
				return result;
			}
		}
	}
}