Skip to content

Commit

Permalink
Merge branch 'master' into meteos
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinopony authored Oct 12, 2023
2 parents a868b1f + 7058cb4 commit b7bb93d
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 18 deletions.
13 changes: 11 additions & 2 deletions HintMachine/ArchipelagoHintSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,18 @@ public class ArchipelagoHintSession
public event HintsUpdateHandler OnHintsUpdate;

/// <summary>
/// The amount of remaining random hints the client has to ask the server
/// The amount of remaining random hints the client has yet to ask the server
/// </summary>
public int PendingRandomHints { get; set; } = 0;
public int PendingRandomHints
{
get { return _pendingRandomHints; }
set {
_pendingRandomHints = value;
if (_pendingRandomHints > Globals.PendingHintsQueueMaxSize)
_pendingRandomHints = Globals.PendingHintsQueueMaxSize;
}
}
private int _pendingRandomHints = 0;

/// <summary>
/// A thread responsible for requesting new random hints when PendingRandomHints > 0
Expand Down
7 changes: 6 additions & 1 deletion HintMachine/Games/FZeroGXConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class FZeroGXConnector : IGameConnector

private ProcessRamWatcher _ram = null;
private long _mem1Addr = 0;
private bool _wasRacingLastTick = false;

// ----------------------------------------------------------

