using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; 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 BepInExResoniteShim; using Elements.Core; using FrooxEngine; using FrooxEngine.ProtoFlux; using FrooxEngine.UIX; using HarmonyLib; [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: AssemblyCompany("art0007i")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("2.2.11.0")] [assembly: AssemblyInformationalVersion("2.2.11+2c04bdeba39e815ab33a0ce93cbaafb432a95e0c")] [assembly: AssemblyProduct("ShowDelegates")] [assembly: AssemblyTitle("ShowDelegates")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/art0007i/ShowDelegates")] [assembly: AssemblyVersion("2.2.11.0")] [module: RefSafetyRules(11)] namespace ShowDelegates; public struct MethodArgs { public global::System.Type returnType; public global::System.Type[] argumentTypes; public MethodArgs(global::System.Type returnType, global::System.Type[] argumentTypes) { this.returnType = returnType; this.argumentTypes = argumentTypes; } public MethodArgs(params global::System.Type[] argumentTypes) { returnType = typeof(void); this.argumentTypes = argumentTypes; } public MethodArgs(MethodInfo source) { returnType = source.ReturnType; argumentTypes = Enumerable.ToArray(Enumerable.Select((global::System.Collections.Generic.IEnumerable)((MethodBase)source).GetParameters(), (Func)((ParameterInfo f) => f.ParameterType))); } public string ToString() { string obj = ((returnType == (global::System.Type)null) ? "void" : ((MemberInfo)returnType).Name); string text = string.Join(", ", Enumerable.Select((global::System.Collections.Generic.IEnumerable)argumentTypes, (Func)((global::System.Type t) => ((MemberInfo)t).Name))); return obj + " (" + text + ")"; } public bool Equals(object obj) { if (obj is MethodArgs methodArgs) { MethodArgs methodArgs2 = this; if (methodArgs2.returnType != methodArgs.returnType) { return false; } if (methodArgs2.argumentTypes.Length != methodArgs.argumentTypes.Length) { return false; } for (int i = 0; i < methodArgs2.argumentTypes.Length; i++) { if (methodArgs2.argumentTypes[i] != methodArgs.argumentTypes[i]) { return false; } } return true; } return base.Equals(obj); } public static bool operator ==(MethodArgs lhs, MethodArgs rhs) { return ((object)lhs/*cast due to .constrained prefix*/).Equals((object)rhs); } public static bool operator !=(MethodArgs lhs, MethodArgs rhs) { return !((object)lhs/*cast due to .constrained prefix*/).Equals((object)rhs); } public int GetHashCode() { int num = 17; num = num * 23 + ((returnType != (global::System.Type)null) ? ((object)returnType).GetHashCode() : 0); if (argumentTypes != null) { global::System.Type[] array = argumentTypes; foreach (global::System.Type type in array) { num = num * 23 + ((type != (global::System.Type)null) ? ((object)type).GetHashCode() : 0); } } return num; } } internal class Helper { public static Dictionary argumentLookup; public static global::System.Type ClassifyDelegate(MethodInfo m) { global::System.Type result = default(global::System.Type); if (argumentLookup.TryGetValue(new MethodArgs(m), ref result)) { return result; } global::System.Type[] array = Enumerable.ToArray(Enumerable.Select((global::System.Collections.Generic.IEnumerable)((MethodBase)m).GetParameters(), (Func)((ParameterInfo para) => para.ParameterType))); if (array.Length == 3 && array[0] == typeof(IButton) && array[1] == typeof(ButtonEventData)) { return typeof(ButtonEventHandler<>).MakeGenericType(new global::System.Type[1] { array[2] }); } return GetFuncOrAction(m, array); } public static global::System.Type GetFuncOrAction(MethodInfo m) { global::System.Type[] p = Enumerable.ToArray(Enumerable.Select((global::System.Collections.Generic.IEnumerable)((MethodBase)m).GetParameters(), (Func)((ParameterInfo para) => para.ParameterType))); return GetFuncOrAction(m, p); } public static global::System.Type GetFuncOrAction(MethodInfo m, global::System.Type[] p) { if (m.ReturnType == typeof(void)) { return Expression.GetActionType(p); } p = Enumerable.ToArray(Enumerable.Concat((global::System.Collections.Generic.IEnumerable)p, (global::System.Collections.Generic.IEnumerable)new global::System.Type[1] { m.ReturnType })); return Expression.GetFuncType(p); } static Helper() { Dictionary val = new Dictionary(); val.Add(new MethodArgs(typeof(IButton), typeof(ButtonEventData)), typeof(ButtonEventHandler)); val.Add(new MethodArgs(typeof(bool), new global::System.Type[2] { typeof(IGrabbable), typeof(Grabber) }), typeof(GrabCheck)); val.Add(new MethodArgs(typeof(ITouchable), typeof(TouchEventInfo).MakeByRefType()), typeof(TouchEvent)); val.Add(new MethodArgs(typeof(ITouchable), new global::System.Type[5] { typeof(RelayTouchSource), typeof(float3).MakeByRefType(), typeof(float3).MakeByRefType(), typeof(float3).MakeByRefType(), typeof(bool).MakeByRefType() }), typeof(TouchableGetter)); val.Add(new MethodArgs(typeof(SlotGizmo), typeof(SlotGizmo)), typeof(SlotGizmoReplacement)); val.Add(new MethodArgs(typeof(LegacyWorldItem)), typeof(LegacyWorldItemAction)); val.Add(new MethodArgs(typeof(Display), typeof(Slot)), typeof(DisplayItemHandler)); val.Add(new MethodArgs(typeof(bool), new global::System.Type[2] { typeof(Snapper), typeof(SnapTarget) }), typeof(SnapperFilter)); val.Add(new MethodArgs(typeof(DevCreateNewForm), typeof(Slot)), typeof(ItemCreated)); val.Add(new MethodArgs(typeof(ModalOverlay), new global::System.Type[1] { typeof(Slot) }), typeof(ModalOverlayConstructor)); argumentLookup = val; } } [ResonitePlugin("art0007i.ShowDelegates", "ShowDelegates", "2.2.11", "art0007i", "https://github.com/art0007i/ShowDelegates")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BasePlugin { [HarmonyPatch(typeof(WorkerInitializer), "Initialize", new global::System.Type[] { typeof(global::System.Type) })] public static class InitializeAllDelegatesPatch { public static global::System.Collections.Generic.IEnumerable Transpiler(global::System.Collections.Generic.IEnumerable instructions) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown List val = Enumerable.ToList(instructions); for (int i = 0; i < val.Count; i++) { object operand = val[i].operand; MethodInfo val2 = (MethodInfo)((operand is MethodInfo) ? operand : null); if (val2 != null && ((MemberInfo)val2).Name == "GetMethods") { MethodInfo method = typeof(InitializeAllDelegatesPatch).GetMethod("GetAllMethodsForRealThisTime"); val[i] = new CodeInstruction(OpCodes.Call, (object)method); } } return Enumerable.AsEnumerable((global::System.Collections.Generic.IEnumerable)val); } public static MethodInfo[] GetAllMethodsForRealThisTime(global::System.Type t, BindingFlags _flags) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) Dictionary val = Pool.BorrowDictionary(); global::System.Type type = t; while (type != (global::System.Type)null) { MethodInfo[] methods = type.GetMethods(AccessTools.all); foreach (MethodInfo val2 in methods) { if (!val.ContainsKey(((MethodBase)val2).MethodHandle)) { val.Add(((MethodBase)val2).MethodHandle, val2); } } type = type.BaseType; } MethodInfo[] result = Enumerable.ToArray((global::System.Collections.Generic.IEnumerable)val.Values); Pool.Return(ref val); return result; } } [HarmonyPatch(typeof(ProtoFluxTool), "OnCreateDelegateProxy")] private class FixProtoFluxDeleagtes { [CompilerGenerated] private sealed class d__1 : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator, global::System.Collections.IEnumerator, global::System.IDisposable { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private global::System.Collections.Generic.IEnumerable codes; public global::System.Collections.Generic.IEnumerable <>3__codes; private global::System.Collections.Generic.IEnumerator <>7__wrap1; CodeInstruction global::System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object global::System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void global::System.IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 1) <= 1u) { try { } finally { <>m__Finally1(); } } <>7__wrap1 = null; <>1__state = -2; } private bool MoveNext() { //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>7__wrap1 = codes.GetEnumerator(); <>1__state = -3; break; case 1: <>1__state = -3; break; case 2: <>1__state = -3; break; } if (((global::System.Collections.IEnumerator)<>7__wrap1).MoveNext()) { CodeInstruction current = <>7__wrap1.Current; object operand = current.operand; MethodInfo val = (MethodInfo)((operand is MethodInfo) ? operand : null); if (val != null && ((MemberInfo)val).Name == "GetType") { MethodInfo method = typeof(FixProtoFluxDeleagtes).GetMethod("GetTypeFixed"); <>2__current = new CodeInstruction(OpCodes.Call, (object)method); <>1__state = 1; return true; } <>2__current = current; <>1__state = 2; return true; } <>m__Finally1(); <>7__wrap1 = null; return false; } catch { //try-fault ((global::System.IDisposable)this).Dispose(); throw; } } bool global::System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap1 != null) { ((global::System.IDisposable)<>7__wrap1).Dispose(); } } [DebuggerHidden] void global::System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { d__1 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__1(0); } d__.codes = <>3__codes; return d__; } [DebuggerHidden] global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } public static void Prefix(IButton button, ButtonEventData eventData, ref global::System.Delegate target) { try { global::System.Type funcOrAction = Helper.GetFuncOrAction(target.Method); target = target.Method.CreateDelegate(funcOrAction, target.Target); } catch (global::System.Exception ex) { Log.LogDebug((object)("Exception in FixProtoFluxDeleagtes.Prefix: " + (object)ex)); } } [IteratorStateMachine(typeof(d__1))] public static global::System.Collections.Generic.IEnumerable Transpiler(global::System.Collections.Generic.IEnumerable codes) { global::System.Collections.Generic.IEnumerator enumerator = codes.GetEnumerator(); try { while (((global::System.Collections.IEnumerator)enumerator).MoveNext()) { CodeInstruction current = enumerator.Current; object operand = current.operand; MethodInfo val = (MethodInfo)((operand is MethodInfo) ? operand : null); if (val != null && ((MemberInfo)val).Name == "GetType") { MethodInfo method = typeof(FixProtoFluxDeleagtes).GetMethod("GetTypeFixed"); yield return new CodeInstruction(OpCodes.Call, (object)method); } else { yield return current; } } } finally { ((global::System.IDisposable)enumerator)?.Dispose(); } } public static global::System.Type? GetTypeFixed(string typeName) { return typeof(ProtoFluxTool).Assembly.GetType(typeName); } } [HarmonyPatch(typeof(WorkerInspector))] [HarmonyPatch("BuildInspectorUI")] private class WorkerInspector_BuildInspectorUI_Patch { [CompilerGenerated] private sealed class d__3 : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator, global::System.Collections.IEnumerator, global::System.IDisposable { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private global::System.Collections.Generic.IEnumerable codes; public global::System.Collections.Generic.IEnumerable <>3__codes; private global::System.Collections.Generic.IEnumerator <>7__wrap1; private CodeInstruction 5__3; CodeInstruction global::System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object global::System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__3(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void global::System.IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 1) <= 6u) { try { } finally { <>m__Finally1(); } } <>7__wrap1 = null; 5__3 = null; <>1__state = -2; } private bool MoveNext() { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Expected O, but got Unknown //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Expected O, but got Unknown //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>7__wrap1 = codes.GetEnumerator(); <>1__state = -3; break; case 1: { <>1__state = -3; object operand = 5__3.operand; MethodBase val = (MethodBase)((operand is MethodBase) ? operand : null); if (val != null && ((MemberInfo)val).Name == "get_SyncMethodCount") { <>2__current = new CodeInstruction(OpCodes.Pop, (object)null); <>1__state = 2; return true; } goto IL_01af; } case 2: <>1__state = -3; <>2__current = new CodeInstruction(OpCodes.Ldc_I4_0, (object)null); <>1__state = 3; return true; case 3: <>1__state = -3; <>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null); <>1__state = 4; return true; case 4: <>1__state = -3; <>2__current = new CodeInstruction(OpCodes.Ldarg_1, (object)null); <>1__state = 5; return true; case 5: <>1__state = -3; <>2__current = new CodeInstruction(OpCodes.Ldarg_2, (object)null); <>1__state = 6; return true; case 6: <>1__state = -3; <>2__current = new CodeInstruction(OpCodes.Call, (object)typeof(WorkerInspector_BuildInspectorUI_Patch).GetMethod("GenerateDelegates")); <>1__state = 7; return true; case 7: { <>1__state = -3; goto IL_01af; } IL_01af: 5__3 = null; break; } if (((global::System.Collections.IEnumerator)<>7__wrap1).MoveNext()) { 5__3 = <>7__wrap1.Current; <>2__current = 5__3; <>1__state = 1; return true; } <>m__Finally1(); <>7__wrap1 = null; return false; } catch { //try-fault ((global::System.IDisposable)this).Dispose(); throw; } } bool global::System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap1 != null) { ((global::System.IDisposable)<>7__wrap1).Dispose(); } } [DebuggerHidden] void global::System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { d__3 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__3(0); } d__.codes = <>3__codes; return d__; } [DebuggerHidden] global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } public static MethodInfo delegateFunc = typeof(Plugin).GetMethod("GenerateDelegateProxy", (BindingFlags)40); public static bool ProcessHidden(bool orig) { if (ShowHidden.Value) { return false; } return orig; } public static void GenerateDelegates(Worker worker, UIBuilder ui, Predicate memberFilter) { //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Expected O, but got Unknown //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_033a: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Unknown result type (might be due to invalid IL or missing references) if (ShowHidden.Value) { for (int i = 0; i < worker.SyncMemberCount; i++) { ISyncMember syncMember = worker.GetSyncMember(i); if ((memberFilter == null || memberFilter.Invoke(syncMember)) && CustomAttributeExtensions.GetCustomAttribute((MemberInfo)(object)worker.GetSyncMemberFieldInfo(i)) != null) { GenerateReferenceProxy(ui, worker.GetSyncMemberName(syncMember), (IWorldElement)(object)syncMember); } } } if (!ShowDelegates.Value || worker.SyncMethodCount <= 0) { return; } WorkerInitInfo value = Traverse.Create((object)worker).Field("InitInfo").Value; global::System.Collections.Generic.IEnumerable enumerable = (ShowNonDefault.Value ? Enumerable.AsEnumerable((global::System.Collections.Generic.IEnumerable)value.syncMethods) : Enumerable.Where((global::System.Collections.Generic.IEnumerable)value.syncMethods, (Func)((SyncMethodInfo m) => m.methodType != typeof(global::System.Delegate) && ((MethodBase)m.method).IsPublic))); if (!Enumerable.Any(enumerable)) { return; } LocaleString val = LocaleString.op_Implicit("---- SYNC METHODS HERE ----"); Text val2 = ui.Text(ref val, true, (Alignment?)(Alignment)4, true, (string)null); VerticalLayout val3 = ui.VerticalLayout(0f, 0f, (Alignment?)null, (bool?)null, (bool?)null); ((Component)val3).Slot.ActiveSelf = false; ((ContainerWorker)(object)((Component)val3).Slot).RemoveComponent((Component)(object)((ContainerWorker)(object)((Component)val3).Slot).GetComponent((Predicate)null, false)); Expander obj = ((ContainerWorker)(object)((Component)val2).Slot).AttachComponent(true, (Action)null); obj.SectionRoot.Target = ((Component)val3).Slot; obj.IsExpanded = DefaultOpen.Value; Button obj2 = ((ContainerWorker)(object)((Component)val2).Slot).AttachComponent