using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigWalk.ReplayLauncher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Starts Big Replay alongside a modded Big Walk launch.")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+e65c9e34ee7248944eb473c691106a7deb3a3008")]
[assembly: AssemblyProduct("BigWalk.ReplayLauncher")]
[assembly: AssemblyTitle("BigWalk.ReplayLauncher")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BigWalk.ReplayLauncher
{
[BepInPlugin("com.bigwalk.replaylauncher", "Big Walk — Replay Launcher", "0.1.1")]
public class Plugin : BasePlugin
{
public const string Guid = "com.bigwalk.replaylauncher";
private const string ReplayMutexName = "Local\\BigReplay.Desktop";
private const string ReplayProcessName = "BigReplay";
private static ConfigEntry<bool> Enabled;
private static ConfigEntry<int> GraceSeconds;
public override void Load()
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Expected O, but got Unknown
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Expected O, but got Unknown
Enabled = ((BasePlugin)this).Config.Bind<bool>("Launcher", "Enabled", true, "Start Big Replay automatically alongside this modded launch.");
GraceSeconds = ((BasePlugin)this).Config.Bind<int>("Launcher", "GraceSeconds", 25, new ConfigDescription("Seconds to wait after the game exits before Big Replay closes itself (covers quick relaunches).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 600), Array.Empty<object>()));
if (!Enabled.Value)
{
((BasePlugin)this).Log.LogInfo((object)"Disabled in config; not starting Big Replay.");
return;
}
bool flag = default(bool);
try
{
string text = ResolveExePath();
if (text == null)
{
((BasePlugin)this).Log.LogWarning((object)"BigReplay.exe was not found at <profile>/BigReplay/BigReplay.exe; the package payload appears to be missing, so nothing was started.");
return;
}
if (IsReplayRunning())
{
((BasePlugin)this).Log.LogInfo((object)"Big Replay is already running; leaving it alone.");
return;
}
int id = Process.GetCurrentProcess().Id;
using Process process = Process.Start(new ProcessStartInfo(text)
{
UseShellExecute = false,
WorkingDirectory = Path.GetDirectoryName(text),
ArgumentList =
{
"--exit-with-game",
id.ToString(),
"--grace",
GraceSeconds.Value.ToString()
}
});
ManualLogSource log = ((BasePlugin)this).Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(41, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Started Big Replay (pid ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int?>(process?.Id);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") for game pid ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(id);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
}
log.LogInfo(val);
}
catch (Exception ex)
{
ManualLogSource log2 = ((BasePlugin)this).Log;
BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Could not start Big Replay: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log2.LogError(val2);
}
}
private static string ResolveExePath()
{
string text = Path.Combine(Path.GetFullPath(Path.Combine(Paths.PluginPath, "..", "..")), "BigReplay", "BigReplay.exe");
if (!File.Exists(text))
{
return null;
}
return text;
}
private static bool IsReplayRunning()
{
try
{
if (Mutex.TryOpenExisting("Local\\BigReplay.Desktop", out Mutex result))
{
result.Dispose();
return true;
}
}
catch (Exception)
{
}
try
{
Process[] processesByName = Process.GetProcessesByName("BigReplay");
try
{
return processesByName.Length != 0;
}
finally
{
Process[] array = processesByName;
for (int i = 0; i < array.Length; i++)
{
array[i].Dispose();
}
}
}
catch (Exception)
{
return false;
}
}
}
}