Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCMemcard: Change behavior of TitlePresent() to more closely resemble how saves are actually identified. #8903

Merged

Conversation

AdmiralCurtiss
Copy link
Contributor

@AdmiralCurtiss AdmiralCurtiss commented Jun 27, 2020

This modifies GCMemcard::TitlePresent() to match my findings of how the GC BIOS and various games behave when you muck with the fields in the directory entry.

It looks like for a save to be recognized by a game, the following have to be true:

  • Game code and maker code must exactly match what the game expects.
  • Filename is only checked up to the first null byte. All bytes afterwards can be whatever.

The BIOS itself does a full compare of the filename when checking for whether it should allow copying a file from one card to another, but behaves oddly in some cases when there's non-null bytes after the first null. See the big comment in HasSameIdentity() for details.

The new GCMemcardUtils.cpp file may seem a bit excessive for now, but I have some plans for some improvements to the memory card manager that would fit well in there, and GCMemcard.cpp is pretty crowded already.

I'm also not sure if "Identity" is a good word to describe what we're comparing here; any other suggestions?

@lioncash
Copy link
Member

Commit should probably have the extended description added to it, so that info is stored in the repository

@AdmiralCurtiss
Copy link
Contributor Author

Good point, done.

if (lhs.m_makercode != rhs.m_makercode)
return false;

for (size_t i = 0; i < lhs.m_filename.size(); ++i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this perhaps be i < std::min(lhs.m_filename.size(), rhs.m_filename.size())? Or do we make sure that the lhs filename is shorter than (or of equal length to) the rhs filename?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that, I just noticed this is an array and not an actual string.

if (lhs.m_makercode != rhs.m_makercode)
return false;

for (size_t i = 0; i < lhs.m_filename.size(); ++i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that, I just noticed this is an array and not an actual string.

… how saves are actually identified.

This modifies GCMemcard::TitlePresent() to match my findings of how the GC BIOS and various games behave when you alter the fields in the directory entry.

It looks like for a save to be recognized by a game, the following have to be true:
- Game code and maker code must exactly match what the game expects.
- Filename is only checked up to the first null byte. All bytes afterwards can be whatever.

The BIOS itself does a full compare of the filename when checking for whether it should allow copying a file from one card to another, but behaves oddly in some cases when there's non-null bytes after the first null. See the big comment in `HasSameIdentity()` for details.
@AdmiralCurtiss
Copy link
Contributor Author

Clarified the description a bit, code was not changed.

@JosJuice JosJuice merged commit 213c184 into dolphin-emu:master Jul 23, 2020
10 checks passed
@AdmiralCurtiss AdmiralCurtiss deleted the gcmemcard-file-identity-check branch July 23, 2020 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants