using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using Microsoft.CodeAnalysis; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Cecil.Rocks; using Mono.Collections.Generic; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyCompany("GrimePreloadPatchers")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+ad77b2f166f2c310a5f7e7e68fedc183c7768edb")] [assembly: AssemblyProduct("GrimePreloadPatchers")] [assembly: AssemblyTitle("GrimePreloadPatchers")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] [CompilerGenerated] internal sealed class <>z__ReadOnlySingleElementList : IEnumerable, ICollection, IList, IEnumerable, ICollection, IList { private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator { object IEnumerator.Current => _item; T IEnumerator.Current => _item; public Enumerator(T item) { _item = item; } bool IEnumerator.MoveNext() { if (!_moveNextCalled) { return _moveNextCalled = true; } return false; } void IEnumerator.Reset() { _moveNextCalled = false; } void IDisposable.Dispose() { } } int ICollection.Count => 1; bool ICollection.IsSynchronized => false; object ICollection.SyncRoot => this; object IList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { throw new NotSupportedException(); } } bool IList.IsFixedSize => true; bool IList.IsReadOnly => true; int ICollection.Count => 1; bool ICollection.IsReadOnly => true; T IList.this[int index] { get { if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { throw new NotSupportedException(); } } public <>z__ReadOnlySingleElementList(T item) { _item = item; } IEnumerator IEnumerable.GetEnumerator() { return new Enumerator(_item); } void ICollection.CopyTo(Array array, int index) { array.SetValue(_item, index); } int IList.Add(object value) { throw new NotSupportedException(); } void IList.Clear() { throw new NotSupportedException(); } bool IList.Contains(object value) { return EqualityComparer.Default.Equals(_item, (T)value); } int IList.IndexOf(object value) { if (!EqualityComparer.Default.Equals(_item, (T)value)) { return -1; } return 0; } void IList.Insert(int index, object value) { throw new NotSupportedException(); } void IList.Remove(object value) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } IEnumerator IEnumerable.GetEnumerator() { return new Enumerator(_item); } void ICollection.Add(T item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Contains(T item) { return EqualityComparer.Default.Equals(_item, item); } void ICollection.CopyTo(T[] array, int arrayIndex) { array[arrayIndex] = _item; } bool ICollection.Remove(T item) { throw new NotSupportedException(); } int IList.IndexOf(T item) { if (!EqualityComparer.Default.Equals(_item, item)) { return -1; } return 0; } void IList.Insert(int index, T item) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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; } } } namespace GrimePreloadPatchers { public static class Patcher { private static readonly HashSet dictionaryTypes = new HashSet { "Rewired.Utils.Classes.Data.ADictionary`2", "Rewired.Utils.Classes.Data.IndexedDictionary`2" }; public static IEnumerable TargetDLLs => new <>z__ReadOnlySingleElementList("Rewired_Core.dll"); public static void Patch(AssemblyDefinition assembly) { //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_001a: 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) Enumerator enumerator = assembly.Modules.GetEnumerator(); try { while (enumerator.MoveNext()) { Enumerator enumerator2 = enumerator.Current.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { TypeDefinition current = enumerator2.Current; if (dictionaryTypes.Contains(((MemberReference)current).FullName)) { PatchDictionaryType(current); } } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } } private static void PatchDictionaryType(TypeDefinition type) { TypeDefinition val = ((MemberReference)type).Module.ImportReference(typeof(IDictionary)).Resolve(); CreateShimIntBoolProperty(type, ((IEnumerable)val.Properties).First((PropertyDefinition p) => ((MemberReference)p).Name == "IsFixedSize")); CreateShimIntBoolProperty(type, ((IEnumerable)val.Properties).First((PropertyDefinition p) => ((MemberReference)p).Name == "IsReadOnly")); CreateGenericIDictionaryKeysProperty(type); } private static void CreateShimIntBoolProperty(TypeDefinition typeToModify, PropertyDefinition implementing) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_00aa: Expected O, but got Unknown string text = ((MemberReference)implementing.DeclaringType).FullName + "."; MethodDefinition val = new MethodDefinition(text + ((MemberReference)implementing.GetMethod).Name, BuildAttrs(), ((PropertyReference)implementing).PropertyType); ILProcessor iLProcessor = val.Body.GetILProcessor(); iLProcessor.Append(iLProcessor.Create(OpCodes.Ldc_I4_0)); iLProcessor.Append(iLProcessor.Create(OpCodes.Ret)); val.Overrides.Add(((MemberReference)typeToModify).Module.ImportReference((MethodReference)(object)implementing.GetMethod)); typeToModify.Methods.Add(val); PropertyDefinition val2 = new PropertyDefinition(text + ((MemberReference)implementing).Name, (PropertyAttributes)0, ((PropertyReference)implementing).PropertyType) { GetMethod = val }; typeToModify.Properties.Add(val2); } private static void CreateGenericIDictionaryKeysProperty(TypeDefinition typeToModify) { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Expected O, but got Unknown TypeReference obj = ((MemberReference)typeToModify).Module.ImportReference(typeof(ICollection<>)); TypeDefinition obj2 = ((MemberReference)typeToModify).Module.ImportReference(typeof(IDictionary<, >)).Resolve(); PropertyDefinition val = ((IEnumerable)typeToModify.Properties).First((PropertyDefinition p) => ((MemberReference)p).Name == "System.Collections.IDictionary.Keys"); PropertyDefinition val2 = ((IEnumerable)obj2.Properties).First((PropertyDefinition p) => ((MemberReference)p).Name == "Keys"); TypeReference val3 = (TypeReference)(object)TypeReferenceRocks.MakeGenericInstanceType(obj, (TypeReference[])(object)new TypeReference[1] { (TypeReference)((IEnumerable)((TypeReference)typeToModify).GenericParameters).First() }); MethodDefinition val4 = new MethodDefinition("System.Collections.Generic.IDictionary." + ((MemberReference)val2.GetMethod).Name, BuildAttrs(), val3); ILProcessor iLProcessor = val4.Body.GetILProcessor(); iLProcessor.Append(iLProcessor.Create(OpCodes.Ldarg_0)); iLProcessor.Append(iLProcessor.Create(OpCodes.Callvirt, (MethodReference)(object)val.GetMethod)); iLProcessor.Append(iLProcessor.Create(OpCodes.Ret)); MethodReference method = ((MemberReference)typeToModify).Module.ImportReference((MethodReference)(object)val2.GetMethod); method = CloneMethodReferenceGeneric(method, (TypeReference)((IEnumerable)((TypeReference)typeToModify).GenericParameters).ElementAt(0), (TypeReference)((IEnumerable)((TypeReference)typeToModify).GenericParameters).ElementAt(1)); val4.Overrides.Add(method); typeToModify.Methods.Add(val4); PropertyDefinition val5 = new PropertyDefinition("System.Collections.Generic.IDictionary." + ((MemberReference)val2).Name, (PropertyAttributes)0, val3) { GetMethod = val4 }; typeToModify.Properties.Add(val5); } private static MethodAttributes BuildAttrs() { return (MethodAttributes)2529; } private static MethodReference CloneMethodReferenceGeneric(MethodReference method, params TypeReference[] arguments) { //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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0048: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown MethodReference val = new MethodReference(((MemberReference)method).Name, method.ReturnType, (TypeReference)(object)TypeReferenceRocks.MakeGenericInstanceType(((MemberReference)method).DeclaringType, arguments)) { HasThis = method.HasThis, ExplicitThis = method.ExplicitThis, CallingConvention = method.CallingConvention }; Enumerator enumerator = method.Parameters.GetEnumerator(); try { while (enumerator.MoveNext()) { ParameterReference current = (ParameterReference)(object)enumerator.Current; val.Parameters.Add(new ParameterDefinition(current.ParameterType)); } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } Enumerator enumerator2 = method.GenericParameters.GetEnumerator(); try { while (enumerator2.MoveNext()) { GenericParameter current2 = enumerator2.Current; val.GenericParameters.Add(new GenericParameter(((MemberReference)current2).Name, (IGenericParameterProvider)(object)val)); } return val; } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } } } }