mirror of
https://github.com/thornAvery/kep-hack.git
synced 2025-11-20 11:55:31 +13:00
analyze_incbins now applies map header asm patches
hg-commit-id: aec68677b92a
This commit is contained in:
parent
36fb1f3ce0
commit
7207000776
|
|
@ -5,7 +5,8 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
import subprocess
|
import subprocess
|
||||||
from extract_maps import rom, assert_rom, load_rom, calculate_pointer
|
from extract_maps import rom, assert_rom, load_rom, calculate_pointer, load_map_pointers, read_all_map_headers, map_headers
|
||||||
|
from pretty_map_headers import map_header_pretty_printer, map_name_cleaner
|
||||||
|
|
||||||
#store each line of source code here
|
#store each line of source code here
|
||||||
asm = None
|
asm = None
|
||||||
|
|
@ -57,9 +58,9 @@ def process_incbins():
|
||||||
|
|
||||||
partial_interval = incbin[21:].split(",")[1]
|
partial_interval = incbin[21:].split(",")[1]
|
||||||
partial_interval = partial_interval.replace(";", "#")
|
partial_interval = partial_interval.replace(";", "#")
|
||||||
partial_interval = partial_interval.replace("$", "0x")
|
partial_interval = partial_interval.replace("$", "0x").replace("0xx", "0x")
|
||||||
interval = eval(partial_interval)
|
interval = eval(partial_interval)
|
||||||
interval_hex = hex(interval).replace("0x", "$")
|
interval_hex = hex(interval).replace("0x", "$").replace("x", "")
|
||||||
|
|
||||||
end = start + interval
|
end = start + interval
|
||||||
end_hex = hex(end).replace("0x", "$")
|
end_hex = hex(end).replace("0x", "$")
|
||||||
|
|
@ -77,14 +78,19 @@ def process_incbins():
|
||||||
def find_incbin_to_replace_for(address):
|
def find_incbin_to_replace_for(address):
|
||||||
"""returns a line number for which incbin to edit
|
"""returns a line number for which incbin to edit
|
||||||
if you were to insert bytes into pokered.asm"""
|
if you were to insert bytes into pokered.asm"""
|
||||||
if type(address) == str: int(address, 16)
|
if type(address) == str: address = int(address, 16)
|
||||||
|
|
||||||
for incbin_key in processed_incbins.keys():
|
for incbin_key in processed_incbins.keys():
|
||||||
incbin = processed_incbins[incbin_key]
|
incbin = processed_incbins[incbin_key]
|
||||||
|
|
||||||
start = incbin["start"]
|
start = incbin["start"]
|
||||||
end = incbin["end"]
|
end = incbin["end"]
|
||||||
|
|
||||||
|
print "start is: " + str(start)
|
||||||
|
print "end is: " + str(end)
|
||||||
|
print "address is: " + str(type(address))
|
||||||
|
print "checking.... " + hex(start) + " <= " + hex(address) + " <= " + hex(end)
|
||||||
|
|
||||||
if start <= address <= end:
|
if start <= address <= end:
|
||||||
return incbin_key
|
return incbin_key
|
||||||
return None
|
return None
|
||||||
|
|
@ -140,7 +146,7 @@ def generate_diff_insert(line_number, newline):
|
||||||
newfile_fh.close()
|
newfile_fh.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
diffcontent = subprocess.check_output("diff -u " + original_filename + " " + newfile_filename, shell=True)
|
diffcontent = subprocess.check_output("diff -u ../pokered.asm " + newfile_filename, shell=True)
|
||||||
except Exception, exc:
|
except Exception, exc:
|
||||||
diffcontent = exc.output
|
diffcontent = exc.output
|
||||||
|
|
||||||
|
|
@ -149,13 +155,68 @@ def generate_diff_insert(line_number, newline):
|
||||||
|
|
||||||
return diffcontent
|
return diffcontent
|
||||||
|
|
||||||
|
def insert_map_header_asm(map_id):
|
||||||
|
map = map_headers[map_id]
|
||||||
|
line_number = find_incbin_to_replace_for(map["address"])
|
||||||
|
if line_number == None: # or map_name_cleaner(map["name"], 0) in "\n".join(line for line in asm):
|
||||||
|
print "i think map id=" + str(map_id) + " has previously been added."
|
||||||
|
return #this map has already been added i bet
|
||||||
|
newlines = split_incbin_line_into_three(line_number, map["address"], 12 + (11 * len(map["connections"])))
|
||||||
|
|
||||||
|
map_header_asm = map_header_pretty_printer(map_headers[map_id])
|
||||||
|
|
||||||
|
newlines = newlines.split("\n")
|
||||||
|
if len(newlines) == 2: index = 0
|
||||||
|
elif len(newlines) == 3:
|
||||||
|
index = 1
|
||||||
|
newlines[0] += "\n" #spacing is a nice thing to have
|
||||||
|
newlines[index] = map_header_asm
|
||||||
|
newlines = "\n".join(line for line in newlines)
|
||||||
|
|
||||||
|
diff = generate_diff_insert(line_number, newlines)
|
||||||
|
|
||||||
|
print diff
|
||||||
|
print "... Applying diff."
|
||||||
|
|
||||||
|
#write the diff to a file
|
||||||
|
fh = open("temp.patch", "w")
|
||||||
|
fh.write(diff)
|
||||||
|
fh.close()
|
||||||
|
|
||||||
|
#apply the patch
|
||||||
|
os.system("patch ../pokered.asm temp.patch")
|
||||||
|
|
||||||
|
#remove the patch
|
||||||
|
os.system("rm temp.patch")
|
||||||
|
|
||||||
|
def wrapper_insert_map_header_asm(map_id):
|
||||||
|
"reload the asm because it has changed (probably)"
|
||||||
|
load_asm()
|
||||||
|
isolate_incbins()
|
||||||
|
process_incbins()
|
||||||
|
insert_map_header_asm(map_id)
|
||||||
|
|
||||||
|
def dump_all_remaining_maps():
|
||||||
|
for map_id in map_headers:
|
||||||
|
print "Inserting map id=" + str(map_id)
|
||||||
|
wrapper_insert_map_header_asm(map_id)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
#load map headers
|
||||||
|
load_rom()
|
||||||
|
load_map_pointers()
|
||||||
|
read_all_map_headers()
|
||||||
|
|
||||||
|
#load incbins (mandatory)
|
||||||
load_asm()
|
load_asm()
|
||||||
isolate_incbins()
|
isolate_incbins()
|
||||||
process_incbins() #print processed_incbins
|
process_incbins() #print processed_incbins
|
||||||
|
|
||||||
line_number = find_incbin_to_replace_for(0x492c3)
|
#line_number = find_incbin_to_replace_for(0x492c3)
|
||||||
newlines = split_incbin_line_into_three(line_number, 0x492c3, 12)
|
#newlines = split_incbin_line_into_three(line_number, 0x492c3, 12)
|
||||||
diff = generate_diff_insert(line_number, newlines)
|
#diff = generate_diff_insert(line_number, newlines)
|
||||||
print diff
|
#print diff
|
||||||
|
|
||||||
|
insert_map_header_asm(81)
|
||||||
|
#dump_all_remaining_maps()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue