Пример #1
0
        public void TestPexAddition()
        {
            var path = Path.Combine("Pex", "files", "Art.pex");

            Assert.True(File.Exists(path));

            var pex           = PexFile.CreateFromFile(path, GameCategory.Skyrim);
            var functionToAdd = new DebugFunction()
            {
                FunctionName = "HelloWorld",
                FunctionType = DebugFunctionType.Method,
            };

            pex.DebugInfo?.Functions.Add(functionToAdd);

            using var tempFolder = TestPathing.GetTempFolder(nameof(PexTests));
            var outPath = Path.Combine(tempFolder.Dir.Path, Path.GetTempFileName());

            pex.WritePexFile(outPath, GameCategory.Skyrim);

            var pex2 = PexFile.CreateFromFile(outPath, GameCategory.Skyrim);

            pex2.DebugInfo.Should().NotBeNull();
            pex2.DebugInfo !.Functions.Should().HaveCount(pex.DebugInfo !.Functions.Count);
            pex2.DebugInfo !.Functions[^ 1].FunctionName.Should().Be(functionToAdd.FunctionName);
Пример #2
0
        public void MasterFlagSync_Correct()
        {
            WarmupOblivion.Init();
            using var folder = TestPathing.GetTempFolder(nameof(MasterSync_Tests));
            var masterMod  = new OblivionMod(new ModKey("Test", ModType.Master));
            var masterPath = Path.Combine(folder.Dir.Path, "Test.esm");

            masterMod.WriteToBinary(masterPath,
                                    new BinaryWriteParameters()
            {
                ModKey             = ModKeyOption.ThrowIfMisaligned,
                MastersListContent = MastersListContentOption.NoCheck,
            });
            using var reimport = OblivionMod.CreateFromBinaryOverlay(masterPath);
            Assert.True(reimport.ModHeader.Flags.HasFlag(OblivionModHeader.HeaderFlag.Master));
            var childMod  = new OblivionMod(new ModKey("Test", ModType.Plugin));
            var childPath = Path.Combine(folder.Dir.Path, "Test.esp");

            childMod.WriteToBinary(childPath,
                                   new BinaryWriteParameters()
            {
                ModKey             = ModKeyOption.ThrowIfMisaligned,
                MastersListContent = MastersListContentOption.NoCheck,
            });
            using var reimport2 = OblivionMod.CreateFromBinaryOverlay(childPath);
            Assert.False(reimport2.ModHeader.Flags.HasFlag(OblivionModHeader.HeaderFlag.Master));
        }
Пример #3
0
        public void MasterListSync_AddMissingToEmpty()
        {
            WarmupOblivion.Init();
            using var folder = TestPathing.GetTempFolder(nameof(MasterSync_Tests));
            var obliv    = ModKey.FromNameAndExtension("Oblivion.esm");
            var knights  = ModKey.FromNameAndExtension("Knights.esm");
            var other    = ModKey.FromNameAndExtension("Other.esp");
            var mod      = new OblivionMod(obliv);
            var otherNpc = new Npc(new FormKey(other, 0x123456));

            mod.Potions.RecordCache.Set(new Potion(new FormKey(obliv, 0x123456)));
            mod.Npcs.RecordCache.Set(otherNpc);
            otherNpc.Race.FormKey = new FormKey(knights, 0x123456);
            var modPath = Path.Combine(folder.Dir.Path, obliv.ToString());

            mod.WriteToBinary(modPath,
                              new BinaryWriteParameters()
            {
                ModKey             = ModKeyOption.NoCheck,
                MastersListContent = MastersListContentOption.Iterate,
            });
            using var reimport = OblivionMod.CreateFromBinaryOverlay(modPath);
            Assert.Equal(2, reimport.MasterReferences.Count);
            Assert.Contains(knights, reimport.MasterReferences.Select(m => m.Master));
            Assert.Contains(other, reimport.MasterReferences.Select(m => m.Master));
        }
Пример #4
0
        public void MasterOrderSync_ByLoadOrder()
        {
            WarmupOblivion.Init();
            using var folder = TestPathing.GetTempFolder(nameof(MasterSync_Tests));
            var obliv  = ModKey.FromNameAndExtension("Oblivion.esm");
            var esm    = ModKey.FromNameAndExtension("First.esm");
            var esp    = ModKey.FromNameAndExtension("Second.esp");
            var mod    = new OblivionMod(obliv);
            var espNpc = new Npc(new FormKey(esp, 0x123456));

            mod.Npcs.RecordCache.Set(espNpc);
            var esmNpc = new Npc(new FormKey(esm, 0x123456));

            mod.Npcs.RecordCache.Set(esmNpc);
            var modPath   = Path.Combine(folder.Dir.Path, obliv.ToString());
            var loadOrder = new ModKey[]
            {
                esm,
                esp,
            };

            mod.WriteToBinary(modPath,
                              new BinaryWriteParameters()
            {
                ModKey              = ModKeyOption.NoCheck,
                MastersListContent  = MastersListContentOption.Iterate,
                MastersListOrdering = new MastersListOrderingByLoadOrder(loadOrder)
            });
            using var reimport = OblivionMod.CreateFromBinaryOverlay(modPath);
            Assert.Equal(
                loadOrder,
                reimport.ModHeader.MasterReferences.Select(m => m.Master));
        }
Пример #5
0
        public void GetListings_NoCreationClub()
        {
            using var tmp = TestPathing.GetTempFolder(nameof(LoadOrderIntegrationTests));
            var pluginsPath = Path.Combine(tmp.Dir.Path, "Plugins.txt");
            var dataPath    = Path.Combine(tmp.Dir.Path, "Data");

            File.WriteAllLines(pluginsPath,
                               new string[]
            {
                $"{TestConstants.MasterModKey.FileName}",
                $"{TestConstants.PluginModKey.FileName}",
            });
            Directory.CreateDirectory(dataPath);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.MasterModKey.FileName), string.Empty);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.PluginModKey.FileName), string.Empty);
            var results = LoadOrder.GetListings(
                game: GameRelease.Oblivion,
                dataPath: dataPath,
                pluginsFilePath: pluginsPath,
                creationClubFilePath: null)
                          .ToList();

            results.Should().HaveCount(2);
            results.Should().Equal(new ModListing[]
            {
                new ModListing(TestConstants.MasterModKey, enabled: true),
                new ModListing(TestConstants.PluginModKey, enabled: true),
            });
        }
Пример #6
0
        public void GetListings_VortexCreationClub()
        {
            using var tmp = TestPathing.GetTempFolder(nameof(LoadOrderIntegrationTests));
            var cccPath     = Path.Combine(tmp.Dir.Path, "Skyrim.ccc");
            var pluginsPath = Path.Combine(tmp.Dir.Path, "Plugins.txt");
            var dataPath    = Path.Combine(tmp.Dir.Path, "Data");

            File.WriteAllLines(cccPath,
                               new string[]
            {
                TestConstants.LightMasterModKey.FileName,
                TestConstants.LightMasterModKey2.FileName,
            });
            File.WriteAllLines(pluginsPath,
                               new string[]
            {
                TestConstants.LightMasterModKey2.FileName,
                TestConstants.LightMasterModKey.FileName,
                $"*{TestConstants.MasterModKey.FileName}",
                $"{TestConstants.MasterModKey2.FileName}",
                $"*{TestConstants.LightMasterModKey3.FileName}",
                $"{TestConstants.LightMasterModKey4.FileName}",
                $"*{TestConstants.PluginModKey.FileName}",
                $"{TestConstants.PluginModKey2.FileName}",
            });
            Directory.CreateDirectory(dataPath);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.LightMasterModKey.FileName), string.Empty);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.LightMasterModKey2.FileName), string.Empty);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.MasterModKey.FileName), string.Empty);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.MasterModKey2.FileName), string.Empty);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.LightMasterModKey3.FileName), string.Empty);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.LightMasterModKey4.FileName), string.Empty);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.PluginModKey.FileName), string.Empty);
            File.WriteAllText(Path.Combine(dataPath, TestConstants.PluginModKey2.FileName), string.Empty);
            var results = LoadOrder.GetListings(
                game: GameRelease.SkyrimSE,
                dataPath: dataPath,
                pluginsFilePath: pluginsPath,
                creationClubFilePath: cccPath)
                          .ToList();

            results.Should().HaveCount(8);
            results.Should().Equal(new ModListing[]
            {
                new ModListing(TestConstants.LightMasterModKey2, enabled: true),
                new ModListing(TestConstants.LightMasterModKey, enabled: true),
                new ModListing(TestConstants.MasterModKey, enabled: true),
                new ModListing(TestConstants.MasterModKey2, enabled: false),
                new ModListing(TestConstants.LightMasterModKey3, enabled: true),
                new ModListing(TestConstants.LightMasterModKey4, enabled: false),
                new ModListing(TestConstants.PluginModKey, enabled: true),
                new ModListing(TestConstants.PluginModKey2, enabled: false),
            });
        }
