Exemplo n.º 1
0
 public static object RunActionHandler(ModEntry mod, DllMeta dll, ActionDef act)
 {
     try {
         var lib = ModPhases.LoadDll(mod, dll.Path);
         if (lib == null)
         {
             return(false);
         }
         var handler = ActionMods[dll];
         foreach (var type in dll.Methods[ACTION_METHOD])
         {
             var result = ModPhases.CallInit(mod, lib, type, ACTION_METHOD, (e) => ParamValue(act, e, mod, handler));
             if (result is bool success)
             {
                 if (success)
                 {
                     return(true);
                 }
             }
             else if (result is Exception ex)
             {
                 return(ex);
             }
             else if (result != null)
             {
                 handler.Log().Info("Unexpected ActionMod result: {0}", result.GetType());
             }
         }
         return(null);
     } catch (Exception ex) { mod.Error(ex); return(null); }
 }
Exemplo n.º 2
0
        private static object RunActionHandler(ModEntry mod, DllMeta dll, ActionDef act)
        {
            try {
                var lib = ModPhases.LoadDll(mod, dll.Path);
                if (lib == null)
                {
                    return(false);
                }
                var handler = ActionMods[dll];
                object GetParamValue(ParameterInfo pi) => ParamValue(act, pi, mod, handler);

                object result;
                foreach (var type in dll.Methods["ActionMod"])
                {
                    result = ModPhases.CallInit(mod, lib, type, "ActionMod", GetParamValue);
                    if (result is bool success)
                    {
                        if (success)
                        {
                            return(true);
                        }
                    }
                    else if (result is Exception ex)
                    {
                        LogActionError(handler.Log(), act, ex);
                        if (InList(act.GetText("onerror"), "continue"))
                        {
                            continue;
                        }
                        if (InList(act.GetText("onerror"), "skip"))
                        {
                            return(null);
                        }
                        mod.Log().Info("Aborting Actions. Set OnError to \"Log,Continue\" or \"Log,Skip\" to ignore the error.");
                        return(ex);
                    }
                    else if (result != null)
                    {
                        handler.Log().Error("Unexpected ActionMod result: {0}", result.GetType());
                    }
                }
                return(null);
            } catch (Exception ex) { mod.Error(ex); return(null); }
        }