Skip to content

Commit

Permalink
Fixed Dolphin connection issues for GameCube games
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinopony committed Oct 13, 2023
1 parent 8379bfd commit faf491f
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 85 deletions.
43 changes: 5 additions & 38 deletions HintMachine/Games/FZeroGXConnector.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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. " +
Expand All @@ -40,33 +34,6 @@ public FZeroGXConnector()
Quests.Add(_knockoutsQuest);
}

public override bool Connect()
{
_ram = new ProcessRamWatcher("Dolphin");
if (!_ram.TryConnect())
return false;

List<MemoryRegion> 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;
Expand Down
51 changes: 4 additions & 47 deletions HintMachine/Games/GeometryWarsGalaxiesConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand All @@ -28,46 +25,6 @@ public GeometryWarsGalaxiesConnector()
Quests.Add(_geomsQuest);
}

public override bool Connect()
{
_ram = new ProcessRamWatcher("Dolphin");
if (!_ram.TryConnect())
return false;

List<MemoryRegion> 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;
Expand Down
82 changes: 82 additions & 0 deletions HintMachine/Games/IDolphinConnector.cs
Original file line number Diff line number Diff line change
@@ -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<MemoryRegion> 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<MemoryRegion> 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);
}
}
}
1 change: 1 addition & 0 deletions HintMachine/HintMachine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ArchipelagoHintSession.cs" />
<Compile Include="Games\IDolphinConnector.cs" />
<Compile Include="Games\INintendoDSConnector.cs" />
<Compile Include="Games\MeteosConnector.cs" />
<Compile Include="Games\BustAMove4Connector.cs" />
Expand Down

0 comments on commit faf491f

Please sign in to comment.