mirror of
https://github.com/thornAvery/kep-hack.git
synced 2025-09-17 02:40:50 +12:00
added text_pretty_printer_at to analyze_texts
hg-commit-id: 04e647ab44f8
This commit is contained in:
parent
baa077c579
commit
99fcdc90f6
|
@ -5,7 +5,7 @@
|
||||||
import extract_maps
|
import extract_maps
|
||||||
import analyze_incbins #for asm
|
import analyze_incbins #for asm
|
||||||
try:
|
try:
|
||||||
from pretty_map_headers import map_name_cleaner
|
from pretty_map_headers import map_name_cleaner, txt_bytes, spacing, constant_abbreviation_bytes
|
||||||
except Exception, exc: pass
|
except Exception, exc: pass
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import sys
|
import sys
|
||||||
|
@ -383,6 +383,85 @@ def find_missing_08s(all_texts):
|
||||||
print "missing $08 on map_id=" + str(map_id) + " text_id=" + str(text_id) + " line_id=" + str(line_id) + " at " + hex(current_line["start_address"])
|
print "missing $08 on map_id=" + str(map_id) + " text_id=" + str(text_id) + " line_id=" + str(line_id) + " at " + hex(current_line["start_address"])
|
||||||
return missing_08s
|
return missing_08s
|
||||||
|
|
||||||
|
def text_pretty_printer_at(start_address, label="SomeLabel"):
|
||||||
|
commands = parse_text_script(start_address, None, None)
|
||||||
|
|
||||||
|
wanted_command = None
|
||||||
|
for command_id in commands:
|
||||||
|
command = commands[command_id]
|
||||||
|
if command["type"] == 0:
|
||||||
|
wanted_command = command_id
|
||||||
|
|
||||||
|
if wanted_command == None:
|
||||||
|
raise "error: address did not start with a $0 text"
|
||||||
|
|
||||||
|
lines = commands[wanted_command]["lines"]
|
||||||
|
|
||||||
|
#add the ending byte to the last line- always seems $57
|
||||||
|
lines[len(lines.keys())-1].append(commands[1]["type"])
|
||||||
|
|
||||||
|
output = "\n"
|
||||||
|
output += label + ": ; " + hex(start_address) + "\n"
|
||||||
|
first = True
|
||||||
|
for line_id in lines:
|
||||||
|
line = lines[line_id]
|
||||||
|
output += spacing + "db "
|
||||||
|
if first:
|
||||||
|
output += "$0, "
|
||||||
|
first = False
|
||||||
|
|
||||||
|
quotes_open = False
|
||||||
|
first_byte = True
|
||||||
|
was_byte = False
|
||||||
|
byte_count = 0
|
||||||
|
for byte in line:
|
||||||
|
if byte in txt_bytes:
|
||||||
|
if not quotes_open and not first_byte: #start text
|
||||||
|
output += ", \""
|
||||||
|
quotes_open = True
|
||||||
|
first_byte = False
|
||||||
|
if not quotes_open and first_byte: #start text
|
||||||
|
output += "\""
|
||||||
|
quotes_open = True
|
||||||
|
output += txt_bytes[byte]
|
||||||
|
elif byte in constant_abbreviation_bytes:
|
||||||
|
if quotes_open:
|
||||||
|
output += "\""
|
||||||
|
quotes_open = False
|
||||||
|
if not first_byte:
|
||||||
|
output += ", "
|
||||||
|
output += constant_abbreviation_bytes[byte]
|
||||||
|
else:
|
||||||
|
if quotes_open:
|
||||||
|
output += "\""
|
||||||
|
quotes_open = False
|
||||||
|
|
||||||
|
#if you want the ending byte on the last line
|
||||||
|
#if not (byte == 0x57 or byte == 0x50 or byte == 0x58):
|
||||||
|
if not first_byte:
|
||||||
|
output += ", "
|
||||||
|
|
||||||
|
output += "$" + hex(byte)[2:]
|
||||||
|
was_byte = True
|
||||||
|
|
||||||
|
#add a comma unless it's the end of the line
|
||||||
|
#if byte_count+1 != len(line):
|
||||||
|
# output += ", "
|
||||||
|
|
||||||
|
first_byte = False
|
||||||
|
byte_count += 1
|
||||||
|
#close final quotes
|
||||||
|
if quotes_open:
|
||||||
|
output += "\""
|
||||||
|
quotes_open = False
|
||||||
|
|
||||||
|
output += "\n"
|
||||||
|
|
||||||
|
#output += "\n"
|
||||||
|
print output
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
extract_maps.load_rom()
|
extract_maps.load_rom()
|
||||||
extract_maps.load_map_pointers()
|
extract_maps.load_map_pointers()
|
||||||
|
@ -403,3 +482,5 @@ if __name__ == "__main__":
|
||||||
print "total text commands: " + str(total_text_commands)
|
print "total text commands: " + str(total_text_commands)
|
||||||
print "total text scripts: " + str(should_be_total)
|
print "total text scripts: " + str(should_be_total)
|
||||||
print "missing 08s: " + str(missing_08s)
|
print "missing 08s: " + str(missing_08s)
|
||||||
|
|
||||||
|
text_pretty_printer_at(0x800b1)
|
||||||
|
|
|
@ -278,12 +278,13 @@ def insert_all_text_labels():
|
||||||
isolate_incbins()
|
isolate_incbins()
|
||||||
process_incbins()
|
process_incbins()
|
||||||
|
|
||||||
def insert_08_asm(map_id, text_id):
|
#TODO: if line_id !=0 then don't include the label?
|
||||||
|
def insert_08_asm(map_id, text_id, line_id=0):
|
||||||
map2 = extract_maps.map_headers[map_id]
|
map2 = extract_maps.map_headers[map_id]
|
||||||
base_label = map_name_cleaner(map2["name"], None)[:-2]
|
base_label = map_name_cleaner(map2["name"], None)[:-2]
|
||||||
label = base_label + "Text" + str(text_id)
|
label = base_label + "Text" + str(text_id)
|
||||||
|
|
||||||
start_address = all_texts[map_id][text_id][0]["start_address"]
|
start_address = all_texts[map_id][text_id][line_id]["start_address"]
|
||||||
|
|
||||||
(text_asm, end_address) = text_asm_pretty_printer(label, start_address)
|
(text_asm, end_address) = text_asm_pretty_printer(label, start_address)
|
||||||
print "end address is: " + hex(end_address)
|
print "end address is: " + hex(end_address)
|
||||||
|
@ -328,9 +329,9 @@ def find_all_08s():
|
||||||
for map_id in all_texts:
|
for map_id in all_texts:
|
||||||
for text_id in all_texts[map_id].keys():
|
for text_id in all_texts[map_id].keys():
|
||||||
if 0 in all_texts[map_id][text_id].keys():
|
if 0 in all_texts[map_id][text_id].keys():
|
||||||
if "type" in all_texts[map_id][text_id][0].keys():
|
for line_id in all_texts[map_id][text_id].keys():
|
||||||
if all_texts[map_id][text_id][0]["type"] == 0x8:
|
if all_texts[map_id][text_id][line_id]["type"] == 0x8:
|
||||||
all_08s.append([map_id, text_id])
|
all_08s.append([map_id, text_id, line_id])
|
||||||
return all_08s
|
return all_08s
|
||||||
|
|
||||||
def insert_all_08s():
|
def insert_all_08s():
|
||||||
|
@ -339,9 +340,10 @@ def insert_all_08s():
|
||||||
map_id = the_08_line[0]
|
map_id = the_08_line[0]
|
||||||
if map_id <= 86: continue #speed things up
|
if map_id <= 86: continue #speed things up
|
||||||
text_id = the_08_line[1]
|
text_id = the_08_line[1]
|
||||||
|
line_id = the_08_line[2]
|
||||||
|
|
||||||
print "processing map_id=" + str(map_id) + " text_id=" + str(text_id)
|
print "processing map_id=" + str(map_id) + " text_id=" + str(text_id)
|
||||||
insert_08_asm(map_id, text_id)
|
insert_08_asm(map_id, text_id, line_id)
|
||||||
|
|
||||||
#reset everything
|
#reset everything
|
||||||
analyze_incbins.reset_incbins()
|
analyze_incbins.reset_incbins()
|
||||||
|
@ -424,7 +426,7 @@ if __name__ == "__main__":
|
||||||
#insert_08_asm(83, 1)
|
#insert_08_asm(83, 1)
|
||||||
#insert_all_08s()
|
#insert_all_08s()
|
||||||
|
|
||||||
insert_asm(0x2f9e, "GetMonName")
|
insert_asm(0x19926, "VermilionCityText5_2")
|
||||||
|
|
||||||
if len(failed_attempts) > 0:
|
if len(failed_attempts) > 0:
|
||||||
print "-- FAILED ATTEMPTS --"
|
print "-- FAILED ATTEMPTS --"
|
||||||
|
|
|
@ -8,7 +8,7 @@ import extract_maps
|
||||||
import sprite_helper
|
import sprite_helper
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import analyze_texts #hopefully not a dependency loop
|
#import analyze_texts #hopefully not a dependency loop
|
||||||
|
|
||||||
base = 16
|
base = 16
|
||||||
spacing = " "
|
spacing = " "
|
||||||
|
|
Loading…
Reference in a new issue