djhackersdev / bemanitools

Runs recent Konami arcade games and emulates various arcade hardware.
The Unlicense
84 stars 16 forks source link

Small refactor for rp2 and rp3 + add new sign keys - [merged] #212

Closed icex2 closed 1 year ago

icex2 commented 2 years ago

In GitLab by @33c17f40 on May 11, 2022, 22:19

_Merges rp2refactor -> master

Summary

Refactored rp3 to reuse rp2 signature generation code. Could be merged further as the code is largely the same with seemingly the only differences being to key preparation.

Also changed rp2 to use just the signing key + mcode as parameters as I couldn't find evidence of a 3rd input being used as part of the key in any game, but I did find that I needed to have the last byte in the mcode for generated data to match a real dongle.

Description

rp3 is as documented but some things were not mentioned, so here's the extra details for documentation purposes:

>>> print("".join([chr(ord(c) ^ (127 - i)) for i, c in enumerate(",6<14)86")]))
SHAMOSAN
>>> print("".join([chr(ord(c) ^ (127 - i)) for i, c in enumerate(":S<1.)<K")]))
E-AMUSE3
>>> print("".join([chr(ord(c) ^ (127 - i)) for i, c in enumerate("*:223(21")]))
UDONHRKI

The reason I separate rp3 v1 and v2 into two separate functions is because the key decoding part of the code is baked in with the sign key preparation. rp3 v2 seems to be the most commonly found variant out of rp2, rp3 v1, and rp3 v2.
image

Related Issue

How Has This Been Tested?

Booted the affected games to make sure they still worked. Also tested against information from real dongle dumps to make sure it could generate the same payloads for the given parameters.

Checklist

icex2 commented 2 years ago

A somewhat familiar checksum. Great to see you and your high quality contribution here.

I am happy to see someone figured this out and improved various hacky bits of my rather old code. Most of the stuff was created with when I worked on IIDX 14 to 17 support or when creating the groundwork for jubeat 1 support. I do appreciate the additional documentation and explanation. That should help future readers to understand these parts better, I hope.

Your refactoring suggestion to merge rp2 and rp3 are also highly welcome if you have the motivation to work on that as well.

icex2 commented 2 years ago

approved this merge request

icex2 commented 2 years ago

In GitLab by @33c17f40 on May 12, 2022, 02:14

Your refactoring suggestion to merge rp2 and rp3 are also highly welcome if you have the motivation to work on that as well.

I considered it but I became less confident the longer I compared exact details and dialed it back to something I could justify easier. I'll send over another PR later then to merge the code some more.