Пример #7
0
        public void MasterFlagSync_ChildThrow()
        {
            WarmupOblivion.Init();
            using var folder = TestPathing.GetTempFolder(nameof(MasterSync_Tests));
            var masterMod  = new OblivionMod(new ModKey("Test", ModType.Plugin));
            var masterPath = Path.Combine(folder.Dir.Path, "Test.esm");

            Assert.Throws <ArgumentException>(() =>
            {
                masterMod.WriteToBinary(masterPath,
                                        new BinaryWriteParameters()
                {
                    ModKey             = ModKeyOption.ThrowIfMisaligned,
                    MastersListContent = MastersListContentOption.NoCheck,
                });
            });
        }
Пример #8
0
        public void WriteExclude()
        {
            using var tmpFolder = TestPathing.GetTempFolder(nameof(LoadOrderIntegrationTests));
            var path = Path.Combine(tmpFolder.Dir.Path, "Plugins.txt");

            LoadOrder.Write(
                path,
                GameRelease.Oblivion,
                new ModListing[]
            {
                new ModListing(TestConstants.PluginModKey, false),
                new ModListing(TestConstants.PluginModKey2, true),
                new ModListing(TestConstants.PluginModKey3, false),
            });
            var lines = File.ReadAllLines(path).ToList();

            Assert.Single(lines);
            Assert.Equal(TestConstants.PluginModKey2.FileName, lines[0]);
        }
Пример #9
0
        public void MasterListSync_SkipNulls()
        {
            WarmupOblivion.Init();
            using var folder = TestPathing.GetTempFolder(nameof(MasterSync_Tests));
            var obliv = ModKey.FromNameAndExtension("Oblivion.esm");
            var mod   = new OblivionMod(obliv);
            var npc   = mod.Npcs.AddNew();

            npc.Race.Clear();
            var modPath = Path.Combine(folder.Dir.Path, obliv.ToString());

            mod.WriteToBinary(modPath,
                              new BinaryWriteParameters()
            {
                ModKey             = ModKeyOption.NoCheck,
                MastersListContent = MastersListContentOption.Iterate,
            });
            using var reimport = OblivionMod.CreateFromBinaryOverlay(modPath);
            Assert.Empty(reimport.ModHeader.MasterReferences);
        }
Пример #10
0
        public void WriteImplicitFilteredOut()
        {
            using var tmpFolder = TestPathing.GetTempFolder(nameof(LoadOrderIntegrationTests));
            var path = Path.Combine(tmpFolder.Dir.Path, "Plugins.txt");

            LoadOrder.Write(
                path,
                GameRelease.SkyrimSE,
                new ModListing[]
            {
                new ModListing(TestConstants.Skyrim, true),
                new ModListing(TestConstants.PluginModKey, true),
                new ModListing(TestConstants.PluginModKey2, false),
            },
                removeImplicitMods: true);
            var lines = File.ReadAllLines(path).ToList();

            Assert.Equal(2, lines.Count);
            Assert.Equal($"*{TestConstants.PluginModKey.FileName}", lines[0]);
            Assert.Equal($"{TestConstants.PluginModKey2.FileName}", lines[1]);
        }