Created
December 28, 2023 14:52
-
-
Save LudovicOmarini/dcb99479b53340ac77ee51a975e019b0 to your computer and use it in GitHub Desktop.
Convert Action Replay code to Libretro code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Encryption seeds for Pro Action Replay v3/4 | |
Seeds = [ | |
0x7AA9648F, | |
0x7FAE6994, | |
0xC0EFAAD5, | |
0x42712C57 | |
] | |
def decrypt(opcode, operand): | |
for i in range(32, 0, -1): | |
operand = (operand - ((opcode * 16 + Seeds[2]) ^ ((opcode + 0x9E3779B9 * i) ^ ((opcode >> 5) + Seeds[3])))) & 0xFFFFFFFF | |
opcode = (opcode - ((operand * 16 + Seeds[0]) ^ ((operand + 0x9E3779B9 * i) ^ ((operand >> 5) + Seeds[1])))) & 0xFFFFFFFF | |
return opcode, operand | |
def parse_codes(text): | |
lines = text.strip().split('\n') | |
return [(int(line.split()[0], 16), int(line.split()[1], 16)) for line in lines] | |
def main(input_text): | |
codes = parse_codes(input_text) | |
decrypted_codes = [f"{opcode:08X} {operand:08X}" for opcode, operand in (decrypt(opcode, operand) for opcode, operand in codes)] | |
return '+'.join(decrypted_codes) | |
###### Insert your code here ###### | |
input_text = """ | |
F3A9A86D 4E2629B4 | |
18452A7D DDE55BCC | |
""" | |
# Call function and store result | |
decrypted_result = main(input_text) | |
# Format to .cht | |
print(f"cheatX_desc = \"\"") | |
print(f"cheatX_code = \"{decrypted_result}\"") | |
print(f"cheatX_enable = false") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment