orangeglo / everdrive-gba-editor

Build a custom theme for your EverDrive GBA!
https://orangeglo.github.io/everdrive-gba-editor/
GNU General Public License v3.0
12 stars 1 forks source link

Fix IPS patch importing skipping the "Unselected ROM" entry #3

Closed hazelwarez closed 1 year ago

hazelwarez commented 1 year ago

offsetStr will be incorrect when the second or third byte value is < 16 (that is, results in a hex string with only a single digit).

This becomes an issue due to the predefined offset 0x6A08 being read as the single byte 0x8 and converted to a hex string without adding a padding zero. In other words, the array [0, 106, 8] ends up as the number 1704 (0x6A8) rather than 27144 (0x6A08). It is then skipped when the callback valToState[d.offset] evaluates to undefined and is never called.

This fix also adds an additional 0 to the first byte value 0x6 which is ignored by parseInt and does not change the value.

epbarger commented 1 year ago

Great thanks for catching this! I'll do a quick check later and merge this in. I suspect the issue also exists with the gb editor which I can address.

epbarger commented 1 year ago

I confirmed the bug you found, nice job noticing that.

Unfortunately this patch doesn't seem to work correctly (at least on Firefox & Chrome), it looks liketoString(16) doesn't do what you'd expect on uint8array elements when iterating with map. Here's the patch I used to test everdrive_gba_v16_theme_patch.ips.zip

Looks like .map on a typed array creates a new array of the same type - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map

epbarger commented 1 year ago

Fixed in https://github.com/orangeglo/everdrive-gba-editor/commit/b3d8fbd5f580d57d40b8c1ce5dd2cec9c3caa7ff , thanks again for noticing this issue