コード例 #1
0
        public void PlacedInWorldspaceQuerySucceedsIfMajorRecordType(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var prototype = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var placed    = new PlacedObject(prototype);

            prototype.Worldspaces.Add(new Worldspace(prototype)
            {
                SubCells = new ExtendedList <WorldspaceBlock>()
                {
                    new WorldspaceBlock()
                    {
                        Items = new ExtendedList <WorldspaceSubBlock>()
                        {
                            new WorldspaceSubBlock()
                            {
                                Items = new ExtendedList <Cell>()
                                {
                                    new Cell(prototype)
                                    {
                                        Temporary = new ExtendedList <IPlaced>()
                                        {
                                            placed
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);
            WrapPotentialThrow(cacheType, style, () =>
            {
                package.TryResolve <ISkyrimMajorRecordGetter>(placed.FormKey, out var rec2)
                .Should().BeTrue();
                rec2.Should().Be(placed);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                contextRetriever.TryResolveContext <ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(placed.AsLink(), package, out var rec)
                .Should().BeTrue();
                rec.Record.Should().Be(placed);
            });
        }
コード例 #2
0
        public void DisposedIfException()
        {
            var fs = new MockFileSystem();

            fs.Directory.CreateDirectory("C:/SomeFolder");
            var modPath = Path.Combine("C:/SomeFolder", "Test.esp");

            try
            {
                fs.File.WriteAllText(modPath, "DERP");
                var mod = SkyrimMod.CreateFromBinaryOverlay(modPath, SkyrimRelease.SkyrimLE, fileSystem: fs);
            }
            catch (ArgumentException)
            {
            }
            // Assert that file is released from wrapper's internal stream
            fs.File.Delete(modPath);
        }
コード例 #3
0
        public void FormLink_LoadOrder_Resolve_MarkerInterface(LinkCacheTestTypes cacheType)
        {
            var mod       = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var spell     = mod.Spells.AddNew();
            var loadOrder = new LoadOrder <ISkyrimModGetter>()
            {
                mod,
                new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimLE),
            };

            var(style, package) = GetLinkCache(loadOrder, cacheType);
            FormLink <IEffectRecord> formLink = new FormLink <IEffectRecord>(spell.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.Same(spell, formLink.TryResolve(package));
            });
        }
コード例 #4
0
        public void SimpleGroup()
        {
            var mod  = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var npc1 = mod.Npcs.AddNew();
            var npc2 = mod.Npcs.AddNew();

            var mod2     = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var contexts = mod.EnumerateMajorRecordContexts <INpc, INpcGetter>(linkCache: null !).ToArray();

            contexts.Should().HaveCount(2);
            contexts[0].Record.Should().Be(npc1);
            contexts[1].Record.Should().Be(npc2);
            var npc2Override = contexts[1].GetOrAddAsOverride(mod2);

            npc2.FormKey.Should().Be(npc2Override.FormKey);
            mod2.Npcs.Should().HaveCount(1);
            mod.Npcs.Should().HaveCount(2);
        }
コード例 #5
0
        public static void TestUpdateHeadPart()
        {
            var patchMod = new SkyrimMod(PatchModKey, SkyrimRelease.SkyrimSE);

            var masterMod = new SkyrimMod(MasterModKey, SkyrimRelease.SkyrimSE);

            var oldHeadPart = masterMod.HeadParts.AddNew("oldHeadPart");

            var headPartFormLink = oldHeadPart.AsLink();

            var linkCache = masterMod.ToImmutableLinkCache();

            HeadParts program = new(patchMod, linkCache);

            program.UpdateHeadPart(headPartFormLink, TexturePath, MeshesPath);

            Assert.Empty(patchMod.TextureSets);
        }
コード例 #6
0
        public void FormLink_LoadOrder_Resolve_Linked(LinkCacheTestTypes cacheType)
        {
            var mod       = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var npc       = mod.Npcs.AddNew();
            var loadOrder = new LoadOrder <ISkyrimModGetter>()
            {
                mod,
                new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimLE),
            };

            var(style, package) = GetLinkCache(loadOrder, cacheType);
            FormLink <INpc> formLink = new FormLink <INpc>(npc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.Same(npc, formLink.TryResolve(package));
            });
        }
コード例 #7
0
        public void DirectNoMatch(LinkCacheTestTypes cacheType)
        {
            var prototype = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);

            prototype.ObjectEffects.AddNew();
            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);

            // Test FormKey fails
            Assert.False(package.TryResolve(UnusedFormKey, out var _));
            Assert.False(package.TryResolve(FormKey.Null, out var _));
            Assert.False(package.TryResolve <IMajorRecordGetter>(UnusedFormKey, out var _));
            Assert.False(package.TryResolve <IMajorRecordGetter>(FormKey.Null, out var _));
            Assert.False(package.TryResolve <ISkyrimMajorRecordGetter>(UnusedFormKey, out var _));
            Assert.False(package.TryResolve <ISkyrimMajorRecordGetter>(FormKey.Null, out var _));
            Assert.False(package.TryResolve <IObjectEffectGetter>(UnusedFormKey, out var _));
            Assert.False(package.TryResolve <IObjectEffectGetter>(FormKey.Null, out var _));
            Assert.False(package.TryResolve <IObjectEffect>(UnusedFormKey, out var _));
            Assert.False(package.TryResolve <IObjectEffect>(FormKey.Null, out var _));
            Assert.False(package.TryResolve <ObjectEffect>(UnusedFormKey, out var _));
            Assert.False(package.TryResolve <ObjectEffect>(FormKey.Null, out var _));
            Assert.False(package.TryResolve <IEffectRecord>(UnusedFormKey, out var _));
            Assert.False(package.TryResolve <IEffectRecord>(FormKey.Null, out var _));
            Assert.False(package.TryResolve <IEffectRecordGetter>(UnusedFormKey, out var _));
            Assert.False(package.TryResolve <IEffectRecordGetter>(FormKey.Null, out var _));

            // Test EditorID fails
            Assert.False(package.TryResolve(UnusedEditorID, out var _));
            Assert.False(package.TryResolve(string.Empty, out var _));
            Assert.False(package.TryResolve <IMajorRecordGetter>(UnusedEditorID, out var _));
            Assert.False(package.TryResolve <IMajorRecordGetter>(string.Empty, out var _));
            Assert.False(package.TryResolve <ISkyrimMajorRecordGetter>(UnusedEditorID, out var _));
            Assert.False(package.TryResolve <ISkyrimMajorRecordGetter>(string.Empty, out var _));
            Assert.False(package.TryResolve <IObjectEffectGetter>(UnusedEditorID, out var _));
            Assert.False(package.TryResolve <IObjectEffectGetter>(string.Empty, out var _));
            Assert.False(package.TryResolve <IObjectEffect>(UnusedEditorID, out var _));
            Assert.False(package.TryResolve <IObjectEffect>(string.Empty, out var _));
            Assert.False(package.TryResolve <ObjectEffect>(UnusedEditorID, out var _));
            Assert.False(package.TryResolve <ObjectEffect>(string.Empty, out var _));
            Assert.False(package.TryResolve <IEffectRecord>(UnusedEditorID, out var _));
            Assert.False(package.TryResolve <IEffectRecord>(string.Empty, out var _));
            Assert.False(package.TryResolve <IEffectRecordGetter>(UnusedEditorID, out var _));
            Assert.False(package.TryResolve <IEffectRecordGetter>(string.Empty, out var _));
        }
コード例 #8
0
        public void FormLink_LoadOrder_TryResolve_DeepRecord_Linked(LinkCacheTestTypes cacheType)
        {
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var worldspace = mod.Worldspaces.AddNew();
            var subBlock   = new WorldspaceSubBlock();
            var cell       = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            subBlock.Items.Add(cell);
            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            cell.Temporary.Add(placedNpc);
            var block = new WorldspaceBlock();

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var loadOrder = new LoadOrder <ISkyrimModGetter>()
            {
                mod,
                new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimLE),
            };

            var(style, package) = GetLinkCache(loadOrder, cacheType);
            FormLink <IPlacedNpc> placedFormLink = new FormLink <IPlacedNpc>(placedNpc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(placedFormLink.TryResolve(package, out var linkedPlacedNpc));
                Assert.Same(placedNpc, linkedPlacedNpc);
            });
            FormLink <ICell> cellFormLink = new FormLink <ICell>(cell.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(cellFormLink.TryResolve(package, out var linkedCell));
                Assert.Same(cell, linkedCell);
            });
            FormLink <IWorldspace> worldspaceFormLink = new FormLink <IWorldspace>(worldspace.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(worldspaceFormLink.TryResolve(package, out var linkedWorldspace));
                Assert.Same(worldspace, linkedWorldspace);
            });
        }
