Skip to content

Commit

Permalink
Merge branch 'master' into underanalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
colinator27 committed Dec 1, 2024
2 parents 989a173 + 68f06d7 commit 282ecca
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 48 deletions.
3 changes: 2 additions & 1 deletion UndertaleModLib/Models/UndertaleGeneralInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ public enum OptionsFlags : ulong
UseRearTouch = 0x2000000,
UseFastCollision = 0x4000000,
FastCollisionCompatibility = 0x8000000,
DisableSandbox = 0x10000000
DisableSandbox = 0x10000000,
EnableCopyOnWrite = 0x20000000
}

/// <summary>
Expand Down
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 UndertaleModLibTests/UndertaleModLibTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="xunit" Version="2.9.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="xunit" Version="2.9.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModTests/UndertaleModTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="MSTest.TestFramework">
<Version>3.6.3</Version>
</PackageReference>
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" />
<PackageReference Include="System.ComponentModel.Composition" Version="9.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
</ItemGroup>
</Project>
6 changes: 4 additions & 2 deletions UndertaleModTool/Controls/UndertaleObjectReference.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<local:TextBoxDark Grid.Column="0" x:Name="ObjectText" IsReadOnly="True" Cursor="Arrow" AllowDrop="True"
ToolTip="This is an object reference. Drag and drop an object of matching type from the tree on the left to change it!"
ToolTipService.InitialShowDelay="250"
PreviewDragOver="TextBox_DragOver" PreviewDrop="TextBox_Drop" PreviewMouseDoubleClick="TextBox_MouseDoubleClick" PreviewMouseDown="Details_MouseDown"
Text="{Binding ObjectReference, ElementName=objectReference}">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding CanChange, ElementName=objectReference}" Value="True">
<Setter Property="ToolTip" Value="This is an object reference. Drag and drop an object of matching type from the tree on the left to change it!" />
<Setter Property="ToolTipService.InitialShowDelay" Value="250" />
</DataTrigger>
<DataTrigger Binding="{Binding ObjectReference, ElementName=objectReference}" Value="{x:Null}">
<Setter Property="Background">
<Setter.Value>
Expand Down
29 changes: 22 additions & 7 deletions UndertaleModTool/Controls/UndertaleObjectReference.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ public partial class UndertaleObjectReference : UserControl
typeof(UndertaleObjectReference),
new FrameworkPropertyMetadata(true,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));


