Esempio n. 1
0
        public async Task CreatesOutput()
        {
            using var tmpFolder  = Utility.GetTempFolder();
            using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion);
            var settings = new CodeSnippetPatcherSettings()
            {
                On       = true,
                Code     = @"// Let's do work! 
                    int wer = 23; 
                    wer++;",
                Nickname = "UnitTests",
            };
            var outputFile = Utility.TypicalOutputFile(tmpFolder);
            var snippet    = new CodeSnippetPatcherRun(settings);
            await snippet.Prep(GameRelease.Oblivion, CancellationToken.None);

            await snippet.Run(new RunSynthesisPatcher()
            {
                OutputPath        = ModPath.FromPath(outputFile),
                DataFolderPath    = dataFolder.Dir.Path,
                GameRelease       = GameRelease.Oblivion,
                LoadOrderFilePath = Utility.PathToLoadOrderFile,
                SourcePath        = null
            }, CancellationToken.None);

            Assert.True(File.Exists(outputFile));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void DisabledModsInLoadOrder()
        {
            using var tmpFolder  = Utility.GetTempFolder();
            using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.SkyrimSE);
            var pluginsPath = Path.Combine(dataFolder.Dir.Path, "Plugins.txt");

            File.WriteAllLines(
                pluginsPath,
                new string[]
            {
                $"*{Utility.TestModKey.FileName}",
                Utility.OverrideModKey.FileName
            });
            var prevPath = new ModPath(Utility.OverrideModKey, Path.Combine(dataFolder.Dir.Path, Utility.OverrideModKey.FileName));
            var modPath  = PatchModPath(dataFolder);

            using var state = Mutagen.Bethesda.Synthesis.Internal.Utility.ToState <Mutagen.Bethesda.Skyrim.ISkyrimMod, Mutagen.Bethesda.Skyrim.ISkyrimModGetter>(
                      new RunSynthesisMutagenPatcher()
            {
                DataFolderPath    = dataFolder.Dir.Path,
                GameRelease       = Mutagen.Bethesda.GameRelease.SkyrimSE,
                OutputPath        = modPath,
                SourcePath        = prevPath,
                LoadOrderFilePath = pluginsPath
            },
                      new PatcherPreferences(),
                      Synthesis.Bethesda.Constants.SynthesisModKey);
            state.LoadOrder.PriorityOrder.Should().HaveCount(2);
            state.RawLoadOrder.Should().HaveCount(3);
            state.RawLoadOrder[0].Should().Be(new LoadOrderListing(Utility.TestModKey, true));
            state.RawLoadOrder[1].Should().Be(new LoadOrderListing(Utility.OverrideModKey, false));
            state.RawLoadOrder[2].Should().Be(new LoadOrderListing(Utility.SynthesisModKey, true));
        }
Esempio n. 4
0
        public async Task RunTwice()
        {
            using var tmpFolder  = Utility.GetTempFolder();
            using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion);
            var outputFile = Utility.TypicalOutputFile(tmpFolder);
            var settings   = new CodeSnippetPatcherSettings()
            {
                On       = true,
                Code     = @"state.PatchMod.Npcs.AddNew();",
                Nickname = "UnitTests",
            };

            for (int i = 0; i < 2; i++)
            {
                var snippet = new CodeSnippetPatcherRun(settings);
                await snippet.Prep(GameRelease.Oblivion, CancellationToken.None);

                await snippet.Run(new RunSynthesisPatcher()
                {
                    OutputPath        = ModPath.FromPath(outputFile),
                    DataFolderPath    = dataFolder.Dir.Path,
                    GameRelease       = GameRelease.Oblivion,
                    LoadOrderFilePath = Utility.PathToLoadOrderFile,
                    SourcePath        = i == 1 ? outputFile.Path : null
                }, CancellationToken.None);
            }
            using var mod = OblivionMod.CreateFromBinaryOverlay(outputFile);
            Assert.Equal(2, mod.Npcs.Count);
        }
Esempio n. 5
0
 public static async Task <bool> Run <TKey>(
     string workingDirectory,
     ModPath outputPath,
     string dataFolder,
     IEnumerable <LoadOrderListing> loadOrder,
     GameRelease release,
     IEnumerable <(TKey Key, IPatcherRun Run)> patchers,
Esempio n. 6
0
 public override IRegionGetter Get(ModPath path)
 {
     return(Region.CreateFromBinary(
                TestDataPathing.GetReadFrame(
                    path,
                    GameRelease.SkyrimSE)));
 }
Esempio n. 7
0
        /// <summary>
        /// Constructs a load order from a list of mods and a data folder.
        /// Load Order is sorted to the order the game will load the mod files: by file's date modified timestamp.
        /// </summary>
        /// <param name="incomingLoadOrder">Mods to include</param>
        /// <param name="dataPath">Path to data folder</param>
        /// <param name="throwOnMissingMods">Whether to throw and exception if mods are missing</param>
        /// <returns>Enumerable of modkeys in load order, excluding missing mods</returns>
        /// <exception cref="MissingModException">If throwOnMissingMods true and file is missing</exception>
        public static IEnumerable <IModListingGetter> AlignToTimestamps(
            IEnumerable <IModListingGetter> incomingLoadOrder,
            DirectoryPath dataPath,
            bool throwOnMissingMods = true)
        {
            var list = new List <(bool Enabled, ModKey ModKey, DateTime Write)>();

            foreach (var key in incomingLoadOrder)
            {
                ModPath modPath = new ModPath(key.ModKey, Path.Combine(dataPath.Path, key.ModKey.FileName));
                if (!modPath.Path.Exists)
                {
                    if (throwOnMissingMods)
                    {
                        throw new MissingModException(modPath);
                    }
                    continue;
                }
                list.Add((key.Enabled, key.ModKey, File.GetLastWriteTime(modPath.Path.Path)));
            }
            var comp = new LoadOrderTimestampComparer(incomingLoadOrder.Select(i => i.ModKey).ToList());

            return(list
                   .OrderBy(i => (i.ModKey, i.Write), comp)
                   .Select(i => new ModListing(i.ModKey, i.Enabled)));
        }
        public void ExceptionDisposesExistingMods()
        {
            var dataFolder = "C:/DataFolder";
            var modPaths   = new ModKey[]
            {
                TestConstants.MasterModKey,
                TestConstants.MasterModKey2,
            }
            .Select(x => ModPath.FromPath(Path.Combine(dataFolder, x.FileName)))
            .ToArray();
            var fs = Substitute.For <IFileSystem>();

            fs.File.Exists(Arg.Any <string>()).Returns(true);
            var importer = Substitute.For <IModImporter <IModDisposeGetter> >();
            var mod      = Substitute.For <IModDisposeGetter>();

            importer.Import(modPaths.First()).Returns(mod);
            importer.Import(modPaths.Last()).Throws(new ArgumentException());
            Assert.Throws <AggregateException>(() =>
            {
                new LoadOrderImporter <IModDisposeGetter>(
                    fs,
                    new DataDirectoryInjection(dataFolder),
                    new LoadOrderListingsInjection(modPaths.Select(x => x.ModKey).ToArray()),
                    importer)
                .Import();
            });
            mod.Received().Dispose();
        }
Esempio n. 9
0
        public void TrimsPostSynthesisFromLoadOrder()
        {
            using var tmpFolder  = Utility.GetTempFolder();
            using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.SkyrimLE);
            var pluginsPath = Path.Combine(dataFolder.Dir.Path, "Plugins.txt");

            File.WriteAllLines(
                pluginsPath,
                new string[]
            {
                Utility.TestModKey.FileName,
                Utility.OverrideModKey.FileName,
                Constants.SynthesisModKey.FileName,
                Utility.RandomModKey.FileName
            });
            var prevPath = new ModPath(Utility.OverrideModKey, Path.Combine(dataFolder.Dir.Path, Utility.OverrideModKey.FileName));
            var modPath  = PatchModPath(dataFolder);

            using var state = Mutagen.Bethesda.Synthesis.Internal.Utility.ToState <Mutagen.Bethesda.Skyrim.ISkyrimMod, Mutagen.Bethesda.Skyrim.ISkyrimModGetter>(
                      new RunSynthesisMutagenPatcher()
            {
                DataFolderPath    = dataFolder.Dir.Path,
                GameRelease       = Mutagen.Bethesda.GameRelease.SkyrimLE,
                OutputPath        = modPath,
                SourcePath        = prevPath,
                LoadOrderFilePath = pluginsPath
            },
                      new PatcherPreferences(),
                      Synthesis.Bethesda.Constants.SynthesisModKey);
            Assert.Equal(3, state.LoadOrder.Count);
            Assert.Equal(Utility.TestModKey, state.LoadOrder[0].ModKey);
            Assert.Equal(Utility.OverrideModKey, state.LoadOrder[1].ModKey);
            Assert.Equal(Constants.SynthesisModKey, state.LoadOrder[2].ModKey);
        }
Esempio n. 10
0
 public async Task OutputFileExistsReturnsOutputPath(
     IPatcherRun patcher,
     ModPath existingOutput,
     FinalizePatcherRun sut)
 {
     sut.Finalize(patcher, existingOutput)
     .Should().Be(existingOutput.Path);
 }
Esempio n. 11
0
 public async Task OutputFileMissingReturnsNull(
     IPatcherRun patcher,
     ModPath missingOutput,
     FinalizePatcherRun sut)
 {
     sut.Finalize(patcher, missingOutput)
     .Should().BeNull();
 }