コード例 #9
0
        public void FormLink_LoadOrder_ResolveAllContexts_Linked(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var mod       = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var npc       = mod.Npcs.AddNew();
            var loadOrder = new LoadOrder <ISkyrimModGetter>()
            {
                mod,
                new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimLE),
            };

            var(style, package) = GetLinkCache(loadOrder, cacheType);
            var formLink = new FormLink <INpcGetter>(npc.FormKey);
            var resolved = contextRetriever.ResolveAllContexts <INpc, INpcGetter>(formLink, package).ToArray();

            resolved.Should().HaveCount(1);
            resolved.First().Record.Should().BeSameAs(npc);
            resolved.First().ModKey.Should().Be(TestConstants.PluginModKey);
            resolved.First().Parent.Should().BeNull();
        }
コード例 #10
0
        public void DisableAPI()
        {
            // Some calls assuring the Disable() API is accessible and working.
            SkyrimMod    sourceMod    = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE);
            FormKey      key          = sourceMod.GetNextFormKey();
            PlacedObject placedObject = new PlacedObject(key, SkyrimRelease.SkyrimSE);

            // Simplistic Disable access and verification.
            PlacedObject disabledObj = placedObject;

            disabledObj.Disable();
            //_testOutputHelper.WriteLine($"{disabledPlacedObject.MajorRecordFlagsRaw}");
            Assert.True(EnumExt.HasFlag(disabledObj.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            MajorRecord majorRecord = placedObject;

            majorRecord.Disable();
            Assert.True(EnumExt.HasFlag(majorRecord.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            IMajorRecordCommon interfaceRecord = placedObject;

            interfaceRecord.Disable();
            Assert.True(EnumExt.HasFlag(interfaceRecord.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            IPlaced interfacePlaced = placedObject;

            interfacePlaced.Disable();
            Assert.True(EnumExt.HasFlag(interfacePlaced.MajorRecordFlagsRaw, Constants.InitiallyDisabled));

            // Sanity test both API are invokable under Placed context.
            PlacedTrap placedTrap = new PlacedTrap(key, SkyrimRelease.SkyrimSE);

            placedTrap.Disable(IPlaced.DisableType.DisableWithoutZOffset);
            interfacePlaced = placedTrap;
            interfacePlaced.Disable(IPlaced.DisableType.JustInitiallyDisabled);
            IPlaced abstractPlaced = placedTrap;

            abstractPlaced.Disable();
            abstractPlaced.Disable(IPlaced.DisableType.SafeDisable);

            //Try any other object other than Placed (invoke MajorRecord.Disable() and see if it works)
            var armor = new Armor(key, SkyrimRelease.SkyrimSE);

            armor.Disable();
            Assert.True(EnumExt.HasFlag(armor.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
        }
コード例 #11
0
        public void Worldspace_WinningContextOverride_IPlaced()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = worldspace.SubCells.AddReturn(new WorldspaceBlock());
            var subBlock   = block.Items.AddReturn(new WorldspaceSubBlock());
            var cell       = subBlock.Items.AddReturn(new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE));
            var placedObj  = cell.Persistent.AddReturn(new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE));

            worldspace.TopCell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);
            var placedObj2 = worldspace.TopCell.Persistent.AddReturn(new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE));
            var placedObjs = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: null !).ToList();

            placedObjs.Should().HaveCount(2);
            var placed = mod.EnumerateMajorRecordContexts <IPlaced, IPlacedGetter>(linkCache: null !).ToList();

            placed.Should().HaveCount(2);
        }
コード例 #12
0
        public void PlacedInWorldspaceOnlyOverridesPlaced(LinkCacheTestTypes cacheType)
        {
            var prototype = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var placed    = new PlacedObject(prototype);
            var outgoing  = new SkyrimMod(TestConstants.PluginModKey4, SkyrimRelease.SkyrimSE);

            prototype.Worldspaces.Add(new Worldspace(prototype)
            {
                SubCells = new ExtendedList <WorldspaceBlock>()
                {
                    new WorldspaceBlock()
                    {
                        Items = new ExtendedList <WorldspaceSubBlock>()
                        {
                            new WorldspaceSubBlock()
                            {
                                Items = new ExtendedList <Cell>()
                                {
                                    new Cell(prototype)
                                    {
                                        Landscape = new Landscape(prototype),
                                        Temporary = new ExtendedList <IPlaced>()
                                        {
                                            placed
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);
            WrapPotentialThrow(cacheType, style, () =>
            {
                package.TryResolveContext <ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(placed.FormKey, out var rec)
                .Should().BeTrue();
                rec.Record.Should().Be(placed);
                rec.GetOrAddAsOverride(outgoing);
                outgoing.Worldspaces.First().SubCells.First().Items.First().Items.First().Landscape.Should().BeNull();
            });
        }
コード例 #13
0
        public override IDisposable ConvertMod(SkyrimMod mod, out ISkyrimModGetter getter)
        {
            var tempFile = new TempFile(extraDirectoryPaths: TestPathing.TempFolderPath);
            var path     = new ModPath(mod.ModKey, tempFile.File.Path);

            mod.WriteToBinaryParallel(
                path,
                new BinaryWriteParameters()
            {
                ModKey = ModKeyOption.NoCheck,
            });
            var overlay = SkyrimMod.CreateFromBinaryOverlay(path, SkyrimRelease.SkyrimLE);

            getter = overlay;
            return(Disposable.Create(() =>
            {
                overlay.Dispose();
                tempFile.Dispose();
            }));
        }
コード例 #14
0
        public void ResolveLinkIdentifiers(LinkCacheTestTypes cacheType)
        {
            var prototype = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var armor     = prototype.Armors.AddNew();
            var llist     = prototype.LeveledItems.AddNew();

            llist.Entries = new ExtendedList <LeveledItemEntry>()
            {
                new LeveledItemEntry()
                {
                    Data = new LeveledItemEntryData()
                    {
                        Reference = armor.AsLink()
                    }
                }
            };
            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);
            Assert.True(package.TryResolveIdentifier(mod.LeveledItems.First().Entries[0].Data.Reference.FormKey, out _));
        }
コード例 #15
0
        public void FormLink_LoadOrder_ResolveAll_Linked(LinkCacheTestTypes cacheType)
        {
            var mod       = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var npc       = mod.Npcs.AddNew();
            var loadOrder = new LoadOrder <ISkyrimModGetter>()
            {
                mod,
                new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimLE),
            };

            var(style, package) = GetLinkCache(loadOrder, cacheType);
            var formLink = new FormLink <INpcGetter>(npc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                var resolved = formLink.ResolveAll(package).ToArray();
                resolved.Should().HaveCount(1);
                resolved.First().Should().BeSameAs(npc);
            });
        }
コード例 #16
0
        public static void IKeyworded()
        {
            void TestFunction <T>()
                where T : IKeywordedGetter <IKeywordGetter>
            {
            }

            void TestFunction2 <T>()
                where T : IKeywordedGetter
            {
            }

            TestFunction <IWeaponGetter>();
            TestFunction2 <IWeaponGetter>();

            var mod = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE);
            IKeyworded <IKeywordGetter> keyworded = mod.Armors.AddNew();

            keyworded.TryResolveKeyword(Utility.Form2, mod.ToImmutableLinkCache(), out var keyword);
        }
コード例 #17
0
        public void AddAThing()
        {
            var generalStores = new SkyrimMod(GeneralStores.ModKey, SkyrimRelease.SkyrimSE);

            var xGSxFoodAllFLST = new FormList(GeneralStores.FormList.xGSxFoodAllFLST.FormKey, SkyrimRelease.SkyrimSE);

            generalStores.FormLists.Add(xGSxFoodAllFLST);

            SkyrimMod masterMod = new(masterModKey, SkyrimRelease.SkyrimSE);

            var newThing = masterMod.MiscItems.AddNew("newItem");

            SkyrimMod patchMod = new(patchModKey, SkyrimRelease.SkyrimSE);

            var loadOrder = new LoadOrder <IModListing <ISkyrimModGetter> >
            {
                new ModListing <ISkyrimModGetter>(generalStores, true),
                new ModListing <ISkyrimModGetter>(masterMod, true),
                new ModListing <ISkyrimModGetter>(patchMod, true)
            };

            var linkCache = loadOrder.ToImmutableLinkCache();

            Program program = new(loadOrder, linkCache, patchMod, GameRelease.SkyrimSE);

            program.allFoodSet.Add(newThing.AsLink());

            program.RecordClassifiedItems();

            Assert.Single(patchMod.FormLists);

            var updatedFlst = patchMod.FormLists.Single();

            Assert.Single(updatedFlst.Items);

            var newThingLink = updatedFlst.Items.Single();

            Assert.False(newThingLink.IsNull);

            Assert.Equal(newThing.AsLink(), newThingLink);
        }
コード例 #18
0
ファイル: Write_Tests.cs プロジェクト: erri120/Mutagen
        public void Write_ModNotOnLoadOrder()
        {
            using var tmp = GetFile();
            var mod = new SkyrimMod(WriteKey, SkyrimRelease.SkyrimLE);

            mod.Weapons.RecordCache.Set(
                new Weapon(FormKey.Factory("012345:Skyrim.esm"), SkyrimRelease.SkyrimLE));
            mod.Weapons.RecordCache.Set(
                new Weapon(FormKey.Factory("012345:SomeOtherMod.esp"), SkyrimRelease.SkyrimLE));
            Assert.Throws <MissingModException>(() =>
            {
                mod.WriteToBinary(
                    tmp.File,
                    new BinaryWriteParameters()
                {
                    ModKey              = BinaryWriteParameters.ModKeyOption.NoCheck,
                    MastersListContent  = BinaryWriteParameters.MastersListContentOption.Iterate,
                    MastersListOrdering = new BinaryWriteParameters.MastersListOrderingByLoadOrder(
                        Skyrim.Constants.Skyrim.AsEnumerable())
                });
            });
        }
コード例 #19
0
        public void WinningOverrides_Typical()
        {
            var master         = new SkyrimMod(new ModKey("Base", ModType.Master), SkyrimRelease.SkyrimSE);
            var baseNpc        = master.Npcs.AddNew();
            var otherMasterNpc = master.Npcs.AddNew();
            var plugin         = new SkyrimMod(new ModKey("Plugin", ModType.Plugin), SkyrimRelease.SkyrimSE);
            var pluginNpc      = plugin.Npcs.AddNew();
            var overrideNpc    = (Npc)baseNpc.DeepCopy();

            plugin.Npcs.RecordCache.Set(overrideNpc);
            overrideNpc.Name = "Override";

            var winningOverrides = plugin.AsEnumerable().And(master)
                                   .WinningOverrides <Npc>()
                                   .ToDictionary(n => n.FormKey);

            Assert.Equal(3, winningOverrides.Count);
            Assert.Same(otherMasterNpc, winningOverrides[otherMasterNpc.FormKey]);
            Assert.Same(pluginNpc, winningOverrides[pluginNpc.FormKey]);
            Assert.Equal(overrideNpc.FormKey, baseNpc.FormKey);
            Assert.Same(overrideNpc, winningOverrides[baseNpc.FormKey]);
        }
コード例 #20
0
        public void SubtypeLinking_Typical(LinkCacheTestTypes cacheType)
        {
            var prototype = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var armor     = prototype.Armors.AddNew();
            var llist     = prototype.LeveledItems.AddNew();

            llist.Entries = new ExtendedList <LeveledItemEntry>()
            {
                new LeveledItemEntry()
                {
                    Data = new LeveledItemEntryData()
                    {
                        Reference = armor.AsLink()
                    }
                }
            };
            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(mod.LeveledItems.First().Entries[0].Data.Reference.TryResolve(package, out IArmorGetter armorGetterLink));
            });
        }
コード例 #21
0
        /// <summary>
        /// Shows how to follow a FormID reference to find another record
        /// </summary>
        static void DoSomeLinking(string path)
        {
            // Create a readonly mod object from the file path, using the overlay pattern
            using var mod = SkyrimMod.CreateFromBinaryOverlay(path, SkyrimRelease.SkyrimSE);

            // Create a link cache to store info about all the linking queries we do
            var cache = mod.ToImmutableLinkCache();

            System.Console.WriteLine($"Printing all worn armors that Npcs have:");
            foreach (var npc in mod.Npcs)
            {
                // Attempt to find the armor, using the cache
                if (npc.WornArmor.TryResolve(cache, out var armor))
                {
                    System.Console.WriteLine($"  {npc.EditorID}: {armor.EditorID}.");
                }
                else
                {
                    // Had no armor
                }
            }
            PrintSeparator();
        }
コード例 #22
0
        public void SetModKeys()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Items.Add(cell);

            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.Persistent.Add(placedNpc);
            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.Persistent.Add(placedObj);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray();

            contexts.Should().HaveCount(1);
            contexts[0].ModKey.Should().Be(TestConstants.PluginModKey);
        }
コード例 #23
0
        public void FormLink_Direct_TryResolveContext_DeepRecord_Linked(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var worldspace = mod.Worldspaces.AddNew();
            var subBlock   = new WorldspaceSubBlock();
            var cell       = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            subBlock.Items.Add(cell);
            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            cell.Temporary.Add(placedNpc);
            var block = new WorldspaceBlock();

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var(style, package) = GetLinkCache(mod, cacheType);
            var placedFormLink = new FormLink <IPlacedNpcGetter>(placedNpc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(contextRetriever.TryResolveContext <IPlacedNpc, IPlacedNpcGetter>(placedFormLink, package, out var linkedPlacedNpc));
                linkedPlacedNpc.Record.Should().BeSameAs(placedNpc);
                linkedPlacedNpc.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedPlacedNpc.Parent.Record.Should().Be(cell);
                var cellFormLink = new FormLink <ICellGetter>(cell.FormKey);
                Assert.True(contextRetriever.TryResolveContext <ICell, ICellGetter>(cellFormLink, package, out var linkedCell));
                linkedCell.Record.Should().BeSameAs(cell);
                linkedCell.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedCell.Parent.Record.Should().Be(subBlock);
                var worldspaceFormLink = new FormLink <IWorldspaceGetter>(worldspace.FormKey);
                Assert.True(contextRetriever.TryResolveContext <IWorldspace, IWorldspaceGetter>(worldspaceFormLink, package, out var linkedWorldspace));
                linkedWorldspace.Record.Should().BeSameAs(worldspace);
                linkedWorldspace.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedWorldspace.Parent.Should().BeNull();
            });
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: tstavrianos/SkyrimLib
        private static void Main(string[] args)
        {
            var plugins = Path.Combine(
                Environment.GetEnvironmentVariable("LocalAppData") !, "Skyrim Special Edition/Plugins.txt");
            var gamePath = @"e:\keizaal\Game Root\Data";
            var mods     = new List <Mod>();

            var i = 0;

            foreach (var modName in ParsePlugins(plugins, gamePath))
            {
                mods.Add(new Mod() {
                    Name = modName, OriginalOrder = i
                });
                i++;
            }

            foreach (var mod in mods)
            {
                var m = SkyrimMod.CreateFromBinaryOverlay(Path.Combine(gamePath, mod.Name), SkyrimRelease.SkyrimSE);
                mod.DependsOn = new List <Mod>();
                if (m.MasterReferences is not {
                    Count: > 0
                })
コード例 #25
0
        public void MistypedExtraction()
        {
            var modToExtract = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE);
            var npc          = modToExtract.Npcs.AddNew();
            var race         = modToExtract.Races.AddNew();

            race.CloseLootSound.SetTo(modToExtract.SoundDescriptors.AddNew());
            var unneededRace = modToExtract.Races.AddNew();

            var targetMod = new SkyrimMod(Utility.PluginModKey2, SkyrimRelease.SkyrimSE);

            targetMod.Npcs.Add(npc);
            var safeNpc = targetMod.Npcs.AddNew();

            safeNpc.Race = new FormLink <IRaceGetter>(race.FormKey);

            var linkCache = new MutableLoadOrderLinkCache <ISkyrimMod, ISkyrimModGetter>(modToExtract, targetMod);

            targetMod.DuplicateFromOnlyReferenced(linkCache, modToExtract.ModKey, out var mapping, typeof(IAmmunitionGetter));
            targetMod.EnumerateMajorRecords().Should().HaveCount(2);
            targetMod.Npcs.Should().HaveCount(2);
            targetMod.Npcs.Should().Contain(safeNpc);
            targetMod.Npcs.Should().Contain(npc);
        }
コード例 #26
0
        public static ISkyrimMod GetOrAddPatch(string EspName, bool forLVLI = false)
        {
            if (!(EspName.Contains(Patcher.PatcherSuffix) || EspName.Contains(Patcher.PatcherLLSuffix)))
            {
                var suffix = forLVLI ? Patcher.PatcherLLSuffix : Patcher.PatcherSuffix;
                EspName = EspName.Replace(".esp", "") + suffix;
            }

            ModKey modKey = ModKey.FromNameAndExtension(EspName);

            if (Patches.ContainsKey(modKey.FileName))
            {
                return(Patches.GetValueOrDefault(modKey.FileName));
            }

            ISkyrimMod patch = new SkyrimMod(modKey, SkyrimRelease.SkyrimSE);

            Patches.TryAdd(modKey.FileName, patch);
            Cache.Add(patch);
            //var x = ModListing<ISkyrimModGetter>.CreateEnabled(patch.ModKey);
            //State.LoadOrder.Add((IModListing<ISkyrimModGetter>)x, State.LoadOrder.Count - 2);

            return(patch);
        }
コード例 #27
0
        public void DirectTypical(LinkCacheTestTypes cacheType)
        {
            var prototype  = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var objEffect1 = prototype.ObjectEffects.AddNew("EDID1");
            var objEffect2 = prototype.ObjectEffects.AddNew("EDID2");

            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);

            // Do linked interfaces first, as this tests a specific edge case
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IEffectRecordGetter>(objEffect1.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IEffectRecordGetter>(objEffect1.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IEffectRecordGetter>(objEffect2.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IEffectRecordGetter>(objEffect2.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve(objEffect1.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve(objEffect1.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve(objEffect2.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve(objEffect2.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IMajorRecordGetter>(objEffect1.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IMajorRecordGetter>(objEffect1.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IMajorRecordGetter>(objEffect2.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IMajorRecordGetter>(objEffect2.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <ISkyrimMajorRecordGetter>(objEffect1.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <ISkyrimMajorRecordGetter>(objEffect1.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <ISkyrimMajorRecordGetter>(objEffect2.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <ISkyrimMajorRecordGetter>(objEffect2.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IObjectEffectGetter>(objEffect1.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IObjectEffectGetter>(objEffect1.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect1.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IObjectEffectGetter>(objEffect2.FormKey, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <IObjectEffectGetter>(objEffect2.EditorID, out var rec));
                Assert.Equal(rec.FormKey, objEffect2.FormKey);
            });
            if (ReadOnly)
            {
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <ObjectEffect>(objEffect1.FormKey, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <ObjectEffect>(objEffect2.FormKey, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <IObjectEffect>(objEffect1.FormKey, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <IObjectEffect>(objEffect2.FormKey, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <IEffectRecord>(objEffect1.FormKey, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <IEffectRecord>(objEffect2.FormKey, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <ObjectEffect>(objEffect1.EditorID, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <ObjectEffect>(objEffect2.EditorID, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <IObjectEffect>(objEffect1.EditorID, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <IObjectEffect>(objEffect2.EditorID, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <IEffectRecord>(objEffect1.EditorID, out var _));
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.False(package.TryResolve <IEffectRecord>(objEffect2.EditorID, out var _));
                });

                Assert.False(package.TryResolve <ObjectEffect>(TestConstants.UnusedForm, out var _));
                Assert.False(package.TryResolve <IObjectEffect>(TestConstants.UnusedForm, out var _));
                Assert.False(package.TryResolve <IEffectRecord>(TestConstants.UnusedForm, out var _));
                Assert.False(package.TryResolve <ObjectEffect>(TestConstants.UnusedEdid, out var _));
                Assert.False(package.TryResolve <IObjectEffect>(TestConstants.UnusedEdid, out var _));
                Assert.False(package.TryResolve <IEffectRecord>(TestConstants.UnusedEdid, out var _));
            }
            else
            {
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <ObjectEffect>(objEffect1.FormKey, out var rec));
                    Assert.Equal(rec.FormKey, objEffect1.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <ObjectEffect>(objEffect1.EditorID, out var rec));
                    Assert.Equal(rec.FormKey, objEffect1.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <ObjectEffect>(objEffect2.FormKey, out var rec));
                    Assert.Equal(rec.FormKey, objEffect2.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <ObjectEffect>(objEffect2.EditorID, out var rec));
                    Assert.Equal(rec.FormKey, objEffect2.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <IObjectEffect>(objEffect1.FormKey, out var rec));
                    Assert.Equal(rec.FormKey, objEffect1.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <IObjectEffect>(objEffect1.EditorID, out var rec));
                    Assert.Equal(rec.FormKey, objEffect1.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <IObjectEffect>(objEffect2.FormKey, out var rec));
                    Assert.Equal(rec.FormKey, objEffect2.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <IObjectEffect>(objEffect2.EditorID, out var rec));
                    Assert.Equal(rec.FormKey, objEffect2.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <IEffectRecord>(objEffect1.FormKey, out var rec));
                    Assert.Equal(rec.FormKey, objEffect1.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <IEffectRecord>(objEffect1.EditorID, out var rec));
                    Assert.Equal(rec.FormKey, objEffect1.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <IEffectRecord>(objEffect2.FormKey, out var rec));
                    Assert.Equal(rec.FormKey, objEffect2.FormKey);
                });
                WrapPotentialThrow(cacheType, style, () =>
                {
                    Assert.True(package.TryResolve <IEffectRecord>(objEffect2.EditorID, out var rec));
                    Assert.Equal(rec.FormKey, objEffect2.FormKey);
                });
            }
        }
コード例 #28
0
        public void ComplexOverrides()
        {
            WarmupSkyrim.Init();

            // Construct base mod
            const string Mod1Name   = "Mod1";
            var          mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var          worldspace = mod.Worldspaces.AddNew();

            worldspace.EditorID = Mod1Name;
            var block = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.EditorID = Mod1Name;
            subBlock.Items.Add(cell);

            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            placedObj.EditorID = Mod1Name;
            cell.Persistent.Add(placedObj);

            // Override cell in 2nd mod
            const string Mod2Name    = "Mod2";
            var          mod2        = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var          worldspace2 = new Worldspace(worldspace.FormKey, SkyrimRelease.SkyrimSE);

            worldspace2.EditorID = Mod2Name;
            mod2.Worldspaces.Add(worldspace2);
            var block2 = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock2 = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block2.Items.Add(subBlock2);
            worldspace2.SubCells.Add(block2);
            var cell2 = new Cell(cell.FormKey, SkyrimRelease.SkyrimSE);

            cell2.EditorID = Mod2Name;
            subBlock2.Items.Add(cell2);

            // Override worldspace in 3rd mod
            const string Mod3Name    = "Mod3";
            var          mod3        = new SkyrimMod(TestConstants.PluginModKey3, SkyrimRelease.SkyrimSE);
            var          worldspace3 = new Worldspace(worldspace.FormKey, SkyrimRelease.SkyrimSE);

            worldspace3.EditorID = Mod3Name;
            mod3.Worldspaces.Add(worldspace3);

            // Override in 4th, and check sources
            var loadOrder = new LoadOrder <ISkyrimModGetter>(mod.AsEnumerable().And(mod2).And(mod3));
            var cache     = loadOrder.ToImmutableLinkCache();

            var contexts = mod.EnumerateMajorRecordContexts <IPlaced, IPlacedGetter>(linkCache: cache).ToArray();

            contexts.Should().HaveCount(1);

            var mod4 = new SkyrimMod(TestConstants.PluginModKey4, SkyrimRelease.SkyrimSE);
            var placedObjOverride = contexts[0].GetOrAddAsOverride(mod4);

            placedObjOverride.EditorID.Should().Be(Mod1Name);
            var cellOverride = mod4.Worldspaces.First().SubCells.First().Items.First().Items.First();

            cellOverride.EditorID.Should().Be(Mod2Name);
            var worldspaceOverride = mod4.Worldspaces.First();

            worldspaceOverride.EditorID.Should().Be(Mod3Name);
        }
コード例 #29
0
        public void IPlacedInWorldspace()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);
            var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Items.Add(cell1);
            subBlock.Items.Add(cell2);
            var block2 = new WorldspaceBlock()
            {
                BlockNumberX = 5,
                BlockNumberY = 6,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock2 = new WorldspaceSubBlock()
            {
                BlockNumberX = 8,
                BlockNumberY = 9,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block2.Items.Add(subBlock2);
            worldspace.SubCells.Add(block2);
            var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock2.Items.Add(cell3);

            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell2.Persistent.Add(placedNpc);
            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell2.Persistent.Add(placedObj);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <IPlaced, IPlacedGetter>(linkCache: cache).ToArray();

            Assert.Equal(2, contexts.Length);

            var mod2 = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var placedNpcOverride = contexts[0].GetOrAddAsOverride(mod2);
            var placedObjOverride = contexts[1].GetOrAddAsOverride(mod2);

            Assert.Equal(placedNpc.FormKey, placedNpcOverride.FormKey);
            Assert.Equal(placedObj.FormKey, placedObjOverride.FormKey);
            mod2.Worldspaces.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.First().Items.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.First().Items.First().Items.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.First().Items.First().Items.First().Persistent.Should().HaveCount(2);
            Assert.Same(placedNpcOverride, mod2.Worldspaces.First().SubCells.First().Items.First().Items.First().Persistent.First());
        }
コード例 #30
0
ファイル: MergerTests.cs プロジェクト: erri120/MutagenMerger
        public void TestMerging()
        {
            const string testFolder = "merging-test-folder";

            if (Directory.Exists(testFolder))
            {
                Directory.Delete(testFolder, true);
            }

            var mod1 = MutagenTestHelpers.CreateDummyPlugin(testFolder, "test-file-1.esp", mod =>
            {
                mod.Actions.AddNew("Action1");
                mod.Actions.AddNew("Action2");
            });

            var mod2 = MutagenTestHelpers.CreateDummyPlugin(testFolder, "test-file-2.esp", mod =>
            {
                mod.Actions.AddNew("Action3");
                mod.Actions.AddNew("Action4");
            });

            var mods = new List <ModKey>
            {
                mod1,
                mod2,
            };

            using (var testMod1 =
                       SkyrimMod.CreateFromBinaryOverlay(Path.Combine(testFolder, mod1), SkyrimRelease.SkyrimSE))
            {
                var action1 = testMod1.Actions.First();

                var mod3 = MutagenTestHelpers.CreateDummyPlugin(testFolder, "test-file-3.esp", mod =>
                {
                    var copy      = action1.DeepCopy();
                    copy.EditorID = "Action1x";
                    mod.Actions.Add(copy);
                });

                mods.Add(mod3);
            }

            const string outputFileName = "output.esp";

            using (var merger = new Merger(testFolder, mods, mods, outputFileName))
            {
                merger.Merge();
            }

            var outputFile = Path.Combine(testFolder, outputFileName);

            MutagenTestHelpers.TestPlugin(outputFile, mod =>
            {
                Assert.Equal(4, mod.Actions.Count);

                Assert.Contains(mod.Actions, x => x.EditorID == "Action1x");
                Assert.Contains(mod.Actions, x => x.EditorID == "Action2");
                Assert.Contains(mod.Actions, x => x.EditorID == "Action3");
                Assert.Contains(mod.Actions, x => x.EditorID == "Action4");
            });
        }