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
Reimplement/fix PRX patches #9746
Conversation
Just a note: the MGS4 patch only applies for firmware version 4.87 and may need to be updated with newer firmware versions. |
rpcs3/Emu/Cell/PPUModule.cpp
Outdated
hash[4 + i * 2] = pal[prx->sha1[i] >> 4]; | ||
hash[5 + i * 2] = pal[prx->sha1[i] & 15]; | ||
} | ||
const std::string hash = fmt::format("PRX-%s", fmt::base57(prx->sha1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Killing two birds in one stone: old PRX patches are invalidated, and the hashes naming system is updated to use the newer LLVM's base 57 format as opposed to the old base 16.
I don't really like the idea of having a patch that you need to toggle off and on on game-by-game basis, to me it seems like something that'd cause a lot of confusion for end users and equal amounts of annoyance to those who try to help them. We should find a way to limit this to only apply to MGS4 by default, maybe in another PR if it's out of scope for this one. |
Where do you see the patch in pr.. lmao. |
The patch itself isn't part of this pr, but since we're introducing patching system that allows firmware modifications we should consider the possible problems in such system and ways to avoid them. The very first implementation to this system already seems like a support nightmare, and I suspect that we'll see more patches like this in future. This all is just my own opinion though, I'm just raising my concerns and not demanding changes. That's up to the people who have merge rights. |
It supports gameids.. I don't understand your concern. |
Oh right, you can have the patches in |
No, not right, patches support gameids even with main online patches database. I don't understand why we need specific files for each gameid. |
I'm sorry if I talked agressively but you seemed to not understand how patches work at all. |
Seems like I've misunderstood how patches are applied then. Sorry for the confusion, and feel free to ignore my comments. |
There's a problem in theory with squeezing allocation: there is more chance for OOM because the memory layout may not allow it as it requires one bigger memory "hole" as opposed a few smaller holes which are easier to find. So this should be a function from patches side to handle PRX specially. I will work on it when I have time. |
I doubt minimal patch support needs anything more than one segment base.
|
|
I improved further this, this is the format of PRX patches: |
ffaaad6
to
2544487
Compare
Clear firmware PPU cache before testing the patch itself with pr. |
I updated the patch entry in pr description so update it if you wanna test. |
Utilities/bin_patch.cpp
Outdated
break; | ||
} | ||
} | ||
|
||
applied.push_back(resval); | ||
// Possibly an executable instruction | ||
applied.push_back(offset & -4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only be32 is practically used to signify executable instruction. Okay, also be64 can contain two. But other types are more likely to add garbage to the analyser rather than improve it. Especially floats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, other types push 0 to applied
on purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who said BE32 must not be garbage as well? Analyser should deal with anything you throw at it basically including garbage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I consider changing the patch to be16 as it only meant to change op.uimm16 of ORI instruction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't invert question like this. Basically if it works, don't break it.
If it's be16 it already contains some valid instruction, there is no need to inform analyser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR I don't agree but there's no point in addressing in this pr.
e7a7989
to
ddc9c75
Compare
@@ -607,14 +596,14 @@ static std::basic_string<u32> apply_modification(const patch_engine::patch_info& | |||
} | |||
} | |||
|
|||
// Possibly an executable instruction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of aligning them down, seems better to not add unaligned patches to resval at all.
Utilities/bin_patch.cpp
Outdated
@@ -559,6 +546,7 @@ static std::basic_string<u32> apply_modification(const patch_engine::patch_info& | |||
case patch_type::le32: | |||
{ | |||
*reinterpret_cast<le_t<u32, 1>*>(ptr) = static_cast<u32>(p.value.long_value); | |||
resval = offset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who uses le32 for instructions? It seems very inconvenient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about conveniency, it's about not introducing bugs which can be discovered by the user with some effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed anyways.
Fixed typo in patch hash. |
Where? It's merged |
Just edited pr description. |
What is a PRX file? PRX stands for "PPU Relocatable Executable". What "relocatable" means in this context you ask? it means that the data/code segments of the PRX file can be mapped at any given address as long as the address is free from another memory mapping. Because every single PS3 application has different memory layout (it can even change within different boots of the same application!) we need PRX patches to be able to exist at any address based on relative offsets from segments instead of hardcoded addresses. This is fixed by this pull request.
Enhancements
Bugfixes
What this allows?
This allows to patch SPRX files as for firmware's.
I ported rujkosto's Metal Gear Solid 4's hack build in cellSpurs to a patch file of the firmware instead.
Here is the entry (need to be manually added until pushed to main patches)