Skip to content

Commit

Permalink
Fixed teleports not working sometimes due to new camera reset function
Browse files Browse the repository at this point in the history
Added toggle for camera reset (on by default)
(Rayman 2) Added option to set checkpoint from saved position instead of current position
(Rayman 2) Added flag 1159 (Defeated Foutch)
(Rayman 2) Added indicator for Rayman 2 that the toolbox has been used (resting sad face syndrome)
  • Loading branch information
rtsonneveld committed Jul 1, 2023
1 parent 6b10fe1 commit e2ad8e8
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 40 deletions.
1 change: 1 addition & 0 deletions OpenSpaceToolbox/GameManager/Extras/ExtraAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected ExtraAction()
#region Public Properties

public string Name { get; protected set; }
public string Tooltip { get; protected set; }

public string ShortName { get; protected set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@

namespace OpenSpaceToolbox
{
public class Rayman2CheckpointExtra : OpenspaceExtraAction
{
public Rayman2CheckpointExtra(Rayman2GameManager gameManager) : base(gameManager)
public class Rayman2CheckpointExtra : OpenspaceExtraAction {
public enum CheckpointMode
{
Name = ShortName = "Set spawn point (CAREFUL)";
CurrentPosition,
SavedPosition
}

public Rayman2CheckpointExtra(Rayman2GameManager gameManager, CheckpointMode mode) : base(gameManager)
{
string modeName = mode switch
{
CheckpointMode.CurrentPosition => "(At Current)",
CheckpointMode.SavedPosition => "(At Saved)",
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null)
};
Name = ShortName = $"⚠ Set spawn point {modeName}";
Mode = mode;

ResurrectionPositionPointer = 0x500590;

Expand All @@ -17,8 +29,12 @@ public Rayman2CheckpointExtra(Rayman2GameManager gameManager) : base(gameManager

RespawnPersoPointer = 0x4B7308;
RespawnPersoPointerPath = new int[] {0xC, 0, 0x4, 0x1C, 0xA90 };

Tooltip = "⚠ Warning: these actions modify the program's executable memory and require a game restart to undo!";
}

public CheckpointMode Mode { get; set; }

private int RespawnPersoPointer { get; }
private int[] RespawnPersoPointerPath { get; }

Expand Down Expand Up @@ -59,12 +75,18 @@ public override void Action()
* -> if(g_stEngineStructure.bResurection)
*/

var playerCoords = GameManager.PlayerCoordinates;
var currentCoords = Mode switch {
CheckpointMode.CurrentPosition => GameManager.PlayerCoordinates,
CheckpointMode.SavedPosition => GameManager.SavedPosition,
_ => throw new ArgumentOutOfRangeException()
};

//CheckpointMode.CurrentPosition ? GameManager.PlayerCoordinates;

Thread.Sleep(100);

GameManager.WriteCoordinates(
playerCoords.Item1, playerCoords.Item2, playerCoords.Item3,
currentCoords.Item1, currentCoords.Item2, currentCoords.Item3,
ResurrectionPositionPointer);

// GlobalActorModel.DsgVar_29, reset checkpoint object to null
Expand All @@ -76,7 +98,7 @@ public override void Action()
GameManager.WriteEngineMode(8); // EM_ModePlayerDead

Thread.Sleep(150);
GameManager.PlayerCoordinates = playerCoords;
GameManager.PlayerCoordinates = currentCoords;
}
}
}
23 changes: 22 additions & 1 deletion OpenSpaceToolbox/GameManager/Games/Rayman2/Rayman2GameManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace OpenSpaceToolbox
{
Expand Down Expand Up @@ -36,7 +38,8 @@ public Rayman2GameManager()
new Rayman2MaxHpExtra(this),
new Rayman2GlmMonitorExtra(this),
new Rayman2ProgressArrayExtra(this),
new Rayman2CheckpointExtra(this),
new Rayman2CheckpointExtra(this, Rayman2CheckpointExtra.CheckpointMode.CurrentPosition),
new Rayman2CheckpointExtra(this, Rayman2CheckpointExtra.CheckpointMode.SavedPosition),
};

//Levels
Expand Down Expand Up @@ -181,6 +184,24 @@ public Rayman2GameManager()
};

Levels = LevelContainers.SelectMany(x => x.Levels);

Task.Run(ChangeHudIcon);
}

private int _hudChangedForProcess = -1;

private async void ChangeHudIcon()
{
while (true) {
int processHandle = GetProcessHandle(false);

if (processHandle > 0 && _hudChangedForProcess != processHandle) {
_hudChangedForProcess = processHandle;
WriteBytes(new byte[] { (byte)'x' }, 0x4B7314, 0x48, 0x54, 0x0, 0x10, 0x0, 0x4, 0x6EF);
}

await Task.Delay(1000);
}
}

#endregion
Expand Down
22 changes: 17 additions & 5 deletions OpenSpaceToolbox/GameManager/GenericGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,25 @@ public abstract class GenericGameManager
{
WritePlayerCoordinates(value.Item1, value.Item2, value.Item3);

bool oldGhostMode = ReadGhostMode();
WriteGhostMode(true);
Thread.Sleep(30);
WriteGhostMode(oldGhostMode);
if (CameraResetEnabled) {
bool oldGhostMode = ReadGhostMode();

Thread.Sleep(10);
WriteGhostMode(true);
Thread.Sleep(10);
WriteGhostMode(oldGhostMode);
}
}
}



