Exemple #1
0
        private string ListActiveMods()
        {
            var builder = new StringBuilder();

            builder.Append("Loaded mods:\n");
            foreach (var modContentPack in LoadedModManager.RunningMods)
            {
                builder.AppendFormat("{0}({1})", modContentPack.Name, modContentPack.PackageIdPlayerFacing);
                TryAppendOverrideVersion(builder, modContentPack);
                TryAppendManifestVersion(builder, modContentPack);
                builder.Append(": ");
                var firstAssembly = true;
                var anyAssemblies = false;
                foreach (var loadedAssembly in modContentPack.assemblies.loadedAssemblies)
                {
                    if (!firstAssembly)
                    {
                        builder.Append(", ");
                    }
                    firstAssembly = false;
                    builder.Append(loadedAssembly.GetName().Name);
                    builder.AppendFormat("({0})", AssemblyVersionInfo.ReadModAssembly(loadedAssembly, modContentPack));
                    anyAssemblies = true;
                }
                if (!anyAssemblies)
                {
                    builder.Append("(no assemblies)");
                }
                builder.Append("\n");
            }
            return(builder.ToString());
        }
Exemple #2
0
        private static void ReadOwnVersion()
        {
            var ownAssembly    = typeof(HugsLibController).Assembly;
            var ownContentPack = LoadedModManager.RunningMods
                                 .FirstOrDefault(p => p.assemblies != null && p.assemblies.loadedAssemblies.Contains(ownAssembly));

            if (ownContentPack != null)
            {
                libraryVersionFile = VersionFile.TryParseVersionFile(ownContentPack);
                libraryVersionInfo = AssemblyVersionInfo.ReadModAssembly(ownAssembly, ownContentPack);
            }
            else
            {
                Logger.Error("Failed to identify own ModContentPack");
            }
        }
Exemple #3
0
        // will run on startup and on reload. On reload it will add newly loaded mods
        private void EnumerateChildMods(bool earlyInitMode)
        {
            var modBaseDescendantsInLoadOrder = typeof(ModBase).InstantiableDescendantsAndSelf()
                                                .Select(t => new Pair <Type, ModContentPack>(t, assemblyContentPacks.TryGetValue(t.Assembly)))
                                                .Where(pair => pair.Second != null) // null pack => mod is disabled
                                                .OrderBy(pair => pair.Second.loadOrder).ToArray();

            var instantiatedThisRun = new List <string>();

            foreach (var pair in modBaseDescendantsInLoadOrder)
            {
                var subclass     = pair.First;
                var pack         = pair.Second;
                var hasEarlyInit = subclass.HasAttribute <EarlyInitAttribute>();
                if (hasEarlyInit != earlyInitMode)
                {
                    continue;
                }
                if (childMods.Find(cm => cm.GetType() == subclass) != null)
                {
                    continue;                                                                         // skip duplicate types present in multiple assemblies
                }
                ModBase modbase;
                try {
                    modbase = (ModBase)Activator.CreateInstance(subclass, true);
                    modbase.ApplyHarmonyPatches();
                    modbase.ModContentPack = pack;
                    modbase.VersionInfo    = AssemblyVersionInfo.ReadModAssembly(subclass.Assembly, pack);
                    if (childMods.Find(m => m.ModIdentifier == modbase.ModIdentifier) != null)
                    {
                        Logger.Error("Duplicate mod identifier: " + modbase.ModIdentifier);
                        continue;
                    }
                    childMods.Add(modbase);
                    instantiatedThisRun.Add(modbase.ModIdentifier);
                } catch (Exception e) {
                    Logger.ReportException(e, subclass.ToString(), false, "child mod instantiation");
                }
            }
            if (instantiatedThisRun.Count > 0)
            {
                var template = earlyInitMode ? "early-initializing {0}" : "initializing {0}";
                Logger.Message(template, instantiatedThisRun.ListElements());
            }
        }
Exemple #4
0
        private string ListActiveMods()
        {
            var builder = new StringBuilder();

            builder.Append("Loaded mods:\n");
            foreach (var modContentPack in LoadedModManager.RunningMods)
            {
                builder.Append(modContentPack.Name);
                var versionFile = VersionFile.TryParseVersionFile(modContentPack);
                if (versionFile != null && versionFile.OverrideVersion != null)
                {
                    builder.AppendFormat("[ov:{0}]: ", versionFile.OverrideVersion);
                }
                else
                {
                    builder.Append(": ");
                }
                var firstAssembly = true;
                var anyAssemblies = false;
                foreach (var loadedAssembly in modContentPack.assemblies.loadedAssemblies)
                {
                    if (!firstAssembly)
                    {
                        builder.Append(", ");
                    }
                    firstAssembly = false;
                    builder.Append(loadedAssembly.GetName().Name);
                    builder.AppendFormat("({0})", AssemblyVersionInfo.ReadModAssembly(loadedAssembly, modContentPack));
                    anyAssemblies = true;
                }
                if (!anyAssemblies)
                {
                    builder.Append("(no assemblies)");
                }
                builder.Append("\n");
            }
            return(builder.ToString());
        }