using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
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.FrooxEngine.ProtoFlux.CoreNodes;
using FrooxEngine.ProtoFlux;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes.FrooxEngine.Slots;
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, Gyztor Mizirath")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+2a40ebf1268aafef680c5f020c82e6f134252d9a")]
[assembly: AssemblyProduct("MyInspectors")]
[assembly: AssemblyTitle("MyInspectors")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Gyztor/BepisMyInspectors")]
[assembly: AssemblyVersion("1.0.2.0")]
[module: RefSafetyRules(11)]
namespace MyInspectors;
internal class PatchedSyncRef<T> : SyncRef<T>, EditorTargetField where T : class, IWorldElement
{
private RefID? remoteValue;
bool EditorTargetField.ShouldBuild
{
get
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
if (remoteValue.HasValue)
{
if (remoteValue.HasValue)
{
return IsNullOrDisposed(remoteValue.Value, ((SyncElement)this).World);
}
return false;
}
return true;
}
}
protected override void InternalDecodeFull(BinaryReader reader, BinaryMessageBatch inboundMessage)
{
Decode(reader, inboundMessage);
}
protected override void InternalDecodeDelta(BinaryReader reader, BinaryMessageBatch inboundMessage)
{
Decode(reader, inboundMessage);
}
private void Decode(BinaryReader reader, BinaryMessageBatch inboundMessage)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
RefID val = RefID.op_Implicit(BinaryReaderExtensions.Read7BitEncoded(reader));
remoteValue = val;
((SyncField<RefID>)(object)this).InternalSetValue(ref val, false, true);
}
protected override bool InternalSetRefID(in RefID id, T prevTarget)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
if (!MyInspectors.MyInspectorsEnabled.Value)
{
return base.InternalSetRefID(ref id, prevTarget);
}
RefID val = id;
bool flag = false;
bool flag2 = true;
if (remoteValue.HasValue)
{
global::System.Type type = ((object)((SyncElement)this).Parent).GetType();
if (typeof(SlotInspector).IsAssignableFrom(type) || typeof(UserInspectorItem).IsAssignableFrom(type))
{
RefID? val2 = remoteValue;
RefID val3 = RefID.Null;
if (val2.HasValue && val2.GetValueOrDefault() == val3)
{
return ((SyncField<RefID>)(object)this).InternalSetValue(ref val, flag, flag2);
}
flag = true;
RefID current = val;
val = RefID.Null;
remoteValue = val;
flag2 = false;
((SyncElement)this).World.RunInUpdates(1, (Action)delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
((SyncField<RefID>)(object)this)._value = current;
((SyncField<RefID>)(object)this).ValueChanged();
});
}
else
{
flag = true;
}
}
return ((SyncField<RefID>)(object)this).InternalSetValue(ref val, flag, flag2);
}
private static bool IsNullOrDisposed(RefID id, World world)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if (id == RefID.Null)
{
return true;
}
IWorldElement objectOrNull = world.ReferenceController.GetObjectOrNull(ref id);
if (objectOrNull != null)
{
return objectOrNull.IsRemoved;
}
return true;
}
}
internal interface EditorTargetField
{
bool ShouldBuild { get; }
}
internal class UserInspectorState
{
internal View View;
internal User Target;
internal ushort StreamGroup;
public UserInspectorState(View view, User target, ushort streamGroup = 0)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
ushort streamGroup2 = streamGroup;
View = view;
Target = target;
StreamGroup = streamGroup2;
}
}
[ResonitePlugin("MyInspectors", "MyInspectors", "1.0.2", "art0007i, Gyztor Mizirath", "https://github.com/Gyztor/BepisMyInspectors")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class MyInspectors : BasePlugin
{
[HarmonyPatch(typeof(SceneInspector), "OnAwake")]
private class StupidInspectorFixupPatch
{
public static void Postfix(SceneInspector __instance)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
((ComponentBase<Component>)(object)__instance).RunInUpdates(0, (Action)delegate
{
((MethodBase)AccessTools.Method(typeof(SceneInspector), "OnChanges", (global::System.Type[])null, (global::System.Type[])null)).Invoke((object)__instance, (object[])null);
});
}
}
[HarmonyPatch]
private class SceneInspector_Patch
{
[CompilerGenerated]
private sealed class <TargetMethods>d__0 : global::System.Collections.Generic.IEnumerable<MethodInfo>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<MethodInfo>, global::System.Collections.IEnumerator, global::System.IDisposable
{
private int <>1__state;
private MethodInfo <>2__current;
private int <>l__initialThreadId;
MethodInfo global::System.Collections.Generic.IEnumerator<MethodInfo>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object global::System.Collections.IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <TargetMethods>d__0(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void global::System.IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(WorkerInspector), "OnChanges", (global::System.Type[])null, (global::System.Type[])null);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(SceneInspector), "OnChanges", (global::System.Type[])null, (global::System.Type[])null);
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
return false;
}
}
bool global::System.Collections.IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[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<MethodInfo> global::System.Collections.Generic.IEnumerable<MethodInfo>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <TargetMethods>d__0(0);
}
[DebuggerHidden]
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
{
return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<MethodInfo>)this).GetEnumerator();
}
}
[CompilerGenerated]
private sealed class <Transpiler>d__5 : global::System.Collections.Generic.IEnumerable<CodeInstruction>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<CodeInstruction>, 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<CodeInstruction> instructions;
public global::System.Collections.Generic.IEnumerable<CodeInstruction> <>3__instructions;
private List<CodeInstruction> <codes>5__2;
private FieldInfo <rootField>5__3;
private FieldInfo <compField>5__4;
private int <i>5__5;
private CodeInstruction <code>5__6;
private CodeInstruction <twoBefore>5__7;
CodeInstruction global::System.Collections.Generic.IEnumerator<CodeInstruction>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object global::System.Collections.IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Transpiler>d__5(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void global::System.IDisposable.Dispose()
{
<codes>5__2 = null;
<rootField>5__3 = null;
<compField>5__4 = null;
<code>5__6 = null;
<twoBefore>5__7 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Expected O, but got Unknown
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Expected O, but got Unknown
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Expected O, but got Unknown
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Expected O, but got Unknown
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Expected O, but got Unknown
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Expected O, but got Unknown
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_0259: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Expected O, but got Unknown
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Expected O, but got Unknown
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_029c: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Expected O, but got Unknown
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_034a: Unknown result type (might be due to invalid IL or missing references)
//IL_0354: Expected O, but got Unknown
//IL_0366: Unknown result type (might be due to invalid IL or missing references)
//IL_036c: Unknown result type (might be due to invalid IL or missing references)
//IL_0376: Expected O, but got Unknown
//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
//IL_03f0: Expected O, but got Unknown
//IL_030d: Unknown result type (might be due to invalid IL or missing references)
//IL_0313: Unknown result type (might be due to invalid IL or missing references)
//IL_031d: Expected O, but got Unknown
//IL_00c8: 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_03a9: Unknown result type (might be due to invalid IL or missing references)
//IL_03af: Unknown result type (might be due to invalid IL or missing references)
//IL_03b9: Expected O, but got Unknown
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<codes>5__2 = Enumerable.ToList<CodeInstruction>(instructions);
<rootField>5__3 = AccessTools.Field(typeof(SceneInspector), "Root");
<compField>5__4 = AccessTools.Field(typeof(SceneInspector), "ComponentView");
<i>5__5 = 0;
goto IL_0418;
case 1:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Ceq, (object)null);
<>1__state = 3;
return true;
case 3:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
<>1__state = 4;
return true;
case 4:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SceneInspector_Patch), "IsHost", (global::System.Type[])null, (global::System.Type[])null));
<>1__state = 5;
return true;
case 5:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
<>1__state = 6;
return true;
case 6:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Ldfld, <twoBefore>5__7.operand);
<>1__state = 7;
return true;
case 7:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SceneInspector_Patch), "IsChangedLocally", (global::System.Type[])null, (global::System.Type[])null));
<>1__state = 8;
return true;
case 8:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Or, (object)null);
<>1__state = 9;
return true;
case 9:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.And, (object)null);
<>1__state = 10;
return true;
case 10:
<>1__state = -1;
<code>5__6.opcode = OpCodes.Brfalse;
goto IL_02c7;
case 11:
<>1__state = -1;
if (CodeInstructionExtensions.Calls(<code>5__6, AccessTools.PropertyGetter(typeof(World), "IsAuthority")))
{
<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
<>1__state = 12;
return true;
}
goto IL_0387;
case 12:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SceneInspector_Patch), "ShouldContinue", (global::System.Type[])null, (global::System.Type[])null));
<>1__state = 13;
return true;
case 13:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Or, (object)null);
<>1__state = 14;
return true;
case 14:
<>1__state = -1;
goto IL_0387;
case 15:
<>1__state = -1;
<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SceneInspector_Patch), "ResetContainer", (global::System.Type[])null, (global::System.Type[])null));
<>1__state = 16;
return true;
case 16:
{
<>1__state = -1;
goto IL_0401;
}
IL_02c7:
<twoBefore>5__7 = null;
goto IL_02ce;
IL_0387:
if (CodeInstructionExtensions.StoresField(<code>5__6, AccessTools.Field(typeof(WorkerInspector), "_currentContainer")))
{
<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
<>1__state = 15;
return true;
}
goto IL_0401;
IL_0401:
<code>5__6 = null;
<i>5__5++;
goto IL_0418;
IL_0418:
if (<i>5__5 < <codes>5__2.Count)
{
<code>5__6 = <codes>5__2[<i>5__5];
if (<code>5__6.opcode == OpCodes.Beq && <i>5__5 >= 2)
{
<twoBefore>5__7 = <codes>5__2[<i>5__5 - 2];
object operand = <twoBefore>5__7.operand;
FieldInfo val = (FieldInfo)((operand is FieldInfo) ? operand : null);
if (val != null && (val == <rootField>5__3 || val == <compField>5__4))
{
<>2__current = new CodeInstruction(OpCodes.Ceq, (object)null);
<>1__state = 1;
return true;
}
goto IL_02c7;
}
goto IL_02ce;
}
return false;
IL_02ce:
<>2__current = <code>5__6;
<>1__state = 11;
return true;
}
}
bool global::System.Collections.IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[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<CodeInstruction> global::System.Collections.Generic.IEnumerable<CodeInstruction>.GetEnumerator()
{
<Transpiler>d__5 <Transpiler>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Transpiler>d__ = this;
}
else
{
<Transpiler>d__ = new <Transpiler>d__5(0);
}
<Transpiler>d__.instructions = <>3__instructions;
return <Transpiler>d__;
}
[DebuggerHidden]
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
{
return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
}
}
[IteratorStateMachine(typeof(<TargetMethods>d__0))]
public static global::System.Collections.Generic.IEnumerable<MethodInfo> TargetMethods()
{
yield return AccessTools.Method(typeof(WorkerInspector), "OnChanges", (global::System.Type[])null, (global::System.Type[])null);
yield return AccessTools.Method(typeof(SceneInspector), "OnChanges", (global::System.Type[])null, (global::System.Type[])null);
}
public static bool IsChangedLocally(ConflictingSyncElement el)
{
if (el.LastConfirmedTime != el.LastHostVersion)
{
return ((SyncElement)el).IsSyncDirty;
}
return true;
}
public static bool ShouldContinue(Worker worker)
{
SceneInspector val = (SceneInspector)(object)((worker is SceneInspector) ? worker : null);
if (val != null)
{
if (!IsChangedLocally((ConflictingSyncElement)(object)val.ComponentView))
{
return IsChangedLocally((ConflictingSyncElement)(object)val.Root);
}
return true;
}
WorkerInspector val2 = (WorkerInspector)(object)((worker is WorkerInspector) ? worker : null);
if (val2 != null && _targetContainer.GetValue((object)val2) is SyncRef<Worker> val3)
{
if (val3.Target != null)
{
return IsChangedLocally((ConflictingSyncElement)(object)val3);
}
return false;
}
return false;
}
public static void ResetContainer(WorkerInspector i)
{
if (!((Worker)i).World.IsAuthority && _targetContainer.GetValue((object)i) is SyncRef<Worker> val)
{
val.Target = null;
}
}
public static bool IsHost(SceneInspector i)
{
return ((Worker)i).World.IsAuthority;
}
[IteratorStateMachine(typeof(<Transpiler>d__5))]
public static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> codes = Enumerable.ToList<CodeInstruction>(instructions);
FieldInfo rootField = AccessTools.Field(typeof(SceneInspector), "Root");
FieldInfo compField = AccessTools.Field(typeof(SceneInspector), "ComponentView");
for (int i = 0; i < codes.Count; i++)
{
CodeInstruction code = codes[i];
if (code.opcode == OpCodes.Beq && i >= 2)
{
CodeInstruction twoBefore = codes[i - 2];
object operand = twoBefore.operand;
FieldInfo val = (FieldInfo)((operand is FieldInfo) ? operand : null);
if (val != null && (val == rootField || val == compField))
{
yield return new CodeInstruction(OpCodes.Ceq, (object)null);
yield return new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
yield return new CodeInstruction(OpCodes.Ceq, (object)null);
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SceneInspector_Patch), "IsHost", (global::System.Type[])null, (global::System.Type[])null));
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Ldfld, twoBefore.operand);
yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SceneInspector_Patch), "IsChangedLocally", (global::System.Type[])null, (global::System.Type[])null));
yield return new CodeInstruction(OpCodes.Or, (object)null);
yield return new CodeInstruction(OpCodes.And, (object)null);
code.opcode = OpCodes.Brfalse;
}
}
yield return code;
if (CodeInstructionExtensions.Calls(code, AccessTools.PropertyGetter(typeof(World), "IsAuthority")))
{
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SceneInspector_Patch), "ShouldContinue", (global::System.Type[])null, (global::System.Type[])null));
yield return new CodeInstruction(OpCodes.Or, (object)null);
}
if (CodeInstructionExtensions.StoresField(code, AccessTools.Field(typeof(WorkerInspector), "_currentContainer")))
{
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SceneInspector_Patch), "ResetContainer", (global::System.Type[])null, (global::System.Type[])null));
}
}
}
}
[HarmonyPatch]
private class InitializeSyncMemberPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(SlotInspector), "InitializeSyncMembers")]
private static void SlotInspectorPostfix(SlotInspector __instance, ref SyncRef<Slot> ____rootSlot)
{
MyInspectors.createPatchedSyncref<Slot>(ref ____rootSlot, (IWorldElement)(object)__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UserInspectorItem), "InitializeSyncMembers")]
private static void UserInspectorItemPostfix(UserInspectorItem __instance, ref SyncRef<User> ____user)
{
MyInspectors.createPatchedSyncref<User>(ref ____user, (IWorldElement)(object)__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(BagEditor), "InitializeSyncMembers")]
private static void BagEditorPostfix(BagEditor __instance, ref SyncRef<ISyncBag> ____targetBag)
{
MyInspectors.createPatchedSyncref<ISyncBag>(ref ____targetBag, (IWorldElement)(object)__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ListEditor), "InitializeSyncMembers")]
private static void ListEditorPostfix(ListEditor __instance, ref SyncRef<ISyncList> ____targetList)
{
MyInspectors.createPatchedSyncref<ISyncList>(ref ____targetList, (IWorldElement)(object)__instance);
}
}
[HarmonyPatch(typeof(SlotInspector), "OnChanges")]
private class SlotInspector_OnChanges_Patch
{
private static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
{
return Editor_OnChanges_Transpiler(codes, AccessTools.Field(typeof(SlotInspector), "_rootSlot"));
}
private static void Postfix(SyncRef<TextExpandIndicator> ____expanderIndicator, SyncRef<Slot> ____rootSlot)
{
if (!((SyncElement)____expanderIndicator).World.IsAuthority)
{
TextExpandIndicator target = ____expanderIndicator.Target;
if (target != null && !((SyncElement)target.Empty).IsLinked)
{
target.CustomEmptyCheck.Target = null;
Slot slot = ((Component)target).Slot;
ValueObjectInput<string> val = ((ContainerWorker<Component>)(object)slot).AttachComponent<ValueObjectInput<string>>(true, (Action<ValueObjectInput<string>>)null);
ObjectValueSource<string> val2 = ((ContainerWorker<Component>)(object)slot).AttachComponent<ObjectValueSource<string>>(true, (Action<ObjectValueSource<string>>)null);
ChildrenCount val3 = ((ContainerWorker<Component>)(object)slot).AttachComponent<ChildrenCount>(true, (Action<ChildrenCount>)null);
ValueEquals<int> val4 = ((ContainerWorker<Component>)(object)slot).AttachComponent<ValueEquals<int>>(true, (Action<ValueEquals<int>>)null);
ObjectConditional<string> val5 = ((ContainerWorker<Component>)(object)slot).AttachComponent<ObjectConditional<string>>(true, (Action<ObjectConditional<string>>)null);
ElementSource<Slot> val6 = ((ContainerWorker<Component>)(object)slot).AttachComponent<ElementSource<Slot>>(true, (Action<ElementSource<Slot>>)null);
ObjectFieldDrive<string> obj = ((ContainerWorker<Component>)(object)slot).AttachComponent<ObjectFieldDrive<string>>(true, (Action<ObjectFieldDrive<string>>)null);
((SyncField<string>)(object)val.Value).Value = Sync<string>.op_Implicit(target.Empty);
val2.TrySetRootSource((IWorldElement)(object)target.Closed);
val6.TrySetRootSource((IWorldElement)(object)____rootSlot.Target);
val3.Instance.Target = (INodeObjectOutput<Slot>)(object)val6;
val4.A.Target = (INodeValueOutput<int>)(object)val3;
val5.Condition.Target = (INodeValueOutput<bool>)(object)val4;
val5.OnTrue.Target = (INodeObjectOutput<string>)(object)val;
val5.OnFalse.Target = (INodeObjectOutput<string>)(object)val2;
((FieldDriveBase<string>)(object)obj).TrySetRootTarget((IWorldElement)(object)target.Empty);
obj.Value.Target = (INodeObjectOutput<string>)(object)val5;
}
}
}
}
[HarmonyPatch(typeof(BagEditor), "OnChanges")]
private class BagEditor_Patch
{
private static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
{
return Editor_OnChanges_Transpiler(codes, AccessTools.Field(typeof(BagEditor), "_targetBag"));
}
[HarmonyPrefix]
[HarmonyPatch("Target_ElementAdded")]
private static bool AddedPrefix(BagEditor __instance, SyncField<RefID> ____targetBag, IWorldElement element)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (!ShouldBuild(____targetBag))
{
return false;
}
Enumerator<Slot> enumerator = ((Component)__instance).Slot.Children.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
BagEditorItem component = ((ContainerWorker<Component>)(object)enumerator.Current).GetComponent<BagEditorItem>((Predicate<BagEditorItem>)null, false);
if (component != null && ((SyncRef<IWorldElement>)(object)component.Item).Target == element)
{
return false;
}
}
}
finally
{
((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
}
return true;
}
}
[HarmonyPatch(typeof(ListEditor), "OnChanges")]
private class ListEditor_Patch
{
private static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
{
return Editor_OnChanges_Transpiler(codes, AccessTools.Field(typeof(ListEditor), "_targetList"));
}
[HarmonyPrefix]
[HarmonyPatch("Target_ElementsAdded")]
private static bool AddedPrefix(ListEditor __instance, SyncField<RefID> ____targetList, ISyncList list, int startIndex, int count)
{
return ShouldBuild(____targetList);
}
}
[HarmonyPatch(typeof(UserInspectorItem))]
private class UserInspectorItem_Patch
{
[HarmonyTranspiler]
[HarmonyPatch("OnChanges")]
private static global::System.Collections.Generic.IEnumerable<CodeInstruction> OnChangesTranspiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
{
return Editor_OnChanges_Transpiler(codes, AccessTools.Field(typeof(UserInspectorItem), "_user"));
}
[HarmonyPrefix]
[HarmonyPatch("OpenComponents")]
private static bool OpenComponentsPrefix(UserInspectorItem __instance, SyncRef<User> ____user)
{
if (____user.Target != null && !((Worker)__instance).World.IsAuthority)
{
UserInspector componentInParents = ((Component)__instance).Slot.GetComponentInParents<UserInspector>((Predicate<UserInspector>)null, true, false);
if (componentInParents != null)
{
OpenUserInspector(componentInParents, new UserInspectorState((View)1, ____user.Target, 0));
return false;
}
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("OpenStream")]
private static bool OpenStreamPrefix(UserInspectorItem __instance, SyncRef<User> ____user, ushort streamIndex)
{
if (____user.Target != null && !((Worker)__instance).World.IsAuthority)
{
UserInspector componentInParents = ((Component)__instance).Slot.GetComponentInParents<UserInspector>((Predicate<UserInspector>)null, true, false);
if (componentInParents != null)
{
OpenUserInspector(componentInParents, new UserInspectorState((View)2, ____user.Target, streamIndex));
return false;
}
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("OpenUser")]
private static bool OpenUserPrefix(UserInspectorItem __instance, SyncRef<User> ____user)
{
if (____user.Target != null && !((Worker)__instance).World.IsAuthority)
{
UserInspector componentInParents = ((Component)__instance).Slot.GetComponentInParents<UserInspector>((Predicate<UserInspector>)null, true, false);
if (componentInParents != null)
{
OpenUserInspector(componentInParents, new UserInspectorState((View)0, ____user.Target, 0));
return false;
}
}
return true;
}
}
[HarmonyPatch(typeof(UserInspector), "FilterWorker")]
private class UserInspector_Patch
{
private static bool Prefix(UserInspector __instance, ref bool __result, Worker worker)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected I4, but got Unknown
UserInspectorState userInspectorState = default(UserInspectorState);
if (!userInspectorStates.TryGetValue(__instance, ref userInspectorState))
{
return true;
}
View view = userInspectorState.View;
switch ((int)view)
{
case 1:
__result = worker is UserComponent;
break;
case 2:
{
Stream val = (Stream)(object)((worker is Stream) ? worker : null);
if (val != null)
{
__result = val.GroupIndex == userInspectorState.StreamGroup;
}
else
{
__result = false;
}
break;
}
case 0:
__result = worker is User;
break;
default:
__result = true;
break;
}
return false;
}
}
[HarmonyPatch(typeof(TypeManager), "InitializeAssemblies")]
private class TypeManager_Patch
{
private static void Postfix(Dictionary<Assembly, int> ____assemblyToIndex, List<AssemblyTypeRegistry> ____allowedAssemblies)
{
int num = default(int);
if (____assemblyToIndex.TryGetValue(typeof(SyncRef<>).Assembly, ref num))
{
____assemblyToIndex.TryAdd(typeof(PatchedSyncRef<>).Assembly, num);
Dictionary<global::System.Type, int> val = (Dictionary<global::System.Type, int>)_typeToIndex.GetValue((object)____allowedAssemblies[num]);
val.TryAdd(typeof(PatchedSyncRef<>), val[typeof(SyncRef<>)]);
}
}
}
[HarmonyPatch(typeof(SyncType), "set_Value")]
private class SyncType_Patch
{
private static global::System.Exception Finalizer(global::System.Exception __exception, SyncType __instance, global::System.Type value)
{
if (__exception != null && __exception.Message.Contains("MyInspectors"))
{
SetBase(__instance, value);
return null;
}
return __exception;
}
[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
[HarmonyPatch(typeof(SyncField<global::System.Type>), "set_Value")]
public static void SetBase(object instance, global::System.Type value)
{
}
}
[HarmonyPatch(typeof(Coder), "IsEnginePrimitive")]
private class Coder_Patch
{
private static bool Prefix(ref bool __result, global::System.Type type)
{
if (type != null && ((MemberInfo)type).Name?.Contains("MyInspectors") == true)
{
__result = true;
return false;
}
return true;
}
}
[CompilerGenerated]
private sealed class <Editor_OnChanges_Transpiler>d__11 : global::System.Collections.Generic.IEnumerable<CodeInstruction>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<CodeInstruction>, 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<CodeInstruction> codes;
public global::System.Collections.Generic.IEnumerable<CodeInstruction> <>3__codes;
private FieldInfo targetField;
public FieldInfo <>3__targetField;
private int <hit>5__2;
private global::System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap2;
CodeInstruction global::System.Collections.Generic.IEnumerator<CodeInstruction>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object global::System.Collections.IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Editor_OnChanges_Transpiler>d__11(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) <= 2u)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>7__wrap2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00c1: 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_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<hit>5__2 = 0;
<>7__wrap2 = codes.GetEnumerator();
<>1__state = -3;
break;
case 1:
<>1__state = -3;
<>2__current = new CodeInstruction(OpCodes.Call, (object)ShouldBuildInfo);
<>1__state = 2;
return true;
case 2:
<>1__state = -3;
break;
case 3:
<>1__state = -3;
break;
}
while (((global::System.Collections.IEnumerator)<>7__wrap2).MoveNext())
{
CodeInstruction current = <>7__wrap2.Current;
if (<hit>5__2 <= 0 && CodeInstructionExtensions.Calls(current, AccessTools.PropertyGetter(typeof(Worker), "World")))
{
<hit>5__2++;
<>2__current = new CodeInstruction(OpCodes.Ldfld, (object)targetField);
<>1__state = 1;
return true;
}
if (<hit>5__2 == 1)
{
<hit>5__2++;
continue;
}
<>2__current = current;
<>1__state = 3;
return true;
}
<>m__Finally1();
<>7__wrap2 = 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__wrap2 != null)
{
((global::System.IDisposable)<>7__wrap2).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<CodeInstruction> global::System.Collections.Generic.IEnumerable<CodeInstruction>.GetEnumerator()
{
<Editor_OnChanges_Transpiler>d__11 <Editor_OnChanges_Transpiler>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Editor_OnChanges_Transpiler>d__ = this;
}
else
{
<Editor_OnChanges_Transpiler>d__ = new <Editor_OnChanges_Transpiler>d__11(0);
}
<Editor_OnChanges_Transpiler>d__.codes = <>3__codes;
<Editor_OnChanges_Transpiler>d__.targetField = <>3__targetField;
return <Editor_OnChanges_Transpiler>d__;
}
[DebuggerHidden]
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
{
return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
}
}
internal static ManualLogSource Log = null;
internal static ConfigEntry<bool> MyInspectorsEnabled;
private static FieldInfo _targetContainer = AccessTools.Field(typeof(WorkerInspector), "_targetContainer");
private static ConditionalWeakTable<UserInspector, UserInspectorState> userInspectorStates = new ConditionalWeakTable<UserInspector, UserInspectorState>();
private static MethodInfo ShouldBuildInfo = AccessTools.Method(typeof(MyInspectors), "ShouldBuild", (global::System.Type[])null, (global::System.Type[])null);
private static MethodInfo _FilterWorker = AccessTools.Method(typeof(UserInspector), "FilterWorker", (global::System.Type[])null, (global::System.Type[])null);
private static FieldInfo _typeToIndex = AccessTools.Field(typeof(AssemblyTypeRegistry), "_typeToIndex");
public override void Load()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
MyInspectorsEnabled = ((BasePlugin)this).Config.Bind<bool>("MyInspectors", "Enable MyInspectors", true, new ConfigDescription("Enables the MyInspectors mod.", (AcceptableValueBase)null, global::System.Array.Empty<object>()));
Harmony harmony = new Harmony("me.art0007i.MyInspectors");
Log.LogInfo((object)"MyInspectors Applying Patches");
if (MyInspectorsEnabled.Value)
{
harmony.PatchAll();
}
MyInspectorsEnabled.SettingChanged += (EventHandler)delegate
{
if (MyInspectorsEnabled.Value)
{
Log.LogInfo((object)"Applying Inspector Patches");
harmony.PatchAll();
}
else
{
Log.LogInfo((object)"Removing Inspector Patches");
Harmony.UnpatchID("me.art0007i.MyInspectors");
}
};
}
private static void createPatchedSyncref<T>(ref SyncRef<T> old, IWorldElement existingObj) where T : class, IWorldElement
{
if (!existingObj.World.IsAuthority)
{
old = (SyncRef<T>)(object)new PatchedSyncRef<T>();
}
}
private static bool ShouldBuild(SyncField<RefID> field)
{
if (((SyncElement)field).World.IsAuthority)
{
return true;
}
if (field is EditorTargetField editorTargetField)
{
return editorTargetField.ShouldBuild;
}
return false;
}
[IteratorStateMachine(typeof(<Editor_OnChanges_Transpiler>d__11))]
private static global::System.Collections.Generic.IEnumerable<CodeInstruction> Editor_OnChanges_Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes, FieldInfo targetField)
{
int hit = 0;
global::System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
try
{
while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
{
CodeInstruction current = enumerator.Current;
if (hit <= 0 && CodeInstructionExtensions.Calls(current, AccessTools.PropertyGetter(typeof(Worker), "World")))
{
hit++;
yield return new CodeInstruction(OpCodes.Ldfld, (object)targetField);
yield return new CodeInstruction(OpCodes.Call, (object)ShouldBuildInfo);
}
else if (hit == 1)
{
hit++;
}
else
{
yield return current;
}
}
}
finally
{
((global::System.IDisposable)enumerator)?.Dispose();
}
}
private static void OpenUserInspector(UserInspector Inspector, UserInspectorState state)
{
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Invalid comparison between Unknown and I4
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
userInspectorStates.AddOrUpdate(Inspector, state);
Sync<string> target = ((SyncRef<Sync<string>>)(object)((Worker)Inspector).GetSyncMember("_userText")).Target;
if (target != null)
{
global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler(9, 2);
defaultInterpolatedStringHandler.AppendLiteral("User: ");
User target2 = state.Target;
defaultInterpolatedStringHandler.AppendFormatted((target2 != null) ? target2.UserName : null);
defaultInterpolatedStringHandler.AppendLiteral(" (");
User target3 = state.Target;
defaultInterpolatedStringHandler.AppendFormatted<RefID?>((target3 != null) ? new RefID?(((Worker)target3).ReferenceID) : ((RefID?)null));
defaultInterpolatedStringHandler.AppendLiteral(")");
((SyncField<string>)(object)target).Value = defaultInterpolatedStringHandler.ToStringAndClear();
}
Slot target4 = ((SyncRef<Slot>)(object)((Worker)Inspector).GetSyncMember("_workersContentRoot")).Target;
if (target4 != null)
{
target4.DestroyChildren(false, true, false, (Predicate<Slot>)null);
((ContainerWorker<Component>)(object)target4.AddSlot("WorkersRoot", true)).AttachComponent<WorkerInspector>(true, (Action<WorkerInspector>)null).SetupContainer((Worker)(object)state.Target, (Predicate<ISyncMember>)null, _FilterWorker.CreateDelegate<Predicate<Worker>>((object)Inspector), (int)state.View == 0);
}
}
}
public static class PluginMetadata
{
public const string GUID = "MyInspectors";
public const string NAME = "MyInspectors";
public const string VERSION = "1.0.2";
public const string AUTHORS = "art0007i, Gyztor Mizirath";
public const string REPOSITORY_URL = "https://github.com/Gyztor/BepisMyInspectors";
}