-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added "Progress Array" feature for Rayman 2, allowing you to save/l…
…oad progress, e.g. collected lums/cages - Added "Main Menu" map for Rayman 2
- Loading branch information
1 parent
4173aa1
commit 3076730
Showing
6 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
OpenSpaceToolbox/GameManager/Games/Rayman2/Rayman2ProgressArrayExtra.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
OpenSpaceToolbox/ViewModels/ProgressArrayWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |