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

Implement dynamic patching support in pnaches #11801

Merged
merged 1 commit into from
Sep 26, 2024
Merged

Implement dynamic patching support in pnaches #11801

merged 1 commit into from
Sep 26, 2024

Conversation

F0bes
Copy link
Member

@F0bes F0bes commented Sep 11, 2024

Description of Changes

Implement a new dpatch command

The length of the dpatch line is dynamic and user controlled

dpatch=<version/type>,<# of patterns>,<# of replacements>,...

As of this PR the only valid version/type is 0. This is to prevent the need to break backwards compatibility in the future

After these first three sections you put the patterns and replacements. The format of those are identical:
<offset>,<value>

An example is as follows:

dpatch=0,3,1,0,8FA20000,4,02002025,8,24420010,8,00000000

This line has 3 patterns and 1 replacement

It looks for the following set of instructions

0 | 8FA20000
4 | 02002025
8 | 24420010

and will replace offset #8 with 00000000

The values are a fixed 32 bits because this only works on code memory. Dynamic patches only work on the EE recompiler and only activate during recompilation stage. This means the dpatch will only work on code that has not been compiled to x86 yet. If you enable the dpatch too late, nothing will happen. I suppose the entire rec cache can be invalidated when dpatches are enabled or disabled. I think it's easier just telling people to reset the VM after enabling (or disabling) any dpatches.

Rationale behind Changes

Sometimes you need to patch dynamic code that moves around.

Suggested Testing Steps

Try to write a dynamic patch and see if it works.
Maybe make sure it doesn't cause issues with gamedb dynamic patches?
Interleave them with normal patches?

pcsx2/Patch.cpp Outdated Show resolved Hide resolved
@SuperSamus
Copy link
Contributor

Tested Ratchet: Deadlocked (PCSX2/pcsx2_patches#383), works fine 👍.
It was also interleaved with a normal patch (the Widescreen patch).

make sure it doesn't cause issues with gamedb dynamic patches?

Didn't test it.
Should this system still be here? There's only one game that uses it (R&C 2 PAL), couldn't it be replaced by the patches: default: content: |- syntax used to apply regular patches on other games?

@F0bes
Copy link
Member Author

F0bes commented Sep 11, 2024

Should this system still be here? There's only one game that uses it (R&C 2 PAL), couldn't it be replaced by the patches: default: content: |- syntax used to apply regular patches on other games?

I guess this can replace the dynamic patches in the gamedb. I'll be honest, I don't really know if I like this system. There is no lookahead in the pnach parser. I was forced to write a layout that is placed in all one line and it's kind of unreadable lol

@F0bes
Copy link
Member Author

F0bes commented Sep 16, 2024

I suppose the entire rec cache can be invalidated when dpatches are enabled or disabled.

My fundamental understanding how the dynamic patches are applied was incorrect. Like normal patches, once the patch is enabled it will be stuck and baked into savestates,

@F0bes F0bes force-pushed the dynpnach branch 2 times, most recently from 4ec25cc to a78c53b Compare September 16, 2024 20:54
@F0bes
Copy link
Member Author

F0bes commented Sep 26, 2024

Okay, I've implemented a version/type field and my original PR message has been updated to reflect that.

@F0bes F0bes merged commit cc9c0f9 into master Sep 26, 2024
22 checks passed
@F0bes F0bes deleted the dynpnach branch September 26, 2024 21:15
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