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

Add PS5 system to info #154

Merged
merged 7 commits into from
May 27, 2024
Merged

Add PS5 system to info #154

merged 7 commits into from
May 27, 2024

Conversation

Deterous
Copy link
Contributor

Adds PS5 as a supported system by redumper info
Prints version and serial of the disc:

PS5 [track.iso]:
  version: 01.00
  serial: PPSA01234

More info: https://www.psdevwiki.com/ps5/Param.json

I have implemented a very naive JSON parser, only what is required.

Tested by dumping the only PS5 disc I own.

systems/ps5.ixx Outdated
Comment on lines 47 to 48
auto it = param_json.find("masterVersion");
if(it != param_json.end())
Copy link
Owner

Choose a reason for hiding this comment

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

nit: please move it declaration into if(), like here:
https://github.com/superg/redumper/blob/main/systems/ps3.ixx#L48

systems/ps5.ixx Outdated
Comment on lines 51 to 52
it = param_json.find("masterDataId");
if(it != param_json.end())
Copy link
Owner

Choose a reason for hiding this comment

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

Same as previous comment

systems/ps5.ixx Outdated
std::map<std::string, std::string> json;

auto json_entry = root_directory->subEntry(json_file);
if(json_entry)
Copy link
Owner

Choose a reason for hiding this comment

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

nit: you can get rid of an extra indent by:

if(!json_entry)
    return json;

systems/ps5.ixx Outdated
if(data.size() <= 0x800)
return json;

data.erase(data.begin(), data.begin() + 0x800);
Copy link
Owner

Choose a reason for hiding this comment

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

Erasing from std::vector has to shift all data left. In this case it's not a performance issue but consider using std::span<uint8_t>.
That will basically give you vector interface without modifying data, examples:
https://github.com/superg/redumper/blob/main/systems/ps4.ixx#L52
https://github.com/superg/redumper/blob/main/systems/ps3.ixx#L156

systems/ps5.ixx Outdated
Comment on lines 71 to 72
size_t cur = 0;
while(cur < data.size())
Copy link
Owner

Choose a reason for hiding this comment

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

nit: As you don't need cur outside of the loop, for() loop is preferable over while(), could do:

for(size_t cur = 0; cur < data.size(); )

systems/ps5.ixx Outdated
Comment on lines 127 to 136
std::string key(data.begin() + keyStart, data.begin() + keyEnd);
std::string value(data.begin() + valueStart, data.begin() + valueEnd);
erase_all_inplace(key, '\0');
erase_all_inplace(key, '\r');
erase_all_inplace(key, '\n');
erase_all_inplace(value, '\0');
erase_all_inplace(value, '\r');
erase_all_inplace(value, '\n');
trim_inplace(key);
trim_inplace(value);
Copy link
Owner

Choose a reason for hiding this comment

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

Removing \0 \r \n seem an overkill to me (unless serial and version that we use have those characters).
There is also an easy way to get rid of trailing \0 while being safe if string doesn't end with \0, example:
https://github.com/superg/redumper/blob/main/systems/ps3.ixx#L183

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing new lines is needed in order to properly trim the values due to the naive way I am parsing JSON. As values are not always enclosed in quotations, sometimes it is needed to keep looking until the end } which occurs after a newline. Removing nulls is just for safety.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, got it, so key/value can be surrounded by the new lines that get skipped by parser. Keep it then.

systems/ps5.ixx Outdated
Comment on lines 139 to 140
if(value.size() >= 2 && value.front() == '"' && value.back() == '"')
value = value.substr(1, value.size() - 2);
Copy link
Owner

Choose a reason for hiding this comment

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

Also, not really a performance thing here, but instead of substr() you can define std::string_view() and emplace it instead (same behavior as std::span but for std::string)

@superg
Copy link
Owner

superg commented May 26, 2024

Ah, forgot to mention, please add dash to the serial if it isn't there.

@superg superg merged commit f52fd2e into superg:main May 27, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants