Skip to content

Commit

Permalink
Add dsgVar_3 memory search tool
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfirex86 committed May 24, 2020
1 parent 64a4b9c commit 429b767
Show file tree
Hide file tree
Showing 7 changed files with 1,830 additions and 4 deletions.
19 changes: 17 additions & 2 deletions RevoGlmViewer/GlmViewerForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions RevoGlmViewer/GlmViewerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,16 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
tokenSource?.Dispose();
}

private void findButton_Click(object sender, EventArgs e)
{
SearchForm search = new SearchForm();
search.ShowDialog();

if (search.FoundAddr != 0)
{
textAddr.Text = search.FoundAddr.ToString("X");
}
}
}
}
4 changes: 2 additions & 2 deletions RevoGlmViewer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
9 changes: 9 additions & 0 deletions RevoGlmViewer/RevoGlmViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
<Compile Include="Memory.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SearchForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SearchForm.Designer.cs">
<DependentUpon>SearchForm.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="GlmViewerForm.resx">
<DependentUpon>GlmViewerForm.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -71,6 +77,9 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="SearchForm.resx">
<DependentUpon>SearchForm.cs</DependentUpon>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
113 changes: 113 additions & 0 deletions RevoGlmViewer/SearchForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 133 additions & 0 deletions RevoGlmViewer/SearchForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RevoGlmViewer
{
public partial class SearchForm : Form
{
public SearchForm()
{
InitializeComponent();

handle = Memory.GetProcessHandle("pcsx2");
if (handle == 0)
{
MessageBox.Show("PCSX2 not detected. Start PCSX2 and the game first, or launch RevoGlmViewer as admin if it's already running.");
Close();
}

step = 0;
InitStep();
}

private const int BaseAddr = 0x20000000;

private int handle;
private int step;
private byte searchFor;

private List<int> savedMem;

public int FoundAddr { get; private set; } = 0;

private void buttonNext_Click(object sender, EventArgs e)
{
MemSearch(searchFor);

if (savedMem.Count == 1)
{
FoundAddr = savedMem[0];
MessageBox.Show($"Found DsgVar_3 address: 0x{FoundAddr:X}");
Close();
}
else if (savedMem.Count == 0)
{
MessageBox.Show($"Cannot find DsgVar_3 address - try again.");
Close();
}

step++;
InitStep();
}

private void InitStep()
{
switch (step)
{
case 0:
title.Text = "Walking";
description.Text = "Pause the game while walking or running and press Next.";
searchFor = 2;
break;

case 1:
title.Text = "Standing";
description.Text = "Pause the game while standing and press Next.";
searchFor = 0;
break;

case 2:
title.Text = "Jumping";
description.Text = "Pause the game while jumping (Rayman has to be midair and moving upwards) and press Next.";
searchFor = 11;
break;

case 3:
title.Text = "Falling";
description.Text = "Pause the game while falling (Rayman has to be midair and moving downwards) and press Next.";
searchFor = 13;
break;

default:
step = 0;
InitStep();
break;
}
}

private void MemSearch(byte value)
{
int handle = Memory.GetProcessHandle("pcsx2");
if (handle == 0)
{
MessageBox.Show("PCSX2 not detected. Start PCSX2 and the game first, or launch RevoGlmViewer as admin if it's already running.");
return;
}

int _ = 0;
byte[] buffer;
List<int> found = new List<int>();

if (savedMem == null)
{
buffer = new byte[0x4000000];
Memory.ReadProcessMemory(handle, BaseAddr, buffer, buffer.Length, ref _);

for (int i = 0; i < buffer.Length; i++)
{
if (buffer[i] == value)
{
found.Add(BaseAddr + i);
}
}
}
else
{
buffer = new byte[1];

foreach (int i in savedMem)
{
Memory.ReadProcessMemory(handle, i, buffer, 1, ref _);
if (buffer[0] == value)
{
found.Add(i);
}
}
}

savedMem = found;
addrCount.Text = savedMem.Count.ToString();
}
}
}
Loading

0 comments on commit 429b767

Please sign in to comment.