/// <summary> /// Entry point for Modnix 3 actions. /// Action syntax is the same as traditional PPDefModifier mods. /// </summary> public static bool ActionMod(string modid, ModnixAction action) { if (action == null || (!action.ContainsKey("cls") && !action.ContainsKey("guid"))) { return(false); } if (!action.ContainsKey("value") && !action.ContainsKey("modletlist")) { return(false); } ModFile modfile = GetModFile(modid); if (modid != lastactionmod) { logger.Log("Applying mod actions in {0}", modfile); lastactionmod = modid; } ModDefinition def = new ModDefinition(); try { ConvertActionToMod(action, def); modfile.ApplyMod(def); return(true); } catch (Exception e) { logger.Error("Error applying mod action {0}: {1}", def.GetModName(), e.ToString()); return(false); } }
/// <summary> /// Apply one mod /// </summary> /// <param name="def">The mod def to apply</param> public void ApplyMod(ModDefinition def) { Mod mod = new Mod(fileName, def, repo); mod.Validate(); // If the mod contains a modletlist expand it out into individual mods and apply each in turn. if (def.modletlist != null) { // The index int modletIndex = 1; // Make a new ModifierDefinition for each modlet in the modlet list and apply it. foreach (ModletStep modlet in def.modletlist) { if (modlet.field == null || modlet.value == null) { // Skip any modlets that are malformed. Do this gracefully so we don't break a sequence. logger.Error("Modlet entry {0} is missing field or value in {1}", modletIndex, def.GetModName()); continue; } ModDefinition tmpDef = new ModDefinition { guid = def.guid, cls = def.cls, field = modlet.field, value = modlet.value }; Mod tmpMod = new Mod(fileName, tmpDef, repo); try { tmpMod.Apply(); } catch (Exception e) { logger.Error("Error applying modlet field {0} in {1}: {2}", modlet.field, def.GetModName(), e.ToString()); } logger.Log("Successfully applied modlet field {0} in {1}", modlet.field, def.GetModName()); ++modletIndex; } // Once we're done exit from the function. return; } else { mod.Apply(); logger.Log("Successfully applied {0}", def.GetModName()); } }