Skip to content

Commit

Permalink
Fixed a bug where changes to the progress array textbox wouldn't be s…
Browse files Browse the repository at this point in the history
…aved

Fixed a bug where the progress array didn't capture a few items such as thinking ability, lums in woods of light
  • Loading branch information
rtsonneveld committed Dec 13, 2021
1 parent 3076730 commit 97cd552
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ public Rayman2ProgressArrayExtra(Rayman2GameManager gameManager) : base(gameMana
ProgressArrayOffsets = new[] {0x0, 0x0, 0x6C, 0x4, 0x0, 0x1C, 0x4E4};
}

public const int ProgressArrayLengthBytes = 45 * 4; // 45 ints in global.DsgVar42
public const int ProgressArrayLengthBytes = 46 * 4; // 46 (not 45) ints in global.DsgVar42

private int ProgressArrayBasePointer { get; }
private int[] ProgressArrayOffsets { get; }

public byte[] ProgressArray
{
get => ReadByteArray(ProgressArrayBasePointer, ProgressArrayLengthBytes, ProgressArrayOffsets);
set => WriteByteArray(ProgressArrayBasePointer, value, ProgressArrayOffsets);
set
{
if (value != null) {
WriteByteArray(ProgressArrayBasePointer, value, ProgressArrayOffsets);
}
}
}

public byte[] ReadByteArray(int baseAddress, int arrayLength, params int[] offsets)
Expand Down
6 changes: 5 additions & 1 deletion OpenSpaceToolbox/ViewModels/ProgressArrayWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public ProgressArrayWindowViewModel(Rayman2ProgressArrayExtra extra)

#region Public Properties

public string EditProgressText { get; set; }

public string SavedProgressText
{
get => SavedProgress==null ? string.Empty : string.Join(" ", SavedProgress.Select(b => b.ToString()));
set
{
string[] byteStrings = SavedProgressText.Split(' ');
string[] byteStrings = value.Split(' ');
byte[] byteArray = new byte[Rayman2ProgressArrayExtra.ProgressArrayLengthBytes];

if (byteStrings.Length != byteArray.Length) return;
Expand All @@ -68,12 +70,14 @@ public string SavedProgressText

private void LoadProgress()
{
SavedProgressText = EditProgressText;
Extra.ProgressArray = SavedProgress;
}

private void SaveProgress()
{
SavedProgress = Extra.ProgressArray;
EditProgressText = SavedProgressText;
OnPropertyChanged(nameof(SavedProgressText));
}

Expand Down
2 changes: 1 addition & 1 deletion OpenSpaceToolbox/Windows/ProgressArrayWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="50" />
</Grid.ColumnDefinitions>
<TextBox Text="{Binding Path=SavedProgressText}" TextWrapping="Wrap" MaxWidth="260" />
<TextBox Text="{Binding Path=EditProgressText}" TextWrapping="Wrap" MaxWidth="260" />
<StackPanel Grid.Column="1"
Grid.Row="1">
<WrapPanel Orientation="Horizontal"
Expand Down

0 comments on commit 97cd552

Please sign in to comment.