hg-commit-id: c6f5d5a99ac0
This commit is contained in:
IIMarckus 2012-01-05 22:36:06 -07:00
commit faa63c870b
6 changed files with 5410 additions and 254 deletions

View file

@ -1257,8 +1257,8 @@ SPRITE_PAPER_SHEET EQU $40
SPRITE_BOOK_MAP_DEX EQU $41
SPRITE_CLIPBOARD EQU $42
SPRITE_SNORLAX EQU $43
SPRITE_OLD_AMBER EQU $44
SPRITE_OLD_AMBER_COPY EQU $45
SPRITE_OLD_AMBER_COPY EQU $44
SPRITE_OLD_AMBER EQU $45
SPRITE_LYING_OLD_MAN_UNUSED_1 EQU $46
SPRITE_LYING_OLD_MAN_UNUSED_2 EQU $47
SPRITE_LYING_OLD_MAN EQU $48

View file

@ -532,7 +532,7 @@ def get_object_data(address):
def compute_object_data_size(object):
size = 4
size += 6 * (object["number_of_things"])
size += 6 * (int(object["number_of_things"]))
trainer_count = 0
item_count = 0

View file

@ -0,0 +1,83 @@
#!/usr/bin/python2.7
#author: Bryan Bishop <kanzure@gmail.com>
#date: 2012-01-05
#insert object data into pokered.asm
import extract_maps
from pretty_map_headers import map_name_cleaner, object_data_pretty_printer, make_object_label_name, make_text_label, map_constants
from analyze_incbins import asm, offset_to_pointer, find_incbin_to_replace_for, split_incbin_line_into_three, generate_diff_insert, load_asm, isolate_incbins, process_incbins
import analyze_incbins
import os, sys
import subprocess
spacing = " "
def insert_object(map_id):
map = extract_maps.map_headers[map_id]
object = map["object_data"]
size = extract_maps.compute_object_data_size(object)
address = int(map["object_data_pointer"], 16)
line_number = find_incbin_to_replace_for(address)
if line_number == None:
print "skipping object data for map " + str(map["id"]) + " at " + map["object_data_pointer"] + " for " + str(size) + " bytes."
return
newlines = split_incbin_line_into_three(line_number, address, size)
object_asm = object_data_pretty_printer(map_id)
newlines = newlines.split("\n")
if len(newlines) == 2: index = 0 #replace the 1st line with new content
elif len(newlines) == 3: index = 1 #replace the 2nd line with new content
newlines[index] = object_asm
if len(newlines) == 3 and newlines[2][-2:] == "$0":
#get rid of the last incbin line if it is only including 0 bytes
del newlines[2]
#note that this has to be done after adding in the new 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")
#confirm it's working
subprocess.check_call("cd ../; make clean; LC_CTYPE=UTF-8 make", shell=True)
def insert_all_objects():
for map_id in extract_maps.map_headers.keys():
if map_id not in extract_maps.bad_maps:
insert_object(map_id)
analyze_incbins.asm = None
analyze_incbins.incbin_lines = []
analyze_incbins.processed_incbins = {}
load_asm()
isolate_incbins()
process_incbins()
if __name__ == "__main__":
#load map headers and object data
extract_maps.load_rom()
extract_maps.load_map_pointers()
extract_maps.read_all_map_headers()
#load incbins
load_asm()
isolate_incbins()
process_incbins()
#insert_object(1)
insert_all_objects()

View file

@ -4,6 +4,7 @@
#purpose: dump asm for each map header
import json
import extract_maps
import sprite_helper
import random
import string
@ -415,6 +416,12 @@ def make_object_label_name(name):
name = map_name_cleaner(name, None)
return name.replace("_h", "") + "Object"
def make_text_label(map_name, id):
"""using standard object labels
for instance, PalletTownText3"""
label = map_name_cleaner(map_name, None)[:-2] + "Text" + str(id)
return label
def object_data_pretty_printer(map_id):
map = extract_maps.map_headers[map_id]
output = ""
@ -437,7 +444,10 @@ def object_data_pretty_printer(map_id):
warp_to_point = warp["warp_to_point"]
warp_to_map_id = warp["warp_to_map_id"]
warp_to_map_constant = map_constants[warp_to_map_id]
try:
warp_to_map_constant = map_constants[warp_to_map_id]
except Exception, exc:
warp_to_map_constant = "$" + hex(warp_to_map_id)[2:]
output += spacing + "db $" + hex(int(y))[2:] + ", $" + hex(int(x))[2:] + ", $" + hex(int(warp_to_point))[2:] + ", " + warp_to_map_constant + "\n"
@ -451,7 +461,7 @@ def object_data_pretty_printer(map_id):
x = sign["x"]
text_id = sign["text_id"]
output += spacing + "db $" + hex(int(y))[2:] + ", $" + hex(int(x))[2:] + ", $" + hex(int(text_id))[2:] + "\n"
output += spacing + "db $" + hex(int(y))[2:] + ", $" + hex(int(x))[2:] + ", $" + hex(int(text_id))[2:] + " ; " + make_text_label(map["name"], text_id) + "\n"
output += "\n"
output += spacing + "db $" + hex(int(object["number_of_things"]))[2:] + " ; people\n"
@ -475,13 +485,12 @@ def object_data_pretty_printer(map_id):
movement2 = hex(int(thing["movement2"]))[2:]
text_id = hex(int(thing["original_text_string_number"]))[2:]
output += spacing + "db $" + picture_number + ", $" + y + " + 4, $" + x + " + 4, $" + movement1 + ", $" + movement2 + ", $" + text_id + ending
output += spacing + "db " + sprite_helper.sprites[thing["picture_number"]] + ", $" + y + " + 4, $" + x + " + 4, $" + movement1 + ", $" + movement2 + ", $" + text_id + ending
output += "\n"
if object["number_of_warps"] > 0:
output += spacing + "; warp-to\n"
output += "\n"
for warp_to_id in object["warp_tos"]:
warp_to = object["warp_tos"][warp_to_id]
@ -489,11 +498,16 @@ def object_data_pretty_printer(map_id):
warp_to_y = hex(int(warp_to["y"]))[2:]
warp_to_x = hex(int(warp_to["x"]))[2:]
output += spacing + "EVENT_DISP $" + map_width[2:] + ", $" + warp_to_y + ", $" + warp_to_x + "\n"
try:
previous_location = map_constants[object["warps"][warp_to_id]["warp_to_map_id"]]
comment = " ; " + previous_location
except Exception, exc:
comment = ""
output += spacing + "EVENT_DISP $" + map_width[2:] + ", $" + warp_to_y + ", $" + warp_to_x + comment + "\n"
#output += spacing + "dw $" + hex(int(warp_to["event_displacement"][1]))[2:] + hex(int(warp_to["event_displacement"][0]))[2:] + "\n"
#output += spacing + "db $" + hex(int(warp_to["y"]))[2:] + ", $" + hex(int(warp_to["x"]))[2:] + "\n"
output += "\n"
#output += "\n"
output += "\n"

View file

@ -73,7 +73,7 @@ constants = {
0x41: ["book/map/dex", ""],
0x42: ["clipboard", ""],
0x43: ["snorlax", ""],
0x44: ["old amber", ""],
0x44: ["old amber copy", ""],
0x45: ["old amber", ""],
0x46: ["lying old man unused 1", ""],
0x47: ["lying old man unused 2", ""],
@ -83,6 +83,7 @@ constants = {
icons = {}
unique_icons = set()
todo_sprites = {}
sprites = {}
def load_icons():
for map_id in map_headers:
@ -146,7 +147,6 @@ def sprite_name_cleaner(badname):
def sprite_namer():
"makes up better constant names for each sprite"
insert_todo_sprites()
sprites = {}
for sprite_id in constants:
suggestions = constants[sprite_id]
@ -160,6 +160,7 @@ def sprite_namer():
result = sprite_name_cleaner(original)
sprites[sprite_id] = result
def sprite_printer():
for key in sprites:
line_length = len(sprites[key]) + len(" EQU $") + 2
@ -172,8 +173,9 @@ def sprite_namer():
print sprites[key] + extra + " EQU $" + value
sprite_namer()
if __name__ == "__main__":
#load_icons()
#print_appearances()
sprite_namer()
sprite_printer()

File diff suppressed because it is too large Load diff