From faf491f5b38e2f6784793cc4d4e68d421b0891b1 Mon Sep 17 00:00:00 2001 From: Dinopony Date: Fri, 13 Oct 2023 18:39:07 +0200 Subject: [PATCH] Fixed Dolphin connection issues for GameCube games --- HintMachine/Games/FZeroGXConnector.cs | 43 ++-------- .../Games/GeometryWarsGalaxiesConnector.cs | 51 +----------- HintMachine/Games/IDolphinConnector.cs | 82 +++++++++++++++++++ HintMachine/HintMachine.csproj | 1 + 4 files changed, 92 insertions(+), 85 deletions(-) create mode 100644 HintMachine/Games/IDolphinConnector.cs diff --git a/HintMachine/Games/FZeroGXConnector.cs b/HintMachine/Games/FZeroGXConnector.cs index 793663e..81b7656 100644 --- a/HintMachine/Games/FZeroGXConnector.cs +++ b/HintMachine/Games/FZeroGXConnector.cs @@ -1,10 +1,6 @@ -using System.Collections.Generic; -using System.Linq; -using static HintMachine.ProcessRamWatcher; - -namespace HintMachine.Games +namespace HintMachine.Games { - public class FZeroGXConnector : IGameConnector + public class FZeroGXConnector : IDolphinConnector { private readonly HintQuestCumulative _cupPointsQuest = new HintQuestCumulative { @@ -17,17 +13,15 @@ public class FZeroGXConnector : IGameConnector private readonly HintQuestCumulative _knockoutsQuest = new HintQuestCumulative { Name = "Knock-outs", - GoalValue = 10, - MaxIncrease = 2, + GoalValue = 20, + MaxIncrease = 3, }; - private ProcessRamWatcher _ram = null; - private long _mem1Addr = 0; private bool _wasRacingLastTick = false; // ---------------------------------------------------------- - public FZeroGXConnector() + public FZeroGXConnector() : base(false, "GFZE01") { Name = "F-Zero GX"; Description = "F-Zero GX is the fourth installment in the F-Zero series and the successor to F-Zero X. " + @@ -40,33 +34,6 @@ public FZeroGXConnector() Quests.Add(_knockoutsQuest); } - public override bool Connect() - { - _ram = new ProcessRamWatcher("Dolphin"); - if (!_ram.TryConnect()) - return false; - - List regions = _ram.ListMemoryRegions(0x20000, MemoryRegionType.MEM_MAPPED); - foreach (MemoryRegion region in regions) - { - byte[] SIGNATURE = new byte[] { 0x47, 0x46, 0x5A, 0x45, 0x30, 0x31 }; // GFZE01 - byte[] signatureBytes = _ram.ReadBytes(region.BaseAddress, SIGNATURE.Length); - if (Enumerable.SequenceEqual(signatureBytes, SIGNATURE)) - { - _mem1Addr = region.BaseAddress; - break; - } - } - - return (_mem1Addr != 0); - } - - public override void Disconnect() - { - _ram = null; - _mem1Addr = 0; - } - public override bool Poll() { long isRacingAddr = _mem1Addr + 0x17D7A9; diff --git a/HintMachine/Games/GeometryWarsGalaxiesConnector.cs b/HintMachine/Games/GeometryWarsGalaxiesConnector.cs index bf8879a..cb1685f 100644 --- a/HintMachine/Games/GeometryWarsGalaxiesConnector.cs +++ b/HintMachine/Games/GeometryWarsGalaxiesConnector.cs @@ -4,20 +4,17 @@ namespace HintMachine.Games { - public class GeometryWarsGalaxiesConnector : IGameConnector + public class GeometryWarsGalaxiesConnector : IDolphinConnector { - private ProcessRamWatcher _ram = null; - private readonly HintQuestCumulative _geomsQuest = new HintQuestCumulative { Name = "Geoms collected", GoalValue = 10000 }; - - private long _mem1Addr = 0; - private long _mem2Addr = 0; + + // ------------------------------------------------------ - public GeometryWarsGalaxiesConnector() + public GeometryWarsGalaxiesConnector() : base(true, "RGLP7D") { Name = "Geometry Wars Galaxies (Wii)"; Description = "Destroy geometric enemies in this classic and stylish twin-stick shooter " + @@ -28,46 +25,6 @@ public GeometryWarsGalaxiesConnector() Quests.Add(_geomsQuest); } - public override bool Connect() - { - _ram = new ProcessRamWatcher("Dolphin"); - if (!_ram.TryConnect()) - return false; - - List regions = _ram.ListMemoryRegions(0x2000000, MemoryRegionType.MEM_MAPPED); - foreach (MemoryRegion region in regions) - { - byte[] SIGNATURE = new byte[] { 0x52, 0x47, 0x4C, 0x50, 0x37, 0x44 }; - byte[] signatureBytes = _ram.ReadBytes(region.BaseAddress, SIGNATURE.Length); - if (Enumerable.SequenceEqual(signatureBytes, SIGNATURE)) - { - _mem1Addr = region.BaseAddress; - break; - } - } - - regions = _ram.ListMemoryRegions(0x4000000, MemoryRegionType.MEM_MAPPED); - foreach (MemoryRegion region in regions) - { - byte[] SIGNATURE = new byte[] { 0x02, 0x9F, 0x00, 0x10, 0x02, 0x9F, 0x00, 0x33 }; - byte[] signatureBytes = _ram.ReadBytes(region.BaseAddress, SIGNATURE.Length); - if (Enumerable.SequenceEqual(signatureBytes, SIGNATURE)) - { - _mem2Addr = region.BaseAddress; - break; - } - } - - return (_mem1Addr != 0 && _mem2Addr != 0); - } - - public override void Disconnect() - { - _ram = null; - _mem1Addr = 0; - _mem2Addr = 0; - } - public override bool Poll() { long geomsAddr = _mem2Addr + 0x23A2AF4; diff --git a/HintMachine/Games/IDolphinConnector.cs b/HintMachine/Games/IDolphinConnector.cs new file mode 100644 index 0000000..f214150 --- /dev/null +++ b/HintMachine/Games/IDolphinConnector.cs @@ -0,0 +1,82 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using static HintMachine.ProcessRamWatcher; + +namespace HintMachine.Games +{ + public abstract class IDolphinConnector : IGameConnector + { + protected ProcessRamWatcher _ram = null; + protected long _mem1Addr = 0; + protected long _mem2Addr = 0; + protected readonly bool _isWii; + protected readonly string _gameCode; + + // ---------------------------------------------------------------- + + public IDolphinConnector(bool isWii, string gameCode) + { + _isWii = isWii; + _gameCode = gameCode; + // TODO: Platform + // TODO: SupportedEmulators + } + + public override bool Connect() + { + _ram = new ProcessRamWatcher("Dolphin"); + if (!_ram.TryConnect()) + return false; + + if (!InitMEM1()) + return false; + + if (_isWii && !InitMEM2()) + return false; + + return true; + } + + public override void Disconnect() + { + _ram = null; + _mem1Addr = 0; + _mem2Addr = 0; + } + + protected bool InitMEM1() + { + byte[] signature = Encoding.ASCII.GetBytes(_gameCode); + + List regions = _ram.ListMemoryRegions(0x2000000, MemoryRegionType.MEM_MAPPED); + foreach (MemoryRegion region in regions) + { + byte[] signatureBytes = _ram.ReadBytes(region.BaseAddress, signature.Length); + if (Enumerable.SequenceEqual(signatureBytes, signature)) + { + _mem1Addr = region.BaseAddress; + break; + } + } + + return (_mem1Addr != 0); + } + + protected bool InitMEM2() + { + List regions = _ram.ListMemoryRegions(0x4000000, MemoryRegionType.MEM_MAPPED); + foreach (MemoryRegion region in regions) + { + // byte[] signatureBytes = _ram.ReadBytes(region.BaseAddress + signatureOffset, signature.Length); + // if (Enumerable.SequenceEqual(signatureBytes, signature)) + // { + _mem2Addr = region.BaseAddress; + break; + //} + } + + return (_mem2Addr != 0); + } + } +} diff --git a/HintMachine/HintMachine.csproj b/HintMachine/HintMachine.csproj index 8a9d8db..8bd3248 100644 --- a/HintMachine/HintMachine.csproj +++ b/HintMachine/HintMachine.csproj @@ -129,6 +129,7 @@ Designer +