public static MasterReferenceReader ConstructWriteMasters(IModGetter mod, BinaryWriteParameters param) { MasterReferenceReader ret = new MasterReferenceReader(mod.ModKey); HashSet <ModKey> modKeys = new HashSet <ModKey>(); switch (param.MastersListSync) { case BinaryWriteParameters.MastersListSyncOption.NoCheck: modKeys.Add(mod.MasterReferences.Select(m => m.Master)); break; case BinaryWriteParameters.MastersListSyncOption.Iterate: modKeys.Add( // All FormKeys of links mod.LinkFormKeys.Select(f => f.ModKey) // All FormKeys of records themselves .And(mod.EnumerateMajorRecords().Select(m => m.FormKey.ModKey))); break; default: throw new NotImplementedException(); } modKeys.Remove(mod.ModKey); modKeys.Remove(ModKey.Null); ret.SetTo(modKeys.Select(m => new MasterReference() { Master = m })); return(ret); }
/// <summary> /// Aligns a mod's ModKey to a path's implied ModKey. /// Will adjust its logic based on the MasterFlagSync option: /// - ThrowIfMisaligned: If the path and mod do not match, throw. /// - CorrectToPath: If the path and mod do not match, use path's key. /// </summary> /// <param name="mod">Mod to check and adjust</param> /// <param name="path">Path to compare to</param> /// <returns>ModKey to use</returns> /// <exception cref="ArgumentException">If misaligned and set to ThrowIfMisaligned</exception> public ModKey RunMasterMatch(IModGetter mod, string path) { if (ModKey == ModKeyOption.NoCheck) { return(mod.ModKey); } if (!Bethesda.ModKey.TryFromNameAndExtension(Path.GetFileName(path), out var pathModKey)) { throw new ArgumentException($"Could not convert path to a ModKey to compare against: {Path.GetFileName(path)}"); } switch (ModKey) { case ModKeyOption.ThrowIfMisaligned: if (mod.ModKey != pathModKey) { throw new ArgumentException($"ModKeys were misaligned: {mod.ModKey} != {pathModKey}"); } return(mod.ModKey); case ModKeyOption.CorrectToPath: return(pathModKey); default: throw new NotImplementedException(); } }
public ImmutableModLinkCache(IModGetter sourceMod, LinkCachePreferences?prefs = null) { _sourceMod = sourceMod; var simple = prefs is LinkCachePreferenceOnlyIdentifiers; var category = sourceMod.GameRelease.ToCategory(); _cache = new InternalImmutableModLinkCache(sourceMod, prefs); _formKeyContexts = new ImmutableModLinkCacheSimpleContextCategory <FormKey>( simple: simple, linkCache: this, category: category, contextEnumerable: sourceMod, keyGetter: m => TryGet <FormKey> .Succeed(m.FormKey), shortCircuit: f => f.IsNull); _editorIdContexts = new ImmutableModLinkCacheSimpleContextCategory <string>( simple: simple, linkCache: this, category: category, contextEnumerable: sourceMod, keyGetter: m => { var edid = m.EditorID; return(TryGet <string> .Create(successful: !string.IsNullOrWhiteSpace(edid), edid !)); }, shortCircuit: e => e.IsNullOrWhitespace()); }
private bool TryLinkToMod( IModGetter mod, [MaybeNullWhen(false)] out TMajor item) { if (this.EDID == Null) { item = default !;
private ModHeaderWriteLogic( BinaryWriteParameters?param, IModGetter mod, IModHeaderCommon modHeader) { _params = param ?? BinaryWriteParameters.Default; _modKey = mod.ModKey; _nextFormID = modHeader.MinimumCustomFormID; }
private void AddProcessors( IModGetter mod, IModHeaderCommon modHeader) { ModifyMasterFlags(modHeader); AddMasterCollectionActions(mod); AddRecordCount(); AddNextFormIDActions(); AddFormIDUniqueness(); AddLightMasterFormLimit(modHeader); }
private MasterReferenceReader ConstructWriteMasters(IModGetter mod) { MasterReferenceReader ret = new MasterReferenceReader(mod.ModKey); _modKeys.Remove(mod.ModKey); _modKeys.Remove(ModKey.Null); var modKeysList = _modKeys.Keys.ToList(); SortMasters(modKeysList); ret.SetTo(modKeysList.Select(m => new MasterReference() { Master = m })); return(ret); }
public ImmutableModLinkCache(IModGetter sourceMod, LinkCachePreferences?prefs = null) { _sourceMod = sourceMod; Category = sourceMod.GameRelease.ToCategory(); _simple = prefs is LinkCachePreferenceOnlyIdentifiers; _formKeyCache = new ImmutableModLinkCacheCategory <FormKey>( this, x => TryGet <FormKey> .Succeed(x.FormKey), x => x.IsNull); _editorIdCache = new ImmutableModLinkCacheCategory <string>( this, m => { var edid = m.EditorID; return(TryGet <string> .Create(successful: !string.IsNullOrWhiteSpace(edid), edid !)); },
public static void WriteHeader( BinaryWriteParameters?param, MutagenWriter writer, IModGetter mod, IModHeaderCommon modHeader, ModKey modKey) { var modHeaderWriter = new ModHeaderWriteLogic( param: param, mod: mod, modHeader: modHeader); modHeaderWriter.AddProcessors(mod, modHeader); modHeaderWriter.RunProcessors(mod); modHeaderWriter.PostProcessAdjustments(writer, mod, modHeader); modHeader.WriteToBinary(writer); }
public static void WriteToFile(string path, IModGetter mod) { WriteToFile( path, mod.NextFormID, mod.EnumerateMajorRecords() .SelectWhere(m => { var edid = m.EditorID; if (edid == null) { return(TryGet <KeyValuePair <string, FormKey> > .Failure); } return(TryGet <KeyValuePair <string, FormKey> > .Succeed( new KeyValuePair <string, FormKey>(edid, m.FormKey))); })); }
private void AddMasterCollectionActions(IModGetter mod) { switch (_params.MastersListContent) { case BinaryWriteParameters.MastersListContentOption.NoCheck: _modKeys.Set(mod.MasterReferences.Select(m => new KeyValuePair <ModKey, FormKey>(m.Master, FormKey.Null))); break; case BinaryWriteParameters.MastersListContentOption.Iterate: _recordIterationActions.Add(maj => _modKeys[maj.FormKey.ModKey] = maj.FormKey); _formLinkIterationActions.Add((maj, formLink) => _modKeys[formLink.FormKey.ModKey] = maj); break; default: throw new NotImplementedException(); } }
public static void FillEdidLinkCache <T>(IModGetter mod, RecordType recordType, BinaryOverlayFactoryPackage package) where T : IMajorRecordCommonGetter { var group = mod.GetGroupGetter <T>(); var cache = new Dictionary <RecordType, object>(); package.EdidLinkCache[recordType] = cache; foreach (var item in group) { var edid = item.Value.EditorID; if (edid == null) { continue; } if (edid.Length != Constants.HeaderLength) { throw new ArgumentException($"EDID link record type {recordType} had an EDID of improper length: {edid}"); } cache[new RecordType(edid)] = item.Value; } }
private void PostProcessAdjustments( MutagenWriter writer, IModGetter mod, IModHeaderCommon modHeader) { writer.MetaData.MasterReferences = ConstructWriteMasters(mod); modHeader.MasterReferences.SetTo(writer.MetaData.MasterReferences !.Masters.Select(m => m.DeepCopy())); if (_params.RecordCount != BinaryWriteParameters.RecordCountOption.NoCheck) { modHeader.NumRecords = _numRecords; } if (_params.NextFormID != BinaryWriteParameters.NextFormIDOption.NoCheck) { modHeader.NextFormID = _nextFormID + 1; } if (EnumExt.HasFlag(modHeader.RawFlags, (int)ModHeaderCommonFlag.LightMaster) && _uniqueRecordsFromMod > Constants.LightMasterLimit) { throw new ArgumentException($"Light Master Mod contained more originating records than allowed. {_uniqueRecordsFromMod} > {Constants.LightMasterLimit}"); } }
private void RunProcessors(IModGetter mod) { // Do any major record iteration work if (_recordIterationActions.Count > 0 || _formLinkIterationActions.Count > 0) { foreach (var maj in mod.EnumerateMajorRecords()) { foreach (var majAction in _recordIterationActions) { majAction(maj); } foreach (var formKey in maj.ContainedFormLinks) { foreach (var formLinkAction in _formLinkIterationActions) { formLinkAction(maj.FormKey, formKey); } } } } }
protected AGroup(IModGetter getter) { this.SourceMod = null !; }
public Fallout4Group(IModGetter getter) : base(getter) { }
protected AGroup(IModGetter getter) { this._release = getter.GameRelease; this.SourceMod = null !; }
public Group(IModGetter getter) : base(getter) { }
public OblivionGroup(IModGetter getter) : base(getter) { }
/// <summary> /// Creates a Link Cache using a single mod as its link target. <br/> /// Modification of the target Mod is not safe. Internal caches can become incorrect if /// modifications occur on content already cached. /// </summary> /// <param name="mod">Mod to construct the package relative to</param> /// <param name="prefs">Caching preferences</param> /// <returns>LinkPackage attached to given mod</returns> public static ImmutableModLinkCache ToUntypedImmutableLinkCache( this IModGetter mod, LinkCachePreferences?prefs = null) { return(new ImmutableModLinkCache(mod, prefs ?? LinkCachePreferences.Default)); }
public SkyrimGroup(IModGetter getter) : base(getter) { }