Ejemplo n.º 1
0
 public static void Init()
 {
     try {
         if (Log == null) // First run
         {
             Setup();
             ModScanner.BuildModList();
             ModPhases.LoadMods("SplashMod");
             PatchMenuCrt();
             if (Patcher == null)
             {
                 Log.Log(SourceLevels.Critical, "Cannot patch game with Harmony. Non-SplashMods will not be loaded.");
             }
         }
     } catch (Exception ex) {
         if (Log == null)
         {
             Console.WriteLine(ex);
         }
         else
         {
             Log.Error(ex);
         }
     }
 }
Ejemplo n.º 2
0
 public static void Init()
 {
     try {
         if (Log != null)
         {
             return;
         }
         Setup();
         ModScanner.BuildModList();
         ModPhases.RunPhase("SplashMod");
         if (!GamePatcher.PatchPhases())
         {
             Log.Log(SourceLevels.Critical, "Cannot patch game with Harmony. Non-SplashMods may not be loaded.");
         }
     } catch (Exception ex) {
         if (Log == null)
         {
             Console.WriteLine(ex);
         }
         else
         {
             Log.Error(ex);
         }
     }
 }
Ejemplo n.º 3
0
 private ModEntry GetMod(object target)
 {
     if (LowerAndIsEmpty(target, out string id))
     {
         return(this);
     }
     return(ModScanner.GetModById(id));
 }
Ejemplo n.º 4
0
 private Version GetVersion(object target)
 {
     if (LowerAndIsEmpty(target, out string id))
     {
         lock (Metadata) return(Metadata.Version);
     }
     ModScanner.GetVersionById(id, out _, out Version ver);
     return(ver);
 }
Ejemplo n.º 5
0
        private IEnumerable <Assembly> GetAssemblies(object target)
        {
            if (LowerAndIsEmpty(target, out string id))
            {
                return(ModAssemblies ?? Enumerable.Empty <Assembly>());
            }
            switch (id)
            {
            case "modnix":
                return(new Assembly[] { Assembly.GetExecutingAssembly() });

            case "loader":
                var ppml       = ModLoader.PpmlAssembly;
                var loaderList = new Assembly[ppml == null ? 1 : 2];
                loaderList[0] = Assembly.GetExecutingAssembly();
                if (ppml != null)
                {
                    loaderList[1] = ppml;
                }
                return(loaderList);

            case "phoenixpointmodloader":
            case "phoenix point mod loader":
            case "ppml":
                return(new Assembly[] { ModLoader.PpmlAssembly });

            case "phoenixpoint":
            case "phoenix point":
            case "game":
                if (GameAssembly == null)  // No need to lock. No conflict.
                {
                    GameAssembly = Array.Find(AppDomain.CurrentDomain.GetAssemblies(), e => e.FullName.StartsWith("Assembly-CSharp,"));
                }
                return(new Assembly[] { GameAssembly });

            default:
                var mod = ModScanner.GetModById(id);
                if (mod == null)
                {
                    return(null);
                }
                return(mod.ModAssemblies ?? Enumerable.Empty <Assembly>());
            }
        }
Ejemplo n.º 6
0
        internal static bool GetVersionById(string id, out ModEntry mod, out Version version)
        {
            mod     = null;
            version = null;
            if (string.IsNullOrEmpty(id))
            {
                return(false);
            }
            id = ModScanner.NormaliseModId(id);
            switch (id)
            {
            case "modnix":
            case "loader":
            case "":
                version = ModLoader.LoaderVersion;
                return(true);

            case "phoenixpoint":
            case "phoenix point":
            case "game":
                version = ModLoader.GameVersion;
                return(true);

            case "ppml":
            case "ppml+":
            case "phoenixpointmodloader":
            case "phoenix point mod loader":
                version = ModLoader.PPML_COMPAT;
                return(true);

            case "non-modnix":
            case "nonmodnix":
                return(false);

            default:
                mod     = _GetModById(id);
                version = GetVersionFromMod(mod);
                return(mod != null);
            }
        }
Ejemplo n.º 7
0
        private string GetPath(object target)
        {
            if (LowerAndIsEmpty(target, out string id))
            {
                return(Path);
            }
            switch (id)
            {
            case "mods_root": return(ModLoader.ModDirectory);

            case "loader":
            case "modnix":
                return(ModLoader.LoaderPath);

            case "phoenixpoint":
            case "phoenix point":
            case "game":
                return(Process.GetCurrentProcess().MainModule?.FileName);

            default:
                return(ModScanner.GetModById(id)?.Path);
            }
        }
Ejemplo n.º 8
0
 internal static ModEntry GetModById(string id) => _GetModById(ModScanner.NormaliseModId(id));
Ejemplo n.º 9
0
        private static void RemoveUnfulfilledMods()
        {
            Log.Verbo("Check mod requirements");
            var dependees = new HashSet <string>();

            foreach (var mod in EnabledMods.ToArray())
            {
                if (mod.Disabled)
                {
                    continue;
                }
                var reqs = mod.Metadata.Requires;
                if (reqs == null)
                {
                    continue;
                }
                var requirements = new Dictionary <string, List <AppVer> >();
                foreach (var req in reqs)
                {
                    var id = ModScanner.NormaliseModId(req.Id);
                    if (id == null)
                    {
                        continue;
                    }
                    if (!requirements.ContainsKey(id))
                    {
                        requirements[id] = new List <AppVer>();
                    }
                    requirements[id].Add(req);
                }
                foreach (var reqSet in requirements)
                {
                    bool found = ModLoader.GetVersionById(reqSet.Key, out ModEntry target, out Version ver), fulfill = found;
                    if (target == mod)
                    {
                        mod.Log().Warn("Mod {0} not allowed to depends on itself with mod_info.Requires", reqSet.Key);
                        continue;
                    }
                    if (found)
                    {
                        fulfill = reqSet.Value.Any(r => (r.Min == null || r.Min <= ver) && (r.Max == null || r.Max >= ver));
                    }
                    if (!fulfill)
                    {
                        var r = reqs.FirstOrDefault(e => ModScanner.NormaliseModId(e.Id) == reqSet.Key);
                        DisableAndRemoveMod(mod, "require", "requirement {0} failed, found {1}", reqSet.Key, found ? (object)ver : "none", r?.Name, r?.Url);
                        break;
                    }
                    else
                    {
                        dependees.Add(reqSet.Key);
                    }
                }
            }

            foreach (var mod in EnabledMods.ToArray())
            {
                var flags = mod.Metadata.Flags;
                if (flags != null && Tools.InList(flags, "library") && !dependees.Contains(mod.Key))
                {
                    DisableAndRemoveMod(mod, "no_dependent", "library disabled because no mods require it");
                }
            }
        }