예제 #1
0
        private static Mod Instantiate(LoadedMod mod)
        {
            try {
                Type modType = mod.assembly.GetTypes().SingleOrDefault(t => t.IsSubclassOf(typeof(Mod)));
                if (modType == null)
                {
                    throw new Exception(mod.Name + " does not have a class extending Mod. Mods need a Mod class to function.")
                          {
                              HelpLink = "https://github.com/blushiemagic/tModLoader/wiki/Basic-tModLoader-Modding-FAQ#sequence-contains-no-matching-element-error"
                          }
                }
                ;

                var m = (Mod)Activator.CreateInstance(modType);
                m.File              = mod.modFile;
                m.Code              = mod.assembly;
                m.Logger            = LogManager.GetLogger(m.Name);
                m.Side              = mod.properties.side;
                m.DisplayName       = mod.properties.displayName;
                m.tModLoaderVersion = mod.properties.buildVersion;
                return(m);
            }
            catch (Exception e) {
                e.Data["mod"] = mod.Name;
                throw;
            }
            finally {
                MemoryTracking.Update(mod.Name).code += mod.bytesLoaded;
            }
        }
예제 #2
0
        private static void LoadModContent(CancellationToken token, ref List <Mod> mods, Action <Mod> loadAction)
        {
            MemoryTracking.Checkpoint();
            int num = 0;

            foreach (var mod in ModLoader.Mods)
            {
                Interface.loadModsProgress.SetCurrentMod(num++, $"{mod.Name} v{mod.Version}");
                try {
                    if (!mods.Contains(mod))
                    {
                        mods.Add(mod);
                    }
                    token.ThrowIfCancellationRequested();
                    LoadingMod = mod;
                    loadAction(mod);
                    token.ThrowIfCancellationRequested();
                }
                catch (Exception e) {
                    e.Data["mods"] = mods.Select(x => x.Name).ToArray();
                    throw;
                }
                finally {
                    LoadingMod = null;
                    MemoryTracking.Update(mod.Name);
                }
            }
        }
예제 #3
0
        private static void LoadModContent(Action <Mod> loadAction)
        {
            MemoryTracking.Checkpoint();
            int num = 0;

            foreach (var mod in ModLoader.Mods)
            {
                Interface.loadMods.SetCurrentMod(num++, mod.Name);
                try {
                    LoadingMod = mod;
                    loadAction(mod);
                }
                catch (Exception e) {
                    e.Data["mod"] = mod.Name;
                    throw;
                }
                finally {
                    LoadingMod = null;
                    MemoryTracking.Update(mod.Name);
                }
            }
        }
예제 #4
0
        private static void LoadModContent(CancellationToken token, Action <Mod> loadAction)
        {
            MemoryTracking.Checkpoint();
            int num = 0;

            foreach (var mod in ModLoader.Mods)
            {
                token.ThrowIfCancellationRequested();
                Interface.loadMods.SetCurrentMod(num++, $"{mod.Name} v{mod.Version}");
                try {
                    LoadingMod = mod;
                    loadAction(mod);
                }
                catch (Exception e) {
                    e.Data["mod"] = mod.Name;
                    throw;
                }
                finally {
                    LoadingMod = null;
                    MemoryTracking.Update(mod.Name);
                }
            }
        }