animations and QOL

This commit is contained in:
bird_egop
2026-06-12 02:06:32 +03:00
parent 4d0d1aca12
commit 1cb3940cce
14 changed files with 444 additions and 32 deletions
+53
View File
@@ -0,0 +1,53 @@
using System.Buffers.Binary;
using NResLib;
namespace MshLib;
public static class Msh0x13
{
public static Msh0x13Component ReadComponent(FileStream mshFs, NResArchive archive)
{
var entry = archive.Files.FirstOrDefault(x => x.FileType == "13 00 00 00");
if (entry is null)
{
throw new Exception("Archive doesn't contain animation map component (0x13)");
}
if (entry.ElementSize < 2)
{
throw new Exception("Animation map component (0x13) element size is too small");
}
var data = new byte[entry.FileLength];
mshFs.Seek(entry.OffsetInFile, SeekOrigin.Begin);
mshFs.ReadExactly(data, 0, data.Length);
var elementCount = checked((int)entry.ElementCount);
var entries = new List<MshAnimationMapEntry>(elementCount);
var span = data.AsSpan();
for (var i = 0; i < elementCount; i++)
{
var elementOffset = i * entry.ElementSize;
entries.Add(new MshAnimationMapEntry(
BinaryPrimitives.ReadUInt16LittleEndian(span.Slice(elementOffset, 2))));
}
return new Msh0x13Component(entry.ElementSize, entries)
{
MaxAnimationTime = entry.Magic1
};
}
}
public readonly record struct MshAnimationMapEntry(
ushort KeyframeIndex
);
public sealed record Msh0x13Component(
int ElementSize,
List<MshAnimationMapEntry> Entries
)
{
public int MaxAnimationTime { get; init; }
}