public static DependencyProperty CanChangeProperty =
DependencyProperty.Register("CanChange", typeof(bool),
typeof(UndertaleObjectReference),
new FrameworkPropertyMetadata(true,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

public static DependencyProperty ObjectEventTypeProperty =
DependencyProperty.Register("ObjectEventType", typeof(EventType),
typeof(UndertaleObjectReference),
Expand Down Expand Up @@ -94,8 +100,14 @@ public Type ObjectType

public bool CanRemove
{
get { return (bool)GetValue(ObjectTypeProperty); }
set { SetValue(ObjectTypeProperty, value); }
get { return (bool)GetValue(CanRemoveProperty); }
set { SetValue(CanRemoveProperty, value); }
}

public bool CanChange
{
get { return (bool)GetValue(CanChangeProperty); }
set { SetValue(CanChangeProperty, value); }
}

public EventType ObjectEventType
Expand Down Expand Up @@ -136,8 +148,11 @@ private void UndertaleObjectReference_Loaded(object sender, RoutedEventArgs e)
// If the first letter is a vowel
if (Array.IndexOf(vowels, typeName[0]) != -1)
n = "n";

label.Content = $"(drag & drop a{n} {typeName})";

if (CanChange)
label.Content = $"(drag & drop a{n} {typeName})";
else
label.Content = $"(empty {typeName} reference)";
}

public void ClearRemoveClickHandler()
Expand Down Expand Up @@ -244,15 +259,15 @@ private void TextBox_DragOver(object sender, DragEventArgs e)
{
UndertaleObject sourceItem = e.Data.GetData(e.Data.GetFormats()[0]) as UndertaleObject;

e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && CanChange && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
e.Handled = true;
}

private void TextBox_Drop(object sender, DragEventArgs e)
{
UndertaleObject sourceItem = e.Data.GetData(e.Data.GetFormats()[0]) as UndertaleObject;

e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
e.Effects = e.AllowedEffects.HasFlag(DragDropEffects.Link) && sourceItem != null && CanChange && sourceItem.GetType() == ObjectType ? DragDropEffects.Link : DragDropEffects.None;
if (e.Effects == DragDropEffects.Link)
{
ObjectReference = sourceItem;
Expand Down
9 changes: 8 additions & 1 deletion UndertaleModTool/Editors/UndertaleCodeEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<UserControl.InputBindings>
<KeyBinding Modifiers="Control" Key="K" Command="{x:Static local:UndertaleCodeEditor.Compile}"/>
</UserControl.InputBindings>
<UserControl.Resources>
<local:NullToVisibilityConverter x:Key="VisibleIfNotNull" nullValue="Collapsed" notNullValue="Visible"/>
</UserControl.Resources>
<Grid MaxHeight="{Binding ElementName=DataEditor, Path=ActualHeight}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
Expand All @@ -24,6 +27,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>

Expand All @@ -39,7 +43,10 @@
<TextBlock Grid.Row="3" Grid.Column="0" Margin="3">Offset</TextBlock>
<local:TextBoxDark Grid.Row="3" Grid.Column="1" Margin="3" Text="{Binding Offset}"/>

<TabControl x:Name="CodeModeTabs" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" SelectionChanged="TabControl_SelectionChanged">
<TextBlock Grid.Row="4" Grid.Column="0" Margin="3" Visibility="{Binding ParentEntry, Converter={StaticResource VisibleIfNotNull}}">Parent entry</TextBlock>
<local:UndertaleObjectReference Grid.Row="4" Grid.Column="1" Margin="3" Visibility="{Binding ParentEntry, Converter={StaticResource VisibleIfNotNull}}" ObjectReference="{Binding ParentEntry}" ObjectType="{x:Type undertale:UndertaleCode}" CanRemove="False" CanChange="False"/>

<TabControl x:Name="CodeModeTabs" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" SelectionChanged="TabControl_SelectionChanged">
<TabItem Header="Decompiled" Name="DecompiledTab">
<Grid>
<avalonEdit:TextEditor
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
4 changes: 2 additions & 2 deletions UndertaleModTool/UndertaleModTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<Version>1.1.5</Version>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers">
<Version>3.3.4</Version>
<Version>3.11.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down Expand Up @@ -129,7 +129,7 @@
<PackageReference Include="System.Xml.XPath.XDocument">
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="5.0.2" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="9.0.0" />
</ItemGroup>
<Target Name="AfterResolveReferences">
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace UndertaleModTool.Windows
/// </summary>
public partial class FindReferencesTypesDialog : Window
{
private static readonly MainWindow mainWindow = Application.Current.MainWindow as MainWindow;

private readonly UndertaleResource sourceObj;
private readonly UndertaleData data;
private readonly bool dontShowWindow = false;
Expand Down Expand Up @@ -140,9 +142,21 @@ private async void SearchButton_Click(object sender, RoutedEventArgs e)
return;
}

var results = UndertaleResourceReferenceMethodsMap.GetReferencesOfObject(sourceObj, data, typesList);
FindReferencesResults dialog = new(sourceObj, data, results);
dialog.Show();
FindReferencesResults dialog = null;
try
{
var results = UndertaleResourceReferenceMethodsMap.GetReferencesOfObject(sourceObj, data, typesList);
dialog = new(sourceObj, data, results);
dialog.Show();
}
catch (Exception ex)
{
mainWindow.ShowError("An error occured in the object references related window.\n" +
$"Please report this on GitHub.\n\n{ex}");
dialog?.Close();

}

}
else
{
Expand Down Expand Up @@ -173,9 +187,19 @@ private async void SearchButton_Click(object sender, RoutedEventArgs e)
}

Hide();
var results = await UndertaleResourceReferenceMethodsMap.GetUnreferencedObjects(data, typesDict);
FindReferencesResults dialog = new(data, results);
dialog.Show();
FindReferencesResults dialog = null;
try
{
var results = await UndertaleResourceReferenceMethodsMap.GetUnreferencedObjects(data, typesDict);
dialog = new(data, results);
dialog.Show();
}
catch (Exception ex)
{
mainWindow.ShowError("An error occured in the object references related window.\n" +
$"Please report this on GitHub.\n\n{ex}");
dialog?.Close();
}
}

Close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public static class UndertaleResourceReferenceMap
(typeof(UndertaleGameObject), "Game objects"),
(typeof(UndertaleGeneralInfo), "General info"),
(typeof(UndertaleOptions.Constant), "Game options constants"),
(typeof(UndertaleLanguage), "Languages"),
(typeof(UndertalePath), "Paths"),
(typeof(UndertaleRoom), "Rooms"),
(typeof(UndertaleScript), "Scripts"),
Expand All @@ -179,6 +178,15 @@ public static class UndertaleResourceReferenceMap
}
},
new TypesForVersion
{
// Bytecode version 16
Version = (16, uint.MaxValue, uint.MaxValue),
Types = new[]
{
(typeof(UndertaleLanguage), "Languages"),
}
},
new TypesForVersion
{
Version = (2, 0, 0),
Types = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,6 @@ IEnumerable<object[]> GetExtnFunctions()
outDict["Game options constants"] = new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) };
}

if (types.Contains(typeof(UndertaleLanguage)))
{
bool langsMatches = data.Language.EntryIDs.Contains(obj)
|| data.Language.Languages.Any(x => x.Name == obj || x.Region == obj
|| x.Entries.Contains(obj));
if (langsMatches)
outDict["Languages"] = new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) };
}

if (types.Contains(typeof(UndertalePath)))
{
var paths = data.Paths.Where(x => x.Name == obj);
Expand Down Expand Up @@ -632,6 +623,28 @@ IEnumerable<object[]> GetExtnFunctions()
}
},
new PredicateForVersion()
{
// Bytecode version 16
Version = (16, uint.MaxValue, uint.MaxValue),
Predicate = (objSrc, types, checkOne) =>
{
if (!types.Contains(typeof(UndertaleLanguage)))
return null;

if (objSrc is not UndertaleString obj)
return null;

bool langsMatches = data.Language.EntryIDs.Contains(obj)
|| data.Language.Languages.Any(x => x.Name == obj || x.Region == obj
|| x.Entries.Contains(obj));

if (langsMatches)
return new() { { "Languages", new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) } } };
else
return null;
}
},
new PredicateForVersion()
{
Version = (2, 0, 0),
Predicate = (objSrc, types, checkOne) =>
Expand Down Expand Up @@ -1566,23 +1579,17 @@ await Task.Run(() =>
}
}
}

await mainWindow.StopProgressBarUpdater();
mainWindow.HideProgressBar();
}
catch
finally
{
await mainWindow.StopProgressBarUpdater();
mainWindow.HideProgressBar();

mainWindow.IsEnabled = true;
stringReferences = null;
funcReferences = null;
variReferences = null;

throw;
}
mainWindow.IsEnabled = true;
stringReferences = null;
funcReferences = null;
variReferences = null;

if (outDict.Count == 0)
return null;
Expand Down

0 comments on commit 282ecca

Please sign in to comment.