Exemple #1
0
        public static void TestPlugin(string path, Action <ISkyrimModDisposableGetter> verify)
        {
            Assert.True(File.Exists(path));

            using var mod = SkyrimMod.CreateFromBinaryOverlay(ModPath.FromPath(path), SkyrimRelease.SkyrimSE);
            verify(mod);
        }
        public void DirectReadOnlyMechanics(LinkCacheTestTypes cacheType)
        {
            var wrapper = SkyrimMod.CreateFromBinaryOverlay(TestDataPathing.SkyrimTestMod, SkyrimRelease.SkyrimSE);

            var(style, package) = GetLinkCache(wrapper, cacheType);
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <INpcGetter>(TestFileFormKey, out var rec));
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(package.TryResolve <INpcGetter>(TestFileEditorID, out var rec));
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.False(package.TryResolve <INpc>(TestFileFormKey, out var rec));
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.False(package.TryResolve <INpc>(TestFileEditorID, out var rec));
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.False(package.TryResolve <Npc>(TestFileFormKey, out var rec));
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.False(package.TryResolve <Npc>(TestFileEditorID, out var rec));
            });
        }
Exemple #3
0
        protected override async Task <IMod> ImportCopyIn(FilePath file)
        {
            var wrapper = SkyrimMod.CreateFromBinaryOverlay(file.Path, GameRelease.ToSkyrimRelease());
            var ret     = new SkyrimMod(this.ModKey, GameRelease.ToSkyrimRelease());

            ret.DeepCopyIn(wrapper);
            return(ret);
        }
Exemple #4
0
        public Form1()
        {
            InitializeComponent();
            using var mod = SkyrimMod.CreateFromBinaryOverlay(@"C:\Program Files (x86)\Steam\steamapps\common\Skyrim Special Edition\Data\Skyrim.esm", SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.First();

            FindMinMax(worldspace);
        }
        /// <summary>
        /// Loops over all weapons, and prints their EditorIDs and FormKeys
        /// </summary>
        static void PrintAllWeapons(string path)
        {
            // Create a readonly mod object from the file path, using the overlay pattern
            using var mod = SkyrimMod.CreateFromBinaryOverlay(path, SkyrimRelease.SkyrimSE);

            // Loop and print
            System.Console.WriteLine($"Printing all weapons:");
            foreach (var weap in mod.Weapons)
            {
                System.Console.WriteLine($"  {weap.EditorID}: {weap.FormKey}");
            }
            PrintSeparator();
        }
        public void DisposedIfException()
        {
            using var tmpFolder = Utility.GetTempFolder(nameof(BinaryOverlay_Tests));
            var modPath = Path.Combine(tmpFolder.Dir.Path, "Test.esp");

            try
            {
                File.WriteAllText(modPath, "DERP");
                var mod = SkyrimMod.CreateFromBinaryOverlay(modPath, SkyrimRelease.SkyrimLE);
            }
            catch (ArgumentException)
            {
            }
            // Assert that file is released from wrapper's internal stream
            File.Delete(modPath);
        }
Exemple #7
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);
        }
Exemple #8
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();
            }));
        }
        /// <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();
        }
Exemple #10
0
        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
                })
Exemple #11
0
        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");
            });
        }
        public void GetOverlayTopLevelGroupByParameterDoesNotThrow()
        {
            var mod = SkyrimMod.CreateFromBinaryOverlay(TestDataPathing.SkyrimTestMod, SkyrimRelease.SkyrimSE);

            mod.GetTopLevelGroup(typeof(INpcGetter));
        }
        public void GetOverlayTopLevelGroupByGenericDoesNotThrow()
        {
            var mod = SkyrimMod.CreateFromBinaryOverlay(TestDataPathing.SkyrimTestMod, SkyrimRelease.SkyrimSE);

            mod.GetTopLevelGroup <INpcGetter>();
        }
        /// <summary>
        /// Some record copying and new record construction.  Writes to an esp
        /// </summary>
        public static void MakeAMod(string inputPath, string outputPath)
        {
            // Create a readonly mod object from the file path, using the overlay pattern
            using var inputMod = SkyrimMod.CreateFromBinaryOverlay(inputPath, SkyrimRelease.SkyrimSE);

            // Create our mod to eventually export
            var outputMod = new SkyrimMod(ModKey.FromNameAndExtension(Path.GetFileName(outputPath)), SkyrimRelease.SkyrimSE);

            // Copy over all existing weapons, while changing their damage
            foreach (var weap in inputMod.Weapons)
            {
                // Make a copy of the readonly record so we can modify it
                var copy = weap.DeepCopy();

                if (copy.BasicStats == null)
                {
                    // Skip any weapon that doesn't have the stats subrecord
                    continue;
                }

                // Bump up the damage!
                copy.BasicStats.Damage += 100;

                // Add to our output mod
                // The record is implicitly an override, as its FormKey originates from Skyrim.esm, not our mod.
                outputMod.Weapons.RecordCache.Set(copy);
                System.Console.WriteLine($"Overriding {copy.EditorID}");
            }

            // Add our own brand new weapon
            // This convenience function creates a new weapon already added to the mod, with a new FormID
            var overpoweredSword = outputMod.Weapons.AddNew();

            overpoweredSword.EditorID   = "MutagenBlade";
            overpoweredSword.Name       = "Mutagen Blade";
            overpoweredSword.BasicStats = new WeaponBasicStats()
            {
                Damage = 9000,
                Weight = 1,
                Value  = 9000,
            };
            // Actually, scrap this.  Too many things to add by hand.  Let's try by using an existing record as a template

            // Let's base our weapon off Skyrim's DraugrSword
            if (inputMod.Weapons.RecordCache.TryGetValue(FormKey.Factory("02C66F:Skyrim.esm"), out var templateSword))
            {
                // Now we can copy in the values we like from our template.  Let's skip the items we already set earlier
                overpoweredSword.DeepCopyIn(
                    templateSword,
                    // We can optionally specify a mask that copies over everything but our earlier items
                    new Weapon.TranslationMask(true)
                {
                    Name       = false,
                    EditorID   = false,
                    BasicStats = false
                });

                // Now we are good to go, as our weapon is already in our mod, and has the values we want
            }
            else
            {
                System.Console.WriteLine("Couldn't create our sword!  The template could not be found.");
                // I guess let's remove it
                outputMod.Weapons.RecordCache.Remove(overpoweredSword);
            }

            // Write out our mod
            outputMod.WriteToBinaryParallel(outputPath);
            System.Console.WriteLine($"Wrote out mod to: {new FilePath(outputPath).Path}");

            PrintSeparator();
        }