You've already forked pokecrystal-board
mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-09-08 08:13:02 -07:00
start using classes instead of functions everywhere
This commit is contained in:
@@ -523,6 +523,7 @@ def clean_up_long_info(long_info):
|
|||||||
return long_info
|
return long_info
|
||||||
|
|
||||||
def command_debug_information(command_byte=None, map_group=None, map_id=None, address=0, info=None, long_info=None, pksv_name=None):
|
def command_debug_information(command_byte=None, map_group=None, map_id=None, address=0, info=None, long_info=None, pksv_name=None):
|
||||||
|
"used to help debug in parse_script_engine_script_at"
|
||||||
info1 = "parsing command byte " + hex(command_byte) + " for map " + \
|
info1 = "parsing command byte " + hex(command_byte) + " for map " + \
|
||||||
str(map_group) + "." + str(map_id) + " at " + hex(address)
|
str(map_group) + "." + str(map_id) + " at " + hex(address)
|
||||||
info1 += " pksv: " + str(pksv_name)
|
info1 += " pksv: " + str(pksv_name)
|
||||||
@@ -530,81 +531,11 @@ def command_debug_information(command_byte=None, map_group=None, map_id=None, ad
|
|||||||
#info1 += " long_info: " + long_info
|
#info1 += " long_info: " + long_info
|
||||||
return info1
|
return info1
|
||||||
|
|
||||||
def process_00_subcommands(start_address, end_address):
|
class TextScript():
|
||||||
"""split this text up into multiple lines
|
"a text is a sequence of commands different from a script-engine script"
|
||||||
based on subcommands ending each line"""
|
def to_asm(self): pass
|
||||||
print "process_00_subcommands(" + hex(start_address) + ", " + hex(end_address) + ")"
|
@staticmethod
|
||||||
lines = {}
|
def find_addresses():
|
||||||
subsection = rom[start_address:end_address]
|
|
||||||
|
|
||||||
line_count = 0
|
|
||||||
current_line = []
|
|
||||||
for pbyte in subsection:
|
|
||||||
byte = ord(pbyte)
|
|
||||||
current_line.append(byte)
|
|
||||||
if byte == 0x4f or byte == 0x51 or byte == 0x55:
|
|
||||||
lines[line_count] = current_line
|
|
||||||
current_line = []
|
|
||||||
line_count += 1
|
|
||||||
|
|
||||||
#don't forget the last line
|
|
||||||
lines[line_count] = current_line
|
|
||||||
line_count += 1
|
|
||||||
return lines
|
|
||||||
|
|
||||||
def parse_text_from_bytes(bytes):
|
|
||||||
"""assembles a string based on bytes looked up in the chars table"""
|
|
||||||
line = ""
|
|
||||||
for byte in bytes:
|
|
||||||
if type(byte) != int:
|
|
||||||
byte = ord(byte)
|
|
||||||
if byte in chars.keys():
|
|
||||||
line += chars[byte]
|
|
||||||
else:
|
|
||||||
print "byte not known: " + hex(byte)
|
|
||||||
return line
|
|
||||||
|
|
||||||
def parse_text_at(address, count=10):
|
|
||||||
"""returns a list of bytes from an address
|
|
||||||
see parse_text_at2 for pretty printing"""
|
|
||||||
return parse_text_from_bytes(rom_interval(address, count, strings=False))
|
|
||||||
|
|
||||||
def rom_text_at(address, count=10):
|
|
||||||
"""prints out raw text from the ROM
|
|
||||||
like for 0x112110"""
|
|
||||||
return "".join([chr(x) for x in rom_interval(address, count, strings=False)])
|
|
||||||
|
|
||||||
def parse_text_at2(address, count=10):
|
|
||||||
"""returns a string of text from an address
|
|
||||||
this does not handle text commands"""
|
|
||||||
output = ""
|
|
||||||
commands = process_00_subcommands(address, address+count)
|
|
||||||
for (line_id, line) in commands.items():
|
|
||||||
output += parse_text_from_bytes(line)
|
|
||||||
output += "\n"
|
|
||||||
return output
|
|
||||||
|
|
||||||
def find_all_text_pointers_in_script_engine_script(script, bank):
|
|
||||||
"""returns a list of text pointers
|
|
||||||
based on each script-engine script command"""
|
|
||||||
#TODO: recursively follow any jumps in the script
|
|
||||||
if script == None: return []
|
|
||||||
addresses = set()
|
|
||||||
for (k, command) in script.items():
|
|
||||||
if command["type"] == 0x4B:
|
|
||||||
addresses.add(command["pointer"])
|
|
||||||
elif command["type"] == 0x4C:
|
|
||||||
addresses.add(command["pointer"])
|
|
||||||
elif command["type"] == 0x51:
|
|
||||||
addresses.add(command["text_pointer"])
|
|
||||||
elif command["type"] == 0x53:
|
|
||||||
addresses.add(command["text_pointer"])
|
|
||||||
elif command["type"] == 0x64:
|
|
||||||
addresses.add(command["won_pointer"])
|
|
||||||
addresses.add(command["lost_pointer"])
|
|
||||||
return addresses
|
|
||||||
|
|
||||||
def find_text_addresses():
|
|
||||||
"""returns a list of text pointers
|
"""returns a list of text pointers
|
||||||
useful for testing parse_text_engine_script_at
|
useful for testing parse_text_engine_script_at
|
||||||
|
|
||||||
@@ -692,11 +623,8 @@ def find_text_addresses():
|
|||||||
texts2 = find_all_text_pointers_in_script_engine_script(script2, trainer_bank)
|
texts2 = find_all_text_pointers_in_script_engine_script(script2, trainer_bank)
|
||||||
addresses.update(texts2)
|
addresses.update(texts2)
|
||||||
return addresses
|
return addresses
|
||||||
|
@staticmethod
|
||||||
def old_parse_text_engine_script_at(address, map_group=None, map_id=None, debug=True):
|
def parse_text_at(address, map_group=None, map_id=None, debug=True, show=True):
|
||||||
return {}
|
|
||||||
|
|
||||||
def parse_text_engine_script_at(address, map_group=None, map_id=None, debug=True, show=True):
|
|
||||||
"""parses a text-engine script ("in-text scripts")
|
"""parses a text-engine script ("in-text scripts")
|
||||||
http://hax.iimarck.us/files/scriptingcodes_eng.htm#InText
|
http://hax.iimarck.us/files/scriptingcodes_eng.htm#InText
|
||||||
|
|
||||||
@@ -907,6 +835,105 @@ def parse_text_engine_script_at(address, map_group=None, map_id=None, debug=True
|
|||||||
# sys.exit()
|
# sys.exit()
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
def parse_text_engine_script_at(address, map_group=None, map_id=None, debug=True, show=True):
|
||||||
|
"""parses a text-engine script ("in-text scripts")
|
||||||
|
http://hax.iimarck.us/files/scriptingcodes_eng.htm#InText
|
||||||
|
see parse_text_at2, parse_text_at, and process_00_subcommands
|
||||||
|
"""
|
||||||
|
return TextScript.parse_text_at(address, map_group=map_group, map_id=map_id, debug=debug, show=show)
|
||||||
|
def find_text_addresses():
|
||||||
|
"""returns a list of text pointers
|
||||||
|
useful for testing parse_text_engine_script_at"""
|
||||||
|
return TextScript.find_addresses()
|
||||||
|
|
||||||
|
class EncodedText():
|
||||||
|
"""a sequence of bytes that, when decoded, represent readable text
|
||||||
|
based on the chars table from textpre.py and other places"""
|
||||||
|
def to_asm(self): pass
|
||||||
|
@staticmethod
|
||||||
|
def process_00_subcommands(start_address, end_address):
|
||||||
|
"""split this text up into multiple lines
|
||||||
|
based on subcommands ending each line"""
|
||||||
|
print "process_00_subcommands(" + hex(start_address) + ", " + hex(end_address) + ")"
|
||||||
|
lines = {}
|
||||||
|
subsection = rom[start_address:end_address]
|
||||||
|
|
||||||
|
line_count = 0
|
||||||
|
current_line = []
|
||||||
|
for pbyte in subsection:
|
||||||
|
byte = ord(pbyte)
|
||||||
|
current_line.append(byte)
|
||||||
|
if byte == 0x4f or byte == 0x51 or byte == 0x55:
|
||||||
|
lines[line_count] = current_line
|
||||||
|
current_line = []
|
||||||
|
line_count += 1
|
||||||
|
|
||||||
|
#don't forget the last line
|
||||||
|
lines[line_count] = current_line
|
||||||
|
line_count += 1
|
||||||
|
return lines
|
||||||
|
@staticmethod
|
||||||
|
def from_bytes(bytes):
|
||||||
|
"""assembles a string based on bytes looked up in the chars table"""
|
||||||
|
line = ""
|
||||||
|
for byte in bytes:
|
||||||
|
if type(byte) != int:
|
||||||
|
byte = ord(byte)
|
||||||
|
if byte in chars.keys():
|
||||||
|
line += chars[byte]
|
||||||
|
else:
|
||||||
|
print "byte not known: " + hex(byte)
|
||||||
|
return line
|
||||||
|
@staticmethod
|
||||||
|
def parse_text_at(address, count=10):
|
||||||
|
"""returns a string of text from an address
|
||||||
|
this does not handle text commands"""
|
||||||
|
output = ""
|
||||||
|
commands = process_00_subcommands(address, address+count)
|
||||||
|
for (line_id, line) in commands.items():
|
||||||
|
output += parse_text_from_bytes(line)
|
||||||
|
output += "\n"
|
||||||
|
return output
|
||||||
|
def process_00_subcommands(start_address, end_address):
|
||||||
|
"""split this text up into multiple lines
|
||||||
|
based on subcommands ending each line"""
|
||||||
|
return EncodedText.process_00_subcommands(start_address, end_address)
|
||||||
|
def parse_text_from_bytes(bytes):
|
||||||
|
"""assembles a string based on bytes looked up in the chars table"""
|
||||||
|
return EncodedText.from_bytes(bytes)
|
||||||
|
def parse_text_at(address, count=10):
|
||||||
|
"""returns a list of bytes from an address
|
||||||
|
see parse_text_at2 for pretty printing"""
|
||||||
|
return parse_text_from_bytes(rom_interval(address, count, strings=False))
|
||||||
|
def parse_text_at2(address, count=10):
|
||||||
|
"""returns a string of text from an address
|
||||||
|
this does not handle text commands"""
|
||||||
|
return EncodedText.parse_text_at(address, count)
|
||||||
|
|
||||||
|
def rom_text_at(address, count=10):
|
||||||
|
"""prints out raw text from the ROM
|
||||||
|
like for 0x112110"""
|
||||||
|
return "".join([chr(x) for x in rom_interval(address, count, strings=False)])
|
||||||
|
|
||||||
|
def find_all_text_pointers_in_script_engine_script(script, bank):
|
||||||
|
"""returns a list of text pointers
|
||||||
|
based on each script-engine script command"""
|
||||||
|
#TODO: recursively follow any jumps in the script
|
||||||
|
if script == None: return []
|
||||||
|
addresses = set()
|
||||||
|
for (k, command) in script.items():
|
||||||
|
if command["type"] == 0x4B:
|
||||||
|
addresses.add(command["pointer"])
|
||||||
|
elif command["type"] == 0x4C:
|
||||||
|
addresses.add(command["pointer"])
|
||||||
|
elif command["type"] == 0x51:
|
||||||
|
addresses.add(command["text_pointer"])
|
||||||
|
elif command["type"] == 0x53:
|
||||||
|
addresses.add(command["text_pointer"])
|
||||||
|
elif command["type"] == 0x64:
|
||||||
|
addresses.add(command["won_pointer"])
|
||||||
|
addresses.add(command["lost_pointer"])
|
||||||
|
return addresses
|
||||||
|
|
||||||
def translate_command_byte(crystal=None, gold=None):
|
def translate_command_byte(crystal=None, gold=None):
|
||||||
"""takes a command byte from either crystal or gold
|
"""takes a command byte from either crystal or gold
|
||||||
@@ -1242,7 +1269,6 @@ def pretty_print_pksv_no_names():
|
|||||||
for address in addresses:
|
for address in addresses:
|
||||||
print " " + hex(address)
|
print " " + hex(address)
|
||||||
|
|
||||||
|
|
||||||
recursive_scripts = set([])
|
recursive_scripts = set([])
|
||||||
def rec_parse_script_engine_script_at(address, origin=None):
|
def rec_parse_script_engine_script_at(address, origin=None):
|
||||||
"""this is called in parse_script_engine_script_at for recursion
|
"""this is called in parse_script_engine_script_at for recursion
|
||||||
|
Reference in New Issue
Block a user