Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Ultima/AnimationsUopLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ internal static class AnimationsUopLoader
internal const int _maxAnimActions = 80;
private const int _maxDirections = 5;

/// <summary>"AMOU", the first four bytes of every animation frame payload.</summary>
private const uint _frameMagic = 0x554F4D41;

/// <summary>
/// Size of the fixed part of one AnimationSequence group record: the four leading fields,
/// the per frame bytes and the reserved block. Two variable length lists follow it.
Expand Down Expand Up @@ -568,14 +571,20 @@ private static byte[] ReadEntryData(UopEntry entry)

private static AnimationFrame[] ParseUopFrames(byte[] data, int direction, bool flip)
{
if (data.Length < 36)
// The header is 40 bytes; frame count and table offset sit at 32 and 36
if (data.Length < 40)
{
return null;
}

using var memoryStream = new MemoryStream(data);
using var reader = new BinaryReader(memoryStream);

if (reader.ReadUInt32() != _frameMagic)
{
return null;
}

reader.BaseStream.Seek(32, SeekOrigin.Begin);
int frameCount = reader.ReadInt32();
uint dataStart = reader.ReadUInt32();
Expand Down
2 changes: 1 addition & 1 deletion UoFiddler.Controls/Forms/AnimationEditForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ private void OnFrameCountBarChanged(object sender, EventArgs e)
}

AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit != null && edit.Frames.Count >= FramesTrackBar.Value)
if (edit != null && edit.Frames.Count > FramesTrackBar.Value)
{
CenterXNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.X;
CenterYNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.Y;
Expand Down