Esempio n. 12
0
        public override IRegionGetter Get(ModPath path)
        {
            var overlayStream = TestDataPathing.GetOverlayStream(path.Path, GameRelease.SkyrimSE);

            return(RegionBinaryOverlay.RegionFactory(
                       overlayStream,
                       new BinaryOverlayFactoryPackage(overlayStream.MetaData)));
        }
Esempio n. 13
0
 public static OverlayStream GetOverlayStream(ModPath path, GameRelease release, ModKey?modKey = null)
 {
     return(new OverlayStream(
                File.ReadAllBytes(path),
                new ParsingBundle(
                    GameConstants.Get(release),
                    new MasterReferenceReader(
                        modKey ?? path.ModKey))));
 }
Esempio n. 14
0
 public void HasValueButDoesNotExistThrows(
     ModPath missingPath,
     EnsureSourcePathExists sut)
 {
     Assert.Throws <FileNotFoundException>(() =>
     {
         sut.Ensure(missingPath);
     });
 }
Esempio n. 15
0
 public static MutagenFrame GetReadFrame(ModPath path, GameRelease release, ModKey?modKey = null)
 {
     return(new MutagenFrame(
                new MutagenBinaryReadStream(
                    File.OpenRead(path),
                    new ParsingBundle(
                        release,
                        new MasterReferenceReader(modKey ?? path.ModKey)))));
 }
Esempio n. 16
0
 public BubbleGuy(bool bIsThought, string sText, string sModDir) : this()
 {
     ModPath.Set(sModDir);
     _IsThought.Value = bIsThought;
     _IsThought.MarkDirty();
     _PlayerId.Value = Game1.player.UniqueMultiplayerID;
     _PlayerId.MarkDirty();
     SetTexture();
     Text = sText;
 }
 public void ReturnsListFromProvider(
     IEnumerable <IModListingGetter> listings,
     IReadOnlySet <ModKey> blacklist,
     ModPath outputPath,
     LoadOrderForRunProvider sut)
 {
     sut.LoadOrderListingsProvider.Get(blacklist).Returns(listings);
     sut.Get(outputPath, blacklist)
     .Should().Equal(listings);
 }
        bool ChangeModPath(IAbsoluteDirectoryPath value)
        {
            if (ModPath != null && ModPath.Equals(value))
            {
                return(false);
            }

            ModPath = value;
            return(true);
        }
Esempio n. 19
0
        protected override IWorldspaceGetter Get(IFileSystem fileSystem, ModPath path)
        {
            var bytes = fileSystem.File.ReadAllBytes(path);

            return(WorldspaceBinaryOverlay.WorldspaceFactory(
                       bytes,
                       new BinaryOverlayFactoryPackage(
                           new ParsingBundle(
                               GameConstants.SkyrimSE,
                               null !))));
        }
Esempio n. 20
0
        public override object?ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value)
        {
            switch (value)
            {
            case string str:
                return(ModPath.FromPath(str));

            default:
                return(new NotImplementedException());
            }
        }
Esempio n. 21
0
 /// <summary>
 /// Constructor that opens a read stream to a path
 /// </summary>
 /// <param name="path">Path to read from</param>
 /// <param name="release">Game Release the stream is for</param>
 /// <param name="bufferSize">Size of internal buffer</param>
 /// <param name="offsetReference">Optional offset reference position to use</param>
 public MutagenBinaryReadStream(
     ModPath path,
     GameRelease release,
     int bufferSize       = 4096,
     long offsetReference = 0)
     : base(path, bufferSize)
 {
     this._path    = path;
     this.MetaData = new ParsingBundle(release, MasterReferenceReader.FromPath(path, release))
     {
         ModKey = path.ModKey
     };
     this.OffsetReference = offsetReference;
 }
