public void WriteWithCounterLists() { var param = new BinaryWriteParameters() { ModKey = BinaryWriteParameters.ModKeyOption.NoCheck, MastersListContent = BinaryWriteParameters.MastersListContentOption.Iterate, }; using var tmp = GetFile(); var mod = new SkyrimMod(WriteKey, SkyrimRelease.SkyrimLE); var armor = mod.Armors.AddNew(); mod.WriteToBinaryParallel(tmp.File.Path, param); armor.Keywords = new ExtendedList <IFormLinkGetter <IKeywordGetter> >(); mod.WriteToBinaryParallel(tmp.File.Path, param); armor.Keywords.Add(FormKey.Null); mod.WriteToBinaryParallel(tmp.File.Path, param); for (int i = 0; i < 20000; i++) { armor.Keywords.Add(FormKey.Null); } Assert.Throws <AggregateException>(() => { mod.WriteToBinaryParallel(tmp.File.Path, param); }); }
public void BasicParallelWrite() { using var tmp = GetFile(); var mod = new SkyrimMod(WriteKey, SkyrimRelease.SkyrimLE); var weap = mod.Weapons.AddNew(); mod.WriteToBinaryParallel( tmp.File.Path, new BinaryWriteParameters() { ModKey = BinaryWriteParameters.ModKeyOption.NoCheck, MastersListContent = BinaryWriteParameters.MastersListContentOption.NoCheck }); }
public void Write_MasterFlagSync_Throw() { using var tmp = GetFile(); var mod = new SkyrimMod(BadWriteKey, SkyrimRelease.SkyrimLE); var weap = mod.Weapons.AddNew(); Assert.Throws <ArgumentException>( () => mod.WriteToBinaryParallel( tmp.File.Path, new BinaryWriteParameters() { ModKey = BinaryWriteParameters.ModKeyOption.ThrowIfMisaligned, MastersListContent = BinaryWriteParameters.MastersListContentOption.NoCheck, })); }
public void ParallelWrite_MasterListSync() { 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.WriteToBinaryParallel( tmp.File.Path, new BinaryWriteParameters() { ModKey = BinaryWriteParameters.ModKeyOption.NoCheck, MastersListContent = BinaryWriteParameters.MastersListContentOption.Iterate, }); }
public void ParallelWrite_MasterListSync_Throw() { using var tmp = GetFile(); var mod = new SkyrimMod(WriteKey, SkyrimRelease.SkyrimLE); mod.Weapons.RecordCache.Set( new Weapon(FormKey.Factory("012345:Skyrim.esm"), SkyrimRelease.SkyrimLE)); Assert.Throws <AggregateException>( () => mod.WriteToBinaryParallel( tmp.File.Path, new BinaryWriteParameters() { ModKey = ModKeyOption.NoCheck, MastersListContent = MastersListContentOption.NoCheck, })); }
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> /// 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(); }