using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Alpha;
using Alpha.Core.Command;
using Alpha.Core.Util;
using BepInEx;
using BepInEx.Configuration;
using DnDUtil.Core.Commands;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AndrewLin")]
[assembly: AssemblyConfiguration("Publish")]
[assembly: AssemblyDescription("A DnD dice mod for On-Together. Use /dndhelp")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+1902b86bd15c5c4d436b4d4523e47990ddeec1dd")]
[assembly: AssemblyProduct("AndrewLin.DnDUtil")]
[assembly: AssemblyTitle("AndrewLin.DnDUtil")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/andrewlimforfun/ot-mods")]
[assembly: AssemblyVersion("1.0.5.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace DnDUtil
{
public static class BuildInfo
{
public const string Version = "1.0.5";
}
[BepInPlugin("com.andrewlin.ontogether.dndmod", "DnDUtil", "1.0.5")]
public class DndPlugin : BaseUnityPlugin
{
public const string DefaultAnnouncerChatName = "DnDSystem";
public const string ModGUID = "com.andrewlin.ontogether.dndmod";
public const string ModName = "DnDUtil";
public const string ModVersion = "1.0.5";
public static ConfigEntry<bool>? EnableFeature { get; private set; }
public static ConfigEntry<bool>? ShowCommand { get; private set; }
public static ConfigEntry<string>? AnnouncerArea { get; private set; }
public static ConfigEntry<string>? AnnouncerChatName { get; private set; }
public static string? PlayerId { get; private set; }
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"DnDUtil v1.0.5 is loaded!");
InitConfig();
ChatCommandManager commandManager = AlphaPlugin.CommandManager;
if (commandManager != null)
{
commandManager.Register((IChatCommand)(object)new DndRollCommand());
}
ChatCommandManager commandManager2 = AlphaPlugin.CommandManager;
if (commandManager2 != null)
{
commandManager2.Register((IChatCommand)(object)new RollCommand());
}
ChatCommandManager commandManager3 = AlphaPlugin.CommandManager;
if (commandManager3 != null)
{
commandManager3.Register((IChatCommand)(object)new DndSetAnnouncerAreaCommand());
}
ChatCommandManager commandManager4 = AlphaPlugin.CommandManager;
if (commandManager4 != null)
{
commandManager4.Register((IChatCommand)(object)new DndSetAnnouncerNameCommand());
}
ChatCommandManager commandManager5 = AlphaPlugin.CommandManager;
if (commandManager5 != null)
{
commandManager5.Register((IChatCommand)(object)new DndToggleCommand());
}
}
private void InitConfig()
{
EnableFeature = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableFeature", true, "Enable or disable the DnD utility features.");
ShowCommand = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowCommand", false, "Show the command in chat when used.");
AnnouncerChatName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "AnnouncerChatName", "DnDSystem", "The chat name to use when announcing rolls. Default is 'DnDSystem'.");
AnnouncerArea = ((BaseUnityPlugin)this).Config.Bind<string>("General", "AnnouncerArea", "local", "The area to use when announcing rolls [self|local|global]. Default is 'self'.");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "AndrewLin.DnDUtil";
public const string PLUGIN_NAME = "AndrewLin.DnDUtil";
public const string PLUGIN_VERSION = "1.0.5";
}
}
namespace DnDUtil.Core.Commands
{
public class DndRollCommand : IChatCommand, IComparable<IChatCommand>
{
public virtual string Name => "dndroll";
public virtual string ShortName => "dr";
public string Description => "Rolls a dice. E.g. '/" + Name + " 2d20 1d6' rolls 2 20-sided dice and 1 6-sided die.";
public string Namespace => "dnd";
public void Execute(string[] args)
{
if (args.Length == 0)
{
ChatUtils.AddGlobalNotification("Usage: /" + Name + " [XdY] - Rolls X dice with Y sides. Example: /" + Name + " 2d20");
return;
}
foreach (string text in args)
{
try
{
List<int> values = DiceTokenToNumber(text);
string text2 = string.Join(", ", values);
string userName = PlayerUtils.GetUserName();
string text3 = userName + " rolled " + text + ": " + text2;
string text4 = DndPlugin.AnnouncerChatName?.Value ?? "DnDSystem";
if (DndPlugin.AnnouncerArea?.Value == "self")
{
ChatUtils.AddGlobalNotification(text3);
}
else if (DndPlugin.AnnouncerArea?.Value == "local")
{
ChatUtils.SendMessageAsync(text4, text3, true, "word", (Vector3?)null);
}
else if (DndPlugin.AnnouncerArea?.Value == "global")
{
ChatUtils.SendMessageAsync(text4, text3, false, "word", (Vector3?)null);
}
}
catch (ArgumentException ex)
{
ChatUtils.AddGlobalNotification(ex.Message);
}
}
}
public static List<int> DiceTokenToNumber(string token)
{
if (!token.Contains('d'))
{
throw new ArgumentException("Invalid format '" + token + "'. Use XdY, e.g. 2d20.");
}
if (token.StartsWith('d'))
{
token = "1" + token;
}
string[] array = token.Split('d');
if (array.Length != 2 || !int.TryParse(array[0], out var result) || !int.TryParse(array[1], out var result2))
{
throw new ArgumentException("Invalid format '" + token + "'. Use XdY, e.g. 2d20.");
}
Random random = new Random();
List<int> list = new List<int>();
for (int i = 0; i < result; i++)
{
list.Add(random.Next(1, result2 + 1));
}
return list;
}
}
public class DndSetAnnouncerAreaCommand : IChatCommand, IComparable<IChatCommand>
{
public static readonly HashSet<string> ValidAreas = new HashSet<string> { "self", "local", "global" };
public static readonly string ValidAreasText = string.Join("|", ValidAreas);
public const string CMD = "dndsetannouncerarea";
public string Name => "dndsetannouncerarea";
public string ShortName => "dsaa";
public string Description => "Set the area to use when announcing rolls: [" + ValidAreasText + "]. Current: " + (DndPlugin.AnnouncerArea?.Value ?? "self");
public string Namespace => "dnd";
public void Execute(string[] args)
{
if (DndPlugin.AnnouncerArea == null)
{
return;
}
if (args.Length == 0)
{
ChatUtils.AddGlobalNotification("Usage: /dndsetannouncerarea [" + ValidAreasText + "] - Sets the area to use when announcing rolls.");
return;
}
string text = args[0].ToLower();
if (!ValidAreas.Contains(text))
{
ChatUtils.AddGlobalNotification("Invalid announcer area. Valid areas are: [" + ValidAreasText + "].");
return;
}
DndPlugin.AnnouncerArea.Value = text;
ChatUtils.AddGlobalNotification("Announcer area is now set to " + DndPlugin.AnnouncerArea.Value + ".");
}
}
public class DndSetAnnouncerNameCommand : IChatCommand, IComparable<IChatCommand>
{
public const string CMD = "dndsetannouncername";
public string Name => "dndsetannouncername";
public string ShortName => "dsan";
public string Description => "Set the name to use when sending messages to chat. Current: " + (DndPlugin.AnnouncerChatName?.Value ?? "DnDSystem");
public string Namespace => "dnd";
public void Execute(string[] args)
{
if (DndPlugin.AnnouncerChatName != null)
{
if (args.Length == 0)
{
ChatUtils.AddGlobalNotification("Usage: /dndsetannouncername [name] - Sets the name to use when sending messages to chat.");
return;
}
DndPlugin.AnnouncerChatName.Value = args[0];
ChatUtils.AddGlobalNotification("Chat name is now set to " + DndPlugin.AnnouncerChatName.Value + ".");
}
}
}
public class DndToggleCommand : IChatCommand, IComparable<IChatCommand>
{
public const string CMD = "dndtoggle";
public string Name => "dndtoggle";
public string ShortName => "dt";
public string Description => "Toggle DnDUtil feature on/off. ";
public string Namespace => "dnd";
public void Execute(string[] args)
{
if (DndPlugin.EnableFeature != null)
{
DndPlugin.EnableFeature.Value = !DndPlugin.EnableFeature.Value;
ChatUtils.AddGlobalNotification("DnD feature is now " + (DndPlugin.EnableFeature.Value ? "enabled" : "disabled") + ".");
}
}
}
public class RollCommand : DndRollCommand
{
public override string Name => "roll";
public override string ShortName => "r";
}
}