Esempio n. 1
0
    /// <summary>
    /// Loads a collection of mods with their associated dependencies.
    /// </summary>
    private void LoadModsWithDependencies(IEnumerable <ModConfig> modsToLoad, List <PathTuple <ModConfig> > allMods = null)
    {
        // Cache configuration paths for all mods.
        if (allMods == null)
        {
            allMods = ModConfig.GetAllMods(LoaderConfig.GetModConfigDirectory());
        }

        var configToPathDictionary = new Dictionary <ModConfig, string>();

        foreach (var mod in allMods)
        {
            configToPathDictionary[mod.Config] = mod.Path;
        }

        // Get dependencies, sort and load in order.
        var dependenciesToLoad  = GetDependenciesForMods(modsToLoad, allMods.Select(x => x.Config), LoaderConfig.GetModConfigDirectory());
        var allUniqueModsToLoad = modsToLoad.Concat(dependenciesToLoad).Distinct();
        var allSortedModsToLoad = ModConfig.SortMods(allUniqueModsToLoad);

        var modPaths = new List <PathTuple <ModConfig> >();

        foreach (var modToLoad in allSortedModsToLoad)
        {
            // Reloaded does not allow loading same mod multiple times.
            if (!Manager.IsModLoaded(modToLoad.ModId))
            {
                modPaths.Add(new PathTuple <ModConfig>(configToPathDictionary[modToLoad], modToLoad));
            }
        }

        Manager.LoadMods(modPaths);
    }
Esempio n. 2
0
    /// <summary>
    /// Creates the service instance given an instance of the configuration.
    /// </summary>
    /// <param name="config">Mod loader config.</param>
    /// <param name="context">Context to which background events should be synchronized.</param>
    public ModConfigService(LoaderConfig config, SynchronizationContext context = null)
    {
        this.OnAddItem    += OnAddItemHandler;
        this.OnRemoveItem += OnRemoveItemHandler;

        Initialize(config.GetModConfigDirectory(), ModConfig.ConfigFileName, GetAllConfigs, context, true);
        SetItemsById();
    }
Esempio n. 3
0
    /// <summary>
    /// Sets the Reloaded Mod Loader DLL paths for a launcher config.
    /// </summary>
    private static void SetLoaderPaths(LoaderConfig config, string launcherDirectory)
    {
        if (String.IsNullOrEmpty(launcherDirectory))
        {
            throw new DllNotFoundException("The provided launcher directory is null or empty. This is a bug. Report this to the developer.");
        }

        config.UpdatePaths(launcherDirectory, Resources.ErrorLoaderNotFound.Get());

        // Update Environment Variables
        Task.Run(() => Environment.SetEnvironmentVariable("RELOADEDIIMODS", config.GetModConfigDirectory(), EnvironmentVariableTarget.User));
    }
Esempio n. 4
0
    /// <summary>
    /// Gets a list of all mods from filesystem and returns a mod with a matching ModId.
    /// </summary>
    /// <param name="modId">The modId to find.</param>
    /// <param name="allMods">List of all mod configurations, read during the operation.</param>
    /// <exception cref="ReloadedException">A mod to load has not been found.</exception>
    public PathTuple <ModConfig> FindMod(string modId, out List <PathTuple <ModConfig> > allMods)
    {
        // Get mod with ID
        allMods = ModConfig.GetAllMods(LoaderConfig.GetModConfigDirectory());
        var mod = allMods.FirstOrDefault(x => x.Config.ModId == modId);

        if (mod != null)
        {
            var dllPath = mod.Config.GetDllPath(mod.Path);
            return(new PathTuple <ModConfig>(dllPath, mod.Config));
        }

        throw new ReloadedException(Errors.ModToLoadNotFound(modId));
    }
Esempio n. 5
0
    /// <summary>
    /// Retrieves all of the dependencies for a given set of mods.
    /// </summary>
    /// <exception cref="FileNotFoundException">A dependency for any of the mods has not been found.</exception>
    private HashSet <ModConfig> GetDependenciesForMods(IEnumerable <ModConfig> mods, IEnumerable <ModConfig> allMods, string modDirectory)
    {
        if (allMods == null)
        {
            allMods = ModConfig.GetAllMods(LoaderConfig.GetModConfigDirectory()).Select(x => x.Config);
        }

        var dependencies = ModConfig.GetDependencies(mods, allMods, modDirectory);

        if (dependencies.MissingConfigurations.Count > 0 && !IsTesting)
        {
            string missingMods = String.Join(",", dependencies.MissingConfigurations);
            throw new FileNotFoundException($"Reloaded II was unable to find all dependencies for the mod(s) to be loaded.\n" +
                                            $"Aborting load.\n" +
                                            $"Missing dependencies: {missingMods}");
        }

        return(dependencies.Configurations);
    }
Esempio n. 6
0
    /// <summary>
    /// Loads all mods directly into the process.
    /// </summary>
    public void LoadForAppConfig(IApplicationConfig applicationConfig)
    {
        Wrappers.ThrowIfENotEqual(IsLoaded, false, Errors.ModLoaderAlreadyInitialized);
        Application = applicationConfig;

        // Get all mods and their paths.
        var allModsForApplication = ApplicationConfig.GetAllMods(Application, out var allMods, LoaderConfig.GetModConfigDirectory());

        // Get list of mods to load and load them.
        var modsToLoad = allModsForApplication.Where(x => x.Enabled).Select(x => x.Generic.Config);

        LoadModsWithDependencies(modsToLoad, allMods);
        Manager.LoaderApi.OnModLoaderInitialized();
        IsLoaded = true;
    }
    /* Make LoaderConfig for Testing */
    public static LoaderConfig MakeTestConfig()
    {
        var config = new LoaderConfig();

        config.ApplicationConfigDirectory = IfNotExistsMakeDefaultDirectoryAndReturnFullPath(config.GetApplicationConfigDirectory(), "Apps");
        config.ModConfigDirectory         = IfNotExistsMakeDefaultDirectoryAndReturnFullPath(config.GetModConfigDirectory(), "Mods");
        config.PluginConfigDirectory      = IfNotExistsMakeDefaultDirectoryAndReturnFullPath(config.GetPluginConfigDirectory(), "Plugins");
        config.ModUserConfigDirectory     = IfNotExistsMakeDefaultDirectoryAndReturnFullPath(config.GetModUserConfigDirectory(), "UserConfigs");
        config.EnabledPlugins             = EmptyArray <string> .Instance;
        return(config);
    }