using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.ProtoFlux;
using FrooxEngine.ProtoFlux.Core;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes;
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("LeCloutPanda")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+14e4d9b92f613db16c101c4d5c9b13ac3fddd837")]
[assembly: AssemblyProduct("Flux Grouper")]
[assembly: AssemblyTitle("FluxGrouper")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/LeCloutPanda/FluxGrouper")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace FluxGrouper;
[ResonitePlugin("dev.lecloutpanda.fluxgrouper", "Flux Grouper", "1.0.1", "LeCloutPanda", "https://github.com/LeCloutPanda/FluxGrouper")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Patch : BasePlugin
{
[HarmonyPatch(typeof(ProtoFluxTool), "GenerateMenuItems")]
private class ProtoFluxToolPatch
{
[HarmonyPostfix]
private static void Postfix(ProtoFluxTool __instance, InteractionHandler tool, ContextMenu menu, SyncRefList<ProtoFluxNodeVisual> ____selectedNodes)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Expected O, but got Unknown
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Expected O, but got Unknown
ProtoFluxTool __instance2 = __instance;
SyncRefList<ProtoFluxNodeVisual> ____selectedNodes2 = ____selectedNodes;
ContextMenu menu2 = menu;
if (!ENABLED.Value || ((SyncElementList<SyncRef<ProtoFluxNodeVisual>>)(object)____selectedNodes2).Count <= 0 || ((Component)__instance2).Slot.ActiveUser != ((Worker)__instance2).LocalUser)
{
return;
}
ContextMenu obj = menu2;
LocaleString val = LocaleString.op_Implicit("Recalculate Flux Groups");
Uri val2 = new Uri("resdb:///05616f9bc2e93d18d9fa3a8b98dbd267bcaa5190bc222e384c743945f37ff315.png");
colorX? val3 = colorX.Orange;
obj.AddItem(ref val, val2, ref val3).Button.LocalPressed += (ButtonEventHandler)delegate(IButton button, ButtonEventData data)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Expected O, but got Unknown
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Expected O, but got Unknown
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
IButton button2 = button;
try
{
Slot temp = ((Component)((Component)__instance2).Slot.ActiveUserRoot).Slot.AddSlot("FluxGrouper - Temp", true);
temp.PersistentSelf = false;
Link link = ((ContainerWorker<Component>)(object)temp).AttachComponent<Link>(true, (Action<Link>)null);
link.A.Target = (INode)((Component)____selectedNodes2[0]).Slot.GetComponentInParents<ProtoFluxNode>((Predicate<ProtoFluxNode>)null, true, false);
Action val4 = default(Action);
((ComponentBase<Component>)(object)link).RunInUpdates(3, (Action)delegate
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
//IL_004b: Expected O, but got Unknown
if (link != null && !((Worker)link).IsRemoved)
{
link.A.Target = null;
Link obj3 = link;
Action obj4 = val4;
if (obj4 == null)
{
Action val5 = delegate
{
if (temp != null && !((Worker)temp).IsRemoved)
{
temp.Destroy(false);
}
};
Action val6 = val5;
val4 = val5;
obj4 = val6;
}
((ComponentBase<Component>)(object)obj3).RunInUpdates(3, obj4);
}
});
}
catch (global::System.Exception ex)
{
Logger.LogError((object)ex);
}
finally
{
((ComponentBase<Component>)(object)__instance2).RunInUpdates(6, (Action)delegate
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
Slot obj2 = ((Component)((Component)__instance2).Slot.ActiveUserRoot).Slot.FindChild("FluxGrouper - Temp");
if (obj2 != null)
{
obj2.Destroy();
}
Enumerator<ProtoFluxNodeVisual> enumerator = ____selectedNodes2.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ProtoFluxNodeVisual current = enumerator.Current;
if (current != null)
{
((SyncField<bool>)(object)current.IsSelected).Value = false;
}
}
}
finally
{
((global::System.IDisposable)enumerator).Dispose();
}
((SyncElementList<SyncRef<ProtoFluxNodeVisual>>)(object)____selectedNodes2).Clear();
menu2.CloseMenu(button2, data);
});
}
};
}
}
private static ManualLogSource Logger;
private static ConfigEntry<bool> ENABLED;
public override void Load()
{
ENABLED = ((BasePlugin)this).Config.Bind<bool>("General", "Create Context Menu Item", true, "Create Context Menu item for fixing flux groupings");
Logger = ((BasePlugin)this).Log;
((BasePlugin)this).HarmonyInstance.PatchAll();
}
}
public static class PluginMetadata
{
public const string GUID = "dev.lecloutpanda.fluxgrouper";
public const string NAME = "Flux Grouper";
public const string VERSION = "1.0.1";
public const string AUTHORS = "LeCloutPanda";
public const string REPOSITORY_URL = "https://github.com/LeCloutPanda/FluxGrouper";
}