Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2024.6 masks not showing #1963

Merged
merged 2 commits into from
Nov 29, 2024
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
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
Loading