using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Mdb;
using Mono.Cecil.Pdb;
using Mono.Collections.Generic;
using MonoMod.Cil;
using MonoMod.InlineRT;
using MonoMod.Utils;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("0x0ade")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright 2021 0x0ade")]
[assembly: AssemblyDescription("General purpose .NET assembly modding \"basework\". This package contains the core IL patcher and relinker.")]
[assembly: AssemblyFileVersion("21.8.5.1")]
[assembly: AssemblyInformationalVersion("21.08.05.01")]
[assembly: AssemblyProduct("MonoMod")]
[assembly: AssemblyTitle("MonoMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("21.8.5.1")]
[module: UnverifiableCode]
internal static class MultiTargetShims
{
private static readonly object[] _NoArgs = new object[0];
public static TypeReference GetConstraintType(this TypeReference type)
{
return type;
}
}
namespace MonoMod
{
[MonoMod__SafeToCopy__]
public class MonoModAdded : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModConstructor : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModCustomAttributeAttribute : Attribute
{
public MonoModCustomAttributeAttribute(string h)
{
}
}
[MonoMod__SafeToCopy__]
public class MonoModCustomMethodAttributeAttribute : Attribute
{
public MonoModCustomMethodAttributeAttribute(string h)
{
}
}
[MonoMod__SafeToCopy__]
public class MonoModEnumReplace : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModForceCall : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModForceCallvirt : Attribute
{
}
[MonoMod__SafeToCopy__]
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
[Obsolete("Use MonoModLinkFrom or RuntimeDetour / HookGen instead.")]
public class MonoModHook : Attribute
{
public string FindableID;
public Type Type;
public MonoModHook(string findableID)
{
FindableID = findableID;
}
public MonoModHook(Type type)
{
Type = type;
FindableID = type.FullName;
}
}
[MonoMod__SafeToCopy__]
public class MonoModIfFlag : Attribute
{
public MonoModIfFlag(string key)
{
}
public MonoModIfFlag(string key, bool fallback)
{
}
}
[MonoMod__SafeToCopy__]
public class MonoModIgnore : Attribute
{
}
[MonoMod__SafeToCopy__]
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class MonoModLinkFrom : Attribute
{
public string FindableID;
public Type Type;
public MonoModLinkFrom(string findableID)
{
FindableID = findableID;
}
public MonoModLinkFrom(Type type)
{
Type = type;
FindableID = type.FullName;
}
}
[MonoMod__SafeToCopy__]
public class MonoModLinkTo : Attribute
{
public MonoModLinkTo(string t)
{
}
public MonoModLinkTo(Type t)
{
}
public MonoModLinkTo(string t, string n)
{
}
public MonoModLinkTo(Type t, string n)
{
}
}
[MonoMod__SafeToCopy__]
public class MonoModNoNew : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModOnPlatform : Attribute
{
public MonoModOnPlatform(params Platform[] p)
{
}
}
[MonoMod__SafeToCopy__]
public class MonoModOriginal : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModOriginalName : Attribute
{
public MonoModOriginalName(string n)
{
}
}
[MonoMod__SafeToCopy__]
public class MonoModPatch : Attribute
{
public MonoModPatch(string name)
{
}
}
[MonoMod__SafeToCopy__]
public class MonoModPublic : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModRemove : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModReplace : Attribute
{
}
[MonoMod__SafeToCopy__]
public class MonoModTargetModule : Attribute
{
public MonoModTargetModule(string name)
{
}
}
[MonoMod__SafeToCopy__]
internal class MonoMod__SafeToCopy__ : Attribute
{
}
public delegate bool MethodParser(MonoModder modder, MethodBody body, Instruction instr, ref int instri);
public delegate void MethodRewriter(MonoModder modder, MethodDefinition method);
public delegate void MethodBodyRewriter(MonoModder modder, MethodBody body, Instruction instr, int instri);
public delegate ModuleDefinition MissingDependencyResolver(MonoModder modder, ModuleDefinition main, string name, string fullName);
public delegate void PostProcessor(MonoModder modder);
public delegate void ModReadEventHandler(MonoModder modder, ModuleDefinition mod);
public class RelinkMapEntry
{
public string Type;
public string FindableID;
public RelinkMapEntry()
{
}
public RelinkMapEntry(string type, string findableID)
{
Type = type;
FindableID = findableID;
}
}
public enum DebugSymbolFormat
{
Auto,
MDB,
PDB
}
public class MonoModder : IDisposable
{
public static readonly bool IsMono = (object)Type.GetType("Mono.Runtime") != null;
public static readonly Version Version = typeof(MonoModder).Assembly.GetName().Version;
public Dictionary<string, object> SharedData = new Dictionary<string, object>();
public Dictionary<string, object> RelinkMap = new Dictionary<string, object>();
public Dictionary<string, ModuleDefinition> RelinkModuleMap = new Dictionary<string, ModuleDefinition>();
public HashSet<string> SkipList = new HashSet<string>(EqualityComparer<string>.Default);
public Dictionary<string, IMetadataTokenProvider> RelinkMapCache = new Dictionary<string, IMetadataTokenProvider>();
public Dictionary<string, TypeReference> RelinkModuleMapCache = new Dictionary<string, TypeReference>();
public Dictionary<string, OpCode> ForceCallMap = new Dictionary<string, OpCode>();
public ModReadEventHandler OnReadMod;
public PostProcessor PostProcessors;
public Dictionary<string, Action<object, object[]>> CustomAttributeHandlers = new Dictionary<string, Action<object, object[]>> {
{
"MonoMod.MonoModPublic",
delegate
{
}
} };
public Dictionary<string, Action<object, object[]>> CustomMethodAttributeHandlers = new Dictionary<string, Action<object, object[]>>();
public MissingDependencyResolver MissingDependencyResolver;
public MethodParser MethodParser;
public MethodRewriter MethodRewriter;
public MethodBodyRewriter MethodBodyRewriter;
public Stream Input;
public string InputPath;
public Stream Output;
public string OutputPath;
public List<string> DependencyDirs = new List<string>();
public ModuleDefinition Module;
public Dictionary<ModuleDefinition, List<ModuleDefinition>> DependencyMap = new Dictionary<ModuleDefinition, List<ModuleDefinition>>();
public Dictionary<string, ModuleDefinition> DependencyCache = new Dictionary<string, ModuleDefinition>();
public Func<ICustomAttributeProvider, TypeReference, bool> ShouldCleanupAttrib;
public bool LogVerboseEnabled;
public bool CleanupEnabled;
public bool PublicEverything;
public List<ModuleReference> Mods = new List<ModuleReference>();
public bool Strict;
public bool MissingDependencyThrow;
public bool RemovePatchReferences;
public bool PreventInline;
public bool? UpgradeMSCORLIB;
public ReadingMode ReadingMode = (ReadingMode)1;
public DebugSymbolFormat DebugSymbolOutputFormat;
public int CurrentRID;
protected IAssemblyResolver _assemblyResolver;
protected ReaderParameters _readerParameters;
protected WriterParameters _writerParameters;
public bool GACEnabled;
private string[] _GACPathsNone = new string[0];
protected string[] _GACPaths;
protected MethodDefinition _mmOriginalCtor;
protected MethodDefinition _mmOriginalNameCtor;
protected MethodDefinition _mmAddedCtor;
protected MethodDefinition _mmPatchCtor;
public virtual IAssemblyResolver AssemblyResolver
{
get
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Expected O, but got Unknown
if (_assemblyResolver == null)
{
DefaultAssemblyResolver val = new DefaultAssemblyResolver();
foreach (string dependencyDir in DependencyDirs)
{
((BaseAssemblyResolver)val).AddSearchDirectory(dependencyDir);
}
_assemblyResolver = (IAssemblyResolver)(object)val;
}
return _assemblyResolver;
}
set
{
_assemblyResolver = value;
}
}
public virtual ReaderParameters ReaderParameters
{
get
{
//IL_000a: 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_0014: 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_002c: Expected O, but got Unknown
if (_readerParameters == null)
{
_readerParameters = new ReaderParameters(ReadingMode)
{
AssemblyResolver = AssemblyResolver,
ReadSymbols = true
};
}
return _readerParameters;
}
set
{
_readerParameters = value;
}
}
public virtual WriterParameters WriterParameters
{
get
{
//IL_0037: 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_0043: 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_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
//IL_0067: Expected O, but got Unknown
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
if (_writerParameters == null)
{
bool flag = DebugSymbolOutputFormat == DebugSymbolFormat.PDB;
bool flag2 = DebugSymbolOutputFormat == DebugSymbolFormat.MDB;
if (DebugSymbolOutputFormat == DebugSymbolFormat.Auto)
{
if ((PlatformHelper.Current & 0x25) == 37)
{
flag = true;
}
else
{
flag2 = true;
}
}
WriterParameters val = new WriterParameters
{
WriteSymbols = true
};
object symbolWriterProvider;
if (!flag)
{
if (!flag2)
{
symbolWriterProvider = null;
}
else
{
ISymbolWriterProvider val2 = (ISymbolWriterProvider)new MdbWriterProvider();
symbolWriterProvider = val2;
}
}
else
{
ISymbolWriterProvider val2 = (ISymbolWriterProvider)new NativePdbWriterProvider();
symbolWriterProvider = val2;
}
val.SymbolWriterProvider = (ISymbolWriterProvider)symbolWriterProvider;
_writerParameters = val;
}
return _writerParameters;
}
set
{
_writerParameters = value;
}
}
public string[] GACPaths
{
get
{
if (!GACEnabled)
{
return _GACPathsNone;
}
if (_GACPaths != null)
{
return _GACPaths;
}
if (!IsMono)
{
string environmentVariable = Environment.GetEnvironmentVariable("windir");
if (string.IsNullOrEmpty(environmentVariable))
{
return _GACPaths = _GACPathsNone;
}
environmentVariable = Path.Combine(environmentVariable, "Microsoft.NET");
environmentVariable = Path.Combine(environmentVariable, "assembly");
_GACPaths = new string[3]
{
Path.Combine(environmentVariable, "GAC_32"),
Path.Combine(environmentVariable, "GAC_64"),
Path.Combine(environmentVariable, "GAC_MSIL")
};
}
else
{
List<string> list = new List<string>();
string text = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)), "gac");
if (Directory.Exists(text))
{
list.Add(text);
}
string environmentVariable2 = Environment.GetEnvironmentVariable("MONO_GAC_PREFIX");
if (!string.IsNullOrEmpty(environmentVariable2))
{
string[] array = environmentVariable2.Split(new char[1] { Path.PathSeparator });
foreach (string text2 in array)
{
if (!string.IsNullOrEmpty(text2))
{
string path = text2;
path = Path.Combine(path, "lib");
path = Path.Combine(path, "mono");
path = Path.Combine(path, "gac");
if (Directory.Exists(path) && !list.Contains(path))
{
list.Add(path);
}
}
}
}
_GACPaths = list.ToArray();
}
return _GACPaths;
}
set
{
GACEnabled = true;
_GACPaths = value;
}
}
public MonoModder()
{
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
MethodParser = DefaultParser;
MissingDependencyResolver = DefaultMissingDependencyResolver;
PostProcessors = (PostProcessor)Delegate.Combine(PostProcessors, new PostProcessor(DefaultPostProcessor));
string environmentVariable = Environment.GetEnvironmentVariable("MONOMOD_DEPDIRS");
if (!string.IsNullOrEmpty(environmentVariable))
{
foreach (string item in from dir in environmentVariable.Split(new char[1] { Path.PathSeparator })
select dir.Trim())
{
IAssemblyResolver assemblyResolver = AssemblyResolver;
IAssemblyResolver obj = ((assemblyResolver is BaseAssemblyResolver) ? assemblyResolver : null);
if (obj != null)
{
((BaseAssemblyResolver)obj).AddSearchDirectory(item);
}
DependencyDirs.Add(item);
}
}
LogVerboseEnabled = Environment.GetEnvironmentVariable("MONOMOD_LOG_VERBOSE") == "1";
CleanupEnabled = Environment.GetEnvironmentVariable("MONOMOD_CLEANUP") != "0";
PublicEverything = Environment.GetEnvironmentVariable("MONOMOD_PUBLIC_EVERYTHING") == "1";
PreventInline = Environment.GetEnvironmentVariable("MONOMOD_PREVENTINLINE") == "1";
Strict = Environment.GetEnvironmentVariable("MONOMOD_STRICT") == "1";
MissingDependencyThrow = Environment.GetEnvironmentVariable("MONOMOD_DEPENDENCY_MISSING_THROW") != "0";
RemovePatchReferences = Environment.GetEnvironmentVariable("MONOMOD_DEPENDENCY_REMOVE_PATCH") != "0";
string environmentVariable2 = Environment.GetEnvironmentVariable("MONOMOD_DEBUG_FORMAT");
if (environmentVariable2 != null)
{
environmentVariable2 = environmentVariable2.ToLowerInvariant();
if (environmentVariable2 == "pdb")
{
DebugSymbolOutputFormat = DebugSymbolFormat.PDB;
}
else if (environmentVariable2 == "mdb")
{
DebugSymbolOutputFormat = DebugSymbolFormat.MDB;
}
}
string environmentVariable3 = Environment.GetEnvironmentVariable("MONOMOD_MSCORLIB_UPGRADE");
UpgradeMSCORLIB = (string.IsNullOrEmpty(environmentVariable3) ? null : new bool?(environmentVariable3 != "0"));
GACEnabled = Environment.GetEnvironmentVariable("MONOMOD_GAC_ENABLED") != "0";
MonoModRulesManager.Register(this);
}
public virtual void ClearCaches(bool all = false, bool shareable = false, bool moduleSpecific = false)
{
if (all || shareable)
{
foreach (KeyValuePair<string, ModuleDefinition> item in DependencyCache)
{
item.Value.Dispose();
}
DependencyCache.Clear();
}
if (all || moduleSpecific)
{
RelinkMapCache.Clear();
RelinkModuleMapCache.Clear();
}
}
public virtual void Dispose()
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
ClearCaches(all: true);
ModuleDefinition module = Module;
if (module != null)
{
module.Dispose();
}
Module = null;
((IDisposable)AssemblyResolver)?.Dispose();
AssemblyResolver = null;
foreach (ModuleDefinition mod in Mods)
{
if ((int)mod != 0)
{
mod.Dispose();
}
}
foreach (List<ModuleDefinition> value in DependencyMap.Values)
{
foreach (ModuleDefinition item in value)
{
if (item != null)
{
item.Dispose();
}
}
}
DependencyMap.Clear();
Input?.Dispose();
Output?.Dispose();
}
public virtual void Log(object value)
{
Log(value.ToString());
}
public virtual void Log(string text)
{
Console.Write("[MonoMod] ");
Console.WriteLine(text);
}
public virtual void LogVerbose(object value)
{
if (LogVerboseEnabled)
{
Log(value);
}
}
public virtual void LogVerbose(string text)
{
if (LogVerboseEnabled)
{
Log(text);
}
}
private static ModuleDefinition _ReadModule(Stream input, ReaderParameters args)
{
if (args.ReadSymbols)
{
try
{
return ModuleDefinition.ReadModule(input, args);
}
catch
{
args.ReadSymbols = false;
input.Seek(0L, SeekOrigin.Begin);
}
}
return ModuleDefinition.ReadModule(input, args);
}
private static ModuleDefinition _ReadModule(string input, ReaderParameters args)
{
if (args.ReadSymbols)
{
try
{
return ModuleDefinition.ReadModule(input, args);
}
catch
{
args.ReadSymbols = false;
}
}
return ModuleDefinition.ReadModule(input, args);
}
public virtual void Read()
{
if (Module != null)
{
return;
}
if (Input != null)
{
Log("Reading input stream into module.");
Module = _ReadModule(Input, GenReaderParameters(mainModule: true));
}
else if (InputPath != null)
{
Log("Reading input file into module.");
IAssemblyResolver assemblyResolver = AssemblyResolver;
IAssemblyResolver obj = ((assemblyResolver is BaseAssemblyResolver) ? assemblyResolver : null);
if (obj != null)
{
((BaseAssemblyResolver)obj).AddSearchDirectory(Path.GetDirectoryName(InputPath));
}
DependencyDirs.Add(Path.GetDirectoryName(InputPath));
Module = _ReadModule(InputPath, GenReaderParameters(mainModule: true, InputPath));
}
string environmentVariable = Environment.GetEnvironmentVariable("MONOMOD_MODS");
if (string.IsNullOrEmpty(environmentVariable))
{
return;
}
foreach (string item in from path in environmentVariable.Split(new char[1] { Path.PathSeparator })
select path.Trim())
{
ReadMod(item);
}
}
public virtual void MapDependencies()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
foreach (ModuleDefinition mod in Mods)
{
ModuleDefinition main = mod;
MapDependencies(main);
}
MapDependencies(Module);
}
public virtual void MapDependencies(ModuleDefinition main)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
if (DependencyMap.ContainsKey(main))
{
return;
}
DependencyMap[main] = new List<ModuleDefinition>();
Enumerator<AssemblyNameReference> enumerator = main.AssemblyReferences.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
AssemblyNameReference current = enumerator.Current;
MapDependency(main, current);
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
public virtual void MapDependency(ModuleDefinition main, AssemblyNameReference depRef)
{
MapDependency(main, depRef.Name, depRef.FullName, depRef);
}
public virtual void MapDependency(ModuleDefinition main, string name, string fullName = null, AssemblyNameReference depRef = null)
{
if (!DependencyMap.TryGetValue(main, out var value))
{
value = (DependencyMap[main] = new List<ModuleDefinition>());
}
if (fullName != null && (DependencyCache.TryGetValue(fullName, out var value2) || DependencyCache.TryGetValue(fullName + " [RT:" + main.RuntimeVersion + "]", out value2)))
{
LogVerbose("[MapDependency] " + ((ModuleReference)main).Name + " -> " + ((ModuleReference)value2).Name + " ((" + fullName + "), (" + name + ")) from cache");
value.Add(value2);
MapDependencies(value2);
return;
}
if (DependencyCache.TryGetValue(name, out value2) || DependencyCache.TryGetValue(name + " [RT:" + main.RuntimeVersion + "]", out value2))
{
LogVerbose("[MapDependency] " + ((ModuleReference)main).Name + " -> " + ((ModuleReference)value2).Name + " (" + name + ") from cache");
value.Add(value2);
MapDependencies(value2);
return;
}
string text = Path.GetExtension(name).ToLowerInvariant();
bool flag = text == "pdb" || text == "mdb";
string text2 = null;
foreach (string dependencyDir in DependencyDirs)
{
text2 = Path.Combine(dependencyDir, name + ".dll");
if (!File.Exists(text2))
{
text2 = Path.Combine(dependencyDir, name + ".exe");
}
if (!File.Exists(text2) && !flag)
{
text2 = Path.Combine(dependencyDir, name);
}
if (File.Exists(text2))
{
break;
}
text2 = null;
}
if (text2 == null && depRef != null)
{
try
{
AssemblyDefinition obj = AssemblyResolver.Resolve(depRef);
value2 = ((obj != null) ? obj.MainModule : null);
}
catch
{
}
if (value2 != null)
{
text2 = value2.FileName;
}
}
if (text2 == null)
{
string[] gACPaths = GACPaths;
for (int i = 0; i < gACPaths.Length; i++)
{
text2 = Path.Combine(gACPaths[i], name);
if (Directory.Exists(text2))
{
string[] directories = Directory.GetDirectories(text2);
int num = 0;
int num2 = 0;
for (int j = 0; j < directories.Length; j++)
{
string text3 = directories[j];
if (text3.StartsWith(text2))
{
text3 = text3.Substring(text2.Length + 1);
}
Match match = Regex.Match(text3, "\\d+");
if (match.Success)
{
int num3 = int.Parse(match.Value);
if (num3 > num)
{
num = num3;
num2 = j;
}
}
}
text2 = Path.Combine(directories[num2], name + ".dll");
break;
}
text2 = null;
}
}
if (text2 == null)
{
try
{
AssemblyDefinition obj3 = AssemblyResolver.Resolve(AssemblyNameReference.Parse(fullName ?? name));
value2 = ((obj3 != null) ? obj3.MainModule : null);
}
catch
{
}
if (value2 != null)
{
text2 = value2.FileName;
}
}
if (value2 == null)
{
if (text2 != null && File.Exists(text2))
{
value2 = _ReadModule(text2, GenReaderParameters(mainModule: false, text2));
}
else if ((value2 = MissingDependencyResolver?.Invoke(this, main, name, fullName)) == null)
{
return;
}
}
LogVerbose("[MapDependency] " + ((ModuleReference)main).Name + " -> " + ((ModuleReference)value2).Name + " ((" + fullName + "), (" + name + ")) loaded");
value.Add(value2);
if (fullName == null)
{
fullName = value2.Assembly.FullName;
}
DependencyCache[fullName] = value2;
DependencyCache[name] = value2;
MapDependencies(value2);
}
public virtual ModuleDefinition DefaultMissingDependencyResolver(MonoModder mod, ModuleDefinition main, string name, string fullName)
{
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
if (MissingDependencyThrow && Environment.GetEnvironmentVariable("MONOMOD_DEPENDENCY_MISSING_THROW") == "0")
{
Log("[MissingDependencyResolver] [WARNING] Use MMILRT.Modder.MissingDependencyThrow instead of setting the env var MONOMOD_DEPENDENCY_MISSING_THROW");
MissingDependencyThrow = false;
}
if (MissingDependencyThrow || Strict)
{
throw new RelinkTargetNotFoundException("MonoMod cannot map dependency " + ((ModuleReference)main).Name + " -> ((" + fullName + "), (" + name + ")) - not found", (IMetadataTokenProvider)(object)main, (IMetadataTokenProvider)null);
}
return null;
}
public virtual void Write(Stream output = null, string outputPath = null)
{
output = output ?? Output;
outputPath = outputPath ?? OutputPath;
PatchRefsInType(PatchWasHere());
if (output != null)
{
Log("[Write] Writing modded module into output stream.");
Module.Write(output, WriterParameters);
}
else
{
Log("[Write] Writing modded module into output file.");
Module.Write(outputPath, WriterParameters);
}
}
public virtual ReaderParameters GenReaderParameters(bool mainModule, string path = null)
{
//IL_0008: 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_0013: Expected O, but got Unknown
ReaderParameters readerParameters = ReaderParameters;
ReaderParameters val = new ReaderParameters(readerParameters.ReadingMode);
val.AssemblyResolver = readerParameters.AssemblyResolver;
val.MetadataResolver = readerParameters.MetadataResolver;
val.InMemory = readerParameters.InMemory;
val.MetadataImporterProvider = readerParameters.MetadataImporterProvider;
val.ReflectionImporterProvider = readerParameters.ReflectionImporterProvider;
val.ThrowIfSymbolsAreNotMatching = readerParameters.ThrowIfSymbolsAreNotMatching;
val.ApplyWindowsRuntimeProjections = readerParameters.ApplyWindowsRuntimeProjections;
val.SymbolStream = readerParameters.SymbolStream;
val.SymbolReaderProvider = readerParameters.SymbolReaderProvider;
val.ReadSymbols = readerParameters.ReadSymbols;
if (path != null && !File.Exists(path + ".mdb") && !File.Exists(Path.ChangeExtension(path, "pdb")))
{
val.ReadSymbols = false;
}
return val;
}
public virtual void ReadMod(string path)
{
if (Directory.Exists(path))
{
Log("[ReadMod] Loading mod dir: " + path);
string text = ((ModuleReference)Module).Name.Substring(0, ((ModuleReference)Module).Name.Length - 3);
string value = text.Replace(" ", "");
if (!DependencyDirs.Contains(path))
{
IAssemblyResolver assemblyResolver = AssemblyResolver;
IAssemblyResolver obj = ((assemblyResolver is BaseAssemblyResolver) ? assemblyResolver : null);
if (obj != null)
{
((BaseAssemblyResolver)obj).AddSearchDirectory(path);
}
DependencyDirs.Add(path);
}
string[] files = Directory.GetFiles(path);
foreach (string text2 in files)
{
if ((Path.GetFileName(text2).StartsWith(text) || Path.GetFileName(text2).StartsWith(value)) && text2.ToLower().EndsWith(".mm.dll"))
{
ReadMod(text2);
}
}
return;
}
Log("[ReadMod] Loading mod: " + path);
ModuleDefinition val = _ReadModule(path, GenReaderParameters(mainModule: false, path));
string directoryName = Path.GetDirectoryName(path);
if (!DependencyDirs.Contains(directoryName))
{
IAssemblyResolver assemblyResolver2 = AssemblyResolver;
IAssemblyResolver obj2 = ((assemblyResolver2 is BaseAssemblyResolver) ? assemblyResolver2 : null);
if (obj2 != null)
{
((BaseAssemblyResolver)obj2).AddSearchDirectory(directoryName);
}
DependencyDirs.Add(directoryName);
}
Mods.Add((ModuleReference)(object)val);
OnReadMod?.Invoke(this, val);
}
public virtual void ReadMod(Stream stream)
{
Log($"[ReadMod] Loading mod: stream#{(uint)stream.GetHashCode()}");
ModuleDefinition val = _ReadModule(stream, GenReaderParameters(mainModule: false));
Mods.Add((ModuleReference)(object)val);
OnReadMod?.Invoke(this, val);
}
public virtual void ParseRules(ModuleDefinition mod)
{
//IL_002c: 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)
TypeDefinition type = mod.GetType("MonoMod.MonoModRules");
Type rulesTypeMMILRT = null;
if (type != null)
{
rulesTypeMMILRT = this.ExecuteRules(type);
mod.Types.Remove(type);
}
Enumerator<TypeDefinition> enumerator = mod.Types.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
TypeDefinition current = enumerator.Current;
ParseRulesInType(current, rulesTypeMMILRT);
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
public virtual void ParseRulesInType(TypeDefinition type, Type rulesTypeMMILRT = null)
{
//IL_0035: 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_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_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_0372: Unknown result type (might be due to invalid IL or missing references)
//IL_0377: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_0431: Unknown result type (might be due to invalid IL or missing references)
//IL_0436: Unknown result type (might be due to invalid IL or missing references)
Extensions.GetPatchFullName((MemberReference)(object)type);
if (!MatchingConditionals((ICustomAttributeProvider)(object)type, Module))
{
return;
}
CustomAttribute customAttribute = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModCustomAttributeAttribute");
CustomAttributeArgument val;
if (customAttribute != null)
{
val = customAttribute.ConstructorArguments[0];
MethodInfo method2 = rulesTypeMMILRT.GetMethod((string)((CustomAttributeArgument)(ref val)).Value);
CustomAttributeHandlers[((MemberReference)type).FullName] = delegate(object self, object[] args)
{
method2.Invoke(self, args);
};
}
customAttribute = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModCustomMethodAttributeAttribute");
if (customAttribute != null)
{
val = customAttribute.ConstructorArguments[0];
MethodInfo method = rulesTypeMMILRT.GetMethod((string)((CustomAttributeArgument)(ref val)).Value);
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == 2 && Extensions.IsCompatible(parameters[0].ParameterType, typeof(ILContext)))
{
CustomMethodAttributeHandlers[((MemberReference)type).FullName] = delegate(object self, object[] args)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
ILContext il = new ILContext((MethodDefinition)args[0]);
il.Invoke((Manipulator)delegate
{
method.Invoke(self, new object[2]
{
il,
args[1]
});
});
if (il.IsReadOnly)
{
il.Dispose();
}
};
}
else
{
CustomMethodAttributeHandlers[((MemberReference)type).FullName] = delegate(object self, object[] args)
{
method.Invoke(self, args);
};
}
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModHook"); val2 != null; val2 = ((ICustomAttributeProvider)(object)type).GetNextCustomAttribute("MonoMod.MonoModHook"))
{
ParseLinkFrom((MemberReference)(object)type, val2);
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModLinkFrom"); val2 != null; val2 = ((ICustomAttributeProvider)(object)type).GetNextCustomAttribute("MonoMod.MonoModLinkFrom"))
{
ParseLinkFrom((MemberReference)(object)type, val2);
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModLinkTo"); val2 != null; val2 = ((ICustomAttributeProvider)(object)type).GetNextCustomAttribute("MonoMod.MonoModLinkTo"))
{
ParseLinkTo((MemberReference)(object)type, val2);
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModIgnore"))
{
return;
}
Enumerator<MethodDefinition> enumerator = type.Methods.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
MethodDefinition current = enumerator.Current;
if (MatchingConditionals((ICustomAttributeProvider)(object)current, Module))
{
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current, "MonoMod.MonoModHook"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current).GetNextCustomAttribute("MonoMod.MonoModHook"))
{
ParseLinkFrom((MemberReference)(object)current, val2);
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current, "MonoMod.MonoModLinkFrom"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current).GetNextCustomAttribute("MonoMod.MonoModLinkFrom"))
{
ParseLinkFrom((MemberReference)(object)current, val2);
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current, "MonoMod.MonoModLinkTo"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current).GetNextCustomAttribute("MonoMod.MonoModLinkTo"))
{
ParseLinkTo((MemberReference)(object)current, val2);
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)current, "MonoMod.MonoModForceCall"))
{
ForceCallMap[Extensions.GetID((MethodReference)(object)current, (string)null, (string)null, true, false)] = OpCodes.Call;
}
else if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)current, "MonoMod.MonoModForceCallvirt"))
{
ForceCallMap[Extensions.GetID((MethodReference)(object)current, (string)null, (string)null, true, false)] = OpCodes.Callvirt;
}
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
Enumerator<FieldDefinition> enumerator2 = type.Fields.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
FieldDefinition current2 = enumerator2.Current;
if (MatchingConditionals((ICustomAttributeProvider)(object)current2, Module))
{
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current2, "MonoMod.MonoModHook"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current2).GetNextCustomAttribute("MonoMod.MonoModHook"))
{
ParseLinkFrom((MemberReference)(object)current2, val2);
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current2, "MonoMod.MonoModLinkFrom"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current2).GetNextCustomAttribute("MonoMod.MonoModLinkFrom"))
{
ParseLinkFrom((MemberReference)(object)current2, val2);
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current2, "MonoMod.MonoModLinkTo"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current2).GetNextCustomAttribute("MonoMod.MonoModLinkTo"))
{
ParseLinkTo((MemberReference)(object)current2, val2);
}
}
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
Enumerator<PropertyDefinition> enumerator3 = type.Properties.GetEnumerator();
try
{
while (enumerator3.MoveNext())
{
PropertyDefinition current3 = enumerator3.Current;
if (MatchingConditionals((ICustomAttributeProvider)(object)current3, Module))
{
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current3, "MonoMod.MonoModHook"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current3).GetNextCustomAttribute("MonoMod.MonoModHook"))
{
ParseLinkFrom((MemberReference)(object)current3, val2);
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current3, "MonoMod.MonoModLinkFrom"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current3).GetNextCustomAttribute("MonoMod.MonoModLinkFrom"))
{
ParseLinkFrom((MemberReference)(object)current3, val2);
}
for (CustomAttribute val2 = Extensions.GetCustomAttribute((ICustomAttributeProvider)(object)current3, "MonoMod.MonoModLinkTo"); val2 != null; val2 = ((ICustomAttributeProvider)(object)current3).GetNextCustomAttribute("MonoMod.MonoModLinkTo"))
{
ParseLinkTo((MemberReference)(object)current3, val2);
}
}
}
}
finally
{
((IDisposable)enumerator3).Dispose();
}
Enumerator<TypeDefinition> enumerator4 = type.NestedTypes.GetEnumerator();
try
{
while (enumerator4.MoveNext())
{
TypeDefinition current4 = enumerator4.Current;
ParseRulesInType(current4, rulesTypeMMILRT);
}
}
finally
{
((IDisposable)enumerator4).Dispose();
}
}
public virtual void ParseLinkFrom(MemberReference target, CustomAttribute hook)
{
//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)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_006b: 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_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
CustomAttributeArgument val = hook.ConstructorArguments[0];
string key = (string)((CustomAttributeArgument)(ref val)).Value;
object value;
if (target is TypeReference)
{
value = Extensions.GetPatchFullName((MemberReference)(TypeReference)target);
}
else if (target is MethodReference)
{
value = new RelinkMapEntry(Extensions.GetPatchFullName((MemberReference)(object)((MemberReference)(MethodReference)target).DeclaringType), Extensions.GetID((MethodReference)target, (string)null, (string)null, false, false));
}
else if (target is FieldReference)
{
value = new RelinkMapEntry(Extensions.GetPatchFullName((MemberReference)(object)((MemberReference)(FieldReference)target).DeclaringType), ((MemberReference)(FieldReference)target).Name);
}
else
{
if (!(target is PropertyReference))
{
return;
}
value = new RelinkMapEntry(Extensions.GetPatchFullName((MemberReference)(object)((MemberReference)(PropertyReference)target).DeclaringType), ((MemberReference)(PropertyReference)target).Name);
}
RelinkMap[key] = value;
}
public virtual void ParseLinkTo(MemberReference from, CustomAttribute hook)
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: 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)
MemberReference obj = ((from is MethodReference) ? from : null);
string key = ((obj != null) ? Extensions.GetID((MethodReference)(object)obj, (string)null, (string)null, true, false) : null) ?? Extensions.GetPatchFullName(from);
CustomAttributeArgument val;
if (hook.ConstructorArguments.Count == 1)
{
Dictionary<string, object> relinkMap = RelinkMap;
val = hook.ConstructorArguments[0];
relinkMap[key] = (string)((CustomAttributeArgument)(ref val)).Value;
}
else
{
Dictionary<string, object> relinkMap2 = RelinkMap;
val = hook.ConstructorArguments[0];
string type = (string)((CustomAttributeArgument)(ref val)).Value;
val = hook.ConstructorArguments[1];
relinkMap2[key] = new RelinkMapEntry(type, (string)((CustomAttributeArgument)(ref val)).Value);
}
}
public virtual void RunCustomAttributeHandlers(ICustomAttributeProvider cap)
{
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
if (!cap.HasCustomAttributes)
{
return;
}
CustomAttribute[] array = cap.CustomAttributes.ToArray();
foreach (CustomAttribute val in array)
{
if (CustomAttributeHandlers.TryGetValue(((MemberReference)val.AttributeType).FullName, out var value))
{
value?.Invoke(null, new object[2] { cap, val });
}
if (cap is MethodReference && CustomMethodAttributeHandlers.TryGetValue(((MemberReference)val.AttributeType).FullName, out value))
{
value?.Invoke(null, new object[2]
{
(object)(MethodDefinition)cap,
val
});
}
}
}
public virtual void AutoPatch()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Expected O, but got Unknown
Log("[AutoPatch] Parsing rules in loaded mods");
foreach (ModuleDefinition mod4 in Mods)
{
ModuleDefinition mod = mod4;
ParseRules(mod);
}
Log("[AutoPatch] PrePatch pass");
foreach (ModuleDefinition mod5 in Mods)
{
ModuleDefinition mod2 = mod5;
PrePatchModule(mod2);
}
Log("[AutoPatch] Patch pass");
foreach (ModuleDefinition mod6 in Mods)
{
ModuleDefinition mod3 = mod6;
PatchModule(mod3);
}
Log("[AutoPatch] PatchRefs pass");
PatchRefs();
if (PostProcessors != null)
{
Delegate[] invocationList = PostProcessors.GetInvocationList();
for (int i = 0; i < invocationList.Length; i++)
{
Log($"[PostProcessor] PostProcessor pass #{i + 1}");
((PostProcessor)invocationList[i])?.Invoke(this);
}
}
}
public virtual IMetadataTokenProvider Relinker(IMetadataTokenProvider mtp, IGenericParameterProvider context)
{
//IL_0027: 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)
try
{
return PostRelinker(MainRelinker(mtp, context) ?? mtp, context) ?? throw new RelinkTargetNotFoundException(mtp, (IMetadataTokenProvider)(object)context);
}
catch (Exception ex)
{
throw new RelinkFailedException((string)null, ex, mtp, (IMetadataTokenProvider)(object)context);
}
}
public virtual IMetadataTokenProvider MainRelinker(IMetadataTokenProvider mtp, IGenericParameterProvider context)
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
TypeReference val = (TypeReference)(object)((mtp is TypeReference) ? mtp : null);
if (val != null)
{
if (((MemberReference)val).Module == Module)
{
return (IMetadataTokenProvider)(object)val;
}
if (((MemberReference)val).Module != null && !Mods.Contains((ModuleReference)(object)((MemberReference)val).Module))
{
return (IMetadataTokenProvider)(object)Module.ImportReference(val);
}
val = (TypeReference)(((object)Extensions.SafeResolve(val)) ?? ((object)val));
TypeReference val2 = FindTypeDeep(Extensions.GetPatchFullName((MemberReference)(object)val));
if (val2 == null)
{
if (RelinkMap.ContainsKey(((MemberReference)val).FullName))
{
return null;
}
throw new RelinkTargetNotFoundException(mtp, (IMetadataTokenProvider)(object)context);
}
return (IMetadataTokenProvider)(object)Module.ImportReference(val2);
}
if (mtp is FieldReference || mtp is MethodReference || mtp is PropertyReference || mtp is EventReference)
{
return Extensions.ImportReference(Module, mtp);
}
throw new InvalidOperationException($"MonoMod default relinker can't handle metadata token providers of the type {((object)mtp).GetType()}");
}
public virtual IMetadataTokenProvider PostRelinker(IMetadataTokenProvider mtp, IGenericParameterProvider context)
{
return ResolveRelinkTarget(mtp) ?? mtp;
}
public virtual IMetadataTokenProvider ResolveRelinkTarget(IMetadataTokenProvider mtp, bool relink = true, bool relinkModule = true)
{
//IL_000b: 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_002f: Expected O, but got Unknown
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Expected O, but got Unknown
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Expected O, but got Unknown
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Expected O, but got Unknown
//IL_023c: Expected O, but got Unknown
//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Expected O, but got Unknown
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
string text = null;
string text2;
if (mtp is TypeReference)
{
text2 = ((MemberReference)(TypeReference)mtp).FullName;
}
else if (mtp is MethodReference)
{
text2 = Extensions.GetID((MethodReference)mtp, (string)null, (string)null, true, false);
text = Extensions.GetID((MethodReference)mtp, (string)null, (string)null, true, true);
}
else if (mtp is FieldReference)
{
text2 = ((MemberReference)(FieldReference)mtp).FullName;
}
else
{
if (!(mtp is PropertyReference))
{
return null;
}
text2 = ((MemberReference)(PropertyReference)mtp).FullName;
}
if (RelinkMapCache.TryGetValue(text2, out var value))
{
return value;
}
if (relink && (RelinkMap.TryGetValue(text2, out var value2) || (text != null && RelinkMap.TryGetValue(text, out value2))))
{
if (value2 is IMetadataTokenProvider)
{
return RelinkMapCache[text2] = Extensions.ImportReference(Module, (IMetadataTokenProvider)value2);
}
if (value2 is RelinkMapEntry)
{
string type = ((RelinkMapEntry)value2).Type;
string findableID = ((RelinkMapEntry)value2).FindableID;
TypeReference obj = FindTypeDeep(type);
TypeDefinition val2 = ((obj != null) ? Extensions.SafeResolve(obj) : null);
if (val2 == null)
{
return RelinkMapCache[text2] = ResolveRelinkTarget(mtp, relink: false, relinkModule);
}
value2 = Extensions.FindMethod(val2, findableID, true) ?? ((object)Extensions.FindField(val2, findableID)) ?? ((object)(Extensions.FindProperty(val2, findableID) ?? null));
if (value2 == null)
{
if (Strict)
{
throw new RelinkTargetNotFoundException(string.Format("{0} ({1}, {2}) (remap: {3})", "MonoMod relinker failed finding", type, findableID, mtp), mtp, (IMetadataTokenProvider)null);
}
return null;
}
return RelinkMapCache[text2] = Extensions.ImportReference(Module, (IMetadataTokenProvider)value2);
}
if (value2 is string && mtp is TypeReference)
{
IMetadataTokenProvider val5 = (IMetadataTokenProvider)(object)FindTypeDeep((string)value2);
if (val5 == null)
{
if (Strict)
{
throw new RelinkTargetNotFoundException(string.Format("{0} {1} (remap: {2})", "MonoMod relinker failed finding", value2, mtp), mtp, (IMetadataTokenProvider)null);
}
return null;
}
value2 = Extensions.ImportReference(Module, ResolveRelinkTarget(val5, relink: false, relinkModule) ?? val5);
}
if (value2 is IMetadataTokenProvider)
{
Dictionary<string, IMetadataTokenProvider> relinkMapCache = RelinkMapCache;
string key = text2;
IMetadataTokenProvider val6 = (IMetadataTokenProvider)value2;
IMetadataTokenProvider result = val6;
relinkMapCache[key] = val6;
return result;
}
throw new InvalidOperationException($"MonoMod doesn't support RelinkMap value of type {value2.GetType()} (remap: {mtp})");
}
if (relinkModule && mtp is TypeReference)
{
if (RelinkModuleMapCache.TryGetValue(text2, out var value3))
{
return (IMetadataTokenProvider)(object)value3;
}
value3 = (TypeReference)mtp;
if (RelinkModuleMap.TryGetValue(value3.Scope.Name, out var value4))
{
TypeReference type2 = (TypeReference)(object)value4.GetType(((MemberReference)value3).FullName);
if (type2 == null)
{
if (Strict)
{
throw new RelinkTargetNotFoundException(string.Format("{0} {1} (remap: {2})", "MonoMod relinker failed finding", ((MemberReference)value3).FullName, mtp), mtp, (IMetadataTokenProvider)null);
}
return null;
}
return (IMetadataTokenProvider)(object)(RelinkModuleMapCache[text2] = Module.ImportReference(type2));
}
return (IMetadataTokenProvider)(object)Module.ImportReference(value3);
}
return null;
}
public virtual bool DefaultParser(MonoModder mod, MethodBody body, Instruction instr, ref int instri)
{
return true;
}
public virtual TypeReference FindType(string name)
{
return FindType(Module, name, new Stack<ModuleDefinition>()) ?? Module.GetType(name, false);
}
public virtual TypeReference FindType(string name, bool runtimeName)
{
return FindType(Module, name, new Stack<ModuleDefinition>()) ?? Module.GetType(name, runtimeName);
}
protected virtual TypeReference FindType(ModuleDefinition main, string fullName, Stack<ModuleDefinition> crawled)
{
TypeReference type;
if ((type = main.GetType(fullName, false)) != null)
{
return type;
}
if (fullName.StartsWith("<PrivateImplementationDetails>/"))
{
return null;
}
if (crawled.Contains(main))
{
return null;
}
crawled.Push(main);
foreach (ModuleDefinition item in DependencyMap[main])
{
if ((!RemovePatchReferences || !((AssemblyNameReference)item.Assembly.Name).Name.EndsWith(".mm")) && (type = FindType(item, fullName, crawled)) != null)
{
return type;
}
}
return null;
}
public virtual TypeReference FindTypeDeep(string name)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
TypeReference val = FindType(name, runtimeName: false);
if (val != null)
{
return val;
}
Stack<ModuleDefinition> crawled = new Stack<ModuleDefinition>();
val = null;
foreach (ModuleDefinition mod in Mods)
{
ModuleDefinition key = mod;
foreach (ModuleDefinition item in DependencyMap[key])
{
if ((val = FindType(item, name, crawled)) != null)
{
IMetadataScope scope = val.Scope;
AssemblyNameReference dllRef = (AssemblyNameReference)(object)((scope is AssemblyNameReference) ? scope : null);
if (dllRef != null && !((IEnumerable<AssemblyNameReference>)Module.AssemblyReferences).Any((AssemblyNameReference n) => n.Name == dllRef.Name))
{
Module.AssemblyReferences.Add(dllRef);
}
return Module.ImportReference(val);
}
}
}
return null;
}
public virtual void PrePatchModule(ModuleDefinition mod)
{
//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_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_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Expected O, but got Unknown
Enumerator<TypeDefinition> enumerator = mod.Types.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
TypeDefinition current = enumerator.Current;
PrePatchType(current);
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
Enumerator<ModuleReference> enumerator2 = mod.ModuleReferences.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
ModuleReference current2 = enumerator2.Current;
if (!Module.ModuleReferences.Contains(current2))
{
Module.ModuleReferences.Add(current2);
}
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
Enumerator<Resource> enumerator3 = mod.Resources.GetEnumerator();
try
{
while (enumerator3.MoveNext())
{
Resource current3 = enumerator3.Current;
if (current3 is EmbeddedResource)
{
Module.Resources.Add((Resource)new EmbeddedResource(current3.Name.StartsWith(((AssemblyNameReference)mod.Assembly.Name).Name) ? (((AssemblyNameReference)Module.Assembly.Name).Name + current3.Name.Substring(((AssemblyNameReference)mod.Assembly.Name).Name.Length)) : current3.Name, current3.Attributes, ((EmbeddedResource)current3).GetResourceData()));
}
}
}
finally
{
((IDisposable)enumerator3).Dispose();
}
}
public virtual void PrePatchType(TypeDefinition type, bool forceAdd = false)
{
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Expected O, but got Unknown
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Expected O, but got Unknown
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Expected O, but got Unknown
string patchFullName = Extensions.GetPatchFullName((MemberReference)(object)type);
if ((((TypeReference)type).Namespace != "MonoMod" && Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModIgnore")) || SkipList.Contains(patchFullName) || !MatchingConditionals((ICustomAttributeProvider)(object)type, Module) || (((MemberReference)type).FullName == "MonoMod.MonoModRules" && !forceAdd))
{
return;
}
TypeReference val = (forceAdd ? null : Module.GetType(patchFullName, false));
TypeDefinition val2 = ((val != null) ? Extensions.SafeResolve(val) : null);
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModReplace") || Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModRemove"))
{
if (val2 != null)
{
if (val2.DeclaringType == null)
{
Module.Types.Remove(val2);
}
else
{
val2.DeclaringType.NestedTypes.Remove(val2);
}
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModRemove"))
{
return;
}
}
else if (val != null)
{
PrePatchNested(type);
return;
}
LogVerbose("[PrePatchType] Adding " + patchFullName + " to the target module.");
TypeDefinition val3 = new TypeDefinition(((TypeReference)type).Namespace, ((MemberReference)type).Name, type.Attributes, type.BaseType);
Enumerator<GenericParameter> enumerator = ((TypeReference)type).GenericParameters.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
GenericParameter current = enumerator.Current;
((TypeReference)val3).GenericParameters.Add(Extensions.Clone(current));
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
Enumerator<InterfaceImplementation> enumerator2 = type.Interfaces.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
InterfaceImplementation current2 = enumerator2.Current;
val3.Interfaces.Add(current2);
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
val3.ClassSize = type.ClassSize;
if (type.DeclaringType != null)
{
val3.DeclaringType = Extensions.Relink((TypeReference)(object)type.DeclaringType, new Relinker(Relinker), (IGenericParameterProvider)(object)val3).Resolve();
val3.DeclaringType.NestedTypes.Add(val3);
}
else
{
Module.Types.Add(val3);
}
val3.PackingSize = type.PackingSize;
Extensions.AddRange<SecurityDeclaration>(val3.SecurityDeclarations, (IEnumerable<SecurityDeclaration>)type.SecurityDeclarations);
val3.CustomAttributes.Add(new CustomAttribute(GetMonoModAddedCtor()));
val = (TypeReference)(object)val3;
PrePatchNested(type);
}
protected virtual void PrePatchNested(TypeDefinition type)
{
for (int i = 0; i < type.NestedTypes.Count; i++)
{
PrePatchType(type.NestedTypes[i]);
}
}
public virtual void PatchModule(ModuleDefinition mod)
{
//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_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
Enumerator<TypeDefinition> enumerator = mod.Types.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
TypeDefinition current = enumerator.Current;
if ((((TypeReference)current).Namespace == "MonoMod" || ((TypeReference)current).Namespace.StartsWith("MonoMod.")) && ((MemberReference)current.BaseType).FullName == "System.Attribute")
{
PatchType(current);
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
enumerator = mod.Types.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
TypeDefinition current2 = enumerator.Current;
if ((!(((TypeReference)current2).Namespace == "MonoMod") && !((TypeReference)current2).Namespace.StartsWith("MonoMod.")) || !(((MemberReference)current2.BaseType).FullName == "System.Attribute"))
{
PatchType(current2);
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
public virtual void PatchType(TypeDefinition type)
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
string patchFullName = Extensions.GetPatchFullName((MemberReference)(object)type);
TypeReference type2 = Module.GetType(patchFullName, false);
if (type2 == null)
{
return;
}
TypeDefinition val = ((type2 != null) ? Extensions.SafeResolve(type2) : null);
Enumerator<CustomAttribute> enumerator;
if ((((TypeReference)type).Namespace != "MonoMod" && Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModIgnore")) || SkipList.Contains(patchFullName) || !MatchingConditionals((ICustomAttributeProvider)(object)type, Module))
{
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModIgnore") && val != null)
{
enumerator = type.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current = enumerator.Current;
if (CustomAttributeHandlers.ContainsKey(((MemberReference)current.AttributeType).FullName))
{
val.CustomAttributes.Add(Extensions.Clone(current));
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
PatchNested(type);
return;
}
if (patchFullName == ((MemberReference)type).FullName)
{
LogVerbose("[PatchType] Patching type " + patchFullName);
}
else
{
LogVerbose("[PatchType] Patching type " + patchFullName + " (prefixed: " + ((MemberReference)type).FullName + ")");
}
enumerator = type.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current2 = enumerator.Current;
if (!Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)val, ((MemberReference)current2.AttributeType).FullName))
{
val.CustomAttributes.Add(Extensions.Clone(current2));
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
HashSet<MethodDefinition> hashSet = new HashSet<MethodDefinition>();
Enumerator<PropertyDefinition> enumerator2 = type.Properties.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
PropertyDefinition current3 = enumerator2.Current;
PatchProperty(val, current3, hashSet);
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
HashSet<MethodDefinition> hashSet2 = new HashSet<MethodDefinition>();
Enumerator<EventDefinition> enumerator3 = type.Events.GetEnumerator();
try
{
while (enumerator3.MoveNext())
{
EventDefinition current4 = enumerator3.Current;
PatchEvent(val, current4, hashSet2);
}
}
finally
{
((IDisposable)enumerator3).Dispose();
}
Enumerator<MethodDefinition> enumerator4 = type.Methods.GetEnumerator();
try
{
while (enumerator4.MoveNext())
{
MethodDefinition current5 = enumerator4.Current;
if (!hashSet.Contains(current5) && !hashSet2.Contains(current5))
{
PatchMethod(val, current5);
}
}
}
finally
{
((IDisposable)enumerator4).Dispose();
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)type, "MonoMod.MonoModEnumReplace"))
{
int num = 0;
while (num < val.Fields.Count)
{
if (((MemberReference)val.Fields[num]).Name == "value__")
{
num++;
}
else
{
val.Fields.RemoveAt(num);
}
}
}
Enumerator<FieldDefinition> enumerator5 = type.Fields.GetEnumerator();
try
{
while (enumerator5.MoveNext())
{
FieldDefinition current6 = enumerator5.Current;
PatchField(val, current6);
}
}
finally
{
((IDisposable)enumerator5).Dispose();
}
PatchNested(type);
}
protected virtual void PatchNested(TypeDefinition type)
{
for (int i = 0; i < type.NestedTypes.Count; i++)
{
PatchType(type.NestedTypes[i]);
}
}
public virtual void PatchProperty(TypeDefinition targetType, PropertyDefinition prop, HashSet<MethodDefinition> propMethods = null)
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Expected O, but got Unknown
//IL_022b: Expected O, but got Unknown
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Expected O, but got Unknown
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Expected O, but got Unknown
//IL_02b5: Expected O, but got Unknown
//IL_0363: Unknown result type (might be due to invalid IL or missing references)
//IL_0368: Unknown result type (might be due to invalid IL or missing references)
if (!MatchingConditionals((ICustomAttributeProvider)(object)prop, Module))
{
return;
}
((MemberReference)prop).Name = Extensions.GetPatchName((MemberReference)(object)prop);
PropertyDefinition val = Extensions.FindProperty(targetType, ((MemberReference)prop).Name);
string text = "<" + ((MemberReference)prop).Name + ">__BackingField";
FieldDefinition val2 = Extensions.FindField(prop.DeclaringType, text);
FieldDefinition val3 = Extensions.FindField(targetType, text);
Enumerator<CustomAttribute> enumerator;
Enumerator<MethodDefinition> enumerator2;
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)prop, "MonoMod.MonoModIgnore"))
{
if (val != null)
{
enumerator = prop.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current = enumerator.Current;
if (CustomAttributeHandlers.ContainsKey(((MemberReference)current.AttributeType).FullName))
{
val.CustomAttributes.Add(Extensions.Clone(current));
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
if (val2 != null)
{
val2.DeclaringType.Fields.Remove(val2);
}
if (prop.GetMethod != null)
{
propMethods?.Add(prop.GetMethod);
}
if (prop.SetMethod != null)
{
propMethods?.Add(prop.SetMethod);
}
enumerator2 = prop.OtherMethods.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
MethodDefinition current2 = enumerator2.Current;
propMethods?.Add(current2);
}
return;
}
finally
{
((IDisposable)enumerator2).Dispose();
}
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)prop, "MonoMod.MonoModRemove") || Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)prop, "MonoMod.MonoModReplace"))
{
if (val != null)
{
targetType.Properties.Remove(val);
if (val3 != null)
{
targetType.Fields.Remove(val3);
}
if (val.GetMethod != null)
{
targetType.Methods.Remove(val.GetMethod);
}
if (val.SetMethod != null)
{
targetType.Methods.Remove(val.SetMethod);
}
enumerator2 = val.OtherMethods.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
MethodDefinition current3 = enumerator2.Current;
targetType.Methods.Remove(current3);
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)prop, "MonoMod.MonoModRemove"))
{
return;
}
}
if (val == null)
{
PropertyDefinition val4 = new PropertyDefinition(((MemberReference)prop).Name, prop.Attributes, ((PropertyReference)prop).PropertyType);
val = val4;
PropertyDefinition val5 = val4;
val5.CustomAttributes.Add(new CustomAttribute(GetMonoModAddedCtor()));
Enumerator<ParameterDefinition> enumerator3 = ((PropertyReference)prop).Parameters.GetEnumerator();
try
{
while (enumerator3.MoveNext())
{
ParameterDefinition current4 = enumerator3.Current;
((PropertyReference)val5).Parameters.Add(Extensions.Clone(current4));
}
}
finally
{
((IDisposable)enumerator3).Dispose();
}
val5.DeclaringType = targetType;
targetType.Properties.Add(val5);
if (val2 != null)
{
FieldDefinition val6 = new FieldDefinition(text, val2.Attributes, ((FieldReference)val2).FieldType);
val3 = val6;
FieldDefinition val7 = val6;
targetType.Fields.Add(val7);
}
}
enumerator = prop.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current5 = enumerator.Current;
val.CustomAttributes.Add(Extensions.Clone(current5));
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
MethodDefinition getMethod = prop.GetMethod;
MethodDefinition getMethod2;
if (getMethod != null && (getMethod2 = PatchMethod(targetType, getMethod)) != null)
{
val.GetMethod = getMethod2;
propMethods?.Add(getMethod);
}
MethodDefinition setMethod = prop.SetMethod;
if (setMethod != null && (getMethod2 = PatchMethod(targetType, setMethod)) != null)
{
val.SetMethod = getMethod2;
propMethods?.Add(setMethod);
}
enumerator2 = prop.OtherMethods.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
MethodDefinition current6 = enumerator2.Current;
if ((getMethod2 = PatchMethod(targetType, current6)) != null)
{
val.OtherMethods.Add(getMethod2);
propMethods?.Add(current6);
}
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
}
public virtual void PatchEvent(TypeDefinition targetType, EventDefinition srcEvent, HashSet<MethodDefinition> propMethods = null)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: 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_024e: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Expected O, but got Unknown
//IL_0252: Expected O, but got Unknown
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Expected O, but got Unknown
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Expected O, but got Unknown
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_036f: Unknown result type (might be due to invalid IL or missing references)
//IL_0374: Unknown result type (might be due to invalid IL or missing references)
((MemberReference)srcEvent).Name = Extensions.GetPatchName((MemberReference)(object)srcEvent);
EventDefinition val = Extensions.FindEvent(targetType, ((MemberReference)srcEvent).Name);
string text = "<" + ((MemberReference)srcEvent).Name + ">__BackingField";
FieldDefinition val2 = Extensions.FindField(srcEvent.DeclaringType, text);
FieldDefinition val3 = Extensions.FindField(targetType, text);
Enumerator<CustomAttribute> enumerator;
Enumerator<MethodDefinition> enumerator2;
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)srcEvent, "MonoMod.MonoModIgnore"))
{
if (val != null)
{
enumerator = srcEvent.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current = enumerator.Current;
if (CustomAttributeHandlers.ContainsKey(((MemberReference)current.AttributeType).FullName))
{
val.CustomAttributes.Add(Extensions.Clone(current));
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
if (val2 != null)
{
val2.DeclaringType.Fields.Remove(val2);
}
if (srcEvent.AddMethod != null)
{
propMethods?.Add(srcEvent.AddMethod);
}
if (srcEvent.RemoveMethod != null)
{
propMethods?.Add(srcEvent.RemoveMethod);
}
if (srcEvent.InvokeMethod != null)
{
propMethods?.Add(srcEvent.InvokeMethod);
}
enumerator2 = srcEvent.OtherMethods.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
MethodDefinition current2 = enumerator2.Current;
propMethods?.Add(current2);
}
return;
}
finally
{
((IDisposable)enumerator2).Dispose();
}
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)srcEvent, "MonoMod.MonoModRemove") || Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)srcEvent, "MonoMod.MonoModReplace"))
{
if (val != null)
{
targetType.Events.Remove(val);
if (val3 != null)
{
targetType.Fields.Remove(val3);
}
if (val.AddMethod != null)
{
targetType.Methods.Remove(val.AddMethod);
}
if (val.RemoveMethod != null)
{
targetType.Methods.Remove(val.RemoveMethod);
}
if (val.InvokeMethod != null)
{
targetType.Methods.Remove(val.InvokeMethod);
}
if (val.OtherMethods != null)
{
enumerator2 = val.OtherMethods.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
MethodDefinition current3 = enumerator2.Current;
targetType.Methods.Remove(current3);
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
}
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)srcEvent, "MonoMod.MonoModRemove"))
{
return;
}
}
if (val == null)
{
EventDefinition val4 = new EventDefinition(((MemberReference)srcEvent).Name, srcEvent.Attributes, ((EventReference)srcEvent).EventType);
val = val4;
EventDefinition val5 = val4;
val5.CustomAttributes.Add(new CustomAttribute(GetMonoModAddedCtor()));
val5.DeclaringType = targetType;
targetType.Events.Add(val5);
if (val2 != null)
{
FieldDefinition val6 = new FieldDefinition(text, val2.Attributes, ((FieldReference)val2).FieldType);
targetType.Fields.Add(val6);
}
}
enumerator = srcEvent.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current4 = enumerator.Current;
val.CustomAttributes.Add(Extensions.Clone(current4));
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
MethodDefinition addMethod = srcEvent.AddMethod;
MethodDefinition addMethod2;
if (addMethod != null && (addMethod2 = PatchMethod(targetType, addMethod)) != null)
{
val.AddMethod = addMethod2;
propMethods?.Add(addMethod);
}
MethodDefinition removeMethod = srcEvent.RemoveMethod;
if (removeMethod != null && (addMethod2 = PatchMethod(targetType, removeMethod)) != null)
{
val.RemoveMethod = addMethod2;
propMethods?.Add(removeMethod);
}
MethodDefinition invokeMethod = srcEvent.InvokeMethod;
if (invokeMethod != null && (addMethod2 = PatchMethod(targetType, invokeMethod)) != null)
{
val.InvokeMethod = addMethod2;
propMethods?.Add(invokeMethod);
}
enumerator2 = srcEvent.OtherMethods.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
MethodDefinition current5 = enumerator2.Current;
if ((addMethod2 = PatchMethod(targetType, current5)) != null)
{
val.OtherMethods.Add(addMethod2);
propMethods?.Add(current5);
}
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
}
public virtual void PatchField(TypeDefinition targetType, FieldDefinition field)
{
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Expected O, but got Unknown
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Expected O, but got Unknown
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
string patchFullName = Extensions.GetPatchFullName((MemberReference)(object)field.DeclaringType);
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)field, "MonoMod.MonoModNoNew") || SkipList.Contains(patchFullName + "::" + ((MemberReference)field).Name) || !MatchingConditionals((ICustomAttributeProvider)(object)field, Module))
{
return;
}
((MemberReference)field).Name = Extensions.GetPatchName((MemberReference)(object)field);
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)field, "MonoMod.MonoModRemove") || Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)field, "MonoMod.MonoModReplace"))
{
FieldDefinition val = Extensions.FindField(targetType, ((MemberReference)field).Name);
if (val != null)
{
targetType.Fields.Remove(val);
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)field, "MonoMod.MonoModRemove"))
{
return;
}
}
FieldDefinition val2 = Extensions.FindField(targetType, ((MemberReference)field).Name);
Enumerator<CustomAttribute> enumerator;
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)field, "MonoMod.MonoModIgnore") && val2 != null)
{
enumerator = field.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current = enumerator.Current;
if (CustomAttributeHandlers.ContainsKey(((MemberReference)current.AttributeType).FullName))
{
val2.CustomAttributes.Add(Extensions.Clone(current));
}
}
return;
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
if (val2 == null)
{
val2 = new FieldDefinition(((MemberReference)field).Name, field.Attributes, ((FieldReference)field).FieldType);
val2.CustomAttributes.Add(new CustomAttribute(GetMonoModAddedCtor()));
val2.InitialValue = field.InitialValue;
if (field.HasConstant)
{
val2.Constant = field.Constant;
}
targetType.Fields.Add(val2);
}
enumerator = field.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current2 = enumerator.Current;
val2.CustomAttributes.Add(Extensions.Clone(current2));
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
public virtual MethodDefinition PatchMethod(TypeDefinition targetType, MethodDefinition method)
{
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Unknown result type (might be due to invalid IL or missing references)
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_028f: Unknown result type (might be due to invalid IL or missing references)
//IL_049f: Unknown result type (might be due to invalid IL or missing references)
//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
//IL_04bb: Expected O, but got Unknown
//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0504: Unknown result type (might be due to invalid IL or missing references)
//IL_0511: Unknown result type (might be due to invalid IL or missing references)
//IL_0564: Unknown result type (might be due to invalid IL or missing references)
//IL_0569: Unknown result type (might be due to invalid IL or missing references)
//IL_0453: Unknown result type (might be due to invalid IL or missing references)
//IL_0458: Unknown result type (might be due to invalid IL or missing references)
//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
//IL_02d8: Expected O, but got Unknown
//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
//IL_0300: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_069a: Unknown result type (might be due to invalid IL or missing references)
//IL_06a1: Expected O, but got Unknown
//IL_06be: Unknown result type (might be due to invalid IL or missing references)
//IL_05ec: Unknown result type (might be due to invalid IL or missing references)
//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0630: Unknown result type (might be due to invalid IL or missing references)
//IL_0635: Unknown result type (might be due to invalid IL or missing references)
//IL_0676: Unknown result type (might be due to invalid IL or missing references)
//IL_0680: Expected O, but got Unknown
if (((MemberReference)method).Name.StartsWith("orig_") || Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)method, "MonoMod.MonoModOriginal"))
{
return null;
}
if (!AllowedSpecialName(method, targetType) || !MatchingConditionals((ICustomAttributeProvider)(object)method, Module))
{
return null;
}
string patchFullName = Extensions.GetPatchFullName((MemberReference)(object)targetType);
if (SkipList.Contains(Extensions.GetID((MethodReference)(object)method, (string)null, patchFullName, true, false)))
{
return null;
}
((MemberReference)method).Name = Extensions.GetPatchName((MemberReference)(object)method);
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)method, "MonoMod.MonoModConstructor"))
{
if (!method.IsSpecialName && !Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)method, "MonoMod.MonoModOriginalName"))
{
CustomAttribute val = new CustomAttribute(GetMonoModOriginalNameCtor());
val.ConstructorArguments.Add(new CustomAttributeArgument(Module.TypeSystem.String, (object)("orig_" + ((MemberReference)method).Name)));
method.CustomAttributes.Add(val);
}
((MemberReference)method).Name = (method.IsStatic ? ".cctor" : ".ctor");
method.IsSpecialName = true;
method.IsRuntimeSpecialName = true;
}
MethodDefinition val2 = Extensions.FindMethod(targetType, Extensions.GetID((MethodReference)(object)method, (string)null, patchFullName, true, false), true);
MethodDefinition obj = method;
string text = patchFullName;
MethodDefinition val3 = Extensions.FindMethod(targetType, Extensions.GetID((MethodReference)(object)obj, method.GetOriginalName(), text, true, false), true);
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)method, "MonoMod.MonoModIgnore"))
{
if (val2 != null)
{
Enumerator<CustomAttribute> enumerator = method.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current = enumerator.Current;
if (CustomAttributeHandlers.ContainsKey(((MemberReference)current.AttributeType).FullName) || CustomMethodAttributeHandlers.ContainsKey(((MemberReference)current.AttributeType).FullName))
{
val2.CustomAttributes.Add(Extensions.Clone(current));
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
return null;
}
if (val2 == null && Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)method, "MonoMod.MonoModNoNew"))
{
return null;
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)method, "MonoMod.MonoModRemove"))
{
if (val2 != null)
{
targetType.Methods.Remove(val2);
}
return null;
}
if (Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)method, "MonoMod.MonoModReplace"))
{
if (val2 != null)
{
val2.CustomAttributes.Clear();
val2.Attributes = method.Attributes;
val2.IsPInvokeImpl = method.IsPInvokeImpl;
val2.ImplAttributes = method.ImplAttributes;
}
}
else if (val2 != null && val3 == null)
{
val3 = Extensions.Clone(val2, (MethodDefinition)null);
((MemberReference)val3).Name = method.GetOriginalName();
val3.Attributes = (MethodAttributes)(val2.Attributes & 0xF7FF & 0xEFFF);
((MemberReference)val3).MetadataToken = GetMetadataToken((TokenType)100663296);
val3.IsVirtual = false;
val3.Overrides.Clear();
Enumerator<MethodReference> enumerator2 = method.Overrides.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
MethodReference current2 = enumerator2.Current;
val3.Overrides.Add(current2);
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
val3.CustomAttributes.Add(new CustomAttribute(GetMonoModOriginalCtor()));
MethodDefinition val4 = Extensions.FindMethod(method.DeclaringType, Extensions.GetID((MethodReference)(object)method, method.GetOriginalName(), (string)null, true, false), true);
if (val4 != null)
{
Enumerator<CustomAttribute> enumerator = val4.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current3 = enumerator.Current;
if (CustomAttributeHandlers.ContainsKey(((MemberReference)current3.AttributeType).FullName) || CustomMethodAttributeHandlers.ContainsKey(((MemberReference)current3.AttributeType).FullName))
{
val3.CustomAttributes.Add(Extensions.Clone(current3));
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
targetType.Methods.Add(val3);
}
if (val3 != null && method.IsConstructor && method.IsStatic && method.HasBody && !Extensions.HasCustomAttribute((ICustomAttributeProvider)(object)method, "MonoMod.MonoModConstructor"))
{
Collection<Instruction> instructions = method.Body.Instructions;
ILProcessor iLProcessor = method.Body.GetILProcessor();
iLProcessor.InsertBefore(instructions[instructions.Count - 1], iLProcessor.Create(OpCodes.Call, (MethodReference)(object)val3));
}
if (val2 != null)
{
val2.Body = Extensions.Clone(method.Body, val2);
val2.IsManaged = method.IsManaged;
val2.IsIL = method.IsIL;
val2.IsNative = method.IsNative;
val2.PInvokeInfo = method.PInvokeInfo;
val2.IsPreserveSig = method.IsPreserveSig;
val2.IsInternalCall = method.IsInternalCall;
val2.IsPInvokeImpl = method.IsPInvokeImpl;
Enumerator<CustomAttribute> enumerator = method.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current4 = enumerator.Current;
val2.CustomAttributes.Add(Extensions.Clone(current4));
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
method = val2;
}
else
{
MethodDefinition val5 = new MethodDefinition(((MemberReference)method).Name, method.Attributes, Module.TypeSystem.Void);
((MemberReference)val5).MetadataToken = GetMetadataToken((TokenType)100663296);
((MethodReference)val5).CallingConvention = ((MethodReference)method).CallingConvention;
((MethodReference)val5).ExplicitThis = ((MethodReference)method).ExplicitThis;
((MethodReference)val5).MethodReturnType = ((MethodReference)method).MethodReturnType;
val5.Attributes = method.Attributes;
val5.ImplAttributes = method.ImplAttributes;
val5.SemanticsAttributes = method.SemanticsAttributes;
val5.DeclaringType = targetType;
((MethodReference)val5).ReturnType = ((MethodReference)method).ReturnType;
val5.Body = Extensions.Clone(method.Body, val5);
val5.PInvokeInfo = method.PInvokeInfo;
val5.IsPInvokeImpl = method.IsPInvokeImpl;
Enumerator<GenericParameter> enumerator3 = ((MethodReference)method).GenericParameters.GetEnumerator();
try
{
while (enumerator3.MoveNext())
{
GenericParameter current5 = enumerator3.Current;
((MethodReference)val5).GenericParameters.Add(Extensions.Clone(current5));
}
}
finally
{
((IDisposable)enumerator3).Dispose();
}
Enumerator<ParameterDefinition> enumerator4 = ((MethodReference)method).Parameters.GetEnumerator();
try
{
while (enumerator4.MoveNext())
{
ParameterDefinition current6 = enumerator4.Current;
((MethodReference)val5).Parameters.Add(Extensions.Clone(current6));
}
}
finally
{
((IDisposable)enumerator4).Dispose();
}
Enumerator<CustomAttribute> enumerator = method.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current7 = enumerator.Current;
val5.CustomAttributes.Add(Extensions.Clone(current7));
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
Enumerator<MethodReference> enumerator2 = method.Overrides.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
MethodReference current8 = enumerator2.Current;
val5.Overrides.Add(current8);
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
val5.CustomAttributes.Add(new CustomAttribute(GetMonoModAddedCtor()));
targetType.Methods.Add(val5);
method = val5;
}
if (val3 != null)
{
CustomAttribute val6 = new CustomAttribute(GetMonoModOriginalNameCtor());
val6.ConstructorArguments.Add(new CustomAttributeArgument(Module.TypeSystem.String, (object)((MemberReference)val3).Name));
method.CustomAttributes.Add(val6);
}
return method;
}
public virtual void PatchRefs()
{
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
if (!UpgradeMSCORLIB.HasValue)
{
Version fckUnity = new Version(2, 0, 5, 0);
UpgradeMSCORLIB = ((IEnumerable<AssemblyNameReference>)Module.AssemblyReferences).Any((AssemblyNameReference x) => x.Version == fckUnity);
}
if (UpgradeMSCORLIB.Value)
{
List<AssemblyNameReference> list = new List<AssemblyNameReference>();
for (int i = 0; i < Module.AssemblyReferences.Count; i++)
{
AssemblyNameReference val = Module.AssemblyReferences[i];
if (val.Name == "mscorlib")
{
list.Add(val);
}
}
if (list.Count > 1)
{
AssemblyNameReference val2 = list.OrderByDescending((AssemblyNameReference x) => x.Version).First();
if (DependencyCache.TryGetValue(val2.FullName, out var value))
{
for (int j = 0; j < Module.AssemblyReferences.Count; j++)
{
AssemblyNameReference val3 = Module.AssemblyReferences[j];
if (val3.Name == "mscorlib" && val2.Version > val3.Version)
{
LogVerbose("[PatchRefs] Removing and relinking duplicate mscorlib: " + val3.Version);
RelinkModuleMap[val3.FullName] = value;
Module.AssemblyReferences.RemoveAt(j);
j--;
}
}
}
}
}
Enumerator<TypeDefinition> enumerator = Module.Types.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
TypeDefinition current = enumerator.Current;
PatchRefsInType(current);
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
public virtual void PatchRefs(ModuleDefinition mod)
{
//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)
Enumerator<TypeDefinition> enumerator = mod.Types.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
TypeDefinition current = enumerator.Current;
PatchRefsInType(current);
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
public virtual void PatchRefsInType(TypeDefinition type)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Expected O, but got Unknown
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Expected O, but got Unknown
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: 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_00dc: Expected O, but got Unknown
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Expected O, but got Unknown
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Expected O, but got Unknown
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Expected O, but got Unknown
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Expected O, but got Unknown
//IL_02da: Unknown result type (might be due to invalid IL or missing references)
//IL_02df: Unknown result type (might be due to invalid IL or missing references)
//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0308: Expected O, but got Unknown
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_033c: Expected O, but got Unknown
LogVerbose($"[VERBOSE] [PatchRefsInType] Patching refs in {type}");
if (type.BaseType != null)
{
type.BaseType = Extensions.Relink(type.BaseType, new Relinker(Relinker), (IGenericParameterProvider)(object)type);
}
for (int i = 0; i < ((TypeReference)type).GenericParameters.Count; i++)
{
((TypeReference)type).GenericParameters[i] = Extensions.Relink(((TypeReference)type).GenericParameters[i], new Relinker(Relinker), (IGenericParameterProvider)(object)type);
}
for (int j = 0; j < type.Interfaces.Count; j++)
{
InterfaceImplementation obj = type.Interfaces[j];
InterfaceImplementation val = new InterfaceImplementation(Extensions.Relink(obj.InterfaceType, new Relinker(Relinker), (IGenericParameterProvider)(object)type));
Enumerator<CustomAttribute> enumerator = obj.CustomAttributes.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
CustomAttribute current = enumerator.Current;
val.CustomAttributes.Add(Extensions.Relink(current, new Relinker(Relinker), (IGenericParameterProvider)(object)type));
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
type.Interfaces[j] = val;
}
for (int k = 0; k < type.CustomAttributes.Count; k++)
{
type.CustomAttributes[k] = Extensions.Relink(type.CustomAttributes[k], new Relinker(Relinker), (IGenericParameterProvider)(object)type);
}
Enumerator<PropertyDefinition> enumerator2 = type.Properties.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
PropertyDefinition current2 = enumerator2.Current;
((PropertyReference)current2).PropertyType = Extensions.Relink(((PropertyReference)current2).PropertyType, new Relinker(Relinker), (IGenericParameterProvider)(object)type);
for (int l = 0; l < current2.CustomAttributes.Count; l++)
{
current2.CustomAttributes[l] = Extensions.Relink(current2.CustomAttributes[l], new Relinker(Relinker), (IGenericParameterProvider)(object)type);
}
}
}
finally
{
((IDisposable)enumerator2).Dispose();
}
Enumerator<EventDefinition> enumerator3 = type.Events.GetEnumerator();
try
{
while (enumerator3.MoveNext())
{
EventDefinition current3 = enumerator3.Current;
((EventReference)current3).EventType = Extensions.Relink(((EventReference)current3).EventType, new Relinker(Relinker), (IGenericParameterProvider)(object)type);
for (int m = 0; m < current3.CustomAttributes.Count; m++)
{
current3.CustomAttributes[m] = Extensions.Relink(current3.CustomAttributes[m], new Relinker(Relinker), (IGenericParameterProvider)(object)type);
}
}
}
finally
{
((IDisposable)enumerator3).Dispose();
}
Enumerator<MethodDefinition> enumerator4 = type.Methods.GetEnumerator();
try
{
while (enumerator4.MoveNext())
{
MethodDefinition current4 = enumerator4.Current;
PatchRefsInMethod(current4);
}
}
finally
{
((IDisposable)enumerator4).Dispose();
}
Enumerator<FieldDefinition> enumerator5 = type.Fields.GetEnumerator();
try
{
while (enumerator5.MoveNext())
{
FieldDefinition current5 = enumerator5.Current;
((FieldReference)current5).FieldType = Extensions.Relink(((FieldReference)current5).FieldType, new Relinker(Relinker), (IGenericParameterProvider)(object)type);
for (int n = 0; n < current5.CustomAttributes.Count; n++)
{
current5.CustomAttributes[n] = Extensions.Relink(current5.CustomAttributes[n], new Relinker(Relinker), (IGenericParameterProvider)(object)type);
}
}
}
finally
{
((IDisposable)enumerator5).Dispose();
}
for (int num = 0; num < type.NestedTypes.Count; num++)
{
PatchRefsInType(type.NestedTypes[num]);
}
}
public virtual void PatchRefsInMethod(MethodDefinition method)
{
//IL_0030: Unknown result t