using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using FrooxEngine;
using HarmonyLib;
[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("ResoniteModding")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ac424560d7e5f045302448b5d459c9fa0ef74a1d")]
[assembly: AssemblyProduct("BepisResoniteWrapper")]
[assembly: AssemblyTitle("BepisResoniteWrapper")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ResoniteModding/BepisResoniteWrapper")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace BepisResoniteWrapper
{
public static class ResoniteHooks
{
[CompilerGenerated]
private static Action? m_OnEngineReady;
internal static bool OnEngineReadySubs => ResoniteHooks.OnEngineReady != null;
public static event Action OnEngineReady
{
[CompilerGenerated]
add
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
Action val = ResoniteHooks.m_OnEngineReady;
Action val2;
do
{
val2 = val;
Action val3 = (Action)global::System.Delegate.Combine((global::System.Delegate)(object)val2, (global::System.Delegate)(object)value);
val = Interlocked.CompareExchange<Action>(ref ResoniteHooks.m_OnEngineReady, val3, val2);
}
while (val != val2);
}
[CompilerGenerated]
remove
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
Action val = ResoniteHooks.m_OnEngineReady;
Action val2;
do
{
val2 = val;
Action val3 = (Action)global::System.Delegate.Remove((global::System.Delegate)(object)val2, (global::System.Delegate)(object)value);
val = Interlocked.CompareExchange<Action>(ref ResoniteHooks.m_OnEngineReady, val3, val2);
}
while (val != val2);
}
}
internal static void RunOnEngineReady()
{
Utils.SafeInvokeAll(ResoniteHooks.OnEngineReady);
}
}
[ResonitePlugin("ResoniteModding.BepisResoniteWrapper", "BepisResoniteWrapper", "1.0.0", "ResoniteModding", "https://github.com/ResoniteModding/BepisResoniteWrapper")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class Plugin : BasePlugin
{
internal static ManualLogSource Log;
public override void Load()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
RunPatches();
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("ResoniteModding.BepisResoniteWrapper");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
log.LogInfo(val);
}
private void RunPatches()
{
((BasePlugin)this).HarmonyInstance.SafePatchCategory("EngineReadyHook");
}
}
internal static class Utils
{
public static void SafeInvokeAll(this Action? evt)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
if (evt == null)
{
return;
}
global::System.Delegate[] invocationList = ((global::System.Delegate)(object)evt).GetInvocationList();
bool flag = default(bool);
foreach (global::System.Delegate @delegate in invocationList)
{
try
{
((Action)@delegate).Invoke();
}
catch (global::System.Exception ex)
{
ManualLogSource log = Plugin.Log;
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(28, 4, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Exception in ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((MemberInfo)((object)evt).GetType()).Name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" subscriber ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((MemberInfo)@delegate.Method).DeclaringType?.FullName);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((MemberInfo)@delegate.Method).Name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<global::System.Exception>(ex);
}
log.LogError(val);
}
}
}
public static void SafePatchCategory(this Harmony instance, string CategoryName)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
try
{
instance.PatchCategory(CategoryName);
}
catch (global::System.Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(43, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to patch ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(CategoryName);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(". it's hook will not fire: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<global::System.Exception>(ex);
}
log.LogError(val);
}
}
}
public static class PluginMetadata
{
public const string GUID = "ResoniteModding.BepisResoniteWrapper";
public const string NAME = "BepisResoniteWrapper";
public const string VERSION = "1.0.0";
public const string AUTHORS = "ResoniteModding";
public const string REPOSITORY_URL = "https://github.com/ResoniteModding/BepisResoniteWrapper";
}
}
namespace BepisResoniteWrapper.Hooks
{
[HarmonyPatchCategory("EngineReadyHook")]
[HarmonyPatch(typeof(Engine), "SetReady")]
internal class EngineReadyHook
{
private static void Postfix(Engine __instance)
{
if (ResoniteHooks.OnEngineReadySubs)
{
Plugin.Log.LogInfo((object)"Engine initialization finished, firing OnEngineReady event");
}
ResoniteHooks.RunOnEngineReady();
}
}
}