-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Dolphin connection issues for GameCube games
- Loading branch information
Showing
4 changed files
with
92 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters