using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Fomo;
using Fomo.Core;
using Fomo.Core.Util;
using FomoChatLog.Commands;
using FomoChatLog.Sinks;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AndrewLin.FomoChatLog")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("FomoChatLog: A Fomo submod that logs On-Together chat messages to a local text file. Use /fomohelp and look for /fomochatlog commands")]
[assembly: AssemblyFileVersion("0.2.3.0")]
[assembly: AssemblyInformationalVersion("0.2.3+dc290028f2302c7953f8cdfe5b05908e8e411cbb")]
[assembly: AssemblyProduct("AndrewLin.FomoChatLog")]
[assembly: AssemblyTitle("AndrewLin.FomoChatLog")]
[assembly: AssemblyVersion("0.2.3.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 FomoChatLog
{
public static class BuildInfo
{
public const string Version = "0.2.3";
}
[BepInPlugin("com.andrewlin.ontogether.fomochatlog", "FomoChatLog", "0.2.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class FomoChatLogPlugin : BaseUnityPlugin
{
public const string ModGUID = "com.andrewlin.ontogether.fomochatlog";
public const string ModName = "FomoChatLog";
public const string ModVersion = "0.2.3";
private static readonly string DefaultChatLogPathRaw = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "on-together/fomo/on_together_chat_log.txt");
internal static ManualLogSource Log = null;
public static ConfigEntry<bool>? EnableFeature { get; private set; }
private static ConfigEntry<string>? ChatLogPathRaw { get; set; }
public static ConfigEntry<string>? MessageFormat { get; set; }
public static ConfigEntry<string>? NotificationFormat { get; set; }
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"FomoChatLog v0.2.3 loading…");
InitConfig();
InitializeChatLog();
ChatSinkManager sinkManager = FomoPlugin.SinkManager;
if (sinkManager != null)
{
sinkManager.Register((IChatSink)(object)new LogFileChatSink());
}
Log.LogInfo((object)"LogFileChatSink registered with Fomo SinkManager.");
ChatCommandManager commandManager = FomoPlugin.CommandManager;
if (commandManager != null)
{
commandManager.Register((IChatCommand)(object)new FomoChatLogGetPathCommand());
}
ChatCommandManager commandManager2 = FomoPlugin.CommandManager;
if (commandManager2 != null)
{
commandManager2.Register((IChatCommand)(object)new FomoChatLogSetPathCommand());
}
ChatCommandManager commandManager3 = FomoPlugin.CommandManager;
if (commandManager3 != null)
{
commandManager3.Register((IChatCommand)(object)new FomoChatLogToggleCommand());
}
ChatCommandManager commandManager4 = FomoPlugin.CommandManager;
if (commandManager4 != null)
{
commandManager4.Register((IChatCommand)(object)new FomoChatLogMessageFormatCommand());
}
ChatCommandManager commandManager5 = FomoPlugin.CommandManager;
if (commandManager5 != null)
{
commandManager5.Register((IChatCommand)(object)new FomoChatLogNotificationFormatCommand());
}
Log.LogInfo((object)"FomoChatLog loaded.");
}
private void InitializeChatLog()
{
string chatLogPath = GetChatLogPath();
string text = Path.GetDirectoryName(chatLogPath) ?? string.Empty;
Log.LogInfo((object)("Creating chat log directory if it doesn't exist: " + text));
Directory.CreateDirectory(text);
ConfigEntry<bool>? enableFeature = EnableFeature;
if (enableFeature != null && enableFeature.Value && File.Exists(chatLogPath) && File.GetCreationTime(chatLogPath).Date < DateTime.Now.Date)
{
Log.LogInfo((object)("Clearing chat log file from previous day: " + chatLogPath));
File.Delete(chatLogPath);
}
}
public static string GetChatLogPath()
{
string name = ChatLogPathRaw?.Value ?? DefaultChatLogPathRaw;
name = Environment.ExpandEnvironmentVariables(name);
if (name.StartsWith("~"))
{
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string text = name;
name = Path.Combine(folderPath, text.Substring(1, text.Length - 1));
}
return name;
}
public static void SetChatLogPath(string newPath)
{
if (ChatLogPathRaw != null)
{
ChatLogPathRaw.Value = newPath;
}
}
private void InitConfig()
{
EnableFeature = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableFeature", true, "Enable or disable chat file logging.");
ChatLogPathRaw = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ChatLogPath", DefaultChatLogPathRaw, "Path to the chat log file. Supports ~ and environment variables.");
MessageFormat = ((BaseUnityPlugin)this).Config.Bind<string>("Formatting", "MessageFormat", "[{timestamp:yyyy-MM-dd HH:mm:ss}] [{channel}] {username}: {message}", "Format string for chat messages sent to Telegram.\nPlaceholders: {timestamp[:fmt]}, {channel[:short]}, {username}, {message}, {distance}, {source}, {playerid}");
NotificationFormat = ((BaseUnityPlugin)this).Config.Bind<string>("Formatting", "NotificationFormat", "[{timestamp:yyyy-MM-dd HH:mm:ss}] {message}", "Format string for system notifications sent to Telegram.\nPlaceholders: {timestamp[:fmt]}, {channel[:short]}, {username}, {message}, {distance}, {source}, {playerid}");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "AndrewLin.FomoChatLog";
public const string PLUGIN_NAME = "AndrewLin.FomoChatLog";
public const string PLUGIN_VERSION = "0.2.3";
}
}
namespace FomoChatLog.Sinks
{
public class LogFileChatSink : IChatSink
{
private readonly ManualLogSource _log = Logger.CreateLogSource("FomoChatLog.LFCS");
private const int WarnLimit = 20;
private int _warnCount;
public async Task SendAsync(ChatEntry entry)
{
ConfigEntry<bool>? enableFeature = FomoChatLogPlugin.EnableFeature;
if (enableFeature == null || !enableFeature.Value)
{
return;
}
try
{
string chatLogPath = FomoChatLogPlugin.GetChatLogPath();
string text = ((!entry.IsNotification) ? FomoChatLogPlugin.MessageFormat?.Value : FomoChatLogPlugin.NotificationFormat?.Value);
string text2 = ChatEntryFormatter.Format(entry, text);
await File.AppendAllTextAsync(chatLogPath, text2 + Environment.NewLine);
}
catch (Exception ex)
{
_warnCount++;
if (_warnCount <= 20)
{
_log.LogWarning((object)("Failed to write chat log: " + ex.Message));
}
else if (_warnCount == 21)
{
_log.LogWarning((object)"Further warnings about chat log writing will be suppressed.");
}
}
}
}
}
namespace FomoChatLog.Commands
{
public class FomoChatLogGetPathCommand : IChatCommand, IComparable<IChatCommand>
{
public const string CMD = "fomochatloggetpath";
public string Name => "fomochatloggetpath";
public string ShortName => "fclgp";
public string Description => "Get the current chat log file path.";
public void Execute(string[] args)
{
ChatUtils.AddGlobalNotification("Chat log path: " + FomoChatLogPlugin.GetChatLogPath());
}
}
public class FomoChatLogMessageFormatCommand : IChatCommand, IComparable<IChatCommand>
{
public const string CMD = "fomochatlogmessageformat";
public string Name => "fomochatlogmessageformat";
public string ShortName => "fclmf";
public string Description => "Set or get the chat log message format.";
public void Execute(string[] args)
{
ConfigEntry<bool>? enableFeature = FomoChatLogPlugin.EnableFeature;
if (enableFeature == null || !enableFeature.Value)
{
ChatUtils.AddGlobalNotification("Chat log feature is disabled.");
}
else if (FomoChatLogPlugin.MessageFormat == null)
{
ChatUtils.AddGlobalNotification("Fomo Chat Log Mod is not initialized yet.");
}
else if (args.Length == 0)
{
ChatUtils.AddGlobalNotification("Chat log message format: " + FomoChatLogPlugin.MessageFormat?.Value);
}
else if (args.Length != 0)
{
string text = string.Join(" ", args);
if (string.IsNullOrWhiteSpace(text))
{
ChatUtils.AddGlobalNotification("Please enter a valid chat log message format.");
return;
}
FomoChatLogPlugin.MessageFormat.Value = text;
ChatUtils.AddGlobalNotification("Chat log message format is now set to: " + text + ".");
}
}
}
public class FomoChatLogNotificationFormatCommand : IChatCommand, IComparable<IChatCommand>
{
public const string CMD = "fomochatlognotificationformat";
public string Name => "fomochatlognotificationformat";
public string ShortName => "fclnf";
public string Description => "Set or get the chat log notification format.";
public void Execute(string[] args)
{
ConfigEntry<bool>? enableFeature = FomoChatLogPlugin.EnableFeature;
if (enableFeature == null || !enableFeature.Value)
{
ChatUtils.AddGlobalNotification("Chat log feature is disabled.");
}
else if (FomoChatLogPlugin.NotificationFormat == null)
{
ChatUtils.AddGlobalNotification("Fomo Chat Log Mod is not initialized yet.");
}
else if (args.Length == 0)
{
ChatUtils.AddGlobalNotification("Chat log notification format: " + FomoChatLogPlugin.NotificationFormat?.Value);
}
else if (args.Length != 0)
{
string text = string.Join(" ", args);
if (string.IsNullOrWhiteSpace(text))
{
ChatUtils.AddGlobalNotification("Please enter a valid chat log notification format.");
return;
}
FomoChatLogPlugin.NotificationFormat.Value = text;
ChatUtils.AddGlobalNotification("Chat log notification format is now set to: " + text + ".");
}
}
}
public class FomoChatLogSetPathCommand : IChatCommand, IComparable<IChatCommand>
{
public const string CMD = "fomochatlogsetpath";
public string Name => "fomochatlogsetpath";
public string ShortName => "fclsp";
public string Description => "Set the chat log file path. Usage: /fomochatlogsetpath <path>. Example: /fomochatlogsetpath C:\\Logs\\chat.log";
public void Execute(string[] args)
{
if (args.Length < 1)
{
ChatUtils.AddGlobalNotification("Usage: /fomochatlogsetpath <path>. Example: /fomochatlogsetpath C:\\Logs\\chat.log");
return;
}
string text = args[0];
if (string.IsNullOrWhiteSpace(text))
{
ChatUtils.AddGlobalNotification("Please enter a valid path.");
return;
}
FomoChatLogPlugin.SetChatLogPath(text);
try
{
string text2 = Path.GetDirectoryName(text) ?? string.Empty;
if (!string.IsNullOrEmpty(text2) && !Directory.Exists(text2))
{
Directory.CreateDirectory(text2);
}
}
catch (Exception ex)
{
ChatUtils.AddGlobalNotification("Failed to create directory for the new chat log path: " + ex.Message);
return;
}
ChatUtils.AddGlobalNotification("Chat log path set to: " + text + ". Takes effect on next restart.");
}
}
public class FomoChatLogToggleCommand : IChatCommand, IComparable<IChatCommand>
{
public const string CMD = "fomochatlogtoggle";
public string Name => "fomochatlogtoggle";
public string ShortName => "fclt";
public string Description => "Toggle chat file logging on/off.";
public void Execute(string[] args)
{
if (FomoChatLogPlugin.EnableFeature != null)
{
FomoChatLogPlugin.EnableFeature.Value = !FomoChatLogPlugin.EnableFeature.Value;
ChatUtils.AddGlobalNotification("Fomo chat log is now " + (FomoChatLogPlugin.EnableFeature.Value ? "enabled" : "disabled") + ".");
}
}
}
}