public static void RunPhaseOnDll(ModEntry mod, DllMeta dll, string phase) { try { if (dll.Methods == null) { return; } if (!dll.Methods.TryGetValue(phase, out var entries)) { return; } var lib = LoadDll(mod, dll.Path); if (lib == null) { return; } foreach (var type in entries) { if (CallInit(mod, lib, type, phase, (e) => ParamValue(e, mod)) is Exception err) { Log.Error(err); } } } catch (Exception ex) { mod.Error(ex); } }
private static DllMeta AssignDllMetaProp(DllMeta e, string prop, object val) { prop = prop.Trim(); string txt = val.ToString().Trim(); if (prop.Length <= 0 || txt.Length <= 0) { return(e); } if (prop.Equals("path", StringComparison.OrdinalIgnoreCase)) { e.Path = txt; } else { var methods = e.Methods; if (methods == null) { e.Methods = methods = new Dictionary <string, HashSet <string> >(); } if (!methods.TryGetValue(prop, out var list)) { methods[prop] = list = new HashSet <string>(); } list.Add(txt); } return(e); }
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); } }
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); } }