Skip to content

Commit

Permalink
Removed ModHeaderCommonFlag
Browse files Browse the repository at this point in the history
Starfield doesn't adhere to it anymore, so there's no longer a common setup to be had
  • Loading branch information
Noggog committed Oct 10, 2023
1 parent e18a544 commit e4d2d29
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 39 deletions.
1 change: 0 additions & 1 deletion Mutagen.Bethesda.Core/Mutagen.Bethesda.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@
<Compile Include="Translations\Binary\Int64BinaryTranslation.cs" />
<Compile Include="Translations\Binary\Int8BinaryTranslation.cs" />
<Compile Include="Translations\Binary\ListBinaryTranslation.cs" />
<Compile Include="Plugins\Records\ModHeaderCommonFlag.cs" />
<Compile Include="Plugins\Records\Quadrant.cs" />
<Compile Include="Strings\StringsLanguageFormat.cs" />
<Compile Include="Strings\StringsFileFormat.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public sealed class ModHeaderWriteLogic
private uint? _nextFormID;
private uint _uniqueRecordsFromMod;
private readonly HashSet<FormKey> _formKeyUniqueness = new();
private readonly GameCategory _category;

private ModHeaderWriteLogic(
BinaryWriteParameters? param,
Expand All @@ -28,6 +29,7 @@ private ModHeaderWriteLogic(
{
_params = param ?? BinaryWriteParameters.Default;
_modKey = mod.ModKey;
_category = mod.GameRelease.ToCategory();
}

public static void WriteHeader(
Expand Down Expand Up @@ -113,7 +115,10 @@ private void PostProcessAdjustments(
{
modHeader.NextFormID = _nextFormID.HasValue ? _nextFormID.Value + 1 : modHeader.MinimumCustomFormID;
}
if (Enums.HasFlag(modHeader.RawFlags, (int)ModHeaderCommonFlag.Light)

var lightIndex = _category.GetLightFlagIndex();
if (lightIndex.HasValue
&& Enums.HasFlag(modHeader.RawFlags, lightIndex.Value)
&& _uniqueRecordsFromMod > Constants.LightMasterLimit)
{
throw new ArgumentException($"Light Master Mod contained more originating records than allowed. {_uniqueRecordsFromMod} > {Constants.LightMasterLimit}");
Expand Down Expand Up @@ -256,21 +261,24 @@ public void ModifyMasterFlags(IModHeaderCommon header)
case MasterFlagOption.NoCheck:
break;
case MasterFlagOption.ChangeToMatchModKey:
header.RawFlags = Enums.SetFlag(header.RawFlags, (int)ModHeaderCommonFlag.Master, _modKey.Type == ModType.Master);
header.RawFlags = Enums.SetFlag(header.RawFlags, _category.GetMasterFlagIndex(), _modKey.Type == ModType.Master);
if (_modKey.Type != ModType.Plugin)
{
header.RawFlags = Enums.SetFlag(header.RawFlags, (int)ModHeaderCommonFlag.Master, true);
header.RawFlags = Enums.SetFlag(header.RawFlags, _category.GetMasterFlagIndex(), true);
}
break;
case MasterFlagOption.ExceptionOnMismatch:
if ((_modKey.Type == ModType.Master) != Enums.HasFlag(header.RawFlags, (int)ModHeaderCommonFlag.Master))
if ((_modKey.Type == ModType.Master) != Enums.HasFlag(header.RawFlags, _category.GetMasterFlagIndex()))
{
throw new ArgumentException($"Master flag did not match ModKey type. ({_modKey})");
}
if ((_modKey.Type == ModType.Light) != Enums.HasFlag(header.RawFlags, (int)ModHeaderCommonFlag.Light))

var lightIndex = _category.GetLightFlagIndex();
if (lightIndex.HasValue && (_modKey.Type == ModType.Light) != Enums.HasFlag(header.RawFlags, lightIndex.Value))
{
throw new ArgumentException($"Light flag did not match ModKey type. ({_modKey})");
}

break;
default:
break;
Expand All @@ -281,7 +289,8 @@ public void ModifyMasterFlags(IModHeaderCommon header)
#region Light Master Form Limit
private void AddLightFormLimit(IModHeaderCommon header)
{
if (!Enums.HasFlag(header.RawFlags, (int)ModHeaderCommonFlag.Light)) return;
var lightIndex = _category.GetLightFlagIndex();
if (!lightIndex.HasValue || !Enums.HasFlag(header.RawFlags, lightIndex.Value)) return;
_recordIterationActions.Add(maj =>
{
if (maj.FormKey.ModKey == _modKey)
Expand Down
9 changes: 0 additions & 9 deletions Mutagen.Bethesda.Core/Plugins/Records/ModHeaderCommonFlag.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public partial class RecordTypeInts
public const int CSTY = 0x59545343;
public const int CTDA = 0x41445443;
public const int CUR3 = 0x33525543;
public const int CURV = 0x56525543;
public const int DATA = 0x41544144;
public const int DEBR = 0x52424544;
public const int DFOB = 0x424F4644;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public partial class RecordTypes
public static readonly RecordType CSTY = new(0x59545343);
public static readonly RecordType CTDA = new(0x41445443);
public static readonly RecordType CUR3 = new(0x33525543);
public static readonly RecordType CURV = new(0x56525543);
public static readonly RecordType DATA = new(0x41544144);
public static readonly RecordType DEBR = new(0x52424544);
public static readonly RecordType DFOB = new(0x424F4644);
Expand Down
12 changes: 6 additions & 6 deletions Mutagen.Bethesda.Fallout4/Records/Fallout4Mod_Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6681,7 +6681,7 @@ public static Fallout4Mod CreateFromBinary(
throw new ArgumentException("File stream was too short to parse flags");
}
var flags = reader.GetInt32(offset: 8);
if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))
if (Enums.HasFlag(flags, (int)Fallout4ModHeader.HeaderFlag.Localized))
{
frame.MetaData.StringsLookup = StringsFolderLookupOverlay.TypicalFactory(GameRelease.Fallout4, path.ModKey, Path.GetDirectoryName(path.Path)!, stringsParam);
}
Expand Down Expand Up @@ -6718,7 +6718,7 @@ public static Fallout4Mod CreateFromBinary(
throw new ArgumentException("File stream was too short to parse flags");
}
var flags = reader.GetInt32(offset: 8);
if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))
if (Enums.HasFlag(flags, (int)Fallout4ModHeader.HeaderFlag.Localized))
{
frame.MetaData.StringsLookup = StringsFolderLookupOverlay.TypicalFactory(GameRelease.Fallout4, path.ModKey, Path.GetDirectoryName(path.Path)!, stringsParam);
}
Expand Down Expand Up @@ -7334,7 +7334,7 @@ public static void WriteToBinaryParallel(
var modKey = param.RunMasterMatch(
mod: item,
path: path);
param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, (int)ModHeaderCommonFlag.Localized) ? new StringsWriter(GameRelease.Fallout4, modKey, Path.Combine(Path.GetDirectoryName(path)!, "Strings"), MutagenEncodingProvider.Instance) : null;
param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, item.GameRelease.ToCategory().GetLocalizedFlagIndex()!.Value) ? new StringsWriter(GameRelease.Fallout4, modKey, Path.Combine(Path.GetDirectoryName(path)!, "Strings"), MutagenEncodingProvider.Instance) : null;
bool disposeStrings = param.StringsWriter != null;
using (var stream = fileSystem.GetOrDefault().FileStream.New(path, FileMode.Create, FileAccess.Write))
{
Expand Down Expand Up @@ -7642,7 +7642,7 @@ public static void CopyInFromBinary(
throw new ArgumentException("File stream was too short to parse flags");
}
var flags = reader.GetInt32(offset: 8);
if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))
if (Enums.HasFlag(flags, (int)Fallout4ModHeader.HeaderFlag.Localized))
{
frame.MetaData.StringsLookup = StringsFolderLookupOverlay.TypicalFactory(GameRelease.Fallout4, path.ModKey, Path.GetDirectoryName(path.Path)!, stringsParam);
}
Expand Down Expand Up @@ -24329,7 +24329,7 @@ public static void WriteToBinary(
var modKey = param.RunMasterMatch(
mod: item,
path: path);
param.StringsWriter ??= (Enums.HasFlag((int)item.ModHeader.Flags, (int)ModHeaderCommonFlag.Localized) ? new StringsWriter(GameRelease.Fallout4, modKey, Path.Combine(Path.GetDirectoryName(path)!, "Strings"), MutagenEncodingProvider.Instance) : null);
param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, (int)Fallout4ModHeader.HeaderFlag.Localized) ? new StringsWriter(GameRelease.Fallout4, modKey, Path.Combine(Path.GetDirectoryName(path)!, "Strings"), MutagenEncodingProvider.Instance) : null;
bool disposeStrings = param.StringsWriter != null;
var bundle = new WritingBundle(GameRelease.Fallout4)
{
Expand Down Expand Up @@ -25121,7 +25121,7 @@ public static Fallout4ModBinaryOverlay Fallout4ModFactory(
throw new ArgumentException("File stream was too short to parse flags");
}
var flags = stream.GetInt32(offset: 8);
if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))
if (Enums.HasFlag(flags, (int)Fallout4ModHeader.HeaderFlag.Localized))
{
meta.StringsLookup = StringsFolderLookupOverlay.TypicalFactory(GameRelease.Fallout4, path.ModKey, Path.GetDirectoryName(path.Path)!, stringsParam);
}
Expand Down
2 changes: 1 addition & 1 deletion Mutagen.Bethesda.Generation/Modules/Plugin/ModModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public override async Task GenerateInCommonMixin(ObjectGeneration obj, Structure
}
if (obj.GetObjectData().UsesStringFiles)
{
sb.AppendLine($"param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, (int)ModHeaderCommonFlag.Localized) ? new StringsWriter({gameReleaseStr}, modKey, Path.Combine(Path.GetDirectoryName(path)!, \"Strings\"), {nameof(MutagenEncodingProvider)}.{nameof(MutagenEncodingProvider.Instance)}) : null;");
sb.AppendLine($"param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, item.GameRelease.ToCategory().GetLocalizedFlagIndex()!.Value) ? new StringsWriter({gameReleaseStr}, modKey, Path.Combine(Path.GetDirectoryName(path)!, \"Strings\"), {nameof(MutagenEncodingProvider)}.{nameof(MutagenEncodingProvider.Instance)}) : null;");
sb.AppendLine("bool disposeStrings = param.StringsWriter != null;");
}
sb.AppendLine("using (var stream = fileSystem.GetOrDefault().FileStream.New(path, FileMode.Create, FileAccess.Write))");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private void ConvertFromPathOut(ObjectGeneration obj, StructuredStringBuilder sb
}
if (objData.UsesStringFiles)
{
sb.AppendLine($"param.StringsWriter ??= (Enums.HasFlag((int)item.ModHeader.Flags, (int)ModHeaderCommonFlag.Localized) ? new StringsWriter({gameReleaseStr}, modKey, Path.Combine(Path.GetDirectoryName(path)!, \"Strings\"), {nameof(MutagenEncodingProvider)}.{nameof(MutagenEncodingProvider.Instance)}) : null);");
sb.AppendLine($"param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, (int){obj.GetObjectData().GameCategory}ModHeader.HeaderFlag.Localized) ? new StringsWriter({gameReleaseStr}, modKey, Path.Combine(Path.GetDirectoryName(path)!, \"Strings\"), {nameof(MutagenEncodingProvider)}.{nameof(MutagenEncodingProvider.Instance)}) : null;");
sb.AppendLine("bool disposeStrings = param.StringsWriter != null;");
}
sb.AppendLine($"var bundle = new {nameof(WritingBundle)}({gameReleaseStr})");
Expand Down Expand Up @@ -481,7 +481,7 @@ private void ConvertFromPathIn(ObjectGeneration obj, StructuredStringBuilder sb,
sb.AppendLine($"throw new ArgumentException(\"File stream was too short to parse flags\");");
}
sb.AppendLine($"var flags = reader.GetInt32(offset: 8);");
sb.AppendLine($"if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))");
sb.AppendLine($"if (Enums.HasFlag(flags, (int){obj.GetObjectData().GameCategory}ModHeader.HeaderFlag.Localized))");
using (sb.CurlyBrace())
{
sb.AppendLine($"frame.{nameof(BinaryOverlayFactoryPackage.MetaData)}.{nameof(ParsingBundle.StringsLookup)} = StringsFolderLookupOverlay.TypicalFactory({gameReleaseStr}, path.{nameof(ModPath.ModKey)}, Path.GetDirectoryName(path.{nameof(ModPath.Path)})!, stringsParam);");
Expand Down Expand Up @@ -2472,7 +2472,7 @@ await typeGen.GenerateWrapperCtor(
sb.AppendLine($"throw new ArgumentException(\"File stream was too short to parse flags\");");
}
sb.AppendLine($"var flags = stream.GetInt32(offset: 8);");
sb.AppendLine($"if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))");
sb.AppendLine($"if (Enums.HasFlag(flags, (int){obj.GetObjectData().GameCategory}ModHeader.HeaderFlag.Localized))");
using (sb.CurlyBrace())
{
sb.AppendLine($"meta.StringsLookup = StringsFolderLookupOverlay.TypicalFactory({gameReleaseStr}, path.{nameof(ModPath.ModKey)}, Path.GetDirectoryName(path.{nameof(ModPath.Path)})!, stringsParam);");
Expand Down
23 changes: 23 additions & 0 deletions Mutagen.Bethesda.Kernel/GameCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,27 @@ public static GameCategory ToCategory(this GameRelease release)
_ => throw new NotImplementedException(),
};
}

public static int GetMasterFlagIndex(this GameCategory release)
{
return 0x0000_0001;
}

public static int? GetLocalizedFlagIndex(this GameCategory release)
{
return 0x0000_0080;
}

public static int? GetLightFlagIndex(this GameCategory release)
{
switch (release)
{
case GameCategory.Starfield:
return 0x0000_0100;
case GameCategory.Oblivion:
return null;
default:
return 0x0000_0200;
}
}
}
12 changes: 6 additions & 6 deletions Mutagen.Bethesda.Skyrim/Records/SkyrimMod_Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6099,7 +6099,7 @@ public static SkyrimMod CreateFromBinary(
throw new ArgumentException("File stream was too short to parse flags");
}
var flags = reader.GetInt32(offset: 8);
if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))
if (Enums.HasFlag(flags, (int)SkyrimModHeader.HeaderFlag.Localized))
{
frame.MetaData.StringsLookup = StringsFolderLookupOverlay.TypicalFactory(gameRelease, path.ModKey, Path.GetDirectoryName(path.Path)!, stringsParam);
}
Expand Down Expand Up @@ -6139,7 +6139,7 @@ public static SkyrimMod CreateFromBinary(
throw new ArgumentException("File stream was too short to parse flags");
}
var flags = reader.GetInt32(offset: 8);
if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))
if (Enums.HasFlag(flags, (int)SkyrimModHeader.HeaderFlag.Localized))
{
frame.MetaData.StringsLookup = StringsFolderLookupOverlay.TypicalFactory(gameRelease, path.ModKey, Path.GetDirectoryName(path.Path)!, stringsParam);
}
Expand Down Expand Up @@ -6748,7 +6748,7 @@ public static void WriteToBinaryParallel(
var modKey = param.RunMasterMatch(
mod: item,
path: path);
param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, (int)ModHeaderCommonFlag.Localized) ? new StringsWriter(item.GameRelease, modKey, Path.Combine(Path.GetDirectoryName(path)!, "Strings"), MutagenEncodingProvider.Instance) : null;
param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, item.GameRelease.ToCategory().GetLocalizedFlagIndex()!.Value) ? new StringsWriter(item.GameRelease, modKey, Path.Combine(Path.GetDirectoryName(path)!, "Strings"), MutagenEncodingProvider.Instance) : null;
bool disposeStrings = param.StringsWriter != null;
using (var stream = fileSystem.GetOrDefault().FileStream.New(path, FileMode.Create, FileAccess.Write))
{
Expand Down Expand Up @@ -7060,7 +7060,7 @@ public static void CopyInFromBinary(
throw new ArgumentException("File stream was too short to parse flags");
}
var flags = reader.GetInt32(offset: 8);
if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))
if (Enums.HasFlag(flags, (int)SkyrimModHeader.HeaderFlag.Localized))
{
frame.MetaData.StringsLookup = StringsFolderLookupOverlay.TypicalFactory(gameRelease, path.ModKey, Path.GetDirectoryName(path.Path)!, stringsParam);
}
Expand Down Expand Up @@ -22822,7 +22822,7 @@ public static void WriteToBinary(
var modKey = param.RunMasterMatch(
mod: item,
path: path);
param.StringsWriter ??= (Enums.HasFlag((int)item.ModHeader.Flags, (int)ModHeaderCommonFlag.Localized) ? new StringsWriter(item.SkyrimRelease.ToGameRelease(), modKey, Path.Combine(Path.GetDirectoryName(path)!, "Strings"), MutagenEncodingProvider.Instance) : null);
param.StringsWriter ??= Enums.HasFlag((int)item.ModHeader.Flags, (int)SkyrimModHeader.HeaderFlag.Localized) ? new StringsWriter(item.SkyrimRelease.ToGameRelease(), modKey, Path.Combine(Path.GetDirectoryName(path)!, "Strings"), MutagenEncodingProvider.Instance) : null;
bool disposeStrings = param.StringsWriter != null;
var bundle = new WritingBundle(item.SkyrimRelease.ToGameRelease())
{
Expand Down Expand Up @@ -23558,7 +23558,7 @@ public static SkyrimModBinaryOverlay SkyrimModFactory(
throw new ArgumentException("File stream was too short to parse flags");
}
var flags = stream.GetInt32(offset: 8);
if (Enums.HasFlag(flags, (int)ModHeaderCommonFlag.Localized))
if (Enums.HasFlag(flags, (int)SkyrimModHeader.HeaderFlag.Localized))
{
meta.StringsLookup = StringsFolderLookupOverlay.TypicalFactory(release.ToGameRelease(), path.ModKey, Path.GetDirectoryName(path.Path)!, stringsParam);
}
Expand Down
Loading

0 comments on commit e4d2d29

Please sign in to comment.