private IEnumerable <System.Reflection.Assembly> GetAssembly() { var assemblies = new List <System.Reflection.Assembly>(); BaseDirectory.Create(); if (BaseDirectory.Exists()) { var files = BaseDirectory.GetFiles("*.dll"); foreach (var file in files) { assemblies.Add(CustomAssembly.LoadFile(file.FullName)); } return(assemblies); } else { throw new DirectoryException($"BaseDirectory from path \"{BaseDirectory}\" is not exist"); } }
private void LoadCustomAssembly(string dll) { string dllPath = dll; try { dllPath = Path.Combine(SaveGameModPath, dll).NormalizePath(); Log?.Invoke($"CustomAssemblyLoad: {dll} ({dllPath})", LogLevel.Message); var loadedAssembly = Assembly.LoadFile(dllPath); CustomAssembly current = null; CustomAssemblies.AddOrUpdate(dllPath, current = new CustomAssembly() { FullAssemblyDllName = dllPath, LoadedAssembly = loadedAssembly }, (d, a) => { current = a; a.LoadedAssembly = loadedAssembly; return(a); }); } catch (Exception error) { Log?.Invoke($"CustomAssemblyLoad: {dll} ({dllPath}) -> {error}", LogLevel.Error); } }
static CustomizationApi() { CustomAssembly = Assembly.GetEntryAssembly(); CUSTOM_NAMESPACE = (from t in CustomAssembly.GetExportedTypes() where t.Name == CUSTOM_BOT_CLASS_NAME select t.Namespace).FirstOrDefault(); if (CUSTOM_NAMESPACE == null) { LogMessage.Exit("Could not find class " + CUSTOM_BOT_CLASS_NAME + " in the entry assembly."); } bot_type = CustomAssembly.GetType(CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME); if (bot_type == null) { LogMessage.Exit("Could not find class " + CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME + " in the entry assembly."); } try { session_creating = (Action)Delegate.CreateDelegate(typeof(Action), bot_type.GetMethod("SessionCreating", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static)); } catch { Log.Main.Warning("Method " + CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME + ".SessionCreating was not found."); } try { session_closing = (Action)Delegate.CreateDelegate(typeof(Action), bot_type.GetMethod("SessionClosing", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static)); } catch { Log.Main.Warning("Method " + CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME + ".SessionClosing was not found."); } try { fill_start_input_item_queue = (Action <InputItemQueue, Type>)Delegate.CreateDelegate(typeof(Action <InputItemQueue, Type>), bot_type.GetMethod("FillStartInputItemQueue", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static)); } catch { Log.Main.Warning("Method " + CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME + ".FillStartInputItemQueue was not found."); } }