/// <summary> /// Constructs an instance of <see cref="Mod" />. /// </summary> /// <param name="data">All of the information that the mod needs to initialize its own metadata properties.</param> protected Mod(ModLoadInfo data) { Id = data.Id; Metadata = data.Metadata; Version = data.Version; Logs = new LogProvider(this); }
static void LoadModAssemblyUnsafe(Assembly assembly) { Logger.AtlasDebug(nameof(CoreModule), $"Loading assembly {assembly}"); var mainAttribute = assembly.GetCustomAttribute <ModDefineAttribute>(); if (mainAttribute is null) { throw new ArgumentException($"{assembly.GetName().Name} doesn't implement the mod attribute", nameof(ModDefineAttribute)); } var modType = mainAttribute.EntryPoint; if (modType is null) { throw new ArgumentNullException($"{assembly.GetName().Name} doesn't implement entry point", nameof(ModDefineAttribute.EntryPoint)); } // why? // this way can resolve missing dependencies else if (modType.BaseType != typeof(Mod)) { throw new ArgumentException($"{modType.Name} not a basic type of {nameof(Mod)}"); } ModLoadInfo loadInfo = new ModLoadInfo(mainAttribute.Id, assembly.GetName().Version.ToString(), modType.GetCustomAttribute <MetadataAttribute>() ?? new MetadataAttribute()); var ctor = modType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null, new[] { typeof(ModLoadInfo) }, null); if (ctor is null) { throw new ArgumentException("Standard constructor not found."); } Mod?mod; try { mod = ctor.Invoke(new object[] { loadInfo }) as Mod; } catch (Exception e) { throw new TargetInvocationException("Unhandled exception during construction.", e); } LoadMod(mod !); Logger.AtlasDebug(nameof(CoreModule), $"Loaded {assembly}."); }
/// <summary> /// Constructs an instance of <see cref="ModPreloadInfo" />. /// </summary> /// <param name="type">The type of the mod.</param> /// <param name="loadInfo">The load info that would be used.</param> /// <exception cref="ArgumentNullException"><paramref name="type" /> is <see langword="null"/>.</exception> public ModPreloadInfo(Type type, ModLoadInfo loadInfo) { Type = type ?? throw new ArgumentNullException(nameof(type)); LoadInfo = loadInfo; }