/// <summary> /// Loads and assembly into the current AppDomain. /// </summary> /// <typeparam name="T">The type of the entry point to search for.</typeparam> /// <param name="assembly">Byte array of the assembly.</param> /// <param name="symbols">Optional byte array of the debug symbols.</param> public static void LoadGameAssembly <T>(byte[] assembly, byte[] symbols = null) where T : GameShared { // TODO: Re-enable type check when it's not just a giant pain in the butt. // It slows down development too much and we need other things like System.Type fixed // before it can reasonably be re-enabled. AssemblyTypeChecker.DisableTypeCheck = true; AssemblyTypeChecker.DumpTypes = true; if (!AssemblyTypeChecker.CheckAssembly(assembly)) { return; } var mod = new ModInfo(); mod.GameAssembly = symbols != null ? AppDomain.CurrentDomain.Load(assembly, symbols) : AppDomain.CurrentDomain.Load(assembly); IoCManager.Resolve <IReflectionManager>().LoadAssemblies(mod.GameAssembly); var entryPoints = mod.GameAssembly.GetTypes().Where(t => typeof(T).IsAssignableFrom(t)).ToArray(); if (entryPoints.Length == 0) { Logger.Warning($"[RES] Assembly has no entry points: {mod.GameAssembly.FullName}"); } foreach (var entryPoint in entryPoints) { mod.EntryPoints.Add(Activator.CreateInstance(entryPoint) as T); } _mods.Add(mod); }
/// <summary> /// Loads and assembly into the current AppDomain. /// </summary> /// <typeparam name="T">The type of the entry point to search for.</typeparam> /// <param name="assembly">Byte array of the assembly.</param> /// <param name="symbols">Optional byte array of the debug symbols.</param> public static void LoadGameAssembly <T>(byte[] assembly, byte[] symbols = null) where T : GameShared { AssemblyTypeChecker.DisableTypeCheck = false; AssemblyTypeChecker.DumpTypes = true; if (!AssemblyTypeChecker.CheckAssembly(assembly)) { return; } var mod = new ModInfo(); mod.GameAssembly = symbols != null ? AppDomain.CurrentDomain.Load(assembly, symbols) : AppDomain.CurrentDomain.Load(assembly); IoCManager.Resolve <IReflectionManager>().LoadAssemblies(mod.GameAssembly); var entryPoints = mod.GameAssembly.GetTypes().Where(t => typeof(T).IsAssignableFrom(t)).ToArray(); if (entryPoints.Length == 0) { Logger.Warning($"[RES] Assembly has no entry points: {mod.GameAssembly.FullName}"); } foreach (var entryPoint in entryPoints) { mod.EntryPoints.Add(Activator.CreateInstance(entryPoint) as T); } _mods.Add(mod); }