Skip to content

Commit

Permalink
- Added "Progress Array" feature for Rayman 2, allowing you to save/l…
Browse files Browse the repository at this point in the history
…oad progress, e.g. collected lums/cages

- Added "Main Menu" map for Rayman 2
  • Loading branch information
rtsonneveld committed Dec 12, 2021
1 parent 4173aa1 commit 3076730
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ public Rayman2GameManager()
{
new Rayman2VoidExtra(this),
new Rayman2NoHpExtra(this),
new Rayman2GlmMonitorExtra(this)
new Rayman2GlmMonitorExtra(this),
new Rayman2ProgressArrayExtra(this),
};

//Levels
LevelContainers = new ObservableCollection<LevelContainerViewModel>()
{
new LevelContainerViewModel("Menu", new ObservableCollection<LevelViewModel>()
{
new LevelViewModel("Main Menu", "menu", LevelType.Menu),
new LevelViewModel("The Hall of Doors", "mapmonde", LevelType.Menu),
new LevelViewModel("Score Screen", "raycap", LevelType.Menu),
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Windows;

namespace OpenSpaceToolbox
{
public class Rayman2ProgressArrayExtra : OpenspaceExtraAction
{
public Rayman2ProgressArrayExtra(Rayman2GameManager gameManager) : base(gameManager)
{
Name = "Progress Array";
ShortName = "Progress Array";
ProgressArrayBasePointer = 0x500560;
ProgressArrayOffsets = new[] {0x0, 0x0, 0x6C, 0x4, 0x0, 0x1C, 0x4E4};
}

public const int ProgressArrayLengthBytes = 45 * 4; // 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);
}

public byte[] ReadByteArray(int baseAddress, int arrayLength, params int[] offsets)
{
int processHandle = GameManager.GetProcessHandle();
if (processHandle < 0)
return null;

int bytesReadOrWritten = 0;
int offXcoord = Memory.GetPointerPath(processHandle, baseAddress, offsets);

byte[] buffer = new byte[arrayLength];

Memory.ReadProcessMemory(processHandle, offXcoord, buffer, arrayLength, ref bytesReadOrWritten);

return buffer;
}

public void WriteByteArray(int baseAddress, byte[] bytes, params int[] offsets)
{
int processHandle = GameManager.GetProcessHandle();
if (processHandle < 0)
return;

int bytesReadOrWritten = 0;
int offset = Memory.GetPointerPath(processHandle, baseAddress, offsets);

Memory.WriteProcessMemory(processHandle, offset, bytes, bytes.Length, ref bytesReadOrWritten);
}

public override void Action()
{
ProgressArrayWindow window = new ProgressArrayWindow(new ProgressArrayWindowViewModel(this))
{
Owner = Application.Current.MainWindow
};
window.Show();
}
}
}
9 changes: 9 additions & 0 deletions OpenSpaceToolbox/OpenSpaceToolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@
<Compile Include="Converters\IsValidIndexConverter.cs" />
<Compile Include="DataModels\GameItem.cs" />
<Compile Include="DataModels\GameList.cs" />
<Compile Include="GameManager\Games\Rayman2\Rayman2ProgressArrayExtra.cs" />
<Compile Include="GameManager\Games\Rayman3\Rayman3GameManager.cs" />
<Compile Include="ViewModels\ProgressArrayWindowViewModel.cs" />
<Compile Include="Windows\GameChooser.xaml.cs">
<DependentUpon>GameChooser.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -131,6 +133,9 @@
<Compile Include="Views\GameManagerMinimizedView.xaml.cs">
<DependentUpon>GameManagerMinimizedView.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\ProgressArrayWindow.xaml.cs">
<DependentUpon>ProgressArrayWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\GlmWindow.xaml.cs">
<DependentUpon>GlmWindow.xaml</DependentUpon>
</Compile>
Expand All @@ -149,6 +154,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\ProgressArrayWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Windows\GlmWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
83 changes: 83 additions & 0 deletions OpenSpaceToolbox/ViewModels/ProgressArrayWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace OpenSpaceToolbox
{
/// <summary>
/// View model for the Progress Array
/// </summary>
public class ProgressArrayWindowViewModel : BaseViewModel
{
#region Constructor

public ProgressArrayWindowViewModel(Rayman2ProgressArrayExtra extra)
{
Extra = extra;

LoadProgressCommand = new RelayCommand(LoadProgress);
SaveProgressCommand = new RelayCommand(SaveProgress);
}

#endregion

#region Commands

public ICommand LoadProgressCommand { get; }
public ICommand SaveProgressCommand { get; }

#endregion

#region Private Properties

private Rayman2ProgressArrayExtra Extra { get; }

#endregion

#region Public Properties

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

if (byteStrings.Length != byteArray.Length) return;

for(int i=0;i<byteStrings.Length;i++) {
if (byte.TryParse(byteStrings[i], out byte byteVal)) {
byteArray[i] = byteVal;
}

}

SavedProgress = byteArray;
}
}


public byte[] SavedProgress { get; set; }

#endregion

#region Private Methods

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

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

#endregion

}
}
44 changes: 44 additions & 0 deletions OpenSpaceToolbox/Windows/ProgressArrayWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Window x:Class="OpenSpaceToolbox.ProgressArrayWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OpenSpaceToolbox"
mc:Ignorable="d"
Title="Progress Array"
MinWidth="280"
MinHeight="220"
ResizeMode="NoResize"
SnapsToDevicePixels="True"
d:DataContext="{d:DesignInstance local:ProgressArrayWindowViewModel}" SizeToContent="WidthAndHeight" Closing="Window_Closing">
<Window.Resources>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Padding" Value="5 2" />
</Style>
</Window.Resources>
<StackPanel Margin="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MinHeight="50" />
<RowDefinition MinHeight="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="50" />
</Grid.ColumnDefinitions>
<TextBox Text="{Binding Path=SavedProgressText}" TextWrapping="Wrap" MaxWidth="260" />
<StackPanel Grid.Column="1"
Grid.Row="1">
<WrapPanel Orientation="Horizontal"
Margin="5"
HorizontalAlignment="Center">
<Button Content="Save Progress"
Margin="5 5 5 0"
Command="{Binding Path=SaveProgressCommand}" />
<Button Content="Load Progress"
Margin="5 5 5 0"
Command="{Binding Path=LoadProgressCommand}" />
</WrapPanel>
</StackPanel>
</Grid>
</StackPanel>
</Window>
23 changes: 23 additions & 0 deletions OpenSpaceToolbox/Windows/ProgressArrayWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Windows;

namespace OpenSpaceToolbox
{
/// <summary>
/// Interaction logic for GlmWindow.xaml
/// </summary>
public partial class ProgressArrayWindow : Window
{
public ProgressArrayWindow(ProgressArrayWindowViewModel viewModel)
{
InitializeComponent();

DataContext = ViewModel = viewModel;
}

private ProgressArrayWindowViewModel ViewModel { get; }

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
}
}

0 comments on commit 3076730

Please sign in to comment.