Expand Down Expand Up @@ -69,7 +70,9 @@ public override void Disconnect()
public override bool Poll()
{
long isRacingAddr = _mem1Addr + 0x17D7A9;
if(_ram.ReadUint8(isRacingAddr) == 1)
bool isRacing = (_ram.ReadUint8(isRacingAddr) != 0);

if (_wasRacingLastTick)
{
long knockoutsCountAddr = _mem1Addr + 0xC46A22;
int knockoutsCount = _ram.ReadUint8(knockoutsCountAddr);
Expand All @@ -79,6 +82,8 @@ public override bool Poll()
_cupPointsQuest.UpdateValue(_ram.ReadUint16(cupPointsAddr, true));
}

_wasRacingLastTick = isRacing;

return true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion HintMachine/Games/OneFingerDeathPunchConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public override bool Poll()
{
syncThreadStackAdr();

long killsAddress = _ram.ResolvePointerPath32(_threadstack0Address.ToInt32() - 0x8cc, new int[] { 0x644, 0x90 });
//long killsAddress = _ram.ResolvePointerPath32(_threadstack0Address.ToInt32() - 0x8cc, new int[] { 0x644, 0x90 });
long killsAddress = _ram.ResolvePointerPath32(_threadstack0Address.ToInt32() - 0x8A0, new int[] { 0x710, 0x3C });
_killsQuest.UpdateValue(_ram.ReadUint32(killsAddress));

return true;
Expand Down
40 changes: 40 additions & 0 deletions HintMachine/Games/PacManChampionshipEditionDXConnector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace HintMachine.Games
{
public class PacManChampionshipEditionDXConnector : IGameConnector
{
private readonly HintQuestCumulative _scoreQuest = new HintQuestCumulative
{
Name = "Cumulative Score",
GoalValue = 400000,
};

private ProcessRamWatcher _ram = null;

public PacManChampionshipEditionDXConnector()
{
Name = "PAC-MAN Championship Edition DX+";
Description = "It's time to gear up! Get ready for more ghost chain gobbling and frantic action in PAC-MAN CE-DX+!";
SupportedVersions = "Steam";
Author = "Serpent.AI";

Quests.Add(_scoreQuest);
}

public override bool Connect()
{
_ram = new ProcessRamWatcher("PAC-MAN");
return _ram.TryConnect();
}

public override void Disconnect()
{
_ram = null;
}

public override bool Poll()
{
_scoreQuest.UpdateValue(_ram.ReadUint32(_ram.BaseAddress + 0x33CA14));
return true;
}
}
}
66 changes: 56 additions & 10 deletions HintMachine/Games/TetrisEffectConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,58 @@
{
public class TetrisEffectConnector : IGameConnector
{
private readonly HintQuestCumulative _scoreQuest = new HintQuestCumulative
private readonly HintQuestCumulative _linesQuest = new HintQuestCumulative
{
Name = "Score",
GoalValue = 20000,
Name = "Cleared Lines",
GoalValue = 250,
};
private readonly HintQuestCumulative _tetrisesQuest = new HintQuestCumulative
{
Name = "Tetris™",
GoalValue = 25,
};
private readonly HintQuestCumulative _backToBackQuest = new HintQuestCumulative
{
Name = "Back-to-Back",
GoalValue = 30,
};
private readonly HintQuestCumulative _tspinsQuest = new HintQuestCumulative
{
Name = "T-Spins",
GoalValue = 40,
};
// private readonly HintQuestCumulative _combosQuest = new HintQuestCumulative
// {
// Name = "Combos",
// GoalValue = 60,
// };
// private readonly HintQuestCumulative _perfectClearsQuest = new HintQuestCumulative
// {
// Name = "All Clears",
// GoalValue = 5,
// };

private ProcessRamWatcher _ram = null;

// ------------------------------------------------------------------------

public TetrisEffectConnector()
{
Name = "Tetris Effect Connected";
Description = "Stack tetrominos and fill lines to clear them in the most visually " +
"impressive implementation of Tetris ever made.";
Description = "Named after a real-world phenomenon where players' brains are so engrossed that images of the iconic falling " +
"Tetrimino blocks linger in their vision, thoughts, and even dreams, Tetris Effect amplifies this magical feeling " +
"of total immersion by surrounding you with fantastic, fully three-dimensional worlds that react and evolve based " +
"on how you play. Music, backgrounds, sounds, special effects - everything, down to the Tetris pieces themselves, " +
"pulse, dance, shimmer, and explode in perfect sync with how you're playing.";
SupportedVersions = "Tested on up-to-date Steam version.";
Author = "Dinopony";

Quests.Add(_scoreQuest);
Quests.Add(_linesQuest);
Quests.Add(_tetrisesQuest);
Quests.Add(_backToBackQuest);
Quests.Add(_tspinsQuest);
// Quests.Add(_perfectClearsQuest);
// Quests.Add(_combosQuest);
}

public override bool Connect()
Expand All @@ -34,10 +69,21 @@ public override void Disconnect()

public override bool Poll()
{
int[] OFFSETS = new int[] { 0x0, 0x20, 0x120, 0x0, 0x42C };
long scoreAddress = _ram.ResolvePointerPath64(_ram.BaseAddress + 0x4ED0440, OFFSETS);
if(scoreAddress != 0)
_scoreQuest.UpdateValue(_ram.ReadUint32(scoreAddress));
if (!_ram.TestProcess())
return false;

int[] OFFSETS = new int[] { 0x8, 0x8, 0x220, 0x200, 0x64 };
long linesAddress = _ram.ResolvePointerPath64(_ram.BaseAddress + 0x4ED9990, OFFSETS);
if (linesAddress != 0)
{
_linesQuest.UpdateValue(_ram.ReadUint32(linesAddress));
_tetrisesQuest.UpdateValue(_ram.ReadUint32(linesAddress + 0x40));
_backToBackQuest.UpdateValue(_ram.ReadUint32(linesAddress + 0x50));
_tspinsQuest.UpdateValue(_ram.ReadUint32(linesAddress + 0x70));

// _perfectClearsQuest.UpdateValue(_ram.ReadUint32(linesAddress + 0xC0));
// _combosQuest.UpdateValue(_ram.ReadUint32(combosAddress));
}

return true;
}
Expand Down
10 changes: 10 additions & 0 deletions HintMachine/Games/ZachtronicsSolitaireConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ZachtronicsSolitaireConnector : IGameConnector
private List<FileSystemWatcher> _watchers = new List<FileSystemWatcher>();
private string _fileToReadOnNextTick = "";
private Dictionary<string, int> _totalWinCounts = new Dictionary<string, int>();
private ProcessRamWatcher _ram = null;

// ----------------------------------------------------------------------------------

Expand All @@ -36,6 +37,10 @@ public override bool Connect()
{
try
{
_ram = new ProcessRamWatcher("The Zachtronics Solitaire Collection");
if (!_ram.TryConnect())
return false;

// Setup a watcher to be notified when the file is changed
foreach(string pathToDir in FindPotentialSavefileDirectories())
{
Expand Down Expand Up @@ -70,10 +75,15 @@ public override void Disconnect()
foreach (FileSystemWatcher watcher in _watchers)
watcher.EnableRaisingEvents = false;
_watchers.Clear();

_ram = null;
}

public override bool Poll()
{
if(!_ram.TestProcess())
return false;

if (_fileToReadOnNextTick != "")
{
int oldWins = _totalWinCounts[_fileToReadOnNextTick];
Expand Down
17 changes: 16 additions & 1 deletion HintMachine/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@ internal static class Globals
public const string ProgramName = "HintMachine";
public const string ProgramVersion = "1.0.3";

/// <summary>
/// The duration of a "tick" where the current game connector (if any) watches the game once, in milliseconds
/// </summary>
public const int TickInterval = 100;

/// <summary>
/// The minimal duration between two hint queries obtained from quests
/// </summary>
public const int HintQueueInterval = 2000;

/// <summary>
/// The maximal amount of pending hints obtained from quest that can be stored at any given time.
/// If more hints are obtained, they will be discarded (but it will most likely be because of a bug / exploit anyway)
/// </summary>
public const int PendingHintsQueueMaxSize = 5;

public static readonly string NotificationSoundPath =
$@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Assets\Notification.wav";

Expand All @@ -34,7 +47,8 @@ internal static class Globals
new FZeroGXConnector(),
new IslandersConnector(),
new DorfromantikConnector(),
new MeteosConnector()
new MeteosConnector(),
new PacManChampionshipEditionDXConnector(),
};

public static IGameConnector FindGameFromName(string name)
Expand All @@ -46,6 +60,7 @@ public static IGameConnector FindGameFromName(string name)
return null;
}

// Easter egg commands
public static readonly List<string> HitMachineFacts = new List<string>() {
"Le saviez vous ? Avant d'être présenté par Charly et Lulu, le Hit Machine était animé par Ophelie Winter et Yves Noel.",
"Le saviez vous ? Le Hit Machine a été diffusé sur M6 entre 1994 et 2009",
Expand Down
1 change: 1 addition & 0 deletions HintMachine/HintMachine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<Compile Include="Games\INintendoDSConnector.cs" />
<Compile Include="Games\MeteosConnector.cs" />
<Compile Include="Games\BustAMove4Connector.cs" />
<Compile Include="Games\PacManChampionshipEditionDXConnector.cs" />
<Compile Include="Games\FZeroGXConnector.cs" />
<Compile Include="Games\DorfromantikConnector.cs" />
<Compile Include="Games\Rollcage2Connector.cs" />
Expand Down
14 changes: 12 additions & 2 deletions HintMachine/HintQuestCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public long CurrentValue
_currentValue = value;
}
}
//private bool resetQuest = false;
private long _currentValue = 0;
private DateTime _lastIncrementTime = DateTime.MinValue;

Expand Down Expand Up @@ -140,7 +139,18 @@ public override void InitComponents(Grid questsGrid)
public override void UpdateComponents()
{
_progressBar.Value = CurrentValue;
_progressBarOverlayText.Text = CurrentValue + " / " + GoalValue;
_progressBarOverlayText.Text = CurrentValue + " / " + GoalValue;

#if DEBUG
if (TimeoutBetweenIncrements > 0)
{
DateTime now = DateTime.UtcNow;
TimeSpan t = now - _lastIncrementTime;
double cooldown = TimeoutBetweenIncrements - t.TotalSeconds;
if(cooldown > 0)
_progressBarOverlayText.Text += $" ({Math.Ceiling(cooldown)}s cooldown)";
}
#endif
}
}
}
Expand Down
19 changes: 18 additions & 1 deletion HintMachine/ProcessRamWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected struct MEMORY_BASIC_INFORMATION
private ProcessModule _module = null;
private IntPtr _processHandle = IntPtr.Zero;

public long BaseAddress { get; set; } = 0;
public long BaseAddress { get; private set; } = 0;

// ----------------------------------------------------------------------------------

Expand Down Expand Up @@ -262,6 +262,23 @@ public List<MemoryRegion> ListMemoryRegions(long size = 0, MemoryRegionType type
return regions;
}

/// <summary>
/// Test if the attached process memory is still accessible.
/// </summary>
/// <returns>true if memory can be read, false otherwise</returns>
public bool TestProcess()
{
try
{
ReadUint8(BaseAddress);
return true;
}
catch(Exception)
{
return false;
}
}

/*
public long GetThreadstack0()
{
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Given its high dependency to system calls to do RAM peeking and stuff, only Wind
- ISLANDERS
- Meteos (DS)
- One Finger Death Punch
- PAC-MAN Championship Edition DX+
- Puyo Puyo Tetris
- Rollcage Stage 2 (PS1)
- Sonic 3 Blue Spheres
Expand Down

0 comments on commit b7bb93d

Please sign in to comment.