Skip to content

Commit

Permalink
Merge pull request #1963 from luizzeroxis/fix-2024-6-masks
Browse files Browse the repository at this point in the history
Fix 2024.6 masks not showing
  • Loading branch information
Miepee authored Nov 29, 2024
2 parents 8626c6e + a1fadae commit f1e6da3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
18 changes: 14 additions & 4 deletions UndertaleModLib/Models/UndertaleSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ public void Dispose()

public MaskEntry NewMaskEntry()
{
MaskEntry newEntry = new MaskEntry();
uint len = (Width + 7) / 8 * Height;
newEntry.Data = new byte[len];
MaskEntry newEntry = new MaskEntry(new byte[len], Width, Height);
return newEntry;
}

Expand Down Expand Up @@ -348,13 +347,24 @@ public class MaskEntry : IDisposable
{
public byte[] Data { get; set; }

/// <summary>
/// Width of this sprite mask. UTMT only.
/// </summary>
public uint Width { get; set; }
/// <summary>
/// Height of this sprite mask. UTMT only.
/// </summary>
public uint Height { get; set; }

public MaskEntry()
{
}

public MaskEntry(byte[] data)
public MaskEntry(byte[] data, uint width, uint height)
{
this.Data = data;
this.Width = width;
this.Height = height;
}

/// <inheritdoc/>
Expand Down Expand Up @@ -853,7 +863,7 @@ private void ReadMaskData(UndertaleReader reader)
uint total = 0;
for (uint i = 0; i < maskCount; i++)
{
newMasks.Add(new MaskEntry(reader.ReadBytes((int)len)));
newMasks.Add(new MaskEntry(reader.ReadBytes((int)len), width, height));
total += len;
}

Expand Down
4 changes: 2 additions & 2 deletions UndertaleModTool/Editors/UndertaleSpriteEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@
<MultiBinding.Converter>
<local:MaskImageConverter/>
</MultiBinding.Converter>
<Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.Width" Mode="OneWay"/>
<Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.Height" Mode="OneWay"/>
<Binding Path="Width" Mode="OneWay"/>
<Binding Path="Height" Mode="OneWay"/>
<Binding Path="Data" Mode="OneWay"/>
</MultiBinding>
</Image.Source>
Expand Down
2 changes: 2 additions & 0 deletions UndertaleModTool/Editors/UndertaleSpriteEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ private void MaskImport_Click(object sender, RoutedEventArgs e)
{
(uint maskWidth, uint maskHeight) = sprite.CalculateMaskDimensions(mainWindow.Data);
target.Data = TextureWorker.ReadMaskData(dlg.FileName, (int)maskWidth, (int)maskHeight);
target.Width = maskWidth;
target.Height = maskHeight;
}
catch (Exception ex)
{
Expand Down

0 comments on commit f1e6da3

Please sign in to comment.