Skip to content

Commit

Permalink
Fix RCTrack sector reads
Browse files Browse the repository at this point in the history
It appears rcheevos expects user data, not raw sector data
  • Loading branch information
CasualPokePlayer committed Oct 15, 2024
1 parent 6582431 commit b7e57db
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private class RCTrack : IDisposable
private readonly Disc _disc;
private readonly DiscSectorReader _dsr;
private readonly DiscTrack _track;
private readonly byte[] _buf2448;
private readonly byte[] _buf2352;

public bool IsAvailable => _disc != null;
public int LBA => _track.LBA;
Expand Down Expand Up @@ -194,8 +194,8 @@ public RCTrack(string path, int tracknum)
return;
}

_dsr = new(_disc);
_buf2448 = new byte[2448];
_dsr = new(_disc) { Policy = { ThrowExceptions2048 = false } };
_buf2352 = new byte[2352];
}

public int ReadSector(int lba, IntPtr buffer, nuint requestedBytes)
Expand All @@ -205,9 +205,11 @@ public int ReadSector(int lba, IntPtr buffer, nuint requestedBytes)
return 0;
}

var numRead = _dsr.ReadLBA_2448(lba, _buf2448, 0);
var numRead = _track.IsAudio
? _dsr.ReadLBA_2352(lba, _buf2352, 0)
: _dsr.ReadLBA_2048(lba, _buf2352, 0);
var numCopied = (int)Math.Min((ulong)numRead, requestedBytes);
Marshal.Copy(_buf2448, 0, buffer, numCopied);
Marshal.Copy(_buf2352, 0, buffer, numCopied);
return numCopied;
}

Expand Down

0 comments on commit b7e57db

Please sign in to comment.