Пример #1
0
        public void Unload(List <String> modsToUnload)
        {
            Dictionary <string, List <BaseModWithId> > methodHooks;
            List <BaseModWithId> hookedMods;

            //unload
            foreach (String id in modsToUnload)
            {
                //Removing the Mod from all Hooks it subscribed to.
                foreach (MethodDefinition m in modHooks[id])
                {
                    if (hooks.TryGetValue(m.DeclaringType.Name, out methodHooks))
                    {
                        if (methodHooks.TryGetValue(m.Name, out hookedMods))
                        {
                            hookedMods.RemoveAll((BaseModWithId modWithId) => (modWithId.id.Equals(id)));
                        }
                    }
                }
                loader.unloadMod((LocalMod)loader.modManager.installedMods.Find(delegate(Item lmod) {
                    return(id.Equals((lmod as LocalMod).id));
                }));
            }
            modsToUnload.Clear();
        }
Пример #2
0
        public static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
        {
            if ((e.ExceptionObject as Exception).TargetSite.Module.Assembly.GetName().Name.Equals("UnityEngine") ||
                (e.ExceptionObject as Exception).TargetSite.Module.Assembly.GetName().Name.Equals("Assembly-CSharp") ||
                (e.ExceptionObject as Exception).TargetSite.Module.Assembly.GetName().Name.Equals("ScrollsModLoader") ||
                (e.ExceptionObject as Exception).TargetSite.Module.Assembly.Location.ToLower().Equals(Platform.getGlobalScrollsInstallPath().ToLower()) ||
                (e.ExceptionObject as Exception).TargetSite.Module.Assembly.Location.Equals(""))                  //no location or Managed => mod loader crash

            //log
            {
                Console.WriteLine(e.ExceptionObject);
                new ExceptionLogger().logException((Exception)e.ExceptionObject);

                //unload ScrollsModLoader
                MethodBodyReplacementProviderRegistry.SetProvider(new NoMethodReplacementProvider());

                //check for frequent crashes
                if (!System.IO.File.Exists(Platform.getGlobalScrollsInstallPath() + System.IO.Path.DirectorySeparatorChar + "check.txt"))
                {
                    System.IO.File.CreateText(Platform.getGlobalScrollsInstallPath() + System.IO.Path.DirectorySeparatorChar + "check.txt");
                    Platform.RestartGame();
                }
                else
                {
                    try {
                        foreach (String id in instance.modOrder)
                        {
                            BaseMod mod = instance.modInstances [id];
                            if (mod != null)
                            {
                                try {
                                    instance.unloadMod((LocalMod)instance.modManager.installedMods.Find(delegate(Item lmod) {
                                        return((lmod as LocalMod).id.Equals(id));
                                    }));
                                } catch (Exception exp) {
                                    Console.WriteLine(exp);
                                }
                            }
                        }
                    } catch (Exception exp) {
                        Console.WriteLine(exp);
                    }
                    instance.repatch();
                }
            }
            else if (instance != null && logger != null && logger.Count > 0)
            {
                Console.WriteLine(e.ExceptionObject);

                Assembly asm      = (e.ExceptionObject as Exception).TargetSite.Module.Assembly;
                Type     modClass = (from _modClass in asm.GetTypes()
                                     where _modClass.InheritsFrom(typeof(BaseMod))
                                     select _modClass).First();

                //no mod classes??
                if (modClass == null)
                {
                    return;
                }

                foreach (String id in instance.modOrder)
                {
                    BaseMod mod = null;
                    try {
                        mod = instance.modInstances [id];
                    } catch (Exception exp) {
                        Console.WriteLine(exp);
                    }
                    if (mod != null)
                    {
                        if (modClass.Equals(mod.GetType()))
                        {
                            String folder = Path.GetDirectoryName(asm.Location);
                            if (File.Exists(folder + Path.DirectorySeparatorChar + "config.json"))
                            {
                                JsonReader reader = new JsonReader();
                                LocalMod   lmod   = (LocalMod)reader.Read(File.ReadAllText(folder + Path.DirectorySeparatorChar + "config.json"), typeof(LocalMod));
                                if (!lmod.localInstall)
                                {
                                    logger [lmod.localId].logException((Exception)e.ExceptionObject);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
 public void deinstallMod(LocalMod mod)
 {
     loader.unloadMod(mod);
     mod.queueForUninstall = true;
     updateConfig(mod);
 }