/// <summary>
/// The saved position
/// </summary>
public (float, float, float) SavedPosition { get; set; }

public bool CameraResetEnabled { get; set; } = true;

/// <summary>
/// Current level name.
/// Retrieving and writing values to the memory should be handled in functions: GetCurrentLevelName and ChangeLevel.
Expand Down
2 changes: 1 addition & 1 deletion OpenSpaceToolbox/GameManager/OpenspaceGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void WriteDWord(int value, int baseAddress, params int[] offsets)

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

Expand Down
2 changes: 2 additions & 0 deletions OpenSpaceToolbox/OpenSpaceToolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -52,6 +53,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>OpenSpaceIcon.ico</ApplicationIcon>
Expand Down
22 changes: 2 additions & 20 deletions OpenSpaceToolbox/ViewModels/GameManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ public GameManagerViewModel(GenericGameManager gameManager)

#region Public Properties

/// <summary>
/// The saved X position
/// </summary>
public float SavedXPosition { get; set; }

/// <summary>
/// The saved Y position
/// </summary>
public float SavedYPosition { get; set; }

/// <summary>
/// The saved Z position
/// </summary>
public float SavedZPosition { get; set; }

/// <summary>
/// The random generator for this view model
/// </summary>
Expand Down Expand Up @@ -93,18 +78,15 @@ public void LoadOffsetLevel(int offset)
/// </summary>
public void LoadSavedPosition()
{
GameManager.PlayerCoordinates = (SavedXPosition, SavedYPosition, SavedZPosition);
GameManager.PlayerCoordinates = GameManager.SavedPosition;
}

/// <summary>
/// Save the position
/// </summary>
public void SavePosition()
{
var coords = GameManager.PlayerCoordinates;
SavedXPosition = coords.Item1;
SavedYPosition = coords.Item2;
SavedZPosition = coords.Item3;
GameManager.SavedPosition = GameManager.PlayerCoordinates;
}

#endregion
Expand Down
13 changes: 9 additions & 4 deletions OpenSpaceToolbox/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public MainViewModel(GenericGameManager gameManager)

HotkeysToggleTooltip =
"Enables hotkeys:\nR - reload level\nK - previous level\nL - next level\nP - save position\nO - load position\nB - add bookmark";
}

CameraResetToggleTooltip =
"Forces the camera to reset when changing position - this has some side effects like in Walk of Life/Power or it can even crash";
}

#endregion

Expand Down Expand Up @@ -114,11 +117,13 @@ public void OnKeyPressed(object sender, GlobalKeyboardHookEventArgs e)

public string HotkeysToggleTooltip { get; }

#endregion
public string CameraResetToggleTooltip { get; }

#endregion

#region Private Methods
#region Private Methods

private void SetMinimizedView()
private void SetMinimizedView()
{
CurrentView = new GameManagerMinimizedView();
WindowProperties.SetMinSize(250, 400);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public ProgressArrayWindowViewModel(Rayman2ProgressArrayExtra extra)
new FlagItem(Extra, 1123, "Elixir of Life obtained"),
new FlagItem(Extra, 1133, "watched woods of light teensie cutscene"),
new FlagItem(Extra, 1143, "orange shots, fist charge power (glowfist)"),
new FlagItem(Extra, 1159, "Foutch defeated in Beneath Rock and Lava"),
new FlagItem(Extra, 1171, "Clark destroyed the first wall"),
new FlagItem(Extra, 1172, "Clark destroyed the second wall"),
new FlagItem(Extra, 1175, "Woods of Light murfy 1"),
Expand Down
9 changes: 7 additions & 2 deletions OpenSpaceToolbox/Views/GameManagerFullView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,23 @@

<MenuItem.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:ExtraAction}">
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock ToolTip="{Binding Tooltip}" Text="{Binding Name}"></TextBlock>
</HierarchicalDataTemplate>
</MenuItem.ItemTemplate>

</MenuItem>

<MenuItem Header="Settings">
<MenuItem Header="Settings" Click="MenuItem_Click">

<MenuItem Header="Enable hotkeys"
IsCheckable="True"
IsChecked="{Binding Path=HotkeysEnabled}"
ToolTip="{Binding Path=HotkeysToggleTooltip}" />

<MenuItem Header="Enable camera reset"
IsCheckable="True"
IsChecked="{Binding Path=GameManager.CameraResetEnabled}"
ToolTip="{Binding Path=CameraResetToggleTooltip}" />

<MenuItem Header="Minimized UI"
Command="{Binding Path=ToggleMinimizedUiCommand}">
Expand Down
5 changes: 5 additions & 0 deletions OpenSpaceToolbox/Views/GameManagerFullView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ private void LevelTreeItemDoubleClick(object sender, MouseButtonEventArgs e)
DataContext is MainViewModel viewModel)
viewModel.GameManager.CurrentLevel = lvl.FileName;
}

private void MenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
{

}
}
}

0 comments on commit e2ad8e8

Please sign in to comment.