using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("NepuShiro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3a9637faa96f80a8e1b61a13d51e56fed7a342d0")]
[assembly: AssemblyProduct("ALogViewer")]
[assembly: AssemblyTitle("ALogSender")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/NepuShiro/ALogSender")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace ALogSender;
[ResonitePlugin("NepuShiro.ALogSender", "ALogViewer", "1.0.0", "NepuShiro", "https://github.com/NepuShiro/ALogSender")]
public class Plugin : BasePlugin
{
private class ALogListener : ILogListener, global::System.IDisposable
{
public LogLevel LogLevelFilter => (LogLevel)63;
public void LogEvent(object sender, LogEventArgs args)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource val = (ManualLogSource)((sender is ManualLogSource) ? sender : null);
if (val != null && val != Logger)
{
global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler(5, 3);
defaultInterpolatedStringHandler.AppendLiteral("[");
LogLevel level = args.Level;
defaultInterpolatedStringHandler.AppendFormatted(((object)(LogLevel)(ref level)).ToString().ToUpper());
defaultInterpolatedStringHandler.AppendLiteral("][");
defaultInterpolatedStringHandler.AppendFormatted(val.SourceName);
defaultInterpolatedStringHandler.AppendLiteral("] ");
defaultInterpolatedStringHandler.AppendFormatted<object>(args.Data);
UdpLog(defaultInterpolatedStringHandler.ToStringAndClear(), (LogLevel)16);
}
}
public void Dispose()
{
}
}
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
[StructLayout(3)]
private struct <<Load>b__7_4>d : IAsyncStateMachine
{
public int <>1__state;
public AsyncTaskMethodBuilder <>t__builder;
private TaskAwaiter <>u__1;
private void MoveNext()
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
int num = <>1__state;
try
{
try
{
TaskAwaiter awaiter;
if (num != 0)
{
awaiter = global::System.Threading.Tasks.Task.Delay(3000).GetAwaiter();
if (!((TaskAwaiter)(ref awaiter)).IsCompleted)
{
num = (<>1__state = 0);
<>u__1 = awaiter;
((AsyncTaskMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter, <<Load>b__7_4>d>(ref awaiter, ref this);
return;
}
}
else
{
awaiter = <>u__1;
<>u__1 = default(TaskAwaiter);
num = (<>1__state = -1);
}
((TaskAwaiter)(ref awaiter)).GetResult();
StartALogViewer();
StartUdpClient(_port.Value);
}
catch (OperationCanceledException)
{
}
}
catch (global::System.Exception exception)
{
<>1__state = -2;
((AsyncTaskMethodBuilder)(ref <>t__builder)).SetException(exception);
return;
}
<>1__state = -2;
((AsyncTaskMethodBuilder)(ref <>t__builder)).SetResult();
}
[DebuggerHidden]
private void SetStateMachine(IAsyncStateMachine stateMachine)
{
((AsyncTaskMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
}
}
public static readonly <>c <>9 = new <>c();
public static Func<global::System.Threading.Tasks.Task?> <>9__7_4;
public static EventHandler <>9__7_0;
public static Action<string> <>9__7_1;
public static Action<string> <>9__7_2;
public static Action<string> <>9__7_3;
internal void <Load>b__7_0(object? _, EventArgs _)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
CancellationTokenSource changeCts = _changeCts;
if (changeCts != null)
{
changeCts.Cancel();
}
CancellationTokenSource changeCts2 = _changeCts;
if (changeCts2 != null)
{
changeCts2.Dispose();
}
_changeCts = new CancellationTokenSource();
global::System.Threading.Tasks.Task.Run((Func<global::System.Threading.Tasks.Task>)([AsyncStateMachine(typeof(<<Load>b__7_4>d))] () =>
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
<<Load>b__7_4>d <<Load>b__7_4>d = default(<<Load>b__7_4>d);
<<Load>b__7_4>d.<>t__builder = AsyncTaskMethodBuilder.Create();
<<Load>b__7_4>d.<>1__state = -1;
((AsyncTaskMethodBuilder)(ref <<Load>b__7_4>d.<>t__builder)).Start<<<Load>b__7_4>d>(ref <<Load>b__7_4>d);
return ((AsyncTaskMethodBuilder)(ref <<Load>b__7_4>d.<>t__builder)).Task;
}), _changeCts.Token);
}
[AsyncStateMachine(typeof(<<Load>b__7_4>d))]
internal global::System.Threading.Tasks.Task? <Load>b__7_4()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
<<Load>b__7_4>d <<Load>b__7_4>d = default(<<Load>b__7_4>d);
<<Load>b__7_4>d.<>t__builder = AsyncTaskMethodBuilder.Create();
<<Load>b__7_4>d.<>1__state = -1;
((AsyncTaskMethodBuilder)(ref <<Load>b__7_4>d.<>t__builder)).Start<<<Load>b__7_4>d>(ref <<Load>b__7_4>d);
return ((AsyncTaskMethodBuilder)(ref <<Load>b__7_4>d.<>t__builder)).Task;
}
internal void <Load>b__7_1(string msg)
{
UdpLog(msg, (LogLevel)8, _logToConsole.Value);
}
internal void <Load>b__7_2(string msg)
{
UdpLog(msg, (LogLevel)4, _logToConsole.Value);
}
internal void <Load>b__7_3(string msg)
{
UdpLog(msg, (LogLevel)2, _logToConsole.Value);
}
}
internal static ManualLogSource Logger;
private static ConfigEntry<int> _port;
private static ConfigEntry<bool> _logToConsole;
private static UdpClient _udpClient;
private static CancellationTokenSource _changeCts;
private static ProcessStartInfo _startInfo;
private static Process _aLogViewerProcess;
public override void Load()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Expected O, but got Unknown
Logger = ((BasePlugin)this).Log;
_port = ((BasePlugin)this).Config.Bind<int>("General", "Port", 9999, new ConfigDescription("Port to listen on", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1024, 65535), global::System.Array.Empty<object>()));
_logToConsole = ((BasePlugin)this).Config.Bind<bool>("General", "LogToConsole", true, new ConfigDescription("Log to the BepInEx Console?", (AcceptableValueBase)null, global::System.Array.Empty<object>()));
ConfigEntry<int> port = _port;
object obj = <>c.<>9__7_0;
if (obj == null)
{
EventHandler val = delegate
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
CancellationTokenSource changeCts = _changeCts;
if (changeCts != null)
{
changeCts.Cancel();
}
CancellationTokenSource changeCts2 = _changeCts;
if (changeCts2 != null)
{
changeCts2.Dispose();
}
_changeCts = new CancellationTokenSource();
global::System.Threading.Tasks.Task.Run((Func<global::System.Threading.Tasks.Task>)([AsyncStateMachine(typeof(<>c.<<Load>b__7_4>d))] () =>
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
<>c.<<Load>b__7_4>d <<Load>b__7_4>d = default(<>c.<<Load>b__7_4>d);
<<Load>b__7_4>d.<>t__builder = AsyncTaskMethodBuilder.Create();
<<Load>b__7_4>d.<>1__state = -1;
((AsyncTaskMethodBuilder)(ref <<Load>b__7_4>d.<>t__builder)).Start<<>c.<<Load>b__7_4>d>(ref <<Load>b__7_4>d);
return ((AsyncTaskMethodBuilder)(ref <<Load>b__7_4>d.<>t__builder)).Task;
}), _changeCts.Token);
};
<>c.<>9__7_0 = val;
obj = (object)val;
}
port.SettingChanged += (EventHandler)obj;
StartALogViewer();
StartUdpClient(_port.Value);
Logger.Listeners.Add((ILogListener)(object)new ALogListener());
UniLog.OnLog += delegate(string msg)
{
UdpLog(msg, (LogLevel)8, _logToConsole.Value);
};
UniLog.OnWarning += delegate(string msg)
{
UdpLog(msg, (LogLevel)4, _logToConsole.Value);
};
UniLog.OnError += delegate(string msg)
{
UdpLog(msg, (LogLevel)2, _logToConsole.Value);
};
ManualLogSource logger = Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("NepuShiro.ALogSender");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is loaded!");
}
logger.LogInfo(val2);
}
private static void StartALogViewer()
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
if (_startInfo == null)
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (directoryName == null)
{
Logger.LogError((object)"Could not get main directory");
return;
}
string text = Path.Combine(directoryName, "ALogViewer.exe");
if (!File.Exists(text))
{
ManualLogSource logger = Logger;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(27, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ALogViewer.exe not found - ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
}
logger.LogError(val);
return;
}
_startInfo = new ProcessStartInfo
{
FileName = text,
WorkingDirectory = directoryName,
Arguments = _port.Value.ToString(),
UseShellExecute = false,
WindowStyle = (ProcessWindowStyle)0,
CreateNoWindow = false
};
}
else
{
_startInfo.Arguments = _port.Value.ToString();
}
if (_startInfo != null)
{
Process aLogViewerProcess = _aLogViewerProcess;
if (aLogViewerProcess != null)
{
aLogViewerProcess.Kill();
}
Process aLogViewerProcess2 = _aLogViewerProcess;
if (aLogViewerProcess2 != null)
{
((Component)aLogViewerProcess2).Dispose();
}
_aLogViewerProcess = Process.Start(_startInfo);
}
}
private static void StartUdpClient(int port)
{
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Expected O, but got Unknown
try
{
UdpClient udpClient = _udpClient;
if (udpClient != null)
{
udpClient.Close();
}
UdpClient udpClient2 = _udpClient;
if (udpClient2 != null)
{
udpClient2.Dispose();
}
_udpClient = new UdpClient
{
EnableBroadcast = true
};
_udpClient.Client.SetSocketOption((SocketOptionLevel)65535, (SocketOptionName)4, true);
_udpClient.Client.Bind((EndPoint)new IPEndPoint(IPAddress.Any, port));
Logger.LogMessage((object)"UDP Client started");
}
catch (global::System.Exception ex)
{
ManualLogSource logger = Logger;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(21, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error in UDP Client: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logger.LogError(val);
}
}
private static void UdpLog(string msg, LogLevel level = 16, bool logToLocal = false)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
UdpLogInternal(msg, level, logToLocal);
}
private static void UdpLogInternal(string message, LogLevel level, bool logToLocal)
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Expected O, but got Unknown
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
try
{
if (logToLocal)
{
Logger.Log(level, (object)message);
}
if (_udpClient != null)
{
byte[] bytes = Encoding.UTF8.GetBytes(DataTypeExtensions.ToMillisecondTimeString(global::System.DateTime.Now) + " " + message);
_udpClient.Send(bytes, bytes.Length, "255.255.255.255", _port.Value);
}
}
catch (global::System.Exception ex)
{
ManualLogSource logger = Logger;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(37, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error sending message to UDP Server: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logger.LogError(val);
}
}
}
public static class PluginMetadata
{
public const string GUID = "NepuShiro.ALogSender";
public const string NAME = "ALogViewer";
public const string VERSION = "1.0.0";
public const string AUTHORS = "NepuShiro";
public const string REPOSITORY_URL = "https://github.com/NepuShiro/ALogSender";
}