Skip to content

Conversation

@PhoenixBound
Copy link
Contributor

@PhoenixBound PhoenixBound commented Feb 8, 2025

When a ROM has a change that begins at address 454F46 (ASCII EOF), it can't normally be encoded in an IPS file, because that offset value is used to mark the end of the patch. CoilSnake did have code to catch that case, but it seems like it was never tested, at least not in any recent version of Python... it caused a single int to be inserted as the change to make to an offset, rather than a bytes object. All of the other code was based on bytes objects being appended together, so the next loop iteration would raise a TypeError (unsupported operand type(s) for +=: 'int' and 'bytes')

Changes were tested by changing an all-zeroes file to have the bytes DE AD at offset 454F46 and confirming that the IPS patch contained a 3-byte change beginning at offset 454F45 consisting of 00 DE AD.

The design of this patch creation loop is... kinda weird, with how it processes -1 or 0 or 1 bytes each loop iteration (this PR fixes the only -1 case), and how it manually calls methods like __len__() and __getitem__(index). But it doesn't seem buggy apart from this one thing.

Copy link
Contributor

@charasyn charasyn left a comment

Choose a reason for hiding this comment

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

Thanks for making this PR!

As discovered by @Messianic, this code path was buggy and not properly
tested. It made the record a single int instead of a bytes object.
@charasyn charasyn merged commit ab8b3d7 into pk-hack:master Feb 9, 2025
1 check passed
@PhoenixBound PhoenixBound deleted the patch-eof-offset branch February 10, 2025 00:00
ichee added a commit to ichee/CoilSnake that referenced this pull request Feb 10, 2025
* Fix creation of IPS patches with records beginning at 454F46 (pk-hack#314)

As discovered by @Messianic, this code path was buggy and not properly
tested. It made the record a single int instead of a bytes object.

* Upgrade project files

* Update EnemyModule.py

* Upgrade project files

* Update EnemyModule.py

---------

Co-authored-by: PhoenixBound <PhoenixBound@users.noreply.github.com>
ichee added a commit to ichee/CoilSnake that referenced this pull request Feb 10, 2025
* Fix creation of IPS patches with records beginning at 454F46 (pk-hack#314)

As discovered by @Messianic, this code path was buggy and not properly
tested. It made the record a single int instead of a bytes object.

* Upgrade project files

* Update EnemyModule.py

* Upgrade project files

* Update EnemyModule.py

* Update version maybe

* Update EnemyModule take 2

* Update eb.yml

* Update EnemyModule.py

---------

Co-authored-by: PhoenixBound <PhoenixBound@users.noreply.github.com>
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