Beispiel #1
0
        private ModLoader.ModInfo _LoadOrIgnoreIfBlacklisted(string mods_dir_entry, HashSet <string> blacklist)
        {
            var filename = Path.GetFileName(mods_dir_entry);

            if (blacklist.Contains(mods_dir_entry))
            {
                Logger.Info($"Refusing to load blacklisted mod: {filename}");
                return(null);
            }
            Logger.Info($"Loading mod: {filename}");
            try {
                return(ModLoader.Load(mods_dir_entry));
            } catch (Exception e) {
                Logger.Error($"Exception while loading mod {filename}: [{e.GetType().Name}] {e.Message}");
                ErrorLoadingMod.Invoke(filename, e);

                foreach (var l in e.StackTrace.Split('\n'))
                {
                    Logger.ErrorIndent(l);
                }

                if (e.InnerException != null)
                {
                    Logger.ErrorIndent($"Inner exception: [{e.InnerException.GetType().Name}] {e.InnerException.Message}");
                    foreach (var l in e.InnerException.StackTrace.Split('\n'))
                    {
                        Logger.ErrorIndent(l);
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
            public LuaVararg RunLua(LuaFunction func, string name = "[unknown]", params LuaValue[] args)
            {
                LuaVararg ret = null;

                try {
                    func.Environment = LuaEnvironment;

                    ret = func.Call(args);
                } catch (Exception e) {
                    ETGMod.ModLoader.LuaError.Invoke(this, LuaEventMethod.Loaded, e);
                    Logger.Error(e.Message);

                    if (e is LuaException)
                    {
                        for (int i = 0; i < ((LuaException)e).TracebackArray.Length; i++)
                        {
                            Logger.ErrorIndent("  " + ((LuaException)e).TracebackArray[i]);
                        }
                    }
                    else
                    {
                        var lines = e.StackTrace.Split('\n');
                        for (int i = 0; i < lines.Length; i++)
                        {
                            Logger.ErrorIndent(lines[i]);
                        }
                    }
                }

                return(ret);
            }
Beispiel #3
0
        public void Unload(ModInfo info)
        {
            UnloadAll(info.EmbeddedMods);

            Logger.Info($"Unloading mod {info.Name}");
            if (info.HasScript)
            {
                try {
                    info.Triggers.InvokeUnloaded();
                } catch (LuaException e) {
                    Logger.Error(e.Message);
                    LuaError.Invoke(info, LuaEventMethod.Unloaded, e);

                    for (int i = 0; i < e.TracebackArray.Length; i++)
                    {
                        Logger.ErrorIndent("  " + e.TracebackArray[i]);
                    }
                }
            }

            info.Dispose();

            info.EmbeddedMods = new List <ModInfo>();
            PostUnloadMod.Invoke(info);
        }
Beispiel #4
0
 private static void SafeExecLua(LuaFunction func, string what)
 {
     try {
         func.Call();
     } catch (LuaException e) {
         Logger.Error($"Failed {what}: [{e.GetType()}]");
         Logger.ErrorIndent(e.Message);
         foreach (var line in e.TracebackArray)
         {
             Logger.ErrorIndent(line);
         }
     } catch (Exception e) {
         Logger.Error($"Failed {what}: [{e.GetType()}]");
         Logger.ErrorIndent(e.Message);
         foreach (var line in e.StackTrace.Split('\n'))
         {
             Logger.ErrorIndent(line.Replace("  ", ""));
         }
     }
 }