Esempio n. 22
0
 /// <summary>
 /// Constructor that opens a read stream to a path
 /// </summary>
 /// <param name="path">Path to read from</param>
 /// <param name="release">Game Release the stream is for</param>
 /// <param name="bufferSize">Size of internal buffer</param>
 /// <param name="offsetReference">Optional offset reference position to use</param>
 /// <param name="fileSystem">FileSystem to read from</param>
 public MutagenBinaryReadStream(
     ModPath path,
     GameRelease release,
     int bufferSize         = 4096,
     long offsetReference   = 0,
     IFileSystem?fileSystem = null)
     : base(fileSystem.GetOrDefault().File.OpenRead(path), bufferSize)
 {
     this._path    = path;
     this.MetaData = new ParsingBundle(release, MasterReferenceReader.FromPath(path, release, fileSystem: fileSystem))
     {
         ModKey = path.ModKey
     };
     this.OffsetReference = offsetReference;
 }
 public bool Equals(Mod other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     if (ModPath == null)
     {
         return(false);                 // RCW mods will not set a mod path
     }
     return(ModPath.Equals(other.ModPath, StringComparison.InvariantCultureIgnoreCase));
 }
        public void TrimsPastOutputPath(
            IEnumerable <IModListingGetter> listingsFirst,
            IEnumerable <IModListingGetter> listingsSecond,
            IReadOnlySet <ModKey> blacklist,
            ModPath outputPath,
            LoadOrderForRunProvider sut)
        {
            var modListingGetter = new ModListing(outputPath, true);

            sut.LoadOrderListingsProvider.Get(blacklist).Returns(
                listingsFirst
                .And(modListingGetter)
                .Concat(listingsSecond));
            sut.Get(outputPath, blacklist)
            .Should().Equal(listingsFirst);
        }
        public void ExistingNameQueriesModPath(
            FilePath filePath,
            ModKey modKey,
            ISpecimenContext context,
            ModPathParameterBuilder sut)
        {
            var modPath = new ModPath(modKey, filePath);

            context.MockToReturn(modPath);
            foreach (var method in typeof(ExistingName).Methods())
            {
                var param = method.GetParameters().First();
                context.ClearReceivedCalls();
                sut.Create(param, context);
                context.ShouldHaveCreated <ModPath>();
            }
        }
Esempio n. 26
0
        public void HasSourceModOnLoadOrder_HasSource()
        {
            using var tmpFolder  = Utility.GetTempFolder();
            using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion);
            var prevPath = new ModPath(Utility.OverrideModKey, Path.Combine(dataFolder.Dir.Path, Utility.OverrideModKey.FileName));
            var modPath  = PatchModPath(dataFolder);

            using var state = Mutagen.Bethesda.Synthesis.Internal.Utility.ToState <IOblivionMod, IOblivionModGetter>(
                      new RunSynthesisMutagenPatcher()
            {
                DataFolderPath    = dataFolder.Dir.Path,
                GameRelease       = Mutagen.Bethesda.GameRelease.Oblivion,
                OutputPath        = modPath,
                SourcePath        = prevPath,
                LoadOrderFilePath = Utility.PathToLoadOrderFile
            },
                      new UserPreferences());
            Assert.Equal(state.PatchMod.ModKey, state.LoadOrder.Last().Key);
        }
        public void ExistingNameCallsToMakeExist(
            FilePath filePath,
            ModKey modKey,
            ISpecimenContext context,
            ModPathParameterBuilder sut)
        {
            var modPath = new ModPath(modKey, filePath);

            context.MockToReturn(modPath);
            foreach (var method in typeof(ExistingName).Methods())
            {
                var param = method.GetParameters().First();
                sut.MakeModExist.ClearReceivedCalls();
                ModPath mk = (ModPath)sut.Create(param, context);
                sut.MakeModExist
                .Received(1)
                .MakeExist(mk, context);
            }
        }
Esempio n. 28
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();
            }));
        }
Esempio n. 29
0
        public async Task Setup()
        {
            // Load Settings
            System.Console.WriteLine("Running in directory: " + Directory.GetCurrentDirectory());
            FilePath settingsPath = "../../../../TestingSettings.xml";

            System.Console.WriteLine("Settings path: " + settingsPath);
            Settings = JsonConvert.DeserializeObject <TestingSettings>(File.ReadAllText(settingsPath.Path));
            System.Console.WriteLine("Target settings: " + Settings.ToString());

            // Setup folders and paths
            DataPath = new ModPath(
                new ModKey("Oblivion", ModType.Master),
                Path.Combine(Settings.DataFolderLocations.Oblivion, "Oblivion.esm"));
            TempFolder = new TempFolder(deleteAfter: true);
            BinaryPath = Path.Combine(TempFolder.Dir.Path, "Oblivion.esm");

            // Setup
            Mod = OblivionMod.CreateFromBinary(DataPath);

            DataOutput = new MemoryStream(new byte[new FileInfo(DataPath.Path).Length]);
        }
Esempio n. 30
0
 public static async Task <bool> Run(
     string workingDirectory,
     ModPath outputPath,
     string dataFolder,
     IEnumerable <LoadOrderListing> loadOrder,
     GameRelease release,
     IEnumerable <IPatcherRun> patchers,
     ModPath?sourcePath             = null,
     CancellationToken?cancellation = null,
     IRunReporter?reporter          = null)
 {
     return(await Run <object?>(
                workingDirectory : workingDirectory,
                outputPath : outputPath,
                dataFolder : dataFolder,
                loadOrder : loadOrder,
                release : release,
                patchers : patchers.Select(p => (default(object?), p)),
                reporter : new WrapReporter(reporter ?? ThrowReporter.Instance),
                sourcePath : sourcePath,
                cancellation : cancellation));
 }