using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using NEP.MonoDirector.Core;
using WeatherElectric.MonoDirectorOBS;
using WeatherElectric.MonoDirectorOBS.Melon;
using WeatherElectric.OBSControl.OBS;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("OBS integration for MonoDirector.")]
[assembly: AssemblyDescription("OBS integration for MonoDirector.")]
[assembly: AssemblyCompany("Weather Electric")]
[assembly: AssemblyProduct("MonoDirectorOBS")]
[assembly: AssemblyCopyright("Developed by SoulWithMae")]
[assembly: AssemblyTrademark("Weather Electric")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: MelonInfo(typeof(Main), "MonoDirectorOBS", "1.1.0", "SoulWithMae", "https://thunderstore.io/c/bonelab/p/SoulWithMae/MonoDirectorOBS/")]
[assembly: MelonColor(ConsoleColor.White)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace WeatherElectric.MonoDirectorOBS
{
public class Main : MelonMod
{
internal const string Name = "MonoDirectorOBS";
internal const string Description = "OBS integration for MonoDirector.";
internal const string Author = "SoulWithMae";
internal const string Company = "Weather Electric";
internal const string Version = "1.1.0";
internal const string DownloadLink = "https://thunderstore.io/c/bonelab/p/SoulWithMae/MonoDirectorOBS/";
public override void OnInitializeMelon()
{
ModConsole.Setup(((MelonBase)this).LoggerInstance);
Preferences.Setup();
}
}
}
namespace WeatherElectric.MonoDirectorOBS.Patching
{
internal static class MonoMonitor
{
[HarmonyPatch(typeof(Playback))]
private static class PlaybackPatch
{
[HarmonyPostfix]
[HarmonyPatch("OnPlay")]
private static void Play()
{
OnPlay();
}
[HarmonyPostfix]
[HarmonyPatch("OnStopPlayback")]
private static void Stop()
{
OnStop();
}
}
private static void OnPlay()
{
ModConsole.Msg("MD OnPlay Event fired", 1);
ObsBridge.StartRecording();
ModConsole.Msg("Started recording in MD", 1);
}
private static void OnStop()
{
ModConsole.Msg("MD OnStopPlayback Event fired", 1);
ObsBridge.StopRecording();
ModConsole.Msg("Stopped recording in MD", 1);
}
}
}
namespace WeatherElectric.MonoDirectorOBS.Melon
{
internal static class ModConsole
{
private static Instance _logger;
public static void Setup(Instance loggerInstance)
{
_logger = loggerInstance;
}
public static void Msg(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text);
}
}
public static void Msg(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text);
}
}
public static void Msg(ConsoleColor txtcolor, object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text);
}
}
public static void Msg(ConsoleColor txtcolor, string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text);
}
}
public static void Msg(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text, args);
}
}
public static void Msg(ConsoleColor txtcolor, string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text, args);
}
}
public static void Error(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text);
}
}
public static void Error(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text);
}
}
public static void Error(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text, args);
}
}
public static void Warning(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text);
}
}
public static void Warning(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text);
}
}
public static void Warning(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text, args);
}
}
}
internal static class Preferences
{
public static readonly MelonPreferences_Category GlobalCategory = MelonPreferences.CreateCategory("Global");
public static readonly MelonPreferences_Category OwnCategory = MelonPreferences.CreateCategory("MonoDirectorOBS");
public static MelonPreferences_Entry<int> LoggingMode { get; set; }
public static MelonPreferences_Entry<string> WebsocketURL { get; set; }
public static MelonPreferences_Entry<string> WebsocketPassword { get; set; }
public static void Setup()
{
LoggingMode = GlobalCategory.GetEntry<int>("LoggingMode") ?? GlobalCategory.CreateEntry<int>("LoggingMode", 0, "Logging Mode", "The level of logging to use. 0 = Important Only, 1 = All", false, false, (ValueValidator)null, (string)null);
GlobalCategory.SetFilePath(MelonUtils.UserDataDirectory + "/WeatherElectric.cfg");
GlobalCategory.SaveToFile(false);
WebsocketURL = OwnCategory.CreateEntry<string>("WebsocketURL", "ws://127.0.0.1:4455", "Websocket URL", "The URL to use for the websocket connection. Usually don't have to change this.", false, false, (ValueValidator)null, (string)null);
WebsocketPassword = OwnCategory.CreateEntry<string>("WebsocketPassword", "REPLACEME", "Websocket Password", "The password to use for the websocket connection. Change this to the password you set in OBS.", false, false, (ValueValidator)null, (string)null);
OwnCategory.SetFilePath(MelonUtils.UserDataDirectory + "/WeatherElectric.cfg");
OwnCategory.SaveToFile(false);
ModConsole.Msg("Finished preferences setup for MonoDirectorOBS", 1);
}
}
}