# This shitty script looks through a Pokemon Red/Blue (USA) ROM for anything that looks like a string, converts the Pokemon characters to readable ones, then prints each string alongside its position in ROM. # Run with a filename to print the strings in a ROM. # Run with -t to convert entered text to chars (in decimal). # Run with -g to convert entered chars (in decimal) to text. # < and > are "names" ex. "Do you want to give a nickname to >?" or "< reamed >'s bunghole for a million bonus points." # ~ is newline. + advances the textbox. * refreshes the textbox. # # is usually the end of a string. # All other chars will be displayed as % followed by the char as an integer char_table = [[0x00, "_NULL"], [0x4f, "~"], [0x57, "#"], [0x51, "*"], [0x52, "<"], [0x53, ">"], [0x54, "_POKe"], [0x55, "+"], [0x58, "$"], [0x75, "..."], [0x7F, " "], [0x80, "A"], [0x81, "B"], [0x82, "C"], [0x83, "D"], [0x84, "E"], [0x85, "F"], [0x86, "G"], [0x87, "H"], [0x88, "I"], [0x89, "J"], [0x8a, "K"], [0x8b, "L"], [0x8c, "M"], [0x8d, "N"], [0x8e, "O"], [0x8f, "P"], [0x90, "Q"], [0x91, "R"], [0x92, "S"], [0x93, "T"], [0x94, "U"], [0x95, "V"], [0x96, "W"], [0x97, "X"], [0x98, "Y"], [0x99, "Z"], [0x9a, "("], [0x9b, ")"], [0x9c, ":"], [0x9d, ";"], [0x9e, "["], [0x9f, "]"], [0xa0, "a"], [0xa1, "b"], [0xa2, "c"], [0xa3, "d"], [0xa4, "e"], [0xa5, "f"], [0xa6, "g"], [0xa7, "h"], [0xa8, "i"], [0xa9, "j"], [0xaa, "k"], [0xab, "l"], [0xac, "m"], [0xad, "n"], [0xae, "o"], [0xaf, "p"], [0xb0, "q"], [0xb1, "r"], [0xb2, "s"], [0xb3, "t"], [0xb4, "u"], [0xb5, "v"], [0xb6, "w"], [0xb7, "x"], [0xb8, "y"], [0xb9, "z"], [0xba, "e'"], [0xbb, "'d"], [0xbc, "'l"], [0xbd, "'s"], [0xbe, "'t"], [0xbf, "'v"], [0xe0, "'"], [0xe1, "_PK"], [0xe2, "_MN"], [0xe3, "-"], [0xe4, "'r"], [0xe5, "'m"], [0xe6, "?"], [0xe7, "!"], [0xe8, "."], [0xf3, "/"], [0xf1, "_MULT"], [0xf0, "_YEN"], [0xef, "_BOY"], [0xf4, ","], [0xf5, "_GRL"], [0xf6, "0"], [0xf7, "1"], [0xf8, "2"], [0xf9, "3"], [0xfa, "4"], [0xfb, "5"], [0xfc, "6"], [0xfd, "7"], [0xfe, "8"], [0xff, "9"],] def text_to_gb(text): output = "" at = 0 while at < len(text): char = text[at] advance = 1 ok = 0 if char == "'": if text[at+1] == "d" or text[at+1] == "l" or text[at+1] == "s" or text[at+1] == "t" or text[at+1] == "v" or text[at+1] == "r" or text[at+1] == "m": char += text[at+1] advance = 2 if text[at:at+3] == "...": char = text[at:at+3] advance = 3 if text[at:at+3] == "_PK": char = text[at:at+3] advance = 3 if text[at:at+3] == "_MN": char = text[at:at+3] advance = 3 if text[at:at+5] == "_POKe": char = text[at:at+54] advance = 5 if text[at:at+2] == "e'": char = text[at:at+2] advance = 2 if text[at:at+5] == "_NULL": char = text[at:at+5] advance = 54 if text[at:at+5] == "_MULT": char = text[at:at+5] advance = 5 if text[at:at+4] == "_BOY": char = text[at:at+4] advance = 4 if text[at:at+4] == "_GRL": char = text[at:at+4] advance = 4 if text[at:at+4] == "_YEN": char = text[at:at+4] advance = 4 if text[at] == "%": bit = text[at+1:at+4] output += bit advance = 4 else: for b in char_table: if b[1] == char: bit = str(b[0]) while len(bit) < 3: bit = "0" + bit output += bit ok = 1 if ok == 0: bit = str(int(char)) while len(bit) < 3: bit = "0" + bit output += bit at += advance return output def gb_to_text(text): output = "" at = 0 ok = 0 while at < len(text): ok = 1 print(str(int(text[at:at+3]))) for b in char_table: if b[0] == int(text[at:at+3]): output += b[1] ok = 0 break # print the "raw" char if it isn't found on the table if ok: output += chr(int(text[at:at+3])) at += 3 return output def file_to_text(fl): output = "" with open(fl, "rb") as rom: rdata = rom.read() rom.close() at = 0 while at < len(rdata): ok = 0 for b in char_table: if b[0] == rdata[at]: output += b[1] if b[1] == "#": output += "\n(" + str(at) + ") " ok = 1 break #print the "raw" char if it isnt found on the table if ok == 0: bit = str(int(rdata[at])) while len(bit) < 3: bit = "0" + bit output += "%" + bit at += 1 return output def main(args): offset = 0x80 text = "" output = "" is_filename = 1 if args[1] == "-t": print("Convert text to Pokémon chars.\nEnter text:") is_filename = 0 output = text_to_gb(input(text)) if args[1] == "-g": print("Convert pokemon chars to readable text.\nEnter chars:") is_filename = 0 output = gb_to_text(input(text)) if is_filename == 1: output = file_to_text(args[1]) print(output) with open("poke.txt", "w") as rom: rom.write(output) rom.close() return 0 if __name__ == '__main__': import sys sys.exit(main(sys.argv))