Example #1
0
 private void StartMod(ModInstance instance)
 {
     LoaderApi.ModLoading(instance.Mod, instance.ModConfig);
     instance.Start(LoaderApi);
     _modifications[instance.ModConfig.ModId] = instance;
     LoaderApi.ModLoaded(instance.Mod, instance.ModConfig);
 }
Example #2
0
        private ModInstance[] PrepareAllMods(List <PathTuple <ModConfig> > modPaths)
        {
            var modInstances = new ModInstance[modPaths.Count];

            if (_loader.LoaderConfig.LoadModsInParallel)
            {
                var partitioner = Partitioner.Create(0, modPaths.Count);
                Parallel.ForEach(partitioner, (range, loopState) =>
                {
                    for (int x = range.Item1; x < range.Item2; x++)
                    {
                        modInstances[x] = ExecuteWithStopwatch($"Prepared Mod: {modPaths[x].Config.ModId}", GetModInstance, modPaths[x]);
                    }
                });
            }
            else
            {
                for (int x = 0; x < modInstances.Length; x++)
                {
                    modInstances[x] = ExecuteWithStopwatch($"Prepared Mod: {modPaths[x].Config.ModId}", GetModInstance, modPaths[x]);
                }
            }

            return(modInstances);
        }
Example #3
0
        /// <summary>
        /// Loads a collection of mods.
        /// </summary>
        /// <param name="modPaths">Tuples of individual mod configurations and the paths to those configurations.</param>
        public void LoadMods(List <PathGenericTuple <IModConfig> > modPaths)
        {
            PreloadAssemblyMetadata(modPaths);

            /* Load mods. */
            if (modPaths.Count > 0)
            {
                var partitioner  = Partitioner.Create(0, modPaths.Count);
                var modInstances = new ModInstance[modPaths.Count];

                Parallel.ForEach(partitioner, (range, loopState) =>
                {
                    // Loop over each range element without a delegate invocation.
                    for (int i = range.Item1; i < range.Item2; i++)
                    {
                        var modPath     = modPaths[i];
                        modInstances[i] = ExecuteWithStopwatch($"Prepared Mod: {modPath.Object.ModId}", GetModInstance, modPath);
                    }
                });

                foreach (var instance in modInstances)
                {
                    ExecuteWithStopwatch($"Initialized Mod: {instance.ModConfig.ModId}", StartMod, instance);
                }
            }
        }
    public async Task UnloadMod()
    {
        await _client.UnloadModAsync(_testEnvironment.TestModConfigB.ModId, RequestTimeout);

        // Should be loaded last.
        var         loadedMods = _loader.Manager.GetLoadedMods();
        ModInstance configB    = loadedMods.FirstOrDefault(x => x.ModConfig.ModId == _testEnvironment.TestModConfigB.ModId);

        Assert.Null(configB);
    }
    public async Task SuspendMod()
    {
        await _client.SuspendModAsync(_testEnvironment.TestModConfigB.ModId, RequestTimeout);

        // Get instance for B
        var         loadedMods = _loader.Manager.GetLoadedMods();
        ModInstance configB    = loadedMods.FirstOrDefault(x => x.ModConfig.ModId == _testEnvironment.TestModConfigB.ModId);

        Assert.Equal(ModState.Suspended, configB.State);
    }
Example #6
0
        public void SuspendMod()
        {
            var suspendModTask = _client.SuspendModAsync(_testData.TestModConfigB.ModId);

            suspendModTask.Wait();

            // Get instance for B
            var         loadedMods = _loader.Manager.GetLoadedMods();
            ModInstance configB    = loadedMods.FirstOrDefault(x => x.ModConfig.ModId == _testData.TestModConfigB.ModId);

            Assert.Equal(ModState.Suspended, configB.State);
        }
Example #7
0
        public void UnloadMod()
        {
            var unloadModTask = _client.UnloadModAsync(_testData.TestModConfigB.ModId);

            unloadModTask.Wait();

            // Should be loaded last.
            var         loadedMods = _loader.Manager.GetLoadedMods();
            ModInstance configB    = loadedMods.FirstOrDefault(x => x.ModConfig.ModId == _testData.TestModConfigB.ModId);

            Assert.Null(configB);
        }
        public void AddToBossLoot(string[] npcs, string modName, params int[] itemIDs)
        {
            List <int> items = new List <int>();

            foreach (int item in itemIDs)
            {
                items.Add(item);
            }

            foreach (string npc in npcs)
            {
                ModInstance.Call("AddToBossLoot", modName, npc, items);
            }
        }
 private void StartMod(ModInstance instance)
 {
     try
     {
         LoaderApi.ModLoading(instance.Mod, instance.ModConfig);
         instance.Start(LoaderApi);
         _modifications[instance.ModConfig.ModId] = instance;
         LoaderApi.ModLoaded(instance.Mod, instance.ModConfig);
     }
     catch (Exception)
     {
         Logger.WriteLine($"Error while starting mod: {instance.ModConfig.ModId}", Logger.ColorRed);
         throw;
     }
 }
Example #10
0
        public void SuspendAndResumeMod()
        {
            // Suspend first.
            SuspendMod();

            // Now resume.
            var resumeModTask = _client.ResumeModAsync(_testData.TestModConfigB.ModId);

            resumeModTask.Wait();

            // Get instance for B
            var         loadedMods = _loader.Manager.GetLoadedMods();
            ModInstance configB    = loadedMods.FirstOrDefault(x => x.ModConfig.ModId == _testData.TestModConfigB.ModId);

            Assert.Equal(ModState.Running, configB.State);
        }
 public void AddMiniboss(int npcID, float progression, string npcName, Func <bool> downedBoss, int spawnItemID, List <int> lootItemIDs, string spawnInfo, string despawnMessage, string texture, string overrideHeadIconTexutre) => ModInstance.Call("AddMiniBoss", progression, npcID, ModContent.GetInstance <Fargowiltas>(), npcName, downedBoss, spawnItemID, new List <int> {
 }, lootItemIDs, spawnInfo, despawnMessage, texture, overrideHeadIconTexutre);
 public FFAGamemode(ModInstance parent) : base(parent)
 {
     Instance = this;
 }