Exemplo n.º 1
0
        private List <ModEntry> LoadMetadataForModTypes(List <Type> mods)
        {
            var result = new List <ModEntry>();

            foreach (Type mod in mods)
            {
                try
                {
                    string metadataPath = Path.Combine(
                        Path.GetDirectoryName(mod.Assembly.Location),
                        $"{Path.GetFileNameWithoutExtension(mod.Assembly.Location)}.json");
                    ModMetadata metadata = _metadataProvider.Read <ModMetadata>(metadataPath);
                    if (metadata is null)
                    {
                        metadata = new ModMetadata(mod.FullName, "0.0");
                    }
                    result.Add(new ModEntry(mod, metadata));
                }
                catch (FileNotFoundException)
                {
                    ModMetadata metadata = new ModMetadata(mod.FullName, "0.0");
                    result.Add(new ModEntry(mod, metadata));
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        private List <ModEntry> ResolveDisabledMods(List <ModEntry> modsWithMetadata)
        {
            List <ModEntry> Resolved               = new List <ModEntry>();
            List <ModEntry> successfullyResolved   = new List <ModEntry>();
            var             disabledResolutionList = modsWithMetadata;

            foreach (ModEntry entry in disabledResolutionList)
            {
                if (ModDbManager.isInactive(entry))
                {
                    var loaded = InactiveMods.Value.Find(e => e.ModType.FullName == entry.ModType.FullName);
                    if (loaded == null)
                    {
                        InactiveMods.Value.Add(entry);
                    }
                    else
                    {
                        if (conflictingAssemblies.IsValueCreated)
                        {
                            foreach (var assemblyconflict in conflictingAssemblies.Value)
                            {
                                if (assemblyconflict.Item1 == loaded.ModType.Assembly)
                                {
                                    if (loaded.ModType.Assembly.Location.Contains(WTFModLoader.ModsDirectory) && assemblyconflict.Item2.Contains(WTFModLoader.SteamModsDirectory))
                                    {
                                        var mod = entry.ModType;
                                        try
                                        {
                                            string metadataPath = Path.Combine(
                                                Path.GetDirectoryName(assemblyconflict.Item2),
                                                $"{Path.GetFileNameWithoutExtension(assemblyconflict.Item2)}.json");
                                            ModMetadata metadata = _metadataProvider.Read <ModMetadata>(metadataPath);
                                            if (metadata is null)
                                            {
                                                metadata = new ModMetadata(mod.FullName, "0.0");
                                            }
                                            entry.ModMetadata = metadata;
                                        }
                                        catch (FileNotFoundException)
                                        {
                                            ModMetadata metadata = new ModMetadata(mod.FullName, "0.0");
                                            entry.ModMetadata = metadata;
                                        }
                                        entry.Source = assemblyconflict.Item2;
                                        entry.Issue  = $"unable to load steam mod, a local version of this mod is already loaded";
                                        IssuedMods.Value.Add(entry);
                                        break;
                                    }
                                    else if (loaded.ModType.Assembly.Location.Contains(WTFModLoader.SteamModsDirectory) && assemblyconflict.Item2.Contains(WTFModLoader.ModsDirectory))
                                    {
                                        var mod = entry.ModType;
                                        try
                                        {
                                            string metadataPath = Path.Combine(
                                                Path.GetDirectoryName(assemblyconflict.Item2),
                                                $"{Path.GetFileNameWithoutExtension(assemblyconflict.Item2)}.json");
                                            ModMetadata metadata = _metadataProvider.Read <ModMetadata>(metadataPath);
                                            if (metadata is null)
                                            {
                                                metadata = new ModMetadata(mod.FullName, "0.0");
                                            }
                                            entry.ModMetadata = metadata;
                                        }
                                        catch (FileNotFoundException)
                                        {
                                            ModMetadata metadata = new ModMetadata(mod.FullName, "0.0");
                                            entry.ModMetadata = metadata;
                                        }
                                        entry.Source = assemblyconflict.Item2;
                                        entry.Issue  = $"unable to load local mod version, unsub this mod from Steam to resolve";
                                        IssuedMods.Value.Add(entry);
                                        break;
                                    }
                                    if (!IssuedMods.Value.Contains(entry))
                                    {
                                        var mod = entry.ModType;
                                        try
                                        {
                                            string metadataPath = Path.Combine(
                                                Path.GetDirectoryName(assemblyconflict.Item2),
                                                $"{Path.GetFileNameWithoutExtension(assemblyconflict.Item2)}.json");
                                            ModMetadata metadata = _metadataProvider.Read <ModMetadata>(metadataPath);
                                            if (metadata is null)
                                            {
                                                metadata = new ModMetadata(mod.FullName, "0.0");
                                            }
                                            entry.ModMetadata = metadata;
                                        }
                                        catch (FileNotFoundException)
                                        {
                                            ModMetadata metadata = new ModMetadata(mod.FullName, "0.0");
                                            entry.ModMetadata = metadata;
                                        }
                                        entry.Source = assemblyconflict.Item2;
                                        entry.Issue  = $"unable to load mod, a different version of this mod is already loaded";
                                        IssuedMods.Value.Add(entry);
                                        break;
                                    }
                                }
                            }
                        }
                        if (!IssuedMods.Value.Contains(entry))
                        {
                            entry.Issue = $"unable to load mod, a different version of this mod is already loaded";
                            IssuedMods.Value.Add(entry);
                        }
                    }
                }
                else
                {
                    Resolved.Add(entry);
                }
            }

            foreach (ModEntry entry in Resolved)
            {
                var active = successfullyResolved.Find(e => e.ModType.FullName == entry.ModType.FullName);
                if (active == null)
                {
                    successfullyResolved.Add(entry);
                }
                else
                {
                    if (conflictingAssemblies.IsValueCreated)
                    {
                        foreach (var assemblyconflict in conflictingAssemblies.Value)
                        {
                            if (assemblyconflict.Item1 == active.ModType.Assembly)
                            {
                                if (active.ModType.Assembly.Location.Contains(WTFModLoader.ModsDirectory) && assemblyconflict.Item2.Contains(WTFModLoader.SteamModsDirectory))
                                {
                                    var mod = entry.ModType;
                                    try
                                    {
                                        string metadataPath = Path.Combine(
                                            Path.GetDirectoryName(assemblyconflict.Item2),
                                            $"{Path.GetFileNameWithoutExtension(assemblyconflict.Item2)}.json");
                                        ModMetadata metadata = _metadataProvider.Read <ModMetadata>(metadataPath);
                                        if (metadata is null)
                                        {
                                            metadata = new ModMetadata(mod.FullName, "0.0");
                                        }
                                        entry.ModMetadata = metadata;
                                    }
                                    catch (FileNotFoundException)
                                    {
                                        ModMetadata metadata = new ModMetadata(mod.FullName, "0.0");
                                        entry.ModMetadata = metadata;
                                    }
                                    entry.Source = assemblyconflict.Item2;
                                    entry.Issue  = $"unable to load steam mod, a local version of this mod is already loaded";
                                    IssuedMods.Value.Add(entry);
                                    break;
                                }
                                else if (active.ModType.Assembly.Location.Contains(WTFModLoader.SteamModsDirectory) && assemblyconflict.Item2.Contains(WTFModLoader.ModsDirectory))
                                {
                                    var mod = entry.ModType;
                                    try
                                    {
                                        string metadataPath = Path.Combine(
                                            Path.GetDirectoryName(assemblyconflict.Item2),
                                            $"{Path.GetFileNameWithoutExtension(assemblyconflict.Item2)}.json");
                                        ModMetadata metadata = _metadataProvider.Read <ModMetadata>(metadataPath);
                                        if (metadata is null)
                                        {
                                            metadata = new ModMetadata(mod.FullName, "0.0");
                                        }
                                        entry.ModMetadata = metadata;
                                    }
                                    catch (FileNotFoundException)
                                    {
                                        ModMetadata metadata = new ModMetadata(mod.FullName, "0.0");
                                        entry.ModMetadata = metadata;
                                    }
                                    entry.Source = assemblyconflict.Item2;
                                    entry.Issue  = $"unable to load local mod version, unsub this mod from Steam to resolve";
                                    IssuedMods.Value.Add(entry);
                                    break;
                                }
                                if (!IssuedMods.Value.Contains(entry))
                                {
                                    var mod = entry.ModType;
                                    try
                                    {
                                        string metadataPath = Path.Combine(
                                            Path.GetDirectoryName(assemblyconflict.Item2),
                                            $"{Path.GetFileNameWithoutExtension(assemblyconflict.Item2)}.json");
                                        ModMetadata metadata = _metadataProvider.Read <ModMetadata>(metadataPath);
                                        if (metadata is null)
                                        {
                                            metadata = new ModMetadata(mod.FullName, "0.0");
                                        }
                                        entry.ModMetadata = metadata;
                                    }
                                    catch (FileNotFoundException)
                                    {
                                        ModMetadata metadata = new ModMetadata(mod.FullName, "0.0");
                                        entry.ModMetadata = metadata;
                                    }
                                    entry.Source = assemblyconflict.Item2;
                                    entry.Issue  = $"unable to load mod, a different version of this mod is already loaded";
                                    IssuedMods.Value.Add(entry);
                                    break;
                                }
                            }
                        }
                    }
                    if (!IssuedMods.Value.Contains(entry))
                    {
                        entry.Issue = $"unable to load, a different version of this mod is already loaded";
                        IssuedMods.Value.Add(entry);
                    }
                }
            }
            return(successfullyResolved);
        }
 public ModEntry(IWTFMod modInstance, Type modType, ModMetadata modMetadata)
 {
     ModInstance = modInstance;
     ModType     = modType;
     ModMetadata = modMetadata;
 }
 public ModEntry(Type modType, ModMetadata modMetadata) : this(null, modType, modMetadata)
 {
 }