Skip to content

Commit

Permalink
Fix alignment padding checks in UndertaleIO
Browse files Browse the repository at this point in the history
To check if pos is aligned we calculate (pos & (alignment - 1)).
When pos is aligned, the result will always be 0.
However right now the Align functions of UTReader/Writer
checks if it equals to the intended padding byte, which
makes zero sense. This commit makes them check against 0.
  • Loading branch information
Dobby233Liu committed Jan 21, 2025
1 parent e1f5d22 commit 66e0fb9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions UndertaleModLib/UndertaleIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public void ToHere()

public void Align(int alignment, byte paddingbyte = 0x00)
{
while ((AbsPosition & (alignment - 1)) != paddingbyte)
while ((AbsPosition & (alignment - 1)) != 0)
{
DebugUtil.Assert(ReadByte() == paddingbyte, "Invalid alignment padding");
}
Expand Down Expand Up @@ -860,7 +860,7 @@ public void ThrowIfUnwrittenObjects()

public void Align(int alignment, byte paddingbyte = 0x00)
{
while ((Position & (alignment - 1)) != paddingbyte)
while ((Position & (alignment - 1)) != 0)
{
Write(paddingbyte);
}
Expand Down

0 comments on commit 66e0fb9

Please sign in to comment.