示例#1
0
 private static void AssignModsToPhases()
 {
     lock ( ModsInPhase ) {
         ModsInPhase.Clear();
         string[] allPhases = null;
         foreach (var mod in EnabledMods.ToArray())
         {
             var assigned = false;
             var dlls     = mod.Metadata.Dlls;
             if (dlls != null)
             {
                 foreach (var dll in dlls)
                 {
                     if (dll.Methods == null)
                     {
                         continue;
                     }
                     foreach (var phase in dll.Methods.Keys)
                     {
                         AddModToPhase(mod, phase.ToLowerInvariant(), ref assigned);
                     }
                 }
             }
             var actions = mod.Metadata.Actions;
             if (actions != null)
             {
                 if (allPhases == null)
                 {
                     allPhases = ModPhases.PHASES.Select(e => e.ToLowerInvariant()).ToArray();
                 }
                 foreach (var act in actions)
                 {
                     try {
                         if (act.TryGetValue("phase", out object phaseObj) && phaseObj != null)
                         {
                             var aPhase = phaseObj.ToString().ToLowerInvariant();
                             foreach (var p in allPhases)
                             {
                                 if (ModActions.PhaseMatch(aPhase, p))
                                 {
                                     AddModToPhase(mod, p, ref assigned);
                                 }
                             }
                         }
                         else
                         {
                             AddModToPhase(mod, ModActions.DEFAULT_PHASE, ref assigned);
                         }
                     } catch (Exception ex) { mod.Log().Warn(ex); }
                 }
             }
             if (!assigned)
             {
                 DisableAndRemoveMod(mod, "no_phase", "no matching mod phases.");
             }
         }
     }
 }
示例#2
0
 public static void RunPhase(string phase)
 {
     try {
         // Make sure Init, Initialize, and *Mod phases are not repeated
         if (phase.StartsWith("Init") || phase.EndsWith("Mod"))
         {
             lock ( LoadedPhases ) {
                 if (LoadedPhases.Contains(phase))
                 {
                     return;
                 }
                 LoadedPhases.Add(phase);
                 // UnloadMod and ActionMod should not go through here!
                 if (phase == "UnloadMod" || phase == "ActionMod")
                 {
                     Log.Error(new ArgumentException(phase));
                     return;
                 }
             }
         }
         LastPhase = phase;
         if (!ModLoader.ModsInPhase.TryGetValue(phase.ToLowerInvariant(), out List <ModEntry> list))
         {
             Log.Verbo("Phase {0} skipped, no mods.", phase);
             return;
         }
         Log.Info("PHASE {0}", phase);
         foreach (var mod in list)
         {
             lock (mod.Metadata);
             if (mod.Metadata.Dlls != null)
             {
                 foreach (var dll in mod.Metadata.Dlls)
                 {
                     RunPhaseOnDll(mod, dll, phase);
                 }
             }
             if (mod.Metadata.Actions != null)
             {
                 ModActions.RunActions(mod, phase);
             }
         }
         Log.Verbo("Phase {0} ended", phase);
         Log.Flush();
     } catch (Exception ex) { Log.Error(ex); }
 }
示例#3
0
 public static void LoadMods(string phase)
 {
     try {
         if (!phase.EndsWith("OnShow"))
         {
             lock ( LoadedPhases ) {
                 if (LoadedPhases.Contains(phase))
                 {
                     return;
                 }
                 LoadedPhases.Add(phase);
             }
         }
         if (!ModScanner.ModsInPhase.TryGetValue(phase.ToLowerInvariant(), out List <ModEntry> list))
         {
             Log.Verbo("Phase {0} skipped, no mods.", phase);
             return;
         }
         Log.Info("PHASE {0}", phase);
         foreach (var mod in list)
         {
             lock (mod.Metadata);
             if (mod.Metadata.Dlls != null)
             {
                 foreach (var dll in mod.Metadata.Dlls)
                 {
                     RunPhaseOnDll(mod, dll, phase);
                 }
             }
             if (mod.Metadata.Actions != null)
             {
                 ModActions.RunActions(mod, phase);
             }
         }
         Log.Verbo("Phase {0} ended", phase);
         Log.Flush();
     } catch (Exception ex) { Log.Error(ex); }
 }
示例#4
0
        private static void AssignModsToPhases()
        {
            lock ( ModsInPhase ) {
                ModsInPhase.Clear();
                var unassigned = new List <ModEntry>(EnabledMods);
                foreach (var mod in EnabledMods.ToArray())
                {
                    var assigned = false;
                    var dlls     = mod.Metadata.Dlls;
                    if (dlls == null)
                    {
                        continue;
                    }
                    foreach (var dll in dlls)
                    {
                        if (dll.Methods == null)
                        {
                            continue;
                        }
                        foreach (var phase in dll.Methods.Keys)
                        {
                            AddModToPhase(mod, phase.ToLowerInvariant(), ref assigned);
                        }
                    }
                    if (assigned)
                    {
                        unassigned.Remove(mod);
                    }
                }

                var hasActionHandler = ModsInPhase.ContainsKey("actionmod");
                foreach (var mod in EnabledMods.ToArray())
                {
                    try {
                        var     assigned = false;
                        ref var actions  = ref mod.Metadata.Actions;
                        if (actions == null)
                        {
                            continue;
                        }
                        var origLen = actions.Length;
                        actions = ModActions.Resolve(mod, actions);
                        if (actions == null)
                        {
                            continue;
                        }
                        if (actions.Length < origLen)
                        {
                            mod.Metadata.Actions = actions;
                            mod.Log().Verbo("Merged {0} default actions.", origLen - actions.Length);
                            if (actions == null)
                            {
                                continue;
                            }
                        }
                        if (!hasActionHandler && mod.Metadata.Dlls == null)
                        {
                            DisableAndRemoveMod(mod, "no_actionmod", "no action handler mods.");
                            continue;
                        }
                        foreach (var phase in ModActions.FindPhases(actions))
                        {
                            AddModToPhase(mod, phase, ref assigned);
                        }
                        if (assigned)
                        {
                            unassigned.Remove(mod);
                        }
                    } catch (Exception ex) { mod.Log().Warn(ex); }