Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Sep 27, 2024
2 parents 18b8581 + e8f8765 commit e235bbe
Show file tree
Hide file tree
Showing 88 changed files with 22,258 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<VersionPrefix>0.46</VersionPrefix>
<VersionPrefix>0.46.1</VersionPrefix>
<ImplicitUsings>true</ImplicitUsings>
<IsPackable>false</IsPackable>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Mutagen-Modding/Mutagen</PackageProjectUrl>
<RepositoryUrl>https://github.com/Mutagen-Modding/Mutagen</RepositoryUrl>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<Copyright>2023</Copyright>
<Copyright>2024</Copyright>
<Company>Mutagen</Company>
<Product>Mutagen</Product>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
1 change: 1 addition & 0 deletions Mutagen.Bethesda.Core/MutagenSource.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@
<xs:enumeration value="NullTerminate" />
<xs:enumeration value="PrependLength" />
<xs:enumeration value="PrependLengthUShort" />
<xs:enumeration value="PrependLengthUInt8" />
<xs:enumeration value="NullTerminateIfNotEmpty" />
<xs:enumeration value="PrependLengthWithNullIfContent" />
</xs:restriction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static IReadOnlyList<T> FactoryByCount<T>(
1 => initialHeader.Content[0],
2 => (int)BinaryPrimitives.ReadUInt16LittleEndian(initialHeader.Content),
4 => checked((int)BinaryPrimitives.ReadUInt32LittleEndian(initialHeader.Content)),
8 => checked((int)BinaryPrimitives.ReadUInt64LittleEndian(initialHeader.Content)),
_ => throw new NotImplementedException(),
};
stream.Position += initialHeader.TotalLength;
Expand Down Expand Up @@ -157,6 +158,7 @@ public static IReadOnlyList<T> EagerFactoryByPrependedCount<T>(
1 => (int)stream.ReadUInt8(),
2 => (int)stream.ReadUInt16(),
4 => checked((int)stream.ReadUInt32()),
8 => checked((int)stream.ReadUInt64()),
_ => throw new NotImplementedException(),
};
List<T> ret = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public static ReadOnlySpan<byte> ExtractPrependedString(ReadOnlySpan<byte> span,
{
switch (lengthLength)
{
case 1:
{
var length = span[0];
return span.Slice(1, length);
}
case 2:
{
var length = BinaryPrimitives.ReadUInt16LittleEndian(span);
Expand All @@ -130,6 +135,11 @@ public static ReadOnlySpan<byte> ExtractPrependedString(ReadOnlySpan<byte> span,
var length = BinaryPrimitives.ReadUInt32LittleEndian(span);
return span.Slice(4, checked((int)length));
}
case 8:
{
var length = BinaryPrimitives.ReadUInt64LittleEndian(span);
return span.Slice(8, checked((int)length));
}
default:
throw new NotImplementedException();
}
Expand Down Expand Up @@ -207,6 +217,13 @@ public static void Write<TStream>(this TStream stream, ReadOnlySpan<char> str, S
Write(stream, str, encoding, len);
break;
}
case StringBinaryType.PrependLengthUInt8:
{
var len = encoding.GetByteCount(str);
stream.Write(checked((byte)len));
Write(stream, str, encoding, len);
break;
}
default:
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,9 @@ public void Write(
case 4:
writer.Write(items.Count);
break;
case 8:
writer.Write((long)items.Count);
break;
default:
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,22 @@ public string Parse<TReader>(
}
case StringBinaryType.PrependLength:
{
var len = reader.ReadInt32();
return BinaryStringUtility.ToZString(reader.ReadMemory(len), encoding);
var len = reader.ReadUInt32();
return BinaryStringUtility.ToZString(reader.ReadMemory(checked((int)len)), encoding);
}
case StringBinaryType.PrependLengthWithNullIfContent:
{
var len = reader.ReadInt32();
return BinaryStringUtility.ProcessWholeToZString(reader.ReadMemory(len), encoding);
var len = reader.ReadUInt32();
return BinaryStringUtility.ProcessWholeToZString(reader.ReadMemory(checked((int)len)), encoding);
}
case StringBinaryType.PrependLengthUShort:
{
var len = reader.ReadInt16();
var len = reader.ReadUInt16();
return BinaryStringUtility.ToZString(reader.ReadMemory(len), encoding);
}
case StringBinaryType.PrependLengthUInt8:
{
var len = reader.ReadUInt8();
return BinaryStringUtility.ToZString(reader.ReadMemory(len), encoding);
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public enum StringBinaryType
/// Length prepended as a ushort
/// </summary>
PrependLengthUShort,
/// <summary>
/// Length prepended as a byte
/// </summary>
PrependLengthUInt8,
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal record MasterStyleIndex(uint Index, MasterStyle Style);
"OldMars.esm",
"Constellation.esm",
"SFBGS003.esm",
"SFBGS004.esm",
"SFBGS006.esm",
"SFBGS007.esm",
"SFBGS008.esm"
Expand Down
49 changes: 49 additions & 0 deletions Mutagen.Bethesda.Core/Plugins/Records/IMajorRecordIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,53 @@ public interface IMajorRecordIdentifier : IFormKeyGetter
/// The usually unique string identifier assigned to the Major Record
/// </summary>
string? EditorID { get; }
}

public record MajorRecordIdentifier : IMajorRecordIdentifier
{
public required FormKey FormKey { get; init; }
public string? EditorID { get; init; }

public virtual bool Equals(MajorRecordIdentifier? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return FormKey.Equals(other.FormKey)
&& string.Equals(EditorID, other.EditorID, StringComparison.OrdinalIgnoreCase);
}
public override int GetHashCode()
{
return HashCode.Combine(FormKey, EditorID?.GetHashCode(StringComparison.OrdinalIgnoreCase));
}

public static IEqualityComparer<IMajorRecordIdentifier> EqualityComparer => _equalityComparer;

private static readonly Comparer _equalityComparer = new();

class Comparer : IEqualityComparer<IMajorRecordIdentifier>
{
public bool Equals(IMajorRecordIdentifier? x, IMajorRecordIdentifier? y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
return x.FormKey.Equals(y.FormKey)
&& string.Equals(x.EditorID, y.EditorID, StringComparison.OrdinalIgnoreCase);
}

public int GetHashCode(IMajorRecordIdentifier obj)
{
return HashCode.Combine(obj.FormKey, obj.EditorID?.GetHashCode(StringComparison.OrdinalIgnoreCase));
}
}
}

public interface IMajorRecordIdentifier<TMajorGetter> : IMajorRecordIdentifier
where TMajorGetter : class, IMajorRecordQueryableGetter
{
}

public record MajorRecordIdentifier<TMajorGetter> : MajorRecordIdentifier, IMajorRecordIdentifier<TMajorGetter>
where TMajorGetter : class, IMajorRecordQueryableGetter
{
}
3 changes: 3 additions & 0 deletions Mutagen.Bethesda.Core/Strings/StringsLookupOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public sealed class StringsLookupOverlay : IStringsLookup

public StringsFileFormat Type { get; private set; }
public int Count => _locations.Count;
public string? AssociatedPath { get; }

/// <summary>
/// Overlays onto a set of bytes assumed to be in Strings file format
Expand Down Expand Up @@ -49,6 +50,7 @@ public StringsLookupOverlay(ReadOnlyMemorySlice<byte> data, StringsSource source
/// <param name="encoding">Encoding to read strings with</param>
public StringsLookupOverlay(string path, StringsFileFormat type, IMutagenEncoding encoding)
{
AssociatedPath = path;
Init(File.ReadAllBytes(path), type, encoding);
}

Expand All @@ -61,6 +63,7 @@ public StringsLookupOverlay(string path, StringsFileFormat type, IMutagenEncodin
/// <param name="fileSystem">Filesystem to use</param>
public StringsLookupOverlay(string path, StringsSource source, IMutagenEncoding encoding, IFileSystem? fileSystem = null)
{
AssociatedPath = path;
fileSystem ??= fileSystem.GetOrDefault();
Init(fileSystem.File.ReadAllBytes(path), StringsUtility.GetFormat(source), encoding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2667,37 +2667,37 @@ public static void FillBinaryStructs(
item: item);
item.Vertices.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<P3Float>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: P3FloatBinaryTranslation<MutagenFrame, MutagenWriter>.Instance.Parse));
item.Triangles.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<NavmeshTriangle>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: NavmeshTriangle.TryCreateFromBinary));
item.EdgeLinks.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<EdgeLink>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: EdgeLink.TryCreateFromBinary));
item.DoorTriangles.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<DoorTriangle>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: DoorTriangle.TryCreateFromBinary));
item.Cover.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<NavmeshCover>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: NavmeshCover.TryCreateFromBinary));
item.CoverTriangleMappings.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<NavmeshCoverTriangleMap>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: NavmeshCoverTriangleMap.TryCreateFromBinary));
item.Waypoints.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<NavmeshWaypoint>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: NavmeshWaypoint.TryCreateFromBinary));
item.GridSize = frame.ReadUInt32();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ public static void FillBinaryStructs(
frame: frame);
item.Data.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<Boolean>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: BooleanBinaryTranslation<MutagenFrame>.Instance.Parse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ public static void FillBinaryStructs(
{
item.Members.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<ScriptProperty>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: ScriptProperty.TryCreateFromBinary));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ public static void FillBinaryStructs(
frame: frame);
item.Data.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<Single>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: FloatBinaryTranslation<MutagenFrame, MutagenWriter>.Instance.Parse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ public static void FillBinaryStructs(
frame: frame);
item.Data.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<Int32>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: Int32BinaryTranslation<MutagenFrame, MutagenWriter>.Instance.Parse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ public static void FillBinaryStructs(
frame: frame);
item.Objects.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<ScriptObjectProperty>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: ScriptObjectProperty.TryCreateFromBinary));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ public static void FillBinaryStructs(
frame: frame);
item.Data.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<String>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: (MutagenFrame r, [MaybeNullWhen(false)] out String listSubItem) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ public static void FillBinaryStructs(
frame: frame);
item.Structs.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<ScriptEntryStructs>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: ScriptEntryStructs.TryCreateFromBinary));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ public static void FillBinaryStructs(
frame: frame);
item.Members.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<ScriptEntry>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: ScriptEntry.TryCreateFromBinary));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ public static void FillBinaryStructs(
frame: frame);
item.Data.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<Int32>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: Int32BinaryTranslation<MutagenFrame, MutagenWriter>.Instance.Parse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,12 +1354,12 @@ public static void FillBinaryStructs(
item.Max = P3FloatBinaryTranslation<MutagenFrame, MutagenWriter>.Instance.Parse(reader: frame);
item.Triangles.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<P3Int16>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: P3Int16BinaryTranslation<MutagenFrame, MutagenWriter>.Instance.Parse));
item.Vertices.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<P3Float>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: P3FloatBinaryTranslation<MutagenFrame, MutagenWriter>.Instance.Parse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1969,17 +1969,17 @@ public static void FillBinaryStructs(
item.UnknownFloat = FloatBinaryTranslation<MutagenFrame, MutagenWriter>.Instance.Parse(reader: frame);
item.MergedTo.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<IFormLinkGetter<INavigationMeshGetter>>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: FormLinkBinaryTranslation.Instance.Parse));
item.PreferredMerges.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<IFormLinkGetter<INavigationMeshGetter>>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: FormLinkBinaryTranslation.Instance.Parse));
item.LinkedDoors.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<LinkedDoor>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: LinkedDoor.TryCreateFromBinary));
if (frame.Complete) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ public static void FillBinaryStructs(
{
item.Navmeshes.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<IFormLinkGetter<INavigationMeshGetter>>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: FormLinkBinaryTranslation.Instance.Parse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1305,12 +1305,12 @@ public static void FillBinaryStructs(
{
item.NavmeshSets.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<NavmeshSet>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: NavmeshSet.TryCreateFromBinary));
item.NavmeshTree.SetTo(
Mutagen.Bethesda.Plugins.Binary.Translations.ListBinaryTranslation<NavmeshNode>.Instance.Parse(
amount: frame.ReadInt32(),
amount: checked((int)frame.ReadUInt32()),
reader: frame,
transl: NavmeshNode.TryCreateFromBinary));
}
Expand Down
Loading

0 comments on commit e235bbe

Please sign in to comment.