Decompiled source of DeleagateRefEditing v1.0.0

plugins/DeleagateRefEditing.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.UIX;
using FrooxEngine.Undo;
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("eia485")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5b601c508e3fa4a35750e3aa1cf3031155ce2ee8")]
[assembly: AssemblyProduct("DeleagateRefEditing")]
[assembly: AssemblyTitle("DeleagateRefEditing")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/EIA485/NeosDeleagateRefEditing")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace DeleagateRefEditing;

[ResonitePlugin("net.eia485.DeleagateRefEditing", "DeleagateRefEditing", "1.0.0", "eia485", "https://github.com/EIA485/NeosDeleagateRefEditing")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[HarmonyPatch(typeof(DelegateEditor), "Setup")]
	private class Patch
	{
		private static void Postfix(DelegateEditor __instance, ISyncDelegate target)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (uiGen.Value)
			{
				((Component)__instance).Slot.Tag = FanyUiTag;
				if (rightAllignNull.Value)
				{
					Enumerable.Last<Slot>((global::System.Collections.Generic.IEnumerable<Slot>)(object)((Component)__instance).Slot[0].Children).OrderOffset = 10000L;
				}
				UIBuilder val = new UIBuilder(((Component)__instance).Slot[0], (Slot)null);
				RadiantUI_Constants.SetupEditorStyle(val, false);
				val.Style.MinWidth = 24f;
				val.Style.FlexibleWidth = 100f;
				Button val2 = val.Button();
				RefEditor val3 = ((ContainerWorker<Component>)(object)((Component)val2).Slot).AttachComponent<RefEditor>(true, (Action<RefEditor>)null);
				val2.Pressed.Target = SetReference.CreateDelegate<ButtonEventHandler>((object)val3);
				Text componentInChildren = ((Component)val2).Slot.GetComponentInChildren<Text>((Predicate<Text>)null, false, false);
				((ISyncRef)((Worker)val3).GetSyncMember("_textDrive")).Target = (IWorldElement)(object)componentInChildren.Content;
				((ISyncRef)((Worker)val3).GetSyncMember("_targetRef")).Target = (IWorldElement)(object)target;
				((ISyncRef)((Worker)val3).GetSyncMember("_button")).Target = (IWorldElement)(object)val2;
				val.Style.FlexibleWidth = -1f;
				((Component)__instance).Slot[0][0].OrderOffset = -2L;
				LocaleString val4 = LocaleString.op_Implicit("↑");
				Button obj = val.Button(ref val4);
				((Component)obj).Slot.OrderOffset = -1L;
				obj.Pressed.Target = OpenWorkerInspectorButton.CreateDelegate<ButtonEventHandler>((object)val3);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnChanges")]
		private static void OnChangesPostfix(DelegateEditor __instance, FieldDrive<string> ____textDrive, RelayRef<ISyncDelegate> ____targetDelegate)
		{
			if (((Component)__instance).Slot.Tag == FanyUiTag && ((LinkBase<IField<string>>)(object)____textDrive).IsLinkValid)
			{
				ISyncDelegate target = ((SyncRef<ISyncDelegate>)(object)____targetDelegate).Target;
				if (target != null && ((ISyncRef)target).Target != null && target.Method != null)
				{
					((IValue<string>)(object)((SyncRef<IField<string>>)(object)____textDrive).Target).Value = target.MethodName + " on " + ((MemberInfo)((object)target).GetType()).Name + ")";
				}
			}
		}
	}

	[HarmonyPatch]
	private class UndoPatch
	{
		private static MethodBase TargetMethod()
		{
			return (MethodBase)(object)Enumerable.First<MethodInfo>((global::System.Collections.Generic.IEnumerable<MethodInfo>)typeof(SetReferenceExtensions).GetMethods(), (Func<MethodInfo, bool>)((MethodInfo m) => ((MemberInfo)m).Name == "CreateUndoPoint" && !((MethodBase)m).IsGenericMethod));
		}

		private static bool Prefix(ISyncRef reference)
		{
			return ((object)reference).GetType().IsAssignableTo(typeof(SyncRef<>));
		}
	}

	private static readonly string FanyUiTag = "RetargetableDelegateEditor";

	private static ConfigEntry<bool> uiGen;

	private static ConfigEntry<bool> rightAllignNull;

	private static readonly MethodInfo SetReference = AccessTools.Method(typeof(RefEditor), "SetReference", (global::System.Type[])null, (global::System.Type[])null);

	private static readonly MethodInfo OpenWorkerInspectorButton = AccessTools.Method(typeof(RefEditor), "OpenWorkerInspectorButton", (global::System.Type[])null, (global::System.Type[])null);

	public override void Load()
	{
		uiGen = ((BasePlugin)this).Config.Bind<bool>("options", "EnableUiGeneration", true, "when false disable generation of retargeting fields next to delegate editors");
		rightAllignNull = ((BasePlugin)this).Config.Bind<bool>("options", "rightAllignNull", false, "when true moves the null button is on the right otherwise its between the fields");
		((BasePlugin)this).HarmonyInstance.PatchAll();
	}

	public override bool Unload()
	{
		try
		{
			((BasePlugin)this).HarmonyInstance.UnpatchSelf();
			return true;
		}
		catch
		{
			return false;
		}
	}
}
public static class PluginMetadata
{
	public const string GUID = "net.eia485.DeleagateRefEditing";

	public const string NAME = "DeleagateRefEditing";

	public const string VERSION = "1.0.0";

	public const string AUTHORS = "eia485";

	public const string REPOSITORY_URL = "https://github.com/EIA485/NeosDeleagateRefEditing";
}

patchers/DeleagateRefEditingPrePatcher.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx.Preloader.Core.Patching;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;

[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("DeleagateRefEditingPrePatcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5b601c508e3fa4a35750e3aa1cf3031155ce2ee8")]
[assembly: AssemblyProduct("DeleagateRefEditingPrePatcher")]
[assembly: AssemblyTitle("DeleagateRefEditingPrePatcher")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace DeleagateRefEditing;

[PatcherPluginInfo("net.eia485.DeleagateRefEditingPrePatcher", "DeleagateRefEditingPrePatcher", "1.0.0")]
public class Patcher : BasePatcher
{
	[TargetAssembly("FrooxEngine.dll")]
	public void PatchAssembly(AssemblyDefinition assembly)
	{
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Expected O, but got Unknown
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		ModuleDefinition mainModule = assembly.MainModule;
		ModuleDefinition module = ((MemberReference)mainModule.TypeSystem.Object.Resolve()).Module;
		TypeDefinition type = FindType(mainModule, "FrooxEngine.SyncDelegate`1");
		TypeDefinition type2 = FindType(mainModule, "FrooxEngine.ISyncRef");
		TypeDefinition val = FindType(module, "System.Delegate");
		TypeDefinition val2 = FindType(module, "System.Reflection.MethodBase");
		TypeDefinition val3 = FindType(module, "System.Reflection.MemberInfo");
		TypeDefinition val4 = FindType(module, "System.Type");
		MethodDefinition val5 = FindMethod(type, "FrooxEngine.ISyncRef.TrySet");
		MethodDefinition val6 = FindMethod(val4, "GetType");
		MethodDefinition val7 = FindMethod(val4, "IsAssignableTo");
		MethodDefinition getMethod = FindProperty(val, "Method").GetMethod;
		MethodDefinition getMethod2 = FindProperty(val2, "IsStatic").GetMethod;
		MethodDefinition getMethod3 = FindProperty(val3, "DeclaringType").GetMethod;
		MethodDefinition setMethod = FindProperty(type2, "Target").SetMethod;
		FieldDefinition val8 = FindField(type, "_target");
		mainModule.ImportReference((TypeReference)(object)val);
		mainModule.ImportReference((TypeReference)(object)val2);
		mainModule.ImportReference((TypeReference)(object)val3);
		mainModule.ImportReference((TypeReference)(object)val4);
		MethodReference val9 = mainModule.ImportReference((MethodReference)(object)val6);
		MethodReference val10 = mainModule.ImportReference((MethodReference)(object)val7);
		MethodReference val11 = mainModule.ImportReference((MethodReference)(object)getMethod);
		MethodReference val12 = mainModule.ImportReference((MethodReference)(object)getMethod2);
		MethodReference val13 = mainModule.ImportReference((MethodReference)(object)getMethod3);
		val5.Body = new MethodBody(val5);
		MethodBody body = val5.Body;
		body.InitLocals = false;
		ILProcessor iLProcessor = body.GetILProcessor();
		Instruction val14 = Instruction.Create(OpCodes.Ldc_I4_0);
		iLProcessor.Emit(OpCodes.Ldarg_0);
		iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val8);
		iLProcessor.Emit(OpCodes.Brfalse, val14);
		iLProcessor.Emit(OpCodes.Ldarg_0);
		iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val8);
		iLProcessor.Emit(OpCodes.Callvirt, val11);
		iLProcessor.Emit(OpCodes.Callvirt, val12);
		iLProcessor.Emit(OpCodes.Brtrue, val14);
		iLProcessor.Emit(OpCodes.Ldarg_1);
		iLProcessor.Emit(OpCodes.Callvirt, val9);
		iLProcessor.Emit(OpCodes.Ldarg_0);
		iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val8);
		iLProcessor.Emit(OpCodes.Callvirt, val11);
		iLProcessor.Emit(OpCodes.Callvirt, val13);
		iLProcessor.Emit(OpCodes.Callvirt, val10);
		iLProcessor.Emit(OpCodes.Brfalse, val14);
		iLProcessor.Emit(OpCodes.Ldarg_0);
		iLProcessor.Emit(OpCodes.Ldarg_1);
		iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)setMethod);
		iLProcessor.Emit(OpCodes.Ldc_I4_1);
		iLProcessor.Emit(OpCodes.Ret);
		iLProcessor.Append(val14);
		iLProcessor.Emit(OpCodes.Ret);
		body.MaxStackSize = 3;
		MethodBodyRocks.OptimizeMacros(body);
	}

	private static TypeDefinition FindType(ModuleDefinition module, string fullName)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		TypeDefinition type = module.GetType(fullName);
		if (type != null)
		{
			return type;
		}
		throw new InvalidOperationException("Type not found: " + fullName);
	}

	private static MethodDefinition FindMethod(TypeDefinition type, string name)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		string name2 = name;
		return Enumerable.FirstOrDefault<MethodDefinition>((global::System.Collections.Generic.IEnumerable<MethodDefinition>)Enumerable.OrderBy<MethodDefinition, int>((global::System.Collections.Generic.IEnumerable<MethodDefinition>)type.Methods, (Func<MethodDefinition, int>)((MethodDefinition m) => ((MethodReference)m).Parameters.Count)), (Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == name2)) ?? throw new InvalidOperationException("Method not found: " + ((MemberReference)type).FullName + "." + name2);
	}

	private static PropertyDefinition FindProperty(TypeDefinition type, string name)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		string name2 = name;
		return Enumerable.FirstOrDefault<PropertyDefinition>((global::System.Collections.Generic.IEnumerable<PropertyDefinition>)type.Properties, (Func<PropertyDefinition, bool>)((PropertyDefinition p) => ((MemberReference)p).Name == name2)) ?? throw new InvalidOperationException("Property not found: " + ((MemberReference)type).FullName + "." + name2);
	}

	private static FieldDefinition FindField(TypeDefinition type, string name)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		string name2 = name;
		return Enumerable.FirstOrDefault<FieldDefinition>((global::System.Collections.Generic.IEnumerable<FieldDefinition>)type.Fields, (Func<FieldDefinition, bool>)((FieldDefinition f) => ((MemberReference)f).Name == name2)) ?? throw new InvalidOperationException("Field not found: " + ((MemberReference)type).FullName + "." + name2);
	}
}
internal static class MyPluginInfo
{
	public const string PLUGIN_GUID = "net.eia485.DeleagateRefEditingPrePatcher";

	public const string PLUGIN_NAME = "DeleagateRefEditingPrePatcher";

	public const string PLUGIN_VERSION = "1.0.0";

	public const string PLUGIN_AUTHORS = "DeleagateRefEditingPrePatcher";

	public const string PLUGIN_REPOSITORY_URL = "";
}