public static Assembly LoadDll(ModEntry mod, string path) { try { if (mod.ModAssemblies != null) { foreach (var a in mod.ModAssemblies) { if (!a.IsDynamic && a.Location == path) { return(a); } } } /*if ( ! Tools.IsSafePath( path ) ) { // TODO: Make auto-scanned dll use relative path * mod.Log().Error( "Invalid or unsafe path: {0}", path ); * return null; * }*/ mod.Log().Info("Loading {0}", path); var asm = Assembly.LoadFrom(path); if (asm == null) { return(null); } if (mod.ModAssemblies == null) { mod.ModAssemblies = new List <Assembly>(); } if (!mod.ModAssemblies.Contains(asm)) { mod.ModAssemblies.Add(asm); } return(asm); } catch (Exception ex) { mod.Error(ex); return(null); } }
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); } }
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); } }
public static Assembly LoadDll(ModEntry mod, string path) { try { if (mod.ModAssemblies != null) { foreach (var a in mod.ModAssemblies) { if (!a.IsDynamic && a.Location == path) { return(a); } } } mod.Log().Info("Loading {0}", path); var asm = Assembly.LoadFrom(path); if (asm == null) { return(null); } if (mod.ModAssemblies == null) { mod.ModAssemblies = new List <Assembly>(); } if (!mod.ModAssemblies.Contains(asm)) { mod.ModAssemblies.Add(asm); } return(asm); } 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); } }