示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginManager"/> class.
        /// </summary>
        /// <param name="dalamud">The <see cref="Dalamud"/> instance to load plugins with.</param>
        /// <param name="pluginDirectory">The directory for regular plugins.</param>
        /// <param name="devPluginDirectory">The directory for dev plugins.</param>
        public PluginManager(Dalamud dalamud, string pluginDirectory, string devPluginDirectory)
        {
            this.dalamud            = dalamud;
            this.pluginDirectory    = pluginDirectory;
            this.devPluginDirectory = devPluginDirectory;

            this.Plugins =
                new List <(IDalamudPlugin Plugin, PluginDefinition Definition, DalamudPluginInterface PluginInterface,
                           bool IsRaw)>();
            this.IpcSubscriptions = new List <(string SourcePluginName, string SubPluginName, Action <ExpandoObject> SubAction)>();

            this.pluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(dalamud.StartInfo.ConfigurationPath), "pluginConfigs"));

            this.bannedPlugins = JsonConvert.DeserializeObject <List <BannedPlugin> >(
                File.ReadAllText(Path.Combine(this.dalamud.StartInfo.AssetDirectory, "UIRes", "bannedplugin.json")));

            // Try to load missing assemblies from the local directory of the requesting assembly
            // This would usually be implicit when using Assembly.Load(), but Assembly.LoadFile() doesn't do it...
            // This handler should only be invoked on things that fail regular lookups, but it *is* global to this appdomain
            AppDomain.CurrentDomain.AssemblyResolve += (object source, ResolveEventArgs e) =>
            {
                try
                {
                    Log.Debug($"Resolving missing assembly {e.Name}");

                    // This looks weird but I'm pretty sure it's actually correct.  Pretty sure.  Probably.
                    var assemblyPath = Path.Combine(
                        Path.GetDirectoryName(e.RequestingAssembly.Location),
                        new AssemblyName(e.Name).Name + ".dll");

                    if (!File.Exists(assemblyPath))
                    {
                        Log.Error($"Assembly not found at {assemblyPath}");
                        return(null);
                    }

                    return(Assembly.LoadFrom(assemblyPath));
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Could not load assembly " + e.Name);
                    return(null);
                }
            };
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DalamudPluginInterface"/> class.
        /// Set up the interface and populate all fields needed.
        /// </summary>
        /// <param name="dalamud">The dalamud instance to expose.</param>
        /// <param name="pluginName">The internal name of the plugin.</param>
        /// <param name="configs">The plugin configurations handler.</param>
        /// <param name="reason">The reason this plugin was loaded.</param>
        internal DalamudPluginInterface(Dalamud dalamud, string pluginName, PluginConfigurations configs, PluginLoadReason reason)
        {
            this.Reason              = reason;
            this.CommandManager      = dalamud.CommandManager;
            this.Framework           = dalamud.Framework;
            this.ClientState         = dalamud.ClientState;
            this.UiBuilder           = new UiBuilder(dalamud, pluginName);
            this.TargetModuleScanner = dalamud.SigScanner;
            this.Data            = dalamud.Data;
            this.SeStringManager = dalamud.SeStringManager;

            this.dalamud    = dalamud;
            this.pluginName = pluginName;
            this.configs    = configs;

            this.Sanitizer  = new Sanitizer(this.Data.Language);
            this.UiLanguage = this.dalamud.Configuration.LanguageOverride;
            dalamud.LocalizationManager.OnLocalizationChanged += this.OnLocalizationChanged;
        }
示例#3
0
    /// <summary>
    /// Initializes a new instance of the <see cref="DalamudPluginInterface"/> class.
    /// Set up the interface and populate all fields needed.
    /// </summary>
    /// <param name="pluginName">The internal name of the plugin.</param>
    /// <param name="assemblyLocation">Location of the assembly.</param>
    /// <param name="reason">The reason the plugin was loaded.</param>
    /// <param name="isDev">A value indicating whether this is a dev plugin.</param>
    internal DalamudPluginInterface(string pluginName, FileInfo assemblyLocation, PluginLoadReason reason, bool isDev)
    {
        var configuration = Service <DalamudConfiguration> .Get();

        var dataManager = Service <DataManager> .Get();

        var localization = Service <Localization> .Get();

        this.UiBuilder = new UiBuilder(pluginName);

        this.pluginName       = pluginName;
        this.AssemblyLocation = assemblyLocation;
        this.configs          = Service <PluginManager> .Get().PluginConfigs;

        this.Reason = reason;
        this.IsDev  = isDev;

        this.LoadTime    = DateTime.Now;
        this.LoadTimeUTC = DateTime.UtcNow;

        this.GeneralChatType = configuration.GeneralChatType;
        this.Sanitizer       = new Sanitizer(dataManager.Language);
        if (configuration.LanguageOverride != null)
        {
            this.UiLanguage = configuration.LanguageOverride;
        }
        else
        {
            var currentUiLang = CultureInfo.CurrentUICulture;
            if (Localization.ApplicableLangCodes.Any(langCode => currentUiLang.TwoLetterISOLanguageName == langCode))
            {
                this.UiLanguage = currentUiLang.TwoLetterISOLanguageName;
            }
            else
            {
                this.UiLanguage = "en";
            }
        }

        localization.LocalizationChanged        += this.OnLocalizationChanged;
        configuration.DalamudConfigurationSaved += this.OnDalamudConfigurationSaved;
    }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DalamudPluginInterface"/> class.
        /// Set up the interface and populate all fields needed.
        /// </summary>
        /// <param name="dalamud">The dalamud instance to expose.</param>
        /// <param name="pluginName">The internal name of the plugin.</param>
        /// <param name="assemblyLocation">The equivalent of what Assembly.GetExecutingAssembly().Location should return.</param>
        /// <param name="reason">The reason the plugin was loaded.</param>
        internal DalamudPluginInterface(Dalamud dalamud, string pluginName, string assemblyLocation, PluginLoadReason reason)
        {
            this.CommandManager      = dalamud.CommandManager;
            this.Framework           = dalamud.Framework;
            this.ClientState         = dalamud.ClientState;
            this.UiBuilder           = new UiBuilder(dalamud, pluginName);
            this.TargetModuleScanner = dalamud.SigScanner;
            this.Data            = dalamud.Data;
            this.SeStringManager = dalamud.SeStringManager;

            this.dalamud          = dalamud;
            this.pluginName       = pluginName;
            this.configs          = dalamud.PluginManager.PluginConfigs;
            this.AssemblyLocation = assemblyLocation;
            this.Reason           = reason;

            this.GeneralChatType = this.dalamud.Configuration.GeneralChatType;
            this.Sanitizer       = new Sanitizer(this.Data.Language);
            if (this.dalamud.Configuration.LanguageOverride != null)
            {
                this.UiLanguage = this.dalamud.Configuration.LanguageOverride;
            }
            else
            {
                var currentUiLang = CultureInfo.CurrentUICulture;
                if (Localization.ApplicableLangCodes.Any(langCode => currentUiLang.TwoLetterISOLanguageName == langCode))
                {
                    this.UiLanguage = currentUiLang.TwoLetterISOLanguageName;
                }
                else
                {
                    this.UiLanguage = "en";
                }
            }

            dalamud.LocalizationManager.OnLocalizationChanged += this.OnLocalizationChanged;
            dalamud.Configuration.OnDalamudConfigurationSaved += this.OnDalamudConfigurationSaved;
        }