Created
July 22, 2014 11:15
-
-
Save adrian17/5b4aab8396352cfde418 to your computer and use it in GitHub Desktop.
TH autobomb patcher
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
import shutil | |
import os | |
games = [ | |
{"name": "th10", "offset": 0x25013, "data": [0xf6, 0x05, 0x5c, 0x4e, 0x47, 0x00, 0x02, 0x0f, 0x84, 0x52, 0x01, 0x00, 0x00]}, | |
{"name": "th11", "offset": 0x30679, "data": [0xf6, 0x05, 0xc0, 0x93, 0x4c, 0x00, 0x02, 0x0f, 0x84, 0xd5, 0x02, 0x00, 0x00]}, | |
{"name": "th12", "offset": 0x3619b, "data": [0xf6, 0x05, 0xd0, 0x49, 0x4d, 0x00, 0x02, 0x0f, 0x84, 0xe8, 0x01, 0x00, 0x00]}, | |
{"name": "th125", "offset": 0x3ace8, "data": [0xf6, 0x05, 0x10, 0xb2, 0x4d, 0x00, 0x02, 0x0f, 0x84, 0xf9, 0x00, 0x00, 0x00]}, | |
{"name": "th13", "offset": 0x42925, "data": [0xf6, 0x05, 0x14, 0x4c, 0x4e, 0x00, 0x02, 0x0f, 0x84, 0x2c, 0x01, 0x00, 0x00]}, | |
{"name": "th14", "offset": 0x4d2c4, "data": [0xf6, 0x05, 0x9c, 0x8a, 0x4d, 0x00, 0x02, 0x0f, 0x84, 0x00, 0x01, 0x00, 0x00]} | |
] | |
patchLength = 13 | |
def main(): | |
for filename in os.listdir("."): | |
if not filename.endswith(".exe"): | |
continue | |
game = findGame(filename) | |
if game is None: | |
continue | |
print "detected %s as %s." % (filename, game["name"]) | |
newFilename = filename[:-4]+"_autobomb.exe" | |
shutil.copy(filename, newFilename) | |
patch(newFilename, game) | |
print "patched %s as %s \n" % (filename, newFilename) | |
print "Press any key to exit" | |
a=raw_input() | |
def findGame(filename): | |
with open(filename, "rb") as f: | |
for game in games: | |
f.seek(game["offset"]) | |
data = f.read(patchLength) | |
if data == bytearray(game["data"]): | |
return game | |
return None | |
def patch(filename, game): | |
with open(filename, "r+b") as f: | |
f.seek(game["offset"]) | |
f.write("\x90" * patchLength) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment