using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using FrooxEngine;
using HarmonyLib;
using Renderite.Shared;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v10.0", FrameworkDisplayName = ".NET 10.0")]
[assembly: AssemblyMetadata("ResoniteSdkVersion", "2.3.4")]
[assembly: AssemblyMetadata("ResoniteVersion", "2026.8.27.1094")]
[assembly: IgnoresAccessChecksTo("FrooxEngine")]
[assembly: IgnoresAccessChecksTo("Elements.Core")]
[assembly: IgnoresAccessChecksTo("Renderite.Shared")]
[assembly: AssemblyCompany("blhsrwznrghfzpr")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Synchronizes userspace laser toggles with the focused world's lasers.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+a31c306d147e80e499df5636f5a727cf3cde8a2e")]
[assembly: AssemblyProduct("UserspaceLaserSync")]
[assembly: AssemblyTitle("UserspaceLaserSync")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace UserspaceLaserSync;
[BepInPlugin("dev.blhsrwznrghfzpr.UserspaceLaserSync", "UserspaceLaserSync", "1.0.1")]
public sealed class Plugin : BasePlugin
{
public const string PluginGuid = "dev.blhsrwznrghfzpr.UserspaceLaserSync";
public const string PluginName = "UserspaceLaserSync";
public const string PluginVersion = "1.0.1";
private Harmony? _harmony;
private ConfigEntry<bool>? _enabled;
public override void Load()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Expected O, but got Unknown
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Expected O, but got Unknown
_enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable userspace laser synchronization. Changes apply immediately. When disabled, Resonite's original laser behavior is preserved.");
_enabled.SettingChanged += new EventHandler(OnEnabledChanged);
LaserSyncRuntime.SetEnabled(_enabled.Value);
_harmony = new Harmony("dev.blhsrwznrghfzpr.UserspaceLaserSync");
try
{
_harmony.PatchAll(typeof(Plugin).Assembly);
}
catch
{
_harmony.UnpatchSelf();
_enabled.SettingChanged -= new EventHandler(OnEnabledChanged);
LaserSyncRuntime.SetEnabled(enabled: false);
_enabled = null;
throw;
}
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(37, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("UserspaceLaserSync loaded. Enabled: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(_enabled.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
}
log.LogInfo(val);
}
private void OnEnabledChanged(object? sender, EventArgs args)
{
LaserSyncRuntime.SetEnabled(_enabled?.Value ?? false);
}
public override bool Unload()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
if (_enabled != null)
{
_enabled.SettingChanged -= new EventHandler(OnEnabledChanged);
}
LaserSyncRuntime.SetEnabled(enabled: false);
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
_enabled = null;
return true;
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal static class LaserEnabledPatch
{
private static readonly Predicate<InteractionHandler> LeftHand = (InteractionHandler handler) => !((Worker)handler).IsRemoved && (int)((SyncField<Chirality>)(object)handler.Side).Value == 0;
private static readonly Predicate<InteractionHandler> RightHand = (InteractionHandler handler) => !((Worker)handler).IsRemoved && (int)((SyncField<Chirality>)(object)handler.Side).Value == 1;
[HarmonyPostfix]
private static void Postfix(InteractionHandler __instance, ref bool __result)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Invalid comparison between Unknown and I4
if (!LaserSyncRuntime.IsSyncEnabled || ((Worker)__instance).IsRemoved || !((Component)__instance).IsUnderLocalUser || ((Worker)__instance).World != Userspace.UserspaceWorld)
{
return;
}
World focusedWorld = ((Worker)__instance).Engine.WorldManager.FocusedWorld;
if (focusedWorld == null || focusedWorld.IsDestroyed || focusedWorld == ((Worker)__instance).World)
{
return;
}
Chirality value = ((SyncField<Chirality>)(object)__instance.Side).Value;
Predicate<InteractionHandler> val = (((int)value == 0) ? LeftHand : (((int)value != 1) ? null : RightHand));
Predicate<InteractionHandler> val2 = val;
if (val2 != null)
{
User localUser = focusedWorld.LocalUser;
object obj;
if (localUser == null)
{
obj = null;
}
else
{
UserRoot root = localUser.Root;
obj = ((root != null) ? root.GetRegisteredComponent<InteractionHandler>(val2) : null);
}
InteractionHandler val3 = (InteractionHandler)obj;
if (val3 != null && ((Component)val3).IsUnderLocalUser)
{
ITool activeTool = __instance.ActiveTool;
__result = ((SyncField<bool>)(object)val3._laserEnabled).Value || (!(activeTool is UserspacePointer) && activeTool != null && activeTool.UsesLaser);
}
}
}
}
internal static class LaserSyncRuntime
{
private static volatile bool _enabled;
internal static bool IsSyncEnabled => _enabled;
internal static void SetEnabled(bool enabled)
{
_enabled = enabled;
}
}
public static class PluginMetadata
{
public const string GUID = "UserspaceLaserSync";
public const string NAME = "UserspaceLaserSync";
public const string VERSION = "1.0.1";
public const string AUTHORS = "blhsrwznrghfzpr";
public const string REPOSITORY_URL = "";
}