Decompiled source of Runtime Unity Editor v1.0.0
plugins/mcs.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.CodeDom.Compiler; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Text; using System.Threading; using System.Xml; using Microsoft.CodeAnalysis; using Mono.CSharp.Linq; using Mono.CSharp.Nullable; using Mono.CSharp.yyParser; using Mono.CSharp.yydebug; using Mono.CompilerServices.SymbolWriter; using Mono.Security.Cryptography; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Mono C# Compiler")] [assembly: AssemblyProduct("Mono C# Compiler")] [assembly: AssemblyCopyright("2001 - 2009 Novell, Inc.")] [assembly: AssemblyCompany("Novell, Inc.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyFileVersion("4.0.30319.17020")] [assembly: AssemblyDescription("Mono C# Compiler")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("6.13.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } internal static class Consts { public const string MonoCorlibVersion = "1A5E0066-58DC-428A-B21C-0AD6CDAE2789"; public const string MonoVersion = "6.13.0.0"; public const string MonoCompany = "Mono development team"; public const string MonoProduct = "Mono Common Language Infrastructure"; public const string MonoCopyright = "(c) Various Mono authors"; public const string FxVersion = "4.0.0.0"; public const string FxFileVersion = "4.0.30319.17020"; public const string EnvironmentVersion = "4.0.30319.17020"; public const string VsVersion = "0.0.0.0"; public const string VsFileVersion = "11.0.0.0"; private const string PublicKeyToken = "b77a5c561934e089"; public const string AssemblyI18N = "I18N, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"; public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblyMono_Http = "Mono.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"; public const string AssemblyMono_Posix = "Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"; public const string AssemblyMono_Security = "Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"; public const string AssemblyMono_Messaging_RabbitMQ = "Mono.Messaging.RabbitMQ, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"; public const string AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; public const string AssemblySystem = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; public const string AssemblySystem_Data = "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; public const string AssemblySystem_Design = "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblySystem_DirectoryServices = "System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblySystem_Drawing = "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblySystem_Drawing_Design = "System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblySystem_Messaging = "System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblySystem_Security = "System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblySystem_ServiceProcess = "System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblySystem_Web = "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; public const string AssemblySystem_Windows_Forms = "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; public const string AssemblySystem_2_0 = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; public const string AssemblySystemCore_3_5 = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; public const string AssemblySystem_Core = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; public const string WindowsBase_3_0 = "WindowsBase, Version=3.0.0.0, PublicKeyToken=31bf3856ad364e35"; public const string AssemblyWindowsBase = "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; public const string AssemblyPresentationCore_3_5 = "PresentationCore, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; public const string AssemblyPresentationCore_4_0 = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; public const string AssemblyPresentationFramework_3_5 = "PresentationFramework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; public const string AssemblySystemServiceModel_3_0 = "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; } namespace System { internal interface ITupleInternal : ITuple { string ToString(StringBuilder sb); int GetHashCode(IEqualityComparer comparer); } public static class Tuple { public static Tuple<T1> Create<T1>(T1 item1) { return new Tuple<T1>(item1); } public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2) { return new Tuple<T1, T2>(item1, item2); } public static Tuple<T1, T2, T3> Create<T1, T2, T3>(T1 item1, T2 item2, T3 item3) { return new Tuple<T1, T2, T3>(item1, item2, item3); } public static Tuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 item1, T2 item2, T3 item3, T4 item4) { return new Tuple<T1, T2, T3, T4>(item1, item2, item3, item4); } public static Tuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) { return new Tuple<T1, T2, T3, T4, T5>(item1, item2, item3, item4, item5); } public static Tuple<T1, T2, T3, T4, T5, T6> Create<T1, T2, T3, T4, T5, T6>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) { return new Tuple<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, item6); } public static Tuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) { return new Tuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7); } public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>> Create<T1, T2, T3, T4, T5, T6, T7, T8>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) { return new Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>(item1, item2, item3, item4, item5, item6, item7, new Tuple<T8>(item8)); } internal static int CombineHashCodes(int h1, int h2) { return ((h1 << 5) + h1) ^ h2; } internal static int CombineHashCodes(int h1, int h2, int h3) { return CombineHashCodes(CombineHashCodes(h1, h2), h3); } internal static int CombineHashCodes(int h1, int h2, int h3, int h4) { return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4)); } internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5) { return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5); } internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6) { return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6)); } internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7) { return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7)); } internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7, int h8) { return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7, h8)); } } [Serializable] public class Tuple<T1> : IComparable, System.ITupleInternal, ITuple { private readonly T1 m_Item1; public T1 Item1 => m_Item1; int ITuple.Length => 1; object? ITuple.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return Item1; } } public Tuple(T1 item1) { m_Item1 = item1; } public override bool Equals(object? obj) { return Equals(obj, EqualityComparer<object>.Default); } private bool Equals(object? other, IEqualityComparer comparer) { if (other == null) { return false; } if (!(other is Tuple<T1> tuple)) { return false; } return comparer.Equals(m_Item1, tuple.m_Item1); } int IComparable.CompareTo(object? obj) { return CompareTo(obj, Comparer<object>.Default); } private int CompareTo(object? other, IComparer comparer) { if (other == null) { return 1; } if (!(other is Tuple<T1> tuple)) { throw new ArgumentException($"Tuple of incorrect type (expected {GetType()})", "other"); } return comparer.Compare(m_Item1, tuple.m_Item1); } public override int GetHashCode() { return GetHashCode(EqualityComparer<object>.Default); } int System.ITupleInternal.GetHashCode(IEqualityComparer comparer) { return GetHashCode(comparer); } private int GetHashCode(IEqualityComparer comparer) { return comparer.GetHashCode(m_Item1); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('('); return ToString(stringBuilder); } string System.ITupleInternal.ToString(StringBuilder sb) { return ToString(sb); } private string ToString(StringBuilder sb) { sb.Append(m_Item1); sb.Append(')'); return sb.ToString(); } } [Serializable] public class Tuple<T1, T2> : IComparable, System.ITupleInternal, ITuple { private readonly T1 m_Item1; private readonly T2 m_Item2; public T1 Item1 => m_Item1; public T2 Item2 => m_Item2; int ITuple.Length => 2; object? ITuple.this[int index] => index switch { 0 => Item1, 1 => Item2, _ => throw new IndexOutOfRangeException(), }; public Tuple(T1 item1, T2 item2) { m_Item1 = item1; m_Item2 = item2; } public override bool Equals(object? obj) { return Equals(obj, EqualityComparer<object>.Default); } private bool Equals(object? other, IEqualityComparer comparer) { if (other == null) { return false; } if (!(other is Tuple<T1, T2> tuple)) { return false; } if (comparer.Equals(m_Item1, tuple.m_Item1)) { return comparer.Equals(m_Item2, tuple.m_Item2); } return false; } int IComparable.CompareTo(object? obj) { return CompareTo(obj, Comparer<object>.Default); } private int CompareTo(object? other, IComparer comparer) { if (other == null) { return 1; } if (!(other is Tuple<T1, T2> tuple)) { throw new ArgumentException($"Tuple of incorrect type (expected {GetType()})", "other"); } int num = comparer.Compare(m_Item1, tuple.m_Item1); if (num != 0) { return num; } return comparer.Compare(m_Item2, tuple.m_Item2); } public override int GetHashCode() { return GetHashCode(EqualityComparer<object>.Default); } int System.ITupleInternal.GetHashCode(IEqualityComparer comparer) { return GetHashCode(comparer); } private int GetHashCode(IEqualityComparer comparer) { return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2)); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('('); return ToString(stringBuilder); } string System.ITupleInternal.ToString(StringBuilder sb) { return ToString(sb); } private string ToString(StringBuilder sb) { sb.Append(m_Item1); sb.Append(", "); sb.Append(m_Item2); sb.Append(')'); return sb.ToString(); } } [Serializable] public class Tuple<T1, T2, T3> : IComparable, System.ITupleInternal, ITuple { private readonly T1 m_Item1; private readonly T2 m_Item2; private readonly T3 m_Item3; public T1 Item1 => m_Item1; public T2 Item2 => m_Item2; public T3 Item3 => m_Item3; int ITuple.Length => 3; object? ITuple.this[int index] => index switch { 0 => Item1, 1 => Item2, 2 => Item3, _ => throw new IndexOutOfRangeException(), }; public Tuple(T1 item1, T2 item2, T3 item3) { m_Item1 = item1; m_Item2 = item2; m_Item3 = item3; } public override bool Equals(object? obj) { return Equals(obj, EqualityComparer<object>.Default); } private bool Equals(object? other, IEqualityComparer comparer) { if (other == null) { return false; } if (!(other is Tuple<T1, T2, T3> tuple)) { return false; } if (comparer.Equals(m_Item1, tuple.m_Item1) && comparer.Equals(m_Item2, tuple.m_Item2)) { return comparer.Equals(m_Item3, tuple.m_Item3); } return false; } int IComparable.CompareTo(object? obj) { return CompareTo(obj, Comparer<object>.Default); } private int CompareTo(object? other, IComparer comparer) { if (other == null) { return 1; } if (!(other is Tuple<T1, T2, T3> tuple)) { throw new ArgumentException($"Tuple of incorrect type (expected {GetType()})", "other"); } int num = comparer.Compare(m_Item1, tuple.m_Item1); if (num != 0) { return num; } num = comparer.Compare(m_Item2, tuple.m_Item2); if (num != 0) { return num; } return comparer.Compare(m_Item3, tuple.m_Item3); } public override int GetHashCode() { return GetHashCode(EqualityComparer<object>.Default); } int System.ITupleInternal.GetHashCode(IEqualityComparer comparer) { return GetHashCode(comparer); } private int GetHashCode(IEqualityComparer comparer) { return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3)); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('('); return ToString(stringBuilder); } string System.ITupleInternal.ToString(StringBuilder sb) { return ToString(sb); } private string ToString(StringBuilder sb) { sb.Append(m_Item1); sb.Append(", "); sb.Append(m_Item2); sb.Append(", "); sb.Append(m_Item3); sb.Append(')'); return sb.ToString(); } } [Serializable] public class Tuple<T1, T2, T3, T4> : IComparable, System.ITupleInternal, ITuple { private readonly T1 m_Item1; private readonly T2 m_Item2; private readonly T3 m_Item3; private readonly T4 m_Item4; public T1 Item1 => m_Item1; public T2 Item2 => m_Item2; public T3 Item3 => m_Item3; public T4 Item4 => m_Item4; int ITuple.Length => 4; object? ITuple.this[int index] => index switch { 0 => Item1, 1 => Item2, 2 => Item3, 3 => Item4, _ => throw new IndexOutOfRangeException(), }; public Tuple(T1 item1, T2 item2, T3 item3, T4 item4) { m_Item1 = item1; m_Item2 = item2; m_Item3 = item3; m_Item4 = item4; } public override bool Equals(object? obj) { return Equals(obj, EqualityComparer<object>.Default); } private bool Equals(object? other, IEqualityComparer comparer) { if (other == null) { return false; } if (!(other is Tuple<T1, T2, T3, T4> tuple)) { return false; } if (comparer.Equals(m_Item1, tuple.m_Item1) && comparer.Equals(m_Item2, tuple.m_Item2) && comparer.Equals(m_Item3, tuple.m_Item3)) { return comparer.Equals(m_Item4, tuple.m_Item4); } return false; } int IComparable.CompareTo(object? obj) { return CompareTo(obj, Comparer<object>.Default); } private int CompareTo(object? other, IComparer comparer) { if (other == null) { return 1; } if (!(other is Tuple<T1, T2, T3, T4> tuple)) { throw new ArgumentException($"Tuple of incorrect type (expected {GetType()})", "other"); } int num = comparer.Compare(m_Item1, tuple.m_Item1); if (num != 0) { return num; } num = comparer.Compare(m_Item2, tuple.m_Item2); if (num != 0) { return num; } num = comparer.Compare(m_Item3, tuple.m_Item3); if (num != 0) { return num; } return comparer.Compare(m_Item4, tuple.m_Item4); } public override int GetHashCode() { return GetHashCode(EqualityComparer<object>.Default); } int System.ITupleInternal.GetHashCode(IEqualityComparer comparer) { return GetHashCode(comparer); } private int GetHashCode(IEqualityComparer comparer) { return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4)); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('('); return ToString(stringBuilder); } string System.ITupleInternal.ToString(StringBuilder sb) { return ToString(sb); } private string ToString(StringBuilder sb) { sb.Append(m_Item1); sb.Append(", "); sb.Append(m_Item2); sb.Append(", "); sb.Append(m_Item3); sb.Append(", "); sb.Append(m_Item4); sb.Append(')'); return sb.ToString(); } } [Serializable] public class Tuple<T1, T2, T3, T4, T5> : IComparable, System.ITupleInternal, ITuple { private readonly T1 m_Item1; private readonly T2 m_Item2; private readonly T3 m_Item3; private readonly T4 m_Item4; private readonly T5 m_Item5; public T1 Item1 => m_Item1; public T2 Item2 => m_Item2; public T3 Item3 => m_Item3; public T4 Item4 => m_Item4; public T5 Item5 => m_Item5; int ITuple.Length => 5; object? ITuple.this[int index] => index switch { 0 => Item1, 1 => Item2, 2 => Item3, 3 => Item4, 4 => Item5, _ => throw new IndexOutOfRangeException(), }; public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) { m_Item1 = item1; m_Item2 = item2; m_Item3 = item3; m_Item4 = item4; m_Item5 = item5; } public override bool Equals(object? obj) { return Equals(obj, EqualityComparer<object>.Default); } private bool Equals(object? other, IEqualityComparer comparer) { if (other == null) { return false; } if (!(other is Tuple<T1, T2, T3, T4, T5> tuple)) { return false; } if (comparer.Equals(m_Item1, tuple.m_Item1) && comparer.Equals(m_Item2, tuple.m_Item2) && comparer.Equals(m_Item3, tuple.m_Item3) && comparer.Equals(m_Item4, tuple.m_Item4)) { return comparer.Equals(m_Item5, tuple.m_Item5); } return false; } int IComparable.CompareTo(object? obj) { return CompareTo(obj, Comparer<object>.Default); } private int CompareTo(object? other, IComparer comparer) { if (other == null) { return 1; } if (!(other is Tuple<T1, T2, T3, T4, T5> tuple)) { throw new ArgumentException($"Tuple of incorrect type (expected {GetType()})", "other"); } int num = comparer.Compare(m_Item1, tuple.m_Item1); if (num != 0) { return num; } num = comparer.Compare(m_Item2, tuple.m_Item2); if (num != 0) { return num; } num = comparer.Compare(m_Item3, tuple.m_Item3); if (num != 0) { return num; } num = comparer.Compare(m_Item4, tuple.m_Item4); if (num != 0) { return num; } return comparer.Compare(m_Item5, tuple.m_Item5); } public override int GetHashCode() { return GetHashCode(EqualityComparer<object>.Default); } int System.ITupleInternal.GetHashCode(IEqualityComparer comparer) { return GetHashCode(comparer); } private int GetHashCode(IEqualityComparer comparer) { return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5)); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('('); return ToString(stringBuilder); } string System.ITupleInternal.ToString(StringBuilder sb) { return ToString(sb); } private string ToString(StringBuilder sb) { sb.Append(m_Item1); sb.Append(", "); sb.Append(m_Item2); sb.Append(", "); sb.Append(m_Item3); sb.Append(", "); sb.Append(m_Item4); sb.Append(", "); sb.Append(m_Item5); sb.Append(')'); return sb.ToString(); } } [Serializable] public class Tuple<T1, T2, T3, T4, T5, T6> : IComparable, System.ITupleInternal, ITuple { private readonly T1 m_Item1; private readonly T2 m_Item2; private readonly T3 m_Item3; private readonly T4 m_Item4; private readonly T5 m_Item5; private readonly T6 m_Item6; public T1 Item1 => m_Item1; public T2 Item2 => m_Item2; public T3 Item3 => m_Item3; public T4 Item4 => m_Item4; public T5 Item5 => m_Item5; public T6 Item6 => m_Item6; int ITuple.Length => 6; object? ITuple.this[int index] => index switch { 0 => Item1, 1 => Item2, 2 => Item3, 3 => Item4, 4 => Item5, 5 => Item6, _ => throw new IndexOutOfRangeException(), }; public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) { m_Item1 = item1; m_Item2 = item2; m_Item3 = item3; m_Item4 = item4; m_Item5 = item5; m_Item6 = item6; } public override bool Equals(object? obj) { return Equals(obj, EqualityComparer<object>.Default); } private bool Equals(object? other, IEqualityComparer comparer) { if (other == null) { return false; } if (!(other is Tuple<T1, T2, T3, T4, T5, T6> tuple)) { return false; } if (comparer.Equals(m_Item1, tuple.m_Item1) && comparer.Equals(m_Item2, tuple.m_Item2) && comparer.Equals(m_Item3, tuple.m_Item3) && comparer.Equals(m_Item4, tuple.m_Item4) && comparer.Equals(m_Item5, tuple.m_Item5)) { return comparer.Equals(m_Item6, tuple.m_Item6); } return false; } int IComparable.CompareTo(object? obj) { return CompareTo(obj, Comparer<object>.Default); } private int CompareTo(object? other, IComparer comparer) { if (other == null) { return 1; } if (!(other is Tuple<T1, T2, T3, T4, T5, T6> tuple)) { throw new ArgumentException($"Tuple of incorrect type (expected {GetType()})", "other"); } int num = comparer.Compare(m_Item1, tuple.m_Item1); if (num != 0) { return num; } num = comparer.Compare(m_Item2, tuple.m_Item2); if (num != 0) { return num; } num = comparer.Compare(m_Item3, tuple.m_Item3); if (num != 0) { return num; } num = comparer.Compare(m_Item4, tuple.m_Item4); if (num != 0) { return num; } num = comparer.Compare(m_Item5, tuple.m_Item5); if (num != 0) { return num; } return comparer.Compare(m_Item6, tuple.m_Item6); } public override int GetHashCode() { return GetHashCode(EqualityComparer<object>.Default); } int System.ITupleInternal.GetHashCode(IEqualityComparer comparer) { return GetHashCode(comparer); } private int GetHashCode(IEqualityComparer comparer) { return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6)); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('('); return ToString(stringBuilder); } string System.ITupleInternal.ToString(StringBuilder sb) { return ToString(sb); } private string ToString(StringBuilder sb) { sb.Append(m_Item1); sb.Append(", "); sb.Append(m_Item2); sb.Append(", "); sb.Append(m_Item3); sb.Append(", "); sb.Append(m_Item4); sb.Append(", "); sb.Append(m_Item5); sb.Append(", "); sb.Append(m_Item6); sb.Append(')'); return sb.ToString(); } } [Serializable] public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IComparable, System.ITupleInternal, ITuple { private readonly T1 m_Item1; private readonly T2 m_Item2; private readonly T3 m_Item3; private readonly T4 m_Item4; private readonly T5 m_Item5; private readonly T6 m_Item6; private readonly T7 m_Item7; public T1 Item1 => m_Item1; public T2 Item2 => m_Item2; public T3 Item3 => m_Item3; public T4 Item4 => m_Item4; public T5 Item5 => m_Item5; public T6 Item6 => m_Item6; public T7 Item7 => m_Item7; int ITuple.Length => 7; object? ITuple.this[int index] => index switch { 0 => Item1, 1 => Item2, 2 => Item3, 3 => Item4, 4 => Item5, 5 => Item6, 6 => Item7, _ => throw new IndexOutOfRangeException(), }; public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) { m_Item1 = item1; m_Item2 = item2; m_Item3 = item3; m_Item4 = item4; m_Item5 = item5; m_Item6 = item6; m_Item7 = item7; } public override bool Equals(object? obj) { return Equals(obj, EqualityComparer<object>.Default); } private bool Equals(object? other, IEqualityComparer comparer) { if (other == null) { return false; } if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7> tuple)) { return false; } if (comparer.Equals(m_Item1, tuple.m_Item1) && comparer.Equals(m_Item2, tuple.m_Item2) && comparer.Equals(m_Item3, tuple.m_Item3) && comparer.Equals(m_Item4, tuple.m_Item4) && comparer.Equals(m_Item5, tuple.m_Item5) && comparer.Equals(m_Item6, tuple.m_Item6)) { return comparer.Equals(m_Item7, tuple.m_Item7); } return false; } private int CompareTo(object? other, IComparer comparer) { if (other == null) { return 1; } if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7> tuple)) { throw new ArgumentException($"Tuple of incorrect type (expected {GetType()})", "other"); } int num = comparer.Compare(m_Item1, tuple.m_Item1); if (num != 0) { return num; } num = comparer.Compare(m_Item2, tuple.m_Item2); if (num != 0) { return num; } num = comparer.Compare(m_Item3, tuple.m_Item3); if (num != 0) { return num; } num = comparer.Compare(m_Item4, tuple.m_Item4); if (num != 0) { return num; } num = comparer.Compare(m_Item5, tuple.m_Item5); if (num != 0) { return num; } num = comparer.Compare(m_Item6, tuple.m_Item6); if (num != 0) { return num; } return comparer.Compare(m_Item7, tuple.m_Item7); } public override int GetHashCode() { return GetHashCode(EqualityComparer<object>.Default); } int IComparable.CompareTo(object? obj) { return CompareTo(obj, Comparer<object>.Default); } int System.ITupleInternal.GetHashCode(IEqualityComparer comparer) { return GetHashCode(comparer); } private int GetHashCode(IEqualityComparer comparer) { return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7)); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('('); return ToString(stringBuilder); } string System.ITupleInternal.ToString(StringBuilder sb) { return ToString(sb); } private string ToString(StringBuilder sb) { sb.Append(m_Item1); sb.Append(", "); sb.Append(m_Item2); sb.Append(", "); sb.Append(m_Item3); sb.Append(", "); sb.Append(m_Item4); sb.Append(", "); sb.Append(m_Item5); sb.Append(", "); sb.Append(m_Item6); sb.Append(", "); sb.Append(m_Item7); sb.Append(')'); return sb.ToString(); } } [Serializable] public class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IComparable, System.ITupleInternal, ITuple where TRest : notnull { private readonly T1 m_Item1; private readonly T2 m_Item2; private readonly T3 m_Item3; private readonly T4 m_Item4; private readonly T5 m_Item5; private readonly T6 m_Item6; private readonly T7 m_Item7; private readonly TRest m_Rest; public T1 Item1 => m_Item1; public T2 Item2 => m_Item2; public T3 Item3 => m_Item3; public T4 Item4 => m_Item4; public T5 Item5 => m_Item5; public T6 Item6 => m_Item6; public T7 Item7 => m_Item7; public TRest Rest => m_Rest; int ITuple.Length => 7 + ((System.ITupleInternal)(object)Rest).Length; object? ITuple.this[int index] => index switch { 0 => Item1, 1 => Item2, 2 => Item3, 3 => Item4, 4 => Item5, 5 => Item6, 6 => Item7, _ => ((System.ITupleInternal)(object)Rest)[index - 7], }; public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest) { if (!(rest is System.ITupleInternal)) { throw new ArgumentException("Last argument is not a tuple"); } m_Item1 = item1; m_Item2 = item2; m_Item3 = item3; m_Item4 = item4; m_Item5 = item5; m_Item6 = item6; m_Item7 = item7; m_Rest = rest; } public override bool Equals(object? obj) { return Equals(obj, EqualityComparer<object>.Default); } private bool Equals(object? other, IEqualityComparer comparer) { if (other == null) { return false; } if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> tuple)) { return false; } if (comparer.Equals(m_Item1, tuple.m_Item1) && comparer.Equals(m_Item2, tuple.m_Item2) && comparer.Equals(m_Item3, tuple.m_Item3) && comparer.Equals(m_Item4, tuple.m_Item4) && comparer.Equals(m_Item5, tuple.m_Item5) && comparer.Equals(m_Item6, tuple.m_Item6) && comparer.Equals(m_Item7, tuple.m_Item7)) { return comparer.Equals(m_Rest, tuple.m_Rest); } return false; } int IComparable.CompareTo(object? obj) { return CompareTo(obj, Comparer<object>.Default); } private int CompareTo(object? other, IComparer comparer) { if (other == null) { return 1; } if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> tuple)) { throw new ArgumentException($"Tuple of incorrect type (expected {GetType()})", "other"); } int num = comparer.Compare(m_Item1, tuple.m_Item1); if (num != 0) { return num; } num = comparer.Compare(m_Item2, tuple.m_Item2); if (num != 0) { return num; } num = comparer.Compare(m_Item3, tuple.m_Item3); if (num != 0) { return num; } num = comparer.Compare(m_Item4, tuple.m_Item4); if (num != 0) { return num; } num = comparer.Compare(m_Item5, tuple.m_Item5); if (num != 0) { return num; } num = comparer.Compare(m_Item6, tuple.m_Item6); if (num != 0) { return num; } num = comparer.Compare(m_Item7, tuple.m_Item7); if (num != 0) { return num; } return comparer.Compare(m_Rest, tuple.m_Rest); } public override int GetHashCode() { return GetHashCode(EqualityComparer<object>.Default); } private int GetHashCode(IEqualityComparer comparer) { System.ITupleInternal tupleInternal = (System.ITupleInternal)(object)m_Rest; if (tupleInternal.Length >= 8) { return tupleInternal.GetHashCode(comparer); } return (8 - tupleInternal.Length) switch { 1 => Tuple.CombineHashCodes(comparer.GetHashCode(m_Item7), tupleInternal.GetHashCode(comparer)), 2 => Tuple.CombineHashCodes(comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), tupleInternal.GetHashCode(comparer)), 3 => Tuple.CombineHashCodes(comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), tupleInternal.GetHashCode(comparer)), 4 => Tuple.CombineHashCodes(comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), tupleInternal.GetHashCode(comparer)), 5 => Tuple.CombineHashCodes(comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), tupleInternal.GetHashCode(comparer)), 6 => Tuple.CombineHashCodes(comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), tupleInternal.GetHashCode(comparer)), 7 => Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), tupleInternal.GetHashCode(comparer)), _ => -1, }; } int System.ITupleInternal.GetHashCode(IEqualityComparer comparer) { return GetHashCode(comparer); } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('('); return ToString(stringBuilder); } string System.ITupleInternal.ToString(StringBuilder sb) { return ToString(sb); } private string ToString(StringBuilder sb) { sb.Append(m_Item1); sb.Append(", "); sb.Append(m_Item2); sb.Append(", "); sb.Append(m_Item3); sb.Append(", "); sb.Append(m_Item4); sb.Append(", "); sb.Append(m_Item5); sb.Append(", "); sb.Append(m_Item6); sb.Append(", "); sb.Append(m_Item7); sb.Append(", "); return ((System.ITupleInternal)(object)m_Rest).ToString(sb); } } } namespace System.Runtime.CompilerServices { internal interface ITuple { int Length { get; } object? this[int index] { get; } } } namespace Mono.CompilerServices.SymbolWriter { public class MonoSymbolFileException : Exception { public MonoSymbolFileException() { } public MonoSymbolFileException(string message, params object[] args) : base(string.Format(message, args)) { } public MonoSymbolFileException(string message, Exception innerException) : base(message, innerException) { } } internal sealed class MyBinaryWriter : BinaryWriter { public MyBinaryWriter(Stream stream) : base(stream) { } public void WriteLeb128(int value) { Write7BitEncodedInt(value); } } internal class MyBinaryReader : BinaryReader { public MyBinaryReader(Stream stream) : base(stream) { } public int ReadLeb128() { return Read7BitEncodedInt(); } public string ReadString(int offset) { long position = BaseStream.Position; BaseStream.Position = offset; string result = ReadString(); BaseStream.Position = position; return result; } } public interface ISourceFile { SourceFileEntry Entry { get; } } public interface ICompileUnit { CompileUnitEntry Entry { get; } } public interface IMethodDef { string Name { get; } int Token { get; } } public class MonoSymbolFile : IDisposable { private List<MethodEntry> methods = new List<MethodEntry>(); private List<SourceFileEntry> sources = new List<SourceFileEntry>(); private List<CompileUnitEntry> comp_units = new List<CompileUnitEntry>(); private Dictionary<int, AnonymousScopeEntry> anonymous_scopes; private OffsetTable ot; private int last_type_index; private int last_method_index; private int last_namespace_index; public readonly int MajorVersion = 50; public readonly int MinorVersion; public int NumLineNumbers; private MyBinaryReader reader; private Dictionary<int, SourceFileEntry> source_file_hash; private Dictionary<int, CompileUnitEntry> compile_unit_hash; private List<MethodEntry> method_list; private Dictionary<int, MethodEntry> method_token_hash; private Dictionary<string, int> source_name_hash; private Guid guid; internal int LineNumberCount; internal int LocalCount; internal int StringSize; internal int LineNumberSize; internal int ExtendedLineNumberSize; public int CompileUnitCount => ot.CompileUnitCount; public int SourceCount => ot.SourceCount; public int MethodCount => ot.MethodCount; public int TypeCount => ot.TypeCount; public int AnonymousScopeCount => ot.AnonymousScopeCount; public int NamespaceCount => last_namespace_index; public Guid Guid => guid; public OffsetTable OffsetTable => ot; public SourceFileEntry[] Sources { get { if (reader == null) { throw new InvalidOperationException(); } SourceFileEntry[] array = new SourceFileEntry[SourceCount]; for (int i = 0; i < SourceCount; i++) { array[i] = GetSourceFile(i + 1); } return array; } } public CompileUnitEntry[] CompileUnits { get { if (reader == null) { throw new InvalidOperationException(); } CompileUnitEntry[] array = new CompileUnitEntry[CompileUnitCount]; for (int i = 0; i < CompileUnitCount; i++) { array[i] = GetCompileUnit(i + 1); } return array; } } public MethodEntry[] Methods { get { if (reader == null) { throw new InvalidOperationException(); } lock (this) { read_methods(); MethodEntry[] array = new MethodEntry[MethodCount]; method_list.CopyTo(array, 0); return array; } } } internal MyBinaryReader BinaryReader { get { if (reader == null) { throw new InvalidOperationException(); } return reader; } } public MonoSymbolFile() { ot = new OffsetTable(); } public int AddSource(SourceFileEntry source) { sources.Add(source); return sources.Count; } public int AddCompileUnit(CompileUnitEntry entry) { comp_units.Add(entry); return comp_units.Count; } public void AddMethod(MethodEntry entry) { methods.Add(entry); } public MethodEntry DefineMethod(CompileUnitEntry comp_unit, int token, ScopeVariable[] scope_vars, LocalVariableEntry[] locals, LineNumberEntry[] lines, CodeBlockEntry[] code_blocks, string real_name, MethodEntry.Flags flags, int namespace_id) { if (reader != null) { throw new InvalidOperationException(); } MethodEntry methodEntry = new MethodEntry(this, comp_unit, token, scope_vars, locals, lines, code_blocks, real_name, flags, namespace_id); AddMethod(methodEntry); return methodEntry; } internal void DefineAnonymousScope(int id) { if (reader != null) { throw new InvalidOperationException(); } if (anonymous_scopes == null) { anonymous_scopes = new Dictionary<int, AnonymousScopeEntry>(); } anonymous_scopes.Add(id, new AnonymousScopeEntry(id)); } internal void DefineCapturedVariable(int scope_id, string name, string captured_name, CapturedVariable.CapturedKind kind) { if (reader != null) { throw new InvalidOperationException(); } anonymous_scopes[scope_id].AddCapturedVariable(name, captured_name, kind); } internal void DefineCapturedScope(int scope_id, int id, string captured_name) { if (reader != null) { throw new InvalidOperationException(); } anonymous_scopes[scope_id].AddCapturedScope(id, captured_name); } internal int GetNextTypeIndex() { return ++last_type_index; } internal int GetNextMethodIndex() { return ++last_method_index; } internal int GetNextNamespaceIndex() { return ++last_namespace_index; } private void Write(MyBinaryWriter bw, Guid guid) { bw.Write(5037318119232611860L); bw.Write(MajorVersion); bw.Write(MinorVersion); bw.Write(guid.ToByteArray()); long position = bw.BaseStream.Position; ot.Write(bw, MajorVersion, MinorVersion); methods.Sort(); for (int i = 0; i < methods.Count; i++) { methods[i].Index = i + 1; } ot.DataSectionOffset = (int)bw.BaseStream.Position; foreach (SourceFileEntry source in sources) { source.WriteData(bw); } foreach (CompileUnitEntry comp_unit in comp_units) { comp_unit.WriteData(bw); } foreach (MethodEntry method in methods) { method.WriteData(this, bw); } ot.DataSectionSize = (int)bw.BaseStream.Position - ot.DataSectionOffset; ot.MethodTableOffset = (int)bw.BaseStream.Position; for (int j = 0; j < methods.Count; j++) { methods[j].Write(bw); } ot.MethodTableSize = (int)bw.BaseStream.Position - ot.MethodTableOffset; ot.SourceTableOffset = (int)bw.BaseStream.Position; for (int k = 0; k < sources.Count; k++) { sources[k].Write(bw); } ot.SourceTableSize = (int)bw.BaseStream.Position - ot.SourceTableOffset; ot.CompileUnitTableOffset = (int)bw.BaseStream.Position; for (int l = 0; l < comp_units.Count; l++) { comp_units[l].Write(bw); } ot.CompileUnitTableSize = (int)bw.BaseStream.Position - ot.CompileUnitTableOffset; ot.AnonymousScopeCount = ((anonymous_scopes != null) ? anonymous_scopes.Count : 0); ot.AnonymousScopeTableOffset = (int)bw.BaseStream.Position; if (anonymous_scopes != null) { foreach (AnonymousScopeEntry value in anonymous_scopes.Values) { value.Write(bw); } } ot.AnonymousScopeTableSize = (int)bw.BaseStream.Position - ot.AnonymousScopeTableOffset; ot.TypeCount = last_type_index; ot.MethodCount = methods.Count; ot.SourceCount = sources.Count; ot.CompileUnitCount = comp_units.Count; ot.TotalFileSize = (int)bw.BaseStream.Position; bw.Seek((int)position, SeekOrigin.Begin); ot.Write(bw, MajorVersion, MinorVersion); bw.Seek(0, SeekOrigin.End); } public void CreateSymbolFile(Guid guid, FileStream fs) { if (reader != null) { throw new InvalidOperationException(); } Write(new MyBinaryWriter(fs), guid); } private MonoSymbolFile(Stream stream) { reader = new MyBinaryReader(stream); try { long num = reader.ReadInt64(); int num2 = reader.ReadInt32(); int num3 = reader.ReadInt32(); if (num != 5037318119232611860L) { throw new MonoSymbolFileException("Symbol file is not a valid"); } if (num2 != 50) { throw new MonoSymbolFileException("Symbol file has version {0} but expected {1}", num2, 50); } if (num3 != 0) { throw new MonoSymbolFileException("Symbol file has version {0}.{1} but expected {2}.{3}", num2, num3, 50, 0); } MajorVersion = num2; MinorVersion = num3; guid = new Guid(reader.ReadBytes(16)); ot = new OffsetTable(reader, num2, num3); } catch (Exception innerException) { throw new MonoSymbolFileException("Cannot read symbol file", innerException); } source_file_hash = new Dictionary<int, SourceFileEntry>(); compile_unit_hash = new Dictionary<int, CompileUnitEntry>(); } public static MonoSymbolFile ReadSymbolFile(Assembly assembly) { string mdbFilename = assembly.Location + ".mdb"; Guid moduleVersionId = assembly.GetModules()[0].ModuleVersionId; return ReadSymbolFile(mdbFilename, moduleVersionId); } public static MonoSymbolFile ReadSymbolFile(string mdbFilename) { return ReadSymbolFile(new FileStream(mdbFilename, FileMode.Open, FileAccess.Read)); } public static MonoSymbolFile ReadSymbolFile(string mdbFilename, Guid assemblyGuid) { MonoSymbolFile monoSymbolFile = ReadSymbolFile(mdbFilename); if (assemblyGuid != monoSymbolFile.guid) { throw new MonoSymbolFileException("Symbol file `{0}' does not match assembly", mdbFilename); } return monoSymbolFile; } public static MonoSymbolFile ReadSymbolFile(Stream stream) { return new MonoSymbolFile(stream); } public SourceFileEntry GetSourceFile(int index) { if (index < 1 || index > ot.SourceCount) { throw new ArgumentException(); } if (reader == null) { throw new InvalidOperationException(); } lock (this) { if (source_file_hash.TryGetValue(index, out var value)) { return value; } long position = reader.BaseStream.Position; reader.BaseStream.Position = ot.SourceTableOffset + SourceFileEntry.Size * (index - 1); value = new SourceFileEntry(this, reader); source_file_hash.Add(index, value); reader.BaseStream.Position = position; return value; } } public CompileUnitEntry GetCompileUnit(int index) { if (index < 1 || index > ot.CompileUnitCount) { throw new ArgumentException(); } if (reader == null) { throw new InvalidOperationException(); } lock (this) { if (compile_unit_hash.TryGetValue(index, out var value)) { return value; } long position = reader.BaseStream.Position; reader.BaseStream.Position = ot.CompileUnitTableOffset + CompileUnitEntry.Size * (index - 1); value = new CompileUnitEntry(this, reader); compile_unit_hash.Add(index, value); reader.BaseStream.Position = position; return value; } } private void read_methods() { lock (this) { if (method_token_hash == null) { method_token_hash = new Dictionary<int, MethodEntry>(); method_list = new List<MethodEntry>(); long position = reader.BaseStream.Position; reader.BaseStream.Position = ot.MethodTableOffset; for (int i = 0; i < MethodCount; i++) { MethodEntry methodEntry = new MethodEntry(this, reader, i + 1); method_token_hash.Add(methodEntry.Token, methodEntry); method_list.Add(methodEntry); } reader.BaseStream.Position = position; } } } public MethodEntry GetMethodByToken(int token) { if (reader == null) { throw new InvalidOperationException(); } lock (this) { read_methods(); method_token_hash.TryGetValue(token, out var value); return value; } } public MethodEntry GetMethod(int index) { if (index < 1 || index > ot.MethodCount) { throw new ArgumentException(); } if (reader == null) { throw new InvalidOperationException(); } lock (this) { read_methods(); return method_list[index - 1]; } } public int FindSource(string file_name) { if (reader == null) { throw new InvalidOperationException(); } lock (this) { if (source_name_hash == null) { source_name_hash = new Dictionary<string, int>(); for (int i = 0; i < ot.SourceCount; i++) { SourceFileEntry sourceFile = GetSourceFile(i + 1); source_name_hash.Add(sourceFile.FileName, i); } } if (!source_name_hash.TryGetValue(file_name, out var value)) { return -1; } return value; } } public AnonymousScopeEntry GetAnonymousScope(int id) { if (reader == null) { throw new InvalidOperationException(); } lock (this) { if (anonymous_scopes != null) { anonymous_scopes.TryGetValue(id, out var value); return value; } anonymous_scopes = new Dictionary<int, AnonymousScopeEntry>(); reader.BaseStream.Position = ot.AnonymousScopeTableOffset; for (int i = 0; i < ot.AnonymousScopeCount; i++) { AnonymousScopeEntry value = new AnonymousScopeEntry(reader); anonymous_scopes.Add(value.ID, value); } return anonymous_scopes[id]; } } public void Dispose() { Dispose(disposing: true); } protected virtual void Dispose(bool disposing) { if (disposing && reader != null) { reader.Close(); reader = null; } } } public class OffsetTable { [Flags] public enum Flags { IsAspxSource = 1, WindowsFileNames = 2 } public const int MajorVersion = 50; public const int MinorVersion = 0; public const long Magic = 5037318119232611860L; public int TotalFileSize; public int DataSectionOffset; public int DataSectionSize; public int CompileUnitCount; public int CompileUnitTableOffset; public int CompileUnitTableSize; public int SourceCount; public int SourceTableOffset; public int SourceTableSize; public int MethodCount; public int MethodTableOffset; public int MethodTableSize; public int TypeCount; public int AnonymousScopeCount; public int AnonymousScopeTableOffset; public int AnonymousScopeTableSize; public Flags FileFlags; public int LineNumberTable_LineBase = -1; public int LineNumberTable_LineRange = 8; public int LineNumberTable_OpcodeBase = 9; internal OffsetTable() { int platform = (int)Environment.OSVersion.Platform; if (platform != 4 && platform != 128) { FileFlags |= Flags.WindowsFileNames; } } internal OffsetTable(BinaryReader reader, int major_version, int minor_version) { TotalFileSize = reader.ReadInt32(); DataSectionOffset = reader.ReadInt32(); DataSectionSize = reader.ReadInt32(); CompileUnitCount = reader.ReadInt32(); CompileUnitTableOffset = reader.ReadInt32(); CompileUnitTableSize = reader.ReadInt32(); SourceCount = reader.ReadInt32(); SourceTableOffset = reader.ReadInt32(); SourceTableSize = reader.ReadInt32(); MethodCount = reader.ReadInt32(); MethodTableOffset = reader.ReadInt32(); MethodTableSize = reader.ReadInt32(); TypeCount = reader.ReadInt32(); AnonymousScopeCount = reader.ReadInt32(); AnonymousScopeTableOffset = reader.ReadInt32(); AnonymousScopeTableSize = reader.ReadInt32(); LineNumberTable_LineBase = reader.ReadInt32(); LineNumberTable_LineRange = reader.ReadInt32(); LineNumberTable_OpcodeBase = reader.ReadInt32(); FileFlags = (Flags)reader.ReadInt32(); } internal void Write(BinaryWriter bw, int major_version, int minor_version) { bw.Write(TotalFileSize); bw.Write(DataSectionOffset); bw.Write(DataSectionSize); bw.Write(CompileUnitCount); bw.Write(CompileUnitTableOffset); bw.Write(CompileUnitTableSize); bw.Write(SourceCount); bw.Write(SourceTableOffset); bw.Write(SourceTableSize); bw.Write(MethodCount); bw.Write(MethodTableOffset); bw.Write(MethodTableSize); bw.Write(TypeCount); bw.Write(AnonymousScopeCount); bw.Write(AnonymousScopeTableOffset); bw.Write(AnonymousScopeTableSize); bw.Write(LineNumberTable_LineBase); bw.Write(LineNumberTable_LineRange); bw.Write(LineNumberTable_OpcodeBase); bw.Write((int)FileFlags); } public override string ToString() { return $"OffsetTable [{TotalFileSize} - {DataSectionOffset}:{DataSectionSize} - {SourceCount}:{SourceTableOffset}:{SourceTableSize} - {MethodCount}:{MethodTableOffset}:{MethodTableSize} - {TypeCount}]"; } } public class LineNumberEntry { public sealed class LocationComparer : IComparer<LineNumberEntry> { public static readonly LocationComparer Default = new LocationComparer(); public int Compare(LineNumberEntry l1, LineNumberEntry l2) { if (l1.Row != l2.Row) { int row = l1.Row; return row.CompareTo(l2.Row); } return l1.Column.CompareTo(l2.Column); } } public readonly int Row; public int Column; public int EndRow; public int EndColumn; public readonly int File; public readonly int Offset; public readonly bool IsHidden; public static readonly LineNumberEntry Null = new LineNumberEntry(0, 0, 0, 0); public LineNumberEntry(int file, int row, int column, int offset) : this(file, row, column, offset, is_hidden: false) { } public LineNumberEntry(int file, int row, int offset) : this(file, row, -1, offset, is_hidden: false) { } public LineNumberEntry(int file, int row, int column, int offset, bool is_hidden) : this(file, row, column, -1, -1, offset, is_hidden) { } public LineNumberEntry(int file, int row, int column, int end_row, int end_column, int offset, bool is_hidden) { File = file; Row = row; Column = column; EndRow = end_row; EndColumn = end_column; Offset = offset; IsHidden = is_hidden; } public override string ToString() { return string.Format("[Line {0}:{1,2}-{3,4}:{5}]", File, Row, Column, EndRow, EndColumn, Offset); } } public class CodeBlockEntry { public enum Type { Lexical = 1, CompilerGenerated, IteratorBody, IteratorDispatcher } public int Index; public int Parent; public Type BlockType; public int StartOffset; public int EndOffset; public CodeBlockEntry(int index, int parent, Type type, int start_offset) { Index = index; Parent = parent; BlockType = type; StartOffset = start_offset; } internal CodeBlockEntry(int index, MyBinaryReader reader) { Index = index; int num = reader.ReadLeb128(); BlockType = (Type)(num & 0x3F); Parent = reader.ReadLeb128(); StartOffset = reader.ReadLeb128(); EndOffset = reader.ReadLeb128(); if (((uint)num & 0x40u) != 0) { int num2 = reader.ReadInt16(); reader.BaseStream.Position += num2; } } public void Close(int end_offset) { EndOffset = end_offset; } internal void Write(MyBinaryWriter bw) { bw.WriteLeb128((int)BlockType); bw.WriteLeb128(Parent); bw.WriteLeb128(StartOffset); bw.WriteLeb128(EndOffset); } public override string ToString() { return $"[CodeBlock {Index}:{Parent}:{BlockType}:{StartOffset}:{EndOffset}]"; } } public struct LocalVariableEntry { public readonly int Index; public readonly string Name; public readonly int BlockIndex; public LocalVariableEntry(int index, string name, int block) { Index = index; Name = name; BlockIndex = block; } internal LocalVariableEntry(MonoSymbolFile file, MyBinaryReader reader) { Index = reader.ReadLeb128(); Name = reader.ReadString(); BlockIndex = reader.ReadLeb128(); } internal void Write(MonoSymbolFile file, MyBinaryWriter bw) { bw.WriteLeb128(Index); bw.Write(Name); bw.WriteLeb128(BlockIndex); } public override string ToString() { return $"[LocalVariable {Name}:{Index}:{BlockIndex - 1}]"; } } public struct CapturedVariable { public enum CapturedKind : byte { Local, Parameter, This } public readonly string Name; public readonly string CapturedName; public readonly CapturedKind Kind; public CapturedVariable(string name, string captured_name, CapturedKind kind) { Name = name; CapturedName = captured_name; Kind = kind; } internal CapturedVariable(MyBinaryReader reader) { Name = reader.ReadString(); CapturedName = reader.ReadString(); Kind = (CapturedKind)reader.ReadByte(); } internal void Write(MyBinaryWriter bw) { bw.Write(Name); bw.Write(CapturedName); bw.Write((byte)Kind); } public override string ToString() { return $"[CapturedVariable {Name}:{CapturedName}:{Kind}]"; } } public struct CapturedScope { public readonly int Scope; public readonly string CapturedName; public CapturedScope(int scope, string captured_name) { Scope = scope; CapturedName = captured_name; } internal CapturedScope(MyBinaryReader reader) { Scope = reader.ReadLeb128(); CapturedName = reader.ReadString(); } internal void Write(MyBinaryWriter bw) { bw.WriteLeb128(Scope); bw.Write(CapturedName); } public override string ToString() { return $"[CapturedScope {Scope}:{CapturedName}]"; } } public struct ScopeVariable { public readonly int Scope; public readonly int Index; public ScopeVariable(int scope, int index) { Scope = scope; Index = index; } internal ScopeVariable(MyBinaryReader reader) { Scope = reader.ReadLeb128(); Index = reader.ReadLeb128(); } internal void Write(MyBinaryWriter bw) { bw.WriteLeb128(Scope); bw.WriteLeb128(Index); } public override string ToString() { return $"[ScopeVariable {Scope}:{Index}]"; } } public class AnonymousScopeEntry { public readonly int ID; private List<CapturedVariable> captured_vars = new List<CapturedVariable>(); private List<CapturedScope> captured_scopes = new List<CapturedScope>(); public CapturedVariable[] CapturedVariables { get { CapturedVariable[] array = new CapturedVariable[captured_vars.Count]; captured_vars.CopyTo(array, 0); return array; } } public CapturedScope[] CapturedScopes { get { CapturedScope[] array = new CapturedScope[captured_scopes.Count]; captured_scopes.CopyTo(array, 0); return array; } } public AnonymousScopeEntry(int id) { ID = id; } internal AnonymousScopeEntry(MyBinaryReader reader) { ID = reader.ReadLeb128(); int num = reader.ReadLeb128(); for (int i = 0; i < num; i++) { captured_vars.Add(new CapturedVariable(reader)); } int num2 = reader.ReadLeb128(); for (int j = 0; j < num2; j++) { captured_scopes.Add(new CapturedScope(reader)); } } internal void AddCapturedVariable(string name, string captured_name, CapturedVariable.CapturedKind kind) { captured_vars.Add(new CapturedVariable(name, captured_name, kind)); } internal void AddCapturedScope(int scope, string captured_name) { captured_scopes.Add(new CapturedScope(scope, captured_name)); } internal void Write(MyBinaryWriter bw) { bw.WriteLeb128(ID); bw.WriteLeb128(captured_vars.Count); foreach (CapturedVariable captured_var in captured_vars) { captured_var.Write(bw); } bw.WriteLeb128(captured_scopes.Count); foreach (CapturedScope captured_scope in captured_scopes) { captured_scope.Write(bw); } } public override string ToString() { return $"[AnonymousScope {ID}]"; } } public class CompileUnitEntry : ICompileUnit { public readonly int Index; private int DataOffset; private MonoSymbolFile file; private SourceFileEntry source; private List<SourceFileEntry> include_files; private List<NamespaceEntry> namespaces; private bool creating; public static int Size => 8; CompileUnitEntry ICompileUnit.Entry => this; public SourceFileEntry SourceFile { get { if (creating) { return source; } ReadData(); return source; } } public NamespaceEntry[] Namespaces { get { ReadData(); NamespaceEntry[] array = new NamespaceEntry[namespaces.Count]; namespaces.CopyTo(array, 0); return array; } } public SourceFileEntry[] IncludeFiles { get { ReadData(); if (include_files == null) { return new SourceFileEntry[0]; } SourceFileEntry[] array = new SourceFileEntry[include_files.Count]; include_files.CopyTo(array, 0); return array; } } public CompileUnitEntry(MonoSymbolFile file, SourceFileEntry source) { this.file = file; this.source = source; Index = file.AddCompileUnit(this); creating = true; namespaces = new List<NamespaceEntry>(); } public void AddFile(SourceFileEntry file) { if (!creating) { throw new InvalidOperationException(); } if (include_files == null) { include_files = new List<SourceFileEntry>(); } include_files.Add(file); } public int DefineNamespace(string name, string[] using_clauses, int parent) { if (!creating) { throw new InvalidOperationException(); } int nextNamespaceIndex = file.GetNextNamespaceIndex(); NamespaceEntry item = new NamespaceEntry(name, nextNamespaceIndex, using_clauses, parent); namespaces.Add(item); return nextNamespaceIndex; } internal void WriteData(MyBinaryWriter bw) { DataOffset = (int)bw.BaseStream.Position; bw.WriteLeb128(source.Index); int value = ((include_files != null) ? include_files.Count : 0); bw.WriteLeb128(value); if (include_files != null) { foreach (SourceFileEntry include_file in include_files) { bw.WriteLeb128(include_file.Index); } } bw.WriteLeb128(namespaces.Count); foreach (NamespaceEntry @namespace in namespaces) { @namespace.Write(file, bw); } } internal void Write(BinaryWriter bw) { bw.Write(Index); bw.Write(DataOffset); } internal CompileUnitEntry(MonoSymbolFile file, MyBinaryReader reader) { this.file = file; Index = reader.ReadInt32(); DataOffset = reader.ReadInt32(); } public void ReadAll() { ReadData(); } private void ReadData() { if (creating) { throw new InvalidOperationException(); } lock (file) { if (namespaces != null) { return; } MyBinaryReader binaryReader = file.BinaryReader; int num = (int)binaryReader.BaseStream.Position; binaryReader.BaseStream.Position = DataOffset; int index = binaryReader.ReadLeb128(); source = file.GetSourceFile(index); int num2 = binaryReader.ReadLeb128(); if (num2 > 0) { include_files = new List<SourceFileEntry>(); for (int i = 0; i < num2; i++) { include_files.Add(file.GetSourceFile(binaryReader.ReadLeb128())); } } int num3 = binaryReader.ReadLeb128(); namespaces = new List<NamespaceEntry>(); for (int j = 0; j < num3; j++) { namespaces.Add(new NamespaceEntry(file, binaryReader)); } binaryReader.BaseStream.Position = num; } } } public class SourceFileEntry { public readonly int Index; private int DataOffset; private MonoSymbolFile file; private string file_name; private byte[] guid; private byte[] hash; private bool creating; private bool auto_generated; private readonly string sourceFile; public static int Size => 8; public byte[] Checksum => hash; public string FileName { get { return file_name; } set { file_name = value; } } public bool AutoGenerated => auto_generated; public SourceFileEntry(MonoSymbolFile file, string file_name) { this.file = file; this.file_name = file_name; Index = file.AddSource(this); creating = true; } public SourceFileEntry(MonoSymbolFile file, string sourceFile, byte[] guid, byte[] checksum) : this(file, sourceFile, sourceFile, guid, checksum) { } public SourceFileEntry(MonoSymbolFile file, string fileName, string sourceFile, byte[] guid, byte[] checksum) : this(file, fileName) { this.guid = guid; hash = checksum; this.sourceFile = sourceFile; } internal void WriteData(MyBinaryWriter bw) { DataOffset = (int)bw.BaseStream.Position; bw.Write(file_name); if (guid == null) { guid = new byte[16]; } if (hash == null) { try { using FileStream inputStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read); MD5 mD = MD5.Create(); hash = mD.ComputeHash(inputStream); } catch { hash = new byte[16]; } } bw.Write(guid); bw.Write(hash); bw.Write(auto_generated ? ((byte)1) : ((byte)0)); } internal void Write(BinaryWriter bw) { bw.Write(Index); bw.Write(DataOffset); } internal SourceFileEntry(MonoSymbolFile file, MyBinaryReader reader) { this.file = file; Index = reader.ReadInt32(); DataOffset = reader.ReadInt32(); int num = (int)reader.BaseStream.Position; reader.BaseStream.Position = DataOffset; sourceFile = (file_name = reader.ReadString()); guid = reader.ReadBytes(16); hash = reader.ReadBytes(16); auto_generated = reader.ReadByte() == 1; reader.BaseStream.Position = num; } public void SetAutoGenerated() { if (!creating) { throw new InvalidOperationException(); } auto_generated = true; file.OffsetTable.FileFlags |= OffsetTable.Flags.IsAspxSource; } public bool CheckChecksum() { try { using FileStream inputStream = new FileStream(sourceFile, FileMode.Open); byte[] array = MD5.Create().ComputeHash(inputStream); for (int i = 0; i < 16; i++) { if (array[i] != hash[i]) { return false; } } return true; } catch { return false; } } public override string ToString() { return $"SourceFileEntry ({Index}:{DataOffset})"; } } public class LineNumberTable { protected LineNumberEntry[] _line_numbers; public readonly int LineBase; public readonly int LineRange; public readonly byte OpcodeBase; public readonly int MaxAddressIncrement; public const int Default_LineBase = -1; public const int Default_LineRange = 8; public const byte Default_OpcodeBase = 9; public const byte DW_LNS_copy = 1; public const byte DW_LNS_advance_pc = 2; public const byte DW_LNS_advance_line = 3; public const byte DW_LNS_set_file = 4; public const byte DW_LNS_const_add_pc = 8; public const byte DW_LNE_end_sequence = 1; public const byte DW_LNE_MONO_negate_is_hidden = 64; internal const byte DW_LNE_MONO__extensions_start = 64; internal const byte DW_LNE_MONO__extensions_end = 127; public LineNumberEntry[] LineNumbers => _line_numbers; protected LineNumberTable(MonoSymbolFile file) { LineBase = file.OffsetTable.LineNumberTable_LineBase; LineRange = file.OffsetTable.LineNumberTable_LineRange; OpcodeBase = (byte)file.OffsetTable.LineNumberTable_OpcodeBase; MaxAddressIncrement = (255 - OpcodeBase) / LineRange; } internal LineNumberTable(MonoSymbolFile file, LineNumberEntry[] lines) : this(file) { _line_numbers = lines; } internal void Write(MonoSymbolFile file, MyBinaryWriter bw, bool hasColumnsInfo, bool hasEndInfo) { int num = (int)bw.BaseStream.Position; bool flag = false; int num2 = 1; int num3 = 0; int num4 = 1; for (int i = 0; i < LineNumbers.Length; i++) { int num5 = LineNumbers[i].Row - num2; int num6 = LineNumbers[i].Offset - num3; if (LineNumbers[i].File != num4) { bw.Write((byte)4); bw.WriteLeb128(LineNumbers[i].File); num4 = LineNumbers[i].File; } if (LineNumbers[i].IsHidden != flag) { bw.Write((byte)0); bw.Write((byte)1); bw.Write((byte)64); flag = LineNumbers[i].IsHidden; } if (num6 >= MaxAddressIncrement) { if (num6 < 2 * MaxAddressIncrement) { bw.Write((byte)8); num6 -= MaxAddressIncrement; } else { bw.Write((byte)2); bw.WriteLeb128(num6); num6 = 0; } } if (num5 < LineBase || num5 >= LineBase + LineRange) { bw.Write((byte)3); bw.WriteLeb128(num5); if (num6 != 0) { bw.Write((byte)2); bw.WriteLeb128(num6); } bw.Write((byte)1); } else { byte value = (byte)(num5 - LineBase + LineRange * num6 + OpcodeBase); bw.Write(value); } num2 = LineNumbers[i].Row; num3 = LineNumbers[i].Offset; } bw.Write((byte)0); bw.Write((byte)1); bw.Write((byte)1); if (hasColumnsInfo) { for (int j = 0; j < LineNumbers.Length; j++) { LineNumberEntry lineNumberEntry = LineNumbers[j]; if (lineNumberEntry.Row >= 0) { bw.WriteLeb128(lineNumberEntry.Column); } } } if (hasEndInfo) { for (int k = 0; k < LineNumbers.Length; k++) { LineNumberEntry lineNumberEntry2 = LineNumbers[k]; if (lineNumberEntry2.EndRow == -1 || lineNumberEntry2.EndColumn == -1 || lineNumberEntry2.Row > lineNumberEntry2.EndRow) { bw.WriteLeb128(16777215); continue; } bw.WriteLeb128(lineNumberEntry2.EndRow - lineNumberEntry2.Row); bw.WriteLeb128(lineNumberEntry2.EndColumn); } } file.ExtendedLineNumberSize += (int)bw.BaseStream.Position - num; } internal static LineNumberTable Read(MonoSymbolFile file, MyBinaryReader br, bool readColumnsInfo, bool readEndInfo) { LineNumberTable lineNumberTable = new LineNumberTable(file); lineNumberTable.DoRead(file, br, readColumnsInfo, readEndInfo); return lineNumberTable; } private void DoRead(MonoSymbolFile file, MyBinaryReader br, bool includesColumns, bool includesEnds) { List<LineNumberEntry> list = new List<LineNumberEntry>(); bool flag = false; bool flag2 = false; int num = 1; int num2 = 0; int file2 = 1; while (true) { byte b = br.ReadByte(); if (b == 0) { byte b2 = br.ReadByte(); long position = br.BaseStream.Position + b2; b = br.ReadByte(); switch (b) { case 1: { if (flag2) { list.Add(new LineNumberEntry(file2, num, -1, num2, flag)); } _line_numbers = list.ToArray(); if (includesColumns) { for (int i = 0; i < _line_numbers.Length; i++) { LineNumberEntry lineNumberEntry = _line_numbers[i]; if (lineNumberEntry.Row >= 0) { lineNumberEntry.Column = br.ReadLeb128(); } } } if (!includesEnds) { return; } for (int j = 0; j < _line_numbers.Length; j++) { LineNumberEntry lineNumberEntry2 = _line_numbers[j]; int num3 = br.ReadLeb128(); if (num3 == 16777215) { lineNumberEntry2.EndRow = -1; lineNumberEntry2.EndColumn = -1; } else { lineNumberEntry2.EndRow = lineNumberEntry2.Row + num3; lineNumberEntry2.EndColumn = br.ReadLeb128(); } } return; } case 64: flag = !flag; flag2 = true; break; default: throw new MonoSymbolFileException("Unknown extended opcode {0:x}", b); case 65: case 66: case 67: case 68: case 69: case 70: case 71: case 72: case 73: case 74: case 75: case 76: case 77: case 78: case 79: case 80: case 81: case 82: case 83: case 84: case 85: case 86: case 87: case 88: case 89: case 90: case 91: case 92: case 93: case 94: case 95: case 96: case 97: case 98: case 99: case 100: case 101: case 102: case 103: case 104: case 105: case 106: case 107: case 108: case 109: case 110: case 111: case 112: case 113: case 114: case 115: case 116: case 117: case 118: case 119: case 120: case 121: case 122: case 123: case 124: case 125: case 126: case 127: break; } br.BaseStream.Position = position; } else if (b < OpcodeBase) { switch (b) { case 1: list.Add(new LineNumberEntry(file2, num, -1, num2, flag)); flag2 = false; break; case 2: num2 += br.ReadLeb128(); flag2 = true; break; case 3: num += br.ReadLeb128(); flag2 = true; break; case 4: file2 = br.ReadLeb128(); flag2 = true; break; case 8: num2 += MaxAddressIncrement; flag2 = true; break; default: throw new MonoSymbolFileException("Unknown standard opcode {0:x} in LNT", b); } } else { b -= OpcodeBase; num2 += b / LineRange; num += LineBase + b % LineRange; list.Add(new LineNumberEntry(file2, num, -1, num2, flag)); flag2 = false; } } } public bool GetMethodBounds(out LineNumberEntry start, out LineNumberEntry end) { if (_line_numbers.Length > 1) { start = _line_numbers[0]; end = _line_numbers[_line_numbers.Length - 1]; return true; } start = LineNumberEntry.Null; end = LineNumberEntry.Null; return false; } } public class MethodEntry : IComparable { [Flags] public enum Flags { LocalNamesAmbiguous = 1, ColumnsInfoIncluded = 2, EndInfoIncluded = 4 } public readonly int CompileUnitIndex; public readonly int Token; public readonly int NamespaceID; private int DataOffset; private int LocalVariableTableOffset; private int LineNumberTableOffset; private int CodeBlockTableOffset; private int ScopeVariableTableOffset; private int RealNameOffset; private Flags flags; private int index; public readonly CompileUnitEntry CompileUnit; private LocalVariableEntry[] locals; private CodeBlockEntry[] code_blocks; private ScopeVariable[] scope_vars; private LineNumberTable lnt; private string real_name; public readonly MonoSymbolFile SymbolFile; public const int Size = 12; public Flags MethodFlags => flags; public int Index { get { return index; } set { index = value; } } internal MethodEntry(MonoSymbolFile file, MyBinaryReader reader, int index) { SymbolFile = file; this.index = index; Token = reader.ReadInt32(); DataOffset = reader.ReadInt32(); LineNumberTableOffset = reader.ReadInt32(); long position = reader.BaseStream.Position; reader.BaseStream.Position = DataOffset; CompileUnitIndex = reader.ReadLeb128(); LocalVariableTableOffset = reader.ReadLeb128(); NamespaceID = reader.ReadLeb128(); CodeBlockTableOffset = reader.ReadLeb128(); ScopeVariableTableOffset = reader.ReadLeb128(); RealNameOffset = reader.ReadLeb128(); flags = (Flags)reader.ReadLeb128(); reader.BaseStream.Position = position; CompileUnit = file.GetCompileUnit(CompileUnitIndex); } internal MethodEntry(MonoSymbolFile file, CompileUnitEntry comp_unit, int token, ScopeVariable[] scope_vars, LocalVariableEntry[] locals, LineNumberEntry[] lines, CodeBlockEntry[] code_blocks, string real_name, Flags flags, int namespace_id) { SymbolFile = file; this.real_name = real_name; this.locals = locals; this.code_blocks = code_blocks; this.scope_vars = scope_vars; this.flags = flags; index = -1; Token = token; CompileUnitIndex = comp_unit.Index; CompileUnit = comp_unit; NamespaceID = namespace_id; CheckLineNumberTable(lines); lnt = new LineNumberTable(file, lines); file.NumLineNumbers += lines.Length; int num = ((locals != null) ? locals.Length : 0); if (num <= 32) { for (int i = 0; i < num; i++) { string name = locals[i].Name; for (int j = i + 1; j < num; j++) { if (locals[j].Name == name) { flags |= Flags.LocalNamesAmbiguous; return; } } } return; } Dictionary<string, LocalVariableEntry> dictionary = new Dictionary<string, LocalVariableEntry>(); for (int k = 0; k < locals.Length; k++) { LocalVariableEntry value = locals[k]; if (dictionary.ContainsKey(value.Name)) { flags |= Flags.LocalNamesAmbiguous; break; } dictionary.Add(value.Name, value); } } private static void CheckLineNumberTable(LineNumberEntry[] line_numbers) { int num = -1; int num2 = -1; if (line_numbers == null) { return; } foreach (LineNumberEntry lineNumberEntry in line_numbers) { if (lineNumberEntry.Equals(LineNumberEntry.Null)) { throw new MonoSymbolFileException(); } if (lineNumberEntry.Offset < num) { throw new MonoSymbolFileException(); } if (lineNumberEntry.Offset > num) { num2 = lineNumberEntry.Row; num = lineNumberEntry.Offset; } else if (lineNumberEntry.Row > num2) { num2 = lineNumberEntry.Row; } } } internal void Write(MyBinaryWriter bw) { if (index <= 0 || DataOffset == 0) { throw new InvalidOperationException(); } bw.Write(Token); bw.Write(DataOffset); bw.Write(LineNumberTableOffset); } internal void WriteData(MonoSymbolFile file, MyBinaryWriter bw) { if (index <= 0) { throw new InvalidOperationException(); } LocalVariableTableOffset = (int)bw.BaseStream.Position; int num = ((locals != null) ? locals.Length : 0); bw.WriteLeb128(num); for (int i = 0; i < num; i++) { locals[i].Write(file, bw); } file.LocalCount += num; CodeBlockTableOffset = (int)bw.BaseStream.Position; int num2 = ((code_blocks != null) ? code_blocks.Length : 0); bw.WriteLeb128(num2); for (int j = 0; j < num2; j++) { code_blocks[j].Write(bw); } ScopeVariableTableOffset = (int)bw.BaseStream.Position; int num3 = ((scope_vars != null) ? scope_vars.Length : 0); bw.WriteLeb128(num3); for (int k = 0; k < num3; k++) { scope_vars[k].Write(bw); } if (real_name != null) { RealNameOffset = (int)bw.BaseStream.Position; bw.Write(real_name); } LineNumberEntry[] lineNumbers = lnt.LineNumbers; foreach (LineNumberEntry lineNumberEntry in lineNumbers) { if (lineNumberEntry.EndRow != -1 || lineNumberEntry.EndColumn != -1) { flags |= Flags.EndInfoIncluded; } } LineNumberTableOffset = (int)bw.BaseStream.Position; lnt.Write(file, bw, (flags & Flags.ColumnsInfoIncluded) != 0, (flags & Flags.EndInfoIncluded) != 0); DataOffset = (int)bw.BaseStream.Position; bw.WriteLeb128(CompileUnitIndex); bw.WriteLeb128(LocalVariableTableOffset); bw.WriteLeb128(NamespaceID); bw.WriteLeb128(CodeBlockTableOffset); bw.WriteLeb128(ScopeVariableTableOffset); bw.WriteLeb128(RealNameOffset); bw.WriteLeb128((int)flags); } public void ReadAll() { GetLineNumberTable(); GetLocals(); GetCodeBlocks(); GetScopeVariables(); GetRealName(); } public LineNumberTable GetLineNumberTable() { lock (SymbolFile) { if (lnt != null) { return lnt; } if (LineNumberTableOffset == 0) { return null; } MyBinaryReader binaryReader = SymbolFile.BinaryReader; long position = binaryReader.BaseStream.Position; binaryReader.BaseStream.Position = LineNumberTableOffset; lnt = LineNumberTable.Read(SymbolFile, binaryReader, (flags & Flags.ColumnsInfoIncluded) != 0, (flags & Flags.EndInfoIncluded) != 0); binaryReader.BaseStream.Position = position; return lnt; } } public LocalVariableEntry[] GetLocals() { lock (SymbolFile) { if (locals != null) { return locals; } if (LocalVariableTableOffset == 0) { return null; } MyBinaryReader binaryReader = SymbolFile.BinaryReader; long position = binaryReader.BaseStream.Position; binaryReader.BaseStream.Position = LocalVariableTableOffset; int num = binaryReader.ReadLeb128(); locals = new LocalVariableEntry[num]; for (int i = 0; i < num; i++) { locals[i] = new LocalVariableEntry(SymbolFile, binaryReader); } binaryReader.BaseStream.Position = position; return locals; } } public CodeBlockEntry[] GetCodeBlocks() { lock (SymbolFile) { if (code_blocks != null) { return code_blocks; } if (CodeBlockTableOffset == 0) { return null; } MyBinaryReader binaryReader = SymbolFile.BinaryReader; long position = binaryReader.BaseStream.Position; binaryReader.BaseStream.Position = CodeBlockTableOffset; int num = binaryReader.ReadLeb128(); code_blocks = new CodeBlockEntry[num]; for (int i = 0; i < num; i++) { code_blocks[i] = new CodeBlockEntry(i, binaryReader); } binaryReader.BaseStream.Position = position; return code_blocks; } } public ScopeVariable[] GetScopeVariables() { lock (SymbolFile) { if (scope_vars != null) { return scope_vars; } if (ScopeVariableTableOffset == 0) { return null; } MyBinaryReader binaryReader = SymbolFile.BinaryReader; long position = binaryReader.BaseStream.Position; binaryReader.BaseStream.Position = ScopeVariableTableOffset; int num = binaryReader.ReadLeb128(); scope_vars = new ScopeVariable[num]; for (int i = 0; i < num; i++) { scope_vars[i] = new ScopeVariable(binaryReader); } binaryReader.BaseStream.Position = position; return scope_vars; } } public string GetRealName() { lock (SymbolFile) { if (real_name != null) { return real_name; } if (RealNameOffset == 0) { return null; } real_name = SymbolFile.BinaryReader.ReadString(RealNameOffset); return real_name; } } public int CompareTo(object obj) { MethodEntry methodEntry = (MethodEntry)obj; if (methodEntry.Token < Token) { return 1; } if (methodEntry.Token > Token) { return -1; } return 0; } public override string ToString() { return $"[Method {index}:{Token:x}:{CompileUnitIndex}:{CompileUnit}]"; } } public struct NamespaceEntry { public readonly string Name; public readonly int Index; public readonly int Parent; public readonly string[] UsingClauses; public NamespaceEntry(string name, int index, string[] using_clauses, int parent) { Name = name; Index = index; Parent = parent; UsingClauses = ((using_clauses != null) ? using_clauses : new string[0]); } internal NamespaceEntry(MonoSymbolFile file, MyBinaryReader reader) { Name = reader.ReadString(); Index = reader.ReadLeb128(); Parent = reader.ReadLeb128(); int num = reader.ReadLeb128(); UsingClauses = new string[num]; for (int i = 0; i < num; i++) { UsingClauses[i] = reader.ReadString(); } } internal void Write(MonoSymbolFile file, MyBinaryWriter bw) { bw.Write(Name); bw.WriteLeb128(Index); bw.WriteLeb128(Parent); bw.WriteLeb128(UsingClauses.Length); string[] usingClauses = UsingClauses; foreach (string value in usingClauses) { bw.Write(value); } } public override string ToString() { return $"[Namespace {Name}:{Index}:{Parent}]"; } } public class SourceMethodBuilder { private List<LocalVariableEntry> _locals; private List<CodeBlockEntry> _blocks; private List<ScopeVariable> _scope_vars; private Stack<CodeBlockEntry> _block_stack; private readonly List<LineNumberEntry> method_lines; private readonly ICompileUnit _comp_unit; private readonly int ns_id; private readonly IMethodDef method; public CodeBlockEntry[] Blocks { get { if (_blocks == null) { return new CodeBlockEntry[0]; } CodeBlockEntry[] array = new CodeBlockEntry[_blocks.Count]; _blocks.CopyTo(array, 0); return array; } } public CodeBlockEntry CurrentBlock { get { if (_block_stack != null && _block_stack.Count > 0) { return _block_stack.Peek(); } return null; } } public LocalVariableEntry[] Locals { get { if (_locals == null) { return new LocalVariableEntry[0]; } return _locals.ToArray(); } } public ICompileUnit SourceFile => _comp_unit; public ScopeVariable[] ScopeVariables { get { if (_scope_vars == null) { return new ScopeVariable[0]; } return _scope_vars.ToArray(); } } public SourceMethodBuilder(ICompileUnit comp_unit) { _comp_unit = comp_unit; method_lines = new List<LineNumberEntry>(); } public SourceMethodBuilder(ICompileUnit comp_unit, int ns_id, IMethodDef method) : this(comp_unit) { this.ns_id = ns_id; this.method = method; } public void MarkSequencePoint(int offset, SourceFileEntry file, int line, int column, bool is_hidden) { MarkSequencePoint(offset, file, line, column, -1, -1, is_hidden); } public void MarkSequencePoint(int offset, SourceFileEntry file, int line, int column, int end_line, int end_column, bool is_hidden) { LineNumberEntry lineNumberEntry = new LineNumberEntry(file?.Index ?? 0, line, column, end_line, end_column, offset, is_hidden); if (method_lines.Count > 0) { LineNumberEntry lineNumberEntry2 = method_lines[method_lines.Count - 1]; if (lineNumberEntry2.Offset == offset) { if (LineNumberEntry.LocationComparer.Default.Compare(lineNumberEntry, lineNumberEntry2) > 0) { method_lines[method_lines.Count - 1] = lineNumberEntry; } return; } } method_lines.Add(lineNumberEntry); } public void StartBlock(CodeBlockEntry.Type type, int start_offset) { StartBlock(type, start_offset, (_blocks == null) ? 1 : (_blocks.Count + 1)); } public void StartBlock(CodeBlockEntry.Type type, int start_offset, int scopeIndex) { if (_block_stack == null) { _block_stack = new Stack<CodeBlockEntry>(); } if (_blocks == null) { _blocks = new List<CodeBlockEntry>(); } int parent = ((CurrentBlock != null) ? CurrentBlock.Index : (-1)); CodeBlockEntry item = new CodeBlockEntry(scopeIndex, parent, type, start_offset); _block_stack.Push(item); _blocks.Add(item); } public void EndBlock(int end_offset) { _block_stack.Pop().Close(end_offset); } public void AddLocal(int index, string name) { if (_locals == null) { _locals = new List<LocalVariableEntry>(); } int block = ((CurrentBlock != null) ? CurrentBlock.Index : 0); _locals.Add(new LocalVariableEntry(index, name, block)); } public void AddScopeVariable(int scope, int index) { if (_scope_vars == null) { _scope_vars = new List<ScopeVariable>(); } _scope_vars.Add(new ScopeVariable(scope, index)); } public void DefineMethod(MonoSymbolFile file) { DefineMethod(file, method.Token); } public void DefineMethod(MonoSymbolFile file, int token) { CodeBlockEntry[] array = Blocks; if (array.Length != 0) { List<CodeBlockEntry> list = new List<CodeBlockEntry>(array.Length); int num = 0; for (int i = 0; i < array.Length; i++) { num = Math.Max(num, array[i].Index); } for (int j = 0; j < num; j++) { int num2 = j + 1; if (j < array.Length && array[j].Index == num2) { list.Add(array[j]); continue; } bool flag = false; for (int k = 0; k < array.Length; k++) { if (array[k].Index == num2) { list.Add(array[k]); flag = true; break; } } if (!flag) { list.Add(new CodeBlockEntry(num2, -1, CodeBlockEntry.Type.CompilerGenerated, 0)); } } array = list.ToArray(); } MethodEntry entry = new MethodEntry(file, _comp_unit.Entry, token, ScopeVariables, Locals, method_lines.ToArray(), array, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id); file.AddMethod(entry); } } } namespace Mono.Security.Cryptography { public sealed class CryptoConvert { private CryptoConvert() { } private static int ToInt32LE(byte[] bytes, int offset) { return (bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1] << 8) | bytes[offset]; } private static uint ToUInt32LE(byte[] bytes, int offset) { return (uint)((bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1] << 8) | bytes[offset]); } private static byte[] GetBytesLE(int val) { return new byte[4] { (byte)((uint)val & 0xFFu), (byte)((uint)(val >> 8) & 0xFFu), (byte)((uint)(val >> 16) & 0xFFu), (byte)((uint)(val >> 24) & 0xFFu) }; } private static byte[] Trim(byte[] array) { for (int i = 0; i < array.Length; i++) { if (array[i] != 0) { byte[] array2 = new byte[array.Length - i]; Buffer.BlockCopy(array, i, array2, 0, array2.Length); return array2; } } return null; } public static RSA FromCapiPrivateKeyBlob(byte[] blob) { return FromCapiPrivateKeyBlob(blob, 0); } public static RSA FromCapiPrivateKeyBlob(byte[] blob, int offset) { RSAParameters parametersFromCapiPrivateKeyBlob = GetParametersFromCapiPrivateKeyBlob(blob, offset); RSA rSA = null; try { rSA = RSA.Create(); rSA.ImportParameters(parametersFromCapiPrivateKeyBlob); } catch (CryptographicException ex) { try { rSA = new RSACryptoServiceProvider(new CspParameters { Flags = CspProviderFlags.UseMachineKeyStore }); rSA.ImportParameters(parametersFromCapiPrivateKeyBlob); } catch { throw ex; } } return rSA; } private static RSAParameters GetParametersFromCapiPrivateKeyBlob(byte[] blob, int offset) { if (blob == null) { throw new ArgumentNullException("blob"); } if (offset >= blob.Length) { throw new ArgumentException("blob is too small."); } RSAParameters result = default(RSAParameters); try { if (blob[offset] != 7 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || ToUInt32LE(blob, offset + 8) != 843141970) { throw new CryptographicException("Invalid blob header"); } int num = ToInt32LE(blob, offset + 12); byte[] array = new byte[4]; Buffer.BlockCopy(blob, offset + 16, array, 0, 4); Array.Reverse((Array)array); result.Exponent = Trim(array); int num2 = offset + 20; int num3 = num >> 3; result.Modulus = new byte[num3]; Buffer.BlockCopy(blob, num2, result.Modulus, 0, num3); Array.Reverse((Array)result.Modulus); num2 += num3; int num4 = num3 >> 1; result.P = new byte[num4]; Buffer.BlockCopy(blob, num2, result.P, 0, num4); Array.Reverse((Array)result.P); num2 += num4; result.Q = new byte[num4]; Buffer.BlockCopy(blob, num2, result.Q, 0, num4); Array.Reverse((Array)result.Q); num2 += num4; result.DP = new byte[num4]; Buffer.BlockCopy(blob, num2, result.DP, 0, num4); Array.Reverse((Array)result.DP); num2 += num4; result.DQ = new byte[num4]; Buffer.BlockCopy(blob, num2, result.DQ, 0, num4); Array.Reverse((Array)result.DQ); num2 += num4; result.InverseQ = new byte[num4]; Buffer.BlockCopy(blob, num2, result.InverseQ, 0, num4); Array.Reverse((Array)result.InverseQ); num2 += num4; result.D = new byte[num3]; if (num2 + num3 + offset <= blob.Length) { Buffer.BlockCopy(blob, num2, result.D, 0, num3); Array.Reverse((Array)result.D); } return result; } catch (Exception inner) { throw new CryptographicException("Invalid blob.", inner); } } public static DSA FromCapiPrivateKeyBlobDSA(byte[] blob) { return FromCapiPrivateKeyBlobDSA(blob, 0); } public static DSA FromCapiPrivateKeyBlobDSA(byte[] blob, int offset) { if (blob == null) { throw new ArgumentNullException("blob"); } if (offset >= blob.Length) { throw new ArgumentException("blob is too small."); } DSAParameters parameters = default(DSAParameters); try { if (blob[offset] != 7 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || ToUInt32LE(blob, offset + 8) != 844321604) { throw new CryptographicException("Invalid blob header"); } int num = ToInt32LE(blob, offset + 12) >> 3; int num2 = offset + 16; parameters.P = new byte[num]; Buffer.BlockCopy(blob, num2, parameters.P, 0, num); Array.Reverse((Array)parameters.P); num2 += num; parameters.Q = new byte[20]; Buffer.BlockCopy(blob, num2, parameters.Q, 0, 20); Array.Reverse((Array)parameters.Q); num2 += 20; parameters.G = new byte[num]; Buffer.BlockCopy(blob, num2, parameters.G, 0, num); Array.Reverse((Array)parameters.G); num2 += num; parameters.X = new byte[20]; Buffer.BlockCopy(blob, num2, parameters.X, 0, 20); Array.Reverse((Array)parameters.X); num2 += 20; parameters.Counter = ToInt32LE(blob, num2); num2 += 4; parameters.Seed = new byte[20]; Buffer.BlockCopy(blob, num2, parameters.Seed, 0, 20); Array.Reverse((Array)parameters.Seed); num2 += 20; } catch (Exception inner) { throw new CryptographicException("Invalid blob.", inner); } DSA dSA = null; try { dSA = DSA.Create(); dSA.ImportParameters(parameters); } catch (CryptographicException ex) { try { dSA = new DSACryptoServiceProvider(new CspParameters { Flags = CspProviderFlags.UseMachineKeyStore }); dSA.ImportParameters(parameters); } catch { throw ex; } } return dSA; } public static byte[] ToCapiPrivateKeyBlob(RSA rsa) { RSAParameters rSAParameters = rsa.ExportParameters(includePrivateParameters: true); int num = rSAParameters.Modulus.Length; byte[] array = new byte[20 + (num << 2) + (num >> 1)]; array[0] = 7; array[1] = 2; array[5] = 36; array[8] = 82; array[9] = 83; array[10] = 65; array[11] = 50; byte[] bytesLE = GetBytesLE(num << 3); array[12] = bytesLE[0]; array[13] = bytesLE[1]; array[14] = bytesLE[2]; array[15] = bytesLE[3]; int num2 = 16; int num3 = rSAParameters.Exponent.Length; while (num3 > 0) { array[num2++] = rSAParameters.Exponent[--num3]; } num2 = 20; byte[]? modulus = rSAParameters.Modulus; int num4 = modulus.Length; Array.Reverse((Array)modulus, 0, num4); Buffer.BlockCopy(modulus, 0, array, num2, num4); num2 += num4; byte[]? p = rSAParameters.P; num4 = p.Length; Array.Reverse((Array)p, 0, num4); Buffer.BlockCopy(p, 0, array, num2, num4); num2 += num4; byte[]? q = rSAParameters.Q; num4 = q.Length; Array.Reverse((Array)q, 0, num4); Buffer.BlockCopy(q, 0, array, num2, num4); num2 += num4; byte[]? dP = rSAParameters.DP; num4 = dP.Length; Array.Reverse((Array)dP, 0, num4); Buffer.BlockCopy(dP, 0, array, num2, num4); num2 += num4; byte[]? dQ = rSAParameters.DQ; num4 = dQ.Length; Array.Reverse((Array)dQ, 0, num4); Buffer.BlockCopy(dQ, 0, array, num2, num4); num2 += num4; byte[]? inverseQ = rSAParameters.InverseQ; num4 = inverseQ.Length; Array.Reverse((Array)inverseQ, 0, num4); Buffer.BlockCopy(inverseQ, 0, array, num2, num4); num2 += num4; byte[]? d = rSAParameters.D; num4 = d.Length; Array.Reverse((Array)d, 0, num4); Buffer.BlockCopy(d, 0, array, num2, num4); return array; } public static byte[] ToCapiPrivateKeyBlob(DSA dsa) { DSAParameters dSAParameters = dsa.ExportParameters(includePrivateParameters: true); int num = dSAParameters.P.Length; byte[] array = new byte[16 + num + 20 + num + 20 + 4 + 20]; array[0] = 7; array[1] = 2; array[5] = 34; array[8] = 68; array[9] = 83; array[10] = 83; array[11] = 50; byte[] bytesLE = GetBytesLE(num << 3); array[12] = bytesLE[0]; array[13] = bytesLE[1]; array[14] = bytesLE[2]; array[15] = bytesLE[3]; int num2 = 16; byte[]? p = dSAParameters.P; Array.Reverse((Array)p); Buffer.BlockCopy(p, 0, array, num2, num); num2 += num; byte[]? q = dSAParameters.Q; Array.Reverse((Array)q); Buffer.BlockCopy(q, 0, array, num2, 20); num2 += 20; byte[]? g = dSAParameters.G; Array.Reverse((Array)g); Buffer.BlockCopy(g, 0, array, num2, num); num2 += num; byte[]? x = dSAParameters.X; Array.Reverse((Array)x); Buffer.BlockCopy(x, 0, array, num2, 20); num2 += 20; Buffer.BlockCopy(GetBytesLE(dSAParameters.Counter), 0, array, num2, 4); num2 += 4; byte[]? seed = dSAParameters.Seed; Array.Reverse((Array)seed); Buffer.BlockCopy(seed, 0, array, num2, 20); return array; } public static RSA FromCapiPublicKeyBlob(byte[] blob) { return FromCapiPublicKeyBlob(blob, 0); } public static RSA FromCapiPublicKeyBlob(byte[] blob, int offset) { RSAParameters parametersFromCapiPublicKeyBlob = GetParametersFromCapiPublicKeyBlob(blob, offset); try { RSA rSA = null; try { rSA = RSA.Create(); rSA.ImportParameters(parametersFromCapiPublicKeyBlob); } catch (CryptographicException) { rSA = new RSACryptoServiceProvider(new CspParameters { Flags = CspProviderFlags.UseMachineKeyStore }); rSA.ImportParameters(parametersFromCapiPublicKeyBlob); } return rSA; } catch (Exception inner) { throw new CryptographicException("Invalid blob.", inner); } } private static RSAParameters GetParametersFromCapiPublicKeyBlob(byte[] blob, int offset) { if (blob == null) { throw new ArgumentNullException("blob"); } if (offset >= blob.Length) { throw new ArgumentException("blob is too small."); } try { if (blob[offset] != 6 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || ToUInt32LE(blob, offset + 8) != 826364754) { throw new CryptographicException("Invalid blob header"); } int num = ToInt32LE(blob, offset + 12); RSAParameters result = new RSAParameters { Exponent = new byte[3] }; result.Exponent[0] = blob[offset + 18]; result.Exponent[1] = blob[offset + 17]; result.Exponent[2] = blob[offset + 16]; int srcOffset = offset + 20; int num2 = num >> 3; result.Modulus = new byte[num2]; Buffer.BlockCopy(blob, srcOffset, result.Modulus, 0, num2); Array.Reverse((Array)result.Modulus); return result; } catch (Exception inner) { throw new CryptographicException("Invalid blob.", inner); } } public static DSA FromCapiPublicKeyBlobDSA(byte[] blob) { return FromCapiPublicKeyBlobDSA(blob, 0); } public static DSA FromCapiPublicKeyBlobDSA(byte[] blob, int offset) { if (blob == null) { throw new ArgumentNullException("blob"); } if (offset >= blob.Length) { throw new ArgumentException("blob is too small."); } try { if (blob[offset] != 6 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || ToUInt32LE(blob, offset + 8) != 827544388) { throw new CryptographicException("Invalid blob header"); } int num = ToInt32LE(blob, offset + 12); DSAParameters parameters = default(DSAParameters); int num2 = num >> 3; int num3 = offset + 16; parameters.P = new byte[num2]; Buffer.BlockCopy(blob, num3, parameters.P, 0, num2); Array.Reverse((Array)parameters.P); num3 += num2; parameters.Q = new byte[20]; Buffer.BlockCopy(blob, num3, parameters.Q, 0, 20); Array.Reverse((Array)parameters.Q); num3 += 20; parameters.G = new byte[num2]; Buffer.BlockCopy(blob, num3, parameters.G, 0, num2); Array.Reverse((Array)parameters.G); num3 += num2; parameters.Y = new byte[num2]; Buffer.BlockCopy(blob, num3, parameters.Y, 0, num2); Array.Reverse((Array)parameters.Y); num3 += num2; parameters.Counter = ToInt32LE(blob, num3); num3 += 4; parameters.Seed = new byte[20]; Buffer.BlockCopy(blob, num3, parameters.Seed, 0, 20); Array.Reverse((Array)parameters.Seed); num3 += 20; DSA dSA = DSA.Create(); dSA.ImportParameters(parameters); return dSA; } catch (Exception inner) { throw new CryptographicException("Invalid blob.", inner); } } public static byte[] ToCapiPublicKeyBlob(RSA rsa) { RSAParameters rSAParameters = rsa.ExportParameters(includePrivateParameters: false); int num = rSAParameters.Modulus.Length; byte[] array = new byte[20 + num]; array[0] = 6; array[1] = 2; array[5] = 36; array[8] = 82; array[9] = 83; array[10] = 65; array[11] = 49; byte[] bytesLE = GetBytesLE(num << 3); array[12] = bytesLE[0]; array[13] = bytesLE[1]; array[14] = bytesLE[2]; array[15] = bytesLE[3]; int num2 = 16; int num3 = rSAParameters.Exponent.Length; while (num3 > 0) { array[num2++] = rSAParameters.Exponent[--num3]; } num2 = 20; byte[]? modulus = rSAParameters.Modulus; int num4 = modulus.Length; Array.Reverse((Array)modulus, 0, num4); Buffer.BlockCopy(modulus, 0, array, num2, num4); num2 += num4; return array; } public static byte[] ToCapiPublicKeyBlob(DSA dsa) { DSAParameters dSAParameters = dsa.ExportParameters(includePrivateParameters: false); int num = dSAParameters.P.Length; byte[] array = new byte[16 + num + 20 + num + num + 4 + 20]; array[0] = 6; array[1] = 2; array[5] = 34; array[8] = 68; array[9] = 83; array[10] = 83; array[11] = 49; byte[] bytesLE = GetBytesLE(num << 3); array[12] = bytesLE[0]; array[13] = bytesLE[1]; array[14] = bytesLE[2]; array[15] = bytesLE[3]; int num2 = 16; byte[]? p = dSAParameters.P; Array.Reverse((Array)p); Buffer.BlockCopy(p, 0, array, num2, num);
plugins/RuntimeUnityEditor.Bepin5.dll
Decompiled a month agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using RuntimeUnityEditor.Bepin5.LogViewer; using RuntimeUnityEditor.Core; using RuntimeUnityEditor.Core.Inspector; using RuntimeUnityEditor.Core.Inspector.Entries; using RuntimeUnityEditor.Core.Utils; using RuntimeUnityEditor.Core.Utils.Abstractions; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyCompany("https://github.com/ManlyMarco/RuntimeUnityEditor")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright GPL-3 © 2018")] [assembly: AssemblyFileVersion("6.0.0.0")] [assembly: AssemblyInformationalVersion("6.0+1cb4bc68ece99c0d0b7bdf9149831f8a59ca0dcb")] [assembly: AssemblyProduct("RuntimeUnityEditor")] [assembly: AssemblyTitle("In-game inspector and debugging tools for applications made with Unity3D game engine")] [assembly: AssemblyVersion("6.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } } namespace RuntimeUnityEditor.Bepin5 { [Obsolete("It's recommended to reference RuntimeUnityEditorCore directly")] [BepInPlugin("RuntimeUnityEditor", "Runtime Unity Editor", "6.0")] public class RuntimeUnityEditor5 : BaseUnityPlugin { private sealed class Bep5InitSettings : InitSettings { private readonly RuntimeUnityEditor5 _instance; public override MonoBehaviour PluginMonoBehaviour => (MonoBehaviour)(object)_instance; public override ILoggerWrapper LoggerWrapper { get; } public override string ConfigPath => Paths.ConfigPath; public Bep5InitSettings(RuntimeUnityEditor5 instance) { _instance = instance; LoggerWrapper = (ILoggerWrapper)(object)new Logger5(((BaseUnityPlugin)_instance).Logger); } protected override Action<T> RegisterSetting<T>(string category, string name, T defaultValue, string description, Action<T> onValueUpdated) { ConfigEntry<T> s = ((BaseUnityPlugin)_instance).Config.Bind<T>(category, name, defaultValue, description); s.SettingChanged += delegate { onValueUpdated(s.Value); }; onValueUpdated(s.Value); return delegate(T x) { s.Value = x; }; } } private sealed class Logger5 : ILoggerWrapper { private readonly ManualLogSource _logger; public Logger5(ManualLogSource logger) { _logger = logger; } public void Log(LogLevel logLevel, object content) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) _logger.Log((LogLevel)logLevel, content); } } private static RuntimeUnityEditorCore Instance { get; set; } private void Start() { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown if (!TomlTypeConverter.CanConvert(typeof(Rect))) { TypeConverter converter = TomlTypeConverter.GetConverter(typeof(Rect)); TomlTypeConverter.AddConverter(typeof(Rect), new TypeConverter { ConvertToObject = converter.ConvertToObject, ConvertToString = converter.ConvertToString }); } Instance = new RuntimeUnityEditorCore((InitSettings)(object)new Bep5InitSettings(this)); Instance.AddFeature((IFeature)(object)new LogViewerWindow()); } private void Update() { Instance.Update(); } private void LateUpdate() { Instance.LateUpdate(); } private void OnGUI() { Instance.OnGUI(); } } internal static class Constants { public const string Version = "6.0"; public const string Name = "RuntimeUnityEditor"; public const string Description = "In-game inspector and debugging tools for applications made with Unity3D game engine"; public const string Website = "https://github.com/ManlyMarco/RuntimeUnityEditor"; public const string Copyright = "Copyright GPL-3 © 2018"; } } namespace RuntimeUnityEditor.Bepin5.LogViewer { internal readonly struct LogViewerEntry { private readonly GUIContent _timeString; private readonly GUIContent _logLevelString; private readonly GUIContent _sourceNameString; private readonly GUIContent _dataString; private const int SkippedStackFrames = 4; private static bool _stacktraceTostringFallback; public MethodBase Method { get; } public LogEventArgs LogEventArgs { get; } public StackFrame[] FilteredStackTrace { get; } public string FilteredStackTraceString { get; } public object Sender { get; } private LogViewerEntry(object sender, LogEventArgs logEventArgs, StackFrame[] filteredStackTrace, string filteredStackTraceString) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown Sender = sender; LogEventArgs = logEventArgs; FilteredStackTrace = filteredStackTrace; FilteredStackTraceString = filteredStackTraceString; Method = ((filteredStackTrace != null && filteredStackTrace.Length != 0) ? filteredStackTrace[0].GetMethod() : null); string text = "Filtered stack trace of this log write:\n\n" + filteredStackTraceString; _timeString = new GUIContent(DateTime.UtcNow.ToShortTimeString(), text); LogLevel level = logEventArgs.Level; _logLevelString = new GUIContent(((object)(LogLevel)(ref level)).ToString(), text); _sourceNameString = new GUIContent(logEventArgs.Source.SourceName, text); _dataString = new GUIContent(logEventArgs.Data?.ToString() ?? "NULL", text); } public string GetClipboardString() { object[] obj = new object[7] { _timeString, _logLevelString, _sourceNameString, _dataString, FilteredStackTraceString, Sender, null }; object sender = Sender; obj[6] = ((sender != null) ? TypeNameExtensions.GetSourceCodeRepresentation(sender.GetType()) : null) ?? "NULL"; return string.Format("{0} {1} {2} {3}\n{4}\nSender: {5} ({6})", obj); } public bool DrawEntry() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) GUI.color = GetColor(); bool flag = GUILayout.Button(_timeString, GUI.skin.label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(35f) }); GUILayout.Label("[", IMGUIUtils.LayoutOptionsExpandWidthFalse); flag |= GUILayout.Button(_logLevelString, GUI.skin.label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(45f) }); GUILayout.Label(":", IMGUIUtils.LayoutOptionsExpandWidthFalse); flag |= GUILayout.Button(_sourceNameString, GUI.skin.label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(100f) }); GUILayout.Label("]", IMGUIUtils.LayoutOptionsExpandWidthFalse); GUI.color = Color.white; return flag | GUILayout.Button(_dataString, GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue); } public Color GetColor() { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Invalid comparison between Unknown and I4 //IL_002c: 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_0018: Invalid comparison between Unknown and I4 //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Invalid comparison between Unknown and I4 //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) LogLevel level = LogEventArgs.Level; if ((int)level <= 4) { if (level - 1 <= 1) { return Color.red; } if ((int)level == 4) { return Color.yellow; } } else if ((int)level != 8 && (int)level != 16 && (int)level == 32) { return Color.gray; } return Color.white; } public bool IsMatch(string searchString, LogLevel logLevelFilter) { //IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references) if ((logLevelFilter & LogEventArgs.Level) != 0) { if (!string.IsNullOrEmpty(searchString) && !Extensions.Contains(_dataString.text, searchString, StringComparison.OrdinalIgnoreCase) && !Extensions.Contains(FilteredStackTraceString, searchString, StringComparison.OrdinalIgnoreCase)) { return Extensions.Contains(LogEventArgs.Source.SourceName, searchString, StringComparison.OrdinalIgnoreCase); } return true; } return false; } public static LogViewerEntry CreateFromLogEventArgs(object sender, LogEventArgs eventArgs) { StackTrace stackTrace = new StackTrace(4); StackFrame[] filteredFrames = null; string filteredStackTraceString; while (true) { if (!_stacktraceTostringFallback) { try { filteredStackTraceString = ParseStackTrace(stackTrace, out filteredFrames); } catch (Exception ex) { RuntimeUnityEditorCore.Logger.Log((LogLevel)2, (object)("[LogViewerWindow] Crash when trying to parse stack trace, falling back to using ToString\n" + ex)); _stacktraceTostringFallback = true; continue; } } else { filteredStackTraceString = ParseStackTraceString(stackTrace); try { filteredFrames = stackTrace.GetFrames(); } catch (Exception value) { Console.WriteLine(value); } } break; } return new LogViewerEntry(sender, eventArgs, filteredFrames, filteredStackTraceString); } private static string ParseStackTrace(StackTrace st, out StackFrame[] filteredFrames) { filteredFrames = null; StackFrame[] frames = st.GetFrames(); if (frames == null || frames.Length == 0) { return ParseStackTraceString(st); } StringBuilder stringBuilder = new StringBuilder(); bool flag = false; int count = 0; for (int i = 0; i < frames.Length; i++) { StackFrame stackFrame = frames[i]; MethodBase method = stackFrame.GetMethod(); string name = method.Name; Type? obj = method.DeclaringType ?? method.ReflectedType; string text = (((object)obj != null) ? TypeNameExtensions.GetSourceCodeRepresentation(obj) : null) ?? "???"; bool flag2 = false; if (!flag) { if (text.StartsWith("BepInEx.", StringComparison.Ordinal) || text.StartsWith("System.", StringComparison.Ordinal) || (text.StartsWith("UnityEngine.", StringComparison.Ordinal) && Extensions.Contains(name, "Log", StringComparison.Ordinal)) || (text.StartsWith("RuntimeUnityEditor", StringComparison.Ordinal) && name.Equals("Log", StringComparison.Ordinal))) { continue; } flag = true; flag2 = true; } if (flag2) { count = i; } stringBuilder.AppendFormat("[{0}] ", i + 4); stringBuilder.Append(text); stringBuilder.Append('.'); stringBuilder.Append(name); stringBuilder.AppendLine(); } filteredFrames = frames.Skip(count).ToArray(); if (stringBuilder.Length == 0) { stringBuilder.Append("\u00af\\_(ツ)_/\u00af"); } return stringBuilder.ToString(); } private static string ParseStackTraceString(StackTrace st) { string[] array = st.ToString().Split(new char[2] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); int num = Array.FindIndex(array, (string part) => !part.Contains("at BepInEx.") && !part.Contains("at System.")); if (num >= 0) { string[] array2 = new string[array.Length - num]; Array.Copy(array, num, array2, 0, array.Length - num); return "Origin: " + string.Join("\n", array2); } return string.Empty; } } internal sealed class LogViewerListener : ILogListener, IDisposable { private readonly LogViewerWindow _owner; public LogViewerListener(LogViewerWindow owner) { _owner = owner; } public void Dispose() { } public void LogEvent(object sender, LogEventArgs eventArgs) { //IL_0006: 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) //IL_0011: Unknown result type (might be due to invalid IL or missing references) if ((_owner.LogLevelFilter & eventArgs.Level) == 0) { return; } try { _owner.OnLogEvent(sender, eventArgs); } catch (Exception ex) { RuntimeUnityEditorCore.Logger.Log((LogLevel)2, (object)("[LogViewerWindow] Unexpected crash when trying to parse stack trace, disabling log capture!" + ex)); _owner.Capture = false; } } } public sealed class LogViewerWindow : Window<LogViewerWindow> { private Setting<bool> _captureOnStartup; private bool _capture; private LogViewerListener _listener; private Setting<LogLevel> _logLevelFilter; private string _searchString; private readonly List<LogViewerEntry> _logEntries = new List<LogViewerEntry>(); private readonly List<LogViewerEntry> _filteredLogEntries = new List<LogViewerEntry>(); private Vector2 _scrollPosition; private int _itemHeight; public bool CaptureOnStartup { get { return _captureOnStartup.Value; } set { _captureOnStartup.Value = value; } } public bool Capture { get { return _capture; } set { if (_capture != value) { _capture = value; if (_capture) { Logger.Listeners.Add((ILogListener)(object)_listener); } else { Logger.Listeners.Remove((ILogListener)(object)_listener); } } } } public LogLevel LogLevelFilter { get { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return _logLevelFilter.Value; } set { //IL_0006: Unknown result type (might be due to invalid IL or missing references) _logLevelFilter.Value = value; } } public string SearchString { get { return _searchString; } set { if (_searchString != value) { _searchString = value; UpdateFilteredLogEntries(); } } } private void UpdateFilteredLogEntries() { _filteredLogEntries.Clear(); _filteredLogEntries.AddRange(_logEntries.Where((LogViewerEntry entry) => entry.IsMatch(SearchString, LogLevelFilter))); } protected override void Initialize(InitSettings initSettings) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) ((FeatureBase<LogViewerWindow>)(object)this).Enabled = false; base.DefaultScreenPosition = (ScreenPartition)12; ((FeatureBase<LogViewerWindow>)(object)this).DisplayName = "Logger"; ((Window<LogViewerWindow>)this).Title = "BepInEx Log Viewer"; base.MinimumSize = new Vector2(640f, 200f); _listener = new LogViewerListener(this); _captureOnStartup = initSettings.RegisterSetting<bool>("Log Viewer", "Enable capture on startup", false, "Start capturing log messages as soon as possible after game starts."); if (_captureOnStartup.Value) { Capture = true; } _logLevelFilter = initSettings.RegisterSetting<LogLevel>("Log Viewer", "Log level filter", (LogLevel)63, "Filter captured log messages by their log level."); _logLevelFilter.ValueChanged += delegate { UpdateFilteredLogEntries(); }; ToStringConverter.AddConverter<ILogSource>((Func<ILogSource, string>)((ILogSource obj) => obj.SourceName + " (" + GetTrimmedTypeName(obj) + ")")); static string GetTrimmedTypeName(ILogSource obj) { string text = ((obj != null) ? TypeNameExtensions.GetSourceCodeRepresentation(((object)obj).GetType()) : null) ?? "NULL"; if (text.StartsWith("BepInEx.Logging.", StringComparison.Ordinal)) { text = text.Substring("BepInEx.Logging.".Length); } return text; } } protected override void DrawContents() { //IL_044a: Unknown result type (might be due to invalid IL or missing references) //IL_0454: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0461: Unknown result type (might be due to invalid IL or missing references) //IL_0467: Invalid comparison between Unknown and I4 //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Expected O, but got Unknown //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_046e: Unknown result type (might be due to invalid IL or missing references) //IL_04c6: Unknown result type (might be due to invalid IL or missing references) //IL_04cb: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: 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_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Invalid comparison between Unknown and I4 //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Expected O, but got Unknown //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: 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_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Expected O, but got Unknown //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue); GUI.changed = false; string searchString = SearchString; bool flag = string.IsNullOrEmpty(searchString) && GUI.GetNameOfFocusedControl() != "sbox"; if (flag) { GUI.color = Color.gray; } GUI.SetNextControlName("sbox"); string searchString2 = GUILayout.TextField(flag ? "Search log text and stack traces..." : searchString, IMGUIUtils.LayoutOptionsExpandWidthTrue); if (GUI.changed) { SearchString = searchString2; } GUI.color = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthFalse); if (!Capture) { GUI.color = Color.red; } Capture = GUILayout.Toggle(Capture, new GUIContent("Enable log capture", "Note: This can hurt performance, especially if there is log spam."), (GUILayoutOption[])(object)new GUILayoutOption[0]); GUI.color = Color.white; CaptureOnStartup = GUILayout.Toggle(CaptureOnStartup, new GUIContent("Enable on game startup", "Warning: This can hurt performance, especially after running for a while!"), (GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUILayout.Button("Clear the list", (GUILayoutOption[])(object)new GUILayoutOption[0])) { _logEntries.Clear(); _filteredLogEntries.Clear(); } GUILayout.EndHorizontal(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.BeginHorizontal(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Label(new GUIContent("Captured log levels:", "Only new log messages with these levels will be captured, therefore enabling levels will not show past log messages!"), (GUILayoutOption[])(object)new GUILayoutOption[0]); LogLevel logLevelFilter = LogLevelFilter; LogLevel[] array = (LogLevel[])(object)new LogLevel[7] { (LogLevel)32, (LogLevel)16, (LogLevel)8, (LogLevel)4, (LogLevel)2, (LogLevel)1, (LogLevel)63 }; for (int i = 0; i < array.Length; i++) { LogLevel val = array[i]; GUI.changed = false; bool flag2 = GUILayout.Toggle((logLevelFilter & val) > 0, ((object)(LogLevel)(ref val)).ToString(), (GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUI.changed) { LogLevelFilter = (LogLevel)(flag2 ? (logLevelFilter | val) : (logLevelFilter & ~val)); } } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUILayout.Button("Sources", (GUILayoutOption[])(object)new GUILayoutOption[0])) { FeatureBase<Inspector>.Instance.Push((InspectorStackEntryBase)new InstanceStackEntry((object)Logger.Sources, "Log Sources"), true); } if (GUILayout.Button("Listeners", (GUILayoutOption[])(object)new GUILayoutOption[0])) { FeatureBase<Inspector>.Instance.Push((InspectorStackEntryBase)new InstanceStackEntry((object)Logger.Listeners, "Log Listeners"), true); } GUILayout.EndHorizontal(); GUILayout.EndHorizontal(); bool flag3 = _itemHeight != 0; _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true, (GUILayoutOption[])(object)new GUILayoutOption[0]); List<LogViewerEntry> filteredLogEntries = _filteredLogEntries; int num = (flag3 ? ((int)(_scrollPosition.y / (float)_itemHeight)) : 0); int num2; Rect val2; if (!flag3) { num2 = filteredLogEntries.Count; } else { val2 = ((Window<LogViewerWindow>)this).WindowRect; num2 = Mathf.Min((int)((Rect)(ref val2)).height / _itemHeight, filteredLogEntries.Count - num); } int num3 = num2; int num4 = filteredLogEntries.Count - num - num3 + 3; GUILayout.Space((float)(num * _itemHeight)); for (int j = num; j < num + num3; j++) { LogViewerEntry logViewerEntry = filteredLogEntries[filteredLogEntries.Count - 1 - j]; GUILayout.BeginHorizontal(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]); if (logViewerEntry.DrawEntry()) { if (IMGUIUtils.IsMouseRightClick() && FeatureBase<ContextMenu>.Initialized) { if (logViewerEntry.Sender != null) { FeatureBase<ContextMenu>.Instance.Show(logViewerEntry.Sender); } else { RuntimeUnityEditorCore.Logger.Log((LogLevel)4, (object)"[LogViewerWindow] Sender is null, cannot inspect"); } } else { try { UnityFeatureHelper.systemCopyBuffer = logViewerEntry.GetClipboardString(); RuntimeUnityEditorCore.Logger.Log((LogLevel)8, (object)"[LogViewerWindow] Copied to clipboard"); } catch (Exception ex) { RuntimeUnityEditorCore.Logger.Log((LogLevel)10, (object)("[LogViewerWindow] Failed to copy to clipboard: " + ex.Message)); } } } if (logViewerEntry.Sender != null && GUILayout.Button("Inspect", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { FeatureBase<Inspector>.Instance.Push((InspectorStackEntryBase)new InstanceStackEntry((object)logViewerEntry, logViewerEntry.LogEventArgs.Source.SourceName + " -> Log entry"), true); } DnSpyHelper.DrawDnSpyButtonIfAvailable((MemberInfo)logViewerEntry.Method, new GUIContent("^", "In dnSpy, attempt to navigate to the method that produced this log message:\n\n" + TypeNameExtensions.GetFancyDescription((MemberInfo)logViewerEntry.Method))); GUILayout.EndHorizontal(); if (!flag3 && (int)Event.current.type == 7) { val2 = GUILayoutUtility.GetLastRect(); int num5 = (int)((Rect)(ref val2)).height; if (_itemHeight == 0 || _itemHeight > num5) { _itemHeight = num5; } } } GUILayout.Space((float)(num4 * _itemHeight)); GUILayout.EndScrollView(); val2 = ((Window<LogViewerWindow>)this).WindowRect; base.TooltipWidth = Mathf.Min(777, Mathf.Max(300, (int)((Rect)(ref val2)).width - 100)); } internal void OnLogEvent(object sender, LogEventArgs eventArgs) { try { LogViewerEntry entry = LogViewerEntry.CreateFromLogEventArgs(sender, eventArgs); AddEntry(entry); } catch (Exception value) { Console.WriteLine(value); } } private void AddEntry(LogViewerEntry entry) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) _logEntries.Add(entry); if (entry.IsMatch(SearchString, LogLevelFilter)) { _filteredLogEntries.Add(entry); } } } }
plugins/RuntimeUnityEditor.Core.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Timers; using HarmonyLib; using Microsoft.CodeAnalysis; using Mono.CSharp; using RuntimeUnityEditor.Core.Breakpoints; using RuntimeUnityEditor.Core.ChangeHistory; using RuntimeUnityEditor.Core.Clipboard; using RuntimeUnityEditor.Core.Gizmos.lib; using RuntimeUnityEditor.Core.Gizmos.lib.Drawers; using RuntimeUnityEditor.Core.Inspector; using RuntimeUnityEditor.Core.Inspector.Entries; using RuntimeUnityEditor.Core.ObjectTree; using RuntimeUnityEditor.Core.ObjectView; using RuntimeUnityEditor.Core.REPL; using RuntimeUnityEditor.Core.REPL.MCS; using RuntimeUnityEditor.Core.UI; using RuntimeUnityEditor.Core.Utils; using RuntimeUnityEditor.Core.Utils.Abstractions; using RuntimeUnityEditor.Core.Utils.ObjectDumper; using UnityEngine; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("RuntimeUnityEditor.Bepin5")] [assembly: InternalsVisibleTo("RuntimeUnityEditor.Bepin6.IL2CPP")] [assembly: InternalsVisibleTo("RuntimeUnityEditor.UMM")] [assembly: AssemblyCompany("https://github.com/ManlyMarco/RuntimeUnityEditor")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright GPL-3 © 2018")] [assembly: AssemblyFileVersion("6.0.0.0")] [assembly: AssemblyInformationalVersion("6.0+1cb4bc68ece99c0d0b7bdf9149831f8a59ca0dcb")] [assembly: AssemblyProduct("RuntimeUnityEditor")] [assembly: AssemblyTitle("In-game inspector and debugging tools for applications made with Unity3D game engine")] [assembly: AssemblyVersion("6.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } } internal static class FailedToGetGenericArguments { } namespace RuntimeUnityEditor.Core { public interface IFeature { bool Enabled { get; set; } FeatureDisplayType DisplayType { get; } string DisplayName { get; } void OnInitialize(InitSettings initSettings); void OnUpdate(); void OnLateUpdate(); void OnOnGUI(); void OnEditorShownChanged(bool visible); } public enum FeatureDisplayType { Hidden, Feature, Window } public abstract class FeatureBase<T> : IFeature where T : FeatureBase<T> { private static bool _initialized; protected string SettingCategory = "Features"; private protected string _displayName; private InitSettings.Setting<bool> _enabled; private bool _initialEnabled = true; public static bool Initialized => _initialized; public static T Instance { get; private set; } public virtual string DisplayName { get { return _displayName ?? (_displayName = GetType().Name); } set { _displayName = value; } } public virtual bool Enabled { get { if (_enabled != null) { return _enabled.Value; } return _initialEnabled; } set { if (_enabled == null) { _initialEnabled = value; } else if (_enabled.Value != value) { bool visible = Visible; _enabled.Value = value; bool visible2 = Visible; if (visible != visible2) { OnVisibleChanged(visible2); } } } } public bool Visible { get { if (Enabled) { return RuntimeUnityEditorCore.Instance.Show; } return false; } } public FeatureDisplayType DisplayType { get; protected set; } protected FeatureBase() { DisplayType = FeatureDisplayType.Feature; Instance = (T)this; } void IFeature.OnInitialize(InitSettings initSettings) { if (Initialized) { throw new InvalidOperationException("The Feature is already initialized"); } Initialize(initSettings); AfterInitialized(initSettings); _initialized = true; } protected virtual void AfterInitialized(InitSettings initSettings) { _enabled = initSettings.RegisterSetting(SettingCategory, DisplayName + " enabled", _initialEnabled, string.Empty); } void IFeature.OnUpdate() { if (_initialized && Enabled) { try { Update(); } catch (Exception content) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, content); } } } void IFeature.OnLateUpdate() { if (_initialized && Enabled) { try { LateUpdate(); } catch (Exception content) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, content); } } } void IFeature.OnOnGUI() { if (_initialized && Enabled) { try { OnGUI(); } catch (Exception content) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, content); } } } void IFeature.OnEditorShownChanged(bool visible) { if (_initialized && Enabled) { OnVisibleChanged(visible); } } protected virtual void OnVisibleChanged(bool visible) { try { VisibleChanged(visible); } catch (Exception content) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, content); } } protected abstract void Initialize(InitSettings initSettings); protected virtual void Update() { } protected virtual void LateUpdate() { } protected virtual void OnGUI() { } protected virtual void VisibleChanged(bool visible) { } } public class ContextMenu : FeatureBase<ContextMenu> { public readonly struct MenuEntry { private readonly GUIContent _name; private readonly Func<object, bool> _onCheckVisible; private readonly Action<object> _onClick; public MenuEntry(string name, Func<object, bool> onCheckVisible, Action<object> onClick) : this(new GUIContent(name), onCheckVisible, onClick) { }//IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Expected O, but got Unknown public MenuEntry(GUIContent name, Func<object, bool> onCheckVisible, Action<object> onClick) { _name = name; _onCheckVisible = onCheckVisible; _onClick = onClick; } public bool IsVisible(object obj) { if (_onCheckVisible != null) { return _onCheckVisible(obj); } return true; } public bool Draw(object obj) { if (_onClick != null) { if (GUILayout.Button(_name, (GUILayoutOption[])(object)new GUILayoutOption[0])) { if (IMGUIUtils.IsMouseRightClick()) { return false; } _onClick(obj); return true; } } else if (_name != null) { GUILayout.Label(_name, (GUILayoutOption[])(object)new GUILayoutOption[0]); } else { GUILayout.Space(4f); } return false; } } private object _obj; private MemberInfo _objMemberInfo; private Func<object> _getValue; private Action<object> _setValue; private string _objName; private Rect _windowRect; private int _windowId; private List<MenuEntry> _currentContents; public override bool Enabled { get { if (base.Enabled) { if (_obj == null) { return (object)_objMemberInfo != null; } return true; } return false; } set { if (value && _obj == null && (object)_objMemberInfo == null) { value = false; } base.Enabled = value; } } public List<MenuEntry> MenuContents { get; } = new List<MenuEntry>(); protected override void Initialize(InitSettings initSettings) { MenuContents.AddRange(new MenuEntry[8] { new MenuEntry("! Destroyed unity Object !", delegate(object obj) { Object val23 = (Object)((obj is Object) ? obj : null); return val23 != null && !Object.op_Implicit(val23); }, null), new MenuEntry("Preview", (object o) => o != null && FeatureBase<ObjectViewWindow>.Initialized && FeatureBase<ObjectViewWindow>.Instance.CanPreview(o), delegate(object o) { FeatureBase<ObjectViewWindow>.Instance.SetShownObject(o, _objName); }), new MenuEntry("Show event details", (object o) => o is UnityEventBase && FeatureBase<ObjectViewWindow>.Initialized, delegate(object o) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown FeatureBase<ObjectViewWindow>.Instance.SetShownObject(ReflectionUtils.GetEventDetails((UnityEventBase)o), o?.ToString() + " - Event details"); }), new MenuEntry("Find in object tree", (object o) => o is GameObject || o is Component, delegate(object o) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) ObjectTreeViewer instance = FeatureBase<ObjectTreeViewer>.Instance; object obj2 = ((o is GameObject) ? o : null); instance.SelectAndShowObject(((obj2 != null) ? ((GameObject)obj2).transform : null) ?? ((Component)o).transform); }), default(MenuEntry), new MenuEntry("Send to inspector", (object o) => o != null && FeatureBase<RuntimeUnityEditor.Core.Inspector.Inspector>.Initialized, delegate(object o) { if (o is Type staticType) { FeatureBase<RuntimeUnityEditor.Core.Inspector.Inspector>.Instance.Push(new StaticStackEntry(staticType, _objName), newTab: true); } else { FeatureBase<RuntimeUnityEditor.Core.Inspector.Inspector>.Instance.Push(new InstanceStackEntry(o, _objName), newTab: true); } }), new MenuEntry("Send to REPL", (object o) => o != null && FeatureBase<ReplWindow>.Initialized, delegate(object o) { FeatureBase<ReplWindow>.Instance.IngestObject(o); }), default(MenuEntry) }); AddBreakpointControls(MenuContents); MenuContents.AddRange(new MenuEntry[12] { new MenuEntry("Copy to clipboard", (object o) => o != null && FeatureBase<ClipboardWindow>.Initialized, delegate(object o) { if (ClipboardWindow.Contents.LastOrDefault() != o) { ClipboardWindow.Contents.Add(o); } }), new MenuEntry("Export texture...", delegate(object o) { if (!(o is Texture) && !(o is Sprite)) { Material val19 = (Material)((o is Material) ? o : null); if (val19 == null || !((Object)(object)val19.mainTexture != (Object)null)) { Image val20 = (Image)((o is Image) ? o : null); if (val20 == null || !((Object)(object)((Graphic)val20).mainTexture != (Object)null)) { RawImage val21 = (RawImage)((o is RawImage) ? o : null); if (val21 == null || !((Object)(object)((Graphic)val21).mainTexture != (Object)null)) { Renderer val22 = (Renderer)((o is Renderer) ? o : null); if (val22 != null && (Object)(object)(val22.sharedMaterial ?? val22.material) != (Object)null) { return (Object)(object)(val22.sharedMaterial ?? val22.material).mainTexture != (Object)null; } return false; } } } } return true; }, delegate(object o) { Texture val13 = (Texture)((o is Texture) ? o : null); if (val13 != null) { val13.SaveTextureToFileWithDialog(); } else { Sprite val14 = (Sprite)((o is Sprite) ? o : null); if (val14 != null) { ((Texture)(object)val14.texture).SaveTextureToFileWithDialog(); } else { Material val15 = (Material)((o is Material) ? o : null); if (val15 != null) { val15.mainTexture.SaveTextureToFileWithDialog(); } else { Image val16 = (Image)((o is Image) ? o : null); if (val16 != null) { ((Graphic)val16).mainTexture.SaveTextureToFileWithDialog(); } else { RawImage val17 = (RawImage)((o is RawImage) ? o : null); if (val17 != null) { ((Graphic)val17).mainTexture.SaveTextureToFileWithDialog(); } else { Renderer val18 = (Renderer)((o is Renderer) ? o : null); if (val18 != null) { (val18.sharedMaterial ?? val18.material).mainTexture.SaveTextureToFileWithDialog(); } } } } } } }), new MenuEntry("Replace texture...", delegate(object o) { if (!(o is Texture2D) && (!(o is Texture) || _setValue == null) && !(o is Material) && !(o is RawImage)) { Renderer val12 = (Renderer)((o is Renderer) ? o : null); if (val12 != null) { if (!((Object)(object)val12.sharedMaterial != (Object)null)) { return (Object)(object)val12.material != (Object)null; } return true; } return false; } return true; }, delegate(object o) { string filename = "null"; Texture2D newTex = TextureUtils.LoadTextureFromFileWithDialog(ref filename); Texture val6 = (Texture)((o is Texture) ? o : null); if (val6 != null) { try { if (_setValue != null) { object current = _getValue?.Invoke(); Change.Action("(ContextMenu)::" + _objName + " = Texture2D.LoadImage(File.ReadAllBytes(\"" + filename + "\"))", o, delegate { _setValue(newTex); }, (current != null) ? ((Action<object>)delegate { _setValue(current); }) : null); return; } throw new NotImplementedException(); } catch (Exception ex) { if (!(ex is NotImplementedException)) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, ex); } Texture2D val7 = (Texture2D)(object)((val6 is Texture2D) ? val6 : null); if (val7 != null) { try { ((Action<Texture2D, Texture2D>)delegate(Texture2D target, Texture2D source) { target.LoadRawTextureData(source.GetRawTextureData()); target.Apply(true); })(val7, newTex); Change.Report("(ContextMenu)::" + _objName + ".LoadImage(File.ReadAllBytes(\"" + filename + "\"))"); return; } catch (Exception content) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, content); return; } finally { Object.Destroy((Object)(object)newTex); } } return; } } Material val8 = (Material)((o is Material) ? o : null); if (val8 != null) { Change.WithUndo("(ContextMenu)::" + _objName + ".mainTexture = Texture2D.LoadImage(File.ReadAllBytes(\"" + filename + "\"))", val8, (Texture)(object)newTex, delegate(Material material, Texture texture2D) { material.mainTexture = texture2D; }, null, null, val8.mainTexture); } else { Image val9 = (Image)((o is Image) ? o : null); if (val9 != null && (Object)(object)((Graphic)val9).material != (Object)null) { Change.WithUndo("(ContextMenu)::" + _objName + ".material.mainTexture = Texture2D.LoadImage(File.ReadAllBytes(\"" + filename + "\"))", ((Graphic)val9).material, (Texture)(object)newTex, delegate(Material material, Texture texture2D) { material.mainTexture = texture2D; }, null, null, ((Graphic)val9).material.mainTexture); } else { RawImage val10 = (RawImage)((o is RawImage) ? o : null); if (val10 != null) { Change.WithUndo("(ContextMenu)::" + _objName + ".texture = Texture2D.LoadImage(File.ReadAllBytes(\"" + filename + "\"))", val10, (Texture)(object)newTex, delegate(RawImage rawImage, Texture texture2D) { rawImage.texture = texture2D; }, null, null, val10.texture); } else { Renderer val11 = (Renderer)((o is Renderer) ? o : null); if (val11 != null) { if ((Object)(object)val11.sharedMaterial != (Object)null) { Change.WithUndo("(ContextMenu)::" + _objName + ".sharedMaterial.mainTexture = Texture2D.LoadImage(File.ReadAllBytes(\"" + filename + "\"))", val11.sharedMaterial, (Texture)(object)newTex, delegate(Material material, Texture texture2D) { material.mainTexture = texture2D; }, null, null, val11.sharedMaterial.mainTexture); } else { Change.WithUndo("(ContextMenu)::" + _objName + ".material.mainTexture = Texture2D.LoadImage(File.ReadAllBytes(\"" + filename + "\"))", val11.material, (Texture)(object)newTex, delegate(Material material, Texture texture2D) { material.mainTexture = texture2D; }, null, null, val11.material.mainTexture); } } } } } }), new MenuEntry("Export mesh to .obj", delegate(object o) { Renderer val5 = (Renderer)((o is Renderer) ? o : null); return val5 != null && MeshExport.CanExport(val5); }, delegate(object o) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown MeshExport.ExportObj((Renderer)o, bakedMesh: false, bakedWorldPosition: false); }), new MenuEntry("Export mesh to .obj (Baked)", delegate(object o) { Renderer val4 = (Renderer)((o is Renderer) ? o : null); return val4 != null && MeshExport.CanExport(val4); }, delegate(object o) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown MeshExport.ExportObj((Renderer)o, bakedMesh: true, bakedWorldPosition: false); }), new MenuEntry("Export mesh to .obj (World)", delegate(object o) { Renderer val3 = (Renderer)((o is Renderer) ? o : null); return val3 != null && MeshExport.CanExport(val3); }, delegate(object o) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown MeshExport.ExportObj((Renderer)o, bakedMesh: true, bakedWorldPosition: true); }), new MenuEntry("Dump object to file...", (object o) => o != null, delegate(object o) { Dumper.DumpToTempFile(o, _objName); }), new MenuEntry("Destroy", delegate(object o) { Object val2 = (Object)((o is Object) ? o : null); return val2 != null && Object.op_Implicit(val2); }, delegate(object o) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Transform val = (Transform)((o is Transform) ? o : null); Change.Action("(ContextMenu)::UnityEngine.Object.Destroy({0})", (Object)((val != null) ? ((object)((Component)val).gameObject) : ((object)(Object)o)), (Action<Object>)Object.Destroy, (Action<Object>)null); }), default(MenuEntry), new MenuEntry("Find references in scene", (object o) => o != null && FeatureBase<ObjectViewWindow>.Initialized && o.GetType().IsClass, delegate(object o) { FeatureBase<ObjectTreeViewer>.Instance.FindReferencesInScene(o); }), new MenuEntry("Find member in dnSpy", (object o) => DnSpyHelper.IsAvailable && (object)_objMemberInfo != null, delegate { DnSpyHelper.OpenInDnSpy(_objMemberInfo); }), new MenuEntry("Find member type in dnSpy", (object o) => o != null && DnSpyHelper.IsAvailable, delegate(object o) { DnSpyHelper.OpenInDnSpy(o.GetType()); }) }); _windowId = base.GetHashCode(); Enabled = false; base.DisplayType = FeatureDisplayType.Hidden; } private void AddBreakpointControls(List<MenuEntry> menuContents) { menuContents.AddRange(AddGroup("call", (object o, MemberInfo info) => info as MethodBase)); menuContents.AddRange(AddGroup("getter", (object o, MemberInfo info) => (!(info is PropertyInfo propertyInfo2)) ? null : propertyInfo2.GetGetMethod(nonPublic: true))); menuContents.AddRange(AddGroup("setter", (object o, MemberInfo info) => (!(info is PropertyInfo propertyInfo)) ? null : propertyInfo.GetSetMethod(nonPublic: true))); menuContents.Add(default(MenuEntry)); IEnumerable<MenuEntry> AddGroup(string name, Func<object, MemberInfo, MethodBase> getMethod) { yield return new MenuEntry("Attach " + name + " breakpoint (this instance)", delegate(object o) { if (o == null) { return false; } MethodBase methodBase4 = getMethod(o, _objMemberInfo); return (object)methodBase4 != null && !RuntimeUnityEditor.Core.Breakpoints.Breakpoints.IsAttached(methodBase4, o); }, delegate(object o) { RuntimeUnityEditor.Core.Breakpoints.Breakpoints.AttachBreakpoint(getMethod(o, _objMemberInfo), o); }); yield return new MenuEntry("Detach " + name + " breakpoint (this instance)", delegate(object o) { if (o == null) { return false; } MethodBase methodBase3 = getMethod(o, _objMemberInfo); return (object)methodBase3 != null && RuntimeUnityEditor.Core.Breakpoints.Breakpoints.IsAttached(methodBase3, o); }, delegate(object o) { RuntimeUnityEditor.Core.Breakpoints.Breakpoints.DetachBreakpoint(getMethod(o, _objMemberInfo), o); }); yield return new MenuEntry("Attach " + name + " breakpoint (all instances)", delegate(object o) { MethodBase methodBase2 = getMethod(o, _objMemberInfo); return (object)methodBase2 != null && !RuntimeUnityEditor.Core.Breakpoints.Breakpoints.IsAttached(methodBase2, null); }, delegate(object o) { RuntimeUnityEditor.Core.Breakpoints.Breakpoints.AttachBreakpoint(getMethod(o, _objMemberInfo), null); }); yield return new MenuEntry("Detach " + name + " breakpoint (all instances)", delegate(object o) { MethodBase methodBase = getMethod(o, _objMemberInfo); return (object)methodBase != null && RuntimeUnityEditor.Core.Breakpoints.Breakpoints.IsAttached(methodBase, null); }, delegate(object o) { RuntimeUnityEditor.Core.Breakpoints.Breakpoints.DetachBreakpoint(getMethod(o, _objMemberInfo), null); }); } } public void Show(object obj, ICacheEntry objEntry) { if (objEntry == null) { throw new ArgumentNullException("objEntry"); } if (obj == null && objEntry.CanEnterValue()) { obj = objEntry.GetValue(); } string memberFullName = ((objEntry is FieldCacheEntry fieldCacheEntry) ? (fieldCacheEntry.FieldInfo.DeclaringType?.Name + "." + fieldCacheEntry.FieldInfo.Name) : ((objEntry is PropertyCacheEntry propertyCacheEntry) ? (propertyCacheEntry.PropertyInfo.DeclaringType?.Name + "." + propertyCacheEntry.PropertyInfo.Name) : ((objEntry != null) ? objEntry.Name() : GeneralExtensions.FullDescription(obj.GetType())))); bool flag = objEntry.CanSetValue(); Show(obj, objEntry.MemberInfo, memberFullName, flag ? new Action<object>(objEntry.SetValue) : null, flag ? new Func<object>(objEntry.GetValue) : null); } public void Show(object obj) { Show(obj, null, (obj != null) ? GeneralExtensions.FullDescription(obj.GetType()) : null, null, null); } public void Show(object obj, MemberInfo memberInfo, string memberFullName, Action<object> setObj, Func<object> getObj) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) Vector3 mousePosition = UnityInput.Current.mousePosition; Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(mousePosition.x, (float)Screen.height - mousePosition.y); _windowRect = new Rect(val.x, val.y, 100f, 100f); if (obj == null && getObj != null) { obj = getObj(); } if (obj != null || (object)memberInfo != null) { _obj = obj; _objMemberInfo = memberInfo ?? (obj as MemberInfo); _objName = memberFullName ?? (((object)_objMemberInfo != null) ? (_objMemberInfo.DeclaringType?.Name + "." + _objMemberInfo.Name) : ((obj != null) ? GeneralExtensions.FullDescription(obj.GetType()) : null)); _setValue = setObj; _getValue = getObj; _currentContents = MenuContents.Where((MenuEntry x) => x.IsVisible(_obj)).ToList(); _windowId++; Enabled = true; } else { _obj = null; Enabled = false; } } public void DrawContextButton(object obj, ICacheEntry objEntry) { if (obj != null && GUILayout.Button("...", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { Show(obj, objEntry); } } public void DrawContextButton(object obj, MemberInfo memberInfo, string memberFullName, Action<object> setObj, Func<object> getObj) { if (obj != null && GUILayout.Button("...", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { Show(obj, memberInfo, memberFullName, setObj, getObj); } } protected override void OnGUI() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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) int num = _windowId - 10; GUILayout.Window(num, new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), new WindowFunction(DisableOnClickWindowFunc), string.Empty, GUI.skin.label, (GUILayoutOption[])(object)new GUILayoutOption[0]); GUI.color = Color.white; IMGUIUtils.DrawSolidBox(_windowRect); _windowRect = GUILayout.Window(_windowId, _windowRect, new WindowFunction(DrawMenu), _objName, (GUILayoutOption[])(object)new GUILayoutOption[0]); IMGUIUtils.EatInputInRect(_windowRect); GUI.BringWindowToFront(num); GUI.BringWindowToFront(_windowId); if (((Rect)(ref _windowRect)).xMax > (float)Screen.width) { ((Rect)(ref _windowRect)).x = (float)Screen.width - ((Rect)(ref _windowRect)).width; } if (((Rect)(ref _windowRect)).yMax > (float)Screen.height) { ((Rect)(ref _windowRect)).y = (float)Screen.height - ((Rect)(ref _windowRect)).height; } } private void DisableOnClickWindowFunc(int id) { if (GUILayout.Button(GUIContent.none, GUI.skin.label, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true) })) { Enabled = false; } } private void DrawMenu(int id) { if (_currentContents == null || _currentContents.Count == 0) { Enabled = false; return; } GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[0]); foreach (MenuEntry currentContent in _currentContents) { if (currentContent.Draw(_obj)) { Enabled = false; } } GUILayout.EndVertical(); } } public sealed class CursorUnlocker : FeatureBase<CursorUnlocker> { private bool _obsoleteCursor; private PropertyInfo _curLockState; private PropertyInfo _curVisible; private int _previousCursorLockState; private bool _previousCursorVisible; protected override void Initialize(InitSettings initSettings) { Type typeFromHandle = typeof(Cursor); _curLockState = typeFromHandle.GetProperty("lockState", BindingFlags.Static | BindingFlags.Public); _curVisible = typeFromHandle.GetProperty("visible", BindingFlags.Static | BindingFlags.Public); if ((object)_curLockState == null || (object)_curVisible == null) { _obsoleteCursor = true; _curLockState = typeof(Screen).GetProperty("lockCursor", BindingFlags.Static | BindingFlags.Public); _curVisible = typeof(Screen).GetProperty("showCursor", BindingFlags.Static | BindingFlags.Public); if ((object)_curLockState == null || (object)_curVisible == null) { throw new InvalidOperationException("Unsupported Cursor class"); } } DisplayName = "Unlock cursor"; Enabled = true; base.DisplayType = FeatureDisplayType.Hidden; } protected override void Update() { if (_obsoleteCursor) { _curLockState.SetValue(null, false, null); } else { _curLockState.SetValue(null, 0, null); } _curVisible.SetValue(null, true, null); } protected override void LateUpdate() { if (_obsoleteCursor) { _curLockState.SetValue(null, false, null); } else { _curLockState.SetValue(null, 0, null); } _curVisible.SetValue(null, true, null); } protected override void OnGUI() { if (_obsoleteCursor) { _curLockState.SetValue(null, false, null); } else { _curLockState.SetValue(null, 0, null); } _curVisible.SetValue(null, true, null); } protected override void VisibleChanged(bool visible) { if (visible) { _previousCursorLockState = (_obsoleteCursor ? Convert.ToInt32((bool)_curLockState.GetValue(null, null)) : ((int)_curLockState.GetValue(null, null))); _previousCursorVisible = (bool)_curVisible.GetValue(null, null); } else if (!_previousCursorVisible || _previousCursorLockState != 0) { if (_obsoleteCursor) { _curLockState.SetValue(null, Convert.ToBoolean(_previousCursorLockState), null); } else { _curLockState.SetValue(null, _previousCursorLockState, null); } _curVisible.SetValue(null, _previousCursorVisible, null); } } } public class MouseInspect : FeatureBase<MouseInspect> { private static readonly StringBuilder _hoverTextSb = new StringBuilder(100); private static string _hoverText = string.Empty; private GUIStyle _labelSkin; protected override void Initialize(InitSettings initSettings) { DisplayName = "Mouse inspect"; } protected override void Update() { //IL_0059: 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_00e6: Unknown result type (might be due to invalid IL or missing references) Camera main = Camera.main; Transform val = DoRaycast(main); List<RectTransform> list = DoCanvas(main); Transform selectedTransform = FeatureBase<ObjectTreeViewer>.Instance.SelectedTransform; _hoverTextSb.Length = 0; if ((Object)(object)val != (Object)null) { _hoverTextSb.AppendFormat("Raycast hit:\n{0}0: {1} pos={2}\n", ((Object)(object)selectedTransform == (Object)(object)val) ? "> " : "", ((Object)val).name, val.position); } if (list.Count > 0) { _hoverTextSb.AppendLine("Canvas hits:"); for (int i = 0; i < list.Count && i < 10; i++) { RectTransform val2 = list[i]; _hoverTextSb.AppendFormat("{0}{1}: {2} pos={3} size={4}\n", ((Object)(object)selectedTransform == (Object)(object)val2) ? "> " : "", i + 1, ((Object)val2).name, ((Transform)val2).position, val2.sizeDelta); } } if (_hoverTextSb.Length > 0) { if (FeatureBase<ObjectTreeViewer>.Initialized) { _hoverTextSb.Append("[ Press Middle Mouse Button to browse to the next object ]"); if (UnityInput.Current.GetMouseButtonDown(2)) { List<Transform> list2 = (from x in Enumerable.Repeat<Transform>(val, 1).Concat(list.Cast<Transform>()) where (Object)(object)x != (Object)null select x).ToList(); int num = list2.IndexOf(selectedTransform); Transform target = list2.Concat(list2).Skip(num + 1).First(); FeatureBase<ObjectTreeViewer>.Instance.SelectAndShowObject(target); } } _hoverText = _hoverTextSb.ToString(); } else { _hoverText = string.Empty; } } protected override void OnGUI() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) if (_hoverText.Length > 0) { if (_labelSkin == null) { _labelSkin = GUI.skin.label.CreateCopy(); } _labelSkin.alignment = (TextAnchor)0; Vector3 mousePosition = UnityInput.Current.mousePosition; Rect rect = default(Rect); ((Rect)(ref rect))..ctor((float)((int)mousePosition.x + 5), (float)(Screen.height - (int)mousePosition.y + 20), (float)(Screen.width / 2), 500f); if ((int)((Rect)(ref rect)).x > Screen.width / 2) { ((Rect)(ref rect)).x = (int)(((Rect)(ref rect)).x - ((Rect)(ref rect)).width); _labelSkin.alignment = (TextAnchor)2; } if ((int)((Rect)(ref rect)).y > Screen.height / 2) { ((Rect)(ref rect)).y = (int)(((Rect)(ref rect)).y - (((Rect)(ref rect)).height + 23f)); GUIStyle labelSkin = _labelSkin; labelSkin.alignment = (TextAnchor)(labelSkin.alignment + 6); } IMGUIUtils.DrawLabelWithOutline(rect, _hoverText, _labelSkin, Color.white, Color.black, 2); } } private static Transform DoRaycast(Camera camera) { //IL_0011: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)camera == (Object)null) { return null; } Ray val = camera.ScreenPointToRay(UnityInput.Current.mousePosition); RaycastHit val2 = default(RaycastHit); if (!Physics.Raycast(val, ref val2, 1000f)) { return null; } return ((RaycastHit)(ref val2)).transform; } private static List<RectTransform> DoCanvas(Camera camera) { //IL_0013: 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) Vector2 mousePosition = Vector2.op_Implicit(UnityInput.Current.mousePosition); IEnumerable<RectTransform> source = Object.FindObjectsOfType<RectTransform>().Where(delegate(RectTransform rt) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)rt) && rt.sizeDelta.x > 0f && rt.sizeDelta.y > 0f && ((Component)rt).gameObject.activeInHierarchy) { Canvas componentInParent = ((Component)rt).GetComponentInParent<Canvas>(); if ((Object)(object)componentInParent != (Object)null && ((Behaviour)componentInParent).enabled && ((Component)rt).GetComponentsInParent<CanvasGroup>().All((CanvasGroup x) => x.alpha > 0.1f)) { Camera val = (((int)componentInParent.renderMode == 0) ? null : (((Object)(object)componentInParent.worldCamera != (Object)null) ? componentInParent.worldCamera : camera)); return RectTransformUtility.RectangleContainsScreenPoint(rt, mousePosition, val); } } return false; }); return source.OrderBy(delegate(RectTransform x) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) Vector2 sizeDelta = x.sizeDelta; return ((Vector2)(ref sizeDelta)).sqrMagnitude; }).ToList(); } } public sealed class WireframeFeature : FeatureBase<WireframeFeature> { private static readonly string[] _disableEffectNames = new string[5] { "GlobalFog", "BloomAndFlares", "CustomRender", "AmplifyColorEffect", "PostProcessLayer" }; private MonoBehaviour _monoBehaviour; private readonly List<Behaviour> _disabledEffects = new List<Behaviour>(); private static Camera _targetCamera; private bool _updateCoRunning; public override bool Enabled { get { return base.Enabled; } set { if (base.Enabled != value) { base.Enabled = value; if (value) { _monoBehaviour.AbstractStartCoroutine(UpdateCo()); } } } } protected override void Initialize(InitSettings initSettings) { UnityFeatureHelper.EnsureCameraRenderEventsAreAvailable(); DisplayName = "Wireframe"; Enabled = false; _monoBehaviour = initSettings.PluginMonoBehaviour; } private IEnumerator UpdateCo() { if (_updateCoRunning) { yield break; } _updateCoRunning = true; CollectEffects(); SetEffectEnabled(enabled: false); yield return null; if (Enabled) { yield return null; } if (Enabled) { Camera.onPreRender = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreRender, (Delegate?)new CameraCallback(OnPreRender)); Camera.onPostRender = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(OnPostRender)); yield return null; while (Enabled) { SetEffectEnabled(enabled: false); yield return null; } Camera.onPreRender = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreRender, (Delegate?)new CameraCallback(OnPreRender)); Camera.onPostRender = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(OnPostRender)); } SetEffectEnabled(enabled: true); _updateCoRunning = false; } private void CollectEffects() { _disabledEffects.Clear(); _disabledEffects.AddRange(from b in Object.FindObjectsOfType<Camera>().SelectMany((Camera cam) => ((IEnumerable<string>)_disableEffectNames).Select((Func<string, Component>)((Component)cam).GetComponent)).OfType<Behaviour>() where Object.op_Implicit((Object)(object)b) && b.enabled select b); } private void SetEffectEnabled(bool enabled) { for (int i = 0; i < _disabledEffects.Count; i++) { Behaviour val = _disabledEffects[i]; if (Object.op_Implicit((Object)(object)val)) { val.enabled = enabled; } } } private static void OnPreRender(Camera cam) { if (!GL.wireframe) { _targetCamera = cam; GL.wireframe = true; } } private static void OnPostRender(Camera cam) { if ((Object)(object)_targetCamera == (Object)(object)cam) { GL.wireframe = false; _targetCamera = null; } } } public class RuntimeUnityEditorCore { public const string Version = "6.0"; public const string GUID = "RuntimeUnityEditor"; private static InitSettings _initSettings; private readonly List<IFeature> _initializedFeatures = new List<IFeature>(); private readonly InitSettings.Setting<KeyCode> _showHotkey; public static string InstalledVersion => "6.0"; public static RuntimeUnityEditorCore Instance { get; private set; } public KeyCode ShowHotkey { get { //IL_0010: Unknown result type (might be due to invalid IL or missing references) return (KeyCode)(((??)_showHotkey?.Value) ?? 293); } set { //IL_0006: Unknown result type (might be due to invalid IL or missing references) _showHotkey.Value = value; } } public bool Show { get { return Taskbar.Instance.Enabled; } set { if (Taskbar.Instance.Enabled != value) { Taskbar.Instance.Enabled = value; for (int i = 0; i < _initializedFeatures.Count; i++) { _initializedFeatures[i].OnEditorShownChanged(value); } } } } public IEnumerable<IFeature> InitializedFeatures => _initializedFeatures; internal static MonoBehaviour PluginObject => _initSettings.PluginMonoBehaviour; internal static ILoggerWrapper Logger => _initSettings.LoggerWrapper; public static bool IsInitialized() { lock ("RuntimeUnityEditor") { return Instance != null; } } public void AddFeature(IFeature feature) { AddFeatureInt(feature); Taskbar.Instance.SetFeatures(_initializedFeatures); } public bool RemoveFeature(IFeature feature) { if (_initializedFeatures.Remove(feature)) { Taskbar.Instance.SetFeatures(_initializedFeatures); return true; } return false; } internal RuntimeUnityEditorCore(InitSettings initSettings) { lock ("RuntimeUnityEditor") { if (Instance != null) { throw new InvalidOperationException("Can create only one instance of the Core object"); } _initSettings = initSettings; Instance = this; try { _showHotkey = initSettings.RegisterSetting<KeyCode>("General", "Open/close runtime editor", (KeyCode)293, ""); Type iFeatureType = typeof(IFeature); List<IFeature> list = (from t in typeof(RuntimeUnityEditorCore).Assembly.GetTypesSafe() where !t.IsAbstract && iFeatureType.IsAssignableFrom(t) select t).Select(Activator.CreateInstance).Cast<IFeature>().ToList(); foreach (IFeature item in list) { try { AddFeatureInt(item); } catch (Exception ex) { if (item is Taskbar) { throw new InvalidOperationException("WindowManager somehow failed to initialize! I am die, thank you forever.", ex); } Logger.Log(LogLevel.Warning, "Failed to initialize " + item.GetType().Name + " - " + ((ex is NotSupportedException) ? ex.Message : ex.ToString())); } } Taskbar.Instance.SetFeatures(_initializedFeatures); Logger.Log(LogLevel.Info, string.Format("Successfully initialized {0}/{1} features: {2}", _initializedFeatures.Count, list.Count, string.Join(", ", _initializedFeatures.Select((IFeature x) => x.GetType().Name).ToArray()))); } catch { Instance = null; throw; } } } private void AddFeatureInt(IFeature feature) { feature.OnInitialize(_initSettings); _initializedFeatures.Add(feature); } internal void OnGUI() { if (Show) { GUISkin skin = GUI.skin; GUI.skin = InterfaceMaker.CustomSkin; for (int i = 0; i < _initializedFeatures.Count; i++) { _initializedFeatures[i].OnOnGUI(); } GUI.skin = skin; } } internal void Update() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (UnityInput.Current.GetKeyDown(ShowHotkey)) { Show = !Show; } if (Show) { for (int i = 0; i < _initializedFeatures.Count; i++) { _initializedFeatures[i].OnUpdate(); } } } internal void LateUpdate() { if (Show) { for (int i = 0; i < _initializedFeatures.Count; i++) { _initializedFeatures[i].OnLateUpdate(); } } } } public enum ScreenPartition { Default = 0, Full = 5, Center = 10, CenterUpper = 11, CenterLower = 12, Left = 20, LeftUpper = 21, LeftLower = 22, Right = 30, RightUpper = 31, RightLower = 32 } internal static class IL2CppAbstractions { public static void Set(this RectOffset obj, int left, int right, int top, int bottom) { obj.left = left; obj.right = right; obj.top = top; obj.bottom = bottom; } public static Transform[] AbstractGetChildren(this Transform transform, bool castedIl2Cpp = true) { Transform[] array = (Transform[])(object)new Transform[transform.childCount]; for (int i = 0; i < transform.childCount; i++) { Transform child = transform.GetChild(i); array[i] = child; } return array; } public static Component[] AbstractGetAllComponents(this GameObject gameObject, bool castedIl2Cpp = true) { return gameObject.GetComponents<Component>(); } public static Component[] AbstractGetAllComponents(this Component component, bool castedIl2Cpp = true) { return component.GetComponents<Component>(); } public static Component[] AbstractGetAllComponentsInChildren(this GameObject gameObject, bool includeInactive, bool castedIl2Cpp = true) { return gameObject.GetComponentsInChildren<Component>(includeInactive); } public static Component[] AbstractGetAllComponentsInChildren(this Component component, bool includeInactive, bool castedIl2Cpp = true) { return component.GetComponentsInChildren<Component>(includeInactive); } public static Coroutine AbstractStartCoroutine(this MonoBehaviour monoBehaviour, IEnumerator routine) { return monoBehaviour.StartCoroutine(routine); } public static T AbstractAddComponent<T>(this GameObject go) where T : Component { return go.AddComponent<T>(); } } public interface IWindow : IFeature { string Title { get; set; } int WindowId { get; set; } Rect WindowRect { get; set; } Vector2 MinimumSize { get; set; } ScreenPartition DefaultScreenPosition { get; } } public abstract class Window<T> : FeatureBase<T>, IWindow, IFeature where T : Window<T> { protected const int DefaultTooltipWidth = 400; private static GUIStyle _tooltipStyle; private static GUIContent _tooltipContent; private static Texture2D _tooltipBackground; private bool _canShow; private Rect _initialWindowRect; private InitSettings.Setting<Rect> _windowRect; public int TooltipWidth { get; set; } = 400; public override string DisplayName { get { string text = _displayName; if (text == null) { string obj = Title ?? base.DisplayName; string text2 = obj; _displayName = obj; text = text2; } return text; } set { _displayName = value; } } public virtual string Title { get; set; } public int WindowId { get; set; } public virtual Rect WindowRect { get { //IL_0015: 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) if (_windowRect != null) { return _windowRect.Value; } return _initialWindowRect; } set { //IL_0016: 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_000e: Unknown result type (might be due to invalid IL or missing references) if (_windowRect != null) { _windowRect.Value = value; } else { _initialWindowRect = value; } } } public Vector2 MinimumSize { get; set; } = new Vector2(100f, 100f); public ScreenPartition DefaultScreenPosition { get; protected set; } protected Window() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) base.DisplayType = FeatureDisplayType.Window; SettingCategory = "Windows"; } protected override void AfterInitialized(InitSettings initSettings) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) base.AfterInitialized(initSettings); WindowId = base.GetHashCode(); _windowRect = initSettings.RegisterSetting<Rect>(SettingCategory, DisplayName + " window size", _initialWindowRect, string.Empty); } protected override void OnGUI() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009a: 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) if (_canShow) { string title = Title; WindowRect = GUILayout.Window(WindowId, WindowRect, new WindowFunction(DrawContentsInt), title, (GUILayoutOption[])(object)new GUILayoutOption[0]); Rect windowRect = WindowRect; if (((Rect)(ref windowRect)).width < MinimumSize.x) { Rect windowRect2 = WindowRect; ((Rect)(ref windowRect2)).width = MinimumSize.x; WindowRect = windowRect2; } windowRect = WindowRect; if (((Rect)(ref windowRect)).height < MinimumSize.y) { Rect windowRect3 = WindowRect; ((Rect)(ref windowRect3)).height = MinimumSize.y; WindowRect = windowRect3; } } } private void DrawContentsInt(int id) { //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) //IL_0037: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) int num = GUI.skin.window.border.top - 4; Rect windowRect = WindowRect; if (GUI.Button(new Rect(((Rect)(ref windowRect)).width - (float)num - 2f, 2f, (float)num, (float)num), "X")) { Enabled = false; return; } try { DrawContents(); DrawTooltip(WindowRect); } catch (Exception ex) { if (!ex.Message.Contains("GUILayout")) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, $"[{Title}] GUI crash: {ex}"); } } WindowRect = IMGUIUtils.DragResizeEat(id, WindowRect); } private void DrawTooltip(Rect area) { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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 //IL_00e7: 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_012d: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrEmpty(GUI.tooltip)) { if ((Object)(object)_tooltipBackground == (Object)null) { _tooltipBackground = new Texture2D(1, 1, (TextureFormat)5, false); _tooltipBackground.SetPixel(0, 0, Color.black); _tooltipBackground.Apply(); _tooltipStyle = new GUIStyle { normal = new GUIStyleState { textColor = Color.white, background = _tooltipBackground }, wordWrap = true, alignment = (TextAnchor)4 }; _tooltipContent = new GUIContent(); } _tooltipContent.text = GUI.tooltip; float num = TooltipWidth; Rect windowRect = WindowRect; float num2 = Mathf.Min(num, ((Rect)(ref windowRect)).width); float num3 = _tooltipStyle.CalcHeight(_tooltipContent, num2) + 10f; Event current = Event.current; float num4 = ((current.mousePosition.x + num2 > ((Rect)(ref area)).width) ? (((Rect)(ref area)).width - num2) : current.mousePosition.x); float num5 = ((current.mousePosition.y + 25f + num3 > ((Rect)(ref area)).height) ? (current.mousePosition.y - num3) : (current.mousePosition.y + 25f)); GUI.Box(new Rect(num4, num5, num2, num3), GUI.tooltip, _tooltipStyle); } } protected override void OnVisibleChanged(bool visible) { if (visible && Taskbar.Instance.Height == 0) { RuntimeUnityEditorCore.PluginObject.AbstractStartCoroutine(DelayedVisible()); } else { base.OnVisibleChanged(visible); } IEnumerator DelayedVisible() { yield return null; base.OnVisibleChanged(base.Visible); } } protected override void VisibleChanged(bool visible) { if (visible) { if (!WindowManager.IsWindowRectValid(this)) { ResetWindowRect(); } _canShow = true; } } public void ResetWindowRect() { WindowManager.ResetWindowRect(this); } protected abstract void DrawContents(); } public class WindowManager { private const int ScreenMargin = 10; private const int SideWidth = 350; public static Rect MakeDefaultWindowRect(Rect screenClientRect, ScreenPartition screenPartition) { //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: 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_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0275: 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_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) switch (screenPartition) { case ScreenPartition.Left: return EnsureVisible(new Rect(((Rect)(ref screenClientRect)).xMin, ((Rect)(ref screenClientRect)).yMin, 350f, ((Rect)(ref screenClientRect)).height)); case ScreenPartition.LeftUpper: return EnsureVisible(new Rect(((Rect)(ref screenClientRect)).xMin, ((Rect)(ref screenClientRect)).yMin, 350f, ((Rect)(ref screenClientRect)).height / 2f - 10f)); case ScreenPartition.LeftLower: return EnsureVisible(new Rect(((Rect)(ref screenClientRect)).xMin, ((Rect)(ref screenClientRect)).yMin + ((Rect)(ref screenClientRect)).height / 2f, 350f, ((Rect)(ref screenClientRect)).height / 2f)); case ScreenPartition.Center: { int num7 = (int)Mathf.Min(850f, ((Rect)(ref screenClientRect)).width); int num8 = (int)(((Rect)(ref screenClientRect)).xMin + ((Rect)(ref screenClientRect)).width / 2f - (float)Mathf.RoundToInt((float)num7 / 2f)); return EnsureVisible(new Rect((float)num8, ((Rect)(ref screenClientRect)).yMin, (float)num7, ((Rect)(ref screenClientRect)).height)); } case ScreenPartition.CenterUpper: { int num4 = (int)Mathf.Min(850f, ((Rect)(ref screenClientRect)).width); int num5 = (int)(((Rect)(ref screenClientRect)).xMin + ((Rect)(ref screenClientRect)).width / 2f - (float)Mathf.RoundToInt((float)num4 / 2f)); int num6 = (int)(((Rect)(ref screenClientRect)).height / 4f) * 3; return EnsureVisible(new Rect((float)num5, ((Rect)(ref screenClientRect)).yMin, (float)num4, (float)num6)); } case ScreenPartition.CenterLower: { int num = (int)Mathf.Min(850f, ((Rect)(ref screenClientRect)).width); int num2 = (int)(((Rect)(ref screenClientRect)).xMin + ((Rect)(ref screenClientRect)).width / 2f - (float)Mathf.RoundToInt((float)num / 2f)); int num3 = (int)(((Rect)(ref screenClientRect)).height / 4f) * 3; return EnsureVisible(new Rect((float)num2, ((Rect)(ref screenClientRect)).yMin + (float)num3 + 10f, (float)num, ((Rect)(ref screenClientRect)).height - (float)num3 - 10f)); } case ScreenPartition.Right: return EnsureVisible(new Rect(((Rect)(ref screenClientRect)).xMax - 350f, ((Rect)(ref screenClientRect)).yMin, 350f, ((Rect)(ref screenClientRect)).height)); case ScreenPartition.RightUpper: return EnsureVisible(new Rect(((Rect)(ref screenClientRect)).xMax - 350f, ((Rect)(ref screenClientRect)).yMin, 350f, ((Rect)(ref screenClientRect)).height / 2f)); case ScreenPartition.RightLower: return EnsureVisible(new Rect(((Rect)(ref screenClientRect)).xMax - 350f, ((Rect)(ref screenClientRect)).yMin + ((Rect)(ref screenClientRect)).height / 2f, 350f, ((Rect)(ref screenClientRect)).height / 2f)); case ScreenPartition.Full: return screenClientRect; case ScreenPartition.Default: if (!FeatureBase<ReplWindow>.Initialized) { goto case ScreenPartition.Center; } goto case ScreenPartition.CenterUpper; default: throw new ArgumentOutOfRangeException("screenPartition", screenPartition, null); } } private static Rect EnsureVisible(Rect rect) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) Rect result = rect; IEnumerable<IWindow> source = RuntimeUnityEditorCore.Instance.InitializedFeatures.OfType<IWindow>(); List<Rect> source2 = source.Select((IWindow w) => w.WindowRect).ToList(); while (source2.Any((Rect r) => Mathf.Abs(((Rect)(ref r)).x - ((Rect)(ref result)).x) < 7f && Mathf.Abs(((Rect)(ref r)).y - ((Rect)(ref result)).y) < 7f)) { ref Rect reference = ref result; ((Rect)(ref reference)).x = ((Rect)(ref reference)).x + 17f; ref Rect reference2 = ref result; ((Rect)(ref reference2)).y = ((Rect)(ref reference2)).y + 17f; } if (!(((Rect)(ref result)).x < (float)(Screen.width - 50)) || !(((Rect)(ref result)).y < (float)(Screen.height - 50))) { return rect; } return result; } public static void ResetWindowRect(IWindow window) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) Rect screenClientRect = default(Rect); ((Rect)(ref screenClientRect))..ctor(10f, 10f, (float)(Screen.width - 20), (float)(Screen.height - 20 - Taskbar.Instance.Height)); window.WindowRect = MakeDefaultWindowRect(screenClientRect, window.DefaultScreenPosition); } public static bool IsWindowRectValid(IWindow window) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_0082: 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) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) Rect windowRect = window.WindowRect; if (((Rect)(ref windowRect)).width >= window.MinimumSize.x) { windowRect = window.WindowRect; if (((Rect)(ref windowRect)).height >= window.MinimumSize.y) { windowRect = window.WindowRect; if (((Rect)(ref windowRect)).x < (float)(Screen.width - 10)) { windowRect = window.WindowRect; if (((Rect)(ref windowRect)).y < (float)(Screen.height - 10)) { windowRect = window.WindowRect; float x = ((Rect)(ref windowRect)).x; windowRect = window.WindowRect; if (x >= 0f - ((Rect)(ref windowRect)).width + 10f) { windowRect = window.WindowRect; float y = ((Rect)(ref windowRect)).y; windowRect = window.WindowRect; return y >= 0f - ((Rect)(ref windowRect)).height + 10f; } } } } } return false; } } public class Taskbar : IFeature { private int _windowId; private Rect _windowRect; private List<IFeature> _orderedFeatures; private string _title; public static Taskbar Instance { get; private set; } public int Height => (int)((Rect)(ref _windowRect)).height; public bool Enabled { get; set; } FeatureDisplayType IFeature.DisplayType => FeatureDisplayType.Hidden; string IFeature.DisplayName => "WindowManager"; protected string GetTitle() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if ((int)RuntimeUnityEditorCore.Instance.ShowHotkey != 0) { return _title + $" / Press {RuntimeUnityEditorCore.Instance.ShowHotkey} to show/hide"; } return _title; } public Taskbar() { Instance = this; } void IFeature.OnInitialize(InitSettings initSettings) { _windowId = GetHashCode(); _title = "RuntimeUnityEditor v6.0"; } public void SetFeatures(List<IFeature> initializedFeatures) { _orderedFeatures = (from x in initializedFeatures orderby x.DisplayType descending, x.DisplayName select x).ToList(); } void IFeature.OnOnGUI() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) _windowRect = GUILayout.Window(_windowId, _windowRect, new WindowFunction(DrawTaskbar), GetTitle(), (GUILayoutOption[])(object)new GUILayoutOption[3] { GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false), GUILayout.MaxWidth((float)Screen.width) }); IMGUIUtils.EatInputInRect(_windowRect); ((Rect)(ref _windowRect)).x = (int)(((float)Screen.width - ((Rect)(ref _windowRect)).width) / 2f); ((Rect)(ref _windowRect)).y = (int)((float)Screen.height - ((Rect)(ref _windowRect)).height); } private void DrawTaskbar(int id) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]); bool flag = true; foreach (IFeature orderedFeature in _orderedFeatures) { if (orderedFeature.DisplayType == FeatureDisplayType.Window) { GUI.color = (orderedFeature.Enabled ? Color.cyan : Color.white); if (GUILayout.Button(orderedFeature.DisplayName, (GUILayoutOption[])(object)new GUILayoutOption[0])) { orderedFeature.Enabled = !orderedFeature.Enabled; } } else { if (orderedFeature.DisplayType != FeatureDisplayType.Feature) { continue; } if (flag) { GUI.color = new Color(1f, 1f, 1f, 0.75f); if (GUILayout.Button("Reset", (GUILayoutOption[])(object)new GUILayoutOption[0])) { foreach (IWindow item in _orderedFeatures.OfType<IWindow>()) { item.WindowRect = new Rect(-1000f, -1000f, 0f, 0f); } foreach (IWindow item2 in from x in _orderedFeatures.OfType<IWindow>() orderby x.Title select x) { GUI.BringWindowToFront(item2.WindowId); WindowManager.ResetWindowRect(item2); } } flag = false; GUI.color = Color.white; GUILayout.Label("|", (GUILayoutOption[])(object)new GUILayoutOption[0]); } orderedFeature.Enabled = GUILayout.Toggle(orderedFeature.Enabled, orderedFeature.DisplayName, (GUILayoutOption[])(object)new GUILayoutOption[0]); } } GUILayout.Label("|", (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Label("Time", IMGUIUtils.LayoutOptionsExpandWidthFalse); if (GUILayout.Button(">", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { Time.timeScale = 1f; } if (GUILayout.Button("||", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { Time.timeScale = 0f; } if (float.TryParse(GUILayout.TextField(Time.timeScale.ToString("F2", CultureInfo.InvariantCulture), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(38f) }), NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) { Time.timeScale = result; } GUI.changed = false; bool runInBackground = GUILayout.Toggle(Application.runInBackground, "in BG", (GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUI.changed) { Application.runInBackground = runInBackground; } GUILayout.Label("|", (GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUILayout.Button("Log", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { UnityFeatureHelper.OpenLog(); } AssetBundleManagerHelper.DrawButtonIfAvailable(); GUILayout.EndHorizontal(); } void IFeature.OnUpdate() { } void IFeature.OnLateUpdate() { } void IFeature.OnEditorShownChanged(bool visible) { } } internal static class Constants { public const string Version = "6.0"; public const string Name = "RuntimeUnityEditor"; public const string Description = "In-game inspector and debugging tools for applications made with Unity3D game engine"; public const string Website = "https://github.com/ManlyMarco/RuntimeUnityEditor"; public const string Copyright = "Copyright GPL-3 © 2018"; } } namespace RuntimeUnityEditor.Core.REPL { public class REPL : InteractiveBase { [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)] private class DocumentationAttribute : Attribute { public string Docs { get; } public DocumentationAttribute(string doc) { Docs = doc; } } public static string clear { get { FeatureBase<ReplWindow>.Instance.Clear(); return "Log cleared"; } } public static string help { get { string arg = InteractiveBase.help; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(" clear; - Clear this log\n"); stringBuilder.AppendLine(); stringBuilder.AppendLine("In addition, the following helper methods are provided:"); MethodInfo[] methods = typeof(REPL).GetMethods(BindingFlags.Static | BindingFlags.Public); foreach (MethodInfo methodInfo in methods) { object[] customAttributes = methodInfo.GetCustomAttributes(typeof(DocumentationAttribute), inherit: false); if (customAttributes.Length != 0) { stringBuilder.Append(" "); stringBuilder.AppendLine(((DocumentationAttribute)customAttributes[0]).Docs); } } return $"{arg}{stringBuilder}"; } } public static object InteropTempVar { get; set; } [Documentation("MB - A dummy MonoBehaviour for accessing Unity.")] public static ReplHelper MB { get; } static REPL() { MB = ((Component)RuntimeUnityEditorCore.PluginObject).gameObject.AbstractAddComponent<ReplHelper>(); } [Documentation("find<T>() - find a UnityEngine.Object of type T.")] public static T find<T>() where T : Object { return MB.Find<T>(); } [Documentation("findAll<T>() - find all UnityEngine.Object of type T.")] public static T[] findAll<T>() where T : Object { return MB.FindAll<T>(); } [Documentation("runCoroutine(enumerator) - runs an IEnumerator as a Unity coroutine.")] public static Coroutine runCoroutine(IEnumerator i) { return MB.RunCoroutine(i); } [Documentation("endCoroutine(co) - ends a Unity coroutine.")] public static void endCoroutine(Coroutine c) { MB.EndCoroutine(c); } [Documentation("type<T>() - obtain type info about a type T. Provides some Reflection helpers.")] public static TypeHelper type<T>() { return new TypeHelper(typeof(T)); } [Documentation("type(obj) - obtain type info about object obj. Provides some Reflection helpers.")] public static TypeHelper type(object instance) { return new TypeHelper(instance); } [Documentation("dir(obj) - lists all available methods and fiels of a given obj.")] public static string dir(object instance) { return type(instance).info(); } [Documentation("dir<T>() - lists all available methods and fields of type T.")] public static string dir<T>() { return type<T>().info(); } [Documentation("findrefs(obj) - find references to the object in currently loaded components.")] public static Component[] findrefs(object obj) { if (obj == null) { throw new ArgumentNullException("obj"); } List<Component> list = new List<Component>(); Component[] array = Object.FindObjectsOfType<Component>(); foreach (Component val in array) { Type type = ((object)val).GetType(); string[] nameBlacklist = new string[5] { "parent", "parentInternal", "root", "transform", "gameObject" }; Type[] typeBlacklist = new Type[1] { typeof(bool) }; foreach (PropertyInfo item in from x in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where x.CanRead && !nameBlacklist.Contains(x.Name) && !typeBlacklist.Contains(x.PropertyType) select x) { try { if (object.Equals(item.GetValue(val, null), obj)) { list.Add(val); goto IL_0179; } } catch { } } foreach (FieldInfo item2 in from x in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where !nameBlacklist.Contains(x.Name) && !typeBlacklist.Contains(x.FieldType) select x) { try { if (object.Equals(item2.GetValue(val), obj)) { list.Add(val); break; } } catch { } } IL_0179:; } return list.ToArray(); } [Documentation("geti() - get object currently opened in inspector. Will get expanded upon accepting. Best to use like this: var x = geti()")] public static object geti() { return FeatureBase<RuntimeUnityEditor.Core.Inspector.Inspector>.Instance.GetInspectedObject() ?? throw new InvalidOperationException("No object is opened in inspector or a static type is opened"); } public static T geti<T>() { return (T)geti(); } [Documentation("seti(obj) - send the object to the inspector. To send a static class use the setis(type) command.")] public static void seti(object obj) { if (obj == null) { throw new ArgumentNullException("obj"); } FeatureBase<RuntimeUnityEditor.Core.Inspector.Inspector>.Instance.Push(new InstanceStackEntry(obj, "REPL > " + obj.GetType().Name), newTab: true); } [Documentation("setis(type) - send the static class to the inspector.")] public static void setis(Type type) { if ((object)type == null) { throw new ArgumentNullException("type"); } FeatureBase<RuntimeUnityEditor.Core.Inspector.Inspector>.Instance.Push(new StaticStackEntry(type, "REPL > " + type.Name), newTab: true); } [Documentation("getTree() - get the transform currently selected in tree view.")] public static Transform getTree() { return FeatureBase<ObjectTreeViewer>.Instance.SelectedTransform; } [Documentation("findTree(Transform) - find and select the transform in the tree view.")] public static void findTree(Transform tr) { if ((Object)(object)tr == (Object)null) { throw new ArgumentNullException("tr"); } FeatureBase<ObjectTreeViewer>.Instance.SelectAndShowObject(tr); } [Documentation("findTree(GameObject) - find and select the object in the tree view.")] public static void findTree(GameObject go) { if ((Object)(object)go == (Object)null) { throw new ArgumentNullException("go"); } FeatureBase<ObjectTreeViewer>.Instance.SelectAndShowObject(go.transform); } [Documentation("dnspy(type) - open the type in dnSpy if dnSpy path is configured.")] public static void dnspy(Type type) { if ((object)type == null) { throw new ArgumentNullException("type"); } DnSpyHelper.OpenInDnSpy(type); } [Documentation("dnspy(memberInfo) - open the type member in dnSpy if dnSpy is configured.")] public static void dnspy(MemberInfo member) { if ((object)member == null) { throw new ArgumentNullException("member"); } DnSpyHelper.OpenInDnSpy(member); } [Documentation("echo(string) - write a string to REPL output.")] public static void echo(string message) { FeatureBase<ReplWindow>.Instance.AppendLogLine(message); } [Documentation("message(string) - write a string to log.")] public static void message(string message) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Message, message); } [Documentation("paste(index) - paste clipboard contents from a given int index.")] public static object paste(int index) { return ClipboardWindow.Contents[index]; } [Documentation("copy(object) - copy given object to clipboard (classes are copied by reference, returns the index it was added under).")] public static int copy(object @object) { ClipboardWindow.Contents.Add(@object); return ClipboardWindow.Contents.Count - 1; } [Documentation("dump(object, fileName) - dump given object to a new text file at specitied path.")] public static void dump(object @object, string fileName) { @object.DumpToFile("REPL_OBJECT", fileName); } [Documentation("dump(object) - dump given object to a temporary text file and open it in notepad. Returns path to the temp file.")] public static string dump(object @object) { return Dumper.DumpToTempFile(@object, "REPL_OBJECT"); } [Documentation("registerToString<TObj>(Func<TObj, string>) - add a ToString converter for a Type to change how it's displayed in Inspector and some other places.")] public static void registerToString<TObj>(Func<TObj, string> objectToString) { ToStringConverter.AddConverter(objectToString); } } public class ReplHelper : MonoBehaviour { public T Find<T>() where T : Object { return Object.FindObjectOfType<T>(); } public T[] FindAll<T>() where T : Object { return Object.FindObjectsOfType<T>(); } public Coroutine RunCoroutine(IEnumerator i) { return ((MonoBehaviour)(object)this).AbstractStartCoroutine(i); } public void EndCoroutine(Coroutine c) { ((MonoBehaviour)this).StopCoroutine(c); } } public sealed class ReplWindow : Window<ReplWindow> { private class VoidType { public static readonly VoidType Value = new VoidType(); private VoidType() { } } private string _autostartFilename; private static readonly char[] _inputSplitChars = new char[11] { ',', ';', '<', '>', '(', ')', '[', ']', '=', '|', '&' }; private const int HistoryLimit = 50; private ScriptEvaluator _evaluator; private readonly List<string> _history = new List<string>(); private int _historyPosition; private readonly StringBuilder _sb = new StringBuilder(); private string _inputField = ""; private string _prevInput = ""; private Vector2 _scrollPosition = Vector2.zero; private TextEditor _textEditor; private int _newCursorLocation = -1; private MemberInfo _cursorIndex; private MemberInfo _selectIndex; private HashSet<string> _namespaces; private readonly List<Suggestion> _suggestions = new List<Suggestion>(); private const string SnippletSeparator = "/****************************************/"; private string _snippletFilename; private readonly List<string> _savedSnipplets = new List<string>(); private bool _snippletsShown; private GUIStyle _completionsListingStyle; private bool _refocus; private int _refocusCursorIndex = -1; private int _refocusSelectIndex; private HashSet<string> Namespaces { get { if (_namespaces == null) { _namespaces = new HashSet<string>(from x in AppDomain.CurrentDomain.GetAssemblies().SelectMany(Extensions.GetTypesSafe) where !string.IsNullOrEmpty(x.Namespace) select x.Namespace); RuntimeUnityEditorCore.Logger.Log(LogLevel.Debug, $"[REPL] Found {_namespaces.Count} public namespaces"); } return _namespaces; } } protected override void Initialize(InitSettings initSettings) { //IL_00d1: Unknown result type (might be due to invalid IL or missing references) if (!UnityFeatureHelper.SupportsRepl) { throw new InvalidOperationException("mcs is not supported on this Unity version"); } InitSettings.Setting<bool> setting = initSettings.RegisterSetting("General", "Disable REPL function", defaultValue: false, "Completely turn off REPL even if it's supported. Useful if mcs is causing compatibility issues (e.g. in rare cases it can crash the game when used together with some versions of RuntimeDetours in some Unity versions)."); if (setting.Value) { throw new InvalidOperationException("REPL is disabled in config"); } string configPath = initSettings.ConfigPath; _autostartFilename = Path.Combine(configPath, "RuntimeUnityEditor.Autostart.cs"); _snippletFilename = Path.Combine(configPath, "RuntimeUnityEditor.Snipplets.cs"); Title = "C# REPL Console"; _sb.AppendLine("Welcome to C# REPL (read-evaluate-print loop)! Enter \"help\" to get a list of common methods."); ScriptEvaluator scriptEvaluator = new ScriptEvaluator(new StringWriter(_sb)); ((Evaluator)scriptEvaluator).InteractiveBaseClass = typeof(REPL); _evaluator = scriptEvaluator; initSettings.PluginMonoBehaviour.AbstractStartCoroutine(DelayedReplSetup()); DisplayName = "REPL console"; base.MinimumSize = new Vector2(280f, 130f); Enabled = false; base.DefaultScreenPosition = ScreenPartition.CenterLower; } protected override void VisibleChanged(bool visible) { base.VisibleChanged(visible); _namespaces = null; } private IEnumerator DelayedReplSetup() { yield return null; try { RunEnvSetup(); } catch (Exception ex) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Warning, "Failed to initialize REPL environment - " + ex.Message); try { RuntimeUnityEditorCore.Instance.RemoveFeature(this); _evaluator.Dispose(); } catch (Exception content) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Debug, content); } } } public void RunEnvSetup() { string str = "using System;using UnityEngine;using System.Linq;using System.Collections;using System.Collections.Generic;"; Evaluate(str); RunAutostart(_autostartFilename); } private void RunAutostart(string autostartFilename) { if (!File.Exists(autostartFilename)) { return; } string[] array = (from x in File.ReadAllLines(autostartFilename) select x.Trim('\t', ' ', '\r', '\n') into x where !string.IsNullOrEmpty(x) && !x.StartsWith("//") select x).ToArray(); if (array.Length != 0) { string text = "Executing code from " + autostartFilename; RuntimeUnityEditorCore.Logger.Log(LogLevel.Info, text); AppendLogLine(text); string[] array2 = array; foreach (string str in array2) { Evaluate(str); } } } protected override void DrawContents() { //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Invalid comparison between Unknown and I4 //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) if (_completionsListingStyle == null) { _completionsListingStyle = GUI.skin.button.CreateCopy(); _completionsListingStyle.border = new RectOffset(); _completionsListingStyle.margin = new RectOffset(); _completionsListingStyle.padding = new RectOffset(); _completionsListingStyle.hover.background = Texture2D.whiteTexture; _completionsListingStyle.hover.textColor = Color.black; _completionsListingStyle.normal.background = null; _completionsListingStyle.focused.background = Texture2D.whiteTexture; _completionsListingStyle.focused.textColor = Color.black; _completionsListingStyle.active.background = Texture2D.whiteTexture; _completionsListingStyle.active.textColor = Color.black; } GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[0]); _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true, GUIStyle.none, GUI.skin.verticalScrollbar, GUI.skin.textArea, (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.FlexibleSpace(); if (_snippletsShown) { if (_savedSnipplets.Count == 0) { GUILayout.Label("This is a list of saved snipplets of code that you can load later into the input field.\n\nTo save a snipplet, type someting in the input field and click the Save button.\nTo load a snipplet, make sure the input field is empty, click the Load button, then choose a snipplet.\nTo remove a snipplet you can edit the snipplet file by choosing the bottom option on the snipplet list.\n\nClose this menu without loading anything by clicking the Cancel button below.", GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]); } else { _completionsListingStyle.normal.textColor = Color.white; foreach (string savedSnipplet in _savedSnipplets) { if (GUILayout.Button(savedSnipplet, GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue)) { _inputField = savedSnipplet; _snippletsShown = false; break; } } if (GUILayout.Button(">> Edit snipplet list in external editor <<", GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue)) { AppendLogLine("Opening snipplet file at " + _snippletFilename); if (!File.Exists(_snippletFilename)) { File.WriteAllText(_snippletFilename, ""); } try { Process.Start(_snippletFilename); } catch (Exception ex) { AppendLogLine(ex.Message); } } } } else if (_suggestions.Count > 0) { foreach (Suggestion suggestion in _suggestions) { _completionsListingStyle.normal.textColor = suggestion.GetTextColor(); if (GUILayout.Button(suggestion.Result, _completionsListingStyle, IMGUIUtils.LayoutOptionsExpandWidthTrue)) { AcceptSuggestion(suggestion); break; } } } else { GUILayout.TextArea(_sb.ToString(), GUI.skin.label, (GUILayoutOption[])(object)new GUILayoutOption[0]); } GUILayout.EndScrollView(); GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]); GUI.SetNextControlName("replInput"); _inputField = GUILayout.TextArea(_inputField, (GUILayoutOption[])(object)new GUILayoutOption[0]); if ((int)Event.current.type == 7) { if (_refocus) { if (_refocusCursorIndex < 0) { _refocusCursorIndex = (int)ReflectionUtils.GetValue(_cursorIndex, _textEditor); _refocusSelectIndex = (int)ReflectionUtils.GetValue(_selectIndex, _textEditor); } GUI.FocusControl("replInput"); _refocus = false; } else if (_refocusCursorIndex >= 0) { ReflectionUtils.SetValue(_cursorIndex, _textEditor, _refocusCursorIndex); ReflectionUtils.SetValue(_selectIndex, _textEditor, _refocusSelectIndex); _refocusCursorIndex = -1; } } if (GUILayout.Button("Run", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { AcceptInput(); } if (GUILayout.Button(_snippletsShown ? "Cancel" : ((_inputField.Length == 0) ? "Load" : "Save"), IMGUIUtils.LayoutOptionsExpandWidthFalse)) { if (_snippletsShown) { _snippletsShown = false; } else if (_inputField.Length == 0) { _snippletsShown = true; IEnumerable<string> enumerable2; if (!File.Exists(_snippletFilename)) { IEnumerable<string> enumerable = new string[0]; enumerable2 = enumerable; } else { enumerable2 = from x in File.ReadAllText(_snippletFilename).Split(new string[1] { "/****************************************/" }, StringSplitOptions.RemoveEmptyEntries) select x.Replace("\t", " ").Trim(' ', '\r', '\n') into x where x.Length > 0 select x; } IEnumerable<string> collection = enumerable2; _savedSnipplets.Clear(); _savedSnipplets.AddRange(collection); } else { string contents = (File.Exists(_snippletFilename) ? (_inputField + Environment.NewLine + "/****************************************/" + Environment.NewLine + File.ReadAllText(_snippletFilename)) : _inputField); File.WriteAllText(_snippletFilename, contents); AppendLogLine("Saved current command to snipplets. Clear the input box and click Load to load it."); } } if (GUILayout.Button("Autostart", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { AppendLogLine("Opening autostart file at " + _autostartFilename); if (!File.Exists(_autostartFilename)) { File.WriteAllText(_autostartFilename, "// This C# code will be executed by the REPL near the end of plugin initialization. Only single-line statements are supported. Use echo(string) to write to REPL log and message(string) to write to global log.\n\n"); } try { Process.Start(_autostartFilename); } catch (Exception ex2) { AppendLogLine(ex2.Message); } ScrollToBottom(); } if (GUILayout.Button("History", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { AppendLogLine(""); AppendLogLine("# History of executed commands:"); foreach (string item in _history) { AppendLogLine(item); } ScrollToBottom(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); CheckReplInput(); } private void AcceptSuggestion(Suggestion suggestion) { int num = (int)ReflectionUtils.GetValue(_cursorIndex, _textEditor); if (num - suggestion.Original.Length >= 0) { num -= suggestion.Original.Length; _inputField = _inputField.Remove(num, suggestion.Original.Length); } _inputField = _inputField.Insert(num, suggestion.Result); _newCursorLocation = num + suggestion.Result.Length; ClearSuggestions(); _refocus = true; _refocusCursorIndex = _newCursorLocation; _refocusSelectIndex = _newCursorLocation; } public object Evaluate(string str) { object value = VoidType.Value; CompiledMethod val = default(CompiledMethod); ((Evaluator)_evaluator).Compile(str, ref val); try { if (val != null) { val.Invoke(ref value); } } catch (Exception ex) { AppendLogLine(ex.ToString()); } return value; } private void FetchHistory(int move) { if (_history.Count != 0) { _historyPosition += move; _historyPosition %= _history.Count; if (_historyPosition < 0) { _historyPosition = _history.Count - 1; } _inputField = _history[_historyPosition]; } } private void FetchSuggestions(string input) { try { _suggestions.Clear(); if (input.IndexOfAny(new char[5] { '?', '{', '}', '[', ']' }) < 0) { int length = _sb.Length; string prefix = default(string); string[] completions = ((Evaluator)_evaluator).GetCompletions(input, ref prefix); _sb.Length = length; if (completions != null) { if (prefix == null) { prefix = input; } _suggestions.AddRange(from x in completions where !string.IsNullOrEmpty(x) select new Suggestion(x, prefix, Namespaces.Contains(x) ? SuggestionKind.Namespace : SuggestionKind.Unknown)); } } _refocus = true; } catch (Exception ex) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Debug, "[REPL] " + ex); ClearSuggestions(); } } private void CheckReplInput() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Invalid comparison between Unknown and I4 //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Invalid comparison between Unknown and I4 //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Invalid comparison between Unknown and I4 //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Invalid comparison between Unknown and I4 if (GUI.GetNameOfFocusedControl() != "replInput") { return; } _textEditor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl); Type typeFromHandle = typeof(TextEditor); _cursorIndex = typeFromHandle.GetProperty("cursorIndex", BindingFlags.Instance | BindingFlags.Public); _selectIndex = typeFromHandle.GetProperty("selectIndex", BindingFlags.Instance | BindingFlags.Public); if ((object)_cursorIndex == null && (object)_selectIndex == null) { _cursorIndex = typeFromHandle.GetField("pos", BindingFlags.Instance | BindingFlags.Public); _selectIndex = typeFromHandle.GetField("selectPos", BindingFlags.Instance | BindingFlags.Public); } if (_newCursorLocation >= 0) { ReflectionUtils.SetValue(_cursorIndex, _textEditor, _newCursorLocation); ReflectionUtils.SetValue(_selectIndex, _textEditor, _newCursorLocation); _newCursorLocation = -1; } string text = _inputField; Event current = Event.current; if (current.isKey) { if ((int)current.keyCode == 13 || (int)current.keyCode == 271) { if (!current.shift) { int num = (int)ReflectionUtils.GetValue(_cursorIndex, _textEditor); if (num - 1 >= 0) { _inputField = _inputField.Remove(num - 1, 1); } AcceptInput(); current.Use(); } } else if (text == null || !Enumerable.Contains(text, '\n')) { if ((int)current.keyCode == 273) { FetchHistory(-1); current.Use(); ClearSuggestions(); } else if ((int)current.keyCode == 274) { FetchHistory(1); current.Use(); ClearSuggestions(); } } } if (!string.IsNullOrEmpty(text)) { try { int num2 = ((_refocusCursorIndex >= 0) ? _refocusCursorIndex : ((int)ReflectionUtils.GetValue(_cursorIndex, _textEditor))); int num3 = ((num2 > 0) ? (text.LastIndexOfAny(_inputSplitChars, num2 - 1) + 1) : 0); int num4 = ((num2 <= 0) ? text.Length : text.IndexOfAny(_inputSplitChars, num2 - 1)); if (num4 < 0 || num4 < num3) { num4 = text.Length; } text = text.Substring(num3, num4 - num3); } catch (ArgumentException) { } if (text != _prevInput && !string.IsNullOrEmpty(text)) { FetchSuggestions(text); } } else { ClearSuggestions(); } _prevInput = text; } private void ClearSuggestions() { if (_suggestions.Any()) { _suggestions.Clear(); _refocus = true; } } private void AcceptInput() { _inputField = _inputField.Trim(); if (_inputField == "") { return; } _history.Add(_inputField); if (_history.Count > 50) { _history.RemoveRange(0, _history.Count - 50); } _historyPosition = 0; Change.Report("(REPL)::" + _inputField); if (_inputField.Contains("geti()")) { try { object obj = REPL.geti(); if (obj != null) { _inputField = _inputField.Replace("geti()", "geti<" + obj.GetType().GetSourceCodeRepresentation() + ">()"); } } catch (SystemException) { } } AppendLogLine("> " + _inputField); object obj2 = Evaluate(_inputField); if (obj2 != null && !object.Equals(obj2, VoidType.Value)) { AppendLogLine(obj2.ToString()); } ScrollToBottom(); _inputField = string.Empty; ClearSuggestions(); } private void ScrollToBottom() { _scrollPosition.y = float.MaxValue; } internal void AppendLogLine(string message) { _sb.AppendLine(message); } public void Clear() { _sb.Length = 0; } public void IngestObject(object obj) { if (obj == null) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Warning, "obj is null in: " + new StackTrace()); return; } REPL.InteropTempVar = obj; _prevInput = (_inputField = "var " + GetUniqueVarName() + " = (" + obj.GetType().GetSourceCodeRepresentation() + ")InteropTempVar"); ClearSuggestions(); } private string GetUniqueVarName() { string text = default(string); int num = ((Evaluator)_evaluator).GetCompletions("q", ref text).Max(delegate(string x) { Match match = Regex.Match(x, "^q(\\d*)$", RegexOptions.Singleline); if (match.Success) { string value = match.Groups[1].Value; if (!string.IsNullOrEmpty(value)) { return int.Parse(value); } return 0; } return -1; }); return "q" + ((num >= 0) ? (num + 1).ToString() : ""); } } internal struct Suggestion { public readonly string Original; public readonly string Result; public readonly SuggestionKind Kind; public Suggestion(string result, string original, SuggestionKind kind) { Original = original; Kind = kind; Result = result; } public Color GetTextColor() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (Kind != SuggestionKind.Namespace) { return Color.white; } return Color.gray; } } internal enum SuggestionKind { Unknown, Namespace } public class TypeHelper { public object instance; public Type type; public TypeHelper(Type type) { this.type = type; instance = null; } public TypeHelper(object instance) { this.instance = instance; type = instance.GetType(); } public T val<T>(string name) where T : class { FieldInfo field = type.GetField(name, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if ((object)field != null) { if (!field.IsStatic && instance == null) { throw new ArgumentException("Field is not static, but instance is missing."); } return field.GetValue(field.IsStatic ? null : instance) as T; } PropertyInfo property = type.GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if ((object)property == null || !property.CanWrite) { throw new ArgumentException("No field or settable property of name " + name + " was found!"); } MethodInfo setMethod = property.GetSetMethod(nonPublic: true); if (!setMethod.IsStatic && instance == null) { throw new ArgumentException("Property is not static, but instance is missing."); } return setMethod.Invoke(setMethod.IsStatic ? null : instance, null) as T; } public void set(string name, object value) { FieldInfo field = type.GetField(name, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if ((object)field != null) { if (!field.IsStatic && instance == null) { throw new ArgumentException("Field is not static, but instance is missing."); } field.SetValue(field.IsStatic ? null : instance, value); return; } PropertyInfo property = type.GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if ((object)property == null || !property.CanWrite) { throw new ArgumentException("No field or settable property of name " + name + " was found!"); } MethodInfo setMethod = property.GetSetMethod(nonPublic: true); if (!setMethod.IsStatic && instance == null) { throw new ArgumentException("Property is not static, but instance is missing."); } setMethod.Invoke(setMethod.IsStatic ? null : instance, new object[1] { value }); } public object invoke(string name, params object[] args) { MethodInfo method = type.GetMethod(name, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if ((object)method == null) { throw new ArgumentException("No method of name " + name + " was found!"); } if (!method.IsStatic